summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ControllerConfig.cpp98
-rw-r--r--src/core/ControllerConfig.h17
-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.h4
-rw-r--r--src/core/config.h2
-rw-r--r--src/core/patcher.cpp3
8 files changed, 187 insertions, 21 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..76f9882b 100644
--- a/src/core/ControllerConfig.h
+++ b/src/core/ControllerConfig.h
@@ -96,6 +96,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:
@@ -115,8 +125,9 @@ public:
#ifdef __DINPUT_INCLUDED__
DIJOYSTATE2 m_OldState;
DIJOYSTATE2 m_NewState;
-#else
- uint32 ___padd[0x110 / 4 * 2];
+#elif defined RW_GL3
+ GlfwJoyState m_OldState;
+ GlfwJoyState m_NewState;
#endif
wchar m_aActionNames[MAX_CONTROLLERACTIONS][ACTIONNAME_LENGTH];
bool m_aButtonStates[MAX_BUTTONS];
@@ -193,6 +204,6 @@ public:
void ResetSettingOrder (e_ControllerAction action);
};
-VALIDATE_SIZE(CControllerConfigManager, 0x143C);
+//VALIDATE_SIZE(CControllerConfigManager, 0x143C);
extern CControllerConfigManager ControlsManager; \ No newline at end of file
diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp
index c7e7d26e..cc076057 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;
@@ -4474,12 +4480,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 8a3fc7cb..84bb1526 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"
@@ -423,6 +425,7 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp()
{
CMouseControllerState state;
+#if defined RW_D3D9 || defined RWLIBS
if ( PSGLOBAL(mouse) == nil )
_InputInitialiseMouse();
@@ -432,7 +435,6 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp()
devCaps.dwSize = sizeof(DIDEVCAPS);
PSGLOBAL(mouse)->GetCapabilities(&devCaps);
-
switch ( devCaps.dwButtons )
{
case 3:
@@ -456,6 +458,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;
}
@@ -464,6 +479,7 @@ void CPad::UpdateMouse()
{
if ( IsForegroundApp() )
{
+#if defined RW_D3D9 || defined RWLIBS
if ( PSGLOBAL(mouse) == nil )
_InputInitialiseMouse();
@@ -500,6 +516,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..2cc3d98c 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
diff --git a/src/core/config.h b/src/core/config.h
index 84712af3..80e2ff19 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -200,7 +200,7 @@ enum Config {
//#define PS2_ALTERNATIVE_CARSPLASH // unused on PS2
// Pad
-#define XINPUT
+// #define XINPUT
#define KANGAROO_CHEAT
#define REGISTER_START_BUTTON
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)