]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_effects.c
missed this one...
[divverent/darkplaces.git] / cl_effects.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "quakedef.h"
22
23 #define MAX_EFFECTS 256
24
25 typedef struct effect_s
26 {
27         int active;
28         vec3_t origin;
29         float starttime;
30         float framerate;
31         int modelindex;
32         int startframe;
33         int endframe;
34         // these are for interpolation
35         int frame;
36         double frame1start;
37         double frame2start;
38 }
39 effect_t;
40
41 effect_t effect[MAX_EFFECTS];
42
43 cvar_t r_draweffects = {"r_draweffects", "1"};
44
45 void r_effects_start()
46 {
47         memset(effect, 0, sizeof(effect));
48 }
49
50 void r_effects_shutdown()
51 {
52 }
53
54 void CL_Effects_Init()
55 {
56         Cvar_RegisterVariable(&r_draweffects);
57
58         R_RegisterModule("R_Effects", r_effects_start, r_effects_shutdown);
59 }
60
61 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
62 {
63         int i;
64         effect_t *e;
65         if (!modelindex) // sanity check
66                 return;
67         for (i = 0, e = effect;i < MAX_EFFECTS;i++, e++)
68         {
69                 if (e->active)
70                         continue;
71                 e->active = true;
72                 VectorCopy(org, e->origin);
73                 e->modelindex = modelindex;
74                 e->starttime = cl.time;
75                 e->startframe = startframe;
76                 e->endframe = startframe + framecount;
77                 e->framerate = framerate;
78
79                 e->frame = 0;
80                 e->frame1start = cl.time;
81                 e->frame2start = cl.time;
82                 break;
83         }
84 }
85
86 void CL_DoEffects()
87 {
88         int i, intframe;
89         effect_t *e;
90         entity_t *vis;
91         float frame;
92
93         for (i = 0, e = effect;i < MAX_EFFECTS;i++, e++)
94         {
95                 if (e->active)
96                 {
97                         frame = (cl.time - e->starttime) * e->framerate + e->startframe;
98                         intframe = frame;
99                         if (intframe < 0 || intframe >= e->endframe)
100                         {
101                                 e->active = false;
102                                 memset(e, 0, sizeof(*e));
103                                 continue;
104                         }
105
106                         if (intframe != e->frame)
107                         {
108                                 e->frame = intframe;
109                                 e->frame1start = e->frame2start;
110                                 e->frame2start = cl.time;
111                         }
112
113                         vis = CL_NewTempEntity();
114                         if (!vis)
115                                 continue;
116                         VectorCopy(e->origin, vis->origin);
117                         vis->lerp_model = vis->model = cl.model_precache[e->modelindex];
118                         vis->frame1 = e->frame;
119                         vis->frame2 = e->frame + 1;
120                         if (vis->frame2 >= e->endframe)
121                                 vis->frame2 = -1; // disappear
122                         vis->frame = vis->frame2;
123                         vis->framelerp = frame - vis->frame1;
124                         vis->frame1start = e->frame1start;
125                         vis->frame2start = e->frame2start;
126                         vis->lerp_starttime = -1;
127                         vis->colormap = -1; // no special coloring
128                         vis->scale = 1;
129                         vis->alpha = 1;
130                         vis->colormod[0] = vis->colormod[1] = vis->colormod[2] = 1;
131                 }
132         }
133 }