Skip to content

Commit

Permalink
Node definition manager refactor (#7016)
Browse files Browse the repository at this point in the history
* Rename IWritableNodeDefManager to NodeDefManager
* Make INodeDefManager functions const
* Use "const *NodeDefManager" instead of "*INodeDefManager"
* Remove unused INodeDefManager class
* Merge NodeDefManager and CNodeDefManager
* Document NodeDefManager
  • Loading branch information
juhdanad authored and SmallJoker committed Feb 10, 2018
1 parent 617d94c commit 3face01
Show file tree
Hide file tree
Showing 61 changed files with 585 additions and 459 deletions.
2 changes: 1 addition & 1 deletion src/camera.cpp
Expand Up @@ -413,7 +413,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
my_cp.Y = m_camera_position.Y + (m_camera_direction.Y * -i);

// Prevent camera positioned inside nodes
INodeDefManager *nodemgr = m_client->ndef();
const NodeDefManager *nodemgr = m_client->ndef();
MapNode n = m_client->getEnv().getClientMap()
.getNodeNoEx(floatToInt(my_cp, BS));

Expand Down
4 changes: 2 additions & 2 deletions src/client.cpp
Expand Up @@ -71,7 +71,7 @@ Client::Client(
IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc,
IWritableItemDefManager *itemdef,
IWritableNodeDefManager *nodedef,
NodeDefManager *nodedef,
ISoundManager *sound,
MtEventManager *event,
bool ipv6,
Expand Down Expand Up @@ -1798,7 +1798,7 @@ IItemDefManager* Client::getItemDefManager()
{
return m_itemdef;
}
INodeDefManager* Client::getNodeDefManager()
const NodeDefManager* Client::getNodeDefManager()
{
return m_nodedef;
}
Expand Down
8 changes: 4 additions & 4 deletions src/client.h
Expand Up @@ -48,7 +48,7 @@ class MapBlockMesh;
class IWritableTextureSource;
class IWritableShaderSource;
class IWritableItemDefManager;
class IWritableNodeDefManager;
class NodeDefManager;
//class IWritableCraftDefManager;
class ClientMediaDownloader;
struct MapDrawControl;
Expand Down Expand Up @@ -129,7 +129,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc,
IWritableItemDefManager *itemdef,
IWritableNodeDefManager *nodedef,
NodeDefManager *nodedef,
ISoundManager *sound,
MtEventManager *event,
bool ipv6,
Expand Down Expand Up @@ -365,7 +365,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

// IGameDef interface
virtual IItemDefManager* getItemDefManager();
virtual INodeDefManager* getNodeDefManager();
virtual const NodeDefManager* getNodeDefManager();
virtual ICraftDefManager* getCraftDefManager();
ITextureSource* getTextureSource();
virtual IShaderSource* getShaderSource();
Expand Down Expand Up @@ -477,7 +477,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
IWritableTextureSource *m_tsrc;
IWritableShaderSource *m_shsrc;
IWritableItemDefManager *m_itemdef;
IWritableNodeDefManager *m_nodedef;
NodeDefManager *m_nodedef;
ISoundManager *m_sound;
MtEventManager *m_event;

Expand Down
2 changes: 1 addition & 1 deletion src/client/gameui.cpp
Expand Up @@ -131,7 +131,7 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_

if (pointed_old.type == POINTEDTHING_NODE) {
ClientMap &map = client->getEnv().getClientMap();
const INodeDefManager *nodedef = client->getNodeDefManager();
const NodeDefManager *nodedef = client->getNodeDefManager();
MapNode n = map.getNodeNoEx(pointed_old.node_undersurface);

if (n.getContent() != CONTENT_IGNORE && nodedef->get(n).name != "unknown") {
Expand Down
6 changes: 3 additions & 3 deletions src/clientmap.cpp
Expand Up @@ -480,9 +480,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
}

static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step,
float step_multiplier, float start_distance, float end_distance,
INodeDefManager *ndef, u32 daylight_factor, float sunlight_min_d,
int *result, bool *sunlight_seen)
float step_multiplier, float start_distance, float end_distance,
const NodeDefManager *ndef, u32 daylight_factor, float sunlight_min_d,
int *result, bool *sunlight_seen)
{
int brightness_sum = 0;
int brightness_count = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/collision.cpp
Expand Up @@ -202,8 +202,8 @@ bool wouldCollideWithCeiling(
return false;
}

static inline void getNeighborConnectingFace(const v3s16 &p, INodeDefManager *nodedef,
Map *map, MapNode n, int v, int *neighbors)
static inline void getNeighborConnectingFace(const v3s16 &p,
const NodeDefManager *nodedef, Map *map, MapNode n, int v, int *neighbors)
{
MapNode n2 = map->getNodeNoEx(p);
if (nodedef->nodeboxConnects(n, n2, v))
Expand Down Expand Up @@ -283,7 +283,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
// Object collides into walkable nodes

any_position_valid = true;
INodeDefManager *nodedef = gamedef->getNodeDefManager();
const NodeDefManager *nodedef = gamedef->getNodeDefManager();
const ContentFeatures &f = nodedef->get(n);

if (!f.walkable)
Expand Down
2 changes: 1 addition & 1 deletion src/content_cao.cpp
Expand Up @@ -874,7 +874,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
if (m_step_distance_counter > 1.5f * BS) {
m_step_distance_counter = 0.0f;
if (!m_is_local_player && m_prop.makes_footstep_sound) {
INodeDefManager *ndef = m_client->ndef();
const NodeDefManager *ndef = m_client->ndef();
v3s16 p = floatToInt(getPosition() +
v3f(0.0f, (m_prop.collisionbox.MinEdge.Y - 0.5f) * BS, 0.0f), BS);
MapNode n = m_env->getMap().getNodeNoEx(p);
Expand Down
2 changes: 1 addition & 1 deletion src/content_mapblock.h
Expand Up @@ -49,7 +49,7 @@ class MapblockMeshGenerator
MeshMakeData *data;
MeshCollector *collector;

INodeDefManager *nodedef;
const NodeDefManager *nodedef;
scene::IMeshManipulator *meshmanip;

// options
Expand Down
6 changes: 3 additions & 3 deletions src/emerge.h
Expand Up @@ -36,7 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
}

class EmergeThread;
class INodeDefManager;
class NodeDefManager;
class Settings;

class BiomeManager;
Expand All @@ -53,7 +53,7 @@ struct BlockMakeData {
v3s16 blockpos_max;
v3s16 blockpos_requested;
UniqueQueue<v3s16> transforming_liquid;
INodeDefManager *nodedef = nullptr;
const NodeDefManager *nodedef = nullptr;

BlockMakeData() = default;

Expand Down Expand Up @@ -88,7 +88,7 @@ struct BlockEmergeData {

class EmergeManager {
public:
INodeDefManager *ndef;
const NodeDefManager *ndef;
bool enable_mapgen_debug_info;

// Generation Notify
Expand Down
4 changes: 2 additions & 2 deletions src/environment.cpp
Expand Up @@ -87,7 +87,7 @@ float Environment::getTimeOfDayF()
Check if a node is pointable
*/
inline static bool isPointableNode(const MapNode &n,
INodeDefManager *nodedef , bool liquids_pointable)
const NodeDefManager *nodedef , bool liquids_pointable)
{
const ContentFeatures &features = nodedef->get(n);
return features.pointable ||
Expand All @@ -96,7 +96,7 @@ inline static bool isPointableNode(const MapNode &n,

void Environment::continueRaycast(RaycastState *state, PointedThing *result)
{
INodeDefManager *nodedef = getMap().getNodeDefManager();
const NodeDefManager *nodedef = getMap().getNodeDefManager();
if (state->m_initialization_needed) {
// Add objects
if (state->m_objects_pointable) {
Expand Down
10 changes: 5 additions & 5 deletions src/game.cpp
Expand Up @@ -255,7 +255,7 @@ class NodeDugEvent: public MtEvent
class SoundMaker
{
ISoundManager *m_sound;
INodeDefManager *m_ndef;
const NodeDefManager *m_ndef;
public:
bool makes_footstep_sound;
float m_player_step_timer;
Expand All @@ -264,7 +264,7 @@ class SoundMaker
SimpleSoundSpec m_player_leftpunch_sound;
SimpleSoundSpec m_player_rightpunch_sound;

SoundMaker(ISoundManager *sound, INodeDefManager *ndef):
SoundMaker(ISoundManager *sound, const NodeDefManager *ndef):
m_sound(sound),
m_ndef(ndef),
makes_footstep_sound(true),
Expand Down Expand Up @@ -809,7 +809,7 @@ class Game {

// When created, these will be filled with data received from the server
IWritableItemDefManager *itemdef_manager = nullptr;
IWritableNodeDefManager *nodedef_manager = nullptr;
NodeDefManager *nodedef_manager = nullptr;

GameOnDemandSoundFetcher soundfetcher; // useful when testing
ISoundManager *sound = nullptr;
Expand Down Expand Up @@ -3066,7 +3066,7 @@ PointedThing Game::updatePointedThing(

ClientEnvironment &env = client->getEnv();
ClientMap &map = env.getClientMap();
INodeDefManager *nodedef = map.getNodeDefManager();
const NodeDefManager *nodedef = map.getNodeDefManager();

runData.selected_object = NULL;

Expand Down Expand Up @@ -3252,7 +3252,7 @@ bool Game::nodePlacementPrediction(const ItemDefinition &playeritem_def,
const ItemStack &playeritem, const v3s16 &nodepos, const v3s16 &neighbourpos)
{
std::string prediction = playeritem_def.node_placement_prediction;
INodeDefManager *nodedef = client->ndef();
const NodeDefManager *nodedef = client->ndef();
ClientMap &map = client->getEnv().getClientMap();
MapNode node;
bool is_valid_position;
Expand Down
6 changes: 3 additions & 3 deletions src/gamedef.h
Expand Up @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes.h"

class IItemDefManager;
class INodeDefManager;
class NodeDefManager;
class ICraftDefManager;
class ITextureSource;
class ISoundManager;
Expand Down Expand Up @@ -53,7 +53,7 @@ class IGameDef
// These are thread-safe IF they are not edited while running threads.
// Thus, first they are set up and then they are only read.
virtual IItemDefManager* getItemDefManager()=0;
virtual INodeDefManager* getNodeDefManager()=0;
virtual const NodeDefManager* getNodeDefManager()=0;
virtual ICraftDefManager* getCraftDefManager()=0;

// Used for keeping track of names/ids of unknown nodes
Expand All @@ -67,7 +67,7 @@ class IGameDef

// Shorthands
IItemDefManager *idef() { return getItemDefManager(); }
INodeDefManager *ndef() { return getNodeDefManager(); }
const NodeDefManager *ndef() { return getNodeDefManager(); }
ICraftDefManager *cdef() { return getCraftDefManager(); }

MtEventManager *event() { return getEventManager(); }
Expand Down
8 changes: 4 additions & 4 deletions src/localplayer.cpp
Expand Up @@ -70,7 +70,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
v3s16(-1, 0, -1)
};

INodeDefManager *nodemgr = m_client->ndef();
const NodeDefManager *nodemgr = m_client->ndef();
MapNode node;
bool is_valid_position;
bool new_sneak_node_exists = m_sneak_node_exists;
Expand Down Expand Up @@ -181,7 +181,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
}

Map *map = &env->getMap();
INodeDefManager *nodemgr = m_client->ndef();
const NodeDefManager *nodemgr = m_client->ndef();

v3f position = getPosition();

Expand Down Expand Up @@ -762,7 +762,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
std::vector<CollisionInfo> *collision_info)
{
Map *map = &env->getMap();
INodeDefManager *nodemgr = m_client->ndef();
const NodeDefManager *nodemgr = m_client->ndef();

v3f position = getPosition();

Expand Down Expand Up @@ -1063,7 +1063,7 @@ float LocalPlayer::getSlipFactor(Environment *env, const v3f &speedH)

float slip_factor = 1.0f;
// Slip on slippery nodes
const INodeDefManager *nodemgr = env->getGameDef()->ndef();
const NodeDefManager *nodemgr = env->getGameDef()->ndef();
Map *map = &env->getMap();
const ContentFeatures &f = nodemgr->get(map->getNodeNoEx(
floatToInt(getPosition() - v3f(0, 0.05f * BS, 0), BS)));
Expand Down
4 changes: 2 additions & 2 deletions src/map.h
Expand Up @@ -178,7 +178,7 @@ class Map /*: public NodeContainer*/
virtual MapBlock * emergeBlock(v3s16 p, bool create_blank=true)
{ return getBlockNoCreateNoEx(p); }

inline INodeDefManager * getNodeDefManager() { return m_nodedef; }
inline const NodeDefManager * getNodeDefManager() { return m_nodedef; }

// Returns InvalidPositionException if not found
bool isNodeUnderground(v3s16 p);
Expand Down Expand Up @@ -311,7 +311,7 @@ class Map /*: public NodeContainer*/
UniqueQueue<v3s16> m_transforming_liquid;

// This stores the properties of the nodes on the map.
INodeDefManager *m_nodedef;
const NodeDefManager *m_nodedef;

bool isOccluded(v3s16 p0, v3s16 p1, float step, float stepfac,
float start_off, float end_off, u32 needed_count);
Expand Down
9 changes: 5 additions & 4 deletions src/mapblock.cpp
Expand Up @@ -132,6 +132,7 @@ std::string MapBlock::getModifiedReasonString()
return reason;
}


void MapBlock::copyTo(VoxelManipulator &dst)
{
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
Expand All @@ -154,7 +155,7 @@ void MapBlock::copyFrom(VoxelManipulator &dst)

void MapBlock::actuallyUpdateDayNightDiff()
{
INodeDefManager *nodemgr = m_gamedef->ndef();
const NodeDefManager *nodemgr = m_gamedef->ndef();

// Running this function un-expires m_day_night_differs
m_day_night_differs_expired = false;
Expand Down Expand Up @@ -252,7 +253,7 @@ s16 MapBlock::getGroundLevel(v2s16 p2d)
// mapblocks.
static content_t getBlockNodeIdMapping_mapping[USHRT_MAX + 1];
static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
INodeDefManager *nodedef)
const NodeDefManager *nodedef)
{
memset(getBlockNodeIdMapping_mapping, 0xFF, (USHRT_MAX + 1) * sizeof(content_t));

Expand Down Expand Up @@ -294,7 +295,7 @@ static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
static void correctBlockNodeIds(const NameIdMapping *nimap, MapNode *nodes,
IGameDef *gamedef)
{
INodeDefManager *nodedef = gamedef->ndef();
const NodeDefManager *nodedef = gamedef->ndef();
// This means the block contains incorrect ids, and we contain
// the information to convert those to names.
// nodedef contains information to convert our names to globally
Expand Down Expand Up @@ -741,7 +742,7 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)

// Legacy data changes
// This code has to convert from pre-22 to post-22 format.
INodeDefManager *nodedef = m_gamedef->ndef();
const NodeDefManager *nodedef = m_gamedef->ndef();
for(u32 i=0; i<nodecount; i++)
{
const ContentFeatures &f = nodedef->get(data[i].getContent());
Expand Down

0 comments on commit 3face01

Please sign in to comment.