surface_fractal_terrain::surface_fractal_terrain(double sidelen, int size, double hscale, double h, int seed) { rand_generator.seed(seed); if ((size & (size - 1)) != 0) { throw_exception("size should be the power of 2."); } std::vector<std::vector<double> > height; generate_heightmap(height, size, hscale, h); generate_mesh(height, size, sidelen); }
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); }