From 66479394037baa941cb06d75d3afc79ff4c717a2 Mon Sep 17 00:00:00 2001 From: Rogier Date: Tue, 10 Jan 2017 04:39:45 +0900 Subject: Performance fix + SAO factorization Original credits goes to @Rogier-5 * Merge common attributes between LuaEntitySAO & PlayerSAO to UnitSAO * Make some functions const * Improve some lists performance by returning const ref Signed-off-by: Loic Blot --- src/activeobject.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/activeobject.h') diff --git a/src/activeobject.h b/src/activeobject.h index 48f078d3f..fe6c08514 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -64,7 +64,7 @@ public: m_id(id) { } - + u16 getId() { return m_id; @@ -76,8 +76,8 @@ public: } virtual ActiveObjectType getType() const = 0; - virtual bool getCollisionBox(aabb3f *toset) = 0; - virtual bool collideWithObjects() = 0; + virtual bool getCollisionBox(aabb3f *toset) const = 0; + virtual bool collideWithObjects() const = 0; protected: u16 m_id; // 0 is invalid, "no id" }; -- cgit v1.2.3 From cf37a5569002e83cc4d6916b39118ceba134da1b Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Wed, 19 Apr 2017 00:36:30 +0200 Subject: Fix various variables passed by copy instead of const ref (#5610) Pointed by cppcheck --- src/activeobject.h | 2 +- src/client.cpp | 2 +- src/client.h | 2 +- src/content_cao.cpp | 2 +- src/content_cao.h | 2 +- src/filecache.h | 2 +- src/game.cpp | 18 ++++++++++-------- src/map.cpp | 7 ++++--- src/map.h | 8 +++----- src/mods.cpp | 2 +- src/mods.h | 5 +++-- src/shader.cpp | 4 ++-- src/treegen.cpp | 2 +- src/treegen.h | 2 +- 14 files changed, 31 insertions(+), 29 deletions(-) (limited to 'src/activeobject.h') diff --git a/src/activeobject.h b/src/activeobject.h index fe6c08514..71b9df514 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -43,7 +43,7 @@ enum ActiveObjectType { struct ActiveObjectMessage { - ActiveObjectMessage(u16 id_, bool reliable_=true, std::string data_=""): + ActiveObjectMessage(u16 id_, bool reliable_=true, const std::string &data_ = "") : id(id_), reliable(reliable_), datastring(data_) diff --git a/src/client.cpp b/src/client.cpp index 7b962cd94..3cea4fbf4 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -57,7 +57,7 @@ extern gui::IGUIEnvironment* guienv; Client::Client( IrrlichtDevice *device, const char *playername, - std::string password, + const std::string &password, MapDrawControl &control, IWritableTextureSource *tsrc, IWritableShaderSource *shsrc, diff --git a/src/client.h b/src/client.h index e7fcb597d..c55d7bcd5 100644 --- a/src/client.h +++ b/src/client.h @@ -245,7 +245,7 @@ public: Client( IrrlichtDevice *device, const char *playername, - std::string password, + const std::string &password, MapDrawControl &control, IWritableTextureSource *tsrc, IWritableShaderSource *shsrc, diff --git a/src/content_cao.cpp b/src/content_cao.cpp index ac283da88..3aa3bad97 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -1313,7 +1313,7 @@ void GenericCAO::updateTexturePos() } } -void GenericCAO::updateTextures(const std::string mod) +void GenericCAO::updateTextures(const std::string &mod) { ITextureSource *tsrc = m_client->tsrc(); diff --git a/src/content_cao.h b/src/content_cao.h index f30e90e21..a0601d692 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -200,7 +200,7 @@ public: void updateTexturePos(); - void updateTextures(const std::string mod); + void updateTextures(const std::string &mod); void updateAnimation(); diff --git a/src/filecache.h b/src/filecache.h index f390f71b7..627ab45ed 100644 --- a/src/filecache.h +++ b/src/filecache.h @@ -30,7 +30,7 @@ public: /* 'dir' is the file cache directory to use. */ - FileCache(std::string dir) : m_dir(dir) {} + FileCache(const std::string &dir) : m_dir(dir) {} bool update(const std::string &name, const std::string &data); bool load(const std::string &name, std::ostream &os); diff --git a/src/game.cpp b/src/game.cpp index f584a58ef..198baeca3 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -79,14 +79,15 @@ extern Profiler *g_profiler; Text input system */ -struct TextDestNodeMetadata : public TextDest { +struct TextDestNodeMetadata : public TextDest +{ TextDestNodeMetadata(v3s16 p, Client *client) { m_p = p; m_client = client; } // This is deprecated I guess? -celeron55 - void gotText(std::wstring text) + void gotText(const std::wstring &text) { std::string ntext = wide_to_utf8(text); infostream << "Submitting 'text' field of node at (" << m_p.X << "," @@ -104,13 +105,14 @@ struct TextDestNodeMetadata : public TextDest { Client *m_client; }; -struct TextDestPlayerInventory : public TextDest { +struct TextDestPlayerInventory : public TextDest +{ TextDestPlayerInventory(Client *client) { m_client = client; m_formname = ""; } - TextDestPlayerInventory(Client *client, std::string formname) + TextDestPlayerInventory(Client *client, const std::string &formname) { m_client = client; m_formname = formname; @@ -131,13 +133,13 @@ struct LocalFormspecHandler : public TextDest m_formname = formname; } - LocalFormspecHandler(std::string formname, Client *client): + LocalFormspecHandler(const std::string &formname, Client *client): m_client(client) { m_formname = formname; } - void gotText(std::wstring message) + void gotText(const std::wstring &message) { errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl; } @@ -1190,7 +1192,7 @@ protected: u16 port, const SubgameSpec &gamespec); bool initSound(); - bool createSingleplayerServer(const std::string map_dir, + bool createSingleplayerServer(const std::string &map_dir, const SubgameSpec &gamespec, u16 port, std::string *address); // Client creation @@ -1780,7 +1782,7 @@ bool Game::initSound() return true; } -bool Game::createSingleplayerServer(const std::string map_dir, +bool Game::createSingleplayerServer(const std::string &map_dir, const SubgameSpec &gamespec, u16 port, std::string *address) { showOverlayMessage(wgettext("Creating server..."), 0, 5); diff --git a/src/map.cpp b/src/map.cpp index b690ea3b3..3da96e77b 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1226,7 +1226,8 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) { /* ServerMap */ -ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge): +ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef, + EmergeManager *emerge): Map(dout_server, gamedef), settings_mgr(g_settings, savedir + DIR_DELIM + "map_meta.txt"), m_emerge(emerge), @@ -1936,7 +1937,7 @@ std::string ServerMap::getSectorDir(v2s16 pos, int layout) } } -v2s16 ServerMap::getSectorPos(std::string dirname) +v2s16 ServerMap::getSectorPos(const std::string &dirname) { unsigned int x = 0, y = 0; int r; @@ -1966,7 +1967,7 @@ v2s16 ServerMap::getSectorPos(std::string dirname) return pos; } -v3s16 ServerMap::getBlockPos(std::string sectordir, std::string blockfile) +v3s16 ServerMap::getBlockPos(const std::string §ordir, const std::string &blockfile) { v2s16 p2d = getSectorPos(sectordir); diff --git a/src/map.h b/src/map.h index ea8dc76d1..90f97db8b 100644 --- a/src/map.h +++ b/src/map.h @@ -360,7 +360,7 @@ public: /* savedir: directory to which map data should be saved */ - ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge); + ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge); ~ServerMap(); s32 mapType() const @@ -422,16 +422,14 @@ public: // returns something like "map/sectors/xxxxxxxx" std::string getSectorDir(v2s16 pos, int layout = 2); // dirname: final directory name - v2s16 getSectorPos(std::string dirname); - v3s16 getBlockPos(std::string sectordir, std::string blockfile); + v2s16 getSectorPos(const std::string &dirname); + v3s16 getBlockPos(const std::string §ordir, const std::string &blockfile); static std::string getBlockFilename(v3s16 p); /* Database functions */ static Database *createDatabase(const std::string &name, const std::string &savedir, Settings &conf); - // Verify we can read/write to the database - void verifyDatabase(); // Returns true if the database file does not exist bool loadFromFolders(); diff --git a/src/mods.cpp b/src/mods.cpp index 5a7dc6dca..6fce8e93d 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -347,7 +347,7 @@ ClientModConfiguration::ClientModConfiguration(const std::string &path): #endif #if USE_CURL -Json::Value getModstoreUrl(std::string url) +Json::Value getModstoreUrl(const std::string &url) { std::vector extra_headers; diff --git a/src/mods.h b/src/mods.h index c9bd51d99..1e62db54d 100644 --- a/src/mods.h +++ b/src/mods.h @@ -146,9 +146,10 @@ public: #endif #if USE_CURL -Json::Value getModstoreUrl(std::string url); +Json::Value getModstoreUrl(const std::string &url); #else -inline Json::Value getModstoreUrl(std::string url) { +inline Json::Value getModstoreUrl(const std::string &url) +{ return Json::Value(); } #endif diff --git a/src/shader.cpp b/src/shader.cpp index 79485025b..66f32c9a1 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -340,7 +340,7 @@ IWritableShaderSource* createShaderSource(IrrlichtDevice *device) /* Generate shader given the shader name. */ -ShaderInfo generate_shader(std::string name, +ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype, IrrlichtDevice *device, std::vector &callbacks, const std::vector &setter_factories, @@ -525,7 +525,7 @@ void ShaderSource::rebuildShaders() } -ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype, +ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype, IrrlichtDevice *device, std::vector &callbacks, const std::vector &setter_factories, SourceShaderCache *sourcecache) diff --git a/src/treegen.cpp b/src/treegen.cpp index 505954e8e..8bf9619a0 100644 --- a/src/treegen.cpp +++ b/src/treegen.cpp @@ -113,7 +113,7 @@ void make_tree(MMVManip &vmanip, v3s16 p0, // L-System tree LUA spawner treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0, - INodeDefManager *ndef, TreeDef tree_definition) + INodeDefManager *ndef, const TreeDef &tree_definition) { ServerMap *map = &env->getServerMap(); std::map modified_blocks; diff --git a/src/treegen.h b/src/treegen.h index 4e6f95e67..8777c369c 100644 --- a/src/treegen.h +++ b/src/treegen.h @@ -73,7 +73,7 @@ namespace treegen { TreeDef tree_definition); // Spawn L-systems tree from LUA treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, - TreeDef tree_definition); + const TreeDef &tree_definition); // L-System tree gen helper functions void tree_node_placement(MMVManip &vmanip, v3f p0, -- cgit v1.2.3 From ce9802266ef1def339ec2e119c59090d0fd07c90 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 20 May 2017 08:15:56 +0200 Subject: Various code cleanup & little performance improvement on HTTP download (#5772) * Disable or remove unused enum members/functions * Tiny code style fixes * Make some functions const * Replace ClientMediaDownloader std::unordered_map with std::map --- src/activeobject.h | 6 +++--- src/camera.h | 20 ++------------------ src/chat.cpp | 5 ----- src/chat.h | 5 +---- src/client.cpp | 2 +- src/client.h | 3 +-- src/clientiface.cpp | 2 +- src/clientiface.h | 3 +-- src/clientmedia.cpp | 2 +- src/clientmedia.h | 3 ++- src/clientobject.h | 15 +++++---------- src/content_cao.cpp | 15 --------------- src/content_cao.h | 11 ----------- src/nodedef.cpp | 8 -------- src/nodedef.h | 3 --- 15 files changed, 18 insertions(+), 85 deletions(-) (limited to 'src/activeobject.h') diff --git a/src/activeobject.h b/src/activeobject.h index 71b9df514..f349ddef3 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -28,9 +28,9 @@ enum ActiveObjectType { ACTIVEOBJECT_TYPE_TEST = 1, // Deprecated stuff ACTIVEOBJECT_TYPE_ITEM = 2, - ACTIVEOBJECT_TYPE_RAT = 3, - ACTIVEOBJECT_TYPE_OERKKI1 = 4, - ACTIVEOBJECT_TYPE_FIREFLY = 5, +// ACTIVEOBJECT_TYPE_RAT = 3, +// ACTIVEOBJECT_TYPE_OERKKI1 = 4, +// ACTIVEOBJECT_TYPE_FIREFLY = 5, ACTIVEOBJECT_TYPE_MOBV2 = 6, // End deprecated stuff ACTIVEOBJECT_TYPE_LUAENTITY = 7, diff --git a/src/camera.h b/src/camera.h index ca2e4ddcc..1e4800cba 100644 --- a/src/camera.h +++ b/src/camera.h @@ -64,22 +64,6 @@ public: Client *client); ~Camera(); - // Get player scene node. - // This node is positioned at the player's torso (without any view bobbing), - // as given by Player::m_position. Yaw is applied but not pitch. - inline scene::ISceneNode* getPlayerNode() const - { - return m_playernode; - } - - // Get head scene node. - // It has the eye transformation and pitch applied, - // but no view bobbing. - inline scene::ISceneNode* getHeadNode() const - { - return m_headnode; - } - // Get camera scene node. // It has the eye transformation, pitch and view bobbing applied. inline scene::ICameraSceneNode* getCameraNode() const @@ -160,13 +144,13 @@ public: else m_camera_mode = CAMERA_MODE_FIRST; } - + // Set the current camera mode inline void setCameraMode(CameraMode mode) { m_camera_mode = mode; } - + //read the current camera mode inline CameraMode getCameraMode() { diff --git a/src/chat.cpp b/src/chat.cpp index de7483e22..f070e6e7b 100644 --- a/src/chat.cpp +++ b/src/chat.cpp @@ -77,11 +77,6 @@ u32 ChatBuffer::getLineCount() const return m_unformatted.size(); } -u32 ChatBuffer::getScrollback() const -{ - return m_scrollback; -} - const ChatLine& ChatBuffer::getLine(u32 index) const { assert(index < getLineCount()); // pre-condition diff --git a/src/chat.h b/src/chat.h index 5de676a2e..b7c6b74b9 100644 --- a/src/chat.h +++ b/src/chat.h @@ -86,8 +86,6 @@ public: // Get number of lines currently in buffer. u32 getLineCount() const; - // Get scrollback size, maximum number of lines in buffer. - u32 getScrollback() const; // Get reference to i-th chat line. const ChatLine& getLine(u32 index) const; @@ -162,8 +160,7 @@ public: std::wstring getLine() const { return m_line; } // Get section of line that is currently selected - std::wstring getSelection() const - { return m_line.substr(m_cursor, m_cursor_len); } + std::wstring getSelection() const { return m_line.substr(m_cursor, m_cursor_len); } // Clear the current line void clear(); diff --git a/src/client.cpp b/src/client.cpp index 5f2d2d9d2..a36f5413f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1723,7 +1723,7 @@ float Client::getRTT() float Client::getCurRate() { - return ( m_con.getLocalStat(con::CUR_INC_RATE) + + return (m_con.getLocalStat(con::CUR_INC_RATE) + m_con.getLocalStat(con::CUR_DL_RATE)); } diff --git a/src/client.h b/src/client.h index 11b670977..cc0d4699d 100644 --- a/src/client.h +++ b/src/client.h @@ -467,8 +467,7 @@ public: Minimap* getMinimap() { return m_minimap; } void setCamera(Camera* camera) { m_camera = camera; } - Camera* getCamera () - { return m_camera; } + Camera* getCamera () { return m_camera; } bool shouldShowMinimap() const; diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 78339055f..356281ca6 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -590,7 +590,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event) } } -u32 RemoteClient::uptime() +u32 RemoteClient::uptime() const { return porting::getTime(PRECISION_SECONDS) - m_connection_time; } diff --git a/src/clientiface.h b/src/clientiface.h index 49101fbc1..a219ed5fc 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -345,7 +345,7 @@ public: { serialization_version = m_pending_serialization_version; } /* get uptime */ - u32 uptime(); + u32 uptime() const; /* set version information */ void setVersionInfo(u8 major, u8 minor, u8 patch, const std::string &full) @@ -360,7 +360,6 @@ public: u8 getMajor() const { return m_version_major; } u8 getMinor() const { return m_version_minor; } u8 getPatch() const { return m_version_patch; } - std::string getVersion() const { return m_full_version; } private: // Version is stored in here after INIT before INIT2 u8 m_pending_serialization_version; diff --git a/src/clientmedia.cpp b/src/clientmedia.cpp index 14a38ca66..9c1e430df 100644 --- a/src/clientmedia.cpp +++ b/src/clientmedia.cpp @@ -348,7 +348,7 @@ void ClientMediaDownloader::remoteMediaReceived( std::string name; { - std::map::iterator it = + UNORDERED_MAP::iterator it = m_remote_file_transfers.find(fetch_result.request_id); assert(it != m_remote_file_transfers.end()); name = it->second; diff --git a/src/clientmedia.h b/src/clientmedia.h index e292be5ea..3c96dfe8a 100644 --- a/src/clientmedia.h +++ b/src/clientmedia.h @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "util/cpp11_container.h" class Client; struct HTTPFetchResult; @@ -137,7 +138,7 @@ private: s32 m_httpfetch_active; s32 m_httpfetch_active_limit; s32 m_outstanding_hash_sets; - std::map m_remote_file_transfers; + UNORDERED_MAP m_remote_file_transfers; // All files up to this name have either been received from a // remote server or failed on all remote servers, so those files diff --git a/src/clientobject.h b/src/clientobject.h index 1db5bcf24..aa0ec9c56 100644 --- a/src/clientobject.h +++ b/src/clientobject.h @@ -49,18 +49,13 @@ public: virtual aabb3f *getSelectionBox() { return NULL; } virtual bool getCollisionBox(aabb3f *toset) const { return false; } virtual bool collideWithObjects() const { return false; } - virtual v3f getPosition(){return v3f(0,0,0);} - virtual float getYaw() const {return 0;} - virtual scene::ISceneNode *getSceneNode(){return NULL;} - virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;} - virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;} - virtual WieldMeshSceneNode *getWieldMeshSceneNode(){return NULL;} - virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;} - virtual bool isPlayer() const {return false;} + virtual v3f getPosition(){ return v3f(0,0,0); } + virtual float getYaw() const { return 0; } + virtual scene::ISceneNode *getSceneNode() { return NULL; } + virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() { return NULL; } virtual bool isLocalPlayer() const {return false;} - virtual void setAttachments(){} + virtual void setAttachments() {} virtual bool doShowSelectionBox(){return true;} - virtual void updateCameraOffset(v3s16 camera_offset){}; // Step object in time virtual void step(float dtime, ClientEnvironment *env){} diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 4dde2bb7b..5690ecf1e 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -706,26 +706,11 @@ scene::ISceneNode* GenericCAO::getSceneNode() return NULL; } -scene::IMeshSceneNode* GenericCAO::getMeshSceneNode() -{ - return m_meshnode; -} - scene::IAnimatedMeshSceneNode* GenericCAO::getAnimatedMeshSceneNode() { return m_animated_meshnode; } -WieldMeshSceneNode* GenericCAO::getWieldMeshSceneNode() -{ - return m_wield_meshnode; -} - -scene::IBillboardSceneNode* GenericCAO::getSpriteSceneNode() -{ - return m_spritenode; -} - void GenericCAO::setChildrenVisible(bool toset) { for (std::vector::size_type i = 0; i < m_children.size(); i++) { diff --git a/src/content_cao.h b/src/content_cao.h index 3be753529..412cdff12 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -146,19 +146,8 @@ public: scene::ISceneNode *getSceneNode(); - scene::IMeshSceneNode *getMeshSceneNode(); - scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(); - WieldMeshSceneNode *getWieldMeshSceneNode(); - - scene::IBillboardSceneNode *getSpriteSceneNode(); - - inline bool isPlayer() const - { - return m_is_player; - } - inline bool isLocalPlayer() const { return m_is_local_player; diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 2ac59f8ae..98b34ea9e 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -881,7 +881,6 @@ public: void serialize(std::ostream &os, u16 protocol_version) const; void deSerialize(std::istream &is); - inline virtual bool getNodeRegistrationStatus() const; inline virtual void setNodeRegistrationStatus(bool completed); virtual void pendNodeResolve(NodeResolver *nr); @@ -1805,13 +1804,6 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version) } } - -inline bool CNodeDefManager::getNodeRegistrationStatus() const -{ - return m_node_registration_complete; -} - - inline void CNodeDefManager::setNodeRegistrationStatus(bool completed) { m_node_registration_complete = completed; diff --git a/src/nodedef.h b/src/nodedef.h index 07a962ed0..4669df7f0 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -432,8 +432,6 @@ public: virtual void serialize(std::ostream &os, u16 protocol_version) const=0; - virtual bool getNodeRegistrationStatus() const=0; - virtual void pendNodeResolve(NodeResolver *nr)=0; virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0; virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0; @@ -491,7 +489,6 @@ public: virtual void serialize(std::ostream &os, u16 protocol_version) const=0; virtual void deSerialize(std::istream &is)=0; - virtual bool getNodeRegistrationStatus() const=0; virtual void setNodeRegistrationStatus(bool completed)=0; virtual void pendNodeResolve(NodeResolver *nr)=0; -- cgit v1.2.3