PDA

View Full Version : PJPlib - 2D Game Library



pjpdev
08-04-2009, 04:23 PM
Development can finally begin on PJPlib... To find previous posts on this lib go to http://www.pascalgamedevelopment.com/forum/index.php?topic=5687.0

My current aim with this is:
- To make use of components compatible with both Lazarus and Delphi.
- Use JEDI-SDL for graphics and controls, and use OpenAL for sound & music.
- Make it cross-platform (currently Windows and Linux)
- To act as an game development introduction for new developers

PJPlib will be making use of an Open Source license, but it can still be used in commercial projects. Thanks to the LGPL (GNU Lesser General Public License).

More posts will be made here at PGD and at the official PJP Dev forums - http://forum.pjpdev.co.za

Wizard
08-04-2009, 05:05 PM
Great 8) Please consider making an install file which will install everything automatically...a lot of libraries doesn't have this >:( unDelphix has such an installation feature ;)

pjpdev
08-04-2009, 06:38 PM
Great 8) Please consider making an install file which will install everything automatically...a lot of libraries doesn't have this >:( unDelphix has such an installation feature ;)


I actually want to do it this way... Just have to do the research on it first. It would simplify the installation process instead of you sitting for quite some time setting path settings and manually installing components.

pjpdev
09-04-2009, 07:42 PM
Grrrrr... >:( This component idea just exploded in my face xx(. So now I'm gonna toy around with components and make a decision if I should actually make use of it or not.

pjpdev
10-04-2009, 02:20 PM
I had to drop the component idea. It will still be object orientated by means of derived classes... This is the basic concept I have...



type
TMyApp1 = class(TPJPApp)
private
{Private Declarations}
public
{Public Declarations}
procedure LoadContent(); override;
procedure GameLoop(); override;
end;

var
MyApp1: TMyApp1;


The implementation...


procedure TMyApp1.LoadContent();
begin
//Place your code here
end;

procedure TMyApp1.GameLoop();
begin
//Place your code here
end;


This is what I currently have... Using a class derived from the TPJPApp class which makes use of routines that overrides the originals in TPJPApp.

pstudio
10-04-2009, 04:42 PM
I like it this way. This is basically the way XNA does it. As long as you have some good documentation/tutorials I don't think any beginners will have trouble using this method ;)

Is GameLoop() both for checking input, update sprites... and render graphics? I would personally go for two methods. One for updating whatever needs updating and one for all the drawing.

pjpdev
10-04-2009, 07:41 PM
Is GameLoop() both for checking input, update sprites... and render graphics? I would personally go for two methods. One for updating whatever needs updating and one for all the drawing.


It depends on how the developer utilises it. He could jam all his update routines in there or he could code routines which will be called from within GameLoop()...

A good example:

A basic routine for updating the player...



procedure UpdatePlayer();
begin
Case App1.KeyDown of
KEY_UP: sprPlayer.Y := sprPlayer.Y - 1;
KEY_DOWN: sprPlayer.Y := sprPlayer.Y + 1;
KEY_LEFT: sprPlayer.X := sprPlayer.X - 1;
KEY_RIGHT: sprPlayer.X := sprPlayer.X + 1;
end;
end;


The UpdatePlayer() routine will be called from within GameLoop()...



procedure TApp1.GameLoop();
begin
UpdatePlayer()
UpdateEnemies()

//And whatever needs to follow after that...
end;


I also plan on adding a "Best Practices" section to the documentation where recommended methods will be discussed. And the above method will definitely feature in it.

I recently started coding on the lib and the input routines shown is just a basic "sketch" of what I'm trying to achieve... ::)

pstudio
10-04-2009, 08:50 PM
Funne you should mention "Best practises" cause this is exactly what I'm concerned about. Usually (all the time) you'll want to seperate your game logic from the drawing of the game. IMO you might as well force the developers to do it this way by having a method for game logic and another method for rendering.
The way it is now, some persons (my self included) may feel a bit lazy and just put it all (logic and rendering) in the GameLoop method as a single chunk. However by having two methods you force them to a bit more organized, and it's not gonna hurt them at all. It's still the same code they'll have to write.

Out of curiosity. How do you plan to handle timing in the lib? I consider this to be a tricky thing to learn for a new developer. How to make the game run at the same speed at all computers.

pjpdev
11-04-2009, 07:02 AM
The way it is now, some persons (my self included) may feel a bit lazy and just put it all (logic and rendering) in the GameLoop method as a single chunk. However by having two methods you force them to a bit more organized, and it's not gonna hurt them at all. It's still the same code they'll have to write.


Thats true... I also tend to get lazy sometimes... So I'll split it into two methods, namely Render() and UpdateLogic()... or something like that.



Out of curiosity. How do you plan to handle timing in the lib? I consider this to be a tricky thing to learn for a new developer. How to make the game run at the same speed at all computers.


Timing is always a complicated subject. I seriously need to find a way to make it easier for new developers. Last time I checked, JEDI-SDL's timing methods don't work very well. I don't know if they have fixed that yet. So I'm looking at other alternatives.

I'm gonna do a bit more coding to get more of the basics ready, write the documentation and upload it to SF.net to show you all what I've done so far.

Thanks again for the advice pstudio... 8)

pjpdev
13-04-2009, 03:02 PM
Hey I got a few things running with the lib, there is still a lot of work to do before the first release. Here's a list:

- Design a better sprite engine that updates movements, etc...
- Implement the sound system... Not even a single line of code for this yet...
- Get the input system running... This might take a while.
- Figure out how to handle timing...
- Finish the documentation...
- Do a few illistration demos

I also have to get things a bit more organised in the source code, it's a warzone.

pjpdev
19-04-2009, 07:10 PM
I recently commited the first bits of source to the project's CVS repository. You can go check it out at http://pjplib.cvs.sourceforge.net/pjplib

The current version of the source still needs a lot of work.

Implement the sound system (OpenAL)
Develop the sprite engine


These are key features that must be implemented before the first release.

Also you should check out the SVN repository http://pjplib.svn.sourceforge.net/viewvc/pjplib and get yourself a tarball.

pstudio
19-04-2009, 08:07 PM
I've just taken a quick look at it.
The test demo won't run on my comp :( It opens a console and a window and then freezes.

Otherwise I like the way you inherit from TPJPApp. I would probably also add a setup or initialize method that's called before loadcontent. It gives a place to for instance create objects like imagelist and spriteengine.

And btw. I would personally write

if not Fullscreen then
instead of

if Fullscreen <> true then
It's more readible imo. :)


Edit:

The current version of the source still needs a lot of work.
Implement the sound system (OpenAL)
Develop the sprite engine
I think you need to add at least add timing on that list. :)

pjpdev
19-04-2009, 09:02 PM
I've just taken a quick look at it.
The test demo won't run on my comp :( It opens a console and a window and then freezes.



I get a Windows error... I'm still trying to figure that one out. It happens when the draw routine takes place. I might have to add a bit of "debug" code in order to find the cause of the error, using SDL_GetError. I think thats where the problem lies.



And btw. I would personally write

if not Fullscreen then
instead of

if Fullscreen <> true then
It's more readible imo. :)


Bad habits die hard... ::)




The current version of the source still needs a lot of work.
Implement the sound system (OpenAL)
Develop the sprite engine
I think you need to add at least add timing on that list. :)


Oops... Slipped my mind!!! Thats also one of the top priorities.

This is getting somewhere... Yippee Kai Yay Mother :-X

paul_nicholls
20-04-2009, 02:56 AM
I recently commited the first bits of source to the project's CVS repository. You can go check it out at http://pjplib.cvs.sourceforge.net/pjplib

The current version of the source still needs a lot of work.

Implement the sound system (OpenAL)
Develop the sprite engine


These are key features that must be implemented before the first release.

Also you should check out the SVN repository http://pjplib.svn.sourceforge.net/viewvc/pjplib and get yourself a tarball.


Hi :)
I had a look at the source code and it is very similar to what I do myself in my projects!

I have a SDL 'app' class that I inherit from too...just that mine has only one update method where you do all rendering and updating instead of separate ones.

I do like the thought of separate update and render methods like you have :)

Nice job :-)

cheers,
Paul

pjpdev
20-04-2009, 07:36 PM
Got the problem with the test app sorted out. I've made a stupid error in the test app...


