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