IGem.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "platform.h"
  10. #include "ISystem.h"
  11. #include "CrySystemBus.h"
  12. #include <AzCore/Module/Module.h>
  13. /**
  14. * CryHooksModule is an AZ::Module with common hooks into CryEngine systems.
  15. * - Sets gEnv once CrySystem has initialized.
  16. * - Registers as a CrySystem event handler.
  17. */
  18. class CryHooksModule
  19. : public AZ::Module
  20. , protected CrySystemEventBus::Handler
  21. , protected ISystemEventListener
  22. {
  23. public:
  24. AZ_CLASS_ALLOCATOR(CryHooksModule, AZ::SystemAllocator)
  25. AZ_RTTI(CryHooksModule, "{BD896D16-6F7D-4EA6-A532-0A9E6BF3C089}", AZ::Module);
  26. CryHooksModule()
  27. : Module()
  28. {
  29. CrySystemEventBus::Handler::BusConnect();
  30. }
  31. ~CryHooksModule() override
  32. {
  33. CrySystemEventBus::Handler::BusDisconnect();
  34. if (gEnv && gEnv->pSystem && gEnv->pSystem->GetISystemEventDispatcher())
  35. {
  36. gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener(this);
  37. }
  38. }
  39. protected:
  40. void OnCrySystemPreInitialize(ISystem& system, const SSystemInitParams& systemInitParams) override
  41. {
  42. (void)systemInitParams;
  43. #if !defined(AZ_MONOLITHIC_BUILD)
  44. // When module is linked dynamically, we must set our gEnv pointer.
  45. // When module is linked statically, we'll share the application's gEnv pointer.
  46. gEnv = system.GetGlobalEnvironment();
  47. #else
  48. (void)system;
  49. #endif
  50. }
  51. void OnCrySystemInitialized(ISystem& system, const SSystemInitParams& systemInitParams) override
  52. {
  53. (void)systemInitParams;
  54. system.GetISystemEventDispatcher()->RegisterListener(this);
  55. }
  56. void OnCrySystemPostShutdown() override
  57. {
  58. #if !defined(AZ_MONOLITHIC_BUILD)
  59. gEnv = nullptr;
  60. #endif
  61. }
  62. void OnSystemEvent(ESystemEvent /*event*/, UINT_PTR /*wparam*/, UINT_PTR /*lparam*/) override {}
  63. };