[Orxonox-commit 231] r2890 - in trunk/src/orxonox: objects/gametypes objects/infos overlays overlays/hud
landauf at orxonox.net
landauf at orxonox.net
Thu Apr 2 20:42:12 CEST 2009
Author: landauf
Date: 2009-04-02 20:42:11 +0200 (Thu, 02 Apr 2009)
New Revision: 2890
Added:
trunk/src/orxonox/overlays/hud/PongScore.cc
trunk/src/orxonox/overlays/hud/PongScore.h
Modified:
trunk/src/orxonox/objects/gametypes/Gametype.cc
trunk/src/orxonox/objects/gametypes/Gametype.h
trunk/src/orxonox/objects/gametypes/Pong.cc
trunk/src/orxonox/objects/gametypes/Pong.h
trunk/src/orxonox/objects/infos/HumanPlayer.cc
trunk/src/orxonox/overlays/OrxonoxOverlay.h
trunk/src/orxonox/overlays/OverlayGroup.cc
trunk/src/orxonox/overlays/OverlayGroup.h
trunk/src/orxonox/overlays/hud/CMakeLists.txt
Log:
- Added overlay element for the Pong Gametype
- Changed the type of the overlay's owner to BaseObject (former ControllableEntity) to allow other classes to own an overlay (for example a Gametype)
- OverlayGroup does now use a std::set instead of a std::map to store it's overlay elements. Therefore a name is not anymore compulsory for an overlay element.
Modified: trunk/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/Gametype.cc 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/objects/gametypes/Gametype.cc 2009-04-02 18:42:11 UTC (rev 2890)
@@ -230,6 +230,15 @@
it->second.frags_++;
}
+ int Gametype::getScore(PlayerInfo* player) const
+ {
+ std::map<PlayerInfo*, Player>::const_iterator it = this->players_.find(player);
+ if (it != this->players_.end())
+ return it->second.frags_;
+ else
+ return 0;
+ }
+
SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const
{
if (this->spawnpoints_.size() > 0)
Modified: trunk/src/orxonox/objects/gametypes/Gametype.h
===================================================================
--- trunk/src/orxonox/objects/gametypes/Gametype.h 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/objects/gametypes/Gametype.h 2009-04-02 18:42:11 UTC (rev 2890)
@@ -106,6 +106,8 @@
inline const std::map<PlayerInfo*, Player>& getPlayers() const
{ return this->players_; }
+ int getScore(PlayerInfo* player) const;
+
inline void registerSpawnPoint(SpawnPoint* spawnpoint)
{ this->spawnpoints_.insert(spawnpoint); }
Modified: trunk/src/orxonox/objects/gametypes/Pong.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/Pong.cc 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/objects/gametypes/Pong.cc 2009-04-02 18:42:11 UTC (rev 2890)
@@ -53,6 +53,8 @@
this->bat_[0] = 0;
this->bat_[1] = 0;
+ this->setHUDTemplate("PongHUD");
+
this->starttimer_.setTimer(1.0, false, this, createExecutor(createFunctor(&Pong::startBall)));
this->starttimer_.stopTimer();
@@ -180,4 +182,20 @@
if (this->ball_ && this->center_)
this->ball_->setSpeed(this->center_->getBallSpeed());
}
+
+ PlayerInfo* Pong::getLeftPlayer() const
+ {
+ if (this->bat_ && this->bat_[0])
+ return this->bat_[0]->getPlayer();
+ else
+ return 0;
+ }
+
+ PlayerInfo* Pong::getRightPlayer() const
+ {
+ if (this->bat_ && this->bat_[1])
+ return this->bat_[1]->getPlayer();
+ else
+ return 0;
+ }
}
Modified: trunk/src/orxonox/objects/gametypes/Pong.h
===================================================================
--- trunk/src/orxonox/objects/gametypes/Pong.h 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/objects/gametypes/Pong.h 2009-04-02 18:42:11 UTC (rev 2890)
@@ -52,6 +52,9 @@
void setCenterpoint(PongCenterpoint* center)
{ this->center_ = center; }
+ PlayerInfo* getLeftPlayer() const;
+ PlayerInfo* getRightPlayer() const;
+
protected:
void startBall();
Modified: trunk/src/orxonox/objects/infos/HumanPlayer.cc
===================================================================
--- trunk/src/orxonox/objects/infos/HumanPlayer.cc 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/objects/infos/HumanPlayer.cc 2009-04-02 18:42:11 UTC (rev 2890)
@@ -172,9 +172,6 @@
if (this->humanHud_)
this->humanHud_->setOwner(this->getControllableEntity());
-
- if (this->gametypeHud_)
- this->gametypeHud_->setOwner(this->getControllableEntity());
}
void HumanPlayer::updateHumanHUD()
@@ -205,7 +202,7 @@
{
this->gametypeHud_ = new OverlayGroup(this);
this->gametypeHud_->addTemplate(this->gametypeHudTemplate_);
- this->gametypeHud_->setOwner(this->getControllableEntity());
+ this->gametypeHud_->setOwner(this->getGametype());
}
}
}
Modified: trunk/src/orxonox/overlays/OrxonoxOverlay.h
===================================================================
--- trunk/src/orxonox/overlays/OrxonoxOverlay.h 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/overlays/OrxonoxOverlay.h 2009-04-02 18:42:11 UTC (rev 2890)
@@ -153,7 +153,7 @@
virtual void changedVisibility();
- inline void setOwner(ControllableEntity* owner)
+ inline void setOwner(BaseObject* owner)
{
if (this->owner_ != owner)
{
@@ -161,7 +161,7 @@
this->changedOwner();
}
}
- inline ControllableEntity* getOwner() const
+ inline BaseObject* getOwner() const
{ return this->owner_; }
virtual void changedOwner() {}
@@ -205,7 +205,7 @@
/** Contains all the overlays in a map for quick access via console commands.
We could also use the ObjectList, but that doesn't guarantee XMLPort(.) was called and is slower. */
static std::map<std::string, OrxonoxOverlay*> overlays_s;
- ControllableEntity* owner_;
+ BaseObject* owner_;
OverlayGroup* group_;
};
Modified: trunk/src/orxonox/overlays/OverlayGroup.cc
===================================================================
--- trunk/src/orxonox/overlays/OverlayGroup.cc 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/overlays/OverlayGroup.cc 2009-04-02 18:42:11 UTC (rev 2890)
@@ -62,8 +62,8 @@
OverlayGroup::~OverlayGroup()
{
- for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
- delete it->second;
+ for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+ delete (*it);
}
/**
@@ -82,41 +82,34 @@
XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode);
}
- //! Scales every element in the map.
+ //! Scales every element in the set.
void OverlayGroup::setScale(const Vector2& scale)
{
- for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
- (*it).second->scale(scale / this->scale_);
+ for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+ (*it)->scale(scale / this->scale_);
this->scale_ = scale;
}
- //! Scrolls every element in the map.
+ //! Scrolls every element in the set.
void OverlayGroup::setScroll(const Vector2& scroll)
{
- for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
- (*it).second->scroll(scroll - this->scroll_);
+ for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+ (*it)->scroll(scroll - this->scroll_);
this->scroll_ = scroll;
}
/**
@brief
- Adds an element to the map (used when loading with XMLPort).
+ Adds an element to the set (used when loading with XMLPort).
@remarks
The names of the OrxonoxOverlays have to be unique!
*/
void OverlayGroup::addElement(OrxonoxOverlay* element)
{
- if (hudElements_.find(element->getName()) != hudElements_.end())
- {
- COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
- }
- else
- {
- hudElements_[element->getName()] = element;
- element->setVisible(this->isVisible());
- if (this->owner_)
- element->setOwner(this->owner_);
- }
+ hudElements_.insert(element);
+ element->setVisible(this->isVisible());
+ if (this->owner_)
+ element->setOwner(this->owner_);
}
//! Returns a different element as long as index < hudElements_.size().
@@ -124,10 +117,10 @@
{
if (index < this->hudElements_.size())
{
- std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
+ std::set<OrxonoxOverlay*>::const_iterator it = hudElements_.begin();
for (unsigned int i = 0; i != index; ++it, ++i)
;
- return (*it).second;
+ return (*it);
}
else
return 0;
@@ -136,16 +129,16 @@
//! Changes the visibility of all elements
void OverlayGroup::changedVisibility()
{
- for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
- (*it).second->setVisible(this->isVisible());
+ for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+ (*it)->setVisible(this->isVisible());
}
- void OverlayGroup::setOwner(ControllableEntity* owner)
+ void OverlayGroup::setOwner(BaseObject* owner)
{
this->owner_ = owner;
- for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
- (*it).second->setOwner(owner);
+ for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
+ (*it)->setOwner(owner);
}
//########### Console commands ############
Modified: trunk/src/orxonox/overlays/OverlayGroup.h
===================================================================
--- trunk/src/orxonox/overlays/OverlayGroup.h 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/overlays/OverlayGroup.h 2009-04-02 18:42:11 UTC (rev 2890)
@@ -36,7 +36,7 @@
#include "OrxonoxPrereqs.h"
-#include <map>
+#include <set>
#include <OgrePrerequisites.h>
#include "core/BaseObject.h"
#include "util/Math.h"
@@ -63,13 +63,13 @@
static void scaleGroup(const std::string& name, float scale);
static void scrollGroup(const std::string& name, const Vector2& scroll);
- inline const std::map<std::string, OrxonoxOverlay*>& getOverlays() const
+ inline const std::set<OrxonoxOverlay*>& getOverlays() const
{ return this->hudElements_; }
void changedVisibility();
- void setOwner(ControllableEntity* owner);
- inline ControllableEntity* getOwner() const
+ void setOwner(BaseObject* owner);
+ inline BaseObject* getOwner() const
{ return this->owner_; }
//! Scales each OrxonoxOverlay individually by scale.
@@ -88,10 +88,10 @@
OrxonoxOverlay* getElement(unsigned int index);
private:
- std::map<std::string, OrxonoxOverlay*> hudElements_; //!< Contains all the OrxonoxOverlays of the this group.
- Vector2 scale_; //!< Current scale (independent of the elements).
- Vector2 scroll_; //!< Current scrolling offset.
- ControllableEntity* owner_; //!< The owner of this OverlayGroup
+ std::set<OrxonoxOverlay*> hudElements_; //!< Contains all the OrxonoxOverlays of the this group.
+ Vector2 scale_; //!< Current scale (independent of the elements).
+ Vector2 scroll_; //!< Current scrolling offset.
+ BaseObject* owner_; //!< The owner of this OverlayGroup
};
}
Modified: trunk/src/orxonox/overlays/hud/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/overlays/hud/CMakeLists.txt 2009-04-02 16:36:23 UTC (rev 2889)
+++ trunk/src/orxonox/overlays/hud/CMakeLists.txt 2009-04-02 18:42:11 UTC (rev 2890)
@@ -6,4 +6,5 @@
HUDHealthBar.cc
ChatOverlay.cc
GametypeStatus.cc
+ PongScore.cc
)
Added: trunk/src/orxonox/overlays/hud/PongScore.cc
===================================================================
--- trunk/src/orxonox/overlays/hud/PongScore.cc (rev 0)
+++ trunk/src/orxonox/overlays/hud/PongScore.cc 2009-04-02 18:42:11 UTC (rev 2890)
@@ -0,0 +1,139 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "PongScore.h"
+
+#include <OgreTextAreaOverlayElement.h>
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "util/Convert.h"
+#include "objects/gametypes/Pong.h"
+#include "objects/infos/PlayerInfo.h"
+
+namespace orxonox
+{
+ CreateFactory(PongScore);
+
+ PongScore::PongScore(BaseObject* creator) : OverlayText(creator)
+ {
+ RegisterObject(PongScore);
+
+ this->owner_ = 0;
+
+ this->bShowName_ = false;
+ this->bShowScore_ = false;
+ this->bShowLeftPlayer_ = false;
+ this->bShowRightPlayer_ = false;
+ }
+
+ PongScore::~PongScore()
+ {
+ }
+
+ void PongScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(PongScore, XMLPort, xmlelement, mode);
+
+ XMLPortParam(PongScore, "showname", setShowName, getShowName, xmlelement, mode).defaultValues(false);
+ XMLPortParam(PongScore, "showscore", setShowScore, getShowScore, xmlelement, mode).defaultValues(false);
+ XMLPortParam(PongScore, "showleftplayer", setShowLeftPlayer, getShowLeftPlayer, xmlelement, mode).defaultValues(false);
+ XMLPortParam(PongScore, "showrightplayer", setShowRightPlayer, getShowRightPlayer, xmlelement, mode).defaultValues(false);
+ }
+
+ void PongScore::tick(float dt)
+ {
+ SUPER(PongScore, tick, dt);
+
+ if (this->owner_)
+ {
+ PlayerInfo* player1 = this->owner_->getLeftPlayer();
+ PlayerInfo* player2 = this->owner_->getRightPlayer();
+
+ std::string name1;
+ std::string name2;
+
+ std::string score1 = "0";
+ std::string score2 = "0";
+
+ if (player1)
+ {
+ name1 = player1->getName();
+ score1 = convertToString(this->owner_->getScore(player1));
+ }
+
+ if (player2)
+ {
+ name2 = player2->getName();
+ score2 = convertToString(this->owner_->getScore(player2));
+ }
+
+ std::string output1;
+ if (this->bShowLeftPlayer_)
+ {
+ if (this->bShowName_ && this->bShowScore_ && player1)
+ output1 = name1 + " - " + score1;
+ else if (this->bShowScore_)
+ output1 = score1;
+ else if (this->bShowName_)
+ output1 = name1;
+ }
+
+ std::string output2;
+ if (this->bShowRightPlayer_)
+ {
+ if (this->bShowName_ && this->bShowScore_ && player2)
+ output2 = score2 + " - " + name2;
+ else if (this->bShowScore_)
+ output2 = score2;
+ else if (this->bShowName_)
+ output2 = name2;
+ }
+
+ std::string output = "PONG";
+ if (this->bShowName_ || this->bShowScore_)
+ {
+ if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)
+ output = output1 + ":" + output2;
+ else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)
+ output = output1 + output2;
+ }
+
+ this->setCaption(output);
+ }
+ }
+
+
+ void PongScore::changedOwner()
+ {
+ SUPER(PongScore, changedOwner);
+
+ this->owner_ = dynamic_cast<Pong*>(this->getOwner());
+ }
+}
Added: trunk/src/orxonox/overlays/hud/PongScore.h
===================================================================
--- trunk/src/orxonox/overlays/hud/PongScore.h (rev 0)
+++ trunk/src/orxonox/overlays/hud/PongScore.h 2009-04-02 18:42:11 UTC (rev 2890)
@@ -0,0 +1,77 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _PongScore_H__
+#define _PongScore_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "overlays/OverlayText.h"
+#include "objects/Tickable.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport PongScore : public OverlayText, public Tickable
+ {
+ public:
+ PongScore(BaseObject* creator);
+ ~PongScore();
+
+ virtual void tick(float dt);
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ virtual void changedOwner();
+
+ inline void setShowName(bool value)
+ { this->bShowName_ = value; }
+ inline bool getShowName() const
+ { return this->bShowName_; }
+
+ inline void setShowScore(bool value)
+ { this->bShowScore_ = value; }
+ inline bool getShowScore() const
+ { return this->bShowScore_; }
+
+ inline void setShowLeftPlayer(bool value)
+ { this->bShowLeftPlayer_ = value; }
+ inline bool getShowLeftPlayer() const
+ { return this->bShowLeftPlayer_; }
+
+ inline void setShowRightPlayer(bool value)
+ { this->bShowRightPlayer_ = value; }
+ inline bool getShowRightPlayer() const
+ { return this->bShowRightPlayer_; }
+
+ private:
+ Pong* owner_;
+ bool bShowName_;
+ bool bShowScore_;
+ bool bShowLeftPlayer_;
+ bool bShowRightPlayer_;
+ };
+}
+#endif /* _PongScore_H__ */
More information about the Orxonox-commit
mailing list