split the update method up into components, easier to understand

This commit is contained in:
Tim Anema 2014-09-27 12:54:48 -04:00
parent 08e50a7b2a
commit 3502fe7d3e

View File

@ -105,8 +105,23 @@ function light_world:update()
love.graphics.setColor(255, 255, 255)
love.graphics.setBlendMode("alpha")
self:updateShadows()
self:updatePixelShadows()
self:updateGlow()
self:updateRefraction()
self:updateRelfection()
love.graphics.setShader()
love.graphics.setBlendMode("alpha")
love.graphics.setStencil()
love.graphics.setCanvas(self.last_buffer)
self.changed = false
end
function light_world:updateShadows()
if not self.optionShadows or not (self.isShadows or self.isLight) then
return
end
if self.optionShadows and (self.isShadows or self.isLight) then
love.graphics.setShader(self.shader)
for i = 1, #self.lights do
@ -139,7 +154,10 @@ function light_world:update()
end
end
if self.optionPixelShadows and self.isPixelShadows then
function light_world:updatePixelShadows()
if not self.optionPixelShadows or not self.isPixelShadows then
return
end
-- update pixel shadow
love.graphics.setBlendMode("alpha")
@ -173,7 +191,10 @@ function light_world:update()
love.graphics.setBlendMode("alpha")
end
if self.optionGlow and self.isGlow then
function light_world:updateGlow()
if not self.optionGlow or not self.isGlow then
return
end
-- create glow map
self.glowMap:clear(0, 0, 0)
love.graphics.setCanvas(self.glowMap)
@ -195,7 +216,10 @@ function light_world:update()
end
end
if self.optionRefraction and self.isRefraction then
function light_world:updateRefraction()
if not self.optionRefraction or not self.isRefraction then
return
end
love.graphics.setShader()
-- create refraction map
self.refractionMap:clear()
@ -205,7 +229,10 @@ function light_world:update()
end
end
if self.optionReflection and self.isReflection then
function light_world:updateRelfection()
if not self.optionReflection or not self.isReflection then
return
end
-- create reflection map
if self.changed then
self.reflectionMap:clear(0, 0, 0)
@ -216,14 +243,6 @@ function light_world:update()
end
end
love.graphics.setShader()
love.graphics.setBlendMode("alpha")
love.graphics.setStencil()
love.graphics.setCanvas(self.last_buffer)
self.changed = false
end
function light_world:refreshScreenSize()
self.shadow = love.graphics.newCanvas()
self.shadow2 = love.graphics.newCanvas()
@ -239,6 +258,7 @@ function light_world:refreshScreenSize()
self.pixelShadow = love.graphics.newCanvas()
self.pixelShadow2 = love.graphics.newCanvas()
end
-- draw shadow
function light_world:drawShadow()
if self.optionShadows and (self.isShadows or self.isLight) then