Lua Player for PSP

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

Moderators: Shine, Insert_witty_name

Post Reply
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

that "worked" to a degree. It keeps drawing the screen really fast, making it look like a strobe effet. It does allow me to move the smiley around in all directions, but it leaves a trail of smileys. I was able to get that result earlier as well.

Thanks for the suggestion though.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

F34R wrote:Now this doesnt move the smiley at all.
For successful debugging imperative programs (if you would like to write it in Prolog, it would be more correct like you've done it) you have to simulate the program flow in your brain or on paper. This is what your program does:

1. usb active, image loading
2. blit background to offscreen
3. set start position
4. check pad and update position
5. goto 4
6. blit smiley to offscreen and flip visible screen and offscreen
7. exit, if start was pressed
8. goto 2

Perhaps now you can correct your program.
Nils wrote:Shine, Nevin, is it possible to add a function inside LUA to rotate an image ?
Yes, this is possible. There was a discussion on #pspdev on freenode and ooPo suggested to use libart. It has some nice vector operations, and could be built on top of the current graphics.c. Then you can use the old API, but if you want something more, which may be slower, you can use the libart functions, too.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

F34R, add a fillrect with black color in the main while loop, in order to erase previous smiley

Shine > seems interesting :)
" Libart has full support for RGB and RGBA image operations, including rotation, scaling, skewing, and alpha compositing."

Yay !
Puzzle Bobble - The arcade port!
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Nils wrote:F34R, add a fillrect with black color in the main while loop, in order to erase previous smiley
You don't need this. There are two reasons against it: If you want to clear the screen, call the clear function, it is faster. And in step 2 of my program flow explanation the background is blitted without alpha, so assuming the background image is 480x272, the whole display is already reseted to the background pixels.
Nils wrote: Shine > seems interesting :)
" Libart has full support for RGB and RGBA image operations, including rotation, scaling, skewing, and alpha compositing."
Ok, now we only need someone who ports this to PSP and integrates it in Lua Player :-)
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

screen:clear() or myemptygraphic:clear() doesnt work for me; nobody uses that, not even you in snake but at newgame ?
Puzzle Bobble - The arcade port!
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Sticky this bad boy.
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

Shine wrote:
F34R wrote:Now this doesnt move the smiley at all.
For successful debugging imperative programs (if you would like to write it in Prolog, it would be more correct like you've done it) you have to simulate the program flow in your brain or on paper. This is what your program does:

1. usb active, image loading
2. blit background to offscreen
3. set start position
4. check pad and update position
5. goto 4
6. blit smiley to offscreen and flip visible screen and offscreen
7. exit, if start was pressed
8. goto 2

Perhaps now you can correct your program.
Nils wrote:Shine, Nevin, is it possible to add a function inside LUA to rotate an image ?
Yes, this is possible. There was a discussion on #pspdev on freenode and ooPo suggested to use libart. It has some nice vector operations, and could be built on top of the current graphics.c. Then you can use the old API, but if you want something more, which may be slower, you can use the libart functions, too.
Ok Shine, thanks for that info. I now have the following flow :
1. usb active, image loading
2. blit background to offscreen
3. set start position (x,y)
5. blit smiley to offscreen, then flip offscreen with visible screen.
6. check for pad input, using if/elseif a direction returns a +/-5 to x,y.
7. restart if Start is pressed.
8. end the while do loop.

My problem is getting the new value to update. Just a little hint please. I am soooo trying to figure this out.
MSX
Posts: 12
Joined: Wed Jul 06, 2005 2:16 pm

Post by MSX »

First off, thanks Shine for your great tutorial and work on LuaPlay.

I've been testing small code, nothing useful at all, but something's better than nothing...anyways, the problem I'm having is that "Press start to restart" is shown on the screen when I start the code. I added the screenshot feature in and took a sceen to show you what I mean.

Here's the code:

Code: Select all

green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
white = Color.new(255, 255, 255)
red = Color.new(255, 0, 0)
orange = Color.new(255, 140, 0)

System.usbDiskModeActivate()

while true do

	screen:print(1, 80, "To see the best and worst teams of the NFL:", white)
	screen:print(1, 90, "Press Circle: The best NFL teams.", white)
	screen:print(1, 100, "Press Square: The worst NFL teams.", white)
	screen:print(1, 110, "Press Triangle: Exit USB mode.", white)
	screen:print(1, 260, "Created by Nate", green)

	pad = Controls.read()
	if pad:start() then
		break
	end

	if pad:circle() then
		screen:print(1, 140, "Here are the best NFL teams:", orange)
		screen:print(1, 150, "Jacksonville Jaguars", blue)
		screen:print(1, 160, "Carolina Panthers", blue)
		screen:print(1, 170, "Miami Dolphins", blue)
	end

	if pad:square() then
		screen:print(1, 200, "Here are the worst NFL teams:", orange)
		screen:print(1, 210, "San Francisco 49ers", red)
		screen:print(1, 220, "Cleveland Browns", red)
		screen:print(1, 230, "Chicago Bears", red)
	end

	if pad:triangle() then
		System.usbDiskModeDeactivate()
		screen:print(1, 250, "USB Mode Deactivated", white)
	end

	if pad:select() then
		Image:save("screen.tga")
	end

screen.waitVblankStart()
screen.flip()

end
And the screenshot:
Image

Thanks for any help.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Try that at beginning... i ran into this bug also.

Code: Select all

-- this to prevent the press start to restart display bug
layout =Image.createEmpty(480, 272)
layout:fillRect(0, 0 , 480, 272, Color.new(0,0,0))
screen:blit(0, 0, layout)
screen.flip()
screen:blit(0, 0, layout)
screen.flip()
Puzzle Bobble - The arcade port!
MSX
Posts: 12
Joined: Wed Jul 06, 2005 2:16 pm

Post by MSX »

Worked fine Nils, thanks for the tip. ;)
indianajonesilm
Posts: 15
Joined: Tue Feb 08, 2005 6:36 pm

