mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
Cleanup sdlmain.cpp
Remove unused global variables, rewrite internal functions, remove `-game_checksum` cmdline option.
This commit is contained in:
parent
c6ab519652
commit
30f8fefa0b
@ -26,6 +26,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
@ -52,14 +53,12 @@
|
||||
#include "descent.h"
|
||||
#include "dedicated_server.h"
|
||||
#include "init.h"
|
||||
#include "osiris_dll.h"
|
||||
|
||||
std::filesystem::path orig_pwd;
|
||||
|
||||
static volatile char already_tried_signal_cleanup = 0;
|
||||
|
||||
|
||||
void just_exit(void) {
|
||||
void just_exit() {
|
||||
ddio_InternalClose(); // try to reset serial port.
|
||||
|
||||
SDL_Quit();
|
||||
@ -91,55 +90,43 @@ void fatal_signal_handler(int signum) {
|
||||
just_exit();
|
||||
} // else
|
||||
break;
|
||||
case SIGXCPU:
|
||||
case SIGXFSZ:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_exit(-10);
|
||||
}
|
||||
|
||||
void safe_signal_handler(int signum) {}
|
||||
|
||||
void install_signal_handlers() {
|
||||
struct sigaction sact{}, fact{};
|
||||
struct sigaction fact{};
|
||||
|
||||
memset(&sact, 0, sizeof(sact));
|
||||
memset(&fact, 0, sizeof(fact));
|
||||
sact.sa_handler = safe_signal_handler;
|
||||
fact.sa_handler = fatal_signal_handler;
|
||||
|
||||
if (sigaction(SIGHUP, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGHUP\n");
|
||||
if (sigaction(SIGABRT, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGABRT\n");
|
||||
if (sigaction(SIGINT, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGINT\n");
|
||||
if (sigaction(SIGBUS, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGBUS\n");
|
||||
if (sigaction(SIGFPE, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGFPE\n");
|
||||
if (sigaction(SIGILL, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGILL\n");
|
||||
if (sigaction(SIGQUIT, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGQUIT\n");
|
||||
if (sigaction(SIGSEGV, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGSEGV\n");
|
||||
if (sigaction(SIGTERM, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGTERM\n");
|
||||
if (sigaction(SIGXCPU, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGXCPU\n");
|
||||
if (sigaction(SIGXFSZ, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGXFSZ\n");
|
||||
if (sigaction(SIGVTALRM, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGVTALRM\n");
|
||||
if (sigaction(SIGTRAP, &fact, NULL))
|
||||
fprintf(stderr, "SIG: Unable to install SIGTRAP\n");
|
||||
const std::map<int, std::string> signals = {
|
||||
{SIGHUP, "SIGHUP"},
|
||||
{SIGABRT, "SIGABRT"},
|
||||
{SIGINT, "SIGINT"},
|
||||
{SIGBUS, "SIGBUS"},
|
||||
{SIGFPE, "SIGFPE"},
|
||||
{SIGILL, "SIGILL"},
|
||||
{SIGQUIT, "SIGQUIT"},
|
||||
{SIGSEGV, "SIGSEGV"},
|
||||
{SIGTERM, "SIGTERM"},
|
||||
{SIGXCPU, "SIGXCPU"},
|
||||
{SIGXFSZ, "SIGXFSZ"},
|
||||
{SIGVTALRM, "SIGVTALRM"},
|
||||
{SIGTRAP, "SIGTRAP"},
|
||||
};
|
||||
|
||||
for (const auto &signal : signals) {
|
||||
if (sigaction(signal.first, &fact, nullptr) != 0) {
|
||||
LOG_WARNING << "SIG: Unable to install " << signal.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
void install_signal_handlers() {
|
||||
SetUnhandledExceptionFilter(RecordExceptionInfo);
|
||||
}
|
||||
void install_signal_handlers() { SetUnhandledExceptionFilter(RecordExceptionInfo); }
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -300,7 +287,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// !!! FIXME: Don't use an event filter!
|
||||
SDL_SetEventFilter(d3SDLEventFilter, NULL);
|
||||
SDL_SetEventFilter(d3SDLEventFilter, nullptr);
|
||||
install_signal_handlers();
|
||||
|
||||
int winArg = FindArgChar("-windowed", 'w');
|
||||
@ -309,22 +296,10 @@ int main(int argc, char *argv[]) {
|
||||
if ((fsArg) && (winArg)) {
|
||||
LOG_FATAL.printf("ERROR: %s AND %s specified!", GameArgs[winArg], GameArgs[fsArg]);
|
||||
return (0);
|
||||
} // if
|
||||
}
|
||||
|
||||
if (FindArg("-game_checksum")) {
|
||||
extern tOSIRISModuleInit Osiris_module_init;
|
||||
extern void Osiris_CreateModuleInitStruct(tOSIRISModuleInit * st);
|
||||
extern uint32_t Osiris_CreateGameChecksum(void);
|
||||
|
||||
Osiris_CreateModuleInitStruct(&Osiris_module_init);
|
||||
uint32_t checksum = Osiris_CreateGameChecksum();
|
||||
printf("Descent 3\n");
|
||||
printf("Game Checksum: %u\n", checksum);
|
||||
return (0);
|
||||
} else {
|
||||
/*initialize our OS Object. This could be a game dependant OS object, or a default OS object.
|
||||
once we create it, if successful, we can start the game.
|
||||
*/
|
||||
// Initialize our OS Object. This could be a game dependant OS object, or a default OS object.
|
||||
// Once we create it, if successful, we can start the game.
|
||||
int flags = 0;
|
||||
|
||||
if (!FindArgChar("-dedicated", 'd')) {
|
||||
@ -341,6 +316,8 @@ int main(int argc, char *argv[]) {
|
||||
flags |= APPFLAG_NOSHAREDMEMORY;
|
||||
}
|
||||
flags |= APPFLAG_WINDOWEDMODE;
|
||||
|
||||
|
||||
#else
|
||||
LOG_FATAL << "Error: \"--dedicated\" or \"-d\" flag required";
|
||||
return 0;
|
||||
@ -382,7 +359,6 @@ int main(int argc, char *argv[]) {
|
||||
d3.init();
|
||||
d3.run();
|
||||
}
|
||||
}
|
||||
|
||||
just_exit();
|
||||
return 0;
|
||||
|
@ -379,7 +379,8 @@ int opengl_Setup(oeApplication *app, const int *width, const int *height) {
|
||||
gl_library[0] = 0;
|
||||
}
|
||||
|
||||
mprintf(0, "OpenGL: Attempting to use \"%s\" for OpenGL\n", gl_library[0] ? gl_library : "[system default library]");
|
||||
LOG_INFO.printf("OpenGL: Attempting to use \"%s\" for OpenGL",
|
||||
gl_library[0] ? gl_library : "[system default library]");
|
||||
|
||||
// ryan's adds. 04/18/2000...SDL stuff on 04/25/2000
|
||||
bool success = true;
|
||||
@ -516,7 +517,7 @@ int opengl_Setup(oeApplication *app, const int *width, const int *height) {
|
||||
Uint16 ramp[256];
|
||||
SDL_CalculateGammaRamp(Render_preferred_state.gamma, ramp);
|
||||
SDL_SetWindowGammaRamp(GSDLWindow, ramp, ramp, ramp);
|
||||
} // else
|
||||
}
|
||||
|
||||
if (ParentApplication) {
|
||||
reinterpret_cast<oeLnxApplication *>(ParentApplication)->set_sizepos(0, 0, *width, *height);
|
||||
|
Loading…
Reference in New Issue
Block a user