World::World () { int pad_x = Utils::rand_int(0, Screen::WIDTH - SEGMENT_WIDTH); int pad_y = Utils::rand_int(3 * Screen::HEIGHT / 4, Screen::HEIGHT - 10); Ground pad(true, pad_x, pad_y, pad_x + SEGMENT_WIDTH, pad_y); Ground top(false, 0, 0, Screen::WIDTH, 0); Ground left(false, 0, 0, 0, Screen::HEIGHT); Ground right(false, Screen::WIDTH, 0, Screen::WIDTH, Screen::HEIGHT); grounds.push_back(pad); grounds.push_back(top); grounds.push_back(left); grounds.push_back(right); // The pad location has already been chosen, // create random terrain on both sides of it generate_terrain(pad_x, pad_y, -SEGMENT_WIDTH); generate_terrain(pad_x + SEGMENT_WIDTH, pad_y, SEGMENT_WIDTH); }
RSTag* create_chunk(int x, int z, uint8_t* zero_height) { uint8_t* blocks = rs_malloc0(0x8000); uint8_t* blocklight = rs_malloc0(0x4000); uint8_t* skylight = rs_malloc0(0x4000); uint8_t* data = rs_malloc0(0x4000); uint8_t* heightmap = rs_malloc0(0x100); generate_terrain(x, z, blocks); generate_heightmap(blocks, heightmap); generate_skylight(blocks, heightmap, skylight); if (zero_height) *zero_height = heightmap[0]; RSTag* level = rs_tag_new(RS_TAG_COMPOUND, "xPos", rs_tag_new(RS_TAG_INT, x), "zPos", rs_tag_new(RS_TAG_INT, z), "Blocks", rs_tag_new(RS_TAG_BYTE_ARRAY, 0x8000, blocks), "BlockLight", rs_tag_new(RS_TAG_BYTE_ARRAY, 0x4000, blocklight), "SkyLight", rs_tag_new(RS_TAG_BYTE_ARRAY, 0x4000, skylight), "Data", rs_tag_new(RS_TAG_BYTE_ARRAY, 0x4000, data), "HeightMap", rs_tag_new(RS_TAG_BYTE_ARRAY, 0x100, heightmap), "Entities", rs_tag_new(RS_TAG_LIST, NULL), "TileEntities", rs_tag_new(RS_TAG_LIST, NULL), "TerrainPopulated", rs_tag_new(RS_TAG_BYTE, 1), "LastUpdate", rs_tag_new(RS_TAG_LONG, 0), NULL); rs_free(blocks); rs_free(blocklight); rs_free(skylight); rs_free(data); rs_free(heightmap); return rs_tag_new(RS_TAG_COMPOUND, "Level", level, NULL); }