LAB: Avoid manual memory management of CloseData
This commit is contained in:
parent
1a1525a155
commit
0d97d1af82
7 changed files with 72 additions and 114 deletions
|
@ -568,7 +568,6 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
|
||||||
|
|
||||||
uint16 oldDirection = 0;
|
uint16 oldDirection = 0;
|
||||||
uint16 lastInv = kItemMap;
|
uint16 lastInv = kItemMap;
|
||||||
CloseDataPtr wrkClosePtr = nullptr;
|
|
||||||
bool leftButtonClick = false;
|
bool leftButtonClick = false;
|
||||||
bool rightButtonClick = false;
|
bool rightButtonClick = false;
|
||||||
|
|
||||||
|
@ -640,29 +639,24 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
|
||||||
mayShowCrumbIndicator();
|
mayShowCrumbIndicator();
|
||||||
_graphics->screenUpdate();
|
_graphics->screenUpdate();
|
||||||
} else if (msgClass == kMessageDeltaMove) {
|
} else if (msgClass == kMessageDeltaMove) {
|
||||||
ViewData *vptr = getViewData(_roomNum, _direction);
|
|
||||||
CloseDataPtr oldClosePtr = vptr->_closeUps;
|
|
||||||
CloseDataPtr tmpClosePtr = _closeDataPtr;
|
CloseDataPtr tmpClosePtr = _closeDataPtr;
|
||||||
setCurrentClose(curPos, &tmpClosePtr, true);
|
|
||||||
|
|
||||||
if (!tmpClosePtr || (tmpClosePtr == _closeDataPtr)) {
|
// get next close-up in list after the one pointed to by curPos
|
||||||
if (!_closeDataPtr)
|
setCurrentClose(curPos, &tmpClosePtr, true, true);
|
||||||
wrkClosePtr = oldClosePtr;
|
|
||||||
else
|
|
||||||
wrkClosePtr = _closeDataPtr->_subCloseUps;
|
|
||||||
} else
|
|
||||||
wrkClosePtr = tmpClosePtr->_nextCloseUp;
|
|
||||||
|
|
||||||
|
if (tmpClosePtr == _closeDataPtr) {
|
||||||
if (!wrkClosePtr) {
|
tmpClosePtr = nullptr;
|
||||||
if (!_closeDataPtr)
|
if (!_closeDataPtr) {
|
||||||
wrkClosePtr = oldClosePtr;
|
ViewData *vptr = getViewData(_roomNum, _direction);
|
||||||
else
|
if (!vptr->_closeUps.empty())
|
||||||
wrkClosePtr = _closeDataPtr->_subCloseUps;
|
tmpClosePtr = &(*vptr->_closeUps.begin());
|
||||||
|
} else {
|
||||||
|
if (!_closeDataPtr->_subCloseUps.empty())
|
||||||
|
tmpClosePtr = &(*_closeDataPtr->_subCloseUps.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (tmpClosePtr)
|
||||||
if (wrkClosePtr)
|
_event->setMousePos(Common::Point(_utils->scaleX((tmpClosePtr->_x1 + tmpClosePtr->_x2) / 2), _utils->scaleY((tmpClosePtr->_y1 + tmpClosePtr->_y2) / 2)));
|
||||||
_event->setMousePos(Common::Point(_utils->scaleX((wrkClosePtr->_x1 + wrkClosePtr->_x2) / 2), _utils->scaleY((wrkClosePtr->_y1 + wrkClosePtr->_y2) / 2)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -141,8 +141,6 @@ LabEngine::~LabEngine() {
|
||||||
DebugMan.clearAllDebugChannels();
|
DebugMan.clearAllDebugChannels();
|
||||||
|
|
||||||
freeMapData();
|
freeMapData();
|
||||||
for (int i = 1; i <= _manyRooms; i++)
|
|
||||||
_resource->freeViews(i);
|
|
||||||
delete[] _rooms;
|
delete[] _rooms;
|
||||||
delete[] _inventory;
|
delete[] _inventory;
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,7 @@ private:
|
||||||
* some of the closeups have the same hit boxes, then this returns the first
|
* some of the closeups have the same hit boxes, then this returns the first
|
||||||
* occurrence of the object with the same hit box.
|
* occurrence of the object with the same hit box.
|
||||||
*/
|
*/
|
||||||
CloseDataPtr findClosePtrMatch(CloseDataPtr closePtr, CloseDataPtr closePtrList);
|
CloseDataPtr findClosePtrMatch(CloseDataPtr closePtr, Common::List<CloseData> &list);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a floor has been visited.
|
* Checks if a floor has been visited.
|
||||||
|
@ -441,7 +441,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* Sets the current close up data.
|
* Sets the current close up data.
|
||||||
*/
|
*/
|
||||||
void setCurrentClose(Common::Point pos, CloseDataPtr *closePtrList, bool useAbsoluteCoords);
|
void setCurrentClose(Common::Point pos, CloseDataPtr *closePtrList, bool useAbsoluteCoords, bool next=false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes the currently selected item.
|
* Takes the currently selected item.
|
||||||
|
|
|
@ -69,39 +69,37 @@ ViewData *LabEngine::getViewData(uint16 roomNum, uint16 direction) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseData *LabEngine::getObject(Common::Point pos, CloseDataPtr closePtr) {
|
CloseData *LabEngine::getObject(Common::Point pos, CloseDataPtr closePtr) {
|
||||||
CloseDataPtr wrkClosePtr;
|
Common::List<CloseData> *list;
|
||||||
if (!closePtr)
|
if (!closePtr)
|
||||||
wrkClosePtr = getViewData(_roomNum, _direction)->_closeUps;
|
list = &(getViewData(_roomNum, _direction)->_closeUps);
|
||||||
else
|
else
|
||||||
wrkClosePtr = closePtr->_subCloseUps;
|
list = &(closePtr->_subCloseUps);
|
||||||
|
|
||||||
Common::Rect objRect;
|
Common::List<CloseData>::iterator wrkClosePtr;
|
||||||
while (wrkClosePtr) {
|
for (wrkClosePtr = list->begin(); wrkClosePtr != list->end(); ++wrkClosePtr) {
|
||||||
|
Common::Rect objRect;
|
||||||
objRect = _utils->rectScale(wrkClosePtr->_x1, wrkClosePtr->_y1, wrkClosePtr->_x2, wrkClosePtr->_y2);
|
objRect = _utils->rectScale(wrkClosePtr->_x1, wrkClosePtr->_y1, wrkClosePtr->_x2, wrkClosePtr->_y2);
|
||||||
if (objRect.contains(pos))
|
if (objRect.contains(pos))
|
||||||
return wrkClosePtr;
|
return &(*wrkClosePtr);
|
||||||
|
|
||||||
wrkClosePtr = wrkClosePtr->_nextCloseUp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseDataPtr LabEngine::findClosePtrMatch(CloseDataPtr closePtr, CloseDataPtr closePtrList) {
|
CloseDataPtr LabEngine::findClosePtrMatch(CloseDataPtr closePtr, Common::List<CloseData> &list) {
|
||||||
CloseDataPtr resClosePtr;
|
Common::List<CloseData>::iterator i;
|
||||||
|
|
||||||
while (closePtrList) {
|
for (i = list.begin(); i != list.end(); ++i) {
|
||||||
if ((closePtr->_x1 == closePtrList->_x1) && (closePtr->_x2 == closePtrList->_x2) &&
|
if ((closePtr->_x1 == i->_x1) && (closePtr->_x2 == i->_x2) &&
|
||||||
(closePtr->_y1 == closePtrList->_y1) && (closePtr->_y2 == closePtrList->_y2) &&
|
(closePtr->_y1 == i->_y1) && (closePtr->_y2 == i->_y2) &&
|
||||||
(closePtr->_depth == closePtrList->_depth))
|
(closePtr->_depth == i->_depth))
|
||||||
return closePtrList;
|
return &(*i);
|
||||||
|
|
||||||
resClosePtr = findClosePtrMatch(closePtr, closePtrList->_subCloseUps);
|
CloseDataPtr resClosePtr;
|
||||||
|
resClosePtr = findClosePtrMatch(closePtr, i->_subCloseUps);
|
||||||
|
|
||||||
if (resClosePtr)
|
if (resClosePtr)
|
||||||
return resClosePtr;
|
return resClosePtr;
|
||||||
else
|
|
||||||
closePtrList = closePtrList->_nextCloseUp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -174,50 +172,56 @@ uint16 LabEngine::processArrow(uint16 curDirection, uint16 arrow) {
|
||||||
return curDirection;
|
return curDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LabEngine::setCurrentClose(Common::Point pos, CloseDataPtr *closePtrList, bool useAbsoluteCoords) {
|
void LabEngine::setCurrentClose(Common::Point pos, CloseDataPtr *closePtrList, bool useAbsoluteCoords, bool next) {
|
||||||
CloseDataPtr closePtr;
|
|
||||||
|
Common::List<CloseData> *list;
|
||||||
|
|
||||||
if (!*closePtrList)
|
if (!*closePtrList)
|
||||||
closePtr = getViewData(_roomNum, _direction)->_closeUps;
|
list = &(getViewData(_roomNum, _direction)->_closeUps);
|
||||||
else
|
else
|
||||||
closePtr = (*closePtrList)->_subCloseUps;
|
list = &((*closePtrList)->_subCloseUps);
|
||||||
|
|
||||||
Common::Rect target;
|
Common::List<CloseData>::iterator closePtr;
|
||||||
while (closePtr) {
|
for (closePtr = list->begin(); closePtr != list->end(); ++closePtr) {
|
||||||
|
Common::Rect target;
|
||||||
if (!useAbsoluteCoords)
|
if (!useAbsoluteCoords)
|
||||||
target = Common::Rect(closePtr->_x1, closePtr->_y1, closePtr->_x2, closePtr->_y2);
|
target = Common::Rect(closePtr->_x1, closePtr->_y1, closePtr->_x2, closePtr->_y2);
|
||||||
else
|
else
|
||||||
target = _utils->rectScale(closePtr->_x1, closePtr->_y1, closePtr->_x2, closePtr->_y2);
|
target = _utils->rectScale(closePtr->_x1, closePtr->_y1, closePtr->_x2, closePtr->_y2);
|
||||||
|
|
||||||
if (target.contains(pos) && !closePtr->_graphicName.empty()) {
|
if (target.contains(pos) && !closePtr->_graphicName.empty()) {
|
||||||
*closePtrList = closePtr;
|
|
||||||
|
if (next) {
|
||||||
|
// cycle to the next one
|
||||||
|
++closePtr;
|
||||||
|
if (closePtr == list->end())
|
||||||
|
closePtr = list->begin();
|
||||||
|
}
|
||||||
|
*closePtrList = &(*closePtr);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
closePtr = closePtr->_nextCloseUp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LabEngine::takeItem(Common::Point pos, CloseDataPtr *closePtrList) {
|
bool LabEngine::takeItem(Common::Point pos, CloseDataPtr *closePtrList) {
|
||||||
CloseDataPtr closePtr;
|
Common::List<CloseData> *list;
|
||||||
|
|
||||||
if (!*closePtrList) {
|
if (!*closePtrList) {
|
||||||
closePtr = getViewData(_roomNum, _direction)->_closeUps;
|
list = &(getViewData(_roomNum, _direction)->_closeUps);
|
||||||
} else if ((*closePtrList)->_closeUpType < 0) {
|
} else if ((*closePtrList)->_closeUpType < 0) {
|
||||||
_conditions->inclElement(abs((*closePtrList)->_closeUpType));
|
_conditions->inclElement(abs((*closePtrList)->_closeUpType));
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
closePtr = (*closePtrList)->_subCloseUps;
|
list = &((*closePtrList)->_subCloseUps);
|
||||||
|
|
||||||
Common::Rect objRect;
|
Common::List<CloseData>::iterator closePtr;
|
||||||
while (closePtr) {
|
for (closePtr = list->begin(); closePtr != list->end(); ++closePtr) {
|
||||||
|
Common::Rect objRect;
|
||||||
objRect = _utils->rectScale(closePtr->_x1, closePtr->_y1, closePtr->_x2, closePtr->_y2);
|
objRect = _utils->rectScale(closePtr->_x1, closePtr->_y1, closePtr->_x2, closePtr->_y2);
|
||||||
if (objRect.contains(pos) && (closePtr->_closeUpType < 0)) {
|
if (objRect.contains(pos) && (closePtr->_closeUpType < 0)) {
|
||||||
_conditions->inclElement(abs(closePtr->_closeUpType));
|
_conditions->inclElement(abs(closePtr->_closeUpType));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
closePtr = closePtr->_nextCloseUp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -143,14 +143,13 @@ struct CloseData {
|
||||||
uint16 _depth; // Level of the closeup.
|
uint16 _depth; // Level of the closeup.
|
||||||
Common::String _graphicName;
|
Common::String _graphicName;
|
||||||
Common::String _message;
|
Common::String _message;
|
||||||
CloseData *_nextCloseUp;
|
Common::List<CloseData> _subCloseUps;
|
||||||
CloseData *_subCloseUps;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ViewData {
|
struct ViewData {
|
||||||
Common::Array<int16> _condition;
|
Common::Array<int16> _condition;
|
||||||
Common::String _graphicName;
|
Common::String _graphicName;
|
||||||
CloseDataPtr _closeUps;
|
Common::List<CloseData> _closeUps;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Action {
|
struct Action {
|
||||||
|
|
|
@ -133,7 +133,6 @@ void Resource::readViews(uint16 roomNum) {
|
||||||
Common::String fileName = "LAB:Rooms/" + Common::String::format("%d", roomNum);
|
Common::String fileName = "LAB:Rooms/" + Common::String::format("%d", roomNum);
|
||||||
Common::File *dataFile = openDataFile(fileName, MKTAG('R', 'O', 'M', '4'));
|
Common::File *dataFile = openDataFile(fileName, MKTAG('R', 'O', 'M', '4'));
|
||||||
|
|
||||||
freeViews(roomNum);
|
|
||||||
RoomData *curRoom = &_vm->_rooms[roomNum];
|
RoomData *curRoom = &_vm->_rooms[roomNum];
|
||||||
|
|
||||||
curRoom->_roomMsg = readString(dataFile);
|
curRoom->_roomMsg = readString(dataFile);
|
||||||
|
@ -147,14 +146,6 @@ void Resource::readViews(uint16 roomNum) {
|
||||||
delete dataFile;
|
delete dataFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::freeViews(uint16 roomNum) {
|
|
||||||
if (!_vm->_rooms)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
freeView(_vm->_rooms[roomNum]._view[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Common::String Resource::translateFileName(const Common::String filename) {
|
Common::String Resource::translateFileName(const Common::String filename) {
|
||||||
Common::String upperFilename = filename;
|
Common::String upperFilename = filename;
|
||||||
upperFilename.toUppercase();
|
upperFilename.toUppercase();
|
||||||
|
@ -285,39 +276,21 @@ Common::List<Action> Resource::readAction(Common::File *file) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseData *Resource::readCloseUps(uint16 depth, Common::File *file) {
|
void Resource::readCloseUps(uint16 depth, Common::File *file, Common::List<CloseData> &list) {
|
||||||
CloseData *closeup = nullptr;
|
list.clear();
|
||||||
CloseData *prev = nullptr;
|
|
||||||
CloseData *head = nullptr;
|
|
||||||
|
|
||||||
while (file->readByte() != '\0') {
|
while (file->readByte() != '\0') {
|
||||||
closeup = new CloseData();
|
list.push_back(CloseData());
|
||||||
if (!head)
|
CloseData &closeup = list.back();
|
||||||
head = closeup;
|
|
||||||
if (prev)
|
|
||||||
prev->_nextCloseUp = closeup;
|
|
||||||
closeup->_x1 = file->readUint16LE();
|
|
||||||
closeup->_y1 = file->readUint16LE();
|
|
||||||
closeup->_x2 = file->readUint16LE();
|
|
||||||
closeup->_y2 = file->readUint16LE();
|
|
||||||
closeup->_closeUpType = file->readSint16LE();
|
|
||||||
closeup->_depth = depth;
|
|
||||||
closeup->_graphicName = readString(file);
|
|
||||||
closeup->_message = readString(file);
|
|
||||||
closeup->_subCloseUps = readCloseUps(depth + 1, file);
|
|
||||||
closeup->_nextCloseUp = nullptr;
|
|
||||||
prev = closeup;
|
|
||||||
}
|
|
||||||
|
|
||||||
return head;
|
closeup._x1 = file->readUint16LE();
|
||||||
}
|
closeup._y1 = file->readUint16LE();
|
||||||
|
closeup._x2 = file->readUint16LE();
|
||||||
void Resource::freeCloseUps(CloseData *closeUps) {
|
closeup._y2 = file->readUint16LE();
|
||||||
while (closeUps) {
|
closeup._closeUpType = file->readSint16LE();
|
||||||
CloseData *nextCloseUp = closeUps->_nextCloseUp;
|
closeup._depth = depth;
|
||||||
freeCloseUps(closeUps->_subCloseUps);
|
closeup._graphicName = readString(file);
|
||||||
delete closeUps;
|
closeup._message = readString(file);
|
||||||
closeUps = nextCloseUp;
|
readCloseUps(depth + 1, file, closeup._subCloseUps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,14 +302,8 @@ void Resource::readView(Common::File *file, Common::List<ViewData> &list) {
|
||||||
|
|
||||||
view._condition = readConditions(file);
|
view._condition = readConditions(file);
|
||||||
view._graphicName = readString(file);
|
view._graphicName = readString(file);
|
||||||
view._closeUps = readCloseUps(0, file);
|
readCloseUps(0, file, view._closeUps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::freeView(Common::List<ViewData> &view) {
|
|
||||||
Common::List<ViewData>::iterator i;
|
|
||||||
for (i = view.begin(); i != view.end(); ++i)
|
|
||||||
freeCloseUps(i->_closeUps);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End of namespace Lab
|
} // End of namespace Lab
|
||||||
|
|
|
@ -101,7 +101,6 @@ public:
|
||||||
void readRoomData(const Common::String fileName);
|
void readRoomData(const Common::String fileName);
|
||||||
InventoryData *readInventory(const Common::String fileName);
|
InventoryData *readInventory(const Common::String fileName);
|
||||||
void readViews(uint16 roomNum);
|
void readViews(uint16 roomNum);
|
||||||
void freeViews(uint16 roomNum);
|
|
||||||
TextFont *getFont(const Common::String fileName);
|
TextFont *getFont(const Common::String fileName);
|
||||||
Common::String getText(const Common::String fileName);
|
Common::String getText(const Common::String fileName);
|
||||||
Common::String getStaticText(byte index) const { return _staticText[index]; }
|
Common::String getStaticText(byte index) const { return _staticText[index]; }
|
||||||
|
@ -112,11 +111,8 @@ private:
|
||||||
Common::Array<int16> readConditions(Common::File *file);
|
Common::Array<int16> readConditions(Common::File *file);
|
||||||
void readRule(Common::File *file, RuleList &rules);
|
void readRule(Common::File *file, RuleList &rules);
|
||||||
Common::List<Action> readAction(Common::File *file);
|
Common::List<Action> readAction(Common::File *file);
|
||||||
void freeAction(Action *action);
|
void readCloseUps(uint16 depth, Common::File *file, Common::List<CloseData> &close);
|
||||||
CloseData *readCloseUps(uint16 depth, Common::File *file);
|
|
||||||
void freeCloseUps(CloseData *closeUps);
|
|
||||||
void readView(Common::File *file, Common::List<ViewData> &view);
|
void readView(Common::File *file, Common::List<ViewData> &view);
|
||||||
void freeView(Common::List<ViewData> &view);
|
|
||||||
void readStaticText();
|
void readStaticText();
|
||||||
Common::String translateFileName(const Common::String filename);
|
Common::String translateFileName(const Common::String filename);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue