DEADSOFTWARE

render: remove graphics data from TAnimationState
[d2df-sdl.git] / src / game / opengl / r_gfx.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../shared/a_modes.inc}
16 unit r_gfx;
18 interface
20 {
21 const
22 R_GFX_FLAME_WIDTH = 32;
23 R_GFX_FLAME_HEIGHT = 32;
24 R_GFX_SMOKE_WIDTH = 32;
25 R_GFX_SMOKE_HEIGHT = 32;
26 }
28 procedure r_GFX_Load;
29 procedure r_GFX_Free;
30 procedure r_GFX_Draw;
31 procedure r_GFX_Update;
33 procedure r_GFX_OnceAnim (AnimType, X, Y: Integer);
35 implementation
37 uses
38 {$INCLUDE ../nogl/noGLuses.inc}
39 SysUtils, Classes, Math,
40 utils,
41 g_base, r_graphics, g_options, r_animations,
42 g_game, g_textures,
43 g_gfx
44 ;
46 type
47 TOnceAnim = record
48 AnimType: Byte;
49 Alpha: Byte;
50 x, y: Integer;
51 oldX, oldY: Integer;
52 Animation: TAnimationState;
53 end;
55 var
56 OnceAnims: array of TOnceAnim = nil;
57 gfxFrames: array [0..R_GFX_LAST] of DWORD;
59 procedure r_GFX_Load;
60 begin
61 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
62 g_Frames_Get(gfxFrames[R_GFX_TELEPORT], 'FRAMES_TELEPORT');
63 g_Frames_Get(gfxFrames[R_GFX_FLAME], 'FRAMES_FLAME');
64 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_ROCKET], 'FRAMES_EXPLODE_ROCKET');
65 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BFG], 'FRAMES_EXPLODE_BFG');
66 g_Frames_Get(gfxFrames[R_GFX_BFG_HIT], 'FRAMES_BFGHIT');
67 g_Frames_Get(gfxFrames[R_GFX_FIRE], 'FRAMES_FIRE');
68 g_Frames_Get(gfxFrames[R_GFX_ITEM_RESPAWN], 'FRAMES_ITEM_RESPAWN');
69 g_Frames_Get(gfxFrames[R_GFX_SMOKE], 'FRAMES_SMOKE');
70 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_SKELFIRE], 'FRAMES_EXPLODE_SKELFIRE');
71 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_PLASMA], 'FRAMES_EXPLODE_PLASMA');
72 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BSPFIRE], 'FRAMES_EXPLODE_BSPFIRE');
73 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_IMPFIRE], 'FRAMES_EXPLODE_IMPFIRE');
74 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_CACOFIRE], 'FRAMES_EXPLODE_CACOFIRE');
75 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BARONFIRE], 'FRAMES_EXPLODE_BARONFIRE');
76 end;
78 procedure r_GFX_Free;
79 var a: Integer;
80 begin
81 g_Frames_DeleteByName('FRAMES_TELEPORT');
82 if OnceAnims <> nil then
83 begin
84 for a := 0 to High(OnceAnims) do
85 OnceAnims[a].Animation.Free();
86 OnceAnims := nil;
87 end;
88 end;
90 function FindOnceAnim (): DWORD;
91 var i: Integer;
92 begin
93 if OnceAnims <> nil then
94 for i := 0 to High(OnceAnims) do
95 if OnceAnims[i].Animation = nil then
96 begin
97 Result := i;
98 Exit;
99 end;
100 if OnceAnims = nil then
101 begin
102 SetLength(OnceAnims, 16);
103 Result := 0;
104 end
105 else
106 begin
107 Result := High(OnceAnims) + 1;
108 SetLength(OnceAnims, Length(OnceAnims) + 16);
109 end;
110 end;
112 procedure r_GFX_OnceAnim (AnimType, x, y: Integer);
113 var find_id: DWORD; a: TAnimationState; alpha: Byte;
114 begin
115 if not gpart_dbg_enabled then exit;
116 find_id := FindOnceAnim();
117 alpha := 0;
118 case AnimType of
119 R_GFX_NONE: a := nil;
120 R_GFX_TELEPORT: a := TAnimationState.Create(false, 6, 10); // !!! speed can be 3
121 R_GFX_TELEPORT_FAST:
122 begin
123 AnimType := R_GFX_TELEPORT;
124 a := TAnimationState.Create(false, 3, 10);
125 end;
126 R_GFX_FLAME: a := TAnimationState.Create(false, 3, 11);
127 R_GFX_FLAME_RAND:
128 begin
129 AnimType := R_GFX_FLAME;
130 a := TAnimationState.Create(false, 2 + Random(2), 10);
131 end;
132 R_GFX_EXPLODE_ROCKET: a := TAnimationState.Create(false, 6, 6);
133 R_GFX_EXPLODE_BFG: a := TAnimationState.Create(false, 6, 6);
134 R_GFX_BFG_HIT: a := TAnimationState.Create(false, 4, 4);
135 R_GFX_FIRE: a := TAnimationState.Create(false, 4, 8); // !!! speed can be random
136 R_GFX_ITEM_RESPAWN: a := TAnimationState.Create(false, 4, 5);
137 R_GFX_SMOKE: a := TAnimationState.Create(false, 3, 10);
138 R_GFX_SMOKE_TRANS:
139 begin
140 AnimType := R_GFX_SMOKE;
141 a := TAnimationState.Create(false, 3, 10);
142 alpha := 150;
143 end;
144 R_GFX_EXPLODE_SKELFIRE: a := TAnimationState.Create(false, 8, 3);
145 R_GFX_EXPLODE_PLASMA: a := TAnimationState.Create(false, 3, 4);
146 R_GFX_EXPLODE_BSPFIRE: a := TAnimationState.Create(false, 3, 5);
147 R_GFX_EXPLODE_IMPFIRE: a := TAnimationState.Create(false, 6, 3);
148 R_GFX_EXPLODE_CACOFIRE: a := TAnimationState.Create(false, 6, 3);
149 R_GFX_EXPLODE_BARONFIRE: a := TAnimationState.Create(false, 6, 3);
150 else
151 a := nil;
152 assert(false)
153 end;
154 OnceAnims[find_id].AnimType := AnimType;
155 OnceAnims[find_id].Alpha := alpha;
156 OnceAnims[find_id].Animation := a;
157 OnceAnims[find_id].x := x;
158 OnceAnims[find_id].y := y;
159 end;
161 procedure r_GFX_Update;
162 var a: Integer;
163 begin
164 if OnceAnims <> nil then
165 begin
166 for a := 0 to High(OnceAnims) do
167 begin
168 if OnceAnims[a].Animation <> nil then
169 begin
170 OnceAnims[a].oldx := OnceAnims[a].x;
171 OnceAnims[a].oldy := OnceAnims[a].y;
172 case OnceAnims[a].AnimType of
173 R_GFX_FLAME, R_GFX_SMOKE: (*ONCEANIM_SMOKE:*)
174 begin
175 if Random(3) = 0 then
176 OnceAnims[a].x := OnceAnims[a].x-1+Random(3);
177 if Random(2) = 0 then
178 OnceAnims[a].y := OnceAnims[a].y-Random(2);
179 end;
180 end;
181 if OnceAnims[a].Animation.Played then
182 begin
183 OnceAnims[a].Animation.Free();
184 OnceAnims[a].Animation := nil;
185 end
186 else
187 OnceAnims[a].Animation.Update();
188 end;
189 end;
190 end;
191 end;
193 procedure r_GFX_Draw;
194 var
195 a, len, fx, fy: Integer;
196 begin
197 if not gpart_dbg_enabled then exit;
199 if (Particles <> nil) then
200 begin
201 glDisable(GL_TEXTURE_2D);
202 if (g_dbg_scale < 0.6) then glPointSize(1)
203 else if (g_dbg_scale > 1.3) then glPointSize(g_dbg_scale+1)
204 else glPointSize(2);
205 glDisable(GL_POINT_SMOOTH);
207 glEnable(GL_BLEND);
208 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
210 glBegin(GL_POINTS);
212 len := High(Particles);
213 for a := 0 to len do
214 begin
215 with Particles[a] do
216 begin
217 if not alive then continue;
218 if (x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight) then
219 begin
220 fx := nlerp(oldx, x, gLerpFactor);
221 fy := nlerp(oldy, y, gLerpFactor);
222 glColor4ub(red, green, blue, alpha);
223 glVertex2f(fx+0.37, fy+0.37);
224 end;
225 end;
226 end;
228 glEnd();
230 glDisable(GL_BLEND);
231 end;
233 if (OnceAnims <> nil) then
234 begin
235 len := High(OnceAnims);
236 for a := 0 to len do
237 begin
238 if (OnceAnims[a].Animation <> nil) then
239 begin
240 with OnceAnims[a] do
241 begin
242 fx := nlerp(oldx, x, gLerpFactor);
243 fy := nlerp(oldy, y, gLerpFactor);
244 r_AnimationState_Draw(gfxFrames[AnimType], Animation, x, y, Alpha, TMirrorType.None, False);
245 end;
246 end;
247 end;
248 end;
249 end;
251 end.