add core:obstacle block & move cameras from base to core & add new generator

This commit is contained in:
MihailRis 2024-09-25 15:45:45 +03:00
parent d534207deb
commit 788ad1f6a6
19 changed files with 147 additions and 114 deletions

View File

@ -0,0 +1,86 @@
sea_level = 64
-- 1 - temperature
-- 2 - humidity
biome_parameters = 2
biomes = json.parse(file.read("base:generators/demo/biomes.json"))
function place_structures(x, z, w, d, seed, hmap)
local placements = {}
for i=1,10 do
local sx = math.random() * w
local sz = math.random() * d
local sy = math.random() * 128
if sy < hmap:at(sx, sz) * 256 - 6 then
table.insert(placements, {"coal_ore0", {sx, sy, sz}, math.random()*4})
end
end
return placements
end
local function _generate_heightmap(x, y, w, h, seed, s)
local umap = Heightmap(w, h)
local vmap = Heightmap(w, h)
umap.noiseSeed = seed
vmap.noiseSeed = seed
vmap:noise({x+521, y+70}, 0.1*s, 3, 25.8)
vmap:noise({x+95, y+246}, 0.15*s, 3, 25.8)
local map = Heightmap(w, h)
map.noiseSeed = seed
map:noise({x, y}, 0.8*s, 4, 0.02)
map:cellnoise({x, y}, 0.1*s, 3, 0.3, umap, vmap)
map:add(0.4)
local rivermap = Heightmap(w, h)
rivermap.noiseSeed = seed
rivermap:noise({x+21, y+12}, 0.1*s, 4)
rivermap:abs()
rivermap:mul(2.0)
rivermap:pow(0.15)
rivermap:max(0.3)
map:add(0.3)
map:mul(rivermap)
return map
end
function generate_heightmap(x, y, w, h, seed)
-- blocks per dot
-- 8 - linear interpolation is visible, but not so much
-- 4 - high quality, but slower
-- 2 - you really don't need it
-- 1 - please have mercy on your CPU
local bpd = 4
local map = _generate_heightmap(
math.floor(x/bpd), math.floor(y/bpd),
math.floor(w/bpd)+1, math.floor(h/bpd)+1, seed, bpd)
map:resize(w+bpd, h+bpd, 'linear')
map:crop(0, 0, w, h)
return map
end
local function _generate_biome_parameters(x, y, w, h, seed, s)
local tempmap = Heightmap(w, h)
tempmap.noiseSeed = seed + 5324
tempmap:noise({x, y}, 0.04*s, 6)
local hummap = Heightmap(w, h)
hummap.noiseSeed = seed + 953
hummap:noise({x, y}, 0.04*s, 6)
tempmap:pow(3)
hummap:pow(3)
return tempmap, hummap
end
function generate_biome_parameters(x, y, w, h, seed)
local bpd = 8
local tmap, hmap = _generate_biome_parameters(
math.floor(x/bpd), math.floor(y/bpd),
math.floor(w/bpd)+1, math.floor(h/bpd)+1, seed, bpd)
tmap:resize(w+bpd, h+bpd, 'linear')
tmap:crop(0, 0, w, h)
hmap:resize(w+bpd, h+bpd, 'linear')
hmap:crop(0, 0, w, h)
return tmap, hmap
end

View File

