Skip to content

Commit

Permalink
KOTOR: Use ScopedPtr in Module
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Oct 26, 2016
1 parent 562e0c8 commit d75c4fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
36 changes: 15 additions & 21 deletions src/engines/kotor/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ bool Module::Action::operator<(const Action &s) const {


Module::Module(::Engines::Console &console) : Object(kObjectTypeModule),
_console(&console), _hasModule(false), _running(false), _pc(0),
_currentTexturePack(-1), _exit(false), _entryLocationType(kObjectTypeAll),
_area(0) {
_console(&console), _hasModule(false), _running(false),
_currentTexturePack(-1), _exit(false), _entryLocationType(kObjectTypeAll) {

}

Expand Down Expand Up @@ -118,12 +117,11 @@ void Module::loadModule(const Common::UString &module, const Common::UString &en
}

void Module::usePC(Creature *pc) {
delete _pc;
_pc = pc;
_pc.reset(pc);
}

Creature *Module::getPC() {
return _pc;
return _pc.get();
}

bool Module::isLoaded() const {
Expand Down Expand Up @@ -188,7 +186,7 @@ void Module::loadIFO() {
}

void Module::loadArea() {
_area = new Area(*this, _ifo.getEntryArea());
_area.reset(new Area(*this, _ifo.getEntryArea()));
}

static const char * const texturePacks[3] = {
Expand Down Expand Up @@ -252,13 +250,11 @@ void Module::unloadIFO() {
}

void Module::unloadArea() {
delete _area;
_area = 0;
_area.reset();
}

void Module::unloadPC() {
delete _pc;
_pc = 0;
_pc.reset();
}

void Module::unloadTexturePack() {
Expand Down Expand Up @@ -327,7 +323,7 @@ bool Module::getObjectLocation(const Common::UString &object, ObjectType locatio
if (object.empty())
return false;

Aurora::NWScript::ObjectSearch *search = findObjectsByTag(object);
Common::ScopedPtr<Aurora::NWScript::ObjectSearch> search(findObjectsByTag(object));


KotOR::Object *kotorObject = 0;
Expand All @@ -337,8 +333,6 @@ bool Module::getObjectLocation(const Common::UString &object, ObjectType locatio
kotorObject = 0;
}

delete search;

if (!kotorObject)
return false;

Expand Down Expand Up @@ -373,21 +367,21 @@ void Module::leave() {
void Module::enterArea() {
_area->show();

runScript(kScriptModuleLoad , this, _pc);
runScript(kScriptModuleStart, this, _pc);
runScript(kScriptEnter , this, _pc);
runScript(kScriptModuleLoad , this, _pc.get());
runScript(kScriptModuleStart, this, _pc.get());
runScript(kScriptEnter , this, _pc.get());

_area->runScript(kScriptEnter, _area, _pc);
_area->runScript(kScriptEnter, _area.get(), _pc.get());
}

void Module::leaveArea() {
if (_area) {
_area->runScript(kScriptExit, _area, _pc);
_area->runScript(kScriptExit, _area.get(), _pc.get());

_area->hide();
}

runScript(kScriptExit, this, _pc);
runScript(kScriptExit, this, _pc.get());
}

void Module::addEvent(const Events::Event &event) {
Expand Down Expand Up @@ -502,7 +496,7 @@ const Common::UString &Module::getName() const {
}

Area *Module::getCurrentArea() {
return _area;
return _area.get();
}

void Module::delayScript(const Common::UString &script,
Expand Down
5 changes: 3 additions & 2 deletions src/engines/kotor/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <list>
#include <set>

#include "src/common/scopedptr.h"
#include "src/common/ustring.h"
#include "src/common/changeid.h"
#include "src/common/configman.h"
Expand Down Expand Up @@ -156,7 +157,7 @@ class Module : public KotOR::Object, public KotOR::ObjectContainer {
/** The current module's IFO. */
Aurora::IFOFile _ifo;

Creature *_pc; ///< The player character we use.
Common::ScopedPtr<Creature> _pc; ///< The player character we use.

/** The current texture pack. */
int _currentTexturePack;
Expand All @@ -173,7 +174,7 @@ class Module : public KotOR::Object, public KotOR::ObjectContainer {
/** The type(s) of the object in the start location for this module. */
ObjectType _entryLocationType;

Area *_area; ///< The current module's area.
Common::ScopedPtr<Area> _area; ///< The current module's area.

EventQueue _eventQueue;
ActionQueue _delayedActions;
Expand Down

0 comments on commit d75c4fc

Please sign in to comment.