Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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( "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  //=================================
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  {
291  g_Plugins = new PluginManager;
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 
316 PluginBase 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 
339 bool IsModuleExist(typename plugin_type)
340 {
341  if ( IsPluginManagerExists() )
342  {
343  return ( GetPlugin(plugin_type) != NULL );
344  }
345 
346  return false;
347 }
GetGame
proto native CGame GetGame()
CALL_CATEGORY_GAMEPLAY
const int CALL_CATEGORY_GAMEPLAY
Definition: tools.c:10
PluginManagerDelete
void PluginManagerDelete()
Definition: pluginmanager.c:297
IsModuleExist
bool IsModuleExist(typename plugin_type)
Definition: pluginmanager.c:339
PluginBase
Definition: pluginadminlog.c:1
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
map
map
Definition: controlsxboxnew.c:3
IsPluginManagerExists
bool IsPluginManagerExists()
Definition: pluginmanager.c:306
PrintString
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition: enscript.c:345
g_Plugins
class PluginManager g_Plugins
GetPluginManager
PluginManager GetPluginManager()
Returns registred plugin by class type, better is to use global funtion GetPlugin(typename plugin_typ...
Definition: pluginmanager.c:274
DumpStack
proto void DumpStack()
Prints current call stack (stack trace)
array< typename >
PluginManager
Definition: pluginmanager.c:1
PluginManagerInit
void PluginManagerInit()
Definition: pluginmanager.c:287