Browse Source

made counter static

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 2 years ago
parent
commit
ca9d96e63a

+ 6 - 3
Project/Gem/Source/FruitStorage/FruitStorageComponent.cpp

@@ -145,7 +145,9 @@ namespace AppleKraken
             SpawnCrate();
             SpawnCrate();
             m_applesInStorage = 0;
             m_applesInStorage = 0;
         }
         }
-        displayNumberOfApples(m_applesGathered);
+
+        m_allApplesGathered++;
+        displayNumberOfApples(m_allApplesGathered);
     }
     }
 
 
     void FruitStorageComponent::displayNumberOfApples(int num){
     void FruitStorageComponent::displayNumberOfApples(int num){
@@ -169,14 +171,15 @@ namespace AppleKraken
             AZ_Warning("FruitStorageComponent", false,  "ui canvas doest not have %s \n", kAppleGatheredElementName.c_str());
             AZ_Warning("FruitStorageComponent", false,  "ui canvas doest not have %s \n", kAppleGatheredElementName.c_str());
             return;
             return;
         }
         }
-        AZStd::string t = "Apples gathered : " + AZStd::to_string(m_applesGathered);
+        AZStd::string t = "Apples gathered : " + AZStd::to_string(num);
         UiTextBus::Event(ui_text_entity, &UiTextInterface::SetText, t);
         UiTextBus::Event(ui_text_entity, &UiTextInterface::SetText, t);
     }
     }
 
 
     void FruitStorageComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     void FruitStorageComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     {
     {
-        displayNumberOfApples(m_applesGathered);
+        displayNumberOfApples(m_allApplesGathered);
         AZ::TickBus::Handler::BusDisconnect();
         AZ::TickBus::Handler::BusDisconnect();
     }
     }
     const AZStd::string FruitStorageComponent::kAppleGatheredElementName{"AppleGatheredElement"};
     const AZStd::string FruitStorageComponent::kAppleGatheredElementName{"AppleGatheredElement"};
+    AZStd::atomic_int32_t FruitStorageComponent::m_allApplesGathered {0};
 } // namespace AppleKraken
 } // namespace AppleKraken

+ 1 - 0
Project/Gem/Source/FruitStorage/FruitStorageComponent.h

@@ -45,6 +45,7 @@ namespace AppleKraken
         uint32_t m_crateCapacity = 0;
         uint32_t m_crateCapacity = 0;
         uint32_t m_applesGathered = 0;
         uint32_t m_applesGathered = 0;
         uint32_t m_applesInStorage = 0;
         uint32_t m_applesInStorage = 0;
+        static AZStd::atomic_int32_t m_allApplesGathered;
         ApplesGatheredByTag m_tagsStored;
         ApplesGatheredByTag m_tagsStored;
         AZ::EntityId m_ui_entity;
         AZ::EntityId m_ui_entity;
         const static AZStd::string kAppleGatheredElementName;
         const static AZStd::string kAppleGatheredElementName;