ScummVM API documentation
osystem.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef PLATFORM_3DS_H
23 #define PLATFORM_3DS_H
24 
25 #define FORBIDDEN_SYMBOL_EXCEPTION_time_h
26 
27 #include "backends/base-backend.h"
28 #include "graphics/paletteman.h"
29 #include "base/main.h"
30 #include "audio/mixer_intern.h"
31 #include "backends/graphics/graphics.h"
32 #include "backends/log/log.h"
33 #include "backends/platform/3ds/sprite.h"
34 #include "common/rect.h"
35 #include "common/queue.h"
36 #include "common/ustr.h"
37 #include "engines/engine.h"
38 
39 #define TICKS_PER_MSEC 268123
40 
41 namespace N3DS {
42 
43 enum MagnifyMode {
44  MODE_MAGON,
45  MODE_MAGOFF,
46 };
47 
48 enum InputMode {
49  MODE_HOVER,
50  MODE_DRAG,
51 };
52 
53 enum GraphicsModeID {
54  RGBA8,
55  RGB565,
56  RGB555,
57  RGB5A1,
58  CLUT8
59 };
60 
61 enum Screen {
62  kScreenTop = 0x10000002,
63  kScreenBottom,
64  kScreenBoth,
65 };
66 
67 enum TransactionState {
68  kTransactionNone = 0,
69  kTransactionActive = 1,
70  kTransactionRollback = 2
71 };
72 
73 
75  bool formatChanged, modeChanged;
76 
78  formatChanged = false;
79  modeChanged = false;
80  }
81 };
82 
83 typedef struct GfxMode3DS {
84  Graphics::PixelFormat surfaceFormat;
85  GPU_TEXCOLOR textureFormat;
86  uint32 textureTransferFlags;
87 } GfxMode3DS;
88 
89 struct GfxState {
90  bool setup;
91  GraphicsModeID gfxModeID;
92  const GfxMode3DS *gfxMode;
93 
94  GfxState() {
95  setup = false;
96  gfxModeID = CLUT8;
97  }
98 };
99 
100 
102 public:
103  OSystem_3DS();
104  virtual ~OSystem_3DS();
105 
106  volatile bool exiting;
107  volatile bool sleeping;
108 
109  virtual void initBackend();
110 
111  virtual bool hasFeature(OSystem::Feature f);
112  virtual void setFeatureState(OSystem::Feature f, bool enable);
113  virtual bool getFeatureState(OSystem::Feature f);
114 
115  bool pollEvent(Common::Event &event) override;
116  bool notifyEvent(const Common::Event &event) override;
117  Common::HardwareInputSet *getHardwareInputSet() override;
118  Common::KeymapArray getGlobalKeymaps() override;
119  Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() override;
120 
121  void registerDefaultSettings(const Common::String &target) const override;
122  GUI::OptionsContainerWidget *buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;
123  void applyBackendSettings() override;
124 
125  virtual uint32 getMillis(bool skipRecord = false);
126  virtual void delayMillis(uint msecs);
127  virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
128 
129  virtual Common::MutexInternal *createMutex();
130 
131  virtual void logMessage(LogMessageType::Type type, const char *message);
132 
133  virtual Audio::Mixer *getMixer();
134  virtual PaletteManager *getPaletteManager() { return this; }
135  virtual Common::String getSystemLanguage() const;
136  virtual void fatalError();
137  virtual void quit();
138 
139  virtual Common::Path getDefaultConfigFileName();
140  void addSysArchivesToSearchSet(Common::SearchSet &s, int priority) override;
141 
142  // Graphics
143  inline Graphics::PixelFormat getScreenFormat() const { return _pfGame; }
144  virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
145  void initSize(uint width, uint height,
146  const Graphics::PixelFormat *format = NULL);
147  virtual int getScreenChangeID() const { return _screenChangeId; };
148  GraphicsModeID chooseMode(Graphics::PixelFormat *format);
149  bool setGraphicsMode(GraphicsModeID modeID);
150 
151  void beginGFXTransaction();
152  OSystem::TransactionError endGFXTransaction();
153  int16 getHeight(){ return _gameHeight; }
154  int16 getWidth(){ return _gameWidth; }
155  float getScaleRatio() const;
156  void setPalette(const byte *colors, uint start, uint num);
157  void grabPalette(byte *colors, uint start, uint num) const;
158  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w,
159  int h);
160  Graphics::Surface *lockScreen();
161  void unlockScreen();
162  void updateScreen();
163  void setShakePos(int shakeXOffset, int shakeYOffset);
164  void setFocusRectangle(const Common::Rect &rect);
165  void clearFocusRectangle();
166  void showOverlay(bool inGUI);
167  void hideOverlay();
168  bool isOverlayVisible() const { return _overlayVisible; }
169  Graphics::PixelFormat getOverlayFormat() const;
170  void clearOverlay();
171  void grabOverlay(Graphics::Surface &surface);
172  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w,
173  int h);
174  virtual int16 getOverlayHeight();
175  virtual int16 getOverlayWidth();
176  void displayMessageOnOSD(const Common::U32String &msg) override;
177  void displayActivityIconOnOSD(const Graphics::Surface *icon) override;
178 
179  bool showMouse(bool visible);
180  void warpMouse(int x, int y);
181  void setMouseCursor(const void *buf, uint w, uint h, int hotspotX,
182  int hotspotY, uint32 keycolor, bool dontScale = false,
183  const Graphics::PixelFormat *format = NULL, const byte *mask = NULL);
184  void setCursorPalette(const byte *colors, uint start, uint num);
185 
186  // Transform point from touchscreen coords into gamescreen coords
187  void transformPoint(touchPosition &point);
188  // Clip point to gamescreen coords
189  void clipPoint(touchPosition &point);
190 
191  void setCursorDelta(float deltaX, float deltaY);
192 
193  void updateFocus();
194  void updateMagnify();
195  void updateBacklight();
196  void updateConfig();
197  void updateSize();
198 
199 private:
200  void init3DSGraphics();
201  void destroy3DSGraphics();
202  void initAudio();
203  void destroyAudio();
204  void initEvents();
205  void destroyEvents();
206 
207  void flushGameScreen();
208  void flushCursor();
209 
210  virtual Common::Path getDefaultLogFileName();
211  virtual Common::WriteStream *createLogFile();
212 
213 protected:
214  Audio::MixerImpl *_mixer;
215  Backends::Log::Log *_logger;
216 
217 private:
218  u16 _gameWidth, _gameHeight;
219  u16 _gameTopX, _gameTopY;
220  u16 _gameBottomX, _gameBottomY;
221 
222  // Audio
223  Thread audioThread;
224 
225  // Graphics
226  GraphicsModeID _graphicsModeID;
227  TransactionState _transactionState;
228  TransactionDetails _transactionDetails;
229 
230  GfxState _gfxState, _oldGfxState;
231  Graphics::PixelFormat _pfDefaultTexture;
232  Graphics::PixelFormat _pfGame, _oldPfGame;
233  Graphics::PixelFormat _pfCursor;
234  byte _palette[3 * 256];
235  byte _cursorPalette[3 * 256];
236  uint32 _paletteMap[256];
237 
238  Graphics::Surface _gameScreen;
239  bool _gameTextureDirty;
240  Sprite _gameTopTexture;
241  Sprite _gameBottomTexture;
242  Sprite _overlay;
243  Sprite _activityIcon;
244  Sprite _osdMessage;
245  bool _filteringEnabled;
246 
247  enum {
248  kOSDMessageDuration = 800
249  };
250  uint32 _osdMessageEndTime;
251 
252  int _screenShakeXOffset;
253  int _screenShakeYOffset;
254  bool _overlayVisible;
255  bool _overlayInGUI;
256  int _screenChangeId;
257 
258  DVLB_s *_dvlb;
259  shaderProgram_s _program;
260  int _projectionLocation;
261  int _modelviewLocation;
262  C3D_Mtx _projectionTop;
263  C3D_Mtx _projectionBottom;
264  C3D_RenderTarget* _renderTargetTop;
265  C3D_RenderTarget* _renderTargetBottom;
266 
267  // Focus
268  Common::Rect _focusRect;
269  bool _focusDirty;
270  C3D_Mtx _focusMatrix;
271  int _focusPosX, _focusPosY;
272  int _focusTargetPosX, _focusTargetPosY;
273  float _focusStepPosX, _focusStepPosY;
274  float _focusScaleX, _focusScaleY;
275  float _focusTargetScaleX, _focusTargetScaleY;
276  float _focusStepScaleX, _focusStepScaleY;
277  uint32 _focusClearTime;
278 
279  // Events
280  Thread _eventThread;
281  Thread _timerThread;
282  Common::Queue<Common::Event> _eventQueue;
283 
284  // Cursor
285  Graphics::Surface _cursor;
286  Sprite _cursorTexture;
287  bool _cursorPaletteEnabled;
288  bool _cursorVisible;
289  bool _cursorScalable;
290  float _cursorScreenX, _cursorScreenY;
291  float _cursorOverlayX, _cursorOverlayY;
292  float _cursorDeltaX, _cursorDeltaY;
293  int _cursorHotspotX, _cursorHotspotY;
294  uint32 _cursorKeyColor;
295 
296  // Magnify
297  MagnifyMode _magnifyMode;
298  u16 _magX, _magY;
299  u16 _magWidth, _magHeight;
300  u16 _magCenterX, _magCenterY;
301 
302  Common::Path _logFilePath;
303 
304 public:
305  // Pause
306  PauseToken _sleepPauseToken;
307 
308  bool _showCursor;
309  bool _snapToBorder;
310  bool _stretchToFit;
311  Screen _screen;
312 };
313 
314 } // namespace N3DS
315 
316 #endif
Definition: engine.h:102
Definition: osystem.h:41
virtual int getScreenChangeID() const
Definition: osystem.h:147
virtual PaletteManager * getPaletteManager()
Definition: osystem.h:134
Definition: system.h:105
Definition: str.h:59
Definition: osystem.h:83
Definition: surface.h:66
Definition: osystem.h:74
Definition: osystem.h:101
Definition: stream.h:77
Definition: log.h:41
Definition: array.h:52
Definition: pixelformat.h:138
Feature
Definition: system.h:417
Definition: default_display_client.h:78
Definition: list.h:44
Definition: rect.h:144
Definition: path.h:52
int16 getWidth()
Definition: osystem.h:154
Definition: object.h:60
Definition: widget.h:528
Type
Definition: system.h:121
Definition: mixer_intern.h:58
bool isOverlayVisible() const
Definition: osystem.h:168
Definition: mixer.h:59
int16 getHeight()
Definition: osystem.h:153
Definition: events.h:317
Definition: ustr.h:57
TransactionError
Definition: system.h:1148
Definition: archive.h:312
Definition: events.h:198
Definition: hardware-input.h:199
Definition: keymapper-defaults.h:32
Definition: base-backend.h:44
Definition: mutex.h:40
Definition: paletteman.h:46
Definition: osystem.h:89
Definition: sprite.h:40