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 »

The button images definately weren't interlaced, and they definately worked using your first version of the player that you posted here.

Odd.

edit: Embedded colour profile - that'll be it, then.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

SnowSurfer wrote:ok i got it to work, it was the button pictures from the button match program, i made my own buttons and low and behold it works fine..

i put the bad pictures in a handy zip for you to look at

http://www.members.cox.net/snowsurfns/Buttons.zip
I was able to reproduce the warning message with Lua Player 0.5 and with Lua Player 0.6 it works, even with the images which causes a warning, because version 0.6 ignores the warnings.
27Bstroke6
Posts: 23
Joined: Thu Jul 07, 2005 3:56 pm

Post by 27Bstroke6 »

The Lowser doc specifies that pressing START should exit from the current running script. This doesn't seem to work for me (using Lowser 0.5). Any clues? Thanks.
SnowSurfer
Posts: 21
Joined: Fri Jul 08, 2005 2:59 am

Post by SnowSurfer »

how do i get a timer to work so it counts down 60seconds on an interval of 1 second at a time?

the code im using just counts down really really really fast..

any ideas? thanks again :)
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

SnowSurfer wrote:how do i get a timer to work so it counts down 60seconds on an interval of 1 second at a time?

the code im using just counts down really really really fast..

any ideas? thanks again :)
waitVblankStart has an optional parameter and since the VSync frequency on PSP is 60 Hz, you can use waitVblankStart(60) for 1 second delay.

I know, it should be better documented, but someone wrote me, that he is already working at a small tutorial and I'll setup a dedicated domain with forum etc. for Lua Player, when I have some time (I want to use it for my own games on PC, too).
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

27Bstroke6 wrote:The Lowser doc specifies that pressing START should exit from the current running script. This doesn't seem to work for me (using Lowser 0.5). Any clues? Thanks.
Where does it say that? You can do it manually, however, by breaking out of your main loop like so:

Code: Select all

while true do
    ... (your app code)
    if isCtrlStart(pad) then-- assumes that you have done pad = ctrlRead()
        break
    end
end
---------------------------
SnowSurfer wrote:how do i get a timer to work so it counts down 60seconds on an interval of 1 second at a time?

the code im using just counts down really really really fast..

any ideas? thanks again :)
From the documentation:
Documentation wrote:void waitVblankStart([int count])

Wait for next Vblank start. If you specify a count parameter, it waits multiple times for Vblank start. This can be used for delays, for example 60 for a one seconds delay.
Laurens
Posts: 14
Joined: Tue Jun 28, 2005 10:26 pm

Post by Laurens »

You could use

void waitVblankStart(60) - this should wait 1 second.
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.
Nils
Posts: 16
Joined: Wed Aug 03, 2005 2:27 pm

Post by Nils »

Great work Shine on the Lua player :)
I started to toy around with it, even if documentation on lua.org website is really bad.
Development is easy, but one looses too much time sending to psp / testing / reconnecting psp resending...

I ended up testing bits of my code on weblua (http://doris.sourceforge.net/lua/weblua.php) in order to have a quick small debuger.

I wondered, and i saw it has been asked already, if you would include a rotation feature for png ? Like the Flash one, object._rotation = angle. A handy feature ...

I'll port i guess one of my Flash games to Lua. I talked a bit with VgSlag, and it seems that Lua for the PSP is kinda the "Flash" of the psp, in many aspects. Lua is fast enough on the PSP to let us do virtually any 2D games.

Keep up the good work !
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Sound and music

Post by nevyn »

I've ported Jim Shaw's port of mikmod for use with LuaPlayer. With this, any mod file (xm, s3m, mod, mad, ...) can be played as background music, and any wav file can be played as a sound effect (with stereo panning, changeable frequency and volume).

There's a major bug in it now though, that disables the playing of wav files. If you want to try out just the music part, or if you want to help with the bug, here's the modified luaplayer code (with compiled eboot):
http://ncoder.nevyn.nu/psp/LuaPlayer_mikmod_TEST.zip
Bug description in KNOWN-BUGS. If you want to compile, read "README.linking-with-mikmod". If you want to hear a good tune, install luaplayer and luaplayer% on your psp and launch Music Test from Lowser.
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Re: Sound and music

Post by Kinsman »

nevyn wrote:I've ported Jim Shaw's port of mikmod for use with LuaPlayer. With this, any mod file (xm, s3m, mod, mad, ...) can be played as background music, and any wav file can be played as a sound effect (with stereo panning, changeable frequency and volume).

There's a major bug in it now though, that disables the playing of wav files.
Cool! I went and set the Pyramid Panic demo to some music :)

I think I see the problem of the sound bug. When Shine set up his image handles, he didn't use the value of the pointer as his handle - instead he wrapped the image in an array of 'Image' structs and used the index of the array as his handle. Try setting up something similar for sounds and see what happens.
SnowSurfer
Posts: 21
Joined: Fri Jul 08, 2005 2:59 am

Post by SnowSurfer »

hmm im trying to put a counter on my game so it starts at 60 seconds and when it goes down to zero the game is over.

heres what i have so far (at least i think this is how it should work)
timerout=0 (this is for the display on the screen to show how much time is left)
timer=60 (main timer)
while timerout != 0 (not sure how to write not equals)
void waitVblankStart(timer)
timerout=timer-1
printText(100, 50, "Timer: " .. timerout, red)
waitVblankStart()
flipScreen()
any ideas?
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

Snow:

Relational expressions
Relational operators are supplied which return the boolean values true or false.

== equal to
~= not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to

This came from:
http://lua-users.org/wiki/ExpressionsTutorial

Kins:

Cool, I've already got some sound fx and eery music that a friend made for me for the Flash version of Pyramid Panic.

Shine:

Will nevyn's port of milkmod get put into the offical player?
Last edited by VgSlag on Thu Aug 04, 2005 8:09 am, edited 1 time in total.
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Post by Kinsman »

VgSlag wrote: Shine:

Will kins port of milkmod get put into the offical player?
nevyn's :)
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

Sorry, my mistake, will edit the original;

Snow:

Code: Select all

timerout=0
timer=60
red = getColorNumber&#40;255, 0, 0&#41; 
while timerout < 60 do
	waitVblankStart&#40;60&#41; 
	timerout=timerout+1 
	clear&#40;0&#41;;
	printText&#40;100, 50, "Timer&#58; " .. timerout, red&#41; 
	flipScreen&#40;&#41; 
end
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Re: Sound and music

Post by nevyn »

Kinsman wrote:
nevyn wrote:I've ported Jim Shaw's port of mikmod for use with LuaPlayer. With this, any mod file (xm, s3m, mod, mad, ...) can be played as background music, and any wav file can be played as a sound effect (with stereo panning, changeable frequency and volume).

There's a major bug in it now though, that disables the playing of wav files.
Cool! I went and set the Pyramid Panic demo to some music :)

I think I see the problem of the sound bug. When Shine set up his image handles, he didn't use the value of the pointer as his handle - instead he wrapped the image in an array of 'Image' structs and used the index of the array as his handle. Try setting up something similar for sounds and see what happens.
They're both numbers. I don't see what the difference is. Anyhow, I tried it at least, but it doesn't work. soundfile is /still/ being reported as a nil value. I just don't get it.

The sound is definitely loaded, I can see the ms light flash for a second, and no errors are reported from anywhere. Lua keeps getting a nil value even though I'm explicitly pushing a number.

Now that I think about it though, I have never... Oh holy CRAP what a stupid mistake. Perhaps if I read the manual now and then...
You have to return the number of arguments that you have pushed as the function return value. D'OH! I thought that stuff was automatic. Now that's working. I have to fix some new bugs, then it's ready to go.
SnowSurfer
Posts: 21
Joined: Fri Jul 08, 2005 2:59 am

Post by SnowSurfer »

thanks vg, i got the timer to work i just need to be able to get everything else to show up on the screen at the same time...

what exactly is a vblank start? could someone explain it to me, like can it run in the background when other program functions are running?

the timer will run in its own function but when i start the function in my main program code or in my intialization code it wont go to the program until after the amount of time. i wanted the timer to be able to be used as a timer for the game. ill play with it some more. i also tried to write the main function as

while timerout > 0 do

(main program code)

waitVblankStart(60)
end
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

LuaPlayer with Mikmod done!

Post by nevyn »

Hooray! It works! Music, sounds, panning, frequencies, everything :)

Check out the package:
http://ncoder.nevyn.nu/psp/LuaPlayer_mikmod.zip

Binary "nice" package:
http://ncoder.nevyn.nu/Lowser/Lowser_bundle_0.12.zip

Interface:

Code: Select all

loadAndPlayMusicFile&#40;filename, bool loop&#41;
stopAndUnloadMusic&#40;&#41;
Sound loadSound&#40;filename&#41; - ONLY MONO, stereo will crash your PSP
unloadSound&#40;sound&#41;
Voice playSound&#40;sound&#41;
stopSound&#40;voice&#41;
setVoiceVolume&#40;voice&#41; - 0-255
setVoicePanning&#40;voice&#41; - 0-255, 128 is center
setVoiceFrequency&#40;voice&#41;, 0-44000
bool musicIsPlaying&#40;&#41;
bool voiceIsPlaying&#40;voice&#41;
Example in luaplayer/Applications/Music Test/index.lua
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Re: LuaPlayer with Mikmod done!

Post by Kinsman »

nevyn wrote:Hooray! It works! Music, sounds, panning, frequencies, everything :)
So far, so good. I added Mario jumping noises to the Pyramid Panic demo :)

The sound is playing awfully quietly. I don't think it's a library problem, since you're using a sample-playing function, and the background music is drowning out the sound effects.

When you play the sound effect, I see you're setting the panning straight away - would setting the volume straight away have an effect?

Also, where can I find a copy of the mikmod library? I can't seem to find it in PSPSDK, or in the toolchain.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Re: LuaPlayer with Mikmod done!

Post by nevyn »

Kinsman wrote:
nevyn wrote:Hooray! It works! Music, sounds, panning, frequencies, everything :)
So far, so good. I added Mario jumping noises to the Pyramid Panic demo :)

The sound is playing awfully quietly. I don't think it's a library problem, since you're using a sample-playing function, and the background music is drowning out the sound effects.

When you play the sound effect, I see you're setting the panning straight away - would setting the volume straight away have an effect?

Also, where can I find a copy of the mikmod library? I can't seem to find it in PSPSDK, or in the toolchain.
Hmm. In my Music Test, I set the volume to 255 when I start the sample. You're right, that sample is playing pretty quietly... I could provide a function to lower the music volume. Yeah, I think I'll add that... Check back in an hour.

As for the mikmod library, see
http://forums.ps2dev.org/viewtopic.php?t=2540
and
http://ncoder.nevyn.nu/psp/mikmodlib.zip (ugly repack)
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Re: LuaPlayer with Mikmod done!

Post by Kinsman »

I'm about to head for bed, but I hunted through the mikmod source code and found something in mdriver.c, lines 26-28:

Code: Select all

UBYTE md_volume         = 96;       /* Global sound volume &#40;0-128&#41; */
UBYTE md_musicvolume    = 128;      /* volume of song */
UBYTE md_sndfxvolume    = 128;      /* volume of sound effects */
Maybe you can fiddle with the global variables - turn up the master volume a bit, then turn down the music volume until it sounds about right compared to the sound effects.

I expected to see md_musicvolume turned up much higher than md_sndfxvolume based on the behaviour I was seeing, but oh well.

I don't think it'd be good to have the sound quiet all around - players would have to turn their PSP volume up to hear a Lua game, then turn it down again when moving to something else..
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Re: LuaPlayer with Mikmod done!

Post by nevyn »

Kinsman wrote:I'm about to head for bed, but I hunted through the mikmod source code and found something in mdriver.c, lines 26-28:

Code: Select all

UBYTE md_volume         = 96;       /* Global sound volume &#40;0-128&#41; */
UBYTE md_musicvolume    = 128;      /* volume of song */
UBYTE md_sndfxvolume    = 128;      /* volume of sound effects */
Maybe you can fiddle with the global variables - turn up the master volume a bit, then turn down the music volume until it sounds about right compared to the sound effects.

I expected to see md_musicvolume turned up much higher than md_sndfxvolume based on the behaviour I was seeing, but oh well.

I don't think it'd be good to have the sound quiet all around - players would have to turn their PSP volume up to hear a Lua game, then turn it down again when moving to something else..
One step ahead of you ;)

http://ncoder.nevyn.nu/psp/LuaPlayer_mikmod.zip
http://ncoder.nevyn.nu/lowser/Lowser_bundle_0.12.zip

Both are updated with the following lua functions:

setMusicVolume(arg) -- 0-128
setSFXVolume(arg) -- 0-128
setReverb(arg) -- 0-15 ( 0 = no reverb)
setPanSep(arg) -- 0-128 ( 0 = mono, 128 = full separation)


I have also changed the initial volume values:
md_volume = 128;
md_musicvolume = 96;
md_sndfxvolume = 128;
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Re: LuaPlayer with Mikmod done!

Post by Kinsman »

Tried it out - got an error; 'tried to reference setGlobalVolume (a nil value)'.

Not sure what it could be, and don't have time at the moment to check..
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Re: LuaPlayer with Mikmod done!

Post by nevyn »

Kinsman wrote:Tried it out - got an error; 'tried to reference setGlobalVolume (a nil value)'.

Not sure what it could be, and don't have time at the moment to check..
There is no such function, "setGlobalVolume"... Only setMusicVolume and setSFXVolume. I don't see the reason for setting the mikmod global volume programatically; there's the psp global volume that the user can adjust him/herself.
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

nevyn, have you spoke to shine abou tadding this to the official release?
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

VgSlag wrote:nevyn, have you spoke to shine abou tadding this to the official release?
Yeah, it'll be added to the official release. Oobles mailed me and gave me cvn commit access! So if it's okay with Shine, I'll be adding it myself :)
SnowSurfer
Posts: 21
Joined: Fri Jul 08, 2005 2:59 am

Post by SnowSurfer »

is there anyway that i can have two different functions running at the same time such as my timer needs to be running (and counting down) while the game is being played..

if i put it in a new function and call it, the game wont show up.

if i put it in the main game code it will just hang on the timer until the time is up.
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

nevyn, that's brilliant news!

I bought some sounds for the phone version of my game and my friend that does music made me some.

I'm going to source or make a jumping sound and add some rooms over the weekend. Will up a new version on Sunday.

Will all functionality remain the same when it gets added to the official version?
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

SnowSurfer wrote:is there anyway that i can have two different functions running at the same time such as my timer needs to be running (and counting down) while the game is being played..

if i put it in a new function and call it, the game wont show up.

if i put it in the main game code it will just hang on the timer until the time is up.


There are two ways of doing stuff simultaneously. Either you do it little-by-little in the main loop, or you thread it. The first one is way simpler.

Code: Select all

timeout = 0
while timeout < &#40;60 * 60&#41; do -- 60 seconds times framerate
    timeout = timeout + 1
    clear&#40;0&#41;
    printText&#40;100,50,"Timer&#58; ".. 60 - timeout/60, red&#41;
    &#91; anything else your app would want to do in this frame &#93;
    waitVblankStart&#40;&#41;
    flipScreen&#40;&#41;
end
Threads in Lua is called coroutines, but those are probably way out of your league...
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

VgSlag wrote:nevyn, that's brilliant news!

I bought some sounds for the phone version of my game and my friend that does music made me some.

I'm going to source or make a jumping sound and add some rooms over the weekend. Will up a new version on Sunday.

Will all functionality remain the same when it gets added to the official version?
Looking forward to the new version of your game!

I think the interface is all okay, I don't know what Shine thinks of it though. If I were to add it now it'd be identical, except for one thing: the freeSound() doesn't belong in lua since it's a garbage collected environment and shouldn't be needed. I'll have to read up on garbage collection to fix that, though... For now, just never mind freeSound() and be content that theoretically, your sound will be automatically freed sometime.
SnowSurfer
Posts: 21
Joined: Fri Jul 08, 2005 2:59 am

Post by SnowSurfer »

nevyn im reading about coroutines in the wiki right now

it is...interesting to say the least
http://lua-users.org/wiki/CoroutinesTutorial

i am going to try what you said when i get home from breakfast, thanks for the help.

edit: yeahhhhhhhhhh! it works, thanks nevyn :)
Post Reply