S3D_SET_CALLBACK(3)
π S3D_SET_CALLBACK π
okay bestie, gather round, we're doing the s3d manual today (yes, the whole manual name, it's giving β¨officialβ¨) and this one is genuinely one of my faves because it's all about callbacks π
πΈ NAME πΈ
s3d_set_callback β sets a callback π«Ά
like. that's the whole job. it sets a callback. iconic behaviour honestly.
β¨ SYNOPSIS β¨
#include <s3d.h>
void s3d_set_callback(uint8_t event, s3d_cb func);
π¦ DESCRIPTION π¦
So what this does is it sets a callback for a certain event. and like⦠that's so useful if you're building an event-oriented application, fr fr. you just go "hey s3d, when this happens, run this function for me" and it does. no cap.
One thing you gotta know though: event callbacks will not interrupt each other, and they will not interrupt the mainloop. so no chaos, no stepping on each other's toes, everyone waits their turn like civilized little functions π
β οΈ Warning β οΈ Defining callbacks will only work after callings3d_init(). do not skip that step, i am begging you. nos3d_init(), no callbacks. periodt.
and here's the lil example they gave us, keep it, love it, it's literally the blueprint:
#include <inttypes.h>
void obj_click(struct s3d_evt event)
{
printf("object id %"PRIu32" got clicked", *((uint32_t *)event->buf));
}
...
s3d_set_callback(S3D_EVENT_NEW_OBJECT, obj_click);
// this will tell you when a object got clicked
see that? S3D_EVENT_NEW_OBJECT + your function = it will tell you when a object got clicked. that's it. that's the vibe check and it passed π₯
π AUTHOR π
Simon Wunderlich Author of s3d π
like, the actual author. the main character. we stan. π«Ά
and that's a wrap on this one!! the s3d manual, page S3D_SET_CALLBACK(3) β catch you in the next one bestie πβ¨πΈ
π¦ where this page comes from
- debian bookworm: s3d-doc 0.2.2.1-5 Β· GPL-2.0-or-later
- debian trixie: s3d-doc 0.2.2.1-7 Β· GPL-2.0-or-later
- ubuntu jammy: s3d-doc 0.2.2.1-3build1 Β· GPL-2.0-or-later
- ubuntu noble: s3d-doc 0.2.2.1-6build3 Β· GPL-2.0-or-later
- ubuntu questing: s3d-doc 0.2.2.1-7build1
- ubuntu resolute: s3d-doc 0.2.2.1-7build3 Β· GPL-2.0-or-later
- ubuntu stonking: s3d-doc 0.2.3-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms