aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/README.md
blob: 77e722af78022af255ee2591c85f53407d4a6e78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Development Test (devtest)

This is a basic testing environment that contains a bunch of things to test the engine, but it could also be used as a minimal testbed for testing out mods.

## Features

* Basic nodes for mapgen
* Basic, minimal map generator
* Lots of example nodes for testing drawtypes, param2, light level, and many other node properties
* Example entities
* Other example items
* Formspec test (via `/test_formspec` command)
* Automated unit tests (disabled by default)
* Tools for manipulating nodes and entities, like the "Param2 Tool"

## Getting started

Basically, just create a world and start. A few important things to note:

* Items are gotten from the “Chest of Everything” (`chest_of_everything:chest`)
* When you lost your initial items, type in `/stuff` command to get them back
* By default, Creative Mode activates infinite node placement. This behavior can be changed with the `devtest_infplace` setting
* Use the `/infplace` command to toggle infinite node placement in-game
* Use the Param2 Tool to change the param2 of nodes; it's useful to experiment with the various drawtype test nodes
* Check out the game settings and server commands for additional tests and features

Confused by a certain node or item? Check out for inline code comments. The usages of most tools are explained in their tooltips.

### Example tests

* You can use this to test what happens if a player is simultaneously in 2 nodes with `damage_per_second` but with a different value.
* Or use the Falling Node Tool on various test nodes to see how they behave when falling.
* You could also use this as a testbed for dependency-free mods, e.g. to test out how your formspecs behave without theming.

## Random notes

* Experimental/strange/unstructured tests can be found in the `experimental` mod
* Textures of drawtype test nodes have a red dot at the top left corner. This is to see whether the textures are oriented properly

## Design philosophy

This should loosely follow the following principles:

* Engine testing: The main focus of this is to aid testing of *engine* features, such as mapgen or node drawtypes
* Mod testing: The secondary focus is to help modders as well, either as a minimal testbed for mods or even as a code example
* Minimal interference: Under default settings, it shall not interfere with APIs except on explicit user wish. Non-trivial tests and features need to be enabled by a setting first
* Convenience: Have various tools to make usage easier and more convenient
* Reproducing engine bugs: When an engine bug was found, consider creating a test case
* Clarity: Textures and names need to be designed to keep different things clearly visually apart at a glance
* Low loading time: It must load blazing-fast so stuff can be tested quickly

href='#n179'>179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
/*
Minetest
Copyright (C) 2010-2020 Minetest core development team

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 "serverinventorymgr.h"
#include "map.h"
#include "nodemetadata.h"
#include "player_sao.h"
#include "remoteplayer.h"
#include "server.h"
#include "serverenvironment.h"

ServerInventoryManager::ServerInventoryManager() : InventoryManager()
{
}

ServerInventoryManager::~ServerInventoryManager()
{
	// Delete detached inventories
	for (auto &detached_inventory : m_detached_inventories) {
		delete detached_inventory.second.inventory;
	}
}

Inventory *ServerInventoryManager::getInventory(const InventoryLocation &loc)
{
	switch (loc.type) {
	case InventoryLocation::UNDEFINED:
	case InventoryLocation::CURRENT_PLAYER:
		break;
	case InventoryLocation::PLAYER: {
		RemotePlayer *player = m_env->getPlayer(loc.name.c_str());
		if (!player)
			return NULL;
		PlayerSAO *playersao = player->getPlayerSAO();
		if (!playersao)
			return NULL;
		return playersao->getInventory();
	} break;
	case InventoryLocation::NODEMETA: {
		NodeMetadata *meta = m_env->getMap().getNodeMetadata(loc.p);
		if (!meta)
			return NULL;
		return meta->getInventory();
	} break;
	case InventoryLocation::DETACHED: {
		auto it = m_detached_inventories.find(loc.name);
		if (it == m_detached_inventories.end())
			return nullptr;
		return it->second.inventory;
	} break;
	default:
		sanity_check(false); // abort
		break;
	}
	return NULL;
}

void ServerInventoryManager::setInventoryModified(const InventoryLocation &loc)
{
	switch (loc.type) {
	case InventoryLocation::UNDEFINED:
		break;
	case InventoryLocation::PLAYER: {

		RemotePlayer *player = m_env->getPlayer(loc.name.c_str());

		if (!player)
			return;

		player->setModified(true);
		player->inventory.setModified(true);
		// Updates are sent in ServerEnvironment::step()