PDA

View Full Version : KohKae Engine



PSmonkey
June 8th, 2006, 05:08
Ok, kind of posting early but some already know i'm working on it.

Anyways i realised a need for a reasonable engine for the psp that could be used to make projects in days not weeks. Everybody knows i've starting a new 3d beat-em up game but actualy i have not really coded anything still since it would be a mess to use Iris in its current forum.

I know I am posting this a little early but I just recently started work this week and have started to put alot of focus behind it. The engine is going to be open source from the start. I plan to start posting some stuff soon in here. I would hopefuly like to see other coders contribute (but sadly atm there is only 1 other coder in atlantis besides me).

Anyways here is a simple cube example i'm using to build the engine. The vertex list is actualy just the cube list from the pspsdk cube demo.


int main(int argc, char* argv[])
{
//* Register Callbacks
SystemInitCallbacks();

//* Init Input
SystemInitInput();

//* Init Display
SystemInitDisplay();

int val = 0;
TGAImage myImage[2];
ObjectMesh myCube;

//* Setup Texture
TGALoadImage( &myImage[0], "./Art/mario_floor.tga" );
TGALoadImage( &myImage[1], "./Art/mario_bg.tga" );

//* Setup Mesh
myCube.SetPrimitiveType( GU_TRIANGLES );
myCube.SetVertexType( GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|G U_TRANSFORM_3D );
myCube.LoadVertexs( vertices, 12*3, false );
myCube.SetPosition( 0, 0, -2.5f );

//* Validate an image was loaded
if( myImage[0].pImageData && myImage[1].pImageData )
{
myCube.SetRenderStages( myImage, 2 );
myCube.SetBlendMode( GU_ADD, GU_SRC_COLOR, GU_FIX, 0, 0x9f9f9f9f );
}

while( 1 )
{
SystemStartFrame();

// setup matrices for cube
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();

myCube.SetRotation( val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) );

// draw cube
myCube.SetPosition( -5.0f, 0, -5.5f );
myCube.Render();

myCube.SetPosition( 5.0f, 0, -5.5f );
myCube.Render();

SystemEndFrame();

val++;
}

sceGuTerm();

sceKernelExitGame();
return 0;
}

As you can see above. Loading a simple TGA image is very simple as is applying 2 textures to a single geometry object. There is still much i'm trying to improve & as well make more flexable with out making things more complicated.

