about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-24 13:27:04 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-24 13:27:04 -0700
commitce31b74b10798799f03b1a9fb54dff491a1cf223 (patch)
tree3c4ff3c6fc1501fbc743a85157b2768b2c7bfbe2 /main.lua
parent89222f86a0dc3dd774ce46afaa1ba791ed65dba9 (diff)
downloadlines.love-ce31b74b10798799f03b1a9fb54dff491a1cf223.tar.gz
infrastructure for caching LÖVE text objects
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua11
1 files changed, 11 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index f328139..a41d93b 100644
--- a/main.lua
+++ b/main.lua
@@ -16,6 +16,9 @@ Editor_state = {}
 function App.initialize_globals()
   -- tests currently mostly clear their own state
 
+  -- a few text objects we can avoid recomputing unless the font changes
+  Text_cache = {}
+
   -- blinking cursor
   Cursor_time = 0
 
@@ -204,3 +207,11 @@ function App.keyreleased(key, scancode)
   Cursor_time = 0  -- ensure cursor is visible immediately after it moves
   return edit.key_released(Editor_state, key, scancode)
 end
+
+-- use this sparingly
+function to_text(s)
+  if Text_cache[s] == nil then
+    Text_cache[s] = App.newText(love.graphics.getFont(), s)
+  end
+  return Text_cache[s]
+end