Skip to content

Commit

Permalink
JADE: 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 c681e42 commit 3aecec9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
20 changes: 9 additions & 11 deletions src/engines/jade/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool Module::Action::operator<(const Action &s) const {


Module::Module(::Engines::Console &console) : _console(&console), _hasModule(false),
_running(false), _pc(0), _exit(false), _area(0) {
_running(false), _exit(false) {

}

Expand Down Expand Up @@ -99,13 +99,13 @@ void Module::loadModule(const Common::UString &module) {
void Module::usePC(Creature *pc) {
unloadPC();

_pc = pc;
_pc.reset(pc);

addObject(*_pc);
}

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

bool Module::isLoaded() const {
Expand Down Expand Up @@ -135,7 +135,7 @@ void Module::load() {
}

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

void Module::unload(bool completeUnload) {
Expand All @@ -156,8 +156,7 @@ void Module::unload(bool completeUnload) {
}

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

void Module::unloadPC() {
Expand All @@ -166,8 +165,7 @@ void Module::unloadPC() {

removeObject(*_pc);

delete _pc;
_pc = 0;
_pc.reset();
}

void Module::changeModule(const Common::UString &module) {
Expand Down Expand Up @@ -219,12 +217,12 @@ void Module::leave() {
void Module::enterArea() {
_area->show();

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

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

_area->hide();
}
Expand Down Expand Up @@ -333,7 +331,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/jade/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 @@ -159,14 +160,14 @@ class Module : public Jade::ObjectContainer {
/** Resources added by the current module. */
std::list<Common::ChangeID> _resources;

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

bool _exit; ///< Should we exit the module?

Common::UString _module; ///< The current module's name.
Common::UString _newModule; ///< The module we should change to.

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 3aecec9

Please sign in to comment.