Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1214


Ignore:
Timestamp:
May 2, 2008, 9:23:30 PM (17 years ago)
Author:
landauf
Message:

merged console-branch back to trunk.
IMPORTANT: update your media directory!

you need TCL to compile. TCL is available here: http://www.tcl.tk/
another option is to check out https://svn.orxonox.net/ogre/tcl8.5.2/ and compile it by yourself. makefiles are in the 'macosx', 'unix' and 'win' subfolders.
FindTCL.cmake searches in the usual locations and in ../libs/tcl8.5.2/

the orxonox console can be activated with numpad-enter. whatever you enter will be parsed by TCL. if TCL doesn't know a command, it gets executed by orxonox.

simple tcl commands are: "puts text" to write "text" into the console, "expr 1+1" to calculate the result of the given expression. just try it by yourself with "puts [expr 1+1]".
[x] means: evaluate x and use the returnvalue as an argument. in this case the returned value is "2" and the resulting command therefore "puts 2".

you can combine orxonox and tcl commands. a simple orxonox command is "log text" that writes text into the console and the logfile. test it with "log [expr 1+1]" to write "2" into all output channels of orxonox. something more advanced: "log [clock seconds]" writes the seconds since 1970 into the logfile. feel free to combine both: "log [clock seconds]: 1+1 is [expr 1+1]"

TCL uses variables. to set a new variable, use "set varname value". you can use the variable wherever you want with $varname. with this we can make the above command a bit more elegant:
set myexpression 1+1
log [clock seconds]: $myexpression is [expr $myexpression]

read more about tcl in the wiki: http://wiki.tcl.tk/

