Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075912 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 02:34:44 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Jumpcore: A starting point for crossplatform games
Pages: [1]
Print
Author Topic: Jumpcore: A starting point for crossplatform games  (Read 1415 times)
mcc
Level 10
*****


glitch


View Profile WWW Email
« on: July 01, 2009, 12:27:13 AM »

Not sure whether to post this in Technical, Tutorials, Announcements or Feedback? But, here is another free (BSD-equivalent license) "game engine" (?) to add to the handful that have been posted lately. This one is based on the code to my game Jumpman, and comes with a fun if minimal little physics demo. There are three things that might make this code of interest to you: First, as just sample code if you are making a game with C++/SDL/OpenGL and have not done this before; second, because it comes with compile frameworks for all three platforms mac, linux and windows (and comes with some workarounds for problems in mac SDL); and third, it comes with a small but functional C++ GUI library (a much more minimal one than Lynx's kytten, but for some people's needs that may be better anyway).

The person best served by this code, I think, would be someone who is on a Macintosh and wants to develop games that run on Windows as well without requiring a Windows machine to compile on (and I think we do get people in here occasionally who are in that situation).

A copy of this post can also be found at my blog.

----

NON-PROGRAMMERS READ THIS

Here is a silly physics toy you can download:

"Typewriter"


Controls: Keyboard, mouse, F1, F4, ESC

PROGRAMMERS READ THIS

When I started writing Jumpman, something that frustrated me was that there are a couple of seemingly basic things that SDL/OpenGL doesn't actually provide out of the box, and that I couldn't seem to find a really good source for sample code for-- things like drawing text, or creating a simple GUI, or building a crossplatform binary. So once the game was done I decided to clean up my code a little, strip out the "Jumpman" parts and release the basic skeleton as open source sample code. Below is that code, and a small tutorial on setting up Mac OS X such that it can build Windows and Linux executables. The hope is to make an overall package that would allow someone starting an SDL/OpenGL game to just sit down and start writing, rather than having to spend time downloading and fiddling with libraries.

The Jumpcore package comes in two versions. A minimal version that includes only:

  • The ability to draw text (provided by the Freetype and FTGL libraries).
  • A code snippet for managing "internal files" (which live in a directory named "Internal" on windows/linux, and inside the application package in OS X)
  • Alt-tab support for OS X (SDL does not do this out of the box for fullscreen apps)
  • Makefiles (and one .xcodeproj) for Windows, Mac and Linux

And a more fully featured version that also comes packaged with:

  • The Chipmunk 2D physics library
  • The LodePNG library (and a code snippet for loading PNGs into OpenGL textures)
  • The TinyXML library
  • Some color conversion routines
  • A minimal "ControlBase" GUI library (dependent on Chipmunk, see below)
  • The "Typewriter" demo code linked at the top of this post.

The included libraries were picked in an attempt to include all the basic stuff a game needs, while still making the package as easy as possible to port and reuse in weird situations: all the libraries are self-contained and except for SDL itself can be built from the package as source where necessary; nothing depends on anything more complicated than the STL-- I avoided heavyweight dependencies like Ogre or libpng; and everything is under a BSD-like license. The biggest limitation of the package at the moment is that it's a bit mac-centric (I have not tested it with Visual Studio or Dev-C++).

Basically, here's a box full of Legos and half a robot. Have fun.

DOWNLOAD


HOW TO BUILD

Included is a Jumpcore.xcodeproj for compiling on mac, which can be compiled with XCode; windows makefile and support files are in a folder named win/, and can be compiled with mingw; Linux makefile and support files are in a folder named lin/, and can be compiled with gcc. More detailed instructions for all three platforms follow:

If you're on a mac:

