Skip to content

Commit

Permalink
SCI: Moved the engine hunk pointer processing code inside the GfxPort…
Browse files Browse the repository at this point in the history
…s class

This allows us make _windowList private again
  • Loading branch information
bluegr committed Mar 20, 2011
1 parent 4df049f commit 89f9c5a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
47 changes: 15 additions & 32 deletions engines/sci/engine/gc.cpp
Expand Up @@ -49,28 +49,23 @@ const char *segmentTypeNames[] = {
};
#endif

struct WorklistManager {
Common::Array<reg_t> _worklist;
AddrSet _map; // used for 2 contains() calls, inside push() and run_gc()
void WorklistManager::push(reg_t reg) {
if (!reg.segment) // No numbers
return;

void push(reg_t reg) {
if (!reg.segment) // No numbers
return;
debugC(kDebugLevelGC, "[GC] Adding %04x:%04x", PRINT_REG(reg));

debugC(kDebugLevelGC, "[GC] Adding %04x:%04x", PRINT_REG(reg));
if (_map.contains(reg))
return; // already dealt with it

if (_map.contains(reg))
return; // already dealt with it

_map.setVal(reg, true);
_worklist.push_back(reg);
}
_map.setVal(reg, true);
_worklist.push_back(reg);
}

void pushArray(const Common::Array<reg_t> &tmp) {
for (Common::Array<reg_t>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
push(*it);
}
};
void WorklistManager::pushArray(const Common::Array<reg_t> &tmp) {
for (Common::Array<reg_t>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
push(*it);
}

static AddrSet *normalizeAddresses(SegManager *segMan, const AddrSet &nonnormal_map) {
AddrSet *normal_map = new AddrSet();
Expand Down Expand Up @@ -103,18 +98,6 @@ static void processWorkList(SegManager *segMan, WorklistManager &wm, const Commo
}
}

static void processEngineHunkList(WorklistManager &wm) {
PortList windowList = g_sci->_gfxPorts->_windowList;

for (PortList::const_iterator it = windowList.begin(); it != windowList.end(); ++it) {
if ((*it)->isWindow()) {
Window *wnd = ((Window *)*it);
wm.push(wnd->hSaved1);
wm.push(wnd->hSaved2);
}
}
}

AddrSet *findAllActiveReferences(EngineState *s) {
assert(!s->_executionStack.empty());

Expand Down Expand Up @@ -174,8 +157,8 @@ AddrSet *findAllActiveReferences(EngineState *s) {

processWorkList(s->_segMan, wm, heap);

if (getSciVersion() <= SCI_VERSION_1_1)
processEngineHunkList(wm);
if (g_sci->_gfxPorts)
g_sci->_gfxPorts->processEngineHunkList(wm);

return normalizeAddresses(s->_segMan, wm._map);
}
Expand Down
9 changes: 9 additions & 0 deletions engines/sci/engine/gc.h
Expand Up @@ -58,6 +58,15 @@ AddrSet *findAllActiveReferences(EngineState *s);
*/
void run_gc(EngineState *s);

struct WorklistManager {
Common::Array<reg_t> _worklist;
AddrSet _map; // used for 2 contains() calls, inside push() and run_gc()

void push(reg_t reg);
void pushArray(const Common::Array<reg_t> &tmp);
};


} // End of namespace Sci

#endif // SCI_ENGINE_GC_H
11 changes: 11 additions & 0 deletions engines/sci/graphics/ports.cpp
Expand Up @@ -28,6 +28,7 @@
#include "sci/console.h"
#include "sci/sci.h"
#include "sci/engine/features.h"
#include "sci/engine/gc.h"
#include "sci/engine/kernel.h"
#include "sci/engine/state.h"
#include "sci/engine/selector.h"
Expand Down Expand Up @@ -708,6 +709,16 @@ int16 GfxPorts::kernelPriorityToCoordinate(byte priority) {
return _priorityBottom;
}

void GfxPorts::processEngineHunkList(WorklistManager &wm) {
for (PortList::const_iterator it = _windowList.begin(); it != _windowList.end(); ++it) {
if ((*it)->isWindow()) {
Window *wnd = ((Window *)*it);
wm.push(wnd->hSaved1);
wm.push(wnd->hSaved2);
}
}
}

void GfxPorts::printWindowList(Console *con) {
for (PortList::const_iterator it = _windowList.begin(); it != _windowList.end(); ++it) {
if ((*it)->isWindow()) {
Expand Down
4 changes: 3 additions & 1 deletion engines/sci/graphics/ports.h
Expand Up @@ -35,6 +35,7 @@ namespace Sci {
class GfxPaint16;
class GfxScreen;
class GfxText16;
struct WorklistManager;

// window styles
enum {
Expand Down Expand Up @@ -102,6 +103,7 @@ class GfxPorts : public Common::Serializable {
void kernelGraphAdjustPriority(int top, int bottom);
byte kernelCoordinateToPriority(int16 y);
int16 kernelPriorityToCoordinate(byte priority);
void processEngineHunkList(WorklistManager &wm);
void printWindowList(Console *con);

Port *_wmgrPort;
Expand All @@ -115,10 +117,10 @@ class GfxPorts : public Common::Serializable {

virtual void saveLoadWithSerializer(Common::Serializer &ser);

private:
/** The list of open 'windows' (and ports), in visual order. */
PortList _windowList;

private:
/** The list of all open 'windows' (and ports), ordered by their id. */
PortArray _windowsById;

Expand Down

0 comments on commit 89f9c5a

Please sign in to comment.