From b46d4c4d5f4579f43723f7db1610df9c01540328 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 14 Mar 2012 15:45:15 -0300 Subject: [PATCH] non relevant changes --- modules/core_lib/globals.lua | 4 +- src/framework/CMakeLists.txt | 2 + src/framework/application.cpp | 8 ++-- src/framework/core/eventdispatcher.cpp | 2 +- src/framework/core/eventdispatcher.h | 2 +- src/framework/graphics/animatedtexture.cpp | 4 +- src/framework/luafunctions.cpp | 6 +-- src/framework/net/connection.cpp | 2 +- src/framework/ui/uihorizontallayout.cpp | 2 +- src/framework/ui/uilayout.cpp | 2 +- src/framework/ui/uimanager.cpp | 2 +- src/framework/ui/uiverticallayout.cpp | 2 +- src/framework/ui/uiwidget.cpp | 10 ++--- src/framework/util/tools.h | 48 ++++++++-------------- src/otclient/core/animatedtext.cpp | 2 +- src/otclient/core/creature.cpp | 8 ++-- src/otclient/core/effect.cpp | 2 +- src/otclient/core/mapview.cpp | 2 +- src/otclient/core/missile.cpp | 2 +- src/otclient/core/spritemanager.cpp | 2 +- src/otclient/core/statictext.cpp | 4 +- src/otclient/net/protocolgameparse.cpp | 2 +- 22 files changed, 53 insertions(+), 67 deletions(-) diff --git a/modules/core_lib/globals.lua b/modules/core_lib/globals.lua index 43da9fc6..2e98cfac 100644 --- a/modules/core_lib/globals.lua +++ b/modules/core_lib/globals.lua @@ -37,7 +37,7 @@ function createWidget(style, parent) end function scheduleEvent(callback, delay) - local event = g_dispatcher.scheduleEvent(callback, delay) + local event = g_eventDispatcher.scheduleEvent(callback, delay) -- must hold a reference to the callback, otherwise it would be collected event._callback = callback @@ -45,7 +45,7 @@ function scheduleEvent(callback, delay) end function addEvent(callback, front) - local event = g_dispatcher.addEvent(callback, front) + local event = g_eventDispatcher.addEvent(callback, front) -- must hold a reference to the callback, otherwise it would be collected event._callback = callback return event diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 67daa416..910baed9 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -45,6 +45,8 @@ IF(CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") SET(CMAKE_C_FLAGS_RELEASE "-O2") + #SET(CMAKE_CXX_FLAGS_PERFORMANCE "-Ofast -fomit-frame-pointer") + #SET(CMAKE_C_FLAGS_PERFORMANCE "-Ofast -fomit-frame-pointer") SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libgcc -static-libstdc++ -Wl,--as-needed") ENDIF(CMAKE_COMPILER_IS_GNUCXX) diff --git a/src/framework/application.cpp b/src/framework/application.cpp index 4a6a5a26..41935e36 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -46,7 +46,7 @@ void exitSignalHandler(int sig) case SIGINT: if(!signaled) { signaled = true; - g_dispatcher.addEvent(std::bind(&Application::close, g_app)); + g_eventDispatcher.addEvent(std::bind(&Application::close, g_app)); } break; } @@ -111,7 +111,7 @@ void Application::init(const std::vector& args, int appFlags) resize(g_window.getSize()); // display window when the application starts running - //g_dispatcher.addEvent([]{ g_window.show(); }); + //g_eventDispatcher.addEvent([]{ g_window.show(); }); } if(m_appFlags & Fw::AppEnableModules) @@ -146,7 +146,7 @@ void Application::terminate() } // flush remaining dispatcher events - g_dispatcher.flush(); + g_eventDispatcher.flush(); // save configurations if(m_appFlags & Fw::AppEnableConfigs) @@ -214,7 +214,7 @@ void Application::poll() } Connection::poll(); - g_dispatcher.poll(); + g_eventDispatcher.poll(); } void Application::close() diff --git a/src/framework/core/eventdispatcher.cpp b/src/framework/core/eventdispatcher.cpp index 649b0b91..31386e67 100644 --- a/src/framework/core/eventdispatcher.cpp +++ b/src/framework/core/eventdispatcher.cpp @@ -24,7 +24,7 @@ #include -EventDispatcher g_dispatcher; +EventDispatcher g_eventDispatcher; void EventDispatcher::flush() { diff --git a/src/framework/core/eventdispatcher.h b/src/framework/core/eventdispatcher.h index ac397ed9..28aafe6f 100644 --- a/src/framework/core/eventdispatcher.h +++ b/src/framework/core/eventdispatcher.h @@ -84,6 +84,6 @@ private: std::priority_queue, lessScheduledEvent> m_scheduledEventList; }; -extern EventDispatcher g_dispatcher; +extern EventDispatcher g_eventDispatcher; #endif diff --git a/src/framework/graphics/animatedtexture.cpp b/src/framework/graphics/animatedtexture.cpp index c4ab63d9..de972762 100644 --- a/src/framework/graphics/animatedtexture.cpp +++ b/src/framework/graphics/animatedtexture.cpp @@ -42,7 +42,7 @@ AnimatedTexture::AnimatedTexture(int width, int height, int channels, int numFra m_framesDelay[i] = framesDelay[i]; } m_currentFrame = -1; - g_dispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, this), 0); + g_eventDispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, this), 0); } AnimatedTexture::~AnimatedTexture() @@ -71,5 +71,5 @@ void AnimatedTexture::processAnimation() // continue to animate only if something still referencing this texture if(self.use_count() > 2) - g_dispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, self), m_framesDelay[m_currentFrame]); + g_eventDispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, self), m_framesDelay[m_currentFrame]); } diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index f9dcf793..8474270d 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -505,7 +505,7 @@ void Application::registerLuaFunctions() g_lua.bindClassStaticFunction("g_fonts", "setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1)); // EventDispatcher - g_lua.registerStaticClass("g_dispatcher"); - g_lua.bindClassStaticFunction("g_dispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, _2)); - g_lua.bindClassStaticFunction("g_dispatcher", "scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2)); + g_lua.registerStaticClass("g_eventDispatcher"); + g_lua.bindClassStaticFunction("g_eventDispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_eventDispatcher, _1, _2)); + g_lua.bindClassStaticFunction("g_eventDispatcher", "scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_eventDispatcher, _1, _2)); } diff --git a/src/framework/net/connection.cpp b/src/framework/net/connection.cpp index 3415746f..bcc9c72e 100644 --- a/src/framework/net/connection.cpp +++ b/src/framework/net/connection.cpp @@ -123,7 +123,7 @@ void Connection::write(uint8* buffer, uint16 size) if(!m_sendEvent || m_sendEvent->isExecuted() || m_sendEvent->isCanceled()) { auto weakSelf = ConnectionWeakPtr(shared_from_this()); - m_sendEvent = g_dispatcher.scheduleEvent([=] { + m_sendEvent = g_eventDispatcher.scheduleEvent([=] { if(!weakSelf.lock()) return; //m_writeTimer.cancel(); diff --git a/src/framework/ui/uihorizontallayout.cpp b/src/framework/ui/uihorizontallayout.cpp index 2bc50f84..1b002d24 100644 --- a/src/framework/ui/uihorizontallayout.cpp +++ b/src/framework/ui/uihorizontallayout.cpp @@ -83,7 +83,7 @@ void UIHorizontalLayout::internalUpdate() if(m_fitChildren && prefferedWidth != parentWidget->getWidth()) { // must set the preffered width later - g_dispatcher.addEvent([=] { + g_eventDispatcher.addEvent([=] { parentWidget->setWidth(prefferedWidth); }); } diff --git a/src/framework/ui/uilayout.cpp b/src/framework/ui/uilayout.cpp index 1021a417..1adf530a 100644 --- a/src/framework/ui/uilayout.cpp +++ b/src/framework/ui/uilayout.cpp @@ -44,7 +44,7 @@ void UILayout::updateLater() return; auto self = asUILayout(); - g_dispatcher.addEvent([self] { + g_eventDispatcher.addEvent([self] { self->m_updateScheduled = false; self->update(); }); diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 3eb029e4..9dbc48b6 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -147,7 +147,7 @@ void UIManager::updateHoveredWidget() if(m_hoverUpdateScheduled) return; - g_dispatcher.addEvent([this] { + g_eventDispatcher.addEvent([this] { if(!m_rootWidget) return; diff --git a/src/framework/ui/uiverticallayout.cpp b/src/framework/ui/uiverticallayout.cpp index 718fc938..af2affad 100644 --- a/src/framework/ui/uiverticallayout.cpp +++ b/src/framework/ui/uiverticallayout.cpp @@ -83,7 +83,7 @@ void UIVerticalLayout::internalUpdate() if(m_fitChildren && prefferedHeight != parentWidget->getHeight()) { // must set the preffered width later - g_dispatcher.addEvent([=] { + g_eventDispatcher.addEvent([=] { parentWidget->setHeight(prefferedHeight); }); } diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index c5ffb320..2044f269 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -650,7 +650,7 @@ void UIWidget::destroy() #ifdef DEBUG auto self = asUIWidget(); if(self != g_ui.getRootWidget()) { - g_dispatcher.scheduleEvent([self] { + g_eventDispatcher.scheduleEvent([self] { g_lua.collectGarbage(); if(self->getUseCount() != 1) logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left"); @@ -735,7 +735,7 @@ void UIWidget::setRect(const Rect& rect) // avoid massive update events if(!m_updateEventScheduled) { UIWidgetPtr self = asUIWidget(); - g_dispatcher.addEvent([self, oldRect]() { + g_eventDispatcher.addEvent([self, oldRect]() { self->m_updateEventScheduled = false; if(oldRect != self->getRect()) self->onGeometryChange(oldRect, self->getRect()); @@ -1110,9 +1110,9 @@ void UIWidget::updateState(Fw::WidgetState state) if(setState(state, newStatus)) { if(state == Fw::FocusState) { - g_dispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason)); + g_eventDispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason)); } else if(state == Fw::HoverState) - g_dispatcher.addEvent(std::bind(&UIWidget::onHoverChange, asUIWidget(), newStatus)); + g_eventDispatcher.addEvent(std::bind(&UIWidget::onHoverChange, asUIWidget(), newStatus)); } } @@ -1145,7 +1145,7 @@ void UIWidget::updateStyle() if(m_loadingStyle && !m_updateStyleScheduled) { UIWidgetPtr self = asUIWidget(); - g_dispatcher.addEvent([self] { + g_eventDispatcher.addEvent([self] { self->m_updateStyleScheduled = false; self->updateStyle(); }); diff --git a/src/framework/util/tools.h b/src/framework/util/tools.h index 68ff79fe..641e44ea 100644 --- a/src/framework/util/tools.h +++ b/src/framework/util/tools.h @@ -56,9 +56,7 @@ inline uint32 getU32(std::istream& in) { return tmp; } -/// Fill an ostream by concatenating args -/// Usage: -/// Fw::fill_ostream(stream, a1, a2, ..., aN); +// fills an ostream by concatenating args inline void fillOstream(std::ostringstream&) { } template void fillOstream(std::ostringstream& stream, const T& first, const Args&... rest) { @@ -66,9 +64,7 @@ void fillOstream(std::ostringstream& stream, const T& first, const Args&... rest fillOstream(stream, rest...); } -/// Makes a std::string by concatenating args -/// Usage: -/// std::string str = Fw::mkstr(a1, a2, ..., aN); +// makes a std::string by concatenating args template std::string mkstr(const T&... args) { std::ostringstream buf; @@ -76,9 +72,10 @@ std::string mkstr(const T&... args) { return buf.str(); } +// throw a generic expcetion template void throwException(const T&... args) { - throw Exception(Fw::mkstr(args...)); + throw Exception(mkstr(args...)); } // used by dumper @@ -91,9 +88,7 @@ struct dump_util { } }; -/// Utility for dumping variables -/// Usage: -/// Fw::dump << v1, v2, ..., vN; +// utility for dumping variables struct dumper { dumper() { } template @@ -104,9 +99,7 @@ struct dumper { } }; -/// Utility for printing messages into stdout -/// Usage: -/// Fw::print(v1, v2, ..., vN); +// utility for printing messages into stdout template void print(const T&... args) { std::ostringstream buf; @@ -114,14 +107,13 @@ void print(const T&... args) { std::cout << buf.str(); } -/// Same as Fw::print but adds a new line at the end template void println(const T&... args) { print(args...); std::cout << std::endl; } -/// Demangle names for GNU g++ compiler +// demangle names for GNU g++ compiler inline std::string demangleName(const char* name) { size_t len; int status; @@ -134,15 +126,13 @@ inline std::string demangleName(const char* name) { return ret; } -/// Returns the name of a type -/// e.g. Fw::demangle_type() returns a string containing 'Foo*' +// returns the name of a type template std::string demangleType() { return demangleName(typeid(T).name()); } -/// Cast a type to another type -/// @return whether the conversion was successful or not +// cast a type to another type template bool cast(const T& in, R& out) { std::stringstream ss; @@ -194,9 +184,9 @@ inline bool cast(const bool& in, std::string& out) { } // used by safe_cast -class CastException : public Exception { +class cast_exception : public Exception { public: - virtual ~CastException() throw() { } + virtual ~cast_exception() throw() { } template void setWhat() { m_what = mkstr("failed to cast value of type '", demangleType(), @@ -207,28 +197,24 @@ private: std::string m_what; }; -/// Cast a type to another type, any error throws a Fw::bad_cast_exception -/// Usage: -/// R r = Fw::safe_cast(t); +// cast a type to another type, any error throws a cast_exception template R safeCast(const T& t) { R r; if(!cast(t, r)) { - CastException e; + cast_exception e; e.setWhat(); throw e; } return r; } -/// Cast a type to another type, cast errors are ignored -/// Usage: -/// R r = Fw::unsafe_cast(t); +// cast a type to another type, cast errors are ignored template R unsafeCast(const T& t, R def = R()) { try { return safeCast(t); - } catch(CastException& e) { + } catch(cast_exception& e) { println("CAST ERROR: ", e.what()); return def; } @@ -271,7 +257,7 @@ std::vector split(const std::string& str, const std::string& separators = " " boost::split(splitted, str, boost::is_any_of(std::string(separators))); std::vector results(splitted.size()); for(uint i=0;i(splitted[i]); + results[i] = safeCast(splitted[i]); return results; } @@ -311,6 +297,4 @@ inline float randomRange(float min, float max) { // shortcut for Fw::dump const static Fw::dumper dump; -#define forever for(;;) - #endif diff --git a/src/otclient/core/animatedtext.cpp b/src/otclient/core/animatedtext.cpp index e9b35709..a801b1bd 100644 --- a/src/otclient/core/animatedtext.cpp +++ b/src/otclient/core/animatedtext.cpp @@ -50,7 +50,7 @@ void AnimatedText::startAnimation() // schedule removal auto self = asAnimatedText(); - g_dispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::ANIMATED_TEXT_DURATION); + g_eventDispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::ANIMATED_TEXT_DURATION); } void AnimatedText::setColor(int color) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index f3f7f05b..fe08268a 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -377,7 +377,7 @@ void Creature::nextWalkUpdate() // schedules next update if(m_walking) { auto self = asCreature(); - m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { + m_walkUpdateEvent = g_eventDispatcher.scheduleEvent([self] { self->m_walkUpdateEvent = nullptr; self->nextWalkUpdate(); }, m_walkAnimationInterval / 32); @@ -500,7 +500,7 @@ void Creature::setShieldTexture(const std::string& filename, bool blink) if(blink && !m_shieldBlink) { auto self = asCreature(); - g_dispatcher.scheduleEvent([self]() { + g_eventDispatcher.scheduleEvent([self]() { self->updateShield(); }, SHIELD_BLINK_TICKS); } @@ -520,7 +520,7 @@ void Creature::addTimedSquare(uint8 color) // schedule removal auto self = asCreature(); - g_dispatcher.scheduleEvent([self]() { + g_eventDispatcher.scheduleEvent([self]() { self->removeTimedSquare(); }, VOLATILE_SQUARE_DURATION); } @@ -531,7 +531,7 @@ void Creature::updateShield() if(m_shield != Otc::ShieldNone && m_shieldBlink) { auto self = asCreature(); - g_dispatcher.scheduleEvent([self]() { + g_eventDispatcher.scheduleEvent([self]() { self->updateShield(); }, SHIELD_BLINK_TICKS); } diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index 19c6f829..f4493fcf 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -41,7 +41,7 @@ void Effect::startAnimation() // schedule removal auto self = asEffect(); - g_dispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::EFFECT_TICKS_PER_FRAME * getAnimationPhases()); + g_eventDispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::EFFECT_TICKS_PER_FRAME * getAnimationPhases()); } void Effect::setId(uint32 id) diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index c9ec08b2..f59897bb 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -347,7 +347,7 @@ void MapView::updateVisibleTilesCache(int start) if(stop) { // schedule next update continuation - m_updateTilesCacheEvent = g_dispatcher.addEvent(std::bind(&MapView::updateVisibleTilesCache, asMapView(), count)); + m_updateTilesCacheEvent = g_eventDispatcher.addEvent(std::bind(&MapView::updateVisibleTilesCache, asMapView(), count)); } if(start == 0) m_cachedFloorVisibleCreatures = g_map.getSpectators(cameraPosition, false); diff --git a/src/otclient/core/missile.cpp b/src/otclient/core/missile.cpp index 8b09ac08..70ec2cec 100644 --- a/src/otclient/core/missile.cpp +++ b/src/otclient/core/missile.cpp @@ -78,7 +78,7 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition) // schedule removal auto self = asMissile(); - g_dispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, m_duration); + g_eventDispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, m_duration); } void Missile::setId(uint32 id) diff --git a/src/otclient/core/spritemanager.cpp b/src/otclient/core/spritemanager.cpp index 48b6f8b7..4abdff8b 100644 --- a/src/otclient/core/spritemanager.cpp +++ b/src/otclient/core/spritemanager.cpp @@ -67,7 +67,7 @@ void SpriteManager::preloadSprites() }; for(int i=1;i<=m_spritesCount;i+=burst) - g_dispatcher.scheduleEvent(std::bind(preload, i), (i/burst) * interval); + g_eventDispatcher.scheduleEvent(std::bind(preload, i), (i/burst) * interval); } TexturePtr SpriteManager::loadSpriteTexture(int id) diff --git a/src/otclient/core/statictext.cpp b/src/otclient/core/statictext.cpp index baccf05f..77bf63d5 100644 --- a/src/otclient/core/statictext.cpp +++ b/src/otclient/core/statictext.cpp @@ -62,7 +62,7 @@ bool StaticText::addMessage(const std::string& name, Otc::SpeakType type, const compose(); auto self = asStaticText(); - g_dispatcher.scheduleEvent([self]() { + g_eventDispatcher.scheduleEvent([self]() { self->removeMessage(); }, std::max(Otc::STATIC_DURATION_PER_CHARACTER * message.length(), Otc::MIN_STATIC_TEXT_DURATION)); @@ -76,7 +76,7 @@ void StaticText::removeMessage() if(m_messages.empty()) { // schedule removal auto self = asStaticText(); - g_dispatcher.addEvent([self]() { g_map.removeThing(self); }); + g_eventDispatcher.addEvent([self]() { g_map.removeThing(self); }); } else compose(); } diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index d38ffe99..198a271b 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -1164,7 +1164,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) // now that the local player is known, we can schedule login event if(creature == m_localPlayer && !m_localPlayer->isKnown()) { m_localPlayer->setKnown(true); - g_dispatcher.addEvent([] { g_game.processLogin(); }); + g_eventDispatcher.addEvent([] { g_game.processLogin(); }); } }