diff options
author | Vincent Glize <vincentglize@hotmail.fr> | 2017-06-19 23:54:58 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-06-19 23:54:58 +0200 |
commit | 4a5e8ad343079f6552fab639770e5771ed7c4e7a (patch) | |
tree | eeab3adec1fc3e7a3b06d9f53b92ab99a5e0d290 | |
parent | 4a789490834157baa8788a2f36c95b86c1e4440e (diff) | |
download | minetest-4a5e8ad343079f6552fab639770e5771ed7c4e7a.tar.gz minetest-4a5e8ad343079f6552fab639770e5771ed7c4e7a.tar.bz2 minetest-4a5e8ad343079f6552fab639770e5771ed7c4e7a.zip |
C++11 cleanup on constructors (#6000)
* C++11 cleanup on constructors dir script
40 files changed, 117 insertions, 180 deletions
diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 722359066..5cca5fc03 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -34,13 +34,6 @@ extern "C" { #include "common/c_internal.h" /******************************************************************************/ -AsyncEngine::AsyncEngine() : - initDone(false), - jobIdCounter(0) -{ -} - -/******************************************************************************/ AsyncEngine::~AsyncEngine() { diff --git a/src/script/cpp_api/s_async.h b/src/script/cpp_api/s_async.h index 45f935d0a..94b55db6e 100644 --- a/src/script/cpp_api/s_async.h +++ b/src/script/cpp_api/s_async.h @@ -39,24 +39,18 @@ class AsyncEngine; // Data required to queue a job struct LuaJobInfo { - LuaJobInfo() : - serializedFunction(""), - serializedParams(""), - serializedResult(""), - id(0), - valid(false) - {} + LuaJobInfo() {}; // Function to be called in async environment - std::string serializedFunction; + std::string serializedFunction = ""; // Parameter to be passed to function - std::string serializedParams; + std::string serializedParams = ""; // Result of function call - std::string serializedResult; + std::string serializedResult = ""; // JobID used to identify a job and match it to callback - unsigned int id; + unsigned int id = 0; - bool valid; + bool valid = false; }; // Asynchronous working environment @@ -68,7 +62,7 @@ public: void *run(); private: - AsyncEngine *jobDispatcher; + AsyncEngine *jobDispatcher = nullptr; }; // Asynchornous thread and job management @@ -76,7 +70,7 @@ class AsyncEngine { friend class AsyncWorkerThread; typedef void (*StateInitializer)(lua_State *L, int top); public: - AsyncEngine(); + AsyncEngine() {}; ~AsyncEngine(); /** @@ -137,13 +131,13 @@ protected: private: // Variable locking the engine against further modification - bool initDone; + bool initDone = false; // Internal store for registred state initializers std::vector<StateInitializer> stateInitializers; // Internal counter to create job IDs - unsigned int jobIdCounter; + unsigned int jobIdCounter = 0; // Mutex to protect job queue std::mutex jobQueueMutex; diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 4d7461c5b..aaf26a9c3 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -71,9 +71,7 @@ public: ScriptApiBase */ -ScriptApiBase::ScriptApiBase() : - m_luastackmutex(), - m_gamedef(NULL) +ScriptApiBase::ScriptApiBase() { #ifdef SCRIPTAPI_LOCK_DEBUG m_lock_recursion_count = 0; @@ -111,14 +109,6 @@ ScriptApiBase::ScriptApiBase() : lua_pushstring(m_luastack, porting::getPlatformName()); lua_setglobal(m_luastack, "PLATFORM"); - - // m_secure gets set to true inside - // ScriptApiSecurity::initializeSecurity(), if neccessary. - // Default to false otherwise - m_secure = false; - - m_environment = NULL; - m_guiengine = NULL; } ScriptApiBase::~ScriptApiBase() diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h index ed056db31..38ee9901b 100644 --- a/src/script/cpp_api/s_base.h +++ b/src/script/cpp_api/s_base.h @@ -119,7 +119,7 @@ protected: std::recursive_mutex m_luastackmutex; std::string m_last_run_mod; - bool m_secure; + bool m_secure = false; #ifdef SCRIPTAPI_LOCK_DEBUG int m_lock_recursion_count; std::thread::id m_owning_thread; @@ -128,11 +128,11 @@ protected: private: static int luaPanic(lua_State *L); - lua_State* m_luastack; + lua_State *m_luastack = nullptr; - IGameDef* m_gamedef; - Environment* m_environment; - GUIEngine* m_guiengine; + IGameDef *m_gamedef = nullptr; + Environment *m_environment = nullptr; + GUIEngine *m_guiengine = nullptr; }; #endif /* S_BASE_H_ */ diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp index b81985a7f..1e30e704e 100644 --- a/src/script/lua_api/l_areastore.cpp +++ b/src/script/lua_api/l_areastore.cpp @@ -300,20 +300,19 @@ int LuaAreaStore::l_from_file(lua_State *L) return deserialization_helper(L, o->as, is); } -LuaAreaStore::LuaAreaStore() +LuaAreaStore::LuaAreaStore() : as(AreaStore::getOptimalImplementation()) { - this->as = AreaStore::getOptimalImplementation(); } LuaAreaStore::LuaAreaStore(const std::string &type) { #if USE_SPATIAL if (type == "LibSpatial") { - this->as = new SpatialAreaStore(); + as = new SpatialAreaStore(); } else #endif { - this->as = new VectorAreaStore(); + as = new VectorAreaStore(); } } diff --git a/src/script/lua_api/l_areastore.h b/src/script/lua_api/l_areastore.h index 8292e7712..9cb6249d0 100644 --- a/src/script/lua_api/l_areastore.h +++ b/src/script/lua_api/l_areastore.h @@ -49,7 +49,7 @@ private: static int l_from_file(lua_State *L); public: - AreaStore *as; + AreaStore *as = nullptr; LuaAreaStore(); LuaAreaStore(const std::string &type); diff --git a/src/script/lua_api/l_camera.cpp b/src/script/lua_api/l_camera.cpp index 862384198..ef842a222 100644 --- a/src/script/lua_api/l_camera.cpp +++ b/src/script/lua_api/l_camera.cpp @@ -4,9 +4,8 @@ #include "content_cao.h" #include "camera.h" -LuaCamera::LuaCamera(Camera *m) +LuaCamera::LuaCamera(Camera *m) : m_camera(m) { - m_camera = m; } void LuaCamera::create(lua_State *L, Camera *m) diff --git a/src/script/lua_api/l_camera.h b/src/script/lua_api/l_camera.h index 04921ad03..c4a0f877c 100644 --- a/src/script/lua_api/l_camera.h +++ b/src/script/lua_api/l_camera.h @@ -26,7 +26,7 @@ private: static int l_get_look_horizontal(lua_State *L); static int l_get_aspect_ratio(lua_State *L); - Camera *m_camera; + Camera *m_camera = nullptr; public: LuaCamera(Camera *m); diff --git a/src/script/lua_api/l_itemstackmeta.h b/src/script/lua_api/l_itemstackmeta.h index 4ef64a91e..6e841d2dc 100644 --- a/src/script/lua_api/l_itemstackmeta.h +++ b/src/script/lua_api/l_itemstackmeta.h @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class ItemStackMetaRef : public MetaDataRef { private: - ItemStack *istack; + ItemStack *istack = nullptr; static const char className[]; static const luaL_Reg methods[]; diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 7ec4eaa62..7f932cbca 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -21,9 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "l_internal.h" #include "script/common/c_converter.h" -LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) +LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m) { - m_localplayer = m; } void LuaLocalPlayer::create(lua_State *L, LocalPlayer *m) diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h index e56ec808f..e618e6be5 100644 --- a/src/script/lua_api/l_localplayer.h +++ b/src/script/lua_api/l_localplayer.h @@ -67,7 +67,7 @@ private: static int l_get_movement(lua_State *L); - LocalPlayer *m_localplayer; + LocalPlayer *m_localplayer = nullptr; public: LuaLocalPlayer(LocalPlayer *m); diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index afb3766fb..be981c884 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -24,9 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "minimap.h" #include "settings.h" -LuaMinimap::LuaMinimap(Minimap *m) +LuaMinimap::LuaMinimap(Minimap *m) : m_minimap(m) { - m_minimap = m; } void LuaMinimap::create(lua_State *L, Minimap *m) diff --git a/src/script/lua_api/l_minimap.h b/src/script/lua_api/l_minimap.h index ba702b0b1..d4fbf6330 100644 --- a/src/script/lua_api/l_minimap.h +++ b/src/script/lua_api/l_minimap.h @@ -48,7 +48,7 @@ private: static int l_set_shape(lua_State *L); static int l_get_shape(lua_State *L); - Minimap *m_minimap; + Minimap *m_minimap = nullptr; public: LuaMinimap(Minimap *m); diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 5dfa6d52e..aa8d1c453 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -171,14 +171,12 @@ bool NodeMetaRef::handleFromTable(lua_State *L, int table, Metadata *_meta) NodeMetaRef::NodeMetaRef(v3s16 p, ServerEnvironment *env): m_p(p), - m_env(env), - m_is_local(false) + m_env(env) { } NodeMetaRef::NodeMetaRef(Metadata *meta): - m_meta(meta), - m_is_local(true) + m_meta(meta) { } diff --git a/src/script/lua_api/l_nodemeta.h b/src/script/lua_api/l_nodemeta.h index dd4260ff9..72d26ef36 100644 --- a/src/script/lua_api/l_nodemeta.h +++ b/src/script/lua_api/l_nodemeta.h @@ -34,9 +34,9 @@ class NodeMetadata; class NodeMetaRef : public MetaDataRef { private: v3s16 m_p; - ServerEnvironment *m_env; - Metadata *m_meta; - bool m_is_local; + ServerEnvironment *m_env = nullptr; + Metadata *m_meta = nullptr; + bool m_is_local = false; static const char className[]; static const luaL_Reg methodsServer[]; diff --git a/src/script/lua_api/l_nodetimer.h b/src/script/lua_api/l_nodetimer.h index ae362d8b3..df77ed98f 100644 --- a/src/script/lua_api/l_nodetimer.h +++ b/src/script/lua_api/l_nodetimer.h @@ -29,7 +29,7 @@ class NodeTimerRef : public ModApiBase { private: v3s16 m_p; - ServerEnvironment *m_env; + ServerEnvironment *m_env = nullptr; static const char className[]; static const luaL_Reg methods[]; diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index 9801ce02b..77874f00c 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -33,16 +33,29 @@ class RemotePlayer; */ class ObjectRef : public ModApiBase { -private: - ServerActiveObject *m_object; - - static const char className[]; - static const luaL_Reg methods[]; public: + ObjectRef(ServerActiveObject *object); + + ~ObjectRef(); + + // Creates an ObjectRef and leaves it on top of stack + // Not callable from Lua; all references are created on the C side. + static void create(lua_State *L, ServerActiveObject *object); + + static void set_null(lua_State *L); + + static void Register(lua_State *L); + static ObjectRef *checkobject(lua_State *L, int narg); static ServerActiveObject* getobject(ObjectRef *ref); private: + ServerActiveObject *m_object = nullptr; + + static const char className[]; + static const luaL_Reg methods[]; + + static LuaEntitySAO* getluaobject(ObjectRef *ref); static PlayerSAO* getplayersao(ObjectRef *ref); @@ -319,18 +332,6 @@ private: // get_nametag_attributes(self) static int l_get_nametag_attributes(lua_State *L); -public: - ObjectRef(ServerActiveObject *object); - - ~ObjectRef(); - - // Creates an ObjectRef and leaves it on top of stack - // Not callable from Lua; all references are created on the C side. - static void create(lua_State *L, ServerActiveObject *object); - - static void set_null(lua_State *L); - - static void Register(lua_State *L); }; #endif /* L_OBJECT_H_ */ diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index 70807f3d2..3dc5c9574 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -32,9 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., LuaSettings::LuaSettings(Settings *settings, const std::string &filename) : m_settings(settings), - m_filename(filename), - m_is_own_settings(false), - m_write_allowed(true) + m_filename(filename) { } diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h index 54b003ab3..a664b4494 100644 --- a/src/script/lua_api/l_settings.h +++ b/src/script/lua_api/l_settings.h @@ -57,10 +57,10 @@ private: // to_table(self) -> {[key1]=value1,...} static int l_to_table(lua_State *L); - Settings *m_settings; + Settings *m_settings = nullptr; std::string m_filename; - bool m_is_own_settings; - bool m_write_allowed; + bool m_is_own_settings = false; + bool m_write_allowed = true; public: LuaSettings(Settings *settings, const std::string &filename); diff --git a/src/script/lua_api/l_storage.h b/src/script/lua_api/l_storage.h index ec6f8d941..eaf7ec9f6 100644 --- a/src/script/lua_api/l_storage.h +++ b/src/script/lua_api/l_storage.h @@ -38,7 +38,7 @@ public: class StorageRef : public MetaDataRef { private: - ModMetadata *m_object; + ModMetadata *m_object = nullptr; static const char className[]; static const luaL_Reg methods[]; diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 254a7e5a6..ed5042bcf 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -365,22 +365,17 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L) return 2; } -LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) +LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) : vm(mmvm), is_mapgen_vm(is_mg_vm) { - this->vm = mmvm; - this->is_mapgen_vm = is_mg_vm; } -LuaVoxelManip::LuaVoxelManip(Map *map) +LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map)) { - this->vm = new MMVManip(map); - this->is_mapgen_vm = false; } LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2) { - this->vm = new MMVManip(map); - this->is_mapgen_vm = false; + vm = new MMVManip(map); v3s16 bp1 = getNodeBlockPos(p1); v3s16 bp2 = getNodeBlockPos(p2); diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index b6a69f36a..e706f3727 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -35,7 +35,7 @@ class LuaVoxelManip : public ModApiBase { private: std::map<v3s16, MapBlock *> modified_blocks; - bool is_mapgen_vm; + bool is_mapgen_vm = false; static const char className[]; static const luaL_Reg methods[]; @@ -65,7 +65,7 @@ private: static int l_get_emerged_area(lua_State *L); public: - MMVManip *vm; + MMVManip *vm = nullptr; LuaVoxelManip(MMVManip *mmvm, bool is_mapgen_vm); LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2); diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index cc4d65656..8f54fb762 100644 --- a/src/threading/thread.cpp +++ b/src/threading/thread.cpp @@ -60,8 +60,6 @@ DEALINGS IN THE SOFTWARE. Thread::Thread(const std::string &name) : m_name(name), - m_retval(NULL), - m_joinable(false), m_request_stop(false), m_running(false) { @@ -130,7 +128,7 @@ bool Thread::wait() m_thread_obj->join(); delete m_thread_obj; - m_thread_obj = NULL; + m_thread_obj = nullptr; assert(m_running == false); m_joinable = false; @@ -162,7 +160,7 @@ bool Thread::kill() wait(); #endif - m_retval = NULL; + m_retval = nullptr; m_joinable = false; m_request_stop = false; diff --git a/src/threading/thread.h b/src/threading/thread.h index 284c8e46c..dab5d0ec7 100644 --- a/src/threading/thread.h +++ b/src/threading/thread.h @@ -145,8 +145,8 @@ private: static void threadProc(Thread *thr); - void *m_retval; - bool m_joinable; + void *m_retval = nullptr; + bool m_joinable = false; std::atomic<bool> m_request_stop; std::atomic<bool> m_running; std::mutex m_mutex; diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 570807ba7..911b647f7 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -70,16 +70,16 @@ public: virtual void unregisterModStorage(const std::string &name) {} private: - IItemDefManager *m_itemdef; - INodeDefManager *m_nodedef; - ICraftDefManager *m_craftdef; - ITextureSource *m_texturesrc; - IShaderSource *m_shadersrc; - ISoundManager *m_soundmgr; - MtEventManager *m_eventmgr; - scene::ISceneManager *m_scenemgr; - IRollbackManager *m_rollbackmgr; - EmergeManager *m_emergemgr; + IItemDefManager *m_itemdef = nullptr; + INodeDefManager *m_nodedef = nullptr; + ICraftDefManager *m_craftdef = nullptr; + ITextureSource *m_texturesrc = nullptr; + IShaderSource *m_shadersrc = nullptr; + ISoundManager *m_soundmgr = nullptr; + MtEventManager *m_eventmgr = nullptr; + scene::ISceneManager *m_scenemgr = nullptr; + IRollbackManager *m_rollbackmgr = nullptr; + EmergeManager *m_emergemgr = nullptr; }; diff --git a/src/unittest/test_connection.cpp b/src/unittest/test_connection.cpp index d63322d69..3ea3d7444 100644 --- a/src/unittest/test_connection.cpp +++ b/src/unittest/test_connection.cpp @@ -53,12 +53,7 @@ void TestConnection::runTests(IGameDef *gamedef) struct Handler : public con::PeerHandler { - Handler(const char *a_name) - { - count = 0; - last_id = 0; - name = a_name; - } + Handler(const char *a_name) : name(a_name) {} void peerAdded(con::Peer *peer) { @@ -76,8 +71,8 @@ struct Handler : public con::PeerHandler count--; } - s32 count; - u16 last_id; + s32 count = 0; + u16 last_id = 0; const char *name; }; diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp index cef67da2c..c660502f6 100644 --- a/src/util/areastore.cpp +++ b/src/util/areastore.cpp @@ -58,7 +58,7 @@ const Area *AreaStore::getArea(u32 id) const { AreaMap::const_iterator it = areas_map.find(id); if (it == areas_map.end()) - return NULL; + return nullptr; return &it->second; } @@ -239,7 +239,7 @@ bool SpatialAreaStore::insertArea(Area *a) if (!areas_map.insert(std::make_pair(a->id, *a)).second) // ID is not unique return false; - m_tree->insertData(0, NULL, get_spatial_region(a->minedge, a->maxedge), a->id); + m_tree->insertData(0, nullptr, get_spatial_region(a->minedge, a->maxedge), a->id); invalidateCache(); return true; } diff --git a/src/util/areastore.h b/src/util/areastore.h index bebecfd78..8c22c3ad7 100644 --- a/src/util/areastore.h +++ b/src/util/areastore.h @@ -38,14 +38,14 @@ with this program; if not, write to the Free Software Foundation, Inc., struct Area { - Area() : id(U32_MAX) {} + Area() {} Area(const v3s16 &mine, const v3s16 &maxe) : - id(U32_MAX), minedge(mine), maxedge(maxe) + minedge(mine), maxedge(maxe) { sortBoxVerticies(minedge, maxedge); } - u32 id; + u32 id = U32_MAX; v3s16 minedge, maxedge; std::string data; }; @@ -54,10 +54,7 @@ struct Area { class AreaStore { public: AreaStore() : - m_cache_enabled(true), - m_cacheblock_radius(64), - m_res_cache(1000, &cacheMiss, this), - m_next_id(0) + m_res_cache(1000, &cacheMiss, this) {} virtual ~AreaStore() {} @@ -123,13 +120,13 @@ private: /// Called by the cache when a value isn't found in the cache. static void cacheMiss(void *data, const v3s16 &mpos, std::vector<Area *> *dest); - bool m_cache_enabled; + bool m_cache_enabled = true; /// Range, in nodes, of the getAreasForPos cache. /// If you modify this, call invalidateCache() - u8 m_cacheblock_radius; + u8 m_cacheblock_radius = 64; LRUCache<v3s16, std::vector<Area *> > m_res_cache; - u32 m_next_id; + u32 m_next_id = 0; }; @@ -165,8 +162,8 @@ protected: virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos); private: - SpatialIndex::ISpatialIndex *m_tree; - SpatialIndex::IStorageManager *m_storagemanager; + SpatialIndex::ISpatialIndex *m_tree = nullptr; + SpatialIndex::IStorageManager *m_storagemanager = nullptr; class VectorResultVisitor : public SpatialIndex::IVisitor { public: @@ -194,8 +191,8 @@ private: } private: - SpatialAreaStore *m_store; - std::vector<Area *> *m_result; + SpatialAreaStore *m_store = nullptr; + std::vector<Area *> *m_result = nullptr; }; }; diff --git a/src/util/auth.cpp b/src/util/auth.cpp index 912987259..c329e36e6 100644 --- a/src/util/auth.cpp +++ b/src/util/auth.cpp @@ -71,7 +71,7 @@ std::string generate_srp_verifier(const std::string &name, // get modified if &salt_ptr isn't NULL. char *salt_ptr = (char *)salt.c_str(); - char *bytes_v = NULL; + char *bytes_v = nullptr; size_t verifier_len = 0; gen_srp_v(name, password, &salt_ptr, &salt_len, &bytes_v, &verifier_len); std::string verifier = std::string(bytes_v, verifier_len); @@ -84,9 +84,9 @@ void generate_srp_verifier_and_salt(const std::string &name, const std::string &password, std::string *verifier, std::string *salt) { - char *bytes_v = NULL; + char *bytes_v = nullptr; size_t verifier_len; - char *salt_ptr = NULL; + char *salt_ptr = nullptr; size_t salt_len; gen_srp_v(name, password, &salt_ptr, &salt_len, &bytes_v, &verifier_len); *verifier = std::string(bytes_v, verifier_len); diff --git a/src/util/enriched_string.cpp b/src/util/enriched_string.cpp index a7fc3a828..05d7b8c25 100644 --- a/src/util/enriched_string.cpp +++ b/src/util/enriched_string.cpp @@ -30,8 +30,7 @@ EnrichedString::EnrichedString() EnrichedString::EnrichedString(const std::wstring &string, const std::vector<SColor> &colors): m_string(string), - m_colors(colors), - m_has_background(false) + m_colors(colors) {} EnrichedString::EnrichedString(const std::wstring &s, const SColor &color) diff --git a/src/util/enriched_string.h b/src/util/enriched_string.h index 1aca8948a..a3b8feb2a 100644 --- a/src/util/enriched_string.h +++ b/src/util/enriched_string.h @@ -84,7 +84,7 @@ public: private: std::wstring m_string; std::vector<irr::video::SColor> m_colors; - bool m_has_background; + bool m_has_background = false; irr::video::SColor m_background; }; diff --git a/src/util/numeric.h b/src/util/numeric.h index 3b1b85f64..5143c92e6 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -282,7 +282,7 @@ inline aabb3f getNodeBox(v3s16 p, float d) class IntervalLimiter { public: - IntervalLimiter() : m_accumulator(0) {} + IntervalLimiter() {} /* dtime: time from last call to this method wanted_interval: interval wanted @@ -300,7 +300,7 @@ public: } private: - float m_accumulator; + float m_accumulator = 0.0f; }; diff --git a/src/util/pointedthing.cpp b/src/util/pointedthing.cpp index ed3d4bb67..f1f1d3f20 100644 --- a/src/util/pointedthing.cpp +++ b/src/util/pointedthing.cpp @@ -23,16 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "../exceptions.h" #include <sstream> -PointedThing::PointedThing(): - type(POINTEDTHING_NOTHING), - node_undersurface(0,0,0), - node_abovesurface(0,0,0), - node_real_undersurface(0,0,0), - intersection_point(0,0,0), - intersection_normal(0,0,0), - object_id(-1) -{} - std::string PointedThing::dump() const { std::ostringstream os(std::ios::binary); diff --git a/src/util/pointedthing.h b/src/util/pointedthing.h index f695a4ebd..92c33968f 100644 --- a/src/util/pointedthing.h +++ b/src/util/pointedthing.h @@ -36,7 +36,7 @@ enum PointedThingType struct PointedThing { //! The type of the pointed object. - PointedThingType type; + PointedThingType type = POINTEDTHING_NOTHING; /*! * Only valid if type is POINTEDTHING_NODE. * The coordinates of the node which owns the @@ -74,9 +74,9 @@ struct PointedThing * Only valid if type is POINTEDTHING_OBJECT. * The ID of the object the ray hit. */ - s16 object_id; + s16 object_id = -1; - PointedThing(); + PointedThing() {}; std::string dump() const; void serialize(std::ostream &os) const; void deSerialize(std::istream &is); diff --git a/src/util/serialize.cpp b/src/util/serialize.cpp index 61d369bc4..75843cb1b 100644 --- a/src/util/serialize.cpp +++ b/src/util/serialize.cpp @@ -422,7 +422,7 @@ bool deSerializeStringToStruct(std::string valstr, char *fmtpos, *fmt = &format[0]; while ((f = strtok_r(fmt, ",", &fmtpos)) && s) { - fmt = NULL; + fmt = nullptr; bool is_unsigned = false; int width = 0; @@ -510,7 +510,7 @@ bool deSerializeStringToStruct(std::string valstr, bufpos += sizeof(std::string *); strs_alloced.push_back(str); - s = *snext ? snext + 1 : NULL; + s = *snext ? snext + 1 : nullptr; break; case 'v': while (*s == ' ' || *s == '\t') @@ -582,7 +582,7 @@ bool serializeStructToString(std::string *out, char *bufpos = (char *) value; char *fmtpos, *fmt = &format[0]; while ((f = strtok_r(fmt, ",", &fmtpos))) { - fmt = NULL; + fmt = nullptr; bool is_unsigned = false; int width = 0; char valtype = *f; diff --git a/src/util/serialize.h b/src/util/serialize.h index e22434191..f43480557 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -454,8 +454,7 @@ class BufReader { public: BufReader(const u8 *data_, size_t size_) : data(data_), - size(size_), - pos(0) + size(size_) { } @@ -515,7 +514,7 @@ public: const u8 *data; size_t size; - size_t pos; + size_t pos = 0; }; #undef MAKE_BUFREADER_GET_FXN diff --git a/src/util/sha1.cpp b/src/util/sha1.cpp index 6ed7385d5..c04b6c0c0 100644 --- a/src/util/sha1.cpp +++ b/src/util/sha1.cpp @@ -66,15 +66,6 @@ SHA1::SHA1() { // make sure that the data type is the right size assert( sizeof( Uint32 ) * 5 == 20 ); - - // initialize - H0 = 0x67452301; - H1 = 0xefcdab89; - H2 = 0x98badcfe; - H3 = 0x10325476; - H4 = 0xc3d2e1f0; - unprocessedBytes = 0; - size = 0; } // Destructor ******************************************************** diff --git a/src/util/sha1.h b/src/util/sha1.h index 0ac08c67b..a55f94f44 100644 --- a/src/util/sha1.h +++ b/src/util/sha1.h @@ -31,10 +31,14 @@ class SHA1 { private: // fields - Uint32 H0, H1, H2, H3, H4; + Uint32 H0 = 0x67452301; + Uint32 H1 = 0xefcdab89; + Uint32 H2 = 0x98badcfe; + Uint32 H3 = 0x10325476; + Uint32 H4 = 0xc3d2e1f0; unsigned char bytes[64]; - int unprocessedBytes; - Uint32 size; + int unprocessedBytes = 0; + Uint32 size = 0; void process(); public: diff --git a/src/util/timetaker.cpp b/src/util/timetaker.cpp index ac686c3a3..6079e5cca 100644 --- a/src/util/timetaker.cpp +++ b/src/util/timetaker.cpp @@ -27,7 +27,6 @@ TimeTaker::TimeTaker(const std::string &name, u64 *result, TimePrecision prec) { m_name = name; m_result = result; - m_running = true; m_precision = prec; m_time1 = porting::getTime(prec); } @@ -36,7 +35,7 @@ u64 TimeTaker::stop(bool quiet) { if (m_running) { u64 dtime = porting::getTime(m_precision) - m_time1; - if (m_result != NULL) { + if (m_result != nullptr) { (*m_result) += dtime; } else { if (!quiet) { diff --git a/src/util/timetaker.h b/src/util/timetaker.h index c10f4f535..34564ee4b 100644 --- a/src/util/timetaker.h +++ b/src/util/timetaker.h @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class TimeTaker { public: - TimeTaker(const std::string &name, u64 *result=NULL, + TimeTaker(const std::string &name, u64 *result=nullptr, TimePrecision prec=PRECISION_MILLI); ~TimeTaker() @@ -45,9 +45,9 @@ public: private: std::string m_name; u64 m_time1; - bool m_running; + bool m_running = true; TimePrecision m_precision; - u64 *m_result; + u64 *m_result = nullptr; }; #endif |