]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
com_list: Move all functions to the header and inline them. Include where needed
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 13 Apr 2021 16:31:41 +0000 (16:31 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 13 Apr 2021 16:31:41 +0000 (16:31 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13123 d7cf8633-e32d-0410-b094-e92efae38249

com_list.c [deleted file]
com_list.h
darkplaces-sdl2-vs2017.vcxproj
darkplaces-sdl2-vs2019.vcxproj
darkplaces.h
makefile.inc
world.c
world.h

diff --git a/com_list.c b/com_list.c
deleted file mode 100644 (file)
index c4d79b4..0000000
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
-Copyright (C) 2020 David "Cloudwalk" Knapp
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-// com_list.c - generic doubly linked list interface, adapted from Linux list.h
-
-#include "qtypes.h"
-#include "com_list.h"
-
-/*
- * Creates a new linked list. Initializes the head to point to itself.
- * If it's a list header, the result is an empty list.
- */
-void List_Create(llist_t *list)
-{
-       list->next = list->prev = NULL;
-}
-
-/*
- * Insert a node between two known nodes.
- * 
- * Only use when prev and next are known.
- */
-static void __List_Add(llist_t *node, llist_t *prev, llist_t *next)
-{
-       next->prev = node;
-       node->next = next;
-       node->prev = prev;
-       prev->next = node;
-}
-
-/*
- * Insert a node immediately after head.
- */
-void List_Add(llist_t *node, llist_t *head)
-{
-       __List_Add(node, head, head->next);
-}
-
-/*
- * Insert a node immediately before head.
- */
-void List_Add_Tail(llist_t *node, llist_t *head)
-{
-       __List_Add(node, head->prev, head);
-}
-
-/*
- * Bridge prev and next together, when removing the parent of them.
- */
-static inline void __List_Delete(llist_t *prev, llist_t *next)
-{
-       next->prev = prev;
-       prev->next = next;
-}
-
-/*
- * Redundant?
- */
-static inline void __List_Delete_Node(llist_t *node)
-{
-       __List_Delete(node->prev, node->next);
-}
-
-/*
- * Removes a node from its list. Sets its pointers to NULL.
- */
-void List_Delete(llist_t *node)
-{
-       __List_Delete_Node(node);
-       node->next = node->prev = NULL;
-}
-
-/*
- * Removes a node from its list. Reinitialize it.
- */
-void List_Delete_Init(llist_t *node)
-{
-       __List_Delete_Node(node);
-       node->next = node->prev = node;
-}
-
-/*
- * Replace old with new. Old is overwritten if empty.
- */
-void List_Replace(llist_t *old, llist_t *_new)
-{
-       _new->next = old->next;
-       _new->next->prev = _new;
-       _new->prev = old->prev;
-       _new->prev->next = _new;
-       old->next = old->prev = old;
-}
-
-/*
- * Replace old with new. Initialize old.
- * Old is overwritten if empty.
- */
-void List_Replace_Init(llist_t *old, llist_t *_new)
-{
-       List_Replace(old, _new);
-       List_Create(old);
-}
-
-/*
- * Swap node1 with node2 in place.
- */
-void List_Swap(llist_t *node1, llist_t *node2)
-{
-       llist_t *pos = node2->prev;
-       List_Delete_Init(node2);
-       List_Replace(node1, node2);
-       if(pos == node1)
-               pos = node2;
-       List_Add(node1, pos);
-}
-
-/*
- * Delete list from its... list, then insert after head.
- */
-void List_Move(llist_t *list, llist_t *head)
-{
-       __List_Delete_Node(list);
-       List_Add(list, head);
-}
-
-/*
- * Delete list from its... list, then insert before head.
- */
-void List_Move_Tail(llist_t *list, llist_t *head)
-{
-       __List_Delete_Node(list);
-       List_Add_Tail(list, head);
-}
-
-/*
- * Move the first node of a range of nodes immediately after head.
- * All three parameters must belong to the same list.
- */
-
-void List_Bulk_Move_Tail(llist_t *head, llist_t *first, llist_t *last)
-{
-       first->prev->next = last->next;
-       last->next->prev = first->prev;
-
-       head->prev->next = first;
-       first->prev = head->prev;
-
-       last->next = head;
-       head->prev = last;
-}
-
-/*
- * Shift the head to the right (like rotating a wheel counterclockwise).
- * The node immediately to the right becomes the new head.
- */
-void List_Rotate_Left(llist_t *head)
-{
-       llist_t *first;
-
-       if (!List_Is_Empty(head))
-       {
-               first = head->next;
-               List_Move_Tail(first, head);
-       }
-}
-
-/*
- * Make list the new head.
- */
-void List_Rotate_To_Front(llist_t *list, llist_t *head)
-{
-       List_Move_Tail(head, list);
-}
-
-/*
- * Concatenate two lists. The head of list will be discarded.
- */
-static inline void __List_Splice(const llist_t *list, llist_t *prev, llist_t *next)
-{
-       llist_t *first = list->next;
-       llist_t *last = list->prev;
-
-       first->prev = prev;
-       prev->next = first;
-
-       last->next = next;
-       next->prev = last;
-}
-
-/*
- * Concatenate two lists. The first node of list will be inserted after head.
- */
-void List_Splice(const llist_t *list, llist_t *head)
-{
-       if(!List_Is_Empty(list))
-               __List_Splice(list, head, head->next);
-}
-
-/*
- * Concatenate two lists. The tail of list will be inserted before head.
- */
-void List_Splice_Tail(const llist_t *list, llist_t *head)
-{
-       if (!List_Is_Empty(list))
-               __List_Splice(list, head->prev, head);
-}
-
-qbool List_Is_First(llist_t *list, llist_t *start)
-{
-       return list->prev == start;
-}
-
-qbool List_Is_Last(llist_t *list, llist_t *start)
-{
-       return list->next == start;
-}
-
-qbool List_Is_Empty(const llist_t *list)
-{
-       return list->next == list;
-}
index 9fe42a312711fe136bbd0052bfc7246a0fe86c38..cf05f541277a4037880d7959c6cc394f64c92ff4 100644 (file)
@@ -206,23 +206,218 @@ typedef struct llist_s
 #define List_Safe_Reset_Next(pos, n, member) \
                n = List_Next_Entry(pos, member)
 
 #define List_Safe_Reset_Next(pos, n, member) \
                n = List_Next_Entry(pos, member)
 
-void List_Create(llist_t *list);
-void List_Add(llist_t *node, llist_t *start);
-void List_Add_Tail(llist_t *node, llist_t *start);
-void List_Delete(llist_t *node);
-void List_Delete_Init(llist_t *node);
-void List_Replace(llist_t *old, llist_t *_new);
-void List_Replace_Init(llist_t *old, llist_t *_new);
-void List_Swap(llist_t *node1, llist_t *node2);
-void List_Move(llist_t *list, llist_t *start);
-void List_Move_Tail(llist_t *list, llist_t *start);
-void List_Bulk_Move_Tail(llist_t *start, llist_t *first, llist_t *last);
-void List_Rotate_Left(llist_t *head);
-void List_Rotate_To_Front(llist_t *list, llist_t *head);
-void List_Splice(const llist_t *list, llist_t *head);
-void List_Splice_Tail(const llist_t *list, llist_t *head);
-qbool List_Is_First(llist_t *list, llist_t *start);
-qbool List_Is_Last(llist_t *list, llist_t *start);
-qbool List_Is_Empty(const llist_t *list);
+static inline qbool List_Is_Empty(const llist_t *list)
+{
+       return list->next == list;
+}
+
+/*
+ * Creates a new linked list. Initializes the head to point to itself.
+ * If it's a list header, the result is an empty list.
+ */
+static inline void List_Create(llist_t *list)
+{
+       list->next = list->prev = NULL;
+}
+
+/*
+ * Insert a node between two known nodes.
+ * 
+ * Only use when prev and next are known.
+ */
+static inline void __List_Add(llist_t *node, llist_t *prev, llist_t *next)
+{
+       next->prev = node;
+       node->next = next;
+       node->prev = prev;
+       prev->next = node;
+}
+
+/*
+ * Insert a node immediately after head.
+ */
+static inline void List_Add(llist_t *node, llist_t *head)
+{
+       __List_Add(node, head, head->next);
+}
+
+/*
+ * Insert a node immediately before head.
+ */
+static inline void List_Add_Tail(llist_t *node, llist_t *head)
+{
+       __List_Add(node, head->prev, head);
+}
+
+/*
+ * Bridge prev and next together, when removing the parent of them.
+ */
+static inline void __List_Delete(llist_t *prev, llist_t *next)
+{
+       next->prev = prev;
+       prev->next = next;
+}
+
+/*
+ * Redundant?
+ */
+static inline void __List_Delete_Node(llist_t *node)
+{
+       __List_Delete(node->prev, node->next);
+}
+
+/*
+ * Removes a node from its list. Sets its pointers to NULL.
+ */
+static inline void List_Delete(llist_t *node)
+{
+       __List_Delete_Node(node);
+       node->next = node->prev = NULL;
+}
+
+/*
+ * Removes a node from its list. Reinitialize it.
+ */
+static inline void List_Delete_Init(llist_t *node)
+{
+       __List_Delete_Node(node);
+       node->next = node->prev = node;
+}
+
+/*
+ * Replace old with new. Old is overwritten if empty.
+ */
+static inline void List_Replace(llist_t *old, llist_t *_new)
+{
+       _new->next = old->next;
+       _new->next->prev = _new;
+       _new->prev = old->prev;
+       _new->prev->next = _new;
+       old->next = old->prev = old;
+}
+
+/*
+ * Replace old with new. Initialize old.
+ * Old is overwritten if empty.
+ */
+static inline void List_Replace_Init(llist_t *old, llist_t *_new)
+{
+       List_Replace(old, _new);
+       List_Create(old);
+}
+
+/*
+ * Swap node1 with node2 in place.
+ */
+static inline void List_Swap(llist_t *node1, llist_t *node2)
+{
+       llist_t *pos = node2->prev;
+       List_Delete_Init(node2);
+       List_Replace(node1, node2);
+       if(pos == node1)
+               pos = node2;
+       List_Add(node1, pos);
+}
+
+/*
+ * Delete list from its... list, then insert after head.
+ */
+static inline void List_Move(llist_t *list, llist_t *head)
+{
+       __List_Delete_Node(list);
+       List_Add(list, head);
+}
+
+/*
+ * Delete list from its... list, then insert before head.
+ */
+static inline void List_Move_Tail(llist_t *list, llist_t *head)
+{
+       __List_Delete_Node(list);
+       List_Add_Tail(list, head);
+}
+
+/*
+ * Move the first node of a range of nodes immediately after head.
+ * All three parameters must belong to the same list.
+ */
+
+static inline void List_Bulk_Move_Tail(llist_t *head, llist_t *first, llist_t *last)
+{
+       first->prev->next = last->next;
+       last->next->prev = first->prev;
+
+       head->prev->next = first;
+       first->prev = head->prev;
+
+       last->next = head;
+       head->prev = last;
+}
+
+/*
+ * Shift the head to the right (like rotating a wheel counterclockwise).
+ * The node immediately to the right becomes the new head.
+ */
+static inline void List_Rotate_Left(llist_t *head)
+{
+       llist_t *first;
+
+       if (!List_Is_Empty(head))
+       {
+               first = head->next;
+               List_Move_Tail(first, head);
+       }
+}
+
+/*
+ * Make list the new head.
+ */
+static inline void List_Rotate_To_Front(llist_t *list, llist_t *head)
+{
+       List_Move_Tail(head, list);
+}
+
+/*
+ * Concatenate two lists. The head of list will be discarded.
+ */
+static inline void __List_Splice(const llist_t *list, llist_t *prev, llist_t *next)
+{
+       llist_t *first = list->next;
+       llist_t *last = list->prev;
+
+       first->prev = prev;
+       prev->next = first;
+
+       last->next = next;
+       next->prev = last;
+}
+
+/*
+ * Concatenate two lists. The first node of list will be inserted after head.
+ */
+static inline void List_Splice(const llist_t *list, llist_t *head)
+{
+       if(!List_Is_Empty(list))
+               __List_Splice(list, head, head->next);
+}
+
+/*
+ * Concatenate two lists. The tail of list will be inserted before head.
+ */
+static inline void List_Splice_Tail(const llist_t *list, llist_t *head)
+{
+       if (!List_Is_Empty(list))
+               __List_Splice(list, head->prev, head);
+}
+
+static inline qbool List_Is_First(llist_t *list, llist_t *start)
+{
+       return list->prev == start;
+}
+
+static inline qbool List_Is_Last(llist_t *list, llist_t *start)
+{
+       return list->next == start;
+}
 
 #endif
 
 #endif
index 511ea7c0bb4376c047be6c4a7c429a944b25a467..eb3ac72a1aa960fcddbe05cc4fe48c011b76f4c4 100644 (file)
        <ClCompile Include="com_ents.c" />\r
        <ClCompile Include="com_ents4.c" />\r
        <ClCompile Include="com_game.c" />\r
        <ClCompile Include="com_ents.c" />\r
        <ClCompile Include="com_ents4.c" />\r
        <ClCompile Include="com_game.c" />\r
-       <ClCompile Include="com_list.c" />\r
        <ClCompile Include="com_msg.c" />\r
     <ClCompile Include="common.c" />\r
     <ClCompile Include="console.c" />\r
        <ClCompile Include="com_msg.c" />\r
     <ClCompile Include="common.c" />\r
     <ClCompile Include="console.c" />\r
index 974db39daa1a877b47b4e16bd9f0646d03ced7ae..a44a9231634c208ac61e4e3f463be216c9fe7cdd 100644 (file)
     <ClCompile Include="com_ents.c" />\r
     <ClCompile Include="com_ents4.c" />\r
     <ClCompile Include="com_game.c" />\r
     <ClCompile Include="com_ents.c" />\r
     <ClCompile Include="com_ents4.c" />\r
     <ClCompile Include="com_game.c" />\r
-    <ClCompile Include="com_list.c" />\r
     <ClCompile Include="com_msg.c" />\r
     <ClCompile Include="common.c" />\r
     <ClCompile Include="console.c" />\r
     <ClCompile Include="com_msg.c" />\r
     <ClCompile Include="common.c" />\r
     <ClCompile Include="console.c" />\r
index b025e2a7ae79d609d9cd547f16a59096d3e1bfb2..7fff85242d008c4653624906ab5a45398a07db50 100644 (file)
@@ -46,7 +46,6 @@ extern char engineversion[128];
 #include "qdefs.h"
 #include "zone.h"
 #include "thread.h"
 #include "qdefs.h"
 #include "zone.h"
 #include "thread.h"
-#include "com_list.h"
 #include "common.h"
 #include "fs.h"
 #include "host.h"
 #include "common.h"
 #include "fs.h"
 #include "host.h"
index 2fdc966a2d3c1c612d6b5b6deba187e40f165965..16dd546f0f1035299b369385af55e67837f15fc0 100644 (file)
@@ -101,7 +101,6 @@ OBJ_COMMON= \
        com_ents.o \
        com_ents4.o \
        com_game.o \
        com_ents.o \
        com_ents4.o \
        com_game.o \
-       com_list.o \
        com_msg.o \
        common.o \
        console.o \
        com_msg.o \
        common.o \
        console.o \
diff --git a/world.c b/world.c
index 6c833975188f1ef470f8e8d587a1de79cb62f9fb..26ffd9bbe57d4fd5365eb1b279364fc72b8a583f 100644 (file)
--- a/world.c
+++ b/world.c
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "clvm_cmds.h"
 #include "cl_collision.h"
 #include "quakedef.h"
 #include "clvm_cmds.h"
 #include "cl_collision.h"
+#include "com_list.h"
 
 /*
 
 
 /*
 
diff --git a/world.h b/world.h
index 01968a0a2a1dac72f080f3df1cb2be805983c4e2..1b60ac6c2b48cbd74db530237db1db418e98ec4d 100644 (file)
--- a/world.h
+++ b/world.h
@@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define WORLD_H
 
 #include "qtypes.h"
 #define WORLD_H
 
 #include "qtypes.h"
-#include "com_list.h"
 #include "collision.h"
 
 #define MOVE_NORMAL     0
 #include "collision.h"
 
 #define MOVE_NORMAL     0