public static void RegisterInstance <T>(IInstance instance) { if (instance.GetType() != typeof(T) && !instance.GetType().IsSubclassOf(typeof(T))) { DebugLog.LogErrorColor("Type mismatch in registering instance of type " + typeof(T).Name, LogColor.red); return; } _instances[typeof(T)] = instance; }
/// <summary> /// Creates a lookup for the instance and assigns an InstanceId. /// </summary> public void AssignInstance(IInstance instance) { uint instanceId; bool success; if (instance is Character character) { success = _characterPool.TryAssign((uint)character.id, out instanceId); } else if (instance is DeadBody deadBody) { success = _deadBodyPool.TryAssign((uint)deadBody.id, out instanceId); } else if (instance is NpcSpawn npc) { success = _npcPool.TryAssign((uint)npc.id, out instanceId); } else if (instance is MonsterSpawn monster) { success = _monsterPool.TryAssign((uint)monster.id, out instanceId); } else if (_dynamicPool.TryPop(out instanceId)) { success = true; } else { instanceId = INVALID_INSTANCE_ID; success = false; } if (instanceId == INVALID_INSTANCE_ID) { _Logger.Error($"Failed to retrieve instanceId for type {instance.GetType()}"); return; } if (!success) { if (_instances.ContainsKey(instanceId)) { // object already exists in lookup. instance.instanceId = instanceId; return; } _Logger.Error($"Failed to assign instanceId for type {instance.GetType()}"); return; } instance.instanceId = instanceId; _instances.Add(instanceId, instance); }
/// <summary> /// Регистрирует объект-сервер. /// </summary> public static void RegisterServer(string portName, string objectUri, IInstance instance) { var channel = new IpcChannel(portName); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType( instance.GetType(), objectUri, WellKnownObjectMode.Singleton); }
public void ExcludeInstance(IInstance instance) { if (instance == null) { Debug.LogError("Can't exclude instance! Instance is null!"); return; } Type type = instance.GetType(); if (Main.Singleton.m_Instances.ContainsKey(type)) { Main.Singleton.m_Instances.Remove(type); } }
public void RegisterInstance(IInstance instance) { if (instance == null) { Debug.LogError("Can't register instance! Instance is null!"); return; } Type type = instance.GetType(); if (!m_Instances.ContainsKey(type)) { m_Instances.Add(type, instance); } }
public bool RemoveComponent(IInstance instance) { Type type = instance.GetType(); if (RemoveFuncDict.TryGetValue(type, out var removeFunc) == false) { throw new InvalidOperationException($"Trying to add an instance of an unregistered type: {type}!"); } if (ComponentsDict.TryGetValue(type, out var list) == false) { throw new InvalidOperationException($"Trying to add an instance of an unregistered type: {type}!"); } // Because the compiler doesn't do proper null checking here we // use ! to say that the parameter definetly isn't null here. return(removeFunc !(list !, instance)); }
/// <inheritdoc cref="FileLog.WriteInstanceData"/> public void WriteInstanceData(IInstance instance) { Debug.WriteLine("InstanceLogger - writing instance data (type: {0})", instance.GetType()); log.WriteInstanceData(instance); }
/// <summary> /// Write instance data, usually upon closing the instance. Note: don't call this method repeatedly, because there is no way to delete the old data! /// </summary> /// <param name="instance"></param> public void WriteInstanceData(IInstance instance) { lock (streamLock) { var initialPos = stream.Position; Debug.WriteLine("FileLog ({0}) writing instance data (type: {1})", filename, instance.GetType()); stream.Position = 0; stream.Position = binReader.ReadInt64() + sizeof(long); // write the pointer to serialized instance data binWriter.Write(stream.Length); stream.Position = stream.Length; formatter.Serialize(stream, instance); stream.Flush(); stream.Position = initialPos; } }
/// <inheritdoc/> public void Stop() { if (Active) { Debug.WriteLine("DefaultInstanceController - stopping instance(type: {0})", instance.GetType(), 1); instance.Stop(); Debug.WriteLine("DefaultInstanceController - instance(type: {0}) stopped", instance.GetType(), 1); } }