Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7163 for code/trunk/src


Ignore:
Timestamp:
Aug 11, 2010, 8:55:13 AM (14 years ago)
Author:
dafrick
Message:

Merged presentation3 branch into trunk.

Location:
code/trunk
Files:
6 deleted
254 edited
67 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/CMakeLists.txt

    r5781 r7163  
    3131INCLUDE(OrxonoxConfig.cmake)
    3232
    33 ################ Library Defines ################
     33####### Library Behaviour (dependencies) ########
    3434
    3535# Disable Boost auto linking completely
     
    4040ADD_COMPILER_FLAGS("-DENET_DLL"           WIN32 LINK_ENET_DYNAMIC)
    4141ADD_COMPILER_FLAGS("-DLUA_BUILD_AS_DLL"   WIN32 LINK_LUA_DYNAMIC)
    42 ADD_COMPILER_FLAGS("-DOIS_DYNAMIC_LIB")
    4342ADD_COMPILER_FLAGS("-DZLIB_DLL"           WIN32 LINK_ZLIB_DYNAMIC)
    4443# If no defines are specified, these libs get linked dynamically
     
    4746ADD_COMPILER_FLAGS("-DSTATIC_BUILD"       WIN32 NOT LINK_TCL_DYNAMIC)
    4847
     48######### Library Behaviour (external) ##########
     49
    4950# Use TinyXML++
    5051ADD_COMPILER_FLAGS("-DTIXML_USE_TICPP")
     52
     53# Default linking for externals is SHARED
     54SET(ORXONOX_EXTERNAL_LINK_MODE SHARED CACHE STRING "Link mode for external libraries that we build ourselves. Note: on Windows, some libraries cannot be linked shared.")
     55
     56IF(ORXONOX_EXTERNAL_LINK_MODE STREQUAL "SHARED")
     57  SET(_external_shared_link TRUE)
     58ELSE()
     59  SET(_external_shared_link FALSE)
     60ENDIF()
     61# If no defines are specified, these libs get linked dynamically
     62ADD_COMPILER_FLAGS("-DCEGUILUA_STATIC"             WIN32 NOT _external_shared_link)
     63ADD_COMPILER_FLAGS("-DOGRE_GUIRENDERER_STATIC_LIB" WIN32 NOT _external_shared_link)
     64ADD_COMPILER_FLAGS("-DOIS_STATIC_LIB"              WIN32 NOT _external_shared_link)
     65ADD_COMPILER_FLAGS("-DTOLUA_STATIC_BUILD"          WIN32 NOT _external_shared_link)
    5166
    5267############## Include Directories ##############
  • code/trunk/src/OrxonoxConfig.cmake

    r5929 r7163  
    2727
    2828#################### Options ####################
    29 
    30 # Default linking is SHARED
    31 SET(ORXONOX_DEFAULT_LINK SHARED)
    3229
    3330# Use, i.e. don't skip the full RPATH for the build tree
  • code/trunk/src/external/ceguilua/CMakeLists.txt

    r6417 r7163  
    5656ADD_CUSTOM_COMMAND(
    5757  OUTPUT ${CEGUILUA_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lua_CEGUI.cpp
    58   COMMAND tolua++app_orxonox -n CEGUI
    59                              -w ${CEGUILUA_BINARY_DIR}
    60                              -o ${CMAKE_CFG_INTDIR}/lua_CEGUI.cpp
    61                              -L exceptions.lua
    62                              -s ${TOLUA_PARSER_SOURCE}
    63                                 CEGUI.pkg
     58  COMMAND toluaapp_orxonox -n CEGUI
     59                           -w ${CEGUILUA_BINARY_DIR}
     60                           -o ${CMAKE_CFG_INTDIR}/lua_CEGUI.cpp
     61                           -L exceptions.lua
     62                           -s ${TOLUA_PARSER_SOURCE}
     63                              CEGUI.pkg
    6464  DEPENDS              ${TOLUA_PARSER_DEPENDENCIES}
    6565  WORKING_DIRECTORY    ${RUNTIME_LIBRARY_DIRECTORY}
     
    7979    ${CEGUI_VERSION}
    8080  LINK_LIBRARIES
    81     tolua++_orxonox
     81    tolua_orxonox
    8282    ${LUA_LIBRARIES}
    8383    ${CEGUI_LIBRARY}
  • code/trunk/src/external/ceguilua/ceguilua-0.6.0/ceguilua/CEGUILua.h

    r5781 r7163  
    3535        Import / Export control macros
    3636*************************************************************************/
    37 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
     37#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUILUA_STATIC)
    3838#   ifdef CEGUILUA_EXPORTS
    3939#       define CEGUILUA_API __declspec(dllexport)
  • code/trunk/src/external/ceguilua/ceguilua-0.6.0/ceguilua/changes_orxonox.diff

    r5781 r7163  
    6767--- CEGUILua.h  Wed Jul  9 18:24:49 2008
    6868+++ CEGUILua.h  Thu Jan 29 10:17:07 2009
    69 @@ -38,7 +38,11 @@
     69@@ -34,11 +34,15 @@
     70 /*************************************************************************
     71        Import / Export control macros
     72 *************************************************************************/
     73-#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
     74+#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUILUA_STATIC)
    7075 #   ifdef CEGUILUA_EXPORTS
    7176 #       define CEGUILUA_API __declspec(dllexport)
  • code/trunk/src/external/ceguilua/ceguilua-0.6.1/ceguilua/CEGUILua.h

    r5781 r7163  
    3535        Import / Export control macros
    3636*************************************************************************/
    37 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
     37#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUILUA_STATIC)
    3838#   ifdef CEGUILUA_EXPORTS
    3939#       define CEGUILUA_API __declspec(dllexport)
  • code/trunk/src/external/ceguilua/ceguilua-0.6.1/ceguilua/changes_orxonox.diff

    r5781 r7163  
    11--- CEGUILua.h  Mi Jul  9 18:24:49 2008
    22+++ CEGUILua.h  Do Jan 29 10:18:14 2009
    3 @@ -38,7 +38,11 @@
     3@@ -34,11 +34,15 @@
     4 /*************************************************************************
     5        Import / Export control macros
     6 *************************************************************************/
     7-#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
     8+#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUILUA_STATIC)
    49 #   ifdef CEGUILUA_EXPORTS
    510 #       define CEGUILUA_API __declspec(dllexport)
  • code/trunk/src/external/ceguilua/ceguilua-0.6.2/ceguilua/CEGUILua.h

    r5781 r7163  
    3535        Import / Export control macros
    3636*************************************************************************/
    37 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
     37#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUILUA_STATIC)
    3838#   ifdef CEGUILUA_EXPORTS
    3939#       define CEGUILUA_API __declspec(dllexport)
  • code/trunk/src/external/ceguilua/ceguilua-0.6.2/ceguilua/changes_orxonox.diff

    r6762 r7163  
    8282--- CEGUILua.h  Sun Jan 25 18:32:57 2009
    8383+++ CEGUILua.h  Thu Jan 29 10:17:42 2009
    84 @@ -38,7 +38,11 @@
     84@@ -34,11 +34,15 @@
     85 /*************************************************************************
     86        Import / Export control macros
     87 *************************************************************************/
     88-#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
     89+#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUILUA_STATIC)
    8590 #   ifdef CEGUILUA_EXPORTS
    8691 #       define CEGUILUA_API __declspec(dllexport)
  • code/trunk/src/external/ogreceguirenderer/CMakeLists.txt

    r5929 r7163  
    3232ORXONOX_ADD_LIBRARY(ogreceguirenderer_orxonox
    3333  ORXONOX_EXTERNAL
    34   LINK_LIBRARIES
    35     ${OGRE_LIBRARY}
    36     ${CEGUI_LIBRARY}
    3734  DEFINE_SYMBOL
    3835    "OGRE_GUIRENDERER_EXPORTS"
    3936  VERSION
    4037    1.4.9
     38  LINK_LIBRARIES
     39    ${OGRE_LIBRARY}
     40    ${CEGUI_LIBRARY}
    4141  SOURCE_FILES
    4242    ${OCR_FILES}
  • code/trunk/src/external/ogreceguirenderer/OgreCEGUIRenderer.h

    r5781 r7163  
    3838#include <OgreTextureUnitState.h>
    3939
    40 #if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(OGRE_STATIC_LIB)
     40#if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(OGRE_GUIRENDERER_STATIC_LIB)
    4141#   ifdef OGRE_GUIRENDERER_EXPORTS
    4242#       define OGRE_GUIRENDERER_API __declspec(dllexport)
  • code/trunk/src/external/ogreceguirenderer/changes_orxonox.diff

    r5781 r7163  
    3232--- OgreCEGUIRenderer.h Wed Jan 28 21:14:09 2009
    3333+++ OgreCEGUIRenderer.h Wed Jan 28 21:06:46 2009
    34 @@ -29,9 +29,9 @@
     34@@ -29,15 +29,15 @@
    3535 #ifndef _OgreCEGUIRenderer_h_
    3636 #define _OgreCEGUIRenderer_h_
     
    4545 #include <OgreRenderQueueListener.h>
    4646 #include <OgreSceneManagerEnumerator.h>
     47 #include <OgreTextureUnitState.h>
     48
     49-#if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(OGRE_STATIC_LIB)
     50+#if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(OGRE_GUIRENDERER_STATIC_LIB)
     51 #   ifdef OGRE_GUIRENDERER_EXPORTS
     52 #       define OGRE_GUIRENDERER_API __declspec(dllexport)
     53 #   else
    4754--- OgreCEGUIResourceProvider.cpp       Wed Jan 28 21:14:09 2009
    4855+++ OgreCEGUIResourceProvider.cpp       Wed Jan 28 21:07:15 2009
  • code/trunk/src/external/ois/OISPrereqs.h

    r5781 r7163  
    6161#       else
    6262#               define OIS_WIN32_PLATFORM
    63 #               if defined( OIS_DYNAMIC_LIB )
     63#               if !defined( OIS_STATIC_LIB )
    6464#                       undef _OISExport
    6565                        //Ignorable Dll interface warning...
  • code/trunk/src/external/ois/changes_orxonox.diff

    r5929 r7163  
     1--- OISPrereqs.h        (revision 7141)
     2+++ OISPrereqs.h        (working copy)
     3@@ -60,7 +60,7 @@
     4 #              define OIS_XBOX_PLATFORM
     5 #      else
     6 #              define OIS_WIN32_PLATFORM
     7-#              if defined( OIS_DYNAMIC_LIB )
     8+#              if !defined( OIS_STATIC_LIB )
     9 #                      undef _OISExport
     10                        //Ignorable Dll interface warning...
     11 #           if !defined(OIS_MINGW_COMPILER)
    112--- linux/EventHelpers.cpp      (revision 5668)
    213+++ linux/EventHelpers.cpp      (working copy)
  • code/trunk/src/external/tinyxml/CMakeLists.txt

    r5929 r7163  
    1818 #
    1919
    20 SET_SOURCE_FILES(TINYXML++_FILES
     20SET_SOURCE_FILES(TINYXML_FILES
    2121  ticpp.h
    2222  ticpprc.h
     
    3333)
    3434
    35 ORXONOX_ADD_LIBRARY(tinyxml++_orxonox
     35ORXONOX_ADD_LIBRARY(tinyxml_orxonox
    3636  ORXONOX_EXTERNAL
    3737  NO_DLL_INTERFACE
     
    3939    2.5.3
    4040  SOURCE_FILES
    41     ${TINYXML++_FILES}
     41    ${TINYXML_FILES}
    4242)
  • code/trunk/src/external/tolua/CMakeLists.txt

    r5929 r7163  
    2020################### Tolua++ library ###################
    2121
    22 SET_SOURCE_FILES(TOLUA++_FILES
     22SET_SOURCE_FILES(TOLUA_FILES
    2323  tolua_event.h
    2424  tolua++.h
     
    3232)
    3333
    34 ORXONOX_ADD_LIBRARY(tolua++_orxonox
     34ORXONOX_ADD_LIBRARY(tolua_orxonox
    3535  ORXONOX_EXTERNAL
    3636  DEFINE_SYMBOL
     
    4141    ${LUA_LIBRARIES}
    4242  SOURCE_FILES
    43     ${TOLUA++_FILES}
     43    ${TOLUA_FILES}
    4444)
    4545
     
    4747################## Tolua++ generator ##################
    4848
    49 ORXONOX_ADD_EXECUTABLE(tolua++app_orxonox
     49ORXONOX_ADD_EXECUTABLE(toluaapp_orxonox
    5050  ORXONOX_EXTERNAL
    5151  VERSION
     
    6161SET(TOLUA_PARSER_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/all-${LUA_VERSION}.lua" CACHE INTERNAL "")
    6262SET(TOLUA_PARSER_DEPENDENCIES
    63   tolua++app_orxonox
     63  toluaapp_orxonox
    6464  ${CMAKE_CURRENT_SOURCE_DIR}/all-${LUA_VERSION}.lua
    6565  ${CMAKE_CURRENT_SOURCE_DIR}/lua/compat-5.1.lua
  • code/trunk/src/libraries/core/BaseObject.cc

    r6800 r7163  
    7575            this->setScene(this->creator_->getScene(), this->creator_->getSceneID());
    7676            this->setGametype(this->creator_->getGametype());
     77            this->setLevel(this->creator_->getLevel());
    7778        }
    7879        else
     
    8384            this->sceneID_ = OBJECTID_UNKNOWN;
    8485            this->gametype_ = 0;
     86            this->level_ = 0;
    8587        }
    8688    }
     
    103105        }
    104106    }
    105    
     107
    106108    /** @brief Adds an object which listens to the events of this object. */
    107109    void BaseObject::registerEventListener(BaseObject* object)
     
    123125        XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode);
    124126        XMLPortParamTemplate(BaseObject, "template", addTemplate, getSingleTemplate, xmlelement, mode, const std::string&);
    125        
     127
    126128        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
    127129        XMLPortObject(BaseObject, BaseObject, "eventlisteners", addEventListener, getEventListener, xmlelement, mode);
     
    194196    {
    195197        this->templates_.insert(temp);
     198        if( temp->isLink() )
     199        {
     200          this->networkTemplateNames_.insert(temp->getLink());
     201          assert( !Template::getTemplate(temp->getLink())->isLink() );
     202        }
     203        else
     204          this->networkTemplateNames_.insert(temp->getName());
    196205        temp->applyOn(this);
    197206    }
     
    363372    {
    364373        this->registerEventStates();
    365        
     374
    366375        COUT(4) << this->getIdentifier()->getName() << " (&" << this << ") processing event. originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << "), activate: " << event.activate_ << ", name: " << event.name_ << ", statename: " << event.statename_ << "." << std::endl;
    367376
  • code/trunk/src/libraries/core/BaseObject.h

    r6800 r7163  
    5151    class Scene;
    5252    class Gametype;
     53    class Level;
    5354
    5455    //! The BaseObject is the parent of all classes representing an instance in the game.
     
    154155            virtual void changedGametype() {}
    155156
     157            inline void setLevel(const SmartPtr<Level>& level)
     158            {
     159                if (level != this->level_)
     160                {
     161                    this->level_ = level;
     162                    this->changedLevel();
     163                }
     164            }
     165            inline const SmartPtr<Level>& getLevel() const { return this->level_; }
     166            virtual void changedLevel() {}
     167
    156168            void addEventSource(BaseObject* source, const std::string& state);
    157169            void removeEventSource(BaseObject* source);
     
    179191            EventState* getEventState(const std::string& name) const;
    180192
    181             std::string name_;                                 //!< The name of the object
    182             std::string oldName_;                              //!< The old name of the object
    183             mbool       bActive_;                              //!< True = the object is active
    184             mbool       bVisible_;                             //!< True = the object is visible
    185             std::string mainStateName_;
    186             Functor*    mainStateFunctor_;
     193            std::string             name_;                     //!< The name of the object
     194            std::string             oldName_;                  //!< The old name of the object
     195            mbool                   bActive_;                  //!< True = the object is active
     196            mbool                   bVisible_;                 //!< True = the object is visible
     197            std::string             mainStateName_;
     198            Functor*                mainStateFunctor_;
     199            std::set<std::string>   networkTemplateNames_;
    187200
    188201        private:
     
    209222            SmartPtr<Gametype>     gametype_;
    210223            Gametype*              oldGametype_;
     224            SmartPtr<Level>        level_;
    211225            std::set<Template*>    templates_;
    212226
  • code/trunk/src/libraries/core/CMakeLists.txt

    r6417 r7163  
    9696    input/KeyBinder.h
    9797    input/KeyBinderManager.h
    98   DEFINE_SYMBOL
    99     "CORE_SHARED_BUILD"
    10098  PCH_FILE
    10199    CorePrecompiledHeaders.h
     
    112110    ogreceguirenderer_orxonox
    113111    ois_orxonox
    114     tinyxml++_orxonox
    115     tolua++_orxonox
     112    tinyxml_orxonox
     113    tolua_orxonox
    116114    util
    117115  SOURCE_FILES
  • code/trunk/src/libraries/core/ConfigFileManager.cc

    r6536 r7163  
    3333#include "util/Convert.h"
    3434#include "util/Math.h"
     35#include "util/StringUtils.h"
    3536#include "ConsoleCommand.h"
    3637#include "ConfigValueContainer.h"
  • code/trunk/src/libraries/core/ConfigFileManager.h

    r6536 r7163  
    3939
    4040#include "util/Singleton.h"
    41 #include "util/StringUtils.h"
    4241
    4342namespace orxonox // tolua_export
  • code/trunk/src/libraries/core/Core.cc

    r6746 r7163  
    7979    SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
    8080    SetCommandLineSwitch(noIOConsole).information("Use this if you don't want to use the IOConsole (for instance for Lua debugging)");
     81
    8182#ifdef ORXONOX_PLATFORM_WINDOWS
    8283    SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)");
  • code/trunk/src/libraries/core/Event.cc

    r6859 r7163  
    6060
    6161        COUT(4) << "Processing event (EventState) : originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << "), activate: " << event.activate_ << ", name: " << event.name_ << ", statename: " << event.statename_ << ", object: " << object->getIdentifier()->getName() << " (&" << object << ")" << "." << std::endl;
    62        
     62
    6363        // check if the originator is an instance of the requested class
    6464        if (event.originator_->isA(this->subclass_))
  • code/trunk/src/libraries/core/EventIncludes.h

    r6800 r7163  
    5252    } \
    5353    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
    54    
     54
    5555#define XMLPortEventSink(classname, subclassname, statename, function, xmlelement, mode) \
    5656    orxonox::EventState* containername##function = this->getEventState(statename); \
  • code/trunk/src/libraries/core/Executor.cc

    r6417 r7163  
    3030#include "Executor.h"
    3131
     32#include <algorithm>
     33
    3234#include "util/Convert.h"
     35#include "util/Debug.h"
     36#include "util/StringUtils.h"
     37#include "util/SubString.h"
    3338#include "Language.h"
    3439
     
    6368    bool Executor::parse(const std::string& params, const std::string& delimiter) const
    6469    {
    65         EXECUTOR_PARSE(normal);
     70        unsigned int paramCount = this->functor_->getParamCount();
     71       
     72        if (paramCount == 0)
     73        {
     74            COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl;
     75            (*this->functor_)();
     76        }
     77        else if (paramCount == 1)
     78        {
     79            const std::string& temp = getStripped(params);
     80            if (!temp.empty())
     81            {
     82                COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl;
     83                (*this->functor_)(MultiType(params));
     84            }
     85            else if (this->bAddedDefaultValue_[0])
     86            {
     87                COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl;
     88                (*this->functor_)(this->defaultValue_[0]);
     89            }
     90            else
     91            {
     92                COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl;
     93                return false;
     94            }
     95        }
     96        else
     97        {
     98            SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0');
     99           
     100            for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
     101            {
     102                if (!this->bAddedDefaultValue_[i])
     103                {
     104                    COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl;
     105                    return false;
     106                }
     107            }
     108           
     109            MultiType param[MAX_FUNCTOR_ARGUMENTS];
     110            COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens (";
     111            for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++)
     112            {
     113                param[i] = tokens[i];
     114                if (i != 0)
     115                {
     116                    COUT(5) << ", ";
     117                }
     118                COUT(5) << tokens[i];
     119            }
     120            COUT(5) << ") and " << std::max((int)paramCount - (int)tokens.size(), 0) << " default values (";
     121            for (unsigned int i = tokens.size(); i < paramCount; i++)
     122            {
     123                param[i] = this->defaultValue_[i];
     124                if (i != 0)
     125                {
     126                    COUT(5) << ", ";
     127                }
     128                COUT(5) << this->defaultValue_[i];
     129            }
     130            COUT(5) << ")." << std::endl;
     131           
     132            if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string"))
     133                param[paramCount - 1] = tokens.subSet(paramCount - 1).join();
     134           
     135            switch(paramCount)
     136            {
     137                case 2:
     138                    (*this->functor_)(param[0], param[1]);
     139                    break;
     140                case 3:
     141                    (*this->functor_)(param[0], param[1], param[2]);
     142                    break;
     143                case 4:
     144                    (*this->functor_)(param[0], param[1], param[2], param[3]);
     145                    break;
     146                case 5:
     147                    (*this->functor_)(param[0], param[1], param[2], param[3], param[4]);
     148                    break;
     149            }
     150        }
     151
     152        return true;
    66153    }
    67154
  • code/trunk/src/libraries/core/Executor.h

    r6417 r7163  
    3333#include "CorePrereqs.h"
    3434
    35 #include <algorithm>
    3635#include <string>
    37 
    38 #include "util/Debug.h"
    39 #include "util/Math.h"
    40 #include "util/StringUtils.h"
    41 #include "util/SubString.h"
     36#include "util/MultiType.h"
    4237#include "Functor.h"
    43 
    44 
    45 #define EXECUTOR_PARSE_FUNCTORCALL(mode) EXECUTOR_PARSE_FUNCTORCALL##mode
    46 #define EXECUTOR_PARSE_FUNCTORCALLnormal (*this->functor_)
    47 #define EXECUTOR_PARSE_FUNCTORCALLobject (*((FunctorMember<T>*)this->functor_))
    48 
    49 #define EXECUTOR_PARSE_OBJECT(mode, comma) EXECUTOR_PARSE_OBJECT##mode##comma
    50 #define EXECUTOR_PARSE_OBJECTnormal0
    51 #define EXECUTOR_PARSE_OBJECTnormal1
    52 #define EXECUTOR_PARSE_OBJECTobject0 object
    53 #define EXECUTOR_PARSE_OBJECTobject1 object,
    54 
    55 #define EXECUTOR_PARSE(mode) \
    56     unsigned int paramCount = this->functor_->getParamCount(); \
    57     \
    58     if (paramCount == 0) \
    59     { \
    60         COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; \
    61         EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 0)); \
    62     } \
    63     else if (paramCount == 1) \
    64     { \
    65         const std::string& temp = getStripped(params); \
    66         if (!temp.empty()) \
    67         { \
    68             COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; \
    69             EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) MultiType(params)); \
    70         } \
    71         else if (this->bAddedDefaultValue_[0]) \
    72         { \
    73             COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; \
    74             EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) this->defaultValue_[0]); \
    75         } \
    76         else \
    77         { \
    78             COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; \
    79             return false; \
    80         } \
    81     } \
    82     else \
    83     { \
    84         SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \
    85         \
    86         for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \
    87         { \
    88             if (!this->bAddedDefaultValue_[i]) \
    89             { \
    90                 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; \
    91                 return false; \
    92             } \
    93         } \
    94         \
    95         MultiType param[MAX_FUNCTOR_ARGUMENTS]; \
    96         COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \
    97         for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \
    98         { \
    99             param[i] = tokens[i]; \
    100             if (i != 0) \
    101             { \
    102                 COUT(5) << ", "; \
    103             } \
    104             COUT(5) << tokens[i]; \
    105         } \
    106         COUT(5) << ") and " << std::max(static_cast<int>(paramCount) - static_cast<int>(tokens.size()), 0) << " default values ("; \
    107         for (unsigned int i = tokens.size(); i < paramCount; i++) \
    108         { \
    109             param[i] = this->defaultValue_[i]; \
    110             if (i != 0) \
    111             { \
    112                 COUT(5) << ", "; \
    113             } \
    114             COUT(5) << this->defaultValue_[i]; \
    115         } \
    116         COUT(5) << ")." << std::endl; \
    117         \
    118         if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \
    119             param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \
    120         \
    121         switch(paramCount) \
    122         { \
    123             case 2: \
    124                 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1]); \
    125                 break; \
    126             case 3: \
    127                 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2]); \
    128                 break; \
    129             case 4: \
    130                 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3]); \
    131                 break; \
    132             case 5: \
    133                 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3], param[4]); \
    134                 break; \
    135         } \
    136     } \
    137     \
    138     return true
    13938
    14039namespace orxonox
     
    284183            bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const
    285184            {
    286                 EXECUTOR_PARSE(object);
     185                static_cast<FunctorMember<T>*>(this->functor_)->setObject(object);
     186                if (Executor::parse(params, delimiter))
     187                    return true;
     188                else
     189                {
     190                    static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL);
     191                    return false;
     192                }
    287193            }
    288194
    289195            bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const
    290196            {
    291                 EXECUTOR_PARSE(object);
     197                static_cast<FunctorMember<T>*>(this->functor_)->setObject(object);
     198                if (Executor::parse(params, delimiter))
     199                    return true;
     200                else
     201                {
     202                    static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL);
     203                    return false;
     204                }
    292205            }
    293206    };
  • code/trunk/src/libraries/core/GUIManager.cc

    r6763 r7163  
    321321    }
    322322
    323     void GUIManager::keyPressed(const KeyEvent& evt)
     323    void GUIManager::buttonPressed(const KeyEvent& evt)
    324324    {
    325325        this->protectedCall(boost::bind(&CEGUI::System::injectKeyDown, _1, evt.getKeyCode()));
     
    327327    }
    328328
    329     void GUIManager::keyReleased(const KeyEvent& evt)
     329    void GUIManager::buttonReleased(const KeyEvent& evt)
    330330    {
    331331        this->protectedCall(boost::bind(&CEGUI::System::injectKeyUp, _1, evt.getKeyCode()));
  • code/trunk/src/libraries/core/GUIManager.h

    r6749 r7163  
    8484        //! Creates a new InputState to be used with a GUI Sheet
    8585        const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
     86        LuaState* getLuaState(void)
     87            { return this->luaState_.get(); }
    8688
    8789        //! Returns the root window for all menu sheets
     
    9597        inline void setPlayer(const std::string& guiname, PlayerInfo* player)
    9698            { this->players_[guiname] = player; }
    97         inline PlayerInfo* getPlayer(const std::string& guiname) const
    98             { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; }
     99        inline orxonox::PlayerInfo* getPlayer(const std::string& guiname) const { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; } // tolua_export
    99100
    100101        // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
     
    105106    private:
    106107        GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
     108        void executeCode(const std::string& str);
    107109
    108         void executeCode(const std::string& str);
    109110        template <typename FunctionType>
    110111        bool protectedCall(FunctionType function);
    111112
    112113        // keyHandler functions
    113         void keyPressed (const KeyEvent& evt);
    114         void keyReleased(const KeyEvent& evt);
     114        void buttonPressed (const KeyEvent& evt);
     115        void buttonReleased(const KeyEvent& evt);
    115116
    116117        // mouseHandler functions
  • code/trunk/src/libraries/core/OrxonoxClass.h

    r6524 r7163  
    108108            bool isParentOf(const OrxonoxClass* object);
    109109            bool isDirectParentOf(const OrxonoxClass* object);
    110            
     110
    111111            virtual void clone(OrxonoxClass*& item) {}
    112112
     
    172172            std::vector<std::pair<unsigned int, void*> > objectPointers_;
    173173    };
    174    
    175     SUPER_FUNCTION(11, OrxonoxClass, clone, true);
    176    
     174
     175    SUPER_FUNCTION(11, OrxonoxClass, clone, false);
     176
    177177}
    178178
  • code/trunk/src/libraries/core/Super.h

    r6524 r7163  
    267267    #define SUPER_changedGametype(classname, functionname, ...) \
    268268        SUPER_NOARGS(classname, functionname)
    269        
     269
    270270    #define SUPER_changedUsed(classname, functionname, ...) \
    271271        SUPER_NOARGS(classname, functionname)
    272        
     272
    273273    #define SUPER_clone(classname, functionname, ...) \
    274274        SUPER_ARGS(classname, functionname, __VA_ARGS__)
    275        
     275
    276276    #define SUPER_changedCarrier(classname, functionname, ...) \
    277277        SUPER_NOARGS(classname, functionname)
    278        
     278
    279279    #define SUPER_changedPickedUp(classname, functionname, ...) \
    280280        SUPER_NOARGS(classname, functionname)
    281        
     281
    282282    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    283283
     
    530530            ()
    531531        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    532        
     532
    533533        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedUsed, false)
    534534            ()
     
    538538            (item)
    539539        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    540        
     540
    541541        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedCarrier, false)
    542542            ()
    543543        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    544        
     544
    545545        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(13, changedPickedUp, false)
    546546            ()
  • code/trunk/src/libraries/core/Template.cc

    r6746 r7163  
    9999    }
    100100
    101     const TiXmlElement& Template::getXMLElement() const
     101    const TiXmlElement& Template::getXMLElement()
    102102    {
    103103        if (this->bIsLink_)
     
    106106            if (temp)
    107107            {
     108                this->bLoadDefaults_ = temp->bLoadDefaults_;
     109
    108110                if (!temp->bIsReturningXMLElement_)
    109111                {
  • code/trunk/src/libraries/core/Template.h

    r6417 r7163  
    5151            inline const std::string& getLink() const
    5252                { return this->link_; }
     53            inline bool isLink() const
     54                { return this->bIsLink_; }
    5355
    5456            inline void setLoadDefaults(bool bLoadDefaults)
     
    5860
    5961            void setXMLElement(const TiXmlElement& xmlelement);
    60             const TiXmlElement& getXMLElement() const;
     62            const TiXmlElement& getXMLElement();
    6163
    6264            void setBaseclass(const std::string& baseclass);
  • code/trunk/src/libraries/core/XMLPort.cc

    r5781 r7163  
    4141        return ((!this->bApplyLoaderMask_) || identifier->isA(ClassIdentifier<Namespace>::getIdentifier()) || Loader::currentMask_s.isIncluded(identifier));
    4242    }
     43
     44    XMLPortObjectContainer& XMLPortObjectContainer::port(BaseObject* object, Element& xmlelement, XMLPort::Mode mode)
     45    {
     46        if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject))
     47        {
     48            try
     49            {
     50                Element* xmlsubelement;
     51                if (!this->sectionname_.empty())
     52                    xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false);
     53                else
     54                    xmlsubelement = &xmlelement;
     55
     56                if (!xmlsubelement)
     57                    return (*this);
     58
     59                for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
     60                {
     61                    Identifier* identifier = Identifier::getIdentifierByString(child->Value());
     62                    if (!identifier)
     63                    {
     64                        if (!this->sectionname_.empty())
     65                        {
     66                            COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl;
     67                        }
     68                        else
     69                        {
     70                            // It's probably just another subsection
     71                        }
     72                        continue;
     73                    }
     74                    if (!identifier->isA(objectIdentifier_))
     75                    {
     76                        COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a '" << objectIdentifier_->getName() << "'." << std::endl;
     77                        continue;
     78                    }
     79                    if (!identifier->isLoadable())
     80                    {
     81                        COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl;
     82                        continue;
     83                    }
     84                    if (!this->identifierIsIncludedInLoaderMask(identifier))
     85                        continue;
     86
     87                    try
     88                    {
     89                        COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
     90
     91                        BaseObject* newObject = identifier->fabricate(object);
     92                        newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
     93
     94                        if (this->bLoadBefore_)
     95                        {
     96                            newObject->XMLPort(*child, XMLPort::LoadObject);
     97                            COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl;
     98                        }
     99                        else
     100                        {
     101                            COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl;
     102                        }
     103
     104                        COUT(5) << object->getLoaderIndentation();
     105
     106                        this->callLoadExecutor(object, newObject);
     107
     108                        if (!this->bLoadBefore_)
     109                            newObject->XMLPort(*child, XMLPort::LoadObject);
     110
     111                        COUT(5) << object->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
     112                    }
     113                    catch (AbortLoadingException& ex)
     114                    {
     115                        COUT(1) << "An error occurred while loading object, abort loading..." << std::endl;
     116                        throw ex;
     117                    }
     118                    catch (...)
     119                    {
     120                        COUT(1) << "An error occurred while loading object:" << std::endl;
     121                        COUT(1) << Exception::handleMessage() << std::endl;
     122                    }
     123                }
     124            }
     125            catch (ticpp::Exception& ex)
     126            {
     127                COUT(1) << std::endl;
     128                COUT(1) << "An error occurred in XMLPort.h while loading a '" << objectIdentifier_->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << object->getName() << ") in " << object->getFilename() << ':' << std::endl;
     129                COUT(1) << ex.what() << std::endl;
     130            }
     131        }
     132        else if (mode == XMLPort::SaveObject)
     133        {
     134        }
     135
     136        return (*this);
     137    }
    43138}
  • code/trunk/src/libraries/core/XMLPort.h

    r6417 r7163  
    197197    @param loadfunction The function to add a new object to the class
    198198    @param loadfunction The function to get all added objects from the class
    199     @param xmlelement The XMLElement (recieved through the XMLPort function)
     199    @param xmlelement The XMLElement (received through the XMLPort function)
    200200    @param mode The mode (load/save) (received through the XMLPort function)
    201201    @param bApplyLoaderMask If this is true, an added sub-object gets loaded only if it's class is included in the Loaders ClassTreeMask (this is usually false)
     
    495495            virtual ~XMLPortObjectContainer() {}
    496496
     497            XMLPortObjectContainer& port(BaseObject* object, Element& xmlelement, XMLPort::Mode mode);
     498
     499            virtual void callLoadExecutor(BaseObject* object, BaseObject* newObject) = 0;
     500
    497501            inline const std::string& getName() const
    498502                { return this->sectionname_; }
     
    508512            bool bLoadBefore_;
    509513            Identifier* identifier_;
     514            Identifier* objectIdentifier_;
    510515    };
    511516
     
    518523                this->sectionname_ = sectionname;
    519524                this->identifier_ = identifier;
     525                assert(identifier->isA(ClassIdentifier<T>::getIdentifier()));
     526                this->objectIdentifier_ = ClassIdentifier<O>::getIdentifier();
    520527                this->loadexecutor_ = loadexecutor;
    521528                this->saveexecutor_ = saveexecutor;
     
    532539            }
    533540
    534             XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode)
    535             {
    536                 if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject))
    537                 {
    538                     try
    539                     {
    540                         Element* xmlsubelement;
    541                         if (!this->sectionname_.empty())
    542                             xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false);
    543                         else
    544                             xmlsubelement = &xmlelement;
    545 
    546                         if (xmlsubelement)
    547                         {
    548                             for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
    549                             {
    550                                 Identifier* identifier = Identifier::getIdentifierByString(child->Value());
    551                                 if (identifier)
    552                                 {
    553                                     if (identifier->isA(ClassIdentifier<O>::getIdentifier()))
    554                                     {
    555                                         if (identifier->isLoadable())
    556                                         {
    557                                             if (this->identifierIsIncludedInLoaderMask(identifier))
    558                                             {
    559                                                 try
    560                                                 {
    561                                                     COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
    562 
    563                                                     BaseObject* newObject = identifier->fabricate(static_cast<BaseObject*>(object));
    564                                                     assert(newObject);
    565                                                     newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
    566 
    567                                                     O* castedObject = orxonox_cast<O*>(newObject);
    568                                                     assert(castedObject);
    569 
    570                                                     if (this->bLoadBefore_)
    571                                                     {
    572                                                         newObject->XMLPort(*child, XMLPort::LoadObject);
    573                                                         COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl;
    574                                                     }
    575                                                     else
    576                                                     {
    577                                                         COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << static_cast<BaseObject*>(object)->getName() << ')' << std::endl;
    578                                                     }
    579 
    580                                                     COUT(5) << object->getLoaderIndentation();
    581                                                     (*this->loadexecutor_)(object, castedObject);
    582 
    583                                                     if (!this->bLoadBefore_)
    584                                                         newObject->XMLPort(*child, XMLPort::LoadObject);
    585 
    586                                                     COUT(5) << object->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
    587                                                 }
    588                                                 catch (AbortLoadingException& ex)
    589                                                 {
    590                                                     COUT(1) << "An error occurred while loading object, abort loading..." << std::endl;
    591                                                     throw ex;
    592                                                 }
    593                                                 catch (...)
    594                                                 {
    595                                                     COUT(1) << "An error occurred while loading object:" << std::endl;
    596                                                     COUT(1) << Exception::handleMessage() << std::endl;
    597                                                 }
    598                                             }
    599                                         }
    600                                         else
    601                                         {
    602                                             COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl;
    603                                         }
    604                                     }
    605                                     else
    606                                     {
    607                                         COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a '" << ClassIdentifier<O>::getIdentifier()->getName() << "'." << std::endl;
    608                                     }
    609                                 }
    610                                 else
    611                                 {
    612                                     if (!this->sectionname_.empty())
    613                                     {
    614                                         COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl;
    615                                     }
    616                                     else
    617                                     {
    618                                         // It's probably just another subsection
    619                                     }
    620                                 }
    621                             }
    622                         }
    623                     }
    624                     catch (ticpp::Exception& ex)
    625                     {
    626                         COUT(1) << std::endl;
    627                         COUT(1) << "An error occurred in XMLPort.h while loading a '" << ClassIdentifier<O>::getIdentifier()->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << object->getName() << ") in " << object->getFilename() << ':' << std::endl;
    628                         COUT(1) << ex.what() << std::endl;
    629                     }
    630                 }
    631                 else if (mode == XMLPort::SaveObject)
    632                 {
    633                 }
    634 
    635                 return (*this);
     541            void callLoadExecutor(BaseObject* object, BaseObject* newObject)
     542            {
     543                T* castedObject = orxonox_cast<T*>(object);
     544                assert(castedObject);
     545                O* castedNewObject = orxonox_cast<O*>(newObject);
     546                assert(castedNewObject);
     547
     548                (*this->loadexecutor_)(castedObject, castedNewObject);
    636549            }
    637550
  • code/trunk/src/libraries/network/CMakeLists.txt

    r5781 r7163  
    2929  GamestateClient.cc
    3030  GamestateHandler.cc
     31  LANDiscoverable.cc
     32  LANDiscovery.cc
    3133  NetworkFunction.cc
    3234  Host.cc
     
    4850  GamestateManager.h
    4951  Host.h
     52  LANDiscoverable.h
     53  LANDiscovery.h
    5054  NetworkFunction.h
    5155  NetworkPrecompiledHeaders.h
     
    6064
    6165ORXONOX_ADD_LIBRARY(network
    62   DEFINE_SYMBOL
    63     "NETWORK_SHARED_BUILD"
     66  TOLUA_FILES
     67    Client.h
     68    LANDiscovery.h
    6469  PCH_FILE
    6570    NetworkPrecompiledHeaders.h
  • code/trunk/src/libraries/network/ChatListener.cc

    r5781 r7163  
    3636        RegisterRootObject(ChatListener);
    3737    }
     38
     39    //void ChatListener::incomingChat( const std::string& message,
     40      //unsigned int senderID )
     41    //{
     42      //COUT(0) << "Chat: \"" << message << "\"\n";
     43
     44
     45    //}
     46
     47
    3848}
    3949
  • code/trunk/src/libraries/network/ChatListener.h

    r5781 r7163  
    3838    {
    3939        public:
     40            /* constructor, destructor */
    4041            ChatListener();
    4142            virtual ~ChatListener() {}
    4243
     44            /* What to do with incoming chat */
    4345            virtual void incomingChat(const std::string& message, unsigned int senderID) = 0;
    4446    };
  • code/trunk/src/libraries/network/Client.cc

    r6417 r7163  
    5050#include "FunctionCallManager.h"
    5151#include "core/CoreIncludes.h"
     52#include "core/CommandLineParser.h"
    5253#include "core/Game.h"
     54#include "core/ScopedSingletonManager.h"
    5355
    5456namespace orxonox
    5557{
    5658
     59  ManageScopedSingleton( Client, ScopeID::Root, true );
    5760
    5861  /**
     
    6164  */
    6265  Client::Client():
     66      gamestate(0),
    6367      isSynched_(false),
    6468      gameStateFailure_(false),
    6569      timeSinceLastUpdate_(0)
    6670  {
    67   }
    68 
    69   /**
    70   * Constructor for the Client class
    71   * @param address the server address
    72   * @param port port of the application on the server
    73   */
    74   Client::Client(const std::string& address, int port):
    75       isSynched_(false),
    76       gameStateFailure_(false),
    77       timeSinceLastUpdate_(0)
    78   {
    79       setPort( port );
    80       setServerAddress( address );
    81   }
    82 
    83   Client::~Client(){
     71    this->setDestination( CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
     72  }
     73
     74  Client::~Client()
     75  {
    8476    if ( ClientConnection::isConnected() )
    8577      closeConnection();
     
    9082  * @return true/false
    9183  */
    92   bool Client::establishConnection(){
     84  bool Client::establishConnection()
     85  {
    9386    Synchronisable::setClient(true);
    94     return ClientConnection::establishConnection();
     87    this->gamestate = new GamestateClient();
     88    if( ClientConnection::establishConnection() )
     89    {
     90      Host::setActive(true);
     91      return true;
     92    }
     93    else
     94      return false;
    9595  }
    9696
     
    9999  * @return true/false
    100100  */
    101   bool Client::closeConnection(){
     101  bool Client::closeConnection()
     102  {
     103    assert(this->gamestate);
     104    delete this->gamestate;
     105    this->gamestate = 0;
     106    Host::setActive(false);
    102107    return ClientConnection::closeConnection();
    103108  }
    104 
    105   bool Client::queuePacket(ENetPacket *packet, int clientID){
     109 
     110  void Client::setDestination(const std::string& serverAddress, unsigned int port)
     111  {
     112    ClientConnection::setServerAddress(serverAddress);
     113    ClientConnection::setPort(port);
     114  }
     115
     116  bool Client::queuePacket(ENetPacket *packet, int clientID)
     117  {
    106118    bool b = ClientConnection::addPacket(packet);
    107119    assert(b);
     
    109121  }
    110122
    111   bool Client::processChat(const std::string& message, unsigned int playerID){
     123  bool Client::processChat(const std::string& message, unsigned int playerID)
     124  {
    112125//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
    113126    return true;
    114127  }
    115128
    116   void Client::printRTT(){
     129  void Client::printRTT()
     130  {
    117131    COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
    118132  }
     
    123137   * @return result(true/false)
    124138   */
    125   bool Client::chat(const std::string& message){
     139  bool Client::chat(const std::string& message)
     140  {
    126141    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
    127142    return m->send();
     
    133148   * @param time
    134149   */
    135   void Client::update(const Clock& time){
     150  void Client::update(const Clock& time)
     151  {
    136152    //this steers our network frequency
    137153    timeSinceLastUpdate_+=time.getDeltaTime();
     
    143159      {
    144160        COUT(4) << "popping partial gamestate: " << std::endl;
    145         packet::Gamestate *gs = gamestate.getGamestate();
     161        packet::Gamestate *gs = gamestate->getGamestate();
    146162        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
    147163        if(gs){
     
    157173
    158174    Connection::processQueue();
    159     if(gamestate.processGamestates())
     175    if(gamestate->processGamestates())
    160176    {
    161177      if(!isSynched_)
    162178        isSynched_=true;
    163179    }
    164     gamestate.cleanup();
     180    gamestate->cleanup();
    165181    Connection::sendPackets();
    166182
     
    184200  }
    185201
     202
     203
    186204}
  • code/trunk/src/libraries/network/Client.h

    r5961 r7163  
    4747
    4848#include "util/UtilPrereqs.h"
     49#include "util/Singleton.h"
    4950#include "ClientConnection.h"
    5051#include "GamestateClient.h"
    5152#include "Host.h"
     53#include "LANDiscovery.h"
     54#include "packet/ServerInformation.h"
    5255
     56// tolua_begin
    5357namespace orxonox
    5458{
     59// tolua_end
    5560  /**
    5661  Client *client;
     
    6065  *
    6166  */
    62   class _NetworkExport Client : public Host, public ClientConnection{
     67  class _NetworkExport Client // tolua_export
     68    : public Host, protected ClientConnection, public Singleton<Client>
     69  { // tolua_export
     70  friend class Singleton<Client>;
    6371  public:
    6472    Client();
    65     Client(const std::string& address, int port);
    6673    ~Client();
     74   
     75    static Client* getInstance(){ return singletonPtr_s; } // tolua_export
    6776
    6877    bool establishConnection();
     78    void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export
    6979    bool closeConnection();
    7080    bool queuePacket(ENetPacket *packet, int clientID);
     
    8191    virtual bool isServer_(){return false;}
    8292
    83     GamestateClient gamestate;
     93    static Client* singletonPtr_s;
     94    GamestateClient* gamestate;
    8495    bool isSynched_;
    8596
    8697    bool gameStateFailure_;
    8798    float timeSinceLastUpdate_;
    88   };
     99  }; // tolua_export
    89100
    90101
    91 }
     102} // tolua_export
    92103
    93104#endif /* _Client_H__ */
  • code/trunk/src/libraries/network/Connection.cc

    r6417 r7163  
    3636namespace orxonox
    3737{
    38   Connection *Connection::instance_=0;
     38//   Connection *Connection::instance_=0;
    3939
    4040  Connection::Connection():
    4141    host_(0)
    4242  {
    43     assert(instance_==0);
    44     Connection::instance_=this;
     43//     assert(instance_==0);
     44//     Connection::instance_=this;
    4545    enet_initialize();
    4646    atexit(enet_deinitialize);
     
    4848
    4949  Connection::~Connection(){
    50     Connection::instance_=0;
     50//     Connection::instance_=0;
    5151  }
    5252
     
    6767
    6868  bool Connection::sendPackets() {
    69     if ( !Connection::instance_ || this->host_==NULL )
     69    if ( /*!Connection::instance_ || */this->host_==NULL )
    7070      return false;
    7171    enet_host_flush(this->host_);
  • code/trunk/src/libraries/network/Connection.h

    r6417 r7163  
    6161  protected:
    6262    Connection();
    63     static Connection* getInstance(){ return Connection::instance_; }
     63//     static Connection* getInstance(){ return Connection::instance_; }
    6464
    6565    int service(ENetEvent* event);
     
    7575    ENetAddress *bindAddress_;
    7676
    77     static Connection *instance_;
     77//     static Connection *instance_;
    7878
    7979  };
  • code/trunk/src/libraries/network/GamestateClient.cc

    r6417 r7163  
    161161      assert(b);
    162162    }
    163     if(gs->isDiffed()){
    164       packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
    165       if(!base){
    166         COUT(3) << "could not find base gamestate id: " << gs->getBaseID() << endl;
    167         delete gs;
    168         return 0;
    169       }
    170 //       assert(base); //TODO: fix this
    171       packet::Gamestate *undiffed = gs->undiff(base);
    172       delete gs;
    173       gs=undiffed;
    174       COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
     163    if(gs->isDiffed())
     164    {
     165      assert(0);
     166//       packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
     167//       if(!base)
     168//       {
     169//         COUT(0) << "could not find base gamestate id: " << gs->getBaseID() << endl;
     170//         assert(0);
     171//         delete gs;
     172//         return 0;
     173//       }
     174//       packet::Gamestate *undiffed = gs->undiff(base);
     175//       delete gs;
     176//       gs=undiffed;
     177//       COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
    175178    }
    176179    if(gs->spreadData(0x2))
     
    178181    else
    179182    {
    180       COUT(3) << "could not spread gamestate" << endl;
     183      COUT(0) << "could not spread gamestate" << endl;
     184      assert(0);
    181185      return NULL;
    182186    }
  • code/trunk/src/libraries/network/GamestateManager.cc

    r6417 r7163  
    4343#include <cassert>
    4444#include <queue>
     45#include "util/Clock.h"
    4546// #include <boost/thread/mutex.hpp>
    4647
     
    158159
    159160      clientGamestates.push(0);
    160       finishGamestate( cid, &clientGamestates.back(), client, reference );
     161      finishGamestate( cid, clientGamestates.back(), client, reference );
    161162      //FunctorMember<GamestateManager>* functor =
    162163//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) );
     
    180181
    181182
    182   void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
     183  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
    183184    //why are we searching the same client's gamestate id as we searched in
    184185    //Server::sendGameState?
     
    186187    //chose wheather the next gamestate is the first or not
    187188
    188     packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
    189 //     packet::Gamestate *gs = new packet::Gamestate(*gamestate);
     189//     packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
     190//       packet::Gamestate* gs = new packet::Gamestate(*gamestate);
     191//     packet::Gamestate* gs = gamestate;
     192    packet::Gamestate *gs = new packet::Gamestate(*gamestate); //TODO: is this neccessary ?
    190193//     packet::Gamestate *gs = new packet::Gamestate();
    191194//     gs->collectData( id_, 0x1 );
     
    193196    gamestateMap_[clientID][gamestate->getID()]=gs;
    194197//     this->threadMutex_->unlock();
     198      Clock clock;
     199      clock.capture();
    195200
    196201    if(base)
    197202    {
    198 
    199 //       COUT(3) << "diffing" << std::endl;
    200 //       packet::Gamestate* gs1  = gs;
    201       packet::Gamestate *diffed = gs->diff(base);
    202       //packet::Gamestate *gs2 = diffed->undiff(gs);
    203 //       assert(*gs == *gs2);
    204       gs = diffed;
    205 //       packet::Gamestate* gs2 = gs->undiff(client);
    206 //       gs = new packet::Gamestate(*gs);
    207 //       assert(*gs1==*gs2);
    208     }
    209     else{
     203      packet::Gamestate *diffed1 = gs->diffVariables(base);
     204      if( diffed1->getDataSize() == 0 )
     205      {
     206        delete diffed1;
     207        destgamestate = 0;
     208        return;
     209      }
     210      gs = diffed1;
     211    }
     212    else
     213    {
    210214      gs = new packet::Gamestate(*gs);
    211215    }
     
    214218    bool b = gs->compressData();
    215219    assert(b);
    216 //     COUT(4) << "sending gamestate with id " << gs->getID();
     220      clock.capture();
     221      COUT(0) << "diff time: " << clock.getDeltaTime() << endl;
     222//     COUT(5) << "sending gamestate with id " << gs->getID();
    217223//     if(gamestate->isDiffed())
    218 //     COUT(4) << " and baseid " << gs->getBaseID() << endl;
     224//       COUT(5) << " and baseid " << gs->getBaseID() << endl;
    219225//     else
    220 //     COUT(4) << endl;
     226//       COUT(5) << endl;
    221227    gs->setClientID(clientID);
    222     *destgamestate = gs;
     228    destgamestate = gs;
    223229  }
    224230
  • code/trunk/src/libraries/network/GamestateManager.h

    r5781 r7163  
    7676    void sendGamestates();
    7777//     packet::Gamestate *popGameState(unsigned int clientID);
    78     void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
     78    void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
    7979
    8080    bool getSnapshot();
  • code/trunk/src/libraries/network/Host.cc

    r5961 r7163  
    3838namespace orxonox {
    3939
    40 SetConsoleCommandShortcut(Host, Chat);
     40  SetConsoleCommandShortcut(Host, Chat);
    4141
    42 Host *Host::instance_=0;
     42  // Host*               Host::instance_=0;
     43  uint32_t            Host::clientID_s=0;
     44  uint32_t            Host::shipID_s=-1;
     45  std::vector<Host*>  Host::instances_s;
    4346
    44 /**
    45  * @brief Constructor: assures that only one reference will be created and sets the pointer
    46  */
    47 Host::Host()
    48 {
    49   clientID_=0;
    50   assert(instance_==0);
    51   instance_=this;
    52   this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
    53   CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
    54 }
     47  /**
     48  * @brief Constructor: assures that only one reference will be created and sets the pointer
     49  */
     50  Host::Host()
     51  {
     52  //   assert(instance_==0);
     53    instances_s.push_back(this);
     54    this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" );
     55    CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );
     56    this->bIsActive_ = false;
     57  }
    5558
    5659
    57 /**
    58  * @brief Destructor: resets the instance pointer to 0
    59  */
    60 Host::~Host()
    61 {
    62   instance_=0;
    63   if( this->printRTTCC_ )
    64     delete this->printRTTCC_;
    65 }
     60  /**
     61  * @brief Destructor: resets the instance pointer to 0
     62  */
     63  Host::~Host()
     64  {
     65    assert( std::find( instances_s.begin(), instances_s.end(), this )!=instances_s.end() );
     66    instances_s.erase(std::find( instances_s.begin(), instances_s.end(), this ));
     67    if( this->printRTTCC_ )
     68      delete this->printRTTCC_;
     69  }
    6670
    67 /**
    68  * This function is used to add an enetpacket to be sent to another peer
    69  * @param packet Packet to be added
    70  * @param clientID ID of the client the packet should be sent to
    71  * @return success?
    72  */
    73 bool Host::addPacket(ENetPacket *packet, int clientID){
    74   if(instance_)
    75     return instance_->queuePacket(packet, clientID);
    76   else
    77     return false;
    78 }
     71  /**
     72  * This function is used to add an enetpacket to be sent to another peer
     73  * @param packet Packet to be added
     74  * @param clientID ID of the client the packet should be sent to
     75  * @return success?
     76  */
     77  bool Host::addPacket(ENetPacket *packet, int clientID)
     78  {
     79    bool result = true;
     80    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     81    {
     82      if( (*it)->isActive() )
     83      {
     84        if( !(*it)->queuePacket(packet, clientID) )
     85          result = false;
     86      }
     87    }
     88    return result;
     89  }
    7990
    80 /**
    81  * This function returns the ID of the player
    82  * @return playerID
    83  */
    84 unsigned int Host::getPlayerID(){
    85   if(!instance_)
    86     return 0;
    87   return instance_->clientID_;
    88 }
     91  bool Host::Chat(const std::string& message)
     92  {
     93    if(instances_s.size()==0)
     94    {
     95      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
     96        it->incomingChat(message, 0);
     97      return true;
     98    }
     99    else
     100    {
     101      bool result = true;
     102      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     103      {
     104        if( (*it)->isActive() )
     105        {
     106          if( !(*it)->chat(message) )
     107            result = false;
     108        }
     109      }
     110      return result;
     111    }
     112  }
    89113
    90 bool Host::Chat(const std::string& message){
    91   if(!instance_)
     114  bool Host::Broadcast(const std::string& message)
     115  {
     116    if(instances_s.size()==0)
     117    {
     118      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
     119        it->incomingChat(message, CLIENTID_UNKNOWN);
     120      return true;
     121    }
     122    else
     123    {
     124      bool result = true;
     125      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     126      {
     127        if( (*it)->isActive() )
     128        {
     129          if( !(*it)->broadcast(message) )
     130            result = false;
     131        }
     132      }
     133      return result;
     134    }
     135  }
     136
     137  bool Host::incomingChat(const std::string& message, unsigned int playerID)
    92138  {
    93139    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    94       it->incomingChat(message, 0);
    95     return true;
     140      it->incomingChat(message, playerID);
     141   
     142    bool result = true;
     143    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     144    {
     145      if( (*it)->isActive() )
     146      {
     147        if( !(*it)->processChat(message, playerID) )
     148          result = false;
     149      }
     150    }
     151    return result;
    96152  }
    97   return instance_->chat(message);
    98 }
    99153
    100 bool Host::Broadcast(const std::string& message){
    101   if(!instance_)
     154  bool Host::isServer()
    102155  {
    103     for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    104       it->incomingChat(message, CLIENTID_UNKNOWN);
    105     return true;
     156    for (std::vector<Host*>::iterator it=instances_s.begin(); it!=instances_s.end(); ++it )
     157    {
     158      if( (*it)->isServer_() )
     159        return true;
     160    }
     161    return false;
    106162  }
    107   else
    108     return instance_->broadcast(message);
    109 }
    110 
    111 bool Host::incomingChat(const std::string& message, unsigned int playerID){
    112   for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    113     it->incomingChat(message, playerID);
    114 
    115   return instance_->processChat(message, playerID);
    116 }
    117163
    118164}//namespace orxonox
  • code/trunk/src/libraries/network/Host.h

    r6073 r7163  
    3333#include "core/CorePrereqs.h"
    3434
     35#include <vector>
     36
    3537namespace orxonox {
    3638
    3739  const unsigned int CLIENTID_SERVER = 0;
    38   const unsigned int NETWORK_FREQUENCY = 30;
     40  const unsigned int NETWORK_FREQUENCY = 25;
    3941  const float NETWORK_PERIOD = 1.0f/NETWORK_FREQUENCY;
    4042
     
    4951class _NetworkExport Host{
    5052  private:
    51     //TODO add theese functions or adequate
     53    //TODO add these functions or adequate
    5254    //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
    5355    //virtual bool sendChat(packet::Chat *chat)=0;
     
    6365    Host();
    6466    virtual ~Host();
    65     static Host *instance_;
    66     unsigned int clientID_;
    67     unsigned int shipID_;
     67    void setActive( bool bActive ){ bIsActive_ = bActive; }
     68//     static Host *instance_;
    6869
    6970  public:
    70     static bool running(){return instance_!=0;}
     71//     static Host* getInstance(){ return instance_; }
     72    static bool running(){ return instances_s.size(); }
    7173    static bool addPacket(ENetPacket *packet, int clientID=0);
    7274    //static bool chat(std::string& message);
    7375//     static bool receiveChat(packet::Chat *message, unsigned int clientID);
    74     static unsigned int getPlayerID();
    75     static unsigned int getShipID(){return instance_->shipID_;}
    76     static void setClientID(unsigned int id){ instance_->clientID_ = id; }
    77     static void setShipID(unsigned int id){ instance_->shipID_ = id; }
    78     static bool isServer(){ return instance_->isServer_(); }
     76    static unsigned int getPlayerID(){ return clientID_s; }
     77    static unsigned int getShipID(){return shipID_s;}
     78    static void setClientID(unsigned int id){ clientID_s = id; }
     79    static void setShipID(unsigned int id){ shipID_s = id; }
     80    static bool isServer();
    7981    static bool Chat(const std::string& message);
    8082    static bool Broadcast(const std::string& message);
    8183    static bool incomingChat(const std::string& message, unsigned int playerID);
    8284    virtual void printRTT()=0;
     85    bool isActive(){ return bIsActive_; }
    8386  private:
    8487    ConsoleCommand* printRTTCC_;
     88    static uint32_t clientID_s;
     89    static uint32_t shipID_s;
     90    static std::vector<Host*> instances_s;
     91    bool bIsActive_;
    8592};
    8693
  • code/trunk/src/libraries/network/NetworkPrereqs.h

    r6417 r7163  
    6464namespace orxonox
    6565{
    66   static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
    67   static const unsigned int CLIENTID_UNKNOWN    = static_cast<unsigned int>(-2);
     66  static const unsigned int GAMESTATEID_INITIAL     = static_cast<unsigned int>(-1);
     67  static const unsigned int CLIENTID_UNKNOWN        = static_cast<unsigned int>(-2);
     68  extern const char* LAN_DISCOVERY_MESSAGE;
     69  extern const char* LAN_DISCOVERY_ACK;
     70  static const unsigned int LAN_DISCOVERY_PORT      = 55557;
    6871}
    6972
  • code/trunk/src/libraries/network/Server.cc

    r6417 r7163  
    6969  *
    7070  */
    71   Server::Server() {
     71  Server::Server()
     72  {
    7273    this->timeSinceLastUpdate_=0;
    7374  }
    7475
    75   Server::Server(int port){
     76  Server::Server(int port)
     77  {
    7678    this->setPort( port );
    7779    this->timeSinceLastUpdate_=0;
     
    8385  * @param bindAddress Address to listen on
    8486  */
    85   Server::Server(int port, const std::string& bindAddress) {
     87  Server::Server(int port, const std::string& bindAddress)
     88  {
    8689    this->setPort( port );
    8790    this->setBindAddress( bindAddress );
     
    9295  * @brief Destructor
    9396  */
    94   Server::~Server(){
     97  Server::~Server()
     98  {
    9599  }
    96100
     
    98102  * This function opens the server by creating the listener thread
    99103  */
    100   void Server::open() {
     104  void Server::open()
     105  {
     106    Host::setActive(true);
    101107    COUT(4) << "opening server" << endl;
    102108    this->openListener();
     109    LANDiscoverable::setActivity(true);
    103110    return;
    104111  }
     
    107114  * This function closes the server
    108115  */
    109   void Server::close() {
     116  void Server::close()
     117  {
     118    Host::setActive(false);
    110119    COUT(4) << "closing server" << endl;
    111120    this->disconnectClients();
    112121    this->closeListener();
     122    LANDiscoverable::setActivity(false);
    113123    return;
    114124  }
    115125
    116   bool Server::processChat(const std::string& message, unsigned int playerID){
     126  bool Server::processChat(const std::string& message, unsigned int playerID)
     127  {
    117128    ClientInformation *temp = ClientInformation::getBegin();
    118129    packet::Chat *chat;
     
    134145  * @param time time since last tick
    135146  */
    136   void Server::update(const Clock& time) {
     147  void Server::update(const Clock& time)
     148  {
    137149    // receive incoming packets
    138150    Connection::processQueue();
     151    // receive and process incoming discovery packets
     152    LANDiscoverable::update();
    139153
    140154    if ( ClientInformation::hasClients() )
     
    157171  }
    158172
    159   bool Server::queuePacket(ENetPacket *packet, int clientID){
     173  bool Server::queuePacket(ENetPacket *packet, int clientID)
     174  {
    160175    return ServerConnection::addPacket(packet, clientID);
    161176  }
     
    164179   * @brief: returns ping time to client in milliseconds
    165180   */
    166   unsigned int Server::getRTT(unsigned int clientID){
     181  unsigned int Server::getRTT(unsigned int clientID)
     182  {
    167183    assert(ClientInformation::findClient(clientID));
    168184    return ClientInformation::findClient(clientID)->getRTT();
     
    178194   * @brief: return packet loss ratio to client (scales from 0 to 1)
    179195   */
    180   double Server::getPacketLoss(unsigned int clientID){
     196  double Server::getPacketLoss(unsigned int clientID)
     197  {
    181198    assert(ClientInformation::findClient(clientID));
    182199    return ClientInformation::findClient(clientID)->getPacketLoss();
     
    186203  * takes a new snapshot of the gamestate and sends it to the clients
    187204  */
    188   void Server::updateGamestate() {
     205  void Server::updateGamestate()
     206  {
    189207    if( ClientInformation::getBegin()==NULL )
    190208      //no client connected
     
    208226  * sends the gamestate
    209227  */
    210   bool Server::sendGameState() {
     228  bool Server::sendGameState()
     229  {
    211230//     COUT(5) << "Server: starting function sendGameState" << std::endl;
    212231//     ClientInformation *temp = ClientInformation::getBegin();
     
    244263  }
    245264
    246   bool Server::sendObjectDeletes(){
     265  bool Server::sendObjectDeletes()
     266  {
    247267    ClientInformation *temp = ClientInformation::getBegin();
    248268    if( temp == NULL )
     
    257277//     COUT(3) << "sending DeleteObjects" << std::endl;
    258278    while(temp != NULL){
    259       if( !(temp->getSynched()) ){
     279      if( !(temp->getSynched()) )
     280      {
    260281        COUT(5) << "Server: not sending gamestate" << std::endl;
    261282        temp=temp->next();
     
    276297
    277298
    278   void Server::addPeer(ENetEvent *event){
     299  void Server::addPeer(ENetEvent *event)
     300  {
    279301    static unsigned int newid=1;
    280302
    281303    COUT(2) << "Server: adding client" << std::endl;
    282304    ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
    283     if(!temp){
     305    if(!temp)
     306    {
    284307      COUT(2) << "Server: could not add client" << std::endl;
    285308    }
     
    310333  }
    311334
    312   bool Server::createClient(int clientID){
     335  bool Server::createClient(int clientID)
     336  {
    313337    ClientInformation *temp = ClientInformation::findClient(clientID);
    314     if(!temp){
     338    if(!temp)
     339    {
    315340      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
    316341      return false;
     
    345370  }
    346371
    347   void Server::disconnectClient( ClientInformation *client ){
     372  void Server::disconnectClient( ClientInformation *client )
     373  {
    348374    ServerConnection::disconnectClient( client );
    349375    GamestateManager::removeClient(client);
     
    352378  }
    353379
    354   bool Server::chat(const std::string& message){
     380  bool Server::chat(const std::string& message)
     381  {
    355382      return this->sendChat(message, Host::getPlayerID());
    356383  }
    357384
    358   bool Server::broadcast(const std::string& message){
     385  bool Server::broadcast(const std::string& message)
     386  {
    359387      return this->sendChat(message, CLIENTID_UNKNOWN);
    360388  }
    361389
    362   bool Server::sendChat(const std::string& message, unsigned int clientID){
     390  bool Server::sendChat(const std::string& message, unsigned int clientID)
     391  {
    363392    ClientInformation *temp = ClientInformation::getBegin();
    364393    packet::Chat *chat;
    365     while(temp){
     394    while(temp)
     395    {
    366396      chat = new packet::Chat(message, clientID);
    367397      chat->setClientID(temp->getID());
     
    377407  }
    378408
    379   void Server::syncClassid(unsigned int clientID) {
     409  void Server::syncClassid(unsigned int clientID)
     410  {
    380411    int failures=0;
    381412    packet::ClassID *classid = new packet::ClassID();
  • code/trunk/src/libraries/network/Server.h

    r6417 r7163  
    3737#include "GamestateManager.h"
    3838#include "ServerConnection.h"
     39#include "LANDiscoverable.h"
    3940
    4041namespace orxonox
     
    4546  * It implements all functions necessary for a Server
    4647  */
    47   class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{
     48  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{
    4849  public:
    4950    Server();
  • code/trunk/src/libraries/network/ServerConnection.cc

    r6417 r7163  
    9494
    9595  bool ServerConnection::addPacketAll(ENetPacket *packet) {
    96     if ( !Connection::getInstance() )
    97       return false;
    98     enet_host_broadcast( Connection::getInstance()->getHost(), 0, packet);
     96//     if ( !Connection::getInstance() )
     97//       return false;
     98    enet_host_broadcast( Connection::getHost(), 0, packet);
    9999    return true;
    100100  }
  • code/trunk/src/libraries/network/ServerConnection.h

    r6417 r7163  
    5656    bool openListener();
    5757    bool closeListener();
    58     static bool addPacket(ENetPacket *packet, unsigned int ID);
    59     static bool addPacketAll(ENetPacket *packet);
     58    bool addPacket(ENetPacket *packet, unsigned int ID);
     59    bool addPacketAll(ENetPacket *packet);
    6060    virtual void disconnectClient(ClientInformation *client);
    6161    void disconnectClient(int clientID);
  • code/trunk/src/libraries/network/packet/CMakeLists.txt

    r5929 r7163  
    1111  Welcome.cc
    1212COMPILATION_END
     13  ServerInformation.cc
    1314)
    1415
     
    2324  Gamestate.h
    2425  Packet.h
     26  ServerInformation.h
    2527  Welcome.h
    2628)
  • code/trunk/src/libraries/network/packet/Chat.cc

    r6417 r7163  
    3737
    3838#define   PACKET_FLAGS_CHAT PacketFlag::Reliable
     39
     40/* Some lengths */
    3941#define   _PACKETID         0
    4042const int _PLAYERID     =   _PACKETID + sizeof(Type::Value);
     
    4547 : Packet()
    4648{
     49  /* Add chat flag to packet flags */
    4750  flags_ = flags_ | PACKET_FLAGS_CHAT;
     51
     52  /* set message length to length of input string + 1 */
    4853  messageLength_ = message.length()+1;
     54
     55  /* allocate memory for the data */
    4956  data_=new unsigned char[ getSize() ];
     57
    5058  *(Type::Value *)(data_ + _PACKETID ) = Type::Chat;
    5159  *(unsigned int *)(data_ + _PLAYERID ) = playerID;
    5260  *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
     61
     62  /* cast the hell out of the message string, and copy it into the
     63   * data buffer.
     64   */
    5365  memcpy( data_+_MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())), messageLength_ );
    5466}
  • code/trunk/src/libraries/network/packet/Chat.h

    r6073 r7163  
    4141{
    4242public:
     43  /* constructors */
    4344  Chat( const std::string& message, unsigned int playerID );
    4445  Chat( uint8_t* data, unsigned int clientID );
     46
     47  /* destructor */
    4548  ~Chat();
    4649
     50  /* get size of packet */
    4751  inline unsigned int getSize() const;
     52
     53  /* process chat message packet and remove it afterwards */
    4854  bool process();
    4955
     56  /* Get the length of the message (not the full size of the packet) */
    5057  unsigned int getMessageLength(){ return messageLength_; };
     58
     59  /* return message content */
    5160  unsigned char *getMessage();
     61
    5262private:
     63
     64  /* Message length */
    5365  uint32_t messageLength_;
     66
     67  /* Client ID (an integral value for identification) */
    5468  unsigned int clientID_;
    5569};
  • code/trunk/src/libraries/network/packet/ClassID.cc

    r6417 r7163  
    6565    tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) );
    6666    ++nrOfClasses;
    67     packetSize += (classname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t);
     67    packetSize += (classname.size()+1)+sizeof(network_id)+sizeof(uint32_t);
    6868  }
    6969
     
    8080  // now save all classids and classnames
    8181  std::pair<uint32_t, std::string> tempPair;
     82  uint32_t tempsize = 2*sizeof(uint32_t); // packetid and nrOfClasses
    8283  while( !tempQueue.empty() ){
    8384    tempPair = tempQueue.front();
     
    8788    memcpy(temp+2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);
    8889    temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
     90    tempsize+=2*sizeof(uint32_t)+tempPair.second.size()+1;
    8991  }
     92  assert(tempsize==packetSize);
    9093
    9194  COUT(5) << "classid packetSize is " << packetSize << endl;
     
    111114  for(unsigned int i=0; i<nrOfClasses; i++){
    112115    totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
     116    temp += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
    113117  }
    114118  return totalsize;
     
    141145    COUT(3) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
    142146    if(id==NULL){
    143       COUT(0) << "Recieved a bad classname" << endl;
     147      COUT(0) << "Received a bad classname" << endl;
    144148      abort();
    145149    }
  • code/trunk/src/libraries/network/packet/Gamestate.cc

    r6417 r7163  
    4545#define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
    4646
    47 
    48 Gamestate::Gamestate()
     47inline bool memzero( uint8_t* data, uint32_t datalength)
     48{
     49  uint64_t* d = (uint64_t*)data;
     50
     51  for( unsigned int i=0; i<datalength/8; i++ )
     52  {
     53    if( *(d+i) != 0 )
     54      return false;
     55  }
     56  // now process the rest (when datalength isn't a multiple of 4)
     57  for( unsigned int j = 8*(datalength/8); j<datalength; j++ )
     58  {
     59    if( *(data+j) != 0 )
     60      return false;
     61  }
     62  return true;
     63}
     64
     65
     66Gamestate::Gamestate():
     67  header_(0)
    4968{
    5069  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
    51   header_ = 0;
    52 }
     70}
     71
    5372
    5473Gamestate::Gamestate(uint8_t *data, unsigned int clientID):
    55     Packet(data, clientID)
     74  Packet(data, clientID)
    5675{
    5776  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
     
    5978}
    6079
     80
    6181Gamestate::Gamestate(uint8_t *data)
    6282{
    6383  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
    64   data_=data;
     84  data_ = data;
    6585  header_ = new GamestateHeader(data_);
    6686}
    6787
     88
    6889Gamestate::Gamestate(const Gamestate& g) :
    69     Packet( *(Packet*)&g )
     90    Packet( *(Packet*)&g ), nrOfVariables_(0)
    7091{
    7192  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
    7293  header_ = new GamestateHeader(data_);
     94  sizes_ = g.sizes_;
    7395}
    7496
     
    79101    delete header_;
    80102}
     103
    81104
    82105bool Gamestate::collectData(int id, uint8_t mode)
     
    91114    return false;
    92115  data_ = new uint8_t[size + GamestateHeader::getSize()];
    93   if(!data_){
     116  if(!data_)
     117  {
    94118    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
    95119    return false;
     
    101125
    102126  //start collect data synchronisable by synchronisable
    103   uint8_t *mem=data_;
     127  uint8_t *mem = data_; // in this stream store all data of the variables and the headers of the synchronisable
    104128  mem += GamestateHeader::getSize();
    105129  ObjectList<Synchronisable>::iterator it;
    106   for(it = ObjectList<Synchronisable>::begin(); it; ++it){
     130  for(it = ObjectList<Synchronisable>::begin(); it; ++it)
     131  {
    107132
    108133//     tempsize=it->getSize(id, mode);
    109134
    110     tempsize = it->getData(mem, id, mode);
     135    tempsize = it->getData(mem, this->sizes_, id, mode);
    111136    if ( tempsize != 0 )
    112137      dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
    113138
    114139#ifndef NDEBUG
    115     if(currentsize+tempsize > size){
     140    if(currentsize+tempsize > size)
     141    {
    116142      assert(0); // if we don't use multithreading this part shouldn't be neccessary
    117143      // start allocate additional memory
     
    148174}
    149175
     176
    150177bool Gamestate::spreadData(uint8_t mode)
    151178{
     
    153180  assert(data_);
    154181  assert(!header_->isCompressed());
    155   assert(!header_->isDiffed());
    156182  uint8_t *mem=data_+GamestateHeader::getSize();
    157183  Synchronisable *s;
    158184
    159185  // update the data of the objects we received
    160   while(mem < data_+GamestateHeader::getSize()+header_->getDataSize()){
     186  while(mem < data_+GamestateHeader::getSize()+header_->getDataSize())
     187  {
    161188    SynchronisableHeader objectheader(mem);
    162189
     
    170197      else
    171198      {
    172         mem += objectheader.getDataSize();
     199        mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() );
    173200      }
    174201    }
     
    181208   // In debug mode, check first, whether there are no duplicate objectIDs
    182209#ifndef NDEBUG
    183   if(this->getID()%1000==0){
     210  if(this->getID()%1000==1)
     211  {
    184212    std::list<uint32_t> v1;
    185213    ObjectList<Synchronisable>::iterator it;
    186     for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) {
    187       if (it->getObjectID() == OBJECTID_UNKNOWN) {
    188         if (it->objectMode_ != 0x0) {
     214    for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it)
     215    {
     216      if (it->getObjectID() == OBJECTID_UNKNOWN)
     217      {
     218        if (it->objectMode_ != 0x0)
     219        {
    189220          COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl;
    190221          COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
     
    193224        }
    194225      }
    195       else {
     226      else
     227      {
    196228        std::list<uint32_t>::iterator it2;
    197         for (it2 = v1.begin(); it2 != v1.end(); ++it2) {
    198           if (it->getObjectID() == *it2) {
     229        for (it2 = v1.begin(); it2 != v1.end(); ++it2)
     230        {
     231          if (it->getObjectID() == *it2)
     232          {
    199233            COUT(0) << "Found duplicate objectIDs on the client!" << std::endl
    200234                    << "Are you sure you don't create a Sychnronisable objcect with 'new' \
     
    211245}
    212246
     247
    213248uint32_t Gamestate::getSize() const
    214249{
     
    222257}
    223258
    224 bool Gamestate::operator==(packet::Gamestate gs){
     259
     260bool Gamestate::operator==(packet::Gamestate gs)
     261{
    225262  uint8_t *d1 = data_+GamestateHeader::getSize();
    226263  uint8_t *d2 = gs.data_+GamestateHeader::getSize();
     
    233270}
    234271
     272
    235273bool Gamestate::process()
    236274{
    237275  return GamestateHandler::addGamestate(this, getClientID());
    238276}
    239 
    240277
    241278
     
    253290  int retval;
    254291  retval = compress( dest, &buffer, source, (uLong)(header_->getDataSize()) );
    255   switch ( retval ) {
     292  switch ( retval )
     293  {
    256294    case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
    257295    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; return false;
     
    270308  header_->setCompSize( buffer );
    271309  header_->setCompressed( true );
    272   COUT(5) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;
     310  COUT(0) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;
    273311  return true;
    274312}
     313
     314
    275315bool Gamestate::decompressData()
    276316{
     
    289329  uLongf length=bufsize;
    290330  retval = uncompress( dest, &length, source, (uLong)compsize );
    291   switch ( retval ) {
     331  switch ( retval )
     332  {
    292333    case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
    293334    case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return false;
     
    301342  delete temp;
    302343
    303   if (this->bDataENetAllocated_){
     344  if (this->bDataENetAllocated_)
     345  {
    304346    // Memory was allocated by ENet. --> We let it be since enet_packet_destroy will
    305347    // deallocated it anyway. So data and packet stay together.
    306348    this->bDataENetAllocated_ = false;
    307349  }
    308   else{
     350  else
     351  {
    309352    // We allocated the memory in the first place (unlikely). So we destroy the old data
    310353    // and overwrite it with the new decompressed data.
     
    320363}
    321364
    322 /*Gamestate *Gamestate::diff(Gamestate *base)
    323 {
    324   assert(data_);
    325   assert(!header_->isCompressed());
     365
     366Gamestate* Gamestate::diffVariables(Gamestate *base)
     367{
     368  assert(this && base); assert(data_ && base->data_);
     369  assert(!header_->isCompressed() && !base->header_->isCompressed());
    326370  assert(!header_->isDiffed());
    327   GamestateHeader diffHeader(base->data_);
    328   uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
    329   uint32_t of=0; // pointers offset
    330   uint32_t dest_length=0;
    331   dest_length=header_->getDataSize();
    332   if(dest_length==0)
    333     return NULL;
    334   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    335   uint8_t *dest = ndata + GamestateHeader::getSize();
    336   while(of < diffHeader.getDataSize() && of < header_->getDataSize()){
    337     *(dest+of)=*(basep+of)^*(gs+of); // do the xor
    338     ++of;
    339   }
    340   if(diffHeader.getDataSize()!=header_->getDataSize()){
    341     uint8_t n=0;
    342     if(diffHeader.getDataSize() < header_->getDataSize()){
    343       while(of<dest_length){
    344         *(dest+of)=n^*(gs+of);
    345         of++;
    346       }
    347     }
    348   }
    349 
    350   Gamestate *g = new Gamestate(ndata, getClientID());
     371
     372
     373  // *** first do a raw diff of the two gamestates
     374
     375  uint8_t *baseData = GAMESTATE_START(base->data_);
     376  uint8_t *origData = GAMESTATE_START(this->data_);
     377  uint32_t origLength = header_->getDataSize();
     378  uint32_t baseLength = base->header_->getDataSize();
     379
     380  assert( origLength && baseLength );
     381
     382  uint8_t *nData = new uint8_t[origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_]; // this is the maximum size needed in the worst case
     383  uint8_t *dest = GAMESTATE_START(nData);
     384
     385  uint32_t baseOffset = 0; //offset in the diffed stream
     386  uint32_t origOffset = 0; //offset in the new stream with removed 0's
     387  std::vector<uint32_t>::iterator sizes = this->sizes_.begin();
     388
     389  while( origOffset < origLength )
     390  {
     391    //iterate through all objects
     392
     393    SynchronisableHeader h(origData+origOffset);
     394
     395    // Find (if possible) the current object in the datastream of the old gamestate
     396    // Start at the current offset position
     397    if(baseOffset >= baseLength)
     398      baseOffset = 0;
     399    uint8_t* temp = baseData + baseOffset;
     400    uint32_t objectID = h.getObjectID();
     401    assert(temp < baseData+baseLength);
     402    assert(dest < nData + origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_);
     403    assert(sizes != this->sizes_.end());
     404    while ( temp < baseData+baseLength )
     405    {
     406      SynchronisableHeader htemp(temp);
     407      assert( htemp.getDataSize()!=0 );
     408      if ( htemp.getObjectID() == objectID )
     409      {
     410        assert( h.getClassID() == htemp.getClassID() );
     411        goto DODIFF;
     412      }
     413//       {
     414//         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
     415//         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
     416//         {
     417//           assert(htemp2.getClassID()<500);
     418//           assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
     419//           assert(htemp2.isDiffed()==false);
     420//         }
     421//       }
     422      temp += htemp.getDataSize()+SynchronisableHeader::getSize();
     423       
     424    }
     425    // If not found start looking at the beginning
     426    assert( temp==baseData+baseLength );
     427    temp = baseData;
     428//     {
     429//       SynchronisableHeader htemp2(temp);
     430//       if( temp < baseData+baseLength )
     431//       {
     432//         assert(htemp2.getClassID()<500);
     433//         assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
     434//         assert(htemp2.isDiffed()==false);
     435//       }
     436//     }
     437    while ( temp < baseData+baseOffset )
     438    {
     439      SynchronisableHeader htemp(temp);
     440      if ( htemp.getObjectID() == objectID )
     441      {
     442        assert( h.getClassID() == htemp.getClassID() );
     443        goto DODIFF;
     444      }
     445//       {
     446//         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
     447//         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
     448//         {
     449//           assert(htemp2.getClassID()<500);
     450//           assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
     451//           assert(htemp2.isDiffed()==false);
     452//         }
     453//       }
     454      temp += htemp.getDataSize()+SynchronisableHeader::getSize();
     455    }
     456    // Object is new, thus never transmitted -> just copy over
     457    goto DOCOPY;
     458
     459
     460DODIFF:
     461    {
     462//       COUT(4) << "dodiff" << endl;
     463//       if(baseOffset==0)
     464//       {
     465//         assert(origOffset==0);
     466//       }
     467      uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData
     468      // Check whether the whole object stayed the same
     469      if( memcmp( origData+origOffset+objectOffset, temp+objectOffset, h.getDataSize()) == 0 )
     470      {
     471//         COUT(4) << "skip object" << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
     472        origOffset += objectOffset+ h.getDataSize(); // skip the whole object
     473        baseOffset = temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
     474        sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
     475      }
     476      else
     477      {
     478//         if( Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() == "Bot" )
     479//           COUT(0) << "blub" << endl;
     480//         COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
     481//         COUT(4) << "diff " << h.getObjectID() << ":";
     482        // Now start to diff the Object
     483        SynchronisableHeaderLight h2(dest);
     484        h2 = h; // copy over the objectheader
     485        VariableID variableID = 0;
     486        uint32_t newObjectOffset = SynchronisableHeaderLight::getSize();
     487        // iterate through all variables
     488        while( objectOffset < h.getDataSize()+SynchronisableHeader::getSize() )
     489        {
     490          // check whether variable changed and write id and copy over variable to the new stream
     491          // otherwise skip variable
     492          assert(sizes != this->sizes_.end());
     493          uint32_t varSize = *sizes;
     494          assert( varSize == Synchronisable::getSynchronisable(h.getObjectID())->getVarSize(variableID) );
     495          if ( varSize != 0 )
     496          {
     497            if ( memcmp(origData+origOffset+objectOffset, temp+objectOffset, varSize) != 0 )
     498            {
     499//               COUT(4) << "copy variable" << endl;
     500              *(VariableID*)(dest+newObjectOffset) = variableID; // copy over the variableID
     501              newObjectOffset += sizeof(VariableID);
     502              memcpy( dest+newObjectOffset, origData+origOffset+objectOffset, varSize );
     503              newObjectOffset += varSize;
     504              objectOffset += varSize;
     505            }
     506            else
     507            {
     508//               COUT(4) << "skip variable" << endl;
     509              objectOffset += varSize;
     510            }
     511          }
     512//           else
     513//             COUT(4) << "varsize 0" << endl;
     514
     515          ++variableID;
     516          ++sizes;
     517        }
     518       
     519        if( Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() != variableID )
     520          sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() - variableID;
     521//         COUT(4) << endl;
     522        h2.setDiffed(true);
     523        h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize());
     524        assert(objectOffset == h.getDataSize()+SynchronisableHeader::getSize());
     525        origOffset += objectOffset;
     526//         baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
     527        //baseOffset += objectOffset;
     528//         SynchronisableHeader htemp(temp);
     529//         baseOffset += SynchronisableHeader::getSize() + htemp.getDataSize();
     530//         {
     531//           SynchronisableHeader htemp2( baseData+(temp-baseData+objectOffset) );
     532//           if( baseData+(temp-baseData+objectOffset) < baseData+baseLength )
     533//           {
     534//             assert(htemp2.getClassID()<500);
     535//             assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
     536//             assert(htemp2.isDiffed()==false);
     537//           }
     538//         }
     539        baseOffset = temp-baseData + objectOffset;
     540        dest += newObjectOffset;
     541      }
     542
     543      continue;
     544    }
     545
     546DOCOPY:
     547    {
     548//       COUT(4) << "docopy" << endl;
     549      // Just copy over the whole Object
     550      memcpy( dest, origData+origOffset, h.getDataSize()+SynchronisableHeader::getSize() );
     551      dest += h.getDataSize()+SynchronisableHeader::getSize();
     552      origOffset += h.getDataSize()+SynchronisableHeader::getSize();
     553      assert( Synchronisable::getSynchronisable(h.getObjectID()) );
     554//       COUT(4) << "copy " << h.getObjectID() << endl;
     555//       COUT(4) << "copy " << h.getObjectID() << ":";
     556      //sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
     557      for( unsigned int i = 0; i < Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); ++i )
     558      {
     559//         COUT(4) << " " << *sizes;
     560        ++sizes;
     561      }
     562//       COUT(4) << endl;
     563      assert(sizes != this->sizes_.end() || origOffset>=origLength);
     564      continue;
     565    }
     566  }
     567
     568
     569  Gamestate *g = new Gamestate(nData, getClientID());
     570  assert(g->header_);
    351571  *(g->header_) = *header_;
    352   g->header_->setDiffed( true );
    353572  g->header_->setBaseID( base->getID() );
     573  g->header_->setDataSize(dest - nData - GamestateHeader::getSize());
    354574  g->flags_=flags_;
    355575  g->packetDirection_ = packetDirection_;
     576  assert(!g->isCompressed());
    356577  return g;
    357 }*/
    358 
    359 Gamestate *Gamestate::diff(Gamestate *base)
     578}
     579
     580
     581Gamestate* Gamestate::diffData(Gamestate *base)
    360582{
    361583  assert(this && base); assert(data_ && base->data_);
     
    393615}
    394616
    395 Gamestate *Gamestate::undiff(Gamestate *base)
     617
     618Gamestate* Gamestate::undiff(Gamestate *base)
    396619{
    397620  assert(this && base); assert(data_ && base->data_);
     
    423646
    424647
    425 // Gamestate *Gamestate::diff(Gamestate *base)
    426 // {
    427 //   assert(data_);
    428 //   assert(!header_->isCompressed());
    429 //   assert(!header_->isDiffed());
    430 //   GamestateHeader diffHeader(base->data_);
    431 //   uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
    432 //   uint32_t of=0; // pointers offset
    433 //   uint32_t dest_length=0;
    434 //   dest_length=header_->getDataSize();
    435 //   if(dest_length==0)
    436 //     return NULL;
    437 //   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    438 //   uint8_t *dest = ndata + GamestateHeader::getSize();
    439 //
    440 //
    441 //   // LOOP-UNROLLED DIFFING
    442 //   uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
    443 //   // diff in 4-byte steps
    444 //   while( of < (uint32_t)(header_->getDataSize())/4 ){
    445 //     if( of < (uint32_t)(diffHeader.getDataSize())/4 )
    446 //     {
    447 //       *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
    448 //       ++of;
    449 //     }
    450 //     else
    451 //     {
    452 //       *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
    453 //       ++of;
    454 //     }
    455 //   }
    456 //   for( unsigned int of2 = 0; of2 < header_->getDataSize()%4; ++of2 )
    457 //   {
    458 //     if( of*4+of2 < diffHeader.getDataSize() )
    459 //     {
    460 //       *(dest+4*of+of2)=*(basep+4*of+of2) ^ *(gs+4*of+of2); // do the xor
    461 //     }
    462 //     else
    463 //     {
    464 //       *(dest+4*of+of2)=*(gs+4*of+of2); // same as 0 ^ *(gs32+of)
    465 //     }
    466 //   }
    467 //
    468 //   Gamestate *g = new Gamestate(ndata, getClientID());
    469 //   *(g->header_) = *header_;
    470 //   g->header_->setDiffed( true );
    471 //   g->header_->setBaseID( base->getID() );
    472 //   g->flags_=flags_;
    473 //   g->packetDirection_ = packetDirection_;
    474 //   return g;
    475 // }
    476 
    477 
    478648void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)
    479649{
     
    501671  assert(j==datalength);
    502672}
     673
    503674
    504675Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
     
    529700//   COUT(0) << "myvector contains:";
    530701//   for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )
    531 //     COUT(0) << ' ' << (*itt).objID;
     702//     COUT(0) << " " << (*itt).objID;
    532703//   COUT(0) << endl;
    533704  for(it=dataVector_.begin(); it!=dataVector_.end();){
    534705    SynchronisableHeader oldobjectheader(origdata);
    535706    SynchronisableHeader newobjectheader(newdata);
    536     if ( it->objSize == 0 )
     707    if ( (*it).objSize == 0 )
    537708    {
    538709      ++it;
    539710      continue;
    540711    }
    541     objectsize = oldobjectheader.getDataSize();
     712    objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();
    542713    objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader
    543     if ( it->objID == oldobjectheader.getObjectID() ){
     714    if ( (*it).objID == oldobjectheader.getObjectID() ){
    544715      memcpy(newdata, origdata, objectsize);
    545       assert(newobjectheader.isDataAvailable()==true);
    546716      ++it;
    547717    }else{
    548718      newobjectheader = oldobjectheader;
    549       newobjectheader.setDataAvailable(false);
    550719      memset(newdata+objectOffset, 0, objectsize-objectOffset);
    551720    }
     
    559728  {
    560729    SynchronisableHeader oldobjectheader(origdata);
    561     objectsize = oldobjectheader.getDataSize();
     730    objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();
    562731    origdata += objectsize;
    563732    origsize += objectsize;
     
    571740
    572741
    573 /*Gamestate *Gamestate::undiff(Gamestate *base)
    574 {
    575   assert(this && base);assert(data_);
    576   assert(header_->isDiffed());
    577   assert(!header_->isCompressed() && !base->header_->isCompressed());
    578   uint8_t *basep = GAMESTATE_START(base->data_);
    579   uint8_t *gs = GAMESTATE_START(this->data_);
    580   uint32_t of=0; // pointers offset
    581   uint32_t dest_length=0;
    582   dest_length=header_->getDataSize();
    583   if(dest_length==0)
    584     return NULL;
    585   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    586   uint8_t *dest = ndata + GamestateHeader::getSize();
    587   while(of < base->header_->getDataSize() && of < header_->getDataSize()){
    588     *(dest+of)=*(basep+of)^*(gs+of); // do the xor
    589     ++of;
    590   }
    591   if(base->header_->getDataSize()!=header_->getDataSize()){
    592     uint8_t n=0;
    593     if(base->header_->getDataSize() < header_->getDataSize()){
    594       while(of < dest_length){
    595         *(dest+of)=n^*(gs+of);
    596         of++;
    597       }
    598     }
    599   }
    600   Gamestate *g = new Gamestate(ndata, getClientID());
    601   assert(g->header_);
    602   *(g->header_) = *header_;
    603   g->header_->setDiffed( false );
    604   g->flags_=flags_;
    605   g->packetDirection_ = packetDirection_;
    606   assert(!g->isDiffed());
    607   assert(!g->isCompressed());
    608   return g;
    609 }*/
    610 
    611742uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
    612743{
    613   uint32_t size=0;
     744  uint32_t size = 0;
     745  uint32_t nrOfVariables = 0;
    614746    // get the start of the Synchronisable list
    615747  ObjectList<Synchronisable>::iterator it;
    616748    // get total size of gamestate
    617   for(it = ObjectList<Synchronisable>::begin(); it; ++it)
     749  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    618750    size+=it->getSize(id, mode); // size of the actual data of the synchronisable
     751    nrOfVariables += it->getNrOfVariables();
     752  }
     753//   COUT(0) << "allocating " << nrOfVariables << " ints" << endl;
     754  this->sizes_.reserve(nrOfVariables);
    619755  return size;
    620756}
     757
    621758
    622759} //namespace packet
  • code/trunk/src/libraries/network/packet/Gamestate.h

    r6073 r7163  
    3636#include <cstring>
    3737#include <list>
     38#include <vector>
    3839
    3940#include "util/CRC32.h"
     
    113114    inline bool isCompressed() const { return header_->isCompressed(); }
    114115    inline int32_t getBaseID() const { return header_->getBaseID(); }
    115     Gamestate *diff(Gamestate *base);
     116    inline uint32_t getDataSize() const { return header_->getDataSize(); }
     117    Gamestate* diffVariables(Gamestate *base);
     118    Gamestate* diffData(Gamestate *base);
    116119    Gamestate *undiff(Gamestate *base);
    117120    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
     
    123126  private:
    124127    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
     128    inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
    125129    virtual uint32_t getSize() const;
    126130    virtual inline bool process();
    127 
    128   private:
    129131    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    130     std::list<obj> dataVector_;
    131     GamestateHeader* header_;
     132   
     133    std::list<obj>          dataVector_;
     134    GamestateHeader*        header_;
     135    std::vector<uint32_t>   sizes_;
     136    uint32_t                nrOfVariables_;
    132137};
    133138
  • code/trunk/src/libraries/network/packet/Packet.cc

    r6417 r7163  
    6262std::map<size_t, Packet *> Packet::packetMap_;
    6363
    64 Packet::Packet(){
     64Packet::Packet()
     65{
    6566  flags_ = PACKET_FLAG_DEFAULT;
    6667  packetDirection_ = Direction::Outgoing;
     
    7172}
    7273
    73 void blub(ENetPacket *packet){
    74   COUT(4) << "blubb" << std::endl;
    75 }
    76 
    77 Packet::Packet(uint8_t *data, unsigned int clientID){
     74Packet::Packet(uint8_t *data, unsigned int clientID)
     75{
    7876  flags_ = PACKET_FLAG_DEFAULT;
    7977  packetDirection_ = Direction::Incoming;
  • code/trunk/src/libraries/network/synchronisable/Serialise.h

    r6417 r7163  
    3838#include "util/TypeTraits.h"
    3939#include "core/CorePrereqs.h"
     40#include "core/CoreIncludes.h"
     41#include "core/SmartPtr.h"
    4042
    4143namespace orxonox{
     
    7274            return *(uint32_t*)(mem) == variable->getObjectID();
    7375        else
     76            return variable == variable->getSynchronisable(*(uint32_t*)(mem));
     77    }
     78   
     79    // These functions implement loading / saving / etc. for SmartPtr<T>
     80   
     81    /** @brief returns the size of the objectID needed to synchronise the pointer */
     82    template <class T> inline uint32_t returnSize( const SmartPtr<T>& variable )
     83    {
     84        return sizeof(uint32_t);
     85    }
     86   
     87    /** @brief reads the objectID of a pointer out of the bytestream and increases the mem pointer */
     88    template <class T> inline void loadAndIncrease( const SmartPtr<T>& variable, uint8_t*& mem )
     89    {
     90//         *const_cast<typename Loki::TypeTraits<T*>::UnqualifiedType*>(&variable) = dynamic_cast<T*>(variable->getSynchronisable( *(uint32_t*)(mem) ));
     91        *const_cast<typename Loki::TypeTraits<SmartPtr<T> >::UnqualifiedType*>(&variable) = orxonox_cast<T*>(T::getSynchronisable(*(uint32_t*)(mem)));
     92        mem += returnSize( variable );
     93    }
     94   
     95    /** @brief saves the objectID of a pointer into the bytestream and increases the mem pointer */
     96    template <class T> inline void saveAndIncrease( const SmartPtr<T>& variable, uint8_t*& mem )
     97    {
     98        if ( variable.get() )
     99            *(uint32_t*)(mem) = static_cast<uint32_t>(variable->getObjectID());
     100        else
     101            *(uint32_t*)(mem) = OBJECTID_UNKNOWN;
     102        mem += returnSize( variable );
     103    }
     104   
     105    /** @brief checks whether the objectID of the variable is the same as in the bytestream */
     106    template <class T> inline  bool checkEquality( const SmartPtr<T>& variable, uint8_t* mem )
     107    {
     108        if ( variable.get() )
     109            return *(uint32_t*)(mem) == variable->getObjectID();
     110        else
     111            return *(uint32_t*)(mem) == OBJECTID_UNKNOWN;
     112    }
     113   
     114    // These functions implement loading / saving / etc. for WeakPtr<T>
     115   
     116    /** @brief returns the size of the objectID needed to synchronise the pointer */
     117    template <class T> inline uint32_t returnSize( const WeakPtr<T>& variable )
     118    {
     119        return sizeof(uint32_t);
     120    }
     121   
     122    /** @brief reads the objectID of a pointer out of the bytestream and increases the mem pointer */
     123    template <class T> inline void loadAndIncrease( const WeakPtr<T>& variable, uint8_t*& mem )
     124    {
     125        //         *const_cast<typename Loki::TypeTraits<T*>::UnqualifiedType*>(&variable) = dynamic_cast<T*>(variable->getSynchronisable( *(uint32_t*)(mem) ));
     126        *const_cast<typename Loki::TypeTraits<SmartPtr<T> >::UnqualifiedType*>(&variable) = orxonox_cast<T*>(T::getSynchronisable(*(uint32_t*)(mem)));
     127        mem += returnSize( variable );
     128    }
     129   
     130    /** @brief saves the objectID of a pointer into the bytestream and increases the mem pointer */
     131    template <class T> inline void saveAndIncrease( const WeakPtr<T>& variable, uint8_t*& mem )
     132    {
     133        if ( variable.get() )
     134            *(uint32_t*)(mem) = static_cast<uint32_t>(variable->getObjectID());
     135        else
     136            *(uint32_t*)(mem) = OBJECTID_UNKNOWN;
     137        mem += returnSize( variable );
     138    }
     139   
     140    /** @brief checks whether the objectID of the variable is the same as in the bytestream */
     141    template <class T> inline  bool checkEquality( const WeakPtr<T>& variable, uint8_t* mem )
     142    {
     143        if ( variable.get() )
     144            return *(uint32_t*)(mem) == variable->getObjectID();
     145        else
    74146            return *(uint32_t*)(mem) == OBJECTID_UNKNOWN;
    75147    }
  • code/trunk/src/libraries/network/synchronisable/Synchronisable.cc

    r6417 r7163  
    4949  * Initializes all Variables and sets the right objectID_
    5050  */
    51   Synchronisable::Synchronisable(BaseObject* creator ){
     51  Synchronisable::Synchronisable(BaseObject* creator )
     52  {
    5253    RegisterRootObject(Synchronisable);
    5354    static uint32_t idCounter=0;
    5455    objectMode_=0x1; // by default do not send data to server
    55     if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) )
     56    if ( GameMode::isMaster()/* || ( Host::running() && Host::isServer() )*/ )
    5657    {
    5758      this->setObjectID( idCounter++ );
     
    7374    else
    7475      this->creatorID_ = OBJECTID_UNKNOWN;
    75 
    76     /*searchcreatorID:
    77     if (creator)
    78     {
    79         Synchronisable* synchronisable_creator = orxonox_cast<Synchronisable*>(creator);
    80         if (synchronisable_creator && synchronisable_creator->objectMode_)
    81         {
    82             this->creatorID = synchronisable_creator->getScene()->getObjectID();
    83         }
    84         else if (creator != creator->getCreator())
    85         {
    86             creator = creator->getCreator();
    87             goto searchcreatorID;
    88         }
    89     }*/
    9076  }
    9177
     
    9480   * Delete all callback objects and remove objectID_ from the objectMap_
    9581   */
    96   Synchronisable::~Synchronisable(){
     82  Synchronisable::~Synchronisable()
     83  {
    9784    // delete callback function objects
    9885    if(!Identifier::isCreatingHierarchy()){
     
    10188        deletedObjects_.push(objectID_);
    10289    }
    103     // delete all Synchronisable Variables from syncList ( which are also in stringList )
    104     for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
     90    // delete all Synchronisable Variables from syncList_ ( which are also in stringList_ )
     91    for(std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); it!=syncList_.end(); it++)
    10592      delete (*it);
    106     syncList.clear();
    107     stringList.clear();
     93    syncList_.clear();
     94    stringList_.clear();
    10895    std::map<uint32_t, Synchronisable*>::iterator it;
    10996    it = objectMap_.find(objectID_);
     
    118105   * @param b true if this object is located on a client or on a server
    119106   */
    120   void Synchronisable::setClient(bool b){
     107  void Synchronisable::setClient(bool b)
     108  {
    121109    if(b) // client
    122110      state_=0x2;
     
    135123  {
    136124    SynchronisableHeader header(mem);
    137 
    138     if(!header.isDataAvailable())
    139     {
    140       mem += header.getDataSize();
    141       return 0;
    142     }
     125    assert( !header.isDiffed() );
    143126
    144127    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
     
    160143      if (!synchronisable_creator)
    161144      {
    162         mem += header.getDataSize(); //.TODO: this suckz.... remove size from header
     145        mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header
    163146        assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^
    164147        return 0;
     
    177160    no->setClassID(header.getClassID());
    178161    assert(no->creatorID_ == header.getCreatorID());
     162    if( creator )
     163      bo->setLevel(creator->getLevel());          // Note: this ensures that the level is known on the client for child objects of the scene (and the scene itself)
    179164    //assert(no->classID_ == header.getClassID());
    180165    COUT(4) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << std::endl;
     
    196181   * @return true/false
    197182   */
    198   bool Synchronisable::deleteObject(uint32_t objectID_){
     183  bool Synchronisable::deleteObject(uint32_t objectID_)
     184  {
    199185    if(!getSynchronisable(objectID_))
    200186      return false;
     
    213199   * @return pointer to the Synchronisable with the objectID_
    214200   */
    215   Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){
     201  Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_)
     202  {
    216203    std::map<uint32_t, Synchronisable*>::iterator it1;
    217204    it1 = objectMap_.find(objectID_);
    218205    if (it1 != objectMap_.end())
    219206      return it1->second;
    220 
    221 //     ObjectList<Synchronisable>::iterator it;
    222 //     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    223 //       if( it->getObjectID()==objectID_ ){
    224 //         objectMap_[objectID_] = *it;
    225 //         return *it;
    226 //       }
    227 //     }
    228207    // if the objects not in the map it should'nt exist at all anymore
    229208    return NULL;
     
    245224   * @return true: if !doSync or if everything was successfully saved
    246225   */
    247   uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
     226  uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode)
     227  {
     228    unsigned int test = 0;
    248229    if(mode==0x0)
    249230      mode=state_;
     
    253234    uint32_t tempsize = 0;
    254235#ifndef NDEBUG
     236    uint8_t* oldmem = mem;
    255237    if (this->classID_==0)
    256238      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     
    270252    // end copy header
    271253
    272 
    273     COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl;
     254    CCOUT(5) << "getting data from objectID_: " << objectID_ << ", classID_: " << classID_ << std::endl;
     255//     COUT(4) << "objectid: " << this->objectID_ << ":";
    274256    // copy to location
    275     for(i=syncList.begin(); i!=syncList.end(); ++i){
    276       tempsize += (*i)->getData( mem, mode );
     257    for(i=syncList_.begin(); i!=syncList_.end(); ++i)
     258    {
     259      uint32_t varsize = (*i)->getData( mem, mode );
     260//       COUT(4) << " " << varsize;
     261      tempsize += varsize;
     262      sizes.push_back(varsize);
     263      ++test;
    277264      //tempsize += (*i)->getSize( mode );
    278265    }
    279 
    280     tempsize += SynchronisableHeader::getSize();
     266//     COUT(4) << endl;
     267
    281268    header.setObjectID( this->objectID_ );
    282269    header.setCreatorID( this->creatorID_ );
    283270    header.setClassID( this->classID_ );
    284     header.setDataAvailable( true );
    285271    header.setDataSize( tempsize );
     272    assert( tempsize == mem-oldmem-SynchronisableHeader::getSize() );
     273    assert( test == this->getNrOfVariables() );
     274    header.setDiffed(false);
     275    tempsize += SynchronisableHeader::getSize();
    286276
    287277#ifndef NDEBUG
     
    300290   * @return true/false
    301291   */
    302   bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){
     292  bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback)
     293  {
    303294    if(mode==0x0)
    304295      mode=state_;
    305     std::vector<SynchronisableVariableBase *>::iterator i;
    306     if(syncList.empty()){
     296    if(syncList_.empty())
     297    {
    307298      assert(0);
    308       COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
     299      COUT(2) << "Synchronisable::updateData syncList_ is empty" << std::endl;
    309300      return false;
    310301    }
     
    312303    uint8_t* data=mem;
    313304    // start extract header
    314     SynchronisableHeader syncHeader(mem);
    315     assert(syncHeader.getObjectID()==this->objectID_);
    316     assert(syncHeader.getCreatorID()==this->creatorID_);
    317     assert(syncHeader.getClassID()==this->classID_);
    318     if(syncHeader.isDataAvailable()==false){
    319       mem += syncHeader.getDataSize();
    320       return true;
    321     }
    322 
    323     mem += SynchronisableHeader::getSize();
    324     // stop extract header
     305    SynchronisableHeaderLight syncHeaderLight(mem);
     306    assert(syncHeaderLight.getObjectID()==this->getObjectID());
    325307
    326308    //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
    327     for(i=syncList.begin(); i!=syncList.end(); i++)
    328     {
    329       assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream
    330       (*i)->putData( mem, mode, forceCallback );
    331     }
    332     assert(mem == data+syncHeader.getDataSize());
     309    if( !syncHeaderLight.isDiffed() )
     310    {
     311      SynchronisableHeader syncHeader2(mem);
     312      assert( this->getClassID() == syncHeader2.getClassID() );
     313      assert( this->getCreatorID() == syncHeader2.getCreatorID() );
     314      mem += SynchronisableHeader::getSize();
     315      std::vector<SynchronisableVariableBase *>::iterator i;
     316      for(i=syncList_.begin(); i!=syncList_.end(); i++)
     317      {
     318        assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream
     319        (*i)->putData( mem, mode, forceCallback );
     320      }
     321      assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeader::getSize() );
     322    }
     323    else
     324    {
     325      mem += SynchronisableHeaderLight::getSize();
     326//       COUT(0) << "objectID: " << this->objectID_ << endl;
     327      while( mem < data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() )
     328      {
     329        VariableID varID = *(VariableID*)mem;
     330//         COUT(0) << "varID: " << varID << endl;
     331        assert( varID < syncList_.size() );
     332        mem += sizeof(VariableID);
     333        syncList_[varID]->putData( mem, mode, forceCallback );
     334      }
     335      assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() );
     336    }
    333337    return true;
    334338  }
     
    340344  * @return amount of bytes
    341345  */
    342   uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    343     int tsize=SynchronisableHeader::getSize();
     346  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode)
     347  {
     348    uint32_t tsize=SynchronisableHeader::getSize();
    344349    if (mode==0x0)
    345350      mode=state_;
     
    349354    tsize += this->dataSize_;
    350355    std::vector<SynchronisableVariableBase*>::iterator i;
    351     for(i=stringList.begin(); i!=stringList.end(); ++i){
     356    for(i=stringList_.begin(); i!=stringList_.end(); ++i)
     357    {
    352358      tsize += (*i)->getSize( mode );
    353359    }
     
    360366   * @return true/false
    361367   */
    362   bool Synchronisable::doSync(int32_t id, uint8_t mode){
     368  bool Synchronisable::doSync(int32_t id, uint8_t mode)
     369  {
    363370    if(mode==0x0)
    364371      mode=state_;
    365     return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) );
    366   }
    367 
    368   /**
    369    * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones
    370    * @param mem pointer to the bytestream
    371    */
    372   bool Synchronisable::isMyData(uint8_t* mem)
    373   {
    374     SynchronisableHeader header(mem);
    375     assert(header.getObjectID()==this->objectID_);
    376     return header.isDataAvailable();
     372    return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) );
    377373  }
    378374
     
    385381   * @param mode same as in registerVar
    386382   */
    387   void Synchronisable::setSyncMode(uint8_t mode){
     383  void Synchronisable::setSyncMode(uint8_t mode)
     384  {
    388385    assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
    389386    this->objectMode_=mode;
     
    397394    else
    398395      sv = new SynchronisableVariable<std::string>(variable, mode, cb);
    399     syncList.push_back(sv);
    400     stringList.push_back(sv);
     396    syncList_.push_back(sv);
     397    stringList_.push_back(sv);
     398  }
     399
     400template <> void Synchronisable::unregisterVariable( std::string& variable )
     401  {
     402    bool unregistered_nonexistent_variable = true;
     403    std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin();
     404    while(it!=syncList_.end())
     405    {
     406      if( ((*it)->getReference()) == &variable )
     407      {
     408        delete (*it);
     409        syncList_.erase(it);
     410        unregistered_nonexistent_variable = false;
     411        break;
     412      }
     413      else
     414        ++it;
     415    }
     416    assert(unregistered_nonexistent_variable == false);
     417   
     418    it = stringList_.begin();
     419    while(it!=stringList_.end())
     420    {
     421      if( ((*it)->getReference()) == &variable )
     422      {
     423        delete (*it);
     424        stringList_.erase(it);
     425        return;
     426      }
     427      else
     428        ++it;
     429    }
     430    unregistered_nonexistent_variable = true;
     431    assert(unregistered_nonexistent_variable == false); //if we reach this point something went wrong:
     432    // the variable has not been registered before
    401433  }
    402434
  • code/trunk/src/libraries/network/synchronisable/Synchronisable.h

    r6417 r7163  
    3737#include <map>
    3838#include <queue>
     39#include <set>
    3940
    4041#include "util/mbool.h"
     
    6465    };
    6566  }
     67 
     68  typedef uint8_t VariableID;
    6669
    6770  /**
     
    7174   * in an emulated bitset.
    7275   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    73    * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
     76   * Bit 32 is a bool and defines whether the variables are stored in diff mode
    7477   * Byte 5 to 8: objectID_
    7578   * Byte 9 to 12: classID_
     
    7780   */
    7881  class _NetworkExport SynchronisableHeader{
     82    friend class SynchronisableHeaderLight;
    7983    private:
    80       uint8_t *data_;
     84      uint8_t* data_;
    8185    public:
    8286      SynchronisableHeader(uint8_t* data)
    8387        { data_ = data; }
    8488      inline static uint32_t getSize()
    85         { return 16; }
    86       inline uint32_t getDataSize() const
    87         { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits
    88       inline void setDataSize(uint32_t size)
    89         { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }
    90       inline bool isDataAvailable() const
    91         { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
    92       inline void setDataAvailable( bool b)
    93         { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
     89        { return 14; }
     90      inline uint16_t getDataSize() const
     91        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits
     92      inline void setDataSize(uint16_t size)
     93        { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(uint16_t*)(data_) & 0x8000 ); }
     94      inline bool isDiffed() const
     95        { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
     96      inline void setDiffed( bool b)
     97        { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
    9498      inline uint32_t getObjectID() const
    95         { return *(uint32_t*)(data_+4); }
     99        { return *(uint32_t*)(data_+2); }
    96100      inline void setObjectID(uint32_t objectID_)
    97         { *(uint32_t*)(data_+4) = objectID_; }
     101        { *(uint32_t*)(data_+2) = objectID_; }
    98102      inline uint32_t getClassID() const
    99         { return *(uint32_t*)(data_+8); }
     103        { return *(uint32_t*)(data_+6); }
    100104      inline void setClassID(uint32_t classID_)
    101         { *(uint32_t*)(data_+8) = classID_; }
     105        { *(uint32_t*)(data_+6) = classID_; }
    102106      inline uint32_t getCreatorID() const
    103         { return *(uint32_t*)(data_+12); }
     107        { return *(uint32_t*)(data_+10); }
    104108      inline void setCreatorID(uint32_t creatorID_)
    105         { *(uint32_t*)(data_+12) = creatorID_; }
     109        { *(uint32_t*)(data_+10) = creatorID_; }
    106110      inline void operator=(SynchronisableHeader& h)
    107111        { memcpy(data_, h.data_, getSize()); }
    108112  };
    109113
     114    /**
     115   * @brief: stores information about a Synchronisable (light version)
     116   *
     117   * This class stores the information about a Synchronisable (objectID_, dataSize)
     118   * in an emulated bitset.
     119   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
     120   * Bit 32 is a bool and defines whether the variables are stored in diff mode
     121   * Byte 5 to 8: objectID_
     122   */
     123  class _NetworkExport SynchronisableHeaderLight{
     124    private:
     125      uint8_t* data_;
     126    public:
     127      SynchronisableHeaderLight(uint8_t* data)
     128        { data_ = data; }
     129      inline static uint32_t getSize()
     130        { return 6; }
     131      inline uint16_t getDataSize() const
     132        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits
     133      inline void setDataSize(uint16_t size)
     134        { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
     135      inline bool isDiffed() const
     136        { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
     137      inline void setDiffed( bool b)
     138        { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
     139      inline uint32_t getObjectID() const
     140        { return *(uint32_t*)(data_+2); }
     141      inline void setObjectID(uint32_t objectID_)
     142        { *(uint32_t*)(data_+2) = objectID_; }
     143      inline void operator=(SynchronisableHeader& h)
     144        { memcpy(data_, h.data_, getSize()); }
     145  };
    110146
    111147  /**
     
    134170
    135171    void setSyncMode(uint8_t mode);
     172   
     173    inline uint32_t getNrOfVariables(){ return this->syncList_.size(); }
     174    inline uint32_t getVarSize( VariableID ID )
     175    { return this->syncList_[ID]->getSize(state_); }
    136176
    137177  protected:
    138178    Synchronisable(BaseObject* creator);
    139179    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
     180    template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
     181    template <class T> void unregisterVariable(T& var);
    140182
    141183    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    143185
    144186  private:
    145     uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
     187    uint32_t getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode);
    146188    uint32_t getSize(int32_t id, uint8_t mode=0x0);
    147189    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
    148     bool isMyData(uint8_t* mem);
    149190    bool doSync(int32_t id, uint8_t mode=0x0);
    150191
     
    156197    uint32_t classID_;
    157198
    158     std::vector<SynchronisableVariableBase*> syncList;
    159     std::vector<SynchronisableVariableBase*> stringList;
     199    std::vector<SynchronisableVariableBase*> syncList_;
     200    std::vector<SynchronisableVariableBase*> stringList_;
    160201    uint32_t dataSize_; //size of all variables except strings
    161202    static uint8_t state_; // detemines wheter we are server (default) or client
     
    171212    if (bidirectional)
    172213    {
    173       syncList.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
    174       this->dataSize_ += syncList.back()->getSize(state_);
     214      syncList_.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
     215      this->dataSize_ += syncList_.back()->getSize(state_);
    175216    }
    176217    else
    177218    {
    178       syncList.push_back(new SynchronisableVariable<T>(variable, mode, cb));
     219      syncList_.push_back(new SynchronisableVariable<T>(variable, mode, cb));
    179220      if ( this->state_ == mode )
    180         this->dataSize_ += syncList.back()->getSize(state_);
     221        this->dataSize_ += syncList_.back()->getSize(state_);
    181222    }
    182223  }
     224 
     225  template <class T> void Synchronisable::unregisterVariable(T& variable){
     226    std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin();
     227    while(it!=syncList_.end()){
     228      if( ((*it)->getReference()) == &variable ){
     229        this->dataSize_ -= (*it)->getSize(Synchronisable::state_);
     230        delete (*it);
     231        syncList_.erase(it);
     232        return;
     233      }
     234      else
     235        it++;
     236    }
     237    bool unregistered_nonexistent_variable = false;
     238    assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     239    // the variable has not been registered before
     240  }
     241
     242  template <class T> void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     243  {
     244    SynchronisableVariableBase* sv;
     245    if (bidirectional)
     246      sv = new SynchronisableVariableBidirectional<std::set<T> >(variable, mode, cb);
     247    else
     248      sv = new SynchronisableVariable<std::set<T> >(variable, mode, cb);
     249    syncList_.push_back(sv);
     250    stringList_.push_back(sv);
     251  }
    183252
    184253  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     254//   template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T> >( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     255  template <> _NetworkExport void Synchronisable::unregisterVariable( std::string& variable );
    185256
    186257
  • code/trunk/src/libraries/tools/CMakeLists.txt

    r6417 r7163  
    1515COMPILATION_END
    1616)
     17#ADD_SUBDIRECTORY(bsp)
    1718ADD_SUBDIRECTORY(interfaces)
    1819
    1920ORXONOX_ADD_LIBRARY(tools
    2021  FIND_HEADER_FILES
    21   DEFINE_SYMBOL
    22     "TOOLS_SHARED_BUILD"
    2322  LINK_LIBRARIES
    2423    core
  • code/trunk/src/libraries/tools/ToolsPrereqs.h

    r5929 r7163  
    4242//-----------------------------------------------------------------------
    4343
    44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
     44#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(TOOLS_STATIC_BUILD)
    4545#  ifdef TOOLS_SHARED_BUILD
    4646#    define _ToolsExport __declspec(dllexport)
  • code/trunk/src/libraries/util/CMakeLists.txt

    r6503 r7163  
    2727  Clipboard.cc
    2828  Clock.cc
     29  Convert.cc
    2930  CRC32.cc
    3031  ExprParser.cc
     
    4950ORXONOX_ADD_LIBRARY(util
    5051  FIND_HEADER_FILES
    51   DEFINE_SYMBOL
    52     "UTIL_SHARED_BUILD"
    5352  LINK_LIBRARIES
    5453    ${CEGUI_LIBRARY}
  • code/trunk/src/libraries/util/Convert.h

    r6417 r7163  
    6464
    6565    Defining your own functions:
    66     There are obviously 4 ways to specifiy a user defined conversion. What should I use?
     66    There are obviously 4 ways to specify a user defined conversion. What should you use?
    6767
    6868    Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from
     
    7070
    7171    However if you want to overwrite an implicit conversion or an iostream operator, you really need to
    72     make use of ConverterExplicit.
     72    make use of ConverterExplicit. We have to do this for the Ogre classes for instance because they
     73    define stream operators we don't particulary like.
    7374*/
    7475
     
    388389    };
    389390
    390     // Declarations to avoid StringUtils.h include
    391     _UtilExport std::string removeTrailingWhitespaces(const std::string& str);
    392     _UtilExport std::string getLowercase(const std::string& str);
    393 
    394391    // std::string to bool
    395392    template <>
    396     struct ConverterExplicit<std::string, bool>
    397     {
    398         static bool convert(bool* output, const std::string& input)
    399         {
    400             const std::string& stripped = getLowercase(removeTrailingWhitespaces(input));
    401             if (stripped == "true" || stripped == "on" || stripped == "yes")
    402             {
    403                 *output = true;
    404                 return true;
    405             }
    406             else if (stripped == "false" || stripped == "off" || stripped == "no")
    407             {
    408                 *output = false;
    409                 return true;
    410             }
    411 
    412             std::istringstream iss(input);
    413             if (iss >> (*output))
    414                 return true;
    415             else
    416                 return false;
    417         }
     393    struct _UtilExport ConverterExplicit<std::string, bool>
     394    {
     395        static bool convert(bool* output, const std::string& input);
    418396    };
    419397}
  • code/trunk/src/libraries/util/Serialise.h

    r6746 r7163  
    3838
    3939#include <cstring>
     40#include <set>
    4041#include "Math.h"
    4142#include "mbool.h"
     
    5253    template <class T> inline bool checkEquality( const T& variable, uint8_t* mem );
    5354
     55 
     56  // =========== char*
     57   
     58  inline uint32_t returnSize( char*& variable )
     59  {
     60    return strlen(variable)+1;
     61  }
     62     
     63  inline void saveAndIncrease( char*& variable, uint8_t*& mem )
     64  {
     65    strcpy((char*)mem, variable);
     66    mem += returnSize(variable);
     67  }
     68       
     69  inline void loadAndIncrease( char*& variable, uint8_t*& mem )
     70  {
     71    if( variable )
     72      delete variable;
     73    uint32_t len = strlen((char*)mem)+1;
     74    variable = new char[len];
     75    strcpy((char*)variable, (char*)mem);
     76    mem += len;
     77  }
     78         
     79  inline bool checkEquality( char*& variable, uint8_t* mem )
     80  {
     81    return strcmp(variable, (char*)mem)==0;
     82  }
     83   
    5484// =================== Template specialisation stuff =============
    5585
     
    393423        return memcmp(&temp, mem, sizeof(uint64_t))==0;
    394424    }
    395 
     425       
    396426// =========== string
    397427
     
    635665        return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem );
    636666    }
     667
     668    // =========== std::set
     669
     670    template <class T> inline uint32_t returnSize( const std::set<T>& variable )
     671    {
     672        uint32_t tempsize = sizeof(uint32_t); // for the number of entries
     673        for( typename std::set<T>::iterator it=((std::set<T>*)(&variable))->begin(); it!=((std::set<T>*)(&variable))->end(); ++it)
     674            tempsize += returnSize( *it );
     675        return tempsize;
     676    }
     677
     678    template <class T> inline void saveAndIncrease(  const std::set<T>& variable, uint8_t*& mem )
     679    {
     680        typename std::set<T>::const_iterator it = variable.begin();
     681        saveAndIncrease( (uint32_t)variable.size(), mem );
     682        for( ; it!=variable.end(); ++it )
     683            saveAndIncrease( *it, mem );
     684    }
     685
     686    template <class T> inline void loadAndIncrease( const std::set<T>& variable, uint8_t*& mem )
     687    {
     688        uint32_t nrOfElements = 0;
     689        loadAndIncrease( nrOfElements, mem );
     690        typename std::set<T>::const_iterator it = variable.begin();
     691        for( uint32_t i = 0; i<nrOfElements; ++i )
     692        {
     693            T temp;
     694            loadAndIncrease(temp, mem);
     695            while( it!=variable.end() && *it!=temp )
     696            {
     697                ((std::set<T>*)(&variable))->erase(it++);
     698                ++it;
     699            }
     700            if( it==variable.end() )
     701            {
     702                ((std::set<T>*)(&variable))->insert(temp);
     703            }
     704        }
     705    }
     706
     707    template <class T> inline bool checkEquality( const std::set<T>& variable, uint8_t* mem )
     708    {
     709        uint8_t* temp = mem;
     710        uint32_t nrOfElements;
     711        loadAndIncrease(nrOfElements, mem);
     712        if( variable.size() == nrOfElements )
     713        {
     714            T tempT;
     715            for( uint32_t i=0; i<nrOfElements; ++i )
     716            {
     717                loadAndIncrease(tempT, mem);
     718                if( variable.find(tempT) == variable.end() )
     719                {
     720                    mem = temp;
     721                    return false;
     722                }
     723            }
     724        }
     725        else
     726        {
     727            mem = temp;
     728            return false;
     729        }
     730        return true;
     731    }
    637732}
    638733
  • code/trunk/src/libraries/util/SignalHandler.cc

    r5738 r7163  
    124124      if( SignalHandler::singletonPtr_s == 0 )
    125125      {
    126         COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl;
     126        COUT(0) << "received signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl;
    127127        exit(EXIT_FAILURE);
    128128      }
     
    134134
    135135
    136       COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "try to write backtrace to file orxonox_crash.log" << std::endl;
     136      COUT(0) << "received signal " << sigName.c_str() << std::endl << "try to write backtrace to file orxonox_crash.log" << std::endl;
    137137
    138138      int sigPipe[2];
  • code/trunk/src/libraries/util/Singleton.h

    r6751 r7163  
    3131
    3232#include "UtilPrereqs.h"
     33
    3334#include <cassert>
     35#include <cstring>
    3436
    3537namespace orxonox
  • code/trunk/src/modules/CMakeLists.txt

    r6524 r7163  
    3333ADD_SUBDIRECTORY(questsystem)
    3434ADD_SUBDIRECTORY(weapons)
     35ADD_SUBDIRECTORY(designtools)
  • code/trunk/src/modules/objects/CMakeLists.txt

    r5781 r7163  
    1515  PCH_FILE
    1616    ObjectsPrecompiledHeaders.h
    17   DEFINE_SYMBOL
    18     "OBJECTS_SHARED_BUILD"
    1917  LINK_LIBRARIES
    2018    orxonox
  • code/trunk/src/modules/objects/ObjectsPrereqs.h

    r6906 r7163  
    4343//-----------------------------------------------------------------------
    4444
    45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
     45#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(OBJECTS_STATIC_BUILD)
    4646#  ifdef OBJECTS_SHARED_BUILD
    4747#    define _ObjectsExport __declspec(dllexport)
  • code/trunk/src/modules/objects/Planet.cc

    r6501 r7163  
    7070        {
    7171            Camera* activeCamera = CameraManager::getInstance().getActiveCamera();
    72             if (activeCamera)
     72            if (activeCamera && this->billboard_.getBillboardSet())
    7373            {
    7474                float distance = this->getPosition().distance( activeCamera->getWorldPosition() );
     
    8989    void Planet::init()
    9090    {
    91         float scaleFactor = this->getScale();
    92 
    93 #if OGRE_VERSION >= 0x010700
    94         Ogre::Mesh::LodValueList distList;
    95 #else
    96         Ogre::Mesh::LodDistanceList distList;
    97 #endif
    98 
    99         distList.push_back(10.0f*scaleFactor);
    100         distList.push_back(19.0f*scaleFactor);
    101         distList.push_back(27.0f*scaleFactor);
    102         distList.push_back(34.0f*scaleFactor);
    103         distList.push_back(40.0f*scaleFactor);
    104         distList.push_back(45.0f*scaleFactor);
    105         distList.push_back(49.0f*scaleFactor);
    106         distList.push_back(52.0f*scaleFactor);
    107         distList.push_back(54.0f*scaleFactor);
    108         distList.push_back(55.0f*scaleFactor);
    109 
    110         float reductionValue = 0.2f;
    111 
    112         this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
    113         billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
    114 
    115         this->attachOgreObject(this->billboard_.getBillboardSet());
    116         this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
    117         this->setCastShadows(true);
    118         this->billboard_.getBillboardSet()->setRenderQueueGroup(this->mesh_.getEntity()->getRenderQueueGroup());
    119         this->mesh_.setCastShadows(true);
    12091    }
    12192
    12293    void Planet::changedMesh()
    12394    {
    124         if (this->mesh_.getEntity())
    125             this->detachOgreObject(this->mesh_.getEntity());
     95        if( GameMode::showsGraphics() )
     96        {
     97            if (this->mesh_.getEntity())
     98                this->detachOgreObject(this->mesh_.getEntity());
    12699
    127         this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
     100            this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
    128101
    129         if (this->mesh_.getEntity())
    130         {
    131             this->attachOgreObject(this->mesh_.getEntity());
    132             this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
    133             this->mesh_.setVisible(this->isVisible());
     102            if (this->mesh_.getEntity())
     103            {
     104                this->attachOgreObject(this->mesh_.getEntity());
     105                this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
     106                this->mesh_.setVisible(this->isVisible());
     107
     108                float scaleFactor = this->getScale();
     109
     110    #if OGRE_VERSION >= 0x010700
     111                Ogre::Mesh::LodValueList distList;
     112    #else
     113                Ogre::Mesh::LodDistanceList distList;
     114    #endif
     115
     116                distList.push_back(10.0f*scaleFactor);
     117                distList.push_back(19.0f*scaleFactor);
     118                distList.push_back(27.0f*scaleFactor);
     119                distList.push_back(34.0f*scaleFactor);
     120                distList.push_back(40.0f*scaleFactor);
     121                distList.push_back(45.0f*scaleFactor);
     122                distList.push_back(49.0f*scaleFactor);
     123                distList.push_back(52.0f*scaleFactor);
     124                distList.push_back(54.0f*scaleFactor);
     125                distList.push_back(55.0f*scaleFactor);
     126
     127                float reductionValue = 0.2f;
     128
     129                this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
     130                billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
     131
     132                this->attachOgreObject(this->billboard_.getBillboardSet());
     133                this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
     134                this->setCastShadows(true);
     135                this->billboard_.getBillboardSet()->setRenderQueueGroup(this->mesh_.getEntity()->getRenderQueueGroup());
     136                this->mesh_.setCastShadows(true);
     137            }
    134138        }
    135         this->init();
    136139    }
    137140
     
    151154        SUPER(Planet, XMLPort, xmlelement, mode);
    152155
    153         if (GameMode::showsGraphics())
    154         {
    155             XMLPortParam(Planet, "atmosphere", setAtmosphere, getAtmosphere, xmlelement, mode).defaultValues("planet/Atmosphere");
    156             XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode);
    157             XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode);
    158             XMLPortParam(Planet, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
    159             XMLPortParam(Planet, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
    160         }
     156        XMLPortParam(Planet, "atmosphere", setAtmosphere, getAtmosphere, xmlelement, mode).defaultValues("planet/Atmosphere");
     157        XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode);
     158        XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode);
     159        XMLPortParam(Planet, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
     160        XMLPortParam(Planet, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
    161161    }
    162162
     
    164164    {
    165165        registerVariable(this->atmosphere_, VariableDirection::ToClient);
     166        registerVariable(this->atmosphereSize, VariableDirection::ToClient);
     167        registerVariable(this->imageSize, VariableDirection::ToClient);
     168        // Note: the meshSrc should be synchronised after atmosphere and other values, because the meshSrc callback setts the atmosphere billboards
    166169        registerVariable(this->meshSrc_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedMesh));
    167170        registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedShadows));
    168         registerVariable(this->atmosphereSize, VariableDirection::ToClient);
    169         registerVariable(this->imageSize, VariableDirection::ToClient);
    170171    }
    171172
  • code/trunk/src/modules/objects/Planet.h

    r6501 r7163  
    9494
    9595        protected:
    96             void registerVariables();
    9796
    9897        private:
     98            void registerVariables();
    9999
    100100            void changedMesh();
  • code/trunk/src/modules/objects/collisionshapes/BoxCollisionShape.h

    r5781 r7163  
    4343            virtual ~BoxCollisionShape();
    4444
    45             void registerVariables();
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4746
     
    6766
    6867        private:
     68            void registerVariables();
     69
    6970            btCollisionShape* createNewShape() const;
    7071
  • code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h

    r5781 r7163  
    4141            virtual ~ConeCollisionShape();
    4242
    43             void registerVariables();
    4443            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4544
     
    5554
    5655        private:
     56            void registerVariables();
     57
    5758            btCollisionShape* createNewShape() const;
    5859
  • code/trunk/src/modules/objects/collisionshapes/PlaneCollisionShape.h

    r5781 r7163  
    4343            virtual ~PlaneCollisionShape();
    4444
    45             void registerVariables();
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4746
     
    5756
    5857        private:
     58            void registerVariables();
     59
    5960            btCollisionShape* createNewShape()const;
    6061
  • code/trunk/src/modules/objects/collisionshapes/SphereCollisionShape.h

    r5781 r7163  
    4141            virtual ~SphereCollisionShape();
    4242
    43             void registerVariables();
    4443            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4544
     
    5049
    5150        private:
     51            void registerVariables();
     52
    5253            btCollisionShape* createNewShape() const;
    5354
  • code/trunk/src/modules/objects/eventsystem/EventListener.cc

    r6856 r7163  
    6161            return;
    6262        }
    63        
     63
    6464        COUT(4) << "EventListener, processing event: originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << ")" << ", activate: " << event.activate_ << ", name: " << event.name_ << std::endl;
    6565
  • code/trunk/src/modules/objects/triggers/CheckPoint.cc

    r5929 r7163  
    3838    CreateFactory(CheckPoint);
    3939
    40     CheckPoint::CheckPoint(BaseObject* creator) : DistanceTrigger(creator)
     40    CheckPoint::CheckPoint(BaseObject* creator)
     41        : DistanceTrigger(creator)
     42        , RadarViewable(creator, static_cast<WorldEntity*>(this))
    4143    {
    4244        RegisterObject(CheckPoint);
  • code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc

    • Property svn:eol-style set to native
    r6906 r7163  
    4040namespace orxonox
    4141{
    42    
     42
    4343    CreateFactory(DistanceMultiTrigger);
    4444
    4545    /**
    4646    @brief
    47         Default Constructor. Registers the object and initializes default values. 
     47        Default Constructor. Registers the object and initializes default values.
    4848    */
    4949    DistanceMultiTrigger::DistanceMultiTrigger(BaseObject* creator) : MultiTrigger(creator)
    5050    {
    5151        RegisterObject(DistanceMultiTrigger);
    52        
     52
    5353        this->distance_ = 100.0f;
    5454        this->targetName_ = BLANKSTRING;
     
    9898                continue;
    9999            }
    100            
     100
    101101            Vector3 distanceVec = entity->getWorldPosition() - this->getWorldPosition();
    102102            // If the object is no longer in range.
     
    154154                if(this->singleTargetMode_)
    155155                    entity = entity->getParent();
    156                
     156
    157157                // If no queue has been created, yet.
    158158                if(queue == NULL)
     
    166166            }
    167167        }
    168        
     168
    169169        return queue;
    170170    }
    171    
     171
    172172}
  • code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h

    • Property svn:eol-style set to native
    r6906 r7163  
    5656    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
    5757    {
    58        
     58
    5959        public:
    6060            DistanceMultiTrigger(BaseObject* creator); //!< Default Constructor. Registers the object and initializes default values.
    6161            ~DistanceMultiTrigger(); //!< Destructor.
    62            
     62
    6363            void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a DistanceMultiTrigger object through XML.
    6464
     
    7575            inline const std::string& getTargetName(void)
    7676                { return this->targetName_; }
    77            
     77
    7878            /**
    7979            @brief Set the distance at which the DistanceMultiTrigger triggers.
     
    8888            inline float getDistance() const
    8989                { return this->distance_; }
    90                
     90
    9191        protected:
    9292            virtual std::queue<MultiTriggerState*>* letTrigger(void); //!< This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
     
    106106            inline bool removeFromRange(WorldEntity* entity)
    107107                { WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second; bool erased = this->range_.erase(entity) > 0; if(erased) delete weakptr; return erased; }
    108                
     108
    109109        private:
    110110            float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
    111111            std::string targetName_; //!< The target name, used in singleTargetMode.
    112112            bool singleTargetMode_; //!< To indicate whe the MultiDistanceTrigger is in single-target-mode.
    113            
     113
    114114            std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
    115        
     115
    116116    };
    117    
     117
    118118}
    119119
  • code/trunk/src/modules/objects/triggers/DistanceTrigger.cc

    r6906 r7163  
    136136          continue;
    137137      }
    138      
     138
    139139      Vector3 distanceVec = entity->getWorldPosition() - this->getWorldPosition();
    140140      if (distanceVec.length() < this->distance_)
     
    155155      }
    156156    }
     157
    157158    return false;
    158159  }
  • code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc

    • Property svn:eol-style set to native
    r6906 r7163  
    3535
    3636    CreateFactory(DistanceTriggerBeacon);
    37    
     37
    3838    DistanceTriggerBeacon::DistanceTriggerBeacon(BaseObject* creator) : StaticEntity(creator)
    3939    {
    4040        RegisterObject(DistanceTriggerBeacon);
    4141    }
    42    
     42
    4343}
  • code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h

    • Property svn:eol-style set to native
    r6906 r7163  
    3939    class _ObjectsExport DistanceTriggerBeacon : public StaticEntity
    4040    {
    41        
     41
    4242        public:
    4343
  • code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc

    • Property svn:eol-style set to native
    r6864 r7163  
    5252    EventMultiTrigger::~EventMultiTrigger()
    5353    {
    54        
     54
    5555    }
    5656
     
    6161        this->setBroadcast(true);
    6262    }
    63    
     63
    6464    void EventMultiTrigger::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
    6565    {
  • code/trunk/src/modules/objects/triggers/EventMultiTrigger.h

    • Property svn:eol-style set to native
    r6864 r7163  
    4444    class _ObjectsExport EventMultiTrigger : public MultiTrigger
    4545    {
    46        
     46
    4747        public:
    4848            EventMultiTrigger(BaseObject* creator);
  • code/trunk/src/modules/objects/triggers/MultiTrigger.cc

    • Property svn:eol-style set to native
    r6864 r7163  
    4747    /*static*/ const std::string MultiTrigger::or_s = "or";
    4848    /*static*/ const std::string MultiTrigger::xor_s = "xor";
    49    
     49
    5050    CreateFactory(MultiTrigger);
    5151
     
    6565        this->bSwitch_ = false;
    6666        this->bStayActive_ = false;
    67        
     67
    6868        this->remainingActivations_ = INF_s;
    6969        this->maxNumSimultaniousTriggerers_ = INF_s;
     
    7575
    7676        this->parentTrigger_ = NULL;
    77        
     77
    7878        this->targetMask_.exclude(Class(BaseObject));
    7979
    8080        this->setSyncMode(0x0);
    8181    }
    82    
     82
    8383    /**
    8484    @brief
     
    9595        }
    9696    }
    97    
     97
    9898    /**
    9999    @brief
     
    117117        //TODO: Maybe nicer with explicit subgroup, e.g. triggers
    118118        XMLPortObject(MultiTrigger, MultiTrigger, "", addTrigger, getTrigger, xmlelement, mode);
    119        
     119
    120120        COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") created." << std::endl;
    121121    }
    122    
     122
    123123
    124124    /**
     
    131131    {
    132132        // If this is the first tick.
    133         //TODO: Determine need for this, else kick it out. 
     133        //TODO: Determine need for this, else kick it out.
    134134        if(this->bFirstTick_)
    135135        {
     
    174174                    delete state;
    175175                }
    176                
     176
    177177                queue->pop();
    178178            }
     
    185185            MultiTriggerState* state;
    186186            float timeRemaining;
    187            
     187
    188188            // Go through all pending states.
    189189            for(int size = this->stateQueue_.size(); size >= 1; size--)
     
    212212                                this->triggered_.erase(state->originator);
    213213                            }
    214                            
     214
    215215                            bStateChanged = true;
    216216                        }
     
    229229
    230230                            bool bFire = true;
    231                            
     231
    232232                            // Add the originator to the objects activating this MultiTrigger.
    233233                            if(bActive == true)
     
    266266                                else
    267267                                    this->fire(bActive, state->originator);
    268                                
     268
    269269                                bStateChanged = true;
    270270                            }
     
    289289                        }
    290290                    }
    291                    
     291
    292292                    // Remove the state from the state queue.
    293293                    this->stateQueue_.pop_front();
     
    509509            return returnVal;
    510510        }
    511        
     511
    512512        return true;
    513513    }
    514    
     514
    515515    /**
    516516    @brief
     
    547547            return;
    548548        }
    549        
     549
    550550        MultiTriggerContainer* container = new MultiTriggerContainer(this, this, originator);
    551551        this->fireEvent(status, container);
     
    563563    {
    564564        ClassTreeMask& targetMask = this->getTargetMask();
    565        
     565
    566566        for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it)
    567567        {
     
    580580    {
    581581        assert(state);
    582        
     582
    583583        // If the originator is no target of this MultiTrigger.
    584584        if(!this->isTarget(state->originator))
    585585            return false;
    586        
     586
    587587        // Add it ot the state queue.
    588588        this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(this->delay_, state));
  • code/trunk/src/modules/objects/triggers/MultiTrigger.h

    • Property svn:eol-style set to native
    r6864 r7163  
    9494            MultiTrigger(BaseObject* creator); //!< Constructor. Registers the objects and initializes default values.
    9595            ~MultiTrigger(); //!< Destructor.
    96            
     96
    9797            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a MultiTrigger object through XML.
    9898            virtual void tick(float dt); //!< A method that is executed each tick.
    99            
     99
    100100            bool isActive(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is active for a given object.
    101101
     
    215215            void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
    216216            void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
    217            
     217
    218218            void addTrigger(MultiTrigger* trigger); //!< Adds a MultiTrigger as a sub-trigger to the trigger.
    219219            const MultiTrigger* getTrigger(unsigned int index) const; //!< Get the sub-trigger of this MultiTrigger at the given index.
    220            
     220
    221221        protected:
    222222            virtual std::queue<MultiTriggerState*>* letTrigger(void); //!< This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
    223223
    224224            void changeTriggered(BaseObject* originator = NULL); //!< This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator.
    225            
     225
    226226            bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whetherx the MultiTrigger is triggered concerning it's sub-triggers.
    227227            bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object.
     
    236236            inline void addParentTrigger(MultiTrigger* parent)
    237237                { this->parentTrigger_ = parent; }
    238            
     238
    239239            /**
    240240            @brief Get the target mask used to identify the targets of this MultiTrigger.
     
    248248            //TODO: Check if something mus be done here.
    249249            virtual void notifyMaskUpdate(void) {}
    250            
     250
    251251        private:
    252252            static const int INF_s; //!< Magic number for infinity.
     
    257257
    258258            void subTrigggerActivityChanged(BaseObject* originator); //!< This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
    259            
     259
    260260            bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active.
    261            
     261
    262262            bool checkAnd(BaseObject* triggerer); //!< Checks whether the sub-triggers amount to true for the 'and' mode for a given object.
    263263            bool checkOr(BaseObject* triggerer); //!< Checks whether the sub-triggers amount to true for the 'or' mode for a given object.
     
    276276            bool bSwitch_; //!< Bool for the switch-mode, if true the MultiTrigger behaves like a switch.
    277277            bool bStayActive_; //!< Bool for the stay-active-mode, if true the MultiTrigger stays active after its last activation.;
    278            
     278
    279279            int remainingActivations_; //!< The remaining activations of this MultiTrigger.
    280280            int maxNumSimultaniousTriggerers_; //!< The maximum number of objects simultaniously trigggering this MultiTrigger.
     
    287287            MultiTrigger* parentTrigger_;
    288288            std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger.
    289            
     289
    290290            std::set<BaseObject*> active_; //!< The set of all objects the MultiTrigger is active for.
    291291            std::set<BaseObject*> triggered_; //!< The set of all objects the MultiTrigger is triggered for.
    292292
    293293            std::deque< std::pair<float, MultiTriggerState*> > stateQueue_; //!< The queue of states waiting to become active.
    294            
     294
    295295            ClassTreeMask targetMask_; //!< The target mask, masking all objects that can trigger this MultiTrigger.
    296            
     296
    297297    };
    298298
  • code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc

    • Property svn:eol-style set to native
    r6859 r7163  
    4040
    4141    CreateUnloadableFactory(MultiTriggerContainer);
    42    
     42
    4343    /**
    4444    @brief
     
    7373    MultiTriggerContainer::~MultiTriggerContainer()
    7474    {
    75        
     75
    7676    }
    7777
  • code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h

    • Property svn:eol-style set to native
    r6856 r7163  
    5050    class _ObjectsExport MultiTriggerContainer : public BaseObject
    5151    {
    52        
     52
    5353        public:
    5454            MultiTriggerContainer(BaseObject* creator); //!< Default constructor. Registers the object and creates an empty container.
     
    6868            inline BaseObject* getData(void)
    6969                { return this->data_; }
    70            
     70
    7171        private:
    7272            MultiTrigger* originator_; //!< The originator.
    7373            BaseObject* data_; //!< The data.
    7474    };
    75    
     75
    7676}
    7777
  • code/trunk/src/modules/overlays/CMakeLists.txt

    r5781 r7163  
    1414  PCH_FILE
    1515    OverlaysPrecompiledHeaders.h
    16   DEFINE_SYMBOL
    17     "OVERLAYS_SHARED_BUILD"
    1816  LINK_LIBRARIES
    1917    orxonox
  • code/trunk/src/modules/overlays/GUIOverlay.cc

    r6799 r7163  
    3030
    3131#include <string>
    32 #include <sstream>
    3332
     33#include "util/Convert.h"
    3434#include "core/input/InputManager.h"
    3535#include "core/CoreIncludes.h"
     
    7373        if (this->isVisible())
    7474        {
    75             std::ostringstream out;
    76             out << reinterpret_cast<long>(this);
    77             const std::string& str = out.str();
     75            const std::string& str = multi_cast<std::string>(reinterpret_cast<long>(this));
    7876            GUIManager::getInstance().showGUIExtra(this->guiName_, str);
    7977
  • code/trunk/src/modules/overlays/OverlaysPrereqs.h

    r5929 r7163  
    4343//-----------------------------------------------------------------------
    4444
    45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
     45#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(OVERLAYS_STATIC_BUILD)
    4646#  ifdef OVERLAYS_SHARED_BUILD
    4747#    define _OverlaysExport __declspec(dllexport)
     
    7878    class ChatOverlay;
    7979    class DeathMessage;
     80    class GametypeFadingMessage;
     81    class GametypeStaticMessage;
    8082    class GametypeStatus;
    8183    class HUDBar;
  • code/trunk/src/modules/overlays/hud/CMakeLists.txt

    r5781 r7163  
    1313  UnderAttackHealthBar.cc
    1414  TeamBaseMatchScore.cc
     15  GametypeStaticMessage.cc
     16  GametypeFadingMessage.cc
    1517)
  • code/trunk/src/modules/overlays/hud/GametypeStatus.cc

    r5781 r7163  
    3030
    3131#include "util/Convert.h"
     32#include "core/ConsoleCommand.h"
    3233#include "core/CoreIncludes.h"
    3334#include "infos/GametypeInfo.h"
     
    3940{
    4041    CreateFactory(GametypeStatus);
     42
     43    /*static*/ bool GametypeStatus::noCaption_s = false;
     44    SetConsoleCommand(GametypeStatus, setGametypeStatus, true);
    4145
    4246    GametypeStatus::GametypeStatus(BaseObject* creator) : OverlayText(creator)
     
    5963            const GametypeInfo* gtinfo = this->owner_->getGametypeInfo();
    6064            ControllableEntity* ce = this->owner_->getControllableEntity();
     65
     66            if(GametypeStatus::noCaption_s) // No captions are displayed.
     67            {
     68                this->setCaption("");
     69                return;
     70            }
    6171
    6272            if (!gtinfo->hasStarted() && !gtinfo->isStartCountdownRunning())
     
    8898        this->owner_ = orxonox_cast<PlayerInfo*>(this->getOwner());
    8999    }
     100
     101    /**
     102    @brief
     103        Sets whether the gametype status is displayed.
     104    @param bValue
     105        If true captions are displayed, if false, not.
     106    */
     107    /*static*/ void GametypeStatus::setGametypeStatus(bool bValue)
     108    {
     109        GametypeStatus::noCaption_s = !bValue;
     110    }
     111
    90112}
  • code/trunk/src/modules/overlays/hud/GametypeStatus.h

    r5781 r7163  
    4646            virtual void changedOwner();
    4747
     48            static void setGametypeStatus(bool bValue); //!< Toggles whether the gametype status is displayed.
     49
    4850        private:
    4951            PlayerInfo* owner_;
     52            static bool noCaption_s;
     53
    5054    };
    5155}
  • code/trunk/src/modules/overlays/hud/HUDNavigation.cc

    r6502 r7163  
    2929#include "HUDNavigation.h"
    3030
    31 #include <string>
    3231#include <OgreCamera.h>
     32#include <OgreFontManager.h>
    3333#include <OgreOverlayManager.h>
    3434#include <OgreTextAreaOverlayElement.h>
     
    4545#include "controllers/HumanController.h"
    4646#include "worldentities/pawns/Pawn.h"
     47#include "worldentities/WorldEntity.h"
     48#include "core/ConfigValueIncludes.h"
     49#include "tools/TextureGenerator.h"
     50// #include <boost/bind/bind_template.hpp>
     51
    4752
    4853namespace orxonox
    4954{
    50     CreateFactory(HUDNavigation);
    51 
    52     HUDNavigation::HUDNavigation(BaseObject* creator)
    53         : OrxonoxOverlay(creator)
    54     {
    55         RegisterObject(HUDNavigation);
    56 
    57         // create nav text
    58         navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
    59             .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
    60 
    61         // create nav marker
    62         navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    63             .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
    64         navMarker_->setMaterialName("Orxonox/NavArrows");
    65 
    66 /*
    67         // create aim marker
    68         aimMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    69             .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberString()));
    70         aimMarker_->setMaterialName("Orxonox/NavCrosshair");
    71         this->wasOutOfView_ = true; // Ensure the material is changed right the first time..
    72 
    73         setFont("Monofur");
    74         setTextSize(0.05f);
    75         setNavMarkerSize(0.05f);
    76         setAimMarkerSize(0.04f);
    77 */
    78 
    79         background_->addChild(navMarker_);
    80 //        background_->addChild(aimMarker_);
    81         background_->addChild(navText_);
    82 
    83         // hide at first
    84         this->setVisible(false);
    85     }
    86 
    87     HUDNavigation::~HUDNavigation()
    88     {
    89         if (this->isInitialized())
     55bool compareDistance ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b )
     56{
     57    return a.second<b.second;
     58
     59}
     60
     61void HUDNavigation::setConfigValues()
     62{
     63  SetConfigValue(markerLimit_, 3);
     64}
     65
     66CreateFactory ( HUDNavigation );
     67
     68HUDNavigation::HUDNavigation ( BaseObject* creator )
     69        : OrxonoxOverlay ( creator )
     70{
     71    RegisterObject ( HUDNavigation );
     72    this->setConfigValues();
     73
     74    // Set default values
     75    setFont ( "Monofur" );
     76    setTextSize ( 0.05f );
     77    setNavMarkerSize ( 0.05f );
     78}
     79
     80HUDNavigation::~HUDNavigation()
     81{
     82    if ( this->isInitialized() )
     83    {
     84        for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); )
     85            removeObject ( ( it++ )->first );
     86
     87    }
     88
     89    sortedObjectList_.clear();
     90}
     91
     92void HUDNavigation::XMLPort ( Element& xmlElement, XMLPort::Mode mode )
     93{
     94    SUPER ( HUDNavigation, XMLPort, xmlElement, mode );
     95
     96    XMLPortParam ( HUDNavigation, "font",          setFont,          getFont,          xmlElement, mode );
     97    XMLPortParam ( HUDNavigation, "textSize",      setTextSize,      getTextSize,      xmlElement, mode );
     98    XMLPortParam ( HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode );
     99}
     100
     101void HUDNavigation::setFont ( const std::string& font )
     102{
     103    const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName ( font );
     104    if ( fontPtr.isNull() )
     105    {
     106        COUT ( 2 ) << "Warning: HUDNavigation: Font '" << font << "' not found" << std::endl;
     107        return;
     108    }
     109    fontName_ = font;
     110    for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it )
     111    {
     112        if ( it->second.text_ != NULL )
     113            it->second.text_->setFontName ( fontName_ );
     114    }
     115}
     116
     117const std::string& HUDNavigation::getFont() const
     118{
     119    return fontName_;
     120}
     121
     122void HUDNavigation::setTextSize ( float size )
     123{
     124    if ( size <= 0.0f )
     125    {
     126        COUT ( 2 ) << "Warning: HUDNavigation: Negative font size not allowed" << std::endl;
     127        return;
     128    }
     129    textSize_ = size;
     130    for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )
     131    {
     132        if ( it->second.text_ )
     133            it->second.text_->setCharHeight ( size );
     134    }
     135}
     136
     137float HUDNavigation::getTextSize() const
     138{
     139    return textSize_;
     140}
     141
     142
     143
     144void HUDNavigation::tick ( float dt )
     145{
     146    SUPER ( HUDNavigation, tick, dt );
     147
     148    Camera* cam = CameraManager::getInstance().getActiveCamera();
     149    if ( cam == NULL )
     150        return;
     151    const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
     152
     153
     154    for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
     155    {
     156        listIt->second = ( int ) ( ( listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition() ).length() + 0.5f );
     157    }
     158
     159    sortedObjectList_.sort ( compareDistance );
     160
     161    unsigned int markerCount_ = 0;
     162
     163//         for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it)
     164    for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt )
     165    {
     166        ObjectMap::iterator it = activeObjectList_.find ( listIt->first );
     167
     168        if ( markerCount_ < markerLimit_ )
    90169        {
    91             Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->navMarker_);
    92             Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->navText_);
    93 //            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->aimMarker_);
    94         }
    95     }
    96 
    97     void HUDNavigation::XMLPort(Element& xmlElement, XMLPort::Mode mode)
    98     {
    99         SUPER(HUDNavigation, XMLPort, xmlElement, mode);
    100 
    101         XMLPortParam(HUDNavigation, "font",     setFont,     getFont,     xmlElement, mode);
    102         XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlElement, mode);
    103         XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode);
    104 //        XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode);
    105     }
    106 
    107     void HUDNavigation::setFont(const std::string& font)
    108     {
    109         if (this->navText_ && !font.empty())
    110             this->navText_->setFontName(font);
    111     }
    112 
    113     const std::string& HUDNavigation::getFont() const
    114     {
    115         if (this->navText_)
    116             return this->navText_->getFontName();
    117         else
    118             return BLANKSTRING;
    119     }
    120 
    121     void HUDNavigation::setTextSize(float size)
    122     {
    123         if (this->navText_ && size >= 0.0f)
    124             this->navText_->setCharHeight(size);
    125     }
    126 
    127     float HUDNavigation::getTextSize() const
    128     {
    129         if (this->navText_)
    130             return this->navText_->getCharHeight();
    131         else
    132             return 0.0f;
    133     }
    134 
    135     void HUDNavigation::tick(float dt)
    136     {
    137         SUPER(HUDNavigation, tick, dt);
    138 
    139         // Get radar
    140         Radar* radar = this->getOwner()->getScene()->getRadar();
    141 
    142         if (!radar->getFocus())
    143         {
    144             this->overlay_->hide();
    145             return;
    146         }
    147         else
    148         {
    149             this->overlay_->show();
    150         }
    151 
    152         // set text
    153         int dist = static_cast<int>(getDist2Focus());
    154         navText_->setCaption(multi_cast<std::string>(dist));
    155         float textLength = multi_cast<std::string>(dist).size() * navText_->getCharHeight() * 0.3f;
    156 
    157         orxonox::Camera* cam = CameraManager::getInstance().getActiveCamera();
    158         if (!cam)
    159             return;
    160         const Matrix4& transform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
    161         // transform to screen coordinates
    162         Vector3 pos = transform * radar->getFocus()->getRVWorldPosition();
    163 
    164         bool outOfView;
    165         if (pos.z > 1.0)
    166         {
    167             // z > 1.0 means that the object is behind the camera
    168             outOfView = true;
    169             // we have to switch all coordinates (if you don't know why,
    170             // try linear algebra lectures, because I can't explain..)
    171             pos.x = -pos.x;
    172             pos.y = -pos.y;
    173         }
    174         else
    175             outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
    176 
    177         if (outOfView)
    178         {
    179             // object is not in view
    180 //            aimMarker_->hide();
    181 
    182             if (!wasOutOfView_)
     170
     171
     172            // Get Distance to HumanController and save it in the TextAreaOverlayElement.
     173            int dist = listIt->second;
     174            it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
     175            float textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f;
     176
     177            // Transform to screen coordinates
     178            Vector3 pos = camTransform * it->first->getRVWorldPosition();
     179
     180            bool outOfView = true;
     181            if ( pos.z > 1.0 )
    183182            {
    184                 navMarker_->setMaterialName("Orxonox/NavArrows");
    185                 wasOutOfView_ = true;
     183                // z > 1.0 means that the object is behind the camera
     184                outOfView = true;
     185                // we have to switch all coordinates (if you don't know why,
     186                // try linear algebra lectures, because I can't explain..)
     187                pos.x = -pos.x;
     188                pos.y = -pos.y;
    186189            }
    187 
    188             if (pos.x < pos.y)
     190            else
     191                outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
     192            // Get Distance to HumanController and save it in the TextAreaOverlayElement.
     193            it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
     194
     195            if ( outOfView )
    189196            {
    190                 if (pos.y > -pos.x)
     197                // Object is not in view
     198
     199                // Change material only if outOfView changed
     200                if ( !it->second.wasOutOfView_ )
    191201                {
    192                     // up
    193                     float position = pos.x / pos.y + 1.0f;
    194                     navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 0.0f);
    195                     navMarker_->setUV(0.5f, 0.0f, 1.0f, 0.5f);
    196                     navText_->setLeft((position - textLength) * 0.5f);
    197                     navText_->setTop(navMarker_->getHeight());
     202                    it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "arrows.tga", it->first->getRadarObjectColour()) );
     203                    it->second.wasOutOfView_ = true;
    198204                }
     205
     206                // Switch between top, bottom, left and right position of the arrow at the screen border
     207                if ( pos.x < pos.y )
     208                {
     209                    if ( pos.y > -pos.x )
     210                    {
     211                        // Top
     212                        float position = pos.x / pos.y + 1.0f;
     213                        it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 0.0f );
     214                        it->second.panel_->setUV ( 0.5f, 0.0f, 1.0f, 0.5f );
     215                        it->second.text_->setLeft ( ( position - textLength ) * 0.5f );
     216                        it->second.text_->setTop ( it->second.panel_->getHeight() );
     217                    }
     218                    else
     219                    {
     220                        // Left
     221                        float position = pos.y / pos.x + 1.0f;
     222                        it->second.panel_->setPosition ( 0.0f, ( position - it->second.panel_->getWidth() ) * 0.5f );
     223                        it->second.panel_->setUV ( 0.0f, 0.0f, 0.5f, 0.5f );
     224                        it->second.text_->setLeft ( it->second.panel_->getWidth() + 0.01f );
     225                        it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f );
     226                    }
     227                }
     228
    199229                else
    200230                {
    201                     // left
    202                     float position = pos.y / pos.x + 1.0f;
    203                     navMarker_->setPosition(0.0f, (position - navMarker_->getWidth()) * 0.5f);
    204                     navMarker_->setUV(0.0f, 0.0f, 0.5f, 0.5f);
    205                     navText_->setLeft(navMarker_->getWidth() + 0.01f);
    206                     navText_->setTop((position - navText_->getCharHeight()) * 0.5f);
     231
     232                    if ( pos.y < -pos.x )
     233                    {
     234                        // Bottom
     235                        float position = -pos.x / pos.y + 1.0f;
     236                        it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 1.0f - it->second.panel_->getHeight() );
     237                        it->second.panel_->setUV ( 0.0f, 0.5f, 0.5f, 1.0f );
     238                        it->second.text_->setLeft ( ( position - textLength ) * 0.5f );
     239                        it->second.text_->setTop ( 1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight() );
     240                    }
     241                    else
     242                    {
     243                        // Right
     244                        float position = -pos.y / pos.x + 1.0f;
     245                        it->second.panel_->setPosition ( 1.0f - it->second.panel_->getWidth(), ( position - it->second.panel_->getHeight() ) * 0.5f );
     246                        it->second.panel_->setUV ( 0.5f, 0.5f, 1.0f, 1.0f );
     247                        it->second.text_->setLeft ( 1.0f - it->second.panel_->getWidth() - textLength - 0.01f );
     248                        it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f );
     249                    }
    207250                }
    208251            }
    209252            else
    210253            {
    211                 if (pos.y < -pos.x)
     254                // Object is in view
     255
     256                // Change material only if outOfView changed
     257                if ( it->second.wasOutOfView_ )
    212258                {
    213                     // down
    214                     float position = -pos.x / pos.y + 1.0f;
    215                     navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 1.0f - navMarker_->getHeight());
    216                     navMarker_->setUV(0.0f, 0.5f, 0.5f, 1.0f);
    217                     navText_->setLeft((position - textLength) * 0.5f);
    218                     navText_->setTop(1.0f - navMarker_->getHeight() - navText_->getCharHeight());
     259                  //it->second.panel_->setMaterialName ( "Orxonox/NavTDC" );
     260                    it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "tdc.tga", it->first->getRadarObjectColour()) );
     261                    it->second.wasOutOfView_ = false;
    219262                }
    220                 else
    221                 {
    222                     // right
    223                     float position = -pos.y / pos.x + 1.0f;
    224                     navMarker_->setPosition(1.0f - navMarker_->getWidth(), (position - navMarker_->getHeight()) * 0.5f);
    225                     navMarker_->setUV(0.5f, 0.5f, 1.0f, 1.0f);
    226                     navText_->setLeft(1.0f - navMarker_->getWidth() - textLength - 0.01f);
    227                     navText_->setTop((position - navText_->getCharHeight()) * 0.5f);
    228                 }
     263
     264                // Position marker
     265                it->second.panel_->setUV ( 0.0f, 0.0f, 1.0f, 1.0f );
     266                it->second.panel_->setLeft ( ( pos.x + 1.0f - it->second.panel_->getWidth() ) * 0.5f );
     267                it->second.panel_->setTop ( ( -pos.y + 1.0f - it->second.panel_->getHeight() ) * 0.5f );
     268
     269                // Position text
     270                it->second.text_->setLeft ( ( pos.x + 1.0f + it->second.panel_->getWidth() ) * 0.5f );
     271                it->second.text_->setTop ( ( -pos.y + 1.0f + it->second.panel_->getHeight() ) * 0.5f );
    229272            }
     273
     274            // Make sure the overlays are shown
     275            it->second.panel_->show();
     276            it->second.text_->show();
    230277        }
    231278        else
    232279        {
    233             // object is in view
    234 /*
    235             Vector3 aimpos = transform * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(),
    236                     Projectile::getSpeed(), Radar::getInstance().getFocus()->getRVWorldPosition(), Radar::getInstance().getFocus()->getRVOrientedVelocity());
     280            it->second.panel_->hide();
     281            it->second.text_->hide();
     282        }
     283
     284    }
     285}
     286
     287
     288/** Overridden method of OrxonoxOverlay.
     289@details
     290    Usually the entire overlay scales with scale().
     291    Here we obviously have to adjust this.
    237292*/
    238             if (wasOutOfView_)
    239             {
    240                 navMarker_->setMaterialName("Orxonox/NavTDC");
    241                 wasOutOfView_ = false;
    242             }
    243 
    244             // object is in view
    245             navMarker_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
    246             navMarker_->setLeft((pos.x + 1.0f - navMarker_->getWidth()) * 0.5f);
    247             navMarker_->setTop((-pos.y + 1.0f - navMarker_->getHeight()) * 0.5f);
    248 
    249 /*
    250             aimMarker_->show();
    251             aimMarker_->setLeft((aimpos.x + 1.0f - aimMarker_->getWidth()) * 0.5f);
    252             aimMarker_->setTop((-aimpos.y + 1.0f - aimMarker_->getHeight()) * 0.5f);
    253 */
    254             navText_->setLeft((pos.x + 1.0f + navMarker_->getWidth()) * 0.5f);
    255             navText_->setTop((-pos.y + 1.0f + navMarker_->getHeight()) * 0.5f);
     293void HUDNavigation::sizeChanged()
     294{
     295    // Use size to compensate for aspect ratio if enabled.
     296    float xScale = this->getActualSize().x;
     297    float yScale = this->getActualSize().y;
     298
     299    for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )
     300    {
     301        if ( it->second.panel_ != NULL )
     302            it->second.panel_->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );
     303        if ( it->second.text_ != NULL )
     304            it->second.text_->setCharHeight ( it->second.text_->getCharHeight() * yScale );
     305    }
     306}
     307
     308void HUDNavigation::addObject ( RadarViewable* object )
     309{
     310    if( showObject(object)==false )
     311        return;
     312
     313    if ( activeObjectList_.size() >= markerLimit_ )
     314        if ( object == NULL )
     315            return;
     316
     317    // Object hasn't been added yet (we know that)
     318    assert ( this->activeObjectList_.find ( object ) == this->activeObjectList_.end() );
     319
     320    // Scales used for dimensions and text size
     321    float xScale = this->getActualSize().x;
     322    float yScale = this->getActualSize().y;
     323
     324    // Create everything needed to display the object on the radar and add it to the map
     325
     326    // Create arrow/marker
     327    Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*> ( Ogre::OverlayManager::getSingleton()
     328                                       .createOverlayElement ( "Panel", "HUDNavigation_navMarker_" + getUniqueNumberString() ) );
     329//     panel->setMaterialName ( "Orxonox/NavTDC" );
     330    panel->setMaterialName( TextureGenerator::getMaterialName( "tdc.tga", object->getRadarObjectColour()) );
     331    panel->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );
     332//     panel->setColour( object->getRadarObjectColour() );
     333
     334    Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*> ( Ogre::OverlayManager::getSingleton()
     335                                         .createOverlayElement ( "TextArea", "HUDNavigation_navText_" + getUniqueNumberString() ) );
     336    text->setFontName ( this->fontName_ );
     337    text->setCharHeight ( text->getCharHeight() * yScale );
     338    text->setColour( object->getRadarObjectColour() );
     339
     340    panel->hide();
     341    text->hide();
     342
     343    ObjectInfo tempStruct = {panel, text, false};
     344    activeObjectList_[object] = tempStruct;
     345
     346    this->background_->addChild ( panel );
     347    this->background_->addChild ( text );
     348
     349    sortedObjectList_.push_front ( std::make_pair ( object, ( unsigned int ) 0 ) );
     350
     351
     352}
     353
     354void HUDNavigation::removeObject ( RadarViewable* viewable )
     355{
     356    ObjectMap::iterator it = activeObjectList_.find ( viewable );
     357
     358    if ( activeObjectList_.find ( viewable ) != activeObjectList_.end() )
     359    {
     360        // Detach overlays
     361        this->background_->removeChild ( it->second.panel_->getName() );
     362        this->background_->removeChild ( it->second.text_->getName() );
     363        // Properly destroy the overlay elements (do not use delete!)
     364        Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.panel_ );
     365        Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.text_ );
     366        // Remove from the list
     367        activeObjectList_.erase ( viewable );
     368
     369
     370    }
     371
     372    for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
     373    {
     374        if ( (listIt->first) == viewable )
     375        {
     376            sortedObjectList_.erase ( listIt );
     377            break;
    256378        }
    257     }
    258 
    259     float HUDNavigation::getDist2Focus() const
    260     {
    261         Radar* radar = this->getOwner()->getScene()->getRadar();
    262         if (radar->getFocus() && HumanController::getLocalControllerEntityAsPawn())
    263             return (radar->getFocus()->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length();
    264         else
    265             return 0;
    266     }
    267 
    268     /**
    269     @brief Overridden method of OrxonoxOverlay. Usually the entire overlay
    270            scales with scale(). Here we obviously have to adjust this.
    271     */
    272     void HUDNavigation::sizeChanged()
    273     {
    274         // use size to compensate for aspect ratio if enabled.
    275         float xScale = this->getActualSize().x;
    276         float yScale = this->getActualSize().y;
    277         if (this->navMarker_)
    278             navMarker_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale);
    279 /*
    280         if (this->aimMarker_)
    281             aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale);
    282 */
    283         if (this->navText_)
    284             navText_->setCharHeight(navText_->getCharHeight() * yScale);
    285     }
    286 }
     379
     380    }
     381
     382}
     383
     384void HUDNavigation::objectChanged(RadarViewable* viewable)
     385{
     386    // TODO: niceification neccessary ;)
     387    removeObject(viewable);
     388    addObject(viewable);
     389}
     390
     391
     392bool HUDNavigation::showObject(RadarViewable* rv)
     393{
     394    if ( rv == dynamic_cast<RadarViewable*> ( this->getOwner() ) )
     395        return false;
     396    assert( rv->getWorldEntity() );
     397    if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false )
     398        return false;
     399    return true;
     400}
     401
     402void HUDNavigation::changedOwner()
     403{
     404
     405    const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects();
     406    for ( std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it )
     407    {
     408        if ( ! ( *it )->isHumanShip_ )
     409            this->addObject ( *it );
     410    }
     411}
     412}
  • code/trunk/src/modules/overlays/hud/HUDNavigation.h

    r6417 r7163  
    3232#include "overlays/OverlaysPrereqs.h"
    3333
     34#include <map>
     35#include <string>
     36
     37
    3438#include "util/OgreForwardRefs.h"
    3539#include "tools/interfaces/Tickable.h"
     40#include "interfaces/RadarListener.h"
    3641#include "overlays/OrxonoxOverlay.h"
    3742
    3843namespace orxonox
    3944{
    40     class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable
     45class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener
     46{
     47public:
     48    HUDNavigation ( BaseObject* creator );
     49    virtual ~HUDNavigation();
     50
     51    void setConfigValues();
     52
     53    virtual void XMLPort ( Element& xmlElement, XMLPort::Mode mode );
     54    virtual void tick ( float dt );
     55
     56    virtual void addObject ( RadarViewable* object );
     57    virtual void removeObject ( RadarViewable* viewable );
     58    virtual void objectChanged ( RadarViewable* viewable );
     59
     60    virtual void changedOwner();
     61    virtual void sizeChanged();
     62    virtual void angleChanged() { }
     63    virtual void positionChanged() { }
     64    virtual void radarTick ( float dt ) {}
     65
     66    inline float getRadarSensitivity() const
     67    { return 1.0f; }
     68
     69private:
     70    struct ObjectInfo
    4171    {
    42     public:
    43         HUDNavigation(BaseObject* creator);
    44         virtual ~HUDNavigation();
     72        Ogre::PanelOverlayElement* panel_;
     73        Ogre::TextAreaOverlayElement* text_;
     74        bool outOfView_;
     75        bool wasOutOfView_;
    4576
    46         virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
    47         virtual void tick(float dt);
     77    };
    4878
    49     private:
    50         void sizeChanged();
    51         void angleChanged() { }
    52         void positionChanged() { }
     79    bool showObject( RadarViewable* rv );
    5380
    54         // XMLPort accessors
    55         void setNavMarkerSize(float size) { this->navMarkerSize_ = size; this->sizeChanged(); }
    56         float getNavMarkerSize() const    { return this->navMarkerSize_; }
     81    // XMLPort accessors
     82    void setNavMarkerSize ( float size )
     83    { navMarkerSize_ = size; this->sizeChanged(); }
     84    float getNavMarkerSize() const
     85    { return navMarkerSize_; }
    5786
    58 /*
    59         void setAimMarkerSize(float size) { this->aimMarkerSize_ = size; this->sizeChanged(); }
    60         float getAimMarkerSize() const    { return this->aimMarkerSize_; }
    61 */
     87    void setTextSize ( float size );
     88    float getTextSize() const;
    6289
    63         void setTextSize(float size);
    64         float getTextSize() const;
     90    void setFont ( const std::string& font );
     91    const std::string& getFont() const;
    6592
    66         void setFont(const std::string& font);
    67         const std::string& getFont() const;
     93    typedef std::map<RadarViewable*, ObjectInfo > ObjectMap;
     94    ObjectMap activeObjectList_;
    6895
    69         void updateMarker();
    70         void updateFocus();
    71         float getDist2Focus() const;
     96    typedef std::list < std::pair<RadarViewable*, unsigned int > > sortedList;
     97    sortedList sortedObjectList_;
    7298
    73         Ogre::PanelOverlayElement* navMarker_;      //!< the panel used to show the arrow and the target marker
    74         float navMarkerSize_;                       //!< One paramter size of the navigation marker
    75 /*
    76         Ogre::PanelOverlayElement* aimMarker_;      //!< Panel used to show the aim Marker
    77         float aimMarkerSize_;                       //!< One paramter size of the aim marker
    78 */
    79         Ogre::TextAreaOverlayElement* navText_;     //!< Text overlay to display the target distance
    80         bool wasOutOfView_;                         //!< Performance booster variable: setMaterial is not cheap
    81     };
     99
     100    float navMarkerSize_;
     101    std::string fontName_;
     102    float textSize_;
     103
     104    unsigned int markerLimit_;; //TODO: is it possible to set this over the console and/or the IG-Setting
     105
     106
     107};
    82108}
    83109
  • code/trunk/src/modules/overlays/hud/HUDRadar.cc

    r6502 r7163  
    4040#include "worldentities/WorldEntity.h"
    4141#include "worldentities/pawns/Pawn.h"
     42#include "Scene.h"
     43#include "Radar.h"
    4244
    4345namespace orxonox
     
    7274        {
    7375            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->marker_);
    74             for (std::vector<Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.begin();
    75                 it != this->radarDots_.end(); ++it)
     76            for (std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it = this->radarObjects_.begin();
     77                it != this->radarObjects_.end(); ++it)
    7678            {
    77                 Ogre::OverlayManager::getSingleton().destroyOverlayElement(*it);
     79                Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second);
    7880            }
    7981        }
     
    8991    }
    9092
    91     void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked)
     93    void HUDRadar::addObject(RadarViewable* object)
    9294    {
    93         if (object == static_cast<RadarViewable*>(this->owner_))
     95        if (object == dynamic_cast<RadarViewable*>(this->owner_))
    9496            return;
    9597
    96         const WorldEntity* wePointer = object->getWorldEntity();
     98        // Make sure the object hasn't been added yet
     99        assert( this->radarObjects_.find(object) == this->radarObjects_.end() );
    97100
    98         // Just to be sure that we actually have a WorldEntity.
    99         // We could do a dynamic_cast, but that would be a lot slower.
    100         if (!wePointer || !this->owner_)
     101        // Create everything needed to display the object on the radar and add it to the map
     102        Ogre::PanelOverlayElement* panel;
     103        panel = static_cast<Ogre::PanelOverlayElement*>(
     104            Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString()));
     105        this->overlay_->add2D(panel);
     106        // get right material
     107        panel->setMaterialName(TextureGenerator::getMaterialName(
     108            shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour()));
     109        this->radarObjects_[object] = panel;
     110    }
     111
     112    void HUDRadar::removeObject(RadarViewable* object)
     113    {
     114        // If object was added at all then remove it
     115        std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it;
     116        it = this->radarObjects_.find( object );
     117        if( it != this->radarObjects_.end() )
    101118        {
    102             if (!wePointer)
    103                 CCOUT(2) << "Cannot display a non-WorldEntitiy on the radar" << std::endl;
    104             if (!this->owner_)
    105                 CCOUT(2) << "No owner defined" << std::endl;
     119            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second);
     120            this->radarObjects_.erase(it);
     121        }
     122    }
     123
     124    void HUDRadar::objectChanged( RadarViewable* rv )
     125    {
     126        if (rv == dynamic_cast<RadarViewable*>(this->owner_))
    106127            return;
    107         }
     128        assert( this->radarObjects_.find(rv) != this->radarObjects_.end() );
     129        Ogre::PanelOverlayElement* panel = this->radarObjects_[rv];
     130        panel->setMaterialName(TextureGenerator::getMaterialName(
     131            shapeMaterials_[rv->getRadarObjectShape()], rv->getRadarObjectColour()));
     132    }
    108133
    109         // try to find a panel already created
    110         Ogre::PanelOverlayElement* panel;
    111         //std::map<RadarViewable*, Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.find(object);
    112         if (itRadarDots_ == this->radarDots_.end())
    113         {
    114             // we have to create a new entry
    115             panel = static_cast<Ogre::PanelOverlayElement*>(
    116                 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString()));
    117             radarDots_.push_back(panel);
    118             // get right material
    119             panel->setMaterialName(TextureGenerator::getMaterialName(
    120                 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour()));
    121             this->overlay_->add2D(panel);
    122             this->itRadarDots_ = this->radarDots_.end();
    123         }
    124         else
    125         {
    126             panel = *itRadarDots_;
    127             ++itRadarDots_;
    128             const std::string& materialName = TextureGenerator::getMaterialName(
    129                 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour());
    130             if (materialName != panel->getMaterialName())
    131                 panel->setMaterialName(materialName);
    132         }
    133         panel->show();
    134 
    135         // set size to fit distance...
    136         float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length();
    137         // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda)
    138         float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance);
    139         panel->setDimensions(size, size);
    140 
    141         // calc position on radar...
    142         Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
    143         coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture
    144         panel->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f);
    145 
    146         if (bIsMarked)
    147         {
    148             this->marker_->show();
    149             this->marker_->setDimensions(size * 1.5f, size * 1.5f);
    150             this->marker_->setPosition((1.0f + coord.x - size * 1.5f) * 0.5f, (1.0f - coord.y - size * 1.5f) * 0.5f);
    151         }
     134    void HUDRadar::gatherObjects()
     135    {
     136        const std::set<RadarViewable*>& objectSet = this->getCreator()->getScene()->getRadar()->getRadarObjects();
     137        std::set<RadarViewable*>::const_iterator it;
     138        for( it=objectSet.begin(); it!=objectSet.end(); ++it )
     139            this->addObject(*it);
    152140    }
    153141
    154142    void HUDRadar::radarTick(float dt)
    155143    {
    156         for (itRadarDots_ = radarDots_.begin(); itRadarDots_ != radarDots_.end(); ++itRadarDots_)
    157             (*itRadarDots_)->hide();
    158         this->itRadarDots_ = this->radarDots_.begin();
    159         this->marker_->hide();
     144        // Make sure the owner of the radar was defined
     145        if( !this->owner_ )
     146        {
     147            CCOUT(0) << "No owner defined" << std::endl;
     148            assert(0);
     149        }
     150
     151        this->marker_->hide();      // in case that no object is in focus
     152        // get the focus object
     153        Radar* radar = this->getOwner()->getScene()->getRadar();
     154        const RadarViewable* focusObject = radar->getFocus();
     155
     156        // update the distances for all objects
     157        std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it;
     158        for( it = this->radarObjects_.begin(); it != this->radarObjects_.end(); ++it )
     159        {
     160            // Make sure the object really is a WorldEntity
     161            const WorldEntity* wePointer = it->first->getWorldEntity();
     162            if( !wePointer )
     163            {
     164                CCOUT(0) << "Cannot display a non-WorldEntitiy on the radar" << std::endl;
     165                assert(0);
     166            }
     167            bool isFocus = (it->first == focusObject);
     168            // set size to fit distance...
     169            float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length();
     170            // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda)
     171            float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance);
     172            it->second->setDimensions(size, size);
     173
     174            // calc position on radar...
     175            Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
     176            coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture
     177            it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f);
     178            it->second->show();
     179
     180            // if this object is in focus, then set the focus marker
     181            if (isFocus)
     182            {
     183                this->marker_->setDimensions(size * 1.5f, size * 1.5f);
     184                this->marker_->setPosition((1.0f + coord.x - size * 1.5f) * 0.5f, (1.0f - coord.y - size * 1.5f) * 0.5f);
     185                this->marker_->show();
     186            }
     187        }
    160188    }
    161189
    162190    void HUDRadar::changedOwner()
    163191    {
    164         SUPER(HUDRadar, changedOwner);
     192    SUPER(HUDRadar, changedOwner);
    165193
    166         this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
    167     }
     194    this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
     195    assert(this->radarObjects_.size()==0);
     196    this->gatherObjects();
    168197}
     198}
  • code/trunk/src/modules/overlays/hud/HUDRadar.h

    r5781 r7163  
    6565
    6666        // RadarListener interface
    67         void displayObject(RadarViewable* viewable, bool bIsMarked);
     67        virtual void addObject(RadarViewable* viewable);
     68        virtual void removeObject(RadarViewable* viewable);
     69        virtual void objectChanged( RadarViewable* rv );
    6870        void radarTick(float dt);
     71
     72        void gatherObjects();
    6973
    7074        std::map<RadarViewable::Shape, std::string> shapeMaterials_;
    7175
    72         std::vector<Ogre::PanelOverlayElement*> radarDots_;
    73         std::vector<Ogre::PanelOverlayElement*>::iterator itRadarDots_;
     76//         std::vector<Ogre::PanelOverlayElement*> radarDots_;
     77//         std::vector<Ogre::PanelOverlayElement*>::iterator itRadarDots_;
     78        std::map<RadarViewable*, Ogre::PanelOverlayElement*> radarObjects_;
    7479        Ogre::PanelOverlayElement* marker_;
    7580
  • code/trunk/src/modules/pickup/CMakeLists.txt

    r6711 r7163  
    11SET_SOURCE_FILES(PICKUP_SRC_FILES
     2  CollectiblePickup.cc
    23  DroppedPickup.cc
    34  Pickup.cc
     
    1718    PickupManager.h
    1819    PickupRepresentation.h
    19   DEFINE_SYMBOL
    20     "PICKUP_SHARED_BUILD"
    2120  PCH_FILE
    2221    PickupPrecompiledHeaders.h
  • code/trunk/src/modules/pickup/DroppedPickup.cc

    r6540 r7163  
    4141namespace orxonox
    4242{
    43    
     43
    4444    CreateFactory(DroppedPickup);
    45    
     45
    4646    /**
    4747    @brief
     
    5151    {
    5252        RegisterObject(DroppedPickup);
    53        
     53
    5454    }
    5555
     
    6767    */
    6868    DroppedPickup::DroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance) : PickupSpawner(creator, pickup, triggerDistance, 5, 1)
    69     {   
     69    {
    7070        RegisterObject(DroppedPickup);
    7171
    7272        this->setPosition(carrier->getCarrierPosition());
    7373        this->setActive(false);
    74        
     74
    7575        //TODO: Do more elegantly.
    7676        this->startRespawnTimer();
  • code/trunk/src/modules/pickup/DroppedPickup.h

    r6540 r7163  
    4141namespace orxonox
    4242{
    43    
     43
    4444    /**
    4545    @brief
  • code/trunk/src/modules/pickup/Pickup.cc

    • Property svn:eol-style set to native
    r6709 r7163  
    4848    /*static*/ const std::string Pickup::durationTypeOnce_s = "once";
    4949    /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
     50
     51    CreateUnloadableFactory(Pickup);
    5052
    5153    Pickup::Pickup(BaseObject* creator) : BaseObject(creator)
     
    146148    void Pickup::setActivationType(const std::string& type)
    147149    {
    148         if(type == activationTypeImmediate_s)
     150        if(Pickup::activationTypeImmediate_s.compare(type) == 0)
    149151        {
    150152            this->activationType_ = pickupActivationType::immediate;
    151153        }
    152         else if(type == activationTypeOnUse_s)
     154        else if(Pickup::activationTypeOnUse_s.compare(type) == 0)
    153155        {
    154156            this->activationType_ = pickupActivationType::onUse;
     
    168170    void Pickup::setDurationType(const std::string& type)
    169171    {
    170         if(type == durationTypeOnce_s)
     172        if(Pickup::durationTypeOnce_s.compare(type) == 0)
    171173        {
    172174            this->durationType_ = pickupDurationType::once;
    173175        }
    174         else if(type == durationTypeContinuous_s)
     176        else if(Pickup::durationTypeContinuous_s.compare(type) == 0)
    175177        {
    176178            this->durationType_ = pickupDurationType::continuous;
     
    192194
    193195        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
    194         if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
     196        if(this->isPickedUp() && this->isImmediate())
    195197        {
    196198            this->setUsed(true);
  • code/trunk/src/modules/pickup/Pickup.h

    • Property svn:eol-style set to native
    r6728 r7163  
    4040#include "core/XMLPort.h"
    4141
    42 #include "interfaces/Pickupable.h"
     42#include "CollectiblePickup.h"
    4343
    4444#include "tools/Timer.h"
     
    7474        Damian 'Mozork' Frick
    7575    */
    76     class _PickupExport Pickup : public Pickupable, public BaseObject
     76    class _PickupExport Pickup : public CollectiblePickup, public BaseObject
    7777    {
    7878
    79         protected:
     79        public:
    8080            Pickup(BaseObject* creator); //!< Constructor.
    81 
    82         public:
    8381            virtual ~Pickup(); //!< Destructor.
    8482
     
    167165        private:
    168166            void initialize(void); //!< Initializes the member variables.
    169            
     167
    170168            //TODO: Problems, when there are more Timers needed? Solutions?
    171169            Timer durationTimer_; //!< Timer at the disposal of each Class implementing Pickup.
  • code/trunk/src/modules/pickup/PickupCollection.cc

    r6901 r7163  
    3535#include "core/XMLPort.h"
    3636#include "interfaces/PickupCarrier.h"
     37#include "CollectiblePickup.h"
    3738#include "DroppedPickup.h"
    3839#include "PickupCollectionIdentifier.h"
     
    4243namespace orxonox
    4344{
    44  
     45
    4546    CreateFactory(PickupCollection);
    4647
     
    5253    {
    5354        RegisterObject(PickupCollection);
    54        
     55
    5556        this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this);
    56     }
    57    
     57        this->usedCounter_ = 0;
     58        this->pickedUpCounter_ = 0;
     59        this->disabledCounter_ = 0;
     60        this->processingUsed_ = false;
     61        this->processingPickedUp_ = false;
     62    }
     63
    5864    /**
    5965    @brief
     
    6268    PickupCollection::~PickupCollection()
    6369    {
    64         //! Destroy all Pickupables constructing this PickupCollection.
    65         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    66         {
    67             if((*it).get() != NULL)
    68                 (*it).get()->destroy();
    69         }
    70     }
    71    
     70        // Destroy all Pickupables constructing this PickupCollection.
     71        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     72        {
     73            (*it)->removeFromCollection();
     74            (*it)->destroy();
     75        }
     76        this->pickups_.clear();
     77    }
     78
    7279    /**
    7380    @brief
     
    7784    {
    7885        SUPER(PickupCollection, XMLPort, xmlelement, mode);
    79        
    80         XMLPortObject(PickupCollection, Pickupable, "pickupables", addPickupable, getPickupable, xmlelement, mode);
    81        
     86
     87        XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode);
     88
    8289        this->initializeIdentifier();
    8390    }
    84    
     91
    8592    /**
    8693    @brief
     
    8996    void PickupCollection::initializeIdentifier(void)
    9097    {
    91         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    92         {
    93             this->pickupCollectionIdentifier_->addPickup((*it).get()->getPickupIdentifier());
    94         }
    95     }
    96    
     98        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     99        {
     100            this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
     101        }
     102    }
     103
    97104    /**
    98105    @brief
     
    103110    {
    104111        SUPER(PickupCollection, changedUsed);
    105        
    106         //! Change used for all Pickupables this PickupCollection consists of.
    107         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    108         {
    109             (*it).get()->setUsed(this->isUsed());
    110         }
    111     }
    112    
     112
     113        this->processingUsed_ = true;
     114        // Change used for all Pickupables this PickupCollection consists of.
     115        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     116        {
     117            (*it)->setUsed(this->isUsed());
     118        }
     119        this->processingUsed_ = false;
     120
     121        this->changedUsedAction();
     122    }
     123
     124    /**
     125    @brief
     126        Helper method.
     127        Checks whether due to changes in the used status of the pickups of this PickupCollection the used status of this PickupCollection has to change as well.
     128    */
     129    void PickupCollection::changedUsedAction(void)
     130    {
     131        if(this->processingUsed_)
     132            return;
     133
     134        // If all the pickups are not in use but the PickupCollection is.
     135        if(this->usedCounter_ == 0 && this->isUsed())
     136            this->setUsed(false);
     137
     138        // If all the enabled pickups are in use but the PickupCollection is not.
     139        if(this->usedCounter_ != 0 && this->usedCounter_ == this->pickups_.size()-this->disabledCounter_ && !this->isUsed())
     140            this->setUsed(true);
     141    }
     142
    113143    /**
    114144    @brief
     
    119149    {
    120150        SUPER(PickupCollection, changedCarrier);
    121        
    122         //! Change the PickupCarrier for all Pickupables this PickupCollection consists of.
    123         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    124         {
    125             (*it).get()->setCarrier(this->getCarrier()->getTarget(*it));
    126         }
    127     }
    128    
     151
     152        // Change the PickupCarrier for all Pickupables this PickupCollection consists of.
     153        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     154        {
     155            if(this->getCarrier() == NULL)
     156                (*it)->setCarrier(NULL);
     157            else
     158                (*it)->setCarrier(this->getCarrier()->getTarget(*it));
     159        }
     160    }
     161
    129162    /**
    130163    @brief
     
    135168    {
    136169        SUPER(PickupCollection, changedPickedUp);
    137        
    138         //! Change the pickedUp status for all Pickupables this PickupCollection consists of.
    139         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    140         {
    141             (*it).get()->setPickedUp(this->isPickedUp());
    142         }
    143     }
    144    
     170
     171        this->processingPickedUp_ = true;
     172        // Change the pickedUp status for all Pickupables this PickupCollection consists of.
     173        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     174        {
     175            (*it)->setPickedUp(this->isPickedUp());
     176        }
     177        this->processingPickedUp_ = false;
     178
     179        this->changedPickedUpAction();
     180    }
     181
     182    /**
     183    @brief
     184        Helper method.
     185        Checks whether due to changes in the picked up status of the pickups of this PickupCollection the picked up status of this PickupCollection has to change as well.
     186    */
     187    void PickupCollection::changedPickedUpAction(void)
     188    {
     189        if(this->processingPickedUp_)
     190            return;
     191
     192        // If at least all the enabled pickups of this PickupCollection are no longer picked up.
     193        if(this->pickedUpCounter_ <= this->disabledCounter_ && this->isPickedUp())
     194            this->Pickupable::destroy();
     195
     196        // If the PickupCollection is no longer picked up.
     197        if(!this->isPickedUp())
     198            this->pickedUpCounter_ = 0;
     199    }
     200
    145201    /**
    146202    @brief
     
    154210        if(item == NULL)
    155211            item = new PickupCollection(this);
    156        
     212
    157213        SUPER(PickupCollection, clone, item);
    158        
     214
    159215        PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
    160         //! Clone all Pickupables this PickupCollection consist of.
    161         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    162         {
    163             Pickupable* newPickup = (*it).get()->clone();
    164             pickup->addPickupable(newPickup);
     216        // Clone all Pickupables this PickupCollection consist of.
     217        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     218        {
     219            Pickupable* newPickup = (*it)->clone();
     220            CollectiblePickup* collectible = static_cast<CollectiblePickup*>(newPickup);
     221            pickup->addPickupable(collectible);
    165222        }
    166223
    167224        pickup->initializeIdentifier();
    168225    }
    169    
     226
    170227    /**
    171228    @brief
     
    178235    bool PickupCollection::isTarget(PickupCarrier* carrier) const
    179236    {
    180         for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    181         {
    182             if(!carrier->isTarget((*it).get()))
     237        for(std::vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     238        {
     239            if(!carrier->isTarget(*it))
    183240                return false;
    184241        }
    185        
     242
    186243        return true;
    187244    }
    188    
     245
    189246    /**
    190247    @brief
     
    198255        return this->pickupCollectionIdentifier_;
    199256    }
    200    
     257
    201258    /**
    202259    @brief
     
    207264        Returns true if successful,
    208265    */
    209     bool PickupCollection::addPickupable(Pickupable* pickup)
     266    bool PickupCollection::addPickupable(CollectiblePickup* pickup)
    210267    {
    211268        if(pickup == NULL)
    212269            return false;
    213        
    214         WeakPtr<Pickupable> ptr = pickup; //!< Create a weak pointer to be able to test in the constructor if the Pointer is still valid.
    215         this->pickups_.push_back(ptr);
     270
     271        pickup->addToCollection(this);
     272        this->pickups_.push_back(pickup);
    216273        return true;
    217274    }
    218    
     275
    219276    /**
    220277    @brief
     
    227284    const Pickupable* PickupCollection::getPickupable(unsigned int index)
    228285    {
    229         return this->pickups_[index].get();
    230     }
    231        
     286        return this->pickups_[index];
     287    }
     288
     289    /**
     290    @brief
     291        Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
     292        This is used internally by the CollectiblePickup class.
     293    @param changed
     294        The value the used status has changed to.
     295    */
     296    void PickupCollection::pickupChangedUsed(bool changed)
     297    {
     298        if(changed)
     299            this->usedCounter_++;
     300        else
     301            this->usedCounter_--;
     302
     303        this->changedUsedAction();
     304    }
     305
     306    /**
     307    @brief
     308        Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value.
     309        This is used internally by the CollectiblePickup class.
     310    @param changed
     311        The value the picked up status has changed to.
     312    */
     313    void PickupCollection::pickupChangedPickedUp(bool changed)
     314    {
     315        if(changed)
     316            this->pickedUpCounter_++;
     317        else
     318            this->pickedUpCounter_--;
     319
     320        this->changedPickedUpAction();
     321    }
     322
     323    /**
     324    @brief
     325        Informs the PickupCollection, that one of its pickups has been disabled.
     326        This is used internally by the CollectiblePickup class.
     327    */
     328    void PickupCollection::pickupDisabled(void)
     329    {
     330        this->disabledCounter_++;
     331    }
     332
    232333    /**
    233334    @brief
     
    245346        return true;
    246347    }
    247    
     348
    248349}
  • code/trunk/src/modules/pickup/PickupCollection.h

    r6731 r7163  
    3737#include "PickupPrereqs.h"
    3838
    39 #include "interfaces/Pickupable.h"
    4039#include "core/BaseObject.h"
     40#include "CollectiblePickup.h"
    4141
    4242#include <list>
     
    4747    /**
    4848    @brief
    49         The PickupCollection combines different Pickupables to a coherent, single pickup and makes the seem (from the outside looking in) just as if they were just one Pickupable.
     49        The PickupCollection combines different Pickupables to a coherent, single pickup and makes them seem (from the outside looking in) just as if they were just one Pickupable.
    5050    @author
    5151        Damian 'Mozork' Frick
    5252    */
    53     class _PickupExport PickupCollection : public Pickupable, public BaseObject
     53    class _PickupExport PickupCollection : public CollectiblePickup, public BaseObject
    5454    {
    55        
     55
    5656        public:
    57            
    5857            PickupCollection(BaseObject* creator); //!< Default Constructor.
    5958            virtual ~PickupCollection(); //!< Destructor.
    60            
     59
    6160            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates an instance of this Class through XML.
    6261
     
    6463            virtual void changedCarrier(void); //!< Is called when the pickup has changed its PickupCarrier.
    6564            virtual void changedPickedUp(void); //!< Is called when the pickup has transited from picked up to dropped or the other way around.
    66            
     65
    6766            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    68            
     67
    6968            virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection.
    70            
     69
    7170            virtual const PickupIdentifier* getPickupIdentifier(void); //!< Get the PickupIdentifier of this PickupCollection.
    72            
    73             bool addPickupable(Pickupable* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
     71
     72            bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
    7473            const Pickupable* getPickupable(unsigned int index); //!< Get the Pickupable at the given index.
    75            
     74
     75            void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
     76            void pickupChangedPickedUp(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value.
     77            void pickupDisabled(void); //!< Informs the PickupCollection, that one of its pickups has been disabled.
     78
    7679        protected:
    7780            void initializeIdentifier(void); //!< Initializes the PickupIdentifier for this pickup.
     81
     82            virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
     83
     84            PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves.
     85
     86        private:
     87            void changedUsedAction(void); //!< Helper method.
     88            void changedPickedUpAction(void); //!< Helper method.
    7889           
    79             virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    80            
    81             PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves.
    82            
    83         private:
    84            
    85             std::vector<WeakPtr<Pickupable> > pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
    86        
     90            std::vector<CollectiblePickup*> pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
     91
     92            unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use.
     93            unsigned int pickedUpCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are picked up.
     94            unsigned int disabledCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are disabled.
     95
     96            bool processingUsed_; //!< Boolean to ensure, that the PickupCollection doesn't update its used status while its internal state is inconsistent.
     97            bool processingPickedUp_; //!< Boolean to ensure, that the PickupCollection doesn't update its picked upp status while its internal state is inconsistent.
     98
    8799    };
    88    
     100
    89101}
    90102
  • code/trunk/src/modules/pickup/PickupCollectionIdentifier.cc

    • Property svn:eol-style set to native
    r6538 r7163  
    3838namespace orxonox
    3939{
    40    
     40
    4141    /**
    4242    @brief
     
    4747        RegisterObject(PickupCollectionIdentifier);
    4848    }
    49    
     49
    5050    /**
    5151    @brief
     
    5454    PickupCollectionIdentifier::~PickupCollectionIdentifier()
    5555    {
    56        
     56
    5757    }
    5858
     
    6767    int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
    6868    {
    69         //! Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
     69        // Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
    7070        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
    7171        const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp);
    72        
    73         //! If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
     72
     73        // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
    7474        if(collectionIdentifier == NULL)
    7575        {
    7676            return this->PickupIdentifier::compare(identifier);
    7777        }
    78        
    79         //! If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
     78
     79        // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
    8080        if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
    8181            return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
    82        
    83         //! Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
     82
     83        // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
    8484        std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
    8585        for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
    8686        {
    87            
     87
    8888            if((*it)->compare(*it2) < 0)
    8989                return -1;
     
    9191                return 1;
    9292        }
    93        
     93
    9494        //! Means they are equal.
    9595        return 0;
    9696    }
    97    
     97
    9898    /**
    9999    @brief
     
    106106        this->identifiers_.insert(identifier);
    107107    }
    108    
     108
    109109}
    110110
  • code/trunk/src/modules/pickup/PickupCollectionIdentifier.h

    • Property svn:eol-style set to native
    r6538 r7163  
    5454    class _PickupExport PickupCollectionIdentifier : public PickupIdentifier
    5555    {
    56        
     56
    5757        public:
    5858            PickupCollectionIdentifier(Pickupable* pickup); //!< Constructor.
    5959            ~PickupCollectionIdentifier(); //!< Destructor.
    60            
     60
    6161            virtual int compare(const PickupIdentifier* identifier) const; //!< Compares a PickupCollectionIdentifier with a PickupIdentifier.
    62            
     62
    6363            void addPickup(const PickupIdentifier* identifier); //!< Add a Pickupable to the PickupCollectionIdentifier.
    64            
     64
    6565        private:
    6666            std::set<const PickupIdentifier*, PickupIdentifierCompare> identifiers_; //!< The set of PickupIdentifiers of the Pickupables the PickupCollection with this PickupCollectionIdentifier consists of, ordered by the rule set by PickupIdentifierCompare.
    67            
     67
    6868    };
    69    
     69
    7070}
    7171
  • code/trunk/src/modules/pickup/PickupManager.cc

    • Property svn:eol-style set to native
    r6752 r7163  
    3939#include "core/ScopedSingletonManager.h"
    4040#include "core/Identifier.h"
     41#include "util/Convert.h"
    4142#include "interfaces/PickupCarrier.h"
    4243#include "infos/PlayerInfo.h"
    4344#include "worldentities/pawns/Pawn.h"
     45#include "CollectiblePickup.h"
    4446#include "PickupRepresentation.h"
    4547
     
    5052    // Register tolua_open function when loading the library
    5153    DeclareToluaInterface(Pickup);
    52    
    53     ManageScopedSingleton(PickupManager, ScopeID::Graphics, false);
    54    
     54
     55    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
     56
    5557    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
    56    
     58
    5759    /**
    5860    @brief
     
    6264    {
    6365        RegisterRootObject(PickupManager);
    64        
     66
     67        //TODO: This doesn't work, yet.
     68        if( GameMode::showsGraphics() )
     69        {
     70            GUIManager::getInstance().loadGUI(PickupManager::guiName_s);
     71        }
    6572        this->defaultRepresentation_ = new PickupRepresentation();
    66        
     73
    6774        COUT(3) << "PickupManager created." << std::endl;
    6875    }
    69    
     76
    7077    /**
    7178    @brief
     
    7784        if(this->defaultRepresentation_ != NULL)
    7885            this->defaultRepresentation_->destroy();
    79        
     86
    8087        this->representations_.clear();
    81        
     88
    8289        COUT(3) << "PickupManager destroyed." << std::endl;
    8390    }
    84    
     91
    8592    /**
    8693    @brief
     
    95102    */
    96103    bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    97     {       
     104    {
    98105        if(identifier == NULL || representation == NULL || this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a Representation registered.
    99106            return false;
    100        
     107
    101108        this->representations_[identifier] = representation;
    102        
     109
    103110        COUT(4) << "PickupRepresentation " << representation << " registered with the PickupManager." << std::endl;
    104111        return true;
    105112    }
    106    
     113
    107114    /**
    108115    @brief
     
    116123    */
    117124    bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    118     {       
     125    {
    119126        if(identifier == NULL || representation == NULL)
    120127            return false;
    121        
     128
    122129        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
    123130        if(it == this->representations_.end()) //!< If the Pickupable is not registered in the first place.
    124131            return false;
    125        
     132
    126133        this->representations_.erase(it);
    127        
     134
    128135        COUT(4) << "PickupRepresentation " << representation << " unregistered with the PickupManager." << std::endl;
    129136        return true;
    130137    }
    131    
     138
    132139    /**
    133140    @brief
     
    146153            return this->defaultRepresentation_;
    147154        }
    148        
     155
    149156        return it->second;
    150157    }
    151    
    152     PickupCarrier* PickupManager::getPawn(void)
    153     {
     158
     159    int PickupManager::getNumPickups(void)
     160    {
     161        this->pickupsList_.clear();
     162
    154163        PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s);
     164        PickupCarrier* carrier = NULL;
    155165        if (player != NULL)
    156             return dynamic_cast<PickupCarrier*>(player->getControllableEntity());
     166            carrier = dynamic_cast<PickupCarrier*>(player->getControllableEntity());
    157167        else
    158             return NULL;
    159     }
    160    
    161     int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
    162     {
    163         if(carrier == NULL)
    164168            return 0;
    165         return carrier->getNumCarrierChildren();
    166     }
    167            
    168     PickupCarrier* PickupManager::getCarrierChild(int index, PickupCarrier* carrier)
    169     {
    170         if(carrier == NULL)
    171             return NULL;
    172         return carrier->getCarrierChild(index);
    173     }
    174    
    175     const std::string& PickupManager::getCarrierName(orxonox::PickupCarrier* carrier)
    176     {
    177         if(carrier == NULL)
    178             return BLANKSTRING;
    179         return carrier->getCarrierName();
    180     }
    181    
    182     PickupRepresentation* PickupManager::getPickupRepresentation(int index, PickupCarrier* carrier)
    183     {
    184         Pickupable* pickup = carrier->getPickup(index);
    185         if(pickup == NULL)
    186             return NULL;
    187        
    188         return this->getRepresentation(pickup->getPickupIdentifier());
    189     }
    190    
    191     int PickupManager::getNumPickups(PickupCarrier* carrier)
    192     {
    193         if(carrier == NULL)
    194             return 0;
    195         return carrier->getNumPickups();
    196     }
    197    
    198     void PickupManager::dropPickup(int index, PickupCarrier* carrier)
    199     {
    200         Pickupable* pickup = carrier->getPickup(index);
    201         if(pickup != NULL)
    202             carrier->drop(pickup);
    203     }
    204    
    205     void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
    206     {
    207         Pickupable* pickup = carrier->getPickup(index);
    208         if(pickup != NULL)
     169
     170        std::vector<PickupCarrier*>* carriers = this->getAllCarriers(carrier);
     171        for(std::vector<PickupCarrier*>::iterator it = carriers->begin(); it != carriers->end(); it++)
     172        {
     173            std::set<Pickupable*> pickups = (*it)->getPickups();
     174            for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
     175            {
     176                CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(*pickup);
     177                if(collectible == NULL || !collectible->isInCollection())
     178                    this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup)));
     179            }
     180        }
     181        delete carriers;
     182
     183        this->pickupsIterator_ = this->pickupsList_.begin();
     184        return this->pickupsList_.size();
     185    }
     186
     187    std::vector<PickupCarrier*>* PickupManager::getAllCarriers(PickupCarrier* carrier)
     188    {
     189        //TODO: More efficiently.
     190        std::vector<PickupCarrier*>* carriers = new std::vector<PickupCarrier*>();
     191        carriers->insert(carriers->end(), carrier);
     192        std::vector<PickupCarrier*>* children = carrier->getCarrierChildren();
     193        for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
     194        {
     195            std::vector<PickupCarrier*>* childrensChildren = this->getAllCarriers(*it);
     196            for(std::vector<PickupCarrier*>::iterator it2 = childrensChildren->begin(); it2 != childrensChildren->end(); it2++)
     197            {
     198                carriers->insert(carriers->end(), *it2);
     199            }
     200            delete childrensChildren;
     201        }
     202        delete children;
     203        return carriers;
     204    }
     205
     206    void PickupManager::dropPickup(orxonox::Pickupable* pickup)
     207    {
     208        std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup);
     209        if(pickup == NULL || it == this->pickupsList_.end() || it->second.get() == NULL)
     210            return;
     211
     212        if(!pickup->isPickedUp())
     213            return;
     214
     215        PickupCarrier* carrier = pickup->getCarrier();
     216        if(pickup != NULL && carrier != NULL)
     217        {
     218            pickup->drop(carrier);
     219        }
     220    }
     221
     222    void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use)
     223    {
     224        std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup);
     225        if(pickup == NULL || it == this->pickupsList_.end() || it->second.get() == NULL)
     226            return;
     227
     228        if(!pickup->isPickedUp())
     229            return;
     230
     231        PickupCarrier* carrier = pickup->getCarrier();
     232        if(pickup != NULL && carrier != NULL)
    209233            pickup->setUsed(use);
    210234    }
    211    
     235
    212236}
  • code/trunk/src/modules/pickup/PickupManager.h

    • Property svn:eol-style set to native
    r6725 r7163  
    3939#include <map>
    4040#include "util/Singleton.h"
     41#include "core/WeakPtr.h"
    4142#include "pickup/PickupIdentifier.h"
    4243#include "PickupRepresentation.h"
     
    5960    { // tolua_export
    6061        friend class Singleton<PickupManager>;
    61        
     62
    6263        public:
    6364            PickupManager();
    6465            virtual ~PickupManager();
    65            
     66
    6667            static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export
    67            
     68
    6869            bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    6970            bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    7071            PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    71            
     72
    7273            // tolua_begin
    73             orxonox::PickupCarrier* getPawn(void);
    74            
    75             int getNumCarrierChildren(orxonox::PickupCarrier* carrier);
    76             orxonox::PickupCarrier* getCarrierChild(int index, orxonox::PickupCarrier* carrier);
    77            
    78             const std::string& getCarrierName(orxonox::PickupCarrier* carrier);
    79            
    80             int getNumPickups(orxonox::PickupCarrier* carrier);
    81             PickupRepresentation* getPickupRepresentation(int index, orxonox::PickupCarrier* carrier);
    82             void dropPickup(int index, orxonox::PickupCarrier* carrier);
    83             void usePickup(int index, orxonox::PickupCarrier* carrier, bool use);
     74            int getNumPickups(void);
     75            orxonox::Pickupable* popPickup(void) { return (this->pickupsIterator_++)->first; }
     76            orxonox::PickupRepresentation* getPickupRepresentation(orxonox::Pickupable* pickup) { if(pickup != NULL) return this->getRepresentation(pickup->getPickupIdentifier()); return NULL; }
     77
     78            void dropPickup(orxonox::Pickupable* pickup);
     79            void usePickup(orxonox::Pickupable* pickup, bool use);
     80            bool isValidPickup(orxonox::Pickupable* pickup) { std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup); if(it == this->pickupsList_.end()) return false; return it->second.get() != NULL; }
    8481            // tolua_end
    85            
     82
    8683        private:
    8784            static PickupManager* singletonPtr_s;
    8885            static const std::string guiName_s;
    89            
     86
    9087            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    9188            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
    92        
     89
     90            std::map<Pickupable*, WeakPtr<Pickupable> > pickupsList_;
     91            std::map<Pickupable*, WeakPtr<Pickupable> >::iterator pickupsIterator_;
     92
     93            std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier);
     94
    9395    }; // tolua_export
    94    
     96
    9597} // tolua_export
    9698
  • code/trunk/src/modules/pickup/PickupPrereqs.h

    r6711 r7163  
    4343//-----------------------------------------------------------------------
    4444
    45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
     45#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(PICKUP_STATIC_BUILD)
    4646#  ifdef PICKUP_SHARED_BUILD
    4747#    define _PickupExport __declspec(dllexport)
     
    6565namespace orxonox
    6666{
    67    
     67
     68    class CollectiblePickup;
    6869    class DroppedPickup;
    6970    class Pickup;
     
    7576
    7677    //items
     78    class DronePickup;
    7779    class HealthPickup;
    7880    class InvisiblePickup;
    7981    class MetaPickup;
    8082    class SpeedPickup;
     83    class ShieldPickup;
    8184
    8285}
  • code/trunk/src/modules/pickup/PickupRepresentation.cc

    • Property svn:eol-style set to native
    r6725 r7163  
    4141namespace orxonox
    4242{
    43    
     43
    4444    CreateFactory(PickupRepresentation);
    45    
     45
    4646    /**
    4747    @brief
     
    5252    {
    5353        RegisterObject(PickupRepresentation);
    54        
     54
    5555        this->initialize();
    5656    }
    57    
     57
    5858    /**
    5959    @brief
     
    6363    {
    6464        RegisterObject(PickupRepresentation);
    65        
     65
    6666        this->initialize();
    6767    }
    68    
     68
    6969    /**
    7070    @brief
     
    7575        if(this->spawnerRepresentation_ != NULL)
    7676            this->spawnerRepresentation_->destroy();
    77        
     77
    7878        if(this->pickup_ != NULL)
    7979            PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this);
    8080    }
    81    
     81
    8282    /**
    8383    @brief
     
    9191        this->inventoryRepresentation_ = "Default";
    9292    }
    93    
     93
    9494    /**
    9595    @brief
     
    9999    {
    100100        SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
    101        
     101
    102102        XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode);
    103103        XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode);
     
    106106        XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
    107107        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
    108        
     108
    109109        PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.
    110        
     110
    111111        if(this->spawnerRepresentation_ != NULL)
    112112            this->spawnerRepresentation_->setVisible(false);
    113        
     113
    114114        COUT(4) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << std::endl;
    115115    }
    116    
     116
    117117    /**
    118118    @brief
     
    136136            this->addTemplate(this->spawnerTemplate_);
    137137        }
    138        
     138
    139139        StaticEntity* representation = this->spawnerRepresentation_;
    140140        representation->setVisible(true);
    141        
     141
    142142        this->addTemplate(this->spawnerTemplate_);
    143143        this->spawnerRepresentation_->setVisible(false);
    144        
     144
    145145        return representation;
    146146    }
    147    
     147
    148148    /**
    149149    @brief
     
    171171        return representation;
    172172    }
    173    
     173
    174174}
  • code/trunk/src/modules/pickup/PickupRepresentation.h

    • Property svn:eol-style set to native
    r6711 r7163  
    5656        : public BaseObject
    5757    { // tolua_export
    58        
     58
    5959        public:
    6060            PickupRepresentation(); //!< Constructor
    6161            PickupRepresentation(BaseObject* creator); //!< Default constructor.
    6262            virtual ~PickupRepresentation(); //!< Destructor.
    63            
     63
    6464            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    65            
     65
    6666            /**
    6767            @brief Set the name of the Pickupable represented by this PickupRepresentation.
     
    102102            inline void setPickup(Pickupable* pickup)
    103103                { this->pickup_ = pickup; }
    104                
     104
    105105            /**
    106106            @brief Get the name of the Pickupable represented by this PickupRepresentation.
     
    138138            inline const Pickupable* getPickup(unsigned int index)
    139139                { if(index == 0) return this->pickup_; return NULL; }
    140                
     140
    141141            StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner.
    142        
     142
    143143        private:
    144144            void initialize(void); //!< Initializes the member variables of this PickupRepresentation.
    145145            StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner.
    146            
     146
    147147            std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation.
    148148            std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation.
    149149            std::string spawnerTemplate_; //!<  The name of the template of this PickupRepresentation.
    150150            StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation.
    151             std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. TODO: Exact format and placement of image?
    152            
     151            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory.
     152
    153153            Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
    154            
     154
    155155    }; // tolua_export
    156156
    157157} // tolua_export
    158    
     158
    159159#endif // _PickupRepresentation_H__
  • code/trunk/src/modules/pickup/PickupSpawner.cc

    r6711 r7163  
    5555    {
    5656        RegisterObject(PickupSpawner);
    57        
     57
    5858        this->initialize();
    5959    }
     
    7676    {
    7777        RegisterObject(PickupSpawner);
    78        
     78
    7979        this->initialize();
    80  
     80
    8181        this->pickup_ = pickup;
    8282
     
    8484        this->respawnTime_ = respawnTime;
    8585        this->setMaxSpawnedItems(maxSpawnedItems);
    86        
     86
    8787        if(this->pickup_ == NULL)
    8888        {
     
    107107        this->maxSpawnedItems_ = INF;
    108108        this->spawnsRemaining_ = INF;
     109        this->selfDestruct_ = false;
    109110    }
    110111
     
    115116    PickupSpawner::~PickupSpawner()
    116117    {
    117         if(this->pickup_ != NULL)
     118        if(this->selfDestruct_ && this->pickup_ != NULL)
    118119            this->pickup_->destroy();
    119120    }
     
    132133
    133134        XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode);
    134        
     135
    135136        XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
    136137        XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode);
    137138        XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode);
    138        
     139
    139140        if(this->pickup_ == NULL)
    140141        {
     
    150151        }
    151152    }
    152    
     153
    153154    /**
    154155    @brief
     
    161162        this->setVisible(this->isActive());
    162163    }
    163      
     164
    164165    /**
    165166    @brief
     
    172173    {
    173174        SUPER(PickupSpawner, tick, dt);
    174        
     175
    175176        //! If the PickupSpawner is active.
    176177        if (this->isActive())
    177178        {
     179            SmartPtr<PickupSpawner> temp = this; //Create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
     180
    178181            //! Iterate trough all Pawns.
    179182            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
     
    189192        }
    190193    }
    191    
     194
    192195    /**
    193196    @brief
     
    201204        this->spawnsRemaining_ = items;
    202205    }
    203    
     206
    204207    /**
    205208    @brief
     
    223226        else
    224227        {
    225             COUT(3) << "PickupSpawner empty, selfdestruct initialized." << std::endl;
     228            COUT(4) << "PickupSpawner (&" << this << ") empty, selfdestruct initialized." << std::endl;
    226229            this->setActive(false);
    227230            this->destroy();
    228231        }
    229232    }
    230    
     233
    231234    /**
    232235    @brief
     
    237240        this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
    238241    }
    239    
     242
    240243    /**
    241244    @brief
     
    248251        if(this->pickup_ != NULL)
    249252        {
    250             COUT(1) << "In PickupSpawner: setPickupable called, with this->pickup_ already set." << std::endl;
     253            COUT(1) << "In PickupSpawner (&" << this << "): setPickupable called, with this->pickup_ already set." << std::endl;
    251254            return;
    252255        }
    253256        if(pickup == NULL)
    254257        {
    255             COUT(1) << "In PickupSpawner: Argument of setPickupable is NULL." << std::endl;
     258            COUT(1) << "In PickupSpawner (&" << this << "): Argument of setPickupable is NULL." << std::endl;
    256259            return;
    257260        }
    258        
     261
    259262        this->pickup_ = pickup;
    260263    }
    261    
     264
    262265    /**
    263266    @brief
     
    282285        if (this->isActive()) //!< Checks whether PickupSpawner is active.
    283286        {
    284             COUT(3) << "PickupSpawner triggered and active." << std::endl;
    285            
     287            COUT(4) << "PickupSpawner (&" << this << ") triggered and active." << std::endl;
     288
    286289            PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
    287290            if(carrier == NULL)
     
    290293                return;
    291294            }
    292            
     295
    293296            if(!carrier->isTarget(this->pickup_))
    294297            {
    295                 COUT(4) << "PickupSpawner triggered but Pawn wasn't a target of the Pickupable." << std::endl;
     298                COUT(4) << "PickupSpawner (&" << this << ") triggered but Pawn wasn't a target of the Pickupable." << std::endl;
    296299                return;
    297300            }
    298            
     301
    299302            PickupCarrier* target = carrier->getTarget(this->pickup_);
    300303            Pickupable* pickup = this->getPickup();
    301            
     304
    302305            if(target != NULL && pickup != NULL)
    303306            {
    304                 if(target->pickup(pickup))
    305                 {
     307                if(pickup->pickup(target))
    306308                    this->decrementSpawnsRemaining();
    307                 }
    308309                else
    309310                {
     311                    this->selfDestruct_ = true;
    310312                    pickup->destroy();
    311313                }
     
    314316            {
    315317                if(target == NULL)
    316                     COUT(1) << "PickupSpawner: Pickupable has no target." << std::endl;
    317                
     318                    COUT(1) << "PickupSpawner (&" << this << "): Pickupable has no target." << std::endl;
     319
    318320                if(pickup == NULL)
    319                 {
    320                     COUT(1) << "PickupSpawner: getPickup produced an error, no Pickupable created." << std::endl;
    321                 }
     321                    COUT(1) << "PickupSpawner (&" << this << "): getPickup produced an error, no Pickupable created." << std::endl;
    322322                else
    323323                {
     324                    this->selfDestruct_ = true;
    324325                    pickup->destroy();
    325326                }
     
    333334    @return
    334335        The Pickupable created.
    335     */   
     336    */
    336337    Pickupable* PickupSpawner::getPickup(void)
    337338    {
     
    341342            return NULL;
    342343        }
    343        
     344
    344345        Pickupable* pickup = this->pickup_->clone();
    345346        return pickup;
     
    352353    void PickupSpawner::respawnTimerCallback()
    353354    {
    354         COUT(3) << "PickupSpawner reactivated." << std::endl;
     355        COUT(4) << "PickupSpawner (&" << this << ") reactivated." << std::endl;
    355356
    356357        this->setActive(true);
  • code/trunk/src/modules/pickup/PickupSpawner.h

    r6540 r7163  
    101101        protected:
    102102            void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.
    103                        
     103
    104104            void startRespawnTimer(void);
    105            
     105
    106106            virtual Pickupable* getPickup(void); //!< Creates a new Pickupable.
    107            
     107
    108108            void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn.
    109109            const Pickupable* getPickupable(void); //!< Get the Pickupable that is spawned by this PickupSpawner.
    110            
     110
    111111            Pickupable* pickup_; //!< The pickup to be spawned.
    112112
    113113        private:
    114114            void initialize(void);
    115            
     115
    116116            void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.
    117117            void respawnTimerCallback(); //!< Method called when the timer runs out.
     
    125125            Timer respawnTimer_; //!< Timer used for re-activating.
    126126
     127            bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing.
     128
    127129            static const int INF = -1; //!< Constant for infinity.
    128130    };
  • code/trunk/src/modules/pickup/items/CMakeLists.txt

    • Property svn:eol-style set to native
    r6710 r7163  
    33  InvisiblePickup.cc
    44  MetaPickup.cc
     5  DronePickup.cc
    56  SpeedPickup.cc
     7  ShieldPickup.cc
    68)
  • code/trunk/src/modules/pickup/items/HealthPickup.cc

    r6709 r7163  
    4545namespace orxonox
    4646{
    47    
     47
    4848    /*static*/ const std::string HealthPickup::healthTypeLimited_s = "limited";
    4949    /*static*/ const std::string HealthPickup::healthTypeTemporary_s = "temporary";
    5050    /*static*/ const std::string HealthPickup::healthTypePermanent_s = "permanent";
    51    
     51
    5252    CreateFactory(HealthPickup);
    53    
     53
    5454    /**
    5555    @brief
     
    5959    {
    6060        RegisterObject(HealthPickup);
    61        
     61
    6262        this->initialize();
    6363    }
    64    
     64
    6565    /**
    6666    @brief
     
    6969    HealthPickup::~HealthPickup()
    7070    {
    71        
    72     }
    73    
    74     /**
    75     @brief 
     71
     72    }
     73
     74    /**
     75    @brief
    7676        Initializes the member variables.
    7777    */
    7878    void HealthPickup::initialize(void)
    79     {       
     79    {
    8080        this->health_ = 0;
    8181        this->healthRate_ = 0;
     
    8383        this->maxHealthSave_ = 0;
    8484        this->maxHealthOverwrite_ = 0;
    85        
     85
    8686        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
    8787    }
    88    
     88
    8989    /**
    9090    @brief
     
    9898        std::string val1 = stream.str();
    9999        this->pickupIdentifier_->addParameter(type1, val1);
    100        
     100
    101101        std::string val2 = this->getHealthType();
    102102        std::string type2 = "healthType";
    103103        this->pickupIdentifier_->addParameter(type2, val2);
    104        
     104
    105105        stream.clear();
    106106        stream << this->getHealthRate();
     
    109109        this->pickupIdentifier_->addParameter(type3, val3);
    110110    }
    111    
     111
    112112    /**
    113113    @brief
     
    117117    {
    118118        SUPER(HealthPickup, XMLPort, xmlelement, mode);
    119        
     119
    120120        XMLPortParam(HealthPickup, "health", setHealth, getHealth, xmlelement, mode);
    121121        XMLPortParam(HealthPickup, "healthRate", setHealthRate, getHealthRate, xmlelement, mode);
    122122        XMLPortParam(HealthPickup, "healthType", setHealthType, getHealthType, xmlelement, mode);
    123        
     123
    124124        if(!this->isContinuous())
    125125            this->healthRate_ = 0.0;
    126        
     126
    127127        this->initializeIdentifier();
    128128    }
    129    
     129
    130130    /**
    131131    @brief
     
    138138    {
    139139        SUPER(HealthPickup, tick, dt);
    140        
     140
    141141        if(this->isContinuous() && this->isUsed())
    142142        {
    143143            Pawn* pawn = this->carrierToPawnHelper();
    144144            if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    145                 this->destroy();
    146            
     145                this->Pickupable::destroy();
     146
    147147            //! Calculate the health that is added this tick.
    148148            float health = dt*this->getHealthRate();
     
    152152            float fullHealth = pawn->getHealth() + health;
    153153            this->setHealth(this->getHealth()-health);
    154                    
     154
    155155            switch(this->getHealthTypeDirect())
    156156            {
     
    173173                    COUT(1) << "Invalid healthType in HealthPickup." << std::endl;
    174174            }
    175            
     175
    176176            //! If all health has been transfered.
    177177            if(this->getHealth() == 0)
     
    181181        }
    182182    }
    183    
     183
    184184    /**
    185185    @brief
     
    189189    {
    190190        SUPER(HealthPickup, changedUsed);
    191        
     191
    192192        //! If the pickup is not picked up nothing must be done.
    193         if(!this->isPickedUp())
     193        if(!this->isPickedUp()) //TODO: Needed?
    194194            return;
    195        
     195
    196196        //! If the pickup has transited to used.
    197197        if(this->isUsed())
     
    201201                Pawn* pawn = this->carrierToPawnHelper();
    202202                if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    203                     this->destroy();
    204                
     203                    this->Pickupable::destroy();
     204
    205205                float health = 0;
    206206                switch(this->getHealthTypeDirect())
     
    226226                        COUT(1) << "Invalid healthType in HealthPickup." << std::endl;
    227227                }
    228                
     228
    229229                //! The pickup has been used up.
    230230                this->setUsed(false);
     
    237237                PickupCarrier* carrier = this->getCarrier();
    238238                Pawn* pawn = dynamic_cast<Pawn*>(carrier);
    239                
     239
    240240                if(pawn == NULL)
    241241                {
    242242                    COUT(1) << "Something went horribly wrong in Health Pickup. PickupCarrier is no Pawn." << std::endl;
    243                     this->destroy();
     243                    this->Pickupable::destroy();
    244244                    return;
    245245                }
    246                
     246
    247247                if(pawn->getMaxHealth() == this->maxHealthOverwrite_)
    248248                {
     
    252252                }
    253253            }
    254            
     254
    255255            //! If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
    256256            if(this->isOnce() || (this->isContinuous() && this->getHealth() == 0))
    257257            {
    258                 this->destroy();
    259             }
    260         }
    261     }
    262    
     258                this->Pickupable::destroy();
     259            }
     260        }
     261    }
     262
    263263    /**
    264264    @brief
     
    271271        PickupCarrier* carrier = this->getCarrier();
    272272        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
    273        
     273
    274274        if(pawn == NULL)
    275275        {
    276276            COUT(1) << "Invalid PickupCarrier in HealthPickup." << std::endl;
    277277        }
    278        
     278
    279279        return pawn;
    280280    }
    281    
     281
    282282    /**
    283283    @brief
     
    290290        if(item == NULL)
    291291            item = new HealthPickup(this);
    292        
     292
    293293        SUPER(HealthPickup, clone, item);
    294        
     294
    295295        HealthPickup* pickup = dynamic_cast<HealthPickup*>(item);
    296296        pickup->setHealth(this->getHealth());
    297297        pickup->setHealthRate(this->getHealthRate());
    298298        pickup->setHealthTypeDirect(this->getHealthTypeDirect());
    299        
     299
    300300        pickup->initializeIdentifier();
    301301    }
    302    
     302
    303303    /**
    304304    @brief
     
    322322        }
    323323    }
    324    
     324
    325325    /**
    326326    @brief
     
    341341        }
    342342    }
    343    
     343
    344344    /**
    345345    @brief
     
    356356        else
    357357        {
    358             COUT(1) << "Invalid healthSpeed in HealthPickup." << std::endl; 
    359         }
    360     }
    361    
     358            COUT(1) << "Invalid healthSpeed in HealthPickup." << std::endl;
     359        }
     360    }
     361
    362362    /**
    363363    @brief
  • code/trunk/src/modules/pickup/items/HealthPickup.h

    r6709 r7163  
    4545
    4646namespace orxonox {
    47    
     47
    4848    //! Enum for the type of the HealthPickup
    4949    namespace pickupHealthType
     
    5656        };
    5757    }
    58    
     58
    5959    /**
    6060    @brief
     
    7171    {
    7272        public:
    73        
     73
    7474            HealthPickup(BaseObject* creator); //!< Constructor.
    7575            virtual ~HealthPickup(); //!< Destructor.
    76            
     76
    7777            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
    7878            virtual void tick(float dt); //!< Is called every tick.
    79            
     79
    8080            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    8181            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    82            
     82
    8383            /**
    8484            @brief Get the health that is transfered to the Pawn upon usage of this pickup.
     
    9393            inline float getHealthRate(void)
    9494                { return this->healthRate_; }
    95                
     95
    9696            /**
    9797            @brief Get the type of HealthPickup, this pickup is.
    98             @return Returns the health type as an enum. 
     98            @return Returns the health type as an enum.
    9999            */
    100100            inline pickupHealthType::Value getHealthTypeDirect(void)
    101101                { return this->healthType_; }
    102102            const std::string& getHealthType(void); //!< Get the health type of this pickup.
    103            
     103
    104104        protected:
    105105            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
     
    107107            void setHealth(float health); //!< Sets the health.
    108108            void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous.
    109            
     109
    110110            /**
    111111            @brief Set the health type of this pickup.
     
    115115                { this->healthType_ = type; }
    116116            void setHealthType(std::string type); //!< Set the type of the HealthPickup.
    117        
     117
    118118        private:
    119119            void initialize(void); //!< Initializes the member variables.
    120120            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
    121            
     121
    122122            float health_; //!< The health that is transferred to the Pawn.
    123123            float healthRate_; //!< The rate at which the health is transferred.
     
    125125            float maxHealthOverwrite_; //!< Helper to remember with which value we overwrote the maxHealh, to detect if someone else changed it as well.
    126126            pickupHealthType::Value healthType_; //!< The type of the HealthPickup.
    127            
     127
    128128            //! Strings for the health types.
    129129            static const std::string healthTypeLimited_s;
    130130            static const std::string healthTypeTemporary_s;
    131131            static const std::string healthTypePermanent_s;
    132        
     132
    133133    };
    134134}
  • code/trunk/src/modules/pickup/items/InvisiblePickup.cc

    • Property svn:eol-style set to native
    r6755 r7163  
    3434#include "InvisiblePickup.h"
    3535
     36#include <sstream>
     37#include <OgreEntity.h>
     38#include <OgreAnimationState.h>
     39
     40#include "util/StringUtils.h"
    3641#include "core/CoreIncludes.h"
    3742#include "core/XMLPort.h"
    38 #include "util/StringUtils.h"
    3943
    4044#include "worldentities/pawns/Pawn.h"
    4145#include "pickup/PickupIdentifier.h"
    4246
    43 #include <sstream>
    44 
    4547namespace orxonox
    4648{
    4749
    4850    CreateFactory(InvisiblePickup);
    49    
     51
    5052    /**
    5153    @brief
     
    5658        RegisterObject(InvisiblePickup);
    5759        //! Defines who is allowed to pick up the pickup.
    58         this->initialize(); 
    59     }
    60    
     60        this->initialize();
     61    }
     62
    6163    /**
    6264    @brief
     
    6466    */
    6567    InvisiblePickup::~InvisiblePickup()
    66     {       
    67     }
    68    
    69    
     68    {
     69    }
     70
     71
    7072    void InvisiblePickup::initializeIdentifier(void)
    7173    {
     
    7678        this->pickupIdentifier_->addParameter(type1, val1);
    7779    }
    78    
     80
    7981    /**
    8082    @brief
     
    9395    void InvisiblePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
    9496    {
    95         SUPER(InvisiblePickup, XMLPort, xmlelement, mode);   
     97        SUPER(InvisiblePickup, XMLPort, xmlelement, mode);
    9698        XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode);
    97        
     99
    98100        this->initializeIdentifier();
    99101    }
    100    
     102
    101103    /**
    102104    @brief
     
    106108    {
    107109        SUPER(InvisiblePickup, changedUsed);
    108        
     110
    109111        //! If the pickup is not picked up nothing must be done.
    110112        if(!this->isPickedUp())
    111113            return;
    112        
     114
    113115        if (this->isUsed())
    114116        {
     
    121123                this->startPickupTimer(this->getDuration());
    122124            }
     125
    123126            this->setInvisible(true);
     127
    124128        }
    125129        else
    126130        {
    127131            this->setInvisible(false);
    128        
     132
    129133            if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
    130134            {
    131                 this->destroy();
     135                this->Pickupable::destroy();
    132136            }
    133137            else
     
    136140            }
    137141        }
    138        
    139     }
    140    
     142
     143    }
     144
    141145    /**
    142146    @brief
     
    149153        PickupCarrier* carrier = this->getCarrier();
    150154        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
    151        
     155
    152156        if(pawn == NULL)
    153157        {
     
    156160        return pawn;
    157161    }
    158    
     162
    159163    /**
    160164    @brief
     
    167171        if(item == NULL)
    168172            item = new InvisiblePickup(this);
    169        
     173
    170174        SUPER(InvisiblePickup, clone, item);
    171        
     175
    172176        InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item);
    173177        pickup->setDuration(this->getDuration());
    174178        pickup->initializeIdentifier();
    175179    }
    176    
     180
    177181    /**
    178182    @brief
     
    186190        if(pawn == NULL)
    187191            return false;
    188        
     192
    189193        pawn->setVisible(!invisibility);
     194        pawn->setRadarVisibility(!invisibility);
     195
     196// Test to change Material at runtime!
     197
     198//      Ogre::MaterialPtr mat = this->mesh_.getEntity()->getSubEntity(0)->getMaterial();
     199//      mat->setDiffuse(0.4, 0.3, 0.1, 0.1);
     200//      mat->setAmbient(0.3, 0.7, 0.8);
     201//      mat->setSpecular(0.5, 0.5, 0.5, 0.1);
     202//      Ogre::SceneBlendType sbt = Ogre::SBT_ADD;
     203//
     204//      mat->setSceneBlending(sbt);
     205
    190206        return true;
    191207    }
    192    
     208
    193209    /**
    194210    @brief
     
    209225        }
    210226    }
    211    
     227
    212228    void InvisiblePickup::pickupTimerCallback(void)
    213229    {
  • code/trunk/src/modules/pickup/items/InvisiblePickup.h

    • Property svn:eol-style set to native
    r6710 r7163  
    3838
    3939#include <string>
     40
    4041#include <worldentities/pawns/Pawn.h>
    4142#include "worldentities/StaticEntity.h"
    42 
    4343#include "pickup/Pickup.h"
    4444
    4545namespace orxonox {
    46        
     46
    4747    /**
    4848    @brief
     
    5757    {
    5858        public:
    59        
     59
    6060            InvisiblePickup(BaseObject* creator); //!< Constructor.
    6161            virtual ~InvisiblePickup(); //!< Destructor.
     
    6363            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    6464            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    65            
     65
    6666            /**
    6767            @brief Checks whether the Pawn is invisible.
     
    7272            inline float getDuration()
    7373                { return this->duration_; }
    74  
     74
    7575        protected:
    7676            bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again.
     
    7878            void initializeIdentifier(void);
    7979            virtual void pickupTimerCallback(void); //!< Function that gets called when the timer ends.
    80        
     80
    8181        private:
    8282            void initialize(void); //!< Initializes the member variables.
  • code/trunk/src/modules/pickup/items/MetaPickup.cc

    r6709 r7163  
    3434#include "core/CoreIncludes.h"
    3535#include "core/XMLPort.h"
     36#include "worldentities/pawns/Pawn.h"
    3637#include "interfaces/PickupCarrier.h"
    3738#include "pickup/PickupIdentifier.h"
     
    4041
    4142namespace orxonox {
    42  
     43
    4344    CreateFactory(MetaPickup);
    44    
     45
    4546    //! Setting the static variables to their values.
    4647    /*static*/ const std::string MetaPickup::metaTypeNone_s = "none";
    4748    /*static*/ const std::string MetaPickup::metaTypeUse_s = "use";
    4849    /*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop";
    49    
     50    /*static*/ const std::string MetaPickup::metaTypeDestroy_s = "destroy";
     51    /*static*/ const std::string MetaPickup::metaTypeDestroyCarrier_s = "destroyCarrier";
     52
    5053    /**
    5154    @brief
     
    5558    {
    5659        RegisterObject(MetaPickup);
    57        
     60
    5861        this->initialize();
    5962    }
    60    
     63
    6164    /**
    6265    @brief
     
    6568    MetaPickup::~MetaPickup()
    6669    {
    67        
    68     }
    69    
     70
     71    }
     72
    7073    /**
    7174    @brief
     
    7578    {
    7679        this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier());
    77        
     80
    7881        this->setActivationTypeDirect(pickupActivationType::immediate);
    7982        this->setDurationTypeDirect(pickupDurationType::once);
    8083        this->metaType_ = pickupMetaType::none;
    8184    }
    82    
     85
    8386    /**
    8487    @brief
     
    9194        this->pickupIdentifier_->addParameter(type, val);
    9295    }
    93    
     96
    9497    /**
    9598    @brief
     
    99102    {
    100103        SUPER(MetaPickup, XMLPort, xmlelement, mode);
    101        
     104
    102105        XMLPortParam(MetaPickup, "metaType", setMetaType, getMetaType, xmlelement, mode);
    103        
     106
    104107        this->initializeIdentifier();
    105108    }
    106    
     109
    107110    /**
    108111    @brief
     
    113116    {
    114117        SUPER(MetaPickup, changedUsed);
    115        
     118
    116119        //! If the MetaPickup transited to used.
    117120        if(this->isUsed())
     
    120123            if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL)
    121124            {
     125                if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier)
     126                {
     127                    Pawn* pawn = orxonox_cast<Pawn*>(carrier);
     128                    pawn->kill();
     129                    return;
     130                }
    122131                std::set<Pickupable*> pickups = carrier->getPickups();
    123                 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending o the meta type.
     132                //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending on the meta type.
    124133                for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++)
    125134                {
     
    136145                        if(pickup != NULL && pickup != this)
    137146                        {
    138                             carrier->drop(pickup);
     147                            pickup->drop();
     148                        }
     149                    }
     150                    if(this->getMetaTypeDirect() == pickupMetaType::destroy)
     151                    {
     152                        if(pickup != NULL && pickup != this)
     153                        {
     154                            pickup->Pickupable::destroy();
    139155                        }
    140156                    }
    141157                }
    142158            }
    143             this->destroy();
    144         }
    145     }
    146        
     159            this->Pickupable::destroy();
     160        }
     161    }
     162
    147163    /**
    148164    @brief
     
    155171        if(item == NULL)
    156172            item = new MetaPickup(this);
    157        
     173
    158174        SUPER(MetaPickup, clone, item);
    159        
     175
    160176        MetaPickup* pickup = dynamic_cast<MetaPickup*>(item);
    161177        pickup->setMetaTypeDirect(this->getMetaTypeDirect());
    162        
     178
    163179        pickup->initializeIdentifier();
    164180    }
    165    
     181
    166182    /**
    167183    @brief
     
    180196            case pickupMetaType::drop:
    181197                return MetaPickup::metaTypeDrop_s;
     198            case pickupMetaType::destroy:
     199                return MetaPickup::metaTypeDestroy_s;
     200            case pickupMetaType::destroyCarrier:
     201                return MetaPickup::metaTypeDestroyCarrier_s;
    182202            default:
    183203                return BLANKSTRING;
    184204        }
    185205    }
    186    
     206
    187207    /**
    188208    @brief
     
    205225            this->setMetaTypeDirect(pickupMetaType::drop);
    206226        }
    207     }
    208    
     227        else if(type == MetaPickup::metaTypeDestroy_s)
     228        {
     229            this->setMetaTypeDirect(pickupMetaType::destroy);
     230        }
     231        else if(type == MetaPickup::metaTypeDestroyCarrier_s)
     232        {
     233            this->setMetaTypeDirect(pickupMetaType::destroyCarrier);
     234        }
     235        else
     236            COUT(2) << "Invalid metaType '" << type << "' in MetaPickup." << std::endl;
     237    }
     238
    209239}
  • code/trunk/src/modules/pickup/items/MetaPickup.h

    r6709 r7163  
    4848            none,
    4949            use,
    50             drop
     50            drop,
     51            destroy,
     52            destroyCarrier
    5153        };
    5254    }
    53    
     55
    5456    /**
    5557    @brief
    56         The MetaPickup is a pickup that can, depending on the parameters, either drop all pickups of the PickupCarrier that picks it up, or use all the unused pickups of the PickupCarrier, that picks it up. The parameter to set for this is the metaType and it can be used with the values 'none', 'drop' and 'use'.
     58        The MetaPickup is a pickup that can, depending on the parameter 'metaType', do different things. If the 'metaType' is set to
     59        1) 'use', all the pickups, the PickupCarrier has, are immediately set to used upon pickup of the MetaPickup.
     60        2) 'drop', all the pickups, the PickupCarrier has, are immediately dropped upon pickup of the MetaPickup.
     61        3) 'destroy', all the pickups, the PickupCarrier has, are immediately destroyed upon pickup of the MetaPickup.
     62        4) 'destroyCarrier', the PickupCarrier is immediately destroyed upon pickup of the MetaPickup.
    5763    @author
    5864        Damian 'Mozork' Frick
     
    6066    class _PickupExport MetaPickup : public Pickup
    6167    {
    62        
     68
    6369        public:
    6470            MetaPickup(BaseObject* creator); //!< Constructor. Registers and initializes the object.
    6571            virtual ~MetaPickup(); //!< Destructor.
    66            
     72
    6773            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a MetaPickup object through XML.
    68            
     74
    6975            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    7076            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    71            
     77
    7278            /**
    7379            @brief Returns the meta type of the MetaPickup.
     
    7783                { return this->metaType_; }
    7884            const std::string& getMetaType(void); //!< Get the meta type of this MetaPickup.
    79            
     85
    8086        protected:
    8187            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    82            
     88
    8389            /**
    8490            @brief Set the meta type of the MetaPickup.
     
    8894                { this->metaType_ =  type; }
    8995            void setMetaType(const std::string& type); //!< Set the meta type of this MetaPickup.
    90            
     96
    9197        private:
    9298            void initialize(void); //!< Initializes the member variables.
    93            
     99
    94100            pickupMetaType::Value metaType_; //!< The meta type of the MetaPickup, determines which actions are taken.
    95            
     101
    96102            //! Static strings for the meta types.
    97103            static const std::string metaTypeNone_s;
    98104            static const std::string metaTypeUse_s;
    99105            static const std::string metaTypeDrop_s;
    100            
    101        
     106            static const std::string metaTypeDestroy_s;
     107            static const std::string metaTypeDestroyCarrier_s;
     108
     109
    102110    };
    103111
  • code/trunk/src/modules/pickup/items/SpeedPickup.cc

    r6755 r7163  
    136136        Engine* engine = this->carrierToEngineHelper();
    137137        if(engine == NULL) //!< If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed.
    138             this->destroy();
    139        
     138            this->Pickupable::destroy();
     139
    140140        //! If the pickup has transited to used.
    141141        if(this->isUsed())
     
    156156            engine->setSpeedAdd(0.0f);
    157157            engine->setSpeedMultiply(1.0f);
    158            
     158
    159159            if(this->isOnce())
    160160            {
    161161                if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
    162162                {
    163                     this->destroy();
     163                    this->Pickupable::destroy();
    164164                }
    165165                else
     
    186186            COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl;
    187187        }
    188        
     188
    189189        return engine;
    190190    }
     
    269269
    270270    void SpeedPickup::pickupTimerCallback(void)
    271     {       
     271    {
    272272        this->setUsed(false);
    273273    }
  • code/trunk/src/modules/pickup/items/SpeedPickup.h

    r6709 r7163  
    7878        protected:
    7979            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    80            
     80
    8181            virtual void pickupTimerCallback(void); //!< Function that gets called when timer ends.
    8282
  • code/trunk/src/modules/pong/CMakeLists.txt

    r5929 r7163  
    1414  MODULE
    1515  FIND_HEADER_FILES
    16   DEFINE_SYMBOL
    17     "PONG_SHARED_BUILD"
    1816  LINK_LIBRARIES
    1917    orxonox
  • code/trunk/src/modules/pong/PongBall.h

    r5929 r7163  
    4545            virtual void tick(float dt);
    4646
    47             void registerVariables();
    48 
    4947            void setFieldDimension(float width, float height)
    5048                { this->fieldWidth_ = width; this->fieldHeight_ = height; }
     
    7472
    7573        private:
     74            void registerVariables();
     75
    7676            float fieldWidth_;
    7777            float fieldHeight_;
  • code/trunk/src/modules/pong/PongBat.h

    r5781 r7163  
    4141            virtual ~PongBat() {}
    4242
    43             void registerVariables();
    4443            virtual void tick(float dt);
    4544
     
    6564
    6665        private:
     66            void registerVariables();
     67
    6768            float movement_;
    6869            bool bMoveLocal_;
  • code/trunk/src/modules/pong/PongPrereqs.h

    r5929 r7163  
    4343//-----------------------------------------------------------------------
    4444
    45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
     45#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(PONG_STATIC_BUILD)
    4646#  ifdef PONG_SHARED_BUILD
    4747#    define _PongExport __declspec(dllexport)
  • code/trunk/src/modules/questsystem/AddQuest.cc

    r5781 r7163  
    6868        SUPER(AddQuest, XMLPort, xmlelement, mode);
    6969
    70         COUT(3) << "New AddQuest, with target Quest {" << this->getQuestId() << "}, created." << std::endl;
     70        COUT(4) << "New AddQuest, with target Quest {" << this->getQuestId() << "}, created." << std::endl;
    7171    }
    7272
     
    8787        }
    8888
    89         COUT(3) << "AddQuest on player: " << player << " ." << std::endl;
     89        COUT(5) << "AddQuest on player: " << player << " ." << std::endl;
    9090
    9191        try
     
    103103        }
    104104
    105         COUT(3) << "Quest {" << this->getQuestId() << "} successfully added to player: " << player << " ." << std::endl;
     105        COUT(4) << "Quest {" << this->getQuestId() << "} successfully added to player: " << player << " ." << std::endl;
    106106        return true;
    107107    }
  • code/trunk/src/modules/questsystem/AddQuestHint.cc

    r6417 r7163  
    7272        XMLPortParam(AddQuestHint, "hintId", setHintId, getHintId, xmlelement, mode);
    7373
    74         COUT(3) << "New AddQuestHint, with target QuestHint {" << this->getHintId() << "}, created." << std::endl;
     74        COUT(4) << "New AddQuestHint, with target QuestHint {" << this->getHintId() << "}, created." << std::endl;
    7575    }
    7676
     
    8585    bool AddQuestHint::setHintId(const std::string & id)
    8686    {
    87         if(!QuestItem::isId(id))
     87        if(id.compare(BLANKSTRING) == 0)
    8888        {
    8989            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
     
    111111        }
    112112
    113         COUT(3) << "AddQuestHint on player: " << player << " ." << std::endl;
     113        COUT(5) << "AddQuestHint on player: " << player << " ." << std::endl;
    114114
    115115        try
     
    127127        }
    128128
    129         COUT(3) << "QuestHint {" << this->getHintId() << "} successfully added to player: " << player << " ." << std::endl;
     129        COUT(4) << "QuestHint {" << this->getHintId() << "} successfully added to player: " << player << " ." << std::endl;
    130130        return true;
    131131
  • code/trunk/src/modules/questsystem/AddReward.cc

    r6417 r7163  
    6868        XMLPortObject(AddReward, Rewardable, "", addRewardable, getRewardables, xmlelement, mode);
    6969
    70         COUT(3) << "New AddReward, with " << this->rewards_.size() << " Rewardables created." << std::endl;
     70        COUT(4) << "New AddReward, with " << this->rewards_.size() << " Rewardables created." << std::endl;
    7171    }
    7272
     
    103103    bool AddReward::invoke(PlayerInfo* player)
    104104    {
    105         COUT(3) << "AddReward on player: " << player << " ." << std::endl;
     105        COUT(5) << "AddReward on player: " << player << " ." << std::endl;
    106106
    107107        bool check = true;
     
    111111        }
    112112
    113         COUT(3) << "Rewardable successfully added to player." << player << " ." << std::endl;
     113        COUT(4) << "Rewardable successfully added to player." << player << " ." << std::endl;
    114114
    115115        return check;
  • code/trunk/src/modules/questsystem/CMakeLists.txt

    r6800 r7163  
    1212  QuestEffect.cc
    1313  QuestEffectBeacon.cc
    14   QuestGUINode.cc
    15   QuestGUI.cc
    1614  QuestHint.cc
    1715  QuestItem.cc
     
    2826  TOLUA_FILES
    2927    QuestManager.h
    30   DEFINE_SYMBOL
    31     "QUESTSYSTEM_SHARED_BUILD"
     28    QuestDescription.h
     29    Quest.h
     30    QuestHint.h
    3231  PCH_FILE
    3332    QuestsystemPrecompiledHeaders.h
  • code/trunk/src/modules/questsystem/ChangeQuestStatus.cc

    r6417 r7163  
    7878    bool ChangeQuestStatus::setQuestId(const std::string & id)
    7979    {
    80         if(!QuestItem::isId(id))
     80        if(id.compare(BLANKSTRING) == 0)
    8181        {
    8282            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
  • code/trunk/src/modules/questsystem/CompleteQuest.cc

    r6417 r7163  
    6868        SUPER(CompleteQuest, XMLPort, xmlelement, mode);
    6969
    70         COUT(3) << "New CompleteQuest, with target Quest {" << this->getQuestId() << "}, created." << std::endl;
     70        COUT(4) << "New CompleteQuest, with target Quest {" << this->getQuestId() << "}, created." << std::endl;
    7171    }
    7272
     
    8787        }
    8888
    89         COUT(3) << "CompleteQuest on player: " << player << " ." << std::endl;
     89        COUT(5) << "CompleteQuest on player: " << player << " ." << std::endl;
    9090
    9191        Quest* quest;
     
    105105        }
    106106
    107         COUT(3) << "Quest {" << quest->getId() << "} successfully completed by player: " << player << " ." << std::endl;
     107        COUT(4) << "Quest {" << quest->getId() << "} successfully completed by player: " << player << " ." << std::endl;
    108108        return true;
    109109    }
  • code/trunk/src/modules/questsystem/FailQuest.cc

    r6417 r7163  
    6868        SUPER(FailQuest, XMLPort, xmlelement, mode);
    6969
    70         COUT(3) << "New FailQUest, with target Quest {" << this->getQuestId() << "}, created." << std::endl;
     70        COUT(4) << "New FailQUest, with target Quest {" << this->getQuestId() << "}, created." << std::endl;
    7171    }
    7272
     
    8787        }
    8888
    89         COUT(3) << "FailQuest on player: " << player << " ." << std::endl;
     89        COUT(4) << "FailQuest on player: " << player << " ." << std::endl;
    9090
    9191        Quest* quest;
     
    104104        }
    105105
    106         COUT(3) << "Quest {" << quest->getId() << "} failed by player: " << player << " ." << std::endl;
     106        COUT(4) << "Quest {" << quest->getId() << "} failed by player: " << player << " ." << std::endl;
    107107        return true;
    108108    }
  • code/trunk/src/modules/questsystem/GlobalQuest.cc

    r6417 r7163  
    7070        XMLPortObject(GlobalQuest, QuestEffect, "reward-effects", addRewardEffect, getRewardEffects, xmlelement, mode);
    7171
    72         COUT(3) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
     72        COUT(4) << "New GlobalQuest {" << this->getId() << "} created." << std::endl;
    7373    }
    7474
     
    253253        this->rewards_.push_back(effect); //!< Add the QuestEffect to the list.
    254254
    255         COUT(3) << "Reward effect was added to Quest {" << this->getId() << "}." << std::endl;
     255        COUT(4) << "Reward effect was added to Quest {" << this->getId() << "}." << std::endl;
    256256        return true;
    257257    }
  • code/trunk/src/modules/questsystem/LocalQuest.cc

    r6417 r7163  
    6868        SUPER(LocalQuest, XMLPort, xmlelement, mode);
    6969
    70         COUT(3) << "New LocalQuest {" << this->getId() << "} created." << std::endl;
     70        COUT(4) << "New LocalQuest {" << this->getId() << "} created." << std::endl;
    7171    }
    7272
  • code/trunk/src/modules/questsystem/Quest.cc

    r6417 r7163  
    6161    Quest::~Quest()
    6262    {
    63 
     63        if(this->isRegistered())
     64            QuestManager::getInstance().unregisterQuest(this);
    6465    }
    6566
     
    9899        this->parentQuest_ = quest;
    99100
    100         COUT(3) << "Parent Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
     101        COUT(4) << "Parent Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
    101102        return true;
    102103    }
     
    121122        this->subQuests_.push_back(quest); //!< Adds the Quest to the end of the list of subquests.
    122123
    123         COUT(3) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
     124        COUT(4) << "Sub Quest {" << quest->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
    124125        return true;
    125126    }
     
    145146        this->hints_.push_back(hint); //!< Adds the QuestHint to the end of the list of QuestHints.
    146147
    147         COUT(3) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
     148        COUT(4) << "QuestHint {" << hint->getId() << "} was added to Quest {" << this->getId() << "}." << std::endl;
    148149        return true;
    149150    }
     
    167168        this->failEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of fail QuestEffects.
    168169
    169         COUT(3) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl;
     170        COUT(4) << "A FailEffect was added to Quest {" << this->getId() << "}." << std::endl;
    170171        return true;
    171172    }
     
    189190        this->completeEffects_.push_back(effect); //!< Adds the QuestEffect to the end of the list of complete QuestEffects.
    190191
    191         COUT(3) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl;
     192        COUT(4) << "A CompleteEffect was added to Quest {" << this->getId() << "}." << std::endl;
    192193        return true;
    193194    }
  • code/trunk/src/modules/questsystem/Quest.h

    r5781 r7163  
    4141#include "QuestItem.h"
    4242
    43 namespace orxonox
    44 {
     43namespace orxonox // tolua_export
     44{ // tolua_export
    4545    namespace QuestStatus
    4646    {
     
    6767        Damian 'Mozork' Frick
    6868    */
    69     class _QuestsystemExport Quest : public QuestItem
    70     {
     69    class _QuestsystemExport Quest // tolua_export
     70        : public QuestItem
     71    { // tolua_export
    7172        public:
    7273            Quest(BaseObject* creator);
     
    9798
    9899            bool isInactive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'inactive'.
    99             bool isActive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'active'.
    100             bool isFailed(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'failed'.
    101             bool isCompleted(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'completed'.
     100            bool isActive(const orxonox::PlayerInfo* player) const; // tolua_export //!< Returns true if the quest status for the specific player is 'active'.
     101            bool isFailed(const orxonox::PlayerInfo* player) const; // tolua_export //!< Returns true if the quest status for the specific player is 'failed'.
     102            bool isCompleted(const orxonox::PlayerInfo* player) const; // tolua_export //!< Returns true if the quest status for the specific player is 'completed'.
    102103
    103104            bool start(PlayerInfo* player); //!< Sets a Quest to active.
     
    151152            bool addCompleteEffect(QuestEffect* effect); //!< Adds an QuestEffect to the list of complete QuestEffects.
    152153
    153     };
     154    }; // tolua_export
    154155
    155 }
     156} // tolua_export
    156157
    157158#endif /* _Quest_H__ */
  • code/trunk/src/modules/questsystem/QuestDescription.cc

    r6417 r7163  
    7474        XMLPortParam(QuestDescription, "completeMessage", setCompleteMessage, getCompleteMessage, xmlelement, mode);
    7575
    76         COUT(3) << "New QuestDescription with title '" << this->getTitle() << "' created." << std::endl;
     76        COUT(4) << "New QuestDescription with title '" << this->getTitle() << "' created." << std::endl;
    7777    }
    7878
     
    8989        Make sure the messages meet the conditions.
    9090    */
    91     bool QuestDescription::notificationHelper(const std::string & item, const std::string & status) const
     91    bool QuestDescription::notificationHelper(const std::string & item, const std::string & status)
    9292    {
    9393        std::string message;
     
    122122        }
    123123
    124         QuestNotification* notification = new QuestNotification(message);
     124        QuestNotification* notification = new QuestNotification(this, message);
    125125        notification->send();
    126126        return true;
  • code/trunk/src/modules/questsystem/QuestDescription.h

    r5781 r7163  
    8383            @return Returns a string containing the fail message of the QuestDescription.
    8484            */
    85             inline const std::string & getFailMessage(void) const
     85            inline const std::string & getFailMessage(void)
    8686                { return this->failMessage_; }
    8787
     
    9090            @return Returns a string containing the complete message of the QuestDescription.
    9191            */
    92             inline const std::string & getCompleteMessage(void) const
     92            inline const std::string & getCompleteMessage(void)
    9393                { return this->completeMessage_; }
    9494
     
    9797            @return Returns true if successful.
    9898            */
    99             inline bool sendAddHintNotification(void) const
     99            inline bool sendAddHintNotification(void)
    100100                { return notificationHelper("hint", ""); }
    101101
     
    104104            @return Returns true if successful.
    105105            */
    106             inline bool sendAddQuestNotification(void) const
     106            inline bool sendAddQuestNotification(void)
    107107                { return notificationHelper("quest", "start"); }
    108108
     
    111111            @return Returns true if successful.
    112112            */
    113             inline bool sendFailQuestNotification(void) const
     113            inline bool sendFailQuestNotification(void)
    114114                { return notificationHelper("quest", "fail"); }
    115115
     
    118118            @return Returns true if successful.
    119119            */
    120             inline bool sendCompleteQuestNotification(void) const
     120            inline bool sendCompleteQuestNotification(void)
    121121                { return notificationHelper("quest", "complete"); }
    122122
     
    127127            std::string completeMessage_; //!< The message displayed when the Quest is completed.
    128128
    129             bool notificationHelper(const std::string & item, const std::string & status) const; //!< Helper for sending QuestDescriptions as Notifications.
     129            bool notificationHelper(const std::string & item, const std::string & status); //!< Helper for sending QuestDescriptions as Notifications.
    130130
    131131            /**
  • code/trunk/src/modules/questsystem/QuestEffectBeacon.cc

    r6906 r7163  
    7878        XMLPortEventSink(QuestEffectBeacon, BaseObject, "execute", execute, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
    7979
    80         COUT(3) << "New QuestEffectBeacon created." << std::endl;
     80        COUT(4) << "New QuestEffectBeacon created." << std::endl;
    8181    }
    8282
     
    112112        MultiTriggerContainer* mTrigger = orxonox_cast<MultiTriggerContainer*>(trigger);
    113113        Pawn* pawn = NULL;
    114        
     114
    115115        //! If the trigger is neither a Playertrigger nor a MultiTrigger (i.e. a MultitriggerContainer) we can do anything with it.
    116116        if(pTrigger == NULL && mTrigger == NULL)
    117117            return false;
    118        
    119         // If the trigger is a PlayerTrigger.       
     118
     119        // If the trigger is a PlayerTrigger.
    120120        if(pTrigger != NULL)
    121121        {
     
    125125                pawn = pTrigger->getTriggeringPlayer();
    126126        }
    127        
     127
    128128        // If the trigger is a MultiTrigger (i.e. a MultiTriggerContainer)
    129129        if(mTrigger != NULL)
     
    134134        if(pawn == NULL)
    135135        {
    136             COUT(2) << "The QuestEffectBeacon was triggered by an entity other than a Pawn." << std::endl;
     136            COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
    137137            return false;
    138138        }
     
    147147        }
    148148
    149         COUT(3) << "QuestEffectBeacon executed on player: " << player << " ." << std::endl;
     149        COUT(4) << "QuestEffectBeacon executed on player: " << player << " ." << std::endl;
    150150
    151151        bool check = QuestEffect::invokeEffects(player, this->effects_); //!< Invoke the QuestEffects on the PlayerInfo.
     
    249249        this->effects_.push_back(effect);
    250250
    251         COUT(3) << "A QuestEffect was added to a QuestEffectBeacon." << std::endl;
     251        COUT(4) << "A QuestEffect was added to a QuestEffectBeacon." << std::endl;
    252252        return true;
    253253    }
  • code/trunk/src/modules/questsystem/QuestHint.cc

    r6417 r7163  
    5959    QuestHint::~QuestHint()
    6060    {
    61 
     61        if(this->isRegistered())
     62            QuestManager::getInstance().unregisterHint(this);
    6263    }
    6364
     
    7273        QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager.
    7374
    74         COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
     75        COUT(4) << "New QuestHint {" << this->getId() << "} created." << std::endl;
    7576    }
    7677
     
    125126            else
    126127            {
    127                 COUT(2) << "An already active questHint was trying to get activated." << std::endl;
     128                COUT(4) << "An already active questHint was trying to get activated." << std::endl;
    128129                return false;
    129130            }
    130131        }
    131132
    132         COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl;
     133        COUT(4) << "A hint of a non-active quest was trying to get activated." << std::endl;
    133134        return false;
    134135    }
  • code/trunk/src/modules/questsystem/QuestHint.h

    r5781 r7163  
    4040#include "QuestItem.h"
    4141
    42 namespace orxonox
    43 {
     42namespace orxonox // tolua_export
     43{ // tolua_export
    4444    namespace QuestHintStatus
    4545    {
     
    6666        Damian 'Mozork' Frick
    6767    */
    68     class _QuestsystemExport QuestHint : public QuestItem
    69     {
     68    class _QuestsystemExport QuestHint // tolua_export
     69        : public QuestItem
     70    { // tolua_export
    7071
    7172        public:
     
    9192            std::map<const PlayerInfo*, QuestHintStatus::Value> playerStatus_; //!< List of the states for each player, with the Player-pointer as key.
    9293
    93     };
     94    }; // tolua_export
    9495
    95 }
     96} // tolua_export
    9697
    9798#endif /* _QuestHint_H__ */
  • code/trunk/src/modules/questsystem/QuestItem.cc

    r6417 r7163  
    4040namespace orxonox
    4141{
     42
     43    CreateUnloadableFactory(QuestItem);
     44
    4245    /**
    4346    @brief
     
    4649    QuestItem::QuestItem(BaseObject* creator) : BaseObject(creator)
    4750    {
     51        this->registered_ = false;
     52
    4853        RegisterObject(QuestItem);
    4954    }
     
    7984    void QuestItem::setId(const std::string & id)
    8085    {
    81         if(!isId(id)) //!< Checks whether the id is a valid id.
     86        if(id.compare(BLANKSTRING) == 0) //!< Checks whether the id is a valid id.
    8287        {
    8388            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
     
    8893    }
    8994
    90     /**
    91     @brief
    92         Checks whether an input id is of the required form.
    93     @param id
    94         The id to be checked.
    95     @return
    96         Returns true if the string is likely to be of the required form.
    97     */
    98     /*static*/ bool QuestItem::isId(const std::string & id)
    99     {
    100         return id.size() >= 32;
    101     }
    102 
    10395}
  • code/trunk/src/modules/questsystem/QuestItem.h

    r5781 r7163  
    4141#include <string>
    4242#include "core/BaseObject.h"
     43#include "QuestManager.h"
    4344
    4445namespace orxonox
     
    7172            @return Returns a pointer to the QuestDescription object of the QuestItem.
    7273            */
    73             inline const QuestDescription* getDescription(void) const
     74            inline QuestDescription* getDescription(void) const
    7475                { return this->description_; }
    7576
    76             static bool isId(const std::string & id); //!< Checks whether a given id is valid.
     77            /**
     78            @brief Check whether the QuestItem is registered with the QuestManager.
     79            @return Returns true if the QuestItem is registered with the QuestManager.
     80            */
     81            inline bool isRegistered(void)
     82                { return this->registered_; }
     83            /**
     84            @brief Set the QuestItem as being registered with the QuestManager.
     85            */
     86            inline void setRegistered(void)
     87                { this->registered_ = true; }
    7788
    7889        protected:
     
    90101            QuestDescription* description_; //!< The QuestDescription of the QuestItem.
    91102
     103            bool registered_;
     104
    92105    };
    93106
  • code/trunk/src/modules/questsystem/QuestListener.cc

    r6417 r7163  
    7474        XMLPortParam(QuestListener, "mode", setMode, getMode, xmlelement, mode);
    7575
    76         this->quest_->addListener(this); //!< Adds the QuestListener to the Quests list of listeners.
    77 
    78         COUT(3) << "QuestListener created for quest: {" << this->quest_->getId() << "} with mode '" << this->getMode() << "'." << std::endl;
     76        if(this->quest_ != NULL)
     77            this->quest_->addListener(this); //!< Adds the QuestListener to the Quests list of listeners.
     78
     79        COUT(4) << "QuestListener created for quest: {" << this->quest_->getId() << "} with mode '" << this->getMode() << "'." << std::endl;
    7980    }
    8081
  • code/trunk/src/modules/questsystem/QuestManager.cc

    r6536 r7163  
    7474    QuestManager::~QuestManager()
    7575    {
    76         for(std::map<PlayerInfo*, QuestGUI*>::iterator it = this->questGUIs_.begin(); it != this->questGUIs_.end(); it++)
    77         {
    78             it->second->destroy();
    79         }
    80         this->questGUIs_.clear();
     76
    8177    }
    8278
     
    114110        if(result.second) //!< If inserting was a success.
    115111        {
    116             COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
     112            quest->setRegistered();
     113            COUT(4) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
    117114            return true;
    118115        }
     
    122119           return false;
    123120        }
     121    }
     122
     123    /**
     124    @brief
     125        Unregisters a Quest in the QuestManager.
     126    */
     127    bool QuestManager::unregisterQuest(Quest* quest)
     128    {
     129        return this->questMap_.erase(quest->getId()) == 1;
    124130    }
    125131
     
    146152        if(result.second) //!< If inserting was a success.
    147153        {
    148             COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
     154            hint->setRegistered();
     155            COUT(4) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
    149156            return true;
    150157        }
     
    154161           return false;
    155162        }
     163    }
     164
     165    /**
     166    @brief
     167        Unregisters a QuestHint in the QuestManager.
     168    */
     169    bool QuestManager::unregisterHint(QuestHint* hint)
     170    {
     171        return this->hintMap_.erase(hint->getId()) == 1;
    156172    }
    157173
     
    169185    Quest* QuestManager::findQuest(const std::string & questId)
    170186    {
    171         if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
     187        if(questId.compare(BLANKSTRING) == 1) //!< Check vor validity of the given id.
    172188        {
    173189            ThrowException(Argument, "Invalid questId.");
     
    203219    QuestHint* QuestManager::findHint(const std::string & hintId)
    204220    {
    205         if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
     221        if(hintId.compare(BLANKSTRING) == 1) //!< Check vor validity of the given id.
    206222        {
    207223            ThrowException(Argument, "Invalid hintId.");
     
    224240    }
    225241
    226     /**
    227     @brief
    228         Retreive the main window for the GUI.
    229         This is for the use in the lua script tu start the QuestGUI.
    230     @param guiName
    231         The name of the GUI.
    232     @return
    233         Returns a CEGUI Window.
    234     */
    235     CEGUI::Window* QuestManager::getQuestGUI(const std::string & guiName)
    236     {
    237         PlayerInfo* player = this->retrievePlayer(guiName);
    238 
    239         if(this->questGUIs_.find(player) == this->questGUIs_.end()) //!< Create a new GUI, if there is none, yet.
    240             this->questGUIs_[player] = new QuestGUI(player);
    241 
    242         return this->questGUIs_[player]->getGUI();
     242    int QuestManager::getNumParentQuests(PlayerInfo* player)
     243    {
     244        int numQuests = 0;
     245        for(std::map<std::string, Quest*>::iterator it = this->questMap_.begin(); it != this->questMap_.end(); it++)
     246        {
     247            if(it->second->getParentQuest() == NULL && !it->second->isInactive(player))
     248                numQuests++;
     249        }
     250        return numQuests;
     251    }
     252
     253    Quest* QuestManager::getParentQuest(PlayerInfo* player, int index)
     254    {
     255        for(std::map<std::string, Quest*>::iterator it = this->questMap_.begin(); it != this->questMap_.end(); it++)
     256        {
     257            if(it->second->getParentQuest() == NULL && !it->second->isInactive(player) && index-- == 0)
     258                return it->second;
     259        }
     260        return NULL;
     261    }
     262
     263    int QuestManager::getNumSubQuests(Quest* quest, PlayerInfo* player)
     264    {
     265        std::list<Quest*> quests = quest->getSubQuestList();
     266        int numQuests = 0;
     267        for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
     268        {
     269            if(!(*it)->isInactive(player))
     270                numQuests++;
     271        }
     272        return numQuests;
     273    }
     274
     275    Quest* QuestManager::getSubQuest(Quest* quest, PlayerInfo* player, int index)
     276    {
     277        std::list<Quest*> quests = quest->getSubQuestList();
     278        for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
     279        {
     280            if(!(*it)->isInactive(player) && index-- == 0)
     281                return *it;
     282        }
     283        return NULL;
     284    }
     285
     286    int QuestManager::getNumHints(Quest* quest, PlayerInfo* player)
     287    {
     288        std::list<QuestHint*> hints = quest->getHintsList();
     289        int numHints = 0;
     290        for(std::list<QuestHint*>::iterator it = hints.begin(); it != hints.end(); it++)
     291        {
     292            if((*it)->isActive(player))
     293                numHints++;
     294        }
     295        return numHints;
     296    }
     297
     298    QuestHint* QuestManager::getHints(Quest* quest, PlayerInfo* player, int index)
     299    {
     300        std::list<QuestHint*> hints = quest->getHintsList();
     301        for(std::list<QuestHint*>::iterator it = hints.begin(); it != hints.end(); it++)
     302        {
     303            if((*it)->isActive(player) && index-- == 0)
     304                return *it;
     305        }
     306        return NULL;
     307    }
     308
     309    QuestDescription* QuestManager::getDescription(Quest* item)
     310    {
     311        return item->getDescription();
     312    }
     313
     314    QuestDescription* QuestManager::getDescription(QuestHint* item)
     315    {
     316        return item->getDescription();
    243317    }
    244318
  • code/trunk/src/modules/questsystem/QuestManager.h

    r6536 r7163  
    3636
    3737#include "questsystem/QuestsystemPrereqs.h"
    38 #include <CEGUIForwardRefs.h>
    3938
    4039#include <list>
     
    4443#include "util/Singleton.h"
    4544#include "core/OrxonoxClass.h"
    46 
    47 #include "QuestGUI.h"
    4845
    4946// tolua_begin
     
    6360
    6461            friend class Singleton<QuestManager>;
    65             friend class QuestGUI;
    6662
    6763        public:
     
    7268            static QuestManager& getInstance() { return Singleton<QuestManager>::getInstance(); } // tolua_export
    7369
    74             //! Retrieve the main window for the GUI.
    75             CEGUI::Window* getQuestGUI(const std::string & guiName); // tolua_export
     70            // tolua_begin
     71            int getNumParentQuests(orxonox::PlayerInfo* player);
     72            Quest* getParentQuest(orxonox::PlayerInfo* player, int index);
     73
     74            int getNumSubQuests(Quest* quest, orxonox::PlayerInfo* player);
     75            Quest* getSubQuest(Quest* quest, orxonox::PlayerInfo* player, int index);
     76
     77            int getNumHints(Quest* quest, orxonox::PlayerInfo* player);
     78            QuestHint* getHints(Quest* quest, orxonox::PlayerInfo* player, int index);
     79
     80            QuestDescription* getDescription(Quest* item);
     81            QuestDescription* getDescription(QuestHint* item);
     82            // tolua_end
    7683
    7784            bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
    78             bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
     85            bool unregisterQuest(Quest* quest); //!< Unregisters a Quest in the QuestManager.
     86            bool registerHint(QuestHint* hint); //!< Registers a QuestHint in the QuestManager.
     87            bool unregisterHint(QuestHint* hint); //!< Unregisters a QuestHint in the QuestManager.
    7988
    8089            Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
     
    91100            std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
    92101
    93             std::map<PlayerInfo*, QuestGUI*> questGUIs_; //!< All GUI's registered by the players.
    94 
    95102    }; // tolua_export
    96103
  • code/trunk/src/modules/questsystem/QuestNotification.cc

    r6417 r7163  
    3232namespace orxonox {
    3333
    34     const std::string QuestNotification::SENDER("questsystem");
     34    /*static*/ const std::string QuestNotification::SENDER("questsystem");
    3535
     36    CreateUnloadableFactory(QuestNotification);
     37
     38    /**
     39    @brief
     40        Default Constructor. Creates a useless QuestNotification.
     41    */
    3642    QuestNotification::QuestNotification(BaseObject* creator) : Notification(creator)
    3743    {
    38         this->initialize();
     44        RegisterObject(QuestNotification);
    3945    }
    4046
    41     QuestNotification::QuestNotification(const std::string & message) : Notification(message)
     47    /**
     48    @brief
     49        Creates a QuestNotification with the input message.
     50    @param message
     51        The message to be sent.
     52    */
     53    QuestNotification::QuestNotification(BaseObject* creator, const std::string & message) : Notification(creator, message)
    4254    {
    43         this->initialize();
     55        RegisterObject(QuestNotification);
    4456    }
    4557
     58    /**
     59    @brief
     60        Destructor.
     61    */
    4662    QuestNotification::~QuestNotification()
    4763    {
     
    4965    }
    5066
     67    /**
     68    @brief
     69        Send the QuestNotification.
     70    @return
     71        Returns true if successful.
     72    */
    5173    bool QuestNotification::send(void)
    5274    {
     
    5476    }
    5577
    56     void QuestNotification::initialize(void)
    57     {
    58         RegisterObject(QuestNotification);
    59     }
    60 
    6178
    6279}
  • code/trunk/src/modules/questsystem/QuestNotification.h

    • Property svn:executable deleted
    r5781 r7163  
    3939    /**
    4040    @brief
    41 
     41        The QuestNotification is a special Notification that has the single property that it is only sent by the questsystem.
    4242    @author
    4343        Damian 'Mozork' Frick
     
    4646    {
    4747        public:
    48             QuestNotification(BaseObject* creator);
    49             QuestNotification(const std::string & message);
    50             virtual ~QuestNotification();
     48            QuestNotification(BaseObject* creator); //!< Default Constructor.
     49            QuestNotification(BaseObject* creator, const std::string & message); //!< Constructor.
     50            virtual ~QuestNotification(); //!< Destructor.
    5151
    52             bool send(void);
     52            bool send(void); //!< Send the QuestNotification.
    5353
    5454        private:
    55             static const std::string SENDER;
    56 
    57             void initialize(void);
     55            static const std::string SENDER; //!< A string identifying the questsystem as the sender.
    5856
    5957    };
  • code/trunk/src/modules/questsystem/QuestsystemPrereqs.h

    r5929 r7163  
    4343//-----------------------------------------------------------------------
    4444
    45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
     45#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(QUESTSYSTEM_STATIC_BUILD)
    4646#  ifdef QUESTSYSTEM_SHARED_BUILD
    4747#    define _QuestsystemExport __declspec(dllexport)
     
    7777    class QuestEffect;
    7878    class QuestEffectBeacon;
    79     class QuestGUI;
    80     class QuestGUINode;
    8179    class QuestHint;
    8280    class QuestItem;
  • code/trunk/src/modules/questsystem/notifications/Notification.cc

    r6417 r7163  
    4040{
    4141
     42    CreateUnloadableFactory(Notification);
     43
    4244    /**
    4345    @brief
     
    5658        The message of the Notification.
    5759    */
    58     Notification::Notification(const std::string & message) : BaseObject(NULL)
     60    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator)
    5961    {
    6062        this->message_ = message;
     
    6769    Notification::~Notification()
    6870    {
     71
    6972    }
    7073
  • code/trunk/src/modules/questsystem/notifications/Notification.h

    r5781 r7163  
    5353        public:
    5454            Notification(BaseObject* creator);
    55             Notification(const std::string & message);
     55            Notification(BaseObject* creator, const std::string & message);
    5656            virtual ~Notification();
    5757
  • code/trunk/src/modules/questsystem/notifications/NotificationManager.cc

    r6417 r7163  
    6666    NotificationManager::~NotificationManager()
    6767    {
     68
    6869    }
    6970
     
    101102                this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener.
    102103                it->first->update(notification, time); //!< Update the listener.
     104                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification);
     105                if(counterIt == this->listenerCounter_.end())
     106                    this->listenerCounter_[notification] = 1;
     107                else
     108                    this->listenerCounter_[notification] = counterIt->second + 1;
    103109            }
    104110        }
    105111
    106         COUT(3) << "Notification registered with the NotificationManager." << std::endl;
     112        COUT(4) << "Notification registered with the NotificationManager." << std::endl;
    107113
    108114        return true;
     115    }
     116
     117    /**
     118    @brief
     119        Unregisters a Notification within the NotificationManager.
     120    @param notification
     121        A pointer to the Notification to be unregistered.
     122    @param listener
     123        A pointer to the NotificationListener the Notification is unregistered for.
     124    */
     125    void NotificationManager::unregisterNotification(Notification* notification, NotificationListener* listener)
     126    {
     127        assert(notification);
     128        assert(listener);
     129
     130        // If the Notification was removed from the list of Notifications of the input NotificationListener, the counter for the Notification of the number of NotificationListeners it is present in is decremented.
     131        if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)))
     132            this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
     133
     134        // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed.
     135        if(this->listenerCounter_[notification] == (unsigned int) 0)
     136        {
     137            this->removeNotification(notification, this->allNotificationsList_);
     138            this->listenerCounter_.erase(notification);
     139            notification->destroy();
     140        }
     141
     142        COUT(4) << "Notification unregistered with the NotificationManager." << std::endl;
     143    }
     144
     145    /**
     146    @brief
     147        Helper method that removes an input notification form an input map.
     148    @param notification
     149        A pointer to the notification to be removed.
     150    @param map
     151        The map the notification should be removed from.
     152    @return
     153        Returns true if successful.
     154    */
     155    bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map)
     156    {
     157        // Iterates through all items in the map until the Notification is found.
     158        //TODO: Do more efficiently?
     159        for(std::multimap<std::time_t, Notification*>::iterator it = map.begin(); it != map.end(); it++)
     160        {
     161            if(it->second == notification)
     162            {
     163                map.erase(it);
     164                return true;
     165            }
     166        }
     167        return false;
    109168    }
    110169
     
    130189        {
    131190            this->notificationLists_[index] = &this->allNotificationsList_;
    132             COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
     191            COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    133192            return true;
    134193        }
     
    142201            if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
    143202            {
    144                 map.insert(std::pair<std::time_t,Notification*>(it->first, it->second));
     203                map.insert(std::pair<std::time_t, Notification*>(it->first, it->second));
     204                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second);
     205                if(counterIt == this->listenerCounter_.end())
     206                    this->listenerCounter_[it->second] = 1;
     207                else
     208                    this->listenerCounter_[it->second] = counterIt->second + 1;
    145209            }
    146210        }
     
    148212        listener->update(); //!< Update the listener.
    149213
    150         COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
     214        COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    151215
    152216        return true;
     217    }
     218
     219    /**
     220    @brief
     221        Unregisters a NotificationListener withing the NotificationManager.
     222    */
     223    void NotificationManager::unregisterListener(NotificationListener* listener)
     224    {
     225        assert(listener);
     226
     227        int identifier = this->listenerList_.find(listener)->second;
     228        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
     229
     230        // Make sure all Notifications are removed.
     231        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
     232        while(it != map->end())
     233        {
     234            this->unregisterNotification(it->second, listener);
     235            it = map->begin();
     236        }
     237
     238        this->listenerList_.erase(listener);
     239        this->notificationLists_.erase(identifier);
     240
     241        // If the map is not the map of all notifications, delete it.
     242        if(map != &this->allNotificationsList_)
     243            delete map;
     244
     245        COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl;
    153246    }
    154247
  • code/trunk/src/modules/questsystem/notifications/NotificationManager.h

    r5929 r7163  
    6060            virtual ~NotificationManager();
    6161
    62             static const std::string ALL;
    63             static const std::string NONE;
     62            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.
     63            static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
    6464
    6565            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
     66            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager.
    6667            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
     68            void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
    6769
    6870            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.
     
    9092            static NotificationManager* singletonPtr_s;
    9193
    92             int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
     94            int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
    9395
    94             std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps).
     96            std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored.
    9597            std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
    9698            std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
     99            std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with.
    97100
     101            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map.
    98102
    99103    };
  • code/trunk/src/modules/questsystem/notifications/NotificationOverlay.cc

    • Property svn:executable deleted
  • code/trunk/src/modules/questsystem/notifications/NotificationOverlay.h

    • Property svn:executable deleted
  • code/trunk/src/modules/questsystem/notifications/NotificationQueue.cc

    r6502 r7163  
    3434#include "NotificationQueue.h"
    3535
    36 #include <sstream>
    37 
     36#include "util/Convert.h"
    3837#include "core/CoreIncludes.h"
    3938#include "core/XMLPort.h"
     
    5655    NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator)
    5756    {
     57        this->registered_ = false;
     58
    5859        RegisterObject(NotificationQueue);
    5960        this->initialize();
     
    6869        this->targets_.clear();
    6970        this->clear();
     71
     72        if(this->registered_)
     73            NotificationManager::getInstance().unregisterListener(this);
    7074    }
    7175
     
    8185
    8286        NotificationManager::getInstance().registerListener(this);
     87        this->registered_ = true;
    8388    }
    8489
     
    118123        XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode);
    119124
    120         COUT(3) << "NotificationQueue created." << std::endl;
     125        COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
    121126    }
    122127
     
    173178        delete notifications;
    174179
    175         COUT(3) << "NotificationQueue updated." << std::endl;
     180        COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;
    176181    }
    177182
     
    196201        }
    197202
    198         COUT(3) << "NotificationQueue updated. A new Notifications has been added." << std::endl;
     203        COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notifications has been added." << std::endl;
    199204    }
    200205
     
    397402        std::string timeString = std::ctime(&time);
    398403        timeString.erase(timeString.length()-1);
    399         std::ostringstream stream;
    400         stream << reinterpret_cast<unsigned long>(notification);
    401         const std::string& addressString = stream.str();
     404        const std::string& addressString = multi_cast<std::string>(reinterpret_cast<unsigned long>(notification));
    402405        container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
    403406
     
    422425        if(this->size_ == 0) //!< You cannot remove anything if the queue is empty.
    423426            return false;
     427
     428        // Unregister the NotificationQueue with the NotificationManager.
     429        NotificationManager::getInstance().unregisterNotification(container->notification, this);
    424430
    425431        this->removeElement(container->overlay);
     
    443449        {
    444450            this->removeContainer(*it);
    445             it = this->containers_.begin(); //TODO: Needed?
     451            it = this->containers_.begin();
    446452        }
    447453    }
  • code/trunk/src/modules/questsystem/notifications/NotificationQueue.h

    r5781 r7163  
    7171
    7272        Creating a NotificationQueue through XML goes as follows:
     73        Be aware that the NotificationQueue must be inside the <Level></Level> tags or bad things will happen.
    7374        <NotificationQueue
    7475            name = "SuperQueue" //Name of your OverlayQueue.
     
    185186            NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    186187
     188            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
     189
    187190            void initialize(void); //!< Initializes the object.
    188191            void setDefaults(void); //!< Helper method to set the default values.
  • code/trunk/src/modules/weapons/CMakeLists.txt

    r5781 r7163  
    11SET_SOURCE_FILES(WEAPONS_SRC_FILES
    22  MuzzleFlash.cc
     3  RocketController.cc
    34)
    45
     
    1213  PCH_FILE
    1314    WeaponsPrecompiledHeaders.h
    14   DEFINE_SYMBOL
    15     "WEAPONS_SHARED_BUILD"
    1615  LINK_LIBRARIES
    1716    orxonox
  • code/trunk/src/modules/weapons/WeaponsPrereqs.h

    r5929 r7163  
    4343//-----------------------------------------------------------------------
    4444
    45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
     45#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(WEAPONS_STATIC_BUILD)
    4646#  ifdef WEAPONS_SHARED_BUILD
    4747#    define _WeaponsExport __declspec(dllexport)
  • code/trunk/src/modules/weapons/projectiles/CMakeLists.txt

    r6417 r7163  
    55  LightningGunProjectile.cc
    66  Rocket.cc
     7  SimpleRocket.cc
    78)
  • code/trunk/src/modules/weapons/projectiles/Rocket.cc

    r6540 r7163  
    4141#include "controllers/Controller.h"
    4242#include "sound/WorldSound.h"
     43#include "Scene.h"
    4344
    4445namespace orxonox
     
    8788            this->defSndWpnEngine_->setLooping(true);
    8889            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
     90            this->defSndWpnEngine_->setVolume(100);
    8991            this->attach(defSndWpnEngine_);
    9092
     
    9294            this->defSndWpnLaunch_->setLooping(false);
    9395            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
     96            this->defSndWpnLaunch_->setVolume(100);
    9497            this->attach(defSndWpnLaunch_);
    9598        }
     
    114117        if(this->isInitialized())
    115118        {
    116             if (GameMode::isMaster() && this->player_)
    117                 this->player_->stopTemporaryControl();
     119            if (GameMode::isMaster())
     120            {
     121                this->destructionEffect();
     122
     123                if (this->getPlayer() && this->getController())
     124                    this->player_->stopTemporaryControl();
     125            }
    118126
    119127            if ( this->defSndWpnEngine_ )
     
    138146    {
    139147        this->owner_ = owner;
    140         this->originalControllableEntity_ = this->owner_->getPlayer()->getControllableEntity();
    141148        this->player_ = this->owner_->getPlayer();
    142149        this->owner_->getPlayer()->startTemporaryControl(this);
     
    164171            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
    165172            this->localAngularVelocity_ = 0;
    166 
     173        }
     174
     175        if( GameMode::isMaster() )
     176        {
    167177            if( this->bDestroy_ )
    168178                this->destroy();
     179
    169180        }
    170181    }
     
    222233    void Rocket::fired(unsigned int firemode)
    223234    {
    224         if (this->owner_)
    225         {
    226             {
    227                 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
    228                 effect->setPosition(this->getPosition());
    229                 effect->setOrientation(this->getOrientation());
    230                 effect->setDestroyAfterLife(true);
    231                 effect->setSource("Orxonox/explosion4");
    232                 effect->setLifetime(2.0f);
    233             }
    234 
    235             {
    236                 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
    237                 effect->setPosition(this->getPosition());
    238                 effect->setOrientation(this->getOrientation());
    239                 effect->setDestroyAfterLife(true);
    240                 effect->setSource("Orxonox/smoke4");
    241                 effect->setLifetime(3.0f);
    242             }
     235//         if (this->owner_)
     236//         {
    243237            this->destroy();
    244         }
     238//         }
     239    }
     240   
     241    void Rocket::destructionEffect()
     242    {
     243        ParticleSpawner *effect1, *effect2;
     244        if( this->owner_ )
     245        {
     246            effect1 = new ParticleSpawner(this->owner_->getCreator());
     247            effect2 = new ParticleSpawner(this->owner_->getCreator());
     248        }
     249        else
     250        {
     251            effect1 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
     252            effect2 = new ParticleSpawner(static_cast<BaseObject*>(this->getScene().get()));
     253        }
     254       
     255        effect1->setPosition(this->getPosition());
     256        effect1->setOrientation(this->getOrientation());
     257        effect1->setDestroyAfterLife(true);
     258        effect1->setSource("Orxonox/explosion4");
     259        effect1->setLifetime(2.0f);
     260       
     261        effect2->setPosition(this->getPosition());
     262        effect2->setOrientation(this->getOrientation());
     263        effect2->setDestroyAfterLife(true);
     264        effect2->setSource("Orxonox/smoke4");
     265        effect2->setLifetime(3.0f);
    245266    }
    246267
  • code/trunk/src/modules/weapons/projectiles/Rocket.h

    r6417 r7163  
    5757            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
    5858            void destroyObject();
     59            void destructionEffect();
    5960
    6061            virtual void moveFrontBack(const Vector2& value){}
     
    119120            float damage_;
    120121            bool bDestroy_;
    121             ControllableEntity* originalControllableEntity_;
    122122
    123123            WeakPtr<PlayerInfo> player_;
  • code/trunk/src/modules/weapons/weaponmodes/CMakeLists.txt

    r6417 r7163  
    66  LightningGun.cc
    77  RocketFire.cc
     8  SimpleRocketFire.cc
    89)
  • code/trunk/src/orxonox/CMakeLists.txt

    r6711 r7163  
    3232  PlayerManager.cc
    3333  Radar.cc
     34  ChatHistory.cc
     35  ChatInputHandler.cc
     36#  Test.cc
    3437COMPILATION_BEGIN SceneCompilation.cc
    3538  CameraManager.cc
     
    5558  FIND_HEADER_FILES
    5659  TOLUA_FILES
     60    ChatInputHandler.h
    5761    LevelManager.h
    5862    MoodManager.h
    5963    controllers/HumanController.h
    60     interfaces/PickupCarrier.h
     64    interfaces/Pickupable.h
     65    infos/PlayerInfo.h
    6166    sound/SoundManager.h
    62   DEFINE_SYMBOL
    63     "ORXONOX_SHARED_BUILD"
    6467  PCH_FILE
    6568    OrxonoxPrecompiledHeaders.h
     
    7578    ${VORBIS_LIBRARY}
    7679    ${OGG_LIBRARY}
    77     tinyxml++_orxonox
    78     tolua++_orxonox
     80    tinyxml_orxonox
     81    tolua_orxonox
    7982    bullet_orxonox
    8083    util
  • code/trunk/src/orxonox/Level.cc

    r6746 r7163  
    4949        RegisterObject(Level);
    5050
     51
    5152        this->registerVariables();
    5253        this->xmlfilename_ = this->getFilename();
     
    7374        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
    7475
     76        XMLPortObject(Level, MeshLodInformation, "lodinformation", addLodInfo, getLodInfo, xmlelement, mode);
    7577        XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
    76     }
     78}
    7779
    7880    void Level::registerVariables()
    7981    {
    80         registerVariable(this->xmlfilename_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
    81         registerVariable(this->name_,        VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
    82         registerVariable(this->description_, VariableDirection::ToClient);
     82        registerVariable(this->xmlfilename_,            VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
     83        registerVariable(this->name_,                   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
     84        registerVariable(this->description_,            VariableDirection::ToClient);
     85        registerVariable(this->networkTemplateNames_,   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkCallbackTemplatesChanged));
    8386    }
    8487
     
    9598
    9699        Loader::open(this->xmlfile_);
     100    }
     101
     102    void Level::networkCallbackTemplatesChanged()
     103    {
     104        for( std::set<std::string>::iterator it = this->networkTemplateNames_.begin(); it!=this->networkTemplateNames_.end(); ++it )
     105        {
     106            assert(Template::getTemplate(*it));
     107            Template::getTemplate(*it)->applyOn(this);
     108        }
    97109    }
    98110
     
    125137        this->objects_.push_back(object);
    126138        object->setGametype(this->getGametype());
     139        object->setLevel(this);
    127140    }
    128141
     
    136149            ++i;
    137150        }
     151        return 0;
     152    }
     153
     154    void Level::addLodInfo(MeshLodInformation* lodInformation)
     155    {
     156        std::string meshName = lodInformation->getMeshName();
     157//         this->lodInformation_.insert(std::make_pair(meshName,lodInformation));
     158        if( this->lodInformation_.find(meshName) != this->lodInformation_.end())
     159          CCOUT(4) << "replacing lod information for " << meshName << endl;
     160        this->lodInformation_[meshName] = lodInformation;
     161    }
     162
     163    MeshLodInformation* Level::getLodInfo(std::string meshName) const
     164    {
     165        if(this->lodInformation_.find(meshName)!=this->lodInformation_.end())
     166            return this->lodInformation_.find(meshName)->second;
     167
    138168        return 0;
    139169    }
  • code/trunk/src/orxonox/Level.h

    r5929 r7163  
    3434#include <list>
    3535#include <string>
     36#include <map>
    3637#include "core/BaseObject.h"
    3738#include "network/synchronisable/Synchronisable.h"
     39#include "graphics/MeshLodInformation.h"
    3840
    3941namespace orxonox
     
    4648
    4749            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4950
    5051            inline void setDescription(const std::string& description)
     
    5657            void playerLeft(PlayerInfo* player);
    5758
     59            MeshLodInformation* getLodInfo(std::string meshName) const;
     60
     61
    5862        private:
     63            void registerVariables();
    5964            void addObject(BaseObject* object);
    6065            BaseObject* getObject(unsigned int index) const;
     66
     67            void addLodInfo(MeshLodInformation* object);
     68            void networkCallbackTemplatesChanged();
     69//            const MeshLodInformation* getLodInfo(std::string meshName) const;
     70//            MeshLodInformation* getLodInfo(unsigned int index) const;
    6171
    6272            void setGametypeString(const std::string& gametype);
     
    6676            void networkcallback_applyXMLFile();
    6777
    68             std::string            description_;
    69             std::string            gametype_;
    70             std::string            xmlfilename_;
    71             XMLFile*               xmlfile_;
    72             std::list<BaseObject*> objects_;
     78            std::string                    description_;
     79            std::string                    gametype_;
     80            std::string                    xmlfilename_;
     81            XMLFile*                       xmlfile_;
     82            std::list<BaseObject*>         objects_;
     83            std::map<std::string,MeshLodInformation*>  lodInformation_;
    7384    };
    7485}
  • code/trunk/src/orxonox/LevelManager.cc

    r6501 r7163  
    7070    void LevelManager::requestActivity(Level* level)
    7171    {
     72        assert( std::find(this->levels_s.begin(), this->levels_s.end(), level)==this->levels_s.end() );
     73        if( std::find(this->levels_s.begin(), this->levels_s.end(), level)!=this->levels_s.end() )
     74            return; // level is already in list
    7275        this->levels_s.push_back(level);
    7376        if (this->levels_s.size() == 1)
  • code/trunk/src/orxonox/Main.cc

    r6105 r7163  
    4040#include "core/LuaState.h"
    4141#include "ToluaBindOrxonox.h"
     42#include "ToluaBindNetwork.h"
    4243#include "Main.h"
    4344
     
    5152
    5253DeclareToluaInterface(Orxonox);
     54DeclareToluaInterface(Network);
    5355
    5456namespace orxonox
  • code/trunk/src/orxonox/MoodManager.cc

    r6417 r7163  
    3232#include "core/CoreIncludes.h"
    3333#include "core/ScopedSingletonManager.h"
     34#include "core/Resource.h"
    3435
    3536namespace orxonox
     
    3738    ManageScopedSingleton(MoodManager, ScopeID::Root, false);
    3839
     40    // Note: I'm (Kevin Young) not entirely sure whether that's good code style:
     41    const std::string MoodManager::defaultMood_ = "default";
     42
    3943    MoodManager::MoodManager()
    4044    {
    4145        RegisterRootObject(MoodManager);
    4246        this->setConfigValues();
     47
     48        // Need to use a variable to store old data because ResetConfigValues() doesn't seem to work.
     49        oldMood_ = MoodManager::defaultMood_;
     50       
     51        // Checking for the existence of the folder for the default mood
     52        const std::string& path = "ambient/" + MoodManager::defaultMood_ + "/.";
     53        if (!Resource::exists(path))
     54        {
     55            // TODO: Non-fatal error handling (non-critical resource missing)
     56            COUT(2) << "Mood Warning: Folder for default mood (" << MoodManager::defaultMood_ << ") does not exist!" << std::endl;
     57        }
    4358    }
    4459
    4560    void MoodManager::setConfigValues()
    4661    {
    47         SetConfigValue(mood_, "default")
     62        SetConfigValue(mood_, MoodManager::defaultMood_)
    4863            .description("Sets the mood for the current level.")
    4964            .callback(this, &MoodManager::checkMoodValidity);
    5065    }
    5166
    52     /** Sets the mood
    53     @note
    54         TODO: Inform dependent classes of mood change
    55     */
     67    /** Set a new mood
     68     */
    5669    void MoodManager::setMood(const std::string& mood)
    5770    {
     71        oldMood_ = mood_;
    5872        ModifyConfigValue(mood_, set, mood);
    5973    }
     
    6175    void MoodManager::checkMoodValidity()
    6276    {
    63         // TODO: Insert new moods here & make this generic
    64         if (mood_ != "default" && mood_ != "dnb")
     77        //  Generic mood validation
     78        const std::string& path = "ambient/" + mood_ + "/.";
     79        if (!Resource::exists(path))
    6580        {
    66             ResetConfigValue(mood_);
     81            COUT(3) << "Mood " << mood_ << " does not exist. Will not change." << std::endl;
     82            this->setMood(oldMood_);
    6783        }
    6884        else
  • code/trunk/src/orxonox/MoodManager.h

    r6417 r7163  
    3838namespace orxonox
    3939{
     40    /*
     41    @brief
     42        The MoodListener class is aware of a change in themes and directs that info to dependent classes.
     43    */
    4044    class _OrxonoxExport MoodListener : virtual public OrxonoxClass
    4145    {
     
    5559    };
    5660
     61    /*
     62    @brief
     63        The MoodManager class serves to allow for different musical themes in the game.
     64    */
    5765    class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass
    5866    {
     
    7482            // config values
    7583            std::string mood_;
     84            std::string oldMood_;
     85            static const std::string defaultMood_;
    7686
    7787            static MoodManager* singletonPtr_s;
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r6524 r7163  
    8282    class ArtificialController;
    8383    class Controller;
     84    class DroneController;
    8485    class HumanController;
    8586    class ScriptController;
     
    9091    class Asteroids;
    9192    class Deathmatch;
     93    class Dynamicmatch;
    9294    class Gametype;
    9395    class TeamBaseMatch;
     
    135137    class OrxonoxOverlay;
    136138    class OverlayGroup;
    137    
     139
    138140    // pickup
    139141    class PickupIdentifier;
     
    161163    class CameraPosition;
    162164    class ControllableEntity;
     165    class Drone;
    163166    class EffectContainer;
    164167    class ExplosionChunk;
  • code/trunk/src/orxonox/Radar.cc

    r6417 r7163  
    7777    }
    7878
     79    void Radar::addRadarObject(RadarViewable* rv)
     80    {
     81        assert( this->radarObjects_.find(rv) == this->radarObjects_.end() );
     82        this->radarObjects_.insert(rv);
     83        // iterate through all radarlisteners and notify them
     84        for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener)
     85        {
     86            (*itListener)->addObject(rv);
     87        }
     88    }
     89
     90    void Radar::removeRadarObject(RadarViewable* rv)
     91    {
     92        assert( this->radarObjects_.find(rv) != this->radarObjects_.end() );
     93        this->radarObjects_.erase(rv);
     94        // iterate through all radarlisteners and notify them
     95        for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener)
     96        {
     97            (*itListener)->removeObject(rv);
     98        }
     99    }
     100
    79101    const RadarViewable* Radar::getFocus()
    80102    {
     
    109131        {
    110132            (*itListener)->radarTick(dt);
    111 
    112             for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement)
    113             {
    114                 if ((*itElement)->getRadarVisibility())
    115                     if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage())
    116                         (*itListener)->displayObject(*itElement, *itElement == this->focus_);
    117             }
    118133        }
    119134    }
     
    188203        }
    189204    }
     205
     206    void Radar::radarObjectChanged(RadarViewable* rv)
     207    {
     208        for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener)
     209        {
     210          (*itListener)->objectChanged(rv);
     211        }
     212    }
    190213}
  • code/trunk/src/orxonox/Radar.h

    r6417 r7163  
    3838
    3939#include <map>
     40#include <set>
    4041#include <string>
    4142
     
    4849    class _OrxonoxExport Radar : public Tickable
    4950    {
     51        friend class RadarViewable;
    5052    public:
    5153        Radar();
     
    5860
    5961        void listObjects() const;
     62        const std::set<RadarViewable*>& getRadarObjects() const
     63            { return this->radarObjects_; }
    6064
    6165        void releaseFocus();
     
    6670
    6771        void updateFocus();
     72        void addRadarObject(RadarViewable* rv);
     73        void removeRadarObject(RadarViewable* rv);
     74        void radarObjectChanged(RadarViewable* rv);
    6875
    6976        ObjectListIterator<RadarViewable> itFocus_;
    7077        RadarViewable* focus_;
    7178        std::map<std::string, RadarViewable::Shape> objectTypes_;
     79        std::set<RadarViewable*> radarObjects_;
    7280        int objectTypeCounter_;
    7381    };
  • code/trunk/src/orxonox/Scene.cc

    r6417 r7163  
    4747#include "Radar.h"
    4848#include "worldentities/WorldEntity.h"
     49#include "Level.h"
    4950
    5051namespace orxonox
     
    133134        registerVariable(this->bHasPhysics_,        VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::networkcallback_hasPhysics));
    134135        registerVariable(this->bShadows_,           VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyShadows));
     136        registerVariable(this->getLevel(),          VariableDirection::ToClient, new NetworkCallback<Scene>(this, &Scene::changedLevel));
    135137    }
    136138
  • code/trunk/src/orxonox/Test.cc

    r6417 r7163  
    8888    void Test::registerVariables()
    8989    {
    90         registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
    91         registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
    92         registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
    93         registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
     90        registerVariable ( this->mySet_, VariableDirection::ToClient );
     91     
     92//         registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
     93//         registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
     94//         registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
     95//         registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
    9496   
    95         registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
    96         registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
    97         registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
    98         registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
     97//         registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
     98//         registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
     99//         registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
     100//         registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
    99101   
    100         registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
     102//         registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
    101103    }
    102104 
  • code/trunk/src/orxonox/Test.h

    r6417 r7163  
    3535#include "tools/interfaces/Tickable.h"
    3636
     37#include <set>
    3738
    3839typedef int TYPE;
     
    4950
    5051      void setConfigValues();
    51       void registerVariables();
    5252
    5353      static void call(unsigned int clientID);
     
    7878      void printPointer();
    7979
    80       static void printV1(){ instance_->checkU1(); }
    81       static void printV2(){ instance_->checkU2(); }
     80      static void printV1(){ instance_->blub(); }
     81      static void printV2(){ instance_->blub2(); }
    8282      static void printV3(){ instance_->checkU3(); }
    8383      static void printV4(){ instance_->checkU4(); }
     
    8686
    8787    private:
     88      void registerVariables();
     89
    8890      UTYPE u1;
    8991      UTYPE u2;
     
    9799
    98100      Test* pointer_;
     101     
     102      std::set<uint32_t> mySet_;
    99103
    100104      static Test* instance_;
     105     
     106      void blub()
     107      { mySet_.insert(2); }
     108     
     109      void blub2()
     110      { for( std::set<uint32_t>::iterator it=mySet_.begin(); it!=mySet_.end(); ++it ) COUT(0) << *it << endl; }
    101111  };
    102112}
  • code/trunk/src/orxonox/collisionshapes/CollisionShape.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            inline void setPosition(const Vector3& position)
     
    8887
    8988        private:
     89            void registerVariables();
     90
    9091            Vector3                 position_;
    9192            Quaternion              orientation_;
  • code/trunk/src/orxonox/controllers/AIController.cc

    r5929 r7163  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    3333#include "core/Executor.h"
    3434#include "worldentities/ControllableEntity.h"
     35#include "worldentities/pawns/Pawn.h"
    3536
    3637namespace orxonox
     
    5657        float maxrand = 100.0f / ACTION_INTERVAL;
    5758
    58         // search enemy
    59         random = rnd(maxrand);
    60         if (random < 15 && (!this->target_))
    61             this->searchNewTarget();
    62 
    63         // forget enemy
    64         random = rnd(maxrand);
    65         if (random < 5 && (this->target_))
    66             this->forgetTarget();
    67 
    68         // next enemy
    69         random = rnd(maxrand);
    70         if (random < 10 && (this->target_))
    71             this->searchNewTarget();
    72 
    73         // fly somewhere
    74         random = rnd(maxrand);
    75         if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    76             this->searchRandomTargetPosition();
    77 
    78         // stop flying
    79         random = rnd(maxrand);
    80         if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    81             this->bHasTargetPosition_ = false;
    82 
    83         // fly somewhere else
    84         random = rnd(maxrand);
    85         if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    86             this->searchRandomTargetPosition();
    87 
    88         // shoot
    89         random = rnd(maxrand);
    90         if (random < 75 && (this->target_ && !this->bShooting_))
    91             this->bShooting_ = true;
    92 
    93         // stop shooting
    94         random = rnd(maxrand);
    95         if (random < 25 && (this->bShooting_))
    96             this->bShooting_ = false;
     59        if (this->state_ == FREE)
     60        {
     61
     62            if (this->formationFlight_)
     63            {
     64                // return to Master after being forced free
     65                if (this->freedomCount_ == 1)
     66                {
     67                this->state_ = SLAVE;
     68                this->freedomCount_ = 0;
     69                }
     70
     71                random = rnd(maxrand);
     72                if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
     73                    this->searchNewMaster();
     74            }
     75
     76            // search enemy
     77            random = rnd(maxrand);
     78            if (random < 15 && (!this->target_))
     79                this->searchNewTarget();
     80
     81            // forget enemy
     82            random = rnd(maxrand);
     83            if (random < 5 && (this->target_))
     84                this->forgetTarget();
     85
     86            // next enemy
     87            random = rnd(maxrand);
     88            if (random < 10 && (this->target_))
     89                this->searchNewTarget();
     90
     91            // fly somewhere
     92            random = rnd(maxrand);
     93            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     94                this->searchRandomTargetPosition();
     95
     96            // stop flying
     97            random = rnd(maxrand);
     98            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
     99                this->bHasTargetPosition_ = false;
     100
     101            // fly somewhere else
     102            random = rnd(maxrand);
     103            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     104                this->searchRandomTargetPosition();
     105
     106            // shoot
     107            random = rnd(maxrand);
     108            if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
     109                this->bShooting_ = true;
     110
     111            // stop shooting
     112            random = rnd(maxrand);
     113            if (random < 25 && (this->bShooting_))
     114                this->bShooting_ = false;
     115
     116        }
     117
     118        if (this->state_ == SLAVE)
     119        {
     120
     121        }
     122
     123        if (this->state_ == MASTER)
     124        {
     125
     126
     127            this->commandSlaves();
     128
     129            if  (this->specificMasterAction_ != NONE)
     130                    this->specificMasterActionHold();
     131
     132            else {
     133
     134                 // make 180 degree turn - a specific Master Action
     135                random = rnd(1000.0f);
     136                if (random < 5)
     137                   this->turn180Init();
     138
     139                // spin around - a specific Master Action
     140                random = rnd(1000.0f);
     141                if (random < 5)
     142                   this->spinInit();
     143
     144                // follow a randomly chosen human - a specific Master Action
     145                random = rnd(1000.0f);
     146                if (random < 1)
     147                   this->followRandomHumanInit();
     148
     149                 // lose master status (only if less than 4 slaves in formation)
     150                random = rnd(maxrand);
     151                if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 )
     152                   this->loseMasterState();
     153
     154                // look out for outher masters if formation is small
     155                random = rnd(maxrand);
     156                if(this->slaves_.size() < 3 && random < 20)
     157                    this->searchNewMaster();
     158
     159                // search enemy
     160                random = rnd(maxrand);
     161                if (random < 15 && (!this->target_))
     162                    this->searchNewTarget();
     163
     164                // forget enemy
     165                random = rnd(maxrand);
     166                if (random < 5 && (this->target_))
     167                    this->forgetTarget();
     168
     169                // next enemy
     170                random = rnd(maxrand);
     171                if (random < 10 && (this->target_))
     172                    this->searchNewTarget();
     173
     174                // fly somewhere
     175                random = rnd(maxrand);
     176                if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     177                    this->searchRandomTargetPosition();
     178
     179
     180                // fly somewhere else
     181                random = rnd(maxrand);
     182                if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     183                    this->searchRandomTargetPosition();
     184
     185                // shoot
     186                random = rnd(maxrand);
     187                if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
     188                {
     189                this->bShooting_ = true;
     190                this->forceFreeSlaves();
     191                }
     192
     193                // stop shooting
     194                random = rnd(maxrand);
     195                if (random < 25 && (this->bShooting_))
     196                    this->bShooting_ = false;
     197
     198            }
     199        }
     200
    97201    }
    98202
     
    102206            return;
    103207
    104         if (this->target_)
    105             this->aimAtTarget();
    106 
    107         if (this->bHasTargetPosition_)
    108             this->moveToTargetPosition();
    109 
    110         if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    111             this->getControllableEntity()->fire(0);
     208        if (this->state_ == MASTER)
     209        {
     210            if (this->specificMasterAction_ ==  NONE)
     211            {
     212                if (this->target_)
     213                {
     214                                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
     215                        this->forgetTarget();
     216                else this->aimAtTarget();
     217            }
     218
     219                if (this->bHasTargetPosition_)
     220                    this->moveToTargetPosition();
     221
     222                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     223                    this->getControllableEntity()->fire(0);
     224            }
     225
     226            if (this->specificMasterAction_  == TURN180)
     227                    this->turn180();
     228
     229            if (this->specificMasterAction_ == SPIN)
     230                    this->spin();
     231            if (this->specificMasterAction_ == FOLLOW)
     232                    this->follow();
     233        }
     234
     235        if (this->state_ == SLAVE)
     236        {
     237
     238            if (this->bHasTargetPosition_)
     239                this->moveToTargetPosition();
     240
     241        }
     242
     243         if (this->state_ == FREE)
     244        {
     245            if (this->target_)
     246            {
     247                                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
     248                        this->forgetTarget();
     249                else this->aimAtTarget();
     250            }
     251
     252            if (this->bHasTargetPosition_)
     253                this->moveToTargetPosition();
     254
     255            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     256                this->getControllableEntity()->fire(0);
     257        }
    112258
    113259        SUPER(AIController, tick, dt);
  • code/trunk/src/orxonox/controllers/ArtificialController.cc

    r6502 r7163  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    2929#include "ArtificialController.h"
    3030
     31#include <vector>
     32#include <climits>
     33
     34#include "util/Math.h"
     35#include "core/ConsoleCommand.h"
    3136#include "core/CoreIncludes.h"
     37#include "core/XMLPort.h"
    3238#include "worldentities/ControllableEntity.h"
    3339#include "worldentities/pawns/Pawn.h"
    3440#include "worldentities/pawns/TeamBaseMatchBase.h"
    3541#include "gametypes/TeamDeathmatch.h"
     42#include "gametypes/Dynamicmatch.h"
    3643#include "controllers/WaypointPatrolController.h"
     44#include "controllers/NewHumanController.h"
     45#include "controllers/DroneController.h"
    3746
    3847namespace orxonox
    3948{
     49    SetConsoleCommand(ArtificialController, formationflight, true);
     50    SetConsoleCommand(ArtificialController, masteraction, true);
     51    SetConsoleCommand(ArtificialController, followme, true);
     52    SetConsoleCommand(ArtificialController, passivebehaviour, true);
     53    SetConsoleCommand(ArtificialController, formationsize, true);
     54
     55    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
     56    static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
     57    static const int FORMATION_LENGTH =  130;
     58    static const int FORMATION_WIDTH =  110;
     59    static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
     60    static const float SPEED_MASTER = 0.6f;
     61    static const float ROTATEFACTOR_MASTER = 0.2f;
     62    static const float SPEED_FREE = 0.8f;
     63    static const float ROTATEFACTOR_FREE = 0.8f;
     64
     65
    4066    ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
    4167    {
     
    4369
    4470        this->target_ = 0;
     71        this->formationFlight_ = true;
     72        this->passive_ = false;
     73        this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
     74        this->myMaster_ = 0;
     75        this->freedomCount_ = 0;
     76        this->team_ = -1;
     77        this->state_ = FREE;
     78        this->specificMasterAction_ = NONE;
     79        this->specificMasterActionHoldCount_  = 0;
    4580        this->bShooting_ = false;
    4681        this->bHasTargetPosition_ = false;
     82        this->speedCounter_ = 0.2f;
    4783        this->targetPosition_ = Vector3::ZERO;
    4884
     
    5288    ArtificialController::~ArtificialController()
    5389    {
     90        if (this->isInitialized())
     91        {
     92            this->removeFromFormation();
     93
     94            for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it)
     95            {
     96                if (*it != this)
     97                {
     98                    if (it->myMaster_ == this)
     99                    {
     100                        COUT(1) << "error: " << this << " is still master in " << (*it) << std::endl;
     101                        it->myMaster_ = 0;
     102                    }
     103
     104                    while (true)
     105                    {
     106                        std::vector<ArtificialController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this);
     107                        if (it2 != it->slaves_.end())
     108                        {
     109                            COUT(1) << "error: " << this << " is still slave in " << (*it) << std::endl;
     110                            it->slaves_.erase(it2);
     111                        }
     112                        else
     113                            break;
     114                    }
     115                }
     116            }
     117        }
     118    }
     119
     120    void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     121    {
     122        SUPER(ArtificialController, XMLPort, xmlelement, mode);
     123
     124        XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
     125        XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
     126        XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
     127        XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
     128    }
     129
     130// Documentation only here to get a faster overview for creating a useful documentation...
     131
     132    /**
     133        @brief Activates / deactivates formationflight behaviour
     134        @param form activate formflight if form is true
     135    */
     136    void ArtificialController::formationflight(const bool form)
     137    {
     138        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     139        {
     140            Controller* controller = 0;
     141
     142            if (it->getController())
     143                controller = it->getController();
     144            else if (it->getXMLController())
     145                controller = it->getXMLController();
     146
     147            if (!controller)
     148                continue;
     149
     150            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     151
     152            if (aiController)
     153            {
     154                aiController->formationFlight_ = form;
     155                if (!form)
     156                {
     157                    aiController->removeFromFormation();
     158                }
     159            }
     160        }
     161    }
     162
     163    /**
     164        @brief Get all masters to do a "specific master action"
     165        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
     166    */
     167    void ArtificialController::masteraction(const int action)
     168    {
     169        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     170        {
     171            Controller* controller = 0;
     172
     173            if (it->getController())
     174                controller = it->getController();
     175            else if (it->getXMLController())
     176                controller = it->getXMLController();
     177
     178            if (!controller)
     179                continue;
     180
     181            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     182
     183            if(aiController && aiController->state_ == MASTER)
     184            {
     185                if (action == 1)
     186                    aiController->spinInit();
     187                if (action == 2)
     188                    aiController->turn180Init();
     189            }
     190        }
     191    }
     192
     193    /**
     194        @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup).
     195    */
     196    void ArtificialController::followme()
     197    {
     198
     199        Pawn *humanPawn = NULL;
     200        NewHumanController *currentHumanController = NULL;
     201        std::vector<ArtificialController*> allMasters;
     202
     203        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     204        {
     205            Controller* controller = 0;
     206
     207            if (it->getController())
     208                controller = it->getController();
     209            else if (it->getXMLController())
     210                controller = it->getXMLController();
     211
     212            if (!controller)
     213                continue;
     214
     215            currentHumanController = orxonox_cast<NewHumanController*>(controller);
     216
     217            if(currentHumanController) humanPawn = *it;
     218
     219            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     220
     221            if(aiController && aiController->state_ == MASTER)
     222                allMasters.push_back(aiController);
     223
     224        }
     225
     226        if((humanPawn != NULL) && (allMasters.size() != 0))
     227        {
     228                float posHuman = humanPawn->getPosition().length();
     229                float distance = 0.0f;
     230                float minDistance = FLT_MAX;
     231                int index = 0;
     232                int i = 0;
     233
     234                for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
     235                    {
     236                        if (!ArtificialController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
     237                        distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
     238                        if(distance < minDistance) index = i;
     239                    }
     240                allMasters[index]->followInit(humanPawn);
     241            }
     242
     243    }
     244
     245    /**
     246        @brief Sets shooting behaviour of pawns.
     247        @param passive if true, bots won't shoot.
     248    */
     249    void ArtificialController::passivebehaviour(const bool passive)
     250    {
     251        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     252        {
     253            Controller* controller = 0;
     254
     255            if (it->getController())
     256                controller = it->getController();
     257            else if (it->getXMLController())
     258                controller = it->getXMLController();
     259
     260            if (!controller)
     261                continue;
     262
     263            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     264
     265            if(aiController)
     266            {
     267                aiController->passive_ = passive;
     268            }
     269        }
     270    }
     271
     272
     273    /**
     274        @brief Sets maximal formation size
     275        @param size maximal formation size.
     276    */
     277    void ArtificialController::formationsize(const int size)
     278    {
     279        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     280        {
     281            Controller* controller = 0;
     282
     283            if (it->getController())
     284                controller = it->getController();
     285            else if (it->getXMLController())
     286                controller = it->getXMLController();
     287
     288            if (!controller)
     289                continue;
     290
     291            ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
     292
     293            if(aiController)
     294            {
     295                aiController->maxFormationSize_ = size;
     296            }
     297        }
     298    }
     299
     300    /**
     301        @brief Gets called when ControllableEntity is being changed. Resets the bot when it dies.
     302    */
     303    void ArtificialController::changedControllableEntity()
     304    {
     305        if (!this->getControllableEntity())
     306            this->removeFromFormation();
     307    }
     308
     309    void ArtificialController::removeFromFormation()
     310    {
     311        if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set
     312            this->unregisterSlave();
     313        else if (this->state_ == MASTER)
     314            this->setNewMasterWithinFormation();
    54315    }
    55316
     
    59320            return;
    60321
     322        // Slave uses special movement if its master is in FOLLOW mode
     323        if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW)
     324        {
     325//             this->followForSlaves(target);
     326//             return;
     327        }
     328
    61329        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    62330        float distance = (target - this->getControllableEntity()->getPosition()).length();
    63331
    64         if (this->target_ || distance > 10)
    65         {
    66             // Multiply with 0.8 to make them a bit slower
    67             this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
    68             this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
    69         }
    70 
    71         if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    72             this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance
     332
     333        if(this->state_ == FREE)
     334        {
     335            if (this->target_ || distance > 10)
     336            {
     337                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
     338                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
     339                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
     340            }
     341
     342            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     343            {
     344              this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
     345            } else this->getControllableEntity()->moveFrontBack(SPEED_FREE);
     346        }
     347
     348
     349
     350        if(this->state_ == MASTER)
     351        {
     352            if (this->target_ || distance > 10)
     353            {
     354                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
     355                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     356            }
     357
     358            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     359            {
     360                this->getControllableEntity()->moveFrontBack(-0.05f);
     361            } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     362        }
     363
     364
     365
     366        if(this->state_ == SLAVE)
     367        {
     368
     369           this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
     370           this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     371
     372            if (distance < 300)
     373            {
     374                if (distance < 40)
     375                {
     376                    this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER);
     377                } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
     378
     379            } else {
     380                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
     381            }
     382        }
     383    }
     384
     385    void ArtificialController::moveToTargetPosition()
     386    {
     387        this->moveToPosition(this->targetPosition_);
     388    }
     389
     390
     391    /**
     392        @brief Unregisters a slave from its master. Initiated by a slave.
     393    */
     394    void ArtificialController::unregisterSlave()
     395    {
     396        if (this->myMaster_)
     397        {
     398            std::vector<ArtificialController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this);
     399            if (it != this->myMaster_->slaves_.end())
     400                this->myMaster_->slaves_.erase(it);
     401        }
     402
     403        this->myMaster_ = 0;
     404        this->state_ = FREE;
     405    }
     406
     407    void ArtificialController::searchNewMaster()
     408    {
     409
     410        if (!this->getControllableEntity())
     411            return;
     412
     413        this->targetPosition_ = this->getControllableEntity()->getPosition();
     414        this->forgetTarget();
     415        int teamSize = 0;
     416        //go through all pawns
     417        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     418        {
     419            //same team?
     420            if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
     421                continue;
     422
     423            //has it an ArtificialController?
     424            Controller* controller = 0;
     425
     426            if (it->getController())
     427                controller = it->getController();
     428            else if (it->getXMLController())
     429                controller = it->getXMLController();
     430
     431            if (!controller)
     432                continue;
     433
     434            //is pawn oneself?
     435            if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
     436                continue;
     437
     438            teamSize++;
     439
     440            ArtificialController *newMaster = orxonox_cast<ArtificialController*>(controller);
     441
     442            //is it a master?
     443            if (!newMaster || newMaster->state_ != MASTER)
     444                continue;
     445
     446            float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
     447
     448            // is pawn in range?
     449            if (distance < RADIUS_TO_SEARCH_FOR_MASTERS)
     450            {
     451                if(newMaster->slaves_.size() > this->maxFormationSize_) continue;
     452
     453                for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
     454                {
     455                    (*itSlave)->myMaster_ = newMaster;
     456                    newMaster->slaves_.push_back(*itSlave);
     457                }
     458                this->slaves_.clear();
     459                this->state_ = SLAVE;
     460
     461                this->myMaster_ = newMaster;
     462                newMaster->slaves_.push_back(this);
     463
     464                break;
     465            }
     466        }
     467
     468        if (this->state_ != SLAVE  && teamSize != 0)
     469        {
     470            this->state_ = MASTER;
     471            this->myMaster_ = 0;
     472        }
     473    }
     474
     475    /**
     476        @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
     477    */
     478    void ArtificialController::commandSlaves()
     479    {
     480        if(this->state_ != MASTER) return;
     481
     482        Quaternion orient = this->getControllableEntity()->getOrientation();
     483        Vector3 dest = this->getControllableEntity()->getPosition();
     484
     485        // 1 slave: follow
     486        if (this->slaves_.size() == 1)
     487        {
     488            dest += 4*orient*WorldEntity::BACK;
     489            this->slaves_.front()->setTargetPosition(dest);
     490        }
    73491        else
    74             this->getControllableEntity()->moveFrontBack(0.8f);
    75     }
    76 
    77     void ArtificialController::moveToTargetPosition()
    78     {
    79         this->moveToPosition(this->targetPosition_);
    80     }
     492        {
     493            dest += 1.0f*orient*WorldEntity::BACK;
     494            Vector3 pos = Vector3::ZERO;
     495            int i = 1;
     496
     497            for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     498            {
     499                pos = Vector3::ZERO;
     500                if (i <= 1) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::LEFT);
     501                if (i == 2) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
     502                if (i == 3) pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::UP);
     503                if (i >= 4)
     504                {
     505                    pos += dest  + FORMATION_WIDTH*(orient*WorldEntity::DOWN);
     506                    i = 1;
     507                    dest += FORMATION_LENGTH*(orient*WorldEntity::BACK);
     508                    (*it)->setTargetPosition(pos);
     509                    continue;
     510                }
     511                i++;
     512                (*it)->setTargetPosition(pos);
     513            }
     514        }
     515    }
     516
     517    /**
     518        @brief Sets a new master within the formation. Called by a master.
     519    */
     520    void ArtificialController::setNewMasterWithinFormation()
     521    {
     522        if(this->state_ != MASTER) return;
     523
     524        if (!this->slaves_.empty())
     525        {
     526            ArtificialController *newMaster = this->slaves_.back();
     527            this->slaves_.pop_back();
     528
     529            newMaster->state_ = MASTER;
     530            newMaster->slaves_ = this->slaves_;
     531            newMaster->myMaster_ = 0;
     532
     533            for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
     534            {
     535                (*it)->myMaster_ = newMaster;
     536            }
     537        }
     538
     539        this->slaves_.clear();
     540        this->specificMasterAction_ = NONE;
     541        this->state_ = FREE;
     542    }
     543
     544    /**
     545        @brief Frees all slaves form a master. Initiated by a master.
     546    */
     547    void ArtificialController::freeSlaves()
     548    {
     549        if(this->state_ != MASTER) return;
     550
     551        for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     552        {
     553            (*it)->state_ = FREE;
     554            (*it)->myMaster_ = 0;
     555        }
     556        this->slaves_.clear();
     557    }
     558
     559    /**
     560        @brief Master sets its slaves free for @var FREEDOM_COUNT seconds.
     561    */
     562    void ArtificialController::forceFreeSlaves()
     563    {
     564        if(this->state_ != MASTER) return;
     565
     566        for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     567        {
     568            (*it)->state_ = FREE;
     569            (*it)->forceFreedom();
     570            (*it)->targetPosition_ = this->targetPosition_;
     571            (*it)->bShooting_ = true;
     572//             (*it)->getControllableEntity()->fire(0);// fire once for fun
     573        }
     574    }
     575
     576    void ArtificialController::loseMasterState()
     577    {
     578        this->freeSlaves();
     579        this->state_ = FREE;
     580    }
     581
     582
     583    void ArtificialController::forceFreedom()
     584    {
     585        this->freedomCount_ = FREEDOM_COUNT;
     586    }
     587
     588    /**
     589        @brief Checks wether caller has been forced free, decrements time to stay forced free.
     590        @return true if forced free.
     591    */
     592    bool ArtificialController::forcedFree()
     593    {
     594        if(this->freedomCount_ > 0)
     595        {
     596            this->freedomCount_--;
     597            return true;
     598        } else return false;
     599    }
     600
     601    /**
     602        @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
     603    */
     604    void ArtificialController::specificMasterActionHold()
     605    {
     606        if(this->state_ != MASTER) return;
     607
     608        if (specificMasterActionHoldCount_ == 0)
     609         {
     610            this->specificMasterAction_ = NONE;
     611            this->searchNewTarget();
     612         }
     613        else specificMasterActionHoldCount_--;
     614    }
     615
     616    /**
     617        @brief Master initializes a 180 degree turn. Leads to a "specific master action".
     618    */
     619    void ArtificialController::turn180Init()
     620    {
     621        if(this->state_ != MASTER) return;
     622
     623        Quaternion orient = this->getControllableEntity()->getOrientation();
     624
     625        this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK);
     626
     627        this->specificMasterActionHoldCount_ = 4;
     628
     629        this->specificMasterAction_ = TURN180;
     630    }
     631
     632    /**
     633        @brief Execute the 180 degree turn. Called within tick.
     634    */
     635    void ArtificialController::turn180()
     636    {
     637            Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
     638
     639            this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
     640            this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
     641
     642            this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     643    }
     644
     645    /**
     646        @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action".
     647    */
     648    void ArtificialController::spinInit()
     649    {
     650        if(this->state_ != MASTER) return;
     651        this->specificMasterAction_ = SPIN;
     652        this->specificMasterActionHoldCount_ = 10;
     653    }
     654
     655    /**
     656        @brief Execute the spin. Called within tick.
     657    */
     658    void ArtificialController::spin()
     659    {
     660            this->moveToTargetPosition();
     661            this->getControllableEntity()->rotateRoll(0.8f);
     662    }
     663
     664    /**
     665        @brief Master begins to follow a pawn. Is a "specific master action".
     666        @param pawn pawn to follow.
     667        @param alaways follows pawn forever if true (false if omitted).
     668        @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header).
     669    */
     670    void ArtificialController::followInit(Pawn* pawn, const bool always, const int secondsToFollow)
     671    {
     672        if (pawn == NULL || this->state_ != MASTER)
     673            return;
     674        this->specificMasterAction_  =  FOLLOW;
     675
     676        this->setTarget(pawn);
     677        if (!always)
     678            this->specificMasterActionHoldCount_ = secondsToFollow;
     679        else
     680            this->specificMasterActionHoldCount_ = INT_MAX; //for now...
     681
     682    }
     683
     684
     685    /**
     686        @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
     687    */
     688    void ArtificialController::followRandomHumanInit()
     689    {
     690
     691        Pawn *humanPawn = NULL;
     692        NewHumanController *currentHumanController = NULL;
     693
     694        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     695        {
     696            if (!it->getController())
     697                continue;
     698
     699            currentHumanController = orxonox_cast<NewHumanController*>(it->getController());
     700            if(currentHumanController)
     701            {
     702                if (!ArtificialController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;
     703                humanPawn = *it;
     704                break;
     705            }
     706        }
     707
     708        if((humanPawn != NULL))
     709                this->followInit(humanPawn);
     710    }
     711
     712    /**
     713        @brief Master follows target with adjusted speed. Called within tick.
     714    */
     715    void ArtificialController::follow()
     716    {
     717        if (this->target_)
     718            this->moveToPosition(this->target_->getPosition());
     719        else
     720            this->specificMasterActionHoldCount_ = 0;
     721/*
     722        if (!this->getControllableEntity())
     723            return;
     724
     725        float distance = (this->target_->getPosition() - this->getControllableEntity()->getPosition()).length();
     726
     727        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->target_->getPosition());
     728
     729
     730        this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
     731        this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
     732
     733        float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->target_->getVelocity().squaredLength();
     734
     735COUT(0) << "~follow distance: " << distance << "SpeedCounter: " << this->speedCounter_ << "~speedDiv: " << speedDiv << std::endl;
     736        if (distance < 800)
     737        {
     738            if (distance < 200)
     739            {
     740                this->speedCounter_ -= 0.5f;
     741                if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
     742                this->getControllableEntity()->moveFrontBack(speedCounter_);
     743            } else {
     744                if(speedDiv < 0)
     745                    this->speedCounter_ +=  0.01f;
     746                else
     747                    this->speedCounter_ -= 0.05f;
     748                this->getControllableEntity()->moveFrontBack(speedCounter_);
     749            }
     750
     751        } else {
     752            this->speedCounter_ += 0.05f;
     753            this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
     754        }
     755//         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
     756
     757*/
     758    }
     759
     760
     761    /**
     762        @brief Slave moving behaviour when master is following a pawn, gets redirected from moveToPosition(const Vector3& target)). Called within tick.
     763    */
     764    void ArtificialController::followForSlaves(const Vector3& target)
     765    {
     766
     767/*
     768        if (!this->getControllableEntity() && !this->myMaster_ && this->myMaster_->state_ != FOLLOW && !this->myMaster_->target_)
     769            return;
     770
     771        float distance = (target - this->getControllableEntity()->getPosition()).length();
     772
     773        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     774
     775
     776        this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
     777        this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
     778
     779
     780        float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->myMaster_->target_->getVelocity().squaredLength();
     781
     782
     783         if (distance < 800)
     784        {
     785            if (distance < 200)
     786            {
     787                this->speedCounter_ -= 5.0f;
     788                if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
     789                this->getControllableEntity()->moveFrontBack(speedCounter_);
     790            } else {
     791                if(speedDiv < 0)
     792                    this->speedCounter_ +=  0.01f;
     793                else
     794                    this->speedCounter_ -= 0.05f;
     795                this->getControllableEntity()->moveFrontBack(speedCounter_);
     796            }
     797
     798        } else {
     799            this->speedCounter_ += 0.05f;
     800            this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
     801        }
     802//         if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
     803*/
     804    }
     805
    81806
    82807    void ArtificialController::setTargetPosition(const Vector3& target)
     
    111836        {
    112837            if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
     838                continue;
     839
     840            /* So AI won't choose invisible Spaceships as target */
     841            if (!it->getRadarVisibility())
    113842                continue;
    114843
     
    144873        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
    145874
    146         Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());
     875        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
    147876        if (pawn)
    148877            pawn->setAimPosition(this->targetPosition_);
     
    188917        int team2 = -1;
    189918
    190         if (entity1->getXMLController())
    191         {
    192             WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity1->getXMLController());
    193             if (wpc)
    194                 team1 = wpc->getTeam();
    195         }
    196         if (entity2->getXMLController())
    197         {
    198             WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity2->getXMLController());
    199             if (wpc)
    200                 team2 = wpc->getTeam();
     919        Controller* controller = 0;
     920        if (entity1->getController())
     921            controller = entity1->getController();
     922        else
     923            controller = entity1->getXMLController();
     924        if (controller)
     925        {
     926            ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
     927            if (ac)
     928                team1 = ac->getTeam();
     929        }
     930
     931        if (entity2->getController())
     932            controller = entity2->getController();
     933        else
     934            controller = entity2->getXMLController();
     935        if (controller)
     936        {
     937            ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
     938            if (ac)
     939                team2 = ac->getTeam();
    201940        }
    202941
     
    245984        }
    246985
     986        DroneController* droneController = 0;
     987        droneController = orxonox_cast<DroneController*>(entity1->getController());
     988        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
     989            return true;
     990        droneController = orxonox_cast<DroneController*>(entity2->getController());
     991        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
     992            return true;
     993        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
     994        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
     995        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
     996            return true;
     997
     998        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
     999        if (dynamic)
     1000        {
     1001            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
     1002
     1003            if (entity1->getPlayer())
     1004                team1 = dynamic->getParty(entity1->getPlayer());
     1005
     1006            if (entity2->getPlayer())
     1007                team2 = dynamic->getParty(entity2->getPlayer());
     1008
     1009            if (team1 ==-1 ||team2 ==-1 ) {return false;}
     1010            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
     1011            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
     1012            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
     1013            else return true;
     1014        }
     1015
    2471016        return (team1 == team2 && team1 != -1);
    2481017    }
  • code/trunk/src/orxonox/controllers/ArtificialController.h

    r6417 r7163  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include <vector>
     35
    3436#include "util/Math.h"
    3537#include "Controller.h"
     38#include "controllers/NewHumanController.h"
    3639
    3740namespace orxonox
     
    4346            virtual ~ArtificialController();
    4447
     48            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     49
    4550            void abandonTarget(Pawn* target);
    4651
     52            inline void setTeam(int team)
     53                { this->team_ = team; }
     54            inline int getTeam() const
     55                { return this->team_; }
     56
     57            inline void setFormationFlight(bool formation)
     58                { this->formationFlight_ = formation; }
     59            inline bool getFormationFlight() const
     60                { return this->formationFlight_; }
     61
     62            inline void setFormationSize(int size)
     63                { this->maxFormationSize_ = size; }
     64            inline int getFormationSize() const
     65                { return this->maxFormationSize_; }
     66
     67            inline void setPassive(bool passive)
     68                { this->passive_ = passive; }
     69            inline bool getPassive() const
     70                { return this->passive_; }
     71
     72            virtual void changedControllableEntity();
     73
     74            static void formationflight(const bool form);
     75            static void masteraction(const int action);
     76            static void followme();
     77            static void passivebehaviour(const bool passive);
     78            static void formationsize(const int size);
     79
    4780        protected:
    48             void targetDied();
     81
     82            int team_;
     83            bool formationFlight_;
     84            bool passive_;
     85            unsigned int maxFormationSize_;
     86            int freedomCount_;
     87            enum State {SLAVE, MASTER, FREE};
     88            State state_;
     89            std::vector<ArtificialController*> slaves_;
     90            ArtificialController *myMaster_;
     91            enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
     92            SpecificMasterAction specificMasterAction_;
     93            int specificMasterActionHoldCount_;
     94            float speedCounter_; //for speed adjustment when following
    4995
    5096            void moveToPosition(const Vector3& target);
    5197            void moveToTargetPosition();
     98
     99            void removeFromFormation();
     100            void unregisterSlave();
     101            void searchNewMaster();
     102            void commandSlaves();
     103            void setNewMasterWithinFormation();
     104
     105            void freeSlaves();
     106            void forceFreeSlaves();
     107            void loseMasterState();
     108            void forceFreedom();
     109            bool forcedFree();
     110
     111            void specificMasterActionHold();
     112            void turn180Init();
     113            void turn180();
     114            void spinInit();
     115            void spin();
     116            void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
     117            void followRandomHumanInit();
     118            void follow();
     119            void followForSlaves(const Vector3& target);
    52120
    53121            void setTargetPosition(const Vector3& target);
     
    61129            bool isCloseAtTarget(float distance) const;
    62130            bool isLookingAtTarget(float angle) const;
     131
     132            void targetDied();
    63133
    64134            static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
  • code/trunk/src/orxonox/controllers/CMakeLists.txt

    r6417 r7163  
    88  WaypointController.cc
    99  WaypointPatrolController.cc
     10  DroneController.cc
    1011)
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r6417 r7163  
    3535#include "gametypes/Gametype.h"
    3636#include "infos/PlayerInfo.h"
    37 #include "overlays/Map.h"
    3837#include "Radar.h"
    3938#include "Scene.h"
     
    116115    void HumanController::yaw(const Vector2& value)
    117116    {
    118         //Hack to enable mouselook in map
    119         if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
    120         {
    121             Map::getSingletonPtr()->rotateYaw(value);
    122             return;
    123         }
    124117        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    125118            HumanController::localController_s->controllableEntity_->rotateYaw(value);
     
    128121    void HumanController::pitch(const Vector2& value)
    129122    {
    130         //Hack to enable mouselook in map
    131         if ( Map::getSingletonPtr() && Map::getSingletonPtr()->getVisibility() && HumanController::localController_s->controllableEntity_->isInMouseLook() )
    132         {
    133             Map::getSingletonPtr()->rotatePitch(value);
    134             return;
    135         }
    136123        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    137124            HumanController::localController_s->controllableEntity_->rotatePitch(value);
  • code/trunk/src/orxonox/controllers/NewHumanController.cc

    r6598 r7163  
    217217                    if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
    218218                        this->showOverlays();
     219                    else if (this->getControllableEntity() &&  this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
     220                    {
     221                        this->showOverlays();
     222                        this->hideArrows();
     223                    }
    219224
    220225                    this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5f-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5f-overlaySize_/2));
     
    364369        Ogre::RaySceneQueryResult& result = rsq->execute();
    365370        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     371        WorldEntity* myWe = static_cast<WorldEntity*>(this->getControllableEntity());
    366372
    367373        Ogre::RaySceneQueryResult::iterator itr;
    368374        for (itr = result.begin(); itr != result.end(); ++itr)
    369375        {
    370             if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500)
     376//             CCOUT(0) << "testing object as target" << endl;
     377            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" /*&& itr->distance > 500*/)
    371378            {
    372379                // Try to cast the user pointer
    373                 WorldEntity* wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
     380                WorldEntity* wePtr;
     381                try
     382                {
     383                    wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
     384                }
     385                catch (...)
     386                {
     387                    continue;
     388                }
     389
     390                // make sure we don't shoot ourselves
     391                if( wePtr==myWe )
     392                    continue;
     393
    374394                if (wePtr)
    375395                {
     
    379399                    while (parent)
    380400                    {
    381                         if (this->targetMask_.isExcluded(parent->getIdentifier()))
     401                        if (this->targetMask_.isExcluded(parent->getIdentifier()) || parent==myWe)
    382402                        {
    383403                            parent = parent->getParent();
     
    430450            HumanController::yaw(value);
    431451
    432         this->currentYaw_ = value.x;
     452        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
     453            this->currentYaw_ = value.x;
    433454    }
    434455
     
    439460            HumanController::pitch(value);
    440461
    441         this->currentPitch_ = value.x;
     462        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
     463            this->currentPitch_ = value.x;
    442464    }
    443465
     
    579601        }
    580602    }
     603
     604
     605
     606
     607
    581608}
  • code/trunk/src/orxonox/controllers/NewHumanController.h

    r6417 r7163  
    6767            virtual void doResumeControl();
    6868
     69
    6970        protected:
    7071            void updateTarget();
  • code/trunk/src/orxonox/controllers/WaypointPatrolController.cc

    r6502 r7163  
    4242        RegisterObject(WaypointPatrolController);
    4343
    44         this->team_ = 0;
     44        //this->team_ = 0;
    4545        this->alertnessradius_ = 500;
    4646
     
    5353
    5454        XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f);
    55         XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
     55//        XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
    5656    }
    5757
  • code/trunk/src/orxonox/controllers/WaypointPatrolController.h

    r5929 r7163  
    4646            virtual void tick(float dt);
    4747
    48             inline void setTeam(int team)
     48           /* inline void setTeam(int team)
    4949                { this->team_ = team; }
    5050            inline int getTeam() const
    51                 { return this->team_; }
     51                { return this->team_; } */
    5252
    5353            inline void setAlertnessRadius(float radius)
     
    5959            void searchEnemy();
    6060
    61             int team_;
     61            //int team_;
    6262            float alertnessradius_;
    6363            Timer patrolTimer_;
  • code/trunk/src/orxonox/gamestates/GSClient.cc

    r6426 r7163  
    4040    DeclareGameState(GSClient, "client", false, false);
    4141
    42     SetCommandLineArgument(ip, "127.0.0.1").information("Sever IP as string in the form #.#.#.#");
     42    SetCommandLineArgument(dest, "127.0.0.1").information("Server hostname/IP (IP in the form of #.#.#.#)");
    4343
    4444    GSClient::GSClient(const GameStateInfo& info)
    4545        : GameState(info)
    46         , client_(0)
    4746    {
    4847    }
     
    5655        GameMode::setIsClient(true);
    5756
    58         this->client_ = new Client(CommandLineParser::getValue("ip").getString(), CommandLineParser::getValue("port"));
     57//         this->client_ = new Client();
     58//         this->client_->setDestination(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
    5959
    60         if(!client_->establishConnection())
     60        if( !Client::getInstance()->establishConnection() )
    6161        {
    62             delete this->client_;
    6362            ThrowException(InitialisationFailed, "Could not establish connection with server.");
    6463        }
    6564
    66         client_->update(Game::getInstance().getGameClock());
     65        Client::getInstance()->update(Game::getInstance().getGameClock());
    6766    }
    6867
    6968    void GSClient::deactivate()
    7069    {
    71         client_->closeConnection();
     70        Client::getInstance()->closeConnection();
    7271
    7372        // destroy client
    74         delete this->client_;
     73//         delete this->client_;
    7574
    7675        GameMode::setIsClient(false);
     
    7978    void GSClient::update(const Clock& time)
    8079    {
    81         client_->update(time);
     80        Client::getInstance()->update(time);
    8281    }
    8382}
  • code/trunk/src/orxonox/gamestates/GSClient.h

    r5929 r7163  
    4646        void deactivate();
    4747        void update(const Clock& time);
    48 
    49     private:
    50         Client* client_;
    5148    };
    5249}
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r6417 r7163  
    3939#include "core/Game.h"
    4040#include "core/GUIManager.h"
    41 // HACK:
    42 #include "overlays/Map.h"
    4341
    4442namespace orxonox
     
    7371    void GSGraphics::deactivate()
    7472    {
    75         // HACK: (destroys a resource smart pointer)
    76         Map::hackDestroyMap();
     73
    7774    }
    7875
  • code/trunk/src/orxonox/gametypes/CMakeLists.txt

    r5781 r7163  
    66  UnderAttack.cc
    77  Asteroids.cc
     8  Dynamicmatch.cc
    89)
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r6417 r7163  
    309309        if (this->spawnpoints_.size() > 0)
    310310        {
     311            SpawnPoint* fallbackSpawnPoint = NULL;
    311312            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
    312313            unsigned int index = 0;
     314            std::set<SpawnPoint*> activeSpawnPoints = this->spawnpoints_;
    313315            for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it)
     316            {
     317                if (index == randomspawn)
     318                    fallbackSpawnPoint = (*it);
     319
     320                if (!(*it)->isActive())
     321                    activeSpawnPoints.erase(*it);
     322
     323                ++index;
     324            }
     325
     326            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(this->spawnpoints_.size())));
     327            index = 0;
     328            for (std::set<SpawnPoint*>::const_iterator it = activeSpawnPoints.begin(); it != activeSpawnPoints.end(); ++it)
    314329            {
    315330                if (index == randomspawn)
     
    318333                ++index;
    319334            }
     335
     336            return fallbackSpawnPoint;
    320337        }
    321338        return 0;
  • code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc

    r6417 r7163  
    137137        }
    138138
     139        SpawnPoint* fallbackSpawnPoint = NULL;
    139140        if (teamSpawnPoints.size() > 0)
    140141        {
    141142            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
    142143            unsigned int index = 0;
     144            // Get random fallback spawnpoint in case there is no active SpawnPoint.
     145            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
     146            {
     147                if (index == randomspawn)
     148                {
     149                    fallbackSpawnPoint = (*it);
     150                    break;
     151                }
     152
     153                ++index;
     154            }
     155
     156            // Remove all inactive SpawnPoints from the list.
     157            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
     158            {
     159                if(!(*it)->isActive())
     160                {
     161                    teamSpawnPoints.erase(it++);
     162                    continue;
     163                }
     164
     165                ++it;
     166            }
     167
     168            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
     169            index = 0;
    143170            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
    144171            {
     
    148175                ++index;
    149176            }
     177
     178            return fallbackSpawnPoint;
    150179        }
    151180
  • code/trunk/src/orxonox/graphics/Backlight.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void tick(float dt);
     
    8180
    8281        private:
     82            void registerVariables();
    8383            virtual void startturnonoff();
    8484            virtual void stopturnonoff();
  • code/trunk/src/orxonox/graphics/Billboard.h

    r5781 r7163  
    4646
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4948
    5049            virtual void changedVisibility();
     
    7877
    7978        private:
     79            void registerVariables();
    8080            void changedMaterial();
    8181//            void changedRotation();
  • code/trunk/src/orxonox/graphics/BlinkingBillboard.cc

    r6417 r7163  
    6666    void BlinkingBillboard::registerVariables()
    6767    {
    68 //        registerVariable(this->amplitude_, VariableDirection::ToClient);
    69 //        registerVariable(this->frequency_, VariableDirection::ToClient);
    70 //        registerVariable(this->phase_,     VariableDirection::ToClient);
     68        unregisterVariable(this->getScale3D());
     69        registerVariable(this->amplitude_,  VariableDirection::ToClient);
     70        registerVariable(this->frequency_,  VariableDirection::ToClient);
     71        registerVariable(this->phase_,      VariableDirection::ToClient);
     72        registerVariable(this->bQuadratic_, VariableDirection::ToClient);
    7173    }
    7274
     
    7577        SUPER(BlinkingBillboard, tick, dt);
    7678
    77         if (GameMode::isMaster() && this->isActive())
     79        if (this->isActive())
    7880        {
    7981            this->time_ += dt;
  • code/trunk/src/orxonox/graphics/BlinkingBillboard.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void tick(float dt);
     
    7069
    7170        private:
     71            void registerVariables();
     72           
    7273            float amplitude_;
    7374            float frequency_;
  • code/trunk/src/orxonox/graphics/CMakeLists.txt

    r5929 r7163  
    44  FadingBillboard.cc
    55  GlobalShader.cc
     6  MeshLodInformation.cc
    67  Model.cc
     8  AnimatedModel.cc
    79  ParticleEmitter.cc
    810  ParticleSpawner.cc
  • code/trunk/src/orxonox/graphics/Camera.cc

    r6501 r7163  
    111111        SUPER(Camera, tick, dt);
    112112
    113         if (this->bDrag_)
     113        if (this->bDrag_ && this->getTimeFactor() != 0)
    114114        {
    115115            // this stuff here may need some adjustments
  • code/trunk/src/orxonox/graphics/FadingBillboard.h

    r5929 r7163  
    4646
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4948
    5049            virtual void tick(float dt);
     
    6665
    6766        protected:
     67            void registerVariables();
    6868            virtual void startturnonoff();
    6969            virtual void stopturnonoff();
  • code/trunk/src/orxonox/graphics/GlobalShader.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void changedVisibility();
     
    5352
    5453        private:
     54            void registerVariables();
    5555            void changedCompositor();
    5656
  • code/trunk/src/orxonox/graphics/Light.h

    r5781 r7163  
    5757
    5858            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    59             void registerVariables();
    6059
    6160            virtual void changedVisibility();
     
    132131
    133132        private:
     133            void registerVariables();
    134134            void setTypeString(const std::string& type);
    135135            std::string getTypeString() const;
  • code/trunk/src/orxonox/graphics/Model.cc

    r5781 r7163  
    3535#include "core/XMLPort.h"
    3636#include "Scene.h"
     37#include "graphics/MeshLodInformation.h"
     38#include "Level.h"
    3739
    3840namespace orxonox
     
    4042    CreateFactory(Model);
    4143
    42     Model::Model(BaseObject* creator) : StaticEntity(creator)
     44    Model::Model(BaseObject* creator) :
     45        StaticEntity(creator), bCastShadows_(true), lodLevel_(5), bLodEnabled_(true), numLodLevels_(10), lodReductionRate_(.15)
    4346    {
    4447        RegisterObject(Model);
    45 
    46         this->bCastShadows_ = true;
    4748
    4849        this->registerVariables();
     
    5960        SUPER(Model, XMLPort, xmlelement, mode);
    6061
     62        XMLPortParam(Model, "lodLevel", setLodLevel, getLodLevel, xmlelement, mode);
     63
    6164        XMLPortParam(Model, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
    6265        XMLPortParam(Model, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
     
    6770        registerVariable(this->meshSrc_,    VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMesh));
    6871        registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedShadows));
     72    }
     73
     74    float Model::getBiggestScale(Vector3 scale3d)
     75    {
     76        float scaleFactor = scale3d.x;
     77        if(scale3d.y>scaleFactor)
     78            scaleFactor = scale3d.y;
     79        if(scale3d.z>scaleFactor)
     80            scaleFactor = scale3d.z;
     81        return scaleFactor;
    6982    }
    7083
     
    8396                this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
    8497                this->mesh_.setVisible(this->isVisible());
     98
     99
     100                //LOD
     101                if( this->mesh_.getEntity()->getMesh()->getNumLodLevels()==1 )
     102                {
     103                    Level* level = this->getLevel();
     104
     105                    assert( level != 0 );
     106
     107                    MeshLodInformation* lodInfo = level->getLodInfo(this->meshSrc_);
     108                    if( lodInfo )
     109                    {
     110                        setLodLevel(lodInfo->getLodLevel());
     111                        this->bLodEnabled_ = lodInfo->getEnabled();
     112                        this->numLodLevels_ = lodInfo->getNumLevels();
     113                        this->lodReductionRate_ = lodInfo->getReductionRate();
     114                    }
     115                    if( this->numLodLevels_>10 )
     116                    {
     117                        CCOUT(2) << "More than 10 LoD levels requested. Creating only 10." << endl;
     118                        this->numLodLevels_ = 10;
     119                    }
     120                    if( this->bLodEnabled_ )
     121                    {
     122                        float volume = this->mesh_.getEntity()->getBoundingBox().volume();
     123    //                     float scaleFactor = 1;
     124
     125    //                     BaseObject* creatorPtr = this;
     126    //
     127    //                     while(creatorPtr!=NULL&&orxonox_cast<WorldEntity*>(creatorPtr))
     128    //                     {
     129    //                         scaleFactor *= getBiggestScale(((WorldEntity*) creatorPtr)->getScale3D());
     130    //                         creatorPtr = creatorPtr->getCreator();
     131    //                     }
     132    //                     COUT(0) << "name: " << this->meshSrc_ << "scaleFactor: " << scaleFactor << ", volume: " << volume << endl;
     133
     134                        COUT(4) << "Setting lodLevel for " << this->meshSrc_<< " with lodLevel_: " << this->lodLevel_ <<" and volume: "<< volume << ":" << std::endl;
     135
     136#if OGRE_VERSION >= 0x010700
     137                        Ogre::Mesh::LodValueList distList;
     138#else
     139                        Ogre::Mesh::LodDistanceList distList;
     140#endif
     141
     142                        if( lodLevel_>0 )
     143                        {
     144    //                         float factor = scaleFactor*5/lodLevel_;
     145                            float factor = pow(volume, 2.0f / 3.0f) * 15.0f / lodLevel_;
     146
     147                            COUT(4) << "LodLevel set with factor: " << factor << endl;
     148
     149                            distList.push_back(70.0f*factor);
     150                            distList.push_back(140.0f*factor);
     151                            distList.push_back(170.0f*factor);
     152                            distList.push_back(200.0f*factor);
     153                            distList.push_back(230.0f*factor);
     154                            distList.push_back(250.0f*factor);
     155                            distList.push_back(270.0f*factor);
     156                            distList.push_back(290.0f*factor);
     157                            distList.push_back(310.0f*factor);
     158                            distList.push_back(330.0f*factor);
     159                            while(distList.size()>this->numLodLevels_)
     160                                distList.pop_back();
     161
     162
     163                            //Generiert LOD-Levels
     164                            this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, this->lodReductionRate_);
     165                        }
     166                        else
     167                        {
     168                            std::string what;
     169                            if(lodLevel_>5)
     170                                what = ">5";
     171                            else
     172                                what = "<0";
     173
     174                            COUT(4)<<"LodLevel not set because lodLevel("<<lodLevel_<<") was "<<what<<"." << endl;
     175                        }
     176                    }
     177                    else
     178                        COUT(4) << "LodLevel for " << this->meshSrc_ << " not set because is disabled." << endl;
     179                }
    85180            }
    86181        }
  • code/trunk/src/orxonox/graphics/Model.h

    r5781 r7163  
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             void registerVariables();
    4847
    4948            virtual void changedVisibility();
     
    6261                { return this->bCastShadows_; }
    6362
    64         private:
     63        protected:
     64            void registerVariables();
    6565            void changedMesh();
    6666            void changedShadows();
     67
     68            //LoD
     69            inline void setLodLevel(float lodLevel)
     70                { this->lodLevel_ =  lodLevel; }
     71            inline float getLodLevel() const
     72                { return this->lodLevel_; }
     73            float getBiggestScale(Vector3 scale3d);
    6774
    6875            std::string meshSrc_;
    6976            Mesh mesh_;
    7077            bool bCastShadows_;
     78
     79            //LoD
     80            float lodLevel_;
     81            bool bLodEnabled_;
     82            unsigned int numLodLevels_;
     83            float lodReductionRate_;
     84
    7185    };
    7286}
  • code/trunk/src/orxonox/graphics/ParticleEmitter.h

    r5781 r7163  
    4444
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    46             void registerVariables();
    4746
    4847            virtual void changedVisibility();
     
    7473            std::string        source_;
    7574            LODParticle::Value   LOD_;
     75
     76        private:
     77            void registerVariables();
    7678    };
    7779}
  • code/trunk/src/orxonox/infos/GametypeInfo.cc

    r5781 r7163  
    4242    registerMemberNetworkFunction(GametypeInfo, dispatchKillMessage);
    4343    registerMemberNetworkFunction(GametypeInfo, dispatchDeathMessage);
     44    registerMemberNetworkFunction(GametypeInfo, dispatchStaticMessage);
     45    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    4446
    4547    GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
     
    110112    }
    111113
     114    void GametypeInfo::sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour)
     115    {
     116        if (GameMode::isMaster())
     117        {
     118            if (clientID == CLIENTID_SERVER)
     119                this->dispatchStaticMessage(message, colour);
     120            else
     121                callMemberNetworkFunction(GametypeInfo, dispatchStaticMessage, this->getObjectID(), clientID, message, colour);
     122        }
     123    }
     124
     125    void GametypeInfo::sendFadingMessage(const std::string& message, unsigned int clientID)
     126    {
     127        if (GameMode::isMaster())
     128        {
     129            if (clientID == CLIENTID_SERVER)
     130                this->dispatchFadingMessage(message);
     131            else
     132                callMemberNetworkFunction(GametypeInfo, dispatchFadingMessage, this->getObjectID(), clientID, message);
     133        }
     134    }
     135
    112136    void GametypeInfo::dispatchAnnounceMessage(const std::string& message)
    113137    {
     
    127151            it->deathmessage(this, message);
    128152    }
     153
     154     void GametypeInfo::dispatchStaticMessage(const std::string& message, const ColourValue& colour)
     155    {
     156        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     157            it->staticmessage(this, message, colour);
     158    }
     159
     160     void GametypeInfo::dispatchFadingMessage(const std::string& message)
     161    {
     162        for (ObjectList<GametypeMessageListener>::iterator it = ObjectList<GametypeMessageListener>::begin(); it != ObjectList<GametypeMessageListener>::end(); ++it)
     163            it->fadingmessage(this, message);
     164    }
    129165}
  • code/trunk/src/orxonox/infos/GametypeInfo.h

    r5781 r7163  
    4545            virtual ~GametypeInfo();
    4646
    47             void registerVariables();
    48 
    4947            inline bool hasStarted() const
    5048                { return this->bStarted_; }
     
    6462            void sendKillMessage(const std::string& message, unsigned int clientID);
    6563            void sendDeathMessage(const std::string& message, unsigned int clientID);
     64            void sendStaticMessage(const std::string& message, unsigned int clientID, const ColourValue& colour);
     65            void sendFadingMessage(const std::string& message, unsigned int clientID);
    6666
    6767            void dispatchAnnounceMessage(const std::string& message);
    6868            void dispatchKillMessage(const std::string& message);
    6969            void dispatchDeathMessage(const std::string& message);
     70            void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
     71            void dispatchFadingMessage(const std::string& message);
    7072
    7173        private:
     74            void registerVariables();
     75
    7276            bool bStarted_;
    7377            bool bEnded_;
  • code/trunk/src/orxonox/infos/HumanPlayer.h

    r5781 r7163  
    4343            virtual ~HumanPlayer();
    4444
    45             void registerVariables();
    4645            void setConfigValues();
    4746
     
    101100            std::string gametypeHudTemplate_;
    102101            OverlayGroup* gametypeHud_;
     102        private:
     103            void registerVariables();
    103104    };
    104105}
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r6417 r7163  
    177177            return;
    178178
    179 //         assert( this->temporaryControllableEntity_==0 );
     179        assert( this->oldControllableEntity_==0 );
    180180
    181181        this->oldControllableEntity_ = this->controllableEntity_;
     
    184184
    185185        entity->setPlayer(this);
     186        entity->setController(this->controller_);
    186187
    187188        if (this->controller_)
     
    222223            return;
    223224
     225        this->controllableEntity_->setController(0);
     226       
    224227        this->controllableEntity_ = this->oldControllableEntity_;
    225228        this->controllableEntityID_ = this->controllableEntity_->getObjectID();
  • code/trunk/src/orxonox/infos/PlayerInfo.h

    r6417 r7163  
    3535#include "core/SubclassIdentifier.h"
    3636
    37 namespace orxonox
    38 {
    39     class _OrxonoxExport PlayerInfo : public Info
    40     {
     37namespace orxonox // tolua_export
     38{ // tolua_export
     39    class _OrxonoxExport PlayerInfo // tolua_export
     40        : public Info
     41    { // tolua_export
    4142        public:
    4243            PlayerInfo(BaseObject* creator);
    4344            virtual ~PlayerInfo();
    44 
    45             void registerVariables();
    4645
    4746            virtual void changedName();
     
    9190
    9291        private:
     92            void registerVariables();
    9393            void networkcallback_changedcontrollableentityID();
    9494            void networkcallback_changedgtinfoID();
     
    103103            const GametypeInfo* gtinfo_;
    104104            unsigned int gtinfoID_;
    105     };
    106 }
     105    }; // tolua_export
     106} // tolua_export
    107107
    108108#endif /* _PlayerInfo_H__ */
  • code/trunk/src/orxonox/interfaces/GametypeMessageListener.h

    r5781 r7163  
    4444            virtual void killmessage(const GametypeInfo* gtinfo, const std::string& message) {}
    4545            virtual void deathmessage(const GametypeInfo* gtinfo, const std::string& message) {}
     46            virtual void staticmessage(const GametypeInfo* gtinfo, const std::string& message, const ColourValue& colour) {}
     47            virtual void fadingmessage(const GametypeInfo* gtinfo, const std::string& message) {}
    4648    };
    4749}
  • code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc

    r6711 r7163  
    5252        RegisterRootObject(GametypeMessageListener);
    5353    }
    54    
     54
    5555    //----------------------------
    5656    // PickupCarrier
     
    5959    {
    6060        RegisterRootObject(PickupCarrier);
    61        
    62         this->setCarrierName("PickupCarrier");
    6361    }
    64    
     62
    6563    PickupCarrier::~PickupCarrier()
    6664    {
     65
     66    }
     67
     68    void PickupCarrier::preDestroy(void)
     69    {
    6770        std::set<Pickupable*>::iterator it = this->pickups_.begin();
     71        std::set<Pickupable*>::iterator temp;
    6872        while(it != this->pickups_.end())
    6973        {
    70             (*(it++))->destroy();
     74            (*it)->carrierDestroyed();
     75            temp = it;
     76            it = this->pickups_.begin();
     77            if(it == temp) // Infinite loop avoidance, in case the pickup wasn't removed from the carrier somewhere in the carrierDestroy() procedure.
     78            {
     79                COUT(2) << "Oops. In a PickupCarrier, while cleaning up, a Pickupable (&" << (*temp) << ") didn't unregister itself as it should have." << std::endl;;
     80                it++;
     81            }
    7182        }
    7283
     
    8495        this->isForPlayer_ = true;
    8596    }
    86    
     97
    8798    //----------------------------
    8899    // RadarListener
  • code/trunk/src/orxonox/interfaces/NotificationListener.h

    r5929 r7163  
    4747    class Notification;
    4848
     49    /**
     50    @brief
     51        NotificationListener interface.
     52    @author
     53        Fabian 'x3n' Landau
     54    */
    4955    class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
    5056    {
  • code/trunk/src/orxonox/interfaces/PickupCarrier.h

    • Property svn:eol-style set to native
    r6711 r7163  
    4545#include "core/OrxonoxClass.h"
    4646
    47 namespace orxonox // tolua_export
    48 { // tolua_export
     47namespace orxonox
     48{
    4949
    5050    //! Forward-declarations.
     
    5454    class InvisiblePickup;
    5555    class MetaPickup;
     56    class DronePickup;
    5657    class SpeedPickup;
    5758
     
    6263        Damian 'Mozork' Frick
    6364    */
    64     class _OrxonoxExport PickupCarrier  // tolua_export
    65         : virtual public OrxonoxClass
    66     { // tolua_export
     65    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
     66    {
    6767        //! So that the different Pickupables have full access to their PickupCarrier.
    6868        friend class Pickupable;
    6969        friend class PickupManager;
    70         //! Friends. 
     70        //! Friends.
    7171        friend class Pickup;
    7272        friend class HealthPickup;
    7373        friend class InvisiblePickup;
    7474        friend class MetaPickup;
     75        friend class DronePickup;
    7576        friend class SpeedPickup;
    7677
     
    7879            PickupCarrier(); //!< Constructor.
    7980            virtual ~PickupCarrier(); //!< Destructor.
    80 
    81             /**
    82             @brief Can be called to pick up a Pickupable.
    83             @param pickup A pointer to the Pickupable.
    84             @return Returns true if the Pickupable was picked up, false if not.
    85             */
    86             bool pickup(Pickupable* pickup)
    87                 {
    88                     bool pickedUp = this->pickups_.insert(pickup).second;
    89                     if(pickedUp)
    90                     {
    91                         COUT(4) << "Picked up Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;
    92                         pickup->pickedUp(this);
    93                     }
    94                     return pickedUp;
    95                 }
    96 
    97             /**
    98             @brief Can be called to drop a Pickupable.
    99             @param pickup A pointer to the Pickupable.
    100             @param drop If the Pickupable should just be removed from the PickupCarrier without further action, this can be set to false. true is default.
    101             @return Returns true if the Pickupable has been dropped, false if not.
    102             */
    103             bool drop(Pickupable* pickup, bool drop = true)
    104                 {
    105                     bool dropped = this->pickups_.erase(pickup) == 1;
    106                     if(dropped && drop)
    107                     {
    108                         COUT(4) << "Dropping Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;
    109                         pickup->dropped();
    110                     }
    111                     return dropped;
    112                 }
     81            void preDestroy(void);
    11382
    11483            /**
     
    169138            */
    170139            virtual const Vector3& getCarrierPosition(void) = 0;
    171            
    172             /**
    173             @brief Get the name of this PickupCarrier.
    174             @return Returns the name as a string.
    175             */
    176             const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export
    177            
    178         protected:       
     140
     141        protected:
    179142            /**
    180143            @brief Get all direct children of this PickupSpawner.
     
    197160            std::set<Pickupable*>& getPickups(void)
    198161                { return this->pickups_; }
    199                
    200             /**
    201             @brief Set the name of this PickupCarrier.
    202                    The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName().
    203             @param name The name to be set.
    204             */
    205             void setCarrierName(const std::string& name)
    206                 { this->carrierName_ = name; }
    207        
     162
    208163        private:
    209164            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    210             std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory.
    211            
     165
    212166            /**
    213             @brief Get the number of carrier children this PickupCarrier has.
    214             @return Returns the number of carrier children.
     167            @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
     168            @param pickup A pointer to the pickup to be added.
     169            @return Returns true if successfull, false if the Pickupable was already present.
    215170            */
    216             unsigned int getNumCarrierChildren(void)
     171            bool addPickup(Pickupable* pickup)
    217172                {
    218                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    219                     unsigned int size = list->size();
    220                     delete list;
    221                     return size;
     173                    COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl;
     174                    return this->pickups_.insert(pickup).second;
    222175                }
    223            
     176
    224177            /**
    225             @brief Get the index-th child of this PickupCarrier.
    226             @param index The index of the child to return.
    227             @return Returns the index-th child.
     178            @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier.
     179            @param pickup A pointer to the pickup to be removed.
     180            @return Returns true if successfull, false if the Pickupable was not present in the list.
    228181            */
    229             PickupCarrier* getCarrierChild(unsigned int index)
     182            bool removePickup(Pickupable* pickup)
    230183                {
    231                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    232                     if(list->size() < index)
    233                         return NULL;
    234                     PickupCarrier* carrier = (*list)[index];
    235                     delete list;
    236                     return carrier;
     184                    COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl;
     185                    return this->pickups_.erase(pickup) == 1;
    237186                }
    238            
    239             /**
    240             @brief Get the number of Pickupables this PickupCarrier carries.
    241             @return returns the number of pickups.
    242             */
    243             unsigned int getNumPickups(void)
    244                 { return this->pickups_.size(); }
    245            
    246             /**
    247             @brief Get the index-th Pickupable of this PickupCarrier.
    248             @param index The index of the Pickupable to return.
    249             @return Returns the index-th pickup.
    250             */
    251             Pickupable* getPickup(unsigned int index)
    252                 {
    253                     std::set<Pickupable*>::iterator it;
    254                     for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++)
    255                         index--;
    256                     if(it == this->pickups_.end())
    257                         return NULL;
    258                     return *it;
    259                 }
    260            
    261     }; // tolua_export
    262 } // tolua_export
     187
     188    };
     189}
    263190
    264191#endif /* _PickupCarrier_H__ */
  • code/trunk/src/orxonox/interfaces/Pickupable.cc

    • Property svn:eol-style set to native
    r6901 r7163  
    3434#include "Pickupable.h"
    3535
     36#include "core/LuaState.h"
     37#include "core/GUIManager.h"
    3638#include "core/Identifier.h"
    3739#include "core/CoreIncludes.h"
     40#include "util/Convert.h"
     41#include "infos/PlayerInfo.h"
    3842#include "pickup/PickupIdentifier.h"
     43#include "worldentities/pawns/Pawn.h"
    3944#include "PickupCarrier.h"
    4045
    4146namespace orxonox
    4247{
    43    
     48
    4449    /**
    4550    @brief
     
    4752    */
    4853    Pickupable::Pickupable() : pickupIdentifier_(NULL), used_(false), pickedUp_(false)
    49     {       
     54    {
    5055        RegisterRootObject(Pickupable);
    51        
     56
    5257        this->carrier_ = NULL;
    53        
     58
    5459        this->pickupIdentifier_ = new PickupIdentifier(this);
    55     }
    56    
    57     /**
    58     @brief
    59         Destructor.
     60        this->beingDestroyed_ = false;
     61        this->enabled_ = true;
     62    }
     63
     64    /**
     65    @brief
     66        Destructor.
    6067    */
    6168    Pickupable::~Pickupable()
    6269    {
    63         if(this->isUsed())
    64             this->setUsed(false);
    65        
    66         if(this->isPickedUp() && this->getCarrier() != NULL)
    67         {
    68             this->getCarrier()->drop(this, false);
    69             this->setCarrier(NULL);
    70         }
    71        
     70        COUT(4) << "Pickupable (" << this->getIdentifier()->getName() << ") (&" << this << ") destroyed." << std::endl;
    7271        if(this->pickupIdentifier_ != NULL)
    7372            this->pickupIdentifier_->destroy();
    7473    }
    75    
     74
     75    /**
     76    @brief
     77        A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
     78    */
     79    void Pickupable::preDestroy(void)
     80    {
     81        this->beingDestroyed_ = true;
     82
     83        if(this->isPickedUp())
     84            this->drop(false); // Drops the pickup without creating a PickupSpawner.
     85    }
     86
     87    /**
     88    @brief
     89        Is called internally within the pickup module to destroy pickups.
     90    */
     91    void Pickupable::destroy(void)
     92    {
     93        this->destroyPickup();
     94    }
     95
     96    /**
     97    @brief
     98        Destroys a Pickupable.
     99        If the Pickupable is already in the process of being destroyed a warning is displayed and this method is skipped.
     100    */
     101    void Pickupable::destroyPickup(void)
     102    {
     103        if(!this->beingDestroyed_)
     104            this->OrxonoxClass::destroy();
     105        else
     106            COUT(2) << this->getIdentifier()->getName() << " may be unsafe. " << std::endl;
     107    }
     108
    76109    /**
    77110    @brief
     
    84117    bool Pickupable::setUsed(bool used)
    85118    {
    86         if(this->used_ == used)
    87             return false;
    88        
     119        if(this->used_ == used || !this->isPickedUp()) // If either the used status of the Pickupable doesn't change or it isn't picked up.
     120            return false;
     121
     122        if((!this->isUsable() && used) || (!this->isUnusable() && !used)) // If either the Pickupable is requested to be used but it is not usable or the Pickupable is requested to be unused, while it is not unusable.
     123            return false;
     124
    89125        COUT(4) << "Pickupable (&" << this << ") set to used " << used << "." << std::endl;
    90        
     126
    91127        this->used_ = used;
    92128        this->changedUsed();
    93         return true;
    94     }
    95    
     129
     130        GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
     131        return true;
     132    }
     133
    96134    /**
    97135    @brief
     
    106144        if(carrier == NULL)
    107145            return false;
     146
    108147        return this->isTarget(carrier->getIdentifier());
    109148    }
    110    
     149
    111150    /**
    112151    @brief
     
    125164                return true;
    126165        }
     166
    127167        return false;
    128168    }
    129        
     169
    130170    /**
    131171    @brief
     
    140180        return this->addTarget(target->getIdentifier());
    141181    }
    142    
     182
    143183    /**
    144184    @brief
     
    153193        if(this->isTarget(target)) //!< If the input target is already present in the list of targets.
    154194            return false;
    155        
     195
    156196        COUT(4) << "Target " << target->getName() << " added to Pickupable (&" << this << ")." << std::endl;
    157197        this->targets_.push_back(target);
    158198        return true;
    159199    }
    160    
    161     /**
    162     @brief 
    163         Sets the Pickupable to picked up.
    164         This method will be called by the PickupCarrier picking the Pickupable up.
     200
     201    /**
     202    @brief
     203        Can be called to pick up a Pickupable.
    165204    @param carrier
    166         The PickupCarrier that picked the Pickupable up.
    167     @return
    168         Returns false if, for some reason, the pickup could not be picked up, e.g. it was picked up already.
    169     */
    170     bool Pickupable::pickedUp(PickupCarrier* carrier)
    171     {
    172         if(this->isPickedUp()) //!< If the Pickupable is already picked up.
    173             return false;
     205        A pointer to the PickupCarrier that picks up the Pickupable.
     206    @return
     207        Returns true if the Pickupable was picked up, false if not.
     208    */
     209    bool Pickupable::pickup(PickupCarrier* carrier)
     210    {
     211        if(carrier == NULL || this->isPickedUp()) //!< If carrier is NULL or the Pickupable is already picked up.
     212            return false;
     213
     214        if(!this->setCarrier(carrier))
     215        {
     216            COUT(3) << "A Pickupable (&" << this << ") was trying to be added to a PickupCarrier, but was already present." << std::endl;
     217            return false;
     218        }
    174219       
     220        this->setPickedUp(true);
    175221        COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl;
    176         this->setCarrier(carrier);
    177         this->setPickedUp(true);
    178         return true;
    179     }
    180    
     222        return true;
     223    }
     224
     225    /**
     226    @brief
     227        Can be called to drop a Pickupable.
     228    @param createSpawner
     229        If true a spawner is to be created for the dropped Pickupable. True is default.
     230    @return
     231        Returns true if the Pickupable has been dropped, false if not.
     232    */
     233    bool Pickupable::drop(bool createSpawner)
     234    {
     235        if(!this->isPickedUp()) // If the Pickupable is not picked up.
     236            return false;
     237
     238        assert(this->getCarrier()); // The Carrier cannot be NULL at this point.
     239        if(!this->getCarrier()->removePickup(this)) //TODO Shouldn't this be a little later?
     240            COUT(2) << "Pickupable (&" << this << ", " << this->getIdentifier()->getName() << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl;
     241
     242        COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;
     243        this->setUsed(false);
     244        this->setPickedUp(false);
     245
     246        bool created = false;
     247        if(createSpawner)
     248            created = this->createSpawner();
     249
     250        this->setCarrier(NULL);
     251
     252        if(!created && createSpawner) // If a PickupSpawner should have been created but wasn't.
     253            this->destroy();
     254
     255        return true;
     256    }
     257
    181258    /**
    182259    @brief
     
    189266    bool Pickupable::setPickedUp(bool pickedUp)
    190267    {
    191         if(this->pickedUp_ == pickedUp)
    192             return false;
    193        
     268        if(this->pickedUp_ == pickedUp) // If the picked up status has not changed.
     269            return false;
     270
    194271        COUT(4) << "Pickupable (&" << this << ") set to pickedUp " << pickedUp << "." << std::endl;
    195        
     272
    196273        this->pickedUp_ = pickedUp;
     274        if(!pickedUp) // if the Pickupable has been dropped it unregisters itself with its PickupCarrier.
     275            this->getCarrier()->removePickup(this);
    197276        this->changedPickedUp();
    198         return true;
    199     }
    200        
     277        GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
     278        return true;
     279    }
     280
    201281    /**
    202282    @brief
     
    204284    @param carrier
    205285        Sets the input PickupCarrier as the carrier of the pickup.
    206     */
    207     inline bool Pickupable::setCarrier(PickupCarrier* carrier)
    208     {
    209         if(this->carrier_ == carrier)
    210             return false;
    211        
     286    @param tell
     287        If true (default) the pickup is added to the list of pickups in the PickupCarrier.
     288    @return
     289        Returns true if successful, false if not.
     290    */
     291    bool Pickupable::setCarrier(orxonox::PickupCarrier* carrier, bool tell)
     292    {
     293        if(this->carrier_ == carrier) // If the PickupCarrier doesn't change.
     294            return false;
     295
    212296        COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl;
     297
     298        if(carrier != NULL && tell)
     299        {
     300            if(!carrier->addPickup(this))
     301                return false;
     302        }
    213303       
    214304        this->carrier_ = carrier;
     
    216306        return true;
    217307    }
    218    
    219     /**
    220     @brief
    221         Sets the Pickupable to not picked up or dropped.
    222         This method will be called by the PickupCarrier dropping the Pickupable.
    223     @return
    224         Returns false if the pickup could not be dropped.
    225     */
    226     bool Pickupable::dropped(void)
    227     {
    228         if(!this->isPickedUp()) //!< If the Pickupable is not picked up.
    229             return false;
    230        
    231         COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;
    232         this->setUsed(false);
    233         this->setPickedUp(false);
    234        
    235         bool created = this->createSpawner();
    236        
    237         this->setCarrier(NULL);
    238        
    239         if(!created)
    240         {
    241             this->destroy();
    242         }
    243        
    244         return true;
    245     }
    246    
     308
     309    /**
     310    @brief
     311        Is called by the PickupCarrier when it is being destroyed.
     312    */
     313    void Pickupable::carrierDestroyed(void)
     314    {
     315        this->destroy();
     316    }
     317
    247318    /**
    248319    @brief
     
    255326        OrxonoxClass* item = NULL;
    256327        this->clone(item);
    257        
     328
    258329        Pickupable* pickup = dynamic_cast<Pickupable*>(item);
    259        
     330
    260331        COUT(4) << "Pickupable (&" << this << ") cloned. Clone is new Pickupable (&" << pickup << ")." << std::endl;
    261332        return pickup;
    262333    }
    263    
     334
    264335    /**
    265336    @brief
     
    273344        SUPER(Pickupable, clone, item);
    274345    }
    275    
     346
     347    /**
     348    @brief
     349        Method to transcribe a Pickupable as a Rewardable to the player.
     350    @param player
     351        A pointer to the PlayerInfo, do whatever you want with it.
     352    @return
     353        Return true if successful.
     354    */
     355    bool Pickupable::reward(PlayerInfo* player)
     356    {
     357        ControllableEntity* entity = player->getControllableEntity();
     358        Pawn* pawn = static_cast<Pawn*>(entity);
     359        PickupCarrier* carrier = static_cast<PickupCarrier*>(pawn);
     360        return this->pickup(carrier);
     361    }
     362
    276363}
  • code/trunk/src/orxonox/interfaces/Pickupable.h

    • Property svn:eol-style set to native
    r6901 r7163  
    4141
    4242#include "core/OrxonoxClass.h"
     43#include "Rewardable.h"
    4344
    44 namespace orxonox
    45 {
    46    
     45namespace orxonox // tolua_export
     46{ // tolua_export
     47
    4748    /**
    4849    @brief
     
    5152        Damian 'Mozork' Frick
    5253    */
    53     class _OrxonoxExport Pickupable : virtual public OrxonoxClass
    54     {
     54    class _OrxonoxExport Pickupable  // tolua_export
     55        : virtual public OrxonoxClass, public Rewardable
     56    {  // tolua_export
    5557        protected:
    5658            Pickupable(); //!< Default constructor.
    57        
     59
    5860        public:
    5961            virtual ~Pickupable(); //!< Default destructor.
    60            
     62
    6163            /**
    6264            @brief Get whether the pickup is currently in use or not.
    6365            @return Returns true if the pickup is currently in use.
    6466            */
    65             inline bool isUsed(void)
    66                 { return this->used_; }
     67            inline bool isUsed(void) { return this->used_; }  // tolua_export
    6768            /**
    6869            @brief  Should be called when the pickup has transited from used to unused or the other way around.
     
    7071            */
    7172            virtual void changedUsed(void) {}
    72            
     73
    7374            /**
    7475            @brief Get the carrier of the pickup.
     
    8283            */
    8384            virtual void changedCarrier(void) {}
    84            
     85
    8586            /**
    8687            @brief Returns whether the Pickupable is currently picked up.
    8788            @return Returns true if the Pickupable is currently picked up, false if not.
    8889            */
    89             inline bool isPickedUp(void)
    90                 { return this->pickedUp_; }
     90            inline bool isPickedUp(void) { return this->pickedUp_; }  // tolua_export
    9191            /**
    9292            @brief  Should be called when the pickup has transited from picked up to dropped or the other way around.
     
    9494            */
    9595            virtual void changedPickedUp(void) {}
     96
     97            /**
     98            @brief Returns whether the Pickupable can be used.
     99            @return Returns true if it can be used.
     100            */
     101            inline bool isUsable(void) { return this->enabled_; } // tolua_export
    96102           
    97             bool pickedUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up.
    98             bool dropped(void); //!< Sets the Pickupable to not picked up or dropped.
    99            
     103            /**
     104            @brief Returns whether the Pickupable can be unused.
     105            @return Returns true if it can be unused.
     106            */
     107            inline bool isUnusable(void) { return this->enabled_; } // tolua_export
     108
     109            /**
     110            @brief Returns whether the Pickupable is enabled.
     111                   Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused.
     112            @return Returns true if the Pickupable is enabled.
     113            */
     114            inline bool isEnabled(void)
     115                { return this->enabled_; }
     116
     117            bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable.
     118            bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable.
     119
    100120            virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup.
    101121            bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable.
    102122            bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup.
    103123            bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this pickup.
    104            
     124
    105125            Pickupable* clone(void); //!< Creates a duplicate of the Pickupable.
    106126            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    107            
     127
    108128            /**
    109129            @brief Get the PickupIdentifier of this Pickupable.
     
    112132            virtual const PickupIdentifier* getPickupIdentifier(void)
    113133                { return this->pickupIdentifier_; }
    114                
     134
    115135            bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
    116136            bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
    117             bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup.
    118            
     137            //TODO: private?
     138            bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the pickup.
     139
     140            //TODO: private?
     141            virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed.
     142
     143            void destroy(void); //!< Is called internally within the pickup module to destroy pickups.
     144
    119145        protected:
    120146            /**
     
    122148            */
    123149            void initializeIdentifier(void) {}
    124            
     150
     151            virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
     152            virtual void destroyPickup(void); //!< Destroys a Pickupable.
     153
     154            /**
     155            @brief Sets the Pickuapble to disabled.
     156            */
     157            inline void setDisabled(void)
     158                { this->enabled_ = false; }
     159
    125160            /**
    126161            @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
     
    131166            */
    132167            virtual bool createSpawner(void) = 0;
    133            
     168
    134169            PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable.
    135            
     170
    136171        private:
    137            
    138             bool used_; //!< Whether the pickup is currently in use or not.
    139             bool pickedUp_; //!< Whether the pickup is currently picked up or not.
    140            
    141             PickupCarrier* carrier_; //!< The carrier of the pickup.
    142             std::list<Identifier*> targets_; //!< The possible targets of this pickup.
    143172
    144     };
    145    
     173            bool used_; //!< Whether the Pickupable is currently in use or not.
     174            bool pickedUp_; //!< Whether the Pickupable is currently picked up or not.
     175
     176            bool enabled_; //!< Whether the Pickupable is enabled or not.
     177
     178            PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable.
     179            std::list<Identifier*> targets_; //!< The possible targets of this Pickupable.
     180
     181            bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed.
     182
     183        // For implementing the Rewardable interface:
     184        public:
     185            virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player.
     186
     187    };  // tolua_export
     188
    146189    SUPER_FUNCTION(10, Pickupable, changedUsed, false);
    147190    SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
    148191    SUPER_FUNCTION(13, Pickupable, changedPickedUp, false);
    149 }
     192}  // tolua_export
    150193
    151194#endif /* _Pickupable_H__ */
  • code/trunk/src/orxonox/interfaces/RadarListener.h

    r5781 r7163  
    4141        virtual ~RadarListener() { }
    4242
    43         virtual void displayObject(RadarViewable* viewable, bool bIsMarked) = 0;
     43        virtual void addObject(RadarViewable* viewable) = 0;
     44        virtual void removeObject(RadarViewable* viewable) = 0;
     45        virtual void objectChanged(RadarViewable* viewable) = 0;
    4446        virtual float getRadarSensitivity() const = 0;
    4547        virtual void radarTick(float dt) = 0;
  • code/trunk/src/orxonox/interfaces/RadarViewable.cc

    r6417 r7163  
    2929#include "RadarViewable.h"
    3030
    31 #include <OgreSceneManager.h>
    32 #include <OgreSceneNode.h>
    33 #include <OgreEntity.h>
    34 
    3531#include "util/StringUtils.h"
    3632#include "core/CoreIncludes.h"
    37 #include "tools/DynamicLines.h"
     33#include "core/GameMode.h"
    3834#include "worldentities/WorldEntity.h"
    3935#include "Radar.h"
    4036#include "Scene.h"
    41 #include "overlays/Map.h"
    4237
    4338namespace orxonox
     
    4641        @brief Constructor.
    4742    */
    48     RadarViewable::RadarViewable()
    49         : MapNode_(NULL)
    50         , MapEntity_(NULL)
    51         , line_(NULL)
    52         , LineNode_(NULL)
    53         , isHumanShip_(false)
     43    RadarViewable::RadarViewable(BaseObject* creator, const WorldEntity* wePtr)
     44        : isHumanShip_(false)
    5445        , bVisibility_(true)
     46        , bInitialized_(false)
     47        , creator_(creator)
     48        , wePtr_(wePtr)
    5549        , radarObjectCamouflage_(0.0f)
    5650        , radarObjectShape_(Dot)
     
    6054
    6155        this->uniqueId_=getUniqueNumberString();
    62 /*
    63         if(Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr())
     56        if( GameMode::showsGraphics() )
    6457        {
    65             this->addEntity();
     58            this->radar_ = this->creator_->getScene()->getRadar();
     59            this->radar_->addRadarObject(this);
    6660        }
    67 
    68         */
     61        this->bInitialized_ = true;
    6962    }
    7063
     
    7265    RadarViewable::~RadarViewable()
    7366    {
    74         if (this->isHumanShip_ && MapNode_)
    75             MapNode_->removeAllChildren();
    7667
    77         if (MapNode_)
    78             delete MapNode_;
    79 
    80         if (MapEntity_)
    81             delete MapEntity_;
    82 
    83         if (line_)
    84             delete line_;
    85 
    86         if (LineNode_)
    87             delete LineNode_;
    88     }
    89 
    90     void RadarViewable::addMapEntity()
    91     { //TODO Check shape and add accordantly
    92         if( this->MapNode_ && !this->MapEntity_ && Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr() )
     68        if( this->bInitialized_ )
    9369        {
    94             COUT(0) << "Adding " << this->uniqueId_ << " to Map.\n";
    95             this->MapEntity_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createEntity( this->uniqueId_, "drone.mesh");
    96             /*this->line_ =  Map::getSingletonPtr()->getMapSceneManagerPtr()->createManualObject(this->uniqueId_ + "_l");
    97             this->line_->begin("Map/line_", Ogre::RenderOperation::OT_LINE_STRIP);
    98             //line_->position(0, -it->getRVWorldPosition().y, 0);
    99             //this->line_->position(0, -20, 0);
    100             this->line_->position(0, 0, -10); //Front Arrow
    101             this->line_->position(0, 0, 0);
    102 
    103             this->line_->end(); */
    104             this->line_ = new Ogre::DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
    105             this->line_->addPoint( Vector3(0,0,0) );
    106             this->line_->addPoint( Vector3(0,0,0) );
    107 
    108             this->MapNode_->attachObject( this->MapEntity_ );
    109 
    110             this->LineNode_ = this->MapNode_->createChildSceneNode();
    111             this->LineNode_->attachObject( this->line_ );
    112         }
    113         else
    114         {
    115             COUT(0) << "Unable to load " << this->uniqueId_ << " to Map.\n";
     70            if( GameMode::showsGraphics() )
     71            {
     72                this->radar_->removeRadarObject(this);
     73            }
    11674        }
    11775    }
    11876
    119     void RadarViewable::updateMapPosition()
    120     {
    121         if( this->MapNode_ )
    122         {
    123             this->MapNode_->setPosition( this->getRVWorldPosition() );
    124             this->MapNode_->translate( this->getRVOrientedVelocity(), static_cast<Ogre::Node::TransformSpace>(3) );
    125             this->MapNode_->setOrientation( this->getWorldEntity()->getOrientation() );
    126 //Vector3 v = this->getRVWorldPosition();
    127             //this->line_->setPoint(1, Vector3(0,v.y,0) );
    128             this->line_->setPoint(1, Vector3( 0, static_cast<float>(static_cast<int>( -Map::getSingletonPtr()->movablePlane_->getDistance( this->getRVWorldPosition() ) ) ) ,0 ));
    129             this->line_->update();
    130             if( Map::getSingletonPtr()->playerShipNode_ )
    131                 this->LineNode_->setDirection( Map::getSingletonPtr()->playerShipNode_->getLocalAxes().GetColumn(1) ,Ogre::Node::TS_WORLD,Vector3::UNIT_Y);
    132         }
    133     }
    134 
    135     void RadarViewable::setRadarObjectDescription(const std::string& str)
    136     {
    137         Radar* radar = this->getWorldEntity()->getScene()->getRadar();
    138         if (radar)
    139             this->radarObjectShape_ = radar->addObjectDescription(str);
    140         else
    141         {
    142             CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl;
    143         }
    144         this->radarObjectDescription_ = str;
    145     }
     77//     void RadarViewable::setRadarObjectDescription(const std::string& str)
     78//     {
     79//         Radar* radar = this->getWorldEntity()->getScene()->getRadar();
     80//         if (radar)
     81//             this->radarObjectShape_ = radar->addObjectDescription(str);
     82//         else
     83//         {
     84//             CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl;
     85//         }
     86//         this->radarObjectDescription_ = str;
     87//     }
    14688
    14789    const Vector3& RadarViewable::getRVWorldPosition() const
     
    167109        }
    168110    }
     111
     112    void RadarViewable::settingsChanged()
     113    {
     114        if( GameMode::showsGraphics() )
     115        {
     116            this->radar_->radarObjectChanged(this);
     117        }
     118    }
    169119}
  • code/trunk/src/orxonox/interfaces/RadarViewable.h

    r5781 r7163  
    3636
    3737#include "util/Math.h"
    38 #include "util/OgreForwardRefs.h"
    3938#include "core/OrxonoxClass.h"
     39#include "core/SmartPtr.h"
    4040
    4141namespace orxonox
    4242{
     43    class BaseObject;
     44
    4345    /**
    4446    @brief Interface for receiving window events.
     
    5658
    5759    public:
    58         RadarViewable();
     60        RadarViewable(BaseObject* creator, const WorldEntity* wePtr);
    5961        virtual ~RadarViewable();
    6062
    6163        inline void setRadarObjectCamouflage(float camouflage)
    62             { this->radarObjectCamouflage_ = camouflage; }
     64            {
     65                if( this->radarObjectCamouflage_ != camouflage )
     66                {
     67                    this->radarObjectCamouflage_ = camouflage;
     68                    this->settingsChanged();
     69                }
     70            }
    6371        inline float getRadarObjectCamouflage() const
    6472            { return this->radarObjectCamouflage_; }
    6573
    6674        inline void setRadarObjectColour(const ColourValue& colour)
    67             { this->radarObjectColour_ = colour; }
     75            {
     76                if(this->radarObjectColour_ != colour)
     77                {
     78                    this->radarObjectColour_ = colour;
     79                    this->settingsChanged();
     80                }
     81            }
    6882        inline const ColourValue& getRadarObjectColour() const
    6983            { return this->radarObjectColour_; }
    7084
    71         void setRadarObjectDescription(const std::string& str);
    72         inline const std::string& getRadarObjectDescription() const
    73             { return this->radarObjectDescription_; }
     85//         void setRadarObjectDescription(const std::string& str);
     86//         inline const std::string& getRadarObjectDescription() const
     87//             { return this->radarObjectDescription_; }
    7488
    7589        inline void setRadarVisibility(bool b)
    76             { this->bVisibility_ = b; }
     90            {
     91                if(b!=this->bVisibility_)
     92                {
     93                    this->bVisibility_ = b;
     94                    this->settingsChanged();
     95                }
     96            }
    7797        inline bool getRadarVisibility() const
    7898            { return this->bVisibility_; }
    7999
    80         virtual const WorldEntity* getWorldEntity() const = 0;
     100        virtual const WorldEntity* getWorldEntity() const{ return this->wePtr_; }
    81101
    82102        const Vector3& getRVWorldPosition() const;
     
    84104
    85105        inline void setRadarObjectShape(Shape shape)
    86             { this->radarObjectShape_ = shape; }
     106            {
     107                if( this->radarObjectShape_ != shape )
     108                {
     109                    this->radarObjectShape_ = shape;
     110                    this->settingsChanged();
     111                }
     112            }
    87113        inline Shape getRadarObjectShape() const
    88114            { return this->radarObjectShape_; }
     115        void settingsChanged();
    89116
    90 /*
    91         inline void setMapNode(Ogre::SceneNode * node)
    92             { this->MapNode_ = node; }
    93         inline Ogre::SceneNode * getMapNode() const
    94             { return this->MapNode_; }
    95         inline void setMapEntity(Ogre::Entity * ent)
    96             { this->MapEntity_ = ent; }
    97         inline Ogre::Entity * getMapEntity() const
    98             { return this->MapEntity_; }
    99 */
    100         //Used for Map
    101         Ogre::SceneNode * MapNode_;
    102         Ogre::Entity * MapEntity_;
    103         Ogre::DynamicLines* line_;
    104         Ogre::SceneNode * LineNode_;
    105         void addMapEntity();
    106         void updateMapPosition();
     117
    107118        bool isHumanShip_;
    108119        inline const std::string& getUniqueId()
     
    115126        void validate(const WorldEntity* object) const;
    116127        bool bVisibility_;
     128        bool bInitialized_;
    117129        //Map
    118130        std::string uniqueId_;
     131        BaseObject* creator_;
    119132
    120133
    121134        //Radar
     135        const WorldEntity* wePtr_;
     136        SmartPtr<Radar> radar_;
    122137        float radarObjectCamouflage_;
    123138        Shape radarObjectShape_;
  • code/trunk/src/orxonox/interfaces/Rewardable.h

    r6417 r7163  
    4848        Damian 'Mozork' Frick
    4949    */
    50     class _OrxonoxExport Rewardable : public OrxonoxClass
     50    class _OrxonoxExport Rewardable : virtual public OrxonoxClass
    5151    {
    5252        public:
     
    5959                Must be implemented by every class inheriting from Rewardable.
    6060            @param player
    61                 A pointer to the ControllableEntity, do whatever you want with it.
     61                A pointer to the PlayerInfo, do whatever you want with it.
    6262            @return
    6363                Return true if successful.
  • code/trunk/src/orxonox/items/Engine.cc

    r6711 r7163  
    6464        this->boostBlur_ = 0;
    6565
    66         this->setCarrierName("Engine");
    6766        this->speedAdd_ = 0.0;
    6867        this->speedMultiply_ = 1.0;
  • code/trunk/src/orxonox/items/Engine.h

    r6711 r7163  
    4646
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    48             void registerVariables();
    4948            void setConfigValues();
    5049
     
    127126
    128127        private:
     128            void registerVariables();
    129129            void networkcallback_shipID();
    130130
  • code/trunk/src/orxonox/items/MultiStateEngine.h

    r6417 r7163  
    5353
    5454            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    55             void registerVariables();
    5655
    5756            virtual void tick(float dt);
     
    6867
    6968        private:
     69            void registerVariables();
     70
    7071            int state_;
    7172            int oldState_;
  • code/trunk/src/orxonox/overlays/CMakeLists.txt

    r6746 r7163  
    44  OverlayGroup.cc
    55
    6 COMPILATION_BEGIN OverlayCompilation.cc
     6#COMPILATION_BEGIN OverlayCompilation.cc
    77  InGameConsole.cc
    8   Map.cc
    9 COMPILATION_END
     8#COMPILATION_END
    109)
  • code/trunk/src/orxonox/overlays/GUISheet.cc

    r6746 r7163  
    3232#include "core/GUIManager.h"
    3333#include "core/XMLPort.h"
     34#include "core/GameMode.h"
    3435
    3536namespace orxonox
  • code/trunk/src/orxonox/pickup/PickupIdentifier.cc

    • Property svn:eol-style set to native
    r6725 r7163  
    3939namespace orxonox
    4040{
    41    
     41
    4242    /**
    4343    @brief
     
    4747    {
    4848        RegisterRootObject(PickupIdentifier);
    49        
     49
    5050        if(pickup == NULL)
    5151            COUT(1) << "Error, PickupIdentifier was created without a valid Pickupable." << std::endl;
    52        
     52
    5353        this->pickup_ = pickup;
    5454    }
    55    
     55
    5656    PickupIdentifier::~PickupIdentifier()
    5757    {
    5858
    5959    }
    60    
     60
    6161    /**
    6262    @brief
     
    7474            COUT(1) << "Error in PickupIdentifier::compare: Input Identifier is NULL." << std::endl;
    7575        }
    76        
     76
    7777        if(identifier->pickup_ == NULL && this->pickup_ == NULL)
    7878        {
     
    8080            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
    8181        }
    82        
     82
    8383        if(identifier->pickup_ == NULL)
    8484        {
     
    8686            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
    8787        }
    88        
     88
    8989        if(this->pickup_ == NULL)
    9090        {
     
    9292            COUT(1) << "Error in PickupIdentifier::compare: Pickup stored by Identifier is NULL." << std::endl;
    9393        }
    94        
     94
    9595        //! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames.
    9696        if(!identifier->pickup_->getIdentifier()->isExactlyA(this->pickup_->getIdentifier()))
    9797            return this->pickup_->getIdentifier()->getName().compare(identifier->pickup_->getIdentifier()->getName());
    98        
     98
    9999        //! If the class is the same for both PickupIdentifiers we go on to check the parameters of the class.
    100100        //! If the two have a different number of parameters then obviusly something is very wrong.
     
    104104            return this->parameters_.size()-identifier->parameters_.size();
    105105        }
    106        
    107         //! We iterate through all parameters and compar their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
     106
     107        //! We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
    108108        for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++)
    109109        {
     
    117117                return it->second.compare(identifier->parameters_.find(it->first)->second);
    118118        }
    119            
     119
    120120        return 0;
    121121    }
    122    
     122
    123123    /**
    124124    @brief
     
    134134    {
    135135        COUT(4) << "PickupIdentifier " << name << ", " << value << std::endl;
    136        
     136
    137137        if(!(this->parameters_.find(name) == this->parameters_.end()))
    138138        {
     
    140140            return false;
    141141        }
    142        
     142
    143143        this->parameters_[name] = value;
    144        
     144
    145145        return true;
    146146    }
    147    
     147
    148148}
  • code/trunk/src/orxonox/pickup/PickupIdentifier.h

    • Property svn:eol-style set to native
    r6540 r7163  
    4141#include "core/Identifier.h"
    4242
    43 #include "core/OrxonoxClass.h" 
     43#include "core/OrxonoxClass.h"
    4444
    4545namespace orxonox
    4646{
    47    
     47
    4848    /**
    4949    @brief
     
    5757    class _OrxonoxExport PickupIdentifier : virtual public OrxonoxClass
    5858    {
    59        
     59
    6060        public:
    6161            PickupIdentifier(Pickupable* pickup); //!< Constructor.
    6262            ~PickupIdentifier(); //!< Destructor.
    63            
     63
    6464            virtual int compare(const PickupIdentifier* identifier) const; //!< Compares two PickupIdentifiers and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b).
    65            
     65
    6666            bool addParameter(std::string & name, std::string & value); //!< Add a parameter to the PickupIdentifier.
    67            
     67
    6868        private:
    6969            Pickupable* pickup_; //!< The Pickupable the PickupIdentififer is for.
    7070            std::map<std::string, std::string> parameters_; //!< The parameters identifying the type of the pickup beyond the class.
    71            
     71
    7272    };
    73    
     73
    7474    /**
    7575    @brief
     
    8181            { return lhs->compare(rhs) < 0; }
    8282    };
    83    
     83
    8484}
    8585
  • code/trunk/src/orxonox/sound/BaseSound.cc

    r6502 r7163  
    3333#include <al.h>
    3434
     35#include "util/Math.h"
    3536#include "core/CoreIncludes.h"
    3637#include "core/GameMode.h"
     
    248249        else // No source acquired so far, but might be set to playing or paused
    249250        {
    250             State state = this->state_; // save
     251            State state = static_cast<State>(this->state_); // save
    251252            if (this->isPlaying() || this->isPaused())
    252253                doPlay();
  • code/trunk/src/orxonox/sound/BaseSound.h

    r6417 r7163  
    112112        float           volume_;
    113113        bool            bLooping_;
    114         State           state_;
     114        uint8_t         state_;       // This Variable is actually of type State
    115115        float           pitch_;
    116116
  • code/trunk/src/orxonox/sound/SoundStreamer.cc

    • Property svn:eol-style set to native
  • code/trunk/src/orxonox/sound/SoundStreamer.h

    • Property svn:eol-style set to native
  • code/trunk/src/orxonox/sound/WorldSound.cc

    r6417 r7163  
    5858        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::loopingChanged));
    5959        registerVariable(pitch_,    ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::pitchChanged));
    60         registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
     60        registerVariable((uint8_t&)(BaseSound::state_), ObjectDirection::ToClient, new NetworkCallback<WorldSound>(this, &WorldSound::stateChanged));
    6161    }
    6262
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.cc

    r6417 r7163  
    274274            return BLANKSTRING;
    275275    }
     276
     277    void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume){
     278        if (this->defSndWpnFire_) {
     279            this->defSndWpnFire_->setSource(soundPath);
     280            this->defSndWpnFire_->setVolume(soundVolume);
     281        }
     282    }
     283
    276284}
  • code/trunk/src/orxonox/weaponsystem/WeaponMode.h

    r6417 r7163  
    5555            void setDefaultSound(const std::string& soundPath);
    5656            const std::string& getDefaultSound();
    57 
     57            void setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume);
    5858
    5959            // Munition
  • code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc

    r6417 r7163  
    214214        Weapon* weapon = 0;
    215215        while ((weapon = wPack->getWeapon(i++)))
    216             weapon->getWeaponSlot()->removeWeapon();
     216            if (weapon->getWeaponSlot())
     217                weapon->getWeaponSlot()->removeWeapon();
    217218
    218219        // Remove all added links from the WeaponSets
  • code/trunk/src/orxonox/worldentities/BigExplosion.cc

    r5929 r7163  
    101101        this->debrisEntity3_ = new MovableEntity(this);
    102102        this->debrisEntity4_ = new MovableEntity(this);
     103       
     104        this->debrisEntity1_->setSyncMode(0);
     105        this->debrisEntity2_->setSyncMode(0);
     106        this->debrisEntity3_->setSyncMode(0);
     107        this->debrisEntity4_->setSyncMode(0);
    103108
    104109        this->debris1_ = new Model(this);
     
    106111        this->debris3_ = new Model(this);
    107112        this->debris4_ = new Model(this);
     113       
     114        this->debris1_->setSyncMode(0);
     115        this->debris2_->setSyncMode(0);
     116        this->debris3_->setSyncMode(0);
     117        this->debris4_->setSyncMode(0);
    108118
    109119        this->explosion_ = new StaticEntity(this);
     120        this->explosion_->setSyncMode(0);
    110121
    111122        this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
     
    158169        effect->setSource("Orxonox/explosion2b");
    159170        effect->setLifetime(4.0f);
     171        effect->setSyncMode(0);
    160172
    161173        ParticleSpawner* effect2 = new ParticleSpawner(this->getCreator());
     
    163175        effect2->setSource("Orxonox/smoke6");
    164176        effect2->setLifetime(4.0f);
     177        effect2->setSyncMode(0);
    165178
    166179        this->explosion_->attach(effect);
     
    181194            MovableEntity* partEntity1 = new MovableEntity(this);
    182195            MovableEntity* partEntity2 = new MovableEntity(this);
     196           
     197            part1->setSyncMode(0);
     198            part2->setSyncMode(0);
     199            partEntity1->setSyncMode(0);
     200            partEntity2->setSyncMode(0);
    183201
    184202            partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100));
  • code/trunk/src/orxonox/worldentities/BigExplosion.h

    r5929 r7163  
    4545
    4646            virtual void tick(float dt);
    47             void registerVariables();
    4847
    4948            inline void setLOD(LODParticle::Value level)
     
    5352
    5453        private:
     54            void registerVariables();
    5555
    5656            void LODchanged();
  • code/trunk/src/orxonox/worldentities/CMakeLists.txt

    r6417 r7163  
    55  MobileEntity.cc
    66  ControllableEntity.cc
    7 
     7  Drone.cc
    88  BigExplosion.cc
    99  EffectContainer.cc
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r6417 r7163  
    4949            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5050            virtual void tick(float dt);
    51             void registerVariables();
    5251            void setConfigValues();
    5352
     
    137136            inline float getMouseLookSpeed() const
    138137                { return this->mouseLookSpeed_; }
     138            inline CameraPosition* getCurrentCameraPosition()
     139                { return this->currentCameraPosition_; }
    139140
    140141            inline Controller* getXMLController() const
     
    162163                { this->hudtemplate_ = name; }
    163164
     165            Ogre::SceneNode* cameraPositionRootNode_;
     166
    164167        private:
     168            void registerVariables();
    165169            void setXMLController(Controller* controller);
    166170
     
    208212            bool bMouseLook_;
    209213            float mouseLookSpeed_;
    210             Ogre::SceneNode* cameraPositionRootNode_;
    211214            std::list<SmartPtr<CameraPosition> > cameraPositions_;
    212215            CameraPosition* currentCameraPosition_;
  • code/trunk/src/orxonox/worldentities/ExplosionChunk.h

    r5929 r7163  
    4444
    4545            virtual void tick(float dt);
    46             void registerVariables();
    4746
    4847            inline void setLOD(LODParticle::Value level)
     
    5251
    5352        private:
     53            void registerVariables();
    5454            void LODchanged();
    5555            void checkStop();
  • code/trunk/src/orxonox/worldentities/MobileEntity.cc

    r5781 r7163  
    4646        this->angularAcceleration_ = Vector3::ZERO;
    4747        this->angularVelocity_     = Vector3::ZERO;
    48 
    49         this->registerVariables();
    5048    }
    5149
  • code/trunk/src/orxonox/worldentities/MovableEntity.h

    r6417 r7163  
    4848            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4949            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
    50             void registerVariables();
    5150
    5251            using WorldEntity::setPosition;
     
    7978
    8079        private:
     80            void registerVariables();
    8181            void clientConnected(unsigned int clientID);
    8282            void clientDisconnected(unsigned int clientID);
  • code/trunk/src/orxonox/worldentities/StaticEntity.h

    r5781 r7163  
    4242            virtual ~StaticEntity();
    4343
    44             void registerVariables();
    45 
    4644            using WorldEntity::setPosition;
    4745            using WorldEntity::setOrientation;
     
    5149
    5250        private:
     51            void registerVariables();
    5352            bool isCollisionTypeLegal(CollisionType type) const;
    5453
  • code/trunk/src/orxonox/worldentities/WorldEntity.cc

    r6524 r7163  
    8181        this->node_->setPosition(Vector3::ZERO);
    8282        this->node_->setOrientation(Quaternion::IDENTITY);
    83        
     83
    8484        // Activity and visibility memory.
    8585        this->bActiveMem_ = true;
     
    205205        registerVariable(this->parentID_,       VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::networkcallback_parentChanged));
    206206    }
    207    
     207
    208208    /**
    209209    @brief
     
    213213    {
    214214        SUPER(WorldEntity, changedActivity);
    215        
     215
    216216        for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
    217217        {
     
    227227        }
    228228    }
    229    
     229
    230230    /**
    231231    @brief
     
    235235    {
    236236        SUPER(WorldEntity, changedVisibility);
    237        
     237
    238238        for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
    239239        {
  • code/trunk/src/orxonox/worldentities/WorldEntity.h

    r6524 r7163  
    9494
    9595            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    96             void registerVariables();
    9796
    9897            inline const Ogre::SceneNode* getNode() const
     
    105104            static const Vector3 DOWN;
    106105            static const Vector3 UP;
    107            
     106
    108107            virtual void changedActivity(void);
    109108            virtual void changedVisibility(void);
     
    214213
    215214        private:
     215            void registerVariables();
     216           
    216217            inline void lookAt_xmlport(const Vector3& target)
    217218                { this->lookAt(target); }
     
    234235            std::set<WorldEntity*> children_;
    235236            bool bDeleteWithParent_;
    236            
     237
    237238            bool bActiveMem_;
    238239            bool bVisibleMem_;
  • code/trunk/src/orxonox/worldentities/pawns/CMakeLists.txt

    r5781 r7163  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
     2  FpsPlayer.cc
    23  Spectator.cc
    34  Pawn.cc
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r6864 r7163  
    5353    CreateFactory(Pawn);
    5454
    55     Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator)
     55    Pawn::Pawn(BaseObject* creator)
     56        : ControllableEntity(creator)
     57        , RadarViewable(creator, static_cast<WorldEntity*>(this))
    5658    {
    5759        RegisterObject(Pawn);
     
    6466        this->maxHealth_ = 0;
    6567        this->initialHealth_ = 0;
     68        this->shieldHealth_ = 0;
     69        this->shieldAbsorption_ = 0.5;
    6670
    6771        this->lastHitOriginator_ = 0;
     
    7882        else
    7983            this->weaponSystem_ = 0;
    80        
    81         this->setCarrierName("Pawn");
    8284
    8385        this->setRadarObjectColour(ColourValue::Red);
     
    105107        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    106108        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     109
     110        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
     111        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
     112
    107113        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
    108114        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
     
    116122    void Pawn::registerVariables()
    117123    {
    118         registerVariable(this->bAlive_,        VariableDirection::ToClient);
    119         registerVariable(this->health_,        VariableDirection::ToClient);
    120         registerVariable(this->initialHealth_, VariableDirection::ToClient);
    121         registerVariable(this->bReload_,       VariableDirection::ToServer);
    122         registerVariable(this->aimPosition_,   Bidirectionality::ServerMaster, 0, true);
     124        registerVariable(this->bAlive_,           VariableDirection::ToClient);
     125        registerVariable(this->health_,           VariableDirection::ToClient);
     126        registerVariable(this->initialHealth_,    VariableDirection::ToClient);
     127        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
     128        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
     129        registerVariable(this->bReload_,          VariableDirection::ToServer);
     130        registerVariable(this->aimPosition_,      VariableDirection::ToServer);  // For the moment this variable gets only transfered to the server
    123131    }
    124132
     
    162170        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    163171        {
    164             this->setHealth(this->health_ - damage);
     172            //share the dealt damage to the shield and the Pawn.
     173            float shielddamage = damage*this->shieldAbsorption_;
     174            float healthdamage = damage*(1-this->shieldAbsorption_);
     175
     176            // In case the shield can not take all the shield damage.
     177            if (shielddamage > this->getShieldHealth())
     178            {
     179                healthdamage += shielddamage-this->getShieldHealth();
     180                this->setShieldHealth(0);
     181            }
     182
     183            this->setHealth(this->health_ - healthdamage);
     184
     185            if (this->getShieldHealth() > 0)
     186            {
     187                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     188            }
     189
    165190            this->lastHitOriginator_ = originator;
    166191
     
    336361    {
    337362        if (this->weaponSystem_)
     363        {
    338364            this->weaponSystem_->addWeaponPack(wPack);
     365            this->addedWeaponPack(wPack);
     366        }
    339367    }
    340368
     
    342370    {
    343371        if (this->weaponSystem_)
     372        {
    344373            if (!this->weaponSystem_->addWeaponPack(wPack))
    345374                wPack->destroy();
     375            else
     376                this->addedWeaponPack(wPack);
     377        }
    346378    }
    347379
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r6711 r7163  
    5050            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5151            virtual void tick(float dt);
    52             void registerVariables();
    5352
    5453            inline bool isAlive() const
     
    7372                { return this->initialHealth_; }
    7473
     74            inline void setShieldHealth(float shieldHealth)
     75            { this->shieldHealth_ = shieldHealth; }
     76            inline float getShieldHealth()
     77            { return this->shieldHealth_; }
     78
     79            inline void setShieldAbsorption(float shieldAbsorption)
     80            { this->shieldAbsorption_ = shieldAbsorption; }
     81            inline float getShieldAbsorption()
     82            { return this->shieldAbsorption_; }
     83
    7584            inline ControllableEntity* getLastHitOriginator() const
    7685                { return this->lastHitOriginator_; }
     
    91100            void addWeaponPackXML(WeaponPack * wPack);
    92101            WeaponPack * getWeaponPack(unsigned int index) const;
     102
     103            virtual void addedWeaponPack(WeaponPack* wPack) {}
    93104
    94105            inline const WorldEntity* getWorldEntity() const
     
    116127            Vector3 getAimPosition()
    117128                { return this->aimPosition_; }
    118                
     129
    119130            virtual const Vector3& getCarrierPosition(void)
    120131                { return this->getWorldPosition(); };
     
    141152            float maxHealth_;
    142153            float initialHealth_;
     154            float shieldHealth_;
     155            float shieldAbsorption_; // Has to be between 0 and 1
    143156
    144157            Pawn* lastHitOriginator_;
     
    152165
    153166        private:
     167            void registerVariables();
    154168            inline void setWeaponSystem(WeaponSystem* weaponsystem)
    155169                { this->weaponSystem_ = weaponsystem; }
  • code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h

    r6711 r7163  
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4848            virtual void tick(float dt);
    49             void registerVariables();
    5049            void setConfigValues();
    5150
     
    9998
    10099        private:
     100            void registerVariables();
    101101            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    102102
    103         private:
    104103            void loadEngineTemplate();
    105104
  • code/trunk/src/orxonox/worldentities/pawns/Spectator.h

    r6417 r7163  
    4444
    4545            void setConfigValues();
    46             void registerVariables();
    4746            virtual void tick(float dt);
    4847
     
    6362
    6463        private:
     64            void registerVariables();
    6565            void changedGreeting();
    6666            void changedFlareVisibility();
Note: See TracChangeset for help on using the changeset viewer.