aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2023-03-05 21:34:49 +0000
committerFederico Igne <git@federicoigne.com>2023-03-05 21:34:49 +0000
commitcd3d19443e80ed1d328dd0cb466906bb90e3baae (patch)
treede7458465a937f8874b1b7bb75b2c65256f2a8d3
parent90d98efdaf7147bf7c704af722c96b95d101b7e8 (diff)
downloadraccoon-cd3d19443e80ed1d328dd0cb466906bb90e3baae.tar.gz
raccoon-cd3d19443e80ed1d328dd0cb466906bb90e3baae.zip
perf: do not draw entites off the screen
-rw-r--r--raccoon.lua30
1 files 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
614 614
615local DrawingSystem = System(Pos) 615local DrawingSystem = System(Pos)
616function DrawingSystem:exec(entity,level) 616function DrawingSystem:exec(entity,level)
617 local x, y = entity.get_component[Pos]:to_screen(level) 617 local x, y = entity:get_pos():to_screen(level)
618 if entity.has_component[Pixel] then 618 if 0 <= x and x <= util.screen.width then
619 local c = entity.get_component[Pixel].color 619 if entity:has_pixel() then
620 pix(x, y, c) 620 local c = entity:get_pixel().color
621 elseif entity.has_component[Sprite] then 621 pix(x, y, c)
622 local sprite = entity.get_component[Sprite] 622 elseif entity:has_sprite() then
623 spr(sprite.i, x, y, 0) 623 local sprite = entity:get_sprite()
624 end 624 spr(sprite.i, x, y, 0)
625 -- Effects 625 end
626 local effects = { CircleEffect } 626 -- Effects
627 for _,e in ipairs(effects) do 627 local effects = { "CircleEffect" }
628 if entity.has_component[e] then 628 for _,e in ipairs(effects) do
629 local e = entity.get_component[e] 629 if Entity["has_"..e:lower()](entity) then
630 e:draw(x,y) 630 Entity["get_"..e:lower()](entity):draw(x,y)
631 end
631 end 632 end
632 end 633 end
633
634end 634end
635function DrawingSystem:draw(game) 635function DrawingSystem:draw(game)
636 local level = game.levels[game.level] 636 local level = game.levels[game.level]