[Orxonox-commit 5916] r10575 - in code/branches/core7/src/orxonox: . gametypes overlays
landauf at orxonox.net
landauf at orxonox.net
Wed Sep 9 14:02:01 CEST 2015
Author: landauf
Date: 2015-09-09 14:02:01 +0200 (Wed, 09 Sep 2015)
New Revision: 10575
Modified:
code/branches/core7/src/orxonox/Level.cc
code/branches/core7/src/orxonox/gametypes/Gametype.cc
code/branches/core7/src/orxonox/gametypes/Gametype.h
code/branches/core7/src/orxonox/overlays/OverlayGroup.cc
code/branches/core7/src/orxonox/overlays/OverlayGroup.h
Log:
create the scoreboard directly with the correct gametype. this prevents that we have to re-set the gametype (and pass it to sub-overlays).
Modified: code/branches/core7/src/orxonox/Level.cc
===================================================================
--- code/branches/core7/src/orxonox/Level.cc 2015-09-09 11:49:55 UTC (rev 10574)
+++ code/branches/core7/src/orxonox/Level.cc 2015-09-09 12:02:01 UTC (rev 10575)
@@ -121,8 +121,10 @@
this->gametype_ = gametype;
Gametype* rootgametype = orxonox_cast<Gametype*>(identifier->fabricate(this));
+
rootgametype->setLevel(NULL); // avoid circular references
this->setGametype(rootgametype);
+ rootgametype->init(); // call init() AFTER the gametype was set
if (LevelManager::exists())
LevelManager::getInstance().requestActivity(this);
Modified: code/branches/core7/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/branches/core7/src/orxonox/gametypes/Gametype.cc 2015-09-09 11:49:55 UTC (rev 10574)
+++ code/branches/core7/src/orxonox/gametypes/Gametype.cc 2015-09-09 12:02:01 UTC (rev 10575)
@@ -63,9 +63,9 @@
this->setGametype(StrongPtr<Gametype>(this, false));
this->gtinfo_ = new GametypeInfo(context);
- this->gtinfo_->setGametype(this);
this->defaultControllableEntity_ = Class(Spectator);
+ this->scoreboard_ = 0;
this->bAutoStart_ = false;
this->bForceSpawn_ = false;
@@ -80,16 +80,6 @@
this->setConfigValues();
- // load the corresponding score board
- if (GameMode::showsGraphics() && !this->scoreboardTemplate_.empty())
- {
- this->scoreboard_ = new OverlayGroup(context);
- this->scoreboard_->addTemplate(this->scoreboardTemplate_);
- this->scoreboard_->setGametype(this);
- }
- else
- this->scoreboard_ = 0;
-
ModifyConsoleCommand(__CC_addBots_name).setObject(this);
ModifyConsoleCommand(__CC_killBots_name).setObject(this);
}
@@ -106,6 +96,20 @@
}
}
+ /**
+ * @brief Initializes sub-objects of the Gametype. This must be called after the constructor.
+ * At this point, the context is expected to have the current gametype. This allows to pass the current gametype to the sub-objects via constructor.
+ */
+ void Gametype::init()
+ {
+ // load the corresponding score board
+ if (GameMode::showsGraphics() && !this->scoreboardTemplate_.empty())
+ {
+ this->scoreboard_ = new OverlayGroup(this->getContext());
+ this->scoreboard_->addTemplate(this->scoreboardTemplate_);
+ }
+ }
+
void Gametype::setConfigValues()
{
SetConfigValue(initialStartCountdown_, 3.0f);
Modified: code/branches/core7/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/core7/src/orxonox/gametypes/Gametype.h 2015-09-09 11:49:55 UTC (rev 10574)
+++ code/branches/core7/src/orxonox/gametypes/Gametype.h 2015-09-09 12:02:01 UTC (rev 10575)
@@ -71,6 +71,8 @@
Gametype(Context* context);
virtual ~Gametype();
+ virtual void init();
+
void setConfigValues();
virtual void tick(float dt);
Modified: code/branches/core7/src/orxonox/overlays/OverlayGroup.cc
===================================================================
--- code/branches/core7/src/orxonox/overlays/OverlayGroup.cc 2015-09-09 11:49:55 UTC (rev 10574)
+++ code/branches/core7/src/orxonox/overlays/OverlayGroup.cc 2015-09-09 12:02:01 UTC (rev 10575)
@@ -150,15 +150,6 @@
(*it)->changedVisibility(); //inform all Child Overlays that our visibility has changed
}
- //! Changes the gametype of all elements
- void OverlayGroup::changedGametype()
- {
- SUPER( OverlayGroup, changedGametype );
-
- for (std::set< StrongPtr<OrxonoxOverlay> >::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
- (*it)->setGametype(this->getGametype());
- }
-
void OverlayGroup::setOwner(BaseObject* owner)
{
this->owner_ = owner;
Modified: code/branches/core7/src/orxonox/overlays/OverlayGroup.h
===================================================================
--- code/branches/core7/src/orxonox/overlays/OverlayGroup.h 2015-09-09 11:49:55 UTC (rev 10574)
+++ code/branches/core7/src/orxonox/overlays/OverlayGroup.h 2015-09-09 12:02:01 UTC (rev 10575)
@@ -68,7 +68,6 @@
{ return this->hudElements_; }
virtual void changedVisibility();
- virtual void changedGametype();
void setOwner(BaseObject* owner);
inline BaseObject* getOwner() const
More information about the Orxonox-commit
mailing list