示例#1
0
        static async void ProcessOps()
        {
            if (shipReferences.Count < 1)
            {
                return;
            }

            var shipSnapshots = (DocumentSnapshot[])await firestore.GetAllSnapshotsAsync(shipReferences);

            var count = shipSnapshots.Length;

            var ships = new List <Entity>(count);

            for (int i = 0; i < count; i++)
            {
                var shipSnapshot = shipSnapshots[i];
                var ship         = shipEntities[i];

                if (!shipSnapshot.Exists)//(new?) player with no ship
                {
                    EntityTemplates.SetRandomStartingPosition(ship);
                    EntityTemplates.AddStarterModules(ship);

                    SpatialOSConnectionSystem.entitiesToCreate.Enqueue(ship);
                }
                else//returning player with ship
                {
                    if (shipSnapshot.TryGetValue <double[]>(ShipCoordinates, out var xyz))
                    {
                        EntityTemplates.SetStartingPosition(new Coordinates(xyz[0], xyz[1], xyz[2]), ship);
                    }
                    else
                    {
                        EntityTemplates.SetRandomStartingPosition(ship);
                    }

                    ships.Add(ship);
                }
            }

            ShipsConstructorSystem.AddOps(shipReferences, ships);

            lock (opLock)
            {
                shipReferences.RemoveRange(0, count);
                shipEntities.RemoveRange(0, count);
            }
        }