Unretarded the collision tags #337
|
@ -1,2 +1,16 @@
|
|||
0 1 65535
|
||||
1 2 65415
|
||||
0 1 0000000000000000
|
||||
1 2 0000000000000000
|
||||
2 3 0000000000000000
|
||||
3 4 0000000000000000
|
||||
4 5 0000000000000000
|
||||
5 6 0000000000000000
|
||||
6 7 0000000000000000
|
||||
7 8 0000000000000000
|
||||
8 9 0000000000000000
|
||||
9 10 0000000000000000
|
||||
10 11 0000000000000000
|
||||
11 12 0000000000000000
|
||||
12 13 0000000000000000
|
||||
13 14 0000000000000000
|
||||
14 15 0000000000000000
|
||||
15 16 0000000000000000
|
||||
|
|
|
@ -132,8 +132,8 @@ Size=165,120
|
|||
Collapsed=0
|
||||
|
||||
[Table][0x9D40AE32,17]
|
||||
Column 0 Weight=0.9945
|
||||
Column 1 Weight=0.9945
|
||||
Column 0 Weight=1.0696
|
||||
Column 1 Weight=0.9194
|
||||
Column 2 Weight=0.9945
|
||||
Column 3 Weight=1.0320
|
||||
Column 4 Weight=0.9570
|
||||
|
@ -147,8 +147,8 @@ Column 11 Weight=1.0133
|
|||
Column 12 Weight=0.9945
|
||||
Column 13 Weight=0.8444
|
||||
Column 14 Weight=0.9945
|
||||
Column 15 Weight=1.2009
|
||||
Column 16 Weight=1.0133
|
||||
Column 15 Weight=0.8632
|
||||
Column 16 Weight=1.3510
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=1920,941 Split=X
|
||||
|
@ -159,7 +159,7 @@ DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=1920,941 Split
|
|||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1130,1036 Split=Y Selected=0xB41284E7
|
||||
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=1501,672 Split=Y Selected=0xB41284E7
|
||||
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=1501,700 Split=Y Selected=0xB41284E7
|
||||
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=1501,705 CentralNode=1 Selected=0xB41284E7
|
||||
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=1501,705 CentralNode=1 Selected=0x69428B24
|
||||
DockNode ID=0x0000000C Parent=0x00000009 SizeRef=1501,234 Selected=0xB128252A
|
||||
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6
|
||||
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1501,338 Selected=0xD9F31532
|
||||
|
|
|
@ -16,48 +16,52 @@ namespace SHADE
|
|||
ImGui::TableNextRow();
|
||||
ImGui::PushID("CollisionTagNames");
|
||||
|
||||
for (int i = SHCollisionTag::NUM_LAYERS; i >= 1; --i)
|
||||
// Draw Layers
|
||||
// We have 16 layers for each tag
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
for (int i = 1; i <= SHCollisionTag::NUM_LAYERS; ++i)
|
||||
{
|
||||
ImGui::TableNextColumn();
|
||||
if(i == SHCollisionTag::NUM_LAYERS) continue;
|
||||
|
||||
std::string const& tagName = SHCollisionTagMatrix::GetTagName(i);
|
||||
auto tag = SHCollisionTagMatrix::GetTag(i);
|
||||
if (!tag)
|
||||
continue;
|
||||
//ImGui::Text(tagName.data());
|
||||
ImGui::PushID(i);
|
||||
SHEditorWidgets::InputText("##", [i]{return SHCollisionTagMatrix::GetTagName(i);}, [i](std::string const& value){SHCollisionTagMatrix::GetTag(i)->SetName(value);}, tagName.data(), ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
ImGui::PopID();
|
||||
|
||||
// Show the layer number
|
||||
ImGui::Text(std::to_string(i).c_str());
|
||||
|
||||
}
|
||||
ImGui::PopID();
|
||||
|
||||
// Draw the table
|
||||
// Convenient how we have 16 layers & 16 tags huh?
|
||||
|
||||
for (int i = 0; i < SHCollisionTag::NUM_LAYERS - 1; ++i)
|
||||
{
|
||||
std::string tagName = SHCollisionTagMatrix::GetTagName(i);
|
||||
auto tag = SHCollisionTagMatrix::GetTag(i);
|
||||
|
||||
if(!tag)
|
||||
continue;
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text(tagName.data());
|
||||
for (int j = (SHCollisionTag::NUM_LAYERS) - 1; j >= i; --j)
|
||||
|
||||
ImGui::PushID(i);
|
||||
SHEditorWidgets::InputText("##", [i]{return SHCollisionTagMatrix::GetTagName(i);}, [i](std::string const& value){SHCollisionTagMatrix::GetTag(i)->SetName(value);}, tagName.data(), ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
ImGui::PopID();
|
||||
|
||||
// The checkboxes are just to set the layers of each tag
|
||||
// Nothing else should be altered.
|
||||
|
||||
for (int j = 0; j < SHCollisionTag::NUM_LAYERS; ++j)
|
||||
{
|
||||
int idx = j;
|
||||
std::string tagName2 = SHCollisionTagMatrix::GetTagName(idx);
|
||||
auto tag2 = SHCollisionTagMatrix::GetTag(idx);
|
||||
|
||||
if(!tag2)
|
||||
continue;
|
||||
|
||||
if(tagName.empty())
|
||||
tagName = std::to_string(i);
|
||||
if(tagName2.empty())
|
||||
tagName2 = std::to_string(idx);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if(i == idx)
|
||||
continue;
|
||||
std::string label = std::format("##{} vs {}", tagName, tagName2);
|
||||
if (SHEditorWidgets::CheckBox(label, [tag, &idx] {return tag->GetLayerState(idx); }, [tag, i, idx](bool const& value) {tag->SetLayerState(idx, value); SHCollisionTagMatrix::GetTag(idx)->SetLayerState(i, value); }, label.substr(2)))
|
||||
|
||||
std::string label = std::format("##{}, Layer {}", tagName, j);
|
||||
if (SHEditorWidgets::CheckBox(label, [tag, &j] {return tag->GetLayerState(j); }, [tag, j](bool const& value) {tag->SetLayerState(j, value); }, label.substr(2)))
|
||||
{
|
||||
isDirty = true;
|
||||
}
|
||||
|
@ -77,7 +81,7 @@ namespace SHADE
|
|||
{
|
||||
std::filesystem::path defaultCollisionTagNameFilePath{ ASSET_ROOT };
|
||||
defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig");
|
||||
SHCollisionTagMatrix::Exit(defaultCollisionTagNameFilePath);
|
||||
SHCollisionTagMatrix::SaveToFile(defaultCollisionTagNameFilePath);
|
||||
isDirty = false;
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
|
|
@ -166,7 +166,7 @@ namespace SHADE
|
|||
/* Public Function Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
void SHCollisionTagMatrix::Init(const std::filesystem::path& tagNameFilePath) noexcept
|
||||
void SHCollisionTagMatrix::LoadFromFile(const std::filesystem::path& tagNameFilePath) noexcept
|
||||
{
|
||||
/**
|
||||
* I HATE FILE IO
|
||||
|
@ -240,21 +240,26 @@ namespace SHADE
|
|||
, linesRead + 1
|
||||
, tagIndex
|
||||
)
|
||||
|
||||
collisionTags[tagIndex].SetMask(mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask = static_cast<uint16_t>(std::stoi(maskString));
|
||||
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
|
||||
{
|
||||
const bool LAYER_STATE = mask & 1U << i;
|
||||
collisionTags[tagIndex].SetLayerState(i, LAYER_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
collisionTags[tagIndex].SetMask(mask);
|
||||
|
||||
ss.clear();
|
||||
}
|
||||
|
||||
collisionTagNamesFile.close();
|
||||
}
|
||||
|
||||
void SHCollisionTagMatrix::Exit(const std::filesystem::path& tagNameFilePath) noexcept
|
||||
void SHCollisionTagMatrix::SaveToFile(const std::filesystem::path& tagNameFilePath) noexcept
|
||||
{
|
||||
std::ofstream collisionTagNamesFile { tagNameFilePath };
|
||||
|
||||
|
@ -266,7 +271,15 @@ namespace SHADE
|
|||
|
||||
// Index Name Mask
|
||||
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
|
||||
collisionTagNamesFile << i << " " << collisionTags[i].GetName() << " " << collisionTags[i].GetMask() << std::endl;
|
||||
{
|
||||
collisionTagNamesFile << i << " " << collisionTags[i].GetName() << " ";
|
||||
|
||||
// Write 1 or 0 for each layer for improved clarity
|
||||
for (int j = 0; j < SHCollisionTag::NUM_LAYERS; ++j)
|
||||
collisionTagNamesFile << (collisionTags[i].GetMask() & 1U << j ? 1 : 0);
|
||||
|
||||
collisionTagNamesFile << std::endl;
|
||||
}
|
||||
|
||||
collisionTagNamesFile.close();
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ namespace SHADE
|
|||
/* Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
static void Init (const std::filesystem::path& tagNameFilePath) noexcept;
|
||||
static void Exit (const std::filesystem::path& tagNameFilePath) noexcept;
|
||||
static void LoadFromFile (const std::filesystem::path& tagNameFilePath) noexcept;
|
||||
static void SaveToFile (const std::filesystem::path& tagNameFilePath) noexcept;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
|
|
@ -120,7 +120,10 @@ namespace SHADE
|
|||
collisionTag = newCollisionTag;
|
||||
|
||||
if (rp3dCollider)
|
||||
{
|
||||
rp3dCollider->setCollisionCategoryBits(collisionTag->GetMask());
|
||||
rp3dCollider->setCollideWithMaskBits(collisionTag->GetMask());
|
||||
}
|
||||
}
|
||||
|
||||
void SHCollisionShape::SetFriction(float friction) noexcept
|
||||
|
@ -150,7 +153,6 @@ namespace SHADE
|
|||
// Recompute the bodies' mass
|
||||
dynamic_cast<rp3d::RigidBody*>(collider->collisionBody)->updateMassPropertiesFromColliders();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SHCollisionShape::SetMaterial(const SHPhysicsMaterial& newMaterial) noexcept
|
||||
|
@ -204,8 +206,11 @@ namespace SHADE
|
|||
|
||||
void SHCollisionShape::UpdateCollisionTags() noexcept
|
||||
{
|
||||
if (collisionTag->IsDirty())
|
||||
if (rp3dCollider && collisionTag->IsDirty())
|
||||
{
|
||||
rp3dCollider->setCollisionCategoryBits(collisionTag->GetMask());
|
||||
rp3dCollider->setCollideWithMaskBits(collisionTag->GetMask());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace SHADE
|
|||
// Initialise collision tags
|
||||
std::filesystem::path defaultCollisionTagNameFilePath { ASSET_ROOT };
|
||||
defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig");
|
||||
SHCollisionTagMatrix::Init(defaultCollisionTagNameFilePath);
|
||||
SHCollisionTagMatrix::LoadFromFile(defaultCollisionTagNameFilePath);
|
||||
|
||||
// Register Events
|
||||
for (int i = 0; i < NUM_EVENT_FUNCTIONS; ++i)
|
||||
|
@ -145,7 +145,7 @@ namespace SHADE
|
|||
// Write collision tag names to file
|
||||
std::filesystem::path defaultCollisionTagNameFilePath { ASSET_ROOT };
|
||||
defaultCollisionTagNameFilePath.append("CollisionTags.SHConfig");
|
||||
SHCollisionTagMatrix::Exit(defaultCollisionTagNameFilePath);
|
||||
SHCollisionTagMatrix::SaveToFile(defaultCollisionTagNameFilePath);
|
||||
}
|
||||
|
||||
const std::vector<SHPhysicsRaycastResult>& SHPhysicsSystem::Raycast(const SHRaycaster::RaycastInfo& info) noexcept
|
||||
|
|
Loading…
Reference in New Issue