Location:
code/trunk
Files:
20 edited
21 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/CMakeLists.txt

    r1126 r1214  
    11PROJECT(Orxonox)
     2
     3cmake_minimum_required(VERSION 2.4)
     4
     5if(COMMAND cmake_policy)
     6  cmake_policy(SET CMP0003 NEW)
     7endif(COMMAND cmake_policy)
    28
    39#This sets where to look for modules (e.g. "Find*.cmake" files)
     
    6369FIND_PACKAGE(ZLIB)
    6470FIND_PACKAGE(Lua)
     71FIND_PACKAGE(TCL)
    6572
    6673#Set the search paths for the linking
     
    7279  ${Boost_LIBRARY_DIRS}
    7380  ${Zlib_LIBRARY_DIR}
     81  ${TCL_LIBRARY}
    7482)
    7583
     
    8694  ${OGG_INCLUDE_DIR}
    8795  ${Lua_INCLUDE_DIR}
     96  ${TCL_INCLUDE_PATH}
    8897)
    8998
  • code/trunk/cmake/FindTCL.cmake

    r1160 r1214  
    44# the library is. This code sets the following variables:
    55#  TCL_LIBRARY        = path to Tcl library (tcl tcl80)
     6#  TCL_LIBRARY_DEBUG  = path to Tcl library (debug)
     7#  TCL_STUB_LIBRARY   = path to Tcl stub library
     8#  TCL_STUB_LIBRARY_DEBUG = path to debug stub library
    69#  TCL_INCLUDE_PATH   = path to where tcl.h can be found
     10#  TCL_TCLSH          = path to tclsh binary (tcl tcl80)
     11#  TK_LIBRARY         = path to Tk library (tk tk80 etc)
     12#  TK_LIBRARY_DEBUG   = path to Tk library (debug)
     13#  TK_STUB_LIBRARY    = path to Tk stub library
     14#  TK_STUB_LIBRARY_DEBUG = path to debug Tk stub library
     15#  TK_INCLUDE_PATH    = path to where tk.h can be found
     16#  TK_INTERNAL_PATH   = path to where tkWinInt.h is found
     17#  TK_WISH            = full path to the wish executable
     18
     19INCLUDE(CMakeFindFrameworks)
     20INCLUDE(FindTclsh)
     21INCLUDE(FindWish)
    722
    823GET_FILENAME_COMPONENT(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH)
     24GET_FILENAME_COMPONENT(TK_WISH_PATH "${TK_WISH}" PATH)
    925
    1026SET (TCLTK_POSSIBLE_LIB_PATHS
    11   /usr/lib
    12   /usr/local/lib
     27  "${TCL_TCLSH_PATH}/../lib"
     28  "${TK_WISH_PATH}/../lib"
     29  "${TCL_INCLUDE_PATH}/../lib"
     30  "${TK_INCLUDE_PATH}/../lib"
    1331  "$ENV{ProgramFiles}/Tcl/Lib"
    1432  "C:/Program Files/Tcl/lib"
    1533  "C:/Tcl/lib"
     34  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/lib
     35  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/lib
     36  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/lib
     37  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/lib
     38  /usr/lib
     39  /usr/local/lib
     40  /usr/pack/tcltk-8.4.9.linux-mo/lib
     41  ../libs/tcl8.5.2/win
    1642  ../libs/tcl8.5.2/unix
    17   ../libs/tcl8.5.2/win
     43  ../libs/tcl8.5.2/macosx
    1844)
    1945
     
    2349)
    2450
     51FIND_LIBRARY(TCL_LIBRARY_DEBUG
     52  NAMES tcld tcl85d tcl8.5d tcl84d tcl8.4d tcl83d tcl8.3d tcl82d tcl8.2d tcl80d tcl8.0d
     53  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
     54)
     55
     56FIND_LIBRARY(TCL_STUB_LIBRARY
     57  NAMES tclstub tclstub84 tclstub8.4 tclstub83 tclstub8.3 tclstub82 tclstub8.2 tclstub80 tclstub8.0
     58  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
     59)
     60
     61FIND_LIBRARY(TCL_STUB_LIBRARY_DEBUG
     62  NAMES tclstubd tclstub84d tclstub8.4d tclstub83d tclstub8.3d tclstub82d tclstub8.2d tclstub80d tclstub8.0d
     63  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
     64)
     65
     66FIND_LIBRARY(TK_LIBRARY
     67  NAMES tk tk84 tk8.4 tk83 tk8.3 tk82 tk8.2 tk80 tk8.0
     68  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
     69)
     70
     71FIND_LIBRARY(TK_LIBRARY_DEBUG
     72  NAMES tkd tk84d tk8.4d tk83d tk8.3d tk82d tk8.2d tk80d tk8.0d
     73  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
     74)
     75
     76FIND_LIBRARY(TK_STUB_LIBRARY
     77  NAMES tkstub tkstub84 tkstub8.4 tkstub83 tkstub8.3 tkstub82 tkstub8.2 tkstub80 tkstub8.0
     78  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
     79)
     80
     81FIND_LIBRARY(TK_STUB_LIBRARY_DEBUG
     82  NAMES tkstubd tkstub84d tkstub8.4d tkstub83d tkstub8.3d tkstub82d tkstub8.2d tkstub80d tkstub8.0d
     83  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
     84)
     85
     86CMAKE_FIND_FRAMEWORKS(Tcl)
     87CMAKE_FIND_FRAMEWORKS(Tk)
     88
     89SET(TCL_FRAMEWORK_INCLUDES)
     90IF(Tcl_FRAMEWORKS)
     91  IF(NOT TCL_INCLUDE_PATH)
     92    FOREACH(dir ${Tcl_FRAMEWORKS})
     93      SET(TCL_FRAMEWORK_INCLUDES ${TCL_FRAMEWORK_INCLUDES} ${dir}/Headers)
     94    ENDFOREACH(dir)
     95  ENDIF(NOT TCL_INCLUDE_PATH)
     96ENDIF(Tcl_FRAMEWORKS)
     97
     98SET(TK_FRAMEWORK_INCLUDES)
     99IF(Tk_FRAMEWORKS)
     100  IF(NOT TK_INCLUDE_PATH)
     101    FOREACH(dir ${Tk_FRAMEWORKS})
     102      SET(TK_FRAMEWORK_INCLUDES ${TK_FRAMEWORK_INCLUDES}
     103        ${dir}/Headers ${dir}/PrivateHeaders)
     104    ENDFOREACH(dir)
     105  ENDIF(NOT TK_INCLUDE_PATH)
     106ENDIF(Tk_FRAMEWORKS)
     107
    25108GET_FILENAME_COMPONENT(TCL_LIBRARY_PATH "${TCL_LIBRARY}" PATH)
     109GET_FILENAME_COMPONENT(TK_LIBRARY_PATH "${TK_LIBRARY}" PATH)
    26110
    27111SET (TCLTK_POSSIBLE_INCLUDE_PATHS
     112  ${TCL_TCLSH_PATH}/../include
     113  ${TK_WISH_PATH}/../include
     114  "${TCL_LIBRARY_PATH}/../include"
     115  "${TK_LIBRARY_PATH}/../include"
     116  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/include
     117  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/include
     118  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/include
     119  [HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/include
     120  "$ENV{ProgramFiles}/Tcl/include"
     121  "C:/Program Files/Tcl/include"
     122  C:/Tcl/include
    28123  /usr/include
    29124  /usr/local/include
     
    32127  /usr/include/tcl8.2
    33128  /usr/include/tcl8.0
    34   "$ENV{ProgramFiles}/Tcl/include"
    35   "C:/Program Files/Tcl/include"
    36   C:/Tcl/include
    37129  ../libs/tcl8.5.2/generic
    38130)
     
    41133  ${TCL_FRAMEWORK_INCLUDES} ${TCLTK_POSSIBLE_INCLUDE_PATHS}
    42134)
     135
     136FIND_PATH(TK_INCLUDE_PATH tk.h
     137  ${TK_FRAMEWORK_INCLUDES} ${TCLTK_POSSIBLE_INCLUDE_PATHS}
     138)
     139
     140IF (WIN32)
     141  FIND_PATH(TK_INTERNAL_PATH tkWinInt.h
     142    ${TCLTK_POSSIBLE_INCLUDE_PATHS}
     143  )
     144  MARK_AS_ADVANCED(TK_INTERNAL_PATH)
     145ENDIF(WIN32)
     146
     147MARK_AS_ADVANCED(
     148    TCL_TCLSH_PATH
     149    TK_WISH_PATH
     150    TCL_INCLUDE_PATH
     151    TK_INCLUDE_PATH
     152    TCL_LIBRARY
     153    TCL_LIBRARY_DEBUG
     154    TK_LIBRARY 
     155    TK_LIBRARY_DEBUG
     156  TCL_STUB_LIBRARY
     157  TCL_STUB_LIBRARY_DEBUG
     158  TK_STUB_LIBRARY 
     159  TK_STUB_LIBRARY
     160  TK_STUB_LIBRARY_DEBUG
     161  )
    43162
    44163IF(TCL_INCLUDE_PATH)
  • code/trunk/src/CMakeLists.txt

    r1209 r1214  
    55ADD_SUBDIRECTORY(tinyxml)
    66ADD_SUBDIRECTORY(tolua)
     7ADD_SUBDIRECTORY(cpptcl)
    78ADD_SUBDIRECTORY(util)
    89ADD_SUBDIRECTORY(core)
  • code/trunk/src/core/CMakeLists.txt

    r1209 r1214  
    2828  tolua/tolua_bind.cc
    2929#tolua/tolua_bind.h
     30  TclBind.cc
    3031)
    3132
     
    4950
    5051TARGET_LINK_LIBRARIES(core
     52  cpptcl
    5153  ${Lua_LIBRARIES}
    5254  ${OIS_LIBRARIES}
  • code/trunk/src/core/CommandExecutor.cc

    r1059 r1214  
    3636#include "Executor.h"
    3737#include "ConfigValueContainer.h"
     38#include "TclBind.h"
    3839
    3940#define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set"
     
    236237            if (this->shortcut_)
    237238            {
    238                 if (this->shortcut_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
    239                 {
    240                     this->bEvaluatedParams_ = true;
    241                     this->evaluatedExecutor_ = this->shortcut_;
     239                if (this->tokens_.size() <= 1)
     240                {
     241                    if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " "))
     242                    {
     243                        this->bEvaluatedParams_ = true;
     244                        this->evaluatedExecutor_ = this->shortcut_;
     245                    }
     246                }
     247                else if (this->tokens_.size() > 1)
     248                {
     249                    if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " "))
     250                    {
     251                        this->bEvaluatedParams_ = true;
     252                        this->evaluatedExecutor_ = this->shortcut_;
     253                    }
    242254                }
    243255            }
     
    247259            if (this->function_)
    248260            {
    249                 if (this->function_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
    250                 {
    251                     this->bEvaluatedParams_ = true;
    252                     this->evaluatedExecutor_ = this->function_;
     261                if (this->tokens_.size() <= 2)
     262                {
     263                    if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))
     264                    {
     265                        this->bEvaluatedParams_ = true;
     266                        this->evaluatedExecutor_ = this->function_;
     267                    }
     268                }
     269                else if (this->tokens_.size() > 2)
     270                {
     271                    if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " "))
     272                    {
     273                        this->bEvaluatedParams_ = true;
     274                        this->evaluatedExecutor_ = this->function_;
     275                    }
    253276                }
    254277            }
     
    266289        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
    267290            return this->param_[index];
     291
     292        return MT_null;
     293    }
     294
     295    bool CommandEvaluation::hasReturnvalue() const
     296    {
     297        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     298        {
     299            if (this->shortcut_)
     300                return this->shortcut_->hasReturnvalue();
     301        }
     302        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
     303        {
     304            if (this->function_)
     305                return this->function_->hasReturnvalue();
     306        }
    268307
    269308        return MT_null;
     
    297336
    298337    CommandEvaluation& CommandExecutor::getEvaluation()
     338    {
     339        return CommandExecutor::getInstance().evaluation_;
     340    }
     341
     342    const CommandEvaluation& CommandExecutor::getLastEvaluation()
    299343    {
    300344        return CommandExecutor::getInstance().evaluation_;
     
    336380    }
    337381
    338     bool CommandExecutor::execute(const std::string& command)
    339     {
    340         std::string strippedCommand = stripEnclosingQuotes(command);
    341 
    342         SubString tokensIO(strippedCommand, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    343         if (tokensIO.size() >= 2)
    344         {
    345             if (tokensIO[tokensIO.size() - 2] == ">")
    346             {
    347                 bool success = CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join());
    348                 write(tokensIO[tokensIO.size() - 1], CommandExecutor::getEvaluation().getReturnvalue());
    349                 return success;
    350             }
    351             else if (tokensIO[tokensIO.size() - 2] == "<")
    352             {
    353                 std::string input = read(tokensIO[tokensIO.size() - 1]);
    354                 if (input == "" || input.size() == 0)
    355                     return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join());
    356                 else
    357                     return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join() + " " + input);
    358             }
    359         }
    360 
    361 
    362         SubString tokensPipeline(strippedCommand, "|", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    363         if (tokensPipeline.size() > 1)
    364         {
    365             bool success = true;
    366             std::string returnValue = "";
    367             for (int i = tokensPipeline.size() - 1; i >= 0; i--)
    368             {
    369                 if (returnValue == "" || returnValue.size() == 0)
    370                 {
    371                     //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i]);
    372                     if (!CommandExecutor::execute(tokensPipeline[i]))
    373                         success = false;
    374                 }
    375                 else
    376                 {
    377                     //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i] + " " + returnValue);
    378                     if (!CommandExecutor::execute(tokensPipeline[i] + " " + returnValue))
    379                         success = false;
    380                 }
    381 
    382                 //CommandExecutor::execute(evaluation);
    383                 //returnValue = evaluation.getReturnvalue();
    384                 returnValue = CommandExecutor::getEvaluation().getReturnvalue().toString();
    385             }
    386             return success;
    387         }
    388 
    389         if ((CommandExecutor::getEvaluation().processedCommand_ != strippedCommand) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    390             CommandExecutor::parse(strippedCommand);
    391 
    392         return CommandExecutor::execute(CommandExecutor::getEvaluation());
     382    bool CommandExecutor::execute(const std::string& command, bool useTcl)
     383    {
     384        if (useTcl)
     385        {
     386            return TclBind::eval(command);
     387        }
     388        else
     389        {
     390            if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
     391                CommandExecutor::parse(command);
     392
     393            return CommandExecutor::execute(CommandExecutor::getEvaluation());
     394        }
    393395    }
    394396
     
    400402        if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_)
    401403        {
     404std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl;
    402405            (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]);
    403         }
    404 
     406            return true;
     407        }
     408
     409std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n";
    405410        switch (evaluation.state_)
    406411        {
     
    645650    {
    646651        CommandExecutor::parse(command, true);
     652
     653        if (CommandExecutor::getEvaluation().tokens_.size() > 0)
     654        {
     655            std::string lastToken;
     656            lastToken = CommandExecutor::getEvaluation().tokens_[CommandExecutor::getEvaluation().tokens_.size() - 1];
     657            lastToken = lastToken.substr(0, lastToken.size() - 1);
     658            CommandExecutor::getEvaluation().tokens_.pop_back();
     659            CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0'));
     660        }
     661
    647662        CommandExecutor::getEvaluation().evaluateParams();
    648663        return CommandExecutor::getEvaluation();
     
    10821097        CommandExecutor::getEvaluation().additionalParameter_ = "";
    10831098
     1099        CommandExecutor::getEvaluation().bEvaluatedParams_ = false;
     1100        CommandExecutor::getEvaluation().evaluatedExecutor_ = 0;
     1101
    10841102        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear();
    10851103        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
  • code/trunk/src/core/CommandExecutor.h

    r1064 r1214  
    9595            void evaluateParams();
    9696
     97            bool hasReturnvalue() const;
    9798            MultiTypeMath getReturnvalue() const;
    9899
     
    130131    {
    131132        public:
    132             static bool execute(const std::string& command);
     133            static bool execute(const std::string& command, bool useTcl = true);
    133134            static bool execute(const CommandEvaluation& evaluation);
    134135
     
    140141
    141142            static CommandEvaluation evaluate(const std::string& command);
     143
     144            static const CommandEvaluation& getLastEvaluation();
    142145
    143146            static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
  • code/trunk/src/core/CorePrereqs.h

    r1062 r1214  
    139139  template <class T>
    140140  class SubclassIdentifier;
     141  class TclBind;
    141142  class Tickable;
    142143  template <class T, class O>
  • code/trunk/src/core/Functor.h

    r1064 r1214  
    284284#define FUNCTOR_EVALUATE_PARAM0
    285285#define FUNCTOR_EVALUATE_PARAM1 \
    286     if (index == 0) param = (P1)param
     286    if (index == 0) { P1 temp = param; param = temp; }
    287287#define FUNCTOR_EVALUATE_PARAM2 \
    288     if (index == 0) param = (P1)param; \
    289     else if (index == 1) param = (P2)param
     288    if (index == 0) { P1 temp = param; param = temp; } \
     289    else if (index == 1) { P2 temp = param; param = temp; }
    290290#define FUNCTOR_EVALUATE_PARAM3 \
    291     if (index == 0) param = (P1)param; \
    292     else if (index == 1) param = (P2)param; \
    293     else if (index == 2) param = (P3)param
     291    if (index == 0) { P1 temp = param; param = temp; } \
     292    else if (index == 1) { P2 temp = param; param = temp; } \
     293    else if (index == 2) { P3 temp = param; param = temp; }
    294294#define FUNCTOR_EVALUATE_PARAM4 \
    295     if (index == 0) param = (P1)param; \
    296     else if (index == 1) param = (P2)param; \
    297     else if (index == 2) param = (P3)param; \
    298     else if (index == 3) param = (P4)param
     295    if (index == 0) { P1 temp = param; param = temp; } \
     296    else if (index == 1) { P2 temp = param; param = temp; } \
     297    else if (index == 2) { P3 temp = param; param = temp; } \
     298    else if (index == 3) { P4 temp = param; param = temp; }
    299299#define FUNCTOR_EVALUATE_PARAM5 \
    300     if (index == 0) param = (P1)param; \
    301     else if (index == 1) param = (P2)param; \
    302     else if (index == 2) param = (P3)param; \
    303     else if (index == 3) param = (P4)param; \
    304     else if (index == 4) param = (P5)param
     300    if (index == 0) { P1 temp = param; param = temp; } \
     301    else if (index == 1) { P2 temp = param; param = temp; } \
     302    else if (index == 2) { P3 temp = param; param = temp; } \
     303    else if (index == 3) { P4 temp = param; param = temp; } \
     304    else if (index == 4) { P5 temp = param; param = temp; }
    305305
    306306
  • code/trunk/src/core/InputBuffer.cc

    r1066 r1214  
    3939    {
    4040        //this->bActivated_ = false;
    41         this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"().:,;_-+*/=!?<>[|]";
     41        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^";
    4242        this->keyboard_ = InputManager::getSingleton().getKeyboard();
    4343        this->buffer_ = "";
    4444
    4545        //this->keyboard_->setEventCallback(this);
     46    }
     47
     48    InputBuffer::InputBuffer(const std::string allowedChars)
     49    {
     50        //this->bActivated_ = false;
     51        this->allowedChars_ = allowedChars;
     52        this->keyboard_ = InputManager::getSingleton().getKeyboard();
     53        this->buffer_ = "";
    4654    }
    4755/*
  • code/trunk/src/core/InputBuffer.h

    r1066 r1214  
    5959        public:
    6060            InputBuffer();
     61            InputBuffer(const std::string allowedChars);
    6162
    6263            template <class T>
  • code/trunk/src/core/InputHandler.cc

    r1066 r1214  
    8585      InputHandlerGame::callListeners(e);
    8686    }
    87     else if (e.key == OIS::KC_NUMPADENTER)
     87    else if (e.key == OIS::KC_UNASSIGNED || e.key == OIS::KC_NUMPADENTER)
    8888    {
    8989      InputManager::getSingleton().setInputMode(IM_KEYBOARD);
  • code/trunk/src/orxonox/CMakeLists.txt

    r1209 r1214  
    33  Main.cc
    44  Orxonox.cc
     5  console/InGameConsole.cc
    56#  SpaceshipSteering.cc
    67  hud/HUD.cc
  • code/trunk/src/orxonox/GraphicsEngine.cc

    r1090 r1214  
    4040#include <OgreLogManager.h>
    4141#include <OgreTextureManager.h>
    42 #include <OgreRenderWindow.h>
    43 
     42#include "core/InputManager.h"
    4443#include "core/CoreIncludes.h"
    4544#include "core/ConfigValueIncludes.h"
    4645#include "core/Debug.h"
     46#include "core/TclBind.h"
    4747
    4848
     
    9090  {
    9191    COUT(4) << "*** GraphicsEngine: Destroying objects..." << std::endl;
     92    Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
    9293    if (this->root_)
    9394      delete this->root_;
     
    112113    SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    113114    SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
     115
     116    TclBind::getInstance().setDataPath(this->dataPath_);
    114117  }
    115118
     
    184187  {
    185188    this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
     189    Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
    186190    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    187191    //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
     
    289293        << "*** Ogre: " << message << std::endl;
    290294  }
     295
     296    void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw){
     297        int w = rw->getWidth();
     298        int h = rw->getHeight();
     299        InputManager::getSingleton().setWindowExtents(w, h);
     300    }
     301
     302    void GraphicsEngine::windowResized(Ogre::RenderWindow *rw){
     303        int w = rw->getWidth();
     304        int h = rw->getHeight();
     305        InputManager::getSingleton().setWindowExtents(w, h);
     306    }
     307
     308    void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw){
     309        int w = rw->getWidth();
     310        int h = rw->getHeight();
     311        InputManager::getSingleton().setWindowExtents(w, h);
     312    }
    291313}
  • code/trunk/src/orxonox/GraphicsEngine.h

    r1056 r1214  
    4242#include <OgrePrerequisites.h>
    4343#include <OgreLog.h>
    44 
     44#include <OgreRenderWindow.h>
     45#include <OgreWindowEventUtilities.h>
    4546#include "core/OrxonoxClass.h"
    4647
     
    4849namespace orxonox {
    4950
    50   /**
     51    /**
    5152    @brief Graphics engine manager class
    52   */
    53   class _OrxonoxExport GraphicsEngine : public OrxonoxClass, public Ogre::LogListener
    54   {
    55     friend class ClassIdentifier<GraphicsEngine>;
    56     public:
    57       void setConfigPath(std::string path) { this->configPath_ = path; };
    58       void setConfigValues();
    59       void setup();
    60       bool load(std::string path);
    61       void loadRessourceLocations(std::string path);
    62       Ogre::SceneManager* getSceneManager();
    63       void initialise();
    64       void destroy();
     53    */
     54    class _OrxonoxExport GraphicsEngine : public Ogre::WindowEventListener, public OrxonoxClass, public Ogre::LogListener
     55    {
     56        friend class ClassIdentifier<GraphicsEngine>;
     57        public:
     58            void setConfigPath(std::string path) { this->configPath_ = path; };
     59            void setConfigValues();
     60            void setup();
     61            bool load(std::string path);
     62            void loadRessourceLocations(std::string path);
     63            Ogre::SceneManager* getSceneManager();
     64            void initialise();
     65            void destroy();
    6566
    66       // several window properties
    67       Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
    68       size_t getWindowHandle();
    69       int getWindowWidth() const;
    70       int getWindowHeight() const;
     67            // several window properties
     68            Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
     69            size_t getWindowHandle();
     70            int getWindowWidth() const;
     71            int getWindowHeight() const;
    7172
    72       static GraphicsEngine& getSingleton();
    73       static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }
     73            static GraphicsEngine& getSingleton();
     74            static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }
    7475
    75     private:
    76       // don't mess with singletons
    77       GraphicsEngine();
    78       ~GraphicsEngine();
    79       GraphicsEngine(GraphicsEngine&) { }
     76            void windowMoved(Ogre::RenderWindow* rw);
     77            void windowResized(Ogre::RenderWindow* rw);
     78            void windowFocusChanged(Ogre::RenderWindow* rw);
    8079
    81       //! Method called by the LogListener from Ogre
    82       void messageLogged(const std::string&, Ogre::LogMessageLevel,
    83                          bool, const std::string&);
     80        private:
     81            // don't mess with singletons
     82            GraphicsEngine();
     83            ~GraphicsEngine();
     84            GraphicsEngine(GraphicsEngine&) { }
    8485
    85       Ogre::Root*         root_;        //!< Ogre's root
    86       Ogre::SceneManager* scene_;       //!< scene manager of the game
    87       Ogre::RenderWindow* renderWindow_;//!< the current render window
    88       //bool               bOverwritePath_; //!< overwrites path
    89       std::string         configPath_;  //!< path to config file
    90       std::string         dataPath_;    //!< path to data file
    91       std::string         ogreLogfile_; //!< log file name for Ogre log messages
    92       int ogreLogLevelTrivial_;         //!< Corresponding Orxonx debug level for LL_TRIVIAL
    93       int ogreLogLevelNormal_;          //!< Corresponding Orxonx debug level for LL_NORMAL
    94       int ogreLogLevelCritical_;        //!< Corresponding Orxonx debug level for LL_CRITICAL
     86            //! Method called by the LogListener from Ogre
     87            void messageLogged(const std::string&, Ogre::LogMessageLevel,
     88                             bool, const std::string&);
    9589
    96   };
    97 
     90            Ogre::Root*         root_;        //!< Ogre's root
     91            Ogre::SceneManager* scene_;       //!< scene manager of the game
     92            Ogre::RenderWindow* renderWindow_;//!< the current render window
     93            //bool               bOverwritePath_; //!< overwrites path
     94            std::string         configPath_;  //!< path to config file
     95            std::string         dataPath_;    //!< path to data file
     96            std::string         ogreLogfile_; //!< log file name for Ogre log messages
     97            int ogreLogLevelTrivial_;         //!< Corresponding Orxonx debug level for LL_TRIVIAL
     98            int ogreLogLevelNormal_;          //!< Corresponding Orxonx debug level for LL_NORMAL
     99            int ogreLogLevelCritical_;        //!< Corresponding Orxonx debug level for LL_CRITICAL
     100    };
    98101}
    99102
  • code/trunk/src/orxonox/Main.cc

    r1056 r1214  
    7474int main(int argc, char **argv)
    7575{
    76   try {
     76  //try {
    7777    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
    7878    Orxonox* orx = Orxonox::getSingleton();
     
    8686    orx->start();
    8787    orx->destroySingleton();
    88   }
     88  /*}
    8989  catch (std::exception &ex)
    9090  {
     
    9292    std::cerr << ex.what() << "\n";
    9393    return 1;
    94   }
     94  }*/
    9595
    9696  return 0;
  • code/trunk/src/orxonox/Orxonox.cc

    r1206 r1214  
    7676#include "tools/Timer.h"
    7777#include "hud/HUD.h"
     78#include "console/InGameConsole.h"
    7879
    7980// FIXME: is this really file scope?
     
    128129  {
    129130  public:
    130     static void calculate(const std::string& calculation)
     131    static float calculate(const std::string& calculation)
    131132    {
    132133      ExprParser expr(calculation);
     
    140141          std::cout << "Warning: Expression could not be parsed to the end! Remains: '"
    141142              << expr.getRemains() << "'" << std::endl;
     143        return expr.getResult();
    142144      }
    143145      else
     146      {
    144147        std::cout << "Cannot calculate expression: Parse error" << std::endl;
     148        return 0;
     149      }
    145150    }
    146151  };
     
    420425    InputBuffer* ib = new InputBuffer();
    421426    InputManager::getSingleton().feedInputBuffer(ib);
     427    /*
    422428    Testconsole* console = new Testconsole(ib);
    423429    ib->registerListener(console, &Testconsole::listen, true);
    424430    ib->registerListener(console, &Testconsole::execute, '\r', false);
    425     ib->registerListener(console, &Testconsole::execute, '\n', false);
    426431    ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);
    427432    ib->registerListener(console, &Testconsole::clear, '§', true);
    428433    ib->registerListener(console, &Testconsole::removeLast, '\b', true);
    429434    ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
     435    */
     436
     437    orxonoxConsole_ = new InGameConsole(ib);
     438    ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);
     439    ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false);
     440    ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true);
     441    ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true);
     442    ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true);
     443    ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);
    430444
    431445    // first check whether ogre root object has been created
     
    477491      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    478492        it->tick((float)evt.timeSinceLastFrame * this->timefactor_);
     493      orxonoxConsole_->tick((float)evt.timeSinceLastFrame * this->timefactor_);
    479494
    480495      // don't forget to call _fireFrameStarted in ogre to make sure
  • code/trunk/src/orxonox/Orxonox.h

    r1089 r1214  
    105105      // TODO: make this a config-value by creating a config class for orxonox
    106106      float                 frameSmoothingTime_;
     107      InGameConsole*        orxonoxConsole_;
    107108      HUD*                  orxonoxHUD_;
    108109      bool                  bAbort_;        //!< aborts the render loop if true
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r1056 r1214  
    9696  // hud
    9797  class HUD;
     98  //console
     99  class InGameConsole;
    98100}
    99101
  • code/trunk/src/orxonox/console/InGameConsole.cc

    r1145 r1214  
    6868    void InGameConsole::listen(){
    6969        if(!active) activate();
    70         print(this->ib_->get());
     70        print(convert2UTF(this->ib_->get()));
    7171    }
    7272
     
    8484        newline();
    8585        this->ib_->set(CommandExecutor::complete(this->ib_->get()));
    86         print(this->ib_->get());
     86        print(convert2UTF(this->ib_->get()));
    8787    }
    8888
     
    109109        scrollTimer = 0;
    110110        cursor = 0;
     111
    111112        // create overlay and elements
    112113        om = &Ogre::OverlayManager::getSingleton();
     
    195196        cursor += dt;
    196197        if(cursor >= 2*BLINK) cursor = 0;
    197         print(this->ib_->get());
     198        print(convert2UTF(this->ib_->get()));
    198199
    199200// this creates a flickering effect
     
    243244    @param s string to be printed
    244245    */
    245     void InGameConsole::print(std::string s){
     246    void InGameConsole::print(Ogre::UTFString s){
    246247        if(cursor>BLINK) consoleOverlayTextAreas[0]->setCaption(">" + s);
    247248        else consoleOverlayTextAreas[0]->setCaption(">" + s + "_");
     
    252253    */
    253254    void InGameConsole::newline(){
    254 
    255         std::string line;
     255        Ogre::UTFString line;
    256256        for(int i = LINES-1; i>=1; i--){
    257257            line = consoleOverlayTextAreas[i-1]->getCaption();
     
    263263        consoleOverlayTextAreas[0]->setCaption(">");
    264264    }
     265
     266    Ogre::UTFString InGameConsole::convert2UTF(std::string s){
     267        Ogre::UTFString utf;
     268        int i;
     269        Ogre::UTFString::code_point cp;
     270        for (i=0; i<(int)s.size(); ++i){
     271          cp = s[i];
     272          cp &= 0xFF;
     273          utf.append(1, cp);
     274        }
     275        return utf;
     276    }
    265277}
  • code/trunk/src/orxonox/console/InGameConsole.h

    r1145 r1214  
    6060        private:
    6161            void resize();
    62             void print(std::string s);
     62            void print(Ogre::UTFString s);
    6363            void newline();
     64            Ogre::UTFString convert2UTF(std::string s);
    6465
    6566            int windowW;
  • code/trunk/src/util/String.cc

    r1111 r1214  
    272272std::string removeSlashes(const std::string& str)
    273273{
    274     if (str.size() == 0)
     274    if (str.size() <= 1)
    275275        return str;
    276     else if (str.size() == 1)
    277     {
    278       //TODO: decide whether we need the commented code
    279       /*if (str[0] != '\\')
    280         return "";
    281       else*/
    282       return str;
    283     }
    284276
    285277    std::string output = "";
  • code/trunk/visual_studio/vc8/orxonox.vcproj

    r1153 r1214  
    385385                        </Filter>
    386386                        <Filter
     387                                Name="console"
     388                                >
     389                                <File
     390                                        RelativePath="..\..\src\orxonox\console\InGameConsole.cc"
     391                                        >
     392                                </File>
     393                        </Filter>
     394                        <Filter
    387395                                Name="tolua"
    388396                                >
     
    527535                                <File
    528536                                        RelativePath="..\..\src\orxonox\tools\Timer.h"
     537                                        >
     538                                </File>
     539                        </Filter>
     540                        <Filter
     541                                Name="console"
     542                                >
     543                                <File
     544                                        RelativePath="..\..\src\orxonox\console\InGameConsole.h"
    529545                                        >
    530546                                </File>
Note: See TracChangeset for help on using the changeset viewer.