@ -7,13 +7,6 @@
"models": [
"drop-item"
],
"shaders": [
"ui3d",
"entity",
"screen",
"background",
"skybox_gen"
],
"textures": [
"misc/moon",
"misc/sun",

View File

@ -1,84 +1,15 @@
sea_level = 64
biome_parameters = 0
-- 1 - temperature
-- 2 - humidity
biome_parameters = 2
biomes = json.parse(file.read("core:generators/default/biomes.json"))
function place_structures(x, z, w, d, seed, hmap)
local placements = {}
for i=1,10 do
local sx = math.random() * w
local sz = math.random() * d
local sy = math.random() * hmap:at(sx, sz)*256 - 6
table.insert(placements, {"coal_ore0", {sx, sy, sz}, math.random()*4})
end
return placements
end
local function _generate_heightmap(x, y, w, h, seed, s)
local umap = Heightmap(w, h)
local vmap = Heightmap(w, h)
umap.noiseSeed = seed
vmap.noiseSeed = seed
vmap:noise({x+521, y+70}, 0.1*s, 3, 25.8)
vmap:noise({x+95, y+246}, 0.15*s, 3, 25.8)
local map = Heightmap(w, h)
map.noiseSeed = seed
map:noise({x, y}, 0.8*s, 4, 0.02)
map:cellnoise({x, y}, 0.1*s, 3, 0.3, umap, vmap)
map:add(0.4)
local rivermap = Heightmap(w, h)
rivermap.noiseSeed = seed
rivermap:noise({x+21, y+12}, 0.1*s, 4)
rivermap:abs()
rivermap:mul(2.0)
rivermap:pow(0.15)
rivermap:max(0.3)
map:add(0.3)
map:mul(rivermap)
return map
end
biomes = {flat = {
parameters = {},
layers = {
{height=-1, block="core:obstacle"},
},
sea_layers = {
{height=-1, block="core:obstacle"}
}
}}
function generate_heightmap(x, y, w, h, seed)
-- blocks per dot
-- 8 - linear interpolation is visible, but not so much
-- 4 - high quality, but slower
-- 2 - you really don't need it
-- 1 - please have mercy on your CPU
local bpd = 4
local map = _generate_heightmap(
math.floor(x/bpd), math.floor(y/bpd),
math.floor(w/bpd)+1, math.floor(h/bpd)+1, seed, bpd)
map:resize(w+bpd, h+bpd, 'linear')
map:crop(0, 0, w, h)
return map
end
local function _generate_biome_parameters(x, y, w, h, seed, s)
local tempmap = Heightmap(w, h)
tempmap.noiseSeed = seed + 5324
tempmap:noise({x, y}, 0.04*s, 6)
local hummap = Heightmap(w, h)
hummap.noiseSeed = seed + 953
hummap:noise({x, y}, 0.04*s, 6)
tempmap:pow(3)
hummap:pow(3)
return tempmap, hummap
end
function generate_biome_parameters(x, y, w, h, seed)
local bpd = 8
local tmap, hmap = _generate_biome_parameters(
math.floor(x/bpd), math.floor(y/bpd),
math.floor(w/bpd)+1, math.floor(h/bpd)+1, seed, bpd)
tmap:resize(w+bpd, h+bpd, 'linear')
tmap:crop(0, 0, w, h)
hmap:resize(w+bpd, h+bpd, 'linear')
hmap:crop(0, 0, w, h)
return tmap, hmap
return Heightmap(w, h)
end

View File

@ -1,8 +1,13 @@
{
"shaders": [
"ui",
"ui3d",
"main",
"lines"
"lines",
"entity",
"screen",
"background",
"skybox_gen"
],
"textures": [
"gui/menubg",

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -17,6 +17,7 @@ inline constexpr bool ENGINE_DEBUG_BUILD = true;
inline const std::string ENGINE_VERSION_STRING = "0.23";
inline constexpr blockid_t BLOCK_AIR = 0;
inline constexpr blockid_t BLOCK_OBSTACLE = 1;
inline constexpr itemid_t ITEM_EMPTY = 0;
inline constexpr entityid_t ENTITY_NONE = 0;

View File

@ -528,6 +528,18 @@ void ContentLoader::load() {
}
}
fs::path resourcesFile = folder / fs::u8path("resources.json");
if (fs::exists(resourcesFile)) {
auto resRoot = files::read_json(resourcesFile);
for (const auto& [key, arr] : resRoot.asObject()) {
if (auto resType = ResourceType_from(key)) {
loadResources(*resType, arr);
} else {
logger.warning() << "unknown resource type: " << key;
}
}
}
if (!fs::is_regular_file(pack->getContentFile())) return;
auto root = files::read_json(pack->getContentFile());
@ -723,18 +735,6 @@ void ContentLoader::load() {
}
}
}
fs::path resourcesFile = folder / fs::u8path("resources.json");
if (fs::exists(resourcesFile)) {
auto resRoot = files::read_json(resourcesFile);
for (const auto& [key, arr] : resRoot.asObject()) {
if (auto resType = ResourceType_from(key)) {
loadResources(*resType, arr);
} else {
logger.warning() << "unknown resource type: " << key;
}
}
}
}
void ContentLoader::loadResources(ResourceType type, const dv::value& list) {

View File

@ -12,7 +12,8 @@
// All in-game definitions (blocks, items, etc..)
void corecontent::setup(EnginePaths* paths, ContentBuilder* builder) {
Block& block = builder->blocks.create("core:air");
{
Block& block = builder->blocks.create(CORE_AIR);
block.replaceable = true;
block.drawGroup = 1;
block.lightPassing = true;
@ -20,9 +21,10 @@ void corecontent::setup(EnginePaths* paths, ContentBuilder* builder) {
block.obstacle = false;
block.selectable = false;
block.model = BlockModel::none;
block.pickingItem = "core:empty";
block.pickingItem = CORE_EMPTY;
}
ItemDef& item = builder->items.create("core:empty");
ItemDef& item = builder->items.create(CORE_EMPTY);
item.iconType = item_icon_type::none;
auto bindsFile = paths->getResourcesFolder()/fs::path("bindings.toml");
@ -31,4 +33,17 @@ void corecontent::setup(EnginePaths* paths, ContentBuilder* builder) {
bindsFile.u8string(), files::read_string(bindsFile)
);
}
{
Block& block = builder->blocks.create(CORE_OBSTACLE);
for (uint i = 0; i < 6; i++) {
block.textureFaces[i] = "obstacle";
}
block.hitboxes = {AABB()};
ItemDef& item = builder->items.create(CORE_OBSTACLE+".item");
item.iconType = item_icon_type::block;
item.icon = CORE_OBSTACLE;
item.placingBlock = CORE_OBSTACLE;
item.caption = block.caption;
}
}

View File

@ -3,6 +3,7 @@
#include <string>
inline const std::string CORE_EMPTY = "core:empty";
inline const std::string CORE_OBSTACLE = "core:obstacle";
inline const std::string CORE_AIR = "core:air";
inline const std::string TEXTURE_NOTFOUND = "notfound";

View File

@ -286,7 +286,8 @@ std::unique_ptr<GeneratorScript> scripting::load_generator(
lua::pop(L);
uint biomeParameters = root["biome_parameters"].asInteger();
uint seaLevel = root["sea_level"].asInteger();
uint seaLevel = 0;
root.at("sea_level").get(seaLevel);
std::vector<Biome> biomes;

View File

@ -37,9 +37,9 @@ Player::Player(
position(position),
inventory(std::move(inv)),
eid(eid),
camera(level->getCamera("base:first-person")),
spCamera(level->getCamera("base:third-person-front")),
tpCamera(level->getCamera("base:third-person-back")),
camera(level->getCamera("core:first-person")),
spCamera(level->getCamera("core:third-person-front")),
tpCamera(level->getCamera("core:third-person-back")),
currentCamera(camera) {
camera->setFov(glm::radians(90.0f));
spCamera->setFov(glm::radians(90.0f));