Skip to content
Permalink
Browse files

Environment & IGameDef code refactoring (#4985)

* Environment code refactoring
* Cleanup includes & class declarations in client & server environment to improve build speed
* ServerEnvironment::m_gamedef is now a pointer to Server instead of IGameDef, permitting to cleanup many casts.
* Cleanup IGameDef
  * Move ITextureSource* IGameDef::getTextureSource() to Client only.
  * Also move ITextureSource *IGameDef::tsrc() helper
  * drop getShaderSource, getSceneManager, getSoundManager & getCamera abstract call
  * drop unused emerge() call
  * cleanup server unused functions (mentionned before)
* Drop one unused parameter from ContentFeatures::updateTextures
* move checkLocalPrivilege to Client
* Remove some unnecessary casts
* create_formspec_menu: remove IWritableTextureSource pointer, as client already knows it
* Fix some comments
* Change required IGameDef to Server/Client pointers
* Previous change that game.cpp sometimes calls functions with Client + InventoryManager + IGameDef in same functions but it's the same objects
* Remove duplicate Client pointer in GUIFormSpecMenu::GUIFormSpecMenu
* drop ClientMap::sectorWasDrawn which is unused
  • Loading branch information
nerzhul committed Jan 9, 2017
1 parent 11df7e8 commit 8e7449e09253e138716d8dbad6a2ab5c6e089e28
@@ -117,6 +117,7 @@ LOCAL_SRC_FILES := \
jni/src/cavegen.cpp \
jni/src/chat.cpp \
jni/src/client.cpp \
jni/src/clientenvironment.cpp \
jni/src/clientiface.cpp \
jni/src/clientmap.cpp \
jni/src/clientmedia.cpp \
@@ -210,6 +211,7 @@ LOCAL_SRC_FILES := \
jni/src/rollback_interface.cpp \
jni/src/serialization.cpp \
jni/src/server.cpp \
jni/src/serverenvironment.cpp \
jni/src/serverlist.cpp \
jni/src/serverobject.cpp \
jni/src/shader.cpp \
@@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "wieldmesh.h"
#include "noise.h" // easeCurve
#include "gamedef.h"
#include "sound.h"
#include "event.h"
#include "profiler.h"
@@ -41,7 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h"

Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
IGameDef *gamedef):
Client *client):
m_playernode(NULL),
m_headnode(NULL),
m_cameranode(NULL),
@@ -50,7 +49,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
m_wieldnode(NULL),

m_draw_control(draw_control),
m_gamedef(gamedef),
m_client(client),

m_camera_position(0,0,0),
m_camera_direction(0,0,0),
@@ -88,7 +87,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
m_wieldmgr = smgr->createNewSceneManager();
m_wieldmgr->addCameraSceneNode();
m_wieldnode = new WieldMeshSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr, -1, false);
m_wieldnode->setItem(ItemStack(), m_gamedef);
m_wieldnode->setItem(ItemStack(), m_client);
m_wieldnode->drop(); // m_wieldmgr grabbed it

/* TODO: Add a callback function so these can be updated when a setting
@@ -151,7 +150,7 @@ void Camera::step(f32 dtime)
m_wield_change_timer = MYMIN(m_wield_change_timer + dtime, 0.125);

if (m_wield_change_timer >= 0 && was_under_zero)
m_wieldnode->setItem(m_wield_item_next, m_gamedef);
m_wieldnode->setItem(m_wield_item_next, m_client);

if (m_view_bobbing_state != 0)
{
@@ -189,7 +188,7 @@ void Camera::step(f32 dtime)
(was > 0.5f && m_view_bobbing_anim <= 0.5f));
if(step) {
MtEvent *e = new SimpleTriggerEvent("ViewBobbingStep");
m_gamedef->event()->put(e);
m_client->event()->put(e);
}
}
}
@@ -210,10 +209,10 @@ void Camera::step(f32 dtime)
if(m_digging_button == 0)
{
MtEvent *e = new SimpleTriggerEvent("CameraPunchLeft");
m_gamedef->event()->put(e);
m_client->event()->put(e);
} else if(m_digging_button == 1) {
MtEvent *e = new SimpleTriggerEvent("CameraPunchRight");
m_gamedef->event()->put(e);
m_client->event()->put(e);
}
}
}
@@ -352,7 +351,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
my_cp.Y = m_camera_position.Y + (m_camera_direction.Y*-i);

// Prevent camera positioned inside nodes
INodeDefManager *nodemgr = m_gamedef->ndef();
INodeDefManager *nodemgr = m_client->ndef();
MapNode n = c_env.getClientMap().getNodeNoEx(floatToInt(my_cp, BS));
const ContentFeatures& features = nodemgr->get(n);
if(features.walkable)
@@ -390,7 +389,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,

// Get FOV
f32 fov_degrees;
if (player->getPlayerControl().zoom && m_gamedef->checkLocalPrivilege("zoom")) {
if (player->getPlayerControl().zoom && m_client->checkLocalPrivilege("zoom")) {
fov_degrees = m_cache_zoom_fov;
} else {
fov_degrees = m_cache_fov;
@@ -468,7 +467,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
const bool climbing = movement_Y && player->is_climbing;
if ((walking || swimming || climbing) &&
m_cache_view_bobbing &&
(!g_settings->getBool("free_move") || !m_gamedef->checkLocalPrivilege("fly")))
(!g_settings->getBool("free_move") || !m_client->checkLocalPrivilege("fly")))
{
// Start animation
m_view_bobbing_state = 1;
@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

class LocalPlayer;
struct MapDrawControl;
class IGameDef;
class Client;
class WieldMeshSceneNode;

struct Nametag {
@@ -61,7 +61,7 @@ class Camera
{
public:
Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
IGameDef *gamedef);
Client *client);
~Camera();

// Get player scene node.
@@ -189,7 +189,7 @@ class Camera
// draw control
MapDrawControl& m_draw_control;

IGameDef *m_gamedef;
Client *m_client;
video::IVideoDriver *m_driver;

// Absolute camera position
@@ -221,7 +221,7 @@ Client::Client(
m_event(event),
m_mesh_update_thread(),
m_env(
new ClientMap(this, this, control,
new ClientMap(this, control,
device->getSceneManager()->getRootSceneNode(),
device->getSceneManager(), 666),
device->getSceneManager(),
@@ -34,7 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "localplayer.h"
#include "hud.h"
#include "particles.h"
#include "network/networkpacket.h"

struct MeshMakeData;
class MapBlockMesh;
@@ -51,6 +50,7 @@ class Database;
class Mapper;
struct MinimapMapblock;
class Camera;
class NetworkPacket;

struct QueuedMeshUpdate
{
@@ -402,9 +402,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

void ProcessData(NetworkPacket *pkt);

// Returns true if something was received
bool AsyncProcessPacket();
bool AsyncProcessData();
void Send(NetworkPacket* pkt);

void interact(u8 action, const PointedThing& pointed);
@@ -422,8 +419,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void sendRespawn();
void sendReady();

ClientEnvironment& getEnv()
{ return m_env; }
ClientEnvironment& getEnv() { return m_env; }
ITextureSource *tsrc() { return getTextureSource(); }
ISoundManager *sound() { return getSoundManager(); }

// Causes urgent mesh updates (unlike Map::add/removeNodeWithEvent)
void removeNode(v3s16 p);
@@ -521,14 +519,15 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
virtual IItemDefManager* getItemDefManager();
virtual INodeDefManager* getNodeDefManager();
virtual ICraftDefManager* getCraftDefManager();
virtual ITextureSource* getTextureSource();
ITextureSource* getTextureSource();
virtual IShaderSource* getShaderSource();
virtual scene::ISceneManager* getSceneManager();
IShaderSource *shsrc() { return getShaderSource(); }
scene::ISceneManager* getSceneManager();
virtual u16 allocateUnknownNodeId(const std::string &name);
virtual ISoundManager* getSoundManager();
virtual MtEventManager* getEventManager();
virtual ParticleManager* getParticleManager();
virtual bool checkLocalPrivilege(const std::string &priv)
bool checkLocalPrivilege(const std::string &priv)
{ return checkPrivilege(priv); }
virtual scene::IAnimatedMesh* getMesh(const std::string &filename);

@@ -34,13 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
ITextureSource *texturesource, IGameDef *gamedef,
ITextureSource *texturesource, Client *client,
IrrlichtDevice *irr):
m_map(map),
m_local_player(NULL),
m_smgr(smgr),
m_texturesource(texturesource),
m_gamedef(gamedef),
m_client(client),
m_irr(irr)
{
char zero = 0;
@@ -94,7 +94,7 @@ void ClientEnvironment::step(float dtime)
stepTimeOfDay(dtime);

// Get some settings
bool fly_allowed = m_gamedef->checkLocalPrivilege("fly");
bool fly_allowed = m_client->checkLocalPrivilege("fly");
bool free_move = fly_allowed && g_settings->getBool("free_move");

// Get local player
@@ -223,7 +223,7 @@ void ClientEnvironment::step(float dtime)
f32 post_factor = 1; // 1 hp per node/s
if(info.type == COLLISION_NODE)
{
const ContentFeatures &f = m_gamedef->ndef()->
const ContentFeatures &f = m_client->ndef()->
get(m_map->getNodeNoEx(info.node_p));
// Determine fall damage multiplier
int addp = itemgroup_get(f.groups, "fall_damage_add_percent");
@@ -237,7 +237,7 @@ void ClientEnvironment::step(float dtime)
if(damage != 0){
damageLocalPlayer(damage, true);
MtEvent *e = new SimpleTriggerEvent("PlayerFallingDamage");
m_gamedef->event()->put(e);
m_client->event()->put(e);
}
}
}
@@ -259,11 +259,11 @@ void ClientEnvironment::step(float dtime)

u32 damage_per_second = 0;
damage_per_second = MYMAX(damage_per_second,
m_gamedef->ndef()->get(n1).damage_per_second);
m_client->ndef()->get(n1).damage_per_second);
damage_per_second = MYMAX(damage_per_second,
m_gamedef->ndef()->get(n2).damage_per_second);
m_client->ndef()->get(n2).damage_per_second);
damage_per_second = MYMAX(damage_per_second,
m_gamedef->ndef()->get(n3).damage_per_second);
m_client->ndef()->get(n3).damage_per_second);

if(damage_per_second != 0)
{
@@ -272,7 +272,7 @@ void ClientEnvironment::step(float dtime)
}

// Protocol v29 make this behaviour obsolete
if (((Client*) getGameDef())->getProtoVersion() < 29) {
if (getGameDef()->getProtoVersion() < 29) {
/*
Drowning
*/
@@ -282,7 +282,7 @@ void ClientEnvironment::step(float dtime)
// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNodeNoEx(p);
ContentFeatures c = m_gamedef->ndef()->get(n);
ContentFeatures c = m_client->ndef()->get(n);
u8 drowning_damage = c.drowning;
if (drowning_damage > 0 && lplayer->hp > 0) {
u16 breath = lplayer->getBreath();
@@ -306,7 +306,7 @@ void ClientEnvironment::step(float dtime)
// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNodeNoEx(p);
ContentFeatures c = m_gamedef->ndef()->get(n);
ContentFeatures c = m_client->ndef()->get(n);
if (!lplayer->hp) {
lplayer->setBreath(11);
} else if (c.drowning == 0) {
@@ -332,7 +332,7 @@ void ClientEnvironment::step(float dtime)
v3s16 p = lplayer->getLightPosition();
node_at_lplayer = m_map->getNodeNoEx(p);

u16 light = getInteriorLight(node_at_lplayer, 0, m_gamedef->ndef());
u16 light = getInteriorLight(node_at_lplayer, 0, m_client->ndef());
u8 day = light & 0xff;
u8 night = (light >> 8) & 0xff;
finalColorBlend(lplayer->light_color, day, night, day_night_ratio);
@@ -360,7 +360,7 @@ void ClientEnvironment::step(float dtime)
v3s16 p = obj->getLightPosition();
MapNode n = m_map->getNodeNoEx(p, &pos_ok);
if (pos_ok)
light = n.getLightBlend(day_night_ratio, m_gamedef->ndef());
light = n.getLightBlend(day_night_ratio, m_client->ndef());
else
light = blend_light(day_night_ratio, LIGHT_SUN, 0);

@@ -467,7 +467,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
v3s16 p = object->getLightPosition();
MapNode n = m_map->getNodeNoEx(p, &pos_ok);
if (pos_ok)
light = n.getLightBlend(getDayNightRatio(), m_gamedef->ndef());
light = n.getLightBlend(getDayNightRatio(), m_client->ndef());
else
light = blend_light(getDayNightRatio(), LIGHT_SUN, 0);

@@ -480,7 +480,7 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type,
const std::string &init_data)
{
ClientActiveObject* obj =
ClientActiveObject::create((ActiveObjectType) type, m_gamedef, this);
ClientActiveObject::create((ActiveObjectType) type, m_client, this);
if(obj == NULL)
{
infostream<<"ClientEnvironment::addActiveObject(): "
@@ -30,6 +30,7 @@ class ClientMap;
class ClientActiveObject;
class GenericCAO;
class LocalPlayer;
struct PointedThing;

/*
The client-side environment.
@@ -66,15 +67,14 @@ class ClientEnvironment : public Environment
{
public:
ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
ITextureSource *texturesource, IGameDef *gamedef,
ITextureSource *texturesource, Client *client,
IrrlichtDevice *device);
~ClientEnvironment();

Map & getMap();
ClientMap & getClientMap();

IGameDef *getGameDef()
{ return m_gamedef; }
Client *getGameDef() { return m_client; }

void step(f32 dtime);

@@ -175,7 +175,7 @@ class ClientEnvironment : public Environment
LocalPlayer *m_local_player;
scene::ISceneManager *m_smgr;
ITextureSource *m_texturesource;
IGameDef *m_gamedef;
Client *m_client;
IrrlichtDevice *m_irr;
UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects;
std::vector<ClientSimpleObject*> m_simple_objects;
@@ -35,13 +35,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,

ClientMap::ClientMap(
Client *client,
IGameDef *gamedef,
MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id
):
Map(dout_client, gamedef),
Map(dout_client, client),
scene::ISceneNode(parent, mgr, id),
m_client(client),
m_control(control),
@@ -140,7 +139,7 @@ static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
return false;
}

void ClientMap::getBlocksInViewRange(v3s16 cam_pos_nodes,
void ClientMap::getBlocksInViewRange(v3s16 cam_pos_nodes,
v3s16 *p_blocks_min, v3s16 *p_blocks_max)
{
v3s16 box_nodes_d = m_control.wanted_range * v3s16(1, 1, 1);
@@ -766,7 +765,7 @@ void ClientMap::renderPostFx(CameraMode cam_mode)
const ContentFeatures& features = m_nodedef->get(n);
video::SColor post_effect_color = features.post_effect_color;
if(features.solidness == 2 && !(g_settings->getBool("noclip") &&
m_gamedef->checkLocalPrivilege("noclip")) &&
m_client->checkLocalPrivilege("noclip")) &&
cam_mode == CAMERA_MODE_FIRST)
{
post_effect_color = video::SColor(255, 0, 0, 0);

0 comments on commit 8e7449e

Please sign in to comment.