Skip to content

Commit

Permalink
DRAGONAGE2: Replace PtrList with std::list<std::unique_ptr<>>
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Aug 24, 2020
1 parent e8e9257 commit cbfe591
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 62 deletions.
51 changes: 21 additions & 30 deletions src/engines/dragonage2/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ const Aurora::LocString &Area::getName() const {

void Area::clean() {
try {
for (Objects::iterator o = _objects.begin(); o != _objects.end(); ++o)
_campaign->removeObject(**o);
for (auto &object : _objects)
_campaign->removeObject(*object);

deindexResources(_resources);
} catch (...) {
Expand Down Expand Up @@ -167,41 +167,32 @@ void Area::loadARE(const Common::UString &resRef) {
loadCreatures (areTop.getList("CreatureList"));
}

void Area::loadObject(DragonAge2::Object &object) {
_objects.push_back(&object);
void Area::loadObject(std::unique_ptr<DragonAge2::Object> &&object) {
_objects.push_back(std::move(object));

_campaign->addObject(object);
_campaign->addObject(*_objects.back());

if (!object.isStatic()) {
const std::list<uint32_t> &ids = object.getIDs();

for (std::list<uint32_t>::const_iterator id = ids.begin(); id != ids.end(); ++id)
_objectMap.insert(std::make_pair(*id, &object));
}
if (!_objects.back()->isStatic())
for (auto &id : _objects.back()->getIDs())
_objectMap.insert(std::make_pair(id, _objects.back().get()));
}

void Area::loadWaypoints(const Aurora::GFF3List &list) {
for (Aurora::GFF3List::const_iterator w = list.begin(); w != list.end(); ++w) {
Waypoint *waypoint = new Waypoint(**w);

loadObject(*waypoint);
}
for (auto &waypoint : list)
if (waypoint)
loadObject(std::make_unique<Waypoint>(*waypoint));
}

void Area::loadPlaceables(const Aurora::GFF3List &list) {
for (Aurora::GFF3List::const_iterator p = list.begin(); p != list.end(); ++p) {
Placeable *placeable = new Placeable(**p);

loadObject(*placeable);
}
for (auto &placeable : list)
if (placeable)
loadObject(std::make_unique<Placeable>(*placeable));
}

void Area::loadCreatures(const Aurora::GFF3List &list) {
for (Aurora::GFF3List::const_iterator c = list.begin(); c != list.end(); ++c) {
Creature *creature = new Creature(**c);

loadObject(*creature);
}
for (auto &creature : list)
if (creature)
loadObject(std::make_unique<Creature>(*creature));
}

void Area::show() {
Expand All @@ -211,8 +202,8 @@ void Area::show() {

for (auto &room : _rooms)
room->show();
for (Objects::iterator o = _objects.begin(); o != _objects.end(); ++o)
(*o)->show();
for (auto &object : _objects)
object->show();

GfxMan.unlockFrame();
}
Expand All @@ -222,8 +213,8 @@ void Area::hide() {

removeFocus();

for (Objects::iterator o = _objects.begin(); o != _objects.end(); ++o)
(*o)->hide();
for (auto &object : _objects)
object->hide();
for (auto &room : _rooms)
room->hide();

Expand Down
5 changes: 2 additions & 3 deletions src/engines/dragonage2/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <map>
#include <memory>

#include "src/common/ptrlist.h"
#include "src/common/ustring.h"
#include "src/common/mutex.h"

Expand Down Expand Up @@ -95,7 +94,7 @@ class Area : public DragonAge2::Object, public Events::Notifyable {
private:
typedef std::vector<std::unique_ptr<Room>> Rooms;

typedef Common::PtrList<DragonAge2::Object> Objects;
typedef std::list<std::unique_ptr<DragonAge2::Object>> Objects;
typedef std::map<uint32_t, DragonAge2::Object *> ObjectMap;


Expand Down Expand Up @@ -132,7 +131,7 @@ class Area : public DragonAge2::Object, public Events::Notifyable {
void loadEnvironment(const Common::UString &resRef);
void loadARE(const Common::UString &resRef);

void loadObject(DragonAge2::Object &object);
void loadObject(std::unique_ptr<DragonAge2::Object> &&object);
void loadWaypoints (const Aurora::GFF3List &list);
void loadPlaceables(const Aurora::GFF3List &list);
void loadCreatures (const Aurora::GFF3List &list);
Expand Down
52 changes: 25 additions & 27 deletions src/engines/dragonage2/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* A creature in a Dragon Age II area.
*/

#include <memory>

#include "src/common/util.h"
#include "src/common/strutil.h"
#include "src/common/maths.h"
Expand Down Expand Up @@ -91,26 +89,26 @@ void Creature::setPosition(float x, float y, float z) {
Object::setPosition(x, y, z);
Object::getPosition(x, y, z);

for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
(*m)->setPosition(x, y, z);
for (auto &model : _models)
model->setPosition(x, y, z);
}

void Creature::setOrientation(float x, float y, float z, float angle) {
Object::setOrientation(x, y, z, angle);
Object::getOrientation(x, y, z, angle);

for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
(*m)->setOrientation(x, y, z, angle);
for (auto &model : _models)
model->setOrientation(x, y, z, angle);
}

void Creature::show() {
for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
(*m)->show();
for (auto &model : _models)
model->show();
}

void Creature::hide() {
for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
(*m)->hide();
for (auto &model : _models)
model->hide();
}

bool Creature::isPC() const {
Expand Down Expand Up @@ -138,8 +136,8 @@ void Creature::leave() {
}

void Creature::highlight(bool enabled) {
for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
(*m)->drawBound(enabled);
for (auto &model : _models)
model->drawBound(enabled);
}

bool Creature::click(Object *triggerer) {
Expand Down Expand Up @@ -213,31 +211,31 @@ void Creature::loadModelsSimple(const Aurora::GDAFile &gda, size_t row) {

Model *model = loadModelObject(gda.getString(row, "ModelName"));
if (model)
_models.push_back(model);
_models.emplace_back(model);
}

void Creature::loadModelsWelded(const Aurora::GDAFile &gda, size_t row) {
// Welded, single mesh with baked weapons

Model *model = loadModelObject(gda.getString(row, "ModelName"));
if (model)
_models.push_back(model);
_models.emplace_back(model);
}

void Creature::loadModelsHead(const Aurora::GDAFile &gda, size_t row) {
// Head, single mesh for body + head model

Model *model = loadModelObject(gda.getString(row, "ModelName"));
if (model)
_models.push_back(model);
_models.emplace_back(model);

const Common::UString prefix = createModelPrefix(gda, row);

bool haveHelm = false;
if ((model = loadModelObject(findEquipModel(kInventorySlotHead, prefix)))) {
haveHelm = true;

_models.push_back(model);
_models.emplace_back(model);
}

if (!_headMorph.empty())
Expand All @@ -263,7 +261,7 @@ void Creature::loadModelsHeadMorph(bool loadHair) {
continue;

if ((model = loadModelObject(parts[i])))
_models.push_back(model);
_models.emplace_back(model);
}

} catch (...) {
Expand Down Expand Up @@ -294,7 +292,7 @@ void Creature::loadModelsHeadList(const Aurora::GDAFile &gda, size_t row, bool l

Model *model = loadModelObject(createModelPart(sheet, sheetRow, prefix));
if (model)
_models.push_back(model);
_models.emplace_back(model);
}
}

Expand Down Expand Up @@ -326,7 +324,7 @@ void Creature::loadModelsParts(const Aurora::GDAFile &gda, size_t row) {
model = loadModelObject(getItemModel(kNakedTorso, prefix, &armorType));

if (model)
_models.push_back(model);
_models.emplace_back(model);

// Armor of type 5 (clothing) already includes hands and feet in the model...
if (armorType != 5) {
Expand All @@ -339,7 +337,7 @@ void Creature::loadModelsParts(const Aurora::GDAFile &gda, size_t row) {
model = loadModelObject(getItemModel(kNakedGloves, prefix));

if (model)
_models.push_back(model);
_models.emplace_back(model);

// Boots: appearance override -> equipped boots item -> naked

Expand All @@ -350,7 +348,7 @@ void Creature::loadModelsParts(const Aurora::GDAFile &gda, size_t row) {
model = loadModelObject(getItemModel(kNakedBoots, prefix));

if (model)
_models.push_back(model);
_models.emplace_back(model);
}

// Helm: appearance override -> equipped helm item
Expand All @@ -363,7 +361,7 @@ void Creature::loadModelsParts(const Aurora::GDAFile &gda, size_t row) {
if (model) {
haveHelm = true;

_models.push_back(model);
_models.emplace_back(model);
}

// Head: morph -> part list
Expand Down Expand Up @@ -428,13 +426,13 @@ void Creature::load(const GFF3Struct &instance, const GFF3Struct *blueprint = 0)
const float scaleY = gda.getFloat(row, "ModelScaleY", 1.0f);
const float scaleZ = gda.getFloat(row, "ModelScaleZ", 1.0f);

for (Models::iterator m = _models.begin(); m != _models.end(); ++m) {
(*m)->setScale(scaleX, scaleY, scaleZ);
for (auto &model : _models) {
model->setScale(scaleX, scaleY, scaleZ);

(*m)->setTag(_tag);
(*m)->setClickable(isClickable());
model->setTag(_tag);
model->setClickable(isClickable());

_ids.push_back((*m)->getID());
_ids.push_back(model->getID());
}

syncPosition();
Expand Down
4 changes: 2 additions & 2 deletions src/engines/dragonage2/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

#include <vector>
#include <list>
#include <memory>

#include "src/common/ptrlist.h"
#include "src/common/ustring.h"

#include "src/aurora/types.h"
Expand Down Expand Up @@ -102,7 +102,7 @@ class Creature : public Object {
};
typedef std::vector<EquipItem> Items;

typedef Common::PtrList<Graphics::Aurora::Model> Models;
typedef std::list<std::unique_ptr<Graphics::Aurora::Model>> Models;


bool _isPC; ///< Is the creature a PC?
Expand Down

0 comments on commit cbfe591

Please sign in to comment.