DayZ 1.30
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 RegisterPluginDebug( "PluginUndergroundTriggerManager", true, false );
103
104 g_Game.GetUpdateQueue(CALL_CATEGORY_GAMEPLAY).Insert(MainOnUpdate);
105 }
106
107 //=================================
108 // PluginsInit
109 //=================================
111 {
112 int i = 0;
113 int regCount = m_PluginRegister.Count();
114
115 array<PluginBase> pluginPtrs = {};
116 pluginPtrs.Reserve(regCount);
117
118 foreach (typename pluginType : m_PluginRegister)
119 {
120 PluginBase moduleExist = GetPluginByType( pluginType );
121 if ( moduleExist )
122 {
123 m_PluginsPtrs.Remove( pluginType );
124 }
125
126 PluginBase moduleNew = PluginBase.Cast(pluginType.Spawn());
127 m_PluginsPtrs.Set(pluginType, moduleNew);
128 pluginPtrs.Insert(moduleNew);
129 }
130
131 foreach (PluginBase plugin : pluginPtrs)
132 {
133 if ( plugin )
134 {
135 plugin.OnInit();
136 }
137 }
138 }
139
140 //=================================
141 // MainOnUpdate
142 //=================================
143 void MainOnUpdate(float delta_time)
144 {
145 int nPlugins = m_PluginsPtrs.Count();
146 for (int i = 0; i < nPlugins; ++i)
147 {
148 PluginBase plugin = m_PluginsPtrs.GetElement(i);
149 if ( plugin != NULL )
150 {
151 plugin.OnUpdate(delta_time);
152 }
153 }
154 }
155
164 //=================================
165 // GetPluginByType
166 //=================================
167 PluginBase GetPluginByType( typename plugin_type )
168 {
169 if ( m_PluginsPtrs.Contains( plugin_type ) )
170 {
171 return m_PluginsPtrs.Get( plugin_type );
172 }
173
174 return null;
175 }
176
190 //=================================
191 // RegisterPlugin
192 //=================================
193 protected void RegisterPlugin( string plugin_class_name, bool reg_on_client, bool reg_on_server, bool reg_on_release = true )
194 {
195 if ( !reg_on_client )
196 {
197 if ( g_Game.IsMultiplayer() && g_Game.IsClient() )
198 {
199 return;
200 }
201 }
202
203 if ( !reg_on_server )
204 {
205 if ( g_Game.IsMultiplayer() )
206 {
207 if ( g_Game.IsServer() )
208 {
209 return;
210 }
211 }
212 }
213
214 if ( !reg_on_release )
215 {
216 if ( !g_Game.IsDebug() )
217 {
218 return;
219 }
220 }
221
222 m_PluginRegister.Insert( plugin_class_name.ToType() );
223 }
224
238 //=================================
239 // RegisterPlugin
240 //=================================
241 protected void RegisterPluginDebug( string plugin_class_name, bool reg_on_client, bool reg_on_server )
242 {
243 RegisterPlugin(plugin_class_name, reg_on_client, reg_on_server, false);
244 }
245 //=================================
246 // RegisterPlugin
247 //=================================
248 protected void RegisterPluginDiag( string plugin_class_name, bool reg_on_client, bool reg_on_server )
249 {
250 #ifdef DIAG_DEVELOPER
251 RegisterPlugin(plugin_class_name, reg_on_client, reg_on_server, true);
252 #else
253 return;
254 #endif
255 }
256
257 //---------------------------------
258 // UnregisterPlugin
259 //---------------------------------
260 protected bool UnregisterPlugin( string plugin_class_name )
261 {
262 typename plugin_type = plugin_class_name.ToType();
263
264 if ( m_PluginRegister.Find( plugin_type ) != -1 )
265 {
266 m_PluginRegister.RemoveItem( plugin_type );
267 return true;
268 }
269
270 return false;
271 }
272}
273
275
285{
286 /*
287 if ( g_Plugins == NULL )
288 {
289 PluginManagerInit();
290 }
291 */
292
293 return g_Plugins;
294}
295
296
298{
299 if (g_Plugins == NULL)
300 {
302 g_Plugins.Init();
303 g_Plugins.PluginsInit();
304 }
305}
306
308{
309 if ( g_Plugins )
310 {
311 delete g_Plugins;
312 g_Plugins = NULL;
313 }
314}
315
317{
318 if ( g_Plugins != null )
319 {
320 return true;
321 }
322
323 return false;
324}
325
326PluginBase GetPlugin(typename plugin_type)
327{
328 PluginBase plugin = null;
329
330 if ( IsPluginManagerExists() )
331 {
332 plugin = GetPluginManager().GetPluginByType(plugin_type);
333
334 if ( plugin == null )
335 {
336 #ifdef DIAG_DEVELOPER
337 if ( IsPluginManagerExists() )
338 {
339 PrintString("Module " + plugin_type.ToString() + " is not Registred in PluginManager.c!");
340 DumpStack();
341 }
342 #endif
343 }
344 }
345
346 return plugin;
347}
348
349// Inspired by BaseItem::SafeCast, no asserts version
350PluginBase GetPluginSafe(typename plugin_type)
351{
352 PluginBase plugin = null;
353
354 if ( IsPluginManagerExists() )
355 {
356 plugin = GetPluginManager().GetPluginByType(plugin_type);
357 }
358
359 return plugin;
360}
361
362bool IsModuleExist(typename plugin_type)
363{
364 if ( IsPluginManagerExists() )
365 {
366 return ( GetPlugin(plugin_type) != NULL );
367 }
368
369 return false;
370}
DayZGame g_Game
Определения DayZGame.c:4074
PluginManager GetPluginManager()
Returns registred plugin by class type, better is to use global funtion GetPlugin(typename plugin_typ...
Определения PluginManager.c:284
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:326
bool IsPluginManagerExists()
Определения PluginManager.c:316
bool IsModuleExist(typename plugin_type)
Определения PluginManager.c:362
PluginBase GetPluginSafe(typename plugin_type)
Определения PluginManager.c:350
class PluginManager g_Plugins
void PluginManagerInit()
Определения PluginManager.c:297
void PluginManagerDelete()
Определения PluginManager.c:307
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:167
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:241
void ~PluginManager()
Определения PluginManager.c:18
void PluginsInit()
Определения PluginManager.c:110
bool UnregisterPlugin(string plugin_class_name)
Определения PluginManager.c:260
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:248
void MainOnUpdate(float delta_time)
Определения PluginManager.c:143
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:193
Определения PluginManager.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Определения Transport.c:70
proto void DumpStack()
Prints current call stack (stack trace)
Obsolete Managed PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Определения EnScript.c:369
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