]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cl_effects.c
rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/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 frame1time;
37         double frame2time;
38 }
39 effect_t;
40
41 static effect_t effect[MAX_EFFECTS];
42
43 static cvar_t r_draweffects = {0, "r_draweffects", "1"};
44
45 static void r_effects_start(void)
46 {
47         memset(effect, 0, sizeof(effect));
48 }
49
50 static void r_effects_shutdown(void)
51 {
52 }
53
54 static void r_effects_newmap(void)
55 {
56         memset(effect, 0, sizeof(effect));
57 }
58
59 void CL_Effects_Init(void)
60 {
61         Cvar_RegisterVariable(&r_draweffects);
62
63         R_RegisterModule("R_Effects", r_effects_start, r_effects_shutdown, r_effects_newmap);
64 }
65
66 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
67 {
68         int i;
69         effect_t *e;
70         if (!modelindex) // sanity check
71                 return;
72         for (i = 0, e = effect;i < MAX_EFFECTS;i++, e++)
73         {
74                 if (e->active)
75                         continue;
76                 e->active = true;
77                 VectorCopy(org, e->origin);
78                 e->modelindex = modelindex;
79                 e->starttime = cl.time;
80                 e->startframe = startframe;
81                 e->endframe = startframe + framecount;
82                 e->framerate = framerate;
83
84                 e->frame = 0;
85                 e->frame1time = cl.time;
86                 e->frame2time = cl.time;
87                 break;
88         }
89 }
90
91 extern void CL_LerpAnimation(entity_t *e);
92
93 void CL_DoEffects()
94 {
95         int i, intframe;
96         effect_t *e;
97         entity_t *vis;
98         float frame;
99
100         for (i = 0, e = effect;i < MAX_EFFECTS;i++, e++)
101         {
102                 if (e->active)
103                 {
104                         frame = (cl.time - e->starttime) * e->framerate + e->startframe;
105                         intframe = frame;
106                         if (intframe < 0 || intframe >= e->endframe)
107                         {
108                                 e->active = false;
109                                 memset(e, 0, sizeof(*e));
110                                 continue;
111                         }
112
113                         if (intframe != e->frame)
114                         {
115                                 e->frame = intframe;
116                                 e->frame1time = e->frame2time;
117                                 e->frame2time = cl.time;
118                         }
119
120                         if ((vis = CL_NewTempEntity()))
121                         {
122                                 // interpolation stuff
123                                 vis->render.frame1 = intframe;
124                                 vis->render.frame2 = intframe + 1;
125                                 if (vis->render.frame2 >= e->endframe)
126                                         vis->render.frame2 = -1; // disappear
127                                 vis->render.framelerp = frame - intframe;
128                                 vis->render.frame1time = e->frame1time;
129                                 vis->render.frame2time = e->frame2time;
130
131                                 // normal stuff
132                                 VectorCopy(e->origin, vis->render.origin);
133                                 vis->render.model = cl.model_precache[e->modelindex];
134                                 vis->render.frame = vis->render.frame2;
135                                 vis->render.colormap = -1; // no special coloring
136                                 vis->render.scale = 1;
137                                 vis->render.alpha = 1;
138                                 vis->render.colormod[0] = vis->render.colormod[1] = vis->render.colormod[2] = 1;
139                         }
140                 }
141         }
142 }