private void GameHostResponse(BaseResponse e) { switch (e.Type) { case PacketType.UserEnter: Connected = true; _changingConnection = false; break; case PacketType.UserLogin: RUserLogin userLogin = (RUserLogin)e; _sessionToken = userLogin.SessionToken; ShortSize screenRes = new ShortSize ( Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height ); TCPClientDataSend(new PUserEnter { SessionToken = _sessionToken, ScreenRes = screenRes }); break; } }
private void RecreateMiniMap() { if (_miniMap != null) { Memory.HeapFree(_miniMap); } if (_width <= MINI_MAP_SIZE && _height <= MINI_MAP_SIZE) { MiniMapWidth = _width; MiniMapHeight = _height; } else if (_width > _height) { MiniMapWidth = MINI_MAP_SIZE; MiniMapHeight = (ushort)((float)_height / _width * MINI_MAP_SIZE); } else { MiniMapHeight = MINI_MAP_SIZE; MiniMapWidth = (ushort)((float)_width / _height * MINI_MAP_SIZE); } MiniMapSize = new ShortSize(MiniMapWidth, MiniMapHeight); int miniMapArea = MiniMapWidth * MiniMapHeight; _miniMap = (byte *)Memory.HeapAlloc(miniMapArea / 2); float xCoef = (float)_width / MiniMapWidth; float yCoef = (float)_height / MiniMapHeight; for (int i = 0; i < miniMapArea; i++) { ushort mapX = (ushort)(i * xCoef % _width); ushort mapY = (ushort)(i * xCoef * yCoef / _width); Tile *tile = &_tiles[mapY * _width + mapX]; byte pxl = (byte)((*tile).Type == TileType.Wall ? 1 : 0); if (i % 2 == 0) { _miniMap[i / 2] = (byte)(pxl << 4); } else { _miniMap[i / 2] = (byte)(_miniMap[i / 2] | pxl); } } }
private BaseResponse Enter(int clientId, BasePacket packet) { PUserEnter pUserEnter = (PUserEnter)packet; PlayerDataEx playerData = World.PlayerDataGet(pUserEnter.SessionToken); if (playerData == null) { ThrowSessionError(packet.Type, packet.SessionToken); return(null); } int maxScreenSide = Math.Max(pUserEnter.ScreenRes.Width, pUserEnter.ScreenRes.Height); playerData.ScreenRes = new ShortSize(maxScreenSide, maxScreenSide); List <Player> nearestPlayers = World.PlayersGetNearest(playerData); ShortRect mapWindow; byte[] mapData = World.MapWindowGet(playerData, out mapWindow); ShortSize mapSize = new ShortSize(playerData.Map.Width, playerData.Map.Height); ShortSize miniMapSize; byte[] miniMapData = World.MiniMapGet(playerData, out miniMapSize); RegisterWorldResponseForNearest(playerData, new RPlayerEnter { Player = playerData }); return(new RUserEnter(pUserEnter) { MyPlayerId = playerData.Player.Id, PlayersOnLocation = nearestPlayers, MapSize = mapSize, MapData = mapData, MapWindow = mapWindow, MiniMapData = miniMapData, MiniMapSize = miniMapSize }); }
public void AppendMiniMapData(byte[] data, ShortSize size) { if (_miniMapData != null) { Memory.HeapFree(_miniMapData); } _miniMapSize = size; int miniMapArea = size.Width * size.Height; _miniMapData = (byte *)Memory.HeapAlloc(miniMapArea / 2); fixed(byte *bData = data) { int pos = 0, pxlCnt, curIdx = 0; Serializer.Read(bData, out pxlCnt, ref pos); for (int i = 0; i < pxlCnt; i++) { byte rleMark; ushort seriesLength; Serializer.Read(bData, out rleMark, ref pos); if ((rleMark | 0x80) == rleMark) { byte rleMark2; Serializer.Read(bData, out rleMark2, ref pos); seriesLength = (ushort)((rleMark & ~0x80) << 8 | rleMark2); } else { seriesLength = rleMark; } byte pxl; Serializer.Read(bData, out pxl, ref pos); int maxIdx = curIdx + seriesLength; for (; curIdx < maxIdx; curIdx++) { _miniMapData[curIdx] = pxl; } } } }
private BaseResponse Enter(int clientId, BasePacket packet) { PUserEnter pUserEnter = (PUserEnter) packet; PlayerDataEx playerData = World.PlayerDataGet(pUserEnter.SessionToken); if (playerData == null) { ThrowSessionError(packet.Type, packet.SessionToken); return null; } int maxScreenSide = Math.Max(pUserEnter.ScreenRes.Width, pUserEnter.ScreenRes.Height); playerData.ScreenRes = new ShortSize(maxScreenSide, maxScreenSide); List<Player> nearestPlayers = World.PlayersGetNearest(playerData); ShortRect mapWindow; byte[] mapData = World.MapWindowGet(playerData, out mapWindow); ShortSize mapSize = new ShortSize(playerData.Map.Width, playerData.Map.Height); ShortSize miniMapSize; byte[] miniMapData = World.MiniMapGet(playerData, out miniMapSize); RegisterWorldResponseForNearest(playerData, new RPlayerEnter { Player = playerData }); return new RUserEnter(pUserEnter) { MyPlayerId = playerData.Player.Id, PlayersOnLocation = nearestPlayers, MapSize = mapSize, MapData = mapData, MapWindow = mapWindow, MiniMapData = miniMapData, MiniMapSize = miniMapSize }; }
public void Setup(ShortSize mapSize) { _width = mapSize.Width; _height = mapSize.Height; }
public void AppendMiniMapData(byte[] data, ShortSize size) { if (_miniMapData != null) { Memory.HeapFree(_miniMapData); } _miniMapSize = size; int miniMapArea = size.Width*size.Height; _miniMapData = (byte*) Memory.HeapAlloc(miniMapArea/2); fixed (byte* bData = data) { int pos = 0, pxlCnt, curIdx = 0; Serializer.Read(bData, out pxlCnt, ref pos); for (int i = 0; i < pxlCnt; i++) { byte rleMark; ushort seriesLength; Serializer.Read(bData, out rleMark, ref pos); if ((rleMark | 0x80) == rleMark) { byte rleMark2; Serializer.Read(bData, out rleMark2, ref pos); seriesLength = (ushort)((rleMark & ~0x80) << 8 | rleMark2); } else { seriesLength = rleMark; } byte pxl; Serializer.Read(bData, out pxl, ref pos); int maxIdx = curIdx + seriesLength; for (; curIdx < maxIdx; curIdx++) { _miniMapData[curIdx] = pxl; } } } }
private void RecreateMiniMap() { if (_miniMap != null) { Memory.HeapFree(_miniMap); } if (_width <= MINI_MAP_SIZE && _height <= MINI_MAP_SIZE) { MiniMapWidth = _width; MiniMapHeight = _height; } else if (_width > _height) { MiniMapWidth = MINI_MAP_SIZE; MiniMapHeight = (ushort) ((float) _height/_width*MINI_MAP_SIZE); } else { MiniMapHeight = MINI_MAP_SIZE; MiniMapWidth = (ushort) ((float) _width/_height*MINI_MAP_SIZE); } MiniMapSize = new ShortSize(MiniMapWidth, MiniMapHeight); int miniMapArea = MiniMapWidth*MiniMapHeight; _miniMap = (byte*) Memory.HeapAlloc(miniMapArea/2); float xCoef = (float) _width/MiniMapWidth; float yCoef = (float) _height/MiniMapHeight; for (int i = 0; i < miniMapArea; i++) { ushort mapX = (ushort) (i*xCoef%_width); ushort mapY = (ushort) (i*xCoef*yCoef/_width); Tile* tile = &_tiles[mapY*_width + mapX]; byte pxl = (byte) ((*tile).Type == TileType.Wall ? 1 : 0); if (i%2 == 0) _miniMap[i/2] = (byte) (pxl << 4); else _miniMap[i/2] = (byte) (_miniMap[i/2] | pxl); } }
private void GameHostResponse(BaseResponse e) { if (e.HasError) { ReconnectToHost(); return; } switch (e.Type) { case PacketType.UserLogin: RUserLogin userLogin = (RUserLogin) e; _sessionToken = userLogin.SessionToken; ShortSize screenRes = new ShortSize ( Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height ); TCPClientDataSend(new PUserEnter { SessionToken = _sessionToken, ScreenRes = screenRes }); break; case PacketType.UserEnter: lock (_playersData) { RUserEnter userEnter = (RUserEnter) e; //!!! _map.Setup(userEnter.MapSize); _map.AppendMapData(userEnter.MapData, userEnter.MapWindow); _map.AppendMiniMapData(userEnter.MiniMapData, userEnter.MiniMapSize); OnMapChanged(); foreach (Player p in userEnter.PlayersOnLocation) { if (!_playersData.ContainsKey(p.Id)) { _playersData.Add(p.Id, new PlayerDataEx(p)); } } _myPlayerData = _playersData[userEnter.MyPlayerId]; _playersRo = new ReadOnlyCollection<PlayerDataEx>(_playersData.Values.ToArray()); } CenterTo((int) (_myPlayerData.Player.Position.X*_scaleFactor), //!!! (int) (_myPlayerData.Player.Position.Y*_scaleFactor), true); break; case PacketType.PlayerEnter: lock (_playersData) { RPlayerEnter playerEnter = (RPlayerEnter) e; if (!_playersData.ContainsKey(playerEnter.Player.Id) && _myPlayerData != null && playerEnter.Player.Id != _myPlayerData.Player.Id) { _playersData.Add(playerEnter.Player.Id, new PlayerDataEx(playerEnter.Player)); _playersRo = new ReadOnlyCollection<PlayerDataEx>(_playersData.Values.ToArray()); _somethingChanged = true; //!!! } } break; case PacketType.PlayerExit: lock (_playersData) { RPlayerExit playerExit = (RPlayerExit) e; if (_playersData.ContainsKey(playerExit.PlayerId) && _myPlayerData != null && playerExit.PlayerId != _myPlayerData.Player.Id) { _playersData.Remove(playerExit.PlayerId); _playersRo = new ReadOnlyCollection<PlayerDataEx>(_playersData.Values.ToArray()); _somethingChanged = true; //!!! } } break; case PacketType.PlayerRotate: lock (_playersData) { PlayerDataEx playerData; RPlayerRotate playerRotate = (RPlayerRotate) e; if (_playersData.TryGetValue(playerRotate.PlayerId, out playerData)) playerData.Player.Angle = playerRotate.Angle; } break; case PacketType.PlayerMove: lock (_playersData) { PlayerDataEx playerData; RPlayerMove playerMove = (RPlayerMove) e; if (_playersData.TryGetValue(playerMove.PlayerId, out playerData)) { if (playerMove.Direction == Direction.None) playerData.StopMoving(playerMove.Position); else playerData.StartMoving(playerMove.Position, playerMove.Direction); } } break; case PacketType.MapData: RMapData mapData = (RMapData) e; _map.AppendMapData(mapData.MapData, mapData.MapWindow); //!!! _myPlayerData.GettingMapWindow = false; break; } }
private void GameHostResponse(BaseResponse e) { switch (e.Type) { case PacketType.UserEnter: Connected = true; _changingConnection = false; break; case PacketType.UserLogin: RUserLogin userLogin = (RUserLogin) e; _sessionToken = userLogin.SessionToken; ShortSize screenRes = new ShortSize ( Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height ); TCPClientDataSend(new PUserEnter { SessionToken = _sessionToken, ScreenRes = screenRes }); break; } }
public byte[] MiniMapGet(PlayerDataEx playerData, out ShortSize miniMapSize) { miniMapSize = playerData.Map.MiniMapSize; return(playerData.Map.GetMiniMap()); }
public static void Read(byte *bData, out ShortSize val, ref int pos) { val = *(ShortSize *)&bData[pos]; pos += sizeof(ShortSize); }
public static void Write(byte *bData, ShortSize val, ref int pos) { (*(ShortSize *)&bData[pos]) = val; pos += sizeof(ShortSize); }
public byte[] MiniMapGet(PlayerDataEx playerData, out ShortSize miniMapSize) { miniMapSize = playerData.Map.MiniMapSize; return playerData.Map.GetMiniMap(); }
private void GameHostResponse(BaseResponse e) { if (e.HasError) { ReconnectToHost(); return; } switch (e.Type) { case PacketType.UserLogin: RUserLogin userLogin = (RUserLogin)e; _sessionToken = userLogin.SessionToken; ShortSize screenRes = new ShortSize ( Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height ); TCPClientDataSend(new PUserEnter { SessionToken = _sessionToken, ScreenRes = screenRes }); break; case PacketType.UserEnter: lock (_playersData) { RUserEnter userEnter = (RUserEnter)e; //!!! _map.Setup(userEnter.MapSize); _map.AppendMapData(userEnter.MapData, userEnter.MapWindow); _map.AppendMiniMapData(userEnter.MiniMapData, userEnter.MiniMapSize); OnMapChanged(); foreach (Player p in userEnter.PlayersOnLocation) { if (!_playersData.ContainsKey(p.Id)) { _playersData.Add(p.Id, new PlayerDataEx(p)); } } _myPlayerData = _playersData[userEnter.MyPlayerId]; _playersRo = new ReadOnlyCollection <PlayerDataEx>(_playersData.Values.ToArray()); } CenterTo((int)(_myPlayerData.Player.Position.X * _scaleFactor), //!!! (int)(_myPlayerData.Player.Position.Y * _scaleFactor), true); break; case PacketType.PlayerEnter: lock (_playersData) { RPlayerEnter playerEnter = (RPlayerEnter)e; if (!_playersData.ContainsKey(playerEnter.Player.Id) && _myPlayerData != null && playerEnter.Player.Id != _myPlayerData.Player.Id) { _playersData.Add(playerEnter.Player.Id, new PlayerDataEx(playerEnter.Player)); _playersRo = new ReadOnlyCollection <PlayerDataEx>(_playersData.Values.ToArray()); _somethingChanged = true; //!!! } } break; case PacketType.PlayerExit: lock (_playersData) { RPlayerExit playerExit = (RPlayerExit)e; if (_playersData.ContainsKey(playerExit.PlayerId) && _myPlayerData != null && playerExit.PlayerId != _myPlayerData.Player.Id) { _playersData.Remove(playerExit.PlayerId); _playersRo = new ReadOnlyCollection <PlayerDataEx>(_playersData.Values.ToArray()); _somethingChanged = true; //!!! } } break; case PacketType.PlayerRotate: lock (_playersData) { PlayerDataEx playerData; RPlayerRotate playerRotate = (RPlayerRotate)e; if (_playersData.TryGetValue(playerRotate.PlayerId, out playerData)) { playerData.Player.Angle = playerRotate.Angle; } } break; case PacketType.PlayerMove: lock (_playersData) { PlayerDataEx playerData; RPlayerMove playerMove = (RPlayerMove)e; if (_playersData.TryGetValue(playerMove.PlayerId, out playerData)) { if (playerMove.Direction == Direction.None) { playerData.StopMoving(playerMove.Position); } else { playerData.StartMoving(playerMove.Position, playerMove.Direction); } } } break; case PacketType.MapData: RMapData mapData = (RMapData)e; _map.AppendMapData(mapData.MapData, mapData.MapWindow); //!!! _myPlayerData.GettingMapWindow = false; break; } }