-- Small note --
So what is KohKae? Koh-Kae are a coated penut snack. Quite often found in asian markets. They are sadly tooo good to put down. :( I pretty much down a can at work in 3 days (stress at work don't help).

http://www.koh-kae.com/kohkae.htm

AnonymousTipster
June 8th, 2006, 08:35
Sounds like a good project. Especially if you're going to make it open source. I know a lot of people want to get into 3D programming, but find it very daunting; a good engine could smooth the transition.
Personally, I prefer to use the .png format over .tga as it is smaller and I can save translucent .pngs (32-bit tga is only possible in Photoshop....which I don't have v_v )
In the future I'd like to see support for 2D stuff as well, for HUDs and possibly flib for font rendering too.

I think I've tried Koh-Kae before - they're quite nice.

In unrelated talk: Does the VFPU require 1.5, or can it be used in 2.0+?

DPyro
June 8th, 2006, 13:51
Lol I was wondering why I saw a folder named KohKae. For some reason though, the stupid make file don't work :(

PSmonkey
June 8th, 2006, 15:59
Sounds like a good project. Especially if you're going to make it open source. I know a lot of people want to get into 3D programming, but find it very daunting; a good engine could smooth the transition.
Personally, I prefer to use the .png format over .tga as it is smaller and I can save translucent .pngs (32-bit tga is only possible in Photoshop....which I don't have v_v )
In the future I'd like to see support for 2D stuff as well, for HUDs and possibly flib for font rendering too.

I think I've tried Koh-Kae before - they're quite nice.

In unrelated talk: Does the VFPU require 1.5, or can it be used in 2.0+?

Thats actualy another big reason I am doing this. So few are actualy trying to do something 3d on the psp. I want to make something that is simple for them to start with yet flexable enough they can accomplish things even far greater then my iris game.

Regarding images. I just threw in TGA suport so I could have textures running with in a few hours. I am actualy going to rewrite a small base class for textures. So then anybody can write a main class for the prefered texture format and not have to worrie about it plugging into object classes. So eventualy the engine will be able to suport an array of formats ( in the near future I will add BMP & either PNG or JPG ).

Regarding VFPU. Actualy my last public release of m64 used the VFPU GUM functions & nobody seem to have issues with it. So VFPU should work on any psp unit.

--edit--
One more note. I do plan to add in a clipping system so people wont have to worrie about this issue.

AnonymousTipster
June 8th, 2006, 18:13
What are you going to do about loading models? It would be nice to have support for a generic format like ascii .obj rather than exporting it via Maya to some odd format.

PSmonkey
June 8th, 2006, 18:24
Actualy I want to suport a few formats. I plan to add simple game formats as well like MD2 so people can use character models off the net, but I also want to try adding in things like max, waveformat obj, and other general formats.

Pretty much want to add every thing I posibly can that would make development easier on a person.

--edit--
I heavly want to get a format in that uses bones as well.

So there will be suport for both static meshes (world geometry) & Animated meshes (characters, interactive objects, ...).

AnonymousTipster
June 8th, 2006, 19:32
Sounds cool. A lot of work though.
Good luck ^_^

PSmonkey
June 8th, 2006, 19:34
Yep :)

I heavly look forward to when i add ODE tho.

AnonymousTipster
June 8th, 2006, 19:43
Yeah, including the physics engine is a great part. It reverts you back to the mental age of a child though - all you want to do is throw blocks around! ^_^
If you want the source to ThrottleX 0.2 then I can send it you, but it's not much help for anything other than car physics - the codes a mess. It's a little cleaner in 0.3, but it's a little more unstable due to the Editor code added in.
My ODE sample is floating around the ps2dev.org forums somewhere, which is better to get a quick ODE environment set up.

PSmonkey
June 8th, 2006, 20:22
Yeah, including the physics engine is a great part. It reverts you back to the mental age of a child though - all you want to do is throw blocks around! ^_^
If you want the source to ThrottleX 0.2 then I can send it you, but it's not much help for anything other than car physics - the codes a mess. It's a little cleaner in 0.3, but it's a little more unstable due to the Editor code added in.
My ODE sample is floating around the ps2dev.org forums somewhere, which is better to get a quick ODE environment set up.

sure if you dont mind. I actualy have your ODE port at the moment. Just need more time to get though stuff before I add it in.

--edit--
Actualy attached below is the current engine. It's still in a very early state since I only just started on it this week and only have put in a good 4-6 hours so far.

AnonymousTipster
June 8th, 2006, 21:17
Well, your engine is definitely a good start, and still works even if you forget to copy the Art directory over (oops :p) It lags a little every now and then (looks like vis. lag), i'm assuming that this is because they're unswizzled RAM textures?

Here is the ThrottleX 0.2 source code:
--rm by monkey--
Please post when you've got it so I can remove the file from my server.
The makefile links lpng and lz, but I don't think these are needed for 0.2, so can be removed if you don't have the libs installed.
I hope you can extract some sort of usefullness out of it. Most physics stuff is labelled with 'physics' so just search for that.

Produkt
June 8th, 2006, 21:22
AT... would you be Interested in making an extention to ThrottleX?

have you heard of a game called track mania? its like throttleX but its based on a more fast paced idea.I'd be happy to do the levels.

If not, how about a racing game?

PSmonkey
June 8th, 2006, 21:36
Got it AT. Feel free to delete.

Yeah the lag is the textures. Its rendering two cubes both have 2 32bit textures (one is 32x32, other 256x128) in ram unswizzled. :P

I will fix that this weekend by adding in a memory manager for vram & add in the pspsdk fast swizzle command. :)

Actualy if you think about that math wise, it's easy to see how crazy it is.

its 2 6 sided cubes rendering a 16x16x4+256x128x4.

AnonymousTipster
June 8th, 2006, 21:43
AT... would you be Interested in making an extention to ThrottleX?

have you heard of a game called track mania? its like throttleX but its based on a more fast paced idea.I'd be happy to do the levels.

If not, how about a racing game?
I actually play TM:N a lot and have Sunrise too. I think it was a subconscious inspiration as the concept developed in my mind.
I have thought about doing a proper racing game, and I like the idea, but the engine needs tweaking and optimising first (still running at 333mhz). Also there's the issue of models. So far I've been too lazy to code an .obj loader, and ThrottleX (and any other 3D game) could really use one.
So, yes, I would like to do one, but not quite yet. I want to finish ThrottleX 0.3, and let people play with the editor, level downloads and high score tables for a bit. It may be an idea to code a racing game for KohKae once it's near completion.
I've also got that little project called Eclipse to work on too....oh, and there's a rhythm game idea stewing in my head too.

If only I could pause time for a bit ;)


EDIT: @Monkey
I thought it would be the textures, as the blended texture is very large for such as small cube. Something you'll almost certainly want to look into is support for CLUT textures. It reduces colour fidelity, but can quarter the space needed, meaning you can squeeze more into VRAM.
One other thing you may already know; don't swizzle if the texture is in VRAM - it actually slows it down.

PSmonkey
June 8th, 2006, 22:09
EDIT: @Monkey
I thought it would be the textures, as the blended texture is very large for such as small cube. Something you'll almost certainly want to look into is support for CLUT textures. It reduces colour fidelity, but can quarter the space needed, meaning you can squeeze more into VRAM.
One other thing you may already know; don't swizzle if the texture is in VRAM - it actually slows it down.

Yeah, Actualy on iris I cheated. I would generate a 256 color palette from the image. I was not pleased with the results so I plan to add in suport for images with palettes.

Also really the textures are examples for the time being (ripped from mario bros nes). I had them because as a sample for the engine I am building a small game that will kind of be like tower building with tetris style blocks. You will recieve a score based on the hight of your tower subtracted by the side of the base (smaller base = more points). The game ends as soon as the tower starts to fall down. I'm also going to luminies it by allowing people to add their own theme. :P

It's a simple concept that will weight heavly on the ODE. :)

AnonymousTipster
June 8th, 2006, 22:30
Have you played Bontago? It's a game a little like your idea, but more fleshed out. The physics were done with Tokamak, a physics engine I happened to be very fond of, until the creators stopped working on it. I rallied them round to start again about a year ago, but they're gone again. I'm pretty sure Tokamak will just fade away, but Bontago is worth a look: http://www.bontago.com/

PSmonkey
June 9th, 2006, 02:38
Have you played Bontago? It's a game a little like your idea, but more fleshed out. The physics were done with Tokamak, a physics engine I happened to be very fond of, until the creators stopped working on it. I rallied them round to start again about a year ago, but they're gone again. I'm pretty sure Tokamak will just fade away, but Bontago is worth a look: http://www.bontago.com/

Yeah, actualy that is where part of the concept comes from. The other half is partly from a PC game called "trembling towers" wich kind of adds a puzzle feel to it.

I'm more thinking something that is kind of both which is kind of like tetris/jenga. So kind of like bontago but you more get tetris style shapes fed to you at random and you just have to keep building up the best you can. Yet also borrowing some of the feel of trembling towers (ie its 2d play vs 3d play like bontago).

PSmonkey
July 19th, 2006, 18:32
Small update notes. I am planning a new sdk/src release in a few days. Mostly it will add md2 suport, view frustum clipping class, at3 player & if i can get it sorted in time a simple texture page manager.

Also thinking to add a simple sprite animation system where you just load a image, give dimentions and set how fast you wish to run the animation. Should make adding animated 2d objects much easier.

Again anybody here is free to use the engine providing they note in the about page that it's running on KohKae. Ultimatly later I will add in a splash screen callback that can be called anywhere in the game (either intro, menu or help) that will state its the kohkae engine and what version.

AnonymousTipster
July 19th, 2006, 19:52
Sounds like it's coming along nicely.
Are you planning on adding a BSP format or another format that could be used for worlds? I was thinking about if I were to do a racing game based on kohkae, it would need to be able to load a world as the track, and then overlay the physics onto that, probably via a different file. IE, you have map.bsp and map.phy which go together to form the track.

The sprite system sounds good, might I suggest an option to set target co-ordinates for the sprite? Say you have a menu which you want to slide onto the screen, which is at x:-100, if you set the target to x:0 and time to 1, it would automatically animate the sprite so that it ends up at x:0 after 1 second.

The other thing i'd like to see is a nice text renderer. At the moment, flib is good, but can't do real-time rendering, so you'd have to render all the glyphs to textures first.

Keep up the good work, and I might have a play with the engine once I've got some time away from my current projects.

PSmonkey
July 19th, 2006, 21:57
Sounds like it's coming along nicely.
Are you planning on adding a BSP format or another format that could be used for worlds? I was thinking about if I were to do a racing game based on kohkae, it would need to be able to load a world as the track, and then overlay the physics onto that, probably via a different file. IE, you have map.bsp and map.phy which go together to form the track.

The sprite system sounds good, might I suggest an option to set target co-ordinates for the sprite? Say you have a menu which you want to slide onto the screen, which is at x:-100, if you set the target to x:0 and time to 1, it would automatically animate the sprite so that it ends up at x:0 after 1 second.

The other thing i'd like to see is a nice text renderer. At the moment, flib is good, but can't do real-time rendering, so you'd have to render all the glyphs to textures first.

Keep up the good work, and I might have a play with the engine once I've got some time away from my current projects.

Q3 Bsp file format will be added in. Its on my list of todo things. I just have not jumped yet since it will take a few days to rewrite and port my stuff from iris over (I made things messy, plus iris is in C, kohkai is c++).

I want to get the physics engine tied into the q3 map as well but worried it will bottleneck too many things since collission detection on a q3 map is rather costly. So I might do your idea with an external file format that contains object & plane data for the ODE system.

Your idea for sprites has been noted and will go in. :)

I also want a nice font system in soon. I am looking at all options.

PSmonkey
July 25th, 2006, 05:12
*evil laugh in a stich/experiment 626 voice*

God I love that movie (lilo & stich).

Anyway, Basic ODE suport added. While nothing complex it's pretty much a cleaned up port of AT ODE test. Still need to add more suport but over all still works quite well.

-- How to use --
. Choose your Bios (1.0 or 1.5 folder) and copy to your psp.
. Copy the Art folder to the root of the memory stick.
. Run App
. Press Square button ( up to 10 times at max ).

:P Yeah it's basic but hey it works.

-- Code Imp --
{
PhysicsODE myPWorld;
myPWorld.InitPhysicsEngine( 10 );
myPWorld.CreateObjectPlane( 0, 1, 0, 0 );

while(1)
{
if( input )
myPWorld.CreateObjectBox( 0, 30, -7, 0, 0, 0 );

myPWorld.UpdateObjects( 0.05 );
iloop = myPWorld.GetObjectCount();

for( i = 0; i < iloop; i++ )
{
ScePspFMatrix4 myMat;
myPWorld.GetWorldMatrix( &myMat, i );
myCube.Render( &myMat );
}
}
}

PSmonkey
July 25th, 2006, 05:13
Oh minor note. I might change this

