Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into package
Browse files Browse the repository at this point in the history
  • Loading branch information
maggu2810 committed Dec 26, 2023
2 parents 4327ce7 + d724905 commit d3b23c9
Show file tree
Hide file tree
Showing 99 changed files with 964 additions and 1,063 deletions.
7 changes: 3 additions & 4 deletions common/arch/sdl/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -170,8 +170,7 @@ void event_poll_state::process_event_batch(const ranges::subrange<const SDL_Even
case SDL_JOYBALLMOTION:
continue;
case SDL_QUIT: {
d_event qevent = { EVENT_QUIT };
result = call_default_handler(qevent);
result = call_default_handler(d_event{event_type::quit});
break;
}
default:
Expand Down Expand Up @@ -245,7 +244,7 @@ window_event_result event_process(void)
if ((highest_result == window_event_result::deleted) || (window_get_front() != wind))
return highest_result;

const d_event event{EVENT_WINDOW_DRAW}; // then draw all visible windows
const d_event event{event_type::window_draw}; // then draw all visible windows
for (wind = window_get_first(); wind != nullptr;)
{
if (wind->is_visible())
Expand Down
32 changes: 16 additions & 16 deletions common/arch/sdl/joy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<const d_event_joystick_moved &>(event);
Assert(e.type == EVENT_JOYSTICK_MOVED);
assert(e.type == event_type::joystick_moved);
return e;
}
#endif
Expand All @@ -479,7 +479,7 @@ void joy_flush()
int event_joystick_get_button(const d_event &event)
{
auto &e = static_cast<const d_event_joystickbutton &>(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
Expand All @@ -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<const d_event_joystickbutton &>(event);
assert(e.button < joy_key_map.size());
Expand Down
9 changes: 4 additions & 5 deletions common/arch/sdl/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "",
Expand Down Expand Up @@ -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<const d_event_keycommand &>(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;
}

Expand Down
37 changes: 23 additions & 14 deletions common/arch/sdl/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -178,12 +177,14 @@ void mouse_flush() // clears all mice events...
}

//========================================================================
void mouse_get_pos( int *x, int *y, int *z )
std::tuple<int, int, int> 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)
Expand All @@ -193,14 +194,22 @@ window_event_result mouse_in_window(window *wind)
(static_cast<unsigned>(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<int, int, int> 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 {

Expand Down
23 changes: 12 additions & 11 deletions common/arch/sdl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "console.h"
#include "dxxerror.h"
#include "event.h"
#include "d_underlying_value.h"

namespace dcx {

Expand All @@ -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()
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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});
}
}

Expand All @@ -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;
}

Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions common/arch/win32/messagebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit d3b23c9

Please sign in to comment.