From cd3d19443e80ed1d328dd0cb466906bb90e3baae Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sun, 5 Mar 2023 21:34:49 +0000 Subject: perf: do not draw entites off the screen --- raccoon.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/raccoon.lua b/raccoon.lua index 18939a1..fac2f03 100644 --- a/raccoon.lua +++ b/raccoon.lua @@ -614,23 +614,23 @@ end local DrawingSystem = System(Pos) function DrawingSystem:exec(entity,level) - local x, y = entity.get_component[Pos]:to_screen(level) - if entity.has_component[Pixel] then - local c = entity.get_component[Pixel].color - pix(x, y, c) - elseif entity.has_component[Sprite] then - local sprite = entity.get_component[Sprite] - spr(sprite.i, x, y, 0) - end - -- Effects - local effects = { CircleEffect } - for _,e in ipairs(effects) do - if entity.has_component[e] then - local e = entity.get_component[e] - e:draw(x,y) + local x, y = entity:get_pos():to_screen(level) + if 0 <= x and x <= util.screen.width then + if entity:has_pixel() then + local c = entity:get_pixel().color + pix(x, y, c) + elseif entity:has_sprite() then + local sprite = entity:get_sprite() + spr(sprite.i, x, y, 0) + end + -- Effects + local effects = { "CircleEffect" } + for _,e in ipairs(effects) do + if Entity["has_"..e:lower()](entity) then + Entity["get_"..e:lower()](entity):draw(x,y) + end end end - end function DrawingSystem:draw(game) local level = game.levels[game.level] -- cgit v1.2.3