ScummVM API documentation
libretro-os.h
1 /* Copyright (C) 2023 Giovanni Cascione <ing.cascione@gmail.com>
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 #ifndef BACKENDS_LIBRETRO_OS_H
18 #define BACKENDS_LIBRETRO_OS_H
19 
20 #include "audio/mixer_intern.h"
21 #include "base/main.h"
22 //#include "backends/base-backend.h"
23 #include "common/system.h"
24 #include "common/mutex.h"
25 #include "common/list.h"
26 #include "common/events.h"
27 #include "backends/modular-backend.h"
28 #include "graphics/managed_surface.h"
29 
30 #define BASE_CURSOR_SPEED 4
31 #define CURSOR_STATUS_DOING_JOYSTICK (1 << 0)
32 #define CURSOR_STATUS_DOING_MOUSE (1 << 1)
33 #define CURSOR_STATUS_DOING_X (1 << 2)
34 #define CURSOR_STATUS_DOING_Y (1 << 3)
35 #define CURSOR_STATUS_DOING_SLOWER (1 << 4)
36 
37 #define LIBRETRO_G_SYSTEM dynamic_cast<OSystem_libretro *>(g_system)
38 
43 public:
45  ~LibretroMutexInternal() override {};
46  bool lock() override {
47  return 0;
48  }
49  bool unlock() override {
50  return 0;
51  };
52 };
53 
55 private:
56  int _relMouseX;
57  int _relMouseY;
58  float _mouseXAcc;
59  float _mouseYAcc;
60  float _dpadXAcc;
61  float _dpadYAcc;
62  float _dpadXVel;
63  float _dpadYVel;
64  float _adjusted_cursor_speed;
65  float _inverse_acceleration_time;
66  uint32 _startTime;
67  uint8 _cursorStatus;
68  Common::String s_systemDir;
69  Common::String s_saveDir;
70  Common::String s_playlistDir;
72 
73 public:
74  Audio::MixerImpl *_mixer;
75  bool _mouseButtons[2];
76  bool _ptrmouseButton;
77  int _mouseX;
78  int _mouseY;
79 
80  /* Base */
81  OSystem_libretro(void);
82  ~OSystem_libretro(void) override;
83  void initBackend(void) override;
84  void engineInit(void) override;
85  void refreshRetroSettings(void);
86  void refreshScreen(void);
87  void destroy(void);
88  void quit() override {}
89  void resetGraphicsManager(void);
90  void getScreen(const Graphics::ManagedSurface *&screen);
91  int16 getScreenWidth(void);
92  int16 getScreenHeight(void);
93  bool inLauncher(void);
94 
95 #ifdef USE_OPENGL
96  void resetGraphicsContext(void);
97 #ifdef USE_GLAD
98  void *getOpenGLProcAddress(const char *name) const override;
99 #endif
100 #endif
101 
102  /* Events */
103 public:
104  bool pollEvent(Common::Event &event) override;
105  uint32 getMillis(bool skipRecord = false) override;
106  void delayMillis(uint msecs) override;
107  Common::MutexInternal *createMutex(void) override;
108  void requestQuit(void);
109  void resetQuit(void);
110  void setMousePosition(int x, int y);
111 
112  /* Utils */
113  void getTimeAndDate(TimeDate &t, bool skipRecord) const override;
114  Audio::Mixer *getMixer(void) override;
115  Common::Path getDefaultConfigFileName(void) override;
116  void logMessage(LogMessageType::Type type, const char *message) override;
117  int testGame(const char *filedata, bool autodetect);
118  void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
119  const char *const *buildHelpDialogData() override;
120  Common::String getSaveDir(void);
121  GUI::OptionsContainerWidget *buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;
122  void applyBackendSettings() override;
123 private:
124  bool parseGameName(const Common::String &gameName, Common::String &engineId, Common::String &gameId);
125  bool checkPathSetting(const char *setting, Common::String const &defaultPath, bool isDirectory = true);
126  void setLibretroDir(const char *path, Common::String &var);
127 
128  /* Inputs */
129 public:
130  void processInputs(void);
131  void processKeyEvent(bool down, unsigned keycode, uint32 character, uint16 key_modifiers);
132 private:
133  void updateMouseXY(float deltaAcc, float *cumulativeXYAcc, int doing_x);
134  void getMouseXYFromAnalog(bool is_x, int16 coor);
135  void getMouseXYFromButton(bool is_x, int16 sign);
136 };
137 
138 #endif
Definition: managed_surface.h:51
Definition: modular-backend.h:48
Definition: system.h:106
Definition: str.h:59
Definition: libretro-os.h:42
Definition: path.h:52
Definition: object.h:60
Definition: widget.h:532
Type
Definition: log.h:33
Definition: mixer_intern.h:58
Definition: mixer.h:59
Definition: archive.h:312
Definition: libretro-os.h:54
Definition: events.h:199
Definition: base-backend.h:44
Definition: mutex.h:40
void quit() override
Definition: libretro-os.h:88