summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2020-04-26 23:55:22 +0200
committerNikolay Korolev <nickvnuk@gmail.com>2020-04-26 23:55:22 +0200
commita38a867cc5fe1677866b7a6b6c01c4dc5dc3387b (patch)
tree35f1795ea2a38d996e43dd5119e28e26a34f06d3 /src/core
parentpools compatibility (diff)
parentMerge pull request #489 from Nick007J/master (diff)
downloadre3-a38a867cc5fe1677866b7a6b6c01c4dc5dc3387b.tar
re3-a38a867cc5fe1677866b7a6b6c01c4dc5dc3387b.tar.gz
re3-a38a867cc5fe1677866b7a6b6c01c4dc5dc3387b.tar.bz2
re3-a38a867cc5fe1677866b7a6b6c01c4dc5dc3387b.tar.lz
re3-a38a867cc5fe1677866b7a6b6c01c4dc5dc3387b.tar.xz
re3-a38a867cc5fe1677866b7a6b6c01c4dc5dc3387b.tar.zst
re3-a38a867cc5fe1677866b7a6b6c01c4dc5dc3387b.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ControllerConfig.cpp98
-rw-r--r--src/core/ControllerConfig.h23
-rw-r--r--src/core/Frontend.cpp24
-rw-r--r--src/core/Game.cpp2
-rw-r--r--src/core/Pad.cpp58
-rw-r--r--src/core/common.h18
-rw-r--r--src/core/config.h2
-rw-r--r--src/core/patcher.cpp3
8 files changed, 201 insertions, 27 deletions
diff --git a/src/core/ControllerConfig.cpp b/src/core/ControllerConfig.cpp
index a2382c12..f55568be 100644
--- a/src/core/ControllerConfig.cpp
+++ b/src/core/ControllerConfig.cpp
@@ -1,7 +1,10 @@
+#if defined RW_D3D9 || defined RWLIBS
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
-#include "common.h"
+#endif
+#include "common.h"
+#include "crossplatform.h"
#include "ControllerConfig.h"
#include "Pad.h"
#include "FileMgr.h"
@@ -15,7 +18,6 @@
#include "World.h"
#include "ModelIndices.h"
#include "Camera.h"
-#include "win.h"
#include "GenericGameStorage.h"
CControllerConfigManager ControlsManager;
@@ -41,14 +43,72 @@ void CControllerConfigManager::MakeControllerActionsBlank()
}
}
+#ifdef RW_GL3
+int MapIdToButtonId(int mapId) {
+ switch (mapId) {
+ case GLFW_GAMEPAD_BUTTON_A: // Cross
+ return 2;
+ case GLFW_GAMEPAD_BUTTON_B: // Circle
+ return 1;
+ case GLFW_GAMEPAD_BUTTON_X: // Square
+ return 3;
+ case GLFW_GAMEPAD_BUTTON_Y: // Triangle
+ return 4;
+ case GLFW_GAMEPAD_BUTTON_LEFT_BUMPER:
+ return 7;
+ case GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER:
+ return 8;
+ case GLFW_GAMEPAD_BUTTON_BACK:
+ return 9;
+ case GLFW_GAMEPAD_BUTTON_START:
+ return 12;
+ case GLFW_GAMEPAD_BUTTON_LEFT_THUMB:
+ return 10;
+ case GLFW_GAMEPAD_BUTTON_RIGHT_THUMB:
+ return 11;
+ case GLFW_GAMEPAD_BUTTON_DPAD_UP:
+ return 13;
+ case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT:
+ return 14;
+ case GLFW_GAMEPAD_BUTTON_DPAD_DOWN:
+ return 15;
+ case GLFW_GAMEPAD_BUTTON_DPAD_LEFT:
+ return 16;
+ // GLFW sends those as axes, so I added them here manually.
+ case 15: // Left trigger
+ return 5;
+ case 16: // Right trigger
+ return 6;
+ default:
+ return 0;
+ }
+}
+#endif
+
int32 CControllerConfigManager::GetJoyButtonJustDown()
{
#ifdef __DINPUT_INCLUDED__
+#ifdef FIX_BUGS
+ for (int32 i = 0; i < MAX_BUTTONS; i++)
+#else
for (int32 i = 0; i < JOY_BUTTONS; i++)
+#endif
{
if (m_NewState.rgbButtons[i] & 0x80 && !(m_OldState.rgbButtons[i] & 0x80))
return i + 1;
}
+#elif defined RW_GL3
+ if (m_NewState.isGamepad) {
+ for (int32 i = 0; i < MAX_BUTTONS; i++) {
+ if (m_NewState.mappedButtons[i] && !(m_OldState.mappedButtons[i]))
+ return MapIdToButtonId(i);
+ }
+ } else {
+ for (int32 i = 0; i < Min(m_NewState.numButtons, MAX_BUTTONS); i++) {
+ if (m_NewState.buttons[i] && !(m_OldState.buttons[i]))
+ return i + 1;
+ }
+ }
#endif
return 0;
}
@@ -249,8 +309,13 @@ void CControllerConfigManager::InitDefaultControlConfigJoyPad(uint32 buttons)
if (buttons > 16)
btn = 16;
+ // Now we use SDL Game Controller DB
+#if defined RW_D3D9 || defined RWLIBS
if ( AllValidWinJoys.m_aJoys[JOYSTICK1].m_nVendorID == 0x3427
&& AllValidWinJoys.m_aJoys[JOYSTICK1].m_nProductID == 0x1190)
+#else
+ if (0)
+#endif
{
//GIC USB Joystick, PS2 Gamepad ?
@@ -445,8 +510,13 @@ void CControllerConfigManager::UpdateJoyInConfigMenus_ButtonDown(int32 button, i
break;
}
- if ( AllValidWinJoys.m_aJoys[JOYSTICK1].m_nVendorID == 0x3427
+ // Now we use SDL Game Controller DB
+#if defined RW_D3D9 || defined RWLIBS
+ if (AllValidWinJoys.m_aJoys[JOYSTICK1].m_nVendorID == 0x3427
&& AllValidWinJoys.m_aJoys[JOYSTICK1].m_nProductID == 0x1190)
+#else
+ if (0)
+#endif
{
//GIC USB Joystick, PS2 Gamepad ?
@@ -872,8 +942,13 @@ void CControllerConfigManager::UpdateJoyInConfigMenus_ButtonUp(int32 button, int
break;
}
- if ( AllValidWinJoys.m_aJoys[JOYSTICK1].m_nVendorID == 0x3427
+ // Now we use SDL Game Controller DB
+#if defined RW_D3D9 || defined RWLIBS
+ if (AllValidWinJoys.m_aJoys[JOYSTICK1].m_nVendorID == 0x3427
&& AllValidWinJoys.m_aJoys[JOYSTICK1].m_nProductID == 0x1190)
+#else
+ if (0)
+#endif
{
//GIC USB Joystick, PS2 Gamepad ?
@@ -1809,7 +1884,7 @@ wchar *CControllerConfigManager::GetControllerSettingTextKeyBoard(e_ControllerAc
static wchar ActionText[50];
static wchar NewStringWithNumber[30];
- for (int32 i = 0; i < ARRAYSIZE(ActionText); i++)
+ for (int32 i = 0; i < ARRAY_SIZE(ActionText); i++)
ActionText[i] = '\0';
if (GetControllerKeyAssociatedWithAction(action, type) != rsNULL)
@@ -2266,6 +2341,19 @@ void CControllerConfigManager::UpdateJoyButtonState(int32 padnumber)
else
m_aButtonStates[i] = false;
}
+#elif defined RW_GL3
+ if (m_NewState.isGamepad) {
+ for (int32 i = 0; i < MAX_BUTTONS; i++) {
+ if (i == GLFW_GAMEPAD_BUTTON_GUIDE)
+ continue;
+
+ m_aButtonStates[MapIdToButtonId(i)-1] = m_NewState.mappedButtons[i];
+ }
+ } else {
+ for (int32 i = 0; i < Min(m_NewState.numButtons, MAX_BUTTONS); i++) {
+ m_aButtonStates[i] = m_NewState.buttons[i];
+ }
+ }
#endif
}
diff --git a/src/core/ControllerConfig.h b/src/core/ControllerConfig.h
index 82174343..7d0e1073 100644
--- a/src/core/ControllerConfig.h
+++ b/src/core/ControllerConfig.h
@@ -1,5 +1,9 @@
#pragma once
+#if defined RW_D3D9 || defined RWLIBS
+#define DIRECTINPUT_VERSION 0x0800
+#include <dinput.h>
+#endif
// based on x-gtasa
@@ -96,6 +100,16 @@ class CControllerState;
#define ACTIONNAME_LENGTH 40
+#ifdef RW_GL3
+struct GlfwJoyState {
+ int8 id;
+ bool isGamepad;
+ uint8 numButtons;
+ uint8* buttons;
+ bool mappedButtons[17];
+};
+#endif
+
class CControllerConfigManager
{
public:
@@ -112,11 +126,12 @@ public:
};
bool m_bFirstCapture;
-#ifdef __DINPUT_INCLUDED__
+#if defined RW_GL3
+ GlfwJoyState m_OldState;
+ GlfwJoyState m_NewState;
+#else
DIJOYSTATE2 m_OldState;
DIJOYSTATE2 m_NewState;
-#else
- uint32 ___padd[0x110 / 4 * 2];
#endif
wchar m_aActionNames[MAX_CONTROLLERACTIONS][ACTIONNAME_LENGTH];
bool m_aButtonStates[MAX_BUTTONS];
@@ -193,6 +208,8 @@ public:
void ResetSettingOrder (e_ControllerAction action);
};
+#ifndef RW_GL3
VALIDATE_SIZE(CControllerConfigManager, 0x143C);
+#endif
extern CControllerConfigManager ControlsManager; \ No newline at end of file
diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp
index 81560b76..b0766cff 100644
--- a/src/core/Frontend.cpp
+++ b/src/core/Frontend.cpp
@@ -1,8 +1,11 @@
+#if defined RW_D3D9 || defined RWLIBS
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
-#include "common.h"
+#endif
-#include "win.h"
+#define WITHWINDOWS
+#include "common.h"
+#include "crossplatform.h"
#include "Frontend.h"
#include "Font.h"
#include "Pad.h"
@@ -430,13 +433,16 @@ CMenuManager::BuildStatLine(char *text, void *stat, bool itsFloat, void *stat2)
void
CMenuManager::CentreMousePointer()
{
- tagPOINT Point;
-
if (SCREEN_WIDTH * 0.5f != 0.0f && 0.0f != SCREEN_HEIGHT * 0.5f) {
+#if defined RW_D3D9 || defined RWLIBS
+ tagPOINT Point;
Point.x = SCREEN_WIDTH / 2;
Point.y = SCREEN_HEIGHT / 2;
ClientToScreen(PSGLOBAL(window), &Point);
SetCursorPos(Point.x, Point.y);
+#elif defined RW_GL3
+ glfwSetCursorPos(PSGLOBAL(window), SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
+#endif
PSGLOBAL(lastMousePos.x) = SCREEN_WIDTH / 2;
PSGLOBAL(lastMousePos.y) = SCREEN_HEIGHT / 2;
@@ -4495,12 +4501,20 @@ CMenuManager::ProcessButtonPresses(void)
ControlsManager.MakeControllerActionsBlank();
ControlsManager.InitDefaultControlConfiguration();
ControlsManager.InitDefaultControlConfigMouse(MousePointerStateHelper.GetMouseSetUp());
- if (AllValidWinJoys.m_aJoys[0].m_bInitialised) {
+#if !defined RW_GL3
+ if (AllValidWinJoys.m_aJoys[JOYSTICK1].m_bInitialised) {
DIDEVCAPS devCaps;
devCaps.dwSize = sizeof(DIDEVCAPS);
PSGLOBAL(joy1)->GetCapabilities(&devCaps);
ControlsManager.InitDefaultControlConfigJoyPad(devCaps.dwButtons);
}
+#else
+ if (PSGLOBAL(joy1id) != -1 && glfwJoystickPresent(PSGLOBAL(joy1id))) {
+ int count;
+ glfwGetJoystickButtons(PSGLOBAL(joy1id), &count);
+ ControlsManager.InitDefaultControlConfigJoyPad(count);
+ }
+#endif
m_ControlMethod = CONTROL_STANDARD;
MousePointerStateHelper.bInvertVertically = false;
TheCamera.m_fMouseAccelHorzntl = 0.0025f;
diff --git a/src/core/Game.cpp b/src/core/Game.cpp
index f72d342f..8633d222 100644
--- a/src/core/Game.cpp
+++ b/src/core/Game.cpp
@@ -2,7 +2,7 @@
#pragma warning( disable : 4005)
#pragma warning( pop )
#include "common.h"
-#include "win.h"
+#include "crossplatform.h"
#include "Game.h"
#include "main.h"
diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp
index 44b22d6d..0a626570 100644
--- a/src/core/Pad.cpp
+++ b/src/core/Pad.cpp
@@ -1,10 +1,13 @@
#pragma warning( push )
#pragma warning( disable : 4005)
+#if defined RW_D3D9 || defined RWLIBS
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
+#endif
#pragma warning( pop )
#include "common.h"
+#include "crossplatform.h"
#ifdef XINPUT
#include <xinput.h>
#pragma comment( lib, "Xinput9_1_0.lib" )
@@ -29,7 +32,6 @@
#include "Record.h"
#include "Replay.h"
#include "Weather.h"
-#include "win.h"
#include "Streaming.h"
#include "PathFind.h"
#include "Wanted.h"
@@ -455,6 +457,7 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp()
{
CMouseControllerState state;
+#if defined RW_D3D9 || defined RWLIBS
if ( PSGLOBAL(mouse) == nil )
_InputInitialiseMouse();
@@ -464,7 +467,6 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp()
devCaps.dwSize = sizeof(DIDEVCAPS);
PSGLOBAL(mouse)->GetCapabilities(&devCaps);
-
switch ( devCaps.dwButtons )
{
case 3:
@@ -488,6 +490,19 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp()
state.WHEELUP = true;
}
}
+#else
+ // It seems there is no way to get number of buttons on mouse, so assign all buttons if we have mouse.
+ double xpos = 1.0f, ypos;
+ glfwGetCursorPos(PSGLOBAL(window), &xpos, &ypos);
+
+ if (xpos != NULL) {
+ state.MMB = true;
+ state.RMB = true;
+ state.LMB = true;
+ state.WHEELDN = true;
+ state.WHEELUP = true;
+ }
+#endif
return state;
}
@@ -496,6 +511,7 @@ void CPad::UpdateMouse()
{
if ( IsForegroundApp() )
{
+#if defined RW_D3D9 || defined RWLIBS
if ( PSGLOBAL(mouse) == nil )
_InputInitialiseMouse();
@@ -532,6 +548,44 @@ void CPad::UpdateMouse()
OldMouseControllerState = NewMouseControllerState;
NewMouseControllerState = PCTempMouseControllerState;
}
+#else
+ double xpos = 1.0f, ypos;
+ glfwGetCursorPos(PSGLOBAL(window), &xpos, &ypos);
+ if (xpos == NULL)
+ return;
+
+ int32 signX = 1;
+ int32 signy = 1;
+
+ if (!FrontEndMenuManager.m_bMenuActive)
+ {
+ if (MousePointerStateHelper.bInvertVertically)
+ signy = -1;
+ if (MousePointerStateHelper.bInvertHorizontally)
+ signX = -1;
+ }
+
+ PCTempMouseControllerState.Clear();
+
+ PCTempMouseControllerState.x = (float)(signX * (xpos - PSGLOBAL(lastMousePos.x)));
+ PCTempMouseControllerState.y = (float)(signy * (ypos - PSGLOBAL(lastMousePos.y)));
+ PCTempMouseControllerState.LMB = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_LEFT);
+ PCTempMouseControllerState.RMB = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_RIGHT);
+ PCTempMouseControllerState.MMB = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_MIDDLE);
+ PCTempMouseControllerState.MXB1 = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_4);
+ PCTempMouseControllerState.MXB2 = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_5);
+
+ PSGLOBAL(lastMousePos.x) = xpos;
+ PSGLOBAL(lastMousePos.y) = ypos;
+
+ if (PSGLOBAL(mouseWheel) > 0)
+ PCTempMouseControllerState.WHEELUP = 1;
+ else if (PSGLOBAL(mouseWheel) < 0)
+ PCTempMouseControllerState.WHEELDN = 1;
+
+ OldMouseControllerState = NewMouseControllerState;
+ NewMouseControllerState = PCTempMouseControllerState;
+#endif
}
}
diff --git a/src/core/common.h b/src/core/common.h
index 8b057efa..18f4715c 100644
--- a/src/core/common.h
+++ b/src/core/common.h
@@ -11,11 +11,11 @@
#include <string.h>
#include <math.h>
-#ifdef WITHWINDOWS
+#if defined _WIN32 && defined WITHWINDOWS
#include <windows.h>
#endif
-#ifdef WITHD3D
+#if defined _WIN32 && defined WITHD3D
#include <windows.h>
#include <d3d8types.h>
#endif
@@ -31,6 +31,7 @@
#define HIERNODEID(hier, i) ((hier)->nodeInfo[i].id)
#define HANIMFRAMES(anim) ((anim)->keyframes)
#else
+#define RWHALFPIXEL // always d3d
#define STREAMPOS(str) ((str)->Type.memory.position)
#define STREAMFILE(str) ((str)->Type.file.fpFile)
#define HIERNODEINFO(hier) ((hier)->pNodeInfo)
@@ -38,6 +39,12 @@
#define HANIMFRAMES(anim) ((anim)->pFrames)
#endif
+#ifdef RWHALFPIXEL
+#define HALFPX (0.5f)
+#else
+#define HALFPX (0.0f)
+#endif
+
#define rwVENDORID_ROCKSTAR 0x0253F2
// Get rid of bullshit windows definitions, we're not running on an 8086
@@ -88,13 +95,6 @@ inline uint32 ldb(uint32 p, uint32 s, uint32 w)
return w>>p & (1<<s)-1;
}
-
-#ifndef RWLIBS
-// little hack
-extern void **rwengine;
-#define RwEngineInstance (*rwengine)
-#endif
-
#include "skeleton.h"
#include "Draw.h"
diff --git a/src/core/config.h b/src/core/config.h
index f1999c71..11d443ea 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -200,7 +200,9 @@ enum Config {
//#define PS2_ALTERNATIVE_CARSPLASH // unused on PS2
// Pad
+#ifndef RW_GL3
#define XINPUT
+#endif
#define KANGAROO_CHEAT
#define ALLCARSHELI_CHEAT
#define ALT_DODO_CHEAT
diff --git a/src/core/patcher.cpp b/src/core/patcher.cpp
index 58f19767..e5242e9d 100644
--- a/src/core/patcher.cpp
+++ b/src/core/patcher.cpp
@@ -1,11 +1,10 @@
+#define WITHWINDOWS
#include "common.h"
#include "patcher.h"
#include <algorithm>
#include <vector>
-#include <windows.h>
-
StaticPatcher *StaticPatcher::ms_head;
StaticPatcher::StaticPatcher(Patcher func)