Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions Descent3/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,37 +176,6 @@ class oeD3LnxDatabase final : public oeLnxAppDatabase {
}
};

bool sdlKeyFilter(const SDL_Event *event);
bool sdlMouseButtonUpFilter(const SDL_Event *event);
bool sdlMouseButtonDownFilter(const SDL_Event *event);
bool sdlMouseWheelFilter(const SDL_Event *event);
bool sdlMouseMotionFilter(const SDL_Event *event);

bool SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event) {
switch (event->type) {
case SDL_EVENT_KEY_UP:
case SDL_EVENT_KEY_DOWN:
return (sdlKeyFilter(event));
case SDL_EVENT_JOYSTICK_BALL_MOTION:
case SDL_EVENT_MOUSE_MOTION:
return (sdlMouseMotionFilter(event));
case SDL_EVENT_MOUSE_BUTTON_UP:
return (sdlMouseButtonUpFilter(event));
case SDL_EVENT_MOUSE_BUTTON_DOWN:
return (sdlMouseButtonDownFilter(event));
case SDL_EVENT_MOUSE_WHEEL:
return (sdlMouseWheelFilter(event));
case SDL_EVENT_QUIT:
SDL_Quit();
_exit(0);
break;
default:
break;
} // switch

return (1);
}

// ---------------------------------------------------------------------------
// Main
// creates all the OS objects and then runs Descent 3.
Expand Down Expand Up @@ -250,8 +219,6 @@ int main(int argc, char *argv[]) {
return (0);
}

// !!! FIXME: Don't use an event filter!
SDL_SetEventFilter(d3SDLEventFilter, nullptr);
install_signal_handlers();

// Initialize our OS Object. This could be a game dependant OS object, or a default OS object.
Expand Down
42 changes: 41 additions & 1 deletion ddio/ddio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@

#include <cstdlib>

#include <SDL3/SDL.h>

#include "ddio.h"
#include "ddio_lnx.h"
#include "joystick.h"
#include "log.h"
#include "pserror.h"
Expand Down Expand Up @@ -140,9 +143,46 @@ void ddio_Resume() {
ddio_InternalKeyResume();
ddio_InternalMouseResume();
}

// handles buffered input from devices once per frame.
void sdlKeyEvent(const SDL_Event *event);
void sdlMouseButtonUpEvent(const SDL_Event *event);
void sdlMouseButtonDownEvent(const SDL_Event *event);
void sdlMouseWheelEvent(const SDL_Event *event);
void sdlMouseMotionEvent(const SDL_Event *event);
void ddio_Frame() {
if (Input_mode == Input_sdl) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_EVENT_KEY_UP:
case SDL_EVENT_KEY_DOWN:
sdlKeyEvent(&event);
break;
case SDL_EVENT_JOYSTICK_BALL_MOTION:
case SDL_EVENT_MOUSE_MOTION:
sdlMouseMotionEvent(&event);
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
sdlMouseButtonUpEvent(&event);
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
sdlMouseButtonDownEvent(&event);
break;
case SDL_EVENT_MOUSE_WHEEL:
sdlMouseWheelEvent(&event);
break;
case SDL_EVENT_QUIT:
SDL_Quit();
_exit(0);
break;
default:
break;
}
}
}

ddio_InternalKeyFrame();
ddio_InternalMouseFrame();
ddio_InternalJoyFrame();
}
}
6 changes: 6 additions & 0 deletions ddio/ddio_lnx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@

extern oeLnxApplication *Lnx_app_obj;

enum input_mode_t {
Input_null,
Input_sdl,
};
extern enum input_mode_t Input_mode;

#endif
13 changes: 13 additions & 0 deletions ddio/lnxio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@
#include "application.h"
#include "ddio.h"
#include "log.h"
#include "ddio_lnx.h"

bool DDIO_init = false;
oeLnxApplication *Lnx_app_obj = NULL;
enum input_mode_t Input_mode;

// ----------------------------------------------------------------------------
// Initialization and destruction functions
Expand All @@ -80,6 +82,17 @@ oeLnxApplication *Lnx_app_obj = NULL;
bool ddio_InternalInit(ddio_init_info *init_info) {
LOG_DEBUG << "DDIO: ddio_InternalInit() called.";
Lnx_app_obj = (oeLnxApplication *)init_info->obj;

if (!Lnx_app_obj) {
return false;
}

tLnxAppInfo app_info;
Lnx_app_obj->get_info(&app_info);

// determine if we are to use SDL or null mode
Input_mode = (app_info.flags & APPFLAG_USESERVICE) ? Input_null : Input_sdl;

DDIO_init = true;
return true;
}
Expand Down
36 changes: 10 additions & 26 deletions ddio/lnxkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "application.h"
#include "ddio.h"
#include "mono.h"
#include "ddio_lnx.h"

volatile struct tLnxKeys {
union {
Expand Down Expand Up @@ -87,29 +88,12 @@ void ddio_sdl_InternalResetKey(uint8_t key);
bool ddio_sdl_KeyFrame();
void ddio_sdl_InternalKeyFrame(void);

enum {
Input_null,
Input_sdl // Input_svga,Input_xwin
} Keyboard_mode;

// ----------------------------------------------------------------------------
// Initialization of keyboard device.
// ----------------------------------------------------------------------------

bool ddio_InternalKeyInit(ddio_init_info *init_info) {
oeLnxApplication *app = (oeLnxApplication *)init_info->obj;
tLnxAppInfo app_info;

if (!app) {
return false;
}

app->get_info(&app_info);

// determine if we are to use SDL or null mode
Keyboard_mode = (app_info.flags & APPFLAG_USESERVICE) ? Input_null : Input_sdl;

switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
return ddio_null_InternalKeyInit(init_info);
case Input_sdl:
Expand All @@ -120,7 +104,7 @@ bool ddio_InternalKeyInit(ddio_init_info *init_info) {
}

void ddio_InternalKeyClose() {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
return ddio_null_InternalKeyClose();
case Input_sdl:
Expand All @@ -129,7 +113,7 @@ void ddio_InternalKeyClose() {
}

bool ddio_InternalKeyState(uint8_t key) {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
return ddio_null_InternalKeyState(key);
case Input_sdl:
Expand All @@ -140,7 +124,7 @@ bool ddio_InternalKeyState(uint8_t key) {
}

void ddio_InternalKeySuspend() {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
ddio_null_InternalKeySuspend();
break;
Expand All @@ -150,7 +134,7 @@ void ddio_InternalKeySuspend() {
}

void ddio_InternalKeyResume() {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
ddio_null_InternalKeyResume();
break;
Expand All @@ -160,7 +144,7 @@ void ddio_InternalKeyResume() {
}

float ddio_InternalKeyDownTime(uint8_t key) {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
return ddio_null_InternalKeyDownTime(key);
case Input_sdl:
Expand All @@ -171,7 +155,7 @@ float ddio_InternalKeyDownTime(uint8_t key) {
}

void ddio_InternalResetKey(uint8_t key) {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
ddio_null_InternalResetKey(key);
break;
Expand All @@ -181,7 +165,7 @@ void ddio_InternalResetKey(uint8_t key) {
}

bool ddio_KeyFrame() {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_sdl:
break;
case Input_null:
Expand All @@ -192,7 +176,7 @@ bool ddio_KeyFrame() {
}

void ddio_InternalKeyFrame(void) {
switch (Keyboard_mode) {
switch (Input_mode) {
case Input_null:
ddio_null_InternalKeyFrame();
break;
Expand Down
14 changes: 6 additions & 8 deletions ddio/lnxkey_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ static inline uint8_t sdlkeycode_to_keycode(uint32_t sdlkeycode) {
return (uint8_t)rc;
}

bool sdlKeyFilter(const SDL_Event *event) {
void sdlKeyEvent(const SDL_Event *event) {
uint8_t kc = 0;

if ((event->type != SDL_EVENT_KEY_UP) && (event->type != SDL_EVENT_KEY_DOWN))
return true;
return;

if (event->key.down) {
if (event->key.repeat) {
return false; // ignore these, we only want to know if it's a first time pressed, not a key-repeat.
return; // ignore these, we only want to know if it's a first time pressed, not a key-repeat.
}
kc = sdlkeycode_to_keycode(event->key.key);
if (event->key.mod & SDL_KMOD_CTRL) {
Expand All @@ -358,15 +358,15 @@ bool sdlKeyFilter(const SDL_Event *event) {
bool grab = !ddio_MouseGetGrab();
ddio_MouseSetGrab(grab);
SDL_SetWindowRelativeMouseMode(GSDLWindow, grab);
return false;
return;
} // switch
} // if

else if (event->key.mod & SDL_KMOD_ALT) {
if ((kc == KEY_ENTER) || (kc == KEY_PADENTER)) {
Game_fullscreen = !Game_fullscreen;
rend_SetFullScreen(Game_fullscreen);
return false;
return;
} // if
} // else if

Expand All @@ -382,9 +382,7 @@ bool sdlKeyFilter(const SDL_Event *event) {
ddio_UpdateKeyState(kc, false);
} // if
}

return false;
} // sdlKeyFilter
}

bool ddio_sdl_InternalKeyInit(ddio_init_info *init_info) {
// reset key list
Expand Down
22 changes: 5 additions & 17 deletions ddio/lnxmouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void ddio_MouseMode(int mode) { Mouse_mode = mode; }
// virtual coordinate system for mouse (match to video resolution set for optimal mouse usage.
void ddio_MouseSetVCoords(int width, int height) { ddio_MouseSetLimits(0, 0, width, height); }

bool sdlMouseButtonDownFilter(SDL_Event const *event) {
void sdlMouseButtonDownEvent(SDL_Event const *event) {
ASSERT(event->type == SDL_EVENT_MOUSE_BUTTON_DOWN);

const SDL_MouseButtonEvent *ev = &event->button;
Expand Down Expand Up @@ -258,11 +258,9 @@ bool sdlMouseButtonDownFilter(SDL_Event const *event) {
MB_queue.send(mevt);
// mprintf(0, "MOUSE Button 7: Down\n");
}

return false;
}

bool sdlMouseButtonUpFilter(SDL_Event const *event) {
void sdlMouseButtonUpEvent(SDL_Event const *event) {
ASSERT(event->type == SDL_EVENT_MOUSE_BUTTON_UP);

const SDL_MouseButtonEvent *ev = &event->button;
Expand Down Expand Up @@ -332,11 +330,9 @@ bool sdlMouseButtonUpFilter(SDL_Event const *event) {
MB_queue.send(mevt);
// mprintf(0, "MOUSE Button 7: Up\n");
}

return false;
}

bool sdlMouseWheelFilter(SDL_Event const *event) {
void sdlMouseWheelEvent(SDL_Event const *event) {
ASSERT(event->type == SDL_EVENT_MOUSE_WHEEL);

const SDL_MouseWheelEvent *ev = &event->wheel;
Expand Down Expand Up @@ -383,11 +379,9 @@ bool sdlMouseWheelFilter(SDL_Event const *event) {
MB_queue.send(mevt);
// mprintf(0, "MOUSE Scrollwheel: Rolled Down\n");
}

return false;
}

bool sdlMouseMotionFilter(SDL_Event const *event) {
void sdlMouseMotionEvent(SDL_Event const *event) {
if (event->type == SDL_EVENT_JOYSTICK_BALL_MOTION) {
DDIO_mouse_state.dx = event->jball.xrel / 100.0f;
DDIO_mouse_state.dy = event->jball.yrel / 100.0f;
Expand All @@ -408,16 +402,10 @@ bool sdlMouseMotionFilter(SDL_Event const *event) {
DDIO_mouse_state.y = DDIO_mouse_state.t;
if (DDIO_mouse_state.y >= DDIO_mouse_state.b)
DDIO_mouse_state.y = DDIO_mouse_state.b - 1;

return false;
}

// This function will handle all mouse events.
void ddio_InternalMouseFrame(void) {
static unsigned frame_count = 0;
SDL_PumpEvents();
frame_count++;
}
void ddio_InternalMouseFrame(void) {}

/* x, y = absolute mouse position
dx, dy = mouse deltas since last call
Expand Down
4 changes: 1 addition & 3 deletions ddio/sdljoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,4 @@ static int joyGetNumDevs(void) {
return found;
}

void ddio_InternalJoyFrame(void) {
// All the work is done already in SDL_PumpEvents()
}
void ddio_InternalJoyFrame(void) {}
Loading