This commit is contained in:
A-lex-Ra
2024-01-16 12:53:57 +06:00
10 changed files with 212 additions and 231 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"id": "base", "id": "base",
"title": "Base", "title": "Base",
"version": "0.16", "version": "0.18",
"description": "basic content package" "description": "basic content package"
} }
+4 -1
View File
@@ -5,7 +5,10 @@
#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 BLOCK_AIR = 0;
const int ITEM_EMPTY = 0;
const int CHUNK_W = 16; const int CHUNK_W = 16;
const int CHUNK_H = 256; const int CHUNK_H = 256;
+1 -1
View File
@@ -48,7 +48,7 @@ ItemDef* ContentBuilder::createItem(std::string id) {
void ContentBuilder::checkIdentifier(std::string id) { void ContentBuilder::checkIdentifier(std::string id) {
contenttype result; contenttype result;
if ((checkContentType(id) != contenttype::none)) { if (((result = checkContentType(id)) != contenttype::none)) {
throw namereuse_error("name "+id+" is already used", result); throw namereuse_error("name "+id+" is already used", result);
} }
} }
+2 -2
View File
@@ -1,12 +1,12 @@
#ifndef SRC_CORE_DEFS_H_ #ifndef SRC_CORE_DEFS_H_
#define SRC_CORE_DEFS_H_ #define SRC_CORE_DEFS_H_
/* blocks and bindings used in engine code */ #include <string>
const int BLOCK_AIR = 0;
const std::string TEXTURE_NOTFOUND = "notfound"; const std::string TEXTURE_NOTFOUND = "notfound";
/* bindings used in engine code */
const std::string BIND_MOVE_FORWARD = "movement.forward"; const std::string BIND_MOVE_FORWARD = "movement.forward";
const std::string BIND_MOVE_BACK = "movement.back"; const std::string BIND_MOVE_BACK = "movement.back";
const std::string BIND_MOVE_LEFT = "movement.left"; const std::string BIND_MOVE_LEFT = "movement.left";
-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));
+14 -10
View File
@@ -43,21 +43,25 @@ void CameraControl::refresh() {
void CameraControl::updateMouse(PlayerInput& input) { void CameraControl::updateMouse(PlayerInput& input) {
glm::vec2& cam = player->cam; glm::vec2& cam = player->cam;
if (input.zoom) {
cam += -Events::delta / (float)Window::height * settings.sensitivity / 4.f;
} else {
cam += -Events::delta / (float)Window::height * settings.sensitivity;
}
if (cam.y < -glm::radians(89.9f)) { float sensitivity = (input.zoom ? settings.sensitivity / 4.f : settings.sensitivity);
cam.y = -glm::radians(89.9f); cam -= glm::degrees(Events::delta / (float)Window::height * sensitivity);
if (cam.y < -89.9f) {
cam.y = -89.9f;
} }
if (cam.y > glm::radians(89.9f)) { else if (cam.y > 89.9f) {
cam.y = glm::radians(89.9f); cam.y = 89.9f;
}
if (cam.x > 180.f) {
cam.x -= 360.f;
}
else if (cam.x < -180.f) {
cam.x += 360.f;
} }
camera->rotation = glm::mat4(1.0f); camera->rotation = glm::mat4(1.0f);
camera->rotate(cam.y, cam.x, 0); camera->rotate(glm::radians(cam.y), glm::radians(cam.x), 0);
} }
void CameraControl::update(PlayerInput& input, float delta, Chunks* chunks) { void CameraControl::update(PlayerInput& input, float delta, Chunks* chunks) {
-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)){