Serge Bazanski | 18c1a26 | 2022-07-07 14:24:53 +0200 | [diff] [blame] | 1 | class = require('vendor.30log') |
| 2 | inspect = require('vendor.inspect') |
| 3 | lume = require('vendor.lume') |
| 4 | |
| 5 | Node = require('core.node') |
| 6 | ThreadNode = require('core.thread-node') |
| 7 | NodeManager = require('core.node-manager') |
| 8 | |
| 9 | local config = nil |
| 10 | if 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 |
| 17 | else |
| 18 | config = require('config') |
| 19 | end |
| 20 | |
| 21 | local push = require('vendor.push') |
| 22 | |
| 23 | local lurker = require('vendor.lurker') |
| 24 | lurker.quiet = true |
| 25 | lurker.interval = 3 |
| 26 | |
| 27 | local debugGraph = require('vendor.debugGraph') |
| 28 | local fpsGraph = debugGraph:new('fps', 0, 0) |
| 29 | local memGraph = debugGraph:new('mem', 0, 30) |
| 30 | |
| 31 | local gameWidth, gameHeight = config.renderWidth, config.renderHeight |
| 32 | local windowWidth, windowHeight = love.window.getDesktopDimensions() |
| 33 | windowWidth, windowHeight = windowWidth*.5, windowHeight*.5 --make the window a bit smaller than the screen itself |
| 34 | |
| 35 | if config.environment == 'dev' then |
| 36 | push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, {fullscreen = false, resizable = true}) |
| 37 | else |
| 38 | push:setupScreen(gameWidth, gameHeight, gameWidth, gameHeight, {fullscreen = true}) |
| 39 | end |
| 40 | |
| 41 | function love.resize(w, h) |
| 42 | push:resize(w, h) |
| 43 | manager:resize(w, h) |
| 44 | end |
| 45 | |
| 46 | function love.load() |
| 47 | manager = NodeManager(config) |
| 48 | manager:load() |
| 49 | manager:resize(push:getWidth(), push:getHeight()) |
| 50 | |
| 51 | love.mouse.setVisible( false ) |
| 52 | end |
| 53 | |
| 54 | function getw() return push:getWidth() end |
| 55 | function geth() return push:getHeight() end |
| 56 | |
| 57 | function 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() |
| 77 | end |
| 78 | |
| 79 | function love.keypressed( key, scancode, isrepeat ) |
| 80 | if key == "right" then |
| 81 | -- Cycle to next state |
| 82 | manager.stateTime = 2137 |
| 83 | end |
| 84 | end |
| 85 | |
| 86 | function love.update(dt) |
| 87 | manager:update(dt) |
| 88 | |
| 89 | -- Update the graphs |
| 90 | fpsGraph:update(dt) |
| 91 | memGraph:update(dt) |
| 92 | lurker.update() |
| 93 | end |
| 94 | |
| 95 | function 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 |
| 104 | end |