From f98bbe193e0093aca8d8957cec82fdbd28639915 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 20 Apr 2017 00:12:52 +0200 Subject: Fix various copy instead of const ref reported by cppcheck (part 3) (#5616) * Also remove 2 non declared but defined functions * Make some functions around const ref changes const --- src/network/connection.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/network/connection.h') diff --git a/src/network/connection.h b/src/network/connection.h index 5ee53b9d4..7ba0d086e 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -383,7 +383,7 @@ struct OutgoingPacket bool reliable; bool ack; - OutgoingPacket(u16 peer_id_, u8 channelnum_, SharedBuffer data_, + OutgoingPacket(u16 peer_id_, u8 channelnum_, const SharedBuffer &data_, bool reliable_,bool ack_=false): peer_id(peer_id_), channelnum(channelnum_), @@ -448,7 +448,7 @@ struct ConnectionCommand reliable = reliable_; } - void ack(u16 peer_id_, u8 channelnum_, SharedBuffer data_) + void ack(u16 peer_id_, u8 channelnum_, const SharedBuffer &data_) { type = CONCMD_ACK; peer_id = peer_id_; @@ -457,7 +457,7 @@ struct ConnectionCommand reliable = false; } - void createPeer(u16 peer_id_, SharedBuffer data_) + void createPeer(u16 peer_id_, const SharedBuffer &data_) { type = CONCMD_CREATE_PEER; peer_id = peer_id_; @@ -467,7 +467,7 @@ struct ConnectionCommand raw = true; } - void disableLegacy(u16 peer_id_, SharedBuffer data_) + void disableLegacy(u16 peer_id_, const SharedBuffer &data_) { type = CONCMD_DISABLE_LEGACY; peer_id = peer_id_; @@ -874,7 +874,7 @@ struct ConnectionEvent return "Invalid ConnectionEvent"; } - void dataReceived(u16 peer_id_, SharedBuffer data_) + void dataReceived(u16 peer_id_, const SharedBuffer &data_) { type = CONNEVENT_DATA_RECEIVED; peer_id = peer_id_; -- cgit v1.2.3 From 370354cc87937bbfb6f24aa062966af8e039cec0 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Fri, 21 Apr 2017 10:06:08 +0200 Subject: Fix various performance issues reported by cppcheck (#5628) * Also remove 1 non declared but defined functions --- src/clientmedia.cpp | 14 +++++----- src/clientmedia.h | 4 +-- src/guiEngine.cpp | 4 +-- src/guiEngine.h | 7 ++--- src/guiFormSpecMenu.h | 65 +++++++++++++++++++--------------------------- src/network/connection.cpp | 5 ++-- src/network/connection.h | 4 +-- src/settings.h | 33 +++++++++++------------ 8 files changed, 59 insertions(+), 77 deletions(-) (limited to 'src/network/connection.h') diff --git a/src/clientmedia.cpp b/src/clientmedia.cpp index bca3f67c2..14a38ca66 100644 --- a/src/clientmedia.cpp +++ b/src/clientmedia.cpp @@ -42,12 +42,12 @@ static std::string getMediaCacheDir() */ ClientMediaDownloader::ClientMediaDownloader(): - m_media_cache(getMediaCacheDir()) + m_media_cache(getMediaCacheDir()), + m_initial_step_done(false), + m_uncached_count(0), + m_uncached_received_count(0), + m_name_bound("") { - m_initial_step_done = false; - m_name_bound = ""; // works because "" is an invalid file name - m_uncached_count = 0; - m_uncached_received_count = 0; m_httpfetch_caller = HTTPFETCH_DISCARD; m_httpfetch_active = 0; m_httpfetch_active_limit = 0; @@ -69,7 +69,7 @@ ClientMediaDownloader::~ClientMediaDownloader() delete m_remotes[i]; } -void ClientMediaDownloader::addFile(std::string name, std::string sha1) +void ClientMediaDownloader::addFile(const std::string &name, const std::string &sha1) { assert(!m_initial_step_done); // pre-condition @@ -104,7 +104,7 @@ void ClientMediaDownloader::addFile(std::string name, std::string sha1) m_files.insert(std::make_pair(name, filestatus)); } -void ClientMediaDownloader::addRemoteServer(std::string baseurl) +void ClientMediaDownloader::addRemoteServer(const std::string &baseurl) { assert(!m_initial_step_done); // pre-condition diff --git a/src/clientmedia.h b/src/clientmedia.h index 1f0da70d9..e292be5ea 100644 --- a/src/clientmedia.h +++ b/src/clientmedia.h @@ -58,10 +58,10 @@ public: } // Add a file to the list of required file (but don't fetch it yet) - void addFile(std::string name, std::string sha1); + void addFile(const std::string &name, const std::string &sha1); // Add a remote server to the list; ignored if not built with cURL - void addRemoteServer(std::string baseurl); + void addRemoteServer(const std::string &baseurl); // Steps the media downloader: // - May load media into client by calling client->loadMedia() diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index e0ee00ad6..ebc4aac44 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -60,7 +60,7 @@ void TextDestGuiEngine::gotText(const StringMap &fields) } /******************************************************************************/ -void TextDestGuiEngine::gotText(std::wstring text) +void TextDestGuiEngine::gotText(const std::wstring &text) { m_engine->getScriptIface()->handleMainMenuEvent(wide_to_utf8(text)); } @@ -540,7 +540,7 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath, } /******************************************************************************/ -bool GUIEngine::downloadFile(std::string url, std::string target) +bool GUIEngine::downloadFile(const std::string &url, const std::string &target) { #if USE_CURL std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary); diff --git a/src/guiEngine.h b/src/guiEngine.h index 98e88574c..e7e5ca05d 100644 --- a/src/guiEngine.h +++ b/src/guiEngine.h @@ -80,7 +80,7 @@ public: * receive text/events transmitted by guiFormSpecMenu * @param text textual representation of event */ - void gotText(std::wstring text); + void gotText(const std::wstring &text); private: /** target to transmit data to */ @@ -260,14 +260,11 @@ private: * @param url url to download * @param target file to store to */ - static bool downloadFile(std::string url,std::string target); + static bool downloadFile(const std::string &url, const std::string &target); /** array containing pointers to current specified texture layers */ image_definition m_textures[TEX_LAYER_MAX]; - /** draw version string in topleft corner */ - void drawVersion(); - /** * specify text to appear as top left string * @param text to set diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h index 4bc2448d8..ec122b617 100644 --- a/src/guiFormSpecMenu.h +++ b/src/guiFormSpecMenu.h @@ -78,22 +78,19 @@ class GUIFormSpecMenu : public GUIModalMenu { struct ItemSpec { - ItemSpec() - { - i = -1; - } + ItemSpec() : + i(-1) + {} + ItemSpec(const InventoryLocation &a_inventoryloc, const std::string &a_listname, - s32 a_i) - { - inventoryloc = a_inventoryloc; - listname = a_listname; - i = a_i; - } - bool isValid() const - { - return i != -1; - } + s32 a_i) : + inventoryloc(a_inventoryloc), + listname(a_listname), + i(a_i) + {} + + bool isValid() const { return i != -1; } InventoryLocation inventoryloc; std::string listname; @@ -208,14 +205,13 @@ class GUIFormSpecMenu : public GUIModalMenu const std::wstring &default_text, int id) : fname(name), flabel(label), + fdefault(unescape_enriched(default_text)), fid(id), send(false), ftype(f_Unknown), is_exit(false) - { - //flabel = unescape_enriched(label); - fdefault = unescape_enriched(default_text); - } + {} + std::string fname; std::wstring flabel; std::wstring fdefault; @@ -239,17 +235,14 @@ class GUIFormSpecMenu : public GUIModalMenu }; struct TooltipSpec { - TooltipSpec() - { - } + TooltipSpec() {} TooltipSpec(std::string a_tooltip, irr::video::SColor a_bgcolor, irr::video::SColor a_color): + tooltip(utf8_to_wide(a_tooltip)), bgcolor(a_bgcolor), color(a_color) - { - //tooltip = unescape_enriched(utf8_to_wide(a_tooltip)); - tooltip = utf8_to_wide(a_tooltip); - } + {} + std::wstring tooltip; irr::video::SColor bgcolor; irr::video::SColor color; @@ -271,12 +264,11 @@ class GUIFormSpecMenu : public GUIModalMenu StaticTextSpec(const std::wstring &a_text, const core::rect &a_rect, gui::IGUIButton *a_parent_button): + text(a_text), rect(a_rect), parent_button(a_parent_button) - { - //text = unescape_enriched(a_text); - text = a_text; - } + {} + std::wstring text; core::rect rect; gui::IGUIButton *parent_button; @@ -550,22 +542,19 @@ private: class FormspecFormSource: public IFormSource { public: - FormspecFormSource(const std::string &formspec) - { - m_formspec = formspec; - } + FormspecFormSource(const std::string &formspec): + m_formspec(formspec) + {} ~FormspecFormSource() {} - void setForm(const std::string &formspec) { + void setForm(const std::string &formspec) + { m_formspec = FORMSPEC_VERSION_STRING + formspec; } - std::string getForm() - { - return m_formspec; - } + std::string getForm() { return m_formspec; } std::string m_formspec; }; diff --git a/src/network/connection.cpp b/src/network/connection.cpp index e11b4a953..f9a4821a6 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -930,7 +930,7 @@ void Peer::DecUseCount() delete this; } -void Peer::RTTStatistics(float rtt, std::string profiler_id, +void Peer::RTTStatistics(float rtt, const std::string &profiler_id, unsigned int num_samples) { if (m_last_rtt > 0) { @@ -969,8 +969,7 @@ void Peer::RTTStatistics(float rtt, std::string profiler_id, m_rtt.jitter_avg = m_rtt.jitter_avg * (num_samples/(num_samples-1)) + jitter * (1/num_samples); - if (profiler_id != "") - { + if (profiler_id != "") { g_profiler->graphAdd(profiler_id + "_rtt", rtt); g_profiler->graphAdd(profiler_id + "_jitter", jitter); } diff --git a/src/network/connection.h b/src/network/connection.h index 7ba0d086e..dc86d2293 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -732,8 +732,8 @@ class Peer { virtual void reportRTT(float rtt) {}; void RTTStatistics(float rtt, - std::string profiler_id="", - unsigned int num_samples=1000); + const std::string &profiler_id = "", + unsigned int num_samples = 1000); bool IncUseCount(); void DecUseCount(); diff --git a/src/settings.h b/src/settings.h index 777d0eff5..8c4f6e559 100644 --- a/src/settings.h +++ b/src/settings.h @@ -74,24 +74,21 @@ struct ValueSpec { }; struct SettingsEntry { - SettingsEntry() - { - group = NULL; - is_group = false; - } - - SettingsEntry(const std::string &value_) - { - value = value_; - group = NULL; - is_group = false; - } - - SettingsEntry(Settings *group_) - { - group = group_; - is_group = true; - } + SettingsEntry() : + group(NULL), + is_group(false) + {} + + SettingsEntry(const std::string &value_) : + value(value_), + group(NULL), + is_group(false) + {} + + SettingsEntry(Settings *group_) : + group(group_), + is_group(true) + {} std::string value; Settings *group; -- cgit v1.2.3 From f727f54192644f6427ac1b2c86df8c64c7c5fdf0 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 29 Apr 2017 14:36:55 +0200 Subject: Fix Travis/unittest broken since b662a45 --- src/client.cpp | 4 ++-- src/network/connection.cpp | 15 ++++++++------- src/network/connection.h | 2 +- src/unittest/test_connection.cpp | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/network/connection.h') diff --git a/src/client.cpp b/src/client.cpp index 43b58d819..48ebd2f2c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -769,7 +769,7 @@ void Client::initLocalMapSaving(const Address &address, void Client::ReceiveAll() { DSTACK(FUNCTION_NAME); - u32 start_ms = porting::getTimeMs(); + u64 start_ms = porting::getTimeMs(); for(;;) { // Limit time even if there would be huge amounts of data to @@ -1631,7 +1631,7 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress) // update the loading menu -- if neccessary bool do_draw = false; - u32 time_ms = targs->last_time_ms; + u64 time_ms = targs->last_time_ms; if (cur_percent != targs->last_percent) { targs->last_percent = cur_percent; time_ms = porting::getTimeMs(); diff --git a/src/network/connection.cpp b/src/network/connection.cpp index f9a4821a6..fb3ba92ae 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -54,7 +54,8 @@ Mutex log_message_mutex; #endif -static inline float CALC_DTIME(unsigned int lasttime, unsigned int curtime) { +static inline float CALC_DTIME(u64 lasttime, u64 curtime) +{ float value = ( curtime - lasttime) / 1000.0; return MYMAX(MYMIN(value,0.1),0.0); } @@ -981,7 +982,7 @@ void Peer::RTTStatistics(float rtt, const std::string &profiler_id, bool Peer::isTimedOut(float timeout) { MutexAutoLock lock(m_exclusive_access_mutex); - u32 current_time = porting::getTimeMs(); + u64 current_time = porting::getTimeMs(); float dtime = CALC_DTIME(m_last_timeout_check,current_time); m_last_timeout_check = current_time; @@ -1276,8 +1277,8 @@ void * ConnectionSendThread::run() LOG(dout_con<getDesc() <<"ConnectionSend thread started"<getDesc() << "]"); @@ -2046,8 +2047,8 @@ void * ConnectionReceiveThread::run() PROFILE(ThreadIdentifier << "ConnectionReceive: [" << m_connection->getDesc() << "]"); #ifdef DEBUG_CONNECTION_KBPS - u32 curtime = porting::getTimeMs(); - u32 lasttime = curtime; + u64 curtime = porting::getTimeMs(); + u64 lasttime = curtime; float debug_print_timer = 0.0; #endif @@ -2390,7 +2391,7 @@ SharedBuffer ConnectionReceiveThread::processPacket(Channel *channel, // only calculate rtt from straight sent packets if (p.resend_count == 0) { // Get round trip time - unsigned int current_time = porting::getTimeMs(); + u64 current_time = porting::getTimeMs(); // a overflow is quite unlikely but as it'd result in major // rtt miscalculation we handle it here diff --git a/src/network/connection.h b/src/network/connection.h index dc86d2293..3a8388522 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -175,7 +175,7 @@ struct BufferedPacket Buffer data; // Data of the packet, including headers float time; // Seconds from buffering the packet or re-sending float totaltime; // Seconds from buffering the packet - unsigned int absolute_send_time; + u64 absolute_send_time; Address address; // Sender or destination unsigned int resend_count; }; diff --git a/src/unittest/test_connection.cpp b/src/unittest/test_connection.cpp index 49e412fc8..d63322d69 100644 --- a/src/unittest/test_connection.cpp +++ b/src/unittest/test_connection.cpp @@ -305,7 +305,7 @@ void TestConnection::testConnectSendReceive() u16 peer_id = 132; u16 size = 0; bool received = false; - u32 timems0 = porting::getTimeMs(); + u64 timems0 = porting::getTimeMs(); for (;;) { if (porting::getTimeMs() - timems0 > 5000 || received) break; -- cgit v1.2.3 From d99b6fed5517797bfafe4bbb307963967f0ca749 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 26 May 2017 14:03:36 +0200 Subject: Time: Change old `u32` timestamps to 64-bit (#5818) MacOSX build fix + cleanups --- src/clientiface.cpp | 4 ++-- src/clientiface.h | 6 +++--- src/guiFormSpecMenu.cpp | 4 ++-- src/guiFormSpecMenu.h | 4 ++-- src/hud.cpp | 2 +- src/intlGUIEditBox.h | 2 +- src/map.cpp | 2 +- src/map.h | 2 +- src/network/connection.h | 2 +- src/profiler.cpp | 30 ++++++++++++++++++++++++++++++ src/profiler.h | 44 ++------------------------------------------ src/touchscreengui.cpp | 4 ++-- src/unittest/test.cpp | 8 ++++---- src/unittest/test.h | 4 ++-- src/util/timetaker.cpp | 23 ++++++++--------------- src/util/timetaker.h | 14 +++++++------- src/voxel.cpp | 12 ++++-------- src/voxel.h | 4 ++-- 18 files changed, 75 insertions(+), 96 deletions(-) (limited to 'src/network/connection.h') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 356281ca6..68bd4afe7 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -590,9 +590,9 @@ void RemoteClient::notifyEvent(ClientStateEvent event) } } -u32 RemoteClient::uptime() const +u64 RemoteClient::uptime() const { - return porting::getTime(PRECISION_SECONDS) - m_connection_time; + return porting::getTimeS() - m_connection_time; } ClientInterface::ClientInterface(con::Connection* con) diff --git a/src/clientiface.h b/src/clientiface.h index a219ed5fc..d2299c879 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -266,7 +266,7 @@ public: m_version_patch(0), m_full_version("unknown"), m_deployed_compression(0), - m_connection_time(porting::getTime(PRECISION_SECONDS)) + m_connection_time(porting::getTimeS()) { } ~RemoteClient() @@ -345,7 +345,7 @@ public: { serialization_version = m_pending_serialization_version; } /* get uptime */ - u32 uptime() const; + u64 uptime() const; /* set version information */ void setVersionInfo(u8 major, u8 minor, u8 patch, const std::string &full) @@ -432,7 +432,7 @@ private: /* time this client was created */ - const u32 m_connection_time; + const u64 m_connection_time; }; class ClientInterface { diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index 64642cf1f..971d505fd 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -2658,7 +2658,7 @@ void GUIFormSpecMenu::drawMenu() if (hovered != NULL) { s32 id = hovered->getID(); - u32 delta = 0; + u64 delta = 0; if (id == -1) { m_old_tooltip_id = id; m_old_tooltip = L""; @@ -3247,7 +3247,7 @@ bool GUIFormSpecMenu::DoubleClickDetection(const SEvent event) m_doubleclickdetect[1].time = porting::getTimeMs(); } else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) { - u32 delta = porting::getDeltaMs(m_doubleclickdetect[0].time, porting::getTimeMs()); + u64 delta = porting::getDeltaMs(m_doubleclickdetect[0].time, porting::getTimeMs()); if (delta > 400) { return false; } diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h index 18ccf1c3a..557a1cc9f 100644 --- a/src/guiFormSpecMenu.h +++ b/src/guiFormSpecMenu.h @@ -420,8 +420,8 @@ protected: v2s32 m_old_pointer; // Mouse position after previous mouse event gui::IGUIStaticText *m_tooltip_element; - u32 m_tooltip_show_delay; - s64 m_hovered_time; + u64 m_tooltip_show_delay; + u64 m_hovered_time; s32 m_old_tooltip_id; std::wstring m_old_tooltip; diff --git a/src/hud.cpp b/src/hud.cpp index 3e4162b64..72145b4da 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -626,7 +626,7 @@ void Hud::resizeHotbar() { } struct MeshTimeInfo { - s64 time; + u64 time; scene::IMesh *mesh; }; diff --git a/src/intlGUIEditBox.h b/src/intlGUIEditBox.h index e3ee15a30..bb617476c 100644 --- a/src/intlGUIEditBox.h +++ b/src/intlGUIEditBox.h @@ -155,7 +155,7 @@ namespace gui gui::IGUIFont *OverrideFont, *LastBreakFont; IOSOperator* Operator; - u32 BlinkStartTime; + u64 BlinkStartTime; s32 CursorPos; s32 HScrollPos, VScrollPos; // scroll position in characters u32 Max; diff --git a/src/map.cpp b/src/map.cpp index 63e1e4ccd..641b7d2dd 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -981,7 +981,7 @@ void Map::transformLiquids(std::map &modified_blocks, time_until_purge *= 1000; // seconds -> milliseconds - u32 curr_time = porting::getTime(PRECISION_MILLI); + u64 curr_time = porting::getTimeMs(); u32 prev_unprocessed = m_unprocessed_count; m_unprocessed_count = m_transforming_liquid.size(); diff --git a/src/map.h b/src/map.h index 7e597bef6..41a1a246b 100644 --- a/src/map.h +++ b/src/map.h @@ -343,7 +343,7 @@ protected: private: f32 m_transforming_liquid_loop_count_multiplier; u32 m_unprocessed_count; - u32 m_inc_trending_up_start_time; // milliseconds + u64 m_inc_trending_up_start_time; // milliseconds bool m_queue_size_timer_started; DISABLE_CLASS_COPY(Map); diff --git a/src/network/connection.h b/src/network/connection.h index 3a8388522..8b7ed9773 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -769,7 +769,7 @@ class Peer { // Seconds from last receive float m_timeout_counter; - u32 m_last_timeout_check; + u64 m_last_timeout_check; }; class UDPPeer : public Peer diff --git a/src/profiler.cpp b/src/profiler.cpp index 197e094f6..8e997442c 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -21,3 +21,33 @@ with this program; if not, write to the Free Software Foundation, Inc., static Profiler main_profiler; Profiler *g_profiler = &main_profiler; +ScopeProfiler::ScopeProfiler( + Profiler *profiler, const std::string &name, ScopeProfilerType type) + : m_profiler(profiler), m_name(name), m_timer(NULL), m_type(type) +{ + if (m_profiler) + m_timer = new TimeTaker(m_name); +} + +ScopeProfiler::~ScopeProfiler() +{ + if (!m_timer) + return; + + float duration_ms = m_timer->stop(true); + float duration = duration_ms / 1000.0; + if (m_profiler) { + switch (m_type) { + case SPT_ADD: + m_profiler->add(m_name, duration); + break; + case SPT_AVG: + m_profiler->avg(m_name, duration); + break; + case SPT_GRAPH_ADD: + m_profiler->graphAdd(m_name, duration); + break; + } + } + delete m_timer; +} diff --git a/src/profiler.h b/src/profiler.h index 6da115972..ce60c6262 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -193,48 +193,8 @@ class ScopeProfiler { public: ScopeProfiler(Profiler *profiler, const std::string &name, - enum ScopeProfilerType type = SPT_ADD): - m_profiler(profiler), - m_name(name), - m_timer(NULL), - m_type(type) - { - if(m_profiler) - m_timer = new TimeTaker(m_name.c_str()); - } - // name is copied - ScopeProfiler(Profiler *profiler, const char *name, - enum ScopeProfilerType type = SPT_ADD): - m_profiler(profiler), - m_name(name), - m_timer(NULL), - m_type(type) - { - if(m_profiler) - m_timer = new TimeTaker(m_name.c_str()); - } - ~ScopeProfiler() - { - if(m_timer) - { - float duration_ms = m_timer->stop(true); - float duration = duration_ms / 1000.0; - if(m_profiler){ - switch(m_type){ - case SPT_ADD: - m_profiler->add(m_name, duration); - break; - case SPT_AVG: - m_profiler->avg(m_name, duration); - break; - case SPT_GRAPH_ADD: - m_profiler->graphAdd(m_name, duration); - break; - } - } - delete m_timer; - } - } + ScopeProfilerType type = SPT_ADD); + ~ScopeProfiler(); private: Profiler *m_profiler; std::string m_name; diff --git a/src/touchscreengui.cpp b/src/touchscreengui.cpp index f32679ca4..0139b8c4f 100644 --- a/src/touchscreengui.cpp +++ b/src/touchscreengui.cpp @@ -922,7 +922,7 @@ bool TouchScreenGUI::doubleTapDetection() m_key_events[1].x = m_move_downlocation.X; m_key_events[1].y = m_move_downlocation.Y; - u32 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs()); + u64 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs()); if (delta > 400) return false; @@ -1006,7 +1006,7 @@ void TouchScreenGUI::step(float dtime) (!m_move_has_really_moved) && (!m_move_sent_as_mouse_event)) { - u32 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs()); + u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs()); if (delta > MIN_DIG_TIME_MS) { m_shootline = m_device diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 9d223b82d..570807ba7 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -229,7 +229,7 @@ bool run_tests() { DSTACK(FUNCTION_NAME); - u32 t1 = porting::getTime(PRECISION_MILLI); + u64 t1 = porting::getTimeMs(); TestGameDef gamedef; g_logger.setLevelSilenced(LL_ERROR, true); @@ -246,7 +246,7 @@ bool run_tests() num_total_tests_run += testmods[i]->num_tests_run; } - u32 tdiff = porting::getTime(PRECISION_MILLI) - t1; + u64 tdiff = porting::getTimeMs() - t1; g_logger.setLevelSilenced(LL_ERROR, false); @@ -273,12 +273,12 @@ bool run_tests() bool TestBase::testModule(IGameDef *gamedef) { rawstream << "======== Testing module " << getName() << std::endl; - u32 t1 = porting::getTime(PRECISION_MILLI); + u64 t1 = porting::getTimeMs(); runTests(gamedef); - u32 tdiff = porting::getTime(PRECISION_MILLI) - t1; + u64 tdiff = porting::getTimeMs() - t1; rawstream << "======== Module " << getName() << " " << (num_tests_failed ? "failed" : "passed") << " (" << num_tests_failed << " failures / " << num_tests_run << " tests) - " << tdiff diff --git a/src/unittest/test.h b/src/unittest/test.h index e60e657cc..bf76e8bb2 100644 --- a/src/unittest/test.h +++ b/src/unittest/test.h @@ -33,7 +33,7 @@ class TestFailedException : public std::exception { // Runs a unit test and reports results #define TEST(fxn, ...) do { \ - u32 t1 = porting::getTime(PRECISION_MILLI); \ + u64 t1 = porting::getTimeMs(); \ try { \ fxn(__VA_ARGS__); \ rawstream << "[PASS] "; \ @@ -46,7 +46,7 @@ class TestFailedException : public std::exception { num_tests_failed++; \ } \ num_tests_run++; \ - u32 tdiff = porting::getTime(PRECISION_MILLI) - t1; \ + u64 tdiff = porting::getTimeMs() - t1; \ rawstream << #fxn << " - " << tdiff << "ms" << std::endl; \ } while (0) diff --git a/src/util/timetaker.cpp b/src/util/timetaker.cpp index 0e92696ac..ac686c3a3 100644 --- a/src/util/timetaker.cpp +++ b/src/util/timetaker.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "../log.h" #include -TimeTaker::TimeTaker(const char *name, u32 *result, TimePrecision prec) +TimeTaker::TimeTaker(const std::string &name, u64 *result, TimePrecision prec) { m_name = name; m_result = result; @@ -32,18 +32,13 @@ TimeTaker::TimeTaker(const char *name, u32 *result, TimePrecision prec) m_time1 = porting::getTime(prec); } -u32 TimeTaker::stop(bool quiet) +u64 TimeTaker::stop(bool quiet) { - if(m_running) - { - u32 time2 = porting::getTime(m_precision); - u32 dtime = time2 - m_time1; - if(m_result != NULL) - { + if (m_running) { + u64 dtime = porting::getTime(m_precision) - m_time1; + if (m_result != NULL) { (*m_result) += dtime; - } - else - { + } else { if (!quiet) { static const char* const units[] = { "s" /* PRECISION_SECONDS */, @@ -62,10 +57,8 @@ u32 TimeTaker::stop(bool quiet) return 0; } -u32 TimeTaker::getTimerTime() +u64 TimeTaker::getTimerTime() { - u32 time2 = porting::getTime(m_precision); - u32 dtime = time2 - m_time1; - return dtime; + return porting::getTime(m_precision) - m_time1; } diff --git a/src/util/timetaker.h b/src/util/timetaker.h index 5512c205f..c10f4f535 100644 --- a/src/util/timetaker.h +++ b/src/util/timetaker.h @@ -30,24 +30,24 @@ with this program; if not, write to the Free Software Foundation, Inc., class TimeTaker { public: - TimeTaker(const char *name, u32 *result=NULL, - TimePrecision=PRECISION_MILLI); + TimeTaker(const std::string &name, u64 *result=NULL, + TimePrecision prec=PRECISION_MILLI); ~TimeTaker() { stop(); } - u32 stop(bool quiet=false); + u64 stop(bool quiet=false); - u32 getTimerTime(); + u64 getTimerTime(); private: - const char *m_name; - u32 m_time1; + std::string m_name; + u64 m_time1; bool m_running; TimePrecision m_precision; - u32 *m_result; + u64 *m_result; }; #endif diff --git a/src/voxel.cpp b/src/voxel.cpp index 87773b240..78efde5bb 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -27,14 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc., /* Debug stuff */ -u32 addarea_time = 0; -u32 emerge_time = 0; -u32 emerge_load_time = 0; -u32 clearflag_time = 0; -//u32 getwaterpressure_time = 0; -//u32 spreadwaterpressure_time = 0; -u32 updateareawaterpressure_time = 0; -u32 flowwater_pre_time = 0; +u64 addarea_time = 0; +u64 emerge_time = 0; +u64 emerge_load_time = 0; +u64 clearflag_time = 0; VoxelManipulator::VoxelManipulator(): diff --git a/src/voxel.h b/src/voxel.h index 58ad39be4..3a64ccc79 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -49,8 +49,8 @@ class INodeDefManager; /* Debug stuff */ -extern u32 emerge_time; -extern u32 emerge_load_time; +extern u64 emerge_time; +extern u64 emerge_load_time; /* This class resembles aabbox3d a lot, but has inclusive -- cgit v1.2.3