Allegro.cc - Online Community

Allegro.cc Forums » The Depot » [CH05] Santa Sleigh Race

This thread is locked; no one can reply to it. rss feed Print
 1   2 
[CH05] Santa Sleigh Race
BAF
Member #2,981
December 2002
avatar

Pole Position from the Atari... plus you have the modern remakes of it and those little games you plug into the tv that have older games on it.

Thomas Harte
Member #33
April 2000
avatar

Well, I've started porting the various ChristmasHack entries to OS X, and have attempted Santa Sleigh Race as my first.

I had to make two changes to the code to reflect the different file structure expectations of an OS X program (i.e. one icon representing a bundle) compared to Linux/Windows (i.e. lots of files thrown into a directory completely visible to the user) and the work already done within Allegro to help with that. At the top of load_track in track.c, I substituted the following:

#ifndef ALLEGRO_MACOSX
  get_executable_name(path, 1024);
  TRACE("exe: %s\n", path);
  replace_filename(path, path, file, 1024);
  TRACE("track: %s\n", path);
#else
  strcpy(path, file);
#endif

Very similarly indeed, I modified init_framework in framework.c to:

#ifndef ALLEGRO_MACOSX
DEBUG
  /* Construct aboslute path for the configuration file. */
  get_executable_name(config_path, PATH_LENGTH);
  replace_filename(config_path, config_path, "allegro.cfg", PATH_LENGTH);

DEBUG
  /* Construct aboslute path for the datafile containing game data. */
  get_executable_name(data_path, PATH_LENGTH);
  replace_filename(data_path, data_path, "game.dat", PATH_LENGTH);
#else
  sprintf(data_path, "game.dat");
  sprintf(config_path, "allegro.cfg");
#endif

As I'm no artist whatsoever, I've just reused the Windows icon. OS X likes to have a 128x128 icon around, but I've done nothing about that.

A compiled version, alas slightly too big to attach, is available at http://members.allegro.cc/ThomasHarte/osx/SantaSleighRace.zip. I still don't trust that the Allegro XCode template is embedding the Allegro framework, so this binary may require Allegro to be installed. I need to look into that more properly as it affects every binary I release.

The only thing I noticed that seemed odd about the game is that if you start a new game and press up/down without any prior attempt to turn then the sleigh moves straight up and down the y axis. Possibly something isn't initialised somewhere?

Other than that I found it to be quite fun, if very difficult. Would it not be possible to move the camera out a little?

Billybob
Member #3,136
January 2003

If only I had OS X in VMWare...

Matthew Leverton
Supreme Loser
January 1999
avatar

Thomas Harte said:

I still don't trust that the Allegro XCode template is embedding the Allegro framework, so this binary may require Allegro to be installed.

I prefer just using the command line for this.

# make -f makefile.linux
# cd ..
# fixbundle SantaSleighRace -e

Then, go into the Resources folder, create "SantaSleighRace" (same as executable name) and copy all the data files in there. The changes you made to the source obviously still apply.

I also manually copied the icon file (after creating it with Icon Composer) into the Resources file and updated the plist file accordingly. I think fixbundle is supposed to be able to do this, but it never worked for me.

If you want to compare my bundle with yours: SantaSleighRace

Thomas Harte
Member #33
April 2000
avatar

Quote:

Then, go into the Resources folder, create "SantaSleighRace" (same as executable name) and copy all the data files in there.

Oh, I've patched my copy of Allegro so that I don't have to live with its stupid internal folder naming. So that's one obvious area in which our application bundles vary. Otherwise I note you have the framework embedded whereas I definitely do not, and I'm following that observation up in the correct forum.

miran
Member #2,407
June 2002

Mac OS X is confusing :P

--
sig used to be here

Thomas Harte
Member #33
April 2000
avatar

Quote:

Mac OS X is confusing

Well, I'm annoyed now because Firefox 1.5 has once again decided that switching from one tab to another means the tab switched to should be reloaded - throwing away my post. It's a good thing I'm not a violent man or I might not have a computer any more.

Anyway, blah blah blah OS X is very straightforward and easy for the end user, bundles make a lot of sense but Allegro is confusing.

A bundle is just a hierarchy of folders and files - like any other folder in the filesystem - except that it is graphically represented to the user as a single icon and if you double click an application bundle then the binary at a particular place in it is launched. Most frequently OS X applications come as .DMG files, which are virtual disk images. You mount the image (by double click), drag the included application bundle to wherever you want to keep it (usually /Applications - some DMGs come with symbolic links to /Applications in them so that you only have to drag the icon about two centimetres even if the other convention of whacking icon sizes up to full size in DMGs is followed), then unmount the disk image (drag the drive to the trash or right click and select eject) and, probably, throw the DMG into the trash too. To uninstall you drag the application bundle to the trash.

Also not uncommon is to see applications distributed as .zip or .sit, which are usually just the application bundle in a more traditional archive format. In the Mac world .sit was a de facto standard before they realised that they weren't somehow masters of the universe able to live in their own bubble with their own standards, etc.

It isn't just applications that are bundled. Ordinary data sometimes is also - for example XCode projects are. So rather than the VC6 collection of a .dsw, a .dsp, a .ncb, etc, you just see one "file" in your project directory.

Bundles are not an OS X invention. They were in NextStep and, presumably independently as both arrived in 1989, RISC OS. Due to their NextStep heritage they also exist in GNUstep. Because the folder conventions are preserved, it would be perfectly feasible to produce an Allegro based fat binary that supported both GNUstep and PPC OS X out of the box as long as you didn't rely very heavily at all on any other common APIs being in place. OS X does retain a lot of its NextStep heritage, e.g. the base class for applications is still NSApplication, the thing representing a bundle is still NSBundle, and most things other than specifics of the widget set are carried over. My guess is that Intel OS X will expect to find its application binary in the same place in the bundle as you'd place an intel GNUstep though, so this possibility probably won't hang around for very much longer.

In a sense the Application framework provides a third option for linking. Frameworks are essentially similar to DLLs and SOs (albeit better at versioning) and may be dynamically linked against as you'd expect. If you build a BSD style lib<whatever>.a then you can statically link against that. But you can also dynamically link against a framework and then include it in the bundle. That gives the usability advantages of static linking in that the user doesn't have to install any special frameworks or in any other way maintain multiple "files". It also means that a competent user could update the embedded framework with a newer version if they chose, so brings LGPL compatibility.

Allegro has been a confusion. As you see, Matthew prefers to use the commandline and does a reasonable amount by hand. I prefer to use XCode, the Apple |DE. As it turns out the project template provided by Allegro doesn't embed the framework even if you've built it to be embeddable. You'll see I've posted instructions to fix that to the Installation, Setup & Configuration forum + a substitution project template for users of XCode 2.0 or above. Now, when I press XCode's build button (or hit command+b!) it does everything necessary and leaves me with a perfectly formed bundle - no manual copying or editing of anything. So the process is really as simple as it could possibly be.

To Matt:

As you're at the commandline, have you performed

export MACOSX_DEPLOYMENT_TARGET=10.2
export NEXT_ROOT=/Developer/SDKs/MacOSX10.2.8.sdk

And added -L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 to your linker somewhere so that you aren't just building for whatever version of OS X you have and upwards?

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

As you're at the commandline, have you performed

No, I was unaware of any such options.

However, I think I am on gcc 3.3 via gcc_select. (I should be, unless I switched back to 4.) That's all it takes with Allegro to get it backward compatible with older versions. I know Peter Hull has an older version of OS X, and he was able to run my programs that were compiled with GCC 3 (but not 4).

 1   2 


Go to: