Skip to content
Snippets Groups Projects
Commit f3cd48b4 authored by dg's avatar dg
Browse files

Increased UI display speed. LogFlasher, LogDisplay, HotkeysDisplay,...

Increased UI display speed. LogFlasher, LogDisplay, HotkeysDisplay, ActorsSeenDisplay, Tooltip and PlayerDisplay classes have changed and are now easier (and faster) to use. Converting is easy:
 * In your Game:display() change lines like self.log:display():toScreen(self.display_x, self.display_y)
 * to simply: self.log:toScreen()
 * To convert your own PlayerDisplay have a look at ToME's one, but basically you just need to create a texture with :glTexture() and then update it at the end of yoru display() and add a new toScreen() method


git-svn-id: http://svn.net-core.org/repos/t-engine4@1174 51575b47-30f0-44d4-a5cc-537603b46e54
parent db497bff
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ function _M:resize(x, y, w, h)
self.display_x, self.display_y = math.floor(x), math.floor(y)
self.w, self.h = math.floor(w), math.floor(h)
self.surface = core.display.newSurface(w, h)
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
if self.actor then self.actor.changed = true end
local cw, ch = self.font:size(" ")
......@@ -71,5 +72,11 @@ function _M:display()
self.surface:drawColorStringBlended(self.font, ("%s (%d)#WHITE#; distance [%s]"):format(a.name, a.nb, table.concat(a.dist, ",")), 0, (i - 1) * self.font_h, a.color[1], a.color[2], a.color[3])
end
self.surface:updateTexture(self.texture)
return self.surface
end
function _M:toScreen()
self:display()
self.texture:toScreenFull(self.display_x, self.display_y, self.w, self.h, self.texture_w, self.texture_h)
end
......@@ -35,6 +35,7 @@ function _M:resize(x, y, w, h)
self.display_x, self.display_y = math.floor(x), math.floor(y)
self.w, self.h = math.floor(w), math.floor(h)
self.surface = core.display.newSurface(w, h)
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
if self.actor then self.actor.changed = true end
local cw, ch = self.font:size(" ")
......@@ -107,9 +108,15 @@ function _M:display()
end
end
self.surface:updateTexture(self.texture)
return self.surface
end
function _M:toScreen()
self:display()
self.texture:toScreenFull(self.display_x, self.display_y, self.w, self.h, self.texture_w, self.texture_h)
end
--- Call when a mouse event arrives in this zone
-- This is optional, only if you need mouse support
function _M:onMouse(button, mx, my, click)
......
......@@ -31,6 +31,7 @@ function _M:init(x, y, w, h, max, fontname, fontsize, color, bgcolor)
self.font = core.display.newFont(fontname or "/data/font/Vera.ttf", fontsize or 12)
self.font_h = self.font:lineSkip()
self.surface = core.display.newSurface(w, h)
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
self.log = {}
getmetatable(self).__call = _M.call
self.max = max or 4000
......@@ -43,6 +44,7 @@ function _M:resize(x, y, w, h)
self.display_x, self.display_y = math.floor(x), math.floor(y)
self.w, self.h = math.floor(w), math.floor(h)
self.surface = core.display.newSurface(w, h)
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
self.changed = true
end
......@@ -96,9 +98,15 @@ function _M:display()
if self.log[self.scroll + i].reset then r, g, b = self.color[1], self.color[2], self.color[3] end
end
end
self.surface:updateTexture(self.texture)
return self.surface
end
function _M:toScreen()
self:display()
self.texture:toScreenFull(self.display_x, self.display_y, self.w, self.h, self.texture_w, self.texture_h)
end
--- Scroll the zone
-- @param i number representing how many lines to scroll
function _M:scrollUp(i)
......
......@@ -35,6 +35,7 @@ function _M:init(x, y, w, h, max, fontname, fontsize, color, bgcolor)
self.font = core.display.newFont(fontname or "/data/font/Vera.ttf", fontsize or 16)
self.font_h = self.font:lineSkip()
self.surface = core.display.newSurface(w, h)
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
self.log = {}
getmetatable(self).__call = _M.call
self.flashing_style = NEUTRAL
......@@ -47,6 +48,7 @@ function _M:resize(x, y, w, h)
self.display_x, self.display_y = math.floor(x), math.floor(y)
self.w, self.h = math.floor(w), math.floor(h)
self.surface = core.display.newSurface(w, h)
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
self.changed = true
end
......@@ -58,17 +60,27 @@ function _M:call(style, str, ...)
if self.flashing == 0 and #self.log > 0 then self.log = {} end
local base = ""
if #self.log > 0 then base = table.remove(self.log)[1] end
if #self.log > 0 then base = table.remove(self.log) end
local lines = (base .. " " .. str:format(...)):splitLines(self.w - 4, self.font)
for i = 1, #lines do
self.surface:erase(0,0,0,255)
self.surface:drawColorStringBlended(self.font, lines[i], 0, 0, self.color[1], self.color[2], self.color[3])
local t = self.surface:glTexture()
table.insert(self.log, {lines[i],t})
table.insert(self.log, lines[i])
end
self.flashing_style = style
self.flashing = 20
self:getNext()
end
function _M:getNext(remove)
if remove then table.remove(self.log, 1) end
local line = self.log[1]
self.surface:erase(0,0,0,0)
if line then
self.surface:drawColorStringBlended(self.font, line, 0, 0, self.color[1], self.color[2], self.color[3], true)
end
self.surface:updateTexture(self.texture)
self.changed = true
end
......@@ -81,7 +93,7 @@ function _M:empty(force)
end
end
function _M:display()
function _M:toScreen()
self.changed = false
-- Erase and the display the map
......@@ -92,10 +104,8 @@ function _M:display()
else
core.display.drawQuad(self.display_x, self.display_y, self.w, self.h, self.bgcolor[1], self.bgcolor[2] + self.flashing * 10, self.bgcolor[3], 255)
end
self.texture:toScreenFull(self.display_x, self.display_y, self.w, self.h, self.texture_w, self.texture_h)
-- if self.log[1] then self.log[1][2]:toScreen(self.display_x, self.display_y, self.w, self.h) end
self.flashing = self.flashing - 1
if self.flashing > 0 then
else table.remove(self.log, 1) end
if self.flashing > 0 then self.flashing = self.flashing - 1
elseif self.changed then self:getNext(true) end
end
......@@ -58,6 +58,7 @@ end
function _M:erase()
self.surface = nil
self.texture = nil
end
function _M:display()
......@@ -97,12 +98,12 @@ function _M:display()
y = y + self.font_h
end
end
self.texture = self.surface:glTexture()
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
end
function _M:toScreen(x, y)
if self.surface then
self.surface:toScreenWithTexture(self.texture, x, y)
if self.texture then
self.texture:toScreenFull(x, y, self.w, self.h, self.texture_w, self.texture_h)
end
end
......@@ -135,13 +136,13 @@ function _M:displayAtMap(tmx, tmy, mx, my)
end
end
if self.surface then
if self.texture then
mx = mx - self.w / 2 + game.level.map.tile_w / 2
my = my - self.h
if mx < 0 then mx = 0 end
if my < 0 then my = 0 end
if mx > game.w - self.w then mx = game.w - self.w end
if my > game.h - self.h then my = game.h - self.h end
self.surface:toScreenWithTexture(self.texture, mx, my)
self.texture:toScreenFull(mx, my, self.w, self.h, self.texture_w, self.texture_h)
end
end
......@@ -248,7 +248,7 @@ function string.parseHex(str)
end
local tmps = core.display.newSurface(1, 1)
getmetatable(tmps).__index.drawColorString = function(s, font, str, x, y, r, g, b)
getmetatable(tmps).__index.drawColorString = function(s, font, str, x, y, r, g, b, alpha_from_texture)
local list = str:split("#" * (Puid + Pcolorcodefull + Pcolorname + Pfontstyle) * "#", true)
r = r or 255
g = g or 255
......@@ -286,21 +286,21 @@ getmetatable(tmps).__index.drawColorString = function(s, font, str, x, y, r, g,
else
local w, h = font:size(v)
if h > max_h then max_h = h end
s:drawString(font, v, x, y, r, g, b)
s:drawString(font, v, x, y, r, g, b, alpha_from_texture)
x = x + w
end
end
return r, g, b, max_h
end
getmetatable(tmps).__index.drawColorStringCentered = function(s, font, str, dx, dy, dw, dh, r, g, b)
getmetatable(tmps).__index.drawColorStringCentered = function(s, font, str, dx, dy, dw, dh, r, g, b, alpha_from_texture)
local w, h = font:size(str)
local x, y = dx + (dw - w) / 2, dy + (dh - h) / 2
s:drawColorString(font, str, x, y, r, g, b)
s:drawColorString(font, str, x, y, r, g, b, alpha_from_texture)
end
getmetatable(tmps).__index.drawColorStringBlended = function(s, font, str, x, y, r, g, b)
getmetatable(tmps).__index.drawColorStringBlended = function(s, font, str, x, y, r, g, b, alpha_from_texture)
local list = str:split("#" * (Puid + Pcolorcodefull + Pcolorname + Pfontstyle) * "#", true)
r = r or 255
g = g or 255
......@@ -338,17 +338,17 @@ getmetatable(tmps).__index.drawColorStringBlended = function(s, font, str, x, y,
else
local w, h = font:size(v)
if h > max_h then max_h = h end
s:drawStringBlended(font, v, x, y, r, g, b)
s:drawStringBlended(font, v, x, y, r, g, b, alpha_from_texture)
x = x + w
end
end
return r, g, b, max_h
end
getmetatable(tmps).__index.drawColorStringBlendedCentered = function(s, font, str, dx, dy, dw, dh, r, g, b)
getmetatable(tmps).__index.drawColorStringBlendedCentered = function(s, font, str, dx, dy, dw, dh, r, g, b, alpha_from_texture)
local w, h = font:size(str)
local x, y = dx + (dw - w) / 2, dy + (dh - h) / 2
s:drawColorStringBlended(font, str, x, y, r, g, b)
s:drawColorStringBlended(font, str, x, y, r, g, b, alpha_from_texture)
end
dir_to_coord = {
......
......@@ -225,12 +225,12 @@ function _M:display()
end
-- We display the player's interface
self.flash:display():toScreen(self.flash.display_x, self.flash.display_y)
self.logdisplay:display():toScreen(self.logdisplay.display_x, self.logdisplay.display_y)
self.flash:toScreen()
self.logdisplay:toScreen()
if self.show_npc_list then
self.npcs_display:display():toScreen(self.npcs_display.display_x, self.npcs_display.display_y)
self.npcs_display:toScreen()
else
self.hotkeys_display:display():toScreen(self.hotkeys_display.display_x, self.hotkeys_display.display_y)
self.hotkeys_display:toScreen()
end
if self.player then self.player.changed = false end
......
......@@ -224,12 +224,12 @@ function _M:display()
end
-- We display the player's interface
self.flash:display():toScreen(self.flash.display_x, self.flash.display_y)
self.logdisplay:display():toScreen(self.logdisplay.display_x, self.logdisplay.display_y)
self.flash:toScreen()
self.logdisplay:toScreen()
if self.show_npc_list then
self.npcs_display:display():toScreen(self.npcs_display.display_x, self.npcs_display.display_y)
self.npcs_display:toScreen()
else
self.hotkeys_display:display():toScreen(self.hotkeys_display.display_x, self.hotkeys_display.display_y)
self.hotkeys_display:toScreen()
end
if self.player then self.player.changed = false end
......
......@@ -403,10 +403,8 @@ function _M:onTurn()
end
function _M:display()
local st = core.game.getTime()
-- Now the map, if any
if self.level and self.level.map and self.level.map.finished then
print("=====display01", core.game.getTime()-st)
-- Display the map and compute FOV for the player if needed
if self.level.map.changed then
self.player:playerFOV()
......@@ -417,7 +415,6 @@ print("=====display01", core.game.getTime()-st)
self.level.data.background(self.level)
end
print("=====display02", core.game.getTime()-st)
-- Display using Framebuffer, sotaht we can use shaders and all
if self.fbo then
self.fbo:use(true)
......@@ -436,8 +433,6 @@ print("=====display02", core.game.getTime()-st)
self.target:display()
end
print("=====display03", core.game.getTime()-st)
if not self.zone_name_s then
local s = core.display.drawStringBlendedNewSurface(self.player_display.font, ("%s (%d)"):format(self.zone.name, self.level.level), 0, 255, 255)
self.zone_name_s = s:glTexture()
......@@ -448,34 +443,26 @@ print("=====display03", core.game.getTime()-st)
self.level.map.display_y + self.level.map.viewport.height - self.zone_name_h,
self.zone_name_w, self.zone_name_h
)
print("=====display04", core.game.getTime()-st)
-- Minimap display
self.level.map:minimapDisplay(0, 20, util.bound(self.player.x - 25, 0, self.level.map.w - 50), util.bound(self.player.y - 25, 0, self.level.map.h - 50), 50, 50, 1)
print("=====display05", core.game.getTime()-st)
end
-- We display the player's interface
self.flash:display()
print("=====display06", core.game.getTime()-st)
self.logdisplay:display():toScreen(self.logdisplay.display_x, self.logdisplay.display_y)
print("=====display07", core.game.getTime()-st)
self.player_display:display():toScreen(self.player_display.display_x, self.player_display.display_y)
print("=====display08", core.game.getTime()-st)
self.flash:toScreen()
self.logdisplay:toScreen()
self.player_display:toScreen()
if self.show_npc_list then
self.npcs_display:display():toScreen(self.npcs_display.display_x, self.npcs_display.display_y)
self.npcs_display:toScreen()
else
self.hotkeys_display:display():toScreen(self.hotkeys_display.display_x, self.hotkeys_display.display_y)
self.hotkeys_display:toScreen()
end
if self.player then self.player.changed = false end
print("=====display09", core.game.getTime()-st)
-- Tooltip is displayed over all else
self:targetDisplayTooltip(game.w, game.h)
print("=====display10", core.game.getTime()-st)
engine.GameTurnBased.display(self)
print("=====display11", core.game.getTime()-st)
end
function _M:setupCommands()
......
......@@ -27,7 +27,6 @@ function _M:init(x, y, w, h, bgcolor)
self.w, self.h = w, h
self.bgcolor = bgcolor
self.font = core.display.newFont("/data/font/VeraMono.ttf", 14)
self.surface = core.display.newSurface(w, h)
self:resize(x, y, w, h)
end
......@@ -40,6 +39,7 @@ function _M:resize(x, y, w, h)
self.bars_x = self.font_w * 9
self.bars_w = self.w - self.bars_x - 5
self.surface = core.display.newSurface(w, h)
self.texture, self.texture_w, self.texture_h = self.surface:glTexture()
end
-- Displays the stats
......@@ -124,5 +124,11 @@ function _M:display()
end
end
self.surface:updateTexture(self.texture)
return self.surface
end
function _M:toScreen()
self:display()
self.texture:toScreenFull(self.display_x, self.display_y, self.w, self.h, self.texture_w, self.texture_h)
end
......@@ -527,11 +527,13 @@ static int sdl_surface_drawstring(lua_State *L)
int r = luaL_checknumber(L, 6);
int g = luaL_checknumber(L, 7);
int b = luaL_checknumber(L, 8);
bool alpha_from_texture = lua_toboolean(L, 9);
SDL_Color color = {r,g,b};
SDL_Surface *txt = TTF_RenderUTF8_Solid(*f, str, color);
if (txt)
{
if (alpha_from_texture) SDL_SetAlpha(txt, 0, 0);
sdlDrawImage(*s, txt, x, y);
SDL_FreeSurface(txt);
}
......@@ -549,11 +551,13 @@ static int sdl_surface_drawstring_aa(lua_State *L)
int r = luaL_checknumber(L, 6);
int g = luaL_checknumber(L, 7);
int b = luaL_checknumber(L, 8);
bool alpha_from_texture = lua_toboolean(L, 9);
SDL_Color color = {r,g,b};
SDL_Surface *txt = TTF_RenderUTF8_Blended(*f, str, color);
if (txt)
{
if (alpha_from_texture) SDL_SetAlpha(txt, 0, 0);
sdlDrawImage(*s, txt, x, y);
SDL_FreeSurface(txt);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment