private EntityInfo NewEntityInfo(int id) { EntityInfo entity = null; if (m_UnusedEntities.Count > 0) { entity = m_UnusedEntities.Dequeue(); entity.Reset(); entity.InitId(id); } else { entity = new EntityInfo(id); } return(entity); }
private void RecycleEntityInfo(EntityInfo npcInfo) { if (null != npcInfo) { int id = npcInfo.GetId(); if (id >= c_StartId && id < c_StartId + c_MaxIdNum) { m_UnusedIds.Push(id); } if (id >= c_StartId_Client && id < c_StartId_Client + c_MaxIdNum) { m_UnusedClientIds.Push(id); } if (m_UnusedEntities.Count < m_EntityPoolSize) { npcInfo.Reset(); m_UnusedEntities.Enqueue(npcInfo); } } }