sgdk
|
Base object management unit. More...
#include "pool.h"
Go to the source code of this file.
Classes | |
struct | Object_ |
Base object structure. More... | |
Defines | |
#define | OBJ_ALLOCATED 0x8000 |
Allocated state for object (mainly useful for debugging) | |
Typedefs | |
typedef struct Object_ | Object |
Base object structure. | |
typedef void | ObjectCallback (Object *obj) |
Object function callback. | |
Functions | |
Pool * | OBJ_createObjectPool (u16 size, u16 objectSize) |
Create and allocate the new object pool (this method is an alias of POOL_create(..)) | |
Object * | OBJ_create (Pool *pool) |
Create a new objet from the given object pool (object must extend basic Object structure) | |
void | OBJ_release (Pool *pool, Object *object, bool maintainCoherency) |
Release an objet from the given object pool (object must extend basic Object structure) | |
void | OBJ_updateAll (Pool *pool) |
Iterate over all active objects from the given object pool and call update method for each of them. | |
void | OBJ_setInitMethod (Object *object, ObjectCallback *initMethod) |
Set the initialization method for the given object. | |
void | OBJ_setUpdateMethod (Object *object, ObjectCallback *updateMethod) |
Set the update method for the given object. | |
void | OBJ_setEndMethod (Object *object, ObjectCallback *endMethod) |
Set the ending method for the given object. |
Base object management unit.
This unit provides methods to manage objects.
It works in concert with the pool.h unit which provide dynamic object allocation.
The idea of Object is that you can use it as base structure for your own object (entity, enemy, character, whatever you want..).
To do that the idea is to declare your new object structure by embedding the Object into it can be anonymous) and always at the first position:
struct entity_ { Object; f32 posX; f32 posY; Sprite* sprite; ... };
Doing that your Entity structure can be used through OBJ_xxx methods.
Base object structure.
internalState | Object internal state, you can use it but you should save bit 15 as it's used internally to detect invalid object |
type | Object type, can be used to recognize the underlying object / structure type. |
init | Initialisation function callback, should be only called once after object creation |
update | Update function callback, usually called once per frame |
end | Ending function callback, should be only called once before object release |
typedef void ObjectCallback(Object *obj) |
Object function callback.
obj | Object |
Create a new objet from the given object pool (object must extend basic Object structure)
pool | Object pool to allocate from (see pool.h unit) |
Create and allocate the new object pool (this method is an alias of POOL_create(..))
size | the capacity of the pool (in number of object) |
objectSize | the size of a single object (usually you should use sizeof(Struct) here) |
Release an objet from the given object pool (object must extend basic Object structure)
pool | Object pool allocator to release from (see pool.h unit) |
object | Object to release (must extend basic Object structure) |
maintainCoherency | set it to TRUE if you want to keep coherency for stack iteration and use OBJ_updateAll(). Set it to FALSE for faster release process if you don't require object iteration through alloc stack. |
void OBJ_setEndMethod | ( | Object * | object, |
ObjectCallback * | endMethod | ||
) |
Set the ending method for the given object.
object | Object to set end method for |
endMethod | the method to set for object destruction (should be called just before object is released) |
void OBJ_setInitMethod | ( | Object * | object, |
ObjectCallback * | initMethod | ||
) |
Set the initialization method for the given object.
object | Object to set init method for |
initMethod | the method to set for object initialization (should be called after object creation) |
void OBJ_setUpdateMethod | ( | Object * | object, |
ObjectCallback * | updateMethod | ||
) |
Set the update method for the given object.
object | Object to set update method for |
updateMethod | the method to set for object update (should be called once per frame) |
void OBJ_updateAll | ( | Pool * | pool | ) |
Iterate over all active objects from the given object pool and call update method for each of them.
pool | Object pool to update all objects from. |