All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PlaceNamesController.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "PlaceNames.h"
6 #include "PlaceNameModel.h"
7 #include "PlaceNameView.h"
8 #include "Types.h"
9 #include "ICityThemeChangedObserver.h"
10 #include "Camera.h"
11 #include "Rendering.h"
12 #include "CityThemes.h"
13 #include "ITextRenderablesSource.h"
14 #include "PlaceNameCategory.h"
15 #include <functional>
16 #include <vector>
17 
18 namespace Eegeo
19 {
20  namespace Resources
21  {
22  namespace
23  {
24  class PlaceNamePrioritySort : public std::binary_function<const Eegeo::Resources::PlaceNames::PlaceNameModel*, const Eegeo::Resources::PlaceNames::PlaceNameModel*, bool>
25  {
26  public:
27  inline bool operator()(const Eegeo::Resources::PlaceNames::PlaceNameModel* pA,
29  {
30  float aPri = pA->GetPriority();
31  float bPri = pB->GetPriority();
32  if(aPri == bPri)
33  {
34  const Eegeo::Resources::PlaceNames::PlaceNameView& viewA = pA->GetView();
35  const Eegeo::Resources::PlaceNames::PlaceNameView& viewB = pB->GetView();
36 
37  float aY = viewA.GetScreenBounds().GetMax().GetY();
38  float bY = viewB.GetScreenBounds().GetMax().GetY();
39  if(aY == bY)
40  {
41  return viewA.GetScreenBounds().GetMax().GetX() > viewB.GetScreenBounds().GetMax().GetX();
42  }
43  return aY > bY;
44  }
45  return aPri < bPri;
46  }
47  };
48  }
49 
50  namespace PlaceNames
51  {
52  static const float DefaultTargetAlpha = 1.0f;
53  static const double DefaultTextMinOpaqueAltitude = 100.0;
54  static const float DefaultTransitionSpeed = 5;
55  static const int MaxOcclusionChecksPerFrame = 750;
56 
58  {
59  private:
60  static const float OtherSideOfWorldDotProdThreshold;
61 
62  public:
64  PlaceNamesRepository& placeNamesRepository,
65  const Rendering::EnvironmentFlatteningService& environmentFlatteningService,
67  float baseScale
68  );
69 
71 
72  void Update(float deltaTime, const Camera::RenderCamera& renderCamera);
73  void UpdateVisiblePlaceNameTransformsForCamera(const Camera::RenderCamera& renderCamera);
74 
75  void SetTargetAlpha(const float targetAlpha);
76  float GetTargetAlpha() const;
77 
78  void SetTextMinOpaqueAltitude(double minOpaqueAltitutde);
79  double GetTextMinOpaqueAltitude() const;
80 
81  void SetTransitionSpeed(float transitionSpeed);
82  float GetTransitionSpeed() const;
83 
84  float GetBaseScale() const;
85  void SetBaseScale(float baseScale);
86 
87  void AddPlaceName(PlaceNameModel* pPlaceNameModel);
88  void RemovePlaceName(PlaceNameModel* pPlaceNameModel);
89  void BeforePlaceNameModelDeleted(PlaceNameModel* pPlaceNameModel);
90  void OnThemeRequested(const CityThemes::CityThemeData& newTheme) {}
91  void OnThemeChanged(const CityThemes::CityThemeData& newTheme);
92 
93  typedef std::vector<PlaceNameModel*> TPlaceNameModels;
94  const TPlaceNameModels& GetSortedPlaceNamesInFrustum() const { return m_sortedPlaceNameModels; } const
95 
96  void GetRenderablesInScene(Eegeo::Rendering::TTextRenderables& out_Renderables) const;
97 
98  private:
99  typedef std::vector<PlaceNameModel*> TPlaceNameModelVec;
100 
101  PlaceNamesRepository& m_placeNamesRepository;
102  const Rendering::EnvironmentFlatteningService& m_environmentFlatteningService;
103  Resources::CityThemes::ICityThemesService& m_cityThemesService;
104 
105  float m_baseScale;
106 
107  double m_minOpaqueAltitude;
108  float m_targetTextAlpha;
109  float m_textAlpha;
110  float m_transitionSpeed;
111  float m_time;
112 
113  int m_nextCheckIndex;
114  int m_nextCheckInnerIndex;
115  TPlaceNameModelVec m_sortedPlaceNameModels;
116  TPlaceNameModelVec m_placeNamesUpdatedThisFrame;
117 
118  void UpdateTextAltitudeAlpha(float deltaTime, const Camera::RenderCamera& renderCamera);
119  void UpdateTransformsAndVisibility(bool visibleOnly, const Camera::RenderCamera& renderCamera);
120  void UpdatePlaceNameOcclusions(const Camera::RenderCamera& renderCamera);
121  void UpdateTransitions(float deltaTime);
122  void PrunePlaceNames();
123  void RestartOcclusionChecking();
124  void UpdateCullState(PlaceNameRenderable& renderable) const;
125  void ApplyCategoryStyleToView(PlaceNameView& view, const std::string& categoryKey, const std::map<std::string, Resources::PlaceNames::PlaceNameCategoryStyle>& styleMap);
126 
127 
128  static void ResolveOcclusion(PlaceNameModel* pInnerPlaceNameModel, PlaceNameModel* pOuterPlaceNameModel);
129  static int GetPriorityForCategory(PlaceNameCategory category);
130  };
131  }
132  }
133 }