Added Collision Tags #233

Merged
direnbharwani merged 10 commits from SP3-2-Physics into main 2022-11-20 22:40:53 +08:00
8 changed files with 399 additions and 277 deletions
Showing only changes of commit 4ebc16564a - Show all commits

View File

@ -0,0 +1,255 @@
/****************************************************************************************
* \file SHCollisionTagMatrix.cpp
* \author Diren D Bharwani, diren.dbharwani, 390002520
* \brief Implementation for Collision Tag Matrix for handling sets of Collision Tags.
*
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
* disclosure of this file or its contents without the prior written consent
* of DigiPen Institute of Technology is prohibited.
****************************************************************************************/
#include <SHpch.h>
#include <fstream>
// Primary Header
#include "SHCollisionTagMatrix.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Static Data Member Definitions */
/*-----------------------------------------------------------------------------------*/
SHCollisionTag SHCollisionTagMatrix::collisionTags[SHCollisionTag::NUM_LAYERS];
/*-----------------------------------------------------------------------------------*/
/* Getter Function Definitions */
/*-----------------------------------------------------------------------------------*/
const std::string& SHCollisionTagMatrix::GetTagName(int tagIndex)
{
if (tagIndex < 0 || tagIndex > SHCollisionTag::NUM_LAYERS)
throw std::invalid_argument("Index out of range!");
return collisionTags[tagIndex].GetName();
}
int SHCollisionTagMatrix::GetTagIndex(const std::string& tagName) noexcept
{
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
{
if (collisionTags[i].GetName() == tagName)
return i;
}
SHLOGV_WARNING("Collision Tag {} cannot be found!", tagName)
return -1;
}
/*-----------------------------------------------------------------------------------*/
/* Setter Function Definitions */
/*-----------------------------------------------------------------------------------*/
void SHCollisionTagMatrix::SetTagName(const std::string& oldTagName, const std::string& newTagName) noexcept
{
for (auto& collisionTag : collisionTags)
{
if (collisionTag.GetName() != oldTagName)
continue;
collisionTag.SetName(newTagName);
return;
}
SHLOGV_WARNING("Collision tag {} cannot be found!", oldTagName)
}
void SHCollisionTagMatrix::SetTag(const std::string& tagName, const SHCollisionTag& newTag) noexcept
{
for (auto& collisionTag : collisionTags)
{
if (collisionTag.GetName() != tagName)
continue;
collisionTag = newTag;
return;
}
SHLOGV_WARNING("Collision tag {} cannot be found!", tagName)
}
void SHCollisionTagMatrix::SetTag(const std::string& tagName, uint16_t mask) noexcept
{
for (auto& collisionTag : collisionTags)
{
if (collisionTag.GetName() != tagName)
continue;
collisionTag.SetMask(mask);
return;
}
SHLOGV_WARNING("Collision tag {} cannot be found!", tagName)
}
void SHCollisionTagMatrix::SetTagName(int tagIndex, const std::string& newTagName)
{
if (tagIndex < 0 || tagIndex > SHCollisionTag::NUM_LAYERS)
throw std::invalid_argument("Index out of range!");
collisionTags[tagIndex].SetName(newTagName);
}
void SHCollisionTagMatrix::SetTag(int tagIndex, const SHCollisionTag& newTag)
{
if (tagIndex < 0 || tagIndex > SHCollisionTag::NUM_LAYERS)
throw std::invalid_argument("Index out of range!");
collisionTags[tagIndex] = newTag;
}
void SHCollisionTagMatrix::SetTag(int tagIndex, uint16_t mask)
{
if (tagIndex < 0 || tagIndex > SHCollisionTag::NUM_LAYERS)
throw std::invalid_argument("Index out of range!");
collisionTags[tagIndex].SetMask(mask);
}
/*-----------------------------------------------------------------------------------*/
/* Public Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
void SHCollisionTagMatrix::Init(const std::filesystem::path& tagNameFilePath) noexcept
{
/**
* I HATE FILE IO
*
* Each line in the file should be "index<space>tag name".
* If the line fails to follow this format, use the default tag name (index + 1)
*/
// Populate tag names with default
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
collisionTags[i].SetName(std::to_string(i + 1));
std::ifstream collisionTagNamesFile { tagNameFilePath };
if (!collisionTagNamesFile.is_open())
{
SHLOG_ERROR("Failed to open file for Collision Tag Names! Default tag names used!")
return;
}
std::stringstream ss;
std::string line;
int linesRead = 0;
while (std::getline(collisionTagNamesFile, line))
{
// Do not read anything beyond the first 16 lines
if (linesRead >= 16)
break;
ss << line;
++linesRead;
// First element is index.
int tagIndex;
ss >> tagIndex;
// Next element is name of the tag
std::string tagName;
ss >> tagName;
// If no tag name read, use default.
if (tagName.empty())
{
SHLOG_ERROR
(
"Collision tag file line {} does not match the required format of 'index<space>tag name'. Default tag used for index {}"
, linesRead + 1
, tagIndex
)
// Use default
collisionTags[tagIndex].SetName(std::to_string(tagIndex + 1));
continue;
}
collisionTags[tagIndex].SetName(tagName);
ss.clear();
}
collisionTagNamesFile.close();
}
void SHCollisionTagMatrix::Exit(const std::filesystem::path& tagNameFilePath) noexcept
{
std::ofstream collisionTagNamesFile { tagNameFilePath };
if (!collisionTagNamesFile.is_open())
{
SHLOG_ERROR("Failed to open file for Collision Tag Names! Tag names not saved!")
return;
}
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
collisionTagNamesFile << i << " " << collisionTags[i].GetName() << std::endl;
collisionTagNamesFile.close();
}
void SHCollisionTagMatrix::UpdateTagNamesFromFile(const std::filesystem::path& tagNameFilePath) noexcept
{
std::ifstream collisionTagNamesFile { tagNameFilePath };
if (!collisionTagNamesFile.is_open())
{
SHLOG_ERROR("Failed to open file for Collision Tag Names! Default tag names used!")
return;
}
std::stringstream ss;
std::string line;
int linesRead = 0;
while (std::getline(collisionTagNamesFile, line))
{
// Do not read anything beyond the first 16 lines
if (linesRead >= 16)
break;
ss << line;
++linesRead;
// First element is index.
int tagIndex;
ss >> tagIndex;
// Next element is name of the tag
std::string tagName;
ss >> tagName;
// If no tag name read, use default.
if (tagName.empty())
{
SHLOG_ERROR
(
"Collision tag file line {} does not match the required format of 'index<space>tag name'. Name left unchanged for index {}"
, linesRead + 1
, tagIndex
)
continue;
}
collisionTags[tagIndex].SetName(tagName);
ss.clear();
}
collisionTagNamesFile.close();
}
} // namespace SHADE

View File

@ -0,0 +1,65 @@
/****************************************************************************************
* \file SHCollisionTagMatrix.h
* \author Diren D Bharwani, diren.dbharwani, 390002520
* \brief Interface for Collision Tag Matrix for handling sets of Collision Tags.
*
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
* disclosure of this file or its contents without the prior written consent
* of DigiPen Institute of Technology is prohibited.
****************************************************************************************/
#pragma once
#include <filesystem>
// Project Includes
#include "SH_API.h"
#include "SHCollisionTags.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SH_API SHCollisionTagMatrix
{
public:
/*---------------------------------------------------------------------------------*/
/* Getter Functions */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] static const std::string& GetTagName (int tagIndex);
[[nodiscard]] static int GetTagIndex (const std::string& tagName) noexcept;
/*---------------------------------------------------------------------------------*/
/* Setter Functions */
/*---------------------------------------------------------------------------------*/
static void SetTagName (const std::string& oldTagName, const std::string& newTagName) noexcept;
static void SetTag (const std::string& tagName, const SHCollisionTag& newTag) noexcept;
static void SetTag (const std::string& tagName, uint16_t mask) noexcept;
// Unsafe Setters: Can throw exceptions
static void SetTagName (int tagIndex, const std::string& newTagName);
static void SetTag (int tagIndex, const SHCollisionTag& newTag);
static void SetTag (int tagIndex, uint16_t mask);
/*---------------------------------------------------------------------------------*/
/* Function Members */
/*---------------------------------------------------------------------------------*/
static void Init (const std::filesystem::path& tagNameFilePath) noexcept;
static void Exit (const std::filesystem::path& tagNameFilePath) noexcept;
static void UpdateTagNamesFromFile (const std::filesystem::path& tagNameFilePath) noexcept;
private:
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
static SHCollisionTag collisionTags[SHCollisionTag::NUM_LAYERS];
};
}

View File

@ -14,31 +14,24 @@
// Primary Header
#include "SHCollisionTags.h"
// Project Headers
#include "Tools/FileIO/SHFileIO.h"
#include "Tools/Utilities/SHUtilities.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Static Data Member Definitions */
/*-----------------------------------------------------------------------------------*/
std::string SHCollisionTag::tagNames[NUM_TAGS];
/*-----------------------------------------------------------------------------------*/
/* Constructors & Destructor Definitions */
/*-----------------------------------------------------------------------------------*/
SHCollisionTag::SHCollisionTag() noexcept
: mask { SHUtilities::ConvertEnum(eTag::TAG_1) }
: mask { SHUtilities::ConvertEnum(Layer::ALL) }
{}
SHCollisionTag::SHCollisionTag(uint16_t tagValue) noexcept
: mask { tagValue }
SHCollisionTag::SHCollisionTag(uint16_t _mask) noexcept
: mask { _mask }
{}
SHCollisionTag::SHCollisionTag(eTag tagValue) noexcept
: mask { SHUtilities::ConvertEnum(tagValue) }
SHCollisionTag::SHCollisionTag(Layer layer) noexcept
: mask { SHUtilities::ConvertEnum(layer) }
{}
/*-----------------------------------------------------------------------------------*/
@ -64,238 +57,60 @@ namespace SHADE
/* Getter Function Definitions */
/*-----------------------------------------------------------------------------------*/
uint16_t SHCollisionTag::GetTagValue() const noexcept
uint16_t SHCollisionTag::GetMask() const noexcept
{
return mask;
}
bool SHCollisionTag::GetTagState(eTag tag) const noexcept
const std::string& SHCollisionTag::GetName() const noexcept
{
return (mask & SHUtilities::ConvertEnum(tag)) > 0;
return name;
}
bool SHCollisionTag::GetTagState(int tagIndex) const
bool SHCollisionTag::GetLayerState(Layer layer) const noexcept
{
if (tagIndex < 0 || tagIndex > NUM_TAGS)
return (mask & SHUtilities::ConvertEnum(layer)) > 0;
}
bool SHCollisionTag::GetLayerState(int layerIndex) const
{
if (layerIndex < 0 || layerIndex > NUM_LAYERS)
throw std::invalid_argument("Index out of range!");
return (mask & (1U << tagIndex)) > 0;
return (mask & (1U << layerIndex)) > 0;
}
/*-----------------------------------------------------------------------------------*/
/* Setter Function Definitions */
/*-----------------------------------------------------------------------------------*/
void SHCollisionTag::SetValue(uint16_t tagValue) noexcept
void SHCollisionTag::SetMask(uint16_t newMask) noexcept
{
mask = tagValue;
mask = newMask;
}
void SHCollisionTag::SetTagState(eTag tag, bool tagState) noexcept
void SHCollisionTag::SetName(const std::string_view& newName) noexcept
{
const auto VALUE = SHUtilities::ConvertEnum(tag);
tagState ? mask |= VALUE : mask &= ~(VALUE);
name = newName;
}
void SHCollisionTag::SetTagState(const std::string& tagName, bool tagState) noexcept
void SHCollisionTag::SetLayerState(Layer layer, bool state) noexcept
{
// This find is expensive.
int tagIndex = -1;
for (int i = 0; i < NUM_TAGS; ++i)
{
if (tagNames[i] != tagName)
continue;
tagIndex = i;
break;
}
if (tagIndex < 0)
{
SHLOGV_WARNING("Parameter tagName {} not found in list of tag names. Tag unmodified.", tagName)
return;
}
const auto VALUE = 1U << tagIndex;
tagState ? mask |= (VALUE) : mask &= ~(VALUE);
const auto VALUE = SHUtilities::ConvertEnum(layer);
state ? mask |= VALUE : mask &= ~(VALUE);
}
void SHCollisionTag::SetTagState(int tagIndex, bool tagState)
void SHCollisionTag::SetLayerState(int layerIndex, bool state)
{
if (tagIndex < 0 || tagIndex > NUM_TAGS)
if (layerIndex < 0 || layerIndex > NUM_LAYERS)
throw std::invalid_argument("Index out of range!");
const auto VALUE = 1U << tagIndex;
tagState ? mask |= (VALUE) : mask &= ~(VALUE);
}
/*-----------------------------------------------------------------------------------*/
/* Public Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
void SHCollisionTag::Init(const std::filesystem::path& tagNameFilePath) noexcept
{
/**
* I HATE FILE IO
*
* Each line in the file should be "index<space>tag name".
* If the line fails to follow this format, use the default tag name (index + 1)
*/
// Populate tag names with default
for (int i = 0; i < NUM_TAGS; ++i)
tagNames[i] = std::to_string(i + 1);
std::ifstream collisionTagNamesFile { tagNameFilePath };
if (!collisionTagNamesFile.is_open())
{
SHLOG_ERROR("Failed to open file for Collision Tag Names! Default tag names used!")
return;
}
std::stringstream ss;
std::string line;
int linesRead = 0;
while (std::getline(collisionTagNamesFile, line))
{
// Do not read anything beyond the first 16 lines
if (linesRead >= 16)
break;
ss << line;
++linesRead;
// First element is index.
int tagIndex;
ss >> tagIndex;
// Next element is name of the tag
std::string tagName;
ss >> tagName;
// If no tag name read, use default.
if (tagName.empty())
{
SHLOG_ERROR
(
"Collision tag file line {} does not match the required format of 'index<space>tag name'. Default tag used for index {}"
, linesRead + 1
, tagIndex
)
// Use default since
tagNames[tagIndex] = std::to_string(tagIndex + 1);
continue;
}
tagNames[tagIndex] = tagName;
ss.clear();
}
collisionTagNamesFile.close();
}
void SHCollisionTag::Exit(const std::filesystem::path& tagNameFilePath) noexcept
{
std::ofstream collisionTagNamesFile { tagNameFilePath };
if (!collisionTagNamesFile.is_open())
{
SHLOG_ERROR("Failed to open file for Collision Tag Names! Tag names not saved!")
return;
}
for (int i = 0; i < NUM_TAGS; ++i)
collisionTagNamesFile << i << " " << tagNames[i] << std::endl;
collisionTagNamesFile.close();
}
void SHCollisionTag::UpdateTagNamesFromFile(const std::filesystem::path& tagNameFilePath) noexcept
{
std::ifstream collisionTagNamesFile { tagNameFilePath };
if (!collisionTagNamesFile.is_open())
{
SHLOG_ERROR("Failed to open file for Collision Tag Names! Default tag names used!")
return;
}
std::stringstream ss;
std::string line;
int linesRead = 0;
while (std::getline(collisionTagNamesFile, line))
{
// Do not read anything beyond the first 16 lines
if (linesRead >= 16)
break;
ss << line;
++linesRead;
// First element is index.
int tagIndex;
ss >> tagIndex;
// Next element is name of the tag
std::string tagName;
ss >> tagName;
// If no tag name read, use default.
if (tagName.empty())
{
SHLOG_ERROR
(
"Collision tag file line {} does not match the required format of 'index<space>tag name'. Name left unchanged for index {}"
, linesRead + 1
, tagIndex
)
// Use default since
tagNames[tagIndex] = std::to_string(tagIndex + 1);
continue;
}
tagNames[tagIndex] = tagName;
ss.clear();
}
collisionTagNamesFile.close();
}
void SHCollisionTag::RemoveTagName(int tagIndex)
{
if (tagIndex < 0 || tagIndex > NUM_TAGS)
throw std::invalid_argument("Index out of range!");
tagNames[tagIndex].clear();
}
void SHCollisionTag::SetTagName(const std::string& newTagName, int tagIndex)
{
if (tagIndex < 0 || tagIndex > NUM_TAGS)
throw std::invalid_argument("Index out of range!");
tagNames[tagIndex] = newTagName;
}
const std::string& SHCollisionTag::GetTagName(int tagIndex)
{
if (tagIndex < 0 || tagIndex > NUM_TAGS)
throw std::invalid_argument("Index out of range!");
return tagNames[tagIndex];
const auto VALUE = 1U << layerIndex;
state ? mask |= (VALUE) : mask &= ~(VALUE);
}
} // namespace SHADE
SHADE::SHCollisionTag::eTag operator|(SHADE::SHCollisionTag::eTag lhs, SHADE::SHCollisionTag::eTag rhs) noexcept
SHADE::SHCollisionTag::Layer operator|(SHADE::SHCollisionTag::Layer lhs, SHADE::SHCollisionTag::Layer rhs) noexcept
{
return static_cast<SHADE::SHCollisionTag::eTag>(SHADE::SHUtilities::ConvertEnum(lhs) | SHADE::SHUtilities::ConvertEnum(rhs));
return static_cast<SHADE::SHCollisionTag::Layer>(SHADE::SHUtilities::ConvertEnum(lhs) | SHADE::SHUtilities::ConvertEnum(rhs));
}

View File

@ -10,7 +10,7 @@
#pragma once
#include <filesystem>
#include <string>
// Project Headers
#include "SH_API.h"
@ -28,34 +28,39 @@ namespace SHADE
/* Type Definitions */
/*---------------------------------------------------------------------------------*/
enum class eTag : uint16_t
enum class Layer : uint16_t
{
TAG_1 = 0x0001
, TAG_2 = 0x0002
, TAG_3 = 0x0004
, TAG_4 = 0x0008
, TAG_5 = 0x0010
, TAG_6 = 0x0020
, TAG_7 = 0x0040
, TAG_8 = 0x0080
, TAG_9 = 0x0100
, TAG_10 = 0x0200
, TAG_11 = 0x0400
, TAG_12 = 0x0800
, TAG_13 = 0x1000
, TAG_14 = 0x2000
, TAG_15 = 0x4000
, TAG_16 = 0x8000
, ALL_TAGS = 0xFFFF
_1 = 0x0001
, _2 = 0x0002
, _3 = 0x0004
, _4 = 0x0008
, _5 = 0x0010
, _6 = 0x0020
, _7 = 0x0040
, _8 = 0x0080
, _9 = 0x0100
, _10 = 0x0200
, _11 = 0x0400
, _12 = 0x0800
, _13 = 0x1000
, _14 = 0x2000
, _15 = 0x4000
, _16 = 0x8000
, ALL = 0xFFFF
};
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
static constexpr int NUM_LAYERS = 16;
/*---------------------------------------------------------------------------------*/
/* Constructors & Destructor */
/*---------------------------------------------------------------------------------*/
SHCollisionTag () noexcept;
SHCollisionTag (uint16_t tagValue) noexcept;
SHCollisionTag (eTag tagValue) noexcept;
SHCollisionTag () noexcept;
SHCollisionTag (uint16_t mask) noexcept;
SHCollisionTag (Layer layer) noexcept;
SHCollisionTag (const SHCollisionTag&) noexcept = default;
SHCollisionTag (SHCollisionTag&&) noexcept = default;
@ -77,50 +82,31 @@ namespace SHADE
/* Getter Functions */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] uint16_t GetTagValue () const noexcept;
[[nodiscard]] bool GetTagState (eTag tag) const noexcept;
[[nodiscard]] bool GetTagState (int tagIndex) const;
[[nodiscard]] uint16_t GetMask () const noexcept;
[[nodiscard]] const std::string& GetName () const noexcept;
[[nodiscard]] bool GetLayerState (Layer layer) const noexcept;
[[nodiscard]] bool GetLayerState (int layerIndex) const;
/*---------------------------------------------------------------------------------*/
/* Setter Functions */
/*---------------------------------------------------------------------------------*/
void SetValue (uint16_t tagValue) noexcept;
void SetTagState (eTag tag, bool tagState) noexcept;
void SetTagState (const std::string& tagName, bool tagState) noexcept;
void SetTagState (int tagIndex, bool tagState);
/*---------------------------------------------------------------------------------*/
/* Function Members */
/*---------------------------------------------------------------------------------*/
static void Init (const std::filesystem::path& tagNameFilePath) noexcept;
static void Exit (const std::filesystem::path& tagNameFilePath) noexcept;
static void UpdateTagNamesFromFile(const std::filesystem::path& tagNameFilePath) noexcept;
static void SetTagName (const std::string& newTagName, int tagIndex);
static void RemoveTagName (int tagIndex);
[[nodiscard]] static const std::string& GetTagName (int tagIndex);
void SetMask (uint16_t newMask) noexcept;
void SetName (const std::string_view& newName) noexcept;
void SetLayerState (Layer layer, bool state) noexcept;
void SetLayerState (int layerIndex, bool state);
private:
/*---------------------------------------------------------------------------------*/
/* Static Data Members */
/*---------------------------------------------------------------------------------*/
static constexpr int NUM_TAGS = 16;
static std::string tagNames[NUM_TAGS];
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
uint16_t mask;
uint16_t mask;
std::string name;
};
} // namespace SHADE
SHADE::SHCollisionTag::eTag SH_API operator|(SHADE::SHCollisionTag::eTag lhs, SHADE::SHCollisionTag::eTag rhs) noexcept;
SHADE::SHCollisionTag::Layer SH_API operator|(SHADE::SHCollisionTag::Layer lhs, SHADE::SHCollisionTag::Layer rhs) noexcept;

