summary refs log tree commit diff
path: root/lib/main.fnl
diff options
context:
space:
mode:
authorequa <equaa@protonmail.com>2021-04-18 14:45:55 -0500
committerequa <equaa@protonmail.com>2021-04-18 14:48:02 -0500
commit78530480d35be5dbb57f1a264147bec48d6cf800 (patch)
tree197350b11e46593db326b563e0917e9536329aa1 /lib/main.fnl
parent0c8a8cf8d861bc4ef3162e45e8b58d2f0173d2f7 (diff)
visual changes (zooming) and optimization
also profiling
Diffstat (limited to 'lib/main.fnl')
-rw-r--r--lib/main.fnl25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/main.fnl b/lib/main.fnl
index 4a9d26e..03383ad 100644
--- a/lib/main.fnl
+++ b/lib/main.fnl
@@ -2,6 +2,8 @@
 (local proto (require :lib.proto))
 (local state (require :lib.state))
 (local game (require :lib.game))
+(local profi (require :vendor.ProFi))
+(local profi? false)
 
 ;; i am thinking we could actually do a really hacky thing (modules add themselves
 ;; to this list) with this later but
@@ -16,6 +18,10 @@
 ;; oh thats why it doesnt work lmao
 
 (fn love.load []
+  (when profi?
+    (profi:start))
+  (set love.frame 0)
+  (love.keyboard.setKeyRepeat true)
   (global the-state (state.init game))
   (global messages {})
   (print "a"))
@@ -42,6 +48,13 @@
 
 ;; TODO: we need a better way to display errors at runtime for updates too
 (fn love.update []
+  (when profi?
+    (profi:startHooks)
+    (set love.frame (+ love.frame 1))
+    (when (= (% love.frame 100) 0)
+      (profi:stop)
+      (profi:writeReport)
+      (os.exit)))
   ;; TODO: make state changes actually possible
   (match (pcall #(state.update the-state))
     (true x) nil
@@ -49,10 +62,18 @@
                 (print (.. "update: \n" x))
                 (table.insert messages
                               {:ticks 1
-                               :msg (.. "update: \n" x)}))))
+                               :msg (.. "update: \n" x)})))
+  (when profi?
+    (profi:stopHooks)))
 
 (fn love.keypressed [key scancode repeat]
-  ;; (print key scancode repeat)
+  (match (pcall #(state.keypressed the-state key scancode repeat))
+    (true x) nil
+    (false x) (do
+                (print (.. "keypressed: \n" x))
+                (table.insert messages
+                              {:ticks 5
+                               :msg (.. "keypressed: \n" x)})))
   (when (= key "r")
     (each [k v (lume.ripairs messages)]
       (when (= v.type :reload-error)