PDA

View Full Version : Basic needs for FreePascal with game programming.



firehead
12-05-2009, 04:16 PM
Hello. I wonder if there's any way that I can start the game programming in just using the original FPC compiler(with out Lazarus).

If there is any following for what I need:

* The ability to hold down a key while the player is moving. (key just pressed once and holding down a key)
* No need to distribute DLLs when distributing the game. (I don't know if SDL does that)
* All media in one file when distributing.
* Sound Library (Again, Jedi-SDL offers that but I don't know if there's an option to not distribute the library DLL when distributing the game, because it can be a hassle for both developer, and for anyone who just wants to play the game with out the need to look for a certain file to get the game working).

That's all the time I have now.

NecroDOME
12-05-2009, 05:00 PM
Yes you can.

* You can retrieve what key the user pressed with pascal.
* Yes, if it's plane windows forms. I don't know it SDL has an dll, otherwise you can compile it inside your exe.
* Yes, you could use package/zip files or compile it as resource inside your .exe or have an installer.
* You could try to use a sound lib that you can distribute with your game. I know DirectX is installed on most windows pc. If you want to go cross platform, you could use FMOD (dll) or something)

firehead
12-05-2009, 07:51 PM
I wonder if there's a tutorial for all of that. I like FreePascal because it's a fast programming language but too bad it's not that widley used.

I wish more people would contribute things to it.

chronozphere
12-05-2009, 10:19 PM
Why don't distribute any DLL's and data-files along with your game? I don't see why you should avoid that. Just zip/rar the whole thing. The user just downloads, unpacks the archive and all files are there, and you're ready to play.

It's almost impossible to write a game that just works "out of the box" on all computers. Different libraries and API's for 3d/sound/input/windowing are involved and some of the might need to be installed/updated in order to run the game.

As far as I know, there are tricks to store the DLL inside the exe. You could try to include it as a resource and write it to disk as soon as the exe is started. This might be a possible workaround.

jdarling
12-05-2009, 11:47 PM
Like most of the people on here, I have plenty of samples on my website (http://www.eonclash.com/) including spriting using only GDI and transparent input. Even have an example game engine based around FreePascal, Lua, and SDL.

You will have a problem trying to find sound libraries that are cross platform that don't require a DLL, SO, LIB, or other module (dependent on platform).

- Jeremy

marcov
25-06-2009, 10:40 AM
Hello. I wonder if there's any way that I can start the game programming in just using the original FPC compiler(with out Lazarus).


Well best to start with the (admitted pretty sad) games that come with FPC. There is a tetris and samegame clone, and both work with both graph and in textmode. I still must have an half finished chain-reaction somewhere.



* The ability to hold down a key while the player is moving. (key just pressed once and holding down a key)
* No need to distribute DLLs when distributing the game. (I don't know if SDL does that)
* All media in one file when distributing.


The first point is dependant on what lib you use, but nearly any will provide it.

The second and third points are always possible when doing open source. But it can be quite hard, specially if you have to figure it out for yourself how to compile and initialize SDL. I hope you realize you set the bar for yourself quite high with these.

Besides that, there might also be license limitations (e.g. when SDL is LGPL or something with similar shared library limitations)

Brainer
25-06-2009, 02:24 PM
As far as I know, there are tricks to store the DLL inside the exe. You could try to include it as a resource and write it to disk as soon as the exe is started. This might be a possible workaround.

I wouldn't be so sure about that. For all I know, Windows looks up for needed libraries before the app is actually executed, so it might not be possible to extract it before it's invoked by the very app. Of course I may be wrong, but that's how it works, I think.

WILL
25-06-2009, 04:10 PM
Honestly, I fail to see the point of avoiding having any other file than the EXE in your distributed games. It's not as if you are running DOS and you have to copy each file over one by one. :P

SDL distributable libraries are just that distributable. They are intended to be packaged and included in your game. These days size is not an issue either as 1 GB USB drives are pretty much a minimum that you can get in some places. (Some it's 2 GB) sdl.dll and it's friends barely reach that.

Further compressing and packing all your textures, sound and config files into some bootstrap format is a waste of time until you have nearly completed development. Especially if you don't know how to do it. You end up putting off what you need to learn most, which is all the core fundamentals for game development, first and foremost.

My recommendations are if you want to use Lazarus or FPC alone try using SDL since it's probably the easiest to work with. (Asphyre is also good to try, but I believe it may require Lazarus.) Don't get hung up on small things like included DLL files and the like. Learn the basics FIRST then once you have actually made something THEN work on areas to improve your skills in different areas.

If you need help or get stuck with something feel free to post in the forums and ask about it. Sometimes it's the quickest way to get what you need, right to the point. ;)

AthenaOfDelphi
25-06-2009, 07:17 PM
I wouldn't be so sure about that. For all I know, Windows looks up for needed libraries before the app is actually executed, so it might not be possible to extract it before it's invoked by the very app. Of course I may be wrong, but that's how it works, I think.


You can dynamically load your libraries using loadLibrary (if my memory serves), then you can stream it out to disk and load it (and I perhaps should have read the parent post properly first... I can't say for certain anything about FreePascal as I've never used it, but on Windows I'd be suprised if you can't dynamically load libraries since thats part of the Windows API and on other platforms there should be an equivalent function).

However... I have to agree with Will. Packaging your game is a non-issue if you don't actually have a game to package. Write the game, learn what you need to along the way, and by the end of it, if you've not learned enough to package the game I'd be very suprised.

Regardless... good luck :)

Brainer
25-06-2009, 09:08 PM
You can dynamically load your libraries using loadLibrary (if my memory serves)
Yep, that's true. To be honest, I have never tried loading a DLL during application's execution, i.e. not at start. But AFAIK existence of external dependencies is checked before an application is actually run. I've never really met any program which thrown an error saying there's a DLL missing in the middle of its execution. But like I said, I may be wrong. If anyone can dispell the doubt, please do so. :)

Yep, I agree both with Athena and WILL. First make the game working, then you can think about compacting your data files or protecting them. While in development, it's easier to keep your files "raw" (not compressed/encrypted), because it's faster to edit them.

Ñuño Martínez
26-06-2009, 10:46 AM
Hello. I wonder if there's any way that I can start the game programming in just using the original FPC compiler(with out Lazarus).


Well best to start with the (admitted pretty sad) games that come with FPC. There is a tetris and samegame clone, and both work with both graph and in textmode. I still must have an half finished chain-reaction somewhere.


My Allegro.pas (http://allegro-pas.sourceforge.net) wrapper includes a nice complete platform game (http://sourceforge.net/project/screenshots.php?group_id=184664). It's very simple and I think very documented. Also I plan to release an almost beta version.

AthenaOfDelphi
26-06-2009, 02:40 PM
You can dynamically load your libraries using loadLibrary (if my memory serves)
Yep, that's true. To be honest, I have never tried loading a DLL during application's execution, i.e. not at start. But AFAIK existence of external dependencies is checked before an application is actually run. I've never really met any program which thrown an error saying there's a DLL missing in the middle of its execution. But like I said, I may be wrong. If anyone can dispell the doubt, please do so. :)


I can dispell the doubt because I've written an application that does it. It's a fractal renderer I wrote many years ago and it stored it's equations in a DLL that is loaded dynamically at run time.

The way it works is you load a library with loadLibrary and then rather than have the compiler sort the dependencies etc. out at compile time, you use a mechanism similar to event handlers to sort them out yourself. You get the addresses of the calls using getProcAddress (IIRC).

For example (taken from my Fractal program), here is a prototype definition:-


TEQPConfigEQ = procedure( CurrentEQ:Integer;
var xmin:TFloaty;
var xmax:TFloaty;
var ymin:TFloaty;
var ymax:TFloaty;
var arg1:TFloaty;
var arg2:TFloaty;
var arg3:TFloaty;
var arg4:TFloaty;
var arg5:TFloaty;
var arg6:TFloaty;
var arg7:TFloaty;
var arg8:TFloaty ); stdcall;


In your main code you declare a variable like this...


EQPConfigEQ : TEQPConfigEQ;


And initialise it using getProcAddress something like this...


@EQPConfigEq:=GetProcAddress(EQPLibraryHandle,'EQP lug_ConfigEq');


If this fails, I think (IIRC) EQPConfigEQ ends up equal to NIL. If it succeeds, you call the routines just like a normal procedure called 'EQPConfigEQ'.

Brainer
26-06-2009, 07:47 PM
Thank you very much, Athena. :)

AthenaOfDelphi
26-06-2009, 08:32 PM
I should perhaps also add an example that is closer to home... if anyone uses the DGL OpenGL interface, that uses a similar mechanism to load the OpenGL DLL on the host machine.

marcov
23-07-2009, 04:32 PM
Personally I would not >:( use some DLL extraction technique. It is going to bring you into more problems with antivirusses, and the constantly increasing limitations of doing with binaries that use code.

If you really want to pursue this, go the way of static linking, but be warned, that takes work and skill.

Of course I wouldn't even try to do this, and just distribute DLLs. The one .EXE thing is fun from a purist stance, but there are many practical problems. The biggest being that if you finally figured it out, an year later, versions have changed and to upgrade you will have to do it all over again.

In other words, it is not an one way effort, but something that needs to be repeated as new versions, antivirruses, general security limitations in Windows etc mature.