Debian Codegraph @

similar/main/gamerend.cpp

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20 /*
21 *
22 * Stuff for rendering the HUD
23 *
24 */
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include "timer.h"
30 #include "pstypes.h"
31 #include "console.h"
32 #include "inferno.h"
33 #include "dxxerror.h"
34 #include "gr.h"
35 #include "palette.h"
36 #include "bm.h"
37 #include "player.h"
38 #include "render.h"
39 #include "newmenu.h"
40 #include "screens.h"
41 #include "config.h"
42 #include "maths.h"
43 #include "robot.h"
44 #include "game.h"
45 #include "gauges.h"
46 #include "gamefont.h"
47 #include "newdemo.h"
48 #include "text.h"
49 #include "multi.h"
50 #include "hudmsg.h"
51 #include "endlevel.h"
52 #include "powerup.h"
53 #include "playsave.h"
54 #include "automap.h"
55 #include "mission.h"
56 #include "gameseq.h"
57 #include "args.h"
58 #include "object.h"
59
60 #include "compiler-range_for.h"
61 #include "d_levelstate.h"
62 #include "d_range.h"
63
64 #if DXX_USE_OGL
65 #include "ogl_init.h"
66 #endif
67
68 namespace dcx {
69 int netplayerinfo_on;
70 cockpit_mode_t last_drawn_cockpit = cockpit_mode_t{UINT8_MAX};
71 }
72
73 namespace dsx {
74 namespace {
75 #if DXX_BUILD_DESCENT == 1
76 static inline void game_draw_marker_message(grs_canvas &)
77 {
78 }
79 #elif DXX_BUILD_DESCENT == 2
80 static void game_draw_marker_message(grs_canvas &canvas)
81 {
82 if (MarkerState.DefiningMarkerMessage())
83 {
84 gr_set_fontcolor(canvas, BM_XRGB(0, 63, 0),-1);
85 auto &game_font = *GAME_FONT;
86 gr_printf(canvas, game_font, 0x8000, (LINE_SPACING(game_font, game_font) * 5) + FSPACY(1), "Marker: %s%c", Marker_input.data(), Marker_input[Marker_input.size() - 2] ? 0 : '_');
87 }
88 }
89 #endif
90
91 static void update_cockpits(grs_canvas &);
92 }
93 }
94
95 namespace dcx {
96
97 namespace {
98
99 static void game_draw_multi_message(grs_canvas &canvas)
100 {
101 if (!(Game_mode&GM_MULTI))
102 return;
103 const auto sending = multi_sending_message[Player_num];
104 std::array<char, 64> buffer;
105 if (sending != msgsend_state::none)
106 std::snprintf(std::data(buffer), std::size(buffer), "%s: %s_", TXT_MESSAGE, Network_message.data());
107 else if (const auto defining{multi_defining_message}; defining != multi_macro_message_index::None)
108 /* Use 1-based counting for user-visible text. */
109 std::snprintf(std::data(buffer), std::size(buffer), "%s #%d: %s_", TXT_MACRO, 1 + underlying_value(defining), Network_message.data());
110 else
111 return;
112 gr_set_fontcolor(canvas, BM_XRGB(0, 63, 0),-1);
113 auto &game_font = *GAME_FONT;
114 const auto &&y = (LINE_SPACING(game_font, game_font) * 5) + FSPACY(1);
115 gr_string(canvas, game_font, 0x8000, y, std::data(buffer));
116 }
117
118 static void show_framerate(grs_canvas &canvas)
119 {
120 static int fps_count = 0, fps_rate = 0;
121 static fix64 fps_time = 0;
122 fps_count++;
123 const auto tq = timer_query();
124 if (tq >= fps_time + F1_0)
125 {
126 fps_rate = fps_count;
127 fps_count = 0;
128 fps_time += F1_0;
129 }
130 const auto &&line_spacing = LINE_SPACING(*canvas.cv_font, *GAME_FONT);
131 unsigned line_displacement;
132 switch (PlayerCfg.CockpitMode[1])
133 {
134 case cockpit_mode_t::full_cockpit:
135 line_displacement = line_spacing * 2;
136 break;
137 case cockpit_mode_t::status_bar:
138 line_displacement = line_spacing;
139 break;
140 case cockpit_mode_t::full_screen:
141 switch (PlayerCfg.HudMode)
142 {
143 case HudType::Standard:
144 line_displacement = line_spacing * 4;
145 break;
146 case HudType::Alternate1:
147 line_displacement = line_spacing * 6;
148 if (Game_mode & GM_MULTI)
149 line_displacement -= line_spacing * 4;
150 break;
151 case HudType::Alternate2:
152 line_displacement = line_spacing;
153 break;
154 case HudType::Hidden:
155 default:
156 return;
157 }
158 break;
159 case cockpit_mode_t::letterbox:
160 case cockpit_mode_t::rear_view:
161 default:
162 return;
163 }
164 const auto &game_font = *GAME_FONT;
165 gr_set_fontcolor(canvas, BM_XRGB(0, 31, 0),-1);
166 char buf[16];
167 if (CGameArg.DbgVerbose)
168 snprintf(buf, sizeof(buf), "%iFPS (%.2fms)", fps_rate, (FrameTime * 1000.) / F1_0);
169 else
170 snprintf(buf, sizeof(buf), "%iFPS", fps_rate);
171 const auto &&[w, h] = gr_get_string_size(game_font, buf);
172 const auto bm_h = canvas.cv_bitmap.bm_h;
173 gr_string(canvas, game_font, FSPACX(318) - w, bm_h - line_displacement, buf, w, h);
174 }
175
176 }
177
178 }
179
180 namespace dsx {
181
182 namespace {
183
184 static void show_netplayerinfo(grs_canvas &canvas)
185 {
186 auto &Objects = LevelUniqueObjectState.Objects;
187 auto &vcobjptr = Objects.vcptr;
188 int x{0}, y=0;
189 static const char *const eff_strings[]={"trashing","really hurting","seriously affecting","hurting","affecting","tarnishing"};
190
191 gr_set_fontcolor(canvas, 255, -1);
192
193 const auto &&fspacx = FSPACX();
194 const auto &&fspacx120 = fspacx(120);
195 const auto &&fspacy84 = FSPACY(84);
196 x = (SWIDTH / 2) - fspacx120;
197 y = (SHEIGHT / 2) - fspacy84;
198
199 gr_settransblend(canvas, gr_fade_level{14}, gr_blend::normal);
200 const uint8_t color000 = BM_XRGB(0, 0, 0);
201 gr_rect(canvas, (SWIDTH / 2) - fspacx120, (SHEIGHT / 2) - fspacy84, (SWIDTH / 2) + fspacx120, (SHEIGHT / 2) + fspacy84, color000);
202 gr_settransblend(canvas, GR_FADE_OFF, gr_blend::normal);
203
204 // general game information
205 const auto &&line_spacing = LINE_SPACING(*canvas.cv_font, *GAME_FONT);
206 y += line_spacing;
207 auto &game_font = *GAME_FONT;
208 gr_string(canvas, game_font, 0x8000, y, Netgame.game_name.data());
209 y += line_spacing;
210 gr_printf(canvas, game_font, 0x8000, y, "%s - lvl: %i", Netgame.mission_title.data(), Netgame.levelnum);
211
212 const auto &&fspacx8 = fspacx(8);
213 x += fspacx8;
214 y += line_spacing * 2;
215 const auto gamemode = underlying_value(Netgame.gamemode);
216 gr_printf(canvas, game_font, x, y, "game mode: %s", gamemode < GMNames.size() ? GMNames[gamemode] : "INVALID");
217 y += line_spacing;
218 gr_printf(canvas, game_font, x, y,"difficulty: %s", MENU_DIFFICULTY_TEXT(Netgame.difficulty));
219 y += line_spacing;
220 {
221 auto &plr = get_local_player();
222 gr_printf(canvas, game_font, x, y,"level time: %i:%02i:%02i", plr.hours_level, f2i(plr.time_level) / 60 % 60, f2i(plr.time_level) % 60);
223 y += line_spacing;
224 gr_printf(canvas, game_font, x, y,"total time: %i:%02i:%02i", plr.hours_total, f2i(plr.time_total) / 60 % 60, f2i(plr.time_total) % 60);
225 }
226 y += line_spacing;
227 if (Netgame.KillGoal)
228 gr_printf(canvas, game_font, x, y,"Kill goal: %d",Netgame.KillGoal*5);
229
230 // player information (name, kills, ping, game efficiency)
231 y += line_spacing * 2;
232 gr_string(canvas, game_font, x, y, "player");
233 gr_string(canvas, game_font, x + fspacx8 * 7, y, ((Game_mode & GM_MULTI_COOP)
234 ? "score"
235 : (gr_string(canvas, game_font, x + fspacx8 * 12, y, "deaths"), "kills")
236 ));
237 gr_string(canvas, game_font, x + fspacx8 * 18, y, "ping");
238 gr_string(canvas, game_font, x + fspacx8 * 23, y, "efficiency");
239
240 // process players table
241 for (unsigned i = 0; i < MAX_PLAYERS; ++i)
242 {
243 auto &plr = *vcplayerptr(i);
244 if (plr.connected == player_connection_status::disconnected)
245 continue;
246
247 y += line_spacing;
248
249 const auto color{get_player_or_team_color(Netgame, Game_mode, i)};
250 auto &prgb = player_rgb[color];
251 gr_set_fontcolor(canvas, BM_XRGB(prgb.r, prgb.g, prgb.b), -1);
252 gr_string(canvas, game_font, x, y, plr.callsign);
253 {
254 auto &plrobj = *vcobjptr(plr.objnum);
255 auto &player_info = plrobj.ctype.player_info;
256 auto v = ((Game_mode & GM_MULTI_COOP)
257 ? player_info.mission.score
258 : (gr_printf(canvas, game_font, x + fspacx8 * 12, y,"%-6d", player_info.net_killed_total), player_info.net_kills_total)
259 );
260 gr_printf(canvas, game_font, x + fspacx8 * 7, y, "%-6d", v);
261 }
262
263 gr_printf(canvas, game_font, x + fspacx8 * 18, y,"%-6d", Netgame.players[i].ping);
264 if (i != Player_num)
265 gr_printf(canvas, game_font, x + fspacx8 * 23, y, "%hu/%hu", kill_matrix[Player_num][i], kill_matrix[i][Player_num]);
266 }
267
268 y += (line_spacing * 2) + (line_spacing * (MAX_PLAYERS - N_players));
269
270 // printf team scores
271 if (Game_mode & GM_TEAM)
272 {
273 gr_set_fontcolor(canvas, 255, -1);
274 gr_string(canvas, game_font, x, y, "team");
275 gr_string(canvas, game_font, x + fspacx8 * 8, y, "score");
276 y += line_spacing;
277 gr_set_fontcolor(canvas, BM_XRGB(player_rgb[player_ship_color::blue].r, player_rgb[player_ship_color::blue].g, player_rgb[player_ship_color::blue].b), -1);
278 gr_printf(canvas, game_font, x, y, "%s:", Netgame.team_name[team_number::blue].operator const char *());
279 gr_printf(canvas, game_font, x + fspacx8 * 8, y, "%i", team_kills[team_number::blue]);
280 y += line_spacing;
281 gr_set_fontcolor(canvas, BM_XRGB(player_rgb[player_ship_color::red].r, player_rgb[player_ship_color::red].g, player_rgb[player_ship_color::red].b), -1);
282 gr_printf(canvas, game_font, x, y, "%s:", Netgame.team_name[team_number::red].operator const char *());
283 gr_printf(canvas, game_font, x + fspacx8 * 8, y, "%i", team_kills[team_number::red]);
284 y += line_spacing * 2;
285 }
286 else
287 y += line_spacing * 4;
288
289 gr_set_fontcolor(canvas, 255, -1);
290
291 // additional information about game - hoard, ranking
292
293 #if DXX_BUILD_DESCENT == 2
294 if (game_mode_hoard(Game_mode))
295 {
296 if (hoard_highest_record_stats.player >= Players.size())
297 gr_string(canvas, game_font, 0x8000, y, "There is no record yet for this level.");
298 else
299 gr_printf(canvas, game_font, 0x8000, y, "%s has the record at %d points.", static_cast<const char *>(vcplayerptr(hoard_highest_record_stats.player)->callsign), hoard_highest_record_stats.points);
300 }
301 else
302 #endif
303 if (!PlayerCfg.NoRankings)
304 {
305 const int ieff = (PlayerCfg.NetlifeKills + PlayerCfg.NetlifeKilled <= 0)
306 ? 0
307 : static_cast<int>(
308 static_cast<float>(PlayerCfg.NetlifeKills) / (
309 static_cast<float>(PlayerCfg.NetlifeKilled) + static_cast<float>(PlayerCfg.NetlifeKills)
310 ) * 100.0
311 );
312 const unsigned eff = ieff < 0 ? 0 : static_cast<unsigned>(ieff);
313 gr_printf(canvas, game_font, 0x8000, y, "Your lifetime efficiency of %d%% (%d/%d)", eff, PlayerCfg.NetlifeKills, PlayerCfg.NetlifeKilled);
314 y += line_spacing;
315 if (eff<60)
316 gr_printf(canvas, game_font, 0x8000, y, "is %s your ranking.", eff_strings[eff / 10]);
317 else
318 gr_string(canvas, game_font, 0x8000, y, "is serving you well.");
319 y += line_spacing;
320 gr_printf(canvas, game_font, 0x8000, y, "your rank is: %s", RankStrings[GetMyNetRanking()]);
321 }
322 }
323
324 }
325
326 }
327
328 #ifndef NDEBUG
329
330 fix Show_view_text_timer = -1;
331
332 namespace {
333
334 static void draw_window_label(object_array &Objects, grs_canvas &canvas)
335 {
336 auto &vcobjptridx = Objects.vcptridx;
337 if ( Show_view_text_timer > 0 )
338 {
339 const char *viewer_name,*control_name,*viewer_id;
340 Show_view_text_timer -= FrameTime;
341
342 viewer_id = "";
343 switch( Viewer->type )
344 {
345 case OBJ_FIREBALL: viewer_name = "Fireball"; break;
346 case OBJ_ROBOT: viewer_name = "Robot";
347 #if DXX_USE_EDITOR
348 viewer_id = Robot_names[get_robot_id(*Viewer)].data();
349 #endif
350 break;
351 case OBJ_HOSTAGE: viewer_name = "Hostage"; break;
352 case OBJ_PLAYER: viewer_name = "Player"; break;
353 case OBJ_WEAPON: viewer_name = "Weapon"; break;
354 case OBJ_CAMERA: viewer_name = "Camera"; break;
355 case OBJ_POWERUP: viewer_name = "Powerup";
356 #if DXX_USE_EDITOR
357 viewer_id = Powerup_names[get_powerup_id(*Viewer)].data();
358 #endif
359 break;
360 case OBJ_DEBRIS: viewer_name = "Debris"; break;
361 case OBJ_CNTRLCEN: viewer_name = "Reactor"; break;
362 default: viewer_name = "Unknown"; break;
363 }
364
365 switch ( Viewer->control_source) {
366 case object::control_type::None: control_name = "Stopped"; break;
367 case object::control_type::ai: control_name = "AI"; break;
368 case object::control_type::flying: control_name = "Flying"; break;
369 case object::control_type::slew: control_name = "Slew"; break;
370 case object::control_type::flythrough: control_name = "Flythrough"; break;
371 case object::control_type::morph: control_name = "Morphing"; break;
372 default: control_name = "Unknown"; break;
373 }
374
375 gr_set_fontcolor(canvas, BM_XRGB(31, 0, 0),-1);
376 auto &game_font = *GAME_FONT;
377 gr_printf(canvas, game_font, 0x8000, (SHEIGHT / 10), "%hu: %s [%s] View - %s", vcobjptridx(Viewer).get_unchecked_index(), viewer_name, viewer_id, control_name);
378
379 }
380 }
381
382 }
383 #endif
384
385 namespace dsx {
386
387 namespace {
388
389 static void render_countdown_gauge(grs_canvas &canvas)
390 {
391 auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState;
392 int Countdown_seconds_left;
393 if (!Endlevel_sequence && LevelUniqueControlCenterState.Control_center_destroyed && (Countdown_seconds_left = LevelUniqueControlCenterState.Countdown_seconds_left) > -1)
394 { // && (Countdown_seconds_left<127))
395 #if DXX_BUILD_DESCENT == 2
396 if (!is_D2_OEM && !is_MAC_SHARE && !is_SHAREWARE) // no countdown on registered only
397 {
398 // On last level, we don't want a countdown.
399 if (PLAYING_BUILTIN_MISSION && Current_level_num == Current_mission->last_level)
400 {
401 if (!(Game_mode & GM_MULTI))
402 return;
403 if (Game_mode & GM_MULTI_ROBOTS)
404 return;
405 }
406 }
407 #endif
408 gr_set_fontcolor(canvas, BM_XRGB(0, 63, 0),-1);
409 auto &game_font = *GAME_FONT;
410 gr_printf(canvas, game_font, 0x8000, (LINE_SPACING(game_font, game_font) * 6) + FSPACY(1), "T-%d s", Countdown_seconds_left);
411 }
412 }
413
414 static void game_draw_hud_stuff(const d_robot_info_array &Robot_info, grs_canvas &canvas, const control_info &Controls)
415 {
416 auto &Objects = LevelUniqueObjectState.Objects;
417 auto &vmobjptr = Objects.vmptr;
418 #ifndef NDEBUG
419 draw_window_label(Objects, canvas);
420 #endif
421
422 game_draw_multi_message(canvas);
423
424 game_draw_marker_message(canvas);
425
426 if ((Newdemo_state == ND_STATE_PLAYBACK || Newdemo_state == ND_STATE_RECORDING) && PlayerCfg.CockpitMode[1] != cockpit_mode_t::rear_view)
427 {
428 int y;
429
430 auto &game_font = *GAME_FONT;
431 gr_set_curfont(canvas, game_font);
432 gr_set_fontcolor(canvas, BM_XRGB(27, 0, 0), -1);
433
434 y = canvas.cv_bitmap.bm_h - (LINE_SPACING(*canvas.cv_font, *GAME_FONT) * 2);
435
436 if (PlayerCfg.CockpitMode[1] == cockpit_mode_t::full_cockpit)
437 y = canvas.cv_bitmap.bm_h / 1.2 ;
438 if (Newdemo_state == ND_STATE_PLAYBACK) {
439 if (Newdemo_show_percentage) {
440 gr_printf(canvas, game_font, 0x8000, y, "%s (%d%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
441 }
442 } else {
443 gr_printf(canvas, game_font, 0x8000, y, "%s (%dK)", TXT_DEMO_RECORDING, (Newdemo_num_written / 1024));
444 }
445 }
446
447 render_countdown_gauge(canvas);
448
449 if (CGameCfg.FPSIndicator && PlayerCfg.CockpitMode[1] != cockpit_mode_t::rear_view)
450 show_framerate(canvas);
451
452 auto previous_game_mode = Game_mode;
453 if (Newdemo_state == ND_STATE_PLAYBACK)
454 Game_mode = Newdemo_game_mode;
455
456 auto &plrobj = get_local_plrobj();
457 draw_hud(Robot_info, canvas, plrobj, Controls, Game_mode);
458
459 if (Newdemo_state == ND_STATE_PLAYBACK)
460 Game_mode = previous_game_mode;
461
462 if (Player_dead_state != player_dead_state::no)
463 player_dead_message(canvas);
464 }
465
466 }
467
468 #if DXX_BUILD_DESCENT == 2
469
470 ubyte RenderingType{0};
471 ubyte DemoDoingRight{0},DemoDoingLeft=0;
472
473 namespace {
474
475 constexpr weapon_box_user DemoWBUType[]={weapon_box_user::weapon, weapon_box_user::guided, weapon_box_user::missile, weapon_box_user::rear, weapon_box_user::escort, weapon_box_user::marker, weapon_box_user::weapon};
476 constexpr char DemoRearCheck[]={0,0,0,1,0,0,0};
477 constexpr char DemoExtraMessage[][10] = {
478 "PLAYER",
479 "GUIDED",
480 "MISSILE",
481 "REAR",
482 "GUIDE-BOT",
483 "MARKER",
484 "SHIP"
485 };
486
487 static const char *get_missile_name(const unsigned laser_type)
488 {
489 switch(laser_type)
490 {
491 case weapon_id_type::CONCUSSION_ID:
492 return "CONCUSSION";
493 case weapon_id_type::HOMING_ID:
494 return "HOMING";
495 case weapon_id_type::SMART_ID:
496 return "SMART";
497 case weapon_id_type::MEGA_ID:
498 return "MEGA";
499 case weapon_id_type::FLASH_ID:
500 return "FLASH";
501 case weapon_id_type::MERCURY_ID:
502 return "MERCURY";
503 case weapon_id_type::EARTHSHAKER_ID:
504 return "SHAKER";
505 default:
506 return "MISSILE"; // Bad!
507 }
508 }
509
510 static void set_missile_viewer(object &o)
511 {
512 Missile_viewer = &o;
513 Missile_viewer_sig = o.signature;
514 }
515
516 static int clear_missile_viewer()
517 {
518 if (!Missile_viewer)
519 return 0;
520 Missile_viewer = nullptr;
521 return 1;
522 }
523
524 [[nodiscard]]
525 static bool is_viewable_missile(weapon_id_type laser_type)
526 {
527 return laser_type == weapon_id_type::CONCUSSION_ID ||
528 laser_type == weapon_id_type::HOMING_ID ||
529 laser_type == weapon_id_type::SMART_ID ||
530 laser_type == weapon_id_type::MEGA_ID ||
531 laser_type == weapon_id_type::FLASH_ID ||
532 laser_type == weapon_id_type::GUIDEDMISS_ID ||
533 laser_type == weapon_id_type::MERCURY_ID ||
534 laser_type == weapon_id_type::EARTHSHAKER_ID;
535 }
536
537 static bool choose_missile_viewer()
538 {
539 auto &Objects = LevelUniqueObjectState.Objects;
540 auto &vcobjptr = Objects.vcptr;
541 auto &vmobjptr = Objects.vmptr;
542 const auto MissileViewEnabled{PlayerCfg.MissileViewEnabled};
543 if (unlikely(MissileViewEnabled == MissileViewMode::None))
544 return false;
545 const auto need_new_missile_viewer = []{
546 if (!Missile_viewer)
547 return true;
548 if (Missile_viewer->type != OBJ_WEAPON)
549 return true;
550 if (Missile_viewer->signature != Missile_viewer_sig)
551 return true;
552 /* No check on parent here. Missile_viewer is cleared if needed
553 * when a missile is fired.
554 */
555 return false;
556 };
557 if (likely(!need_new_missile_viewer()))
558 /* Valid viewer already set */
559 return true;
560 const auto better_match = [](object *const a, object &b) {
561 if (!a)
562 return true;
563 return a->lifeleft < b.lifeleft;
564 };
565 /* Find new missile */
566 object *local_player_missile = nullptr, *other_player_missile = nullptr;
567 const auto game_mode{Game_mode};
568 const auto local_player_objnum = get_local_player().objnum;
569 range_for (object &o, vmobjptr)
570 {
571 if (o.type != OBJ_WEAPON)
572 continue;
573 if (o.ctype.laser_info.parent_type != OBJ_PLAYER)
574 continue;
575 const auto laser_type = get_weapon_id(o);
576 if (!is_viewable_missile(laser_type))
577 continue;
578 if (o.ctype.laser_info.parent_num == local_player_objnum)
579 {
580 if (!better_match(local_player_missile, o))
581 continue;
582 local_player_missile = &o;
583 }
584 else
585 {
586 if (MissileViewEnabled != MissileViewMode::EnabledSelfAndAllies)
587 continue;
588 if (!better_match(other_player_missile, o))
589 continue;
590 else if (game_mode & GM_MULTI_COOP)
591 {
592 /* Always allow missiles of other players */
593 }
594 else if (game_mode & GM_TEAM)
595 {
596 /* Allow missiles from same team */
597 if (multi_get_team_from_player(Netgame, Player_num) != multi_get_team_from_player(Netgame, get_player_id(vcobjptr(o.ctype.laser_info.parent_num))))
598 continue;
599 }
600 else
601 continue;
602 other_player_missile = &o;
603 }
604 }
605 object *o;
606 if ((o = local_player_missile) != nullptr ||
607 (o = other_player_missile) != nullptr)
608 set_missile_viewer(*o);
609 else
610 return false;
611 return true;
612 }
613
614 static void show_one_extra_view(grs_canvas &canvas, const gauge_inset_window_view w);
615 static void show_extra_views(grs_canvas &canvas)
616 {
617 auto &Objects = LevelUniqueObjectState.Objects;
618 auto &vmobjptr = Objects.vmptr;
619 int did_missile_view{0};
620 int save_newdemo_state = Newdemo_state;
621 if (Newdemo_state==ND_STATE_PLAYBACK)
622 {
623 if (DemoDoLeft)
624 {
625 DemoDoingLeft=DemoDoLeft;
626
627 if (DemoDoLeft==3)
628 do_cockpit_window_view(canvas, gauge_inset_window_view::primary, *ConsoleObject, 1, weapon_box_user::rear, "REAR");
629 else
630 do_cockpit_window_view(canvas, gauge_inset_window_view::primary, DemoLeftExtra, DemoRearCheck[DemoDoLeft], DemoWBUType[DemoDoLeft], DemoExtraMessage[DemoDoLeft], DemoDoLeft == 1 ? &get_local_plrobj().ctype.player_info : nullptr);
631 }
632 else
633 do_cockpit_window_view(gauge_inset_window_view::primary, weapon_box_user::weapon);
634
635 if (DemoDoRight)
636 {
637 DemoDoingRight=DemoDoRight;
638
639 if (DemoDoRight==3)
640 do_cockpit_window_view(canvas, gauge_inset_window_view::secondary, *ConsoleObject, 1, weapon_box_user::rear, "REAR");
641 else
642 do_cockpit_window_view(canvas, gauge_inset_window_view::secondary, DemoRightExtra, DemoRearCheck[DemoDoRight], DemoWBUType[DemoDoRight], DemoExtraMessage[DemoDoRight], DemoDoLeft == 1 ? &get_local_plrobj().ctype.player_info : nullptr);
643 }
644 else
645 do_cockpit_window_view(gauge_inset_window_view::secondary, weapon_box_user::weapon);
646
647 DemoDoLeft=DemoDoRight=0;
648 DemoDoingLeft=DemoDoingRight=0;
649 return;
650 }
651
652 const auto &&gimobj = LevelUniqueObjectState.Guided_missile.get_player_active_guided_missile(vmobjptr, Player_num);
653 if (gimobj != nullptr)
654 {
655 if (PlayerCfg.GuidedInBigWindow)
656 {
657 RenderingType=6+(1<<4);
658 do_cockpit_window_view(canvas, gauge_inset_window_view::secondary, *Viewer, 0, weapon_box_user::missile, "SHIP");
659 }
660 else
661 {
662 RenderingType=1+(1<<4);
663 auto &player_info = get_local_plrobj().ctype.player_info;
664 do_cockpit_window_view(canvas, gauge_inset_window_view::secondary, *gimobj, 0, weapon_box_user::guided, "GUIDED", &player_info);
665 }
666
667 did_missile_view=1;
668 }
669 else {
670 if (choose_missile_viewer())
671 //do missile view
672 {
673 RenderingType=2+(1<<4);
674 do_cockpit_window_view(canvas, gauge_inset_window_view::secondary, *Missile_viewer, 0, weapon_box_user::missile, get_missile_name(get_weapon_id(*Missile_viewer)));
675 did_missile_view=1;
676 }
677 else {
678 if (clear_missile_viewer())
679 do_cockpit_window_view(gauge_inset_window_view::secondary, weapon_box_user::post_missile_static);
680 RenderingType=255;
681 }
682 }
683 show_one_extra_view(canvas, gauge_inset_window_view::primary);
684 if (!did_missile_view) //if showing missile view in right window, can't show anything else
685 show_one_extra_view(canvas, gauge_inset_window_view::secondary);
686 RenderingType=0;
687 Newdemo_state = save_newdemo_state;
688 }
689
690 static void show_one_extra_view(grs_canvas &canvas, const gauge_inset_window_view w)
691 {
692 auto &Objects = LevelUniqueObjectState.Objects;
693 auto &vcobjptr = Objects.vcptr;
694 auto &vmobjptridx = Objects.vmptridx;
695 auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
696 //show special views if selected
697 switch (PlayerCfg.Cockpit3DView[w]) {
698 case cockpit_3d_view::None:
699 RenderingType=255;
700 do_cockpit_window_view(w, weapon_box_user::weapon);
701 break;
702 case cockpit_3d_view::Rear:
703 RenderingType = 3 + (static_cast<unsigned>(w) << 4);
704 {
705 int rear_view_flag;
706 const char *label;
707 if (Rear_view) //if big window is rear view, show front here
708 {
709 rear_view_flag = 0;
710 label = "FRONT";
711 }
712 else //show normal rear view
713 {
714 rear_view_flag = 1;
715 label = "REAR";
716 }
717 do_cockpit_window_view(canvas, w, *ConsoleObject, rear_view_flag, weapon_box_user::rear, label);
718 }
719 break;
720 case cockpit_3d_view::Escort: {
721 const auto &&buddy = find_escort(vmobjptridx, Robot_info);
722 if (buddy == object_none) {
723 do_cockpit_window_view(w, weapon_box_user::weapon);
724 PlayerCfg.Cockpit3DView[w] = cockpit_3d_view::None;
725 }
726 else {
727 RenderingType = 4 + (static_cast<unsigned>(w) << 4);
728 do_cockpit_window_view(canvas, w, *buddy, 0, weapon_box_user::escort, PlayerCfg.GuidebotName);
729 }
730 break;
731 }
732 case cockpit_3d_view::Coop: {
733 const auto player = Coop_view_player[w];
734
735 RenderingType=255; // don't handle coop stuff
736
737 if (player < Players.size() && vcplayerptr(player)->connected != player_connection_status::disconnected && ((Game_mode & GM_MULTI_COOP) || ((Game_mode & GM_TEAM) && (multi_get_team_from_player(Netgame, player) == multi_get_team_from_player(Netgame, Player_num)))))
738 {
739 auto &p = *vcplayerptr(player);
740 do_cockpit_window_view(canvas, w, *vcobjptr(p.objnum), 0, weapon_box_user::coop, p.callsign);
741 }
742 else {
743 do_cockpit_window_view(w, weapon_box_user::weapon);
744 PlayerCfg.Cockpit3DView[w] = cockpit_3d_view::None;
745 }
746 break;
747 }
748 case cockpit_3d_view::Marker: {
749 char label[10];
750 RenderingType = 5 + (static_cast<unsigned>(w) << 4);
751 const auto mvn = Marker_viewer_num[w];
752 if (!MarkerState.imobjidx.valid_index(mvn))
753 {
754 PlayerCfg.Cockpit3DView[w] = cockpit_3d_view::None;
755 break;
756 }
757 const auto mo = MarkerState.imobjidx[mvn];
758 if (mo == object_none)
759 {
760 PlayerCfg.Cockpit3DView[w] = cockpit_3d_view::None;
761 break;
762 }
763 const auto displayed_marker_id = static_cast<unsigned>(mvn) + 1;
764 snprintf(label, sizeof(label), "Marker %u", displayed_marker_id);
765 do_cockpit_window_view(canvas, w, *vcobjptr(mo), 0, weapon_box_user::marker, label);
766 break;
767 }
768 default:
769 Int3(); //invalid window type
770 }
771 }
772
773 }
774
775 uint8_t BigWindowSwitch;
776 #endif
777
778 //render a frame for the game
779 void game_render_frame_mono(const d_robot_info_array &Robot_info, const control_info &Controls)
780 {
781 int no_draw_hud{0};
782
783 gr_set_current_canvas(Screen_3d_window);
784 {
785 auto &canvas = *grd_curcanv;
786 #if DXX_BUILD_DESCENT == 2
787 auto &Objects = LevelUniqueObjectState.Objects;
788 auto &vmobjptr = Objects.vmptr;
789 if (const auto &&gimobj = (
790 PlayerCfg.GuidedInBigWindow
791 ? LevelUniqueObjectState.Guided_missile.get_player_active_guided_missile(LevelUniqueObjectState.get_objects().vmptr, Player_num)
792 : nullptr))
793 {
794 const auto viewer_save{Viewer};
795
796 if (PlayerCfg.CockpitMode[1] == cockpit_mode_t::full_cockpit || PlayerCfg.CockpitMode[1] == cockpit_mode_t::rear_view)
797 {
798 BigWindowSwitch=1;
799 force_cockpit_redraw=1;
800 PlayerCfg.CockpitMode[1] = cockpit_mode_t::status_bar;
801 return;
802 }
803
804 Viewer = gimobj;
805
806 window_rendered_data window;
807 #if DXX_USE_STEREOSCOPIC_RENDER
808 if (VR_stereo != StereoFormat::None)
809 {
810 render_frame(canvas, -VR_eye_width, window);
811 render_frame(canvas, +VR_eye_width, window);
812 }
813 else
814 #endif
815 {
816 render_frame(canvas, 0, window);
817 }
818
819 wake_up_rendered_objects(*Viewer, window);
820 show_HUD_names(Robot_info, canvas, Game_mode);
821
822 Viewer = viewer_save;
823
824 auto &game_font = *GAME_FONT;
825 gr_set_fontcolor(canvas, BM_XRGB(27, 0, 0), -1);
826
827 gr_string(canvas, game_font, 0x8000, FSPACY(1), "Guided Missile View");
828
829 auto &player_info = get_local_plrobj().ctype.player_info;
830 show_reticle(canvas, player_info, reticle_type::cross_v1, 0);
831
832 HUD_render_message_frame(canvas);
833
834 no_draw_hud=1;
835 }
836 else
837 #endif
838 {
839 #if DXX_BUILD_DESCENT == 2
840 if (BigWindowSwitch)
841 {
842 force_cockpit_redraw=1;
843 PlayerCfg.CockpitMode[1] = (Rear_view ? cockpit_mode_t::rear_view : cockpit_mode_t::full_cockpit);
844 BigWindowSwitch=0;
845 return;
846 }
847 #endif
848 window_rendered_data window;
849 #if DXX_USE_STEREOSCOPIC_RENDER
850 if (VR_stereo != StereoFormat::None)
851 {
852 render_frame(canvas, -VR_eye_width, window);
853 render_frame(canvas, +VR_eye_width, window);
854 }
855 else
856 #endif
857 {
858 render_frame(canvas, 0, window);
859 }
860 }
861 }
862 gr_set_default_canvas();
863 {
864 auto &canvas = *grd_curcanv;
865 update_cockpits(canvas);
866
867 if (PlayerCfg.CockpitMode[1] == cockpit_mode_t::full_cockpit || PlayerCfg.CockpitMode[1] == cockpit_mode_t::status_bar)
868 render_gauges(canvas, Newdemo_state == ND_STATE_PLAYBACK ? Newdemo_game_mode : Game_mode);
869 }
870
871 if (!no_draw_hud) {
872 #if DXX_USE_STEREOSCOPIC_RENDER
873 if (VR_stereo != StereoFormat::None)
874 {
875 game_draw_hud_stuff(Robot_info, VR_hud_left, Controls);
876 game_draw_hud_stuff(Robot_info, VR_hud_right, Controls);
877 }
878 else
879 #endif
880 {
881 game_draw_hud_stuff(Robot_info, Screen_3d_window, Controls);
882 }
883 }
884
885 #if DXX_BUILD_DESCENT == 2
886 gr_set_default_canvas();
887 show_extra_views(*grd_curcanv); //missile view, buddy bot, etc.
888 #endif
889
890 if (netplayerinfo_on && Game_mode & GM_MULTI)
891 {
892 gr_set_default_canvas();
893 show_netplayerinfo(*grd_curcanv);
894 }
895 }
896
897 }
898
899 void toggle_cockpit()
900 {
901 if (Rear_view || Player_dead_state != player_dead_state::no)
902 return;
903 #if DXX_USE_STEREOSCOPIC_RENDER
904 if (VR_stereo != StereoFormat::None)
905 return;
906 #endif
907
908 auto new_mode = cockpit_mode_t::full_screen;
909
910 switch (PlayerCfg.CockpitMode[1])
911 {
912 case cockpit_mode_t::full_cockpit:
913 new_mode = cockpit_mode_t::status_bar;
914 break;
915 case cockpit_mode_t::status_bar:
916 new_mode = cockpit_mode_t::full_screen;
917 break;
918 case cockpit_mode_t::full_screen:
919 new_mode = cockpit_mode_t::full_cockpit;
920 break;
921 case cockpit_mode_t::rear_view:
922 case cockpit_mode_t::letterbox:
923 break;
924 }
925
926 select_cockpit(new_mode);
927 HUD_clear_messages();
928 PlayerCfg.CockpitMode[0] = new_mode;
929 write_player_file();
930 }
931
932 namespace dsx {
933 namespace {
934
935 // This actually renders the new cockpit onto the screen.
936 static void update_cockpits(grs_canvas &canvas)
937 {
938 const auto raw_cockpit_mode{PlayerCfg.CockpitMode[1]};
939 const auto cp_idx{
940 #if DXX_BUILD_DESCENT == 2
941 HIRESMODE
942 ? static_cast<cockpit_bitmap_index>(underlying_value(raw_cockpit_mode) + 3)
943 :
944 #endif
945 static_cast<cockpit_bitmap_index>(raw_cockpit_mode)
946 };
947
948 switch( PlayerCfg.CockpitMode[1] ) {
949 case cockpit_mode_t::full_cockpit:
950 case cockpit_mode_t::rear_view:
951 {
952 const auto bi{cockpit_bitmap[cp_idx]};
953 PIGGY_PAGE_IN(bi);
954 grs_bitmap *const bm = &GameBitmaps[bi];
955 #if DXX_USE_OGL
956 ogl_ubitmapm_cs(canvas, 0, 0, opengl_bitmap_use_dst_canvas, opengl_bitmap_use_dst_canvas, *bm, 255);
957 #else
958 gr_ubitmapm(canvas, 0, 0, *bm);
959 #endif
960 }
961 break;
962
963 case cockpit_mode_t::full_screen:
964 break;
965
966 case cockpit_mode_t::status_bar:
967 {
968 const auto bi{cockpit_bitmap[cp_idx]};
969 PIGGY_PAGE_IN(bi);
970 grs_bitmap *const bm = &GameBitmaps[bi];
971 #if DXX_USE_OGL
972 ogl_ubitmapm_cs(canvas, 0, (HIRESMODE ? (SHEIGHT * 2) / 2.6 : (SHEIGHT * 2) / 2.72), opengl_bitmap_use_dst_canvas, (static_cast<int>(static_cast<double>(bm->bm_h) * (HIRESMODE ? static_cast<double>(SHEIGHT) / 480 : static_cast<double>(SHEIGHT) / 200) + 0.5)), *bm, 255);
973 #else
974 gr_ubitmapm(canvas, 0, SHEIGHT - bm->bm_h, *bm);
975 #endif
976 }
977 break;
978
979 case cockpit_mode_t::letterbox:
980 break;
981 }
982 if (PlayerCfg.CockpitMode[1] != last_drawn_cockpit)
983 last_drawn_cockpit = PlayerCfg.CockpitMode[1];
984 else
985 return;
986
987 if (PlayerCfg.CockpitMode[1] == cockpit_mode_t::full_cockpit || PlayerCfg.CockpitMode[1] == cockpit_mode_t::status_bar)
988 init_gauges();
989
990 }
991 }
992
993 void game_render_frame(const d_robot_info_array &Robot_info, const control_info &Controls)
994 {
995 auto &Objects = LevelUniqueObjectState.Objects;
996 auto &vmobjptr = Objects.vmptr;
997 set_screen_mode( SCREEN_GAME );
998 auto &player_info = get_local_plrobj().ctype.player_info;
999 play_homing_warning(player_info);
1000 gr_set_default_canvas();
1001 game_render_frame_mono(Robot_info, Controls);
1002 }
1003
1004 }
1005
1006 //show a message in a nice little box
1007 void show_boxed_message(grs_canvas &canvas, const char *msg)
1008 {
1009 int x,y;
1010
1011 gr_set_fontcolor(canvas, BM_XRGB(31, 31, 31), -1);
1012 auto &medium1_font = *MEDIUM1_FONT;
1013 const auto &&[w, h] = gr_get_string_size(medium1_font, msg);
1014
1015 x = (SWIDTH-w)/2;
1016 y = (SHEIGHT-h)/2;
1017
1018 nm_draw_background(canvas, x - BORDERX, y - BORDERY, x + w + BORDERX, y + h + BORDERY);
1019
1020 gr_string(canvas, medium1_font, 0x8000, y, msg, w, h);
1021 }