Move Position.h to a better location.
Update some files I forgot in previous commits. This was SVN commit r7361.
This commit is contained in:
parent
18b5a7f17c
commit
baead3409e
@ -22,8 +22,7 @@
|
||||
#include "simulation2/system/Entity.h"
|
||||
#include "simulation2/system/Message.h"
|
||||
|
||||
#include "simulation2/system/Position.h"
|
||||
#include "maths/Fixed.h"
|
||||
#include "simulation2/helpers/Position.h"
|
||||
|
||||
#define DEFAULT_MESSAGE_IMPL(name) \
|
||||
virtual EMessageTypeId GetType() const { return MT_##name; } \
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "ICmpObstruction.h"
|
||||
|
||||
#include "ICmpFootprint.h"
|
||||
#include "ICmpPathfinder.h"
|
||||
#include "ICmpObstructionManager.h"
|
||||
|
||||
#include "simulation2/MessageTypes.h"
|
||||
|
||||
@ -40,10 +40,21 @@ public:
|
||||
|
||||
DEFAULT_COMPONENT_ALLOCATOR(Obstruction)
|
||||
|
||||
ICmpPathfinder::tag_t m_Tag;
|
||||
const CSimContext* m_Context;
|
||||
|
||||
virtual void Init(const CSimContext& UNUSED(context), const CParamNode& UNUSED(paramNode))
|
||||
bool m_Active; // whether the obstruction is obstructing or just an inactive placeholder
|
||||
|
||||
ICmpObstructionManager::tag_t m_Tag;
|
||||
|
||||
virtual void Init(const CSimContext& context, const CParamNode& paramNode)
|
||||
{
|
||||
m_Context = &context;
|
||||
|
||||
if (paramNode.GetChild("Inactive").IsOk())
|
||||
m_Active = false;
|
||||
else
|
||||
m_Active = true;
|
||||
|
||||
m_Tag = 0;
|
||||
}
|
||||
|
||||
@ -53,14 +64,14 @@ public:
|
||||
|
||||
virtual void Serialize(ISerializer& UNUSED(serialize))
|
||||
{
|
||||
// TODO: Coordinate with CCmpPathfinder serialisation
|
||||
// TODO: Coordinate with CCmpObstructionManager serialisation
|
||||
}
|
||||
|
||||
virtual void Deserialize(const CSimContext& context, const CParamNode& paramNode, IDeserializer& UNUSED(deserialize))
|
||||
{
|
||||
Init(context, paramNode);
|
||||
|
||||
// TODO: Coordinate with CCmpPathfinder serialisation
|
||||
// TODO: Coordinate with CCmpObstructionManager serialisation
|
||||
}
|
||||
|
||||
virtual void HandleMessage(const CSimContext& context, const CMessage& msg, bool UNUSED(global))
|
||||
@ -69,18 +80,21 @@ public:
|
||||
{
|
||||
case MT_PositionChanged:
|
||||
{
|
||||
if (!m_Active)
|
||||
break;
|
||||
|
||||
const CMessagePositionChanged& data = static_cast<const CMessagePositionChanged&> (msg);
|
||||
|
||||
if (!data.inWorld && !m_Tag)
|
||||
break; // nothing to do
|
||||
break; // nothing needs to change
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(context, SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(context, SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
break;
|
||||
|
||||
if (data.inWorld && m_Tag)
|
||||
{
|
||||
cmpPathfinder->MoveShape(m_Tag, data.x, data.z, data.a);
|
||||
cmpObstructionManager->MoveShape(m_Tag, data.x, data.z, data.a);
|
||||
}
|
||||
else if (data.inWorld && !m_Tag)
|
||||
{
|
||||
@ -95,13 +109,13 @@ public:
|
||||
cmpFootprint->GetShape(shape, size0, size1, height);
|
||||
|
||||
if (shape == ICmpFootprint::SQUARE)
|
||||
m_Tag = cmpPathfinder->AddSquare(data.x, data.z, data.a, size0, size1);
|
||||
m_Tag = cmpObstructionManager->AddSquare(data.x, data.z, data.a, size0, size1);
|
||||
else
|
||||
m_Tag = cmpPathfinder->AddCircle(data.x, data.z, size0);
|
||||
m_Tag = cmpObstructionManager->AddCircle(data.x, data.z, size0);
|
||||
}
|
||||
else if (!data.inWorld && m_Tag)
|
||||
{
|
||||
cmpPathfinder->RemoveShape(m_Tag);
|
||||
cmpObstructionManager->RemoveShape(m_Tag);
|
||||
m_Tag = 0;
|
||||
}
|
||||
break;
|
||||
@ -110,17 +124,44 @@ public:
|
||||
{
|
||||
if (m_Tag)
|
||||
{
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(context, SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(context, SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
break;
|
||||
|
||||
cmpPathfinder->RemoveShape(m_Tag);
|
||||
cmpObstructionManager->RemoveShape(m_Tag);
|
||||
m_Tag = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool CheckCollisions()
|
||||
{
|
||||
CmpPtr<ICmpFootprint> cmpFootprint(*m_Context, GetEntityId());
|
||||
if (cmpFootprint.null())
|
||||
return false;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(*m_Context, GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
return false;
|
||||
|
||||
ICmpFootprint::EShape shape;
|
||||
entity_pos_t size0, size1, height;
|
||||
cmpFootprint->GetShape(shape, size0, size1, height);
|
||||
|
||||
CFixedVector3D pos = cmpPosition->GetPosition();
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(*m_Context, SYSTEM_ENTITY);
|
||||
|
||||
SkipTagObstructionFilter filter(m_Tag); // ignore collisions with self
|
||||
|
||||
if (shape == ICmpFootprint::SQUARE)
|
||||
return !cmpObstructionManager->TestSquare(filter, pos.X, pos.Z, cmpPosition->GetRotation().Y, size0, size1);
|
||||
else
|
||||
return !cmpObstructionManager->TestCircle(filter, pos.X, pos.Z, size0);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_COMPONENT_TYPE(Obstruction)
|
||||
|
@ -65,6 +65,11 @@ public:
|
||||
|
||||
return entity_pos_t::FromFloat(height);
|
||||
}
|
||||
|
||||
virtual float GetGroundLevel(float x, float z)
|
||||
{
|
||||
return m_Terrain->GetExactGroundLevel(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_COMPONENT_TYPE(Terrain)
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "simulation2/system/Interface.h"
|
||||
|
||||
#include "simulation2/system/Position.h"
|
||||
#include "simulation2/helpers/Position.h"
|
||||
|
||||
/**
|
||||
* Footprints - an approximation of the entity's shape, used for collision detection and for
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "simulation2/system/Interface.h"
|
||||
|
||||
#include "simulation2/system/Position.h"
|
||||
#include "simulation2/helpers/Position.h"
|
||||
#include "maths/FixedVector3D.h"
|
||||
|
||||
class CMatrix3D;
|
||||
|
Loading…
Reference in New Issue
Block a user