Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Oct 24, 2024
1 parent 80e724c commit 4121899
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/client/fm_far_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.

#include "client/clientmap.h"
#include "constants.h"
#include "debug/iostream_debug_helpers.h"
#include "irr_v3d.h"
#include "irrlichttypes.h"

Expand Down
32 changes: 28 additions & 4 deletions src/client/fm_farmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
*/
#include <array>
#include <cstddef>
#include <cstdint>
#include <unordered_set>
#include <utility>

#include "fm_farmesh.h"
Expand All @@ -30,6 +33,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "constants.h"
#include "emerge.h"
#include "irr_v3d.h"
#include "irrlichttypes.h"
#include "mapblock.h"
#include "mapgen/mapgen.h"
#include "mapnode.h"
Expand Down Expand Up @@ -274,14 +278,34 @@ int FarMesh::go_flat()

const auto cbpos = getNodeBlockPos(m_camera_pos_aligned);

std::array<std::unordered_set<v3bpos_t>, FARMESH_STEP_MAX> blocks;
runFarAll(draw_control, cbpos, draw_control.cell_size_pow, 1,
[this, &draw_control](const v3bpos_t &bpos, const bpos_t &size) -> bool {
const auto stp = int(log(size) / log(2)) - draw_control.cell_size_pow;
// DUMP(bpos, size, stp);
makeFarBlocks(bpos, stp);
[this, &draw_control, &blocks](
const v3bpos_t &bpos, const bpos_t &size) -> bool {
for (const auto &add : {
v2bpos_t(0, 0), v2bpos_t(0, size - 1), v2bpos_t(size - 1, 0),
v2bpos_t(size - 1, size - 1), v2bpos_t(size >> 1, size >> 1),
}) {
v3bpos_t bpos_new(bpos.X + add.X, 0, bpos.Z + add.Y);

bpos_new.Y = mg->getGroundLevelAtPoint(
v2pos_t((bpos_new.X << MAP_BLOCKP) - 1,
(bpos_new.Z << MAP_BLOCKP) - 1)) >>
MAP_BLOCKP;

auto step_new = getFarStep(draw_control,
getNodeBlockPos(m_camera_pos_aligned), bpos_new);
blocks[step_new].emplace(bpos_new);
}
return false;
});

for (size_t step = 0; step < blocks.size(); ++step) {
for (const auto &bpos : blocks[step]) {
makeFarBlocks(bpos, step);
}
}

return last_range;
}

Expand Down
10 changes: 7 additions & 3 deletions src/mapgen/mapgen_earth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ MapgenEarth::MapgenEarth(MapgenEarthParams *params_, EmergeParams *emerge) :
scale = {params["scale"]["x"].asDouble(), params["scale"]["y"].asDouble(),
params["scale"]["z"].asDouble()};

/* todomake test
/* todomake test
static bool shown = 0;
if (!shown) {
shown = true;
Expand All @@ -168,7 +168,7 @@ MapgenEarth::MapgenEarth(MapgenEarthParams *params_, EmergeParams *emerge) :
}
}
*/
/*
/*
hgt_reader.debug = 1;
std::vector<std::pair<int, int>> a{
{0, 0}, {-30000, -30000}, {-30000, 30000}, {30000, -30000}, {30000, 30000}};
Expand Down Expand Up @@ -270,6 +270,11 @@ int MapgenEarth::getSpawnLevelAtPoint(v2pos_t p)
return std::max(2, get_height(p.X, p.Y) + 2);
}

int MapgenEarth::getGroundLevelAtPoint(v2pos_t p)
{
return get_height(p.X, p.Y); // + MGV6_AVERAGE_MUD_AMOUNT;
}

// https://www.roguebasin.com/index.php?title=Bresenham%27s_Line_Algorithm
void MapgenEarth::bresenham(pos_t x1, pos_t y1, const pos_t x2, const pos_t y2, pos_t y,
pos_t h, const MapNode &n)
Expand Down Expand Up @@ -371,5 +376,4 @@ void MapgenEarth::generateBuildings()

if (handler)
handler->apply();

}
1 change: 1 addition & 0 deletions src/mapgen/mapgen_earth.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class MapgenEarth : public MapgenV7
int generateTerrain() override;
void generateBuildings() override;
int getSpawnLevelAtPoint(v2pos_t p) override;
int getGroundLevelAtPoint(v2pos_t p) override;

v3d scale{1, 1, 1};
v3d center{0, 0, 0};
Expand Down

0 comments on commit 4121899

Please sign in to comment.