[Orxonox-commit 1085] r5806 - in code/branches/core5/src: libraries/core modules/gamestates modules/objects/triggers modules/overlays/hud modules/pong orxonox/gametypes orxonox/infos orxonox/worldentities/pawns
landauf at orxonox.net
landauf at orxonox.net
Sun Sep 27 04:13:14 CEST 2009
Author: landauf
Date: 2009-09-27 04:13:13 +0200 (Sun, 27 Sep 2009)
New Revision: 5806
Modified:
code/branches/core5/src/libraries/core/BaseObject.h
code/branches/core5/src/modules/gamestates/GSLevel.cc
code/branches/core5/src/modules/objects/triggers/CheckPoint.cc
code/branches/core5/src/modules/overlays/hud/TeamBaseMatchScore.cc
code/branches/core5/src/modules/overlays/hud/UnderAttackHealthBar.cc
code/branches/core5/src/modules/pong/Pong.cc
code/branches/core5/src/modules/pong/PongCenterpoint.cc
code/branches/core5/src/modules/pong/PongScore.cc
code/branches/core5/src/orxonox/gametypes/Asteroids.cc
code/branches/core5/src/orxonox/gametypes/Gametype.cc
code/branches/core5/src/orxonox/gametypes/Gametype.h
code/branches/core5/src/orxonox/gametypes/TeamBaseMatch.cc
code/branches/core5/src/orxonox/gametypes/UnderAttack.cc
code/branches/core5/src/orxonox/infos/HumanPlayer.cc
code/branches/core5/src/orxonox/worldentities/pawns/Destroyer.cc
code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc
Log:
- The gametype pointer in BaseObject is now also a SmartPtr
- The GametypeInfo object in Gametype is now a pointer instead of a member object to prevent double free (once deleted by the unloader and once when the gametype gets destroyed)
- GSLevel sets the Gametype of all HumanPlayer objects to 0 because they don't get deleted and would prevent the Gametype from being destroyed.
- Fixed a bug in HumanPlayer when Gametype is set to 0
Unloading seems to work with bots now.
Modified: code/branches/core5/src/libraries/core/BaseObject.h
===================================================================
--- code/branches/core5/src/libraries/core/BaseObject.h 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/libraries/core/BaseObject.h 2009-09-27 02:13:13 UTC (rev 5806)
@@ -137,7 +137,7 @@
inline void setScene(const SmartPtr<Scene>& scene) { this->scene_ = scene; }
inline const SmartPtr<Scene>& getScene() const { return this->scene_; }
- inline void setGametype(Gametype* gametype)
+ inline void setGametype(const SmartPtr<Gametype>& gametype)
{
if (gametype != this->gametype_)
{
@@ -146,7 +146,7 @@
this->changedGametype();
}
}
- inline Gametype* getGametype() const { return this->gametype_; }
+ inline const SmartPtr<Gametype>& getGametype() const { return this->gametype_; }
inline Gametype* getOldGametype() const { return this->oldGametype_; }
virtual void changedGametype() {}
@@ -195,7 +195,7 @@
Namespace* namespace_;
BaseObject* creator_;
SmartPtr<Scene> scene_;
- Gametype* gametype_;
+ SmartPtr<Gametype> gametype_;
Gametype* oldGametype_;
std::set<Template*> templates_;
std::map<BaseObject*, std::string> eventListeners_;
Modified: code/branches/core5/src/modules/gamestates/GSLevel.cc
===================================================================
--- code/branches/core5/src/modules/gamestates/GSLevel.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/modules/gamestates/GSLevel.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -51,6 +51,7 @@
#include "CameraManager.h"
#include "LevelManager.h"
#include "PlayerManager.h"
+#include "infos/HumanPlayer.h"
namespace orxonox
{
@@ -241,6 +242,9 @@
void GSLevel::unloadLevel()
{
+ for (ObjectList<HumanPlayer>::iterator it = ObjectList<HumanPlayer>::begin(); it; ++it)
+ it->setGametype(0);
+
Loader::unload(startFile_s);
delete startFile_s;
Modified: code/branches/core5/src/modules/objects/triggers/CheckPoint.cc
===================================================================
--- code/branches/core5/src/modules/objects/triggers/CheckPoint.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/modules/objects/triggers/CheckPoint.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -84,7 +84,7 @@
{
DistanceTrigger::triggered(bIsTriggered);
- Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype());
+ Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype().get());
if (gametype)
{
gametype->addTime(addTime_);
Modified: code/branches/core5/src/modules/overlays/hud/TeamBaseMatchScore.cc
===================================================================
--- code/branches/core5/src/modules/overlays/hud/TeamBaseMatchScore.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/modules/overlays/hud/TeamBaseMatchScore.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -117,7 +117,7 @@
SUPER(TeamBaseMatchScore, changedOwner);
if (this->getOwner() && this->getOwner()->getGametype())
- this->owner_ = orxonox_cast<TeamBaseMatch*>(this->getOwner()->getGametype());
+ this->owner_ = orxonox_cast<TeamBaseMatch*>(this->getOwner()->getGametype().get());
else
this->owner_ = 0;
}
Modified: code/branches/core5/src/modules/overlays/hud/UnderAttackHealthBar.cc
===================================================================
--- code/branches/core5/src/modules/overlays/hud/UnderAttackHealthBar.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/modules/overlays/hud/UnderAttackHealthBar.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -77,7 +77,7 @@
{
this->owner_ = player;
- UnderAttack* ua = orxonox_cast<UnderAttack*>(player->getGametype());
+ UnderAttack* ua = orxonox_cast<UnderAttack*>(player->getGametype().get());
if (ua)
{
this->setOwner(ua->getDestroyer());
Modified: code/branches/core5/src/modules/pong/Pong.cc
===================================================================
--- code/branches/core5/src/modules/pong/Pong.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/modules/pong/Pong.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -157,7 +157,7 @@
this->center_->fireEvent();
if (player)
- this->gtinfo_.sendAnnounceMessage(player->getName() + " scored");
+ this->gtinfo_->sendAnnounceMessage(player->getName() + " scored");
}
if (this->ball_)
Modified: code/branches/core5/src/modules/pong/PongCenterpoint.cc
===================================================================
--- code/branches/core5/src/modules/pong/PongCenterpoint.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/modules/pong/PongCenterpoint.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -72,7 +72,7 @@
{
if (this->getGametype() && this->getGametype()->isA(Class(Pong)))
{
- Pong* pong_gametype = orxonox_cast<Pong*>(this->getGametype());
+ Pong* pong_gametype = orxonox_cast<Pong*>(this->getGametype().get());
pong_gametype->setCenterpoint(this);
}
}
Modified: code/branches/core5/src/modules/pong/PongScore.cc
===================================================================
--- code/branches/core5/src/modules/pong/PongScore.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/modules/pong/PongScore.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -132,7 +132,7 @@
SUPER(PongScore, changedOwner);
if (this->getOwner() && this->getOwner()->getGametype())
- this->owner_ = orxonox_cast<Pong*>(this->getOwner()->getGametype());
+ this->owner_ = orxonox_cast<Pong*>(this->getOwner()->getGametype().get());
else
this->owner_ = 0;
}
Modified: code/branches/core5/src/orxonox/gametypes/Asteroids.cc
===================================================================
--- code/branches/core5/src/orxonox/gametypes/Asteroids.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/gametypes/Asteroids.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -53,7 +53,7 @@
if (this->time_ < 0 && !this->hasEnded() && this->timerIsActive_)
{
- this->gtinfo_.sendAnnounceMessage("Time's up - you have lost the match!");
+ this->gtinfo_->sendAnnounceMessage("Time's up - you have lost the match!");
this->end();
}
}
@@ -62,7 +62,7 @@
{
if (victim && victim->getPlayer())
{
- this->gtinfo_.sendAnnounceMessage("You're dead - you have lost the match!");
+ this->gtinfo_->sendAnnounceMessage("You're dead - you have lost the match!");
this->end();
}
}
Modified: code/branches/core5/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/branches/core5/src/orxonox/gametypes/Gametype.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/gametypes/Gametype.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -46,11 +46,13 @@
{
CreateUnloadableFactory(Gametype);
- Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator)
+ Gametype::Gametype(BaseObject* creator) : BaseObject(creator)
{
RegisterObject(Gametype);
+
+ this->gtinfo_ = new GametypeInfo(creator);
- this->setGametype(this);
+ this->setGametype(SmartPtr<Gametype>(this, false));
this->defaultControllableEntity_ = Class(Spectator);
@@ -76,6 +78,12 @@
else
this->scoreboard_ = 0;
}
+
+ Gametype::~Gametype()
+ {
+ if (this->isInitialized())
+ this->gtinfo_->destroy();
+ }
void Gametype::setConfigValues()
{
@@ -99,12 +107,12 @@
this->time_ -= dt;
}
- if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_)
- this->gtinfo_.startCountdown_ -= dt;
+ if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_)
+ this->gtinfo_->startCountdown_ -= dt;
- if (!this->gtinfo_.bStarted_)
+ if (!this->gtinfo_->bStarted_)
this->checkStart();
- else if (!this->gtinfo_.bEnded_)
+ else if (!this->gtinfo_->bEnded_)
this->spawnDeadPlayersIfRequested();
this->assignDefaultPawnsIfNeeded();
@@ -114,14 +122,14 @@
{
this->addBots(this->numberOfBots_);
- this->gtinfo_.bStarted_ = true;
+ this->gtinfo_->bStarted_ = true;
this->spawnPlayersIfRequested();
}
void Gametype::end()
{
- this->gtinfo_.bEnded_ = true;
+ this->gtinfo_->bEnded_ = true;
for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
{
@@ -242,9 +250,9 @@
it->second.frags_++;
if (killer->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
- this->gtinfo_.sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
+ this->gtinfo_->sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
if (victim->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
- this->gtinfo_.sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
+ this->gtinfo_->sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
}
}
@@ -307,7 +315,7 @@
{
it->second.state_ = PlayerState::Dead;
- if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_)
+ if (!it->first->isReadyToSpawn() || !this->gtinfo_->bStarted_)
{
this->spawnPlayerAsDefaultPawn(it->first);
it->second.state_ = PlayerState::Dead;
@@ -318,14 +326,14 @@
void Gametype::checkStart()
{
- if (!this->gtinfo_.bStarted_)
+ if (!this->gtinfo_->bStarted_)
{
- if (this->gtinfo_.bStartCountdownRunning_)
+ if (this->gtinfo_->bStartCountdownRunning_)
{
- if (this->gtinfo_.startCountdown_ <= 0)
+ if (this->gtinfo_->startCountdown_ <= 0)
{
- this->gtinfo_.bStartCountdownRunning_ = false;
- this->gtinfo_.startCountdown_ = 0;
+ this->gtinfo_->bStartCountdownRunning_ = false;
+ this->gtinfo_->startCountdown_ = 0;
this->start();
}
}
@@ -348,8 +356,8 @@
}
if (allplayersready && hashumanplayers)
{
- this->gtinfo_.startCountdown_ = this->initialStartCountdown_;
- this->gtinfo_.bStartCountdownRunning_ = true;
+ this->gtinfo_->startCountdown_ = this->initialStartCountdown_;
+ this->gtinfo_->bStartCountdownRunning_ = true;
}
}
}
Modified: code/branches/core5/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/core5/src/orxonox/gametypes/Gametype.h 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/gametypes/Gametype.h 2009-09-27 02:13:13 UTC (rev 5806)
@@ -67,19 +67,19 @@
public:
Gametype(BaseObject* creator);
- virtual ~Gametype() {}
+ virtual ~Gametype();
void setConfigValues();
virtual void tick(float dt);
inline const GametypeInfo* getGametypeInfo() const
- { return &this->gtinfo_; }
+ { return this->gtinfo_; }
inline bool hasStarted() const
- { return this->gtinfo_.bStarted_; }
+ { return this->gtinfo_->bStarted_; }
inline bool hasEnded() const
- { return this->gtinfo_.bEnded_; }
+ { return this->gtinfo_->bEnded_; }
virtual void start();
virtual void end();
@@ -113,14 +113,14 @@
{ this->spawnpoints_.insert(spawnpoint); }
inline bool isStartCountdownRunning() const
- { return this->gtinfo_.bStartCountdownRunning_; }
+ { return this->gtinfo_->bStartCountdownRunning_; }
inline float getStartCountdown() const
- { return this->gtinfo_.startCountdown_; }
+ { return this->gtinfo_->startCountdown_; }
inline void setHUDTemplate(const std::string& name)
- { this->gtinfo_.hudtemplate_ = name; }
+ { this->gtinfo_->hudtemplate_ = name; }
inline const std::string& getHUDTemplate() const
- { return this->gtinfo_.hudtemplate_; }
+ { return this->gtinfo_->hudtemplate_; }
void addBots(unsigned int amount);
void killBots(unsigned int amount = 0);
@@ -162,7 +162,7 @@
virtual void spawnPlayersIfRequested();
virtual void spawnDeadPlayersIfRequested();
- GametypeInfo gtinfo_;
+ SmartPtr<GametypeInfo> gtinfo_;
bool bAutoStart_;
bool bForceSpawn_;
Modified: code/branches/core5/src/orxonox/gametypes/TeamBaseMatch.cc
===================================================================
--- code/branches/core5/src/orxonox/gametypes/TeamBaseMatch.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/gametypes/TeamBaseMatch.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -66,12 +66,12 @@
if (teamnr == 0)
{
base->setState(BaseState::ControlTeam1);
- this->gtinfo_.sendAnnounceMessage("The red team captured a base");
+ this->gtinfo_->sendAnnounceMessage("The red team captured a base");
}
if (teamnr == 1)
{
base->setState(BaseState::ControlTeam2);
- this->gtinfo_.sendAnnounceMessage("The blue team captured a base");
+ this->gtinfo_->sendAnnounceMessage("The blue team captured a base");
}
}
@@ -193,9 +193,9 @@
continue;
if (it->second == winningteam)
- this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
+ this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
else
- this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+ this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
}
this->end();
Modified: code/branches/core5/src/orxonox/gametypes/UnderAttack.cc
===================================================================
--- code/branches/core5/src/orxonox/gametypes/UnderAttack.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/gametypes/UnderAttack.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -80,9 +80,9 @@
continue;
if (it->second == 0)
- this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
+ this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
else
- this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+ this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
}
}
}
@@ -163,9 +163,9 @@
continue;
if (it->second == 1)
- this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
+ this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
else
- this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+ this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
}
}
@@ -177,7 +177,7 @@
COUT(0) << message << std::endl;
Host::Broadcast(message);
*/
- this->gtinfo_.sendAnnounceMessage(message);
+ this->gtinfo_->sendAnnounceMessage(message);
if (timesequence_ >= 30 && timesequence_ <= 60)
{
Modified: code/branches/core5/src/orxonox/infos/HumanPlayer.cc
===================================================================
--- code/branches/core5/src/orxonox/infos/HumanPlayer.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/infos/HumanPlayer.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -161,8 +161,12 @@
PlayerInfo::changedGametype();
if (this->isInitialized() && this->isLocalPlayer())
- if (this->getGametype()->getHUDTemplate() != "")
+ {
+ if (this->getGametype() && this->getGametype()->getHUDTemplate() != "")
this->setGametypeHUDTemplate(this->getGametype()->getHUDTemplate());
+ else
+ this->setGametypeHUDTemplate("");
+ }
}
void HumanPlayer::updateHumanHUD()
Modified: code/branches/core5/src/orxonox/worldentities/pawns/Destroyer.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/pawns/Destroyer.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/worldentities/pawns/Destroyer.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -39,7 +39,7 @@
{
RegisterObject(Destroyer);
- UnderAttack* gametype = orxonox_cast<UnderAttack*>(this->getGametype());
+ UnderAttack* gametype = orxonox_cast<UnderAttack*>(this->getGametype().get());
if (gametype)
{
gametype->addDestroyer(this);
Modified: code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc
===================================================================
--- code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc 2009-09-27 00:33:48 UTC (rev 5805)
+++ code/branches/core5/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc 2009-09-27 02:13:13 UTC (rev 5806)
@@ -44,7 +44,7 @@
this->state_ = BaseState::Uncontrolled;
- TeamBaseMatch* gametype = orxonox_cast<TeamBaseMatch*>(this->getGametype());
+ TeamBaseMatch* gametype = orxonox_cast<TeamBaseMatch*>(this->getGametype().get());
if (gametype)
{
gametype->addBase(this);
@@ -57,7 +57,7 @@
{
this->fireEvent();
- TeamDeathmatch* gametype = orxonox_cast<TeamDeathmatch*>(this->getGametype());
+ TeamDeathmatch* gametype = orxonox_cast<TeamDeathmatch*>(this->getGametype().get());
if (!gametype)
return;
More information about the Orxonox-commit
mailing list