This repository has been archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
141 lines (109 loc) · 3.18 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
132
133
134
135
136
137
138
139
140
141
require "constants"
require "globals"
require "includes"
function love.load()
love.resize(lg.getDimensions())
profi:setGetTimeMethod(lt.getTime)
humpstate.registerEvents()
stache.load()
receiver.init()
input.init()
world.init()
humpstate.switch(playState)
end
function love.run()
local dt = 0
local accu = 0
if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
if lt then
stopwatch.begin()
dt = lt.step() end
return function()
if love.event then
le.pump()
for name, a,b,c,d,e,f in le.poll() do
if name == "quit" then
profi:writeReport()
if not love.quit or not love.quit() then
return a or 0
end
end
love.handlers[name](a,b,c,d,e,f)
end
end
if humpstate.current() == playState and DEBUG_ROLLBACK then
world.rollback() end
while humpstate.current() == playState and world.roll > 0 do
world.update(stopwatch.ticklength * stopwatch.timescale)
world.step()
end
if lt then
dt = lt.step()
stopwatch.update(dt)
accu = accu + dt
end
while accu >= stopwatch.ticklength do -- TODO: MAKE THIS >= ZERO ONCE WE ADD STATE BLENDING?
--profi:start("once")
--stopwatch.profile(75)
input.translate(stopwatch.ticklength)
if humpstate.current() == playState then
world.update(stopwatch.ticklength * stopwatch.timescale) end
love.update(stopwatch.ticklength * stopwatch.timescale)
if humpstate.current() == playState then
world.step() end
accu = accu - stopwatch.ticklength
if humpstate.current() == playState then
stopwatch.tick() end
--profi:stop()
--stopwatch.lap()
end
if lg and lg.isActive() then
lg.clear()
lg.origin()
if love.draw then
--profi:start("once")
love.draw(accu / dt)
--profi:stop()
utils.draw()
end
lg.present()
end
if lt then
stopwatch.sleep() end
end
end
function love.update(tl)
flux.update(tl)
end
function love.keypressed(key)
if key == "m" and humpstate.current() ~= introState then
if not lw.getFullscreen() then lw.updateMode(0, 0, { fullscreen = true })
else lw.updateMode(WINDOW_DEF_WIDTH, WINDOW_DEF_HEIGHT, { fullscreen = false }) end
love.resize(lg.getDimensions()) -- Force the resize callback
elseif key == "kp0" and stopwatch.ticks > NET_ROLLBACK_FRAMES then
DEBUG_ROLLBACK = not DEBUG_ROLLBACK
elseif key == "kpenter" then
LUMINANCE = not LUMINANCE
elseif key == "kp*" then
stopwatch.timescale = stopwatch.timescale * 2
elseif key == "kp/" then
stopwatch.timescale = stopwatch.timescale / 2
end
end
function love.resize(w, h)
UI_SCALE = w <= h and w / WINDOW_MIN_WIDTH or h / WINDOW_MIN_HEIGHT
UI_SCALE_FLOORED = math.floor(UI_SCALE)
WINDOW_DIMS_VEC2 = vec2(w, h)
WINDOW_CENTER_VEC2 = vec2(w / 2, h / 2)
SDF_STENCIL = lg.newCanvas(w, h, { format = "stencil8" })
SDF_DECALS = lg.newCanvas(w, h, { format = "normal" })
SDF_LIGHT = lg.newCanvas(w, h, { format = "normal" })
SDF_FRONT = lg.newCanvas(w, h, { format = "normal" })
SDF_BACK = lg.newCanvas(w, h, { format = "normal" })
Background.overdraw = math.sqrt((w / h) ^ 2 + 1)
Background.canvas = lg.newCanvas()
if not lw.getFullscreen() then
local dw, dh = lw.getDesktopDimensions()
lw.setPosition(dw - w - 40, 40)
end
end