Changed ColliderBound to CollisionShape because ColliderBound sounds weird

This commit is contained in:
Diren D Bharwani 2022-10-28 14:29:05 +08:00
parent 4fc87866ee
commit 1a4b15feb2
4 changed files with 59 additions and 59 deletions

View File

@ -417,13 +417,13 @@ namespace SHADE
( (
DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_LIB_NAME,
DEFAULT_CSHARP_NAMESPACE + ".Collider", DEFAULT_CSHARP_NAMESPACE + ".Collider",
"OnColliderBoundChanged" "OnCollisionShapeChanged"
); );
csColliderOnRemoved = dotNet.GetFunctionPtr<CsEventRelayFuncPtr> csColliderOnRemoved = dotNet.GetFunctionPtr<CsEventRelayFuncPtr>
( (
DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_LIB_NAME,
DEFAULT_CSHARP_NAMESPACE + ".Collider", DEFAULT_CSHARP_NAMESPACE + ".Collider",
"OnColliderRemoved" "OnCollisionShapeRemoved"
); );
csEditorRenderScripts = dotNet.GetFunctionPtr<CsScriptEditorFuncPtr> csEditorRenderScripts = dotNet.GetFunctionPtr<CsScriptEditorFuncPtr>
( (

View File

@ -22,7 +22,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* ColliderBound - Constructors */ /* ColliderBound - Constructors */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
ColliderBound::ColliderBound(int arrayIdx, Entity attachedEntity) CollisionShape::CollisionShape(int arrayIdx, Entity attachedEntity)
: arrayIndex { arrayIdx } : arrayIndex { arrayIdx }
, entity { attachedEntity } , entity { attachedEntity }
{} {}
@ -30,7 +30,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* ColliderBound - Setter Functions */ /* ColliderBound - Setter Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void ColliderBound::updateArrayIndex(int index) void CollisionShape::updateArrayIndex(int index)
{ {
arrayIndex = index; arrayIndex = index;
} }
@ -38,42 +38,42 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* BoxColliderBound - Constructors */ /* BoxColliderBound - Constructors */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
BoxColliderBound::BoxColliderBound(int arrayIdx, Entity attachedEntity) BoxCollider::BoxCollider(int arrayIdx, Entity attachedEntity)
: ColliderBound { arrayIndex, attachedEntity } : CollisionShape { arrayIndex, attachedEntity }
{} {}
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* BoxColliderBound - Properties */ /* BoxColliderBound - Properties */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
Vector3 BoxColliderBound::Center::get() Vector3 BoxCollider::Center::get()
{ {
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetCenter()); return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetCenter());
} }
void BoxColliderBound::Center::set(Vector3 value) void BoxCollider::Center::set(Vector3 value)
{ {
getNativeBoundObject<SHBoundingBox>().SetCenter(Convert::ToNative(value)); getNativeBoundObject<SHBoundingBox>().SetCenter(Convert::ToNative(value));
} }
Vector3 BoxColliderBound::HalfExtents::get() Vector3 BoxCollider::HalfExtents::get()
{ {
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetHalfExtents()); return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetHalfExtents());
} }
void BoxColliderBound::HalfExtents::set(Vector3 value) void BoxCollider::HalfExtents::set(Vector3 value)
{ {
getNativeBoundObject<SHBoundingBox>().SetHalfExtents(Convert::ToNative(value)); getNativeBoundObject<SHBoundingBox>().SetHalfExtents(Convert::ToNative(value));
} }
Vector3 BoxColliderBound::Min::get() Vector3 BoxCollider::Min::get()
{ {
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetMin()); return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetMin());
} }
void BoxColliderBound::Min::set(Vector3 value) void BoxCollider::Min::set(Vector3 value)
{ {
getNativeBoundObject<SHBoundingBox>().SetMin(Convert::ToNative(value)); getNativeBoundObject<SHBoundingBox>().SetMin(Convert::ToNative(value));
} }
Vector3 BoxColliderBound::Max::get() Vector3 BoxCollider::Max::get()
{ {
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetMax()); return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetMax());
} }
void BoxColliderBound::Max::set(Vector3 value) void BoxCollider::Max::set(Vector3 value)
{ {
getNativeBoundObject<SHBoundingBox>().SetMax(Convert::ToNative(value)); getNativeBoundObject<SHBoundingBox>().SetMax(Convert::ToNative(value));
} }
@ -81,11 +81,11 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* BoxColliderBound - Usage Functions */ /* BoxColliderBound - Usage Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
bool BoxColliderBound::TestPoint(Vector3 point) bool BoxCollider::TestPoint(Vector3 point)
{ {
return getNativeBoundObject<SHBoundingBox>().TestPoint(Convert::ToNative(point)); return getNativeBoundObject<SHBoundingBox>().TestPoint(Convert::ToNative(point));
} }
bool BoxColliderBound::Raycast(Ray ray, float maxDistance) bool BoxCollider::Raycast(Ray ray, float maxDistance)
{ {
return getNativeBoundObject<SHBoundingBox>().Raycast(Convert::ToNative(ray), maxDistance); return getNativeBoundObject<SHBoundingBox>().Raycast(Convert::ToNative(ray), maxDistance);
} }
@ -93,19 +93,19 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* BoxColliderBound - Properties */ /* BoxColliderBound - Properties */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
Vector3 SphereColliderBound::Center::get() Vector3 SphereCollider::Center::get()
{ {
return Convert::ToCLI(getNativeBoundObject<SHBoundingSphere>().GetCenter()); return Convert::ToCLI(getNativeBoundObject<SHBoundingSphere>().GetCenter());
} }
void SphereColliderBound::Center::set(Vector3 value) void SphereCollider::Center::set(Vector3 value)
{ {
getNativeBoundObject<SHBoundingSphere>().SetCenter(Convert::ToNative(value)); getNativeBoundObject<SHBoundingSphere>().SetCenter(Convert::ToNative(value));
} }
float SphereColliderBound::Radius::get() float SphereCollider::Radius::get()
{ {
return getNativeBoundObject<SHBoundingSphere>().GetRadius(); return getNativeBoundObject<SHBoundingSphere>().GetRadius();
} }
void SphereColliderBound::Radius::set(float value) void SphereCollider::Radius::set(float value)
{ {
getNativeBoundObject<SHBoundingSphere>().SetRadius(value); getNativeBoundObject<SHBoundingSphere>().SetRadius(value);
} }
@ -113,11 +113,11 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* SphereColliderBound - Usage Functions */ /* SphereColliderBound - Usage Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
bool SphereColliderBound::TestPoint(Vector3 point) bool SphereCollider::TestPoint(Vector3 point)
{ {
return getNativeBoundObject<SHBoundingBox>().TestPoint(Convert::ToNative(point)); return getNativeBoundObject<SHBoundingBox>().TestPoint(Convert::ToNative(point));
} }
bool SphereColliderBound::Raycast(Ray ray, float maxDistance) bool SphereCollider::Raycast(Ray ray, float maxDistance)
{ {
return getNativeBoundObject<SHBoundingBox>().Raycast(Convert::ToNative(ray), maxDistance); return getNativeBoundObject<SHBoundingBox>().Raycast(Convert::ToNative(ray), maxDistance);
} }
@ -125,8 +125,8 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* SphereColliderBound - Constructors */ /* SphereColliderBound - Constructors */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SphereColliderBound::SphereColliderBound(int arrayIndex, Entity attachedEntity) SphereCollider::SphereCollider(int arrayIndex, Entity attachedEntity)
: ColliderBound{ arrayIndex, attachedEntity } : CollisionShape{ arrayIndex, attachedEntity }
{} {}
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -137,7 +137,7 @@ namespace SHADE
{ {
// Create lists if they don't exist // Create lists if they don't exist
if (colliders == nullptr) if (colliders == nullptr)
colliders = gcnew CollidersMap; colliders = gcnew ColliderMap;
if (!colliders->ContainsKey(entity)) if (!colliders->ContainsKey(entity))
colliders->Add(entity, gcnew WeakReferenceList()); colliders->Add(entity, gcnew WeakReferenceList());
@ -148,7 +148,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Collider - Properties */ /* Collider - Properties */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
int Collider::ColliderBoundsCount::get() int Collider::CollisionShapeCount::get()
{ {
return static_cast<int>(GetNativeComponent()->GetColliders().size()); return static_cast<int>(GetNativeComponent()->GetColliders().size());
} }
@ -156,7 +156,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Collider - ColliderBound Functions */ /* Collider - ColliderBound Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
ColliderBound^ Collider::GetColliderBound(int index) CollisionShape^ Collider::GetCollisionShape(int index)
{ {
// Populate the list if it hasn't been // Populate the list if it hasn't been
if (subColliderList == nullptr) if (subColliderList == nullptr)
@ -172,15 +172,15 @@ namespace SHADE
return subColliderList[index]; return subColliderList[index];
} }
generic<typename T> generic<typename T>
T Collider::GetColliderBound(int index) T Collider::GetCollisionShape(int index)
{ {
return safe_cast<T>(GetColliderBound(index)); return safe_cast<T>(GetCollisionShape(index));
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Event Handling Functions */ /* Event Handling Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void Collider::OnColliderRemoved(EntityID entity) void Collider::OnCollisionShapeRemoved(EntityID entity)
{ {
SAFE_NATIVE_CALL_BEGIN SAFE_NATIVE_CALL_BEGIN
// Check if there are any colliders to update // Check if there are any colliders to update
@ -192,7 +192,7 @@ namespace SHADE
SAFE_NATIVE_CALL_END("Collider.OnColliderRemoved") SAFE_NATIVE_CALL_END("Collider.OnColliderRemoved")
} }
void Collider::OnColliderBoundChanged(EntityID entity) void Collider::OnCollisionShapeChanged(EntityID entity)
{ {
SAFE_NATIVE_CALL_BEGIN SAFE_NATIVE_CALL_BEGIN
// Check if there are any colliders to update // Check if there are any colliders to update
@ -226,20 +226,20 @@ namespace SHADE
if (subColliderList) if (subColliderList)
subColliderList->Clear(); subColliderList->Clear();
else else
subColliderList = gcnew System::Collections::Generic::List<ColliderBound^>(); subColliderList = gcnew System::Collections::Generic::List<CollisionShape^>();
// Populate the list // Populate the list
int i = 0; int i = 0;
for (const auto& collider : GetNativeComponent()->GetColliders()) for (const auto& collider : GetNativeComponent()->GetColliders())
{ {
ColliderBound^ bound = nullptr; CollisionShape^ bound = nullptr;
switch (collider.GetType()) switch (collider.GetType())
{ {
case SHCollider::Type::BOX: case SHCollider::Type::BOX:
bound = gcnew BoxColliderBound(i, Owner.GetEntity()); bound = gcnew BoxCollider(i, Owner.GetEntity());
break; break;
case SHCollider::Type::SPHERE: case SHCollider::Type::SPHERE:
bound = gcnew SphereColliderBound(i, Owner.GetEntity()); bound = gcnew SphereCollider(i, Owner.GetEntity());
break; break;
case SHCollider::Type::CAPSULE: case SHCollider::Type::CAPSULE:
// TODO // TODO

View File

@ -18,8 +18,8 @@ of DigiPen Institute of Technology is prohibited.
#include "Component.hxx" #include "Component.hxx"
namespace SHADE namespace SHADE
{ {
template<typename ColliderBoundType> template<typename CollisionShapeType>
ColliderBoundType& SHADE::ColliderBound::getNativeBoundObject() CollisionShapeType& SHADE::CollisionShape::getNativeBoundObject()
{ {
SHColliderComponent* collider = SHComponentManager::GetComponent_s<SHColliderComponent>(entity); SHColliderComponent* collider = SHComponentManager::GetComponent_s<SHColliderComponent>(entity);
if (!collider) if (!collider)
@ -31,7 +31,7 @@ namespace SHADE
if (bounds.GetType() != SHCollider::Type::BOX) if (bounds.GetType() != SHCollider::Type::BOX)
throw gcnew System::InvalidOperationException("Attempted to retrieve invalid ColliderBound."); throw gcnew System::InvalidOperationException("Attempted to retrieve invalid ColliderBound.");
return reinterpret_cast<ColliderBoundType&>(bounds); return reinterpret_cast<CollisionShapeType&>(bounds);
} }
catch (std::invalid_argument&) catch (std::invalid_argument&)
{ {

View File

@ -27,7 +27,7 @@ namespace SHADE
/// <summary> /// <summary>
/// Base interface for all Collider Shapes. /// Base interface for all Collider Shapes.
/// </summary> /// </summary>
public ref class ColliderBound public ref class CollisionShape
{ {
public: public:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -51,7 +51,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Constructors */ /* Constructors */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
ColliderBound(int arrayIdx, Entity attachedEntity); CollisionShape(int arrayIdx, Entity attachedEntity);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Data Members */ /* Data Members */
@ -62,8 +62,8 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
template<typename ColliderBoundType> template<typename CollisionShapeType>
ColliderBoundType& getNativeBoundObject(); CollisionShapeType& getNativeBoundObject();
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -75,7 +75,7 @@ namespace SHADE
/// <summary> /// <summary>
/// Box-shaped Collider Bound. /// Box-shaped Collider Bound.
/// </summary> /// </summary>
public ref class BoxColliderBound : public ColliderBound public ref class BoxCollider : public CollisionShape
{ {
public: public:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -128,13 +128,13 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Constructors */ /* Constructors */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
BoxColliderBound(int arrayIndex, Entity attachedEntity); BoxCollider(int arrayIndex, Entity attachedEntity);
}; };
/// <summary> /// <summary>
/// Sphere-shaped Collider Bound. /// Sphere-shaped Collider Bound.
/// </summary> /// </summary>
public ref class SphereColliderBound : public ColliderBound public ref class SphereCollider : public CollisionShape
{ {
public: public:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -169,7 +169,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Constructors */ /* Constructors */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
SphereColliderBound(int arrayIndex, Entity attachedEntity); SphereCollider(int arrayIndex, Entity attachedEntity);
}; };
/// <summary> /// <summary>
@ -196,7 +196,7 @@ namespace SHADE
/// <summary> /// <summary>
/// Total number of ColliderBounds in the Collider component. /// Total number of ColliderBounds in the Collider component.
/// </summary> /// </summary>
property int ColliderBoundsCount property int CollisionShapeCount
{ {
int get(); int get();
} }
@ -209,7 +209,7 @@ namespace SHADE
/// </summary> /// </summary>
/// <param name="index">Index to retrieve a ColliderBound from.</param> /// <param name="index">Index to retrieve a ColliderBound from.</param>
/// <returns>ColliderBound for the specified index.</returns> /// <returns>ColliderBound for the specified index.</returns>
ColliderBound^ GetColliderBound(int index); CollisionShape^ GetCollisionShape(int index);
/// <summary> /// <summary>
/// Retrieves a ColliderBound at the specified index in the ColliderBound list /// Retrieves a ColliderBound at the specified index in the ColliderBound list
/// and casts it to the appropriate type. /// and casts it to the appropriate type.
@ -217,42 +217,42 @@ namespace SHADE
/// <typeparam name="T">Type of the ColliderBound to cast to.</typeparam> /// <typeparam name="T">Type of the ColliderBound to cast to.</typeparam>
/// <param name="index">Index to retrieve a ColliderBound from.</param> /// <param name="index">Index to retrieve a ColliderBound from.</param>
/// <returns>ColliderBound for the specified index.</returns> /// <returns>ColliderBound for the specified index.</returns>
generic<typename T> where T:ColliderBound generic<typename T> where T:CollisionShape
T GetColliderBound(int index); T GetCollisionShape(int index);
internal: internal:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Event Handling Functions */ /* Event Handling Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/// <summary> /// <summary>
/// To be called from native code when a collider has been removed. /// To be called from native code when a collision shape has been removed.
/// </summary> /// </summary>
/// <param name="entity">The entity which has it's collider removed.</param> /// <param name="entity">The entity which has it's collision shape removed.</param>
static void OnColliderRemoved(EntityID entity); static void OnCollisionShapeRemoved(EntityID entity);
/// <summary> /// <summary>
/// To be called from native code when a Collider bound has been removed. /// To be called from native code when a Collision Shape has been changed.
/// </summary> /// </summary>
/// <param name="entity"> /// <param name="entity">
/// The entity which has it's collider bounds changed. /// The entity which has it's collision shape changed.
/// </param> /// </param>
static void OnColliderBoundChanged(EntityID entity); static void OnCollisionShapeChanged(EntityID entity);
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Type Definitions */ /* Type Definitions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
using WeakReferenceList = System::Collections::Generic::List<System::WeakReference^>; using WeakReferenceList = System::Collections::Generic::List<System::WeakReference^>;
using CollidersMap = System::Collections::Generic::Dictionary<EntityID, WeakReferenceList^>; using ColliderMap = System::Collections::Generic::Dictionary<EntityID, WeakReferenceList^>;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Static Data Members */ /* Static Data Members */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
static CollidersMap^ colliders; static ColliderMap^ colliders;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Data Members */ /* Data Members */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
System::Collections::Generic::List<ColliderBound^>^ subColliderList; System::Collections::Generic::List<CollisionShape^>^ subColliderList;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */