Skip to content

Commit 95d912c

Browse files
Get rid of the input_state global linkage.
1 parent fd0af5b commit 95d912c

File tree

8 files changed

+18
-23
lines changed

8 files changed

+18
-23
lines changed

Core/Core.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ static double lastActivity = 0.0;
5757
static double lastKeepAwake = 0.0;
5858
static GraphicsContext *graphicsContext;
5959

60-
extern InputState input_state;
61-
6260
void Core_SetGraphicsContext(GraphicsContext *ctx) {
6361
graphicsContext = ctx;
6462
}
@@ -152,30 +150,30 @@ bool UpdateScreenScale(int width, int height, bool smallWindow) {
152150
return false;
153151
}
154152

155-
void UpdateRunLoop() {
153+
void UpdateRunLoop(InputState *input_state) {
156154
if (windowHidden && g_Config.bPauseWhenMinimized) {
157155
sleep_ms(16);
158156
return;
159157
}
160-
NativeUpdate(input_state);
158+
NativeUpdate(*input_state);
161159

162160
{
163-
lock_guard guard(input_state.lock);
164-
EndInputState(&input_state);
161+
lock_guard guard(input_state->lock);
162+
EndInputState(input_state);
165163
}
166164

167165
if (GetUIState() != UISTATE_EXIT) {
168166
NativeRender(graphicsContext);
169167
}
170168
}
171169

172-
void Core_RunLoop(GraphicsContext *ctx) {
170+
void Core_RunLoop(GraphicsContext *ctx, InputState *input_state) {
173171
graphicsContext = ctx;
174172
while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) {
175173
time_update();
176174
#if defined(USING_WIN_UI)
177175
double startTime = time_now_d();
178-
UpdateRunLoop();
176+
UpdateRunLoop(input_state);
179177

180178
// Simple throttling to not burn the GPU in the menu.
181179
time_update();
@@ -187,13 +185,13 @@ void Core_RunLoop(GraphicsContext *ctx) {
187185
ctx->SwapBuffers();
188186
}
189187
#else
190-
UpdateRunLoop();
188+
UpdateRunLoop(input_state);
191189
#endif
192190
}
193191

194192
while (!coreState && GetUIState() == UISTATE_INGAME) {
195193
time_update();
196-
UpdateRunLoop();
194+
UpdateRunLoop(input_state);
197195
#if defined(USING_WIN_UI)
198196
if (!windowHidden && !Core_IsStepping()) {
199197
ctx->SwapBuffers();
@@ -234,7 +232,7 @@ static inline void CoreStateProcessed() {
234232
}
235233

236234
// Some platforms, like Android, do not call this function but handle things on their own.
237-
void Core_Run(GraphicsContext *ctx)
235+
void Core_Run(GraphicsContext *ctx, InputState *input_state)
238236
{
239237
#if defined(_DEBUG)
240238
host->UpdateDisassembly();
@@ -249,7 +247,7 @@ void Core_Run(GraphicsContext *ctx)
249247
if (GetUIState() == UISTATE_EXIT) {
250248
return;
251249
}
252-
Core_RunLoop(ctx);
250+
Core_RunLoop(ctx, input_state);
253251
#if defined(USING_QT_UI) && !defined(MOBILE_DEVICE)
254252
return;
255253
#else
@@ -261,7 +259,7 @@ void Core_Run(GraphicsContext *ctx)
261259
{
262260
case CORE_RUNNING:
263261
// enter a fast runloop
264-
Core_RunLoop(ctx);
262+
Core_RunLoop(ctx, input_state);
265263
break;
266264

267265
// We should never get here on Android.

Core/Core.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
#include "Core/CoreParameter.h"
2222

2323
class GraphicsContext;
24+
struct InputState;
2425

2526
// called from emu thread
26-
void UpdateRunLoop();
27-
void Core_Run(GraphicsContext *ctx);
27+
void UpdateRunLoop(GraphicsContext *input_state);
28+
void Core_Run(GraphicsContext *ctx, InputState *input_state);
2829
void Core_Stop();
2930
void Core_ErrorPause();
3031
// For platforms that don't call Core_Run

Windows/EmuThread.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ unsigned int WINAPI TheThread(void *)
192192
if (!Core_IsActive())
193193
UpdateUIState(UISTATE_MENU);
194194

195-
Core_Run(graphicsContext);
195+
Core_Run(graphicsContext, &input_state);
196196
}
197197

198198
shutdown:

ext/native/base/BlackberryMain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void BlackberryMain::runMain() {
348348
switchDisplay(screen_ui);
349349
}
350350
time_update();
351-
UpdateRunLoop();
351+
UpdateRunLoop(&input_state);
352352
// This handles VSync
353353
if (emulating)
354354
eglSwapBuffers(egl_disp[screen_emu], egl_surf[screen_emu]);

ext/native/base/PCMain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ int main(int argc, char *argv[]) {
859859
SimulateGamepad(keys, &input_state);
860860
input_state.pad_buttons = pad_buttons;
861861
UpdateInputState(&input_state, true);
862-
UpdateRunLoop();
862+
UpdateRunLoop(&input_state);
863863
if (g_QuitRequested)
864864
break;
865865
#if defined(PPSSPP) && !defined(MOBILE_DEVICE)

ext/native/base/QtMain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void MainUI::paintGL()
360360
updateAccelerometer();
361361
UpdateInputState(&input_state);
362362
time_update();
363-
UpdateRunLoop();
363+
UpdateRunLoop(&input_state);
364364
}
365365

366366
void MainUI::updateAccelerometer()

headless/Headless.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &default
8282
void System_AskForPermission(SystemPermission permission) {}
8383
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
8484

85-
InputState input_state;
86-
8785
int printUsage(const char *progname, const char *reason)
8886
{
8987
if (reason != NULL)

unittest/UnitTest.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
#include "unittest/TestVertexJit.h"
4949
#include "unittest/UnitTest.h"
5050

51-
InputState input_state;
52-
5351
std::string System_GetProperty(SystemProperty prop) { return ""; }
5452
int System_GetPropertyInt(SystemProperty prop) { return -1; }
5553
void NativeMessageReceived(const char *message, const char *value) {}

0 commit comments

Comments
 (0)