From 084cdea6862cb65fe4bb807a211a9e1c17cffec8 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 24 Dec 2016 14:26:03 +0100 Subject: Irrlicht 1.9 support --- src/guiChatConsole.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/guiChatConsole.cpp') diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index 8dd5ab032..867576175 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -630,7 +630,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) } else if(event.KeyInput.Char != 0 && !event.KeyInput.Control) { - #if (defined(__linux__)) + #if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9) wchar_t wc = L'_'; mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); prompt.input(wc); -- cgit v1.2.3 From 707e27b5c26b6c082abbd2f385a976c5bc8964fe Mon Sep 17 00:00:00 2001 From: Zeno- Date: Sun, 29 Jan 2017 19:26:00 +1000 Subject: Rename height to scale for openConsole() (#5139) For Game::openConsole() and GUIChatConsole::openConsole() the parameter name 'height' is misleading because it's actually a percentage of the screen/window height. --- src/game.cpp | 8 +++++--- src/guiChatConsole.cpp | 8 +++++--- src/guiChatConsole.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/guiChatConsole.cpp') diff --git a/src/game.cpp b/src/game.cpp index 07d429c6b..4b4597a7a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1372,7 +1372,7 @@ protected: void dropSelectedItem(); void openInventory(); - void openConsole(float height, const wchar_t *line=NULL); + void openConsole(float scale, const wchar_t *line=NULL); void toggleFreeMove(float *statustext_time); void toggleFreeMoveAlt(float *statustext_time, float *jump_timer); void toggleFast(float *statustext_time); @@ -2779,15 +2779,17 @@ void Game::openInventory() } -void Game::openConsole(float height, const wchar_t *line) +void Game::openConsole(float scale, const wchar_t *line) { + assert(scale > 0.0f && scale <= 1.0f); + #ifdef __ANDROID__ porting::showInputDialog(gettext("ok"), "", "", 2); m_android_chat_open = true; #else if (gui_chat_console->isOpenInhibited()) return; - gui_chat_console->openConsole(height); + gui_chat_console->openConsole(scale); if (line) { gui_chat_console->setCloseOnEnter(true); gui_chat_console->replaceAndAddToHistory(line); diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index 867576175..bea5571f4 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -116,11 +116,13 @@ GUIChatConsole::~GUIChatConsole() m_font->drop(); } -void GUIChatConsole::openConsole(f32 height) +void GUIChatConsole::openConsole(f32 scale) { + assert(scale > 0.0f && scale <= 1.0f); + m_open = true; - m_desired_height_fraction = height; - m_desired_height = height * m_screensize.Y; + m_desired_height_fraction = scale; + m_desired_height = scale * m_screensize.Y; reformatConsole(); m_animate_time_old = getTimeMs(); IGUIElement::setVisible(true); diff --git a/src/guiChatConsole.h b/src/guiChatConsole.h index 3013a1d31..4e3cae13f 100644 --- a/src/guiChatConsole.h +++ b/src/guiChatConsole.h @@ -41,7 +41,7 @@ public: // Open the console (height = desired fraction of screen size) // This doesn't open immediately but initiates an animation. // You should call isOpenInhibited() before this. - void openConsole(f32 height); + void openConsole(f32 scale); bool isOpen() const; -- cgit v1.2.3 From b662a4577d692329b9ca83525e6039f2ddcd1ac1 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 6 Mar 2016 14:31:16 -0500 Subject: Clean up getTime helpers This increases size of the getTime return values to 64 bits. It also removes the TimeGetter classes since the getTime functions are now very precise. --- src/client.cpp | 6 +- src/client/clientlauncher.cpp | 19 ----- src/client/clientlauncher.h | 36 -------- src/client/joystick_controller.cpp | 3 +- src/clientiface.cpp | 2 +- src/clientiface.h | 3 +- src/database-sqlite3.cpp | 2 +- src/gettime.h | 21 +---- src/guiChatConsole.cpp | 8 +- src/guiChatConsole.h | 2 +- src/guiFormSpecMenu.cpp | 8 +- src/guiFormSpecMenu.h | 4 +- src/guiTable.cpp | 2 +- src/guiTable.h | 2 +- src/hud.cpp | 6 +- src/main.cpp | 18 ---- src/map.cpp | 2 +- src/porting.cpp | 13 +++ src/porting.h | 163 ++++++++++++++++--------------------- src/touchscreengui.cpp | 2 +- src/touchscreengui.h | 2 +- src/util/timetaker.cpp | 8 +- 22 files changed, 116 insertions(+), 216 deletions(-) (limited to 'src/guiChatConsole.cpp') diff --git a/src/client.cpp b/src/client.cpp index 019693f1d..43b58d819 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1618,7 +1618,7 @@ float Client::mediaReceiveProgress() typedef struct TextureUpdateArgs { IrrlichtDevice *device; gui::IGUIEnvironment *guienv; - u32 last_time_ms; + u64 last_time_ms; u16 last_percent; const wchar_t* text_base; ITextureSource *tsrc; @@ -1634,7 +1634,7 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress) u32 time_ms = targs->last_time_ms; if (cur_percent != targs->last_percent) { targs->last_percent = cur_percent; - time_ms = getTimeMs(); + time_ms = porting::getTimeMs(); // only draw when the user will notice something: do_draw = (time_ms - targs->last_time_ms > 100); } @@ -1692,7 +1692,7 @@ void Client::afterContentReceived(IrrlichtDevice *device) TextureUpdateArgs tu_args; tu_args.device = device; tu_args.guienv = guienv; - tu_args.last_time_ms = getTimeMs(); + tu_args.last_time_ms = porting::getTimeMs(); tu_args.last_percent = 0; tu_args.text_base = wgettext("Initializing nodes"); tu_args.tsrc = m_tsrc; diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 249f6727a..be4e82134 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -51,22 +51,6 @@ bool noMenuActive() MainGameCallback *g_gamecallback = NULL; -// Instance of the time getter -static TimeGetter *g_timegetter = NULL; - -u32 getTimeMs() -{ - if (g_timegetter == NULL) - return 0; - return g_timegetter->getTime(PRECISION_MILLI); -} - -u32 getTime(TimePrecision prec) { - if (g_timegetter == NULL) - return 0; - return g_timegetter->getTime(prec); -} - ClientLauncher::~ClientLauncher() { if (receiver) @@ -96,9 +80,6 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) return false; } - // Create time getter - g_timegetter = new IrrlichtTimeGetter(device); - // Speed tests (done after irrlicht is loaded to get timer) if (cmd_args.getFlag("speedtests")) { dstream << "Running speed tests" << std::endl; diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h index ab22d7aaa..4ff77bc03 100644 --- a/src/client/clientlauncher.h +++ b/src/client/clientlauncher.h @@ -24,42 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/inputhandler.h" #include "gameparams.h" -// A small helper class -class TimeGetter -{ -public: - virtual u32 getTime(TimePrecision prec) = 0; -}; - -// A precise irrlicht one -class IrrlichtTimeGetter: public TimeGetter -{ -public: - IrrlichtTimeGetter(IrrlichtDevice *device): - m_device(device) - {} - u32 getTime(TimePrecision prec) - { - if (prec == PRECISION_MILLI) { - if (m_device == NULL) - return 0; - return m_device->getTimer()->getRealTime(); - } else { - return porting::getTime(prec); - } - } -private: - IrrlichtDevice *m_device; -}; -// Not so precise one which works without irrlicht -class SimpleTimeGetter: public TimeGetter -{ -public: - u32 getTime(TimePrecision prec) - { - return porting::getTime(prec); - } -}; class ClientLauncher { diff --git a/src/client/joystick_controller.cpp b/src/client/joystick_controller.cpp index cb9d64b9f..905ca6420 100644 --- a/src/client/joystick_controller.cpp +++ b/src/client/joystick_controller.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "keys.h" #include "settings.h" #include "gettime.h" +#include "porting.h" #include "../util/string.h" bool JoystickButtonCmb::isTriggered(const irr::SEvent::SJoystickEvent &ev) const @@ -199,7 +200,7 @@ bool JoystickController::handleEvent(const irr::SEvent::SJoystickEvent &ev) if (ev.Joystick != m_joystick_id) return false; - m_internal_time = getTimeMs() / 1000.f; + m_internal_time = porting::getTimeMs() / 1000.f; std::bitset keys_pressed; diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 64fa1c6b7..7f476f0ea 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -592,7 +592,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event) u32 RemoteClient::uptime() { - return getTime(PRECISION_SECONDS) - m_connection_time; + return porting::getTime(PRECISION_SECONDS) - m_connection_time; } ClientInterface::ClientInterface(con::Connection* con) diff --git a/src/clientiface.h b/src/clientiface.h index 11ebdaab6..49101fbc1 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "threading/mutex.h" #include "network/networkpacket.h" #include "util/cpp11_container.h" +#include "porting.h" #include #include @@ -265,7 +266,7 @@ public: m_version_patch(0), m_full_version("unknown"), m_deployed_compression(0), - m_connection_time(getTime(PRECISION_SECONDS)) + m_connection_time(porting::getTime(PRECISION_SECONDS)) { } ~RemoteClient() diff --git a/src/database-sqlite3.cpp b/src/database-sqlite3.cpp index 714f56c39..7bc87a7d0 100644 --- a/src/database-sqlite3.cpp +++ b/src/database-sqlite3.cpp @@ -71,7 +71,7 @@ int Database_SQLite3::busyHandler(void *data, int count) { s64 &first_time = reinterpret_cast(data)[0]; s64 &prev_time = reinterpret_cast(data)[1]; - s64 cur_time = getTimeMs(); + s64 cur_time = porting::getTimeMs(); if (count == 0) { first_time = cur_time; diff --git a/src/gettime.h b/src/gettime.h index b2f09a7bb..a93eee387 100644 --- a/src/gettime.h +++ b/src/gettime.h @@ -21,33 +21,18 @@ with this program; if not, write to the Free Software Foundation, Inc., #define GETTIME_HEADER #include "irrlichttypes.h" +#include +#include -/* - Get a millisecond counter value. - Precision depends on implementation. - Overflows at any value above 10000000. - Implementation of this is done in: - Normal build: main.cpp - Server build: servermain.cpp -*/ enum TimePrecision { - PRECISION_SECONDS = 0, + PRECISION_SECONDS, PRECISION_MILLI, PRECISION_MICRO, PRECISION_NANO }; -extern u32 getTimeMs(); -extern u32 getTime(TimePrecision prec); - -/* - Timestamp stuff -*/ - -#include -#include inline std::string getTimestamp() { diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index bea5571f4..b3c119555 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -55,7 +55,7 @@ GUIChatConsole::GUIChatConsole( m_client(client), m_menumgr(menumgr), m_screensize(v2u32(0,0)), - m_animate_time_old(0), + m_animate_time_old(porting::getTimeMs()), m_open(false), m_close_on_enter(false), m_height(0), @@ -71,8 +71,6 @@ GUIChatConsole::GUIChatConsole( m_font(NULL), m_fontsize(0, 0) { - m_animate_time_old = getTimeMs(); - // load background settings s32 console_alpha = g_settings->getS32("console_alpha"); m_background_color.setAlpha(clamp_u8(console_alpha)); @@ -124,7 +122,7 @@ void GUIChatConsole::openConsole(f32 scale) m_desired_height_fraction = scale; m_desired_height = scale * m_screensize.Y; reformatConsole(); - m_animate_time_old = getTimeMs(); + m_animate_time_old = porting::getTimeMs(); IGUIElement::setVisible(true); Environment->setFocus(this); m_menumgr->createdMenu(this); @@ -212,7 +210,7 @@ void GUIChatConsole::draw() } // Animation - u32 now = getTimeMs(); + u64 now = porting::getTimeMs(); animate(now - m_animate_time_old); m_animate_time_old = now; diff --git a/src/guiChatConsole.h b/src/guiChatConsole.h index 4e3cae13f..0332678c7 100644 --- a/src/guiChatConsole.h +++ b/src/guiChatConsole.h @@ -98,7 +98,7 @@ private: v2u32 m_screensize; // used to compute how much time passed since last animate() - u32 m_animate_time_old; + u64 m_animate_time_old; // should the console be opened or closed? bool m_open; diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index 14d576f8f..64642cf1f 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -2664,9 +2664,9 @@ void GUIFormSpecMenu::drawMenu() m_old_tooltip = L""; } else { if (id == m_old_tooltip_id) { - delta = porting::getDeltaMs(m_hovered_time, getTimeMs()); + delta = porting::getDeltaMs(m_hovered_time, porting::getTimeMs()); } else { - m_hovered_time = getTimeMs(); + m_hovered_time = porting::getTimeMs(); m_old_tooltip_id = id; } } @@ -3244,10 +3244,10 @@ bool GUIFormSpecMenu::DoubleClickDetection(const SEvent event) m_doubleclickdetect[0].time = m_doubleclickdetect[1].time; m_doubleclickdetect[1].pos = m_pointer; - m_doubleclickdetect[1].time = getTimeMs(); + m_doubleclickdetect[1].time = porting::getTimeMs(); } else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) { - u32 delta = porting::getDeltaMs(m_doubleclickdetect[0].time, getTimeMs()); + u32 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 af2d3f45e..18ccf1c3a 100644 --- a/src/guiFormSpecMenu.h +++ b/src/guiFormSpecMenu.h @@ -421,7 +421,7 @@ protected: gui::IGUIStaticText *m_tooltip_element; u32 m_tooltip_show_delay; - s32 m_hovered_time; + s64 m_hovered_time; s32 m_old_tooltip_id; std::wstring m_old_tooltip; @@ -527,7 +527,7 @@ private: struct clickpos { v2s32 pos; - s32 time; + s64 time; }; clickpos m_doubleclickdetect[2]; diff --git a/src/guiTable.cpp b/src/guiTable.cpp index 6b33b8266..d223e3069 100644 --- a/src/guiTable.cpp +++ b/src/guiTable.cpp @@ -828,7 +828,7 @@ bool GUITable::OnEvent(const SEvent &event) } else if (event.KeyInput.PressedDown && event.KeyInput.Char) { // change selection based on text as it is typed - s32 now = getTimeMs(); + u64 now = porting::getTimeMs(); if (now - m_keynav_time >= 500) m_keynav_buffer = L""; m_keynav_time = now; diff --git a/src/guiTable.h b/src/guiTable.h index 9fbe1c9da..02e8af00b 100644 --- a/src/guiTable.h +++ b/src/guiTable.h @@ -196,7 +196,7 @@ protected: bool m_sel_doubleclick; // Keyboard navigation stuff - s32 m_keynav_time; + u64 m_keynav_time; core::stringw m_keynav_buffer; // Drawing and geometry information diff --git a/src/hud.cpp b/src/hud.cpp index c482912e9..9729013ee 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -619,7 +619,7 @@ void Hud::resizeHotbar() { } struct MeshTimeInfo { - s32 time; + s64 time; scene::IMesh *mesh; }; @@ -653,9 +653,9 @@ void drawItemStack(video::IVideoDriver *driver, MeshTimeInfo &ti = rotation_time_infos[rotation_kind]; if (mesh != ti.mesh) { ti.mesh = mesh; - ti.time = getTimeMs(); + ti.time = porting::getTimeMs(); } else { - delta = porting::getDeltaMs(ti.time, getTimeMs()) % 100000; + delta = porting::getDeltaMs(ti.time, porting::getTimeMs()) % 100000; } } core::rect oldViewPort = driver->getViewPort(); diff --git a/src/main.cpp b/src/main.cpp index 2ad4e2780..6a2e89f7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -107,24 +107,6 @@ static bool migrate_map_database(const GameParams &game_params, const Settings & /**********************************************************************/ -/* - gettime.h implementation -*/ - -#ifdef SERVER - -u32 getTimeMs() -{ - /* Use imprecise system calls directly (from porting.h) */ - return porting::getTime(PRECISION_MILLI); -} - -u32 getTime(TimePrecision prec) -{ - return porting::getTime(prec); -} - -#endif FileLogOutput file_log_output; diff --git a/src/map.cpp b/src/map.cpp index 9e8823f84..63e1e4ccd 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 = getTime(PRECISION_MILLI); + u32 curr_time = porting::getTime(PRECISION_MILLI); u32 prev_unprocessed = m_unprocessed_count; m_unprocessed_count = m_transforming_liquid.size(); diff --git a/src/porting.cpp b/src/porting.cpp index 8c92a3cba..10b6fc940 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -942,5 +942,18 @@ void attachOrCreateConsole(void) #endif } +// Load performance counter frequency only once at startup +#ifdef _WIN32 + +inline double get_perf_freq() +{ + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + return freq.QuadPart; +} + +double perf_freq = get_perf_freq(); + +#endif } //namespace porting diff --git a/src/porting.h b/src/porting.h index aa389d02c..7034d956b 100644 --- a/src/porting.h +++ b/src/porting.h @@ -181,124 +181,99 @@ std::string get_sysinfo(); void initIrrlicht(irr::IrrlichtDevice * ); -/* - Resolution is 10-20ms. - Remember to check for overflows. - Overflow can occur at any value higher than 10000000. -*/ -#ifdef _WIN32 // Windows - inline u32 getTimeS() - { - return GetTickCount() / 1000; - } +// Monotonic counter getters. - inline u32 getTimeMs() - { - return GetTickCount(); - } +#ifdef _WIN32 // Windows - inline u32 getTimeUs() - { - LARGE_INTEGER freq, t; - QueryPerformanceFrequency(&freq); - QueryPerformanceCounter(&t); - return (double)(t.QuadPart) / ((double)(freq.QuadPart) / 1000000.0); - } +extern double perf_freq; - inline u32 getTimeNs() - { - LARGE_INTEGER freq, t; - QueryPerformanceFrequency(&freq); - QueryPerformanceCounter(&t); - return (double)(t.QuadPart) / ((double)(freq.QuadPart) / 1000000000.0); - } +inline u64 os_get_time(double mult) +{ + LARGE_INTEGER t; + QueryPerformanceCounter(&t); + return static_cast(t.QuadPart) / (perf_freq / mult); +} + +// Resolution is <1us. +inline u64 getTimeS() { return os_get_time(1); } +inline u64 getTimeMs() { return os_get_time(1000); } +inline u64 getTimeUs() { return os_get_time(1000*1000); } +inline u64 getTimeNs() { return os_get_time(1000*1000*1000); } #else // Posix - inline void _os_get_clock(struct timespec *ts) - { + +inline void os_get_clock(struct timespec *ts) +{ #if defined(__MACH__) && defined(__APPLE__) - // from http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x - // OS X does not have clock_gettime, use clock_get_time - clock_serv_t cclock; - mach_timespec_t mts; - host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); - clock_get_time(cclock, &mts); - mach_port_deallocate(mach_task_self(), cclock); - ts->tv_sec = mts.tv_sec; - ts->tv_nsec = mts.tv_nsec; +// From http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x +// OS X does not have clock_gettime, use clock_get_time + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts->tv_sec = mts.tv_sec; + ts->tv_nsec = mts.tv_nsec; #elif defined(CLOCK_MONOTONIC_RAW) - clock_gettime(CLOCK_MONOTONIC_RAW, ts); + clock_gettime(CLOCK_MONOTONIC_RAW, ts); #elif defined(_POSIX_MONOTONIC_CLOCK) - clock_gettime(CLOCK_MONOTONIC, ts); + clock_gettime(CLOCK_MONOTONIC, ts); #else - struct timeval tv; - gettimeofday(&tv, NULL); - TIMEVAL_TO_TIMESPEC(&tv, ts); -#endif // defined(__MACH__) && defined(__APPLE__) - } + struct timeval tv; + gettimeofday(&tv, NULL); + TIMEVAL_TO_TIMESPEC(&tv, ts); +#endif +} - // Note: these clock functions do not return wall time, but - // generally a clock that starts at 0 when the process starts. - inline u32 getTimeS() - { - struct timespec ts; - _os_get_clock(&ts); - return ts.tv_sec; - } +inline u64 getTimeS() +{ + struct timespec ts; + os_get_clock(&ts); + return ts.tv_sec; +} - inline u32 getTimeMs() - { - struct timespec ts; - _os_get_clock(&ts); - return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; - } +inline u64 getTimeMs() +{ + struct timespec ts; + os_get_clock(&ts); + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +} - inline u32 getTimeUs() - { - struct timespec ts; - _os_get_clock(&ts); - return ts.tv_sec * 1000000 + ts.tv_nsec / 1000; - } +inline u64 getTimeUs() +{ + struct timespec ts; + os_get_clock(&ts); + return ts.tv_sec * 1000000 + ts.tv_nsec / 1000; +} - inline u32 getTimeNs() - { - struct timespec ts; - _os_get_clock(&ts); - return ts.tv_sec * 1000000000 + ts.tv_nsec; - } +inline u64 getTimeNs() +{ + struct timespec ts; + os_get_clock(&ts); + return ts.tv_sec * 1000000000 + ts.tv_nsec; +} - /*#include - inline u32 getTimeMs() - { - struct timeb tb; - ftime(&tb); - return tb.time * 1000 + tb.millitm; - }*/ #endif -inline u32 getTime(TimePrecision prec) +inline u64 getTime(TimePrecision prec) { switch (prec) { - case PRECISION_SECONDS: - return getTimeS(); - case PRECISION_MILLI: - return getTimeMs(); - case PRECISION_MICRO: - return getTimeUs(); - case PRECISION_NANO: - return getTimeNs(); + case PRECISION_SECONDS: return getTimeS(); + case PRECISION_MILLI: return getTimeMs(); + case PRECISION_MICRO: return getTimeUs(); + case PRECISION_NANO: return getTimeNs(); } - return 0; + FATAL_ERROR("Called getTime with invalid time precision"); } /** - * Delta calculation function taking two 32bit arguments. - * @param old_time_ms old time for delta calculation (order is relevant!) - * @param new_time_ms new time for delta calculation (order is relevant!) - * @return positive 32bit delta value + * Delta calculation function arguments. + * @param old_time_ms old time for delta calculation + * @param new_time_ms new time for delta calculation + * @return positive delta value */ -inline u32 getDeltaMs(u32 old_time_ms, u32 new_time_ms) +inline u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms) { if (new_time_ms >= old_time_ms) { return (new_time_ms - old_time_ms); diff --git a/src/touchscreengui.cpp b/src/touchscreengui.cpp index 8d210c63a..1f80da691 100644 --- a/src/touchscreengui.cpp +++ b/src/touchscreengui.cpp @@ -794,7 +794,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) if (m_move_id == -1) { m_move_id = event.TouchInput.ID; m_move_has_really_moved = false; - m_move_downtime = getTimeMs(); + m_move_downtime = porting::getTimeMs(); m_move_downlocation = v2s32(event.TouchInput.X, event.TouchInput.Y); m_move_sent_as_mouse_event = false; } diff --git a/src/touchscreengui.h b/src/touchscreengui.h index 1308d78ae..f4f1766c9 100644 --- a/src/touchscreengui.h +++ b/src/touchscreengui.h @@ -186,7 +186,7 @@ private: int m_move_id; bool m_move_has_really_moved; - s32 m_move_downtime; + s64 m_move_downtime; bool m_move_sent_as_mouse_event; v2s32 m_move_downlocation; diff --git a/src/util/timetaker.cpp b/src/util/timetaker.cpp index dcf07dc0d..0e92696ac 100644 --- a/src/util/timetaker.cpp +++ b/src/util/timetaker.cpp @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "timetaker.h" -#include "../gettime.h" +#include "../porting.h" #include "../log.h" #include @@ -29,14 +29,14 @@ TimeTaker::TimeTaker(const char *name, u32 *result, TimePrecision prec) m_result = result; m_running = true; m_precision = prec; - m_time1 = getTime(prec); + m_time1 = porting::getTime(prec); } u32 TimeTaker::stop(bool quiet) { if(m_running) { - u32 time2 = getTime(m_precision); + u32 time2 = porting::getTime(m_precision); u32 dtime = time2 - m_time1; if(m_result != NULL) { @@ -64,7 +64,7 @@ u32 TimeTaker::stop(bool quiet) u32 TimeTaker::getTimerTime() { - u32 time2 = getTime(m_precision); + u32 time2 = porting::getTime(m_precision); u32 dtime = time2 - m_time1; return dtime; } -- cgit v1.2.3 From 605599b6f150b89ba6539c4d088231b326adcb48 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Sat, 20 May 2017 11:29:31 +0100 Subject: Fix shift key producing space in console (#5777) * Fix shift key producing space in console --- src/guiChatConsole.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/guiChatConsole.cpp') diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index b3c119555..4af1caa80 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -628,7 +628,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) prompt.nickCompletion(names, backwards); return true; } - else if(event.KeyInput.Char != 0 && !event.KeyInput.Control) + else if(isprint(event.KeyInput.Char) && !event.KeyInput.Control) { #if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9) wchar_t wc = L'_'; -- cgit v1.2.3 From a2bb776ea81715a7b9eae4b2ea8aca032d42fb5e Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 20 May 2017 20:13:29 +0200 Subject: Fix wchar_t type on 605599b6f150b89ba6539c4d088231b326adcb48 event.KeyInput.Char is a wchar_t, iswprint should be used --- src/guiChatConsole.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/guiChatConsole.cpp') diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index 4af1caa80..8281da861 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -627,9 +627,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) bool backwards = event.KeyInput.Shift; prompt.nickCompletion(names, backwards); return true; - } - else if(isprint(event.KeyInput.Char) && !event.KeyInput.Control) - { + } else if (iswprint(event.KeyInput.Char) && !event.KeyInput.Control) { #if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9) wchar_t wc = L'_'; mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); -- cgit v1.2.3 From 90808a4f34dca379e872074bdfd472faf1c48cf3 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 20 May 2017 22:29:15 +0200 Subject: Real control fix (#5787) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Allow enabling and disabling mods. * Re-fix 605599b6f150b89ba6539c4d088231b326adcb48 This breaks some chars like € in chat. Instead verify is char is a non control char -> iswcntrl --- src/guiChatConsole.cpp | 2 +- src/mods.cpp | 100 +++++++++++++++++++++++++++++-------------------- src/mods.h | 2 + src/server.cpp | 26 ------------- 4 files changed, 62 insertions(+), 68 deletions(-) (limited to 'src/guiChatConsole.cpp') diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index 8281da861..5bb80bbbe 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -627,7 +627,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) bool backwards = event.KeyInput.Shift; prompt.nickCompletion(names, backwards); return true; - } else if (iswprint(event.KeyInput.Char) && !event.KeyInput.Control) { + } else if (!iswcntrl(event.KeyInput.Char) && !event.KeyInput.Control) { #if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9) wchar_t wc = L'_'; mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); diff --git a/src/mods.cpp b/src/mods.cpp index 6fce8e93d..0e583b2db 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -214,6 +214,55 @@ void ModConfiguration::addMods(const std::vector &new_mods) } } +void ModConfiguration::addModsFormConfig(const std::string &settings_path, const std::set &mods) +{ + Settings conf; + std::set load_mod_names; + + conf.readConfigFile(settings_path.c_str()); + std::vector names = conf.getNames(); + for (std::vector::iterator it = names.begin(); + it != names.end(); ++it) { + std::string name = *it; + if (name.compare(0,9,"load_mod_")==0 && conf.getBool(name)) + load_mod_names.insert(name.substr(9)); + } + + std::vector addon_mods; + for (std::set::const_iterator i = mods.begin(); + i != mods.end(); ++i) { + std::vector addon_mods_in_path = flattenMods(getModsInPath(*i)); + for (std::vector::const_iterator it = addon_mods_in_path.begin(); + it != addon_mods_in_path.end(); ++it) { + const ModSpec& mod = *it; + if (load_mod_names.count(mod.name) != 0) + addon_mods.push_back(mod); + else + conf.setBool("load_mod_" + mod.name, false); + } + } + conf.updateConfigFile(settings_path.c_str()); + + addMods(addon_mods); + checkConflictsAndDeps(); + + // complain about mods declared to be loaded, but not found + for (std::vector::iterator it = addon_mods.begin(); + it != addon_mods.end(); ++it) + load_mod_names.erase((*it).name); + std::vector UnsatisfiedMods = getUnsatisfiedMods(); + for (std::vector::iterator it = UnsatisfiedMods.begin(); + it != UnsatisfiedMods.end(); ++it) + load_mod_names.erase((*it).name); + if (!load_mod_names.empty()) { + errorstream << "The following mods could not be found:"; + for (std::set::iterator it = load_mod_names.begin(); + it != load_mod_names.end(); ++it) + errorstream << " \"" << (*it) << "\""; + errorstream << std::endl; + } +} + void ModConfiguration::checkConflictsAndDeps() { // report on name conflicts @@ -296,53 +345,22 @@ ServerModConfiguration::ServerModConfiguration(const std::string &worldpath): addModsInPath(gamespec.gamemods_path); addModsInPath(worldpath + DIR_DELIM + "worldmods"); - // check world.mt file for mods explicitely declared to be - // loaded or not by a load_mod_ = ... line. - std::string worldmt = worldpath+DIR_DELIM+"world.mt"; - Settings worldmt_settings; - worldmt_settings.readConfigFile(worldmt.c_str()); - std::vector names = worldmt_settings.getNames(); - std::set include_mod_names; - for (std::vector::const_iterator it = names.begin(); - it != names.end(); ++it) { - std::string name = *it; - // for backwards compatibility: exclude only mods which are - // explicitely excluded. if mod is not mentioned at all, it is - // enabled. So by default, all installed mods are enabled. - if (name.compare(0,9,"load_mod_") == 0 && - worldmt_settings.getBool(name)) { - include_mod_names.insert(name.substr(9)); - } - } - - // Collect all mods that are also in include_mod_names - std::vector addon_mods; - for (std::set::const_iterator it_path = gamespec.addon_mods_paths.begin(); - it_path != gamespec.addon_mods_paths.end(); ++it_path) { - std::vector addon_mods_in_path = flattenMods(getModsInPath(*it_path)); - for (std::vector::const_iterator it = addon_mods_in_path.begin(); - it != addon_mods_in_path.end(); ++it) { - const ModSpec& mod = *it; - if (include_mod_names.count(mod.name) != 0) - addon_mods.push_back(mod); - else - worldmt_settings.setBool("load_mod_" + mod.name, false); - } - } - worldmt_settings.updateConfigFile(worldmt.c_str()); - - addMods(addon_mods); - - checkConflictsAndDeps(); + // Load normal mods + std::string worldmt = worldpath + DIR_DELIM + "world.mt"; + addModsFormConfig(worldmt, gamespec.addon_mods_paths); } #ifndef SERVER ClientModConfiguration::ClientModConfiguration(const std::string &path): ModConfiguration(path) { - addModsInPath(path); - addModsInPath(porting::path_user + DIR_DELIM + "clientmods"); - checkConflictsAndDeps(); + std::set paths; + std::string path_user = porting::path_user + DIR_DELIM + "clientmods"; + paths.insert(path); + paths.insert(path_user); + + std::string settings_path = path_user + DIR_DELIM + "mods.conf"; + addModsFormConfig(settings_path, paths); } #endif diff --git a/src/mods.h b/src/mods.h index 1e62db54d..7455a51ea 100644 --- a/src/mods.h +++ b/src/mods.h @@ -99,6 +99,8 @@ protected: // adds all mods in the set. void addMods(const std::vector &new_mods); + void addModsFormConfig(const std::string &settings_path, const std::set &mods); + void checkConflictsAndDeps(); private: // move mods from m_unsatisfied_mods to m_sorted_mods diff --git a/src/server.cpp b/src/server.cpp index 6889451d9..1e8e6a5d2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -230,32 +230,6 @@ Server::Server( modconf.printUnsatisfiedModsError(); } - Settings worldmt_settings; - std::string worldmt = m_path_world + DIR_DELIM + "world.mt"; - worldmt_settings.readConfigFile(worldmt.c_str()); - std::vector names = worldmt_settings.getNames(); - std::set load_mod_names; - for(std::vector::iterator it = names.begin(); - it != names.end(); ++it) { - std::string name = *it; - if(name.compare(0,9,"load_mod_")==0 && worldmt_settings.getBool(name)) - load_mod_names.insert(name.substr(9)); - } - // complain about mods declared to be loaded, but not found - for(std::vector::iterator it = m_mods.begin(); - it != m_mods.end(); ++it) - load_mod_names.erase((*it).name); - for(std::vector::iterator it = unsatisfied_mods.begin(); - it != unsatisfied_mods.end(); ++it) - load_mod_names.erase((*it).name); - if(!load_mod_names.empty()) { - errorstream << "The following mods could not be found:"; - for(std::set::iterator it = load_mod_names.begin(); - it != load_mod_names.end(); ++it) - errorstream << " \"" << (*it) << "\""; - errorstream << std::endl; - } - //lock environment MutexAutoLock envlock(m_env_mutex); -- cgit v1.2.3