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
@ -137,9 +152,12 @@ function light_world:update()
for i = 1, #self.lights do
self.lights[i]:drawShine()
end
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")
@ -171,9 +189,12 @@ function light_world:update()
love.graphics.setColor({self.ambient[1], self.ambient[2], self.ambient[3]})
love.graphics.rectangle("fill", self.translate_x, self.translate_y, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.setBlendMode("alpha")
end
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)
@ -193,9 +214,12 @@ function light_world:update()
for i = 1, #self.body do
self.body[i]:drawGlow()
end
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()
@ -203,9 +227,12 @@ function light_world:update()
for i = 1, #self.body do
self.body[i]:drawRefraction()
end
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)
@ -214,14 +241,6 @@ function light_world:update()
self.body[i]:drawReflection()
end
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()
@ -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