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