示例#1
0
 public void MoveClientToWorld(RemoteClient client, World world, Vector3?spawnPoint = null)
 {
     if (client.World == world)
     {
         return;
     }
     lock (client.LoadedChunks)
         client.PauseChunkUpdates = true;
     EntityManager.Despawn(client.Entity);
     while (client.KnownEntities.Any())
     {
         client.ForgetEntity(EntityManager.GetEntityById(client.KnownEntities[0]));
     }
     EntityManager.Update();
     EntityManager.SpawnEntity(world, client.Entity);
     client.UnloadAllChunks();
     // TODO: Allow player to save their positions in each world
     if (spawnPoint == null)
     {
         client.Entity.Position = world.WorldGenerator.SpawnPoint;
     }
     else
     {
         client.Entity.Position = spawnPoint.Value;
     }
     client.UpdateChunks(true);
     client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y + 0.1 + PlayerEntity.Height,
                                                       client.Entity.Position.Z, client.Entity.Position.Y + 0.1, client.Entity.Yaw, client.Entity.Pitch, false));
     EntityManager.SendClientEntities(client);
     lock (client.LoadedChunks)
         client.PauseChunkUpdates = false;
 }
示例#2
0
 private void PhysicsWorker()
 {
     while (true)
     {
         foreach (var engine in PhysicsEngines)
         {
             engine.Update();
         }
         EntityManager.Update();
         if (Settings.SaveInterval != -1 && Level.BaseDirectory != null && NextScheduledSave < DateTime.Now)
         {
             Level.Save();
             NextScheduledSave = DateTime.Now.AddSeconds(Settings.SaveInterval);
         }
         Thread.Sleep(_millisecondsBetweenPhysicsUpdates);
     }
 }