Lua Player for PSP
Moderators: Shine, Insert_witty_name
edit: Oops. I pasted into the wrong window.
edit again: Aw crap, I pasted over the message I had already written here.
Egh. I had written that me and Shine concluded that keeping backwards-compatibility with the API isn't that important this early in the project, so we'll simply change the API. I'll get back to this subject later today...
edit again: Aw crap, I pasted over the message I had already written here.
Egh. I had written that me and Shine concluded that keeping backwards-compatibility with the API isn't that important this early in the project, so we'll simply change the API. I'll get back to this subject later today...
I did? Aw crap. Oh well. There'll be a new api by next version anyway...Kinsman wrote:The problem was actually with 'setMusicVolume', but it's probably because you forgot to release an updated EBOOT.PBP with the code or something.
Example with the new sound API, should be self-explainatory:
Code: Select all
Music.volume(96)
SoundSystem.SFXVolume(128) -- max
SoundSystem.reverb(4) -- out of 15
SoundSystem.panoramicSeparation(128) -- 0 is mono
Music.playFile("music.xm")
while Music.playing() do
print("A music file is playing.")
end
Music.playFile("music.xm", true) -- loops forever
local sndExplosion = Sound.load("explosion.wav")
voice = sndExplosion:play()
voice:volume(255) -- max volume
voice:frequency(11000) -- play at half speed
voice:pan(0) -- pan all the way to the left
while voice:playing() do
i = i + 1
voice:pan(i)
waitVblankStart(5)
end
-- note that the voice has stopped playing now, and is invalid.
voice = sndExplosion:play()
voice:stop()
Music.stop()
Last edited by nevyn on Sun Aug 07, 2005 12:03 am, edited 1 time in total.
Is anyone seeing an odd image bug when moving an image off the left hand side of the screen?
I haven't tested any other scenarios but what I have is my BG being blitted to screen then blitting and alpha image (16 * 16) on top.
When the character moves off the left hand side of the screen the image appears to stop moving but the right hand side starts cutting off like it is moving off screen jsut not updating the image.
The only file I have to show this is my "Pyramid Panic" game, but it's in the middle of being worked on, so if you do look at it in this file you may get crashes or unexpected results.
To see it move right, and slowly onto the next screen. If you were slow enough then you'll see the character is half missing.
Move right then slowly move left onto the first screen again, you'll see it there.
Any ideas? Can this be fixed?
My game is here:
http://www.flash-git.net/pyramidPanic.rar
I haven't tested any other scenarios but what I have is my BG being blitted to screen then blitting and alpha image (16 * 16) on top.
When the character moves off the left hand side of the screen the image appears to stop moving but the right hand side starts cutting off like it is moving off screen jsut not updating the image.
The only file I have to show this is my "Pyramid Panic" game, but it's in the middle of being worked on, so if you do look at it in this file you may get crashes or unexpected results.
To see it move right, and slowly onto the next screen. If you were slow enough then you'll see the character is half missing.
Move right then slowly move left onto the first screen again, you'll see it there.
Any ideas? Can this be fixed?
My game is here:
http://www.flash-git.net/pyramidPanic.rar
OK. I have the latest svn of everything - luaplayer, zlib, libpng, mikmodlib, and lua. But when I try to make luaplayer it gives me all sorts of errors in liblualib.a:
Code: Select all
<somefile.c>:(.text+<some offset>): relocation truncated to fit: R_MIPS_GPREL16 against '_i
mpure_ptr'
You need the latest psp toolchain from SVN. Checkout psptoolchain and update your environment with the toochain.sh shell script. The current Lua Player from SVN works for me, but it is not ready for release, so be patient.Soban wrote:OK. I have the latest svn of everything - luaplayer, zlib, libpng, mikmodlib, and lua. But when I try to make luaplayer it gives me all sorts of errors in liblualib.a:
Haven't checked the game, but I ran into a similar-sounding issue on my own project. You can't just say you want to draw an image at, for example, (-10,30), and expect it to work, since the Lua Player goes through a bitmap adjusting step where it does bound checking on what it's going to draw. Try using blitAlphaImageRect() for the chases that your images are going to go off-screen, and clip it yourself.VgSlag wrote:Is anyone seeing an odd image bug when moving an image off the left hand side of the screen?
I haven't tested any other scenarios but what I have is my BG being blitted to screen then blitting and alpha image (16 * 16) on top.
When the character moves off the left hand side of the screen the image appears to stop moving but the right hand side starts cutting off like it is moving off screen jsut not updating the image.
The only file I have to show this is my "Pyramid Panic" game, but it's in the middle of being worked on, so if you do look at it in this file you may get crashes or unexpected results.
To see it move right, and slowly onto the next screen. If you were slow enough then you'll see the character is half missing.
Move right then slowly move left onto the first screen again, you'll see it there.
Any ideas? Can this be fixed?
Looks like posts picked up again after a rest of a day or so :)
Here's a screenshot of what I'm working on: a 'digital novel' engine, and an engine that could be used for any console-style text game - or a text game mixed with inline graphics.
Ignore the mediocre script and art :) I just made up something off the cuff..
Here's a screenshot of what I'm working on: a 'digital novel' engine, and an engine that could be used for any console-style text game - or a text game mixed with inline graphics.
Ignore the mediocre script and art :) I just made up something off the cuff..
I've fixed the bug, I hope now everything is ok, perhaps someone can verify, if it is correct for every boundary case:Kinsman wrote:Haven't checked the game, but I ran into a similar-sounding issue on my own project. You can't just say you want to draw an image at, for example, (-10,30), and expect it to work, since the Lua Player goes through a bitmap adjusting step where it does bound checking on what it's going to draw. Try using blitAlphaImageRect() for the chases that your images are going to go off-screen, and clip it yourself.
Code: Select all
// returns 0, if nothing to blit
static int adjustBlitRectangle(
int sourceWidth, int sourceHeight,
int destinationWidth, int destinationHeight,
int* sx, int* sy,
int* width, int* height,
int* dx, int* dy)
{
if (*width <= 0 || *height <= 0) return 0; // zero area, nothing to blit
if (*sx < 0 || *sy < 0) return 0; // illegal, source is not clipped
if (*dx < 0) {
*width += *dx;
if (*width <= 0) return 0;
*sx -= *dx;
*dx = 0;
if (*sx >= destinationWidth) return 0;
}
if (*dy < 0) {
*height += *dy;
if (*height <= 0) return 0;
*sy -= *dy;
*dy = 0;
if (*sy >= destinationHeight) return 0;
}
if (*dx + *width > destinationWidth) {
*width = destinationWidth - *dx;
if (*width <= 0) return 0;
}
if (*dy + *height > destinationHeight) {
*height = destinationHeight - *dy;
if (*height <= 0) return 0;
}
return 1;
}
I've tested it with a small program, where you can move a mandelbrot fractal, which is calculated by the program:
Code: Select all
-- create mandelbrot fractal
w = 50
h = 50
image = createImage(w, h)
for x=0,w-1 do
for y=0,h-1 do
r = 0; n = 0; b = x / w * 3 - 2; e = y / h * 2 - 1; i = 31
while i > 0 and r * r < 4 do
d = r; r = r * r - n * n + b; n = 2 * d * n + e; i = i - 1
end
color = math.mod(i * 43, 32)
putPixel(color * 1024 + color * 32, x, y, image)
end
end
-- move
x = 200
y = 100
while true do
pad = ctrlRead()
if isCtrlUp(pad) then
y = y - 3
elseif isCtrlDown(pad) then
y = y + 3
elseif isCtrlLeft(pad) then
x = x - 3
elseif isCtrlRight(pad) then
x = x + 3
end
clear(0)
blitImage(x, y, image)
waitVblankStart()
flipScreen()
end
I just ran the toolchain and recompiled lua itself, and now luaplayer compiles fine. I have no idea what changed... svn didn't do anything to lua when I ran it and I just ran the toolchain friday, but whatever... For some reason it decided to work now...
Anyway, I'm starting a text editor in lua and c specifically for editing lua scripts. I suppose you could call it a lua IDE. Right now the only special features I'm planning to add are a second virtual keyboard for lua commands and auto-indenting and coloring of functions, vars, reserved words, etc. but if anyone has any suggestions, I'm open.
I probably won't get much done on it this week with family over from cali and work and all, but I'll be working hard on it next week.
Anyway, I'm starting a text editor in lua and c specifically for editing lua scripts. I suppose you could call it a lua IDE. Right now the only special features I'm planning to add are a second virtual keyboard for lua commands and auto-indenting and coloring of functions, vars, reserved words, etc. but if anyone has any suggestions, I'm open.
I probably won't get much done on it this week with family over from cali and work and all, but I'll be working hard on it next week.
"lua and c"? Why not just lua?Soban wrote:I just ran the toolchain and recompiled lua itself, and now luaplayer compiles fine. I have no idea what changed... svn didn't do anything to lua when I ran it and I just ran the toolchain friday, but whatever... For some reason it decided to work now...
Anyway, I'm starting a text editor in lua and c specifically for editing lua scripts. I suppose you could call it a lua IDE. Right now the only special features I'm planning to add are a second virtual keyboard for lua commands and auto-indenting and coloring of functions, vars, reserved words, etc. but if anyone has any suggestions, I'm open.
I probably won't get much done on it this week with family over from cali and work and all, but I'll be working hard on it next week.
I'm planning on writing an event-driven application framework for Lua after LuaPlayer 0.7 is done. That should probably make application writing very much easier. (it will probably take some time though...) (I'll be designing it to resemble the Cocoa framework)
It's not in svn yet, I'm still working hard on the new API... I'm getting there, give me one more day...VgSlag wrote:Thanks Shine, I'll check the latest compiled version with my game and see if it's fixed.Shine wrote: I've fixed the bug, I hope now everything is ok, perhaps someone can verify, if it is correct for every boundary case:
Point ;)Soban wrote:Because I've barely done any programming on the PSP and I want to mess with it :D .nevyn wrote:"lua and c"? Why not just lua?
The problem is, you can't bundle c with lua, so it would need a custom build of luaplayer...
otoh, if you write useful reusable code, it could of course be merged with the real luaplayer sources :)
-
- Posts: 116
- Joined: Mon Jul 18, 2005 2:20 am
Well... Here's my page with Dr. Mario coded in Lua:
http://haggar.pocketheaven.com/
Prolly some of the worst code you'll ever see though ;)
http://haggar.pocketheaven.com/
Prolly some of the worst code you'll ever see though ;)
Ohyeah! Excellent job! How long did it take to write?MikeHaggar wrote:Well... Here's my page with Dr. Mario coded in Lua:
http://haggar.pocketheaven.com/
Prolly some of the worst code you'll ever see though ;)
Oh, as long as it works it doesn't matter what the code lo-- holy /crap/! One thousand lines of Lua? That's... That's... You were right, that code ain't too pretty :P I'm impressed that you got it working! (that's actually a compliment :P)
-
- Posts: 116
- Joined: Mon Jul 18, 2005 2:20 am
Nice game. The code is not so bad, but you can shorten it a bit, for example if you use a table for indexing the image for drawing with drawPillTile, so you don't need the long if-elseif-end statement any more. And you could use some more verbose names instead of just indexes (in Lua you can index the tables, like you've done with the red/yellow/blue tables). Nested tables and prototype based classes are possible, too.MikeHaggar wrote:Well... Here's my page with Dr. Mario coded in Lua:
http://haggar.pocketheaven.com/
Prolly some of the worst code you'll ever see though ;)
And you should use the screenshot function instead of a digital camera, but you can use the picture below.
-
- Posts: 116
- Joined: Mon Jul 18, 2005 2:20 am
for the stuff in the drawFullPill() function you mean, or the stuff in drawMap()?Shine wrote:The code is not so bad, but you can shorten it a bit, for example if you use a table for indexing the image for drawing with drawPillTile, so you don't need the long if-elseif-end statement any more.
Whoops! Forgot all about the screenshot function. I'll use your pic instead of my crappy digicam ones ;)
I'll fix that other pic tomorrow... Time for sleep... 00:30 here now...
For those of you who are writing an IDE for Lua, check out some of the features this editor has: http://www.wowguru.com/ui/wow-scite-lua/
It was made for World of Warcraft Lua scripting, but it works great for editing my PSP Lua scripts. It's based off SciTe.
While debugging on the PC would speed up the development process, having an enviornment to do realtime debugging on the PSP itself would be much more beneficial. I downloaded nevyn's last build and the 'press any key to restart' is a great help, but what we really need to do is map a function in Lua to activate the USB port. Then the script.lua file can be modified while Lua Player is running, and a key sequence can be used to restart the game.
This should be all we need as far as the drivers go... But how can it be made into a function accessible in Lua?
From the USB Sample
It was made for World of Warcraft Lua scripting, but it works great for editing my PSP Lua scripts. It's based off SciTe.
While debugging on the PC would speed up the development process, having an enviornment to do realtime debugging on the PSP itself would be much more beneficial. I downloaded nevyn's last build and the 'press any key to restart' is a great help, but what we really need to do is map a function in Lua to activate the USB port. Then the script.lua file can be modified while Lua Player is running, and a key sequence can be used to restart the game.
This should be all we need as far as the drivers go... But how can it be made into a function accessible in Lua?
Code: Select all
//start necessary drivers
LoadStartModule("flash0:/kd/semawm.prx");
LoadStartModule("flash0:/kd/usbstor.prx");
LoadStartModule("flash0:/kd/usbstormgr.prx");
LoadStartModule("flash0:/kd/usbstorms.prx");
LoadStartModule("flash0:/kd/usbstorboot.prx");
//setup USB drivers
retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Bus driver (0x%08X)\n", retVal);
sceKernelSleepThread();
}
retVal = sceUsbStart(PSP_USBSTOR_DRIVERNAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Mass Storage driver (0x%08X)\n",
retVal);
sceKernelSleepThread();
}
retVal = sceUsbstorBootSetCapacity(0x800000);
if (retVal != 0) {
printf
("Error setting capacity with USB Mass Storage driver (0x%08X)\n",
retVal);
sceKernelSleepThread();
}
retVal = 0;
-- BIG UPDATE --
The new version of LuaPlayer, 0.7b5, is ready for testing. It has an ENTIRE NEW API, so old apps will NOT be compatible without rewriting. It is entirely possible to write a wrapper library (defining functions with the old names calling functions with the new names), but I'm not going to do it myself...
New in 0.7 (from 0.6):
- Sound and music through Mikmodlib
- Analog stick is fully functional
- Objects garbage collect
- The API is completely redesigned.
I hope people are willing to test the API a little before it's released in binary form... And plus, I have to rewrite Lowser first, too... So, anyone who wants to try it out, update from svn and build. The luaplayer folder (into which a 'make kxploit' will create a binary) contains an example.
The new API:
New in 0.7 (from 0.6):
- Sound and music through Mikmodlib
- Analog stick is fully functional
- Objects garbage collect
- The API is completely redesigned.
I hope people are willing to test the API a little before it's released in binary form... And plus, I have to rewrite Lowser first, too... So, anyone who wants to try it out, update from svn and build. The luaplayer folder (into which a 'make kxploit' will create a binary) contains an example.
The new API:
Code: Select all
Graphics
========================================
Image Image.createEmpty(width, height)
Image Image.load( filename )
nil image:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])
nil image:clear([color = white])
nil image:fillRect(x, y, width, height, [color = black])
nil image:drawLine(x0, y0, x1, y1, [color = black])
Color image:pixel(x, y) --get
nil image:pixel(x, y, Color) --set
nil image:print(x, y, text, [color = black])
Number image:width()
Number image:height()
nil Image:save( filename )
global Image screen
nil screen.flip() -- note the small s; this is a function of the screen
nil screen.waitVblankStart([count])
Color Color.new(r, g, b, [a])
table[r,g,b,a] color:colors()
Bool (Color a == Color b)
Controls
========================================
Controls Controls.read()
Bool controls:select()
Bool controls:start()
Bool controls:up()
Bool controls:right()
Bool controls:down()
Bool controls:left()
Bool controls:l()
Bool controls:r()
Bool controls:triangle()
Bool controls:circle()
Bool controls:cross()
Bool controls:square()
Bool controls:home()
Bool controls:hold()
Bool controls:note()
Number controls:analogX() -- ranges from -127 to 128.
Number controls:analogY() -- same
Bool (Controls a == Controls b) -- note! The analog stick is NOT considered when comparing because of analog fluctuations.
System
========================================
String System.currentDirectory() -- get
String System.currentDirectory( path ) -- set, returns old path.
table System.listDirectory()
table System.listDirectory( path )
Sound and music
========================================
nil Music.playFile( string file, bool loop )
nil Music.stop()
bool Music.playing()
nil Music.volume( number {0-128} )
nil SoundSystem.SFXVolume( number {0-128} )
nil SoundSystem.reverb( number {0-15} )
nil SoundSystem.panoramicSeparation( number {0-128} )
Sound Sound.load(filename)
Voice sound:play()
nil voice:stop()
nil voice:volume( number [0-25] )
nil voice:pan( number [0-255] )
nil voice:frequency( number [0-255] )
bool voice:playing()
Re: -- BIG UPDATE --
This is difficult for many people without a psptoolchain, so I've built a binary release, but I'll announce it on my webpage later, when the new API is more stable and Nevyn has ported Lowser. The other scripts in the samples directory are ported, including Snake, now with some background music and effect sounds. And there are 2 new functions for activating and deactivating USB. Together with Lowser, the turnaround-time for uploading and testing a new script could be really fast now.nevyn wrote:I hope people are willing to test the API a little before it's released in binary form...