-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
355 lines (271 loc) · 7.39 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
--require "game.programwalk"
--programwalk.start()
do -- Default
heart = heart or {}
--external libs
require "tool.imagedataffilib"
if heart.init == nil then
_TableDefault = {}
heart.timer = {}
heart.debug = {}
heart.hotLoadNameTable = {}
heart.graphics = {}
heart.hotLoadNameTable["main.lua"] = love.filesystem.getLastModified("main.lua")
_TimeStart = love.timer.getTime()
_Time = 0
_TimeF = 0
_RealDir = love.filesystem.getRealDirectory("main.lua").."/"
_toSleep = false
love.filesystem.load("framework/debug.lua") ()
love.filesystem.load("shader/shader.lua") ()
-- Above and debug.lua is considered Default _G value.
-- Move "love.filesystem.load("debug.lua") ()" below to consider debug.lua nondefault.
for k , v in pairs(_G) do
_TableDefault[k] = true
end
love.filesystem.load("framework/window.lua") ()
window.start()
heart.init = true
end
local _TableApproved =
{
--Evine approved
"_Loaded",
"_ERRMSG",
"ui",
"tile",
"entity",
"dt",
"viewport",
"memcheck",
"keyboard",
"asset",
"translateToScreen",
"translateToIso",
"grid",
"window",
"filter",
"mouse",
"blendMode",
"PSDprintdrawTEST",
"blendModeDrawingsTEST",
"v",
"PriorityQueue",
--Temporary
"path",
"drawTileWraped",
"drawWallWraped",
"drawTileDirect",
"drawWallDirect",
"drawFlatTile",
"drawFlatWall",
"drawPolygonTile",
"renderTranslateToScreen",
"drawAndInk",
"removeIndexes",
"isocircleRender",
"isocircle",
"insert2d",
}
for i = 1, #_TableApproved do
_TableDefault[_TableApproved[i]] = true
end
function heart.renderInfo()
local stats = love.graphics.getStats( )
--printv("Texturememory MB",math.floor(stats.texturememory/1024/1024))
printv("Canvas Swaps",stats.canvasswitches)
printv("Images Loaded", stats.images)
printv("Draw Calls",stats.drawcalls-heart.debug.drawCalls)
--printv("Debug Draw Calls",heart.debug.drawCalls)
--printv("PrintOutput" , #heart.debug.printOutput)
printv("Time",_TimeF)
printv("Lua memory MB",math.floor(collectgarbage("count")/1024*1000)/1000)
end
end
-- Requireing a new file causes loads a frame late. Thus unessasery error on load
function heart.require()
shader.hotLoad()
_Loaded = false
-- Should assert on nonexist file???
heart.hotLoad("framework/debug.lua")
-- Require files
heart.hotLoad("main.lua")
heart.hotLoad("tool/memcheck.lua")
heart.hotLoad("shader/shader.lua")
heart.hotLoad("tool/v.lua")
heart.hotLoad("tool/utility.lua")
heart.hotLoad("framework/window.lua")
heart.hotLoad("framework/viewport.lua")
heart.hotLoad("framework/keyboard.lua")
heart.hotLoad("framework/ui.lua")
heart.hotLoad("framework/mouse.lua")
heart.hotLoad("shader/blendmodes.lua")
heart.hotLoad("shader/filter.lua")
heart.hotLoad("game/tile.lua")
heart.hotLoad("game/entity.lua")
heart.hotLoad("game/grid.lua")
heart.hotLoad("game/asset.lua")
heart.hotLoad("game/path.lua")
end
function heart.load(argument)
--love.mouse.setVisible(false)
love.graphics.setBackgroundColor(22,17,15)
love.keyboard.setKeyRepeat(true)
heart.font = love.graphics.setNewFont("font/nyala.ttf",72)
heart.fontSmall = love.graphics.setNewFont("font/nyala.ttf",24)
heart.fontMedium = love.graphics.setNewFont("font/nyala.ttf",40)
heart.debug.load()
viewport.load()
end
function love.quit()
asset.quit()
end
function love.keypressed(key,isRepeat)
if isRepeat == false then
heart.debug.keypressed(key)
window.keypressed(key)
end
end
function love.keyreleased(key)
heart.debug.keyreleased(key)
window.keyreleased(key)
end
function love.mousepressed(x , y , button)
heart.debug.mousepressed(x , y , button)
mouse.pressed(button)
grid.mousepressed(button)
end
function love.mousereleased(x,y,button)
mouse.released(button)
--asset.mousereleased(button)
end
function heart.update()
keyboard.update()
mouse.update()
grid.mouseupdate()
viewport.push()
--Background Color
love.graphics.setColor(230,230,215)
love.graphics.rectangle("fill",0,0,1920,1080)
love.graphics.setColor(255,255,255)
--PSDprintdrawTEST()
--mouse.draw()
grid.update()
--asset.draw()
--filter.draw()
--blendModeDrawingsTEST()
viewport.screenshot()
viewport.pop()
end
do --Default
function heart.runningTimer()
_Time = love.timer.getTime() - _TimeStart
_TimeF = math.floor(_Time)
end
function heart.hotLoad(fileName, force)
assert(love.filesystem.exists(fileName),"File does not exists")
local ok , hotData , err
if heart.hotLoadNameTable[fileName] ~= love.filesystem.getLastModified(fileName) or force then
heart.hotLoadNameTable[fileName] = love.filesystem.getLastModified(fileName)
if _Debug then
ok , hotData = pcall(love.filesystem.load ,fileName) -- Load program
if ok then
_Loaded = true -- I want to set this true before loading the program, but I need to prevent it from being set to true forever.
ok,err = xpcall(love.filesystem.load(fileName),heart.hotLoadHandler) -- Execute program
if ok then
print("Time: ".._TimeF..", Loaded: "..fileName)
_ERRMSG = nil
heart.debug.loadError = ""
else
heart.debug.loadError = "Execute error"
end
else
print("\nTime: ".._TimeF..", Syntax Error: \n"..fileName.." "..hotData.."\n"..debug.traceback())
heart.debug.loadError = "Syntax error"
end
else
love.filesystem.load(fileName) ( )
end
end
end
function heart.hotLoadHandler(msg)
print("\nTime: ".._TimeF..", Execute Load Error: \n"..msg.."\n"..debug.traceback().."\n\n".."Unresolved Push Error: "..heart.pushSAFETY.."\n")
while heart.pushSAFETY > 0 do
heart.pop()
end
end
function heart.updateHandler(msg)
if _ERRMSG ~= msg then
print("\nTime: ".._TimeF..", Run Error: \n"..msg.."\n"..debug.traceback().."\n\n".."Unresolved Push Error: "..heart.pushSAFETY.."\n")
_ERRMSG = msg
end
while heart.pushSAFETY > 0 do
heart.pop()
end
if viewport.pushed > 0 then
viewport.pop()
end
end
-- Can't be updated during runtime
function love.run()
love.math.setRandomSeed(os.time())
for i=1,3 do love.math.random() end
love.event.pump()
if heart.require then heart.require() print("All files loaded") end
if heart.load then heart.load(arg) end
-- We don't want the first frame's dt to include time taken by love.load.
love.timer.step()
dt = 0.016
print("Load Time:",math.floor((love.timer.getTime() - _TimeStart)*1000)/1000)
-- Main loop time.
while true do
-- Process events.
mouse.reset()
for e,a,b,c,d in love.event.poll() do
if e == "quit" then
if not love.quit or not love.quit() then
if love.audio then
love.audio.stop()
end
return
end
end
love.handlers[e](a,b,c,d)
end
heart.run()
end
end
function heart.run()
if _toSleep then
love.timer.sleep(1)
end
do
love.timer.step()
dt = love.timer.getDelta()
if dt > 0.04 then
dt = 0.04 -- Clamp dt
end
end
-- Require files
if heart.require then heart.require() end
love.graphics.clear()
love.graphics.origin()
heart.runningTimer()
if _Debug then
xpcall(heart.update,heart.updateHandler)
else
heart.update()
end
love.graphics.origin()
heart.pushUpdate()
heart.debug.update()
if not _Debug then
love.timer.sleep(0.001)
end
heart.renderInfo() -- Do NOT draw anything between this and love.graphics.present.
love.graphics.present()
--programwalk.stop()
love.event.pump()
debug.sethook()
end
end