blob: e2c1bbc455f1d1d5d91ae2b080bb5d0f7e11bdb9 [file] [log] [blame]
Serge Bazanski18c1a262022-07-07 14:24:53 +02001class = require('vendor.30log')
2inspect = require('vendor.inspect')
3lume = require('vendor.lume')
4
5Node = require('core.node')
6ThreadNode = require('core.thread-node')
7NodeManager = require('core.node-manager')
8
9local config = nil
10if os.getenv("SIGNAGE_CONFIG") ~= nil then
11 local f = loadfile(os.getenv("SIGNAGE_CONFIG"))
12 if f ~= nil then
13 config = f()
14 else
15 error("SIGNAGE_CONFIG given but could not be loaded")
16 end
17else
18 config = require('config')
19end
20
21local push = require('vendor.push')
22
23local lurker = require('vendor.lurker')
24lurker.quiet = true
25lurker.interval = 3
26
27local debugGraph = require('vendor.debugGraph')
28local fpsGraph = debugGraph:new('fps', 0, 0)
29local memGraph = debugGraph:new('mem', 0, 30)
30
31local gameWidth, gameHeight = config.renderWidth, config.renderHeight
32local windowWidth, windowHeight = love.window.getDesktopDimensions()
33windowWidth, windowHeight = windowWidth*.5, windowHeight*.5 --make the window a bit smaller than the screen itself
34
35if config.environment == 'dev' then
36 push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, {fullscreen = false, resizable = true})
37else
38 push:setupScreen(gameWidth, gameHeight, gameWidth, gameHeight, {fullscreen = true})
39end
40
41function love.resize(w, h)
42 push:resize(w, h)
43 manager:resize(w, h)
44end
45
46function love.load()
47 manager = NodeManager(config)
48 manager:load()
49 manager:resize(push:getWidth(), push:getHeight())
50
51 love.mouse.setVisible( false )
52end
53
54function getw() return push:getWidth() end
55function geth() return push:getHeight() end
56
57function love.draw()
58 push:start()
59
60 -- Patch love.graphics.getWidth/Height to account for push
61 oldw, oldh = love.graphics.getWidth, love.graphics.getHeight
62 love.graphics.getWidth, love.graphics.getHeight = getw, geth
63
64 manager:render()
65
66 -- Draw graphs
67 love.graphics.setColor(1.0, 1.0, 1.0, 0.5)
68
69 -- love.graphics.setNewFont(10)
70 -- love.graphics.print(inspect(state), 0, 60, 0)
71
72 fpsGraph:draw()
73 memGraph:draw()
74
75 love.graphics.getWidth, love.graphics.getHeight = oldw, oldh
76 push:finish()
77end
78
79function love.keypressed( key, scancode, isrepeat )
80 if key == "right" then
81 -- Cycle to next state
82 manager.stateTime = 2137
83 end
84end
85
86function love.update(dt)
87 manager:update(dt)
88
89 -- Update the graphs
90 fpsGraph:update(dt)
91 memGraph:update(dt)
92 lurker.update()
93end
94
95function lurker.preswap(f)
96 if f == 'config.lua' then
97 print('config reloaded, notifying nodemanager')
98 package.loaded['config'] = nil
99 manager.config = require('config');
100 manager:configChanged();
101 elseif f:match('_thread.lua') then
102 return false
103 end
104end