View File

@ -134,9 +134,9 @@ namespace SHADE
return type;
}
const SHCollisionTag& SHCollisionShape::GetCollisionTags() const noexcept
const SHCollisionTag& SHCollisionShape::GetCollisionTag() const noexcept
{
return collisionTags;
return collisionTag;
}
float SHCollisionShape::GetFriction() const noexcept
@ -245,10 +245,10 @@ namespace SHADE
isTrigger = trigger;
}
void SHCollisionShape::SetCollisionTags(const SHCollisionTag& newCollisionTag) noexcept
void SHCollisionShape::SetCollisionTag(const SHCollisionTag& newCollisionTag) noexcept
{
dirty = true;
collisionTags = newCollisionTag;
collisionTag = newCollisionTag;
}
void SHCollisionShape::SetFriction(float friction) noexcept

View File

@ -75,7 +75,7 @@ namespace SHADE
[[nodiscard]] Type GetType () const noexcept;
[[nodiscard]] const SHCollisionTag& GetCollisionTags () const noexcept;
[[nodiscard]] const SHCollisionTag& GetCollisionTag () const noexcept;
[[nodiscard]] float GetFriction () const noexcept;
[[nodiscard]] float GetBounciness () const noexcept;
@ -95,7 +95,7 @@ namespace SHADE
void SetBoundingSphere (float radius);
void SetIsTrigger (bool isTrigger) noexcept;
void SetCollisionTags (const SHCollisionTag& newCollisionTag) noexcept;
void SetCollisionTag (const SHCollisionTag& newCollisionTag) noexcept;
void SetFriction (float friction) noexcept;
void SetBounciness (float bounciness) noexcept;
void SetDensity (float density) noexcept;
@ -113,7 +113,7 @@ namespace SHADE
EntityID entityID; // The entity this collider belongs to
bool isTrigger;
bool dirty;
SHCollisionTag collisionTags;
SHCollisionTag collisionTag;
SHShape* shape;
SHPhysicsMaterial material;
SHVec3 positionOffset;

View File

@ -322,7 +322,7 @@ namespace SHADE
rp3dMaterial.setMassDensity(collisionShape.GetDensity());
// Sync tags
const unsigned short MASK_BITS = collisionShape.GetCollisionTags();
const unsigned short MASK_BITS = collisionShape.GetCollisionTag();
rp3dCollider->setCollisionCategoryBits(MASK_BITS);
rp3dCollider->setCollideWithMaskBits(MASK_BITS);

View File

@ -19,6 +19,7 @@
#include "ECS_Base/Managers/SHEntityManager.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Editor/SHEditor.h"
#include "Physics/Collision/SHCollisionTagMatrix.h"
#include "Physics/SHPhysicsEvents.h"
#include "Scene/SHSceneManager.h"
#include "Scripting/SHScriptEngine.h"
@ -87,7 +88,7 @@ namespace SHADE
void SHPhysicsSystem::SetCollisionTagFile(const std::filesystem::path& tagNamesFilePath) noexcept
{
SHCollisionTag::UpdateTagNamesFromFile(tagNamesFilePath);
SHCollisionTagMatrix::UpdateTagNamesFromFile(tagNamesFilePath);
}
@ -100,7 +101,7 @@ namespace SHADE
// Initialise collision tags
std::filesystem::path defaultCollisionTagNameFilePath { ASSET_ROOT };
defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig");
SHCollisionTag::Init(defaultCollisionTagNameFilePath);
SHCollisionTagMatrix::Init(defaultCollisionTagNameFilePath);
// Subscribe to component events
const std::shared_ptr ADD_COMPONENT_RECEIVER { std::make_shared<SHEventReceiverSpec<SHPhysicsSystem>>(this, &SHPhysicsSystem::addPhysicsComponent) };
@ -138,7 +139,7 @@ namespace SHADE
// Write collision tag names to file
std::filesystem::path defaultCollisionTagNameFilePath { ASSET_ROOT };
defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig");
SHCollisionTag::Exit(defaultCollisionTagNameFilePath);
SHCollisionTagMatrix::Exit(defaultCollisionTagNameFilePath);
}
void SHPhysicsSystem::ForceUpdate()