Created
September 22, 2011 03:16
-
-
Save jlitewski/1233934 to your computer and use it in GitHub Desktop.
CraftD rapid prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static | |
bool | |
cdsurvival_SendChunk (CDServer* server, SVPlayer* player, SVChunkPosition* coord) | |
{ | |
DO { | |
SVPacketPreChunk pkt = { | |
.response = { | |
.position = *coord, | |
.mode = true | |
} | |
}; | |
SVPacket response = { SVResponse, SVPreChunk, (CDPointer) &pkt }; | |
SV_PlayerSendPacketAndCleanData(player, &response); | |
} | |
DO { | |
SDEBUG(server, "sending chunk (%d, %d)", coord->x, coord->z); | |
SVChunk* chunk = CD_malloc(sizeof(SVChunk)); | |
CDError status; | |
CD_EventDispatchWithError(status, server, "World.chunk", player->world, coord->x, coord->z, chunk); | |
if (status != CDOk) { | |
CD_free(chunk); | |
return false; | |
} | |
uLongf written = compressBound(81920); | |
Bytef* buffer = CD_malloc(written); | |
Bytef* data = CD_malloc(81920); | |
SV_ChunkToByteArray(chunk, data); | |
if (compress(buffer, &written, (Bytef*) data, 81920) != Z_OK) { | |
SERR(server, "zlib compress failure"); | |
CD_free(chunk); | |
CD_free(data); | |
return false; | |
} | |
SDEBUG(server, "compressed to %ld bytes", written); | |
CD_free(chunk); | |
CD_free(data); | |
SVPacketMapChunk pkt = { | |
.response = { | |
.position = SV_ChunkPositionToBlockPosition(*coord), | |
.size = { | |
.x = 16, | |
.y = 128, | |
.z = 16 | |
}, | |
.length = written, | |
.item = (SVByte*) buffer | |
} | |
}; | |
SVPacket response = { SVResponse, SVMapChunk, (CDPointer) &pkt }; | |
SV_PlayerSendPacketAndCleanData(player, &response); | |
} | |
return true; | |
} | |
static | |
void | |
cdsurvival_ChunkRadiusUnload (CDSet* self, SVChunkPosition* coord, SVPlayer* player) | |
{ | |
assert(self); | |
assert(coord); | |
assert(player); | |
DO { | |
SVPacketPreChunk pkt = { | |
.response = { | |
.position = *coord, | |
.mode = false | |
} | |
}; | |
SVPacket response = { SVResponse, SVPreChunk, (CDPointer) &pkt }; | |
SV_PlayerSendPacketAndCleanData(player, &response); | |
} | |
CD_free(coord); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment