src/feature/gui/gui-runner.h (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef GUI_RUNNER_H
7#define GUI_RUNNER_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/config.h>
14#include "feature/gui/remap.h"
15#include <mgba/internal/gba/hardware.h>
16#include <mgba-util/circle-buffer.h>
17#include <mgba-util/gui.h>
18#include <mgba-util/threading.h>
19
20enum mGUIInput {
21 mGUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START,
22 mGUI_INPUT_DECREASE_BRIGHTNESS,
23 mGUI_INPUT_SCREEN_MODE,
24 mGUI_INPUT_SCREENSHOT,
25 mGUI_INPUT_FAST_FORWARD_HELD,
26 mGUI_INPUT_FAST_FORWARD_TOGGLE
27};
28
29struct mGUIBackground {
30 struct GUIBackground d;
31 struct mGUIRunner* p;
32
33 color_t* screenshot;
34 int screenshotId;
35};
36
37struct mCore;
38struct mGUIRunnerLux {
39 struct GBALuminanceSource d;
40 int luxLevel;
41};
42
43#ifndef DISABLE_THREADING
44struct VFile;
45struct mGUIAutosaveContext {
46 struct VFile* buffer;
47 struct mCore* core;
48 Thread thread;
49 Mutex mutex;
50 Condition cond;
51 bool running;
52};
53#endif
54
55struct mGUIRunner {
56 struct mCore* core;
57 struct GUIParams params;
58
59 struct mGUIBackground background;
60 struct mGUIRunnerLux luminanceSource;
61#ifndef DISABLE_THREADING
62 struct mGUIAutosaveContext autosave;
63#endif
64
65 struct mInputMap guiKeys;
66 struct mCoreConfig config;
67 struct GUIMenuItem* configExtra;
68 size_t nConfigExtra;
69
70 struct GUIInputKeys* keySources;
71
72 const char* port;
73 float fps;
74 int64_t lastFpsCheck;
75 int32_t totalDelta;
76 struct CircleBuffer fpsBuffer;
77
78 void (*setup)(struct mGUIRunner*);
79 void (*teardown)(struct mGUIRunner*);
80 void (*gameLoaded)(struct mGUIRunner*);
81 void (*gameUnloaded)(struct mGUIRunner*);
82 void (*prepareForFrame)(struct mGUIRunner*);
83 void (*drawFrame)(struct mGUIRunner*, bool faded);
84 void (*drawScreenshot)(struct mGUIRunner*, const color_t* pixels, unsigned width, unsigned height, bool faded);
85 void (*paused)(struct mGUIRunner*);
86 void (*unpaused)(struct mGUIRunner*);
87 void (*incrementScreenMode)(struct mGUIRunner*);
88 void (*setFrameLimiter)(struct mGUIRunner*, bool limit);
89 uint16_t (*pollGameInput)(struct mGUIRunner*);
90 bool (*running)(struct mGUIRunner*);
91};
92
93void mGUIInit(struct mGUIRunner*, const char* port);
94void mGUIDeinit(struct mGUIRunner*);
95void mGUIRun(struct mGUIRunner*, const char* path);
96void mGUIRunloop(struct mGUIRunner*);
97
98#ifndef DISABLE_THREADING
99THREAD_ENTRY mGUIAutosaveThread(void* context);
100#endif
101
102CXX_GUARD_END
103
104#endif