diff options
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/being/actorsprite.cpp | 2 | ||||
-rw-r--r-- | src/being/being.cpp | 1 | ||||
-rw-r--r-- | src/being/compoundsprite.cpp | 4 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 1 | ||||
-rw-r--r-- | src/client.cpp | 85 | ||||
-rw-r--r-- | src/client.h | 19 | ||||
-rw-r--r-- | src/commands.cpp | 1 | ||||
-rw-r--r-- | src/game.cpp | 1 | ||||
-rw-r--r-- | src/gui/palette.cpp | 2 | ||||
-rw-r--r-- | src/gui/sdlfont.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 1 | ||||
-rw-r--r-- | src/gui/windows/debugwindow.cpp | 3 | ||||
-rw-r--r-- | src/guildmanager.cpp | 2 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 5 | ||||
-rw-r--r-- | src/input/joystick.cpp | 2 | ||||
-rw-r--r-- | src/map.cpp | 1 | ||||
-rw-r--r-- | src/net/ea/beinghandler.cpp | 9 | ||||
-rw-r--r-- | src/net/ea/buysellhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/eathena/beinghandler.cpp | 5 | ||||
-rw-r--r-- | src/net/tmwa/beinghandler.cpp | 6 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 2 | ||||
-rw-r--r-- | src/utils/timer.cpp | 122 | ||||
-rw-r--r-- | src/utils/timer.h | 49 |
26 files changed, 220 insertions, 118 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 254704a88..5ea4bdad5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -553,6 +553,8 @@ SET(SRCS utils/stringutils.cpp utils/stringutils.h utils/stringvector.h + utils/timer.cpp + utils/timer.h utils/mutex.h utils/mkdir.cpp utils/mkdir.h diff --git a/src/Makefile.am b/src/Makefile.am index 8f7f49367..a6e2b73c3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -572,6 +572,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ utils/stringutils.cpp \ utils/stringutils.h \ utils/stringvector.h \ + utils/timer.cpp \ + utils/timer.h \ utils/mutex.h \ utils/xml.cpp \ utils/xml.h \ diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp index 5dc114380..327996e2d 100644 --- a/src/being/actorsprite.cpp +++ b/src/being/actorsprite.cpp @@ -21,7 +21,6 @@ #include "being/actorsprite.h" -#include "client.h" #include "configuration.h" #include "imagesprite.h" #include "statuseffect.h" @@ -34,6 +33,7 @@ #include "resources/resourcemanager.h" #include "utils/checkutils.h" +#include "utils/timer.h" #include "debug.h" diff --git a/src/being/being.cpp b/src/being/being.cpp index ed794a49a..cda6557e4 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -68,6 +68,7 @@ #include "gui/widgets/tabs/langtab.h" #include "utils/gettext.h" +#include "utils/timer.h" #include "debug.h" diff --git a/src/being/compoundsprite.cpp b/src/being/compoundsprite.cpp index f7adddf50..3a615aa2b 100644 --- a/src/being/compoundsprite.cpp +++ b/src/being/compoundsprite.cpp @@ -21,7 +21,6 @@ #include "being/compoundsprite.h" -#include "client.h" #include "configuration.h" #include "game.h" @@ -39,6 +38,9 @@ #include "utils/dtor.h" #include "utils/sdlcheckutils.h" +#include "utils/timer.h" + +#include <SDL_endian.h> #include "debug.h" diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 6df48dec7..974660db3 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -67,6 +67,7 @@ #include "resources/iteminfo.h" #include "utils/gettext.h" +#include "utils/timer.h" #include "mumblemanager.h" diff --git a/src/client.cpp b/src/client.cpp index 130ddcc80..4bff155e8 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -114,6 +114,7 @@ #include "utils/process.h" #include "utils/sdlcheckutils.h" #include "utils/sdlhelper.h" +#include "utils/timer.h" #include "utils/translation/translationmanager.h" @@ -151,12 +152,6 @@ #define _nacl_dir std::string("/persistent/manaplus") #endif -/** - * Tells the max tick value, - * setting it back to zero (and start again). - */ -static const int MAX_TICK_VALUE = INT_MAX / 2; - std::string errorMessage; ErrorListener errorListener; LoginData loginData; @@ -175,9 +170,6 @@ Graphics *mainGraphics = nullptr; SoundManager soundManager; RenderType openGLMode = RENDER_SOFTWARE; -static uint32_t nextTick(uint32_t interval, void *param A_UNUSED); -static uint32_t nextSecond(uint32_t interval, void *param A_UNUSED); - void ErrorListener::action(const gcn::ActionEvent &event) { if (event.getId() == "yes") @@ -185,12 +177,6 @@ void ErrorListener::action(const gcn::ActionEvent &event) client->setState(STATE_CHOOSE_SERVER); } -volatile int tick_time; /**< Tick counter */ -volatile int fps = 0; /**< Frames counted in the last second */ -volatile int lps = 0; /**< Logic processed per second */ -volatile int frame_count = 0; /**< Counts the frames during one second */ -volatile int logic_count = 0; /**< Counts the logic during one second */ -volatile int cur_time; volatile bool runCounters; bool isSafeMode = false; int serverVersion = 0; @@ -203,60 +189,6 @@ int textures_count = 0; extern "C" char const *_nl_locale_name_default(void); #endif -/** - * Advances game logic counter. - * Called every 10 milliseconds by SDL_AddTimer() - * @see MILLISECONDS_IN_A_TICK value - */ -static uint32_t nextTick(uint32_t interval, void *param A_UNUSED) -{ - tick_time++; - if (tick_time == MAX_TICK_VALUE) - tick_time = 0; - return interval; -} - -/** - * Updates fps. - * Called every seconds by SDL_AddTimer() - */ -static uint32_t nextSecond(uint32_t interval, void *param A_UNUSED) -{ - fps = frame_count; - lps = logic_count; - frame_count = 0; - logic_count = 0; - - return interval; -} - -/** - * @return the elapsed time in milliseconds - * between two tick values. - */ -int get_elapsed_time(const int startTime) -{ - const int time = tick_time; - if (startTime <= time) - { - return (time - startTime) * MILLISECONDS_IN_A_TICK; - } - else - { - return (time + (MAX_TICK_VALUE - startTime)) - * MILLISECONDS_IN_A_TICK; - } -} - -int get_elapsed_time1(const int startTime) -{ - const int time = tick_time; - if (startTime <= time) - return time - startTime; - else - return time + (MAX_TICK_VALUE - startTime); -} - class AccountListener final : public gcn::ActionListener { public: @@ -306,13 +238,6 @@ Client::Client(const Options &options) : mState(STATE_CHOOSE_SERVER), mOldState(STATE_START), mIcon(nullptr), -#ifdef USE_SDL2 - mLogicCounterId(0), - mSecondsCounterId(0), -#else - mLogicCounterId(nullptr), - mSecondsCounterId(nullptr), -#endif mCaption(), mFpsManager(), mSkin(nullptr), @@ -727,10 +652,7 @@ void Client::gameInit() if (mState != STATE_ERROR) mState = STATE_CHOOSE_SERVER; - // Initialize logic and seconds counters - tick_time = 0; - mLogicCounterId = SDL_AddTimer(MILLISECONDS_IN_A_TICK, nextTick, nullptr); - mSecondsCounterId = SDL_AddTimer(1000, nextSecond, nullptr); + startTimers(); const int fpsLimit = config.getIntValue("fpslimit"); mLimitFps = fpsLimit > 0; @@ -818,8 +740,7 @@ void Client::gameClear() delete didYouKnowWindow; didYouKnowWindow = nullptr; - SDL_RemoveTimer(mLogicCounterId); - SDL_RemoveTimer(mSecondsCounterId); + stopTimers(); // Unload XML databases CharDB::unload(); diff --git a/src/client.h b/src/client.h index 9d1a23266..f3b2bcc26 100644 --- a/src/client.h +++ b/src/client.h @@ -46,17 +46,8 @@ class Skin; class Window; class QuitDialog; -/** - * Set the milliseconds value of a tick time. - */ -static const int MILLISECONDS_IN_A_TICK = 10; - static const uint16_t DEFAULT_PORT = 6901; -extern volatile int fps; -extern volatile int lps; -extern volatile int tick_time; -extern volatile int cur_time; extern bool isSafeMode; extern int serverVersion; extern unsigned int tmwServerVersion; @@ -74,13 +65,6 @@ extern ErrorListener errorListener; extern LoginData loginData; /** - * Returns elapsed time. (Warning: supposes the delay is always < 100 seconds) - */ -int get_elapsed_time(const int startTime) A_WARN_UNUSED; - -int get_elapsed_time1(const int startTime) A_WARN_UNUSED; - -/** * All client states. */ enum State @@ -420,9 +404,6 @@ private: SDL_Surface *mIcon; - SDL_TimerID mLogicCounterId; - SDL_TimerID mSecondsCounterId; - std::string mCaption; FPSmanager mFpsManager; Skin *mSkin; diff --git a/src/commands.cpp b/src/commands.cpp index 36ea69a0c..551aa9943 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -77,6 +77,7 @@ #include "utils/gettext.h" #include "utils/process.h" +#include "utils/timer.h" #include "debug.h" diff --git a/src/game.cpp b/src/game.cpp index 342aaf249..73cafad69 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -105,6 +105,7 @@ #include "utils/physfstools.h" #include "utils/process.h" #include "utils/sdlcheckutils.h" +#include "utils/timer.h" #include <sstream> #include <string> diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 0f7d76e85..b47203f8f 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -23,7 +23,7 @@ #include "gui/palette.h" -#include "client.h" +#include "utils/timer.h" #include <cmath> diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 985ddf69b..b0596418d 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -23,7 +23,6 @@ #include "gui/sdlfont.h" -#include "client.h" #include "logger.h" #include "main.h" @@ -39,6 +38,8 @@ #include "utils/paths.h" #include "utils/physfsrwops.h" #include "utils/sdlcheckutils.h" +#include "utils/stringutils.h" +#include "utils/timer.h" #include <guichan/exception.hpp> diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 5cd9b54f7..8d1550f43 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -23,8 +23,6 @@ #include "gui/widgets/browserbox.h" -#include "client.h" - #include "input/inputmanager.h" #include "gui/gui.h" @@ -36,6 +34,9 @@ #include "resources/imageset.h" #include "resources/resourcemanager.h" +#include "utils/stringutils.h" +#include "utils/timer.h" + #include <guichan/graphics.hpp> #include <guichan/font.hpp> #include <guichan/cliprectangle.hpp> diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 04527e1ae..a361e1a12 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -39,6 +39,7 @@ #include "resources/image.h" #include "utils/copynpaste.h" +#include "utils/timer.h" #include <guichan/font.hpp> diff --git a/src/gui/windows/debugwindow.cpp b/src/gui/windows/debugwindow.cpp index 7fec86369..cb5e06c3d 100644 --- a/src/gui/windows/debugwindow.cpp +++ b/src/gui/windows/debugwindow.cpp @@ -22,7 +22,6 @@ #include "gui/windows/debugwindow.h" -#include "client.h" #include "game.h" #include "main.h" @@ -43,6 +42,8 @@ #include "net/packetcounters.h" #include "utils/gettext.h" +#include "utils/stringutils.h" +#include "utils/timer.h" #include "debug.h" diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 1eae0b0eb..ab79337ed 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -36,6 +36,8 @@ #include "net/chathandler.h" #include "net/net.h" +#include "utils/timer.h" + #include "debug.h" static const int requestTimeout = 5; diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index e395aad8e..7e7da4433 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -20,7 +20,6 @@ #include "input/inputmanager.h" -#include "client.h" #include "configuration.h" #include "game.h" #include "touchmanager.h" @@ -37,14 +36,16 @@ #include "gui/widgets/tabs/setup_input.h" +#include "gui/windows/chatwindow.h" #include "gui/windows/inventorywindow.h" #include "gui/windows/npcdialog.h" #include "gui/windows/npcpostdialog.h" #include "gui/windows/setup.h" #include "gui/windows/textdialog.h" #include "gui/windows/tradewindow.h" +#include "gui/windows/quitdialog.h" -#include "gui/windows/chatwindow.h" +#include "utils/timer.h" #include <guichan/exception.hpp> #include <guichan/focushandler.hpp> diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp index 99a751525..aa7aa3ee9 100644 --- a/src/input/joystick.cpp +++ b/src/input/joystick.cpp @@ -29,6 +29,8 @@ #include "input/inputmanager.h" +#include "utils/timer.h" + #include "debug.h" int Joystick::joystickCount = 0; diff --git a/src/map.cpp b/src/map.cpp index 6071d22f2..dac9fc71f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -45,6 +45,7 @@ #include "utils/dtor.h" #include "utils/mkdir.h" #include "utils/physfstools.h" +#include "utils/timer.h" #include <climits> #include <queue> diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 4938ea525..daef49b42 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -25,7 +25,6 @@ #include "net/ea/eaprotocol.h" #include "actormanager.h" -#include "client.h" #include "configuration.h" #include "effectmanager.h" #include "game.h" @@ -39,13 +38,13 @@ #include "input/keyboardconfig.h" +#include "gui/windows/botcheckerwindow.h" +#include "gui/windows/outfitwindow.h" #include "gui/windows/socialwindow.h" #include "gui/windows/killstats.h" #include "gui/windows/questswindow.h" -#include "gui/windows/botcheckerwindow.h" - -#include "gui/windows/outfitwindow.h" +#include "utils/timer.h" #include "resources/iteminfo.h" @@ -53,6 +52,8 @@ #include "debug.h" +extern int serverVersion; + namespace Ea { BeingHandler::BeingHandler(const bool enableSync) : diff --git a/src/net/ea/buysellhandler.cpp b/src/net/ea/buysellhandler.cpp index 15a4385dc..581e706b3 100644 --- a/src/net/ea/buysellhandler.cpp +++ b/src/net/ea/buysellhandler.cpp @@ -22,7 +22,6 @@ #include "net/ea/buysellhandler.h" -#include "client.h" #include "configuration.h" #include "inventory.h" #include "notifications.h" @@ -42,6 +41,8 @@ #include "net/ea/eaprotocol.h" +#include "utils/timer.h" + #include "debug.h" namespace Ea diff --git a/src/net/eathena/beinghandler.cpp b/src/net/eathena/beinghandler.cpp index ab0af709e..652776e28 100644 --- a/src/net/eathena/beinghandler.cpp +++ b/src/net/eathena/beinghandler.cpp @@ -23,7 +23,6 @@ #include "net/eathena/beinghandler.h" #include "actormanager.h" -#include "client.h" #include "guild.h" #include "guildmanager.h" #include "party.h" @@ -44,9 +43,13 @@ #include "resources/db/itemdb.h" +#include "utils/stringutils.h" +#include "utils/timer.h" + #include "debug.h" extern Net::BeingHandler *beingHandler; +extern int serverVersion; namespace EAthena { diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 8f91371b1..47d86a240 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -23,7 +23,6 @@ #include "net/tmwa/beinghandler.h" #include "actormanager.h" -#include "client.h" #include "guild.h" #include "guildmanager.h" #include "party.h" @@ -38,10 +37,15 @@ #include "resources/db/itemdb.h" +#include "utils/stringutils.h" +#include "utils/timer.h" + #include "debug.h" extern Net::BeingHandler *beingHandler; +extern int serverVersion; + namespace TmwAthena { diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index d50df6b50..193647a6e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -23,7 +23,6 @@ #include "resources/resourcemanager.h" #include "animationdelayload.h" -#include "client.h" #include "configuration.h" #include "logger.h" #include "navigationmanager.h" @@ -43,6 +42,7 @@ #include "utils/physfscheckutils.h" #include "utils/physfsrwops.h" #include "utils/sdlcheckutils.h" +#include "utils/timer.h" #include <SDL_image.h> #include <dirent.h> diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp new file mode 100644 index 000000000..f6aab825c --- /dev/null +++ b/src/utils/timer.cpp @@ -0,0 +1,122 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "utils/timer.h" + +#include "SDL_timer.h" + +#include <climits> + +#include "debug.h" + +namespace +{ +#ifdef USE_SDL2 + SDL_TimerID mLogicCounterId(0); + SDL_TimerID mSecondsCounterId(0); +#else + SDL_TimerID mLogicCounterId(nullptr); + SDL_TimerID mSecondsCounterId(nullptr); +#endif +} // namespace + +/** + * Tells the max tick value, + * setting it back to zero (and start again). + */ +static const int MAX_TICK_VALUE = INT_MAX / 2; + +volatile int tick_time; /**< Tick counter */ +volatile int fps = 0; /**< Frames counted in the last second */ +volatile int lps = 0; /**< Logic processed per second */ +volatile int frame_count = 0; /**< Counts the frames during one second */ +volatile int logic_count = 0; /**< Counts the logic during one second */ +volatile int cur_time; + +static uint32_t nextTick(uint32_t interval, void *param A_UNUSED); +static uint32_t nextSecond(uint32_t interval, void *param A_UNUSED); + +/** + * Advances game logic counter. + * Called every 10 milliseconds by SDL_AddTimer() + * @see MILLISECONDS_IN_A_TICK value + */ +static uint32_t nextTick(uint32_t interval, void *param A_UNUSED) +{ + tick_time++; + if (tick_time == MAX_TICK_VALUE) + tick_time = 0; + return interval; +} + +/** + * Updates fps. + * Called every seconds by SDL_AddTimer() + */ +static uint32_t nextSecond(uint32_t interval, void *param A_UNUSED) +{ + fps = frame_count; + lps = logic_count; + frame_count = 0; + logic_count = 0; + + return interval; +} + +/** + * @return the elapsed time in milliseconds + * between two tick values. + */ +int get_elapsed_time(const int startTime) +{ + const int time = tick_time; + if (startTime <= time) + { + return (time - startTime) * MILLISECONDS_IN_A_TICK; + } + else + { + return (time + (MAX_TICK_VALUE - startTime)) + * MILLISECONDS_IN_A_TICK; + } +} + +int get_elapsed_time1(const int startTime) +{ + const int time = tick_time; + if (startTime <= time) + return time - startTime; + else + return time + (MAX_TICK_VALUE - startTime); +} + +void startTimers() +{ + // Initialize logic and seconds counters + tick_time = 0; + mLogicCounterId = SDL_AddTimer(MILLISECONDS_IN_A_TICK, nextTick, nullptr); + mSecondsCounterId = SDL_AddTimer(1000, nextSecond, nullptr); +} + +void stopTimers() +{ + SDL_RemoveTimer(mLogicCounterId); + SDL_RemoveTimer(mSecondsCounterId); +} diff --git a/src/utils/timer.h b/src/utils/timer.h new file mode 100644 index 000000000..40f8cc39d --- /dev/null +++ b/src/utils/timer.h @@ -0,0 +1,49 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef UTILS_TIMER_H +#define UTILS_TIMER_H + +#include "localconsts.h" + +/** + * Set the milliseconds value of a tick time. + */ +static const int MILLISECONDS_IN_A_TICK = 10; + +extern volatile int fps; +extern volatile int lps; +extern volatile int tick_time; +extern volatile int cur_time; +extern volatile int frame_count; +extern volatile int logic_count; + +void startTimers(); + +void stopTimers(); + +/** + * Returns elapsed time. (Warning: supposes the delay is always < 100 seconds) + */ +int get_elapsed_time(const int startTime) A_WARN_UNUSED; + +int get_elapsed_time1(const int startTime) A_WARN_UNUSED; + +#endif // UTILS_TIMER_H |