Merge pull request #241 from icculus/ryan-sdl2-port

Initial SDL2 port
This commit is contained in:
Louis Gombert 2024-05-06 08:57:20 +00:00 committed by GitHub
commit 0e69bf465f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 249 additions and 761 deletions

View File

@ -66,7 +66,7 @@ jobs:
run: | run: |
sudo apt update sudo apt update
sudo apt install -y --no-install-recommends \ sudo apt install -y --no-install-recommends \
ninja-build cmake g++ libgtest-dev libsdl1.2-dev libsdl-image1.2-dev libncurses-dev zlib1g-dev libspdlog-dev ninja-build cmake g++ libgtest-dev libsdl2-dev libncurses-dev zlib1g-dev libspdlog-dev
- name: Configure CMake - name: Configure CMake
env: env:

View File

@ -1,8 +1,7 @@
# Homebrew dependencies to build Descent3 # Homebrew dependencies to build Descent3
# SDL # SDL
brew "sdl12-compat" brew "sdl2"
brew "sdl2_image"
brew "cmake" brew "cmake"
brew "googletest" brew "googletest"

View File

@ -76,27 +76,21 @@ if(UNIX)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-multichar;${BITS};${EXTRA_CXX_FLAGS}>") add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-multichar;${BITS};${EXTRA_CXX_FLAGS}>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${BITS}>") add_compile_options("$<$<COMPILE_LANGUAGE:C>:${BITS}>")
find_package(SDL REQUIRED) find_package(SDL2 REQUIRED)
if(APPLE)
# Provide FIND_PACKAGE( SDL_image ) below with an include dir and library that work with brew-installed sdl2_image
find_path(SDL_IMAGE_INCLUDE_DIR NAMES SDL_image.h PATH_SUFFIXES include/SDL2)
find_library(SDL_IMAGE_LIBRARY NAMES SDL2_image)
endif()
find_package(SDL_image REQUIRED)
find_package(Curses REQUIRED) find_package(Curses REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
message("SDL Include Dir is " ${SDL_INCLUDE_DIR}) # Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both.
message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}")
endif() endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux") if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message("Building for Linux") message("Building for Linux")
add_compile_definitions(__LINUX__ LINUX _MAX_PATH=260 _MAX_FNAME=256 _REENRANT __32BIT__ HAVEALLOCA_H _USE_OGL_ACTIVE_TEXTURES) add_compile_definitions(__LINUX__ LINUX _MAX_PATH=260 _MAX_FNAME=256 _REENRANT __32BIT__ HAVEALLOCA_H _USE_OGL_ACTIVE_TEXTURES)
set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR}) set(PLATFORM_INCLUDES "lib/linux" ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
message("Building for MAC OSX") message("Building for MAC OSX")
add_compile_definitions(__LINUX__ LINUX _MAX_PATH=260 _MAX_FNAME=256 _REENRANT MACOSX=1 _USE_OGL_ACTIVE_TEXTURES) add_compile_definitions(__LINUX__ LINUX _MAX_PATH=260 _MAX_FNAME=256 _REENRANT MACOSX=1 _USE_OGL_ACTIVE_TEXTURES)
set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR}) set(PLATFORM_INCLUDES "lib/linux" ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND CMAKE_LIBRARY_PATH "lib/win" "lib/win/directx") list(APPEND CMAKE_LIBRARY_PATH "lib/win" "lib/win/directx")
add_compile_options("$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/EHsc;/RTC1;/W3;/nologo;/c;/Zi;/TP;/errorReport:prompt>") add_compile_options("$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/EHsc;/RTC1;/W3;/nologo;/c;/Zi;/TP;/errorReport:prompt>")

View File

@ -282,13 +282,13 @@ if(WIN32)
endif() endif()
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
set(PLATFORM_LIBS linux dd_lnxsound ddvid_lnx lnxcontroller ddio_lnx SDL::SDL m ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES}) set(PLATFORM_LIBS linux dd_lnxsound ddvid_lnx lnxcontroller ddio_lnx SDL2::SDL2 m ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES})
set(PLATFORM_CPPS loki_utils.c lnxmain.cpp) set(PLATFORM_CPPS loki_utils.c lnxmain.cpp)
endif() endif()
if(APPLE) if(APPLE)
set(PLATFORM_LIBS linux dd_lnxsound ddvid_lnx lnxcontroller ddio_lnx SDL::SDL ${CURSES_LIBRARIES}) set(PLATFORM_LIBS linux dd_lnxsound ddvid_lnx lnxcontroller ddio_lnx SDL2::SDL2 ${CURSES_LIBRARIES})
set(PLATFORM_CPPS loki_utils.c lnxmain.cpp SDLMain.m) set(PLATFORM_CPPS loki_utils.c lnxmain.cpp)
set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework Cocoa -framework OpenGL -framework Carbon") set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework Cocoa -framework OpenGL -framework Carbon")
endif() endif()

View File

