Explorar o código

disappearing of the apples

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

+ 8 - 3
Project/Gem/Source/ApplePicker/ApplePickerComponent.cpp

@@ -11,9 +11,9 @@
 #include <AzCore/EBus/Event.h>
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/EditContextConstants.inl>
+#include <ROS2/Frame/ROS2FrameComponent.h>
 #include <ROS2/ROS2Bus.h>
 #include <ROS2/Utilities/ROS2Names.h>
-#include <ROS2/Frame/ROS2FrameComponent.h>
 
 using namespace ROS2;
 
@@ -53,7 +53,7 @@ namespace AppleKraken
     bool ApplePickerComponent::IsBusy() const
     {
         if (!m_currentAppleTasks.empty())
-        {   // busy - still has tasks in queue
+        { // busy - still has tasks in queue
             return true;
         }
 
@@ -61,7 +61,7 @@ namespace AppleKraken
         PickingState pickingState;
         ApplePickingRequestBus::EventResult(pickingState, m_effectorEntityId, &ApplePickingRequests::GetEffectorState);
         if (pickingState.m_effectorState != EffectorState::IDLE && pickingState.m_effectorState != EffectorState::PREPARED)
-        {   // Effector is not ready - still transitioning to a state. This should be a rare occurrence.
+        { // Effector is not ready - still transitioning to a state. This should be a rare occurrence.
             AZ_Warning("ApplePicker", false, "Task queue empty but apple picker is busy since the effector is working");
             return true;
         }
@@ -176,7 +176,12 @@ namespace AppleKraken
             AZ_Error("ApplePicker", false, "ApplePicked called but no current task");
             return;
         }
+
         AZ_TracePrintf("ApplePicker", "%s. Picked apple\n", Internal::CurrentTaskString(m_currentAppleTasks).c_str());
+
+        // Disappear the apple
+        AZ::Render::MeshComponentRequestBus::Event(
+            m_currentAppleTasks.front().m_appleEntityId, &AZ::Render::MeshComponentRequestBus::Events::SetVisibility, false);
     }
 
     void ApplePickerComponent::AppleRetrieved()

+ 15 - 4
Project/Gem/Source/ApplePicker/KrakenEffectorComponent.cpp

@@ -38,10 +38,10 @@ namespace AppleKraken
         {
             static const TransitionMap tm = {
                 { std::make_pair(EffectorState::IDLE, EffectorState::PREPARED), 0.1f },
-                { std::make_pair(EffectorState::PREPARED, EffectorState::PICKING), 0.5f },
-                { std::make_pair(EffectorState::PICKING, EffectorState::RETRIEVING), 2.0f },
-                { std::make_pair(EffectorState::RETRIEVING, EffectorState::PREPARED), 2.0f },
-                { std::make_pair(EffectorState::PREPARED, EffectorState::IDLE), 0.1f },
+                { std::make_pair(EffectorState::PREPARED, EffectorState::PICKING), 0.05f },
+                { std::make_pair(EffectorState::PICKING, EffectorState::RETRIEVING), 0.1f },
+                { std::make_pair(EffectorState::RETRIEVING, EffectorState::PREPARED), 0.1f },
+                { std::make_pair(EffectorState::PREPARED, EffectorState::IDLE), 0.05f },
             };
             return tm;
         }
@@ -154,6 +154,7 @@ namespace AppleKraken
     {
         AZ_TracePrintf("KrakenEffectorComponent", "PickApple\n");
         // TODO - handle appleTask
+        m_currentTask = appleTask;
         BeginTransitionIfAcceptable(EffectorState::PICKING);
     }
 
@@ -168,6 +169,10 @@ namespace AppleKraken
         PickingState state;
         state.m_effectorState = m_effectorState;
         state.m_taskProgress = 0.0f; // TODO
+        if (m_currentTask.IsValid())
+        {
+            state.m_currentTask = m_currentTask;
+        }
         return state;
     }
 
@@ -225,6 +230,12 @@ namespace AppleKraken
 
     void KrakenEffectorComponent::OnApplePicked()
     {
+        if (!m_currentTask.IsValid())
+        {
+            AZ_Error("KrakenEffectorComponent", true, "No valid task for current picking!");
+            return;
+        }
+
         // TODO - also handle picking failed
         ApplePickingNotificationBus::Broadcast(&ApplePickingNotifications::ApplePicked);
 

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

@@ -45,6 +45,7 @@ namespace AppleKraken
         void OnApplePicked();
         void OnAppleRetrieved();
 
+        PickAppleTask m_currentTask; //!> valid if RETRIEVING or PICKING
         EffectorState m_effectorState = EffectorState::IDLE;
         EffectorState m_effectorTargetState = EffectorState::IDLE;
         float m_currentStateTransitionTime = 0.0f;

+ 19 - 8
Project/Gem/Source/ApplePicker/PickingStructs.h

@@ -22,21 +22,32 @@ namespace AppleKraken
         RETRIEVING = 30 //!< The effector is retrieving a fruit to storage position.
     };
 
-    //! A structure holding a state of effector, including optional progress and descriptive information.
-    struct PickingState
-    {
-        EffectorState m_effectorState = EffectorState::IDLE; //!< Current state of effector.
-        float m_taskProgress = 0.0f; //!< Optional field signalling progress within current state (picking/retrieving).
-        AZStd::string m_description; //!< Optional descriptive field to inform the user.
-    };
-
     //! A task to pick a single apple.
     struct PickAppleTask
     {
+        bool IsValid() const
+        {
+            return m_appleEntityId.IsValid();
+        }
+
+        void Invalidate()
+        {
+            m_appleEntityId = AZ::EntityId();
+        }
+
         AZ::EntityId m_appleEntityId; //!< EntityId of the apple. Can be Invalid if the information is not available (check IsValid()).
         AZ::Aabb m_appleBoundingBox; //!< Bounding box of the apple to pick.
         AZ::Vector3 m_middle; //!< Middle point of Apple
     };
 
+    //! A structure holding a state of effector, including optional progress and descriptive information.
+    struct PickingState
+    {
+        EffectorState m_effectorState = EffectorState::IDLE; //!< Current state of effector.
+        PickAppleTask m_currentTask; //!< Only valid for EffectorState::PICKING and EffectorState::RETRIEVING
+        float m_taskProgress = 0.0f; //!< Optional field signalling progress within current state (picking/retrieving).
+        AZStd::string m_description; //!< Optional descriptive field to inform the user.
+    };
+
     using StateTransition = std::pair<EffectorState, EffectorState>;
 } // namespace AppleKraken