Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 26, 2008, 4:26:04 PM (16 years ago)
Author:
rgrieder
Message:

Still working on the GameStates, but I have to save the work because of some major changes.

  • Exported InputManager- and TclThreadManager-tick to GSGraphics instead of Core
  • Fixed a few bugs in GameState by adding an internal state variable as bitfield (quite practical)
  • Fixed a bug in InputManager that occurred when destroying an active InputState
  • Added GSIO and GSIOConsole (3 lines of loop code with std::cin, but works ;))
  • Added more boost thread includes to OrxonoxStableHeaders.h
  • Many changes in all GameState derived classes
Location:
code/branches/gui/src/core/input
Files:
2 edited

Legend:

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

    r1660 r1670  
    348348        for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
    349349            it != inputStatesByPriority_.end(); ++it)
    350             (*it).second->setNumOfJoySticks(joySticksSize_);
     350            it->second->setNumOfJoySticks(joySticksSize_);
    351351    }
    352352
     
    506506    }
    507507
     508    /**
     509    @brief
     510        Removes and destroys an InputState.
     511    @return
     512        True if state was removed immediately, false if postponed.
     513    */
    508514    void InputManager::_destroyState(InputState* state)
    509515    {
    510         assert(state);
     516        assert(state && !(this->internalState_ & Ticking));
    511517        std::map<int, InputState*>::iterator it = this->activeStates_.find(state->getPriority());
    512518        if (it != this->activeStates_.end())
     
    633639        internalState_ |= Ticking;
    634640
    635         // check for states to leave (don't use unsigned int!)
    636         for (int i = stateLeaveRequests_.size() - 1; i >= 0; --i)
    637         {
    638             stateLeaveRequests_[i]->onLeave();
     641        // check for states to leave
     642        for (std::set<InputState*>::reverse_iterator it = stateLeaveRequests_.rbegin();
     643            it != stateLeaveRequests_.rend(); ++it)
     644        {
     645            (*it)->onLeave();
    639646            // just to be sure that the state actually is registered
    640             assert(inputStatesByName_.find(stateLeaveRequests_[i]->getName()) != inputStatesByName_.end());
    641            
    642             activeStates_.erase(stateLeaveRequests_[i]->getPriority());
     647            assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     648
     649            activeStates_.erase((*it)->getPriority());
    643650            _updateActiveStates();
    644             stateLeaveRequests_.pop_back();
    645         }
    646 
    647 
    648         // check for states to enter (don't use unsigned int!)
    649         for (int i = stateEnterRequests_.size() - 1; i >= 0; --i)
     651        }
     652        stateLeaveRequests_.clear();
     653
     654        // check for states to enter
     655        for (std::set<InputState*>::reverse_iterator it = stateEnterRequests_.rbegin();
     656            it != stateEnterRequests_.rend(); ++it)
    650657        {
    651658            // just to be sure that the state actually is registered
    652             assert(inputStatesByName_.find(stateEnterRequests_[i]->getName()) != inputStatesByName_.end());
    653            
    654             activeStates_[stateEnterRequests_[i]->getPriority()] = stateEnterRequests_[i];
     659            assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
     660
     661            activeStates_[(*it)->getPriority()] = (*it);
    655662            _updateActiveStates();
    656             stateEnterRequests_[i]->onEnter();
    657             stateEnterRequests_.pop_back();
     663            (*it)->onEnter();
     664        }
     665        stateEnterRequests_.clear();
     666
     667        // check for states to destroy
     668        for (std::set<InputState*>::reverse_iterator it = stateDestroyRequests_.rbegin();
     669            it != stateDestroyRequests_.rend(); ++it)
     670        {
     671            _destroyState((*it));
    658672        }
    659673
     
    703717        for (std::map<int, InputState*>::const_iterator it = activeStates_.begin(); it != activeStates_.end(); ++it)
    704718            for (unsigned int i = 0; i < devicesNum_; ++i)
    705                 if ((*it).second->isInputDeviceEnabled(i))
    706                     activeStatesTop_[i] = (*it).second;
     719                if (it->second->isInputDeviceEnabled(i))
     720                    activeStatesTop_[i] = it->second;
    707721
    708722        // update tickables (every state will only appear once)
     
    11351149    /**
    11361150    @brief
    1137         Removes an input state internally.
     1151        Removes and destroys an input state internally.
    11381152    @param name
    11391153        Name of the handler.
     
    11421156    @remarks
    11431157        You can't remove the internal states "empty", "calibrator" and "detector".
    1144     */
    1145     bool InputManager::destroyState(const std::string& name)
     1158        The removal process is being postponed if InputManager::tick() is currently running.
     1159    */
     1160    bool InputManager::requestDestroyState(const std::string& name)
    11461161    {
    11471162        if (name == "empty" || name == "calibrator" || name == "detector")
     
    11531168        if (it != inputStatesByName_.end())
    11541169        {
    1155             _destroyState((*it).second);
     1170            if (activeStates_.find(it->second->getPriority()) != activeStates_.end())
     1171            {
     1172                // The state is still active. We have to postpone
     1173                stateLeaveRequests_.insert(it->second);
     1174                stateDestroyRequests_.insert(it->second);
     1175            }
     1176            else if (this->internalState_ & Ticking)
     1177            {
     1178                // cannot remove state while ticking
     1179                stateDestroyRequests_.insert(it->second);
     1180            }
     1181            else
     1182                _destroyState(it->second);
     1183
    11561184            return true;
    11571185        }
     
    11711199        std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name);
    11721200        if (it != inputStatesByName_.end())
    1173             return (*it).second;
     1201            return it->second;
    11741202        else
    11751203            return 0;
     
    12021230        if (it != inputStatesByName_.end())
    12031231        {
    1204             stateEnterRequests_.push_back((*it).second);
    1205             return true;
     1232            // exists
     1233            if (activeStates_.find(it->second->getPriority()) == activeStates_.end())
     1234            {
     1235                // not active
     1236                if (stateDestroyRequests_.find(it->second) == stateDestroyRequests_.end())
     1237                {
     1238                    // not scheduled for destruction
     1239                    // set prevents a state being added multiple times
     1240                    stateEnterRequests_.insert(it->second);
     1241                    return true;
     1242                }
     1243            }
    12061244        }
    12071245        return false;
     
    12221260        if (it != inputStatesByName_.end())
    12231261        {
    1224             stateLeaveRequests_.push_back((*it).second);
    1225             return true;
     1262            // exists
     1263            if (activeStates_.find(it->second->getPriority()) != activeStates_.end())
     1264            {
     1265                // active
     1266                stateLeaveRequests_.insert(it->second);
     1267                return true;
     1268            }
    12261269        }
    12271270        return false;
  • code/branches/gui/src/core/input/InputManager.h

    r1659 r1670  
    127127        }
    128128
    129         bool destroyState          (const std::string& name);
    130129        InputState* getState       (const std::string& name);
    131130        InputState* getCurrentState();
     131        bool requestDestroyState   (const std::string& name);
    132132        bool requestEnterState     (const std::string& name);
    133133        bool requestLeaveState     (const std::string& name);
     134
     135        void tick(float dt);
    134136
    135137        static InputManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
     
    167169        void _updateActiveStates();
    168170        bool _configureInputState(InputState* state, const std::string& name, int priority);
    169 
    170         void tick(float dt);
    171171
    172172        // input events
     
    204204        std::map<int, InputState*>          inputStatesByPriority_;
    205205
    206         std::vector<InputState*>            stateEnterRequests_;   //!< Request to enter a new state
    207         std::vector<InputState*>            stateLeaveRequests_;   //!< Request to leave the current state
     206        std::set<InputState*>               stateEnterRequests_;   //!< Request to enter a new state
     207        std::set<InputState*>               stateLeaveRequests_;   //!< Request to leave a running state
     208        std::set<InputState*>               stateDestroyRequests_; //!< Request to destroy a state
    208209
    209210        std::map<int, InputState*>          activeStates_;
Note: See TracChangeset for help on using the changeset viewer.