EntityLatticeTestComponent.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <CommonSampleComponentBase.h>
  9. #include <Utils/Utils.h>
  10. #include <EntityLatticeTestComponent_Traits_Platform.h>
  11. struct ImGuiContext;
  12. namespace AtomSampleViewer
  13. {
  14. //! Common base class for test components that display a lattice of entities.
  15. class EntityLatticeTestComponent
  16. : public CommonSampleComponentBase
  17. {
  18. public:
  19. AZ_RTTI(EntityLatticeTestComponent, "{73C13F66-6F5B-43D3-B1F0-CB4F7BEA1334}", CommonSampleComponentBase)
  20. static void Reflect(AZ::ReflectContext* context);
  21. // AZ::Component overrides...
  22. void Activate() override;
  23. void Deactivate() override;
  24. protected:
  25. //! Returns total number of instances (width * height * depth)
  26. uint32_t GetInstanceCount() const;
  27. //! Call this to render ImGui controls for controlling the size of the lattice.
  28. void RenderImGuiLatticeControls();
  29. //! Destroys and rebuilds the lattice.
  30. virtual void RebuildLattice();
  31. void SetLatticeDimensions(uint32_t width, uint32_t depth, uint32_t height);
  32. private:
  33. //! Called once before CreateLatticeInstance() is called for each instance so the subclass can prepare for the total number of instances.
  34. virtual void PrepareCreateLatticeInstances(uint32_t instanceCount) = 0;
  35. //! This is called for each entity in the lattice when it is being built. The subclass should attach
  36. //! whatever components are necessary to achieve the desired result.
  37. virtual void CreateLatticeInstance(const AZ::Transform& transform) = 0;
  38. //! This is called after all the instances are created to any final work. Not required.
  39. virtual void FinalizeLatticeInstances() {};
  40. //! Called when the subclass should destroy all of its instances, either because of shutdown or recreation.
  41. virtual void DestroyLatticeInstances() = 0;
  42. void BuildLattice();
  43. // These are signed to avoid casting with imgui controls.
  44. int32_t m_latticeWidth = ENTITY_LATTICE_TEST_COMPONENT_WIDTH;
  45. int32_t m_latticeHeight = ENTITY_LATTICE_TEST_COMPONENT_HEIGHT;
  46. int32_t m_latticeDepth = ENTITY_LATTICE_TEST_COMPONENT_DEPTH;
  47. Utils::DefaultIBL m_defaultIbl;
  48. };
  49. } // namespace AtomSampleViewer