From 8c5bf82aa5cbf4d7ed7f380ea80b0bd51e9bcd0a Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Thu, 30 Mar 2023 15:16:18 +0800 Subject: [PATCH 1/3] Added CaughtRaccoon State. --- Assets/Scenes/Level2.shade | 4 +- .../AIBehaviour/AIRework/HomeOwnerAI.cs | 10 +++ .../AIRework/HomeOwnerAttackHitbox.cs | 17 +++-- .../AIBehaviour/AIRework/RotateToVelocity.cs | 36 +++++----- .../AIRework/States/AttackState.cs | 14 +++- .../AIRework/States/CaughtRaccoonState.cs | 62 ++++++++++++++++++ .../States/CaughtRaccoonState.cs.shmeta | 3 + .../AIBehaviour/AIRework/States/ChaseState.cs | 2 +- Assets/Shaders/UI_Slider_FS.glsl | 3 + Assets/Shaders/UI_Slider_FS.shshaderb | Bin 2777 -> 2829 bytes 10 files changed, 120 insertions(+), 31 deletions(-) create mode 100644 Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs create mode 100644 Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta diff --git a/Assets/Scenes/Level2.shade b/Assets/Scenes/Level2.shade index 4355b33e..f5bd5b4f 100644 --- a/Assets/Scenes/Level2.shade +++ b/Assets/Scenes/Level2.shade @@ -5911,6 +5911,7 @@ - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAI Enabled: true idleDuration: 1 + caughtDuration: 2 timeoutDuration: 2 patrolPointParent: 166 patrolSpeed: 1 @@ -17270,4 +17271,5 @@ Scripts: - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAttackHitbox Enabled: true - aiGO: 158 \ No newline at end of file + aiGO: 158 + raccoonFound: false \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs index c86342a0..095ef1a3 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs @@ -10,6 +10,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework public class HomeOwnerAI : Script { public float idleDuration = 1.0f; + public float caughtDuration = 2.0f; public float timeoutDuration = 2.0f; public GameObject patrolPointParent; @@ -41,6 +42,9 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework private Transform transform; + [NonSerialized] + public HomeOwnerAttackHitbox hitboxScript; + public void Reset() { StateMachine machine = GetScript(); @@ -65,6 +69,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework dictionary.Add(typeof(ChaseState), new ChaseState(machine)); dictionary.Add(typeof(AlertState), new AlertState(machine)); dictionary.Add(typeof(AttackState), new AttackState(machine)); + dictionary.Add(typeof(CaughtRaccoonState), new CaughtRaccoonState(machine)); machine.InitStateMachine(dictionary); } @@ -84,6 +89,11 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework //attackHitbox.SetActive(false); if (pppList != null) startPos = pppList[0].LocalPosition; + + if (attackHitbox) + hitboxScript = attackHitbox.GetScript(); + + } diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs index 30d99e57..6f392962 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs @@ -13,11 +13,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework { public GameObject aiGO; - private bool raccoonFound = false; + public bool raccoonFound = false; Transform transform; Transform aiTransform; - private PlayerController pc; + [NonSerialized] + public PlayerController pc; private HomeOwnerAI ai; protected override void start() @@ -39,20 +40,18 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework if (raccoonFound && pc && ai) { - pc.currentState = RaccoonStates.CAUGHT; - if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState))) - pc.stateMachine.SetState(typeof(PlayerCaughtState)); + if (!ai.atk) + raccoonFound = false; - pc.GotCaught(); - ai.Reset(); - raccoonFound = false; } + } protected override void onTriggerStay(CollisionInfo info) { - pc = info.GameObject.GetScript(); + if(info.GameObject.GetScript()) + pc = info.GameObject.GetScript(); if (ai && ai.atk && pc) { raccoonFound = true; diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs index 7791aa77..03ee9ba2 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs @@ -37,23 +37,23 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework { lookOffset = 0.0f; } - else - { - if(left ) - { - if (lookOffset > -lookAroundAngle) - lookOffset -= rotationPerSecond * Time.DeltaTimeF; - else - left = false; - } - if (!left) - { - if (lookOffset < lookAroundAngle) - lookOffset += rotationPerSecond * Time.DeltaTimeF; - else - left = false; - } - } + //else + //{ + // if(left ) + // { + // if (lookOffset > -lookAroundAngle) + // lookOffset -= rotationPerSecond * Time.DeltaTimeF; + // else + // left = false; + // } + // if (!left) + // { + // if (lookOffset < lookAroundAngle) + // lookOffset += rotationPerSecond * Time.DeltaTimeF; + // else + // left = false; + // } + //} @@ -75,7 +75,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework if(vel.GetMagnitude() > 0.01f) { Quaternion currentRotation = transform.LocalRotation; - Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f); + Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f); transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.DeltaTimeF); } } diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs index b444c2fb..b57ad2a6 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs @@ -26,7 +26,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States public AttackState(StateMachine machine) : base(machine) { - + stateName = "Attack"; } @@ -68,7 +68,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States public override void OnExit() { - animator.Stop(); + RotateToVelocity rotate = ai.GetScript(); if (rotate) { @@ -84,6 +84,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States public override void update() { + if (ai.hitboxScript.raccoonFound) + { + machine.SetState(typeof(CaughtRaccoonState)); + } + + timer -= Time.DeltaTimeF; if (windUp) { @@ -141,9 +147,13 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States machine.SetState(typeof(TimeoutState)); } } + + } + + } public override void fixedUpdate() diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs new file mode 100644 index 00000000..0381b0bd --- /dev/null +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SHADE; +using static PlayerController; + +namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States +{ + public class CaughtRaccoonState: AIBaseState + { + + private float timer = 0.0f; + private PlayerController pc; + + public CaughtRaccoonState(StateMachine machine):base(machine) + { + stateName = "Caught Raccoon"; + } + + public override void OnEnter() + { + if(ai.hitboxScript) + pc = ai.hitboxScript.pc; + + timer = ai.caughtDuration; + } + + + public override void OnExit() + { + animator.Stop(); + } + + public override void update() + { + timer -= Time.DeltaTimeF; + if(timer <= 0.0f) + { + if (pc) + { + pc.currentState = RaccoonStates.CAUGHT; + if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState))) + pc.stateMachine.SetState(typeof(PlayerCaughtState)); + + pc.GotCaught(); + } + ai.Reset(); + } + + + } + + public override void fixedUpdate() + { + + } + + + } +} diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta new file mode 100644 index 00000000..619e1c4b --- /dev/null +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta @@ -0,0 +1,3 @@ +Name: CaughtRaccoonState +ID: 153010954 +Type: 9 diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs index fdd3fdc1..c2a32c81 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs @@ -14,7 +14,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States float giveUpDuration = 10.0f; float giveUpTimer = 0.0f; - float atkDistance = 2.0f; + float atkDistance = 1.0f; bool run = true; diff --git a/Assets/Shaders/UI_Slider_FS.glsl b/Assets/Shaders/UI_Slider_FS.glsl index b39f18dd..f08f974f 100644 --- a/Assets/Shaders/UI_Slider_FS.glsl +++ b/Assets/Shaders/UI_Slider_FS.glsl @@ -8,6 +8,7 @@ struct MatPropData int textureIndex; float alpha; float sliderThreshold; + float borderThickness; vec4 sliderStartColor; vec4 sliderEndColor; vec4 sliderBarColor; @@ -43,6 +44,8 @@ void main() { //fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); + + if (In.uv.x > MatProp.data[In2.materialIndex].sliderThreshold) fragColor = MatProp.data[In2.materialIndex].sliderBarColor; else diff --git a/Assets/Shaders/UI_Slider_FS.shshaderb b/Assets/Shaders/UI_Slider_FS.shshaderb index 0dcfb62dfc82208709fa737c851fc7f22b01a68a..09feea58b719ac854357e90e66d8130bbfba2718 100644 GIT binary patch delta 169 zcmca9+AGE^z{0(e`3s{mJA*I-0|PSEVq!xu_WF}|lr4|=6urY9eFW0YrP zoh-*B&B(UdipiVNln1EXgMk$y4P+|=u>g`7D^yGYNsMjtGUi%FZceZ!kO6FywOGG1 cvQ1WE(-&j`^0gUQ7(n87K+L*1iLIOk0K?@Le*gdg delta 117 zcmeAbyD7>naDi(h^A|>T4hCTc1_tKIQcUuUER(I6q#0Q^hcS6GDhdFFJs4QQ(kwu> wG7u{uiLq|J##{^2&oeoW^*bZ$ Date: Thu, 30 Mar 2023 15:26:15 +0800 Subject: [PATCH 2/3] Added CaughtRaccoon State. --- Assets/Scenes/Level2.shade | 4 +- .../AIBehaviour/AIRework/HomeOwnerAI.cs | 10 +++ .../AIRework/HomeOwnerAttackHitbox.cs | 17 +++-- .../AIBehaviour/AIRework/RotateToVelocity.cs | 36 +++++------ .../AIRework/States/AttackState.cs | 14 ++++- .../AIRework/States/CaughtRaccoonState.cs | 62 +++++++++++++++++++ .../States/CaughtRaccoonState.cs.shmeta | 3 + .../AIBehaviour/AIRework/States/ChaseState.cs | 2 +- 8 files changed, 117 insertions(+), 31 deletions(-) create mode 100644 Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs create mode 100644 Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta diff --git a/Assets/Scenes/Level2.shade b/Assets/Scenes/Level2.shade index 4355b33e..f5bd5b4f 100644 --- a/Assets/Scenes/Level2.shade +++ b/Assets/Scenes/Level2.shade @@ -5911,6 +5911,7 @@ - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAI Enabled: true idleDuration: 1 + caughtDuration: 2 timeoutDuration: 2 patrolPointParent: 166 patrolSpeed: 1 @@ -17270,4 +17271,5 @@ Scripts: - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAttackHitbox Enabled: true - aiGO: 158 \ No newline at end of file + aiGO: 158 + raccoonFound: false \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs index c86342a0..095ef1a3 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs @@ -10,6 +10,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework public class HomeOwnerAI : Script { public float idleDuration = 1.0f; + public float caughtDuration = 2.0f; public float timeoutDuration = 2.0f; public GameObject patrolPointParent; @@ -41,6 +42,9 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework private Transform transform; + [NonSerialized] + public HomeOwnerAttackHitbox hitboxScript; + public void Reset() { StateMachine machine = GetScript(); @@ -65,6 +69,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework dictionary.Add(typeof(ChaseState), new ChaseState(machine)); dictionary.Add(typeof(AlertState), new AlertState(machine)); dictionary.Add(typeof(AttackState), new AttackState(machine)); + dictionary.Add(typeof(CaughtRaccoonState), new CaughtRaccoonState(machine)); machine.InitStateMachine(dictionary); } @@ -84,6 +89,11 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework //attackHitbox.SetActive(false); if (pppList != null) startPos = pppList[0].LocalPosition; + + if (attackHitbox) + hitboxScript = attackHitbox.GetScript(); + + } diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs index 30d99e57..6f392962 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAttackHitbox.cs @@ -13,11 +13,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework { public GameObject aiGO; - private bool raccoonFound = false; + public bool raccoonFound = false; Transform transform; Transform aiTransform; - private PlayerController pc; + [NonSerialized] + public PlayerController pc; private HomeOwnerAI ai; protected override void start() @@ -39,20 +40,18 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework if (raccoonFound && pc && ai) { - pc.currentState = RaccoonStates.CAUGHT; - if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState))) - pc.stateMachine.SetState(typeof(PlayerCaughtState)); + if (!ai.atk) + raccoonFound = false; - pc.GotCaught(); - ai.Reset(); - raccoonFound = false; } + } protected override void onTriggerStay(CollisionInfo info) { - pc = info.GameObject.GetScript(); + if(info.GameObject.GetScript()) + pc = info.GameObject.GetScript(); if (ai && ai.atk && pc) { raccoonFound = true; diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs index 7791aa77..03ee9ba2 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/RotateToVelocity.cs @@ -37,23 +37,23 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework { lookOffset = 0.0f; } - else - { - if(left ) - { - if (lookOffset > -lookAroundAngle) - lookOffset -= rotationPerSecond * Time.DeltaTimeF; - else - left = false; - } - if (!left) - { - if (lookOffset < lookAroundAngle) - lookOffset += rotationPerSecond * Time.DeltaTimeF; - else - left = false; - } - } + //else + //{ + // if(left ) + // { + // if (lookOffset > -lookAroundAngle) + // lookOffset -= rotationPerSecond * Time.DeltaTimeF; + // else + // left = false; + // } + // if (!left) + // { + // if (lookOffset < lookAroundAngle) + // lookOffset += rotationPerSecond * Time.DeltaTimeF; + // else + // left = false; + // } + //} @@ -75,7 +75,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework if(vel.GetMagnitude() > 0.01f) { Quaternion currentRotation = transform.LocalRotation; - Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f); + Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f); transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.DeltaTimeF); } } diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs index b444c2fb..b57ad2a6 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/AttackState.cs @@ -26,7 +26,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States public AttackState(StateMachine machine) : base(machine) { - + stateName = "Attack"; } @@ -68,7 +68,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States public override void OnExit() { - animator.Stop(); + RotateToVelocity rotate = ai.GetScript(); if (rotate) { @@ -84,6 +84,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States public override void update() { + if (ai.hitboxScript.raccoonFound) + { + machine.SetState(typeof(CaughtRaccoonState)); + } + + timer -= Time.DeltaTimeF; if (windUp) { @@ -141,9 +147,13 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States machine.SetState(typeof(TimeoutState)); } } + + } + + } public override void fixedUpdate() diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs new file mode 100644 index 00000000..0381b0bd --- /dev/null +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SHADE; +using static PlayerController; + +namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States +{ + public class CaughtRaccoonState: AIBaseState + { + + private float timer = 0.0f; + private PlayerController pc; + + public CaughtRaccoonState(StateMachine machine):base(machine) + { + stateName = "Caught Raccoon"; + } + + public override void OnEnter() + { + if(ai.hitboxScript) + pc = ai.hitboxScript.pc; + + timer = ai.caughtDuration; + } + + + public override void OnExit() + { + animator.Stop(); + } + + public override void update() + { + timer -= Time.DeltaTimeF; + if(timer <= 0.0f) + { + if (pc) + { + pc.currentState = RaccoonStates.CAUGHT; + if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState))) + pc.stateMachine.SetState(typeof(PlayerCaughtState)); + + pc.GotCaught(); + } + ai.Reset(); + } + + + } + + public override void fixedUpdate() + { + + } + + + } +} diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta new file mode 100644 index 00000000..619e1c4b --- /dev/null +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/CaughtRaccoonState.cs.shmeta @@ -0,0 +1,3 @@ +Name: CaughtRaccoonState +ID: 153010954 +Type: 9 diff --git a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs index fdd3fdc1..c2a32c81 100644 --- a/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs +++ b/Assets/Scripts/Gameplay/AIBehaviour/AIRework/States/ChaseState.cs @@ -14,7 +14,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States float giveUpDuration = 10.0f; float giveUpTimer = 0.0f; - float atkDistance = 2.0f; + float atkDistance = 1.0f; bool run = true; From 3f7522d76ff9350f38997a73491dd41981fb0dbd Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Thu, 30 Mar 2023 15:37:42 +0800 Subject: [PATCH 3/3] Revert "Merge pull request #446 from SHADE-DP/Fix-ResourceHubCrashOnExit" This reverts commit 5ab7cbe5f36379d26db817666a796f257035afa0, reversing changes made to ffc638e14b8fe9d6959b1d9e6a57d733cc879ed5. --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 53 +++++++++---------- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 +- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 4738b70c..21b08829 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -216,13 +216,13 @@ namespace SHADE } // Get render graph from default viewport world renderer - renderGraph = resourceManager->Create(); + renderGraph = resourceManager.Create(); /*-----------------------------------------------------------------------*/ /* WORLD RENDER GRAPH RESOURCES */ /*-----------------------------------------------------------------------*/ // Initialize world render graph - renderGraph->Init("World Render Graph", device, swapchain, resourceManager, renderContextCmdPools); + renderGraph->Init("World Render Graph", device, swapchain, &resourceManager, renderContextCmdPools); renderGraph->AddResource("Position", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); renderGraph->AddResource("Position World Space", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); renderGraph->AddResource("Object VFX", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); @@ -292,7 +292,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SSAO PASS AND DATA INIT */ /*-----------------------------------------------------------------------*/ - ssaoStorage = resourceManager->Create(); + ssaoStorage = resourceManager.Create(); // command buffer operation to transfer data for ssao ssaoTransferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); @@ -475,7 +475,7 @@ namespace SHADE void SHGraphicsSystem::InitSubsystems(void) noexcept { - mousePickSubSystem = resourceManager->Create(); + mousePickSubSystem = resourceManager.Create(); std::vector> cmdPools; cmdPools.reserve(swapchain->GetNumImages()); @@ -486,28 +486,28 @@ namespace SHADE mousePickSubSystem->Init(device, cmdPools, renderGraph->GetRenderGraphResource("Entity ID")); // Register the post offscreen render to the system - postOffscreenRenderSubSystem = resourceManager->Create(); + postOffscreenRenderSubSystem = resourceManager.Create(); postOffscreenRenderSubSystem->Init(device, renderGraph->GetRenderGraphResource("Scene"), descPool); - lightingSubSystem = resourceManager->Create(); - lightingSubSystem->Init(device, descPool, resourceManager, samplerCache.GetSampler (device, SHVkSamplerParams + lightingSubSystem = resourceManager.Create(); + lightingSubSystem->Init(device, descPool, &resourceManager, samplerCache.GetSampler (device, SHVkSamplerParams { .addressMode = vk::SamplerAddressMode::eClampToBorder, }) ); - textRenderingSubSystem = resourceManager->Create(); + textRenderingSubSystem = resourceManager.Create(); // initialize the text renderer auto uiNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data()); textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_TRANSLUCENT_SUBPASS), descPool, textVS, textFS); - trajectoryRenderingSubSystem = resourceManager->Create(); + trajectoryRenderingSubSystem = resourceManager.Create(); auto vfxPass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data()); // particle sub system initialization - particleSubSystem = resourceManager->Create(); + particleSubSystem = resourceManager.Create(); particleSubSystem->Init(device, descPool, vfxPass->GetRenderpass(), vfxPass->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::VFX_SUBPASS), particleVS, particleFS, particleEmitCS, particleUpdateCS); auto vfxNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data()); @@ -608,9 +608,6 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ void SHGraphicsSystem::Init(void) { - // Create resource manager - resourceManager = new SHResourceHub(); - InitBoilerplate(); InitMiddleEnd(); InitSubsystems(); @@ -870,7 +867,7 @@ namespace SHADE } // Create the renderer - auto renderer = resourceManager->Create(device, swapchain->GetNumImages(), descPool, projectionType); + auto renderer = resourceManager.Create(device, swapchain->GetNumImages(), descPool, projectionType); // Store renderers.emplace_back(renderer); @@ -914,7 +911,7 @@ namespace SHADE // Create new renderer for the light component and give it to the light component - Handle newRenderer = resourceManager->Create(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); + Handle newRenderer = resourceManager.Create(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); lightComp->SetRenderer(newRenderer); // Add the shadow map resource to the graph @@ -1061,7 +1058,7 @@ namespace SHADE auto shaderPair = std::make_pair(vertShader, fragShader); // Create material - auto mat = resourceManager->Create(); + auto mat = resourceManager.Create(); auto renderGraphNode = subpass->GetParentNode(); auto pipeline = renderGraphNode->GetOrCreatePipeline(std::make_pair(vertShader, fragShader), subpass); @@ -1075,12 +1072,12 @@ namespace SHADE void SHGraphicsSystem::RemoveMaterial(Handle material) { - resourceManager->Free(material); + resourceManager.Free(material); } Handle SHGraphicsSystem::AddOrGetBaseMaterialInstance(Handle material) { - return materialInstanceCache.CreateOrGet(*resourceManager, material); + return materialInstanceCache.CreateOrGet(resourceManager, material); } SHADE::Handle SHGraphicsSystem::AddOrGetBaseMaterialInstance() @@ -1090,17 +1087,17 @@ namespace SHADE SHADE::Handle SHGraphicsSystem::AddMaterialInstanceCopy(Handle materialInst) { - return resourceManager->Create(materialInst->GetBaseMaterial()); + return resourceManager.Create(materialInst->GetBaseMaterial()); } std::pair, typename SHResourceHub::dense_iterator> SHGraphicsSystem::GetAllMaterialInstances() { - return resourceManager->GetDenseAccess(); + return resourceManager.GetDenseAccess(); } void SHGraphicsSystem::RemoveMaterialInstance(Handle materialInstance) { - resourceManager->Free(materialInstance); + resourceManager.Free(materialInstance); } /*---------------------------------------------------------------------------------*/ @@ -1192,12 +1189,12 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ Handle SHGraphicsSystem::AddFont(SHFontAsset const& fontAsset) noexcept { - return fontLibrary.AddFont(device, *resourceManager, fontAsset); + return fontLibrary.AddFont(device, resourceManager, fontAsset); } void SHGraphicsSystem::BuildFonts(void) noexcept { - fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::FONT)[0], *resourceManager); + fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager); } #pragma endregion ADD_REMOVE @@ -1241,7 +1238,7 @@ namespace SHADE // Reset all material isDirty auto gfxSystem = reinterpret_cast(system); - auto [matBegin, matEnd] = gfxSystem->resourceManager->GetDenseAccess(); + auto [matBegin, matEnd] = gfxSystem->resourceManager.GetDenseAccess(); for (auto iter = matBegin; iter != matEnd; ++iter) { iter->ClearChangeFlag(); @@ -1259,7 +1256,7 @@ namespace SHADE // Clean up and update all materials auto gfxSystem = reinterpret_cast(system); - auto [matInstBegin, matInstEnd] = gfxSystem->resourceManager->GetDenseAccess(); + auto [matInstBegin, matInstEnd] = gfxSystem->resourceManager.GetDenseAccess(); for (auto iter = matInstBegin; iter != matInstEnd; ++iter) { auto baseMat = iter->GetBaseMaterial(); @@ -1312,7 +1309,7 @@ namespace SHADE // Unset all material old pipeline since we would have finished processing auto gfxSystem = reinterpret_cast(system); - auto [matBegin, matEnd] = gfxSystem->resourceManager->GetDenseAccess(); + auto [matBegin, matEnd] = gfxSystem->resourceManager.GetDenseAccess(); for (auto iter = matBegin; iter != matEnd; ++iter) { iter->ForgetOldPipeline(); @@ -1452,7 +1449,7 @@ namespace SHADE Handle SHGraphicsSystem::createDebugDrawPipeline(Handle renderPass, Handle subpass, bool filled, bool triMesh, bool instanced) { - auto pipelineLayout = resourceManager->Create + auto pipelineLayout = resourceManager.Create ( device, SHPipelineLayoutParams { @@ -1460,7 +1457,7 @@ namespace SHADE .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts } ); - auto pipeline = resourceManager->Create(device, pipelineLayout, nullptr, renderPass, subpass); + auto pipeline = resourceManager.Create(device, pipelineLayout, nullptr, renderPass, subpass); pipeline->GetPipelineState().SetRasterizationState(SHRasterizationState { .polygonMode = filled ? vk::PolygonMode::eFill : vk::PolygonMode::eLine, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index aff756cd..3d0b3cc6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -440,7 +440,7 @@ namespace SHADE SHWindow* window = nullptr; // Middle End Resources - SHResourceHub* resourceManager; + SHResourceHub resourceManager; SHMeshLibrary meshLibrary; SHTextureLibrary texLibrary; SHGraphicsGenericData graphicsGenericData;