Make game window inherit from dcx::window
This commit is contained in:
parent
b79eff0e5c
commit
0f2c1cdd45
|
@ -201,7 +201,7 @@ window_event_result event_send(const d_event &event)
|
|||
window_event_result handled = window_event_result::ignored;
|
||||
|
||||
for (wind = window_get_front(); wind && handled == window_event_result::ignored; wind = window_get_prev(*wind))
|
||||
if (window_is_visible(wind))
|
||||
if (window_is_visible(*wind))
|
||||
{
|
||||
handled = window_send_event(*wind, event);
|
||||
|
||||
|
@ -241,7 +241,7 @@ window_event_result event_process(void)
|
|||
const d_event event{EVENT_WINDOW_DRAW}; // then draw all visible windows
|
||||
for (wind = window_get_first(); wind != nullptr;)
|
||||
{
|
||||
if (window_is_visible(wind))
|
||||
if (window_is_visible(*wind))
|
||||
{
|
||||
auto prev = window_get_prev(*wind);
|
||||
auto result = window_send_event(*wind, event);
|
||||
|
|
|
@ -87,9 +87,9 @@ public:
|
|||
return w_visible;
|
||||
}
|
||||
|
||||
friend int window_is_visible(window *wind)
|
||||
friend int window_is_visible(window &wind)
|
||||
{
|
||||
return wind->is_visible();
|
||||
return wind.is_visible();
|
||||
}
|
||||
|
||||
void set_modal(int modal)
|
||||
|
|
|
@ -35,7 +35,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "fwd-object.h"
|
||||
#include "fwd-player.h"
|
||||
#include "fwd-segment.h"
|
||||
#include "fwd-window.h"
|
||||
#include "window.h"
|
||||
#include "d_array.h"
|
||||
#include "gauges.h"
|
||||
#include "wall.h"
|
||||
|
@ -51,8 +51,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#define MAXIMUM_FPS 1000
|
||||
#endif
|
||||
|
||||
extern class window *Game_wind;
|
||||
|
||||
// from mglobal.c
|
||||
namespace dcx {
|
||||
using d_time_fix = std::chrono::duration<uint32_t, std::ratio<1, F1_0>>;
|
||||
|
@ -203,6 +201,14 @@ extern int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
|
|||
|
||||
#if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
|
||||
namespace dsx {
|
||||
|
||||
struct game_window : window
|
||||
{
|
||||
using window::window;
|
||||
virtual window_event_result event_handler(const d_event &) override;
|
||||
};
|
||||
extern game_window *Game_wind;
|
||||
|
||||
void game();
|
||||
void init_game();
|
||||
void init_cockpit();
|
||||
|
@ -448,7 +454,7 @@ struct game_cheats : prohibit_void_ptr<game_cheats>
|
|||
};
|
||||
extern game_cheats cheats;
|
||||
|
||||
window *game_setup();
|
||||
game_window *game_setup();
|
||||
window_event_result game_handler(window *wind,const d_event &event, const unused_window_userdata_t *);
|
||||
window_event_result ReadControls(const d_event &event);
|
||||
bool allowed_to_fire_laser(const player_info &);
|
||||
|
|
|
@ -1142,7 +1142,7 @@ window_event_result automap::event_handler(const d_event &event)
|
|||
* Eventually, grd_curcanv will be removed entirely.
|
||||
*/
|
||||
gr_set_default_canvas();
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
Automap_active = 0;
|
||||
multi_send_msgsend_state(msgsend_none);
|
||||
return window_event_result::ignored; // continue closing
|
||||
|
@ -1181,7 +1181,7 @@ void do_automap()
|
|||
am->pause_game = !((Game_mode & GM_MULTI) && (!Endlevel_sequence)); // Set to 1 if everything is paused during automap...No pause during net.
|
||||
|
||||
if (am->pause_game) {
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -314,9 +314,9 @@ window_event_result start_endlevel_sequence()
|
|||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
if (PLAYING_BUILTIN_MISSION) // only play movie for built-in mission
|
||||
{
|
||||
window_set_visible(Game_wind, 0); // suspend the game, including drawing
|
||||
window_set_visible(*Game_wind, 0); // suspend the game, including drawing
|
||||
start_endlevel_movie();
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
}
|
||||
strcpy(last_palette_loaded,""); //force palette load next time
|
||||
#endif
|
||||
|
@ -355,9 +355,9 @@ window_event_result start_endlevel_sequence()
|
|||
if (PLAYING_BUILTIN_MISSION) // only play movie for built-in mission
|
||||
if (!(Game_mode & GM_MULTI))
|
||||
{
|
||||
window_set_visible(Game_wind, 0); // suspend the game, including drawing
|
||||
window_set_visible(*Game_wind, 0); // suspend the game, including drawing
|
||||
endlevel_movie_played = start_endlevel_movie();
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
}
|
||||
|
||||
if (!(!(Game_mode & GM_MULTI) && (endlevel_movie_played == MOVIE_NOT_PLAYED) && endlevel_data_loaded))
|
||||
|
|
|
@ -143,6 +143,9 @@ int Global_missile_firing_count = 0;
|
|||
// Function prototypes for GAME.C exclusively.
|
||||
|
||||
namespace dsx {
|
||||
|
||||
game_window *Game_wind;
|
||||
|
||||
static window_event_result GameProcessFrame(void);
|
||||
static bool FireLaser(player_info &);
|
||||
static void powerup_grab_cheat_all();
|
||||
|
@ -1524,17 +1527,15 @@ void game_disable_cheats()
|
|||
|
||||
namespace dsx {
|
||||
|
||||
window *game_setup(void)
|
||||
game_window *game_setup()
|
||||
{
|
||||
|
||||
PlayerCfg.CockpitMode[1] = PlayerCfg.CockpitMode[0];
|
||||
last_drawn_cockpit = -1; // Force cockpit to redraw next time a frame renders.
|
||||
Endlevel_sequence = 0;
|
||||
|
||||
const auto game_wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, game_handler, unused_window_userdata);
|
||||
if (!game_wind)
|
||||
return NULL;
|
||||
|
||||
auto game_wind = std::make_unique<game_window>(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT);
|
||||
game_wind->send_creation_events(nullptr);
|
||||
reset_palette_add();
|
||||
init_cockpit();
|
||||
init_gauges();
|
||||
|
@ -1557,17 +1558,15 @@ window *game_setup(void)
|
|||
fix_object_segs();
|
||||
if (CGameArg.SysAutoRecordDemo && Newdemo_state == ND_STATE_NORMAL)
|
||||
newdemo_start_recording();
|
||||
return game_wind;
|
||||
return game_wind.release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window *Game_wind = NULL;
|
||||
|
||||
namespace dsx {
|
||||
|
||||
// Event handler for the game
|
||||
window_event_result game_handler(window *,const d_event &event, const unused_window_userdata_t *)
|
||||
window_event_result game_window::event_handler(const d_event &event)
|
||||
{
|
||||
auto result = window_event_result::ignored;
|
||||
|
||||
|
@ -1657,7 +1656,6 @@ window_event_result game_handler(window *,const d_event &event, const unused_win
|
|||
key_toggle_repeat(1);
|
||||
Game_wind = nullptr;
|
||||
return window_event_result::ignored;
|
||||
break;
|
||||
|
||||
case EVENT_LOOP_BEGIN_LOOP:
|
||||
kconfig_begin_loop(Controls);
|
||||
|
|
|
@ -1308,7 +1308,7 @@ static window_event_result HandleTestKey(fvmsegptridx &vmsegptridx, int key)
|
|||
|
||||
case KEY_E + KEY_DEBUGGED:
|
||||
{
|
||||
window_set_visible(Game_wind, 0); // don't let the game do anything while we set the editor up
|
||||
window_set_visible(*Game_wind, 0); // don't let the game do anything while we set the editor up
|
||||
auto old_gamestate = gamestate;
|
||||
gamestate = editor_gamestate::unsaved; // saved game editing mode
|
||||
|
||||
|
@ -1316,7 +1316,7 @@ static window_event_result HandleTestKey(fvmsegptridx &vmsegptridx, int key)
|
|||
// If editor failed to load, carry on playing
|
||||
if (!EditorWindow)
|
||||
{
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
gamestate = old_gamestate;
|
||||
return window_event_result::handled;
|
||||
}
|
||||
|
@ -1707,9 +1707,9 @@ static window_event_result FinalCheats()
|
|||
if (item != -1) {
|
||||
new_level_num = atoi(m[0].text);
|
||||
if (new_level_num!=0 && new_level_num>=0 && new_level_num<=Last_level) {
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
StartNewLevel(new_level_num);
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1447,7 +1447,7 @@ window_event_result ExitSecretLevel()
|
|||
return window_event_result::ignored;
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
|
||||
if (!LevelUniqueControlCenterState.Control_center_destroyed)
|
||||
{
|
||||
|
@ -1477,7 +1477,7 @@ window_event_result ExitSecretLevel()
|
|||
}
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
reset_time();
|
||||
|
||||
return result;
|
||||
|
@ -1520,7 +1520,7 @@ void EnterSecretLevel(void)
|
|||
Assert(! (Game_mode & GM_MULTI) );
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
|
||||
digi_play_sample( SOUND_SECRET_EXIT, F1_0 ); // after above call which stops all sounds
|
||||
|
||||
|
@ -1559,7 +1559,7 @@ void EnterSecretLevel(void)
|
|||
|
||||
// do_cloak_invul_stuff();
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
reset_time();
|
||||
}
|
||||
#endif
|
||||
|
@ -1570,7 +1570,7 @@ window_event_result PlayerFinishedLevel(int secret_flag)
|
|||
auto &Objects = LevelUniqueObjectState.Objects;
|
||||
auto &vmobjptr = Objects.vmptr;
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
|
||||
//credit the player for hostages
|
||||
auto &player_info = get_local_plrobj().ctype.player_info;
|
||||
|
@ -1593,7 +1593,7 @@ window_event_result PlayerFinishedLevel(int secret_flag)
|
|||
auto result = AdvanceLevel(secret_flag); //now go on to the next one (if one)
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
reset_time();
|
||||
|
||||
return result;
|
||||
|
@ -1817,13 +1817,13 @@ window_event_result DoPlayerDead()
|
|||
{
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
result = AdvanceLevel(0); //if finished, go on to next level
|
||||
|
||||
init_player_stats_new_ship(Player_num);
|
||||
last_drawn_cockpit = -1;
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
}
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
} else if (Current_level_num < 0) {
|
||||
|
|
|
@ -335,7 +335,7 @@ window_event_result standard_handler(const d_event &event)
|
|||
case KEY_ALTED+KEY_ENTER:
|
||||
case KEY_ALTED+KEY_PADENTER:
|
||||
if (Game_wind)
|
||||
if (Game_wind == window_get_front())
|
||||
if (window_get_front() == Game_wind)
|
||||
return window_event_result::ignored;
|
||||
gr_toggle_fullscreen();
|
||||
#if SDL_MAJOR_VERSION == 2
|
||||
|
|
|
@ -2190,23 +2190,23 @@ int sound_menu_items::menuset(newmenu *, const d_event &event, sound_menu_items
|
|||
else if (citem == opt_sm_redbook_playorder)
|
||||
{
|
||||
GameCfg.OrigTrackOrder = items[citem].value;
|
||||
replay = (Game_wind != NULL);
|
||||
replay = static_cast<bool>(Game_wind);
|
||||
}
|
||||
#if DXX_USE_SDLMIXER
|
||||
else if (citem == opt_sm_mtype3_lmplayorder1)
|
||||
{
|
||||
CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder::Continuous;
|
||||
replay = (Game_wind != NULL);
|
||||
replay = static_cast<bool>(Game_wind);
|
||||
}
|
||||
else if (citem == opt_sm_mtype3_lmplayorder2)
|
||||
{
|
||||
CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder::Level;
|
||||
replay = (Game_wind != NULL);
|
||||
replay = static_cast<bool>(Game_wind);
|
||||
}
|
||||
else if (citem == opt_sm_mtype3_lmplayorder3)
|
||||
{
|
||||
CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder::Random;
|
||||
replay = (Game_wind != NULL);
|
||||
replay = static_cast<bool>(Game_wind);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
@ -2275,7 +2275,8 @@ void do_sound_menu()
|
|||
newmenu_do1(nullptr, "Sound Effects & Music", items.m.size(), items.m.data(), &sound_menu_items::menuset, &items, 0);
|
||||
|
||||
#if DXX_USE_SDLMIXER
|
||||
if ((Game_wind != NULL && strcmp(old_CMLevelMusicPath.data(), CGameCfg.CMLevelMusicPath.data())) || (Game_wind == NULL && strcmp(old_CMMiscMusic0.data(), CGameCfg.CMMiscMusic[SONG_TITLE].data())))
|
||||
if ((Game_wind && strcmp(old_CMLevelMusicPath.data(), CGameCfg.CMLevelMusicPath.data())) ||
|
||||
(!Game_wind && strcmp(old_CMMiscMusic0.data(), CGameCfg.CMMiscMusic[SONG_TITLE].data())))
|
||||
{
|
||||
songs_uninit();
|
||||
|
||||
|
|
|
@ -433,10 +433,10 @@ kmatrix_result multi_endlevel_score()
|
|||
// If there still is a Game_wind and it's suspended (usually both should be the case), bring it up again so host can still take actions of the game
|
||||
if (Game_wind)
|
||||
{
|
||||
if (!window_is_visible(Game_wind))
|
||||
if (!window_is_visible(*Game_wind))
|
||||
{
|
||||
game_wind_visible = 1;
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
}
|
||||
}
|
||||
// Save connect state and change to new connect state
|
||||
|
@ -502,7 +502,7 @@ kmatrix_result multi_endlevel_score()
|
|||
|
||||
// hide Game_wind again if we brought it up
|
||||
if (Game_wind && game_wind_visible)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
@ -2078,10 +2078,10 @@ void multi_disconnect_player(const playernum_t pnum)
|
|||
if (pnum == multi_who_is_master()) // Host has left - Quit game!
|
||||
{
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
nm_messagebox(NULL, 1, TXT_OK, "Host left the game!");
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
multi_quit_game = 1;
|
||||
game_leave_menus();
|
||||
return;
|
||||
|
@ -3194,10 +3194,10 @@ void multi_consistency_error(int reset)
|
|||
return;
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
count = 0;
|
||||
multi_quit_game = 1;
|
||||
game_leave_menus();
|
||||
|
|
|
@ -2932,13 +2932,13 @@ static void net_udp_process_dump(ubyte *data, int, const _sockaddr &sender_addr)
|
|||
case DUMP_PKTTIMEOUT:
|
||||
case DUMP_KICKED:
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
if (data[1] == DUMP_PKTTIMEOUT)
|
||||
nm_messagebox(NULL, 1, TXT_OK, "You were removed from the game.\nYou failed receiving important\npackets. Sorry.");
|
||||
if (data[1] == DUMP_KICKED)
|
||||
else if (data[1] == DUMP_KICKED)
|
||||
nm_messagebox(NULL, 1, TXT_OK, "You were kicked by Host!");
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
multi_quit_game = 1;
|
||||
game_leave_menus();
|
||||
break;
|
||||
|
@ -4981,10 +4981,10 @@ static void net_udp_noloss_add_queue_pkt(fix64 time, const ubyte *data, ushort d
|
|||
{
|
||||
Netgame.PacketLossPrevention = 0; // Disable PLP - otherwise we get stuck in an infinite loop here. NOTE: We could as well clean the whole queue to continue protect our disconnect signal bit it's not that important - we just wanna leave.
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
nm_messagebox(NULL, 1, TXT_OK, "You left the game. You failed\nsending important packets.\nSorry.");
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
multi_quit_game = 1;
|
||||
game_leave_menus();
|
||||
}
|
||||
|
@ -5182,10 +5182,10 @@ void net_udp_noloss_process_queue(fix64 time)
|
|||
{
|
||||
Netgame.PacketLossPrevention = 0; // Disable PLP - otherwise we get stuck in an infinite loop here. NOTE: We could as well clean the whole queue to continue protect our disconnect signal bit it's not that important - we just wanna leave.
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
nm_messagebox(NULL, 1, TXT_OK, "You left the game. You failed\nsending important packets.\nSorry.");
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 1);
|
||||
window_set_visible(*Game_wind, 1);
|
||||
multi_quit_game = 1;
|
||||
game_leave_menus();
|
||||
}
|
||||
|
|
|
@ -1806,7 +1806,7 @@ int state_restore_all_sub(const d_level_shared_destructible_light_state &LevelSh
|
|||
}
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
window_set_visible(*Game_wind, 0);
|
||||
|
||||
//Read player info
|
||||
|
||||
|
@ -2364,8 +2364,8 @@ int state_restore_all_sub(const d_level_shared_destructible_light_state &LevelSh
|
|||
else
|
||||
state_set_next_autosave(GameUniqueState, PlayerCfg.SPGameplayOptions.AutosaveInterval);
|
||||
if (Game_wind)
|
||||
if (!window_is_visible(Game_wind))
|
||||
window_set_visible(Game_wind, 1);
|
||||
if (!window_is_visible(*Game_wind))
|
||||
window_set_visible(*Game_wind, 1);
|
||||
reset_time();
|
||||
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue