Implemented a custom physics engine #316

Merged
direnbharwani merged 95 commits from SHPhysics into main 2023-01-23 15:55:45 +08:00
4 changed files with 52 additions and 25 deletions
Showing only changes of commit 0460d776b0 - Show all commits

View File

@ -1,16 +1,16 @@
0 1 0 1 3
1 2 1 2 3
2 3 2 3 65535
3 4 3 4 65535
4 5 4 5 65535
5 6 5 6 65535
6 7 6 7 65535
7 8 7 8 65535
8 9 8 9 65535
9 10 9 10 65535
10 11 10 11 65535
11 12 11 12 65535
12 13 12 13 65535
13 14 13 14 65535
14 15 14 15 65535
15 16 15 16 65535

View File

@ -77,7 +77,7 @@
Interpolate: true Interpolate: true
Sleeping Enabled: true Sleeping Enabled: true
Freeze Position X: false Freeze Position X: false
Freeze Position Y: true Freeze Position Y: false
Freeze Position Z: false Freeze Position Z: false
Freeze Rotation X: false Freeze Rotation X: false
Freeze Rotation Y: false Freeze Rotation Y: false

View File

@ -15,7 +15,7 @@ namespace SHADE
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::PushID("CollisionTagNames"); ImGui::PushID("CollisionTagNames");
for (int i = SHCollisionTag::NUM_LAYERS; i >= 0; --i) for (int i = SHCollisionTag::NUM_LAYERS; i >= 1; --i)
{ {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if(i == SHCollisionTag::NUM_LAYERS) continue; if(i == SHCollisionTag::NUM_LAYERS) continue;
@ -29,7 +29,7 @@ namespace SHADE
ImGui::PopID(); ImGui::PopID();
} }
ImGui::PopID(); ImGui::PopID();
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i) for (int i = 0; i < SHCollisionTag::NUM_LAYERS - 1; ++i)
{ {
std::string tagName = SHCollisionTagMatrix::GetTagName(i); std::string tagName = SHCollisionTagMatrix::GetTagName(i);
auto tag = SHCollisionTagMatrix::GetTag(i); auto tag = SHCollisionTagMatrix::GetTag(i);
@ -53,8 +53,8 @@ namespace SHADE
tagName2 = std::to_string(idx); tagName2 = std::to_string(idx);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
//if(i == idx) if(i == idx)
// continue; continue;
std::string label = std::format("##{} vs {}", tagName, tagName2); std::string label = std::format("##{} vs {}", tagName, tagName2);
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)); 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));
} }

View File

@ -14,6 +14,9 @@
// Primary Header // Primary Header
#include "SHCollisionTagMatrix.h" #include "SHCollisionTagMatrix.h"
// Project Headers
#include "Tools/Utilities/SHUtilities.h"
namespace SHADE namespace SHADE
{ {
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -145,8 +148,9 @@ namespace SHADE
/** /**
* I HATE FILE IO * I HATE FILE IO
* *
* Each line in the file should be "index<space>tag name". * Each line in the file should be "index<space>tag name<space>mask".
* If the line fails to follow this format, use the default tag name (index + 1) * If the line fails to follow this format, use the default tag name (index + 1) and default mask.
* If no mask was read, use a default mask.
*/ */
// Populate tag names with default // Populate tag names with default
@ -187,18 +191,40 @@ namespace SHADE
{ {
SHLOG_ERROR SHLOG_ERROR
( (
"Collision tag file line {} does not match the required format of 'index<space>tag name'. Default tag used for index {}" "Collision tag file line {} does not match the required format of 'index<space>tag name<space>mask'. Default tag used for index {}"
, linesRead + 1 , linesRead + 1
, tagIndex , tagIndex
) )
// Use default // Use default
collisionTags[tagIndex].SetName(std::to_string(tagIndex + 1)); collisionTags[tagIndex].SetName(std::to_string(tagIndex + 1));
collisionTags[tagIndex].SetMask(SHUtilities::ConvertEnum(SHCollisionTag::Layer::ALL));
continue; continue;
} }
collisionTags[tagIndex].SetName(tagName); collisionTags[tagIndex].SetName(tagName);
// Next element is the mask value
std::string maskString;
ss >> maskString;
uint16_t mask = std::numeric_limits<uint16_t>::max();
if (maskString.empty())
{
SHLOG_ERROR
(
"Collision tag file line {} does not match the required format of 'index<space>tag name<space>mask'. Default mask used for index {}"
, linesRead + 1
, tagIndex
)
}
else
{
mask = static_cast<uint16_t>(std::stoi(maskString));
}
collisionTags[tagIndex].SetMask(mask);
ss.clear(); ss.clear();
} }
@ -215,8 +241,9 @@ namespace SHADE
return; return;
} }
// Index Name Mask
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i) for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
collisionTagNamesFile << i << " " << collisionTags[i].GetName() << std::endl; collisionTagNamesFile << i << " " << collisionTags[i].GetName() << " " << collisionTags[i].GetMask() << std::endl;
collisionTagNamesFile.close(); collisionTagNamesFile.close();
} }