All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ThemeStateTransitionController.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Rendering.h"
6 #include "ThemeStateController.h"
7 
8 namespace Eegeo
9 {
10  namespace Resources
11  {
12  namespace CityThemes
13  {
15  {
16  public:
18  const std::string& initialStateName,
19  ThemeStateController& themeStateController)
20  : m_themeStateController(themeStateController)
21  , m_targetStateName(initialStateName)
22  , m_pTargetState(NULL)
23  , m_pTargetStateTextures(NULL)
24  , m_transitionParam(0.0f)
25  , m_transitionSpeed(0.0f)
26  {
27  }
28 
29  void OnSharedThemeDataUpdate()
30  {
31  m_themeStateController.ResetFromState();
32  }
33 
34  void StartTransitionToState(const Resources::CityThemes::CityThemeState& targetState, const Rendering::EnvironmentStateTextures& targetStateTextures, float transitionSpeed )
35  {
36  m_pTargetState = &targetState;
37  m_pTargetStateTextures = &targetStateTextures;
38  m_targetStateName = m_pTargetState->Name;
39 
40  m_themeStateController.StartTransitionToState(targetState, targetStateTextures);
41 
42  m_transitionParam = 0.0f;
43  m_transitionSpeed = transitionSpeed;
44  }
45 
46  void SetState(const Resources::CityThemes::CityThemeState& targetState, const Rendering::EnvironmentStateTextures& targetStateTextures)
47  {
48  m_pTargetState = &targetState;
49  m_pTargetStateTextures = &targetStateTextures;
50  m_targetStateName = m_pTargetState->Name;
51 
52  m_themeStateController.SetState(targetState, targetStateTextures);
53 
54  m_transitionParam = 0.0f;
55  m_transitionSpeed = 0.0f;
56  }
57 
58  void Update(float dt, const dv3& ecefInterestPoint)
59  {
60  m_transitionParam += (dt * m_transitionSpeed);
61 
62  if(m_transitionParam < 1.0f)
63  {
64  m_themeStateController.SetTransition(m_transitionParam, ecefInterestPoint);
65  }
66  else
67  {
68  m_transitionParam = 0.0f;
69  m_transitionSpeed = 0.0f;
70  m_themeStateController.SetState(*m_pTargetState, *m_pTargetStateTextures);
71  m_themeStateController.SetTransition(m_transitionParam, ecefInterestPoint);
72  }
73  }
74 
75  const std::string& GetTargetStateName() const
76  {
77  return m_targetStateName;
78  }
79 
80  private:
81  ThemeStateController& m_themeStateController;
82 
83  std::string m_targetStateName;
84  const Resources::CityThemes::CityThemeState* m_pTargetState;
85  const Rendering::EnvironmentStateTextures* m_pTargetStateTextures;
86 
87  float m_transitionParam;
88  float m_transitionSpeed;
89  };
90  }
91  }
92 }