DayZ 1.24
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 //=================================
14
15 //=================================
16 // Destructor
17 //=================================
19 {
20 int i;
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("PluginAdditionalInfo", true, true); //TODO clean up after Gamescom
56 RegisterPlugin("PluginConfigEmotesProfile", true, true);
57 RegisterPlugin("PluginPresenceNotifier", true, false);
58 RegisterPlugin("PluginAdminLog", false, true);
59
60 // Developer + Diag
61 RegisterPluginDiag("PluginKeyBinding", true, false);
62 RegisterPluginDiag("PluginDeveloper", true, true);
63 RegisterPluginDiag("PluginDeveloperSync", true, true);
64 RegisterPluginDiag("PluginDiagMenuClient", true, false);
65 RegisterPluginDiag("PluginDiagMenuServer", false, true);
66 RegisterPluginDiag("PluginPermanentCrossHair", true, false);
67 RegisterPluginDiag("PluginRemotePlayerDebugClient", true, false);
68 RegisterPluginDiag("PluginRemotePlayerDebugServer", false, true);
69 RegisterPluginDiag("PluginUniversalTemperatureSourceClient", true, false);
70 RegisterPluginDiag("PluginUniversalTemperatureSourceServer", false, true);
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 //=================================
102 {
103 int i = 0;
104 int regCount = m_PluginRegister.Count();
105
107 pluginPtrs.Reserve(regCount);
108
109 foreach (typename pluginType : m_PluginRegister)
110 {
112 if (moduleExist)
114
117 pluginPtrs.Insert(moduleNew);
118 }
119
120 foreach (PluginBase plugin : pluginPtrs)
121 {
122 if (plugin)
123 plugin.OnInit();
124 }
125 }
126
127 //=================================
128 // MainOnUpdate
129 //=================================
131 {
132 for (int i = 0; i < m_PluginsPtrs.Count(); ++i)
133 {
134 PluginBase plugin = m_PluginsPtrs.GetElement(i);
135 if (plugin != NULL)
136 plugin.OnUpdate(delta_time);
137 }
138 }
139
148 //=================================
149 // GetPluginByType
150 //=================================
152 {
153 if (m_PluginsPtrs.Contains(plugin_type))
154 return m_PluginsPtrs.Get(plugin_type);
155
156 return null;
157 }
158
172 //=================================
173 // RegisterPlugin
174 //=================================
175 protected void RegisterPlugin(string plugin_class_name, bool reg_on_client, bool reg_on_server, bool reg_on_release = true)
176 {
177 if (!reg_on_client)
178 {
179 if (GetGame().IsMultiplayer() && GetGame().IsClient())
180 return;
181 }
182
183 if (!reg_on_server)
184 {
185 if (GetGame().IsMultiplayer())
186 {
187 if (GetGame().IsServer())
188 return;
189 }
190 }
191
192 if (!reg_on_release)
193 {
194 if (!GetGame().IsDebug())
195 return;
196 }
197
198 m_PluginRegister.Insert(plugin_class_name.ToType());
199 }
200
214 //=================================
215 // RegisterPlugin
216 //=================================
221 //=================================
222 // RegisterPlugin
223 //=================================
225 {
226#ifdef DIAG_DEVELOPER
228#else
229 return;
230#endif
231 }
232
233 //---------------------------------
234 // UnregisterPlugin
235 //---------------------------------
236 protected bool UnregisterPlugin(string plugin_class_name)
237 {
238 typename plugin_type = plugin_class_name.ToType();
239
240 if (m_PluginRegister.Find(plugin_type) != -1)
241 {
242 m_PluginRegister.RemoveItem(plugin_type);
243 return true;
244 }
245
246 return false;
247 }
248}
249
251
261{
262 /*
263 if ( g_Plugins == NULL )
264 {
265 PluginManagerInit();
266 }
267 */
268
269 return g_Plugins;
270}
271
272
274{
275 if (g_Plugins == NULL)
276 {
278 g_Plugins.Init();
279 g_Plugins.PluginsInit();
280 }
281}
282
284{
285 if (g_Plugins)
286 {
287 delete g_Plugins;
288 g_Plugins = NULL;
289 }
290}
291
293{
294 if (g_Plugins != null)
295 return true;
296
297 return false;
298}
299
301{
303
305 {
307
308 if (plugin == null)
309 {
310#ifdef DIAG_DEVELOPER
312 {
313 PrintString("Module " + plugin_type.ToString() + " is not Registred in PluginManager.c!");
314 DumpStack();
315 }
316#endif
317 }
318 }
319
320 return plugin;
321}
322
324{
326 return (GetPlugin(plugin_type) != NULL);
327
328 return false;
329}
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()
PluginBase GetPluginByType(typename plugin_type)
Returns registred plugin by class type, better is to use global funtion GetPlugin(typename plugin_typ...
void RegisterPluginDebug(string plugin_class_name, bool reg_on_client, bool reg_on_server)
Register new PluginBase to PluginManager for storing and handling plugin.
void ~PluginManager()
bool UnregisterPlugin(string plugin_class_name)
ref map< typename, ref PluginBase > m_PluginsPtrs
void RegisterPluginDiag(string plugin_class_name, bool reg_on_client, bool reg_on_server)
void MainOnUpdate(float delta_time)
ref array< typename > m_PluginRegister
void PluginManager()
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.
proto native CGame GetGame()
proto void DumpStack()
Prints current call stack (stack trace)
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:344
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10