Debian Codegraph @

Descent3/NewPyroGauges.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * 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, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/NewPyroGauges.cpp $
21 * $Revision: 10 $
22 * $Date: 4/17/99 6:15p $
23 * $Author: Samir $
24 *
25 * New Pyro GX Gauge rendering functions
26 *
27 * $Log: /DescentIII/main/NewPyroGauges.cpp $
28 *
29 * 10 4/17/99 6:15p Samir
30 * replaced gr.h with grdefs.h and fixed resulting compile bugs.
31 *
32 * 9 12/29/97 5:44p Samir
33 * Took out references to grViewport and old 2d library.
34 *
35 * 8 11/17/97 10:49a Samir
36 * Fadeouts and Fadeins 90% working.
37 *
38 * 7 11/16/97 6:56p Samir
39 * Started fade out system for weapon gauges. Also put name of weapon in
40 * box.
41 *
42 * 6 11/14/97 5:30p Samir
43 * Now we get more information about the gauge's world position.
44 *
45 * 5 11/14/97 12:54p Samir
46 * Bad shield ring gauge.
47 *
48 * 4 11/11/97 1:27p Samir
49 * Weapon gauges partially working. Still needs work.
50 *
51 * 3 11/04/97 7:27p Jason
52 * made shield ring draw correctly
53 *
54 * 2 11/04/97 6:24p Samir
55 * Semi functioning shield gauges.
56 *
57 * 1 10/30/97 3:27p Samir
58 * Initial revision
59 *
60 * $NoKeywords: $
61 */
62
63 #include "NewPyroGauges.h"
64 #include "gauges.h"
65 #include "gamefont.h"
66 #include "game.h"
67 #include "hud.h"
68 #include "grdefs.h"
69 #include "bitmap.h"
70 #include "player.h"
71 #include "polymodel.h"
72 #include "3d.h"
73 #include "renderer.h"
74 #include "gametexture.h"
75
76 // how long it takes for a weapon gauge to fade out/in
77 #define GAUGE_WEAPON_FADE_TIME 1.0f
78
79 //////////////////////////////////////////////////////////////////////////////
80
81 static struct {
82 int ringbmp;
83 } NewPyroGaugeData;
84
85 //////////////////////////////////////////////////////////////////////////////
86
87 void GetCenterPoint(int *x, int *y, vector *wpos);
88
89 void NewPyroInitGauges() {
90 int texhandle;
91 texhandle = FindTextureName("GaugeShieldRing");
92 if (texhandle == -1) {
93 Int3(); // Samir.
94 NewPyroGaugeData.ringbmp = -1;
95 return;
96 } else {
97 NewPyroGaugeData.ringbmp = GetTextureBitmap(texhandle, 0);
98 }
99 }
100
101 //////////////////////////////////////////////////////////////////////////////
102 // Energy gauges
103
104 // shield gauge handler
105 void NewPyroShieldGauge(tGauge *gauge, tGaugePos *pos) {
106 // we need to get the rectangular position in screen coords of the submodel for this gauge.
107 // find center point of face/polygon.
108 //@@ int cx, cy,x,y;
109 //@@ char str[8];
110 //@@
111 //@@ GetCenterPoint(&cx, &cy, &pos->center);
112
113 //@@ START_TEXT_BLOCK_ALPHA(0.7f)
114 //@@ {
115 //@@ int text_spacing = parentvp->get_text_spacing();
116 //@@ parentvp->set_font("small");
117 //@@ parentvp->set_text_color(GR_RGB(255,128,128));
118 //@@ parentvp->set_text_spacing(0);
119 //@@ rend_SetCharacterParameters (parentvp->get_text_color(), parentvp->get_text_color(),
120 // parentvp->get_text_color(), parentvp->get_text_color());
121 //@@ sprintf(str, "%d", (int)Players[Player_num].shields);
122 //@@ x = cx - (parentvp->get_text_line_width(str)/2);
123 //@@ y = cy - (parentvp->get_current_font_height()/2);
124 //@@ parentvp->printf(x,y,str);
125 //@@ parentvp->set_text_spacing(text_spacing);
126 //@@ }
127 //@@ END_TEXT_BLOCK
128 }
129
130 #define NUM_SHIELD_SEGMENTS 36
131
132 float Zfactor = 2.0f;
133
134 // ship status gauge
135 void NewPyroShipGauge(tGauge *gauge, tGaugePos *pos) {
136 // we should draw at least an octogonal polygon with the shield gauge texture.
137 //@@ g3Point inner_points[NUM_SHIELD_SEGMENTS];
138 //@@ g3Point outer_points[NUM_SHIELD_SEGMENTS];
139 //@@ g3Point center_pnt;
140 //@@ g3Point *pntlist[4];
141 //@@ poly_model *pm = HudGetPolyModel();
142 //@@ bsp_info *sm = &pm->submodel[gauge->submodel];
143 //@@
144 //@@ float lifenorm, outoffset, zdepth, zdiff;
145 //@@ int ring_increment, ring_angle;
146 //@@ int num_segs, i;
147 //@@ int bmphandle = NewPyroGaugeData.ringbmp;
148 //@@
149 //@@// determine depth of ring.
150 //@@ lifenorm = Players[Player_num].shields/(float)INITIAL_SHIELDS;
151 //@@ if (lifenorm > 1.0f) lifenorm = 1.0f;
152 //@@ outoffset = 32.0f + (lifenorm * 16.0f);
153 //@@
154 //@@// prepare renderer
155 //@@ rend_SetLighting(LS_NONE);
156 //@@ rend_SetTextureType (TT_LINEAR);
157 //@@ rend_SetAlphaType (AT_CONSTANT+AT_TEXTURE);
158 //@@ rend_SetAlphaValue (0.75f * 255);
159 //@@ rend_SetZBufferState (0);
160 //@@
161 //@@// do 3d stuff
162 //@@ g3_RotatePoint (&center_pnt,&pos->center);
163 //@@ g3_ProjectPoint (&center_pnt);
164 //@@
165 //@@ num_segs=NUM_SHIELD_SEGMENTS;
166 //@@ ring_increment=65536/num_segs;
167 //@@ ring_angle=0;
168 //@@ zdiff = (sm->max.z - sm->min.z);
169 //@@
170 //@@ for (i=0;i<num_segs;i++,ring_angle+=ring_increment)
171 //@@ {
172 //@@ float ring_sin=FixSin(ring_angle);
173 //@@ float ring_cos=FixCos(ring_angle);
174
175 //@@//@@ inner_points[i].p3_x = center_pnt.p3_x + ring_cos*1.5;
176 //@@//@@ inner_points[i].p3_y = center_pnt.p3_y + ring_sin*1.5;
177 //@@//@@ inner_points[i].p3_z = center_pnt.p3_z + ring_sin*zdiff;
178 //@@//@@ inner_points[i].p3_codes = 0;
179 //@@//@@ inner_points[i].p3_flags = 0;
180 //@@//@@ outer_points[i].p3_x = center_pnt.p3_x + ring_cos*(1.5f + lifenorm*1.5f);
181 //@@//@@ outer_points[i].p3_y = center_pnt.p3_y + ring_sin*(1.5f + lifenorm*1.5f);
182 //@@//@@ outer_points[i].p3_z = center_pnt.p3_z + ring_sin*zdiff;
183 //@@//@@ outer_points[i].p3_codes = 0;
184 //@@//@@ outer_points[i].p3_flags = 0;
185 //@@//@@ g3_ProjectPoint(&inner_points[i]);
186 //@@//@@ g3_ProjectPoint(&outer_points[i]);
187 //@@//@@
188 //@@//@@ inner_points[i].p3_z = 0;
189 //@@//@@ outer_points[i].p3_z = 0;
190 //@@
191 //@@ zdepth = 1.0f - (ring_sin/zdiff);
192 //@@
193 //@@ inner_points[i].p3_sx=center_pnt.p3_sx + (ring_cos*32.0f)/zdepth;
194 //@@ inner_points[i].p3_sy=center_pnt.p3_sy + (ring_sin*32.0f)/zdepth;
195 //@@
196 //@@ outer_points[i].p3_sx=center_pnt.p3_sx + (ring_cos*outoffset)/zdepth;
197 //@@ outer_points[i].p3_sy=center_pnt.p3_sy + (ring_sin*outoffset)/zdepth;
198 //@@
199 //@@ inner_points[i].p3_z=0;
200 //@@ outer_points[i].p3_z=0;
201 //@@
202 //@@ inner_points[i].p3_flags |=PF_PROJECTED;
203 //@@ outer_points[i].p3_flags |=PF_PROJECTED;
204 //@@
205 //@@ }
206 //@@
207 //@@ for (i=0;i<num_segs;i++)
208 //@@ {
209 //@@ int next=(i+1)%num_segs;
210 //@@
211 //@@ outer_points[i].p3_u=0;
212 //@@ outer_points[next].p3_u=1.0;
213 //@@ outer_points[i].p3_v=0;
214 //@@ outer_points[next].p3_v=0;
215 //@@
216 //@@ inner_points[i].p3_u=0;
217 //@@ inner_points[next].p3_u=1.0;
218 //@@ inner_points[i].p3_v=1;
219 //@@ inner_points[next].p3_v=1;
220 //@@
221 //@@ pntlist[0]=&outer_points[i];
222 //@@ pntlist[1]=&outer_points[next];
223 //@@ pntlist[2]=&inner_points[next];
224 //@@ pntlist[3]=&inner_points[i];
225 //@@
226 //@@ rend_DrawPolygon (bmphandle,pntlist,4);
227 //@@ }
228 //@@
229 //@@ rend_SetZBufferState (1);
230 }
231
232 //////////////////////////////////////////////////////////////////////////////
233 // Energy gauges
234
235 void NewPyroEnergyDigitalGauge(tGauge *gauge, tGaugePos *pos) {
236 // we need to get the rectangular position in screen coords of the submodel for this gauge.
237 // find center point of face/polygon.
238 //@@ int cx, cy,x,y;
239 //@@ char str[8];
240 //@@
241 //@@ GetCenterPoint(&cx, &cy, &pos->center);
242 //@@
243 //@@ START_TEXT_BLOCK_ALPHA(0.7f)
244 //@@ {
245 //@@ int text_spacing = parentvp->get_text_spacing();
246 //@@ parentvp->set_font("small");
247 //@@ parentvp->set_text_color(GR_RGB(192,192,128));
248 //@@ parentvp->set_text_spacing(0);
249 //@@ rend_SetCharacterParameters (parentvp->get_text_color(), parentvp->get_text_color(),
250 // parentvp->get_text_color(), parentvp->get_text_color());
251 //@@ sprintf(str, "%d", (int)Players[Player_num].energy);
252 //@@ x = cx - (parentvp->get_text_line_width(str)/2);
253 //@@ y = cy - (parentvp->get_current_font_height()/2);
254 //@@ parentvp->printf(x,y,str);
255 //@@ parentvp->set_text_spacing(text_spacing);
256 //@@ }
257 //@@ END_TEXT_BLOCK
258 }
259
260 void NewPyroEnergyAnalogGauge(tGauge *gauge, tGaugePos *pos) {}
261
262 //////////////////////////////////////////////////////////////////////////////
263 // Weapon gauges
264
265 void NewPyroPrimaryWeaponGauge(tGauge *gauge, tGaugePos *pos) {
266 //@@ static float fade_time = 0.0f;
267 //@@ static int fade_state = 0;
268 //@@ float gauge_alpha;
269 //@@ poly_model *pm;
270 //@@ bsp_info *sm;
271 //@@
272 //@@ pm = HudGetPolyModel();
273 //@@ sm = &pm->submodel[gauge->submodel];
274 //@@
275 //@@// first time initialization of gauge
276 //@@ if (!gauge->init) {
277 //@@ GameTextures[pm->textures[gauge->texindex]].bm_handle =
278 //@@ Weapons[Players[Player_num].primary_weapon].hud_image_handle;
279 //@@ fade_state = 0;
280 //@@ return;
281 //@@ }
282 //@@
283 //@@ gauge_alpha = 1.0f;
284 //@@
285 //@@// handle starting fade in and fade out.
286 //@@ if (gauge->modified) {
287 //@@ // alter texture of gauge submodel face 0 to param once faded out.
288 //@@ fade_state = 1; // go to fade out.
289 //@@ gauge->modified = false;
290 //@@ fade_time = 0.0f;
291 //@@ }
292 //@@
293 //@@// handle fade.
294 //@@ if (fade_state == 1) {
295 //@@ // fade out.
296 //@@ gauge_alpha = 1.0f - (fade_time/GAUGE_WEAPON_FADE_TIME);
297 //@@ if (fade_time >= GAUGE_WEAPON_FADE_TIME) {
298 //@@ GameTextures[pm->textures[gauge->texindex]].bm_handle =
299 //@@ Weapons[Players[Player_num].primary_weapon].hud_image_handle;
300 //@@ fade_time = 0.0f;
301 //@@ fade_state = 2; // advance to fade in
302 //@@ }
303 //@@ else
304 //@@ fade_time += Frametime;
305 //@@ GameTextures[pm->textures[gauge->texindex]].alpha = gauge_alpha;
306 //@@ }
307 //@@ else if (fade_state == 2) {
308 //@@ // fade in!
309 //@@ gauge_alpha = (fade_time/GAUGE_WEAPON_FADE_TIME);
310 //@@ if (fade_time >= GAUGE_WEAPON_FADE_TIME) {
311 //@@ fade_time = 0.0f;
312 //@@ fade_state = 0; // null fade state
313 //@@ }
314 //@@ else
315 //@@ fade_time += Frametime;
316 //@@ GameTextures[pm->textures[gauge->texindex]].alpha = gauge_alpha;
317 //@@ }
318 //@@
319 //@@// do weapon name text.
320 //@@ if (fade_state == 0) {
321 //@@ int x,y,cx,cy;
322 //@@ char str[PAGENAME_LEN];
323 //@@ GetCenterPoint(&cx, &cy, &pos->center);
324 //@@
325 //@@ START_TEXT_BLOCK_ALPHA(gauge_alpha)
326 //@@ {
327 //@@ int text_spacing = parentvp->get_text_spacing();
328 //@@ parentvp->set_font("small");
329 //@@ parentvp->set_text_color(GR_RGB(0,192,0));
330 //@@ parentvp->set_text_spacing(0);
331 //@@ rend_SetCharacterParameters (parentvp->get_text_color(), parentvp->get_text_color(),
332 // parentvp->get_text_color(), parentvp->get_text_color());
333 //@@ sprintf(str, "%s", Weapons[Players[Player_num].primary_weapon].name);
334 //@@ x = cx - (parentvp->get_text_line_width(str)/3);
335 //@@ y = cy - (parentvp->get_current_font_height()/3);
336 //@@ parentvp->printf(x,y,str);
337 //@@ parentvp->set_text_spacing(text_spacing);
338 //@@ }
339 //@@ END_TEXT_BLOCK
340 //@@ GameTextures[pm->textures[gauge->texindex]].alpha = gauge_alpha;
341 //@@ }
342 }
343
344 void NewPyroSecondaryWeaponGauge(tGauge *gauge, tGaugePos *pos) {
345 //@@ static float fade_time = 0.0f;
346 //@@ static int fade_state = 0;
347 //@@ float gauge_alpha;
348 //@@ poly_model *pm;
349 //@@ bsp_info *sm;
350 //@@
351 //@@ pm = HudGetPolyModel();
352 //@@ sm = &pm->submodel[gauge->submodel];
353 //@@
354 //@@// first time initialization of gauge
355 //@@ if (!gauge->init) {
356 //@@ GameTextures[pm->textures[gauge->texindex]].bm_handle =
357 //@@ Weapons[Players[Player_num].secondary_weapon].hud_image_handle;
358 //@@ fade_state = 0;
359 //@@ return;
360 //@@ }
361 //@@
362 //@@ gauge_alpha = 1.0f;
363 //@@
364 //@@// handle starting fade in and fade out.
365 //@@ if (gauge->modified) {
366 //@@ // alter texture of gauge submodel face 0 to param once faded out.
367 //@@ fade_state = 1; // go to fade out.
368 //@@ gauge->modified = false;
369 //@@ fade_time = 0.0f;
370 //@@ }
371 //@@
372 //@@// handle fade.
373 //@@ if (fade_state == 1) {
374 //@@ // fade out.
375 //@@ gauge_alpha = 1.0f - (fade_time/GAUGE_WEAPON_FADE_TIME);
376 //@@ if (fade_time >= GAUGE_WEAPON_FADE_TIME) {
377 //@@ GameTextures[pm->textures[gauge->texindex]].bm_handle =
378 //@@ Weapons[Players[Player_num].secondary_weapon].hud_image_handle;
379 //@@ fade_time = 0.0f;
380 //@@ fade_state = 2; // advance to fade in
381 //@@ }
382 //@@ else
383 //@@ fade_time += Frametime;
384 //@@ GameTextures[pm->textures[gauge->texindex]].alpha = gauge_alpha;
385 //@@ }
386 //@@ else if (fade_state == 2) {
387 //@@ // fade in!
388 //@@ gauge_alpha = (fade_time/GAUGE_WEAPON_FADE_TIME);
389 //@@ if (fade_time >= GAUGE_WEAPON_FADE_TIME) {
390 //@@ fade_time = 0.0f;
391 //@@ fade_state = 0; // null fade state
392 //@@ }
393 //@@ else
394 //@@ fade_time += Frametime;
395 //@@ GameTextures[pm->textures[gauge->texindex]].alpha = gauge_alpha;
396 //@@ }
397 //@@
398 //@@// do weapon name text.
399 //@@ if (fade_state == 0) {
400 //@@ int x,y,cx,cy;
401 //@@ char str[PAGENAME_LEN];
402 //@@ GetCenterPoint(&cx, &cy, &pos->center);
403 //@@
404 //@@ START_TEXT_BLOCK_ALPHA(gauge_alpha)
405 //@@ {
406 //@@ int text_spacing = parentvp->get_text_spacing();
407 //@@ parentvp->set_font("small");
408 //@@ parentvp->set_text_color(GR_RGB(0,192,0));
409 //@@ parentvp->set_text_spacing(0);
410 //@@ rend_SetCharacterParameters (parentvp->get_text_color(), parentvp->get_text_color(),
411 // parentvp->get_text_color(), parentvp->get_text_color());
412 //@@ sprintf(str, "%s", Weapons[Players[Player_num].secondary_weapon].name);
413 //@@ x = cx - (parentvp->get_text_line_width(str)/1.5f);
414 //@@ y = cy - (parentvp->get_current_font_height()/3);
415 //@@ parentvp->printf(x,y,str);
416 //@@ parentvp->set_text_spacing(text_spacing);
417 //@@ }
418 //@@ END_TEXT_BLOCK
419 //@@ GameTextures[pm->textures[gauge->texindex]].alpha = gauge_alpha;
420 //@@ }
421 }
422
423 //////////////////////////////////////////////////////////////////////////////////////////
424
425 // This function will return the center point of a flat face in global screen coordinates
426 void GetCenterPoint(int *x, int *y, vector *wpos) {
427 g3Point pt;
428
429 g3_RotatePoint(&pt, wpos);
430 g3_ProjectPoint(&pt);
431
432 *x = (int)pt.p3_sx;
433 *y = (int)pt.p3_sy;
434 }