declared Asset trait combining Drop with a getter and setter for an asset id
This commit is contained in:
parent
67b751c136
commit
6e61a7666a
34
src/asset.h
Normal file
34
src/asset.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef _fencer_asset_h
|
||||
#define _fencer_asset_h
|
||||
|
||||
#include "drop.h"
|
||||
#include "typeclass_helpers.h"
|
||||
#include <SDL2/SDL_render.h>
|
||||
|
||||
typedef uintptr_t asset_id;
|
||||
|
||||
typedef struct {
|
||||
asset_id (*const get_id)(void*);
|
||||
void (*const set_id)(void*, asset_id);
|
||||
} IAsset;
|
||||
|
||||
typedef struct Asset {
|
||||
void* data;
|
||||
IAsset const* tc;
|
||||
IDrop const* drop;
|
||||
} Asset;
|
||||
|
||||
#define impl_Asset_for(T, get_id_f, set_id_f)\
|
||||
static inline Asset T##_as_Asset(T* x) {\
|
||||
TC_FN_TYPECHECK(asset_id, get_id_f, T*);\
|
||||
TC_FN_TYPECHECK(void, set_id_f, T*, asset_id);\
|
||||
TC_FN_TYPECHECK(Drop, T##_as_Drop, T*);\
|
||||
static IAsset tc = (IAsset){\
|
||||
.get_id = (asset_id(*const)(void*)) get_id_f,\
|
||||
.set_id = (void(*const)(void*,asset_id)) set_id_f,\
|
||||
};\
|
||||
IDrop const* drop = T##_as_Drop(x).tc;\
|
||||
return (Asset){.data=x, .tc=&tc, .drop=drop};\
|
||||
}
|
||||
|
||||
#endif // !_fencer_asset_h
|
Loading…
Reference in a new issue