Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1112


Ignore:
Timestamp:
Apr 19, 2008, 10:31:52 PM (16 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).

Location:
code/branches/input
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/core/InputHandler.cc

    r1066 r1112  
    3838#include "InputEvent.h"
    3939#include "InputManager.h"
     40#include "core/CommandExecutor.h"
    4041
    4142namespace orxonox
     
    6869    {
    6970      // simply write the key number (i) in the string
    70       this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i);
    71       this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i);
    72     }
     71      this->bindingsKeyPress_[i] = "";
     72      this->bindingsKeyRelease_[i] = "";
     73    }
     74    this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD);
     75    this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
    7376    return true;
    7477  }
     
    8083  bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
    8184  {
    82     if (e.key == OIS::KC_ESCAPE)
    83     {
    84       InputEvent e = {1, true, 0, 0, 0};
    85       InputHandlerGame::callListeners(e);
    86     }
    87     else if (e.key == OIS::KC_NUMPADENTER)
    88     {
    89       InputManager::getSingleton().setInputMode(IM_KEYBOARD);
    90     }
    91     else
    92     {
    93       // find the appropriate key binding
    94       std::string cmdStr = bindingsKeyPressed_[int(e.key)];
    95       //COUT(3) << cmdStr << " pressed" << std::endl;
     85    // find the appropriate key binding
     86    std::string cmdStr = bindingsKeyPress_[int(e.key)];
     87    if (cmdStr != "")
     88    {
     89      CommandExecutor::execute(cmdStr);
     90      COUT(3) << "Executing command: " << cmdStr << std::endl;
    9691    }
    9792    return true;
     
    105100  {
    106101    // find the appropriate key binding
    107     std::string cmdStr = bindingsKeyReleased_[int(e.key)];
    108     //COUT(3) << cmdStr << " released" << std::endl;
     102    std::string cmdStr = bindingsKeyRelease_[int(e.key)];
     103    if (cmdStr != "")
     104    {
     105      CommandExecutor::execute(cmdStr);
     106      COUT(3) << "Executing command: " << cmdStr << std::endl;
     107    }
    109108    return true;
    110109  }
  • code/branches/input/src/core/InputHandler.h

    r1062 r1112  
    4444namespace orxonox
    4545{
     46  namespace KeybindSetting
     47  {
     48    enum KeybindSetting
     49    {
     50      none,
     51      onPress,
     52      onRelease,
     53      continuous,
     54    };
     55  }
     56
     57  class _CoreExport BaseInputHandler
     58      : public OIS::KeyListener, public OIS::MouseListener
     59  {
     60  };
     61   
    4662  /**
    4763    @brief Captures mouse and keyboard input while in the actual game mode.
    4864    Manages the key bindings.
    4965  */
    50   class _CoreExport InputHandlerGame
    51         : public OIS::KeyListener, public OIS::MouseListener
     66  class _CoreExport InputHandlerGame : public BaseInputHandler
    5267  {
    5368  public:
     
    7287    static const int numberOfKeys_s = 256;
    7388    //! Array of input events for every pressed key
    74     std::string bindingsKeyPressed_[numberOfKeys_s];
     89    std::string bindingsKeyPress_[numberOfKeys_s];
    7590    //! Array of input events for every released key
    76     std::string bindingsKeyReleased_[numberOfKeys_s];
     91    std::string bindingsKeyRelease_[numberOfKeys_s];
     92    //! Array of input events for every holding key
     93    std::string bindingsKeyHold_[numberOfKeys_s];
    7794
    7895    /** denotes the maximum number of different buttons there are in OIS.
     
    91108    GUI.
    92109  */
    93   class _CoreExport InputHandlerGUI
    94         : public OIS::KeyListener, public OIS::MouseListener
     110  class _CoreExport InputHandlerGUI : public BaseInputHandler
    95111  {
    96112  public:
  • code/branches/input/src/core/InputManager.cc

    r1089 r1112  
    9393      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    9494
    95 #if defined OIS_LINUX_PLATFORM
    96       paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    97 #endif
     95//#if defined OIS_LINUX_PLATFORM
     96//      paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
     97//#endif
    9898
    9999      try
  • 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  }
  • code/branches/input/src/util/String.cc

    r1064 r1112  
    274274    if (str.size() == 0)
    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    }
    276284
    277285    std::string output = "";
  • code/branches/input/visual_studio/vc8/core.vcproj

    r1084 r1112  
    258258                                        RelativePath="..\..\src\core\tolua\tolua_bind.cc"
    259259                                        >
    260                                         <FileConfiguration
    261                                                 Name="Debug|Win32"
    262                                                 >
    263                                                 <Tool
    264                                                         Name="VCCLCompilerTool"
    265                                                 />
    266                                         </FileConfiguration>
    267260                                </File>
    268261                        </Filter>
  • code/branches/input/visual_studio/vc8/util.vcproj

    r1064 r1112  
    157157                        </File>
    158158                        <File
     159                                RelativePath="..\..\src\util\FloatParser.cpp"
     160                                >
     161                        </File>
     162                        <File
    159163                                RelativePath="..\..\src\util\Math.cc"
    160164                                >
     
    199203                        </File>
    200204                        <File
     205                                RelativePath="..\..\src\util\FloatParser.h"
     206                                >
     207                        </File>
     208                        <File
    201209                                RelativePath="..\..\src\util\Math.h"
    202210                                >
Note: See TracChangeset for help on using the changeset viewer.