Game Development Community

dev|Pro Game Development Curriculum

Torque2D for Linux first release

by Frogger · 01/12/2014 (12:23 am) · 21 comments

Hello all,

After hearing about the buzz around SteamOS and how it would be nice to see Torque2D at least possible to run on those machines, I've created a branch for Linux support.

i.imgur.com/1Xmcb6q.pngi.imgur.com/PjVT117.pngFPS dropped because taking the screenshot made the Torque2D window lose focus.
i.imgur.com/9aLGKUT.png

How to get it

To get this first iteration of Torque2D for Linux, go to the GitHub repository for my fork: github.com/camporter/Torque2D. You'll either:

  1. Need to clone the repo if you want a fresh copy in a new folder
    git clone https://github.com/camporter/Torque2D.git
    then change to the linuxsupport branch with
    git checkout linuxsupport
  2. Otherwise, if you already have a Torque2D repo setup and you have no trouble moving between git branches, you can quickly get the linuxsupport branch by first setting up tracking the linuxsupport branch in your repo:
    git remote add -t linuxsupport camporter https://github.com/camporter/Torque2D.git
    then fetching the linuxsupport remote branch:
    git fetch camporter
    then finally switching to the linuxsupport branch by doing
    git checkout linuxsupport

For those building Torque2D on other platforms, please test that I haven't broken your builds or caused any bugs. I'm contemplating grabbing a Mac Mini so that I can to make sure that OSX stuff doesn't break. Haven't bothered getting VS set up on Windows to make sure things still work, but they most likely do.

This build was done on top of the last commit on the current Torque2D development branch.

Changes in the first commit

  1. Add new folder with makefiles (source/compilers/Make).
  2. Move the 'box2d folder to 'Box2D'. Update all references to the old folder to the new folder in all makefiles, project files, and includes. Most platforms are not affected, since they have case insensitive filenames.
  3. Fix up includes to match the case of the header file.
  4. Fix OpenAL problems. We now expect to load libopenal.so.1 using standard paths or at least expect that it exist in the same folder as the executable. There's lots of ugly OpenAL stuff going on still, but I tested audio and it seems to be working fine.
  5. Fix some other problems due to incompatibilities with gcc and also undefined standard C++ behavior (such as with dSprintf's use of vsnprintf in certain cases).
  6. Fix minor issue with cpu freq reporting.
  7. Ripped CD audio/Redbook out. Don't think anyone's going to miss it.
  8. Other things I can't think of off the top of my head.

Known issues

  1. No cursor! This can be solved by changing SDL_ShowCursor(SDL_DISABLE); to SDL_ShowCursor(SDL_ENABLE); in UInputManager::activate()
  2. SDL 1.3 has lots of ugliness associated with it in the current code. The next piece of the project will be to get SDL 2.0 going. Ideally a lot of the current Xlib crap will be able to go away at the same time :)
  3. There's lots of things that should be defined at the platform layer that don't exist at the moment. Most of these aren't heavily used by the current codebase or scripts that exist.

32-bit building

If you're like me and you run a 64-bit machine, you'll want to setup a build environment just for building 32 bit programs such as Torque2D. My preferred method is to setup a chroot for this purpose and manage and access it easily.

For Debian-based users, here's a slightly old article about doing this here: help.ubuntu.com/community/DebootstrapChroot. Replace 'hardy' references with 'saucy' if you use Ubuntu, otherwise you can get this same information for Debian as well. Other distros can try something similar, or a bit more complex way is to setup something like VirtualBox, however that is more painful when you just want your chroot to be able to access the files in your home folder directly and easily.

How to build

First, you'll need the libraries below (if you're using a chroot like I explained above, make sure you are logged in as the root user in your chroot when installing the necessary packages).

  1. build-essential
  2. libsdl-dev
  3. libxft-dev
  4. libopenal-dev
  5. nasm

Then, in a 32 bit environment, change directories to engine/compilers/Make and run
make -f Torque2D.makefile debug -j<#CORES>
while making sure to replace the number of cores with however many you have to speed up the build process. With an 8-core i7, I get
real	0m26.881s
user	2m56.995s
sys	0m11.218s
which is pretty awesome in my opinion.

Running

After you've compiled the 32-bit binary, you should be able to run it in a 64-bit environment.

I haven't performed any tests on any drivers besides the proprietary Nvidia ones as shown in the output above. However, considering how well it runs (steady 60 FPS unless tens of thousands of sprites are on-screen), there shouldn't be issues.

Future Plans

Hopefully these changes can be merged into the official codebase at some point, but more work needs to be done first.

Now, how do I convince Valve to give me a dev Steambox to start testing on their official hardware and new controller? :P

Enjoy!

About the author

Recent Blogs

• New stuff
• Stuff
• Plan for Frogger
• Plan for Frogger
• Plan for Frogger
Page «Previous 1 2
#1
01/12/2014 (1:42 am)
Phenomenal achievement! I'm going to try this now since running through wine is too slow.
#2
01/12/2014 (3:09 am)
Great work!

If you want 64bit support, I made a patch for 64bit support last year which has yet to be merged in, see https://github.com/GarageGames/Torque2D/tree/sixtyfoursupport

I ported the engine code to emscripten a while back which uses a variant of the SDL 1.3 API.

There is a slight problem in removing the XLib stuff, and that is X11_KeyToUnicode. This is used to generate the corresponding keycodes when using SHIFT (etc). In my emscripten port I had to just make my own table.

Ideally for text input it should probably be using the SDL_TEXTINPUT stuff in SDL 2.0.

