Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 19, 2008, 10:31:52 PM (17 years ago)
Author:
rgrieder
Message:

added calculate command ;)
In the console, you can now type something like "calculate sin(cos(3+4) - 8)*7" or even "calculate 7>8" and you'll get the result as a double.
The parser was something I've written 3 years ago when I first used C++ (the parser is mainly C).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/orxonox/Orxonox.cc

    r1092 r1112  
    5454//#include "util/Sleep.h"
    5555#include "util/ArgReader.h"
     56#include "util/FloatParser.h"
    5657
    5758// core
     
    123124      InputBuffer* ib_;
    124125  };
     126
     127  class Calculator
     128  {
     129  public:
     130    static void calculate(std::string calculation)
     131    {
     132      char** useless = 0;
     133      double result = 0.0;
     134      bool success = parse_float((char* const)calculation.c_str(), useless, &result);
     135      if (success)
     136      {
     137        if (result == 42.0)
     138          std::cout << "Greetings from the restaurant at the end of the universe." << std::endl;
     139        std::cout << "Result is: " << result << std::endl;
     140      }
     141      else
     142        std::cout << "Cannot calculate expression: Parse error" << std::endl;
     143    }
     144  };
     145  ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None);
    125146
    126147  /**
     
    410431      return;
    411432    }
     433    Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
     434
    412435
    413436    // Contains the times of recently fired events
     
    429452          {
    430453                  // Pump messages in all registered RenderWindows
     454      // This calls the WindowEventListener objects.
    431455      Ogre::WindowEventUtilities::messagePump();
    432456
     
    452476      // don't forget to call _fireFrameStarted in ogre to make sure
    453477      // everything goes smoothly
    454       Ogre::Root::getSingleton()._fireFrameStarted(evt);
     478      ogreRoot._fireFrameStarted(evt);
    455479
    456480      // server still renders at the moment
    457481      //if (mode_ != SERVER)
    458       Ogre::Root::getSingleton()._updateAllRenderTargets(); // only render in non-server mode
     482      ogreRoot._updateAllRenderTargets(); // only render in non-server mode
    459483
    460484      // get current time
     
    466490
    467491      // again, just to be sure ogre works fine
    468       Ogre::Root::getSingleton()._fireFrameEnded(evt);
     492      ogreRoot._fireFrameEnded(evt);
    469493          }
    470494  }
Note: See TracChangeset for help on using the changeset viewer.