sokol_app.h: user pointer for callback functions

Created on 18 Feb 2019  路  9Comments  路  Source: floooh/sokol

Hey, is there plan for a user pointer that would be passed in to the sapp callback functions? The only other option is to use a global, which I'd rather not do.

enhancement

Most helpful comment

Don't worry, I'm currently on sokol_app.h anyway, and it's just a small feature. Will happen in the next couple of days :)

All 9 comments

Hmm, yeah, probably makes sense. I'll think about it, not sure yet whether to break compatibility, or add a second set of callbacks with a userdata param.

...I think I will add a separate set of callback functions, so the sapp_desc would get new callback pointers with a different function signature (in addition to an void* user_data):

    void (*init_userdata_cb)(void*);
    void (*frame_userdata_cb)(void*);
    void (*cleanup_userdata_cb)(void*);
    void (*event_userdata_cb)(const sapp_event*, void*);
    void (*fail_userdata_cb)(const char*, void*);

For each callback type, the user code can than either use the version with, or without user_data.

Ah that's clever! I can try implementing it if you're swamped.

Don't worry, I'm currently on sokol_app.h anyway, and it's just a small feature. Will happen in the next couple of days :)

FYI the user_data stuff is tracked in this PR: https://github.com/floooh/sokol/pull/120

Just a bit more testing and then its ready.

May I suggest a similar addition to the stream callback function in sokol_audio?

May I suggest a similar addition to the stream callback function in sokol_audio?

yep, good idea, totally forgot about that

Ok, this is fixed in 77c2b42e2ee26c86541dbf40acf6b99d0529d20d, both sokol_app.h and sokol_audio.h now have an alternative set of callbacks with userdata.

I have changed the noentry-sapp.c and modplay-sapp.c samples as test and demo.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DomDumont picture DomDumont  路  6Comments

SrMordred picture SrMordred  路  4Comments

floooh picture floooh  路  7Comments

pjako picture pjako  路  3Comments

amerkoleci picture amerkoleci  路  4Comments