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
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

View File

@ -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)

View File

@ -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<std::string>& 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()

View File

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

View File

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

View File

@ -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]);
}

View File

@ -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));
}

View File

@ -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();

View File

@ -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);
});
}

View File

@ -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();
});

View File

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

View File

@ -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);
});
}

View File

@ -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();
});

View File

@ -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<class T, class... Args>
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<class... T>
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<typename... T>
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<class T>
@ -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<class... T>
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<class... T>
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<Foo*>() returns a string containing 'Foo*'
// returns the name of a type
template<typename T>
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<typename T, typename R>
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<class T, class R>
void setWhat() {
m_what = mkstr("failed to cast value of type '", demangleType<T>(),
@ -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<R>(t);
// cast a type to another type, any error throws a cast_exception
template<typename R, typename T>
R safeCast(const T& t) {
R r;
if(!cast(t, r)) {
CastException e;
cast_exception e;
e.setWhat<T,R>();
throw e;
}
return r;
}
/// Cast a type to another type, cast errors are ignored
/// Usage:
/// R r = Fw::unsafe_cast<R>(t);
// cast a type to another type, cast errors are ignored
template<typename R, typename T>
R unsafeCast(const T& t, R def = R()) {
try {
return safeCast<R,T>(t);
} catch(CastException& e) {
} catch(cast_exception& e) {
println("CAST ERROR: ", e.what());
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)));
std::vector<T> results(splitted.size());
for(uint i=0;i<splitted.size();++i)
results[i] = Fw::safeCast<T>(splitted[i]);
results[i] = safeCast<T>(splitted[i]);
return results;
}
@ -311,6 +297,4 @@ inline float randomRange<float>(float min, float max) {
// shortcut for Fw::dump
const static Fw::dumper dump;
#define forever for(;;)
#endif

View File

@ -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)

View File

@ -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);
}

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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)

View File

@ -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<int>(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();
}

View File

@ -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(); });
}
}