-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
73 lines (62 loc) · 1.86 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
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by yangfan
--- DateTime: 2021/11/15 20:05
---程序主入口,以及love2d相关的生命周期回调
require('app/approot')
---@type AppRoot
local AppRoot = classLib.AppRoot.new()
local loveGraphics = love.graphics
local loveTimer = love.timer
local renderingTimeTips = {'Rendering Time: ',0}
local triangleCountTips = {'Triangles : ',0}
local pixelCountTips = {'Pixels : ',0}
local resolutionTips = table.concat({'渲染分辨率: ',PIXEL_WIDTH,' x ',PIXEL_HEIGHT},'')
local doRendering = true
local function start()
love.window.setTitle("使用Lua基于Love2D引擎实现3D图形渲染 "..resolutionTips)
love.window.setMode(SCREEN_WIDTH, SCREEN_HEIGHT, {resizable=false, vsync=false})
love.filesystem.setSymlinksEnabled(true)
AppRoot:Init()
end
function love.load()
AppRoot:OnLoad()
end
function love.keyreleased(key)
if key == "escape" then
love.event.quit()
elseif key == 'space' then
doRendering = true
end
end
function love.update(dt)
AppRoot:OnUpdate(dt)
end
function love.draw()
--
if doRendering then
local statTime = loveTimer.getTime()
--
AppRoot:RenderOneFrame()
--
renderingTimeTips[2] = loveTimer.getTime() - statTime
--
doRendering = false
--
triangleCountTips[2] = AppRoot.renderer.drawnTriangleCnt
pixelCountTips[2] = AppRoot.renderer.drawnPixelCnt
end
--
AppRoot:OuputFrame()
--
loveGraphics.setColor(1,0,0,1)
local concat = table.concat
loveGraphics.print(concat(renderingTimeTips,''),10,0)
loveGraphics.print(concat(triangleCountTips,''),10,20)
loveGraphics.print(concat(pixelCountTips,''),10,40)
loveGraphics.print('Click \'Space\' to render next frame !',10,60)
end
function love.quit()
AppRoot:Quit()
end
do start() end