diff --git a/Assets/Navigation Data/Level2_AITest_NavData.shnav.shmeta b/Assets/Navigation Data/Level2_AITest_NavData.shnav.shmeta index 9a745d73..045dc5de 100644 --- a/Assets/Navigation Data/Level2_AITest_NavData.shnav.shmeta +++ b/Assets/Navigation Data/Level2_AITest_NavData.shnav.shmeta @@ -1,3 +1,3 @@ Name: Level2_AITest_NavData -ID: 255209218 +ID: 258243609 Type: 15 diff --git a/Assets/Scenes/Level2_AITest.shade b/Assets/Scenes/Level2_AITest.shade index d09afa6a..ccbc2737 100644 --- a/Assets/Scenes/Level2_AITest.shade +++ b/Assets/Scenes/Level2_AITest.shade @@ -1,4 +1,4 @@ -- NavData: 255209218 +- NavData: 258243609 - EID: 20 Name: ===== Light ===== IsActive: true @@ -112,6 +112,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -164,6 +165,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -216,6 +218,7 @@ Enabled: true Score: 500 currCategory: 2 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -268,6 +271,7 @@ Enabled: true Score: 500 currCategory: 2 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -320,6 +324,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -372,6 +377,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -424,6 +430,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -482,6 +489,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 2 dontReturn: false soundDistance: 10 @@ -702,6 +710,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -754,6 +763,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -806,6 +816,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -858,6 +869,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -910,6 +922,7 @@ Enabled: true Score: 500 currCategory: 2 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -962,6 +975,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1014,6 +1028,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1066,6 +1081,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1118,6 +1134,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1170,6 +1187,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1222,6 +1240,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1274,6 +1293,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1326,6 +1346,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1378,6 +1399,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1430,6 +1452,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1482,6 +1505,7 @@ Enabled: true Score: 500 currCategory: 2 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1534,6 +1558,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1586,6 +1611,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1638,6 +1664,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1696,6 +1723,7 @@ Enabled: true Score: 500 currCategory: 2 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -1748,6 +1776,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -1800,6 +1829,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -1852,6 +1882,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -1904,6 +1935,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -1956,6 +1988,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -2014,6 +2047,7 @@ Enabled: true Score: 500 currCategory: 2 + currFood: 0 density: 1 dontReturn: false soundDistance: 10 @@ -2066,6 +2100,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -2118,6 +2153,7 @@ Enabled: true Score: 50 currCategory: 1 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -2170,6 +2206,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -2222,6 +2259,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -2274,6 +2312,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 3 dontReturn: false soundDistance: 10 @@ -2332,6 +2371,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 2 dontReturn: false soundDistance: 10 @@ -2558,6 +2598,7 @@ Enabled: true Score: 10 currCategory: 0 + currFood: 0 density: 2 dontReturn: false soundDistance: 10 @@ -2778,6 +2819,7 @@ Scripts: - Type: ScoringZone Enabled: true + startingParticleCount: 10 - EID: 18 Name: CollisionWall IsActive: true @@ -2841,6 +2883,7 @@ Scripts: - Type: ScoringZone Enabled: true + startingParticleCount: 10 - EID: 17 Name: CollisionWall IsActive: true @@ -3041,8 +3084,6 @@ armLength: 2 turnSpeedPitch: 0.200000003 turnSpeedYaw: 0.400000006 - inverseXControls: true - inverseYControls: false pitchUpperClamp: 45 pitchLowerClamp: 5 - EID: 9 diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index e458bbf6..d61161bf 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -442,6 +442,11 @@ namespace SHADE if (ImGui::DragScalar("Col", ImGuiDataType_U16, &navSystem->numCols_editor)) {} if(ImGui::DragScalar("Row", ImGuiDataType_U16, &navSystem->numRows_editor)){} + if (ImGui::Checkbox("Draw Navigation Area", &navSystem->drawNavigationArea)) {} + if (ImGui::Checkbox("Draw Navigation Data", &navSystem->drawNavigationData)) {} + if (ImGui::Checkbox("Draw Path", &navSystem->drawPath)) {} + + if (ImGui::Button("Generate")) { diff --git a/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp b/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp index 8f692d90..1c194fe6 100644 --- a/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp +++ b/SHADE_Engine/src/Navigation/SHNavigationSystem.cpp @@ -26,6 +26,11 @@ namespace SHADE auto id = ComponentFamily::GetID(); SHComponentManager::CreateComponentSparseSet(); SystemID i = SystemFamily::GetID(); + + drawNavigationArea = true; + drawNavigationData = true; + drawPath = true; + } void SHNavigationSystem::Exit() @@ -227,61 +232,57 @@ namespace SHADE if (editor->editorState != SHEditor::State::PLAY) { SHNavigationSystem* system = static_cast(GetSystem()); - if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::H)) - { - system->GenerateNavigationGridData(SHVec3{ 0.0f }, navigationAreaSize, 80, 80); - } auto debugDrawSystem = SHSystemManager::GetSystem(); if (debugDrawSystem) { - SHTransform trans; - trans.position = SHVec3{ 0.0f }; - trans.scale = navigationAreaSize; - trans.ComputeTRS(); - debugDrawSystem->DrawWireCube(trans.trs, SHColour::YELLOW, false); - -#ifdef DRAW_NAVIGATION_DATA - for (uint16_t r = 0; r < system->numRows; ++r) + if (system->drawNavigationArea) { - for (uint16_t c = 0; c < system->numCols; ++c) + SHTransform trans; + trans.position = SHVec3{ 0.0f }; + trans.scale = navigationAreaSize; + trans.ComputeTRS(); + debugDrawSystem->DrawWireCube(trans.trs, SHColour::YELLOW, false); + } + if (system->drawNavigationData) + { + for (uint16_t r = 0; r < system->numRows; ++r) { - if (system->GetNavigationData(r, c) == true) + for (uint16_t c = 0; c < system->numCols; ++c) { - SHVec3 topleft{ system->origin.x - (system->size.x / 2.0f), system->origin.y, system->origin.z - (system->size.z / 2.0f) }; - SHVec2 halfGridSize = system->GetGridSize() * 0.5f; + if (system->GetNavigationData(r, c) == true) + { + SHVec3 topleft{ system->origin.x - (system->size.x / 2.0f), system->origin.y, system->origin.z - (system->size.z / 2.0f) }; + SHVec2 halfGridSize = system->GetGridSize() * 0.5f; + + //offset it by row and column and center it with half grid size. + topleft += SHVec3{ c * system->GetGridSize().x, 0.0f, r * system->GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y }; + SHTransform t; + t.position = system->GetGridWorldPos({ r,c }); + t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f }; + t.ComputeTRS(); + debugDrawSystem->DrawCube(t.trs, SHColour::RED, true); + + } + else + { + SHVec3 topleft{ system->origin.x - (system->size.x / 2.0f), system->origin.y, system->origin.z - (system->size.z / 2.0f) }; + SHVec2 halfGridSize = system->GetGridSize() * 0.5f; + + //offset it by row and column and center it with half grid size. + topleft += SHVec3{ c * system->GetGridSize().x, 0.0f, r * system->GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y }; + SHTransform t; + t.position = system->GetGridWorldPos({ r,c }); + t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f }; + t.ComputeTRS(); + debugDrawSystem->DrawCube(t.trs, SHColour::WHITE, true); + } - //offset it by row and column and center it with half grid size. - topleft += SHVec3{ c * system->GetGridSize().x, 0.0f, r * system->GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y }; - SHTransform t; - t.position = system->GetGridWorldPos({r,c}); - t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f}; - t.ComputeTRS(); - debugDrawSystem->DrawCube(t.trs, SHColour::RED, true); } - else - { - SHVec3 topleft{ system->origin.x - (system->size.x / 2.0f), system->origin.y, system->origin.z - (system->size.z / 2.0f) }; - SHVec2 halfGridSize = system->GetGridSize() * 0.5f; - - //offset it by row and column and center it with half grid size. - topleft += SHVec3{ c * system->GetGridSize().x, 0.0f, r * system->GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y }; - SHTransform t; - t.position = system->GetGridWorldPos({ r,c }); - t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f }; - t.ComputeTRS(); - debugDrawSystem->DrawCube(t.trs, SHColour::WHITE, true); - } - - } } -#endif - - } - } #endif } @@ -334,37 +335,36 @@ namespace SHADE //return so we don't run the parts after this twice. return; } - - comp.forward = SHVec3::Normalise(direction); -#ifdef DRAW_NAVIGATION_PATH - - auto debugDrawSystem = SHSystemManager::GetSystem(); - - auto queue = comp.path; - - while (!queue.empty()) +#ifdef SHEDITOR + if (drawPath) { - uint16_t r = queue.front().row; - uint16_t c = queue.front().column; - + auto debugDrawSystem = SHSystemManager::GetSystem(); + + auto queue = comp.path; + + while (!queue.empty()) { - SHVec3 topleft{ origin.x - (size.x / 2.0f), origin.y, origin.z - (size.z / 2.0f) }; - SHVec2 halfGridSize = GetGridSize() * 0.5f; + uint16_t r = queue.front().row; + uint16_t c = queue.front().column; - //offset it by row and column and center it with half grid size. - topleft += SHVec3{ c * GetGridSize().x, 0.0f, r * GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y }; - SHTransform t; - t.position = GetGridWorldPos({ r,c }); - t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f }; - t.ComputeTRS(); - debugDrawSystem->DrawCube(t.trs, SHColour::YELLOW, true); + { + SHVec3 topleft{ origin.x - (size.x / 2.0f), origin.y, origin.z - (size.z / 2.0f) }; + SHVec2 halfGridSize = GetGridSize() * 0.5f; + //offset it by row and column and center it with half grid size. + topleft += SHVec3{ c * GetGridSize().x, 0.0f, r * GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y }; + SHTransform t; + t.position = GetGridWorldPos({ r,c }); + t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f }; + t.ComputeTRS(); + debugDrawSystem->DrawCube(t.trs, SHColour::YELLOW, true); + + } + queue.pop(); } - queue.pop(); } - #endif } @@ -404,13 +404,92 @@ namespace SHADE NavigationNode startingNode; startingNode.index = GetNavigationGridIndex(transform->GetWorldPosition()); - startingNode.parent.row = NullGridIndex; - startingNode.parent.column = NullGridIndex; - startingNode.h = std::numeric_limits::max(); - startingNode.g = 0; - startingNode.f = 0; + if (GetNavigationData(startingNode.index) == true) + { + uint16_t i = comp.tolerance; + while (openList.empty()) + { + + NavigationGridIndex tolCheckIndex = startingNode.index; + tolCheckIndex.row += i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + + tolCheckIndex = startingNode.index; + tolCheckIndex.row -= i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + + tolCheckIndex = startingNode.index; + tolCheckIndex.column += i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + + tolCheckIndex = startingNode.index; + tolCheckIndex.column -= i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + + tolCheckIndex = startingNode.index; + tolCheckIndex.row += i; + tolCheckIndex.column += i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + + tolCheckIndex = startingNode.index; + tolCheckIndex.row -= i; + tolCheckIndex.column -= i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + + tolCheckIndex = startingNode.index; + tolCheckIndex.row -= i; + tolCheckIndex.column += i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + + tolCheckIndex = startingNode.index; + tolCheckIndex.row += i; + tolCheckIndex.column -= i; + if (GetNavigationData(tolCheckIndex) == false) + { + startingNode.index = tolCheckIndex; + break; + } + ++i; + } + } + + startingNode.parent.row = NullGridIndex; + startingNode.parent.column = NullGridIndex; + startingNode.h = std::numeric_limits::max(); + startingNode.g = 0; + startingNode.f = 0; + + openList.push_back(startingNode); + - openList.push_back(startingNode); NavigationNode endNode; diff --git a/SHADE_Engine/src/Navigation/SHNavigationSystem.h b/SHADE_Engine/src/Navigation/SHNavigationSystem.h index 5b3fa0ca..ab388979 100644 --- a/SHADE_Engine/src/Navigation/SHNavigationSystem.h +++ b/SHADE_Engine/src/Navigation/SHNavigationSystem.h @@ -75,6 +75,9 @@ namespace SHADE AssetID navDataAsset{}; + bool drawNavigationArea; + bool drawNavigationData; + bool drawPath; void GenerateNavigationGridData(SHVec3 origin, SHVec3 size, uint16_t numRow, uint16_t numCol) noexcept;