private void LoadComponent(MySessionComponentBase component) { if (component.Loaded) { return; } foreach (var dependency in component.Dependencies) { MySessionComponentBase comp; m_sessionComponents.TryGetValue(dependency, out comp); if (comp == null) { continue; } LoadComponent(comp); } if (!m_loadOrder.Contains(component)) { m_loadOrder.Add(component); } else { var message = string.Format("Circular dependency: {0}", component.DebugName); MySandboxGame.Log.WriteLine(message); throw new Exception(message); } ProfilerShort.Begin(component.DebugName); component.LoadData(); component.AfterLoadData(); ProfilerShort.End(); }
public void RegisterSession(MySession session) { if (plugin != null) { try { Type descType = typeof(MySessionComponentDescriptor); int count = 0; foreach (Type t in mainAssembly.GetTypes().Where(t => Attribute.IsDefined(t, descType))) { MySessionComponentBase comp = (MySessionComponentBase)Activator.CreateInstance(t); session.RegisterComponent(comp, comp.UpdateOrder, comp.Priority); count++; } if (count > 0) { LogFile.WriteLine($"Registered {count} session components from: {mainAssembly.FullName}"); } } catch (Exception e) { ThrowError($"Failed to register {data} because of an error: {e}"); } } }
public void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority) { // TODO: Better handling of component overrides //if(m_sessionComponents.ContainsKey(component.ComponentType)) m_sessionComponents[component.ComponentType] = component; component.Session = this; AddComponentForUpdate(updateOrder, component); }
internal static FatProfilerEntry SessionComponentEntry(MySessionComponentBase component) { if (!ProfileSessionComponentsUpdate || component == null) { return(null); } return(FixedProfiler(ProfilerFixedEntry.Session)?.GetFat(component)); }
public void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority) { m_sessionComponents.Add(component.ComponentType, component); AddComponentForUpdate(updateOrder, MyUpdateOrder.BeforeSimulation, component); AddComponentForUpdate(updateOrder, MyUpdateOrder.Simulation, component); AddComponentForUpdate(updateOrder, MyUpdateOrder.AfterSimulation, component); AddComponentForUpdate(updateOrder, MyUpdateOrder.NoUpdate, component); }
public void RemoveComponentFromUpdate(MySessionComponentBase component) { for (int i = 0; i <= 2; ++i) { SortedSet <MySessionComponentBase> componentList = null; if (m_sessionComponentsForUpdate.TryGetValue((int)i, out componentList)) { componentList.Remove(component); } } }
public void AddComponentForUpdate(MyUpdateOrder updateOrder, MySessionComponentBase component) { for (int i = 0; i <= 2; ++i) { if (((int)updateOrder & (1 << i)) == 0) { continue; } SortedSet <MySessionComponentBase> componentList = null; if (!m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList)) { m_sessionComponentsForUpdate.Add(1 << i, componentList = new SortedSet <MySessionComponentBase>(SessionComparer)); } componentList.Add(component); } }
private static void Load() { foreach (MyObjectBuilder_Checkpoint.ModItem mod in MyAPIGateway.Session.Mods) { if (mod.PublishedFileId == 1286147283uL || mod.Name == "ARMS") { Logger.DebugLog("ARMS mod: FriendlyName: " + mod.FriendlyName + ", Name: " + mod.Name + ", Published ID: " + mod.PublishedFileId); MySessionComponentBase component = Mods.FindModSessionComponent(mod.Name, "SteamShipped", "SteamShipped.Notify"); if (component == null) { Logger.AlwaysLog($"Failed to find Session Component.", Logger.severity.ERROR); return; } component.GetType().GetField("HasNotified").SetValue(component, true); return; } } Logger.AlwaysLog("Failed to find mod", Logger.severity.ERROR); return; }
public void SetComponentUpdateOrder(MySessionComponentBase component, MyUpdateOrder order) { for (int i = 0; i <= 2; ++i) { SortedSet <MySessionComponentBase> componentList = null; if ((order & (MyUpdateOrder)(1 << i)) != 0) { if (!m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList)) { componentList = new SortedSet <MySessionComponentBase>(); m_sessionComponentsForUpdate.Add(i, componentList); } componentList.Add(component); } else { if (m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList)) { componentList.Remove(component); } } } }
private static void SessionComponentEntry(MySessionComponentBase component, ref MultiProfilerEntry mpe) { if (_activeProfilers == 0) { return; } if (_modMask != null && component.ModContext != _modMask) { return; } if (_activeProfilersByType[(int)ProfilerRequestType.Mod] > 0) { var modContext = ModLookupUtils.GetMod(component) ?? MyModContext.BaseGame; mpe.Add(PerfMod.GetOrAdd(modContext, DelMakeMod)); } if (_activeProfilersByType[(int)ProfilerRequestType.Session] > 0) { mpe.Add(PerfSessionComponent.GetOrAdd(component.GetType(), DelMakeSessionComponent)); } }
void IMySession.RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority) { RegisterComponent(component, updateOrder, priority); }
private void SaveComponent(MySessionComponentBase component) { component.SaveData(); }
public void UnregisterComponent(MySessionComponentBase component) { component.Session = null; m_sessionComponents.Remove(component.ComponentType); }
static ProfilerToken?CreateTokenInUpdateReplicationCategory(MySessionComponentBase obj, int methodIndex) { //Log.Trace($"replication layer: {obj?.GetType()}"); return(ProfilerPatch.StartToken(obj, methodIndex, ProfilerCategory.UpdateReplication)); }
private void AddComponentForUpdate(MyUpdateOrder updateOrder, MyUpdateOrder insertIfOrder, MySessionComponentBase component) { if ((updateOrder & insertIfOrder) != insertIfOrder) { return; } SortedSet <MySessionComponentBase> componentList = null; if (!m_sessionComponentsForUpdate.TryGetValue((int)insertIfOrder, out componentList)) { m_sessionComponentsForUpdate.Add((int)insertIfOrder, componentList = new SortedSet <MySessionComponentBase>(SessionComparer)); } componentList.Add(component); }
private static SlimProfilerEntry SingleMethodEntryProvider_SessionComponent(MySessionComponentBase __instance, string __key) { return(ProfilerData.SessionComponentEntry(__instance)?.GetSlim(__key)); }