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
45namespace N3DS {
46
47enum MagnifyMode {
48 MODE_MAGON,
49 MODE_MAGOFF,
50};
51
52enum InputMode {
53 MODE_HOVER,
54 MODE_DRAG,
55};
56
57enum GraphicsModeID {
58 RGBA8,
59 RGB565,
60 RGB5A1,
61 RGBA4,
62 CLUT8
63};
64
65enum Screen {
66 kScreenTop = 0x10000002,
67 kScreenBottom,
68 kScreenBoth,
69};
70
71enum 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
87typedef struct GfxMode3DS {
88 Graphics::PixelFormat surfaceFormat;
89 GPU_TEXCOLOR textureFormat;
90 uint32 textureTransferFlags;
92
93struct GfxState {
94 bool setup;
95 GraphicsModeID gfxModeID;
96 const GfxMode3DS *gfxMode;
97
98 GfxState() {
99 setup = false;
100 gfxModeID = CLUT8;
101 }
102};
103
104
106public:
107 OSystem_3DS();
108 virtual ~OSystem_3DS();
109
110 volatile bool exiting;
111 volatile bool sleeping;
112
113 virtual void initBackend();
114
116 virtual void setFeatureState(OSystem::Feature f, bool enable);
118
119 bool pollEvent(Common::Event &event) override;
120 bool notifyEvent(const Common::Event &event) override;
124
125 void registerDefaultSettings(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
134
135 virtual void logMessage(LogMessageType::Type type, const char *message);
136
138 virtual PaletteManager *getPaletteManager() { return this; }
140 virtual void fatalError();
141 virtual void quit();
142
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
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);
166 void fillScreen(uint32 col);
167 void fillScreen(const Common::Rect &r, uint32 col);
169 void setShakePos(int shakeXOffset, int shakeYOffset);
172 void showOverlay(bool inGUI);
174 bool isOverlayVisible() const { return _overlayVisible; }
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
206private:
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
220protected:
221 Audio::MixerImpl *_mixer;
222 Backends::Log::Log *_logger;
223
224private:
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;
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
311public:
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: mixer.h:70
Definition: mixer_intern.h:58
Definition: log.h:41
Definition: base-backend.h:31
Definition: events.h:337
Definition: events.h:278
Definition: hardware-input.h:199
Definition: keymapper-defaults.h:32
Definition: list.h:44
Definition: mutex.h:40
Definition: path.h:52
Definition: archive.h:330
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: object.h:60
Definition: widget.h:542
Definition: dirtyrects.h:43
Definition: osystem.h:105
virtual PaletteManager * getPaletteManager()
Definition: osystem.h:138
void fillScreen(uint32 col)
virtual void fatalError()
Graphics::Surface * lockScreen()
Graphics::PixelFormat getOverlayFormat() const
void fillScreen(const Common::Rect &r, uint32 col)
void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h)
GUI::OptionsContainerWidget * buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override
virtual void logMessage(LogMessageType::Type type, const char *message)
void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, const Graphics::PixelFormat *format, const byte *mask, frac_t scaleX, frac_t scaleY)
void setCursorPalette(const byte *colors, uint start, uint num)
void displayActivityIconOnOSD(const Graphics::Surface *icon) override
void registerDefaultSettings(const Common::String &target) const override
virtual void quit()
virtual Common::String getSystemLanguage() const
virtual int16 getOverlayHeight() const
bool pollEvent(Common::Event &event) override
void initSize(uint width, uint height, const Graphics::PixelFormat *format=NULL)
OSystem::TransactionError endGFXTransaction()
void applyBackendSettings() override
virtual void initBackend()
virtual int getScreenChangeID() const
Definition: osystem.h:151
virtual void getTimeAndDate(TimeDate &td, bool skipRecord=false) const
Common::KeymapperDefaultBindings * getKeymapperDefaultBindings() override
int16 getHeight()
Definition: osystem.h:157
virtual Common::MutexInternal * createMutex()
void setPalette(const byte *colors, uint start, uint num)
void showOverlay(bool inGUI)
void beginGFXTransaction()
virtual uint32 getMillis(bool skipRecord=false)
bool isOverlayVisible() const
Definition: osystem.h:174
virtual void delayMillis(uint msecs)
bool notifyEvent(const Common::Event &event) override
int16 getWidth()
Definition: osystem.h:158
virtual bool getFeatureState(OSystem::Feature f)
virtual bool hasFeature(OSystem::Feature f)
virtual int16 getOverlayWidth() const
void grabPalette(byte *colors, uint start, uint num) const
void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h)
void clearFocusRectangle()
virtual void setFeatureState(OSystem::Feature f, bool enable)
void displayMessageOnOSD(const Common::U32String &msg) override
virtual Common::Path getDefaultConfigFileName()
bool showMouse(bool visible)
Common::KeymapArray getGlobalKeymaps() override
void grabOverlay(Graphics::Surface &surface)
void warpMouse(int x, int y)
void setFocusRectangle(const Common::Rect &rect)
void setShakePos(int shakeXOffset, int shakeYOffset)
virtual Audio::Mixer * getMixer()
void addSysArchivesToSearchSet(Common::SearchSet &s, int priority) override
Common::HardwareInputSet * getHardwareInputSet() override
Definition: sprite.h:40
Definition: paletteman.h:47
Definition: engine.h:110
int32 frac_t
Definition: frac.h:52
Feature
Definition: system.h:415
TransactionError
Definition: system.h:1188
Type
Definition: log.h:33
Definition: events.h:218
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: osystem.h:87
Definition: osystem.h:93
Definition: osystem.h:78
Definition: atari-screen.h:58
Definition: system.h:111