Adding optimizations done by other developers

This commit is contained in:
Tim Anema 2021-11-05 12:29:33 -04:00
parent adcc2ecf22
commit 55f537a9b3
No known key found for this signature in database
GPG Key ID: 222D82A25F3857A4
2 changed files with 80 additions and 71 deletions

View File

@ -40,6 +40,8 @@ local function new(options)
local obj = {}
obj.lights = {}
obj.bodies = {}
obj.visibleLights = {}
obj.visibleBodies = {}
obj.post_shader = PostShader()
obj.l, obj.t, obj.s = 0, 0, 1
@ -83,14 +85,22 @@ function light_world:refreshScreenSize(w, h)
end
function light_world:update(dt)
self.visibleBodies = {}
self.visibleLights = {}
for i = 1, #self.bodies do
self.bodies[i].is_on_screen = self.bodies[i]:inRange(-self.l,-self.t,self.w,self.h,self.s)
if self.bodies[i]:isVisible() then
self.bodies[i]:update(dt)
local body = self.bodies[i]
body.is_on_screen = body:inRange(-self.l,-self.t,self.w,self.h,self.s)
if body:isVisible() then
body:update(dt)
table.insert(self.visibleBodies, body)
end
end
for i = 1, #self.lights do
self.lights[i].is_on_screen = self.lights[i]:inRange(self.l,self.t,self.w,self.h,self.s)
local light = self.lights[i]
light.is_on_screen = light:inRange(self.l,self.t,self.w,self.h,self.s)
if light.is_on_screen then
table.insert(self.visibleLights, light)
end
end
end
@ -112,10 +122,8 @@ function light_world:drawShadows(l,t,w,h,s)
love.graphics.clear()
love.graphics.setCanvas()
util.drawto(self.normalMap, l, t, s, false, function()
for i = 1, #self.bodies do
if self.bodies[i]:isVisible() then
self.bodies[i]:drawNormal()
end
for i = 1, #self.visibleBodies do
self.visibleBodies[i]:drawNormal()
end
end)
@ -125,9 +133,8 @@ function light_world:drawShadows(l,t,w,h,s)
love.graphics.setCanvas( self.shadow_buffer )
love.graphics.clear()
love.graphics.setCanvas()
for i = 1, #self.lights do
local light = self.lights[i]
if light:isVisible() then
for i = 1, #self.visibleLights do
local light = self.visibleLights[i]
-- create shadow map for this light
love.graphics.setCanvas( self.shadowMap )
love.graphics.clear()
@ -174,7 +181,6 @@ function light_world:drawShadows(l,t,w,h,s)
end
})
end
end
-- add in ambient color
util.drawto(self.shadow_buffer, l, t, s, false, function()

View File

@ -1,11 +1,14 @@
local util = {}
local tempCanvas
--TODO: the whole stencil/canvas system should be reviewed since it has been changed in a naive way
function util.process(canvas, options)
--TODO: now you cannot draw a canvas to itself
temp = love.graphics.newCanvas()
util.drawCanvasToCanvas(canvas, temp, options)
util.drawCanvasToCanvas(temp, canvas, options)
if not tempCanvas then
tempCanvas = love.graphics.newCanvas()
end
util.drawCanvasToCanvas(canvas, tempCanvas, options)
util.drawCanvasToCanvas(tempCanvas, canvas, options)
end
function util.drawCanvasToCanvas(canvas, other_canvas, options)