Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2009, 8:20:07 PM (15 years ago)
Author:
rgrieder
Message:

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/input/KeyDetector.cc

    r5781 r5929  
    2929#include "KeyDetector.h"
    3030
    31 #include "util/Debug.h"
     31#include "core/ConsoleCommand.h"
    3232#include "core/CoreIncludes.h"
     33#include "core/ScopedSingletonManager.h"
    3334#include "Button.h"
     35#include "InputManager.h"
     36#include "InputState.h"
    3437
    3538namespace orxonox
    3639{
    37     /**
    38     @brief
    39         Constructor
    40     */
     40    std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
     41    KeyDetector* KeyDetector::singletonPtr_s = 0;
     42    ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false);
     43
    4144    KeyDetector::KeyDetector()
     45        : KeyBinder("")
    4246    {
    4347        RegisterObject(KeyDetector);
     48
     49        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback,  this), callbackCommand_s));
     50        this->assignCommands();
     51
     52        inputState_ = InputManager::getInstance().createInputState("detector", false, false, InputStatePriority::Detector);
     53        // Create a callback to avoid buttonHeld events after the key has been detected
     54        inputState_->setLeaveFunctor(createFunctor(&InputManager::clearBuffers, &InputManager::getInstance()));
     55        inputState_->setHandler(this);
    4456    }
    4557
    46     /**
    47     @brief
    48         Destructor
    49     */
    5058    KeyDetector::~KeyDetector()
    5159    {
     60        inputState_->setHandler(NULL);
     61        InputManager::getInstance().destroyState("detector");
    5262    }
    5363
    54     /**
    55     @brief
    56         Assigns all the buttons 'command' plus the button's name.
    57     */
    58     void KeyDetector::setCallbackCommand(const std::string& command)
     64    void KeyDetector::assignCommands()
    5965    {
    60         callbackCommand_ = command;
     66        // Assign every button/axis the same command, but with its name as argument
    6167        clearBindings();
    6268        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    6369        {
    64             it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;
     70            it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_;
    6571            it->second->parse();
    6672        }
     73    }
     74
     75    void KeyDetector::callback(const std::string& name)
     76    {
     77        // Call the registered function
     78        if (this->callbackFunction_)
     79            (*this->callbackFunction_)(name);
    6780    }
    6881
     
    7083    {
    7184        KeyBinder::JoyStickQuantityChanged(joyStickList);
    72         if (!callbackCommand_.empty())
    73             setCallbackCommand(callbackCommand_);
     85        this->assignCommands();
    7486    }
    7587}
Note: See TracChangeset for help on using the changeset viewer.