From: Elias Fleckenstein Date: Fri, 14 Aug 2020 12:15:04 +0000 (+0200) Subject: Trees; Random Seed X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=1c962efa0a383bbbe4370cafe22c825c895065dc;p=dragonblocks3d-lua.git Trees; Random Seed --- diff --git a/modules/Client/src/graphics.lua b/modules/Client/src/graphics.lua index 9f41267..a56074b 100644 --- a/modules/Client/src/graphics.lua +++ b/modules/Client/src/graphics.lua @@ -10,7 +10,7 @@ function graphics:init() RenderEngine.mesh_effect_grow_time = 0.25 RenderEngine.mesh_effect_flyin_time = 0.5 RenderEngine.mesh_effect_flyin_offset = 20 - --RenderEngine.mesh_effect_rotate_speed = + RenderEngine.mesh_effect_rotate_speed = 1 RenderEngine:set_wireframe(false) diff --git a/modules/Client/src/init.lua b/modules/Client/src/init.lua index 067b041..c368a2d 100644 --- a/modules/Client/src/init.lua +++ b/modules/Client/src/init.lua @@ -13,3 +13,6 @@ Dragonblocks:add_task(function() coroutine.yield("FPS:" .. math.floor(Dragonblocks.tps or 0)) until false end) + + +RenderEngine:render_loop(true) diff --git a/modules/Game/ressources/dirt.png b/modules/Game/ressources/dirt.png index 5cc6e86..617d353 100644 Binary files a/modules/Game/ressources/dirt.png and b/modules/Game/ressources/dirt.png differ diff --git a/modules/Game/ressources/grass.png b/modules/Game/ressources/grass.png new file mode 100644 index 0000000..273d7c6 Binary files /dev/null and b/modules/Game/ressources/grass.png differ diff --git a/modules/Game/ressources/leaves.png b/modules/Game/ressources/leaves.png new file mode 100644 index 0000000..33ac473 Binary files /dev/null and b/modules/Game/ressources/leaves.png differ diff --git a/modules/Game/ressources/old/dirt.png b/modules/Game/ressources/old/dirt.png new file mode 100644 index 0000000..5cc6e86 Binary files /dev/null and b/modules/Game/ressources/old/dirt.png differ diff --git a/modules/Game/ressources/old/grass.png b/modules/Game/ressources/old/grass.png new file mode 100644 index 0000000..e522a90 Binary files /dev/null and b/modules/Game/ressources/old/grass.png differ diff --git a/modules/Game/ressources/old/leaves.png b/modules/Game/ressources/old/leaves.png new file mode 100644 index 0000000..02b6cf0 Binary files /dev/null and b/modules/Game/ressources/old/leaves.png differ diff --git a/modules/Game/ressources/old/stone.png b/modules/Game/ressources/old/stone.png new file mode 100644 index 0000000..a641ceb Binary files /dev/null and b/modules/Game/ressources/old/stone.png differ diff --git a/modules/Game/ressources/old/tree.png b/modules/Game/ressources/old/tree.png new file mode 100644 index 0000000..d0b26b8 Binary files /dev/null and b/modules/Game/ressources/old/tree.png differ diff --git a/modules/Game/ressources/stone.png b/modules/Game/ressources/stone.png index a641ceb..87e19ff 100644 Binary files a/modules/Game/ressources/stone.png and b/modules/Game/ressources/stone.png differ diff --git a/modules/Game/ressources/tree.png b/modules/Game/ressources/tree.png new file mode 100644 index 0000000..914cb5f Binary files /dev/null and b/modules/Game/ressources/tree.png differ diff --git a/modules/Game/src/init.lua b/modules/Game/src/init.lua index 707ce0d..061eace 100644 --- a/modules/Game/src/init.lua +++ b/modules/Game/src/init.lua @@ -1,11 +1,26 @@ -local ressource_path = Game:get_path() .. "/ressources/" +local ressource_path = Game:get_path() .. "/ressources" BlockSystem:register_block({ name = "game:stone", - texture_path = ressource_path .. "stone.png", + texture_path = ressource_path .. "/stone.png", }) BlockSystem:register_block({ name = "game:dirt", - texture_path = ressource_path .. "dirt.png", + texture_path = ressource_path .. "/dirt.png", +}) + +BlockSystem:register_block({ + name = "game:grass", + texture_path = ressource_path .. "/grass.png", +}) + +BlockSystem:register_block({ + name = "game:tree", + texture_path = ressource_path .. "/tree.png", +}) + +BlockSystem:register_block({ + name = "game:leaves", + texture_path = ressource_path .. "/leaves.png", }) diff --git a/modules/MapGen/src/init.lua b/modules/MapGen/src/init.lua index 86f4087..5d2c4cb 100644 --- a/modules/MapGen/src/init.lua +++ b/modules/MapGen/src/init.lua @@ -1,19 +1,88 @@ local stone = BlockSystem:get_def("game:stone") local dirt = BlockSystem:get_def("game:dirt") +local grass = BlockSystem:get_def("game:grass") +local leaves = BlockSystem:get_def("game:leaves") +local tree = BlockSystem:get_def("game:tree") -local air_probability = 2 -local random_blocks = {stone, dirt} -local random_blocks_num = #random_blocks + air_probability +math.randomseed(os.time()) function MapGen:generate(chunk) + local grass_layer_table, old_grass_layer_table + local grass_layer for x = 0, 15 do - for y = 0, 15 do - for z = 0, 15 do - local block = random_blocks[math.random(random_blocks_num)] - if block then - chunk:add_block(glm.vec3(x, y, z), block) + grass_layer_table, old_grass_layer_table = {}, grass_layer_table + grass_layer = old_grass_layer_table and old_grass_layer_table[1] or 8 + math.random(5) + for z = 0, 15 do + local old_grass_layer = old_grass_layer_table and old_grass_layer_table[z] or grass_layer + grass_layer = math.floor((grass_layer + old_grass_layer) / 2) + if math.random(3) == 1 then + grass_layer = grass_layer + math.random(3) - 2 + end + grass_layer = glm.clamp(grass_layer, 0, 15) + grass_layer_table[z] = grass_layer + if math.random(25) == 1 then + chunk:add_block(glm.vec3(x, grass_layer, z), dirt) + self:add_tree(chunk, glm.vec3(x, grass_layer + 1, z)) + else + chunk:add_block(glm.vec3(x, grass_layer, z), grass) + end + local dirt_start, dirt_end = grass_layer - 1, math.max(grass_layer - 5, 0) + local stone_start, stone_end = grass_layer - 6, 0 + if dirt_start >= 0 then + for y = dirt_start, dirt_end, -1 do + chunk:add_block(glm.vec3(x, y, z), dirt) end end + if stone_start >= 0 then + for y = stone_start, stone_end, -1 do + chunk:add_block(glm.vec3(x, y, z), stone) + end + end + end + end +end + +local tree_blocks = { + glm.vec3( 0, 0, 0), + glm.vec3( 0, 1, 0), + glm.vec3(-1, 2, -1), + glm.vec3(-1, 2, 0), + glm.vec3(-1, 2, 1), + glm.vec3( 0, 2, -1), + glm.vec3( 0, 2, 0), + glm.vec3( 0, 2, 1), + glm.vec3( 1, 2, -1), + glm.vec3( 1, 2, 0), + glm.vec3( 1, 2, 1), + glm.vec3(-1, 3, -1), + glm.vec3(-1, 3, 0), + glm.vec3(-1, 3, 1), + glm.vec3( 0, 3, -1), + glm.vec3( 0, 3, 0), + glm.vec3( 0, 3, 1), + glm.vec3( 1, 3, -1), + glm.vec3( 1, 3, 0), + glm.vec3( 1, 3, 1), + glm.vec3(-1, 4, -1), + glm.vec3(-1, 4, 0), + glm.vec3(-1, 4, 1), + glm.vec3( 0, 4, -1), + glm.vec3( 0, 4, 0), + glm.vec3( 0, 4, 1), + glm.vec3( 1, 4, -1), + glm.vec3( 1, 4, 0), + glm.vec3( 1, 4, 1), +} + +function MapGen:add_tree(chunk, tree_pos) + for i, p in ipairs(tree_blocks) do + local block = leaves + if i < 3 then + block = tree + end + local pos = tree_pos + p + if chunk:get_pos_hash(pos) then + chunk:add_block(pos, block) end end end diff --git a/modules/RenderEngine/src/mesh.lua b/modules/RenderEngine/src/mesh.lua index 94c2a57..3ebb4e5 100644 --- a/modules/RenderEngine/src/mesh.lua +++ b/modules/RenderEngine/src/mesh.lua @@ -67,7 +67,7 @@ function Mesh:apply_vertices(vertices) end function Mesh:render(dtime) - local pos, size = self.pos, self.size + local pos, size, rotation = self.pos, self.size, 0 if self.effect then if self.effect_lasts then @@ -86,6 +86,8 @@ function Mesh:render(dtime) size = size * math.pow(1 - self.effect_lasts / RenderEngine.mesh_effect_grow_time, 1) elseif self.effect == Mesh.EFFECT_FLYIN then pos = pos - glm.vec3(0, RenderEngine.mesh_effect_flyin_offset * self.effect_lasts / RenderEngine.mesh_effect_flyin_time, 0) + elseif self.effect == Mesh.EFFECT_ROTATE then + rotation = glfw.get_time() * RenderEngine.mesh_effect_rotate_speed * math.pi * 2 end end @@ -93,6 +95,7 @@ function Mesh:render(dtime) local model_matrix = 1 * glm.translate(pos) + * glm.rotate(rotation, glm.vec3(0, 1, 0)) * glm.scale(size) gl.uniform_matrix4f(gl.get_uniform_location(RenderEngine.shaders, "model"), true, model_matrix)