Skip to content

Commit

Permalink
DRAGONAGE2: Use ScopedPtr in the area object classes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Oct 26, 2016
1 parent 18ffe06 commit ae9bd7b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 38 deletions.
33 changes: 16 additions & 17 deletions src/engines/dragonage2/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* A creature in a Dragon Age II area.
*/

#include "src/common/scopedptr.h"
#include "src/common/util.h"
#include "src/common/strutil.h"
#include "src/common/maths.h"
Expand Down Expand Up @@ -71,18 +72,13 @@ Creature::Creature(const GFF3Struct &creature) : Object(kObjectTypeCreature) {
try {
load(creature);
} catch (...) {
for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
delete *m;

clean();
throw;
}
}

Creature::~Creature() {
hide();

for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
delete *m;
clean();
}

void Creature::init() {
Expand All @@ -94,6 +90,16 @@ void Creature::init() {
_partVariation[i] = 0xFFFFFFFF;
}

void Creature::clean() {
try {
hide();

for (Models::iterator m = _models.begin(); m != _models.end(); ++m)
delete *m;
} catch (...) {
}
}

void Creature::setPosition(float x, float y, float z) {
Object::setPosition(x, y, z);
Object::getPosition(x, y, z);
Expand Down Expand Up @@ -159,22 +165,15 @@ bool Creature::click(Object *triggerer) {
void Creature::load(const GFF3Struct &creature) {
_resRef = creature.getString("TemplateResRef");

GFF3File *utc = 0;
Common::ScopedPtr<GFF3File> utc;
if (!_resRef.empty()) {
try {
utc = new GFF3File(_resRef, Aurora::kFileTypeUTC, kUTCID);
utc.reset(new GFF3File(_resRef, Aurora::kFileTypeUTC, kUTCID));
} catch (...) {
}
}

try {
load(creature, utc ? &utc->getTopLevel() : 0);
} catch (...) {
delete utc;
throw;
}

delete utc;
load(creature, utc ? &utc->getTopLevel() : 0);
}

Common::UString Creature::createModelPrefix(const Aurora::GDAFile &gda, size_t row) {
Expand Down
2 changes: 2 additions & 0 deletions src/engines/dragonage2/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class Creature : public Object {
static Common::UString createModelPrefix(const Aurora::GDAFile &gda, size_t row);
static Common::UString createModelPart(const Aurora::GDAFile &gda, size_t row,
const Common::UString &prefix);

void clean();
};

} // End of namespace Dragon Age
Expand Down
26 changes: 6 additions & 20 deletions src/engines/dragonage2/placeable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,13 @@ namespace Engines {
namespace DragonAge2 {

Placeable::Placeable(const Aurora::GFF3Struct &placeable) : Object(kObjectTypePlaceable),
_appearanceID(0xFFFFFFFF), _model(0) {
_appearanceID(0xFFFFFFFF) {

try {
load(placeable);
} catch (...) {
delete _model;
throw;
}
load(placeable);
}

Placeable::~Placeable() {
hide();

delete _model;
}

void Placeable::setPosition(float x, float y, float z) {
Expand Down Expand Up @@ -108,22 +101,15 @@ bool Placeable::click(Object *triggerer) {
void Placeable::load(const Aurora::GFF3Struct &placeable) {
_resRef = placeable.getString("TemplateResRef");

Aurora::GFF3File *utp = 0;
Common::ScopedPtr<Aurora::GFF3File> utp;
if (!_resRef.empty()) {
try {
utp = new Aurora::GFF3File(_resRef, Aurora::kFileTypeUTP, MKTAG('U', 'T', 'P', ' '));
utp.reset(new Aurora::GFF3File(_resRef, Aurora::kFileTypeUTP, MKTAG('U', 'T', 'P', ' ')));
} catch (...) {
}
}

try {
load(placeable, utp ? &utp->getTopLevel() : 0);
} catch (...) {
delete utp;
throw;
}

delete utp;
load(placeable, utp ? &utp->getTopLevel() : 0);
}

void Placeable::load(const Aurora::GFF3Struct &instance, const Aurora::GFF3Struct *blueprint = 0) {
Expand All @@ -133,7 +119,7 @@ void Placeable::load(const Aurora::GFF3Struct &instance, const Aurora::GFF3Struc

const Aurora::GDAFile &gda = getMGDA(kWorksheetPlaceables);

_model = loadModelObject(gda.getString(gda.findRow(_appearanceID), "Model"));
_model.reset(loadModelObject(gda.getString(gda.findRow(_appearanceID), "Model")));

if (_model) {
_model->setTag(_tag);
Expand Down
3 changes: 2 additions & 1 deletion src/engines/dragonage2/placeable.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef ENGINES_DRAGONAGE2_PLACEABLE_H
#define ENGINES_DRAGONAGE2_PLACEABLE_H

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

#include "src/aurora/types.h"
Expand Down Expand Up @@ -71,7 +72,7 @@ class Placeable : public Object {
/** The placeable's appearance; index into the Placeables MGDA. */
uint32 _appearanceID;

Graphics::Aurora::Model *_model; ///< The placeable's model.
Common::ScopedPtr<Graphics::Aurora::Model> _model; ///< The placeable's model.


void load(const Aurora::GFF3Struct &placeable);
Expand Down

0 comments on commit ae9bd7b

Please sign in to comment.