Skip to content

cResource

Stephen P edited this page Oct 14, 2021 · 4 revisions

Holds a programmer-implemented object. It doesn't offer any functionality on its own; the programmer must provide a drawing and cleanup routine.

Members

subclass

void*
Holds a pointer to whatever struct or datatype you want, casted into void*. This is what you're passing into drawingRoutine to draw, and cleanupRoutine to de-allocate (if necessary).

drawingRoutine

void (*drawingRoutine)(void*, cCamera)
The function pointer to your custom draw routine. The subclass what is passed into the function through the void* argument (i.e. when called, it is called as such: yourCResource->drawingRoutine(yourCResource->subclass, camera);)
Note that of course you must cast the void* argument back to whatever struct or datatype your subclass initially was.

cleanupRoutine

void (*cleanupRoutine)(void*)
The function pointer to your custom cleanup routine. Again, the subclass is what will be passed into this method at runtime. If no cleanup is required, initialize this as NULL.

Functions

initCResource

void initCResource(cResource* res, void* subclass, void (*drawingRoutine)(void*, cCamera), void (*cleanupRoutine)(void*), int renderLayer)
This will initialize the cResource you pass in with the data passed in. Pass NULL for cleanupRoutine if no cleanup routine is required.

drawCResource

void drawCResource(cResource* res, cCamera camera)
All this does is call your custom draw routine with your subclass data and the given camera as arguments.

destroyCResource

void destroyCResource(cResource* res)
All this does is call your custom cleanup routine with your subclass data as the argument. If the custom cleanup routine is NULL, this will be skipped.

Clone this wiki locally