Post by indianajonesilm »

Hi everyone. I'm having trouble creating an options menu for my game and I was wondering what your opinion was on the best way to go about making a menu. I've been trying several different ways over the last few days but nothing seem to work right. Is there a simple way to do it? I've never programmed anything before so, I'm not quite sure how to go about it. Here is what I'm trying to do:
Image
I wanted to make a menu where you would press up or down to change to the selected option and the title would highlight blue, then pressing left or right to select 1, 2, or 3. I got a few ideas in the middle of the night, so I got up and wrote them down, but it didn't work. I don't know what the hell I'm doing! :P

If anyone has some example code of a menu or if you could let me know what I should study up on, I would appreciate that very much. (or you could write the code for me!) :)

Oh by the way I made this little lua player logo screen, if anybody wants to use it.
Image
MSX
Posts: 12
Joined: Wed Jul 06, 2005 2:16 pm

Post by MSX »

indianajoneslim, sorry, can't help ya there, don't know too much :(.

Anyone know what button controls:note() is? My guess was the musical note button at the bottom (what's that for anyways?), but when I press it I don't get the expected output.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

MSX wrote:I've been testing small code, nothing useful at all, but something's better than nothing...anyways, the problem I'm having is that "Press start to restart" is shown on the screen when I start the code.
Thanks, this is a bug, it will be fixed for the next version. The problem is, that the screen is not deleted for the second start, after the text "Press start to restart" was displayed. Just add one "screen:clear()" before all your text outputs and ignore the confusing tip of Nils :-)
Nils wrote:screen:clear() or myemptygraphic:clear() doesnt work for me; nobody uses that, not even you in snake but at newgame ?
Can you describe in detail what does not work for you? Remember that all drawing operations goes to the offscreen or seperate images, even the clear functions. And it may be confusing, that image:clear() deletes the image with transparent pixels, so blitting this with alpha channel enabled to screen doesn't delete the content, if you doen't specify a color without alpha, for example with the default parameter from Color.new: "opaqueBlack = Color.new(0, 0, 0); image:clear(opaqueBlack)". This is ok for Snake for the multilayer concept for which it is used in this code, but perhaps it should be better commented in the functions.txt and tutorial.
F34R wrote:Ok Shine, thanks for that info. I now have the following flow :
1. usb active, image loading
2. blit background to offscreen
3. set start position (x,y)
5. blit smiley to offscreen, then flip offscreen with visible screen.
6. check for pad input, using if/elseif a direction returns a +/-5 to x,y.
7. restart if Start is pressed.
8. end the while do loop.
Another important thing when programming is to be exact. Point 7 is not very clear. Do you restart your loop, or is the whole scripted exited for the restart message? And if this is really your program flow, it will display the "Press start for restart" message after one drawing immidiatly, because in point 8 you say, that you end your loop instead of jumping back to some other number. It is not that difficult: Just read your script line by line and imagine what Lua Player does. A program flow is not just writing the commands in plain English, but you have to think, which line is executed as next under which circumstances.

Instead of using a numbered list, you can draw it as a flowchart, or if you like buzz words, an UML state diagram.
MSX
Posts: 12
Joined: Wed Jul 06, 2005 2:16 pm

Post by MSX »

Thanks for the info on the bug Shine.

Could you tell me what button controls:note() is? I thought it was for the musical note button at the bottom, but when I press it I don't get the expected output.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

"confusing tip"...i cannot get clear() to work and that was the only way to get rid of the "press restart" bug in 0.7.

I tried all possible ways of clear() with nevyn on IRC.
Tried screen:clear(), screen:clear(Color.new(0,0,0)), screen:clear(Color.new(0,0,0,255)) myEmptygraphic:clear() ... nothing happens. No nothing. Also just did add as you suggested screen:clear() at beginning of the script to get rid of the "press start to restart" bug, nothing happens.

Try it Shine.
See my 3dcube demo script there http://lua.ventoline.com/3dcube.lua.txt , locate the theScene:fillRect(0, 0 , 480, 272, color.black) around line 114 (there is only one like that), try to replace it with theScene:clear() or any others that i tried... I even thought that i needed to blit just after to take in account that, but it doesnt work :/

That's 3 times i post for that now .... try it at least :) It doesnt work for me . Show me an example with it working, with an animated thing on screen not leaving trails with clear() :)
Puzzle Bobble - The arcade port!
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Well, lol.
I managed to get clear working, but NOT in the way it should: it behaves strangely:

i had to do a screen:clear() in my main while loop, AND a theScene:clear() in my rotate function that is called just after that, meaning it clears screen, then clears theScene.
It doesnt work with one or the other only, it needs both ! How come ? Bug ?

See it here -> http://lua.ventoline.com/3dcube2.lua.txt

[edit] and FPS has decreased drastically...it's slow now. I'll stick with fillrect until clear() is cleared :)[/edit]
Puzzle Bobble - The arcade port!
MSX
Posts: 12
Joined: Wed Jul 06, 2005 2:16 pm

Post by MSX »

First release on the PSP scene! Wouldn't be of much use, but it makes for a good tutorial, and it's fun to play around with :D
Hey guys...

I've been coding and testing all night in Lua, and I've come up with something that's somewhat useful, well, I guess not useful, but this is my first PSP app .

Basically this will output whichever button you press to the PSP screen, except for Home, Vol +/-, Display Brightness, and the Musical Note buttons. It isn't too hard, but if you put too much power into it, you can turn the PSP off instead of turning Hold off (if you press it to show the output on the screen).

You can go into and out of USB mode while still in this program. Read the readme to see the controls for clearing the screen, starting USB mode, and exiting USB mode.

I think that covers it...hopefully I'll release a more advanced game soon .

Enjoy
Download Here - Looking for mirrors also
Oobles
Site Admin
Posts: 347
Joined: Sat Jan 17, 2004 9:49 am
Location: Melbourne, Australia
Contact:

Post by Oobles »

Just a reminder that anyone looking for a place to host their projects. The main ps2dev.org can be used. Simply login using your userid/password from forums and then use "add topic" from the right menu in one Demos page. After you've added a topic which describes your project, then do "add file" to add your latest release.

Accounts are copied from the forums for anyone who has posted ~8+ posts. If you've done less, just private message me, and I'll setup the account for you.

David. aka Oobles.
ps2dev.org site admin.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

indianajonesilm wrote:I wanted to make a menu where you would press up or down to change to the selected option and the title would highlight blue, then pressing left or right to select 1, 2, or 3. I got a few ideas in the middle of the night, so I got up and wrote them down, but it didn't work. I don't know what the hell I'm doing! :P
Not knowing what you are doing is always a bad thing when it comes to programming :-)

A menu could look like this:

Code: Select all

options = { speed = 1, backgroundImage = "stone" }

possibleOptions = {
	speed = {
		displayName = "Speed",
		values = { 1, 2, 3} },
	backgroundImage = {
		displayName = "Background Image",
		values = { "wood", "stone" }
	}
}

