1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "AnimationBase.h"
6 #include <CryAnimation/ICryAnimation.h>
7 #include <CryAnimation/IFacialAnimation.h>
8 #include "CharacterManager.h"
9 #include "AnimEventLoader.h"
10 #include "SkeletonAnim.h"
11 #include "AttachmentSkin.h"
13 #include <CryCore/Platform/platform_impl.inl> // Must be included once in the module.
14 #include <CrySystem/IEngineModule.h>
16 //////////////////////////////////////////////////////////////////////////
17 struct CSystemEventListener_Animation
: public ISystemEventListener
20 virtual void OnSystemEvent(ESystemEvent event
, UINT_PTR wparam
, UINT_PTR lparam
)
24 case ESYSTEM_EVENT_LEVEL_UNLOAD
:
26 case ESYSTEM_EVENT_LEVEL_POST_UNLOAD
:
28 if (Memory::CPoolFrameLocal
* pMemoryPool
= CharacterInstanceProcessing::GetMemoryPool())
30 pMemoryPool
->ReleaseBuckets();
33 if (!gEnv
->IsEditor())
35 delete g_pCharacterManager
;
36 g_pCharacterManager
= NULL
;
37 gEnv
->pCharacterManager
= NULL
;
42 case ESYSTEM_EVENT_3D_POST_RENDERING_START
:
44 if (!g_pCharacterManager
)
46 g_pCharacterManager
= new CharacterManager
;
47 gEnv
->pCharacterManager
= g_pCharacterManager
;
49 AnimEventLoader::SetPreLoadParticleEffects(false);
52 case ESYSTEM_EVENT_3D_POST_RENDERING_END
:
54 if (Memory::CPoolFrameLocal
* pMemoryPool
= CharacterInstanceProcessing::GetMemoryPool())
56 pMemoryPool
->ReleaseBuckets();
59 SAFE_DELETE(g_pCharacterManager
);
60 gEnv
->pCharacterManager
= NULL
;
61 AnimEventLoader::SetPreLoadParticleEffects(true);
64 case ESYSTEM_EVENT_LEVEL_LOAD_START
:
66 if (!g_pCharacterManager
)
68 g_pCharacterManager
= new CharacterManager
;
69 gEnv
->pCharacterManager
= g_pCharacterManager
;
70 gEnv
->pCharacterManager
->PostInit();
77 static CSystemEventListener_Animation g_system_event_listener_anim
;
79 //////////////////////////////////////////////////////////////////////////
80 class CEngineModule_CryAnimation
: public IAnimationEngineModule
83 CRYINTERFACE_ADD(Cry::IDefaultModule
)
84 CRYINTERFACE_ADD(IAnimationEngineModule
)
86 CRYGENERATE_SINGLETONCLASS_GUID(CEngineModule_CryAnimation
, "EngineModule_CryAnimation", "9c73d2cd-142c-4256-a8f0-706d80cd7ad2"_cry_guid
)
88 virtual ~CEngineModule_CryAnimation()
90 gEnv
->pSystem
->GetISystemEventDispatcher()->RemoveListener(&g_system_event_listener_anim
);
91 SAFE_RELEASE(gEnv
->pCharacterManager
);
94 //////////////////////////////////////////////////////////////////////////
95 virtual const char* GetName() const override
{ return "CryAnimation"; };
96 virtual const char* GetCategory() const override
{ return "CryEngine"; };
98 //////////////////////////////////////////////////////////////////////////
99 virtual bool Initialize(SSystemGlobalEnvironment
& env
, const SSystemInitParams
& initParams
) override
101 ISystem
* pSystem
= env
.pSystem
;
103 if (!CharacterInstanceProcessing::InitializeMemoryPool())
106 g_pISystem
= pSystem
;
109 if (!g_controllerHeap
.IsInitialised())
110 g_controllerHeap
.Init(Console::GetInst().ca_MemoryDefragPoolSize
);
112 pSystem
->GetISystemEventDispatcher()->RegisterListener(&g_system_event_listener_anim
, "CSystemEventListener_Animation");
114 g_pCharacterManager
= NULL
;
115 env
.pCharacterManager
= NULL
;
116 if (gEnv
->IsEditor())
118 g_pCharacterManager
= new CharacterManager
;
119 gEnv
->pCharacterManager
= g_pCharacterManager
;
126 CRYREGISTER_SINGLETON_CLASS(CEngineModule_CryAnimation
)
128 // cached interfaces - valid during the whole session, when the character manager is alive; then get erased
129 ISystem
* g_pISystem
= NULL
;
130 ITimer
* g_pITimer
= NULL
; //module implemented in CrySystem
131 ILog
* g_pILog
= NULL
; //module implemented in CrySystem
132 IConsole
* g_pIConsole
= NULL
; //module implemented in CrySystem
133 ICryPak
* g_pIPak
= NULL
; //module implemented in CrySystem
134 IStreamEngine
* g_pIStreamEngine
= NULL
; //module implemented in CrySystem
136 IRenderer
* g_pIRenderer
= NULL
;
137 IPhysicalWorld
* g_pIPhysicalWorld
= NULL
;
138 I3DEngine
* g_pI3DEngine
= NULL
; //Need just for loading of chunks. Should be part of CrySystem
140 f32 g_AverageFrameTime
= 0;
141 CAnimation g_DefaultAnim
;
142 CharacterManager
* g_pCharacterManager
;
143 QuatT g_IdentityQuatT
= QuatT(IDENTITY
);
144 int32 g_nRenderThreadUpdateID
= 0;
145 DynArray
<string
> g_DataMismatch
;
146 SParametricSamplerInternal
* g_parametricPool
= NULL
;
147 bool* g_usedParametrics
= NULL
;
148 int32 g_totalParametrics
= 0;
149 uint32 g_DefaultTransitionInterpolationType
= (uint32
)CA_Interpolation_Type::QuadraticInOut
;
150 AABB g_IdentityAABB
= AABB(ZERO
, ZERO
);
152 CControllerDefragHeap g_controllerHeap
;
154 ILINE
void g_LogToFile(const char* szFormat
, ...)
156 char szBuffer
[2 * 1024];
158 va_start(args
, szFormat
);
159 cry_vsprintf(szBuffer
, szFormat
, args
);
161 g_pILog
->LogToFile("%s", szBuffer
);
166 AnimStatisticsInfo g_AnimStatisticsInfo
;
168 // TypeInfo implementations for CryAnimation
170 #include <CryCore/Common_TypeInfo.h>
171 #include <Cry3DEngine/CGF/CGFContent_info.h>