aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/unittests/crafting_prepare.lua
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2021-09-19 20:23:35 +0200
committerGitHub <noreply@github.com>2021-09-19 20:23:35 +0200
commite79d6154fc26b2a9bac242f0ac01ec785b5c53b1 (patch)
treeeb4587e1a83696f4e9d08531856a7170d019ae65 /games/devtest/mods/unittests/crafting_prepare.lua
parent40ea4ddef1fe56dab9a1479302f0b2578b4b0ed5 (diff)
downloadminetest-e79d6154fc26b2a9bac242f0ac01ec785b5c53b1.tar.gz
minetest-e79d6154fc26b2a9bac242f0ac01ec785b5c53b1.tar.bz2
minetest-e79d6154fc26b2a9bac242f0ac01ec785b5c53b1.zip
Fix client-side performance of chat UI (#11612)
Diffstat (limited to 'games/devtest/mods/unittests/crafting_prepare.lua')
0 files changed, 0 insertions, 0 deletions
9' href='#n139'>139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
/*
Minetest
Copyright (C) 2014-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
Copyright (C) 2015-2018 paramat

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.
*/

#pragma once

#include <map>
#include "mg_decoration.h"
#include "util/string.h"

class Map;
class ServerMap;
class Mapgen;
class MMVManip;
class PseudoRandom;
class NodeResolver;
class Server;

/*
	Minetest Schematic File Format

	All values are stored in big-endian byte order.
	[u32] signature: 'MTSM'
	[u16] version: 4
	[u16] size X
	[u16] size Y
	[u16] size Z
	For each Y:
		[u8] slice probability value
	[Name-ID table] Name ID Mapping Table
		[u16] name-id count
		For each name-id mapping:
			[u16] name length
			[u8[]] name
	ZLib deflated {
	For each node in schematic:  (for z, y, x)
		[u16] content
	For each node in schematic:
		[u8] param1
		  bit 0-6: probability
		  bit 7:   specific node force placement
	For each node in schematic:
		[u8] param2
	}

	Version changes:
	1 - Initial version
	2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
	3 - Added y-slice probabilities; this allows for variable height structures
	4 - Compressed range of node occurence prob., added per-node force placement bit
*/

//// Schematic constants
#define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
#define MTSCHEM_FILE_VER_HIGHEST_READ  4
#define MTSCHEM_FILE_VER_HIGHEST_WRITE 4

#define MTSCHEM_PROB_MASK       0x7F

#define MTSCHEM_PROB_NEVER      0x00
#define MTSCHEM_PROB_ALWAYS     0x7F
#define MTSCHEM_PROB_ALWAYS_OLD 0xFF

#define MTSCHEM_FORCE_PLACE     0x80

enum SchematicType
{
	SCHEMATIC_NORMAL,
};

enum SchematicFormatType {
	SCHEM_FMT_HANDLE,
	SCHEM_FMT_MTS,
	SCHEM_FMT_LUA,
};

class Schematic : public ObjDef, public NodeResolver {
public:
	Schematic();
	virtual ~Schematic();

	ObjDef *clone() const;

	virtual void resolveNodeNames();

	bool loadSchematicFromFile(const std::string &filename,
		const NodeDefManager *ndef, StringMap *replace_names = NULL);
	bool saveSchematicToFile(const std::string &filename,
		const NodeDefManager *ndef);
	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) const;
	bool serializeToLua(std::ostream *os, const std::vector<std::string> &names,
		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);
	void placeOnMap(ServerMap *map, v3s16 p, u32 flags, Rotation rot, bool force_place);

	void applyProbabilities(v3s16 p0,
		std::vector<std::pair<v3s16, u8> > *plist,
		std::vector<std::pair<s16, u8> > *splist);

	std::vector<content_t> c_nodes;
	u32 flags = 0;
	v3s16 size;
	MapNode *schemdata = nullptr;
	u8 *slice_probs = nullptr;
};

class SchematicManager : public ObjDefManager {
public:
	SchematicManager(Server *server);
	virtual ~SchematicManager() = default;