AppStateManager.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #include "AppStateManager.h"
  4. #include "AppState_Benchmark01.h"
  5. #include "AppState_Benchmark02.h"
  6. #include "AppState_Benchmark03.h"
  7. #include "AppState_Benchmark04.h"
  8. #include "AppState_MainScreen.h"
  9. #include "AppState_ResultScreen.h"
  10. #include <Urho3D/DebugNew.h>
  11. using namespace Urho3D;
  12. AppStateManager::AppStateManager(Context* context)
  13. : Object(context)
  14. {
  15. appStates_.Insert({APPSTATEID_MAINSCREEN, MakeShared<AppState_MainScreen>(context_)});
  16. appStates_.Insert({APPSTATEID_RESULTSCREEN, MakeShared<AppState_ResultScreen>(context_)});
  17. appStates_.Insert({APPSTATEID_BENCHMARK01, MakeShared<AppState_Benchmark01>(context_)});
  18. appStates_.Insert({APPSTATEID_BENCHMARK02, MakeShared<AppState_Benchmark02>(context_)});
  19. appStates_.Insert({APPSTATEID_BENCHMARK03, MakeShared<AppState_Benchmark03>(context_)});
  20. appStates_.Insert({APPSTATEID_BENCHMARK04, MakeShared<AppState_Benchmark04>(context_)});
  21. }
  22. void AppStateManager::Apply()
  23. {
  24. if (requiredAppStateId_ == currentAppStateId_)
  25. return;
  26. assert(requiredAppStateId_ != APPSTATEID_NULL);
  27. if (currentAppStateId_ != APPSTATEID_NULL)
  28. {
  29. SharedPtr<AppState_Base> currentAppStatePtr = appStates_[currentAppStateId_];
  30. currentAppStatePtr->OnLeave();
  31. }
  32. previousAppStateId_ = currentAppStateId_;
  33. currentAppStateId_ = requiredAppStateId_;
  34. SharedPtr<AppState_Base> requiredAppStatePtr = appStates_[requiredAppStateId_];
  35. requiredAppStatePtr->OnEnter();
  36. }