コード例 #1
0
 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;
 }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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));
        }
コード例 #7
0
ファイル: InstanceLogger.cs プロジェクト: schlndh/netool
 /// <inheritdoc cref="FileLog.WriteInstanceData"/>
 public void WriteInstanceData(IInstance instance)
 {
     Debug.WriteLine("InstanceLogger - writing instance data (type: {0})", instance.GetType());
     log.WriteInstanceData(instance);
 }
コード例 #8
0
 /// <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;
     }
 }
コード例 #9
0
 /// <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);
     }
 }