procedure TMyApp1.LoadContent();
begin
image := TImage.Create(MyApp1); //This is where I made an error...
end;


That should look like this:

procedure TMyApp1.LoadContent();
begin
image := TImage.Create(Self); //That's better...
end;


A simple slip of mind and it all bombs out!!! :D

It's all updated in the CVS here (http://pjplib.cvs.sourceforge.net/pjplib)

Now whats left? A lot!!!


Finish the Sprite Engine (It still does nothing!!!)
Get the sound system up and running (I should really stop sleeping on this)
Sort out timing... (Should I make it run at the same speed on all machines? If so... How?
Input handling
Physics (Newton? ODE? Both?)
GUI System
Compression for sound and graphics archives

arthurprs
21-04-2009, 01:58 AM
thats how i do on my engine,

i want the game running with 100fps, so 1 gamelogic every 10ms



# tickcount() acts like Windows.GetTickCount()
ac = 0.0 # this is the acumulator
old = tickcount()
while running:
new = tickcount()
ac += (old - new) / 10.0
loops = trunc(ac)
if loops > 0:
ac -= loops
for i = 1 to loops:
update()
draw()
old = new
else
sleep(1)

pjpdev
22-04-2009, 09:01 PM
Thanks for the example. I will definitely have a try at it. While I'm figuring out timing on the sideline, the next things to do is finalising the sprite engine and implementing the sound.

This lib is slowly reaching it's first release. PJPlib's first release will happen when the following things have been done:


Completion of Sprite Engine
Implementation of sound system
Timing
Input handling
A few tech demos
Documentation


Then I can add other fancy stuff like physics, video playback, gui system, etc...

Remember to keep an eye on the CVS (http://pjplib.cvs.sourceforge.net/pjplib) to see how things are going.

pjpdev
26-04-2009, 11:11 PM
Recruitment Time!!!!

Yes, I'm looking for some folks to help me out on PJPlib. So if you want to get involved get yourself a SourceForge.net (http://www.sourceforge.net) account if you don't already have one and send me a PM or e-mail with your SF.net username. This will give you full access to the CVS, documentation system and everything else.

Brainer already volunteered but I haven't heard from him in a while.

Thanks guys...

pjpdev
02-05-2009, 02:06 PM
I have a little issue about timing for the lib...

I want the developer to be able to set a desired FPS for his game and that the game will run at the same speed on all systems.


//Desired FPS eg. 100 FPS
DoTimer(100);


Could someone please help me with this... How should I do it?

arthurprs
02-05-2009, 04:42 PM
adapting my code


# tickcount() acts like Windows.GetTickCount()
#frameduration is 1000.0 / desired fps
ac = 0.0 # this is the acumulator
old = tickcount()
while running:
new = tickcount()
ac += (old - new) / frameduration
loops = trunc(ac)
if loops > 0:
ac -= loops
for i = 1 to loops:
update()
draw()
old = new
else
sleep(1)

pjpdev
02-05-2009, 06:33 PM
I tried that... With some strange results. It looked like everything happened backwards. ???

For now I have a timing method in place adapted from the JEDI-SDL documentation. But it needs some fine-tuning.

Thanks anyway arthur... ;)

pjpdev
03-05-2009, 08:52 PM
Hey people...

I've updated the CVS (http://pjplib.cvs.sourceforge.net/pjplib) again. This time the attention is on timing. I've adapted the test app to ask for a desired FPS before continuing. Anyone checking out the CVS, can you please give me your FPS results so that I can improve the timing.

Thanks

P.S. If you need a CVS client try TortoiseCVS (http://www.tortoisecvs.org). If you need any help, just ask... ;)

Edit:

While I have some sort of timing system in place I'm going to work on the other important stuff... Sound and input handling.

arthurprs
03-05-2009, 10:22 PM
i looked at you code, but i don't think it will guarantee that a computer that can't run the game at desired fps, runs at the same speed as the others

i would like to offer my help with that, and with another things too

pjpdev
04-05-2009, 04:03 PM
Thanks Arthur, really apreciate it man... Timing is just one of those things that I have to learn more.

I'm currently busy with the sound framework for the lib. When I have something to show I'll update the CVS. And another problem... I really need to work on commenting my source! ::)

arthurprs
05-05-2009, 12:06 AM
:D

how can i get acess to cvs?

my username on sourceforge is arthurprsll

pjpdev
05-05-2009, 04:14 PM
Thanks Arthur, I've added you to the project and sent you a PM with the CVS access details via SSH.

I'll add better commenting to the source and commit it to CVS.

arthurprs
06-05-2009, 12:39 AM
PJP Dev,
i just commited my changes to the cvs

timing is fixed now :)

