Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1502 for code/trunk


Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (16 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
Location:
code/trunk
Files:
5 deleted
131 edited
31 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/CMakeLists.txt

    r1293 r1502  
    4545SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O0 -Wall -g -ggdb")
    4646SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
     47#SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O3")
     48#SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O3")
     49
    4750SET(CMAKE_LD_FLAGS "$ENV{LDFLAGS}")
    4851SET(CMAKE_EXE_LINKER_FLAGS " --no-undefined")
     
    6568FIND_PACKAGE(ENet)
    6669FIND_PACKAGE(Boost REQUIRED thread)
     70FIND_PACKAGE(Boost REQUIRED filesystem)
    6771FIND_PACKAGE(OpenAL)
    6872FIND_PACKAGE(ALUT)
     
    7175FIND_PACKAGE(Lua)
    7276FIND_PACKAGE(TCL)
     77FIND_PACKAGE(DirectX)
    7378
    7479#Set the search paths for the linking
     
    96101  ${Lua_INCLUDE_DIR}
    97102  ${TCL_INCLUDE_PATH}
     103  ${DirectX_INCLUDE_DIR}
     104  ${ZLIB_INCLUDE_DIR}
    98105)
    99106
  • code/trunk/TODO

    r1293 r1502  
    1 very urgent: make sure receiver thread of connectionmanager is
    2 threadsafe (event_type_receive, findclient)
     1- should we use enet_peer_ping to test if a client is still alive ?
     2- enet_host_broadcast ? (to all peers)
     3- enet_host_check_events ? instead of enet_host_service
  • code/trunk/bin/disco.txt

    r1069 r1502  
    22delay 0.2 Ambient setAmbientLightTest 0,1,0,1
    33delay 0.4 Ambient setAmbientLightTest 0,0,1,1
    4 delay 0.6 exec disco.txt
     4delay 0.6 source disco.txt
  • code/trunk/bin/levels/sample.oxw

    r1407 r1502  
    99  </audio-->
    1010
    11 <!--Ambient colourvalue="1,1,1" /-->
    12 <Skybox src="Orxonox/StarSkyBox" />
     11<Ambient colourvalue="0.1, 0.1, 0.1" />
     12<Skybox src="Orxonox/Starbox" />
    1313<SpaceShip camera="true" position="0,0,0" scale="10" yawpitchroll="0,0,0" mesh="assff.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
    14 <Model position="1500,0,100" scale="10" mesh="tomato.mesh" yawpitchroll="-40,30,0" rotationAxis="1,0,0" rotationRate="-30"/>
    15 <Model position="0,4200,0" scale="10" mesh="tomato.mesh" yawpitchroll="-50,60,0" rotationAxis="1,0,0" rotationRate="-30"/>
    16 <Model position="0,0,6800" scale="10" mesh="tomato.mesh" yawpitchroll="-50,-30,0" rotationAxis="1,0,0" rotationRate="-30"/>
     14<Model position="2000,0,0" scale="10" mesh="tomato.mesh" yawpitchroll="-40,30,0" rotationAxis="1,0,0" rotationRate="-30"/>
     15<Model position="0,2000,0" scale="10" mesh="tomato.mesh" yawpitchroll="-50,60,0" rotationAxis="1,0,0" rotationRate="-30"/>
     16<Model position="0,0,2000" scale="10" mesh="tomato.mesh" yawpitchroll="-50,-30,0" rotationAxis="1,0,0" rotationRate="-30"/>
     17<Model position="10000,16000,0" scale="100" mesh="DuBall1.mesh"/>
     18<Model position="11400,16000,0" scale="60" mesh="DuBall2.mesh"/>
    1719<NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
    1820<NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
  • code/trunk/bin/run-script

    r1293 r1502  
    88fi
    99
    10 if [[ ! -f orge.cfg ]] ; then
     10if [[ -ne orge.cfg ]] ; then
    1111        cp ogre.cfg-init ogre.cfg
    1212fi
  • code/trunk/cmake/FindBoost.cmake

    r1293 r1502  
    102102SET(SUFFIX_FOR_PATH
    103103 boost
     104 boost-1_35_0
     105 boost-1_35
    104106 boost-1_34_1
    105107 boost-1_34_0
     
    113115#
    114116IF(WIN32)
    115   SET(Boost_INCLUDE_DIR ../libs/boost_1_33_1)
     117  SET(Boost_INCLUDE_DIR
     118#    ../libs/boost_1_33_1
     119    ../libs/boost_1_34_1
     120#    ../libs/boost_1_35_0
     121  )
    116122ELSE(WIN32)
    117123  FIND_PATH(Boost_INCLUDE_DIR NAMES boost/config.hpp PATH_SUFFIXES ${SUFFIX_FOR_PATH} PATHS
     
    188194  gcc-1_33_1
    189195  gcc-mt-1_33_1
     196  mgw34-mt-1_34_1
     197  mgw34-mt-1_35
    190198)
    191199
  • code/trunk/cmake/FindZLIB.cmake

    r790 r1502  
    5858  ENDIF(EXISTS "../libs/ogre/Dependencies/lib/Release")
    5959
     60  FIND_PATH(ZLIB_INCLUDE_DIR zlib.h
     61    ../libs/ogre/Dependencies/include
     62  )
     63
    6064  FIND_LIBRARY(ZLIB_LIBRARY
    6165    NAMES zlib
     
    6367  )
    6468
    65   IF(ZLIB_LIBRARY)
     69  IF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR)
    6670    MESSAGE(STATUS "Zlib was found.")
    67   ELSE(ZLIB_LIBRARY)
     71  ELSE(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR)
    6872    MESSAGE(FATAL_ERROR "Zlib was NOT found.")
    69   ENDIF(ZLIB_LIBRARY)
     73  ENDIF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR)
    7074ENDIF(WIN32)
  • code/trunk/src/audio/AudioPrereqs.h

    r1069 r1502  
    3535#define _AudioPrereqs_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939//-----------------------------------------------------------------------
  • code/trunk/src/audio/AudioStream.cc

    r1064 r1502  
    117117
    118118            for(int i = 0; i < vorbisComment->comments; i++)
     119            {
    119120                COUT(3) << "   " << vorbisComment->user_comments[i] << std::endl;
     121            }
    120122
    121123            COUT(3) << std::endl;
  • code/trunk/src/core/CMakeLists.txt

    r1224 r1502  
    22  BaseObject.cc
    33  ClassTreeMask.cc
    4   CommandExecutor.cc
    54  ConfigFileManager.cc
    65  ConfigValueContainer.cc
     
    1110  Identifier.cc
    1211  IdentifierDistributor.cc
     12  InputManager.cc
     13  KeyBinder.cc
     14  OutputBuffer.cc
    1315  InputBuffer.cc
    14   InputHandler.cc
    15   InputManager.cc
     16  Shell.cc
     17  CommandExecutor.cc
     18  CommandEvaluation.cc
     19  ConsoleCommand.cc
     20  ArgumentCompletionFunctions.cc
     21  ConsoleCommandCompilation.cc
    1622  Language.cc
    1723  Loader.cc
     
    2632  Tickable.cc
    2733  XMLPort.cc
     34  TclThreadManager.cc
     35  IRC.cc
    2836  tolua/tolua_bind.cc
    2937)
     
    4755  ois
    4856  util
     57  ${Boost_thread_LIBRARIES}
     58  ${Boost_filesystem_LIBRARIES}
    4959)
  • code/trunk/src/core/ClassManager.h

    r1062 r1502  
    4949#include "Identifier.h"
    5050#include "IdentifierDistributor.h"
     51#include "Debug.h"
    5152
    5253namespace orxonox
  • code/trunk/src/core/CommandExecutor.cc

    r1349 r1502  
    3131#include "util/String.h"
    3232#include "util/Convert.h"
    33 #include "util/SubString.h"
    3433#include "Identifier.h"
    3534#include "Language.h"
    3635#include "Debug.h"
    37 #include "Executor.h"
    38 #include "ConfigValueContainer.h"
    3936#include "TclBind.h"
    40 
    41 #define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set"
    42 #define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY "tset"
    43 #define COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND "bind"
    4437
    4538namespace orxonox
    4639{
    47     ConsoleCommandShortcutGeneric(keyword1, createExecutor((FunctorStatic*)0, "set", AccessLevel::User));
    48     ConsoleCommandShortcutGeneric(keyword2, createExecutor((FunctorStatic*)0, "tset", AccessLevel::User));
    49     ConsoleCommandShortcutGeneric(keyword3, createExecutor((FunctorStatic*)0, "bind", AccessLevel::User));
    50 
    51     ConsoleCommandShortcutExtern(exec, AccessLevel::None);
    52     ConsoleCommandShortcutExtern(echo, AccessLevel::None);
    53 
    54     ConsoleCommandShortcutExtern(read, AccessLevel::None);
    55     ConsoleCommandShortcutExtern(append, AccessLevel::None);
    56     ConsoleCommandShortcutExtern(write, AccessLevel::None);
    57 
    58     void exec(const std::string& filename)
    59     {
    60         static std::set<std::string> executingFiles;
    61 
    62         std::set<std::string>::const_iterator it = executingFiles.find(filename);
    63         if (it != executingFiles.end())
    64         {
    65             COUT(1) << "Error: Recurring exec command in \"" << filename << "\". Stopped execution." << std::endl;
    66             return;
    67         }
    68 
    69         // Open the file
    70         std::ifstream file;
    71         file.open(filename.c_str(), std::fstream::in);
    72 
    73         if (!file.is_open())
    74         {
    75             COUT(1) << "Error: Couldn't execute file \"" << filename << "\"." << std::endl;
    76             return;
    77         }
    78 
    79         executingFiles.insert(filename);
    80 
    81         // Iterate through the file and put the lines into the CommandExecutor
    82         char line[1024];
    83         while (file.good() && !file.eof())
    84         {
    85             file.getline(line, 1024);
    86             CommandExecutor::execute(line);
    87         }
    88 
    89         executingFiles.erase(filename);
    90         file.close();
    91     }
    92 
    93     std::string echo(const std::string& text)
    94     {
    95         return text;
    96     }
    97 
    98     void write(const std::string& filename, const std::string& text)
    99     {
    100         std::ofstream file;
    101         file.open(filename.c_str(), std::fstream::out);
    102 
    103         if (!file.is_open())
    104         {
    105             COUT(1) << "Error: Couldn't write to file \"" << filename << "\"." << std::endl;
    106             return;
    107         }
    108 
    109         file << text << std::endl;
    110         file.close();
    111     }
    112 
    113     void append(const std::string& filename, const std::string& text)
    114     {
    115         std::ofstream file;
    116         file.open(filename.c_str(), std::fstream::app);
    117 
    118         if (!file.is_open())
    119         {
    120             COUT(1) << "Error: Couldn't append to file \"" << filename << "\"." << std::endl;
    121             return;
    122         }
    123 
    124         file << text << std::endl;
    125         file.close();
    126     }
    127 
    128     std::string read(const std::string& filename)
    129     {
    130         std::ifstream file;
    131         file.open(filename.c_str(), std::fstream::in);
    132 
    133         if (!file.is_open())
    134         {
    135             COUT(1) << "Error: Couldn't read from file \"" << filename << "\"." << std::endl;
    136             return "";
    137         }
    138 
    139         std::string output = "";
    140         char line[1024];
    141         while (file.good() && !file.eof())
    142         {
    143             file.getline(line, 1024);
    144             output += line;
    145             output += "\n";
    146         }
    147 
    148         file.close();
    149 
    150         return output;
    151     }
    152 
    153 
    154     ///////////////////////
    155     // CommandEvaluation //
    156     ///////////////////////
    157     CommandEvaluation::CommandEvaluation()
    158     {
    159         this->processedCommand_ = "";
    160         this->additionalParameter_ = "";
    161 
    162         this->functionclass_ = 0;
    163         this->configvalueclass_ = 0;
    164         this->shortcut_ = 0;
    165         this->function_ = 0;
    166         this->configvalue_ = 0;
    167         this->key_ = 0;
    168 
    169         this->errorMessage_ = "";
    170         this->state_ = CS_Uninitialized;
    171 
    172         this->bEvaluatedParams_ = false;
    173         this->evaluatedExecutor_ = 0;
    174     }
    175 
    176     KeybindMode::Enum CommandEvaluation::getKeybindMode()
    177     {
    178         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    179         {
    180 //            if (this->shortcut_ != 0)
    181 //                return this->shortcut_->getKeybindMode();
    182         }
    183         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    184         {
    185 //            if (this->function_ != 0)
    186 //                return this->function_->getKeybindMode();
    187         }
    188         else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
    189         {
    190 //            return KeybindMode::onPress;
    191         }
    192         else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
    193         {
    194 //            return KeybindMode::onPress;
    195         }
    196         else
    197         {
    198 //            return KeybindMode::onPress;
    199         }
    200         // FIXME: Had to insert a return statement
    201         return (KeybindMode::Enum)0;
    202     }
    203 
    204     bool CommandEvaluation::isValid() const
    205     {
    206         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    207         {
    208             return this->shortcut_;
    209         }
    210         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    211         {
    212             return (this->functionclass_ && this->function_);
    213         }
    214         else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
    215         {
    216             return (this->configvalueclass_ && this->configvalue_);
    217         }
    218         else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
    219         {
    220             return this->key_;
    221         }
    222         else
    223         {
    224             return false;
    225         }
    226     }
    227 
    228     void CommandEvaluation::evaluateParams()
    229     {
    230         this->bEvaluatedParams_ = false;
    231         this->evaluatedExecutor_ = 0;
    232 
    233         for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++)
    234             this->param_[i] = MT_null;
    235 
    236         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    237         {
    238             if (this->shortcut_)
    239             {
    240                 if (this->tokens_.size() <= 1)
    241                 {
    242                     if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " "))
    243                     {
    244                         this->bEvaluatedParams_ = true;
    245                         this->evaluatedExecutor_ = this->shortcut_;
    246                     }
    247                 }
    248                 else if (this->tokens_.size() > 1)
    249                 {
    250                     if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " "))
    251                     {
    252                         this->bEvaluatedParams_ = true;
    253                         this->evaluatedExecutor_ = this->shortcut_;
    254                     }
    255                 }
    256             }
    257         }
    258         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    259         {
    260             if (this->function_)
    261             {
    262                 if (this->tokens_.size() <= 2)
    263                 {
    264                     if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))
    265                     {
    266                         this->bEvaluatedParams_ = true;
    267                         this->evaluatedExecutor_ = this->function_;
    268                     }
    269                 }
    270                 else if (this->tokens_.size() > 2)
    271                 {
    272                     if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " "))
    273                     {
    274                         this->bEvaluatedParams_ = true;
    275                         this->evaluatedExecutor_ = this->function_;
    276                     }
    277                 }
    278             }
    279         }
    280     }
    281 
    282     void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param)
    283     {
    284         if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
    285             this->param_[index] = param;
    286     }
    287 
    288     MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const
    289     {
    290         if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
    291             return this->param_[index];
    292 
    293         return MT_null;
    294     }
    295 
    296     bool CommandEvaluation::hasReturnvalue() const
    297     {
    298         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    299         {
    300             if (this->shortcut_)
    301                 return this->shortcut_->hasReturnvalue();
    302         }
    303         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    304         {
    305             if (this->function_)
    306                 return this->function_->hasReturnvalue();
    307         }
    308 
    309         return MT_null;
    310     }
    311 
    312     MultiTypeMath CommandEvaluation::getReturnvalue() const
    313     {
    314         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
    315         {
    316             if (this->shortcut_)
    317                 return this->shortcut_->getReturnvalue();
    318         }
    319         else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    320         {
    321             if (this->function_)
    322                 return this->function_->getReturnvalue();
    323         }
    324 
    325         return MT_null;
    326     }
    327 
    328 
    329     /////////////////////
    330     // CommandExecutor //
    331     /////////////////////
    33240    CommandExecutor& CommandExecutor::getInstance()
    33341    {
     
    34654    }
    34755
    348     Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
    349     {
    350         CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor;
    351         CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor;
    352         return (*executor);
     56    ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command)
     57    {
     58        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName());
     59        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
     60        {
     61            COUT(2) << "Warning: Overwriting console-command shortcut with name " << command->getName() << "." << std::endl;
     62        }
     63
     64
     65        CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
     66        CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(command->getName())] = command;
     67        return (*command);
    35368    }
    35469
     
    35873        @return The executor of the requested console command shortcut
    35974    */
    360     ExecutorStatic* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
    361     {
    362         std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
     75    ConsoleCommand* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
     76    {
     77        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
    36378        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
    36479            return (*it).second;
     
    37287        @return The executor of the requested console command shortcut
    37388    */
    374     ExecutorStatic* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
    375     {
    376         std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
     89    ConsoleCommand* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
     90    {
     91        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
    37792        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end())
    37893            return (*it).second;
     
    38499    {
    385100        if (useTcl)
    386         {
    387101            return TclBind::eval(command);
    388         }
    389         else
    390         {
    391             if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    392                 CommandExecutor::parse(command);
    393 
    394             return CommandExecutor::execute(CommandExecutor::getEvaluation());
    395         }
    396     }
    397 
    398 
    399     bool CommandExecutor::execute(const CommandEvaluation& evaluation)
    400     {
    401         SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    402 
    403         if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_)
    404         {
    405 std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl;
    406             (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]);
    407             return true;
    408         }
    409 
    410 std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n";
    411         switch (evaluation.state_)
    412         {
    413             case CS_Uninitialized:
    414                 break;
    415             case CS_Empty:
    416                 break;
    417             case CS_FunctionClass_Or_Shortcut_Or_Keyword:
    418                 break;
    419             case CS_Shortcut_Params:
    420                 // not enough parameters but lets hope there are some additional parameters and go on
    421             case CS_Shortcut_Finished:
    422                 // call the shortcut
    423                 if (evaluation.shortcut_)
    424                 {
    425                     if (tokens.size() >= 2)
    426                         return evaluation.shortcut_->parse(removeSlashes(tokens.subSet(1).join() + evaluation.getAdditionalParameter()));
    427                     else
    428                         return evaluation.shortcut_->parse(removeSlashes(evaluation.additionalParameter_));
    429                 }
    430                 break;
    431             case CS_Function:
    432                 break;
    433             case CS_Function_Params:
    434                 // not enough parameters but lets hope there are some additional parameters and go on
    435             case CS_Function_Finished:
    436                 // call the shortcut
    437                 if (evaluation.function_)
    438                 {
    439                     if (tokens.size() >= 3)
    440                         return evaluation.function_->parse(removeSlashes(tokens.subSet(2).join() + evaluation.getAdditionalParameter()));
    441                     else
    442                         return evaluation.function_->parse(removeSlashes(evaluation.additionalParameter_));
    443                 }
    444                 break;
    445             case CS_ConfigValueClass:
    446                 break;
    447             case CS_ConfigValue:
    448                 break;
    449             case CS_ConfigValueType:
    450                 // not enough parameters but lets hope there are some additional parameters and go on
    451             case CS_ConfigValueFinished:
    452                 // set the config value
    453                 if (evaluation.configvalue_)
    454                 {
    455                     if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE))
    456                     {
    457                         if (tokens.size() >= 4)
    458                             return evaluation.configvalue_->set(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter()));
    459                         else
    460                             return evaluation.configvalue_->set(removeSlashes(evaluation.additionalParameter_));
    461                     }
    462                     else if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
    463                     {
    464                         if (tokens.size() >= 4)
    465                             return evaluation.configvalue_->tset(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter()));
    466                         else
    467                             return evaluation.configvalue_->tset(removeSlashes(evaluation.additionalParameter_));
    468                     }
    469                 }
    470                 break;
    471             case CS_KeybindKey:
    472                 break;
    473             case CS_KeybindCommand:
    474                 // not enough parameters but lets hope there are some additional parameters and go on
    475             case CS_KeybindFinished:
    476                 // set the keybind
    477                 // ...todo
    478                 break;
    479             case CS_Error:
    480                 break;
    481         }
    482 
    483         return false;
     102
     103        CommandExecutor::parseIfNeeded(command);
     104        return CommandExecutor::getEvaluation().execute();
    484105    }
    485106
    486107    std::string CommandExecutor::complete(const std::string& command)
    487108    {
    488         if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    489             CommandExecutor::parse(command);
    490 
    491         return CommandExecutor::complete(CommandExecutor::getEvaluation());
    492     }
    493 
    494     std::string CommandExecutor::complete(const CommandEvaluation& evaluation)
    495     {
    496         SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    497 
    498         std::list<std::pair<const std::string*, const std::string*> > temp;
    499         if (evaluation.state_ == CS_Empty)
    500         {
    501             temp.insert(temp.end(), evaluation.listOfPossibleShortcuts_.begin(), evaluation.listOfPossibleShortcuts_.end());
    502             temp.insert(temp.end(), evaluation.listOfPossibleFunctionClasses_.begin(), evaluation.listOfPossibleFunctionClasses_.end());
    503         }
    504 
    505         switch (evaluation.state_)
    506         {
    507             case CS_Uninitialized:
    508                 break;
    509             case CS_Empty:
    510                 return (CommandExecutor::getCommonBegin(temp));
    511                 break;
    512             case CS_FunctionClass_Or_Shortcut_Or_Keyword:
    513                 break;
    514             case CS_Shortcut_Params:
    515                 if (evaluation.shortcut_)
    516                     return (evaluation.shortcut_->getName() + " ");
    517                 break;
    518             case CS_Shortcut_Finished:
    519                 if (evaluation.shortcut_)
    520                 {
    521                     if (evaluation.shortcut_->getParamCount() == 0)
    522                         return (evaluation.shortcut_->getName());
    523                     else if (tokens.size() >= 2)
    524                         return (evaluation.shortcut_->getName() + " " + tokens.subSet(1).join());
    525                 }
    526                 break;
    527             case CS_Function:
    528                 if (evaluation.functionclass_)
    529                     return (evaluation.functionclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_));
    530                 break;
    531             case CS_Function_Params:
    532                 if (evaluation.functionclass_ && evaluation.function_)
    533                     return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " ");
    534                 break;
    535             case CS_Function_Finished:
    536                 if (evaluation.functionclass_ && evaluation.function_)
    537                 {
    538                     if (evaluation.function_->getParamCount() == 0)
    539                         return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName());
    540                     else if (tokens.size() >= 3)
    541                         return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " " + tokens.subSet(2).join());
    542                 }
    543                 break;
    544             case CS_ConfigValueClass:
    545                 if (tokens.size() >= 1)
    546                     return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_));
    547                 break;
    548             case CS_ConfigValue:
    549                 if ((tokens.size() >= 1) && evaluation.configvalueclass_)
    550                     return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_));
    551                 break;
    552             case CS_ConfigValueType:
    553                 if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_)
    554                     return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " ");
    555                 break;
    556             case CS_ConfigValueFinished:
    557                 if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_ && (tokens.size() >= 4))
    558                     return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " " + tokens.subSet(3).join());
    559                 break;
    560             case CS_KeybindKey:
    561                 if (tokens.size() >= 1)
    562                     return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_));
    563                 break;
    564             case CS_KeybindCommand:
    565                 if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
    566                     return (evaluation.processedCommand_ + " ");
    567                 break;
    568             case CS_KeybindFinished:
    569                 break;
    570             case CS_Error:
    571                 break;
    572         }
    573 
    574         return evaluation.processedCommand_;
     109        CommandExecutor::parseIfNeeded(command);
     110        return CommandExecutor::getEvaluation().complete();
    575111    }
    576112
    577113    std::string CommandExecutor::hint(const std::string& command)
    578114    {
    579         if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    580             CommandExecutor::parse(command);
    581 
    582         return CommandExecutor::hint(CommandExecutor::getEvaluation());
    583     }
    584 
    585     std::string CommandExecutor::hint(const CommandEvaluation& evaluation)
    586     {
    587         SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    588 
    589         switch (evaluation.state_)
    590         {
    591             case CS_Uninitialized:
    592                 break;
    593             case CS_Empty:
    594                 return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_));
    595                 break;
    596             case CS_FunctionClass_Or_Shortcut_Or_Keyword:
    597                 break;
    598             case CS_Shortcut_Params:
    599                 if (evaluation.shortcut_)
    600                     return CommandExecutor::dump(evaluation.shortcut_);
    601                 break;
    602             case CS_Shortcut_Finished:
    603                 if (evaluation.shortcut_)
    604                     return CommandExecutor::dump(evaluation.shortcut_);
    605                 break;
    606             case CS_Function:
    607                 return CommandExecutor::dump(evaluation.listOfPossibleFunctions_);
    608                 break;
    609             case CS_Function_Params:
    610                 if (evaluation.function_)
    611                     return CommandExecutor::dump(evaluation.function_);
    612                 break;
    613             case CS_Function_Finished:
    614                 if (evaluation.function_)
    615                     return CommandExecutor::dump(evaluation.function_);
    616                 break;
    617             case CS_ConfigValueClass:
    618                 return CommandExecutor::dump(evaluation.listOfPossibleConfigValueClasses_);
    619                 break;
    620             case CS_ConfigValue:
    621                 return CommandExecutor::dump(evaluation.listOfPossibleConfigValues_);
    622                 break;
    623             case CS_ConfigValueType:
    624                 if (evaluation.configvalue_)
    625                     return CommandExecutor::dump(evaluation.configvalue_);
    626                 break;
    627             case CS_ConfigValueFinished:
    628                 if (evaluation.configvalue_)
    629                     return CommandExecutor::dump(evaluation.configvalue_);
    630                 break;
    631             case CS_KeybindKey:
    632                 return CommandExecutor::dump(evaluation.listOfPossibleKeys_);
    633                 break;
    634             case CS_KeybindCommand:
    635                 if (evaluation.key_)
    636                     return CommandExecutor::dump(evaluation.key_);
    637                 break;
    638             case CS_KeybindFinished:
    639                 if (evaluation.key_)
    640                     return CommandExecutor::dump(evaluation.key_);
    641                 break;
    642             case CS_Error:
    643                 return CommandExecutor::getEvaluation().errorMessage_;
    644                 break;
    645         }
    646 
    647         return "";
     115        CommandExecutor::parseIfNeeded(command);
     116        return CommandExecutor::getEvaluation().hint();
    648117    }
    649118
    650119    CommandEvaluation CommandExecutor::evaluate(const std::string& command)
    651120    {
    652         CommandExecutor::parse(command, true);
    653 
    654         if (CommandExecutor::getEvaluation().tokens_.size() > 0)
    655         {
    656             std::string lastToken;
    657             lastToken = CommandExecutor::getEvaluation().tokens_[CommandExecutor::getEvaluation().tokens_.size() - 1];
    658             lastToken = lastToken.substr(0, lastToken.size() - 1);
    659             CommandExecutor::getEvaluation().tokens_.pop_back();
    660             CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0'));
    661         }
    662 
     121        CommandExecutor::parse(command);
    663122        CommandExecutor::getEvaluation().evaluateParams();
    664123        return CommandExecutor::getEvaluation();
    665124    }
    666125
     126    void CommandExecutor::parseIfNeeded(const std::string& command)
     127    {
     128        if (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)
     129        {
     130            CommandExecutor::parse(command);
     131        }
     132        else if (CommandExecutor::getEvaluation().originalCommand_ != command)
     133        {
     134            if (CommandExecutor::getEvaluation().command_ == command)
     135            {
     136                CommandExecutor::parse(command);
     137                CommandExecutor::getEvaluation().bNewCommand_ = false;
     138            }
     139            else
     140            {
     141                CommandExecutor::parse(command);
     142            }
     143        }
     144    }
     145
    667146    void CommandExecutor::parse(const std::string& command, bool bInitialize)
    668147    {
    669         CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    670         CommandExecutor::getEvaluation().processedCommand_ = command;
    671 
    672148        if (bInitialize)
    673             CommandExecutor::initialize(command);
     149            CommandExecutor::getEvaluation().initialize(command);
     150
     151        CommandExecutor::getEvaluation().commandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
     152        CommandExecutor::getEvaluation().command_ = command;
    674153
    675154        switch (CommandExecutor::getEvaluation().state_)
    676155        {
    677156            case CS_Uninitialized:
     157            {
    678158                // Impossible
    679159                break;
     160            }
    680161            case CS_Empty:
     162            {
    681163                if (CommandExecutor::argumentsGiven() == 0)
    682164                {
    683                     // We want a hint for the first token
    684                     // Check if there is already a perfect match
    685                     CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
    686                     CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
    687 
    688                     if ((CommandExecutor::getEvaluation().functionclass_) || (CommandExecutor::getEvaluation().shortcut_))
    689                     {
    690                         // Yes, there is a class or a shortcut with the searched name
    691                         // Add a whitespace and continue parsing
    692                         CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
    693                         CommandExecutor::parse(command + " ", false);
     165                    CommandExecutor::createListOfPossibleFunctions("");
     166                    CommandExecutor::createListOfPossibleIdentifiers("");
     167                    break;
     168                }
     169                else
     170                {
     171                    CommandExecutor::getEvaluation().state_ = CS_ShortcutOrIdentifier;
     172                    // Move on to next case
     173                }
     174            }
     175            case CS_ShortcutOrIdentifier:
     176            {
     177                if (CommandExecutor::argumentsGiven() > 1)
     178                {
     179                    // There's a finished first argument - check if it's a shortcut or a classname
     180                    CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0));
     181                    CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0));
     182
     183                    if (CommandExecutor::getEvaluation().function_)
     184                    {
     185                        // It's a shortcut
     186                        CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     187                        CommandExecutor::getEvaluation().functionclass_ = 0;
     188                        // Move on to next case
     189                    }
     190                    else if (CommandExecutor::getEvaluation().functionclass_)
     191                    {
     192                        // It's a functionname
     193                        CommandExecutor::getEvaluation().state_ = CS_Function;
     194                        CommandExecutor::getEvaluation().function_ = 0;
     195                        // Move on to next case
     196                    }
     197                    else
     198                    {
     199                        // The first argument is bad
     200                        CommandExecutor::getEvaluation().state_ = CS_Error;
     201                        AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname");
     202                        CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + ".";
    694203                        return;
    695204                    }
    696 
    697                     // No perfect match: Create the lists of all possible classes and shortcuts and return
    698                     CommandExecutor::createListOfPossibleFunctionClasses(CommandExecutor::getToken(0));
    699                     CommandExecutor::createListOfPossibleShortcuts(CommandExecutor::getToken(0));
    700 
    701                     // Check if there's only one possiblility
    702                     if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 1) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 0))
    703                     {
    704                         // There's only one possible class
     205                }
     206                else
     207                {
     208                    // There's no finished first argument - search possible shortcuts or classnames
     209                    CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0));
     210                    CommandExecutor::createListOfPossibleIdentifiers(CommandExecutor::getArgument(0));
     211
     212                    unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size();
     213                    unsigned int num_identifiers = CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.size();
     214
     215                    if (num_functions == 1 && num_identifiers == 0)
     216                    {
     217                        // It's a shortcut
     218                        std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first;
     219                        CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname);
     220                        if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(0)))
     221                        {
     222                            // Unfinished shortcut
     223                            CommandExecutor::getEvaluation().bCommandChanged_ = true;
     224                        }
     225                        CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     226                        CommandExecutor::getEvaluation().functionclass_ = 0;
     227                        CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName();
     228                        if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
     229                        {
     230                            CommandExecutor::getEvaluation().command_ += " ";
     231                            CommandExecutor::getEvaluation().bCommandChanged_ = true;
     232                        }
     233                        // Move on to next case
     234                    }
     235                    else if (num_identifiers == 1 && num_functions == 0)
     236                    {
     237                        // It's a classname
     238                        std::string classname = *(*CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin()).first;
     239                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(classname);
     240                        if (getLowercase(classname) != getLowercase(CommandExecutor::getArgument(0)))
     241                        {
     242                            // Unfinished classname
     243                            CommandExecutor::getEvaluation().bCommandChanged_ = true;
     244                        }
    705245                        CommandExecutor::getEvaluation().state_ = CS_Function;
    706                         CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first);
    707                         CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first + " ", false);
     246                        CommandExecutor::getEvaluation().function_ = 0;
     247                        CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " ";
     248                        // Move on to next case
     249                    }
     250                    else if (num_identifiers == 0 && num_functions == 0)
     251                    {
     252                        // No possibilities
     253                        CommandExecutor::getEvaluation().state_ = CS_Error;
     254                        AddLanguageEntry("commandexecutorunknownfirstargumentstart", "There is no command or classname starting with");
     255                        CommandExecutor::getEvaluation().errorMessage_ = "Error: " + GetLocalisation("commandexecutorunknownfirstargumentstart") + " " + CommandExecutor::getArgument(0) + ".";
    708256                        return;
    709257                    }
    710                     else if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 0) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 1))
    711                     {
    712                         if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)
    713                          && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)
    714                          && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND))
    715                         {
    716                             // There's only one possible shortcut
    717                             CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params;
    718                             CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first);
    719                         }
    720                         else if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)
    721                               || (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
    722                         {
    723                             // It's the 'set' or 'tset' keyword
    724                             CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass;
    725                         }
    726                         else if (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)
    727                         {
    728                             // It's the 'bind' keyword
    729                             CommandExecutor::getEvaluation().state_ = CS_KeybindKey;
    730                         }
    731 
    732                         CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first + " ", false);
     258                    else
     259                    {
     260                        // There are several possiblilities
     261                        std::list<std::pair<const std::string*, const std::string*> > temp;
     262                        temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.end());
     263                        temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.end());
     264                        CommandExecutor::getEvaluation().command_ = CommandExecutor::getCommonBegin(temp);
     265                        CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0));
     266                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0));
     267                        CommandExecutor::getEvaluation().bCommandChanged_ = true;
    733268                        return;
    734269                    }
    735 
    736                     // It's ambiguous
     270                }
     271            }
     272            case CS_Function:
     273            {
     274                if (CommandExecutor::getEvaluation().functionclass_)
     275                {
     276                    // There is a classname - search for the commandname
     277                    if (CommandExecutor::argumentsGiven() > 2)
     278                    {
     279                        // There is a finished second argument - check if it's a commandname
     280                        CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_);
     281
     282                        if (CommandExecutor::getEvaluation().function_)
     283                        {
     284                            // It's a function
     285                            CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     286                            // Move on to next case
     287                        }
     288                        else
     289                        {
     290                            // The second argument is bad
     291                            CommandExecutor::getEvaluation().state_ = CS_Error;
     292                            AddLanguageEntry("commandexecutorunknownsecondargument", "is not a function of");
     293                            CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknownsecondargument") + " " + CommandExecutor::getEvaluation().functionclass_->getName() + ".";
     294                            return;
     295                        }
     296                    }
     297                    else
     298                    {
     299                        // There is no finished second argument - search for possibilities
     300                        CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_);
     301                        unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size();
     302
     303                        if (num_functions == 1)
     304                        {
     305                            // It's a function
     306                            std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first;
     307                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname, CommandExecutor::getEvaluation().functionclass_);
     308                            if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(1)))
     309                            {
     310                                // Unfinished function
     311                                CommandExecutor::getEvaluation().bCommandChanged_ = true;
     312                            }
     313                            CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     314                            CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getEvaluation().function_->getName();
     315                            if (CommandExecutor::getEvaluation().function_->getParamCount() > 0)
     316                            {
     317                                CommandExecutor::getEvaluation().command_ += " ";
     318                                CommandExecutor::getEvaluation().bCommandChanged_ = true;
     319                            }
     320                            // Move on to next case
     321                        }
     322                        else if (num_functions == 0)
     323                        {
     324                            // No possibilities
     325                            CommandExecutor::getEvaluation().state_ = CS_Error;
     326                            AddLanguageEntry("commandexecutorunknownsecondargumentstart", "has no function starting with");
     327                            CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getEvaluation().functionclass_->getName() + " " + GetLocalisation("commandexecutorunknownsecondargumentstart") + " " + CommandExecutor::getArgument(1) + ".";
     328                            return;
     329                        }
     330                        else
     331                        {
     332                            // There are several possibilities
     333                            CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleFunctions_);
     334                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_);
     335                            CommandExecutor::getEvaluation().bCommandChanged_ = true;
     336                            return;
     337                        }
     338                    }
     339                }
     340                else
     341                {
     342                    // There is no classname - move on to CS_ParamPreparation
     343                }
     344            }
     345            case CS_ParamPreparation:
     346            {
     347                if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))
     348                {
     349                    CommandExecutor::getEvaluation().state_ = CS_Finished;
    737350                    return;
    738351                }
    739352                else
    740353                {
    741                     // There is at least one argument: Check if it's a shortcut, a classname or a special keyword
    742                     CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
    743                     CommandExecutor::parse(command, false);
     354                    unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 2;
     355                    if (CommandExecutor::getEvaluation().functionclass_)
     356                        argumentNumber -= 1;
     357
     358                    CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber);
     359                    CommandExecutor::getEvaluation().state_ = CS_Params;
     360
     361                    if (CommandExecutor::getEvaluation().bCommandChanged_)
     362                    {
     363                        // Don't do more than one change
     364                        return;
     365                    }
     366                }
     367            }
     368            case CS_Params:
     369            {
     370                if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 1)
     371                {
     372                    // There is exactly one possible argument
     373                    CommandExecutor::getEvaluation().argument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString();
     374                    CommandExecutor::getEvaluation().possibleArgument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString();
     375                    CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
    744376                    return;
    745377                }
     378                else if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 0)
     379                {
     380                    // The user tries something new - we let him do
     381                    CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     382                    CommandExecutor::getEvaluation().argument_ = CommandExecutor::getLastArgument();
     383                    return;
     384                }
     385                else
     386                {
     387                    // There are several possibilities
     388                    unsigned int argumentNumber = CommandExecutor::argumentsGiven();
     389                    if (argumentNumber > 0)
     390                        --argumentNumber;
     391                    if (CommandExecutor::getEvaluation().functionclass_ && argumentNumber > 0)
     392                        --argumentNumber;
     393
     394                    CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_);
     395                    CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber);
     396                    CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
     397                    return;
     398                }
     399            }
     400            case CS_Finished:
     401            {
     402                // Nothing more to do
    746403                break;
    747             case CS_FunctionClass_Or_Shortcut_Or_Keyword:
    748                 if (CommandExecutor::argumentsGiven() >= 1)
    749                 {
    750                     if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
    751                     {
    752                         // We want to set a config value
    753                         CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass;
    754                         CommandExecutor::parse(command, false);
    755                         return;
    756                     }
    757                     else if (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)
    758                     {
    759                         // We want to set a keybinding
    760                         CommandExecutor::getEvaluation().state_ = CS_KeybindKey;
    761                         CommandExecutor::parse(command, false);
    762                         return;
    763                     }
    764 
    765                     if (!CommandExecutor::getEvaluation().functionclass_)
    766                         CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
    767                     if (!CommandExecutor::getEvaluation().shortcut_)
    768                         CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
    769 
    770                     if ((!CommandExecutor::getEvaluation().functionclass_) && (!CommandExecutor::getEvaluation().shortcut_))
    771                     {
    772                         // Argument 1 seems to be wrong
    773                         AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname");
    774                         CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName"));
    775                         CommandExecutor::getEvaluation().state_ = CS_Error;
    776                         return;
    777                     }
    778                     else if (CommandExecutor::getEvaluation().shortcut_)
    779                     {
    780                         // Argument 1 is a shortcut: Return the needed parameter types
    781                         CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params;
    782                         CommandExecutor::parse(command, false);
    783                         return;
    784                     }
    785                     else
    786                     {
    787                         // Argument 1 is a classname: Return the possible functions
    788                         CommandExecutor::getEvaluation().state_ = CS_Function;
    789                         CommandExecutor::parse(command, false);
    790                         return;
    791                     }
    792                 }
    793                 else
    794                 {
    795                     CommandExecutor::getEvaluation().state_ = CS_Error;
    796                     return;
    797                 }
     404            }
     405            case CS_Error:
     406            {
     407                // Bad, very bad
    798408                break;
    799             case CS_Shortcut_Params:
    800                 if (CommandExecutor::getEvaluation().shortcut_)
    801                 {
    802                     // Valid command
    803                     // Check if there are enough parameters
    804                     if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getEvaluation().shortcut_))
    805                     {
    806                         CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished;
    807                         return;
    808                     }
    809                 }
    810                 else
    811                 {
    812                     // Something is wrong
    813                     CommandExecutor::getEvaluation().state_ = CS_Error;
    814                     return;
    815                 }
    816                 break;
    817             case CS_Function:
    818                 if (CommandExecutor::getEvaluation().functionclass_)
    819                 {
    820                     // We have a valid classname
    821                     // Check if there is a second argument
    822                     if (CommandExecutor::argumentsGiven() >= 2)
    823                     {
    824                         // There is a second argument: Check if it's a valid functionname
    825                         CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
    826                         if (!CommandExecutor::getEvaluation().function_)
    827                         {
    828                             // Argument 2 seems to be wrong
    829                             AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in");
    830                             CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getEvaluation().functionclass_->getName());
    831                             CommandExecutor::getEvaluation().state_ = CS_Error;
    832                             return;
    833                         }
    834                         else
    835                         {
    836                             // Argument 2 seems to be a valid functionname: Get the parameters
    837                             CommandExecutor::getEvaluation().state_ = CS_Function_Params;
    838                             CommandExecutor::parse(command, false);
    839                             return;
    840                         }
    841                     }
    842                     else
    843                     {
    844                         // There is no finished second argument
    845                         // Check if there's already a perfect match
    846                         if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
    847                         {
    848                             CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
    849                             if (CommandExecutor::getEvaluation().function_)
    850                             {
    851                                 // There is a perfect match: Add a whitespace and continue parsing
    852                                 CommandExecutor::getEvaluation().state_ = CS_Function_Params;
    853                                 CommandExecutor::parse(command + " ", false);
    854                                 return;
    855                             }
    856                         }
    857 
    858                         // No perfect match: Create the list of all possible functions and return
    859                         CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
    860 
    861                         // Check if there's only one possiblility
    862                         if (CommandExecutor::getEvaluation().listOfPossibleFunctions_.size() == 1)
    863                         {
    864                             // There's only one possible function
    865                             CommandExecutor::getEvaluation().state_ = CS_Function_Params;
    866                             CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(*(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first, CommandExecutor::getEvaluation().functionclass_);
    867                             CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first + " ", false);
    868                             return;
    869                         }
    870 
    871                         // It's ambiguous
    872                         return;
    873                     }
    874                 }
    875                 else
    876                 {
    877                     CommandExecutor::getEvaluation().state_ = CS_Error;
    878                     return;
    879                 }
    880                 break;
    881             case CS_Function_Params:
    882                 if (CommandExecutor::getEvaluation().functionclass_ && CommandExecutor::getEvaluation().function_)
    883                 {
    884                     // Valid command
    885                     // Check if there are enough parameters
    886                     if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getEvaluation().function_))
    887                     {
    888                         CommandExecutor::getEvaluation().state_ = CS_Function_Finished;
    889                         return;
    890                     }
    891                 }
    892                 else
    893                 {
    894                     // Something is wrong
    895                     CommandExecutor::getEvaluation().state_ = CS_Error;
    896                     return;
    897                 }
    898                 break;
    899             case CS_ConfigValueClass:
    900                 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)))
    901                 {
    902                     // We want to set a config value
    903                     // Check if there is a second argument
    904                     if (CommandExecutor::argumentsGiven() >= 2)
    905                     {
    906                         // There is a second argument: Check if it's a valid classname
    907                         CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
    908                         if (!CommandExecutor::getEvaluation().configvalueclass_)
    909                         {
    910                             // Argument 2 seems to be wrong
    911                             AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values");
    912                             CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues"));
    913                             CommandExecutor::getEvaluation().state_ = CS_Error;
    914                             return;
    915                         }
    916                         else
    917                         {
    918                             // Argument 2 seems to be a valid classname: Search for possible config values
    919                             CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
    920                             CommandExecutor::parse(command, false);
    921                             return;
    922                         }
    923                     }
    924                     else
    925                     {
    926                         // There's no finished second argument
    927                         // Check if there's already a perfect match
    928                         if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
    929                         {
    930                             CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
    931                             if (CommandExecutor::getEvaluation().configvalueclass_)
    932                             {
    933                                 // There is a perfect match: Add a whitespace and continue parsing
    934                                 CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
    935                                 CommandExecutor::parse(command + " ", false);
    936                                 return;
    937                             }
    938                         }
    939 
    940                         // No perfect match: Create the list of all possible classnames and return
    941                         CommandExecutor::createListOfPossibleConfigValueClasses(CommandExecutor::getToken(1));
    942 
    943                         // Check if there's only one possiblility
    944                         if (CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.size() == 1)
    945                         {
    946                             // There's only one possible classname
    947                             CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
    948                             CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first);
    949                             CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first + " ", false);
    950                             return;
    951                         }
    952 
    953                         // It's ambiguous
    954                         return;
    955                     }
    956                 }
    957                 else
    958                 {
    959                     // Something is wrong
    960                     CommandExecutor::getEvaluation().state_ = CS_Error;
    961                     return;
    962                 }
    963                 break;
    964             case CS_ConfigValue:
    965                 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_))
    966                 {
    967                     // Check if there is a third argument
    968                     if (CommandExecutor::argumentsGiven() >= 3)
    969                     {
    970                         // There is a third argument: Check if it's a valid config value
    971                         CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
    972                         if (!CommandExecutor::getEvaluation().configvalue_)
    973                         {
    974                             // Argument 3 seems to be wrong
    975                             AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in");
    976                             CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getEvaluation().configvalueclass_->getName());
    977                             CommandExecutor::getEvaluation().state_ = CS_Error;
    978                             return;
    979                         }
    980                         else
    981                         {
    982                             // Argument 3 seems to be a valid config value: Get the type
    983                             CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
    984                             CommandExecutor::parse(command, false);
    985                             return;
    986                         }
    987                     }
    988                     else
    989                     {
    990                         // There is no finished third argument
    991                         // Check if there's already a perfect match
    992                         if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
    993                         {
    994                             CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
    995                             if (CommandExecutor::getEvaluation().configvalue_)
    996                             {
    997                                 // There is a perfect match: Add a whitespace and continue parsing
    998                                 CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
    999                                 CommandExecutor::parse(command + " ", false);
    1000                                 return;
    1001                             }
    1002                         }
    1003 
    1004                         // No perfect match: Create the list of all possible config values
    1005                         CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
    1006 
    1007                         // Check if there's only one possiblility
    1008                         if (CommandExecutor::getEvaluation().listOfPossibleConfigValues_.size() == 1)
    1009                         {
    1010                             // There's only one possible config value
    1011                             CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
    1012                             CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first, CommandExecutor::getEvaluation().configvalueclass_);
    1013                             CommandExecutor::parse(CommandExecutor::getToken(0) + " " + CommandExecutor::getToken(1) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first + " ", false);
    1014                             return;
    1015                         }
    1016 
    1017                         // It's ambiguous
    1018                         return;
    1019                     }
    1020                 }
    1021                 else
    1022                 {
    1023                     // Something is wrong
    1024                     CommandExecutor::getEvaluation().state_ = CS_Error;
    1025                     return;
    1026                 }
    1027                 break;
    1028             case CS_ConfigValueType:
    1029                 if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && CommandExecutor::getEvaluation().configvalueclass_ && CommandExecutor::getEvaluation().configvalue_)
    1030                 {
    1031                     // Valid command
    1032                     // Check if there are enough parameters
    1033                     if ((CommandExecutor::getEvaluation().tokens_.size() >= 4) && (CommandExecutor::getEvaluation().tokens_[3] != COMMAND_EXECUTOR_CURSOR))
    1034                     {
    1035                         CommandExecutor::getEvaluation().state_ = CS_ConfigValueFinished;
    1036                         return;
    1037                     }
    1038                 }
    1039                 else
    1040                 {
    1041                     // Something is wrong
    1042                     CommandExecutor::getEvaluation().state_ = CS_Error;
    1043                     return;
    1044                 }
    1045                 break;
    1046             case CS_KeybindKey:
    1047                 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND))
    1048                 {
    1049                     // todo
    1050                 }
    1051                 else
    1052                 {
    1053                     // Something is wrong
    1054                     CommandExecutor::getEvaluation().state_ = CS_Error;
    1055                     return;
    1056                 }
    1057                 break;
    1058             case CS_KeybindCommand:
    1059                 if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) && (false)) // todo
    1060                 {
    1061                     // Valid command
    1062                     // Check if there are enough parameters
    1063                     if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
    1064                     {
    1065                         CommandExecutor::getEvaluation().state_ = CS_KeybindFinished;
    1066                         return;
    1067                     }
    1068 
    1069                 }
    1070                 else
    1071                 {
    1072                     // Something is wrong
    1073                     CommandExecutor::getEvaluation().state_ = CS_Error;
    1074                     return;
    1075                 }
    1076                 break;
    1077             case CS_Shortcut_Finished:
    1078                 // Nothing to do
    1079                 break;
    1080             case CS_Function_Finished:
    1081                 // Nothing to do
    1082                 break;
    1083             case CS_ConfigValueFinished:
    1084                 // Nothing to do
    1085                 break;
    1086             case CS_KeybindFinished:
    1087                 // Nothing to do
    1088                 break;
    1089             case CS_Error:
    1090                 // This is bad
    1091                 break;
    1092         }
    1093     }
    1094 
    1095     void CommandExecutor::initialize(const std::string& command)
    1096     {
    1097         CommandExecutor::getEvaluation().processedCommand_ = command;
    1098         CommandExecutor::getEvaluation().additionalParameter_ = "";
    1099 
    1100         CommandExecutor::getEvaluation().bEvaluatedParams_ = false;
    1101         CommandExecutor::getEvaluation().evaluatedExecutor_ = 0;
    1102 
    1103         CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear();
    1104         CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
     409            }
     410        }
     411    }
     412
     413    unsigned int CommandExecutor::argumentsFinished()
     414    {
     415        unsigned int argumentsGiven = CommandExecutor::argumentsGiven();
     416        if (argumentsGiven > 0)
     417            return argumentsGiven - 1;
     418        else
     419            return 0;
     420    }
     421
     422    unsigned int CommandExecutor::argumentsGiven()
     423    {
     424        if (CommandExecutor::getEvaluation().command_.size() > 0 && CommandExecutor::getEvaluation().command_[CommandExecutor::getEvaluation().command_.size() - 1] == ' ')
     425            return CommandExecutor::getEvaluation().commandTokens_.size() + 1;
     426        else
     427            return CommandExecutor::getEvaluation().commandTokens_.size();
     428    }
     429
     430    bool CommandExecutor::enoughArgumentsGiven(ConsoleCommand* command)
     431    {
     432        if (CommandExecutor::getEvaluation().functionclass_)
     433            return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount()));
     434        else
     435            return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount()));
     436    }
     437
     438    std::string CommandExecutor::getArgument(unsigned int index)
     439    {
     440        if (index < (CommandExecutor::getEvaluation().commandTokens_.size()))
     441            return CommandExecutor::getEvaluation().commandTokens_[index];
     442        else
     443            return "";
     444    }
     445
     446    std::string CommandExecutor::getLastArgument()
     447    {
     448        return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() - 1);
     449    }
     450
     451    void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment)
     452    {
     453        CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear();
     454        std::string lowercase = getLowercase(fragment);
     455        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
     456            if ((*it).second->hasConsoleCommands())
     457                if ((*it).first.find(lowercase) == 0 || fragment == "")
     458                    CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
     459    }
     460
     461    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
     462    {
    1105463        CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear();
    1106         CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.clear();
    1107         CommandExecutor::getEvaluation().listOfPossibleConfigValues_.clear();
    1108         CommandExecutor::getEvaluation().listOfPossibleKeys_.clear();
    1109 
    1110         CommandExecutor::getEvaluation().functionclass_ = 0;
    1111         CommandExecutor::getEvaluation().configvalueclass_ = 0;
    1112         CommandExecutor::getEvaluation().shortcut_ = 0;
    1113         CommandExecutor::getEvaluation().function_ = 0;
    1114         CommandExecutor::getEvaluation().configvalue_ = 0;
    1115         CommandExecutor::getEvaluation().key_ = 0;
    1116 
    1117         CommandExecutor::getEvaluation().errorMessage_ = "";
    1118         CommandExecutor::getEvaluation().state_ = CS_Empty;
    1119     }
    1120 
    1121     bool CommandExecutor::argumentsGiven(unsigned int num)
    1122     {
    1123         // Because we added a cursor we have +1 arguments
    1124         // There are num arguments given if there are at least num arguments + one cursor
    1125         return (CommandExecutor::getEvaluation().tokens_.size() >= (num + 1));
    1126     }
    1127 
    1128     unsigned int CommandExecutor::argumentsGiven()
    1129     {
    1130         // Because we added a cursor we have +1 arguments
    1131         if (CommandExecutor::getEvaluation().tokens_.size() >= 1)
    1132             return (CommandExecutor::getEvaluation().tokens_.size() - 1);
    1133         else
    1134             return 0;
    1135     }
    1136 
    1137     std::string CommandExecutor::getToken(unsigned int index)
    1138     {
    1139         if ((index >= 0) && (index < (CommandExecutor::getEvaluation().tokens_.size() - 1)))
    1140             return CommandExecutor::getEvaluation().tokens_[index];
    1141         else if (index == (CommandExecutor::getEvaluation().tokens_.size() - 1))
    1142             return CommandExecutor::getEvaluation().tokens_[index].substr(0, CommandExecutor::getEvaluation().tokens_[index].size() - 1);
    1143         else
    1144             return "";
    1145     }
    1146 
    1147     bool CommandExecutor::enoughParametersGiven(unsigned int head, Executor* executor)
    1148     {
    1149         unsigned int neededParams = head + executor->getParamCount();
    1150         /*
    1151         for (unsigned int i = executor->getParamCount() - 1; i >= 0; i--)
    1152         {
    1153             if (executor->defaultValueSet(i))
    1154                 neededParams--;
     464        std::string lowercase = getLowercase(fragment);
     465        if (!identifier)
     466        {
     467            for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
     468                if ((*it).first.find(lowercase) == 0 || fragment == "")
     469                    CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
     470        }
     471        else
     472        {
     473            for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
     474                if ((*it).first.find(lowercase) == 0 || fragment == "")
     475                    CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
     476        }
     477    }
     478
     479    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
     480    {
     481        CommandExecutor::createArgumentCompletionList(command, param);
     482
     483        CommandExecutor::getEvaluation().listOfPossibleArguments_.clear();
     484        std::string lowercase = getLowercase(fragment);
     485        for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
     486        {
     487            if ((*it).lowercaseComparison())
     488            {
     489                if ((*it).getComparable().find(lowercase) == 0 || fragment == "")
     490                    CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it);
     491            }
    1155492            else
    1156                 break;
    1157         }
    1158         */
    1159         return ((CommandExecutor::getEvaluation().tokens_.size() >= neededParams) && (CommandExecutor::getEvaluation().tokens_[neededParams - 1] != COMMAND_EXECUTOR_CURSOR));
    1160     }
    1161 
    1162     void CommandExecutor::createListOfPossibleFunctionClasses(const std::string& fragment)
    1163     {
    1164         for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
    1165         {
    1166             if ((*it).second->hasConsoleCommands())
    1167             {
    1168                 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    1169                 {
    1170                     CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    1171                 }
    1172             }
    1173         }
    1174 
    1175         CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList);
    1176     }
    1177 
    1178     void CommandExecutor::createListOfPossibleShortcuts(const std::string& fragment)
    1179     {
    1180         for (std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
    1181         {
    1182             if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    1183             {
    1184                 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    1185             }
    1186         }
    1187 
    1188         CommandExecutor::getEvaluation().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList);
    1189     }
    1190 
    1191     void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
    1192     {
    1193         for (std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
    1194         {
    1195             if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    1196             {
    1197                 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    1198             }
    1199         }
    1200 
    1201         CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList);
    1202     }
    1203 
    1204     void CommandExecutor::createListOfPossibleConfigValueClasses(const std::string& fragment)
    1205     {
    1206         for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
    1207         {
    1208             if ((*it).second->hasConfigValues())
    1209             {
    1210                 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    1211                 {
    1212                     CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    1213                 }
    1214             }
    1215         }
    1216 
    1217         CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList);
    1218     }
    1219 
    1220     void CommandExecutor::createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier)
    1221     {
    1222         for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMapBegin(); it != identifier->getLowercaseConfigValueMapEnd(); ++it)
    1223         {
    1224             if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
    1225             {
    1226                 CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    1227             }
    1228         }
    1229 
    1230         CommandExecutor::getEvaluation().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList);
    1231     }
    1232 
    1233     void CommandExecutor::createListOfPossibleKeys(const std::string& fragment)
    1234     {
    1235         // todo
    1236 
    1237         CommandExecutor::getEvaluation().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList);
    1238     }
    1239 
    1240     bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second)
    1241     {
    1242         return ((*first.first) < (*second.first));
    1243     }
    1244 
    1245     Identifier* CommandExecutor::getIdentifierOfPossibleFunctionClass(const std::string& name)
    1246     {
    1247         std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name));
     493            {
     494                if ((*it).getComparable().find(fragment) == 0 || fragment == "")
     495                    CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it);
     496            }
     497        }
     498    }
     499
     500    Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name)
     501    {
     502        std::string lowercase = getLowercase(name);
     503        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(lowercase);
    1248504        if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands())
    1249505            return (*it).second;
     
    1252508    }
    1253509
    1254     ExecutorStatic* CommandExecutor::getExecutorOfPossibleShortcut(const std::string& name)
    1255     {
    1256         std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name));
    1257         if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
    1258             return (*it).second;
    1259 
     510    ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier)
     511    {
     512        std::string lowercase = getLowercase(name);
     513        if (!identifier)
     514        {
     515            std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase);
     516            if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
     517                return (*it).second;
     518        }
     519        else
     520        {
     521            std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase);
     522            if (it != identifier->getLowercaseConsoleCommandMapEnd())
     523                return (*it).second;
     524        }
    1260525        return 0;
    1261526    }
    1262527
    1263     ExecutorStatic* CommandExecutor::getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier)
    1264     {
    1265         std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name));
    1266         if (it != identifier->getLowercaseConsoleCommandMapEnd())
    1267             return (*it).second;
    1268 
    1269         return 0;
    1270     }
    1271 
    1272     Identifier* CommandExecutor::getIdentifierOfPossibleConfigValueClass(const std::string& name)
    1273     {
    1274         std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name));
    1275         if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConfigValues())
    1276             return (*it).second;
    1277 
    1278         return 0;
    1279     }
    1280 
    1281     ConfigValueContainer* CommandExecutor::getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier)
    1282     {
    1283         std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMap().find(getLowercase(name));
    1284         if (it != identifier->getLowercaseConfigValueMapEnd())
    1285         {
    1286             return (*it).second;
    1287         }
    1288 
    1289         return 0;
    1290     }
    1291 
    1292     ConfigValueContainer* CommandExecutor::getContainerOfPossibleKey(const std::string& name)
    1293     {
    1294         // todo
    1295 
    1296         return 0;
    1297     }
    1298 
    1299     std::string CommandExecutor::dump(const std::list<std::pair<const std::string*, const std::string*> >& list)
    1300     {
    1301         std::string output = "";
    1302         for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it)
    1303         {
    1304             if (it != list.begin())
    1305                 output += " ";
    1306 
    1307             output += *(*it).second;
    1308         }
    1309         return output;
    1310     }
    1311 
    1312     std::string CommandExecutor::dump(const ExecutorStatic* executor)
    1313     {
    1314         std::string output = "";
    1315         for (unsigned int i = 0; i < executor->getParamCount(); i++)
    1316         {
    1317             if (i != 0)
    1318                 output += " ";
    1319 
    1320             if (executor->defaultValueSet(i))
    1321                 output += "[";
     528    std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
     529    {
     530        CommandExecutor::createArgumentCompletionList(command, param);
     531
     532        std::string lowercase = getLowercase(name);
     533        for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
     534        {
     535            if ((*it).lowercaseComparison())
     536            {
     537                if ((*it).getComparable() == lowercase)
     538                    return (*it).getString();
     539            }
    1322540            else
    1323                 output += "{";
    1324 
    1325             output += executor->getTypenameParam(i);
    1326 
    1327             if (executor->defaultValueSet(i))
    1328                 output += "=" + executor->getDefaultValue(i).toString() + "]";
    1329             else
    1330                 output += "}";
    1331         }
    1332         return output;
    1333     }
    1334 
    1335     std::string CommandExecutor::dump(const ConfigValueContainer* container)
    1336     {
    1337         AddLanguageEntry("CommandExecutor::oldvalue", "old value");
    1338         if (!container->isVector())
    1339             return ("{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")");
    1340         else
    1341             return ("(vector<" + container->getTypename() + ">) (size: " + getConvertedValue<unsigned int, std::string>(container->getVectorSize()) + ")");
     541            {
     542                if ((*it).getComparable() == name)
     543                    return (*it).getString();
     544            }
     545        }
     546
     547        return "";
     548    }
     549
     550    void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param)
     551    {
     552        std::string params[5];
     553
     554        unsigned int index = 0;
     555        unsigned int lowestIndex = 1 + (CommandExecutor::getEvaluation().functionclass_ != 0);
     556
     557        for (unsigned int i = CommandExecutor::argumentsGiven() - 1; i >= lowestIndex; --i)
     558        {
     559            params[index] = CommandExecutor::getArgument(i);
     560            ++index;
     561            if (index >= 5)
     562                break;
     563        }
     564
     565        command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]);
    1342566    }
    1343567
     
    1382606        }
    1383607    }
     608
     609    std::string CommandExecutor::getCommonBegin(const ArgumentCompletionList& list)
     610    {
     611        if (list.size() == 0)
     612        {
     613            return "";
     614        }
     615        else if (list.size() == 1)
     616        {
     617            return ((*list.begin()).getComparable() + " ");
     618        }
     619        else
     620        {
     621            std::string output = "";
     622            for (unsigned int i = 0; true; i++)
     623            {
     624                char temp = 0;
     625                for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
     626                {
     627                    std::string argument = (*it).getComparable();
     628                    if (argument.size() > i)
     629                    {
     630                        if (it == list.begin())
     631                        {
     632                            temp = argument[i];
     633                        }
     634                        else
     635                        {
     636                            if (temp != argument[i])
     637                                return output;
     638                        }
     639                    }
     640                    else
     641                    {
     642                        return output;
     643                    }
     644                }
     645                output += temp;
     646            }
     647            return output;
     648        }
     649    }
    1384650}
  • code/trunk/src/core/CommandExecutor.h

    r1349 r1502  
    3232#include "CorePrereqs.h"
    3333
    34 #include <string>
    3534#include <map>
    36 #include <list>
    3735
    38 #include "util/SubString.h"
    39 #include "util/MultiTypeMath.h"
    40 
    41 #define COMMAND_EXECUTOR_CURSOR "$"
     36#include "CommandEvaluation.h"
    4237
    4338namespace orxonox
    4439{
    45     enum CommandState
    46     {
    47         CS_Uninitialized,
    48         CS_Empty,
    49         CS_FunctionClass_Or_Shortcut_Or_Keyword,
    50         CS_Shortcut_Params,
    51         CS_Shortcut_Finished,
    52         CS_Function,
    53         CS_Function_Params,
    54         CS_Function_Finished,
    55         CS_ConfigValueClass,
    56         CS_ConfigValue,
    57         CS_ConfigValueType,
    58         CS_ConfigValueFinished,
    59         CS_KeybindKey,
    60         CS_KeybindCommand,
    61         CS_KeybindFinished,
    62         CS_Error
    63     };
    64 
    65     void exec(const std::string& filename);
    66     std::string echo(const std::string& text);
    67 
    68     void write(const std::string& filename, const std::string& text);
    69     void append(const std::string& filename, const std::string& text);
    70     std::string read(const std::string& filename);
    71 
    72     ///////////////////////
    73     // CommandEvaluation //
    74     ///////////////////////
    75     class _CoreExport CommandEvaluation
    76     {
    77         friend class CommandExecutor;
    78 
    79         public:
    80             CommandEvaluation();
    81 
    82             KeybindMode::Enum getKeybindMode();
    83             bool isValid() const;
    84 
    85             inline void setAdditionalParameter(const std::string& param)
    86                 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }
    87             inline std::string getAdditionalParameter() const
    88                 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }
    89             inline ExecutorStatic* getEvaluatedExecutor() { return evaluatedExecutor_; }
    90             inline std::string getCommandString() { return this->processedCommand_; }
    91 
    92             void setEvaluatedParameter(unsigned int index, MultiTypeMath param);
    93             MultiTypeMath getEvaluatedParameter(unsigned int index) const;
    94 
    95             void evaluateParams();
    96 
    97             bool hasReturnvalue() const;
    98             MultiTypeMath getReturnvalue() const;
    99 
    100         private:
    101             std::string processedCommand_;
    102             SubString tokens_;
    103             std::string additionalParameter_;
    104 
    105             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctionClasses_;
    106             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleShortcuts_;
    107             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;
    108             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValueClasses_;
    109             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValues_;
    110             std::list<std::pair<const std::string*, const std::string*> > listOfPossibleKeys_;
    111 
    112             Identifier* functionclass_;
    113             Identifier* configvalueclass_;
    114             ExecutorStatic* shortcut_;
    115             ExecutorStatic* function_;
    116             ConfigValueContainer* configvalue_;
    117             ConfigValueContainer* key_;
    118 
    119             std::string errorMessage_;
    120             CommandState state_;
    121 
    122             bool bEvaluatedParams_;
    123             MultiTypeMath param_[5];
    124             ExecutorStatic* evaluatedExecutor_;
    125     };
    126 
    127     /////////////////////
    128     // CommandExecutor //
    129     /////////////////////
    13040    class _CoreExport CommandExecutor
    13141    {
    13242        public:
    13343            static bool execute(const std::string& command, bool useTcl = true);
    134             static bool execute(const CommandEvaluation& evaluation);
    135 
    13644            static std::string complete(const std::string& command);
    137             static std::string complete(const CommandEvaluation& evaluation);
    138 
    13945            static std::string hint(const std::string& command);
    140             static std::string hint(const CommandEvaluation& evaluation);
    14146
    14247            static CommandEvaluation evaluate(const std::string& command);
    143 
    14448            static const CommandEvaluation& getLastEvaluation();
    14549
    146             static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
    147             static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);
    148             static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);
     50            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command);
     51            static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
     52            static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
    14953
    15054            /** @brief Returns the map that stores all console commands. @return The const_iterator */
    151             static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
     55            static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
    15256            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
    153             static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
     57            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
    15458            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
    155             static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
     59            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
    15660
    15761            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
    158             static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
     62            static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
    15963            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    160             static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
     64            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
    16165            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    162             static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
     66            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
    16367
    16468        private:
     
    17074            static CommandEvaluation& getEvaluation();
    17175
     76            static void parseIfNeeded(const std::string& command);
    17277            static void parse(const std::string& command, bool bInitialize = true);
    173             static void initialize(const std::string& command);
    17478
    175             static bool argumentsGiven(unsigned int num);
     79            static unsigned int argumentsFinished();
    17680            static unsigned int argumentsGiven();
     81            static bool enoughArgumentsGiven(ConsoleCommand* command);
     82            static std::string getArgument(unsigned int index);
     83            static std::string getLastArgument();
    17784
    178             static std::string getToken(unsigned int index);
     85            static void createListOfPossibleIdentifiers(const std::string& fragment);
     86            static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0);
     87            static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param);
    17988
    180             static bool enoughParametersGiven(unsigned int head, Executor* executor);
     89            static Identifier* getPossibleIdentifier(const std::string& name);
     90            static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
     91            static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
    18192
    182             static void createListOfPossibleShortcuts(const std::string& fragment);
    183             static void createListOfPossibleFunctionClasses(const std::string& fragment);
    184             static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier);
    185             static void createListOfPossibleConfigValueClasses(const std::string& fragment);
    186             static void createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier);
    187             static void createListOfPossibleKeys(const std::string& fragment);
    188 
    189             static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second);
    190 
    191             static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
    192             static std::string dump(const ExecutorStatic* executor);
    193             static std::string dump(const ConfigValueContainer* container);
    194 
     93            static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
    19594            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
    196 
    197             static Identifier* getIdentifierOfPossibleFunctionClass(const std::string& name);
    198             static ExecutorStatic* getExecutorOfPossibleShortcut(const std::string& name);
    199             static ExecutorStatic* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier);
    200             static Identifier* getIdentifierOfPossibleConfigValueClass(const std::string& name);
    201             static ConfigValueContainer* getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier);
    202             static ConfigValueContainer* getContainerOfPossibleKey(const std::string& name);
     95            static std::string getCommonBegin(const ArgumentCompletionList& list);
    20396
    20497            CommandEvaluation evaluation_;
    205 
    206             std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_;
    207             std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_;
     98            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
     99            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
    208100    };
    209101}
  • code/trunk/src/core/ConfigFileManager.cc

    r1056 r1502  
    3838namespace orxonox
    3939{
    40     ConsoleCommandShortcutExtern(reloadConfig, AccessLevel::None);
    41     ConsoleCommandShortcutExtern(cleanConfig, AccessLevel::None);
    42     ConsoleCommandShortcutExtern(loadSettings, AccessLevel::None);
    43     ConsoleCommandShortcutExtern(loadKeybindings, AccessLevel::None);
     40    SetConsoleCommandShortcutExtern(config).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue());
     41    SetConsoleCommandShortcutExtern(tconfig).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue());
     42    SetConsoleCommandShortcutExtern(reloadConfig);
     43    SetConsoleCommandShortcutExtern(cleanConfig);
     44    SetConsoleCommandShortcutExtern(loadSettings).setArgumentCompleter(0, autocompletion::files());
     45    SetConsoleCommandShortcutExtern(loadKeybindings).setArgumentCompleter(0, autocompletion::files());
     46
     47    bool config(const std::string& classname, const std::string& varname, const std::string& value)
     48    {
     49        std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
     50        if (identifier != Identifier::getLowercaseIdentifierMapEnd())
     51        {
     52            std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
     53            if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
     54                return (*variable).second->set(value);
     55        }
     56        return false;
     57    }
     58
     59    bool tconfig(const std::string& classname, const std::string& varname, const std::string& value)
     60    {
     61        std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
     62        if (identifier != Identifier::getLowercaseIdentifierMapEnd())
     63        {
     64            std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
     65            if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
     66                return (*variable).second->tset(value);
     67        }
     68        return false;
     69    }
    4470
    4571    void reloadConfig()
     
    336362
    337363        COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl;
     364    }
     365
     366    void ConfigFile::save(const std::string& filename)
     367    {
     368        std::string temp = this->filename_;
     369        this->filename_ = filename;
     370        this->save();
     371        this->filename_ = temp;
    338372    }
    339373
     
    473507    }
    474508
     509    void ConfigFileManager::save(ConfigFileType type, const std::string& filename)
     510    {
     511        this->getFile(type)->save(filename);
     512    }
     513
    475514    void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments)
    476515    {
  • code/trunk/src/core/ConfigFileManager.h

    r1116 r1502  
    5050
    5151
     52    bool config(const std::string& classname, const std::string& varname, const std::string& value);
     53    bool tconfig(const std::string& classname, const std::string& varname, const std::string& value);
    5254    void reloadConfig();
    5355    void saveConfig();
     
    222224            void load(bool bCreateIfNotExisting = true);
    223225            void save() const;
     226            void save(const std::string& filename);
    224227            void clean(bool bCleanComments = false);
    225228
     
    265268            void load(ConfigFileType type, bool bCreateIfNotExisting = true);
    266269            void save(ConfigFileType type);
     270            void save(ConfigFileType type, const std::string& filename);
    267271            void clean(ConfigFileType type, bool bCleanComments = false);
    268272
  • code/trunk/src/core/ConfigValueContainer.cc

    r1062 r1502  
    8787
    8888        if (defvalue.size() > 0)
    89             this->value_ = defvalue[0];
    90 
    91         for (unsigned int i = 0; i < defvalue.size(); i++)
    92             ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string));
    93 
    94         for (unsigned int i = 0; i < defvalue.size(); i++)
    95             this->defvalueStringVector_.push_back(defvalue[i].toString());
    96 
    97         this->update();
     89        {
     90                this->value_ = defvalue[0];
     91
     92            for (unsigned int i = 0; i < defvalue.size(); i++)
     93            {
     94                ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string));
     95                this->defvalueStringVector_.push_back(defvalue[i].toString());
     96            }
     97
     98            this->update();
     99        }
     100    }
     101
     102    /**
     103        @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
     104        @param input The new value
     105        @return True if the new value was successfully assigned
     106    */
     107    bool ConfigValueContainer::set(const MultiTypeMath& input)
     108    {
     109        if (this->bIsVector_)
     110        {
     111            return this->callFunctionWithIndex(&ConfigValueContainer::set, input.toString());
     112        }
     113        else
     114        {
     115            if (this->tset(input))
     116            {
     117                ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input.toString(), this->value_.isA(MT_string));
     118                return true;
     119            }
     120        }
     121        return false;
     122    }
     123
     124    /**
     125        @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
     126        @param index The index in the vector
     127        @param input The new value
     128        @return True if the new value was successfully assigned
     129    */
     130    bool ConfigValueContainer::set(unsigned int index, const MultiTypeMath& input)
     131    {
     132        if (this->bIsVector_)
     133        {
     134            if (this->tset(index, input))
     135            {
     136                ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input.toString(), this->value_.isA(MT_string));
     137                return true;
     138            }
     139        }
     140        else
     141        {
     142            COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
     143        }
     144        return false;
     145    }
     146
     147    /**
     148        @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
     149        @param input The new value. If bIsVector_ then write "index value"
     150        @return True if the new value was successfully assigned
     151    */
     152    bool ConfigValueContainer::tset(const MultiTypeMath& input)
     153    {
     154        if (this->bIsVector_)
     155        {
     156            return this->callFunctionWithIndex(&ConfigValueContainer::tset, input.toString());
     157        }
     158        else
     159        {
     160            MultiTypeMath temp = this->value_;
     161            if (temp.assimilate(input))
     162            {
     163                this->value_ = temp;
     164                if (this->identifier_)
     165                    this->identifier_->updateConfigValues();
     166
     167                return true;
     168            }
     169        }
     170        return false;
     171    }
     172
     173    /**
     174        @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
     175        @param index The index in the vector
     176        @param input The new value
     177        @return True if the new value was successfully assigned
     178    */
     179    bool ConfigValueContainer::tset(unsigned int index, const MultiTypeMath& input)
     180    {
     181        if (this->bIsVector_)
     182        {
     183            if (index > MAX_VECTOR_INDEX)
     184            {
     185                COUT(1) << "Error: Index " << index << " is too large." << std::endl;
     186                return false;
     187            }
     188
     189            if (index >= this->valueVector_.size())
     190            {
     191                for (unsigned int i = this->valueVector_.size(); i <= index; i++)
     192                {
     193                    this->valueVector_.push_back(MultiTypeMath());
     194                }
     195            }
     196
     197            MultiTypeMath temp = this->value_;
     198            if (temp.assimilate(input))
     199            {
     200                this->valueVector_[index] = temp;
     201
     202                if (this->identifier_)
     203                    this->identifier_->updateConfigValues();
     204
     205                return true;
     206            }
     207        }
     208        else
     209        {
     210            COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
     211        }
     212        return false;
    98213    }
    99214
     
    103218        @return True if the new entry was successfully added
    104219    */
    105     bool ConfigValueContainer::add(const std::string& input)
     220    bool ConfigValueContainer::add(const MultiTypeMath& input)
    106221    {
    107222        if (this->bIsVector_)
     
    123238            if (index < this->valueVector_.size())
    124239            {
     240                // Erase the entry from the vector, change (shift) all entries beginning with index in the config file, remove the last entry from the file
    125241                this->valueVector_.erase(this->valueVector_.begin() + index);
    126242                for (unsigned int i = index; i < this->valueVector_.size(); i++)
     
    131247            }
    132248            COUT(1) << "Error: Invalid vector-index." << std::endl;
    133         }
    134 
    135         COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
    136         return false;
    137     }
    138 
    139     /**
    140         @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
    141         @param input The new value
    142         @return True if the new value was successfully assigned
    143     */
    144     bool ConfigValueContainer::set(const std::string& input)
    145     {
    146         if (this->bIsVector_)
    147         {
    148             SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0');
    149             int index = -1;
    150             bool success = false;
    151 
    152             if (token.size() > 0)
    153                 success = ConvertValue(&index, token[0]);
    154 
    155             if (!success || index < 0 || index > MAX_VECTOR_INDEX)
    156             {
    157                 if (!success)
    158                 {
    159                     COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;
    160                 }
    161                 else
    162                 {
    163                     COUT(1) << "Error: Invalid vector-index." << std::endl;
    164                 }
    165                 return false;
    166             }
    167 
    168             if (token.size() >= 2)
    169                 return this->set(index, token.subSet(1).join());
    170             else
    171                 return this->set(index, "");
    172         }
    173 
    174         bool success = this->tset(input);
    175         ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isA(MT_string));
    176         return success;
    177     }
    178 
    179     /**
    180         @brief Assigns a new value to the config-value of all objects and writes the change into the config-file.
    181         @param index The index in the vector
    182         @param input The new value
    183         @return True if the new value was successfully assigned
    184     */
    185     bool ConfigValueContainer::set(unsigned int index, const std::string& input)
    186     {
    187         if (this->bIsVector_)
    188         {
    189             bool success = this->tset(index, input);
    190             ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isA(MT_string));
    191             return success;
    192         }
    193 
    194         COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
    195         return false;
    196     }
    197 
    198     /**
    199         @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
    200         @param input The new value
    201         @return True if the new value was successfully assigned
    202     */
    203     bool ConfigValueContainer::tset(const std::string& input)
    204     {
    205         bool success = this->parse(input);
    206         if (this->identifier_)
    207             this->identifier_->updateConfigValues();
    208         return success;
    209     }
    210 
    211     /**
    212         @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
    213         @param index The index in the vector
    214         @param input The new value
    215         @return True if the new value was successfully assigned
    216     */
    217     bool ConfigValueContainer::tset(unsigned int index, const std::string& input)
    218     {
    219         if (this->bIsVector_)
    220         {
    221             bool success = this->parse(index, input);
    222             if (this->identifier_)
    223                 this->identifier_->updateConfigValues();
    224             return success;
    225249        }
    226250
     
    259283            for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++)
    260284            {
    261                 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string)));
    262                 this->valueVector_.push_back(this->value_);
    263             }
    264         }
    265     }
    266 
    267     /**
    268         @brief Parses a given std::string into a value of the type of the associated variable and assigns it.
    269         @param input The string to convert
    270         @return True if the string was successfully parsed
    271     */
    272     bool ConfigValueContainer::parse(const std::string& input)
    273     {
    274         if (this->bIsVector_)
    275         {
    276             SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0');
    277             int index = -1;
    278             bool success = false;
    279 
    280             if (token.size() > 0)
    281                 success = ConvertValue(&index, token[0]);
    282 
    283             if (!success || index < 0 || index > MAX_VECTOR_INDEX)
    284             {
    285                 if (!success)
     285                if (i < this->defvalueStringVector_.size())
    286286                {
    287                     COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;
     287                    this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string)));
    288288                }
    289289                else
    290290                {
    291                     COUT(1) << "Error: Invalid vector-index." << std::endl;
     291                    this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, MultiTypeMath(), this->value_.isA(MT_string)));
    292292                }
    293                 return false;
    294             }
    295 
    296             if (token.size() >= 2)
    297                 return this->parse(index, token.subSet(1).join());
     293
     294                this->valueVector_.push_back(this->value_);
     295            }
     296        }
     297    }
     298
     299    /**
     300        @brief Calls the given function with parsed index and the parsed argument from the input string.
     301        @param function The function to call
     302        @param input The input string
     303        @return The returnvalue of the functioncall
     304    */
     305    bool ConfigValueContainer::callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input)
     306    {
     307        SubString token(input, " ", SubString::WhiteSpaces, true, '\\', false, '"', false, '(', ')', false, '\0');
     308        int index = -1;
     309        bool success = false;
     310
     311        if (token.size() > 0)
     312            success = ConvertValue(&index, token[0]);
     313
     314        if (!success || index < 0 || index > MAX_VECTOR_INDEX)
     315        {
     316            if (!success)
     317            {
     318                COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl;
     319            }
    298320            else
    299                 return this->parse(index, "");
    300         }
    301 
    302         MultiTypeMath temp = this->value_;
    303         if (temp.fromString(input))
    304         {
    305             this->value_ = temp;
    306             return true;
    307         }
    308         return false;
    309     }
    310 
    311     /**
    312         @brief Parses a given std::string into a value of the type of the associated variable and assigns it.
    313         @param index The index in the vector
    314         @param input The string to convert
    315         @return True if the string was successfully parsed
    316     */
    317     bool ConfigValueContainer::parse(unsigned int index, const std::string& input)
    318     {
    319         if (this->bIsVector_)
    320         {
    321             if (index >= this->valueVector_.size())
    322             {
    323                 for (unsigned int i = this->valueVector_.size(); i <= index; i++)
    324                 {
    325                     this->valueVector_.push_back(MultiTypeMath());
    326                     ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string));
    327                 }
    328             }
    329 
    330             MultiTypeMath temp = this->value_;
    331             if (temp.fromString(input))
    332             {
    333                 this->valueVector_[index] = temp;
    334                 return true;
     321            {
     322                COUT(1) << "Error: Invalid vector-index." << std::endl;
    335323            }
    336324            return false;
    337325        }
    338326
    339         COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
    340         return false;
    341     }
    342 
    343     /**
    344         @brief Parses a given std::string into a value of the type of the associated variable and assigns it.
    345         @param input The string to convert
    346         @param defvalue The default value to assign if the parsing fails
    347         @return True if the string was successfully parsed
    348     */
    349     bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue)
    350     {
    351         if (this->parse(input))
    352             return true;
    353 
    354         this->value_ = defvalue;
    355         return false;
    356     }
    357 
    358     /**
    359         @brief Parses a given std::string into a value of the type of the associated variable and assigns it.
    360         @param index The index in the vector
    361         @param input The string to convert
    362         @param defvalue The default value to assign if the parsing fails
    363         @return True if the string was successfully parsed
    364     */
    365     bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue)
    366     {
    367         if (this->bIsVector_)
    368         {
    369             if (this->parse(index, input))
    370                 return true;
    371 
    372             this->valueVector_[index] = defvalue;
    373             return false;
    374         }
    375 
    376         COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl;
    377         return false;
     327        if (token.size() >= 2)
     328            return (this->*function)(index, token.subSet(1).join());
     329        else
     330            return (this->*function)(index, "");
    378331    }
    379332
  • code/trunk/src/core/ConfigValueContainer.h

    r1062 r1502  
    9090            }
    9191
     92            template <typename T>
     93            inline void setVectorType(const std::vector<T>& value)
     94            {
     95                this->value_ = T();
     96                this->update();
     97            }
     98
    9299            inline const std::string& getName() const
    93100                { return this->varname_; }
     
    100107            const std::string& getDescription() const;
    101108
    102             bool add(const std::string& input);
     109            bool set(const MultiTypeMath& input);
     110            bool tset(const MultiTypeMath& input);
     111
     112            bool set(unsigned int index, const MultiTypeMath& input);
     113            bool tset(unsigned int index, const MultiTypeMath& input);
     114            bool add(const MultiTypeMath& input);
    103115            bool remove(unsigned int index);
    104             bool set(const std::string& input);
    105             bool tset(const std::string& input);
     116
    106117            bool reset();
    107118            void update();
     
    115126
    116127        private:
    117             bool parse(const std::string& input);
    118             bool parse(const std::string& input, const MultiTypeMath& defvalue);
    119 
    120             bool set(unsigned int index, const std::string& input);
    121             bool tset(unsigned int index, const std::string& input);
    122             bool parse(unsigned int index, const std::string& input);
    123             bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue);
     128            bool callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiTypeMath&), const std::string& input);
    124129
    125130            bool                       bIsVector_;                  //!< True if the container contains a std::vector
  • code/trunk/src/core/ConfigValueIncludes.h

    r1062 r1502  
    5757
    5858/**
     59    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
     60    @param classname name in which the config value should be stored
     61    @param varname The name of the variable
     62    @param defvalue The default-value of the variable
     63*/
     64#define SetConfigValueGeneric(classname, varname, defvalue) \
     65    orxonox::ConfigValueContainer* container##varname = ClassManager<classname>::getIdentifier()->getConfigValueContainer(#varname); \
     66    if (!container##varname) \
     67    { \
     68        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, ClassManager<classname>::getIdentifier(), #varname, varname = defvalue); \
     69        ClassManager<classname>::getIdentifier()->addConfigValueContainer(#varname, container##varname); \
     70    } \
     71    container##varname->getValue(&varname)
     72
     73/**
    5974    @brief Assigns the vector-values, defined in the config-file, to the vector (or the default-value, if there are no entries in the file).
    6075    @param varname The name of the std::vector
     
    6984            temp.push_back(MultiTypeMath(defvalue[i])); \
    7085        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \
     86        container##varname->setVectorType(varname); \
    7187        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
    7288    } \
     
    106122    }
    107123
    108 /**
    109     @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file).
    110     @param varname The name of the key-variable
    111 */
    112 #define SetKeybind(keyname) \
    113     orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \
    114     if (!container##keyname) \
    115     { \
    116         container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \
    117         this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \
    118     } \
    119     container##keyname->getValue(&varname)
    120 
    121124#endif /* _ConfigValueIncludes_H__ */
  • code/trunk/src/core/ConsoleCommand.h

    r1062 r1502  
    3434#include "Executor.h"
    3535#include "ClassManager.h"
    36 #include "Identifier.h"
    3736#include "CommandExecutor.h"
     37#include "ArgumentCompletionFunctions.h"
    3838
    3939
     40#define SetConsoleCommand(classname, function,  bCreateShortcut) \
     41    SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut)
    4042
    41 #define ConsoleCommand(classname, function, accesslevel, bCreateShortcut) \
    42     ConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel), bCreateShortcut)
    43 
    44 #define ConsoleCommandGeneric(fakevariable, classname, executor, bCreateShortcut) \
    45     Executor& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ExecutorStatic*)executor, bCreateShortcut)
     43#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
     44    ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut)
    4645
    4746
    48 #define ConsoleCommandShortcut(classname, function, accesslevel) \
    49     ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&classname::function), #function, accesslevel))
     47#define SetConsoleCommandShortcut(classname, function) \
     48    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function))
    5049
    51 #define ConsoleCommandShortcutExtern(function, accesslevel) \
    52     ConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createExecutor(orxonox::createFunctor(&function), #function, accesslevel))
     50#define SetConsoleCommandShortcutExtern(function) \
     51    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function))
    5352
    54 #define ConsoleCommandShortcutGeneric(fakevariable, executor) \
    55     Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)
     53#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
     54    ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command)
    5655
    5756
     57namespace orxonox
     58{
     59    namespace AccessLevel
     60    {
     61        enum Level
     62        {
     63            None,
     64            User,
     65            Admin,
     66            Offline,
     67            Debug,
     68            Disabled
     69        };
     70    }
     71
     72    class _CoreExport ConsoleCommand : public ExecutorStatic
     73    {
     74        public:
     75            ConsoleCommand(FunctorStatic* functor, const std::string& name = "");
     76
     77            inline ConsoleCommand& setDescription(const std::string& description)
     78                { this->ExecutorStatic::setDescription(description); return (*this); }
     79            inline ConsoleCommand& setDescriptionParam(int param, const std::string& description)
     80                { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); }
     81            inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description)
     82                { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); }
     83            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1)
     84                { this->ExecutorStatic::setDefaultValues(param1); return (*this); }
     85            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
     86                { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); }
     87            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
     88                { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); }
     89            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
     90                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); }
     91            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
     92                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
     93            inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param)
     94                { this->ExecutorStatic::setDefaultValue(index, param); return (*this); }
     95
     96            inline ConsoleCommand& setAccessLevel(AccessLevel::Level level)
     97                { this->accessLevel_ = level; return (*this); }
     98            inline AccessLevel::Level getAccessLevel() const
     99                { return this->accessLevel_; }
     100
     101            ConsoleCommand& setArgumentCompleter(unsigned int param, ArgumentCompleter* completer);
     102            ArgumentCompleter* getArgumentCompleter(unsigned int param) const;
     103
     104            void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "");
     105            const ArgumentCompletionList& getArgumentCompletionList() const
     106                { return this->argumentList_; }
     107            ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
     108                { return this->argumentList_.begin(); }
     109            ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
     110                { return this->argumentList_.end(); }
     111
     112            inline ConsoleCommand& setKeybindMode(KeybindMode::Enum mode)
     113                { this->keybindMode_ = mode; return *this; }
     114            inline KeybindMode::Enum getKeybindMode() const
     115                { return this->keybindMode_; }
     116
     117            inline ConsoleCommand& setAxisParamIndex(int index)
     118                { this->axisParamIndex_ = index; return *this; }
     119            inline int getAxisParamIndex() const
     120                { return this->axisParamIndex_; }
     121
     122            inline ConsoleCommand& setIsAxisRelative(bool val)
     123                { this->bAxisRelative_ = val; return *this; }
     124            inline int getIsAxisRelative() const
     125                { return this->bAxisRelative_; }
     126
     127        private:
     128            AccessLevel::Level accessLevel_;
     129            ArgumentCompleter* argumentCompleter_[5];
     130            ArgumentCompletionList argumentList_;
     131
     132            KeybindMode::Enum keybindMode_;
     133            int axisParamIndex_;
     134            bool bAxisRelative_;
     135    };
     136
     137    inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "")
     138    {
     139        return new ConsoleCommand(functor, name);
     140    }
     141}
     142
    58143#endif /* _ConsoleCommand_H__ */
  • code/trunk/src/core/CorePrereqs.h

    r1349 r1502  
    3535#define _CorePrereqs_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939#include <string>
     
    6666namespace orxonox
    6767{
    68 #ifndef _XMLPort_Mode__
    69 #define _XMLPort_Mode__
    7068  namespace XMLPort
    7169  {
     
    7674    };
    7775  }
    78 #endif
    7976
    8077  namespace KeybindMode
     
    9188  typedef std::string LanguageEntryLabel;
    9289
     90  class ArgumentCompleter;
     91  class ArgumentCompletionListElement;
    9392  class BaseFactory;
    9493  class BaseMetaObjectListElement;
     
    112111  class ConfigFileSection;
    113112  class ConfigValueContainer;
     113  class ConsoleCommand;
    114114  class CoreSettings;
    115115  class Error;
     
    125125  class Identifier;
    126126  class IdentifierDistributor;
     127  class IRC;
    127128  template <class T>
    128129  class Iterator;
     
    141142  class ObjectListElement;
    142143  class OrxonoxClass;
     144  class OutputBuffer;
     145  class OutputBufferListener;
    143146  class OutputHandler;
    144147  class Shell;
     148  class ShellListener;
    145149  template <class T>
    146150  class SubclassIdentifier;
    147151  class TclBind;
     152  struct TclInterpreterBundle;
     153  class TclThreadManager;
    148154  class Tickable;
    149155  template <class T, class O>
     
    156162  // input
    157163  //class GUIInputHandler;
     164  class Calibrator;
     165  class CalibratorCallback;
    158166  class InputBuffer;
    159167  class InputBufferListener;
     
    161169  class JoyStickHandler;
    162170  class KeyBinder;
    163   class KeyHandler;
     171  class KeyDetector;
    164172  class MouseHandler;
    165173
  • code/trunk/src/core/CoreSettings.cc

    r1058 r1502  
    117117
    118118    /**
    119         @brief Static function that holds the singleton.
     119        @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created).
     120        @param device The device
     121        @return The softDebugLevel
    120122    */
    121123    int CoreSettings::getSoftDebugLevel(OutputHandler::OutputDevice device)
     
    136138        return 2;
    137139    }
     140
     141     /**
     142        @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value.
     143        @param device The device
     144        @param level The level
     145    */
     146     void CoreSettings::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
     147     {
     148        if (!CoreSettings::isCreatingCoreSettings())
     149        {
     150            if (device == OutputHandler::LD_All)
     151                CoreSettings::getInstance().softDebugLevel_ = level;
     152            else if (device == OutputHandler::LD_Console)
     153                CoreSettings::getInstance().softDebugLevelConsole_ = level;
     154            else if (device == OutputHandler::LD_Logfile)
     155                CoreSettings::getInstance().softDebugLevelLogfile_ = level;
     156            else if (device == OutputHandler::LD_Shell)
     157                CoreSettings::getInstance().softDebugLevelShell_ = level;
     158        }
     159     }
    138160
    139161    /**
  • code/trunk/src/core/CoreSettings.h

    r1064 r1502  
    5454
    5555            static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
     56            static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
    5657            static const std::string& getLanguage();
    5758            static void resetLanguage();
  • code/trunk/src/core/Debug.h

    r1293 r1502  
    206206   COUT ## x
    207207
     208  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
     209   #define COUT0  \
     210    if (getSoftDebugLevel() >= ORX_NONE)  \
     211     COUT_EXEC(0)
     212  #else
     213   #define COUT0 if (ORX_NONE)\
     214    COUT_EXEC(0)
     215  #endif
     216
    208217  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
    209218   #define COUT1  \
     
    256265 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
    257266
    258  #define COUT0 \
    259   COUT_EXEC(0)
    260267#endif /* ifndef COUT */
    261268
     
    280287   CCOUT ## x
    281288
     289  #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
     290   #define CCOUT0  \
     291    if (getSoftDebugLevel() >= ORX_NONE)  \
     292     CCOUT_EXEC(0)
     293  #else
     294   #define CCOUT0 if (ORX_NONE)\
     295    CCOUT_EXEC(0)
     296  #endif
     297
    282298  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
    283299   #define CCOUT1  \
     
    330346 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
    331347
    332  #define CCOUT0 \
    333   CCOUT_EXEC(0)
    334348#endif /* ifndef CCOUT */
    335349
  • code/trunk/src/core/Executor.cc

    r1349 r1502  
    3434namespace orxonox
    3535{
    36     Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level)
     36    Executor::Executor(Functor* functor, const std::string& name)
    3737    {
    3838        this->functor_ = functor;
    3939        this->name_ = name;
    40         this->accessLevel_ = level;
    41         this->keybindMode_ = KeybindMode::OnPress;
    42         this->axisParamIndex_ = -1;
    43         this->bAxisRelative_ = false;
    4440
    4541        this->bAddedDescription_ = false;
  • code/trunk/src/core/Executor.h

    r1349 r1502  
    3535#include "util/SubString.h"
    3636#include "util/String.h"
     37#include "util/Math.h"
    3738#include "Functor.h"
    3839#include "Debug.h"
     
    100101            COUT(5) << tokens[i]; \
    101102        } \
    102         COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; \
     103        COUT(5) << ") and " << max((int)paramCount - (int)tokens.size(), 0) << " default values ("; \
    103104        for (unsigned int i = tokens.size(); i < paramCount; i++) \
    104105        { \
     
    134135    return true
    135136
    136 namespace AccessLevel
    137 {
    138     enum Level
    139     {
    140         None,
    141         User,
    142         Admin,
    143         Offline,
    144         Debug,
    145         Disabled
    146     };
    147 }
    148 
    149137namespace orxonox
    150138{
     
    152140    {
    153141        public:
    154             Executor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None);
     142            Executor(Functor* functor, const std::string& name = "");
    155143            virtual ~Executor();
    156144
     
    181169            const std::string& getDescriptionReturnvalue(int param) const;
    182170
     171            inline Functor* getFunctor() const
     172                { return this->functor_; }
    183173            inline unsigned int getParamCount() const
    184174                { return this->functor_->getParamCount(); }
     
    199189                { return this->name_; }
    200190
    201             inline void setAccessLevel(AccessLevel::Level level)
    202                 { this->accessLevel_ = level; }
    203             inline AccessLevel::Level getAccessLevel() const
    204                 { return this->accessLevel_; }
    205 
    206             inline Executor& setKeybindMode(KeybindMode::Enum mode)
    207                 { this->keybindMode_ = mode; return *this; }
    208             inline KeybindMode::Enum getKeybindMode() const
    209                 { return this->keybindMode_; }
    210 
    211             inline Executor& setAxisParamIndex(int index)
    212                 { this->axisParamIndex_ = index; return *this; }
    213             inline int getAxisParamIndex() const
    214                 { return this->axisParamIndex_; }
    215 
    216             inline Executor& setIsAxisRelative(bool val)
    217                 { this->bAxisRelative_ = val; return *this; }
    218             inline int getIsAxisRelative() const
    219                 { return this->bAxisRelative_; }
    220 
    221191            Executor& setDefaultValues(const MultiTypeMath& param1);
    222192            Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2);
     
    249219            bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS];
    250220
    251             KeybindMode::Enum keybindMode_;
    252             int axisParamIndex_;
    253             bool bAxisRelative_;
    254 
    255221        private:
    256222            LanguageEntryLabel description_;
     
    261227            bool bAddedDescriptionReturnvalue_;
    262228            bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS];
    263 
    264             AccessLevel::Level accessLevel_;
    265229    };
    266230
     
    268232    {
    269233        public:
    270             ExecutorStatic(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}
     234            ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {}
    271235            virtual ~ExecutorStatic() {}
    272236    };
     
    276240    {
    277241        public:
    278             ExecutorMember(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {}
     242            ExecutorMember(FunctorMember<T>* functor, const std::string& name = "") : Executor(functor, name) {}
    279243            virtual ~ExecutorMember() {}
    280244
     
    322286    };
    323287
    324     inline Executor* createExecutor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None)
    325     {
    326         return new Executor(functor, name, level);
     288    inline Executor* createExecutor(Functor* functor, const std::string& name = "")
     289    {
     290        return new Executor(functor, name);
    327291    }
    328292
    329293    template <class T>
    330     inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None)
    331     {
    332         return new ExecutorMember<T>(functor, name, level);
     294    inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "")
     295    {
     296        return new ExecutorMember<T>(functor, name);
    333297    }
    334298
    335     inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None)
    336     {
    337         return new ExecutorStatic(functor, name, level);
     299    inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "")
     300    {
     301        return new ExecutorStatic(functor, name);
    338302    }
    339303}
  • code/trunk/src/core/Identifier.cc

    r1062 r1502  
    3737
    3838#include "Factory.h"
    39 #include "Executor.h"
     39#include "ConsoleCommand.h"
    4040#include "CommandExecutor.h"
    4141
     
    231231    void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
    232232    {
     233        std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname);
     234        if (it != this->configValues_.end())
     235        {
     236            COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl;
     237        }
     238
    233239        this->bHasConfigValues_ = true;
    234240        this->configValues_[varname] = container;
     
    270276        @return The executor of the command
    271277    */
    272     ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut)
    273     {
     278    ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut)
     279    {
     280        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName());
     281        if (it != this->consoleCommands_.end())
     282        {
     283            COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl;
     284        }
     285
    274286        this->bHasConsoleCommands_ = true;
    275         this->consoleCommands_[executor->getName()] = executor;
    276         this->consoleCommands_LC_[getLowercase(executor->getName())] = executor;
     287        this->consoleCommands_[command->getName()] = command;
     288        this->consoleCommands_LC_[getLowercase(command->getName())] = command;
    277289
    278290        if (bCreateShortcut)
    279             CommandExecutor::addConsoleCommandShortcut(executor);
    280 
    281         return (*executor);
     291            CommandExecutor::addConsoleCommandShortcut(command);
     292
     293        return (*command);
    282294    }
    283295
     
    287299        @return The executor of the requested console command
    288300    */
    289     ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const
    290     {
    291         std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name);
     301    ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const
     302    {
     303        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name);
    292304        if (it != this->consoleCommands_.end())
    293305            return (*it).second;
     
    301313        @return The executor of the requested console command
    302314    */
    303     ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const
    304     {
    305         std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name);
     315    ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const
     316    {
     317        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name);
    306318        if (it != this->consoleCommands_LC_.end())
    307319            return (*it).second;
  • code/trunk/src/core/Identifier.h

    r1064 r1502  
    6363#include "Debug.h"
    6464#include "Iterator.h"
     65#include "MetaObjectList.h"
    6566#include "util/String.h"
    6667
     
    175176
    176177            /** @brief Returns the map that stores all console commands. @return The const_iterator */
    177             inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; }
     178            inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandMap() const { return this->consoleCommands_; }
    178179            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
    179             inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }
     180            inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }
    180181            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
    181             inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }
     182            inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }
    182183
    183184            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
    184             inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }
     185            inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }
    185186            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    186             inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }
     187            inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }
    187188            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    188             inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
     189            inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
    189190
    190191
     
    213214            virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
    214215
    215             ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut);
    216             ExecutorStatic* getConsoleCommand(const std::string& name) const;
    217             ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const;
     216            ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
     217            ConsoleCommand* getConsoleCommand(const std::string& name) const;
     218            ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
    218219
    219220        protected:
     
    270271
    271272            bool bHasConsoleCommands_;                                     //!< True if this class has at least one assigned console command
    272             std::map<std::string, ExecutorStatic*> consoleCommands_;       //!< All console commands of this class
    273             std::map<std::string, ExecutorStatic*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
     273            std::map<std::string, ConsoleCommand*> consoleCommands_;       //!< All console commands of this class
     274            std::map<std::string, ConsoleCommand*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
    274275    };
    275276
  • code/trunk/src/core/InputBuffer.cc

    r1349 r1502  
    3737namespace orxonox
    3838{
    39   InputBuffer::InputBuffer(const std::string allowedChars) :
    40     buffer_(""),
    41     allowedChars_(allowedChars),
    42     lastKey_(KeyCode::Unassigned),
    43     timeSinceKeyPressed_(0.0f),
    44     timeSinceKeyRepeated_(0.0f),
    45     keysToRepeat_(0)
    46   {
    47     RegisterObject(InputBuffer);
    48     setConfigValues();
    49   }
    50 
    51   void InputBuffer::setConfigValues()
    52   {
    53     SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer");
    54     SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer");
    55     if (keyRepeatDeleay_ < 0.0)
    56     {
    57       ResetConfigValue(keyRepeatDeleay_);
    58     }
    59     if (keyRepeatTime_ < 0.0)
    60     {
    61       ResetConfigValue(keyRepeatTime_);
    62     }
    63   }
    64   /*
    65   void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), bool bOnlySingleInput)
    66   {
    67     struct InputBufferListenerTuple newListener = {listener, function, true, bOnlySingleInput, ' '};
    68     listeners_.insert(listeners_.end(), newListener);
    69   }
    70 
    71   void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), char char_, bool bOnlySingleInput)
    72   {
    73     struct InputBufferListenerTuple newListener = {listener, function, false, bOnlySingleInput, char_};
    74     listeners_.insert(listeners_.end(), newListener);
    75   }
    76   */
    77   void InputBuffer::set(const std::string& input)
    78   {
    79     buffer_ = "";
    80     append(input);
    81   }
    82 
    83   void InputBuffer::append(const std::string& input)
    84   {
    85     for (unsigned int i = 0; i < input.size(); i++)
    86     {
    87       if (charIsAllowed(input[i]))
    88         buffer_ += input[i];
    89 
    90       updated(input[i], false);
    91     }
    92     updated();
    93   }
    94 
    95   void InputBuffer::append(const char& input)
    96   {
    97     if (charIsAllowed(input))
    98       buffer_ += input;
    99 
    100     updated(input, true);
    101   }
    102 
    103   void InputBuffer::clear()
    104   {
    105     buffer_ = "";
    106     updated();
    107   }
    108 
    109   void InputBuffer::removeLast()
    110   {
    111     buffer_ = buffer_.substr(0, buffer_.size() - 1);
    112     updated();
    113   }
    114 
    115   void InputBuffer::updated()
    116   {
    117     for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
    118     {
    119       if ((*it).bListenToAllChanges_)
    120         (*(*it).listener_.*(*it).function_)();
    121     }
    122   }
    123 
    124   void InputBuffer::updated(const char& update, bool bSingleInput)
    125   {
    126     for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
    127     {
    128       if (((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput))
    129         (*(*it).listener_.*(*it).function_)();
    130     }
    131   }
    132 
    133   bool InputBuffer::charIsAllowed(const char& input)
    134   {
    135     if (allowedChars_ == "")
    136       return true;
    137     else
    138       return (allowedChars_.find(input) != std::string::npos);
    139   }
    140 
    141 
    142   void InputBuffer::processKey(const KeyEvent &evt)
    143   {
    144     if (evt.isModifierDown(KeyboardModifier::Ctrl))
    145     {
    146       if (evt.key == KeyCode::V)
    147         append(fromClipboard());
    148       else if (evt.key == KeyCode::C)
    149         toClipboard(buffer_);
    150       else if (evt.key == KeyCode::X)
    151       {
    152         toClipboard(buffer_);
    153         clear();
    154       }
    155     }
    156     else if (evt.isModifierDown(KeyboardModifier::Shift))
    157     {
    158       if (evt.key == KeyCode::Insert)
    159       {
    160         append(fromClipboard());
    161       }
    162       else if (evt.key == KeyCode::Delete)
    163       {
    164         toClipboard(buffer_);
    165         clear();
    166       }
    167     }
    168     //std::string input = keyboard_->getAsString(e.key);
    169     /*if (input.size() >= 1)
    170     append(input[0]);*/
    171 
    172     append((char)evt.text);
    173   }
    174 
    175   /**
    176   * This tick() function is called by the InputManager if the InputBuffer is active.
    177   * @param dt Delta time
    178   */
    179   void InputBuffer::tick(float dt)
    180   {
    181     timeSinceKeyPressed_ += dt;
    182     if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_)
    183     {
    184       // initial time out has gone by, start repeating keys
    185       while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_)
    186       {
    187         timeSinceKeyRepeated_ += keyRepeatTime_;
    188         keysToRepeat_++;
    189       }
    190     }
    191   }
    192 
    193   void InputBuffer::keyPressed(const KeyEvent &evt)
    194   {
    195     lastKey_ = evt.key;
    196     timeSinceKeyPressed_ = 0.0;
    197     timeSinceKeyRepeated_ = keyRepeatDeleay_;
    198     keysToRepeat_ = 0;
    199 
    200     processKey(evt);
    201   }
    202 
    203   void InputBuffer::keyHeld(const KeyEvent& evt)
    204   {
    205     if (evt.key == lastKey_)
    206     {
    207       while (keysToRepeat_)
    208       {
     39    InputBuffer::InputBuffer()
     40    {
     41        RegisterObject(InputBuffer);
     42
     43        this->buffer_ = "";
     44        this->cursor_ = 0;
     45        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyz \
     46                               ABCDEFGHIJKLMNOPQRSTUVWXYZ \
     47                               äëïöüÄËÏÖÜáâàéêèíîìóôòúûù \
     48                               0123456789 \
     49                               \\\"(){}[]<>.:,;_-+*/=!?|$&%^~#";
     50
     51        this->lastKey_ = KeyCode::Unassigned;
     52        this->timeSinceKeyPressed_ = 0.0f;
     53        this->timeSinceKeyRepeated_ = 0.0f;
     54        this->keysToRepeat_ = 0;
     55
     56        setConfigValues();
     57    }
     58
     59    InputBuffer::InputBuffer(const std::string allowedChars)
     60    {
     61        RegisterObject(InputBuffer);
     62
     63        this->allowedChars_ = allowedChars;
     64        this->buffer_ = "";
     65        this->cursor_ = 0;
     66
     67        this->lastKey_ = KeyCode::Unassigned;
     68        this->timeSinceKeyPressed_ = 0.0f;
     69        this->timeSinceKeyRepeated_ = 0.0f;
     70        this->keysToRepeat_ = 0;
     71
     72        setConfigValues();
     73    }
     74
     75    void InputBuffer::setConfigValues()
     76    {
     77        SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer");
     78        SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer");
     79
     80        if (keyRepeatDeleay_ < 0.0)
     81        {
     82            ResetConfigValue(keyRepeatDeleay_);
     83        }
     84        if (keyRepeatTime_ < 0.0)
     85        {
     86            ResetConfigValue(keyRepeatTime_);
     87        }
     88    }
     89
     90    void InputBuffer::set(const std::string& input, bool update)
     91    {
     92        this->clear(false);
     93        this->insert(input, update);
     94    }
     95
     96    void InputBuffer::insert(const std::string& input, bool update)
     97    {
     98        for (unsigned int i = 0; i < input.size(); ++i)
     99        {
     100            this->insert(input[i], false);
     101
     102            if (update)
     103                this->updated(input[i], false);
     104        }
     105
     106        if (update)
     107            this->updated();
     108    }
     109
     110    void InputBuffer::insert(const char& input, bool update)
     111    {
     112        if (this->charIsAllowed(input))
     113        {
     114            this->buffer_.insert(this->cursor_, 1, input);
     115            ++this->cursor_;
     116        }
     117
     118        if (update)
     119            this->updated(input, true);
     120    }
     121
     122    void InputBuffer::clear(bool update)
     123    {
     124        this->buffer_ = "";
     125        this->cursor_ = 0;
     126
     127        if (update)
     128            this->updated();
     129    }
     130
     131    void InputBuffer::removeBehindCursor(bool update)
     132    {
     133        if (this->cursor_ > 0)
     134        {
     135            --this->cursor_;
     136            this->buffer_.erase(this->cursor_, 1);
     137
     138            if (update)
     139                this->updated();
     140        }
     141    }
     142
     143    void InputBuffer::removeAtCursor(bool update)
     144    {
     145        if (this->cursor_ < this->buffer_.size())
     146        {
     147            this->buffer_.erase(this->cursor_, 1);
     148
     149            if (update)
     150                this->updated();
     151        }
     152    }
     153
     154    void InputBuffer::updated()
     155    {
     156        for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     157        {
     158            if ((*it)->bListenToAllChanges_)
     159                (*it)->callFunction();
     160        }
     161    }
     162
     163    void InputBuffer::updated(const char& update, bool bSingleInput)
     164    {
     165        for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     166        {
     167            if ((!(*it)->trueKeyFalseChar_) && ((*it)->bListenToAllChanges_ || ((*it)->char_ == update)) && (!(*it)->bOnlySingleInput_ || bSingleInput))
     168                (*it)->callFunction();
     169        }
     170    }
     171
     172    bool InputBuffer::charIsAllowed(const char& input)
     173    {
     174        if (this->allowedChars_ == "")
     175            return true;
     176        else
     177            return (this->allowedChars_.find(input) != std::string::npos);
     178    }
     179
     180
     181    void InputBuffer::processKey(const KeyEvent &evt)
     182    {
     183        if (evt.isModifierDown(KeyboardModifier::Alt) && evt.key == KeyCode::Tab)
     184            return;
     185
     186        for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     187        {
     188            if ((*it)->trueKeyFalseChar_ && ((*it)->key_ == evt.key))
     189                (*it)->callFunction();
     190        }
     191
     192        if (evt.isModifierDown(KeyboardModifier::Ctrl))
     193        {
     194            if (evt.key == KeyCode::V)
     195                this->insert(fromClipboard());
     196            else if (evt.key == KeyCode::C)
     197                toClipboard(this->buffer_);
     198            else if (evt.key == KeyCode::X)
     199            {
     200                toClipboard(this->buffer_);
     201                this->clear();
     202            }
     203        }
     204        else if (evt.isModifierDown(KeyboardModifier::Shift))
     205        {
     206            if (evt.key == KeyCode::Insert)
     207                this->insert(fromClipboard());
     208            else if (evt.key == KeyCode::Delete)
     209            {
     210                toClipboard(this->buffer_);
     211                this->clear();
     212            }
     213        }
     214
     215        this->insert((char)evt.text);
     216    }
     217
     218    /**
     219        @brief This tick() function is called by the InputManager if the InputBuffer is active.
     220        @param dt Delta time
     221    */
     222    void InputBuffer::tickInput(float dt, const HandlerState& state)
     223    {
     224        timeSinceKeyPressed_ += dt;
     225        if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_)
     226        {
     227            // initial time out has gone by, start repeating keys
     228            while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_)
     229            {
     230                timeSinceKeyRepeated_ += keyRepeatTime_;
     231                keysToRepeat_++;
     232            }
     233        }
     234    }
     235
     236    void InputBuffer::keyPressed(const KeyEvent &evt)
     237    {
     238        lastKey_ = evt.key;
     239        timeSinceKeyPressed_ = 0.0;
     240        timeSinceKeyRepeated_ = keyRepeatDeleay_;
     241        keysToRepeat_ = 0;
     242
    209243        processKey(evt);
    210         keysToRepeat_--;
    211       }
    212     }
    213   }
    214 
     244    }
     245
     246    void InputBuffer::keyHeld(const KeyEvent& evt)
     247    {
     248        if (evt.key == lastKey_)
     249        {
     250            while (keysToRepeat_)
     251            {
     252                processKey(evt);
     253                keysToRepeat_--;
     254            }
     255        }
     256    }
    215257}
  • code/trunk/src/core/InputBuffer.h

    r1349 r1502  
    3636
    3737#include "InputInterfaces.h"
    38 #include "Tickable.h"
     38#include "OrxonoxClass.h"
    3939
    4040namespace orxonox
    4141{
    42   class _CoreExport InputBufferListener
    43   {};
    44 
    45   class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass
    46   {
    47     struct InputBufferListenerTuple
     42    class BaseInputBufferListenerTuple
    4843    {
    49       InputBufferListener* listener_;
    50       void (InputBufferListener::*function_)();
    51       bool bListenToAllChanges_;
    52       bool bOnlySingleInput_;
    53       char char_;
     44    public:
     45        BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput,
     46            bool trueKeyFalseChar, char _char, KeyCode::Enum key)
     47            : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput),
     48              trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key)
     49        { }
     50        virtual ~BaseInputBufferListenerTuple() { }
     51        virtual void callFunction() = 0;
     52        bool bListenToAllChanges_;
     53        bool bOnlySingleInput_;
     54        bool trueKeyFalseChar_;
     55        char char_;
     56        KeyCode::Enum key_;
    5457    };
    5558
    56   public:
    57     InputBuffer(const std::string allowedChars =
    58       "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^");
     59    template <class T>
     60    class InputBufferListenerTuple : public BaseInputBufferListenerTuple
     61    {
     62    public:
     63        InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges,
     64            bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key)
     65            : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key),
     66              listener_(listener), function_(function)
     67        { }
     68        virtual ~InputBufferListenerTuple() { }
     69        void callFunction()
     70        {
     71            (listener_->*function_)();
     72        }
     73        T* listener_;
     74        void (T::*function_)();
     75    };
    5976
    60     void setConfigValues();
     77    class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass
     78    {
     79        public:
     80            InputBuffer();
     81            InputBuffer(const std::string allowedChars);
    6182
    62     template <class T>
    63     void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput)
    64     {
    65       struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '};
    66       this->listeners_.insert(this->listeners_.end(), newListener);
    67     }
    68     template <class T>
    69     void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput)
    70     {
    71       struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '};
    72       this->listeners_.insert(this->listeners_.end(), newListener);
    73     }
     83            void setConfigValues();
    7484
    75     template <class T>
    76     void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput)
    77     {
    78       struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};
    79       this->listeners_.insert(this->listeners_.end(), newListener);
    80     }
    81     template <class T>
    82     void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput)
    83     {
    84       struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};
    85       this->listeners_.insert(this->listeners_.end(), newListener);
    86     }
     85            template <class T>
     86            void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput)
     87            {
     88                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned);
     89                this->listeners_.insert(this->listeners_.end(), newTuple);
     90            }
     91            template <class T>
     92            void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput)
     93            {
     94                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned);
     95                this->listeners_.insert(this->listeners_.end(), newTuple);
     96            }
     97            template <class T>
     98            void registerListener(T* listener, void (T::*function)(), char _char, bool bOnlySingleInput)
     99            {
     100                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned);
     101                this->listeners_.insert(this->listeners_.end(), newTuple);
     102            }
     103            template <class T>
     104            void registerListener(T* listener, void (T::*function)() const, char _char, bool bOnlySingleInput)
     105            {
     106                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned);
     107                this->listeners_.insert(this->listeners_.end(), newTuple);
     108            }
    87109
    88     void set(const std::string& input);
    89     void append(const std::string& input);
    90     void append(const char& input);
    91     void removeLast();
    92     void clear();
     110            template <class T>
     111            void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key)
     112            {
     113                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);
     114                this->listeners_.insert(this->listeners_.end(), newTuple);
     115            }
     116            template <class T>
     117            void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key)
     118            {
     119                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);
     120                this->listeners_.insert(this->listeners_.end(), newTuple);
     121            }
    93122
    94     void updated();
    95     void updated(const char& update, bool bSingleInput);
     123            template <class T>
     124            void unregisterListener(T* listener)
     125            {
     126                for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
     127                {
     128                    InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it);
     129                    if (refListener && refListener->listener_ == listener)
     130                        this->listeners_.erase(it++);
     131                    else
     132                        it++;
     133                }
     134            }
    96135
    97     inline std::string get() const
    98     { return this->buffer_; }
     136            void set(const std::string& input, bool update = true);
     137            void insert(const std::string& input, bool update = true);
     138            void insert(const char& input, bool update = true);
     139            void clear(bool update = true);
     140            void removeAtCursor(bool update = true);
     141            void removeBehindCursor(bool update = true);
    99142
    100   private:  // functions
    101     bool charIsAllowed(const char& input);
     143            void updated();
     144            void updated(const char& update, bool bSingleInput);
    102145
    103     void keyPressed (const KeyEvent& evt);
    104     void keyReleased(const KeyEvent& evt) { }
    105     void keyHeld    (const KeyEvent& evt);
    106     void processKey (const KeyEvent &e);
     146            inline std::string get() const
     147                { return this->buffer_; }
     148            inline unsigned int getSize() const
     149                { return this->buffer_.size(); }
    107150
    108     void tick(float dt);
     151            inline unsigned int getCursorPosition() const
     152                { return this->cursor_; }
     153            inline void setCursorPosition(unsigned int cursor)
     154                { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } }
     155            inline void setCursorToEnd()
     156                { this->cursor_ = this->buffer_.size(); }
     157            inline void setCursorToBegin()
     158                { this->cursor_ = 0; }
     159            inline void increaseCursor()
     160                { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } }
     161            inline void decreaseCursor()
     162                { if (this->cursor_ > 0) { --this->cursor_; } }
    109163
    110   private: // variables
    111     std::string buffer_;
    112     std::list<InputBufferListenerTuple> listeners_;
    113     std::string allowedChars_;
     164        private:
     165            bool charIsAllowed(const char& input);
    114166
    115     KeyCode::Enum lastKey_;
    116     float timeSinceKeyPressed_;
    117     float timeSinceKeyRepeated_;
    118     int keysToRepeat_;
     167            void keyPressed (const KeyEvent& evt);
     168            void keyReleased(const KeyEvent& evt) { }
     169            void keyHeld    (const KeyEvent& evt);
     170            void processKey (const KeyEvent &e);
    119171
    120     // configured values
    121     float keyRepeatDeleay_;
    122     float keyRepeatTime_;
    123   };
     172            void tickInput(float dt, const HandlerState& state);
     173
     174            std::string buffer_;
     175            std::list<BaseInputBufferListenerTuple*> listeners_;
     176            std::string allowedChars_;
     177            unsigned int cursor_;
     178
     179            KeyCode::Enum lastKey_;
     180            float timeSinceKeyPressed_;
     181            float timeSinceKeyRepeated_;
     182            int keysToRepeat_;
     183
     184            float keyRepeatDeleay_;
     185            float keyRepeatTime_;
     186    };
    124187}
    125188
  • code/trunk/src/core/InputInterfaces.h

    r1349 r1502  
    254254                std::vector<Vector3> mVectors;
    255255  };*/
     256 
     257  /**
     258  * Helper struct to determine which handlers of an object (can implement
     259  * multiple handlers) are active.
     260  */
     261  struct HandlerState
     262  {
     263    HandlerState() : key(false), mouse(false), joyStick(false) { }
     264    bool key;
     265    bool mouse;
     266    bool joyStick;
     267  };
    256268
    257269  class _CoreExport InputTickable
     
    259271  public:
    260272    virtual ~InputTickable() { }
    261     virtual void tick(float dt) = 0;
     273    virtual void tickInput(float dt, const HandlerState& state) = 0;
    262274  };
    263275
     
    272284    virtual void keyReleased(const KeyEvent& evt) = 0;
    273285    virtual void keyHeld    (const KeyEvent& evt) = 0;
     286    //virtual void tickKey    (float dt) { }
    274287  };
    275288
     
    286299    virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    287300    virtual void mouseScrolled      (int abs, int rel)     = 0;
     301    //virtual void tickMouse          (float dt) { }
    288302  };
    289303
     
    299313    virtual void joyStickButtonReleased(int joyStickID, int button) = 0;
    300314    virtual void joyStickButtonHeld    (int joyStickID, int button) = 0;
    301     virtual void joyStickAxisMoved     (int joyStickID, int axis, int value) = 0;
     315    virtual void joyStickAxisMoved     (int joyStickID, int axis, float value) = 0;
    302316    //virtual bool joyStickVector3Moved  (int joyStickID, int index /*, fill list*/) {return true;}
     317    //virtual void tickJoyStick          (float dt) { }
    303318  };
    304319
  • code/trunk/src/core/InputManager.cc

    r1349 r1502  
    3434
    3535#include "InputManager.h"
     36#include "util/Convert.h"
    3637#include "CoreIncludes.h"
     38#include "ConfigValueIncludes.h"
    3739#include "Debug.h"
    3840#include "InputBuffer.h"
    39 #include "InputHandler.h"
     41#include "KeyBinder.h"
     42#include "CommandExecutor.h"
     43#include "ConsoleCommand.h"
     44#include "Shell.h"
    4045
    4146namespace orxonox
    4247{
     48  SetConsoleCommandShortcut(InputManager, keyBind);
     49  SetConsoleCommandShortcut(InputManager, storeKeyStroke);
     50  SetConsoleCommandShortcut(InputManager, calibrate);
     51
    4352  // ###############################
    4453  // ###    Internal Methods     ###
     
    5362      inputSystem_(0), keyboard_(0), mouse_(0),
    5463      joySticksSize_(0),
    55       state_(IS_UNINIT), stateRequest_(IS_UNINIT),
     64      keyBinder_(0), keyDetector_(0), buffer_(0), calibratorCallback_(0),
     65      state_(IS_UNINIT), stateRequest_(IS_UNINIT), savedState_(IS_UNINIT),
    5666      keyboardModifiers_(0)
    5767  {
     
    129139      if (mouse_)
    130140      {
    131         //// hack the mouse position
    132         //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2;
    133         //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2;
    134141        setWindowExtents(windowWidth, windowHeight);
    135142      }
     
    137144      state_ = IS_NONE;
    138145      CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl;
     146
     147      // InputManager holds the input buffer --> create one and add it.
     148      buffer_ = new InputBuffer();
     149      addKeyHandler(buffer_, "buffer");
     150      Shell::getInstance().setInputBuffer(buffer_);
     151
     152      keyBinder_ = new KeyBinder();
     153      keyBinder_->loadBindings();
     154      addKeyHandler(keyBinder_, "keybinder");
     155      addMouseHandler(keyBinder_, "keybinder");
     156      addJoyStickHandler(keyBinder_, "keybinder");
     157
     158      keyDetector_ = new KeyDetector();
     159      keyDetector_->loadBindings();
     160      addKeyHandler(keyDetector_, "keydetector");
     161      addMouseHandler(keyDetector_, "keydetector");
     162      addJoyStickHandler(keyDetector_, "keydetector");
     163
     164      calibratorCallback_ = new CalibratorCallback();
     165      addKeyHandler(calibratorCallback_, "calibratorcallback");
     166
     167      setConfigValues();
     168
     169      CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
    139170    }
    140171    else
     
    142173      CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;
    143174    }
    144 
    145     // InputManager holds the input buffer --> create one and add it.
    146     addKeyHandler(new InputBuffer(), "buffer");
    147 
    148     KeyBinder* binder = new KeyBinder();
    149     binder->loadBindings();
    150     addKeyHandler(binder, "keybinder");
    151     addMouseHandler(binder, "keybinder");
    152     addJoyStickHandler(binder, "keybinder");
    153 
    154     // Read all the key bindings and assign them
    155     //if (!_loadBindings())
    156     //  return false;
    157 
    158     CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
    159175    return true;
    160176  }
     
    216232        // register our listener in OIS.
    217233        mouse_->setEventCallback(this);
    218         CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
     234        CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl;
    219235        return true;
    220236      }
     
    276292    povStates_.resize(joySticksSize_);
    277293    sliderStates_.resize(joySticksSize_);
     294    joySticksCalibration_.resize(joySticksSize_);
     295    for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++)
     296    {
     297      // reset the calibration with default values
     298      for (unsigned int i = 0; i < 24; i++)
     299      {
     300        joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f;
     301        joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f;
     302        joySticksCalibration_[iJoyStick].zeroStates[i] = 0;
     303      }
     304    }
    278305    return success;
    279306  }
    280307
    281308  /**
     309    @brief Sets the configurable values. Use keybindings.ini as file..
     310  */
     311  void InputManager::setConfigValues()
     312  {
     313    if (joySticksSize_)
     314    {
     315      std::vector<MultiTypeMath> coeffPos;
     316      std::vector<MultiTypeMath> coeffNeg;
     317      std::vector<MultiTypeMath> zero;
     318      coeffPos.resize(24);
     319      coeffNeg.resize(24);
     320      zero.resize(24);
     321      for (unsigned int i = 0; i < 24; i++)
     322      {
     323        coeffPos[i] =  1.0f/32767.0f;
     324        coeffNeg[i] =  1.0f/32768.0f;
     325        zero[i]     =  0;
     326      }
     327
     328      ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
     329      if (!cont)
     330      {
     331          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos);
     332          getIdentifier()->addConfigValueContainer("CoeffPos", cont);
     333      }
     334      cont->getValue(&coeffPos);
     335
     336      cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
     337      if (!cont)
     338      {
     339          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg);
     340          getIdentifier()->addConfigValueContainer("CoeffNeg", cont);
     341      }
     342      cont->getValue(&coeffNeg);
     343
     344      cont = getIdentifier()->getConfigValueContainer("Zero");
     345      if (!cont)
     346      {
     347          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero);
     348          getIdentifier()->addConfigValueContainer("Zero", cont);
     349      }
     350      cont->getValue(&zero);
     351
     352      // copy values to our own variables
     353      for (unsigned int i = 0; i < 24; i++)
     354      {
     355        joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i];
     356        joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i];
     357        joySticksCalibration_[0].zeroStates[i]    = zero[i];
     358      }
     359    }
     360  }
     361
     362  /**
    282363    @brief Destroys all the created input devices and sets the InputManager to construction state.
    283364  */
     
    288369      CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
    289370
    290       if (keyHandlers_.find("buffer") != keyHandlers_.end())
    291         delete keyHandlers_["buffer"];
    292 
    293       if (keyHandlers_.find("keybinder") != keyHandlers_.end())
    294         delete keyHandlers_["keybinder"];
     371      if (buffer_)
     372        delete buffer_;
     373
     374      if (keyBinder_)
     375        delete keyBinder_;
     376
     377      if (keyDetector_)
     378        delete keyDetector_;
     379
     380      if (calibratorCallback_)
     381        delete calibratorCallback_;
    295382
    296383      keyHandlers_.clear();
     
    301388      _destroyMouse();
    302389      _destroyJoySticks();
     390
     391      activeHandlers_.clear();
    303392
    304393      // inputSystem_ can never be 0, or else the code is mistaken
     
    355444      activeJoyStickHandlers_.clear();
    356445      joyStickButtonsDown_.clear();
     446      povStates_.clear();
     447      sliderStates_.clear();
     448      joySticksCalibration_.clear();
    357449    }
    358450    CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
    359451  }
    360452
     453  void InputManager::_saveState()
     454  {
     455    savedHandlers_.activeHandlers_ = activeHandlers_;
     456    savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_;
     457    savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_;
     458    savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_;
     459  }
     460
     461  void InputManager::_restoreState()
     462  {
     463    activeHandlers_ = savedHandlers_.activeHandlers_;
     464    activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_;
     465    activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_;
     466    activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_;
     467  }
     468
    361469  void InputManager::_updateTickables()
    362470  {
    363     // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
    364     std::set<InputTickable*> tempSet;
     471    // we can use a map to have a list of unique pointers (an object can implement all 3 handlers)
     472    std::map<InputTickable*, HandlerState> tempSet;
    365473    for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
    366       tempSet.insert(activeKeyHandlers_[iHandler]);
     474      tempSet[activeKeyHandlers_[iHandler]].joyStick = true;
    367475    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    368       tempSet.insert(activeMouseHandlers_[iHandler]);
     476      tempSet[activeMouseHandlers_[iHandler]].mouse = true;
    369477    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
    370478      for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    371         tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]);
    372 
    373     // copy the content of the set back to the actual vector
     479        tempSet[activeJoyStickHandlers_[iJoyStick][iHandler]].joyStick = true;
     480
     481    // copy the content of the map back to the actual vector
    374482    activeHandlers_.clear();
    375     for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++)
    376       activeHandlers_.push_back(*itHandler);
     483    for (std::map<InputTickable*, HandlerState>::const_iterator itHandler = tempSet.begin();
     484        itHandler != tempSet.end(); itHandler++)
     485      activeHandlers_.push_back(std::pair<InputTickable*, HandlerState>((*itHandler).first, (*itHandler).second));
    377486  }
    378487
     
    392501      return;
    393502
    394     // reset the game if it has changed
    395503    if (state_ != stateRequest_)
    396504    {
    397       if (stateRequest_ != IS_CUSTOM)
    398       {
     505      InputState sr = stateRequest_;
     506      switch (sr)
     507      {
     508      case IS_NORMAL:
    399509        activeKeyHandlers_.clear();
    400510        activeMouseHandlers_.clear();
     
    402512          activeJoyStickHandlers_[i].clear();
    403513
    404         switch (stateRequest_)
     514        // normal play mode
     515        // note: we assume that the handlers exist since otherwise, something's wrong anyway.
     516        enableKeyHandler("keybinder");
     517        enableMouseHandler("keybinder");
     518        enableJoyStickHandler("keybinder", 0);
     519        stateRequest_ = IS_NORMAL;
     520        state_ = IS_NORMAL;
     521        break;
     522
     523      case IS_GUI:
     524        state_ = IS_GUI;
     525        break;
     526
     527      case IS_CONSOLE:
     528        activeKeyHandlers_.clear();
     529        activeMouseHandlers_.clear();
     530        for (unsigned int i = 0; i < joySticksSize_; i++)
     531          activeJoyStickHandlers_[i].clear();
     532
     533        enableMouseHandler("keybinder");
     534        enableJoyStickHandler("keybinder", 0);
     535        enableKeyHandler("buffer");
     536        stateRequest_ = IS_CONSOLE;
     537        state_ = IS_CONSOLE;
     538        break;
     539
     540      case IS_DETECT:
     541        savedState_ = state_;
     542        _saveState();
     543
     544        activeKeyHandlers_.clear();
     545        activeMouseHandlers_.clear();
     546        for (unsigned int i = 0; i < joySticksSize_; i++)
     547          activeJoyStickHandlers_[i].clear();
     548
     549        enableKeyHandler("keydetector");
     550        enableMouseHandler("keydetector");
     551        enableJoyStickHandler("keydetector", 0);
     552
     553        stateRequest_ = IS_DETECT;
     554        state_ = IS_DETECT;
     555        break;
     556
     557      case IS_NODETECT:
     558        _restoreState();
     559        keysDown_.clear();
     560        mouseButtonsDown_.clear();
     561        joyStickButtonsDown_[0].clear();
     562        state_ = IS_NODETECT;
     563        stateRequest_ = savedState_;
     564        break;
     565
     566      case IS_CALIBRATE:
     567        if (joySticksSize_)
    405568        {
    406         case IS_NORMAL:
    407           // normal play mode
    408           // note: we assume that the handlers exist since otherwise, something's wrong anyway.
    409           enableKeyHandler("keybinder");
    410           enableMouseHandler("keybinder");
    411           enableMouseHandler("SpaceShip");
    412           enableJoyStickHandler("keybinder", 0);
    413           break;
    414 
    415         case IS_GUI:
    416           // TODO: do stuff
    417           break;
    418 
    419         case IS_CONSOLE:
    420           enableMouseHandler("keybinder");
    421           enableMouseHandler("SpaceShip");
    422           enableJoyStickHandler("keybinder", 0);
    423           enableKeyHandler("buffer");
    424           break;
    425 
    426         default:
    427           break;
     569          savedState_ = _getSingleton().state_;
     570          for (unsigned int i = 0; i < 24; i++)
     571          {
     572            marginalsMax_[i] = INT_MIN;
     573            marginalsMin_[i] = INT_MAX;
     574          }
     575          COUT(0) << "Move all joy stick axes in all directions a few times. "
     576            << "Then put all axes in zero state and hit enter." << std::endl;
     577
     578          savedState_ = state_;
     579          _saveState();
     580
     581          activeKeyHandlers_.clear();
     582          activeMouseHandlers_.clear();
     583          for (unsigned int i = 0; i < joySticksSize_; i++)
     584            activeJoyStickHandlers_[i].clear();
     585
     586          enableKeyHandler("calibratorcallback");
     587          stateRequest_ = IS_CALIBRATE;
     588          state_ = IS_CALIBRATE;
    428589        }
    429         state_ = stateRequest_;
     590        else
     591        {
     592          COUT(3) << "Connot calibrate, no joy stick found!" << std::endl;
     593          stateRequest_ = state_;
     594        }
     595        break;
     596
     597      case IS_NOCALIBRATE:
     598        _completeCalibration();
     599        _restoreState();
     600        keyBinder_->resetJoyStickAxes();
     601        state_ = IS_NOCALIBRATE;
     602        stateRequest_ = savedState_;
     603        break;
     604
     605      case IS_NONE:
     606        activeKeyHandlers_.clear();
     607        activeMouseHandlers_.clear();
     608        for (unsigned int i = 0; i < joySticksSize_; i++)
     609          activeJoyStickHandlers_[i].clear();
     610        state_ = IS_NONE;
     611
     612      default:
     613        break;
    430614      }
    431615    }
     
    439623      joySticks_[i]->capture();
    440624
    441 
    442     // call all the handlers for the held key events
    443     for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
    444       for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
    445         activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
    446 
    447     // call all the handlers for the held mouse button events
    448     for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    449       for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    450         activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    451 
    452     // call all the handlers for the held joy stick button events
    453     for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
    454       for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    455         for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    456           activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
    457 
    458 
    459     // call the ticks
     625    if (state_ != IS_CALIBRATE)
     626    {
     627      // call all the handlers for the held key events
     628      for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++)
     629        for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
     630          activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_));
     631
     632      // call all the handlers for the held mouse button events
     633      for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
     634        for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
     635          activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
     636
     637      // call all the handlers for the held joy stick button events
     638      for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
     639        for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
     640          for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     641            activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     642    }
     643
     644    // call the ticks for the handlers (need to be treated specially)
    460645    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
    461       activeHandlers_[iHandler]->tick(dt);
     646      activeHandlers_[iHandler].first->tickInput(dt, activeHandlers_[iHandler].second);
     647  }
     648
     649  void InputManager::_completeCalibration()
     650  {
     651    for (unsigned int i = 0; i < 24; i++)
     652    {
     653      // positive coefficient
     654      if (marginalsMax_[i] == INT_MIN)
     655        marginalsMax_[i] =  32767;
     656      // coefficients
     657      if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i])
     658        joySticksCalibration_[0].positiveCoeff[i] =  1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]);
     659      else
     660        joySticksCalibration_[0].positiveCoeff[i] =  1.0f;
     661
     662      // config value
     663      ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
     664      assert(cont);
     665      cont->set(i, joySticksCalibration_[0].positiveCoeff[i]);
     666
     667      // negative coefficient
     668      if (marginalsMin_[i] == INT_MAX)
     669        marginalsMin_[i] = -32768;
     670      // coefficients
     671      if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i])
     672        joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]);
     673      else
     674        joySticksCalibration_[0].negativeCoeff[i] =  1.0f;
     675      // config value
     676      cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
     677      assert(cont);
     678      cont->set(i, joySticksCalibration_[0].negativeCoeff[i]);
     679
     680      // zero states
     681      if (i < 8)
     682      {
     683        if (!(i & 1))
     684          joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX;
     685        else
     686          joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY;
     687      }
     688      else
     689      {
     690        if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size())
     691          joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs;
     692        else
     693          joySticksCalibration_[0].zeroStates[i] = 0;
     694      }
     695      // config value
     696      cont = getIdentifier()->getConfigValueContainer("Zero");
     697      assert(cont);
     698      cont->set(i, joySticksCalibration_[0].zeroStates[i]);
     699    }
    462700  }
    463701
     
    594832  // ###### Joy Stick Events ######
    595833
    596   bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     834  inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg)
    597835  {
    598836    // use the device to identify which one called the method
     
    600838    unsigned int iJoyStick = 0;
    601839    while (joySticks_[iJoyStick] != joyStick)
     840    {
    602841      iJoyStick++;
     842      if (iJoyStick == joySticksSize_)
     843      {
     844        CCOUT(3) << "Unknown joystick fired an event. This means there is a bug somewhere! Aborting." << std::endl;
     845        abort();
     846      }
     847    }
     848    return iJoyStick;
     849  }
     850
     851  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     852  {
     853    unsigned int iJoyStick = _getJoystick(arg);
    603854
    604855    // check whether the button already is in the list (can happen when focus was lost)
    605     std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
     856    std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
    606857    unsigned int iButton = 0;
    607858    while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
     
    618869  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
    619870  {
    620     // use the device to identify which one called the method
    621     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    622     unsigned int iJoyStick = 0;
    623     while (joySticks_[iJoyStick] != joyStick)
    624       iJoyStick++;
     871    unsigned int iJoyStick = _getJoystick(arg);
    625872
    626873    // remove the button from the joyStickButtonsDown_ list
    627     std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick];
     874    std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
    628875    for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
    629876    {
     
    641888  }
    642889
     890  void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value)
     891  {
     892    if (state_ == IS_CALIBRATE)
     893    {
     894      if (value > marginalsMax_[axis])
     895        marginalsMax_[axis] = value;
     896      if (value < marginalsMin_[axis])
     897        marginalsMin_[axis] = value;
     898    }
     899    else
     900    {
     901      float fValue = value - joySticksCalibration_[iJoyStick].zeroStates[axis];
     902      if (fValue > 0.0f)
     903        fValue *= joySticksCalibration_[iJoyStick].positiveCoeff[axis];
     904      else
     905        fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis];
     906
     907      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     908        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis, fValue);
     909    }
     910  }
     911
    643912  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    644913  {
    645     //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl;
    646     // use the device to identify which one called the method
    647     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    648     unsigned int iJoyStick = 0;
    649     while (joySticks_[iJoyStick] != joyStick)
    650       iJoyStick++;
     914    //if (arg.state.mAxes[axis].abs > 10000 || arg.state.mAxes[axis].abs < -10000)
     915    //{ CCOUT(3) << "axis " << axis << " moved" << arg.state.mAxes[axis].abs << std::endl;}
     916
     917    unsigned int iJoyStick = _getJoystick(arg);
    651918
    652919    // keep in mind that the first 8 axes are reserved for the sliders
    653     for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    654       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
     920    _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
    655921
    656922    return true;
     
    659925  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    660926  {
     927    //if (arg.state.mSliders[id].abX > 10000 || arg.state.mSliders[id].abX < -10000)
     928    //{CCOUT(3) << "slider " << id << " moved" << arg.state.mSliders[id].abX << std::endl;}
    661929    //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;
    662     // use the device to identify which one called the method
    663     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    664     unsigned int iJoyStick = 0;
    665     while (joySticks_[iJoyStick] != joyStick)
    666       iJoyStick++;
     930
     931    unsigned int iJoyStick = _getJoystick(arg);
    667932
    668933    if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX)
    669     {
    670       // slider X axis changed
    671       sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX;
    672       for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    673         activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX);
    674     }
     934      _fireAxis(iJoyStick, id * 2, arg.state.mSliders[id].abX);
    675935    else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY)
    676     {
    677       // slider Y axis changed
    678       sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY;
    679       for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    680         activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
    681     }
     936      _fireAxis(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
    682937
    683938    return true;
     
    686941  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
    687942  {
    688     // use the device to identify which one called the method
    689     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    690     unsigned int iJoyStick = 0;
    691     while (joySticks_[iJoyStick] != joyStick)
    692       iJoyStick++;
     943    unsigned int iJoyStick = _getJoystick(arg);
    693944
    694945    // translate the POV into 8 simple buttons
     
    702953    if (lastState & OIS::Pov::West)
    703954      buttonReleased(arg, 32 + id * 4 + 3);
    704    
     955
    705956    povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction;
     957
    706958    int currentState = povStates_[iJoyStick][id];
    707959    if (currentState & OIS::Pov::North)
     
    719971  /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
    720972  {
    721     // use the device to identify which one called the method
    722     OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
    723     unsigned int iJoyStick = 0;
    724     while (joySticks_[iJoyStick] != joyStick)
    725       iJoyStick++;
     973    unsigned int iJoyStick = _getJoystick(arg);
    726974
    727975    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     
    737985  // ################################
    738986
     987  std::string InputManager::bindingCommmandString_s = "";
     988
    739989  bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,
    740990    bool createKeyboard, bool createMouse, bool createJoySticks)
     
    7801030  }
    7811031
    782   bool InputManager::isKeyDown(KeyCode::Enum key)
     1032  /*bool InputManager::isKeyDown(KeyCode::Enum key)
    7831033  {
    7841034    if (_getSingleton().keyboard_)
     
    7861036    else
    7871037      return false;
    788   }
    789 
    790   bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
     1038  }*/
     1039
     1040  /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
    7911041  {
    7921042    if (_getSingleton().keyboard_)
     
    7941044    else
    7951045      return false;
    796   }
     1046  }*/
    7971047
    7981048  /*const MouseState InputManager::getMouseState()
     
    8111061      return JoyStickState();
    8121062  }*/
    813 
    8141063
    8151064  void InputManager::destroy()
     
    8701119  }
    8711120
     1121  void InputManager::storeKeyStroke(const std::string& name)
     1122  {
     1123    setInputState(IS_NODETECT);
     1124    COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl;
     1125    CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false);
     1126  }
     1127
     1128  void InputManager::keyBind(const std::string& command)
     1129  {
     1130    bindingCommmandString_s = command;
     1131    setInputState(IS_DETECT);
     1132    COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
     1133  }
     1134
     1135  void InputManager::calibrate()
     1136  {
     1137    _getSingleton().setInputState(IS_CALIBRATE);
     1138  }
    8721139
    8731140  // ###### KeyHandler ######
  • code/trunk/src/core/InputManager.h

    r1349 r1502  
    6565  public:
    6666    IntVector2 sliderStates[4];
     67  };
     68
     69  /**
     70  * Struct for storing a custom input state
     71  */
     72  struct StoredState
     73  {
     74    std::vector<KeyHandler*>                    activeKeyHandlers_;
     75    std::vector<MouseHandler*>                  activeMouseHandlers_;
     76    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
     77    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
     78  };
     79
     80  struct JoyStickCalibration
     81  {
     82    int zeroStates[24];
     83    float positiveCoeff[24];
     84    float negativeCoeff[24];
    6785  };
    6886
     
    8098    enum InputState
    8199    {
    82       IS_UNINIT,  //!< InputManager has not yet been initialised.
    83       IS_NONE,    //!< Input is discarded.
    84       IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
    85       IS_GUI,     //!< All OIS input events are passed to CEGUI.
    86       IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
    87       IS_CUSTOM   //!< Any possible configuration.
     100      IS_UNINIT,    //!< InputManager has not yet been initialised.
     101      IS_NONE,      //!< Input is discarded.
     102      IS_NORMAL,    //!< Normal play state. Key and button bindings are active.
     103      IS_GUI,       //!< All OIS input events are passed to CEGUI.
     104      IS_CONSOLE,   //!< Keyboard input is redirected to the InputBuffer.
     105      IS_DETECT,    //!< All the input additionally goes to the KeyDetector
     106      IS_NODETECT,  //!< remove KeyDetector
     107      IS_NOCALIBRATE,
     108      IS_CALIBRATE,
     109      IS_CUSTOM     //!< Any possible configuration.
    88110    };
     111
     112  public: // member functions
     113    void setConfigValues();
    89114
    90115  public: // static functions
     
    103128    static void destroyJoySticks();
    104129
    105     static bool isModifierDown(KeyboardModifier::Enum modifier);
    106     static bool isKeyDown(KeyCode::Enum key);
     130    //static bool isModifierDown(KeyboardModifier::Enum modifier);
     131    //static bool isKeyDown(KeyCode::Enum key);
    107132    //static const MouseState getMouseState();
    108133    //static const JoyStickState getJoyStickState(unsigned int ID);
     
    112137    static void setInputState(const InputState state);
    113138    static InputState getInputState();
     139
     140    static void storeKeyStroke(const std::string& name);
     141    static void keyBind(const std::string& command);
     142
     143    static void calibrate();
    114144
    115145    static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
     
    152182
    153183    void _updateTickables();
     184
     185    void _saveState();
     186    void _restoreState();
     187
     188    void _completeCalibration();
     189
     190    void _fireAxis(unsigned int iJoyStick, int axis, int value);
     191    unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
    154192
    155193    void tick(float dt);
     
    172210
    173211  private: // variables
    174     OIS::InputManager*                          inputSystem_; //!< OIS input manager
    175     OIS::Keyboard*                              keyboard_;    //!< OIS mouse
    176     OIS::Mouse*                                 mouse_;       //!< OIS keyboard
    177     std::vector<OIS::JoyStick*>                 joySticks_;   //!< OIS joy sticks
     212    OIS::InputManager*                          inputSystem_;     //!< OIS input manager
     213    OIS::Keyboard*                              keyboard_;        //!< OIS mouse
     214    OIS::Mouse*                                 mouse_;           //!< OIS keyboard
     215    std::vector<OIS::JoyStick*>                 joySticks_;       //!< OIS joy sticks
    178216    unsigned int                                joySticksSize_;
     217
     218    KeyBinder*                                  keyBinder_;       //!< KeyBinder instance
     219    KeyDetector*                                keyDetector_;     //!< KeyDetector instance
     220    InputBuffer*                                buffer_;          //!< InputBuffer instance
     221    CalibratorCallback*                         calibratorCallback_;
    179222
    180223    InputState state_;
    181224    InputState stateRequest_;
     225    InputState savedState_;
    182226    unsigned int keyboardModifiers_;
     227    StoredState savedHandlers_;
     228
     229    // joystick calibration
     230    //std::vector<int> marginalsMaxConfig_;
     231    //std::vector<int> marginalsMinConfig_;
     232    int marginalsMax_[24];
     233    int marginalsMin_[24];
     234    bool bCalibrated_;
    183235
    184236    //! Keeps track of the joy stick POV states
     
    186238    //! Keeps track of the possibly two slider axes
    187239    std::vector<SliderStates>                   sliderStates_;
     240    std::vector<JoyStickCalibration>            joySticksCalibration_;
    188241
    189242    std::map<std::string, KeyHandler*>          keyHandlers_;
     
    194247    std::vector<MouseHandler*>                  activeMouseHandlers_;
    195248    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
    196     std::vector<InputTickable*>                activeHandlers_;
     249    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
    197250
    198251    std::vector<Key>                            keysDown_;
     
    200253    std::vector<std::vector<int> >              joyStickButtonsDown_;
    201254
     255    static std::string                          bindingCommmandString_s;
    202256  };
    203257
  • code/trunk/src/core/Iterator.h

    r1063 r1502  
    5050
    5151#include "ObjectList.h"
    52 #include "Debug.h"
    5352
    5453namespace orxonox
  • code/trunk/src/core/Language.cc

    r1062 r1502  
    3737
    3838#include "CoreSettings.h"
     39
     40#include "Debug.h"
    3941
    4042namespace orxonox
  • code/trunk/src/core/Language.h

    r1064 r1502  
    5050#include <map>
    5151#include <string>
    52 
    5352
    5453#define AddLanguageEntry(label, fallbackstring) \
  • code/trunk/src/core/OrxonoxClass.cc

    r1293 r1502  
    3333
    3434#include "OrxonoxClass.h"
     35#include "MetaObjectList.h"
     36#include "Identifier.h"
    3537
    3638namespace orxonox
     
    4143      parents_(0)
    4244    {
     45        this->metaList_ = new MetaObjectList();
     46
    4347        this->setConfigValues();
    4448    }
     
    4751    OrxonoxClass::~OrxonoxClass()
    4852    {
     53        delete this->metaList_;
     54
    4955        // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
    5056        if (this->parents_)
    5157            delete this->parents_;
    5258    }
     59
     60    /** @brief Returns true if the objects class is of the given type or a derivative. */
     61    bool OrxonoxClass::isA(const Identifier* identifier)
     62        { return this->getIdentifier()->isA(identifier); }
     63    /** @brief Returns true if the objects class is exactly of the given type. */
     64    bool OrxonoxClass::isExactlyA(const Identifier* identifier)
     65        { return this->getIdentifier()->isExactlyA(identifier); }
     66    /** @brief Returns true if the objects class is a child of the given type. */
     67    bool OrxonoxClass::isChildOf(const Identifier* identifier)
     68        { return this->getIdentifier()->isChildOf(identifier); }
     69    /** @brief Returns true if the objects class is a direct child of the given type. */
     70    bool OrxonoxClass::isDirectChildOf(const Identifier* identifier)
     71        { return this->getIdentifier()->isDirectChildOf(identifier); }
     72    /** @brief Returns true if the objects class is a parent of the given type. */
     73    bool OrxonoxClass::isParentOf(const Identifier* identifier)
     74        { return this->getIdentifier()->isParentOf(identifier); }
     75    /** @brief Returns true if the objects class is a direct parent of the given type. */
     76    bool OrxonoxClass::isDirectParentOf(const Identifier* identifier)
     77        { return this->getIdentifier()->isDirectParentOf(identifier); }
     78
     79
     80    /** @brief Returns true if the objects class is of the given type or a derivative. */
     81    bool OrxonoxClass::isA(const SubclassIdentifier<class B>* identifier)
     82        { return this->getIdentifier()->isA(identifier->getIdentifier()); }
     83    /** @brief Returns true if the objects class is exactly of the given type. */
     84    bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B>* identifier)
     85        { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }
     86    /** @brief Returns true if the objects class is a child of the given type. */
     87    bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B>* identifier)
     88        { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
     89    /** @brief Returns true if the objects class is a direct child of the given type. */
     90    bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B>* identifier)
     91        { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }
     92    /** @brief Returns true if the objects class is a parent of the given type. */
     93    bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B>* identifier)
     94        { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
     95    /** @brief Returns true if the objects class is a direct parent of the given type. */
     96    bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B>* identifier)
     97        { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }
     98
     99
     100    /** @brief Returns true if the objects class is of the given type or a derivative. */
     101    bool OrxonoxClass::isA(const SubclassIdentifier<class B> identifier)
     102        { return this->getIdentifier()->isA(identifier.getIdentifier()); }
     103    /** @brief Returns true if the objects class is exactly of the given type. */
     104    bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B> identifier)
     105        { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }
     106    /** @brief Returns true if the objects class is a child of the given type. */
     107    bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B> identifier)
     108        { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
     109    /** @brief Returns true if the objects class is a direct child of the given type. */
     110    bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B> identifier)
     111        { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }
     112    /** @brief Returns true if the objects class is a parent of the given type. */
     113    bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B> identifier)
     114        { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
     115    /** @brief Returns true if the objects class is a direct parent of the given type. */
     116    bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B> identifier)
     117        { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }
     118
     119
     120    /** @brief Returns true if the objects class is of the given type or a derivative. */
     121    bool OrxonoxClass::isA(const OrxonoxClass* object)
     122        { return this->getIdentifier()->isA(object->getIdentifier()); }
     123    /** @brief Returns true if the objects class is exactly of the given type. */
     124    bool OrxonoxClass::isExactlyA(const OrxonoxClass* object)
     125        { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
     126    /** @brief Returns true if the objects class is a child of the given type. */
     127    bool OrxonoxClass::isChildOf(const OrxonoxClass* object)
     128        { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
     129    /** @brief Returns true if the objects class is a direct child of the given type. */
     130    bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object)
     131        { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
     132    /** @brief Returns true if the objects class is a parent of the given type. */
     133    bool OrxonoxClass::isParentOf(const OrxonoxClass* object)
     134        { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
     135    /** @brief Returns true if the objects class is a direct child of the given type. */
     136    bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object)
     137        { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
    53138}
  • code/trunk/src/core/OrxonoxClass.h

    r1062 r1502  
    4343#include <string>
    4444
    45 #include "MetaObjectList.h"
    46 #include "Iterator.h"
    47 
    4845namespace orxonox
    4946{
     
    7572
    7673            /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */
    77             inline MetaObjectList& getMetaList() { return this->metaList_; }
     74            inline MetaObjectList& getMetaList() { return (*this->metaList_); }
    7875
    7976
    80             /** @brief Returns true if the objects class is of the given type or a derivative. */
    81             inline bool isA(const Identifier* identifier)
    82                 { return this->getIdentifier()->isA(identifier); }
    83             /** @brief Returns true if the objects class is exactly of the given type. */
    84             inline bool isExactlyA(const Identifier* identifier)
    85                 { return this->getIdentifier()->isExactlyA(identifier); }
    86             /** @brief Returns true if the objects class is a child of the given type. */
    87             inline bool isChildOf(const Identifier* identifier)
    88                 { return this->getIdentifier()->isChildOf(identifier); }
    89             /** @brief Returns true if the objects class is a direct child of the given type. */
    90             inline bool isDirectChildOf(const Identifier* identifier)
    91                 { return this->getIdentifier()->isDirectChildOf(identifier); }
    92             /** @brief Returns true if the objects class is a parent of the given type. */
    93             inline bool isParentOf(const Identifier* identifier)
    94                 { return this->getIdentifier()->isParentOf(identifier); }
    95             /** @brief Returns true if the objects class is a direct parent of the given type. */
    96             inline bool isDirectParentOf(const Identifier* identifier)
    97                 { return this->getIdentifier()->isDirectParentOf(identifier); }
     77            bool isA(const Identifier* identifier);
     78            bool isExactlyA(const Identifier* identifier);
     79            bool isChildOf(const Identifier* identifier);
     80            bool isDirectChildOf(const Identifier* identifier);
     81            bool isParentOf(const Identifier* identifier);
     82            bool isDirectParentOf(const Identifier* identifier);
    9883
     84            bool isA(const SubclassIdentifier<class B>* identifier);
     85            bool isExactlyA(const SubclassIdentifier<class B>* identifier);
     86            bool isChildOf(const SubclassIdentifier<class B>* identifier);
     87            bool isDirectChildOf(const SubclassIdentifier<class B>* identifier);
     88            bool isParentOf(const SubclassIdentifier<class B>* identifier);
     89            bool isDirectParentOf(const SubclassIdentifier<class B>* identifier);
    9990
    100             /** @brief Returns true if the objects class is of the given type or a derivative. */
    101             inline bool isA(const SubclassIdentifier<class B>* identifier)
    102                 { return this->getIdentifier()->isA(identifier->getIdentifier()); }
    103             /** @brief Returns true if the objects class is exactly of the given type. */
    104             inline bool isExactlyA(const SubclassIdentifier<class B>* identifier)
    105                 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }
    106             /** @brief Returns true if the objects class is a child of the given type. */
    107             inline bool isChildOf(const SubclassIdentifier<class B>* identifier)
    108                 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }
    109             /** @brief Returns true if the objects class is a direct child of the given type. */
    110             inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier)
    111                 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }
    112             /** @brief Returns true if the objects class is a parent of the given type. */
    113             inline bool isParentOf(const SubclassIdentifier<class B>* identifier)
    114                 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }
    115             /** @brief Returns true if the objects class is a direct parent of the given type. */
    116             inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier)
    117                 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }
     91            bool isA(const SubclassIdentifier<class B> identifier);
     92            bool isExactlyA(const SubclassIdentifier<class B> identifier);
     93            bool isChildOf(const SubclassIdentifier<class B> identifier);
     94            bool isDirectChildOf(const SubclassIdentifier<class B> identifier);
     95            bool isParentOf(const SubclassIdentifier<class B> identifier);
     96            bool isDirectParentOf(const SubclassIdentifier<class B> identifier);
    11897
    119 
    120             /** @brief Returns true if the objects class is of the given type or a derivative. */
    121             inline bool isA(const SubclassIdentifier<class B> identifier)
    122                 { return this->getIdentifier()->isA(identifier.getIdentifier()); }
    123             /** @brief Returns true if the objects class is exactly of the given type. */
    124             inline bool isExactlyA(const SubclassIdentifier<class B> identifier)
    125                 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }
    126             /** @brief Returns true if the objects class is a child of the given type. */
    127             inline bool isChildOf(const SubclassIdentifier<class B> identifier)
    128                 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }
    129             /** @brief Returns true if the objects class is a direct child of the given type. */
    130             inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier)
    131                 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }
    132             /** @brief Returns true if the objects class is a parent of the given type. */
    133             inline bool isParentOf(const SubclassIdentifier<class B> identifier)
    134                 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }
    135             /** @brief Returns true if the objects class is a direct parent of the given type. */
    136             inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier)
    137                 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }
    138 
    139 
    140             /** @brief Returns true if the objects class is of the given type or a derivative. */
    141             inline bool isA(const OrxonoxClass* object)
    142                 { return this->getIdentifier()->isA(object->getIdentifier()); }
    143             /** @brief Returns true if the objects class is exactly of the given type. */
    144             inline bool isExactlyA(const OrxonoxClass* object)
    145                 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
    146             /** @brief Returns true if the objects class is a child of the given type. */
    147             inline bool isChildOf(const OrxonoxClass* object)
    148                 { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
    149             /** @brief Returns true if the objects class is a direct child of the given type. */
    150             inline bool isDirectChildOf(const OrxonoxClass* object)
    151                 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
    152             /** @brief Returns true if the objects class is a parent of the given type. */
    153             inline bool isParentOf(const OrxonoxClass* object)
    154                 { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
    155             /** @brief Returns true if the objects class is a direct child of the given type. */
    156             inline bool isDirectParentOf(const OrxonoxClass* object)
    157                 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
     98            bool isA(const OrxonoxClass* object);
     99            bool isExactlyA(const OrxonoxClass* object);
     100            bool isChildOf(const OrxonoxClass* object);
     101            bool isDirectChildOf(const OrxonoxClass* object);
     102            bool isParentOf(const OrxonoxClass* object);
     103            bool isDirectParentOf(const OrxonoxClass* object);
    158104
    159105        private:
    160             Identifier* identifier_;                    //!< The Identifier of the object
     106            Identifier* identifier_;                   //!< The Identifier of the object
    161107            std::set<const Identifier*>* parents_;     //!< List of all parents of the object
    162             MetaObjectList metaList_;                   //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
     108            MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
    163109    };
    164110}
  • code/trunk/src/core/OutputHandler.cc

    r1062 r1502  
    3535#include "CoreSettings.h"
    3636#include "ConsoleCommand.h"
     37#include "Shell.h"
    3738
    3839namespace orxonox
    3940{
    40     ConsoleCommandShortcutGeneric(log, createExecutor(createFunctor(&OutputHandler::log), "log", AccessLevel::None));
     41    SetConsoleCommandShortcutGeneric(log,     createConsoleCommand(createFunctor(&OutputHandler::log),     "log"    ));
     42    SetConsoleCommandShortcutGeneric(error,   createConsoleCommand(createFunctor(&OutputHandler::error),   "error"  ));
     43    SetConsoleCommandShortcutGeneric(warning, createConsoleCommand(createFunctor(&OutputHandler::warning), "warning"));
     44    SetConsoleCommandShortcutGeneric(info,    createConsoleCommand(createFunctor(&OutputHandler::info),    "info"   ));
     45    SetConsoleCommandShortcutGeneric(debug,   createConsoleCommand(createFunctor(&OutputHandler::debug),   "debug"  ));
    4146
    4247    /**
     
    8287
    8388    /**
     89        @brief Returns the Shell's OutputBuffer. This is mere placed here to avoid
     90               recompiling the entire project when Shell.h changes.
     91        @return The OutputBuffer of the Shell
     92    */
     93    OutputBuffer& OutputHandler::getShellOutputBuffer()
     94    {
     95        return Shell::getInstance().getOutputBuffer();
     96    }
     97
     98    /**
    8499        @brief Overloaded << operator, redirects the output to the console and the logfile.
    85100        @param sb The streambuffer that should be shown in the console
     
    96111            this->logfile_.flush();
    97112        }
     113
     114        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     115            Shell::getInstance().getOutputBuffer() << sb;
    98116
    99117        return *this;
     
    116134        }
    117135
     136        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     137            Shell::getInstance().getOutputBuffer() << manipulator;
     138
    118139        return *this;
    119140    }
     
    134155            this->logfile_.flush();
    135156        }
     157
     158        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     159            Shell::getInstance().getOutputBuffer() << manipulator;
    136160
    137161        return *this;
     
    154178        }
    155179
     180        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     181            Shell::getInstance().getOutputBuffer() << manipulator;
     182
    156183        return *this;
    157184    }
  • code/trunk/src/core/OutputHandler.h

    r1064 r1502  
    4444#include <string>
    4545
     46#include "OutputBuffer.h"
     47
    4648namespace orxonox
    4749{
     
    6466                { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; }
    6567
     68            /** @brief Puts an error on the outstream. @param text The text */
     69            static inline std::string error(const std::string& text)
     70                { OutputHandler::getOutStream().setOutputLevel(1); OutputHandler::getOutStream().output(text + "\n"); return text; }
     71
     72            /** @brief Puts a warning on the outstream. @param text The text */
     73            static inline std::string warning(const std::string& text)
     74                { OutputHandler::getOutStream().setOutputLevel(2); OutputHandler::getOutStream().output(text + "\n"); return text; }
     75
     76            /** @brief Puts an info on the outstream. @param text The text */
     77            static inline std::string info(const std::string& text)
     78                { OutputHandler::getOutStream().setOutputLevel(3); OutputHandler::getOutStream().output(text + "\n"); return text; }
     79
     80            /** @brief Puts some debug output on the outstream. @param text The text */
     81            static inline std::string debug(const std::string& text)
     82                { OutputHandler::getOutStream().setOutputLevel(4); OutputHandler::getOutStream().output(text + "\n"); return text; }
     83
    6684            /** @brief Returns a reference to the logfile. @return The logfile */
    6785            inline std::ofstream& getLogfile()
     
    7795
    7896            static int getSoftDebugLevel(OutputHandler::OutputDevice device);
     97
     98            OutputBuffer& getShellOutputBuffer();
    7999
    80100            template <class T>
     
    138158        }
    139159
     160        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     161            OutputHandler::getOutStream().getShellOutputBuffer() << output;
     162
    140163        return *this;
    141164    }
     
    159182        }
    160183
     184        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= out.getOutputLevel())
     185            OutputHandler::getOutStream().getShellOutputBuffer() << output;
     186
    161187        return out;
    162188    }
  • code/trunk/src/core/Script.cc

    r1153 r1502  
    6767  {
    6868    output_ += str;
    69     COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
     69//    COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
     70    COUT(5) << str;
    7071  }
    7172
     
    99100
    100101    if (luaTags) luaSource_ = replaceLuaTags(levelString);
    101     COUT(4) << "ParsedSourceCode: " << luaSource_ << std::endl;
     102    COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl;
    102103  }
    103104
     
    127128    if (error == 0)
    128129      error = lua_pcall(luaState_, 0, 0, 0);
    129     if (error != 0) COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
     130    if (error != 0)
     131    {
     132      COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
     133    }
    130134  }
    131135
  • code/trunk/src/core/TclBind.cc

    r1214 r1502  
    3333#include "CommandExecutor.h"
    3434#include "Debug.h"
     35#include "TclThreadManager.h"
    3536#include "TclBind.h"
     37#include "util/String.h"
    3638
    3739namespace orxonox
    3840{
    39     ConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl", AccessLevel::None));
     41    SetConsoleCommandShortcutGeneric(tcl, createConsoleCommand(createFunctor(&TclBind::tcl), "tcl"));
     42    SetConsoleCommandShortcutGeneric(bgerror, createConsoleCommand(createFunctor(&TclBind::bgerror), "bgerror"));
    4043
    4144    TclBind::TclBind()
     
    5962    void TclBind::setDataPath(const std::string& datapath)
    6063    {
    61         this->tclLibPath_ = datapath + "/tcl";
     64        this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/";
    6265        this->bSetTclLibPath_ = true;
    6366
     
    7073        {
    7174            this->interpreter_ = new Tcl::interpreter(this->tclLibPath_);
    72             this->interpreter_->def("puts", TclBind::puts, Tcl::variadic());
    73             this->interpreter_->def("orxonox", TclBind::orxonox, Tcl::variadic());
    74             this->interpreter_->def("execute", TclBind::execute, Tcl::variadic());
    75             this->interpreter_->eval("proc unknown {args} { return [orxonox $args] }");
    76             this->interpreter_->eval("rename exit tclexit; proc exit {} { orxonox exit }");
     75            this->interpreter_->def("orxonox::query", TclBind::tcl_query, Tcl::variadic());
     76            this->interpreter_->def("orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
     77            this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
     78
     79            try
     80            {
     81                this->interpreter_->eval("proc query args { orxonox::query $args }");
     82                this->interpreter_->eval("proc crossquery {id args} { orxonox::crossquery 0 $id $args }");
     83                this->interpreter_->eval("set id 0");
     84                this->interpreter_->eval("rename exit tcl::exit; proc exit {} { execute exit }");
     85                this->interpreter_->eval("redef_puts");
     86            }
     87            catch (Tcl::tcl_error const &e)
     88            {   COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl;   }
     89            catch (std::exception const &e)
     90            {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl;   }
    7791        }
    7892    }
     
    89103    }
    90104
    91     void TclBind::puts(Tcl::object const &args)
     105    std::string TclBind::tcl_query(Tcl::object const &args)
    92106    {
    93         COUT(0) << args.get() << std::endl;
    94     }
     107        COUT(4) << "Tcl_query: " << args.get() << std::endl;
    95108
    96     std::string TclBind::orxonox(Tcl::object const &args)
    97     {
    98 std::cout << "Tcl_execute: args: " << args.get() << std::endl;
    99         std::string command = args.get();
    100 
    101         if (command.size() >= 2 && command[0] == '{' && command[command.size() - 1] == '}')
    102             command = command.substr(1, command.size() - 2);
     109        std::string command = stripEnclosingBraces(args.get());
    103110
    104111        if (!CommandExecutor::execute(command, false))
     112        {
    105113            COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
     114        }
    106115
    107116        if (CommandExecutor::getLastEvaluation().hasReturnvalue())
     
    111120    }
    112121
    113     void TclBind::execute(Tcl::object const &args)
     122    void TclBind::tcl_execute(Tcl::object const &args)
    114123    {
     124        COUT(4) << "Tcl_execute: " << args.get() << std::endl;
     125        std::string command = stripEnclosingBraces(args.get());
     126
     127        if (!CommandExecutor::execute(command, false))
     128        {
     129            COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
     130        }
    115131    }
    116132
    117133    std::string TclBind::tcl(const std::string& tclcode)
    118134    {
    119         try
     135        if (TclBind::getInstance().interpreter_)
    120136        {
    121             std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
    122             if (output != "")
    123                 COUT(0) << "tcl> " << output << std::endl;
    124             return output;
    125         }
    126         catch (Tcl::tcl_error const &e)
    127         {
    128             COUT(1) << "tcl> Error: " << e.what() << std::endl;
    129         }
    130         catch (std::exception const &e)
    131         {
    132             COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
     137            try
     138            {
     139                std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
     140                if (output != "")
     141                {
     142                    COUT(0) << "tcl> " << output << std::endl;
     143                }
     144                return output;
     145            }
     146            catch (Tcl::tcl_error const &e)
     147            {   COUT(1) << "tcl> Error: " << e.what() << std::endl;   }
     148            catch (std::exception const &e)
     149            {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
    133150        }
    134151
    135152        return "";
     153    }
     154
     155    void TclBind::bgerror(std::string error)
     156    {
     157        COUT(1) << "Tcl background error: " << stripEnclosingBraces(error) << std::endl;
    136158    }
    137159
     
    144166        }
    145167        catch (Tcl::tcl_error const &e)
    146         {
    147             COUT(1) << "Error: " << e.what() << std::endl;
    148         }
     168        {   COUT(1) << "Tcl error: " << e.what() << std::endl;   }
    149169        catch (std::exception const &e)
    150         {
    151             COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
    152         }
     170        {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
    153171
    154172        return false;
  • code/trunk/src/core/TclBind.h

    r1223 r1502  
    4141            static TclBind& getInstance();
    4242
     43            static std::string tcl(const std::string& tclcode);
     44            static void bgerror(std::string error);
     45
    4346            void setDataPath(const std::string& datapath);
     47            std::string getTclLibPath() const { return this->tclLibPath_; }
    4448            void createTclInterpreter();
    4549            void createNewTclInterpreter();
     50            Tcl::interpreter* getTclInterpreter() const { return this->interpreter_; }
    4651
    47             static void puts(Tcl::object const &args);
    48             static void execute(Tcl::object const &args);
    49             static std::string orxonox(Tcl::object const &args);
    50             static std::string tcl(const std::string& tclcode);
     52            static std::string tcl_query(Tcl::object const &args);
     53            static void tcl_execute(Tcl::object const &args);
     54
    5155            static bool eval(const std::string& tclcode);
    5256
  • code/trunk/src/core/XMLPort.h

    r1209 r1502  
    7878namespace orxonox
    7979{
    80 
    81 #ifndef _XMLPort_Mode__
    82 #define _XMLPort_Mode__
    83     namespace XMLPort
    84     {
    85         enum Mode
    86         {
    87             LoadObject,
    88             SaveObject
    89         };
    90     }
    91 #endif
    92 
    9380    // ###############################
    9481    // ###  XMLPortParamContainer  ###
     
    166153                        }
    167154                    }
    168                     catch(ticpp::Exception& ex)
     155                    catch (ticpp::Exception& ex)
    169156                    {
    170157                        COUT(1) << std::endl;
     
    344331                        }
    345332                    }
    346                     catch(ticpp::Exception& ex)
     333                    catch (ticpp::Exception& ex)
    347334                    {
    348335                        COUT(1) << std::endl;
  • code/trunk/src/cpptcl/CppTcl.cc

    r1214 r1502  
    953953
    954954     {
     955          // TODO: why could this probably be necessary? map::find of empty map
     956          // shouldn't be a problem.
     957          if (callbacks.size() == 0)
     958            return;
    955959          callback_map::iterator it = callbacks.find(interp);
    956960          if (it == callbacks.end())
  • code/trunk/src/network/Client.cc

    r1360 r1502  
    8585    isConnected=false;
    8686    isSynched_=false;
     87    gameStateFailure_=false;
    8788  }
    8889
     
    9596    isConnected=false;
    9697    isSynched_=false;
     98    gameStateFailure_=false;
    9799  }
    98100
     
    105107    isConnected=false;
    106108    isSynched_=false;
     109    gameStateFailure_=false;
    107110  }
    108111
     
    120123    isConnected=client_connection.createConnection();
    121124    if(isConnected){
    122       COUT(3) << "sending connectrequest" << std::endl;
    123       if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
    124         COUT(1) << "could not create connection" << std::endl;
     125//       COUT(3) << "sending connectrequest" << std::endl;
     126//       if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
     127//         COUT(1) << "could not send connection request !!!!!!!!!" << std::endl;
    125128    }else
    126       COUT(1) << "could not create connection" << std::endl;
     129      COUT(1) << "could not create connection laber" << std::endl;
    127130    return isConnected;
    128131  }
     
    137140  }
    138141
    139   /**
    140   * submits a MouseAction to the server
    141   * @param x x Coordinate
    142   * @param y y Coordinate
    143   * @return true/false
    144   */
    145   bool Client::sendMouse(double x, double y){
    146     // generate packet and add it to the queue
    147     if(!isConnected)
    148       return false;
    149     if(!client_connection.addPacket(pck_gen.mousem(x, y)))
    150       return false;
    151     // send packets
    152     return client_connection.sendPackets();
    153   }
    154 
    155   /**
    156   * submits a Keystrike to the server
    157   * @param key_code code to submit
    158   * @return true/false
    159   */
    160   bool Client::sendKeyboard(char key_code){
    161     // generate packet and add it to queue
    162     if(!isConnected)
    163       return false;
    164     if(!client_connection.addPacket(pck_gen.keystrike(key_code)))
    165       return false;
    166     // send packets
    167     return client_connection.sendPackets();
    168   }
     142 
     143
     144 
    169145
    170146  /**
     
    177153    if(!isConnected)
    178154      return false;
    179     if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))
    180       return client_connection.sendPackets();
     155    return client_connection.addPacket(pck_gen.chatMessage( message.c_str() ));
     156      //return client_connection.sendPackets();
    181157    // send packets
    182158    return false;
    183   }
    184 
    185   /**
    186   * Adds a MouseAction to the PacketQueue
    187   * @param x x Coordinate
    188   * @param y y Coordinate
    189   * @return true/false
    190   */
    191   bool Client::addMouse(double x, double y){
    192     // generate packet and add it to the queue
    193     if(client_connection.addPacket(pck_gen.mousem(x, y)))
    194       return true;
    195     else
    196       return false;
    197   }
    198 
    199   /**
    200   * Adds a Keystrike to the PacketQueue
    201   * @param key_code
    202   * @return true/false
    203   */
    204   bool Client::addKeyboard(char key_code){
    205     // generate packet and add it to queue
    206     if(client_connection.addPacket(pck_gen.keystrike(key_code)))
    207       return true;
    208     else
    209       return false;
    210   }
    211 
    212   /**
    213   * Sends out all the packets queued by addXXX
    214   */
    215   bool Client::sendPackets(){
    216     if(!isConnected)
    217       return false;
    218     ENetEvent event;
    219     // send packets
    220     client_connection.sendPackets(&event);
    221     if(event.type==ENET_EVENT_TYPE_NONE)
    222       return true;
    223     else
    224       return false;
    225159  }
    226160
     
    243177      }
    244178    }
    245     ENetPacket *packet;
     179    ENetEvent *event;
    246180    // stop if the packet queue is empty
    247181    while(!(client_connection.queueEmpty())){
    248       packet = client_connection.getPacket();
    249       COUT(5) << "tick packet size " << packet->dataLength << std::endl;
    250       elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
    251     }
    252     if(!client_connection.sendPackets())
    253       COUT(3) << "Problem sending packets to server" << std::endl;
    254     return;
    255   }
    256 
    257   void Client::processGamestate( GameStateCompressed *data, int clientID){
    258     int id = data->id;
    259     COUT(5) << "received gamestate id: " << data->id << std::endl;
    260     if(gamestate.pushGameState(data)){
     182      event = client_connection.getEvent();
     183      COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
     184      elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
     185    }
     186    int gameStateID = gamestate.processGameState();
     187    if(gameStateID==GAMESTATEID_INITIAL)
     188      if(gameStateFailure_){
     189        if(!client_connection.addPacket(pck_gen.acknowledgement(GAMESTATEID_INITIAL)))
     190          COUT(3) << "could not (negatively) ack gamestate" << std::endl;
     191        else
     192          COUT(4) << "negatively acked a gamestate" << std::endl;
     193        }
     194      else
     195        gameStateFailure_=true;
     196    else if(gameStateID!=0){
     197      // ack gamestate and set synched
    261198      if(!isSynched_)
    262199        isSynched_=true;
    263       if(!client_connection.addPacket(pck_gen.acknowledgement(id)))
    264         return;
    265         // we do this at the end of a tick
    266       if(!client_connection.sendPackets())
    267         COUT(2) << "Could not send acknowledgment" << std::endl;
    268     }
     200      gameStateFailure_=false;
     201      if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID)))
     202        COUT(3) << "could not ack gamestate" << std::endl;
     203    }// otherwise we had no gamestate to load
     204    gamestate.cleanup();
     205    /*if(!client_connection.sendPackets())
     206      COUT(3) << "Problem sending packets to server" << std::endl;*/
     207    return;
     208  }
     209
     210  void Client::processGamestate( GameStateCompressed *data, int clientID){
     211    COUT(5) << "received gamestate id: " << data->id << std::endl;
     212    gamestate.addGameState(data);
    269213  }
    270214
     
    275219      id->setNetworkID(clid->clid);
    276220    COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
     221    COUT(4) << "id(classid)->getName " << ID((unsigned int)clid->clid)->getName() << std::endl;
    277222    delete clid;
    278223    return;
  • code/trunk/src/network/Client.h

    r1293 r1502  
    7575    bool closeConnection();
    7676
    77     bool sendMouse(double x, double y);
    78     bool sendKeyboard(char key_code);
    7977    bool sendChat( std::string message );
    80 
    81     bool addMouse(double x, double y);
    82     bool addKeyboard(char key_code);
    83 
    84     bool sendPackets();
    8578   
    8679    int getShipID(){return shipID_;}
     
    110103    int clientID_;     // this is the id the server gave to us
    111104    int shipID_;
     105    bool gameStateFailure_;
    112106  };
    113107
  • code/trunk/src/network/ClientConnection.cc

    r1293 r1502  
    5050{
    5151  //static boost::thread_group network_threads;
     52
     53  boost::recursive_mutex ClientConnection::enet_mutex_;
    5254
    5355  ClientConnection::ClientConnection(int port, std::string address) {
     
    7577
    7678
    77   ENetPacket *ClientConnection::getPacket(ENetAddress &address) {
     79  /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) {
    7880    if(!buffer.isEmpty()) {
    7981      //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl;
     
    8890    ENetAddress address; //sems that address is not needed
    8991    return getPacket(address);
     92  }*/
     93 
     94  ENetEvent *ClientConnection::getEvent(){
     95    if(!buffer.isEmpty())
     96      return buffer.pop();
     97    else
     98      return NULL;
    9099  }
    91100
     
    98107    //network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
    99108    // wait 10 seconds for the connection to be established
    100     return waitEstablished(10000);
     109    return waitEstablished(3000);
    101110  }
    102111
     
    117126      return false;
    118127    }
     128    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    119129    if(enet_peer_send(server, 0, packet)<0)
    120130      return false;
     
    123133  }
    124134
    125   bool ClientConnection::sendPackets(ENetEvent *event) {
     135  bool ClientConnection::sendPackets() {
    126136    if(server==NULL)
    127137      return false;
    128     if(enet_host_service(client, event, NETWORK_SEND_WAIT)>=0){
    129       return true;}
    130     else
    131       return false;
    132   }
    133 
    134   bool ClientConnection::sendPackets() {
    135     ENetEvent event;
    136     if(server==NULL)
    137       return false;
    138     if(enet_host_service(client, &event, NETWORK_SEND_WAIT)>=0){
    139       return true;}
    140     else
    141       return false;
     138    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     139    enet_host_flush(client);
     140    lock.unlock();
     141    return true;
    142142  }
    143143
    144144  void ClientConnection::receiverThread() {
    145145    // what about some error-handling here ?
    146     enet_initialize();
    147146    atexit(enet_deinitialize);
    148     ENetEvent event;
    149     client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
    150     if(client==NULL)
     147    ENetEvent *event;
     148    {
     149      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     150      enet_initialize();
     151      client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
     152      lock.unlock();
     153    }
     154    if(client==NULL) {
     155      COUT(2) << "ClientConnection: could not create client host" << std::endl;
    151156      // add some error handling here ==========================
    152157      quit=true;
     158    }
    153159    //connect to the server
    154160    if(!establishConnection()){
     161      COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl;
    155162      quit=true;
    156163      return;
    157164    }
     165    event = new ENetEvent;
    158166    //main loop
    159167    while(!quit){
    160168      //std::cout << "connection loop" << std::endl;
    161       if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)<0){
    162         // we should never reach this point
    163         quit=true;
    164         // add some error handling here ========================
     169      {
     170        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     171        if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){
     172          // we should never reach this point
     173          quit=true;
     174          continue;
     175          // add some error handling here ========================
     176        }
     177        lock.unlock();
    165178      }
    166       switch(event.type){
     179      switch(event->type){
    167180        // log handling ================
    168181      case ENET_EVENT_TYPE_CONNECT:
     182        break;
    169183      case ENET_EVENT_TYPE_RECEIVE:
    170184        COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl;
    171         if ( !processData(&event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
     185        if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
    172186        COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl;
     187        event = new ENetEvent;
    173188        break;
    174189      case ENET_EVENT_TYPE_DISCONNECT:
     
    178193        break;
    179194      case ENET_EVENT_TYPE_NONE:
    180         continue;
     195        //receiverThread_->yield();
     196        usleep(1000);
     197        break;
    181198      }
    182       //receiverThread_->yield();
    183199    }
    184200    // now disconnect
     
    186202    if(!disconnectConnection())
    187203      // if disconnecting failed destroy conn.
     204      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    188205      enet_peer_reset(server);
    189206    return;
     
    192209  bool ClientConnection::disconnectConnection() {
    193210    ENetEvent event;
     211    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    194212    enet_peer_disconnect(server, 0);
    195213    while(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT) > 0){
     
    212230    ENetEvent event;
    213231    // connect to peer (server is type ENetPeer*)
     232    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    214233    server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS);
    215     if(server==NULL)
     234    if(server==NULL) {
     235      COUT(2) << "ClientConnection: server == NULL" << std::endl;
    216236      // error handling
    217237      return false;
     238    }
    218239    // handshake
    219     if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)>0 && event.type == ENET_EVENT_TYPE_CONNECT){
     240    if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)>=0 && event.type == ENET_EVENT_TYPE_CONNECT){
    220241      established=true;
    221242      return true;
    222243    }
    223     else
    224       return false;
     244    else {
     245      COUT(2) << "ClientConnection: enet_host_service < 0 or event.type != ENET_EVENT_TYPE_CONNECT # EVENT:" << event.type << std::endl;
     246      return false;
     247    }
    225248  }
    226249
  • code/trunk/src/network/ClientConnection.h

    r1293 r1502  
    5454#define NETWORK_PORT 55556
    5555#define NETWORK_CLIENT_MAX_CONNECTIONS 5
    56 #define NETWORK_CLIENT_TIMEOUT 100
    57 #define NETWORK_SEND_WAIT 5
     56#define NETWORK_CLIENT_TIMEOUT 1
    5857#define NETWORK_CLIENT_CHANNELS 2
    5958
     
    6362    ClientConnection(int port, std::string address);
    6463    ClientConnection(int port, const char* address);
    65     ENetPacket *getPacket(ENetAddress &address); // thread1
    66     ENetPacket *getPacket(); // thread1
     64    //ENetPacket *getPacket(ENetAddress &address); // thread1
     65    //ENetPacket *getPacket(); // thread1
     66    ENetEvent *getEvent();
    6767    // check wheter the packet queue is empty
    6868    bool queueEmpty();
     
    7575    bool sendPackets();
    7676    // send out all queued packets and save result in event
    77     bool sendPackets(ENetEvent *event);
     77    //bool sendPackets(ENetEvent *event);
    7878    bool waitEstablished(int milisec);
    7979    bool isConnected(){return established;}
     
    9595    ENetPeer *server;
    9696    boost::thread *receiverThread_;
     97   
     98    static boost::recursive_mutex enet_mutex_;
    9799  };
    98100
  • code/trunk/src/network/ClientInformation.cc

    r1360 r1502  
    4545namespace network
    4646{
    47   boost::recursive_mutex ClientInformation::mutex_;
    4847 
    4948  ClientInformation::ClientInformation() {
     
    8483
    8584  ClientInformation::~ClientInformation() {
    86     boost::recursive_mutex::scoped_lock lock(mutex_);
    87     if(preve!=0)
    88       preve->setNext(this->nexte);
    89     if(nexte!=0)
    90       nexte->setPrev(this->preve);
     85    if(prev()!=0)
     86      prev()->setNext(this->next());
     87    if(next()!=0)
     88      next()->setPrev(this->prev());
    9189  }
    9290
    9391  ClientInformation *ClientInformation::next() {
    94     boost::recursive_mutex::scoped_lock lock(mutex_);
    9592    if(this!=0)
    9693      return this->nexte;
     
    9996  }
    10097  ClientInformation *ClientInformation::prev() {
    101     boost::recursive_mutex::scoped_lock lock(mutex_);
    10298    if(this!=0)
    10399      return this->preve;
     
    107103
    108104  bool ClientInformation::setPrev(ClientInformation *prev) {
    109     boost::recursive_mutex::scoped_lock lock(mutex_);
    110105    if(!head_)
    111106      this->preve = prev;
     
    116111
    117112  bool ClientInformation::setNext(ClientInformation *next) {
    118     boost::recursive_mutex::scoped_lock lock(mutex_);
    119113    this->nexte = next;
    120114    return true;
     
    122116
    123117  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
    124     boost::recursive_mutex::scoped_lock lock(mutex_);
    125     this->nexte->setPrev(ins);
    126     ins->setNext(this->nexte);
     118    this->next()->setPrev(ins);
     119    ins->setNext(this->next());
    127120    ins->setPrev(this);
    128121    this->nexte = ins;
     
    131124
    132125  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
    133     boost::recursive_mutex::scoped_lock lock(mutex_);
    134126    if(!this)
    135127      return NULL;
    136128    this->prev()->setNext(ins);
    137     ins->setPrev(this->preve);
     129    ins->setPrev(this->prev());
    138130    this->preve=ins;
    139131    ins->setNext(this);
     
    142134
    143135  void ClientInformation::setID(int clientID){
    144     boost::recursive_mutex::scoped_lock lock(mutex_);
     136    if(!this)
     137      return;
    145138    clientID_ = clientID;
    146139  }
    147140
    148141  bool ClientInformation::setPeer(ENetPeer *peer){
    149     boost::recursive_mutex::scoped_lock lock(mutex_);
    150142    if(!this)
    151143      return false;
     
    154146  }
    155147
    156   bool ClientInformation::setGamestateID(int id){
    157     boost::recursive_mutex::scoped_lock lock(mutex_);
     148  bool ClientInformation::setGameStateID(int id){
    158149    if(!this)
    159150      return false;
     
    163154 
    164155  bool ClientInformation::setPartialGamestateID(int id){
    165     boost::recursive_mutex::scoped_lock lock(mutex_);
    166156    if(!this)
    167157      return false;
     
    171161
    172162  int ClientInformation::getID() {
    173     boost::recursive_mutex::scoped_lock lock(mutex_);
    174163    if(!this)
    175164      return CLIENTID_UNKNOWN;
     
    179168
    180169  ENetPeer *ClientInformation::getPeer() {
    181     boost::recursive_mutex::scoped_lock lock(mutex_);
    182170    if(this)
    183171      return peer_;
     
    187175 
    188176  bool ClientInformation::getHead(){
    189     boost::recursive_mutex::scoped_lock lock(mutex_);
    190177    return head_;
    191178  }
    192179 
    193180  void ClientInformation::setHead(bool h){
    194     boost::recursive_mutex::scoped_lock lock(mutex_);
    195181    head_=h;
    196182  }
    197183 
    198184  int ClientInformation::getFailures(){
    199     boost::recursive_mutex::scoped_lock lock(mutex_);
    200185    return failures_;
    201186  }
    202187  void ClientInformation::addFailure(){
    203     boost::recursive_mutex::scoped_lock lock(mutex_);
    204188    failures_++;
    205189  }
    206190  void ClientInformation::resetFailures(){
    207     boost::recursive_mutex::scoped_lock lock(mutex_);
    208191    failures_=0;
    209192  }
    210193
    211194  int ClientInformation::getGamestateID() {
    212     boost::recursive_mutex::scoped_lock lock(mutex_);
    213195    if(this)
    214196      return gamestateID_;
     
    218200 
    219201  int ClientInformation::getPartialGamestateID() {
    220     boost::recursive_mutex::scoped_lock lock(mutex_);
    221202    if(this)
    222203      return partialGamestateID_;
     
    226207
    227208  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
    228     boost::recursive_mutex::scoped_lock lock(mutex_);
    229209    if(!this)
    230210      return NULL;
     
    239219
    240220  bool ClientInformation::removeClient(int clientID) {
    241     boost::recursive_mutex::scoped_lock lock(mutex_);
    242221    if(!this || clientID==CLIENTID_UNKNOWN)
    243222      return false;
     
    252231
    253232  bool ClientInformation::removeClient(ENetPeer *peer) {
    254     boost::recursive_mutex::scoped_lock lock(mutex_);
    255233    if(!this || !peer)
    256234      return false;
     
    275253  */
    276254  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
    277     boost::recursive_mutex::scoped_lock lock(mutex_);
    278255    ClientInformation *temp = this;
    279256    if (temp->head_)
     
    293270  */
    294271  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
    295     boost::recursive_mutex::scoped_lock lock(mutex_);
    296272    ClientInformation *temp = this;
    297273    while(temp!=0){
     
    309285
    310286  bool ClientInformation::setSynched(bool s) {
    311     boost::recursive_mutex::scoped_lock lock(mutex_);
    312287    if(!this)
    313288      return false;
     
    317292
    318293  bool ClientInformation::getSynched() {
    319     boost::recursive_mutex::scoped_lock lock(mutex_);
    320294    if(this)
    321295      return synched_;
  • code/trunk/src/network/ClientInformation.h

    r1360 r1502  
    4949#define CLIENTID_UNKNOWN -2
    5050
     51// WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
     52
    5153namespace network
    5254{
     
    6971    void setID(int clientID);
    7072    bool setPeer(ENetPeer *peer);
    71     bool setGamestateID(int id);
     73    bool setGameStateID(int id);
    7274    bool setPartialGamestateID(int id);
    7375    inline void setShipID(int id){ShipID_=id;}
     
    114116    bool head_;
    115117    unsigned short failures_;
    116     static boost::recursive_mutex mutex_;
    117118   
    118119  };
  • code/trunk/src/network/ConnectionManager.cc

    r1360 r1502  
    4444#include "core/CoreIncludes.h"
    4545#include "core/BaseObject.h"
     46#include "objects/SpaceShip.h"
    4647#include "util/Math.h"
    47 #include "objects/SpaceShip.h"
     48#include "util/Sleep.h"
    4849#include "ClientInformation.h"
    4950#include "ConnectionManager.h"
     
    6566 
    6667  ConnectionManager::ConnectionManager():receiverThread_(0){}
     68  boost::recursive_mutex ConnectionManager::enet_mutex_;
    6769 
    6870  ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
     
    7274    head_ = head;
    7375  }
     76 
     77  ConnectionManager::ConnectionManager(ClientInformation *head, int port){
     78    quit=false;
     79    bindAddress.host = ENET_HOST_ANY;
     80    bindAddress.port = port;
     81    head_ = head;
     82  }
    7483
    7584  ConnectionManager::ConnectionManager(int port, std::string address, ClientInformation *head) :receiverThread_(0) {
     
    8796  }
    8897
    89   ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {
     98  /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {
    9099    if(!buffer.isEmpty())
    91100      return buffer.pop(address);
    92101    else
    93102      return NULL;
    94   }
     103  }*/
    95104/**
    96105This function only pops the first element in PacketBuffer (first in first out)
    97106used by processQueue in Server.cc
    98107*/
    99   ENetPacket *ConnectionManager::getPacket(int &clientID) {
     108  /*ENetPacket *ConnectionManager::getPacket(int &clientID) {
    100109    ENetAddress address;
    101110    ENetPacket *packet=getPacket(address);
     
    105114    clientID=temp->getID();
    106115    return packet;
     116  }*/
     117 
     118  ENetEvent *ConnectionManager::getEvent(){
     119    if(!buffer.isEmpty())
     120      return buffer.pop();
     121    else
     122      return NULL;
    107123  }
    108124
     
    129145    if(!temp)
    130146      return false;
     147    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    131148    if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0)
    132149      return false;
     
    136153  bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) {
    137154    ClientInformation *temp = head_->findClient(clientID);
    138     if(!temp)
    139       return false;
    140     if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0)
    141       return false;
     155    if(!temp){
     156      COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
     157      return false;
     158    }
     159    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     160    if(enet_peer_send(temp->getPeer(), 0, packet)!=0){
     161      COUT(3) << "C.Man: addPacket enet_peer_send failed" << std::endl;
     162      return false;
     163    }
    142164    return true;
    143165  }
    144166
    145167  bool ConnectionManager::addPacketAll(ENetPacket *packet) {
     168    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
    146169    for(ClientInformation *i=head_->next(); i!=0; i=i->next()){
    147170      if(enet_peer_send(i->getPeer(), (enet_uint8)i->getID(), packet)!=0)
     
    151174  }
    152175
    153   bool ConnectionManager::sendPackets(ENetEvent *event) {
     176  // we actually dont need that function, because host_service does that for us
     177  bool ConnectionManager::sendPackets() {
    154178    if(server==NULL)
    155179      return false;
    156     if(enet_host_service(server, event, NETWORK_SEND_WAIT)>=0)
    157       return true;
    158     else
    159       return false;
    160   }
    161 
    162   bool ConnectionManager::sendPackets() {
    163     ENetEvent event;
    164     if(server==NULL)
    165       return false;
    166     if(enet_host_service(server, &event, NETWORK_SEND_WAIT)>=0)
    167       return true;
    168     else
    169       return false;
     180    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     181    enet_host_flush(server);
     182    lock.unlock();
     183    return true;
    170184  }
    171185
    172186  void ConnectionManager::receiverThread() {
    173187    // what about some error-handling here ?
    174     enet_initialize();
     188    ENetEvent *event;
    175189    atexit(enet_deinitialize);
    176     ENetEvent *event = new ENetEvent;
    177     server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
     190    { //scope of the mutex
     191      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     192      enet_initialize();
     193      server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
     194      lock.unlock();
     195    }
    178196    if(server==NULL){
    179197      // add some error handling here ==========================
     
    182200    }
    183201
     202    event = new ENetEvent;
    184203    while(!quit){
    185       if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    186         // we should never reach this point
    187         quit=true;
    188         // add some error handling here ========================
     204      { //mutex scope
     205        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     206        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
     207          // we should never reach this point
     208          quit=true;
     209          continue;
     210          // add some error handling here ========================
     211        }
     212        lock.unlock();
    189213      }
    190214      switch(event->type){
    191215        // log handling ================
    192216        case ENET_EVENT_TYPE_CONNECT:
    193           addClient(event);
     217          COUT(3) << "adding event_type_connect to queue" << std::endl;
     218        case ENET_EVENT_TYPE_DISCONNECT:
     219          //addClient(event);
    194220          //this is a workaround to ensure thread safety
    195           COUT(5) << "Con.Man: connection event has occured" << std::endl;
    196           break;
     221          //COUT(5) << "Con.Man: connection event has occured" << std::endl;
     222          //break;
    197223        case ENET_EVENT_TYPE_RECEIVE:
    198224          //std::cout << "received data" << std::endl;
    199225          COUT(5) << "Con.Man: receive event has occured" << std::endl;
    200226          // only add, if client has connected yet and not been disconnected
    201           if(head_->findClient(&event->peer->address))
     227          //if(head_->findClient(&event->peer->address))
    202228            processData(event);
    203           else
    204             COUT(3) << "received a packet from a client we don't know" << std::endl;
     229            event = new ENetEvent;
     230//           else
     231//             COUT(3) << "received a packet from a client we don't know" << std::endl;
    205232          break;
    206         case ENET_EVENT_TYPE_DISCONNECT:
    207           clientDisconnect(event->peer);
     233        //case ENET_EVENT_TYPE_DISCONNECT:
     234          //clientDisconnect(event->peer);
     235          //break;
     236        case ENET_EVENT_TYPE_NONE:
     237          //receiverThread_->yield();
     238          usleep(1000);
    208239          break;
    209         case ENET_EVENT_TYPE_NONE:
    210           receiverThread_->yield();
    211           break;
    212240      }
    213241//       usleep(100);
    214       receiverThread_->yield(); //TODO: find apropriate
     242      //receiverThread_->yield(); //TODO: find apropriate
    215243    }
    216244    disconnectClients();
    217245    // if we're finishied, destroy server
    218     enet_host_destroy(server);
     246    {
     247      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     248      enet_host_destroy(server);
     249      lock.unlock();
     250    }
    219251  }
    220252 
     
    226258    ClientInformation *temp = head_->next();
    227259    while(temp!=0){
    228       enet_peer_disconnect(temp->getPeer(), 0);
     260      {
     261        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     262        enet_peer_disconnect(temp->getPeer(), 0);
     263        lock.unlock();
     264      }
    229265      temp = temp->next();
    230266    }
    231267    //bugfix: might be the reason why server crashes when clients disconnects
    232     //temp = temp->next();
    233268    temp = head_->next();
    234     while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){
     269    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     270    while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
    235271      switch (event.type)
    236272      {
     
    258294  }
    259295
    260   bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
    261     COUT(4) << "removing client from list" << std::endl;
    262     return removeClient(head_->findClient(&(peer->address))->getID());
    263   }
    264 /**
    265 This function adds a client that connects to the clientlist of the server
    266 NOTE: if you change this, don't forget to change the test function
    267 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid
    268 */
    269   bool ConnectionManager::addClient(ENetEvent *event) {
    270     ClientInformation *temp = head_->insertBack(new ClientInformation);
    271     if(!temp){
    272       COUT(2) << "Conn.Man. could not add client" << std::endl;
    273       return false;
    274     }
    275     if(temp->prev()->getHead()) { //not good if you use anything else than insertBack
    276       temp->prev()->setID(0); //bugfix: not necessary but usefull
    277       temp->setID(1);
    278     }
    279     else
    280       temp->setID(temp->prev()->getID()+1);
    281     temp->setPeer(event->peer);
    282     COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl;
    283     return true;
    284   }
     296
    285297
    286298  int ConnectionManager::getClientID(ENetPeer peer) {
     
    316328      ++it;
    317329    }
    318     sendPackets();
     330    //sendPackets();
    319331    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
    320332  }
    321333
    322   bool ConnectionManager::createClient(int clientID){
    323     ClientInformation *temp = head_->findClient(clientID);
    324     if(!temp){
    325       COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
    326       return false;
    327     }
    328     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    329     syncClassid(temp->getID());
    330     COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
    331     // TODO: this is only a hack, untill we have a possibility to define default player-join actions
    332     if(!createShip(temp))
    333       COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;
    334     else
    335       COUT(3) << "created spaceship" << std::endl;
    336     temp->setSynched(true);
    337     COUT(3) << "sending welcome" << std::endl;
    338     sendWelcome(temp->getID(), temp->getShipID(), true);
    339     return true;
    340   }
    341  
    342   bool ConnectionManager::removeClient(int clientID){
    343     orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
    344     ClientInformation *client = head_->findClient(clientID);
    345     if(!client)
    346       return false;
    347     while(it){
    348       if(it->objectID!=client->getShipID()){
    349         ++it;
    350         continue;
    351       }
    352       orxonox::Iterator<orxonox::SpaceShip> temp=it;
    353       ++it;
    354       delete  *temp;
    355       return head_->removeClient(clientID);
    356     }
    357     return false;
    358   }
    359  
    360   bool ConnectionManager::createShip(ClientInformation *client){
    361     if(!client)
    362       return false;
    363     orxonox::Identifier* id = ID("SpaceShip");
    364     if(!id){
    365       COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;
    366       return false;
    367     }
    368     orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
    369     no->setPosition(orxonox::Vector3(0,80,0));
    370     no->setScale(10);
    371     no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));
    372     no->setMesh("assff.mesh");
    373     no->setMaxSpeed(500);
    374     no->setMaxSideAndBackSpeed(50);
    375     no->setMaxRotation(1.0);
    376     no->setTransAcc(200);
    377     no->setRotAcc(3.0);
    378     no->setTransDamp(75);
    379     no->setRotDamp(1.0);
    380     no->setCamera("cam_"+client->getID());
    381     no->classID = id->getNetworkID();
    382     no->create();
    383    
    384     client->setShipID(no->objectID);
    385     return true;
    386   }
     334 
    387335 
    388336  bool ConnectionManager::removeShip(ClientInformation *client){
     
    399347  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    400348    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
    401       sendPackets();
     349      //sendPackets();
    402350      return true;
    403351    }else
     
    406354 
    407355  void ConnectionManager::disconnectClient(ClientInformation *client){
    408     enet_peer_disconnect(client->getPeer(), 0);
     356    {
     357      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     358      enet_peer_disconnect(client->getPeer(), 0);
     359      lock.unlock();
     360    }
    409361    removeShip(client);
    410362  }
     
    418370 
    419371 
    420 //   int ConnectionManager::getNumberOfClients() {
    421 //     
    422 //     return clientsShip.size();
    423 //   }
    424  
    425   /*void ConnectionManager::addClientsObjectID( int clientID, int objectID ) {
    426   COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl;
    427   clientsShip.insert( std::make_pair( clientID, objectID ) );
     372
    428373}
    429 
    430   int ConnectionManager::getClientsShipID( int clientID ) {
    431   return clientsShip[clientID];
    432 }
    433 
    434   int ConnectionManager::getObjectsClientID( int objectID ) {
    435   std::map<int, int>::iterator iter;
    436   for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    437   if( iter->second == objectID ) return iter->first;
    438 }
    439   return -99;
    440 }
    441 
    442   void ConnectionManager::deleteClientIDReg( int clientID ) {
    443   clientsShip.erase( clientID );
    444 }
    445 
    446   void ConnectionManager::deleteObjectIDReg( int objectID ) {
    447   std::map<int, int>::iterator iter = clientsShip.begin();
    448   for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    449   if( iter->second == objectID ) break;
    450 }
    451   clientsShip.erase( iter->first );
    452 }*/
    453 }
  • code/trunk/src/network/ConnectionManager.h

    r1293 r1502  
    4848#include <enet/enet.h>
    4949#include <boost/thread/thread.hpp>
     50#include <boost/thread/recursive_mutex.hpp>
    5051
    5152#include "PacketBuffer.h"
     
    6162#define NETWORK_PORT 55556
    6263#define NETWORK_MAX_CONNECTIONS 50
    63 #define NETWORK_WAIT_TIMEOUT 5000
    64 #define NETWORK_SEND_WAIT 5
     64#define NETWORK_WAIT_TIMEOUT 1
    6565
    6666  struct ClientList{
     
    7474    ConnectionManager();
    7575    ConnectionManager(ClientInformation *head);
     76    ConnectionManager(ClientInformation *head, int port);
    7677    ConnectionManager(int port, const char *address, ClientInformation *head);
    7778    ConnectionManager(int port, std::string address, ClientInformation *head);
    78     ENetPacket *getPacket(ENetAddress &address); // thread1
    79     ENetPacket *getPacket(int &clientID);
     79    //ENetPacket *getPacket(ENetAddress &address); // thread1
     80    //ENetPacket *getPacket(int &clientID);
     81    ENetEvent *getEvent();
    8082    bool queueEmpty();
    8183    void createListener();
     
    8486    bool addPacket(ENetPacket *packet, int ID);
    8587    bool addPacketAll(ENetPacket *packet);
    86     bool sendPackets(ENetEvent *event);
     88  //  bool sendPackets(ENetEvent *event);
    8789    bool sendPackets();
    88     bool createClient(int clientID);
     90    //bool createClient(int clientID);
    8991    void disconnectClient(ClientInformation *client);
     92    void syncClassid(int clientID);
     93    bool sendWelcome(int clientID, int shipID, bool allowed);
    9094
    9195  private:
    92     bool clientDisconnect(ENetPeer *peer);
    93     bool removeClient(int clientID);
     96//     bool clientDisconnect(ENetPeer *peer);
     97//     bool removeClient(int clientID);
    9498    bool processData(ENetEvent *event);
    95     bool addClient(ENetEvent *event);
     99    //bool addClient(ENetEvent *event);
    96100    void receiverThread();
    97101    void disconnectClients();
    98102    int getClientID(ENetPeer peer);
    99103    int getClientID(ENetAddress address);
    100     void syncClassid(int clientID);
    101104    ENetPeer *getClientPeer(int clientID);
    102     bool createShip(ClientInformation *client);
     105    //bool createShip(ClientInformation *client);
    103106    bool removeShip(ClientInformation *client);
    104     bool sendWelcome(int clientID, int shipID, bool allowed);
    105107    bool addFakeConnectRequest(ENetEvent *ev);
    106108    PacketBuffer buffer;
     
    114116
    115117    boost::thread *receiverThread_;
     118    static boost::recursive_mutex enet_mutex_;
    116119//     int getNumberOfClients();
    117120    //functions to map what object every clients uses
  • code/trunk/src/network/GameStateClient.cc

    r1360 r1502  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    25  *      ...
     25 *      Dumeni Manatschal
    2626 *
    2727 */
     
    3535#include "Synchronisable.h"
    3636
    37 #define GAMESTATEID_INITIAL -1
    3837
    3938namespace network
     
    4342    int id;
    4443  };
    45  
     44
    4645  GameStateClient::GameStateClient() {
    4746    COUT(5) << "this: " << this << std::endl;
    4847    last_diff_=0;
    4948    last_gamestate_=GAMESTATEID_INITIAL-1;
     49    tempGameState_=NULL;
     50    myShip_=NULL;
    5051  }
    5152
     
    9596    return false;
    9697  }
    97  
     98
    9899  GameStateCompressed *GameStateClient::popPartialGameState(){
    99100    GameState *gs = getPartialSnapshot();
     101    if(!gs)
     102      return NULL;
    100103    GameStateCompressed *cgs = compress_(gs);
    101104    delete[] gs->data;
     
    103106    return cgs;
    104107  }
    105  
     108
     109  void GameStateClient::addGameState(GameStateCompressed *gs){
     110    if(tempGameState_!=NULL){
     111      //delete the obsolete gamestate
     112      if(tempGameState_->id>gs->id)
     113        return;
     114      delete[] tempGameState_->data;
     115      delete tempGameState_;
     116    }
     117    tempGameState_=gs;
     118  }
     119  int GameStateClient::processGameState(){
     120    if(tempGameState_==NULL)
     121      return 0;
     122    int id=tempGameState_->id;
     123    bool b = saveShipCache();
     124    if(pushGameState(tempGameState_)){
     125      if(b)
     126        loadShipCache();
     127      return id;
     128    }
     129    else
     130      return GAMESTATEID_INITIAL;
     131  }
     132
    106133
    107134  /**
     
    151178          orxonox::Identifier* id = ID((unsigned int)sync.classID);
    152179          if(!id){
    153             COUT(4) << "We could not identify a new object; classid: " << sync.classID << std::endl;
    154             return false;
     180            COUT(3) << "We could not identify a new object; classid: " << sync.classID << " uint: " << (unsigned int)sync.classID << " objectID: " << sync.objectID << " size: " << sync.length << std::endl;
     181            return false; // most probably the gamestate is corrupted
    155182          }
    156183          Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
     
    168195          }
    169196          if( !no->create() )
     197          {
    170198            COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
     199          }
    171200          it=orxonox::ObjectList<Synchronisable>::end();
    172201        }
     
    174203        // we have our object
    175204        if(! it->updateData(sync))
     205        {
    176206          COUT(1) << "We couldn't update objectID: " \
    177207          << sync.objectID << "; classID: " << sync.classID << std::endl;
     208        }
    178209      }
    179210      ++it;
     
    213244    }
    214245    //retval->data = (unsigned char*)malloc(size);
     246    if(size==0)
     247      return NULL;
    215248    retval->data = new unsigned char[size];
    216249    if(!retval->data){
     
    245278    return retval;
    246279  }
    247  
    248  
     280
     281
    249282  GameState *GameStateClient::undiff(GameState *old, GameState *diff) {
    250283    if(!old || !diff)
     
    253286    int of=0; // pointers offset
    254287    int dest_length=0;
    255     if(old->size>=diff->size)
     288    /*if(old->size>=diff->size)
    256289      dest_length=old->size;
    257     else
     290    else*/
    258291      dest_length=diff->size;
    259292//     unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
     293    if(dest_length==0)
     294      return NULL;
    260295    unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)];
    261296    while(of<old->size && of<diff->size){
     
    270305          of++;
    271306        }
    272       } else{
     307      } /*else{
    273308        while(of<dest_length){
    274309          *(dp+of)=*(ap+of)^n;
    275310          of++;
    276311        }
    277       }
     312      }*/
    278313    }
    279314    // should be finished now
     
    297332
    298333    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
     334    if(buffer==0)
     335      return NULL;
    299336    unsigned char *dest = new unsigned char[buffer];
    300337    int retval;
     
    303340    switch ( retval ) {
    304341      case Z_OK: COUT(5) << "G.St.Cl: compress: successfully compressed" << std::endl; break;
    305       case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl; 
     342      case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl;
    306343      return NULL;
    307344      case Z_BUF_ERROR: COUT(2) << "G.St.Cl: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
     
    321358    return compressedGamestate;
    322359  }
    323  
    324  
     360
     361
    325362  GameState *GameStateClient::decompress(GameStateCompressed *a) {
    326363    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
     
    333370      bufsize = normsize;
    334371//     unsigned char* dest = (unsigned char*)malloc( bufsize );
     372    if(bufsize==0)
     373      return NULL;
    335374    unsigned char *dest = new unsigned char[bufsize];
    336375    int retval;
     
    376415    return t;
    377416  }
    378  
     417
    379418  void GameStateClient::cleanup(){
    380419    std::map<int, GameState*>::iterator temp, it = gameStateMap.begin();
     
    388427      gameStateMap.erase(temp);
    389428    }
     429    tempGameState_=NULL;
    390430  }
    391431
     
    397437    }
    398438    COUT(4) << std::endl;
    399    
    400   }
    401  
    402  
     439
     440  }
     441
     442  bool GameStateClient::saveShipCache(){
     443    if(myShip_==NULL)
     444      myShip_ = orxonox::SpaceShip::getLocalShip();
     445    if(myShip_){
     446      //      unsigned char *data = new unsigned char[myShip_->getSize()];
     447      int size=myShip_->getSize(0x3);
     448      if(size==0)
     449        return false;
     450      unsigned char *data = new unsigned char [size];
     451      shipCache_ = myShip_->getData(data, 0x1);
     452      return true;
     453    }else
     454      return false;
     455  }
     456
     457  bool GameStateClient::loadShipCache(){
     458    if(myShip_){
     459      myShip_->updateData(shipCache_, 0x2);
     460      if(shipCache_.data){
     461        delete[] shipCache_.data;
     462      }
     463      return true;
     464    }else
     465      return false;
     466  }
     467
    403468    //##### ADDED FOR TESTING PURPOSE #####
    404469  GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) {
    405470    return decompress( gc );
    406471  }
    407  
     472
    408473  GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) {
    409474    return undiff( g_old, g_diffed );
    410475  }
    411476  //##### ADDED FOR TESTING PURPOSE #####
    412  
    413  
     477
     478
    414479}
    415480
  • code/trunk/src/network/GameStateClient.h

    r1360 r1502  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    25  *      ...
     25 *      Dumeni Manatschal
    2626 *
    2727 */
     
    3333//
    3434//
    35 // Author:  <>, (C) 2007
     35// Author:  Oliver Scheuss, (C) 2007
    3636//
    3737// Copyright: See COPYING file that comes with this distribution
     
    4646#include "core/CorePrereqs.h"
    4747#include "PacketTypes.h"
     48#include "objects/SpaceShip.h"
    4849
     50
     51#define GAMESTATEID_INITIAL -1
    4952
    5053namespace network
     
    5659    ~GameStateClient();
    5760   
     61    void addGameState(GameStateCompressed *gs);
     62    int processGameState();
     63    GameStateCompressed *popPartialGameState();
     64    void cleanup();
     65  private:
    5866    bool pushGameState(GameStateCompressed *compstate);
    59     GameStateCompressed *popPartialGameState();
    60   private:
    6167    bool loadSnapshot(GameState *state);
    6268    GameState *getPartialSnapshot();
    63     void cleanup();
    6469    GameState *undiff(GameState *old, GameState *diff);
    6570    GameStateCompressed *compress_(GameState *a);
     
    6974    void removeObject(orxonox::Iterator<Synchronisable> &it);
    7075    void printGameStateMap();
     76    bool saveShipCache();
     77    bool loadShipCache();
    7178
    7279    int           last_diff_;
    7380    int           last_gamestate_;
    7481    std::map<int, GameState *> gameStateMap;
     82    GameStateCompressed *tempGameState_; // we save the received gamestates here during processQueue
     83    orxonox::SpaceShip *myShip_;
     84    syncData shipCache_;
    7585   
    7686   
  • code/trunk/src/network/GameStateManager.cc

    r1360 r1502  
    6868    printGameStates();
    6969    return;
     70  }
     71 
     72  void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){
     73    if(!gs)
     74      return;
     75    std::map<int, GameStateCompressed*>::iterator it = gameStateQueue.find(clientID);
     76    if(it!=gameStateQueue.end()){
     77      // delete obsolete gamestate
     78      delete[] it->second->data;
     79      delete it->second;
     80    }
     81    gameStateQueue[clientID] = gs;
     82    return;
     83  }
     84 
     85  void GameStateManager::processGameStates(){
     86    std::map<int, GameStateCompressed*>::iterator it;
     87    // now push only the most recent gamestates we received (ignore obsolete ones)
     88    for(it = gameStateQueue.begin(); it!=gameStateQueue.end(); it++){
     89      pushGameState(it->second, it->first);
     90    }
     91    // now clear the queue
     92    gameStateQueue.clear();
    7093  }
    7194 
     
    117140        client = it->second;
    118141      GameState *server = reference;
    119       COUT(3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << std::endl;
     142      COUT(4) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl;
    120143      if(client)
    121144        return encode(client, server);
     
    170193    }
    171194    //retval->data = (unsigned char*)malloc(size);
     195    if(size==0)
     196      return NULL;
    172197    retval->data = new unsigned char[size];
    173198    if(!retval->data){
     
    237262      data+=sizeof(int);
    238263      sync.classID = *(int*)data;
     264      if(sync.classID == 0) // TODO: remove this
     265        COUT(3) << "received a classid 0" << std::endl;
    239266      data+=sizeof(int);
    240267      sync.data = data;
     
    246273
    247274      if(!it){
    248         // the object does not exist yet
     275        // the objectaber ich glaub die does not exist yet
    249276        COUT(4) << "loadsnapshot: creating new object " << std::endl;
    250277        //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
     
    314341  }
    315342
    316   GameState *GameStateManager::diff(GameState *a, GameState *b) {
    317     unsigned char *ap = a->data, *bp = b->data;
     343  GameState *GameStateManager::diff(GameState *alt, GameState *neu) {
     344    unsigned char *ap = alt->data, *bp = neu->data;
    318345    int of=0; // pointers offset
    319346    int dest_length=0;
    320     if(a->size>=b->size)
    321       dest_length=a->size;
    322     else
    323       dest_length=b->size;
     347    /*if(alt->size>neu->size)
     348      dest_length=alt->size;
     349    else*/
     350      dest_length=neu->size;
     351    if(dest_length==0)
     352      return NULL;
    324353    //unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
    325354    unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)];
    326     while(of<a->size && of<b->size){
     355    while(of<alt->size && of<neu->size){
    327356      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
    328357      ++of;
    329358    }
    330     if(a->size!=b->size){ // do we have to fill up ?
     359    if(alt->size!=neu->size){ // do we have to fill up ?
    331360      unsigned char n=0;
    332       if(a->size<b->size){
     361      if(alt->size<neu->size){
    333362        while(of<dest_length){
    334363          *(dp+of)=n^*(bp+of);
    335364          of++;
    336365        }
    337       } else{
     366      } /*else{
    338367        while(of<dest_length){
    339368          *(dp+of)=*(ap+of)^n;
    340369          of++;
    341370        }
    342       }
     371      }*/
    343372    }
    344373
    345374    GameState *r = new GameState;
    346     r->id = b->id;
     375    r->id = neu->id;
    347376    r->size = dest_length;
    348377    r->diffed = true;
    349     r->base_id = a->id;
     378    r->base_id = alt->id;
    350379    r->data = dp;
    351380    r->complete = true;
     
    362391    //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl;
    363392    //unsigned char* dest = (unsigned char*)malloc( buffer );
     393    if(buffer==0)
     394      return NULL;
    364395    unsigned char *dest = new unsigned char[buffer];
    365396    //COUT(4) << "dest: " << dest << std::endl;
     
    404435      bufsize = normsize;
    405436//     unsigned char* dest = (unsigned char*)malloc( bufsize );
     437    if(bufsize==0)
     438      return NULL;
    406439    unsigned char *dest = new unsigned char[bufsize];
    407440    int retval;
     
    436469      return;
    437470    int curid = temp->getGamestateID();
     471   
     472    if(gamestateID == GAMESTATEID_INITIAL){
     473      temp->setGameStateID(GAMESTATEID_INITIAL);
     474      if(curid!=GAMESTATEID_INITIAL)
     475        --(gameStateUsed.find(curid)->second);
     476      return;
     477    }
    438478    if(curid > gamestateID)
    439479      // the network packets got messed up
     
    446486      --(gameStateUsed.find(curid)->second);
    447487    ++(gameStateUsed.find(gamestateID)->second);
    448     temp->setGamestateID(gamestateID);
     488    temp->setGameStateID(gamestateID);
    449489    /*
    450490    GameState *old = clientGameState[clientID];
  • code/trunk/src/network/GameStateManager.h

    r1293 r1502  
    7272    ~GameStateManager();
    7373   
     74    void addGameState(GameStateCompressed *gs, int clientID);
     75    void processGameStates();
     76   
    7477    void update();
    7578    GameStateCompressed *popGameState(int clientID);
    76     bool pushGameState(GameStateCompressed *gs, int clientID);
    7779    void ackGameState(int clientID, int gamestateID);
    7880    void removeClient(ClientInformation *client);
    79   private:
     81    private:
     82    bool pushGameState(GameStateCompressed *gs, int clientID);
    8083    void cleanup(); // "garbage handler"
    8184    GameState *getSnapshot();
     
    8386    GameStateCompressed *encode(GameState *a, GameState *b);
    8487    GameStateCompressed *encode(GameState *a);
    85     GameState *diff(GameState *a, GameState *b);
     88    GameState *diff(GameState *alt, GameState *neu);
    8689    GameStateCompressed *compress_(GameState *a);
    8790    GameState *decompress(GameStateCompressed *a);
     
    9194    std::map<int, GameState*> gameStateMap; //map gsID to gamestate*
    9295    std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate
     96    std::map<int, GameStateCompressed*> gameStateQueue;
    9397    GameState *reference;
    9498    ClientInformation *head_;
  • code/trunk/src/network/NetworkPrereqs.h

    r1360 r1502  
    3535#define _NetworkPrereqs_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939//-----------------------------------------------------------------------
     
    5454#else
    5555#  define _NetworkExport
    56 #endif
    57 
    58 //-----------------------------------------------------------------------
    59 // fixed width integers
    60 //-----------------------------------------------------------------------
    61 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
    62 typedef __int8            int8_t;
    63 typedef __int16           int16_t;
    64 typedef __int32           int32_t;
    65 typedef __int64           int64_t;
    66 typedef unsigned __int8   uint8_t;
    67 typedef unsigned __int16  uint16_t;
    68 typedef unsigned __int32  uint32_t;
    69 typedef unsigned __int64  uint64_t;
    70 #else
    71 # include "inttypes.h"
    7256#endif
    7357
  • code/trunk/src/network/PacketBuffer.cc

    r1360 r1502  
    6262      last->next=NULL;
    6363      // change this!!!!!!!  ---- we are not doing stl so we won't change this
    64       last->packet = ev->packet;
    65       last->address = ev->peer->address;
     64      last->event = ev;
    6665      //last->address = ev->peer->address;
    6766    } else {
     
    7271      last->next=NULL;
    7372      // save the packet to the new element
    74       last->packet = ev->packet;
    75       last->address = ev->peer->address;
     73      last->event = ev;
    7674      //last->address = ev->peer->address;
    7775    }
     
    8280  //returns the first element in the list without deleting it but
    8381  //moving first pointer to next element
    84   ENetPacket *PacketBuffer::pop() {
     82  /*ENetPacket *PacketBuffer::pop() {
    8583    ENetAddress address;
    8684    return pop(address);
    87   }
    88 
    89   ENetPacket *PacketBuffer::pop(ENetAddress &address) {
     85  }*/
     86 
     87  ENetEvent *PacketBuffer::pop(){
    9088    boost::recursive_mutex::scoped_lock lock(mutex_);
    9189    //std::cout << "packetbuffer pop(address)" << std::endl;
     
    9391      QueueItem *temp = first;
    9492      // get packet
    95       ENetPacket *pck=first->packet;
    96       address = first->address;
     93      ENetEvent *ev=first->event;
     94      //address = first->address;
     95      // remove first element
     96      first = first->next;
     97      delete temp;
     98      lock.unlock();
     99      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
     100      return ev;
     101    } else{
     102      lock.unlock();
     103      return NULL;
     104    }
     105  }
     106
     107  /*ENetPacket *PacketBuffer::pop(ENetAddress &address) {
     108    boost::recursive_mutex::scoped_lock lock(mutex_);
     109    //std::cout << "packetbuffer pop(address)" << std::endl;
     110    if(first!=NULL ){
     111      QueueItem *temp = first;
     112      // get packet
     113      ENetPacket *pck=first->event->packet;
     114      address = first->event->peer->address;
    97115      // remove first element
    98116      first = first->next;
     
    105123      return NULL;
    106124    }
    107   }
     125  }*/
    108126
    109127  bool PacketBuffer::isEmpty() {
  • code/trunk/src/network/PacketBuffer.h

    r1360 r1502  
    5555
    5656  struct QueueItem{
    57     ENetPacket *packet;
    58     ENetAddress address;
     57    ENetEvent *event;
     58    //ENetAddress address;
    5959    QueueItem *next;
    6060  };
     
    6868    void print();
    6969    // pops a packet from the queue
    70     ENetPacket *pop();
    71     ENetPacket *pop(ENetAddress &address);
     70    //ENetPacket *pop();
     71    //ENetPacket *pop(ENetAddress &address);
     72    ENetEvent *pop();
    7273    // pushs a packet to the queue
    7374    bool push(ENetEvent *ev);
  • code/trunk/src/network/PacketDecoder.cc

    r1360 r1502  
    6868    case COMMAND:
    6969      return command( packet, clientId );
    70     case MOUSE:
    71       mousem( packet, clientId );
    72       return true;
    73     case KEYBOARD:
    74       keystrike( packet, clientId );
    75       return true;
    7670    case CHAT:
    7771      chatMessage( packet, clientId );
     
    9084    return false;
    9185  }
    92  
     86
    9387  bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){
    9488    uint32_t submittetcrc;
     
    108102    return false;
    109103  }
    110  
     104
    111105  // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function
    112106
     
    124118    enet_packet_destroy( packet );
    125119  }
    126  
     120
    127121  bool PacketDecoder::command( ENetPacket* packet, int clientId ){
    128122    int length = *(int*)((unsigned char *)packet->data+sizeof(int));
     123    if(length<=0)
     124      return false;
    129125    void *data = (void *)new unsigned char[length];
    130126    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
     
    133129  }
    134130
    135   void PacketDecoder::mousem( ENetPacket* packet, int clientId )
    136   {
    137     mouse* mouseMove = new mouse;
    138     //copy data of packet->data to new struct
    139     *mouseMove = *(mouse*)packet->data;
    140 
    141     //clean memory
    142     enet_packet_destroy( packet );
    143     printMouse( mouseMove ); //debug info
    144   }
    145 
    146   void PacketDecoder::keystrike( ENetPacket* packet, int clientId )
    147   {
    148     keyboard* key = new keyboard;
    149     *key = *(keyboard*)packet->data; //see above
    150 
    151     //clean memory
    152     enet_packet_destroy( packet );
    153     printKey( key ); //debug info
    154 
    155   }
    156 
    157131  void PacketDecoder::chatMessage( ENetPacket* packet, int clientId )
    158132  {
    159133    chat* chatting = new chat;
     134    if(packet->dataLength==4)
     135      return;
    160136    chatting->id = (int)*packet->data; //first copy id into new struct
    161137    //since the chat message is a char*, allocate the memory needed
     
    185161      return;
    186162    }
    187     //since it's not alowed to use void* for pointer arithmetic
    188     //FIXME: variable never used
    189     unsigned char* data = (unsigned char *)(packet->data);
    190163    //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
    191164    memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) );
     
    202175    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
    203176    if(currentState->compsize==0)
     177    {
    204178      COUT(2) << "PacketDecoder: compsize is 0" << std::endl;
     179    }
    205180//     currentState->data = (unsigned char*)(malloc( currentState->compsize ));
     181    if(currentState->compsize==0)
     182      return;
    206183    currentState->data = new unsigned char[currentState->compsize];
    207184    if(currentState->data==NULL)
     185    {
    208186      COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl;
     187    }
    209188    //copy the GameStateCompressed data
    210189    memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + 2*sizeof(bool)), currentState->compsize );
     
    221200    cid->id = ((classid *)(packet->data))->id;
    222201    cid->clid = ((classid *)(packet->data))->clid;
     202    if(cid->length==0)
     203      return;
    223204//     cid->message = (const char *)malloc(cid->length);
    224205    cid->message = new char[cid->length];
     
    229210    processClassid(cid);
    230211  }
    231  
    232  
     212
     213
    233214  bool PacketDecoder::decodeWelcome( ENetPacket* packet, int clientID ){
    234215    welcome *w = new welcome;
     
    240221    return processWelcome(w);
    241222  }
    242  
     223
    243224  bool PacketDecoder::decodeConnectRequest( ENetPacket *packet, int clientID ){
    244225    connectRequest *con = new connectRequest;
     
    279260    return;
    280261  }
    281  
     262
    282263  bool PacketDecoder::processWelcome( welcome *w ){
    283264    delete w;
    284265    return true;
    285266  }
    286  
     267
    287268  bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){
    288269    COUT(3) << "packetdecoder: processing connectRequest" << std::endl;
     
    299280  }
    300281
    301   void PacketDecoder::printMouse( mouse* data )
    302   {
    303     COUT(5) << "data id: " << data->id << std::endl;
    304     COUT(5) << "data:    " << data->x << " " << data->y << std::endl;
    305   }
    306 
    307   void PacketDecoder::printKey( keyboard* data )
    308   {
    309     COUT(5) << "data id: " << data->id << std::endl;
    310     COUT(5) << "data:    " << (char)data->press << std::endl;
    311   }
    312282
    313283  void PacketDecoder::printChat( chat* data, int clientId )
    314284  {
    315285    if(clientId!=CLIENTID_CLIENT)
     286    {
    316287      COUT(5) << "client: " << clientId << std::endl;
     288    }
    317289    COUT(5) << "data id: " << data->id << std::endl;
    318290    COUT(5) << "data:    " << data->message << std::endl;
  • code/trunk/src/network/PacketGenerator.cc

    r1360 r1502  
    7878  {
    7979    COUT(4) << "PacketGenerator: generating new acknowledgement, id: " << state << std::endl;
    80     ack* ackreq = new ack;
     80   
     81    ENetPacket *packet = enet_packet_create( NULL , sizeof( ack ), reliable );
     82    ack* ackreq = (ack *)packet->data;
    8183    ackreq->id = ACK;
    8284    ackreq->a = state;
    83 
    84     ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable );
    85     delete ackreq;
     85    //delete ackreq;
    8686    return packet;
    8787  }
     
    8989  ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE )
    9090  {
     91    if(dataLength==0)
     92      return NULL;
    9193    unsigned char *stream = new unsigned char[dataLength + 2*sizeof(int)];
    9294    if(!stream)
     
    101103  }
    102104
    103   /*### mouseupdates */
    104   ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )
    105   {
    106     COUT(4) << "PacketGenerator: generating new mouse" << std::endl;
    107     mouse* mousemove = new mouse;
    108     mousemove->id = MOUSE;
    109     mousemove->x = x;
    110     mousemove->y = y;
    111 
    112     ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable );
    113     delete mousemove;
    114     return packet;
    115   }
    116 
    117   /*### keystrikes updates */
    118   ENetPacket* PacketGenerator::keystrike( char press, int reliable )
    119   {
    120     COUT(4) << "PacketGenerator: generating new keyboard" << std::endl;
    121     keyboard* key = new keyboard;
    122     key->id = KEYBOARD;
    123     key->press = press;
    124 
    125     ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable );
    126     delete key;
    127     return packet;
    128   }
    129105
    130106  /*### chat messages packet */
     
    150126    //std::cout << "totalLen " << totalLen << std::endl;
    151127    //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
    152     unsigned char *data = new unsigned char[totalLen];
     128    if(totalLen==0)
     129      return NULL;
     130    ENetPacket *packet = enet_packet_create( NULL , totalLen+sizeof(uint32_t), reliable );
     131    //unsigned char *data = new unsigned char[totalLen];
     132    unsigned char *data = packet->data;
    153133    memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id
    154134    memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
     
    163143    //create an enet packet with the generated bytestream
    164144    COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
    165     ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
    166     delete[] data;
     145    //delete[] data;
    167146    if(!addCRC(packet))
    168147      COUT(3) << "could not add crc to gamestate packet" << std::endl;
     
    173152  {
    174153    //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
     154    if(classname.length()==0)
     155      return NULL;
    175156    unsigned char *data = new unsigned char[3*sizeof(int)+classname.length()+1];
    176157    std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl;
     
    206187  bool PacketGenerator::addCRC( ENetPacket *packet){
    207188    unsigned char *data = packet->data;
    208     uint32_t crc32=calcCRC(data, packet->dataLength);
     189    uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t));
    209190    // now append the crc to the packet data
    210     int oldlength = packet->dataLength;
    211     if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){
     191    int oldlength = packet->dataLength-sizeof(uint32_t);
     192    //if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){
    212193      memcpy(&packet->data[oldlength], &crc32, sizeof(uint32_t));
    213194      return true;
    214     }else{
    215       COUT(3) << "could not add crc to gamestate" << std::endl;
    216       return false;
    217     }
     195    //}else{
     196     // COUT(3) << "could not add crc to gamestate" << std::endl;
     197     // return false;
     198    //}
    218199  }
    219200
  • code/trunk/src/network/PacketManager.h

    r1360 r1502  
    5959    ENetPacket* acknowledgement( int state, int reliable = 0 ); // we do not want reliability
    6060    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
    61     ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
    62     ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
    6361    ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
    6462    ENetPacket* gstate( GameStateCompressed *states, int reliable = 0 ); // we do not want reliability of gamestates
     
    9492    void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
    9593    bool command( ENetPacket* packet, int clientId );
    96     void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
    97     void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
    9894    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
    9995    void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
     
    113109    //print functions
    114110    void printAck( ack* data );
    115     void printMouse( mouse* data );
    116     void printKey( keyboard* data );
    117111    void printChat( chat* data, int clientId );
    118112    void printGamestate( GameStateCompressed *data );
  • code/trunk/src/network/PacketTypes.h

    r1293 r1502  
    4848  enum packet_id {
    4949    ACK,
    50     MOUSE,
    5150    COMMAND,
    52     KEYBOARD,
    5351    CHAT,
    5452    GAMESTATE ,
     
    104102  };
    105103
    106   struct mouse {
    107     int id;
    108     double x;
    109     double y;
    110   };
    111 
    112   struct keyboard {
    113     int id;
    114     char press;
    115   };
    116104  //only in this class, not PacketGenerator, used as pattern to put incoming
    117105  //bytes inside
  • code/trunk/src/network/Server.cc

    r1360 r1502  
    4242
    4343#include <iostream>
     44
    4445
    4546#include "ConnectionManager.h"
     
    4950//#include "NetworkFrameListener.h"
    5051#include "util/Sleep.h"
     52#include "objects/SpaceShip.h"
    5153
    5254
     
    5658 
    5759#define MAX_FAILURES 20;
    58  
     60#define NETWORK_FREQUENCY 30
    5961 
    6062  /**
     
    6365  */
    6466  Server::Server() {
     67    timeSinceLastUpdate_=0;
    6568    packet_gen = PacketGenerator();
    6669    clients = new ClientInformation(true);
     
    6871    gamestates = new GameStateManager(clients);
    6972  }
     73 
     74  Server::Server(int port){
     75    timeSinceLastUpdate_=0;
     76    packet_gen = PacketGenerator();
     77    clients = new ClientInformation(true);
     78    connection = new ConnectionManager(clients, port);
     79    gamestates = new GameStateManager(clients);
     80  }
    7081
    7182  /**
     
    7586  */
    7687  Server::Server(int port, std::string bindAddress) {
     88    timeSinceLastUpdate_=0;
    7789    packet_gen = PacketGenerator();
    7890    clients = new ClientInformation();
     
    8799  */
    88100  Server::Server(int port, const char *bindAddress) {
     101    timeSinceLastUpdate_=0;
    89102    packet_gen = PacketGenerator();
    90103    clients = new ClientInformation();
     
    117130    ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
    118131    //std::cout <<"adding packets" << std::endl;
    119     if(connection->addPacketAll(packet))
    120     //std::cout <<"added packets" << std::endl;
    121       return connection->sendPackets();
    122     else
    123       return false;
     132    return connection->addPacketAll(packet);
    124133  }
    125134
     
    132141    ENetPacket *packet = packet_gen.chatMessage(msg);
    133142    COUT(4) <<"Server: adding Packets" << std::endl;
    134     connection->addPacketAll(packet);
    135     //std::cout <<"added packets" << std::endl;
    136     if (connection->sendPackets()){
    137       COUT(4) << "Server: Sucessfully" << std::endl;
    138       return true;
    139     }
    140     return false;
     143    return connection->addPacketAll(packet);
    141144  }
    142145
     
    148151  void Server::tick(float time) {
    149152    processQueue();
    150     updateGamestate();
    151 //     usleep(500000); // TODO remove
     153    //this steers our network frequency
     154    timeSinceLastUpdate_+=time;
     155    if(timeSinceLastUpdate_>=(1./NETWORK_FREQUENCY)){
     156      timeSinceLastUpdate_-=(1./NETWORK_FREQUENCY);
     157      gamestates->processGameStates();
     158      updateGamestate();
     159    }
     160//     usleep(5000); // TODO remove
    152161    return;
    153162  }
     
    157166  */
    158167  void Server::processQueue() {
    159     ENetPacket *packet;
     168    ENetEvent *event;
    160169    int clientID=-1;
    161170    while(!connection->queueEmpty()){
    162171      //std::cout << "Client " << clientID << " sent: " << std::endl;
    163172      //clientID here is a reference to grab clientID from ClientInformation
    164       packet = connection->getPacket(clientID);
    165       if(!packet)
    166         continue;
     173      event = connection->getEvent();
     174      if(!event)
     175        continue;
     176      assert(event->type != ENET_EVENT_TYPE_NONE);
     177      switch( event->type ) {
     178      case ENET_EVENT_TYPE_CONNECT:
     179        COUT(3) << "processing event_Type_connect" << std::endl;
     180        addClient(event);
     181        break;
     182      case ENET_EVENT_TYPE_DISCONNECT:
     183        if(clients->findClient(&event->peer->address))
     184          disconnectClient(event);
     185        break;
     186      case ENET_EVENT_TYPE_RECEIVE:
     187        if(clients->findClient(&event->peer->address)){
     188          clientID = clients->findClient(&event->peer->address)->getID();
     189          if( !elaborate(event->packet, clientID) )
     190            COUT(3) << "Server: could not elaborate" << std::endl;
     191        }
     192        break;
     193      }
     194      delete event;
    167195      //if statement to catch case that packetbuffer is empty
    168       if( !elaborate(packet, clientID) )
    169         COUT(3) << "Server: could not elaborate" << std::endl;
    170196    }
    171197  }
     
    210236      if(gs==NULL){
    211237        COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
    212         return false;
     238        continue;
    213239      }
    214240      //std::cout << "adding gamestate" << std::endl;
    215       if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) ){
     241      ENetPacket *packet = packet_gen.gstate(gs);
     242      if(!packet)
     243        continue;
     244      if ( !(connection->addPacket(packet, cid)) ){
    216245        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    217246        temp->addFailure();
    218         if(temp->getFailures() > 20 )
    219           disconnectClient(temp);
     247        /*if(temp->getFailures() > 0 )
     248          disconnectClient(temp);*/
    220249      //std::cout << "added gamestate" << std::endl;
    221       }
     250      }else
     251        temp->resetFailures();
    222252      added=true;
    223253      temp=temp->next();
     
    226256      delete gs;
    227257    }
    228     if(added) {
     258    /*if(added) {
    229259      //std::cout << "send gamestates from server.cc in sendGameState" << std::endl;
    230260      return connection->sendPackets();
    231     }
    232     COUT(5) << "Server: had no gamestates to send" << std::endl;
    233     return false;
     261    }*/
     262    //COUT(5) << "Server: had no gamestates to send" << std::endl;
     263    return true;
    234264  }
    235265
    236266  void Server::processAck( ack *data, int clientID) {
    237     COUT(4) << "\b\b\b\n\n\n\n\nServer: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;
     267    COUT(4) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;
    238268    gamestates->ackGameState(clientID, data->a);
    239269    delete data;
     
    241271 
    242272  bool Server::processConnectRequest( connectRequest *con, int clientID ){
    243     COUT(3) << "processing connectRequest " << std::endl;
     273    //(COUT(3) << "processing connectRequest " << std::endl;
    244274    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
    245     connection->createClient(clientID);
     275    //createClient(clientID);
    246276    delete con;
    247277    return true;
     
    250280  void Server::processGamestate( GameStateCompressed *data, int clientID){
    251281    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
    252     if(!gamestates->pushGameState(data, clientID))
    253         COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
     282    gamestates->addGameState(data, clientID);
     283        /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
    254284    else
    255285      if(clients->findClient(clientID))
    256         clients->findClient(clientID)->resetFailures();
     286        clients->findClient(clientID)->resetFailures();*/
     287  }
     288 
     289  bool Server::addClient(ENetEvent *event){
     290    ClientInformation *temp = clients->insertBack(new ClientInformation);
     291    if(!temp){
     292      COUT(2) << "Server: could not add client" << std::endl;
     293      return false;
     294    }
     295    if(temp->prev()->getHead()) { //not good if you use anything else than insertBack
     296      temp->prev()->setID(0); //bugfix: not necessary but usefull
     297      temp->setID(1);
     298    }
     299    else
     300      temp->setID(temp->prev()->getID()+1);
     301    temp->setPeer(event->peer);
     302    COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
     303    return createClient(temp->getID());
     304  }
     305 
     306  bool Server::createClient(int clientID){
     307    ClientInformation *temp = clients->findClient(clientID);
     308    if(!temp){
     309      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
     310      return false;
     311    }
     312    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     313    connection->syncClassid(temp->getID());
     314    COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
     315    // TODO: this is only a hack, untill we have a possibility to define default player-join actions
     316    if(!createShip(temp))
     317      COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;
     318    else
     319      COUT(3) << "created spaceship" << std::endl;
     320    temp->setSynched(true);
     321    COUT(3) << "sending welcome" << std::endl;
     322    connection->sendWelcome(temp->getID(), temp->getShipID(), true);
     323    return true;
     324  }
     325 
     326  bool Server::createShip(ClientInformation *client){
     327    if(!client)
     328      return false;
     329    orxonox::Identifier* id = ID("SpaceShip");
     330    if(!id){
     331      COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;
     332      return false;
     333    }
     334    orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
     335    no->setPosition(orxonox::Vector3(0,0,80));
     336    no->setScale(10);
     337    //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));
     338    no->setMesh("assff.mesh");
     339    no->setMaxSpeed(500);
     340    no->setMaxSideAndBackSpeed(50);
     341    no->setMaxRotation(1.0);
     342    no->setTransAcc(200);
     343    no->setRotAcc(3.0);
     344    no->setTransDamp(75);
     345    no->setRotDamp(1.0);
     346    no->setCamera("cam_"+client->getID());
     347    no->classID = id->getNetworkID();
     348    no->create();
     349   
     350    client->setShipID(no->objectID);
     351    return true;
     352  }
     353 
     354  bool Server::disconnectClient(ENetEvent *event){
     355    COUT(4) << "removing client from list" << std::endl;
     356    //return removeClient(head_->findClient(&(peer->address))->getID());
     357   
     358    //boost::recursive_mutex::scoped_lock lock(head_->mutex_);
     359    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     360    ClientInformation *client = clients->findClient(&event->peer->address);
     361    if(!client)
     362      return false;
     363    while(it){
     364      if(it->objectID!=client->getShipID()){
     365        ++it;
     366        continue;
     367      }
     368      orxonox::Iterator<orxonox::SpaceShip> temp=it;
     369      ++it;
     370      delete  *temp;
     371      return clients->removeClient(event->peer);
     372    }
     373    return false;
    257374  }
    258375
  • code/trunk/src/network/Server.h

    r1293 r1502  
    6060  public:
    6161    Server();
     62    Server(int port);
    6263    Server(int port, std::string bindAddress);
    6364    Server(int port, const char *bindAddress);
     
    7172    void updateGamestate();
    7273  private:
     74    bool addClient(ENetEvent *event);
     75    bool createClient(int clientID);
     76    bool createShip(ClientInformation *client);
     77    bool disconnectClient(ENetEvent *event);
    7378    void disconnectClient(int clientID);
    7479    void disconnectClient( ClientInformation *client);
     
    8287
    8388    ClientInformation *clients;
     89    float timeSinceLastUpdate_;
    8490  };
    8591
  • code/trunk/src/network/Synchronisable.cc

    r1360 r1502  
    6666
    6767  Synchronisable::~Synchronisable(){
     68  }
     69 
     70  bool Synchronisable::create(){
     71    this->classID = this->getIdentifier()->getNetworkID();
     72    COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
     73    return true;
    6874  }
    6975 
     
    151157  * @return data containing all variables and their sizes
    152158  */
    153   syncData Synchronisable::getData(unsigned char *mem){
     159  syncData Synchronisable::getData(unsigned char *mem, int mode){
    154160    //std::cout << "inside getData" << std::endl;
     161    if(mode==0x0)
     162      mode=state_;
    155163    if(classID==0)
    156164      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     
    167175    for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
    168176      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
    169       if( ((*i)->mode & state_) == 0 ){
     177      if( ((*i)->mode & mode) == 0 ){
    170178        COUT(5) << "not getting data: " << std::endl;
    171179        continue;  // this variable should only be received
     
    194202  * @return true/false
    195203  */
    196   bool Synchronisable::updateData(syncData vars){
     204  bool Synchronisable::updateData(syncData vars, int mode){
     205    if(mode==0x0)
     206      mode=state_;
    197207    unsigned char *data=vars.data;
    198208    std::list<synchronisableVariable *>::iterator i;
     
    203213    COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl;
    204214    for(i=syncList->begin(); i!=syncList->end(); i++){
    205       if( ((*i)->mode ^ state_) == 0 ){
     215      if( ((*i)->mode ^ mode) == 0 ){
    206216        COUT(5) << "synchronisable: not updating variable " << std::endl;
    207         continue;  // this variable should only be updated
     217        continue;  // this variable should only be set
    208218      }
    209219      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
     
    230240  * @return amount of bytes
    231241  */
    232   int Synchronisable::getSize(){
     242  int Synchronisable::getSize(int mode){
    233243    int tsize=0;
     244    if(mode==0x0)
     245      mode=state_;
    234246    std::list<synchronisableVariable *>::iterator i;
    235247    for(i=syncList->begin(); i!=syncList->end(); i++){
    236       if( ((*i)->mode & state_) == 0 )
     248      if( ((*i)->mode & mode) == 0 )
    237249        continue;  // this variable should only be received, so dont add its size to the send-size
    238250      switch((*i)->type){
  • code/trunk/src/network/Synchronisable.h

    r1293 r1502  
    8383    void registerVar(void *var, int size, variableType t, int mode=1);
    8484    //  syncData getData();
    85     syncData getData(unsigned char *mem);
    86     int getSize();
    87     bool updateData(syncData vars);
     85    syncData getData(unsigned char *mem, int mode=0x0);
     86    int getSize(int mode=0x0);
     87    bool updateData(syncData vars, int mode=0x0);
    8888    void setBacksync(bool sync);
    8989    bool getBacksync();
    9090    virtual void registerAllVariables()=0;
    91     virtual bool create()=0;
     91    virtual bool create();
    9292    static void setClient(bool b);
    9393  protected:
  • code/trunk/src/network/diffTest.cc

    r1360 r1502  
    549549
    550550  std::cout << "test setGamestateID" << std::endl;
    551   temp->setGamestateID( 8 );
     551  temp->setGameStateID( 8 );
    552552  printClientInformationBox( temp );
    553553
     
    559559  newInfo->setSynched( true );
    560560  newInfo->setPeer( NULL );
    561   toool->setGamestateID( 199 );
     561  toool->setGameStateID( 199 );
    562562  toool->setID( numberOfClients+1);
    563563  toool->setSynched( true );
  • code/trunk/src/network/dummyclient3.cc

    r1293 r1502  
    5151  Client client( str, PORT );
    5252  if ( client.establishConnection() )
     53  {
    5354    COUT(3) << "connection established" << std::endl;
    54   else COUT(0) << "problems establishing connection" << std::endl;
     55  }
     56  else
     57  {
     58    COUT(0) << "problems establishing connection" << std::endl;
     59  }
    5560  char message[10000];
    5661  char signs[] = "abcdefghijklmnopqrstuvwxy";
  • code/trunk/src/ois/CMakeLists.txt

    r1219 r1502  
    3737
    3838ADD_LIBRARY( ois SHARED ${OIS_SRC_FILES} )
     39
     40IF(WIN32)
     41  LINK_DIRECTORIES(${DirectX_LIB_DIR})
     42  TARGET_LINK_LIBRARIES( ois
     43    dxguid
     44    dinput8
     45  )
     46ENDIF(WIN32)
     47
  • code/trunk/src/ois/OISException.cpp

    r1219 r1502  
    2626
    2727//----------------------------------------------------------------------------//
    28 const char* Exception::what() const throw()
     28/*const char* Exception::what() const throw()
    2929{
    3030        return eText;
    3131}
    32 
     32*/
  • code/trunk/src/ois/OISException.h

    r1219 r1502  
    5858                        : eType(err), eLine(line), eFile(file), eText(str) {}
    5959
    60                 ~Exception() throw() {}
    61 
    62                 virtual const char* what() const throw();
     60                virtual const char* what() const throw()
     61            { return eText; }
    6362
    6463                //! The type of exception raised
  • code/trunk/src/orxonox/CMakeLists.txt

    r1407 r1502  
    99  hud/RadarOverlayElement.cc
    1010  hud/RadarObject.cc
     11  hud/Navigation.cc
    1112  particle/ParticleInterface.cc
    1213  tolua/tolua_bind.cc
     
    2425  objects/NPC.cc
    2526  objects/Projectile.cc
     27  objects/RotatingProjectile.cc
    2628  objects/Skybox.cc
    2729  objects/SpaceShip.cc
     30  objects/SpaceShipAI.cc
    2831  objects/WorldEntity.cc
    2932
  • code/trunk/src/orxonox/GraphicsEngine.cc

    r1349 r1502  
    4545#include "core/Debug.h"
    4646#include "core/CommandExecutor.h"
    47 
     47#include "core/TclBind.h"
     48#include "console/InGameConsole.h"
     49
     50#include "core/ConsoleCommand.h"
     51#include <OgreSceneManager.h>
     52#include <OgreCompositorManager.h>
     53#include <OgreViewport.h>
    4854
    4955namespace orxonox {
    50 
    5156  /**
    5257    @brief Returns the singleton instance and creates it the first time.
     
    8388    SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    8489    SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
     90
     91    TclBind::getInstance().setDataPath(this->dataPath_);
    8592  }
    8693
     
    137144#endif
    138145
    139 /*    // create a logManager
     146// TODO: LogManager doesn't work on specific systems. The why is unknown yet.
     147#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     148    // create a logManager
    140149    // note: If there's already a logManager, Ogre will complain by a failed assertation.
    141150    // but that shouldn't happen, since this is the first time to create a logManager..
     
    148157      myLog = logger->createLog("ogre.log", true, false, true);
    149158    else
    150           myLog = logger->createLog(this->ogreLogfile_, true, false, false);
     159      myLog = logger->createLog(this->ogreLogfile_, true, false, false);
    151160    CCOUT(4) << "Ogre Log created" << std::endl;
    152161
    153162    myLog->setLogDetail(Ogre::LL_BOREME);
    154     myLog->addListener(this);*/
     163    myLog->addListener(this);
     164#endif
    155165
    156166    // Root will detect that we've already created a Log
    157167    CCOUT(4) << "Creating Ogre Root..." << std::endl;
    158     root_ = new Ogre::Root(plugin_filename);
     168
     169    root_ = new Ogre::Root(plugin_filename, "ogre.cfg", this->ogreLogfile_);
     170
     171#if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32
     172    // tame the ogre ouput so we don't get all the mess in the console
     173    Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
     174    defaultLog->setDebugOutputEnabled(false);
     175    defaultLog->setLogDetail(Ogre::LL_BOREME);
     176    defaultLog->addListener(this);
     177#endif
     178
    159179    CCOUT(4) << "Creating Ogre Root done" << std::endl;
    160180
     
    241261  bool GraphicsEngine::createNewScene()
    242262  {
    243     CCOUT(4) << "Creating new SceneManager" << std::endl;
     263    CCOUT(4) << "Creating new SceneManager..." << std::endl;
    244264    if (scene_)
    245265    {
     
    291311    else
    292312      return 0;
     313  }
     314
     315  /**
     316    @brief Returns the window aspect ratio height/width.
     317    @return The ratio
     318  */
     319  float GraphicsEngine::getWindowAspectRatio() const
     320  {
     321    if (this->renderWindow_)
     322        return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth();
     323    else
     324        return 1.0f;
    293325  }
    294326
     
    345377    int h = rw->getHeight();
    346378    InputManager::setWindowExtents(w, h);
     379    InGameConsole::getInstance().resize();
    347380  }
    348381
     
    365398    CommandExecutor::execute("exit", false);
    366399  }
     400
     401  //HACK!!
     402  /*SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOn).setAccessLevel(AccessLevel::User);
     403  SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOn).setAccessLevel(AccessLevel::User);
     404  SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOff).setAccessLevel(AccessLevel::User);
     405  SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOff).setAccessLevel(AccessLevel::User);
     406  void GraphicsEngine::CompositorBloomOn()
     407  {
     408    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     409    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     410    Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom");
     411    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", true);
     412  }
     413  void GraphicsEngine::CompositorBloomOff()
     414  {
     415    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     416    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     417    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", false);
     418  }
     419
     420  void GraphicsEngine::CompositorMotionBlurOn()
     421  {
     422    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     423    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     424    Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur");
     425    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", true);
     426  }
     427  void GraphicsEngine::CompositorMotionBlurOff()
     428  {
     429    Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     430    Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     431    Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", false);
     432  }*/
    367433}
  • code/trunk/src/orxonox/GraphicsEngine.h

    r1293 r1502  
    7272            int getWindowWidth() const;
    7373            int getWindowHeight() const;
     74            float getWindowAspectRatio() const;
     75            float getAverageFPS() const
     76            { if (renderWindow_) return this->renderWindow_->getAverageFPS(); else return 0.0f; }
    7477
    7578            void windowMoved       (Ogre::RenderWindow* rw);
     
    8083            static GraphicsEngine& getSingleton();
    8184            static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }
     85
     86            //HACK!!!
     87            //void static CompositorBloomOn();
     88            //void static CompositorBloomOff();
     89            //void static CompositorMotionBlurOn();
     90            //void static CompositorMotionBlurOff();
     91
    8292
    8393        private:
  • code/trunk/src/orxonox/Main.cc

    r1293 r1502  
    3636#include <exception>
    3737
    38 #include "OrxonoxPlatform.h"
     38#include "util/OrxonoxPlatform.h"
    3939#include "core/SignalHandler.h"
    4040#include "Orxonox.h"
  • code/trunk/src/orxonox/Orxonox.cc

    r1407 r1502  
    5151//#include "util/Sleep.h"
    5252#include "util/ArgReader.h"
    53 #include "util/ExprParser.h"
    5453
    5554// core
     
    5756#include "core/ConsoleCommand.h"
    5857#include "core/Debug.h"
    59 #include "core/Factory.h"
    6058#include "core/Loader.h"
    6159#include "core/Tickable.h"
    62 #include "core/InputBuffer.h"
    6360#include "core/InputManager.h"
    6461#include "core/TclBind.h"
     
    7269
    7370// objects and tools
    74 #include "tools/Timer.h"
    7571#include "hud/HUD.h"
    76 #include "console/InGameConsole.h"
     72#include <Ogre.h>
     73
     74#include "GraphicsEngine.h"
    7775
    7876// FIXME: is this really file scope?
     
    8381namespace orxonox
    8482{
    85   ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None).setKeybindMode(KeybindMode::OnPress);
    86   ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0)
    87     .setAxisParamIndex(0).setIsAxisRelative(false);
    88   ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0);
    89   ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None);
    90   class Testconsole : public InputBufferListener
    91   {
    92     public:
    93       Testconsole(InputBuffer* ib) : ib_(ib) {}
    94       void listen() const
    95       {
    96         std::cout << "> " << this->ib_->get() << std::endl;
    97       }
    98       void execute() const
    99       {
    100         std::cout << ">> " << this->ib_->get() << std::endl;
    101         if (!CommandExecutor::execute(this->ib_->get()))
    102           std::cout << "Error" << std::endl;
    103         this->ib_->clear();
    104       }
    105       void hintandcomplete() const
    106       {
    107         std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl;
    108         this->ib_->set(CommandExecutor::complete(this->ib_->get()));
    109       }
    110       void clear() const
    111       {
    112         this->ib_->clear();
    113       }
    114       void removeLast() const
    115       {
    116         this->ib_->removeLast();
    117       }
    118       void exit() const
    119       {
    120         InputManager::setInputState(InputManager::IS_NORMAL);
    121       }
    122 
    123     private:
    124       InputBuffer* ib_;
    125   };
    126 
    127   class Calculator
    128   {
    129   public:
    130     static float calculate(const std::string& calculation)
    131     {
    132       ExprParser expr(calculation);
    133       if (expr.getSuccess())
    134       {
    135         if (expr.getResult() == 42.0)
    136           std::cout << "Greetings from the restaurant at the end of the universe." << std::endl;
    137         // FIXME: insert modifier to display in full precision
    138         std::cout << "Result is: " << expr.getResult() << std::endl;
    139         if (expr.getRemains() != "")
    140           std::cout << "Warning: Expression could not be parsed to the end! Remains: '"
    141               << expr.getRemains() << "'" << std::endl;
    142         return expr.getResult();
    143       }
    144       else
    145       {
    146         std::cout << "Cannot calculate expression: Parse error" << std::endl;
    147         return 0;
    148       }
    149     }
    150   };
    151   ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None);
     83  SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress);
     84  SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false);
     85  SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0);
    15286
    15387  /**
     
    16599    // turn on frame smoothing by setting a value different from 0
    166100    frameSmoothingTime_(0.0f),
    167     orxonoxConsole_(0),
    168101    orxonoxHUD_(0),
    169102    bAbort_(false),
    170103    timefactor_(1.0f),
    171104    mode_(STANDALONE),
    172     serverIp_("")
     105    serverIp_(""),
     106    serverPort_(NETWORK_PORT)
    173107  {
    174108  }
     
    180114  {
    181115    // keep in mind: the order of deletion is very important!
    182     if (this->orxonoxHUD_)
    183       delete this->orxonoxHUD_;
     116//    if (this->orxonoxHUD_)
     117//      delete this->orxonoxHUD_;
    184118    Loader::close();
    185119    InputManager::destroy();
     
    244178    ar.checkArgument("data", dataPath, false);
    245179    ar.checkArgument("ip", serverIp_, false);
     180    ar.checkArgument("port", serverPort_, false);
    246181    if(ar.errorHandling())
    247182      return false;
     
    251186    else if (mode == "server")
    252187      mode_ = SERVER;
     188    else if (mode == "dedicated")
     189      mode_ = DEDICATED;
    253190    else
    254191    {
     
    265202    // procedure until the GUI is identical
    266203
    267     TclBind::getInstance().setDataPath(dataPath);
    268204    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    269205    Factory::createClassHierarchy();
     
    281217  bool Orxonox::start()
    282218  {
    283     //if (mode == DEDICATED)
    284     // do something else
    285     //else
    286 
    287     if (!ogre_->loadRenderer())    // creates the render window
    288       return false;
    289 
    290     // Calls the InputManager which sets up the input devices.
    291     // The render window width and height are used to set up the mouse movement.
    292     if (!InputManager::initialise(ogre_->getWindowHandle(),
    293           ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true))
    294       return false;
    295 
    296     // TODO: Spread this so that this call only initialises things needed for the GUI
    297     if (!ogre_->initialiseResources())
    298       return false;
    299 
    300     // TOOD: load the GUI here
    301     // set InputManager to GUI mode
    302     InputManager::setInputState(InputManager::IS_GUI);
    303     // TODO: run GUI here
    304 
    305     // The following lines depend very much on the GUI output, so they're probably misplaced here..
    306 
    307     InputManager::setInputState(InputManager::IS_NONE);
    308 
    309     if (!loadPlayground())
    310       return false;
     219    if (mode_ == DEDICATED)
     220    {
     221      // do something else
     222    }
     223    else
     224    { // not dedicated server
     225      if (!ogre_->loadRenderer())    // creates the render window
     226        return false;
     227
     228      // Calls the InputManager which sets up the input devices.
     229      // The render window width and height are used to set up the mouse movement.
     230      if (!InputManager::initialise(ogre_->getWindowHandle(),
     231            ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true))
     232        return false;
     233
     234      // TODO: Spread this so that this call only initialises things needed for the GUI
     235      if (!ogre_->initialiseResources())
     236        return false;
     237
     238      // TOOD: load the GUI here
     239      // set InputManager to GUI mode
     240      InputManager::setInputState(InputManager::IS_GUI);
     241      // TODO: run GUI here
     242
     243      // The following lines depend very much on the GUI output, so they're probably misplaced here..
     244
     245      InputManager::setInputState(InputManager::IS_NONE);
     246
     247      // create Ogre SceneManager
     248      ogre_->createNewScene();
     249
     250      if (!loadPlayground())
     251        return false;
     252    }
    311253
    312254    switch (mode_)
     
    320262        return false;
    321263      break;
     264    case DEDICATED:
     265      if (!serverLoad())
     266        return false;
     267      break;
    322268    default:
    323269      if (!standaloneLoad())
     
    336282  bool Orxonox::loadPlayground()
    337283  {
    338     ogre_->createNewScene();
    339 
    340           // Init audio
     284    // Init audio
    341285    //auMan_ = new audio::AudioManager();
    342286    //auMan_->ambientAdd("a1");
     
    348292    // Load the HUD
    349293    COUT(3) << "Orxonox: Loading HUD..." << std::endl;
    350     orxonoxHUD_ = new HUD(1);
    351 
    352     COUT(3) << "Orxonox: Loading Console..." << std::endl;
    353     InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));
    354     /*
    355     Testconsole* console = new Testconsole(ib);
    356     ib->registerListener(console, &Testconsole::listen, true);
    357     ib->registerListener(console, &Testconsole::execute, '\r', false);
    358     ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);
    359     ib->registerListener(console, &Testconsole::clear, '§', true);
    360     ib->registerListener(console, &Testconsole::removeLast, '\b', true);
    361     ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
    362     */
    363     orxonoxConsole_ = new InGameConsole(ib);
    364     ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);
    365     ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);
    366     ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);
    367     ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);
    368     ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);
    369     ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);
    370 
     294    orxonoxHUD_ = &HUD::getSingleton();
    371295    return true;
    372296  }
     
    379303    COUT(2) << "Loading level in server mode" << std::endl;
    380304
    381     server_g = new network::Server();
     305    server_g = new network::Server(serverPort_);
    382306
    383307    if (!loadScene())
     
    399323      client_g = network::Client::createSingleton();
    400324    else
    401       client_g = network::Client::createSingleton(serverIp_, NETWORK_PORT);
    402 
    403     client_g->establishConnection();
     325
     326      client_g = network::Client::createSingleton(serverIp_, serverPort_);
     327
     328    if(!client_g->establishConnection())
     329      return false;
    404330    client_g->tick(0);
    405331
     
    427353    Level* startlevel = new Level("levels/sample.oxw");
    428354    Loader::open(startlevel);
    429 
     355   
     356    // HACK: shader stuff for presentation
     357    /*Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     358    mSceneMgr->setAmbientLight(ColourValue(0.4,0.4,0.4));
     359    Ogre::Light* dirlight = mSceneMgr->createLight("Light1");
     360
     361    dirlight->setType(Ogre::Light::LT_DIRECTIONAL);
     362    dirlight->setDirection(Vector3( 0, 1, 5 ));
     363    dirlight->setDiffuseColour(ColourValue(0.6, 0.6, 0.4));
     364    dirlight->setSpecularColour(ColourValue(1.0, 1.0, 1.0));*/
     365   
    430366    return true;
    431367  }
     
    453389    // Contains the times of recently fired events
    454390    // eventTimes[4] is the list for the times required for the fps counter
    455     std::deque<unsigned long> eventTimes[4];
     391    std::deque<unsigned long> eventTimes[3];
    456392    // Clear event times
    457     for (int i = 0; i < 4; ++i)
     393    for (int i = 0; i < 3; ++i)
    458394      eventTimes[i].clear();
    459     // fill the fps time list with zeros
    460     for (int i = 0; i < 50; i++)
    461       eventTimes[3].push_back(0);
    462395
    463396    // use the ogre timer class to measure time.
     
    466399    timer_->reset();
    467400
     401    float renderTime = 0.0f;
     402    float frameTime = 0.0f;
     403    clock_t time = 0;
     404
     405    //Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager();
     406    //Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport();
     407   
     408    //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom");
     409    //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur");
     410
    468411    COUT(3) << "Orxonox: Starting the main loop." << std::endl;
    469           while (!bAbort_)
    470           {
    471                   // Pump messages in all registered RenderWindows
    472       // This calls the WindowEventListener objects.
    473       Ogre::WindowEventUtilities::messagePump();
    474 
     412    while (!bAbort_)
     413    {
    475414      // get current time
    476415      unsigned long now = timer_->getMilliseconds();
    477       eventTimes[3].push_back(now);
    478       eventTimes[3].erase(eventTimes[3].begin());
    479416
    480417      // create an event to pass to the frameStarted method in ogre
     
    482419      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
    483420      evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]);
     421      frameTime += evt.timeSinceLastFrame;
    484422
    485423      // show the current time in the HUD
    486 //      orxonoxHUD_->setTime((int)now, 0);
    487 //      orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber());
    488       if (eventTimes[3].back() - eventTimes[3].front() != 0)
    489 //        orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front())));
    490 
    491       // Iterate through all Tickables and call their tick(dt) function
     424      // HUD::getSingleton().setTime(now);
     425      if (mode_ != DEDICATED && frameTime > 0.4f)
     426      {
     427        HUD::getSingleton().setRenderTimeRatio(renderTime / frameTime);
     428        frameTime = 0.0f;
     429        renderTime = 0.0f;
     430      }
     431
     432      // Call those objects that need the real time
     433      for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
     434        it->tick((float)evt.timeSinceLastFrame);
     435      // Call the scene objects
    492436      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    493437        it->tick((float)evt.timeSinceLastFrame * this->timefactor_);
    494       // Iterate through all TickableReals and call their tick(dt) function
    495       for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
    496         it->tick((float)evt.timeSinceLastFrame);
    497       orxonoxConsole_->tick((float)evt.timeSinceLastFrame);
    498438
    499439      // don't forget to call _fireFrameStarted in ogre to make sure
     
    501441      ogreRoot._fireFrameStarted(evt);
    502442
    503       // server still renders at the moment
    504       //if (mode_ != SERVER)
    505       ogreRoot._updateAllRenderTargets(); // only render in non-server mode
    506 
    507443      // get current time
    508444      now = timer_->getMilliseconds();
     445      calculateEventTime(now, eventTimes[2]);
     446
     447      if (mode_ != DEDICATED)
     448      {
     449        // Pump messages in all registered RenderWindows
     450        // This calls the WindowEventListener objects.
     451        Ogre::WindowEventUtilities::messagePump();
     452
     453        // render
     454        ogreRoot._updateAllRenderTargets();
     455      }
     456
     457      // get current time
     458      now = timer_->getMilliseconds();
    509459
    510460      // create an event to pass to the frameEnded method in ogre
    511461      evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]);
    512       evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[2]);
     462      renderTime += calculateEventTime(now, eventTimes[2]);
    513463
    514464      // again, just to be sure ogre works fine
    515465      ogreRoot._fireFrameEnded(evt);
    516           }
    517 
    518     if(mode_==CLIENT)
     466      //msleep(200);
     467    }
     468
     469    if (mode_ == CLIENT)
    519470      network::Client::getSingleton()->closeConnection();
    520     else if(mode_==SERVER)
     471    else if (mode_ == SERVER)
    521472      server_g->close();
     473
    522474    return true;
    523475  }
     
    560512    return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);
    561513  }
    562 
    563   /**
    564    * Static function that shows the console in game mode.
    565    */
    566   void Orxonox::activateConsole()
    567   {
    568     // currently, the console shows itself when feeded with input.
    569     InputManager::setInputState(InputManager::IS_CONSOLE);
    570   }
    571514}
  • code/trunk/src/orxonox/Orxonox.h

    r1293 r1502  
    5050    SERVER,
    5151    CLIENT,
    52     STANDALONE
     52    STANDALONE,
     53    DEDICATED
    5354  };
    5455
     
    7071      static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; }
    7172      static inline void exit() { Orxonox::getSingleton()->abortRequest(); }
    72       static inline void activateConsole();
    7373
    7474   private:
     
    9797      // TODO: make this a config-value by creating a config class for orxonox
    9898      float                 frameSmoothingTime_;
    99       InGameConsole*        orxonoxConsole_;
    10099      HUD*                  orxonoxHUD_;
    101100      bool                  bAbort_;        //!< aborts the render loop if true
     
    105104      gameMode              mode_;
    106105      std::string           serverIp_;
     106      int                   serverPort_;
    107107
    108108      static Orxonox *singletonRef_s;
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r1214 r1502  
    3535#define _OrxonoxPrereqs_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939//-----------------------------------------------------------------------
     
    7474  class Skybox;
    7575  class SpaceShip;
     76  class SpaceShipAI;
    7677  class WorldEntity;
    7778
     
    9596
    9697  // hud
     98  class BarOverlayElement;
    9799  class HUD;
     100  class Navigation;
     101  class RadarObject;
     102  class RadarOverlayElement;
     103
    98104  //console
    99105  class InGameConsole;
  • code/trunk/src/orxonox/OrxonoxStableHeaders.h

    r1219 r1502  
    3535#define _OrxonoxStableHeaders_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     
    109109#include "network/Synchronisable.h"
    110110
    111 #include "OrxonoxPlatform.h"
    112111#include "OrxonoxPrereqs.h"
    113112#include "tools/Timer.h"
  • code/trunk/src/orxonox/console/InGameConsole.cc

    r1362 r1502  
    2323 *      Felix Schulthess
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
     
    4040#include "core/Debug.h"
    4141#include "core/CoreIncludes.h"
     42#include "core/ConfigValueIncludes.h"
    4243#include "core/ConsoleCommand.h"
    4344#include "core/InputManager.h"
     45#include "util/Math.h"
    4446#include "GraphicsEngine.h"
    4547
    46 #define LINES 20
     48#define LINES 30
     49#define CHAR_WIDTH1 7.78 //34 // fix this please - determine the char-width dynamically
     50#define CHAR_WIDTH2 8.28 // fix this please - determine the char-width dynamically
     51#define CHAR_WIDTH3 7.80 //78 // fix this please - determine the char-width dynamically
    4752
    4853namespace orxonox
    4954{
     55    SetConsoleCommand(InGameConsole, openConsole, true);
     56    SetConsoleCommand(InGameConsole, closeConsole, true);
     57
    5058    using namespace Ogre;
    5159
    52     const float REL_WIDTH = 0.8;
    53     const float REL_HEIGHT = 0.4;
    54     const float BLINK = 0.25;
    55 
    56     InGameConsole::InGameConsole(InputBuffer* ib) :
    57         windowW(0), windowH(0),
    58         scroll(0), scrollTimer(0.0f),
    59         cursor(0.0f),
    60         active(false),
    61         ib_(ib),
    62         om(0),
    63         consoleOverlay(0),
    64         consoleOverlayContainer(0),
    65         consoleOverlayNoise(0),
    66         consoleOverlayBorder(0),
    67         consoleOverlayTextAreas(0)
    68     {
    69         //RegisterObject(InGameConsole);
    70         init();
    71     }
    72 
    73     InGameConsole::~InGameConsole(void){
    74         for(int i=0; i<LINES; i++) delete consoleOverlayTextAreas[i];
    75         delete consoleOverlayTextAreas;
    76     }
    77 
    78     void InGameConsole::listen(){
    79         if(!active) activate();
    80         print(convert2UTF(this->ib_->get()));
    81     }
    82 
    83     void InGameConsole::execute(){     
    84         newline();
    85         if (!CommandExecutor::execute(this->ib_->get())){
    86             print("Error");
    87             newline();
    88         }
    89         this->ib_->clear();
    90     }
    91 
    92     void InGameConsole::hintandcomplete(){
    93         print(CommandExecutor::hint(this->ib_->get()));
    94         newline();
    95         this->ib_->set(CommandExecutor::complete(this->ib_->get()));
    96         print(convert2UTF(this->ib_->get()));
    97     }
    98 
    99     void InGameConsole::clear(){
    100         this->ib_->clear();
    101     }
    102 
    103     void InGameConsole::removeLast(){
    104         this->ib_->removeLast();
    105     }
    106 
    107     void InGameConsole::exit(){
    108         clear();
    109         deactivate();
    110         InputManager::setInputState(InputManager::IS_NORMAL);
    111     }
    112 
    113     /**
    114     @brief called once by constructor
    115     */
    116     void InGameConsole::init(){
     60    float InGameConsole::REL_WIDTH = 0.8;
     61    float InGameConsole::REL_HEIGHT = 0.4;
     62    float InGameConsole::BLINK = 0.5;
     63
     64    /**
     65        @brief Constructor: Creates and initializes the InGameConsole.
     66    */
     67    InGameConsole::InGameConsole() :
     68        om_(0), consoleOverlay_(0), consoleOverlayContainer_(0),
     69        consoleOverlayNoise_(0), consoleOverlayBorder_(0), consoleOverlayTextAreas_(0)
     70    {
     71        RegisterObject(InGameConsole);
     72
     73        this->active_ = false;
     74        this->cursor_ = 0.0;
     75        this->cursorSymbol_ = '|';
     76        this->inputWindowStart_ = 0;
     77        this->numLinesShifted_ = LINES - 1;
     78
     79        this->init();
     80        this->setConfigValues();
     81
     82        Shell::getInstance().addOutputLevel(true);
     83    }
     84
     85    /**
     86        @brief Destructor: Destroys the TextAreas.
     87    */
     88    InGameConsole::~InGameConsole(void)
     89    {
     90        /*for (int i = 0; i < LINES; i++)
     91            if (this->consoleOverlayTextAreas_[i])
     92                om_->destroyOverlayElement(this->consoleOverlayTextAreas_[i]);
     93
     94        if (this->consoleOverlayTextAreas_)
     95            delete[] this->consoleOverlayTextAreas_;*/
     96    }
     97
     98    /**
     99        @brief Returns a reference to the only existing instance of InGameConsole.
     100    */
     101    InGameConsole& InGameConsole::getInstance()
     102    {
     103        static InGameConsole instance;
     104        return instance;
     105    }
     106
     107    /**
     108        @brief Sets the config values, describing the size of the console.
     109    */
     110    void InGameConsole::setConfigValues()
     111    {
     112        SetConfigValue(REL_WIDTH, 0.8);
     113        SetConfigValue(REL_HEIGHT, 0.4);
     114        SetConfigValue(BLINK, 0.5);
     115    }
     116
     117    /**
     118        @brief Called if all output-lines have to be redrawn.
     119    */
     120    void InGameConsole::linesChanged()
     121    {
     122        std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator();
     123        int max = 0;
     124        for (int i = 1; i < LINES; ++i)
     125        {
     126            if (it != Shell::getInstance().getEndIterator())
     127            {
     128                ++it;
     129                max = i;
     130            }
     131            else
     132                break;
     133        }
     134
     135        for (int i = LINES - 1; i > max; --i)
     136            this->print("", i, true);
     137
     138        for (int i = max; i >= 1; --i)
     139        {
     140            --it;
     141            this->print(*it, i, true);
     142        }
     143    }
     144
     145    /**
     146        @brief Called if only the last output-line has changed.
     147    */
     148    void InGameConsole::onlyLastLineChanged()
     149    {
     150        if (LINES > 1)
     151            this->print(*Shell::getInstance().getNewestLineIterator(), 1);
     152    }
     153
     154    /**
     155        @brief Called if a new output-line was added.
     156    */
     157    void InGameConsole::lineAdded()
     158    {
     159        this->numLinesShifted_ = 0;
     160        this->shiftLines();
     161        this->onlyLastLineChanged();
     162    }
     163
     164    /**
     165        @brief Called if the text in the input-line has changed.
     166    */
     167    void InGameConsole::inputChanged()
     168    {
     169        if (LINES > 0)
     170            this->print(Shell::getInstance().getInput(), 0);
     171
     172        if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0)
     173            this->inputWindowStart_ = 0;
     174    }
     175
     176    /**
     177        @brief Called if the position of the cursor in the input-line has changed.
     178    */
     179    void InGameConsole::cursorChanged()
     180    {
     181        /*std::string input = Shell::getInstance().getInput();
     182        input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_);
     183        if (LINES > 0)
     184            this->print(input, 0);*/
     185        this->setCursorPosition(Shell::getInstance().getCursorPosition() - inputWindowStart_);
     186    }
     187
     188    /**
     189        @brief Called if the console gets closed.
     190    */
     191    void InGameConsole::exit()
     192    {
     193        this->deactivate();
     194    }
     195
     196    /**
     197        @brief Called once by constructor, initializes the InGameConsole.
     198    */
     199    void InGameConsole::init()
     200    {
    117201        // for the beginning, don't scroll
    118         scroll = 0;
    119         scrollTimer = 0;
    120         cursor = 0;
     202        this->scroll_ = 0;
     203        this->scrollTimer_ = 0;
     204        this->cursor_ = 0;
    121205
    122206        // create overlay and elements
    123         om = &Ogre::OverlayManager::getSingleton();
     207        this->om_ = &Ogre::OverlayManager::getSingleton();
    124208
    125209        // create a container
    126         consoleOverlayContainer = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", "container"));
    127         consoleOverlayContainer->setMetricsMode(Ogre::GMM_RELATIVE);
    128         consoleOverlayContainer->setPosition((1-REL_WIDTH)/2, 0);
    129         consoleOverlayContainer->setDimensions(REL_WIDTH, REL_HEIGHT);
     210        this->consoleOverlayContainer_ = static_cast<OverlayContainer*>(this->om_->createOverlayElement("Panel", "InGameConsoleContainer"));
     211        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
     212        this->consoleOverlayContainer_->setPosition((1 - InGameConsole::REL_WIDTH) / 2, 0);
     213        this->consoleOverlayContainer_->setDimensions(InGameConsole::REL_WIDTH, InGameConsole::REL_HEIGHT);
    130214
    131215        // create BorderPanel
    132         consoleOverlayBorder = static_cast<BorderPanelOverlayElement*>(om->createOverlayElement("BorderPanel", "borderPanel"));
    133         consoleOverlayBorder->setMetricsMode(Ogre::GMM_PIXELS);
    134         consoleOverlayBorder->setMaterialName("ConsoleCenter");
     216        this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>(this->om_->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
     217        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
     218        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
    135219        // set parameters for border
    136         consoleOverlayBorder->setBorderSize(16, 16, 0, 16);
    137         consoleOverlayBorder->setBorderMaterialName("ConsoleBorder");
    138         consoleOverlayBorder->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
    139         consoleOverlayBorder->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
    140         consoleOverlayBorder->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
    141         consoleOverlayBorder->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
    142         consoleOverlayBorder->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
     220        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
     221        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
     222        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
     223        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
     224        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
     225        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
     226        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
    143227
    144228        // create the text lines
    145         consoleOverlayTextAreas = new TextAreaOverlayElement*[LINES];
    146         for(int i = 0; i<LINES; i++){
    147             consoleOverlayTextAreas[i] = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "textArea"+Ogre::StringConverter::toString(i)));
    148             consoleOverlayTextAreas[i]->setMetricsMode(Ogre::GMM_PIXELS);
    149             consoleOverlayTextAreas[i]->setFontName("Console");
    150             consoleOverlayTextAreas[i]->setCharHeight(20);
    151             consoleOverlayTextAreas[i]->setParameter("colour_top", "0.21 0.69 0.21");
    152             consoleOverlayTextAreas[i]->setLeft(8);
    153             consoleOverlayTextAreas[i]->setCaption("");
     229        this->consoleOverlayTextAreas_ = new TextAreaOverlayElement*[LINES];
     230        for (int i = 0; i < LINES; i++)
     231        {
     232            this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>(this->om_->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i)));
     233            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
     234            this->consoleOverlayTextAreas_[i]->setFontName("Console");
     235            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
     236            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
     237            this->consoleOverlayTextAreas_[i]->setLeft(8);
     238            this->consoleOverlayTextAreas_[i]->setCaption("");
    154239        }
    155240
    156241        // create noise
    157         consoleOverlayNoise = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "noise"));
    158         consoleOverlayNoise->setMetricsMode(Ogre::GMM_PIXELS);
    159         consoleOverlayNoise->setPosition(5,0);
    160         consoleOverlayNoise->setMaterialName("ConsoleNoise");
    161 
    162         consoleOverlay = om->create("Console");
    163         consoleOverlay->add2D(consoleOverlayContainer);
    164         consoleOverlayContainer->addChild(consoleOverlayBorder);
    165 //comment following line to disable noise
    166         consoleOverlayContainer->addChild(consoleOverlayNoise);
    167         for(int i = 0; i<LINES; i++) consoleOverlayContainer->addChild(consoleOverlayTextAreas[i]);
    168         resize();
     242        this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleNoise"));
     243        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
     244        this->consoleOverlayNoise_->setPosition(5,0);
     245        this->consoleOverlayNoise_->setMaterialName("ConsoleNoise");
     246
     247        // create cursor
     248        this->consoleOverlayCursor_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleCursor"));
     249        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
     250        this->consoleOverlayCursor_->setPosition(5,219);
     251        this->consoleOverlayCursor_->setDimensions(1, 14);
     252        this->consoleOverlayCursor_->setMaterialName("Orxonox/GreenDot");
     253
     254        this->consoleOverlay_ = this->om_->create("InGameConsoleConsole");
     255        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
     256        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
     257        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
     258        //comment following line to disable noise
     259        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
     260        for (int i = 0; i < LINES; i++)
     261            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
     262
     263        this->resize();
    169264
    170265        // move overlay "above" the top edge of the screen
    171266        // we take -1.2 because the border mkes the panel bigger
    172         consoleOverlayContainer->setTop(-1.2*REL_HEIGHT);
     267        this->consoleOverlayContainer_->setTop(-1.2 * InGameConsole::REL_HEIGHT);
    173268        // show overlay
    174         consoleOverlay->show();
    175 
    176         COUT(3) << "Info: InGameConsole initialized" << std::endl;
    177     }
    178 
    179     /**
    180     @brief used to control the actual scrolling and cursor
    181     */
    182     void InGameConsole::tick(float dt){
    183         scrollTimer += dt;
    184         if(scrollTimer >= 0.01){
    185             float top = consoleOverlayContainer->getTop();
    186             scrollTimer = 0;
    187             if(scroll!=0){
     269        this->consoleOverlay_->show();
     270
     271        COUT(4) << "Info: InGameConsole initialized" << std::endl;
     272    }
     273
     274    /**
     275        @brief Resizes the console elements. Call if window size changes.
     276    */
     277    void InGameConsole::resize()
     278    {
     279        this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
     280        this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
     281        this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH);
     282        this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT);
     283        this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10);
     284        this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5);
     285
     286        // now adjust the text lines...
     287        this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12;
     288
     289        if (LINES > 0)
     290            this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH3));
     291        else
     292            this->maxCharsPerLine_ = 10;
     293
     294        for (int i = 0; i < LINES; i++)
     295        {
     296            this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_);
     297            this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i);
     298        }
     299
     300        this->linesChanged();
     301    }
     302
     303    /**
     304        @brief Used to control the actual scrolling and the cursor.
     305    */
     306    void InGameConsole::tick(float dt)
     307    {
     308        this->scrollTimer_ += dt;
     309        if (this->scrollTimer_ >= 0.01)
     310        {
     311            float top = this->consoleOverlayContainer_->getTop();
     312            float timePassed = scrollTimer_;
     313            this->scrollTimer_ = 0;
     314            if (this->scroll_ != 0)
     315            {
    188316                // scroll
    189                 top = top + 0.02*scroll;
    190                 consoleOverlayContainer->setTop(top);
     317                top = top + timePassed * this->scroll_;
     318                this->consoleOverlayContainer_->setTop(top);
    191319            }
    192             if(top <= -1.2*REL_HEIGHT){
     320            if (top <= -1.2 * InGameConsole::REL_HEIGHT)
     321            {
    193322                // window has completely scrolled up
    194                 scroll = 0;
    195                 consoleOverlay->hide();
    196                 active = false;
     323                this->scroll_ = 0;
     324                this->consoleOverlay_->hide();
     325                this->active_ = false;
     326                Shell::getInstance().unregisterListener(this);
    197327            }
    198             if(top >= 0){
     328            if (top >= 0)
     329            {
    199330                // window has completely scrolled down
    200                 scroll = 0;
    201                 consoleOverlayContainer->setTop(0);
    202                 active = true;
     331                this->scroll_ = 0;
     332                this->consoleOverlayContainer_->setTop(0);
     333                this->active_ = true;
    203334            }
    204335        }
    205336
    206         cursor += dt;
    207         if(cursor >= 2*BLINK) cursor = 0;
    208         print(convert2UTF(this->ib_->get()));
    209 
    210 // this creates a flickering effect
    211         consoleOverlayNoise->setTiling(1, rand()%5+1);
    212     }
    213 
    214     /**
    215     @brief resizes the console elements. call if window size changes
    216     */
    217     void InGameConsole::resize(){
    218         windowW = GraphicsEngine::getSingleton().getWindowWidth();
    219         windowH = GraphicsEngine::getSingleton().getWindowHeight();
    220         consoleOverlayBorder->setWidth((int) windowW*REL_WIDTH);
    221         consoleOverlayBorder->setHeight((int) windowH*REL_HEIGHT);
    222         consoleOverlayNoise->setWidth((int) windowW*REL_WIDTH - 10);
    223         consoleOverlayNoise->setHeight((int) windowH*REL_HEIGHT - 5);
    224         // now adjust the text lines...
    225         for(int i = 0; i<LINES; i++){
    226             consoleOverlayTextAreas[i]->setWidth(windowW*REL_WIDTH);
    227             consoleOverlayTextAreas[i]->setTop((int)windowH*REL_HEIGHT - 24 - 16*i);
    228         }
    229     }
    230 
    231     /**
    232     @brief shows console
    233     */
    234     void InGameConsole::activate(){
    235         consoleOverlay->show();
     337        this->cursor_ += dt;
     338        if (this->cursor_ >= InGameConsole::BLINK)
     339        {
     340            this->cursor_ = 0;
     341            bShowCursor_ = !bShowCursor_;
     342            if (bShowCursor_)
     343              this->consoleOverlayCursor_->show();
     344            else
     345              this->consoleOverlayCursor_->hide();
     346        }
     347
     348        /*if (this->cursor_ >= 2 * InGameConsole::BLINK)
     349          this->cursor_ = 0;
     350
     351        if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|')
     352        {
     353            this->cursorSymbol_ = ' ';
     354            this->cursorChanged();
     355        }
     356        else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ')
     357        {
     358            this->cursorSymbol_ = '|';
     359            this->cursorChanged();
     360        }*/
     361
     362        // this creates a flickering effect
     363        this->consoleOverlayNoise_->setTiling(1, rand() % 5 + 1);
     364    }
     365
     366    /**
     367        @brief Shows the InGameConsole.
     368    */
     369    void InGameConsole::activate()
     370    {
     371        InputManager::setInputState(InputManager::IS_CONSOLE);
     372        Shell::getInstance().registerListener(this);
     373        this->linesChanged();
     374
     375        this->consoleOverlay_->show();
    236376        // just in case window size has changed...
    237         resize();
     377        this->resize();
    238378        // scroll down
    239         scroll = 1;
     379        this->scroll_ = 1;
    240380        // the rest is done by tick
    241381    }
    242382
    243383    /**
    244     @brief hides console
    245     */
    246     void InGameConsole::deactivate(){
     384    @brief Hides the InGameConsole.
     385    */
     386    void InGameConsole::deactivate()
     387    {
    247388        // scroll up
    248         scroll = -1;
     389        this->scroll_ = -1;
    249390        // the rest is done by tick
    250     }
    251 
    252     /**
    253     @brief prints string to bottom line
    254     @param s string to be printed
    255     */
    256     void InGameConsole::print(Ogre::UTFString s){
    257         if(cursor>BLINK) consoleOverlayTextAreas[0]->setCaption(">" + s);
    258         else consoleOverlayTextAreas[0]->setCaption(">" + s + "_");
    259     }
    260 
    261     /**
    262     @brief shifts all lines up and clears the bottom line
    263     */
    264     void InGameConsole::newline(){
    265         Ogre::UTFString line;
    266         for(int i = LINES-1; i>=1; i--){
    267             line = consoleOverlayTextAreas[i-1]->getCaption();
    268             // don't copy the cursor...
    269             int l = line.length();
    270             if(!line.empty() && line.substr(l-1) == "_") line.erase(l-1);
    271             consoleOverlayTextAreas[i]->setCaption(line);
    272         }
    273         consoleOverlayTextAreas[0]->setCaption(">");
    274     }
    275 
    276     Ogre::UTFString InGameConsole::convert2UTF(std::string s){
     391        InputManager::setInputState(InputManager::IS_NORMAL);
     392    }
     393
     394    /**
     395        @brief Activates the console.
     396    */
     397    void InGameConsole::openConsole()
     398    {
     399        InGameConsole::getInstance().activate();
     400    }
     401
     402    /**
     403        @brief Deactivates the console.
     404    */
     405    void InGameConsole::closeConsole()
     406    {
     407        InGameConsole::getInstance().deactivate();
     408    }
     409
     410    /**
     411        @brief Shifts all output lines one line up
     412    */
     413    void InGameConsole::shiftLines()
     414    {
     415        for (unsigned int i = LINES - 1; i > 1; --i)
     416        {
     417            this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption());
     418            this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop());
     419            this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom());
     420        }
     421    }
     422
     423    void InGameConsole::colourLine(int colourcode, int index)
     424    {
     425        if (colourcode == -1)
     426        {
     427            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.90, 0.90, 0.90, 1.00));
     428            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00));
     429        }
     430        else if (colourcode == 1)
     431        {
     432            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.25, 0.25, 1.00));
     433            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00));
     434        }
     435        else if (colourcode == 2)
     436        {
     437            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.95, 0.50, 0.20, 1.00));
     438            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00));
     439        }
     440        else if (colourcode == 3)
     441        {
     442            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.50, 0.50, 0.95, 1.00));
     443            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00));
     444        }
     445        else if (colourcode == 4)
     446        {
     447            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.65, 0.48, 0.44, 1.00));
     448            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00));
     449        }
     450        else if (colourcode == 5)
     451        {
     452            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.40, 0.20, 0.40, 1.00));
     453            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00));
     454        }
     455        else
     456        {
     457            this->consoleOverlayTextAreas_[index]->setColourTop   (ColourValue(0.21, 0.69, 0.21, 1.00));
     458            this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00));
     459        }
     460    }
     461
     462    void InGameConsole::setCursorPosition(int pos)
     463    {
     464        static std::string char1 = "bdefgilpqtzCEGIJKNOPQT5[}äü";
     465        static std::string char2 = "Z4";
     466
     467        if (pos > (int)maxCharsPerLine_)
     468          pos = maxCharsPerLine_;
     469        else if (pos < 0)
     470          pos = 0;
     471
     472        float width = 0;
     473        for (int i = 0; i < pos; ++i)
     474        {
     475            if (char1.find(displayedText_[i]) != std::string::npos)
     476                width += CHAR_WIDTH1;
     477            else if (char2.find(displayedText_[i]) != std::string::npos)
     478                width += CHAR_WIDTH2;
     479            else
     480                width += CHAR_WIDTH3;
     481        }
     482        this->consoleOverlayCursor_->setPosition(width + 5, this->windowH_ * InGameConsole::REL_HEIGHT - 20);
     483    }
     484
     485    /**
     486        @brief Prints string to bottom line.
     487        @param s String to be printed
     488    */
     489    void InGameConsole::print(const std::string& text, int index, bool alwaysShift)
     490    {
     491        char level = 0;
     492        if (text.size() > 0)
     493            level = text[0];
     494
     495        std::string output = text;
     496
     497        if (level >= -1 && level <= 5)
     498            output.erase(0, 1);
     499
     500        if (LINES > index)
     501        {
     502            this->colourLine(level, index);
     503
     504            if (index > 0)
     505            {
     506                unsigned int linesUsed = 1;
     507                while (output.size() > this->maxCharsPerLine_)
     508                {
     509                    ++linesUsed;
     510                    this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_)));
     511                    output.erase(0, this->maxCharsPerLine_);
     512                    output.insert(0, 1, ' ');
     513                    if (linesUsed > numLinesShifted_ || alwaysShift)
     514                        this->shiftLines();
     515                    this->colourLine(level, index);
     516                }
     517                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
     518                this->displayedText_ = output;
     519                this->numLinesShifted_ = linesUsed;
     520            }
     521            else
     522            {
     523                if (output.size() > this->maxCharsPerLine_)
     524                {
     525                    if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_)
     526                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition();
     527                    else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
     528                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1;
     529
     530                    output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
     531                }
     532                else
     533                  this->inputWindowStart_ = 0;
     534                this->displayedText_ = output;
     535                this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output));
     536            }
     537        }
     538    }
     539
     540    /**
     541        @brief Converts a string into an Ogre::UTFString.
     542        @param s The string to convert
     543        @return The converted string
     544    */
     545    Ogre::UTFString InGameConsole::convert2UTF(std::string s)
     546    {
    277547        Ogre::UTFString utf;
    278         int i;
    279548        Ogre::UTFString::code_point cp;
    280         for (i=0; i<(int)s.size(); ++i){
     549        for (unsigned int i = 0; i < s.size(); ++i)
     550        {
    281551          cp = s[i];
    282552          cp &= 0xFF;
  • code/trunk/src/orxonox/console/InGameConsole.h

    r1214 r1502  
    2323 *      Felix Schulthess
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
     
    3737
    3838#include "core/Tickable.h"
    39 #include "core/InputBuffer.h"
     39#include "core/Shell.h"
    4040
    4141
    4242namespace orxonox
    4343{
    44     class _OrxonoxExport InGameConsole : public InputBufferListener
     44    class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener
    4545    {
    4646        public:
    47             InGameConsole(InputBuffer* ib);
    48             ~InGameConsole();
    49             void listen();
    50             void execute();
    51             void hintandcomplete();
    52             void clear();
    53             void removeLast();
    54             void exit();
    55             void init();
     47            static InGameConsole& getInstance();
     48
     49            void setConfigValues();
    5650            void tick(float dt);
     51
    5752            void activate();
    5853            void deactivate();
     54            void resize();
     55
     56            static void openConsole();
     57            static void closeConsole();
    5958
    6059        private:
    61             void resize();
    62             void print(Ogre::UTFString s);
    63             void newline();
    64             Ogre::UTFString convert2UTF(std::string s);
     60            InGameConsole();
     61            InGameConsole(const InGameConsole& other);
     62            ~InGameConsole();
    6563
    66             int windowW;
    67             int windowH;
    68             int scroll;
    69             float scrollTimer;
    70             float cursor;
    71             bool active;
    72             InputBuffer* ib_;
    73             Ogre::OverlayManager* om;
    74             Ogre::Overlay* consoleOverlay;
    75             Ogre::OverlayContainer* consoleOverlayContainer;
    76             Ogre::PanelOverlayElement* consoleOverlayNoise;
    77             Ogre::BorderPanelOverlayElement* consoleOverlayBorder;
    78             Ogre::TextAreaOverlayElement** consoleOverlayTextAreas;
     64            virtual void linesChanged();
     65            virtual void onlyLastLineChanged();
     66            virtual void lineAdded();
     67            virtual void inputChanged();
     68            virtual void cursorChanged();
     69            virtual void exit();
     70
     71            void init();
     72            void shiftLines();
     73            void colourLine(int colourcode, int index);
     74            void setCursorPosition(int pos);
     75            void print(const std::string& text, int index, bool alwaysShift = false);
     76            static Ogre::UTFString convert2UTF(std::string s);
     77
     78            static float REL_WIDTH;
     79            static float REL_HEIGHT;
     80            static float BLINK;
     81
     82            int windowW_;
     83            int windowH_;
     84            int desiredTextWidth_;
     85            unsigned int maxCharsPerLine_;
     86            unsigned int numLinesShifted_;
     87            int scroll_;
     88            float scrollTimer_;
     89            float cursor_;
     90            unsigned int inputWindowStart_;
     91            char cursorSymbol_;
     92            bool active_;
     93            bool bShowCursor_;
     94            std::string displayedText_;
     95            Ogre::OverlayManager* om_;
     96            Ogre::Overlay* consoleOverlay_;
     97            Ogre::OverlayContainer* consoleOverlayContainer_;
     98            Ogre::PanelOverlayElement* consoleOverlayNoise_;
     99            Ogre::PanelOverlayElement* consoleOverlayCursor_;
     100            Ogre::BorderPanelOverlayElement* consoleOverlayBorder_;
     101            Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_;
    79102    };
    80103}
  • code/trunk/src/orxonox/hud/BarOverlayElement.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
     29#include "OrxonoxStableHeaders.h"
     30#include "BarOverlayElement.h"
    2831#include <OgreOverlayManager.h>
    29 #include <OgreOverlayElement.h>
    30 #include <OgrePanelOverlayElement.h>
    3132#include "GraphicsEngine.h"
    32 #include "BarOverlayElement.h"
    3333
    3434namespace orxonox
    3535{
    36   using namespace Ogre;
     36    using namespace Ogre;
    3737
    38     BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
     38    BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
    3939        name_ = name;
    4040    }
     
    4242    BarOverlayElement::~BarOverlayElement(){}
    4343
    44     void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
     44    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
    4545        // init some values...
    4646        container_ = container;
    47         om = &Ogre::OverlayManager::getSingleton();
     47        om = &OverlayManager::getSingleton();
    4848        value_ = 0;
    4949        color_ = 2;
     
    5353        topRel_ = topRel;
    5454        dimRel_ = dimRel;
    55        
     55
    5656        // create background...
    5757        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
    5858        background_->show();
    5959        container_->addChild(background_);
    60         background_->setMetricsMode(Ogre::GMM_PIXELS);
     60        background_->setMetricsMode(GMM_PIXELS);
    6161        background_->setMaterialName("Orxonox/BarBackground");
    6262
     
    6565
    6666        show();
    67         setMetricsMode(Ogre::GMM_PIXELS);
     67        setMetricsMode(GMM_PIXELS);
    6868        setMaterialName("Orxonox/Green");
    6969        background_->addChild(this);
     
    126126    }
    127127}
    128 
    129 
  • code/trunk/src/orxonox/hud/BarOverlayElement.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
     29#ifndef _BarOverlayElement_H__
     30#define _BarOverlayElement_H__
    2831
    29 #ifndef _BAR_H__
    30 #define _BAR_H__
    31 
    32 #include <OgreOverlayManager.h>
    33 #include <OgreOverlayElement.h>
    34 #include <OgrePanelOverlayElement.h>
     32#include "OrxonoxPrereqs.h"
    3533
    3634#include <OgrePrerequisites.h>
    37 #include "../OrxonoxPrereqs.h"
    38 
    39 
     35#include <OgrePanelOverlayElement.h>
    4036
    4137namespace orxonox
     
    4440  {
    4541    private:
    46         bool autoColor_;                    // whether bar changes color automatically
    47         float value_;                       // progress of bar
    48         int color_;
    49         int left_;
    50         int top_;
    51         int width_;
    52         int height_;
    53         int windowW_, windowH_;
    54         Ogre::Real leftRel_;
    55         Ogre::Real topRel_;
    56         Ogre::Real dimRel_;
    57         Ogre::OverlayManager* om;           // our overlay manager
    58         Ogre::OverlayContainer* container_; // our parent container to attach to
    59         Ogre::OverlayContainer* background_;
    60         Ogre::String name_;
     42      bool autoColor_;                    // whether bar changes color automatically
     43      float value_;                       // progress of bar
     44      int color_;
     45      int left_;
     46      int top_;
     47      int width_;
     48      int height_;
     49      int windowW_, windowH_;
     50      Ogre::Real leftRel_;
     51      Ogre::Real topRel_;
     52      Ogre::Real dimRel_;
     53      Ogre::OverlayManager* om;           // our overlay manager
     54      Ogre::OverlayContainer* container_; // our parent container to attach to
     55      Ogre::OverlayContainer* background_;
     56      Ogre::String name_;
    6157
    6258    public:
    63         bool left2Right;
    64         static const int RED = 0;           // predefined colors
    65         static const int YELLOW = 1;
    66         static const int GREEN = 2;
     59      bool left2Right;
     60      static const int RED = 0;           // predefined colors
     61      static const int YELLOW = 1;
     62      static const int GREEN = 2;
    6763
    68         BarOverlayElement(const Ogre::String& name);
    69         virtual ~BarOverlayElement();
    70         void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
    71         void resize();
    72         void setValue(float value);
    73         void setColor(int color);
    74         float getValue();
    75         int getBarColor();
     64      BarOverlayElement(const Ogre::String& name);
     65      virtual ~BarOverlayElement();
     66      void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
     67      void resize();
     68      void setValue(float value);
     69      void setColor(int color);
     70      float getValue();
     71      int getBarColor();
    7672    };
    7773}
    78 #endif
    79 
    80 
     74#endif /* _BarOverlayElement_H__ */
  • code/trunk/src/orxonox/hud/HUD.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
    27 
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2828
    2929#include "OrxonoxStableHeaders.h"
     30#include "HUD.h"
     31
     32#include <string>
     33#include <set>
    3034#include <OgreOverlay.h>
    3135#include <OgreOverlayContainer.h>
    3236#include <OgreOverlayManager.h>
    33 #include <OgreSceneNode.h>
    34 #include <OgreEntity.h>
    3537#include <OgreStringConverter.h>
     38
    3639#include "core/Debug.h"
     40#include "core/ConsoleCommand.h"
    3741#include "objects/SpaceShip.h"
    38 #include "HUD.h"
     42#include "GraphicsEngine.h"
    3943#include "BarOverlayElement.h"
     44#include "RadarObject.h"
    4045#include "RadarOverlayElement.h"
     46#include "Navigation.h"
    4147#include "OverlayElementFactories.h"
    4248
    4349namespace orxonox
    4450{
     51    SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User);
     52    SetConsoleCommandShortcut(HUD, toggleFPS).setAccessLevel(AccessLevel::User);
     53    SetConsoleCommandShortcut(HUD, toggleRenderTime).setAccessLevel(AccessLevel::User);
     54
    4555    using namespace Ogre;
    4656
    47     HUD::HUD(int zoom){
     57    HUD::HUD(){
    4858        om = &Ogre::OverlayManager::getSingleton();
    49 
    50                 // create Factories
     59        sm = GraphicsEngine::getSingleton().getSceneManager();
     60        showFPS = true;
     61        showRenderTime = true;
     62
     63        // create Factories
    5164        BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
    5265        om->addOverlayElementFactory(barOverlayElementFactory);
     
    5669        orxonoxHUD = om->create("Orxonox/HUD");
    5770        container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
    58         // test
    59         test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123"));
    60         test->show();
    61         test->setMetricsMode(Ogre::GMM_RELATIVE);
    62         test->setDimensions(0.8, 0.8);
    63         test->setPosition(0.02, 0.02);
    64         test->setFontName("Console");
    65         test->setCaption("init");
     71
     72        // creating text to display fps
     73        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
     74        fpsText->show();
     75        fpsText->setMetricsMode(Ogre::GMM_PIXELS);
     76        fpsText->setDimensions(0.001, 0.001);
     77        fpsText->setPosition(10, 10);
     78        fpsText->setFontName("Console");
     79        fpsText->setCharHeight(20);
     80        fpsText->setCaption("init");
     81
     82        // creating text to display render time ratio
     83        rTRText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "rTRText"));
     84        rTRText->show();
     85        rTRText->setMetricsMode(Ogre::GMM_PIXELS);
     86        rTRText->setDimensions(0.001, 0.001);
     87        rTRText->setPosition(10, 30);
     88        rTRText->setFontName("Console");
     89        rTRText->setCharHeight(20);
     90        rTRText->setCaption("init");
    6691
    6792        // create energy bar
     
    75100        radar->show();
    76101
    77                 // set up screen-wide container
     102        // create Navigation
     103        nav = new Navigation(container);
     104
     105        // set up screen-wide container
    78106        container->show();
    79107
     
    85113        container->setHeight(1.0);
    86114        container->setMetricsMode(Ogre::GMM_RELATIVE);
    87         container->addChild(test);
     115        container->addChild(fpsText);
     116        container->addChild(rTRText);
     117
    88118        energyBar->init(0.01, 0.94, 0.4, container);
    89119        energyBar->setValue(1);
     120
    90121        speedoBar->init(0.01, 0.90, 0.4, container);
     122
    91123        radar->init(0.5, 0.9, 0.2, container);
    92         radar->addObject(Vector3(1500.0, 0.0, 100.0));
    93         radar->addObject(Vector3(0.0, 4000.0, 0.0));
    94         radar->addObject(Vector3(0.0, 0.0, 6800.0));
    95         RadarOverlayElement::cycleFocus();
     124        SceneNode* node;
     125        node = sm->getRootSceneNode()->createChildSceneNode("tomato1", Vector3(2000.0, 0.0, 0.0));
     126        addRadarObject(node);
     127        node = sm->getRootSceneNode()->createChildSceneNode("tomato2", Vector3(0.0, 2000.0, 0.0));
     128        addRadarObject(node);
     129        node = sm->getRootSceneNode()->createChildSceneNode("tomato3", Vector3(0.0, 0.0, 2000.0));
     130        addRadarObject(node);
     131        node = sm->getRootSceneNode()->createChildSceneNode("station", Vector3(10000.0,16000.0,0.0));
     132        addRadarObject(node, 3);
     133    }
     134
     135    HUD::~HUD(){
     136        //todo: clean up objects
    96137    }
    97138
    98139    void HUD::tick(float dt)
    99140    {
    100         int d = radar->getDist2Focus()/10;
    101         if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));
    102         else test->setCaption("");
    103 
    104141        energyBar->resize();
    105142
    106         float v = SpaceShip::instance_s->getVelocity().length();
    107         float vmax = SpaceShip::instance_s->getMaxSpeed();
     143        if(!SpaceShip::getLocalShip())
     144          return;
     145        float v = SpaceShip::getLocalShip()->getVelocity().length();
     146        float vmax = SpaceShip::getLocalShip()->getMaxSpeed();
    108147        speedoBar->setValue(v/vmax);
    109148        speedoBar->resize();
     
    111150        radar->resize();
    112151        radar->update();
    113     }
    114 
    115     HUD::~HUD(void){
     152
     153        nav->update();
     154
     155        setFPS();
     156    }
     157
     158    void HUD::setRenderTimeRatio(float ratio)
     159    {
     160        if(showRenderTime){
     161            rTRText->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio));
     162        }
     163        else{
     164            rTRText->setCaption("");
     165            return;
     166        }
     167    }
     168
     169    void HUD::setFPS(){
     170        if(showFPS){
     171            float fps = GraphicsEngine::getSingleton().getAverageFPS();
     172            fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
     173        }
     174        else{
     175            fpsText->setCaption("");
     176            return;
     177        }
     178    }
     179
     180    void HUD::addRadarObject(SceneNode* node, int colour){
     181        RadarObject* obj = new RadarObject(container, node, colour);
     182        roSet.insert(obj);
     183//        // check if this is the first RadarObject to create
     184//        if(firstRadarObject == NULL){
     185//            firstRadarObject = new RadarObject(container, node, colour);
     186//            lastRadarObject = firstRadarObject;
     187//        }
     188//        else{ // if not, append to list
     189//            lastRadarObject->next = new RadarObject(container, node, colour);
     190//            lastRadarObject = lastRadarObject->next;
     191//        }
     192    }
     193
     194    void HUD::removeRadarObject(Ogre::SceneNode* node){
     195      COUT(3) << "blabla" << std::endl;
     196        for(std::set<RadarObject*>::iterator it=roSet.begin(); it!=roSet.end(); it++){
     197            if((*it)->getNode() == node) {
     198                delete (*it);
     199                roSet.erase(it);
     200            }
     201        }
     202    }
     203
     204    /*static*/ HUD& HUD::getSingleton(){
     205        static HUD theInstance;
     206        return theInstance;
     207    }
     208
     209    /*static*/ void HUD::setEnergy(float value){
     210        HUD::getSingleton().energyBar->setValue(value);
     211    }
     212
     213    /*static*/ void HUD::cycleNavigationFocus(){
     214        HUD::getSingleton().nav->cycleFocus();
     215    }
     216
     217    /*static*/ void HUD::toggleFPS(){
     218        HUD::getSingleton().showFPS = !HUD::getSingleton().showFPS;
     219    }
     220
     221    /*static*/ void HUD::toggleRenderTime(){
     222        HUD::getSingleton().showRenderTime = !HUD::getSingleton().showRenderTime;
    116223    }
    117224}
  • code/trunk/src/orxonox/hud/HUD.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
    2829
     
    3031#define _HUD_H__
    3132
    32 #include <string.h>
    33 #include <OgreOverlayElement.h>
     33#include "OrxonoxPrereqs.h"
     34
     35#include <OgrePrerequisites.h>
    3436#include <OgreTextAreaOverlayElement.h>
    35 #include <OgrePrerequisites.h>
    36 
    37 #include "OrxonoxPrereqs.h"
     37#include <OgreSceneNode.h>
    3838#include "core/Tickable.h"
    39 #include "BarOverlayElement.h"
    40 #include "RadarOverlayElement.h"
    41 
     39#include "util/Math.h"
    4240
    4341namespace orxonox
     
    4543    class _OrxonoxExport HUD : public Tickable
    4644    {
    47         private:
    48             Ogre::OverlayManager* om;
    49             Ogre::Overlay* orxonoxHUD;
    50             Ogre::OverlayContainer* container;
    51             Ogre::TextAreaOverlayElement* test;
    52             BarOverlayElement* energyBar;
    53             BarOverlayElement* speedoBar;
    54             RadarOverlayElement* radar;
     45      private:
     46        HUD();
     47        HUD(HUD& instance);
     48        ~HUD();
     49        Ogre::OverlayManager* om;
     50        Ogre::SceneManager* sm;
     51        Ogre::Overlay* orxonoxHUD;
     52        Ogre::OverlayContainer* container;
     53        Ogre::TextAreaOverlayElement* fpsText;
     54        Ogre::TextAreaOverlayElement* rTRText;
     55        BarOverlayElement* energyBar;
     56        BarOverlayElement* speedoBar;
     57        RadarOverlayElement* radar;
     58        Navigation* nav;
    5559
    56         public:
    57             HUD(int zoom);
    58             ~HUD();
    59             virtual void tick(float);
     60        bool showFPS;
     61        bool showRenderTime;
    6062
     63      public:
     64        virtual void tick(float);
     65        void addRadarObject(Ogre::SceneNode* node, int colour = 0);
     66        void removeRadarObject(Ogre::SceneNode* node);
     67        void setRenderTimeRatio(float ratio);
     68        void setFPS();
     69
     70        std::set<RadarObject*> roSet;
     71
     72        static HUD* instance_s;
     73        static HUD& getSingleton();
     74        static void setEnergy(float value);
     75        static void cycleNavigationFocus();
     76        static void toggleFPS();
     77        static void toggleRenderTime();
    6178    };
    6279}
    6380
    64 #endif
     81#endif /* _HUD_H__ */
  • code/trunk/src/orxonox/hud/OverlayElementFactories.h

    r1362 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      Felix Schulthess
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
    28 #ifndef _FACTORIES_H__
    29 #define _FACTORIES_H__
     29#ifndef _OverlayElementFactories_H__
     30#define _OverlayElementFactories_H__
    3031
     32#include "OrxonoxPrereqs.h"
     33
     34#include <OgrePrerequisites.h>
    3135#include <OgreOverlayElement.h>
    32 #include <OgrePrerequisites.h>
    3336#include <OgreOverlayElementFactory.h>
    3437
    3538#include "BarOverlayElement.h"
     39#include "RadarOverlayElement.h"
    3640
    3741namespace orxonox{
    3842    class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{
    39         public:
     43      public:
    4044        Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){
    4145            return new BarOverlayElement(instanceName);
     
    4852
    4953    class _OrxonoxExport RadarOverlayElementFactory : public Ogre::OverlayElementFactory{
    50         public:
     54      public:
    5155        Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){
    5256            return new RadarOverlayElement(instanceName);
     
    5963}
    6064
    61 #endif
     65#endif /* _OverlayElementFactories_H__ */
  • code/trunk/src/orxonox/hud/RadarObject.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Felix Schulthess
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Felix Schulthess
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
    2728
     29#include "OrxonoxStableHeaders.h"
    2830#include "RadarObject.h"
     31
     32#include <OgreOverlayManager.h>
     33#include <OgreStringConverter.h>
     34#include "GraphicsEngine.h"
    2935
    3036namespace orxonox
     
    3238    using namespace Ogre;
    3339
    34         int RadarObject::count = 0;             // initialize static variable
     40    int RadarObject::count = 0;         // initialize static variable
    3541
    36         RadarObject::RadarObject(Ogre::OverlayContainer* container){
    37                 container_ = container;
    38                 pos_ = Vector3(0.0, 0.0, 0.0);
    39                 init();
    40         }
    41 
    42         RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){
    43                 container_ = container;
    44                 pos_ = pos;
    45                 init();
    46         }
    47 
    48         RadarObject::~RadarObject(){}
    49 
    50         void RadarObject::init(){
    51             next = NULL;
    52                 om = &Ogre::OverlayManager::getSingleton();
    53                 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
    54                         "Object"+Ogre::StringConverter::toString(count)));
    55                 panel_->setMaterialName("Orxonox/RedDot");
    56                 panel_->setDimensions(3,3);
     42    RadarObject::RadarObject(OverlayContainer* container, SceneNode* node, int colour){
     43        container_ = container;
     44        node_ = node;
     45        colour_ = colour;
     46        om = &OverlayManager::getSingleton();
     47        panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
     48            "Object"+StringConverter::toString(count)));
     49        setColour(colour_);
     50        panel_->setDimensions(3,3);
    5751        panel_->setMetricsMode(Ogre::GMM_PIXELS);
    5852        panel_->show();
     
    6054        count++;
    6155        container_->addChild(panel_);
    62         }
     56    }
     57
     58    RadarObject::~RadarObject(){
     59        delete panel_;
     60    }
     61
     62    void RadarObject::setColour(int colour){
     63        switch(colour){
     64        case RED: panel_->setMaterialName("Orxonox/RedDot"); break;
     65        case YELLOW: panel_->setMaterialName("Orxonox/YellowDot"); break;
     66        case GREEN: panel_->setMaterialName("Orxonox/GreenDot"); break;
     67        case BLUE: panel_->setMaterialName("Orxonox/BlueDot"); break;
     68        case WHITE: panel_->setMaterialName("Orxonox/WhiteDot"); break;
     69        default: panel_->setMaterialName("Orxonox/RedDot"); break;
     70        }
     71    }
     72
     73    void RadarObject::resetColour(){
     74        setColour(colour_);
     75    }
     76
     77    Vector3 RadarObject::getPosition(){
     78        return node_->getPosition();
     79    }
     80
     81    SceneNode* RadarObject::getNode(){
     82        return node_;
     83    }
    6384}
    6485
    65 /* my local clipboard...
    66 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    67 COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
    68 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    69 */
  • code/trunk/src/orxonox/hud/RadarObject.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Felix Schulthess
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
    2728
    28 #ifndef _RADAR2_H__
    29 #define _RADAR2_H__
     29#ifndef _RadarObject_H__
     30#define _RadarObject_H__
    3031
    31 #include <string.h>
    3232#include <OgrePrerequisites.h>
    33 #include <OgreOverlayManager.h>
    34 #include <OgreOverlayElement.h>
     33#include <OgreSceneNode.h>
    3534#include <OgrePanelOverlayElement.h>
    36 #include <OgreStringConverter.h>
    37 
    38 #include <util/Math.h>
    39 #include "../OrxonoxPrereqs.h"
     35#include "OrxonoxPrereqs.h"
     36#include "util/Math.h"
    4037
    4138namespace orxonox
     
    4340    class _OrxonoxExport RadarObject
    4441    {
    45         private:
    46                 Ogre::OverlayManager* om;                               // our one and only overlay manager
    47                 void init();
     42      private:
     43        Ogre::OverlayManager* om;                               // our one and only overlay manager
     44        Ogre::SceneNode* node_;                                 // node of object
     45        int colour_;
    4846
    49         public:
    50                 RadarObject(Ogre::OverlayContainer* container);
    51                 RadarObject(Ogre::OverlayContainer* container, Vector3 pos);
    52                 ~RadarObject();
     47      public:
     48        RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, int colour = 0);
     49        ~RadarObject();
     50        void setColour(int colour);
     51        void resetColour();
     52        Vector3 getPosition();
     53        Ogre::SceneNode* getNode();
    5354
    54             bool right_;
    55             int index_;                             // index number of object
    56                 Vector3 pos_;                                                   // position in space
    57                         Ogre::Real radius_, phi_;                               // position on radar
    58                         Ogre::OverlayContainer* container_;
    59                         Ogre::PanelOverlayElement* panel_;              // the panel used to show the dot
    60                         RadarObject* next;                      // next pointer of linked list
     55        bool right_;
     56        int index_;                             // index number of object
     57        Ogre::OverlayContainer* container_;
     58        Ogre::PanelOverlayElement* panel_;              // the panel used to show the dot
    6159
    62                 static int count;
    63         };
     60        static int count;
     61        static const int RED = 0;
     62        static const int YELLOW = 1;
     63        static const int GREEN = 2;
     64        static const int BLUE = 3;
     65        static const int WHITE = 99;            // used if object got nav focus
     66  };
    6467}
    6568
    66 #endif
     69#endif /* _RadarObject_H__ */
  • code/trunk/src/orxonox/hud/RadarOverlayElement.cc

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
     29#include "OrxonoxStableHeaders.h"
    2830#include "RadarOverlayElement.h"
     31
     32#include <string>
     33#include <OgreOverlayManager.h>
     34#include <OgreStringConverter.h>
     35
     36#include "GraphicsEngine.h"
     37#include "core/Tickable.h"
     38#include "core/ConsoleCommand.h"
     39#include "objects/SpaceShip.h"
     40#include "RadarObject.h"
     41#include "HUD.h"
    2942
    3043namespace orxonox
    3144{
    32     ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);
    33 
    3445    using namespace Ogre;
    3546
    36     RadarOverlayElement* RadarOverlayElement::instance_s = NULL;
    37 
    38     RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
    39         RadarOverlayElement::instance_s = this;
     47    RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){
    4048    }
    4149
     
    4351    }
    4452
    45     void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
     53    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
    4654        // some initial data
    47                 om = &Ogre::OverlayManager::getSingleton();
     55        om = &OverlayManager::getSingleton();
    4856        dimRel_ = dimRel;
    4957        leftRel_ = leftRel;
    5058        topRel_ = topRel;
    5159        container_ = container;
    52         firstRadarObject_ = NULL;
    53         lastRadarObject_ = NULL;
    54         focus_ = NULL;
    5560
    56         // create nav marker ...
    57         navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker"));
    58         navMarker_->setMetricsMode(Ogre::GMM_PIXELS);
    59         navMarker_->setMaterialName("Orxonox/NavMarker");
    60         navMarker_->setDimensions(16,16);
    61         navMarker_->setPosition(0,386);
    62         navMarker_->hide();
    63         container_->addChild(navMarker_);
    64 
    65         // these have to fit the data in the level
    66         shipPos_ = Vector3(0.0, 0.0, 0.0);
    67         initialDir_ = Vector3(1.0, 0.0, 0.0);
    68         currentDir_ = initialDir_;
    69         initialOrth_ = Vector3(0.0, 0.0, 1.0);
    70         currentOrth_ = initialOrth_;
    71         plane = Plane(currentDir_, shipPos_);
    72 
    73         setMetricsMode(Ogre::GMM_PIXELS);
     61        setMetricsMode(GMM_PIXELS);
    7462        setMaterialName("Orxonox/Radar");
    7563        resize();
     
    9078
    9179    void RadarOverlayElement::update() {
    92         shipPos_ = SpaceShip::instance_s->getPosition();
    93         currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
    94                 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
    95         plane = Plane(currentDir_, shipPos_);
    96 
    97         RadarObject* ro = firstRadarObject_;
     80        shipPos_ = SpaceShip::getLocalShip()->getPosition();
     81        currentDir_ = SpaceShip::getLocalShip()->getDir();
     82        currentOrth_ = SpaceShip::getLocalShip()->getOrth();
    9883        // iterate through all RadarObjects
    99                 while(ro != NULL){
    100                     // calc position on radar...
    101             ro->radius_ = calcRadius(ro);
    102             ro->phi_ = calcPhi(ro);
    103             ro->right_ = calcRight(ro);
     84        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
     85        // calc position on radar...
     86            float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it));
     87            float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it));
     88            bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it));
    10489
    10590            // set size to fit distance...
    106             float d = (ro->pos_-shipPos_).length();
    107             if(d<4000) ro->panel_->setDimensions(4,4);
    108             else if(d<8000) ro->panel_->setDimensions(3,3);
    109             else if(d<16000) ro->panel_->setDimensions(2,2);
    110             else ro->panel_->setDimensions(1,1);
     91            float d = ((*it)->getPosition()-shipPos_).length();
     92            if(d<10000) (*it)->panel_->setDimensions(4,4);
     93            else if(d<20000) (*it)->panel_->setDimensions(3,3);
     94            else (*it)->panel_->setDimensions(2,2);
    11195
    112             if (ro->right_){
    113                 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/
    114                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     96            if (right){
     97                (*it)->panel_->setPosition(sin(phi)*radius/
     98                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    11599            }
    116100            else {
    117                 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/
    118                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
    119             }
    120             ro = ro->next;
    121                 }
    122                 updateNavMarker();
    123     }
    124 
    125     void RadarOverlayElement::updateNavMarker(){
    126         if(focus_ == NULL) return;
    127         // from the angle we find out where to draw the marker
    128         // and which of the four arrows to take
    129         float r1 = atan((float)(windowW_)/(float)(windowH_));
    130         float phi = focus_->phi_;
    131         if(focus_->right_){
    132             if(phi<r1){
    133                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
    134                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    135             }
    136             else if(phi>3.14-r1){
    137                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    138                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    139             }
    140             else {
    141                 navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    142                 navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
    143             }
    144         }
    145         else{
    146             if(phi<r1) {
    147                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
    148                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    149             }
    150             else if(phi>3.14-r1) {
    151                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    152                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    153             }
    154             else {
    155                 navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    156                 navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
     101                (*it)->panel_->setPosition(-sin(phi)*radius/
     102                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    157103            }
    158104        }
    159105    }
    160106
    161     void RadarOverlayElement::addObject(Vector3 pos){
    162         if(firstRadarObject_ == NULL){
    163             firstRadarObject_ = new RadarObject(container_, pos);
    164             lastRadarObject_ = firstRadarObject_;
     107    void RadarOverlayElement::listObjects(){
     108        int i = 0;
     109        COUT(3) << "List of RadarObjects:\n";
     110        // iterate through all Radar Objects
     111        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
     112            COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl;
    165113        }
    166         else{
    167             lastRadarObject_->next = new RadarObject(container_, pos);
    168             lastRadarObject_ = lastRadarObject_->next;
    169         }
    170         }
     114    }
    171115
    172         void RadarOverlayElement::listObjects(){
    173             int i = 0;
    174             RadarObject* ro = firstRadarObject_;
    175             COUT(3) << "List of RadarObjects:\n";
    176             // iterate through all Radar Objects
    177             while(ro != NULL) {
    178                 COUT(3) << i++ << ": " << ro->pos_ << std::endl;
    179                 ro = ro->next;
    180             }
    181         }
     116    float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     117        return(acos((dir.dotProduct(obj->getPosition() - pos))/
     118        ((obj->getPosition() - pos).length()*dir.length())));
     119    }
    182120
    183         float RadarOverlayElement::getDist2Focus(){
    184             if(focus_ == NULL) return(0.0);
    185             return((focus_->pos_-shipPos_).length());
    186         }
     121    float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     122        // project difference vector on our plane...
     123        Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos);
     124        // ...and find out the angle
     125        return(acos((orth.dotProduct(proj))/
     126              (orth.length()*proj.length())));
     127    }
    187128
    188         float RadarOverlayElement::calcRadius(RadarObject* obj){
    189             return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/
    190                         ((obj->pos_ - shipPos_).length()*currentDir_.length())));
    191         }
    192 
    193         float RadarOverlayElement::calcPhi(RadarObject* obj){
    194             // project difference vector on our plane...
    195             Ogre::Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);
    196             // ...and find out the angle
    197             return(acos((currentOrth_.dotProduct(proj))/
    198             (currentOrth_.length()*proj.length())));
    199         }
    200 
    201         bool RadarOverlayElement::calcRight(RadarObject* obj){
    202             if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)
    203                 return true;
     129    bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     130        if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0)
     131            return true;
    204132        else return false;
    205         }
    206 
    207         /*static*/void RadarOverlayElement::cycleFocus(){
    208             if(RadarOverlayElement::instance_s == NULL) return;
    209 
    210             if(RadarOverlayElement::instance_s->focus_ == NULL){
    211             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_;
    212             }
    213         else{
    214             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot");
    215             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next;
    216         }
    217 
    218         if(RadarOverlayElement::instance_s->focus_ == NULL){
    219             RadarOverlayElement::instance_s->navMarker_->hide();
    220         }
    221         else{
    222             RadarOverlayElement::instance_s->navMarker_->show();
    223             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot");
    224         }
    225         }
     133    }
    226134}
    227 
    228 /* my local clipboard...
    229 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    230 COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
    231 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    232 */
  • code/trunk/src/orxonox/hud/RadarOverlayElement.h

    r1407 r1502  
    11/*
    2 *   ORXONOX - the hottest 3D action shooter ever to exist
    3 *
    4 *
    5 *   License notice:
    6 *
    7 *   This program is free software; you can redistribute it and/or
    8 *   modify it under the terms of the GNU General Public License
    9 *   as published by the Free Software Foundation; either version 2
    10 *   of the License, or (at your option) any later version.
    11 *
    12 *   This program is distributed in the hope that it will be useful,
    13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 *   GNU General Public License for more details.
    16 *
    17 *   You should have received a copy of the GNU General Public License
    18 *   along with this program; if not, write to the Free Software
    19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20 *
    21 *   Author:
    22 *      Yuning Chai
    23 *   Co-authors:
    24 *      ...
    25 *
    26 */
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Yuning Chai
     24 *   Co-authors:
     25 *      Felix Schulthess
     26 *
     27 */
    2728
    28 #ifndef _RADAR_H__
    29 #define _RADAR_H__
     29#ifndef _RadarOverlayElement_H__
     30#define _RadarOverlayElement_H__
    3031
    31 #include <string.h>
    32 #include <OgreOverlayManager.h>
    33 #include <OgreStringConverter.h>
    34 #include <OgreOverlayElement.h>
     32#include "OrxonoxPrereqs.h"
     33
     34#include <OgrePrerequisites.h>
    3535#include <OgrePanelOverlayElement.h>
    36 #include <OgrePrerequisites.h>
    37 
    38 #include <util/Math.h>
    39 #include <string.h>
    40 #include "core/Tickable.h"
    41 #include "core/ConsoleCommand.h"
    42 #include "objects/SpaceShip.h"
    43 #include "../OrxonoxPrereqs.h"
    44 #include "RadarObject.h"
    45 #include "GraphicsEngine.h"
     36#include "util/Math.h"
    4637
    4738namespace orxonox
     
    4940    class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement
    5041    {
    51         private:
    52             Ogre::OverlayManager* om;               // our one and only overlay manager
    53             Ogre::OverlayContainer* container_;     // pointer to the container we're in
    54             Vector3 initialDir_;                        // direction of nose
    55             Vector3 currentDir_;
    56             Vector3 initialOrth_;                   // direction of normal
    57             Vector3 currentOrth_;
    58             Vector3 shipPos_;                       // position of ship
    59             Ogre::Plane plane;                      // plane perpendicular to dir
     42      private:
     43        Ogre::OverlayManager* om;               // our one and only overlay manager
     44        Ogre::OverlayContainer* container_;     // pointer to the container we're in
     45        Vector3 currentDir_;
     46        Vector3 currentOrth_;
     47        Vector3 shipPos_;                       // position of ship
    6048
    61             Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
    62             int left_, top_, dim_;                  // absolute position/dimension
    63             int windowW_, windowH_;                     // absolute window dimensions
     49        Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
     50        int left_, top_, dim_;                  // absolute position/dimension
     51        int windowW_, windowH_;                   // absolute window dimensions
    6452
    65         public:
    66             RadarOverlayElement(const Ogre::String& name);
    67             ~RadarOverlayElement();
    68             void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
    69                         void resize();
    70             void update();
    71             void updateNavMarker();
    72             void addObject(Vector3 pos);
    73             void listObjects();
    74             float getDist2Focus();
    75             float calcRadius(RadarObject* obj);
    76             float calcPhi(RadarObject* obj);
    77             bool calcRight(RadarObject* obj);
     53      public:
     54        RadarOverlayElement(const Ogre::String& name);
     55        ~RadarOverlayElement();
     56        void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
     57        void resize();
     58        void update();
     59        void listObjects();
    7860
    79             Ogre::PanelOverlayElement* navMarker_;  // marker to help navigating
    80                         RadarObject* firstRadarObject_;         // start of linked list
    81                         RadarObject* lastRadarObject_;          // end of linked list
    82                         RadarObject* focus_;                    // object that is focussed
    83 
    84             static RadarOverlayElement* instance_s;
    85             static void cycleFocus();
    86         };
     61        static float calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     62        static float calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     63        static bool calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj);
     64  };
    8765}
    8866
    89 #endif
     67#endif /* _RadarOverlayElement_H__ */
  • code/trunk/src/orxonox/objects/Ambient.cc

    r1293 r1502  
    4747namespace orxonox
    4848{
    49     ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));
     49    SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline);
    5050
    5151    CreateFactory(Ambient);
     
    6666    bool Ambient::create(){
    6767      GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_);
    68       return true;
     68      return Synchronisable::create();
    6969    }
    7070   
  • code/trunk/src/orxonox/objects/Ambient.h

    r1293 r1502  
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4848            void setAmbientLight(const ColourValue& colour);
    49             bool create();
     49            virtual bool create();
    5050            void registerAllVariables();
    5151
  • code/trunk/src/orxonox/objects/Camera.cc

    r1293 r1502  
    6060  {
    6161    CameraHandler::getInstance()->releaseFocus(this);
     62    GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName());
    6263  }
    6364
     
    7576  void Camera::tick(float dt)
    7677  {
    77     if(this->positionNode_ != NULL) {
     78    if (this->positionNode_ != NULL)
     79    {
    7880      // this stuff here may need some adjustments
    79       Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getPosition();
    80       this->cameraNode_->translate(15*dt*offset);
     81      Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getWorldPosition();
     82      float coeff = 15.0f * dt;
     83      if (coeff > 1.0f)
     84        coeff = 1.0f;
    8185
    82       this->cameraNode_->setOrientation(Quaternion::Slerp(0.7, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false));
     86      this->cameraNode_->translate(coeff * offset);
     87
     88      this->cameraNode_->setOrientation(Quaternion::Slerp(7.0f * dt, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false));
    8389    }
    8490  }
  • code/trunk/src/orxonox/objects/Camera.h

    r1407 r1502  
    5050        void setTargetNode(Ogre::SceneNode* obj);
    5151
     52        Ogre::Camera* cam_;
     53
    5254        void tick(float dt);
    5355        void update();
     
    6365        Ogre::SceneNode* cameraNode_;
    6466        Ogre::Vector3 oldPos;
    65         Ogre::Camera* cam_;
    6667        bool bHasFocus_;
    6768    };
  • code/trunk/src/orxonox/objects/CameraHandler.cc

    r1293 r1502  
    2626 *
    2727 */
     28#include "OrxonoxStableHeaders.h"
     29#include "CameraHandler.h"
     30
    2831#include <OgreSceneManager.h>
    2932#include <OgreRenderWindow.h>
    3033
    31 #include "OrxonoxStableHeaders.h"
    3234#include "core/ObjectList.h"
    33 #include "CameraHandler.h"
    3435#include "Camera.h"
    3536#include "GraphicsEngine.h"
  • code/trunk/src/orxonox/objects/Explosion.cc

    r1293 r1502  
    7979        }
    8080    };
     81   
     82    /*bool Explosion::create(){
     83      if(!WorldEntity::create())
     84        return false;
     85      classID=this->getIdentifier()->getNetworkID();
     86    }*/
    8187
    8288    void Explosion::destroyObject()
  • code/trunk/src/orxonox/objects/Explosion.h

    r1056 r1502  
    4343            virtual ~Explosion();
    4444            void destroyObject();
     45            virtual bool create(){return WorldEntity::create();}
    4546
    4647        private:
  • code/trunk/src/orxonox/objects/Model.cc

    r1293 r1502  
    3434#include "GraphicsEngine.h"
    3535#include "core/XMLPort.h"
     36
     37#include <OgreEntity.h>
     38#include <OgreMesh.h>
     39#include <OgreHardwareVertexBuffer.h>
     40#include <OgreMeshManager.h>
     41
    3642
    3743namespace orxonox
     
    7783        this->mesh_.setMesh(meshSrc_);
    7884        this->attachObject(this->mesh_.getEntity());
     85
     86        //HACK!!
     87        /*if ((this->meshSrc_ == "assff.mesh") || (this->meshSrc_ == "ast1.mesh") || (this->meshSrc_ == "ast2.mesh") || (this->meshSrc_ == "ast3.mesh") || (this->meshSrc_ == "ast4.mesh") ||(this->meshSrc_ == "ast5.mesh") || (this->meshSrc_ == "ast6.mesh"))
     88        {
     89          Ogre::MeshPtr pMesh = this->mesh_.getEntity()->getMesh();
     90          //set Mesh to tangentspace
     91          unsigned short src, dest;
     92          if (!pMesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
     93          {
     94            pMesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
     95          }
     96          if ((this->meshSrc_ == "assff.mesh"))
     97          {
     98            (this->mesh_.getEntity())->setMaterialName("Assff/BumpMap");
     99          }
     100          else
     101          {
     102            (this->mesh_.getEntity())->setMaterialName("Asteroid/BumpMap");
     103          }
     104
     105
     106        }*/
    79107        COUT(4) << "Loader (Model.cc): Created model" << std::endl;
    80108      }
  • code/trunk/src/orxonox/objects/Model.h

    r1293 r1502  
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646            void setMesh(const std::string& meshname);
    47             bool create();
     47            virtual bool create();
    4848
    4949        protected:
  • code/trunk/src/orxonox/objects/NPC.cc

    r1293 r1502  
    6767  }
    6868 
    69   bool NPC::create(){
    70     Model::create();
    71     return true;
    72   }
    7369
    7470  /**
  • code/trunk/src/orxonox/objects/NPC.h

    r1293 r1502  
    5353      void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable);
    5454      void registerAllVariables();
    55       bool create();
     55      virtual bool create(){return Model::create();}
    5656
    5757    private:
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1360 r1502  
    3030#include "Projectile.h"
    3131
     32#include <OgreBillboard.h>
     33
    3234#include "core/CoreIncludes.h"
    3335#include "core/Executor.h"
     
    4143{
    4244    CreateFactory(Projectile);
     45
     46    float Projectile::speed_ = 0;
    4347
    4448    Projectile::Projectile(SpaceShip* owner) :
     
    6367
    6468        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    65         this->classID = this->getIdentifier()->getNetworkID(); // TODO: remove this hack
    6669//        COUT(3) << this->classID << std::endl;
    6770    }
     
    9295                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    9396                {
    94                     new Explosion(this);
     97                    Explosion *exp = new Explosion(this);
     98                    exp->create();
    9599                    delete this;
    96100                    return;
     
    104108        delete this;
    105109    }
     110
     111    void Projectile::setColour(const ColourValue& colour)
     112    {
     113        this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
     114    }
    106115}
  • code/trunk/src/orxonox/objects/Projectile.h

    r1056 r1502  
    3535#include "../tools/BillboardSet.h"
    3636#include "../tools/Timer.h"
     37#include "util/Math.h"
    3738
    3839namespace orxonox
     
    4647            void destroyObject();
    4748            virtual void tick(float dt);
     49            virtual bool create(){return WorldEntity::create();}
     50            void setColour(const ColourValue& colour);
     51
     52            static float getSpeed()
     53                { return Projectile::speed_; }
     54
     55        protected:
     56            SpaceShip* owner_;
    4857
    4958        private:
    50             SpaceShip* owner_;
    5159            BillboardSet billboard_;
    52             float speed_;
     60            static float speed_;
    5361            float lifetime_;
    5462            Timer<Projectile> destroyTimer_;
  • code/trunk/src/orxonox/objects/Skybox.cc

    r1293 r1502  
    9090    bool Skybox::create(){
    9191      this->setSkybox(skyboxSrc_);
    92       return true;
     92      return Synchronisable::create();
    9393    }
    9494   
  • code/trunk/src/orxonox/objects/Skybox.h

    r1293 r1502  
    4747            void setSkybox(const std::string& skyboxname);
    4848           
    49             bool create();
     49            virtual bool create();
    5050            void registerAllVariables();
    5151            void setSkyboxSrc(const std::string &src);
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1407 r1502  
    4545#include "particle/ParticleInterface.h"
    4646#include "Projectile.h"
     47#include "RotatingProjectile.h"
    4748#include "core/XMLPort.h"
    4849#include "core/ConsoleCommand.h"
    4950#include "network/Client.h"
     51#include "hud/HUD.h"
    5052
    5153namespace orxonox
    5254{
    53     ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);
    54     ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true);
    55     ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);
    56     ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);
    57     ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);
     55    SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug);
     56    SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User);
     57    SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     58    SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     59    SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     60    SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     61    SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
     62    SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold);
     63    SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);
     64    SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);
     65    SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);
    5866
    5967    CreateFactory(SpaceShip);
     
    6472      Iterator<SpaceShip> it;
    6573      for(it = ObjectList<SpaceShip>::start(); it; ++it){
    66         if((it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ) )
     74        if( (it)->myShip_ )
    6775          return *it;
    6876      }
    6977      return NULL;
    7078    }
    71    
     79
    7280    SpaceShip::SpaceShip() :
    7381      //testvector_(0,0,0),
     
    103111      mouseY_(0.0f),
    104112      emitterRate_(0.0f),
    105       server_(false)
     113      myShip_(false),
     114      teamNr_(0),
     115      health_(100)
    106116    {
    107117        RegisterObject(SpaceShip);
     
    112122        this->setConfigValues();
    113123
     124        initialDir_ = Vector3(1.0, 0.0, 0.0);
     125        currentDir_ = initialDir_;
     126        initialOrth_ = Vector3(0.0, 0.0, 1.0);
     127        currentOrth_ = initialOrth_;
     128
     129        this->camName_ = this->getName() + "CamNode";
    114130
    115131        this->setRotationAxis(1, 0, 0);
     
    127143        if (this->cam_)
    128144          delete this->cam_;
     145        if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL)
     146          //remove the radar object
     147          HUD::getSingleton().removeRadarObject(this->getNode());
    129148    }
    130149
    131150    bool SpaceShip::create(){
     151      if(!myShip_){
     152        if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID())
     153          myShip_=true;
     154        else
     155          HUD::getSingleton().addRadarObject(this->getNode(), 3);
     156      }
    132157      if(Model::create())
    133158        this->init();
     
    153178    void SpaceShip::init()
    154179    {
    155         if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))
    156         {
    157               if (!setMouseEventCallback_)
    158               {
    159                   InputManager::addMouseHandler(this, "SpaceShip");
    160                   //InputManager::enableMouseHandler("SpaceShip");
    161                   setMouseEventCallback_ = true;
    162               }
    163         }
    164 
    165180        // START CREATING THRUSTER
    166181        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     
    200215        // END CREATING BLINKING LIGHTS
    201216
    202         // START of testing crosshair
    203         this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
    204         this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
    205 
    206         this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
    207         this->chNearNode_->setInheritScale(false);
    208         this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
    209         this->chFarNode_->setInheritScale(false);
    210 
    211         this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
    212         this->chNearNode_->setScale(0.2, 0.2, 0.2);
    213 
    214         this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
    215         this->chFarNode_->setScale(0.4, 0.4, 0.4);
     217        if (this->isExactlyA(Class(SpaceShip)))
     218        {
     219            // START of testing crosshair
     220            this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
     221            this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
     222
     223            this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
     224            this->chNearNode_->setInheritScale(false);
     225            this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
     226            this->chFarNode_->setInheritScale(false);
     227
     228            this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
     229            this->chNearNode_->setScale(0.2, 0.2, 0.2);
     230
     231            this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
     232            this->chFarNode_->setScale(0.4, 0.4, 0.4);
     233        }
    216234
    217235        createCamera();
     
    237255        CameraHandler::getInstance()->requestFocus(cam_);
    238256
     257    }
     258
     259    Camera* SpaceShip::getCamera(){
     260        return cam_;
    239261    }
    240262
     
    295317        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    296318        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
    297         server_=true; // TODO: this is only a hack
     319        myShip_=true; // TODO: this is only a hack
     320
    298321        SpaceShip::create();
    299         getFocus();
     322        if (this->isExactlyA(Class(SpaceShip)))
     323            getFocus();
    300324    }
    301325
     
    308332    }
    309333
    310     void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    311     {
    312 /*
    313         this->mouseX += e.state.X.rel;
    314         if (this->bInvertMouse_)
    315             this->mouseY += e.state.Y.rel;
    316         else
    317             this->mouseY -= e.state.Y.rel;
    318 
    319 //        if(mouseX>maxMouseX) maxMouseX = mouseX;
    320 //        if(mouseX<minMouseX) minMouseX = mouseX;
    321 //        cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;
    322 
    323         this->moved = true;
    324 */
    325         if (this->bRMousePressed_)
    326         {
    327             this->camNode_->roll(Degree(-rel.x * 0.10));
    328             this->camNode_->yaw(Degree(rel.y * 0.10));
    329         }
    330         else
    331         {
    332             float minDimension = clippingSize.y;
    333             if (clippingSize.x < minDimension)
    334                 minDimension = clippingSize.x;
    335 
    336             this->mouseX_ += rel.x;
    337             if (this->mouseX_ < -minDimension)
    338                 this->mouseX_ = -minDimension;
    339             if (this->mouseX_ > minDimension)
    340                 this->mouseX_ = minDimension;
    341 
    342             this->mouseY_ += rel.y;
    343             if (this->mouseY_ < -minDimension)
    344                 this->mouseY_ = -minDimension;
    345             if (this->mouseY_ > minDimension)
    346                 this->mouseY_ = minDimension;
    347 
    348             float xRotation = this->mouseX_ / minDimension;
    349             xRotation = xRotation*xRotation * sgn(xRotation);
    350             xRotation *= -this->rotationAcceleration_;
    351             if (xRotation > this->maxRotation_)
    352                 xRotation = this->maxRotation_;
    353             if (xRotation < -this->maxRotation_)
    354                 xRotation = -this->maxRotation_;
    355             this->mouseXRotation_ = Radian(xRotation);
    356 
    357             float yRotation = this->mouseY_ / minDimension;
    358             yRotation = yRotation*yRotation * sgn(yRotation);
    359             yRotation *= this->rotationAcceleration_;
    360             if (yRotation > this->maxRotation_)
    361                 yRotation = this->maxRotation_;
    362             if (yRotation < -this->maxRotation_)
    363                 yRotation = -this->maxRotation_;
    364             this->mouseYRotation_ = Radian(yRotation);
    365         }
    366     }
    367 
    368     void SpaceShip::mouseButtonPressed(MouseButton::Enum id)
    369     {
    370         if (id == MouseButton::Left)
    371             this->bLMousePressed_ = true;
    372         else if (id == MouseButton::Right)
    373             this->bRMousePressed_ = true;
    374     }
    375 
    376     void SpaceShip::mouseButtonReleased(MouseButton::Enum id)
    377     {
    378         if (id == MouseButton::Left)
    379             this->bLMousePressed_ = false;
    380         else if (id == MouseButton::Right)
    381         {
    382             this->bRMousePressed_ = false;
    383             this->camNode_->resetOrientation();
    384         }
    385     }
    386 
    387334    std::string SpaceShip::whereAmI() {
    388335        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
     
    391338    }
    392339
    393     Vector3 SpaceShip::getSPosition() {
    394         return SpaceShip::getLocalShip()->getPosition();
    395     }
    396 
    397     Quaternion SpaceShip::getSOrientation() {
    398         return SpaceShip::getLocalShip()->getOrientation();
     340    Vector3 SpaceShip::getDir() {
     341        return currentDir_;
     342    }
     343
     344    Vector3 SpaceShip::getOrth(){
     345        return currentOrth_;
    399346    }
    400347
     
    403350    void SpaceShip::tick(float dt)
    404351    {
     352        currentDir_ = getOrientation()*initialDir_;
     353                currentOrth_ = getOrientation()*initialOrth_;
     354
    405355        if (this->cam_)
    406356            this->cam_->tick(dt);
     
    422372        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
    423373        {
    424          
    425             Projectile *p = new Projectile(this);
    426            
     374
     375            Projectile *p;
     376            if (this->isExactlyA(Class(SpaceShip)))
     377                p = new RotatingProjectile(this);
     378            else
     379                p = new Projectile(this);
     380            p->setColour(this->getProjectileColour());
     381            p->create();
     382            if(p->classID==0)
     383              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
     384
    427385            p->setBacksync(true);
    428386            this->timeToReload_ = this->reloadTime_;
     
    495453        }
    496454
    497         if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ )
    498         {
    499           COUT(4) << "steering our ship: " << objectID << std::endl;
    500           if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W))
    501             this->acceleration_.x = this->translationAcceleration_;
    502           else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S))
    503             this->acceleration_.x = -this->translationAcceleration_;
    504           else
    505             this->acceleration_.x = 0;
    506 
    507           if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D))
    508             this->acceleration_.y = -this->translationAcceleration_;
    509           else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A))
    510             this->acceleration_.y = this->translationAcceleration_;
    511           else
    512             this->acceleration_.y = 0;
    513 
    514           if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q))
    515             this->momentum_ = Radian(-this->rotationAccelerationRadian_);
    516           else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E))
    517             this->momentum_ = Radian(this->rotationAccelerationRadian_);
    518           else
    519             this->momentum_ = 0;
    520         }/*else
    521           COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
    522455
    523456        WorldEntity::tick(dt);
     
    533466        else
    534467            this->tt_->setRate(0);
    535     }
    536 
     468
     469        if( myShip_ )
     470        {
     471          COUT(4) << "steering our ship: " << objectID << std::endl;
     472          this->acceleration_.x = 0;
     473          this->acceleration_.y = 0;
     474          this->momentum_ = 0;
     475          this->mouseXRotation_ = Radian(0);
     476          this->mouseYRotation_ = Radian(0);
     477          this->bLMousePressed_ = false;
     478        }/*else
     479          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
     480    }
     481
     482    void SpaceShip::movePitch(float val)
     483    {   getLocalShip()->setMovePitch(val);   }
     484    void SpaceShip::moveYaw(float val)
     485    {   getLocalShip()->setMoveYaw(val);   }
     486    void SpaceShip::moveRoll(float val)
     487    {   getLocalShip()->setMoveRoll(val);   }
     488    void SpaceShip::moveLongitudinal(float val)
     489    {   getLocalShip()->setMoveLongitudinal(val);   }
     490    void SpaceShip::moveLateral(float val)
     491    {   getLocalShip()->setMoveLateral(val);   }
     492    void SpaceShip::fire()
     493    {   getLocalShip()->doFire();   }
     494
     495    void SpaceShip::setMovePitch(float val)
     496    {
     497        val = -val * val * sgn(val) * this->rotationAcceleration_;
     498        if (val > this->maxRotation_)
     499            val = this->maxRotation_;
     500        if (val < -this->maxRotation_)
     501            val = -this->maxRotation_;
     502        this->mouseYRotation_ = Radian(val);
     503    }
     504
     505    void SpaceShip::setMoveYaw(float val)
     506    {
     507        val = -val * val * sgn(val) * this->rotationAcceleration_;
     508        if (val > this->maxRotation_)
     509            val = this->maxRotation_;
     510        if (val < -this->maxRotation_)
     511            val = -this->maxRotation_;
     512        this->mouseXRotation_ = Radian(val);
     513    }
     514
     515    void SpaceShip::setMoveRoll(float val)
     516    {
     517        this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val);
     518        //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl;
     519    }
     520
     521    void SpaceShip::setMoveLongitudinal(float val)
     522    {
     523        this->acceleration_.x = this->translationAcceleration_ * val;
     524    }
     525
     526    void SpaceShip::setMoveLateral(float val)
     527    {
     528        this->acceleration_.y = -this->translationAcceleration_ * val;
     529    }
     530
     531    void SpaceShip::doFire()
     532    {
     533        this->bLMousePressed_ = true;
     534    }
    537535}
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1407 r1502  
    4141namespace orxonox
    4242{
    43     class _OrxonoxExport SpaceShip : public Model, public MouseHandler
     43    class _OrxonoxExport SpaceShip : public Model
    4444    {
    4545        public:
    46          
     46
    4747            static SpaceShip *getLocalShip();
    48            
     48
    4949            SpaceShip();
    5050            ~SpaceShip();
    51             bool create();
     51            virtual bool create();
    5252            void registerAllVariables();
    5353            void init();
     
    6464            void setTransDamp(float value);
    6565            void setRotDamp(float value);
     66            void getFocus();
    6667
    67             void getFocus();
    68             static SpaceShip* instance_s;
    69             static Vector3 getSPosition();
    70             static Quaternion getSOrientation();
    7168            static std::string whereAmI();
    7269            static void setMaxSpeedTest(float value)
    7370                { SpaceShip::instance_s->setMaxSpeed(value); }
    7471
    75             void mouseButtonPressed (MouseButton::Enum id);
    76             void mouseButtonReleased(MouseButton::Enum id);
    77             void mouseButtonHeld    (MouseButton::Enum id) { }
    78             void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    79             void mouseScrolled      (int abs, int rel) { }
     72            static void movePitch(float value);
     73            static void moveYaw(float value);
     74            static void moveRoll(float value);
     75            static void moveLongitudinal(float value);
     76            static void moveLateral(float value);
     77            static void fire();
     78            void setMovePitch(float value);
     79            void setMoveYaw(float value);
     80            void setMoveRoll(float value);
     81            void setMoveLongitudinal(float value);
     82            void setMoveLateral(float value);
     83            void doFire();
    8084
    8185            float getMaxSpeed();
     86            Vector3 getDir();
     87            Vector3 getOrth();
     88            Camera* getCamera();
     89
     90            int getTeamNr() const
     91                { return this->teamNr_; }
     92            int getHealth() const
     93                { return this->health_; }
     94
     95            bool getMyShip(){return myShip_;}
     96
     97        protected:
     98            void setTeamNr(int teamNr)
     99                { this->teamNr_ = teamNr; }
    82100
    83101        private:
    84102            void createCamera();
     103            virtual ColourValue getProjectileColour() const
     104                { return ColourValue(1.0, 1.0, 0.5); }
    85105
    86106            Vector3 testvector_;
     107            Vector3 initialDir_;
     108            Vector3 currentDir_;
     109            Vector3 initialOrth_;
     110            Vector3 currentOrth_;
    87111            bool bInvertYAxis_;
    88112            bool setMouseEventCallback_;
     
    130154
    131155            float emitterRate_;
    132             bool server_;
     156
     157        protected:
     158            bool myShip_;
     159
     160            int teamNr_;
     161            int health_;
     162
     163            static SpaceShip* instance_s;
    133164    };
    134165}
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r1360 r1502  
    8585            this->rotationRate_ += (dt * this->momentum_);
    8686            this->rotate(this->rotationAxis_, dt * this->rotationRate_);
     87            //COUT(3) << "rotationrate: " << this->rotationRate_.valueDegrees() << " momentum: " << this->momentum_.valueDegrees() << std::endl;
    8788        }
    8889    }
     
    153154      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
    154155      //register acceleration & momentum
    155       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
    156       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
    157       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
    158       registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA);
     156//       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x2);
     157//       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x2);
     158//       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x2);
     159//       registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA, 0x2); // only backsync
    159160    }
    160161
  • code/trunk/src/orxonox/objects/WorldEntity.h

    r1227 r1502  
    5353            virtual void loadParams(TiXmlElement* xmlElem);
    5454            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    55             inline bool create(){ return true; }
     55            virtual inline bool create(){ return Synchronisable::create(); }
    5656
    5757            void attachWorldEntity(WorldEntity* entity);
  • code/trunk/src/orxonox/objects/weapon/AmmunitionDump.h

    r1056 r1502  
    6060
    6161  protected:
    62     inline bool create() { return true; }
     62    inline bool create() { return Synchronisable::create(); }
    6363    void registerAllVariables();
    6464
  • code/trunk/src/orxonox/objects/weapon/BulletManager.h

    r1209 r1502  
    6060
    6161  protected:
    62     inline bool create() { return true; }
     62    inline bool create() { return Synchronisable::create(); }
    6363    void registerAllVariables();
    6464
  • code/trunk/src/orxonox/tools/Mesh.cc

    r1056 r1502  
    4040    unsigned int Mesh::meshCounter_s = 0;
    4141
    42     Mesh::Mesh()
     42    Mesh::Mesh() :
     43      entity_(0)
    4344    {
    44         this->entity_ = 0;
    4545    }
    4646
  • code/trunk/src/orxonox/tools/Timer.cc

    r1293 r1502  
    2727 */
    2828
     29#include <set>
     30
    2931#include "OrxonoxStableHeaders.h"
    3032#include "Timer.h"
     
    3739namespace orxonox
    3840{
    39     ConsoleCommandShortcutExtern(delay, AccessLevel::None);
     41    SetConsoleCommandShortcutExtern(delay);
     42    SetConsoleCommandShortcutExtern(killdelays);
     43
     44    static std::set<StaticTimer*> delaytimerset;
    4045
    4146    /**
     
    4752    {
    4853        StaticTimer *delaytimer = new StaticTimer();
     54        delaytimerset.insert(delaytimer);
     55
    4956        ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand));
    5057        delayexecutor->setDefaultValues(delaytimer, command);
     
    6168        CommandExecutor::execute(command);
    6269        delete timer;
     70        delaytimerset.erase(timer);
     71    }
     72
     73    /**
     74        @brief Kills all delayed commands.
     75    */
     76    void killdelays()
     77    {
     78        for (std::set<StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it)
     79            delete (*it);
     80
     81        delaytimerset.clear();
    6382    }
    6483
  • code/trunk/src/orxonox/tools/Timer.h

    r1056 r1502  
    6969    class StaticTimer;
    7070    void delay(float delay, const std::string& command);
     71    void killdelays();
    7172    void executeDelayedCommand(StaticTimer* timer, const std::string& command);
    7273
  • code/trunk/src/util/Convert.h

    r1064 r1502  
    384384        else if (input.getType() == MT_vector3)
    385385            return ConvertValue(output, input.getVector3());
     386        else if (input.getType() == MT_vector4)
     387            return ConvertValue(output, input.getVector4());
    386388        else if (input.getType() == MT_quaternion)
    387389            return ConvertValue(output, input.getQuaternion());
  • code/trunk/src/util/Math.h

    r1349 r1502  
    121121
    122122template <typename T>
     123inline int mod(T x, int max)
     124{
     125    if (x >= 0)
     126        return (x % max);
     127    else
     128        return ((x % max) + max);
     129}
     130
     131template <typename T>
    123132T interpolate(float time, const T& start, const T& end)
    124133{
  • code/trunk/src/util/MultiType.h

    r1056 r1502  
    5454    MT_vector2,
    5555    MT_vector3,
     56    MT_vector4,
    5657    MT_colourvalue,
    5758    MT_quaternion,
  • code/trunk/src/util/MultiTypeMath.cc

    r1056 r1502  
    3737    else if (type == MT_vector3)
    3838        this->vector3_ = orxonox::Vector3(0, 0, 0);
     39    else if (type == MT_vector4)
     40        this->vector4_ = orxonox::Vector4(0, 0, 0, 0);
    3941    else if (type == MT_colourvalue)
    4042        this->colourvalue_ = orxonox::ColourValue(0, 0, 0, 0);
     
    5557        else if (this->type_ == MT_vector3)
    5658            return (this->vector3_ == mtm.vector3_);
     59        else if (this->type_ == MT_vector4)
     60            return (this->vector4_ == mtm.vector4_);
    5761        else if (this->type_ == MT_colourvalue)
    5862            return (this->colourvalue_ == mtm.colourvalue_);
     
    6872}
    6973
     74bool MultiTypeMath::operator==(const MultiTypeString& mts) const
     75{
     76    return MultiTypeString::operator==(mts);
     77}
     78
     79bool MultiTypeMath::operator==(const MultiTypePrimitive& mtp) const
     80{
     81    return MultiTypePrimitive::operator==(mtp);
     82}
     83
    7084bool MultiTypeMath::operator!=(const MultiTypeMath& mtm) const
    7185{
     
    7690        else if (this->type_ == MT_vector3)
    7791            return (this->vector3_ != mtm.vector3_);
     92        else if (this->type_ == MT_vector4)
     93            return (this->vector4_ != mtm.vector4_);
    7894        else if (this->type_ == MT_colourvalue)
    7995            return (this->colourvalue_ != mtm.colourvalue_);
     
    87103
    88104    return true;
     105}
     106
     107bool MultiTypeMath::operator!=(const MultiTypeString& mts) const
     108{
     109    return MultiTypeString::operator!=(mts);
     110}
     111
     112bool MultiTypeMath::operator!=(const MultiTypePrimitive& mtp) const
     113{
     114    return MultiTypePrimitive::operator!=(mtp);
    89115}
    90116
     
    123149MultiTypeMath::operator orxonox::Vector3() const
    124150{ return (this->type_ == MT_vector3) ? this->vector3_ : getConvertedValue<MultiTypeMath, orxonox::Vector3>(*this); }
     151MultiTypeMath::operator orxonox::Vector4() const
     152{ return (this->type_ == MT_vector4) ? this->vector4_ : getConvertedValue<MultiTypeMath, orxonox::Vector4>(*this); }
    125153MultiTypeMath::operator orxonox::Quaternion() const
    126154{ return (this->type_ == MT_quaternion) ? this->quaternion_ : getConvertedValue<MultiTypeMath, orxonox::Quaternion>(*this); }
     
    137165    this->vector2_ = mtm.vector2_;
    138166    this->vector3_ = mtm.vector3_;
     167    this->vector4_ = mtm.vector4_;
    139168    this->quaternion_ = mtm.quaternion_;
    140169    this->colourvalue_ = mtm.colourvalue_;
     
    143172}
    144173
     174void MultiTypeMath::setValue(const MultiTypeString& mts)
     175{
     176    MultiTypeString::setValue(mts);
     177}
     178
     179void MultiTypeMath::setValue(const MultiTypePrimitive& mtp)
     180{
     181    MultiTypePrimitive::setValue(mtp);
     182}
     183
    145184std::string MultiTypeMath::getTypename() const
    146185{
     
    149188    else if (this->type_ == MT_vector3)
    150189        return "Vector3";
     190    else if (this->type_ == MT_vector4)
     191        return "Vector4";
    151192    else if (this->type_ == MT_colourvalue)
    152193        return "ColourValue";
     
    169210    else if (this->type_ == MT_vector3)
    170211        ConvertValue(&output, this->vector3_);
     212    else if (this->type_ == MT_vector4)
     213        ConvertValue(&output, this->vector4_);
    171214    else if (this->type_ == MT_colourvalue)
    172215        ConvertValue(&output, this->colourvalue_);
     
    189232    else if (this->type_ == MT_vector3)
    190233        return ConvertValue(&this->vector3_, value, orxonox::Vector3(0, 0, 0));
     234    else if (this->type_ == MT_vector4)
     235        return ConvertValue(&this->vector4_, value, orxonox::Vector4(0, 0, 0, 0));
    191236    else if (this->type_ == MT_colourvalue)
    192237        return ConvertValue(&this->colourvalue_, value, orxonox::ColourValue(0, 0, 0, 0));
     
    201246}
    202247
     248bool MultiTypeMath::assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue)
     249{
     250    if (this->type_ == MT_void)
     251        return ConvertValue(&this->value_.void_, mtm, defvalue.value_.void_);
     252    else if (this->type_ == MT_int)
     253        return ConvertValue(&this->value_.int_, mtm, defvalue.value_.int_);
     254    else if (this->type_ == MT_uint)
     255        return ConvertValue(&this->value_.uint_, mtm, defvalue.value_.uint_);
     256    else if (this->type_ == MT_char)
     257        return ConvertValue(&this->value_.char_, mtm, defvalue.value_.char_);
     258    else if (this->type_ == MT_uchar)
     259        return ConvertValue(&this->value_.uchar_, mtm, defvalue.value_.uchar_);
     260    else if (this->type_ == MT_short)
     261        return ConvertValue(&this->value_.short_, mtm, defvalue.value_.short_);
     262    else if (this->type_ == MT_ushort)
     263        return ConvertValue(&this->value_.ushort_, mtm, defvalue.value_.ushort_);
     264    else if (this->type_ == MT_long)
     265        return ConvertValue(&this->value_.long_, mtm, defvalue.value_.long_);
     266    else if (this->type_ == MT_ulong)
     267        return ConvertValue(&this->value_.ulong_, mtm, defvalue.value_.ulong_);
     268    else if (this->type_ == MT_float)
     269        return ConvertValue(&this->value_.float_, mtm, defvalue.value_.float_);
     270    else if (this->type_ == MT_double)
     271        return ConvertValue(&this->value_.double_, mtm, defvalue.value_.double_);
     272    else if (this->type_ == MT_longdouble)
     273        return ConvertValue(&this->value_.longdouble_, mtm, defvalue.value_.longdouble_);
     274    else if (this->type_ == MT_bool)
     275        return ConvertValue(&this->value_.bool_, mtm, defvalue.value_.bool_);
     276    else if (this->type_ == MT_constchar)
     277        return ConvertValue(&this->string_, mtm, defvalue.string_);
     278    else if (this->type_ == MT_string)
     279        return ConvertValue(&this->string_, mtm, defvalue.string_);
     280    else if (this->type_ == MT_vector2)
     281        return ConvertValue(&this->vector2_, mtm, defvalue.vector2_);
     282    else if (this->type_ == MT_vector3)
     283        return ConvertValue(&this->vector3_, mtm, defvalue.vector3_);
     284    else if (this->type_ == MT_vector4)
     285        return ConvertValue(&this->vector4_, mtm, defvalue.vector4_);
     286    else if (this->type_ == MT_colourvalue)
     287        return ConvertValue(&this->colourvalue_, mtm, defvalue.colourvalue_);
     288    else if (this->type_ == MT_quaternion)
     289        return ConvertValue(&this->quaternion_, mtm, defvalue.quaternion_);
     290    else if (this->type_ == MT_radian)
     291        return ConvertValue(&this->radian_, mtm, defvalue.radian_);
     292    else if (this->type_ == MT_degree)
     293        return ConvertValue(&this->degree_, mtm, defvalue.degree_);
     294    else
     295        return false;
     296}
     297
    203298std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm)
    204299{
  • code/trunk/src/util/MultiTypeMath.h

    r1064 r1502  
    6363        inline MultiTypeMath(const orxonox::Vector2&     value) { this->setValue(value); }
    6464        inline MultiTypeMath(const orxonox::Vector3&     value) { this->setValue(value); }
     65        inline MultiTypeMath(const orxonox::Vector4&     value) { this->setValue(value); }
    6566        inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); }
    6667        inline MultiTypeMath(const orxonox::Quaternion&  value) { this->setValue(value); }
     
    6869        inline MultiTypeMath(const orxonox::Degree&      value) { this->setValue(value); }
    6970        inline MultiTypeMath(const MultiTypeMath& mtm)          { this->setValue(mtm);   }
     71        inline MultiTypeMath(const MultiTypeString& mts)        { this->setValue(mts);   }
     72        inline MultiTypeMath(const MultiTypePrimitive& mtp)     { this->setValue(mtp);   }
    7073        virtual inline ~MultiTypeMath() {}
    7174
     
    7376        inline MultiTypeMath& operator=(const orxonox::Vector2&     value) { this->setValue(value); return *this; }
    7477        inline MultiTypeMath& operator=(const orxonox::Vector3&     value) { this->setValue(value); return *this; }
     78        inline MultiTypeMath& operator=(const orxonox::Vector4&     value) { this->setValue(value); return *this; }
    7579        inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; }
    7680        inline MultiTypeMath& operator=(const orxonox::Quaternion&  value) { this->setValue(value); return *this; }
     
    7882        inline MultiTypeMath& operator=(const orxonox::Degree&      value) { this->setValue(value); return *this; }
    7983        inline MultiTypeMath& operator=(const MultiTypeMath& mtm)          { this->setValue(mtm);   return *this; }
     84        inline MultiTypeMath& operator=(const MultiTypeString& mts)        { this->setValue(mts);   return *this; }
     85        inline MultiTypeMath& operator=(const MultiTypePrimitive mtp)      { this->setValue(mtp);   return *this; }
    8086
    8187        using MultiTypeString::operator==;
    8288        inline bool operator==(const orxonox::Vector2&     value) const { return (this->vector2_     == value); }
    8389        inline bool operator==(const orxonox::Vector3&     value) const { return (this->vector3_     == value); }
     90        inline bool operator==(const orxonox::Vector4&     value) const { return (this->vector4_     == value); }
    8491        inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); }
    8592        inline bool operator==(const orxonox::Quaternion&  value) const { return (this->quaternion_  == value); }
     
    8794        inline bool operator==(const orxonox::Degree&      value) const { return (this->degree_      == value); }
    8895        bool operator==(const MultiTypeMath& mtm) const;
     96        bool operator==(const MultiTypeString& mts) const;
     97        bool operator==(const MultiTypePrimitive& mtp) const;
    8998
    9099        using MultiTypeString::operator!=;
    91100        inline bool operator!=(const orxonox::Vector2&     value) const { return (this->vector2_     != value); }
    92101        inline bool operator!=(const orxonox::Vector3&     value) const { return (this->vector3_     != value); }
     102        inline bool operator!=(const orxonox::Vector4&     value) const { return (this->vector4_     != value); }
    93103        inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); }
    94104        inline bool operator!=(const orxonox::Quaternion&  value) const { return (this->quaternion_  != value); }
     
    96106        inline bool operator!=(const orxonox::Degree&      value) const { return (this->degree_      != value); }
    97107        bool operator!=(const MultiTypeMath& mtm) const;
     108        bool operator!=(const MultiTypeString& mts) const;
     109        bool operator!=(const MultiTypePrimitive& mtp) const;
    98110
    99111        virtual operator void*()                const;
     
    114126        virtual operator orxonox::Vector2()     const;
    115127        virtual operator orxonox::Vector3()     const;
     128        virtual operator orxonox::Vector4()     const;
    116129        virtual operator orxonox::ColourValue() const;
    117130        virtual operator orxonox::Quaternion()  const;
     
    122135        inline void setValue(const orxonox::Vector2&     value) { this->type_ = MT_vector2;     this->vector2_     = value; }
    123136        inline void setValue(const orxonox::Vector3&     value) { this->type_ = MT_vector3;     this->vector3_     = value; }
     137        inline void setValue(const orxonox::Vector4&     value) { this->type_ = MT_vector4;     this->vector4_     = value; }
    124138        inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; }
    125139        inline void setValue(const orxonox::Quaternion&  value) { this->type_ = MT_quaternion;  this->quaternion_  = value; }
     
    127141        inline void setValue(const orxonox::Degree&      value) { this->type_ = MT_degree;      this->degree_      = value; }
    128142        void setValue(const MultiTypeMath& mtm);
     143        void setValue(const MultiTypeString& mts);
     144        void setValue(const MultiTypePrimitive& mtp);
    129145
    130146        inline orxonox::Vector2     getVector2()     const { return this->vector2_;     }
    131147        inline orxonox::Vector3     getVector3()     const { return this->vector3_;     }
     148        inline orxonox::Vector4     getVector4()     const { return this->vector4_;     }
    132149        inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; }
    133150        inline orxonox::Quaternion  getQuaternion()  const { return this->quaternion_;  }
     
    137154        inline orxonox::Vector2&     getVector2()     { return this->vector2_;     }
    138155        inline orxonox::Vector3&     getVector3()     { return this->vector3_;     }
     156        inline orxonox::Vector4&     getVector4()     { return this->vector4_;     }
    139157        inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; }
    140158        inline orxonox::Quaternion&  getQuaternion()  { return this->quaternion_;  }
     
    145163        inline void getValue(orxonox::Vector2*     variable) const { (*variable) = orxonox::Vector2     (this->vector2_);     }
    146164        inline void getValue(orxonox::Vector3*     variable) const { (*variable) = orxonox::Vector3     (this->vector3_);     }
     165        inline void getValue(orxonox::Vector4*     variable) const { (*variable) = orxonox::Vector4     (this->vector4_);     }
    147166        inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); }
    148167        inline void getValue(orxonox::Quaternion*  variable) const { (*variable) = orxonox::Quaternion  (this->quaternion_);  }
     
    155174        virtual bool fromString(const std::string value);
    156175
     176        virtual bool assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue = MultiTypeMath());
     177
    157178    protected:
    158179        orxonox::Vector2      vector2_;
    159180        orxonox::Vector3      vector3_;
     181        orxonox::Vector4      vector4_;
    160182        orxonox::ColourValue  colourvalue_;
    161183        orxonox::Quaternion   quaternion_;
  • code/trunk/src/util/MultiTypePrimitive.cc

    r1056 r1502  
    266266}
    267267
     268bool MultiTypePrimitive::assimilate(const MultiTypePrimitive& mtp, const MultiTypePrimitive& defvalue)
     269{
     270    if (this->type_ == MT_void)
     271        return ConvertValue(&this->value_.void_, mtp, defvalue.value_.void_);
     272    else if (this->type_ == MT_int)
     273        return ConvertValue(&this->value_.int_, mtp, defvalue.value_.int_);
     274    else if (this->type_ == MT_uint)
     275        return ConvertValue(&this->value_.uint_, mtp, defvalue.value_.uint_);
     276    else if (this->type_ == MT_char)
     277        return ConvertValue(&this->value_.char_, mtp, defvalue.value_.char_);
     278    else if (this->type_ == MT_uchar)
     279        return ConvertValue(&this->value_.uchar_, mtp, defvalue.value_.uchar_);
     280    else if (this->type_ == MT_short)
     281        return ConvertValue(&this->value_.short_, mtp, defvalue.value_.short_);
     282    else if (this->type_ == MT_ushort)
     283        return ConvertValue(&this->value_.ushort_, mtp, defvalue.value_.ushort_);
     284    else if (this->type_ == MT_long)
     285        return ConvertValue(&this->value_.long_, mtp, defvalue.value_.long_);
     286    else if (this->type_ == MT_ulong)
     287        return ConvertValue(&this->value_.ulong_, mtp, defvalue.value_.ulong_);
     288    else if (this->type_ == MT_float)
     289        return ConvertValue(&this->value_.float_, mtp, defvalue.value_.float_);
     290    else if (this->type_ == MT_double)
     291        return ConvertValue(&this->value_.double_, mtp, defvalue.value_.double_);
     292    else if (this->type_ == MT_longdouble)
     293        return ConvertValue(&this->value_.longdouble_, mtp, defvalue.value_.longdouble_);
     294    else if (this->type_ == MT_bool)
     295        return ConvertValue(&this->value_.bool_, mtp, defvalue.value_.bool_);
     296    else
     297        return false;
     298
     299}
     300
    268301std::ostream& operator<<(std::ostream& out, const MultiTypePrimitive& mtp)
    269302{
  • code/trunk/src/util/MultiTypePrimitive.h

    r1062 r1502  
    138138        void setValue(const MultiTypePrimitive& mtp);
    139139
    140         inline void*          getVoid()          const { return this->value_.void_;        }
     140        inline void*          getVoid()          const { return this->value_.void_;       }
    141141        inline int            getInt()           const { return this->value_.int_;        }
    142142        inline unsigned int   getUnsignedInt()   const { return this->value_.uint_;       }
     
    187187        virtual bool fromString(const std::string value);
    188188
     189        virtual bool assimilate(const MultiTypePrimitive& mtp, const MultiTypePrimitive& defvalue = MultiTypePrimitive());
     190
    189191    protected:
    190192        MultiTypeValue  value_;
  • code/trunk/src/util/MultiTypeString.cc

    r1064 r1502  
    3333MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type)
    3434{
    35     // Nothing to do for string and xml-element
     35    // Nothing to do for string
    3636}
    3737
     
    4949}
    5050
     51bool MultiTypeString::operator==(const MultiTypePrimitive& mtp) const
     52{
     53    return MultiTypePrimitive::operator==(mtp);
     54}
     55
    5156bool MultiTypeString::operator!=(const MultiTypeString& mts) const
    5257{
     
    6065
    6166    return true;
     67}
     68
     69bool MultiTypeString::operator!=(const MultiTypePrimitive& mtp) const
     70{
     71    return MultiTypePrimitive::operator!=(mtp);
    6272}
    6373
     
    99109}
    100110
     111void MultiTypeString::setValue(const MultiTypePrimitive& mtp)
     112{
     113    MultiTypePrimitive::setValue(mtp);
     114}
     115
    101116std::string MultiTypeString::getTypename() const
    102117{
     
    136151}
    137152
     153bool MultiTypeString::assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue)
     154{
     155    if (this->type_ == MT_void)
     156        return ConvertValue(&this->value_.void_, mts, defvalue.value_.void_);
     157    else if (this->type_ == MT_int)
     158        return ConvertValue(&this->value_.int_, mts, defvalue.value_.int_);
     159    else if (this->type_ == MT_uint)
     160        return ConvertValue(&this->value_.uint_, mts, defvalue.value_.uint_);
     161    else if (this->type_ == MT_char)
     162        return ConvertValue(&this->value_.char_, mts, defvalue.value_.char_);
     163    else if (this->type_ == MT_uchar)
     164        return ConvertValue(&this->value_.uchar_, mts, defvalue.value_.uchar_);
     165    else if (this->type_ == MT_short)
     166        return ConvertValue(&this->value_.short_, mts, defvalue.value_.short_);
     167    else if (this->type_ == MT_ushort)
     168        return ConvertValue(&this->value_.ushort_, mts, defvalue.value_.ushort_);
     169    else if (this->type_ == MT_long)
     170        return ConvertValue(&this->value_.long_, mts, defvalue.value_.long_);
     171    else if (this->type_ == MT_ulong)
     172        return ConvertValue(&this->value_.ulong_, mts, defvalue.value_.ulong_);
     173    else if (this->type_ == MT_float)
     174        return ConvertValue(&this->value_.float_, mts, defvalue.value_.float_);
     175    else if (this->type_ == MT_double)
     176        return ConvertValue(&this->value_.double_, mts, defvalue.value_.double_);
     177    else if (this->type_ == MT_longdouble)
     178        return ConvertValue(&this->value_.longdouble_, mts, defvalue.value_.longdouble_);
     179    else if (this->type_ == MT_bool)
     180        return ConvertValue(&this->value_.bool_, mts, defvalue.value_.bool_);
     181    else if (this->type_ == MT_constchar)
     182        return ConvertValue(&this->string_, mts, defvalue.string_);
     183    else if (this->type_ == MT_string)
     184        return ConvertValue(&this->string_, mts, defvalue.string_);
     185    else
     186        return false;
     187}
     188
    138189std::ostream& operator<<(std::ostream& out, MultiTypeString& mts)
    139190{
  • code/trunk/src/util/MultiTypeString.h

    r1064 r1502  
    6161        inline MultiTypeString(long double    value) : MultiTypePrimitive(value) {}
    6262        inline MultiTypeString(bool           value) : MultiTypePrimitive(value) {}
    63         inline MultiTypeString(const char*           value)   { this->setValue(value); }
    64         inline MultiTypeString(const std::string&    value)   { this->setValue(value); }
    65         inline MultiTypeString(const MultiTypeString& mts)    { this->setValue(mts);   }
     63        inline MultiTypeString(const char*             value) { this->setValue(value); }
     64        inline MultiTypeString(const std::string&      value) { this->setValue(value); }
     65        inline MultiTypeString(const MultiTypeString&    mts)  { this->setValue(mts);   }
     66        inline MultiTypeString(const MultiTypePrimitive& mtp)  { this->setValue(mtp);   }
    6667        virtual inline ~MultiTypeString() {}
    6768
    6869        using MultiTypePrimitive::operator=;
    69         inline MultiTypeString& operator=(const char*             value)   { this->setValue(value); return *this; }
    70         inline MultiTypeString& operator=(const std::string&      value)   { this->setValue(value); return *this; }
    71         inline MultiTypeString& operator=(const MultiTypeString& mts)      { this->setValue(mts);   return *this; }
     70        inline MultiTypeString& operator=(const char*             value) { this->setValue(value); return *this; }
     71        inline MultiTypeString& operator=(const std::string&      value) { this->setValue(value); return *this; }
     72        inline MultiTypeString& operator=(const MultiTypeString&    mts) { this->setValue(mts);   return *this; }
     73        inline MultiTypeString& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp);   return *this; }
    7274
    7375        using MultiTypePrimitive::operator==;
    74         inline bool operator==(const char*             value) const { return (this->string_      == std::string(value)); }
    75         inline bool operator==(const std::string&      value) const { return (this->string_      == value);              }
    76         bool operator==(const MultiTypeString& mts) const;
     76        inline bool operator==(const char*        value) const { return (this->string_ == std::string(value)); }
     77        inline bool operator==(const std::string& value) const { return (this->string_ == value);              }
     78        bool operator==(const MultiTypeString&    mts) const;
     79        bool operator==(const MultiTypePrimitive& mtp) const;
    7780
    7881        using MultiTypePrimitive::operator!=;
    79         inline bool operator!=(const char*             value) const { return (this->string_      != std::string(value)); }
    80         inline bool operator!=(const std::string&      value) const { return (this->string_      != value);              }
    81         bool operator!=(const MultiTypeString& mts) const;
     82        inline bool operator!=(const char*        value) const { return (this->string_ != std::string(value)); }
     83        inline bool operator!=(const std::string& value) const { return (this->string_ != value);              }
     84        bool operator!=(const MultiTypeString&    mts) const;
     85        bool operator!=(const MultiTypePrimitive& mtp) const;
    8286
    83         virtual operator void*()                const;
    84         virtual operator int()                  const;
    85         virtual operator unsigned int()         const;
    86         virtual operator char()                 const;
    87         virtual operator unsigned char()        const;
    88         virtual operator short()                const;
    89         virtual operator unsigned short()       const;
    90         virtual operator long()                 const;
    91         virtual operator unsigned long()        const;
    92         virtual operator float ()               const;
    93         virtual operator double ()              const;
    94         virtual operator long double()          const;
    95         virtual operator bool()                 const;
    96         virtual operator std::string()          const;
    97         virtual operator const char*()          const;
     87        virtual operator void*()          const;
     88        virtual operator int()            const;
     89        virtual operator unsigned int()   const;
     90        virtual operator char()           const;
     91        virtual operator unsigned char()  const;
     92        virtual operator short()          const;
     93        virtual operator unsigned short() const;
     94        virtual operator long()           const;
     95        virtual operator unsigned long()  const;
     96        virtual operator float ()         const;
     97        virtual operator double ()        const;
     98        virtual operator long double()    const;
     99        virtual operator bool()           const;
     100        virtual operator std::string()    const;
     101        virtual operator const char*()    const;
    98102
    99103        using MultiTypePrimitive::setValue;
    100         inline void setValue(const char*             value) { this->type_ = MT_string;     this->string_     = std::string(value); }
    101         inline void setValue(const std::string&      value) { this->type_ = MT_string;     this->string_     = value;              }
    102         void setValue(const MultiTypeString& mts);
     104        inline void setValue(const char*        value) { this->type_ = MT_string; this->string_ = std::string(value); }
     105        inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value;              }
     106        void setValue(const MultiTypeString&    mts);
     107        void setValue(const MultiTypePrimitive& mtp);
    103108
    104         inline std::string getString()          const { return this->string_;         }
    105         inline const char*  getConstChar()      const { return this->string_.c_str(); }
     109        inline std::string getString()     const { return this->string_;         }
     110        inline const char*  getConstChar() const { return this->string_.c_str(); }
    106111
    107         inline std::string& getString()          { return this->string_;         }
    108         inline const char*  getConstChar()       { return this->string_.c_str(); }
     112        inline std::string& getString()    { return this->string_;         }
     113        inline const char*  getConstChar() { return this->string_.c_str(); }
    109114
    110115        using MultiTypePrimitive::getValue;
    111         inline void getValue(std::string*      variable) const { (*variable) = this->string_;         }
    112         inline void getValue(const char**      variable) const { (*variable) = this->string_.c_str(); }
     116        inline void getValue(std::string* variable) const { (*variable) = this->string_;         }
     117        inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); }
    113118
    114119        virtual std::string getTypename() const;
     
    116121        virtual std::string toString() const;
    117122        virtual bool fromString(const std::string value);
     123
     124        virtual bool assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue = MultiTypeString());
    118125
    119126    protected:
  • code/trunk/src/util/String.cc

    r1219 r1502  
    108108
    109109    unsigned int quotecount = 0;
    110     unsigned int quote = 0;
    111     while ((quote = getNextQuote(str, quote)) < pos)
     110    unsigned int quote = (unsigned int)-1;
     111    while ((quote = getNextQuote(str, quote + 1)) < pos)
    112112    {
    113113        quotecount++;
     
    185185    else
    186186        return str;
     187}
     188
     189/**
     190    @brief Removes enclosing {braces}.
     191    @param str The string to strip
     192    @return The striped string
     193*/
     194std::string stripEnclosingBraces(const std::string& str)
     195{
     196    std::string output = str;
     197
     198    while (output.size() >= 2 && output[0] == '{' && output[output.size() - 1] == '}')
     199        output = output.substr(1, output.size() - 2);
     200
     201    return output;
    187202}
    188203
  • code/trunk/src/util/String.h

    r1062 r1502  
    4747
    4848_UtilExport std::string  stripEnclosingQuotes(const std::string& str);
     49_UtilExport std::string  stripEnclosingBraces(const std::string& str);
    4950
    5051_UtilExport bool         isEmpty(const std::string& str);
  • code/trunk/src/util/UtilPrereqs.h

    r1062 r1502  
    3535#define _UtilPrereqs_H__
    3636
    37 #include "OrxonoxPlatform.h"
     37#include "util/OrxonoxPlatform.h"
    3838
    3939//-----------------------------------------------------------------------
  • code/trunk/visual_studio/base_properties_release.vsprops

    r1024 r1502  
    99                Name="VCCLCompilerTool"
    1010                Optimization="2"
    11                 WholeProgramOptimization="true"
     11                WholeProgramOptimization="false"
    1212                PreprocessorDefinitions="NDEBUG"
    1313                RuntimeLibrary="2"
  • code/trunk/visual_studio/vc8/core.vcproj

    r1293 r1502  
    149149                        >
    150150                        <File
    151                                 RelativePath="..\..\src\core\BaseObject.cc"
    152                                 >
    153                         </File>
    154                         <File
    155                                 RelativePath="..\..\src\core\ClassTreeMask.cc"
    156                                 >
    157                         </File>
    158                         <File
    159                                 RelativePath="..\..\src\core\CommandExecutor.cc"
    160                                 >
    161                         </File>
    162                         <File
    163151                                RelativePath="..\..\src\core\ConfigFileManager.cc"
    164152                                >
     
    177165                        </File>
    178166                        <File
    179                                 RelativePath="..\..\src\core\Executor.cc"
    180                                 >
    181                         </File>
    182                         <File
    183                                 RelativePath="..\..\src\core\Factory.cc"
    184                                 >
    185                         </File>
    186                         <File
    187                                 RelativePath="..\..\src\core\Identifier.cc"
    188                                 >
    189                         </File>
    190                         <File
    191                                 RelativePath="..\..\src\core\IdentifierDistributor.cc"
    192                                 >
    193                         </File>
    194                         <File
    195                                 RelativePath="..\..\src\core\InputBuffer.cc"
    196                                 >
    197                         </File>
    198                         <File
    199                                 RelativePath="..\..\src\core\InputHandler.cc"
    200                                 >
    201                         </File>
    202                         <File
    203                                 RelativePath="..\..\src\core\InputManager.cc"
    204                                 >
    205                         </File>
    206                         <File
    207167                                RelativePath="..\..\src\core\Language.cc"
    208168                                >
    209169                        </File>
    210170                        <File
    211                                 RelativePath="..\..\src\core\Loader.cc"
    212                                 >
    213                         </File>
    214                         <File
    215                                 RelativePath="..\..\src\core\MetaObjectList.cc"
    216                                 >
    217                         </File>
    218                         <File
    219                                 RelativePath="..\..\src\core\Namespace.cc"
    220                                 >
    221                         </File>
    222                         <File
    223                                 RelativePath="..\..\src\core\NamespaceNode.cc"
    224                                 >
    225                         </File>
    226                         <File
    227171                                RelativePath="..\..\src\core\OrxonoxClass.cc"
    228172                                >
    229173                        </File>
    230174                        <File
     175                                RelativePath="..\..\src\core\OutputBuffer.cc"
     176                                >
     177                        </File>
     178                        <File
    231179                                RelativePath="..\..\src\core\OutputHandler.cc"
    232180                                >
     
    241189                        </File>
    242190                        <File
    243                                 RelativePath="..\..\src\core\TclBind.cc"
    244                                 >
    245                         </File>
    246                         <File
    247191                                RelativePath="..\..\src\core\Tickable.cc"
    248192                                >
    249193                        </File>
    250                         <File
    251                                 RelativePath="..\..\src\core\XMLPort.cc"
    252                                 >
    253                         </File>
    254194                        <Filter
    255195                                Name="tolua"
     
    257197                                <File
    258198                                        RelativePath="..\..\src\core\tolua\tolua_bind.cc"
     199                                        >
     200                                </File>
     201                        </Filter>
     202                        <Filter
     203                                Name="command"
     204                                >
     205                                <File
     206                                        RelativePath="..\..\src\core\ArgumentCompletionFunctions.cc"
     207                                        >
     208                                </File>
     209                                <File
     210                                        RelativePath="..\..\src\core\CommandEvaluation.cc"
     211                                        >
     212                                </File>
     213                                <File
     214                                        RelativePath="..\..\src\core\CommandExecutor.cc"
     215                                        >
     216                                </File>
     217                                <File
     218                                        RelativePath="..\..\src\core\ConsoleCommand.cc"
     219                                        >
     220                                </File>
     221                                <File
     222                                        RelativePath="..\..\src\core\ConsoleCommandCompilation.cc"
     223                                        >
     224                                </File>
     225                                <File
     226                                        RelativePath="..\..\src\core\Executor.cc"
     227                                        >
     228                                </File>
     229                        </Filter>
     230                        <Filter
     231                                Name="hierarchy"
     232                                >
     233                                <File
     234                                        RelativePath="..\..\src\core\Factory.cc"
     235                                        >
     236                                </File>
     237                                <File
     238                                        RelativePath="..\..\src\core\Identifier.cc"
     239                                        >
     240                                </File>
     241                                <File
     242                                        RelativePath="..\..\src\core\IdentifierDistributor.cc"
     243                                        >
     244                                </File>
     245                                <File
     246                                        RelativePath="..\..\src\core\MetaObjectList.cc"
     247                                        >
     248                                </File>
     249                        </Filter>
     250                        <Filter
     251                                Name="level"
     252                                >
     253                                <File
     254                                        RelativePath="..\..\src\core\BaseObject.cc"
     255                                        >
     256                                </File>
     257                                <File
     258                                        RelativePath="..\..\src\core\ClassTreeMask.cc"
     259                                        >
     260                                </File>
     261                                <File
     262                                        RelativePath="..\..\src\core\Loader.cc"
     263                                        >
     264                                </File>
     265                                <File
     266                                        RelativePath="..\..\src\core\Namespace.cc"
     267                                        >
     268                                </File>
     269                                <File
     270                                        RelativePath="..\..\src\core\NamespaceNode.cc"
     271                                        >
     272                                </File>
     273                                <File
     274                                        RelativePath="..\..\src\core\XMLPort.cc"
     275                                        >
     276                                </File>
     277                        </Filter>
     278                        <Filter
     279                                Name="input"
     280                                >
     281                                <File
     282                                        RelativePath="..\..\src\core\InputBuffer.cc"
     283                                        >
     284                                </File>
     285                                <File
     286                                        RelativePath="..\..\src\core\InputManager.cc"
     287                                        >
     288                                </File>
     289                                <File
     290                                        RelativePath="..\..\src\core\KeyBinder.cc"
     291                                        >
     292                                </File>
     293                        </Filter>
     294                        <Filter
     295                                Name="shell"
     296                                >
     297                                <File
     298                                        RelativePath="..\..\src\core\IRC.cc"
     299                                        >
     300                                </File>
     301                                <File
     302                                        RelativePath="..\..\src\core\Shell.cc"
     303                                        >
     304                                </File>
     305                                <File
     306                                        RelativePath="..\..\src\core\TclBind.cc"
     307                                        >
     308                                </File>
     309                                <File
     310                                        RelativePath="..\..\src\core\TclThreadManager.cc"
    259311                                        >
    260312                                </File>
     
    267319                        >
    268320                        <File
    269                                 RelativePath="..\..\src\core\BaseObject.h"
    270                                 >
    271                         </File>
    272                         <File
    273                                 RelativePath="..\..\src\core\ClassFactory.h"
    274                                 >
    275                         </File>
    276                         <File
    277                                 RelativePath="..\..\src\core\ClassManager.h"
    278                                 >
    279                         </File>
    280                         <File
    281                                 RelativePath="..\..\src\core\ClassTreeMask.h"
    282                                 >
    283                         </File>
    284                         <File
    285                                 RelativePath="..\..\src\core\CommandExecutor.h"
    286                                 >
    287                         </File>
    288                         <File
    289321                                RelativePath="..\..\src\core\ConfigFileManager.h"
    290322                                >
     
    299331                        </File>
    300332                        <File
    301                                 RelativePath="..\..\src\core\ConsoleCommand.h"
    302                                 >
    303                         </File>
    304                         <File
    305                                 RelativePath="..\..\src\core\CoreIncludes.h"
    306                                 >
    307                         </File>
    308                         <File
    309333                                RelativePath="..\..\src\core\CorePrereqs.h"
    310334                                >
     
    323347                        </File>
    324348                        <File
    325                                 RelativePath="..\..\src\core\Executor.h"
    326                                 >
    327                         </File>
    328                         <File
    329                                 RelativePath="..\..\src\core\Factory.h"
    330                                 >
    331                         </File>
    332                         <File
    333                                 RelativePath="..\..\src\core\Functor.h"
    334                                 >
    335                         </File>
    336                         <File
    337                                 RelativePath="..\..\src\core\Identifier.h"
    338                                 >
    339                         </File>
    340                         <File
    341                                 RelativePath="..\..\src\core\IdentifierDistributor.h"
    342                                 >
    343                         </File>
    344                         <File
    345                                 RelativePath="..\..\src\core\InputBuffer.h"
    346                                 >
    347                         </File>
    348                         <File
    349                                 RelativePath="..\..\src\core\InputHandler.h"
    350                                 >
    351                         </File>
    352                         <File
    353                                 RelativePath="..\..\src\core\InputInterfaces.h"
    354                                 >
    355                         </File>
    356                         <File
    357                                 RelativePath="..\..\src\core\InputManager.h"
    358                                 >
    359                         </File>
    360                         <File
    361                                 RelativePath="..\..\src\core\Iterator.h"
    362                                 >
    363                         </File>
    364                         <File
    365349                                RelativePath="..\..\src\core\Language.h"
    366350                                >
    367351                        </File>
    368352                        <File
    369                                 RelativePath="..\..\src\core\Level.h"
    370                                 >
    371                         </File>
    372                         <File
    373                                 RelativePath="..\..\src\core\Loader.h"
    374                                 >
    375                         </File>
    376                         <File
    377                                 RelativePath="..\..\src\core\MetaObjectList.h"
    378                                 >
    379                         </File>
    380                         <File
    381                                 RelativePath="..\..\src\core\Namespace.h"
    382                                 >
    383                         </File>
    384                         <File
    385                                 RelativePath="..\..\src\core\NamespaceNode.h"
    386                                 >
    387                         </File>
    388                         <File
    389                                 RelativePath="..\..\src\core\ObjectList.h"
    390                                 >
    391                         </File>
    392                         <File
    393353                                RelativePath="..\..\src\core\OrxonoxClass.h"
    394354                                >
    395355                        </File>
    396356                        <File
     357                                RelativePath="..\..\src\core\OutputBuffer.h"
     358                                >
     359                        </File>
     360                        <File
    397361                                RelativePath="..\..\src\core\OutputHandler.h"
    398362                                >
     
    403367                        </File>
    404368                        <File
     369                                RelativePath="..\..\src\core\Script_clean.h"
     370                                >
     371                        </File>
     372                        <File
    405373                                RelativePath="..\..\src\core\SignalHandler.h"
    406374                                >
    407375                        </File>
    408376                        <File
    409                                 RelativePath="..\..\src\core\TclBind.h"
    410                                 >
    411                         </File>
    412                         <File
    413377                                RelativePath="..\..\src\core\Tickable.h"
    414378                                >
    415379                        </File>
    416                         <File
    417                                 RelativePath="..\..\src\core\XMLPort.h"
    418                                 >
    419                         </File>
     380                        <Filter
     381                                Name="input"
     382                                >
     383                                <File
     384                                        RelativePath="..\..\src\core\InputBuffer.h"
     385                                        >
     386                                </File>
     387                                <File
     388                                        RelativePath="..\..\src\core\InputInterfaces.h"
     389                                        >
     390                                </File>
     391                                <File
     392                                        RelativePath="..\..\src\core\InputManager.h"
     393                                        >
     394                                </File>
     395                                <File
     396                                        RelativePath="..\..\src\core\KeyBinder.h"
     397                                        >
     398                                </File>
     399                        </Filter>
     400                        <Filter
     401                                Name="command"
     402                                >
     403                                <File
     404                                        RelativePath="..\..\src\core\ArgumentCompleter.h"
     405                                        >
     406                                </File>
     407                                <File
     408                                        RelativePath="..\..\src\core\ArgumentCompletionFunctions.h"
     409                                        >
     410                                </File>
     411                                <File
     412                                        RelativePath="..\..\src\core\ArgumentCompletionListElement.h"
     413                                        >
     414                                </File>
     415                                <File
     416                                        RelativePath="..\..\src\core\CommandEvaluation.h"
     417                                        >
     418                                </File>
     419                                <File
     420                                        RelativePath="..\..\src\core\CommandExecutor.h"
     421                                        >
     422                                </File>
     423                                <File
     424                                        RelativePath="..\..\src\core\ConsoleCommand.h"
     425                                        >
     426                                </File>
     427                                <File
     428                                        RelativePath="..\..\src\core\ConsoleCommandCompilation.h"
     429                                        >
     430                                </File>
     431                                <File
     432                                        RelativePath="..\..\src\core\Executor.h"
     433                                        >
     434                                </File>
     435                                <File
     436                                        RelativePath="..\..\src\core\Functor.h"
     437                                        >
     438                                </File>
     439                        </Filter>
     440                        <Filter
     441                                Name="shell"
     442                                >
     443                                <File
     444                                        RelativePath="..\..\src\core\IRC.h"
     445                                        >
     446                                </File>
     447                                <File
     448                                        RelativePath="..\..\src\core\Shell.h"
     449                                        >
     450                                </File>
     451                                <File
     452                                        RelativePath="..\..\src\core\TclBind.h"
     453                                        >
     454                                </File>
     455                                <File
     456                                        RelativePath="..\..\src\core\TclThreadManager.h"
     457                                        >
     458                                </File>
     459                        </Filter>
     460                        <Filter
     461                                Name="hierarchy"
     462                                >
     463                                <File
     464                                        RelativePath="..\..\src\core\ClassFactory.h"
     465                                        >
     466                                </File>
     467                                <File
     468                                        RelativePath="..\..\src\core\ClassManager.h"
     469                                        >
     470                                </File>
     471                                <File
     472                                        RelativePath="..\..\src\core\CoreIncludes.h"
     473                                        >
     474                                </File>
     475                                <File
     476                                        RelativePath="..\..\src\core\Factory.h"
     477                                        >
     478                                </File>
     479                                <File
     480                                        RelativePath="..\..\src\core\Identifier.h"
     481                                        >
     482                                </File>
     483                                <File
     484                                        RelativePath="..\..\src\core\IdentifierDistributor.h"
     485                                        >
     486                                </File>
     487                                <File
     488                                        RelativePath="..\..\src\core\Iterator.h"
     489                                        >
     490                                </File>
     491                                <File
     492                                        RelativePath="..\..\src\core\MetaObjectList.h"
     493                                        >
     494                                </File>
     495                                <File
     496                                        RelativePath="..\..\src\core\ObjectList.h"
     497                                        >
     498                                </File>
     499                        </Filter>
     500                        <Filter
     501                                Name="level"
     502                                >
     503                                <File
     504                                        RelativePath="..\..\src\core\BaseObject.h"
     505                                        >
     506                                </File>
     507                                <File
     508                                        RelativePath="..\..\src\core\ClassTreeMask.h"
     509                                        >
     510                                </File>
     511                                <File
     512                                        RelativePath="..\..\src\core\Level.h"
     513                                        >
     514                                </File>
     515                                <File
     516                                        RelativePath="..\..\src\core\Loader.h"
     517                                        >
     518                                </File>
     519                                <File
     520                                        RelativePath="..\..\src\core\Namespace.h"
     521                                        >
     522                                </File>
     523                                <File
     524                                        RelativePath="..\..\src\core\NamespaceNode.h"
     525                                        >
     526                                </File>
     527                                <File
     528                                        RelativePath="..\..\src\core\XMLPort.h"
     529                                        >
     530                                </File>
     531                        </Filter>
    420532                        <Filter
    421533                                Name="tolua"
  • code/trunk/visual_studio/vc8/orxonox.vcproj

    r1293 r1502  
    188188                                >
    189189                                <File
     190                                        RelativePath="..\..\src\orxonox\hud\BarOverlayElement.cc"
     191                                        >
     192                                </File>
     193                                <File
    190194                                        RelativePath="..\..\src\orxonox\hud\HUD.cc"
    191195                                        >
    192196                                </File>
     197                                <File
     198                                        RelativePath="..\..\src\orxonox\hud\Navigation.cc"
     199                                        >
     200                                </File>
     201                                <File
     202                                        RelativePath="..\..\src\orxonox\hud\RadarObject.cc"
     203                                        >
     204                                </File>
     205                                <File
     206                                        RelativePath="..\..\src\orxonox\hud\RadarOverlayElement.cc"
     207                                        >
     208                                </File>
    193209                        </Filter>
    194210                        <Filter
     
    224240                                </File>
    225241                                <File
     242                                        RelativePath="..\..\src\orxonox\objects\RotatingProjectile.cc"
     243                                        >
     244                                </File>
     245                                <File
    226246                                        RelativePath="..\..\src\orxonox\objects\Skybox.cc"
    227247                                        >
     
    229249                                <File
    230250                                        RelativePath="..\..\src\orxonox\objects\SpaceShip.cc"
     251                                        >
     252                                </File>
     253                                <File
     254                                        RelativePath="..\..\src\orxonox\objects\SpaceShipAI.cc"
    231255                                        >
    232256                                </File>
     
    435459                        </File>
    436460                        <File
    437                                 RelativePath="..\..\src\orxonox\OrxonoxPlatform.h"
    438                                 >
    439                         </File>
    440                         <File
    441461                                RelativePath="..\..\src\orxonox\OrxonoxPrereqs.h"
    442462                                >
     
    450470                                >
    451471                                <File
     472                                        RelativePath="..\..\src\orxonox\hud\BarOverlayElement.h"
     473                                        >
     474                                </File>
     475                                <File
    452476                                        RelativePath="..\..\src\orxonox\hud\HUD.h"
    453477                                        >
    454478                                </File>
     479                                <File
     480                                        RelativePath="..\..\src\orxonox\hud\Navigation.h"
     481                                        >
     482                                </File>
     483                                <File
     484                                        RelativePath="..\..\src\orxonox\hud\OverlayElementFactories.h"
     485                                        >
     486                                </File>
     487                                <File
     488                                        RelativePath="..\..\src\orxonox\hud\RadarObject.h"
     489                                        >
     490                                </File>
     491                                <File
     492                                        RelativePath="..\..\src\orxonox\hud\RadarOverlayElement.h"
     493                                        >
     494                                </File>
    455495                        </Filter>
    456496                        <Filter
     
    486526                                </File>
    487527                                <File
     528                                        RelativePath="..\..\src\orxonox\objects\RotatingProjectile.h"
     529                                        >
     530                                </File>
     531                                <File
    488532                                        RelativePath="..\..\src\orxonox\objects\Skybox.h"
    489533                                        >
     
    491535                                <File
    492536                                        RelativePath="..\..\src\orxonox\objects\SpaceShip.h"
     537                                        >
     538                                </File>
     539                                <File
     540                                        RelativePath="..\..\src\orxonox\objects\SpaceShipAI.h"
    493541                                        >
    494542                                </File>
  • code/trunk/visual_studio/vc8/util.vcproj

    r1126 r1502  
    227227                        </File>
    228228                        <File
     229                                RelativePath="..\..\src\util\OrxonoxPlatform.h"
     230                                >
     231                        </File>
     232                        <File
    229233                                RelativePath="..\..\src\util\Sleep.h"
    230234                                >
Note: See TracChangeset for help on using the changeset viewer.