1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "server/packets/WorldPackets.h"
- #include "common/network/Packets.h"
- void WorldPackets::sendChunk(ServerPlayer& p, World& w, int cx, int cz) {
- constexpr int size = BlockStorage::SEGMENT;
- cx *= size;
- cz *= size;
- OutPacket out = OutPacket::reliable(
- w.blocks.getHeight() * size * size * sizeof(Block::Id) * 2 + 10);
- out.writeU16(Packets::S_WORLD_SEGMENT);
- out.writeS32(cx);
- out.writeS32(cz);
- int endX = cx + size;
- int endZ = cz + size;
- Block::Id current = w.blocks.get(cx, 0, cz);
- uint16 counter = 0;
- for(int y = 0; y < w.blocks.getHeight(); y++) {
- for(int x = cx; x < endX; x++) {
- for(int z = cz; z < endZ; z++) {
- Block::Id id = w.blocks.get(x, y, z);
- if(current == id && counter < 65535) {
- counter++;
- } else {
- out.writeU16(current);
- out.writeU16(counter);
- current = id;
- counter = 1;
- }
- }
- }
- }
- out.writeU16(current);
- out.writeU16(counter);
- p.send(out);
- }
|