Skip to content

Commit

Permalink
Get rid of the input_state global linkage.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed May 28, 2016
1 parent fd0af5b commit 95d912c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 23 deletions.
24 changes: 11 additions & 13 deletions Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ static double lastActivity = 0.0;
static double lastKeepAwake = 0.0;
static GraphicsContext *graphicsContext;

extern InputState input_state;

void Core_SetGraphicsContext(GraphicsContext *ctx) {
graphicsContext = ctx;
}
Expand Down Expand Up @@ -152,30 +150,30 @@ bool UpdateScreenScale(int width, int height, bool smallWindow) {
return false;
}

void UpdateRunLoop() {
void UpdateRunLoop(InputState *input_state) {
if (windowHidden && g_Config.bPauseWhenMinimized) {
sleep_ms(16);
return;
}
NativeUpdate(input_state);
NativeUpdate(*input_state);

{
lock_guard guard(input_state.lock);
EndInputState(&input_state);
lock_guard guard(input_state->lock);
EndInputState(input_state);
}

if (GetUIState() != UISTATE_EXIT) {
NativeRender(graphicsContext);
}
}

void Core_RunLoop(GraphicsContext *ctx) {
void Core_RunLoop(GraphicsContext *ctx, InputState *input_state) {
graphicsContext = ctx;
while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) {
time_update();
#if defined(USING_WIN_UI)
double startTime = time_now_d();
UpdateRunLoop();
UpdateRunLoop(input_state);

// Simple throttling to not burn the GPU in the menu.
time_update();
Expand All @@ -187,13 +185,13 @@ void Core_RunLoop(GraphicsContext *ctx) {
ctx->SwapBuffers();
}
#else
UpdateRunLoop();
UpdateRunLoop(input_state);
#endif
}

while (!coreState && GetUIState() == UISTATE_INGAME) {
time_update();
UpdateRunLoop();
UpdateRunLoop(input_state);
#if defined(USING_WIN_UI)
if (!windowHidden && !Core_IsStepping()) {
ctx->SwapBuffers();
Expand Down Expand Up @@ -234,7 +232,7 @@ static inline void CoreStateProcessed() {
}

// Some platforms, like Android, do not call this function but handle things on their own.
void Core_Run(GraphicsContext *ctx)
void Core_Run(GraphicsContext *ctx, InputState *input_state)
{
#if defined(_DEBUG)
host->UpdateDisassembly();
Expand All @@ -249,7 +247,7 @@ void Core_Run(GraphicsContext *ctx)
if (GetUIState() == UISTATE_EXIT) {
return;
}
Core_RunLoop(ctx);
Core_RunLoop(ctx, input_state);
#if defined(USING_QT_UI) && !defined(MOBILE_DEVICE)
return;
#else
Expand All @@ -261,7 +259,7 @@ void Core_Run(GraphicsContext *ctx)
{
case CORE_RUNNING:
// enter a fast runloop
Core_RunLoop(ctx);
Core_RunLoop(ctx, input_state);
break;

// We should never get here on Android.
Expand Down
5 changes: 3 additions & 2 deletions Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
#include "Core/CoreParameter.h"

class GraphicsContext;
struct InputState;

// called from emu thread
void UpdateRunLoop();
void Core_Run(GraphicsContext *ctx);
void UpdateRunLoop(GraphicsContext *input_state);
void Core_Run(GraphicsContext *ctx, InputState *input_state);
void Core_Stop();
void Core_ErrorPause();
// For platforms that don't call Core_Run
Expand Down
2 changes: 1 addition & 1 deletion Windows/EmuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ unsigned int WINAPI TheThread(void *)
if (!Core_IsActive())
UpdateUIState(UISTATE_MENU);

Core_Run(graphicsContext);
Core_Run(graphicsContext, &input_state);
}

shutdown:
Expand Down
2 changes: 1 addition & 1 deletion ext/native/base/BlackberryMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void BlackberryMain::runMain() {
switchDisplay(screen_ui);
}
time_update();
UpdateRunLoop();
UpdateRunLoop(&input_state);
// This handles VSync
if (emulating)
eglSwapBuffers(egl_disp[screen_emu], egl_surf[screen_emu]);
Expand Down
2 changes: 1 addition & 1 deletion ext/native/base/PCMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ int main(int argc, char *argv[]) {
SimulateGamepad(keys, &input_state);
input_state.pad_buttons = pad_buttons;
UpdateInputState(&input_state, true);
UpdateRunLoop();
UpdateRunLoop(&input_state);
if (g_QuitRequested)
break;
#if defined(PPSSPP) && !defined(MOBILE_DEVICE)
Expand Down
2 changes: 1 addition & 1 deletion ext/native/base/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void MainUI::paintGL()
updateAccelerometer();
UpdateInputState(&input_state);
time_update();
UpdateRunLoop();
UpdateRunLoop(&input_state);
}

void MainUI::updateAccelerometer()
Expand Down
2 changes: 0 additions & 2 deletions headless/Headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ bool System_InputBoxGetWString(const wchar_t *title, const std::wstring &default
void System_AskForPermission(SystemPermission permission) {}
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }

InputState input_state;

int printUsage(const char *progname, const char *reason)
{
if (reason != NULL)
Expand Down
2 changes: 0 additions & 2 deletions unittest/UnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
#include "unittest/TestVertexJit.h"
#include "unittest/UnitTest.h"

InputState input_state;

std::string System_GetProperty(SystemProperty prop) { return ""; }
int System_GetPropertyInt(SystemProperty prop) { return -1; }
void NativeMessageReceived(const char *message, const char *value) {}
Expand Down

0 comments on commit 95d912c

Please sign in to comment.