Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CCmpSelectable.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "ICmpSelectable.h"
21 
22 #include "graphics/Overlay.h"
23 #include "graphics/Terrain.h"
25 #include "maths/Ease.h"
26 #include "maths/MathUtil.h"
27 #include "maths/Matrix3D.h"
28 #include "maths/Vector3D.h"
29 #include "maths/Vector2D.h"
30 #include "renderer/Scene.h"
31 #include "renderer/Renderer.h"
43 
44 // Minimum alpha value for always visible overlays [0 fully transparent, 1 fully opaque]
45 static const float MIN_ALPHA_ALWAYS_VISIBLE = 0.65f;
46 // Minimum alpha value for other overlays
47 static const float MIN_ALPHA_UNSELECTED = 0.0f;
48 // Desaturation value for unselected, always visible overlays (0.33 = 33% desaturated or 66% of original saturation)
49 static const float RGB_DESATURATION = 0.333333f;
50 
52 {
53 public:
54  static void ClassInit(CComponentManager& componentManager)
55  {
56  componentManager.SubscribeToMessageType(MT_Interpolate);
57  componentManager.SubscribeToMessageType(MT_RenderSubmit);
60  // TODO: it'd be nice if we didn't get these messages except in the rare
61  // cases where we're actually drawing a selection highlight
62  }
63 
65 
68  m_BuildingOverlay(NULL), m_UnitOverlay(NULL),
70  m_Selected(false), m_Cached(false), m_Visible(false)
71  {
73  }
74 
76  {
79  delete m_BuildingOverlay;
80  delete m_UnitOverlay;
81  }
82 
83  static std::string GetSchema()
84  {
85  return
86  "<a:help>Allows this entity to be selected by the player.</a:help>"
87  "<a:example/>"
88  "<optional>"
89  "<element name='EditorOnly' a:help='If this element is present, the entity is only selectable in Atlas'>"
90  "<empty/>"
91  "</element>"
92  "</optional>"
93  "<element name='Overlay' a:help='Specifies the type of overlay to be displayed when this entity is selected'>"
94  "<optional>"
95  "<element name='AlwaysVisible' a:help='If this element is present, the selection overlay will always be visible (with transparency and desaturation)'>"
96  "<empty/>"
97  "</element>"
98  "</optional>"
99  "<choice>"
100  "<element name='Texture' a:help='Displays a texture underneath the entity.'>"
101  "<element name='MainTexture' a:help='Texture to display underneath the entity. Filepath relative to art/textures/selection/.'><text/></element>"
102  "<element name='MainTextureMask' a:help='Mask texture that controls where to apply player color. Filepath relative to art/textures/selection/.'><text/></element>"
103  "</element>"
104  "<element name='Outline' a:help='Traces the outline of the entity with a line texture.'>"
105  "<element name='LineTexture' a:help='Texture to apply to the line. Filepath relative to art/textures/selection/.'><text/></element>"
106  "<element name='LineTextureMask' a:help='Texture that controls where to apply player color. Filepath relative to art/textures/selection/.'><text/></element>"
107  "<element name='LineThickness' a:help='Thickness of the line, in world units.'><ref name='positiveDecimal'/></element>"
108  "</element>"
109  "</choice>"
110  "</element>";
111  }
112 
113  virtual void Init(const CParamNode& paramNode)
114  {
115  m_EditorOnly = paramNode.GetChild("EditorOnly").IsOk();
116 
117  // Certain special units always have their selection overlay shown
118  m_AlwaysVisible = paramNode.GetChild("Overlay").GetChild("AlwaysVisible").IsOk();
119  if (m_AlwaysVisible)
120  {
122  m_Color.a = m_AlphaMin;
123  }
124  else
126 
127  const CParamNode& textureNode = paramNode.GetChild("Overlay").GetChild("Texture");
128  const CParamNode& outlineNode = paramNode.GetChild("Overlay").GetChild("Outline");
129 
130  const char* textureBasePath = "art/textures/selection/";
131 
132  // Save some memory by using interned file paths in these descriptors (almost all actors and
133  // entities have this component, and many use the same textures).
134  if (textureNode.IsOk())
135  {
136  // textured quad mode (dynamic, for units)
138  m_OverlayDescriptor.m_QuadTexture = CStrIntern(textureBasePath + textureNode.GetChild("MainTexture").ToUTF8());
139  m_OverlayDescriptor.m_QuadTextureMask = CStrIntern(textureBasePath + textureNode.GetChild("MainTextureMask").ToUTF8());
140  }
141  else if (outlineNode.IsOk())
142  {
143  // textured outline mode (static, for buildings)
145  m_OverlayDescriptor.m_LineTexture = CStrIntern(textureBasePath + outlineNode.GetChild("LineTexture").ToUTF8());
146  m_OverlayDescriptor.m_LineTextureMask = CStrIntern(textureBasePath + outlineNode.GetChild("LineTextureMask").ToUTF8());
147  m_OverlayDescriptor.m_LineThickness = outlineNode.GetChild("LineThickness").ToFloat();
148  }
149  }
150 
151  virtual void Deinit() { }
152 
153  virtual void Serialize(ISerializer& UNUSED(serialize))
154  {
155  // Nothing to do here (the overlay object is not worth saving, it'll get
156  // reconstructed by the GUI soon enough, I think)
157  }
158 
159  virtual void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize))
160  {
161  // Need to call Init to reload the template properties
162  Init(paramNode);
163  }
164 
165  virtual void HandleMessage(const CMessage& msg, bool UNUSED(global));
166 
167  virtual void SetSelectionHighlight(CColor color, bool selected)
168  {
169  m_Selected = selected;
170  m_Color.r = color.r;
171  m_Color.g = color.g;
172  m_Color.b = color.b;
173 
174  // Always-visible overlays will be desaturated if their parent unit is deselected.
175  if (m_AlwaysVisible && !selected)
176  {
177  float max;
178 
179  // Reduce saturation by one-third, the quick-and-dirty way.
180  if (m_Color.r > m_Color.b)
181  max = (m_Color.r > m_Color.g) ? m_Color.r : m_Color.g;
182  else
183  max = (m_Color.b > m_Color.g) ? m_Color.b : m_Color.g;
184 
185  m_Color.r += (max - m_Color.r) * RGB_DESATURATION;
186  m_Color.g += (max - m_Color.g) * RGB_DESATURATION;
187  m_Color.b += (max - m_Color.b) * RGB_DESATURATION;
188  }
189 
191  }
192 
193  virtual void SetSelectionHighlightAlpha(float alpha)
194  {
195  alpha = std::max(m_AlphaMin, alpha);
196 
197  // set up fading from the current value (as the baseline) to the target value
200  m_FadeProgress = 0.f;
201  }
202 
203  virtual void SetVisibility(bool visible)
204  {
205  m_Visible = visible;
206  }
207 
208  virtual bool IsEditorOnly()
209  {
210  return m_EditorOnly;
211  }
212 
213  void RenderSubmit(SceneCollector& collector);
214 
215  /**
216  * Called from RenderSubmit if using a static outline; responsible for ensuring that the static overlay
217  * is up-to-date before it is rendered. Has no effect unless the static overlay is explicitly marked as
218  * invalid first (see InvalidateStaticOverlay).
219  */
220  void UpdateStaticOverlay();
221 
222  /**
223  * Called from the interpolation handler; responsible for ensuring the dynamic overlay (provided we're
224  * using one) is up-to-date and ready to be submitted to the next rendering run.
225  */
226  void UpdateDynamicOverlay(float frameOffset);
227 
228  /// Explicitly invalidates the static overlay.
230 
231 private:
235 
238 
239  // Whether the selectable will be rendered.
240  bool m_Visible;
241  // Whether the entity is only selectable in Atlas editor
243  // Whether the selection overlay is always visible
245  /// Whether the parent entity is selected (caches GUI's selection state).
247  /// Current selection overlay color. Alpha component is subject to fading.
249  /// Whether the selectable's player colour has been cached for rendering.
250  bool m_Cached;
251  /// Minimum value for current selection overlay alpha.
252  float m_AlphaMin;
253  /// Baseline alpha value to start fading from. Constant during a single fade.
255  /// Delta between target and baseline alpha. Constant during a single fade. Can be positive or negative.
257  /// Linear time progress of the fade, between 0 and m_FadeDuration.
259 
260  /// Total duration of a single fade, in seconds. Assumed constant for now; feel free to change this into
261  /// a member variable if you need to adjust it per component.
262  static const double FADE_DURATION;
263 };
264 
265 const double CCmpSelectable::FADE_DURATION = 0.3;
266 
267 void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global))
268 {
269  switch (msg.GetType())
270  {
271  case MT_Interpolate:
272  {
273  const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
274 
275  if (m_FadeDeltaAlpha != 0.f)
276  {
277  m_FadeProgress += msgData.deltaRealTime;
279  {
280  const float targetAlpha = m_FadeBaselineAlpha + m_FadeDeltaAlpha;
281 
282  // stop the fade
283  m_Color.a = targetAlpha;
284  m_FadeBaselineAlpha = targetAlpha;
285  m_FadeDeltaAlpha = 0.f;
286  m_FadeProgress = FADE_DURATION; // will need to be reset to start the next fade again
287  }
288  else
289  {
291  }
292  }
293 
294  // update dynamic overlay only when visible
295  if (m_Color.a > 0)
296  UpdateDynamicOverlay(msgData.offset);
297 
298  break;
299  }
300  case MT_OwnershipChanged:
301  {
302  const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg);
303 
304  // don't update color if there's no new owner (e.g. the unit died)
305  if (msgData.to == INVALID_PLAYER)
306  break;
307 
308  // update the selection highlight color
309  CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
310  if (!cmpPlayerManager)
311  break;
312 
313  CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(msgData.to));
314  if (!cmpPlayer)
315  break;
316 
317  // Update the highlight color, while keeping the current alpha target value intact
318  // (i.e. baseline + delta), so that any ongoing fades simply continue with the new color.
319  CColor color = cmpPlayer->GetColour();
321  }
322  // fall-through
323  case MT_PositionChanged:
324  {
326  break;
327  }
328  case MT_RenderSubmit:
329  {
330  const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg);
331  RenderSubmit(msgData.collector);
332 
333  break;
334  }
335  }
336 }
337 
339 {
341 }
342 
344 {
345  // Static overlays are allocated once and not updated until they are explicitly deleted again
346  // (see InvalidateStaticOverlay). Since they are expected to change rarely (if ever) during
347  // normal gameplay, this saves us doing all the work below on each frame.
348 
350  return;
351 
353  return;
354 
355  CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle());
356  CmpPtr<ICmpFootprint> cmpFootprint(GetEntityHandle());
357  if (!cmpFootprint || !cmpPosition || !cmpPosition->IsInWorld())
358  return;
359 
360  CmpPtr<ICmpTerrain> cmpTerrain(GetSystemEntity());
361  if (!cmpTerrain)
362  return; // should never happen
363 
364  // grab position/footprint data
365  CFixedVector2D position = cmpPosition->GetPosition2D();
366  CFixedVector3D rotation = cmpPosition->GetRotation();
367 
368  ICmpFootprint::EShape fpShape;
369  entity_pos_t fpSize0_fixed, fpSize1_fixed, fpHeight_fixed;
370  cmpFootprint->GetShape(fpShape, fpSize0_fixed, fpSize1_fixed, fpHeight_fixed);
371 
373  texturePropsBase.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
374  texturePropsBase.SetMaxAnisotropy(4.f);
375 
377  texturePropsMask.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
378  texturePropsMask.SetMaxAnisotropy(4.f);
379 
380  // -------------------------------------------------------------------------------------
381 
384  m_BuildingOverlay->m_Closed = true;
387  m_BuildingOverlay->m_TextureBase = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase);
388  m_BuildingOverlay->m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask);
389 
390  CVector2D origin(position.X.ToFloat(), position.Y.ToFloat());
391 
392  switch (fpShape)
393  {
395  {
396  float s = sinf(-rotation.Y.ToFloat());
397  float c = cosf(-rotation.Y.ToFloat());
398  CVector2D unitX(c, s);
399  CVector2D unitZ(-s, c);
400 
401  // add half the line thickness to the radius so that we get an 'outside' stroke of the footprint shape
402  const float halfSizeX = fpSize0_fixed.ToFloat()/2.f + m_BuildingOverlay->m_Thickness/2.f;
403  const float halfSizeZ = fpSize1_fixed.ToFloat()/2.f + m_BuildingOverlay->m_Thickness/2.f;
404 
405  std::vector<CVector2D> points;
406  points.push_back(CVector2D(origin + unitX * halfSizeX + unitZ *(-halfSizeZ)));
407  points.push_back(CVector2D(origin + unitX *(-halfSizeX) + unitZ *(-halfSizeZ)));
408  points.push_back(CVector2D(origin + unitX *(-halfSizeX) + unitZ * halfSizeZ));
409  points.push_back(CVector2D(origin + unitX * halfSizeX + unitZ * halfSizeZ));
410 
412  m_BuildingOverlay->PushCoords(points);
413  }
414  break;
416  {
417  const float radius = fpSize0_fixed.ToFloat() + m_BuildingOverlay->m_Thickness/3.f;
418  if (radius > 0) // prevent catastrophic failure
419  {
420  float stepAngle;
421  unsigned numSteps;
422  SimRender::AngularStepFromChordLen(TERRAIN_TILE_SIZE/3.f, radius, stepAngle, numSteps);
423 
424  for (unsigned i = 0; i < numSteps; i++) // '<' is sufficient because the line is closed automatically
425  {
426  float angle = i * stepAngle;
427  float px = origin.X + radius * sinf(angle);
428  float pz = origin.Y + radius * cosf(angle);
429 
430  m_BuildingOverlay->PushCoords(px, pz);
431  }
432  }
433  }
434  break;
435  }
436 
438 }
439 
441 {
442  // Dynamic overlay lines are allocated once and never deleted. Since they are expected to change frequently,
443  // they are assumed dirty on every call to this function, and we should therefore use this function more
444  // thoughtfully than calling it right before every frame render.
445 
447  return;
448 
450  return;
451 
452  CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle());
453  CmpPtr<ICmpFootprint> cmpFootprint(GetEntityHandle());
454  if (!cmpFootprint || !cmpPosition || !cmpPosition->IsInWorld())
455  return;
456 
457  float rotY;
458  CVector2D position;
459  cmpPosition->GetInterpolatedPosition2D(frameOffset, position.X, position.Y, rotY);
460 
461  CmpPtr<ICmpWaterManager> cmpWaterManager(GetSystemEntity());
462  CmpPtr<ICmpTerrain> cmpTerrain(GetSystemEntity());
463  ENSURE(cmpWaterManager && cmpTerrain);
464 
465  CTerrain* terrain = cmpTerrain->GetCTerrain();
466  ENSURE(terrain);
467 
468  ICmpFootprint::EShape fpShape;
469  entity_pos_t fpSize0_fixed, fpSize1_fixed, fpHeight_fixed;
470  cmpFootprint->GetShape(fpShape, fpSize0_fixed, fpSize1_fixed, fpHeight_fixed);
471 
472  // ---------------------------------------------------------------------------------
473 
474  if (!m_UnitOverlay)
475  {
477 
478  // Assuming we don't need the capability of swapping textures on-demand.
480  texturePropsBase.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
481  texturePropsBase.SetMaxAnisotropy(4.f);
482 
484  texturePropsMask.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
485  texturePropsMask.SetMaxAnisotropy(4.f);
486 
487  m_UnitOverlay->m_Texture = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase);
488  m_UnitOverlay->m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask);
489  }
490 
492 
493  // TODO: some code duplication here :< would be nice to factor out getting the corner points of an
494  // entity based on its footprint sizes (and regardless of whether it's a circle or a square)
495 
496  float s = sinf(-rotY);
497  float c = cosf(-rotY);
498  CVector2D unitX(c, s);
499  CVector2D unitZ(-s, c);
500 
501  float halfSizeX = fpSize0_fixed.ToFloat();
502  float halfSizeZ = fpSize1_fixed.ToFloat();
503  if (fpShape == ICmpFootprint::SQUARE)
504  {
505  halfSizeX /= 2.0f;
506  halfSizeZ /= 2.0f;
507  }
508 
509  std::vector<CVector2D> points;
510  points.push_back(CVector2D(position + unitX *(-halfSizeX) + unitZ * halfSizeZ)); // top left
511  points.push_back(CVector2D(position + unitX *(-halfSizeX) + unitZ *(-halfSizeZ))); // bottom left
512  points.push_back(CVector2D(position + unitX * halfSizeX + unitZ *(-halfSizeZ))); // bottom right
513  points.push_back(CVector2D(position + unitX * halfSizeX + unitZ * halfSizeZ)); // top right
514 
515  for (int i=0; i < 4; i++)
516  {
517  float quadY = std::max(
518  terrain->GetExactGroundLevel(points[i].X, points[i].Y),
519  cmpWaterManager->GetExactWaterLevel(points[i].X, points[i].Y)
520  );
521 
522  m_UnitOverlay->m_Corners[i] = CVector3D(points[i].X, quadY, points[i].Y);
523  }
524 }
525 
527 {
528  // don't render selection overlay if it's not gonna be visible
529  if (m_Visible && m_Color.a > 0)
530  {
531  if (!m_Cached)
532  {
533  // Default to white if there's no owner (e.g. decorative, editor-only actors)
534  CColor color = CColor(1.0, 1.0, 1.0, 1.0);
535  CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle());
536  if (cmpOwnership)
537  {
538  player_id_t owner = cmpOwnership->GetOwner();
539  if (owner == INVALID_PLAYER)
540  return;
541 
542  // Try to initialize m_Color to the owning player's colour.
543  CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
544  if (!cmpPlayerManager)
545  return;
546 
547  CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(owner));
548  if (!cmpPlayer)
549  return;
550 
551  color = cmpPlayer->GetColour();
552  }
554 
556  m_Cached = true;
557  }
558 
559  switch (m_OverlayDescriptor.m_Type)
560  {
561  case STATIC_OUTLINE:
562  {
564  m_BuildingOverlay->m_Color = m_Color; // done separately so alpha changes don't require a full update call
565  collector.Submit(m_BuildingOverlay);
566  }
567  break;
568  case DYNAMIC_QUAD:
569  {
570  if (m_UnitOverlay)
571  collector.Submit(m_UnitOverlay);
572  }
573  break;
574  default:
575  break;
576  }
577  }
578 
579  // Render bounding box debug overlays if we have a positive target alpha value. This ensures
580  // that the debug overlays respond immediately to deselection without delay from fading out.
582  {
584  {
585  // allocate debug overlays on-demand
588 
589  CmpPtr<ICmpVisual> cmpVisual(GetEntityHandle());
590  if (cmpVisual)
591  {
594  m_DebugBoundingBoxOverlay->m_Color = CColor(1.f, 0.f, 0.f, 1.f);
595 
598  m_DebugSelectionBoxOverlay->m_Color = CColor(0.f, 1.f, 0.f, 1.f);
599 
602  }
603  }
604  else
605  {
606  // reclaim debug overlay line memory when no longer debugging (and make sure to set to zero after deletion)
609  }
610  }
611 }
612 
613 REGISTER_COMPONENT_TYPE(Selectable)
An entity initialisation parameter node.
Definition: ParamNode.h:112
static void ClassInit(CComponentManager &componentManager)
virtual void SetSelectionHighlightAlpha(float alpha)
Set the alpha of the selection highlight.
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
CVector3D m_Corners[4]
Definition: Overlay.h:153
static const double FADE_DURATION
Total duration of a single fade, in seconds.
A simple fixed-point number class.
Definition: Fixed.h:115
static std::string GetSchema()
Definition: Decompose.h:22
#define REGISTER_COMPONENT_TYPE(cname)
Definition: Component.h:30
CTexturePtr m_TextureBase
Definition: Overlay.h:84
A single textured quad overlay, intended for entities that move around much, like units (e...
float g
Definition: Overlay.h:57
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
Definition: Overlay.h:36
float X
Definition: Vector2D.h:157
virtual void Serialize(ISerializer &serialize)
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
Definition: Terrain.h:40
Definition: Decompose.h:22
static bool ms_EnableDebugOverlays
const std::string ToUTF8() const
Returns the content of this node as an 8-bit string.
Definition: ParamNode.cpp:203
virtual void Deserialize(const CParamNode &paramNode, IDeserializer &deserialize)
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
Definition: ParamNode.cpp:193
Definition: Overlay.h:34
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
Represents the filename and GL parameters of a texture, for passing to CTextureManager::CreateTexture...
Add renderable objects to the scene collector.
Definition: MessageTypes.h:145
void PushCoords(const float x, const float z)
Definition: Overlay.h:124
virtual CFixedVector3D GetRotation()=0
Returns the current rotation (relative to the upwards axis), as Euler angles with X=pitch...
bool m_AlwaysVisible
Should this line be rendered fully visible at all times, even under the SoD?
Definition: Overlay.h:96
CColor m_Color
Definition: Overlay.h:154
float GetExactGroundLevel(float x, float z) const
Definition: Terrain.cpp:353
void UpdateDynamicOverlay(float frameOffset)
Called from the interpolation handler; responsible for ensuring the dynamic overlay (provided we&#39;re u...
virtual bool IsEditorOnly()
Returns true if the entity is only selectable in Atlas editor, e.g.
void RenderSubmit(SceneCollector &collector)
virtual void SetSelectionHighlight(CColor color, bool selected)
Set the selection highlight state.
bool m_Selected
Whether the parent entity is selected (caches GUI&#39;s selection state).
virtual CBoundingBoxOriented GetSelectionBox()=0
Get the oriented world-space bounding box of the object&#39;s visual representation, clipped at the Y=0 p...
virtual bool IsInWorld()=0
Returns true if the entity currently exists at a defined position in the world.
SOverlayQuad * m_UnitOverlay
static float QuartOut(float t, const float b, const float c, const float d)
Definition: Ease.h:111
void UpdateStaticOverlay()
Called from RenderSubmit if using a static outline; responsible for ensuring that the static overlay ...
bool m_Cached
Whether the selectable&#39;s player colour has been cached for rendering.
float m_FadeProgress
Linear time progress of the fade, between 0 and m_FadeDuration.
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:24
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
Definition: MessageTypes.h:138
This interface accepts renderable objects.
Definition: Scene.h:82
#define g_Renderer
Definition: Renderer.h:61
CEntityHandle GetEntityHandle() const
Definition: IComponent.h:45
void InvalidateStaticOverlay()
Explicitly invalidates the static overlay.
const char * c_str() const
Returns null-terminated string.
Definition: CStrIntern.cpp:140
#define ENSURE(expr)
ensure the expression &lt;expr&gt; evaluates to non-zero.
Definition: debug.h:282
virtual int GetType() const =0
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
Definition: ParamNode.cpp:185
float b
Definition: Overlay.h:57
CTexturePtr m_Texture
Definition: Overlay.h:151
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain...
Definition: Overlay.h:62
bool m_Closed
Should this line be treated as a closed loop? If set, any end cap settings are ignored.
Definition: Overlay.h:94
Interned 8-bit strings.
Definition: CStrIntern.h:37
float ToFloat() const
Parses the content of this node as a floating-point number.
Definition: ParamNode.cpp:227
void SubdividePoints(std::vector< CVector2D > &points, float maxSegmentLength, bool closed)
Subdivides a list of points into segments of maximum length maxSegmentLength that are of equal size b...
Definition: Render.cpp:534
void AngularStepFromChordLen(const float maxChordLength, const float radius, float &out_stepAngle, unsigned &out_numSteps)
Computes angular step parameters out_stepAngle and out_numSteps, given a maxChordLength on a circle o...
Definition: Render.cpp:525
virtual entity_id_t GetPlayerByID(int32_t id)=0
float ToFloat() const
Convert to float. May be lossy - float can&#39;t represent all values.
Definition: Fixed.h:161
virtual CFixedVector2D GetPosition2D()=0
Returns the current x,z position (no interpolation).
#define SAFE_DELETE(p)
delete memory ensuing from new and set the pointer to zero (thus making double-frees safe / a no-op) ...
float a
Definition: Overlay.h:57
virtual player_id_t GetOwner()=0
CColor m_Color
Color to apply to the line texture, where indicated by the mask.
Definition: Overlay.h:88
float offset
Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns...
Definition: MessageTypes.h:136
virtual float GetExactWaterLevel(float x, float z)=0
Get the current water level at the given point.
static const float RGB_DESATURATION
SOverlayLine * m_DebugSelectionBoxOverlay
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
Definition: Component.h:44
static const float MIN_ALPHA_ALWAYS_VISIBLE
const CSimContext & GetSimContext() const
Definition: IComponent.h:52
static bool IsInitialised()
Definition: Singleton.h:63
CTexturePtr m_TextureMask
Definition: Overlay.h:85
virtual void Init(const CParamNode &paramNode)
A simplified syntax for accessing entity components.
Definition: CmpPtr.h:55
virtual void GetInterpolatedPosition2D(float frameOffset, float &x, float &z, float &rotY)=0
Get the current interpolated 2D position and orientation, for rendering.
float Y
Definition: Vector2D.h:157
virtual CTerrain * GetCTerrain()=0
CEntityHandle GetSystemEntity() const
Definition: IComponent.h:50
Helper functions related to rendering.
A more complex textured line overlay, composed of several textured line segments. ...
Rectangular single-quad terrain overlay, in world space coordinates.
Definition: Overlay.h:149
CColor m_Color
Current selection overlay color. Alpha component is subject to fading.
virtual void SetVisibility(bool visible)
Enables or disables rendering of an entity&#39;s selectable.
u8 m_Thickness
Definition: Overlay.h:42
float m_AlphaMin
Minimum value for current selection overlay alpha.
SceneCollector & collector
Definition: MessageTypes.h:155
virtual CBoundingBoxAligned GetBounds()=0
Get the world-space bounding box of the object&#39;s visual representation.
SOverlayDescriptor m_OverlayDescriptor
virtual void HandleMessage(const CMessage &msg, bool global)
SOverlayLine * m_DebugBoundingBoxOverlay
virtual void GetShape(EShape &shape, entity_pos_t &size0, entity_pos_t &size1, entity_pos_t &height)=0
Return the shape of this footprint.
const CSimContext * m_SimContext
Simulation context applicable for this overlay line; used to obtain terrain information during automa...
Definition: Overlay.h:105
Prepare for rendering a new frame (set up model positions etc).
Definition: MessageTypes.h:122
float m_FadeBaselineAlpha
Baseline alpha value to start fading from. Constant during a single fade.
float m_Thickness
Half-width of the line, in world-space units.
Definition: Overlay.h:92
CColor m_Color
Definition: Overlay.h:40
void ConstructBoxOutline(const CBoundingBoxOriented &box, SOverlayLine &overlayLine)
Constructs a solid outline of an arbitrarily-aligned bounding box.
Definition: Render.cpp:190
float m_FadeDeltaAlpha
Delta between target and baseline alpha. Constant during a single fade. Can be positive or negative...
static const float MIN_ALPHA_UNSELECTED
void SetWrap(GLint wrap)
Set wrapping mode (typically GL_REPEAT, GL_CLAMP_TO_EDGE, etc).
virtual void Submit(CPatch *patch)=0
Submit a terrain patch that is part of the scene.
static const player_id_t INVALID_PLAYER
Definition: Player.h:26
virtual void Deinit()
SOverlayTexturedLine * m_BuildingOverlay
float r
Definition: Overlay.h:57
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:34
CTexturePtr m_TextureMask
Definition: Overlay.h:152