diff --git a/Assets/Scenes/M2Scene.shade b/Assets/Scenes/M2Scene.shade index 585582e4..b2a5683f 100644 --- a/Assets/Scenes/M2Scene.shade +++ b/Assets/Scenes/M2Scene.shade @@ -50,7 +50,7 @@ Colliders: - Is Trigger: false Type: Box - Half Extents: {x: 24.7399445, y: 0.25, z: 8.75} + Half Extents: {x: 1, y: 1, z: 1} Friction: 0.400000006 Bounciness: 0 Density: 1 @@ -90,23 +90,7 @@ Bounciness: 0 Density: 1 Position Offset: {x: 0, y: 0.5, z: 0} - Scripts: - - Type: PlayerController - drag: 2 - currentState: 0 - maxMoveVel: 2 - moveForce: 50 - sprintMultiplier: 2 - rotationFactorPerFrame: 1 - maxJumpHeight: 4 - maxJumpTime: 0.75 - fallMultipler: 2 - lightMultiper: 0.75 - mediumMultiper: 0.5 - heavyMultiper: 0.25 - - Type: PickAndThrow - throwForce: [200, 300, 200] - item: 5 + Scripts: ~ - EID: 3 Name: Default IsActive: true @@ -126,12 +110,7 @@ Translate: {x: 0, y: 0, z: 0} Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} - Scripts: - - Type: SHADE_Scripting.ThirdPersonCamera - armLength: 2 - turnSpeedPitch: 0.300000012 - turnSpeedYaw: 0.5 - pitchClamp: 45 + Scripts: ~ - EID: 9 Name: Default IsActive: true @@ -145,6 +124,67 @@ Mesh: 144838771 Material: 123745521 Scripts: ~ +- EID: 6 + Name: AI + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -8, y: -2, z: 2.5} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + Renderable Component: + Mesh: 149697411 + Material: 126974645 + RigidBody Component: + Type: Dynamic + Mass: 1 + Drag: 0 + Angular Drag: 0 + Use Gravity: true + Interpolate: false + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: true + Freeze Rotation Y: true + Freeze Rotation Z: true + Collider Component: + Colliders: + - Is Trigger: false + Type: Box + Half Extents: {x: 0.5, y: 0.5, z: 0.5} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0.5, z: 0} + Scripts: ~ +- EID: 7 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -16.8647861, z: -14.039052} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} + Renderable Component: + Mesh: 149697411 + Material: 126974645 + Scripts: ~ +- EID: 8 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Ambient + Direction: {x: 0, y: 0, z: 1} + Color: {x: 1, y: 1, z: 1, w: 1} + Layer: 4294967295 + Strength: 0.25 + Scripts: ~ - EID: 5 Name: item IsActive: true @@ -186,77 +226,4 @@ Bounciness: 0 Density: 1 Position Offset: {x: 0, y: 0.5, z: 0} - Scripts: - - Type: Item - currCategory: 0 -- EID: 6 - Name: AI - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: -8, y: -2, z: 2.5} - Rotate: {x: 0, y: 0, z: 0} - Scale: {x: 1, y: 1, z: 1} - Renderable Component: - Mesh: 149697411 - Material: 126974645 - RigidBody Component: - Type: Dynamic - Mass: 1 - Drag: 0 - Angular Drag: 0 - Use Gravity: true - Interpolate: false - Freeze Position X: false - Freeze Position Y: false - Freeze Position Z: false - Freeze Rotation X: true - Freeze Rotation Y: true - Freeze Rotation Z: true - Collider Component: - Colliders: - - Is Trigger: false - Type: Box - Half Extents: {x: 0.5, y: 0.5, z: 0.5} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0.5, z: 0} - Scripts: - - Type: AIPrototype - movementForceMultiplier: 100 - patrolSpeed: 0.400000006 - chaseSpeed: 0.800000012 - distanceToCapture: 1.20000005 - distanceToStartChase: 2 - distanceToEndChase: 2.5 -- EID: 7 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 0, y: -16.8647861, z: -14.039052} - Rotate: {x: -0, y: 0, z: -0} - Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} - Renderable Component: - Mesh: 149697411 - Material: 126974645 - Scripts: ~ -- EID: 8 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Light Component: - Position: {x: 0, y: 0, z: 0} - Type: Ambient - Direction: {x: 0, y: 0, z: 1} - Color: {x: 1, y: 1, z: 1, w: 1} - Layer: 4294967295 - Strength: 0.25 - Scripts: - - Type: PickAndThrow - throwForce: [100, 200, 100] - item: 1 \ No newline at end of file + Scripts: ~ \ No newline at end of file diff --git a/TempScriptsFolder/AIPrototype.cs b/Assets/Scripts/AIPrototype.cs similarity index 100% rename from TempScriptsFolder/AIPrototype.cs rename to Assets/Scripts/AIPrototype.cs diff --git a/TempScriptsFolder/CameraControl.cs b/Assets/Scripts/CameraControl.cs similarity index 100% rename from TempScriptsFolder/CameraControl.cs rename to Assets/Scripts/CameraControl.cs diff --git a/TempScriptsFolder/CameraFix.cs b/Assets/Scripts/CameraFix.cs similarity index 100% rename from TempScriptsFolder/CameraFix.cs rename to Assets/Scripts/CameraFix.cs diff --git a/TempScriptsFolder/PhysicsTest.cs b/Assets/Scripts/PhysicsTest.cs similarity index 100% rename from TempScriptsFolder/PhysicsTest.cs rename to Assets/Scripts/PhysicsTest.cs diff --git a/TempScriptsFolder/PrintWhenActive.cs b/Assets/Scripts/PrintWhenActive.cs similarity index 100% rename from TempScriptsFolder/PrintWhenActive.cs rename to Assets/Scripts/PrintWhenActive.cs diff --git a/TempScriptsFolder/RaccoonShowcase.cs b/Assets/Scripts/RaccoonShowcase.cs similarity index 79% rename from TempScriptsFolder/RaccoonShowcase.cs rename to Assets/Scripts/RaccoonShowcase.cs index da0b89d2..836b93d0 100644 --- a/TempScriptsFolder/RaccoonShowcase.cs +++ b/Assets/Scripts/RaccoonShowcase.cs @@ -27,6 +27,11 @@ public class RaccoonShowcase : Script Debug.LogError("Transform is NULL!"); } + foreach (var child in Owner) + { + Debug.Log(child.Name); + } + originalScale = Transform.LocalScale.z; } protected override void update() @@ -36,4 +41,10 @@ public class RaccoonShowcase : Script //Transform.LocalRotation = new Vector3(0.0f, rotation, 0.0f); //Transform.LocalScale = new Vector3(System.Math.Abs(System.Math.Sin(scale.x)) * originalScale, System.Math.Abs(System.Math.Cos(scale.y)) * originalScale, System.Math.Abs(System.Math.Sin(scale.z)) * originalScale); } + + protected override void onDrawGizmos() + { + Gizmos.DrawLine(new Vector3(-1.0f, 0.0f, 0.0f), new Vector3(1.0f, 0.0f, 0.0f)); + Gizmos.DrawLine(new Vector3(-1.0f, 1.0f, 0.0f), new Vector3(1.0f, 1.0f, 0.0f), Color.Red); + } } \ No newline at end of file diff --git a/TempScriptsFolder/RaccoonSpin.cs b/Assets/Scripts/RaccoonSpin.cs similarity index 100% rename from TempScriptsFolder/RaccoonSpin.cs rename to Assets/Scripts/RaccoonSpin.cs diff --git a/TempScriptsFolder/ThirdPersonCamera.cs b/Assets/Scripts/ThirdPersonCamera.cs similarity index 100% rename from TempScriptsFolder/ThirdPersonCamera.cs rename to Assets/Scripts/ThirdPersonCamera.cs diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index f4102067..6b67dbce 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -106,6 +106,7 @@ namespace Sandbox SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index 02977f19..8281f114 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -92,7 +92,7 @@ namespace Sandbox floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC); - auto* floorBox = floorCollider.AddBoundingBox(); + floorCollider.AddBoundingBox(); // Create blank entity with a script //testObj = SHADE::SHEntityManager::CreateEntity(); @@ -114,8 +114,8 @@ namespace Sandbox racoonTransform.SetWorldPosition({ -3.0f, -2.0f, -5.0f }); racoonCollider.AddBoundingBox(); - racoonCollider.GetCollider(0).SetPositionOffset(SHVec3(0.0f,0.5f,0.0f)); - racoonCollider.GetCollider(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); + racoonCollider.GetCollisionShape(0).SetPositionOffset(SHVec3(0.0f,0.5f,0.0f)); + racoonCollider.GetCollisionShape(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); auto racoonItemLocation = SHEntityManager::CreateEntity(); auto& racoonItemLocationTransform = *SHComponentManager::GetComponent_s(racoonItemLocation); @@ -140,13 +140,13 @@ namespace Sandbox itemCollider.AddBoundingBox(); itemCollider.AddBoundingBox(SHVec3(2.0f,2.0f,2.0f)); - itemCollider.GetCollider(1).SetIsTrigger(true); + itemCollider.GetCollisionShape(1).SetIsTrigger(true); - itemCollider.GetCollider(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); - itemCollider.GetCollider(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); + itemCollider.GetCollisionShape(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); + itemCollider.GetCollisionShape(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); - itemCollider.GetCollider(1).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); - itemCollider.GetCollider(1).SetBoundingBox(SHVec3(1.0f, 1.0f, 1.0f)); + itemCollider.GetCollisionShape(1).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); + itemCollider.GetCollisionShape(1).SetBoundingBox(SHVec3(1.0f, 1.0f, 1.0f)); itemRigidBody.SetInterpolate(false); itemRigidBody.SetFreezeRotationX(true); @@ -168,8 +168,8 @@ namespace Sandbox AITransform.SetWorldPosition({ -8.0f, -2.0f, 2.5f }); AICollider.AddBoundingBox(); - AICollider.GetCollider(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); - AICollider.GetCollider(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); + AICollider.GetCollisionShape(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); + AICollider.GetCollisionShape(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); AIRigidBody.SetInterpolate(false); AIRigidBody.SetFreezeRotationX(true); diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index 92c4b69e..e0551262 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -51,6 +51,7 @@ enum class AssetType : AssetTypeMeta SCENE, PREFAB, MATERIAL, + SCRIPT, MESH, MAX_COUNT }; @@ -91,12 +92,12 @@ constexpr std::string_view EXTENSIONS[] = { AUDIO_EXTENSION, SHADER_EXTENSION, SHADER_BUILT_IN_EXTENSION, - MATERIAL_EXTENSION, - TEXTURE_EXTENSION, + TEXTURE_EXTENSION, MODEL_EXTENSION, - SCRIPT_EXTENSION, - SCENE_EXTENSION, + SCENE_EXTENSION, PREFAB_EXTENSION, + MATERIAL_EXTENSION, + SCRIPT_EXTENSION, AUDIO_WAV_EXTENSION, }; diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 3fd71a8e..f4727417 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -338,7 +338,7 @@ namespace SHADE return result; } - void SHAssetManager::CompileAsset(AssetPath const& path) noexcept + void SHAssetManager::CompileAsset(AssetPath const& path, bool genMeta) noexcept { if (!std::filesystem::exists(path)) { @@ -360,10 +360,12 @@ namespace SHADE std::string modelPath = path.string().substr(0, path.string().find_last_of('.')); modelPath += MODEL_EXTENSION; newPath = modelPath; - - GenerateNewMeta(newPath); } + if (genMeta) + { + GenerateNewMeta(newPath); + } } FolderPointer SHAssetManager::GetRootFolder() noexcept @@ -371,6 +373,13 @@ namespace SHADE return folderRoot; } + void SHAssetManager::RefreshDirectory() noexcept + { + SHFileSystem::DestroyDirectory(folderRoot); + assetCollection.clear(); + BuildAssetCollection(); + } + bool SHAssetManager::IsRecognised(char const* ext) noexcept { for (auto const& e : EXTENSIONS) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index ba10d84f..a891ec23 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -87,9 +87,10 @@ namespace SHADE static std::vector GetAllDataOfType(AssetType type) noexcept; static std::vector GetAllRecordOfType(AssetType type) noexcept; - static void CompileAsset(AssetPath const& path) noexcept; + static void CompileAsset(AssetPath const& path, bool genMeta) noexcept; static FolderPointer GetRootFolder() noexcept; + static void RefreshDirectory() noexcept; private: diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp index c3c7ef03..c913030b 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp @@ -17,6 +17,8 @@ #include #include +const std::string AUDIO_FOLDER_PATH{ std::string(ASSET_ROOT)+ "/Audio/" }; + namespace SHADE { SHAudioSystem::SHAudioSystem() @@ -79,10 +81,10 @@ namespace SHADE //SHResourceManager::LoadAllAudio(system, soundList); - LoadBank("../../Assets/Audio/Master.bank"); - LoadBank("../../Assets/Audio/Master.strings.bank"); - //LoadBank("../../Assets/Audio/Music.bank"); - LoadBank("../../Assets/Audio/footsteps.bank"); + LoadBank((AUDIO_FOLDER_PATH + "Master.bank").data()); + LoadBank((AUDIO_FOLDER_PATH + "Master.strings.bank").data()); + //LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data()); + LoadBank((AUDIO_FOLDER_PATH + "footsteps.bank").data()); //auto clip = CreateAudioClip("event:/Characters/sfx_footsteps_human"); //clip->Play(); diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index e2c39ad8..ff65ba58 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -419,7 +419,7 @@ namespace SHADE void SHEntityParentCommand::Execute() { - auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); + auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); for (auto const& eid : entities) { if (entityParentData[eid].newParentEID == MAX_EID) @@ -431,7 +431,7 @@ namespace SHADE void SHEntityParentCommand::Undo() { - auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); + auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); for (auto const& eid : entities) { if (entityParentData[eid].oldParentEID == MAX_EID) diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 72c38d6f..85d10c1a 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -224,9 +224,6 @@ namespace SHADE if (!component) return; - // Get transform component for extrapolating relative sizes - auto* transformComponent = SHComponentManager::GetComponent_s(component->GetEID()); - const auto componentType = rttr::type::get(*component); SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); ImGui::SameLine(); @@ -234,46 +231,39 @@ namespace SHADE { DrawContextMenu(component); - auto& colliders = component->GetColliders(); + auto& colliders = component->GetCollisionShapes(); int const size = static_cast(colliders.size()); - ImGui::BeginChild("Colliders", { 0.0f, colliders.empty() ? 1.0f : 250.0f }, true); + ImGui::BeginChild("Collision Shapes", { 0.0f, colliders.empty() ? 1.0f : 250.0f }, true); std::optional colliderToDelete{ std::nullopt }; for (int i{}; i < size; ++i) { ImGui::PushID(i); - SHCollider* collider = &component->GetCollider(i); + SHCollisionShape* collider = &component->GetCollisionShape(i); auto cursorPos = ImGui::GetCursorPos(); //collider->IsTrigger - if (collider->GetType() == SHCollider::Type::BOX) + if (collider->GetType() == SHCollisionShape::Type::BOX) { - SHEditorWidgets::BeginPanel(std::format("{} Box Collider #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); - SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger"); + SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); auto box = reinterpret_cast(collider->GetShape()); SHEditorWidgets::DragVec3 ( "Half Extents", { "X", "Y", "Z" }, - [box, transformComponent] { return (box->GetHalfExtents() * 2.0f) / transformComponent->GetWorldScale(); }, + [box] { return box->GetRelativeExtents(); }, [collider](SHVec3 const& vec) { collider->SetBoundingBox(vec); }); } - else if (collider->GetType() == SHCollider::Type::SPHERE) + else if (collider->GetType() == SHCollisionShape::Type::SPHERE) { - SHEditorWidgets::BeginPanel(std::format("{} Sphere Collider #{}", ICON_MD_CIRCLE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); - SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger"); + SHEditorWidgets::BeginPanel(std::format("{} Sphere #{}", ICON_MD_CIRCLE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); auto sphere = reinterpret_cast(collider->GetShape()); SHEditorWidgets::DragFloat ( "Radius", - [sphere, transformComponent] - { - const SHVec3& TF_WORLD_SCALE = transformComponent->GetWorldScale(); - const float MAX_SCALE = SHMath::Max({ TF_WORLD_SCALE.x, TF_WORLD_SCALE.y, TF_WORLD_SCALE.z }); - return (sphere->GetRadius() / MAX_SCALE) * 2.0f; - }, + [sphere] { return sphere->GetRelativeRadius(); }, [collider](float const& value) { collider->SetBoundingSphere(value); }); } - else if (collider->GetType() == SHCollider::Type::CAPSULE) + else if (collider->GetType() == SHCollisionShape::Type::CAPSULE) { } diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index c18f0c8c..cfb36cd0 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -24,6 +24,9 @@ #include "Serialization/SHSerialization.h" #include "Serialization/Configurations/SHConfigurationManager.h" + +const std::string LAYOUT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts" }; + namespace SHADE { constexpr ImGuiWindowFlags editorMenuBarFlags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | @@ -43,8 +46,7 @@ namespace SHADE void SHEditorMenuBar::Init() { SHEditorWindow::Init(); - constexpr std::string_view path = "../../Assets/Editor/Layouts"; - for(auto const& entry : std::filesystem::directory_iterator(path)) + for(auto const& entry : std::filesystem::directory_iterator(LAYOUT_FOLDER_PATH)) { layoutPaths.push_back(entry.path()); } diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index 19d147e6..c4ad3459 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -65,6 +65,10 @@ RTTR_REGISTRATION ); } +const std::string USER_LAYOUT_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts/UserLayout.ini" }; +const std::string DEFAULT_LAYOUT_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts/Default.ini" }; +const std::string FONT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Fonts/"}; + namespace SHADE { @@ -106,7 +110,7 @@ namespace SHADE io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; //Enable for Multi-Viewports io->ConfigFlags |= ImGuiConfigFlags_DockingEnable; //Enable docking - io->IniFilename = "../../Assets/Editor/Layouts/UserLayout.ini"; + io->IniFilename = USER_LAYOUT_PATH.data(); io->ConfigWindowsMoveFromTitleBarOnly = true; InitLayout(); @@ -236,20 +240,20 @@ namespace SHADE { if(!std::filesystem::exists(io->IniFilename)) { - std::filesystem::copy_file("../../Assets/Editor/Layouts/Default.ini", io->IniFilename); + std::filesystem::copy_file(DEFAULT_LAYOUT_PATH.data(), io->IniFilename); } //eventually load preferred layout here } void SHEditor::InitFonts() noexcept { - ImFont* mainFont = io->Fonts->AddFontFromFileTTF("../../Assets/Editor/Fonts/Segoe UI.ttf", 20.f);//TODO: Change to config based assets path + ImFont* mainFont = io->Fonts->AddFontFromFileTTF(std::string(FONT_FOLDER_PATH + "Segoe UI.ttf").data(), 20.f);//TODO: Change to config based assets path ImFontConfig icons_config{}; icons_config.MergeMode = true; icons_config.GlyphOffset.y = 5.f; constexpr ImWchar icon_ranges_fa[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; - ImFont* UIFontFA = io->Fonts->AddFontFromFileTTF("../../Assets/Editor/Fonts/fa-solid-900.ttf", 20.f, &icons_config, icon_ranges_fa); //TODO: Change to config based assets path + ImFont* UIFontFA = io->Fonts->AddFontFromFileTTF(std::string(FONT_FOLDER_PATH + "fa-solid-900.ttf").data(), 20.f, &icons_config, icon_ranges_fa); //TODO: Change to config based assets path constexpr ImWchar icon_ranges_md[] = { ICON_MIN_MD, ICON_MAX_16_MD, 0 }; - ImFont* UIFontMD = io->Fonts->AddFontFromFileTTF("../../Assets/Editor/Fonts/MaterialIcons-Regular.ttf", 20.f, &icons_config, icon_ranges_md); //TODO: Change to config based assets path + ImFont* UIFontMD = io->Fonts->AddFontFromFileTTF(std::string(FONT_FOLDER_PATH + "MaterialIcons-Regular.ttf").data(), 20.f, &icons_config, icon_ranges_md); //TODO: Change to config based assets path io->Fonts->Build(); } diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index d649fabf..d7bbf5f0 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -11,9 +11,11 @@ constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT { 2 }; constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT { 3 }; constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT { 4 }; constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 }; -constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 6 }; -constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 7 }; -constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 8 }; -constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 9 }; -constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 10 }; +constexpr SHEventIdentifier SH_SCENEGRAPH_ADD_CHILD_EVENT { 6 }; +constexpr SHEventIdentifier SH_SCENEGRAPH_REMOVE_CHILD_EVENT { 7 }; +constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 8 }; +constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 9 }; +constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 }; +constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 }; +constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 }; diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp index 4c0971e6..c4bcc5dc 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.cpp +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.cpp @@ -12,6 +12,7 @@ #include "SHFileSystem.h" #include #include +#include #include "Assets/SHAssetMetaHandler.h" @@ -24,23 +25,37 @@ namespace SHADE return true; } - void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept + bool SHFileSystem::IsCompilable(std::string ext) noexcept + { + for (auto const& external : EXTERNALS) + { + if (ext == external) + { + return true; + } + } + + return false; + } + + void SHFileSystem::BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept { - std::queue folderQueue; + std::stack folderStack; root = new SHFolder("root"); root->path = path; - folderQueue.push(root); + folderStack.push(root); - while (!folderQueue.empty()) + while (!folderStack.empty()) { - auto const folder = folderQueue.front(); - folderQueue.pop(); + auto const folder = folderStack.top(); + folderStack.pop(); std::vector assets; - for (auto const& dirEntry : std::filesystem::directory_iterator(folder->path)) + for (auto& dirEntry : std::filesystem::directory_iterator(folder->path)) { - auto const& path = dirEntry.path(); + auto path = dirEntry.path(); + path.make_preferred(); if (!dirEntry.is_directory()) { if (path.extension().string() == META_EXTENSION) @@ -55,14 +70,15 @@ namespace SHADE path.stem().string(), path.string(), path.extension().string(), - nullptr + nullptr, + IsCompilable(path.extension().string()) ); } continue; } auto newFolder{ folder->CreateSubFolderHere(path.stem().string()) }; - folderQueue.push(newFolder); + folderStack.push(newFolder); } for (auto const& asset : assets) @@ -72,11 +88,34 @@ namespace SHADE { if (file.name == asset.name) { - file.assetMeta = &assetCollection[asset.id]; - break; + AssetPath path{ file.path }; + if (SHAssetMetaHandler::GetTypeFromExtension(path.extension().string()) == asset.type) + { + file.assetMeta = &assetCollection[asset.id]; + break; + } } } } } } + + void SHFileSystem::DestroyDirectory(FolderPointer root) noexcept + { + std::stack folderStack; + folderStack.push(root); + + while(!folderStack.empty()) + { + auto const folder = folderStack.top(); + folderStack.pop(); + + for (auto const& ptr : folder->subFolders) + { + folderStack.push(ptr); + } + + delete folder; + } + } } diff --git a/SHADE_Engine/src/Filesystem/SHFileSystem.h b/SHADE_Engine/src/Filesystem/SHFileSystem.h index 956d3916..87d13f42 100644 --- a/SHADE_Engine/src/Filesystem/SHFileSystem.h +++ b/SHADE_Engine/src/Filesystem/SHFileSystem.h @@ -20,9 +20,9 @@ namespace SHADE { public: static void BuildDirectory(FolderPath path, FolderPointer& root, std::unordered_map& assetCollection) noexcept; - + static void DestroyDirectory(FolderPointer root) noexcept; private: static bool DeleteFolder(FolderPointer location) noexcept; - + static bool IsCompilable(std::string ext) noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Filesystem/SHFolder.h b/SHADE_Engine/src/Filesystem/SHFolder.h index 54e95033..5c702b51 100644 --- a/SHADE_Engine/src/Filesystem/SHFolder.h +++ b/SHADE_Engine/src/Filesystem/SHFolder.h @@ -33,6 +33,7 @@ namespace SHADE FilePath path; FileExt ext; SHAsset const* assetMeta; + bool compilable; }; class SHFolder diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index 883e4894..daa6a23d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -323,7 +323,7 @@ namespace SHADE static const SHMeshData SPHERE = SHPrimitiveGenerator::Sphere(); for (const auto& idx : SPHERE.Indices) { - spherePoints.emplace_back(SPHERE.VertexPositions[idx]); + spherePoints.emplace_back(SPHERE.VertexPositions[idx] * radius); } } drawLineSet(storage, color, spherePoints.begin(), spherePoints.end()); diff --git a/SHADE_Engine/src/Math/Geometry/SHBoundingBox.cpp b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.cpp index d0ba2f14..5bbf5e15 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBoundingBox.cpp +++ b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.cpp @@ -25,11 +25,13 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ SHBoundingBox::SHBoundingBox() noexcept + : RelativeExtents { SHVec3::One } { type = Type::BOX; } SHBoundingBox::SHBoundingBox(const SHVec3& c, const SHVec3& hE) noexcept + : RelativeExtents { SHVec3::One } { type = Type::BOX; @@ -45,16 +47,18 @@ namespace SHADE type = Type::BOX; - Center = rhs.Center; - Extents = rhs.Extents; + Center = rhs.Center; + Extents = rhs.Extents; + RelativeExtents = rhs.RelativeExtents; } SHBoundingBox::SHBoundingBox(SHBoundingBox&& rhs) noexcept { type = Type::BOX; - Center = rhs.Center; - Extents = rhs.Extents; + Center = rhs.Center; + Extents = rhs.Extents; + RelativeExtents = rhs.RelativeExtents; } /*-----------------------------------------------------------------------------------*/ @@ -69,8 +73,9 @@ namespace SHADE } else if (this != &rhs) { - Center = rhs.Center; - Extents = rhs.Extents; + Center = rhs.Center; + Extents = rhs.Extents; + RelativeExtents = rhs.RelativeExtents; } return *this; @@ -84,8 +89,9 @@ namespace SHADE } else { - Center = rhs.Center; - Extents = rhs.Extents; + Center = rhs.Center; + Extents = rhs.Extents; + RelativeExtents = rhs.RelativeExtents; } return *this; @@ -100,11 +106,16 @@ namespace SHADE return Center; } - SHVec3 SHBoundingBox::GetHalfExtents() const noexcept + SHVec3 SHBoundingBox::GetWorldExtents() const noexcept { return Extents; } + const SHVec3& SHBoundingBox::GetRelativeExtents() const noexcept + { + return RelativeExtents; + } + SHVec3 SHBoundingBox::GetMin() const noexcept { return SHVec3{ Center.x - Extents.x, Center.y - Extents.y, Center.z - Extents.z }; @@ -124,9 +135,14 @@ namespace SHADE Center = newCenter; } - void SHBoundingBox::SetHalfExtents(const SHVec3& newHalfExtents) noexcept + void SHBoundingBox::SetWorldExtents(const SHVec3& newWorldExtents) noexcept { - Extents = newHalfExtents; + Extents = newWorldExtents; + } + + void SHBoundingBox::SetRelativeExtents(const SHVec3& newRelativeExtents) noexcept + { + RelativeExtents = newRelativeExtents; } void SHBoundingBox::SetMin(const SHVec3& min) noexcept diff --git a/SHADE_Engine/src/Math/Geometry/SHBoundingBox.h b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.h index 5b3d26d5..e2757c17 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBoundingBox.h +++ b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.h @@ -54,21 +54,23 @@ namespace SHADE /* Getter Functions */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] SHVec3 GetCenter () const noexcept; - [[nodiscard]] SHVec3 GetHalfExtents() const noexcept; - [[nodiscard]] SHVec3 GetMin () const noexcept; - [[nodiscard]] SHVec3 GetMax () const noexcept; - [[nodiscard]] std::vector GetVertices () const noexcept; + [[nodiscard]] SHVec3 GetCenter () const noexcept; + [[nodiscard]] SHVec3 GetWorldExtents () const noexcept; + [[nodiscard]] const SHVec3& GetRelativeExtents () const noexcept; + [[nodiscard]] SHVec3 GetMin () const noexcept; + [[nodiscard]] SHVec3 GetMax () const noexcept; + [[nodiscard]] std::vector GetVertices () const noexcept; /*---------------------------------------------------------------------------------*/ /* Setter Functions */ /*---------------------------------------------------------------------------------*/ - void SetCenter (const SHVec3& newCenter) noexcept; - void SetHalfExtents (const SHVec3& newHalfExtents) noexcept; - void SetMin (const SHVec3& min) noexcept; - void SetMax (const SHVec3& max) noexcept; - void SetMinMax (const SHVec3& min, const SHVec3& max) noexcept; + void SetCenter (const SHVec3& newCenter) noexcept; + void SetWorldExtents (const SHVec3& newWorldExtents) noexcept; + void SetRelativeExtents (const SHVec3& newRelativeExtents) noexcept; + void SetMin (const SHVec3& min) noexcept; + void SetMax (const SHVec3& max) noexcept; + void SetMinMax (const SHVec3& min, const SHVec3& max) noexcept; /*---------------------------------------------------------------------------------*/ /* Function Members */ @@ -89,6 +91,13 @@ namespace SHADE [[nodiscard]] static bool Intersect (const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept; [[nodiscard]] static SHBoundingBox BuildFromBoxes (const SHBoundingBox* boxes, size_t numBoxes) noexcept; [[nodiscard]] static SHBoundingBox BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept; + + private: + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + SHVec3 RelativeExtents; }; diff --git a/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.cpp b/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.cpp index 62bf12b2..f843a6bb 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.cpp +++ b/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.cpp @@ -25,11 +25,13 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ SHBoundingSphere::SHBoundingSphere() noexcept + : RelativeRadius { 1.0f } { type = Type::SPHERE; } SHBoundingSphere::SHBoundingSphere(const SHVec3& center, float radius) noexcept + : RelativeRadius { 1.0f } { type = Type::SPHERE; @@ -44,16 +46,18 @@ namespace SHADE type = Type::SPHERE; - Center = rhs.Center; - Radius = rhs.Radius; + Center = rhs.Center; + Radius = rhs.Radius; + RelativeRadius = rhs.RelativeRadius; } SHBoundingSphere::SHBoundingSphere(SHBoundingSphere&& rhs) noexcept { type = Type::SPHERE; - Center = rhs.Center; - Radius = rhs.Radius; + Center = rhs.Center; + Radius = rhs.Radius; + RelativeRadius = rhs.RelativeRadius; } /*-----------------------------------------------------------------------------------*/ @@ -68,8 +72,9 @@ namespace SHADE } else if (this != &rhs) { - Center = rhs.Center; - Radius = rhs.Radius; + Center = rhs.Center; + Radius = rhs.Radius; + RelativeRadius = rhs.RelativeRadius; } return *this; @@ -83,8 +88,9 @@ namespace SHADE } else { - Center = rhs.Center; - Radius = rhs.Radius; + Center = rhs.Center; + Radius = rhs.Radius; + RelativeRadius = rhs.RelativeRadius; } return *this; @@ -99,11 +105,16 @@ namespace SHADE return Center; } - float SHBoundingSphere::GetRadius() const noexcept + float SHBoundingSphere::GetWorldRadius() const noexcept { return Radius; } - + + float SHBoundingSphere::GetRelativeRadius() const noexcept + { + return RelativeRadius; + } + /*-----------------------------------------------------------------------------------*/ /* Setter Function Definitions */ /*-----------------------------------------------------------------------------------*/ @@ -113,9 +124,14 @@ namespace SHADE Center = center; } - void SHBoundingSphere::SetRadius(float radius) noexcept + void SHBoundingSphere::SetWorldRadius(float newWorldRadius) noexcept { - Radius = radius; + Radius = newWorldRadius; + } + + void SHBoundingSphere::SetRelativeRadius(float newRelativeRadius) noexcept + { + RelativeRadius = newRelativeRadius; } /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.h b/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.h index 001e889b..d94722d6 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.h +++ b/SHADE_Engine/src/Math/Geometry/SHBoundingSphere.h @@ -48,15 +48,17 @@ namespace SHADE /* Getter Functions */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] SHVec3 GetCenter () const noexcept; - [[nodiscard]] float GetRadius () const noexcept; + [[nodiscard]] SHVec3 GetCenter () const noexcept; + [[nodiscard]] float GetWorldRadius () const noexcept; + [[nodiscard]] float GetRelativeRadius () const noexcept; /*---------------------------------------------------------------------------------*/ /* Setter Functions */ /*---------------------------------------------------------------------------------*/ - void SetCenter (const SHVec3& center) noexcept; - void SetRadius (float radius) noexcept; + void SetCenter (const SHVec3& center) noexcept; + void SetWorldRadius (float newWorldRadius) noexcept; + void SetRelativeRadius (float newRelativeRadius) noexcept; /*---------------------------------------------------------------------------------*/ /* Function Members */ @@ -79,5 +81,12 @@ namespace SHADE [[nodiscard]] static SHBoundingSphere BuildFromSpheres (const SHBoundingSphere* spheres, size_t numSpheres) noexcept; [[nodiscard]] static SHBoundingSphere BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept; + private: + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + float RelativeRadius; + }; } // namespace SHADE diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp index f000aa5b..94c133dd 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -231,12 +231,12 @@ namespace SHADE tf.worldRotation = tf.localRotation + (parent ? parent->GetLocalRotation() : SHVec3::Zero); // Set the orientation - // Wrap rotations between -360 and 360 and convert to radians + // Wrap rotations between -720 and 720 and convert to radians SHVec3 worldRotRad, localRotRad; for (size_t i = 0; i < SHVec3::SIZE; ++i) { - worldRotRad[i] = SHMath::Wrap(tf.worldRotation[i], -SHMath::TWO_PI, SHMath::TWO_PI); - localRotRad[i] = SHMath::Wrap(tf.localRotation[i], -SHMath::TWO_PI, SHMath::TWO_PI); + worldRotRad[i] = SHMath::Wrap(tf.worldRotation[i], -2.0f * SHMath::TWO_PI, 2.0f * SHMath::TWO_PI); + localRotRad[i] = SHMath::Wrap(tf.localRotation[i], -2.0f * SHMath::TWO_PI, 2.0f * SHMath::TWO_PI); } tf.world.orientation = SHQuaternion::FromEuler(worldRotRad); diff --git a/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp b/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp index c7e327fa..93126fc5 100644 --- a/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp +++ b/SHADE_Engine/src/Physics/Components/SHColliderComponent.cpp @@ -48,17 +48,22 @@ namespace SHADE return orientation.ToEuler(); } - const SHColliderComponent::Colliders& SHColliderComponent::GetColliders() const noexcept + const SHVec3& SHColliderComponent::GetScale() const noexcept { - return colliders; + return scale; } - SHCollider& SHColliderComponent::GetCollider(int index) + const SHColliderComponent::CollisionShapes& SHColliderComponent::GetCollisionShapes() const noexcept { - if (index < 0 || static_cast(index) >= colliders.size()) + return collisionShapes; + } + + SHCollisionShape& SHColliderComponent::GetCollisionShape(int index) + { + if (index < 0 || static_cast(index) >= collisionShapes.size()) throw std::invalid_argument("Out-of-range access!"); - return colliders[index]; + return collisionShapes[index]; } /*-----------------------------------------------------------------------------------*/ @@ -75,39 +80,74 @@ namespace SHADE } - SHBoundingBox* SHColliderComponent::AddBoundingBox(const SHVec3& halfExtents, const SHVec3& posOffset) noexcept + void SHColliderComponent::RecomputeCollisionShapes() noexcept + { + for (auto& collisionShape : collisionShapes) + { + switch (collisionShape.GetType()) + { + case SHCollisionShape::Type::BOX: + { + auto* box = reinterpret_cast(collisionShape.GetShape()); + const SHVec3& RELATIVE_EXTENTS = box->GetRelativeExtents(); + + // Recompute world extents based on new scale and fixed relative extents + const SHVec3 WORLD_EXTENTS = RELATIVE_EXTENTS * (scale * 0.5f); + box->SetWorldExtents(WORLD_EXTENTS); + + continue; + } + case SHCollisionShape::Type::SPHERE: + { + auto* sphere = reinterpret_cast(collisionShape.GetShape()); + const float RELATIVE_RADIUS = sphere->GetRelativeRadius(); + + // Recompute world radius based on new scale and fixed radius + const float MAX_SCALE = SHMath::Max({ scale.x, scale.y, scale.z }); + const float WORLD_RADIUS = RELATIVE_RADIUS * MAX_SCALE * 0.5f; + sphere->SetWorldRadius(WORLD_RADIUS); + + continue; + } + default: continue; + } + } + } + + int SHColliderComponent::AddBoundingBox(const SHVec3& halfExtents, const SHVec3& posOffset, const SHVec3& rotOffset) noexcept { if (!system) { SHLOG_ERROR("Physics system does not exist, unable to add Box Collider!") - return nullptr; + return -1; } - static constexpr auto TYPE = SHCollider::Type::BOX; + static constexpr auto TYPE = SHCollisionShape::Type::BOX; - auto& collider = colliders.emplace_back(SHCollider{ GetEID(), TYPE }); + auto& collider = collisionShapes.emplace_back(SHCollisionShape{ GetEID(), TYPE }); collider.entityID = GetEID(); collider.SetPositionOffset(posOffset); + collider.SetRotationOffset(rotOffset); collider.SetBoundingBox(halfExtents); // Notify Physics System system->AddCollisionShape(GetEID(), &collider); - return reinterpret_cast(collider.GetShape()); + return static_cast(collisionShapes.size()) - 1; } - SHBoundingSphere* SHColliderComponent::AddBoundingSphere(float radius, const SHVec3& posOffset) noexcept + int SHColliderComponent::AddBoundingSphere(float radius, const SHVec3& posOffset) noexcept { if (!system) { SHLOG_ERROR("Physics system does not exist, unable to add Sphere Collider!") - return nullptr; + return -1; } - static constexpr auto TYPE = SHCollider::Type::SPHERE; + static constexpr auto TYPE = SHCollisionShape::Type::SPHERE; - auto& collider = colliders.emplace_back(SHCollider{ GetEID(), TYPE }); + auto& collider = collisionShapes.emplace_back(SHCollisionShape{ GetEID(), TYPE }); collider.entityID = GetEID(); collider.SetPositionOffset(posOffset); @@ -116,17 +156,17 @@ namespace SHADE // Notify Physics System system->AddCollisionShape(GetEID(), &collider); - return reinterpret_cast(collider.GetShape()); + return static_cast(collisionShapes.size()) - 1; } void SHColliderComponent::RemoveCollider(int index) { - if (index < 0 || static_cast(index) >= colliders.size()) + if (index < 0 || static_cast(index) >= collisionShapes.size()) throw std::invalid_argument("Out-of-range access!"); int idx = 0; - auto it = colliders.begin(); - for (; it != colliders.end(); ++it) + auto it = collisionShapes.begin(); + for (; it != collisionShapes.end(); ++it) { if (idx == index) break; @@ -134,7 +174,7 @@ namespace SHADE ++idx; } - it = colliders.erase(it); + it = collisionShapes.erase(it); // Notify Physics System if (!system) diff --git a/SHADE_Engine/src/Physics/Components/SHColliderComponent.h b/SHADE_Engine/src/Physics/Components/SHColliderComponent.h index 7ce272a9..5f9b7a1b 100644 --- a/SHADE_Engine/src/Physics/Components/SHColliderComponent.h +++ b/SHADE_Engine/src/Physics/Components/SHColliderComponent.h @@ -14,7 +14,7 @@ // Project Headers #include "ECS_Base/Components/SHComponent.h" -#include "Physics/SHCollider.h" +#include "Physics/SHCollisionShape.h" #include "Math/Geometry/SHBoundingBox.h" #include "Math/Geometry/SHBoundingSphere.h" @@ -43,7 +43,7 @@ namespace SHADE /* Type Definitions */ /*---------------------------------------------------------------------------------*/ - using Colliders = std::vector; + using CollisionShapes = std::vector; public: @@ -67,26 +67,29 @@ namespace SHADE /* Getter Functions */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] bool HasChanged () const noexcept; + [[nodiscard]] bool HasChanged () const noexcept; - [[nodiscard]] const SHVec3& GetPosition () const noexcept; - [[nodiscard]] const SHQuaternion& GetOrientation () const noexcept; - [[nodiscard]] SHVec3 GetRotation () const noexcept; + [[nodiscard]] const SHVec3& GetPosition () const noexcept; + [[nodiscard]] const SHQuaternion& GetOrientation () const noexcept; + [[nodiscard]] SHVec3 GetRotation () const noexcept; + [[nodiscard]] const SHVec3& GetScale () const noexcept; - [[nodiscard]] const Colliders& GetColliders () const noexcept; - [[nodiscard]] SHCollider& GetCollider (int index); + [[nodiscard]] const CollisionShapes& GetCollisionShapes() const noexcept; + [[nodiscard]] SHCollisionShape& GetCollisionShape (int index); /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ - void OnCreate () override; - void OnDestroy () override; + void OnCreate () override; + void OnDestroy () override; - void RemoveCollider (int index); + void RecomputeCollisionShapes () noexcept; - SHBoundingBox* AddBoundingBox (const SHVec3& halfExtents = SHVec3::One, const SHVec3& posOffset = SHVec3::Zero) noexcept; - SHBoundingSphere* AddBoundingSphere (float radius = 1.0f, const SHVec3& posOffset = SHVec3::Zero) noexcept; + void RemoveCollider (int index); + + int AddBoundingBox (const SHVec3& halfExtents = SHVec3::One, const SHVec3& posOffset = SHVec3::Zero, const SHVec3& rotOffset = SHVec3::Zero) noexcept; + int AddBoundingSphere (float radius = 1.0f, const SHVec3& posOffset = SHVec3::Zero) noexcept; private: @@ -98,7 +101,8 @@ namespace SHADE SHVec3 position; SHQuaternion orientation; - Colliders colliders; + SHVec3 scale; + CollisionShapes collisionShapes; RTTR_ENABLE() }; diff --git a/SHADE_Engine/src/Physics/SHCollider.cpp b/SHADE_Engine/src/Physics/SHCollisionShape.cpp similarity index 62% rename from SHADE_Engine/src/Physics/SHCollider.cpp rename to SHADE_Engine/src/Physics/SHCollisionShape.cpp index 6d455d67..c8f8020c 100644 --- a/SHADE_Engine/src/Physics/SHCollider.cpp +++ b/SHADE_Engine/src/Physics/SHCollisionShape.cpp @@ -11,12 +11,12 @@ #include // Primary Header -#include "SHCollider.h" +#include "SHCollisionShape.h" // Project Headers #include "Math/Geometry/SHBoundingBox.h" #include "Math/Geometry/SHBoundingSphere.h" -#include "Math/Transform/SHTransformComponent.h" #include "Math/SHMathHelpers.h" +#include "Physics/Components/SHColliderComponent.h" #include "Reflection/SHReflectionMetadata.h" namespace SHADE @@ -25,7 +25,7 @@ namespace SHADE /* Constructors & Destructor Definitions */ /*-----------------------------------------------------------------------------------*/ - SHCollider::SHCollider(EntityID eid, Type colliderType, const SHPhysicsMaterial& physicsMaterial) + SHCollisionShape::SHCollisionShape(EntityID eid, Type colliderType, const SHPhysicsMaterial& physicsMaterial) : type { colliderType } , entityID { eid } , isTrigger { false } @@ -49,7 +49,7 @@ namespace SHADE } } - SHCollider::SHCollider(const SHCollider& rhs) noexcept + SHCollisionShape::SHCollisionShape(const SHCollisionShape& rhs) noexcept : type { rhs.type} , entityID { rhs.entityID } , isTrigger { rhs.isTrigger } @@ -61,7 +61,7 @@ namespace SHADE CopyShape(rhs.shape); } - SHCollider::SHCollider(SHCollider&& rhs) noexcept + SHCollisionShape::SHCollisionShape(SHCollisionShape&& rhs) noexcept : type { rhs.type} , entityID { rhs.entityID } , isTrigger { rhs.isTrigger } @@ -73,7 +73,7 @@ namespace SHADE CopyShape(rhs.shape); } - SHCollider::~SHCollider() noexcept + SHCollisionShape::~SHCollisionShape() noexcept { shape = nullptr; } @@ -82,7 +82,7 @@ namespace SHADE /* Operator Overload Definitions */ /*-----------------------------------------------------------------------------------*/ - SHCollider& SHCollider::operator=(const SHCollider& rhs) noexcept + SHCollisionShape& SHCollisionShape::operator=(const SHCollisionShape& rhs) noexcept { if (this == &rhs) return *this; @@ -100,7 +100,7 @@ namespace SHADE return *this; } - SHCollider& SHCollider::operator=(SHCollider&& rhs) noexcept + SHCollisionShape& SHCollisionShape::operator=(SHCollisionShape&& rhs) noexcept { type = rhs.type; entityID = rhs.entityID; @@ -119,52 +119,52 @@ namespace SHADE /* Getter Function Definitions */ /*-----------------------------------------------------------------------------------*/ - bool SHCollider::HasChanged() const noexcept + bool SHCollisionShape::HasChanged() const noexcept { return dirty; } - bool SHCollider::IsTrigger() const noexcept + bool SHCollisionShape::IsTrigger() const noexcept { return isTrigger; } - SHCollider::Type SHCollider::GetType() const noexcept + SHCollisionShape::Type SHCollisionShape::GetType() const noexcept { return type; } - float SHCollider::GetFriction() const noexcept + float SHCollisionShape::GetFriction() const noexcept { return material.GetFriction(); } - float SHCollider::GetBounciness() const noexcept + float SHCollisionShape::GetBounciness() const noexcept { return material.GetBounciness(); } - float SHCollider::GetDensity() const noexcept + float SHCollisionShape::GetDensity() const noexcept { return material.GetDensity(); } - const SHPhysicsMaterial& SHCollider::GetMaterial() const noexcept + const SHPhysicsMaterial& SHCollisionShape::GetMaterial() const noexcept { return material; } - const SHVec3& SHCollider::GetPositionOffset() const noexcept + const SHVec3& SHCollisionShape::GetPositionOffset() const noexcept { return positionOffset; } - const SHVec3& SHCollider::GetRotationOffset() const noexcept + const SHVec3& SHCollisionShape::GetRotationOffset() const noexcept { return rotationOffset; } - SHShape* SHCollider::GetShape() noexcept + SHShape* SHCollisionShape::GetShape() noexcept { dirty = true; return shape; @@ -174,93 +174,80 @@ namespace SHADE /* Setter Function Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHCollider::SetBoundingBox(const SHVec3& halfExtents) + void SHCollisionShape::SetBoundingBox(const SHVec3& halfExtents) { dirty = true; - // Set the half extents relative to transform - SHVec3 worldHalfExtents = halfExtents; + const auto* colliderComponent = SHComponentManager::GetComponent(entityID); + // Set the half extents relative to world scale + const SHVec3 WORLD_EXTENTS = halfExtents * colliderComponent->GetScale() * 0.5f; - const auto* transformComponent = SHComponentManager::GetComponent_s(entityID); - if (transformComponent != nullptr) - worldHalfExtents *= (transformComponent->GetWorldScale() * 0.5f); - - if (type == Type::BOX) - { - auto* box = reinterpret_cast(shape); - box->SetHalfExtents(worldHalfExtents); - } - else + if (type != Type::BOX) { type = Type::BOX; delete shape; - shape = new SHBoundingBox{ positionOffset, worldHalfExtents }; + shape = new SHBoundingBox{ positionOffset, WORLD_EXTENTS }; } + + auto* box = reinterpret_cast(shape); + box->SetWorldExtents(WORLD_EXTENTS); + box->SetRelativeExtents(halfExtents); } - void SHCollider::SetBoundingSphere(float radius) + void SHCollisionShape::SetBoundingSphere(float radius) { dirty = true; - // Set the radius relative to transform - float worldRadius = radius; + const auto* colliderComponent = SHComponentManager::GetComponent(entityID); + // Set the radius relative to world scale + const SHVec3 WORLD_SCALE = colliderComponent->GetScale(); + const float MAX_SCALE = SHMath::Max({ WORLD_SCALE.x, WORLD_SCALE.y, WORLD_SCALE.z }); + const float WORLD_RADIUS = radius * MAX_SCALE * 0.5f; - const auto* transformComponent = SHComponentManager::GetComponent_s(entityID); - if (transformComponent != nullptr) - { - const SHVec3 TF_WORLD_SCALE = transformComponent->GetWorldScale(); - const float MAX_SCALE = SHMath::Max({ TF_WORLD_SCALE.x, TF_WORLD_SCALE.y, TF_WORLD_SCALE.z }); - - worldRadius *= MAX_SCALE * 0.5f; - } - - if (type == Type::SPHERE) - { - auto* sphere = reinterpret_cast(shape); - sphere->SetRadius(worldRadius); - } - else + if (type != Type::SPHERE) { type = Type::SPHERE; delete shape; - shape = new SHBoundingSphere{ positionOffset, worldRadius }; + shape = new SHBoundingSphere{ positionOffset, WORLD_RADIUS }; } - + + auto* sphere = reinterpret_cast(shape); + sphere->SetWorldRadius(WORLD_RADIUS); } - void SHCollider::SetIsTrigger(bool trigger) noexcept + void SHCollisionShape::SetIsTrigger(bool trigger) noexcept { dirty = true; isTrigger = trigger; } - void SHCollider::SetFriction(float friction) noexcept + void SHCollisionShape::SetFriction(float friction) noexcept { dirty = true; material.SetFriction(friction); } - void SHCollider::SetBounciness(float bounciness) noexcept + void SHCollisionShape::SetBounciness(float bounciness) noexcept { dirty = true; material.SetBounciness(bounciness); } - void SHCollider::SetDensity(float density) noexcept + void SHCollisionShape::SetDensity(float density) noexcept { dirty = true; material.SetDensity(density); } - void SHCollider::SetMaterial(const SHPhysicsMaterial& newMaterial) noexcept + void SHCollisionShape::SetMaterial(const SHPhysicsMaterial& newMaterial) noexcept { dirty = true; material = newMaterial; } - void SHCollider::SetPositionOffset(const SHVec3& posOffset) noexcept + void SHCollisionShape::SetPositionOffset(const SHVec3& posOffset) noexcept { dirty = true; positionOffset = posOffset; @@ -281,7 +268,7 @@ namespace SHADE } } - void SHCollider::SetRotationOffset(const SHVec3& rotOffset) noexcept + void SHCollisionShape::SetRotationOffset(const SHVec3& rotOffset) noexcept { dirty = true; rotationOffset = rotOffset; @@ -291,7 +278,7 @@ namespace SHADE /* Private Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHCollider::CopyShape(const SHShape* rhs) + void SHCollisionShape::CopyShape(const SHShape* rhs) { switch (type) { @@ -299,14 +286,14 @@ namespace SHADE { const auto* RHS_BOX = reinterpret_cast(rhs); - shape = new SHBoundingBox{ positionOffset, RHS_BOX->GetHalfExtents() }; + shape = new SHBoundingBox{ positionOffset, RHS_BOX->GetWorldExtents() }; break; } case Type::SPHERE: { const auto* RHS_SPHERE = reinterpret_cast(rhs); - shape = new SHBoundingSphere{ positionOffset, RHS_SPHERE->GetRadius() }; + shape = new SHBoundingSphere{ positionOffset, RHS_SPHERE->GetWorldRadius() }; break; } default: break; @@ -320,14 +307,14 @@ RTTR_REGISTRATION using namespace SHADE; using namespace rttr; - registration::enumeration("Collider Type") + registration::enumeration("Collider Type") ( - value("Box", SHCollider::Type::BOX), - value("Sphere", SHCollider::Type::SPHERE) + value("Box", SHCollisionShape::Type::BOX), + value("Sphere", SHCollisionShape::Type::SPHERE) // TODO(Diren): Add More Shapes ); - registration::class_("Collider") - .property("Position Offset", &SHCollider::GetPositionOffset, &SHCollider::SetPositionOffset) - .property("Rotation Offset", &SHCollider::GetRotationOffset, &SHCollider::SetRotationOffset) (metadata(META::angleInRad, true)); + registration::class_("Collider") + .property("Position Offset", &SHCollisionShape::GetPositionOffset, &SHCollisionShape::SetPositionOffset) + .property("Rotation Offset", &SHCollisionShape::GetRotationOffset, &SHCollisionShape::SetRotationOffset) (metadata(META::angleInRad, true)); } \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/SHCollider.h b/SHADE_Engine/src/Physics/SHCollisionShape.h similarity index 91% rename from SHADE_Engine/src/Physics/SHCollider.h rename to SHADE_Engine/src/Physics/SHCollisionShape.h index 8cc233c4..9c8c1d41 100644 --- a/SHADE_Engine/src/Physics/SHCollider.h +++ b/SHADE_Engine/src/Physics/SHCollisionShape.h @@ -24,7 +24,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SH_API SHCollider + class SH_API SHCollisionShape { private: @@ -51,18 +51,18 @@ namespace SHADE /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ - SHCollider (EntityID eid, Type colliderType = Type::BOX, const SHPhysicsMaterial& physicsMaterial = SHPhysicsMaterial::DEFAULT); + SHCollisionShape (EntityID eid, Type colliderType = Type::BOX, const SHPhysicsMaterial& physicsMaterial = SHPhysicsMaterial::DEFAULT); - SHCollider (const SHCollider& rhs) noexcept; - SHCollider (SHCollider&& rhs) noexcept; - ~SHCollider () noexcept; + SHCollisionShape (const SHCollisionShape& rhs) noexcept; + SHCollisionShape (SHCollisionShape&& rhs) noexcept; + ~SHCollisionShape () noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - SHCollider& operator=(const SHCollider& rhs) noexcept; - SHCollider& operator=(SHCollider&& rhs) noexcept; + SHCollisionShape& operator=(const SHCollisionShape& rhs) noexcept; + SHCollisionShape& operator=(SHCollisionShape&& rhs) noexcept; /*---------------------------------------------------------------------------------*/ /* Getter Functions */ diff --git a/SHADE_Engine/src/Physics/SHPhysicsObject.cpp b/SHADE_Engine/src/Physics/SHPhysicsObject.cpp index 37c1269e..00c6943b 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsObject.cpp +++ b/SHADE_Engine/src/Physics/SHPhysicsObject.cpp @@ -128,24 +128,24 @@ namespace SHADE /* Public Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - int SHPhysicsObject::AddCollider(SHCollider* collider) + int SHPhysicsObject::AddCollider(SHCollisionShape* collider) { const rp3d::Transform OFFSETS{ collider->GetPositionOffset(), collider->GetRotationOffset() }; switch (collider->GetType()) { - case SHCollider::Type::BOX: + case SHCollisionShape::Type::BOX: { const auto* box = reinterpret_cast(collider->GetShape()); - rp3d::BoxShape* newBox = factory->createBoxShape(box->GetHalfExtents()); + rp3d::BoxShape* newBox = factory->createBoxShape(box->GetWorldExtents()); rp3dBody->addCollider(newBox, OFFSETS); break; } - case SHCollider::Type::SPHERE: + case SHCollisionShape::Type::SPHERE: { const auto* sphere = reinterpret_cast(collider->GetShape()); - rp3d::SphereShape* newSphere = factory->createSphereShape(sphere->GetRadius()); + rp3d::SphereShape* newSphere = factory->createSphereShape(sphere->GetWorldRadius()); rp3dBody->addCollider(newSphere, OFFSETS); break; @@ -173,7 +173,7 @@ namespace SHADE void SHPhysicsObject::SyncColliders(SHColliderComponent* c) const noexcept { int index = 0; - for (auto& collider : c->colliders) + for (auto& collider : c->collisionShapes) { if (!collider.dirty) continue; @@ -188,21 +188,21 @@ namespace SHADE switch (collider.GetType()) { - case SHCollider::Type::BOX: + case SHCollisionShape::Type::BOX: { const auto* box = reinterpret_cast(collider.GetShape()); auto* rp3dBoxShape = reinterpret_cast(rp3dCollider->getCollisionShape()); - rp3dBoxShape->setHalfExtents(box->GetHalfExtents()); + rp3dBoxShape->setHalfExtents(box->GetWorldExtents()); break; } - case SHCollider::Type::SPHERE: + case SHCollisionShape::Type::SPHERE: { const auto* sphere = reinterpret_cast(collider.GetShape()); auto* rp3dSphereShape = reinterpret_cast(rp3dCollider->getCollisionShape()); - rp3dSphereShape->setRadius(sphere->GetRadius()); + rp3dSphereShape->setRadius(sphere->GetWorldRadius()); break; } diff --git a/SHADE_Engine/src/Physics/SHPhysicsObject.h b/SHADE_Engine/src/Physics/SHPhysicsObject.h index 64caacdb..09b70b11 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsObject.h +++ b/SHADE_Engine/src/Physics/SHPhysicsObject.h @@ -69,7 +69,7 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - int AddCollider (SHCollider* collider); + int AddCollider (SHCollisionShape* collider); void RemoveCollider (int index); void SyncColliders (SHColliderComponent* c) const noexcept; diff --git a/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp index bdee8ba1..437b5ff8 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp @@ -348,7 +348,7 @@ namespace SHADE factory.destroyPhysicsWorld(world); } - void SHPhysicsSystem::AddCollisionShape(EntityID entityID, SHCollider* collider) + void SHPhysicsSystem::AddCollisionShape(EntityID entityID, SHCollisionShape* collider) { auto* physicsObject = GetPhysicsObject(entityID); @@ -395,6 +395,7 @@ namespace SHADE { const auto WORLD_POS = transformComponent->GetWorldPosition(); const auto WORLD_ROT = transformComponent->GetWorldOrientation(); + const auto WORLD_SCL = transformComponent->GetWorldScale(); physicsObject.SetPosition(WORLD_POS); physicsObject.SetOrientation(WORLD_ROT); @@ -409,8 +410,11 @@ namespace SHADE if (colliderComponent) { - colliderComponent->position = WORLD_POS; - colliderComponent->orientation = WORLD_ROT; + colliderComponent->position = WORLD_POS; + colliderComponent->orientation = WORLD_ROT; + colliderComponent->scale = WORLD_SCL; + + colliderComponent->RecomputeCollisionShapes(); } } @@ -605,7 +609,6 @@ namespace SHADE if (rigidBodyComponent != nullptr) { - if (rigidBodyComponent->GetType() == SHRigidBodyComponent::Type::STATIC) continue; @@ -658,8 +661,10 @@ namespace SHADE { const auto IT = std::ranges::find_if(container.begin(), container.end(), [&](const SHCollisionEvent& e) { - const bool ENTITY_MATCH = e.value[0] == collisionEvent.value[0]; - const bool COLLIDERS_MATCH = e.value[1] == collisionEvent.value[1]; + const bool ENTITY_MATCH = (e.ids[0] == collisionEvent.ids[0] && e.ids[1] == collisionEvent.ids[1]) + || (e.ids[0] == collisionEvent.ids[1] && e.ids[1] == collisionEvent.ids[0]); + const bool COLLIDERS_MATCH = (e.ids[2] == collisionEvent.ids[2] && e.ids[3] == collisionEvent.ids[3]) + || (e.ids[2] == collisionEvent.ids[3] && e.ids[3] == collisionEvent.ids[2]); return ENTITY_MATCH && COLLIDERS_MATCH; }); @@ -734,7 +739,7 @@ namespace SHADE // Add collision shapes back into the body if (colliderComponent != nullptr) { - for (auto& collider : colliderComponent->colliders) + for (auto& collider : colliderComponent->collisionShapes) physicsObject->AddCollider(&collider); } } @@ -743,8 +748,9 @@ namespace SHADE { SHASSERT(colliderComponent != nullptr, "Collider Component was not added to Entity " + std::to_string(ENTITY_ID) + "!"); - colliderComponent->position = transformComponent->GetWorldPosition(); - colliderComponent->orientation = transformComponent->GetWorldOrientation(); + colliderComponent->position = transformComponent->GetWorldPosition(); + colliderComponent->orientation = transformComponent->GetWorldOrientation(); + colliderComponent->scale = transformComponent->GetWorldScale(); if (physicsObject->rp3dBody == nullptr) { @@ -755,7 +761,7 @@ namespace SHADE } // Add Collision Shapes - for (auto& collider : colliderComponent->colliders) + for (auto& collider : colliderComponent->collisionShapes) physicsObject->AddCollider(&collider); } } @@ -800,7 +806,7 @@ namespace SHADE rp3d::Transform{ colliderComponent->position, colliderComponent->orientation } ); - for (auto& collider : colliderComponent->colliders) + for (auto& collider : colliderComponent->collisionShapes) physicsObject->AddCollider(&collider); } } diff --git a/SHADE_Engine/src/Physics/SHPhysicsSystem.h b/SHADE_Engine/src/Physics/SHPhysicsSystem.h index 05e6e57e..55575c73 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsSystem.h +++ b/SHADE_Engine/src/Physics/SHPhysicsSystem.h @@ -114,7 +114,7 @@ namespace SHADE void Init () override; void Exit () override; - void AddCollisionShape (EntityID entityID, SHCollider* collider); + void AddCollisionShape (EntityID entityID, SHCollisionShape* collider); void RemoveCollisionShape (EntityID entityID, int index); void onContact (const rp3d::CollisionCallback::CallbackData& callbackData) override; @@ -183,24 +183,24 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - SHPhysicsObject* EnsurePhysicsObject (EntityID entityID) noexcept; - SHPhysicsObject* GetPhysicsObject (EntityID entityID) noexcept; - void DestroyPhysicsObject (EntityID entityID) noexcept; + SHPhysicsObject* EnsurePhysicsObject (EntityID entityID) noexcept; + SHPhysicsObject* GetPhysicsObject (EntityID entityID) noexcept; + void DestroyPhysicsObject (EntityID entityID) noexcept; - static void SyncActiveStates (SHPhysicsObject& physicsObject, bool componentActive) noexcept; - void SyncTransforms () noexcept; + static void SyncActiveStates (SHPhysicsObject& physicsObject, bool componentActive) noexcept; + void SyncTransforms () noexcept; - static void UpdateEventContainers (const SHCollisionEvent& collisionEvent, CollisionEvents& container) noexcept; - void ClearInvalidCollisions () noexcept; + static void UpdateEventContainers (const SHCollisionEvent& collisionEvent, CollisionEvents& container) noexcept; + void ClearInvalidCollisions () noexcept; - SHEventHandle AddPhysicsComponent (SHEventPtr addComponentEvent); - SHEventHandle RemovePhysicsComponent (SHEventPtr removeComponentEvent); - SHEventHandle ResetWorld (SHEventPtr editorStopEvent); + SHEventHandle AddPhysicsComponent (SHEventPtr addComponentEvent); + SHEventHandle RemovePhysicsComponent (SHEventPtr removeComponentEvent); + SHEventHandle ResetWorld (SHEventPtr editorStopEvent); template || std::is_same_v>> - SHCollisionEvent GenerateCollisionEvent (const RP3DCollisionPair& cp) noexcept; + SHCollisionEvent GenerateCollisionEvent (const RP3DCollisionPair& cp) noexcept; }; } // namespace SHADE diff --git a/SHADE_Engine/src/Physics/SHPhysicsUtils.cpp b/SHADE_Engine/src/Physics/SHPhysicsUtils.cpp index 8d5bc956..14b6cc2f 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsUtils.cpp +++ b/SHADE_Engine/src/Physics/SHPhysicsUtils.cpp @@ -75,14 +75,14 @@ namespace SHADE return SHComponentManager::GetComponent_s(ids[ENTITY_B]); } - const SHCollider* SHCollisionEvent::GetColliderA() const noexcept + const SHCollisionShape* SHCollisionEvent::GetColliderA() const noexcept { - return &SHComponentManager::GetComponent(ids[ENTITY_A])->GetCollider(ids[COLLIDER_A]); + return &SHComponentManager::GetComponent(ids[ENTITY_A])->GetCollisionShape(ids[COLLIDER_A]); } - const SHCollider* SHCollisionEvent::GetColliderB() const noexcept + const SHCollisionShape* SHCollisionEvent::GetColliderB() const noexcept { - return &SHComponentManager::GetComponent(ids[ENTITY_B])->GetCollider(ids[COLLIDER_B]); + return &SHComponentManager::GetComponent(ids[ENTITY_B])->GetCollisionShape(ids[COLLIDER_B]); } SHCollisionEvent::State SHCollisionEvent::GetCollisionState() const noexcept diff --git a/SHADE_Engine/src/Physics/SHPhysicsUtils.h b/SHADE_Engine/src/Physics/SHPhysicsUtils.h index 57f9c6fc..753f8d3b 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsUtils.h +++ b/SHADE_Engine/src/Physics/SHPhysicsUtils.h @@ -24,7 +24,7 @@ namespace SHADE struct SHPhysicsColliderAddedEvent { EntityID entityID; - SHCollider::Type colliderType; + SHCollisionShape::Type colliderType; int colliderIndex; }; @@ -88,8 +88,8 @@ namespace SHADE [[nodiscard]] EntityID GetEntityB () const noexcept; [[nodiscard]] const SHRigidBodyComponent* GetRigidBodyA () const noexcept; [[nodiscard]] const SHRigidBodyComponent* GetRigidBodyB () const noexcept; - [[nodiscard]] const SHCollider* GetColliderA () const noexcept; - [[nodiscard]] const SHCollider* GetColliderB () const noexcept; + [[nodiscard]] const SHCollisionShape* GetColliderA () const noexcept; + [[nodiscard]] const SHCollisionShape* GetColliderB () const noexcept; [[nodiscard]] State GetCollisionState () const noexcept; private: diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index df46b3fb..6240b7bf 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -1,7 +1,7 @@ /**************************************************************************************** * \file SHSceneGraph.cpp * \author Diren D Bharwani, diren.dbharwani, 390002520 - * \brief Implementation for a Scene Graph & Scene Nodes. + * \brief Implementation for a Scene Graph. * * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or * disclosure of this file or its contents without the prior written consent @@ -16,8 +16,6 @@ // Project Headers #include "ECS_Base/Managers/SHEntityManager.h" #include "Events/SHEventManager.hpp" -#include "Tools/SHLogger.h" -#include "Tools/SHException.h" namespace SHADE { @@ -25,56 +23,6 @@ namespace SHADE /* Constructors & Destructor Definitions */ /*-----------------------------------------------------------------------------------*/ - SHSceneNode::SHSceneNode(EntityID eid, SHSceneNode* parent) noexcept - : active { true } - , entityID { eid } - , parent { parent } - {} - - - SHSceneNode::SHSceneNode(const SHSceneNode& rhs) noexcept - : active { rhs.active } - , entityID { rhs.entityID } - , parent { rhs.parent } - { - std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); - } - - SHSceneNode::SHSceneNode(SHSceneNode&& rhs) noexcept - : active { rhs.active } - , entityID { rhs.entityID } - , parent { rhs.parent } - { - std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); - } - - SHSceneNode& SHSceneNode::operator=(const SHSceneNode& rhs) noexcept - { - if (this == &rhs) - return *this; - - active = rhs.active; - entityID = rhs.entityID; - parent = rhs.parent; - - children.clear(); - std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); - - return *this; - } - - SHSceneNode& SHSceneNode::operator=(SHSceneNode&& rhs) noexcept - { - active = rhs.active; - entityID = rhs.entityID; - parent = rhs.parent; - - children.clear(); - std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); - - return *this; - } - SHSceneGraph::SHSceneGraph() noexcept : root { nullptr } { @@ -110,56 +58,6 @@ namespace SHADE /* Getter Function Definitions */ /*-----------------------------------------------------------------------------------*/ - bool SHSceneNode::IsActive() const noexcept - { - return active; - } - - EntityID SHSceneNode::GetEntityID() const noexcept - { - return entityID; - } - - SHSceneNode* SHSceneNode::GetParent() const noexcept - { - return parent; - } - - const std::vector& SHSceneNode::GetChildren() const noexcept - { - return children; - } - - SHSceneNode* SHSceneNode::GetChild(EntityID childID) const noexcept - { - //////////////////////////////////////// - // Error handling - if (!SHEntityManager::IsValidEID(childID)) - { - SHLOG_ERROR("Child Entity {} is invalid! Unable to get child from Entity {}", childID, entityID) - return nullptr; - } - - if (children.empty()) - { - SHLOG_WARNING("Entity {} has no children!", entityID) - return nullptr; - } - //////////////////////////////////////// - - // Find child - const auto ENTITY_MATCH = [&](const SHSceneNode* node) { return node->GetEntityID() == childID; }; - - const auto CHILD_ITER = std::ranges::find_if(children.begin(), children.end(),ENTITY_MATCH); - if (CHILD_ITER == children.end()) - { - SHLOG_WARNING("Entity {} is not a child of Entity {}! Unable to retrieve child node!", childID, entityID) - return nullptr; - } - - return *CHILD_ITER; - } - const SHSceneNode* SHSceneGraph::GetRoot() const noexcept { if (root != nullptr) @@ -313,41 +211,7 @@ namespace SHADE /* Setter Function Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHSceneNode::SetParent(SHSceneNode* parentNode) noexcept - { - if (parentNode == nullptr) - { - SHLOG_WARNING("Removing Entity {}'s parent", entityID) - - if (parent) - parent->RemoveChild(this); - - return; - } - - // Handle self assignment - if (parent && parentNode->entityID == parent->entityID) - return; - - if (parent) - parent->RemoveChild(this); - - parent = parentNode; - // Update parent's children - parent->AddChild(this); - } - - void SHSceneNode::SetActive(bool newActiveState) noexcept - { - active = newActiveState; - - for (auto* child : children) - { - SetActive(newActiveState); - } - } - - void SHSceneGraph::SetParent(EntityID entityID, SHSceneNode* parent) const noexcept + void SHSceneGraph::SetParent(EntityID entityID, SHSceneNode* newParent) noexcept { //////////////////////////////////////// // Error Handling @@ -369,30 +233,31 @@ namespace SHADE { .node = NODE_ITER->second , .oldParent = NODE_ITER->second->GetParent() - , .newParent = parent ? parent : root + , .newParent = newParent ? newParent : root }; - if (parent == nullptr) - parent = root; + if (newParent == nullptr) + newParent = root; - NODE_ITER->second->SetParent(parent); + ChangeParent(NODE_ITER->second, newParent); SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT); } - void SHSceneGraph::SetParent(EntityID entityID, EntityID parent) const noexcept + void SHSceneGraph::SetParent(EntityID entityID, EntityID newParent) noexcept { //////////////////////////////////////// // Error Handling + if (!SHEntityManager::IsValidEID(entityID)) { SHLOG_ERROR("Entity {} is invalid! Unable to set parent of an invalid entity!", entityID) return; } - if (!SHEntityManager::IsValidEID(parent)) + if (!SHEntityManager::IsValidEID(newParent)) { - SHLOG_ERROR("Parent Entity {} is invalid! Unable to set Entity {}'s parent!", parent, entityID) + SHLOG_ERROR("Parent Entity {} is invalid! Unable to set Entity {}'s parent!", newParent, entityID) return; } @@ -403,10 +268,10 @@ namespace SHADE return; } - auto PARENT_ITER = entityNodeMap.find(parent); + auto PARENT_ITER = entityNodeMap.find(newParent); if (PARENT_ITER == entityNodeMap.end()) { - SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to parent to Entity {}", parent, entityID) + SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to parent to Entity {}", newParent, entityID) return; } //////////////////////////////////////// @@ -419,7 +284,7 @@ namespace SHADE }; SHSceneNode* currentNode = NODE_ITER->second; - currentNode->SetParent(PARENT_ITER->second); + ChangeParent(currentNode, PARENT_ITER->second); SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT); } @@ -428,84 +293,6 @@ namespace SHADE /* Public Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHSceneNode::AddChild(SHSceneNode* newChild) noexcept - { - //////////////////////////////////////// - // Error Handling - if (newChild == nullptr) - { - SHLOG_WARNING("Attempting to add a non-existent child to an entity!") - return; - } - //////////////////////////////////////// - - if (newChild->parent) - newChild->parent->RemoveChild(newChild); - - newChild->parent = this; - children.emplace_back(newChild); - } - - bool SHSceneNode::RemoveChild(EntityID childID) noexcept - { - //////////////////////////////////////// - // Error Handling - if (!SHEntityManager::IsValidEID(childID)) - { - SHLOG_ERROR("Entity {} is invalid!", childID) - return false; - } - //////////////////////////////////////// - - auto childIter = std::find_if(children.begin(), children.end(), [&](SHSceneNode* node) - { - return node->GetEntityID() == childID; - }); - - if (childIter == children.end()) - { - SHLOG_WARNING("Unable to remove Entity {} from Entity {} since it is not it's child!", childID, entityID) - return false; - } - - (*childIter)->parent = nullptr; - childIter = children.erase(childIter); - - return true; - } - - bool SHSceneNode::RemoveChild(SHSceneNode* childToRemove) noexcept - { - //////////////////////////////////////// - // Error Handling - if (childToRemove == nullptr) - { - SHLOG_WARNING("Attempting to remove non-existent child from Entity {}", entityID) - return false; - } - //////////////////////////////////////// - - auto childIter = std::find(children.begin(), children.end(), childToRemove); - if (childIter == children.end()) - { - SHLOG_WARNING("Unable to remove Entity {} from Entity {} since it is not it's child!", childToRemove->entityID, entityID) - return false; - } - - childIter = children.erase(childIter); - childToRemove->parent = nullptr; - - return true; - } - - void SHSceneNode::RemoveAllChildren() noexcept - { - for (const auto child : children) - child->parent = nullptr; - - children.clear(); - } - SHSceneNode* SHSceneGraph::AddNode(EntityID entityID, SHSceneNode* parent) { //////////////////////////////////////// @@ -528,13 +315,12 @@ namespace SHADE if (parent == nullptr) { // Specific handling for root to avoid a warning when removing a non-existent child - parent = root; newNode->parent = root; root->children.emplace_back(newNode); } else { - newNode->SetParent(parent); + ChangeParent(newNode, parent); } return newNode; @@ -542,6 +328,8 @@ namespace SHADE bool SHSceneGraph::RemoveNode(EntityID entityID) noexcept { + //////////////////////////////////////// + // Error Handling if (!SHEntityManager::IsValidEID(entityID)) { SHLOG_ERROR("Entity {} is invalid!", entityID) @@ -554,12 +342,12 @@ namespace SHADE SHLOG_ERROR("Entity {} does not exist in the scene!", entityID) return false; } + //////////////////////////////////////// // Remove reference of current node from parent SHSceneNode* currentNode = NODE_ITER->second; - SHSceneNode* parent = currentNode->GetParent(); - if (parent != nullptr) - parent->RemoveChild(currentNode); + if (currentNode->parent != nullptr) + RemoveChild(currentNode->parent, currentNode); ReleaseNode(currentNode); return true; @@ -568,9 +356,8 @@ namespace SHADE bool SHSceneGraph::RemoveNode(SHSceneNode* nodeToRemove) noexcept { // Remove reference of current node from parent - SHSceneNode* parent = nodeToRemove->GetParent(); - if (parent != nullptr) - parent->RemoveChild(nodeToRemove); + if (nodeToRemove->parent != nullptr) + RemoveChild(nodeToRemove->parent, nodeToRemove); ReleaseNode(nodeToRemove); return true; @@ -582,6 +369,91 @@ namespace SHADE ReleaseNode(node); } + bool SHSceneGraph::IsChildOf(EntityID entityID, SHSceneNode* targetNode) noexcept + { + //////////////////////////////////////// + // Error Handling + + if (!SHEntityManager::IsValidEID(entityID)) + { + SHLOG_ERROR("Entity {} is invalid!", entityID) + return false; + } + + auto NODE_ITER = entityNodeMap.find(entityID); + if (NODE_ITER == entityNodeMap.end()) + { + SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to check child!", entityID) + return false; + } + + //////////////////////////////////////// + + // Handle self-checks + if (NODE_ITER->second == targetNode) + { + SHLOG_WARNING("Entity {} cannot be a child of itself!", entityID) + return false; + } + + // Search for a matching target until the root + const SHSceneNode* CURRENT_TARGET = NODE_ITER->second->parent; + while (CURRENT_TARGET != root) + { + if (CURRENT_TARGET == targetNode) + return true; + + CURRENT_TARGET = CURRENT_TARGET->parent; + } + + return false; + } + + bool SHSceneGraph::IsChildOf(EntityID entityID, EntityID targetID) noexcept + { + //////////////////////////////////////// + // Error Handling + + if (!SHEntityManager::IsValidEID(entityID)) + { + SHLOG_ERROR("Entity {} is invalid!", entityID) + return false; + } + + if (!SHEntityManager::IsValidEID(targetID)) + { + SHLOG_ERROR("Entity {} is invalid!", targetID) + return false; + } + + auto NODE_ITER = entityNodeMap.find(entityID); + if (NODE_ITER == entityNodeMap.end()) + { + SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to check child!", entityID) + return false; + } + + auto TARGET_ITER = entityNodeMap.find(targetID); + if (TARGET_ITER == entityNodeMap.end()) + { + SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to check child!", targetID) + return false; + } + + //////////////////////////////////////// + + const SHSceneNode* CURRENT_TARGET = NODE_ITER->second->parent; + while (CURRENT_TARGET != root) + { + if (CURRENT_TARGET == TARGET_ITER->second) + return true; + + CURRENT_TARGET = CURRENT_TARGET->parent; + } + + return false; + } + void SHSceneGraph::Traverse (const UnaryFunction& function) const { TraverseAndInvokeFunction(root, function); @@ -594,11 +466,6 @@ namespace SHADE SHSceneNode* SHSceneGraph::AllocateNode(EntityID entityID) { SHSceneNode* newNode = new SHSceneNode{entityID}; - - //#ifdef _DEBUG - // SHLOG_INFO("Allocated a new Scene Node for Entity {}!", entityID) - //#endif - entityNodeMap.emplace(entityID, newNode); return newNode; } @@ -608,19 +475,81 @@ namespace SHADE SHASSERT(node != nullptr, "Attempting to release Invalid Node!") // Remove parent's reference to this node if there is a parent - if (node->GetParent() != nullptr) - node->GetParent()->RemoveChild(node); + if (node->parent != nullptr) + RemoveChild(node->parent, node); // Remove child's references to this node. Children end up as floating nodes. for (auto* child : node->GetChildren()) { - child->SetParent(nullptr); + ChangeParent(child, nullptr); } entityNodeMap.erase(node->GetEntityID()); delete node; } + void SHSceneGraph::ChangeParent(SHSceneNode* node, SHSceneNode* newParent) + { + // Handle self assignment + if (node->parent != nullptr && newParent != nullptr && node->parent->entityID == newParent->entityID) + return; + + // Remove child + if (node->parent) + RemoveChild(node->parent, node); + + if (newParent == nullptr) + { + SHLOG_WARNING("Removing Entity {}'s parent", node->entityID) + return; + } + + node->parent = newParent; + // Update parent's children + AddChild(newParent, node); + } + + void SHSceneGraph::AddChild(SHSceneNode* node, SHSceneNode* newChild) + { + SHASSERT(node != nullptr, "Attempting to modify a non-existent scene node!") + SHASSERT(newChild != nullptr, "Attempting to add a non-existent child to a SceneNode!") + + if (newChild->parent) + RemoveChild(newChild->parent, newChild); + + newChild->parent = node; + node->children.emplace_back(newChild); + + const SHSceneGraphAddChildEvent EVENT_DATA + { + .parent = node + , .childAdded = newChild + }; + + SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_ADD_CHILD_EVENT); + } + + void SHSceneGraph::RemoveChild(SHSceneNode* node, SHSceneNode* childToRemove) + { + SHASSERT(node != nullptr, "Attempting to modify a non-existent scene node!") + SHASSERT(childToRemove != nullptr, "Attempting to remove a non-existent child from a SceneNode!") + + auto childIter = std::find(node->children.begin(), node->children.end(), childToRemove); + if (childIter == node->children.end()) + return; + + childIter = node->children.erase(childIter); + childToRemove->parent = nullptr; + + const SHSceneGraphRemoveChildEvent EVENT_DATA + { + .parent = node + , .childRemoved = childToRemove + }; + + SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_REMOVE_CHILD_EVENT); + } + void SHSceneGraph::TraverseAndInvokeFunction(const SHSceneNode* node, const UnaryFunction& function) { for (auto* child : node->children) diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.h b/SHADE_Engine/src/Scene/SHSceneGraph.h index 45ab48e5..5747be7b 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.h +++ b/SHADE_Engine/src/Scene/SHSceneGraph.h @@ -1,7 +1,7 @@ /**************************************************************************************** * \file SHSceneGraph.h * \author Diren D Bharwani, diren.dbharwani, 390002520 - * \brief Interface for a Scene Graph & Scene Nodes. + * \brief Interface for a Scene Graph. * * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or * disclosure of this file or its contents without the prior written consent @@ -15,81 +15,15 @@ // Project Headers #include "ECS_Base/Entity/SHEntity.h" #include "SH_API.h" +#include "SHSceneNode.h" +#include "SHSceneGraphEvents.h" namespace SHADE { - /*-----------------------------------------------------------------------------------*/ - /* Forward Declarations */ - /*-----------------------------------------------------------------------------------*/ - - class SHSceneGraph; - /*-----------------------------------------------------------------------------------*/ /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SH_API SHSceneNode - { - private: - /*---------------------------------------------------------------------------------*/ - /* Friends */ - /*---------------------------------------------------------------------------------*/ - - friend class SHSceneGraph; - - public: - /*---------------------------------------------------------------------------------*/ - /* Constructors & Destructor */ - /*---------------------------------------------------------------------------------*/ - - ~SHSceneNode () = default; - - SHSceneNode (EntityID eid, SHSceneNode* parent = nullptr) noexcept; - SHSceneNode (const SHSceneNode& rhs) noexcept; - SHSceneNode (SHSceneNode&& rhs) noexcept; - SHSceneNode& operator= (const SHSceneNode& rhs) noexcept; - SHSceneNode& operator= (SHSceneNode&& rhs) noexcept; - - /*---------------------------------------------------------------------------------*/ - /* Getter Functions */ - /*---------------------------------------------------------------------------------*/ - - [[nodiscard]] bool IsActive () const noexcept; - [[nodiscard]] EntityID GetEntityID () const noexcept; - [[nodiscard]] SHSceneNode* GetParent () const noexcept; - [[nodiscard]] const std::vector& GetChildren () const noexcept; - - [[nodiscard]] SHSceneNode* GetChild (EntityID childID) const noexcept; - - /*---------------------------------------------------------------------------------*/ - /* Setter Functions */ - /*---------------------------------------------------------------------------------*/ - - void SetParent (SHSceneNode* parentNode) noexcept; - void SetActive (bool newActiveState) noexcept; - - /*---------------------------------------------------------------------------------*/ - /* Function Members */ - /*---------------------------------------------------------------------------------*/ - - void AddChild (SHSceneNode* newChild) noexcept; - - bool RemoveChild (EntityID childID) noexcept; - bool RemoveChild (SHSceneNode* childToRemove) noexcept; - - void RemoveAllChildren () noexcept; - - private: - /*---------------------------------------------------------------------------------*/ - /* Data Members */ - /*---------------------------------------------------------------------------------*/ - - bool active; - EntityID entityID; - SHSceneNode* parent; - std::vector children; - }; - class SH_API SHSceneGraph { public: @@ -130,19 +64,22 @@ namespace SHADE /* Setter Functions */ /*---------------------------------------------------------------------------------*/ - void SetParent (EntityID entityID, SHSceneNode* parent) const noexcept; - void SetParent (EntityID entityID, EntityID parent) const noexcept; + void SetParent (EntityID entityID, SHSceneNode* newParent) noexcept; + void SetParent (EntityID entityID, EntityID newParent) noexcept; /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ SHSceneNode* AddNode (EntityID entityID, SHSceneNode* parent = nullptr); - bool RemoveNode (EntityID entityID) noexcept; - bool RemoveNode (SHSceneNode* nodeToRemove) noexcept; - void Reset () noexcept; + bool RemoveNode (EntityID entityID) noexcept; + bool RemoveNode (SHSceneNode* nodeToRemove) noexcept; + void Reset () noexcept; - void Traverse (const UnaryFunction& function) const; + bool IsChildOf (EntityID entityID, SHSceneNode* targetNode) noexcept; + bool IsChildOf (EntityID entityID, EntityID targetID) noexcept; + + void Traverse (const UnaryFunction& function) const; private: /*---------------------------------------------------------------------------------*/ @@ -156,20 +93,14 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - SHSceneNode* AllocateNode (EntityID entityID); - void ReleaseNode (SHSceneNode* node) noexcept; - static void TraverseAndInvokeFunction (const SHSceneNode* node, const UnaryFunction& function); - }; + SHSceneNode* AllocateNode (EntityID entityID); + void ReleaseNode (SHSceneNode* node) noexcept; - /*-----------------------------------------------------------------------------------*/ - /* Event Data Definitions */ - /*-----------------------------------------------------------------------------------*/ + void ChangeParent (SHSceneNode* node, SHSceneNode* newParent); + void AddChild (SHSceneNode* node, SHSceneNode* newChild); + void RemoveChild (SHSceneNode* node, SHSceneNode* childToRemove); - struct SHSceneGraphChangeParentEvent - { - SHSceneNode* node; - SHSceneNode* oldParent; - SHSceneNode* newParent; + static void TraverseAndInvokeFunction (const SHSceneNode* node, const UnaryFunction& function); }; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Scene/SHSceneGraphEvents.h b/SHADE_Engine/src/Scene/SHSceneGraphEvents.h new file mode 100644 index 00000000..ccdf06be --- /dev/null +++ b/SHADE_Engine/src/Scene/SHSceneGraphEvents.h @@ -0,0 +1,41 @@ +/**************************************************************************************** + * \file SHSceneGraphEvents.h + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for Scene Graph Events. + * + * \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 + +// Project Headers +#include "SHSceneNode.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Event Data Definitions */ + /*-----------------------------------------------------------------------------------*/ + + struct SHSceneGraphChangeParentEvent + { + SHSceneNode* node; + SHSceneNode* oldParent; + SHSceneNode* newParent; + }; + + struct SHSceneGraphAddChildEvent + { + SHSceneNode* parent; + SHSceneNode* childAdded; + }; + + struct SHSceneGraphRemoveChildEvent + { + SHSceneNode* parent; + SHSceneNode* childRemoved; + }; + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Scene/SHSceneNode.cpp b/SHADE_Engine/src/Scene/SHSceneNode.cpp new file mode 100644 index 00000000..b619d464 --- /dev/null +++ b/SHADE_Engine/src/Scene/SHSceneNode.cpp @@ -0,0 +1,143 @@ +/**************************************************************************************** + * \file SHSceneNode.c[[ + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Implementation for a Scene Node. + * + * \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 + +// Primary Header +#include "SHSceneNode.h" + +// Project Headers +#include "ECS_Base/Managers/SHEntityManager.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Constructors & Destructor Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHSceneNode::SHSceneNode(EntityID eid, SHSceneNode* parent) noexcept + : active { true } + , entityID { eid } + , parent { parent } + {} + + + SHSceneNode::SHSceneNode(const SHSceneNode& rhs) noexcept + : active { rhs.active } + , entityID { rhs.entityID } + , parent { rhs.parent } + { + std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); + } + + SHSceneNode::SHSceneNode(SHSceneNode&& rhs) noexcept + : active { rhs.active } + , entityID { rhs.entityID } + , parent { rhs.parent } + { + std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); + } + + SHSceneNode& SHSceneNode::operator=(const SHSceneNode& rhs) noexcept + { + if (this == &rhs) + return *this; + + active = rhs.active; + entityID = rhs.entityID; + parent = rhs.parent; + + children.clear(); + std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); + + return *this; + } + + SHSceneNode& SHSceneNode::operator=(SHSceneNode&& rhs) noexcept + { + active = rhs.active; + entityID = rhs.entityID; + parent = rhs.parent; + + children.clear(); + std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children)); + + return *this; + } + + /*-----------------------------------------------------------------------------------*/ + /* Getter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + bool SHSceneNode::IsActive() const noexcept + { + return active; + } + + EntityID SHSceneNode::GetEntityID() const noexcept + { + return entityID; + } + + SHSceneNode* SHSceneNode::GetParent() const noexcept + { + return parent; + } + + const std::vector& SHSceneNode::GetChildren() const noexcept + { + return children; + } + + SHSceneNode* SHSceneNode::GetChild(EntityID childID) const noexcept + { + //////////////////////////////////////// + // Error handling + if (!SHEntityManager::IsValidEID(childID)) + { + SHLOG_ERROR("Child Entity {} is invalid! Unable to get child from Entity {}", childID, entityID) + return nullptr; + } + + if (children.empty()) + { + SHLOG_WARNING("Entity {} has no children!", entityID) + return nullptr; + } + //////////////////////////////////////// + + // Find child + const auto ENTITY_MATCH = [&](const SHSceneNode* node) { return node->GetEntityID() == childID; }; + + const auto CHILD_ITER = std::ranges::find_if(children.begin(), children.end(),ENTITY_MATCH); + if (CHILD_ITER == children.end()) + { + SHLOG_WARNING("Entity {} is not a child of Entity {}! Unable to retrieve child node!", childID, entityID) + return nullptr; + } + + return *CHILD_ITER; + } + + /*-----------------------------------------------------------------------------------*/ + /* Setter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + void SHSceneNode::SetActive(bool newActiveState) noexcept + { + active = newActiveState; + + for (auto* child : children) + { + SetActive(newActiveState); + } + } + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Scene/SHSceneNode.h b/SHADE_Engine/src/Scene/SHSceneNode.h new file mode 100644 index 00000000..87bd8d0b --- /dev/null +++ b/SHADE_Engine/src/Scene/SHSceneNode.h @@ -0,0 +1,82 @@ +/**************************************************************************************** + * \file SHSceneNode.h + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for a Scene Node. + * + * \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 + +// Project Headers +#include "ECS_Base/Entity/SHEntity.h" +#include "SH_API.h" +#include "SHSceneGraph.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*-----------------------------------------------------------------------------------*/ + + class SHSceneGraph; + + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + class SH_API SHSceneNode + { + private: + /*---------------------------------------------------------------------------------*/ + /* Friends */ + /*---------------------------------------------------------------------------------*/ + + friend class SHSceneGraph; + + public: + /*---------------------------------------------------------------------------------*/ + /* Constructors & Destructor */ + /*---------------------------------------------------------------------------------*/ + + ~SHSceneNode () = default; + + SHSceneNode (EntityID eid, SHSceneNode* parent = nullptr) noexcept; + SHSceneNode (const SHSceneNode& rhs) noexcept; + SHSceneNode (SHSceneNode&& rhs) noexcept; + SHSceneNode& operator= (const SHSceneNode& rhs) noexcept; + SHSceneNode& operator= (SHSceneNode&& rhs) noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Getter Functions */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] bool IsActive () const noexcept; + [[nodiscard]] EntityID GetEntityID () const noexcept; + [[nodiscard]] SHSceneNode* GetParent () const noexcept; + [[nodiscard]] const std::vector& GetChildren () const noexcept; + + [[nodiscard]] SHSceneNode* GetChild (EntityID childID) const noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Setter Functions */ + /*---------------------------------------------------------------------------------*/ + + void SetActive (bool newActiveState) noexcept; + + private: + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + bool active; + EntityID entityID; + SHSceneNode* parent; + std::vector children; + }; +} // namespace SHADE + diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 4a73342e..f279bec1 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -26,13 +26,15 @@ of DigiPen Institute of Technology is prohibited. #include "Events/SHEventManager.hpp" #include "Physics/SHPhysicsSystem.h" +#include "Assets/SHAssetMacros.h" + namespace SHADE { /*-----------------------------------------------------------------------------------*/ /* Static Definitions */ /*----------------------------------------------------------------------------------*/ const std::string SHScriptEngine::DEFAULT_CSHARP_NAMESPACE = std::string("SHADE"); - const std::string SHScriptEngine::CSPROJ_DIR = "..\\..\\TempScriptsFolder"; + const std::string SHScriptEngine::CSPROJ_DIR = std::string(ASSET_ROOT) + "/Scripts"; const std::string SHScriptEngine::CSPROJ_PATH = std::string(CSPROJ_DIR) + "\\SHADE_Scripting.csproj"; /*-----------------------------------------------------------------------------------*/ @@ -262,18 +264,18 @@ namespace SHADE \n\ \n\ \n\ - ..\\bin\\Debug\\SHADE_Managed.dll\n\ - ..\\bin\\Release\\SHADE_Managed.dll\n\ + ..\\..\\bin\\Debug\\SHADE_Managed.dll\n\ + ..\\..\\bin\\Release\\SHADE_Managed.dll\n\ \n\ \n\ - ..\\bin\\Debug\\SHADE_CSharp.dll\n\ - ..\\bin\\Release\\SHADE_CSharp.dll\n\ + ..\\..\\bin\\Debug\\SHADE_CSharp.dll\n\ + ..\\..\\bin\\Release\\SHADE_CSharp.dll\n\ \n\ \n\ "; // Attempt to create the file - std::ofstream file(path); + std::ofstream file(path, std::ios::out | std::ios::trunc); if (!file.is_open()) throw std::runtime_error("Unable to create CsProj file!"); @@ -316,6 +318,20 @@ namespace SHADE return eventData->handle; } + SHEventHandle SHScriptEngine::onSceneNodeChildrenAdded(SHEventPtr eventPtr) + { + auto eventData = reinterpret_cast*>(eventPtr.get()); + csSceneNodeChildrenChanged(eventData->data->parent->GetEntityID()); + return eventData->handle; + } + + SHEventHandle SHScriptEngine::onSceneNodeChildrenRemoved(SHEventPtr eventPtr) + { + auto eventData = reinterpret_cast*>(eventPtr.get()); + csSceneNodeChildrenChanged(eventData->data->parent->GetEntityID()); + return eventData->handle; + } + /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/ @@ -379,6 +395,12 @@ namespace SHADE DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", "ExecuteLateUpdate" + ); + csScriptsExecuteDrawGizmos = dotNet.GetFunctionPtr + ( + DEFAULT_CSHARP_LIB_NAME, + DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", + "ExecuteOnDrawGizmos" ); csScriptsExecutePhysicsEvents = dotNet.GetFunctionPtr ( @@ -434,6 +456,12 @@ namespace SHADE DEFAULT_CSHARP_NAMESPACE + ".Collider", "OnCollisionShapeRemoved" ); + csSceneNodeChildrenChanged = dotNet.GetFunctionPtr + ( + DEFAULT_CSHARP_LIB_NAME, + DEFAULT_CSHARP_NAMESPACE + ".ChildListCache", + "OnChildrenChanged" + ); csEditorRenderScripts = dotNet.GetFunctionPtr ( DEFAULT_CSHARP_LIB_NAME, @@ -456,6 +484,7 @@ namespace SHADE void SHScriptEngine::registerEvents() { + /* Entity */ // Register for entity destroyed event std::shared_ptr> destroyedEventReceiver { @@ -463,26 +492,39 @@ namespace SHADE }; SHEventManager::SubscribeTo(SH_ENTITY_DESTROYED_EVENT, std::dynamic_pointer_cast(destroyedEventReceiver)); + /* Colliders */ // Register for collider added event std::shared_ptr> addedColliderEventReceiver { std::make_shared>(this, &SHScriptEngine::onColliderAdded) }; SHEventManager::SubscribeTo(SH_PHYSICS_COLLIDER_ADDED_EVENT, std::dynamic_pointer_cast(addedColliderEventReceiver)); - // Register for collider removed event std::shared_ptr> removedColliderEventReceiver { std::make_shared>(this, &SHScriptEngine::onColliderRemoved) }; SHEventManager::SubscribeTo(SH_PHYSICS_COLLIDER_REMOVED_EVENT, std::dynamic_pointer_cast(removedColliderEventReceiver)); - // Register for collider component removed event std::shared_ptr> removedColliderComponentEventReceiver { std::make_shared>(this, &SHScriptEngine::onColliderComponentRemoved) }; SHEventManager::SubscribeTo(SH_COMPONENT_REMOVED_EVENT, std::dynamic_pointer_cast(removedColliderComponentEventReceiver)); + + /* SceneGraph */ + // Register for SceneNode child added event + std::shared_ptr> addChildEventReceiver + { + std::make_shared>(this, &SHScriptEngine::onSceneNodeChildrenAdded) + }; + SHEventManager::SubscribeTo(SH_SCENEGRAPH_ADD_CHILD_EVENT, std::dynamic_pointer_cast(addChildEventReceiver)); + // Register for SceneNode child removed event + std::shared_ptr> removeChildEventReceiver + { + std::make_shared>(this, &SHScriptEngine::onSceneNodeChildrenRemoved) + }; + SHEventManager::SubscribeTo(SH_SCENEGRAPH_REMOVE_CHILD_EVENT, std::dynamic_pointer_cast(removeChildEventReceiver)); } void SHScriptEngine::dumpBuildLog(const std::string_view& buildLogPath) diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 9ddd617a..ef778627 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -55,6 +55,12 @@ namespace SHADE LateUpdateRoutine(); void Execute(double dt) noexcept override final; }; + class SH_API GizmosDrawRoutine final : public SHSystemRoutine + { + public: + GizmosDrawRoutine(); + void Execute(double dt) noexcept override final; + }; class SH_API FrameCleanUpRoutine final : public SHSystemRoutine { public: @@ -250,6 +256,7 @@ namespace SHADE CsFuncPtr csScriptsExecuteFixedUpdate = nullptr; CsFuncPtr csScriptsExecuteUpdate = nullptr; CsFuncPtr csScriptsExecuteLateUpdate = nullptr; + CsFuncPtr csScriptsExecuteDrawGizmos = nullptr; CsFuncPtr csScriptsExecutePhysicsEvents = nullptr; CsFuncPtr csScriptsFrameCleanUp = nullptr; CsScriptManipFuncPtr csScriptsAdd = nullptr; @@ -260,6 +267,7 @@ namespace SHADE // - Events CsEventRelayFuncPtr csColliderOnListChanged = nullptr; CsEventRelayFuncPtr csColliderOnRemoved = nullptr; + CsEventRelayFuncPtr csSceneNodeChildrenChanged = nullptr; // - Editor CsScriptEditorFuncPtr csEditorRenderScripts = nullptr; CsFuncPtr csEditorUndo = nullptr; @@ -272,6 +280,8 @@ namespace SHADE SHEventHandle onColliderAdded(SHEventPtr eventPtr); SHEventHandle onColliderRemoved(SHEventPtr eventPtr); SHEventHandle onColliderComponentRemoved(SHEventPtr eventPtr); + SHEventHandle onSceneNodeChildrenAdded(SHEventPtr eventPtr); + SHEventHandle onSceneNodeChildrenRemoved(SHEventPtr eventPtr); /*-----------------------------------------------------------------------------*/ /* Helper Functions */ diff --git a/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp b/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp index a2981c06..699776ca 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngineRoutines.cpp @@ -50,6 +50,17 @@ namespace SHADE reinterpret_cast(system)->csScriptsExecuteLateUpdate(); } + /*-----------------------------------------------------------------------------------*/ + /* System Routine Functions - GizmosDrawRoutine */ + /*-----------------------------------------------------------------------------------*/ + SHScriptEngine::GizmosDrawRoutine::GizmosDrawRoutine() + : SHSystemRoutine("Script Engine Gizmos Draw", true) + {} + void SHScriptEngine::GizmosDrawRoutine::Execute(double dt) noexcept + { + reinterpret_cast(system)->csScriptsExecuteDrawGizmos(); + } + /*-----------------------------------------------------------------------------------*/ /* System Routine Functions - FrameCleanUpRoutine */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Serialization/Configurations/SHConfigurationManager.h b/SHADE_Engine/src/Serialization/Configurations/SHConfigurationManager.h index abf679ca..767b8c2b 100644 --- a/SHADE_Engine/src/Serialization/Configurations/SHConfigurationManager.h +++ b/SHADE_Engine/src/Serialization/Configurations/SHConfigurationManager.h @@ -25,8 +25,8 @@ namespace SHADE class SH_API SHConfigurationManager { public: - static constexpr std::string_view applicationConfigPath{"../../Assets/Application.SHConfig"}; - static constexpr std::string_view editorConfigPath{"../../Assets/Editor/Editor.SHConfig"}; + static inline std::string applicationConfigPath{ std::string(ASSET_ROOT) + "/Application.SHConfig"}; + static inline std::string editorConfigPath{ std::string(ASSET_ROOT) + "/Editor/Editor.SHConfig"}; static void SaveApplicationConfig(); static SHApplicationConfig& LoadApplicationConfig(WindowData* wndData = nullptr); diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index d4b97244..1b93c63a 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -3,7 +3,7 @@ #include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" #include "Math/Geometry/SHBoundingBox.h" #include "Math/Geometry/SHBoundingSphere.h" -#include "Physics/SHCollider.h" +#include "Physics/SHCollisionShape.h" #include "Resource/SHResourceManager.h" #include "Math/Vector/SHVec2.h" #include "Math/Vector/SHVec3.h" @@ -101,7 +101,7 @@ namespace YAML }; template<> - struct convert + struct convert { static constexpr const char* IsTrigger = "Is Trigger"; @@ -114,33 +114,33 @@ namespace YAML static constexpr const char* Density = "Density"; static constexpr const char* PositionOffset = "Position Offset"; - static Node encode(SHCollider& rhs) + static Node encode(SHCollisionShape& rhs) { Node node; node[IsTrigger] = rhs.IsTrigger(); - rttr::type const shapeRttrType = rttr::type::get(); + rttr::type const shapeRttrType = rttr::type::get(); rttr::enumeration const enumAlign = shapeRttrType.get_enumeration(); - SHCollider::Type colliderType = rhs.GetType(); + SHCollisionShape::Type colliderType = rhs.GetType(); node[Type] = enumAlign.value_to_name(colliderType).data(); switch (colliderType) { - case SHCollider::Type::BOX: + case SHCollisionShape::Type::BOX: { auto const bb = reinterpret_cast(rhs.GetShape()); - node[HalfExtents] = bb->GetHalfExtents(); + node[HalfExtents] = bb->GetRelativeExtents(); } break; - case SHCollider::Type::SPHERE: + case SHCollisionShape::Type::SPHERE: { auto const bs = reinterpret_cast(rhs.GetShape()); - node[Radius] = bs->GetRadius(); + node[Radius] = bs->GetRelativeRadius(); } break; - case SHCollider::Type::CAPSULE: break; + case SHCollisionShape::Type::CAPSULE: break; default:; } @@ -151,33 +151,33 @@ namespace YAML return node; } - static bool decode(Node const& node, SHCollider& rhs) + static bool decode(Node const& node, SHCollisionShape& rhs) { if (node[IsTrigger].IsDefined()) rhs.SetIsTrigger(node[IsTrigger].as()); if (!node[Type].IsDefined()) return false; - rttr::type const shapeRttrType = rttr::type::get(); + rttr::type const shapeRttrType = rttr::type::get(); rttr::enumeration const enumAlign = shapeRttrType.get_enumeration(); bool ok; - const SHCollider::Type colliderType = enumAlign.name_to_value(node[Type].as()).convert(&ok); + const SHCollisionShape::Type colliderType = enumAlign.name_to_value(node[Type].as()).convert(&ok); if (!ok) return false; switch (colliderType) { - case SHCollider::Type::BOX: + case SHCollisionShape::Type::BOX: { if (node[HalfExtents].IsDefined()) - rhs.SetBoundingBox(node[HalfExtents].as() * 2.0f); + rhs.SetBoundingBox(node[HalfExtents].as()); } break; - case SHCollider::Type::SPHERE: + case SHCollisionShape::Type::SPHERE: { if (node[Radius].IsDefined()) rhs.SetBoundingSphere(node[Radius].as()); } break; - case SHCollider::Type::CAPSULE: break; + case SHCollisionShape::Type::CAPSULE: break; default:; } if (node[Friction].IsDefined()) @@ -200,12 +200,12 @@ namespace YAML static Node encode(SHColliderComponent& rhs) { Node node, collidersNode; - auto const& colliders = rhs.GetColliders(); + auto const& colliders = rhs.GetCollisionShapes(); int const numColliders = static_cast(colliders.size()); for (int i = 0; i < numColliders; ++i) { - auto& collider = rhs.GetCollider(i); - Node colliderNode = convert::encode(collider); + auto& collider = rhs.GetCollisionShape(i); + Node colliderNode = convert::encode(collider); if (colliderNode.IsDefined()) collidersNode[i] = colliderNode; } @@ -219,21 +219,21 @@ namespace YAML int numColliders{}; for (auto const& colliderNode : node[Colliders]) { - rttr::type const shapeRttrType = rttr::type::get(); + rttr::type const shapeRttrType = rttr::type::get(); rttr::enumeration const enumAlign = shapeRttrType.get_enumeration(); bool ok = false; - const SHCollider::Type colliderType = enumAlign.name_to_value(colliderNode[convert::Type].as()).convert(&ok); + const SHCollisionShape::Type colliderType = enumAlign.name_to_value(colliderNode[convert::Type].as()).convert(&ok); if (!ok) return false; switch (colliderType) { - case SHCollider::Type::BOX: rhs.AddBoundingBox(); break; - case SHCollider::Type::SPHERE: rhs.AddBoundingSphere(); break; - case SHCollider::Type::CAPSULE: break; + case SHCollisionShape::Type::BOX: rhs.AddBoundingBox(); break; + case SHCollisionShape::Type::SPHERE: rhs.AddBoundingSphere(); break; + case SHCollisionShape::Type::CAPSULE: break; default:; } - YAML::convert::decode(colliderNode, rhs.GetCollider(numColliders++)); + YAML::convert::decode(colliderNode, rhs.GetCollisionShape(numColliders++)); } } return true; diff --git a/SHADE_Managed/src/Components/Collider.cxx b/SHADE_Managed/src/Components/Collider.cxx index f2119b43..0e916b7b 100644 --- a/SHADE_Managed/src/Components/Collider.cxx +++ b/SHADE_Managed/src/Components/Collider.cxx @@ -55,11 +55,11 @@ namespace SHADE } Vector3 BoxCollider::HalfExtents::get() { - return Convert::ToCLI(getNativeBoundObject().GetHalfExtents()); + return Convert::ToCLI(getNativeBoundObject().GetWorldExtents()); } void BoxCollider::HalfExtents::set(Vector3 value) { - getNativeBoundObject().SetHalfExtents(Convert::ToNative(value)); + getNativeBoundObject().SetWorldExtents(Convert::ToNative(value)); } Vector3 BoxCollider::Min::get() { @@ -103,11 +103,11 @@ namespace SHADE } float SphereCollider::Radius::get() { - return getNativeBoundObject().GetRadius(); + return getNativeBoundObject().GetWorldRadius(); } void SphereCollider::Radius::set(float value) { - getNativeBoundObject().SetRadius(value); + getNativeBoundObject().SetWorldRadius(value); } /*---------------------------------------------------------------------------------*/ @@ -150,7 +150,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ int Collider::CollisionShapeCount::get() { - return static_cast(GetNativeComponent()->GetColliders().size()); + return static_cast(GetNativeComponent()->GetCollisionShapes().size()); } /*---------------------------------------------------------------------------------*/ @@ -230,18 +230,18 @@ namespace SHADE // Populate the list int i = 0; - for (const auto& collider : GetNativeComponent()->GetColliders()) + for (const auto& collider : GetNativeComponent()->GetCollisionShapes()) { CollisionShape^ bound = nullptr; switch (collider.GetType()) { - case SHCollider::Type::BOX: + case SHCollisionShape::Type::BOX: bound = gcnew BoxCollider(i, Owner.GetEntity()); break; - case SHCollider::Type::SPHERE: + case SHCollisionShape::Type::SPHERE: bound = gcnew SphereCollider(i, Owner.GetEntity()); break; - case SHCollider::Type::CAPSULE: + case SHCollisionShape::Type::CAPSULE: // TODO break; default: diff --git a/SHADE_Managed/src/Components/Collider.h++ b/SHADE_Managed/src/Components/Collider.h++ index 1f8b43eb..6e165619 100644 --- a/SHADE_Managed/src/Components/Collider.h++ +++ b/SHADE_Managed/src/Components/Collider.h++ @@ -27,11 +27,11 @@ namespace SHADE try { - auto& bounds = collider->GetCollider(arrayIndex); - if (bounds.GetType() != SHCollider::Type::BOX) + auto& shape = collider->GetCollisionShape(arrayIndex); + if (shape.GetType() != SHCollisionShape::Type::BOX) throw gcnew System::InvalidOperationException("Attempted to retrieve invalid ColliderBound."); - return reinterpret_cast(bounds); + return reinterpret_cast(shape); } catch (std::invalid_argument&) { diff --git a/SHADE_Managed/src/Components/Component.hxx b/SHADE_Managed/src/Components/Component.hxx index 5ffa3952..e52ab3a7 100644 --- a/SHADE_Managed/src/Components/Component.hxx +++ b/SHADE_Managed/src/Components/Component.hxx @@ -97,7 +97,7 @@ namespace SHADE /// /// Removes all Scripts of the specified type from this GameObject. /// - /// Type of PLushieScripts to remove. + /// Type of Scripts to remove. generic where T : ref class, Script void RemoveScript(); diff --git a/SHADE_Managed/src/Components/Light.cxx b/SHADE_Managed/src/Components/Light.cxx new file mode 100644 index 00000000..a220c79a --- /dev/null +++ b/SHADE_Managed/src/Components/Light.cxx @@ -0,0 +1,79 @@ +/************************************************************************************//*! +\file Light.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 8, 2022 +\brief Contains the definition of the functions of the managed Light class. + + Note: This file is written in C++17/CLI. + +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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Light.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + Light::Light(Entity entity) + : Component(entity) + {} + + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + Vector3 Light::Position::get() + { + return Convert::ToCLI(GetNativeComponent()->GetPosition()); + } + void Light::Position::set(Vector3 value) + { + GetNativeComponent()->SetPosition(Convert::ToNative(value)); + } + Light::Type Light::LightType::get() + { + return static_cast(GetNativeComponent()->GetType()); + } + void Light::LightType::set(Light::Type value) + { + GetNativeComponent()->SetType(static_cast(value)); + } + Vector3 Light::Direction::get() + { + return Convert::ToCLI(GetNativeComponent()->GetDirection()); + } + void Light::Direction::set(Vector3 value) + { + GetNativeComponent()->SetDirection(Convert::ToNative(value)); + } + Color Light::Color::get() + { + return Convert::ToCLI(SHColour(GetNativeComponent()->GetColor())); + } + void Light::Color::set(SHADE::Color value) + { + GetNativeComponent()->SetColor(Convert::ToNative(value)); + } + System::UInt32 Light::CullingMask::get() + { + return GetNativeComponent()->GetCullingMask(); + } + void Light::CullingMask::set(System::UInt32 value) + { + GetNativeComponent()->SetCullingMask(value); + } + float Light::Strength::get() + { + return GetNativeComponent()->GetStrength(); + } + void Light::Strength::set(float value) + { + GetNativeComponent()->SetStrength(value); + } +} diff --git a/SHADE_Managed/src/Components/Light.hxx b/SHADE_Managed/src/Components/Light.hxx new file mode 100644 index 00000000..9abb05d5 --- /dev/null +++ b/SHADE_Managed/src/Components/Light.hxx @@ -0,0 +1,125 @@ +/************************************************************************************//*! +\file Light.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 8, 2022 +\brief Contains the definition of the managed Light class with the declaration + of functions for working with it. + + Note: This file is written in C++17/CLI. + +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 + +// Project Includes +#include "Components/Component.hxx" +#include "Math/Vector3.hxx" +// External Dependencies +#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" + +namespace SHADE +{ + /// + /// CLR version of the SHADE Engine's SHLightComponent. + /// + public ref class Light : public Component + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructs a Light Component that represents a native Light component tied to + /// the specified Entity. + /// + /// Entity that this Component will be tied to. + Light(Entity entity); + + public: + /*-----------------------------------------------------------------------------*/ + /* Constants */ + /*-----------------------------------------------------------------------------*/ + /// + /// Supported types of the Light Component. + /// + enum class Type + { + /// + /// Light applied uniformly across the scene at a specified direction. + /// + Directional, + /// + /// Light that originates from a certain point in all directions. + /// Not implemented yet. + /// + Point, + /// + /// Light that originates from a certain point within a angle. + /// Not implemented yet. + /// + Spot, + /// + /// Light applied to all objects. Has no source point. + /// + Ambient + }; + + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Position of the light. Only works for Point Light (unimplemented). + /// + [System::ObsoleteAttribute("Not implemented yet.", true)] + property Vector3 Position + { + Vector3 get(); + void set(Vector3 val); + } + /// + /// Type of lighting that this Light component will apply onto the scene. + /// + property Type LightType + { + Type get(); + void set(Type val); + } + /// + /// Direction of the light. Only applicable for Directional Lights. + /// + property Vector3 Direction + { + Vector3 get(); + void set(Vector3 val); + } + /// + /// Colour of the Light. + /// + property SHADE::Color Color + { + SHADE::Color get(); + void set(SHADE::Color val); + } + /// + /// Culling mask that is used to control what types of Materials would be + /// affected by this Light. + /// + property System::UInt32 CullingMask + { + System::UInt32 get(); + void set(System::UInt32 val); + } + /// + /// Intensity of the Light + /// + property float Strength + { + float get(); + void set(float val); + } + }; +} + diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index 2afe9697..54200c1e 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -414,19 +414,10 @@ namespace SHADE generic Attribute Editor::hasAttribute(System::Reflection::FieldInfo^ field) { - array^ attributes = field->GetCustomAttributes(true); - for each (System::Object^ attrib in attributes) + array^ attributes = field->GetCustomAttributes(Attribute::typeid, false); + if (attributes->Length > 0) { - try - { - Attribute attribute = safe_cast(attrib); - if (attribute != nullptr) - return attribute; - } - catch (System::InvalidCastException^) - { - continue; - } + return safe_cast(attributes[0]); } // Failed to find return Attribute{}; diff --git a/SHADE_Managed/src/Editor/Editor.hxx b/SHADE_Managed/src/Editor/Editor.hxx index 6b59589a..109842b5 100644 --- a/SHADE_Managed/src/Editor/Editor.hxx +++ b/SHADE_Managed/src/Editor/Editor.hxx @@ -39,10 +39,10 @@ namespace SHADE /// The Entity to render the Scripts of. static void RenderScriptsInInspector(Entity entity); /// - /// Renders a dropdown button that allows for the addition of PlushieScripts - /// onto the specified Entity. + /// Renders a dropdown button that allows for the addition of Scripts onto the + /// specified Entity. /// - /// The Entity to add PlushieScripts to. + /// The Entity to add Scripts to. static void RenderScriptAddButton(Entity entity); /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Engine/ChildListCache.cxx b/SHADE_Managed/src/Engine/ChildListCache.cxx new file mode 100644 index 00000000..b183646f --- /dev/null +++ b/SHADE_Managed/src/Engine/ChildListCache.cxx @@ -0,0 +1,89 @@ +/************************************************************************************//*! +\file ChildListCache.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 11, 2022 +\brief Contains the definition of the functions for the ChildListCache managed + class. + + Note: This file is written in C++17/CLI. + +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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "ChildListCache.hxx" +// External Dependencies +#include "Scene/SHSceneManager.h" +// Project Headers +#include "Utility/Debug.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Static Usage Functions */ + /*---------------------------------------------------------------------------------*/ + ChildListCache::ChildEnumerable^ ChildListCache::GetChildList(Entity entity) + { + // Ignore if invalid + if (entity == MAX_EID) + return nullptr; + + // Check if in cache + if (cachedLists->ContainsKey(entity)) + return cachedLists[entity]; + + // Grab the native child list + auto node = GameObject(entity).GetSceneNode(); + if (!node || node->GetChildren().empty()) + return nullptr; + + // Otherwise + // - Create the list + ChildList^ list = gcnew ChildList(); + updateChildList(list, node); + // - Cache it + cachedLists[entity] = list; + + return list; + } + + void ChildListCache::UpdateChildList(Entity entity) + { + // Ignore if invalid + if (entity == MAX_EID) + return; + + // Check if in cache + if (!cachedLists->ContainsKey(entity)) + return; + + // Update + updateChildList(cachedLists[entity], GameObject(entity).GetSceneNode()); + } + + /*---------------------------------------------------------------------------------*/ + /* Event Handling Functions */ + /*---------------------------------------------------------------------------------*/ + void ChildListCache::OnChildrenChanged(EntityID entity) + { + SAFE_NATIVE_CALL_BEGIN + UpdateChildList(entity); + SAFE_NATIVE_CALL_END_N("SHADE_Managed.ChildListCache") + } + + /*---------------------------------------------------------------------------------*/ + /* Helper Functions */ + /*---------------------------------------------------------------------------------*/ + void ChildListCache::updateChildList(ChildList^ list, const SHSceneNode* sceneNode) + { + list->Clear(); + for (auto node : sceneNode->GetChildren()) + { + list->Add(GameObject(node->GetEntityID())); + } + } +} diff --git a/SHADE_Managed/src/Engine/ChildListCache.hxx b/SHADE_Managed/src/Engine/ChildListCache.hxx new file mode 100644 index 00000000..1a2637d3 --- /dev/null +++ b/SHADE_Managed/src/Engine/ChildListCache.hxx @@ -0,0 +1,80 @@ +/************************************************************************************//*! +\file ChildListCache.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 11, 2022 +\brief Contains the definition of the ChildListCache managed class. + + Note: This file is written in C++17/CLI. + +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 + +// Project Includes +#include "GameObject.hxx" + +namespace SHADE { } + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*---------------------------------------------------------------------------------*/ + class SHSceneNode; + + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Static class that caches all the lists of children for GameObjects. + /// + private ref class ChildListCache abstract sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------*/ + using ChildList = System::Collections::Generic::List; + using ChildEnumerable = System::Collections::Generic::IEnumerable; + using ListMap = System::Collections::Generic::Dictionary; + + internal: + /*-----------------------------------------------------------------------------*/ + /* Static Usage Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Retrieves the children list for the specified Entity. + /// + /// + /// Enumerable read only list of an Entity's children. Null if entity is invalid + /// or there are no children. + /// + static ChildEnumerable^ GetChildList(Entity entity); + /// + /// Updates the children list for the specified Entity if it exists. + /// + static void UpdateChildList(Entity entity); + + /*-----------------------------------------------------------------------------*/ + /* Event Handling Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// To be + /// + static void OnChildrenChanged(EntityID entity); + + private: + /*-----------------------------------------------------------------------------*/ + /* Static Data Members */ + /*-----------------------------------------------------------------------------*/ + static ListMap^ cachedLists = gcnew ListMap(); + + /*-----------------------------------------------------------------------------*/ + /* Helper Functions */ + /*-----------------------------------------------------------------------------*/ + static void updateChildList(ChildList^ list, const SHSceneNode* sceneNode); + }; +} \ No newline at end of file diff --git a/SHADE_Managed/src/Engine/ECS.cxx b/SHADE_Managed/src/Engine/ECS.cxx index 3da39394..00c3c182 100644 --- a/SHADE_Managed/src/Engine/ECS.cxx +++ b/SHADE_Managed/src/Engine/ECS.cxx @@ -22,8 +22,8 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "ECS_Base/Managers/SHEntityManager.h" #include "Math/Transform/SHTransformComponent.h" -#include "Physics\Components\SHColliderComponent.h" -#include "Physics\Components\SHRigidBodyComponent.h" +#include "Physics/Components/SHColliderComponent.h" +#include "Physics/Components/SHRigidBodyComponent.h" #include "Scene/SHSceneManager.h" #include "Scene/SHSceneGraph.h" #include "Tools/SHLog.h" @@ -31,10 +31,11 @@ of DigiPen Institute of Technology is prohibited. #include "Utility/Convert.hxx" #include "Utility/Debug.hxx" #include "Components/Transform.hxx" -#include "Components\RigidBody.hxx" -#include "Components\Collider.hxx" +#include "Components/RigidBody.hxx" +#include "Components/Collider.hxx" #include "Components/Camera.hxx" #include "Components/CameraArm.hxx" +#include "Components/Light.hxx" namespace SHADE { @@ -252,6 +253,7 @@ namespace SHADE componentMap.Add(createComponentSet()); componentMap.Add(createComponentSet()); componentMap.Add(createComponentSet()); + componentMap.Add(createComponentSet()); } /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Engine/EngineInterface.hxx b/SHADE_Managed/src/Engine/EngineInterface.hxx index 4fd8f7b3..37ded4eb 100644 --- a/SHADE_Managed/src/Engine/EngineInterface.hxx +++ b/SHADE_Managed/src/Engine/EngineInterface.hxx @@ -20,7 +20,7 @@ namespace SHADE { /// /// Static class that contains the functions for interfacing with the core - /// PlushieEngine written in C++ for managing the lifecycle of managed code. + /// SHADE Engine written in C++ for managing the lifecycle of managed code. /// private ref class EngineInterface abstract sealed { diff --git a/SHADE_Managed/src/Engine/GameObject.cxx b/SHADE_Managed/src/Engine/GameObject.cxx index 9f15c6c9..017366fe 100644 --- a/SHADE_Managed/src/Engine/GameObject.cxx +++ b/SHADE_Managed/src/Engine/GameObject.cxx @@ -23,6 +23,7 @@ of DigiPen Institute of Technology is prohibited. #include "Utility/Convert.hxx" #include "Scripts/ScriptStore.hxx" #include "Utility/Debug.hxx" +#include "ChildListCache.hxx" namespace SHADE { @@ -87,30 +88,43 @@ namespace SHADE throw gcnew System::NullReferenceException(); return entity; } - GameObject^ GameObject::Parent::get() + GameObject GameObject::Parent::get() { if (!valid) throw gcnew System::NullReferenceException(); + const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); const auto* ROOT = SCENE_GRAPH.GetRoot(); - const auto* NODE = SCENE_GRAPH.GetNode(entity); if (NODE == nullptr) throw gcnew System::InvalidOperationException("Unable to retrieve SceneGraphNode for Entity " + entity.ToString()); const auto* PARENT = NODE->GetParent(); - return PARENT != ROOT ? gcnew GameObject(PARENT->GetEntityID()) : nullptr; + return PARENT != ROOT ? GameObject(PARENT->GetEntityID()) : GameObject(); } - void GameObject::Parent::set(GameObject^ newParent) + void GameObject::Parent::set(GameObject newParent) { if (!valid) throw gcnew System::NullReferenceException(); - const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); - if (newParent == nullptr) - SCENE_GRAPH.SetParent(entity, nullptr); + if (newParent) + SCENE_GRAPH.SetParent(entity, newParent.EntityId); else - SCENE_GRAPH.SetParent(entity, newParent->EntityId); + SCENE_GRAPH.SetParent(entity, nullptr); + } + int GameObject::ChildCount::get() + { + if (!valid) + throw gcnew System::NullReferenceException(); + + const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + const auto* ROOT = SCENE_GRAPH.GetRoot(); + const auto* NODE = SCENE_GRAPH.GetNode(entity); + if (NODE == nullptr) + throw gcnew System::InvalidOperationException("Unable to retrieve SceneGraphNode for Entity " + entity.ToString()); + + return static_cast(NODE->GetChildren().size()); } /*---------------------------------------------------------------------------------*/ @@ -215,6 +229,90 @@ namespace SHADE ScriptStore::RemoveScript(entity); } + /*---------------------------------------------------------------------------------*/ + /* Scene Graph Functions */ + /*---------------------------------------------------------------------------------*/ + void GameObject::DetachChildren() + { + // Validity Checks + if (!valid) + throw gcnew System::NullReferenceException(); + auto node = GetSceneNode(); + if (!node) + throw gcnew System::NullReferenceException(); + + // Unparent all children to the root + for (auto child : node->GetChildren()) + { + SHSceneManager::GetCurrentSceneGraph().SetParent(child->GetEntityID(), nullptr); + } + ChildListCache::UpdateChildList(entity); + } + + GameObject GameObject::GetChild(int index) + { + // Validity Checks + if (!valid) + throw gcnew System::NullReferenceException(); + auto node = GetSceneNode(); + if (!node) + throw gcnew System::NullReferenceException(); + + auto child = node->GetChild(index); + return child ? GameObject(child->GetEntityID()) : GameObject(); + } + + System::Collections::Generic::IEnumerable^ GameObject::GetChildren() + { + // Validity Checks + if (!valid) + throw gcnew System::NullReferenceException(); + return ChildListCache::GetChildList(entity); + } + + int GameObject::GetSiblingIndex() + { + throw gcnew System::NotImplementedException(); + } + + bool GameObject::IsChildOf(GameObject gameObj) + { + // Search parents recursively + auto node = GetSceneNode(); + while (node != nullptr) + { + if (node->GetEntityID() == gameObj.entity) + return true; + + // Go up higher + node = node->GetParent(); + } + return false; + } + + void GameObject::SetAsFirstSibling() + { + throw gcnew System::NotImplementedException(); + } + + void GameObject::SetAsLastSibling() + { + throw gcnew System::NotImplementedException(); + } + + void GameObject::SetSiblingIndex(int index) + { + throw gcnew System::NotImplementedException(); + } + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + GameObject::operator bool(GameObject gameObj) + { + return gameObj.valid; + } + /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/ @@ -245,11 +343,15 @@ namespace SHADE } /*---------------------------------------------------------------------------------*/ - /* Operator Overloads */ + /* Helper Functions */ /*---------------------------------------------------------------------------------*/ - GameObject::operator bool(GameObject gameObj) + SHSceneNode* GameObject::GetSceneNode() { - return gameObj.valid; + const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + const auto* ROOT = SCENE_GRAPH.GetRoot(); + if (!ROOT) + return nullptr; + return SCENE_GRAPH.GetNode(entity); } /*---------------------------------------------------------------------------------*/ @@ -290,4 +392,21 @@ namespace SHADE { return !(lhs == rhs); } + + /*---------------------------------------------------------------------------------*/ + /* IEnummerable */ + /*---------------------------------------------------------------------------------*/ + System::Collections::Generic::IEnumerator^ GameObject::GetEnumerator() + { + System::Collections::Generic::IEnumerable^ childList = GetChildren(); + if (childList == nullptr) + return System::Linq::Enumerable::Empty()->GetEnumerator(); + else + return childList->GetEnumerator(); + } + + System::Collections::IEnumerator^ GameObject::GetEnumeratorNonGeneric() + { + return GetEnumerator(); + } } diff --git a/SHADE_Managed/src/Engine/GameObject.hxx b/SHADE_Managed/src/Engine/GameObject.hxx index 030b917c..2e0f360c 100644 --- a/SHADE_Managed/src/Engine/GameObject.hxx +++ b/SHADE_Managed/src/Engine/GameObject.hxx @@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { /*---------------------------------------------------------------------------------*/ - /* Forward Declarations */ + /* Forward Declarations */ /*---------------------------------------------------------------------------------*/ ref class Script; ref class BaseComponent; @@ -32,8 +32,9 @@ namespace SHADE /// Lightweight object for an Entity that allows for easy access to Component and /// Script operations. /// Can be set to a invalid/null GameObject by default construction. + /// Can also be iterated to access children. /// - public value class GameObject : public System::IEquatable + public value class GameObject : public System::IEquatable, public System::Collections::Generic::IEnumerable { public: /*-----------------------------------------------------------------------------*/ @@ -97,10 +98,17 @@ namespace SHADE /// /// The parent entity for this GameObject. /// - property GameObject^ Parent + property GameObject Parent { - GameObject^ get(); - void set(GameObject^); + GameObject get(); + void set(GameObject); + } + /// + /// Number of Children held by this GameObject + /// + property int ChildCount + { + int get(); } /*-----------------------------------------------------------------------------*/ @@ -120,8 +128,7 @@ namespace SHADE /// /// Whether to activate or deactivate this GameObject. /// - void SetActive(bool active); - + void SetActive(bool active); /*-----------------------------------------------------------------------------*/ /* Component Access Functions */ @@ -210,10 +217,86 @@ namespace SHADE /// /// Removes all Scripts of the specified type from this GameObject. /// - /// Type of PLushieScripts to remove. + /// Type of Scripts to remove. generic where T : ref class, Script void RemoveScript(); + /*-----------------------------------------------------------------------------*/ + /* Scene Graph Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Unparents all children. Useful if you want to destroy the root of a hierarchy + /// without destroying the children. + /// + void DetachChildren(); + /// + /// Returns a child by index. + /// + /// Index of the child GameObject to retrieve. + /// + /// Handle to the GameObject if the index is valid. Invalid GameObject otherwise. + /// + GameObject GetChild(int index); + /// + /// Returns a cached enumerable container of child GameObjects of this + /// GameObject. + /// + /// + /// Enumerable container of child GameObjects of this GameObject. Null if + /// ChildCount is 0. + /// + System::Collections::Generic::IEnumerable^ GetChildren(); + /// + /// Gets the sibling index. Use GetSiblingIndex to find out the GameObject’s + /// place in this hierarchy. When the sibling index of a GameObject is changed, + /// its order in the Hierarchy window will also change. + /// + /// + /// Index of this GameObject among the parent GameObject's children. + /// + [System::ObsoleteAttribute("Not yet implemented.", true)] + int GetSiblingIndex(); + /// + /// Checks if this GameObject a direct or indirect child of the specified + /// GameObject. + /// + /// + /// True if this GameObject is a child, deep child (child of a child) or + /// identical to this GameObject, otherwise false. + /// + bool IsChildOf(GameObject gameObj); + /// + /// Move the GameObject to the start of the parent GameObject's children list. + /// + [System::ObsoleteAttribute("Not yet implemented.", true)] + void SetAsFirstSibling(); + /// + /// Move the GameObject to the end of the parent GameObject's children list. + /// + [System::ObsoleteAttribute("Not yet implemented.", true)] + void SetAsLastSibling(); + /// + /// Move the GameObject to the specified position in the parent GameObject's + /// children list. An existing object at that position if any, will be pushed + /// to the next index (existing element will be at index + 1). + /// + /// + /// Position to place this GameObject at in the hierarchy. Clamped to between + /// [0, parent.ChildCount]. + /// + [System::ObsoleteAttribute("Not yet implemented.", true)] + void SetSiblingIndex(int index); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a GameObject is valid. + /// + /// GameObjects to check. + /// True if the GameObject is valid. + static operator bool(GameObject gameObj); + internal: /*-----------------------------------------------------------------------------*/ /* Constructors */ @@ -249,13 +332,13 @@ namespace SHADE SHEntity& GetNativeEntity(); /*-----------------------------------------------------------------------------*/ - /* Operator Overloads */ + /* Helper Functions */ /*-----------------------------------------------------------------------------*/ /// - /// Implicit conversion operator to enable checking if a GameObject is valid. + /// Retrieves the SceneNode for this GameObject's referenced entity. /// - /// GameObjects to check. - static operator bool(GameObject gameObj); + /// Pointer to the SceneNode for this GameObject.. + SHSceneNode* GetSceneNode(); private: /*-----------------------------------------------------------------------------*/ @@ -304,6 +387,14 @@ namespace SHADE /// Another GameObject to check with. /// True if both Components are different. static bool operator!=(GameObject lhs, GameObject rhs); + + /*-----------------------------------------------------------------------------*/ + /* IEnummerable */ + /*-----------------------------------------------------------------------------*/ + /// + System::Collections::Generic::IEnumerator^ GetEnumerator() override; + /// + System::Collections::IEnumerator^ GetEnumeratorNonGeneric() override = System::Collections::IEnumerable::GetEnumerator; }; } diff --git a/SHADE_Managed/src/Graphics/Color.hxx b/SHADE_Managed/src/Graphics/Color.hxx index d6a46216..64152394 100644 --- a/SHADE_Managed/src/Graphics/Color.hxx +++ b/SHADE_Managed/src/Graphics/Color.hxx @@ -25,95 +25,85 @@ namespace SHADE { public: /*-----------------------------------------------------------------------------*/ - /* Type Definitions */ + /* Properties */ /*-----------------------------------------------------------------------------*/ /// - /// A static class that contains a set of default Colors. + /// Pure black. /// - ref class Defaults abstract sealed + static property Color Black { - public: - /*-------------------------------------------------------------------------*/ - /* Properties */ - /*-------------------------------------------------------------------------*/ - /// - /// Pure black. - /// - static property Color Black - { - Color get() { return Color(0.0f, 0.0f, 0.0f); } - } - /// - /// Light Gray, lighter than gray. - /// - static property Color LightGray - { - Color get() { return Color(0.827451f, 0.827451f, 0.827451f); } - } - /// - /// Gray, halfway between black and white. - /// - static property Color Gray - { - Color get() { return Color(0.5f, 0.5f, 0.5f); } - } - /// - /// Dark Gray, darker than gray. - /// - static property Color DarkGray - { - Color get() { return Color(0.622f, 0.622f, 0.622f); } - } - /// - /// Pure white. - /// - static property Color White - { - Color get() { return Color(1.0f, 1.0f, 1.0f); } - } - /// - /// Pure red. - /// - static property Color Red - { - Color get() { return Color(1.0f, 0.0f, 0.0f); } - } - /// - /// Pure green. - /// - static property Color Green - { - Color get() { return Color(0.0f, 1.0f, 0.0f); } - } - /// - /// Pure blue. - /// - static property Color Blue - { - Color get() { return Color(0.0f, 0.0f, 1.0f); } - } - /// - /// Pure cyan, mix of pure green and blue. - /// - static property Color Cyan - { - Color get() { return Color(0.0f, 1.0f, 1.0f); } - } - /// - /// Pure magenta, mix of pure red and blue. - /// - static property Color Magenta - { - Color get() { return Color(1.0f, 0.0f, 1.0f); } - } - /// - /// Pure yellow, mix of pure red and green. - /// - static property Color Yellow - { - Color get() { return Color(1.0f, 1.0f, 0.0f); } - } - }; + Color get() { return Color(0.0f, 0.0f, 0.0f); } + } + /// + /// Light Gray, lighter than gray. + /// + static property Color LightGray + { + Color get() { return Color(0.827451f, 0.827451f, 0.827451f); } + } + /// + /// Gray, halfway between black and white. + /// + static property Color Gray + { + Color get() { return Color(0.5f, 0.5f, 0.5f); } + } + /// + /// Dark Gray, darker than gray. + /// + static property Color DarkGray + { + Color get() { return Color(0.622f, 0.622f, 0.622f); } + } + /// + /// Pure white. + /// + static property Color White + { + Color get() { return Color(1.0f, 1.0f, 1.0f); } + } + /// + /// Pure red. + /// + static property Color Red + { + Color get() { return Color(1.0f, 0.0f, 0.0f); } + } + /// + /// Pure green. + /// + static property Color Green + { + Color get() { return Color(0.0f, 1.0f, 0.0f); } + } + /// + /// Pure blue. + /// + static property Color Blue + { + Color get() { return Color(0.0f, 0.0f, 1.0f); } + } + /// + /// Pure cyan, mix of pure green and blue. + /// + static property Color Cyan + { + Color get() { return Color(0.0f, 1.0f, 1.0f); } + } + /// + /// Pure magenta, mix of pure red and blue. + /// + static property Color Magenta + { + Color get() { return Color(1.0f, 0.0f, 1.0f); } + } + /// + /// Pure yellow, mix of pure red and green. + /// + static property Color Yellow + { + Color get() { return Color(1.0f, 1.0f, 0.0f); } + } /*-----------------------------------------------------------------------------*/ /* Constructors */ diff --git a/SHADE_Managed/src/Math/Vector2.cxx b/SHADE_Managed/src/Math/Vector2.cxx index 42080d60..8242a11c 100644 --- a/SHADE_Managed/src/Math/Vector2.cxx +++ b/SHADE_Managed/src/Math/Vector2.cxx @@ -276,4 +276,4 @@ namespace SHADE { return !(lhs == rhs); } -} // namespace PlushieAPI::Mathematics \ No newline at end of file +} diff --git a/SHADE_Managed/src/Math/Vector3.cxx b/SHADE_Managed/src/Math/Vector3.cxx index 83adbb38..f2286aa7 100644 --- a/SHADE_Managed/src/Math/Vector3.cxx +++ b/SHADE_Managed/src/Math/Vector3.cxx @@ -294,4 +294,4 @@ namespace SHADE { return Vector3(vec); } -} // namespace PlushieAPI::Mathematics \ No newline at end of file +} diff --git a/SHADE_Managed/src/Math/Vector3.hxx b/SHADE_Managed/src/Math/Vector3.hxx index 4cdf653e..189f2930 100644 --- a/SHADE_Managed/src/Math/Vector3.hxx +++ b/SHADE_Managed/src/Math/Vector3.hxx @@ -439,4 +439,5 @@ namespace SHADE /// Vector2 to convert from. static explicit operator Vector3(Vector2 vec); }; -} // namespace PlushieAPI::Mathematics +} + diff --git a/SHADE_Managed/src/Scripts/Script.cxx b/SHADE_Managed/src/Scripts/Script.cxx index e476d69d..9d6cadb8 100644 --- a/SHADE_Managed/src/Scripts/Script.cxx +++ b/SHADE_Managed/src/Scripts/Script.cxx @@ -3,8 +3,7 @@ \author Tng Kah Wei, kahwei.tng, 390009620 \par email: kahwei.tng\@digipen.edu \date Oct 28, 2021 -\brief Contains the definition of the functions for the PlushieScript managed - class. +\brief Contains the definition of the functions for the Script managed class. Note: This file is written in C++17/CLI. @@ -140,6 +139,13 @@ namespace SHADE lateUpdate(); SAFE_NATIVE_CALL_END(this) } + void Script::OnDrawGizmos() + { + SAFE_NATIVE_CALL_BEGIN + OnGizmosDrawOverriden = true; + onDrawGizmos(); + SAFE_NATIVE_CALL_END(this) + } void Script::OnDestroy() { SAFE_NATIVE_CALL_BEGIN @@ -194,6 +200,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ Script::Script(GameObject gameObj) : owner { gameObj } + , OnGizmosDrawOverriden { false } {} /*---------------------------------------------------------------------------------*/ @@ -210,6 +217,10 @@ namespace SHADE void Script::fixedUpdate() {} void Script::update() {} void Script::lateUpdate() {} + void Script::onDrawGizmos() + { + OnGizmosDrawOverriden = false; + } void Script::onDestroy() {} /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Scripts/Script.hxx b/SHADE_Managed/src/Scripts/Script.hxx index afeaa8a0..bbe36784 100644 --- a/SHADE_Managed/src/Scripts/Script.hxx +++ b/SHADE_Managed/src/Scripts/Script.hxx @@ -164,6 +164,14 @@ namespace SHADE static operator bool(Script^ s); internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// If true, the OnGizmosDraw function was overridden. + /// + bool OnGizmosDrawOverriden; + /*-----------------------------------------------------------------------------*/ /* "All-Time" Lifecycle Functions */ /*-----------------------------------------------------------------------------*/ @@ -208,6 +216,11 @@ namespace SHADE /// void LateUpdate(); /// + /// Used to call onDrawGizmos(). This should be called just before rendering + /// the scene. This will only be called when working in the editor. + /// + void OnDrawGizmos(); + /// /// Used to call onDestroy(). This should be called at the end of the frame /// where the attached GameObject or this script is destroyed directly or /// indirectly due to destruction of the owner. @@ -308,6 +321,10 @@ namespace SHADE /// virtual void lateUpdate(); /// + /// Called every frame just before rendering but only if working in the editor. + /// + virtual void onDrawGizmos(); + /// /// Called just before the end of the frame where the attached GameObject or /// this script is destroyed directly or indirectly due to destruction of the /// owner. diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 407d0fa8..a90b4f12 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -478,6 +478,24 @@ namespace SHADE SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") } + void ScriptStore::ExecuteOnDrawGizmos() + { + SAFE_NATIVE_CALL_BEGIN + for each (System::Collections::Generic::KeyValuePair entity in scripts) + { + // Check active state + if (!isEntityActive(entity.Key)) + continue; + + // Update each script + for each (Script^ script in entity.Value) + { + script->OnDrawGizmos(); + } + } + SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") + } + void ScriptStore::ExecuteCollisionFunctions() { SAFE_NATIVE_CALL_BEGIN diff --git a/SHADE_Managed/src/Scripts/ScriptStore.hxx b/SHADE_Managed/src/Scripts/ScriptStore.hxx index a4c6e824..23440f3d 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.hxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.hxx @@ -36,7 +36,7 @@ namespace SHADE /// /// /// Type of script to add. - /// This needs to be a default constructable PlushieScript. + /// This needs to be a default constructable Script. /// /// The entity to add a script to. /// Reference to the script added. @@ -234,6 +234,10 @@ namespace SHADE /// static void ExecuteLateUpdate(); /// + /// Executes OnDrawGizmos() for all scripts. + /// + static void ExecuteOnDrawGizmos(); + /// /// Executes OnCollision*() and OnTrigger*() for all scripts. /// static void ExecuteCollisionFunctions(); diff --git a/SHADE_Managed/src/Utility/Convert.cxx b/SHADE_Managed/src/Utility/Convert.cxx index 1d89569f..3b1f0f38 100644 --- a/SHADE_Managed/src/Utility/Convert.cxx +++ b/SHADE_Managed/src/Utility/Convert.cxx @@ -72,6 +72,16 @@ namespace SHADE return Ray(ToCLI(vec.position), ToCLI(vec.direction)); } + SHColour Convert::ToNative(Color col) + { + return SHColour(col.r, col.g, col.b, col.a); + } + + Color Convert::ToCLI(const SHColour& vec) + { + return Color(vec.x, vec.y, vec.z, vec.w); + } + /*---------------------------------------------------------------------------------*/ /* String Conversions */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Utility/Convert.hxx b/SHADE_Managed/src/Utility/Convert.hxx index d3dca740..666b5062 100644 --- a/SHADE_Managed/src/Utility/Convert.hxx +++ b/SHADE_Managed/src/Utility/Convert.hxx @@ -29,6 +29,8 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Quaternion.hxx" #include "Math/Ray.hxx" #include "Engine/GenericHandle.hxx" +#include "Math/SHColour.h" +#include "Graphics/Color.hxx" namespace SHADE { @@ -104,6 +106,17 @@ namespace SHADE /// The native Vector2 to convert from. /// Managed copy of a native Vector2. static Ray ToCLI(const SHRay& vec); + /// Converts from a managed Color to a native Colour. + /// + /// The managed Color to convert from. + /// Native copy of a managed Color. + static SHColour ToNative(Color col); + /// + /// Converts from a native Colour to a managed Color. + /// + /// The native Colour to convert from. + /// Managed copy of a native Colour. + static Color ToCLI(const SHColour& vec); /*-----------------------------------------------------------------------------*/ /* String Conversions */ diff --git a/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.cxx b/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.cxx index ebf2e987..e19c4d06 100644 --- a/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.cxx +++ b/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.cxx @@ -33,4 +33,4 @@ namespace SHADE { return nullptr; } -} // namespace PlushieAPI \ No newline at end of file +} diff --git a/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.hxx b/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.hxx index 433dd85e..14d612b3 100644 --- a/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.hxx +++ b/SHADE_Managed/src/Utility/DisposableAssemblyLoadContext.hxx @@ -36,4 +36,4 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ System::Reflection::Assembly^ Load(System::Reflection::AssemblyName^ assemblyName) override; }; -} // namespace PlushieAPI \ No newline at end of file +} diff --git a/SHADE_Managed/src/Utility/Gizmos.cxx b/SHADE_Managed/src/Utility/Gizmos.cxx new file mode 100644 index 00000000..21636a5d --- /dev/null +++ b/SHADE_Managed/src/Utility/Gizmos.cxx @@ -0,0 +1,69 @@ +/************************************************************************************//*! +\file Gizmos.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 8, 2022 +\brief Contains the definition of the functions for the Convert managed static + class. + + Note: This file is written in C++17/CLI. + +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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Gizmos.hxx" +#include "Convert.hxx" +#include "Tools/SHDebugDraw.h" +// External Dependencies + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Public Properties */ + /*---------------------------------------------------------------------------------*/ + Color Gizmos::Color::get() + { + return defaultColor; + } + void Gizmos::Color::set(SHADE::Color color) + { + defaultColor = color; + } + + /*---------------------------------------------------------------------------------*/ + /* Debug Draw Functions */ + /*---------------------------------------------------------------------------------*/ + void Gizmos::DrawLine(Vector3 from, Vector3 to) + { + DrawLine(from, to, defaultColor); + } + + void Gizmos::DrawLine(Vector3 from, Vector3 to, SHADE::Color color) + { + SHDebugDraw::Line(Convert::ToNative(color), Convert::ToNative(from), Convert::ToNative(to)); + } + + void Gizmos::DrawWireCube(Vector3 center, Vector3 extents) + { + DrawWireCube(center, extents, defaultColor); + } + + void Gizmos::DrawWireCube(Vector3 center, Vector3 extents, SHADE::Color color) + { + SHDebugDraw::Cube(Convert::ToNative(color), Convert::ToNative(center), Convert::ToNative(extents)); + } + + void Gizmos::DrawWireSphere(Vector3 center, float radius) + { + DrawWireSphere(center, radius, defaultColor); + } + + void Gizmos::DrawWireSphere(Vector3 center, float radius, SHADE::Color color) + { + SHDebugDraw::Sphere(Convert::ToNative(color), Convert::ToNative(center), radius); + } +} diff --git a/SHADE_Managed/src/Utility/Gizmos.hxx b/SHADE_Managed/src/Utility/Gizmos.hxx new file mode 100644 index 00000000..1878d867 --- /dev/null +++ b/SHADE_Managed/src/Utility/Gizmos.hxx @@ -0,0 +1,97 @@ +/************************************************************************************//*! +\file Gizmos.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 8, 2022 +\brief Contains the definition of the Gizmos static class and the + declaration of its functions. + + Note: This file is written in C++17/CLI. + +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 + +// Project Includes +#include "Math/Vector3.hxx" +#include "Graphics/Color.hxx" + +namespace SHADE +{ + /// + /// Provides functions for implementing debug drawing. + /// + public value class Gizmos abstract sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Public Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Default colour that will be used for drawing debug primitives if the color + /// parameter is not specified. + /// + static property Color Color + { + SHADE::Color get(); + void set(SHADE::Color color); + } + /*-----------------------------------------------------------------------------*/ + /* Debug Draw Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Renders a line between two points in world space. + /// Uses Color to render. + /// + /// First point of the line. + /// Second point of the line. + static void DrawLine(Vector3 from, Vector3 to); + /// + /// Renders a line between two points in world space. + /// + /// First point of the line. + /// Second point of the line. + /// Colour of the line. + static void DrawLine(Vector3 from, Vector3 to, SHADE::Color color); + /// + /// Renders a wireframe cube centered around the position specified in world + /// space. + /// Uses Color to render. + /// + /// Position where the cube wil be centered at. + /// Size of the rendered cube. + static void DrawWireCube(Vector3 center, Vector3 extents); + /// + /// Renders a wireframe cube centered around the position specified in world + /// space. + /// + /// Position where the cube wil be centered at. + /// Size of the rendered cube. + /// Colour of the cube. + static void DrawWireCube(Vector3 center, Vector3 extents, SHADE::Color color); + /// + /// Renders a wireframe sphere centered around the position specified in world + /// space. + /// Uses Color to render. + /// + /// Position where the sphere wil be centered at. + /// Radius of the rendered sphere. + static void DrawWireSphere(Vector3 center, float radius); + /// + /// Renders a wireframe sphere centered around the position specified in world + /// space. + /// + /// Position where the sphere wil be centered at. + /// Radius of the rendered sphere. + /// Colour of the sphere. + static void DrawWireSphere(Vector3 center, float radius, SHADE::Color color); + + private: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + static SHADE::Color defaultColor = SHADE::Color::White; + }; +}