modules changes

* speedup widget destruction checks
* rework outfit module using grid layout and the new design
* fixes in console, terminal, textmessage modules
This commit is contained in:
Eduardo Bart
2012-03-22 18:47:52 -03:00
parent 159eb98df2
commit 33458a3e39
41 changed files with 335 additions and 234 deletions

View File

@@ -44,6 +44,8 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
std::size_t now = std::time(NULL);
m_logMessages.push_back(LogMessage(level, outmsg, now));
if(m_logMessages.size() > MAX_LOG_HISTORY)
m_logMessages.pop_front();
if(m_onLog)
m_onLog(level, outmsg, now);

View File

@@ -34,6 +34,10 @@ struct LogMessage {
class Logger
{
enum {
MAX_LOG_HISTORY = 1000
};
typedef std::function<void(Fw::LogLevel, std::string, std::size_t)> OnLogCallback;
public:

View File

@@ -171,7 +171,6 @@ void Texture::generateSoftwareMipmaps(std::vector<uint8> inPixels)
Size outSize = inSize / 2;
std::vector<uint8> outPixels(outSize.area()*4);
dump << "yeah";
int mipmap = 1;
while(true) {
// this is a simple bilinear filtering algorithm, it combines every 4 pixels in one pixel

View File

@@ -225,6 +225,31 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget)
updateDraggingWidget(nullptr);
}
void UIManager::addDestroyedWidget(const UIWidgetPtr& widget)
{
static UIWidgetList destroyedWidgets;
static ScheduledEventPtr checkEvent;
if(widget == m_rootWidget)
return;
destroyedWidgets.push_back(widget);
if(checkEvent && !checkEvent->isExecuted())
return;
checkEvent = g_eventDispatcher.scheduleEvent([] {
g_lua.collectGarbage();
g_eventDispatcher.addEvent([] {
g_lua.collectGarbage();
for(const UIWidgetPtr& widget : destroyedWidgets) {
if(widget->getUseCount() != 1)
logWarning("widget '", widget->getId(), "' destroyed but still have ", widget->getUseCount()-1, " reference(s) left");
}
});
}, 1000);
}
bool UIManager::importStyle(const std::string& file)
{
try {

View File

@@ -68,6 +68,7 @@ protected:
void onWidgetAppear(const UIWidgetPtr& widget);
void onWidgetDisappear(const UIWidgetPtr& widget);
void onWidgetDestroy(const UIWidgetPtr& widget);
void addDestroyedWidget(const UIWidgetPtr& widget);
friend class UIWidget;

View File

@@ -636,10 +636,8 @@ void UIWidget::destroy()
g_ui.onWidgetDestroy(asUIWidget());
// remove itself from parent
if(UIWidgetPtr parent = getParent()) {
assert(parent->hasChild(asUIWidget()));
if(UIWidgetPtr parent = getParent())
parent->removeChild(asUIWidget());
}
destroyChildren();
m_focusedChild = nullptr;
@@ -649,15 +647,7 @@ void UIWidget::destroy()
releaseLuaFieldsTable();
#ifdef DEBUG
auto self = asUIWidget();
g_lua.collectGarbage();
if(self != g_ui.getRootWidget()) {
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");
}, 500);
}
g_ui.addDestroyedWidget(asUIWidget());
#endif
}

View File

@@ -207,6 +207,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture);
g_lua.bindClassMemberFunction<Creature>("showStaticSquare", &Creature::showStaticSquare);
g_lua.bindClassMemberFunction<Creature>("hideStaticSquare", &Creature::hideStaticSquare);
g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking);
g_lua.bindClassMemberFunction<Creature>("asMonster", &Creature::asMonster);
g_lua.bindClassMemberFunction<Creature>("asNpc", &Creature::asNpc);
@@ -220,7 +221,9 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<AnimatedText, Thing>();
g_lua.registerClass<Player, Creature>();
g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking);
g_lua.bindClassMemberFunction<Player>("isPartyMember", &LocalPlayer::isPartyMember);
g_lua.bindClassMemberFunction<Player>("isPartyLeader", &LocalPlayer::isPartyLeader);
g_lua.bindClassMemberFunction<Player>("isPartySharedExperienceActive", &LocalPlayer::isPartySharedExperienceActive);
g_lua.registerClass<Npc, Creature>();
g_lua.registerClass<Monster, Creature>();