Improve model support, QUINTUPLE map generation speeds.
parent
7ba58799e9
commit
119b6dfa55
|
@ -1,5 +1,3 @@
|
|||
#include <cmath>
|
||||
|
||||
//
|
||||
// Created by aurailus on 28/01/19.
|
||||
//
|
||||
|
@ -7,6 +5,8 @@
|
|||
#include "MapGen.h"
|
||||
#include "NoiseSample.h"
|
||||
#include "../../game/scene/world/Schematic.h"
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
|
||||
MapGen::MapGen(unsigned int seed, DefinitionAtlas& defs, BiomeAtlas& biomes) :
|
||||
seed(seed),
|
||||
|
@ -42,10 +42,6 @@ MapGen::MapGen(unsigned int seed, DefinitionAtlas& defs, BiomeAtlas& biomes) :
|
|||
roughness.SetSourceModule(0, roughnessTurbulence);
|
||||
roughness.SetScale(0.5);
|
||||
roughness.SetBias(0.5);
|
||||
|
||||
treeMap.SetFrequency(1.25);
|
||||
treeMap.SetOctaveCount(4);
|
||||
treeAbs.SetSourceModule(0, treeMap);
|
||||
}
|
||||
|
||||
MapGen::chunk_partials_map MapGen::generateMapBlock(glm::ivec3 mbPos) {
|
||||
|
@ -160,26 +156,35 @@ void MapGen::buildElevationMap(chunk_partials_map& chunks, chunk_partial& chunk)
|
|||
}
|
||||
|
||||
void MapGen::generateBlocks(chunk_partial& chunk) {
|
||||
glm::ivec3 lp;
|
||||
glm::ivec3 lp {};
|
||||
|
||||
for (unsigned short m = 0; m < 4096; m++) {
|
||||
if (chunk.second->getBlock(m) != DefinitionAtlas::INVALID) continue;
|
||||
Vec::indAssignVec(m, lp);
|
||||
for (unsigned short i = 0; i < 256; i++) {
|
||||
unsigned short x = i / 16;
|
||||
unsigned short z = i % 16;
|
||||
|
||||
auto biome = biomes.getBiomeAt(chunk.first->temperature.get(lp), chunk.first->humidity.get(lp), chunk.first->roughness.get(lp));
|
||||
chunk.second->biomes[m] = biome.index;
|
||||
auto& biome = biomes.getBiomeAt(chunk.first->temperature.get(lp), chunk.first->humidity.get(lp), chunk.first->roughness.get(lp));
|
||||
|
||||
int d = std::floor(chunk.first->depth[m]);
|
||||
for (unsigned short y = 0; y < 16; y++) {
|
||||
lp = {x, y, z};
|
||||
unsigned short ind = Space::Block::index(lp);
|
||||
|
||||
chunk.second->blocks[m]
|
||||
= d <= 1 ? DefinitionAtlas::AIR
|
||||
: d <= 2 ? biome.topBlock
|
||||
: d <= 4 ? biome.soilBlock
|
||||
: biome.rockBlock;
|
||||
}
|
||||
chunk.second->biomes[ind] = biome.index;
|
||||
|
||||
int d = std::floor(chunk.first->depth[ind]);
|
||||
chunk.second->blocks[ind]
|
||||
= d <= 1 ? DefinitionAtlas::AIR
|
||||
: d <= 2 ? biome.topBlock
|
||||
: d <= 4 ? biome.soilBlock
|
||||
: biome.rockBlock;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapGen::generateStructures(chunk_partials_map& chunks, chunk_partial& chunk) {
|
||||
std::default_random_engine generator(chunk.second->pos.x + chunk.second->pos.y * 30 + chunk.second->pos.z * 3.5);
|
||||
std::uniform_real_distribution<float> distribution(0, 1);
|
||||
|
||||
unsigned int cWood = defs.blockFromStr("zeus:default:wood").index;
|
||||
unsigned int cLeaves = defs.blockFromStr("zeus:default:leaves").index;
|
||||
unsigned int cAir = DefinitionAtlas::INVALID;
|
||||
|
@ -194,16 +199,25 @@ void MapGen::generateStructures(chunk_partials_map& chunks, chunk_partial& chunk
|
|||
glm::ivec3 wp = chunk.second->pos;
|
||||
glm::ivec3 lp;
|
||||
|
||||
for (unsigned short m = 0; m < 4096; m++) {
|
||||
Vec::indAssignVec(m, lp);
|
||||
for (unsigned short i = 0; i < 256; i++) {
|
||||
unsigned short x = i / 16;
|
||||
unsigned short z = i % 16;
|
||||
|
||||
glm::ivec3 p = wp * 16 + lp;
|
||||
if (distribution(generator) > 0.97) {
|
||||
for (unsigned short y = 0; y < 16; y++) {
|
||||
lp = {x, y, z};
|
||||
unsigned short ind = Space::Block::index(lp);
|
||||
|
||||
if (treeAbs.GetValue(p.x, p.y, p.z) > 1.2 && chunk.first->depth[m] <= 2 && chunk.first->depth[m] > 1) {
|
||||
glm::ivec3 off = {};
|
||||
for (unsigned int i = 0; i < c.length(); i++) {
|
||||
c.assignOffset(i, off);
|
||||
setBlock(p + off - c.origin, c.blocks[i], chunks);
|
||||
if (chunk.first->depth[ind] <= 2 && chunk.first->depth[ind] > 1) {
|
||||
|
||||
glm::ivec3 off = {};
|
||||
glm::ivec3 p = wp * 16 + lp;
|
||||
|
||||
for (unsigned int j = 0; j < c.length(); j++) {
|
||||
c.assignOffset(j, off);
|
||||
setBlock(p + off - c.origin, c.blocks[j], chunks);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,4 @@ private:
|
|||
module::Perlin roughnessBase;
|
||||
module::Turbulence roughnessTurbulence;
|
||||
module::ScaleBias roughness;
|
||||
|
||||
module::Perlin treeMap;
|
||||
module::Abs treeAbs;
|
||||
};
|
|
@ -270,20 +270,35 @@ std::shared_ptr<GUIComponent> GuiBuilder::createComponent(SerializedGuiElem& dat
|
|||
|
||||
else if (data.type == "model") {
|
||||
glm::vec2 scale = {1, 1};
|
||||
if (data.tokens.count("size")) {
|
||||
auto tokens = splitValue(data.tokens["size"], 2);
|
||||
if (data.tokens.count("scale")) {
|
||||
auto tokens = splitValue(data.tokens["scale"], 2);
|
||||
scale = {stringToNum(tokens[0], PercentBehavior::DECIMAL),
|
||||
stringToNum(tokens[1], PercentBehavior::DECIMAL)};
|
||||
}
|
||||
std::string type = (data.tokens.count("type") ? data.tokens["type"] : "model");
|
||||
std::string source = (data.tokens.count("source") ? data.tokens["source"] : "");
|
||||
std::string texture = (data.tokens.count("texture") ? data.tokens["texture"] : "");
|
||||
|
||||
std::string modelStr = (data.tokens.count("model")) ? data.tokens["model"] : "";
|
||||
glm::vec2 anim_range = {0, 0};
|
||||
if (data.tokens.count("anim_range")) {
|
||||
auto tokens = splitValue(data.tokens["anim_range"], 2);
|
||||
anim_range = {stringToNum(tokens[0], PercentBehavior::DECIMAL),
|
||||
stringToNum(tokens[1], PercentBehavior::DECIMAL)};
|
||||
}
|
||||
|
||||
auto m = std::make_shared<Model>();
|
||||
m->fromSerialized(defs.models.models["zeus:default:bird"], {defs.textures["zeus:default:raven"]});
|
||||
|
||||
if (type == "model") {
|
||||
m->fromSerialized(defs.models.models[source], {defs.textures[texture]});
|
||||
}
|
||||
|
||||
auto model = std::make_shared<GUIModel>(data.key);
|
||||
model->create(scale, m);
|
||||
|
||||
if (anim_range.y != 0) {
|
||||
model->animate(anim_range);
|
||||
}
|
||||
|
||||
model->setPos(pos);
|
||||
model->setCallbacks(cbLeftClick, cbRightClick, cbHover);
|
||||
return model;
|
||||
|
|
|
@ -32,7 +32,7 @@ void GUIComponent::setPos(glm::ivec2 pos) {
|
|||
pos += glm::vec2 {parentPos.x, parentPos.y};
|
||||
pos += glm::vec2 {parent->getPadding().w, parent->getPadding().x};
|
||||
}
|
||||
entity.setPos({pos.x, pos.y, 0});
|
||||
entity.setPos({pos.x, pos.y, depth});
|
||||
for (const auto& child : children) {
|
||||
child->updatePos();
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ void GUIComponent::updatePos() {
|
|||
realPos += glm::vec2 {parentPos.x, parentPos.y};
|
||||
realPos += glm::vec2 {parent->getPadding().w, parent->getPadding().x};
|
||||
}
|
||||
entity.setPos({realPos.x, realPos.y, 0});
|
||||
entity.setPos({realPos.x, realPos.y, depth});
|
||||
for (const auto& child : children) {
|
||||
child->updatePos();
|
||||
}
|
||||
|
|
|
@ -73,6 +73,8 @@ protected:
|
|||
callback cbHover = nullptr;
|
||||
|
||||
Entity entity;
|
||||
protected:
|
||||
float depth = 0;
|
||||
private:
|
||||
void updatePos();
|
||||
};
|
||||
|
|
|
@ -14,11 +14,12 @@ void GUIModel::create(glm::vec2 scale, std::shared_ptr<Model> model) {
|
|||
setRotationY(215);
|
||||
}
|
||||
|
||||
void GUIModel::draw(Renderer &renderer) {
|
||||
renderer.toggleDepthTest(true);
|
||||
renderer.clearDepthBuffer();
|
||||
GUIComponent::draw(renderer);
|
||||
renderer.toggleDepthTest(false);
|
||||
void GUIModel::update(double delta) {
|
||||
entity.update(delta);
|
||||
}
|
||||
|
||||
void GUIModel::animate(glm::vec2 range) {
|
||||
entity.playRange(range.x, range.y, true);
|
||||
}
|
||||
|
||||
void GUIModel::setRotationX(float x) {
|
||||
|
@ -33,6 +34,9 @@ void GUIModel::setRotationZ(float z) {
|
|||
entity.setRotateZ(z);
|
||||
}
|
||||
|
||||
void GUIModel::update(double delta) {
|
||||
entity.update(delta);
|
||||
}
|
||||
void GUIModel::draw(Renderer &renderer) {
|
||||
renderer.toggleDepthTest(true);
|
||||
renderer.clearDepthBuffer();
|
||||
GUIComponent::draw(renderer);
|
||||
renderer.toggleDepthTest(false);
|
||||
}
|
|
@ -16,9 +16,13 @@ public:
|
|||
void create(glm::vec2 scale, std::shared_ptr<Model> model);
|
||||
void update(double delta) override;
|
||||
|
||||
void animate(glm::vec2 range);
|
||||
|
||||
void setRotationX(float x);
|
||||
void setRotationY(float x);
|
||||
void setRotationZ(float x);
|
||||
|
||||
void draw(Renderer& renderer) override;
|
||||
protected:
|
||||
float depth = 300;
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ std::string VenusParser::parse(const std::string& fileName, const std::string& f
|
|||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
|
||||
std::string result;
|
||||
std::array<char, 128> buffer;
|
||||
std::array<char, 1024> buffer;
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) result += buffer.data();
|
||||
|
||||
const static std::string errorHeader = "--ZEPHA_PARSING_ERROR--";
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include "ServerWorld.h"
|
||||
|
||||
const static int MB_GEN_H = 3;
|
||||
const static int MB_GEN_V = 3;
|
||||
const static int MB_GEN_H = 6;
|
||||
const static int MB_GEN_V = 4;
|
||||
|
||||
ServerWorld::ServerWorld(unsigned int seed, ServerDefs& defs, ServerClients& clients) :
|
||||
clientList(clients),
|
||||
|
|
|
@ -4,22 +4,20 @@ zepha.register_entity("zeus:default:test", {
|
|||
display_texture = "zeus:default:player",
|
||||
|
||||
on_create = fn(self) {
|
||||
## self.object.set_animations({
|
||||
## {"wal0, 100}
|
||||
## })
|
||||
## self.object:snap_scale(1/4)
|
||||
self.object.anims:define({
|
||||
walk = {0, 300}
|
||||
})
|
||||
self.object.anims:set_anim("walk"):play()
|
||||
self.object.scale = 1/4
|
||||
},
|
||||
on_update = fn(self, delta) {
|
||||
self.object:set_pos(v(
|
||||
self.object.pos.x + 0.08 * math.sin(math.rad(self.object.yaw)),
|
||||
self.object.pos.y,
|
||||
self.object.pos.z + 0.08 * math.cos(math.rad(self.object.yaw)))
|
||||
)
|
||||
self.object.yaw += 2
|
||||
## self.object.pos = vector.add(vector.multiply(v(0.6 * math.sin(math.rad(self.object.yaw)), 0,
|
||||
## 0.6 * math.cos(math.rad(self.object.yaw))), delta), self.object.pos)
|
||||
## self.object.yaw += 50 * delta
|
||||
}
|
||||
})
|
||||
|
||||
if (zepha.server) {
|
||||
local entity = zepha.add_entity("zeus:default:test", v(10, 0, 0))
|
||||
if (zepha.client) {
|
||||
local entity = zepha.add_entity("zeus:default:test", v(0, 0, 0))
|
||||
##zepha.delay(() => { zepha.remove_entity(entity) }, 10)
|
||||
}
|
|
@ -130,8 +130,12 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
|||
end
|
||||
|
||||
model
|
||||
size: 8px 8px
|
||||
position: 100, 100
|
||||
scale: 96 96
|
||||
position: 195 145
|
||||
type: model
|
||||
source: zeus:default:player
|
||||
texture: zeus:default:player
|
||||
anim_range: 0 300
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue