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