 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Fri Oct 20, 2006 5:11 am Post subject: memory issue |
|
|
I've been working secretly on a 2D scrolling platform game inspired by splinter cell, of wich I will release a testing version soon. This may well be one of the largest luaplayer projects I know of. But, I've got a problem: memory. It runs out. I try to load as much as I can at the program's startup, so that I don't have to reload a lot. This involves loading roughly 60 png's and 3 small wav's. After all this is done, I start my level editor (yes,that's included too(-: ) wich gives me a memory indication: 6 megs. This gradually decreases when loading levels. Luckily, I've managed to let the fileselector load nothing when it's starting, wich would mean I would crash on saving a level in case of low mem.
But is loading everythin at startup the right approach? Or do you have other tips? Please let me know. I'm using 0.16, so it doesn't load modules or stuff like that (wich is good for mem usage) _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Fri Oct 20, 2006 7:45 am Post subject: |
|
|
Try setting variables to nil when your done useing the data.
IE Loading Levels, Sprites, etc.. |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sat Oct 21, 2006 1:59 am Post subject: can't get it done |
|
|
Yes Romero, that's my plan, but I can't get it to work. look at this: | Code: | --some other stuff
elseif item == 3 then
animations={Image.load("./animation/running_right.png"),5,Image.load("./animation/running_left.png"),5,Image.load("./animation/sam_crouchwalk_right.png"),8,Image.load("./animation/sam_crouchwalk_left.png"),8 --1 to 8
,Image.load("./animation/sam_gunreach_right.png"),6,Image.load("./animation/sam_gunreach_left.png"),6,Image.load("./animation/sam_gunwalk_right.png"),8,Image.load("./animation/sam_gunwalk_left.png"),8 -- 9 to 16
,Image.load("./animation/sam_elbow_right.png"),6,Image.load("./animation/sam_elbow_left.png"),6,Image.load("./animation/sam_shoot_right.png"),6,Image.load("./animation/sam_shoot_left.png"),6 -- 17 to 24
,Image.load("./animation/ClimbOnBlock_right.png"),4,Image.load("./animation/ClimbOnBlock_left.png"),4,Image.load("./animation/ClimbOn2Block_right.png"),7,Image.load("./animation/ClimbOn2Block_left.png"),7 --25 to 32
,Image.load("./animation/jump_right.png"),7,Image.load("./animation/jump_right.png"),7,Image.load("./animation/falling_right.png"),3,Image.load("./animation/falling_left.png"),3,Image.load("./animation/Ladder_up.png"),7 --33 to 42
,Image.load("./animation/Jump_up_right.png"),3,Image.load("./animation/Jump_up_left.png"),3,Image.load("./animation/TurnToladder_right.png"),5,Image.load("./animation/TurnToladder_left.png"),5,Image.load("./animation/shimny_right.png"),7,Image.load("./animation/shimny_left.png"),7--43-54
,Image.load("./animation/sam_diying_right.png"),3,Image.load("./animation/sam_diying_left.png"),3} -- 55-58
BufferX,BufferY = Image.createEmpty(64, 320),Image.createEmpty(480, 64)
DeBrief = Image.load("./animation/debriefing.png")
Failed = Image.load("./animation/failed.png")
StatsBar = Image.load("./animation/statsbar.png")
bulletR,bulletL = Image.load("./animation/bulletR.png"),Image.load("./animation/bulletL.png")
pangR,pangL = Image.load("./animation/pangR.png"),Image.load("./animation/pangL.png")
Loaded[3] = 1
end |
| Code: | function Unload(item)
if item == 3 then
UnloadTable = {animations,BufferX,BufferY,DeBrief,Failed,StatsBar,bulletR,bulletL,pangR,pangL}
end
for i,var in ipairs(UnloadTable) do var = nil end
end |
When I call my level editor with Unload(3) (all items in 3 are not neccesary for the editor) at the first line, it still says 2mb free. Almost worse than I started with... Pretty depressing right here... _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Sat Oct 21, 2006 3:41 am Post subject: |
|
|
Try organizing your tables a little bit better. It seems like your tables.. should be setup simpler.
| Code: |
function Unload(item)
if item == 3 then
UnloadTable = {animations,BufferX,BufferY,DeBrief,Failed,StatsBar,bulletR,bulletL,pangR,pangL}
end
for i,var in ipairs(UnloadTable) do
var = nil
end
end
|
Does not remove all instances of the table, Unless Unload(item) returns a new table which you use to write over the existing table. Thus redefining the table and clearing up the existing memory.
Your table configuration also seems a little bit on the weak side.
Try useing nested tables for animations. Then you can search for the object by ID, or use it in an array.
Example
| Code: |
Animations = {
{ "ID1", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID2", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID3", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID4", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID5", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID6", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID7", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID8", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
}
|
There are some options for you to use. Please define all instances of the variable to nil and make shure there is no copys of the tables anywhere else. |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sat Oct 21, 2006 7:06 pm Post subject: |
|
|
Thanks for your quick reply.
when I'm having a problem that I can't solve after 2 days, I like to make some test scripts to clear my mind. Look at this:
| Code: | print(System.getFreeMemory() / 1024)
animations={Image.load("./animation/running_right.png"),5,Image.load("./animation/running_left.png"),5,Image.load("./animation/sam_crouchwalk_right.png"),8,Image.load("./animation/sam_crouchwalk_left.png"),8 --1 to 8
,Image.load("./animation/sam_gunreach_right.png"),6,Image.load("./animation/sam_gunreach_left.png"),6,Image.load("./animation/sam_gunwalk_right.png"),8,Image.load("./animation/sam_gunwalk_left.png"),8 -- 9 to 16
,Image.load("./animation/sam_elbow_right.png"),6,Image.load("./animation/sam_elbow_left.png"),6,Image.load("./animation/sam_shoot_right.png"),6,Image.load("./animation/sam_shoot_left.png"),6 -- 17 to 24
,Image.load("./animation/ClimbOnBlock_right.png"),4,Image.load("./animation/ClimbOnBlock_left.png"),4,Image.load("./animation/ClimbOn2Block_right.png"),7,Image.load("./animation/ClimbOn2Block_left.png"),7 --25 to 32
,Image.load("./animation/jump_right.png"),7,Image.load("./animation/jump_right.png"),7,Image.load("./animation/falling_right.png"),3,Image.load("./animation/falling_left.png"),3,Image.load("./animation/Ladder_up.png"),7 --33 to 42
,Image.load("./animation/Jump_up_right.png"),3,Image.load("./animation/Jump_up_left.png"),3,Image.load("./animation/TurnToladder_right.png"),5,Image.load("./animation/TurnToladder_left.png"),5,Image.load("./animation/shimny_right.png"),7,Image.load("./animation/shimny_left.png"),7--43-54
,Image.load("./animation/sam_diying_right.png"),3,Image.load("./animation/sam_diying_left.png"),3} -- 55-58
print(System.getFreeMemory() / 1024)
animations = nil
print(System.getFreeMemory() / 1024)
animations = {}
print(System.getFreeMemory() / 1024) |
The result is:
19456 -- the memory left after starting luaplayer
15360 -- memory left after loading the images, wich apparantly require 3mb
15360 -- memory available after setting animations to nil, no memory is cleaned
15360 --memory available after redifining table animations, overwriting it like you suggested. Doesn't help either
PS. This script stands alone and thus I can be sure there are no references to it.
PS 2: | Code: | for i,item in ipairs(animations) do
item = nil
end
print(System.getFreeMemory() / 1024) |
gives the same result _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Sat Oct 21, 2006 7:33 pm Post subject: |
|
|
Try adding a call to the garbage collection function, I think this is right but I don't use Lua, sorry:
|
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sun Oct 22, 2006 4:47 pm Post subject: |
|
|
that command exists in lua, but I had no results again... _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Mon Oct 23, 2006 7:31 am Post subject: |
|
|
| the underminer wrote: | | that command exists in lua, but I had no results again... |
There was a problem in earlier version of Lua Player. With 0.20 and this code, saved as script.lua:
| Code: |
white = Color.new(255, 255, 255)
screen:print(0, 0, System.getFreeMemory() / 1024, white)
test1 = Image.load("Applications/Snake/desert.png")
test2 = Image.load("Applications/Snake/desert.png")
test3 = Image.load("Applications/Snake/desert.png")
screen:print(0, 8, System.getFreeMemory() / 1024, white)
test1 = nil
test2 = nil
test3 = nil
collectgarbage()
screen:print(0, 16, System.getFreeMemory() / 1024, white)
while not Controls.read():start() do
screen.waitVblankStart()
screen.flip()
end
|
I get the result 9216, 6144, 9216.
So the right solution would be first to fix the memory problem with loading modules (maybe Oobles has any ideas about it) and then the modules loader for firmware > 1.5. |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Mon Oct 23, 2006 5:23 pm Post subject: |
|
|
Thanks for your reply Shine, but the big downside to this good news is that 020 has a whooping 10mb less memory. Still I tried, but when loading my first level I got this can't create image error (Because it ran outta memory)
I'll just think about what to do next. Maybe I can alter my code so that it can cope with 9 megs, but I don't think Ill manage to do so.
Thanks again _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Mon Oct 23, 2006 6:13 pm Post subject: |
|
|
| the underminer wrote: | | Thanks for your reply Shine, but the big downside to this good news is that 020 has a whooping 10mb less memory. |
Yes, that's what I mean with "the memory problem". Oobles, who implemented the module support, wrote me an eMail that it could be a limitation of the PSPSDK, because you have to specifiy how much memory each module needs at compile time. But currently I don't have time to fix it, maybe ask Oobles. |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Thu Oct 26, 2006 7:18 pm Post subject: |
|
|
I asked Oobles, but he didn't respond. Maybe someone else can do this for me? I would really appreciate it. _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
cools
Joined: 04 Mar 2006 Posts: 46
|
Posted: Sat Oct 28, 2006 10:59 am Post subject: |
|
|
| Well if you wanted a non-module, lots of memory capable lua player check out either mine or youresam's mods to it. They both give around 20 megs or so. |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sun Oct 29, 2006 9:14 am Post subject: |
|
|
thats the mp3 and ogg supported mod right cools?
BTW You left out the over/undeclocking because is is dangerous you say. Is it dangerous when you use the luacode for it or dangerous in itself? I ask because I always use IRShell to overclock LUA as 0.16 cant overclock itself as you know. |
|
| Back to top |
|
 |
cools
Joined: 04 Mar 2006 Posts: 46
|
Posted: Sun Oct 29, 2006 9:29 am Post subject: |
|
|
Yup the Ogg/Mp3 one is non-module. It was originally intended to be used with the original 2.00 tiff exploit (since that is what i was using) with luaplayer .20, since at the time you could only use luaplayer .16 on 2.00.
The Over/Underclocking was removed; The function(s) itself were not harmful to the psp in any way, its just that if one user decides to:
| Code: | function overloadpsp()
l = 1
System.setClockSpeed(l)
l = l + 1
end
|
Even calling any one of the system over/under clocking functions in a while true do loop could be harmful. (Setting your psp to 333 mhz every loop... not good)
Stick with IRShell, its a lot safer! |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sun Oct 29, 2006 9:51 pm Post subject: |
|
|
| Allright nice! And you almost bricked your own PSP with that? Haha almost fell in your own trap. Anyway thx for your mod. Finally mp3 and ogg support. Makes life alot easier. Is there any limit on file size or is that just limited by the amount of free memory? |
|
| Back to top |
|
 |
Mechanical
Joined: 06 Feb 2006 Posts: 4
|
Posted: Mon Nov 06, 2006 6:41 am Post subject: |
|
|
Hi ;)
I have a noob question. How to unload png from memory?
screen = Image.load("screen.png")
screen = nil
?? |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Wed Nov 08, 2006 1:15 am Post subject: |
|
|
| Mechanical wrote: | Hi ;)
I have a noob question. How to unload png from memory?
screen = Image.load("screen.png")
screen = nil
?? |
You can never use screen to store an image in!!
screen is reserved for what you see on the screen. To show an image on the screen you do this:
Duck = Image.load("duck.png")
screen:clear() -- removes everything that was on the screen buffer
screen:blit(0,0,Duck)
screen.flip() -- this draws on the physical screen what is in the screen buffer. Anything you change in the buffer'screen' will only be visible after you do screen.flip() _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Wed Nov 08, 2006 10:41 am Post subject: |
|
|
| and yes to unload it you would do "Duck = nil" |
|
| Back to top |
|
 |
Mechanical
Joined: 06 Feb 2006 Posts: 4
|
Posted: Thu Nov 16, 2006 12:29 am Post subject: |
|
|
big thanks
ducks - new playstation symbol ;))
ok, another question...
i have not any idea why i can't use all psp memory... i can't load more than ~ 3.6MB :/
(luaplayer 0.20).
it is possible to load more data to memory?
thx. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|