Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 8, 2009, 12:36:08 AM (16 years ago)
Author:
dafrick
Message:

Merging of the current QuestSystem branch.

Location:
code/branches/questsystem5
Files:
4 added
2 deleted
35 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem5

  • code/branches/questsystem5/src/core/CMakeLists.txt

    r2710 r2907  
    2424  Core.cc
    2525  Event.cc
     26  Game.cc
     27  GameMode.cc
    2628  GameState.cc
    2729  Language.cc
     
    2931  ObjectListBase.cc
    3032  OrxonoxClass.cc
    31   RootGameState.cc
    3233
    3334  # command
  • code/branches/questsystem5/src/core/Clock.h

    r2171 r2907  
    4545    class _CoreExport Clock
    4646    {
    47         friend class RootGameState;
    48 
    4947    public:
    5048        Clock();
    5149        ~Clock();
     50
     51        void capture();
    5252
    5353        unsigned long long getMicroseconds()   const { return tickTime_; }
     
    6363    private:
    6464        Clock(const Clock& instance);
    65         void capture();
    6665
    6766        Ogre::Timer*       timer_;
  • code/branches/questsystem5/src/core/ConfigFileManager.cc

    r2759 r2907  
    190190        this->bUpdated_ = true;
    191191
    192         return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryValue(name, fallback, bString)));
     192        return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryValue(name, fallback, bString)));
    193193    }
    194194
     
    207207
    208208        if (index == 0)
    209             return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
    210         else
    211             return this->entries_.insert(++this->getEntryIterator(name, index - 1, "", bString), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
     209            return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
     210        else
     211            return this->entries_.insert(++this->getEntryIterator(name, index - 1, "", bString), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
    212212    }
    213213
  • code/branches/questsystem5/src/core/Core.cc

    r2759 r2907  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    25  *      Reto Grieder
     26 *      ...
    2627 *
    2728 */
     
    4142
    4243#ifdef ORXONOX_PLATFORM_WINDOWS
     44#  ifndef WIN32_LEAN_AND_MEAN
     45#    define WIN32_LEAN_AND_MEAN
     46#  endif
    4347#  include <windows.h>
    4448#elif defined(ORXONOX_PLATFORM_APPLE)
     
    5155
    5256#include "SpecialConfig.h"
     57#include "util/Debug.h"
    5358#include "util/Exception.h"
     59#include "util/SignalHandler.h"
     60#include "Clock.h"
     61#include "CommandExecutor.h"
     62#include "CommandLine.h"
     63#include "ConfigFileManager.h"
     64#include "ConfigValueIncludes.h"
     65#include "CoreIncludes.h"
     66#include "Factory.h"
     67#include "Identifier.h"
    5468#include "Language.h"
    55 #include "CoreIncludes.h"
    56 #include "ConfigValueIncludes.h"
    5769#include "LuaBind.h"
    58 #include "CommandLine.h"
     70#include "Shell.h"
     71#include "TclBind.h"
     72#include "TclThreadManager.h"
    5973
    6074namespace orxonox
     
    6781    static boost::filesystem::path logPath_g;                   //!< Path to the log file folder
    6882
    69     bool Core::bShowsGraphics_s = false;
    70     bool Core::bHasServer_s     = false;
    71     bool Core::bIsClient_s      = false;
    72     bool Core::bIsStandalone_s  = false;
    73     bool Core::bIsMaster_s      = false;
    74 
    75     bool Core::isDevBuild_s     = false;
    7683    Core* Core::singletonRef_s  = 0;
    7784
    7885    SetCommandLineArgument(mediaPath, "").information("PATH");
    79     SetCommandLineArgument(directory, "").information("DIR");
    80 
    81     /**
    82         @brief Constructor: Registers the object and sets the config-values.
    83         @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel()
    84     */
     86    SetCommandLineArgument(writingPathSuffix, "").information("DIR");
     87    SetCommandLineArgument(settingsFile, "orxonox.ini");
     88    SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu");
     89
    8590    Core::Core()
    8691    {
     
    8994        assert(Core::singletonRef_s == 0);
    9095        Core::singletonRef_s = this;
    91 
    92         this->bInitializeRandomNumberGenerator_ = false;
    93         this->setConfigValues();
     96    }
     97
     98    void Core::initialise(int argc, char** argv)
     99    {
     100        // Parse command line arguments fist
     101        try
     102        {
     103            CommandLine::parseAll(argc, argv);
     104        }
     105        catch (ArgumentException& ex)
     106        {
     107            COUT(1) << ex.what() << std::endl;
     108            COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
     109        }
     110
     111        // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
     112        // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
     113        // the timer though).
     114        int limitToCPU = CommandLine::getValue("limitToCPU");
     115        if (limitToCPU > 0)
     116            setThreadAffinity((unsigned int)limitToCPU);
     117
     118        // Determine and set the location of the executable
     119        setExecutablePath();
     120
     121        // Determine whether we have an installed or a binary dir run
     122        // The latter occurs when simply running from the build directory
     123        checkDevBuild();
     124
     125        // Make sure the directories we write in exist or else make them
     126        createDirectories();
     127
     128        // create a signal handler (only active for linux)
     129        // This call is placed as soon as possible, but after the directories are set
     130        this->signalHandler_ = new SignalHandler();
     131        this->signalHandler_->doCatch(executablePath_g.string(), Core::getLogPathString() + "orxonox_crash.log");
    94132
    95133        // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used
    96134        OutputHandler::getOutStream().setLogPath(Core::getLogPathString());
    97135
     136        // Manage ini files and set the default settings file (usually orxonox.ini)
     137        this->configFileManager_ = new ConfigFileManager();
     138        this->configFileManager_->setFilename(ConfigFileType::Settings,
     139            CommandLine::getValue("settingsFile").getString());
     140
     141        this->languageInstance_ = new Language();
     142
     143        // Do this soon after the ConfigFileManager has been created to open up the
     144        // possibility to configure everything below here
     145        this->setConfigValues();
     146
    98147        // Possible media path override by the command line
    99148        if (!CommandLine::getArgument("mediaPath")->hasDefaultValue())
     
    102151            Core::tsetMediaPath(CommandLine::getValue("mediaPath"));
    103152        }
     153
     154        // Create the lua interface
     155        this->luaBind_ = new LuaBind();
     156
     157        // initialise Tcl
     158        this->tclBind_ = new TclBind(Core::getMediaPathString());
     159        this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
     160
     161        // create a shell
     162        this->shell_ = new Shell();
     163
     164        // creates the class hierarchy for all classes with factories
     165        Factory::createClassHierarchy();
     166       
     167        this->loaded_ = true;
    104168    }
    105169
     
    109173    Core::~Core()
    110174    {
     175        this->loaded_ = false;
     176
     177        delete this->shell_;
     178        delete this->tclThreadManager_;
     179        delete this->tclBind_;
     180        delete this->luaBind_;
     181        delete this->languageInstance_;
     182        delete this->configFileManager_;
     183        delete this->signalHandler_;
     184
     185        // Destroy command line arguments
     186        CommandLine::destroyAllArguments();
     187        // Also delete external console command that don't belong to an Identifier
     188        CommandExecutor::destroyExternalCommands();
     189
    111190        assert(Core::singletonRef_s);
    112191        Core::singletonRef_s = 0;
     
    292371    }
    293372
    294     /**
    295     @brief
    296         Performs the rather lower level operations just after
    297         int main() has been called.
    298     @remarks
    299         This gets called AFTER pre-main stuff like AddFactory,
    300         SetConsoleCommand, etc.
    301     */
    302     /*static*/ void Core::postMainInitialisation()
    303     {
    304         // set location of the executable
    305         Core::setExecutablePath();
    306 
    307         // Determine whether we have an installed or a binary dir run
    308         // The latter occurs when simply running from the build directory
    309         Core::checkDevBuild();
    310 
    311         // Make sure the directories we write in exist or else make them
    312         Core::createDirectories();
     373
     374    /**
     375    @note
     376        The code of this function has been copied and adjusted from OGRE, an open source graphics engine.
     377            (Object-oriented Graphics Rendering Engine)
     378        For the latest info, see http://www.ogre3d.org/
     379
     380        Copyright (c) 2000-2008 Torus Knot Software Ltd
     381
     382        OGRE is licensed under the LGPL. For more info, see OGRE license.
     383    */
     384    void Core::setThreadAffinity(int limitToCPU)
     385    {
     386        if (limitToCPU <= 0)
     387            return;
     388
     389#ifdef ORXONOX_PLATFORM_WINDOWS
     390        unsigned int coreNr = limitToCPU - 1;
     391        // Get the current process core mask
     392        DWORD procMask;
     393        DWORD sysMask;
     394#  if _MSC_VER >= 1400 && defined (_M_X64)
     395        GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
     396#  else
     397        GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
     398#  endif
     399
     400        // If procMask is 0, consider there is only one core available
     401        // (using 0 as procMask will cause an infinite loop below)
     402        if (procMask == 0)
     403            procMask = 1;
     404
     405        // if the core specified with coreNr is not available, take the lowest one
     406        if (!(procMask & (1 << coreNr)))
     407            coreNr = 0;
     408
     409        // Find the lowest core that this process uses and coreNr suggests
     410        DWORD threadMask = 1;
     411        while ((threadMask & procMask) == 0 || (threadMask < (1u << coreNr)))
     412            threadMask <<= 1;
     413
     414        // Set affinity to the first core
     415        SetThreadAffinityMask(GetCurrentThread(), threadMask);
     416#endif
    313417    }
    314418
     
    317421        Compares the executable path with the working directory
    318422    */
    319     /*static*/ void Core::setExecutablePath()
     423    void Core::setExecutablePath()
    320424    {
    321425#ifdef ORXONOX_PLATFORM_WINDOWS
     
    369473        don't write the logs and config files to ~/.orxonox
    370474    */
    371     /*static*/ void Core::checkDevBuild()
     475    void Core::checkDevBuild()
    372476    {
    373477        if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me"))
    374478        {
    375479            COUT(1) << "Running from the build tree." << std::endl;
    376             Core::isDevBuild_s = true;
     480            Core::isDevBuild_ = true;
    377481            mediaPath_g  = ORXONOX_MEDIA_DEV_PATH;
    378482            configPath_g = ORXONOX_CONFIG_DEV_PATH;
     
    385489            boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
    386490            rootPath_g = executablePath_g;
    387             while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) || rootPath_g.empty())
     491            while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) && !rootPath_g.empty())
    388492                rootPath_g = rootPath_g.branch_path();
    389493            if (rootPath_g.empty())
     
    416520
    417521        // Option to put all the config and log files in a separate folder
    418         if (!CommandLine::getArgument("directory")->hasDefaultValue())
    419         {
    420             std::string directory(CommandLine::getValue("directory").getString());
     522        if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue())
     523        {
     524            std::string directory(CommandLine::getValue("writingPathSuffix").getString());
    421525            configPath_g = configPath_g / directory;
    422526            logPath_g    = logPath_g    / directory;
     
    429533        if necessary. Otherwise me might have problems opening those files.
    430534    */
    431     /*static*/ void Core::createDirectories()
     535    void Core::createDirectories()
    432536    {
    433537        std::vector<std::pair<boost::filesystem::path, std::string> > directories;
     
    451555        }
    452556    }
     557
     558    void Core::update(const Clock& time)
     559    {
     560        this->tclThreadManager_->update(time);
     561    }
    453562}
  • code/branches/questsystem5/src/core/Core.h

    r2759 r2907  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    25  *      Reto Grieder
     26 *      ...
    2627 *
    2728 */
     
    4445#include "util/OutputHandler.h"
    4546
    46 // Only allow main to access postMainInitialisation, so we need a forward declaration
    47 int main(int, char**);
    4847// boost::filesystem header has quite a large tail, use forward declaration
    4948namespace boost { namespace filesystem
     
    5958    class _CoreExport Core : public OrxonoxClass
    6059    {
    61         friend int ::main(int, char**); // sets isDevBuild_s
    62 
    6360        public:
    6461            Core();
    6562            ~Core();
     63
     64            void initialise(int argc, char** argv);
    6665            void setConfigValues();
     66
     67            void update(const Clock& time);
    6768
    6869            static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
     
    7273            static const std::string& getLanguage();
    7374            static void  resetLanguage();
    74 
    75             static bool isDevBuild() { return Core::isDevBuild_s; }
    7675
    7776            static void tsetMediaPath(const std::string& path)
     
    8483            static std::string getLogPathString();
    8584
    86             // fast access global variables.
    87             static bool showsGraphics() { return bShowsGraphics_s; }
    88             static bool hasServer()     { return bHasServer_s; }
    89             static bool isClient()      { return bIsClient_s; }
    90             static bool isStandalone()  { return bIsStandalone_s; }
    91             static bool isMaster()      { return bIsMaster_s; }
    92             static void setShowsGraphics(bool val) { bShowsGraphics_s = val; updateIsMaster(); }
    93             static void setHasServer    (bool val) { bHasServer_s     = val; updateIsMaster(); }
    94             static void setIsClient     (bool val) { bIsClient_s      = val; updateIsMaster(); }
    95             static void setIsStandalone (bool val) { bIsStandalone_s  = val; updateIsMaster(); }
    96             static void updateIsMaster  ()         { bIsMaster_s      = (bHasServer_s || bIsStandalone_s); }
    97 
    9885        private:
    9986            Core(const Core&);
     87
     88            void checkDevBuild();
     89            void setExecutablePath();
     90            void createDirectories();
     91            void setThreadAffinity(int limitToCPU);
     92
    10093            void resetLanguageIntern();
    10194            void initializeRandomNumberGenerator();
     
    10598            void _tsetMediaPath(const std::string& path);
    10699
    107             static void postMainInitialisation();
    108             static void checkDevBuild();
    109             static void setExecutablePath();
    110             static void createDirectories();
     100            // Singletons
     101            ConfigFileManager*    configFileManager_;
     102            Language*             languageInstance_;
     103            LuaBind*              luaBind_;
     104            Shell*                shell_;
     105            SignalHandler*        signalHandler_;
     106            TclBind*              tclBind_;
     107            TclThreadManager*     tclThreadManager_;
    111108
    112109            int softDebugLevel_;                            //!< The debug level
     
    117114            bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
    118115            std::string mediaPathString_;                   //!< Path to the data/media file folder as string
    119 
    120             static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
    121             static bool bHasServer_s;                       //!< global variable that tells whether this is a server
    122             static bool bIsClient_s;
    123             static bool bIsStandalone_s;
    124             static bool bIsMaster_s;
    125 
    126             static bool isDevBuild_s;                       //!< True for builds in the build directory (not installed)
     116            bool isDevBuild_;                               //!< True for builds in the build directory (not installed)
     117            bool loaded_;                                   //!< Only true if constructor was interrupted
    127118
    128119            static Core* singletonRef_s;
  • code/branches/questsystem5/src/core/CorePrereqs.h

    r2710 r2907  
    166166
    167167  // game states
    168   class GameStateBase;
    169   template <class ParentType>
     168  class Game;
    170169  class GameState;
    171   class RootGameState;
     170  struct GameStateTreeNode;
    172171
    173172  // input
  • code/branches/questsystem5/src/core/GameState.cc

    r1764 r2907  
    3030@file
    3131@brief
    32     Implementation of GameStateBase class.
     32    Implementation of GameState class.
    3333*/
    3434
    3535#include "GameState.h"
     36#include <cassert>
    3637#include "util/Debug.h"
    3738#include "util/Exception.h"
     39#include "Clock.h"
    3840
    3941namespace orxonox
     
    4345        Constructor only initialises variables and sets the name permanently.
    4446    */
    45     GameStateBase::GameStateBase(const std::string& name)
     47    GameState::GameState(const std::string& name)
    4648        : name_(name)
    47         //, parent_(0)
    48         , activeChild_(0)
    49         //, bPausegetParent()(false)
     49        , parent_(0)
    5050    {
    51         Operations temp = {false, false, false, false, false};
    52         this->operation_ = temp;
     51        this->activity_.activating   = false;
     52        this->activity_.active       = false;
     53        this->activity_.deactivating = false;
     54        this->activity_.suspended    = false;
     55        this->activity_.topState     = false;
     56        this->activity_.updating     = false;
    5357    }
    5458
     
    5761        Destructor only checks that we don't delete an active state.
    5862    */
    59     GameStateBase::~GameStateBase()
     63    GameState::~GameState()
    6064    {
    61         OrxAssert(this->operation_.active == false, "Deleting an active GameState is a very bad idea..");
     65        OrxAssert(this->activity_.active == false, "Deleting an active GameState is a very bad idea..");
    6266    }
    6367
     
    6973        The state to be added.
    7074    */
    71     void GameStateBase::addChild(GameStateBase* state)
     75    void GameState::addChild(GameState* state)
    7276    {
    73         if (!state)
    74             return;
    75         // check if the state/tree to be added has states in it that already exist in this tree.
    76         for (std::map<std::string, GameStateBase*>::const_iterator it = state->allChildren_.begin();
    77             it != state->allChildren_.end(); ++it)
     77        assert(state != NULL);
     78
     79        std::map<std::string, GameState*>::const_iterator it = this->children_.find(state->getName());
     80        if (it == this->children_.end())
    7881        {
    79             if (this->getState(it->second->getName()))
    80             {
    81                 ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
    82                 return;
    83             }
     82            this->children_[state->getName()] = state;
     83            // mark us as parent
     84            state->setParent(this);
    8485        }
    85         if (this->getState(state->name_))
     86        else
    8687        {
    87             ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
    88             return;
     88            ThrowException(GameState, "Cannot add two children with the same name");
    8989        }
    90         // Make sure we don't add a tree that already has an active state.
    91         if (state->getCurrentState())
    92         {
    93             ThrowException(GameState, "Cannot merge a tree that is already active.");
    94             return;
    95         }
    96 
    97         // merge the child's children into this tree
    98         for (std::map<std::string, GameStateBase*>::const_iterator it = state->allChildren_.begin();
    99             it != state->allChildren_.end(); ++it)
    100             this->grandchildAdded(state, it->second);
    101         // merge 'state' into this tree
    102         this->grandchildAdded(state, state);
    103 
    104         // mark us as parent
    105         state->setParent(this);
    10690    }
    10791
     
    11397        GameState by instance pointer
    11498    */
    115     void GameStateBase::removeChild(GameStateBase* state)
     99    void GameState::removeChild(GameState* state)
    116100    {
    117         std::map<GameStateBase*, GameStateBase*>::iterator it = this->grandchildrenToChildren_.find(state);
    118         if (it != this->grandchildrenToChildren_.end())
    119         {
    120             if (state->isInSubtree(getCurrentState()))
    121             {
    122                 ThrowException(GameState, "Cannot remove an active game state child '"
    123                     + state->getName() + "' from '" + name_ + "'.");
    124                 //COUT(2) << "Warning: Cannot remove an active game state child '" << state->getName()
    125                 //    << "' from '" << name_ << "'." << std::endl;
    126             }
    127             else
    128             {
    129                 for (std::map<GameStateBase*, GameStateBase*>::const_iterator it = state->grandchildrenToChildren_.begin();
    130                     it != state->grandchildrenToChildren_.end(); ++it)
    131                     this->grandchildRemoved(it->first);
    132                 this->grandchildRemoved(state);
    133             }
    134         }
     101        assert(state != NULL);
     102
     103        std::map<std::string, GameState*>::iterator it = this->children_.find(state->getName());
     104        if (it != this->children_.end())
     105            this->children_.erase(it);
    135106        else
    136107        {
    137108            ThrowException(GameState, "Game state '" + name_ + "' doesn't have a child named '"
    138109                + state->getName() + "'.");
    139             //COUT(2) << "Warning: Game state '" << name_ << "' doesn't have a child named '"
    140             //    << state->getName() << "'. Removal skipped." << std::endl;
    141110        }
    142111    }
    143112
    144     /**
    145     @brief
    146         Removes a child by name. This splits the tree in two parts,
    147         each of them functional on its own.
    148     @param state
    149         GameState by name
    150     */
    151 
    152     void GameStateBase::removeChild(const std::string& name)
     113    void GameState::activateInternal()
    153114    {
    154         GameStateBase* state = getState(name);
    155         if (state)
    156         {
    157             removeChild(state);
    158         }
    159         else
    160         {
    161             ThrowException(GameState, "GameState '" + name + "' doesn't exist.");
    162             //COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
    163         }
     115        this->activity_.activating = true;
     116        this->activate();
     117        this->activity_.activating = false;
     118        this->activity_.active = true;
    164119    }
    165120
    166     /**
    167     @brief
    168         Tells a state that one of its children has added a child. This is necessary
    169         to fill the internal maps correctly.
    170     @param child
    171         The child who notices this state.
    172     @param grandchild
    173         The child that has been added.
    174     */
    175     inline void GameStateBase::grandchildAdded(GameStateBase* child, GameStateBase* grandchild)
     121    void GameState::deactivateInternal()
    176122    {
    177         // fill the two maps correctly.
    178         this->allChildren_[grandchild->getName()] = grandchild;
    179         this->grandchildrenToChildren_[grandchild] = child;
    180         if (this->getParent())
    181             this->getParent()->grandchildAdded(this, grandchild);
     123        this->activity_.active = false;
     124        this->activity_.deactivating = true;
     125        this->activate();
     126        this->activity_.deactivating = false;
     127        this->activity_.suspended = false;
     128        this->activity_.updating = false;
    182129    }
    183130
    184     /**
    185     @brief
    186         Tells a state that one of its children has removed a child. This is necessary
    187         to fill the internal maps correctly.
    188     @param child
    189         The child who notices this state.
    190     @param grandchild
    191         The child that has been removed.
    192     */
    193     inline void GameStateBase::grandchildRemoved(GameStateBase* grandchild)
     131    void GameState::updateInternal(const Clock& time)
    194132    {
    195         // adjust the two maps correctly.
    196         this->allChildren_.erase(grandchild->getName());
    197         this->grandchildrenToChildren_.erase(grandchild);
    198         if (this->getParent())
    199             this->getParent()->grandchildRemoved(grandchild);
    200     }
    201 
    202     /**
    203     @brief
    204         Checks whether a specific game states exists in the hierarchy.
    205     @remarks
    206         Remember that the every node has a map with all its child nodes.
    207     */
    208     GameStateBase* GameStateBase::getState(const std::string& name)
    209     {
    210         if (this->getParent())
    211             return this->getParent()->getState(name);
    212         else
    213         {
    214             // The map only contains children, so check ourself first
    215             if (name == this->name_)
    216                 return this;
    217             // Search in the map. If there is no entry, we can be sure the state doesn't exist.
    218             std::map<std::string, GameStateBase*>::const_iterator it = this->allChildren_.find(name);
    219             return (it!= this->allChildren_.end() ? it->second : 0);
    220         }
    221     }
    222 
    223     /**
    224     @brief
    225         Returns the root node of the tree.
    226     */
    227     GameStateBase* GameStateBase::getRoot()
    228     {
    229         if (this->getParent())
    230             return this->getParent()->getRoot();
    231         else
    232             return this;
    233     }
    234 
    235     /**
    236     @brief
    237         Returns the current active state.
    238     @remarks
    239         Remember that the current active state is the one that does not
    240         have active children itself. Many states can be active at once.
    241     */
    242     GameStateBase* GameStateBase::getCurrentState()
    243     {
    244         if (this->operation_.active)
    245         {
    246             if (this->activeChild_)
    247                 return this->activeChild_->getCurrentState();
    248             else
    249                 return this;
    250         }
    251         else
    252         {
    253             if (this->getParent())
    254                 return this->getParent()->getCurrentState();
    255             else
    256                 return 0;
    257         }
    258     }
    259 
    260     /**
    261     @brief
    262         Determines whether 'state' is in this subtree, including this node.
    263     */
    264     bool GameStateBase::isInSubtree(GameStateBase* state) const
    265     {
    266         return (grandchildrenToChildren_.find(state) != grandchildrenToChildren_.end()
    267                 || state == this);
    268     }
    269 
    270     /**
    271     @brief
    272         Makes a state transition according to the state tree. You can choose any state
    273         in the tree to do the call. The function finds the current state on its own.
    274     @param state
    275         The state to be entered, has to exist in the tree.
    276     */
    277     void GameStateBase::requestState(const std::string& name)
    278     {
    279         assert(getRoot());
    280         getRoot()->requestState(name);
    281     }
    282 
    283     /**
    284     @brief
    285         Internal method that actually makes the state transition. Since it is internal,
    286         the method can assume certain things to be granted (like 'this' is always active).
    287     */
    288     void GameStateBase::makeTransition(GameStateBase* source, GameStateBase* destination)
    289     {
    290         if (source == this->getParent())
    291         {
    292             // call is from the parent
    293             this->activate();
    294         }
    295         else if (source == 0)
    296         {
    297             // call was just started by root
    298             // don't do anyting yet
    299         }
    300         else
    301         {
    302             // call is from a child
    303             this->activeChild_ = 0;
    304         }
    305 
    306         if (destination == this)
    307             return;
    308 
    309         // Check for 'destination' in the children map first
    310         std::map<GameStateBase*, GameStateBase*>::const_iterator it
    311             = this->grandchildrenToChildren_.find(destination);
    312         if (it != this->grandchildrenToChildren_.end())
    313         {
    314             // child state. Don't use 'state', might be a grandchild!
    315             this->activeChild_ = it->second;
    316             it->second->makeTransition(this, destination);
    317         }
    318         else
    319         {
    320             // parent. We can be sure of this.
    321             assert(this->getParent() != 0);
    322 
    323             this->deactivate();
    324             this->getParent()->makeTransition(this, destination);
    325         }
    326     }
    327 
    328     /**
    329     @brief
    330         Activates the state. Only sets bActive_ to true and notifies the parent.
    331     */
    332     void GameStateBase::activate()
    333     {
    334         this->operation_.active = true;
    335         this->operation_.entering = true;
    336         this->enter();
    337         this->operation_.entering = false;
    338     }
    339 
    340     /**
    341         Activates the state. Only sets bActive_ to false and notifies the parent.
    342     */
    343     void GameStateBase::deactivate()
    344     {
    345         this->operation_.leaving = true;
    346         this->leave();
    347         this->operation_.leaving = false;
    348         this->operation_.active = false;
    349     }
    350 
    351     /**
    352     @brief
    353         Update method that calls ticked() with enclosed bRunning_ = true
    354         If there was a state transition request within ticked() then this
    355         method will transition in the end.
    356     @param dt Delta time
    357     @note
    358         This method is not virtual! You cannot override it therefore.
    359     */
    360     void GameStateBase::tick(const Clock& time)
    361     {
    362         this->operation_.running = true;
    363         this->ticked(time);
    364         this->operation_.running = false;
     133        this->activity_.updating = true;
     134        this->update(time);
     135        this->activity_.updating = false;
    365136    }
    366137}
  • code/branches/questsystem5/src/core/GameState.h

    r1755 r2907  
    3939
    4040#include <string>
    41 #include <vector>
    4241#include <map>
    43 #include <cassert>
    44 #include "Clock.h"
     42#include "CorePrereqs.h"
    4543
    4644namespace orxonox
     
    6058        Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
    6159    */
    62     class _CoreExport GameStateBase
     60    class _CoreExport GameState
    6361    {
    64         friend class RootGameState;
    65         template <class ParentType>
    66         friend class GameState;
     62        friend class Game;
    6763
    6864    public:
     
    7167            Gives information about what the GameState is currently doing
    7268        */
    73         struct Operations
     69        struct State
    7470        {
    75             unsigned active    : 1;
    76             unsigned entering  : 1;
    77             unsigned leaving   : 1;
    78             unsigned running   : 1;
    79             unsigned suspended : 1;
     71            unsigned active       : 1;
     72            unsigned activating   : 1;
     73            unsigned deactivating : 1;
     74            unsigned updating     : 1;
     75            unsigned suspended    : 1;
     76            unsigned topState     : 1;
    8077        };
    8178
    8279    public:
    83         virtual ~GameStateBase();
     80        GameState(const std::string& name);
     81        virtual ~GameState();
    8482
    8583        const std::string& getName() const { return name_; }
    86         const Operations getOperation() const { return this->operation_; }
    87         bool isInSubtree(GameStateBase* state) const;
     84        State getActivity() const    { return this->activity_; }
     85        GameState* getParent() const       { return this->parent_; }
    8886
    89         GameStateBase* getState(const std::string& name);
    90         GameStateBase* getRoot();
    91         //! Returns the currently active game state
    92         virtual GameStateBase* getCurrentState();
    93 
    94         virtual void requestState(const std::string& name);
    95 
    96         void addChild(GameStateBase* state);
    97         void removeChild(GameStateBase* state);
    98         void removeChild(const std::string& name);
     87        void addChild(GameState* state);
     88        void removeChild(GameState* state);
    9989
    10090    protected:
    101         virtual void enter() = 0;
    102         virtual void leave() = 0;
    103         virtual void ticked(const Clock& time) = 0;
    104 
    105         GameStateBase* getActiveChild() { return this->activeChild_; }
    106 
    107         void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    108 
    109         virtual GameStateBase* getParent() const = 0;
    110         virtual void setParent(GameStateBase* state) = 0;
     91        virtual void activate() = 0;
     92        virtual void deactivate() = 0;
     93        virtual void update(const Clock& time) = 0;
    11194
    11295    private:
    113         // Making the constructor private ensures that game states
    114         // are always derivates of GameState<T>. Note the friend declaration above.
    115         GameStateBase(const std::string& name);
    116 
    117         //! Performs a transition to 'destination'
    118         virtual void makeTransition(GameStateBase* source, GameStateBase* destination);
    119 
    120         void grandchildAdded(GameStateBase* child, GameStateBase* grandchild);
    121         void grandchildRemoved(GameStateBase* grandchild);
    122 
    123         void tick(const Clock& time);
    124         void activate();
    125         void deactivate();
     96        void setParent(GameState* state) { this->parent_ = state; }
     97        void setActivity(State activity);
     98        void activateInternal();
     99        void deactivateInternal();
     100        void updateInternal(const Clock& time);
    126101
    127102        const std::string                        name_;
    128         Operations                               operation_;
    129         GameStateBase*                           activeChild_;
    130         //bool                                     bPauseParent_;
    131         std::map<std::string, GameStateBase*>    allChildren_;
    132         std::map<GameStateBase*, GameStateBase*> grandchildrenToChildren_;
    133     };
    134 
    135 
    136     template <class ParentType>
    137     class GameState : public GameStateBase
    138     {
    139     public:
    140         GameState(const std::string& name)
    141             : GameStateBase(name)
    142             , parent_(0)
    143         { }
    144         virtual ~GameState() { }
    145 
    146         ParentType* getParent() const
    147             { return parent_; }
    148 
    149     protected:
    150         void setParent(GameStateBase* state)
    151         {
    152             assert(dynamic_cast<ParentType*>(state) != 0);
    153             this->parent_ = dynamic_cast<ParentType*>(state);
    154         }
    155 
    156     private:
    157         ParentType* parent_;
     103        State                                    activity_;
     104        GameState*                               parent_;
     105        std::map<std::string, GameState*>        children_;
    158106    };
    159107}
  • code/branches/questsystem5/src/core/Identifier.h

    r2710 r2907  
    357357            static ClassIdentifier<T> *getIdentifier(const std::string& name);
    358358            void addObject(T* object);
    359             static bool isFirstCall();
    360359
    361360            void updateConfigValues(bool updateChildren = true) const;
    362361
    363362        private:
     363            static void initialiseIdentifier();
    364364            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    365365            ClassIdentifier()
     
    376376
    377377    template <class T>
    378     ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s;
    379 
    380     /**
    381         @brief Returns true if the function gets called the first time, false otherwise.
    382         @return True if this function got called the first time.
    383     */
    384     template <class T>
    385     bool ClassIdentifier<T>::isFirstCall()
    386     {
    387         static bool bFirstCall = true;
    388 
    389         if (bFirstCall)
     378    ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;
     379
     380    /**
     381        @brief Returns the only instance of this class.
     382        @return The unique Identifier
     383    */
     384    template <class T>
     385    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
     386    {
     387        // check if the static field has already been filled
     388        if (ClassIdentifier<T>::classIdentifier_s == 0)
     389            ClassIdentifier<T>::initialiseIdentifier();
     390
     391        return ClassIdentifier<T>::classIdentifier_s;
     392    }
     393
     394    /**
     395        @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
     396        @param name The name of this Identifier
     397        @return The Identifier
     398    */
     399    template <class T>
     400    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
     401    {
     402        ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
     403        identifier->setName(name);
     404        return identifier;
     405    }
     406
     407    /**
     408        @brief Assigns the static field for the identifier singleton.
     409    */
     410    template <class T>
     411    void ClassIdentifier<T>::initialiseIdentifier()
     412    {
     413        // Get the name of the class
     414        std::string name = typeid(T).name();
     415
     416        // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
     417        ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
     418
     419        // Get the entry from the map
     420        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
     421
     422        if (ClassIdentifier<T>::classIdentifier_s == proposal)
    390423        {
    391             bFirstCall = false;
    392             return true;
     424            COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
    393425        }
    394426        else
    395427        {
    396             return false;
     428            COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
    397429        }
    398     }
    399 
    400     /**
    401         @brief Returns the only instance of this class.
    402         @return The unique Identifier
    403     */
    404     template <class T>
    405     ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    406     {
    407         // check if the static field has already been filled
    408         if (ClassIdentifier<T>::isFirstCall())
    409         {
    410             // Get the name of the class
    411             std::string name = typeid(T).name();
    412 
    413             // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
    414             ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    415 
    416             // Get the entry from the map
    417             ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
    418 
    419             if (ClassIdentifier<T>::classIdentifier_s == proposal)
    420             {
    421                 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
    422             }
    423             else
    424             {
    425                 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
    426             }
    427         }
    428 
    429         // Finally return the unique ClassIdentifier
    430         return ClassIdentifier<T>::classIdentifier_s;
    431     }
    432 
    433     /**
    434         @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
    435         @param name The name of this Identifier
    436         @return The Identifier
    437     */
    438     template <class T>
    439     ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
    440     {
    441         ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
    442         identifier->setName(name);
    443         return identifier;
    444430    }
    445431
  • code/branches/questsystem5/src/core/Iterator.h

    r2662 r2907  
    7575                this->element_ = exp.element_;
    7676                this->list_ = exp.list_;
    77                 this->iterator_ = this->list_->registerIterator(this);
     77                this->list_->registerIterator(this);
    7878            }
    7979
     
    8686                this->element_ = other.element_;
    8787                this->list_ = other.list_;
    88                 this->iterator_ = this->list_->registerIterator(this);
     88                this->list_->registerIterator(this);
    8989            }
    9090
     
    9898                this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
    9999                this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    100                 this->iterator_ = this->list_->registerIterator(this);
     100                this->list_->registerIterator(this);
    101101            }
    102102
     
    110110                this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0;
    111111                this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    112                 this->iterator_ = this->list_->registerIterator(this);
     112                this->list_->registerIterator(this);
    113113            }
    114114
     
    118118            inline ~Iterator()
    119119            {
    120                 this->list_->unregisterIterator(this->iterator_);
     120                this->list_->unregisterIterator(this);
    121121            }
    122122
     
    128128            {
    129129                if (this->list_)
    130                     this->list_->unregisterIterator(this->iterator_);
     130                    this->list_->unregisterIterator(this);
    131131
    132132                this->element_ = exp.element_;
    133133                this->list_ = exp.list_;
    134                 this->iterator_ = this->list_->registerIterator(this);
     134                this->list_->registerIterator(this);
    135135
    136136                return (*this);
     
    144144            {
    145145                if (this->list_)
    146                     this->list_->unregisterIterator(this->iterator_);
     146                    this->list_->unregisterIterator(this);
    147147
    148148                this->element_ = other.element_;
    149149                this->list_ = other.list_;
    150                 this->iterator_ = this->list_->registerIterator(this);
     150                this->list_->registerIterator(this);
    151151
    152152                return (*this);
     
    161161            {
    162162                if (this->list_)
    163                     this->list_->unregisterIterator(this->iterator_);
     163                    this->list_->unregisterIterator(this);
    164164
    165165                this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
    166166                this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    167                 this->iterator_ = this->list_->registerIterator(this);
     167                this->list_->registerIterator(this);
    168168
    169169                return (*this);
     
    179179            {
    180180                if (this->list_)
    181                     this->list_->unregisterIterator(this->iterator_);
    182 
    183                 this->element_ = (other.element_) ? (ObjectListBaseElement*)other.element_ : 0;
     181                    this->list_->unregisterIterator(this);
     182
     183                this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0;
    184184                this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    185                 this->iterator_ = this->list_->registerIterator(this);
     185                this->list_->registerIterator(this);
    186186
    187187                return (*this);
     
    300300            ObjectListBaseElement* element_;       //!< The element the Iterator points at
    301301            ObjectListBase* list_;                 //!< The list wherein the element is
    302             std::list<void*>::iterator iterator_;  //!< The iterator in the notifying list of the ObjectList
    303302    };
    304303
  • code/branches/questsystem5/src/core/LuaBind.cc

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/questsystem5/src/core/LuaBind.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/questsystem5/src/core/ObjectListBase.cc

    r2171 r2907  
    7575    void ObjectListBase::notifyIterators(OrxonoxClass* object) const
    7676    {
    77         for (std::list<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
     77        for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
    7878            ((Iterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
    79         for (std::list<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it)
     79        for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it)
    8080            ((ObjectListIterator<OrxonoxClass>*)(*it))->incrementIfEqual(object);
    8181    }
  • code/branches/questsystem5/src/core/ObjectListBase.h

    r2171 r2907  
    3838#define _ObjectListBase_H__
    3939
    40 #include <list>
     40#include <vector>
    4141
    4242#include "CorePrereqs.h"
     
    7171    {
    7272        public:
    73             ObjectListElement(T* object) : ObjectListBaseElement((OrxonoxClass*)object), object_(object) {}
     73            ObjectListElement(T* object) : ObjectListBaseElement(static_cast<OrxonoxClass*>(object)), object_(object) {}
    7474            T* object_;              //!< The object
    7575    };
     
    110110            inline Export rend() { return ObjectListBase::Export(this, 0); }
    111111
    112             inline std::list<void*>::iterator registerIterator(void* iterator) { return this->iterators_.insert(this->iterators_.begin(), iterator); }
    113             inline void unregisterIterator(const std::list<void*>::iterator& iterator) { this->iterators_.erase(iterator); }
    114             inline std::list<void*>::iterator registerObjectListIterator(void* iterator) { return this->objectListIterators_.insert(this->objectListIterators_.begin(), iterator); }
    115             inline void unregisterObjectListIterator(const std::list<void*>::iterator& iterator) { this->objectListIterators_.erase(iterator); }
     112            inline void registerIterator(void* iterator) { this->iterators_.push_back(iterator); }
     113            inline void unregisterIterator(void* iterator)
     114            {
     115                for (unsigned int i = 0; i < this->iterators_.size(); ++i)
     116                {
     117                    if (iterators_[i] == iterator)
     118                    {
     119                        iterators_.erase(iterators_.begin() + i);
     120                        break;
     121                    }
     122                }
     123            }
     124            inline void registerObjectListIterator(void* iterator) { this->objectListIterators_.push_back(iterator); }
     125            inline void unregisterObjectListIterator(void* iterator)
     126            {
     127                for (unsigned int i = 0; i < this->objectListIterators_.size(); ++i)
     128                {
     129                    if (objectListIterators_[i] == iterator)
     130                    {
     131                        objectListIterators_.erase(objectListIterators_.begin() + i);
     132                        break;
     133                    }
     134                }
     135            }
    116136            void notifyIterators(OrxonoxClass* object) const;
    117137
     
    122142            ObjectListBaseElement* first_;         //!< The first element in the list
    123143            ObjectListBaseElement* last_;          //!< The last element in the list
    124             std::list<void*> iterators_;           //!< A list of Iterators pointing on an element in this list
    125             std::list<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list
     144            std::vector<void*> iterators_;           //!< A list of Iterators pointing on an element in this list
     145            std::vector<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list
    126146    };
    127147}
  • code/branches/questsystem5/src/core/ObjectListIterator.h

    r2662 r2907  
    6565            {
    6666                this->element_ = 0;
    67                 this->iterator_ = ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
     67                ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
    6868            }
    6969
     
    7575            {
    7676                this->element_ = element;
    77                 this->iterator_ = ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
     77                ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
    7878            }
    7979
     
    8585            {
    8686                this->element_ = other.element_;
    87                 this->iterator_ = ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
     87                ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this);
    8888            }
    8989
     
    9393            inline ~ObjectListIterator()
    9494            {
    95                 ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this->iterator_);
     95                ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this);
    9696            }
    9797
     
    227227        private:
    228228            ObjectListElement<T>* element_;        //!< The element the Iterator points at
    229             std::list<void*>::iterator iterator_;  //!< The iterator in the notifying list of the ObjectList
    230229    };
    231230}
  • code/branches/questsystem5/src/core/TclThreadManager.cc

    r1792 r2907  
    3535#include <OgreTimer.h>
    3636
     37#include "Clock.h"
    3738#include "CoreIncludes.h"
    3839#include "ConsoleCommand.h"
     
    598599    }
    599600
    600     void TclThreadManager::tick(float dt)
     601    void TclThreadManager::update(const Clock& time)
    601602    {
    602603        {
     
    633634            boost::try_mutex::scoped_lock interpreter_lock(this->orxonoxInterpreterBundle_.interpreterMutex_);
    634635#endif
    635             unsigned long maxtime = (unsigned long)(dt * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE);
     636            unsigned long maxtime = (unsigned long)(time.getDeltaTime() * 1000000 * TCLTHREADMANAGER_MAX_CPU_USAGE);
    636637            Ogre::Timer timer;
    637638            while (!this->queueIsEmpty())
  • code/branches/questsystem5/src/core/TclThreadManager.h

    r2710 r2907  
    9090            void debug(const std::string& error);
    9191
    92             virtual void tick(float dt);
     92            void update(const Clock& time);
    9393
    9494            std::list<unsigned int> getThreadList() const;
  • code/branches/questsystem5/src/core/Template.cc

    r2710 r2907  
    6565        if (element)
    6666        {
    67             TiXmlElement* tixmlelement = dynamic_cast<TiXmlElement*>(element->GetTiXmlPointer());
     67            TiXmlElement* tixmlelement = static_cast<TiXmlElement*>(element->GetTiXmlPointer());
    6868            if (tixmlelement)
    6969                this->setXMLElement(*tixmlelement);
     
    138138        COUT(4) << object->getLoaderIndentation() << " aplying Template \"" << this->getName() << "\"..." << std::endl;
    139139
    140         Element temp = ((TiXmlElement*)&this->getXMLElement());
     140        Element temp = &const_cast<TiXmlElement&>(this->getXMLElement());
    141141
    142142        if (this->bLoadDefaults_)
  • code/branches/questsystem5/src/core/Template.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/questsystem5/src/core/XMLFile.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/questsystem5/src/core/XMLIncludes.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/questsystem5/src/core/XMLPort.h

    r2710 r2907  
    556556                                                try
    557557                                                {
    558                                                     COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
     558                                                    COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
    559559
    560560                                                    BaseObject* newObject = identifier->fabricate((BaseObject*)object);
    561561                                                    assert(newObject);
    562                                                     newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + "  ");
     562                                                    newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
    563563
    564564                                                    O* castedObject = dynamic_cast<O*>(newObject);
     
    568568                                                    {
    569569                                                        newObject->XMLPort(*child, XMLPort::LoadObject);
    570                                                         COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
     570                                                        COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
    571571                                                    }
    572572                                                    else
    573573                                                    {
    574                                                         COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
     574                                                        COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl;
    575575                                                    }
    576576
    577                                                     COUT(5) << ((BaseObject*)object)->getLoaderIndentation();
     577                                                    COUT(5) << object->getLoaderIndentation();
    578578                                                    (*this->loadexecutor_)(object, castedObject);
    579579
     
    581581                                                        newObject->XMLPort(*child, XMLPort::LoadObject);
    582582
    583                                                     COUT(5) << ((BaseObject*)object)->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
     583                                                    COUT(5) << object->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
    584584                                                }
    585585                                                catch (AbortLoadingException& ex)
     
    601601                                        else
    602602                                        {
    603                                             COUT(2) << ((BaseObject*)object)->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl;
     603                                            COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl;
    604604                                        }
    605605                                    }
    606606                                    else
    607607                                    {
    608                                         COUT(2) << ((BaseObject*)object)->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a '" << Class(O)->getName() << "'." << std::endl;
     608                                        COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a '" << Class(O)->getName() << "'." << std::endl;
    609609                                    }
    610610                                }
     
    626626                    {
    627627                        COUT(1) << std::endl;
    628                         COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << ((BaseObject*)object)->getName() << ") in " << object->getFilename() << ":" << std::endl;
     628                        COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << object->getName() << ") in " << object->getFilename() << ":" << std::endl;
    629629                        COUT(1) << ex.what() << std::endl;
    630630                    }
  • code/branches/questsystem5/src/core/input/CalibratorCallback.h

    r1755 r2907  
    5252        void keyHeld    (const KeyEvent& evt) { }
    5353
    54         void tickInput(float dt) { }
     54        void updateInput(float dt) { }
    5555    };
    5656}
  • code/branches/questsystem5/src/core/input/ExtendedInputState.cc

    r2773 r2907  
    402402    }
    403403
    404     void ExtendedInputState::tickInput(float dt)
     404    void ExtendedInputState::updateInput(float dt)
    405405    {
    406406        for (unsigned int i = 0; i < allHandlers_.size(); ++i)
    407407        {
    408             allHandlers_[i]->tickInput(dt);
    409         }
    410     }
    411 
    412     void ExtendedInputState::tickInput(float dt, unsigned int device)
     408            allHandlers_[i]->updateInput(dt);
     409        }
     410    }
     411
     412    void ExtendedInputState::updateInput(float dt, unsigned int device)
    413413    {
    414414        switch (device)
     
    416416        case Keyboard:
    417417            for (unsigned int i = 0; i < keyHandlers_.size(); ++i)
    418                 keyHandlers_[i]->tickKey(dt);
     418                keyHandlers_[i]->updateKey(dt);
    419419            break;
    420420
    421421        case Mouse:
    422422            for (unsigned int i = 0; i < mouseHandlers_.size(); ++i)
    423                 mouseHandlers_[i]->tickMouse(dt);
     423                mouseHandlers_[i]->updateMouse(dt);
    424424            break;
    425425
    426426        default: // joy sticks
    427427            for (unsigned int i = 0; i < joyStickHandlers_[device - 2].size(); ++i)
    428                 joyStickHandlers_[device - 2][i]->tickJoyStick(dt, device - 2);
     428                joyStickHandlers_[device - 2][i]->updateJoyStick(dt, device - 2);
    429429            break;
    430430        }
  • code/branches/questsystem5/src/core/input/ExtendedInputState.h

    r1887 r2907  
    6868        ~ExtendedInputState() { }
    6969
    70         void tickInput(float dt);
    71         void tickInput(float dt, unsigned int device);
     70        void updateInput(float dt);
     71        void updateInput(float dt, unsigned int device);
    7272
    7373        void keyPressed (const KeyEvent& evt);
  • code/branches/questsystem5/src/core/input/InputBuffer.cc

    r2662 r2907  
    224224
    225225    /**
    226         @brief This tick() function is called by the InputManager if the InputBuffer is active.
     226        @brief This update() function is called by the InputManager if the InputBuffer is active.
    227227        @param dt Delta time
    228228    */
    229     void InputBuffer::tickInput(float dt)
     229    void InputBuffer::updateInput(float dt)
    230230    {
    231231        timeSinceKeyPressed_ += dt;
  • code/branches/questsystem5/src/core/input/InputBuffer.h

    r2662 r2907  
    127127                for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
    128128                {
    129                     InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it);
     129                    InputBufferListenerTuple<T>* refListener = static_cast<InputBufferListenerTuple<T>*>(*it);
    130130                    if (refListener && refListener->listener_ == listener)
    131131                        this->listeners_.erase(it++);
     
    171171            void processKey (const KeyEvent &e);
    172172
    173             void tickInput(float dt);
    174             void tickKey(float dt) { }
     173            void updateInput(float dt);
     174            void updateKey(float dt) { }
    175175
    176176            std::string buffer_;
  • code/branches/questsystem5/src/core/input/InputInterfaces.h

    r2662 r2907  
    474474    public:
    475475        virtual ~InputHandler() { }
    476         virtual void tickInput(float dt) = 0;
     476        virtual void updateInput(float dt) = 0;
    477477    };
    478478
     
    488488        virtual void keyReleased(const KeyEvent& evt) = 0;
    489489        virtual void keyHeld    (const KeyEvent& evt) = 0;
    490         virtual void tickKey    (float dt) = 0;
     490        virtual void updateKey    (float dt) = 0;
    491491    };
    492492
     
    504504        virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    505505        virtual void mouseScrolled      (int abs, int rel)     = 0;
    506         virtual void tickMouse          (float dt) = 0;
     506        virtual void updateMouse          (float dt) = 0;
    507507    };
    508508
     
    520520        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0;
    521521        virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    522         virtual void tickJoyStick          (float dt, unsigned int joyStick) = 0;
     522        virtual void updateJoyStick          (float dt, unsigned int joyStick) = 0;
    523523    };
    524524
     
    531531        virtual ~EmptyHandler() { }
    532532
    533         void tickInput(float dt) { }
    534         void tickJoyStick(float dt, unsigned int joyStick) { }
    535         void tickMouse(float dt) { }
    536         void tickKey(float dt) { }
     533        void updateInput(float dt) { }
     534        void updateJoyStick(float dt, unsigned int joyStick) { }
     535        void updateMouse(float dt) { }
     536        void updateKey(float dt) { }
    537537
    538538        void keyPressed (const KeyEvent& evt) { }
  • code/branches/questsystem5/src/core/input/InputManager.cc

    r2662 r2907  
    4343
    4444#include "util/Exception.h"
     45#include "core/Clock.h"
    4546#include "core/CoreIncludes.h"
    4647#include "core/ConfigValueIncludes.h"
     
    108109        , internalState_(Uninitialised)
    109110        , stateEmpty_(0)
    110         , stateMaster_(0)
    111111        , keyDetector_(0)
    112112        , calibratorCallbackBuffer_(0)
     
    173173            //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
    174174            //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
    175 #if defined OIS_LINUX_PLATFORM
     175#if defined ORXONOX_PLATFORM_LINUX
    176176            paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    177177            paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true"));
     
    218218
    219219            // Lowest priority empty InputState
    220             stateEmpty_ = createInputState<SimpleInputState>("empty", -1);
     220            stateEmpty_ = createInputState<SimpleInputState>("empty", false, false, InputStatePriority::Empty);
    221221            stateEmpty_->setHandler(&EMPTY_HANDLER);
    222222            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
    223223
    224             // Always active master InputState
    225             stateMaster_ = new ExtendedInputState();
    226             stateMaster_->setName("master");
    227             stateMaster_->setNumOfJoySticks(joySticksSize_);
    228 
    229224            // KeyDetector to evaluate a pressed key's name
    230             SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101);
     225            SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector);
    231226            keyDetector_ = new KeyDetector();
    232227            detector->setHandler(keyDetector_);
    233228
    234229            // Joy stick calibration helper callback
    235             SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", 100);
     230            SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator);
    236231            calibrator->setHandler(&EMPTY_HANDLER);
    237232            calibratorCallbackBuffer_ = new InputBuffer();
     
    424419
    425420        // state management
    426         activeStatesTop_.resize(devicesNum_);
     421        activeStatesTriggered_.resize(devicesNum_);
    427422
    428423        // inform all states
    429         for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
    430             it != inputStatesByPriority_.end(); ++it)
     424        for (std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.begin();
     425            it != inputStatesByName_.end(); ++it)
    431426        {
    432427            it->second->setNumOfJoySticks(joySticksSize_);
    433428        }
    434         // inform master state
    435         if (stateMaster_)
    436             this->stateMaster_->setNumOfJoySticks(joySticksSize_);
    437429
    438430        // inform all JoyStick Device Number Listeners
     
    454446        }
    455447    }
    456    
     448
    457449    void InputManager::_startCalibration()
    458450    {
     
    549541                // destroy the empty InputState
    550542                _destroyState(this->stateEmpty_);
    551                 // destroy the master input state. This might trigger a memory leak
    552                 // because the user has forgotten to destroy the KeyBinder or any Handler!
    553                 delete stateMaster_;
    554543
    555544                // destroy all user InputStates
    556                 while (inputStatesByPriority_.size() > 0)
    557                     _destroyState((*inputStatesByPriority_.rbegin()).second);
     545                while (inputStatesByName_.size() > 0)
     546                    _destroyState((*inputStatesByName_.rbegin()).second);
    558547
    559548                // destroy the devices
     
    639628            _updateActiveStates();
    640629        }
    641         inputStatesByPriority_.erase(state->getPriority());
    642630        inputStatesByName_.erase(state->getName());
    643631        delete state;
     
    670658    @brief
    671659        Public interface. Only reloads immediately if the call stack doesn't
    672         include the tick() method.
     660        include the update() method.
    673661    @param joyStickSupport
    674662        Whether or not to initialise joy sticks as well.
     
    742730    @brief
    743731        Updates the states and the InputState situation.
    744     @param dt
    745         Delta time
    746     */
    747     void InputManager::tick(float dt)
     732    @param time
     733        Clock holding the current time.
     734    */
     735    void InputManager::update(const Clock& time)
    748736    {
    749737        if (internalState_ == Uninitialised)
     
    759747        if (!stateLeaveRequests_.empty())
    760748        {
    761             for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin();
    762                 rit != stateLeaveRequests_.rend(); ++rit)
    763             {
    764                 (*rit)->onLeave();
     749            for (std::set<InputState*>::iterator it = stateLeaveRequests_.begin();
     750                it != stateLeaveRequests_.end(); ++it)
     751            {
     752                (*it)->onLeave();
    765753                // just to be sure that the state actually is registered
    766                 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    767 
    768                 activeStates_.erase((*rit)->getPriority());
     754                assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     755
     756                activeStates_.erase((*it)->getPriority());
     757                if ((*it)->getPriority() < InputStatePriority::HighPriority)
     758                    (*it)->setPriority(0);
    769759                _updateActiveStates();
    770760            }
     
    775765        if (!stateEnterRequests_.empty())
    776766        {
    777             for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin();
    778                 rit != stateEnterRequests_.rend(); ++rit)
     767            for (std::set<InputState*>::const_iterator it = stateEnterRequests_.begin();
     768                it != stateEnterRequests_.end(); ++it)
    779769            {
    780770                // just to be sure that the state actually is registered
    781                 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    782 
    783                 activeStates_[(*rit)->getPriority()] = (*rit);
     771                assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     772
     773                if ((*it)->getPriority() == 0)
     774                {
     775                    // Get smallest possible priority between 1 and maxStateStackSize_s
     776#if defined( __MINGW32__ ) // Avoid the strange mingw-stl bug with const_reverse_iterator
     777                    for(std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
     778                        rit != activeStates_.rend(); ++rit)
     779#else
     780                    for(std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin();
     781                        rit != activeStates_.rend(); ++rit)
     782#endif
     783                    {
     784                        if (rit->first < InputStatePriority::HighPriority)
     785                        {
     786                            (*it)->setPriority(rit->first + 1);
     787                            break;
     788                        }
     789                    }
     790                    // In case no normal handler was on the stack
     791                    if ((*it)->getPriority() == 0)
     792                        (*it)->setPriority(1);
     793                }
     794                activeStates_[(*it)->getPriority()] = (*it);
    784795                _updateActiveStates();
    785                 (*rit)->onEnter();
     796                (*it)->onEnter();
    786797            }
    787798            stateEnterRequests_.clear();
     
    791802        if (!stateDestroyRequests_.empty())
    792803        {
    793             for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin();
    794                 rit != stateDestroyRequests_.rend(); ++rit)
    795             {
    796                 _destroyState((*rit));
     804            for (std::set<InputState*>::iterator it = stateDestroyRequests_.begin();
     805                it != stateDestroyRequests_.end(); ++it)
     806            {
     807                _destroyState((*it));
    797808            }
    798809            stateDestroyRequests_.clear();
     
    812823            _updateActiveStates();
    813824
    814         // mark that we capture and distribute input
     825        // mark that we now start capturing and distributing input
    815826        internalState_ |= Ticking;
    816827
     
    829840            {
    830841                KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_);
    831                 activeStatesTop_[Keyboard]->keyHeld(kEvt);
    832                 stateMaster_->keyHeld(kEvt);
     842
     843                for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     844                    activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt);
    833845            }
    834846
     
    836848            for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    837849            {
    838                 activeStatesTop_[Mouse]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    839                 stateMaster_->mouseButtonHeld(mouseButtonsDown_[iButton]);
     850                for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     851                    activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    840852            }
    841853
     
    844856                for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    845857                {
    846                     activeStatesTop_[JoyStick0 + iJoyStick]
    847                         ->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    848                     stateMaster_->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     858                    for (unsigned int iState = 0; iState < activeStatesTriggered_[JoyStick0 + iJoyStick].size(); ++iState)
     859                        activeStatesTriggered_[JoyStick0 + iJoyStick][iState]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    849860                }
    850861
    851             // tick the handlers for each active handler
     862            // update the handlers for each active handler
    852863            for (unsigned int i = 0; i < devicesNum_; ++i)
    853864            {
    854                 activeStatesTop_[i]->tickInput(dt, i);
    855                 if (stateMaster_->isInputDeviceEnabled(i))
    856                     stateMaster_->tickInput(dt, i);
    857             }
    858 
    859             // tick the handler with a general tick afterwards
     865                for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
     866                    activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i);
     867            }
     868
     869            // update the handler with a general tick afterwards
    860870            for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i)
    861                 activeStatesTicked_[i]->tickInput(dt);
    862             stateMaster_->tickInput(dt);
     871                activeStatesTicked_[i]->updateInput(time.getDeltaTime());
    863872        }
    864873
     
    869878    @brief
    870879        Updates the currently active states (according to activeStates_) for each device.
    871         Also, a list of all active states (no duplicates!) is compiled for the general tick.
     880        Also, a list of all active states (no duplicates!) is compiled for the general update().
    872881    */
    873882    void InputManager::_updateActiveStates()
    874883    {
    875         for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
    876             for (unsigned int i = 0; i < devicesNum_; ++i)
    877                 if (it->second->isInputDeviceEnabled(i))
    878                     activeStatesTop_[i] = it->second;
     884        for (unsigned int i = 0; i < devicesNum_; ++i)
     885        {
     886            bool occupied = false;
     887            activeStatesTriggered_[i].clear();
     888#if defined( __MINGW32__ ) // Avoid the strange mingw-stl bug with const_reverse_iterator
     889            for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
     890            {
     891#else
     892            for (std::map<int, InputState*>::const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)
     893            {
     894#endif
     895                if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_))
     896                {
     897                    activeStatesTriggered_[i].push_back(rit->second);
     898                    if (!rit->second->bTransparent_)
     899                        occupied = true;
     900                }
     901            }
     902        }
    879903
    880904        // update tickables (every state will only appear once)
     
    882906        std::set<InputState*> tempSet;
    883907        for (unsigned int i = 0; i < devicesNum_; ++i)
    884             tempSet.insert(activeStatesTop_[i]);
    885 
    886         // copy the content of the set back to the actual vector
     908            for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)
     909                tempSet.insert(activeStatesTriggered_[i][iState]);
     910
     911        // copy the content of the std::set back to the actual vector
    887912        activeStatesTicked_.clear();
    888913        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
     
    942967
    943968        KeyEvent kEvt(e, keyboardModifiers_);
    944         activeStatesTop_[Keyboard]->keyPressed(kEvt);
    945         stateMaster_->keyPressed(kEvt);
     969        for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     970            activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt);
    946971
    947972        return true;
     
    9751000
    9761001        KeyEvent kEvt(e, keyboardModifiers_);
    977         activeStatesTop_[Keyboard]->keyReleased(kEvt);
    978         stateMaster_->keyReleased(kEvt);
     1002        for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState)
     1003            activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt);
    9791004
    9801005        return true;
     
    9981023            IntVector2 rel(e.state.X.rel, e.state.Y.rel);
    9991024            IntVector2 clippingSize(e.state.width, e.state.height);
    1000             activeStatesTop_[Mouse]->mouseMoved(abs, rel, clippingSize);
    1001             stateMaster_->mouseMoved(abs, rel, clippingSize);
     1025            for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1026                activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize);
    10021027        }
    10031028
     
    10051030        if (e.state.Z.rel != 0)
    10061031        {
    1007             activeStatesTop_[Mouse]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    1008             stateMaster_->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
     1032            for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1033                activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    10091034        }
    10101035
     
    10291054            mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id);
    10301055
    1031         activeStatesTop_[Mouse]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    1032         stateMaster_->mouseButtonPressed((MouseButtonCode::ByEnum)id);
     1056        for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1057            activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id);
    10331058
    10341059        return true;
     
    10551080        }
    10561081
    1057         activeStatesTop_[Mouse]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    1058         stateMaster_->mouseButtonReleased((MouseButtonCode::ByEnum)id);
     1082        for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState)
     1083            activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id);
    10591084
    10601085        return true;
     
    10921117            buttonsDown.push_back((JoyStickButtonCode::ByEnum)button);
    10931118
    1094         activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    1095         stateMaster_->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1119        for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1120            activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonPressed(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    10961121
    10971122        return true;
     
    11131138        }
    11141139
    1115         activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    1116         stateMaster_->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
     1140        for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1141            activeStatesTriggered_[2 + iJoyStick][iState]->joyStickButtonReleased(iJoyStick, (JoyStickButtonCode::ByEnum)button);
    11171142
    11181143        return true;
     
    11411166                fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis];
    11421167
    1143             activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue);
    1144             stateMaster_->joyStickAxisMoved(iJoyStick, axis, fValue);
     1168            for (unsigned int iState = 0; iState < activeStatesTriggered_[2 + iJoyStick].size(); ++iState)
     1169                activeStatesTriggered_[2 + iJoyStick][iState]->joyStickAxisMoved(iJoyStick, axis, fValue);
    11451170        }
    11461171    }
     
    12451270        Unique name of the handler.
    12461271    @param priority
    1247         Unique integer number. Higher means more prioritised.
     1272        Determines which InputState gets the input. Higher is better.
     1273        Use 0 to handle it implicitely by the order of activation.
     1274        Otherwise numbers larger than maxStateStackSize_s have to be used!
    12481275    @return
    12491276        True if added, false if name or priority already existed.
    12501277    */
    1251     bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority)
     1278    bool InputManager::_configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority)
    12521279    {
    12531280        if (name == "")
     
    12571284        if (inputStatesByName_.find(name) == inputStatesByName_.end())
    12581285        {
    1259             if (inputStatesByPriority_.find(priority)
    1260                 == inputStatesByPriority_.end())
    1261             {
    1262                 inputStatesByName_[name] = state;
    1263                 inputStatesByPriority_[priority] = state;
    1264                 state->setNumOfJoySticks(numberOfJoySticks());
    1265                 state->setName(name);
     1286            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
     1287            {
     1288                // Make sure we don't add two high priority states with the same priority
     1289                for (std::map<std::string, InputState*>::const_iterator it = this->inputStatesByName_.begin();
     1290                    it != this->inputStatesByName_.end(); ++it)
     1291                {
     1292                    if (it->second->getPriority() == priority)
     1293                    {
     1294                        COUT(2) << "Warning: Could not add an InputState with the same priority '"
     1295                            << priority << "' != 0." << std::endl;
     1296                        return false;
     1297                    }
     1298                }
     1299            }
     1300            inputStatesByName_[name] = state;
     1301            state->setNumOfJoySticks(numberOfJoySticks());
     1302            state->setName(name);
     1303            state->bAlwaysGetsInput_ = bAlwaysGetsInput;
     1304            state->bTransparent_ = bTransparent;
     1305            if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
    12661306                state->setPriority(priority);
    1267                 return true;
    1268             }
    1269             else
    1270             {
    1271                 COUT(2) << "Warning: Could not add an InputState with the same priority '"
    1272                     << priority << "'." << std::endl;
    1273                 return false;
    1274             }
     1307            return true;
    12751308        }
    12761309        else
     
    12901323    @remarks
    12911324        You can't remove the internal states "empty", "calibrator" and "detector".
    1292         The removal process is being postponed if InputManager::tick() is currently running.
     1325        The removal process is being postponed if InputManager::update() is currently running.
    12931326    */
    12941327    bool InputManager::requestDestroyState(const std::string& name)
     
    13711404                {
    13721405                    // not scheduled for destruction
    1373                     // set prevents a state being added multiple times
     1406                    // prevents a state being added multiple times
    13741407                    stateEnterRequests_.insert(it->second);
    13751408                    return true;
     
    13901423    bool InputManager::requestLeaveState(const std::string& name)
    13911424    {
     1425        if (name == "empty")
     1426        {
     1427            COUT(2) << "InputManager: Leaving the empty state is not allowed!" << std::endl;
     1428            return false;
     1429        }
    13921430        // get pointer from the map with all stored handlers
    13931431        std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name);
  • code/branches/questsystem5/src/core/input/InputManager.h

    r2662 r2907  
    4343#include <stack>
    4444#include "util/Math.h"
     45#include "util/OrxEnum.h"
    4546#include "core/OrxonoxClass.h"
    4647#include "InputInterfaces.h"
     
    7475        float positiveCoeff[24];
    7576        float negativeCoeff[24];
     77    };
     78
     79    struct InputStatePriority : OrxEnum<InputStatePriority>
     80    {
     81        OrxEnumConstructors(InputStatePriority);
     82
     83        static const int Empty        = -1;
     84        static const int Dynamic      = 0;
     85
     86        static const int HighPriority = 1000;
     87        static const int Console      = HighPriority + 0;
     88        static const int Calibrator   = HighPriority + 1;
     89        static const int Detector     = HighPriority + 2;
    7690    };
    7791
     
    116130
    117131        template <class T>
    118         T* createInputState(const std::string& name, int priority);
     132        T* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
    119133
    120134        InputState* getState       (const std::string& name);
    121135        InputState* getCurrentState();
    122         ExtendedInputState* getMasterInputState() { return this->stateMaster_; }
    123136        bool requestDestroyState   (const std::string& name);
    124137        bool requestEnterState     (const std::string& name);
    125138        bool requestLeaveState     (const std::string& name);
    126139
    127         void tick(float dt);
     140        void update(const Clock& time);
    128141
    129142        static InputManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
     
    165178
    166179        void _updateActiveStates();
    167         bool _configureInputState(InputState* state, const std::string& name, int priority);
     180        bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);
    168181
    169182        // input events
     
    197210        // some internally handled states and handlers
    198211        SimpleInputState*                   stateEmpty_;
    199         ExtendedInputState*                 stateMaster_;          //!< Always active master input state
    200212        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    201213        InputBuffer*                        calibratorCallbackBuffer_;
    202214
    203215        std::map<std::string, InputState*>  inputStatesByName_;
    204         std::map<int, InputState*>          inputStatesByPriority_;
    205216
    206217        std::set<InputState*>               stateEnterRequests_;   //!< Request to enter a new state
     
    209220
    210221        std::map<int, InputState*>          activeStates_;
    211         std::vector<InputState*>            activeStatesTop_;      //!< Current input states for joy stick events.
    212         std::vector<InputState*>            activeStatesTicked_;   //!< Current input states for joy stick events.
     222        std::vector<std::vector<InputState*> > activeStatesTriggered_;
     223        std::vector<InputState*>            activeStatesTicked_;
    213224
    214225        // joystick calibration
     
    249260    */
    250261    template <class T>
    251     T* InputManager::createInputState(const std::string& name, int priority)
     262    T* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
    252263    {
    253264        T* state = new T;
    254         if (_configureInputState(state, name, priority))
     265        if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority))
    255266            return state;
    256267        else
  • code/branches/questsystem5/src/core/input/InputState.h

    r1887 r2907  
    7171        virtual void unRegisterOnLeave()                      { executorOnLeave_ = 0; }
    7272
    73         virtual void tickInput(float dt, unsigned int device) = 0;
    74         virtual void tickInput(float dt) = 0;
     73        virtual void updateInput(float dt, unsigned int device) = 0;
     74        virtual void updateInput(float dt) = 0;
    7575
    7676        virtual void keyPressed (const KeyEvent& evt) = 0;
     
    9090
    9191    protected:
    92         InputState() : bHandlersChanged_(false), priority_(0), executorOnEnter_(0), executorOnLeave_(0) { }
     92        InputState()
     93            : bHandlersChanged_(false)
     94            , priority_(0)
     95            , bAlwaysGetsInput_(false)
     96            , bTransparent_(false)
     97            , executorOnEnter_(0)
     98            , executorOnLeave_(0)
     99        { }
    93100        virtual ~InputState() { }
    94101
     
    114121        int                                         priority_;
    115122        std::vector<bool>                           bInputDeviceEnabled_;
     123        bool                                        bAlwaysGetsInput_;
     124        bool                                        bTransparent_;
    116125
    117126        Executor*                                   executorOnEnter_;
  • code/branches/questsystem5/src/core/input/KeyBinder.cc

    r2713 r2907  
    4242#include "core/CoreIncludes.h"
    4343#include "core/ConfigFileManager.h"
    44 #include "core/Core.h"
    4544#include "InputCommands.h"
    4645#include "InputManager.h"
     
    309308    }
    310309
    311     void KeyBinder::tickMouse(float dt)
     310    void KeyBinder::updateMouse(float dt)
    312311    {
    313312        if (bDeriveMouseInput_)
     
    349348            // Why dividing relative value by dt? The reason lies in the simple fact, that when you
    350349            // press a button that has relative movement, that value has to be multiplied by dt to be
    351             // frame rate independent. This can easily (and only) be done in tickInput(float).
     350            // frame rate independent. This can easily (and only) be done in updateInput(float).
    352351            // Hence we need to divide by dt here for the mouse to compensate, because the relative
    353352            // move movements have nothing to do with dt.
     
    362361    }
    363362
    364     void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
     363    void KeyBinder::updateJoyStick(float dt, unsigned int joyStick)
    365364    {
    366365        for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
  • code/branches/questsystem5/src/core/input/KeyBinder.h

    r2710 r2907  
    6868
    6969    protected: // functions
    70         void tickInput(float dt);
    71         void tickKey(float dt) { }
    72         void tickMouse(float dt);
    73         void tickJoyStick(float dt, unsigned int joyStick);
     70        void updateInput(float dt);
     71        void updateKey(float dt) { }
     72        void updateMouse(float dt);
     73        void updateJoyStick(float dt, unsigned int joyStick);
    7474        // internal
    7575        void tickHalfAxis(HalfAxis& halfAxis);
     
    134134        @brief
    135135            Commands that have additional parameters (axes) are executed at the end of
    136             the tick() so that all values can be buffered for single execution.
     136            update() so that all values can be buffered for single execution.
    137137        */
    138138        std::vector<BufferedParamCommand*> paramCommandBuffer_;
     
    200200    { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); }
    201201
    202     inline void KeyBinder::tickInput(float dt)
     202    inline void KeyBinder::updateInput(float dt)
    203203    {
    204204        // execute all buffered bindings (additional parameter)
  • code/branches/questsystem5/src/core/input/SimpleInputState.h

    r1887 r2907  
    5959        ~SimpleInputState() { }
    6060
    61         void tickInput(float dt);
    62         void tickInput(float dt, unsigned int device);
     61        void updateInput(float dt);
     62        void updateInput(float dt, unsigned int device);
    6363
    6464        void keyPressed (const KeyEvent& evt);
     
    8787    };
    8888
    89     inline void SimpleInputState::tickInput(float dt)
     89    inline void SimpleInputState::updateInput(float dt)
    9090    {
    9191        for (unsigned int i = 0; i < allHandlers_.size(); ++i)
    9292        {
    93             allHandlers_[i]->tickInput(dt);
     93            allHandlers_[i]->updateInput(dt);
    9494        }
    9595    }
    9696
    97     inline void SimpleInputState::tickInput(float dt, unsigned int device)
     97    inline void SimpleInputState::updateInput(float dt, unsigned int device)
    9898    {
    9999        switch (device)
     
    101101        case InputDevice::Keyboard:
    102102            if (keyHandler_)
    103                 keyHandler_->tickKey(dt);
     103                keyHandler_->updateKey(dt);
    104104            break;
    105105
    106106        case InputDevice::Mouse:
    107107            if (mouseHandler_)
    108                 mouseHandler_->tickMouse(dt);
     108                mouseHandler_->updateMouse(dt);
    109109            break;
    110110
    111111        default: // joy sticks
    112112            if (joyStickHandler_[device - 2])
    113                 joyStickHandler_[device - 2]->tickJoyStick(dt, device - 2);
     113                joyStickHandler_[device - 2]->updateJoyStick(dt, device - 2);
    114114            break;
    115115        }
Note: See TracChangeset for help on using the changeset viewer.