Exemplo n.º 1
0
/**
 * Load the world from a file.
 * @param ldr Input stream to read from.
 */
void VoxelWorld::Load(Loader &ldr)
{
	uint32 version = ldr.OpenBlock("WRLD");
	uint16 xsize = 64;
	uint16 ysize = 64;
	if (version == 1) {
		xsize = ldr.GetWord();
		ysize = ldr.GetWord();
	} else if (version != 0) {
		ldr.SetFailMessage("Unknown world version.");
	}
	if (xsize >= WORLD_X_SIZE || ysize >= WORLD_Y_SIZE) {
		xsize = std::min<uint16>(xsize, WORLD_X_SIZE);
		ysize = std::min<uint16>(ysize, WORLD_Y_SIZE);
		ldr.SetFailMessage("Incorrect world size");
	}
	ldr.CloseBlock();

	this->SetWorldSize(xsize, ysize);
	if (!ldr.IsFail() && version != 0) {
		for (uint16 x = 0; x < xsize; x++) {
			for (uint16 y = 0; y < ysize; y++) {
				VoxelStack *vs = this->GetModifyStack(x, y);
				vs->Load(ldr);
			}
		}
	}
	if (version == 0 || ldr.IsFail()) this->MakeFlatWorld(8);
}