diff options
-rw-r--r-- | sword1/logic.cpp | 20 | ||||
-rw-r--r-- | sword1/logic.h | 1 | ||||
-rw-r--r-- | sword1/memman.cpp | 25 | ||||
-rw-r--r-- | sword1/memman.h | 1 | ||||
-rw-r--r-- | sword1/mouse.cpp | 41 | ||||
-rw-r--r-- | sword1/mouse.h | 4 | ||||
-rw-r--r-- | sword1/music.cpp | 4 | ||||
-rw-r--r-- | sword1/objectman.cpp | 26 | ||||
-rw-r--r-- | sword1/objectman.h | 10 | ||||
-rw-r--r-- | sword1/resman.cpp | 22 | ||||
-rw-r--r-- | sword1/resman.h | 1 | ||||
-rw-r--r-- | sword1/router.h | 10 | ||||
-rw-r--r-- | sword1/sound.cpp | 2 | ||||
-rw-r--r-- | sword1/sound.h | 2 | ||||
-rw-r--r-- | sword1/sword1.cpp | 84 | ||||
-rw-r--r-- | sword1/sword1.h | 14 | ||||
-rw-r--r-- | sword1/swordres.h | 54 | ||||
-rw-r--r-- | sword1/text.cpp | 15 |
18 files changed, 230 insertions, 106 deletions
diff --git a/sword1/logic.cpp b/sword1/logic.cpp index c569847c3a..2717c6b1ba 100644 --- a/sword1/logic.cpp +++ b/sword1/logic.cpp @@ -48,19 +48,26 @@ SwordLogic::SwordLogic(ObjectMan *pObjMan, ResMan *resMan, SwordScreen *pScreen, _music = pMusic; _sound = pSound; _menu = pMenu; - _textMan = new SwordText(_objMan, _resMan, false); + _textMan = NULL; _screen->useTextManager(_textMan); _router = new SwordRouter(_objMan, _resMan); + _eventMan = NULL; +} - //_collision = new SwordCollision(_objMan, this); - _eventMan = new EventManager(); - +void SwordLogic::initialize(void) { memset(_scriptVars, 0, NUM_SCRIPT_VARS * sizeof(uint32)); for (uint8 cnt = 0; cnt < NON_ZERO_SCRIPT_VARS; cnt++) _scriptVars[_scriptVarInit[cnt][0]] = _scriptVarInit[cnt][1]; + + delete _eventMan; + _eventMan = new EventManager(); + delete _textMan; + _textMan = new SwordText(_objMan, _resMan, false); + _screen->useTextManager(_textMan); _textRunning = _speechRunning = false; _speechFinished = true; + _router->resetExtraData(); } void SwordLogic::newScreen(uint32 screen) { @@ -1542,7 +1549,7 @@ int SwordLogic::fnCheckCD(BsObject *cpt, int32 id, int32 screen, int32 b, int32 } int SwordLogic::fnRestartGame(BsObject *cpt, int32 id, int32 a, int32 b, int32 c, int32 d, int32 z, int32 x) { - SwordEngine::_systemVars.saveGameFlag = 3; + SwordEngine::_systemVars.forceRestart = true; cpt->o_logic = LOGIC_quit; return SCRIPT_STOP; } @@ -1553,8 +1560,7 @@ int SwordLogic::fnQuitGame(BsObject *cpt, int32 id, int32 a, int32 b, int32 c, i } int SwordLogic::fnDeathScreen(BsObject *cpt, int32 id, int32 a, int32 b, int32 c, int32 d, int32 z, int32 x) { - SwordEngine::_systemVars.saveGameFlag = 1; - SwordEngine::_systemVars.snrStatus = 1; + if (_scriptVars[FINALE_OPTION_FLAG] == 4) // successful end of game! SwordEngine::_systemVars.deathScreenFlag = 2; else diff --git a/sword1/logic.h b/sword1/logic.h index 7094b3d930..bde258203a 100644 --- a/sword1/logic.h +++ b/sword1/logic.h @@ -46,6 +46,7 @@ class SwordLogic { public: SwordLogic(ObjectMan *pObjMan, ResMan *resMan, SwordScreen *pScreen, SwordMouse *pMouse, SwordSound *pSound, SwordMusic *pMusic, SwordMenu *pMenu); ~SwordLogic(void); + void initialize(void); void newScreen(uint32 screen); void engine(void); void updateScreenParams(void); diff --git a/sword1/memman.cpp b/sword1/memman.cpp index bee3c736ae..a8cded00e3 100644 --- a/sword1/memman.cpp +++ b/sword1/memman.cpp @@ -67,6 +67,18 @@ void MemMan::setCondition(BsMemHandle *bsMem, uint16 pCond) { } } +void MemMan::flush(void) { + while (_memListFree) { + free(_memListFreeEnd->data); + _memListFreeEnd->data = NULL; + _memListFreeEnd->cond = MEM_FREED; + _alloced -= _memListFreeEnd->size; + removeFromFreeList(_memListFreeEnd); + } + if (_alloced) + warning("MemMan::flush: Something's wrong: still %d bytes alloced", _alloced); +} + void MemMan::checkMemoryUsage(void) { while ((_alloced > MAX_ALLOC) && _memListFree) { free(_memListFreeEnd->data); @@ -92,19 +104,6 @@ void MemMan::addToFreeList(BsMemHandle *bsMem) { } void MemMan::removeFromFreeList(BsMemHandle *bsMem) { - /*BsMemHandle *forw = _memListFree; - BsMemHandle *rev = _memListFreeEnd; - - while (forw || rev) { - if (!(forw && rev)) - error("mem list is completely fubared"); - printf("%p <-> %p\n", forw, rev); - forw = forw->next; - rev = rev->prev; - } - printf("\n");*/ - if (!(bsMem->prev || bsMem->next)) - warning("removeFromFreeList: memory block wasn't in list"); if (_memListFree == bsMem) _memListFree = bsMem->next; if (_memListFreeEnd == bsMem) diff --git a/sword1/memman.h b/sword1/memman.h index 5ff7f298d3..26a3414305 100644 --- a/sword1/memman.h +++ b/sword1/memman.h @@ -46,6 +46,7 @@ public: void setCondition(BsMemHandle *bsMem, uint16 pCond); void freeNow(BsMemHandle *bsMem); void initHandle(BsMemHandle *bsMem); + void flush(void); private: void addToFreeList(BsMemHandle *bsMem); void removeFromFreeList(BsMemHandle *bsMem); diff --git a/sword1/mouse.cpp b/sword1/mouse.cpp index 585fba3bc2..920c3f74cc 100644 --- a/sword1/mouse.cpp +++ b/sword1/mouse.cpp @@ -35,14 +35,6 @@ SwordMouse::SwordMouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) { _resMan = pResMan; _objMan = pObjMan; _system = system; - _numObjs = 0; - _menuStatus = _mouseStatus = 0; // mouse off and unlocked - _getOff = 0; - _specialPtrId = 0; - _inTopMenu = false; - - for (uint8 cnt = 0; cnt < 17; cnt++) - _pointers[cnt] = (MousePtr*)_resMan->mouseResOpen(MSE_POINTER + cnt); /*_resMan->resOpen(MSE_POINTER); // normal mouse (1 frame anim) _resMan->resOpen(MSE_OPERATE); _resMan->resOpen(MSE_PICKUP); @@ -63,6 +55,37 @@ SwordMouse::SwordMouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) { // luggage & chess stuff is opened dynamically } +void SwordMouse::initialize(void) { + _numObjs = 0; + _menuStatus = _mouseStatus = 0; // mouse off and unlocked + _getOff = 0; + _specialPtrId = 0; + _inTopMenu = false; + + for (uint8 cnt = 0; cnt < 17; cnt++) + _pointers[cnt] = (MousePtr*)_resMan->mouseResOpen(MSE_POINTER + cnt); +} + +void SwordMouse::controlPanel(bool on) { // true on entering cpanel, false when leaving + static uint32 savedPtrId = 0, savedSpecialId = 0; + static uint8 savedMouseStatus; + if (on) { + savedPtrId = _currentPtrId; + savedSpecialId = _specialPtrId; + savedMouseStatus = _mouseStatus; + _mouseStatus = 1; + setPointer(MSE_POINTER, 0); + } else { + _currentPtrId = savedPtrId; + _mouseStatus = savedMouseStatus; + _specialPtrId = savedSpecialId; + if (_specialPtrId) + setPointer(_specialPtrId, 0); + else + setPointer(_currentPtrId + MSE_POINTER, 0); + } +} + void SwordMouse::useLogicAndMenu(SwordLogic *pLogic, SwordMenu *pMenu) { _logic = pLogic; _menu = pMenu; @@ -186,7 +209,7 @@ void SwordMouse::setPointer(uint32 resId, uint32 rate) { } _frame = 0; - if (resId == 0) { + if ((resId == 0) || (!(_mouseStatus & 1))) { _system->set_mouse_cursor(NULL, 0, 0, 0, 0); _system->show_mouse(false); } else { diff --git a/sword1/mouse.h b/sword1/mouse.h index 0f36cc83d3..e056aa18e4 100644 --- a/sword1/mouse.h +++ b/sword1/mouse.h @@ -67,6 +67,7 @@ class OSystem; class SwordMouse { public: SwordMouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan); + void initialize(void); void addToList(int id, BsObject *compact); void useLogicAndMenu(SwordLogic *pLogic, SwordMenu *pMenu); void setLuggage(uint32 resID, uint32 rate); @@ -83,9 +84,9 @@ public: void fnLockMouse(void); void fnUnlockMouse(void); void setMenuStatus(uint8 status); + void controlPanel(bool on); private: MousePtr *_pointers[17]; - uint32 _currentPtrId, _frame; OSystem *_system; SwordLogic *_logic; SwordMenu *_menu; @@ -94,6 +95,7 @@ private: ObjectMan *_objMan; uint16 _mouseX, _mouseY; + uint32 _currentPtrId, _frame; uint8 _mouseStatus, _mouseCount; uint16 _numObjs; uint16 _lastState, _state; diff --git a/sword1/music.cpp b/sword1/music.cpp index 8926eb8d46..98a1b69000 100644 --- a/sword1/music.cpp +++ b/sword1/music.cpp @@ -54,9 +54,7 @@ void SwordMusic::mixer(int16 *buf, uint len) { else { _system->lock_mutex(_mutex); len >>= 1; - if (len > _smpInBuf) - warning("SwordMusic::mixer: sample buffer underrun"); - else { + if (len <= _smpInBuf) { uint32 maxLen = BUFSIZE - _bufPos; if (len >= maxLen) { for (uint32 cnt = 0; cnt < maxLen; cnt++) diff --git a/sword1/objectman.cpp b/sword1/objectman.cpp index a2f0881c9e..2673cbb493 100644 --- a/sword1/objectman.cpp +++ b/sword1/objectman.cpp @@ -29,9 +29,14 @@ ObjectMan::ObjectMan(ResMan *pResourceMan) { _resMan = pResourceMan; +} + +void ObjectMan::initialize(void) { for (uint16 cnt = 0; cnt < TOTAL_SECTIONS; cnt++) - _liveList[cnt] = 0; - + _liveList[cnt] = 0; // we don't need to close the files here. When this routine is + // called, the memory was flushed() anyways, so these resources + // already *are* closed. + _liveList[128] = _liveList[129] = _liveList[130] = _liveList[131] = _liveList[133] = _liveList[134] = _liveList[145] = _liveList[146] = _liveList[TEXT_sect] = 1; @@ -41,7 +46,6 @@ ObjectMan::ObjectMan(ResMan *pResourceMan) { else _cptData[cnt] = NULL; } - } ObjectMan::~ObjectMan(void) { @@ -131,3 +135,19 @@ void ObjectMan::closeSection(uint32 screen) { if (_liveList[screen] == 0) // close the section that PLAYER has just left, if it's empty now _resMan->resClose(_objectList[screen]); } + +void ObjectMan::loadLiveList(uint16 *src) { + for (uint16 cnt = 0; cnt < TOTAL_SECTIONS; cnt++) { + if (_liveList[cnt]) { + _resMan->resClose(_objectList[cnt]); + _cptData[cnt] = NULL; + } + _liveList[cnt] = src[cnt]; + if (_liveList[cnt]) + _cptData[cnt] = ((uint8*)_resMan->cptResOpen(_objectList[cnt])) + sizeof(Header); + } +} + +void ObjectMan::saveLiveList(uint16 *dest) { + memcpy(dest, _liveList, TOTAL_SECTIONS * sizeof(uint16)); +} diff --git a/sword1/objectman.h b/sword1/objectman.h index 8b06abe56a..fbbc72dd68 100644 --- a/sword1/objectman.h +++ b/sword1/objectman.h @@ -32,8 +32,9 @@ class ObjectMan { public: ObjectMan(ResMan *pResourceMan); ~ObjectMan(void); + void initialize(void); + BsObject *fetchObject(uint32 id); - //void unlockObject(uint32 id); uint32 fetchNoObjects(int section); bool sectionAlive(uint16 section); void megaEntering(uint16 section); @@ -44,12 +45,15 @@ public: void unlockText(uint32 textId); uint32 lastTextNumber(int section); - void closeSection(uint32 screen); + void closeSection(uint32 screen); + + void saveLiveList(uint16 *dest); // for loading/saving + void loadLiveList(uint16 *src); private: ResMan *_resMan; static const uint32 _objectList[TOTAL_SECTIONS]; //a table of pointers to object files static const uint32 _textList[TOTAL_SECTIONS][7]; //a table of pointers to text files - int _liveList[TOTAL_SECTIONS]; //which sections are active + uint16 _liveList[TOTAL_SECTIONS]; //which sections are active uint8 *_cptData[TOTAL_SECTIONS]; }; diff --git a/sword1/resman.cpp b/sword1/resman.cpp index 2097874acd..61b5a95581 100644 --- a/sword1/resman.cpp +++ b/sword1/resman.cpp @@ -100,7 +100,8 @@ void ResMan::freeCluDescript(void) { if (BsClu *cluster = _prj.clu[clusCnt]) { for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++) if (BsGrp *group = cluster->grp[grpCnt]) { - _memMan->freeNow(group->resHandle); + for (uint32 resCnt = 0; resCnt < group->noRes; resCnt++) + _memMan->freeNow(group->resHandle + resCnt); delete[] group->resHandle; delete[] group->offset; delete[] group->length; @@ -112,6 +113,18 @@ void ResMan::freeCluDescript(void) { delete[] _prj.clu; } +void ResMan::flush(void) { + for (uint32 clusCnt = 0; clusCnt < _prj.noClu; clusCnt++) + if (BsClu *cluster = _prj.clu[clusCnt]) + for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++) + if (BsGrp *group = cluster->grp[grpCnt]) + for (uint32 resCnt = 0; resCnt < group->noRes; resCnt++) + if (group->resHandle[resCnt].cond != MEM_FREED) { + _memMan->setCondition(group->resHandle + resCnt, MEM_CAN_FREE); + group->resHandle[resCnt].refCount = 0; + } +} + void *ResMan::fetchRes(uint32 id) { BsMemHandle *memHandle = resHandle(id); if (!memHandle->data) @@ -192,10 +205,11 @@ void ResMan::resClose(uint32 id) { BsMemHandle *handle = resHandle(id); if (!handle->refCount) { warning("Resource Manager fail: unlocking object with refCount 0. Id: %d\n", id); - } else + } else { handle->refCount--; - if (!handle->refCount) - _memMan->setCondition( handle, MEM_CAN_FREE); + if (!handle->refCount) + _memMan->setCondition( handle, MEM_CAN_FREE); + } } FrameHeader *ResMan::fetchFrame(void *resourceData, uint32 frameNo) { diff --git a/sword1/resman.h b/sword1/resman.h index 527f776d52..23367c70b2 100644 --- a/sword1/resman.h +++ b/sword1/resman.h @@ -50,6 +50,7 @@ class ResMan { public: ResMan(const char *resFile, MemMan *pMemoMan); ~ResMan(void); + void flush(void); void resClose(uint32 id); void resOpen(uint32 id); void *fetchRes(uint32 id); diff --git a/sword1/router.h b/sword1/router.h index e7a8e807fc..eb62e2dafb 100644 --- a/sword1/router.h +++ b/sword1/router.h @@ -79,16 +79,6 @@ struct PathData { int32 num; }; -/*struct FrameInfos { - int32 framesPerStep, framesPerChar; - int32 standFrames; - int32 slowInFrames, slowOutFrames; - int32 turnFramesLeft, turnFramesRight; - int32 walkFramesLeft, walkFramesRight; - uint16 startX, startY, targetX, targetY, targetDir; - int32 scaleA, scaleB; -};*/ - #define ROUTE_END_FLAG 255 #define NO_DIRECTIONS 8 #define MAX_FRAMES_PER_CYCLE 16 diff --git a/sword1/sound.cpp b/sword1/sound.cpp index 6ba4393d93..ea83e27815 100644 --- a/sword1/sound.cpp +++ b/sword1/sound.cpp @@ -121,7 +121,7 @@ bool SwordSound::speechFinished(void) { return (_speechHandle == 0); } -void SwordSound::newScreen(uint16 screen) { +void SwordSound::quitScreen(void) { // stop all running SFX while (_endOfQueue) fnStopFx(_fxQueue[0].id); diff --git a/sword1/sound.h b/sword1/sound.h index 6a3d5ee58b..d139d15ab3 100644 --- a/sword1/sound.h +++ b/sword1/sound.h @@ -57,7 +57,7 @@ class SwordSound { public: SwordSound(const char *searchPath, SoundMixer *mixer, ResMan *pResMan); ~SwordSound(void); - void newScreen(uint16 screen); + void quitScreen(void); bool startSpeech(uint16 roomNo, uint16 localNo); // this should work more or less. // Maybe we'll need a delay of 3 gameCycles. diff --git a/sword1/sword1.cpp b/sword1/sword1.cpp index 24cdb02c59..ae33153869 100644 --- a/sword1/sword1.cpp +++ b/sword1/sword1.cpp @@ -39,6 +39,7 @@ #include "swordres.h" #include "menu.h" #include "music.h" +#include "control.h" /* Broken Sword 1 */ static const GameSettings sword1_setting = @@ -113,10 +114,10 @@ void SwordEngine::initialize(void) { _mouse->useLogicAndMenu(_logic, _menu); _systemVars.justRestoredGame = _systemVars.currentCD = - _systemVars.gamePaused = _systemVars.saveGameFlag = - _systemVars.deathScreenFlag = _systemVars.currentMusic = 0; - _systemVars.snrStatus = 0; + _systemVars.gamePaused = 0; + _systemVars.deathScreenFlag = 3; _systemVars.rate = 8; + _systemVars.forceRestart = false; switch (Common::parseLanguage(ConfMan.get("language"))) { case Common::DE_DEU: @@ -142,8 +143,21 @@ void SwordEngine::initialize(void) { _systemVars.showText = ConfMan.getBool("subtitles"); _systemVars.playSpeech = 1; - startPositions(ConfMan.getInt("boot_param")); _mouseState = 0; + + _logic->initialize(); + _objectMan->initialize(); + _mouse->initialize(); +} + +void SwordEngine::reinitialize(void) { + _resMan->flush(); // free everything that's currently alloced and opened. + _memMan->flush(); // Handle with care. + + _logic->initialize(); // now reinitialize these objects as they (may) have locked + _objectMan->initialize(); // resources which have just been wiped. + _mouse->initialize(); + // todo: reinitialize swordmenu. } void SwordEngine::startPositions(int32 startNumber) { @@ -1000,27 +1014,63 @@ void SwordEngine::startPositions(int32 startNumber) { error("Can't start in location %d", startNumber); } - compact = (BsObject*)_objectMan->fetchObject(PLAYER); _logic->fnEnterSection(compact, PLAYER, startNumber, 0, 0, 0, 0, 0); // (automatically opens the compact resource for that section) + _systemVars.deathScreenFlag = 0; } void SwordEngine::go(void) { initialize(); + _systemVars.deathScreenFlag = 3; // check if we have savegames. if we do, show control panel, else start intro. + /* death flags: + 0 = not dead, normal game + 1 = dead + 2 = game won + 3 = game was just started */ + SwordControl *control = new SwordControl(_resMan, _objectMan, _system, _mouse, getSavePath()); + uint8 controlRes = 0; + + uint8 startPos = ConfMan.getInt("boot_param"); + if (startPos) { + startPositions(startPos); + _systemVars.deathScreenFlag = 0; + } else { + // Temporary: + startPositions(0); + _systemVars.deathScreenFlag = 0; + //todo: check if we have savegames. if we do, show control panel, else start intro. + //control->runPanel(); + } + do { - mainLoop(); - // mainLoop was left, show control panel + mainLoop(); + + // the mainloop was left, either because the player pressed F5 or because the logic + // wants to restart the game. + if (!_systemVars.forceRestart) + controlRes = control->runPanel(); + if ((controlRes == CONTROL_RESTART_GAME) || (_systemVars.forceRestart)) { + _music->fadeDown(); + startPositions(1); + _systemVars.forceRestart = false; + } else if (controlRes == CONTROL_GAME_RESTORED) { + reinitialize(); // first clear anything which was loaded + control->doRestore(); // then actually load the savegame data. + _mouse->fnUnlockMouse(); // and allow mouse movements. + _mouse->fnAddHuman(); + } + _systemVars.deathScreenFlag = 0; } while (true); } void SwordEngine::mainLoop(void) { uint32 newTime, frameTime; + bool wantControlPanel = false; do { // do we need the section45-hack from sword.c here? // todo: ensure right cd is inserted - _sound->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]); _screen->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]); _logic->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]); SwordLogic::_scriptVars[SCREEN] = SwordLogic::_scriptVars[NEW_SCREEN]; @@ -1028,7 +1078,6 @@ void SwordEngine::mainLoop(void) { do { _music->stream(); frameTime = _system->get_msecs(); - _systemVars.saveGameFlag = 0; _logic->engine(); _logic->updateScreenParams(); // sets scrolling @@ -1066,23 +1115,24 @@ void SwordEngine::mainLoop(void) { _mouse->engine( _mouseX, _mouseY, _mouseState); _mouseState = 0; + if (_keyPressed == 63) + wantControlPanel = true; // do something smart here to implement pausing the game. If we even want that, that is. } while ((SwordLogic::_scriptVars[SCREEN] == SwordLogic::_scriptVars[NEW_SCREEN]) && - (_systemVars.saveGameFlag < 2)); // change screen - + (!_systemVars.forceRestart) && (!wantControlPanel)); + if (SwordLogic::_scriptVars[SCREEN] != 53) // we don't fade down after syria pan (53). _screen->fadeDownPalette(); while (_screen->stillFading()) { _music->stream(); _screen->updateScreen(); delay(1000/12); - // todo: fade sfx? } + _sound->quitScreen(); _screen->quitScreen(); // close graphic resources _objectMan->closeSection(SwordLogic::_scriptVars[SCREEN]); // close the section that PLAYER has just left, if it's empty now - // todo: stop sfx, clear sfx queue, free sfx memory - } while (_systemVars.saveGameFlag < 2); + } while ((!_systemVars.forceRestart) && (!wantControlPanel)); } void SwordEngine::delay(uint amount) { //copied and mutilated from sky.cpp @@ -1091,7 +1141,7 @@ void SwordEngine::delay(uint amount) { //copied and mutilated from sky.cpp uint32 start = _system->get_msecs(); uint32 cur = start; - uint16 _key_pressed = 0; //reset + _keyPressed = 0; do { while (_system->poll_event(&event)) { @@ -1100,9 +1150,9 @@ void SwordEngine::delay(uint amount) { //copied and mutilated from sky.cpp // Make sure backspace works right (this fixes a small issue on OS X) if (event.kbd.keycode == 8) - _key_pressed = 8; + _keyPressed = 8; else - _key_pressed = (byte)event.kbd.ascii; + _keyPressed = (uint8)event.kbd.ascii; break; case OSystem::EVENT_MOUSEMOVE: _mouseX = event.mouse.x; diff --git a/sword1/sword1.h b/sword1/sword1.h index 7844e9d7e9..581cac2e53 100644 --- a/sword1/sword1.h +++ b/sword1/sword1.h @@ -45,11 +45,12 @@ struct SystemVars { //uint32 endOfQ; // next available slot in sound fx queue //uint8 debug; // toggles tdebug file - uint8 saveGameFlag; // controls save game loop 0=off 1=save game 2=restore game 3=restart 4=quit to dos - uint8 deathScreenFlag; // 1 death screen version of the control panel, 2 = successful end of game + //uint8 saveGameFlag; // controls save game loop 0=off 1=save game 2=restore game 3=restart 4=quit to dos + uint8 deathScreenFlag; // 1 death screen version of the control panel, 2 = successful end of game, 3 = force restart + bool forceRestart; uint8 playSpeech; uint8 showText; - uint8 snrStatus; + //uint8 snrStatus; // ^=> move into SwordControl... or whatever it will be. //uint8 displayText; // toggles debug text display on "t" //uint8 displayGrid; // toggles debug grid display on "g" @@ -57,8 +58,8 @@ struct SystemVars { //uint8 framesPerSecond; // toggles one frame pre second mode on "1" //uint8 writingPCXs; // writing a PCX every frame on "f" //int16 parallaxOn; I think we don't need this. - uint8 language; - int32 currentMusic; + uint8 language; + //int32 currentMusic; //uint32 gameCycle; }; @@ -68,16 +69,19 @@ public: SwordEngine(GameDetector *detector, OSystem *syst); virtual ~SwordEngine(); static SystemVars _systemVars; + void reinitialize(void); protected: void go(); private: void delay(uint amount); void initialize(void); + void mainLoop(void); void fnCheckCd(uint32 newScreen); void startPositions(int32 startNumber); uint16 _mouseX, _mouseY, _mouseState; + uint8 _keyPressed; GameDetector *_detector; OSystem *_system; diff --git a/sword1/swordres.h b/sword1/swordres.h index a1a9edb9e2..cbbd84aa58 100644 --- a/sword1/swordres.h +++ b/sword1/swordres.h @@ -996,32 +996,34 @@ #define ICON_YES 0x0404005D // 94 entities in TXTs, 94 in datafiles. // save_menu -#define SR_BUTTON 0x04050000 -#define SR_PALETTE 0x04050001 -#define SR_PANEL_ENGLISH 0x04050002 -#define SR_PANEL_FRENCH 0x04050003 -#define SR_PANEL_GERMAN 0x04050004 -#define SR_PANEL_ITALIAN 0x04050005 -#define SR_PANEL_SPANISH 0x04050006 -#define SR_PANEL_AMERICAN 0x04050007 -#define SR_TEXT_BUTTON 0x04050008 -#define SR_SPEED 0x04050009 -#define SR_SCROLL1 0x0405000A -#define SR_SCROLL2 0x0405000B -#define SR_CONFIRM 0x0405000C -#define SR_VOLUME 0x0405000D -#define SR_VLIGHT 0x0405000E -#define SR_VKNOB 0x0405000F -#define SR_WINDOW 0x04050010 -#define SR_SLAB1 0x04050011 -#define SR_SLAB2 0x04050012 -#define SR_SLAB3 0x04050013 -#define SR_SLAB4 0x04050014 -#define SR_BUTUF 0x04050015 -#define SR_BUTUS 0x04050016 -#define SR_BUTDS 0x04050017 -#define SR_BUTDF 0x04050018 -#define SR_DEATHPANEL 0x04050019 +#define SR_UNKNOWN_RESOURCE1 0x04050000 +#define SR_BUTTON 0x04050001 +#define SR_UNKNOWN_RESOURCE2 0x04050002 // this is actually the red font +#define SR_PALETTE 0x04050003 +#define SR_PANEL_ENGLISH 0x04050004 +#define SR_PANEL_FRENCH 0x04050005 +#define SR_PANEL_GERMAN 0x04050006 +#define SR_PANEL_ITALIAN 0x04050007 +#define SR_PANEL_SPANISH 0x04050008 +#define SR_PANEL_AMERICAN 0x04050009 +#define SR_TEXT_BUTTON 0x0405000A +#define SR_SPEED 0x0405000B +#define SR_SCROLL1 0x0405000C +#define SR_SCROLL2 0x0405000D +#define SR_CONFIRM 0x0405000E +#define SR_VOLUME 0x0405000F +#define SR_VLIGHT 0x04050010 +#define SR_VKNOB 0x04050011 +#define SR_WINDOW 0x04050012 +#define SR_SLAB1 0x04050013 +#define SR_SLAB2 0x04050014 +#define SR_SLAB3 0x04050015 +#define SR_SLAB4 0x04050016 +#define SR_BUTUF 0x04050017 +#define SR_BUTUS 0x04050018 +#define SR_BUTDS 0x04050019 +#define SR_BUTDF 0x0405001A +#define SR_DEATHPANEL 0x0405001B // 0x04050019 // 26 entities in TXTs, 29 in datafiles. // george #define GEORGE_MEGA 0x04060000 diff --git a/sword1/text.cpp b/sword1/text.cpp index d833f6a4ce..7bb03a730d 100644 --- a/sword1/text.cpp +++ b/sword1/text.cpp @@ -48,6 +48,13 @@ SwordText::SwordText(ObjectMan *pObjMan, ResMan *pResMan, bool czechVersion) { _textBlocks[0] = _textBlocks[1] = NULL; } +SwordText::~SwordText(void) { + if (_textBlocks[0]) + free(_textBlocks[0]); + if (_textBlocks[1]) + free(_textBlocks[1]); +} + uint32 SwordText::lowTextManager(uint8 *ascii, int32 width, uint8 pen) { _textCount++; if (_textCount > MAX_TEXT_OBS) @@ -170,7 +177,9 @@ FrameHeader *SwordText::giveSpriteData(uint32 textTarget) { void SwordText::releaseText(uint32 id) { id &= ITM_ID; assert(id <= 1); - free(_textBlocks[id]); - _textBlocks[id] = NULL; - _textCount--; + if (_textBlocks[id]) { + free(_textBlocks[id]); + _textBlocks[id] = NULL; + _textCount--; + } } |