I need SPEED!!! (source files included)

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
skar
Posts: 6
Joined: Tue Sep 20, 2005 9:48 am

I need SPEED!!! (source files included)

Post by skar »

Hello guys,

First of all thank you for Lua and this great forum, we learn a lot and Lua is very easy to use...

BUT I have got a problem:SPEED.

I start to develop a ARMOR ALLEY clone on PSP with Lua.

First Screenshot (start development phase)
Image


Everything go easy but now as I load more than 30 images and I use this kind of for:

for i = 1,mtf do
for j=1,etf do
if (et[j]-mt)<5 and (et[j]-mt)>0 then
if math.random(2)==2 then
table.insert(dmt,i)
else
table.insert(det,j)
end
end
end
for j=1,eff do
if (ef[j]-mt)<5 and (ef[j]-mt)>0 then
if math.random(5)==5 then
table.insert(dmt,i)
else
table.insert(def,j)
end
end
end
end


(sorry for the code) my pSP with Lua is too slow and so the game is not playable...

Do you think the slow speed is caused by the images loaded, the "fors" instructions or my bullshit code?
If someone has find a solution to accelerate Lua language or Lua player please help me...

(If you want I can give you the code of my ARMOR ALLEY clone)

Thank you and god save PS2DEV!Image
Last edited by skar on Tue Sep 20, 2005 7:25 pm, edited 2 times in total.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

well you should only load your images at the start of your game.. you could make a loading screen for that.. if the game is being slow during game play then it's the way you draw or process your data..

I don't know if your game uses tiles or not but if it does.. read my I/O File handling thread .. it got a bit off topic and discussed that..
skar
Posts: 6
Joined: Tue Sep 20, 2005 9:48 am

Post by skar »

Thanx Giuliano but I don't use tiles or I/O instructions.
I know that loading images is in the START of the game and not after I was saying that I have more than 30 or 40 blits each flip because all the vehicles of the game are IMAGES blits moving on a slide background of 960 pixels long (2 backgrounds images)...

I don't know if the way I code the game is wrong (I don't have a past experience in game development) but I would like to know if too much blits slow down the game or too much "for" or intertwined instructions (probably badly coded) slow down the game?
Maybe it is better to draw a line or a pack of pixel than to use a blit? I don't know.
Perhaps it is better not to use math.random() or for instructions intertwined?


But thank you for your response I will read your thread on I/O file handling.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Yes, blit is slow and blitting too much will slow down the game. The thing about Blit (as seen in the other thread) is that what makes it slower is calling it many times, not the size of the image.

If you post some code we can see if it's the code or the blit that is being slow.
skar
Posts: 6
Joined: Tue Sep 20, 2005 9:48 am

Post by skar »

OK I understand I will try to use one image and a specified blit on this image that will surely speed up my code...

Thank you Arwin and Giuliani for your support...
Here is a zip with my source files:
http://www.savefile.com/files3.php?fid=8846088

Perhaps I my problem is this: as the goal of this game is to scroll a landscape of 960 pixels long I didn't load a 960 pixels image because it is impossible with Lua but I used this code:

screen:blit(0, 0, background, xk, 0, 480, 272, false)

As my image is 512 px long with xk increasing when I reach the end of the image a next one appear (in fact the same) without coding anything else. I keep this discovery to scroll along my game without creating a particular scrolling engine as some developers. But I am not sure this is good for speed.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

speedowns:

blitting stuff that is not needed (why blit ~900x272px) when you only see 480 in width of em?!

have a look over your code and see where you can optimize it (for sure you can find something in 90% of your cases)

Code: Select all

for i = 1,mtf do
  for j=1,etf do
    if &#40;et&#91;j&#93;-mt&#91;i&#93;&#41;<5 and &#40;et&#91;j&#93;-mt&#91;i&#93;&#41;>0 then
      if math.random&#40;2&#41;==2 then
        table.insert&#40;dmt,i&#41;
      else
        table.insert&#40;det,j&#41;
      end
    end
  end --end for etf
  for j=1,eff do
    if &#40;ef&#91;j&#93;-mt&#91;i&#93;&#41;<5 and &#40;ef&#91;j&#93;-mt&#91;i&#93;&#41;>0 then
      if math.random&#40;5&#41;==5 then
        table.insert&#40;dmt,i&#41;
      else
        table.insert&#40;def,j&#41;
      end
    end
  end --end for eff
end  --end for mtf
what is this code supposed to do?
(comments and variable names with a meaning would help)


note:
1) optimizing is not always removing lines of code
2) (my bomberman-game uses far mor blits than 40 and works smoothly! (the field alone is 15x29blits!))
3) you may have a look on the sidescrolling-idea-code which uses an image of 1500px (but only blits 480px) [although there is a little bug somewhere in the code]

greets
lumo

willed to help, but get us to a starting point
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
skar
Posts: 6
Joined: Tue Sep 20, 2005 9:48 am

Post by skar »

Thanx you all...for your support, this forum is doing very well.

I will keep improve my code, with less blits and try your good ideas and I will come back later with a better code.


PROBLEM RESOLVED THREAD SCROLLING IDEA...
Post Reply