Topic: Port to SDL2

While working on the Android build of Maratis I realized that I yet again had to re-implement, duplicate or stub out the MWindow and related stuff for the new platform. As code duplication is a bad thing and makes maintenance harder than it should be, I decided to instead venture into getting rid of most of our own platform specific code and unify all platforms with SDL2 as it support Windows, Linux, OSX, iOS and Android. The begining of this work is now commited to my development branch on GitHub.

The only platform specific code left in "vanilla" Maratis is MWindow::getTempDirectory, MWindow::getCurrentDirectory, MWindow::setCurrentDirectory, MWindow::setWorkingDirectory and MWindow::execute. While the partials for X11 and WIN32 in C++ is a no-brainer I'm not sure if the equivalent COCOA bit in Objective-C actually can be done that way (as I don't have OSX to test on).

Some of the features of moving to SDL2 is force-feedback and hot-plugable support for joysticks and gamecontroller.

Using the game controller events and semantics makes all joysticks that SDL2 has a mapping for look like an XBox 360 controller to the game engine and makes the buttons and axes on non-XBox controllers map to similar or similarly placed buttons and axes to the user. E.g. the A/B buttons on an X360 Controler is button 0/1 respectively, but on other controllers button 0/1 might be the X/Y button while A/B being 2/3, SDL2 sort all this out and maps them consistently.

So instead of JOY1_BUTTON1, MOTION_X and so on, the semantics has changed to JOY1_BUTTON_A, JOY1_AXIS_LEFTX and so on in Lua. The number of controllers available via Lua has also been upped to four (of course a game can support any number of controllers via the C++ API.) Here is a full list of the available button and axis literals available:

JOY1_BUTTON_A
JOY1_BUTTON_B
JOY1_BUTTON_X
JOY1_BUTTON_Y
JOY1_BUTTON_BACK
JOY1_BUTTON_GUIDE
JOY1_BUTTON_START
JOY1_BUTTON_LEFTSTICK
JOY1_BUTTON_RIGHTSTICK
JOY1_BUTTON_LEFTSHOULDER
JOY1_BUTTON_RIGHTSHOULDER
JOY1_BUTTON_DPADUP
JOY1_BUTTON_DPADDOWN
JOY1_BUTTON_DPADLEFT
JOY1_BUTTON_DPADRIGHT

JOY1_AXIS_LEFTX
JOY1_AXIS_LEFTY
JOY1_AXIS_RIGHTX
JOY1_AXIS_RIGHTY
JOY1_AXIS_TRIGGERLEFT
JOY1_AXIS_TRIGGERRIGHT

Since these are consistent the equivalent set of enums are now available in the C++ API. It is also possible to use the joysticks directly and ignore all the remapping in the C++ API.

With SDL2 mouse motion and button events will be generated by touch devices on e.g. iOS and Android in addition to actual touch events. So the game does not need to be touch aware to work on iOS/Android if it primarily uses the mouse for input. However, there is lot of touch support in SDL2 I have not yet taken advantage of, like multi gestures and dollar gestures.

I am also working on making Maratis more event driven so that systems that produce events (e.g. MWindow) and systems that consume them (e.g. the game, game engine and gui) can be decoupled (it will be up to the consumer subsystem to keep track of state.) This is also a preparation for any future work on adding network support.

SDL2 related things on my todo list:

  • Add force-feedback support.

  • Add multi gesture and dollar gesture support.

  • Refactor MKeyboard and MMouse out from MWindow.

  • Move MWindow (and MWinEvents) from MGui into Common.

  • Ehem... maybe finish the Android build that started it all.

  • Port the iOS build to SDL2

Last edited by Dahnielson (2014-03-12 11:29:54)

Re: Port to SDL2

Hi,
I had a fast look at it and it's very interesting.

Just so you are aware, some months ago I started a rewrite of MGui in the Experimental branch of Maratis SVN :
https://code.google.com/p/maratis/sourc … 2FIncludes
(with some important compatibility breaks and the isolation of the GUI code from data management)

I also started to replace all internal platform code by using the new version of GLFW :
https://code.google.com/p/maratis/sourc … 253Dclosed