diff --git a/src/common.h b/src/common.h index 30667538..ca0f464a 100644 --- a/src/common.h +++ b/src/common.h @@ -161,8 +161,9 @@ extern "C" { #define INTERNAL static #define GLOBAL static +/* Storage specifiers */ #pragma section(".roglob", read) -#define READONLY __declspec(allocate(".roglob")) +#define READ_ONLY __declspec(allocate(".roglob")) /* Markup */ #define UNUSED void @@ -238,6 +239,19 @@ extern "C" { #define CAT1(a, b) a ## b #define CAT(a, b) CAT1(a, b) +/* ========================== * + * Nil structs + * ========================== */ + +/* Declare */ +#define DECLARE_NIL_STRUCT(type, function_name) \ + extern READ_ONLY type CAT(__nil_struct__, function_name); \ + INLINE READ_ONLY type *function_name(void) { return &CAT(__nil_struct__, function_name); } + +/* Expects struct body after invocation. E.g. DEFINE_NIL_STRUCT(struct a, a_nil) { 0 } */ +#define DEFINE_NIL_STRUCT(type, function_name) \ + type READ_ONLY CAT(__nil_struct__, function_name) + #if 0 /* ========================== * * Bit utils @@ -412,11 +426,9 @@ struct v4_array { }; struct xform { - struct { - struct v2 bx; /* X basis vector (x axis) */ - struct v2 by; /* Y basis vector (y axis)*/ - struct v2 og; /* Translation vector (origin) */ - }; + struct v2 bx; /* X basis vector (x axis) */ + struct v2 by; /* Y basis vector (y axis)*/ + struct v2 og; /* Translation vector (origin) */ }; struct mat4x4 { diff --git a/src/entity.c b/src/entity.c index 87cd72c9..3c226d76 100644 --- a/src/entity.c +++ b/src/entity.c @@ -1,6 +1,6 @@ #include "entity.h" -READONLY struct entity _g_entity_nil = { 0 }; +DEFINE_NIL_STRUCT(struct entity, entity_nil) = { 0 }; /* ========================== * * Prop diff --git a/src/entity.h b/src/entity.h index e0e62c6d..90e44c59 100644 --- a/src/entity.h +++ b/src/entity.h @@ -96,14 +96,7 @@ struct entity { f32 camera_zoom; }; -/* Nil entity */ - -extern READONLY struct entity _g_entity_nil; - -INLINE READONLY struct entity *entity_nil(void) -{ - return &_g_entity_nil; -} +DECLARE_NIL_STRUCT(struct entity, entity_nil) /* Prop */