function menu()
	selectedOptionNumber = 0
	deactiveColor = Color.new(0, 255, 0)
	activeColor = Color.new(255, 255, 255)
	oldPad = Controls.read()
	while true do
		screen:clear()
		y = 0
		selectedOptionValues = nil
		selectedOptionIndex = nil
		selectedOptionName = nil
		for optionKey, possibleOption in possibleOptions do
			color = deactiveColor
			if selectedOptionNumber == y then
				color = activeColor
				selectedOptionValues = possibleOption.values
			end
			screen:print(0, y * 10, possibleOption.displayName, color)
			for i, value in possibleOption.values do
				color = deactiveColor
				if options[optionKey] == value then
					color = activeColor
					if selectedOptionNumber == y then
						selectedOptionIndex = i
						selectedOptionName = optionKey
					end
				end
				screen:print(i * 50 + 150, y * 10, value, color)
			end
			y = y + 1
		end

		pad = Controls.read()
		if pad ~= oldPad then
			if pad:triangle() then break end
			if pad:up() then
				selectedOptionNumber = selectedOptionNumber - 1
				if selectedOptionNumber < 0 then selectedOptionNumber = y - 1 end
			end
			if pad&#58;down&#40;&#41; then
				selectedOptionNumber = selectedOptionNumber + 1
				if selectedOptionNumber >= y then selectedOptionNumber = 0 end
			end
			len = table.getn&#40;selectedOptionValues&#41;
			if pad&#58;left&#40;&#41; then
				selectedOptionIndex = selectedOptionIndex - 1
				if selectedOptionIndex <= 0 then selectedOptionIndex = len end
				options&#91;selectedOptionName&#93; = selectedOptionValues&#91;selectedOptionIndex&#93;
			end
			if pad&#58;right&#40;&#41; then
				selectedOptionIndex = selectedOptionIndex + 1
				if selectedOptionIndex > len then selectedOptionIndex = 1 end
				options&#91;selectedOptionName&#93; = selectedOptionValues&#91;selectedOptionIndex&#93;
			end
			oldPad = pad
		end

		screen.waitVblankStart&#40;&#41;
		screen.flip&#40;&#41;
	end
end
MSX wrote:Anyone know what button controls:note() is?
I think it is the note button, which is used to enable/disable the sound (read your PSP manual), but I don't know, if it is available with the note() function. Perhaps a callback needs to be registered for it.
Nils wrote: That's 3 times i post for that now .... try it at least :) It doesnt work for me . Show me an example with it working, with an animated thing on screen not leaving trails with clear() :)
See the animation example from the tutorial page:

Code: Select all

System.usbDiskModeActivate&#40;&#41;
green = Color.new&#40;0, 255, 0&#41;
time = 0
pi = math.atan&#40;1&#41; * 4
while true do
	screen&#58;clear&#40;&#41;

	x = math.sin&#40;pi * 2 / 360 * time&#41; * 150 + 192.5
	screen&#58;print&#40;x, 100, "Hello World!", green&#41;
	time = time + 1
	if time >= 360 then
		time = 0
	end

	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;

	pad = Controls.read&#40;&#41;
	if pad&#58;start&#40;&#41; then
		break
	end
end
Works without problems for me.
Nils wrote: i had to do a screen:clear() in my main while loop, AND a theScene:clear() in my rotate function that is called just after that, meaning it clears screen, then clears theScene.
It doesnt work with one or the other only, it needs both ! How come ? Bug ?
and FPS has decreased drastically...it's slow now. I'll stick with fillrect until clear() is cleared
I don't see any bug. Your code is redundant. Drop the "theScene" image, call screen:clear() at start of your loop, draw everything on the screen (which is in fact the offscreen) and call screen.waitVblankStart() and screen.flip(). Should be faster, because you save one memory copy, which was even slower with your code, because you used the blit function with alpha enabled.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Thx Shine... i did indeed drop the theScene and everything on screen. Now the screen:clear() works.
Seems weird though that theScene:clear() didnt work.
I'm off to code more ... :)
Puzzle Bobble - The arcade port!
emumaniac
Posts: 79
Joined: Sun May 08, 2005 12:22 am

Post by emumaniac »

