Explorar o código

Apple Kraken fake state transitions working

Signed-off-by: Adam Dabrowski <[email protected]>
Adam Dabrowski %!s(int64=2) %!d(string=hai) anos
pai
achega
f3b17bf8bb

+ 14 - 0
Project/Assets/Importer/apple_kraken.prefab

@@ -2153,6 +2153,13 @@
                         "Frame Name": "base_link"
                     }
                 },
+                "Component_[10827857459669795993]": {
+                    "$type": "GenericComponentWrapper",
+                    "Id": 10827857459669795993,
+                    "m_template": {
+                        "$type": "ApplePickerComponent"
+                    }
+                },
                 "Component_[11557544210003172907]": {
                     "$type": "EditorEntitySortComponent",
                     "Id": 11557544210003172907,
@@ -2246,6 +2253,13 @@
                     "$type": "EditorVisibilityComponent",
                     "Id": 15761721196763571641
                 },
+                "Component_[15817514089712196717]": {
+                    "$type": "GenericComponentWrapper",
+                    "Id": 15817514089712196717,
+                    "m_template": {
+                        "$type": "KrakenEffectorComponent"
+                    }
+                },
                 "Component_[17458592949589370902]": {
                     "$type": "EditorEntityIconComponent",
                     "Id": 17458592949589370902

+ 2 - 2
Project/Gem/Source/ApplePicker/ApplePickerComponent.cpp

@@ -48,8 +48,7 @@ namespace AppleKraken
 
         // Get effector reach
         AZ::Obb effectorRangeGlobalBox;
-        ApplePickingRequestBus::EventResult(
-            effectorRangeGlobalBox, m_effectorEntityId, &ApplePickingRequests::GetEffectorReachArea);
+        ApplePickingRequestBus::EventResult(effectorRangeGlobalBox, m_effectorEntityId, &ApplePickingRequests::GetEffectorReachArea);
 
         // Find out apples within the reach
         QueryEnvironmentForAllApplesInBox(effectorRangeGlobalBox);
@@ -152,6 +151,7 @@ namespace AppleKraken
 
     void ApplePickerComponent::PickNextApple()
     {
+        AZ_TracePrintf("ApplePicker", "Pick next apple");
         if (!m_currentAppleTasks.empty())
         { // Get another apple!
             ApplePickingRequestBus::Event(m_effectorEntityId, &ApplePickingRequests::PickApple, m_currentAppleTasks.front());

+ 36 - 9
Project/Gem/Source/ApplePicker/KrakenEffectorComponent.cpp

@@ -170,6 +170,25 @@ namespace AppleKraken
         return reachArea;
     }
 
+    void KrakenEffectorComponent::OnEffectorReadyForPicking()
+    {
+        ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::EffectorReadyForPicking);
+    }
+
+    void KrakenEffectorComponent::OnApplePicked()
+    {
+        // TODO - also handle picking failed
+        ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::ApplePicked);
+
+        // Just entered retrieving state, transition to Prepared
+        BeginTransitionIfAcceptable(EffectorState::PREPARED);
+    }
+
+    void KrakenEffectorComponent::OnAppleRetrieved()
+    {
+        ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::AppleRetrieved);
+    }
+
     void KrakenEffectorComponent::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     {
         if (m_effectorState == m_effectorTargetState)
@@ -187,22 +206,30 @@ namespace AppleKraken
         AZ_TracePrintf(
             "KrakenEffectorComponent", "%s", DebugStateTransit::StateTransitionString(m_effectorState, m_effectorTargetState).c_str());
         m_currentStateTransitionTime = 0.0f;
+
+        // Update state
+        auto previousState = m_effectorState;
         m_effectorState = m_effectorTargetState;
 
-        if (m_effectorState == EffectorState::PICKING && m_effectorTargetState == EffectorState::RETRIEVING)
+        if (previousState == EffectorState::IDLE && m_effectorState == EffectorState::PREPARED)
         {
-            // TODO - also handle picking failed
-            ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::ApplePicked);
+            OnEffectorReadyForPicking();
+        }
 
-            // Start retrieving right away
-            m_effectorTargetState = EffectorState::RETRIEVING;
-            return;
+        if (previousState == EffectorState::PREPARED && m_effectorState == EffectorState::PICKING)
+        {
+            // start picking the apple
+            BeginTransitionIfAcceptable(EffectorState::RETRIEVING);
         }
 
-        if (m_effectorState == EffectorState::RETRIEVING && m_effectorTargetState == EffectorState::PREPARED)
+        if (previousState == EffectorState::PICKING && m_effectorState == EffectorState::RETRIEVING)
         {
-            ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::AppleRetrieved);
-            return;
+            OnApplePicked();
+        }
+
+        if (previousState == EffectorState::RETRIEVING && m_effectorState == EffectorState::PREPARED)
+        {
+            OnAppleRetrieved();
         }
     }
 } // namespace AppleKraken

+ 4 - 0
Project/Gem/Source/ApplePicker/KrakenEffectorComponent.h

@@ -41,6 +41,10 @@ namespace AppleKraken
         bool IsTransitionAcceptable(EffectorState targetState) const;
         bool IsTransitionValid(EffectorState targetState) const;
 
+        void OnEffectorReadyForPicking();
+        void OnApplePicked();
+        void OnAppleRetrieved();
+
         EffectorState m_effectorState = EffectorState::IDLE;
         EffectorState m_effectorTargetState = EffectorState::IDLE;
         float m_currentStateTransitionTime = 0.0f;