From 1dc6fbda1fbd9a731eb20b3ef71c3dda989e511e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Wed, 22 Jul 2020 14:56:28 +0300 Subject: 64-bit on Windows --- src/skel/crossplatform.h | 2 +- src/skel/glfw/glfw.cpp | 2 +- src/skel/win/win.cpp | 47 ++++++++++++++++++++++++++++++++++++++--------- src/skel/win/win.h | 8 ++++++-- 4 files changed, 46 insertions(+), 13 deletions(-) (limited to 'src/skel') diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index a21877c1..678d3ec4 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -4,7 +4,7 @@ // Functions that's different on glfw and win but have same signature, should be located on platform.h. #ifdef _WIN32 -// This only has as Win header. +// This only has as Windows header, which is lighter (as long as WITHWINDOWS isn't defined / isn't included). #include "win.h" extern DWORD _dwOperatingSystemVersion; #else diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index 630b3345..47dc9e4c 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -63,7 +63,7 @@ static psGlobalType PsGlobal; #undef MAKEPOINTS #define MAKEPOINTS(l) (*((POINTS /*FAR*/ *)&(l))) -unsigned long _dwMemAvailPhys; +size_t _dwMemAvailPhys; RwUInt32 gGameState; #ifdef _WIN32 diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index 9795bde9..9fde9d32 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -19,7 +19,12 @@ #pragma warning( push ) #pragma warning( disable : 4005) + +#ifdef USE_D3D9 +#include +#else #include +#endif #include #include #include @@ -27,7 +32,9 @@ #define WM_GRAPHNOTIFY WM_USER+13 +#ifndef USE_D3D9 #pragma comment( lib, "d3d8.lib" ) +#endif #pragma comment( lib, "ddraw.lib" ) #pragma comment( lib, "Winmm.lib" ) #pragma comment( lib, "dxguid.lib" ) @@ -102,7 +109,7 @@ IMediaSeeking *pMS = nil; DWORD dwDXVersion; SIZE_T _dwMemTotalPhys; -SIZE_T _dwMemAvailPhys; +size_t _dwMemAvailPhys; SIZE_T _dwMemTotalVirtual; SIZE_T _dwMemAvailVirtual; DWORD _dwMemTotalVideo; @@ -449,6 +456,16 @@ DWORD GetDXVersion() dwDXVersion = 0x700; pDD7->Release(); +#ifdef USE_D3D9 + HINSTANCE hD3D9DLL = LoadLibrary("D3D9.DLL"); + if (hD3D9DLL != nil) { + FreeLibrary(hDDrawDLL); + FreeLibrary(hD3D9DLL); + + dwDXVersion = 0x900; + return dwDXVersion; + } +#endif //------------------------------------------------------------------------- // DirectX 8.0 Checks @@ -498,6 +515,7 @@ DWORD GetDXVersion() /* ***************************************************************************** */ +#ifndef _WIN64 static char cpuvendor[16] = "UnknownVendr"; __declspec(naked) const char * _psGetCpuVendr() { @@ -571,6 +589,7 @@ void _psPrintCpuInfo() if ( FeaturesEx & 0x80000000 ) debug("with 3DNow"); } +#endif /* ***************************************************************************** @@ -646,9 +665,9 @@ psInitialize(void) gGameState = GS_START_UP; TRACE("gGameState = GS_START_UP"); - +#ifndef _WIN64 _psPrintCpuInfo(); - +#endif OSVERSIONINFO verInfo; verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); @@ -1284,8 +1303,11 @@ RwBool IsForegroundApp() UINT GetBestRefreshRate(UINT width, UINT height, UINT depth) { +#ifdef USE_D3D9 + LPDIRECT3D9 d3d = Direct3DCreate9(D3D_SDK_VERSION); +#else LPDIRECT3D8 d3d = Direct3DCreate8(D3D_SDK_VERSION); - +#endif ASSERT(d3d != nil); UINT refreshRate = INT_MAX; @@ -1298,14 +1320,21 @@ UINT GetBestRefreshRate(UINT width, UINT height, UINT depth) else format = D3DFMT_R5G6B5; +#ifdef USE_D3D9 + UINT modeCount = d3d->GetAdapterModeCount(GcurSel, format); +#else UINT modeCount = d3d->GetAdapterModeCount(GcurSel); - +#endif + for ( UINT i = 0; i < modeCount; i++ ) { D3DDISPLAYMODE mode; +#ifdef USE_D3D9 + d3d->EnumAdapterModes(GcurSel, format, i, &mode); +#else d3d->EnumAdapterModes(GcurSel, i, &mode); - +#endif if ( mode.Width == width && mode.Height == height && mode.Format == format ) { if ( mode.RefreshRate == 0 ) @@ -1599,7 +1628,7 @@ CommandLineToArgv(RwChar *cmdLine, RwInt32 *argCount) RwInt32 i, len; RwChar *res, *str, **aptr; - len = strlen(cmdLine); + len = (int)strlen(cmdLine); /* * Count the number of arguments... @@ -1687,11 +1716,11 @@ void InitialiseLanguage() { WORD primUserLCID = PRIMARYLANGID(GetSystemDefaultLCID()); WORD primSystemLCID = PRIMARYLANGID(GetUserDefaultLCID()); - WORD primLayout = PRIMARYLANGID((DWORD)GetKeyboardLayout(0)); + WORD primLayout = PRIMARYLANGID((DWORD_PTR)GetKeyboardLayout(0)); WORD subUserLCID = SUBLANGID(GetSystemDefaultLCID()); WORD subSystemLCID = SUBLANGID(GetUserDefaultLCID()); - WORD subLayout = SUBLANGID((DWORD)GetKeyboardLayout(0)); + WORD subLayout = SUBLANGID((DWORD_PTR)GetKeyboardLayout(0)); if ( primUserLCID == LANG_GERMAN || primSystemLCID == LANG_GERMAN diff --git a/src/skel/win/win.h b/src/skel/win/win.h index 444e0760..d19c4e0e 100644 --- a/src/skel/win/win.h +++ b/src/skel/win/win.h @@ -9,8 +9,12 @@ #endif /* (!defined(RSREGSETBREAKALLOC)) */ #ifndef _INC_WINDOWS -#define _X86_ -#include + #ifdef _WIN64 + #define _AMD64_ + #else + #define _X86_ + #endif + #include #endif enum eWinVersion -- cgit v1.2.3 From 15918feb8eca09c38d7a40d67cca10cecc4affdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 24 Jul 2020 20:43:51 +0300 Subject: 90% fixes, 10% skel refactoring --- src/skel/crossplatform.h | 30 +++++++++++++++++++++++------- src/skel/glfw/glfw.cpp | 13 +++++++++++-- src/skel/platform.h | 4 ++++ src/skel/win/win.h | 25 ++----------------------- 4 files changed, 40 insertions(+), 32 deletions(-) (limited to 'src/skel') diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index 678d3ec4..066570be 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -3,19 +3,34 @@ // This is the common include for platform/renderer specific skeletons(glfw.cpp, win.cpp etc.) and using cross platform things (like Windows directories wrapper, platform specific global arrays etc.) // Functions that's different on glfw and win but have same signature, should be located on platform.h. +enum eWinVersion +{ + OS_WIN95 = 0, + OS_WIN98, + OS_WINNT, + OS_WIN2000, + OS_WINXP, +}; + #ifdef _WIN32 -// This only has as Windows header, which is lighter (as long as WITHWINDOWS isn't defined / isn't included). + +// As long as WITHWINDOWS isn't defined / isn't included, include , which is lighter. +#ifndef _INC_WINDOWS + #ifdef _WIN64 + #define _ARM64_ + #else + #define _X86_ + #endif + #include +#endif +#if defined RW_D3D9 || defined RWLIBS #include "win.h" +#endif extern DWORD _dwOperatingSystemVersion; + #else char *strupr(char *str); char *strlwr(char *str); -enum { - OS_WIN98, - OS_WIN2000, - OS_WINNT, - OS_WINXP, -}; enum { LANG_OTHER, @@ -42,6 +57,7 @@ typedef struct RwBool fullScreen; RwV2d lastMousePos; double mouseWheel; // glfw doesn't cache it + bool cursorIsInWindow; RwInt8 joy1id; RwInt8 joy2id; } diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index 47dc9e4c..a1170c61 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -278,6 +278,7 @@ psInitialize(void) RsGlobal.ps = &PsGlobal; PsGlobal.fullScreen = FALSE; + PsGlobal.cursorIsInWindow = TRUE; PsGlobal.joy1id = -1; PsGlobal.joy2id = -1; @@ -786,6 +787,7 @@ void keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods) void resizeCB(GLFWwindow* window, int width, int height); void scrollCB(GLFWwindow* window, double xoffset, double yoffset); void cursorCB(GLFWwindow* window, double xpos, double ypos); +void cursorEnterCB(GLFWwindow* window, int entered); void joysChangeCB(int jid, int event); bool IsThisJoystickBlacklisted(int i) @@ -821,9 +823,10 @@ void _InputInitialiseJoys() } } -void _InputInitialiseMouse() +long _InputInitialiseMouse() { glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + return 0; } void psPostRWinit(void) @@ -835,6 +838,7 @@ void psPostRWinit(void) glfwSetWindowSizeCallback(PSGLOBAL(window), resizeCB); glfwSetScrollCallback(PSGLOBAL(window), scrollCB); glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB); + glfwSetCursorEnterCallback(PSGLOBAL(window), cursorEnterCB); glfwSetJoystickCallback(joysChangeCB); _InputInitialiseJoys(); @@ -1340,13 +1344,18 @@ _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) { RsKeyboardEventHandler(rshiftStatus ? rsKEYDOWN : rsKEYUP, &(*rs = rsRSHIFT)); } -// TODO this only works in frontend(and luckily only frontend use this), maybe because of glfw knows that mouse pos is > 32000 in game?? +// TODO this only works in frontend(and luckily only frontend use this). Fun fact: if I get pos manually in game, glfw reports that it's > 32000 void cursorCB(GLFWwindow* window, double xpos, double ypos) { FrontEndMenuManager.m_nMouseTempPosX = xpos; FrontEndMenuManager.m_nMouseTempPosY = ypos; } +void +cursorEnterCB(GLFWwindow* window, int entered) { + PSGLOBAL(cursorIsInWindow) = !!entered; +} + /* ***************************************************************************** */ diff --git a/src/skel/platform.h b/src/skel/platform.h index cbb1be28..0f314b9d 100644 --- a/src/skel/platform.h +++ b/src/skel/platform.h @@ -1,6 +1,8 @@ #ifndef PLATFORM_H #define PLATFORM_H +// Functions that's different on glfw/win etc. but have same signature (but if a function only used in win.cpp you can keep in win.h) + #include "rwcore.h" #include "skeleton.h" @@ -35,6 +37,8 @@ extern RwBool psInstallFileSystem(void); extern RwBool psNativeTextureSupport(void); extern void _InputTranslateShiftKeyUpDown(RsKeyCodes* rs); +extern long _InputInitialiseMouse(); // returns HRESULT on Windows actually +extern void _InputInitialiseJoys(); extern void HandleExit(); diff --git a/src/skel/win/win.h b/src/skel/win/win.h index d19c4e0e..4b2001f8 100644 --- a/src/skel/win/win.h +++ b/src/skel/win/win.h @@ -1,5 +1,5 @@ -// DON'T include directly. crossplatform.h includes this if you're on Windows. +// DON'T include directly. crossplatform.h includes this if you're using D3D9 backend(win.cpp). #if (!defined(_PLATFORM_WIN_H)) #define _PLATFORM_WIN_H @@ -8,25 +8,6 @@ #define RSREGSETBREAKALLOC(_name) /* No op */ #endif /* (!defined(RSREGSETBREAKALLOC)) */ -#ifndef _INC_WINDOWS - #ifdef _WIN64 - #define _AMD64_ - #else - #define _X86_ - #endif - #include -#endif - -enum eWinVersion -{ - OS_WIN95 = 0, - OS_WIN98, - OS_WINNT, - OS_WIN2000, - OS_WINXP, -}; - - #ifdef __DINPUT_INCLUDED__ /* platform specfic global data */ typedef struct @@ -87,14 +68,12 @@ extern "C" { #endif /* __cplusplus */ -#ifdef __DINPUT_INCLUDED__ extern LRESULT CALLBACK MainWndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam); +#ifdef __DINPUT_INCLUDED__ HRESULT _InputInitialise(); -HRESULT _InputInitialiseMouse(); HRESULT CapturePad(RwInt32 padID); -void _InputInitialiseJoys(); void _InputAddJoyStick(LPDIRECTINPUTDEVICE8 lpDevice, INT num); HRESULT _InputAddJoys(); HRESULT _InputGetMouseState(DIMOUSESTATE2 *state); -- cgit v1.2.3 From 199d57b16c80e51ace23e1640a1c92c3ebca0314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sat, 25 Jul 2020 15:13:27 +0300 Subject: Fix/change some Windows define --- src/skel/crossplatform.h | 10 +++------ src/skel/win/win.cpp | 56 ++++++++++++++++++++++++------------------------ src/skel/win/win.h | 3 --- 3 files changed, 31 insertions(+), 38 deletions(-) (limited to 'src/skel') diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index 066570be..268eedff 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -14,14 +14,10 @@ enum eWinVersion #ifdef _WIN32 -// As long as WITHWINDOWS isn't defined / isn't included, include , which is lighter. +// As long as WITHWINDOWS isn't defined / isn't included, we only need type definitions so let's include . +// NOTE: It's perfectly fine to include here, but it can increase build size and time in *some* conditions, and maybe substantially in future if we'll use crossplatform.h more. #ifndef _INC_WINDOWS - #ifdef _WIN64 - #define _ARM64_ - #else - #define _X86_ - #endif - #include + #include #endif #if defined RW_D3D9 || defined RWLIBS #include "win.h" diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index 9fde9d32..5c5c7ece 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -309,34 +309,6 @@ psNativeTextureSupport(void) return RwD3D8DeviceSupportsDXTTexture(); } -/* - ***************************************************************************** - */ -static BOOL -InitApplication(HANDLE instance) -{ - /* - * Perform any necessary MS Windows application initialization. Basically, - * this means registering the window class for this application. - */ - - WNDCLASS windowClass; - - windowClass.style = CS_BYTEALIGNWINDOW; - windowClass.lpfnWndProc = (WNDPROC) MainWndProc; - windowClass.cbClsExtra = 0; - windowClass.cbWndExtra = 0; - windowClass.hInstance = (HINSTANCE)instance; - windowClass.hIcon = nil; - windowClass.hCursor = LoadCursor(nil, IDC_ARROW); - windowClass.hbrBackground = nil; - windowClass.lpszMenuName = NULL; - windowClass.lpszClassName = AppClassName; - - return RegisterClass(&windowClass); -} - - /* ***************************************************************************** */ @@ -1292,6 +1264,34 @@ MainWndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam) } +/* + ***************************************************************************** + */ +static BOOL +InitApplication(HANDLE instance) +{ + /* + * Perform any necessary MS Windows application initialization. Basically, + * this means registering the window class for this application. + */ + + WNDCLASS windowClass; + + windowClass.style = CS_BYTEALIGNWINDOW; + windowClass.lpfnWndProc = (WNDPROC)MainWndProc; + windowClass.cbClsExtra = 0; + windowClass.cbWndExtra = 0; + windowClass.hInstance = (HINSTANCE)instance; + windowClass.hIcon = nil; + windowClass.hCursor = LoadCursor(nil, IDC_ARROW); + windowClass.hbrBackground = nil; + windowClass.lpszMenuName = NULL; + windowClass.lpszClassName = AppClassName; + + return RegisterClass(&windowClass); +} + + /* ***************************************************************************** */ diff --git a/src/skel/win/win.h b/src/skel/win/win.h index 4b2001f8..be840898 100644 --- a/src/skel/win/win.h +++ b/src/skel/win/win.h @@ -68,9 +68,6 @@ extern "C" { #endif /* __cplusplus */ -extern LRESULT CALLBACK -MainWndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam); - #ifdef __DINPUT_INCLUDED__ HRESULT _InputInitialise(); HRESULT CapturePad(RwInt32 padID); -- cgit v1.2.3 From eb8844fd113d3fdae0456d56bdb0eb56e3a5f26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sun, 26 Jul 2020 20:59:58 +0300 Subject: Fix casepath chaos --- src/skel/crossplatform.cpp | 129 ++++++++++++++++++++++++++++----------------- src/skel/crossplatform.h | 6 ++- 2 files changed, 84 insertions(+), 51 deletions(-) (limited to 'src/skel') diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp index 40f4f053..6188992d 100644 --- a/src/skel/crossplatform.cpp +++ b/src/skel/crossplatform.cpp @@ -87,7 +87,7 @@ void FileTimeToSystemTime(time_t* writeTime, SYSTEMTIME* out) { // Funcs/features from Windows that we need on other platforms #ifndef _WIN32 char *strupr(char *s) { - char* tmp = s; + char* tmp = s; for (;*tmp;++tmp) { *tmp = toupper((unsigned char) *tmp); @@ -96,7 +96,7 @@ char *strupr(char *s) { return s; } char *strlwr(char *s) { - char* tmp = s; + char* tmp = s; for (;*tmp;++tmp) { *tmp = tolower((unsigned char) *tmp); @@ -116,86 +116,117 @@ char *trim(char *s) { return s; } +FILE* _fcaseopen(char const* filename, char const* mode) +{ + FILE* result; + char* real = casepath(filename); + if (!real) + result = fopen(filename, mode); + else { + result = fopen(real, mode); + free(real); + } + return result; +} + // Case-insensitivity on linux (from https://github.com/OneSadCookie/fcaseopen) -// r must have strlen(path) + 2 bytes -int casepath(char const *path, char *r) +// Returned string should freed manually (if exists) +char* casepath(char const* path, bool checkPathFirst) { + if (checkPathFirst && access(path, F_OK) != -1) { + // File path is correct + return nil; + } + size_t l = strlen(path); - char *p = (char*)alloca(l + 1); + char* p = (char*)alloca(l + 1); + char* out = (char*)malloc(l + 3); // for extra ./ strcpy(p, path); - // my addon: change \'s with / - char *nextBs; - while(nextBs = strstr(p, "\\")){ - *nextBs = '/'; - } - - // my addon: linux doesn't handle filenames with spaces at the end nicely - p = trim(p); + // my addon: linux doesn't handle filenames with spaces at the end nicely + p = trim(p); size_t rl = 0; - - DIR *d; - if (p[0] == '/') + + DIR* d; + if (p[0] == '/' || p[0] == '\\') { d = opendir("/"); - p = p + 1; } else { d = opendir("."); - r[0] = '.'; - r[1] = 0; + out[0] = '.'; + out[1] = 0; rl = 1; } - - int last = 0; - char *c = strsep(&p, "/"); - while (c) + + bool cantProceed = false; // just convert slashes in what's left in string, not case sensitivity + bool mayBeTrailingSlash = false; + char* c; + while (c = strsep(&p, "/\\")) { - if (!d) + // May be trailing slash(allow), slash at the start(avoid), or multiple slashes(avoid) + if (*c == '\0') { - return 0; + mayBeTrailingSlash = true; + continue; + } else { + mayBeTrailingSlash = false; } - - if (last) + + out[rl] = '/'; + rl += 1; + out[rl] = 0; + + if (cantProceed) { - closedir(d); - return 0; + strcpy(out + rl, c); + rl += strlen(c); + continue; } - - r[rl] = '/'; - rl += 1; - r[rl] = 0; - - struct dirent *e = readdir(d); - while (e) + + struct dirent* e; + while (e = readdir(d)) { if (strcasecmp(c, e->d_name) == 0) { - strcpy(r + rl, e->d_name); - rl += strlen(e->d_name); + strcpy(out + rl, e->d_name); + int reportedLen = (int)strlen(e->d_name); + rl += reportedLen; + assert(reportedLen == strlen(c) && "casepath: This is not good at all"); closedir(d); - d = opendir(r); - + d = opendir(out); + + // Either it wasn't a folder, or permission error, I/O error etc. + if (!d) { + cantProceed = true; + } + break; } - - e = readdir(d); } - + if (!e) { - strcpy(r + rl, c); + printf("casepath couldn't find dir/file \"%s\", full path was %s\n", c, path); + // No match, add original name and continue converting further slashes. + strcpy(out + rl, c); rl += strlen(c); - last = 1; + cantProceed = true; } - - c = strsep(&p, "/"); } - + if (d) closedir(d); - return 1; + if (mayBeTrailingSlash) { + out[rl] = '/'; rl += 1; + out[rl] = '\0'; + } + + if (rl > l + 2) { + printf("\n\ncasepath: Corrected path length is longer then original+2:\n\tOriginal: %s (%d chars)\n\tCorrected: %s (%d chars)\n\n", path, l, out, rl); + } + return out; } #endif diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index 268eedff..69600385 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -23,7 +23,7 @@ enum eWinVersion #include "win.h" #endif extern DWORD _dwOperatingSystemVersion; - +#define fcaseopen fopen #else char *strupr(char *str); char *strlwr(char *str); @@ -43,7 +43,9 @@ enum { }; extern long _dwOperatingSystemVersion; -int casepath(char const *path, char *r); +char *casepath(char const *path, bool checkPathFirst = true); +FILE *_fcaseopen(char const *filename, char const *mode); +#define fcaseopen _fcaseopen #endif #ifdef RW_GL3 -- cgit v1.2.3