Skip to content

Commit

Permalink
merge with handle_impr
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzzrm committed Apr 29, 2014
2 parents 4891206 + 0d0bae2 commit cb09717
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/ai/basictasks/directsuicidetask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

DirectSuicideTask::DirectSuicideTask(BoardComputer* boardComputer, WorldObject* target) :
AiTask(boardComputer),
m_target(target ? target->handle<WorldObject>() : Handle<WorldObject>())
m_target(target ? makeHandle(target) : Handle<WorldObject>())
{
}

void DirectSuicideTask::setTarget(WorldObject* target) {
m_target = (target ? target->handle<WorldObject>() : Handle<WorldObject>());
m_target = (target ? makeHandle(target) : Handle<WorldObject>());
}

void DirectSuicideTask::update(float deltaSec) {
Expand Down
4 changes: 2 additions & 2 deletions src/ai/grouptasks/defendareatask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void DefendAreaTask::update(float deltaSec) {
updatePatrol();
}
}

// update called by the leader himself
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ bool DefendAreaTask::isEnemyInRange() {
if (ship) {
Faction& enemyFaction = ship->character()->faction();
if (enemyFaction.relationTo(m_squad.leader()->character()->faction()).type() == FactionRelationType::Enemy) {
m_enemies.push_back(worldObject->handle<WorldObject>());
m_enemies.push_back(makeHandle(worldObject));
} else {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/camera/camerafollowhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WorldObject* CameraFollowHelper::target() {
}

void CameraFollowHelper::setTarget(WorldObject* target) {
m_target = target->handle<WorldObject>();
m_target = makeHandle(target);
}

glm::vec3 CameraFollowHelper::followPosition() {
Expand Down
2 changes: 1 addition & 1 deletion src/equipment/weapons/rocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ WorldObject* Rocket::target() {

void Rocket::setTarget(WorldObject* targetObject) {
if (targetObject) {
m_targetHandle = targetObject->handle<WorldObject>();
m_targetHandle = makeHandle(targetObject);
m_aiTask.reset(new DirectSuicideTask(&m_boardComputer, targetObject));
} else {
m_targetHandle = Handle<WorldObject>();
Expand Down
2 changes: 1 addition & 1 deletion src/equipment/weapons/splitrocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SplitRocket::SplitRocket():

void SplitRocket::setTarget(WorldObject* targetObject) {
if (targetObject) {
m_targetHandle = targetObject->handle<WorldObject>();
m_targetHandle = makeHandle(targetObject);
m_aiTask.reset(new SplitRocketTask(this, &m_boardComputer, targetObject));
} else {
m_targetHandle = Handle<WorldObject>(nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/events/aabbenteredpoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

AABBEnteredPoll::AABBEnteredPoll(WorldObject* worldObject, const AABB& aabb, const Callback& callback):
EventPoll(callback),
m_worldObject(worldObject->handle<WorldObject>()),
m_worldObject(makeHandle(worldObject)),
m_aabb(aabb),
m_entered(false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/events/aitaskfinishedpoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

AiTaskFinishedPoll::AiTaskFinishedPoll(AiTask* aitask, const Callback& callback):
EventPoll(callback),
m_aiTask(aitask->handle<AiTask>())
m_aiTask(makeHandle(aitask))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/events/worldobjectdestroyedpoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

WorldObjectDestroyedPoll::WorldObjectDestroyedPoll(WorldObject* worldObject, const Callback& callback):
EventPoll(callback),
m_worldObject(worldObject->handle<WorldObject>())
m_worldObject(makeHandle(worldObject))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Ship* Player::ship() {
}

void Player::setShip(Ship* ship) {
m_ship = ship->handle<Ship>();
m_ship = makeHandle(ship);
m_ship->character()->setFaction(World::instance()->factionMatrix().playerFaction());
m_ship->info().setShowOnHud(false);
m_cameraDolly->followWorldObject(ship);
Expand Down
7 changes: 4 additions & 3 deletions src/scripting/bindings/aibindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ int AiBindings::apiAddFightTaskTarget(apikey key, apikey worldObjectKey) {
}

WorldObject* worldObject = m_scriptEngine.get<WorldObject>(worldObjectKey);
if (!worldObject) { return -1; }

if (!worldObject){
return -1;
}

fightTask->addTarget(worldObject->handle<WorldObject>());
fightTask->addTarget(makeHandle(worldObject));
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripting/scriptcallbackimpl.inl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void callHelper(ScriptCallbackImpl<Args...>* callback, const std::string& functi

template<typename... Args>
ScriptCallbackImpl<Args...>::ScriptCallbackImpl(Script& script, const std::string& function, Args... args):
m_script(script.handle<Script>()),
m_script(makeHandle(script)),
m_function(function),
m_call(std::bind(callHelper<Args...>, this, function, args...))
{
Expand Down
2 changes: 1 addition & 1 deletion src/ui/hud/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ glm::vec3 HUD::applyTo(const glm::vec3 &vertex) const {
}

void HUD::setTarget(WorldObject* target) {
m_target = target ? target->handle<WorldObject>() : Handle<WorldObject>();
m_target = target ? makeHandle(target) : Handle<WorldObject>();
}

WorldObject* HUD::target() {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/hud/hudobjectdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

HUDObjectDelegate::HUDObjectDelegate(HUD* hud, WorldObject* worldObject, ObjectHudget* hudget):
m_hud(hud),
m_worldObjectHandle(worldObject->handle<WorldObject>()),
m_worldObjectHandle(makeHandle(worldObject)),
m_hudget(hudget)
{
hudget->setObjectDelegate(this);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/handle/handle.inl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Handle<T>::Handle():

template<typename T>
Handle<T>::Handle(const std::shared_ptr<HandleImpl>& impl):
m_impl(impl),
m_referenced(static_cast<T*>(impl->owner()))
m_impl(impl ? impl : std::make_shared<HandleImpl>(nullptr)),
m_referenced(impl ? static_cast<T*>(impl->owner()) : nullptr)
{
}

Expand Down
6 changes: 6 additions & 0 deletions src/utils/handle/handleowner.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ class HandleOwner {
std::shared_ptr<HandleImpl> m_impl;
};

template<typename T>
Handle<T> makeHandle(T* owner);

template<typename T>
Handle<T> makeHandle(T& owner);


#include "handleowner.inl"
11 changes: 11 additions & 0 deletions src/utils/handle/handleowner.inl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ Handle<T> HandleOwner::handle() {
return Handle<T>(m_impl);
}

template<typename T>
Handle<T> makeHandle(T* owner) {
return owner->template handle<T>();
}


template<typename T>
Handle<T> makeHandle(T& owner) {
return owner.template handle<T>();
}

2 changes: 1 addition & 1 deletion src/worldobject/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Ship::update(float deltaSec) {
}

void Ship::setTargetObject(WorldObject* target) {
m_targetObjectHandle = target ? target->handle<WorldObject>() : Handle<WorldObject>();
m_targetObjectHandle = target ? makeHandle(target) : Handle<WorldObject>();
}

WorldObject* Ship::targetObject() {
Expand Down

0 comments on commit cb09717

Please sign in to comment.