ScePspFMatrix4 myMat;
myPWorld.GetWorldMatrix( &myMat, i );
myCube.Render( &myMat );

to

myCube.Render( &myPWorld.GetWorldMatrix( i ) );

Just not sure atm.

--edit--
wee, must revise my code. create_plane is x,y,z,dist. :P

ODE does not lable things well.

AnonymousTipster
July 25th, 2006, 08:15
Nice work, looks like it's taking shape.
FYI on the ODE front, I tried replacing sinf cosf etc with vfpu functions, but that didn't help much at all. My guess is that it could only be drastically improved by changing core parts to ASM, but I don't have the time nor the skills.
Getting anything to run nicely in ODE on a limited system as the PSP is quite tricky, but the end results are rewarding.

PSmonkey
July 25th, 2006, 16:48
Nice work, looks like it's taking shape.
FYI on the ODE front, I tried replacing sinf cosf etc with vfpu functions, but that didn't help much at all. My guess is that it could only be drastically improved by changing core parts to ASM, but I don't have the time nor the skills.
Getting anything to run nicely in ODE on a limited system as the PSP is quite tricky, but the end results are rewarding.

Actualy that is why my ultimate goal is to write something from scrach specificaly for the VFPU. Its just that it would be another time consuming task I dont have enough time for atm. I will probably try it after the compo. There is a great book on physics programming I think its "Game physics for programmers" or something like that.

PSmonkey
August 7th, 2006, 21:03
FUK,
Finaly I got at3 playback. Just need to tweek and clean up the code. Rather happy now that it works.

