[Orxonox-commit 3960] r8634 - in code/branches/tutoriallevel3/src/orxonox: gametypes infos interfaces
dafrick at orxonox.net
dafrick at orxonox.net
Sat May 28 11:19:03 CEST 2011
Author: dafrick
Date: 2011-05-28 11:19:02 +0200 (Sat, 28 May 2011)
New Revision: 8634
Modified:
code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc
code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h
code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc
code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h
code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.cc
Log:
Gametype status notifications now working.
Modified: code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc 2011-05-28 00:49:58 UTC (rev 8633)
+++ code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc 2011-05-28 09:19:02 UTC (rev 8634)
@@ -57,8 +57,6 @@
this->setGametype(SmartPtr<Gametype>(this, false));
this->defaultControllableEntity_ = Class(Spectator);
-
- this->bFirstTick_ = true;
this->bAutoStart_ = false;
this->bForceSpawn_ = false;
@@ -113,13 +111,6 @@
{
SUPER(Gametype, tick, dt);
- // Activate the GametypeInfo.
- if(this->bFirstTick_)
- {
- this->gtinfo_->setActive(true);
- this->bFirstTick_ = false;
- }
-
//count timer
if (timerIsActive_)
{
@@ -133,7 +124,16 @@
this->gtinfo_->countdownStartCountdown(dt);
if (!this->gtinfo_->hasStarted())
+ {
+ for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+ {
+ // Inform the GametypeInfo that the player is ready to spawn.
+ if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
+ this->gtinfo_->playerReadyToSpawn(it->first);
+ }
+
this->checkStart();
+ }
else if (!this->gtinfo_->hasEnded())
this->spawnDeadPlayersIfRequested();
@@ -181,6 +181,7 @@
void Gametype::playerEntered(PlayerInfo* player)
{
this->players_[player].state_ = PlayerState::Joined;
+ this->gtinfo_->playerEntered(player);
}
bool Gametype::playerLeft(PlayerInfo* player)
@@ -395,11 +396,6 @@
allplayersready = false;
if (it->first->isHumanPlayer())
hashumanplayers = true;
-
- // Inform the GametypeInfo that the player is ready to spawn.
- // TODO: Can it happen, that that changes?
- if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
- this->gtinfo_->playerReadyToSpawn(it->first);
}
if (allplayersready && hashumanplayers)
{
Modified: code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h 2011-05-28 00:49:58 UTC (rev 8633)
+++ code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h 2011-05-28 09:19:02 UTC (rev 8634)
@@ -166,8 +166,6 @@
virtual void spawnDeadPlayersIfRequested();
SmartPtr<GametypeInfo> gtinfo_;
-
- bool bFirstTick_; //!< Whether this is the first tick or not.
bool bAutoStart_;
bool bForceSpawn_;
Modified: code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc
===================================================================
--- code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc 2011-05-28 00:49:58 UTC (rev 8633)
+++ code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc 2011-05-28 09:19:02 UTC (rev 8634)
@@ -39,6 +39,7 @@
#include "network/NetworkFunction.h"
#include "util/Convert.h"
+#include "controllers/HumanController.h"
#include "interfaces/GametypeMessageListener.h"
#include "interfaces/NotificationListener.h"
@@ -54,6 +55,9 @@
registerMemberNetworkFunction(GametypeInfo, dispatchStaticMessage);
registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
+ registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn);
+ registerMemberNetworkFunction(GametypeInfo, changedSpawned);
+
/*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
/**
@@ -63,14 +67,14 @@
GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
{
RegisterObject(GametypeInfo);
-
- this->bActive_ = false; // At first the GametypeInfo is inactive.
this->bStarted_ = false;
this->bEnded_ = false;
this->startCountdown_ = 0.0f;
this->bStartCountdownRunning_ = false;
this->counter_ = 0;
+ this->spawned_ = false;
+ this->readyToSpawn_ = false;
this->registerVariables();
}
@@ -91,19 +95,6 @@
/**
@brief
- Is called when the activity has changed.
- */
- void GametypeInfo::changedActivity(void)
- {
- SUPER(GametypeInfo, changedActivity);
-
- // If the GametypeInfo has become active the "Press [Fire] to start the match" notification is sent.
- if(this->isActive())
- NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER);
- }
-
- /**
- @brief
Is called when the game has changed to started.
*/
void GametypeInfo::changedStarted(void)
@@ -128,11 +119,8 @@
*/
void GametypeInfo::changedStartCountdownRunning(void)
{
- // Clear the notifications if the countdown has stopped running.
- if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
- NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
// Send first countdown notification if the countdown has started.
- if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
+ if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
}
@@ -143,24 +131,29 @@
void GametypeInfo::changedCountdownCounter(void)
{
// Send countdown notification if the counter has gone down.
- if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
+ if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
}
/**
@brief
- Is called when a player has become ready to spawn.
- @param player
- The player that has become ready to spawn.
+ Inform the GametypeInfo that the local player has changed its ready to spawn status.
+ @param ready
+ Whether the player has become ready to spawn or not.
*/
- void GametypeInfo::changedReadyToSpawn(PlayerInfo* player)
+ void GametypeInfo::changedReadyToSpawn(bool ready)
{
- // Send "Waiting for other players" over the network to the right player if a player has become ready to spawn.
- if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
- NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
- // Clear the notifications if the player has respawned.
- if(this->hasStarted() && !this->hasEnded())
- NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
+ if(this->readyToSpawn_ == ready)
+ return;
+
+ this->readyToSpawn_ = ready;
+
+ // Send "Waiting for other players" if the player is ready to spawn but the game has not yet started nor is the countdown running.
+ if(this->readyToSpawn_ && !this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
+ NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER);
+ // Send current countdown if the player is ready to spawn and the countdown has already started.
+ else if(this->readyToSpawn_ && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
+ NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
}
/**
@@ -240,11 +233,14 @@
*/
void GametypeInfo::startStartCountdown(void)
{
- if(this->bStartCountdownRunning_)
- return;
-
- this->bStartCountdownRunning_ = true;
- this->changedStartCountdownRunning();
+ if(GameMode::isMaster())
+ {
+ if(this->bStartCountdownRunning_)
+ return;
+
+ this->bStartCountdownRunning_ = true;
+ this->changedStartCountdownRunning();
+ }
}
/**
@@ -253,11 +249,14 @@
*/
void GametypeInfo::stopStartCountdown(void)
{
- if(!this->bStartCountdownRunning_)
- return;
-
- this->bStartCountdownRunning_ = false;
- this->changedStartCountdownRunning();
+ if(GameMode::isMaster())
+ {
+ if(!this->bStartCountdownRunning_)
+ return;
+
+ this->bStartCountdownRunning_ = false;
+ this->changedStartCountdownRunning();
+ }
}
/**
@@ -268,12 +267,15 @@
*/
void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
{
- // If the player has spawned already.
- if(this->spawned_.find(player) != this->spawned_.end())
- return;
+ if(GameMode::isMaster())
+ {
+ // If the player has spawned already.
+ if(this->spawnedPlayers_.find(player) != this->spawnedPlayers_.end())
+ return;
- this->spawned_.insert(player);
- this->changedReadyToSpawn(player);
+ this->spawnedPlayers_.insert(player);
+ this->setReadyToSpawnHelper(player, true);
+ }
}
/**
@@ -284,9 +286,14 @@
*/
void GametypeInfo::pawnKilled(PlayerInfo* player)
{
- NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
- // Remove the player from the list of players that have spawned, since it currently is not.
- this->spawned_.erase(player);
+ if(GameMode::isMaster())
+ {
+ NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ // Remove the player from the list of players that have spawned, since it currently is not.
+ this->spawnedPlayers_.erase(player);
+ this->setReadyToSpawnHelper(player, false);
+ this->setSpawnedHelper(player, false);
+ }
}
/**
@@ -297,10 +304,93 @@
*/
void GametypeInfo::playerSpawned(PlayerInfo* player)
{
- if(this->hasStarted() && !this->hasEnded())
- NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
+ if(GameMode::isMaster())
+ {
+ if(this->hasStarted() && !this->hasEnded())
+ {
+ //NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
+ this->setSpawnedHelper(player, true);
+ }
+ }
}
+ /**
+ @brief
+ Inform the GametypeInfo that the local player has changed its spawned status.
+ @param spawned
+ Whether the local player has changed to spawned or to not spawned.
+ */
+ void GametypeInfo::changedSpawned(bool spawned)
+ {
+ if(this->spawned_ == spawned)
+ return;
+
+ this->spawned_ = spawned;
+ // Clear the notifications if the Player has spawned.
+ if(this->spawned_ && !this->hasEnded())
+ NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo about a player that has entered,
+ @param player
+ The player that has entered.
+ */
+ void GametypeInfo::playerEntered(PlayerInfo* player)
+ {
+ if(GameMode::isMaster())
+ {
+ // Display "Press [Fire] to start the match" if the game has not yet ended.
+ if(!this->hasEnded())
+ NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ // Else display "Game has ended".
+ else
+ NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ }
+ }
+
+ /**
+ @brief
+ Helper method. Sends changedReadyToSpawn notifiers over the network.
+ @param player
+ The player that has changed its ready to spawn status.
+ @param ready
+ The new ready to spawn status.
+ */
+ void GametypeInfo::setReadyToSpawnHelper(PlayerInfo* player, bool ready)
+ {
+ if(GameMode::isMaster())
+ {
+ if(player->getClientID() == CLIENTID_SERVER)
+ this->changedReadyToSpawn(ready);
+ else
+ callMemberNetworkFunction(GametypeInfo, changedReadyToSpawn, this->getObjectID(), player->getClientID(), ready);
+ }
+ }
+
+ /**
+ @brief
+ Helper method. Sends changedSpawned notifiers over the network.
+ @param player
+ The player that has changed its spawned status.
+ @param ready
+ The new spawned status.
+ */
+ void GametypeInfo::setSpawnedHelper(PlayerInfo* player, bool spawned)
+ {
+ if(GameMode::isMaster())
+ {
+ if(player->getClientID() == CLIENTID_SERVER)
+ this->changedSpawned(spawned);
+ else
+ callMemberNetworkFunction(GametypeInfo, changedSpawned, this->getObjectID(), player->getClientID(), spawned);
+ }
+ }
+
+ // Announce messages.
+ // TODO: Replace with notifications.
+
void GametypeInfo::sendAnnounceMessage(const std::string& message)
{
if (GameMode::isMaster())
Modified: code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h
===================================================================
--- code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h 2011-05-28 00:49:58 UTC (rev 8633)
+++ code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h 2011-05-28 09:19:02 UTC (rev 8634)
@@ -60,8 +60,6 @@
GametypeInfo(BaseObject* creator);
virtual ~GametypeInfo();
- virtual void changedActivity(void); // Is called when the activity has changed.
-
/**
@brief Get whether the game has started yet.
@return Returns true if the game has started, false if not.
@@ -102,6 +100,22 @@
{ return this->counter_; }
void changedCountdownCounter(void); // Is called when the start countdown counter has changed.
+ /**
+ @brief Get whether the local player is ready to spawn.
+ @return Returns true if the player is ready to spawn, false if not.
+ */
+ inline bool isReadyToSpawn() const
+ { return this->readyToSpawn_; }
+ void changedReadyToSpawn(bool ready); // Inform the GametypeInfo that the local player has changed its spawned status.
+
+ /**
+ @brief Get whether the local player is spawned.
+ @return Returns true if the local player is currently spawned, false if not.
+ */
+ inline bool isSpawned() const
+ { return this->spawned_; }
+ void changedSpawned(bool spawned); // Inform the GametypeInfo that the local player has changed its spawned status.
+
inline const std::string& getHUDTemplate() const
{ return this->hudtemplate_; }
@@ -119,8 +133,6 @@
void dispatchFadingMessage(const std::string& message);
protected:
- void changedReadyToSpawn(PlayerInfo* player); // Is called when a player has become ready to spawn.
-
void start(void); // Inform the GametypeInfo that the game has started.
void end(void); // Inform the GametypeInfo that the game has ended.
void setStartCountdown(float countdown); // Set the start countdown to the input value.
@@ -131,12 +143,15 @@
void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn.
void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed.
void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned.
+ void playerEntered(PlayerInfo* player); // Inform the GametypeInfo about a player that has entered,
inline void setHUDTemplate(const std::string& templateName)
{ this->hudtemplate_ = templateName; };
private:
void registerVariables();
+ void setSpawnedHelper(PlayerInfo* player, bool spawned); // Helper method. Sends changedReadyToSpawn notifiers over the network.
+ void setReadyToSpawnHelper(PlayerInfo* player, bool ready); // Helper method. Sends changedSpawned notifiers over the network.
static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications.
@@ -147,7 +162,9 @@
unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter.
std::string hudtemplate_;
- std::set<PlayerInfo*> spawned_; //!< A set of players that are currently spawned.
+ std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned.
+ bool spawned_; //!< Whether the local Player is currently spawned.
+ bool readyToSpawn_; //!< Whether the local Player is ready to spawn.
};
}
Modified: code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.cc
===================================================================
--- code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.cc 2011-05-28 00:49:58 UTC (rev 8633)
+++ code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.cc 2011-05-28 09:19:02 UTC (rev 8634)
@@ -81,12 +81,12 @@
// If we're on the server (and the server is not the intended recipient of the notification/command) we send it over the network.
else if(GameMode::isServer() && sendMode == notificationSendMode::network && Host::getPlayerID() != clientId)
{
- callStaticNetworkFunction(NotificationListener::sendHelper, clientId, message, sender, (unsigned int)messageType);
+ callStaticNetworkFunction(NotificationListener::sendHelper, clientId, message, sender, isCommand, (unsigned int)messageType);
}
else if(GameMode::isServer() && sendMode == notificationSendMode::broadcast)
{
// TODO: Works as intended?
- callStaticNetworkFunction(NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, (unsigned int)messageType);
+ callStaticNetworkFunction(NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, (unsigned int)messageType);
}
}
More information about the Orxonox-commit
mailing list