]> icculus.org git repositories - btb/d2x.git/blob - main/vclip.c
add missing includes
[btb/d2x.git] / main / vclip.c
1 /* $Id: vclip.c,v 1.6 2004-08-28 23:17:45 schaffner Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Routines for vclips.
18  *
19  */
20
21
22 #ifdef HAVE_CONFIG_H
23 #include <conf.h>
24 #endif
25
26 #ifdef RCS
27 static char rcsid[] = "$Id: vclip.c,v 1.6 2004-08-28 23:17:45 schaffner Exp $";
28 #endif
29
30 #include <stdlib.h>
31
32 #include "error.h"
33
34 #include "inferno.h"
35 #include "vclip.h"
36 #include "weapon.h"
37 #include "laser.h"
38
39 //----------------- Variables for video clips -------------------
40 int                                     Num_vclips = 0;
41 vclip                           Vclip[VCLIP_MAXNUM];            // General purpose vclips.
42
43 //draw an object which renders as a vclip
44 void draw_vclip_object(object *obj,fix timeleft,int lighted, int vclip_num)
45 {
46         int nf,bitmapnum;
47
48         nf = Vclip[vclip_num].num_frames;
49
50         bitmapnum =  (nf - f2i(fixdiv( (nf-1)*timeleft,Vclip[vclip_num].play_time))) - 1;
51
52         if (bitmapnum >= Vclip[vclip_num].num_frames)
53                 bitmapnum=Vclip[vclip_num].num_frames-1;
54
55         if (bitmapnum >= 0 )    {
56
57                 if (Vclip[vclip_num].flags & VF_ROD)
58                         draw_object_tmap_rod(obj, Vclip[vclip_num].frames[bitmapnum],lighted);
59                 else {
60                         Assert(lighted==0);             //blob cannot now be lighted
61
62                         draw_object_blob(obj, Vclip[vclip_num].frames[bitmapnum] );
63                 }
64         }
65
66 }
67
68
69 void draw_weapon_vclip(object *obj)
70 {
71         int     vclip_num;
72         fix     modtime,play_time;
73
74         //mprintf( 0, "[Drawing obj %d type %d fireball size %x]\n", obj-Objects, Weapon_info[obj->id].weapon_vclip, obj->size );
75
76         Assert(obj->type == OBJ_WEAPON);
77
78         vclip_num = Weapon_info[obj->id].weapon_vclip;
79
80         modtime = obj->lifeleft;
81         play_time = Vclip[vclip_num].play_time;
82
83         //      Special values for modtime were causing enormous slowdown for omega blobs.
84         if (modtime == IMMORTAL_TIME)
85                 modtime = play_time;
86
87         //      Should cause Omega blobs (which live for one frame) to not always be the same.
88         if (modtime == ONE_FRAME_TIME)
89                 modtime = d_rand();
90
91         if (obj->id == PROXIMITY_ID) {          //make prox bombs spin out of sync
92                 int objnum = obj-Objects;
93
94                 modtime += (modtime * (objnum&7)) / 16; //add variance to spin rate
95
96                 while (modtime > play_time)
97                         modtime -= play_time;
98
99                 if ((objnum&1) ^ ((objnum>>1)&1))                       //make some spin other way
100                         modtime = play_time - modtime;
101
102         }
103         else {
104                 while (modtime > play_time)
105                         modtime -= play_time;
106         }
107
108         draw_vclip_object(obj, modtime, 0, vclip_num);
109
110 }
111
112 #ifndef FAST_FILE_IO
113 /*
114  * reads n vclip structs from a CFILE
115  */
116 int vclip_read_n(vclip *vc, int n, CFILE *fp)
117 {
118         int i, j;
119
120         for (i = 0; i < n; i++) {
121                 vc[i].play_time = cfile_read_fix(fp);
122                 vc[i].num_frames = cfile_read_int(fp);
123                 vc[i].frame_time = cfile_read_fix(fp);
124                 vc[i].flags = cfile_read_int(fp);
125                 vc[i].sound_num = cfile_read_short(fp);
126                 for (j = 0; j < VCLIP_MAX_FRAMES; j++)
127                         vc[i].frames[j].index = cfile_read_short(fp);
128                 vc[i].light_value = cfile_read_fix(fp);
129         }
130         return i;
131 }
132 #endif