Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 2, 2008, 9:23:30 PM (16 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/src/orxonox
Files:
7 edited
3 copied

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.