SceneReloadSoakTestComponent.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <EntityLatticeTestComponent.h>
  10. #include <ExampleComponentBus.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzCore/Math/Random.h>
  13. namespace AtomSampleViewer
  14. {
  15. //! This test repeatedly loads and unloads a set of models and materials at various intervals with
  16. //! the specific goal of exposing race conditions in the renderer and the asset system. Some of the
  17. //! intervals are intentionally too short, such that assets and instances will be shut down and released
  18. //! before they are fully loaded, initialized, and sent to the GPU.
  19. class SceneReloadSoakTestComponent final
  20. : public EntityLatticeTestComponent
  21. , public AZ::TickBus::Handler
  22. , public ExampleComponentRequestBus::Handler
  23. {
  24. using Base = EntityLatticeTestComponent;
  25. public:
  26. AZ_COMPONENT(SceneReloadSoakTestComponent, "{5D0B03A6-F7B9-4952-90AB-C91306229964}", EntityLatticeTestComponent);
  27. SceneReloadSoakTestComponent() = default;
  28. static void Reflect(AZ::ReflectContext* context);
  29. // AZ::Component overrides...
  30. void Activate() override;
  31. void Deactivate() override;
  32. private:
  33. AZ_DISABLE_COPY_MOVE(SceneReloadSoakTestComponent);
  34. struct TimeSetting
  35. {
  36. float resetDelay; //!< How many seconds to wait before resetting the scene
  37. uint32_t count; //!< How many times to use this resetDelay
  38. };
  39. // EntityLatticeTestComponent overrides...
  40. void PrepareCreateLatticeInstances(uint32_t instanceCount) override;
  41. void CreateLatticeInstance(const AZ::Transform& transform) override;
  42. void DestroyLatticeInstances() override;
  43. // AZ::TickBus::Handler overrides...
  44. void OnTick(float deltaTime, AZ::ScriptTimePoint scriptTime) override;
  45. // ExampleComponentRequestBus::Handler overrides...
  46. void ResetCamera() override;
  47. AZ::SimpleLcgRandom m_random;
  48. float m_countdown = 0;
  49. float m_totalTime = 0;
  50. AZStd::vector<TimeSetting> m_timeSettings;
  51. uint32_t m_currentSettingIndex = 0; //!< Which m_timeSettings entry is currently being used
  52. uint32_t m_currentCount = 0; //!< How many times the current TimeSetting has been used
  53. uint32_t m_totalResetCount = 0; //!< Total number of times the scene has been reset since activation
  54. AZ::Data::AssetId m_materialAssetId;
  55. AZ::Data::AssetId m_modelAssetId;
  56. AZStd::vector<bool> m_materialIsUnique; //!< Tracks whether each entity in the lattice uses its own unique material instance
  57. AZStd::vector<AZ::Render::MeshFeatureProcessorInterface::MeshHandle> m_meshHandles;
  58. };
  59. } // namespace AtomSampleViewer