Also I had to redo the input event loop so it uses SDL_PollEvent instead and stores everything in an array for inspection by the input mangers and such.
#3
01/12/2014 (3:27 am)
Is "-j<#CORES>" what I'm actually supposed to type in or did something get lost in translation? How would the steps differ if I were to also merge the 64bit support branch?
#4
01/12/2014 (5:43 am)
Very good news.

Thanks for your work.
#5
01/12/2014 (7:29 am)
This is very cool! Thanks for sharing!
#6
01/12/2014 (7:53 am)
Huge thank you for working on this!

I tested your branch on OSX, built fine and no issues so far running the sandbox toys.

As a general question to everyone, would it be good to have all platforms use SDL 2.0 for stuff like window and input event management (maybe audio) or would that be a ton of work for little benefit?
#7
01/12/2014 (11:47 am)
Thanks all!

James,
I haven't tried merging in the 64-bit stuff yet, but I'd imagine things will work relatively well without too much trouble.
Really cool stuff with the emscripten port! I'm surprised at how well Torque2D handled in the browser.
Thanks for the tips on input handling, that ugliness is why SDL 2.0, GLFW, or something is a really good idea.

practicing101,
I made the mistake of using angle brackets :) Just replace that flag with -j# where # is the number of simultaneous tasks Make should work on.

Luis,
Thanks for your work on Torque3D linux/opengl stuff. The makefiles are very similar to the final output that the torque project generator creates, hopefully that keeps the build process somewhat familiar between the two :)

Mike,
Good to hear! I'm glad nothing broke.
My opinion is that it probably would help with platform maintainability, but since the other platforms seem to be working fine, it probably shouldn't take priority unless there are plans for example to move the project to use OpenGL 3/4 contexts, which I remember seeing a branch for somewhere.
#8
01/12/2014 (2:09 pm)
Awesome!
#9
01/12/2014 (7:51 pm)
Fantastic work, and thanks! So cool to see people jumping in and doing excellent stuff like this.

Quote:I ported the engine code to emscripten a while back
You did what? (I know what emscripten is; what was the outcome?)
#10
01/13/2014 (3:57 am)
@Daniel - I had actually stumbled upon James' emscripten blog a few days ago by accident. The outcome is in a link at the bottom of his post. (Unfortunately it didn't work for me in Safari, the console reported that it couldn't create a Canvas)

www.cuppadev.co.uk/2013/12/torque2d-in-a-web-browser/
#11
01/13/2014 (8:17 am)
I merged the 64bit branch after merging the linus branch and since I'm a newbie I had to manually change filename cases again... Also had compiler errors and I tried using google to resolve them. I probably broke everything...

s8.postimg.org/4pndkpjdx/Screenshot_from_2014_01_13_12_12_59.png
Edit: Release doesn't compile. Debug compiles with *dev:i386 but has gfx problems, after a compile with i386 and then a reinstall of the regular files, it works fine. Perhaps it has to do with the 64bit branch merge? I don't have a clue what's going on :).

s8.postimg.org/9mo33cf39/Screenshot_from_2014_01_13_13_08_49.png
#12
01/13/2014 (9:00 pm)
Yeah, there's likely some platform-related changes that need to be made in order for the 64-bit support to be compatible with the linux port at the moment. I'll try to work on getting a separate branch working for that, but probably after SDL 2.0 is added.
#13
01/14/2014 (7:21 am)
Guys, you Rock!
#14
01/15/2014 (9:14 pm)
@Frogger - we're looking to get T2D 3.0 out the door in a few weeks time and it would be really nice to be able to promote Linux support in addition to the Android port. I don't want to put you under any stress regarding future updates - work on this at your own pace - but could we take what is available now and merge it into the development branch?
#15
01/18/2014 (1:56 pm)
Sweet. I wanted to get it working on linux but required money to do so since I did not have the free time for unpaid work. Since a kickstarter likely was not gonna happen, I am glad someone else did the work.

Now all we are missing is a Metro port :p
#16
01/18/2014 (2:23 pm)
Hey Mike, it'd be great to see the current linux support added to development. It's a bit messy still (though I suppose it's been messy for a while now), but that would make it easier for people to start testing in development.

Tim, it was great to get my hands dirty with C++ again, and actually not as much work as I thought it would be :) Certainly there are a lot of improvements that can still be made to clean stuff up at that level. 64 bit support and OpenGL 3/4 contexts will also play a factor in that as well.

I've managed to get SDL 2.0 working, albeit running slowly and with partially broken input, so that probably won't be ready for a while, but hopefully the existing linux stuff can be added.

I'll prep a pull request then!
#17
01/19/2014 (4:28 am)
@Frogger, I intend to to add SDL2 to T3D, I hope to help you with something.
#18
01/20/2014 (7:52 pm)
Sure, I'm mostly fighting with the way the Torque input system works right now. Since the old code was expecting to be able to translate key codes into unicode characters for torque to use, I'm not sure what needs to be done. I suppose the mappings could be hard-coded, but that seems pretty ugly and there's likely something I'm missing. After SDL2, there won't be any traces of Xlib in T2D hopefully!

Using SDL2, two windows pop up and a lot of stuff is still broken :)
#19
01/21/2014 (4:09 am)
In a few days i'll port the native menus and dialogs to Torque3D GUI for use with SDL on all platforms.

If you have not begun your with that, dedicate yourself to other things and I am responsible for that.
#20
02/12/2014 (5:39 am)
Hey Frogger. Any progress on the known issues, particularly #1 and #3?
Page «Previous 1 2