To build a mac executable, from a mac: Included is a Jumpcore.xcodeproj for use with XCode; just build that in Release mode and it should produce a 10.3.9-compatible universal binary (though note, I've not specifically tested it with 10.3.9).

If you're on a mac and you want to build a Windows executable:

Here's the best way I've found to do this:

  • There is a "Cross Compilers for Mac OS X" page here that actually has OS X installers for mingw. PPC and Intel versions are included; I installed 4.3.0 for Intel. The only problem with these particular installers is they install into strange places, so whichever installer from that page you pick, write down the "Installation directory" listed to the right of it.
  • Once you've installed an installer from that page, you need to install SDL headers. In order to do this, go to the SDL download page and look under "Development Libraries" -> "Win32" -> "Mingw32". Download that tarball. Once you've downloaded it ignore the "INSTALL" file, which is full of lies, and do this: Edit the "Makefile" in the directory so that the "CROSS_PATH" on line 4 is the "Installation directory" you wrote down in step 1. Like in my case this would be:

    CROSS_PATH := /usr/local/i386-mingw32-4.3.0

    Once you've done this, run "sudo make cross" and it will install the SDL headers into your mingw directory.
  • Go into the "win/" directory. Run "make" with the argument MINGW=[Installation Directory], where [Installation Directory] is again the directory from step 1-- in my case this would be

    make MINGW=/usr/local/i386-mingw32-4.3.0

A directory named "Jumpcore" will be created with a Jumpcore.exe and all the support files necessary.

If you're on a mac and you want to build a Linux executable:

Just distribute source. No, really. Building Linux binaries for distribution is tricky, and binaries aren't what people want anyway. However if you want to do what I did and chicken out, what I recommend is installing Virtual Box or Q (probably Virtual Box, though Q is what I used) and loading up an Ubuntu install CD. This is quicker and easier than trying to set up a cross compile. Then go into the "lin/" directory and type "make".

If you're on Windows:

I was able to successfully compile Jumpcore on Windows by doing the following:

  • Download and install MinGW. (Make sure to install the C++ package.)
  • Download and install MSYS (it's part of MinGW, but a separate download)
  • As described on the MinGW install HOWTO, add C:\MinGW\bin to your path: right-click "My Computer", click "Advanced", click "Environment Variables", double-click the line that says "PATH", and in the second line add the characters ;C:\MinGW\bin
  • Go to the SDL download page and look under "Development Libraries" -> "Win32" -> "Mingw32". Download that tarball and open up its contents in MSYS. Type "make native" and it will install itself.
  • A kind of odd step: right-click the file "README.txt", open it in Wordpad, and immediately save it. (This will strip out my evil UNIX newlines.)
  • Go into the directory win/ and run: make WINDOWS=1

This will create an install directory named "Jumpcore". If you want to compile for debugging, in that last step type: make WINDOWS=1 DEBUG=1

If you're on Linux:

Install Freetype and SDL. Go into the directory lin/ and run make. This will create an install directory named "Jumpcore". If you want to compile for debugging, instead type: make DEBUG=1

GETTING STARTED

Once you get the thing built, you're going to want to start focusing on swapping out the Typewriter code for your own code. Jumpcore consists of a main.cpp that does basic bringup/teardown and event loop work hopefully good enough for most games, and makes callbacks as appropriate into a display.cpp (display logic) and a program.cpp (game logic) you provide. You'll want to implement the following methods:

In display.cpp

    display_init() - This is called once each time the display surface is initialized. It's a good place to do things like initialize fonts and textures. (Note it could be called more than once if the window size ever changes.)

    display() - This is called when it is time to draw a new frame.

    audio_callback() - This is set up as the SDL audio callback.

    drawButton ("full version" only) - This is a cpSpaceEach callback which the default display() calls on each interface item. If you want to change the appearance of the ControlBase controls this is a good place to do that.

In program.cpp

    program_init() - This is called once when the program begins.

    program_update() - The default display() calls this once per framedraw.

    program_eventkey() - This is called when SDL gets a key event.

    program_eventjoy() - This is called when SDL gets a joystick event.

    program_eventmouse() - This is called when SDL gets a mouse event.

    program_interface() - This is called after the event system finishes dispatching events to ControlBase controls, to give the interface a chance to redraw itself.

    BackOut() - Called when ESC is hit (quits).

    AboutToQuit() - Called right before the program quits.

Documentation for the individual libraries and functions included with Jumpcore can be found on these separate pages:


LIMITATIONS AND POSSIBLE FUTURE IMPROVEMENTS

I'm not really sure if this is ultimately going to be useful to anyone, and I don't intend to maintain it unless there are people actually using it. However if there turns out to be any interest in this there are a few things I'd like to improve in a future release:

  • The package contains everything you need to build a Windows version from a Mac. It would be awesome if I could eventually reach the point where a Windows user could build a Mac version (is that even possible?).
  • Linux version is poorly tested in general. I have reports of issues on 64 bit systems, and the original Jumpman code seemed to have issues with switching to and from full screen mode.
  • The final executable size is pretty large-- 2 or 3 MB compressed for the very minimal typewriter demo. I'm curious if this can be improved on. At least on the mac a large chunk of this is taken up by SDL, which gets bundled along with the executable. However, to someone who's using OpenGL to draw, a lot of this is wasted space-- because much of the complexity in SDL is taken up by the 2D drawing support. I'd like to try to swap out the SDL libraries for versions that lack 2D drawing.
  • iPhone compatibility? Now that I'm doing iPhone development I'm becoming pretty firmly convinced it does not make sense to create a single codebase that compiles on both PC and iPhone-- the platforms are too different-- but maybe it would make sense to rewrite some parts of the typewriter demo to make portability to something like iPhone easier (for example, rewriting the drawing code to be OpenGL ES-compatible).
  • I am not sure that every library included with this is the most recent version.
  • The one "every game needs this" feature that isn't in this package is configurable joystick/gamepad support. I'm not sure whether it makes sense to try to add it or not.

Finally, there have actually been a number of interesting-looking SDL "game engines" released lately, so you should be aware of those in case one fits your needs better than Jumpcore does. One I'm aware of is 2D Boy's Boy engine (though that one does not appear to come with build files for anything except Visual Studio); if you know of others feel free to share them in the comments below.
« Last Edit: July 06, 2009, 08:23:19 PM by mcc » Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
Strom
Level 0
***


niffix64@live.com.au
View Profile Email
« Reply #1 on: July 01, 2009, 03:07:31 AM »

Nice engine , to bad I do not program C/C++
Logged

See my Assemblee 2009 2D and 3D work Here. My A Game By Its Cover compo entry Journal of Shikoku.
Mattias Gustavsson
Level 1
*


Royal Leamington Spa, UK


View Profile WWW
« Reply #2 on: July 05, 2009, 05:10:27 AM »

Good stuff   Hand Thumbs Up Right

Also, just wanted to point out that Pixie is not SDL-based: it’s using DirectX directly (or if DirectX is unavailable, falls back on Windows GDI)

Logged

Who, Me? www.mattiasgustavsson.com - My blog & projects
Wizard www.rivtind.com - My Fantasy world and isometric RPG engine
Cool www.pixieuniversity.com - My Software 2D Game Engine
mcc
Level 10
*****


glitch


View Profile WWW Email
« Reply #3 on: July 05, 2009, 11:45:32 PM »

Matthias, thanks! To avoid confusion I removed Pixie from the post for now (I may add it to the blog post later if I get the chance to make a longer list of engines.)
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic