void LoadMap(string path) { IMapFormatImporter importer = null; if (path.EndsWith(".dat")) { importer = new MapDatImporter(); } else if (path.EndsWith(".fcm")) { importer = new MapFcm3Importer(); } else if (path.EndsWith(".cw")) { importer = new MapCwImporter(); } else if (path.EndsWith(".lvl")) { importer = new MapLvlImporter(); } try { using (FileStream fs = File.OpenRead(path)) { int width, height, length; game.World.Reset(); game.WorldEvents.RaiseOnNewMap(); if (game.World.TextureUrl != null) { TexturePack.ExtractDefault(game); game.World.TextureUrl = null; } BlockInfo.Reset(game); game.Inventory.SetDefaultMapping(); byte[] blocks = importer.Load(fs, game, out width, out height, out length); #if USE16_BIT game.World.SetNewMap(Utils.UInt8sToUInt16s(blocks), width, height, length); #else game.World.SetNewMap(blocks, width, height, length); #endif game.WorldEvents.RaiseOnNewMapLoaded(); if (game.UseServerTextures && game.World.TextureUrl != null) { game.Server.RetrieveTexturePack(game.World.TextureUrl); } LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnRotY, p.SpawnHeadX, false); p.SetLocation(update, false); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); string file = Path.GetFileName(path); game.Chat.Add("&eFailed to load map \"" + file + "\""); } }
void ResetPlayerPosition() { int x = game.Map.Width / 2, z = game.Map.Length / 2; int y = game.Map.GetLightHeight(x, z) + 2; LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, 0, 0, false); game.LocalPlayer.SetLocation(update, false); game.LocalPlayer.SpawnPoint = new Vector3(x, y, z); }
void ResetPlayerPosition() { int x = game.World.Width / 2, z = game.World.Length / 2; int y = game.World.GetLightHeight(x, z) + 2; LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, 0, 0, false); game.LocalPlayer.SetLocation(update, false); game.LocalPlayer.Spawn = new Vector3(x, y, z); game.CurrentCameraPos = game.Camera.GetCameraPos(game.LocalPlayer.EyePosition); }
void ResetPlayerPosition() { float x = (game.World.Width / 2) + 0.5f; float z = (game.World.Length / 2) + 0.5f; Vector3 spawn = Respawn.FindSpawnPosition(game, x, z, game.LocalPlayer.Size); LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, 0, 0, false); game.LocalPlayer.SetLocation(update, false); game.LocalPlayer.Spawn = spawn; game.CurrentCameraPos = game.Camera.GetPosition(0); }
void HandleRelPosAndOrientationUpdate() { byte id = reader.ReadUInt8(); float x = reader.ReadInt8() / 32f; float y = reader.ReadInt8() / 32f; float z = reader.ReadInt8() / 32f; float rotY = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float headX = (float)Utils.PackedToDegrees(reader.ReadUInt8()); LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, rotY, headX, true); net.UpdateLocation(id, update, true); }
internal void HandleRelPosAndOrientationUpdate() { byte id = reader.ReadUInt8(); float x = reader.ReadInt8() / 32f; float y = reader.ReadInt8() / 32f; float z = reader.ReadInt8() / 32f; float yaw = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float pitch = (float)Utils.PackedToDegrees(reader.ReadUInt8()); LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, yaw, pitch, true); UpdateLocation(id, update, true); }
internal static void LoadMap(Game game, string path) { game.World.Reset(); Events.RaiseOnNewMap(); if (game.World.TextureUrl != null) { TexturePack.ExtractDefault(game); game.World.TextureUrl = null; } BlockInfo.Reset(); game.Inventory.SetDefaultMapping(); int width, height, length; byte[] blocks; try { using (Stream fs = Platform.FileOpen(path)) { IMapFormatImporter importer = null; if (path.EndsWith(".dat")) { importer = new MapDatImporter(); } else if (path.EndsWith(".fcm")) { importer = new MapFcm3Importer(); } else if (path.EndsWith(".cw")) { importer = new MapCwImporter(); } else if (path.EndsWith(".lvl")) { importer = new MapLvlImporter(); } blocks = importer.Load(fs, game, out width, out height, out length); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); game.Chat.Add("&eFailed to load map \"" + path + "\""); return; } game.World.SetNewMap(blocks, width, height, length); Events.RaiseOnNewMapLoaded(); LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnRotY, p.SpawnHeadX, false); p.SetLocation(update, false); }
void LoadMap(string path) { IMapFormatImporter importer = null; if (path.EndsWith(".dat")) { importer = new MapDatImporter(); } else if (path.EndsWith(".fcm")) { importer = new MapFcm3Importer(); } else if (path.EndsWith(".cw")) { importer = new MapCwImporter(); } else if (path.EndsWith(".lvl")) { importer = new MapLvlImporter(); } try { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { int width, height, length; game.World.Reset(); game.World.TextureUrl = null; for (int block = BlockInfo.CpeCount; block < BlockInfo.BlocksCount; block++) { game.BlockInfo.ResetBlockInfo((byte)block, false); } game.BlockInfo.SetupCullingCache(); game.BlockInfo.InitLightOffsets(); byte[] blocks = importer.Load(fs, game, out width, out height, out length); game.World.SetNewMap(blocks, width, height, length); game.WorldEvents.RaiseOnNewMapLoaded(); if (game.AllowServerTextures && game.World.TextureUrl != null) { game.Network.RetrieveTexturePack(game.World.TextureUrl); } LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnYaw, p.SpawnPitch, false); p.SetLocation(update, false); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); string file = Path.GetFileName(path); game.Chat.Add("&e/client loadmap: Failed to load map \"" + file + "\""); } }
internal void ReadAbsoluteLocation(byte id, bool interpolate) { Vector3 P = reader.ReadPosition(id); float rotY = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float headX = (float)Utils.PackedToDegrees(reader.ReadUInt8()); if (id == EntityList.SelfID) { net.receivedFirstPosition = true; } LocationUpdate update = LocationUpdate.MakePosAndOri(P, rotY, headX, false); net.UpdateLocation(id, update, interpolate); }
void HandleRelPosAndOrientationUpdate() { byte id = reader.ReadUInt8(); Vector3 v; v.X = reader.ReadInt8() / 32f; v.Y = reader.ReadInt8() / 32f; v.Z = reader.ReadInt8() / 32f; float rotY = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float headX = (float)Utils.PackedToDegrees(reader.ReadUInt8()); LocationUpdate update = LocationUpdate.MakePosAndOri(v, rotY, headX, true); UpdateLocation(id, update, true); }
void ReadAbsoluteLocation(byte id, bool interpolate) { float x = reader.ReadInt16() / 32f; float y = (reader.ReadInt16() - 51) / 32f; // We have to do this. if (id == 255) { y += 22 / 32f; } float z = reader.ReadInt16() / 32f; float yaw = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float pitch = (float)Utils.PackedToDegrees(reader.ReadUInt8()); if (id == 0xFF) { receivedFirstPosition = true; } LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, yaw, pitch, false); UpdateLocation(id, update, interpolate); }
internal void ReadAbsoluteLocation(byte id, bool interpolate) { float x = reader.ReadInt16() / 32f; float y = (reader.ReadInt16() - 51) / 32f; // We have to do this. if (id == EntityList.SelfID) { y += 22 / 32f; } float z = reader.ReadInt16() / 32f; float rotY = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float headX = (float)Utils.PackedToDegrees(reader.ReadUInt8()); if (id == EntityList.SelfID) { net.receivedFirstPosition = true; } LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, rotY, headX, false); net.UpdateLocation(id, update, interpolate); }