Terminus Est

From Bitpost wiki
Revision as of 20:17, 23 March 2006 by M (talk | contribs)

Terminus Est is John's awesome space shooter. See his Soloforge website.

Mike is hoping to help John build Terminus under linux. Here's John's "getting started" list...

There is some stuff in here on getting set up to build SDL apps with
KDeveloper: http://gpwiki.org/index.php/SDL

You will need SDL, plus the SDL_image and SDL_gfx support libs.  
Available from: http://www.libsdl.org/index.php

And the FMOD sound system from http://www.fmod.org.

Typically I'll be using either Fedora or Gentoo during my porting effort.


FEDORA


1 Install SDL and fmod:

yum install SDL-devel
yum install SDL_gfx
yum install SDL_gfx-devel
yum install SDL_image
yum install SDL_image-devel
yum install fmod
yum install fmod-devel

Mar 19 22:42:01 Installed: SDL_gfx.i386 2.0.13-2.2.fc4.rf
Mar 19 22:45:23 Installed: SDL_image.i386 1.2.4-1.2.fc4.rf
Mar 19 23:11:05 Installed: fmod.i386 3.74.1-1.2.fc4.rf
Mar 20 21:22:26 Installed: fmod-devel.i386 3.74.1-1.2.fc4.rf
Mar 20 21:24:32 Installed: alsa-lib-devel.i386 1.0.10-27.rhfc4.at
Mar 20 21:24:41 Installed: SDL-devel.i386 1.2.8-4
Mar 20 21:24:41 Installed: SDL-devel.i386 1.2.8-4 
Mar 20 21:27:59 Installed: SDL_gfx-devel.i386 2.0.13-2.2.fc4.rf

Mike's comments will occasionally be marked in blue, John's comments in green, when we're not feeling lazy.

Huh. Does that yum app go out and get the latest version too? Slick. I will get some source control up and running today.

Yep it auto-updates everything to the latest stable versions, including tracking down dependencies.


2 Grab the source - John is using subversion - very l337!

yum install subversion
  Mar 20 20:00:03 Installed: subversion.i386 1.2.3-2.1

cd development
mkdir terminus
cd terminus
svn checkout http://xxxxx/terminus/

and there it is!


3 Build it

sdl-config tells you what you need on the gcc command line:

[m@thedigitalmachine terminus]$ sdl-config --libs 
-L/usr/lib -lSDL -lpthread
[m@thedigitalmachine terminus]$ sdl-config --static-libs
-L/usr/lib -lSDL -lpthread -lm -ldl -lasound -L/usr/X11R6/lib -lX11 -lXext

So let's try this:

g++ main.cpp -o main `sdl-config --cflags --static-libs`

Here's what we got so far:

 In file included from system.hpp:17,
                 from startup.hpp:8,
                 from main.cpp:8:
util/audio.hpp:82: error: syntax error before `*' token
util/audio.hpp:145: error: `FMOD_SOUND' was not declared in this scope

Looks like the version of fmod that Fedora wants to pull down is old (3.74). I believe we need to go with FMOD Ex 4 (4.03.03 as of this writing). I will pull down the code from fmod.org and build a local version.

Hmmm... There are two versions of FMOD Ex, the C and the C++ version. I had to use the C version because the C++ version is not compatable with Dev-C++ and MinGW. Check and make sure that you have the C version of the lib installed too.

FYI, here is my linker options:

-lmingw32 -lSDLmain -lSDL -mwindows
../../Dev-Cpp/lib/libSDL_image.a
../../Dev-Cpp/lib/libfmodex.a
../../Dev-Cpp/lib/libSDL_gfx.a


Try this:

Download the linux tar.gz from http://www.fmod.org
Notice there is both a fmod.h and an fmod.hpp in the inc dir.
Put into the compile path, the compiler should compile in the correct one (fmod.h) since that is what is in my files.
There are two .03 files in the lib dir, is one of those the C version of the lib and the other the CPP?

OK I'm getting to the bottom of this.  :> Looks like FMOD Ex 4 is not open source. The download includes pre-built libraries but no source code. The "makefile" just copies the pre-built libraries into place. I think that will be OK but I have to make sure I know what it's doing. From the "makefile" script:

VERSION    = 4.03.03
LIBDIR     = api/lib
HDRDIR     = api/inc
DESTLIBDIR = /usr/local/lib
DESTHDRDIR = /usr/local/include/fmodex

I am going to uninstall Fedora's fmod 3.74 then try the makefile.

FMOD is the one "pay for" piece to the game. The built-in SDL sound libs were problomatic. That, and FMOD allows me to use a compressed XM file format that will save me about 5M off my downloadable size. I think that I will pay about $100 per OS license, once for Win, once for Mac, and once for Linux. To me, it was a close call, borderline, but in the end I deemed it worth it.

Sounds good to me. Removing the older (open-source?) fmod:

yum remove fmod
 Removing:
  fmod                    i386       3.74.1-1.2.fc4.rf  installed         431 k
 Removing for dependencies:
  fmod-devel              i386       3.74.1-1.2.fc4.rf  installed         1.8 M

Then, I believe I won't need to run the "Makefile", I should be able to use the libraries and includes from my local copy, with a little stupid trickery.

cd /home/m/development/terminus
ls
  fmodapi40303linux  fmodapi40303linux.tar.gz  terminus
ln -s fmodapi40303linux fmod
cd fmod/api
ln -s inc fmod
cd ../../terminus
g++ main.cpp -o main `sdl-config --cflags --static-libs` -I../fmod/api/ -L../fmod/api/lib/libfmodex.so

Getting further...

/tmp/cc4ahy85.o(.text+0x12): In function `main':
main.cpp: undefined reference to `TeSystem::Start()'
/tmp/cc4ahy85.o(.text+0x22):main.cpp: undefined reference to `TeStartUp::Execute()'

Awesome, that's in system.hpp. Sounds like time to build that makefile! And I see in the meantime, John's checked in another round of changes, we're at big fat [10] now, whoop! :>


I am excited! The changes I checked in last night include the "introduction movie" from the first campaign. Right now I am completing mission one. If you get the movie up and running on Linux that will be a HUGE milestone.

BTW, I hadn't planned on having any other developers on board, so the code is perhaps not quite up to my normal "team standards". I certainly have not taken any pains to "do the right thing" when the end results would be solely cosmetic. So keep that in mind as you start to dig through the code :)

Take a peek at os.cpp, that is where I planned on putting any OS specific code. Right now the only thing that could use implementing is a window centering routine. And that is a very non-critical piece - cosmetic only.

Hahaha no excuses! Seriously I haven't been up to "Earthmover" quality since... well, Earthmover. Everybody wants it done YESTERDAY!  :>

I am going to set up to build with gcc using GNU autotools. It seems to be a pretty common way of doing things, it's not too hard to set up, and once an autotools-built project is set up, maintaining it is a breeze.

Here's my script to create a new project for existing source files:

[m@thedigitalmachine terminus]$ cat ~m/scripts/setup_new_project.sh
#!/bin/bash

# MDM This sets up some default files, to prevent warnings.
touch NEWS README AUTHORS ChangeLog

# MDM We want to redo everything, kill anything that might screw us up.
rm -rf config_backup 2>&1
rm -rf autom4te.cache_backup 2>&1
mv config config_backup 2>&1
mv autom4te.cache autom4te.cache_backup 2>&1

# MDM Set up default dirs, too.
mkdir src >/dev/null 2>&1
mkdir test >/dev/null 2>&1
mkdir config >/dev/null 2>&1
mkdir doc >/dev/null 2>&1

# MDM This creates configure.scan, an initial template for configure.ac,
# based on the code it finds in the current directory.
autoscan

# MDM From http://lists.nongnu.org/archive/html/automake/2003-04/msg00226.html
# libtoolize is the tool that will install (config.sub, ltmain.sh) in your package.
# Consider also autoreconf, which will run
# libtoolize/autopoint/aclocal/autoconf/automake in the right
# order for you.
libtoolize --force

# MDM This runs all the automake tools.
bootstrap

# MDM Go ahead and configure and make, to see if it works.
./configure && make clean && make

And my boostrap script:

[m@thedigitalmachine terminus]$ cat ~m/scripts/bootstrap
#!/bin/bash

aclocal \
    && automake --add-missing --copy \
    && autoconf

Before I can run those successfully we need to create a configure.in file.

But first, where should I put the autotools files? My ShareTheDJ project has all the autotools files in the project root, and the source code under project/src. It would be nice if I could set up the autotools files under a subdirectory, since the root already has source files in it. I'll see if I can pull that off...

[m@thedigitalmachine terminus]$ ls
config.cpp       craftselect.hpp  gamedef.hpp  gamesys.hpp   mainmenu.hpp  profiles   startup.cpp  system.hpp    Terminus_private.h    util
config.hpp       data             game.hpp     main.cpp      profile.cpp   scene.cpp  startup.hpp  Terminus.ico  Terminus_private.rc   world
craftselect.cpp  game.cpp         gamesys.cpp  mainmenu.cpp  profile.hpp   scene.hpp  system.cpp   Terminus.png  Terminus_private.res  xml

Heh, you are way beyond me here. I have never used the autotools stuff. Dev-Cpp builds a makefile for me from the project settings that I set up in the IDE.

There is a bunch of stuff in the root dir that I did not put into the SC (such as the Dev-Cpp project config file) because it did not apply to the Linux build. Should that kind of stuff end up in the SC? Should it be put into a seperate repository?

I am thinking maybe stuff like that I will put into a zip and check it into the root as "windows_build.zip" with each release. NBD.

I think we should add all building configuration right into the terminus repository. Then comes the question of directory structure. Maybe something like this?

terminus/
  (source code)
  (source code subdirs)
  linux
  windows

autotools expects the source to be UNDER the autotools build directory, but I can get around that with a symlink:

terminus/
  (source code)
  (source code subdirs)
  linux
     src (just a symlink to ../)
  windows

I'm pretty sure that will work for me. Can you set up Dev-Cpp configuration under the windows subdir? If not, I say just dump the files right in with the source code, should be fine. What do you think?

I'm slowly making progress on the autotools config. SDL requires a little trickery, you have to include an autotools "M4" macro. I will wait until I get autotools working, then check in the linux directory, if that sounds OK. The only thing outside the linux directory will be one or two autotools config files in the root - I don't see a way around that - does that sound OK?

---

Back. I have screwed around with setting up autotools under the linux directory until I couldn't stand it any more. As of now I am able to compile and get code-related errors, but the autotools config files are located at the parent of the terminus source directory. Here are the files required to build:

 terminus/
   configure.in
   Makefile.am
   terminus/
     code from svn repository
     Makefile.am

Do this to set up to build:

 cd terminus
 setup_new_project.sh

From that point on I can build by typing "make". Here are the first errors I get:

In file included from world/weapon.hpp:8,
                 from world/craft.hpp:11,
                 from craftselect.hpp:9,
                 from craftselect.cpp:5:
world/bullet.hpp:23: error: type specifier omitted for parameter `szBullet'
world/bullet.hpp: In member function `TeRect TeBullet::getBoundRect()':
world/bullet.hpp:236: error: request for member `CenteredAt' in `rclBullet',
   which is of non-aggregate type `const TeRect ()(TePoint (*)())'
In file included from craftselect.hpp:9,
                 from craftselect.cpp:5:
world/craft.hpp: At global scope:
world/craft.hpp:22: error: type specifier omitted for parameter `szCraft'
world/craft.hpp: In member function `TeRect TeCraft::getBoundRect()':
world/craft.hpp:192: error: request for member `CenteredAt' in `rclCraft',
   which is of non-aggregate type `const TeRect ()(TePoint (*)())'
make[1]: *** [craftselect.o] Error 1
make[1]: Leaving directory `/home/m/development/terminus/terminus'
make: *** [all-recursive] Error 1

Bedtime...

Sorry I did not response to this last night - I was thinking about it, but did not come up with a conclusion until this morning:

terminus (the only thing that goes here is the stuff that HAS to go here, like your autotools stuff)
  src (plus subdirs)
  data (plus subdirs)
  linux (build scripts, dlls, libs, diaries, project files, etc.)
     output (obj files)
     release
        current
        1.0.0
        1.1.0
  windows (build scripts, dlls, libs, diaries, project files, etc.)
     output (obj files)
     release
        current
        1.0.0
        1.1.0

However, if you are up and running (and happy with it) let's not change things. I would have to refactor my project files, my old VSS, and the new SVN to match the changes :-(

Sounds like a plan, man! It will take a little more autotools tweaking. I would agree with you and hold off on the reorganization in the short term, though, since we both have everything working as it is. I can just tar up what's needed and put it in the root, like you had planned to do with the windoze stuff. Here's what I plan on adding, if it sounds OK:

terminus 
  (existing source code and data)
  setup_linux_build.sh
  linux/
    autotools.tar.gz

autotools.tar.gz consists of the following autotools configuration files:

configure.in                the primary autotools configuration file
Makefile.am                 makefile details for the root dir
acinclude.m4                macros needed for SDL - this is a copy of /usr/share/aclocal/sdl.m4
terminus/Makefile.am        makefile details for the source code in the terminus dir
terminus/util/Makefile.am   makefile details for util
terminus/world/Makefile.am  makefile details for world
terminus/xml/Makefile.am    makefile details for xml

After you run the setup script, you will have the following mess (which unfortunately seems to be the linux "standard"). Note that the script WILL dump files one directory above the terminus subversion repository directory.

(tons of autotools files)
config/(autotools config files)
autom4te.cache/(autotools junk)
terminus/
  (source code)
  (source code.o)
  Makefile.am
  Makefile.in
  Makefile
  (source code subdirs)
    (source code)
    (source code.o)
    Makefile.am
    Makefile.in
    Makefile

What do you think? It's not terrible I guess. And we can revisit and reorganize later. So... upwards and onwards?  :>

Yes, that is all cool. You da man!

You need any help with those errors?

Definitely! For now, here is what I am adding:

terminus 
  (existing source code and data)
  setup_linux_build.sh
  linux/
    root/
      acinclude.md4
      configure.in
      Makefile.am
    Makefile.am
    ToDo.txt (just some notes)