summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2018-11-21 18:49:13 -0600
committercheapie <no-email-for-you@example.com>2018-11-21 18:49:13 -0600
commitc199a33bb83319c982031af988f681e2e0c016c4 (patch)
tree346be3c811c4903294d008ce0b54eb2b7835e158 /init.lua
parentb057341a07c688e1560dfef569058e9fdef54d01 (diff)
downloadsigns_lib-master.tar
signs_lib-master.tar.gz
signs_lib-master.tar.bz2
signs_lib-master.tar.xz
signs_lib-master.zip
Cache character texturesHEADmaster
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua20
1 files changed, 14 insertions, 6 deletions
diff --git a/init.lua b/init.lua
index 8e0d047..82a0f1b 100644
--- a/init.lua
+++ b/init.lua
@@ -26,6 +26,9 @@ signs_lib.gettext = S
-- text encoding
dofile(signs_lib.path .. "/encoding.lua");
+-- Initialize character texture cache
+local ctexcache = {}
+
local wall_dir_change = {
[0] = 4,
@@ -362,14 +365,19 @@ end
-- make char texture file name
-- if texture file does not exist use fallback texture instead
local function char_tex(font_name, ch)
- local c = ch:byte()
- local exists, tex = file_exists(CHAR_PATH:format(font_name, c))
- if exists and c ~= 14 then
- tex = CHAR_FILE:format(font_name, c)
+ if ctexcache[font_name..ch] then
+ return ctexcache[font_name..ch], true
else
- tex = CHAR_FILE:format(font_name, 0x0)
+ local c = ch:byte()
+ local exists, tex = file_exists(CHAR_PATH:format(font_name, c))
+ if exists and c ~= 14 then
+ tex = CHAR_FILE:format(font_name, c)
+ else
+ tex = CHAR_FILE:format(font_name, 0x0)
+ end
+ ctexcache[font_name..ch] = tex
+ return tex, exists
end
- return tex, exists
end
local function make_line_texture(line, lineno, pos)