IO File Handling ?

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

Moderators: Shine, Insert_witty_name

Post Reply
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

IO File Handling ?

Post by Giuliano »

Is this possible on Lua ? I wish to make games but it would be much harder to create level files and such within my code. I was wondering if it's possible to load files into tables (arrays) in Lua.

edit:if it's not possible yet, would it be possible to declare my level tables in a separate file as a const.. such as
map={ {1,2,3}, {1,2,3} .... etc... }
and then use dofile("level1.lua") to load in that array ?
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

both are possible. currently i use the dofile method to load my levels.. i also have a level editor that uses the io library to create .lua files on the fly..

unfortunately, the documentation kind of sucks.

http://www.lua.org/manual/5.0/manual.html#5.6

i suggest checking out the source code for one of those lua notepad editor programs, that's what i based my code off of.
Chaosmachine Studios: High Quality Homebrew.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Alright thanks. I actually wasn't aware of that lua.org documentation. Makes life much easier.

How is your game doing on speed btw ?
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

60fps most of the time.. i've done a lot of optimizing..

things start to drop below that if i'm drawing more than about 80 16x16 tiles per refresh.
Last edited by chaos on Tue Sep 13, 2005 1:29 pm, edited 1 time in total.
Chaosmachine Studios: High Quality Homebrew.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

chaos wrote:60fps most of the time.. i've done a lot of optimizing..

things start to drop below than if i'm drawing more than about 80 16x16 tiles per refresh.
that's only about an 128x128 tile screen... pretty small .. I'm trying to cover a 352x272 tile screen
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

chaos wrote:60fps most of the time.. i've done a lot of optimizing..

things start to drop below that if i'm drawing more than about 80 16x16 tiles per refresh.
You can blit the tiles to an offscreen image first, which is created on level start and then blit this to screen on every vsync (or multiple offscreen images, which are updated, when you are scrolling out of range of one image). For many small tiles the overhead for blitting is high.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Shine wrote:
chaos wrote:60fps most of the time.. i've done a lot of optimizing..

things start to drop below that if i'm drawing more than about 80 16x16 tiles per refresh.
You can blit the tiles to an offscreen image first, which is created on level start and then blit this to screen on every vsync (or multiple offscreen images, which are updated, when you are scrolling out of range of one image). For many small tiles the overhead for blitting is high.
Not a bad idea. It's a scrolling tile engine though. Would there be a problem if I am creating the primary level image as like 500x500 and then blit that on every vsync then draw my sprites on top of it ?
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

Shine wrote:
chaos wrote:60fps most of the time.. i've done a lot of optimizing..

things start to drop below that if i'm drawing more than about 80 16x16 tiles per refresh.
You can blit the tiles to an offscreen image first, which is created on level start and then blit this to screen on every vsync (or multiple offscreen images, which are updated, when you are scrolling out of range of one image). For many small tiles the overhead for blitting is high.
i actually found this method to be slower in my initial testing.. i'll have to take another look at it.
Chaosmachine Studios: High Quality Homebrew.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Re: IO File Handling ?

Post by LuMo »

Giuliano wrote:Is this possible on Lua ? I wish to make games but it would be much harder to create level files and such within my code. I was wondering if it's possible to load files into tables (arrays) in Lua.
you can even create your own level files (as i am going to for bomberman)
you can use my Explode/Implode function to convert a string to a table

greets
Lumo
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Shine wrote:
chaos wrote:60fps most of the time.. i've done a lot of optimizing..

things start to drop below that if i'm drawing more than about 80 16x16 tiles per refresh.
You can blit the tiles to an offscreen image first, which is created on level start and then blit this to screen on every vsync (or multiple offscreen images, which are updated, when you are scrolling out of range of one image). For many small tiles the overhead for blitting is high.
After a small test I'm guessing you said "or multiple offscreen images when you are scrolling out of range" because I can't create a 1000x1000 image for the offscreen buffer, it's too big .. ?
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

maximum texture/image size is 512x512, afaik.
Chaosmachine Studios: High Quality Homebrew.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

chaos wrote:maximum texture/image size is 512x512, afaik.
Dunno, 500x500 didnt work for me. I just made them 240x240 and I am almost done w/ my code that allows for scrolling and connects them up to it's seamless to the user :)... I just dont really know what kind of game I will be making.

Btw, it's a hellllll lot faster for me .. running at full speed and I am drawing a 352x272 screen of 16x16 tiles
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Okay.. here it is.. check it out.. I did what Shine said and the speed is a hell lot faster.. If you are interested to see how to make a scrolling tile engine w/ offscreen images and make it seamless this will show you how (a little complicated so don't expect to understand in one reading of the code) .. the white part is going to be a stats panel

Any ideas of what kind of game I should make ?


ps: please don't use my tiles.. the bird is from Mario

Here you go:http://www.peoplegrade.com/g/ATest.zip
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

chaos wrote:maximum texture/image size is 512x512, afaik.
For loading images this is right, but for creating currently it is 480x272, I'll fix this in the next release, there is no reason why it should not be 512x512. Perhaps even larger images maybe possible, I'll check this. Of course, blitting maybe slower then, because of less good cache usage.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Shine wrote:
chaos wrote:maximum texture/image size is 512x512, afaik.
For loading images this is right, but for creating currently it is 480x272, I'll fix this in the next release, there is no reason why it should not be 512x512. Perhaps even larger images maybe possible, I'll check this. Of course, blitting maybe slower then, because of less good cache usage.
I made it 240x240 and it's very fast, check out the file I uploaded
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Giuliano wrote: I made it 240x240 and it's very fast, check out the file I uploaded
This is nice, now we can make all those cool old games like R-Type, Turrican, Giana Sisters etc.

I've found a Java applet which simulates the good old C64 games in your browser: http://www.dreamfabric.com/c64/ Would you believe it some 20 years ago, if someone tells you that you can download a full emulation of your C64 in some seconds in a browser window, including a running game? Oh yes, and some "tilesets" http://kofler.dot.at/c64/font_14.html but some are "multi-color" fonts, with 2 pixels per pixel and maybe some are used as C64 "extended-color" fonts, with different foreground and background colors per char :-)

BTW: you can use image:width and image:height in your sprite class instead of passing it in the constructor.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Shine wrote:
Giuliano wrote: I made it 240x240 and it's very fast, check out the file I uploaded
This is nice, now we can make all those cool old games like R-Type, Turrican, Giana Sisters etc.

I've found a Java applet which simulates the good old C64 games in your browser: http://www.dreamfabric.com/c64/ Would you believe it some 20 years ago, if someone tells you that you can download a full emulation of your C64 in some seconds in a browser window, including a running game? Oh yes, and some "tilesets" http://kofler.dot.at/c64/font_14.html but some are "multi-color" fonts, with 2 pixels per pixel and maybe some are used as C64 "extended-color" fonts, with different foreground and background colors per char :-)

BTW: you can use image:width and image:height in your sprite class instead of passing it in the constructor.
I'll check those out when I get back home. I have college classes right now :)

I can't use image:width and image:height because it's the "frame" sprite width and height not the image.. the image contains all the animation and such.. however, since there are always 4 sprites in a row I could do image:width()/4 and then do a mod to see how many frames are in the image (it varies)
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

Those are way too old.. I am hoping to make something newer but w/ 2d graphics
Post Reply