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