Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
pluginmanager.c
Go to the documentation of this file.
2{
3 private ref array<typename> m_PluginRegister; // list of modules for creation
4 private ref map<typename, ref PluginBase> m_PluginsPtrs; // plugin, plugin pointer
5
6 //=================================
7 // Constructor
8 //=================================
9 void PluginManager()
10 {
11 m_PluginRegister = new array<typename>;
12 m_PluginsPtrs = new map<typename, ref PluginBase>;
13 }
14
15 //=================================
16 // Destructor
17 //=================================
18 void ~PluginManager()
19 {
20 int i;
21 PluginBase plugin;
22
23 for ( i = 0; i < m_PluginsPtrs.Count(); ++i)
24 {
25 plugin = m_PluginsPtrs.GetElement(i);
26 if ( plugin != NULL )
27 {
28 plugin.OnDestroy();
29 delete plugin;
30 }
31 }
32
33 GetGame().GetUpdateQueue(CALL_CATEGORY_GAMEPLAY).Remove(this.MainOnUpdate);
34 }
35
36 //=================================
37 // Init
38 //=================================
39 void Init()
40 {
41 //----------------------------------------------------------------------
42 // Register modules
43 //----------------------------------------------------------------------
44 // Module Class Name Client Server
45 //----------------------------------------------------------------------
46 RegisterPlugin( "PluginHorticulture", true, true );
47 RegisterPlugin( "PluginRepairing", true, true );
48 RegisterPlugin( "PluginPlayerStatus", true, true );
49 RegisterPlugin( "PluginMessageManager", true, true );
50 RegisterPlugin( "PluginLifespan", true, true );
51 RegisterPlugin( "PluginVariables", true, true );
52 RegisterPlugin( "PluginObjectsInteractionManager", false, true );
53 RegisterPlugin( "PluginRecipesManager", true, true );
54 RegisterPlugin( "PluginTransmissionAgents", true, true );
55 RegisterPlugin( "PluginConfigEmotesProfile", true, true );
56 RegisterPlugin( "PluginPresenceNotifier", true, false );
57 RegisterPlugin( "PluginAdminLog", false, true );
58
59 // Developer + Diag
60 RegisterPluginDiag( "PluginKeyBinding", true, false );
61 RegisterPluginDiag( "PluginDeveloper", true, true );
62 RegisterPluginDiag( "PluginDeveloperSync", true, true );
63 RegisterPluginDiag( "PluginDiagMenuClient", true, false );
64 RegisterPluginDiag( "PluginDiagMenuServer", false, true );
65 RegisterPluginDiag( "PluginPermanentCrossHair", true, false );
66 RegisterPluginDiag( "PluginRemotePlayerDebugClient", true, false );
67 RegisterPluginDiag( "PluginRemotePlayerDebugServer", false, true );
68 RegisterPluginDiag( "PluginUniversalTemperatureSourceClient", true, false );
69 RegisterPluginDiag( "PluginUniversalTemperatureSourceServer", false, true );
70 RegisterPluginDiag( "PluginTargetTemperature", true, false );
71 RegisterPluginDiag( "PluginDrawCheckerboard", true, false );
72 RegisterPluginDiag( "PluginItemDiagnostic", true, true );
73 RegisterPluginDiag( "PluginDayZCreatureAIDebug", true, true );
74
75 // Only In Debug / Internal
76 RegisterPluginDebug( "PluginConfigViewer", true, true );
77 RegisterPluginDebug( "PluginLocalEnscriptHistory", true, true );
78 RegisterPluginDebug( "PluginLocalEnscriptHistoryServer", true, true );
79
80 RegisterPluginDebug( "PluginSceneManager", true, true );
81 RegisterPluginDebug( "PluginConfigScene", true, true );
82 RegisterPluginDebug( "PluginMissionConfig", true, true );
83 RegisterPluginDebug( "PluginConfigEmotesProfile", true, true );
84 RegisterPluginDebug( "PluginConfigDebugProfile", true, true );
85 RegisterPluginDebug( "PluginConfigDebugProfileFixed", true, true );
86
87 RegisterPluginDebug( "PluginDayzPlayerDebug", true, true );
88 RegisterPluginDebug( "PluginDayZInfectedDebug", true, true );
89 RegisterPluginDebug( "PluginDoorRuler", true, false );
90 RegisterPluginDebug( "PluginCharPlacement", true, false );
91 //RegisterPluginDebug( "PluginSoundDebug", false, false );
92 RegisterPluginDebug( "PluginCameraTools", true, true );
93 RegisterPluginDebug( "PluginNutritionDumper", true, false );
94
95 GetGame().GetUpdateQueue(CALL_CATEGORY_GAMEPLAY).Insert(MainOnUpdate);
96 }
97
98 //=================================
99 // PluginsInit
100 //=================================
101 void PluginsInit()
102 {
103 int i = 0;
104 int regCount = m_PluginRegister.Count();
105
106 array<PluginBase> pluginPtrs = {};
107 pluginPtrs.Reserve(regCount);
108
109 foreach (typename pluginType : m_PluginRegister)
110 {
111 PluginBase moduleExist = GetPluginByType( pluginType );
112 if ( moduleExist )
113 {
114 m_PluginsPtrs.Remove( pluginType );
115 }
116
117 PluginBase moduleNew = PluginBase.Cast(pluginType.Spawn());
118 m_PluginsPtrs.Set(pluginType, moduleNew);
119 pluginPtrs.Insert(moduleNew);
120 }
121
122 foreach (PluginBase plugin : pluginPtrs)
123 {
124 if ( plugin )
125 {
126 plugin.OnInit();
127 }
128 }
129 }
130
131 //=================================
132 // MainOnUpdate
133 //=================================
134 void MainOnUpdate(float delta_time)
135 {
136 for ( int i = 0; i < m_PluginsPtrs.Count(); ++i)
137 {
138 PluginBase plugin = m_PluginsPtrs.GetElement(i);
139 if ( plugin != NULL )
140 {
141 plugin.OnUpdate(delta_time);
142 }
143 }
144 }
145
154 //=================================
155 // GetPluginByType
156 //=================================
157 PluginBase GetPluginByType( typename plugin_type )
158 {
159 if ( m_PluginsPtrs.Contains( plugin_type ) )
160 {
161 return m_PluginsPtrs.Get( plugin_type );
162 }
163
164 return null;
165 }
166
180 //=================================
181 // RegisterPlugin
182 //=================================
183 protected void RegisterPlugin( string plugin_class_name, bool reg_on_client, bool reg_on_server, bool reg_on_release = true )
184 {
185 if ( !reg_on_client )
186 {
187 if ( GetGame().IsMultiplayer() && GetGame().IsClient() )
188 {
189 return;
190 }
191 }
192
193 if ( !reg_on_server )
194 {
195 if ( GetGame().IsMultiplayer() )
196 {
197 if ( GetGame().IsServer() )
198 {
199 return;
200 }
201 }
202 }
203
204 if ( !reg_on_release )
205 {
206 if ( !GetGame().IsDebug() )
207 {
208 return;
209 }
210 }
211
212 m_PluginRegister.Insert( plugin_class_name.ToType() );
213 }
214
228 //=================================
229 // RegisterPlugin
230 //=================================
231 protected void RegisterPluginDebug( string plugin_class_name, bool reg_on_client, bool reg_on_server )
232 {
233 RegisterPlugin(plugin_class_name, reg_on_client, reg_on_server, false);
234 }
235 //=================================
236 // RegisterPlugin
237 //=================================
238 protected void RegisterPluginDiag( string plugin_class_name, bool reg_on_client, bool reg_on_server )
239 {
240 #ifdef DIAG_DEVELOPER
241 RegisterPlugin(plugin_class_name, reg_on_client, reg_on_server, true);
242 #else
243 return;
244 #endif
245 }
246
247 //---------------------------------
248 // UnregisterPlugin
249 //---------------------------------
250 protected bool UnregisterPlugin( string plugin_class_name )
251 {
252 typename plugin_type = plugin_class_name.ToType();
253
254 if ( m_PluginRegister.Find( plugin_type ) != -1 )
255 {
256 m_PluginRegister.RemoveItem( plugin_type );
257 return true;
258 }
259
260 return false;
261 }
262}
263
265
275{
276 /*
277 if ( g_Plugins == NULL )
278 {
279 PluginManagerInit();
280 }
281 */
282
283 return g_Plugins;
284}
285
286
288{
289 if (g_Plugins == NULL)
290 {
292 g_Plugins.Init();
293 g_Plugins.PluginsInit();
294 }
295}
296
298{
299 if ( g_Plugins )
300 {
301 delete g_Plugins;
302 g_Plugins = NULL;
303 }
304}
305
307{
308 if ( g_Plugins != null )
309 {
310 return true;
311 }
312
313 return false;
314}
315
316PluginBase GetPlugin(typename plugin_type)
317{
318 PluginBase plugin = null;
319
320 if ( IsPluginManagerExists() )
321 {
322 plugin = GetPluginManager().GetPluginByType(plugin_type);
323
324 if ( plugin == null )
325 {
326 #ifdef DIAG_DEVELOPER
327 if ( IsPluginManagerExists() )
328 {
329 PrintString("Module " + plugin_type.ToString() + " is not Registred in PluginManager.c!");
330 DumpStack();
331 }
332 #endif
333 }
334 }
335
336 return plugin;
337}
338
339bool IsModuleExist(typename plugin_type)
340{
341 if ( IsPluginManagerExists() )
342 {
343 return ( GetPlugin(plugin_type) != NULL );
344 }
345
346 return false;
347}
Plugin interface for controlling of agent pool system.
Definition pluginbase.c:2
void RegisterPluginDebug(string plugin_class_name, bool reg_on_client, bool reg_on_server)
Register new PluginBase to PluginManager for storing and handling plugin.
bool UnregisterPlugin(string plugin_class_name)
void RegisterPluginDiag(string plugin_class_name, bool reg_on_client, bool reg_on_server)
void RegisterPlugin(string plugin_class_name, bool reg_on_client, bool reg_on_server, bool reg_on_release=true)
Register new PluginBase to PluginManager for storing and handling plugin.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto void DumpStack()
Prints current call stack (stack trace)
class array< Class T > PrintString
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
PluginManager GetPluginManager()
Returns registred plugin by class type, better is to use global funtion GetPlugin(typename plugin_typ...
PluginBase GetPlugin(typename plugin_type)
bool IsPluginManagerExists()
bool IsModuleExist(typename plugin_type)
class PluginManager g_Plugins
void PluginManagerInit()
void PluginManagerDelete()