Polling SDL events in a Mac/Cocoa App?

Hello everybody,

Right now, I am developing a joy2key-like app for Mac OS X (you probably know this program =] . But, for those that dont know, it is an app for windows to simulate keyboard/mouse events with a joystick). My plan is to sell it on Mac App Store.

Its core is currently at a very advanced state, working pretty well and mostly done.
And I am using SDL, of course =] . The only mac specific stuff is the event sending code.

At first, I was planning to use only SDL, including UI rendering. But after working for some days in UI code, I realized that I won’t have time to finish it in this week*, then, I started coding the UI in cocoa, and it is mostly done.

Due to nature of cocoa, and the lack of control of the mainloop in a default Cocoa app, my first thought was to create a thread for SDL, but after q quick googling I see that the general rule is “Don’t call SDL video/event functions from separate threads” =/, does this still apply to SDL 1.3/2.0 ?

Basically, I have a usual SDL main loop polling for joystick/keyboard events.
So, what you think will be the best approach to integrate with a cocoa app and still poll for events?

Thanks for the Help!

Regards,
Rodrigo Cardoso

*(Note about my hurry: There will be some horribly sandboxing rules that will affect my app, and I want to release it before the rules start applying for new apps in March 1st. So I will have time to figure out what I need to change to comply these ugly rules…)

Well, it seems that I was too wordy. =P

In short: could anyone suggest me a good way to use SDL events in a cocoa app structure?

Thanks in advance :wink:

RodrigoCard wrote:> Hello everybody,

Right now, I am developing a joy2key-like app for Mac OS X (you probably know this program =] . But, for those that dont know, it is an app for windows to simulate keyboard/mouse events with a joystick). My plan is to sell it on Mac App Store.

Its core is currently at a very advanced state, working pretty well and mostly done.
And I am using SDL, of course =] . The only mac specific stuff is the event sending code.

At first, I was planning to use only SDL, including UI rendering. But after working for some days in UI code, I realized that I won’t have time to finish it in this week*, then, I started coding the UI in cocoa, and it is mostly done.

Due to nature of cocoa, and the lack of control of the mainloop in a default Cocoa app, my first thought was to create a thread for SDL, but after q quick googling I see that the general rule is “Don’t call SDL video/event functions from separate threads” =/, does this still apply to SDL 1.3/2.0 ?

Basically, I have a usual SDL main loop polling for joystick/keyboard events.
So, what you think will be the best approach to integrate with a cocoa app and still poll for events?

Thanks for the Help!

Regards,
Rodrigo Cardoso

*(Note about my hurry: There will be some horribly sandboxing rules that will affect my app, and I want to release it before the rules start applying for new apps in March 1st. So I will have time to figure out what I need to change to comply these ugly rules…)

RodrigoCard <cuecax gmail.com> writes:

In short: could anyone suggest me a good way to use SDL events in a cocoa app
structure?

You might want to look at SDLMain.m, which should be included
in the OS X developer archive. It has code that seems to connect
Cocoa events to SDL events. Here’s an interesting snippet:------------------------------------------------------

@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */

  • (void)terminate:(id)sender
    {
    /* Post a SDL_QUIT event */
    SDL_Event event;
    event.type = SDL_QUIT;
    SDL_PushEvent(&event);
    }
    @end

[SDLMain.m, written by Darrell Walisser and Max Horn]