LAB: Avoid manual memory management of ViewData
This commit is contained in:
parent
cd3ebf687c
commit
1a1525a155
4 changed files with 26 additions and 44 deletions
|
@ -56,16 +56,16 @@ ViewData *LabEngine::getViewData(uint16 roomNum, uint16 direction) {
|
|||
if (_rooms[roomNum]._roomMsg.empty())
|
||||
_resource->readViews(roomNum);
|
||||
|
||||
ViewData *view = _rooms[roomNum]._view[direction];
|
||||
Common::List<ViewData> &views = _rooms[roomNum]._view[direction];
|
||||
|
||||
do {
|
||||
Common::List<ViewData>::iterator view;
|
||||
|
||||
for (view = views.begin(); view != views.end(); ++view) {
|
||||
if (checkConditions(view->_condition))
|
||||
break;
|
||||
return &(*view);
|
||||
}
|
||||
|
||||
view = view->_nextCondition;
|
||||
} while (true);
|
||||
|
||||
return view;
|
||||
error("No view with matching condition found");
|
||||
}
|
||||
|
||||
CloseData *LabEngine::getObject(Common::Point pos, CloseDataPtr closePtr) {
|
||||
|
|
|
@ -150,7 +150,6 @@ struct CloseData {
|
|||
struct ViewData {
|
||||
Common::Array<int16> _condition;
|
||||
Common::String _graphicName;
|
||||
ViewData *_nextCondition;
|
||||
CloseDataPtr _closeUps;
|
||||
};
|
||||
|
||||
|
@ -173,7 +172,7 @@ struct Rule {
|
|||
struct RoomData {
|
||||
uint16 _doors[4];
|
||||
byte _transitionType;
|
||||
ViewData *_view[4];
|
||||
Common::List<ViewData> _view[4];
|
||||
RuleList _rules;
|
||||
Common::String _roomMsg;
|
||||
};
|
||||
|
|
|
@ -108,11 +108,6 @@ void Resource::readRoomData(const Common::String fileName) {
|
|||
curRoom->_doors[kDirectionEast] = dataFile->readUint16LE();
|
||||
curRoom->_doors[kDirectionWest] = dataFile->readUint16LE();
|
||||
curRoom->_transitionType = dataFile->readByte();
|
||||
|
||||
curRoom->_view[kDirectionNorth] = nullptr;
|
||||
curRoom->_view[kDirectionSouth] = nullptr;
|
||||
curRoom->_view[kDirectionEast] = nullptr;
|
||||
curRoom->_view[kDirectionWest] = nullptr;
|
||||
}
|
||||
|
||||
delete dataFile;
|
||||
|
@ -142,10 +137,10 @@ void Resource::readViews(uint16 roomNum) {
|
|||
RoomData *curRoom = &_vm->_rooms[roomNum];
|
||||
|
||||
curRoom->_roomMsg = readString(dataFile);
|
||||
curRoom->_view[kDirectionNorth] = readView(dataFile);
|
||||
curRoom->_view[kDirectionSouth] = readView(dataFile);
|
||||
curRoom->_view[kDirectionEast] = readView(dataFile);
|
||||
curRoom->_view[kDirectionWest] = readView(dataFile);
|
||||
readView(dataFile, curRoom->_view[kDirectionNorth]);
|
||||
readView(dataFile, curRoom->_view[kDirectionSouth]);
|
||||
readView(dataFile, curRoom->_view[kDirectionEast]);
|
||||
readView(dataFile, curRoom->_view[kDirectionWest]);
|
||||
readRule(dataFile, curRoom->_rules);
|
||||
|
||||
_vm->updateMusicAndEvents();
|
||||
|
@ -326,34 +321,22 @@ void Resource::freeCloseUps(CloseData *closeUps) {
|
|||
}
|
||||
}
|
||||
|
||||
ViewData *Resource::readView(Common::File *file) {
|
||||
ViewData *view = nullptr;
|
||||
ViewData *prev = nullptr;
|
||||
ViewData *head = nullptr;
|
||||
|
||||
void Resource::readView(Common::File *file, Common::List<ViewData> &list) {
|
||||
list.clear();
|
||||
while (file->readByte() == 1) {
|
||||
view = new ViewData();
|
||||
if (!head)
|
||||
head = view;
|
||||
if (prev)
|
||||
prev->_nextCondition = view;
|
||||
view->_condition = readConditions(file);
|
||||
view->_graphicName = readString(file);
|
||||
view->_closeUps = readCloseUps(0, file);
|
||||
view->_nextCondition = nullptr;
|
||||
prev = view;
|
||||
}
|
||||
list.push_back(ViewData());
|
||||
ViewData &view = list.back();
|
||||
|
||||
return head;
|
||||
view._condition = readConditions(file);
|
||||
view._graphicName = readString(file);
|
||||
view._closeUps = readCloseUps(0, file);
|
||||
}
|
||||
}
|
||||
|
||||
void Resource::freeView(ViewData *view) {
|
||||
while (view) {
|
||||
ViewData *nextView = view->_nextCondition;
|
||||
freeCloseUps(view->_closeUps);
|
||||
delete view;
|
||||
view = nextView;
|
||||
}
|
||||
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
|
||||
|
|
|
@ -115,8 +115,8 @@ private:
|
|||
void freeAction(Action *action);
|
||||
CloseData *readCloseUps(uint16 depth, Common::File *file);
|
||||
void freeCloseUps(CloseData *closeUps);
|
||||
ViewData *readView(Common::File *file);
|
||||
void freeView(ViewData *view);
|
||||
void readView(Common::File *file, Common::List<ViewData> &view);
|
||||
void freeView(Common::List<ViewData> &view);
|
||||
void readStaticText();
|
||||
Common::String translateFileName(const Common::String filename);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue