DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PluginManager.c
См. документацию.
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 //=================================
14
15 //=================================
16 // Destructor
17 //=================================
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 g_Game.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#ifdef NO_GUI
61 RegisterPluginDiag( "PluginKeyBinding", true, false );
62#else
63 RegisterPluginDiag( "PluginKeyBinding", true, true );
64#endif
65 RegisterPluginDiag( "PluginDeveloper", true, true );
66 RegisterPluginDiag( "PluginDeveloperSync", true, true );
67 RegisterPluginDiag( "PluginDiagMenuClient", true, false );
68 RegisterPluginDiag( "PluginDiagMenuServer", false, true );
69 RegisterPluginDiag( "PluginPermanentCrossHair", true, false );
70 RegisterPluginDiag( "PluginRemotePlayerDebugClient", true, false );
71 RegisterPluginDiag( "PluginRemotePlayerDebugServer", false, true );
72 RegisterPluginDiag( "PluginUniversalTemperatureSourceClient", true, false );
73 RegisterPluginDiag( "PluginUniversalTemperatureSourceServer", false, true );
74 RegisterPluginDiag( "PluginTargetTemperature", true, false );
75 RegisterPluginDiag( "PluginDrawCheckerboard", true, false );
76 RegisterPluginDiag( "PluginItemDiagnostic", true, true );
77 RegisterPluginDiag( "PluginDayZCreatureAIDebug", true, true );
78
79 // Only In Debug / Internal
80 RegisterPluginDebug( "PluginConfigViewer", true, true );
81 RegisterPluginDebug( "PluginLocalEnscriptHistory", true, true );
82 RegisterPluginDebug( "PluginLocalEnscriptHistoryServer", true, true );
83
84 RegisterPluginDebug( "PluginSceneManager", true, true );
85 RegisterPluginDebug( "PluginConfigScene", true, true );
86 RegisterPluginDebug( "PluginMissionConfig", true, true );
87 RegisterPluginDebug( "PluginConfigEmotesProfile", true, true );
88 RegisterPluginDebug( "PluginConfigDebugProfile", true, true );
89 RegisterPluginDebug( "PluginConfigDebugProfileFixed", true, true );
90
91 RegisterPluginDebug( "PluginDayzPlayerDebug", true, true );
92 RegisterPluginDebug( "PluginDayZInfectedDebug", true, true );
93 RegisterPluginDebug( "PluginDoorRuler", true, false );
94 RegisterPluginDebug( "PluginCharPlacement", true, false );
95 //RegisterPluginDebug( "PluginSoundDebug", false, false );
96 RegisterPluginDebug( "PluginCameraTools", true, true );
97 RegisterPluginDebug( "PluginNutritionDumper", true, false );
98#ifdef DIAG_DEVELOPER
99 RegisterPluginDebug( "PluginInventoryDebug", true, true );
100#endif
101 RegisterPluginDebug( "PluginInventoryRepair", true, false );
102
103 g_Game.GetUpdateQueue(CALL_CATEGORY_GAMEPLAY).Insert(MainOnUpdate);
104 }
105
106 //=================================
107 // PluginsInit
108 //=================================
110 {
111 int i = 0;
112 int regCount = m_PluginRegister.Count();
113
114 array<PluginBase> pluginPtrs = {};
115 pluginPtrs.Reserve(regCount);
116
117 foreach (typename pluginType : m_PluginRegister)
118 {
119 PluginBase moduleExist = GetPluginByType( pluginType );
120 if ( moduleExist )
121 {
122 m_PluginsPtrs.Remove( pluginType );
123 }
124
125 PluginBase moduleNew = PluginBase.Cast(pluginType.Spawn());
126 m_PluginsPtrs.Set(pluginType, moduleNew);
127 pluginPtrs.Insert(moduleNew);
128 }
129
130 foreach (PluginBase plugin : pluginPtrs)
131 {
132 if ( plugin )
133 {
134 plugin.OnInit();
135 }
136 }
137 }
138
139 //=================================
140 // MainOnUpdate
141 //=================================
142 void MainOnUpdate(float delta_time)
143 {
144 int nPlugins = m_PluginsPtrs.Count();
145 for (int i = 0; i < nPlugins; ++i)
146 {
147 PluginBase plugin = m_PluginsPtrs.GetElement(i);
148 if ( plugin != NULL )
149 {
150 plugin.OnUpdate(delta_time);
151 }
152 }
153 }
154
163 //=================================
164 // GetPluginByType
165 //=================================
166 PluginBase GetPluginByType( typename plugin_type )
167 {
168 if ( m_PluginsPtrs.Contains( plugin_type ) )
169 {
170 return m_PluginsPtrs.Get( plugin_type );
171 }
172
173 return null;
174 }
175
189 //=================================
190 // RegisterPlugin
191 //=================================
192 protected void RegisterPlugin( string plugin_class_name, bool reg_on_client, bool reg_on_server, bool reg_on_release = true )
193 {
194 if ( !reg_on_client )
195 {
196 if ( g_Game.IsMultiplayer() && g_Game.IsClient() )
197 {
198 return;
199 }
200 }
201
202 if ( !reg_on_server )
203 {
204 if ( g_Game.IsMultiplayer() )
205 {
206 if ( g_Game.IsServer() )
207 {
208 return;
209 }
210 }
211 }
212
213 if ( !reg_on_release )
214 {
215 if ( !g_Game.IsDebug() )
216 {
217 return;
218 }
219 }
220
221 m_PluginRegister.Insert( plugin_class_name.ToType() );
222 }
223
237 //=================================
238 // RegisterPlugin
239 //=================================
240 protected void RegisterPluginDebug( string plugin_class_name, bool reg_on_client, bool reg_on_server )
241 {
242 RegisterPlugin(plugin_class_name, reg_on_client, reg_on_server, false);
243 }
244 //=================================
245 // RegisterPlugin
246 //=================================
247 protected void RegisterPluginDiag( string plugin_class_name, bool reg_on_client, bool reg_on_server )
248 {
249 #ifdef DIAG_DEVELOPER
250 RegisterPlugin(plugin_class_name, reg_on_client, reg_on_server, true);
251 #else
252 return;
253 #endif
254 }
255
256 //---------------------------------
257 // UnregisterPlugin
258 //---------------------------------
259 protected bool UnregisterPlugin( string plugin_class_name )
260 {
261 typename plugin_type = plugin_class_name.ToType();
262
263 if ( m_PluginRegister.Find( plugin_type ) != -1 )
264 {
265 m_PluginRegister.RemoveItem( plugin_type );
266 return true;
267 }
268
269 return false;
270 }
271}
272
274
284{
285 /*
286 if ( g_Plugins == NULL )
287 {
288 PluginManagerInit();
289 }
290 */
291
292 return g_Plugins;
293}
294
295
297{
298 if (g_Plugins == NULL)
299 {
301 g_Plugins.Init();
302 g_Plugins.PluginsInit();
303 }
304}
305
307{
308 if ( g_Plugins )
309 {
310 delete g_Plugins;
311 g_Plugins = NULL;
312 }
313}
314
316{
317 if ( g_Plugins != null )
318 {
319 return true;
320 }
321
322 return false;
323}
324
325PluginBase GetPlugin(typename plugin_type)
326{
327 PluginBase plugin = null;
328
329 if ( IsPluginManagerExists() )
330 {
331 plugin = GetPluginManager().GetPluginByType(plugin_type);
332
333 if ( plugin == null )
334 {
335 #ifdef DIAG_DEVELOPER
336 if ( IsPluginManagerExists() )
337 {
338 PrintString("Module " + plugin_type.ToString() + " is not Registred in PluginManager.c!");
339 DumpStack();
340 }
341 #endif
342 }
343 }
344
345 return plugin;
346}
347
348// Inspired by BaseItem::SafeCast, no asserts version
349PluginBase GetPluginSafe(typename plugin_type)
350{
351 PluginBase plugin = null;
352
353 if ( IsPluginManagerExists() )
354 {
355 plugin = GetPluginManager().GetPluginByType(plugin_type);
356 }
357
358 return plugin;
359}
360
361bool IsModuleExist(typename plugin_type)
362{
363 if ( IsPluginManagerExists() )
364 {
365 return ( GetPlugin(plugin_type) != NULL );
366 }
367
368 return false;
369}
DayZGame g_Game
Определения DayZGame.c:3942
PluginManager GetPluginManager()
Returns registred plugin by class type, better is to use global funtion GetPlugin(typename plugin_typ...
Определения PluginManager.c:283
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:325
bool IsPluginManagerExists()
Определения PluginManager.c:315
bool IsModuleExist(typename plugin_type)
Определения PluginManager.c:361
PluginBase GetPluginSafe(typename plugin_type)
Определения PluginManager.c:349
class PluginManager g_Plugins
void PluginManagerInit()
Определения PluginManager.c:296
void PluginManagerDelete()
Определения PluginManager.c:306
void OnDestroy()
void OnUpdate(float delta_time)
Plugin interface for controlling of agent pool system.
Определения PluginBase.c:2
PluginBase GetPluginByType(typename plugin_type)
Returns registred plugin by class type, better is to use global funtion GetPlugin(typename plugin_typ...
Определения PluginManager.c:166
void RegisterPluginDebug(string plugin_class_name, bool reg_on_client, bool reg_on_server)
Register new PluginBase to PluginManager for storing and handling plugin.
Определения PluginManager.c:240
void ~PluginManager()
Определения PluginManager.c:18
void PluginsInit()
Определения PluginManager.c:109
bool UnregisterPlugin(string plugin_class_name)
Определения PluginManager.c:259
ref map< typename, ref PluginBase > m_PluginsPtrs
Определения PluginManager.c:4
void RegisterPluginDiag(string plugin_class_name, bool reg_on_client, bool reg_on_server)
Определения PluginManager.c:247
void MainOnUpdate(float delta_time)
Определения PluginManager.c:142
ref array< typename > m_PluginRegister
Определения PluginManager.c:3
void Init()
Определения PluginManager.c:39
void PluginManager()
Определения PluginManager.c:9
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.
Определения PluginManager.c:192
Определения PluginManager.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Определения CachedEquipmentStorage.c:4
proto void DumpStack()
Prints current call stack (stack trace)
class array< Class T > PrintString
proto native ToType()
Returns internal type representation. Can be used in runtime, or cached in variables and used for fas...
const int CALL_CATEGORY_GAMEPLAY
Определения 3_Game/DayZ/tools/tools.c:10