Beispiel #1
0
        public Optional <AbsoluteEntityCell> UpdateEntityPosition(NitroxId id, NitroxVector3 position, NitroxQuaternion rotation)
        {
            Optional <Entity> opEntity = GetEntityById(id);

            if (!opEntity.HasValue)
            {
                Log.Debug("Could not update entity position because it was not found (maybe it was recently picked up)");
                return(Optional.Empty);
            }

            Entity             entity  = opEntity.Value;
            AbsoluteEntityCell oldCell = entity.AbsoluteEntityCell;

            entity.Transform.Position = position;
            entity.Transform.Rotation = rotation;

            AbsoluteEntityCell newCell = entity.AbsoluteEntityCell;

            if (oldCell != newCell)
            {
                EntitySwitchedCells(entity, oldCell, newCell);
            }

            return(Optional.Of(newCell));
        }
        public override List <EntitySpawnPoint> From(AbsoluteEntityCell absoluteEntityCell, Transform transform, GameObject gameObject)
        {
            List <EntitySpawnPoint> spawnPoints            = new List <EntitySpawnPoint>();
            EntitySlotsPlaceholder  entitySlotsPlaceholder = gameObject.GetComponent <EntitySlotsPlaceholder>();

            if (!ReferenceEquals(entitySlotsPlaceholder, null))
            {
                foreach (EntitySlotData entitySlotData in entitySlotsPlaceholder.slotsData)
                {
                    List <EntitySlot.Type> slotTypes       = SlotsHelper.GetEntitySlotTypes(entitySlotData);
                    List <string>          stringSlotTypes = slotTypes.Select(s => s.ToString()).ToList();

                    spawnPoints.Add(
                        new EntitySpawnPoint(absoluteEntityCell,
                                             entitySlotData.localPosition,
                                             entitySlotData.localRotation,
                                             stringSlotTypes,
                                             entitySlotData.density,
                                             entitySlotData.biomeType.ToString())
                        );
                }
            }
            else
            {
                spawnPoints.Add(
                    new EntitySpawnPoint(absoluteEntityCell, transform.Position, transform.Rotation, transform.Scale, gameObject.ClassId)
                    );
            }

            return(spawnPoints);
        }
Beispiel #3
0
 public bool HasCellLoaded(AbsoluteEntityCell cell)
 {
     lock (visibleCells)
     {
         return(visibleCells.Contains(cell));
     }
 }
Beispiel #4
0
        public Optional <AbsoluteEntityCell> UpdateEntityPosition(NitroxId id, Vector3 position, Quaternion rotation)
        {
            Optional <Entity> opEntity = entityData.GetEntityById(id);

            if (opEntity.IsPresent())
            {
                Entity             entity  = opEntity.Get();
                AbsoluteEntityCell oldCell = entity.AbsoluteEntityCell;

                entity.Position = position;
                entity.Rotation = rotation;

                AbsoluteEntityCell newCell = entity.AbsoluteEntityCell;

                if (oldCell != newCell)
                {
                    entityData.EntitySwitchedCells(entity, oldCell, newCell);
                }

                return(Optional <AbsoluteEntityCell> .Of(newCell));
            }
            else
            {
                Log.Info("Could not update entity position because it was not found (maybe it was recently picked up)");
            }

            return(Optional <AbsoluteEntityCell> .Empty());
        }
Beispiel #5
0
        private void ParseGameObjectsFromStream(Stream stream, Int3 batchId, Int3 cellId, int level, List <EntitySpawnPoint> spawnPoints)
        {
            ProtobufSerializer.LoopHeader gameObjectCount = serializer.Deserialize <ProtobufSerializer.LoopHeader>(stream);

            for (int goCounter = 0; goCounter < gameObjectCount.Count; goCounter++)
            {
                GameObject gameObject = DeserializeGameObject(stream);

                if (gameObject.TotalComponents > 0)
                {
                    AbsoluteEntityCell absoluteEntityCell = new AbsoluteEntityCell(batchId, cellId, level);

                    Transform transform = gameObject.GetComponent <Transform>();
                    EntitySlotsPlaceholder entitySlotsPlaceholder = gameObject.GetComponent <EntitySlotsPlaceholder>();
                    EntitySlot             entitySlot             = gameObject.GetComponent <EntitySlot>();

                    if (!ReferenceEquals(entitySlotsPlaceholder, null))
                    {
                        spawnPoints.AddRange(EntitySpawnPoint.From(absoluteEntityCell, entitySlotsPlaceholder));
                    }
                    else if (!ReferenceEquals(entitySlot, null))
                    {
                        spawnPoints.Add(EntitySpawnPoint.From(absoluteEntityCell, transform.Position, transform.Rotation, transform.Scale, gameObject.ClassId, entitySlot));
                    }
                    else
                    {
                        spawnPoints.Add(EntitySpawnPoint.From(absoluteEntityCell, transform.Position, transform.Rotation, transform.Scale, gameObject.ClassId));
                    }
                }
            }
        }
        public Entity UpdateEntityPosition(string guid, Vector3 position, Quaternion rotation)
        {
            Entity             entity  = GetEntityByGuid(guid);
            AbsoluteEntityCell oldCell = new AbsoluteEntityCell(entity.Position);
            AbsoluteEntityCell newCell = new AbsoluteEntityCell(position);

            if (oldCell != newCell)
            {
                lock (entitiesByAbsoluteCell)
                {
                    List <Entity> oldList;

                    if (entitiesByAbsoluteCell.TryGetValue(oldCell, out oldList))
                    {
                        oldList.Remove(entity);
                    }

                    List <Entity> newList;

                    if (!entitiesByAbsoluteCell.TryGetValue(newCell, out newList))
                    {
                        newList = new List <Entity>();
                        entitiesByAbsoluteCell[newCell] = newList;
                    }

                    newList.Add(entity);
                }
            }

            entity.Position = position;
            entity.Rotation = rotation;

            return(entity);
        }
Beispiel #7
0
 public void Add(AbsoluteEntityCell cell)
 {
     lock (cells)
     {
         cells.Add(cell);
     }
 }
Beispiel #8
0
 public bool Contains(AbsoluteEntityCell cell)
 {
     lock (cells)
     {
         return(cells.Contains(cell));
     }
 }
Beispiel #9
0
 public void Remove(AbsoluteEntityCell cell)
 {
     lock (cells)
     {
         cells.Remove(cell);
     }
 }
Beispiel #10
0
        public Entity UpdateEntityPosition(string guid, Vector3 position, Quaternion rotation)
        {
            Entity             entity  = GetEntityByGuid(guid);
            AbsoluteEntityCell oldCell = entity.AbsoluteEntityCell;
            AbsoluteEntityCell newCell = new AbsoluteEntityCell(position, entity.Level);

            if (oldCell != newCell)
            {
                List <Entity> oldList;

                lock (entitiesByAbsoluteCell)
                {
                    if (GetEntities(oldCell, out oldList))
                    {
                        // Validate.IsTrue?
                        oldList.Remove(entity);
                    }

                    List <Entity> newList = GetEntities(newCell);
                    newList.Add(entity);
                }
            }

            entity.Position = position;
            entity.Rotation = rotation;

            return(entity);
        }
Beispiel #11
0
 public EntitySpawnPoint(AbsoluteEntityCell absoluteEntityCell, Vector3 localPosition, Quaternion localRotation, Vector3 scale, string classId)
 {
     AbsoluteEntityCell = absoluteEntityCell;
     ClassId            = classId;
     Density            = 1;
     Position           = AbsoluteEntityCell.Center + localPosition;
     Scale    = scale;
     Rotation = localRotation;
 }
        public void TestInitialize()
        {
            packetReceiver = new PacketReceiver();

            loadedCell   = new AbsoluteEntityCell(loadedActionPosition, CELL_LEVEL);
            unloadedCell = new AbsoluteEntityCell(unloadedActionPosition, CELL_LEVEL);

            visibleCells.Add(loadedCell);
        }
Beispiel #13
0
 public EntitySpawnPoint(AbsoluteEntityCell absoluteEntityCell, Vector3 localPosition, Quaternion localRotation, List <string> allowedTypes, float density, string biomeType)
 {
     AbsoluteEntityCell = absoluteEntityCell;
     Position           = AbsoluteEntityCell.Center + localPosition;
     Rotation           = localRotation;
     BiomeType          = biomeType;
     Density            = density;
     AllowedTypes       = allowedTypes;
 }
Beispiel #14
0
 public EntitySpawnPoint(AbsoluteEntityCell absoluteEntityCell, NitroxVector3 localPosition, NitroxQuaternion localRotation, NitroxVector3 scale, string classId)
 {
     AbsoluteEntityCell = absoluteEntityCell;
     ClassId            = classId;
     Density            = 1;
     LocalPosition      = localPosition;
     Scale         = scale;
     LocalRotation = localRotation;
 }
Beispiel #15
0
        public void TestInitialize()
        {
            packetReceiver = new PacketReceiver();
            NitroxModel.Helper.Map.Main = new NitroxModel_Subnautica.Helper.SubnauticaMap();

            loadedCell   = new AbsoluteEntityCell(loadedActionPosition, CELL_LEVEL);
            unloadedCell = new AbsoluteEntityCell(unloadedActionPosition, CELL_LEVEL);

            visibleCells.Add(loadedCell);
        }
        public static EntitySpawnPoint From(AbsoluteEntityCell absoluteEntityCell, Vector3 localPosition, Quaternion localRotation, Vector3 scale, string classId, IEntitySlot entitySlot)
        {
            EntitySpawnPoint spawnPoint = From(absoluteEntityCell, localPosition, localRotation, scale, classId);

            spawnPoint.BiomeType        = entitySlot.GetBiomeType();
            spawnPoint.Density          = entitySlot.GetDensity();
            spawnPoint.CanSpawnCreature = entitySlot.IsCreatureSlot();
            spawnPoint.AllowedTypes     = SlotsHelper.GetEntitySlotTypes(entitySlot);

            return(spawnPoint);
        }
Beispiel #17
0
        public void CellUnloaded(Int3 batchId, Int3 cellId, int level)
        {
            AbsoluteEntityCell cell = new AbsoluteEntityCell(batchId.Model(), cellId.Model(), level);

            if (visibleCells.Contains(cell))
            {
                visibleCells.Remove(cell);
                removed.Add(cell);
                MarkCellsReadyForSync(0);
            }
        }
Beispiel #18
0
        public void EntitySwitchedCells(Entity entity, AbsoluteEntityCell oldCell, AbsoluteEntityCell newCell)
        {
            lock (entitiesByAbsoluteCell)
            {
                List <Entity> oldList = EntitiesFromCell(oldCell);
                oldList.Remove(entity);

                List <Entity> newList = EntitiesFromCell(newCell);
                newList.Add(entity);
            }
        }
        private void AddPacketToDeferredMap(PlayerActionPacket playerAction, AbsoluteEntityCell cell)
        {
            lock (deferredPacketsByAbsoluteCell)
            {
                if (!deferredPacketsByAbsoluteCell.ContainsKey(cell))
                {
                    deferredPacketsByAbsoluteCell.Add(cell, new Queue <Packet>());
                }

                deferredPacketsByAbsoluteCell[cell].Enqueue(playerAction);
            }
        }
        public void TestInitialize()
        {
            NitroxServiceLocator.InitializeDependencyContainer(new ClientAutoFacRegistrar(), new TestAutoFacRegistrar());
            NitroxServiceLocator.BeginNewLifetimeScope();

            packetReceiver = NitroxServiceLocator.LocateService <PacketReceiver>();

            loadedCell   = new AbsoluteEntityCell(loadedActionPosition, CELL_LEVEL);
            unloadedCell = new AbsoluteEntityCell(unloadedActionPosition, CELL_LEVEL);

            visibleCells.Add(loadedCell);
        }
Beispiel #21
0
        private IEnumerator WaitAndAddCell(Int3 batchId, Int3 cellId, int level)
        {
            yield return(new WaitForSeconds(0.5f));

            AbsoluteEntityCell cell = new AbsoluteEntityCell(batchId.Model(), cellId.Model(), level);

            if (!visibleCells.Contains(cell))
            {
                visibleCells.Add(cell);
                added.Add(cell);
            }
        }
        public void TestInitialize()
        {
            packetReceiver = new DeferringPacketReceiver(visibleCells);

            Int3 loadedBatchId   = LargeWorldStreamer.main.GetContainingBatch(loadedActionPosition);
            Int3 unloadedBatchId = LargeWorldStreamer.main.GetContainingBatch(unloadedActionPosition);

            loadedCell   = new AbsoluteEntityCell(loadedBatchId, cellId, CELL_LEVEL);
            unloadedCell = new AbsoluteEntityCell(unloadedBatchId, cellId, CELL_LEVEL);

            visibleCells.Add(loadedCell);
        }
Beispiel #23
0
        private void AddPacketToDeferredMap(DeferrablePacket deferrablePacket, AbsoluteEntityCell cell)
        {
            lock (deferredPacketsByAbsoluteCell)
            {
                if (!deferredPacketsByAbsoluteCell.ContainsKey(cell))
                {
                    deferredPacketsByAbsoluteCell.Add(cell, new Queue <Packet>());
                }

                deferredPacketsByAbsoluteCell[cell].Enqueue(deferrablePacket);
            }
        }
        private void AddPacketToDeferredMap(DeferrablePacket deferrablePacket, AbsoluteEntityCell cell)
        {
            lock (deferredPacketsByAbsoluteCell)
            {
                Queue <Packet> queue;
                if (!deferredPacketsByAbsoluteCell.TryGetValue(cell, out queue))
                {
                    deferredPacketsByAbsoluteCell[cell] = queue = new Queue <Packet>();
                }

                queue.Enqueue(deferrablePacket);
            }
        }
Beispiel #25
0
        public List <Entity> GetEntities(AbsoluteEntityCell absoluteEntityCell)
        {
            List <Entity> result;

            lock (phasingEntitiesByAbsoluteCell)
            {
                if (!phasingEntitiesByAbsoluteCell.TryGetValue(absoluteEntityCell, out result))
                {
                    result = phasingEntitiesByAbsoluteCell[absoluteEntityCell] = new List <Entity>();
                }
            }

            return(result);
        }
Beispiel #26
0
        private List <Entity> EntitiesFromCell(AbsoluteEntityCell absoluteEntityCell)
        {
            List <Entity> result;

            lock (entitiesByAbsoluteCell)
            {
                if (!entitiesByAbsoluteCell.TryGetValue(absoluteEntityCell, out result))
                {
                    result = entitiesByAbsoluteCell[absoluteEntityCell] = new List <Entity>();
                }
            }

            return(result);
        }
        public static EntitySpawnPoint From(AbsoluteEntityCell absoluteEntityCell, Vector3 localPosition, Quaternion localRotation, Vector3 scale, string classId)
        {
            EntitySpawnPoint esp = new EntitySpawnPoint
            {
                AbsoluteEntityCell = absoluteEntityCell,
                ClassId            = classId,
                Density            = 1
            };

            esp.Position = esp.AbsoluteEntityCell.Center + localPosition;
            esp.Scale    = scale;
            esp.Rotation = localRotation;

            return(esp);
        }
Beispiel #28
0
        private void ParseGameObjectsFromStream(Stream stream, NitroxInt3 batchId, NitroxInt3 cellId, int level, List <EntitySpawnPoint> spawnPoints)
        {
            LoopHeader gameObjectCount = serializer.Deserialize <LoopHeader>(stream);

            for (int goCounter = 0; goCounter < gameObjectCount.Count; goCounter++)
            {
                GameObject gameObject = DeserializeGameObject(stream);

                if (gameObject.TotalComponents > 0)
                {
                    AbsoluteEntityCell absoluteEntityCell = new AbsoluteEntityCell(batchId, cellId, level);
                    NitroxTransform    transform          = gameObject.GetComponent <NitroxTransform>();
                    spawnPoints.AddRange(entitySpawnPointFactory.From(absoluteEntityCell, transform, gameObject));
                }
            }
        }
Beispiel #29
0
        private void EntitySwitchedCells(Entity entity, AbsoluteEntityCell oldCell, AbsoluteEntityCell newCell)
        {
            if (entity.ExistsInGlobalRoot)
            {
                return; // We don't care what cell a global root entity resides in.  Only phasing entities.
            }

            lock (phasingEntitiesByAbsoluteCell)
            {
                List <Entity> oldList = GetEntities(oldCell);
                oldList.Remove(entity);

                List <Entity> newList = GetEntities(newCell);
                newList.Add(entity);
            }
        }
Beispiel #30
0
        private List <Entity> ListForCell(AbsoluteEntityCell absoluteEntityCell)
        {
            PrepareBatch(absoluteEntityCell.BatchId);

            List <Entity> result;

            lock (entitiesByAbsoluteCell)
            {
                if (!entitiesByAbsoluteCell.TryGetValue(absoluteEntityCell, out result))
                {
                    result = entitiesByAbsoluteCell[absoluteEntityCell] = new List <Entity>();
                }
            }

            return(result);
        }