State.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #ifndef __STATE_H
  11. #define __STATE_H
  12. class FSM;
  13. // States are stored in the FSM class (Finite state machine)
  14. // The FSM only has one active state at a time and stores the state history stack
  15. // State data can be held in this class - however data which is used between states is best stored elsewhere.
  16. class State
  17. {
  18. public:
  19. State();
  20. ~State();
  21. // OnEnter is called when this state will not be the current state
  22. // loadResources true means this state is now in the history stack and was not there before
  23. virtual void OnEnter(const FSM *caller, bool loadResources);
  24. // OnLeave is called when this state is currently the current state and will no longer be the current state
  25. // unloadResources true means this state is no longer in the history stack and we will probably not be entering it again via the back button
  26. virtual void OnLeave(const FSM *caller, bool unloadResources);
  27. // Called once for every time this state is added to the FSM history stack
  28. virtual void FSMAddRef(const FSM *caller);
  29. // Called once for every time this state is removed from the FSM history stack.
  30. virtual void FSMRemoveRef(const FSM *caller);
  31. // The number of times this state is in the FSM history stack.
  32. unsigned FSMRefCount(void) const;
  33. protected:
  34. unsigned fsmRefCount;
  35. };
  36. // Same as State, but self-deletes when fsmRefCount==0
  37. class ManagedState : public State
  38. {
  39. public:
  40. virtual void FSMRemoveRef(const FSM *caller);
  41. };
  42. #endif
粤ICP备19079148号