aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
authorTorbjörn Andersson2004-11-15 08:22:16 +0000
committerTorbjörn Andersson2004-11-15 08:22:16 +0000
commit38baf0a0d303110958e63e7f9875d3254aaa2499 (patch)
tree4a276e3dbbf832e25d6147962a1359713b59dd6b /sword2
parent455d2a127a841dc832a0adbd161db8e4bddca99b (diff)
downloadscummvm-rg350-38baf0a0d303110958e63e7f9875d3254aaa2499.tar.gz
scummvm-rg350-38baf0a0d303110958e63e7f9875d3254aaa2499.tar.bz2
scummvm-rg350-38baf0a0d303110958e63e7f9875d3254aaa2499.zip
I think this is the kind of constructor/go changes _sev was talking about
in his mail to scummvm-devel. (Though "a discussed a while ago change" sounds like sort of thing Robert Jordan writes whenever there is danger of anything actually happening in any of his more recent books. Tantalizing, yet non-informative. ;-) It's still rather messy. I'll look into cleaning it up later. svn-id: r15818
Diffstat (limited to 'sword2')
-rw-r--r--sword2/save_rest.cpp8
-rw-r--r--sword2/sword2.cpp355
-rw-r--r--sword2/sword2.h98
3 files changed, 233 insertions, 228 deletions
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index 0f2a6e74a5..622296e1ec 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -163,7 +163,7 @@ void Sword2Engine::fillSaveBuffer(byte *buffer, uint32 size, byte *desc) {
uint32 Sword2Engine::saveData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
char saveFileName[MAX_FILENAME_LEN];
- sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
SaveFile *out;
@@ -210,7 +210,7 @@ uint32 Sword2Engine::restoreGame(uint16 slotNo) {
uint32 Sword2Engine::restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
char saveFileName[MAX_FILENAME_LEN];
- sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
SaveFile *in;
@@ -355,7 +355,7 @@ uint32 Sword2Engine::restoreFromBuffer(byte *buffer, uint32 size) {
uint32 Sword2Engine::getSaveDescription(uint16 slotNo, byte *description) {
char saveFileName[MAX_FILENAME_LEN];
- sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
SaveFile *in;
@@ -382,7 +382,7 @@ bool Sword2Engine::saveExists(void) {
bool Sword2Engine::saveExists(uint16 slotNo) {
char saveFileName[MAX_FILENAME_LEN];
- sprintf(saveFileName, "%s.%.3d", _targetName, slotNo);
+ sprintf(saveFileName, "%s.%.3d", _targetName.c_str(), slotNo);
SaveFile *in;
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index 941c6a36d9..fdde1d7ea7 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -102,9 +102,7 @@ namespace Sword2 {
Sword2Engine *g_sword2 = NULL;
-Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
- : Engine(syst) {
-
+Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst) {
// Add default file directories
File::addDefaultDirectory(_gameDataPath + "CLUSTERS/");
File::addDefaultDirectory(_gameDataPath + "SWORD2/");
@@ -118,43 +116,15 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
_sound = NULL;
_graphics = NULL;
_features = detector->_game.features;
- _targetName = strdup(detector->_targetName.c_str());
+ _targetName = detector->_targetName;
_bootParam = ConfMan.getInt("boot_param");
_saveSlot = ConfMan.getInt("save_slot");
- // Setup mixer
- if (!_mixer->isReady())
- warning("Sound initialization failed");
-
- // We have our own volume settings panel, so don't let ScummVM's mixer
- // soften the sound in any way.
-
- _mixer->setVolume(256);
-
_keyboardEvent.pending = false;
_mouseEvent.pending = false;
_mouseX = _mouseY = 0;
- // get some falling RAM and put it in your pocket, never let it slip
- // away
-
- _graphics = new Graphics(this, 640, 480);
-
- // Create the debugger as early as possible (but not before the
- // graphics object!) so that errors can be displayed in it. In
- // particular, we want errors about missing files to be clearly
- // visible to the user.
-
- _debugger = new Debugger(this);
-
- _memory = new MemoryManager(this);
- _resman = new ResourceManager(this);
- _logic = new Logic(this);
- _fontRenderer = new FontRenderer(this);
- _gui = new Gui(this);
- _sound = new Sound(this);
-
_lastPaletteRes = 0;
_largestLayerArea = 0;
@@ -176,9 +146,7 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
_totalMasters = 0;
memset(_masterMenuList, 0, sizeof(_masterMenuList));
-
memset(&_thisScreen, 0, sizeof(_thisScreen));
-
memset(_mouseList, 0, sizeof(_mouseList));
_mouseTouching = 0;
@@ -202,10 +170,20 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
_gamePaused = false;
_stepOneCycle = false;
_graphicsLevelFudged = false;
+
+ _debugger = NULL;
+ _graphics = NULL;
+ _sound = NULL;
+ _gui = NULL;
+ _fontRenderer = NULL;
+ _logic = NULL;
+ _resman = NULL;
+ _memory = NULL;
+
+ _quit = false;
}
Sword2Engine::~Sword2Engine() {
- free(_targetName);
delete _debugger;
delete _graphics;
delete _sound;
@@ -239,12 +217,40 @@ void Sword2Engine::errorString(const char *buf1, char *buf2) {
* the game, so that they are never expelled by the resource manager.
*/
-void Sword2Engine::setupPersistentResources(void) {
+void Sword2Engine::setupPersistentResources() {
Logic::_scriptVars = (uint32 *) (_resman->openResource(1) + sizeof(StandardHeader));
_resman->openResource(CUR_PLAYER_ID);
}
-int32 Sword2Engine::initialiseGame(void) {
+void Sword2Engine::mainInit() {
+ // get some falling RAM and put it in your pocket, never let it slip
+ // away
+
+ _graphics = new Graphics(this, 640, 480);
+
+ // Create the debugger as early as possible (but not before the
+ // graphics object!) so that errors can be displayed in it. In
+ // particular, we want errors about missing files to be clearly
+ // visible to the user.
+
+ _debugger = new Debugger(this);
+
+ _memory = new MemoryManager(this);
+ _resman = new ResourceManager(this);
+ _logic = new Logic(this);
+ _fontRenderer = new FontRenderer(this);
+ _gui = new Gui(this);
+ _sound = new Sound(this);
+
+ // Setup mixer
+ if (!_mixer->isReady())
+ warning("Sound initialization failed");
+
+ // We have our own volume settings panel, so don't let ScummVM's mixer
+ // soften the sound in any way.
+
+ _mixer->setVolume(256);
+
// During normal gameplay, we care neither about mouse button releases
// nor the scroll wheel.
setEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN);
@@ -268,18 +274,144 @@ int32 Sword2Engine::initialiseGame(void) {
else
Logic::_scriptVars[DEMO] = 0;
- return 0;
+ debug(5, "CALLING: readOptionSettings");
+ _gui->readOptionSettings();
+
+ if (_saveSlot != -1) {
+ if (saveExists(_saveSlot))
+ restoreGame(_saveSlot);
+ else {
+ setMouse(NORMAL_MOUSE_ID);
+ if (!_gui->restoreControl())
+ startGame();
+ }
+ } else if (!_bootParam && saveExists()) {
+ int32 pars[2] = { 221, FX_LOOP };
+ bool result;
+
+ setMouse(NORMAL_MOUSE_ID);
+ _logic->fnPlayMusic(pars);
+ result = _gui->startControl();
+
+ // If the game is started from the beginning, the cutscene
+ // player will kill the music for us. Otherwise, the restore
+ // will either have killed the music, or done a crossfade.
+
+ if (_quit)
+ return;
+
+ if (result)
+ startGame();
+ } else
+ startGame();
+
+ debug(5, "CALLING: initialiseRenderCycle");
+ _graphics->initialiseRenderCycle();
+
+ _renderSkip = false; // Toggled on 'S' key, to render only
+ // 1 in 4 frames, to speed up game
+
+ _gameCycle = 0;
+}
+
+void Sword2Engine::mainRun() {
+ while (1) {
+ if (_debugger->isAttached())
+ _debugger->onFrame();
+
+ // the screen is build. Mostly because of first scroll
+ // cycle stuff
+
+#ifdef _SWORD2_DEBUG
+ // if we've just stepped forward one cycle while the
+ // game was paused
+
+ if (_stepOneCycle) {
+ pauseGame();
+ _stepOneCycle = false;
+ }
+#endif
+
+ KeyboardEvent *ke = keyboardEvent();
+
+ if (ke) {
+ if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') {
+ _debugger->attach();
+ } else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) {
+ switch (ke->keycode) {
+ case 'p':
+ if (_gamePaused)
+ unpauseGame();
+ else
+ pauseGame();
+ break;
+ case 'c':
+ if (!Logic::_scriptVars[DEMO] && !_logic->_choosing)
+ _logic->fnPlayCredits(NULL);
+ break;
+#ifdef _SWORD2_DEBUG
+ case ' ':
+ if (_gamePaused) {
+ _stepOneCycle = true;
+ unpauseGame();
+ }
+ break;
+ case 's':
+ _renderSkip = !_renderSkip;
+ break;
+#endif
+ default:
+ break;
+ }
+ }
+ }
+
+ // skip GameCycle if we're paused
+ if (!_gamePaused) {
+ _gameCycle++;
+ gameCycle();
+ }
+
+ // We can't use this as termination condition for the looop,
+ // because we want the break to happen before updating the
+ // screen again.
+
+ if (_quit)
+ break;
+
+ // creates the debug text blocks
+ _debugger->buildDebugText();
+
+#ifdef _SWORD2_DEBUG
+ // if not in console & '_renderSkip' is set, only render
+ // display once every 4 game-cycles
+
+ if (console_status || !_renderSkip || (_gameCycle % 4) == 0)
+ buildDisplay(); // create and flip the screen
+#else
+ // create and flip the screen
+ buildDisplay();
+#endif
+ }
+}
+
+void Sword2Engine::go() {
+ mainInit();
+ mainRun();
+
+ // Stop music instantly!
+ killMusic();
}
-void Sword2Engine::closeGame(void) {
+void Sword2Engine::closeGame() {
_quit = true;
}
-bool Sword2Engine::checkForMouseEvents(void) {
+bool Sword2Engine::checkForMouseEvents() {
return _mouseEvent.pending;
}
-MouseEvent *Sword2Engine::mouseEvent(void) {
+MouseEvent *Sword2Engine::mouseEvent() {
if (!_mouseEvent.pending)
return NULL;
@@ -287,7 +419,7 @@ MouseEvent *Sword2Engine::mouseEvent(void) {
return &_mouseEvent;
}
-KeyboardEvent *Sword2Engine::keyboardEvent(void) {
+KeyboardEvent *Sword2Engine::keyboardEvent() {
if (!_keyboardEvent.pending)
return NULL;
@@ -306,7 +438,7 @@ uint32 Sword2Engine::setEventFilter(uint32 filter) {
* OSystem Event Handler. Full of cross platform goodness and 99% fat free!
*/
-void Sword2Engine::parseEvents(void) {
+void Sword2Engine::parseEvents() {
OSystem::Event event;
while (_system->pollEvent(event)) {
@@ -370,7 +502,7 @@ void Sword2Engine::parseEvents(void) {
}
}
-void Sword2Engine::gameCycle(void) {
+void Sword2Engine::gameCycle() {
// do one game cycle
// got a screen to run?
@@ -401,136 +533,7 @@ void Sword2Engine::gameCycle(void) {
processFxQueue();
}
-void Sword2Engine::go() {
- _quit = false;
-
- debug(5, "CALLING: readOptionSettings");
- _gui->readOptionSettings();
-
- debug(5, "CALLING: initialiseGame");
- if (initialiseGame())
- return;
-
- if (_saveSlot != -1) {
- if (saveExists(_saveSlot))
- restoreGame(_saveSlot);
- else {
- setMouse(NORMAL_MOUSE_ID);
- if (!_gui->restoreControl())
- startGame();
- }
- } else if (!_bootParam && saveExists()) {
- int32 pars[2] = { 221, FX_LOOP };
- bool result;
-
- setMouse(NORMAL_MOUSE_ID);
- _logic->fnPlayMusic(pars);
- result = _gui->startControl();
-
- // If the game is started from the beginning, the cutscene
- // player will kill the music for us. Otherwise, the restore
- // will either have killed the music, or done a crossfade.
-
- if (_quit)
- return;
-
- if (result)
- startGame();
- } else
- startGame();
-
- debug(5, "CALLING: initialiseRenderCycle");
- _graphics->initialiseRenderCycle();
-
- _renderSkip = false; // Toggled on 'S' key, to render only
- // 1 in 4 frames, to speed up game
-
- _gameCycle = 0;
-
- while (1) {
- if (_debugger->isAttached())
- _debugger->onFrame();
-
- // the screen is build. Mostly because of first scroll
- // cycle stuff
-
-#ifdef _SWORD2_DEBUG
- // if we've just stepped forward one cycle while the
- // game was paused
-
- if (_stepOneCycle) {
- pauseGame();
- _stepOneCycle = false;
- }
-#endif
-
- KeyboardEvent *ke = keyboardEvent();
-
- if (ke) {
- if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') {
- _debugger->attach();
- } else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) {
- switch (ke->keycode) {
- case 'p':
- if (_gamePaused)
- unpauseGame();
- else
- pauseGame();
- break;
- case 'c':
- if (!Logic::_scriptVars[DEMO] && !_logic->_choosing)
- _logic->fnPlayCredits(NULL);
- break;
-#ifdef _SWORD2_DEBUG
- case ' ':
- if (_gamePaused) {
- _stepOneCycle = true;
- unpauseGame();
- }
- break;
- case 's':
- _renderSkip = !_renderSkip;
- break;
-#endif
- default:
- break;
- }
- }
- }
-
- // skip GameCycle if we're paused
- if (!_gamePaused) {
- _gameCycle++;
- gameCycle();
- }
-
- // We can't use this as termination condition for the looop,
- // because we want the break to happen before updating the
- // screen again.
-
- if (_quit)
- break;
-
- // creates the debug text blocks
- _debugger->buildDebugText();
-
-#ifdef _SWORD2_DEBUG
- // if not in console & '_renderSkip' is set, only render
- // display once every 4 game-cycles
-
- if (console_status || !_renderSkip || (_gameCycle % 4) == 0)
- buildDisplay(); // create and flip the screen
-#else
- // create and flip the screen
- buildDisplay();
-#endif
- }
-
- // Stop music instantly!
- killMusic();
-}
-
-void Sword2Engine::startGame(void) {
+void Sword2Engine::startGame() {
// boot the game straight into a start script
int screen_manager_id;
@@ -587,7 +590,7 @@ void Sword2Engine::sleepUntil(uint32 time) {
}
}
-void Sword2Engine::pauseGame(void) {
+void Sword2Engine::pauseGame() {
// don't allow Pause while screen fading or while black
if (_graphics->getFadeStatus() != RDFADE_NONE)
return;
@@ -623,7 +626,7 @@ void Sword2Engine::pauseGame(void) {
_gamePaused = true;
}
-void Sword2Engine::unpauseGame(void) {
+void Sword2Engine::unpauseGame() {
if (Logic::_scriptVars[OBJECT_HELD] && _realLuggageItem)
setLuggage(_realLuggageItem);
diff --git a/sword2/sword2.h b/sword2/sword2.h
index 747b3f22d9..48cd345149 100644
--- a/sword2/sword2.h
+++ b/sword2/sword2.h
@@ -138,28 +138,28 @@ private:
uint32 _lastPaletteRes;
- void drawBackPar0Frames(void);
- void drawBackPar1Frames(void);
- void drawBackFrames(void);
+ void drawBackPar0Frames();
+ void drawBackPar1Frames();
+ void drawBackFrames();
void drawSortFrames(byte *file);
- void drawForeFrames(void);
- void drawForePar0Frames(void);
- void drawForePar1Frames(void);
+ void drawForeFrames();
+ void drawForePar0Frames();
+ void drawForePar1Frames();
- void startNewPalette(void);
+ void startNewPalette();
void processLayer(byte *file, uint32 layer_number);
void processImage(BuildUnit *build_unit);
- void getPlayerStructures(void);
- void putPlayerStructures(void);
+ void getPlayerStructures();
+ void putPlayerStructures();
uint32 saveData(uint16 slotNo, byte *buffer, uint32 bufferSize);
uint32 restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize);
uint32 calcChecksum(byte *buffer, uint32 size);
- void pauseGame(void);
- void unpauseGame(void);
+ void pauseGame();
+ void unpauseGame();
MenuObject _tempList[TOTAL_engine_pockets];
uint32 _totalTemp;
@@ -170,14 +170,16 @@ private:
public:
Sword2Engine(GameDetector *detector, OSystem *syst);
~Sword2Engine();
- void go(void);
- void setupPersistentResources(void);
- int32 initialiseGame(void);
+ void go();
+ void mainInit();
+ void mainRun();
+
+ void setupPersistentResources();
bool _quit;
uint32 _features;
- char *_targetName; // target name for saves
+ Common::String _targetName; // target name for saves
MemoryManager *_memory;
ResourceManager *_resman;
@@ -200,14 +202,14 @@ public:
uint32 setEventFilter(uint32 filter);
- void parseEvents(void);
+ void parseEvents();
- bool checkForMouseEvents(void);
- MouseEvent *mouseEvent(void);
- KeyboardEvent *keyboardEvent(void);
+ bool checkForMouseEvents();
+ MouseEvent *mouseEvent();
+ KeyboardEvent *keyboardEvent();
- void resetRenderLists(void);
- void buildDisplay(void);
+ void resetRenderLists();
+ void buildDisplay();
void displayMsg(byte *text, int time);
void setFullPalette(int32 palRes);
@@ -244,14 +246,14 @@ public:
int32 initBackground(int32 res, int32 new_palette);
#if RIGHT_CLICK_CLEARS_LUGGAGE
- bool heldIsInInventory(void);
+ bool heldIsInInventory();
#endif
int menuClick(int menu_items);
void addMenuObject(MenuObject *obj);
- void buildMenu(void);
- void buildSystemMenu(void);
+ void buildMenu();
+ void buildSystemMenu();
// _thisScreen describes the current back buffer and its in-game scroll
// positions, etc.
@@ -287,25 +289,25 @@ public:
uint32 _pointerTextBlocNo;
uint32 _playerActivityDelay; // Player activity delay counter
- void resetMouseList(void);
+ void resetMouseList();
- void normalMouse(void);
- void menuMouse(void);
- void dragMouse(void);
- void systemMenuMouse(void);
+ void normalMouse();
+ void menuMouse();
+ void dragMouse();
+ void systemMenuMouse();
- void mouseOnOff(void);
- uint32 checkMouseList(void);
- void mouseEngine(void);
+ void mouseOnOff();
+ uint32 checkMouseList();
+ void mouseEngine();
void setMouse(uint32 res);
void setLuggage(uint32 res);
- void clearPointerText(void);
+ void clearPointerText();
void createPointerText(uint32 text_id, uint32 pointer_res);
- void monitorPlayerActivity(void);
- void noHuman(void);
+ void monitorPlayerActivity();
+ void noHuman();
void registerMouse(ObjectMouse *ob_mouse);
@@ -359,32 +361,32 @@ public:
uint32 saveGame(uint16 slotNo, byte *description);
uint32 restoreGame(uint16 slotNo);
uint32 getSaveDescription(uint16 slotNo, byte *description);
- bool saveExists(void);
+ bool saveExists();
bool saveExists(uint16 slotNo);
void fillSaveBuffer(byte *buffer, uint32 size, byte *desc);
uint32 restoreFromBuffer(byte *buffer, uint32 size);
- uint32 findBufferSize(void);
+ uint32 findBufferSize();
uint8 _scrollFraction;
- void setScrolling(void);
+ void setScrolling();
// used to store id of tunes that loop, for save & restore
uint32 _loopingMusicId;
// to be called during system initialisation
- void initFxQueue(void);
+ void initFxQueue();
// to be called from the main loop, once per cycle
- void processFxQueue(void);
+ void processFxQueue();
// stops all fx & clears the queue - eg. when leaving a location
- void clearFxQueue(void);
+ void clearFxQueue();
- void pauseAllSound(void);
- void unpauseAllSound(void);
+ void pauseAllSound();
+ void unpauseAllSound();
- void killMusic(void);
+ void killMusic();
void triggerFx(uint8 j);
@@ -392,14 +394,14 @@ public:
bool _graphicsLevelFudged;
bool _stepOneCycle; // for use while game paused
- void startGame(void);
- void gameCycle(void);
- void closeGame(void);
+ void startGame();
+ void gameCycle();
+ void closeGame();
void sleepUntil(uint32 time);
void errorString(const char *buf_input, char *buf_output);
- void initialiseFontResourceFlags(void);
+ void initialiseFontResourceFlags();
void initialiseFontResourceFlags(uint8 language);
};