mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-20 19:02:23 +00:00
Switch the windows backend SDLmain.
libSDLmain.a has to be linked and must run anyways. So there's no need for us to reinvent the wheel, just rely on SDLs process setup, argument parsing, message handling and so on. As a nice side effect this may fix some strange bugs related to message handling and argument parsing...
This commit is contained in:
parent
d107d999da
commit
cfddff132b
2 changed files with 7 additions and 86 deletions
2
Makefile
2
Makefile
|
@ -1073,7 +1073,7 @@ endif
|
|||
ifeq ($(YQ2_OSTYPE), Windows)
|
||||
release/q2ded.exe : $(SERVER_OBJS) icon
|
||||
@echo "===> LD $@.exe"
|
||||
${Q}$(CC) build/icon/icon.res $(SERVER_OBJS) $(LDFLAGS) -o $@
|
||||
${Q}$(CC) build/icon/icon.res $(SERVER_OBJS) $(LDFLAGS) $(SDLLDFLAGS) -o $@
|
||||
$(Q)strip $@
|
||||
else
|
||||
release/q2ded : $(SERVER_OBJS)
|
||||
|
|
|
@ -33,25 +33,21 @@
|
|||
#include <io.h>
|
||||
#include <conio.h>
|
||||
#include <shlobj.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "SDL2/SDL.h"
|
||||
#include "SDL2/SDL_Main.h"
|
||||
|
||||
#include "../../common/header/common.h"
|
||||
#include "../generic/header/input.h"
|
||||
#include "header/resource.h"
|
||||
#include "header/winquake.h"
|
||||
|
||||
#define MAX_NUM_ARGVS 128
|
||||
|
||||
int starttime;
|
||||
qboolean ActiveApp;
|
||||
qboolean Minimized;
|
||||
|
||||
static HANDLE hinput, houtput;
|
||||
static HANDLE qwclsemaphore;
|
||||
|
||||
HINSTANCE global_hInstance;
|
||||
static HINSTANCE game_library;
|
||||
|
||||
unsigned int sys_msg_time;
|
||||
unsigned int sys_frame_time;
|
||||
|
||||
static char console_text[256];
|
||||
|
@ -61,9 +57,6 @@ char findbase[MAX_OSPATH];
|
|||
char findpath[MAX_OSPATH];
|
||||
int findhandle;
|
||||
|
||||
int argc;
|
||||
char *argv[MAX_NUM_ARGVS];
|
||||
|
||||
qboolean is_portable;
|
||||
|
||||
/* ================================================================ */
|
||||
|
@ -87,11 +80,6 @@ Sys_Error(char *error, ...)
|
|||
|
||||
MessageBox(NULL, text, "Error", 0 /* MB_OK */);
|
||||
|
||||
if (qwclsemaphore)
|
||||
{
|
||||
CloseHandle(qwclsemaphore);
|
||||
}
|
||||
|
||||
/* Close stdout and stderr */
|
||||
#ifndef DEDICATED_ONLY
|
||||
fclose(stdout);
|
||||
|
@ -111,7 +99,6 @@ Sys_Quit(void)
|
|||
#endif
|
||||
|
||||
Qcommon_Shutdown();
|
||||
CloseHandle(qwclsemaphore);
|
||||
|
||||
if (dedicated && dedicated->value)
|
||||
{
|
||||
|
@ -360,40 +347,6 @@ Sys_GetGameAPI(void *parms)
|
|||
|
||||
/* ======================================================================= */
|
||||
|
||||
void
|
||||
ParseCommandLine(LPSTR lpCmdLine)
|
||||
{
|
||||
argc = 1;
|
||||
argv[0] = "exe";
|
||||
|
||||
while (*lpCmdLine && (argc < MAX_NUM_ARGVS))
|
||||
{
|
||||
while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
|
||||
{
|
||||
lpCmdLine++;
|
||||
}
|
||||
|
||||
if (*lpCmdLine)
|
||||
{
|
||||
argv[argc] = lpCmdLine;
|
||||
argc++;
|
||||
|
||||
while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
|
||||
{
|
||||
lpCmdLine++;
|
||||
}
|
||||
|
||||
if (*lpCmdLine)
|
||||
{
|
||||
*lpCmdLine = 0;
|
||||
lpCmdLine++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
long long
|
||||
Sys_Microseconds(void)
|
||||
{
|
||||
|
@ -753,31 +706,17 @@ Sys_SetHighDPIMode(void)
|
|||
* Windows main function. Containts the
|
||||
* initialization code and the main loop
|
||||
*/
|
||||
int WINAPI
|
||||
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine, int nCmdShow)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
MSG msg;
|
||||
long long oldtime, newtime;
|
||||
|
||||
/* Previous instances do not exist in Win32 */
|
||||
if (hPrevInstance)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Make the current instance global */
|
||||
global_hInstance = hInstance;
|
||||
|
||||
/* Setup FPU if necessary */
|
||||
Sys_SetupFPU();
|
||||
|
||||
/* Force DPI awareness */
|
||||
Sys_SetHighDPIMode();
|
||||
|
||||
/* Parse the command line arguments */
|
||||
ParseCommandLine(lpCmdLine);
|
||||
|
||||
/* Are we portable? */
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-portable") == 0) {
|
||||
|
@ -838,24 +777,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||
/* The legendary main loop */
|
||||
while (1)
|
||||
{
|
||||
/* If at a full screen console, don't update unless needed */
|
||||
if (Minimized || (dedicated && dedicated->value))
|
||||
{
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
|
||||
{
|
||||
if (!GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
Com_Quit();
|
||||
}
|
||||
|
||||
sys_msg_time = msg.time;
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
// Throttle the game a little bit
|
||||
Sys_Nanosleep(5000);
|
||||
|
||||
|
|
Loading…
Reference in a new issue