mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-30 19:22:14 +00:00
Make mapgen chunk size a v3s16 internally
This commit is contained in:
parent
c413ed298e
commit
0deeb57d44
7 changed files with 62 additions and 35 deletions
|
@ -190,7 +190,7 @@ void EmergeManager::initMapgens(MapgenParams *params)
|
||||||
|
|
||||||
mgparams = params;
|
mgparams = params;
|
||||||
|
|
||||||
v3s16 csize = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE);
|
v3s16 csize = params->chunksize * MAP_BLOCKSIZE;
|
||||||
biomegen = biomemgr->createBiomeGen(BIOMEGEN_ORIGINAL, params->bparams, csize);
|
biomegen = biomemgr->createBiomeGen(BIOMEGEN_ORIGINAL, params->bparams, csize);
|
||||||
|
|
||||||
for (u32 i = 0; i != m_threads.size(); i++) {
|
for (u32 i = 0; i != m_threads.size(); i++) {
|
||||||
|
@ -319,11 +319,9 @@ bool EmergeManager::isBlockInQueue(v3s16 pos)
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
// TODO(hmmmm): Move this to ServerMap
|
v3s16 EmergeManager::getContainingChunk(v3s16 blockpos, v3s16 chunksize)
|
||||||
v3s16 EmergeManager::getContainingChunk(v3s16 blockpos, s16 chunksize)
|
|
||||||
{
|
{
|
||||||
s16 coff = -chunksize / 2;
|
v3s16 chunk_offset = -chunksize / 2;
|
||||||
v3s16 chunk_offset(coff, coff, coff);
|
|
||||||
|
|
||||||
return getContainerPos(blockpos - chunk_offset, chunksize)
|
return getContainerPos(blockpos - chunk_offset, chunksize)
|
||||||
* chunksize + chunk_offset;
|
* chunksize + chunk_offset;
|
||||||
|
|
|
@ -189,7 +189,8 @@ public:
|
||||||
int getSpawnLevelAtPoint(v2s16 p);
|
int getSpawnLevelAtPoint(v2s16 p);
|
||||||
bool isBlockUnderground(v3s16 blockpos);
|
bool isBlockUnderground(v3s16 blockpos);
|
||||||
|
|
||||||
static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
|
/// @return min edge of chunk in block units
|
||||||
|
static v3s16 getContainingChunk(v3s16 blockpos, v3s16 chunksize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Mapgen *> m_mapgens;
|
std::vector<Mapgen *> m_mapgens;
|
||||||
|
|
|
@ -100,7 +100,7 @@ Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge) :
|
||||||
water_level = params->water_level;
|
water_level = params->water_level;
|
||||||
mapgen_limit = params->mapgen_limit;
|
mapgen_limit = params->mapgen_limit;
|
||||||
flags = params->flags;
|
flags = params->flags;
|
||||||
csize = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE);
|
csize = params->chunksize * MAP_BLOCKSIZE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We are losing half our entropy by doing this, but it is necessary to
|
We are losing half our entropy by doing this, but it is necessary to
|
||||||
|
@ -1071,10 +1071,11 @@ void MapgenParams::readParams(const Settings *settings)
|
||||||
|
|
||||||
settings->getS16NoEx("water_level", water_level);
|
settings->getS16NoEx("water_level", water_level);
|
||||||
settings->getS16NoEx("mapgen_limit", mapgen_limit);
|
settings->getS16NoEx("mapgen_limit", mapgen_limit);
|
||||||
settings->getS16NoEx("chunksize", chunksize);
|
|
||||||
settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
|
settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
|
||||||
|
|
||||||
chunksize = rangelim(chunksize, 1, 10);
|
s16 tmp;
|
||||||
|
settings->getS16NoEx("chunksize", tmp);
|
||||||
|
chunksize = v3s16(rangelim(tmp, 1, 24));
|
||||||
|
|
||||||
delete bparams;
|
delete bparams;
|
||||||
bparams = BiomeManager::createBiomeParams(BIOMEGEN_ORIGINAL);
|
bparams = BiomeManager::createBiomeParams(BIOMEGEN_ORIGINAL);
|
||||||
|
@ -1091,7 +1092,7 @@ void MapgenParams::writeParams(Settings *settings) const
|
||||||
settings->setU64("seed", seed);
|
settings->setU64("seed", seed);
|
||||||
settings->setS16("water_level", water_level);
|
settings->setS16("water_level", water_level);
|
||||||
settings->setS16("mapgen_limit", mapgen_limit);
|
settings->setS16("mapgen_limit", mapgen_limit);
|
||||||
settings->setS16("chunksize", chunksize);
|
settings->setS16("chunksize", chunksize.X); // TODO
|
||||||
settings->setFlagStr("mg_flags", flags, flagdesc_mapgen);
|
settings->setFlagStr("mg_flags", flags, flagdesc_mapgen);
|
||||||
|
|
||||||
if (bparams)
|
if (bparams)
|
||||||
|
@ -1106,12 +1107,15 @@ s32 MapgenParams::getSpawnRangeMax()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize)
|
std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, v3s16 chunksize)
|
||||||
{
|
{
|
||||||
|
// FIXME: this is no longer exact
|
||||||
|
const s16 cs = std::max(std::max(chunksize.X, chunksize.Y), chunksize.Z);
|
||||||
|
|
||||||
// Central chunk offset, in blocks
|
// Central chunk offset, in blocks
|
||||||
s16 ccoff_b = -chunksize / 2;
|
s16 ccoff_b = -cs / 2;
|
||||||
// Chunksize, in nodes
|
// Chunksize, in nodes
|
||||||
s32 csize_n = chunksize * MAP_BLOCKSIZE;
|
s32 csize_n = cs * MAP_BLOCKSIZE;
|
||||||
// Minp/maxp of central chunk, in nodes
|
// Minp/maxp of central chunk, in nodes
|
||||||
s16 ccmin = ccoff_b * MAP_BLOCKSIZE;
|
s16 ccmin = ccoff_b * MAP_BLOCKSIZE;
|
||||||
s16 ccmax = ccmin + csize_n - 1;
|
s16 ccmax = ccmin + csize_n - 1;
|
||||||
|
@ -1127,8 +1131,8 @@ std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize)
|
||||||
s16 mapgen_limit_max = (mapgen_limit_b + 1) * MAP_BLOCKSIZE - 1;
|
s16 mapgen_limit_max = (mapgen_limit_b + 1) * MAP_BLOCKSIZE - 1;
|
||||||
// Number of complete chunks from central chunk fullminp/fullmaxp
|
// Number of complete chunks from central chunk fullminp/fullmaxp
|
||||||
// to effective mapgen limits.
|
// to effective mapgen limits.
|
||||||
s16 numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0);
|
s16 numcmin = std::max((ccfmin - mapgen_limit_min) / csize_n, 0);
|
||||||
s16 numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0);
|
s16 numcmax = std::max((mapgen_limit_max - ccfmax) / csize_n, 0);
|
||||||
// Mapgen edges, in nodes
|
// Mapgen edges, in nodes
|
||||||
return std::pair<s16, s16>(ccmin - numcmin * csize_n, ccmax + numcmax * csize_n);
|
return {ccmin - numcmin * csize_n, ccmax + numcmax * csize_n};
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ struct MapgenParams {
|
||||||
virtual ~MapgenParams();
|
virtual ~MapgenParams();
|
||||||
|
|
||||||
MapgenType mgtype = MAPGEN_DEFAULT;
|
MapgenType mgtype = MAPGEN_DEFAULT;
|
||||||
s16 chunksize = 5;
|
v3s16 chunksize = v3s16(5);
|
||||||
u64 seed = 0;
|
u64 seed = 0;
|
||||||
s16 water_level = 1;
|
s16 water_level = 1;
|
||||||
s16 mapgen_limit = MAX_MAP_GENERATION_LIMIT;
|
s16 mapgen_limit = MAX_MAP_GENERATION_LIMIT;
|
||||||
|
@ -322,4 +322,4 @@ protected:
|
||||||
|
|
||||||
// Calculate exact edges of the outermost mapchunks that are within the set
|
// Calculate exact edges of the outermost mapchunks that are within the set
|
||||||
// mapgen_limit. Returns the minimum and maximum edges in nodes in that order.
|
// mapgen_limit. Returns the minimum and maximum edges in nodes in that order.
|
||||||
std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize);
|
std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, v3s16 chunksize);
|
||||||
|
|
|
@ -849,23 +849,20 @@ int ModApiMapgen::l_get_mapgen_edges(lua_State *L)
|
||||||
// MapSettingsManager::makeMapgenParams cannot be used here because it would
|
// MapSettingsManager::makeMapgenParams cannot be used here because it would
|
||||||
// make mapgen settings immutable from then on. Mapgen settings should stay
|
// make mapgen settings immutable from then on. Mapgen settings should stay
|
||||||
// mutable until after mod loading ends.
|
// mutable until after mod loading ends.
|
||||||
|
std::unique_ptr<MapgenParams> params(settingsmgr->makeMapgenParamsCopy());
|
||||||
|
|
||||||
s16 mapgen_limit;
|
s16 mapgen_limit;
|
||||||
if (lua_isnumber(L, 1)) {
|
if (lua_isnumber(L, 1)) {
|
||||||
mapgen_limit = lua_tointeger(L, 1);
|
mapgen_limit = lua_tointeger(L, 1);
|
||||||
} else {
|
} else {
|
||||||
std::string mapgen_limit_str;
|
mapgen_limit = params->mapgen_limit;
|
||||||
settingsmgr->getMapSetting("mapgen_limit", &mapgen_limit_str);
|
|
||||||
mapgen_limit = stoi(mapgen_limit_str, 0, MAX_MAP_GENERATION_LIMIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s16 chunksize;
|
v3s16 chunksize;
|
||||||
if (lua_isnumber(L, 2)) {
|
if (lua_isnumber(L, 2)) {
|
||||||
chunksize = lua_tointeger(L, 2);
|
chunksize = v3s16(lua_tointeger(L, 2));
|
||||||
} else {
|
} else {
|
||||||
std::string chunksize_str;
|
chunksize = params->chunksize;
|
||||||
settingsmgr->getMapSetting("chunksize", &chunksize_str);
|
|
||||||
chunksize = stoi(chunksize_str, 1, 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<s16, s16> edges = get_mapgen_edges(mapgen_limit, chunksize);
|
std::pair<s16, s16> edges = get_mapgen_edges(mapgen_limit, chunksize);
|
||||||
|
@ -884,12 +881,9 @@ int ModApiMapgen::l_get_mapgen_chunksize(lua_State *L)
|
||||||
// MapSettingsManager::makeMapgenParams cannot be used here because it would
|
// MapSettingsManager::makeMapgenParams cannot be used here because it would
|
||||||
// make mapgen settings immutable from then on. Mapgen settings should stay
|
// make mapgen settings immutable from then on. Mapgen settings should stay
|
||||||
// mutable until after mod loading ends.
|
// mutable until after mod loading ends.
|
||||||
|
std::unique_ptr<MapgenParams> params(settingsmgr->makeMapgenParamsCopy());
|
||||||
|
|
||||||
std::string chunksize_str;
|
push_v3s16(L, params->chunksize);
|
||||||
settingsmgr->getMapSetting("chunksize", &chunksize_str);
|
|
||||||
s16 chunksize = stoi(chunksize_str, 1, 10);
|
|
||||||
|
|
||||||
push_v3s16(L, {chunksize, chunksize, chunksize});
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,9 +200,9 @@ bool ServerMap::blockpos_over_mapgen_limit(v3s16 p)
|
||||||
bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data)
|
bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data)
|
||||||
{
|
{
|
||||||
assert(data);
|
assert(data);
|
||||||
s16 csize = getMapgenParams()->chunksize;
|
const v3s16 csize = getMapgenParams()->chunksize;
|
||||||
const v3s16 bpmin = EmergeManager::getContainingChunk(blockpos, csize);
|
const v3s16 bpmin = EmergeManager::getContainingChunk(blockpos, csize);
|
||||||
const v3s16 bpmax = bpmin + v3s16(1, 1, 1) * (csize - 1);
|
const v3s16 bpmax = bpmin + csize - v3s16(1);
|
||||||
|
|
||||||
if (!m_chunks_in_progress.insert(bpmin).second)
|
if (!m_chunks_in_progress.insert(bpmin).second)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
#include "noise.h"
|
#include "noise.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "mapgen/mapgen_v5.h"
|
#include "mapgen/mapgen_v5.h"
|
||||||
|
#include "emerge.h"
|
||||||
#include "util/hashing.h"
|
#include "util/hashing.h"
|
||||||
|
#include "irrlicht_changes/printing.h"
|
||||||
#include "map_settings_manager.h"
|
#include "map_settings_manager.h"
|
||||||
|
|
||||||
class TestMapSettingsManager : public TestBase {
|
class TestMapSettingsManager : public TestBase {
|
||||||
|
@ -23,6 +25,7 @@ public:
|
||||||
void testMapSettingsManager();
|
void testMapSettingsManager();
|
||||||
void testMapMetaSaveLoad();
|
void testMapMetaSaveLoad();
|
||||||
void testMapMetaFailures();
|
void testMapMetaFailures();
|
||||||
|
void testChunks();
|
||||||
};
|
};
|
||||||
|
|
||||||
static TestMapSettingsManager g_test_instance;
|
static TestMapSettingsManager g_test_instance;
|
||||||
|
@ -32,6 +35,7 @@ void TestMapSettingsManager::runTests(IGameDef *gamedef)
|
||||||
TEST(testMapSettingsManager);
|
TEST(testMapSettingsManager);
|
||||||
TEST(testMapMetaSaveLoad);
|
TEST(testMapMetaSaveLoad);
|
||||||
TEST(testMapMetaFailures);
|
TEST(testMapMetaFailures);
|
||||||
|
TEST(testChunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -141,7 +145,7 @@ void TestMapSettingsManager::testMapSettingsManager()
|
||||||
// Now make our Params and see if the values are correctly sourced
|
// Now make our Params and see if the values are correctly sourced
|
||||||
MapgenParams *params = mgr.makeMapgenParams();
|
MapgenParams *params = mgr.makeMapgenParams();
|
||||||
UASSERT(params->mgtype == MAPGEN_V5);
|
UASSERT(params->mgtype == MAPGEN_V5);
|
||||||
UASSERT(params->chunksize == 5);
|
UASSERT(params->chunksize == v3s16(5));
|
||||||
UASSERT(params->water_level == 15);
|
UASSERT(params->water_level == 15);
|
||||||
UASSERT(params->seed == 1234);
|
UASSERT(params->seed == 1234);
|
||||||
UASSERT((params->flags & MG_LIGHT) == 0);
|
UASSERT((params->flags & MG_LIGHT) == 0);
|
||||||
|
@ -246,3 +250,29 @@ void TestMapSettingsManager::testMapMetaFailures()
|
||||||
UASSERT(!mgr2.loadMapMeta());
|
UASSERT(!mgr2.loadMapMeta());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestMapSettingsManager::testChunks()
|
||||||
|
{
|
||||||
|
v3s16 csize(5);
|
||||||
|
|
||||||
|
#define GET(x) EmergeManager::getContainingChunk(x, csize)
|
||||||
|
// origin chunk goes from (-2, -2, -2) -> (3, 3, 3) excl
|
||||||
|
UASSERTEQ(auto, GET(v3s16(-2, -2, -2)), v3s16(-2, -2, -2));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(0, 0, 0)), v3s16(-2, -2, -2));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(1, 1, 1)), v3s16(-2, -2, -2));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(2, 2, 2)), v3s16(-2, -2, -2));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(2, 3, 2)), v3s16(-2, 3, -2));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(0, -3, 0)), v3s16(-2, -7, -2));
|
||||||
|
|
||||||
|
csize = v3s16(5, 2, 5);
|
||||||
|
UASSERTEQ(auto, GET(v3s16(0, 0, 0)), v3s16(-2, -1, -2));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(0, 1, 0)), v3s16(-2, 1, -2));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(3, 3, 3)), v3s16(3, 3, 3));
|
||||||
|
|
||||||
|
csize = v3s16(1);
|
||||||
|
UASSERTEQ(auto, GET(v3s16(1, 2, 3)), v3s16(1, 2, 3));
|
||||||
|
UASSERTEQ(auto, GET(v3s16(-3, -2, -1)), v3s16(-3, -2, -1));
|
||||||
|
|
||||||
|
#undef GET
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue