]> icculus.org git repositories - btb/d2x.git/blob - main/vclip.c
added FreeBSD defs
[btb/d2x.git] / main / vclip.c
1 /* $Id: vclip.c,v 1.5 2003-10-10 09:36:35 btb 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  * Old Log:
20  * Revision 1.2  1995/09/14  14:14:31  allender
21  * return void in draw_vclip_object
22  *
23  * Revision 1.1  1995/05/16  15:32:00  allender
24  * Initial revision
25  *
26  * Revision 2.0  1995/02/27  11:32:41  john
27  * New version 2.0, which has no anonymous unions, builds with
28  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
29  *
30  * Revision 1.8  1994/09/25  23:40:52  matt
31  * Changed the object load & save code to read/write the structure fields one
32  * at a time (rather than the whole structure at once).  This mean that the
33  * object structure can be changed without breaking the load/save functions.
34  * As a result of this change, the local_object data can be and has been
35  * incorporated into the object array.  Also, timeleft is now a property
36  * of all objects, and the object structure has been otherwise cleaned up.
37  *
38  * Revision 1.7  1994/09/25  15:45:26  matt
39  * Added OBJ_LIGHT, a type of object that casts light
40  * Added generalized lifeleft, and moved it to local_object
41  *
42  * Revision 1.6  1994/09/09  20:05:57  mike
43  * Add vclips for weapons.
44  *
45  * Revision 1.5  1994/06/14  21:14:35  matt
46  * Made rod objects draw lighted or not depending on a parameter, so the
47  * materialization effect no longer darkens.
48  *
49  * Revision 1.4  1994/06/08  18:16:24  john
50  * Bunch of new stuff that basically takes constants out of the code
51  * and puts them into bitmaps.tbl.
52  *
53  * Revision 1.3  1994/06/03  10:47:17  matt
54  * Made vclips (used by explosions) which can be either rods or blobs, as
55  * specified in BITMAPS.TBL.  (This is for the materialization center effect).
56  *
57  * Revision 1.2  1994/05/11  09:25:25  john
58  * Abandoned new vclip system for now because each wallclip, vclip,
59  * etc, is different and it would be a huge pain to change all of them.
60  *
61  * Revision 1.1  1994/05/10  15:21:12  john
62  * Initial revision
63  *
64  *
65  */
66
67
68 #ifdef HAVE_CONFIG_H
69 #include <conf.h>
70 #endif
71
72 #ifdef RCS
73 static char rcsid[] = "$Id: vclip.c,v 1.5 2003-10-10 09:36:35 btb Exp $";
74 #endif
75
76 #include <stdlib.h>
77
78 #include "error.h"
79
80 #include "inferno.h"
81 #include "vclip.h"
82 #include "weapon.h"
83 #include "laser.h"
84
85 //----------------- Variables for video clips -------------------
86 int                                     Num_vclips = 0;
87 vclip                           Vclip[VCLIP_MAXNUM];            // General purpose vclips.
88
89 //draw an object which renders as a vclip
90 void draw_vclip_object(object *obj,fix timeleft,int lighted, int vclip_num)
91 {
92         int nf,bitmapnum;
93
94         nf = Vclip[vclip_num].num_frames;
95
96         bitmapnum =  (nf - f2i(fixdiv( (nf-1)*timeleft,Vclip[vclip_num].play_time))) - 1;
97
98         if (bitmapnum >= Vclip[vclip_num].num_frames)
99                 bitmapnum=Vclip[vclip_num].num_frames-1;
100
101         if (bitmapnum >= 0 )    {
102
103                 if (Vclip[vclip_num].flags & VF_ROD)
104                         draw_object_tmap_rod(obj, Vclip[vclip_num].frames[bitmapnum],lighted);
105                 else {
106                         Assert(lighted==0);             //blob cannot now be lighted
107
108                         draw_object_blob(obj, Vclip[vclip_num].frames[bitmapnum] );
109                 }
110         }
111
112 }
113
114
115 void draw_weapon_vclip(object *obj)
116 {
117         int     vclip_num;
118         fix     modtime,play_time;
119
120         //mprintf( 0, "[Drawing obj %d type %d fireball size %x]\n", obj-Objects, Weapon_info[obj->id].weapon_vclip, obj->size );
121
122         Assert(obj->type == OBJ_WEAPON);
123
124         vclip_num = Weapon_info[obj->id].weapon_vclip;
125
126         modtime = obj->lifeleft;
127         play_time = Vclip[vclip_num].play_time;
128
129         //      Special values for modtime were causing enormous slowdown for omega blobs.
130         if (modtime == IMMORTAL_TIME)
131                 modtime = play_time;
132
133         //      Should cause Omega blobs (which live for one frame) to not always be the same.
134         if (modtime == ONE_FRAME_TIME)
135                 modtime = d_rand();
136
137         if (obj->id == PROXIMITY_ID) {          //make prox bombs spin out of sync
138                 int objnum = obj-Objects;
139
140                 modtime += (modtime * (objnum&7)) / 16; //add variance to spin rate
141
142                 while (modtime > play_time)
143                         modtime -= play_time;
144
145                 if ((objnum&1) ^ ((objnum>>1)&1))                       //make some spin other way
146                         modtime = play_time - modtime;
147
148         }
149         else {
150                 while (modtime > play_time)
151                         modtime -= play_time;
152         }
153
154         draw_vclip_object(obj, modtime, 0, vclip_num);
155
156 }
157
158 #ifndef FAST_FILE_IO
159 /*
160  * reads n vclip structs from a CFILE
161  */
162 int vclip_read_n(vclip *vc, int n, CFILE *fp)
163 {
164         int i, j;
165
166         for (i = 0; i < n; i++) {
167                 vc[i].play_time = cfile_read_fix(fp);
168                 vc[i].num_frames = cfile_read_int(fp);
169                 vc[i].frame_time = cfile_read_fix(fp);
170                 vc[i].flags = cfile_read_int(fp);
171                 vc[i].sound_num = cfile_read_short(fp);
172                 for (j = 0; j < VCLIP_MAX_FRAMES; j++)
173                         vc[i].frames[j].index = cfile_read_short(fp);
174                 vc[i].light_value = cfile_read_fix(fp);
175         }
176         return i;
177 }
178 #endif