private void HandleCellUpdates(DataReader reader) { ushort consumeCount = reader.Read <ushort>(); for (int i = 0; i < consumeCount; i++) { uint eatenById = reader.Read <uint>(); uint victimId = reader.Read <uint>(); _world.RemoveCell(victimId); } uint cellId; while ((cellId = reader.Read <uint>()) != 0) { int x = reader.Read <int>(); int y = reader.Read <int>(); ushort size = reader.Read <ushort>(); byte flags = reader.ReadByte(); bool isSpiked = (flags & 0x01) != 0; bool newColor = (flags & 0x02) != 0; bool newSkin = (flags & 0x04) != 0; bool newName = (flags & 0x08) != 0; bool isAgitated = (flags & 0x10) != 0; bool isEjectedCell = (flags & 0x20) != 0; Cell cell = _world.GetCell(cellId); if (cell == null) { cell = _world.AddCell(cellId); } if (newColor) { byte r = reader.ReadByte(); byte g = reader.ReadByte(); byte b = reader.ReadByte(); cell.Color = new Color(r, g, b, 255); } if (newSkin) { reader.ReadUTF8String(); } if (newName) { cell.Name = reader.ReadUTF8String(); } cell.Mass = size; cell.Position = new Vector2i(x, y); } ushort deathCount = reader.Read <ushort>(); for (int i = 0; i < deathCount; i++) { uint victimId = reader.Read <uint>(); _world.RemoveCell(victimId); } }
private void handleUpdateCells(BinaryReader data) { // Mergers ushort mergeCount = data.ReadUInt16(); for (uint i = 0; i < mergeCount; ++i) { uint hunter = data.ReadUInt32(); uint prey = data.ReadUInt32(); _world.RemoveCell(prey); //_world->removeCell(hunter); } // Updates uint id; while ((id = data.ReadUInt32()) != 0) { Cell c = _world.GetCell(id); if (c == null) { c = _world.AddCell(id); } ushort x, y, mass; x = data.ReadUInt16(); y = data.ReadUInt16(); mass = data.ReadUInt16(); byte r, g, b, flags; r = data.ReadByte(); g = data.ReadByte(); b = data.ReadByte(); flags = data.ReadByte(); if ((flags & 2) != 0) { data.ReadBytes(4); } if ((flags & 4) != 0) { data.ReadBytes(8); } if ((flags & 8) != 0) { data.ReadBytes(16); } ushort t; string name = ""; while ((t = data.ReadUInt16()) != 0) { name += new string((char)t, 1); } c.Position = new Vector2i(x, y); c.Mass = mass; c.Color = new Color(r, g, b, 255); c.Name = name; } //Death uint deathCount = data.ReadUInt32(); for (uint i = 0; i < deathCount; ++i) { uint did = data.ReadUInt32(); _world.RemoveCell(did); } }