Index: source/simulation2/components/CCmpSelectable.cpp
===================================================================
--- source/simulation2/components/CCmpSelectable.cpp
+++ source/simulation2/components/CCmpSelectable.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2019 Wildfire Games.
+/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -107,9 +107,36 @@
""
""
""
- "";
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "0.0"
+ ""
+ ""
+ ""
+ ""
+ "0.0"
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "0.0"
+ ""
+ ""
+ ""
+ ""
+ "";
}
+ EShape m_Shape;
+ entity_pos_t m_Size0; // width/radius
+ entity_pos_t m_Size1; // height/radius
+
virtual void Init(const CParamNode& paramNode)
{
m_EditorOnly = paramNode.GetChild("EditorOnly").IsOk();
@@ -145,6 +172,22 @@
m_OverlayDescriptor.m_LineThickness = outlineNode.GetChild("LineThickness").ToFloat();
}
+ if (paramNode.GetChild("Square").IsOk())
+ {
+ m_Shape = SQUARE;
+ m_Size0 = paramNode.GetChild("Square").GetChild("@width").ToFixed();
+ m_Size1 = paramNode.GetChild("Square").GetChild("@depth").ToFixed();
+ }
+ else if (paramNode.GetChild("Circle").IsOk())
+ {
+ m_Shape = CIRCLE;
+ m_Size0 = m_Size1 = paramNode.GetChild("Circle").GetChild("@radius").ToFixed();
+ }
+ else
+ {
+ m_Shape = NONE;
+ }
+
m_EnabledInterpolate = false;
m_EnabledRenderSubmit = false;
UpdateMessageSubscriptions();
@@ -218,7 +261,7 @@
void RenderSubmit(SceneCollector& collector, const CFrustum& frustum, bool culling);
/**
- * Draw a textured line overlay. The selection overlays for structures are based solely on footprint shape.
+ * Draw a textured line overlay.
*/
void UpdateTexturedLineOverlay(const SOverlayDescriptor* overlayDescriptor, SOverlayTexturedLine& overlay, float frameOffset);
@@ -427,14 +470,18 @@
return;
CmpPtr cmpPosition(GetEntityHandle());
- CmpPtr cmpFootprint(GetEntityHandle());
- if (!cmpFootprint || !cmpPosition || !cmpPosition->IsInWorld())
+ if (!cmpPosition || !cmpPosition->IsInWorld())
return;
- ICmpFootprint::EShape fpShape;
- entity_pos_t fpSize0_fixed, fpSize1_fixed, fpHeight_fixed;
- cmpFootprint->GetShape(fpShape, fpSize0_fixed, fpSize1_fixed, fpHeight_fixed);
-
+ ICmpFootprint::EShape shape;
+ if (m_Shape == ICmpSelectable::NONE)
+ {
+ CmpPtr cmpFootprint(GetEntityHandle());
+ if (!cmpFootprint)
+ return;
+ entity_pos_t h;
+ cmpFootprint->GetShape(shape, m_Size0, m_Size1, h);
+ }
float rotY;
CVector2D origin;
cmpPosition->GetInterpolatedPosition2D(frameOffset, origin.X, origin.Y, rotY);
@@ -443,10 +490,10 @@
overlay.m_Color = m_Color;
overlay.CreateOverlayTexture(overlayDescriptor);
- if (fpShape == ICmpFootprint::SQUARE)
- SimRender::ConstructTexturedLineBox(overlay, origin, cmpPosition->GetRotation(), fpSize0_fixed.ToFloat(), fpSize1_fixed.ToFloat());
+ if (m_Shape == ICmpSelectable::SQUARE || shape == ICmpFootprint::SQUARE)
+ SimRender::ConstructTexturedLineBox(overlay, origin, cmpPosition->GetRotation(), m_Size0.ToFloat(), m_Size1.ToFloat());
else
- SimRender::ConstructTexturedLineCircle(overlay, origin, fpSize0_fixed.ToFloat());
+ SimRender::ConstructTexturedLineCircle(overlay, origin, m_Size0.ToFloat());
}
void CCmpSelectable::UpdateDynamicOverlay(float frameOffset)
@@ -462,10 +509,19 @@
return;
CmpPtr cmpPosition(GetEntityHandle());
- CmpPtr cmpFootprint(GetEntityHandle());
- if (!cmpFootprint || !cmpPosition || !cmpPosition->IsInWorld())
+ if (!cmpPosition || !cmpPosition->IsInWorld())
return;
+ ICmpFootprint::EShape shape;
+ if (m_Shape == ICmpSelectable::NONE)
+ {
+ CmpPtr cmpFootprint(GetEntityHandle());
+ if (!cmpFootprint)
+ return;
+ entity_pos_t h;
+ cmpFootprint->GetShape(shape, m_Size0, m_Size1, h);
+ }
+
float rotY;
CVector2D position;
cmpPosition->GetInterpolatedPosition2D(frameOffset, position.X, position.Y, rotY);
@@ -477,10 +533,6 @@
CTerrain* terrain = cmpTerrain->GetCTerrain();
ENSURE(terrain);
- ICmpFootprint::EShape fpShape;
- entity_pos_t fpSize0_fixed, fpSize1_fixed, fpHeight_fixed;
- cmpFootprint->GetShape(fpShape, fpSize0_fixed, fpSize1_fixed, fpHeight_fixed);
-
// ---------------------------------------------------------------------------------
if (!m_UnitOverlay)
@@ -510,9 +562,9 @@
CVector2D unitX(c, s);
CVector2D unitZ(-s, c);
- float halfSizeX = fpSize0_fixed.ToFloat();
- float halfSizeZ = fpSize1_fixed.ToFloat();
- if (fpShape == ICmpFootprint::SQUARE)
+ float halfSizeX = m_Size0.ToFloat();
+ float halfSizeZ = m_Size1.ToFloat();
+ if (m_Shape == ICmpSelectable::SQUARE || shape == ICmpFootprint::SQUARE)
{
halfSizeX /= 2.0f;
halfSizeZ /= 2.0f;
Index: source/simulation2/components/ICmpSelectable.h
===================================================================
--- source/simulation2/components/ICmpSelectable.h
+++ source/simulation2/components/ICmpSelectable.h
@@ -25,6 +25,12 @@
class ICmpSelectable : public IComponent
{
public:
+ enum EShape
+ {
+ NONE,
+ CIRCLE,
+ SQUARE
+ };
/**
* Returns true if the entity is only selectable in Atlas editor, e.g. a decorative visual actor.
*/