Following is the little app I've coded for the test. It just load an image then when you press cross sprites are added and when you press circle sprites are removed. In the upper left the FPS and the sprites count are displayed.
Currentlty I could blit 63 sprites 16x16 @ 60 FPS with transparency turned off, and somthing like 47 sprite with transparency turned on.
Is something wrong ??
One thing I've discovered is that Controls.read() eats lots of time. So much that with 2 Controls.read() calls and no sprite displayed FPS started @30 !! Therefore Controls.read() should be called once per app loop and stored for future use in that loop. Maybe some of you already knew it but I didn't....
vh
Code: Select all
-- -----------------------------------------------------------------------
-- CFpsTester
-- -----------------------------------------------------------------------
CFpsTester = {}
CFpsTesterMetaTable = { __index = CFpsTester }
-- -----------------------------------------------------------------------
-- CFpsTester:new
-- -----------------------------------------------------------------------
function CFpsTester:new(ImageName)
local Table =
{
m_Image = Image.load(ImageName),
m_SpriteSize = { m_Width = 16, m_Height = 16 },
m_Sprites = {},
m_Frames = 0,
m_FPS = 0,
m_Timer = -1,
m_CurrentTime = 0,
m_LastFPSTime = 0,
m_InkColor = Color.new(0, 255, 0),
m_BackColor = Color.new(55, 102, 104),
m_Buttons = -1,
}
setmetatable(Table, CFpsTesterMetaTable);
local Now = os.date("*t");
local Seed = Now.hour + Now.min + Now.wday + Now.year + Now.yday + Now.month + Now.sec + Now.day;
math.randomseed(Seed);
Table.m_Timer = Timer.new();
Table.m_Timer:start();
Table.m_Buttons = Controls.read();
return (Table);
end
-- -----------------------------------------------------------------------
-- CFpsTester:update
-- -----------------------------------------------------------------------
function CFpsTester:update()
self.m_Buttons = Controls.read();
self.m_CurrentTime = self.m_Timer:time();
if (1000 <= (self.m_CurrentTime - self.m_LastFPSTime)) then
self.m_LastFPSTime = self.m_CurrentTime;
self.m_FPS = self.m_Frames;
self.m_Frames = 0;
end
self.m_Frames = self.m_Frames + 1;
if (self.m_Buttons:cross()) then
self:privateAddSprite();
end
if (self.m_Buttons:circle()) then
self:privateRemoveSprite();
end
end
-- -----------------------------------------------------------------------
-- CFpsTester:draw
-- -----------------------------------------------------------------------
function CFpsTester:draw(TargetImage)
TargetImage:clear(self.m_BackColor);
for Index, Sprite in self.m_Sprites do
TargetImage:blit(Sprite.m_X, Sprite.m_Y, self.m_Image, Sprite.m_SourceX, Sprite.m_SourceY, self.m_SpriteSize.m_Width, self.m_SpriteSize.m_Height, false);
end
TargetImage:print(5, 5, "FPS " .. tostring(self.m_FPS), self.m_InkColor);
TargetImage:print(5, 15, "Sprites " .. tostring(table.getn(self.m_Sprites)), self.m_InkColor);
end
-- -----------------------------------------------------------------------
-- CFpsTester:checkExistApp
-- -----------------------------------------------------------------------
function CFpsTester:checkExistApp()
return (self.m_Buttons:start());
end
-- -----------------------------------------------------------------------
-- CFpsTester:privateAddSprite
-- -----------------------------------------------------------------------
function CFpsTester:privateAddSprite()
local Sprite =
{
m_X = math.random(screen:width() - self.m_SpriteSize.m_Width),
m_Y = math.random(screen:height() - self.m_SpriteSize.m_Height),
m_SourceX = math.random(self.m_Image:width() - self.m_SpriteSize.m_Width),
m_SourceY = math.random(self.m_Image:height() - self.m_SpriteSize.m_Height),
}
self.m_Sprites[table.getn(self.m_Sprites) + 1] = Sprite;
end
-- -----------------------------------------------------------------------
-- CFpsTester:privateRemoveSprite
-- -----------------------------------------------------------------------
function CFpsTester:privateRemoveSprite()
self.m_Sprites[table.getn(self.m_Sprites)] = nil;
end
g_App = -1;
-- -----------------------------------------------------------------------
-- Update
-- -----------------------------------------------------------------------
function Update()
g_App:update();
end
-- -----------------------------------------------------------------------
-- Draw
-- -----------------------------------------------------------------------
function Draw()
g_App:draw(screen);
screen.waitVblankStart()
screen.flip()
end
-- -----------------------------------------------------------------------
-- main
-- -----------------------------------------------------------------------
function main()
g_App = CFpsTester:new("Image.png"); -- for safety should be at least 64x64
while (false == g_App:checkExistApp()) do
Update();
Draw();
end
end
main();