Пример #1
0
    static public LogicEvent CreateEvent()
    {
        LogicEvent le = msEventPool.Alloc();

        if (le != null)
        {
            return(le);
        }

        return(new LogicEvent());
    }
Пример #2
0
        /// <summary>
        /// 分配实体
        /// </summary>
        /// <param name="assetName"></param>
        public EntityBase AllocEntity(EntityType entityType, string assetName = "")
        {
            EntityBase entity = null;

            if (!string.IsNullOrEmpty(assetName))
            {
                MemoryPool <EntityBase> memoryPool = null;
                if (this.m_entityPool.TryGetValue(assetName, out memoryPool))
                {
                    entity = memoryPool.Alloc();
                    if (entity == null)
                    {
                        entity = CreateEntity(entityType, assetName);
                    }
                    else
                    {
                        entity.IsFromPool = true;
                    }
                }
                else
                {
                    memoryPool = new MemoryPool <EntityBase>(ENTITY_POOL_SIZE);
                    this.m_entityPool.Add(assetName, memoryPool);
                    entity = CreateEntity(entityType, assetName);
                }
            }
            else
            {
                entity = CreateEntity(entityType, assetName);
            }

            AddEntity(entity);

            entity.EntityMemoryStatus = EntityMemoryStatus.IN_USING;

            return(entity);
        }