non relevant changes

This commit is contained in:
Eduardo Bart 2012-03-14 15:45:15 -03:00
parent 27b83fa722
commit b46d4c4d5f
22 changed files with 53 additions and 67 deletions

View File

@ -37,7 +37,7 @@ function createWidget(style, parent)
end end
function scheduleEvent(callback, delay) 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 -- must hold a reference to the callback, otherwise it would be collected
event._callback = callback event._callback = callback
@ -45,7 +45,7 @@ function scheduleEvent(callback, delay)
end end
function addEvent(callback, front) 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 -- must hold a reference to the callback, otherwise it would be collected
event._callback = callback event._callback = callback
return event return event

View File

@ -45,6 +45,8 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2") SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_C_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") SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libgcc -static-libstdc++ -Wl,--as-needed")
ENDIF(CMAKE_COMPILER_IS_GNUCXX) ENDIF(CMAKE_COMPILER_IS_GNUCXX)

View File

@ -46,7 +46,7 @@ void exitSignalHandler(int sig)
case SIGINT: case SIGINT:
if(!signaled) { if(!signaled) {
signaled = true; signaled = true;
g_dispatcher.addEvent(std::bind(&Application::close, g_app)); g_eventDispatcher.addEvent(std::bind(&Application::close, g_app));
} }
break; break;
} }
@ -111,7 +111,7 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
resize(g_window.getSize()); resize(g_window.getSize());
// display window when the application starts running // display window when the application starts running
//g_dispatcher.addEvent([]{ g_window.show(); }); //g_eventDispatcher.addEvent([]{ g_window.show(); });
} }
if(m_appFlags & Fw::AppEnableModules) if(m_appFlags & Fw::AppEnableModules)
@ -146,7 +146,7 @@ void Application::terminate()
} }
// flush remaining dispatcher events // flush remaining dispatcher events
g_dispatcher.flush(); g_eventDispatcher.flush();
// save configurations // save configurations
if(m_appFlags & Fw::AppEnableConfigs) if(m_appFlags & Fw::AppEnableConfigs)
@ -214,7 +214,7 @@ void Application::poll()
} }
Connection::poll(); Connection::poll();
g_dispatcher.poll(); g_eventDispatcher.poll();
} }
void Application::close() void Application::close()

View File

@ -24,7 +24,7 @@
#include <framework/core/clock.h> #include <framework/core/clock.h>
EventDispatcher g_dispatcher; EventDispatcher g_eventDispatcher;
void EventDispatcher::flush() void EventDispatcher::flush()
{ {

View File

@ -84,6 +84,6 @@ private:
std::priority_queue<ScheduledEventPtr, std::vector<ScheduledEventPtr>, lessScheduledEvent> m_scheduledEventList; std::priority_queue<ScheduledEventPtr, std::vector<ScheduledEventPtr>, lessScheduledEvent> m_scheduledEventList;
}; };
extern EventDispatcher g_dispatcher; extern EventDispatcher g_eventDispatcher;
#endif #endif

View File

@ -42,7 +42,7 @@ AnimatedTexture::AnimatedTexture(int width, int height, int channels, int numFra
m_framesDelay[i] = framesDelay[i]; m_framesDelay[i] = framesDelay[i];
} }
m_currentFrame = -1; m_currentFrame = -1;
g_dispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, this), 0); g_eventDispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, this), 0);
} }
AnimatedTexture::~AnimatedTexture() AnimatedTexture::~AnimatedTexture()
@ -71,5 +71,5 @@ void AnimatedTexture::processAnimation()
// continue to animate only if something still referencing this texture // continue to animate only if something still referencing this texture
if(self.use_count() > 2) 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]);
} }

View File

@ -505,7 +505,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_fonts", "setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1)); g_lua.bindClassStaticFunction("g_fonts", "setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1));
// EventDispatcher // EventDispatcher
g_lua.registerStaticClass("g_dispatcher"); g_lua.registerStaticClass("g_eventDispatcher");
g_lua.bindClassStaticFunction("g_dispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, _2)); g_lua.bindClassStaticFunction("g_eventDispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_eventDispatcher, _1, _2));
g_lua.bindClassStaticFunction("g_dispatcher", "scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2)); g_lua.bindClassStaticFunction("g_eventDispatcher", "scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_eventDispatcher, _1, _2));
} }

View File

@ -123,7 +123,7 @@ void Connection::write(uint8* buffer, uint16 size)
if(!m_sendEvent || m_sendEvent->isExecuted() || m_sendEvent->isCanceled()) { if(!m_sendEvent || m_sendEvent->isExecuted() || m_sendEvent->isCanceled()) {
auto weakSelf = ConnectionWeakPtr(shared_from_this()); auto weakSelf = ConnectionWeakPtr(shared_from_this());
m_sendEvent = g_dispatcher.scheduleEvent([=] { m_sendEvent = g_eventDispatcher.scheduleEvent([=] {
if(!weakSelf.lock()) if(!weakSelf.lock())
return; return;
//m_writeTimer.cancel(); //m_writeTimer.cancel();

View File

@ -83,7 +83,7 @@ void UIHorizontalLayout::internalUpdate()
if(m_fitChildren && prefferedWidth != parentWidget->getWidth()) { if(m_fitChildren && prefferedWidth != parentWidget->getWidth()) {
// must set the preffered width later // must set the preffered width later
g_dispatcher.addEvent([=] { g_eventDispatcher.addEvent([=] {
parentWidget->setWidth(prefferedWidth); parentWidget->setWidth(prefferedWidth);
}); });
} }

View File

@ -44,7 +44,7 @@ void UILayout::updateLater()
return; return;
auto self = asUILayout(); auto self = asUILayout();
g_dispatcher.addEvent([self] { g_eventDispatcher.addEvent([self] {
self->m_updateScheduled = false; self->m_updateScheduled = false;
self->update(); self->update();
}); });

View File

@ -147,7 +147,7 @@ void UIManager::updateHoveredWidget()
if(m_hoverUpdateScheduled) if(m_hoverUpdateScheduled)
return; return;
g_dispatcher.addEvent([this] { g_eventDispatcher.addEvent([this] {
if(!m_rootWidget) if(!m_rootWidget)
return; return;

View File

@ -83,7 +83,7 @@ void UIVerticalLayout::internalUpdate()
if(m_fitChildren && prefferedHeight != parentWidget->getHeight()) { if(m_fitChildren && prefferedHeight != parentWidget->getHeight()) {
// must set the preffered width later // must set the preffered width later
g_dispatcher.addEvent([=] { g_eventDispatcher.addEvent([=] {
parentWidget->setHeight(prefferedHeight); parentWidget->setHeight(prefferedHeight);
}); });
} }

View File

@ -650,7 +650,7 @@ void UIWidget::destroy()
#ifdef DEBUG #ifdef DEBUG
auto self = asUIWidget(); auto self = asUIWidget();
if(self != g_ui.getRootWidget()) { if(self != g_ui.getRootWidget()) {
g_dispatcher.scheduleEvent([self] { g_eventDispatcher.scheduleEvent([self] {
g_lua.collectGarbage(); g_lua.collectGarbage();
if(self->getUseCount() != 1) if(self->getUseCount() != 1)
logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left"); 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 // avoid massive update events
if(!m_updateEventScheduled) { if(!m_updateEventScheduled) {
UIWidgetPtr self = asUIWidget(); UIWidgetPtr self = asUIWidget();
g_dispatcher.addEvent([self, oldRect]() { g_eventDispatcher.addEvent([self, oldRect]() {
self->m_updateEventScheduled = false; self->m_updateEventScheduled = false;
if(oldRect != self->getRect()) if(oldRect != self->getRect())
self->onGeometryChange(oldRect, self->getRect()); self->onGeometryChange(oldRect, self->getRect());
@ -1110,9 +1110,9 @@ void UIWidget::updateState(Fw::WidgetState state)
if(setState(state, newStatus)) { if(setState(state, newStatus)) {
if(state == Fw::FocusState) { 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) } 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) { if(m_loadingStyle && !m_updateStyleScheduled) {
UIWidgetPtr self = asUIWidget(); UIWidgetPtr self = asUIWidget();
g_dispatcher.addEvent([self] { g_eventDispatcher.addEvent([self] {
self->m_updateStyleScheduled = false; self->m_updateStyleScheduled = false;
self->updateStyle(); self->updateStyle();
}); });

View File

@ -56,9 +56,7 @@ inline uint32 getU32(std::istream& in) {
return tmp; return tmp;
} }
/// Fill an ostream by concatenating args // fills an ostream by concatenating args
/// Usage:
/// Fw::fill_ostream(stream, a1, a2, ..., aN);
inline void fillOstream(std::ostringstream&) { } inline void fillOstream(std::ostringstream&) { }
template<class T, class... Args> template<class T, class... Args>
void fillOstream(std::ostringstream& stream, const T& first, const Args&... rest) { 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...); fillOstream(stream, rest...);
} }
/// Makes a std::string by concatenating args // makes a std::string by concatenating args
/// Usage:
/// std::string str = Fw::mkstr(a1, a2, ..., aN);
template<class... T> template<class... T>
std::string mkstr(const T&... args) { std::string mkstr(const T&... args) {
std::ostringstream buf; std::ostringstream buf;
@ -76,9 +72,10 @@ std::string mkstr(const T&... args) {
return buf.str(); return buf.str();
} }
// throw a generic expcetion
template<typename... T> template<typename... T>
void throwException(const T&... args) { void throwException(const T&... args) {
throw Exception(Fw::mkstr(args...)); throw Exception(mkstr(args...));
} }
// used by dumper // used by dumper
@ -91,9 +88,7 @@ struct dump_util {
} }
}; };
/// Utility for dumping variables // utility for dumping variables
/// Usage:
/// Fw::dump << v1, v2, ..., vN;
struct dumper { struct dumper {
dumper() { } dumper() { }
template<class T> template<class T>
@ -104,9 +99,7 @@ struct dumper {
} }
}; };
/// Utility for printing messages into stdout // utility for printing messages into stdout
/// Usage:
/// Fw::print(v1, v2, ..., vN);
template<class... T> template<class... T>
void print(const T&... args) { void print(const T&... args) {
std::ostringstream buf; std::ostringstream buf;
@ -114,14 +107,13 @@ void print(const T&... args) {
std::cout << buf.str(); std::cout << buf.str();
} }
/// Same as Fw::print but adds a new line at the end
template<class... T> template<class... T>
void println(const T&... args) { void println(const T&... args) {
print(args...); print(args...);
std::cout << std::endl; std::cout << std::endl;
} }
/// Demangle names for GNU g++ compiler // demangle names for GNU g++ compiler
inline std::string demangleName(const char* name) { inline std::string demangleName(const char* name) {
size_t len; size_t len;
int status; int status;
@ -134,15 +126,13 @@ inline std::string demangleName(const char* name) {
return ret; return ret;
} }
/// Returns the name of a type // returns the name of a type
/// e.g. Fw::demangle_type<Foo*>() returns a string containing 'Foo*'
template<typename T> template<typename T>
std::string demangleType() { std::string demangleType() {
return demangleName(typeid(T).name()); return demangleName(typeid(T).name());
} }
/// Cast a type to another type // cast a type to another type
/// @return whether the conversion was successful or not
template<typename T, typename R> template<typename T, typename R>
bool cast(const T& in, R& out) { bool cast(const T& in, R& out) {
std::stringstream ss; std::stringstream ss;
@ -194,9 +184,9 @@ inline bool cast(const bool& in, std::string& out) {
} }
// used by safe_cast // used by safe_cast
class CastException : public Exception { class cast_exception : public Exception {
public: public:
virtual ~CastException() throw() { } virtual ~cast_exception() throw() { }
template<class T, class R> template<class T, class R>
void setWhat() { void setWhat() {
m_what = mkstr("failed to cast value of type '", demangleType<T>(), m_what = mkstr("failed to cast value of type '", demangleType<T>(),
@ -207,28 +197,24 @@ private:
std::string m_what; std::string m_what;
}; };
/// Cast a type to another type, any error throws a Fw::bad_cast_exception // cast a type to another type, any error throws a cast_exception
/// Usage:
/// R r = Fw::safe_cast<R>(t);
template<typename R, typename T> template<typename R, typename T>
R safeCast(const T& t) { R safeCast(const T& t) {
R r; R r;
if(!cast(t, r)) { if(!cast(t, r)) {
CastException e; cast_exception e;
e.setWhat<T,R>(); e.setWhat<T,R>();
throw e; throw e;
} }
return r; return r;
} }
/// Cast a type to another type, cast errors are ignored // cast a type to another type, cast errors are ignored
/// Usage:
/// R r = Fw::unsafe_cast<R>(t);
template<typename R, typename T> template<typename R, typename T>
R unsafeCast(const T& t, R def = R()) { R unsafeCast(const T& t, R def = R()) {
try { try {
return safeCast<R,T>(t); return safeCast<R,T>(t);
} catch(CastException& e) { } catch(cast_exception& e) {
println("CAST ERROR: ", e.what()); println("CAST ERROR: ", e.what());
return def; return def;
} }
@ -271,7 +257,7 @@ std::vector<T> split(const std::string& str, const std::string& separators = " "
boost::split(splitted, str, boost::is_any_of(std::string(separators))); boost::split(splitted, str, boost::is_any_of(std::string(separators)));
std::vector<T> results(splitted.size()); std::vector<T> results(splitted.size());
for(uint i=0;i<splitted.size();++i) for(uint i=0;i<splitted.size();++i)
results[i] = Fw::safeCast<T>(splitted[i]); results[i] = safeCast<T>(splitted[i]);
return results; return results;
} }
@ -311,6 +297,4 @@ inline float randomRange<float>(float min, float max) {
// shortcut for Fw::dump // shortcut for Fw::dump
const static Fw::dumper dump; const static Fw::dumper dump;
#define forever for(;;)
#endif #endif

View File

@ -50,7 +50,7 @@ void AnimatedText::startAnimation()
// schedule removal // schedule removal
auto self = asAnimatedText(); 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) void AnimatedText::setColor(int color)

View File

@ -377,7 +377,7 @@ void Creature::nextWalkUpdate()
// schedules next update // schedules next update
if(m_walking) { if(m_walking) {
auto self = asCreature(); auto self = asCreature();
m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { m_walkUpdateEvent = g_eventDispatcher.scheduleEvent([self] {
self->m_walkUpdateEvent = nullptr; self->m_walkUpdateEvent = nullptr;
self->nextWalkUpdate(); self->nextWalkUpdate();
}, m_walkAnimationInterval / 32); }, m_walkAnimationInterval / 32);
@ -500,7 +500,7 @@ void Creature::setShieldTexture(const std::string& filename, bool blink)
if(blink && !m_shieldBlink) { if(blink && !m_shieldBlink) {
auto self = asCreature(); auto self = asCreature();
g_dispatcher.scheduleEvent([self]() { g_eventDispatcher.scheduleEvent([self]() {
self->updateShield(); self->updateShield();
}, SHIELD_BLINK_TICKS); }, SHIELD_BLINK_TICKS);
} }
@ -520,7 +520,7 @@ void Creature::addTimedSquare(uint8 color)
// schedule removal // schedule removal
auto self = asCreature(); auto self = asCreature();
g_dispatcher.scheduleEvent([self]() { g_eventDispatcher.scheduleEvent([self]() {
self->removeTimedSquare(); self->removeTimedSquare();
}, VOLATILE_SQUARE_DURATION); }, VOLATILE_SQUARE_DURATION);
} }
@ -531,7 +531,7 @@ void Creature::updateShield()
if(m_shield != Otc::ShieldNone && m_shieldBlink) { if(m_shield != Otc::ShieldNone && m_shieldBlink) {
auto self = asCreature(); auto self = asCreature();
g_dispatcher.scheduleEvent([self]() { g_eventDispatcher.scheduleEvent([self]() {
self->updateShield(); self->updateShield();
}, SHIELD_BLINK_TICKS); }, SHIELD_BLINK_TICKS);
} }

View File

@ -41,7 +41,7 @@ void Effect::startAnimation()
// schedule removal // schedule removal
auto self = asEffect(); 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) void Effect::setId(uint32 id)

View File

@ -347,7 +347,7 @@ void MapView::updateVisibleTilesCache(int start)
if(stop) { if(stop) {
// schedule next update continuation // 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) if(start == 0)
m_cachedFloorVisibleCreatures = g_map.getSpectators(cameraPosition, false); m_cachedFloorVisibleCreatures = g_map.getSpectators(cameraPosition, false);

View File

@ -78,7 +78,7 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
// schedule removal // schedule removal
auto self = asMissile(); 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) void Missile::setId(uint32 id)

View File

@ -67,7 +67,7 @@ void SpriteManager::preloadSprites()
}; };
for(int i=1;i<=m_spritesCount;i+=burst) 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) TexturePtr SpriteManager::loadSpriteTexture(int id)

View File

@ -62,7 +62,7 @@ bool StaticText::addMessage(const std::string& name, Otc::SpeakType type, const
compose(); compose();
auto self = asStaticText(); auto self = asStaticText();
g_dispatcher.scheduleEvent([self]() { g_eventDispatcher.scheduleEvent([self]() {
self->removeMessage(); self->removeMessage();
}, std::max<int>(Otc::STATIC_DURATION_PER_CHARACTER * message.length(), Otc::MIN_STATIC_TEXT_DURATION)); }, std::max<int>(Otc::STATIC_DURATION_PER_CHARACTER * message.length(), Otc::MIN_STATIC_TEXT_DURATION));
@ -76,7 +76,7 @@ void StaticText::removeMessage()
if(m_messages.empty()) { if(m_messages.empty()) {
// schedule removal // schedule removal
auto self = asStaticText(); auto self = asStaticText();
g_dispatcher.addEvent([self]() { g_map.removeThing(self); }); g_eventDispatcher.addEvent([self]() { g_map.removeThing(self); });
} else } else
compose(); compose();
} }

View File

@ -1164,7 +1164,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
// now that the local player is known, we can schedule login event // now that the local player is known, we can schedule login event
if(creature == m_localPlayer && !m_localPlayer->isKnown()) { if(creature == m_localPlayer && !m_localPlayer->isKnown()) {
m_localPlayer->setKnown(true); m_localPlayer->setKnown(true);
g_dispatcher.addEvent([] { g_game.processLogin(); }); g_eventDispatcher.addEvent([] { g_game.processLogin(); });
} }
} }