[Orxonox-commit 2770] r7474 - in code/trunk: data/levels src/modules/notifications src/modules/notifications/dispatchers src/modules/objects src/modules/questsystem src/orxonox
dafrick at orxonox.net
dafrick at orxonox.net
Tue Sep 21 23:15:44 CEST 2010
Author: dafrick
Date: 2010-09-21 23:15:44 +0200 (Tue, 21 Sep 2010)
New Revision: 7474
Removed:
code/trunk/src/modules/questsystem/QuestNotification.cc
code/trunk/src/modules/questsystem/QuestNotification.h
Modified:
code/trunk/data/levels/notifications.oxw
code/trunk/src/modules/notifications/Notification.cc
code/trunk/src/modules/notifications/Notification.h
code/trunk/src/modules/notifications/NotificationDispatcher.cc
code/trunk/src/modules/notifications/NotificationDispatcher.h
code/trunk/src/modules/notifications/NotificationManager.cc
code/trunk/src/modules/notifications/NotificationManager.h
code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc
code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
code/trunk/src/modules/notifications/dispatchers/SimpleNotification.cc
code/trunk/src/modules/objects/Script.cc
code/trunk/src/modules/objects/Script.h
code/trunk/src/modules/questsystem/CMakeLists.txt
code/trunk/src/modules/questsystem/QuestDescription.cc
code/trunk/src/modules/questsystem/QuestDescription.h
code/trunk/src/modules/questsystem/QuestsystemPrereqs.h
code/trunk/src/orxonox/PlayerManager.cc
Log:
Synchronizing Notifications.
In the course of that, notifications are not longer sent by creating a Notification and the calling notification.send() bur by letting the NotificationManager handle all this: NotificationManager::getInstance().sendNotification(message)
This made QuestNotification obsolete, thus it was removde.
Also did some work on synchronizing the Script class. It should work properly most of the time, but the current solution is unreliable and unsatisfactory. So this will change as soon as I know how.
Modified: code/trunk/data/levels/notifications.oxw
===================================================================
--- code/trunk/data/levels/notifications.oxw 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/data/levels/notifications.oxw 2010-09-21 21:15:44 UTC (rev 7474)
@@ -22,7 +22,7 @@
<Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
- <CommandNotification preMessage="Move '" postMessage="' to look left." command="scale 1 rotateYaw">
+ <CommandNotification preMessage="Open the PickupInventory by pressing '" postMessage="'." command="OrxonoxOverlay toggleVisibility PickupInventory">
<events>
<trigger>
<DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn" />
Modified: code/trunk/src/modules/notifications/Notification.cc
===================================================================
--- code/trunk/src/modules/notifications/Notification.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/Notification.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -41,19 +41,13 @@
namespace orxonox
{
- CreateUnloadableFactory(Notification);
-
- registerMemberNetworkFunction(Notification, send);
-
/**
@brief
Default constructor. Initializes the object.
- @param creator
- The object that created this Notification
*/
- Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
+ Notification::Notification()
{
- RegisterObject(Notification);
+ RegisterRootObject(Notification);
this->initialize();
this->registerVariables();
}
@@ -66,12 +60,11 @@
@param message
The message of the Notification.
*/
- Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
+ Notification::Notification(const std::string & message)
{
- RegisterObject(Notification);
+ RegisterRootObject(Notification);
this->initialize();
this->message_ = message;
- this->registerVariables();
}
/**
@@ -94,40 +87,16 @@
this->sent_ = false;
}
- void Notification::registerVariables(void)
- {
- registerVariable(this->message_);
- registerVariable(this->sender_);
- registerVariable(this->sent_);
- }
-
/**
@brief
Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
- @param clientId
- The id of the client that this Notification is sent to.
@param sender
The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
@return
Returns true if successful.
*/
- bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
+ bool Notification::send(const std::string & sender)
{
- COUT(0) << "MUP: " << Host::getPlayerID() << "|" << clientId << std::endl;
- if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
- {
- this->sendHelper(sender);
- }
- else if(GameMode::isServer())
- {
- callMemberNetworkFunction(Notification, send, this->getObjectID(), clientId, clientId, sender);
- }
-
- return true;
- }
-
- bool Notification::sendHelper(const std::string& sender)
- {
if(this->isSent()) //TODO: Needed?
return false;
Modified: code/trunk/src/modules/notifications/Notification.h
===================================================================
--- code/trunk/src/modules/notifications/Notification.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/Notification.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -50,15 +50,14 @@
@author
Damian 'Mozork' Frick
*/
- class _NotificationsExport Notification : public BaseObject, public Synchronisable
+ class _NotificationsExport Notification : public OrxonoxClass
{
public:
- Notification(BaseObject* creator);
- Notification(BaseObject* creator, const std::string & message);
+ Notification();
+ Notification(const std::string & message);
virtual ~Notification();
- bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager.
- bool sendHelper(const std::string& sender);
+ bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
/**
@brief Checks whether the Notification was sent.
Modified: code/trunk/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -34,28 +34,35 @@
#include "NotificationDispatcher.h"
#include "core/CoreIncludes.h"
+#include "core/EventIncludes.h"
#include "core/XMLPort.h"
-#include "core/EventIncludes.h"
-#include "Notification.h"
-#include "NotificationManager.h"
+#include "network/NetworkFunction.h"
+#include "network/Host.h"
+
+#include "infos/PlayerInfo.h"
#include "interfaces/PlayerTrigger.h"
-#include "infos/PlayerInfo.h"
#include "worldentities/pawns/Pawn.h"
+#include "Notification.h"
+#include "NotificationManager.h"
+
namespace orxonox
{
CreateUnloadableFactory(NotificationDispatcher);
+ registerMemberNetworkFunction(NotificationDispatcher, dispatch);
+
/**
@brief
Default constructor. Initializes the object.
*/
- NotificationDispatcher::NotificationDispatcher(BaseObject* creator) : BaseObject(creator)
+ NotificationDispatcher::NotificationDispatcher(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
{
RegisterObject(NotificationDispatcher);
this->sender_ = NotificationManager::NONE;
+ this->registerVariables();
}
/**
@@ -85,6 +92,11 @@
XMLPortEventState(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode);
}
+ void NotificationDispatcher::registerVariables(void)
+ {
+ registerVariable(this->sender_, VariableDirection::ToClient);
+ }
+
/**
@brief
Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded.
@@ -93,10 +105,15 @@
*/
void NotificationDispatcher::dispatch(unsigned int clientId)
{
- const std::string message = this->createNotificationMessage();
- Notification* notification = new Notification(this, message);
-
- notification->send(clientId, this->getSender());
+ if(GameMode::isStandalone() || Host::getPlayerID() == clientId || this->getSyncMode() == 0x0)
+ {
+ const std::string message = this->createNotificationMessage();
+ NotificationManager::sendNotification(message, clientId, this->getSender());
+ }
+ else if(GameMode::isServer())
+ {
+ callMemberNetworkFunction(NotificationDispatcher, dispatch, this->getObjectID(), clientId, clientId);
+ }
}
/**
@@ -122,7 +139,7 @@
// If the trigger is a PlayerTrigger.
if(pTrigger != NULL)
{
- if(!pTrigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
+ if(!pTrigger->isForPlayer()) // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
return false;
else
pawn = pTrigger->getTriggeringPlayer();
@@ -132,11 +149,11 @@
if(pawn == NULL)
{
- COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
+ COUT(4) << "The NotificationDispatcher was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
return false;
}
- //! Extract the PlayerInfo from the Pawn.
+ // Extract the PlayerInfo from the Pawn.
PlayerInfo* player = pawn->getPlayer();
if(player == NULL)
Modified: code/trunk/src/modules/notifications/NotificationDispatcher.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -39,6 +39,7 @@
#include <string>
#include "core/BaseObject.h"
+#include "network/synchronisable/Synchronisable.h"
namespace orxonox
{
@@ -49,7 +50,7 @@
@author
Damian 'Mozork' Frick
*/
- class _NotificationsExport NotificationDispatcher : public BaseObject
+ class _NotificationsExport NotificationDispatcher : public BaseObject, public Synchronisable
{
public:
NotificationDispatcher(BaseObject* creator); //!< Default constructor. Initializes the object.
@@ -71,6 +72,8 @@
protected:
std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher.
+ void registerVariables(void);
+
/**
@brief Set the sender of the Notification dispatched by this NotificationDispatcher.
@param sender The name of the sender.
Modified: code/trunk/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationManager.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/NotificationManager.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -37,6 +37,8 @@
#include "core/CoreIncludes.h"
#include "core/GUIManager.h"
#include "core/LuaState.h"
+#include "network/Host.h"
+#include "network/NetworkFunction.h"
#include "util/ScopedSingletonManager.h"
#include "interfaces/NotificationListener.h"
@@ -59,6 +61,8 @@
SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
+ registerStaticNetworkFunction(NotificationManager::sendNotification);
+
/**
@brief
Constructor. Registers the Object.
@@ -101,6 +105,19 @@
this->queues_.clear();
}
+ /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender)
+ {
+ if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
+ {
+ Notification* notification = new Notification(message);
+ notification->send(sender);
+ }
+ else if(GameMode::isServer())
+ {
+ callStaticNetworkFunction(NotificationManager::sendNotification, clientId, message, clientId, sender);
+ }
+ }
+
/**
@brief
Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationListeners associated with its sender.
Modified: code/trunk/src/modules/notifications/NotificationManager.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationManager.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/NotificationManager.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -69,6 +69,8 @@
static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.
static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
+ static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE);
+
bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
Modified: code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -54,6 +54,7 @@
RegisterObject(CommandNotification);
this->setSender("commandNotification");
+ this->registerVariables();
}
/**
@@ -78,6 +79,13 @@
XMLPortParam(CommandNotification, "postMessage", setPostMessage, getPostMessage, xmlelement, mode);
}
+ void CommandNotification::registerVariables(void)
+ {
+ registerVariable(this->command_, VariableDirection::ToClient);
+ registerVariable(this->preMessage_, VariableDirection::ToClient);
+ registerVariable(this->postMessage_, VariableDirection::ToClient);
+ }
+
/**
@brief
Composes the Notification of the preMessage the name of the key the command is mapped to and the postMessage.
Modified: code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/CommandNotification.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/dispatchers/CommandNotification.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -37,8 +37,8 @@
#include "notifications/NotificationsPrereqs.h"
+#include <string>
#include "notifications/NotificationDispatcher.h"
-#include <string>
namespace orxonox {
@@ -85,6 +85,8 @@
std::string preMessage_; //!< The first part of the displayed message.
std::string postMessage_; //!< The last part of the displayed message.
+ void registerVariables(void);
+
/**
@brief Set the command, whose key is displayed.
@param command The name of the command.
Modified: code/trunk/src/modules/notifications/dispatchers/SimpleNotification.cc
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/SimpleNotification.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/notifications/dispatchers/SimpleNotification.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -49,6 +49,8 @@
RegisterObject(SimpleNotification);
this->setSender("simpleNotification");
+
+ this->setSyncMode(0x0);
}
/**
Modified: code/trunk/src/modules/objects/Script.cc
===================================================================
--- code/trunk/src/modules/objects/Script.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/objects/Script.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -34,11 +34,20 @@
#include "core/GameMode.h"
#include "core/LuaState.h"
#include "core/XMLPort.h"
+#include "network/Host.h"
+#include "network/NetworkFunction.h"
+#include "PlayerManager.h"
+#include "infos/PlayerInfo.h"
+#include "interfaces/PlayerTrigger.h"
+#include "worldentities/pawns/Pawn.h"
+
namespace orxonox
{
CreateFactory(Script);
+ registerMemberNetworkFunction(Script, execute);
+
// Initializing constants.
/*static*/ const std::string Script::NORMAL = "normal";
/*static*/ const std::string Script::LUA = "lua";
@@ -50,7 +59,7 @@
@param creator
The creator of this object.
*/
- Script::Script(BaseObject* creator) : BaseObject(creator)
+ Script::Script(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
{
RegisterObject(Script);
@@ -62,6 +71,9 @@
this->times_ = Script::INF;
this->needsGraphics_ = false;
+ this->counter_ = 0.0f;
+
+ this->registerVariables();
}
/**
@@ -91,11 +103,12 @@
XMLPortParam(Script, "onLoad", setOnLoad, isOnLoad, xmlelement, mode).defaultValues(true);
XMLPortParam(Script, "times", setTimes, getTimes, xmlelement, mode).defaultValues(Script::INF);
XMLPortParam(Script, "needsGraphics", setNeedsGraphics, getNeedsGraphics, xmlelement, mode).defaultValues(false);
+ XMLPortParam(Script, "forAll", setForAll, isForAll, xmlelement, mode).defaultValues(false);
XMLPortEventSink(Script, BaseObject, "trigger", trigger, xmlelement, mode);
- if(this->isOnLoad()) // If the object is onLoad the code is executed at once.
- this->execute();
+ if(this->isOnLoad()) // If the object is onLoad the code is executed at once for all clients.
+ this->execute(0);
}
/**
@@ -115,39 +128,153 @@
/**
@brief
+ Register the variables that need to be synchronized.
+ */
+ void Script::registerVariables(void)
+ {
+ registerVariable(code_, VariableDirection::ToClient);
+ registerVariable(needsGraphics_, VariableDirection::ToClient);
+ registerVariable(modeStr_, VariableDirection::ToClient, new NetworkCallback<Script>(this, &Script::modeChanged));
+ }
+
+ void Script::modeChanged(void)
+ {
+ this->setMode(this->modeStr_);
+ }
+
+ void Script::tick(float dt)
+ {
+ SUPER(Script, tick, dt);
+
+ if(!this->clientCallbacks_.empty())
+ {
+ if(this->counter_ < 2.0f)
+ {
+ this->counter_ += dt;
+ }
+ else
+ {
+ for(std::vector<unsigned int>::iterator it = this->clientCallbacks_.begin(); it != this->clientCallbacks_.end(); it++)
+ {
+ this->execute(*it, true);
+ }
+ this->clientCallbacks_.clear();
+ this->counter_ = 0.0f;
+ }
+ }
+ }
+
+ /**
+ @brief
Is called when an event comes in trough the event port.
@param triggered
Whether the event is triggering or un-triggering.
+ @param trigger
+ The object that caused the event to be fired.
+ @return
+ Returns true if successful.
*/
- void Script::trigger(bool triggered)
+ bool Script::trigger(bool triggered, BaseObject* trigger)
{
- if(triggered) // If the event is triggering (instead of un-triggering) the code of this Script is executed.
- this->execute();
+ if(!triggered || !this->isActive()) // If the Script is inactive it cannot be executed.
+ return false;
+
+ COUT(4) << "Script (&" << this << ") triggered." << std::endl;
+
+ PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
+ Pawn* pawn = NULL;
+
+ // If the trigger is a PlayerTrigger.
+ if(pTrigger != NULL)
+ {
+ if(!pTrigger->isForPlayer()) // The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
+ return false;
+ else
+ pawn = pTrigger->getTriggeringPlayer();
+ }
+ else
+ return false;
+
+ if(pawn == NULL) //TODO: Will this ever happen? If not, change in NotificationDispatcher as well.
+ {
+ COUT(4) << "The Script was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
+ return false;
+ }
+
+ // Extract the PlayerInfo from the Pawn.
+ PlayerInfo* player = pawn->getPlayer();
+
+ if(player == NULL)
+ {
+ COUT(3) << "The PlayerInfo* is NULL." << std::endl;
+ return false;
+ }
+
+ this->execute(player->getClientID());
+ return true;
}
/**
@brief
- Executes the Scripts code, depending on the mode.
+ Executes the Scripts code for the input client, depending on the mode.
+ @param clientId
+ The Id of the client the Script should be executed for.
+ @param fromCallback
+ Whether this method is executed in response to the connectedCallback().
*/
- void Script::execute()
+ void Script::execute(unsigned int clientId, bool fromCallback)
{
- if(this->times_ != Script::INF && this->remainingExecutions_ == 0)
- return;
+ if(GameMode::isServer())
+ {
+ // If the number of executions have been used up.
+ if(this->times_ != Script::INF && this->remainingExecutions_ == 0)
+ return;
- // If the code needs graphics to be executed but the GameMode doesn't show graphics the code isn't executed.
- if(this->needsGraphics_ && !GameMode::showsGraphics())
- return;
+ // Decrement the number of remaining executions.
+ if(this->times_ != Script::INF)
+ this->remainingExecutions_--;
+ }
- if(this->mode_ == ScriptMode::normal) // If the mode is 'normal'.
- CommandExecutor::execute(this->code_);
- else if(this->mode_ == ScriptMode::lua) // If it's 'lua'.
+ if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
{
- assert(this->luaState_);
- this->luaState_->doString(this->code_);
+ // If the code needs graphics to be executed but the GameMode doesn't show graphics the code isn't executed.
+ if(this->needsGraphics_ && !GameMode::showsGraphics())
+ return;
+
+ if(this->mode_ == ScriptMode::normal) // If the mode is 'normal'.
+ CommandExecutor::execute(this->code_);
+ else if(this->mode_ == ScriptMode::lua) // If it's 'lua'.
+ {
+ if(this->luaState_ == NULL)
+ this->luaState_ = new LuaState();
+ this->luaState_->doString(this->code_);
+ }
}
+ if(!GameMode::isStandalone() && GameMode::isServer() && Host::getPlayerID() != clientId)
+ {
+ if(!fromCallback && this->isForAll())
+ {
+ const std::map<unsigned int, PlayerInfo*> clients = PlayerManager::getInstance().getClients();
+ for(std::map<unsigned int, PlayerInfo*>::const_iterator it = clients.begin(); it != clients.end(); it++)
+ {
+ callMemberNetworkFunction(Script, execute, this->getObjectID(), it->first, it->first, false);
+ }
+ }
+ else
+ {
+ callMemberNetworkFunction(Script, execute, this->getObjectID(), clientId, clientId, false);
+ }
+ }
+ }
- if(this->times_ != Script::INF)
- this->remainingExecutions_--;
+ void Script::clientConnected(unsigned int clientId)
+ {
+ if(!GameMode::isStandalone() && GameMode::isServer() && this->isOnLoad())
+ {
+ if(clientId != 0)
+ //TODO: Do better. This is only a temporary fix.
+ this->clientCallbacks_.push_back(clientId);
+ }
}
/**
@@ -159,18 +286,23 @@
void Script::setMode(const std::string& mode)
{
if(mode == Script::NORMAL)
+ {
this->setMode(ScriptMode::normal);
+ this->modeStr_ = Script::NORMAL;
+ }
else if(mode == Script::LUA)
{
this->setMode(ScriptMode::lua);
+ this->modeStr_ = Script::LUA;
// Creates a new LuaState.
if(this->luaState_ == NULL)
this->luaState_ = new LuaState();
}
else
{
- COUT(2) << "Invalid mode '" << mode << "' in Script object." << std::endl;
+ COUT(2) << "Invalid mode '" << mode << "' in Script object. Setting to 'normal'." << std::endl;
this->setMode(ScriptMode::normal);
+ this->modeStr_ = Script::NORMAL;
}
}
@@ -209,8 +341,9 @@
}
else
{
- COUT(2) << "Invalid times '" << times << "' in Script." << std::endl;
+ COUT(2) << "Invalid times '" << times << "' in Script. Setting to infinity." << std::endl;
this->times_ = Script::INF;
+ this->remainingExecutions_ = Script::INF;
}
}
Modified: code/trunk/src/modules/objects/Script.h
===================================================================
--- code/trunk/src/modules/objects/Script.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/objects/Script.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -32,7 +32,12 @@
#include "objects/ObjectsPrereqs.h"
#include <string>
+#include <vector>
+
#include "core/BaseObject.h"
+#include "tools/interfaces/Tickable.h"
+#include "network/synchronisable/Synchronisable.h"
+#include "network/ClientConnectionListener.h"
namespace orxonox
{
@@ -53,8 +58,9 @@
There are three parameters:
'code': The code that should be executed.
'mode': The mode, specifying whether the set code should be executed the normal way ('normal') or in lua ('lua'). Default is 'normal'.
- 'onLoad': Whether the code is executed upon loading (creation) of this object. Default is true.
+ 'onLoad': Whether the code is executed upon loading (creation) of this object. If this is set the code is executed ofr all players, regardless of the value of parameter 'forAll'. Default is true.
'needsGraphics': Whether the code needs graphics to be executed or not. Default is false.
+ 'forAll': Whether the code is executed for all players each time the Script is triggered or jut for the player triggering the Script. If forAll is false, which is default, the event that triggers the Script must come from a PlayerTrigger.
Here are two examples illustrating the usage:
@code
@@ -76,7 +82,7 @@
Benjamin Knecht
Damian 'Mozork' Frick
*/
- class _ObjectsExport Script : public BaseObject
+ class _ObjectsExport Script : public BaseObject, public Synchronisable, public ClientConnectionListener, public Tickable
{
public:
Script(BaseObject* creator);
@@ -85,9 +91,11 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Script object through XML.
virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a port that can be used to channel events and react to them.
- void trigger(bool triggered); //!< Is called when an event comes in trough the event port.
- void execute(); //!< Executes the Scripts code, depending on the mode.
+ virtual void tick(float dt);
+ bool trigger(bool triggered, BaseObject* trigger); //!< Is called when an event comes in trough the event port.
+ void execute(unsigned int clientId, bool fromCallback = false); //!< Executes the Scripts code for the input client, depending on the mode.
+
/**
@brief Sets the code that is executed by this Script.
@param code The code that is executed by this Script.
@@ -138,6 +146,22 @@
bool getNeedsGraphics(void)
{ return this->needsGraphics_; }
+ /**
+ @brief Set whether the code is executed for all players or just for the player triggering the Script.
+ @param forAll If true the code is executed for all players.
+ */
+ void setForAll(bool forAll)
+ { this->forAll_ = forAll; }
+ /**
+ @brief Get whether the Script executes its code for all players or just for the player triggering the Script.
+ @return Returns true if the code is executed for all players, false if not.
+ */
+ bool isForAll(void)
+ { return this->forAll_; }
+
+ virtual void clientConnected(unsigned int clientId);
+ virtual void clientDisconnected(unsigned int clientid) {}
+
private:
//! Static variables to avoid magic strings.
static const std::string NORMAL;
@@ -149,10 +173,19 @@
bool onLoad_; //!< Whether the Scripts code is executed upon loading (creation) of this Script.
int times_; //!< The number of times the Scripts code is executed at the most. -1 denotes infinity.
bool needsGraphics_; //!< Whether the code to be executed needs graphics.
+ bool forAll_; //!< Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering the Script.
+ std::string modeStr_;
+
+ std::vector<unsigned int> clientCallbacks_;
+ float counter_;
+
LuaState* luaState_; //!< The LuaState to execute the code in lua.
int remainingExecutions_; //!< The number of remainign executions. -1 denotes infinity.
+ void registerVariables(void);
+ void modeChanged();
+
/**
@brief Sets the mode of the Script.
@param mode The mode of the Script.
Modified: code/trunk/src/modules/questsystem/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/questsystem/CMakeLists.txt 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/questsystem/CMakeLists.txt 2010-09-21 21:15:44 UTC (rev 7474)
@@ -9,7 +9,6 @@
QuestItem.cc
QuestListener.cc
QuestManager.cc
- QuestNotification.cc
)
ADD_SUBDIRECTORY(effects)
Modified: code/trunk/src/modules/questsystem/QuestDescription.cc
===================================================================
--- code/trunk/src/modules/questsystem/QuestDescription.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/questsystem/QuestDescription.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -37,12 +37,16 @@
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
-#include "QuestNotification.h"
+#include "infos/PlayerInfo.h"
+#include "notifications/NotificationManager.h"
+
namespace orxonox
{
CreateFactory(QuestDescription);
+ /*static*/ const std::string QuestDescription::SENDER = "questsystem";
+
/**
@brief
Constructor. Registers and initializes the object.
@@ -114,8 +118,7 @@
return false;
}
- QuestNotification* notification = new QuestNotification(this, message);
- notification->send(player);
+ NotificationManager::sendNotification(message, player->getClientID(), QuestDescription::SENDER);
return true;
}
Modified: code/trunk/src/modules/questsystem/QuestDescription.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestDescription.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/questsystem/QuestDescription.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -127,6 +127,8 @@
{ return notificationHelper("quest", "complete", player); }
private:
+ static const std::string SENDER;
+
std::string title_; //!< The title.
std::string description_; //!< The description.
std::string failMessage_; //!< The message displayed when the Quest is failed.
Deleted: code/trunk/src/modules/questsystem/QuestNotification.cc
===================================================================
--- code/trunk/src/modules/questsystem/QuestNotification.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/questsystem/QuestNotification.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -1,89 +0,0 @@
-/*
- * 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 thes
- * 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:
- * Damian 'Mozork' Frick
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file QuestNotification.cc
- @brief Implementation of the QuestNotification class.
-*/
-
-#include "QuestNotification.h"
-#include "core/CoreIncludes.h"
-#include "infos/PlayerInfo.h"
-
-namespace orxonox {
-
- /*static*/ const std::string QuestNotification::SENDER("questsystem");
-
- CreateUnloadableFactory(QuestNotification);
-
- /**
- @brief
- Default Constructor. Creates a useless QuestNotification.
- */
- QuestNotification::QuestNotification(BaseObject* creator) : Notification(creator)
- {
- RegisterObject(QuestNotification);
- }
-
- /**
- @brief
- Creates a QuestNotification with the input message.
- @param creator
- The creator of this object
- @param message
- The message to be sent.
- */
- QuestNotification::QuestNotification(BaseObject* creator, const std::string & message) : Notification(creator, message)
- {
- RegisterObject(QuestNotification);
- }
-
- /**
- @brief
- Destructor.
- */
- QuestNotification::~QuestNotification()
- {
-
- }
-
- /**
- @brief
- Send the QuestNotification.
- @param player
- The player the Notification is sent to.
- @return
- Returns true if successful.
- */
- bool QuestNotification::send(PlayerInfo* player)
- {
- return this->Notification::send(player->getClientID(), QuestNotification::SENDER);
- }
-
-
-}
Deleted: code/trunk/src/modules/questsystem/QuestNotification.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestNotification.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/questsystem/QuestNotification.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -1,67 +0,0 @@
-/*
- * 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 thes
- * 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:
- * Damian 'Mozork' Frick
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file QuestNotification.h
- @brief Definition of the QuestNotification class.
- @ingroup Questsystem
-*/
-
-#ifndef _QuestNotification_H__
-#define _QuestNotification_H__
-
-#include "questsystem/QuestsystemPrereqs.h"
-
-#include <string>
-#include "notifications/Notification.h"
-
-namespace orxonox {
-
- /**
- @brief
- The QuestNotification is a special Notification that has the single property that it is only sent by the questsystem.
- @author
- Damian 'Mozork' Frick
- */
- class _QuestsystemExport QuestNotification : public Notification
- {
- public:
- QuestNotification(BaseObject* creator); //!< Default Constructor.
- QuestNotification(BaseObject* creator, const std::string & message); //!< Constructor.
- virtual ~QuestNotification(); //!< Destructor.
-
- bool send(PlayerInfo* player); //!< Send the QuestNotification.
-
- private:
- static const std::string SENDER; //!< A string identifying the questsystem as the sender.
-
- };
-
-}
-
-#endif /* _QuestNotification_H__ */
Modified: code/trunk/src/modules/questsystem/QuestsystemPrereqs.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestsystemPrereqs.h 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/modules/questsystem/QuestsystemPrereqs.h 2010-09-21 21:15:44 UTC (rev 7474)
@@ -80,7 +80,6 @@
class QuestItem;
class QuestListener;
class QuestManager;
- class QuestNotification;
}
#endif /* _QuestsystemPrereqs_H__ */
Modified: code/trunk/src/orxonox/PlayerManager.cc
===================================================================
--- code/trunk/src/orxonox/PlayerManager.cc 2010-09-21 19:50:41 UTC (rev 7473)
+++ code/trunk/src/orxonox/PlayerManager.cc 2010-09-21 21:15:44 UTC (rev 7474)
@@ -28,12 +28,13 @@
#include "PlayerManager.h"
-#include "util/ScopedSingletonManager.h"
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
+#include "util/ScopedSingletonManager.h"
+
#include "Level.h"
+#include "LevelManager.h"
#include "infos/HumanPlayer.h"
-#include "LevelManager.h"
namespace orxonox
{
More information about the Orxonox-commit
mailing list