aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-04-10 02:43:49 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2020-05-05 19:26:59 +0200
commitc28fbd06a8bfafc9691a92c90f0cf10ec94cd314 (patch)
tree09c2dcd20ff76356bb58f055b6877f7d9d3915cd
parent3c65d1acec27366d88fc3686d3f820175673e203 (diff)
downloadminetest-c28fbd06a8bfafc9691a92c90f0cf10ec94cd314.tar.gz
minetest-c28fbd06a8bfafc9691a92c90f0cf10ec94cd314.tar.bz2
minetest-c28fbd06a8bfafc9691a92c90f0cf10ec94cd314.zip
Fix remaining issues with mapgen scriptapi
-rw-r--r--src/emerge.h6
-rw-r--r--src/mapgen/mg_biome.cpp3
-rw-r--r--src/mapgen/mg_biome.h4
-rw-r--r--src/mapgen/mg_schematic.cpp5
-rw-r--r--src/mapgen/mg_schematic.h5
-rw-r--r--src/objdef.h1
-rw-r--r--src/script/lua_api/l_mapgen.cpp24
7 files changed, 26 insertions, 22 deletions
diff --git a/src/emerge.h b/src/emerge.h
index ab9fca2ba..6f204666d 100644
--- a/src/emerge.h
+++ b/src/emerge.h
@@ -44,6 +44,7 @@ class OreManager;
class DecorationManager;
class SchematicManager;
class Server;
+class ModApiMapgen;
// Structure containing inputs/outputs for chunk generation
struct BlockMakeData {
@@ -111,6 +112,11 @@ private:
};
class EmergeManager {
+ /* The mod API needs unchecked access to allow:
+ * - using decomgr or oremgr to place decos/ores
+ * - using schemmgr to load and place schematics
+ */
+ friend class ModApiMapgen;
public:
const NodeDefManager *ndef;
bool enable_mapgen_debug_info;
diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp
index f3bc4e829..8c59ac9e6 100644
--- a/src/mapgen/mg_biome.cpp
+++ b/src/mapgen/mg_biome.cpp
@@ -123,7 +123,8 @@ float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity
// For BiomeGen type 'BiomeGenOriginal'
-Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const
+const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat,
+ float humidity, v3s16 pos) const
{
Biome *biome_closest = nullptr;
Biome *biome_closest_blend = nullptr;
diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h
index 0a4471cc3..57f4aa20d 100644
--- a/src/mapgen/mg_biome.h
+++ b/src/mapgen/mg_biome.h
@@ -90,6 +90,7 @@ struct BiomeParams {
s32 seed;
};
+// WARNING: this class is not thread-safe
class BiomeGen {
public:
virtual ~BiomeGen() = default;
@@ -233,7 +234,8 @@ public:
NoiseParams &np_heat_blend, u64 seed) const;
float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity,
NoiseParams &np_humidity_blend, u64 seed) const;
- Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const;
+ const Biome *getBiomeFromNoiseOriginal(float heat, float humidity,
+ v3s16 pos) const;
private:
BiomeManager() {};
diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp
index c3bd89f3a..ba102d997 100644
--- a/src/mapgen/mg_schematic.cpp
+++ b/src/mapgen/mg_schematic.cpp
@@ -359,7 +359,7 @@ bool Schematic::deserializeFromMts(std::istream *is,
bool Schematic::serializeToMts(std::ostream *os,
- const std::vector<std::string> &names)
+ const std::vector<std::string> &names) const
{
std::ostream &ss = *os;
@@ -383,7 +383,8 @@ bool Schematic::serializeToMts(std::ostream *os,
bool Schematic::serializeToLua(std::ostream *os,
- const std::vector<std::string> &names, bool use_comments, u32 indent_spaces)
+ const std::vector<std::string> &names, bool use_comments,
+ u32 indent_spaces) const
{
std::ostream &ss = *os;
diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h
index 3222085e6..6b31251b6 100644
--- a/src/mapgen/mg_schematic.h
+++ b/src/mapgen/mg_schematic.h
@@ -106,9 +106,10 @@ public:
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
bool deserializeFromMts(std::istream *is, std::vector<std::string> *names);
- bool serializeToMts(std::ostream *os, const std::vector<std::string> &names);
+ bool serializeToMts(std::ostream *os,
+ const std::vector<std::string> &names) const;
bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
- bool use_comments, u32 indent_spaces);
+ bool use_comments, u32 indent_spaces) const;
void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place);
bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place);
diff --git a/src/objdef.h b/src/objdef.h
index 20565029c..e40324a88 100644
--- a/src/objdef.h
+++ b/src/objdef.h
@@ -66,6 +66,7 @@ protected:
// WARNING: Ownership of ObjDefs is transferred to the ObjDefManager it is
// added/set to. Note that ObjDefs managed by ObjDefManager are NOT refcounted,
// so the same ObjDef instance must not be referenced multiple
+// TODO: const correctness for getter methods
class ObjDefManager {
public:
ObjDefManager(IGameDef *gamedef, ObjDefType type);
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index ba0304be3..584085428 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -490,7 +490,7 @@ int ModApiMapgen::l_get_biome_id(lua_State *L)
if (!bmgr)
return 0;
- Biome *biome = (Biome *)bmgr->getByName(biome_str);
+ const Biome *biome = (Biome *)bmgr->getByName(biome_str);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;
@@ -512,7 +512,7 @@ int ModApiMapgen::l_get_biome_name(lua_State *L)
if (!bmgr)
return 0;
- Biome *b = (Biome *)bmgr->getRaw(biome_id);
+ const Biome *b = (Biome *)bmgr->getRaw(biome_id);
lua_pushstring(L, b->name.c_str());
return 1;
@@ -551,8 +551,6 @@ int ModApiMapgen::l_get_heat(lua_State *L)
return 0;
float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed);
- if (!heat)
- return 0;
lua_pushnumber(L, heat);
@@ -593,8 +591,6 @@ int ModApiMapgen::l_get_humidity(lua_State *L)
float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity,
np_humidity_blend, seed);
- if (!humidity)
- return 0;
lua_pushnumber(L, humidity);
@@ -648,7 +644,7 @@ int ModApiMapgen::l_get_biome_data(lua_State *L)
if (!humidity)
return 0;
- Biome *biome = (Biome *)bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos);
+ const Biome *biome = bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;
@@ -1516,8 +1512,7 @@ int ModApiMapgen::l_generate_ores(lua_State *L)
u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed);
- OreManager *oremgr = (OreManager*) emerge->getOreManager(); // FIXME FIXME
- oremgr->placeAllOres(&mg, blockseed, pmin, pmax);
+ emerge->oremgr->placeAllOres(&mg, blockseed, pmin, pmax);
return 0;
}
@@ -1543,8 +1538,7 @@ int ModApiMapgen::l_generate_decorations(lua_State *L)
u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed);
- DecorationManager *decomgr = (DecorationManager*) emerge->getDecorationManager(); // FIXME FIXME
- decomgr->placeAllDecos(&mg, blockseed, pmin, pmax);
+ emerge->decomgr->placeAllDecos(&mg, blockseed, pmin, pmax);
return 0;
}
@@ -1624,8 +1618,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
GET_ENV_PTR;
ServerMap *map = &(env->getServerMap());
- SchematicManager *schemmgr = (SchematicManager*)
- getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME
+ SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
//// Read position
v3s16 p = check_v3s16(L, 1);
@@ -1670,8 +1663,7 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- SchematicManager *schemmgr = (SchematicManager*)
- getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME
+ SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
//// Read VoxelManip object
MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm;
@@ -1727,7 +1719,7 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L)
//// Get schematic
bool was_loaded = false;
- Schematic *schem = (Schematic *)get_objdef(L, 1, schemmgr);
+ const Schematic *schem = (Schematic *)get_objdef(L, 1, schemmgr);
if (!schem) {
schem = load_schematic(L, 1, NULL, NULL);
was_loaded = true;
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "mainmenumanager.h"
#include "debug.h"
#include "clouds.h"
#include "server.h"
#include "filesys.h"
#include "guiMainMenu.h"
#include "game.h"
#include "chat.h"
#include "gettext.h"
#include "profiler.h"
#include "log.h"
#include "serverlist.h"
#include "guiEngine.h"
#include "player.h"
#include "fontengine.h"
#include "clientlauncher.h"

/* mainmenumanager.h
 */
gui::IGUIEnvironment *guienv = NULL;
gui::IGUIStaticText *guiroot = NULL;
MainMenuManager g_menumgr;

bool noMenuActive()
{
	return g_menumgr.menuCount() == 0;
}

// Passed to menus to allow disconnecting and exiting
MainGameCallback *g_gamecallback = NULL;


// Instance of the time getter
static TimeGetter *g_timegetter = NULL;

u32 getTimeMs()
{
	if (g_timegetter == NULL)
		return 0;
	return g_timegetter->getTime(PRECISION_MILLI);
}

u32 getTime(TimePrecision prec) {
	if (g_timegetter == NULL)
		return 0;
	return g_timegetter->getTime(prec);
}

ClientLauncher::~ClientLauncher()
{
	if (receiver)
		delete receiver;

	if (input)
		delete input;

	if (g_fontengine)
		delete g_fontengine;

	if (device)
		device->drop();
}


bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
{
	init_args(game_params, cmd_args);

	// List video modes if requested
	if (list_video_modes)