PDA

View Full Version : Day Of Destruction!



paul_nicholls
09-12-2009, 04:38 AM
Hi all,
Now that the PGD Annual 2009 - Arcadia competition is over, I thought I'd start a new topic dedicated to "Day Of Destruction!" :)

I have now managed to port it over to Lazarus/Freepascal (Win32 only), with minor code changes...

It does have a graphical glitch now under freepascal with the singularity for some reason (need to find this), but it still seems to work ok regardless..yay!

So it now compiles using Delphi AND freepascal ;)

I do have one question now...if I want to port it over to a Linux flavour (Ubuntu, for example), does anyone have any hints or tips on using SDL/OpenGL libraries under Linux?

Or do I just have to find equivalent SDL, etc .so ? files to replace the Win32 dlls and it will then run?

Perhaps PJP Dev could pipe in? LOL ;)

cheers,
Paul

NecroDOME
09-12-2009, 09:05 AM
Keep up the work!!

paul_nicholls
09-12-2009, 10:45 AM
Keep up the work!!


Thanks :)

cheers,
Paul

deathshadow
10-12-2009, 03:12 AM
I do have one question now...if I want to port it over to a Linux flavour (Ubuntu, for example), does anyone have any hints or tips on using SDL/OpenGL libraries under Linux?
I'd be interested in information along those lines for OSX - I can probably provide partial answers for linux since I've dealt with SDL from there, I've just not done so in FPC (yet) - I too am from the Win32 world, and wonder just how much I'd have to change in my game (that I just started writing five days ago).

For the most part so far on mine, I've avoided making any calls to Windows and have used JUST SDL and OpenGL... with one exception, the inclusion of the windows unit just so I can pull the desktop resolution as the game default the first time it runs - and I put that behind a $IFDEF Windows with a fallback to 800x600 for all others.


{$ifdef Windows}
defaultWidth:=GetSystemMetrics(SM_CXSCREEN);
defaultHeight:=GetSystemMetrics(SM_CYSCREEN);
{$else}
defaultWidth:=800;
defaultHeight:=600;
{$endif}


Thankfully under Windows that pulls the default display and not all displays - so SDL reduces the headaches of multi-display too. (though does anyone know if it can specify what display to make a fullscreen surface on?)

I've written cross platform in other languages, and so long as you keep to the libraries that will be available across platforms (SDL, OpenGL) in terms of building the game executables there should be no problems - or in the handful of cases where you want to use some OS specific feature JUST on that one OS, well, blessed be $IFDEF



Or do I just have to find equivalent SDL, etc .so ? files to replace the Win32 dlls and it will then run?
On Linux, all you have to be sure of is that SDL is installed, and FPC should bind to it when you compile. Thankfully it seems like most Linux distributions come with SDL already present, and if not and you are on a mainstream distro it's usually a simple matter of an apt-get or yum away.

You might find this article of use:
http://linux.omnipotent.net/article.php?article_id=12443

Unlike in Windows where you end up needing SDL.DLL either in /SYSTEM or the same directory as your game, in linux so long as the dependency in the source-tree is satisfied you don't have those extra files - good since the version of SDL that works with each distro can vary wildly depending on the versions of svgalib or X11 that are installed. (though I'd not even try working with SDL atop svgalib these days)

Distributing it, particularly if you don't want to share the source or encumber the user with installing FPC is going to be the tricky part - involving makefiles. I've not dealt with makefiles and FPC as yet, not entirely certain I'm looking forward to that since with make I'm always asking "and why the *** can't it just figure this shit out from the compiler defaults and the program source?!?"

jdarling
10-12-2009, 07:14 PM
Hey Paul, great to see you're coming over the to dark side (Lazarus and Cross Compiling). Linux is EASY to get your apps running on with Lazarus. Here is how I do things (granted, its not the only way, but its the best way I've found).

Download and install a pendrive install of linux on a windows box (makes life easier for initial testing) http://www.pendrivelinux.com/
* Personally I have 3 installs Ubuntu, Knoppix, and Arc

Structure your project so you have better control over platform builds (Lazarus does a POOR job of storing settings for each platform in the same lpi file)
ProjectName\
bin\
forms\
lib\
win\
linux\
mac\

DON'T COPY YOUR WIN LPI FOR ANY OTHER VERSION, MAKE NEW ONES! Seriously, I've had really bad luck trying to copy from one to the other its much easier to just create a seperate project file for each OS.

Create your a new .pas file that contains the actual application and link it from each of your platform projects (IE: instead of placing your code in the begin..end. sections of the lpr place it in a new file and call a method in that file between begin..end.)

Make sure ALL of your file names are lowercase (ok, this isn't necessary, but it sure as hell makes life easier)

Build and run to your hearts content!

As for MAC and SDL, Savage has a great writeup. Using it I've been able to get JumpStart to compile on Windows, Win64, Linux, and MAC. All except its scripting engine (Lua) support (can't get the bindings to work on MAC for some reason).

Some place I've got a sample project that shows using SDL in all 3 platforms, I'll see if I can find it. Can't guarntee the MAC support any more as I don't have a test MAC :(

- Jeremy

paul_nicholls
10-12-2009, 07:50 PM
@deathshadow: thanks for the tips :)
As far as I know I don't use any windows platform specific stuff, so this should make it easier ;)

Thanks for the link :)


@jdarling: Going over to the dark side, I love it! haha!
thanks for the advice chief ;)
As you probably already know, I have done some win32 -> arm-linux cross-compiling before with my gp2x, but not using Lazarus at all, so this should be fun :)

It will be nice to get my game running under Ubuntu, for example...

hmm...not sure what you mean by this:


Create your a new .pas file that contains the actual application and link it from each of your platform projects (IE: instead of placing your code in the begin..end. sections of the lpr place it in a new file and call a method in that file between begin..end.)


If it helps, I have my original .dpr file, which I then started a new project from file in Lazarus (Win32) from this (gives me a .lpi file,etc.)

This means I can still edit the .dpr file, .pas files, etc. and still compile it in Delphi and Lazarus.

So I suppose I should take my .dpr file, and do new project from file in each OS's Lazarus? :)

cheers,
Paul

paul_nicholls
13-12-2009, 09:52 AM
Download and install a pendrive install of linux on a windows box (makes life easier for initial testing) http://www.pendrivelinux.com/

Thanks Jeremy, I have downloaded pen-drive linux now and installed it on my new (replacement computer; old one died...) vista home laptop.

It took me a bit of faffing around with Linux packages and dependancies, but I have finally installed freepascal, lazarus, dbg (debugging under Lazarus - wouldn't run without it), and sdl on my linux.

It is certainly fun to be able to use Linux stuff from within windows :)

I now have to try and upgrade my project so I can have different versions like you suggested, and can try a Linux version ;)

EDIT: Now I have moved my pen-drive linux folder to my 8GB USB Key so now it is completely portable - nothing installs on any windows machine...yay!!

cheers,
Paul

paul_nicholls
14-12-2009, 02:36 AM
Ok, this may sound like a silly question, but how do I tell lazarus (under Linux) where the SDL libs are installed?

I am getting a linking error:


/usr/bin/ld: cannot find -lSDL

if it helps, in Linux, I used this (from memory) to install SDL (as root user):


apt-get install SDL

cheers,
Paul

jdarling
14-12-2009, 05:07 PM
Ok, this may sound like a silly question, but how do I tell lazarus (under Linux) where the SDL libs are installed?

I am getting a linking error:


/usr/bin/ld: cannot find -lSDL

if it helps, in Linux, I used this (from memory) to install SDL (as root user):


apt-get install SDL

cheers,
Paul


Not silly at all, first make sure SDL is actually installed (find something that uses it and try running it to see if it runs as if all you did was type "apt-get install sdl" it probably isn't installed). Typical APT command to install SDL:

sudo apt-get install libsdl1.2-dev
sudo apt-get install libsdl-image1.2-dev
sudo apt-get install libsdl-net1.2-dev
...

Do the above for each of the libraries that you want to install (image, net (shown), sound, mixer, etc). Another (cheater) way of doing this would be to install Wesnoth (a game):
sudo apt-get install wesnoth

Once SDL (and all the libraries you are trying to use) are installed properly you won't get that error any more.

See if that helps a bit,
- Jeremy

paul_nicholls
14-12-2009, 07:44 PM
Thanks Jeremy,
I will let you know how I go :)

Long live pen-drive Linux! haha! :D

cheers,
Paul

paul_nicholls
15-12-2009, 01:16 AM
Well, it now compiles...

One slightly huge issue though - I ran it in debug mode in Lazarus, and it crashed...taking out my pendrive linux at the same time!! :(

I had to restore the drive image that I had luckily backed up 1/2 hour earlier!!

I suspect it might be because I'm using

DataPath := ExtractFilePath(ParamStr(0)) + 'data\';

in my code, and then loading stuff from here...

I have read this is definitely not reliable in Linux :(

1. Anyone know how to find an application's path from within a program under Linux?

2. anyone have a simple SDL + OpenGL lazarus linux program with source that they could share so I could try it on my system to help me debug my SDL + OpenGL code and find where it is crashing?

cheers,
Paul

jdarling
15-12-2009, 04:28 PM
Hey paul, no problem using ExtractFilePath(ParamStr(0)) just make sure that you supply /'s and not \'s. This works in windows too as an added bonus (/'s instead of \'s) thus no code changes. In linux the \ is passed directly and the underlying OS may shit itself on an \#0 sequence (thats what your sending at times).

Anyways, here is a zip file with an SDL app that compiles and runs in both windows and linux (I actually share my laz projects folder between the two and edit in both at the same time some times). Its incomplete, kinda jumbled up, and in general a mess, but it works and it runs in both (binaries are included). It also has my slightly modified version of SDL with it (I'm running an old version and refuse to update from being too stuborn). Download at http://www.eonclash.com/PGD/mygame.zip

Hope it helps. Right now its just setup to show a character on the screen and move them around with the arrow keys (nothing fancy). In windows I pull 200FPS in Ubuntu on Windows via VirtualBox (or PenDrive) I get about 33FPS so definite difference. Course I test on a seperate Ubuntu box anyways, just like having all my dev tools on one box :)

- Jeremy

paul_nicholls
15-12-2009, 07:36 PM
Thanks chief!

I will see how I go :)

cheers,
Paul

jdarling
15-12-2009, 08:09 PM
I should add, currently its setup to force OpenGL rendering (UseOpenGL : boolean = true in common.pas and similar in renderingengine.pas). This was more accidental as I was working out some bugs and got tired of passing in the commandline option for switching LOL. You can see where the settings (commandline and ini) can be used instead. Just uncomment the line ~92:
UseOpenGL := CompareText(Settings.Setting['DisplayMode'], 'OpenGL')=0;
in renderingengine.pas
and comment the line ~93:
UseOpenGL := true;

Of course, that version also doesn't have a separate game.pas file that wraps it all up. Was getting to that, just hadn't got there yet :).

paul_nicholls
15-12-2009, 10:35 PM
Hi Jeremy, thanks to your program I have now found out some things (all under pendrive Linux)...

1. using OpenGL on both mine game and yours causes the pendrive linux client to crash and I have to delete a file from within the shell to enable it to restart again.

2. disabling OpenGL on your project makes it work without crashing (shows boy sprite) in Lazarus debug mode, but runs at around 0.2 FPS!

There is also no animation or movement via keys - is this correct?

3. running the same executable via konqueror makes the window appear for a few seconds (window is blank), and then it closes down again without me hitting escape.

4. running the executable from within a terminal window like so:


pendrivelinux:/mnt/win/Lazarus/Projects/myprojects/mygame/bin# ./mygame
open /dev/sequencer or /dev/snd/seq: No such file or directory
pendrivelinux:/mnt/win/Lazarus/Projects/myprojects/mygame/bin#


Works like just like 2 (less than 1 FPS).

So it appears I have discovered 3things:

a. the getting a path from within Lazarus/freepascal doesn't seem to work correctly unless it is the current directory via a shell (as I suspected it wouldn't with my prowling around the net), or possibly via a script to change to that folder prior to executing the program.

b. OpenGL makes my pendrive linux sh*t itself, so I have definitely got a OpenGL issue with my linux - perhaps it has incorrect drivers or something?

c. I am missing something on my linux:


open /dev/sequencer or /dev/snd/seq directories

Thanks for the help so far :)

cheers,
Paul

jdarling
15-12-2009, 11:00 PM
1. using OpenGL on both mine game and yours causes the pendrive linux client to crash and I have to delete a file from within the shell to enable it to restart again.
- You don't have OpenGL installed mate! sudo apt-get install opengl

2. disabling OpenGL on your project makes it work without crashing (shows boy sprite) in Lazarus debug mode, but runs at around 0.2 FPS!
- Software rendering via SDL is SLOW, with OpenGL support you should get somewhere between 10 and 20 FPS!

3. running the same executable via konqueror makes the window appear for a few seconds (window is blank), and then it closes down again without me hitting escape.
- See #1

Etc...

Also, I've been playing with Virtualbox (http://www.virtualbox.org/) with Unbutu and Knoppix/Debian and I must say I'm loving it! Of course, you still have to install all the other crap by hand (apt-get/pakman) but hey, its worth it. Networking on the other hand doesn't quite work right. You can access anything via the IP but forget about using names :( (my research turns up zilch, but it seems to do with IP masking).

Nothing is better than pure hardware for testing, if you haven't done so yet, a great tool for this is to download a disk based distro (I like Knoppix www.knoppix.net (http://www.knoppix.net) but there are others). Use that to boot from, mount your harddrive /mnt/hdsk1 (typically, not always) and run your binary that you built while in your VM. If you have the extra hardware lying around, then the best solution is to setup a linux box. Build on your dev box, deploy via a local web server, download to your "test box" and install. This has the advantage that you can figure out what libs are really needed for your app. It also lets you blow away the test box quickly and try again :)

That's my 2p worth at this point. Now if only we could run MAC OSX on a VM so I didn't have to have a mini and a powerbook for MAC builds (and right now I don't have either :()

- Jeremy

paul_nicholls
15-12-2009, 11:06 PM
Hi Jeremy,

EDIT: Thanks for that:


- You don't have OpenGL installed mate! sudo apt-get install opengl

I didn't know what I should install for OpenGL :)

BTW, After reading on the net, I whipped up this little script as a test (placed in /usr/bin)

rungame.sh


#!/bin/sh
DIR=$(/usr/bin/pwd)
cd /mnt/win/Lazarus/Projects/myprojects/mygame/bin
./mygame
cd $DIR


I can now run a game (yours ATM) from any directory, and it still works :)

Maybe it will help you too...

cheers,
Paul

paul_nicholls
15-12-2009, 11:37 PM
hmm...

I tried:


apt-get install opengl

but it didn't know that package :(

I found a bunch of opengl packages using Synaptic, but I don't know which one (if any to install)

http://img682.imageshack.us/img682/2921/openglpackages.th.png (http://img682.imageshack.us/i/openglpackages.png/)

cheers,
Paul

jdarling
15-12-2009, 11:45 PM
Rather than try and answer, here is a thread over at GD that answers your OpenGL questions http://www.gamedev.net/community/forums/topic.asp?topic_id=482331. Short answer, there is no "one source fits all" but mesa seems to be common. For the long answer, read the thread (actually, just read the thread LOL)

NOTE: The thread is REALLY OLD, so you want to look for latest versions and not the ones listed, but at least it gives you a starting point for package names :)

- Jeremy

paul_nicholls
17-12-2009, 02:46 AM
I installed some mesa opengl package stuff, but I haven't gotten around to seeing if now runs my game in OpenGL mode yet :)

I tried one linux game commercial game I downloaded

an arkanoid clone (uses SDl and OpenGL)

http://www.wegroup.org/games/arkanoid-games/arkanoid-space-ball.html

but it runs like a dead dog still, and doesn't respond to mouse clicks with the onscreen cursor :(

I think I will give things a try with VMWare player and a Ubuntu virtual machine instead...

cheers,
Paul