Skip to content

Commit c28fbd0

Browse files
sfan5nerzhul
authored andcommittedMay 5, 2020
Fix remaining issues with mapgen scriptapi
1 parent 3c65d1a commit c28fbd0

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed
 

‎src/emerge.h

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class OreManager;
4444
class DecorationManager;
4545
class SchematicManager;
4646
class Server;
47+
class ModApiMapgen;
4748

4849
// Structure containing inputs/outputs for chunk generation
4950
struct BlockMakeData {
@@ -111,6 +112,11 @@ class EmergeParams {
111112
};
112113

113114
class EmergeManager {
115+
/* The mod API needs unchecked access to allow:
116+
* - using decomgr or oremgr to place decos/ores
117+
* - using schemmgr to load and place schematics
118+
*/
119+
friend class ModApiMapgen;
114120
public:
115121
const NodeDefManager *ndef;
116122
bool enable_mapgen_debug_info;

‎src/mapgen/mg_biome.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity
123123

124124

125125
// For BiomeGen type 'BiomeGenOriginal'
126-
Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const
126+
const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat,
127+
float humidity, v3s16 pos) const
127128
{
128129
Biome *biome_closest = nullptr;
129130
Biome *biome_closest_blend = nullptr;

‎src/mapgen/mg_biome.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct BiomeParams {
9090
s32 seed;
9191
};
9292

93+
// WARNING: this class is not thread-safe
9394
class BiomeGen {
9495
public:
9596
virtual ~BiomeGen() = default;
@@ -233,7 +234,8 @@ class BiomeManager : public ObjDefManager {
233234
NoiseParams &np_heat_blend, u64 seed) const;
234235
float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
235236
NoiseParams &np_humidity_blend, u64 seed) const;
236-
Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const;
237+
const Biome *getBiomeFromNoiseOriginal(float heat, float humidity,
238+
v3s16 pos) const;
237239

238240
private:
239241
BiomeManager() {};

‎src/mapgen/mg_schematic.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ bool Schematic::deserializeFromMts(std::istream *is,
359359

360360

361361
bool Schematic::serializeToMts(std::ostream *os,
362-
const std::vector<std::string> &names)
362+
const std::vector<std::string> &names) const
363363
{
364364
std::ostream &ss = *os;
365365

@@ -383,7 +383,8 @@ bool Schematic::serializeToMts(std::ostream *os,
383383

384384

385385
bool Schematic::serializeToLua(std::ostream *os,
386-
const std::vector<std::string> &names, bool use_comments, u32 indent_spaces)
386+
const std::vector<std::string> &names, bool use_comments,
387+
u32 indent_spaces) const
387388
{
388389
std::ostream &ss = *os;
389390

‎src/mapgen/mg_schematic.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ class Schematic : public ObjDef, public NodeResolver {
106106
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
107107

108108
bool deserializeFromMts(std::istream *is, std::vector<std::string> *names);
109-
bool serializeToMts(std::ostream *os, const std::vector<std::string> &names);
109+
bool serializeToMts(std::ostream *os,
110+
const std::vector<std::string> &names) const;
110111
bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
111-
bool use_comments, u32 indent_spaces);
112+
bool use_comments, u32 indent_spaces) const;
112113

113114
void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
114115
bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);

‎src/objdef.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ObjDef {
6666
// WARNING: Ownership of ObjDefs is transferred to the ObjDefManager it is
6767
// added/set to. Note that ObjDefs managed by ObjDefManager are NOT refcounted,
6868
// so the same ObjDef instance must not be referenced multiple
69+
// TODO: const correctness for getter methods
6970
class ObjDefManager {
7071
public:
7172
ObjDefManager(IGameDef *gamedef, ObjDefType type);

‎src/script/lua_api/l_mapgen.cpp

+8-16
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ int ModApiMapgen::l_get_biome_id(lua_State *L)
490490
if (!bmgr)
491491
return 0;
492492

493-
Biome *biome = (Biome *)bmgr->getByName(biome_str);
493+
const Biome *biome = (Biome *)bmgr->getByName(biome_str);
494494
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
495495
return 0;
496496

@@ -512,7 +512,7 @@ int ModApiMapgen::l_get_biome_name(lua_State *L)
512512
if (!bmgr)
513513
return 0;
514514

515-
Biome *b = (Biome *)bmgr->getRaw(biome_id);
515+
const Biome *b = (Biome *)bmgr->getRaw(biome_id);
516516
lua_pushstring(L, b->name.c_str());
517517

518518
return 1;
@@ -551,8 +551,6 @@ int ModApiMapgen::l_get_heat(lua_State *L)
551551
return 0;
552552

553553
float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed);
554-
if (!heat)
555-
return 0;
556554

557555
lua_pushnumber(L, heat);
558556

@@ -593,8 +591,6 @@ int ModApiMapgen::l_get_humidity(lua_State *L)
593591

594592
float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity,
595593
np_humidity_blend, seed);
596-
if (!humidity)
597-
return 0;
598594

599595
lua_pushnumber(L, humidity);
600596

@@ -648,7 +644,7 @@ int ModApiMapgen::l_get_biome_data(lua_State *L)
648644
if (!humidity)
649645
return 0;
650646

651-
Biome *biome = (Biome *)bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos);
647+
const Biome *biome = bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos);
652648
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
653649
return 0;
654650

@@ -1516,8 +1512,7 @@ int ModApiMapgen::l_generate_ores(lua_State *L)
15161512

15171513
u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed);
15181514

1519-
OreManager *oremgr = (OreManager*) emerge->getOreManager(); // FIXME FIXME
1520-
oremgr->placeAllOres(&mg, blockseed, pmin, pmax);
1515+
emerge->oremgr->placeAllOres(&mg, blockseed, pmin, pmax);
15211516

15221517
return 0;
15231518
}
@@ -1543,8 +1538,7 @@ int ModApiMapgen::l_generate_decorations(lua_State *L)
15431538

15441539
u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed);
15451540

1546-
DecorationManager *decomgr = (DecorationManager*) emerge->getDecorationManager(); // FIXME FIXME
1547-
decomgr->placeAllDecos(&mg, blockseed, pmin, pmax);
1541+
emerge->decomgr->placeAllDecos(&mg, blockseed, pmin, pmax);
15481542

15491543
return 0;
15501544
}
@@ -1624,8 +1618,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
16241618
GET_ENV_PTR;
16251619

16261620
ServerMap *map = &(env->getServerMap());
1627-
SchematicManager *schemmgr = (SchematicManager*)
1628-
getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME
1621+
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
16291622

16301623
//// Read position
16311624
v3s16 p = check_v3s16(L, 1);
@@ -1670,8 +1663,7 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L)
16701663
{
16711664
NO_MAP_LOCK_REQUIRED;
16721665

1673-
SchematicManager *schemmgr = (SchematicManager*)
1674-
getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME
1666+
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
16751667

16761668
//// Read VoxelManip object
16771669
MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm;
@@ -1727,7 +1719,7 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L)
17271719

17281720
//// Get schematic
17291721
bool was_loaded = false;
1730-
Schematic *schem = (Schematic *)get_objdef(L, 1, schemmgr);
1722+
const Schematic *schem = (Schematic *)get_objdef(L, 1, schemmgr);
17311723
if (!schem) {
17321724
schem = load_schematic(L, 1, NULL, NULL);
17331725
was_loaded = true;

0 commit comments

Comments
 (0)
Please sign in to comment.