Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.54 KB | None | 0 0
  1. #include "MyProject123_precompiled.h"
  2.  
  3. #include <AzCore/Module/Module.h>
  4. #include <AzCore/Component/Entity.h>
  5. #include <platform_impl.h>
  6. #include <AzCore/Memory/SystemAllocator.h>
  7.  
  8. #include <IGem.h>
  9. #include <IActionMapManager.h>
  10. #include <IGameObjectSystem.h>
  11. #include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
  12. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  13.  
  14.  
  15. #include "MyProject123SystemComponent.h"
  16. #include "Components/MyComponent.h"
  17. #include "Components/SimpleCameraController.h"
  18. #include "Components/Jumper.h"
  19. #include "Components/TrackViewExposed.h"
  20. #include "Systems/MyCustomSystemComponent.h"
  21.  
  22.  
  23.  
  24. namespace MyProject123
  25. {
  26.     class MyProject123Module :
  27.         public CryHooksModule,
  28.         public IActionListener
  29.     {
  30.     public:
  31.         AZ_RTTI(MyProject123Module, "{75E7F080-AFD0-40C6-9A29-833B20E74EA8}", CryHooksModule);
  32.         AZ_CLASS_ALLOCATOR(MyProject123Module, AZ::SystemAllocator, 0);
  33.  
  34.         MyProject123Module() : CryHooksModule()
  35.         {
  36.             // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here.
  37.            
  38.             m_descriptors.push_back(MyComponent::CreateDescriptor());
  39.             m_descriptors.push_back(SimpleCameraControllerComponent::CreateDescriptor());
  40.             m_descriptors.push_back(MyProject123SystemComponent::CreateDescriptor());
  41.             m_descriptors.push_back(JumperComponent::CreateDescriptor());
  42.             m_descriptors.push_back(TrackViewExposedComponent::CreateDescriptor());
  43.  
  44.             // System Components
  45.             RegisterSystemComponent<MyProject123SystemComponent>(); // default system created with project
  46.             RegisterSystemComponent<MyCustomSystemComponent>();     // my system
  47.         }
  48.  
  49.         AZ::ComponentTypeList GetRequiredSystemComponents() const override
  50.         {
  51.             return m_systemComponents;
  52.         }
  53.  
  54.         void OnSystemEvent(ESystemEvent systemEvent, UINT_PTR wparam, UINT_PTR lparam)
  55.         {
  56.             CryHooksModule::OnSystemEvent(systemEvent, wparam, lparam);
  57.  
  58.             switch (systemEvent)
  59.             {
  60.             case ESYSTEM_EVENT_GAME_POST_INIT_DONE:
  61.             {
  62.                 RegisterForInput();
  63.                 // load level here?            
  64.             }
  65.             break;
  66.             case ESYSTEM_EVENT_FULL_SHUTDOWN:
  67.             {
  68.                 UnregisterFromInput();
  69.             }
  70.             break;
  71.             default:
  72.                 break;
  73.             }
  74.         }
  75.        
  76.         template<class T>
  77.         void RegisterSystemComponent()
  78.         {
  79.             m_descriptors.push_back(T::CreateDescriptor());
  80.             m_systemComponents.push_back(azrtti_typeid<T>());
  81.         }
  82.  
  83.  
  84.         // IActionListener
  85.         void OnAction(const ActionId& action, int activationMode, float value) override
  86.         {
  87.             if (activationMode & eAAM_OnPress)
  88.             {
  89.                 OnActionPressed(action, value);
  90.             }
  91.             else if (activationMode & eAAM_OnHold)
  92.             {
  93.                 //OnActionHeld(action, value);
  94.             }
  95.             else if (activationMode & eAAM_OnRelease)
  96.             {
  97.                 //OnActionReleased(action, value);
  98.             }
  99.             else if (activationMode & eAAM_Always)
  100.             {
  101.                 //OnActionAlways(action, value);
  102.             }
  103.         }
  104.  
  105.         void OnActionPressed(const ActionId & action, float value)
  106.         {
  107.             const char* actionString = action.c_str();
  108.  
  109.             if (azstricmp(actionString, "exitgame") == 0)
  110.             {
  111.                 // hey! plz stop spinning of the Earth, here I'm out!
  112.             }
  113.             else
  114.             {
  115.                 AZ_Error("SimpleCameraControllerComponent", false, "Unknown command - %s", action.c_str());
  116.             }
  117.         }
  118.  
  119.         void RegisterForInput()
  120.         {
  121.             IGame* pGame = gEnv ? gEnv->pGame : nullptr;
  122.             IGameFramework* pGameFramework = pGame ? pGame->GetIGameFramework() : nullptr;
  123.             IActionMapManager* actionMapManager = pGameFramework ? pGameFramework->GetIActionMapManager() : nullptr;
  124.  
  125.             if (!actionMapManager)
  126.             {
  127.                 return;
  128.             }
  129.  
  130.             actionMapManager->EnableActionMap("gamelauncher", true);
  131.             actionMapManager->AddExtraActionListener(this, "gamelauncher");
  132.         }
  133.  
  134.         void UnregisterFromInput()
  135.         {
  136.             IGame* pGame = gEnv ? gEnv->pGame : nullptr;
  137.             IGameFramework* pGameFramework = pGame ? pGame->GetIGameFramework() : nullptr;
  138.             IActionMapManager* actionMapManager = pGameFramework ? pGameFramework->GetIActionMapManager() : nullptr;
  139.  
  140.             if (!actionMapManager)
  141.             {
  142.                 return;
  143.             }
  144.  
  145.             actionMapManager->RemoveExtraActionListener(this, "gamelauncher");
  146.             actionMapManager->EnableActionMap("gamelauncher", false);
  147.         }
  148.  
  149.     protected:
  150.         AZ::ComponentTypeList m_systemComponents;
  151.     };
  152. }
  153.  
  154. // DO NOT MODIFY THIS LINE UNLESS YOU RENAME THE GEM
  155. // The first parameter should be GemName_GemIdLower
  156. // The second should be the fully qualified name of the class above
  157. AZ_DECLARE_MODULE_CLASS(MyProject123_99921f26970945c38f23c14f164ae6f9, MyProject123::MyProject123Module)
  158.  
  159. //AZ_DECLARE_MODULE_CLASS(MyProject123Module, MyProject123::MyProject123Module)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement