TSAGE: Cleanup custom List usage.
This makes the code use Common::List for all cases where synchronization can not be done with tSage::List::synchronise. Furthermore I renamed the custom List class to SynchronisedList to stress its purpose. I also removed clear2, contains and forEach and replaced them with algorithm usage from Common:: or in the case of "contains" replaced them with a simple inline function which uses Common::find.
This commit is contained in:
parent
0234c9ff95
commit
6db40e0c6c
12 changed files with 88 additions and 99 deletions
|
@ -537,7 +537,7 @@ void PlayerMover::setDest(const Common::Point &destPos) {
|
||||||
#define REGION_LIST_SIZE 20
|
#define REGION_LIST_SIZE 20
|
||||||
|
|
||||||
void PlayerMover::pathfind(Common::Point *routeList, Common::Point srcPos, Common::Point destPos, RouteEnds routeEnds) {
|
void PlayerMover::pathfind(Common::Point *routeList, Common::Point srcPos, Common::Point destPos, RouteEnds routeEnds) {
|
||||||
List<int> regionIndexes;
|
Common::List<int> regionIndexes;
|
||||||
RouteEnds tempRouteEnds;
|
RouteEnds tempRouteEnds;
|
||||||
int routeRegions[REGION_LIST_SIZE];
|
int routeRegions[REGION_LIST_SIZE];
|
||||||
Common::Point objPos;
|
Common::Point objPos;
|
||||||
|
@ -687,7 +687,7 @@ int PlayerMover::regionIndexOf(const Common::Point &pt) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlayerMover::findClosestRegion(Common::Point &pt, List<int> &indexList) {
|
int PlayerMover::findClosestRegion(Common::Point &pt, const Common::List<int> &indexList) {
|
||||||
int newY = pt.y;
|
int newY = pt.y;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
@ -695,35 +695,35 @@ int PlayerMover::findClosestRegion(Common::Point &pt, List<int> &indexList) {
|
||||||
int newX = pt.x + idx;
|
int newX = pt.x + idx;
|
||||||
result = regionIndexOf(newX, pt.y);
|
result = regionIndexOf(newX, pt.y);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
newY = pt.y + idx;
|
newY = pt.y + idx;
|
||||||
result = regionIndexOf(newX, newY);
|
result = regionIndexOf(newX, newY);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
newX -= idx;
|
newX -= idx;
|
||||||
result = regionIndexOf(newX, newY);
|
result = regionIndexOf(newX, newY);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
newX -= idx;
|
newX -= idx;
|
||||||
result = regionIndexOf(newX, newY);
|
result = regionIndexOf(newX, newY);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
newY -= idx;
|
newY -= idx;
|
||||||
result = regionIndexOf(newX, newY);
|
result = regionIndexOf(newX, newY);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
newY -= idx;
|
newY -= idx;
|
||||||
result = regionIndexOf(newX, newY);
|
result = regionIndexOf(newX, newY);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
newX += idx;
|
newX += idx;
|
||||||
result = regionIndexOf(newX, newY);
|
result = regionIndexOf(newX, newY);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
newX += idx;
|
newX += idx;
|
||||||
result = regionIndexOf(newX, newY);
|
result = regionIndexOf(newX, newY);
|
||||||
|
|
||||||
if ((result == 0) || indexList.contains(result)) {
|
if ((result == 0) || contains(indexList, result)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1132,7 +1132,6 @@ void PaletteRotation::remove() {
|
||||||
Action *action = _action;
|
Action *action = _action;
|
||||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_start], _start, _end - _start);
|
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_start], _start, _end - _start);
|
||||||
|
|
||||||
if (_scenePalette->_listeners.contains(this))
|
|
||||||
_scenePalette->_listeners.remove(this);
|
_scenePalette->_listeners.remove(this);
|
||||||
|
|
||||||
delete this;
|
delete this;
|
||||||
|
@ -1213,7 +1212,6 @@ void PaletteUnknown::remove() {
|
||||||
for (int i = 0; i < 256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
_scenePalette->_palette[i] = _palette[i];
|
_scenePalette->_palette[i] = _palette[i];
|
||||||
_scenePalette->refresh();
|
_scenePalette->refresh();
|
||||||
if (_scenePalette->_listeners.contains(this))
|
|
||||||
_scenePalette->_listeners.remove(this);
|
_scenePalette->_listeners.remove(this);
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
@ -1312,13 +1310,13 @@ void ScenePalette::getPalette(int start, int count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenePalette::signalListeners() {
|
void ScenePalette::signalListeners() {
|
||||||
for (List<PaletteModifier *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
|
for (SynchronisedList<PaletteModifier *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
|
||||||
(*i)->signal();
|
(*i)->signal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenePalette::clearListeners() {
|
void ScenePalette::clearListeners() {
|
||||||
List<PaletteModifier *>::iterator i = _listeners.begin();
|
SynchronisedList<PaletteModifier *>::iterator i = _listeners.begin();
|
||||||
while (i != _listeners.end()) {
|
while (i != _listeners.end()) {
|
||||||
PaletteModifier *obj = *i;
|
PaletteModifier *obj = *i;
|
||||||
++i;
|
++i;
|
||||||
|
@ -1377,6 +1375,7 @@ PaletteUnknown *ScenePalette::addUnkPal(RGB8 *arrBufferRGB, int unkNumb, bool di
|
||||||
|
|
||||||
void ScenePalette::changeBackground(const Rect &bounds, FadeMode fadeMode) {
|
void ScenePalette::changeBackground(const Rect &bounds, FadeMode fadeMode) {
|
||||||
ScenePalette tempPalette;
|
ScenePalette tempPalette;
|
||||||
|
|
||||||
if (_globals->_sceneManager._hasPalette) {
|
if (_globals->_sceneManager._hasPalette) {
|
||||||
if ((fadeMode == FADEMODE_GRADUAL) || (fadeMode == FADEMODE_IMMEDIATE)) {
|
if ((fadeMode == FADEMODE_GRADUAL) || (fadeMode == FADEMODE_IMMEDIATE)) {
|
||||||
// Fade out any active palette
|
// Fade out any active palette
|
||||||
|
@ -1397,7 +1396,10 @@ void ScenePalette::changeBackground(const Rect &bounds, FadeMode fadeMode) {
|
||||||
|
|
||||||
_globals->_screenSurface.copyFrom(_globals->_sceneManager._scene->_backSurface,
|
_globals->_screenSurface.copyFrom(_globals->_sceneManager._scene->_backSurface,
|
||||||
bounds, Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), NULL);
|
bounds, Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), NULL);
|
||||||
tempPalette._listeners.clear2();
|
|
||||||
|
for (SynchronisedList<PaletteModifier *>::iterator i = tempPalette._listeners.begin(); i != tempPalette._listeners.end(); ++i)
|
||||||
|
delete *i;
|
||||||
|
tempPalette._listeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenePalette::synchronise(Serialiser &s) {
|
void ScenePalette::synchronise(Serialiser &s) {
|
||||||
|
@ -1941,7 +1943,7 @@ int SceneObject::checkRegion(const Common::Point &pt) {
|
||||||
}
|
}
|
||||||
newY -= _yDiff;
|
newY -= _yDiff;
|
||||||
|
|
||||||
List<SceneObject *>::iterator i;
|
SynchronisedList<SceneObject *>::iterator i;
|
||||||
for (i = _globals->_sceneObjects->begin(); (regionIndex == 0) && (i != _globals->_sceneObjects->end()); ++i) {
|
for (i = _globals->_sceneObjects->begin(); (regionIndex == 0) && (i != _globals->_sceneObjects->end()); ++i) {
|
||||||
if ((*i) && ((*i)->_flags & OBJFLAG_CHECK_REGION)) {
|
if ((*i) && ((*i)->_flags & OBJFLAG_CHECK_REGION)) {
|
||||||
int objYDiff = (*i)->_position.y - _yDiff;
|
int objYDiff = (*i)->_position.y - _yDiff;
|
||||||
|
@ -2229,10 +2231,7 @@ void SceneObject::calcAngle(const Common::Point &pt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneObject::removeObject() {
|
void SceneObject::removeObject() {
|
||||||
if (_globals->_sceneItems.contains(this))
|
|
||||||
_globals->_sceneItems.remove(this);
|
_globals->_sceneItems.remove(this);
|
||||||
|
|
||||||
if (_globals->_sceneObjects->contains(this))
|
|
||||||
_globals->_sceneObjects->remove(this);
|
_globals->_sceneObjects->remove(this);
|
||||||
|
|
||||||
if (_visage) {
|
if (_visage) {
|
||||||
|
@ -2369,7 +2368,7 @@ void SceneObjectList::draw() {
|
||||||
uint32 flagMask = (paneNum == 0) ? OBJFLAG_PANE_0 : OBJFLAG_PANE_1;
|
uint32 flagMask = (paneNum == 0) ? OBJFLAG_PANE_0 : OBJFLAG_PANE_1;
|
||||||
|
|
||||||
// Initial loop to set up object list and update object position, priority, and flags
|
// Initial loop to set up object list and update object position, priority, and flags
|
||||||
for (List<SceneObject *>::iterator i = _globals->_sceneObjects->begin();
|
for (SynchronisedList<SceneObject *>::iterator i = _globals->_sceneObjects->begin();
|
||||||
i != _globals->_sceneObjects->end(); ++i) {
|
i != _globals->_sceneObjects->end(); ++i) {
|
||||||
SceneObject *obj = *i;
|
SceneObject *obj = *i;
|
||||||
objList.push_back(obj);
|
objList.push_back(obj);
|
||||||
|
@ -2523,7 +2522,7 @@ void SceneObjectList::activate() {
|
||||||
_globals->_sceneObjects_queue.push_front(this);
|
_globals->_sceneObjects_queue.push_front(this);
|
||||||
|
|
||||||
// Flag all the objects as modified
|
// Flag all the objects as modified
|
||||||
List<SceneObject *>::iterator i;
|
SynchronisedList<SceneObject *>::iterator i;
|
||||||
for (i = begin(); i != end(); ++i) {
|
for (i = begin(); i != end(); ++i) {
|
||||||
(*i)->_flags |= OBJFLAG_PANES;
|
(*i)->_flags |= OBJFLAG_PANES;
|
||||||
}
|
}
|
||||||
|
@ -2544,7 +2543,7 @@ void SceneObjectList::deactivate() {
|
||||||
_globals->_sceneObjects_queue.pop_front();
|
_globals->_sceneObjects_queue.pop_front();
|
||||||
_globals->_sceneObjects = *_globals->_sceneObjects_queue.begin();
|
_globals->_sceneObjects = *_globals->_sceneObjects_queue.begin();
|
||||||
|
|
||||||
List<SceneObject *>::iterator i;
|
SynchronisedList<SceneObject *>::iterator i;
|
||||||
for (i = objectList->begin(); i != objectList->end(); ++i) {
|
for (i = objectList->begin(); i != objectList->end(); ++i) {
|
||||||
if (!((*i)->_flags & OBJFLAG_CLONED)) {
|
if (!((*i)->_flags & OBJFLAG_CLONED)) {
|
||||||
SceneObject *sceneObj = (*i)->clone();
|
SceneObject *sceneObj = (*i)->clone();
|
||||||
|
@ -3283,9 +3282,9 @@ void WalkRegions::load(int sceneNum) {
|
||||||
* @param pt Point to locate
|
* @param pt Point to locate
|
||||||
* @param indexList List of region indexes that should be ignored
|
* @param indexList List of region indexes that should be ignored
|
||||||
*/
|
*/
|
||||||
int WalkRegions::indexOf(const Common::Point &pt, List<int> *indexList) {
|
int WalkRegions::indexOf(const Common::Point &pt, const Common::List<int> *indexList) {
|
||||||
for (uint idx = 0; idx < _regionList.size(); ++idx) {
|
for (uint idx = 0; idx < _regionList.size(); ++idx) {
|
||||||
if ((!indexList || !indexList->contains(idx + 1)) && _regionList[idx].contains(pt))
|
if ((!indexList || contains(*indexList, int(idx + 1))) && _regionList[idx].contains(pt))
|
||||||
return idx + 1;
|
return idx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3511,7 +3510,7 @@ void SceneHandler::process(Event &event) {
|
||||||
if (_globals->_player._uiEnabled && (event.eventType == EVENT_BUTTON_DOWN) &&
|
if (_globals->_player._uiEnabled && (event.eventType == EVENT_BUTTON_DOWN) &&
|
||||||
!_globals->_sceneItems.empty()) {
|
!_globals->_sceneItems.empty()) {
|
||||||
// Scan the item list to find one the mouse is within
|
// Scan the item list to find one the mouse is within
|
||||||
List<SceneItem *>::iterator i = _globals->_sceneItems.begin();
|
SynchronisedList<SceneItem *>::iterator i = _globals->_sceneItems.begin();
|
||||||
while ((i != _globals->_sceneItems.end()) && !(*i)->contains(event.mousePos))
|
while ((i != _globals->_sceneItems.end()) && !(*i)->contains(event.mousePos))
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
|
@ -3598,7 +3597,7 @@ void Game::execute() {
|
||||||
do {
|
do {
|
||||||
// Process all currently atcive game handlers
|
// Process all currently atcive game handlers
|
||||||
activeFlag = false;
|
activeFlag = false;
|
||||||
for (List<GameHandler *>::iterator i = _handlers.begin(); i != _handlers.end(); ++i) {
|
for (SynchronisedList<GameHandler *>::iterator i = _handlers.begin(); i != _handlers.end(); ++i) {
|
||||||
GameHandler *gh = *i;
|
GameHandler *gh = *i;
|
||||||
if (gh->_lockCtr.getCtr() == 0) {
|
if (gh->_lockCtr.getCtr() == 0) {
|
||||||
gh->execute();
|
gh->execute();
|
||||||
|
|
|
@ -107,7 +107,7 @@ public:
|
||||||
InvObject _jar;
|
InvObject _jar;
|
||||||
InvObject _emptyJar;
|
InvObject _emptyJar;
|
||||||
|
|
||||||
List<InvObject *> _itemList;
|
SynchronisedList<InvObject *> _itemList;
|
||||||
InvObject *_selectedItem;
|
InvObject *_selectedItem;
|
||||||
public:
|
public:
|
||||||
InvObjectList();
|
InvObjectList();
|
||||||
|
@ -264,7 +264,7 @@ protected:
|
||||||
void pathfind(Common::Point *routeList, Common::Point srcPos, Common::Point destPos, RouteEnds routeEnds);
|
void pathfind(Common::Point *routeList, Common::Point srcPos, Common::Point destPos, RouteEnds routeEnds);
|
||||||
int regionIndexOf(const Common::Point &pt);
|
int regionIndexOf(const Common::Point &pt);
|
||||||
int regionIndexOf(int xp, int yp) { return regionIndexOf(Common::Point(xp, yp)); }
|
int regionIndexOf(int xp, int yp) { return regionIndexOf(Common::Point(xp, yp)); }
|
||||||
int findClosestRegion(Common::Point &pt, List<int> &indexList);
|
int findClosestRegion(Common::Point &pt, const Common::List<int> &indexList);
|
||||||
int checkMover(Common::Point &srcPos, const Common::Point &destPos);
|
int checkMover(Common::Point &srcPos, const Common::Point &destPos);
|
||||||
void checkMovement2(const Common::Point &pt1, const Common::Point &pt2, int numSteps, Common::Point &ptOut);
|
void checkMovement2(const Common::Point &pt1, const Common::Point &pt2, int numSteps, Common::Point &ptOut);
|
||||||
int proc1(int *routeList, int srcRegion, int destRegion, int &v);
|
int proc1(int *routeList, int srcRegion, int destRegion, int &v);
|
||||||
|
@ -363,7 +363,7 @@ class ScenePalette: public SavedObject {
|
||||||
public:
|
public:
|
||||||
RGB8 _palette[256];
|
RGB8 _palette[256];
|
||||||
GfxColours _colours;
|
GfxColours _colours;
|
||||||
List<PaletteModifier *> _listeners;
|
SynchronisedList<PaletteModifier *> _listeners;
|
||||||
int _field412;
|
int _field412;
|
||||||
|
|
||||||
uint8 _redColour;
|
uint8 _redColour;
|
||||||
|
@ -684,7 +684,7 @@ public:
|
||||||
static LineSliceSet mergeSlices(const LineSliceSet &set1, const LineSliceSet &set2);
|
static LineSliceSet mergeSlices(const LineSliceSet &set1, const LineSliceSet &set2);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SceneRegions: public List<Region> {
|
class SceneRegions: public Common::List<Region> {
|
||||||
public:
|
public:
|
||||||
void load(int sceneNum);
|
void load(int sceneNum);
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ class SceneObjectList: public SavedObject {
|
||||||
private:
|
private:
|
||||||
void checkIntersection(Common::Array<SceneObject *> &ObjList, uint ObjIndex, int PaneNum);
|
void checkIntersection(Common::Array<SceneObject *> &ObjList, uint ObjIndex, int PaneNum);
|
||||||
|
|
||||||
List<SceneObject *> _objList;
|
SynchronisedList<SceneObject *> _objList;
|
||||||
bool _listAltered;
|
bool _listAltered;
|
||||||
public:
|
public:
|
||||||
SceneObjectList() { _listAltered = false; }
|
SceneObjectList() { _listAltered = false; }
|
||||||
|
@ -712,15 +712,15 @@ public:
|
||||||
void recurse(EventHandlerFn Fn) {
|
void recurse(EventHandlerFn Fn) {
|
||||||
// Loop through each object
|
// Loop through each object
|
||||||
_listAltered = false;
|
_listAltered = false;
|
||||||
for (List<SceneObject *>::iterator i = _objList.begin(); i != _objList.end() && !_listAltered; ) {
|
for (SynchronisedList<SceneObject *>::iterator i = _objList.begin(); i != _objList.end() && !_listAltered; ) {
|
||||||
SceneObject *o = *i;
|
SceneObject *o = *i;
|
||||||
++i;
|
++i;
|
||||||
Fn(o);
|
Fn(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<SceneObject *>::iterator begin() { return _objList.begin(); }
|
SynchronisedList<SceneObject *>::iterator begin() { return _objList.begin(); }
|
||||||
List<SceneObject *>::iterator end() { return _objList.end(); }
|
SynchronisedList<SceneObject *>::iterator end() { return _objList.end(); }
|
||||||
bool contains(SceneObject *sceneObj) { return _objList.contains(sceneObj); }
|
bool contains(SceneObject *sceneObj) { return tSage::contains(_objList, sceneObj); }
|
||||||
void push_back(SceneObject *sceneObj) { _objList.push_back(sceneObj); }
|
void push_back(SceneObject *sceneObj) { _objList.push_back(sceneObj); }
|
||||||
void push_front(SceneObject *sceneObj) { _objList.push_front(sceneObj); }
|
void push_front(SceneObject *sceneObj) { _objList.push_front(sceneObj); }
|
||||||
void remove(SceneObject *sceneObj) {
|
void remove(SceneObject *sceneObj) {
|
||||||
|
@ -729,7 +729,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScenePriorities: public List<Region> {
|
class ScenePriorities: public Common::List<Region> {
|
||||||
public:
|
public:
|
||||||
int _resNum;
|
int _resNum;
|
||||||
int _field14;
|
int _field14;
|
||||||
|
@ -811,7 +811,7 @@ public:
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class SceneItemList: public List<SceneItem *> {
|
class SceneItemList: public SynchronisedList<SceneItem *> {
|
||||||
public:
|
public:
|
||||||
void addItems(SceneItem *first, ...);
|
void addItems(SceneItem *first, ...);
|
||||||
};
|
};
|
||||||
|
@ -873,7 +873,7 @@ public:
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void load(int sceneNum);
|
void load(int sceneNum);
|
||||||
int indexOf(const Common::Point &pt, List<int> *indexList = NULL);
|
int indexOf(const Common::Point &pt, const Common::List<int> *indexList = NULL);
|
||||||
WalkRegion &operator[](int idx) {
|
WalkRegion &operator[](int idx) {
|
||||||
assert((idx >= 1) && (idx <= (int)_regionList.size()));
|
assert((idx >= 1) && (idx <= (int)_regionList.size()));
|
||||||
return _regionList[idx - 1];
|
return _regionList[idx - 1];
|
||||||
|
@ -934,7 +934,7 @@ public:
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
private:
|
private:
|
||||||
List<GameHandler *> _handlers;
|
SynchronisedList<GameHandler *> _handlers;
|
||||||
|
|
||||||
static bool notLockedFn(GameHandler *g);
|
static bool notLockedFn(GameHandler *g);
|
||||||
void restart();
|
void restart();
|
||||||
|
|
|
@ -126,7 +126,7 @@ bool Debugger::Cmd_PriorityRegions(int argc, const char **argv) {
|
||||||
// Lock the background surface for access
|
// Lock the background surface for access
|
||||||
Graphics::Surface destSurface = _globals->_sceneManager._scene->_backSurface.lockSurface();
|
Graphics::Surface destSurface = _globals->_sceneManager._scene->_backSurface.lockSurface();
|
||||||
|
|
||||||
List<Region>::iterator i = _globals->_sceneManager._scene->_priorities.begin();
|
Common::List<Region>::iterator i = _globals->_sceneManager._scene->_priorities.begin();
|
||||||
Common::String regionsDesc;
|
Common::String regionsDesc;
|
||||||
|
|
||||||
for (; i != _globals->_sceneManager._scene->_priorities.end(); ++i, ++colour, ++count) {
|
for (; i != _globals->_sceneManager._scene->_priorities.end(); ++i, ++colour, ++count) {
|
||||||
|
|
|
@ -383,7 +383,7 @@ void InventoryDialog::show(bool allFlag) {
|
||||||
if (!allFlag) {
|
if (!allFlag) {
|
||||||
// Determine how many items are in the player's inventory
|
// Determine how many items are in the player's inventory
|
||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
List<InvObject *>::iterator i;
|
SynchronisedList<InvObject *>::iterator i;
|
||||||
for (i = _globals->_inventory._itemList.begin(); i != _globals->_inventory._itemList.end(); ++i) {
|
for (i = _globals->_inventory._itemList.begin(); i != _globals->_inventory._itemList.end(); ++i) {
|
||||||
if ((*i)->inInventory())
|
if ((*i)->inInventory())
|
||||||
++itemCount;
|
++itemCount;
|
||||||
|
@ -405,7 +405,7 @@ InventoryDialog::InventoryDialog(bool allFlag) {
|
||||||
// Determine the maximum size of the image of any item in the player's inventory
|
// Determine the maximum size of the image of any item in the player's inventory
|
||||||
int imgWidth = 0, imgHeight = 0;
|
int imgWidth = 0, imgHeight = 0;
|
||||||
|
|
||||||
List<InvObject *>::iterator i;
|
SynchronisedList<InvObject *>::iterator i;
|
||||||
for (i = _globals->_inventory._itemList.begin(); i != _globals->_inventory._itemList.end(); ++i) {
|
for (i = _globals->_inventory._itemList.begin(); i != _globals->_inventory._itemList.end(); ++i) {
|
||||||
InvObject *invObject = *i;
|
InvObject *invObject = *i;
|
||||||
if (allFlag || invObject->inInventory()) {
|
if (allFlag || invObject->inInventory()) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Globals: public SavedObject {
|
||||||
public:
|
public:
|
||||||
GfxSurface _screenSurface;
|
GfxSurface _screenSurface;
|
||||||
GfxManager _gfxManagerInstance;
|
GfxManager _gfxManagerInstance;
|
||||||
List<GfxManager *> _gfxManagers;
|
Common::List<GfxManager *> _gfxManagers;
|
||||||
SceneHandler _sceneHandler;
|
SceneHandler _sceneHandler;
|
||||||
Game _game;
|
Game _game;
|
||||||
EventsClass _events;
|
EventsClass _events;
|
||||||
|
@ -49,7 +49,7 @@ public:
|
||||||
SceneItemList _sceneItems;
|
SceneItemList _sceneItems;
|
||||||
SceneObjectList _sceneObjectsInstance;
|
SceneObjectList _sceneObjectsInstance;
|
||||||
SceneObjectList *_sceneObjects;
|
SceneObjectList *_sceneObjects;
|
||||||
List<SceneObjectList *> _sceneObjects_queue;
|
SynchronisedList<SceneObjectList *> _sceneObjects_queue;
|
||||||
SceneText _sceneText;
|
SceneText _sceneText;
|
||||||
int _gfxFontNumber;
|
int _gfxFontNumber;
|
||||||
GfxColours _gfxColours;
|
GfxColours _gfxColours;
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
SoundManager _soundManager;
|
SoundManager _soundManager;
|
||||||
Common::Point _dialogCentre;
|
Common::Point _dialogCentre;
|
||||||
WalkRegions _walkRegions;
|
WalkRegions _walkRegions;
|
||||||
List<EventHandler *> _sceneListeners;
|
SynchronisedList<EventHandler *> _sceneListeners;
|
||||||
bool _flags[256];
|
bool _flags[256];
|
||||||
Player _player;
|
Player _player;
|
||||||
SoundHandler _soundHandler;
|
SoundHandler _soundHandler;
|
||||||
|
|
|
@ -1018,7 +1018,7 @@ void GfxManager::setDefaults() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxManager::activate() {
|
void GfxManager::activate() {
|
||||||
assert(!_globals->_gfxManagers.contains(this));
|
assert(!contains(_globals->_gfxManagers, this));
|
||||||
_globals->_gfxManagers.push_front(this);
|
_globals->_gfxManagers.push_front(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ void SceneArea::wait() {
|
||||||
g_system->delayMillis(10);
|
g_system->delayMillis(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SceneItem *>::iterator ii;
|
SynchronisedList<SceneItem *>::iterator ii;
|
||||||
for (ii = _globals->_sceneItems.begin(); ii != _globals->_sceneItems.end(); ++ii) {
|
for (ii = _globals->_sceneItems.begin(); ii != _globals->_sceneItems.end(); ++ii) {
|
||||||
SceneItem *sceneItem = *ii;
|
SceneItem *sceneItem = *ii;
|
||||||
if (sceneItem->contains(event.mousePos)) {
|
if (sceneItem->contains(event.mousePos)) {
|
||||||
|
|
|
@ -2714,7 +2714,7 @@ void Scene2200::Action3::signal() {
|
||||||
_actionIndex = 8;
|
_actionIndex = 8;
|
||||||
setDelay(5);
|
setDelay(5);
|
||||||
} else {
|
} else {
|
||||||
for (List<SceneObject *>::iterator i = _globals->_sceneObjects->begin();
|
for (SynchronisedList<SceneObject *>::iterator i = _globals->_sceneObjects->begin();
|
||||||
i != _globals->_sceneObjects->end(); ++i) {
|
i != _globals->_sceneObjects->end(); ++i) {
|
||||||
(*i)->hide();
|
(*i)->hide();
|
||||||
}
|
}
|
||||||
|
@ -2751,7 +2751,7 @@ void Scene2200::Action3::signal() {
|
||||||
setDelay(5);
|
setDelay(5);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
for (List<SceneObject *>::iterator i = _globals->_sceneObjects->begin();
|
for (SynchronisedList<SceneObject *>::iterator i = _globals->_sceneObjects->begin();
|
||||||
i != _globals->_sceneObjects->end(); ++i)
|
i != _globals->_sceneObjects->end(); ++i)
|
||||||
(*i)->show();
|
(*i)->show();
|
||||||
|
|
||||||
|
|
|
@ -2239,7 +2239,7 @@ void Scene7700::signal() {
|
||||||
void Scene7700::process(Event &event) {
|
void Scene7700::process(Event &event) {
|
||||||
Scene::process(event);
|
Scene::process(event);
|
||||||
|
|
||||||
if (_globals->_sceneItems.contains(&_sceneItem10)) {
|
if (contains<SceneItem *>(_globals->_sceneItems, &_sceneItem10)) {
|
||||||
if (_gfxButton.process(event)) {
|
if (_gfxButton.process(event)) {
|
||||||
_sceneItem10.remove();
|
_sceneItem10.remove();
|
||||||
_sceneHotspot15.remove();
|
_sceneHotspot15.remove();
|
||||||
|
|
|
@ -52,7 +52,7 @@ Saver::Saver() {
|
||||||
Saver::~Saver() {
|
Saver::~Saver() {
|
||||||
// Internal validation that no saved object is still present
|
// Internal validation that no saved object is still present
|
||||||
int totalLost = 0;
|
int totalLost = 0;
|
||||||
for (List<SavedObject *>::iterator i = _saver->_objList.begin(); i != _saver->_objList.end(); ++i) {
|
for (SynchronisedList<SavedObject *>::iterator i = _saver->_objList.begin(); i != _saver->_objList.end(); ++i) {
|
||||||
SavedObject *so = *i;
|
SavedObject *so = *i;
|
||||||
if (so)
|
if (so)
|
||||||
++totalLost;
|
++totalLost;
|
||||||
|
@ -128,12 +128,12 @@ Common::Error Saver::save(int slot, const Common::String &saveName) {
|
||||||
writeSavegameHeader(saveFile, header);
|
writeSavegameHeader(saveFile, header);
|
||||||
|
|
||||||
// Save out objects that need to come at the start of the savegame
|
// Save out objects that need to come at the start of the savegame
|
||||||
for (List<SaveListener *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
|
for (SynchronisedList<SaveListener *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
|
||||||
(*i)->listenerSynchronise(serialiser);
|
(*i)->listenerSynchronise(serialiser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save each registered SaveObject descendant object into the savegame file
|
// Save each registered SaveObject descendant object into the savegame file
|
||||||
for (List<SavedObject *>::iterator i = _objList.begin(); i != _objList.end(); ++i) {
|
for (SynchronisedList<SavedObject *>::iterator i = _objList.begin(); i != _objList.end(); ++i) {
|
||||||
serialiser.validate((*i)->getClassName());
|
serialiser.validate((*i)->getClassName());
|
||||||
(*i)->synchronise(serialiser);
|
(*i)->synchronise(serialiser);
|
||||||
}
|
}
|
||||||
|
@ -171,12 +171,12 @@ Common::Error Saver::restore(int slot) {
|
||||||
delete header.thumbnail;
|
delete header.thumbnail;
|
||||||
|
|
||||||
// Load in data for objects that need to come at the start of the savegame
|
// Load in data for objects that need to come at the start of the savegame
|
||||||
for (List<SaveListener *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
|
for (Common::List<SaveListener *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
|
||||||
(*i)->listenerSynchronise(serialiser);
|
(*i)->listenerSynchronise(serialiser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each registered object to load in the data
|
// Loop through each registered object to load in the data
|
||||||
for (List<SavedObject *>::iterator i = _objList.begin(); i != _objList.end(); ++i) {
|
for (SynchronisedList<SavedObject *>::iterator i = _objList.begin(); i != _objList.end(); ++i) {
|
||||||
serialiser.validate((*i)->getClassName());
|
serialiser.validate((*i)->getClassName());
|
||||||
(*i)->synchronise(serialiser);
|
(*i)->synchronise(serialiser);
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ bool Saver::savegamesExist() const {
|
||||||
*/
|
*/
|
||||||
int Saver::blockIndexOf(SavedObject *p) {
|
int Saver::blockIndexOf(SavedObject *p) {
|
||||||
int objIndex = 1;
|
int objIndex = 1;
|
||||||
List<SavedObject *>::iterator iObj;
|
SynchronisedList<SavedObject *>::iterator iObj;
|
||||||
|
|
||||||
for (iObj = _objList.begin(); iObj != _objList.end(); ++iObj, ++objIndex) {
|
for (iObj = _objList.begin(); iObj != _objList.end(); ++iObj, ++objIndex) {
|
||||||
SavedObject *iObjP = *iObj;
|
SavedObject *iObjP = *iObj;
|
||||||
|
@ -364,7 +364,7 @@ void Saver::resolveLoadPointers() {
|
||||||
|
|
||||||
// Outer loop through the main object list
|
// Outer loop through the main object list
|
||||||
int objIndex = 1;
|
int objIndex = 1;
|
||||||
for (List<SavedObject *>::iterator iObj = _objList.begin(); iObj != _objList.end(); ++iObj, ++objIndex) {
|
for (SynchronisedList<SavedObject *>::iterator iObj = _objList.begin(); iObj != _objList.end(); ++iObj, ++objIndex) {
|
||||||
Common::List<SavedObjectRef>::iterator iPtr;
|
Common::List<SavedObjectRef>::iterator iPtr;
|
||||||
|
|
||||||
for (iPtr = _unresolvedPtrs.begin(); iPtr != _unresolvedPtrs.end(); ) {
|
for (iPtr = _unresolvedPtrs.begin(); iPtr != _unresolvedPtrs.end(); ) {
|
||||||
|
|
|
@ -103,63 +103,53 @@ public:
|
||||||
* Derived list class with extra functionality
|
* Derived list class with extra functionality
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class List: public Common::List<T> {
|
class SynchronisedList : public Common::List<T> {
|
||||||
public:
|
public:
|
||||||
bool contains(T v) {
|
|
||||||
for (typename List<T>::iterator i = this->begin(); i != this->end(); ++i)
|
|
||||||
if (*i == v)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef void (*ForEachFn)(T fn);
|
|
||||||
void forEach(ForEachFn Fn) {
|
|
||||||
for (typename List<T>::iterator i = this->begin(); i != this->end(); ++i)
|
|
||||||
Fn(*i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear2() {
|
|
||||||
for (typename List<T>::iterator i = this->begin(); i != this->end(); ++i)
|
|
||||||
delete *i;
|
|
||||||
Common::List<T>::clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void synchronise(Serialiser &s) {
|
void synchronise(Serialiser &s) {
|
||||||
int entryCount;
|
int entryCount;
|
||||||
|
|
||||||
if (s.isLoading()) {
|
if (s.isLoading()) {
|
||||||
List<T>::clear();
|
this->clear();
|
||||||
s.syncAsUint32LE(entryCount);
|
s.syncAsUint32LE(entryCount);
|
||||||
|
|
||||||
for (int idx = 0; idx < entryCount; ++idx) {
|
for (int idx = 0; idx < entryCount; ++idx) {
|
||||||
List<T>::push_back(static_cast<T>((T)NULL));
|
this->push_back(static_cast<T>((T)NULL));
|
||||||
T &obj = List<T>::back();
|
T &obj = Common::List<T>::back();
|
||||||
s.syncPointer((SavedObject **)&obj);
|
s.syncPointer((SavedObject **)&obj);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Get the list size
|
// Get the list size
|
||||||
entryCount = 0;
|
entryCount = this->size();
|
||||||
typename List<T>::iterator i;
|
|
||||||
for (i = List<T>::begin(); i != List<T>::end(); ++i, ++entryCount)
|
|
||||||
;
|
|
||||||
|
|
||||||
// Write out list
|
// Write out list
|
||||||
s.syncAsUint32LE(entryCount);
|
s.syncAsUint32LE(entryCount);
|
||||||
for (i = List<T>::begin(); i != List<T>::end(); ++i) {
|
for (typename Common::List<T>::iterator i = this->begin(); i != this->end(); ++i) {
|
||||||
s.syncPointer((SavedObject **)&*i);
|
s.syncPointer((SavedObject **)&*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search whether an element is contained in a list.
|
||||||
|
*
|
||||||
|
* @param l List to search.
|
||||||
|
* @param v Element to search for.
|
||||||
|
* @return True in case the element is contained, false otherwise.
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
inline bool contains(const Common::List<T> &l, const T &v) {
|
||||||
|
return (Common::find(l.begin(), l.end(), v) != l.end());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derived list class for holding function pointers
|
* Derived list class for holding function pointers
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class FunctionList: public List<void (*)(T)> {
|
class FunctionList : public Common::List<void (*)(T)> {
|
||||||
public:
|
public:
|
||||||
void notify(T v) {
|
void notify(T v) {
|
||||||
for (typename List<void (*)(T)>::iterator i = this->begin(); i != this->end(); ++i) {
|
for (typename Common::List<void (*)(T)>::iterator i = this->begin(); i != this->end(); ++i) {
|
||||||
(*i)(v);
|
(*i)(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,10 +170,10 @@ typedef SavedObject *(*SavedObjectFactory)(const Common::String &className);
|
||||||
|
|
||||||
class Saver {
|
class Saver {
|
||||||
private:
|
private:
|
||||||
List<SavedObject *> _objList;
|
SynchronisedList<SavedObject *> _objList;
|
||||||
FunctionList<bool> _saveNotifiers;
|
FunctionList<bool> _saveNotifiers;
|
||||||
FunctionList<bool> _loadNotifiers;
|
FunctionList<bool> _loadNotifiers;
|
||||||
List<SaveListener *> _listeners;
|
Common::List<SaveListener *> _listeners;
|
||||||
|
|
||||||
Common::List<SavedObjectRef> _unresolvedPtrs;
|
Common::List<SavedObjectRef> _unresolvedPtrs;
|
||||||
SavedObjectFactory _factoryPtr;
|
SavedObjectFactory _factoryPtr;
|
||||||
|
|
|
@ -55,7 +55,7 @@ void SceneManager::checkScene() {
|
||||||
_nextSceneNumber = -1;
|
_nextSceneNumber = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_globals->_sceneListeners.forEach(SceneHandler::dispatchObject);
|
Common::for_each(_globals->_sceneListeners.begin(), _globals->_sceneListeners.end(), SceneHandler::dispatchObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneManager::sceneChange() {
|
void SceneManager::sceneChange() {
|
||||||
|
@ -64,7 +64,7 @@ void SceneManager::sceneChange() {
|
||||||
_scene->remove();
|
_scene->remove();
|
||||||
|
|
||||||
// Clear the scene objects
|
// Clear the scene objects
|
||||||
List<SceneObject *>::iterator io = _globals->_sceneObjects->begin();
|
SynchronisedList<SceneObject *>::iterator io = _globals->_sceneObjects->begin();
|
||||||
while (io != _globals->_sceneObjects->end()) {
|
while (io != _globals->_sceneObjects->end()) {
|
||||||
SceneObject *sceneObj = *io;
|
SceneObject *sceneObj = *io;
|
||||||
++io;
|
++io;
|
||||||
|
@ -80,7 +80,7 @@ void SceneManager::sceneChange() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the hotspot list
|
// Clear the hotspot list
|
||||||
List<SceneItem *>::iterator ii = _globals->_sceneItems.begin();
|
SynchronisedList<SceneItem *>::iterator ii = _globals->_sceneItems.begin();
|
||||||
while (ii != _globals->_sceneItems.end()) {
|
while (ii != _globals->_sceneItems.end()) {
|
||||||
SceneItem *sceneItem = *ii;
|
SceneItem *sceneItem = *ii;
|
||||||
++ii;
|
++ii;
|
||||||
|
@ -145,7 +145,7 @@ void SceneManager::changeScene(int newSceneNumber) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop any objects that were animating
|
// Stop any objects that were animating
|
||||||
List<SceneObject *>::iterator i;
|
SynchronisedList<SceneObject *>::iterator i;
|
||||||
for (i = _globals->_sceneObjects->begin(); i != _globals->_sceneObjects->end(); ++i) {
|
for (i = _globals->_sceneObjects->begin(); i != _globals->_sceneObjects->end(); ++i) {
|
||||||
SceneObject *sceneObj = *i;
|
SceneObject *sceneObj = *i;
|
||||||
Common::Point pt(0, 0);
|
Common::Point pt(0, 0);
|
||||||
|
@ -411,7 +411,7 @@ void Scene::drawAltObjects() {
|
||||||
Common::Array<SceneObject *> objList;
|
Common::Array<SceneObject *> objList;
|
||||||
|
|
||||||
// Initial loop to set the priority for entries in the list
|
// Initial loop to set the priority for entries in the list
|
||||||
for (List<SceneObject *>::iterator i = _globals->_sceneManager._altSceneObjects.begin();
|
for (SynchronisedList<SceneObject *>::iterator i = _globals->_sceneManager._altSceneObjects.begin();
|
||||||
i != _globals->_sceneManager._altSceneObjects.end(); ++i) {
|
i != _globals->_sceneManager._altSceneObjects.end(); ++i) {
|
||||||
SceneObject *obj = *i;
|
SceneObject *obj = *i;
|
||||||
objList.push_back(obj);
|
objList.push_back(obj);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue