cache rendering of UILabel

This commit is contained in:
Eduardo Bart 2012-01-17 03:36:25 -02:00
parent e701cce5fd
commit 7bcf7f536e
15 changed files with 124 additions and 87 deletions

107
TODO
View File

@ -1,26 +1,20 @@
==================================================== ====================================================
High priority TODO in order (before first public disclose) High priority TODO in order (before first public disclose)
[bart] chat with tabs termiante chat
[bart] scrollbar scrollbar
[bart] scrollable widgets scrollable widgets
[bart] complete miniwindow (close, minimize, resize) complete miniwindow (close, minimize, resize, move)
[bart] move windows move windows
[bart] add top menu buttons add top menu buttons
[bart] console scrolling modules managment interface
[bart] modules managment interface adjust interface design
[bart] adjust interface design display exit box when exiting from game
attack modes
[baxnie] display exit box when exiting from game player status icons (poison, etc)
[baxnie] auto walk container windows
[baxnie] attack modes move items
[baxnie] player status icons (poison, etc) use with
[baxnie] container windows
[baxnie] move items
[baxnie] use with
[baxnie] hotkeys window
[baxnie] trade window
[baxnie] battle list
@ -28,25 +22,27 @@ High priority TODO in order (before first public disclose)
Low priority TODO Low priority TODO
== Core == Core
[bart] review directories loading search review directories loading search
[bart] load modules from zip packages load modules from zip packages
[bart] create a class for reading binary files create a class for reading binary files
[bart] rework lua/c++ logger rework lua/c++ logger
[bart] make protocol class compatible with old tibia protocols ake protocol class compatible with old tibia protocols
== Graphics == Graphics
[bart] use CoordsBuffer in font use CoordsBuffer in font
[bart] cache renders into framebuffers cache renders into framebuffers
[bart] use hardware buffer use hardware buffer
[bart] use indices use indices
fix opacity and cached framebuffers conflict
== Lua == Lua
[bart] make possible to bind non LuaObject derived classes on lua engine (for usage with Point,Rect,Color,Size) make possible to bind non LuaObject derived classes on lua engine (for usage with Point,Rect,Color,Size)
[bart] review usage of x,y/width,height in lua instead of point/size review usage of x,y/width,height in lua instead of point/size
== Platform == Platform
[bart] port to MacOs and iphone port to MacOs and iphone
change win32 mouse cursor icon change win32 mouse cursor icon
rework win32 key input system
== UI == UI
[bart] fix massive hotkeys when holding down a key [bart] fix massive hotkeys when holding down a key
@ -66,26 +62,29 @@ change win32 mouse cursor icon
[bart] make api to enable/disable capture of events to avoid massive event processing [bart] make api to enable/disable capture of events to avoid massive event processing
[bart] review style apply system [bart] review style apply system
== Client modules
[bart] make possible to reload modules
== Client == Client
[bart] implement left panel with dragging windows make possible to reload modules
[bart] clean sprites cache periodically terminal/console scrolling
[bart] create a shader manager auto walk
[bart] find a way to load map rendering styles hotkeys window
[bart] move redering of creatures names, skulls, etc to UI trade window
[bart] cache screen creatures in a list on map battle list
[bart] handle corrupt errors in dat/spr implement left panel with dragging windows
[bart] remake spr/dat using OTML and image files clean sprites cache periodically
[bart] rework map tile rendering (cache visible tiles, etc) create a shader manager
[bart] minimap window find a way to load map rendering styles
[bart] draw lights using shaders move redering of creatures names, skulls, etc to UI
[bart] limit FPS in options cache screen creatures in a list on map
[bart] resize map, right panel handle corrupt errors in dat/spr
[baxnie] do lua game event calls from Game instead from GameProtocol remake spr/dat using OTML and image files
[baxnie] login queue rework map tile rendering (cache visible tiles, etc)
[baxnie] questlog minimap window
[baxnie] edit texts draw lights using shaders
[baxnie] ignore list limit FPS in options
[baxnie] viplist marks resize map, right panel
do lua game event calls from Game instead from GameProtocol
login queue
questlog
edit texts
ignore list
viplist marks

View File

@ -1,6 +1,6 @@
Client = {} Client = {}
local function setupWindow() function Client.init()
g_window.show() g_window.show()
g_window.setMinimumSize({ width = 600, height = 480 }) g_window.setMinimumSize({ width = 600, height = 480 })
@ -29,11 +29,8 @@ local function setupWindow()
g_window.setIcon(resolvepath('clienticon.png')) g_window.setIcon(resolvepath('clienticon.png'))
end end
function Client.init()
setupWindow()
end
function Client.terminate() function Client.terminate()
-- save window configs
Settings.set('window-size', g_window.getUnmaximizedSize()) Settings.set('window-size', g_window.getUnmaximizedSize())
Settings.set('window-pos', g_window.getUnmaximizedPos()) Settings.set('window-pos', g_window.getUnmaximizedPos())
Settings.set('window-maximized', g_window.isMaximized()) Settings.set('window-maximized', g_window.isMaximized())

View File

@ -8,5 +8,5 @@ Module
require 'options' require 'options'
Options.init() Options.init()
onUnload: onUnload: |
Options.terminate() Options.terminate()

View File

@ -55,8 +55,8 @@ local function onWidgetStyleApply(widget, styleName, styleNode)
end end
end end
--connect(UIWidget, { onStyleApply = onWidgetStyleApply, connect(UIWidget, { onStyleApply = onWidgetStyleApply,
-- onHoverChange = onWidgetHoverChange}) onHoverChange = onWidgetHoverChange})
-- UIWidget extensions -- UIWidget extensions
function UIWidget:setTooltip(text) function UIWidget:setTooltip(text)

View File

@ -42,6 +42,9 @@ FrameBuffer::~FrameBuffer()
void FrameBuffer::resize(const Size& size) void FrameBuffer::resize(const Size& size)
{ {
if(m_texture && m_texture->getSize() == size)
return;
internalBind(); internalBind();
m_texture = TexturePtr(new Texture(size.width(), size.height(), 4)); m_texture = TexturePtr(new Texture(size.width(), size.height(), 4));
m_texture->setSmooth(true); m_texture->setSmooth(true);

View File

@ -131,8 +131,8 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
case CompositionMode_Multiply: case CompositionMode_Multiply:
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
break; break;
case CompositionMode_Addition: case CompositionMode_Add:
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_ONE, GL_ONE);
break; break;
} }
} }

View File

@ -34,7 +34,7 @@ public:
enum CompositionMode { enum CompositionMode {
CompositionMode_Normal, CompositionMode_Normal,
CompositionMode_Multiply, CompositionMode_Multiply,
CompositionMode_Addition CompositionMode_Add
}; };
void init(); void init();
@ -57,6 +57,7 @@ public:
void setCustomProgram(PainterShaderProgramPtr program); void setCustomProgram(PainterShaderProgramPtr program);
void releaseCustomProgram() { m_customProgram = nullptr; } void releaseCustomProgram() { m_customProgram = nullptr; }
void setCompositionMode(CompositionMode compositionMode); void setCompositionMode(CompositionMode compositionMode);
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
void setProjectionMatrix(const Matrix3& projectionMatrix) { m_projectionMatrix = projectionMatrix; } void setProjectionMatrix(const Matrix3& projectionMatrix) { m_projectionMatrix = projectionMatrix; }
Matrix3 getProjectionMatrix() { return m_projectionMatrix; } Matrix3 getProjectionMatrix() { return m_projectionMatrix; }

View File

@ -163,7 +163,7 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
else if(childNode->value() == "multiply") else if(childNode->value() == "multiply")
m_pCompositionMode = Painter::CompositionMode_Multiply; m_pCompositionMode = Painter::CompositionMode_Multiply;
else if(childNode->value() == "addition") else if(childNode->value() == "addition")
m_pCompositionMode = Painter::CompositionMode_Addition; m_pCompositionMode = Painter::CompositionMode_Add;
} }
} }

View File

@ -704,6 +704,7 @@ void X11Window::poll()
break; break;
case UnmapNotify: case UnmapNotify:
m_visible = false; m_visible = false;
releaseAllKeys();
break; break;
case FocusIn: case FocusIn:
m_focused = true; m_focused = true;

View File

@ -407,6 +407,10 @@ private:
void initText(); void initText();
void parseTextStyle(const OTMLNodePtr& styleNode); void parseTextStyle(const OTMLNodePtr& styleNode);
Boolean<true> m_textMustRecache;
FrameBufferPtr m_textFramebuffer;
Size m_textCachedBoxSize;
protected: protected:
void drawText(const Rect& screenCoords); void drawText(const Rect& screenCoords);
@ -423,8 +427,8 @@ public:
void clearText() { setText(""); } void clearText() { setText(""); }
void setText(const std::string& text); void setText(const std::string& text);
void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; } void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; m_textMustRecache = true; }
void setTextOffset(const Point& offset) { m_textOffset = offset; } void setTextOffset(const Point& offset) { m_textOffset = offset; m_textMustRecache = true; }
void setFont(const std::string& fontName); void setFont(const std::string& fontName);
std::string getText() { return m_text; } std::string getText() { return m_text; }

View File

@ -24,6 +24,7 @@
#include "uitranslator.h" #include "uitranslator.h"
#include <framework/graphics/fontmanager.h> #include <framework/graphics/fontmanager.h>
#include <framework/graphics/painter.h> #include <framework/graphics/painter.h>
#include <framework/graphics/framebuffer.h>
void UIWidget::initText() void UIWidget::initText()
{ {
@ -47,12 +48,30 @@ void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode)
void UIWidget::drawText(const Rect& screenCoords) void UIWidget::drawText(const Rect& screenCoords)
{ {
g_painter.setColor(m_color); if(m_text.length() == 0 || m_color.a() == 0)
if(m_text.length() > 0 && m_color.a() > 0) { return;
Rect textRect = screenCoords;
textRect.translate(m_textOffset); Size boxSize = screenCoords.size();
m_font->renderText(m_text, textRect, m_textAlign, m_color); if(boxSize != m_textCachedBoxSize || m_textMustRecache) {
if(!m_textFramebuffer)
m_textFramebuffer = FrameBufferPtr(new FrameBuffer(boxSize));
else
m_textFramebuffer->resize(boxSize);
m_textFramebuffer->bind();
Rect virtualTextRect(0, 0, boxSize);
virtualTextRect.translate(m_textOffset);
g_painter.setCompositionMode(Painter::CompositionMode_Add);
m_font->renderText(m_text, virtualTextRect, m_textAlign, Fw::white);
g_painter.resetCompositionMode();
m_textFramebuffer->release();
m_textMustRecache = false;
m_textCachedBoxSize = boxSize;
} }
g_painter.setColor(m_color);
m_textFramebuffer->draw(screenCoords);
} }
void UIWidget::onTextChange(const std::string& text) void UIWidget::onTextChange(const std::string& text)
@ -67,7 +86,9 @@ void UIWidget::onFontChange(const std::string& font)
void UIWidget::setText(const std::string& text) void UIWidget::setText(const std::string& text)
{ {
if(m_text != text) { if(m_text == text)
return;
m_text = text; m_text = text;
// update rect size // update rect size
@ -82,11 +103,12 @@ void UIWidget::setText(const std::string& text)
} }
onTextChange(text); onTextChange(text);
} m_textMustRecache = true;
} }
void UIWidget::setFont(const std::string& fontName) void UIWidget::setFont(const std::string& fontName)
{ {
m_font = g_fonts.getFont(fontName); m_font = g_fonts.getFont(fontName);
onFontChange(fontName); onFontChange(fontName);
m_textMustRecache = true;
} }

View File

@ -162,7 +162,7 @@ void Game::processWalkCancel(Otc::Direction direction)
void Game::walk(Otc::Direction direction) void Game::walk(Otc::Direction direction)
{ {
if(!isOnline() || isDead() || !checkBotProtection()) if(!isOnline() || !m_localPlayer->isKnown() || isDead() || !checkBotProtection())
return; return;
if(m_localPlayer->isFollowing()) if(m_localPlayer->isFollowing())

View File

@ -39,6 +39,9 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
// check for blockable tiles in the walk direction // check for blockable tiles in the walk direction
TilePtr tile = g_map.getTile(m_pos + Position::getPosFromDirection(direction)); TilePtr tile = g_map.getTile(m_pos + Position::getPosFromDirection(direction));
if(!tile)
return false;
if(!tile->isWalkable()) { if(!tile->isWalkable()) {
g_game.processTextMessage("statusSmall", "Sorry, not possible."); g_game.processTextMessage("statusSmall", "Sorry, not possible.");
return false; return false;

View File

@ -34,6 +34,7 @@ public:
void setAttackingCreature(const CreaturePtr& creature); void setAttackingCreature(const CreaturePtr& creature);
void setFollowingCreature(const CreaturePtr& creature); void setFollowingCreature(const CreaturePtr& creature);
void setIcons(Otc::PlayerIcons icons) { m_icons = icons; } void setIcons(Otc::PlayerIcons icons) { m_icons = icons; }
void setKnown(bool known) { m_known = known; }
bool getCanReportBugs() { return m_canReportBugs; } bool getCanReportBugs() { return m_canReportBugs; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; } int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
@ -42,6 +43,7 @@ public:
CreaturePtr getFollowingCreature() { return m_followingCreature; } CreaturePtr getFollowingCreature() { return m_followingCreature; }
Otc::PlayerIcons getIcons() { return m_icons; } Otc::PlayerIcons getIcons() { return m_icons; }
bool isKnown() { return m_known; }
bool isAttacking() { return m_attackingCreature != nullptr; } bool isAttacking() { return m_attackingCreature != nullptr; }
bool isFollowing() { return m_followingCreature != nullptr; } bool isFollowing() { return m_followingCreature != nullptr; }
@ -65,6 +67,7 @@ public:
private: private:
bool m_canReportBugs; bool m_canReportBugs;
bool m_known;
CreaturePtr m_attackingCreature, m_followingCreature; CreaturePtr m_attackingCreature, m_followingCreature;
Otc::PlayerIcons m_icons; Otc::PlayerIcons m_icons;
int m_skills[Otc::LastSkill][Otc::LastSkillType]; int m_skills[Otc::LastSkill][Otc::LastSkillType];

View File

@ -1142,6 +1142,10 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
creature->setEmblem(emblem); creature->setEmblem(emblem);
creature->setPassable(passable); creature->setPassable(passable);
creature->cancelWalk(direction); creature->cancelWalk(direction);
if(creature == m_localPlayer) {
m_localPlayer->setKnown(true);
}
} }
thing = creature; thing = creature;