From 626390c84d8d4afe64f0ee3d9811104a1c997755 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 19 Nov 2023 16:21:42 +0000 Subject: [PATCH 01/32] Use enum class for event_type --- common/arch/sdl/event.cpp | 7 +-- common/arch/sdl/joy.cpp | 32 +++++----- common/arch/sdl/key.cpp | 9 ++- common/arch/sdl/mouse.cpp | 13 ++-- common/arch/sdl/window.cpp | 23 +++---- common/arch/win32/messagebox.cpp | 5 +- common/include/event.h | 74 +++++++++++------------ common/include/fwd-event.h | 2 +- common/include/key.h | 2 +- common/include/mouse.h | 4 +- common/include/ui.h | 8 +-- common/ui/button.cpp | 10 ++-- common/ui/checkbox.cpp | 10 ++-- common/ui/dialog.cpp | 23 ++++--- common/ui/file.cpp | 8 +-- common/ui/gadget.cpp | 4 +- common/ui/icon.cpp | 11 ++-- common/ui/inputbox.cpp | 8 +-- common/ui/listbox.cpp | 9 +-- common/ui/menubar.cpp | 28 ++++----- common/ui/message.cpp | 2 +- common/ui/radio.cpp | 11 ++-- common/ui/scroll.cpp | 12 ++-- common/ui/userbox.cpp | 11 ++-- d1x-rebirth/editor/ehostage.cpp | 6 +- d2x-rebirth/main/escort.cpp | 15 ++--- d2x-rebirth/main/movie.cpp | 18 +++--- similar/editor/centers.cpp | 12 ++-- similar/editor/eswitch.cpp | 12 ++-- similar/editor/info.cpp | 5 +- similar/editor/med.cpp | 41 ++++++------- similar/editor/medrobot.cpp | 19 +++--- similar/editor/medwall.cpp | 12 ++-- similar/editor/objpage.cpp | 2 +- similar/editor/texpage.cpp | 5 +- similar/main/automap.cpp | 37 ++++++------ similar/main/console.cpp | 12 ++-- similar/main/credits.cpp | 15 +++-- similar/main/game.cpp | 32 +++++----- similar/main/gamecntl.cpp | 24 ++++---- similar/main/inferno.cpp | 12 ++-- similar/main/kconfig.cpp | 71 ++++++++++------------ similar/main/kmatrix.cpp | 10 +--- similar/main/menu.cpp | 100 +++++++++++++++---------------- similar/main/mission.cpp | 8 +-- similar/main/net_udp.cpp | 47 +++++++-------- similar/main/newmenu.cpp | 52 ++++++++-------- similar/main/scores.cpp | 18 +++--- similar/main/state.cpp | 4 +- similar/main/titles.cpp | 26 ++++---- similar/main/weapon.cpp | 4 +- 51 files changed, 438 insertions(+), 507 deletions(-) diff --git a/common/arch/sdl/event.cpp b/common/arch/sdl/event.cpp index 2c4155604f..57e146fe36 100644 --- a/common/arch/sdl/event.cpp +++ b/common/arch/sdl/event.cpp @@ -103,7 +103,7 @@ window_event_result event_poll() // Send the idle event if there were no other events (or they were ignored) if (state.highest_result == window_event_result::ignored) { - const d_event ievent{EVENT_IDLE}; + const d_event ievent{event_type::idle}; state.highest_result = std::max(event_send(ievent), state.highest_result); } else @@ -170,8 +170,7 @@ void event_poll_state::process_event_batch(const ranges::subrangeis_visible()) diff --git a/common/arch/sdl/joy.cpp b/common/arch/sdl/joy.cpp index c4aa873558..233c70497c 100644 --- a/common/arch/sdl/joy.cpp +++ b/common/arch/sdl/joy.cpp @@ -197,10 +197,10 @@ window_event_result joy_button_handler(const SDL_JoyButtonEvent *const jbe) Joystick.button_state[button] = jbe->state; const d_event_joystickbutton event{ - (jbe->type == SDL_JOYBUTTONDOWN) ? EVENT_JOYSTICK_BUTTON_DOWN : EVENT_JOYSTICK_BUTTON_UP, + (jbe->type == SDL_JOYBUTTONDOWN) ? event_type::joystick_button_down : event_type::joystick_button_up, button }; - con_printf(CON_DEBUG, "Sending event %s, button %d", (jbe->type == SDL_JOYBUTTONDOWN) ? "EVENT_JOYSTICK_BUTTON_DOWN" : "EVENT_JOYSTICK_JOYSTICK_UP", event.button); + con_printf(CON_DEBUG, "Sending event %s, button %d", (jbe->type == SDL_JOYBUTTONDOWN) ? "event_type::joystick_button_down" : "EVENT_JOYSTICK_JOYSTICK_UP", event.button); return event_send(event); } #endif @@ -236,14 +236,14 @@ window_event_result joy_hat_handler(const SDL_JoyHatEvent *const jhe) // Same state as before continue; saved_button_state = current_button_state; - const d_event_joystickbutton event{current_button_state ? EVENT_JOYSTICK_BUTTON_DOWN : EVENT_JOYSTICK_BUTTON_UP, hat + i}; + const d_event_joystickbutton event{current_button_state ? event_type::joystick_button_down : event_type::joystick_button_up, hat + i}; if (current_button_state) //last_state up, current state down { - con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_BUTTON_DOWN, button %d", event.button); + con_printf(CON_DEBUG, "Sending event event_type::joystick_button_down, button %d", event.button); } else //last_state down, current state up { - con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_BUTTON_UP, button %d", event.button); + con_printf(CON_DEBUG, "Sending event event_type::joystick_button_up, button %d", event.button); } highest_result = std::max(event_send(event), highest_result); } @@ -258,9 +258,9 @@ namespace { static window_event_result send_axis_button_event(unsigned button, event_type e) { - Joystick.button_state[button] = (e == EVENT_JOYSTICK_BUTTON_UP) ? 0 : 1; + Joystick.button_state[button] = (e == event_type::joystick_button_up) ? 0 : 1; const d_event_joystickbutton event{ e, button }; - con_printf(CON_DEBUG, "Sending event %s, button %d", (e == EVENT_JOYSTICK_BUTTON_UP) ? "EVENT_JOYSTICK_BUTTON_UP" : "EVENT_JOYSTICK_BUTTON_DOWN", event.button); + con_printf(CON_DEBUG, "Sending event %s, button %d", (e == event_type::joystick_button_up) ? "event_type::joystick_button_up" : "event_type::joystick_button_down", event.button); return event_send(event); } @@ -283,16 +283,16 @@ window_event_result joy_axisbutton_handler(const SDL_JoyAxisEvent *const jae) if (prev_value <= 0 && new_value >= 0) // positive pressed { if (prev_value < 0) // Do previous direction release first if the case - highest_result = std::max(send_axis_button_event(button + 1, EVENT_JOYSTICK_BUTTON_UP), highest_result); + highest_result = std::max(send_axis_button_event(button + 1, event_type::joystick_button_up), highest_result); if (new_value > 0) - highest_result = std::max(send_axis_button_event(button, EVENT_JOYSTICK_BUTTON_DOWN), highest_result); + highest_result = std::max(send_axis_button_event(button, event_type::joystick_button_down), highest_result); } else if (prev_value >= 0 && new_value <= 0) // negative pressed { if (prev_value > 0) // Do previous direction release first if the case - highest_result = std::max(send_axis_button_event(button, EVENT_JOYSTICK_BUTTON_UP), highest_result); + highest_result = std::max(send_axis_button_event(button, event_type::joystick_button_up), highest_result); if (new_value < 0) - highest_result = std::max(send_axis_button_event(button + 1, EVENT_JOYSTICK_BUTTON_DOWN), highest_result); + highest_result = std::max(send_axis_button_event(button + 1, event_type::joystick_button_down), highest_result); } return highest_result; @@ -308,10 +308,10 @@ window_event_result joy_axis_handler(const SDL_JoyAxisEvent *const jae) if (axis_value == jae->value/256) return window_event_result::ignored; - d_event_joystick_moved event{EVENT_JOYSTICK_MOVED}; + d_event_joystick_moved event{event_type::joystick_moved}; event.value = axis_value = jae->value/256; event.axis = axis; - con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_MOVED, axis: %d, value: %d",event.axis, event.value); + con_printf(CON_DEBUG, "Sending event event_type::joystick_moved, axis: %d, value: %d",event.axis, event.value); return event_send(event); } @@ -455,7 +455,7 @@ void joy_close() const d_event_joystick_axis_value &event_joystick_get_axis(const d_event &event) { auto &e = static_cast(event); - Assert(e.type == EVENT_JOYSTICK_MOVED); + assert(e.type == event_type::joystick_moved); return e; } #endif @@ -479,7 +479,7 @@ void joy_flush() int event_joystick_get_button(const d_event &event) { auto &e = static_cast(event); - Assert(e.type == EVENT_JOYSTICK_BUTTON_DOWN || e.type == EVENT_JOYSTICK_BUTTON_UP); + assert(e.type == event_type::joystick_button_down || e.type == event_type::joystick_button_up); return e.button; } #endif @@ -496,7 +496,7 @@ int apply_deadzone(int value, int deadzone) #if DXX_MAX_BUTTONS_PER_JOYSTICK bool joy_translate_menu_key(const d_event &event) { - if (event.type != EVENT_JOYSTICK_BUTTON_DOWN) + if (event.type != event_type::joystick_button_down) return false; auto &e = static_cast(event); assert(e.button < joy_key_map.size()); diff --git a/common/arch/sdl/key.cpp b/common/arch/sdl/key.cpp index b78ac343f3..6c4137cf15 100644 --- a/common/arch/sdl/key.cpp +++ b/common/arch/sdl/key.cpp @@ -535,9 +535,9 @@ window_event_result key_handler(const SDL_KeyboardEvent *const kevent) // We allowed the key to be added to the queue for now, // because there are still input loops without associated windows - const d_event_keycommand event{key_state ? EVENT_KEY_COMMAND : EVENT_KEY_RELEASE, keycode}; + const d_event_keycommand event{key_state ? event_type::key_command : event_type::key_release, keycode}; con_printf(CON_DEBUG, "Sending event %s: %s %s %s %s %s %s", - (key_state) ? "EVENT_KEY_COMMAND": "EVENT_KEY_RELEASE", + (key_state) ? "event_type::key_command": "event_type::key_release", (keycode & KEY_METAED) ? "META" : "", (keycode & KEY_DEBUGGED) ? "DEBUG" : "", (keycode & KEY_CTRLED) ? "CTRL" : "", @@ -597,14 +597,13 @@ void key_flush() } void event_keycommand_send(unsigned key) { - const d_event_keycommand event{EVENT_KEY_COMMAND, key}; - event_send(event); + event_send(d_event_keycommand{event_type::key_command, key}); } int event_key_get(const d_event &event) { auto &e = static_cast(event); - Assert(e.type == EVENT_KEY_COMMAND || e.type == EVENT_KEY_RELEASE); + assert(e.type == event_type::key_command || e.type == event_type::key_release); return e.keycode; } diff --git a/common/arch/sdl/mouse.cpp b/common/arch/sdl/mouse.cpp index 03d7b7a129..3962c85f85 100644 --- a/common/arch/sdl/mouse.cpp +++ b/common/arch/sdl/mouse.cpp @@ -80,13 +80,12 @@ static window_event_result maybe_send_z_move(const mbtn button) } else return window_event_result::ignored; - const d_event_mouse_moved event{EVENT_MOUSE_MOVED, 0, 0, dz}; - return event_send(event); + return event_send(d_event_mouse_moved{event_type::mouse_moved, 0, 0, dz}); } static window_event_result send_singleclick(const bool pressed, const mbtn button) { - const d_event_mousebutton event{pressed ? EVENT_MOUSE_BUTTON_DOWN : EVENT_MOUSE_BUTTON_UP, button}; + const d_event_mousebutton event{pressed ? event_type::mouse_button_down : event_type::mouse_button_up, button}; con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_BUTTON_%s, button %d, coords %d,%d,%d", pressed ? "DOWN" : "UP", underlying_value(event.button), Mouse.x, Mouse.y, Mouse.z); return event_send(event); @@ -99,8 +98,8 @@ static window_event_result maybe_send_doubleclick(const fix64 now, const mbtn bu when = now; if (now > then + F1_0/5) return window_event_result::ignored; - const d_event_mousebutton event{EVENT_MOUSE_DOUBLE_CLICKED, button}; - con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_DOUBLE_CLICKED, button %d, coords %d,%d", underlying_value(button), Mouse.x, Mouse.y); + const d_event_mousebutton event{event_type::mouse_double_clicked, button}; + con_printf(CON_DEBUG, "Sending event event_type::mouse_double_clicked, button %d, coords %d,%d", underlying_value(button), Mouse.x, Mouse.y); return event_send(event); } @@ -163,9 +162,9 @@ window_event_result mouse_motion_handler(const SDL_MouseMotionEvent *const mme) Mouse.y += mme->yrel; // z handled in mouse_button_handler - const d_event_mouse_moved event{EVENT_MOUSE_MOVED, mme->xrel, mme->yrel, 0}; + const d_event_mouse_moved event{event_type::mouse_moved, mme->xrel, mme->yrel, 0}; - //con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_MOVED, relative motion %d,%d,%d", + //con_printf(CON_DEBUG, "Sending event event_type::mouse_moved, relative motion %d,%d,%d", // event.dx, event.dy, event.dz); return event_send(event); } diff --git a/common/arch/sdl/window.cpp b/common/arch/sdl/window.cpp index 61908a5790..ebe96a62ca 100644 --- a/common/arch/sdl/window.cpp +++ b/common/arch/sdl/window.cpp @@ -20,6 +20,7 @@ #include "console.h" #include "dxxerror.h" #include "event.h" +#include "d_underlying_value.h" namespace dcx { @@ -43,9 +44,9 @@ void window::send_creation_events() FrontWindow->next = this; FrontWindow = this; if (prev_front) - prev_front->send_event(d_event{EVENT_WINDOW_DEACTIVATED}); + prev_front->send_event(d_event{event_type::window_deactivated}); this->send_event(d_create_event{}); - this->send_event(d_event{EVENT_WINDOW_ACTIVATED}); + this->send_event(d_event{event_type::window_activated}); } window::~window() @@ -69,14 +70,14 @@ mixin_trackable_window::~mixin_trackable_window() int window_close(window *wind) { if (wind == window_get_front()) - wind->send_event(d_event{EVENT_WINDOW_DEACTIVATED}); // Deactivate first + wind->send_event(d_event{event_type::window_deactivated}); // Deactivate first - const auto result = wind->send_event(d_event{EVENT_WINDOW_CLOSE}); + const auto result = wind->send_event(d_event{event_type::window_close}); if (result == window_event_result::handled) { // User 'handled' the event, cancelling close if (wind == window_get_front()) - wind->send_event(d_event{EVENT_WINDOW_ACTIVATED}); + wind->send_event(d_event{event_type::window_activated}); return 0; } @@ -86,7 +87,7 @@ int window_close(window *wind) delete wind; if (const auto prev = window_get_front()) - prev->send_event(d_event{EVENT_WINDOW_ACTIVATED}); + prev->send_event(d_event{event_type::window_activated}); return 1; } @@ -127,8 +128,8 @@ void window_select(window &wind) if (wind.is_visible()) { if (prev) - prev->send_event(d_event{EVENT_WINDOW_DEACTIVATED}); - wind.send_event(d_event{EVENT_WINDOW_ACTIVATED}); + prev->send_event(d_event{event_type::window_deactivated}); + wind.send_event(d_event{event_type::window_activated}); } } @@ -141,10 +142,10 @@ window *window::set_visible(uint8_t visible) return wind; if (prev) - prev->send_event(d_event{EVENT_WINDOW_DEACTIVATED}); + prev->send_event(d_event{event_type::window_deactivated}); if (wind) - wind->send_event(d_event{EVENT_WINDOW_ACTIVATED}); + wind->send_event(d_event{event_type::window_activated}); return wind; } @@ -155,7 +156,7 @@ window_event_result window::send_event(const d_event &event ) { #if DXX_HAVE_CXX_BUILTIN_FILE_LINE - con_printf(CON_DEBUG, "%s:%u: sending event %i to window of dimensions %dx%d", file, line, event.type, w_canv.cv_bitmap.bm_w, w_canv.cv_bitmap.bm_h); + con_printf(CON_DEBUG, "%s:%u: sending event %i to window of dimensions %dx%d", file, line, underlying_value(event.type), w_canv.cv_bitmap.bm_w, w_canv.cv_bitmap.bm_h); #endif const auto r = event_handler(event); if (r == window_event_result::close) diff --git a/common/arch/win32/messagebox.cpp b/common/arch/win32/messagebox.cpp index de231a2b50..d49d0000f0 100644 --- a/common/arch/win32/messagebox.cpp +++ b/common/arch/win32/messagebox.cpp @@ -23,7 +23,7 @@ static void display_win32_alert(const char *message, int error) { // Handle Descent's windows properly if (const auto wind = window_get_front()) - wind->send_event(d_event{EVENT_WINDOW_DEACTIVATED}); + wind->send_event(d_event{event_type::window_deactivated}); int fullscreen = (grd_curscreen && gr_check_fullscreen()); if (fullscreen) @@ -32,8 +32,7 @@ static void display_win32_alert(const char *message, int error) MessageBox(NULL, message, error?"Sorry, a critical error has occurred.":"Attention!", error?MB_OK|MB_ICONERROR:MB_OK|MB_ICONWARNING); if (const auto wind = window_get_front()) - wind->send_event(d_event{EVENT_WINDOW_ACTIVATED}); - + wind->send_event(d_event{event_type::window_activated}); if (!error && fullscreen) gr_toggle_fullscreen(); } diff --git a/common/include/event.h b/common/include/event.h index 737387b169..b3fd68103e 100644 --- a/common/include/event.h +++ b/common/include/event.h @@ -19,48 +19,48 @@ #ifdef __cplusplus namespace dcx { -enum event_type : unsigned +enum class event_type : uint8_t { - EVENT_IDLE = 0, - EVENT_QUIT, + idle = 0, + quit, #if DXX_MAX_BUTTONS_PER_JOYSTICK - EVENT_JOYSTICK_BUTTON_DOWN, - EVENT_JOYSTICK_BUTTON_UP, + joystick_button_down, + joystick_button_up, #endif #if DXX_MAX_AXES_PER_JOYSTICK - EVENT_JOYSTICK_MOVED, + joystick_moved, #endif - EVENT_MOUSE_BUTTON_DOWN, - EVENT_MOUSE_BUTTON_UP, - EVENT_MOUSE_DOUBLE_CLICKED, - EVENT_MOUSE_MOVED, + mouse_button_down, + mouse_button_up, + mouse_double_clicked, + mouse_moved, - EVENT_KEY_COMMAND, - EVENT_KEY_RELEASE, + key_command, + key_release, - EVENT_WINDOW_CREATED, + window_created, #if SDL_MAJOR_VERSION == 2 - EVENT_WINDOW_RESIZE, + window_resize, #endif - EVENT_WINDOW_ACTIVATED, - EVENT_WINDOW_DEACTIVATED, - EVENT_WINDOW_DRAW, - EVENT_WINDOW_CLOSE, - - EVENT_NEWMENU_DRAW, // draw after the newmenu stuff is drawn (e.g. savegame previews) - EVENT_NEWMENU_CHANGED, // an item had its value/text changed - EVENT_NEWMENU_SELECTED, // user chose something - pressed enter/clicked on it - - EVENT_LOOP_BEGIN_LOOP, - EVENT_LOOP_END_LOOP, - - EVENT_UI_DIALOG_DRAW, // draw after the dialog stuff is drawn (e.g. spinning robots) - EVENT_UI_GADGET_PRESSED, // user 'pressed' a gadget - EVENT_UI_LISTBOX_MOVED, - EVENT_UI_LISTBOX_SELECTED, - EVENT_UI_USERBOX_DRAGGED + window_activated, + window_deactivated, + window_draw, + window_close, + + newmenu_draw, // draw after the newmenu stuff is drawn (e.g. savegame previews) + newmenu_changed, // an item had its value/text changed + newmenu_selected, // user chose something - pressed enter/clicked on it + + loop_begin_loop, + loop_end_loop, + + ui_dialog_draw, // draw after the dialog stuff is drawn (e.g. spinning robots) + ui_gadget_pressed, // user 'pressed' a gadget + ui_listbox_moved, + ui_listbox_selected, + ui_userbox_dragged }; enum class window_event_result : uint8_t @@ -87,7 +87,7 @@ struct d_event struct d_create_event : d_event { constexpr d_create_event() : - d_event{EVENT_WINDOW_CREATED} + d_event{event_type::window_created} { } }; @@ -96,7 +96,7 @@ struct d_change_event : d_event { const int citem; constexpr d_change_event(const int c) : - d_event{EVENT_NEWMENU_CHANGED}, citem(c) + d_event{event_type::newmenu_changed}, citem{c} { } }; @@ -105,7 +105,7 @@ struct d_select_event : d_event { int citem; d_select_event(const int c) : - d_event{EVENT_NEWMENU_SELECTED}, citem(c) + d_event{event_type::newmenu_selected}, citem{c} { } }; @@ -116,7 +116,7 @@ struct d_window_size_event : d_event Sint32 width; Sint32 height; d_window_size_event(const Sint32 w, const Sint32 h) : - d_event{EVENT_WINDOW_RESIZE}, width(w), height(h) + d_event{event_type::window_resize}, width{w}, height{h} { } }; @@ -125,7 +125,7 @@ struct d_window_size_event : d_event struct d_event_begin_loop : d_event { d_event_begin_loop() : - d_event{EVENT_LOOP_BEGIN_LOOP} + d_event{event_type::loop_begin_loop} { } }; @@ -133,7 +133,7 @@ struct d_event_begin_loop : d_event struct d_event_end_loop : d_event { d_event_end_loop() : - d_event{EVENT_LOOP_END_LOOP} + d_event{event_type::loop_end_loop} { } }; diff --git a/common/include/fwd-event.h b/common/include/fwd-event.h index a99877548b..118fc06534 100644 --- a/common/include/fwd-event.h +++ b/common/include/fwd-event.h @@ -16,7 +16,7 @@ struct d_event; struct d_change_event; struct d_select_event; -enum event_type : unsigned; +enum class event_type : uint8_t; enum class window_event_result : uint8_t; // Sends input events to event handlers diff --git a/common/include/key.h b/common/include/key.h index a5a2f17e56..87e249c89f 100644 --- a/common/include/key.h +++ b/common/include/key.h @@ -62,7 +62,7 @@ extern std::array unicode_frame_buffer; extern void key_flush(); // Clears the 256 char buffer extern void event_keycommand_send(unsigned key); // synthesize a key command event from a keycode -extern int event_key_get(const d_event &event); // Get the keycode from the EVENT_KEY_COMMAND event +int event_key_get(const d_event &event); // Get the keycode from the event_type::key_command event extern int event_key_get_raw(const d_event &event); // same as above but without mod states unsigned char key_ascii(); diff --git a/common/include/mouse.h b/common/include/mouse.h index fa98027ab6..200b25bdde 100644 --- a/common/include/mouse.h +++ b/common/include/mouse.h @@ -92,14 +92,14 @@ class d_event_mouse_moved : public d_event static inline mbtn event_mouse_get_button(const d_event &event) { auto &e = static_cast(event); - assert(e.type == EVENT_MOUSE_BUTTON_DOWN || e.type == EVENT_MOUSE_BUTTON_UP); + assert(e.type == event_type::mouse_button_down || e.type == event_type::mouse_button_up); return e.button; } static inline void event_mouse_get_delta(const d_event &event, int *dx, int *dy, int *dz) { auto &e = static_cast(event); - assert(e.type == EVENT_MOUSE_MOVED); + assert(e.type == event_type::mouse_moved); *dx = e.dx; *dy = e.dy; *dz = e.dz; diff --git a/common/include/ui.h b/common/include/ui.h index 807d0cb025..f7ac0f78f5 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -247,9 +247,9 @@ struct UI_DIALOG : window virtual window_event_result callback_handler(const d_event &) = 0; }; -#define B1_JUST_PRESSED (event.type == EVENT_MOUSE_BUTTON_DOWN && event_mouse_get_button(event) == mbtn::left) -#define B1_JUST_RELEASED (event.type == EVENT_MOUSE_BUTTON_UP && event_mouse_get_button(event) == mbtn::left) -#define B1_DOUBLE_CLICKED (event.type == EVENT_MOUSE_DOUBLE_CLICKED && event_mouse_get_button(event) == mbtn::left) +#define B1_JUST_PRESSED (event.type == event_type::mouse_button_down && event_mouse_get_button(event) == mbtn::left) +#define B1_JUST_RELEASED (event.type == event_type::mouse_button_up && event_mouse_get_button(event) == mbtn::left) +#define B1_DOUBLE_CLICKED (event.type == event_type::mouse_double_clicked && event_mouse_get_button(event) == mbtn::left) extern grs_font_ptr ui_small_font; @@ -275,7 +275,7 @@ int ui_messagebox( short xc, short yc, const char * text, const ui_messagebox_ti void ui_dialog_set_current_canvas(UI_DIALOG &dlg); void ui_close_dialog(UI_DIALOG &dlg); -#define GADGET_PRESSED(g) (event.type == EVENT_UI_GADGET_PRESSED && &ui_event_get_gadget(event) == g) +#define GADGET_PRESSED(g) (event.type == event_type::ui_gadget_pressed && &ui_event_get_gadget(event) == g) void ui_gadget_add(UI_DIALOG &dlg, short x1, short y1, short x2, short y2, UI_GADGET &); diff --git a/common/ui/button.cpp b/common/ui/button.cpp index e71ec33eb3..e341dffbd7 100644 --- a/common/ui/button.cpp +++ b/common/ui/button.cpp @@ -136,7 +136,7 @@ window_event_result UI_GADGET_BUTTON::event_handler(UI_DIALOG &dlg, const d_even oldposition = position; pressed = 0; - if (event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) + if (event.type == event_type::mouse_button_down || event.type == event_type::mouse_button_up) { const auto OnMe = ui_mouse_on_gadget(*this); @@ -155,7 +155,7 @@ window_event_result UI_GADGET_BUTTON::event_handler(UI_DIALOG &dlg, const d_even } - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) { const auto keypress = event_key_get(event); if (keypress == hotkey || @@ -166,7 +166,7 @@ window_event_result UI_GADGET_BUTTON::event_handler(UI_DIALOG &dlg, const d_even rval = window_event_result::handled; } } - else if (event.type == EVENT_KEY_RELEASE) + else if (event.type == event_type::key_release) { const auto keypress = event_key_get(event); position = 0; @@ -182,7 +182,7 @@ window_event_result UI_GADGET_BUTTON::event_handler(UI_DIALOG &dlg, const d_even } } - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) ui_draw_button(dlg, *this); if (pressed && user_function ) @@ -192,7 +192,7 @@ window_event_result UI_GADGET_BUTTON::event_handler(UI_DIALOG &dlg, const d_even } else if (pressed) { - rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this); + rval = ui_gadget_send_event(dlg, event_type::ui_gadget_pressed, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } diff --git a/common/ui/checkbox.cpp b/common/ui/checkbox.cpp index 5546d59cfc..f70195852a 100644 --- a/common/ui/checkbox.cpp +++ b/common/ui/checkbox.cpp @@ -85,7 +85,7 @@ window_event_result UI_GADGET_CHECKBOX::event_handler(UI_DIALOG &dlg, const d_ev oldposition = position; pressed = 0; - if (event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) + if (event.type == event_type::mouse_button_down || event.type == event_type::mouse_button_up) { const auto OnMe = ui_mouse_on_gadget(*this); @@ -104,7 +104,7 @@ window_event_result UI_GADGET_CHECKBOX::event_handler(UI_DIALOG &dlg, const d_ev } - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) { const auto key = event_key_get(event); if (dlg.keyboard_focus_gadget == this && (key == KEY_SPACEBAR || key == KEY_ENTER)) @@ -113,7 +113,7 @@ window_event_result UI_GADGET_CHECKBOX::event_handler(UI_DIALOG &dlg, const d_ev return window_event_result::handled; } } - else if (event.type == EVENT_KEY_RELEASE) + else if (event.type == event_type::key_release) { const auto key = event_key_get(event); position = 0; @@ -124,13 +124,13 @@ window_event_result UI_GADGET_CHECKBOX::event_handler(UI_DIALOG &dlg, const d_ev if (pressed == 1) { flag ^= 1; - auto rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this); + auto rval = ui_gadget_send_event(dlg, event_type::ui_gadget_pressed, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; return rval; } - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) ui_draw_checkbox(dlg, *this); return window_event_result::ignored; diff --git a/common/ui/dialog.cpp b/common/ui/dialog.cpp index cf72951fad..b0551a468c 100644 --- a/common/ui/dialog.cpp +++ b/common/ui/dialog.cpp @@ -65,8 +65,8 @@ static void ui_dialog_draw(UI_DIALOG *dlg) // The dialog handler borrows heavily from the newmenu_handler window_event_result UI_DIALOG::event_handler(const d_event &event) { - if (event.type == EVENT_WINDOW_ACTIVATED || - event.type == EVENT_WINDOW_DEACTIVATED) + if (event.type == event_type::window_activated || + event.type == event_type::window_deactivated) return window_event_result::ignored; auto rval = callback_handler(event); if (rval != window_event_result::ignored) @@ -74,24 +74,21 @@ window_event_result UI_DIALOG::event_handler(const d_event &event) switch (event.type) { - case EVENT_IDLE: + case event_type::idle: timer_delay2(50); [[fallthrough]]; - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: - case EVENT_MOUSE_MOVED: - case EVENT_KEY_COMMAND: - case EVENT_KEY_RELEASE: + case event_type::mouse_button_down: + case event_type::mouse_button_up: + case event_type::mouse_moved: + case event_type::key_command: + case event_type::key_release: return ui_dialog_do_gadgets(*this, event); - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { ui_dialog_draw(this); rval = ui_dialog_do_gadgets(*this, event); if (rval != window_event_result::close) - { - d_event event2 = { EVENT_UI_DIALOG_DRAW }; - this->send_event(event2); - } + this->send_event(d_event{event_type::ui_dialog_draw}); return rval; } diff --git a/common/ui/file.cpp b/common/ui/file.cpp index a9fecedeca..b31d6bbe48 100644 --- a/common/ui/file.cpp +++ b/common/ui/file.cpp @@ -126,7 +126,7 @@ window_event_result ui_file_browser::callback_handler(const d_event &event) { window_event_result rval = window_event_result::ignored; - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { ui_dputs_at(this, 10, 5, message); @@ -151,8 +151,7 @@ window_event_result ui_file_browser::callback_handler(const d_event &event) ui_messagebox( -1, -1, 1, "Sorry, no help is available!", "Ok" ); rval = window_event_result::handled; } - - if (event.type == EVENT_UI_LISTBOX_MOVED) + if (event.type == event_type::ui_listbox_moved) { if (&ui_event_get_gadget(event) == listbox1.get() && listbox1->current_item >= 0 && filename_list[listbox1->current_item]) ui_inputbox_set_text(user_file.get(), filename_list[listbox1->current_item]); @@ -162,8 +161,7 @@ window_event_result ui_file_browser::callback_handler(const d_event &event) rval = window_event_result::handled; } - - if (GADGET_PRESSED(button1.get()) || GADGET_PRESSED(user_file.get()) || event.type == EVENT_UI_LISTBOX_SELECTED) + if (GADGET_PRESSED(button1.get()) || GADGET_PRESSED(user_file.get()) || event.type == event_type::ui_listbox_selected) { char *p; diff --git a/common/ui/gadget.cpp b/common/ui/gadget.cpp index fc46404fcb..2cd722c4da 100644 --- a/common/ui/gadget.cpp +++ b/common/ui/gadget.cpp @@ -142,7 +142,7 @@ window_event_result ui_gadget_send_event(UI_DIALOG &dlg, const event_type type, UI_GADGET &ui_event_get_gadget(const d_event &event) { auto &e = static_cast(event); - Assert(e.type >= EVENT_UI_GADGET_PRESSED); // Any UI event + assert(e.type >= event_type::ui_gadget_pressed); // Any UI event return e.gadget; } @@ -151,7 +151,7 @@ window_event_result ui_dialog_do_gadgets(UI_DIALOG &dlg, const d_event &event) int keypress = 0; UI_GADGET * tmp, * tmp1; - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); tmp = dlg.gadget; diff --git a/common/ui/icon.cpp b/common/ui/icon.cpp index 2301a9b89a..c159a24e68 100644 --- a/common/ui/icon.cpp +++ b/common/ui/icon.cpp @@ -115,7 +115,7 @@ window_event_result UI_GADGET_ICON::event_handler(UI_DIALOG &dlg, const d_event pressed = 0; window_event_result rval = window_event_result::ignored; - if (event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) + if (event.type == event_type::mouse_button_down || event.type == event_type::mouse_button_up) { const auto OnMe = ui_mouse_on_gadget(*this); @@ -134,7 +134,7 @@ window_event_result UI_GADGET_ICON::event_handler(UI_DIALOG &dlg, const d_event } - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) { const auto key = event_key_get(event); if (key == trap_key) @@ -143,23 +143,22 @@ window_event_result UI_GADGET_ICON::event_handler(UI_DIALOG &dlg, const d_event rval = window_event_result::handled; } } - else if (event.type == EVENT_KEY_RELEASE) + else if (event.type == event_type::key_release) { const auto key = event_key_get(event); position = 0; if (key == trap_key) pressed = 1; } - if (pressed == 1) { flag = static_cast(user_function()); - rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this); + rval = ui_gadget_send_event(dlg, event_type::ui_gadget_pressed, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) ui_draw_icon(*this); return rval; diff --git a/common/ui/inputbox.cpp b/common/ui/inputbox.cpp index bbcdaa0003..73873da74d 100644 --- a/common/ui/inputbox.cpp +++ b/common/ui/inputbox.cpp @@ -93,7 +93,7 @@ std::unique_ptr ui_add_gadget_inputbox(UI_DIALOG &dlg, const window_event_result UI_GADGET_INPUTBOX::event_handler(UI_DIALOG &dlg, const d_event &event) { - const auto keypress = (event.type == EVENT_KEY_COMMAND) + const auto keypress = (event.type == event_type::key_command) ? event_key_get(event) : 0u; @@ -139,15 +139,13 @@ window_event_result UI_GADGET_INPUTBOX::event_handler(UI_DIALOG &dlg, const d_ev } else { first_time = 1; } - if (pressed) { - rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this); + rval = ui_gadget_send_event(dlg, event_type::ui_gadget_pressed, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } - - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) ui_draw_inputbox(dlg, *this); return rval; diff --git a/common/ui/listbox.cpp b/common/ui/listbox.cpp index 385b981031..9f6bfc1844 100644 --- a/common/ui/listbox.cpp +++ b/common/ui/listbox.cpp @@ -143,16 +143,14 @@ std::unique_ptr ui_add_gadget_listbox(UI_DIALOG &dlg, short x window_event_result UI_GADGET_LISTBOX::event_handler(UI_DIALOG &dlg, const d_event &event) { int kf; - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) { ui_draw_listbox(dlg, *this); return window_event_result::ignored; } - - const auto keypress = (event.type == EVENT_KEY_COMMAND) + const auto keypress = (event.type == event_type::key_command) ? event_key_get(event) : 0u; - selected_item = -1; moved = 0; @@ -349,10 +347,9 @@ window_event_result UI_GADGET_LISTBOX::event_handler(UI_DIALOG &dlg, const d_eve } } - if (moved || (selected_item > 0)) { - rval = ui_gadget_send_event(dlg, (selected_item > 0) ? EVENT_UI_LISTBOX_SELECTED : EVENT_UI_LISTBOX_MOVED, *this); + rval = ui_gadget_send_event(dlg, (selected_item > 0) ? event_type::ui_listbox_selected : event_type::ui_listbox_moved, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } diff --git a/common/ui/menubar.cpp b/common/ui/menubar.cpp index 28358ffb3b..dabafbc345 100644 --- a/common/ui/menubar.cpp +++ b/common/ui/menubar.cpp @@ -284,8 +284,7 @@ static int state2_alt_down; static window_event_result do_state_0(const d_event &event) { int keypress = 0; - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); auto &menubar = *Menu[0]; @@ -367,11 +366,10 @@ static window_event_result do_state_1(const d_event &event) { int keypress = 0; window_event_result rval = window_event_result::ignored; - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); auto &menubar = *Menu[0]; - if ((event.type == EVENT_KEY_RELEASE) && !(event_key_get(event) & KEY_ALTED)) + if (event.type == event_type::key_release && !(event_key_get(event) & KEY_ALTED)) { state = 2; state2_alt_down = 0; @@ -429,16 +427,15 @@ static window_event_result do_state_2(const d_event &event) int i; int keypress = 0; window_event_result rval = window_event_result::ignored; - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - if (keypress & KEY_ALTED) { state2_alt_down = 1; rval = window_event_result::handled; } - if ((event.type == EVENT_KEY_RELEASE) && !(event_key_get(event) & KEY_ALTED) && state2_alt_down) + if (event.type == event_type::key_release && !(event_key_get(event) & KEY_ALTED) && state2_alt_down) { state = 0; menu_hide_all(); @@ -545,10 +542,9 @@ window_event_result menu_window::event_handler(const d_event &event) if (state != 3) return window_event_result::ignored; - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - else if (event.type == EVENT_WINDOW_CLOSE) // quitting + else if (event.type == event_type::window_close) // quitting { state = 0; menu_hide_all(); @@ -659,8 +655,7 @@ window_event_result menu_window::event_handler(const d_event &event) break; } } - - if (event.type == EVENT_MOUSE_MOVED || B1_JUST_RELEASED) + if (event.type == event_type::mouse_moved || B1_JUST_RELEASED) { auto &other_menu = *Menu[CMENU]; const auto i = menu_check_mouse_item(other_menu); @@ -708,24 +703,23 @@ window_event_result menu_window::event_handler(const d_event &event) } } - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) { auto &other_menu = *Menu[CMENU]; menu_draw(other_menu); return window_event_result::handled; } - return rval; } window_event_result menubar_window::event_handler(const d_event &event) { - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) { menu_draw(menubar); return window_event_result::handled; } - else if (event.type == EVENT_WINDOW_CLOSE) + else if (event.type == event_type::window_close) { range_for (const auto pi, partial_range(Menu, 1u, num_menus)) { diff --git a/common/ui/message.cpp b/common/ui/message.cpp index 5816adb385..de2ba64375 100644 --- a/common/ui/message.cpp +++ b/common/ui/message.cpp @@ -63,7 +63,7 @@ struct messagebox : UI_DIALOG window_event_result messagebox::callback_handler(const d_event &event) { - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { const grs_font * temp_font; diff --git a/common/ui/radio.cpp b/common/ui/radio.cpp index f77b05ac39..e54f5c0a8a 100644 --- a/common/ui/radio.cpp +++ b/common/ui/radio.cpp @@ -88,7 +88,7 @@ window_event_result UI_GADGET_RADIO::event_handler(UI_DIALOG &dlg, const d_event pressed = 0; window_event_result rval = window_event_result::ignored; - if (event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP) + if (event.type == event_type::mouse_button_down || event.type == event_type::mouse_button_up) { const auto OnMe = ui_mouse_on_gadget(*this); @@ -106,8 +106,7 @@ window_event_result UI_GADGET_RADIO::event_handler(UI_DIALOG &dlg, const d_event } } - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) { const auto key = event_key_get(event); if (dlg.keyboard_focus_gadget == this && (key == KEY_SPACEBAR || key==KEY_ENTER)) @@ -116,7 +115,7 @@ window_event_result UI_GADGET_RADIO::event_handler(UI_DIALOG &dlg, const d_event rval = window_event_result::handled; } } - else if (event.type == EVENT_KEY_RELEASE) + else if (event.type == event_type::key_release) { const auto key = event_key_get(event); position = 0; @@ -141,12 +140,12 @@ window_event_result UI_GADGET_RADIO::event_handler(UI_DIALOG &dlg, const d_event tmp = tmp->next; } flag = 1; - rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this); + rval = ui_gadget_send_event(dlg, event_type::ui_gadget_pressed, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) ui_draw_radio(dlg, *this); return rval; diff --git a/common/ui/scroll.cpp b/common/ui/scroll.cpp index 00052431a2..35a124d28a 100644 --- a/common/ui/scroll.cpp +++ b/common/ui/scroll.cpp @@ -99,8 +99,7 @@ window_event_result UI_GADGET_SCROLLBAR::event_handler(UI_DIALOG &dlg, const d_e { int x, y, z; window_event_result rval = window_event_result::ignored; - - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) { ui_draw_scrollbar(dlg, *this); return window_event_result::ignored; @@ -121,10 +120,9 @@ window_event_result UI_GADGET_SCROLLBAR::event_handler(UI_DIALOG &dlg, const d_e moved = 0; - if (keyfocus && event.type == EVENT_KEY_COMMAND) + if (keyfocus && event.type == event_type::key_command) { int key; - key = event_key_get(event); if (key & KEY_UP) @@ -138,12 +136,10 @@ window_event_result UI_GADGET_SCROLLBAR::event_handler(UI_DIALOG &dlg, const d_e rval = window_event_result::handled; } } - else if (keyfocus && event.type == EVENT_KEY_RELEASE) + else if (keyfocus && event.type == event_type::key_release) { int key; - key = event_key_get(event); - if (key & KEY_UP) { up_button->position = 0; @@ -275,7 +271,7 @@ window_event_result UI_GADGET_SCROLLBAR::event_handler(UI_DIALOG &dlg, const d_e moved = 1; if (moved) { - rval = ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, *this); + rval = ui_gadget_send_event(dlg, event_type::ui_gadget_pressed, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } diff --git a/common/ui/userbox.cpp b/common/ui/userbox.cpp index 84863f1911..b14b292150 100644 --- a/common/ui/userbox.cpp +++ b/common/ui/userbox.cpp @@ -76,14 +76,12 @@ window_event_result UI_GADGET_USERBOX::event_handler(UI_DIALOG &dlg, const d_eve { int x, y, z; window_event_result rval = window_event_result::ignored; - - if (event.type == EVENT_WINDOW_DRAW) + if (event.type == event_type::window_draw) ui_draw_userbox(dlg, *this); - const auto keypress = (event.type == EVENT_KEY_COMMAND) + const auto keypress = (event.type == event_type::key_command) ? event_key_get(event) : 0u; - mouse_get_pos(&x, &y, &z); const auto OnMe = ui_mouse_on_gadget(*this); @@ -113,7 +111,7 @@ window_event_result UI_GADGET_USERBOX::event_handler(UI_DIALOG &dlg, const d_eve rval = window_event_result::handled; } - if ( (event.type == EVENT_MOUSE_MOVED) && b1_held_down ) + if (event.type == event_type::mouse_moved && b1_held_down) { b1_dragging = 1; b1_drag_x2 = x - x1; @@ -146,10 +144,9 @@ window_event_result UI_GADGET_USERBOX::event_handler(UI_DIALOG &dlg, const d_eve this->keypress = keypress; rval = window_event_result::handled; } - if (b1_clicked || b1_dragging) { - rval = ui_gadget_send_event(dlg, b1_clicked ? EVENT_UI_GADGET_PRESSED : EVENT_UI_USERBOX_DRAGGED, *this); + rval = ui_gadget_send_event(dlg, b1_clicked ? event_type::ui_gadget_pressed : event_type::ui_userbox_dragged, *this); if (rval == window_event_result::ignored) rval = window_event_result::handled; } diff --git a/d1x-rebirth/editor/ehostage.cpp b/d1x-rebirth/editor/ehostage.cpp index ab3d7936ce..f141467bc2 100644 --- a/d1x-rebirth/editor/ehostage.cpp +++ b/d1x-rebirth/editor/ehostage.cpp @@ -138,16 +138,16 @@ window_event_result hostage_dialog::callback_handler(const d_event &event) { switch(event.type) { - case EVENT_WINDOW_CREATED: + case event_type::window_created: return hostage_dialog_created(this); - case EVENT_WINDOW_CLOSE: + case event_type::window_close: MainWindow = nullptr; return window_event_result::ignored; default: break; } int keypress = 0; - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); Assert(MainWindow != NULL); diff --git a/d2x-rebirth/main/escort.cpp b/d2x-rebirth/main/escort.cpp index 1783634c53..bd8a368323 100644 --- a/d2x-rebirth/main/escort.cpp +++ b/d2x-rebirth/main/escort.cpp @@ -151,7 +151,7 @@ window_event_result rename_guidebot_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { uint8_t changed = 0; if (PlayerCfg.GuidebotName != guidebot_name_buffer) @@ -1940,21 +1940,18 @@ window_event_result escort_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: game_flush_inputs(Controls); break; - - case EVENT_KEY_COMMAND: + case event_type::key_command: return event_key_command(event); - case EVENT_IDLE: + case event_type::idle: timer_delay2(50); break; - - case EVENT_WINDOW_DRAW: + case event_type::window_draw: show_escort_menu(); break; - - case EVENT_WINDOW_CLOSE: + case event_type::window_close: return window_event_result::ignored; // continue closing default: return window_event_result::ignored; diff --git a/d2x-rebirth/main/movie.cpp b/d2x-rebirth/main/movie.cpp index 24f3db516f..bc13254158 100644 --- a/d2x-rebirth/main/movie.cpp +++ b/d2x-rebirth/main/movie.cpp @@ -246,20 +246,20 @@ window_event_result movie_pause_window::event_handler(const d_event &event) { switch (event.type) { - case EVENT_MOUSE_BUTTON_DOWN: + case event_type::mouse_button_down: if (event_mouse_get_button(event) != mbtn::left) return window_event_result::ignored; [[fallthrough]]; - case EVENT_KEY_COMMAND: + case event_type::key_command: if (const auto result = call_default_handler(event); result == window_event_result::ignored) return window_event_result::close; else return result; - case EVENT_IDLE: + case event_type::idle: timer_delay(F1_0 / 4); break; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { const char *msg = TXT_PAUSE; int y; @@ -287,16 +287,16 @@ window_event_result movie::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: paused = 0; break; - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_deactivated: paused = 1; MVE_rmHoldMovie(); break; - case EVENT_KEY_COMMAND: + case event_type::key_command: { const auto key = event_key_get(event); @@ -318,7 +318,7 @@ window_event_result movie::event_handler(const d_event &event) break; } - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { const auto f = frame_num; if (!paused) @@ -340,7 +340,7 @@ window_event_result movie::event_handler(const d_event &event) break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: break; diff --git a/similar/editor/centers.cpp b/similar/editor/centers.cpp index 6cb6af6b7c..4ebf09b21a 100644 --- a/similar/editor/centers.cpp +++ b/similar/editor/centers.cpp @@ -146,9 +146,9 @@ window_event_result centers_dialog::callback_handler(const d_event &event) auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters; switch(event.type) { - case EVENT_WINDOW_CREATED: + case event_type::window_created: return centers_dialog_created(this); - case EVENT_WINDOW_CLOSE: + case event_type::window_close: MainWindow = NULL; return window_event_result::ignored; default: @@ -160,9 +160,8 @@ window_event_result centers_dialog::callback_handler(const d_event &event) Assert(MainWindow != NULL); - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - //------------------------------------------------------------ // Call the ui code.. //------------------------------------------------------------ @@ -221,15 +220,12 @@ window_event_result centers_dialog::callback_handler(const d_event &event) rval = window_event_result::handled; } } - //------------------------------------------------------------ // If anything changes in the ui system, redraw all the text that // identifies this wall. //------------------------------------------------------------ - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { -// int i; - ui_dprintf_at(this, 12, 6, "Seg: %3hu", static_cast(Cursegp)); } diff --git a/similar/editor/eswitch.cpp b/similar/editor/eswitch.cpp index fd34212d37..a4c53c461c 100644 --- a/similar/editor/eswitch.cpp +++ b/similar/editor/eswitch.cpp @@ -377,9 +377,9 @@ window_event_result trigger_dialog::callback_handler(const d_event &event) { switch(event.type) { - case EVENT_WINDOW_CREATED: + case event_type::window_created: return trigger_dialog_created(this); - case EVENT_WINDOW_CLOSE: + case event_type::window_close: MainWindow = NULL; return window_event_result::ignored; default: @@ -397,10 +397,8 @@ window_event_result trigger_dialog::callback_handler(const d_event &event) // Call the ui code.. //------------------------------------------------------------ ui_button_any_drawn = 0; - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - //------------------------------------------------------------ // If we change walls, we need to reset the ui code for all // of the checkboxes that control the wall flags. @@ -478,7 +476,7 @@ window_event_result trigger_dialog::callback_handler(const d_event &event) //------------------------------------------------------------ // Draw the wall in the little 64x64 box //------------------------------------------------------------ - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { gr_set_current_canvas( wallViewBox->canvas ); auto &canvas = *grd_curcanv; @@ -508,7 +506,7 @@ window_event_result trigger_dialog::callback_handler(const d_event &event) // If anything changes in the ui system, redraw all the text that // identifies this robot. //------------------------------------------------------------ - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { if (markedseg.s.sides[Markedside].wall_num != wall_none) { diff --git a/similar/editor/info.cpp b/similar/editor/info.cpp index 62bb836bb2..2a6e865aaf 100644 --- a/similar/editor/info.cpp +++ b/similar/editor/info.cpp @@ -288,7 +288,7 @@ window_event_result info_dialog_window::event_handler(const d_event &event) switch (event.type) { - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { gr_set_current_canvas(w_canv); auto &canvas = *grd_curcanv; @@ -315,10 +315,9 @@ window_event_result info_dialog_window::event_handler(const d_event &event) grd_curcanv = save_canvas; return window_event_result::handled; } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: Pad_info = NULL; break; - default: break; } diff --git a/similar/editor/med.cpp b/similar/editor/med.cpp index df46ab2944..036aeba672 100644 --- a/similar/editor/med.cpp +++ b/similar/editor/med.cpp @@ -1029,26 +1029,24 @@ window_event_result editor_dialog::callback_handler(const d_event &event) int keypress = 0; window_event_result rval = window_event_result::ignored; - if (event.type == EVENT_WINDOW_CREATED) + if (event.type == event_type::window_created) return window_event_result::ignored; - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - else if (event.type == EVENT_WINDOW_CLOSE) + else if (event.type == event_type::window_close) { EditorWindow = NULL; close_editor(); return window_event_result::ignored; } - // Update the windows - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { // Draw status box gr_set_default_canvas(); gr_rect(*grd_curcanv, STATUS_X,STATUS_Y,STATUS_X+STATUS_W-1,STATUS_Y+STATUS_H-1, CGREY); - medlisp_update_screen(); calc_frame_time(); texpage_do(event); @@ -1060,28 +1058,27 @@ window_event_result editor_dialog::callback_handler(const d_event &event) set_editor_time_of_day(); return window_event_result::handled; } - if ((selected_gadget == GameViewBox.get() && !render_3d_in_big_window) || (selected_gadget == LargeViewBox.get() && render_3d_in_big_window)) switch (event.type) { - case EVENT_MOUSE_BUTTON_UP: - case EVENT_MOUSE_BUTTON_DOWN: + case event_type::mouse_button_up: + case event_type::mouse_button_down: break; - case EVENT_MOUSE_MOVED: + case event_type::mouse_moved: if (!keyd_pressed[ KEY_LCTRL ] && !keyd_pressed[ KEY_RCTRL ]) break; [[fallthrough]]; #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_UP: - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_up: + case event_type::joystick_button_down: #endif #if DXX_MAX_AXES_PER_JOYSTICK - case EVENT_JOYSTICK_MOVED: + case event_type::joystick_moved: #endif - case EVENT_KEY_COMMAND: - case EVENT_KEY_RELEASE: - case EVENT_IDLE: + case event_type::key_command: + case event_type::key_release: + case event_type::idle: kconfig_read_controls(Controls, event, 1); if (slew_frame(0)) @@ -1097,10 +1094,10 @@ window_event_result editor_dialog::callback_handler(const d_event &event) rval = window_event_result::handled; } break; - case EVENT_LOOP_BEGIN_LOOP: + case event_type::loop_begin_loop: kconfig_begin_loop(Controls); break; - case EVENT_LOOP_END_LOOP: + case event_type::loop_end_loop: kconfig_end_loop(Controls, FrameTime); break; @@ -1109,7 +1106,7 @@ window_event_result editor_dialog::callback_handler(const d_event &event) } //do non-essential stuff in idle event - if (event.type == EVENT_IDLE) + if (event.type == event_type::idle) { check_wall_validity(); @@ -1261,7 +1258,7 @@ window_event_result editor_dialog::callback_handler(const d_event &event) Update_flags |= UF_ED_STATE_CHANGED | UF_VIEWPOINT_MOVED; } - if (event.type == EVENT_UI_USERBOX_DRAGGED && &ui_event_get_gadget(event) == GameViewBox.get()) + if (event.type == event_type::ui_userbox_dragged && &ui_event_get_gadget(event) == GameViewBox.get()) { int x, y; x = GameViewBox->b1_drag_x2; @@ -1336,7 +1333,7 @@ window_event_result editor_dialog::callback_handler(const d_event &event) } // Allow specification of LargeView using mouse - if (event.type == EVENT_MOUSE_MOVED && (keyd_pressed[ KEY_LCTRL ] || keyd_pressed[ KEY_RCTRL ])) + if (event.type == event_type::mouse_moved && (keyd_pressed[ KEY_LCTRL ] || keyd_pressed[ KEY_RCTRL ])) { int dx, dy, dz; @@ -1353,7 +1350,7 @@ window_event_result editor_dialog::callback_handler(const d_event &event) } } - if (event.type == EVENT_MOUSE_MOVED) + if (event.type == event_type::mouse_moved) { int dx, dy, dz; diff --git a/similar/editor/medrobot.cpp b/similar/editor/medrobot.cpp index 2517fd4c5c..f72e9706ed 100644 --- a/similar/editor/medrobot.cpp +++ b/similar/editor/medrobot.cpp @@ -578,9 +578,9 @@ window_event_result robot_dialog::callback_handler(const d_event &event) auto &vmobjptridx = Objects.vmptridx; switch(event.type) { - case EVENT_WINDOW_CREATED: + case event_type::window_created: return robot_dialog_created(this); - case EVENT_WINDOW_CLOSE: + case event_type::window_close: MainWindow = NULL; return window_event_result::ignored; default: @@ -591,10 +591,8 @@ window_event_result robot_dialog::callback_handler(const d_event &event) int first_object_index; int keypress = 0; window_event_result rval = window_event_result::ignored; - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - Assert(MainWindow != NULL); first_object_index = Cur_object_index; @@ -665,7 +663,7 @@ window_event_result robot_dialog::callback_handler(const d_event &event) //------------------------------------------------------------ // Redraw the object in the little 64x64 box //------------------------------------------------------------ - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { // A simple frame time counter for spinning the objects... Temp = timer_query(); @@ -855,7 +853,7 @@ window_event_result object_dialog::callback_handler(const d_event &event) auto &vmobjptr = Objects.vmptr; switch(event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: MattWindow = NULL; return window_event_result::ignored; default: @@ -864,23 +862,20 @@ window_event_result object_dialog::callback_handler(const d_event &event) const auto &&obj = vmobjptr(Cur_object_index); int keypress = 0; window_event_result rval = window_event_result::ignored; - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - //------------------------------------------------------------ // Call the ui code.. //------------------------------------------------------------ ui_button_any_drawn = 0; - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { ui_dputs_at(this, 10, 132, "&X:"); ui_dputs_at(this, 10, 162, "&Y:"); ui_dputs_at(this, 10, 192, "&Z:"); } - if (GADGET_PRESSED(quitButton.get()) || keypress == KEY_ESC) { if (initialMode[0]->flag) diff --git a/similar/editor/medwall.cpp b/similar/editor/medwall.cpp index 3507ab6e82..b465f8e922 100644 --- a/similar/editor/medwall.cpp +++ b/similar/editor/medwall.cpp @@ -485,9 +485,9 @@ window_event_result wall_dialog::callback_handler(const d_event &event) { switch(event.type) { - case EVENT_WINDOW_CREATED: + case event_type::window_created: return wall_dialog_created(this); - case EVENT_WINDOW_CLOSE: + case event_type::window_close: MainWindow = nullptr; return window_event_result::ignored; default: @@ -497,10 +497,8 @@ window_event_result wall_dialog::callback_handler(const d_event &event) fix64 Temp; int keypress = 0; window_event_result rval = window_event_result::ignored; - - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) keypress = event_key_get(event); - Assert(MainWindow != NULL); //------------------------------------------------------------ @@ -593,7 +591,7 @@ window_event_result wall_dialog::callback_handler(const d_event &event) //------------------------------------------------------------ // Draw the wall in the little 64x64 box //------------------------------------------------------------ - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { // A simple frame time counter for animating the walls... Temp = timer_query(); @@ -638,7 +636,7 @@ window_event_result wall_dialog::callback_handler(const d_event &event) // If anything changes in the ui system, redraw all the text that // identifies this wall. //------------------------------------------------------------ - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { if (const auto wp = w.get_unchecked_pointer()) { diff --git a/similar/editor/objpage.cpp b/similar/editor/objpage.cpp index 53147cdfb6..f2e88ed777 100644 --- a/similar/editor/objpage.cpp +++ b/similar/editor/objpage.cpp @@ -364,7 +364,7 @@ void objpage_close() int objpage_do(const d_event &event) { - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { for (int i=0; i Replacement_list; int texpage_do(const d_event &event) { - if (event.type == EVENT_UI_DIALOG_DRAW) + if (event.type == event_type::ui_dialog_draw) { gr_set_current_canvas( TmapnameCanvas ); gr_set_curfont(*grd_curcanv, *ui_small_font.get()); gr_set_fontcolor(*grd_curcanv, CBLACK, CWHITE); - texpage_redraw(); - // Don't reset the current tmap every time we go back to the editor. // CurrentTexture = TexturePage*TMAPS_PER_PAGE; texpage_show_current(); - return 1; } diff --git a/similar/main/automap.cpp b/similar/main/automap.cpp index 3d2eb0d994..8fd593b63a 100644 --- a/similar/main/automap.cpp +++ b/similar/main/automap.cpp @@ -297,7 +297,7 @@ window_event_result marker_delete_are_you_sure_menu::event_handler(const d_event { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { const auto citem = static_cast(event).citem; if (citem == 0) @@ -1135,53 +1135,51 @@ window_event_result automap::event_handler(const d_event &event) auto &vmobjptr = Objects.vmptr; switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: game_flush_inputs(controls); event_toggle_focus(1); key_toggle_repeat(0); break; - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_deactivated: event_toggle_focus(0); key_toggle_repeat(1); break; #if SDL_MAJOR_VERSION == 2 - case EVENT_WINDOW_RESIZE: + case event_type::window_resize: init_automap_subcanvas(automap_view, grd_curscreen->sc_canvas); break; #endif - case EVENT_IDLE: + case event_type::idle: #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_UP: - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_up: + case event_type::joystick_button_down: #endif #if DXX_MAX_AXES_PER_JOYSTICK - case EVENT_JOYSTICK_MOVED: + case event_type::joystick_moved: #endif - case EVENT_MOUSE_BUTTON_UP: - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_MOVED: - case EVENT_KEY_RELEASE: + case event_type::mouse_button_up: + case event_type::mouse_button_down: + case event_type::mouse_moved: + case event_type::key_release: return automap_process_input(event, *this); - case EVENT_KEY_COMMAND: + case event_type::key_command: { window_event_result kret = automap_key_command(event, *this); if (kret == window_event_result::ignored) kret = automap_process_input(event, *this); return kret; } - - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { auto &plrobj = get_local_plrobj(); automap_apply_input(*this, plrobj.orient, plrobj.pos); } draw_automap(vcobjptr, *this); break; - - case EVENT_WINDOW_CLOSE: + case event_type::window_close: if (!pause_game) ConsoleObject->mtype.phys_info.flags |= old_wiggle; // Restore wiggle event_toggle_focus(0); @@ -1200,16 +1198,15 @@ window_event_result automap::event_handler(const d_event &event) multi_send_msgsend_state(msgsend_state::none); return window_event_result::ignored; // continue closing - case EVENT_LOOP_BEGIN_LOOP: + case event_type::loop_begin_loop: kconfig_begin_loop(controls); break; - case EVENT_LOOP_END_LOOP: + case event_type::loop_end_loop: kconfig_end_loop(controls, FrameTime); break; default: return window_event_result::ignored; - break; } return window_event_result::handled; } diff --git a/similar/main/console.cpp b/similar/main/console.cpp index 7748cda3d6..c7c14bc525 100644 --- a/similar/main/console.cpp +++ b/similar/main/console.cpp @@ -353,20 +353,19 @@ window_event_result console_window::event_handler(const d_event &event) { int key; static fix64 last_scroll_time = 0; - switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: key_toggle_repeat(1); break; - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_deactivated: key_toggle_repeat(0); con_size = 0; con_state = con_state::closed; break; - case EVENT_KEY_COMMAND: + case event_type::key_command: key = event_key_get(event); switch (key) { @@ -422,7 +421,7 @@ window_event_result console_window::event_handler(const d_event &event) } return window_event_result::handled; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: timer_delay2(50); if (con_state == con_state::opening) { @@ -448,12 +447,11 @@ window_event_result console_window::event_handler(const d_event &event) return window_event_result::close; } break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: break; } - return window_event_result::ignored; } diff --git a/similar/main/credits.cpp b/similar/main/credits.cpp index e43c8bf8f0..292f8a7f1a 100644 --- a/similar/main/credits.cpp +++ b/similar/main/credits.cpp @@ -115,15 +115,15 @@ window_event_result credits_window::event_handler(const d_event &event) switch (event.type) { - case EVENT_KEY_COMMAND: + case event_type::key_command: if ((result = call_default_handler(event)) == window_event_result::ignored) // if not print screen, debug etc { return window_event_result::close; } return result; - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: + case event_type::mouse_button_down: + case event_type::mouse_button_up: if (event_mouse_get_button(event) == mbtn::left || event_mouse_get_button(event) == mbtn::right) { return window_event_result::close; @@ -131,18 +131,17 @@ window_event_result credits_window::event_handler(const d_event &event) break; #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_down: return window_event_result::close; #endif - case EVENT_IDLE: + case event_type::idle: if (done > NUM_LINES) { return window_event_result::close; } break; - - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { #if defined(DXX_BUILD_DESCENT_I) timer_delay(F1_0/17); @@ -242,7 +241,7 @@ window_event_result credits_window::event_handler(const d_event &event) break; } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: songs_set_volume(CGameCfg.MusicVolume); songs_play_song( SONG_TITLE, 1 ); break; diff --git a/similar/main/game.cpp b/similar/main/game.cpp index dd2afeeec9..9c3202c5d3 100644 --- a/similar/main/game.cpp +++ b/similar/main/game.cpp @@ -1773,7 +1773,7 @@ window_event_result game_window::event_handler(const d_event &event) switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: set_screen_mode(SCREEN_GAME); event_toggle_focus(1); @@ -1792,7 +1792,7 @@ window_event_result game_window::event_handler(const d_event &event) reset_cockpit(); break; - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_deactivated: if (!(((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK)) && (!Endlevel_sequence)) ) stop_time(); @@ -1807,21 +1807,21 @@ window_event_result game_window::event_handler(const d_event &event) break; #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_UP: - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_up: + case event_type::joystick_button_down: #endif #if DXX_MAX_AXES_PER_JOYSTICK - case EVENT_JOYSTICK_MOVED: -#endif - case EVENT_MOUSE_BUTTON_UP: - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_MOVED: - case EVENT_KEY_COMMAND: - case EVENT_KEY_RELEASE: - case EVENT_IDLE: + case event_type::joystick_moved: +#endif + case event_type::mouse_button_up: + case event_type::mouse_button_down: + case event_type::mouse_moved: + case event_type::key_command: + case event_type::key_release: + case event_type::idle: return ReadControls(LevelSharedRobotInfoState, event, Controls); - case EVENT_WINDOW_DRAW: + case event_type::window_draw: if (!time_paused) { calc_frame_time(); @@ -1838,7 +1838,7 @@ window_event_result game_window::event_handler(const d_event &event) } break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: digi_stop_digi_sounds(); if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) ) @@ -1862,10 +1862,10 @@ window_event_result game_window::event_handler(const d_event &event) Game_wind = nullptr; return window_event_result::ignored; - case EVENT_LOOP_BEGIN_LOOP: + case event_type::loop_begin_loop: kconfig_begin_loop(Controls); break; - case EVENT_LOOP_END_LOOP: + case event_type::loop_end_loop: kconfig_end_loop(Controls, FrameTime); break; diff --git a/similar/main/gamecntl.cpp b/similar/main/gamecntl.cpp index ba4fab79ab..735efaebb0 100644 --- a/similar/main/gamecntl.cpp +++ b/similar/main/gamecntl.cpp @@ -413,7 +413,7 @@ window_event_result choose_curseg_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { char *p; const auto s = strtoul(text.data(), &p, 0); @@ -445,11 +445,11 @@ window_event_result pause_window::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: game_flush_inputs(Controls); break; - case EVENT_KEY_COMMAND: + case event_type::key_command: switch (event_key_get(event)) { case 0: @@ -466,16 +466,16 @@ window_event_result pause_window::event_handler(const d_event &event) } break; - case EVENT_IDLE: + case event_type::idle: timer_delay2(50); break; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: gr_set_default_canvas(); show_boxed_message(*grd_curcanv, msg.data()); break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: songs_resume(); break; @@ -555,7 +555,7 @@ static int HandleDeathInput(const d_event &event, control_info &Controls) { const auto input_aborts_death_sequence = [&]() { const auto RespawnMode = PlayerCfg.RespawnMode; - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) { const auto key = event_key_get(event); if ((RespawnMode == RespawnPress::Any && !key_isfunc(key) && key != KEY_PAUSE && key) || @@ -566,9 +566,9 @@ static int HandleDeathInput(const d_event &event, control_info &Controls) if (RespawnMode == RespawnPress::Any ? ( #if DXX_MAX_BUTTONS_PER_JOYSTICK - event.type == EVENT_JOYSTICK_BUTTON_UP || + event.type == event_type::joystick_button_up || #endif - event.type == EVENT_MOUSE_BUTTON_UP) + event.type == event_type::mouse_button_up) : (Controls.state.fire_primary || Controls.state.fire_secondary || Controls.state.fire_flare)) return 1; return 0; @@ -1681,7 +1681,7 @@ window_event_result levelwarp_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: handle_close_event(); return window_event_result::ignored; default: @@ -2087,7 +2087,7 @@ window_event_result wimp_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { auto &pl_info = plrobj.ctype.player_info; uint8_t plr_laser_level; @@ -2158,7 +2158,7 @@ window_event_result ReadControls(const d_level_shared_robot_info_state &LevelSha if (Newdemo_state == ND_STATE_PLAYBACK) update_vcr_state(); - if (event.type == EVENT_KEY_COMMAND) + if (event.type == event_type::key_command) { key = event_key_get(event); #if defined(DXX_BUILD_DESCENT_II) diff --git a/similar/main/inferno.cpp b/similar/main/inferno.cpp index dec7c75875..6423f870f1 100644 --- a/similar/main/inferno.cpp +++ b/similar/main/inferno.cpp @@ -296,14 +296,14 @@ window_event_result standard_handler(const d_event &event) switch (event.type) { - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: + case event_type::mouse_button_down: + case event_type::mouse_button_up: // No window selecting // We stay with the current one until it's closed/hidden or another one is made // Not the case for the editor break; - case EVENT_KEY_COMMAND: + case event_type::key_command: key = event_key_get(event); switch (key) @@ -360,15 +360,15 @@ window_event_result standard_handler(const d_event &event) } break; - case EVENT_WINDOW_DRAW: - case EVENT_IDLE: + case event_type::window_draw: + case event_type::idle: //see if redbook song needs to be restarted #if DXX_USE_SDL_REDBOOK_AUDIO RBACheckFinishedHook(); #endif return window_event_result::handled; - case EVENT_QUIT: + case event_type::quit: #if DXX_USE_EDITOR if (!SafetyCheck()) return window_event_result::handled; diff --git a/similar/main/kconfig.cpp b/similar/main/kconfig.cpp index 73118e40bd..63dd34e699 100644 --- a/similar/main/kconfig.cpp +++ b/similar/main/kconfig.cpp @@ -576,10 +576,9 @@ static window_event_result kconfig_mouse(kc_menu &menu, const d_event &event) } } } - else if (event.type == EVENT_MOUSE_BUTTON_UP) + else if (event.type == event_type::mouse_button_up) { int item_height; - mouse_get_pos(&mx, &my, &mz); item_height = get_item_height(*canvas.cv_font, menu.items[menu.citem], menu.mitems[menu.citem]); const auto &&fspacx = FSPACX(); @@ -701,20 +700,18 @@ window_event_result kc_menu::event_handler(const d_event &event) switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: game_flush_inputs(Controls); break; - - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_deactivated: mouse_state = 0; break; - - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: - if (changing && items[citem].type == kc_type::mouse_button && event.type == EVENT_MOUSE_BUTTON_UP) + case event_type::mouse_button_down: + case event_type::mouse_button_up: + if (changing && items[citem].type == kc_type::mouse_button && event.type == event_type::mouse_button_up) { kc_change_mousebutton(*this, event, mitems[citem]); - mouse_state = (event.type == EVENT_MOUSE_BUTTON_DOWN); + mouse_state = (event.type == event_type::mouse_button_down); return window_event_result::handled; } @@ -729,10 +726,10 @@ window_event_result kc_menu::event_handler(const d_event &event) else if (event_mouse_get_button(event) != mbtn::left) return window_event_result::ignored; - mouse_state = (event.type == EVENT_MOUSE_BUTTON_DOWN); + mouse_state = (event.type == event_type::mouse_button_down); return kconfig_mouse(*this, event); - case EVENT_MOUSE_MOVED: + case event_type::mouse_moved: if (changing && items[citem].type == kc_type::mouse_axis) kc_change_mouseaxis(*this, event, mitems[citem]); else @@ -740,14 +737,14 @@ window_event_result kc_menu::event_handler(const d_event &event) break; #if DXX_MAX_BUTTONS_PER_JOYSTICK || DXX_MAX_HATS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_down: if (changing && items[citem].type == kc_type::joy_button) kc_change_joybutton(*this, event, mitems[citem]); break; #endif #if DXX_MAX_AXES_PER_JOYSTICK - case EVENT_JOYSTICK_MOVED: + case event_type::joystick_moved: if (changing && items[citem].type == kc_type::joy_axis) kc_change_joyaxis(*this, event, mitems[citem]); else @@ -760,7 +757,7 @@ window_event_result kc_menu::event_handler(const d_event &event) break; #endif - case EVENT_KEY_COMMAND: + case event_type::key_command: { window_event_result rval = kconfig_key_command(*this, event); if (rval != window_event_result::ignored) @@ -770,19 +767,17 @@ window_event_result kc_menu::event_handler(const d_event &event) return window_event_result::ignored; } - case EVENT_IDLE: + case event_type::idle: kconfig_mouse(*this, event); break; - - case EVENT_WINDOW_DRAW: + case event_type::window_draw: if (changing) timer_delay(f0_1/10); else timer_delay2(50); kconfig_draw(*this); break; - - case EVENT_WINDOW_CLOSE: + case event_type::window_close: // Update save values... for (auto &&[kcm, setting] : zip(kcm_keyboard, PlayerCfg.KeySettings.Keyboard)) setting = kcm.value; @@ -885,7 +880,7 @@ static void kc_change_key( kc_menu &menu,const d_event &event, kc_mitem &mitem ) { ubyte keycode = 255; - Assert(event.type == EVENT_KEY_COMMAND); + assert(event.type == event_type::key_command); keycode = event_key_get_raw(event); auto e = end(system_keys); @@ -903,7 +898,7 @@ static void kc_change_joybutton( kc_menu &menu,const d_event &event, kc_mitem &m { int button = 255; - Assert(event.type == EVENT_JOYSTICK_BUTTON_DOWN); + assert(event.type == event_type::joystick_button_down); button = event_joystick_get_button(event); kc_set_exclusive_binding(menu, mitem, kc_type::joy_button, button); @@ -935,7 +930,7 @@ static void kc_change_mouseaxis( kc_menu &menu,const d_event &event, kc_mitem &m { int dx, dy, dz; - Assert(event.type == EVENT_MOUSE_MOVED); + assert(event.type == event_type::mouse_moved); event_mouse_get_delta( event, &dx, &dy, &dz ); uint8_t code; if (abs(dz) > 5) @@ -1116,8 +1111,8 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut switch (event.type) { - case EVENT_KEY_COMMAND: - case EVENT_KEY_RELEASE: + case event_type::key_command: + case event_type::key_release: { const auto &&key = event_key_get_raw(event); if (key < 255) @@ -1125,9 +1120,9 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut for (auto &&[kc, kcm] : zip(kc_keyboard, kcm_keyboard)) { if (kcm.value == key) - input_button_matched(Controls, kc, event.type == EVENT_KEY_COMMAND); + input_button_matched(Controls, kc, event.type == event_type::key_command); } - if (!automap_flag && event.type == EVENT_KEY_COMMAND) + if (!automap_flag && event.type == event_type::key_command) for (uint_fast32_t i = 0, j = 0; i < 28; i += 3, j++) if (kcm_rebirth[i].value == key) { @@ -1138,8 +1133,8 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut } break; #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_DOWN: - case EVENT_JOYSTICK_BUTTON_UP: + case event_type::joystick_button_down: + case event_type::joystick_button_up: if (!(PlayerCfg.ControlType & CONTROL_USING_JOYSTICK)) break; { @@ -1149,9 +1144,9 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut for (auto &&[kc, kcm] : zip(kc_joystick, kcm_joystick)) { if (kc.type == kc_type::joy_button && kcm.value == button) - input_button_matched(Controls, kc, event.type == EVENT_JOYSTICK_BUTTON_DOWN); + input_button_matched(Controls, kc, event.type == event_type::joystick_button_down); } - if (!automap_flag && event.type == EVENT_JOYSTICK_BUTTON_DOWN) + if (!automap_flag && event.type == event_type::joystick_button_down) for (uint_fast32_t i = 1, j = 0; i < 29; i += 3, j++) if (kcm_rebirth[i].value == button) { @@ -1162,8 +1157,8 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut break; } #endif - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: + case event_type::mouse_button_down: + case event_type::mouse_button_up: if (!(PlayerCfg.ControlType & CONTROL_USING_MOUSE)) break; { @@ -1172,9 +1167,9 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut for (auto &&[kc, kcm] : zip(kc_mouse, kcm_mouse)) { if (kc.type == kc_type::mouse_button && kcm.value == button) - input_button_matched(Controls, kc, event.type == EVENT_MOUSE_BUTTON_DOWN); + input_button_matched(Controls, kc, event.type == event_type::mouse_button_down); } - if (!automap_flag && event.type == EVENT_MOUSE_BUTTON_DOWN) + if (!automap_flag && event.type == event_type::mouse_button_down) for (uint_fast32_t i = 2, j = 0; i < 30; i += 3, j++) if (kcm_rebirth[i].value == button) { @@ -1184,7 +1179,7 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut } break; #if DXX_MAX_AXES_PER_JOYSTICK - case EVENT_JOYSTICK_MOVED: + case event_type::joystick_moved: { int joy_null_value = 0; if (!(PlayerCfg.ControlType & CONTROL_USING_JOYSTICK)) @@ -1214,7 +1209,7 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut break; } #endif - case EVENT_MOUSE_MOVED: + case event_type::mouse_moved: { if (!(PlayerCfg.ControlType & CONTROL_USING_MOUSE)) break; @@ -1245,7 +1240,7 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut } break; } - case EVENT_IDLE: + case event_type::idle: default: if (!PlayerCfg.MouseFlightSim && mouse_delta_time < timer_query()) { diff --git a/similar/main/kmatrix.cpp b/similar/main/kmatrix.cpp index fcb6158a44..336666b5d4 100644 --- a/similar/main/kmatrix.cpp +++ b/similar/main/kmatrix.cpp @@ -326,10 +326,9 @@ window_event_result kmatrix_window::event_handler(const d_event &event) { auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; int k = 0; - switch (event.type) { - case EVENT_KEY_COMMAND: + case event_type::key_command: k = event_key_get(event); switch( k ) { @@ -365,8 +364,7 @@ window_event_result kmatrix_window::event_handler(const d_event &event) break; } break; - - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { timer_delay2(50); gr_set_default_canvas(); @@ -427,12 +425,10 @@ window_event_result kmatrix_window::event_handler(const d_event &event) kmatrix_status_msg(*grd_curcanv, playing == kmatrix_status_mode::reactor_countdown_running ? LevelUniqueControlCenterState.Countdown_seconds_left : f2i(end_time - timer_query()), playing); break; } - - case EVENT_WINDOW_CLOSE: + case event_type::window_close: game_flush_inputs(Controls); newmenu_free_background(); break; - default: break; } diff --git a/similar/main/menu.cpp b/similar/main/menu.cpp index 2b97f39ab4..c372b32e35 100644 --- a/similar/main/menu.cpp +++ b/similar/main/menu.cpp @@ -343,7 +343,7 @@ int hide_menus(void) } // Show all menus, with the front one shown first -// This makes sure EVENT_WINDOW_ACTIVATED is only sent to that window +// This makes sure event_type::window_activated is only sent to that window void show_menus(void) { range_for (auto &i, menus) @@ -518,9 +518,9 @@ window_event_result pilot_selection_listbox::callback_handler(const d_event &eve { switch (event.type) { - case EVENT_KEY_COMMAND: + case event_type::key_command: return player_menu_keycommand(this, event); - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; if (citem < 0) @@ -539,7 +539,7 @@ window_event_result pilot_selection_listbox::callback_handler(const d_event &eve return window_event_result::close; } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: if (read_player_file() != EZERO) return window_event_result::handled; // abort close! @@ -740,32 +740,32 @@ window_event_result main_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CREATED: + case event_type::window_created: if (InterfaceUniqueState.PilotName[0u]) break; RegisterPlayer(); break; - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: #if defined(DXX_BUILD_DESCENT_II) load_palette(MENU_PALETTE, load_palette_use::background, load_palette_change_screen::delayed); //get correct palette #endif keyd_time_when_last_pressed = timer_query(); // .. 20 seconds from now! break; - case EVENT_KEY_COMMAND: + case event_type::key_command: // Don't allow them to hit ESC in the main menu. if (event_key_get(event)==KEY_ESC) return window_event_result::ignored; break; - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: + case event_type::mouse_button_down: + case event_type::mouse_button_up: // Don't allow mousebutton-closing in main menu. if (event_mouse_get_button(event) == mbtn::right) return window_event_result::ignored; break; - case EVENT_IDLE: + case event_type::idle: #if defined(DXX_BUILD_DESCENT_I) #define DXX_DEMO_KEY_DELAY 45 #elif defined(DXX_BUILD_DESCENT_II) @@ -794,11 +794,11 @@ window_event_result main_menu::event_handler(const d_event &event) } break; - case EVENT_NEWMENU_DRAW: + case event_type::newmenu_draw: draw_copyright(parent_canvas, *GAME_FONT); break; - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; return dispatch_menu_option(static_cast(citem)); @@ -895,9 +895,9 @@ window_event_result demo_selection_listbox::callback_handler(const d_event &even { switch (event.type) { - case EVENT_KEY_COMMAND: + case event_type::key_command: return demo_menu_keycommand(this, event); - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; if (citem < 0) @@ -905,7 +905,7 @@ window_event_result demo_selection_listbox::callback_handler(const d_event &even newdemo_start_playback(item[citem]); return window_event_result::handled; // stay in demo selector } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: break; @@ -1076,7 +1076,7 @@ window_event_result options_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; switch (citem) @@ -1097,7 +1097,7 @@ window_event_result options_menu::event_handler(const d_event &event) return window_event_result::handled; // stay in menu until escape } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: write_player_file(); break; @@ -1219,7 +1219,7 @@ window_event_result screen_resolution_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: handle_close_event(); return window_event_result::ignored; default: @@ -1347,8 +1347,8 @@ void screen_resolution_menu::apply_resolution(const screen_mode new_mode) const Game_screen_mode = new_mode; if (const auto g = Game_wind) // shortly activate Game_wind so it's canvas will align to new resolution. really minor glitch but whatever { - g->send_event(d_event{EVENT_WINDOW_ACTIVATED}); - g->send_event(d_event{EVENT_WINDOW_DEACTIVATED}); + g->send_event(d_event{event_type::window_activated}); + g->send_event(d_event{event_type::window_deactivated}); } } game_init_render_sub_buffers(*grd_curcanv, 0, 0, SM_W(Game_screen_mode), SM_H(Game_screen_mode)); @@ -1418,7 +1418,7 @@ window_event_result menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: copy_sensitivity_from_menu_to_cfg(m, copy_sensitivity()); break; default: @@ -1489,7 +1489,7 @@ window_event_result menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: PlayerCfg.MouseFSDead = m[opt_mfsd_deadzone].value; copy_sensitivity_from_menu_to_cfg(m, copy_sensitivity(), @@ -1556,7 +1556,7 @@ window_event_result menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: copy_sensitivity_from_menu_to_cfg(m, copy_sensitivity(), copy_sensitivity(), @@ -1673,7 +1673,7 @@ window_event_result input_config_menu::event_handler(const d_event &event) const auto &items = m; switch (event.type) { - case EVENT_NEWMENU_CHANGED: + case event_type::newmenu_changed: { const auto citem = static_cast(event).citem; MouselookMode mousemode; @@ -1728,7 +1728,7 @@ window_event_result input_config_menu::event_handler(const d_event &event) break; } - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { const auto citem = static_cast(event).citem; if (citem == opt_ic_confkey) @@ -1833,7 +1833,7 @@ window_event_result reticle_config_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: for (uint_fast32_t i = opt_reticle_classic; i != opt_label_blank_reticle_type; ++i) if (m[i].value) { @@ -1901,7 +1901,7 @@ window_event_result hud_style_config_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { const auto new_mode = m[opt_viewstyle_cockpit].value ? cockpit_mode_t::full_cockpit @@ -1984,7 +1984,7 @@ window_event_result hud_config_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; if (citem == opt_hud_reticlemenu) @@ -1993,7 +1993,7 @@ window_event_result hud_config_menu::event_handler(const d_event &event) hud_style_config(); return window_event_result::handled; // stay in menu } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: DSX_HUD_MENU_OPTIONS(READ); #if defined(DXX_BUILD_DESCENT_II) PlayerCfg.MissileViewEnabled = m[opt_missileview_selfandallies].value @@ -2084,7 +2084,7 @@ window_event_result graphics_config_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_CHANGED: + case event_type::newmenu_changed: { auto &citem = static_cast(event).citem; if (citem == opt_gr_brightness) @@ -2098,7 +2098,7 @@ window_event_result graphics_config_menu::event_handler(const d_event &event) #endif break; } - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; if (citem == opt_gr_screenres) @@ -2107,7 +2107,7 @@ window_event_result graphics_config_menu::event_handler(const d_event &event) hud_config(); return window_event_result::handled; // stay in menu } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: #if DXX_USE_OGL if (CGameCfg.VSync != m[opt_gr_vsync].value || CGameCfg.Multisample != m[opt_gr_multisample].value) { @@ -2261,7 +2261,7 @@ window_event_result browser::callback_handler(const d_event &event, window_event switch (event.type) { #ifdef _WIN32 - case EVENT_KEY_COMMAND: + case event_type::key_command: { if (event_key_get(event) == KEY_CTRLED + KEY_D) { @@ -2291,7 +2291,7 @@ window_event_result browser::callback_handler(const d_event &event, window_event break; } #endif - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; auto newpath = view_path.path; @@ -2356,7 +2356,7 @@ window_event_result browser::callback_handler(const d_event &event, window_event } return get_absolute_path(userdata, list[citem]); } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: break; @@ -2578,7 +2578,7 @@ window_event_result sound_menu::event_handler(const d_event &event) int replay = 0; switch (event.type) { - case EVENT_NEWMENU_CHANGED: + case event_type::newmenu_changed: { auto &citem = static_cast(event).citem; if (citem == opt_sm_digivol) @@ -2653,7 +2653,7 @@ window_event_result sound_menu::event_handler(const d_event &event) #endif break; } - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { #if DXX_USE_SDLMIXER auto &citem = static_cast(event).citem; @@ -2683,7 +2683,7 @@ window_event_result sound_menu::event_handler(const d_event &event) #endif return window_event_result::handled; // stay in menu } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: #if DXX_USE_SDLMIXER if (strcmp(old_music.data(), current_music.data())) { @@ -2780,7 +2780,7 @@ window_event_result gameplay_config_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; if (citem == opt_gameplay_reorderprimary_menu) @@ -2789,7 +2789,7 @@ window_event_result gameplay_config_menu::event_handler(const d_event &event) ReorderSecondary(); return window_event_result::handled; // stay in menu } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { #if defined(DXX_BUILD_DESCENT_II) uint8_t thief_absent; @@ -2827,7 +2827,7 @@ window_event_result netgame_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; // stay in multiplayer menu, even after having played a game @@ -2884,13 +2884,13 @@ window_event_result polygon_models_viewer_window::event_handler(const d_event &e switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: #if defined(DXX_BUILD_DESCENT_II) gr_use_palette_table("groupa.256"); #endif key_toggle_repeat(1); break; - case EVENT_KEY_COMMAND: + case event_type::key_command: key = event_key_get(event); switch (key) { @@ -2939,7 +2939,7 @@ window_event_result polygon_models_viewer_window::event_handler(const d_event &e break; } return window_event_result::handled; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: timer_delay(F1_0/60); { auto &canvas = *grd_curcanv; @@ -2950,7 +2950,7 @@ window_event_result polygon_models_viewer_window::event_handler(const d_event &e gr_printf(canvas, game_font, FSPACX(1), FSPACY(1), "ESC: leave\nSPACE/BACKSP: next/prev model (%i/%i)\nA/D: rotate y\nW/S: rotate x\nQ/E: rotate z\nR: reset orientation", underlying_value(view_idx), LevelSharedPolygonModelState.N_polygon_models - 1); } break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: #if defined(DXX_BUILD_DESCENT_II) load_palette(MENU_PALETTE, load_palette_use::background, load_palette_change_screen::delayed); #endif @@ -2977,13 +2977,13 @@ window_event_result gamebitmaps_viewer_window::event_handler(const d_event &even switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: #if defined(DXX_BUILD_DESCENT_II) gr_use_palette_table("groupa.256"); #endif key_toggle_repeat(1); break; - case EVENT_KEY_COMMAND: + case event_type::key_command: key = event_key_get(event); switch (key) { @@ -3002,7 +3002,7 @@ window_event_result gamebitmaps_viewer_window::event_handler(const d_event &even break; } return window_event_result::handled; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { const bitmap_index bi{view_idx}; grs_bitmap *const bm = &GameBitmaps[bi]; @@ -3021,7 +3021,7 @@ window_event_result gamebitmaps_viewer_window::event_handler(const d_event &even gr_printf(canvas, game_font, FSPACX(1), FSPACY(1), "ESC: leave\nSPACE/BACKSP: next/prev bitmap (%i/%i)", view_idx, Num_bitmap_files-1); } break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: #if defined(DXX_BUILD_DESCENT_II) load_palette(MENU_PALETTE, load_palette_use::background, load_palette_change_screen::delayed); #endif @@ -3071,7 +3071,7 @@ window_event_result sandbox_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; switch (citem) diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index d4ba9ce9bd..8fa186143f 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -1326,9 +1326,9 @@ window_event_result mission_menu::callback_handler(const d_event &event, window_ { switch (event.type) { - case EVENT_WINDOW_CREATED: + case event_type::window_created: break; - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { const auto raw_citem = static_cast(event).citem; auto citem = raw_citem; @@ -1338,7 +1338,7 @@ window_event_result mission_menu::callback_handler(const d_event &event, window_ { /* Clear parent pointer so that the parent window is * not implicitly closed during handling of - * EVENT_WINDOW_CLOSE. + * event_type::window_close. */ parent = nullptr; return window_event_result::close; @@ -1375,7 +1375,7 @@ window_event_result mission_menu::callback_handler(const d_event &event, window_ } return (*when_selected)(); } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: /* If the user dismisses the listbox by pressing ESCAPE, * do not close the parent listbox. */ diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index 97bbd0ef14..c024e49945 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -302,7 +302,7 @@ window_event_result net_udp_select_teams_menu::event_handler(const d_event &even { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { const auto citem = static_cast(event).citem; if (citem == idx_item_accept) @@ -358,7 +358,7 @@ window_event_result net_udp_select_teams_menu::event_handler(const d_event &even -- this->citem; } return window_event_result::handled; - case EVENT_NEWMENU_DRAW: + case event_type::newmenu_draw: { const auto draw_team_color_box = [&canv = this->w_canv](const newmenu_item &mi, const color_palette_index cpi) { const unsigned height = mi.h - 8; @@ -1381,7 +1381,7 @@ window_event_result manual_join_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_KEY_COMMAND: + case event_type::key_command: if (connecting != direct_join::connect_type::idle && event_key_get(event) == KEY_ESC) { connecting = direct_join::connect_type::idle; @@ -1389,8 +1389,7 @@ window_event_result manual_join_menu::event_handler(const d_event &event) return window_event_result::handled; } break; - - case EVENT_IDLE: + case event_type::idle: if (connecting != direct_join::connect_type::idle) { if (net_udp_game_connect(this)) @@ -1400,7 +1399,7 @@ window_event_result manual_join_menu::event_handler(const d_event &event) } break; - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { int sockres = -1; @@ -1431,12 +1430,10 @@ window_event_result manual_join_menu::event_handler(const d_event &event) return window_event_result::handled; } } - - case EVENT_WINDOW_CLOSE: + case event_type::window_close: if (!Game_wind) // they cancelled net_udp_close(); break; - default: break; } @@ -1492,7 +1489,7 @@ window_event_result netgame_list_game_menu::event_handler(const d_event &event) static int NLPage = 0; switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: { Netgame.protocol.udp.valid = 0; Active_udp_games = {}; @@ -1509,7 +1506,7 @@ window_event_result netgame_list_game_menu::event_handler(const d_event &event) nm_set_item_text(menus[UDP_NETGAMES_PPAGE+4], "\t"); break; } - case EVENT_IDLE: + case event_type::idle: if (connecting != direct_join::connect_type::idle) { if (net_udp_game_connect(this)) @@ -1518,7 +1515,7 @@ window_event_result netgame_list_game_menu::event_handler(const d_event &event) nm_set_item_text(menus[UDP_NETGAMES_PPAGE+4], "\t"); } break; - case EVENT_KEY_COMMAND: + case event_type::key_command: { int key = event_key_get(event); if (key == KEY_PAGEUP) @@ -1597,7 +1594,7 @@ window_event_result netgame_list_game_menu::event_handler(const d_event &event) } break; } - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; if (((citem+(NLPage*UDP_NETGAMES_PPAGE)) >= 4) && (((citem+(NLPage*UDP_NETGAMES_PPAGE))-3) <= num_active_udp_games)) @@ -1622,7 +1619,7 @@ window_event_result netgame_list_game_menu::event_handler(const d_event &event) } return window_event_result::handled; } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { if (!Game_wind) { @@ -3663,7 +3660,7 @@ static int net_udp_sync_poll( newmenu *,const d_event &event, const unused_newme static fix64 t1 = 0; int rval = 0; - if (event.type != EVENT_WINDOW_DRAW) + if (event.type != event_type::window_draw) return 0; net_udp_listen(); @@ -3690,7 +3687,7 @@ static int net_udp_sync_poll( newmenu *,const d_event &event, const unused_newme static int net_udp_start_poll(newmenu *, const d_event &event, start_poll_menu_items *const items) { - if (event.type != EVENT_WINDOW_DRAW) + if (event.type != event_type::window_draw) return 0; assert(Network_status == network_state::starting); @@ -3868,7 +3865,7 @@ window_event_result netgame_powerups_allowed_menu::event_handler(const d_event & { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { typename std::underlying_type::type AllowedItems = 0; for (auto &&[i, mi] : enumerate(m)) @@ -4159,7 +4156,7 @@ window_event_result grant_powerup_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: read(Netgame.SpawnGrantedItems); break; default: @@ -4185,7 +4182,7 @@ window_event_result more_game_options_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_CHANGED: + case event_type::newmenu_changed: { auto &citem = static_cast(event).citem; auto &menus = m; @@ -4247,7 +4244,7 @@ window_event_result more_game_options_menu::event_handler(const d_event &event) } break; } - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; if (citem == opt_setpower) @@ -4258,7 +4255,7 @@ window_event_result more_game_options_menu::event_handler(const d_event &event) break; return window_event_result::handled; } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: read(); if (Netgame.PacketsPerSec > MAX_PPS) { @@ -4312,7 +4309,7 @@ static int net_udp_game_param_handler( newmenu *menu,const d_event &event, param newmenu_item *menus = newmenu_get_items(menu); switch (event.type) { - case EVENT_NEWMENU_CHANGED: + case event_type::newmenu_changed: { auto &citem = static_cast(event).citem; #if defined(DXX_BUILD_DESCENT_I) @@ -4391,7 +4388,7 @@ static int net_udp_game_param_handler( newmenu *menu,const d_event &event, param Netgame.RefusePlayers=menus[opt->refuse].value; break; } - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; #if defined(DXX_BUILD_DESCENT_I) @@ -5006,7 +5003,7 @@ static int net_udp_request_poll( newmenu *,const d_event &event, const unused_ne // Polling loop for waiting-for-requests menu int num_ready = 0; - if (event.type != EVENT_WINDOW_DRAW) + if (event.type != event_type::window_draw) return 0; net_udp_listen(); net_udp_timeout_check(timer_query()); @@ -6376,7 +6373,7 @@ window_event_result show_game_info_menu::event_handler(const d_event &event) { switch (event.type) { - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { auto &citem = static_cast(event).citem; switch (citem) diff --git a/similar/main/newmenu.cpp b/similar/main/newmenu.cpp index 72fe8dfa31..68c63e5e7c 100644 --- a/similar/main/newmenu.cpp +++ b/similar/main/newmenu.cpp @@ -539,7 +539,7 @@ int newmenu::process_until_closed(newmenu *const menu) // Track to see when the window is freed // Doing this way in case another window is opened on top without its own polling loop // newmenu_do2 and simpler get their own event loop - // This is so the caller doesn't have to provide a callback that responds to EVENT_NEWMENU_SELECTED + // This is so the caller doesn't have to provide a callback that responds to event_type::newmenu_selected for (const auto exists = menu->track(); *exists;) event_process(); @@ -843,7 +843,7 @@ static window_event_result newmenu_mouse(const d_event &event, newmenu *menu, co old_choice = menu->citem; const auto &&fspacx = FSPACX(); - if ((event.type == EVENT_MOUSE_BUTTON_DOWN) && !menu->all_text) + if (event.type == event_type::mouse_button_down && !menu->all_text) { mouse_get_pos(&mx, &my, &mz); const int line_spacing = static_cast(LINE_SPACING(*canvas.cv_font, *GAME_FONT)); @@ -956,7 +956,7 @@ static window_event_result newmenu_mouse(const d_event &event, newmenu *menu, co } } - if (event.type == EVENT_MOUSE_BUTTON_UP && + if (event.type == event_type::mouse_button_up && !menu->all_text && menu->citem != -1 && std::next(menu->items.begin(), menu->citem)->type == nm_type::menu) @@ -982,7 +982,7 @@ static window_event_result newmenu_mouse(const d_event &event, newmenu *menu, co } } - if (event.type == EVENT_MOUSE_BUTTON_UP && menu->citem > -1) + if (event.type == event_type::mouse_button_up && menu->citem > -1) { auto &citem = *std::next(menu->items.begin(), menu->citem); if (citem.type == nm_type::input_menu && citem.imenu().group == 0) @@ -1179,7 +1179,7 @@ static window_event_result newmenu_key_command(const d_event &event, newmenu *co } if ( menu->citem > -1 ) { - // Alerting callback of every keypress for NM_TYPE_INPUT. Alternatively, just respond to EVENT_NEWMENU_SELECTED + // Alerting callback of every keypress for NM_TYPE_INPUT. Alternatively, just respond to event_type::newmenu_selected if ((citem.type == nm_type::input || (citem.type == nm_type::input_menu && citem.imenu().group == 1)) && old_choice == menu->citem) { if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) { @@ -1566,7 +1566,7 @@ static window_event_result newmenu_draw(newmenu *menu) gr_string(menu_canvas, cv_font, sx, sy, (scroll_offset + menu->max_displayable < menu->items.size()) ? DOWN_ARROW_MARKER(cv_font, game_font) : " "); } - menu->event_handler(d_event{EVENT_NEWMENU_DRAW}); + menu->event_handler(d_event{event_type::newmenu_draw}); return window_event_result::handled; } @@ -1592,35 +1592,35 @@ window_event_result newmenu::event_handler(const d_event &event) switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: game_flush_inputs(Controls); event_toggle_focus(0); key_toggle_repeat(1); break; - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_deactivated: //event_toggle_focus(1); // No cursor recentering key_toggle_repeat(1); mouse_state = 0; break; - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: + case event_type::mouse_button_down: + case event_type::mouse_button_up: { - mouse_state = event.type == EVENT_MOUSE_BUTTON_DOWN; + mouse_state = event.type == event_type::mouse_button_down; const auto button = event_mouse_get_button(event); return newmenu_mouse(event, this, button); } - case EVENT_KEY_COMMAND: + case event_type::key_command: return newmenu_key_command(event, this); - case EVENT_IDLE: + case event_type::idle: if (!(Game_mode & GM_MULTI) || !Game_wind || !Game_wind->is_visible()) timer_delay2(CGameArg.SysMaxFPS); break; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: return newmenu_draw(this); - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: break; @@ -1787,7 +1787,7 @@ static window_event_result listbox_mouse(const d_event &event, listbox *lb, cons break; lb->citem = idx_absolute_item; } - else if (event.type == EVENT_MOUSE_BUTTON_UP) + else if (event.type == event_type::mouse_button_up) { if (lb->citem < 0) return window_event_result::ignored; @@ -2096,7 +2096,7 @@ static window_event_result listbox_draw(listbox *lb) } } - return lb->callback_handler(d_event{EVENT_NEWMENU_DRAW}, window_event_result::handled); + return lb->callback_handler(d_event{event_type::newmenu_draw}, window_event_result::handled); } } @@ -2113,30 +2113,30 @@ window_event_result listbox::event_handler(const d_event &event) switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: game_flush_inputs(Controls); event_toggle_focus(0); key_toggle_repeat(1); break; - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_deactivated: //event_toggle_focus(1); // No cursor recentering key_toggle_repeat(0); break; - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: - mouse_state = event.type == EVENT_MOUSE_BUTTON_DOWN; + case event_type::mouse_button_down: + case event_type::mouse_button_up: + mouse_state = event.type == event_type::mouse_button_down; return listbox_mouse(event, this, event_mouse_get_button(event)); - case EVENT_KEY_COMMAND: + case event_type::key_command: return listbox_key_command(event, this); - case EVENT_IDLE: + case event_type::idle: if (!(Game_mode & GM_MULTI && Game_wind)) timer_delay2(CGameArg.SysMaxFPS); return window_event_result::ignored; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: return listbox_draw(this); - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: break; diff --git a/similar/main/scores.cpp b/similar/main/scores.cpp index e86475cba7..bce0d8b68f 100644 --- a/similar/main/scores.cpp +++ b/similar/main/scores.cpp @@ -254,7 +254,7 @@ window_event_result request_user_high_score_comment::event_handler(const d_event { switch (event.type) { - case EVENT_WINDOW_CLOSE: + case event_type::window_close: { std::array &text1 = *this; strcpy(scores.cool_saying, text1[0] ? text1.data() : "No comment"); @@ -504,11 +504,11 @@ window_event_result scores_menu::event_handler(const d_event &event) switch (event.type) { - case EVENT_WINDOW_ACTIVATED: + case event_type::window_activated: game_flush_inputs(Controls); break; - case EVENT_KEY_COMMAND: + case event_type::key_command: k = event_key_get(event); switch( k ) { case KEY_CTRLED+KEY_R: @@ -533,8 +533,8 @@ window_event_result scores_menu::event_handler(const d_event &event) } break; - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: + case event_type::mouse_button_down: + case event_type::mouse_button_up: if (event_mouse_get_button(event) == mbtn::left || event_mouse_get_button(event) == mbtn::right) { return window_event_result::close; @@ -542,15 +542,15 @@ window_event_result scores_menu::event_handler(const d_event &event) break; #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_down: return window_event_result::close; #endif - case EVENT_IDLE: + case event_type::idle: timer_delay2(50); break; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { auto &canvas = w_canv; @@ -594,7 +594,7 @@ window_event_result scores_menu::event_handler(const d_event &event) } } break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: break; diff --git a/similar/main/state.cpp b/similar/main/state.cpp index bc54730d88..7722b524d0 100644 --- a/similar/main/state.cpp +++ b/similar/main/state.cpp @@ -284,10 +284,10 @@ window_event_result savegame_chooser_newmenu::event_handler(const d_event &event { switch (event.type) { - case EVENT_NEWMENU_DRAW: + case event_type::newmenu_draw: draw_handler(); return window_event_result::handled; - case EVENT_NEWMENU_SELECTED: + case event_type::newmenu_selected: { const auto citem = static_cast(event).citem; const auto choice = static_cast(citem - decorative_item_count); diff --git a/similar/main/titles.cpp b/similar/main/titles.cpp index 0c8bc123c7..8ff856ffae 100644 --- a/similar/main/titles.cpp +++ b/similar/main/titles.cpp @@ -129,7 +129,7 @@ window_event_result title_screen::event_handler(const d_event &event) switch (event.type) { - case EVENT_MOUSE_BUTTON_DOWN: + case event_type::mouse_button_down: if (event_mouse_get_button(event) != mbtn::left) return window_event_result::ignored; else @@ -138,7 +138,7 @@ window_event_result title_screen::event_handler(const d_event &event) } break; - case EVENT_KEY_COMMAND: + case event_type::key_command: if ((result = call_default_handler(event)) == window_event_result::ignored) { return window_event_result::close; @@ -146,11 +146,11 @@ window_event_result title_screen::event_handler(const d_event &event) return result; #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_down: return window_event_result::close; #endif - case EVENT_IDLE: + case event_type::idle: timer_delay2(50); if (timer_query() > timer) @@ -159,11 +159,11 @@ window_event_result title_screen::event_handler(const d_event &event) } break; - case EVENT_WINDOW_DRAW: + case event_type::window_draw: show_fullscr(w_canv, title_bm); break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: break; default: @@ -1560,12 +1560,12 @@ window_event_result briefing::event_handler(const d_event &event) switch (event.type) { - case EVENT_WINDOW_ACTIVATED: - case EVENT_WINDOW_DEACTIVATED: + case event_type::window_activated: + case event_type::window_deactivated: key_flush(); break; - case EVENT_MOUSE_BUTTON_DOWN: + case event_type::mouse_button_down: if (event_mouse_get_button(event) == mbtn::left) { if (this->new_screen) @@ -1587,7 +1587,7 @@ window_event_result briefing::event_handler(const d_event &event) break; #if DXX_MAX_BUTTONS_PER_JOYSTICK - case EVENT_JOYSTICK_BUTTON_DOWN: + case event_type::joystick_button_down: // using joy_translate_menu_key doesn't work here for unclear // reasons, so we build a reasonable facsimile right here if (event_joystick_get_button(event) == 1) @@ -1609,7 +1609,7 @@ window_event_result briefing::event_handler(const d_event &event) return window_event_result::handled; #endif - case EVENT_KEY_COMMAND: + case event_type::key_command: { int key = event_key_get(event); @@ -1646,7 +1646,7 @@ window_event_result briefing::event_handler(const d_event &event) break; } - case EVENT_WINDOW_DRAW: + case event_type::window_draw: { auto &canvas = w_canv; @@ -1691,7 +1691,7 @@ window_event_result briefing::event_handler(const d_event &event) gr_string(canvas, game_font, this->text_x, this->text_y, "_"); break; } - case EVENT_WINDOW_CLOSE: + case event_type::window_close: free_briefing_screen(this); #if defined(DXX_BUILD_DESCENT_II) this->hum_channel.reset(); diff --git a/similar/main/weapon.cpp b/similar/main/weapon.cpp index 56516d5c64..1d458d66ee 100644 --- a/similar/main/weapon.cpp +++ b/similar/main/weapon.cpp @@ -259,10 +259,10 @@ window_event_result weapon_reorder_menu::event_handler(const { switch(event.type) { - case EVENT_KEY_COMMAND: + case event_type::key_command: event_key_command(event); break; - case EVENT_WINDOW_CLOSE: + case event_type::window_close: for (auto &&[i, mi] : enumerate(menu_items)) cycle_weapon_state::get_weapon_by_order_slot(i) = mi.value; break; From 9306ed163914ea26e3feb3d7dbc3f2501212007a Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 19 Nov 2023 16:21:42 +0000 Subject: [PATCH 02/32] Value-initialize grs_bitmap pointers by default Value-initialize the pointers to avoid confusing code that reads these members without first assigning a specific value. All code should be able to handle the member being `nullptr`, but an uninitialized pointer with a garbage value would confuse later readers. --- common/include/gr.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/include/gr.h b/common/include/gr.h index e6ea601d3d..8bad2129b6 100644 --- a/common/include/gr.h +++ b/common/include/gr.h @@ -98,7 +98,7 @@ struct grs_bitmap : prohibit_void_ptr short bm_rowsize; // unsigned char offset to next row std::array avg_color_rgb; // same as above but real rgb value to be used to textured objects that should emit light union { - const color_palette_index *bm_data; // ptr to pixel data... + const color_palette_index *bm_data{}; // ptr to pixel data... // Linear = *parent+(rowsize*y+x) // ModeX = *parent+(rowsize*y+x/4) // SVGA = *parent+(rowsize*y+x) @@ -106,9 +106,9 @@ struct grs_bitmap : prohibit_void_ptr }; const color_palette_index *get_bitmap_data() const { return bm_data; } color_palette_index *get_bitmap_data() { return bm_mdata; } - struct grs_bitmap *bm_parent; + struct grs_bitmap *bm_parent{}; #if DXX_USE_OGL - struct ogl_texture *gltexture; + struct ogl_texture *gltexture{}; #else uint8_t avg_color; // Average color of all pixels in texture map. #endif /* def OGL */ From 3a5518ba547b378da2cd255cb6beb77607878b4b Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 19 Nov 2023 16:21:42 +0000 Subject: [PATCH 03/32] Simplify iff_parse_bitmap Using `bmheader.raw_data.reset` was wrong, because then both bmheader and bm would own the data, but both would claim to own it exclusively. Fortunately, no caller passed a non-nullptr data, so this did not cause problems in practice. Remove the `reset` to avoid future issues. Simplify setup of bmheader.w, bmheader.h, since with the reset removed, the `else` path is now guaranteed. Remove from `iff_read_bitmap` a dangerous `bm_data = nullptr`, which discarded the pointer without attempting to free it. Some callers might own the data, and need it to be freed. Others might be borrowing the data and need it not to be freed. Fortunately, as with `iff_parse_bitmap`, no caller supplied a non-nullptr value here, so no memory was leaked by this statement. --- similar/main/iff.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/similar/main/iff.cpp b/similar/main/iff.cpp index 1e0f6c14b1..2fb085e78c 100644 --- a/similar/main/iff.cpp +++ b/similar/main/iff.cpp @@ -540,15 +540,7 @@ static int iff_parse_bitmap(PHYSFS_File *ifile, grs_bitmap &bm, const bm_mode bi int sig,form_len; long form_type; - bmheader.raw_data.reset(bm.get_bitmap_data()); - - if (bmheader.raw_data) { - bmheader.w = bm.bm_w; - bmheader.h = bm.bm_h; - }//added 05/17/99 Matt Mueller - don't just leave them unitialized - else{ bmheader.w=bmheader.h=0; - } sig=get_sig(ifile); @@ -607,7 +599,7 @@ int iff_read_bitmap(const char *const ifilename, grs_bitmap &bm, palette_array_t if (!ifile) return IFF_NO_FILE; - bm.bm_data = nullptr; + assert(bm.bm_data == nullptr); ret = iff_parse_bitmap(ifile, bm, bm_mode::linear, palette, nullptr); return ret; } From 8a2bdb85ca0048f48b6ca1b94d31a0b48c49303e Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 19 Nov 2023 16:21:42 +0000 Subject: [PATCH 04/32] Use list initialization for more variables --- common/main/digi.h | 2 +- common/main/lighting.h | 4 ++-- common/main/object.h | 16 ++++++++-------- similar/editor/medrobot.cpp | 2 +- similar/main/bm.cpp | 6 +++--- similar/main/console.cpp | 2 +- similar/main/credits.cpp | 4 ++-- similar/main/gauges.cpp | 17 ++++++++--------- similar/main/mission.cpp | 4 ++-- similar/main/net_udp.cpp | 8 ++++---- 10 files changed, 32 insertions(+), 33 deletions(-) diff --git a/common/main/digi.h b/common/main/digi.h index 03099cda08..2c8c491971 100644 --- a/common/main/digi.h +++ b/common/main/digi.h @@ -67,7 +67,7 @@ enum class sound_sample_rate : uint16_t struct digi_sound_deleter : std::default_delete { - game_sound_offset offset = {}; + game_sound_offset offset{}; constexpr digi_sound_deleter() = default; constexpr digi_sound_deleter(const game_sound_offset offset) : offset(offset) diff --git a/common/main/lighting.h b/common/main/lighting.h index 1501acd521..8cad087ea5 100644 --- a/common/main/lighting.h +++ b/common/main/lighting.h @@ -52,8 +52,8 @@ namespace dsx { #if defined(DXX_BUILD_DESCENT_II) struct d_level_unique_headlight_state { - unsigned Num_headlights = 0; - std::array Headlights = {}; + unsigned Num_headlights{}; + std::array Headlights{}; }; struct d_level_unique_light_state : diff --git a/common/main/object.h b/common/main/object.h index 80ffcc9927..b287002408 100644 --- a/common/main/object.h +++ b/common/main/object.h @@ -230,13 +230,13 @@ struct quaternionpos : prohibit_void_ptr vms_vector rotvel; }; -// stuctures for different kinds of simulation +// structures for different kinds of simulation struct laser_parent { - int16_t parent_type = {}; // The type of the parent of this object - objnum_t parent_num = {}; // The object's parent's number - object_signature_t parent_signature = object_signature_t{0}; // The object's parent's signature... + int16_t parent_type{}; // The type of the parent of this object + objnum_t parent_num{}; // The object's parent's number + object_signature_t parent_signature{}; // The object's parent's signature... }; struct laser_info : prohibit_void_ptr, laser_parent @@ -251,10 +251,10 @@ struct laser_info : prohibit_void_ptr, laser_parent * hitobj_count == hitobj_values.size(), hitobj_pos wraps around and * begins erasing the oldest elements first. */ - uint8_t hitobj_pos = 0, hitobj_count = 0; - std::array hitobj_values = {}; - objnum_t track_goal = 0; // Object this object is tracking. - fix multiplier = 0; // Power if this is a fusion bolt (or other super weapon to be added). + uint8_t hitobj_pos{}, hitobj_count{}; + std::array hitobj_values{}; + objnum_t track_goal{}; // Object this object is tracking. + fix multiplier{}; // Power if this is a fusion bolt (or other super weapon to be added). uint_fast8_t test_set_hitobj(const vcobjidx_t o); uint_fast8_t test_hitobj(const vcobjidx_t o) const; icobjidx_t get_last_hitobj() const; diff --git a/similar/editor/medrobot.cpp b/similar/editor/medrobot.cpp index f72e9706ed..ccc501e9c1 100644 --- a/similar/editor/medrobot.cpp +++ b/similar/editor/medrobot.cpp @@ -83,7 +83,7 @@ struct robot_dialog : UI_DIALOG std::unique_ptr quitButton, prev_powerup_type, next_powerup_type, prev_powerup_id, next_powerup_id, prev_powerup_count, next_powerup_count, prev_robot_type, next_robot_type, next_segment, prev_object, next_object, delete_object, new_object, set_path; std::array, 6> initialMode; // Number of boxes, AI modes fix64 time; - vms_angvec angles = {}, goody_angles = {}; + vms_angvec angles{}, goody_angles{}; int old_object; virtual window_event_result callback_handler(const d_event &) override; }; diff --git a/similar/main/bm.cpp b/similar/main/bm.cpp index 0c395186e9..b2809b24a9 100644 --- a/similar/main/bm.cpp +++ b/similar/main/bm.cpp @@ -227,7 +227,7 @@ void properties_read_cmp(d_level_shared_robot_info_state &LevelSharedRobotInfoSt range_for (auto &i, ObjBitmapPtrs) { if (const auto oi = ObjBitmaps.valid_index(PHYSFSX_readShort(fp))) - i = *oi; + i = {*oi}; else i = {}; } @@ -375,7 +375,7 @@ void bm_read_all(d_level_shared_robot_info_state &LevelSharedRobotInfoState, d_v range_for (auto &i, partial_range(ObjBitmapPtrs, N_ObjBitmaps)) { if (const auto oi = ObjBitmaps.valid_index(PHYSFSX_readShort(fp))) - i = *oi; + i = {*oi}; else i = {}; } @@ -523,7 +523,7 @@ void bm_read_extra_robots(const char *fname, Mission::descent_version_type type) range_for (auto &i, partial_range(ObjBitmapPtrs, N_D2_OBJBITMAPPTRS.value, N_D2_OBJBITMAPPTRS + t)) { if (const auto oi = ObjBitmaps.valid_index(PHYSFSX_readShort(fp))) - i = *oi; + i = {*oi}; else i = {}; } diff --git a/similar/main/console.cpp b/similar/main/console.cpp index c7c14bc525..f543a472e1 100644 --- a/similar/main/console.cpp +++ b/similar/main/console.cpp @@ -184,7 +184,7 @@ static void con_print_file(const char *const buffer) tm_hour, tm_min, tm_sec; #ifdef _WIN32 #define DXX_LF "\r\n" - SYSTEMTIME st = {}; + SYSTEMTIME st{}; GetLocalTime(&st); #if DXX_CONSOLE_TIME_SHOW_YMD tm_year = st.wYear; diff --git a/similar/main/credits.cpp b/similar/main/credits.cpp index 292f8a7f1a..b24b5a2a74 100644 --- a/similar/main/credits.cpp +++ b/similar/main/credits.cpp @@ -81,13 +81,13 @@ struct credits_window : window { RAIIPHYSFS_File file; const uint8_t have_bin_file; - std::array, NUM_LINES> buffer = {}; + std::array, NUM_LINES> buffer{}; int buffer_line = 0; int first_line_offset = 0; int extra_inc = 0; int done = 0; int row = 0; - grs_main_bitmap backdrop = {}; + grs_main_bitmap backdrop{}; credits_window(grs_canvas &src, int x, int y, int w, int h, RAIIPHYSFS_File f, const uint8_t bin_file) : window(src, x, y, w, h), file(std::move(f)), have_bin_file(bin_file) { diff --git a/similar/main/gauges.cpp b/similar/main/gauges.cpp index c13766b5e2..40a494332e 100644 --- a/similar/main/gauges.cpp +++ b/similar/main/gauges.cpp @@ -847,13 +847,13 @@ constexpr std::array weapon_windows_hires = {{ struct gauge_inset_window { - fix fade_value = 0; - weapon_index old_weapon = {}; - weapon_box_state box_state = weapon_box_state::set; + fix fade_value{}; + weapon_index old_weapon{}; + weapon_box_state box_state{weapon_box_state::set}; #if defined(DXX_BUILD_DESCENT_II) - weapon_box_user user = weapon_box_user::weapon; - uint8_t overlap_dirty = 0; - fix time_static_played = 0; + weapon_box_user user{weapon_box_user::weapon}; + uint8_t overlap_dirty{}; + fix time_static_played{}; #endif }; @@ -2217,8 +2217,7 @@ void close_gauges() namespace dsx { void init_gauges() { - inset_window[gauge_inset_window_view::primary] = {}; - inset_window[gauge_inset_window_view::secondary] = {}; + inset_window = {}; old_laser_level = {}; } } @@ -3739,7 +3738,7 @@ void draw_hud(const d_robot_info_array &Robot_info, grs_canvas &canvas, const ob if (PlayerCfg.CockpitMode[1] == cockpit_mode_t::status_bar || PlayerCfg.CockpitMode[1] == cockpit_mode_t::full_screen) hud_show_homing_warning(canvas, player_info.homing_object_dist); - const local_multires_gauge_graphic multires_gauge_graphic = {}; + const local_multires_gauge_graphic multires_gauge_graphic{}; const hud_draw_context_hs_mr hudctx(canvas, grd_curscreen->get_screen_width(), grd_curscreen->get_screen_height(), multires_gauge_graphic); if (PlayerCfg.CockpitMode[1] == cockpit_mode_t::full_screen) { diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index 8fa186143f..c55e9a0f26 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -139,9 +139,9 @@ struct mission_subdir_stats struct mission_name_and_version { #if defined(DXX_BUILD_DESCENT_II) - const Mission::descent_version_type descent_version = {}; + const Mission::descent_version_type descent_version{}; #endif - char *const name = nullptr; + char *const name{}; mission_name_and_version() = default; mission_name_and_version(Mission::descent_version_type, char *); }; diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index c024e49945..54cbf9fa82 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -1273,7 +1273,7 @@ struct netgame_list_game_menu : netgame_list_game_menu_items, direct_join, newme { unsigned num_active_udp_games = 0; uint8_t num_active_udp_changed = 1; - std::array Active_udp_games = {}; + std::array Active_udp_games{}; netgame_list_game_menu(grs_canvas &src) : newmenu(menu_title{"NETGAMES"}, menu_subtitle{nullptr}, menu_filename{nullptr}, tiny_mode_flag::tiny, tab_processing_flag::process, adjusted_citem::create(menus, 0), src) { @@ -6532,7 +6532,7 @@ static int udp_tracker_register() game_info_light light; std::size_t len = 1; const auto light_span = net_udp_prepare_light_game_info(LevelUniqueObjectState.ControlCenterState, Netgame, light.buf); - std::array pBuf = {}; + std::array pBuf{}; unsigned len = 1; pBuf[0] = UPID_TRACKER_REQGAMES; @@ -6565,7 +6565,7 @@ static int udp_tracker_process_game(const std::span buf, const _s return -1; const char *p0 = NULL, *p1 = NULL, *p3 = NULL; - char sIP[47] = {}; + char sIP[47]{}; std::array sPort{}; uint16_t iPort = 0; From b9aa93295e9c2cd2f30d5a4b6f7137573053ff75 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 25 Nov 2023 19:53:51 +0000 Subject: [PATCH 05/32] Extend enumerate from forward_iterator to bidirectional_iterator --- common/main/d_enumerate.h | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/common/main/d_enumerate.h b/common/main/d_enumerate.h index b67f662f12..93e78a9954 100644 --- a/common/main/d_enumerate.h +++ b/common/main/d_enumerate.h @@ -75,13 +75,13 @@ class enumerated_iterator range_index_type m_idx; public: using index_type = range_index_type; - using iterator_category = std::forward_iterator_tag; + using iterator_category = typename std::iterator_traits::iterator_category; using value_type = typename adjust_iterator_dereference_type::value_type; using difference_type = std::ptrdiff_t; using pointer = value_type *; using reference = value_type &; - constexpr enumerated_iterator(range_iterator_type &&iter, const index_type idx) : - m_iter(std::move(iter)), m_idx(idx) + constexpr enumerated_iterator(range_iterator_type &&iter, index_type idx) : + m_iter{std::move(iter)}, m_idx{std::move(idx)} { } value_type operator*() const @@ -113,6 +113,23 @@ class enumerated_iterator ++ * this; return result; } + enumerated_iterator &operator--() + requires(std::bidirectional_iterator) + { + -- m_iter; + if constexpr (std::is_enum::value) + m_idx = static_cast(static_cast::type>(m_idx) - 1u); + else + -- m_idx; + return *this; + } + enumerated_iterator operator--(int) + requires(std::bidirectional_iterator) + { + auto result = *this; + -- * this; + return result; + } constexpr bool operator==(const enumerated_sentinel &i) const { return m_iter == i.m_sentinel; @@ -129,8 +146,10 @@ class enumerate : ranges::subrange range_iterator_type, range_sentinel_type, d_enumerate::detail::adjust_iterator_dereference_type::type>>; - const range_index_type m_idx; + [[no_unique_address]] + range_index_type m_idx; public: + using base_type::size; using index_type = range_index_type; template /* Block using `enumerate` on an ephemeral range, since the storage @@ -139,8 +158,8 @@ class enumerate : ranges::subrange * storage may cease to exist after this constructor returns. */ requires(ranges::borrowed_range) - enumerate(range_type &&t, const index_type i = index_type{}) : - base_type(std::forward(t)), m_idx(i) + enumerate(range_type &&t, index_type i = index_type{}) : + base_type{std::forward(t)}, m_idx{std::move(i)} { static_assert(std::is_rvalue_reference::value || !std::is_rvalue_reference::value, "lvalue range must not produce rvalue reference enumerated_value"); } From cda3e7febbda52dd32d170ea9771e7231e8906bf Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 25 Nov 2023 19:53:51 +0000 Subject: [PATCH 06/32] Extend zip from forward_iterator to bidirectional_iterator Propagate the most derived iterator type. --- common/main/d_zip.h | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/common/main/d_zip.h b/common/main/d_zip.h index 1029392e67..2f6903c63c 100644 --- a/common/main/d_zip.h +++ b/common/main/d_zip.h @@ -6,6 +6,7 @@ */ #pragma once +#include #include #include #include @@ -34,6 +35,12 @@ void increment_iterator(std::tuple &iterator, std::index discard_arguments(++(std::get(iterator))...); } +template +void decrement_iterator(std::tuple &iterator, std::index_sequence) +{ + discard_arguments(--(std::get(iterator))...); +} + template auto dereference_iterator(const std::tuple &iterator, std::index_sequence) { @@ -52,6 +59,15 @@ auto dereference_iterator(const std::tuple &iterator, st >(*(std::get(iterator))...); } +/* This is declared, but never defined. It is used only for a decltype() + * expression. + * + * Given a tuple of iterator types, return the most-derived iterator_category + * that all the iterator types satisfy. + */ +template +typename std::common_type::iterator_category...>::type common_iterator_category(std::tuple); + /* The overloads of get_static_size are declared, but never defined. They * exist only for use in decltype() expressions. */ @@ -276,7 +292,7 @@ class zip_iterator : range_iterator_type using value_type = decltype(d_zip::detail::dereference_iterator(std::declval(), index_sequence_type())); using pointer = value_type *; using reference = value_type &; - using iterator_category = std::forward_iterator_tag; + using iterator_category = decltype(d_zip::detail::common_iterator_category(std::declval())); auto operator*() const { return d_zip::detail::dereference_iterator(*this, index_sequence_type()); @@ -291,14 +307,29 @@ class zip_iterator : range_iterator_type */ zip_iterator operator++(int) { - auto result = *this; - d_zip::detail::increment_iterator(*this, index_sequence_type()); + auto result{*this}; + ++ *this; + return result; + } + zip_iterator &operator--() + requires(std::derived_from) + { + d_zip::detail::decrement_iterator(*this, index_sequence_type()); + return *this; + } + zip_iterator operator--(int) + requires(std::derived_from) + { + auto result{*this}; + -- *this; return result; } auto operator-(const zip_iterator &i) const + requires(std::derived_from) { return std::get<0>(static_cast(*this)) - std::get<0>(static_cast(i)); } + constexpr bool operator==(const zip_iterator &) const = default; constexpr bool operator==(const range_sentinel_type &i) const { return d_zip::detail::compare_zip_iterators(*this, i, index_sequence_type()); From 6ae11847ed6a952e9da60448097bff187ce08189 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 25 Nov 2023 19:53:51 +0000 Subject: [PATCH 07/32] Return vms_vector from extract_vector_from_segment --- similar/main/gameseg.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/similar/main/gameseg.cpp b/similar/main/gameseg.cpp index de8b3304f2..2ff5a58139 100644 --- a/similar/main/gameseg.cpp +++ b/similar/main/gameseg.cpp @@ -1119,9 +1119,10 @@ namespace { // ------------------------------------------------------------------------------------------ // Extract a vector from a segment. The vector goes from the start face to the end face. // The point on each face is the average of the four points forming the face. -static void extract_vector_from_segment(fvcvertptr &vcvertptr, const shared_segment &sp, vms_vector &vp, const sidenum_t istart, const sidenum_t iend) +[[nodiscard]] +static vms_vector extract_vector_from_segment(fvcvertptr &vcvertptr, const shared_segment &sp, const sidenum_t istart, const sidenum_t iend) { - vp = {}; + vms_vector vp{}; auto &start = Side_to_verts[istart]; auto &end = Side_to_verts[iend]; auto &verts = sp.verts; @@ -1131,16 +1132,15 @@ static void extract_vector_from_segment(fvcvertptr &vcvertptr, const shared_segm vm_vec_add2(vp, vcvertptr(verts[ve])); } vm_vec_scale(vp,F1_0/4); + return vp; } } //create a matrix that describes the orientation of the given segment void extract_orient_from_segment(fvcvertptr &vcvertptr, vms_matrix &m, const shared_segment &seg) { - vms_vector fvec,uvec; - - extract_vector_from_segment(vcvertptr, seg, fvec, sidenum_t::WFRONT, sidenum_t::WBACK); - extract_vector_from_segment(vcvertptr, seg, uvec, sidenum_t::WBOTTOM, sidenum_t::WTOP); + const auto fvec{extract_vector_from_segment(vcvertptr, seg, sidenum_t::WFRONT, sidenum_t::WBACK)}; + const auto uvec{extract_vector_from_segment(vcvertptr, seg, sidenum_t::WBOTTOM, sidenum_t::WTOP)}; //vector to matrix does normalizations and orthogonalizations vm_vector_2_matrix(m, fvec, &uvec, nullptr); @@ -1156,7 +1156,7 @@ namespace { // to the center of the back face of the segment. void extract_forward_vector_from_segment(fvcvertptr &vcvertptr, const shared_segment &sp, vms_vector &vp) { - extract_vector_from_segment(vcvertptr, sp, vp, sidenum_t::WFRONT, sidenum_t::WBACK); + vp = extract_vector_from_segment(vcvertptr, sp, sidenum_t::WFRONT, sidenum_t::WBACK); } // ------------------------------------------------------------------------------------------ @@ -1165,7 +1165,7 @@ void extract_forward_vector_from_segment(fvcvertptr &vcvertptr, const shared_seg // to the center of the right face of the segment. void extract_right_vector_from_segment(fvcvertptr &vcvertptr, const shared_segment &sp, vms_vector &vp) { - extract_vector_from_segment(vcvertptr, sp, vp, sidenum_t::WLEFT, sidenum_t::WRIGHT); + vp = extract_vector_from_segment(vcvertptr, sp, sidenum_t::WLEFT, sidenum_t::WRIGHT); } // ------------------------------------------------------------------------------------------ @@ -1174,7 +1174,7 @@ void extract_right_vector_from_segment(fvcvertptr &vcvertptr, const shared_segme // to the center of the top face of the segment. void extract_up_vector_from_segment(fvcvertptr &vcvertptr, const shared_segment &sp, vms_vector &vp) { - extract_vector_from_segment(vcvertptr, sp, vp, sidenum_t::WBOTTOM, sidenum_t::WTOP); + vp = extract_vector_from_segment(vcvertptr, sp, sidenum_t::WBOTTOM, sidenum_t::WTOP); } #if !DXX_USE_EDITOR From a76068d26a9bd1e7c8d39ee60ab7f603d42194d5 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 25 Nov 2023 19:53:51 +0000 Subject: [PATCH 08/32] Use abbreviated template for d_zip::detail::discard_arguments --- common/main/d_zip.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/main/d_zip.h b/common/main/d_zip.h index 2f6903c63c..48dfa13656 100644 --- a/common/main/d_zip.h +++ b/common/main/d_zip.h @@ -20,8 +20,7 @@ namespace d_zip { namespace detail { -template -void discard_arguments(T &&...) +void discard_arguments(auto &&...) { } From 54f6c0ec08ce1bdab87c92f93e3d93cbfd581fa1 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 25 Nov 2023 19:53:51 +0000 Subject: [PATCH 09/32] Flatten setup of editor function table Only one table is ever used. Reference it directly, rather than requiring a setup step that stores a pointer and length for it. Move the accessor functions to the file where the table is defined. Rewrite them to use range-based for, to make access simpler. --- common/editor/func.cpp | 62 ------------------- common/include/editor/kfuncs.h | 40 ------------ common/include/func.h | 23 +++---- contrib/dxx-rebirth.xcodeproj/project.pbxproj | 2 - similar/editor/kfuncs.cpp | 40 ++++++++++-- similar/editor/med.cpp | 3 - 6 files changed, 47 insertions(+), 123 deletions(-) delete mode 100644 common/include/editor/kfuncs.h diff --git a/common/editor/func.cpp b/common/editor/func.cpp index cba19d442a..a85967f9c8 100644 --- a/common/editor/func.cpp +++ b/common/editor/func.cpp @@ -34,73 +34,11 @@ namespace dcx { #define MAX_PARAMS 10 -static const FUNCTION * func_table = NULL; -static int func_size = 0; -static int initialized = 0; static int func_params[MAX_PARAMS]; -void func_init( const FUNCTION * funtable, int size ) -{ - if (!initialized) - { - initialized = 1; - func_table = funtable; - func_size = size; - atexit( func_close ); - } -} - - -void func_close() -{ - if (initialized) - { - initialized = 0; - func_table = NULL; - func_size = 0; - } -} - -int (*func_get( char * name, int * numparams ))(void) -{ - for (int i=0; i namespace dcx { -typedef struct { + +struct FUNCTION +{ + using callable = int(*)(void); const char * name; int nparams; - int (*cfunction)(void); -} FUNCTION; + callable cfunction; +}; -void func_init( const FUNCTION * funtable, int size ); -void func_close(); -int (*func_get( char * name, int * numparams ))(void); -int (*func_nget( int func_number, int * numparams, const char **name ))(void); int func_get_param( int n ); -int func_get_index( char * name ); -} +FUNCTION::callable func_get(const char *name, int *numparams); +FUNCTION::callable func_nget(std::size_t func_number, int *numparams, const char **name); +int func_get_index(const char *name); -#endif +} diff --git a/contrib/dxx-rebirth.xcodeproj/project.pbxproj b/contrib/dxx-rebirth.xcodeproj/project.pbxproj index 5adce5f1c7..50d1b56695 100644 --- a/contrib/dxx-rebirth.xcodeproj/project.pbxproj +++ b/contrib/dxx-rebirth.xcodeproj/project.pbxproj @@ -302,7 +302,6 @@ 14F8A9741A2D6320003AA93A /* eswitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = eswitch.h; sourceTree = ""; }; 14F8A9751A2D6320003AA93A /* info.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = info.h; sourceTree = ""; }; 14F8A9761A2D6320003AA93A /* kdefs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = kdefs.h; sourceTree = ""; }; - 14F8A9771A2D6320003AA93A /* kfuncs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = kfuncs.h; sourceTree = ""; }; 14F8A9781A2D6320003AA93A /* macro.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macro.h; sourceTree = ""; }; 14F8A9791A2D6320003AA93A /* meddraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = meddraw.h; sourceTree = ""; }; 14F8A97A1A2D6320003AA93A /* medlisp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = medlisp.h; sourceTree = ""; }; @@ -904,7 +903,6 @@ 14F8A9741A2D6320003AA93A /* eswitch.h */, 14F8A9751A2D6320003AA93A /* info.h */, 14F8A9761A2D6320003AA93A /* kdefs.h */, - 14F8A9771A2D6320003AA93A /* kfuncs.h */, 14F8A9781A2D6320003AA93A /* macro.h */, 14F8A9791A2D6320003AA93A /* meddraw.h */, 14F8A97A1A2D6320003AA93A /* medlisp.h */, diff --git a/similar/editor/kfuncs.cpp b/similar/editor/kfuncs.cpp index 185799cf6c..a75b2a4c27 100644 --- a/similar/editor/kfuncs.cpp +++ b/similar/editor/kfuncs.cpp @@ -26,6 +26,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include #include "inferno.h" #include "func.h" +#include "d_enumerate.h" #include "editor/kdefs.h" #include "editor/editor.h" #include "dxxerror.h" @@ -37,7 +38,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "editor/medmisc.h" #include "editor/texpage.h" #include "editor/ehostage.h" -#include "kfuncs.h" #include "dsx-ns.h" namespace dsx { @@ -377,13 +377,43 @@ const FUNCTION med_functions[] = { // In gamesavec { "rename-level", 0, get_level_name }, +}; -// The terminating marker -{ NULL, 0, NULL } }; +} + +namespace dcx { /* This should be dsx, but UI code in common needs to see these accessors */ + +FUNCTION::callable func_get(const char *name, int *numparams) +{ + for (auto &&f : med_functions) + if (!d_stricmp(name, f.name)) + { + *numparams = f.nparams; + return f.cfunction; + } + return NULL; +} + +int func_get_index(const char *name) +{ + for (auto &&[i, f] : enumerate(med_functions)) + if (!d_stricmp(name, f.name)) + { + return i; + } + return -1; +} -void init_med_functions() +FUNCTION::callable func_nget(std::size_t func_number, int *numparams, const char **name) { - func_init(med_functions, (sizeof(med_functions)/sizeof(FUNCTION))-1 ); + if (func_number < std::size(med_functions)) + { + auto &f = med_functions[func_number]; + *name = f.name; + *numparams = f.nparams; + return f.cfunction; + } + return NULL; } } diff --git a/similar/editor/med.cpp b/similar/editor/med.cpp index 036aeba672..8a7a95aa07 100644 --- a/similar/editor/med.cpp +++ b/similar/editor/med.cpp @@ -54,7 +54,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "kconfig.h" #include "mouse.h" #include "dxxerror.h" -#include "kfuncs.h" #ifdef INCLUDE_XLISP #include "medlisp.h" #endif @@ -371,8 +370,6 @@ void init_editor() return; } - init_med_functions(); // Must be called before medlisp_init - for (auto &&[idx, value] : enumerate(pads)) if (!ui_pad_read(idx, value)) { From 7034310711cf0228843daddc4985d1e02313f875 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 2 Dec 2023 21:31:35 +0000 Subject: [PATCH 10/32] Simplify `enumerated_iterator` type Move `adjust_iterator_dereference_type` out of the template parameter list and store it as a member typedef. This reduces the complexity of the name of the `enumerated_iterator` type. --- common/main/d_enumerate.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/common/main/d_enumerate.h b/common/main/d_enumerate.h index 93e78a9954..fba2e08061 100644 --- a/common/main/d_enumerate.h +++ b/common/main/d_enumerate.h @@ -68,9 +68,10 @@ class enumerated_sentinel } }; -template +template class enumerated_iterator { + using adjust_iterator_dereference_type = d_enumerate::detail::adjust_iterator_dereference_type())>::type>; range_iterator_type m_iter; range_index_type m_idx; public: @@ -109,7 +110,7 @@ class enumerated_iterator } enumerated_iterator operator++(int) { - auto result = *this; + auto result{*this}; ++ * this; return result; } @@ -126,7 +127,7 @@ class enumerated_iterator enumerated_iterator operator--(int) requires(std::bidirectional_iterator) { - auto result = *this; + auto result{*this}; -- * this; return result; } @@ -140,12 +141,10 @@ template { using base_type = ranges::subrange; - using iterator_dereference_type = decltype(*std::declval()); using enumerated_iterator_type = enumerated_iterator< range_index_type, range_iterator_type, - range_sentinel_type, - d_enumerate::detail::adjust_iterator_dereference_type::type>>; + range_sentinel_type>; [[no_unique_address]] range_index_type m_idx; public: @@ -161,7 +160,6 @@ class enumerate : ranges::subrange enumerate(range_type &&t, index_type i = index_type{}) : base_type{std::forward(t)}, m_idx{std::move(i)} { - static_assert(std::is_rvalue_reference::value || !std::is_rvalue_reference::value, "lvalue range must not produce rvalue reference enumerated_value"); } enumerated_iterator_type begin() const { From 3b8dfc180ab937d913a8b0f9230859596abe1872 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 2 Dec 2023 21:31:35 +0000 Subject: [PATCH 11/32] Simplify unittest static_assert tests C++20 concepts can be used directly as predicates. Use that instead of a dummy template structure. This still produces detailed compiler diagnostics, and tends to be more readable than the dummy template. --- common/unittest/enumerate.cpp | 11 ++++------- common/unittest/partial_range.cpp | 15 ++++++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/common/unittest/enumerate.cpp b/common/unittest/enumerate.cpp index 340744667b..86ac53fbe7 100644 --- a/common/unittest/enumerate.cpp +++ b/common/unittest/enumerate.cpp @@ -63,13 +63,10 @@ BOOST_AUTO_TEST_CASE(enumerate_starting_value) * static_assert can produce a better error message than letting it fail * at runtime. */ -template -struct assert_index_type -{ - static_assert(std::is_same::value); -}; +template +concept assert_index_type = std::same_as; -template struct assert_index_type &>()))>; +static_assert(assert_index_type &>()))>); template struct custom_index_type : std::array @@ -79,4 +76,4 @@ struct custom_index_type : std::array }; enum class e1 : unsigned char; -template struct assert_index_type&>()))>; +static_assert(assert_index_type&>()))>); diff --git a/common/unittest/partial_range.cpp b/common/unittest/partial_range.cpp index 93505dda5d..666f8c8331 100644 --- a/common/unittest/partial_range.cpp +++ b/common/unittest/partial_range.cpp @@ -105,13 +105,10 @@ BOOST_AUTO_TEST_CASE(range_slice_reversed_begin_1_end_3) * static_assert can produce a better error message than letting it fail * at runtime. */ -template -struct assert_index_type : std::true_type -{ - static_assert(std::is_same::value); -}; +template +concept assert_index_type = std::same_as; -static_assert(assert_index_type&>(), 0u, 1u))>::value); +static_assert(assert_index_type&>(), 0u, 1u))>); template struct custom_index_type_only : std::array { @@ -129,6 +126,6 @@ enum class e1 : unsigned char; /* The type is `void` because resolving index_type fails since `int *` * is not a valid argument type to operator[]. */ -static_assert(assert_index_type&>(), 0u, 1u))>::value); -static_assert(assert_index_type&>(), 0u, 1u))>::value); -static_assert(assert_index_type&>(), 0u, 1u))>::value); +static_assert(assert_index_type&>(), 0u, 1u))>); +static_assert(assert_index_type&>(), 0u, 1u))>); +static_assert(assert_index_type&>(), 0u, 1u))>); From 3b103dd99bb133c917a7bae8c2c0bc275c149a8b Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 2 Dec 2023 21:31:35 +0000 Subject: [PATCH 12/32] Convert serial static checks to use concept predicates These produce better error messages when the check fails. --- common/include/serial.h | 29 +++++++++++++++++++---------- common/unittest/serial.cpp | 10 ++++++++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/common/include/serial.h b/common/include/serial.h index 90e714fb1d..3b72f8a515 100644 --- a/common/include/serial.h +++ b/common/include/serial.h @@ -24,6 +24,9 @@ namespace serial { +template +concept check_equal_value = (Expected == Actual); + template class message; @@ -327,8 +330,11 @@ static inline detail::sign_extend_type sign_ #define DEFINE_SERIAL_MUTABLE_UDT_TO_MESSAGE(TYPE, NAME, MEMBERLIST) \ _DEFINE_SERIAL_UDT_TO_MESSAGE(TYPE, NAME, MEMBERLIST) +template +concept check_serial_udt_maximum_message_size = check_equal_value; + #define ASSERT_SERIAL_UDT_MESSAGE_SIZE(T, SIZE) \ - assert_equal(serial::class_type::maximum_size, SIZE, "sizeof(" #T ") is not " #SIZE) + static_assert(serial::check_serial_udt_maximum_message_size>) template ::type>::type, T1>> struct udt_message_compatible_same_type : base_type @@ -390,8 +396,8 @@ union unaligned_storage typename std::conditional, typename std::conditional>::type::type i; uint8_t u[N]; - assert_equal(sizeof(i), N, "sizeof(i) is not N"); - assert_equal(sizeof(a), sizeof(u), "sizeof(T) is not N"); + static_assert(check_equal_value); + static_assert(check_equal_value); }; template @@ -512,16 +518,19 @@ static constexpr T bswap(const T u) */ } -assert_equal(bswap(static_cast(1)), 1, ""); +template +concept check_bswap = check_equal_value; + +static_assert(check_bswap); -assert_equal(bswap(static_cast(0x12)), 0x1200, ""); -assert_equal(bswap(static_cast(0x92)), 0x9200, ""); -assert_equal(bswap(static_cast(0x9200)), 0x92, ""); -assert_equal(bswap(static_cast(0x102)), 0x201, ""); +static_assert(check_bswap); +static_assert(check_bswap); +static_assert(check_bswap); +static_assert(check_bswap); -assert_equal(bswap(static_cast(0x102)), 0x2010000, ""); +static_assert(check_bswap); -assert_equal(bswap(static_cast(0x102)), 0x201000000000000ull, ""); +static_assert(check_bswap); namespace reader { diff --git a/common/unittest/serial.cpp b/common/unittest/serial.cpp index 4bec4eb0a3..4d30d8fc84 100644 --- a/common/unittest/serial.cpp +++ b/common/unittest/serial.cpp @@ -9,8 +9,14 @@ static_assert(!serial::is_message::value, ""); static_assert(serial::is_message>::value, ""); -assert_equal(serial::detail::size_base<4>::maximum_size, 4, ""); -assert_equal((serial::detail::size_base<4, 2>::minimum_size), 2, ""); +template +concept check_maximum_size = serial::check_equal_value; + +template +concept check_minimum_size = serial::check_equal_value; + +static_assert(check_maximum_size<4, serial::detail::size_base<4>>); +static_assert(check_minimum_size<2, serial::detail::size_base<4, 2>>); static_assert(!serial::is_cxx_array::value, ""); static_assert(!serial::is_cxx_array::value, ""); From f1e0b3ab583e65ec8f615ac0e365ce5dd9f642a8 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 2 Dec 2023 21:31:35 +0000 Subject: [PATCH 13/32] Simplify xrange static_assert --- common/unittest/xrange.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/common/unittest/xrange.cpp b/common/unittest/xrange.cpp index bf96ae1294..e930b73a91 100644 --- a/common/unittest/xrange.cpp +++ b/common/unittest/xrange.cpp @@ -136,10 +136,4 @@ BOOST_AUTO_TEST_CASE(xrange_iter_values) BOOST_TEST(*std::next(r.begin(), 2) == 2); } -template -requires(std::ranges::borrowed_range) -struct check_is_borrowed_range : std::true_type -{ -}; - -static_assert(check_is_borrowed_range::value); +static_assert(std::ranges::borrowed_range); From 9bb539431ccfc7d41e5228edd5a8bb0e92816310 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 2 Dec 2023 21:31:35 +0000 Subject: [PATCH 14/32] Convert zip unit tests to use concepts for static checks --- common/unittest/zip.cpp | 58 ++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/common/unittest/zip.cpp b/common/unittest/zip.cpp index be5ae8fb75..2ce8b38efd 100644 --- a/common/unittest/zip.cpp +++ b/common/unittest/zip.cpp @@ -134,13 +134,10 @@ BOOST_AUTO_TEST_CASE(zip_xrange) * static_assert can produce a better error message than letting it fail * at runtime. */ -template -requires(std::is_same::value) -struct assert_index_type : std::true_type -{ -}; +template +concept assert_index_type = std::same_as; -static_assert(assert_index_type &>(), std::declval &>()))>::value); +static_assert(assert_index_type &>(), std::declval &>()))>); template struct custom_index_type : std::array @@ -151,36 +148,19 @@ struct custom_index_type : std::array enum class e1 : unsigned char; enum class e2 : unsigned char; -static_assert(assert_index_type&>(), std::declval&>()))>::value); -static_assert(assert_index_type&>(), std::declval&>()))>::value); - -template -requires(std::is_same::value) -using assert_same_type = std::true_type; +static_assert(assert_index_type&>(), std::declval&>()))>); +static_assert(assert_index_type&>(), std::declval&>()))>); -static_assert(assert_same_type()))>::value); -static_assert(assert_same_type::iterator>()))>::value); -static_assert(assert_same_type, decltype(d_zip::detail::get_static_size(std::declval()))>::value); -static_assert(assert_same_type, decltype(d_zip::detail::get_static_size(std::declval &>()))>::value); - -template -requires(std::ranges::range) -struct check_is_range : std::true_type -{ -}; - -template -requires(std::ranges::borrowed_range) -struct check_is_borrowed_range : std::true_type -{ -}; +static_assert(std::same_as()))>); +static_assert(std::same_as::iterator>()))>); +static_assert(std::same_as, decltype(d_zip::detail::get_static_size(std::declval()))>); +static_assert(std::same_as, decltype(d_zip::detail::get_static_size(std::declval &>()))>); -static_assert(check_is_borrowed_range()))>::value); +static_assert(std::ranges::borrowed_range()))>); struct difference_range { struct iterator { - int *operator *() const; iterator &operator++(); iterator operator++(int); constexpr auto operator<=>(const iterator &) const = default; @@ -189,6 +169,7 @@ struct difference_range using pointer = value_type *; using reference = value_type &; using iterator_category = std::forward_iterator_tag; + reference operator *() const; difference_type operator-(const iterator &) const; }; struct index_type {}; @@ -196,12 +177,13 @@ struct difference_range iterator end(); }; -static_assert(check_is_range())>::value); -static_assert(check_is_borrowed_range())>::value); -static_assert(assert_same_type()).begin())::difference_type>::value); +static_assert(std::ranges::range); +static_assert(std::ranges::input_range); +static_assert(std::ranges::borrowed_range); +static_assert(std::same_as()).begin())::difference_type>); -static_assert(assert_same_type>::type>::value); -static_assert(assert_same_type, d_zip::detail::minimum_static_size, std::nullptr_t>>::type>::value); -static_assert(assert_same_type, d_zip::detail::minimum_static_size>>::type>::value); -static_assert(assert_same_type, d_zip::detail::minimum_static_size, std::integral_constant>>::type>::value); -static_assert(assert_same_type, d_zip::detail::minimum_static_size, std::nullptr_t, std::integral_constant>>::type>::value); +static_assert(std::same_as>::type>); +static_assert(std::same_as, d_zip::detail::minimum_static_size, std::nullptr_t>>::type>); +static_assert(std::same_as, d_zip::detail::minimum_static_size>>::type>); +static_assert(std::same_as, d_zip::detail::minimum_static_size, std::integral_constant>>::type>); +static_assert(std::same_as, d_zip::detail::minimum_static_size, std::nullptr_t, std::integral_constant>>::type>); From 77a590e3aeefceda9624192e4a9d735d7fc7c900 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 15/32] Use a constructor for BuiltinMovies Move the initialization into a constructor, so that make_unique does not need to value-initialize the structure. init_movie initializes the pathname on success and on failure. --- d2x-rebirth/main/movie.cpp | 8 +++++--- d2x-rebirth/main/movie.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/d2x-rebirth/main/movie.cpp b/d2x-rebirth/main/movie.cpp index bc13254158..974fa9bd38 100644 --- a/d2x-rebirth/main/movie.cpp +++ b/d2x-rebirth/main/movie.cpp @@ -644,11 +644,13 @@ std::unique_ptr init_movies() { if (GameArg.SysNoMovies) return nullptr; + return std::make_unique(); +} - auto r = std::make_unique(); - for (auto &&[f, m] : zip(movielib_files, r->movies)) +BuiltinMovies::BuiltinMovies() +{ + for (auto &&[f, m] : zip(movielib_files, movies)) init_movie(&f[0], 1, m); - return r; } LoadedMovie::~LoadedMovie() diff --git a/d2x-rebirth/main/movie.h b/d2x-rebirth/main/movie.h index 0f966dd7f6..76cf954e7a 100644 --- a/d2x-rebirth/main/movie.h +++ b/d2x-rebirth/main/movie.h @@ -82,6 +82,7 @@ struct LoadedMovieWithResolution : LoadedMovie struct BuiltinMovies { std::array movies; + BuiltinMovies(); }; // find and initialize the movie libraries From ee778f863dd658306c1c5d32fd285606ebfc97ce Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 16/32] Use abbreviated concepts in convert_integer --- common/main/nvparse.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/main/nvparse.h b/common/main/nvparse.h index 9f0a3f25e8..71c12267c3 100644 --- a/common/main/nvparse.h +++ b/common/main/nvparse.h @@ -23,8 +23,9 @@ static inline bool cmp(const char *token, const char *equal, const char (&name)[ return &token[N - 1] == equal && !strncmp(token, name, N - 1); } -template -static inline std::optional convert_integer(const char *value, int base, auto libc_str_to_integer) +template +[[nodiscard]] +static inline std::optional convert_integer(const char *const value, int base, auto libc_str_to_integer) { char *e; const auto r = libc_str_to_integer(value, &e, base); @@ -42,22 +43,21 @@ static inline std::optional convert_integer(const char *value, int base, auto return static_cast(r); } -template -requires(std::is_signed::value) +template +[[nodiscard]] static inline auto convert_integer(const char *value, int base = 10) { return convert_integer(value, base, std::strtol); } -template -requires(std::is_unsigned::value) +template +[[nodiscard]] static inline auto convert_integer(const char *value, int base = 10) { return convert_integer(value, base, std::strtoul); } -template -requires(std::is_integral::value) +template static inline void convert_integer(T &t, const char *value, int base = 10) { if (auto r = convert_integer(value, base)) From 27bed5edefd30ad76acb20f46cfaab2029760744 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 17/32] Reduce scope of type value `p` --- similar/main/mission.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index c55e9a0f26..084dc92f39 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -566,9 +566,8 @@ static int read_mission_file(mission_list_type &mission_list, mission_candidate_ { if (istok(temp,"type")) { - const auto p = get_value(temp); //get mission type - if (p) + if (const auto p = get_value(temp)) mission->anarchy_only_flag = istok(p, "anarchy") ? Mission::anarchy_only_level::only_anarchy_games : Mission::anarchy_only_level::allow_any_game; } } From 1024796db548a4bf8c80d9f0e225175b8c9c394f Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 18/32] Move some valptridx static_assert checks to requires() --- common/include/valptridx.h | 45 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/common/include/valptridx.h b/common/include/valptridx.h index d3e2558956..8cca1f5d2a 100644 --- a/common/include/valptridx.h +++ b/common/include/valptridx.h @@ -407,7 +407,16 @@ class valptridx::idx : idx(const magic_constant &, const allow_none_construction *) : m_idx(v) { + /* Prevent using `allow_none_construction` when the type permits + * use of an invalid index. `allow_none_construction` is intended + * to override the validity requirement on types that require a + * valid index, for the limited purpose of constructing a sentinel. + */ static_assert(!allow_nullptr, "allow_none_construction used where nullptr was already legal"); + /* Prevent using `allow_none_construction` with a valid index. + * Valid indexes should not use the `allow_none_construction` + * override. + */ static_assert(static_cast(v) >= array_size, "allow_none_construction used with valid index"); } idx(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a, const allow_end_construction *) : @@ -427,6 +436,10 @@ class valptridx::idx : constexpr idx(const magic_constant &) : m_idx(v) { + /* If the policy requires a valid index (indicated by + * `allow_nullptr == false`), then require that the magic index be + * valid. + */ static_assert(allow_nullptr || static_cast(v) < array_size, "invalid magic index not allowed for this policy"); } template @@ -510,24 +523,27 @@ class valptridx::ptr : return *get_nonnull_pointer(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VA()); } - ptr(std::nullptr_t) : + ptr(std::nullptr_t) + requires(allow_nullptr) // This constructor always stores nullptr, so require a policy with `allow_nullptr == true`. + : m_ptr(nullptr) { - static_assert(allow_nullptr, "nullptr construction not allowed for this policy"); } template + requires( + static_cast(v) >= array_size // Require that the index be invalid, since a valid index should compute a non-nullptr here, but with no array, no pointer can be computed. + ) ptr(const magic_constant &) : - m_ptr(nullptr) + ptr(nullptr) { - static_assert(static_cast(v) >= array_size, "valid magic index requires an array"); - if constexpr (!allow_nullptr) - static_assert(static_cast(v) < array_size, "invalid magic index not allowed for this policy"); } template + requires( + static_cast(v) < array_size // valid magic index required when using array + ) ptr(const magic_constant &, array_managed_type &a) : m_ptr(&a[v]) { - static_assert(static_cast(v) < array_size, "valid magic index required when using array"); } template requires(policy::allow_nullptr || !rpolicy::allow_nullptr) @@ -543,6 +559,9 @@ class valptridx::ptr : check_null_pointer_conversion>(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_PASS_VARS m_ptr); } template + requires( + policy::allow_nullptr || !rpolicy::allow_nullptr // cannot move from allow_invalid to require_valid + ) ptr(ptr &&rhs) : m_ptr(rhs.get_unchecked_pointer()) { @@ -550,7 +569,6 @@ class valptridx::ptr : * right hand side must be saved and checked for validity before * being used to initialize a require_valid type. */ - static_assert(policy::allow_nullptr || !rpolicy::allow_nullptr, "cannot move from allow_invalid to require_valid"); } ptr(index_type i) = delete; ptr(DXX_VALPTRIDX_REPORT_STANDARD_LEADER_COMMA_R_DEFN_VARS index_type i, array_managed_type &a) : @@ -670,16 +688,21 @@ class valptridx::ptr : -- m_ptr; return *this; } - ptr(const allow_none_construction *) : + ptr(const allow_none_construction *) + requires( + !allow_nullptr // allow_none_construction is only needed where nullptr is not already legal + ) + : m_ptr(nullptr) { - static_assert(!allow_nullptr, "allow_none_construction used where nullptr was already legal"); } template + requires( + allow_nullptr || !rpolicy::allow_nullptr // cannot rebind from allow_invalid to require_valid + ) ptr(ptr &&rhs, const typename containing_type::rebind_policy *) : m_ptr(const_cast(rhs.get_unchecked_pointer())) { - static_assert(allow_nullptr || !rpolicy::allow_nullptr, "cannot rebind from allow_invalid to require_valid"); } }; From bde5d52afe400dd42bde57c7c94e203ae53564fc Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 19/32] Use abbreviated function templates in rle expansion Due to the indent change, this diff is best viewed with `--ignore-space-change`. --- common/include/rle.h | 116 +++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/common/include/rle.h b/common/include/rle.h index 2cffd8f8e6..4de8a6ac89 100644 --- a/common/include/rle.h +++ b/common/include/rle.h @@ -189,71 +189,69 @@ class bm_rle_expand : bm_rle_src_stride end_src_bm(end(src)) { } - template - /* Decode one row of the bitmap, then return control to the - * caller. If the return value is `again`, then the caller - * should perform any per-row processing, then call step() - * again. If the return value is not `again`, then the - * destination buffer is undefined and the caller should not - * access it or call step(). - * - * `const T &` to ensure that t is only modified by the caller - * and that the caller does not accidentally provide an - * implementation of `get_begin_dbits` that moves the - * destination pointer. + /* Decode one row of the bitmap, then return control to the + * caller. If the return value is `again`, then the caller + * should perform any per-row processing, then call step() + * again. If the return value is not `again`, then the + * destination buffer is undefined and the caller should not + * access it or call step(). + * + * Use `const auto &` to ensure that t is only modified by the caller + * and that the caller does not accidentally provide an + * implementation of `get_begin_dbits` that moves the + * destination pointer. + */ + step_result step(const auto &t) + { + /* Poison the memory first, so that it is undefined even if + * the source is exhausted. */ - step_result step(const T &t) - { - /* Poison the memory first, so that it is undefined even if - * the source is exhausted. - */ - const auto b = t.get_begin_dbits(); - const auto e = t.get_end_dbits(); - DXX_MAKE_MEM_UNDEFINED(std::span(b, e)); - /* Check for source exhaustion, so that empty bitmaps are - * not read at all. This allows callers to treat - * src_exhausted as a definitive end-of-record with no data - * available. - */ - if (ptr_src_bit_lengths == end_src_bit_lengths) - return src_exhausted; - return step_internal(b, e); - } - template - /* Decode until source or destination is exhausted. The - * destination position is updated automatically as each row is - * decoded. There is no opportunity for callers to perform - * per-row processing. Callers should call step() directly if - * per-row processing is required. - * - * `T &&` since some callers may not care about the state of `t` - * afterward; `T &&` lets them pass an anonymous temporary. + const auto b = t.get_begin_dbits(); + const auto e = t.get_end_dbits(); + DXX_MAKE_MEM_UNDEFINED(std::span(b, e)); + /* Check for source exhaustion, so that empty bitmaps are + * not read at all. This allows callers to treat + * src_exhausted as a definitive end-of-record with no data + * available. */ - bool loop(const unsigned bm_w, T &&t) + if (ptr_src_bit_lengths == end_src_bit_lengths) + return src_exhausted; + return step_internal(b, e); + } + /* Decode until source or destination is exhausted. The + * destination position is updated automatically as each row is + * decoded. There is no opportunity for callers to perform + * per-row processing. Callers should call step() directly if + * per-row processing is required. + * + * Use `auto &&` since some callers may not care about the state of `t` + * afterward; `auto &&` lets them pass an anonymous temporary. + */ + bool loop(const unsigned bm_w, auto &&t) + { + for (;;) { - for (;;) + switch (step(t)) { - switch (step(t)) - { - case again: - /* Step succeeded. Notify `t` to update its - * dbits position, then loop around. - */ - t.consume_dbits(bm_w); - break; - case src_exhausted: - /* Success: source buffer exhausted and no error - * conditions detected. - */ - return true; - case dst_exhausted: - /* Failure: destination buffer too small to hold - * expanded source. - */ - return false; - } + case again: + /* Step succeeded. Notify `t` to update its + * dbits position, then loop around. + */ + t.consume_dbits(bm_w); + break; + case src_exhausted: + /* Success: source buffer exhausted and no error + * conditions detected. + */ + return true; + case dst_exhausted: + /* Failure: destination buffer too small to hold + * expanded source. + */ + return false; } } + } private: step_result step_internal(uint8_t *begin_dbits, uint8_t *end_dbits); }; From a3ea68d0c4ffd4f92ce0a136a72609a153e92f80 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 20/32] Reduce use of explicit static_cast where practical Prefer generating a literal via the correct suffix, or via an initialization that prohibits narrowing. --- common/include/maths.h | 2 +- common/include/ntstring.h | 4 ++-- common/main/aistruct.h | 2 +- common/mem/mem.cpp | 2 +- common/unittest/valptridx-range.cpp | 2 +- similar/arch/sdl/gr.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/include/maths.h b/common/include/maths.h index 41130dbba3..f2a96dd119 100644 --- a/common/include/maths.h +++ b/common/include/maths.h @@ -56,7 +56,7 @@ static constexpr int f2i(const fix &f) //Convert fix to float and float to fix static constexpr float f2fl(const fix &f) { - return static_cast(f) / static_cast(65536.0); + return static_cast(f) / 65536.0f; } static constexpr double f2db(const fix &f) diff --git a/common/include/ntstring.h b/common/include/ntstring.h index ac049e9e85..fee0d8ec82 100644 --- a/common/include/ntstring.h +++ b/common/include/ntstring.h @@ -41,12 +41,12 @@ class ntstring : template std::size_t copy_if(I &&i) { - return copy_if(static_cast(0), static_cast(i)); + return copy_if(std::size_t{0}, static_cast(i)); } template std::size_t copy_if(I &&i, std::size_t N) { - return copy_if(static_cast(0), static_cast(i), N); + return copy_if(std::size_t{0}, static_cast(i), N); } template std::size_t copy_if(std::size_t out_offset, I &&i) diff --git a/common/main/aistruct.h b/common/main/aistruct.h index cb93145c8d..641f838642 100644 --- a/common/main/aistruct.h +++ b/common/main/aistruct.h @@ -231,7 +231,7 @@ struct ai_local : public prohibit_void_ptr struct ai_static : public prohibit_void_ptr { - ai_behavior behavior = static_cast(0); // + ai_behavior behavior{}; // robot_gun_number CURRENT_GUN; ai_static_state CURRENT_STATE; ai_static_state GOAL_STATE; diff --git a/common/mem/mem.cpp b/common/mem/mem.cpp index 1df9c80096..1ba426139f 100644 --- a/common/mem/mem.cpp +++ b/common/mem/mem.cpp @@ -165,7 +165,7 @@ void *(mem_calloc)( size_t nmemb, size_t size, const char * var, const char * fi if ((nmemb | size) >= threshold) { /* possible overflow condition */ if (request / size != nmemb) - request = ~static_cast(0); + request = ~std::size_t{0}; } void *ptr = mem_malloc(request, var, filename, line); if (ptr) diff --git a/common/unittest/valptridx-range.cpp b/common/unittest/valptridx-range.cpp index 05d6973526..530962d12a 100644 --- a/common/unittest/valptridx-range.cpp +++ b/common/unittest/valptridx-range.cpp @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(idx_convert_check) using vo = valptridx; BOOST_CHECK_NO_THROW( DXX_TEST_VALPTRIDX_IGNORE_RETURN(({ - typename vo::imidx i(static_cast(0)); + typename vo::imidx i(objnum_t{0}); typename vo::vmidx{i}; })) ); diff --git a/similar/arch/sdl/gr.cpp b/similar/arch/sdl/gr.cpp index 3d0c996cd3..ec879ea15f 100644 --- a/similar/arch/sdl/gr.cpp +++ b/similar/arch/sdl/gr.cpp @@ -263,7 +263,7 @@ void gr_palette_load( palette_array_t &pal ) return; // Display is not palettised range_for (const int i, xrange(64u)) - gamma[i] = static_cast((pow((static_cast(14)/static_cast(32)), 1.0)*i) + 0.5); + gamma[i] = static_cast((pow((14.0 / 32.0), 1.0) * i) + 0.5); std::array colors{}; for (int i = 0, j = 0; j < 256; j++) From 3cc71e8d299e1ea5d85bda2f656201ee56abdb4b Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 21/32] Simplify human_readable_mmss_time Replace the defaulted MaximumValue with a direct use of the appropriate maximum value. --- common/main/menu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/main/menu.h b/common/main/menu.h index 6382683d80..9f43883a41 100644 --- a/common/main/menu.h +++ b/common/main/menu.h @@ -33,8 +33,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. namespace dcx { -template ::max()> -using human_readable_mmss_time = std::array + number_to_text_length<60> + sizeof("ms")>; +template +using human_readable_mmss_time = std::array::max() / 60> + number_to_text_length<60> + sizeof("ms")>; template void format_human_readable_time(std::array &buf, const std::chrono::duration duration); From ac18828d2e0cf41efee18602465794b69c865481 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 9 Dec 2023 23:12:38 +0000 Subject: [PATCH 22/32] Use std::rotl for bitwise rotation --- similar/main/text.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/similar/main/text.cpp b/similar/main/text.cpp index 20f4f01f14..4187d0d396 100644 --- a/similar/main/text.cpp +++ b/similar/main/text.cpp @@ -51,19 +51,11 @@ namespace { static std::unique_ptr text; static std::unique_ptr overwritten_text; -// rotates a byte left one bit, preserving the bit falling off the right -static uint8_t encode_rotate_left(const uint8_t v) +static constexpr uint8_t decode_char(const uint8_t c) { - return (v >> 7) | (v << 1); -} - -constexpr std::integral_constant BITMAP_TBL_XOR{}; - -static uint8_t decode_char(const uint8_t c) -{ - const auto c1 = encode_rotate_left(c); - const auto c2 = c1 ^ BITMAP_TBL_XOR; - return encode_rotate_left(c2); + constexpr uint8_t BITMAP_TBL_XOR{0xd3}; + const uint8_t c2 = std::rotl(c, 1) ^ BITMAP_TBL_XOR; + return {std::rotl(c2, 1)}; } } From 7122177103ea5362b8c805d1ab91b91bbefc9f09 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 17 Dec 2023 22:41:29 +0000 Subject: [PATCH 23/32] Return mouse coordinates from mouse_get_pos --- common/arch/sdl/mouse.cpp | 10 ++++++---- common/include/mouse.h | 8 +++----- common/ui/gadget.cpp | 4 +--- common/ui/listbox.cpp | 4 +--- common/ui/menu.cpp | 4 +--- common/ui/menubar.cpp | 5 +---- common/ui/message.cpp | 5 +---- common/ui/scroll.cpp | 3 +-- common/ui/userbox.cpp | 3 +-- similar/main/kconfig.cpp | 6 +++--- similar/main/newmenu.cpp | 15 ++++++--------- 11 files changed, 25 insertions(+), 42 deletions(-) diff --git a/common/arch/sdl/mouse.cpp b/common/arch/sdl/mouse.cpp index 3962c85f85..693f36670d 100644 --- a/common/arch/sdl/mouse.cpp +++ b/common/arch/sdl/mouse.cpp @@ -177,12 +177,14 @@ void mouse_flush() // clears all mice events... } //======================================================================== -void mouse_get_pos( int *x, int *y, int *z ) +std::tuple mouse_get_pos() { //event_poll(); // Have to assume this is called in event_process, because event_poll can cause a window to close (depending on what the user does) - *x=Mouse.x; - *y=Mouse.y; - *z=Mouse.z; + return { + Mouse.x, + Mouse.y, + Mouse.z, + }; } window_event_result mouse_in_window(window *wind) diff --git a/common/include/mouse.h b/common/include/mouse.h index 200b25bdde..8265a1e90e 100644 --- a/common/include/mouse.h +++ b/common/include/mouse.h @@ -12,10 +12,9 @@ #pragma once +#include #include "pstypes.h" #include "maths.h" - -#ifdef __cplusplus #include #include #include "event.h" @@ -56,7 +55,8 @@ enum class mbtn : uint8_t extern void mouse_flush(); // clears all mice events... extern void mouse_init(void); extern void mouse_close(void); -extern void mouse_get_pos( int *x, int *y, int *z ); +[[nodiscard]] +std::tuple mouse_get_pos(); window_event_result mouse_in_window(class window *wind); extern void mouse_get_delta( int *dx, int *dy, int *dz ); void mouse_enable_cursor(); @@ -106,5 +106,3 @@ static inline void event_mouse_get_delta(const d_event &event, int *dx, int *dy, } } - -#endif diff --git a/common/ui/gadget.cpp b/common/ui/gadget.cpp index 2cd722c4da..45767913a9 100644 --- a/common/ui/gadget.cpp +++ b/common/ui/gadget.cpp @@ -115,9 +115,7 @@ int is_under_another_window( UI_DIALOG * dlg, UI_GADGET * gadget ) int ui_mouse_on_gadget(UI_GADGET &gadget) { - int x, y, z; - - mouse_get_pos(&x, &y, &z); + const auto [x, y, z] = mouse_get_pos(); if (x >= gadget.x1 && x <= gadget.x2 - 1 && y >= gadget.y1 && y <= gadget.y2 - 1) { #if 0 // check is no longer required - if it is under another window, that dialog's handler would have returned 1 diff --git a/common/ui/listbox.cpp b/common/ui/listbox.cpp index 9f6bfc1844..c439fe517b 100644 --- a/common/ui/listbox.cpp +++ b/common/ui/listbox.cpp @@ -278,9 +278,7 @@ window_event_result UI_GADGET_LISTBOX::event_handler(UI_DIALOG &dlg, const d_eve { if (dragging) { - int x, y, z; - - mouse_get_pos(&x, &y, &z); + const auto [x, y, z] = mouse_get_pos(); const auto mitem = (y < y1) ? -1 : (y - y1) / textheight; diff --git a/common/ui/menu.cpp b/common/ui/menu.cpp index bea3ec3b8e..4d90dbed04 100644 --- a/common/ui/menu.cpp +++ b/common/ui/menu.cpp @@ -102,9 +102,7 @@ int MenuX( int x, int y, int NumButtons, const char *const text[] ) h = grd_curscreen->get_screen_height(); { - int mx, my, mz; - - mouse_get_pos(&mx, &my, &mz); + const auto [mx, my, mz] = mouse_get_pos(); if ( x == -1 ) x = mx - width/2; if ( y == -1 ) y = my; } diff --git a/common/ui/menubar.cpp b/common/ui/menubar.cpp index dabafbc345..f6cec1fbb6 100644 --- a/common/ui/menubar.cpp +++ b/common/ui/menubar.cpp @@ -237,10 +237,7 @@ static int menu_match_keypress(MENU &menu, int keypress) static int menu_is_mouse_on(const ITEM &item) { - int x, y, z; - - mouse_get_pos(&x, &y, &z); - + const auto [x, y, z] = mouse_get_pos(); if (x >= item.x && x < item.x + item.w && y >= item.y && diff --git a/common/ui/message.cpp b/common/ui/message.cpp index de2ba64375..2e78b7b849 100644 --- a/common/ui/message.cpp +++ b/common/ui/message.cpp @@ -144,10 +144,7 @@ int (ui_messagebox)( short xc, short yc, const char * text, const ui_messagebox_ height += 2; // For line in middle { - int mx, my, mz; - - mouse_get_pos(&mx, &my, &mz); - + const auto [mx, my, mz] = mouse_get_pos(); if ( xc == -1 ) xc = mx; diff --git a/common/ui/scroll.cpp b/common/ui/scroll.cpp index 35a124d28a..66a9ba2eb4 100644 --- a/common/ui/scroll.cpp +++ b/common/ui/scroll.cpp @@ -97,7 +97,6 @@ std::unique_ptr ui_add_gadget_scrollbar(UI_DIALOG &dlg, sho window_event_result UI_GADGET_SCROLLBAR::event_handler(UI_DIALOG &dlg, const d_event &event) { - int x, y, z; window_event_result rval = window_event_result::ignored; if (event.type == event_type::window_draw) { @@ -191,7 +190,7 @@ window_event_result UI_GADGET_SCROLLBAR::event_handler(UI_DIALOG &dlg, const d_e // listbox->dragging = 1; - mouse_get_pos(&x, &y, &z); + const auto [x, y, z] = mouse_get_pos(); const auto OnSlider = y >= fake_position + y1 && y < fake_position + y1 + fake_size && diff --git a/common/ui/userbox.cpp b/common/ui/userbox.cpp index b14b292150..76b2df4f90 100644 --- a/common/ui/userbox.cpp +++ b/common/ui/userbox.cpp @@ -74,7 +74,6 @@ std::unique_ptr ui_add_gadget_userbox(UI_DIALOG &dlg, short x window_event_result UI_GADGET_USERBOX::event_handler(UI_DIALOG &dlg, const d_event &event) { - int x, y, z; window_event_result rval = window_event_result::ignored; if (event.type == event_type::window_draw) ui_draw_userbox(dlg, *this); @@ -82,7 +81,7 @@ window_event_result UI_GADGET_USERBOX::event_handler(UI_DIALOG &dlg, const d_eve const auto keypress = (event.type == event_type::key_command) ? event_key_get(event) : 0u; - mouse_get_pos(&x, &y, &z); + const auto [x, y, z] = mouse_get_pos(); const auto OnMe = ui_mouse_on_gadget(*this); const auto olddrag = b1_held_down; diff --git a/similar/main/kconfig.cpp b/similar/main/kconfig.cpp index 63dd34e699..97f3690440 100644 --- a/similar/main/kconfig.cpp +++ b/similar/main/kconfig.cpp @@ -550,7 +550,7 @@ namespace { static window_event_result kconfig_mouse(kc_menu &menu, const d_event &event) { grs_canvas &save_canvas = *grd_curcanv; - int mx, my, mz, x1, y1; + int x1, y1; window_event_result rval = window_event_result::ignored; gr_set_current_canvas(menu.w_canv); @@ -560,7 +560,7 @@ static window_event_result kconfig_mouse(kc_menu &menu, const d_event &event) { int item_height; - mouse_get_pos(&mx, &my, &mz); + const auto [mx, my, mz] = mouse_get_pos(); const auto &&fspacx = FSPACX(); const auto &&fspacy = FSPACY(); const auto nitems = menu.nitems; @@ -579,7 +579,7 @@ static window_event_result kconfig_mouse(kc_menu &menu, const d_event &event) else if (event.type == event_type::mouse_button_up) { int item_height; - mouse_get_pos(&mx, &my, &mz); + const auto [mx, my, mz] = mouse_get_pos(); item_height = get_item_height(*canvas.cv_font, menu.items[menu.citem], menu.mitems[menu.citem]); const auto &&fspacx = FSPACX(); x1 = canvas.cv_bitmap.bm_x + fspacx(menu.items[menu.citem].xinput); diff --git a/similar/main/newmenu.cpp b/similar/main/newmenu.cpp index 68c63e5e7c..6fcf074cb5 100644 --- a/similar/main/newmenu.cpp +++ b/similar/main/newmenu.cpp @@ -831,7 +831,7 @@ static void check_apply_mouse_scroll(newmenu *const menu, const grs_canvas &canv static window_event_result newmenu_mouse(const d_event &event, newmenu *menu, const mbtn button) { - int old_choice, mx=0, my=0, mz=0, x1 = 0, x2, y1, y2, changed = 0; + int old_choice, x1 = 0, x2, y1, y2, changed = 0; grs_canvas &menu_canvas = menu->w_canv; switch (button) @@ -845,7 +845,7 @@ static window_event_result newmenu_mouse(const d_event &event, newmenu *menu, co const auto &&fspacx = FSPACX(); if (event.type == event_type::mouse_button_down && !menu->all_text) { - mouse_get_pos(&mx, &my, &mz); + const auto [mx, my, mz] = mouse_get_pos(); const int line_spacing = static_cast(LINE_SPACING(*canvas.cv_font, *GAME_FONT)); for (int i = menu->scroll_offset; i < menu->max_on_menu + menu->scroll_offset; ++i) { @@ -883,8 +883,7 @@ static window_event_result newmenu_mouse(const d_event &event, newmenu *menu, co } if ( menu->mouse_state ) { - mouse_get_pos(&mx, &my, &mz); - + const auto [mx, my, mz] = mouse_get_pos(); // check possible scrollbar stuff first const int line_spacing = static_cast(LINE_SPACING(*canvas.cv_font, *GAME_FONT)); if (menu->is_scroll_box) { @@ -961,7 +960,7 @@ static window_event_result newmenu_mouse(const d_event &event, newmenu *menu, co menu->citem != -1 && std::next(menu->items.begin(), menu->citem)->type == nm_type::menu) { - mouse_get_pos(&mx, &my, &mz); + const auto [mx, my, mz] = mouse_get_pos(); const int line_spacing = static_cast(LINE_SPACING(*canvas.cv_font, *GAME_FONT)); for (int i = menu->scroll_offset; i < menu->max_on_menu + menu->scroll_offset; ++i) { @@ -1757,8 +1756,7 @@ static window_event_result listbox_mouse(const d_event &event, listbox *lb, cons { if (lb->mouse_state) { - int mx, my, mz; - mouse_get_pos(&mx, &my, &mz); + const auto [mx, my, mz] = mouse_get_pos(); const int x1{lb->box_x}; if (mx <= x1) break; @@ -1792,8 +1790,7 @@ static window_event_result listbox_mouse(const d_event &event, listbox *lb, cons if (lb->citem < 0) return window_event_result::ignored; - int mx, my, mz; - mouse_get_pos(&mx, &my, &mz); + const auto [mx, my, mz] = mouse_get_pos(); const auto h = gr_get_string_size(*MEDIUM3_FONT, lb->item[lb->citem]).height; const int x1{lb->box_x}; const int x2 = lb->box_x + lb->box_w; From fe114f64b6f5bf63e2f988a4027abde8f3073f18 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 17 Dec 2023 22:41:29 +0000 Subject: [PATCH 24/32] Return mouse coordinates from mouse_get_delta Also, compile out the implementation since it is only used from excluded UI code. --- common/arch/sdl/mouse.cpp | 14 +++++++++++--- common/include/mouse.h | 5 ++++- common/ui/dialog.cpp | 8 +++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/common/arch/sdl/mouse.cpp b/common/arch/sdl/mouse.cpp index 693f36670d..be115d67e4 100644 --- a/common/arch/sdl/mouse.cpp +++ b/common/arch/sdl/mouse.cpp @@ -194,14 +194,22 @@ window_event_result mouse_in_window(window *wind) (static_cast(Mouse.y) - canv.cv_bitmap.bm_y <= canv.cv_bitmap.bm_h) ? window_event_result::handled : window_event_result::ignored; } -void mouse_get_delta( int *dx, int *dy, int *dz ) +#if 0 +std::tuple mouse_get_delta() { - *dz = Mouse.delta_z; + const int dz{Mouse.delta_z}; + int dx{}, dy{}; Mouse.delta_x = 0; Mouse.delta_y = 0; Mouse.delta_z = 0; - SDL_GetRelativeMouseState(dx, dy); + SDL_GetRelativeMouseState(&dx, &dy); + return { + dx, + dy, + dz, + }; } +#endif namespace { diff --git a/common/include/mouse.h b/common/include/mouse.h index 8265a1e90e..2ff0443b07 100644 --- a/common/include/mouse.h +++ b/common/include/mouse.h @@ -58,7 +58,10 @@ extern void mouse_close(void); [[nodiscard]] std::tuple mouse_get_pos(); window_event_result mouse_in_window(class window *wind); -extern void mouse_get_delta( int *dx, int *dy, int *dz ); +#if 0 +[[nodiscard]] +std::tuple mouse_get_delta(); +#endif void mouse_enable_cursor(); void mouse_disable_cursor(); window_event_result mouse_button_handler(const SDL_MouseButtonEvent *mbe); diff --git a/common/ui/dialog.cpp b/common/ui/dialog.cpp index b0551a468c..f491d8c9a5 100644 --- a/common/ui/dialog.cpp +++ b/common/ui/dialog.cpp @@ -149,7 +149,6 @@ void restore_state() void ui_mega_process() { - int mx, my, mz; unsigned char k; event_process(); @@ -157,7 +156,8 @@ void ui_mega_process() switch( Record ) { case 0: - mouse_get_delta( &mx, &my, &mz ); + { + const auto [mx, my, mz] = mouse_get_delta(); Mouse.new_dx = mx; Mouse.new_dy = my; Mouse.new_buttons = mouse_get_btns(); @@ -169,6 +169,7 @@ void ui_mega_process() break; case 1: + { if (ui_event_counter==0 ) { @@ -188,7 +189,7 @@ void ui_mega_process() ui_event_counter++; } - mouse_get_delta( &mx, &my, &mz ); + const auto [mx, my, mz] = mouse_get_delta(); MouseDX = mx; MouseDY = my; MouseButtons = mouse_get_btns(); @@ -286,6 +287,7 @@ void ui_mega_process() Record = 0; } } + } FrameCount++; From 7d4d96e7360a2b5ae12e06d3fb83babf2b4bfb99 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 17 Dec 2023 22:41:29 +0000 Subject: [PATCH 25/32] Return mouse deltas from event_mouse_get_delta --- common/include/mouse.h | 12 ++++++++---- similar/editor/med.cpp | 8 ++------ similar/main/kconfig.cpp | 11 ++++------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/common/include/mouse.h b/common/include/mouse.h index 2ff0443b07..fb16e2f9df 100644 --- a/common/include/mouse.h +++ b/common/include/mouse.h @@ -12,6 +12,7 @@ #pragma once +#include #include #include "pstypes.h" #include "maths.h" @@ -99,13 +100,16 @@ static inline mbtn event_mouse_get_button(const d_event &event) return e.button; } -static inline void event_mouse_get_delta(const d_event &event, int *dx, int *dy, int *dz) +[[nodiscard]] +static inline std::array event_mouse_get_delta(const d_event &event) { auto &e = static_cast(event); assert(e.type == event_type::mouse_moved); - *dx = e.dx; - *dy = e.dy; - *dz = e.dz; + return {{ + e.dx, + e.dy, + e.dz, + }}; } } diff --git a/similar/editor/med.cpp b/similar/editor/med.cpp index 8a7a95aa07..7eae47380f 100644 --- a/similar/editor/med.cpp +++ b/similar/editor/med.cpp @@ -1332,9 +1332,7 @@ window_event_result editor_dialog::callback_handler(const d_event &event) // Allow specification of LargeView using mouse if (event.type == event_type::mouse_moved && (keyd_pressed[ KEY_LCTRL ] || keyd_pressed[ KEY_RCTRL ])) { - int dx, dy, dz; - - event_mouse_get_delta(event, &dx, &dy, &dz); + const auto [dx, dy, dz] = event_mouse_get_delta(event); if ((dx != 0) && (dy != 0)) { vms_matrix MouseRotMat; @@ -1349,9 +1347,7 @@ window_event_result editor_dialog::callback_handler(const d_event &event) if (event.type == event_type::mouse_moved) { - int dx, dy, dz; - - event_mouse_get_delta(event, &dx, &dy, &dz); + const auto [dx, dy, dz] = event_mouse_get_delta(event); if (dz != 0) { current_view->ev_dist += dz*10000; diff --git a/similar/main/kconfig.cpp b/similar/main/kconfig.cpp index 97f3690440..fe4f608b80 100644 --- a/similar/main/kconfig.cpp +++ b/similar/main/kconfig.cpp @@ -733,7 +733,7 @@ window_event_result kc_menu::event_handler(const d_event &event) if (changing && items[citem].type == kc_type::mouse_axis) kc_change_mouseaxis(*this, event, mitems[citem]); else - event_mouse_get_delta(event, &old_maxis[0], &old_maxis[1], &old_maxis[2]); + old_maxis = event_mouse_get_delta(event); break; #if DXX_MAX_BUTTONS_PER_JOYSTICK || DXX_MAX_HATS_PER_JOYSTICK @@ -928,10 +928,8 @@ static void kc_change_joyaxis( kc_menu &menu,const d_event &event, kc_mitem &mit static void kc_change_mouseaxis( kc_menu &menu,const d_event &event, kc_mitem &mitem ) { - int dx, dy, dz; - assert(event.type == event_type::mouse_moved); - event_mouse_get_delta( event, &dx, &dy, &dz ); + const auto [dx, dy, dz] = event_mouse_get_delta(event); uint8_t code; if (abs(dz) > 5) code = 2; @@ -1215,8 +1213,7 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut break; if (PlayerCfg.MouseFlightSim) { - int ax[3]; - event_mouse_get_delta( event, &ax[0], &ax[1], &ax[2] ); + const auto ax{event_mouse_get_delta(event)}; for (uint_fast32_t i = 0; i <= 2; i++) { int mouse_null_value = (i==2?16:PlayerCfg.MouseFSDead*8); @@ -1232,7 +1229,7 @@ void kconfig_read_controls(control_info &Controls, const d_event &event, int aut } else { - event_mouse_get_delta( event, &Controls.raw_mouse_axis[0], &Controls.raw_mouse_axis[1], &Controls.raw_mouse_axis[2] ); + Controls.raw_mouse_axis = event_mouse_get_delta(event); Controls.mouse_axis[0] = (Controls.raw_mouse_axis[0] * frametime) / 8; Controls.mouse_axis[1] = (Controls.raw_mouse_axis[1] * frametime) / 8; Controls.mouse_axis[2] = (Controls.raw_mouse_axis[2] * frametime); From ec41384d2e7809f2ca6b96bec78f43ba1e12e246 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 17 Dec 2023 22:41:29 +0000 Subject: [PATCH 26/32] Remove deprecated global scope definition of static data member allow_nullptr In C++17 and later, a `static constexpr` is implicitly `inline`, and an `inline` does not need to be redeclared at namespace scope. Remove it. --- common/include/valptridx.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/common/include/valptridx.h b/common/include/valptridx.h index 8cca1f5d2a..7ab61a5dd7 100644 --- a/common/include/valptridx.h +++ b/common/include/valptridx.h @@ -298,12 +298,6 @@ class valptridx::partial_policy::allow_invalid } }; -template -constexpr bool valptridx::partial_policy::require_valid::allow_nullptr; - -template -constexpr bool valptridx::partial_policy::allow_invalid::allow_nullptr; - template template