[SDL] Suggestion for dynamic, custom events
Donny Viszneki
donny.viszneki at gmail.com
Tue Mar 2 18:49:44 PST 2010
Well there's some things to nitpick about here, but they aren't
relevant to the basic idea. I say write a patch!
On Tue, Mar 2, 2010 at 9:11 PM, nfries88 <nfries88 at yahoo.com> wrote:
>
> I saw it on the wishlist and thought up this approach:
> Use the current SDL_UserEvent structure alongside this function:
>
>
> Code:
>
>
>
> /**
> * \brief Registers a new type of user event
> *
> * \return 1 if registering the event is successful, otherwise 0.
> *
> * \param type Contains the value of the new type, chosen by SDL, if registration of the new event type is successful.
> */
> extern DECLSPEC SDL_bool SDLCALL SDL_RegisterUserEvent(Uint8* type);
>
>
>
>
> A companion library for SDL 1.3 that passes information through user events (such as a simplistic asynchronous I/O lib) might use it like this:
> "SDL_Companion.h"
>
>
> Code:
>
>
>
> #include
> extern Uint8 SDL_COMPANION_EVENTTYPE;
>
> int SDL_Companion_Init(Uint32 flags);
>
>
>
> "SDL_Companion.c"
>
>
> Code:
>
>
>
> #include "SDL_Companion.h"
>
> Uint8 SDL_COMPANION_EVENTTYPE = 0;
>
> int SDL_Companion_Init(Uint32 flags)
> {
> if(SDL_RegisterUserEvent(&SDL_COMPANION_EVENTTYPE))
> return 1;
> return 0;
> }
>
>
>
>
> A case of SDL_RegisterUserEvent failing would be if 7 types of user events (24 (SDL_USEREVENT) -> 31 (SDL_NUMEVENTS-1)) already exist.
> This method prevents an SDL-based application from being broken by multiple SDL-based dependencies trying to claim the same user event type (let's say, SDL_USER_EVENT); assuming it's actually used.
> It doesn't do anything to the internal state of anything else in SDL. It's implementation can be as simple as a checked increment of a Uint8:
>
>
> Code:
>
>
>
> Uint8 next_EventType = SDL_USEREVENT;
> DECLSPEC SDL_bool SDLCALL SDL_RegisterUserEvent(Uint8* type)
> {
> if(next_EventType == SDL_NUMEVENTS) return SDL_FALSE;
> type = next_EventType++;
> return SDL_TRUE;
> }
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
--
http://codebad.com/
More information about the SDL
mailing list