summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFire_Head <Fire-Head@users.noreply.github.com>2020-04-23 10:50:06 +0200
committerGitHub <noreply@github.com>2020-04-23 10:50:06 +0200
commitff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2 (patch)
treed461c5aca74e9679ec87d1e3d70a5e674a57ee21 /src
parentfix #ifdef (diff)
parentMerge pull request #482 from withmorten/master (diff)
downloadre3-ff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2.tar
re3-ff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2.tar.gz
re3-ff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2.tar.bz2
re3-ff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2.tar.lz
re3-ff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2.tar.xz
re3-ff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2.tar.zst
re3-ff46dc1c6c5a9e8a42ba9f5ac5f1e7a5b7408cc2.zip
Diffstat (limited to 'src')
-rw-r--r--src/animation/CutsceneMgr.cpp3
-rw-r--r--src/control/Script.cpp1
-rw-r--r--src/core/CdStream.cpp2
-rw-r--r--src/core/Game.cpp2
-rw-r--r--src/core/Timer.cpp2
-rw-r--r--src/core/re3.cpp2
-rw-r--r--src/rw/TexRead.cpp3
-rw-r--r--src/save/GenericGameStorage.cpp3
-rw-r--r--src/save/PCSave.cpp9
-rw-r--r--src/skel/crossplatform.cpp81
-rw-r--r--src/skel/crossplatform.h65
-rw-r--r--src/skel/events.cpp6
-rw-r--r--src/skel/win/win.cpp4
-rw-r--r--src/skel/win/win.h11
14 files changed, 170 insertions, 24 deletions
diff --git a/src/animation/CutsceneMgr.cpp b/src/animation/CutsceneMgr.cpp
index 6d9b9755..334fe471 100644
--- a/src/animation/CutsceneMgr.cpp
+++ b/src/animation/CutsceneMgr.cpp
@@ -1,4 +1,3 @@
-#define WITHWINDOWS // just for VK_SPACE
#include "common.h"
#include "General.h"
@@ -416,7 +415,7 @@ CCutsceneMgr::Update(void)
|| (CGame::playingIntro && CPad::GetPad(0)->GetStartJustDown())
|| CPad::GetPad(0)->GetLeftMouseJustDown()
|| CPad::GetPad(0)->GetEnterJustDown()
- || CPad::GetPad(0)->GetCharJustDown(VK_SPACE))
+ || CPad::GetPad(0)->GetCharJustDown(' '))
FinishCutscene();
}
}
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index ca676f52..073cb661 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -1,7 +1,6 @@
#define WITHWINDOWS // for our script loading hack
#include "common.h"
-
#include "Script.h"
#include "ScriptCommands.h"
diff --git a/src/core/CdStream.cpp b/src/core/CdStream.cpp
index 1ab1c8b0..ea79fb9a 100644
--- a/src/core/CdStream.cpp
+++ b/src/core/CdStream.cpp
@@ -1,4 +1,4 @@
-#include <windows.h>
+#define WITHWINDOWS
#include "common.h"
#include "CdStream.h"
diff --git a/src/core/Game.cpp b/src/core/Game.cpp
index 6f3eee29..bfe6eee3 100644
--- a/src/core/Game.cpp
+++ b/src/core/Game.cpp
@@ -1,7 +1,5 @@
#pragma warning( push )
#pragma warning( disable : 4005)
-#define DIRECTINPUT_VERSION 0x0800
-#include <dinput.h>
#pragma warning( pop )
#include "common.h"
#include "win.h"
diff --git a/src/core/Timer.cpp b/src/core/Timer.cpp
index 8f8570d7..aca7c1dc 100644
--- a/src/core/Timer.cpp
+++ b/src/core/Timer.cpp
@@ -1,4 +1,4 @@
-#include <windows.h>
+#define WITHWINDOWS
#include "common.h"
#include "DMAudio.h"
diff --git a/src/core/re3.cpp b/src/core/re3.cpp
index 3c2bc31f..4cec5773 100644
--- a/src/core/re3.cpp
+++ b/src/core/re3.cpp
@@ -1,6 +1,6 @@
#include <direct.h>
#include <csignal>
-#include <windows.h>
+#define WITHWINDOWS
#include "common.h"
#include "patcher.h"
#include "Renderer.h"
diff --git a/src/rw/TexRead.cpp b/src/rw/TexRead.cpp
index 258d520d..d1ff3dc0 100644
--- a/src/rw/TexRead.cpp
+++ b/src/rw/TexRead.cpp
@@ -1,9 +1,6 @@
#pragma warning( push )
#pragma warning( disable : 4005)
-#define DIRECTINPUT_VERSION 0x0800
-#include <dinput.h>
#pragma warning( pop )
-#define WITHWINDOWS
#include "common.h"
#include "win.h"
diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp
index 5e483dc7..29f666df 100644
--- a/src/save/GenericGameStorage.cpp
+++ b/src/save/GenericGameStorage.cpp
@@ -1,5 +1,6 @@
-#define WITHWINDOWS
#include "common.h"
+#define USEALTERNATIVEWINFUNCS
+#include "crossplatform.h"
#include "main.h"
#include "AudioScriptObject.h"
diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp
index 46185850..6f1b1b45 100644
--- a/src/save/PCSave.cpp
+++ b/src/save/PCSave.cpp
@@ -1,5 +1,6 @@
-#define WITHWINDOWS
#include "common.h"
+#define USEALTERNATIVEWINFUNCS
+#include "crossplatform.h"
#include "FileMgr.h"
#include "GenericGameStorage.h"
@@ -94,7 +95,7 @@ C_PcSave::PopulateSlotInfo()
struct {
int size;
wchar FileName[24];
- _SYSTEMTIME SaveDateTime;
+ SYSTEMTIME SaveDateTime;
} header;
sprintf(savename, "%s%i%s", DefaultPCSaveFileName, i + 1, ".b");
int file = CFileMgr::OpenFile(savename, "rb");
@@ -110,8 +111,8 @@ C_PcSave::PopulateSlotInfo()
}
if (Slots[i + 1] == SLOT_OK) {
if (CheckDataNotCorrupt(i, savename)) {
- _SYSTEMTIME st;
- memcpy(&st, &header.SaveDateTime, sizeof(_SYSTEMTIME));
+ SYSTEMTIME st;
+ memcpy(&st, &header.SaveDateTime, sizeof(SYSTEMTIME));
const char *month;
switch (st.wMonth)
{
diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp
new file mode 100644
index 00000000..f9464bb6
--- /dev/null
+++ b/src/skel/crossplatform.cpp
@@ -0,0 +1,81 @@
+#include "common.h"
+#define USEALTERNATIVEWINFUNCS
+#include "crossplatform.h"
+
+// For internal use
+// wMilliseconds is not needed
+void tmToSystemTime(const tm *tm, SYSTEMTIME *out) {
+ out->wYear = tm->tm_year + 1900;
+ out->wMonth = tm->tm_mon + 1;
+ out->wDayOfWeek = tm->tm_wday;
+ out->wDay = tm->tm_mday;
+ out->wHour = tm->tm_hour;
+ out->wMinute = tm->tm_min;
+ out->wSecond = tm->tm_sec;
+}
+
+void GetLocalTime_CP(SYSTEMTIME *out) {
+ time_t timestamp = time(nil);
+ tm *localTm = localtime(&timestamp);
+ tmToSystemTime(localTm, out);
+}
+
+#if !defined _WIN32 || defined __MINGW32__
+HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) {
+ char newpathname[32];
+ strncpy(newpathname, pathname, 32);
+ char* path = strtok(newpathname, "\\*");
+ strncpy(firstfile->folder, path, sizeof(firstfile->folder));
+
+ // Both w/ extension and w/o extension is ok
+ if (strlen(path) + 2 != strlen(pathname))
+ strncpy(firstfile->extension, strtok(NULL, "\\*"), sizeof(firstfile->extension));
+ else
+ strncpy(firstfile->extension, "", sizeof(firstfile->extension));
+
+ HANDLE d;
+ if ((d = opendir(path)) == NULL || !FindNextFile(d, firstfile))
+ return NULL;
+
+ return d;
+}
+
+bool FindNextFile(HANDLE d, WIN32_FIND_DATA* finddata) {
+ dirent *file;
+ static struct stat fileStats;
+ static char path[PATH_MAX], relativepath[NAME_MAX + sizeof(finddata->folder) + 1];
+ int extensionLen = strlen(finddata->extension);
+ while ((file = readdir(d)) != NULL) {
+
+ // We only want "DT_REG"ular Files, but reportedly some FS and OSes gives DT_UNKNOWN as type.
+ if ((file->d_type == DT_UNKNOWN || file->d_type == DT_REG) &&
+ (extensionLen == 0 || strncmp(&file->d_name[strlen(file->d_name) - extensionLen], finddata->extension, extensionLen) == 0)) {
+
+ sprintf(relativepath, "%s/%s", finddata->folder, file->d_name);
+ realpath(relativepath, path);
+ stat(path, &fileStats);
+ strncpy(finddata->cFileName, file->d_name, sizeof(finddata->cFileName));
+ finddata->ftLastWriteTime = fileStats.st_mtime;
+ return true;
+ }
+ }
+ return false;
+}
+
+void GetDateFormat(int unused1, int unused2, SYSTEMTIME* in, int unused3, char* out, int size) {
+ tm linuxTime;
+ linuxTime.tm_year = in->wYear - 1900;
+ linuxTime.tm_mon = in->wMonth - 1;
+ linuxTime.tm_wday = in->wDayOfWeek;
+ linuxTime.tm_mday = in->wDay;
+ linuxTime.tm_hour = in->wHour;
+ linuxTime.tm_min = in->wMinute;
+ linuxTime.tm_sec = in->wSecond;
+ strftime(out, size, nl_langinfo(D_FMT), &linuxTime);
+}
+
+void FileTimeToSystemTime(time_t* writeTime, SYSTEMTIME* out) {
+ tm *ptm = gmtime(writeTime);
+ tmToSystemTime(ptm, out);
+}
+#endif \ No newline at end of file
diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h
new file mode 100644
index 00000000..1b3ad7d6
--- /dev/null
+++ b/src/skel/crossplatform.h
@@ -0,0 +1,65 @@
+#include <time.h>
+
+#ifndef MAX_PATH
+ #if !defined _WIN32 || defined __MINGW32__
+ #define MAX_PATH PATH_MAX
+ #else
+ #define MAX_PATH 260
+ #endif
+#endif
+
+// Mostly wrappers around Windows functions
+
+// TODO: Remove USEALTERNATIVEWINFUNCS and don't use it anywhere when re3 becomes fully cross-platform, this is for testing
+// Codes compatible with Windows and Linux
+#if defined USEALTERNATIVEWINFUNCS || !defined _WIN32 || defined __MINGW32__
+#define DeleteFile unlink
+
+// Needed for save games
+struct SYSTEMTIME {
+ uint16 wYear;
+ uint16 wMonth;
+ uint16 wDayOfWeek;
+ uint16 wDay;
+ uint16 wHour;
+ uint16 wMinute;
+ uint16 wSecond;
+ uint16 wMilliseconds;
+};
+
+#define GetLocalTime GetLocalTime_CP
+#else
+#include <Windows.h>
+#endif
+
+void GetLocalTime_CP(SYSTEMTIME* out);
+
+
+// Only runs on GNU/POSIX/etc.
+#if !defined _WIN32 || defined __MINGW32__
+#define OutputDebugString(s) re3_debug("[DBG-2]: " s "\n")
+
+#include <iostream>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <langinfo.h>
+
+typedef DIR* HANDLE;
+#define INVALID_HANDLE_VALUE NULL
+#define FindClose closedir
+#define LOCALE_USER_DEFAULT 0
+#define DATE_SHORTDATE 0
+
+struct WIN32_FIND_DATA {
+ char extension[32]; // for searching
+ char folder[32]; // for searching
+ char cFileName[256]; // because tSkinInfo has it 256
+ time_t ftLastWriteTime;
+};
+
+HANDLE FindFirstFile(char*, WIN32_FIND_DATA*);
+bool FindNextFile(HANDLE, WIN32_FIND_DATA*);
+void FileTimeToSystemTime(time_t*, SYSTEMTIME*);
+void GetDateFormat(int, int, SYSTEMTIME*, int, char*, int);
+#endif \ No newline at end of file
diff --git a/src/skel/events.cpp b/src/skel/events.cpp
index 5d16d5b0..7116833d 100644
--- a/src/skel/events.cpp
+++ b/src/skel/events.cpp
@@ -2,18 +2,12 @@
#include "skeleton.h"
#include "events.h"
-//#include "main.h"
- #define DIRECTINPUT_VERSION 0x0800
- #include <dinput.h>
#include "common.h"
#include "Pad.h"
#include "ControllerConfig.h"
#include "Frontend.h"
#include "Camera.h"
-
-
-
/*
*****************************************************************************
*/
diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp
index a534e903..d13d3c52 100644
--- a/src/skel/win/win.cpp
+++ b/src/skel/win/win.cpp
@@ -1986,7 +1986,7 @@ WinMain(HINSTANCE instance,
++gGameState;
else if ( CPad::GetPad(0)->GetEnterJustDown() )
++gGameState;
- else if ( CPad::GetPad(0)->GetCharJustDown(VK_SPACE) )
+ else if ( CPad::GetPad(0)->GetCharJustDown(' ') )
++gGameState;
else if ( CPad::GetPad(0)->GetAltJustDown() )
++gGameState;
@@ -2022,7 +2022,7 @@ WinMain(HINSTANCE instance,
++gGameState;
else if ( CPad::GetPad(0)->GetEnterJustDown() )
++gGameState;
- else if ( CPad::GetPad(0)->GetCharJustDown(VK_SPACE) )
+ else if ( CPad::GetPad(0)->GetCharJustDown(' ') )
++gGameState;
else if ( CPad::GetPad(0)->GetAltJustDown() )
++gGameState;
diff --git a/src/skel/win/win.h b/src/skel/win/win.h
index ca16c4a0..d6326294 100644
--- a/src/skel/win/win.h
+++ b/src/skel/win/win.h
@@ -5,6 +5,11 @@
#define RSREGSETBREAKALLOC(_name) /* No op */
#endif /* (!defined(RSREGSETBREAKALLOC)) */
+#ifndef _INC_WINDOWS
+#define _X86_
+#include <windef.h>
+#endif
+
enum eGameState
{
GS_START_UP = 0,
@@ -17,7 +22,9 @@ enum eGameState
GS_FRONTEND,
GS_INIT_PLAYING_GAME,
GS_PLAYING_GAME,
+#ifndef MASTER
GS_ANIMVIEWER,
+#endif
};
enum eWinVersion
@@ -33,6 +40,7 @@ extern DWORD _dwOperatingSystemVersion;
extern RwUInt32 gGameState;
+#ifdef __DINPUT_INCLUDED__
/* platform specfic global data */
typedef struct
{
@@ -86,6 +94,7 @@ public:
};
extern CJoySticks AllValidWinJoys;
+#endif
#ifdef __cplusplus
extern "C"
@@ -97,6 +106,7 @@ MainWndProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
RwBool IsForegroundApp();
+#ifdef __DINPUT_INCLUDED__
HRESULT _InputInitialise();
HRESULT _InputInitialiseMouse();
HRESULT CapturePad(RwInt32 padID);
@@ -110,6 +120,7 @@ BOOL _InputTranslateKey(RsKeyCodes *rs, UINT flag, UINT key);
void _InputTranslateShiftKeyUpDown(RsKeyCodes *rs);;
BOOL _InputTranslateShiftKey(RsKeyCodes *rs, UINT key, BOOLEAN bDown);
BOOL _InputIsExtended(INT flag);
+#endif
void InitialiseLanguage();
RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode);