Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1881 for code/trunk/src/core


Ignore:
Timestamp:
Oct 3, 2008, 3:30:15 PM (16 years ago)
Author:
rgrieder
Message:

Changed initialisation of internally handled InputStates and InputHandlers.

Location:
code/trunk/src/core/input
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/input/ExtendedInputState.cc

    r1878 r1881  
    362362
    363363        return success;
    364     }
    365 
    366     void ExtendedInputState::removeAndDestroyAllHandlers()
    367     {
    368         for (std::vector<InputHandler*>::iterator it = allHandlers_.begin();
    369             it != allHandlers_.end(); ++it)
    370             delete *it;
    371 
    372         allHandlers_.clear();
    373         keyHandlers_.clear();
    374         mouseHandlers_.clear();
    375         joyStickHandlersAll_.clear();
    376         for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandlers_.size(); ++iJoyStick)
    377             joyStickHandlers_[iJoyStick].clear();
    378         update();
    379364    }
    380365
  • code/trunk/src/core/input/ExtendedInputState.h

    r1878 r1881  
    6464        bool removeHandler(InputHandler* handler);
    6565
    66         void removeAndDestroyAllHandlers();
    67 
    6866    private:
    6967        ExtendedInputState() { }
  • code/trunk/src/core/input/InputManager.cc

    r1878 r1881  
    107107        , windowHnd_(0)
    108108        , internalState_(Uninitialised)
    109         , stateDetector_(0)
    110         , stateCalibrator_(0)
    111109        , stateEmpty_(0)
    112110        , stateMaster_(0)
     111        , keyDetector_(0)
     112        , calibratorCallbackBuffer_(0)
    113113        , bCalibrating_(false)
    114114        , keyboardModifiers_(0)
     
    189189            CCOUT(4) << "Initialising InputStates components..." << std::endl;
    190190
     191            // Lowest priority empty InputState
    191192            stateEmpty_ = createInputState<SimpleInputState>("empty", -1);
    192193            stateEmpty_->setHandler(&EMPTY_HANDLER);
    193194            activeStates_[stateEmpty_->getPriority()] = stateEmpty_;
    194195
    195             stateDetector_ = createInputState<SimpleInputState>("detector", 101);
    196             KeyDetector* temp = new KeyDetector();
    197             temp->loadBindings("storeKeyStroke");
    198             stateDetector_->setHandler(temp);
    199 
    200             stateCalibrator_ = createInputState<SimpleInputState>("calibrator", 100);
    201             stateCalibrator_->setHandler(&EMPTY_HANDLER);
    202             InputBuffer* buffer = new InputBuffer();
    203             buffer->registerListener(this, &InputManager::_completeCalibration, '\r', true);
    204             stateCalibrator_->setKeyHandler(buffer);
    205 
     196            // Always active master InputState
    206197            stateMaster_ = new ExtendedInputState();
    207198            stateMaster_->setName("master");
     199
     200            // KeyDetector to evaluate a pressed key's name
     201            SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101);
     202            keyDetector_ = new KeyDetector();
     203            keyDetector_->loadBindings("storeKeyStroke");
     204            detector->setHandler(keyDetector_);
     205
     206            // Joy stick calibration helper callback
     207            SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", 100);
     208            calibrator->setHandler(&EMPTY_HANDLER);
     209            calibratorCallbackBuffer_ = new InputBuffer();
     210            calibratorCallbackBuffer_->registerListener(this, &InputManager::_completeCalibration, '\r', true);
     211            calibrator->setKeyHandler(calibratorCallbackBuffer_);
    208212
    209213            internalState_ |= InternalsReady;
     
    430434                CCOUT(3) << "Destroying ..." << std::endl;
    431435
    432                 // clear our own states
    433                 //stateEmpty_->removeAndDestroyAllHandlers();
    434                 //stateCalibrator_->removeAndDestroyAllHandlers();
    435                 //stateDetector_->removeAndDestroyAllHandlers();
    436                 // TODO: Memory Leak when not deleting the handlers!!!
    437 
    438436                // kick all active states 'nicely'
    439437                for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
     
    443441                }
    444442
    445                 // destroy all input states
    446                 while (inputStatesByPriority_.size() > 0)
    447                     _destroyState((*inputStatesByPriority_.rbegin()).second);
    448 
     443                // Destroy calibrator helper handler and state
     444                delete keyDetector_;
     445                requestDestroyState("calibrator");
     446                // Destroy KeyDetector and state
     447                delete calibratorCallbackBuffer_;
     448                requestDestroyState("detector");
     449                // destroy the empty InputState
     450                _destroyState(this->stateEmpty_);
    449451                // destroy the master input state. This might trigger a memory leak
    450452                // because the user has forgotten to destroy the KeyBinder or any Handler!
    451453                delete stateMaster_;
     454
     455                // destroy all user InputStates
     456                while (inputStatesByPriority_.size() > 0)
     457                    _destroyState((*inputStatesByPriority_.rbegin()).second);
    452458
    453459                // destroy the devices
     
    12311237    bool InputManager::requestDestroyState(const std::string& name)
    12321238    {
    1233         if (name == "empty" || name == "calibrator" || name == "detector")
    1234         {
    1235             COUT(2) << "InputManager: Removing the '" << name << "' state is not allowed!" << std::endl;
     1239        if (name == "empty")
     1240        {
     1241            COUT(2) << "InputManager: Removing the empty state is not allowed!" << std::endl;
    12361242            return false;
    12371243        }
  • code/trunk/src/core/input/InputManager.h

    r1878 r1881  
    193193
    194194        // some internally handled states and handlers
    195         SimpleInputState*                   stateDetector_;        //!< KeyDetector instance
    196         SimpleInputState*                   stateCalibrator_;
    197195        SimpleInputState*                   stateEmpty_;
    198196        ExtendedInputState*                 stateMaster_;          //!< Always active master input state
     197        KeyDetector*                        keyDetector_;        //!< KeyDetector instance
     198        InputBuffer*                        calibratorCallbackBuffer_;
    199199
    200200        std::map<std::string, InputState*>  inputStatesByName_;
  • code/trunk/src/core/input/SimpleInputState.cc

    r1878 r1881  
    184184    }
    185185
    186     //void SimpleInputState::removeAndDestroyAllHandlers()
    187     //{
    188     //    for (std::vector<InputHandler*>::iterator it = allHandlers_.begin();
    189     //        it != allHandlers_.end(); ++it)
    190     //        delete *it;
    191 
    192     //    allHandlers_.clear();
    193     //    keyHandler_ = 0;
    194     //    mouseHandler_ = 0;
    195     //    joyStickHandlerAll_ = 0;
    196     //    for (unsigned int iJoyStick = 0; iJoyStick < joyStickHandler_.size(); ++iJoyStick)
    197     //        joyStickHandler_[iJoyStick] = 0;
    198 
    199     //    update();
    200     //}
    201 
    202186    /**
    203187    @brief
  • code/trunk/src/core/input/SimpleInputState.h

    r1878 r1881  
    5353        bool setJoyStickHandler   (JoyStickHandler* handler);
    5454        bool setHandler(InputHandler* handler);
    55         //void removeAndDestroyAllHandlers();
    5655
    5756    private:
Note: See TracChangeset for help on using the changeset viewer.