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  RGBA4,
59  CLUT8
60 };
61 
62 enum Screen {
63  kScreenTop = 0x10000002,
64  kScreenBottom,
65  kScreenBoth,
66 };
67 
68 enum TransactionState {
69  kTransactionNone = 0,
70  kTransactionActive = 1,
71  kTransactionRollback = 2
72 };
73 
74 
76  bool formatChanged, modeChanged;
77 
79  formatChanged = false;
80  modeChanged = false;
81  }
82 };
83 
84 typedef struct GfxMode3DS {
85  Graphics::PixelFormat surfaceFormat;
86  GPU_TEXCOLOR textureFormat;
87  uint32 textureTransferFlags;
88 } GfxMode3DS;
89 
90 struct GfxState {
91  bool setup;
92  GraphicsModeID gfxModeID;
93  const GfxMode3DS *gfxMode;
94 
95  GfxState() {
96  setup = false;
97  gfxModeID = CLUT8;
98  }
99 };
100 
101 
103 public:
104  OSystem_3DS();
105  virtual ~OSystem_3DS();
106 
107  volatile bool exiting;
108  volatile bool sleeping;
109 
110  virtual void initBackend();
111 
112  virtual bool hasFeature(OSystem::Feature f);
113  virtual void setFeatureState(OSystem::Feature f, bool enable);
114  virtual bool getFeatureState(OSystem::Feature f);
115 
116  bool pollEvent(Common::Event &event) override;
117  bool notifyEvent(const Common::Event &event) override;
118  Common::HardwareInputSet *getHardwareInputSet() override;
119  Common::KeymapArray getGlobalKeymaps() override;
120  Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() override;
121 
122  void registerDefaultSettings(const Common::String &target) const override;
123  GUI::OptionsContainerWidget *buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;
124  void applyBackendSettings() override;
125 
126  virtual uint32 getMillis(bool skipRecord = false);
127  virtual void delayMillis(uint msecs);
128  virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
129 
130  virtual Common::MutexInternal *createMutex();
131 
132  virtual void logMessage(LogMessageType::Type type, const char *message);
133 
134  virtual Audio::Mixer *getMixer();
135  virtual PaletteManager *getPaletteManager() { return this; }
136  virtual Common::String getSystemLanguage() const;
137  virtual void fatalError();
138  virtual void quit();
139 
140  virtual Common::Path getDefaultConfigFileName();
141  void addSysArchivesToSearchSet(Common::SearchSet &s, int priority) override;
142 
143  // Graphics
144  inline Graphics::PixelFormat getScreenFormat() const { return _pfGame; }
145  virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
146  void initSize(uint width, uint height,
147  const Graphics::PixelFormat *format = NULL);
148  virtual int getScreenChangeID() const { return _screenChangeId; };
149  GraphicsModeID chooseMode(Graphics::PixelFormat *format);
150  bool setGraphicsMode(GraphicsModeID modeID);
151 
152  void beginGFXTransaction();
153  OSystem::TransactionError endGFXTransaction();
154  int16 getHeight(){ return _gameHeight; }
155  int16 getWidth(){ return _gameWidth; }
156  float getScaleRatio() const;
157  void setPalette(const byte *colors, uint start, uint num);
158  void grabPalette(byte *colors, uint start, uint num) const;
159  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w,
160  int h);
161  Graphics::Surface *lockScreen();
162  void unlockScreen();
163  void updateScreen();
164  void setShakePos(int shakeXOffset, int shakeYOffset);
165  void setFocusRectangle(const Common::Rect &rect);
166  void clearFocusRectangle();
167  void showOverlay(bool inGUI);
168  void hideOverlay();
169  bool isOverlayVisible() const { return _overlayVisible; }
170  Graphics::PixelFormat getOverlayFormat() const;
171  void clearOverlay();
172  void grabOverlay(Graphics::Surface &surface);
173  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w,
174  int h);
175  virtual int16 getOverlayHeight();
176  virtual int16 getOverlayWidth();
177  void displayMessageOnOSD(const Common::U32String &msg) override;
178  void displayActivityIconOnOSD(const Graphics::Surface *icon) override;
179 
180  bool showMouse(bool visible);
181  void warpMouse(int x, int y);
182  void setMouseCursor(const void *buf, uint w, uint h, int hotspotX,
183  int hotspotY, uint32 keycolor, bool dontScale = false,
184  const Graphics::PixelFormat *format = NULL, const byte *mask = NULL);
185  void setCursorPalette(const byte *colors, uint start, uint num);
186 
187  // Transform point from touchscreen coords into gamescreen coords
188  void transformPoint(touchPosition &point);
189  // Clip point to gamescreen coords
190  void clipPoint(touchPosition &point);
191 
192  void setCursorDelta(float deltaX, float deltaY);
193 
194  void updateFocus();
195  void updateMagnify();
196  void updateBacklight();
197  void updateConfig();
198  void updateSize();
199 
200 private:
201  void init3DSGraphics();
202  void destroy3DSGraphics();
203  void initAudio();
204  void destroyAudio();
205  void initEvents();
206  void destroyEvents();
207 
208  void flushGameScreen();
209  void flushCursor();
210 
211  virtual Common::Path getDefaultLogFileName();
212  virtual Common::WriteStream *createLogFile();
213 
214 protected:
215  Audio::MixerImpl *_mixer;
216  Backends::Log::Log *_logger;
217 
218 private:
219  u16 _gameWidth, _gameHeight;
220  u16 _gameTopX, _gameTopY;
221  u16 _gameBottomX, _gameBottomY;
222 
223  // Audio
224  Thread audioThread;
225 
226  // Graphics
227  GraphicsModeID _graphicsModeID;
228  TransactionState _transactionState;
229  TransactionDetails _transactionDetails;
230 
231  GfxState _gfxState, _oldGfxState;
232  Graphics::PixelFormat _pfDefaultTexture;
233  Graphics::PixelFormat _pfGame, _oldPfGame;
234  Graphics::PixelFormat _pfCursor;
235  byte _palette[3 * 256];
236  byte _cursorPalette[3 * 256];
237  uint32 _paletteMap[256];
238 
239  Graphics::Surface _gameScreen;
240  bool _gameTextureDirty;
241  Sprite _gameTopTexture;
242  Sprite _gameBottomTexture;
243  Sprite _overlay;
244  Sprite _activityIcon;
245  Sprite _osdMessage;
246  bool _filteringEnabled;
247 
248  enum {
249  kOSDMessageDuration = 800
250  };
251  uint32 _osdMessageEndTime;
252 
253  int _screenShakeXOffset;
254  int _screenShakeYOffset;
255  bool _overlayVisible;
256  bool _overlayInGUI;
257  int _screenChangeId;
258 
259  DVLB_s *_dvlb;
260  shaderProgram_s _program;
261  int _projectionLocation;
262  int _modelviewLocation;
263  C3D_Mtx _projectionTop;
264  C3D_Mtx _projectionBottom;
265  C3D_RenderTarget* _renderTargetTop;
266  C3D_RenderTarget* _renderTargetBottom;
267 
268  // Focus
269  Common::Rect _focusRect;
270  bool _focusDirty;
271  C3D_Mtx _focusMatrix;
272  int _focusPosX, _focusPosY;
273  int _focusTargetPosX, _focusTargetPosY;
274  float _focusStepPosX, _focusStepPosY;
275  float _focusScaleX, _focusScaleY;
276  float _focusTargetScaleX, _focusTargetScaleY;
277  float _focusStepScaleX, _focusStepScaleY;
278  uint32 _focusClearTime;
279 
280  // Events
281  Thread _eventThread;
282  Thread _timerThread;
283  Common::Queue<Common::Event> _eventQueue;
284 
285  // Cursor
286  Graphics::Surface _cursor;
287  Sprite _cursorTexture;
288  bool _cursorPaletteEnabled;
289  bool _cursorVisible;
290  bool _cursorScalable;
291  float _cursorScreenX, _cursorScreenY;
292  float _cursorOverlayX, _cursorOverlayY;
293  float _cursorDeltaX, _cursorDeltaY;
294  int _cursorHotspotX, _cursorHotspotY;
295  uint32 _cursorKeyColor;
296 
297  // Magnify
298  MagnifyMode _magnifyMode;
299  u16 _magX, _magY;
300  u16 _magWidth, _magHeight;
301  u16 _magCenterX, _magCenterY;
302 
303  Common::Path _logFilePath;
304 
305 public:
306  // Pause
307  PauseToken _sleepPauseToken;
308 
309  bool _showCursor;
310  bool _snapToBorder;
311  bool _stretchToFit;
312  Screen _screen;
313 };
314 
315 } // namespace N3DS
316 
317 #endif
Definition: engine.h:103
Definition: osystem.h:41
virtual int getScreenChangeID() const
Definition: osystem.h:148
virtual PaletteManager * getPaletteManager()
Definition: osystem.h:135
Definition: system.h:106
Definition: str.h:59
Definition: osystem.h:84
Definition: surface.h:67
Definition: osystem.h:75
Definition: osystem.h:102
Definition: stream.h:77
Definition: log.h:41
Definition: array.h:52
Definition: pixelformat.h:138
Feature
Definition: system.h:403
Definition: list.h:44
Definition: rect.h:144
Definition: path.h:52
Definition: atari-screen.h:60
int16 getWidth()
Definition: osystem.h:155
Definition: object.h:60
Definition: widget.h:532
Type
Definition: log.h:33
Definition: mixer_intern.h:58
bool isOverlayVisible() const
Definition: osystem.h:169
Definition: mixer.h:59
int16 getHeight()
Definition: osystem.h:154
Definition: events.h:318
Definition: ustr.h:57
TransactionError
Definition: system.h:1155
Definition: archive.h:312
Definition: events.h:199
Definition: hardware-input.h:199
Definition: keymapper-defaults.h:32
Definition: base-backend.h:44
Definition: mutex.h:40
Definition: paletteman.h:47
Definition: osystem.h:90
Definition: sprite.h:40