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 
29 #define BASE_CURSOR_SPEED 4
30 #define CURSOR_STATUS_DOING_JOYSTICK (1 << 0)
31 #define CURSOR_STATUS_DOING_MOUSE (1 << 1)
32 #define CURSOR_STATUS_DOING_X (1 << 2)
33 #define CURSOR_STATUS_DOING_Y (1 << 3)
34 #define CURSOR_STATUS_DOING_SLOWER (1 << 4)
35 
36 #define LIBRETRO_G_SYSTEM dynamic_cast<OSystem_libretro *>(g_system)
37 
42 public:
44  ~LibretroMutexInternal() override {};
45  bool lock() override {
46  return 0;
47  }
48  bool unlock() override {
49  return 0;
50  };
51 };
52 
54 private:
55  int _relMouseX;
56  int _relMouseY;
57  float _mouseXAcc;
58  float _mouseYAcc;
59  float _dpadXAcc;
60  float _dpadYAcc;
61  float _dpadXVel;
62  float _dpadYVel;
63  float _adjusted_cursor_speed;
64  float _inverse_acceleration_time;
65  uint32 _startTime;
66  uint8 _cursorStatus;
67  Common::String s_systemDir;
68  Common::String s_saveDir;
69  Common::String s_playlistDir;
71 
72 public:
73  Audio::MixerImpl *_mixer;
74  bool _mouseButtons[2];
75  bool _ptrmouseButton;
76  int _mouseX;
77  int _mouseY;
78 
79  /* Base */
80  OSystem_libretro(void);
81  ~OSystem_libretro(void) override;
82  void initBackend(void) override;
83  void engineInit(void) override;
84  void refreshRetroSettings(void);
85  void refreshScreen(void);
86  void destroy(void);
87  void quit() override {}
88 
89  void resetGraphicsManager(void);
90  void getScreen(const Graphics::Surface *&screen);
91  int16 getScreenWidth(void);
92  int16 getScreenHeight(void);
93  bool isOverlayInGUI(void);
94 
95 #ifdef USE_OPENGL
96  void *getOpenGLProcAddress(const char *name) const override;
97 #endif
98 
99 private:
100  bool checkPathSetting(const char *setting, Common::String const &defaultPath, bool isDirectory = true);
101  void setLibretroDir(const char *path, Common::String &var);
102 
103  /* Events */
104 public:
105  bool pollEvent(Common::Event &event) override;
106  uint32 getMillis(bool skipRecord = false) override;
107  void delayMillis(uint msecs) override;
108  Common::MutexInternal *createMutex(void) override;
109  void requestQuit(void);
110  void resetQuit(void);
111 
112  void setMousePosition(int x, int y);
113  Common::Point convertWindowToVirtual(int x, int y) const;
114 
115  /* Utils */
116  void getTimeAndDate(TimeDate &t, bool skipRecord) const override;
117  Audio::Mixer *getMixer(void) override;
118  Common::Path getDefaultConfigFileName(void) override;
119  void logMessage(LogMessageType::Type type, const char *message) override;
120  int testGame(const char *filedata, bool autodetect);
121  void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
122  const char *const *buildHelpDialogData() override;
123  Common::String getSaveDir(void);
124  GUI::OptionsContainerWidget *buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;
125  void applyBackendSettings() override;
126 private:
127  bool parseGameName(const Common::String &gameName, Common::String &engineId, Common::String &gameId);
128 
129  /* Inputs */
130 public:
131  void processInputs(void);
132  void processKeyEvent(bool down, unsigned keycode, uint32 character, uint16 key_modifiers);
133 private:
134  void updateMouseXY(float deltaAcc, float *cumulativeXYAcc, int doing_x);
135  void getMouseXYFromAnalog(bool is_x, int16 coor);
136  void getMouseXYFromButton(bool is_x, int16 sign);
137 };
138 
139 #endif
Definition: modular-backend.h:48
Definition: system.h:105
Definition: str.h:59
Definition: surface.h:66
Definition: libretro-os.h:41
Definition: path.h:52
Definition: object.h:60
Definition: widget.h:528
Type
Definition: system.h:121
Definition: mixer_intern.h:58
Definition: mixer.h:59
Definition: archive.h:312
Definition: libretro-os.h:53
Definition: events.h:198
Definition: rect.h:45
Definition: base-backend.h:44
Definition: mutex.h:40
void quit() override
Definition: libretro-os.h:87