/// <summary>Don't call me unless your name is <see cref="EngineSystemAttribute"/>!</summary> /// <param name="systemMetadata"> The system metadata. </param> internal static void Register(EngineSystemAttribute systemMetadata) { Contract.Requires(systemMetadata != null); // IReadOnlyDictionary's ContainsKey is not Pure. Check is instead performed in EngineSystemAttribute code //Contract.Requires(!Systems.ContainsKey(systemMetadata.Guid)); gSystems.Add(systemMetadata.Guid, systemMetadata); }
/// <summary>Causes all engine systems to globally initialize and register themselves</summary> internal static void InitializeForNewProgram() { if (mIsInitializedForNewProgram) { throw new System.InvalidOperationException("Tried to initialize the engine registry for a program more than once"); } EngineSystemAttribute.InitializeForNewAssembly(System.Reflection.Assembly.GetCallingAssembly()); mIsInitializedForNewProgram = true; }
public EngineSystemReference <T> GetSystem <T>(EngineBuildHandle forBuild) where T : EngineSystemBase { Contract.Requires <ArgumentNullException>(!forBuild.IsNone); Contract.Requires(forBuild.EngineIndex == RootBuildHandle.EngineIndex); var system_guid = EngineSystemAttribute.GetSystemGuid <T>(); var system = (T)GetSystem(system_guid, forBuild); return(new EngineSystemReference <T>(system, forBuild)); }
EngineSystemBase GetNewOrExistingSystem(EngineSystemAttribute systemMetadata) { // All we care about doing here is getting or constructing a new system. // Referencing counting and the like is handled elsewhere (hopefully only in EngineSystemReference) var proto_system = mSystemPrototypes[systemMetadata.SystemGuid]; EngineSystemBase system; lock (mActiveSystems) if (!mActiveSystems.TryGetValue(systemMetadata.SystemGuid, out system)) { system = systemMetadata.NewInstance(proto_system); mActiveSystems.Add(systemMetadata.SystemGuid, system); } return(system); }
/// <summary>Get a human readable display string for debugging system references from a GUID</summary> /// <param name="systemGuid"></param> /// <returns>Non-null or empty string, no matter the input</returns> public static string GetSystemDebugDisplayString(Values.KGuid systemGuid) { Contract.Ensures(Contract.Result <string>().IsNotNullOrEmpty()); EngineSystemAttribute system_attribute = null; if (systemGuid.IsNotEmpty) { system_attribute = TryGetRegisteredSystem(systemGuid); } string display_string = string.Format("{{{0}}}={1}", systemGuid.ToString(Values.KGuid.kFormatHyphenated), system_attribute != null ? system_attribute.EngineSystemType.ToString() : "UNDEFINED_SYSTEM"); return(display_string); }
internal static void DisposeFromOldProgram() { EngineSystemAttribute.DisposeFromOldAssembly(System.Reflection.Assembly.GetCallingAssembly()); mIsInitializedForNewProgram = false; }