-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.lua
131 lines (103 loc) · 2.73 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
love.run = function()
if love.math then
love.math.setRandomSeed(os.time())
end
if love.load then love.load(arg) end
-- We don't want the first frame's dt to include time taken by love.load.
if love.timer then love.timer.step() end
local dt = 0.0 -- delta time
local tr = 1/60 -- tick rate
local fr = 1/60 -- frame rate
local da = 0.0 -- draw accumulator
local ua = 0.0 -- update accumulator
-- Main loop time.
while true do
-- Process events.
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
if name == "quit" then
if not love.quit or not love.quit() then
return a
end
end
love.handlers[name](a,b,c,d,e,f)
end
end
-- Update dt, as we'll be passing it to update
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
da = da + dt
ua = ua + dt
end
-- Call atomic
if love.atomic then love.atomic(dt) end
-- Call update
if ua > tr then
if love.update then
love.update(tr) -- will pass 0 if love.timer is disabled
end
ua = ua % tr
end
-- Call draw
if da > fr then
if love.graphics and love.graphics.isActive() then
love.graphics.clear(love.graphics.getBackgroundColor())
love.graphics.origin()
if love.draw then love.draw() end -- no interpolation
love.graphics.present()
end
da = da % fr
end
-- Optimal sleep time, anything higher does not go below 0.40 % cpu
-- utilization; 0.001 results in 0.72 %, so this is an improvement.
if love.timer then love.timer.sleep(0.002) end
end
end
local log = function(str,...) print(string.format(str,...)) end
-------------------------------------------------------------------------------
local loader = require "loader"
local module
local routine
function love.filedropped(file)
-- Stop playback; Unload previous data.
if routine and routine.playing then
love.audio.stop()
routine = nil
end
if module then
module = nil
end
-- Use the loader to detect and load in the module file.
module = loader(file)
-- Init playroutine with one fitting the module.
if module then
routine = love.filesystem.load("play_" .. module.fileType .. ".lua")
-- Compile the playroutine.
if routine then routine = routine() end
-- Play the module.
if routine then routine.load(module) end
end
end
-------------------------------------------------------------------------------
love.load = function(args)
love.graphics.setFont(love.graphics.newFont('FSEX300.ttf', 16))
end
love.atomic = function(dt)
if routine then
routine.update(dt)
end
end
love.update = function(dt)
end
love.draw = function()
if routine then
routine.draw()
end
end
love.keypressed = function(...)
if routine then
routine.keypressed(...)
end
end