DEADSOFTWARE

render: move gfx-once objects into render code
[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 const
21 R_GFX_NONE = 0;
22 R_GFX_TELEPORT = 1;
23 R_GFX_FLAME = 2;
24 R_GFX_EXPLODE_ROCKET = 3;
25 R_GFX_EXPLODE_BFG = 4;
26 R_GFX_BFG_HIT = 5;
27 R_GFX_FIRE = 6;
28 R_GFX_ITEM_RESPAWN = 7;
29 R_GFX_SMOKE = 8;
30 R_GFX_EXPLODE_SKELFIRE = 9;
31 R_GFX_EXPLODE_PLASMA = 10;
32 R_GFX_EXPLODE_BSPFIRE = 11;
33 R_GFX_EXPLODE_IMPFIRE = 12;
34 R_GFX_EXPLODE_CACOFIRE = 13;
35 R_GFX_EXPLODE_BARONFIRE = 14;
36 R_GFX_TELEPORT_FAST = 15;
37 R_GFX_SMOKE_TRANS = 16;
38 R_GFX_FLAME_RAND = 17;
39 R_GFX_LAST = 17;
41 R_GFX_FLAME_WIDTH = 32;
42 R_GFX_FLAME_HEIGHT = 32;
43 R_GFX_SMOKE_WIDTH = 32;
44 R_GFX_SMOKE_HEIGHT = 32;
46 procedure r_GFX_Load;
47 procedure r_GFX_Free;
48 procedure r_GFX_Draw;
49 procedure r_GFX_Update;
51 procedure r_GFX_OnceAnim (AnimType, X, Y: Integer);
53 implementation
55 uses
56 {$INCLUDE ../nogl/noGLuses.inc}
57 SysUtils, Classes, Math,
58 utils,
59 g_base, r_graphics, g_options, r_animations,
60 g_game, g_textures,
61 g_gfx
62 ;
64 type
65 TOnceAnim = record
66 AnimType: Byte;
67 x, y: Integer;
68 oldX, oldY: Integer;
69 Animation: TAnimationState;
70 end;
72 var
73 OnceAnims: array of TOnceAnim = nil;
74 gfxFrames: array [0..R_GFX_LAST] of DWORD;
76 procedure r_GFX_Load;
77 begin
78 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
79 g_Frames_Get(gfxFrames[R_GFX_TELEPORT], 'FRAMES_TELEPORT');
80 g_Frames_Get(gfxFrames[R_GFX_FLAME], 'FRAMES_FLAME');
81 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_ROCKET], 'FRAMES_EXPLODE_ROCKET');
82 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BFG], 'FRAMES_EXPLODE_BFG');
83 g_Frames_Get(gfxFrames[R_GFX_BFG_HIT], 'FRAMES_BFGHIT');
84 g_Frames_Get(gfxFrames[R_GFX_FIRE], 'FRAMES_FIRE');
85 g_Frames_Get(gfxFrames[R_GFX_ITEM_RESPAWN], 'FRAMES_ITEM_RESPAWN');
86 g_Frames_Get(gfxFrames[R_GFX_SMOKE], 'FRAMES_SMOKE');
87 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_SKELFIRE], 'FRAMES_EXPLODE_SKELFIRE');
88 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_PLASMA], 'FRAMES_EXPLODE_PLASMA');
89 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BSPFIRE], 'FRAMES_EXPLODE_BSPFIRE');
90 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_IMPFIRE], 'FRAMES_EXPLODE_IMPFIRE');
91 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_CACOFIRE], 'FRAMES_EXPLODE_CACOFIRE');
92 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BARONFIRE], 'FRAMES_EXPLODE_BARONFIRE');
93 end;
95 procedure r_GFX_Free;
96 var a: Integer;
97 begin
98 g_Frames_DeleteByName('FRAMES_TELEPORT');
99 if OnceAnims <> nil then
100 begin
101 for a := 0 to High(OnceAnims) do
102 OnceAnims[a].Animation.Free();
103 OnceAnims := nil;
104 end;
105 end;
107 function FindOnceAnim (): DWORD;
108 var i: Integer;
109 begin
110 if OnceAnims <> nil then
111 for i := 0 to High(OnceAnims) do
112 if OnceAnims[i].Animation = nil then
113 begin
114 Result := i;
115 Exit;
116 end;
117 if OnceAnims = nil then
118 begin
119 SetLength(OnceAnims, 16);
120 Result := 0;
121 end
122 else
123 begin
124 Result := High(OnceAnims) + 1;
125 SetLength(OnceAnims, Length(OnceAnims) + 16);
126 end;
127 end;
129 procedure r_GFX_OnceAnim (AnimType, x, y: Integer);
130 var find_id: DWORD; a: TAnimationState;
131 begin
132 if not gpart_dbg_enabled then exit;
133 find_id := FindOnceAnim();
134 case AnimType of
135 R_GFX_NONE: a := nil;
136 R_GFX_TELEPORT: a := TAnimationState.Create(false, 6, 10); // !!! speed can be 3
137 R_GFX_TELEPORT_FAST:
138 begin
139 AnimType := R_GFX_TELEPORT;
140 a := TAnimationState.Create(false, 3, 10);
141 end;
142 R_GFX_FLAME: a := TAnimationState.Create(false, 3, 11);
143 R_GFX_FLAME_RAND:
144 begin
145 AnimType := R_GFX_FLAME;
146 a := TAnimationState.Create(false, 2 + Random(2), 10);
147 end;
148 R_GFX_EXPLODE_ROCKET: a := TAnimationState.Create(false, 6, 6);
149 R_GFX_EXPLODE_BFG: a := TAnimationState.Create(false, 6, 6);
150 R_GFX_BFG_HIT: a := TAnimationState.Create(false, 4, 4);
151 R_GFX_FIRE: a := TAnimationState.Create(false, 4, 8); // !!! speed can be random
152 R_GFX_ITEM_RESPAWN: a := TAnimationState.Create(false, 4, 5);
153 R_GFX_SMOKE: a := TAnimationState.Create(false, 3, 10);
154 R_GFX_SMOKE_TRANS:
155 begin
156 AnimType := R_GFX_SMOKE;
157 a := TAnimationState.Create(false, 3, 10);
158 a.alpha := 150;
159 end;
160 R_GFX_EXPLODE_SKELFIRE: a := TAnimationState.Create(false, 8, 3);
161 R_GFX_EXPLODE_PLASMA: a := TAnimationState.Create(false, 3, 4);
162 R_GFX_EXPLODE_BSPFIRE: a := TAnimationState.Create(false, 3, 5);
163 R_GFX_EXPLODE_IMPFIRE: a := TAnimationState.Create(false, 6, 3);
164 R_GFX_EXPLODE_CACOFIRE: a := TAnimationState.Create(false, 6, 3);
165 R_GFX_EXPLODE_BARONFIRE: a := TAnimationState.Create(false, 6, 3);
166 else
167 a := nil;
168 assert(false)
169 end;
170 OnceAnims[find_id].AnimType := AnimType;
171 OnceAnims[find_id].Animation := a;
172 // OnceAnims[find_id].Animation.Blending := Anim.Blending;
173 // OnceAnims[find_id].Animation.alpha := Anim.alpha;
174 OnceAnims[find_id].x := x;
175 OnceAnims[find_id].y := y;
176 end;
178 procedure r_GFX_Update;
179 var a: Integer;
180 begin
181 if OnceAnims <> nil then
182 begin
183 for a := 0 to High(OnceAnims) do
184 begin
185 if OnceAnims[a].Animation <> nil then
186 begin
187 OnceAnims[a].oldx := OnceAnims[a].x;
188 OnceAnims[a].oldy := OnceAnims[a].y;
189 case OnceAnims[a].AnimType of
190 R_GFX_FLAME, R_GFX_SMOKE: (*ONCEANIM_SMOKE:*)
191 begin
192 if Random(3) = 0 then
193 OnceAnims[a].x := OnceAnims[a].x-1+Random(3);
194 if Random(2) = 0 then
195 OnceAnims[a].y := OnceAnims[a].y-Random(2);
196 end;
197 end;
198 if OnceAnims[a].Animation.Played then
199 begin
200 OnceAnims[a].Animation.Free();
201 OnceAnims[a].Animation := nil;
202 end
203 else
204 OnceAnims[a].Animation.Update();
205 end;
206 end;
207 end;
208 end;
210 procedure r_GFX_Draw;
211 var
212 a, len, fx, fy: Integer;
213 begin
214 if not gpart_dbg_enabled then exit;
216 if (Particles <> nil) then
217 begin
218 glDisable(GL_TEXTURE_2D);
219 if (g_dbg_scale < 0.6) then glPointSize(1)
220 else if (g_dbg_scale > 1.3) then glPointSize(g_dbg_scale+1)
221 else glPointSize(2);
222 glDisable(GL_POINT_SMOOTH);
224 glEnable(GL_BLEND);
225 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
227 glBegin(GL_POINTS);
229 len := High(Particles);
230 for a := 0 to len do
231 begin
232 with Particles[a] do
233 begin
234 if not alive then continue;
235 if (x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight) then
236 begin
237 fx := nlerp(oldx, x, gLerpFactor);
238 fy := nlerp(oldy, y, gLerpFactor);
239 glColor4ub(red, green, blue, alpha);
240 glVertex2f(fx+0.37, fy+0.37);
241 end;
242 end;
243 end;
245 glEnd();
247 glDisable(GL_BLEND);
248 end;
250 if (OnceAnims <> nil) then
251 begin
252 len := High(OnceAnims);
253 for a := 0 to len do
254 begin
255 if (OnceAnims[a].Animation <> nil) then
256 begin
257 with OnceAnims[a] do
258 begin
259 fx := nlerp(oldx, x, gLerpFactor);
260 fy := nlerp(oldy, y, gLerpFactor);
261 r_AnimationState_Draw(gfxFrames[AnimType], Animation, x, y, TMirrorType.None);
262 end;
263 end;
264 end;
265 end;
266 end;
268 end.