Skip to content
Snippets Groups Projects
Commit 36857c6f authored by Alex Ksandra's avatar Alex Ksandra
Browse files

Show the only_one particle if any part of the map effect is visible.

parent 9f80e574
No related branches found
No related tags found
1 merge request!170Framebuffer fix
......@@ -619,6 +619,7 @@ end
--- Called by the engine map draw code for each z-layer
function _M:zDisplay(z, nb_keyframe, prevfbo)
self:calcEffectVisibility(z)
self:displayParticles(z, nb_keyframe)
self:displayEffects(z, prevfbo, nb_keyframe)
end
......@@ -1090,12 +1091,14 @@ function _M:addEffect(src, x, y, duration, damtype, dam, radius, dir, angle, ove
e.particles = e.particles or {}
if overlay_particle.only_one then
e.particles[#e.particles+1] = self:particleEmitter(x, y, 1, overlay_particle.type, overlay_particle.args, nil, overlay_particle.zdepth)
e.particles[#e.particles].__map_effect = e
e.particles_only_one = true
else
e.fake_overlay = overlay_particle
for lx, ys in pairs(grids) do
for ly, _ in pairs(ys) do
e.particles[#e.particles+1] = self:particleEmitter(lx, ly, 1, overlay_particle.type, overlay_particle.args, nil, overlay_particle.zdepth)
e.particles[#e.particles].__map_effect = e
end
end
end
......@@ -1111,22 +1114,37 @@ function _M:addEffect(src, x, y, duration, damtype, dam, radius, dir, angle, ove
return e
end
-- ElectronicRU: I have no idea why rendering an empty FBO when map seens is empty causes so much distress to CPU. But for now let's maybe just no do it.
-- This serves two important purposes, the first is to show particles that are only_one, the second is to fix the pesky bug described above.
function _M:calcEffectVisibility(z)
for e, _ in pairs(self.z_effects[z]) do
local seen_grids = {}
for lx, ys in pairs(e.grids) do
seen_grids[lx] = {}
for ly, _ in pairs(ys) do
seen_grids[lx][ly] = self.seens(lx, ly)
end
if not next(seen_grids[lx]) then seen_grids[lx] = nil end
end
e.seen_grids = seen_grids
e.seen = next(seen_grids) and true or false
end
end
--- Display the overlay effects, called by self:display()
function _M:displayEffects(z, prevfbo, nb_keyframes)
local sx, sy = self._map:getScroll()
for e, _ in pairs(self.z_effects[z]) do
-- Dont bother with obviously out of screen stuff or invisible stuff
if e.overlay and e.overlay.zdepth == z and e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
if e.seen and e.overlay and e.overlay.zdepth == z and e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
local s = self.tilesEffects:get(e.overlay.display, e.overlay.color_r, e.overlay.color_g, e.overlay.color_b, e.overlay.color_br, e.overlay.color_bg, e.overlay.color_bb, e.overlay.image, e.overlay.alpha)
-- If we dont have a special fbo/shader or no shader image to use, just display with simple quads
if not self.fbo or not e.overlay.effect_shader then
-- Now display each grids
for lx, ys in pairs(e.grids) do
for lx, ys in pairs(e.seen_grids) do
for ly, _ in pairs(ys) do
if self.seens(lx, ly) then
s:toScreen(self.display_x + sx + (lx - self.mx) * self.tile_w * self.zoom, self.display_y + sy + (ly - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
end
s:toScreen(self.display_x + sx + (lx - self.mx) * self.tile_w * self.zoom, self.display_y + sy + (ly - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
end
end
-- We have a fbo/shader pair, so we display everything inside it and apply the shader to get nice borders and such
......@@ -1148,25 +1166,20 @@ function _M:displayEffects(z, prevfbo, nb_keyframes)
end
end
-- ElectronicRU: I have no idea why rendering an empty FBO when map seens is empty causes so much distress to CPU. But for now let's maybe just no do it.
local drawn = false
self.fbo:use(true, 0, 0, 0, 0)
-- Now display each grids
for lx, ys in pairs(e.grids) do
for lx, ys in pairs(e.seen_grids) do
for ly, _ in pairs(ys) do
if self.seens(lx, ly) then
s:toScreen((lx - self.mx) * self.tile_w * self.zoom, (ly - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
drawn = true
end
s:toScreen((lx - self.mx) * self.tile_w * self.zoom, (ly - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
end
end
self.fbo:use(false, prevfbo)
if drawn then
e.overlay.effect_shader_tex[e.overlay.effect_shader_tex.cur]:bind(1, false)
self.fbo_shader.shad:uniTileSize(self.tile_w, self.tile_h)
self.fbo_shader.shad:uniScrollOffset(0, 0)
self.fbo:toScreen(self.display_x + sx, self.display_y + sy, self.viewport.width, self.viewport.height, self.fbo_shader.shad, 1, 1, 1, 1, true)
end
e.overlay.effect_shader_tex[e.overlay.effect_shader_tex.cur]:bind(1, false)
self.fbo_shader.shad:use(true)
self.fbo_shader.shad:uniTileSize(self.tile_w, self.tile_h)
self.fbo_shader.shad:uniScrollOffset(0, 0)
self.fbo:toScreen(self.display_x + sx, self.display_y + sy, self.viewport.width, self.viewport.height, self.fbo_shader.shad, 1, 1, 1, 1, true)
self.fbo_shader.shad:use(false)
e.overlay.effect_shader_tex.cnt = e.overlay.effect_shader_tex.cnt + nb_keyframes
if e.overlay.effect_shader_tex.cnt >= e.overlay.effect_shader_tex.max then
......@@ -1220,6 +1233,7 @@ function _M:processEffects(update_shape_only)
for lx, ys in pairs(e.grids) do
for ly, _ in pairs(ys) do
e.particles[#e.particles+1] = self:particleEmitter(lx, ly, 1, e.fake_overlay.type, e.fake_overlay.args, nil, e.zdepth)
e.particles[#e.particles].__map_effect = e
end
end
end
......@@ -1305,7 +1319,7 @@ end
--- Adds an existing particle emitter to the map
function _M:addParticleEmitter(e, x, y)
if self.particles[e] then return false end
for _, ea in ipairs(self.particles) do if ea==e then return false end end
if x and y then e.x, e.y = x, y end
self.particles[#self.particles+1] = e
if not e.zdepth then e.zdepth = self.zdepth - 1 end
......@@ -1362,17 +1376,25 @@ function _M:displayParticles(z, nb_keyframes)
end
end
local show_particle = (self.seens(e.x, e.y) or e.always_visible)
if e.__map_effect then
local me = e.__map_effect
if me.particles_only_one and me.seen then
show_particle = true
end
end
if nb_keyframes == 0 and e.x and e.y then
-- Just display it, not updating, no emitting
if e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
e.ps:toScreen(dx + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, dy + (ady + e.y - self.my + 0.5 + util.hexOffset(e.x)) * self.tile_h * self.zoom, self.seens(e.x, e.y) or e.always_seen, e.zoom * self.zoom)
e.ps:toScreen(dx + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, dy + (ady + e.y - self.my + 0.5 + util.hexOffset(e.x)) * self.tile_h * self.zoom, show_particle, e.zoom * self.zoom)
end
elseif e.x and e.y then
alive = e.ps:isAlive()
-- Update more, if needed
if alive and e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
e.ps:toScreen(dx + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, dy + (ady + e.y - self.my + 0.5 + util.hexOffset(e.x)) * self.tile_h * self.zoom, self.seens(e.x, e.y) or e.always_seen)
e.ps:toScreen(dx + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, dy + (ady + e.y - self.my + 0.5 + util.hexOffset(e.x)) * self.tile_h * self.zoom, show_particle)
end
if not alive then
......
......@@ -132,7 +132,7 @@ void main(void)
resultColor.a = borderColor.a;
}else
{
borderColor *= borderColor.a
borderColor *= borderColor.a;
resultColor += borderColor;
}
......
......@@ -246,7 +246,7 @@ newTalent{
if n < 1 then return bt, "(error 2)" end
local e_string = ""
if n == 1 then
e_string = DamageType.dam_def[bt[1]].name
e_string = DamageType.dam_def[next(bt)].name
else
local list = table.keys(bt)
for i = 1, #list do if DamageType.dam_def[list[i]] then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment