Lua Player for PSP

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

Moderators: Shine, Insert_witty_name

Post Reply
alex_dsnews
Posts: 13
Joined: Wed Aug 03, 2005 9:48 pm

Post by alex_dsnews »

Why not just try it? :P
at work. ;)

looks like (from Shine's eg) that you can quite happily blit well offscreen, though, which is useful.
Laurens
Posts: 14
Joined: Tue Jun 28, 2005 10:26 pm

Re: PhysicsFS, Lowser and savegame data

Post by Laurens »

Since I'm the one currently working on the physfs thing, I'll also comment on it :)
Shine wrote: - System.openArchive(name) is added, which adds all files from the archive for all read functions (I omitted the nasty details here, like rewriting Lua io-lib and Mikmod to make this possible :-)
I don't quite see what that function would be good for - in my opinion, on startup, _ALL_ .zipfiles can be added to the path, so there is no need to open archives from within scripts yourself. Not having an extra functions should be easier for users.
Shine wrote: So the proposed changes to Lua Player:

- EBOOT.PBP first searchs for script.lua and starts it, if found
- if not found, it search for game.zip, opens it as a PhysicsFS archive and starts script.lua from within it
I'd say: add all found archives to the path. The archives should have a subfolder for the game (so in mygame.zip, there would be mygame/index.lua).
Shine wrote: - System.openArchive(name) is added, which adds all files from the archive for all read functions (I omitted the nasty details here, like rewriting Lua io-lib and Mikmod to make this possible :-)
- System.closeArchive(name) is added, for example for Lowser to find the index.lua from the currently opened archive, only
- Lowser scans the Applications directory for directories and for zip-archives
These functions & changes are imo only needed if not all archives are added at bootup.

As for the path, I think /psp/GAME/luaplayer would be better, or is there a reason you guys like /psp/luaplayer better?

The nasty thing is, unfortunately, that a simple compile of physfs is not possible, so I've started working on a psp driver for it.

BTW: I'm working with the 1.0-stable release of physfs. You guys think I should use the developent version 1.1?
If a beautiful girl tells you she's done some modeling work in the past, and you ask her what 3D software she used, you might be a gamedeveloper.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Re: PhysicsFS, Lowser and savegame data

Post by nevyn »

Laurens wrote:As for the path, I think /psp/GAME/luaplayer would be better, or is there a reason you guys like /psp/luaplayer better?
Yeah. /psp/GAME/luaplayer contains the binary, so that if you want to upgrade to a new version of luaplayer, you have to move all your files (Applications, Documents) somewhere else, remove the old version, put the new version in, and put all the files back. Plus, GAME is indeed for the binaries, and user files don't belong there. (That's like saving your Photoshop images to /Program Files/Photoshop/ or whatever.)

(That's why I place all my roms in ms0:/Documents/ROMS/ and not ms0:/PSP/GAME/whateveremulator/ROMS/)
Laurens
Posts: 14
Joined: Tue Jun 28, 2005 10:26 pm

Re: PhysicsFS, Lowser and savegame data

Post by Laurens »

Good point.
If a beautiful girl tells you she's done some modeling work in the past, and you ask her what 3D software she used, you might be a gamedeveloper.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: PhysicsFS, Lowser and savegame data

Post by Shine »

Laurens wrote:These functions & changes are imo only needed if not all archives are added at bootup.
You are right, no need for user functions for PhysFS archives, if all files with ".luapp" are opened as archives on startup. This can be recursive: If a script is called with the new script instantiate function call and it is in a normal directory, all archives within this directory are opened, too, which may be useful while developing, because you can place your graphics in one file in the directory, but you can still editing the script file(s).
liquid8d
Posts: 66
Joined: Thu Jun 30, 2005 6:29 am

Post by liquid8d »

Hey guys,

Great job on this... I just got to check out the player for the first time, and looks like it will be great to work with...

Quick question though, please don't take this as a feature request, but do you intend sometime in the future (i know you probably have your hands full now) to add network functions to this?

I would like to start working on a simple game but would like to include some network support, and wasn't sure if I should wait for this, or use the hackaround available for network send/receive. I currently have an ftp client in testing, but as a newbie to C, i am having some difficulties getting everything working properly. It would be nice for simple lua purposes, to be able to just call upon network functions like (net.connect net.listen, etc)

Thanks,

LiQuiD8d
alexmae
Posts: 22
Joined: Sat Mar 12, 2005 1:46 am

Post by alexmae »

how can i make it work if 2 keys are pressed at the same time? it only gets one
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

alexmae wrote:how can i make it work if 2 keys are pressed at the same time? it only gets one
make sure you got it like this:

Code: Select all

pad = Controls.read()
if pad:cross() then
  etc
end
if pad:circle() then
  etc
end


and not:

Code: Select all

pad = Controls.read()
if pad:cross() then
  etc
elseif pad:circle() then
  etc
end
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

any chance of a lua tutorial being put together. I have used PASCAL and BASIC on a minimal level. I was wondering if anyone could put together a tutorial of sorts that comments on how to common tasks, such as :

displaying images, button input, sound playing with button presses, looping, scrolling images.

I've been following this thread for a while now, and I have an idea on how to do most of this, but its not working out the way I thought it would lol.

If this would be too much trouble, i'll just keep reading, and trying hehe.

Thanks for making Lua on the PSP. It gives me something that I can use to attempt at creating for the PSP. Thank you.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Any way to implement a millisecond function in lua ? It really lacks it...
We have os.time(), which returns the time in seconds....
How about a os.timems(), which returns the time in milliseconds ?
Puzzle Bobble - The arcade port!
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Nils wrote:Any way to implement a millisecond function in lua ? It really lacks it...
We have os.time(), which returns the time in seconds....
How about a os.timems(), which returns the time in milliseconds ?
what about os.clock() ?
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Excellent .... thx Shine. Lua's doc is really awful and so incomplete.
We lack a math.int or math.round .. somehow founded that one, but would be nice to implement directly in lua:

function math.round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end


idp being the number of decimals you want.

I was wondering also about coroutines / threads, any clue where to look at ?
I'm looking for a typical "onEnterFrame() as in Flash" way to have independents objects behave ; doing everything in a linear way seems weird :/
Puzzle Bobble - The arcade port!
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Ok.. been running a few tests to see what was the fastest loop. Somehow, as usual, it seems that while - is the fastest around.
System.usbDiskModeActivate()
color = {
red = Color.new(255,0,0);
green = Color.new(0, 255, 0);
blue = Color.new(0,0,255);
}
local q = 0
local j = 0
local time = os.clock()
for i=1,100000 do
q = q +1
end
local time2 = os.clock()
local delay = time2 - time
screen:print(10, 40, "for loop: " .. tostring(delay) .. " milliseconds", color.red)
screen:print(10, 50, "|_iterations : " .. tostring(q), color.red)

local q = 0
local i = 0
local j = 100000
local time = os.clock()
while i < j do
i = i +1
q = q +1
end
local time2 = os.clock()
local delay = time2 - time
screen:print(10, 60, "while + loop: " .. tostring(delay) .. " milliseconds", color.green)
screen:print(10, 70, "|_iterations : " .. tostring(q), color.green)

local v = 0
local q = 0
local j = 100000
local time = os.clock()
while j > v do
j = j -1
q = q +1
end
local time2 = os.clock()
local delay = time2 - time
screen:print(10, 80, "while - loop: " .. tostring(delay) .. " milliseconds", color.blue)
screen:print(10, 90, "|_iterations : " .. tostring(q), color.blue)



while not Controls.read():start() do
screen.waitVblankStart()
screen.flip()
end
System.usbDiskModeDeactivate()
Results for me:

For loop, 675.21 ms
While + loop, 639.35 ms
While - loop, 635.05 ms

Not much .. but good to know

[edit]
1 million iterations:
for loop: 7.138 secs
while + loop: 6.790 secs
while - loop: 6.745 secs
[/edit]
Puzzle Bobble - The arcade port!
alexmae
Posts: 22
Joined: Sat Mar 12, 2005 1:46 am

Post by alexmae »

MikeHaggar wrote:
alexmae wrote:how can i make it work if 2 keys are pressed at the same time? it only gets one
make sure you got it like this:

Code: Select all

pad = Controls.read&#40;&#41;
if pad&#58;cross&#40;&#41; then
  etc
end
if pad&#58;circle&#40;&#41; then
  etc
end
thanks alot ;)


and not:

Code: Select all

pad = Controls.read&#40;&#41;
if pad&#58;cross&#40;&#41; then
  etc
elseif pad&#58;circle&#40;&#41; then
  etc
end
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

I am just learning here, so excuse the noobness of this post lol. I am having trouble just displaying a backgroud behind my text. I've looked at the snake example, still having troubles... can anyone clarify what I am doing wrong here.

Code: Select all

-- Define Text Color
green = Color.new&#40;0, 255, 0&#41;

-- Load background Image
backimage = Image.load&#40;"background.png"&#41;

-- Print out text with pre-defined color
screen&#58;print&#40;240, 136, "Just Testing", green&#41;

-- Display background Image
image&#58;blit&#40;0, 0, backimage, 0, 0, backimage&#58;width&#40;&#41;, backimage&#58;height&#40;&#41;, false&#41;


screen.flip&#40;&#41;
while true do
	screen.waitVblankStart&#40;&#41;
end
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

F34R wrote:I am just learning here, so excuse the noobness of this post lol. I am having trouble just displaying a backgroud behind my text. I've looked at the snake example, still having troubles... can anyone clarify what I am doing wrong here.

Code: Select all

-- Define Text Color
green = Color.new&#40;0, 255, 0&#41;

-- Load background Image
backimage = Image.load&#40;"background.png"&#41;

-- Print out text with pre-defined color
screen&#58;print&#40;240, 136, "Just Testing", green&#41;

-- Display background Image
image&#58;blit&#40;0, 0, backimage, 0, 0, backimage&#58;width&#40;&#41;, backimage&#58;height&#40;&#41;, false&#41;


screen.flip&#40;&#41;
while true do
	screen.waitVblankStart&#40;&#41;
end
Um. Look at your code. First you print text to the screen. Then, you paint an image on top of that. Or actually, you're painting the image into nothing... It should be screen:blit(0,0,backimage, false) (the rest of the parameters are redundant)

Reverse the image blitting and the text printing and you should be fine.
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

like i said, I am VERY new to all this, so thank you very much. I'll work on that. Thats why I wondered about a tutorial that showed basic concepts like these.

I'll work on that, and thanks again.

ok... got it all working now... TYVM !!

here is the final code for my first display using Lua ... hehe...

Code: Select all

-- Define text colors

	green = Color.new&#40;0, 255, 0&#41;

-- Load Images

	background = Image.load&#40;"background.png"&#41;
	splash = Image.load&#40;"luasplash.png"&#41;

-- Display Lua Splash

	screen&#58;blit&#40;0, 0, splash, false&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
	screen.waitVblankStart&#40;240&#41;
	screen.flip&#40;&#41;

-- Display Background Image

	screen&#58;blit&#40;0, 0, background, false&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
	screen.waitVblankStart&#40;250&#41;
	screen.flip&#40;&#41;

-- Print text on the screen
	screen&#58;print&#40;200, 100, " DID IT WORK ? ", green&#41;
	screen.flip&#40;&#41;

while true do
screen.waitVblankStart&#40;&#41;

-- End 
end
Now I know that many of you could do this sort of thing with your eyes closed and fingers taped up lol... I am excited that it was really that easy after I learned what I had done wrong.

Another thing:

I noticed that sound and music are saved as .xm files... how do you create those ? and is there a size limit on them ?

What does screen.flip() actually do ?
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

Ok, another question. This one is about displaying a graphic, like the snake. I noticed that the background in the snake tileset is white. Does it HAVE to be white.

I downloaded a few samples of a character walking. It included all 8 directions of the character walking. The background for this brown. Its not a tileset either. Its a seperate bitmap file for each part of the animation.

Will I be able to use this ? Or does it have to be a tileset on a white background ?

I am going to attempt to write the code to display him walking on my own, before asking for help on that. This will be using the D-Pad.
gabriel
Posts: 5
Joined: Thu Aug 11, 2005 8:33 am

on_KeyPress / on_KeyRelease ?

Post by gabriel »

MikeHaggar wrote:
alexmae wrote:how can i make it work if 2 keys are pressed at the same time? it only gets one
make sure you got it like this:

Code: Select all

pad = Controls.read&#40;&#41;
if pad&#58;cross&#40;&#41; then
  etc
end
if pad&#58;circle&#40;&#41; then
  etc
end


and not:

Code: Select all

pad = Controls.read&#40;&#41;
if pad&#58;cross&#40;&#41; then
  etc
elseif pad&#58;circle&#40;&#41; then
  etc
end
Is there any way to track key presses and releases?

I tried to write code which kept track of the last pressed key and this worked good while pressing single buttons. But, when I held the left button and tapped another button the button that was being held was still being executed as though it was being pressed at the same rate as the one I was pressing continuously.

Here's a sample of what I tried:

Code: Select all

pad = Controls.read&#40;&#41;
if pad&#58;left&#40;&#41; and pad ~= last_k then
	--processed key left. prevent execution of code while key remains pressed
end
last_k = pad
gabriel
Posts: 5
Joined: Thu Aug 11, 2005 8:33 am

Image Rotate

Post by gabriel »

I noticed that the "rotate.lua" script contains a function which allows you to rotate an image 90° clockwise however it does not allow you to rotate the image 90° counter-clockwise (which may come in handy for someone). I originally tried to simulate a counter-clockwise rotation by doing 3 clockwise rotations but it didn't seem right.

Here's my modified version of the function:

Code: Select all

function rotate&#40;image, dir&#41;
	local w = image&#58;width&#40;&#41;
	local h = image&#58;height&#40;&#41;
	local result = Image.createEmpty&#40;h, w&#41;
	
	for x=0,w-1 do
		for y=0,h-1 do
			if dir == 0 then
			  result&#58;pixel&#40;h-y-1, x, image&#58;pixel&#40;x, y&#41;&#41;
			else
			  result&#58;pixel&#40;y, w-x-1, image&#58;pixel&#40;x, y&#41;&#41;
			end
		end
	end

	return result
end

Code: Select all

tank = Image.load&#40;"tank.png"&#41;
--90° Clockwise&#58;
tank = rotate&#40;tank, 0&#41;
screen&#58;blit&#40;0, 0, tank, 0, 0, tank&#58;width&#40;&#41;, tank&#58;height&#40;&#41;, false&#41;
--90° Counter-Clockwise&#58;
tank = rotate&#40;tank, 1&#41;
screen&#58;blit&#40;0, 0, tank, 0, 0, tank&#58;width&#40;&#41;, tank&#58;height&#40;&#41;, false&#41;
I hope this comes in handy for someone.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Hi ... My first contrib to luaplayer. Shine, you missed that in your apps !
So here is the classic 3d wireframe cube demo made on all systems / languages... lua for psp had to have it :)

Image

Download it here :
- full with lua 0.7 embedded
- lua script version only

Pad or analog pad to move, select for screenshot, start to get out.
Up to more ... Lua is a wonderful toy :)
Puzzle Bobble - The arcade port!
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

F34R wrote:Ok, another question. This one is about displaying a graphic, like the snake. I noticed that the background in the snake tileset is white. Does it HAVE to be white.
It is not white, use a better graphics program.

There is a new tutorial thread:

http://forums.ps2dev.org/viewtopic.php?t=3009

and a thread for the Lua Player C development:

http://forums.ps2dev.org/viewtopic.php?t=3010
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

Shine wrote:
F34R wrote:Ok, another question. This one is about displaying a graphic, like the snake. I noticed that the background in the snake tileset is white. Does it HAVE to be white.
It is not white, use a better graphics program.
LOL. I was just viewing it in windows explorer. I opened it up in PS and I see that is has a transparent background. Ok, I admit, I am just shy of being retarded when it comes to this lol.

Thanks for the Tuts thread Shine.
SnowSurfer
Posts: 21
Joined: Fri Jul 08, 2005 2:59 am

Post by SnowSurfer »

nice tuts shine, i think one needs to be added about using a timer in a game to determine how much time is left until you get gameover.. :)
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

Ok, I have my little smiley going left, right, up, and down. Here is what i cant figure out...

When I press "right", my smiley moves to the right, but it only moves ONCE. When I stop pressing "right" on the dpad, the smiley moves back to its original position. How do I make it stay on the new position ? I tried doing a while loop, and it locked the psp up hehe..

This locked up the psp

Code: Select all

while pad&#58;right&#40;&#41; do
x = x + 2
end
I used that instead of whats below, and like I said, it locked the psp up.

Code: Select all

        x = 20
	y = 100
	
	pad = Controls.read&#40;&#41;
	if pad&#58;right&#40;&#41; then
		x =  x + 10
	end	
	if pad&#58;left&#40;&#41; then 
		x = x - 10
	end
	if pad&#58;up&#40;&#41; then
		y = y - 10
	end
	if pad&#58;down&#40;&#41; then
		y = y + 10
	end
      
        screen.blit&#40;x, y, smiley&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;

	pad = Controls.read&#40;&#41;
	if pad&#58;start&#40;&#41; then
		break
	end
This only made the smiley move in the direction pressed, then put the smiley back to the original x/y position.
Last edited by F34R on Sat Aug 13, 2005 10:44 pm, edited 1 time in total.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

SnowSurfer wrote:nice tuts shine, i think one needs to be added about using a timer in a game to determine how much time is left until you get gameover.. :)
Things like this are the prerequisites for the Lua Player tutorial, I don't want to write a general Lua tutorial, there are better ones for this purpose, like http://lua-users.org/wiki/TutorialDirectory
gabriel
Posts: 5
Joined: Thu Aug 11, 2005 8:33 am

Post by gabriel »

F34R wrote:Ok, I have my little smiley going left, right, up, and down. Here is what i cant figure out...

When I press "right", my smiley moves to the right, but it only moves ONCE. When I stop pressing "right" on the dpad, the smiley moves back to its original position. How do I make it stay on the new position ? I tried doing a while loop, and it locked the psp up hehe..

This only made the smiley move in the direction pressed, then put the smiley back to the original x/y position.
Wow, you really need to review the tutorials and focus on basic programming with lua...

Anyway, define your starting x/y positions outside of the main program loop so that your positions will remain.

Example:
--starting positions

Code: Select all

x = 20
y = 100

while true do
   pad = Controls.read&#40;&#41;
   if pad&#58;right&#40;&#41; then
      x =  x + 10
   end   
   if pad&#58;left&#40;&#41; then
   ...blah blah blah
end
Just make sure that you don't put that x=20 and y=100 within the main "while" loop.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Shine, Nevin, is it possible to add a function inside LUA to rotate an image ?
I've been coding a few functions, like reading the pixels 1 by 1 of a given image, storing the x,y,color in a table, then recreating the image with that array dot by dot, and modifying x,y in that array live applying 2d sin and cos rotation, but it's AWFULLY slow, even for small images.... besides, the limitation of displaying a dot somewhere (a dot cannot be displayed on negative coords :( makes this rotation trick a real pain in the a**.
Many games rotate images, and the lack of rotation means one has to precompute rotated still images :(

Something wonderful would be image:rotation(int angle) ...

Also, i've been thinking about my wireframe cube, and it seems impossible to make it textured, as Lua lacks a "fillShape" function... would be great, i'm pretty sure Lua can handle textured 3d with the draw API, but it needs to be enhanced.
Puzzle Bobble - The arcade port!
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

Gabriel,

I had tried doing a while loop already, maybe I didnt have the syntax right. Addind the while/do loop for the pad input just made a loop that i can break out of unless I added a break in the while loop.

Here is what I changed the code to. Just FYI, I did go back and read a good bit of the tutorials at http://lua-users.org/wiki/TutorialDirectory. Anywas.. here it is.

Code: Select all

System.usbDiskModeActivate&#40;&#41;
background = Image.load&#40;"background.png"&#41;
smiley = Image.load&#40;"smiley.png"&#41;

while true do
	screen&#58;blit&#40;0, 0, background, 0, 0, background&#58;width&#40;&#41;, background&#58;height&#40;&#41;, false&#41;

-- Set start position for the smiley
	

	x = 221
	y = 135

-- Set postition when dpad is pressed

	while true do

		pad = Controls.read&#40;&#41;
		if pad&#58;right&#40;&#41; then
		x = x + 5
		end
		if pad&#58;left&#40;&#41; then
		x = x - 5
		end
		if pad&#58;up&#40;&#41; then
		y = y - 5
		end
		if pad&#58;down&#40;&#41; then
		y = y + 5
		end
				
	end
	
	screen&#58;blit&#40;x, y, smiley&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;

	if pad&#58;start&#40;&#41; then
		break
	end

end
Now this doesnt move the smiley at all.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

F34R,

try that:

Code: Select all

System.usbDiskModeActivate&#40;&#41;
background = Image.load&#40;"background.png"&#41;
smiley = Image.load&#40;"smiley.png"&#41;

screen&#58;blit&#40;0, 0, background, 0, 0, background&#58;width&#40;&#41;, background&#58;height&#40;&#41;, false&#41;

-- Set start position for the smiley
   x = 221
   y = 135

-- Set postition when dpad is pressed
function keypad&#40;&#41; 
   local pad = Controls.read&#40;&#41;
      if pad&#58;right&#40;&#41; then
      x = x + 5
      elseif pad&#58;left&#40;&#41; then
      x = x - 5
      elseif pad&#58;up&#40;&#41; then
      y = y - 5
      elseif pad&#58;down&#40;&#41; then
      y = y + 5
      end
end

while not Controls.read&#40;&#41;&#58;start&#40;&#41; do
	keypad&#40;&#41;
	screen&#58;blit&#40;x, y, smiley&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
end
Puzzle Bobble - The arcade port!
Post Reply