Debian Codegraph @

Descent3/cockpit.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/cockpit.cpp $
21 * $Revision: 50 $
22 * $Date: 8/10/99 5:10p $
23 * $Author: Jeff $
24 *
25 * Cockpit code
26 *
27 * $Log: /DescentIII/main/cockpit.cpp $
28 *
29 * 50 8/10/99 5:10p Jeff
30 * added missing call to FreeReticle()
31 *
32 * 49 7/28/99 4:21p Kevin
33 * Mac!
34 *
35 * 48 5/10/99 10:17p Ardussi
36 * changes to compile on Mac
37 *
38 * 47 5/05/99 5:48p Samir
39 * initialize reticle in InitCockpit.
40 *
41 * 46 4/21/99 2:15p Samir
42 * table file filter fixes.
43 *
44 * 45 4/17/99 5:43a Jeff
45 * Changes to get it to compile in Linux
46 *
47 * 44 4/06/99 1:50p Jason
48 * added new mass driver effect
49 *
50 * 43 4/01/99 4:50p Matt
51 * Took out Warning() function, chaning those calls to mprintf()
52 *
53 * 42 3/30/99 2:39p Samir
54 * added custom config file for fullscreen hud and hacked mass driver
55 * reticle in special reticle code.
56 *
57 * 41 3/23/99 10:25a Samir
58 * shake cockpit a little more.
59 *
60 * 40 2/11/99 8:28p Matt
61 * Fixed stupid bugs
62 *
63 * 39 2/11/99 4:02p Matt
64 * Flaged a bunch of files for TableParse
65 *
66 * 38 2/05/99 7:03p Jeff
67 * table file parsing macros put in
68 *
69 * 37 1/31/99 7:25p Matt
70 * Renamed a bunch of functions to have HUD capitalized
71 *
72 * 36 10/20/98 12:42p Matt
73 * Made the small views work on the cockpit.
74 *
75 * 35 10/14/98 1:02p Jason
76 * fixed FindSoundName issues
77 *
78 * 34 9/03/98 4:26p Samir
79 * gauges are off this time until cockpit is in functional mode.
80 *
81 * 33 8/28/98 11:54a Samir
82 * turn on monitors only if the cockpit is on.
83 *
84 * 32 8/19/98 5:47p Samir
85 * increased cockpit spee.d
86 *
87 * 31 8/18/98 1:11a Samir
88 * fixed some stuff for multi cockpit configs.
89 *
90 * 30 7/28/98 5:39p Samir
91 * basic cockpit sounds. need work on sync.
92 *
93 * 29 6/24/98 1:11p Samir
94 * dont draw monitors
95 *
96 * 28 6/19/98 4:14p Jason
97 * made multicolor lighting work with volume lights
98 *
99 * 27 6/15/98 4:00p Jason
100 * replaced monochromatic polymodel lighting with rgb lighting
101 *
102 * 26 6/12/98 5:13p Jason
103 * made cockpit work with dynamic lighting system
104 *
105 * 25 5/26/98 10:47p Samir
106 * cockpit shake a little better.
107 *
108 * 24 5/26/98 5:05p Samir
109 * cockpit and hud config file now 'unified'. cockpit adds to hudconfig
110 * load's funtionality, so cockpit info files can contain same syntax as
111 * hud file.
112 *
113 * 23 5/22/98 6:26p Samir
114 * cockpit lighting primatives.
115 *
116 * 22 5/18/98 5:29p Samir
117 * don't move cockpit while moving.
118 *
119 * 21 5/18/98 4:52p Samir
120 * refined cockpit motion.
121 *
122 * 20 5/15/98 12:01p Samir
123 * cockpit buffet more jarring. fixed red crap bug.
124 *
125 * 19 5/14/98 7:40p Samir
126 * shaking cockpit.
127 *
128 * 18 5/14/98 12:07p Sean
129 * Removed an annoying mprintf
130 *
131 * 17 5/13/98 4:01p Samir
132 * cockpit closing and opening secure.
133 *
134 * 16 5/05/98 6:27p Samir
135 * function that tells the cockpit system that it was resized
136 *
137 * 15 5/01/98 4:24p Samir
138 * added function to quickly open the cockpit.
139 *
140 * 14 4/24/98 8:02a Samir
141 * simpler cockpit animation.
142 *
143 * 13 4/23/98 4:13a Samir
144 * new hud system.
145 *
146 * 12 4/06/98 7:35p Samir
147 * added glare over monitor effect.
148 *
149 * 11 4/02/98 3:54p Jason
150 * first pass in getting polymodel paging to work
151 *
152 * 10 3/27/98 11:59a Samir
153 * moved weapon hud text from hud to weapon monitor gauges.
154 *
155 * 9 3/25/98 11:59a Samir
156 * implemented energy analog fully.
157 *
158 * 8 3/24/98 4:28p Samir
159 * fixed bug when calling OpenCockpit immediately after calling
160 * CloseCockpit.
161 *
162 * 7 3/23/98 11:14a Samir
163 * maybe better cockpit lighting.
164 *
165 * 6 3/22/98 5:03p Samir
166 * updated cockpit.
167 *
168 * 5 3/20/98 8:23p Samir
169 * new hud and cockpit customization system.
170 *
171 * 4 3/18/98 6:24p Samir
172 * Better view eye positioning for cockpit.
173 *
174 * 3 3/17/98 2:40p Samir
175 * reorg of cockpit/gauges and hud systems.
176 *
177 * 2 3/16/98 3:30p Samir
178 * incremental checkin.
179 *
180 * 1 3/13/98 11:22a Samir
181 * initial revision.
182 *
183 * $NoKeywords: $
184 */
185 // D3 Cockpit system
186 // needs a model with textures.
187 // major functions:
188 // activate cockpit
189 // render cockpit
190 // deactivate cockpit.
191 #include "cockpit.h"
192 #include "game.h"
193 #include "polymodel.h"
194 #include "hud.h"
195 #include "gauges.h"
196 #include "ship.h"
197 #include "player.h"
198 #include "room.h"
199 #include "hlsoundlib.h"
200 #include "soundload.h"
201 #include "sounds.h"
202
203 #include <string.h>
204
205 #include <algorithm>
206
207 #define COCKPIT_ANIM_TIME 2.0f
208 #define COCKPIT_DORMANT_FRAME 0.0
209 #define COCKPIT_START_FRAME 3.0
210 #define COCKPIT_MIDWAY_FRAME 7.0
211 #define COCKPIT_COMPLETE_FRAME ((float)Cockpit_info.model->frame_max)
212 // cockpit FX modifiers
213 #define MAX_BUFFET_STRENGTH 0.75f
214 #define BUFFET_PERIOD 0.25f
215 #define COCKPIT_SHIFT_DELTA 0.02f
216 struct tCockpitCfgInfo {
217 char modelname[PSFILENAME_LEN + 1];
218 char shieldrings[NUM_SHIELD_GAUGE_FRAMES][PSFILENAME_LEN + 1];
219 char shipimg[PSFILENAME_LEN + 1];
220 char burnimg[PSFILENAME_LEN + 1];
221 char energyimg[PSFILENAME_LEN + 1];
222 char invpulseimg[PSFILENAME_LEN + 1];
223 };
224
225 struct tCockpitInfo {
226 int state; // current state of cockpit on screen.
227 int ship_index; // index into ships page.
228 int model_num; // this should be retreived from the ship info.
229 int snd_open, snd_close; // sound open and close.
230 float frame_time; // current time of animation.
231 float next_keyframe, this_keyframe; // current animation of cockpit.
232 poly_model *model; // model of cockpit.
233 unsigned nonlayered_mask; // non layered submodel mask
234 unsigned layered_mask; // layered submodel mask
235 bool animating; // is cockpit moving?
236 bool resized; // if cockpit is being resized....
237 vector buffet_vec; // buffet direction
238 float buffet_amp; // used to calculate real magnitude
239 float buffet_wave; // current sin angle of buffet
240 float buffet_time; // current position in buffet wave along time axis.
241
242 matrix orient; // orientation of cockpit
243 };
244
245 static tCockpitInfo Cockpit_info;
246 static float KeyframeAnimateCockpit();
247 // loads cockpit. model_name = NULL, then will not load in model name.
248 static void LoadCockpitInfo(const char *ckt_file, tCockpitCfgInfo *info);
249 //////////////////////////////////////////////////////////////////////////////
250 // Initializes the cockpit by loading it in and initializing all it's gauges.
251 // initialization of cockpit.
252 void InitCockpit(int ship_index) {
253 tCockpitCfgInfo cfginfo;
254 int i;
255 mprintf(0, "Initializing cockpit.\n");
256 LoadCockpitInfo(Ships[ship_index].cockpit_name, &cfginfo);
257 // initialize special hud/cockpit images unique to this ship
258 for (i = 0; i < NUM_SHIELD_GAUGE_FRAMES; i++) {
259 if (cfginfo.shieldrings[i][0])
260 HUD_resources.shield_bmp[i] = bm_AllocLoadFileBitmap(IGNORE_TABLE(cfginfo.shieldrings[i]), 0);
261 }
262 HUD_resources.ship_bmp = bm_AllocLoadFileBitmap(IGNORE_TABLE(cfginfo.shipimg), 0);
263 HUD_resources.energy_bmp = bm_AllocLoadFileBitmap(IGNORE_TABLE(cfginfo.energyimg), 0);
264 HUD_resources.afterburn_bmp = bm_AllocLoadFileBitmap(IGNORE_TABLE(cfginfo.burnimg), 0);
265 HUD_resources.invpulse_bmp = bm_AllocLoadFileBitmap(IGNORE_TABLE(cfginfo.invpulseimg), 0);
266 if (cfginfo.modelname[0] == 0) {
267 Cockpit_info.model_num = -1;
268 mprintf(0, "No cockpit found for ship.\n");
269 return;
270 }
271 // initialize cockpit.
272 Cockpit_info.ship_index = ship_index;
273 Cockpit_info.model_num = LoadPolyModel(IGNORE_TABLE(cfginfo.modelname), 0);
274 Cockpit_info.model = GetPolymodelPointer(Cockpit_info.model_num);
275 Cockpit_info.frame_time = 0.0f;
276 Cockpit_info.state = COCKPIT_STATE_DORMANT;
277 Cockpit_info.this_keyframe = COCKPIT_DORMANT_FRAME;
278 Cockpit_info.next_keyframe = COCKPIT_DORMANT_FRAME;
279 Cockpit_info.resized = false;
280 Cockpit_info.buffet_amp = 0.0f;
281 Cockpit_info.snd_open = SOUND_COCKPIT;
282 vm_MakeZero(&Cockpit_info.buffet_vec);
283 // find layered submodel mask
284 Cockpit_info.layered_mask = 0x00000000;
285 Cockpit_info.nonlayered_mask = 0x00000000;
286 for (i = 0; i < Cockpit_info.model->n_models; i++) {
287 if ((Cockpit_info.model->submodel[i].flags & SOF_VIEWER) ||
288 (Cockpit_info.model->submodel[i].flags & SOF_MONITOR_MASK))
289 continue;
290 if (Cockpit_info.model->submodel[i].flags & SOF_LAYER)
291 Cockpit_info.layered_mask |= (1 << i);
292 else
293 Cockpit_info.nonlayered_mask |= (1 << i);
294 }
295 InitGauges(STAT_SHIELDS | STAT_SHIP | STAT_ENERGY | STAT_PRIMARYLOAD | STAT_SECONDARYLOAD | STAT_AFTERBURN);
296 // initialize reticle
297 FreeReticle();
298 InitReticle(-1, -1);
299 }
300 // Forces freeing of cockpit
301 void FreeCockpit() {
302 int i;
303 CloseGauges();
304
305 if (Cockpit_info.model_num > -1) {
306 FreePolyModel(Cockpit_info.model_num);
307 Cockpit_info.model = NULL;
308 Cockpit_info.model_num = -1;
309 }
310 Cockpit_info.ship_index = -1;
311 Cockpit_info.frame_time = 0.0f;
312 Cockpit_info.state = COCKPIT_STATE_DORMANT;
313 // free ship specific stuff for hud-cockpit shared.
314 bm_FreeBitmap(HUD_resources.invpulse_bmp);
315 bm_FreeBitmap(HUD_resources.afterburn_bmp);
316 bm_FreeBitmap(HUD_resources.energy_bmp);
317 for (i = 0; i < NUM_SHIELD_GAUGE_FRAMES; i++)
318 bm_FreeBitmap(HUD_resources.shield_bmp[i]);
319 bm_FreeBitmap(HUD_resources.ship_bmp);
320 }
321 // check if cockpit exists
322 bool IsValidCockpit() { return (Cockpit_info.model_num > -1) ? true : false; }
323 bool CockpitFileParse(const char *command, const char *operand, void *data) {
324 tCockpitCfgInfo *cfginf = (tCockpitCfgInfo *)data;
325 if (!strcmp(command, "ckptmodel")) {
326 // cockpit model name
327 if (cfginf)
328 strcpy(cfginf->modelname, operand);
329 } else if (!strncmp(command, "shieldimg", strlen("shieldimg"))) {
330 // cockpit shield ring names
331 char buf[16];
332 int i;
333 for (i = 0; i < NUM_SHIELD_GAUGE_FRAMES; i++) {
334 snprintf(buf, sizeof(buf), "shieldimg%d", i);
335 if (!stricmp(command, buf)) {
336 if (cfginf)
337 strcpy(cfginf->shieldrings[i], operand);
338 break;
339 }
340 }
341 } else if (!strcmp(command, "shipimg")) {
342 // ship image name
343 if (cfginf)
344 strcpy(cfginf->shipimg, operand);
345 } else if (!strcmp(command, "afterburnimg")) {
346 // ship image name
347 if (cfginf)
348 strcpy(cfginf->burnimg, operand);
349 } else if (!strcmp(command, "energyimg")) {
350 // ship image name
351 if (cfginf)
352 strcpy(cfginf->energyimg, operand);
353 } else if (!strcmp(command, "invpulseimg")) {
354 // ship image name
355 if (cfginf)
356 strcpy(cfginf->invpulseimg, operand);
357 } else if (!strcmp(command, "fullhudinf")) {
358 if (cfginf)
359 strcpy(HUD_resources.hud_inf_name, operand);
360 } else {
361 return false;
362 }
363 return true;
364 }
365 // loads pertinent information about cockpit.
366 void LoadCockpitInfo(const char *ckt_file, tCockpitCfgInfo *cfginfo) {
367 // clear out return values.
368 if (cfginfo) {
369 memset(cfginfo, 0, sizeof(tCockpitCfgInfo));
370 ASSERT(NUM_SHIELD_GAUGE_FRAMES == 5);
371 strcpy(cfginfo->shieldrings[0], TBL_GAMEFILE("shieldring01.ogf"));
372 strcpy(cfginfo->shieldrings[1], TBL_GAMEFILE("shieldring02.ogf"));
373 strcpy(cfginfo->shieldrings[2], TBL_GAMEFILE("shieldring03.ogf"));
374 strcpy(cfginfo->shieldrings[3], TBL_GAMEFILE("shieldring04.ogf"));
375 strcpy(cfginfo->shieldrings[4], TBL_GAMEFILE("shieldring05.ogf"));
376 strcpy(cfginfo->shipimg, TBL_GAMEFILE("hudship.ogf"));
377 strcpy(cfginfo->burnimg, TBL_GAMEFILE("hudburn.ogf"));
378 strcpy(cfginfo->energyimg, TBL_GAMEFILE("hudenergy.ogf"));
379 strcpy(cfginfo->invpulseimg, TBL_GAMEFILE("shieldinv.ogf"));
380 }
381 if (ckt_file[0] == 0)
382 return;
383
384 LoadHUDConfig(ckt_file, CockpitFileParse, cfginfo);
385 }
386 // forces opening of cockpit.
387 void OpenCockpit() {
388 // this should allow for opening cockpit while in closing mode.
389 // do this to insure that an immediate call to CloseCockpit will force it to close again.
390 if (Cockpit_info.this_keyframe <= COCKPIT_COMPLETE_FRAME) {
391 Cockpit_info.state = COCKPIT_STATE_QUASI;
392 Cockpit_info.this_keyframe = COCKPIT_DORMANT_FRAME;
393 Cockpit_info.next_keyframe = COCKPIT_COMPLETE_FRAME;
394 if (Cockpit_info.frame_time > 0.0f)
395 Cockpit_info.frame_time = COCKPIT_ANIM_TIME - Cockpit_info.frame_time;
396 }
397 Sound_system.Play2dSound(Cockpit_info.snd_open);
398 // load hud information for cockpit.
399 LoadCockpitInfo(Ships[Cockpit_info.ship_index].cockpit_name, NULL);
400 }
401 // forces complete closing of cockpit
402 void CloseCockpit() {
403 // this should allow for closing cockpit while in opening mode.
404 // do this to insure that an immediate call to OpenCockpit will force it to open again.
405 if (Cockpit_info.this_keyframe >= COCKPIT_DORMANT_FRAME) {
406 Cockpit_info.next_keyframe = COCKPIT_DORMANT_FRAME;
407 Cockpit_info.this_keyframe = COCKPIT_COMPLETE_FRAME;
408 if (Cockpit_info.frame_time > 0.0f)
409 Cockpit_info.frame_time = COCKPIT_ANIM_TIME - Cockpit_info.frame_time;
410 }
411 FlagGaugesNonfunctional(STAT_ALL);
412 Sound_system.Play2dSound(Cockpit_info.snd_open);
413 }
414 // forces quick opening of cockpit
415 void QuickOpenCockpit() {
416 Cockpit_info.frame_time = 0.0f;
417 Cockpit_info.state = COCKPIT_STATE_FUNCTIONAL;
418 Cockpit_info.this_keyframe = Cockpit_info.next_keyframe = COCKPIT_COMPLETE_FRAME;
419 FlagGaugesFunctional(STAT_ALL);
420 // load hud information for cockpit.
421 LoadCockpitInfo(Ships[Cockpit_info.ship_index].cockpit_name, NULL);
422 }
423 // forces quick closing of cockpit
424 void QuickCloseCockpit() {
425 Cockpit_info.frame_time = 0.0f;
426 Cockpit_info.state = COCKPIT_STATE_DORMANT;
427 Cockpit_info.this_keyframe = Cockpit_info.next_keyframe = COCKPIT_DORMANT_FRAME;
428 FlagGaugesNonfunctional(STAT_ALL);
429 }
430 // resizes cockpit.
431 void ResizeCockpit() { Cockpit_info.resized = true; }
432 // cockpit orientation.
433 void StartCockpitShake(float mag, vector *vec) {
434 ASSERT(vec);
435 if (mag > MAX_BUFFET_STRENGTH)
436 mag = MAX_BUFFET_STRENGTH;
437 Cockpit_info.buffet_amp = mag;
438 Cockpit_info.buffet_vec = (*vec);
439 Cockpit_info.buffet_wave = FixSin(0);
440 Cockpit_info.buffet_time = 0.0f;
441 }
442 //////////////////////////////////////////////////////////////////////////////
443 // renders the cockpit.
444 extern float GetTerrainDynamicScalar(vector *pos, int seg);
445 extern void GetRoomDynamicScalar(vector *pos, room *rp, float *r, float *g, float *b);
446 void RenderCockpit() {
447 object *player_obj = &Objects[Players[Player_num].objnum];
448 physics_info *player_phys = &player_obj->mtype.phys_info;
449 vector view_pos, light_vec;
450 matrix view_tmat;
451 float view_z, view_y, view_x, keyframe;
452 float light_scalar_r, light_scalar_g, light_scalar_b;
453 float normalized_time[MAX_SUBOBJECTS];
454 bool gauge_reset = false;
455 // draw cockpit depending on current state
456 if (Cockpit_info.state == COCKPIT_STATE_DORMANT || Cockpit_info.model_num == -1)
457 return;
458 // position cockpit correctly.
459 bsp_info *viewer_subobj = CockpitGetMonitorSubmodel(SOF_VIEWER);
460 if (!viewer_subobj) {
461 mprintf(0, "Cockpit missing viewer!\n");
462 return;
463 }
464 view_z =
465 viewer_subobj->offset.z - Cockpit_info.buffet_vec.z * Cockpit_info.buffet_amp * Cockpit_info.buffet_wave * 1.1f;
466 view_y = viewer_subobj->offset.y + Cockpit_info.buffet_vec.y * Cockpit_info.buffet_amp * Cockpit_info.buffet_wave;
467 view_x = viewer_subobj->offset.x + Cockpit_info.buffet_vec.x * Cockpit_info.buffet_amp * Cockpit_info.buffet_wave;
468 //@@ if (player_phys->rotthrust.x !=0.0f || player_phys->rotthrust.y != 0.0f) {
469 //@@ gauge_reset = true;
470 //@@ view_x += (player_phys->rotthrust.y*COCKPIT_SHIFT_DELTA/player_phys->full_rotthrust);
471 //@@ view_y -= (player_phys->rotthrust.x*COCKPIT_SHIFT_DELTA/player_phys->full_rotthrust);
472 //@@ }
473 // create new orientation, so the cockpit should be facing the viewer
474 view_tmat = Viewer_object->orient;
475 view_pos = (view_tmat.fvec * view_z) + (view_tmat.uvec * view_y) + (view_tmat.rvec * view_x) + Viewer_object->pos;
476 view_tmat.fvec = -view_tmat.fvec;
477 view_tmat.rvec = -view_tmat.rvec;
478 // lighting.
479 light_vec = -Viewer_object->orient.uvec;
480 if (OBJECT_OUTSIDE(player_obj)) {
481 float light_scalar = GetTerrainDynamicScalar(&player_obj->pos, CELLNUM(player_obj->roomnum));
482 light_scalar_r = light_scalar;
483 light_scalar_g = light_scalar;
484 light_scalar_b = light_scalar;
485 } else {
486 GetRoomDynamicScalar(&player_obj->pos, &Rooms[player_obj->roomnum], &light_scalar_r, &light_scalar_g,
487 &light_scalar_b);
488 }
489 if (light_scalar_r < 0.1f)
490 light_scalar_r = 0.1f;
491 if (light_scalar_g < 0.1f)
492 light_scalar_g = 0.1f;
493 if (light_scalar_b < 0.1f)
494 light_scalar_b = 0.1f;
495 // Samir, I moved this from the DrawPolygonModel call below -JL
496 light_scalar_r *= .8f;
497 light_scalar_g *= .8f;
498 light_scalar_b *= .8f;
499
500 if (player_obj->effect_info) {
501 light_scalar_r = std::min(1.0f, light_scalar_r + (player_obj->effect_info->dynamic_red));
502 light_scalar_g = std::min(1.0f, light_scalar_g + (player_obj->effect_info->dynamic_green));
503 light_scalar_b = std::min(1.0f, light_scalar_b + (player_obj->effect_info->dynamic_blue));
504 }
505 if (Players[player_obj->id].flags & PLAYER_FLAGS_HEADLIGHT) {
506 light_scalar_r = 1.0;
507 light_scalar_g = 1.0;
508 light_scalar_b = 1.0;
509 }
510
511 // animate and draw
512 keyframe = KeyframeAnimateCockpit();
513 SetNormalizedTimeAnim(keyframe, normalized_time, Cockpit_info.model);
514 // must put after animation.
515 if (Cockpit_info.buffet_amp > 0.04f) {
516 angle buffet_angle;
517 Cockpit_info.buffet_time += Frametime;
518 if (Cockpit_info.buffet_time > BUFFET_PERIOD) {
519 Cockpit_info.buffet_time = 0.0f;
520 Cockpit_info.buffet_amp *= 0.5f;
521 }
522 buffet_angle = (angle)(65536.0 * Cockpit_info.buffet_time /
523 (BUFFET_PERIOD - ((BUFFET_PERIOD - Cockpit_info.buffet_time) * 0.5f)));
524 Cockpit_info.buffet_wave = FixSin(buffet_angle);
525 if (Cockpit_info.buffet_wave > 0.5f)
526 Cockpit_info.buffet_wave = 1.0f;
527 else if (Cockpit_info.buffet_wave < -0.5f)
528 Cockpit_info.buffet_wave = -1.0f;
529 else
530 Cockpit_info.buffet_wave = 0.0f;
531 Cockpit_info.animating = true;
532 } else if (Cockpit_info.buffet_amp > 0.0f) {
533 Cockpit_info.animating = true;
534 Cockpit_info.buffet_amp = 0.0f;
535 }
536 // draws lower z cockpit, and monitor glares after gauge renderering
537 rend_SetZBufferState(0);
538 DrawPolygonModel(&view_pos, &view_tmat, Cockpit_info.model_num, normalized_time, 0, &light_vec, light_scalar_r,
539 light_scalar_g, light_scalar_b, Cockpit_info.nonlayered_mask, 0, 1);
540 RenderGauges(&view_pos, &view_tmat, normalized_time, (Cockpit_info.animating || Cockpit_info.resized), gauge_reset);
541 rend_SetZBufferState(0);
542 DrawPolygonModel(&view_pos, &view_tmat, Cockpit_info.model_num, normalized_time, 0, &light_vec, light_scalar_r,
543 light_scalar_g, light_scalar_b, Cockpit_info.layered_mask, 0, 1);
544
545 Cockpit_info.resized = false;
546 }
547 //////////////////////////////////////////////////////////////////////////////
548 //
549 // adjusts current keyframe and dormancy
550 float KeyframeAnimateCockpit() {
551 float newkeyframe;
552
553 newkeyframe = Cockpit_info.this_keyframe + (Cockpit_info.next_keyframe - Cockpit_info.this_keyframe) *
554 (Cockpit_info.frame_time / COCKPIT_ANIM_TIME);
555 // mprintf(0, "this=%.1f next=%.1f ft=%.1f\n", Cockpit_info.this_keyframe, Cockpit_info.next_keyframe, Cockpit_info.frame_time)); // going up in keyframes
556 if (Cockpit_info.this_keyframe < Cockpit_info.next_keyframe) {
557 if (newkeyframe >= Cockpit_info.next_keyframe) {
558 Cockpit_info.frame_time = 0.0f;
559 Cockpit_info.this_keyframe = Cockpit_info.next_keyframe;
560 }
561 }
562 // going down in keyframes
563 else if (Cockpit_info.this_keyframe > Cockpit_info.next_keyframe) {
564 if (newkeyframe <= Cockpit_info.next_keyframe) {
565 Cockpit_info.frame_time = 0.0f;
566 Cockpit_info.this_keyframe = Cockpit_info.next_keyframe;
567 }
568 } else {
569 Cockpit_info.animating = false;
570 return newkeyframe;
571 }
572
573 // decide if we can process cockpit
574 Cockpit_info.animating = true;
575 if (Cockpit_info.this_keyframe != Cockpit_info.next_keyframe) {
576 Cockpit_info.frame_time += Frametime;
577 }
578 if (Cockpit_info.this_keyframe == COCKPIT_COMPLETE_FRAME &&
579 Cockpit_info.next_keyframe == Cockpit_info.this_keyframe) {
580 FlagGaugesFunctional(STAT_ALL);
581 Cockpit_info.state = COCKPIT_STATE_FUNCTIONAL;
582 } else if (Cockpit_info.this_keyframe == COCKPIT_DORMANT_FRAME &&
583 Cockpit_info.next_keyframe == COCKPIT_DORMANT_FRAME) {
584 Cockpit_info.state = COCKPIT_STATE_DORMANT;
585 } else {
586 Cockpit_info.state = COCKPIT_STATE_QUASI;
587 }
588 return newkeyframe;
589 }
590 //////////////////////////////////////////////////////////////////////////////
591 //
592 // returns the submodel number of the monitor requested
593 bsp_info *CockpitGetMonitorSubmodel(uint16_t monitor_flag) {
594 int i;
595 ASSERT(Cockpit_info.model_num > -1);
596 for (i = 0; i < Poly_models[Cockpit_info.model_num].n_models; i++) {
597 if (Poly_models[Cockpit_info.model_num].submodel[i].flags & monitor_flag)
598 return &Poly_models[Cockpit_info.model_num].submodel[i];
599 }
600 return NULL;
601 }
602 // returns the polymodel for the hud
603 poly_model *CockpitGetPolyModel() {
604 ASSERT(Cockpit_info.model_num > -1);
605
606 return &Poly_models[Cockpit_info.model_num];
607 }
608 // Tell whether the cockpit is animating
609 int CockpitState() { return Cockpit_info.state; }