Skip to content

Commit

Permalink
Reduce number of recursively included headers
Browse files Browse the repository at this point in the history
This should improve compilation speed.

Things changed:
* Prefer forward-declarations in headers.
* Move header-includes out of headers if possible.
* Move some functions definitions out of headers.
* Put some member variables into unique_ptrs (see Client).
  • Loading branch information
Desour committed Apr 27, 2023
1 parent e9e8eed commit 8b73743
Show file tree
Hide file tree
Showing 35 changed files with 109 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/client/camera.h
Expand Up @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "inventory.h"
#include "client/tile.h"
#include "client/localplayer.h"
#include <ICameraSceneNode.h>
#include <ISceneNode.h>
#include <plane3d.h>
Expand Down
50 changes: 33 additions & 17 deletions src/client/client.cpp
Expand Up @@ -32,6 +32,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/renderingengine.h"
#include "client/sound.h"
#include "client/tile.h"
#include "client/mesh_generator_thread.h"
#include "client/particles.h"
#include "client/localplayer.h"
#include "util/auth.h"
#include "util/directiontables.h"
#include "util/pointedthing.h"
Expand Down Expand Up @@ -60,6 +63,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "chatmessage.h"
#include "translation.h"
#include "content/mod_configuration.h"
#include "mapnode.h"

extern gui::IGUIEnvironment* guienv;

Expand Down Expand Up @@ -112,12 +116,12 @@ Client::Client(
m_sound(sound),
m_event(event),
m_rendering_engine(rendering_engine),
m_mesh_update_manager(this),
m_mesh_update_manager(std::make_unique<MeshUpdateManager>(this)),
m_env(
new ClientMap(this, rendering_engine, control, 666),
tsrc, this
),
m_particle_manager(&m_env),
m_particle_manager(std::make_unique<ParticleManager>(&m_env)),
m_con(new con::Connection(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this)),
m_address_name(address_name),
m_allow_login_or_register(allow_login_or_register),
Expand Down Expand Up @@ -314,7 +318,7 @@ void Client::Stop()
if (m_mods_loaded)
m_script->on_shutdown();
//request all client managed threads to stop
m_mesh_update_manager.stop();
m_mesh_update_manager->stop();
// Save local server map
if (m_localdb) {
infostream << "Local map saving ended." << std::endl;
Expand All @@ -327,7 +331,7 @@ void Client::Stop()

bool Client::isShutdown()
{
return m_shutdown || !m_mesh_update_manager.isRunning();
return m_shutdown || !m_mesh_update_manager->isRunning();
}

Client::~Client()
Expand All @@ -337,11 +341,11 @@ Client::~Client()

deleteAuthData();

m_mesh_update_manager.stop();
m_mesh_update_manager.wait();
m_mesh_update_manager->stop();
m_mesh_update_manager->wait();

MeshUpdateResult r;
while (m_mesh_update_manager.getNextResult(r)) {
while (m_mesh_update_manager->getNextResult(r)) {
for (auto block : r.map_blocks)
if (block)
block->refDrop();
Expand Down Expand Up @@ -553,7 +557,7 @@ void Client::step(float dtime)
std::vector<v3s16> blocks_to_ack;
bool force_update_shadows = false;
MeshUpdateResult r;
while (m_mesh_update_manager.getNextResult(r))
while (m_mesh_update_manager->getNextResult(r))
{
num_processed_meshes++;

Expand Down Expand Up @@ -1128,12 +1132,14 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
{
m_chosen_auth_mech = chosen_auth_mechanism;

std::string playername = m_env.getLocalPlayer()->getName();

switch (chosen_auth_mechanism) {
case AUTH_MECHANISM_FIRST_SRP: {
// send srp verifier to server
std::string verifier;
std::string salt;
generate_srp_verifier_and_salt(getPlayerName(), m_password,
generate_srp_verifier_and_salt(playername, m_password,
&verifier, &salt);

NetworkPacket resp_pkt(TOSERVER_FIRST_SRP, 0);
Expand All @@ -1147,13 +1153,13 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
u8 based_on = 1;

if (chosen_auth_mechanism == AUTH_MECHANISM_LEGACY_PASSWORD) {
m_password = translate_password(getPlayerName(), m_password);
m_password = translate_password(playername, m_password);
based_on = 0;
}

std::string playername_u = lowercase(getPlayerName());
std::string playername_u = lowercase(playername);
m_auth_data = srp_user_new(SRP_SHA256, SRP_NG_2048,
getPlayerName().c_str(), playername_u.c_str(),
playername.c_str(), playername_u.c_str(),
(const unsigned char *) m_password.c_str(),
m_password.length(), NULL, NULL);
char *bytes_A = 0;
Expand Down Expand Up @@ -1695,12 +1701,12 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
if (b == NULL)
return;

m_mesh_update_manager.updateBlock(&m_env.getMap(), p, ack_to_server, urgent);
m_mesh_update_manager->updateBlock(&m_env.getMap(), p, ack_to_server, urgent);
}

void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool urgent)
{
m_mesh_update_manager.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, true);
m_mesh_update_manager->updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, true);
}

void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent)
Expand All @@ -1714,7 +1720,7 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur

v3s16 blockpos = getNodeBlockPos(nodepos);
v3s16 blockpos_relative = blockpos * MAP_BLOCKSIZE;
m_mesh_update_manager.updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, false);
m_mesh_update_manager->updateBlock(&m_env.getMap(), blockpos, ack_to_server, urgent, false);
// Leading edge
if (nodepos.X == blockpos_relative.X)
addUpdateMeshTask(blockpos + v3s16(-1, 0, 0), false, urgent);
Expand All @@ -1724,6 +1730,11 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur
addUpdateMeshTask(blockpos + v3s16(0, 0, -1), false, urgent);
}

void Client::updateCameraOffset(v3s16 camera_offset)
{
m_mesh_update_manager->m_camera_offset = camera_offset;
}

ClientEvent *Client::getClientEvent()
{
FATAL_ERROR_IF(m_client_event_queue.empty(),
Expand Down Expand Up @@ -1828,7 +1839,7 @@ void Client::afterContentReceived()

// Start mesh update thread after setting up content definitions
infostream<<"- Starting mesh update thread"<<std::endl;
m_mesh_update_manager.start();
m_mesh_update_manager->start();

m_state = LC_Ready;
sendReady();
Expand Down Expand Up @@ -1979,7 +1990,7 @@ MtEventManager* Client::getEventManager()

ParticleManager* Client::getParticleManager()
{
return &m_particle_manager;
return m_particle_manager.get();
}

scene::IAnimatedMesh* Client::getMesh(const std::string &filename, bool cache)
Expand Down Expand Up @@ -2078,3 +2089,8 @@ ModChannel* Client::getModChannel(const std::string &channel)
{
return m_modchannel_mgr->getModChannel(channel);
}

const std::string &Client::getFormspecPrepend() const
{
return m_env.getLocalPlayer()->formspec_prepend;
}
25 changes: 9 additions & 16 deletions src/client/client.h
Expand Up @@ -23,18 +23,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include <ostream>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <unordered_set>
#include "clientobject.h"
#include "gamedef.h"
#include "inventorymanager.h"
#include "localplayer.h"
#include "client/hud.h"
#include "particles.h"
#include "mapnode.h"
#include "tileanimation.h"
#include "mesh_generator_thread.h"
#include "network/address.h"
#include "network/peerhandler.h"
#include "gameparams.h"
Expand All @@ -61,10 +58,14 @@ struct MapDrawControl;
class ModChannelMgr;
class MtEventManager;
struct PointedThing;
struct MapNode;
class MapDatabase;
class Minimap;
struct MinimapMapblock;
class MeshUpdateManager;
class ParticleManager;
class Camera;
struct PlayerControl;
class NetworkPacket;
namespace con {
class Connection;
Expand Down Expand Up @@ -315,8 +316,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server=false, bool urgent=false);
void addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server=false, bool urgent=false);

void updateCameraOffset(v3s16 camera_offset)
{ m_mesh_update_manager.m_camera_offset = camera_offset; }
void updateCameraOffset(v3s16 camera_offset);

bool hasClientEvents() const { return !m_client_event_queue.empty(); }
// Get event from queue. If queue is empty, it triggers an assertion failure.
Expand Down Expand Up @@ -436,10 +436,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
const std::string &message) override;
ModChannel *getModChannel(const std::string &channel) override;

const std::string &getFormspecPrepend() const
{
return m_env.getLocalPlayer()->formspec_prepend;
}
const std::string &getFormspecPrepend() const;
inline MeshGrid getMeshGrid()
{
return m_mesh_grid;
Expand Down Expand Up @@ -470,10 +467,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void sendGotBlocks(const std::vector<v3s16> &blocks);
void sendRemovedSounds(std::vector<s32> &soundList);

// Helper function
inline std::string getPlayerName()
{ return m_env.getLocalPlayer()->getName(); }

bool canSendChatMessage() const;

float m_packetcounter_timer = 0.0f;
Expand All @@ -491,9 +484,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
RenderingEngine *m_rendering_engine;


MeshUpdateManager m_mesh_update_manager;
std::unique_ptr<MeshUpdateManager> m_mesh_update_manager;
ClientEnvironment m_env;
ParticleManager m_particle_manager;
std::unique_ptr<ParticleManager> m_particle_manager;
std::unique_ptr<con::Connection> m_con;
std::string m_address_name;
ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
Expand Down
1 change: 1 addition & 0 deletions src/client/clientenvironment.cpp
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientenvironment.h"
#include "clientsimpleobject.h"
#include "clientmap.h"
#include "localplayer.h"
#include "scripting_client.h"
#include "mapblock_mesh.h"
#include "mtevent.h"
Expand Down
1 change: 1 addition & 0 deletions src/client/clientmap.cpp
Expand Up @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <matrix4.h>
#include "mapsector.h"
#include "mapblock.h"
#include "nodedef.h"
#include "profiler.h"
#include "settings.h"
#include "camera.h" // CameraModes
Expand Down
1 change: 1 addition & 0 deletions src/client/content_cao.cpp
Expand Up @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/renderingengine.h"
#include "client/sound.h"
#include "client/tile.h"
#include "client/mapblock_mesh.h"
#include "util/basic_macros.h"
#include "util/numeric.h"
#include "util/serialize.h"
Expand Down
1 change: 1 addition & 0 deletions src/client/game.cpp
Expand Up @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/tile.h" // For TextureSource
#include "client/keys.h"
#include "client/joystick_controller.h"
#include "client/mapblock_mesh.h"
#include "clientmap.h"
#include "clouds.h"
#include "config.h"
Expand Down
2 changes: 2 additions & 0 deletions src/client/mapblock_mesh.cpp
Expand Up @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client.h"
#include "mapblock.h"
#include "map.h"
#include "noise.h"
#include "profiler.h"
#include "shader.h"
#include "mesh.h"
Expand All @@ -31,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/renderingengine.h"
#include <array>
#include <algorithm>
#include <cmath>

/*
MeshMakeData
Expand Down
9 changes: 5 additions & 4 deletions src/client/render/pipeline.cpp
Expand Up @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "pipeline.h"
#include "client/client.h"
#include "client/hud.h"
#include "IRenderTarget.h"

#include <vector>
#include <memory>
Expand Down Expand Up @@ -63,7 +64,7 @@ void TextureBuffer::setTexture(u8 index, v2f scale_factor, const std::string &na

if (m_definitions.size() <= index)
m_definitions.resize(index + 1);

auto &definition = m_definitions[index];
definition.valid = true;
definition.dirty = true;
Expand Down Expand Up @@ -99,7 +100,7 @@ void TextureBuffer::reset(PipelineContext &context)
ensureTexture(ptr, m_definitions[i], context);
m_definitions[i].dirty = false;
}

RenderSource::reset(context);
}

Expand All @@ -124,7 +125,7 @@ bool TextureBuffer::ensureTexture(video::ITexture **texture, const TextureDefini
size = core::dimension2du(
(u32)(context.target_size.X * definition.scale_factor.X),
(u32)(context.target_size.Y * definition.scale_factor.Y));

modify = definition.dirty || (*texture == nullptr) || (*texture)->getSize() != size;
}
else {
Expand Down Expand Up @@ -283,7 +284,7 @@ void RenderPipeline::run(PipelineContext &context)

for (auto &step: m_pipeline)
step->run(context);

context.target_size = original_size;
}

Expand Down
1 change: 1 addition & 0 deletions src/client/render/secondstage.cpp
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/client.h"
#include "client/shader.h"
#include "client/tile.h"
#include "settings.h"

PostProcessingStep::PostProcessingStep(u32 _shader_id, const std::vector<u8> &_texture_map) :
shader_id(_shader_id), texture_map(_texture_map)
Expand Down
3 changes: 3 additions & 0 deletions src/client/shadows/dynamicshadowsrender.cpp
Expand Up @@ -29,6 +29,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/client.h"
#include "client/clientmap.h"
#include "profiler.h"
#include "EShaderTypes.h"
#include "IGPUProgrammingServices.h"
#include "IMaterialRenderer.h"

ShadowRenderer::ShadowRenderer(IrrlichtDevice *device, Client *client) :
m_smgr(device->getSceneManager()), m_driver(device->getVideoDriver()),
Expand Down
2 changes: 1 addition & 1 deletion src/environment.h
Expand Up @@ -35,8 +35,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <atomic>
#include <mutex>
#include "irr_v3d.h"
#include "network/networkprotocol.h" // for AccessDeniedCode
#include "util/basic_macros.h"
#include "line3d.h"

class IGameDef;
class Map;
Expand Down
1 change: 1 addition & 0 deletions src/gui/guiFormSpecMenu.h
Expand Up @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "irrlichttypes_extrabloated.h"
#include "irr_ptr.h"
#include "inventory.h"
#include "inventorymanager.h"
#include "modalMenu.h"
#include "guiInventoryList.h"
Expand Down
1 change: 1 addition & 0 deletions src/gui/guiHyperText.cpp
Expand Up @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/client.h"
#include "client/renderingengine.h"
#include "hud.h"
#include "inventory.h"
#include "util/string.h"
#include "irrlicht_changes/CGUITTFont.h"

Expand Down

0 comments on commit 8b73743

Please sign in to comment.