@ -307,9 +307,10 @@ static void register_d3_args(void) {
int sdlKeyFilter(const SDL_Event *event); int sdlKeyFilter(const SDL_Event *event);
int sdlMouseButtonUpFilter(const SDL_Event *event); int sdlMouseButtonUpFilter(const SDL_Event *event);
int sdlMouseButtonDownFilter(const SDL_Event *event); int sdlMouseButtonDownFilter(const SDL_Event *event);
int sdlMouseWheelFilter(const SDL_Event *event);
int sdlMouseMotionFilter(const SDL_Event *event); int sdlMouseMotionFilter(const SDL_Event *event);
int d3SDLEventFilter(const SDL_Event *event) { int SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event) {
switch (event->type) { switch (event->type) {
case SDL_KEYUP: case SDL_KEYUP:
case SDL_KEYDOWN: case SDL_KEYDOWN:
@ -322,6 +323,13 @@ int d3SDLEventFilter(const SDL_Event *event) {
return (sdlMouseButtonUpFilter(event)); return (sdlMouseButtonUpFilter(event));
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
return (sdlMouseButtonDownFilter(event)); return (sdlMouseButtonDownFilter(event));
case SDL_MOUSEWHEEL:
return (sdlMouseWheelFilter(event));
case SDL_QUIT:
SDL_Quit();
_exit(0);
break;
default: break;
} // switch } // switch
return (1); return (1);
@ -614,8 +622,11 @@ int main(int argc, char *argv[]) {
} // if } // if
*/ */
SDL_ClearError(); #ifdef DEDICATED
int rc = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_CDROM); setenv("SDL_VIDEODRIVER", "dummy", 1);
#endif
int rc = SDL_Init(SDL_INIT_VIDEO);
if (rc != 0) { if (rc != 0) {
fprintf(stderr, "SDL: SDL_Init() failed! rc == (%d).\n", rc); fprintf(stderr, "SDL: SDL_Init() failed! rc == (%d).\n", rc);
fprintf(stderr, "SDL_GetError() reports \"%s\".\n", SDL_GetError()); fprintf(stderr, "SDL_GetError() reports \"%s\".\n", SDL_GetError());
@ -625,7 +636,7 @@ int main(int argc, char *argv[]) {
// atexit(SDL_Quit); // atexit(SDL_Quit);
// !!! FIXME: Don't use an event filter! // !!! FIXME: Don't use an event filter!
SDL_SetEventFilter(d3SDLEventFilter); SDL_SetEventFilter(d3SDLEventFilter, NULL);
install_signal_handlers(); install_signal_handlers();
// build the command line as one long string, seperated by spaces... // build the command line as one long string, seperated by spaces...

View File

@ -31,6 +31,8 @@
#include <errno.h> #include <errno.h>
#include <sys/mount.h> #include <sys/mount.h>
#include "SDL.h"
#include "loki_utils.h" #include "loki_utils.h"
#define BAIL_IF_MACRO(x, y, z) \ #define BAIL_IF_MACRO(x, y, z) \
@ -174,236 +176,6 @@ int loki_getmountpoint(const char *device, char *mountpoint, int max_size) {
} }
#endif #endif
char *__PHYSFS_platformCurrentDir(void) {
int allocSize = 0;
char *retval = NULL;
char *ptr;
do {
allocSize += 100;
ptr = (char *)realloc(retval, allocSize);
if (ptr == NULL) {
if (retval != NULL)
free(retval);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
retval = ptr;
ptr = getcwd(retval, allocSize);
} while (ptr == NULL && errno == ERANGE);
if (ptr == NULL && errno) {
/*
* getcwd() failed for some reason, for example current
* directory not existing.
*/
if (retval != NULL)
free(retval);
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
} /* if */
return (retval);
} /* __PHYSFS_platformCurrentDir */
/*
* See where program (bin) resides in the $PATH specified by (envr).
* returns a copy of the first element in envr that contains it, or NULL
* if it doesn't exist or there were other problems. PHYSFS_SetError() is
* called if we have a problem.
*
* (envr) will be scribbled over, and you are expected to free() the
* return value when you're done with it.
*/
static char *findBinaryInPath(const char *bin, char *envr) {
size_t alloc_size = 0;
char *exe = NULL;
char *start = envr;
char *ptr;
BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL);
BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL);
do {
size_t size;
ptr = strchr(start, ':'); /* find next $PATH separator. */
if (ptr)
*ptr = '\0';
size = strlen(start) + strlen(bin) + 2;
if (size > alloc_size) {
char *x = (char *)realloc(exe, size);
if (x == NULL) {
if (exe != NULL)
free(exe);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
alloc_size = size;
exe = x;
} /* if */
/* build full binary path... */
strcpy(exe, start);
if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/'))
strcat(exe, "/");
strcat(exe, bin);
if (access(exe, X_OK) == 0) /* Exists as executable? We're done. */
{
strcpy(exe, start); /* i'm lazy. piss off. */
return (exe);
} /* if */
start = ptr + 1; /* start points to beginning of next element. */
} while (ptr != NULL);
if (exe != NULL)
free(exe);
return (NULL); /* doesn't exist in path. */
} /* findBinaryInPath */
char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname) {
const char *envr = getenv(varname);
char *retval = NULL;
if (envr != NULL) {
retval = (char *)malloc(strlen(envr) + 1);
if (retval != NULL)
strcpy(retval, envr);
} /* if */
return (retval);
} /* __PHYSFS_platformCopyEnvironmentVariable */
static char *getUserNameByUID(void) {
uid_t uid = getuid();
struct passwd *pw;
char *retval = NULL;
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_name != NULL)) {
retval = (char *)malloc(strlen(pw->pw_name) + 1);
if (retval != NULL)
strcpy(retval, pw->pw_name);
} /* if */
return (retval);
} /* getUserNameByUID */
static char *getUserDirByUID(void) {
uid_t uid = getuid();
struct passwd *pw;
char *retval = NULL;
pw = getpwuid(uid);
if ((pw != NULL) && (pw->pw_dir != NULL)) {
retval = (char *)malloc(strlen(pw->pw_dir) + 1);
if (retval != NULL)
strcpy(retval, pw->pw_dir);
} /* if */
return (retval);
} /* getUserDirByUID */
char *__PHYSFS_platformGetUserName(void) {
char *retval = getUserNameByUID();
if (retval == NULL)
retval = __PHYSFS_platformCopyEnvironmentVariable("USER");
return (retval);
} /* __PHYSFS_platformGetUserName */
char *__PHYSFS_platformGetUserDir(void) {
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
if (retval == NULL)
retval = getUserDirByUID();
return (retval);
} /* __PHYSFS_platformGetUserDir */
static int appendDirSep(char **dir) {
const char *dirsep = "/";
char *ptr;
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
return (1);
ptr = (char *)realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
if (!ptr) {
free(*dir);
return (0);
} /* if */
strcat(ptr, dirsep);
*dir = ptr;
return (1);
} /* appendDirSep */
static char *unixCalcBaseDir(const char *argv0) {
/* If there isn't a path on argv0, then look through the $PATH for it. */
char *retval;
char *envr;
if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */
return (NULL);
envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
BAIL_IF_MACRO(!envr, NULL, NULL);
retval = findBinaryInPath(argv0, envr);
free(envr);
return (retval);
}
static char *calcBaseDir(const char *argv0) {
const char *dirsep = "/";
char *retval;
char *ptr;
/*
* See if the platform driver wants to handle this for us...
*/
retval = unixCalcBaseDir(argv0);
if (retval != NULL)
return (retval);
/*
* Determine if there's a path on argv0. If there is, that's the base dir.
*/
ptr = strstr(argv0, dirsep);
if (ptr != NULL) {
char *p = ptr;
size_t size;
while (p != NULL) {
ptr = p;
p = strstr(p + 1, dirsep);
} /* while */
size = (size_t)(ptr - argv0);
retval = (char *)malloc(size + 1);
if (retval == NULL)
return NULL;
memcpy(retval, argv0, size);
retval[size] = '\0';
return (retval);
} /* if */
/*
* Last ditch effort: it's the current working directory. (*shrug*)
*/
retval = __PHYSFS_platformCurrentDir();
if (retval != NULL) {
return (retval);
}
/*
* Ok, current directory doesn't exist, use the root directory.
* Not a good alternative, but it only happens if the current
* directory was deleted from under the program.
*/
retval = (char *)malloc(strlen(dirsep) + 1);
strcpy(retval, dirsep);
return (retval);
}
static char *basepath = NULL; static char *basepath = NULL;
static char *prefpath = NULL; static char *prefpath = NULL;
@ -413,65 +185,18 @@ const char *loki_getdatapath(void) { return basepath; }
const char *loki_getprefpath(void) { return prefpath; } const char *loki_getprefpath(void) { return prefpath; }
void loki_initialize(int argc, char **argv, char *desc) { void loki_initialize(int argc, char **argv, char *desc) {
char resolved_path[MAXPATHLEN]; basepath = SDL_GetBasePath();
char *ptr = __PHYSFS_platformGetUserDir();
if (!ptr) {
fprintf(stderr, "ERROR: environment variable HOME not set?!");
exit(42);
}
#if MACOSX
const char *extra = "Library/Application Support/Descent 3";
#else
const char *extra = ".loki/descent3";
#endif
prefpath = (char *)malloc(strlen(ptr) + strlen(extra) + 3);
strcpy(prefpath, ptr);
if (prefpath[strlen(prefpath) - 1] != '/')
strcat(prefpath, "/");
free(ptr);
strcat(prefpath, extra);
ptr = prefpath;
while ((ptr = strchr(ptr, '/')) != NULL) {
*ptr = '\0';
mkdir(prefpath, S_IRWXU);
*ptr = '/';
ptr++;
}
mkdir(prefpath, S_IRWXU);
basepath = calcBaseDir(argv[0]);
if (basepath == NULL) { if (basepath == NULL) {
fprintf(stderr, "ERROR: Couldn't find game directory!\n"); fprintf(stderr, "ERROR: Couldn't find game directory!\n");
exit(43); exit(43);
} }
if (realpath(prefpath, resolved_path)) { prefpath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3");
ptr = (char *)realloc(prefpath, strlen(resolved_path) + 1); if (prefpath == NULL) {
if (ptr) { fprintf(stderr, "ERROR: Couldn't find preference directory!\n");
strcpy(ptr, resolved_path); exit(43);
prefpath = ptr;
}
} }
if (realpath(basepath, resolved_path)) {
ptr = (char *)realloc(basepath, strlen(resolved_path) + 1);
if (ptr) {
strcpy(ptr, resolved_path);
basepath = ptr;
}
}
// Strip out Application Bundle...
#if MACOSX
{
// !!! FIXME
}
#endif
// printf("base path: %s\n", basepath); // printf("base path: %s\n", basepath);
// printf("pref path: %s\n", prefpath); // printf("pref path: %s\n", prefpath);

View File

@ -51,7 +51,7 @@ cmake --build --preset mac --config [Debug|Release]
#### Building - Linux (Ubuntu) #### Building - Linux (Ubuntu)
```sh ```sh
sudo apt update sudo apt update
sudo apt install -y --no-install-recommends ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev zlib1g-dev libspdlog-dev sudo apt install -y --no-install-recommends ninja-build cmake g++ libsdl2-dev libncurses-dev zlib1g-dev libspdlog-dev
cmake --preset linux -D ENABLE_LOGGER=[ON|OFF] cmake --preset linux -D ENABLE_LOGGER=[ON|OFF]
cmake --build --preset linux --config [Debug|Release] cmake --build --preset linux --config [Debug|Release]
``` ```
@ -59,7 +59,7 @@ cmake --build --preset linux --config [Debug|Release]
#### Building - Linux (Fedora) #### Building - Linux (Fedora)
```sh ```sh
sudo dnf update --refresh sudo dnf update --refresh
sudo dnf install -y ninja-build cmake gcc-c++ SDL-devel SDL_image-devel ncurses-devel zlib-devel spdlog-devel sudo dnf install -y ninja-build cmake gcc-c++ SDL2-devel ncurses-devel zlib-devel spdlog-devel
cmake --preset linux -D ENABLE_LOGGER=[ON|OFF] cmake --preset linux -D ENABLE_LOGGER=[ON|OFF]
cmake --build --preset linux --config [Debug|Release] cmake --build --preset linux --config [Debug|Release]
``` ```

View File

@ -95,7 +95,6 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <SDL.h>
#include "mem.h" #include "mem.h"
#include "mono.h" #include "mono.h"
#include "ddio.h" #include "ddio.h"
@ -242,8 +241,6 @@ void cdrom_set_system_shutdown(void) {
system_cdroms::system_cdroms(void) { reinit(); } system_cdroms::system_cdroms(void) { reinit(); }
void system_cdroms::reinit(void) { void system_cdroms::reinit(void) {
SDL_QuitSubSystem(SDL_INIT_CDROM);
SDL_Init(SDL_INIT_CDROM);
m_CreatedMountPoint = false; m_CreatedMountPoint = false;
m_NumCDRoms = 0; m_NumCDRoms = 0;
m_DeviceToUse = -1; m_DeviceToUse = -1;
@ -253,10 +250,9 @@ void system_cdroms::reinit(void) {
} // reinit } // reinit
system_cdroms::~system_cdroms(void) { system_cdroms::~system_cdroms(void) {
// SDL_QuitSubSystem(SDL_INIT_CDROM);
} }
int system_cdroms::GetNumCDRoms(void) { return (SDL_CDNumDrives()); } int system_cdroms::GetNumCDRoms(void) { return 0; }
// Returns the device name of the default drive // Returns the device name of the default drive
const char *system_cdroms::GetDeviceName(void) { return CDName(m_DeviceToUse); } const char *system_cdroms::GetDeviceName(void) { return CDName(m_DeviceToUse); }
@ -264,7 +260,7 @@ const char *system_cdroms::GetDeviceName(void) { return CDName(m_DeviceToUse); }
// Returns the volume name of the default drive // Returns the volume name of the default drive
const char *system_cdroms::GetVolumeName(void) { return GetVolume(m_DeviceToUse); } const char *system_cdroms::GetVolumeName(void) { return GetVolume(m_DeviceToUse); }
const char *system_cdroms::CDName(int drive) { return (SDL_CDName(drive)); } const char *system_cdroms::CDName(int drive) { return NULL; }
const char *system_cdroms::GetVolume(int drive) { const char *system_cdroms::GetVolume(int drive) {
#if 1 // MACOSX #if 1 // MACOSX
@ -342,21 +338,7 @@ const char *system_cdroms::GetVolume(int drive) {
bool system_cdroms::IsCdInDrive(void) { return IsCdInDrive(m_DeviceToUse); } bool system_cdroms::IsCdInDrive(void) { return IsCdInDrive(m_DeviceToUse); }
bool system_cdroms::IsCdInDrive(int drive) { bool system_cdroms::IsCdInDrive(int drive) {
// int cdfd,is_in=0; return false;
// struct cdrom_subchnl info;
// struct stat stbuf;
CDstatus cdStat;
SDL_CD cdInfo;
bool retVal = true;
if (drive < 0 || drive >= m_NumCDRoms)
retVal = false;
else {
cdStat = SDL_CDStatus(&cdInfo);
if ((cdStat == CD_TRAYEMPTY) || (cdStat == CD_ERROR))
retVal = false;
} // else
return (retVal);
} }
static int read_file_string(FILE *fd, char *buffer, int maxsize) { static int read_file_string(FILE *fd, char *buffer, int maxsize) {

View File

@ -199,34 +199,34 @@ inline ubyte sdlkeycode_to_keycode(unsigned int sdlkeycode) {
case SDLK_KP_MULTIPLY: case SDLK_KP_MULTIPLY:
rc = KEY_PADMULTIPLY; rc = KEY_PADMULTIPLY;
break; break;
case SDLK_KP0: case SDLK_KP_0:
rc = KEY_PAD0; rc = KEY_PAD0;
break; break;
case SDLK_KP1: case SDLK_KP_1:
rc = KEY_PAD1; rc = KEY_PAD1;
break; break;
case SDLK_KP2: case SDLK_KP_2:
rc = KEY_PAD2; rc = KEY_PAD2;
break; break;
case SDLK_KP3: case SDLK_KP_3:
rc = KEY_PAD3; rc = KEY_PAD3;
break; break;
case SDLK_KP4: case SDLK_KP_4:
rc = KEY_PAD4; rc = KEY_PAD4;
break; break;
case SDLK_KP5: case SDLK_KP_5:
rc = KEY_PAD5; rc = KEY_PAD5;
break; break;
case SDLK_KP6: case SDLK_KP_6:
rc = KEY_PAD6; rc = KEY_PAD6;
break; break;
case SDLK_KP7: case SDLK_KP_7:
rc = KEY_PAD7; rc = KEY_PAD7;
break; break;
case SDLK_KP8: case SDLK_KP_8:
rc = KEY_PAD8; rc = KEY_PAD8;
break; break;
case SDLK_KP9: case SDLK_KP_9:
rc = KEY_PAD9; rc = KEY_PAD9;
break; break;
case SDLK_SPACE: case SDLK_SPACE:
@ -277,11 +277,11 @@ inline ubyte sdlkeycode_to_keycode(unsigned int sdlkeycode) {
rc = KEY_RCTRL; rc = KEY_RCTRL;
break; break;
case SDLK_LALT: case SDLK_LALT:
case SDLK_LMETA: case SDLK_LGUI:
rc = KEY_LALT; rc = KEY_LALT;
break; break;
case SDLK_RALT: case SDLK_RALT:
case SDLK_RMETA: case SDLK_RGUI:
rc = KEY_RALT; rc = KEY_RALT;
break; break;
@ -319,309 +319,19 @@ inline ubyte sdlkeycode_to_keycode(unsigned int sdlkeycode) {
case SDLK_COMMA: case SDLK_COMMA:
rc = KEY_COMMA; rc = KEY_COMMA;
break; break;
case SDLK_NUMLOCK: case SDLK_NUMLOCKCLEAR:
rc = KEY_NUMLOCK; rc = KEY_NUMLOCK;
break; break;
case SDLK_PRINT: case SDLK_PRINTSCREEN:
rc = KEY_PRINT_SCREEN; rc = KEY_PRINT_SCREEN;
break; break;
case SDLK_SCROLLOCK: case SDLK_SCROLLLOCK:
rc = KEY_SCROLLOCK; rc = KEY_SCROLLOCK;
break; break;
case SDLK_CAPSLOCK: case SDLK_CAPSLOCK:
rc = KEY_CAPSLOCK; rc = KEY_CAPSLOCK;
break; break;
// world keys. Ugh.
case SDLK_WORLD_0:
rc = KEY_WORLD0;
break;
case SDLK_WORLD_1:
rc = KEY_WORLD1;
break;
case SDLK_WORLD_2:
rc = KEY_WORLD2;
break;
case SDLK_WORLD_3:
rc = KEY_WORLD3;
break;
case SDLK_WORLD_4:
rc = KEY_WORLD4;
break;
case SDLK_WORLD_5:
rc = KEY_WORLD5;
break;
case SDLK_WORLD_6:
rc = KEY_WORLD6;
break;
case SDLK_WORLD_7:
rc = KEY_WORLD7;
break;
case SDLK_WORLD_8:
rc = KEY_WORLD8;
break;
case SDLK_WORLD_9:
rc = KEY_WORLD9;
break;
case SDLK_WORLD_10:
rc = KEY_WORLD10;
break;
case SDLK_WORLD_11:
rc = KEY_WORLD11;
break;
case SDLK_WORLD_12:
rc = KEY_WORLD12;
break;
case SDLK_WORLD_13:
rc = KEY_WORLD13;
break;
case SDLK_WORLD_14:
rc = KEY_WORLD14;
break;
case SDLK_WORLD_15:
rc = KEY_WORLD15;
break;
case SDLK_WORLD_16:
rc = KEY_WORLD16;
break;
case SDLK_WORLD_17:
rc = KEY_WORLD17;
break;
case SDLK_WORLD_18:
rc = KEY_WORLD18;
break;
case SDLK_WORLD_19:
rc = KEY_WORLD19;
break;
case SDLK_WORLD_20:
rc = KEY_WORLD20;
break;
case SDLK_WORLD_21:
rc = KEY_WORLD21;
break;
case SDLK_WORLD_22:
rc = KEY_WORLD22;
break;
case SDLK_WORLD_23:
rc = KEY_WORLD23;
break;
case SDLK_WORLD_24:
rc = KEY_WORLD24;
break;
case SDLK_WORLD_25:
rc = KEY_WORLD25;
break;
case SDLK_WORLD_26:
rc = KEY_WORLD26;
break;
case SDLK_WORLD_27:
rc = KEY_WORLD27;
break;
case SDLK_WORLD_28:
rc = KEY_WORLD28;
break;
case SDLK_WORLD_29:
rc = KEY_WORLD29;
break;
case SDLK_WORLD_30:
rc = KEY_WORLD30;
break;
case SDLK_WORLD_31:
rc = KEY_WORLD31;
break;
case SDLK_WORLD_32:
rc = KEY_WORLD32;
break;
case SDLK_WORLD_33:
rc = KEY_WORLD33;
break;
case SDLK_WORLD_34:
rc = KEY_WORLD34;
break;
case SDLK_WORLD_35:
rc = KEY_WORLD35;
break;
case SDLK_WORLD_36:
rc = KEY_WORLD36;
break;
case SDLK_WORLD_37:
rc = KEY_WORLD37;
break;
case SDLK_WORLD_38:
rc = KEY_WORLD38;
break;
case SDLK_WORLD_39:
rc = KEY_WORLD39;
break;
case SDLK_WORLD_40:
rc = KEY_WORLD40;
break;
case SDLK_WORLD_41:
rc = KEY_WORLD41;
break;
case SDLK_WORLD_42:
rc = KEY_WORLD42;
break;
case SDLK_WORLD_43:
rc = KEY_WORLD43;
break;
case SDLK_WORLD_44:
rc = KEY_WORLD44;
break;
case SDLK_WORLD_45:
rc = KEY_WORLD45;
break;
case SDLK_WORLD_46:
rc = KEY_WORLD46;
break;
case SDLK_WORLD_47:
rc = KEY_WORLD47;
break;
case SDLK_WORLD_48:
rc = KEY_WORLD48;
break;
case SDLK_WORLD_49:
rc = KEY_WORLD49;
break;
case SDLK_WORLD_50:
rc = KEY_WORLD50;
break;
case SDLK_WORLD_51:
rc = KEY_WORLD51;
break;
case SDLK_WORLD_52:
rc = KEY_WORLD52;
break;
case SDLK_WORLD_53:
rc = KEY_WORLD53;
break;
case SDLK_WORLD_54:
rc = KEY_WORLD54;
break;
case SDLK_WORLD_55:
rc = KEY_WORLD55;
break;
case SDLK_WORLD_56:
rc = KEY_WORLD56;
break;
case SDLK_WORLD_57:
rc = KEY_WORLD57;
break;
case SDLK_WORLD_58:
rc = KEY_WORLD58;
break;
case SDLK_WORLD_59:
rc = KEY_WORLD59;
break;
case SDLK_WORLD_60:
rc = KEY_WORLD60;
break;
case SDLK_WORLD_61:
rc = KEY_WORLD61;
break;
case SDLK_WORLD_62:
rc = KEY_WORLD62;
break;
case SDLK_WORLD_63:
rc = KEY_WORLD63;
break;
case SDLK_WORLD_64:
rc = KEY_WORLD64;
break;
case SDLK_WORLD_65:
rc = KEY_WORLD65;
break;
case SDLK_WORLD_66:
rc = KEY_WORLD66;
break;
case SDLK_WORLD_67:
rc = KEY_WORLD67;
break;
case SDLK_WORLD_68:
rc = KEY_WORLD68;
break;
case SDLK_WORLD_69:
rc = KEY_WORLD69;
break;
case SDLK_WORLD_70:
rc = KEY_WORLD70;
break;
case SDLK_WORLD_71:
rc = KEY_WORLD71;
break;
case SDLK_WORLD_72:
rc = KEY_WORLD72;
break;
case SDLK_WORLD_73:
rc = KEY_WORLD73;
break;
case SDLK_WORLD_74:
rc = KEY_WORLD74;
break;
case SDLK_WORLD_75:
rc = KEY_WORLD75;
break;
case SDLK_WORLD_76:
rc = KEY_WORLD76;
break;
case SDLK_WORLD_77:
rc = KEY_WORLD77;
break;
case SDLK_WORLD_78:
rc = KEY_WORLD78;
break;
case SDLK_WORLD_79:
rc = KEY_WORLD79;
break;
case SDLK_WORLD_80:
rc = KEY_WORLD80;
break;
case SDLK_WORLD_81:
rc = KEY_WORLD81;
break;
case SDLK_WORLD_82:
rc = KEY_WORLD82;
break;
case SDLK_WORLD_83:
rc = KEY_WORLD83;
break;
case SDLK_WORLD_84:
rc = KEY_WORLD84;
break;
case SDLK_WORLD_85:
rc = KEY_WORLD85;
break;
case SDLK_WORLD_86:
rc = KEY_WORLD86;
break;
case SDLK_WORLD_87:
rc = KEY_WORLD87;
break;
case SDLK_WORLD_88:
rc = KEY_WORLD88;
break;
case SDLK_WORLD_89:
rc = KEY_WORLD89;
break;
case SDLK_WORLD_90:
rc = KEY_WORLD90;
break;
case SDLK_WORLD_91:
rc = KEY_WORLD91;
break;
case SDLK_WORLD_92:
rc = KEY_WORLD92;
break;
case SDLK_WORLD_93:
rc = KEY_WORLD93;
break;
case SDLK_WORLD_94:
rc = KEY_WORLD94;
break;
case SDLK_WORLD_95:
rc = KEY_WORLD95;
break;
// convert 'a' - 'z' to 0-27, and then convert to ddio format. // convert 'a' - 'z' to 0-27, and then convert to ddio format.
default: default:
if (rc >= SDLK_a && rc <= SDLK_z) { if (rc >= SDLK_a && rc <= SDLK_z) {
@ -645,19 +355,14 @@ int sdlKeyFilter(const SDL_Event *event) {
switch (event->key.state) { switch (event->key.state) {
case SDL_PRESSED: case SDL_PRESSED:
if (event->key.repeat) break; // ignore these, we only want to know if it's a first time pressed, not a key-repeat.
kc = sdlkeycode_to_keycode(event->key.keysym.sym); kc = sdlkeycode_to_keycode(event->key.keysym.sym);
if (event->key.keysym.mod & KMOD_CTRL) { if (event->key.keysym.mod & KMOD_CTRL) {
switch (kc) { switch (kc) {
case KEY_G: // toggle grabbed input. case KEY_G: // toggle grabbed input.
if (ddio_mouseGrabbed) { ddio_mouseGrabbed = !ddio_mouseGrabbed;
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_SetRelativeMouseMode(ddio_mouseGrabbed ? SDL_TRUE : SDL_FALSE);
ddio_mouseGrabbed = false; return 0;
} // if
else {
SDL_WM_GrabInput(SDL_GRAB_ON);
ddio_mouseGrabbed = true;
} // else
return (0);
#ifdef __PERMIT_GL_LOGGING #ifdef __PERMIT_GL_LOGGING
case KEY_INSERT: case KEY_INSERT:
@ -681,8 +386,15 @@ int sdlKeyFilter(const SDL_Event *event) {
else if (event->key.keysym.mod & KMOD_ALT) { else if (event->key.keysym.mod & KMOD_ALT) {
if ((kc == KEY_ENTER) || (kc == KEY_PADENTER)) { if ((kc == KEY_ENTER) || (kc == KEY_PADENTER)) {
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); extern SDL_Window *GSDLWindow;
return (0); Uint32 flags = SDL_GetWindowFlags(GSDLWindow);
if (flags & SDL_WINDOW_FULLSCREEN) {
flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
} else {
flags |= SDL_WINDOW_FULLSCREEN; // !!! FIXME: FULLSCREEN_DESKTOP
}
SDL_SetWindowFullscreen(GSDLWindow, flags);
return(0);
} // if } // if
} // else if } // else if
@ -711,9 +423,6 @@ bool ddio_sdl_InternalKeyInit(ddio_init_info *init_info) {
LKeys[i].up_ticks = 0; LKeys[i].up_ticks = 0;
LKeys[i].status = false; LKeys[i].status = false;
} }
SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
SDL_EventState(SDL_KEYUP, SDL_ENABLE);
return true; return true;
} }

View File

@ -125,10 +125,6 @@ static int Mouse_mode = MOUSE_STANDARD_MODE;
bool ddio_MouseInit(void) { bool ddio_MouseInit(void) {
DDIO_mouse_init = true; DDIO_mouse_init = true;
SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
ddio_MouseReset(); ddio_MouseReset();
return true; return true;
} }
@ -211,7 +207,7 @@ int sdlMouseButtonDownFilter(SDL_Event const *event) {
const SDL_MouseButtonEvent *ev = &event->button; const SDL_MouseButtonEvent *ev = &event->button;
t_mse_event mevt; t_mse_event mevt;
if (ev->button == 1) { //(evt.xbutton.state & Button1Mask) || (evt.xbutton.button == Button1)) { if (ev->button == 1) {
DDIO_mouse_state.btn_mask |= MOUSE_LB; DDIO_mouse_state.btn_mask |= MOUSE_LB;
DIM_buttons.down_count[0]++; DIM_buttons.down_count[0]++;
DIM_buttons.time_down[0] = timer_GetTime(); DIM_buttons.time_down[0] = timer_GetTime();
@ -220,7 +216,7 @@ int sdlMouseButtonDownFilter(SDL_Event const *event) {
mevt.state = true; mevt.state = true;
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 0: Down\n")); // mprintf((0, "MOUSE Button 0: Down\n"));
} else if (ev->button == 2) { //((evt.xbutton.state & Button2Mask) || (evt.xbutton.button == Button2)) { } else if (ev->button == 2) {
DDIO_mouse_state.btn_mask |= MOUSE_RB; DDIO_mouse_state.btn_mask |= MOUSE_RB;
DIM_buttons.down_count[1]++; DIM_buttons.down_count[1]++;
DIM_buttons.time_down[1] = timer_GetTime(); DIM_buttons.time_down[1] = timer_GetTime();
@ -230,7 +226,6 @@ int sdlMouseButtonDownFilter(SDL_Event const *event) {
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 1: Down\n")); // mprintf((0, "MOUSE Button 1: Down\n"));
} }
// if ((evt.xbutton.state & Button3Mask) || (evt.xbutton.button == Button3)) {
else if (ev->button == 3) { else if (ev->button == 3) {
DDIO_mouse_state.btn_mask |= MOUSE_CB; DDIO_mouse_state.btn_mask |= MOUSE_CB;
DIM_buttons.down_count[2]++; DIM_buttons.down_count[2]++;
@ -241,19 +236,10 @@ int sdlMouseButtonDownFilter(SDL_Event const *event) {
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 2: Down\n")); // mprintf((0, "MOUSE Button 2: Down\n"));
} }
// if ((evt.xbutton.state & Button4Mask) || (evt.xbutton.button == Button4)) {
else if (ev->button == 4) { /* Mouse scroll up */ // buttons 4 and 5 are reserved for the mouse wheel...that's how the engine works...adjust in here.
DDIO_mouse_state.btn_mask |= MOUSE_B5;
DIM_buttons.down_count[4]++; else if (ev->button == 4) {
DIM_buttons.time_down[4] = timer_GetTime();
DIM_buttons.is_down[4] = true;
mevt.btn = 4;
mevt.state = true;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 4: Down\n"));
}
// if ((evt.xbutton.state & Button5Mask) || (evt.xbutton.button == Button5)) {
else if (ev->button == 5) { /* Mouse scroll down */
DDIO_mouse_state.btn_mask |= MOUSE_B6; DDIO_mouse_state.btn_mask |= MOUSE_B6;
DIM_buttons.down_count[5]++; DIM_buttons.down_count[5]++;
DIM_buttons.time_down[5] = timer_GetTime(); DIM_buttons.time_down[5] = timer_GetTime();
@ -263,6 +249,27 @@ int sdlMouseButtonDownFilter(SDL_Event const *event) {
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 5: Down\n")); // mprintf((0, "MOUSE Button 5: Down\n"));
} }
else if (ev->button == 5) {
DDIO_mouse_state.btn_mask |= MOUSE_B7;
DIM_buttons.down_count[6]++;
DIM_buttons.time_down[6] = timer_GetTime();
DIM_buttons.is_down[6] = true;
mevt.btn = 6;
mevt.state = true;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 6: Down\n"));
}
else if (ev->button == 6) {
DDIO_mouse_state.btn_mask |= MOUSE_B8;
DIM_buttons.down_count[7]++;
DIM_buttons.time_down[7] = timer_GetTime();
DIM_buttons.is_down[7] = true;
mevt.btn = 7;
mevt.state = true;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 7: Down\n"));
}
return (0); return (0);
} }
@ -272,7 +279,6 @@ int sdlMouseButtonUpFilter(SDL_Event const *event) {
const SDL_MouseButtonEvent *ev = &event->button; const SDL_MouseButtonEvent *ev = &event->button;
t_mse_event mevt; t_mse_event mevt;
// if ((evt.xbutton.state & Button1Mask) || (evt.xbutton.button == Button1)) {
if (ev->button == 1) { if (ev->button == 1) {
DDIO_mouse_state.btn_mask &= (~MOUSE_LB); DDIO_mouse_state.btn_mask &= (~MOUSE_LB);
DIM_buttons.up_count[0]++; DIM_buttons.up_count[0]++;
@ -283,7 +289,6 @@ int sdlMouseButtonUpFilter(SDL_Event const *event) {
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 0: Up\n")); // mprintf((0, "MOUSE Button 0: Up\n"));
} }
// if ((evt.xbutton.state & Button2Mask) || (evt.xbutton.button == Button2)) {
else if (ev->button == 2) { else if (ev->button == 2) {
DDIO_mouse_state.btn_mask &= (~MOUSE_RB); DDIO_mouse_state.btn_mask &= (~MOUSE_RB);
DIM_buttons.up_count[1]++; DIM_buttons.up_count[1]++;
@ -294,7 +299,6 @@ int sdlMouseButtonUpFilter(SDL_Event const *event) {
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 1: Up\n")); // mprintf((0, "MOUSE Button 1: Up\n"));
} }
// if ((evt.xbutton.state & Button3Mask) || (evt.xbutton.button == Button3)) {
else if (ev->button == 3) { else if (ev->button == 3) {
DDIO_mouse_state.btn_mask &= (~MOUSE_CB); DDIO_mouse_state.btn_mask &= (~MOUSE_CB);
DIM_buttons.up_count[2]++; DIM_buttons.up_count[2]++;
@ -304,20 +308,12 @@ int sdlMouseButtonUpFilter(SDL_Event const *event) {
mevt.state = false; mevt.state = false;
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 2: Up\n")); // mprintf((0, "MOUSE Button 2: Up\n"));
} }
// if ((evt.xbutton.state & Button4Mask) || (evt.xbutton.button == Button4)) {
// buttons 4 and 5 are reserved for the mouse wheel...that's how the engine works...adjust in here.
else if (ev->button == 4) { else if (ev->button == 4) {
DDIO_mouse_state.btn_mask &= (~MOUSE_B5);
DIM_buttons.up_count[4]++;
DIM_buttons.is_down[4] = false;
DIM_buttons.time_up[4] = timer_GetTime();
mevt.btn = 4;
mevt.state = false;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 4: Up\n"));
}
// if ((evt.xbutton.state & Button5Mask) || (evt.xbutton.button == Button5)) {
else if (ev->button == 5) {
DDIO_mouse_state.btn_mask &= (~MOUSE_B6); DDIO_mouse_state.btn_mask &= (~MOUSE_B6);
DIM_buttons.up_count[5]++; DIM_buttons.up_count[5]++;
DIM_buttons.is_down[5] = false; DIM_buttons.is_down[5] = false;
@ -327,10 +323,81 @@ int sdlMouseButtonUpFilter(SDL_Event const *event) {
MB_queue.send(mevt); MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 5: Up\n")); // mprintf((0, "MOUSE Button 5: Up\n"));
} }
else if (ev->button == 5) {
DDIO_mouse_state.btn_mask &= (~MOUSE_B7);
DIM_buttons.up_count[6]++;
DIM_buttons.is_down[6] = false;
DIM_buttons.time_up[6] = timer_GetTime();
mevt.btn = 6;
mevt.state = false;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 6: Up\n"));
}
else if (ev->button == 6) {
DDIO_mouse_state.btn_mask &= (~MOUSE_B8);
DIM_buttons.up_count[7]++;
DIM_buttons.is_down[7] = false;
DIM_buttons.time_up[7] = timer_GetTime();
mevt.btn = 7;
mevt.state = false;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Button 7: Up\n"));
}
return (0); return (0);
} }
int sdlMouseWheelFilter(SDL_Event const *event) {
ASSERT(event->type == SDL_MOUSEWHEEL);
const SDL_MouseWheelEvent *ev = &event->wheel;
t_mse_event mevt;
// !!! FIXME: this ignores horizontal wheels for now, since Descent3 doesn't currently have a concept of them
// !!! FIXME: (vertical mouse wheels are represented as mouse buttons 4 and 5, incorrectly, on all platforms).
// !!! FIXME: this will require improvements to the engine before this changes here, though.
if (ev->y > 0) { /* Mouse scroll up */
DDIO_mouse_state.btn_mask |= MOUSE_B5;
DIM_buttons.down_count[4]++;
DIM_buttons.time_down[4] = timer_GetTime();
DIM_buttons.is_down[4] = true;
mevt.btn = 4;
mevt.state = true;
MB_queue.send(mevt);
// send an immediate release event, as if the "button" was clicked. !!! FIXME: this also needs improvements in the engine.
// don't remove from btn_mask
DIM_buttons.up_count[4]++;
DIM_buttons.is_down[4] = false;
DIM_buttons.time_up[4] = timer_GetTime();
mevt.btn = 4;
mevt.state = false;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Scrollwheel: Rolled Up\n"));
} else if (ev->y < 0) { /* Mouse scroll down */
DDIO_mouse_state.btn_mask |= MOUSE_B6;
DIM_buttons.down_count[5]++;
DIM_buttons.time_down[5] = timer_GetTime();
DIM_buttons.is_down[5] = true;
mevt.btn = 5;
mevt.state = true;
MB_queue.send(mevt);
// send an immediate release event, as if the "button" was clicked. !!! FIXME: this also needs improvements in the engine.
// don't remove from btn_mask
DIM_buttons.up_count[5]++;
DIM_buttons.is_down[5] = false;
DIM_buttons.time_up[5] = timer_GetTime();
mevt.btn = 5;
mevt.state = false;
MB_queue.send(mevt);
// mprintf((0, "MOUSE Scrollwheel: Rolled Down\n"));
}
return 0;
}
int sdlMouseMotionFilter(SDL_Event const *event) { int sdlMouseMotionFilter(SDL_Event const *event) {
/* /*
int oldmx, oldmy; int oldmx, oldmy;
@ -458,6 +525,10 @@ int ddio_MouseGetState(int *x, int *y, int *dx, int *dy, int *z, int *dz) {
DDIO_mouse_state.dx = 0; DDIO_mouse_state.dx = 0;
DDIO_mouse_state.dy = 0; DDIO_mouse_state.dy = 0;
// unset the mouse wheel "button" once it's been retrieved.
DDIO_mouse_state.btn_mask &= ~(MOUSE_B5|MOUSE_B6);
return btn_mask; return btn_mask;
} }

View File

@ -106,10 +106,6 @@ bool joy_Init(bool remote) {
// FIXME: report an error? // FIXME: report an error?
return false; return false;
} }
SDL_EventState(SDL_JOYAXISMOTION, SDL_IGNORE);
SDL_EventState(SDL_JOYHATMOTION, SDL_IGNORE);
SDL_EventState(SDL_JOYBUTTONDOWN, SDL_IGNORE);
SDL_EventState(SDL_JOYBUTTONUP, SDL_IGNORE);
// check if this OS supports joysticks // check if this OS supports joysticks
if (!joyGetNumDevs() && !remote) { if (!joyGetNumDevs() && !remote) {
@ -155,7 +151,7 @@ static bool joy_InitStick(tJoystick joy, char *server_adr) {
tJoyInfo caps; tJoyInfo caps;
memset(&caps, 0, (sizeof caps)); memset(&caps, 0, (sizeof caps));
strncpy(caps.name, SDL_JoystickName(joy), sizeof(caps.name) - 1); strncpy(caps.name, SDL_JoystickNameForIndex(joy), sizeof(caps.name) - 1);
caps.num_btns = SDL_JoystickNumButtons(stick); caps.num_btns = SDL_JoystickNumButtons(stick);
int axes = SDL_JoystickNumAxes(stick); int axes = SDL_JoystickNumAxes(stick);
switch (axes) { switch (axes) {

View File

@ -237,6 +237,7 @@ inline void SetDebugBreakHandlers(void (*stop)(), void (*resume)()) {
Int3(); \ Int3(); \
} while (0) } while (0)
#elif defined(LINUX) #elif defined(LINUX)
#include "SDL.h"
// For some reason Linux doesn't like the \ continuation character, so I have to uglify this // For some reason Linux doesn't like the \ continuation character, so I have to uglify this
#define DEBUG_BREAK() \ #define DEBUG_BREAK() \
do { \ do { \
@ -246,16 +247,7 @@ inline void SetDebugBreakHandlers(void (*stop)(), void (*resume)()) {
if (DebugBreak_callback_resume) \ if (DebugBreak_callback_resume) \
(*DebugBreak_callback_resume)(); \ (*DebugBreak_callback_resume)(); \
} while (0) } while (0)
#define ASSERT(x) \ #define ASSERT(x) SDL_assert(x)
do { \
if (!(unsigned long long)(x)) { \
mprintf((0, "Assertion failed (%s) in %s line %d.\n", #x, __FILE__, __LINE__)); \
if (Debug_break) \
DEBUG_BREAK(); \
else \
AssertionFailed(#x, __FILE__, __LINE__); \
} \
} while (0)
#define Int3() \ #define Int3() \
do { \ do { \
mprintf((0, "Int3 at %s line %d.\n", __FILE__, __LINE__)); \ mprintf((0, "Int3 at %s line %d.\n", __FILE__, __LINE__)); \

View File

@ -775,6 +775,8 @@ static void LinuxSoundMixBuffersIntoMain(int len) {
} }
static void LinuxSoundThreadHandler(void *unused, Uint8 *stream, int len) { static void LinuxSoundThreadHandler(void *unused, Uint8 *stream, int len) {
SDL_memset(stream, '\0', len);
LnxBuffers[0]->buffer = stream; LnxBuffers[0]->buffer = stream;
LnxBuffers[0]->buffer_len = len; LnxBuffers[0]->buffer_len = len;
LnxBuffers[0]->play_cursor = 0; LnxBuffers[0]->play_cursor = 0;

View File

@ -80,6 +80,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <term.h> #include <term.h>
#include <termios.h> #include <termios.h>
#ifdef buttons // termios.h defines buttons, but SDL's headers use that symbol.
#undef buttons
#endif
#include <stdio.h> #include <stdio.h>
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/shm.h> #include <sys/shm.h>
@ -148,8 +153,6 @@ void LnxAppShutdown(void) {
if (LinuxAppFlags & OEAPP_CONSOLE) { if (LinuxAppFlags & OEAPP_CONSOLE) {
con_Destroy(); con_Destroy();
tcsetattr(0, TCSANOW, &Linux_initial_terminal_settings); tcsetattr(0, TCSANOW, &Linux_initial_terminal_settings);
} else {
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
} }
} }
@ -163,8 +166,6 @@ oeLnxApplication::oeLnxApplication(unsigned flags) {
con_Create(m_Flags); con_Create(m_Flags);
} }
SDL_EnableKeyRepeat(0, 0);
LinuxAppFlags = m_Flags; LinuxAppFlags = m_Flags;
if (!LinuxAppSetAtExit) { if (!LinuxAppSetAtExit) {
@ -252,7 +253,6 @@ void oeLnxApplication::set_sizepos(int x, int y, int w, int h) {
const char *oeLnxApplication::get_window_name(void) { return "Descent 3"; } const char *oeLnxApplication::get_window_name(void) { return "Descent 3"; }
void oeLnxApplication::clear_window(void) { void oeLnxApplication::clear_window(void) {
SDL_FillRect(SDL_GetVideoSurface(), NULL, SDL_MapRGB(SDL_GetVideoSurface()->format, 255, 0, 0));
} }
// initializes OS components. // initializes OS components.

View File

@ -65,7 +65,7 @@ int LnxDraw_InitVideo(LnxVideoDesc *ldesc) {
return 0; return 0;
} }
int d3SDLEventFilter(const SDL_Event *event); int SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event);
///////////////////////// /////////////////////////
// LnxDraw_CreateWindow // LnxDraw_CreateWindow
@ -78,8 +78,10 @@ int d3SDLEventFilter(const SDL_Event *event);
// -2 : Display not opened // -2 : Display not opened
// -3 : Out of memory // -3 : Out of memory
int LnxDraw_CreateWindow(LnxWindowDesc *ldesc, LnxWindow **lphandle) { int LnxDraw_CreateWindow(LnxWindowDesc *ldesc, LnxWindow **lphandle) {
#if 1
SDL_Log("!!! FIXME no movie window %s:%d\n", __FILE__, __LINE__);
return -1; return -1;
#else
if (!ldesc || !lphandle) if (!ldesc || !lphandle)
return -1; return -1;
*lphandle = NULL; *lphandle = NULL;
@ -93,7 +95,7 @@ int LnxDraw_CreateWindow(LnxWindowDesc *ldesc, LnxWindow **lphandle) {
fprintf(stderr, "SDL_GetError() reports \"%s\".\n", SDL_GetError()); fprintf(stderr, "SDL_GetError() reports \"%s\".\n", SDL_GetError());
return (-2); return (-2);
} // if } // if
SDL_SetEventFilter(d3SDLEventFilter); SDL_SetEventFilter(d3SDLEventFilter, NULL);
SDL_Rect **modes = LinuxVideoMode.getModes(); SDL_Rect **modes = LinuxVideoMode.getModes();
Uint32 sdlflags = LinuxVideoMode.getSDLFlags(); Uint32 sdlflags = LinuxVideoMode.getSDLFlags();
@ -315,6 +317,7 @@ int LnxDraw_CreateWindow(LnxWindowDesc *ldesc, LnxWindow **lphandle) {
} }
return 0; return 0;
#endif
} }
////////////////////////// //////////////////////////
@ -326,7 +329,10 @@ int LnxDraw_CreateWindow(LnxWindowDesc *ldesc, LnxWindow **lphandle) {
// 0 : no error // 0 : no error
// -1 : invalid parameter // -1 : invalid parameter
int LnxDraw_DestroyWindow(LnxWindow *handle) { int LnxDraw_DestroyWindow(LnxWindow *handle) {
#if 1
SDL_Log("!!! FIXME no movie window %s:%d\n", __FILE__, __LINE__);
return -1; return -1;
#else
int i; int i;
LnxWindow *wnd = NULL; LnxWindow *wnd = NULL;
@ -373,6 +379,7 @@ int LnxDraw_DestroyWindow(LnxWindow *handle) {
free(wnd); free(wnd);
return 0; return 0;
#endif
} }
//////////////////////// ////////////////////////
@ -385,6 +392,10 @@ int LnxDraw_DestroyWindow(LnxWindow *handle) {
// false : error // false : error
bool LnxDraw_LockSurface(LnxWindow *wnd, unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned char **ptr, bool LnxDraw_LockSurface(LnxWindow *wnd, unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned char **ptr,
int *pitch) { int *pitch) {
#if 1
SDL_Log("!!! FIXME no movie window %s:%d\n", __FILE__, __LINE__);
return false;
#else
return -1; return -1;
if (!wnd || !ptr || !pitch) if (!wnd || !ptr || !pitch)
return false; return false;
@ -460,6 +471,7 @@ bool LnxDraw_LockSurface(LnxWindow *wnd, unsigned x1, unsigned y1, unsigned x2,
*ptr = ((unsigned char *)wnd->surface->pixels) + ((wnd->surface->format->BytesPerPixel * wnd->dwWidth) * linesDown); *ptr = ((unsigned char *)wnd->surface->pixels) + ((wnd->surface->format->BytesPerPixel * wnd->dwWidth) * linesDown);
return true; return true;
#endif
} }
////////////////////////// //////////////////////////
@ -468,7 +480,9 @@ bool LnxDraw_LockSurface(LnxWindow *wnd, unsigned x1, unsigned y1, unsigned x2,
// Unlocks the window surface, blitting the buffer // Unlocks the window surface, blitting the buffer
// //
void LnxDraw_UnlockSurface(LnxWindow *wnd, unsigned char *ptr) { void LnxDraw_UnlockSurface(LnxWindow *wnd, unsigned char *ptr) {
return; #if 1
SDL_Log("!!! FIXME no movie window %s:%d\n", __FILE__, __LINE__);
#else
if (!wnd->bLocked) if (!wnd->bLocked)
return; return;
bool still_have_shared = true; bool still_have_shared = true;
@ -514,6 +528,7 @@ void LnxDraw_UnlockSurface(LnxWindow *wnd, unsigned char *ptr) {
SDL_SaveBMP(wnd->surface, filename); SDL_SaveBMP(wnd->surface, filename);
framenum++; framenum++;
#endif #endif
#endif
} }
//////////////////////////// ////////////////////////////

View File

@ -218,7 +218,7 @@ CFtpGet::CFtpGet(char *URL, char *localfile, char *Username, char *Password) {
} }
// if(df_pthread_create(&thread,NULL,FTPObjThread,this)!=0) // if(df_pthread_create(&thread,NULL,FTPObjThread,this)!=0)
thread = SDL_CreateThread(FTPObjThread, this); thread = SDL_CreateThread(FTPObjThread, "ftpget", this);
if (thread == NULL) { if (thread == NULL) {
m_State = FTP_STATE_INTERNAL_ERROR; m_State = FTP_STATE_INTERNAL_ERROR;
return; return;

View File

@ -291,7 +291,7 @@ void ChttpGet::GetFile(char *URL, char *localfile) {
} }
// if(df_pthread_create(&thread,NULL,HTTPObjThread,this)!=0) // if(df_pthread_create(&thread,NULL,HTTPObjThread,this)!=0)
thread = SDL_CreateThread(HTTPObjThread, this); thread = SDL_CreateThread(HTTPObjThread, "httpget", this);
if (thread == NULL) { if (thread == NULL) {
m_State = HTTP_STATE_INTERNAL_ERROR; m_State = HTTP_STATE_INTERNAL_ERROR;
return; return;
@ -713,7 +713,7 @@ int http_Asyncgethostbyname(unsigned int *ip, int command, char *hostname) {
} }
// df_pthread_create(&thread,NULL,http_gethostbynameworker,newaslu); // df_pthread_create(&thread,NULL,http_gethostbynameworker,newaslu);
newaslu->threadId = SDL_CreateThread(http_gethostbynameworker, newaslu); newaslu->threadId = SDL_CreateThread(http_gethostbynameworker, "httpdns", newaslu);
#endif #endif
return 1; return 1;
} else if (command == NW_AGHBN_CANCEL) { } else if (command == NW_AGHBN_CANCEL) {

View File

@ -2158,7 +2158,7 @@ int nw_Asyncgethostbyname(unsigned int *ip, int command, char *hostname) {
// rcg06192000 SDLified. // rcg06192000 SDLified.
// pthread_t thread; // pthread_t thread;
// dpthread_create(&thread, NULL, gethostbynameworker,newaslu); // dpthread_create(&thread, NULL, gethostbynameworker,newaslu);
aslu.threadId = SDL_CreateThread(gethostbynameworker, &aslu); aslu.threadId = SDL_CreateThread(gethostbynameworker, "dnsworker", &aslu);
} }
#else #else
HOSTENT *he = gethostbyname(lastaslu->host); HOSTENT *he = gethostbyname(lastaslu->host);

View File

@ -108,6 +108,8 @@ static HDC hOpenGLDC = NULL;
HGLRC ResourceContext; HGLRC ResourceContext;
static WORD Saved_gamma_values[256 * 3]; static WORD Saved_gamma_values[256 * 3];
#elif defined(__LINUX__) #elif defined(__LINUX__)
SDL_Window *GSDLWindow = NULL;
SDL_GLContext GSDLGLContext = NULL;
char loadedLibrary[_MAX_PATH]; char loadedLibrary[_MAX_PATH];
#else #else
#endif #endif
@ -216,7 +218,7 @@ int checkForGLErrors( const char *file, int line )
counter++ ; counter++ ;
} }
*/ */
char *sdlp = SDL_GetError(); const char *sdlp = SDL_GetError();
if(sdlp && *sdlp) if(sdlp && *sdlp)
mprintf((0,"SDL: %s",sdlp)); mprintf((0,"SDL: %s",sdlp));
return 1; return 1;
@ -566,7 +568,7 @@ void setMinimumAcceptableRenderTime(int ms) {
extern bool linux_permit_gamma; extern bool linux_permit_gamma;
extern renderer_preferred_state Render_preferred_state; extern renderer_preferred_state Render_preferred_state;
extern bool ddio_mouseGrabbed; extern bool ddio_mouseGrabbed;
int d3SDLEventFilter(const SDL_Event *event); int SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event);
int opengl_Setup(oeApplication *app, int *width, int *height) { int opengl_Setup(oeApplication *app, int *width, int *height) {
// rcg11192000 don't check for FPS. // rcg11192000 don't check for FPS.
@ -595,15 +597,9 @@ int opengl_Setup(oeApplication *app, int *width, int *height) {
rend_SetErrorMessage(buffer); rend_SetErrorMessage(buffer);
return (0); return (0);
} // if } // if
SDL_SetEventFilter(d3SDLEventFilter); SDL_SetEventFilter(d3SDLEventFilter, NULL);
bool fullscreen = false; bool fullscreen = true;
char *env = getenv("MESA_GLX_FX");
if ((!env) || (*env == 'f')) // Full screen Mesa mode !!! needs more.
{
fullscreen = true;
}
if (FindArgChar("-fullscreen", 'f')) { if (FindArgChar("-fullscreen", 'f')) {
fullscreen = true; fullscreen = true;
@ -611,15 +607,6 @@ int opengl_Setup(oeApplication *app, int *width, int *height) {
fullscreen = false; fullscreen = false;
} }
#if 0 // this was for 3DFx Voodoo cards...probably don't need this anymore. --ryan 04/27/2024
if (env == NULL) {
putenv((char *)(fullscreen ? "MESA_GLX_FX=f" : "MESA_GLX_FX=w"));
}
putenv("FX_GLIDE_NO_SPLASH=1");
#endif
if (!Already_loaded) { if (!Already_loaded) {
#define MAX_ARGS 30 #define MAX_ARGS 30
#define MAX_CHARS_PER_ARG 100 #define MAX_CHARS_PER_ARG 100
@ -631,18 +618,10 @@ int opengl_Setup(oeApplication *app, int *width, int *height) {
if (arg != 0) { if (arg != 0) {
strcpy(gl_library, GameArgs[arg + 1]); strcpy(gl_library, GameArgs[arg + 1]);
} else { } else {
#if defined(MACOSX) gl_library[0] = 0;
strcpy(gl_library, "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib");
#else
strcpy(gl_library, "libGL.so");
#endif
} }
mprintf((0, "OpenGL: Attempting to use \"%s\" for OpenGL\n", gl_library)); mprintf((0, "OpenGL: Attempting to use \"%s\" for OpenGL\n", gl_library[0] ? gl_library : "[system default library]"));
#if 0 // this was for 3DFx Voodoo cards...probably don't need this anymore. --ryan 04/27/2024
putenv("MESA_FX_NO_SIGNALS=ihatesegfaults");
#endif
// ryan's adds. 04/18/2000...SDL stuff on 04/25/2000 // ryan's adds. 04/18/2000...SDL stuff on 04/25/2000
bool success = true; bool success = true;
@ -690,45 +669,45 @@ int opengl_Setup(oeApplication *app, int *width, int *height) {
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
int flags = SDL_OPENGL; Uint32 flags = SDL_WINDOW_OPENGL;
if (fullscreen) { if (fullscreen) {
flags |= SDL_FULLSCREEN; flags |= SDL_WINDOW_FULLSCREEN;
} }
// Should we shoot for 32-bpp if available? !!!
SDL_Surface *surface = SDL_SetVideoMode(*width, *height, 32, flags); GSDLWindow = SDL_CreateWindow("Descent 3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, *width, *height, flags);
mprintf((0, "OpenGL: SDL GL surface is %sNULL.", (surface == NULL) ? "" : "NOT ")); if (!GSDLWindow) {
mprintf((0, "OpenGL: SDL window creation failed: %s", SDL_GetError()));
return 0;
}
GSDLGLContext = SDL_GL_CreateContext(GSDLWindow);
if (!GSDLGLContext) {
mprintf((0, "OpenGL: OpenGL context creation failed: %s", SDL_GetError()));
SDL_DestroyWindow(GSDLWindow);
GSDLWindow = NULL;
return 0;
}
if (!FindArg("-nomousecap")) { if (!FindArg("-nomousecap")) {
// ShowCursor(0) and input grabbing need to be done before setting
// the video mode, or the Voodoo 3 gets a hardware cursor stuck
// on the screen.
// On modern systems this is not necessary and must be done after to take effect.
SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);
ddio_mouseGrabbed = true; ddio_mouseGrabbed = true;
} }
if (ddio_mouseGrabbed == false) { SDL_SetRelativeMouseMode(ddio_mouseGrabbed ? SDL_TRUE : SDL_FALSE);
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
SDL_WM_SetCaption("Descent 3", "Descent3");
// rcg09182000 gamma fun. // rcg09182000 gamma fun.
// rcg01112000 --nogamma fun. // rcg01112000 --nogamma fun.
if (FindArgChar("-nogamma", 'M')) { if (FindArgChar("-nogamma", 'M')) {
linux_permit_gamma = false; linux_permit_gamma = false;
} else { } else {
float f = Render_preferred_state.gamma; Uint16 ramp[256];
bool gammarc = SDL_SetGamma(f, f, f); SDL_CalculateGammaRamp(Render_preferred_state.gamma, ramp);
linux_permit_gamma = (gammarc == 0); linux_permit_gamma = (SDL_SetWindowGammaRamp(GSDLWindow, ramp, ramp, ramp) == 0);
} // else } // else
if (ParentApplication) { if (ParentApplication) {
reinterpret_cast<oeLnxApplication *>(ParentApplication)->set_sizepos(0, 0, *width, *height); reinterpret_cast<oeLnxApplication *>(ParentApplication)->set_sizepos(0, 0, *width, *height);
SDL_FillRect(SDL_GetVideoSurface(), NULL, SDL_MapRGB(SDL_GetVideoSurface()->format, 255, 0, 0));
} }
Already_loaded = 1; Already_loaded = 1;
@ -1061,7 +1040,16 @@ void opengl_Close() {
#endif #endif
} }
#elif defined(__LINUX__) #elif defined(__LINUX__)
// SDL_Quit() handles this for us. if (GSDLGLContext) {
SDL_GL_MakeCurrent(NULL, NULL);
SDL_GL_DeleteContext(GSDLGLContext);
GSDLGLContext = NULL;
}
if (GSDLWindow) {
SDL_DestroyWindow(GSDLWindow);
GSDLWindow = NULL;
}
#else #else
#endif #endif
@ -2323,6 +2311,8 @@ void rend_StartFrame(int x1, int y1, int x2, int y2, int clear_flags) {
} }
#ifdef __CHECK_FOR_TOO_SLOW_RENDERING__ #ifdef __CHECK_FOR_TOO_SLOW_RENDERING__
// !!! FIXME: delete this whole section (and definitely the Loki email and phone number!).
#error do not compile this in. This was for software mesa problems in 2000.
static void slownessAbort(void) { static void slownessAbort(void) {
#ifdef __LINUX__ #ifdef __LINUX__
@ -2376,7 +2366,7 @@ void rend_Flip(void) {
#if defined(WIN32) #if defined(WIN32)
SwapBuffers((HDC)hOpenGLDC); SwapBuffers((HDC)hOpenGLDC);
#elif defined(__LINUX__) #elif defined(__LINUX__)
SDL_GL_SwapBuffers(); SDL_GL_SwapWindow(GSDLWindow);
#endif #endif
#ifdef __PERMIT_GL_LOGGING #ifdef __PERMIT_GL_LOGGING

View File

@ -228,12 +228,12 @@ module *LoadOpenGLDLL(const char *dllname) {
#ifdef __LINUX__ #ifdef __LINUX__
char *tmp = getcwd(NULL, 0); char *tmp = getcwd(NULL, 0);
chdir(__orig_pwd); chdir(__orig_pwd);
int rc = SDL_GL_LoadLibrary(dllname); int rc = SDL_GL_LoadLibrary(dllname[0] ? dllname : NULL);
chdir(tmp); chdir(tmp);
free(tmp); free(tmp);
if (rc < 0) { if (rc < 0) {
const char *sdlErr = SDL_GetError(); const char *sdlErr = SDL_GetError();
mprintf((0, "OpenGL: Couldn't open library [%s].\n", dllname)); mprintf((0, "OpenGL: Couldn't open library [%s].\n", dllname[0] ? dllname : "system default"));
mprintf((0, "OpenGL: SDL error is [%s].", sdlErr)); mprintf((0, "OpenGL: SDL error is [%s].", sdlErr));
return NULL; return NULL;
} }

View File

@ -115,6 +115,7 @@ CLnxVideoModes::~CLnxVideoModes() {
// enumerate all the possible video modes // enumerate all the possible video modes
bool CLnxVideoModes::Init(void) // Display *dpy,int screen) bool CLnxVideoModes::Init(void) // Display *dpy,int screen)
{ {
#if 0 // with SDL2, we'll just use FULLSCREEN_DESKTOP and never change the physical vidmode
if (m_Inited) if (m_Inited)
return true; return true;
@ -181,6 +182,7 @@ bool CLnxVideoModes::Init(void) // Display *dpy,int screen)
} // for } // for
mprintf((0, "-------------------------\n")); mprintf((0, "-------------------------\n"));
} // else } // else
#endif
return true; return true;
} }