SceneReloadSoakTestComponent.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // Instead of using the CommonPhotosensitiveWarning, I used a custom message here that specifically calls out headaches and nausea
  28. // as I've personally experienced those while looking at this sample, even though I don't otherwise consider myself to be photosensitive.
  29. static constexpr const char* ContentWarning = "This sample has lots of flashing, may cause headaches and nausea, or may cause seizures for people with certain photosensitivity.";
  30. static constexpr const char* ContentWarningTitle = CommonPhotosensitiveWarningTitle;
  31. SceneReloadSoakTestComponent() = default;
  32. static void Reflect(AZ::ReflectContext* context);
  33. // AZ::Component overrides...
  34. void Activate() override;
  35. void Deactivate() override;
  36. private:
  37. AZ_DISABLE_COPY_MOVE(SceneReloadSoakTestComponent);
  38. struct TimeSetting
  39. {
  40. float resetDelay; //!< How many seconds to wait before resetting the scene
  41. uint32_t count; //!< How many times to use this resetDelay
  42. };
  43. // EntityLatticeTestComponent overrides...
  44. void PrepareCreateLatticeInstances(uint32_t instanceCount) override;
  45. void CreateLatticeInstance(const AZ::Transform& transform) override;
  46. void DestroyLatticeInstances() override;
  47. // AZ::TickBus::Handler overrides...
  48. void OnTick(float deltaTime, AZ::ScriptTimePoint scriptTime) override;
  49. // ExampleComponentRequestBus::Handler overrides...
  50. void ResetCamera() override;
  51. AZ::SimpleLcgRandom m_random;
  52. float m_countdown = 0;
  53. float m_totalTime = 0;
  54. AZStd::vector<TimeSetting> m_timeSettings;
  55. uint32_t m_currentSettingIndex = 0; //!< Which m_timeSettings entry is currently being used
  56. uint32_t m_currentCount = 0; //!< How many times the current TimeSetting has been used
  57. uint32_t m_totalResetCount = 0; //!< Total number of times the scene has been reset since activation
  58. AZ::Data::AssetId m_materialAssetId;
  59. AZ::Data::AssetId m_modelAssetId;
  60. AZStd::vector<bool> m_materialIsUnique; //!< Tracks whether each entity in the lattice uses its own unique material instance
  61. AZStd::vector<AZ::Render::MeshFeatureProcessorInterface::MeshHandle> m_meshHandles;
  62. };
  63. } // namespace AtomSampleViewer