just a heads up to say that MSX released his button logger app for the psp over at PSP News forums http://www.dcemu.co.uk/vbulletin/showthread.php?t=9224
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Windows version

Post by Shine »

You can download a first version of the Lua Player for Windows. It is a very early alpha version, but graphics should work. Sound and directory functions doesn't work and it could be slower than on PSP (depends on your computer) and it flickers. I've tested it with Snake and some demo progams, which are running fine.

Usage: Copy all your game files into the luaplayerwindow directory, open a DOS command prompt, change to the directory and call "luaplayer script.lua". Hit the escape key to close the window (don't close the window with the mouse, there is a bug in OpenGL GLUT, which this program use). The key mappings:

'a' = select
's' = start
'q' = left trigger
'w' = right trigger
'f' = circle
'r' = tirangle
'c' = cross
'd' = square

cursor keys = pad
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

That's lovely shine, speed is about 95% - 100% correct here and I'm not seeing any flickering either.

Well done :)
indianajonesilm
Posts: 15
Joined: Tue Feb 08, 2005 6:36 pm

Post by indianajonesilm »

Shine wrote:Not knowing what you are doing is always a bad thing when it comes to programming :-)

A menu could look like this:
OH WOW! Thank you so much Shine!
Let me just take this opportunity to to thank Shine, nevyn, and all the other people here who take the time to help out newbs like myself. I know what a pain we can be, always asking for help and asking dumb questions sometimes but you guys are always helpful and patient. A big thank you to Shine for Lua Player, I'm having more fun writing lua scripts than I do playing actual PSP games! Also, thanks for the menu example, it's perfect! :)
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

The Controls:note() is indeed the little note button next to the select button. I added it because I saw that it existed in the C libraries. And no, it doesn't seem to work...

Shine: What the hey, no cross platform thingie? :P Source? I'd really like this thing running on Mac, too... (luaplayer.org seems unreachable...?)
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Re: Windows version

Post by MikeHaggar »

Shine wrote:You can download a first version of the Lua Player for Windows. It is a very early alpha version, but graphics should work. Sound and directory functions doesn't work and it could be slower than on PSP (depends on your computer) and it flickers. I've tested it with Snake and some demo progams, which are running fine.
Thanks!
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

nevyn wrote:Shine: What the hey, no cross platform thingie? :P Source? I'd really like this thing running on Mac, too... (luaplayer.org seems unreachable...?)
I don't have much experience with compiling for Mac, but when I have some more time, I'll port it to this system, too. It is OpenGL based with GLUT, so should be as easy as copying the windows/windows.c to mac/mac.c, tweaking a bit the CreateThread and nanosleep things and writing a Makefile for using the Mac libraries and headers for OpenGL and GLUT. Perhaps someone with more Mac developing experience can do it.

Regarding luaplayer.org: I use this as a test, to see if a Lisp webserver can be used for websites, but looks like I have to learn a bit more about how to setup the Lisp webserver the right way, sometimes it hangs, but I have enabled debugging and now I can login into the running Lisp process on the server and examine the environment, so I think I'll find the problem. Currently it works :-)
F34R
Posts: 29
Joined: Thu Jul 28, 2005 1:11 pm

Post by F34R »

Shine,

I think I see what you mean.

1. usb active, image loading
2. blit background to offscreen
3. set start position (x,y)
5. blit smiley to offscreen, then flip offscreen with visible screen.
6. check for pad input, using if/elseif a direction returns a +/-5 to x,y.
7. Goto 5 with new x,y position.


Is that correct ? I just dont get how to display the image again with the new x,y coords..
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

Shine wrote:I don't have much experience with compiling for Mac, but when I have some more time, I'll port it to this system, too. It is OpenGL based with GLUT, so should be as easy as copying the windows/windows.c to mac/mac.c, tweaking a bit the CreateThread and nanosleep things and writing a Makefile for using the Mac libraries and headers for OpenGL and GLUT. Perhaps someone with more Mac developing experience can do it.
Dude, I am a mac coder :P But I can't very well port it without source, can... Oh! It's at the svn. Of course. I'll try to port it tonight.

(that luaplayer.org site really is *slow*...)
emumaniac
Posts: 79
Joined: Sun May 08, 2005 12:22 am

Post by emumaniac »

is there any sites with free Lua games that just need some modification to run on psp ?

I would also love to see this on Dreamcast.
Post Reply