2 * $Logfile: /Freespace2/code/Weapon/MuzzleFlash.cpp $
7 * all sorts of cool stuff about ships
10 * Revision 1.2 2002/05/07 03:16:53 theoddone33
11 * The Great Newline Fix
13 * Revision 1.1.1.1 2002/05/03 03:28:11 root
17 * 7 7/08/99 10:53a Dave
18 * New multiplayer interpolation scheme. Not 100% done yet, but still
19 * better than the old way.
21 * 6 5/18/99 1:30p Dave
22 * Added muzzle flash table stuff.
24 * 5 4/25/99 3:02p Dave
25 * Build defines for the E3 build.
27 * 4 4/12/99 11:03p Dave
28 * Removed contrails and muzzle flashes from MULTIPLAYER_BETA builds.
30 * 3 3/19/99 9:52a Dave
31 * Checkin to repair massive source safe crash. Also added support for
32 * pof-style nebulae, and some new weapons code.
34 * 2 1/08/99 2:08p Dave
35 * Fixed software rendering for pofview. Super early support for AWACS and
44 #include "systemvars.h"
47 #include "muzzleflash.h"
51 // ---------------------------------------------------------------------------------------------------------------------
52 // MUZZLE FLASH DEFINES/VARS
55 // muzzle flash info - read from a table
56 #define MAX_MFLASH_NAME_LEN 32
57 #define MAX_MFLASH_BLOBS 5
58 typedef struct mflash_info {
59 char name[MAX_MFLASH_NAME_LEN+1];
60 char blob_names[MAX_MFLASH_BLOBS][MAX_MFLASH_NAME_LEN+1]; // blob anim name
61 int blob_anims[MAX_MFLASH_BLOBS]; // blob anim
62 float blob_offset[MAX_MFLASH_BLOBS]; // blob offset from muzzle
63 float blob_radius[MAX_MFLASH_BLOBS]; // blob radius
64 int num_blobs; // # of blobs
66 mflash_info Mflash_info[MAX_MUZZLE_FLASH_TYPES];
67 int Num_mflash_types = 0;
71 // Stuff for missile trails doesn't need to be saved or restored... or does it?
73 typedef struct mflash {
77 ubyte type; // muzzle flash type
78 int blobs[MAX_MFLASH_BLOBS]; // blobs
82 mflash Mflash[MAX_MFLASH];
84 mflash Mflash_free_list;
85 mflash Mflash_used_list;
88 // ---------------------------------------------------------------------------------------------------------------------
89 // MUZZLE FLASH FUNCTIONS
92 // initialize muzzle flash stuff for the whole game
93 void mflash_game_init()
97 char name[MAX_MFLASH_NAME_LEN];
101 read_file_text("mflash.tbl");
105 required_string("#Muzzle flash types");
108 Num_mflash_types = 0;
109 while(optional_string("$Mflash:")){
110 if(Num_mflash_types < MAX_MUZZLE_FLASH_TYPES){
111 m = &Mflash_info[Num_mflash_types++];
115 memset(m, 0, sizeof(mflash_info));
116 for(idx=0; idx<MAX_MFLASH_BLOBS; idx++){
117 m->blob_anims[idx] = -1;
120 required_string("+name:");
121 stuff_string(m->name, F_NAME, NULL);
125 while(optional_string("+blob_name:")){
126 stuff_string(name, F_NAME, NULL, MAX_MFLASH_NAME_LEN);
128 required_string("+blob_offset:");
129 stuff_float(&offset);
131 required_string("+blob_radius:");
132 stuff_float(&radius);
134 // if we have room left
135 if(m->num_blobs < MAX_MFLASH_BLOBS){
136 strcpy(m->blob_names[m->num_blobs], name);
137 m->blob_offset[m->num_blobs] = offset;
138 m->blob_radius[m->num_blobs] = radius;
146 required_string("#end");
149 // initialize muzzle flash stuff for the level
150 void mflash_level_init()
157 list_init( &Mflash_free_list );
158 list_init( &Mflash_used_list );
160 // Link all object slots into the free list
161 for (i=0; i<MAX_MFLASH; i++) {
162 memset(&Mflash[i], 0, sizeof(mflash));
163 list_append(&Mflash_free_list, &Mflash[i] );
168 for(i=0; i<Num_mflash_types; i++){
170 for(idx=0; idx<Mflash_info[i].num_blobs; idx++){
171 Mflash_info[i].blob_anims[idx] = -1;
172 Mflash_info[i].blob_anims[idx] = bm_load_animation(Mflash_info[i].blob_names[idx], &num_frames, &fps, 1);
173 Assert(Mflash_info[i].blob_anims[idx] >= 0);
178 // shutdown stuff for the level
179 void mflash_level_close()
183 // create a muzzle flash on the guy
184 void mflash_create(vector *gun_pos, vector *gun_dir, int mflash_type)
191 // standalone server should never create trails
192 if(Game_mode & GM_STANDALONE_SERVER){
197 if((mflash_type >= Num_mflash_types) || (mflash_type < 0)){
202 if (Num_mflash >= MAX_MFLASH ) {
204 mprintf(("Muzzle flash creation failed - too many trails!\n" ));
209 // Find next available trail
210 mflashp = GET_FIRST(&Mflash_free_list);
211 Assert( mflashp != &Mflash_free_list ); // shouldn't have the dummy element
213 // remove trailp from the free list
214 list_remove( &Mflash_free_list, mflashp );
216 // insert trailp onto the end of used list
217 list_append( &Mflash_used_list, mflashp );
220 mflashp->type = (ubyte)mflash_type;
223 // create the actual animations
224 mi = &Mflash_info[mflash_type];
225 for(idx=0; idx<mi->num_blobs; idx++){
228 if(mi->blob_anims[idx] < 0){
233 memset(&p, 0, sizeof(particle_info));
234 vm_vec_scale_add(&p.pos, gun_pos, gun_dir, mi->blob_offset[idx]);
235 p.vel = vmd_zero_vector;
236 p.rad = mi->blob_radius[idx];
237 p.type = PARTICLE_BITMAP;
238 p.optional_data = mi->blob_anims[idx];
239 p.attached_objnum = -1;
248 // process muzzle flash stuff
249 void mflash_process_all()
254 // if the timestamp has elapsed recycle it
255 mflashp = GET_FIRST(&Mflash_used_list);
257 while ( mflashp!=END_OF_LIST(&Mflash_used_list) ) {
258 if((mflashp->stamp == -1) || timestamp_elapsed(mflashp->stamp)){
259 // delete it from the list!
260 mflash *next_one = GET_NEXT(mflashp);
262 // remove objp from the used list
263 list_remove( &Mflash_used_list, mflashp );
265 // add objp to the end of the free
266 list_append( &Mflash_free_list, mflashp );
271 Assert(Num_mflash >= 0);
275 mflashp = GET_NEXT(mflashp);
281 void mflash_render_all()
285 // lookup type by name
286 int mflash_lookup(char *name)
291 for(idx=0; idx<Num_mflash_types; idx++){
292 if(!stricmp(name, Mflash_info[idx].name)){