Changeset View
Changeset View
Standalone View
Standalone View
0ad/source/simulation2/components/CCmpPosition.cpp
Show First 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | if (serialize.IsDebug()) | ||||
anchor = "upright"; | anchor = "upright"; | ||||
break; | break; | ||||
} | } | ||||
serialize.StringASCII("anchor", anchor, 0, 16); | serialize.StringASCII("anchor", anchor, 0, 16); | ||||
} | } | ||||
serialize.NumberU32_Unbounded("turret parent", m_TurretParent); | serialize.NumberU32_Unbounded("turret parent", m_TurretParent); | ||||
if (m_TurretParent != INVALID_ENTITY) | if (m_TurretParent != INVALID_ENTITY) | ||||
{ | { | ||||
serialize.NumberFixed_Unbounded("x", m_TurretPosition.X); | serialize.NumberFixed_Unbounded("x", m_TurretPosition.getX()); | ||||
serialize.NumberFixed_Unbounded("y", m_TurretPosition.Y); | serialize.NumberFixed_Unbounded("y", m_TurretPosition.getY()); | ||||
serialize.NumberFixed_Unbounded("z", m_TurretPosition.Z); | serialize.NumberFixed_Unbounded("z", m_TurretPosition.getZ()); | ||||
} | } | ||||
} | } | ||||
virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) | virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) | ||||
{ | { | ||||
Init(paramNode); | Init(paramNode); | ||||
deserialize.Bool("in world", m_InWorld); | deserialize.Bool("in world", m_InWorld); | ||||
Show All 18 Lines | virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) | ||||
deserialize.NumberFixed_Unbounded("constructionprogress", m_ConstructionProgress); | deserialize.NumberFixed_Unbounded("constructionprogress", m_ConstructionProgress); | ||||
// TODO: should there be range checks on all these values? | // TODO: should there be range checks on all these values? | ||||
m_InterpolatedRotY = m_RotY.ToFloat(); | m_InterpolatedRotY = m_RotY.ToFloat(); | ||||
deserialize.NumberU32_Unbounded("turret parent", m_TurretParent); | deserialize.NumberU32_Unbounded("turret parent", m_TurretParent); | ||||
if (m_TurretParent != INVALID_ENTITY) | if (m_TurretParent != INVALID_ENTITY) | ||||
{ | { | ||||
deserialize.NumberFixed_Unbounded("x", m_TurretPosition.X); | deserialize.NumberFixed_Unbounded("x", m_TurretPosition.Xref()); | ||||
deserialize.NumberFixed_Unbounded("y", m_TurretPosition.Y); | deserialize.NumberFixed_Unbounded("y", m_TurretPosition.Yref()); | ||||
deserialize.NumberFixed_Unbounded("z", m_TurretPosition.Z); | deserialize.NumberFixed_Unbounded("z", m_TurretPosition.Zref()); | ||||
} | } | ||||
if (m_InWorld) | if (m_InWorld) | ||||
UpdateXZRotation(); | UpdateXZRotation(); | ||||
UpdateMessageSubscriptions(); | UpdateMessageSubscriptions(); | ||||
} | } | ||||
Show All 11 Lines | virtual void UpdateTurretPosition() | ||||
{ | { | ||||
LOGERROR("Turret with parent without position component"); | LOGERROR("Turret with parent without position component"); | ||||
return; | return; | ||||
} | } | ||||
if (!cmpPosition->IsInWorld()) | if (!cmpPosition->IsInWorld()) | ||||
MoveOutOfWorld(); | MoveOutOfWorld(); | ||||
else | else | ||||
{ | { | ||||
CFixedVector2D rotatedPosition = CFixedVector2D(m_TurretPosition.X, m_TurretPosition.Z); | CFixedVector2D rotatedPosition = CFixedVector2D(m_TurretPosition.getX(), m_TurretPosition.getZ()); | ||||
rotatedPosition = rotatedPosition.Rotate(cmpPosition->GetRotation().Y); | rotatedPosition = rotatedPosition.Rotate(cmpPosition->GetRotation().getY()); | ||||
CFixedVector2D rootPosition = cmpPosition->GetPosition2D(); | CFixedVector2D rootPosition = cmpPosition->GetPosition2D(); | ||||
entity_pos_t x = rootPosition.X + rotatedPosition.X; | entity_pos_t x = rootPosition.getX() + rotatedPosition.getX(); | ||||
entity_pos_t z = rootPosition.Y + rotatedPosition.Y; | entity_pos_t z = rootPosition.getY() + rotatedPosition.getY(); | ||||
if (!m_InWorld || m_X != x || m_Z != z) | if (!m_InWorld || m_X != x || m_Z != z) | ||||
MoveTo(x, z); | MoveTo(x, z); | ||||
entity_pos_t y = cmpPosition->GetHeightOffset() + m_TurretPosition.Y; | entity_pos_t y = cmpPosition->GetHeightOffset() + m_TurretPosition.getY(); | ||||
if (!m_InWorld || GetHeightOffset() != y) | if (!m_InWorld || GetHeightOffset() != y) | ||||
SetHeightOffset(y); | SetHeightOffset(y); | ||||
m_InWorld = true; | m_InWorld = true; | ||||
} | } | ||||
} | } | ||||
virtual std::set<entity_id_t>* GetTurrets() | virtual std::set<entity_id_t>* GetTurrets() | ||||
{ | { | ||||
return &m_Turrets; | return &m_Turrets; | ||||
} | } | ||||
virtual void SetTurretParent(entity_id_t id, const CFixedVector3D& offset) | virtual void SetTurretParent(entity_id_t id, const CFixedVector3D& offset) | ||||
{ | { | ||||
entity_angle_t angle = GetRotation().Y; | entity_angle_t angle = GetRotation().getY(); | ||||
if (m_TurretParent != INVALID_ENTITY) | if (m_TurretParent != INVALID_ENTITY) | ||||
{ | { | ||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
cmpPosition->GetTurrets()->erase(GetEntityId()); | cmpPosition->GetTurrets()->erase(GetEntityId()); | ||||
} | } | ||||
m_TurretParent = id; | m_TurretParent = id; | ||||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
virtual void TurnTo(entity_angle_t y) | virtual void TurnTo(entity_angle_t y) | ||||
{ | { | ||||
if (m_TurretParent != INVALID_ENTITY) | if (m_TurretParent != INVALID_ENTITY) | ||||
{ | { | ||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
y -= cmpPosition->GetRotation().Y; | y -= cmpPosition->GetRotation().getY(); | ||||
} | } | ||||
m_RotY = y; | m_RotY = y; | ||||
AdvertisePositionChanges(); | AdvertisePositionChanges(); | ||||
UpdateMessageSubscriptions(); | UpdateMessageSubscriptions(); | ||||
} | } | ||||
virtual void SetYRotation(entity_angle_t y) | virtual void SetYRotation(entity_angle_t y) | ||||
{ | { | ||||
if (m_TurretParent != INVALID_ENTITY) | if (m_TurretParent != INVALID_ENTITY) | ||||
{ | { | ||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
y -= cmpPosition->GetRotation().Y; | y -= cmpPosition->GetRotation().getY(); | ||||
} | } | ||||
m_RotY = y; | m_RotY = y; | ||||
m_InterpolatedRotY = m_RotY.ToFloat(); | m_InterpolatedRotY = m_RotY.ToFloat(); | ||||
if (m_InWorld) | if (m_InWorld) | ||||
{ | { | ||||
UpdateXZRotation(); | UpdateXZRotation(); | ||||
Show All 21 Lines | public: | ||||
virtual CFixedVector3D GetRotation() const | virtual CFixedVector3D GetRotation() const | ||||
{ | { | ||||
entity_angle_t y = m_RotY; | entity_angle_t y = m_RotY; | ||||
if (m_TurretParent != INVALID_ENTITY) | if (m_TurretParent != INVALID_ENTITY) | ||||
{ | { | ||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TurretParent); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
y += cmpPosition->GetRotation().Y; | y += cmpPosition->GetRotation().getY(); | ||||
} | } | ||||
return CFixedVector3D(m_RotX, y, m_RotZ); | return CFixedVector3D(m_RotX, y, m_RotZ); | ||||
} | } | ||||
virtual fixed GetDistanceTravelled() const | virtual fixed GetDistanceTravelled() const | ||||
{ | { | ||||
if (!m_InWorld) | if (!m_InWorld) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (m_TurretParent != INVALID_ENTITY) | ||||
m.SetIdentity(); | m.SetIdentity(); | ||||
return m; | return m; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
CMatrix3D parentTransformMatrix = cmpPosition->GetInterpolatedTransform(frameOffset); | CMatrix3D parentTransformMatrix = cmpPosition->GetInterpolatedTransform(frameOffset); | ||||
CMatrix3D ownTransformation = CMatrix3D(); | CMatrix3D ownTransformation = CMatrix3D(); | ||||
ownTransformation.SetYRotation(m_InterpolatedRotY); | ownTransformation.SetYRotation(m_InterpolatedRotY); | ||||
ownTransformation.Translate(-m_TurretPosition.X.ToFloat(), m_TurretPosition.Y.ToFloat(), -m_TurretPosition.Z.ToFloat()); | ownTransformation.Translate(-m_TurretPosition.getX().ToFloat(), m_TurretPosition.getY().ToFloat(), -m_TurretPosition.getZ().ToFloat()); | ||||
return parentTransformMatrix * ownTransformation; | return parentTransformMatrix * ownTransformation; | ||||
} | } | ||||
} | } | ||||
if (!m_InWorld) | if (!m_InWorld) | ||||
{ | { | ||||
LOGERROR("CCmpPosition::GetInterpolatedTransform called on entity when IsInWorld is false"); | LOGERROR("CCmpPosition::GetInterpolatedTransform called on entity when IsInWorld is false"); | ||||
CMatrix3D m; | CMatrix3D m; | ||||
m.SetIdentity(); | m.SetIdentity(); | ||||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator