Beispiel #1
0
        public static AttrLinkAtom Get(Atom baseAtom, string metaKey, bool underLink)
        {
            var atom = ObjPool <AttrLinkAtom> .Get();

            atom.BaseAtom  = baseAtom;
            atom.MetaKey   = metaKey;
            atom.UnderLink = underLink;
            return(atom);
        }
Beispiel #2
0
        public static AttrSizeAtom Get(Atom baseAtom, string sizeStr)
        {
            var atom = ObjPool <AttrSizeAtom> .Get();

            atom.BaseAtom = baseAtom;
            atom.Type     = baseAtom.Type;
            ParseSize(sizeStr, out atom.Size, out atom.Offset);
            return(atom);
        }
 public override void Flush()
 {
     if (BaseAtom != null)
     {
         BaseAtom.Flush();
         BaseAtom = null;
     }
     ObjPool <VerticalCenteredAtom> .Release(this);
 }
Beispiel #4
0
        public static AttrShiftAtom Get(Atom Base, string Offset)
        {
            float s;
            var   atom = ObjPool <AttrShiftAtom> .Get();

            atom.baseAtom = Base;
            atom.offset   = float.TryParse(Offset, out s) ? s : 0;
            return(atom);
        }
Beispiel #5
0
 public override void Flush()
 {
     if (BaseAtom != null)
     {
         BaseAtom.Flush();
         BaseAtom = null;
     }
     ObjPool <NegateAtom> .Release(this);
 }
Beispiel #6
0
        public static SpaceAtom Get(float Width, float Height, float Depth)
        {
            var atom = ObjPool <SpaceAtom> .Get();

            atom.width  = Width;
            atom.height = Height;
            atom.depth  = Depth;
            atom.policy = StrutPolicy.Misc;
            return(atom);
        }
Beispiel #7
0
 public override void Flush()
 {
     base.Flush();
     if (baseAtom != null)
     {
         baseAtom.Flush();
         baseAtom = null;
     }
     ObjPool <AttrShiftAtom> .Release(this);
 }
Beispiel #8
0
        public void Awake()
        {
            _tipPool = ETModel.Game.Scene.GetComponent <SimpleObjectPoolComponent>().GreateObjectPool(UIType.UITip, UIType.CommonUI, UIType.UITip, 10);

            repeatTipQueue = new Queue <GameObject>();

            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();

            resourcesComponent.LoadBundle(UIType.CommonUI.StringToAB());
        }
    public void Init()
    {
        foreach (ParticleType type in System.Enum.GetValues(typeof(ParticleType))) {
            particlesPool[type] = new ObjPool<BaseParticleSys>();
        }

        particlePrefabDict[ParticleType.EXPLOSION] = explosionParticles;
        particlePrefabDict[ParticleType.DEBRIS] = debrisParticles;
        particlePrefabDict[ParticleType.CRASH] = crashParticles;
    }
 private SocketMgr()
 {
     m_Handlers     = new Dictionary <short, MessageEventHandler>(512);
     m_Socket       = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     m_RecvBuffer   = new byte[ByteArray.MSG_MAX_LEN];
     m_RecvLength   = 0;
     m_BytesPool    = new ObjPool <ByteArray>(32);
     m_MessageQueue = new LockedQueue <ByteArray>(32);
     m_SendBuffer   = new ByteArray(128);
 }
    public void Init()
    {
        foreach (ParticleType type in System.Enum.GetValues(typeof(ParticleType)))
        {
            particlesPool[type] = new ObjPool <BaseParticleSys>();
        }

        particlePrefabDict[ParticleType.EXPLOSION] = explosionParticles;
        particlePrefabDict[ParticleType.DEBRIS]    = debrisParticles;
        particlePrefabDict[ParticleType.CRASH]     = crashParticles;
    }
    ////Generic Methods/////

    public GameObject RequestObject(GameObject originalPrefab, Vector3 position, Quaternion rotation)
    {
        if (!pools.ContainsKey(originalPrefab))
        {
            ObjPool newPool = new ObjPool(originalPrefab);
            pools.Add(originalPrefab, newPool);
        }
        ObjPool pool = pools[originalPrefab];

        return(pool.GetObjFromPool(position, rotation));
    }
    public void StoreObj(GameObject originalPrefab, GameObject obj)
    {
        if (!pools.ContainsKey(originalPrefab))
        {
            ObjPool newPool = new ObjPool(originalPrefab);
            pools.Add(originalPrefab, newPool);
        }
        ObjPool pool = pools[originalPrefab];

        pool.ReturnObjToPool(obj);
    }
Beispiel #14
0
    public void Awake()
    {
        if (_myInstance == null)
        {
            _myInstance = this;
        }
        else if (_myInstance != this)
        {
        }

        InitPool(poolSize);
    }
Beispiel #15
0
    public ObjPool(MonoBehaviour _owner, int size)
    {
        this.size = size;
        if (Me != null)
        {
            Me = this;
        }

        for (int i = 0; i < size; i++)
        {
            //objects.Add();
        }
    }
Beispiel #16
0
        public static FractionAtom Get(Atom Numerator, Atom Denominator, float LineThickness,
                                       TexAlignment NumeratorAlignment, TexAlignment DenominatorAlignment)
        {
            var atom = ObjPool <FractionAtom> .Get();

            atom.Type                 = CharTypeInternal.Inner;
            atom.numerator            = Numerator;
            atom.denominator          = Denominator;
            atom.numeratorAlignment   = NumeratorAlignment;
            atom.denominatorAlignment = DenominatorAlignment;
            atom.lineThickness        = LineThickness;
            return(atom);
        }
        public static TexCharMetric Get(TexChar Char, float Height, float Depth, float Bearing, float Italic, float Width, float Scale)
        {
            var metric = ObjPool <TexCharMetric> .Get();

            metric.ch           = Char;
            metric.height       = Height * Scale;
            metric.depth        = Depth * Scale;
            metric.bearing      = Bearing * Scale;
            metric.italic       = Italic * Scale;
            metric.width        = Width * Scale;
            metric.appliedScale = Scale;
            return(metric);
        }
Beispiel #18
0
 public override void Flush()
 {
     if (numerator != null)
     {
         numerator.Flush();
         numerator = null;
     }
     if (denominator != null)
     {
         denominator.Flush();
         denominator = null;
     }
     ObjPool <FractionAtom> .Release(this);
 }
Beispiel #19
0
    private void Awake()
    {
        instance = this;
        DontDestroyOnLoad(this);

        ObjPool = GetComponent <ObjectPool>();
        Spawn   = GetComponent <SpawnManager>();
        Map     = GetComponent <MapManager>();
        //Resource = GetComponent<ResourceManager>();

        ObjPool.Init();
        Map.Init();
        StartCoroutine(NpcWaitDoCoroutine());
    }
Beispiel #20
0
        public static AttrSizeAtom Get(Atom baseAtom, string sizeStr)
        {
            var atom = ObjPool <AttrSizeAtom> .Get();

            atom.BaseAtom = baseAtom;
            if (sizeStr != null)
            {
                if (sizeStr.Length == 0)
                {
                    atom.Offset = 0;
                    atom.Size   = float.NaN;
                }
                else if (sizeStr == dotStr)
                {
                    atom.Offset = 0;
                    atom.Size   = TexUtility.SizeFactor(TexStyle.Script);
                }
                else if (sizeStr == dotdotStr)
                {
                    atom.Offset = 0;
                    atom.Size   = TexUtility.SizeFactor(TexStyle.ScriptScript);
                }
                else
                {
                    int pos = sizeStr.IndexOf('-');
                    if (pos < 0)
                    {
                        pos = sizeStr.IndexOf('+');
                    }
                    if (pos < 0 || !float.TryParse(sizeStr.Substring(pos), out atom.Offset))
                    {
                        atom.Offset = 0;
                    }
                    if (pos < 1 || !float.TryParse(sizeStr.Substring(0, pos), out atom.Size))
                    {
                        if (pos == 0 || !float.TryParse(sizeStr, out atom.Size))
                        {
                            atom.Size = 1;
                        }
                    }
                }
            }
            else
            {
                atom.Size   = 1;
                atom.Offset = 0;
            }
            return(atom);
        }
Beispiel #21
0
 /// <summary>
 /// 回收对象到对象池
 /// </summary>
 /// <param name="poolName"></param>
 /// <param name="obj"></param>
 public void RecycleObj(string poolName, GameObject obj)
 {
     obj.SetActive(false);
     if (ObjPool.ContainsKey(poolName))
     {
         ObjPool[poolName].Add(obj);
     }
     else
     {
         ObjPool.Add(poolName, new List <GameObject>()
         {
             obj
         });
     }
 }
Beispiel #22
0
        public static SymbolAtom Get(TexChar ch, char tag)
        {
            if (ch == null)
            {
                return(null);
            }
            var atom = ObjPool <SymbolAtom> .Get();

            atom.Type        = ch.type;
            atom.Name        = ch.symbolName;
            atom.IsDelimiter = (ch.extensionExist || ch.nextLargerExist) && !(ch.extensionHorizontal) &&
                               (ch.type >= CharType.Relation && ch.type <= CharType.CloseDelimiter);
            atom.Character  = ch;
            atom.TaggedChar = tag;
            return(atom);
        }
Beispiel #23
0
    /* Instantiate: If it detects a recycle script on the object requested,
     * it finds the correct object pool for that requested prefab
     * and requests a new game object from the object pool (regardless of status
     * of the status of the object pool).
     * Otherwise it just instantiates like in GameObject.
     */
    public static GameObject Instantiate(GameObject prefab, Vector3 pos)
    {
        GameObject     instance       = null;
        RecycleGameObj recycledScript = prefab.GetComponent <RecycleGameObj> ();

        if (recycledScript != null)
        {
            ObjPool pool = GetObjPool(recycledScript);
            instance = pool.NextObject(pos).gameObject;
        }
        else
        {
            instance = GameObject.Instantiate(prefab);
            instance.transform.position = pos;
        }
        return(instance);
    }
Beispiel #24
0
        /// <summary>
        /// 初始化token池,BaseServer的子类可以重载该方法以填充 BaseToken 的子类
        /// </summary>
        /// <param name="c"></param>
        /// <param name="coding"></param>
        public virtual void Init(AbsHandlerCenter c)
        {
            //Console.WriteLine("绑定消息处理中心");
            Debugger.Log("绑定消息处理中心");
            center = c;

            //Console.WriteLine("初始化token池");
            Debugger.Log("初始化token池");
            tokens = new ObjPool <BaseToken>(maxConn);
            for (int i = 0; i < maxConn; i++)
            {
                T2 t = Activator.CreateInstance <T2>();
                t.Init(c);
                t.CloseDe = ClientClose;
                tokens.Push(t);
            }
        }
Beispiel #25
0
        public static AttrShiftAtom Get(Atom Base, string Offset)
        {
            var atom = ObjPool <AttrShiftAtom> .Get();

            atom.baseAtom = Base;
            float s;

            if (float.TryParse(Offset, out s))
            {
                atom.offset = s;
            }
            else
            {
                atom.offset = 0;
            }
            return(atom);
        }
Beispiel #26
0
    /* GetObjPool: Gets object pool for particular prefab.  Either gets
     * existing object pool or creates a new object pool for that prefab.
     */
    private static ObjPool GetObjPool(RecycleGameObj reference)
    {
        ObjPool pool = null;

        if (pools.ContainsKey(reference))
        {
            pool = pools [reference];
        }
        else
        {
            GameObject poolContainer = new GameObject(reference.gameObject.name + "ObjectPool");
            pool        = poolContainer.AddComponent <ObjPool> ();
            pool.prefab = reference;
            pools.Add(reference, pool);
        }

        return(pool);
    }
    /// Initialize new Task, or get from unused stack
    public static Task Get(IEnumerator c, bool autoStart = true)
    {
        Task t = ObjPool <Task> .Get();

        if (t.task == null)
        {
            t.task = TaskManager.CreateTask(c);
        }
        else
        {
            t.task.coroutine = c;
        }
        t.task.Finished += t.TaskFinished;
        if (autoStart)
        {
            t.Start();
        }
        return(t);
    }
        public override void SendMessage(byte[] buffer, int bufferPosition, int bufferLength)
        {
            int sendBufferSize = 0;

            for (ushort seq = oldestUnacked; PacketIO.SequenceLessThan(seq, this.sequence); seq++)
            {
                if (sendBuffer.Exists(seq))
                {
                    sendBufferSize++;
                }
            }

            if (sendBufferSize == sendBuffer.Size)
            {
                ByteBuffer tempBuff = ObjPool <ByteBuffer> .Get();

                tempBuff.SetSize(bufferLength);
                tempBuff.BufferCopy(buffer, bufferPosition, 0, bufferLength);
                messageQueue.Enqueue(tempBuff);

                return;
            }

            ushort sequence = this.sequence++;
            var    packet   = sendBuffer.Insert(sequence);

            packet.time = -1.0;

            // ensure size for header
            int varLength = getVariableLengthBytes((ushort)bufferLength);

            packet.buffer.SetSize(2 + varLength + bufferLength);

            using (var writer = ByteArrayReaderWriter.Get(packet.buffer.InternalBuffer)) {
                writer.Write(sequence);

                writeVariableLengthUShort((ushort)bufferLength, writer);
                writer.WriteBuffer(buffer, bufferPosition, bufferLength);
            }

            // signal that packet is ready to be sent
            packet.writeLock = false;
        }
Beispiel #29
0
 /// <summary>
 /// 回收对象到对象池
 /// </summary>
 /// <param name="objName"></param>
 public void RecycleObj(GameObject obj, Transform parent = null)
 {
     //TODO  统一
     if (parent == null)
     {
         parent = transform;
     }
     obj.SetActive(false);
     obj.transform.SetParent(parent);
     if (ObjPool.ContainsKey(obj.name))
     {
         ObjPool[obj.name].Add(obj);
     }
     else
     {
         ObjPool.Add(obj.name, new List <GameObject>()
         {
             obj
         });
     }
 }
Beispiel #30
0
        public static SpaceAtom Get(bool isGlue, float Width, float Height, float Depth)
        {
            var atom = ObjPool <SpaceAtom> .Get();

            if (isGlue)
            {
                float factor = TexUtility.glueRatio;
                atom.width  = Width * factor;
                atom.height = Height * factor;
                atom.depth  = Depth * factor;
                atom.policy = StrutPolicy.Glue;
            }
            else
            {
                atom.width  = Width;
                atom.height = Height;
                atom.depth  = Depth;
                atom.policy = StrutPolicy.Misc;
            }
            return(atom);
        }
Beispiel #31
0
    /// <summary>
    /// 获取名为 name 的预制体的克隆体中未使用的对象并返回。
    /// </summary>
    /// <param name="name">预制体的名字</param>
    public GameObject GetUnUesdObj(string name)
    {
        GameObject go = null;

        for (int i = 0; i < objList.Count; i++) //遍历克隆体列表
        {
            if (objList[i].activeSelf == false) //如果找到未使用的克隆体
            {
                objList[i].SetActive(true);
                go = objList[i];
                break;
            }
        }
        if (go == null)//如果不存在未使用的克隆体
        {
            go = GameObject.Instantiate(PoolManager.GetPrefab(name));
            ObjPool objPool = PoolManager.GetObjPool(name);
            objPool.objList.Add(go);
        }
        return(go);
    }