diff --git a/src/Camera.c b/src/Camera.c index 55f8a77c3..765c18e2a 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -260,12 +260,7 @@ void Camera_CycleActive(void) { static struct Camera* cams_head; static struct Camera* cams_tail; void Camera_Register(struct Camera* cam) { - if (!cams_head) { - cams_head = cam; - } else { - cams_tail->Next = cam; - } - - cams_tail = cam; + LinkedList_Add(cam, cams_head, cams_tail); + /* want a circular linked list */ cam->Next = cams_head; } diff --git a/src/Chat.c b/src/Chat.c index 39f9d92af..3084f592f 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -216,14 +216,7 @@ static bool Commands_IsCommandPrefix(const String* str) { } void Commands_Register(struct ChatCommand* cmd) { - if (!cmds_head) { - cmds_head = cmd; - } else { - cmds_tail->Next = cmd; - } - - cmds_tail = cmd; - cmd->Next = NULL; + LinkedList_Add(cmd, cmds_head, cmds_tail); } static struct ChatCommand* Commands_GetMatch(const String* cmdName) { diff --git a/src/Funcs.h b/src/Funcs.h index f15c62ae4..0c5d2754f 100644 --- a/src/Funcs.h +++ b/src/Funcs.h @@ -32,4 +32,10 @@ if (j - left <= right - i) {\ if (i < right) { quickSort(i, right); }\ right = j;\ } + +#define LinkedList_Add(item, head, tail)\ +if (!head) { head = item; } else { tail->Next = item; }\ +tail = item;\ +item->Next = NULL; + #endif diff --git a/src/Game.c b/src/Game.c index 1b98a1931..f1f8b4c17 100644 --- a/src/Game.c +++ b/src/Game.c @@ -67,13 +67,7 @@ String Game_IPAddress = String_FromArray(Game_IPAddressBuffer); static struct IGameComponent* comps_head; static struct IGameComponent* comps_tail; void Game_AddComponent(struct IGameComponent* comp) { - if (!comps_head) { - comps_head = comp; - } else { - comps_tail->Next = comp; - } - comps_tail = comp; - comp->Next = NULL; + LinkedList_Add(comp, comps_head, comps_tail); } int ScheduledTask_Add(double interval, ScheduledTaskCallback callback) { diff --git a/src/Model.c b/src/Model.c index 64398dbc1..c2bad01d1 100644 --- a/src/Model.c +++ b/src/Model.c @@ -364,7 +364,9 @@ void BoxDesc_ZQuad(struct Model* m, int texX, int texY, int texWidth, int texHei *--------------------------------------------------------Models common----------------------------------------------------* *#########################################################################################################################*/ static struct Model* models_head; +static struct Model* models_tail; static struct ModelTex* textures_head; +static struct ModelTex* textures_tail; #define Model_RetSize(x,y,z) static Vector3 P = { (x)/16.0f,(y)/16.0f,(z)/16.0f }; e->Size = P; #define Model_RetAABB(x1,y1,z1, x2,y2,z2) static struct AABB BB = { (x1)/16.0f,(y1)/16.0f,(z1)/16.0f, (x2)/16.0f,(y2)/16.0f,(z2)/16.0f }; e->ModelAABB = BB; @@ -409,13 +411,11 @@ struct ModelTex* Model_GetTexture(const String* name) { } void Model_Register(struct Model* model) { - model->Next = models_head; - models_head = model; + LinkedList_Add(model, models_head, models_tail); } void Model_RegisterTexture(struct ModelTex* tex) { - tex->Next = textures_head; - textures_head = tex; + LinkedList_Add(tex, textures_head, textures_tail); } static void Models_TextureChanged(void* obj, struct Stream* stream, const String* name) {