[Scummvm-cvs-logs] SF.net SVN: scummvm:[45666] scummvm/trunk/engines/sci
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Wed Nov 4 15:22:18 CET 2009
Revision: 45666
http://scummvm.svn.sourceforge.net/scummvm/?rev=45666&view=rev
Author: thebluegr
Date: 2009-11-04 14:22:17 +0000 (Wed, 04 Nov 2009)
Log Message:
-----------
- Changed the segment manager to be a static part of the engine, and stopped deleting and recreating it when restoring games
- Merged game_exit(), script_free_vm_memory() and script_free_engine()
- Cleanup
Modified Paths:
--------------
scummvm/trunk/engines/sci/engine/game.cpp
scummvm/trunk/engines/sci/engine/savegame.cpp
scummvm/trunk/engines/sci/engine/seg_manager.cpp
scummvm/trunk/engines/sci/engine/seg_manager.h
scummvm/trunk/engines/sci/engine/state.cpp
scummvm/trunk/engines/sci/engine/state.h
scummvm/trunk/engines/sci/engine/vm.cpp
scummvm/trunk/engines/sci/engine/vm.h
scummvm/trunk/engines/sci/gui/gui.cpp
scummvm/trunk/engines/sci/gui/gui_controls.cpp
scummvm/trunk/engines/sci/gui/gui_controls.h
scummvm/trunk/engines/sci/gui/gui_gfx.h
scummvm/trunk/engines/sci/gui32/gui32.cpp
scummvm/trunk/engines/sci/sci.cpp
Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/game.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -304,7 +304,6 @@
// Architectural stuff: Init/Unintialize engine
int script_init_engine(EngineState *s) {
- s->_segMan = new SegManager(s->resMan);
s->_msgState = new MessageState(s->_segMan);
s->gc_countdown = GC_INTERVAL - 1;
@@ -350,23 +349,6 @@
return 0;
}
-void script_free_vm_memory(EngineState *s) {
- debug(2, "Freeing VM memory");
-
- if (s->_segMan)
- s->_segMan->_classtable.clear();
-
- // Close all opened file handles
- s->_fileHandles.clear();
- s->_fileHandles.resize(5);
-}
-
-void script_free_engine(EngineState *s) {
- script_free_vm_memory(s);
-
- debug(2, "Freeing state-dependant data");
-}
-
void script_free_breakpoints(EngineState *s) {
Breakpoint *bp, *bp_next;
@@ -451,12 +433,12 @@
game_init_sound(s, SFX_STATE_FLAG_NOSOUND);
}
- s->_segMan->_classtable.clear();
- delete s->_segMan;
- s->_segMan = 0;
+ // Note: It's a bad idea to delete the segment manager here.
+ // This function is called right after a game is loaded, and
+ // the segment manager has already been initialized from the
+ // save game. Deleting or resetting it here will result in
+ // invalidating the loaded save state
- debug(2, "Freeing miscellaneous data...");
-
// TODO Free parser segment here
// TODO Free scripts here
@@ -465,6 +447,10 @@
_free_graphics_input(s);
+ // Close all opened file handles
+ s->_fileHandles.clear();
+ s->_fileHandles.resize(5);
+
return 0;
}
Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -257,11 +257,8 @@
static void sync_SegManagerPtr(Common::Serializer &s, ResourceManager *&resMan, SegManager *&obj) {
s.skip(1, VER(9), VER(9)); // obsolete: used to be a flag indicating if we got sci11 or not
- if (s.isLoading()) {
- // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch.
- delete obj;
- obj = new SegManager(resMan);
- }
+ if (s.isLoading())
+ obj->resetSegMan();
obj->saveLoadWithSerializer(s);
}
@@ -737,7 +734,7 @@
}
// FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch.
- retval = new EngineState(s->resMan, s->_kernel, s->_voc, s->_gui, s->_audio);
+ retval = new EngineState(s->resMan, s->_kernel, s->_voc, s->_segMan, s->_gui, s->_audio);
// Copy some old data
retval->gfx_state = s->gfx_state;
Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -57,21 +57,34 @@
_exportsAreWide = false;
_resMan = resMan;
- int result = 0;
-
- result = createClassTable();
-
- if (result)
- error("SegManager: Failed to initialize class table");
+ createClassTable();
}
// Destroy the object, free the memorys if allocated before
SegManager::~SegManager() {
+ resetSegMan();
+}
+
+void SegManager::resetSegMan() {
// Free memory
for (uint i = 0; i < _heap.size(); i++) {
if (_heap[i])
deallocate(i, false);
}
+
+ _heap.clear();
+
+ // And reinitialize
+ _heap.push_back(0);
+
+ Clones_seg_id = 0;
+ Lists_seg_id = 0;
+ Nodes_seg_id = 0;
+ Hunks_seg_id = 0;
+
+ // Reinitialize class table
+ _classtable.clear();
+ createClassTable();
}
SegmentId SegManager::findFreeSegment() const {
@@ -1218,7 +1231,7 @@
return 0; // OK
}
-int SegManager::createClassTable() {
+void SegManager::createClassTable() {
Resource *vocab996 = _resMan->findResource(ResourceId(kResourceTypeVocab, 996), 1);
if (!vocab996)
@@ -1235,8 +1248,6 @@
}
_resMan->unlockResource(vocab996);
-
- return 0;
}
} // End of namespace Sci
Modified: scummvm/trunk/engines/sci/engine/seg_manager.h
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.h 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/seg_manager.h 2009-11-04 14:22:17 UTC (rev 45666)
@@ -58,6 +58,8 @@
*/
~SegManager();
+ void resetSegMan();
+
virtual void saveLoadWithSerializer(Common::Serializer &ser);
// 1. Scripts
@@ -456,7 +458,7 @@
SegmentObj *allocSegment(SegmentObj *mem, SegmentId *segid);
LocalVariables *allocLocalsSegment(Script *scr, int count);
int deallocate(SegmentId seg, bool recursive);
- int createClassTable();
+ void createClassTable();
SegmentId findFreeSegment() const;
Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/state.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -32,8 +32,8 @@
namespace Sci {
-EngineState::EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, SciGui *gui, AudioPlayer *audio)
-: resMan(res), _kernel(kernel), _voc(voc), _gui(gui), _audio(audio), _dirseeker(this) {
+EngineState::EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, SegManager *segMan, SciGui *gui, AudioPlayer *audio)
+: resMan(res), _kernel(kernel), _voc(voc), _segMan(segMan), _gui(gui), _audio(audio), _dirseeker(this) {
gfx_state = 0;
@@ -96,7 +96,6 @@
_gameObj = NULL_REG;
- _segMan = 0;
gc_countdown = 0;
successor = 0;
Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/state.h 2009-11-04 14:22:17 UTC (rev 45666)
@@ -116,7 +116,7 @@
struct EngineState : public Common::Serializable {
public:
- EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, SciGui *gui, AudioPlayer *audio);
+ EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc, SegManager *segMan, SciGui *gui, AudioPlayer *audio);
virtual ~EngineState();
virtual void saveLoadWithSerializer(Common::Serializer &ser);
Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/vm.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -1796,7 +1796,6 @@
s->_executionStackPosChanged = false;
game_exit(s);
- script_free_engine(s);
script_init_engine(s);
game_init(s);
s->_sound.sfx_reset_player();
@@ -1811,7 +1810,6 @@
successor = s->successor;
if (successor) {
game_exit(s);
- script_free_vm_memory(s);
delete s;
s = successor;
Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/engine/vm.h 2009-11-04 14:22:17 UTC (rev 45666)
@@ -420,20 +420,6 @@
int script_init_engine(EngineState *);
/**
- * Frees all additional memory associated with a EngineState block
- * @param[in] s The EngineState whose elements should be cleared
- */
-void script_free_engine(EngineState *s);
-
-/**
- * Frees all script memory (heap, hunk, and class tables).
- * This operation is implicit in script_free_engine(), but is required for
- * restoring the game state.
- * @param[in] s The EngineState to free
- */
-void script_free_vm_memory(EngineState *s);
-
-/**
* Looks up a selector and returns its type and value
* varindex is written to iff it is non-NULL and the selector indicates a property of the object.
* @param[in] segMan The Segment Manager
Modified: scummvm/trunk/engines/sci/gui/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/gui/gui.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -61,7 +61,7 @@
_animate = new SciGuiAnimate(_s, _gfx, _screen, _palette);
_text = new SciGuiText(_s->resMan, _gfx, _screen);
_windowMgr = new SciGuiWindowMgr(this, _screen, _gfx, _text);
- _controls = new SciGuiControls(_gfx, _text);
+ _controls = new SciGuiControls(_s->_segMan, _gfx, _text);
_menu = new SciGuiMenu(_gfx, _text, _screen);
// _gui32 = new SciGui32(_s, _screen, _palette, _cursor); // for debug purposes
}
@@ -81,7 +81,6 @@
void SciGui::resetEngineState(EngineState *s) {
_s = s;
- _gfx->resetSegMan(s->_segMan);
_animate->resetEngineState(s);
}
@@ -443,7 +442,7 @@
switch (controlType) {
case SCI_CONTROLS_TYPE_TEXTEDIT:
// Only process textedit controls in here
- _controls->TexteditChange(_s->_segMan, controlObject, eventObject);
+ _controls->TexteditChange(controlObject, eventObject);
return;
}
}
Modified: scummvm/trunk/engines/sci/gui/gui_controls.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_controls.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/gui/gui_controls.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -36,8 +36,8 @@
namespace Sci {
-SciGuiControls::SciGuiControls(SciGuiGfx *gfx, SciGuiText *text)
- : _gfx(gfx), _text(text) {
+SciGuiControls::SciGuiControls(SegManager *segMan, SciGuiGfx *gfx, SciGuiText *text)
+ : _segMan(segMan), _gfx(gfx), _text(text) {
init();
}
@@ -137,10 +137,10 @@
_texteditBlinkTime = g_system->getMillis() + (30 * 1000 / 60);
}
-void SciGuiControls::TexteditChange(SegManager *segMan, reg_t controlObject, reg_t eventObject) {
- uint16 cursorPos = GET_SEL32V(segMan, controlObject, cursor);
- uint16 maxChars = GET_SEL32V(segMan, controlObject, max);
- reg_t textReference = GET_SEL32(segMan, controlObject, text);
+void SciGuiControls::TexteditChange(reg_t controlObject, reg_t eventObject) {
+ uint16 cursorPos = GET_SEL32V(_segMan, controlObject, cursor);
+ uint16 maxChars = GET_SEL32V(_segMan, controlObject, max);
+ reg_t textReference = GET_SEL32(_segMan, controlObject, text);
Common::String text;
uint16 textSize, eventType, eventKey;
bool textChanged = false;
@@ -148,18 +148,18 @@
if (textReference.isNull())
error("kEditControl called on object that doesnt have a text reference");
- text = segMan->getString(textReference);
+ text = _segMan->getString(textReference);
if (!eventObject.isNull()) {
textSize = text.size();
- eventType = GET_SEL32V(segMan, eventObject, type);
+ eventType = GET_SEL32V(_segMan, eventObject, type);
switch (eventType) {
case SCI_EVT_MOUSE_PRESS:
// TODO: Implement mouse support for cursor change
break;
case SCI_EVT_KEYBOARD:
- eventKey = GET_SEL32V(segMan, eventObject, message);
+ eventKey = GET_SEL32V(_segMan, eventObject, message);
switch (eventKey) {
case SCI_K_BACKSPACE:
if (cursorPos > 0) {
@@ -203,9 +203,9 @@
if (textChanged) {
GuiResourceId oldFontId = _text->GetFontId();
- GuiResourceId fontId = GET_SEL32V(segMan, controlObject, font);
- rect = Common::Rect(GET_SEL32V(segMan, controlObject, nsLeft), GET_SEL32V(segMan, controlObject, nsTop),
- GET_SEL32V(segMan, controlObject, nsRight), GET_SEL32V(segMan, controlObject, nsBottom));
+ GuiResourceId fontId = GET_SEL32V(_segMan, controlObject, font);
+ rect = Common::Rect(GET_SEL32V(_segMan, controlObject, nsLeft), GET_SEL32V(_segMan, controlObject, nsTop),
+ GET_SEL32V(_segMan, controlObject, nsRight), GET_SEL32V(_segMan, controlObject, nsBottom));
TexteditCursorErase();
_gfx->EraseRect(rect);
_text->Box(text.c_str(), 0, rect, SCI_TEXT_ALIGNMENT_LEFT, fontId);
@@ -214,7 +214,7 @@
TexteditCursorDraw(rect, text.c_str(), cursorPos);
_text->SetFont(oldFontId);
// Write back string
- segMan->strcpy(textReference, text.c_str());
+ _segMan->strcpy(textReference, text.c_str());
} else {
if (g_system->getMillis() >= _texteditBlinkTime) {
_gfx->InvertRect(_texteditCursorRect);
@@ -224,7 +224,7 @@
}
}
- PUT_SEL32V(segMan, controlObject, cursor, cursorPos);
+ PUT_SEL32V(_segMan, controlObject, cursor, cursorPos);
}
} // End of namespace Sci
Modified: scummvm/trunk/engines/sci/gui/gui_controls.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_controls.h 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/gui/gui_controls.h 2009-11-04 14:22:17 UTC (rev 45666)
@@ -33,18 +33,19 @@
class SciGuiText;
class SciGuiControls {
public:
- SciGuiControls(SciGuiGfx *gfx, SciGuiText *text);
+ SciGuiControls(SegManager *segMan, SciGuiGfx *gfx, SciGuiText *text);
~SciGuiControls();
void drawListControl(Common::Rect rect, reg_t obj, int16 maxChars, int16 count, const char **entries, GuiResourceId fontId, int16 upperPos, int16 cursorPos, bool isAlias);
void TexteditCursorDraw(Common::Rect rect, const char *text, uint16 curPos);
void TexteditCursorErase();
- void TexteditChange(SegManager *segMan, reg_t controlObject, reg_t eventObject);
+ void TexteditChange(reg_t controlObject, reg_t eventObject);
private:
void init();
void TexteditSetBlinkTime();
+ SegManager *_segMan;
SciGuiGfx *_gfx;
SciGuiText *_text;
Modified: scummvm/trunk/engines/sci/gui/gui_gfx.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.h 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.h 2009-11-04 14:22:17 UTC (rev 45666)
@@ -53,8 +53,6 @@
void init(SciGuiText *text);
- void resetSegMan(SegManager *segMan) { _segMan = segMan; }
-
byte *GetSegment(byte seg);
void ResetScreen();
Modified: scummvm/trunk/engines/sci/gui32/gui32.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui32/gui32.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/gui32/gui32.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -408,7 +408,6 @@
void SciGui32::resetEngineState(EngineState *s) {
_s = s;
- _gfx->resetSegMan(s->_segMan);
}
void SciGui32::wait(int16 ticks) {
Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp 2009-11-04 14:17:14 UTC (rev 45665)
+++ scummvm/trunk/engines/sci/sci.cpp 2009-11-04 14:22:17 UTC (rev 45666)
@@ -133,8 +133,10 @@
_vocabulary = new Vocabulary(_resMan);
_audio = new AudioPlayer(_resMan);
+ SegManager *segMan = new SegManager(_resMan);
+
// We'll set the GUI below
- _gamestate = new EngineState(_resMan, _kernel, _vocabulary, NULL, _audio);
+ _gamestate = new EngineState(_resMan, _kernel, _vocabulary, segMan, NULL, _audio);
if (script_init_engine(_gamestate))
return Common::kUnknownError;
@@ -181,15 +183,16 @@
}
_gamestate->_gui->init(_gamestate->usesOldGfxFunctions());
+ _gamestate->_segMan = segMan;
debug("Emulating SCI version %s\n", getSciVersionDesc(getSciVersion()).c_str());
game_run(&_gamestate); // Run the game
game_exit(_gamestate);
- script_free_engine(_gamestate); // Uninitialize game state
script_free_breakpoints(_gamestate);
+ delete segMan;
delete cursor;
delete palette;
delete screen;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list