pjpdev
06-05-2009, 03:53 PM
Thanks Arthur... I'll have a look at it and see what I did wrong. :-[

BTW you can all just call me PJ.... ;)

pjpdev
06-05-2009, 04:07 PM
The timing works great! Check it out and compare it to my excuse for timing... :D

Big thanks to Arthur!

arthurprs
06-05-2009, 04:38 PM
:) I'm glad to help

ps: looks like our timezones are very different, where are you from?

pjpdev
06-05-2009, 05:25 PM
I'm from South Africa (GMT + 2:00), way ahead.Hehe

arthurprs
06-05-2009, 08:45 PM
I'm from South Africa (GMT + 2:00), way ahead.Hehe

(GMT -3:00) here ;D

what lib component you plan to write now?

ps: looks like sprite animation stuff needs to be fixed

pjpdev
06-05-2009, 09:15 PM
what lib component you plan to write now?

ps: looks like sprite animation stuff needs to be fixed


Yeah it needs some fixing. Maybe allowing the end-developer change the fps of the animation. :)

Currently I'm working on the sprite engine and sound engine. Input handling will be started on soon. And it's gonna be a big one, a whole lot 'o' constants for key definitions:

PJP_KEY_A
PJP_KEY_RETURN
PJP_KEY_ESC
PJP_MOUSE_LEFT
PJP_MOUSE_RIGHT
etc, etc.

Great News!!!

I got PJPlib running on Linux with Lazarus/FPC. If you want to check it out make sure you have the OpenAL and SDL development packages installed. And viola... Without having to change the code. ;D

pjpdev
17-05-2009, 10:06 PM
I'm freakin' banging my head against the wall with the sprite engine. I got it working for now, but it's ineffecient. I'll just put this to bed for now, until I find a solution for the problems.

In the meantime I can finish the input system and write some more documentation along the way.

Slowly reaching it's first release...

pjpdev
05-06-2009, 05:23 PM
Eeek... Been sleepin' on this project and got stuck playing online games, like Combat Arms (which is a very cool FPS) and now I'm a bit behind schedule ::)... So I'm really gonna jump back to work on this one. The CVS is a bit old.

Another thing, I really need some help on the sprite engine... Its gonna drive me crazy.

pjpdev
06-11-2009, 03:47 PM
Time to bring this baby back from the dead... Currently I'm busy with a total rewrite of PJPlib and this time things are going smoothly. Most of the the original features will remain the same, but I've added SDL_Image support as well, so that a variety of image formats can be loaded.

Will keep you guys posted...

Later

pjpdev
08-11-2009, 10:02 AM
I just got a blog set up for the development of PJPlib - http://www.pjpdev.co.za/pjplib ;D

pjpdev
15-11-2009, 12:03 PM
Say hi to Tux (LinuxGD.net's Version)

http://www.pjpdev.co.za/pjplib/wp-content/uploads/2009/11/Screenshot-PJPlib-Image-loading-300x225.png (http://www.pjpdev.co.za/pjplib)

Finally got the image loader up and running, with many thanks to Stoney who helped me out with a little issue I had. Now I'm going to work on the rest of the graphics core.

paul_nicholls
15-11-2009, 07:48 PM
LOL cute :)

cheers,
Paul

pjpdev
22-11-2009, 11:38 AM
Okay, so I've got a bit of the graphics framework up and running. But I'm at that point again where I start questioning myself (hate it when that happens). So I'm going to ask for a little help.

The goal of PJPlib: To become an easy to use cross-compilable game development framework.

Currently the title of this post says "PJPlib - 2D Game Library", but since it uses OpenGL to do all that 2D drawing, why not add 3D support as well? Of course that makes more work, but it'll give Pascal developers a great platform to work on.

Any other suggestions?

Thanks in advance

arthurprs
22-11-2009, 02:10 PM
Keep things simple ;)

code_glitch
22-11-2009, 02:54 PM
I'm from South Africa (GMT + 2:00), way ahead.Hehe

sorry, but just can't help asking. where abouts in SA? I lived there for 6 years...
I was in Durban... :D

dazappa
22-11-2009, 06:47 PM
Okay, so I've got a bit of the graphics framework up and running. But I'm at that point again where I start questioning myself (hate it when that happens). So I'm going to ask for a little help.

The goal of PJPlib: To become an easy to use cross-compilable game development framework.

Currently the title of this post says "PJPlib - 2D Game Library", but since it uses OpenGL to do all that 2D drawing, why not add 3D support as well? Of course that makes more work, but it'll give Pascal developers a great platform to work on.

Any other suggestions?

Thanks in advance

I would stick to 2d until it's mostly finished. That way, full games could actually be made with it.

Suggestions?

Particles
Collision Detection (I've made a basic bounding box collision system that you could port over), but pixel based collision detection is necessary for a lot of games
Scalable graphics
Alpha transparency support (Both through PNG (which you shouldn't have to code for) and through a DrawAlpha function. Don't forget there can be tons of variations in functions, like DrawAlphaRotatedScaled ;))

pjpdev
22-11-2009, 08:24 PM
I'm from South Africa (GMT + 2:00), way ahead.Hehe

sorry, but just can't help asking. where abouts in SA? I lived there for 6 years...
I was in Durban... :D


Middelburg, Mpumalanga. Used to live in Jo'burg



I would stick to 2d until it's mostly finished. That way, full games could actually be made with it.

Suggestions?

Particles
Collision Detection (I've made a basic bounding box collision system that you could port over), but pixel based collision detection is necessary for a lot of games
Scalable graphics
Alpha transparency support (Both through PNG (which you shouldn't have to code for) and through a DrawAlpha function. Don't forget there can be tons of variations in functions, like DrawAlphaRotatedScaled ;))



Well, no prob with 2D. And since I'm already using OpenGL for rendering, adding 3D features at a later time won't be too difficult.

And thanks for the suggestions. One thing that tickles my pea brain is scalable graphics, how should I go about implementing it?

dazappa
22-11-2009, 11:20 PM
One thing that tickles my pea brain is scalable graphics, how should I go about implementing it?

If opengl doesn't already have a way to do that, I welcome you to join my google searching. I've been searching for a good half hour now; and of course all of the results that will probably have the answer are at experts-exchange.

Stoney
22-11-2009, 11:58 PM
And thanks for the suggestions. One thing that tickles my pea brain is scalable graphics, how should I go about implementing it?

Scaling images is actually really simple with OpenGL. Just make expand your quad you're drawing to the preferred width and height. The binded texture will be stretched automatically.

pjpdev
23-11-2009, 05:06 PM
I thought it would be like that, thats why I chose OpenGL - as well as for realtime rotation, alpah transparency and other cool effects that could be achieved. The graphics core is no where near perfect, and I'm gonna modify a few things so that adding full 3D support at a later time won't cause headaches. Anyway, thanks for the help everyone. Suggestion box still open.

Please sign up to the PJPlib Blog (http://www.pjpdev.co.za/pjplib) to stay up to date on the development first hand.

paul_nicholls
23-11-2009, 07:50 PM
I've registered at http://www.pjpdev.co.za/pjplib/ but is the the same as signing up?

cheers,
Paul

pjpdev
23-11-2009, 08:20 PM
I've registered at http://www.pjpdev.co.za/pjplib/ but is the the same as signing up?

cheers,
Paul


Hehe, you know what I mean. Anyway thank you, and you too Stoney.

Stoney
24-11-2009, 09:50 AM
Just a quick note on scaling:
I just took a look at my code at it would be much better if you call glScale3f(X-Scale in float, Y-Scale in float, Z-Scale in float) before drawing your quad instead of just scaling the quad to the preferred width and height.
If you use rotating you need (or should) specify an offset. When you just scale the quads' width and height the offset needs to be scaled manually, but when using glScale3f the offset coordinates don't need to be changed.

WILL
03-10-2010, 07:46 AM
Hey what ever became of this? Your website is down and I can't find a trace of the files for it. Are you still working on this library?