From 56f2b2ac562f9dffc17a5eb35753a996344bacd4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 18:22:21 +0200 Subject: [PATCH] - reduce backend's dependency on game state by using callbacks. --- src/CMakeLists.txt | 1 + src/common/engine/i_interface.cpp | 3 + src/common/engine/i_interface.h | 13 +++ src/common/engine/palettecontainer.cpp | 1 + src/common/utility/basics.h | 7 ++ src/d_main.cpp | 75 +++++++++++++++- src/doomtype.h | 7 -- src/g_game.cpp | 9 +- src/playsim/bots/b_game.cpp | 37 ++++++++ src/playsim/p_interaction.cpp | 2 +- src/posix/cocoa/i_input.mm | 35 +------- src/posix/i_system.h | 2 - src/posix/i_system_posix.cpp | 11 --- src/posix/osx/i_specialpaths.mm | 21 ----- src/posix/sdl/i_input.cpp | 24 +---- src/posix/sdl/i_joystick.cpp | 5 +- src/posix/unix/i_specialpaths.cpp | 64 +++++++------ src/r_data/v_palette.cpp | 3 +- src/win32/hardware.cpp | 4 +- src/win32/i_input.cpp | 34 +++---- src/win32/i_input.h | 3 +- src/win32/i_mouse.cpp | 41 +-------- src/win32/i_rawps2.cpp | 1 + src/win32/i_specialpaths.cpp | 119 ++++++++++++++++--------- src/win32/i_system.cpp | 31 ------- src/win32/i_system.h | 2 - src/win32/i_xinput.cpp | 1 + src/win32/win32basevideo.cpp | 2 +- src/win32/win32glvideo.cpp | 7 +- 29 files changed, 289 insertions(+), 276 deletions(-) create mode 100644 src/common/engine/i_interface.cpp create mode 100644 src/common/engine/i_interface.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cf29d66fa..4a2914c8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1147,6 +1147,7 @@ set (PCH_SOURCES common/engine/sc_man.cpp common/engine/palettecontainer.cpp common/engine/stringtable.cpp + common/engine/i_interface.cpp utility/m_random.cpp utility/nodebuilder/nodebuild.cpp diff --git a/src/common/engine/i_interface.cpp b/src/common/engine/i_interface.cpp new file mode 100644 index 000000000..b95563279 --- /dev/null +++ b/src/common/engine/i_interface.cpp @@ -0,0 +1,3 @@ +#include "i_interface.h" + +SystemCallbacks *sysCallbacks; diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h new file mode 100644 index 000000000..0199f97ea --- /dev/null +++ b/src/common/engine/i_interface.h @@ -0,0 +1,13 @@ +#pragma once + + +struct SystemCallbacks +{ + bool (*WantGuiCapture)(); + bool (*WantLeftButton)(); + bool (*NetGame)(); + bool (*WantNativeMouse)(); + bool (*CaptureModeInGame)(); +}; + +extern SystemCallbacks *sysCallbacks; diff --git a/src/common/engine/palettecontainer.cpp b/src/common/engine/palettecontainer.cpp index 41e9a01ba..e42e60cc8 100644 --- a/src/common/engine/palettecontainer.cpp +++ b/src/common/engine/palettecontainer.cpp @@ -71,6 +71,7 @@ void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index) Remap[i] = i; } + uniqueRemaps[0]->MakeIdentity(); // update the identity remap. if (transparent_index >= 0 && transparent_index <= 255) diff --git a/src/common/utility/basics.h b/src/common/utility/basics.h index 1ae1f1764..d71554473 100644 --- a/src/common/utility/basics.h +++ b/src/common/utility/basics.h @@ -57,3 +57,10 @@ typedef uint32_t angle_t; using INTBOOL = int; using BITFIELD = uint32_t; #endif + + +#if defined(_MSC_VER) +#define NOVTABLE __declspec(novtable) +#else +#define NOVTABLE +#endif \ No newline at end of file diff --git a/src/d_main.cpp b/src/d_main.cpp index cbfdb86b7..b0fdde095 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -106,6 +106,7 @@ #include "md5.h" #include "c_buttons.h" #include "d_buttons.h" +#include "i_interface.h" EXTERN_CVAR(Bool, hud_althud) EXTERN_CVAR(Int, vr_mode) @@ -2541,6 +2542,19 @@ static const char *DoomButtons[] = CVAR(Bool, lookspring, true, CVAR_ARCHIVE); // Generate centerview when -mlook encountered? EXTERN_CVAR(String, language) +CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) +{ + if (self < 0) + { + self = 0; + } + else if (self > 2) + { + self = 2; + } +} + + void Mlook_ReleaseHandler() { if (lookspring) @@ -2560,6 +2574,56 @@ bool StrTable_ValidFilter(const char* str) return stricmp(str, GameNames[gameinfo.gametype]) == 0; } +bool System_WantGuiCapture() +{ + bool wantCapt; + + if (menuactive == MENU_Off) + { + wantCapt = ConsoleState == c_down || ConsoleState == c_falling || chatmodeon; + } + else + { + wantCapt = (menuactive == MENU_On || menuactive == MENU_OnNoPause); + } + + // [ZZ] check active event handlers that want the UI processing + if (!wantCapt && primaryLevel->localEventManager->CheckUiProcessors()) + wantCapt = true; + + return wantCapt; +} + +bool System_WantLeftButton() +{ + return (gamestate == GS_DEMOSCREEN || gamestate == GS_TITLELEVEL); +} + +bool System_NetGame() +{ + return netgame; +} + +bool System_WantNativeMouse() +{ + return primaryLevel->localEventManager->CheckRequireMouse(); +} + +static bool System_CaptureModeInGame() +{ + switch (mouse_capturemode) + { + default: + case 0: + return gamestate == GS_LEVEL; + case 1: + return gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_FINALE; + case 2: + return true; + } +} + + //========================================================================== // // D_DoomMain @@ -2588,6 +2652,16 @@ static int D_DoomMain_Internal (void) StrTable_GetGender }; GStrings.SetCallbacks(&stblcb); + + static SystemCallbacks syscb = + { + System_WantGuiCapture, + System_WantLeftButton, + System_NetGame, + System_WantNativeMouse, + System_CaptureModeInGame, + }; + sysCallbacks = &syscb; std::set_new_handler(NewFailure); const char *batchout = Args->CheckValue("-errorlog"); @@ -2872,7 +2946,6 @@ static int D_DoomMain_Internal (void) C_InitConback(); StartScreen->Progress(); - GPalette.Init(NUM_TRANSLATION_TABLES); V_InitFonts(); // [CW] Parse any TEAMINFO lumps. diff --git a/src/doomtype.h b/src/doomtype.h index cabd3f5be..6121d1294 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -33,13 +33,6 @@ class PClassActor; typedef TMap FClassMap; - -#if defined(_MSC_VER) -#define NOVTABLE __declspec(novtable) -#else -#define NOVTABLE -#endif - #include "basics.h" #include "printf.h" diff --git a/src/g_game.cpp b/src/g_game.cpp index 84ac12047..9fb12d612 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -557,6 +557,13 @@ FBaseCVar* G_GetUserCVar(int playernum, const char* cvarname) return cvar; } +static ticcmd_t emptycmd; + +ticcmd_t* G_BaseTiccmd() +{ + return &emptycmd; +} + // // G_BuildTiccmd @@ -574,7 +581,7 @@ void G_BuildTiccmd (ticcmd_t *cmd) ticcmd_t *base; - base = I_BaseTiccmd (); // empty, or external driver + base = G_BaseTiccmd (); *cmd = *base; cmd->consistancy = consistancy[consoleplayer][(maketic/ticdup)%BACKUPTICS]; diff --git a/src/playsim/bots/b_game.cpp b/src/playsim/bots/b_game.cpp index bec02d6bd..8810fd33b 100644 --- a/src/playsim/bots/b_game.cpp +++ b/src/playsim/bots/b_game.cpp @@ -470,6 +470,43 @@ void FCajunMaster::ForgetBots () botinfo = NULL; } +#if defined _WIN32 || defined __APPLE__ + +FString M_GetCajunPath(const char* botfilename) +{ + FString path; + + path << progdir << "zcajun/" << botfilename; + if (!FileExists(path)) + { + path = ""; + } + return path; +} + +#else + +FString M_GetCajunPath(const char* botfilename) +{ + FString path; + + // Check first in $HOME/.config/zdoom/botfilename. + path = GetUserFile(botfilename); + if (!FileExists(path)) + { + // Then check in SHARE_DIR/botfilename. + path = SHARE_DIR; + path << botfilename; + if (!FileExists(path)) + { + path = ""; + } + } + return path; +} + +#endif + bool FCajunMaster::LoadBots () { FScanner sc; diff --git a/src/playsim/p_interaction.cpp b/src/playsim/p_interaction.cpp index 826379081..a9fae573d 100644 --- a/src/playsim/p_interaction.cpp +++ b/src/playsim/p_interaction.cpp @@ -1362,7 +1362,7 @@ static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int da temp = damage < 100 ? damage : 100; if (player == target->Level->GetConsolePlayer() ) { - I_Tactile (40,10,40+temp*2); + //I_Tactile (40,10,40+temp*2); } } else diff --git a/src/posix/cocoa/i_input.mm b/src/posix/cocoa/i_input.mm index 261f5e98b..6b1991e8c 100644 --- a/src/posix/cocoa/i_input.mm +++ b/src/posix/cocoa/i_input.mm @@ -47,6 +47,7 @@ #include "events.h" #include "g_game.h" #include "g_levellocals.h" +#include "i_interface.h" EXTERN_CVAR(Int, m_use_mouse) @@ -57,19 +58,6 @@ CVAR(Bool, m_filter, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) -{ - if (self < 0) - { - self = 0; - } - else if (self > 2) - { - self = 2; - } -} - - extern int paused, chatmodeon; extern constate_e ConsoleState; @@ -152,24 +140,6 @@ void CenterCursor() SetCursorPosition(centerPoint); } -bool IsInGame() -{ - switch (mouse_capturemode) - { - default: - case 0: - return gamestate == GS_LEVEL; - - case 1: - return gamestate == GS_LEVEL - || gamestate == GS_INTERMISSION - || gamestate == GS_FINALE; - - case 2: - return true; - } -} - void CheckNativeMouse() { const bool windowed = (NULL == screen) || !screen->IsFullscreen(); @@ -187,8 +157,9 @@ void CheckNativeMouse() } else { + bool captureModeInGame = sysCallbacks && sysCallbacks->CaptureModeInGame && sysCallbacks->CaptureModeInGame(); wantNative = (!m_use_mouse || MENU_WaitKey != menuactive) - && (!IsInGame() || GUICapture || paused || demoplayback); + && (!captureModeInGame || GUICapture || paused || demoplayback); } } else diff --git a/src/posix/i_system.h b/src/posix/i_system.h index d3ba2945a..61bc8356b 100644 --- a/src/posix/i_system.h +++ b/src/posix/i_system.h @@ -79,8 +79,6 @@ void I_StartTic (void); // for normal input. ticcmd_t *I_BaseTiccmd (void); -void I_Tactile (int on, int off, int total); - // Print a console string void I_PrintStr (const char *str); diff --git a/src/posix/i_system_posix.cpp b/src/posix/i_system_posix.cpp index 179d9f5b7..cef139be4 100644 --- a/src/posix/i_system_posix.cpp +++ b/src/posix/i_system_posix.cpp @@ -32,17 +32,6 @@ #include "x86.h" -void I_Tactile(int /*on*/, int /*off*/, int /*total*/) -{ -} - -static ticcmd_t emptycmd; - -ticcmd_t *I_BaseTiccmd() -{ - return &emptycmd; -} - bool I_WriteIniFailed() { printf("The config file %s could not be saved:\n%s\n", GameConfig->GetPathName(), strerror(errno)); diff --git a/src/posix/osx/i_specialpaths.mm b/src/posix/osx/i_specialpaths.mm index 08be8c0bb..b414d566a 100644 --- a/src/posix/osx/i_specialpaths.mm +++ b/src/posix/osx/i_specialpaths.mm @@ -150,27 +150,6 @@ FString M_GetAutoexecPath() return path; } -//=========================================================================== -// -// M_GetCajunPath macOS -// -// Returns the location of the Cajun Bot definitions. -// -//=========================================================================== - -FString M_GetCajunPath(const char *botfilename) -{ - FString path; - - // Just copies the Windows code. Should this be more Mac-specific? - path << progdir << "zcajun/" << botfilename; - if (!FileExists(path)) - { - path = ""; - } - return path; -} - //=========================================================================== // // M_GetConfigPath macOS diff --git a/src/posix/sdl/i_input.cpp b/src/posix/sdl/i_input.cpp index cf6520e94..e1f9ca75b 100644 --- a/src/posix/sdl/i_input.cpp +++ b/src/posix/sdl/i_input.cpp @@ -48,6 +48,7 @@ #include "g_levellocals.h" #include "utf8.h" #include "engineerrors.h" +#include "i_interface.h" static void I_CheckGUICapture (); @@ -251,32 +252,13 @@ static void MouseRead () } } -CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) -{ - if (self < 0) self = 0; - else if (self > 2) self = 2; -} - -static bool inGame() -{ - switch (mouse_capturemode) - { - default: - case 0: - return gamestate == GS_LEVEL; - case 1: - return gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_FINALE; - case 2: - return true; - } -} - static void I_CheckNativeMouse () { bool focus = SDL_GetKeyboardFocus() != NULL; bool fs = screen->IsFullscreen(); - bool wantNative = !focus || (!use_mouse || GUICapture || paused || demoplayback || !inGame()); + bool captureModeInGame = sysCallbacks && sysCallbacks->CaptureModeInGame && sysCallbacks->CaptureModeInGame(); + bool wantNative = !focus || (!use_mouse || GUICapture || paused || demoplayback || !captureModeInGame); if (wantNative != NativeMouse) { diff --git a/src/posix/sdl/i_joystick.cpp b/src/posix/sdl/i_joystick.cpp index 14015550b..ad3416a10 100644 --- a/src/posix/sdl/i_joystick.cpp +++ b/src/posix/sdl/i_joystick.cpp @@ -32,9 +32,10 @@ */ #include -#include "doomdef.h" +#include "basics.h" #include "templates.h" #include "m_joy.h" +#include "keydef.h" // Very small deadzone so that floating point magic doesn't happen #define MIN_DEADZONE 0.000001f @@ -155,7 +156,7 @@ public: FString GetIdentifier() { char id[16]; - mysnprintf(id, countof(id), "JS:%d", DeviceIndex); + snprintf(id, countof(id), "JS:%d", DeviceIndex); return id; } diff --git a/src/posix/unix/i_specialpaths.cpp b/src/posix/unix/i_specialpaths.cpp index 7effd9128..524f94c60 100644 --- a/src/posix/unix/i_specialpaths.cpp +++ b/src/posix/unix/i_specialpaths.cpp @@ -37,6 +37,7 @@ #include #include "i_system.h" #include "cmdlib.h" +#include "printf.h" #include "engineerrors.h" #include "version.h" // for GAMENAME @@ -152,33 +153,6 @@ FString M_GetAutoexecPath() return GetUserFile("autoexec.cfg"); } -//=========================================================================== -// -// M_GetCajunPath Unix -// -// Returns the location of the Cajun Bot definitions. -// -//=========================================================================== - -FString M_GetCajunPath(const char *botfilename) -{ - FString path; - - // Check first in $HOME/.config/zdoom/botfilename. - path = GetUserFile(botfilename); - if (!FileExists(path)) - { - // Then check in SHARE_DIR/botfilename. - path = SHARE_DIR; - path << botfilename; - if (!FileExists(path)) - { - path = ""; - } - } - return path; -} - //=========================================================================== // // M_GetConfigPath Unix @@ -217,7 +191,7 @@ FString M_GetScreenshotsPath() FString M_GetSavegamesPath() { - return NicePath("$HOME/" GAME_DIR); + return NicePath("$HOME/" GAME_DIR "/"); } //=========================================================================== @@ -230,5 +204,37 @@ FString M_GetSavegamesPath() FString M_GetDocumentsPath() { - return NicePath("$HOME/" GAME_DIR); + return NicePath("$HOME/" GAME_DIR "/"); } + +//=========================================================================== +// +// M_GetDemoPath Unix +// +// Returns the path to the default demo directory. +// +//=========================================================================== + +FString M_GetDemoPath() +{ + return M_GetDocumentsPath() + "demo/"; +} + +//=========================================================================== +// +// M_NormalizedPath +// +// Normalizes the given path and returns the result. +// +//=========================================================================== + +FString M_GetNormalizedPath(const char* path) +{ + char *actualpath; + actualpath = realpath(path, NULL); + if (!actualpath) // error ? + return nullptr; + FString fullpath = actualpath; + return fullpath; +} + diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index 2d9ae90b1..c2f24a2ba 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -156,7 +156,8 @@ void InitPalette () ReadPalette(fileSystem.GetNumForName("PLAYPAL"), pal); - GPalette.SetPalette (pal); + GPalette.Init(NUM_TRANSLATION_TABLES); + GPalette.SetPalette (pal, 0); MakeGoodRemap ((uint32_t*)GPalette.BaseColors, GPalette.Remap); ColorMatcher.SetPalette ((uint32_t *)GPalette.BaseColors); diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 61c4fa311..e654097f6 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -39,9 +39,10 @@ #include "hardware.h" #include "c_dispatch.h" #include "v_text.h" -#include "doomstat.h" +#include "basics.h" #include "m_argv.h" #include "version.h" +#include "printf.h" #include "win32glvideo.h" #include "win32polyvideo.h" #ifdef HAVE_VULKAN @@ -49,7 +50,6 @@ #endif #include "engineerrors.h" #include "i_system.h" -#include "swrenderer/r_swrenderer.h" EXTERN_CVAR(Int, vid_preferbackend) diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index ce6b76a0d..9f62559f8 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -68,14 +68,10 @@ #include "c_dispatch.h" -#include "doomdef.h" -#include "doomstat.h" #include "m_argv.h" #include "i_input.h" #include "v_video.h" #include "i_sound.h" -#include "g_game.h" -#include "d_main.h" #include "d_gui.h" #include "c_console.h" #include "s_sound.h" @@ -84,11 +80,12 @@ #include "d_event.h" #include "v_text.h" #include "version.h" -#include "events.h" #include "engineerrors.h" #include "i_system.h" -#include "g_levellocals.h" +#include "i_interface.h" +#include "printf.h" #include "c_buttons.h" +#include "cmdlib.h" int32_t refreshfreq = -1; @@ -116,6 +113,7 @@ static HMODULE DInputDLL; bool GUICapture; extern FMouse *Mouse; extern FKeyboard *Keyboard; +extern bool ToggleFullscreen; bool VidResizing; @@ -136,8 +134,8 @@ static bool noidle = false; LPDIRECTINPUT8 g_pdi; LPDIRECTINPUT g_pdi3; - extern bool AppActive; + int SessionState = 0; int BlockMouseMove; @@ -151,20 +149,7 @@ extern int chatmodeon; static void I_CheckGUICapture () { - bool wantCapt; - - if (menuactive == MENU_Off) - { - wantCapt = ConsoleState == c_down || ConsoleState == c_falling || chatmodeon; - } - else - { - wantCapt = (menuactive == MENU_On || menuactive == MENU_OnNoPause); - } - - // [ZZ] check active event handlers that want the UI processing - if (!wantCapt && primaryLevel->localEventManager->CheckUiProcessors()) - wantCapt = true; + bool wantCapt = sysCallbacks && sysCallbacks->WantGuiCapture && sysCallbacks->WantGuiCapture(); if (wantCapt != GUICapture) { @@ -427,7 +412,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return result; } - if ((gamestate == GS_DEMOSCREEN || gamestate == GS_TITLELEVEL) && message == WM_LBUTTONDOWN) + if (message == WM_LBUTTONDOWN && sysCallbacks && sysCallbacks->WantLeftButton() && sysCallbacks->WantLeftButton()) { if (GUIWndProcHook(hWnd, message, wParam, lParam, &result)) { @@ -462,6 +447,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_SETFOCUS: + GetRefreshRate(hWnd); I_CheckNativeMouse (false, EventHandlerResultForNativeMouse); // This cannot call the event handler. Doing it from here is unsafe. break; @@ -539,7 +525,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { SetPriorityClass (GetCurrentProcess (), INGAME_PRIORITY_CLASS); } - else if (!noidle && !netgame) + else if (!noidle && !(sysCallbacks && sysCallbacks->NetGame && sysCallbacks->NetGame())) { SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS); } @@ -784,7 +770,7 @@ void I_StartTic () BlockMouseMove--; buttonMap.ResetButtonTriggers (); I_CheckGUICapture (); - EventHandlerResultForNativeMouse = primaryLevel->localEventManager->CheckRequireMouse(); + EventHandlerResultForNativeMouse = sysCallbacks && sysCallbacks->WantNativeMouse && sysCallbacks->WantNativeMouse(); I_CheckNativeMouse (false, EventHandlerResultForNativeMouse); I_GetEvent (); } diff --git a/src/win32/i_input.h b/src/win32/i_input.h index 00f853e9b..5e5204212 100644 --- a/src/win32/i_input.h +++ b/src/win32/i_input.h @@ -34,8 +34,7 @@ #ifndef __I_INPUT_H__ #define __I_INPUT_H__ -#include "doomtype.h" -#include "doomdef.h" +#include "basics.h" bool I_InitInput (void *hwnd); void I_ShutdownInput (); diff --git a/src/win32/i_mouse.cpp b/src/win32/i_mouse.cpp index ce1121c97..62f68ad44 100644 --- a/src/win32/i_mouse.cpp +++ b/src/win32/i_mouse.cpp @@ -41,10 +41,9 @@ #include "i_input.h" #include "d_event.h" #include "d_gui.h" -#include "g_game.h" #include "hardware.h" #include "menu/menu.h" -#include "events.h" +#include "i_interface.h" // MACROS ------------------------------------------------------------------ @@ -181,19 +180,6 @@ CUSTOM_CVAR (Int, in_mouse, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) } } -CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) -{ - if (self < 0) - { - self = 0; - } - else if (self > 2) - { - self = 2; - } -} - - // CODE -------------------------------------------------------------------- //========================================================================== @@ -251,28 +237,6 @@ static void CenterMouse(int curx, int cury, LONG *centxp, LONG *centyp) } } -//========================================================================== -// -// CaptureMode_InGame -// -//========================================================================== - -static bool CaptureMode_InGame() -{ - if (mouse_capturemode == 2) - { - return true; - } - else if (mouse_capturemode == 1) - { - return gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_FINALE; - } - else - { - return gamestate == GS_LEVEL; - } -} - //========================================================================== // // I_CheckNativeMouse @@ -304,8 +268,9 @@ void I_CheckNativeMouse(bool preferNative, bool eventhandlerresult) } else { + bool captureModeInGame = sysCallbacks && sysCallbacks->CaptureModeInGame && sysCallbacks->CaptureModeInGame(); want_native = ((!m_use_mouse || menuactive != MENU_WaitKey) && - (!CaptureMode_InGame() || GUICapture || paused || demoplayback)); + (!captureModeInGame || GUICapture ||paused || demoplayback)); } } diff --git a/src/win32/i_rawps2.cpp b/src/win32/i_rawps2.cpp index 083188a53..a6b31970f 100644 --- a/src/win32/i_rawps2.cpp +++ b/src/win32/i_rawps2.cpp @@ -42,6 +42,7 @@ #include "gameconfigfile.h" #include "m_argv.h" #include "cmdlib.h" +#include "keydef.h" // MACROS ------------------------------------------------------------------ diff --git a/src/win32/i_specialpaths.cpp b/src/win32/i_specialpaths.cpp index 6d0ea884d..8cff2d92c 100644 --- a/src/win32/i_specialpaths.cpp +++ b/src/win32/i_specialpaths.cpp @@ -36,10 +36,11 @@ #include #include #include +#include +#include "printf.h" #include "cmdlib.h" -#include "doomtype.h" -#include "m_misc.h" +#include "findfile.h" #include "version.h" // for GAMENAME // Vanilla MinGW does not have folder ids @@ -65,7 +66,7 @@ bool UseKnownFolders() // Cache this value so the semantics don't change during a single run // of the program. (e.g. Somebody could add write access while the // program is running.) - static INTBOOL iswritable = -1; + static int iswritable = -1; HANDLE file; if (iswritable >= 0) @@ -125,8 +126,6 @@ FString M_GetAppDataPath(bool create) { // Failed (e.g. On Win9x): use program directory path = progdir; } - // Don't use GAME_DIR and such so that ZDoom and its child ports can - // share the node cache. path += "/" GAMENAMELOWERCASE; path.Substitute("//", "/"); // needed because progdir ends with a slash. if (create) @@ -176,33 +175,13 @@ FString M_GetAutoexecPath() return "$PROGDIR/autoexec.cfg"; } -//=========================================================================== -// -// M_GetCajunPath Windows -// -// Returns the location of the Cajun Bot definitions. -// -//=========================================================================== - -FString M_GetCajunPath(const char *botfilename) -{ - FString path; - - path << progdir << "zcajun/" << botfilename; - if (!FileExists(path)) - { - path = ""; - } - return path; -} - //=========================================================================== // // M_GetConfigPath Windows // // Returns the path to the config file. On Windows, this can vary for reading -// vs writing. i.e. If $PROGDIR/zdoom-.ini does not exist, it will try -// to read from $PROGDIR/zdoom.ini, but it will never write to zdoom.ini. +// vs writing. i.e. If the user specific ini does not exist, it will try +// to read from a neutral version, but never write to it. // //=========================================================================== @@ -211,7 +190,7 @@ FString M_GetConfigPath(bool for_reading) FString path; HRESULT hr; - path.Format("%s" GAMENAME "_portable.ini", progdir.GetChars()); + path.Format("%s" GAMENAMELOWERCASE "_portable.ini", progdir.GetChars()); if (FileExists(path)) { return path; @@ -226,12 +205,12 @@ FString M_GetConfigPath(bool for_reading) path += "/" GAMENAMELOWERCASE ".ini"; } else - { // construct "$PROGDIR/zdoom-$USER.ini" - TCHAR uname[UNLEN+1]; - DWORD unamelen = countof(uname); + { // construct "$PROGDIR/-$USER.ini" + WCHAR uname[UNLEN+1]; + DWORD unamelen = UNLEN; path = progdir; - hr = GetUserName(uname, &unamelen); + hr = GetUserNameW(uname, &unamelen); if (SUCCEEDED(hr) && uname[0] != 0) { // Is it valid for a user name to have slashes? @@ -246,13 +225,13 @@ FString M_GetConfigPath(bool for_reading) path << GAMENAMELOWERCASE "-" << FString(uname) << ".ini"; } else - { // Couldn't get user name, so just use zdoom.ini + { // Couldn't get user name, so just use base version. path += GAMENAMELOWERCASE ".ini"; } } // If we are reading the config file, check if it exists. If not, fallback - // to $PROGDIR/zdoom.ini + // to base version. if (for_reading) { if (!FileExists(path)) @@ -283,19 +262,19 @@ FString M_GetScreenshotsPath() if (!UseKnownFolders()) { - return progdir; + path << progdir << "/Screenshots/"; } else if (GetKnownFolder(-1, MyFOLDERID_Screenshots, true, path)) { - path << "/" GAMENAME; + path << "/" GAMENAME "/"; } else if (GetKnownFolder(CSIDL_MYPICTURES, FOLDERID_Pictures, true, path)) { - path << "/Screenshots/" GAMENAME; + path << "/Screenshots/" GAMENAME "/"; } else { - return progdir; + path << progdir << "/Screenshots/"; } CreatePath(path); return path; @@ -315,25 +294,25 @@ FString M_GetSavegamesPath() if (!UseKnownFolders()) { - return progdir; + path << progdir << "Save/"; } // Try standard Saved Games folder else if (GetKnownFolder(-1, FOLDERID_SavedGames, true, path)) { - path << "/" GAMENAME; + path << "/" GAMENAME "/"; } // Try defacto My Documents/My Games folder else if (GetKnownFolder(CSIDL_PERSONAL, FOLDERID_Documents, true, path)) { // I assume since this isn't a standard folder, it doesn't have // a localized name either. - path << "/My Games/" GAMENAME; - CreatePath(path); + path << "/My Games/" GAMENAME "/"; } else { - path = progdir; + path << progdir << "Save/"; } + return path; } @@ -365,7 +344,7 @@ FString M_GetDocumentsPath() { // I assume since this isn't a standard folder, it doesn't have // a localized name either. - path << "/My Games/" GAMENAME; + path << "/My Games/" GAMENAME "/"; CreatePath(path); } else @@ -374,3 +353,55 @@ FString M_GetDocumentsPath() } return path; } + +//=========================================================================== +// +// M_GetDemoPath Windows +// +// Returns the path to the default demp directory. +// +//=========================================================================== + +FString M_GetDemoPath() +{ + FString path; + + // A portable INI means that this storage location should also be portable. + FStringf inipath("%s" GAMENAME "_portable.ini", progdir.GetChars()); + if (FileExists(inipath) || !UseKnownFolders()) + { + path << progdir << "Demos/"; + } + else + // Try defacto My Documents/My Games folder + if (GetKnownFolder(CSIDL_PERSONAL, FOLDERID_Documents, true, path)) + { + // I assume since this isn't a standard folder, it doesn't have + // a localized name either. + path << "/My Games/" GAMENAME "/"; + } + else + { + path << progdir << "Demos/"; + } + + return path; +} + +//=========================================================================== +// +// M_NormalizedPath +// +// Normalizes the given path and returns the result. +// +//=========================================================================== + +FString M_GetNormalizedPath(const char* path) +{ + std::wstring wpath = WideString(path); + wchar_t buffer[MAX_PATH]; + GetFullPathNameW(wpath.c_str(), MAX_PATH, buffer, nullptr); + FString result(buffer); + FixPathSeperator(result); + return result; +} diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 71a804aef..55f48b8ae 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -141,43 +141,12 @@ int sys_ostype = 0; // PRIVATE DATA DEFINITIONS ------------------------------------------------ -static ticcmd_t emptycmd; - static WadStuff *WadList; static int NumWads; static int DefaultWad; static HCURSOR CustomCursor; -//========================================================================== -// -// I_Tactile -// -// Doom calls it when you take damage, so presumably it could be converted -// to something compatible with force feedback. -// -//========================================================================== - -void I_Tactile(int on, int off, int total) -{ - // UNUSED. - on = off = total = 0; -} - -//========================================================================== -// -// I_BaseTiccmd -// -// Returns an empty ticcmd. I have no idea why this should be system- -// specific. -// -//========================================================================== - -ticcmd_t *I_BaseTiccmd() -{ - return &emptycmd; -} - //========================================================================== // // I_DetectOS diff --git a/src/win32/i_system.h b/src/win32/i_system.h index 178002fa2..fb5a49014 100644 --- a/src/win32/i_system.h +++ b/src/win32/i_system.h @@ -78,8 +78,6 @@ ticcmd_t *I_BaseTiccmd (void); void I_Quit (void); -void I_Tactile (int on, int off, int total); - // Set the mouse cursor. The texture must be 32x32. class FTexture; bool I_SetCursor(FTexture *cursor); diff --git a/src/win32/i_xinput.cpp b/src/win32/i_xinput.cpp index 93ef75c01..e473d8bd2 100644 --- a/src/win32/i_xinput.cpp +++ b/src/win32/i_xinput.cpp @@ -44,6 +44,7 @@ #include "gameconfigfile.h" #include "m_argv.h" #include "cmdlib.h" +#include "keydef.h" // MACROS ------------------------------------------------------------------ diff --git a/src/win32/win32basevideo.cpp b/src/win32/win32basevideo.cpp index ed4d382cf..bb1fb81ba 100644 --- a/src/win32/win32basevideo.cpp +++ b/src/win32/win32basevideo.cpp @@ -45,10 +45,10 @@ #include "v_video.h" #include "i_input.h" #include "i_system.h" -#include "doomstat.h" #include "v_text.h" #include "m_argv.h" #include "engineerrors.h" +#include "printf.h" #include "win32basevideo.h" #include "cmdlib.h" diff --git a/src/win32/win32glvideo.cpp b/src/win32/win32glvideo.cpp index 25a9db723..007c6076e 100644 --- a/src/win32/win32glvideo.cpp +++ b/src/win32/win32glvideo.cpp @@ -34,6 +34,7 @@ #include #include +#include #include "wglext.h" #include "gl_sysfb.h" @@ -45,9 +46,9 @@ #include "v_video.h" #include "i_input.h" #include "i_system.h" -#include "doomstat.h" #include "v_text.h" #include "m_argv.h" +#include "printf.h" #include "engineerrors.h" #include "win32glvideo.h" @@ -415,8 +416,8 @@ bool Win32GLVideo::InitHardware(HWND Window, int multisample) if (myWglCreateContextAttribsARB != NULL) { // let's try to get the best version possible. Some drivers only give us the version we request - // which breaks all version checks for feature support. The highest used features we use are from version 4.4, and 3.0 is a requirement. - static int versions[] = { 46, 45, 44, 43, 42, 41, 40, 33, 32, 31, 30, -1 }; + // which breaks all version checks for feature support. The highest used features we use are from version 4.4, and 3.3 is a requirement. + static int versions[] = { 46, 45, 44, 43, 42, 41, 40, 33, -1 }; for (int i = 0; versions[i] > 0; i++) {