The only draw back is you must have a UMD in the drive that is 1.0 or 1.5 firmware + has the audiocodec & at3plus prx modules. Either way, I will code an easy way to manage this by having the code do a umd check & a prx search check (to see if it can find them). That way you can prompt the user on boot before continuing.

DPyro
August 7th, 2006, 21:11
Can you not make a kernal mode version for 1.50?

PSmonkey
August 7th, 2006, 21:14
Can you not make a kernal mode version for 1.50?

I'm having problems with it loading up. I'll try tweaking it later but I am not a fan of the idea of two seperate builds.

AnonymousTipster
August 7th, 2006, 22:03
That's good that it's working, as it'll mean music playback takes no CPU time (it is run on the ME, right?).
It would be good if you allowed the engine to either force the user to insert the UMD, or allow the user to deactivate the music if the game wants to allow that functionality.

Produkt
August 8th, 2006, 00:57
How are we going to know if it has these PRX files?

DPyro
August 8th, 2006, 01:21
The app with check to see if it has the PRX files ;)

PSmonkey
August 8th, 2006, 06:40
That's good that it's working, as it'll mean music playback takes no CPU time (it is run on the ME, right?).
It would be good if you allowed the engine to either force the user to insert the UMD, or allow the user to deactivate the music if the game wants to allow that functionality.

That is exactly how I am planning to do it.

On boot the game checks the drive. If no UMD. Give a message saying "music playback requires a umd in the drive that uses 1.0 or 1.5 firmware". Give the user the option to retry or to disable music.

If the user has a disc already in or selects try, the engine will search the umd and try to auto find the prx files. if it does, it will load them and continue. If it does not find them it will notify the user.

The over all great thing about this. It means I ensure at3 playback on all psp and not just 1.0/1.5 units.

Evab3vA
August 8th, 2006, 21:12
Hmm..

Tried it and I get nothing! The 'Home' button works but crashes the PSP. :/

Not sure if I'm doing anything wrong. What are the .tga files in the 'Art' directory for?

PSmonkey
August 9th, 2006, 02:22
Yay. Sucks my battery was empty ealier today so sadly had to wait till now to test things.

Anyways, I now have auto detecting in the audio lib. I will post a demo later tonight / tomorrow so people can test on a few umd to see if generaly it works well. I do know that 2.5 UMD dont work well (exit caused the psp to crash).

So engine wise;
.) At3 Playback is functional but not final (have issues in stoping audio, as well as adding stuff for looping & maybe streaming).
.) Bsp suport is there but still need clipping, texture & lightmaps loaded.
.) Textures are partial atm. I am in the middle of adding a texture manager (wont be advance, just more a common class to plug in obj classes).
.) There is an improved camera & view frustum class now. Camera part needs to be made more advanced but works for now. Also I desided to make the camera class not do any surface clipping. This is up to the obj class themselfs, yet camera will always have the latest frustum for testing surfaces against.

anyway will post more info later tonight.



Hmm..

Tried it and I get nothing! The 'Home' button works but crashes the PSP. :/

Not sure if I'm doing anything wrong. What are the .tga files in the 'Art' directory for?

.TGA is a image format. Its quite commonly used in Quake2 & Quake3. Personaly the format stuck on me since it's so straight forward, not complicated and no need for external librarys.

PSmonkey
August 9th, 2006, 20:27
small note. Basic Ini suport.

While not complex you can have an ini like so

"
KOHKAI_TEST

AUDIO_FILE = Song.at3;
"

Then just do the following in code


FileFormatINI myIni;
char szSong[200] = "";

if( !myIni.LoadFile( "./Audio.ini", "KOHKAI_TEST" ) )
return;

if( myIni.SeekTag( "AUDIO_FILE", SEEK_CUR ) )
{
sscanf( myIni.GetResults(), "%s;", szSong );
szSong [ strlen( szSong ) - 1] = '\0';
}


you can drop the whole scanf part. I just like to use it for say if I want to parse fror example "BLOCK_LOC = 0, 1, 2;" I can just do sscanf( myIni.GetResults(), "%d,%d,%d;", &vec.x, &vec.y, &vec.z );

-- edit --
If you did not figure it out yet. "KOHKAI_TEST" is just a key so it can validate that the file is what you need.

if you call LoadFile and pass null for the second param it will not parse for a key.