aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/base_game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/wintermute/base/base_game.cpp')
-rw-r--r--engines/wintermute/base/base_game.cpp1054
1 files changed, 238 insertions, 816 deletions
diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp
index f0b1171ca4..0f2a3d1260 100644
--- a/engines/wintermute/base/base_game.cpp
+++ b/engines/wintermute/base/base_game.cpp
@@ -29,32 +29,30 @@
#include "engines/wintermute/dcgf.h"
#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/base/base_game.h"
+#include "engines/wintermute/base/base_game_music.h"
+#include "engines/wintermute/base/base_game_settings.h"
#include "engines/wintermute/base/base_fader.h"
#include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/base/font/base_font.h"
#include "engines/wintermute/base/font/base_font_storage.h"
-#include "engines/wintermute/base/gfx/base_image.h"
-#include "engines/wintermute/base/gfx/base_surface.h"
#include "engines/wintermute/base/gfx/base_renderer.h"
#include "engines/wintermute/base/base_keyboard_state.h"
#include "engines/wintermute/base/base_parser.h"
#include "engines/wintermute/base/base_quick_msg.h"
-#include "engines/wintermute/base/sound/base_sound.h"
#include "engines/wintermute/base/sound/base_sound_manager.h"
#include "engines/wintermute/base/base_sprite.h"
#include "engines/wintermute/base/base_sub_frame.h"
#include "engines/wintermute/base/base_transition_manager.h"
#include "engines/wintermute/base/base_viewport.h"
-#include "engines/wintermute/base/base_string_table.h"
#include "engines/wintermute/base/base_region.h"
-#include "engines/wintermute/base/base_save_thumb_helper.h"
#include "engines/wintermute/base/base_surface_storage.h"
#include "engines/wintermute/base/saveload.h"
+#include "engines/wintermute/base/save_thumb_helper.h"
#include "engines/wintermute/base/scriptables/script_value.h"
#include "engines/wintermute/base/scriptables/script_engine.h"
#include "engines/wintermute/base/scriptables/script_stack.h"
#include "engines/wintermute/base/scriptables/script.h"
-#include "engines/wintermute/base/scriptables/script_ext_math.h"
+#include "engines/wintermute/base/sound/base_sound.h"
#include "engines/wintermute/video/video_player.h"
#include "engines/wintermute/video/video_theora_player.h"
#include "engines/wintermute/utils/utils.h"
@@ -64,6 +62,7 @@
#include "engines/wintermute/ui/ui_window.h"
#include "engines/wintermute/wintermute.h"
#include "engines/wintermute/platform_osystem.h"
+#include "base/version.h"
#include "common/config-manager.h"
#include "common/savefile.h"
#include "common/textconsole.h"
@@ -82,7 +81,7 @@ IMPLEMENT_PERSISTENT(BaseGame, true)
//////////////////////////////////////////////////////////////////////
-BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gameId) {
+BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gameId), _timerNormal(), _timerLive() {
_shuttingDown = false;
_state = GAME_RUNNING;
@@ -92,30 +91,30 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam
_interactive = true;
_origInteractive = false;
- _surfaceStorage = NULL;
- _fontStorage = NULL;
- _renderer = NULL;
- _soundMgr = NULL;
- _transMgr = NULL;
- _scEngine = NULL;
- _keyboardState = NULL;
+ _surfaceStorage = nullptr;
+ _fontStorage = nullptr;
+ _renderer = nullptr;
+ _soundMgr = nullptr;
+ _transMgr = nullptr;
+ _scEngine = nullptr;
+ _keyboardState = nullptr;
- _mathClass = NULL;
+ _mathClass = nullptr;
- _debugLogFile = NULL;
+ _debugLogFile = nullptr;
_debugDebugMode = false;
_debugShowFPS = false;
- _systemFont = NULL;
- _videoFont = NULL;
+ _systemFont = nullptr;
+ _videoFont = nullptr;
- _videoPlayer = NULL;
- _theoraPlayer = NULL;
+ _videoPlayer = nullptr;
+ _theoraPlayer = nullptr;
- _mainObject = NULL;
- _activeObject = NULL;
+ _mainObject = nullptr;
+ _activeObject = nullptr;
- _fader = NULL;
+ _fader = nullptr;
_offsetX = _offsetY = 0;
_offsetPercentX = _offsetPercentY = 0.0f;
@@ -123,50 +122,25 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam
_subtitles = true;
_videoSubtitles = true;
- _timer = 0;
- _timerDelta = 0;
- _timerLast = 0;
-
- _liveTimer = 0;
- _liveTimerDelta = 0;
- _liveTimerLast = 0;
-
_sequence = 0;
_mousePos.x = _mousePos.y = 0;
_mouseLeftDown = _mouseRightDown = _mouseMidlleDown = false;
- _capturedObject = NULL;
+ _capturedObject = nullptr;
// FPS counters
_lastTime = _fpsTime = _deltaTime = _framesRendered = _fps = 0;
- _cursorNoninteractive = NULL;
+ _cursorNoninteractive = nullptr;
_useD3D = false;
- _stringTable = new BaseStringTable(this);
-
- for (int i = 0; i < NUM_MUSIC_CHANNELS; i++) {
- _music[i] = NULL;
- _musicStartTime[i] = 0;
- }
-
- _settingsResWidth = 800;
- _settingsResHeight = 600;
- _settingsRequireAcceleration = false;
- _settingsRequireSound = false;
- _settingsTLMode = 0;
- _settingsAllowWindowed = true;
- _settingsGameFile = NULL;
- _settingsAllowAdvanced = false;
- _settingsAllowAccessTab = true;
- _settingsAllowAboutTab = true;
- _settingsAllowDesktopRes = false;
+ _musicSystem = new BaseGameMusic(this);
_editorForceScripts = false;
_editorAlwaysRegister = false;
- _focusedWindow = NULL;
+ _focusedWindow = nullptr;
_loadInProgress = false;
@@ -175,13 +149,12 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam
_scheduledLoadSlot = -1;
_personalizedSave = false;
- _compressedSavegames = true;
_editorMode = false;
//_doNotExpandStrings = false;
- _engineLogCallback = NULL;
- _engineLogCallbackData = NULL;
+ _engineLogCallback = nullptr;
+ _engineLogCallbackData = nullptr;
_smartCache = false;
_surfaceGCCycleTime = 10000;
@@ -196,22 +169,11 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam
_thumbnailWidth = _thumbnailHeight = 0;
- _richSavedGames = false;
- _savedGameExt = NULL;
- BaseUtils::setString(&_savedGameExt, "dsv");
-
- _musicCrossfadeRunning = false;
- _musicCrossfadeStartTime = 0;
- _musicCrossfadeLength = 0;
- _musicCrossfadeChannel1 = -1;
- _musicCrossfadeChannel2 = -1;
- _musicCrossfadeSwap = false;
+ _localSaveDir = "saves";
- _localSaveDir = NULL;
- BaseUtils::setString(&_localSaveDir, "saves");
_saveDirChecked = false;
- _loadingIcon = NULL;
+ _loadingIcon = nullptr;
_loadingIconX = _loadingIconY = 0;
_loadingIconPersistent = false;
@@ -221,8 +183,7 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam
_soundBufferSizeSec = 3;
_suspendedRendering = false;
- _lastCursor = NULL;
-
+ _lastCursor = nullptr;
BasePlatform::setRectEmpty(&_mouseLockRect);
@@ -230,7 +191,7 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam
_lastMiniUpdate = 0;
_miniUpdateEnabled = false;
- _cachedThumbnail = NULL;
+ _cachedThumbnail = nullptr;
_autorunDisabled = false;
@@ -251,6 +212,8 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam
#else*/
_touchInterface = false;
_constrainedMemory = false;
+
+ _settings = new BaseGameSettings(this);
//#endif
}
@@ -267,10 +230,6 @@ BaseGame::~BaseGame() {
cleanup();
- delete[] _localSaveDir;
- delete[] _settingsGameFile;
- delete[] _savedGameExt;
-
delete _cachedThumbnail;
delete _mathClass;
@@ -285,26 +244,24 @@ BaseGame::~BaseGame() {
//SAFE_DELETE(_keyboardState);
delete _renderer;
- delete _stringTable;
-
- _localSaveDir = NULL;
- _settingsGameFile = NULL;
- _savedGameExt = NULL;
+ delete _musicSystem;
+ delete _settings;
- _cachedThumbnail = NULL;
+ _cachedThumbnail = nullptr;
- _mathClass = NULL;
+ _mathClass = nullptr;
- _transMgr = NULL;
- _scEngine = NULL;
- _fontStorage = NULL;
- _surfaceStorage = NULL;
- _videoPlayer = NULL;
- _theoraPlayer = NULL;
- _soundMgr = NULL;
+ _transMgr = nullptr;
+ _scEngine = nullptr;
+ _fontStorage = nullptr;
+ _surfaceStorage = nullptr;
+ _videoPlayer = nullptr;
+ _theoraPlayer = nullptr;
+ _soundMgr = nullptr;
- _renderer = NULL;
- _stringTable = NULL;
+ _renderer = nullptr;
+ _musicSystem = nullptr;
+ _settings = nullptr;
DEBUG_DebugDisable();
debugC(kWintermuteDebugLog, "--- shutting down normally ---\n");
@@ -314,52 +271,48 @@ BaseGame::~BaseGame() {
//////////////////////////////////////////////////////////////////////////
bool BaseGame::cleanup() {
delete _loadingIcon;
- _loadingIcon = NULL;
+ _loadingIcon = nullptr;
- _engineLogCallback = NULL;
- _engineLogCallbackData = NULL;
+ _engineLogCallback = nullptr;
+ _engineLogCallbackData = nullptr;
- for (int i = 0; i < NUM_MUSIC_CHANNELS; i++) {
- delete _music[i];
- _music[i] = NULL;
- _musicStartTime[i] = 0;
- }
+ _musicSystem->cleanup();
unregisterObject(_fader);
- _fader = NULL;
+ _fader = nullptr;
for (uint32 i = 0; i < _regObjects.size(); i++) {
delete _regObjects[i];
- _regObjects[i] = NULL;
+ _regObjects[i] = nullptr;
}
_regObjects.clear();
_windows.clear(); // refs only
- _focusedWindow = NULL; // ref only
+ _focusedWindow = nullptr; // ref only
delete _cursorNoninteractive;
delete _cursor;
delete _activeCursor;
- _cursorNoninteractive = NULL;
- _cursor = NULL;
- _activeCursor = NULL;
+ _cursorNoninteractive = nullptr;
+ _cursor = nullptr;
+ _activeCursor = nullptr;
delete _scValue;
delete _sFX;
- _scValue = NULL;
- _sFX = NULL;
+ _scValue = nullptr;
+ _sFX = nullptr;
for (uint32 i = 0; i < _scripts.size(); i++) {
- _scripts[i]->_owner = NULL;
+ _scripts[i]->_owner = nullptr;
_scripts[i]->finish();
}
_scripts.clear();
_fontStorage->removeFont(_systemFont);
- _systemFont = NULL;
+ _systemFont = nullptr;
_fontStorage->removeFont(_videoFont);
- _videoFont = NULL;
+ _videoFont = nullptr;
for (uint32 i = 0; i < _quickMessages.size(); i++) {
delete _quickMessages[i];
@@ -369,68 +322,104 @@ bool BaseGame::cleanup() {
_viewportStack.clear();
_viewportSP = -1;
- setName(NULL);
- setFilename(NULL);
+ setName(nullptr);
+ setFilename(nullptr);
for (int i = 0; i < 7; i++) {
delete[] _caption[i];
- _caption[i] = NULL;
+ _caption[i] = nullptr;
}
- _lastCursor = NULL;
+ _lastCursor = nullptr;
delete _keyboardState;
- _keyboardState = NULL;
+ _keyboardState = nullptr;
+
+ return STATUS_OK;
+}
+
+//////////////////////////////////////////////////////////////////////
+bool BaseGame::initConfManSettings() {
+ if (ConfMan.hasKey("debug_mode")) {
+ if (ConfMan.getBool("debug_mode")) {
+ DEBUG_DebugEnable("./wme.log");
+ }
+ }
+
+ if (ConfMan.hasKey("show_fps")) {
+ _debugShowFPS = ConfMan.getBool("show_fps");
+ } else {
+ _debugShowFPS = false;
+ }
+ if (ConfMan.hasKey("disable_smartcache")) {
+ _smartCache = ConfMan.getBool("disable_smartcache");
+ } else {
+ _smartCache = true;
+ }
+
+ if (!_smartCache) {
+ LOG(0, "Smart cache is DISABLED");
+ }
return STATUS_OK;
}
+//////////////////////////////////////////////////////////////////////
+bool BaseGame::initRenderer() {
+ bool windowedMode = !ConfMan.getBool("fullscreen");
+ return _renderer->initRenderer(_settings->getResWidth(), _settings->getResHeight(), windowedMode);
+}
+
+//////////////////////////////////////////////////////////////////////
+bool BaseGame::loadGameSettingsFile() {
+ return loadFile(_settings->getGameFile());
+}
//////////////////////////////////////////////////////////////////////
bool BaseGame::initialize1() {
bool loaded = false; // Not really a loop, but a goto-replacement.
while (!loaded) {
_surfaceStorage = new BaseSurfaceStorage(this);
- if (_surfaceStorage == NULL) {
+ if (_surfaceStorage == nullptr) {
break;
}
_fontStorage = new BaseFontStorage(this);
- if (_fontStorage == NULL) {
+ if (_fontStorage == nullptr) {
break;
}
_soundMgr = new BaseSoundMgr(this);
- if (_soundMgr == NULL) {
+ if (_soundMgr == nullptr) {
break;
}
- _mathClass = new SXMath(this);
- if (_mathClass == NULL) {
+ _mathClass = makeSXMath(this);
+ if (_mathClass == nullptr) {
break;
}
_scEngine = new ScEngine(this);
- if (_scEngine == NULL) {
+ if (_scEngine == nullptr) {
break;
}
_videoPlayer = new VideoPlayer(this);
- if (_videoPlayer == NULL) {
+ if (_videoPlayer == nullptr) {
break;
}
_transMgr = new BaseTransitionMgr(this);
- if (_transMgr == NULL) {
+ if (_transMgr == nullptr) {
break;
}
_keyboardState = new BaseKeyboardState(this);
- if (_keyboardState == NULL) {
+ if (_keyboardState == nullptr) {
break;
}
_fader = new BaseFader(this);
- if (_fader == NULL) {
+ if (_fader == nullptr) {
break;
}
registerObject(_fader);
@@ -456,7 +445,7 @@ bool BaseGame::initialize1() {
//////////////////////////////////////////////////////////////////////
bool BaseGame::initialize2() { // we know whether we are going to be accelerated
_renderer = makeOSystemRenderer(this);
- if (_renderer == NULL) {
+ if (_renderer == nullptr) {
return STATUS_FAILED;
}
@@ -466,8 +455,8 @@ bool BaseGame::initialize2() { // we know whether we are going to be accelerated
//////////////////////////////////////////////////////////////////////
bool BaseGame::initialize3() { // renderer is initialized
- _posX = _renderer->_width / 2;
- _posY = _renderer->_height / 2;
+ _posX = _renderer->getWidth() / 2;
+ _posY = _renderer->getHeight() / 2;
_renderer->initIndicator();
return STATUS_OK;
}
@@ -489,7 +478,7 @@ void BaseGame::DEBUG_DebugEnable(const char *filename) {
LOG(0, "********** DEBUG LOG OPENED %02d-%02d-%02d (Release Build) *****************", hours, mins, secs);
#endif
- LOG(0, "%s ver %d.%d.%d%s, Compiled on " __DATE__ ", " __TIME__, DCGF_NAME, DCGF_VER_MAJOR, DCGF_VER_MINOR, DCGF_VER_BUILD, DCGF_VER_SUFFIX);
+ LOG(0, "%s - %s ver %d.%d.%d%s ", gScummVMFullVersion, DCGF_NAME, DCGF_VER_MAJOR, DCGF_VER_MINOR, DCGF_VER_BUILD, DCGF_VER_SUFFIX);
AnsiString platform = BasePlatform::getPlatformName();
LOG(0, "Platform: %s", platform.c_str());
@@ -499,10 +488,10 @@ void BaseGame::DEBUG_DebugEnable(const char *filename) {
//////////////////////////////////////////////////////////////////////
void BaseGame::DEBUG_DebugDisable() {
- if (_debugLogFile != NULL) {
+ if (_debugLogFile != nullptr) {
LOG(0, "********** DEBUG LOG CLOSED ********************************************");
//fclose((FILE *)_debugLogFile);
- _debugLogFile = NULL;
+ _debugLogFile = nullptr;
}
_debugDebugMode = false;
}
@@ -551,29 +540,25 @@ bool BaseGame::initLoop() {
_currentTime = g_system->getMillis();
_renderer->initLoop();
- updateMusicCrossfade();
+ _musicSystem->updateMusicCrossfade();
_surfaceStorage->initLoop();
_fontStorage->initLoop();
- //_activeObject = NULL;
+ //_activeObject = nullptr;
// count FPS
_deltaTime = _currentTime - _lastTime;
_lastTime = _currentTime;
_fpsTime += _deltaTime;
- _liveTimerDelta = _liveTimer - _liveTimerLast;
- _liveTimerLast = _liveTimer;
- _liveTimer += MIN((uint32)1000, _deltaTime);
+ _timerLive.updateTime(_deltaTime, 1000);
if (_state != GAME_FROZEN) {
- _timerDelta = _timer - _timerLast;
- _timerLast = _timer;
- _timer += MIN((uint32)1000, _deltaTime);
+ _timerNormal.updateTime(_deltaTime, 1000);
} else {
- _timerDelta = 0;
+ _timerNormal.setTimeDelta(0);
}
_framesRendered++;
@@ -586,7 +571,7 @@ bool BaseGame::initLoop() {
getMousePos(&_mousePos);
- _focusedWindow = NULL;
+ _focusedWindow = nullptr;
for (int i = _windows.size() - 1; i >= 0; i--) {
if (_windows[i]->_visible) {
_focusedWindow = _windows[i];
@@ -623,11 +608,11 @@ void BaseGame::setOffset(int offsetX, int offsetY) {
}
//////////////////////////////////////////////////////////////////////////
-void BaseGame::getOffset(int *offsetX, int *offsetY) {
- if (offsetX != NULL) {
+void BaseGame::getOffset(int *offsetX, int *offsetY) const {
+ if (offsetX != nullptr) {
*offsetX = _offsetX;
}
- if (offsetY != NULL) {
+ if (offsetY != nullptr) {
*offsetY = _offsetY;
}
}
@@ -636,7 +621,7 @@ void BaseGame::getOffset(int *offsetX, int *offsetY) {
//////////////////////////////////////////////////////////////////////////
bool BaseGame::loadFile(const char *filename) {
byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename);
- if (buffer == NULL) {
+ if (buffer == nullptr) {
_gameRef->LOG(0, "BaseGame::LoadFile failed for file '%s'", filename);
return STATUS_FAILED;
}
@@ -787,7 +772,7 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) {
if (_systemFont) {
_fontStorage->removeFont(_systemFont);
}
- _systemFont = NULL;
+ _systemFont = nullptr;
_systemFont = _gameRef->_fontStorage->addFont((char *)params);
break;
@@ -796,7 +781,7 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) {
if (_videoFont) {
_fontStorage->removeFont(_videoFont);
}
- _videoFont = NULL;
+ _videoFont = nullptr;
_videoFont = _gameRef->_fontStorage->addFont((char *)params);
break;
@@ -807,18 +792,18 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) {
_cursor = new BaseSprite(_gameRef);
if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) {
delete _cursor;
- _cursor = NULL;
+ _cursor = nullptr;
cmd = PARSERR_GENERIC;
}
break;
case TOKEN_ACTIVE_CURSOR:
delete _activeCursor;
- _activeCursor = NULL;
+ _activeCursor = nullptr;
_activeCursor = new BaseSprite(_gameRef);
if (!_activeCursor || DID_FAIL(_activeCursor->loadFile((char *)params))) {
delete _activeCursor;
- _activeCursor = NULL;
+ _activeCursor = nullptr;
cmd = PARSERR_GENERIC;
}
break;
@@ -828,7 +813,7 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) {
_cursorNoninteractive = new BaseSprite(_gameRef);
if (!_cursorNoninteractive || DID_FAIL(_cursorNoninteractive->loadFile((char *)params))) {
delete _cursorNoninteractive;
- _cursorNoninteractive = NULL;
+ _cursorNoninteractive = nullptr;
cmd = PARSERR_GENERIC;
}
break;
@@ -917,7 +902,7 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) {
break;
case TOKEN_LOCAL_SAVE_DIR:
- BaseUtils::setString(&_localSaveDir, (char *)params);
+ _localSaveDir = (char *)params;
break;
case TOKEN_COMPAT_KILL_METHOD_THREADS:
@@ -1012,7 +997,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
clearOld = val->getBool();
}
- if (DID_FAIL(_stringTable->loadFile(filename, clearOld))) {
+ if (DID_FAIL(_settings->loadStringTable(filename, clearOld))) {
stack->pushBool(false);
} else {
stack->pushBool(true);
@@ -1076,7 +1061,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
stack->pushNative(win, true);
} else {
delete win;
- win = NULL;
+ win = nullptr;
stack->pushNULL();
}
return STATUS_OK;
@@ -1090,278 +1075,13 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
ScValue *val = stack->pop();
char *str = new char[strlen(val->getString()) + 1];
strcpy(str, val->getString());
- _stringTable->expand(&str);
+ expandStringByStringTable(&str);
stack->pushString(str);
delete[] str;
return STATUS_OK;
}
- //////////////////////////////////////////////////////////////////////////
- // PlayMusic / PlayMusicChannel
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "PlayMusic") == 0 || strcmp(name, "PlayMusicChannel") == 0) {
- int channel = 0;
- if (strcmp(name, "PlayMusic") == 0) {
- stack->correctParams(3);
- } else {
- stack->correctParams(4);
- channel = stack->pop()->getInt();
- }
-
- const char *filename = stack->pop()->getString();
- ScValue *valLooping = stack->pop();
- bool looping = valLooping->isNULL() ? true : valLooping->getBool();
-
- ScValue *valLoopStart = stack->pop();
- uint32 loopStart = (uint32)(valLoopStart->isNULL() ? 0 : valLoopStart->getInt());
-
-
- if (DID_FAIL(playMusic(channel, filename, looping, loopStart))) {
- stack->pushBool(false);
- } else {
- stack->pushBool(true);
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // StopMusic / StopMusicChannel
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "StopMusic") == 0 || strcmp(name, "StopMusicChannel") == 0) {
- int channel = 0;
-
- if (strcmp(name, "StopMusic") == 0) {
- stack->correctParams(0);
- } else {
- stack->correctParams(1);
- channel = stack->pop()->getInt();
- }
-
- if (DID_FAIL(stopMusic(channel))) {
- stack->pushBool(false);
- } else {
- stack->pushBool(true);
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // PauseMusic / PauseMusicChannel
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "PauseMusic") == 0 || strcmp(name, "PauseMusicChannel") == 0) {
- int channel = 0;
-
- if (strcmp(name, "PauseMusic") == 0) {
- stack->correctParams(0);
- } else {
- stack->correctParams(1);
- channel = stack->pop()->getInt();
- }
-
- if (DID_FAIL(pauseMusic(channel))) {
- stack->pushBool(false);
- } else {
- stack->pushBool(true);
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // ResumeMusic / ResumeMusicChannel
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "ResumeMusic") == 0 || strcmp(name, "ResumeMusicChannel") == 0) {
- int channel = 0;
- if (strcmp(name, "ResumeMusic") == 0) {
- stack->correctParams(0);
- } else {
- stack->correctParams(1);
- channel = stack->pop()->getInt();
- }
-
- if (DID_FAIL(resumeMusic(channel))) {
- stack->pushBool(false);
- } else {
- stack->pushBool(true);
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // GetMusic / GetMusicChannel
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "GetMusic") == 0 || strcmp(name, "GetMusicChannel") == 0) {
- int channel = 0;
- if (strcmp(name, "GetMusic") == 0) {
- stack->correctParams(0);
- } else {
- stack->correctParams(1);
- channel = stack->pop()->getInt();
- }
- if (channel < 0 || channel >= NUM_MUSIC_CHANNELS) {
- stack->pushNULL();
- } else {
- if (!_music[channel] || !_music[channel]->getFilename()) {
- stack->pushNULL();
- } else {
- stack->pushString(_music[channel]->getFilename());
- }
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // SetMusicPosition / SetMusicChannelPosition
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "SetMusicPosition") == 0 || strcmp(name, "SetMusicChannelPosition") == 0 || strcmp(name, "SetMusicPositionChannel") == 0) {
- int channel = 0;
- if (strcmp(name, "SetMusicPosition") == 0) {
- stack->correctParams(1);
- } else {
- stack->correctParams(2);
- channel = stack->pop()->getInt();
- }
-
- uint32 time = stack->pop()->getInt();
-
- if (DID_FAIL(setMusicStartTime(channel, time))) {
- stack->pushBool(false);
- } else {
- stack->pushBool(true);
- }
-
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // GetMusicPosition / GetMusicChannelPosition
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "GetMusicPosition") == 0 || strcmp(name, "GetMusicChannelPosition") == 0) {
- int channel = 0;
- if (strcmp(name, "GetMusicPosition") == 0) {
- stack->correctParams(0);
- } else {
- stack->correctParams(1);
- channel = stack->pop()->getInt();
- }
-
- if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) {
- stack->pushInt(0);
- } else {
- stack->pushInt(_music[channel]->getPositionTime());
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // IsMusicPlaying / IsMusicChannelPlaying
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "IsMusicPlaying") == 0 || strcmp(name, "IsMusicChannelPlaying") == 0) {
- int channel = 0;
- if (strcmp(name, "IsMusicPlaying") == 0) {
- stack->correctParams(0);
- } else {
- stack->correctParams(1);
- channel = stack->pop()->getInt();
- }
-
- if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) {
- stack->pushBool(false);
- } else {
- stack->pushBool(_music[channel]->isPlaying());
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // SetMusicVolume / SetMusicChannelVolume
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "SetMusicVolume") == 0 || strcmp(name, "SetMusicChannelVolume") == 0) {
- int channel = 0;
- if (strcmp(name, "SetMusicVolume") == 0) {
- stack->correctParams(1);
- } else {
- stack->correctParams(2);
- channel = stack->pop()->getInt();
- }
-
- int volume = stack->pop()->getInt();
- if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) {
- stack->pushBool(false);
- } else {
- if (DID_FAIL(_music[channel]->setVolumePercent(volume))) {
- stack->pushBool(false);
- } else {
- stack->pushBool(true);
- }
- }
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // GetMusicVolume / GetMusicChannelVolume
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "GetMusicVolume") == 0 || strcmp(name, "GetMusicChannelVolume") == 0) {
- int channel = 0;
- if (strcmp(name, "GetMusicVolume") == 0) {
- stack->correctParams(0);
- } else {
- stack->correctParams(1);
- channel = stack->pop()->getInt();
- }
-
- if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) {
- stack->pushInt(0);
- } else {
- stack->pushInt(_music[channel]->getVolumePercent());
- }
-
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // MusicCrossfade
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "MusicCrossfade") == 0) {
- stack->correctParams(4);
- int channel1 = stack->pop()->getInt(0);
- int channel2 = stack->pop()->getInt(0);
- uint32 fadeLength = (uint32)stack->pop()->getInt(0);
- bool swap = stack->pop()->getBool(true);
-
- if (_musicCrossfadeRunning) {
- script->runtimeError("Game.MusicCrossfade: Music crossfade is already in progress.");
- stack->pushBool(false);
- return STATUS_OK;
- }
-
- _musicCrossfadeStartTime = _liveTimer;
- _musicCrossfadeChannel1 = channel1;
- _musicCrossfadeChannel2 = channel2;
- _musicCrossfadeLength = fadeLength;
- _musicCrossfadeSwap = swap;
-
- _musicCrossfadeRunning = true;
-
- stack->pushBool(true);
- return STATUS_OK;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // GetSoundLength
- //////////////////////////////////////////////////////////////////////////
- else if (strcmp(name, "GetSoundLength") == 0) {
- stack->correctParams(1);
-
- int length = 0;
- const char *filename = stack->pop()->getString();
-
- BaseSound *sound = new BaseSound(_gameRef);
- if (sound && DID_SUCCEED(sound->setSound(filename, Audio::Mixer::kMusicSoundType, true))) {
- length = sound->getLength();
- delete sound;
- sound = NULL;
- }
- stack->pushInt(length);
+ else if (_musicSystem->scCallMethod(script, stack, thisStack, name) == STATUS_OK) {
return STATUS_OK;
}
@@ -1373,9 +1093,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
int x = stack->pop()->getInt();
int y = stack->pop()->getInt();
x = MAX(x, 0);
- x = MIN(x, _renderer->_width);
+ x = MIN(x, _renderer->getWidth());
y = MAX(y, 0);
- y = MIN(y, _renderer->_height);
+ y = MIN(y, _renderer->getHeight());
Point32 p;
p.x = x + _renderer->_drawOffsetX;
p.y = y + _renderer->_drawOffsetY;
@@ -1431,7 +1151,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
bool freezeMusic = stack->pop()->getBool(true);
ScValue *valSub = stack->pop();
- const char *subtitleFile = valSub->isNULL() ? NULL : valSub->getString();
+ const char *subtitleFile = valSub->isNULL() ? nullptr : valSub->getString();
if (type < (int)VID_PLAY_POS || type > (int)VID_PLAY_CENTER) {
type = (int)VID_PLAY_STRETCH;
@@ -1471,7 +1191,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
bool dropFrames = stack->pop()->getBool(true);
ScValue *valSub = stack->pop();
- const char *subtitleFile = valSub->isNULL() ? NULL : valSub->getString();
+ const char *subtitleFile = valSub->isNULL() ? nullptr : valSub->getString();
if (type < (int)VID_PLAY_POS || type > (int)VID_PLAY_CENTER) {
type = (int)VID_PLAY_STRETCH;
@@ -1490,7 +1210,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
} else {
stack->pushBool(false);
delete _theoraPlayer;
- _theoraPlayer = NULL;
+ _theoraPlayer = nullptr;
}
return STATUS_OK;
@@ -1542,7 +1262,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
stack->correctParams(2);
const char *key = stack->pop()->getString();
const char *val = stack->pop()->getString();
- Common::String privKey = "priv_" + StringUtil::encodeSetting(key);
+ Common::String privKey = "wme_" + StringUtil::encodeSetting(key);
Common::String privVal = StringUtil::encodeSetting(val);
ConfMan.set(privKey, privVal);
stack->pushNULL();
@@ -1556,7 +1276,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
stack->correctParams(2);
const char *key = stack->pop()->getString();
const char *initVal = stack->pop()->getString();
- Common::String privKey = "priv_" + StringUtil::encodeSetting(key);
+ Common::String privKey = "wme_" + StringUtil::encodeSetting(key);
Common::String result = initVal;
if (ConfMan.hasKey(privKey)) {
result = StringUtil::decodeSetting(ConfMan.get(key));
@@ -1755,7 +1475,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "RemoveActiveCursor") == 0) {
stack->correctParams(0);
delete _activeCursor;
- _activeCursor = NULL;
+ _activeCursor = nullptr;
stack->pushNULL();
return STATUS_OK;
@@ -1861,14 +1581,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
fileNum++;
}
- bool ret = false;
- BaseImage *image = _gameRef->_renderer->takeScreenshot();
- if (image) {
- ret = DID_SUCCEED(image->saveBMPFile(filename));
- delete image;
- } else {
- ret = false;
- }
+ bool ret = _gameRef->_renderer->saveScreenShot(filename);
stack->pushBool(ret);
return STATUS_OK;
@@ -1880,20 +1593,10 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "ScreenshotEx") == 0) {
stack->correctParams(3);
const char *filename = stack->pop()->getString();
- int sizeX = stack->pop()->getInt(_renderer->_width);
- int sizeY = stack->pop()->getInt(_renderer->_height);
-
- bool ret = false;
- BaseImage *image = _gameRef->_renderer->takeScreenshot();
- if (image) {
- ret = DID_SUCCEED(image->resize(sizeX, sizeY));
- if (ret) {
- ret = DID_SUCCEED(image->saveBMPFile(filename));
- }
- delete image;
- } else {
- ret = false;
- }
+ int sizeX = stack->pop()->getInt(_renderer->getWidth());
+ int sizeY = stack->pop()->getInt(_renderer->getHeight());
+
+ bool ret = _gameRef->_renderer->saveScreenShot(filename, sizeX, sizeY);
stack->pushBool(ret);
return STATUS_OK;
@@ -2008,7 +1711,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "RemoveWaitCursor") == 0) {
stack->correctParams(0);
delete _cursorNoninteractive;
- _cursorNoninteractive = NULL;
+ _cursorNoninteractive = nullptr;
stack->pushNULL();
@@ -2067,7 +1770,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
_loadingIcon = new BaseSprite(this);
if (!_loadingIcon || DID_FAIL(_loadingIcon->loadFile(filename))) {
delete _loadingIcon;
- _loadingIcon = NULL;
+ _loadingIcon = nullptr;
} else {
displayContent(false, true);
_gameRef->_renderer->flip();
@@ -2084,7 +1787,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "HideLoadingIcon") == 0) {
stack->correctParams(0);
delete _loadingIcon;
- _loadingIcon = NULL;
+ _loadingIcon = nullptr;
stack->pushNULL();
return STATUS_OK;
}
@@ -2121,10 +1824,10 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "StoreSaveThumbnail") == 0) {
stack->correctParams(0);
delete _cachedThumbnail;
- _cachedThumbnail = new BaseSaveThumbHelper(this);
+ _cachedThumbnail = new SaveThumbHelper(this);
if (DID_FAIL(_cachedThumbnail->storeThumbnail())) {
delete _cachedThumbnail;
- _cachedThumbnail = NULL;
+ _cachedThumbnail = nullptr;
stack->pushBool(false);
} else {
stack->pushBool(true);
@@ -2139,7 +1842,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "DeleteSaveThumbnail") == 0) {
stack->correctParams(0);
delete _cachedThumbnail;
- _cachedThumbnail = NULL;
+ _cachedThumbnail = nullptr;
stack->pushNULL();
return STATUS_OK;
@@ -2178,7 +1881,7 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
}
BaseFileManager::getEngineInstance()->closeFile(file);
- file = NULL;
+ file = nullptr;
} else {
stack->pushNULL();
}
@@ -2270,7 +1973,7 @@ ScValue *BaseGame::scGetProperty(const Common::String &name) {
// CurrentTime (RO)
//////////////////////////////////////////////////////////////////////////
else if (name == "CurrentTime") {
- _scValue->setInt((int)_timer);
+ _scValue->setInt((int)getTimer()->getTime());
return _scValue;
}
@@ -2286,7 +1989,7 @@ ScValue *BaseGame::scGetProperty(const Common::String &name) {
// WindowedMode (RO)
//////////////////////////////////////////////////////////////////////////
else if (name == "WindowedMode") {
- _scValue->setBool(_renderer->_windowed);
+ _scValue->setBool(_renderer->isWindowed());
return _scValue;
}
@@ -2326,7 +2029,7 @@ ScValue *BaseGame::scGetProperty(const Common::String &name) {
// ScreenWidth (RO)
//////////////////////////////////////////////////////////////////////////
else if (name == "ScreenWidth") {
- _scValue->setInt(_renderer->_width);
+ _scValue->setInt(_renderer->getWidth());
return _scValue;
}
@@ -2334,7 +2037,7 @@ ScValue *BaseGame::scGetProperty(const Common::String &name) {
// ScreenHeight (RO)
//////////////////////////////////////////////////////////////////////////
else if (name == "ScreenHeight") {
- _scValue->setInt(_renderer->_height);
+ _scValue->setInt(_renderer->getHeight());
return _scValue;
}
@@ -2681,7 +2384,7 @@ bool BaseGame::scSetProperty(const char *name, ScValue *value) {
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "MainObject") == 0) {
BaseScriptable *obj = value->getNative();
- if (obj == NULL || validObject((BaseObject *)obj)) {
+ if (obj == nullptr || validObject((BaseObject *)obj)) {
_mainObject = (BaseObject *)obj;
}
return STATUS_OK;
@@ -2866,8 +2569,8 @@ bool BaseGame::displayQuickMsg() {
// display
for (uint32 i = 0; i < _quickMessages.size(); i++) {
- _systemFont->drawText((byte *)_quickMessages[i]->getText(), 0, posY, _renderer->_width);
- posY += _systemFont->getTextHeight((byte *)_quickMessages[i]->getText(), _renderer->_width);
+ _systemFont->drawText((const byte *)_quickMessages[i]->getText(), 0, posY, _renderer->getWidth());
+ posY += _systemFont->getTextHeight((const byte *)_quickMessages[i]->getText(), _renderer->getWidth());
}
return STATUS_OK;
}
@@ -2917,7 +2620,7 @@ bool BaseGame::unregisterObject(BaseObject *object) {
// get new focused window
if (_focusedWindow == object) {
- _focusedWindow = NULL;
+ _focusedWindow = nullptr;
}
break;
@@ -2926,12 +2629,12 @@ bool BaseGame::unregisterObject(BaseObject *object) {
// is it active object?
if (_activeObject == object) {
- _activeObject = NULL;
+ _activeObject = nullptr;
}
// is it main object?
if (_mainObject == object) {
- _mainObject = NULL;
+ _mainObject = nullptr;
}
// destroy object
@@ -2957,7 +2660,7 @@ void BaseGame::invalidateValues(void *value, void *data) {
if (!val->_persistent && ((BaseScriptable *)data)->_refCount == 1) {
((BaseScriptable *)data)->_refCount++;
}
- val->setNative(NULL);
+ val->setNative(nullptr);
val->setNULL();
}
}
@@ -3298,7 +3001,7 @@ bool BaseGame::saveGame(int slot, const char *desc, bool quickSave) {
//////////////////////////////////////////////////////////////////////////
-bool BaseGame::loadGame(int slot) {
+bool BaseGame::loadGame(uint32 slot) {
//_gameRef->LOG(0, "Load start %d", BaseUtils::GetUsedMemMB());
_loading = false;
@@ -3320,8 +3023,8 @@ bool BaseGame::displayWindows(bool inGame) {
bool res;
// did we lose focus? focus topmost window
- if (_focusedWindow == NULL || !_focusedWindow->_visible || _focusedWindow->_disable) {
- _focusedWindow = NULL;
+ if (_focusedWindow == nullptr || !_focusedWindow->_visible || _focusedWindow->_disable) {
+ _focusedWindow = nullptr;
for (int i = _windows.size() - 1; i >= 0; i--) {
if (_windows[i]->_visible && !_windows[i]->_disable) {
_focusedWindow = _windows[i];
@@ -3344,225 +3047,6 @@ bool BaseGame::displayWindows(bool inGame) {
return STATUS_OK;
}
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseGame::playMusic(int channel, const char *filename, bool looping, uint32 loopStart) {
- if (channel >= NUM_MUSIC_CHANNELS) {
- _gameRef->LOG(0, "**Error** Attempting to use music channel %d (max num channels: %d)", channel, NUM_MUSIC_CHANNELS);
- return STATUS_FAILED;
- }
-
- delete _music[channel];
- _music[channel] = NULL;
-
- _music[channel] = new BaseSound(_gameRef);
- if (_music[channel] && DID_SUCCEED(_music[channel]->setSound(filename, Audio::Mixer::kMusicSoundType, true))) {
- if (_musicStartTime[channel]) {
- _music[channel]->setPositionTime(_musicStartTime[channel]);
- _musicStartTime[channel] = 0;
- }
- if (loopStart) {
- _music[channel]->setLoopStart(loopStart);
- }
- return _music[channel]->play(looping);
- } else {
- delete _music[channel];
- _music[channel] = NULL;
- return STATUS_FAILED;
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseGame::stopMusic(int channel) {
- if (channel >= NUM_MUSIC_CHANNELS) {
- _gameRef->LOG(0, "**Error** Attempting to use music channel %d (max num channels: %d)", channel, NUM_MUSIC_CHANNELS);
- return STATUS_FAILED;
- }
-
- if (_music[channel]) {
- _music[channel]->stop();
- delete _music[channel];
- _music[channel] = NULL;
- return STATUS_OK;
- } else {
- return STATUS_FAILED;
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseGame::pauseMusic(int channel) {
- if (channel >= NUM_MUSIC_CHANNELS) {
- _gameRef->LOG(0, "**Error** Attempting to use music channel %d (max num channels: %d)", channel, NUM_MUSIC_CHANNELS);
- return STATUS_FAILED;
- }
-
- if (_music[channel]) {
- return _music[channel]->pause();
- } else {
- return STATUS_FAILED;
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseGame::resumeMusic(int channel) {
- if (channel >= NUM_MUSIC_CHANNELS) {
- _gameRef->LOG(0, "**Error** Attempting to use music channel %d (max num channels: %d)", channel, NUM_MUSIC_CHANNELS);
- return STATUS_FAILED;
- }
-
- if (_music[channel]) {
- return _music[channel]->resume();
- } else {
- return STATUS_FAILED;
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseGame::setMusicStartTime(int channel, uint32 time) {
- if (channel >= NUM_MUSIC_CHANNELS) {
- _gameRef->LOG(0, "**Error** Attempting to use music channel %d (max num channels: %d)", channel, NUM_MUSIC_CHANNELS);
- return STATUS_FAILED;
- }
-
- _musicStartTime[channel] = time;
- if (_music[channel] && _music[channel]->isPlaying()) {
- return _music[channel]->setPositionTime(time);
- } else {
- return STATUS_OK;
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-bool BaseGame::loadSettings(const char *filename) {
- TOKEN_TABLE_START(commands)
- TOKEN_TABLE(SETTINGS)
- TOKEN_TABLE(GAME)
- TOKEN_TABLE(STRING_TABLE)
- TOKEN_TABLE(RESOLUTION)
- TOKEN_TABLE(REQUIRE_3D_ACCELERATION)
- TOKEN_TABLE(REQUIRE_SOUND)
- TOKEN_TABLE(HWTL_MODE)
- TOKEN_TABLE(ALLOW_WINDOWED_MODE)
- TOKEN_TABLE(ALLOW_ACCESSIBILITY_TAB)
- TOKEN_TABLE(ALLOW_ABOUT_TAB)
- TOKEN_TABLE(ALLOW_ADVANCED)
- TOKEN_TABLE(ALLOW_DESKTOP_RES)
- TOKEN_TABLE(REGISTRY_PATH)
- TOKEN_TABLE(RICH_SAVED_GAMES)
- TOKEN_TABLE(SAVED_GAME_EXT)
- TOKEN_TABLE(GUID)
- TOKEN_TABLE_END
-
-
- byte *origBuffer = BaseFileManager::getEngineInstance()->readWholeFile(filename);
- if (origBuffer == NULL) {
- _gameRef->LOG(0, "BaseGame::LoadSettings failed for file '%s'", filename);
- return STATUS_FAILED;
- }
-
- bool ret = STATUS_OK;
-
- byte *buffer = origBuffer;
- byte *params;
- int cmd;
- BaseParser parser;
-
- if (parser.getCommand((char **)&buffer, commands, (char **)&params) != TOKEN_SETTINGS) {
- _gameRef->LOG(0, "'SETTINGS' keyword expected in game settings file.");
- return STATUS_FAILED;
- }
- buffer = params;
- while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)&params)) > 0) {
- switch (cmd) {
- case TOKEN_GAME:
- delete[] _settingsGameFile;
- _settingsGameFile = new char[strlen((char *)params) + 1];
- if (_settingsGameFile) {
- strcpy(_settingsGameFile, (char *)params);
- }
- break;
-
- case TOKEN_STRING_TABLE:
- if (DID_FAIL(_stringTable->loadFile((char *)params))) {
- cmd = PARSERR_GENERIC;
- }
- break;
-
- case TOKEN_RESOLUTION:
- parser.scanStr((char *)params, "%d,%d", &_settingsResWidth, &_settingsResHeight);
- break;
-
- case TOKEN_REQUIRE_3D_ACCELERATION:
- parser.scanStr((char *)params, "%b", &_settingsRequireAcceleration);
- break;
-
- case TOKEN_REQUIRE_SOUND:
- parser.scanStr((char *)params, "%b", &_settingsRequireSound);
- break;
-
- case TOKEN_HWTL_MODE:
- parser.scanStr((char *)params, "%d", &_settingsTLMode);
- break;
-
- case TOKEN_ALLOW_WINDOWED_MODE:
- parser.scanStr((char *)params, "%b", &_settingsAllowWindowed);
- break;
-
- case TOKEN_ALLOW_DESKTOP_RES:
- parser.scanStr((char *)params, "%b", &_settingsAllowDesktopRes);
- break;
-
- case TOKEN_ALLOW_ADVANCED:
- parser.scanStr((char *)params, "%b", &_settingsAllowAdvanced);
- break;
-
- case TOKEN_ALLOW_ACCESSIBILITY_TAB:
- parser.scanStr((char *)params, "%b", &_settingsAllowAccessTab);
- break;
-
- case TOKEN_ALLOW_ABOUT_TAB:
- parser.scanStr((char *)params, "%b", &_settingsAllowAboutTab);
- break;
-
- case TOKEN_REGISTRY_PATH:
- //BaseEngine::instance().getRegistry()->setBasePath((char *)params);
- break;
-
- case TOKEN_RICH_SAVED_GAMES:
- parser.scanStr((char *)params, "%b", &_richSavedGames);
- break;
-
- case TOKEN_SAVED_GAME_EXT:
- BaseUtils::setString(&_savedGameExt, (char *)params);
- break;
-
- case TOKEN_GUID:
- break;
- }
- }
- if (cmd == PARSERR_TOKENNOTFOUND) {
- _gameRef->LOG(0, "Syntax error in game settings '%s'", filename);
- ret = STATUS_FAILED;
- }
- if (cmd == PARSERR_GENERIC) {
- _gameRef->LOG(0, "Error loading game settings '%s'", filename);
- ret = STATUS_FAILED;
- }
-
- _settingsAllowWindowed = true; // TODO: These two settings should probably be cleaned out altogether.
- _compressedSavegames = true;
-
- delete[] origBuffer;
-
- return ret;
-}
-
-
//////////////////////////////////////////////////////////////////////////
bool BaseGame::persist(BasePersistenceManager *persistMgr) {
if (!persistMgr->getIsSaving()) {
@@ -3583,10 +3067,8 @@ bool BaseGame::persist(BasePersistenceManager *persistMgr) {
persistMgr->transfer(TMEMBER(_keyboardState));
persistMgr->transfer(TMEMBER(_lastTime));
persistMgr->transfer(TMEMBER(_mainObject));
- for (int i = 0; i < NUM_MUSIC_CHANNELS; i++) {
- persistMgr->transfer(TMEMBER(_music[i]));
- persistMgr->transfer(TMEMBER(_musicStartTime[i]));
- }
+ _musicSystem->persistChannels(persistMgr);
+ _musicSystem->persistCrossfadeSettings(persistMgr);
persistMgr->transfer(TMEMBER(_offsetX));
persistMgr->transfer(TMEMBER(_offsetY));
@@ -3610,20 +3092,8 @@ bool BaseGame::persist(BasePersistenceManager *persistMgr) {
persistMgr->transfer(TMEMBER(_videoFont));
persistMgr->transfer(TMEMBER(_videoSubtitles));
- persistMgr->transfer(TMEMBER(_timer));
- persistMgr->transfer(TMEMBER(_timerDelta));
- persistMgr->transfer(TMEMBER(_timerLast));
-
- persistMgr->transfer(TMEMBER(_liveTimer));
- persistMgr->transfer(TMEMBER(_liveTimerDelta));
- persistMgr->transfer(TMEMBER(_liveTimerLast));
-
- persistMgr->transfer(TMEMBER(_musicCrossfadeRunning));
- persistMgr->transfer(TMEMBER(_musicCrossfadeStartTime));
- persistMgr->transfer(TMEMBER(_musicCrossfadeLength));
- persistMgr->transfer(TMEMBER(_musicCrossfadeChannel1));
- persistMgr->transfer(TMEMBER(_musicCrossfadeChannel2));
- persistMgr->transfer(TMEMBER(_musicCrossfadeSwap));
+ _timerNormal.persist(persistMgr);
+ _timerLive.persist(persistMgr);
_renderer->persistSaveLoadImages(persistMgr);
@@ -3729,7 +3199,7 @@ bool BaseGame::handleKeypress(Common::Event *event, bool printable) {
// TODO
if (_focusedWindow) {
- if (!_gameRef->_focusedWindow->handleKeypress(event, _keyboardState->_currentPrintable)) {
+ if (!_gameRef->_focusedWindow->handleKeypress(event, _keyboardState->isCurrentPrintable())) {
/*if (event->type != SDL_TEXTINPUT) {*/
if (_gameRef->_focusedWindow->canHandleEvent("Keypress")) {
_gameRef->_focusedWindow->applyEvent("Keypress");
@@ -3753,7 +3223,7 @@ void BaseGame::handleKeyRelease(Common::Event *event) {
//////////////////////////////////////////////////////////////////////////
-bool BaseGame::handleMouseWheel(int delta) {
+bool BaseGame::handleMouseWheel(int32 delta) {
bool handled = false;
if (_focusedWindow) {
handled = _gameRef->_focusedWindow->handleMouseWheel(delta);
@@ -3783,7 +3253,7 @@ bool BaseGame::handleMouseWheel(int delta) {
//////////////////////////////////////////////////////////////////////////
-bool BaseGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) {
+bool BaseGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) const {
if (verMajor) {
*verMajor = DCGF_VER_MAJOR;
}
@@ -3806,11 +3276,11 @@ bool BaseGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *
void BaseGame::setWindowTitle() {
if (_renderer) {
char title[512];
- strcpy(title, _caption[0]);
+ Common::strlcpy(title, _caption[0], 512);
if (title[0] != '\0') {
- strcat(title, " - ");
+ Common::strlcat(title, " - ", 512);
}
- strcat(title, "WME Lite");
+ Common::strlcat(title, "WME Lite", 512);
Utf8String utf8Title;
@@ -3831,7 +3301,7 @@ void BaseGame::setWindowTitle() {
bool BaseGame::setActiveObject(BaseObject *obj) {
// not-active when game is frozen
if (obj && !_gameRef->_interactive && !obj->_nonIntMouseEvents) {
- obj = NULL;
+ obj = nullptr;
}
if (obj == _activeObject) {
@@ -3877,16 +3347,16 @@ bool BaseGame::popViewport() {
_renderer->setViewport(_viewportStack[_viewportSP]->getRect());
} else _renderer->setViewport(_renderer->_drawOffsetX,
_renderer->_drawOffsetY,
- _renderer->_width + _renderer->_drawOffsetX,
- _renderer->_height + _renderer->_drawOffsetY);
+ _renderer->getWidth() + _renderer->_drawOffsetX,
+ _renderer->getHeight() + _renderer->_drawOffsetY);
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
-bool BaseGame::getCurrentViewportRect(Rect32 *rect, bool *custom) {
- if (rect == NULL) {
+bool BaseGame::getCurrentViewportRect(Rect32 *rect, bool *custom) const {
+ if (rect == nullptr) {
return STATUS_FAILED;
} else {
if (_viewportSP >= 0) {
@@ -3897,8 +3367,8 @@ bool BaseGame::getCurrentViewportRect(Rect32 *rect, bool *custom) {
} else {
BasePlatform::setRect(rect, _renderer->_drawOffsetX,
_renderer->_drawOffsetY,
- _renderer->_width + _renderer->_drawOffsetX,
- _renderer->_height + _renderer->_drawOffsetY);
+ _renderer->getWidth() + _renderer->_drawOffsetX,
+ _renderer->getHeight() + _renderer->_drawOffsetY);
if (custom) {
*custom = false;
}
@@ -3910,7 +3380,7 @@ bool BaseGame::getCurrentViewportRect(Rect32 *rect, bool *custom) {
//////////////////////////////////////////////////////////////////////////
-bool BaseGame::getCurrentViewportOffset(int *offsetX, int *offsetY) {
+bool BaseGame::getCurrentViewportOffset(int *offsetX, int *offsetY) const {
if (_viewportSP >= 0) {
if (offsetX) {
*offsetX = _viewportStack[_viewportSP]->_offsetX;
@@ -3978,69 +3448,6 @@ bool BaseGame::displayContentSimple() {
}
//////////////////////////////////////////////////////////////////////////
-bool BaseGame::updateMusicCrossfade() {
- /* byte globMusicVol = _soundMgr->getVolumePercent(SOUND_MUSIC); */
-
- if (!_musicCrossfadeRunning) {
- return STATUS_OK;
- }
- if (_state == GAME_FROZEN) {
- return STATUS_OK;
- }
-
- if (_musicCrossfadeChannel1 < 0 || _musicCrossfadeChannel1 >= NUM_MUSIC_CHANNELS || !_music[_musicCrossfadeChannel1]) {
- _musicCrossfadeRunning = false;
- return STATUS_OK;
- }
- if (_musicCrossfadeChannel2 < 0 || _musicCrossfadeChannel2 >= NUM_MUSIC_CHANNELS || !_music[_musicCrossfadeChannel2]) {
- _musicCrossfadeRunning = false;
- return STATUS_OK;
- }
-
- if (!_music[_musicCrossfadeChannel1]->isPlaying()) {
- _music[_musicCrossfadeChannel1]->play();
- }
- if (!_music[_musicCrossfadeChannel2]->isPlaying()) {
- _music[_musicCrossfadeChannel2]->play();
- }
-
- uint32 currentTime = _gameRef->_liveTimer - _musicCrossfadeStartTime;
-
- if (currentTime >= _musicCrossfadeLength) {
- _musicCrossfadeRunning = false;
- //_music[_musicCrossfadeChannel2]->setVolume(GlobMusicVol);
- _music[_musicCrossfadeChannel2]->setVolumePercent(100);
-
- _music[_musicCrossfadeChannel1]->stop();
- //_music[_musicCrossfadeChannel1]->setVolume(GlobMusicVol);
- _music[_musicCrossfadeChannel1]->setVolumePercent(100);
-
-
- if (_musicCrossfadeSwap) {
- // swap channels
- BaseSound *dummy = _music[_musicCrossfadeChannel1];
- int dummyInt = _musicStartTime[_musicCrossfadeChannel1];
-
- _music[_musicCrossfadeChannel1] = _music[_musicCrossfadeChannel2];
- _musicStartTime[_musicCrossfadeChannel1] = _musicStartTime[_musicCrossfadeChannel2];
-
- _music[_musicCrossfadeChannel2] = dummy;
- _musicStartTime[_musicCrossfadeChannel2] = dummyInt;
- }
- } else {
- //_music[_musicCrossfadeChannel1]->setVolume(GlobMusicVol - (float)CurrentTime / (float)_musicCrossfadeLength * GlobMusicVol);
- //_music[_musicCrossfadeChannel2]->setVolume((float)CurrentTime / (float)_musicCrossfadeLength * GlobMusicVol);
- _music[_musicCrossfadeChannel1]->setVolumePercent((int)(100.0f - (float)currentTime / (float)_musicCrossfadeLength * 100.0f));
- _music[_musicCrossfadeChannel2]->setVolumePercent((int)((float)currentTime / (float)_musicCrossfadeLength * 100.0f));
-
- //_gameRef->QuickMessageForm("%d %d", _music[_musicCrossfadeChannel1]->GetVolume(), _music[_musicCrossfadeChannel2]->GetVolume());
- }
-
- return STATUS_OK;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
bool BaseGame::resetContent() {
_scEngine->clearGlobals();
//_timer = 0;
@@ -4083,12 +3490,12 @@ bool BaseGame::restoreDeviceObjects() {
//////////////////////////////////////////////////////////////////////////
bool BaseGame::setWaitCursor(const char *filename) {
delete _cursorNoninteractive;
- _cursorNoninteractive = NULL;
+ _cursorNoninteractive = nullptr;
_cursorNoninteractive = new BaseSprite(_gameRef);
if (!_cursorNoninteractive || DID_FAIL(_cursorNoninteractive->loadFile(filename))) {
delete _cursorNoninteractive;
- _cursorNoninteractive = NULL;
+ _cursorNoninteractive = nullptr;
return STATUS_FAILED;
} else {
return STATUS_OK;
@@ -4114,7 +3521,7 @@ bool BaseGame::stopVideo() {
if (_theoraPlayer && _theoraPlayer->isPlaying()) {
_theoraPlayer->stop();
delete _theoraPlayer;
- _theoraPlayer = NULL;
+ _theoraPlayer = nullptr;
}
return STATUS_OK;
}
@@ -4165,12 +3572,12 @@ bool BaseGame::onMouseLeftDown() {
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("LeftClick");
}
}
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_capturedObject = _activeObject;
}
_mouseLeftDown = true;
@@ -4186,12 +3593,12 @@ bool BaseGame::onMouseLeftUp() {
}
BasePlatform::releaseCapture();
- _capturedObject = NULL;
+ _capturedObject = nullptr;
_mouseLeftDown = false;
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftRelease"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("LeftRelease");
}
}
@@ -4210,7 +3617,7 @@ bool BaseGame::onMouseLeftDblClick() {
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("LeftDoubleClick");
}
}
@@ -4229,7 +3636,7 @@ bool BaseGame::onMouseRightDblClick() {
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightDoubleClick"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("RightDoubleClick");
}
}
@@ -4244,7 +3651,7 @@ bool BaseGame::onMouseRightDown() {
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("RightClick");
}
}
@@ -4259,7 +3666,7 @@ bool BaseGame::onMouseRightUp() {
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("RightRelease");
}
}
@@ -4278,7 +3685,7 @@ bool BaseGame::onMouseMiddleDown() {
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("MiddleClick"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("MiddleClick");
}
}
@@ -4293,7 +3700,7 @@ bool BaseGame::onMouseMiddleUp() {
bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("MiddleRelease"));
if (!handled) {
- if (_activeObject != NULL) {
+ if (_activeObject != nullptr) {
_activeObject->applyEvent("MiddleRelease");
}
}
@@ -4302,7 +3709,7 @@ bool BaseGame::onMouseMiddleUp() {
//////////////////////////////////////////////////////////////////////////
bool BaseGame::onPaint() {
- if (_renderer && _renderer->_windowed && _renderer->_ready) {
+ if (_renderer && _renderer->isWindowed() && _renderer->isReady()) {
_renderer->initLoop();
displayContent(false, true);
displayDebugInfo();
@@ -4325,42 +3732,43 @@ bool BaseGame::onWindowClose() {
//////////////////////////////////////////////////////////////////////////
bool BaseGame::displayDebugInfo() {
- char str[100];
-
+ const uint32 strLength = 100;
+ char str[strLength];
+
if (_debugShowFPS) {
sprintf(str, "FPS: %d", _gameRef->_fps);
_systemFont->drawText((byte *)str, 0, 0, 100, TAL_LEFT);
}
if (_gameRef->_debugDebugMode) {
- if (!_gameRef->_renderer->_windowed) {
- sprintf(str, "Mode: %dx%dx%d", _renderer->_width, _renderer->_height, _renderer->_bPP);
+ if (!_gameRef->_renderer->isWindowed()) {
+ sprintf(str, "Mode: %dx%dx%d", _renderer->getWidth(), _renderer->getHeight(), _renderer->getBPP());
} else {
- sprintf(str, "Mode: %dx%d windowed", _renderer->_width, _renderer->_height);
+ sprintf(str, "Mode: %dx%d windowed", _renderer->getWidth(), _renderer->getHeight());
}
- strcat(str, " (");
- strcat(str, _renderer->getName().c_str());
- strcat(str, ")");
- _systemFont->drawText((byte *)str, 0, 0, _renderer->_width, TAL_RIGHT);
+ Common::strlcat(str, " (", strLength);
+ Common::strlcat(str, _renderer->getName().c_str(), strLength);
+ Common::strlcat(str, ")", strLength);
+ _systemFont->drawText((byte *)str, 0, 0, _renderer->getWidth(), TAL_RIGHT);
_renderer->displayDebugInfo();
int scrTotal, scrRunning, scrWaiting, scrPersistent;
scrTotal = _scEngine->getNumScripts(&scrRunning, &scrWaiting, &scrPersistent);
sprintf(str, "Running scripts: %d (r:%d w:%d p:%d)", scrTotal, scrRunning, scrWaiting, scrPersistent);
- _systemFont->drawText((byte *)str, 0, 70, _renderer->_width, TAL_RIGHT);
+ _systemFont->drawText((byte *)str, 0, 70, _renderer->getWidth(), TAL_RIGHT);
- sprintf(str, "Timer: %d", _timer);
- _gameRef->_systemFont->drawText((byte *)str, 0, 130, _renderer->_width, TAL_RIGHT);
+ sprintf(str, "Timer: %d", getTimer()->getTime());
+ _gameRef->_systemFont->drawText((byte *)str, 0, 130, _renderer->getWidth(), TAL_RIGHT);
- if (_activeObject != NULL) {
- _systemFont->drawText((const byte *)_activeObject->getName(), 0, 150, _renderer->_width, TAL_RIGHT);
+ if (_activeObject != nullptr) {
+ _systemFont->drawText((const byte *)_activeObject->getName(), 0, 150, _renderer->getWidth(), TAL_RIGHT);
}
sprintf(str, "GfxMem: %dMB", _usedMem / (1024 * 1024));
- _systemFont->drawText((byte *)str, 0, 170, _renderer->_width, TAL_RIGHT);
+ _systemFont->drawText((byte *)str, 0, 170, _renderer->getWidth(), TAL_RIGHT);
}
@@ -4471,7 +3879,7 @@ void BaseGame::autoSaveOnExit() {
}
//////////////////////////////////////////////////////////////////////////
-void BaseGame::addMem(int bytes) {
+void BaseGame::addMem(int32 bytes) {
_usedMem += bytes;
}
@@ -4480,4 +3888,18 @@ AnsiString BaseGame::getDeviceType() const {
return "computer";
}
+//////////////////////////////////////////////////////////////////////////
+bool BaseGame::loadSettings(const char *filename) {
+ return _settings->loadSettings(filename);
+}
+
+//////////////////////////////////////////////////////////////////////////
+void BaseGame::expandStringByStringTable(char **str) const {
+ _settings->expandStringByStringTable(str);
+}
+
+char *BaseGame::getKeyFromStringTable(const char *str) const {
+ return _settings->getKeyFromStringTable(str);
+}
+
} // end of namespace Wintermute