version set to 0.18 + WorldGenerator indents fix

This commit is contained in:
MihailRis
2024-01-15 13:08:31 +03:00
parent cec8d75b7d
commit 1e12f80dd6
6 changed files with 190 additions and 216 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
#include "typedefs.h" #include "typedefs.h"
const int ENGINE_VERSION_MAJOR = 0; const int ENGINE_VERSION_MAJOR = 0;
const int ENGINE_VERSION_MINOR = 17; const int ENGINE_VERSION_MINOR = 18;
const int CHUNK_W = 16; const int CHUNK_W = 16;
const int CHUNK_H = 256; const int CHUNK_H = 256;
-3
View File
@@ -56,9 +56,6 @@ void WorldConverter::convertNext() {
std::unique_ptr<ubyte[]> data (wfile->getChunk(gx, gz)); std::unique_ptr<ubyte[]> data (wfile->getChunk(gx, gz));
if (data == nullptr) if (data == nullptr)
continue; continue;
if (wfile->getVoxelRegionVersion(x, z) != REGION_FORMAT_VERSION) {
Chunk::fromOld(data.get());
}
if (lut) { if (lut) {
Chunk::convert(data.get(), lut.get()); Chunk::convert(data.get(), lut.get());
} }
-10
View File
@@ -176,21 +176,11 @@ void open_world(std::string name, Engine* engine) {
} else { } else {
show_convert_request(engine, content, lut, folder); show_convert_request(engine, content, lut, folder);
} }
} else {
// TODO: remove in 0.18
int version;
{
WorldFiles wfile(folder, settings.debug);
version = wfile.getVoxelRegionsVersion();
}
if (version != REGION_FORMAT_VERSION) {
show_convert_request(engine, content, lut, folder);
} else { } else {
Level* level = World::load(folder, settings, content, packs); Level* level = World::load(folder, settings, content, packs);
engine->setScreen(std::make_shared<LevelScreen>(engine, level)); engine->setScreen(std::make_shared<LevelScreen>(engine, level));
} }
} }
}
Panel* create_worlds_panel(Engine* engine) { Panel* create_worlds_panel(Engine* engine) {
auto panel = new Panel(vec2(390, 200), vec4(5.0f)); auto panel = new Panel(vec2(390, 200), vec4(5.0f));
-12
View File
@@ -104,18 +104,6 @@ bool Chunk::decode(ubyte* data) {
return true; return true;
} }
/*
* Convert chunk voxels data from 16 bit to 32 bit
*/
void Chunk::fromOld(ubyte* data) {
for (size_t i = 0; i < CHUNK_VOL; i++) {
data[i + CHUNK_VOL*3] = data[i + CHUNK_VOL];
data[i + CHUNK_VOL] = data[i];
data[i + CHUNK_VOL*2] = 0;
data[i] = 0;
}
}
void Chunk::convert(ubyte* data, const ContentLUT* lut) { void Chunk::convert(ubyte* data, const ContentLUT* lut) {
for (size_t i = 0; i < CHUNK_VOL; i++) { for (size_t i = 0; i < CHUNK_VOL; i++) {
// see encode method to understand what the hell is going on here // see encode method to understand what the hell is going on here
-1
View File
@@ -78,7 +78,6 @@ public:
ubyte* encode() const; ubyte* encode() const;
bool decode(ubyte* data); bool decode(ubyte* data);
static void fromOld(ubyte* data);
static void convert(ubyte* data, const ContentLUT* lut); static void convert(ubyte* data, const ContentLUT* lut);
}; };
+15 -15
View File
@@ -17,10 +17,12 @@
#include "../maths/voxmaths.h" #include "../maths/voxmaths.h"
#include "../core_defs.h" #include "../core_defs.h"
// TODO: do something with long conditions + move magic numbers to constants
const int SEA_LEVEL = 55; const int SEA_LEVEL = 55;
enum class MAPS{ enum class MAPS{
SEND, SAND,
TREE, TREE,
CLIFF, CLIFF,
HEIGHT HEIGHT
@@ -32,13 +34,11 @@ class Map2D {
int w, d; int w, d;
float* heights[MAPS_LEN]; float* heights[MAPS_LEN];
public: public:
Map2D(int x, int z, int w, int d) Map2D(int x, int z, int w, int d) : x(x), z(z), w(w), d(d) {
: x(x), z(z), w(w), d(d) {
for (int i = 0; i < MAPS_LEN; i++) for (int i = 0; i < MAPS_LEN; i++)
heights[i] = new float[w*d]; heights[i] = new float[w*d];
} }
~Map2D() { ~Map2D() {
for (int i = 0; i < MAPS_LEN; i++) for (int i = 0; i < MAPS_LEN; i++)
delete[] heights[i]; delete[] heights[i];
} }
@@ -180,8 +180,8 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
int cur_z = z + cz * CHUNK_D; int cur_z = z + cz * CHUNK_D;
float height = calc_height(&noise, cur_x, cur_z); float height = calc_height(&noise, cur_x, cur_z);
float hum = fnlGetNoise2D(&noise, cur_x * 0.3 + 633, cur_z * 0.3); float hum = fnlGetNoise2D(&noise, cur_x * 0.3 + 633, cur_z * 0.3);
float send = fnlGetNoise2D(&noise, cur_x * 0.1 - 633, cur_z * 0.1 + 1000); float sand = fnlGetNoise2D(&noise, cur_x * 0.1 - 633, cur_z * 0.1 + 1000);
float cliff = pow((send + abs(send)) / 2, 2); float cliff = pow((sand + abs(sand)) / 2, 2);
float w = pow(fmax(-abs(height-SEA_LEVEL)+4,0)/6,2) * cliff; float w = pow(fmax(-abs(height-SEA_LEVEL)+4,0)/6,2) * cliff;
float h1 = -abs(height-SEA_LEVEL - 0.03); float h1 = -abs(height-SEA_LEVEL - 0.03);
float h2 = abs(height-SEA_LEVEL + 0.04); float h2 = abs(height-SEA_LEVEL + 0.04);
@@ -189,9 +189,8 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
height += (h * w); height += (h * w);
heights.set(MAPS::HEIGHT, cur_x, cur_z, height); heights.set(MAPS::HEIGHT, cur_x, cur_z, height);
heights.set(MAPS::TREE, cur_x, cur_z, hum); heights.set(MAPS::TREE, cur_x, cur_z, hum);
heights.set(MAPS::SEND, cur_x, cur_z, send); heights.set(MAPS::SAND, cur_x, cur_z, sand);
heights.set(MAPS::CLIFF, cur_x, cur_z, cliff); heights.set(MAPS::CLIFF, cur_x, cur_z, cliff);
} }
} }
@@ -212,17 +211,18 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
} else if (cur_y < height){ } else if (cur_y < height){
id = idDirt; id = idDirt;
} else { } else {
int tree = generate_tree(&noise, &randomtree, heights, cur_x, cur_y, cur_z, treesTile, idWood, idLeaves); int tree = generate_tree(
&noise, &randomtree, heights,
cur_x, cur_y, cur_z,
treesTile, idWood, idLeaves);
if (tree) { if (tree) {
id = tree; id = tree;
states = BLOCK_DIR_UP; states = BLOCK_DIR_UP;
} }
} }
float send = fmax(heights.get(MAPS::SEND, cur_x, cur_z), heights.get(MAPS::CLIFF, cur_x, cur_z)); float sand = fmax(heights.get(MAPS::SAND, cur_x, cur_z), heights.get(MAPS::CLIFF, cur_x, cur_z));
if ( if (((height - (1.1 - 0.2 * pow(height - 54, 4)) +
((height - (1.1 - 0.2 * pow(height - 54, 4)) (5*sand)) < cur_y + (height - 0.01- (int)height))
+
(5*send)) < cur_y + (height - 0.01- (int)height))
&& (cur_y < height)){ && (cur_y < height)){
id = idSand; id = idSand;
} }
@@ -230,7 +230,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
id = idBazalt; id = idBazalt;
randomgrass.setSeed(cur_x,cur_z); randomgrass.setSeed(cur_x,cur_z);
if ((id == 0) && ((height > SEA_LEVEL+0.4) || (send > 0.1)) && ((int)(height + 1) == cur_y) && ((unsigned short)randomgrass.rand() > 56000)){ if ((id == 0) && ((height > SEA_LEVEL+0.4) || (sand > 0.1)) && ((int)(height + 1) == cur_y) && ((unsigned short)randomgrass.rand() > 56000)){
id = idGrass; id = idGrass;
} }
if ((id == 0) && (height > SEA_LEVEL+0.4) && ((int)(height + 1) == cur_y) && ((unsigned short)randomgrass.rand() > 65000)){ if ((id == 0) && (height > SEA_LEVEL+0.4) && ((int)(height + 1) == cur_y) && ((unsigned short)randomgrass.rand() > 65000)){