diff --git a/SRB2.cbp b/SRB2.cbp
index 43696ee2e..99a712264 100644
--- a/SRB2.cbp
+++ b/SRB2.cbp
@@ -2815,6 +2815,39 @@ HW3SOUND for 3D hardware sound support
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 035b46556..ba354c289 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SRB2_CORE_SOURCES
i_tcp.c
info.c
lzf.c
+ m_aatree.c
m_anigif.c
m_argv.c
m_bbox.c
@@ -83,6 +84,7 @@ set(SRB2_CORE_HEADERS
info.h
keys.h
lzf.h
+ m_aatree.h
m_anigif.h
m_argv.h
m_bbox.h
diff --git a/src/Makefile b/src/Makefile
index f7a8c1b85..02b136f3e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -429,6 +429,7 @@ OBJS:=$(i_main_o) \
$(OBJDIR)/hu_stuff.o \
$(OBJDIR)/y_inter.o \
$(OBJDIR)/st_stuff.o \
+ $(OBJDIR)/m_aatree.o \
$(OBJDIR)/m_anigif.o \
$(OBJDIR)/m_argv.o \
$(OBJDIR)/m_bbox.o \
diff --git a/src/m_aatree.c b/src/m_aatree.c
new file mode 100644
index 000000000..6cb3a32cb
--- /dev/null
+++ b/src/m_aatree.c
@@ -0,0 +1,167 @@
+// SONIC ROBO BLAST 2
+//-----------------------------------------------------------------------------
+// Copyright (C) 1993-1996 by id Software, Inc.
+// Copyright (C) 1998-2000 by DooM Legacy Team.
+// Copyright (C) 1999-2016 by Sonic Team Junior.
+//
+// This program is free software distributed under the
+// terms of the GNU General Public License, version 2.
+// See the 'LICENSE' file for more details.
+//-----------------------------------------------------------------------------
+/// \file m_aatree.h
+/// \brief AA trees code
+
+#include "m_aatree.h"
+#include "z_zone.h"
+
+// A partial implementation of AA trees,
+// according to the algorithms given on Wikipedia.
+// http://en.wikipedia.org/wiki/AA_tree
+
+typedef struct aatree_node_s
+{
+ INT32 level;
+ INT32 key;
+ void* value;
+
+ struct aatree_node_s *left, *right;
+} aatree_node_t;
+
+struct aatree_s
+{
+ aatree_node_t *root;
+ UINT32 flags;
+};
+
+aatree_t *M_AATreeAlloc(UINT32 flags)
+{
+ aatree_t *aatree = Z_Malloc(sizeof (aatree_t), PU_STATIC, NULL);
+ aatree->root = NULL;
+ aatree->flags = flags;
+ return aatree;
+}
+
+static void M_AATreeFree_Node(aatree_node_t *node)
+{
+ if (node->left) M_AATreeFree_Node(node->left);
+ if (node->right) M_AATreeFree_Node(node->right);
+ Z_Free(node);
+}
+
+void M_AATreeFree(aatree_t *aatree)
+{
+ if (aatree->root)
+ M_AATreeFree_Node(aatree->root);
+
+ Z_Free(aatree);
+}
+
+static aatree_node_t *M_AATreeSkew(aatree_node_t *node)
+{
+ if (node && node->left && node->left->level == node->level)
+ {
+ // Not allowed: horizontal left-link. Reverse the
+ // horizontal link and hook the orphan back in.
+ aatree_node_t *oldleft = node->left;
+ node->left = oldleft->right;
+ oldleft->right = node;
+
+ return oldleft;
+ }
+
+ // No change needed.
+ return node;
+}
+
+static aatree_node_t *M_AATreeSplit(aatree_node_t *node)
+{
+ if (node && node->right && node->right->right && node->level == node->right->right->level)
+ {
+ // Not allowed: two consecutive horizontal right-links.
+ // The middle one becomes the new root at this point,
+ // with suitable adjustments below.
+
+ aatree_node_t *oldright = node->right;
+ node->right = oldright->left;
+ oldright->left = node;
+ oldright->level++;
+
+ return oldright;
+ }
+
+ // No change needed.
+ return node;
+}
+
+static aatree_node_t *M_AATreeSet_Node(aatree_node_t *node, UINT32 flags, INT32 key, void* value)
+{
+ if (!node)
+ {
+ // Nothing here, so just add where we are
+
+ node = Z_Malloc(sizeof (aatree_node_t), PU_STATIC, NULL);
+ node->level = 1;
+ node->key = key;
+ if (value && (flags & AATREE_ZUSER)) Z_SetUser(value, &node->value);
+ else node->value = value;
+ node->left = node->right = NULL;
+ }
+ else
+ {
+ if (key < node->key)
+ node->left = M_AATreeSet_Node(node->left, flags, key, value);
+ else if (key > node->key)
+ node->right = M_AATreeSet_Node(node->right, flags, key, value);
+ else
+ {
+ if (value && (flags & AATREE_ZUSER)) Z_SetUser(value, &node->value);
+ else node->value = value;
+ }
+
+ node = M_AATreeSkew(node);
+ node = M_AATreeSplit(node);
+ }
+
+ return node;
+}
+
+void M_AATreeSet(aatree_t *aatree, INT32 key, void* value)
+{
+ aatree->root = M_AATreeSet_Node(aatree->root, aatree->flags, key, value);
+}
+
+// Caveat: we don't distinguish between nodes that don't exists
+// and nodes with value == NULL.
+static void *M_AATreeGet_Node(aatree_node_t *node, INT32 key)
+{
+ if (node)
+ {
+ if (node->key == key)
+ return node->value;
+ else if(node->key < key)
+ return M_AATreeGet_Node(node->right, key);
+ else
+ return M_AATreeGet_Node(node->left, key);
+ }
+
+ return NULL;
+}
+
+void *M_AATreeGet(aatree_t *aatree, INT32 key)
+{
+ return M_AATreeGet_Node(aatree->root, key);
+}
+
+
+static void M_AATreeIterate_Node(aatree_node_t *node, aatree_iter_t callback)
+{
+ if (node->left) M_AATreeIterate_Node(node->left, callback);
+ callback(node->key, node->value);
+ if (node->right) M_AATreeIterate_Node(node->right, callback);
+}
+
+void M_AATreeIterate(aatree_t *aatree, aatree_iter_t callback)
+{
+ if (aatree->root)
+ M_AATreeIterate_Node(aatree->root, callback);
+}
diff --git a/src/m_aatree.h b/src/m_aatree.h
new file mode 100644
index 000000000..c9077b974
--- /dev/null
+++ b/src/m_aatree.h
@@ -0,0 +1,31 @@
+// SONIC ROBO BLAST 2
+//-----------------------------------------------------------------------------
+// Copyright (C) 1993-1996 by id Software, Inc.
+// Copyright (C) 1998-2000 by DooM Legacy Team.
+// Copyright (C) 1999-2016 by Sonic Team Junior.
+//
+// This program is free software distributed under the
+// terms of the GNU General Public License, version 2.
+// See the 'LICENSE' file for more details.
+//-----------------------------------------------------------------------------
+/// \file m_aatree.h
+/// \brief AA trees code
+
+#ifndef __M_AATREE__
+#define __M_AATREE__
+
+#include "doomtype.h"
+
+// Flags for AA trees.
+#define AATREE_ZUSER 1 // Treat values as z_zone-allocated blocks and set their user fields
+
+typedef struct aatree_s aatree_t;
+typedef void (*aatree_iter_t)(INT32 key, void *value);
+
+aatree_t *M_AATreeAlloc(UINT32 flags);
+void M_AATreeFree(aatree_t *aatree);
+void M_AATreeSet(aatree_t *aatree, INT32 key, void* value);
+void *M_AATreeGet(aatree_t *aatree, INT32 key);
+void M_AATreeIterate(aatree_t *aatree, aatree_iter_t callback);
+
+#endif
\ No newline at end of file
diff --git a/src/m_misc.c b/src/m_misc.c
index 64054d4f9..457214e33 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -2323,158 +2323,3 @@ void M_SetupMemcpy(void)
M_Memcpy = cpu_cpy;
#endif
}
-
-
-// A partial implementation of AA trees,
-// according to the algorithms given on Wikipedia.
-// http://en.wikipedia.org/wiki/AA_tree
-
-
-
-typedef struct aatree_node_s
-{
- INT32 level;
- INT32 key;
- void* value;
-
- struct aatree_node_s *left, *right;
-} aatree_node_t;
-
-struct aatree_s
-{
- aatree_node_t *root;
- UINT32 flags;
-};
-
-aatree_t *M_AATreeAlloc(UINT32 flags)
-{
- aatree_t *aatree = Z_Malloc(sizeof (aatree_t), PU_STATIC, NULL);
- aatree->root = NULL;
- aatree->flags = flags;
- return aatree;
-}
-
-static void M_AATreeFree_Node(aatree_node_t *node)
-{
- if (node->left) M_AATreeFree_Node(node->left);
- if (node->right) M_AATreeFree_Node(node->right);
- Z_Free(node);
-}
-
-void M_AATreeFree(aatree_t *aatree)
-{
- if (aatree->root)
- M_AATreeFree_Node(aatree->root);
-
- Z_Free(aatree);
-}
-
-static aatree_node_t *M_AATreeSkew(aatree_node_t *node)
-{
- if (node && node->left && node->left->level == node->level)
- {
- // Not allowed: horizontal left-link. Reverse the
- // horizontal link and hook the orphan back in.
- aatree_node_t *oldleft = node->left;
- node->left = oldleft->right;
- oldleft->right = node;
-
- return oldleft;
- }
-
- // No change needed.
- return node;
-}
-
-static aatree_node_t *M_AATreeSplit(aatree_node_t *node)
-{
- if (node && node->right && node->right->right && node->level == node->right->right->level)
- {
- // Not allowed: two consecutive horizontal right-links.
- // The middle one becomes the new root at this point,
- // with suitable adjustments below.
-
- aatree_node_t *oldright = node->right;
- node->right = oldright->left;
- oldright->left = node;
- oldright->level++;
-
- return oldright;
- }
-
- // No change needed.
- return node;
-}
-
-static aatree_node_t *M_AATreeSet_Node(aatree_node_t *node, UINT32 flags, INT32 key, void* value)
-{
- if (!node)
- {
- // Nothing here, so just add where we are
-
- node = Z_Malloc(sizeof (aatree_node_t), PU_STATIC, NULL);
- node->level = 1;
- node->key = key;
- if (value && (flags & AATREE_ZUSER)) Z_SetUser(value, &node->value);
- else node->value = value;
- node->left = node->right = NULL;
- }
- else
- {
- if (key < node->key)
- node->left = M_AATreeSet_Node(node->left, flags, key, value);
- else if (key > node->key)
- node->right = M_AATreeSet_Node(node->right, flags, key, value);
- else
- {
- if (value && (flags & AATREE_ZUSER)) Z_SetUser(value, &node->value);
- else node->value = value;
- }
-
- node = M_AATreeSkew(node);
- node = M_AATreeSplit(node);
- }
-
- return node;
-}
-
-void M_AATreeSet(aatree_t *aatree, INT32 key, void* value)
-{
- aatree->root = M_AATreeSet_Node(aatree->root, aatree->flags, key, value);
-}
-
-// Caveat: we don't distinguish between nodes that don't exists
-// and nodes with value == NULL.
-static void *M_AATreeGet_Node(aatree_node_t *node, INT32 key)
-{
- if (node)
- {
- if (node->key == key)
- return node->value;
- else if(node->key < key)
- return M_AATreeGet_Node(node->right, key);
- else
- return M_AATreeGet_Node(node->left, key);
- }
-
- return NULL;
-}
-
-void *M_AATreeGet(aatree_t *aatree, INT32 key)
-{
- return M_AATreeGet_Node(aatree->root, key);
-}
-
-
-static void M_AATreeIterate_Node(aatree_node_t *node, aatree_iter_t callback)
-{
- if (node->left) M_AATreeIterate_Node(node->left, callback);
- callback(node->key, node->value);
- if (node->right) M_AATreeIterate_Node(node->right, callback);
-}
-
-void M_AATreeIterate(aatree_t *aatree, aatree_iter_t callback)
-{
- if (aatree->root)
- M_AATreeIterate_Node(aatree->root, callback);
-}
diff --git a/src/m_misc.h b/src/m_misc.h
index fa1f3b33c..dc540dc16 100644
--- a/src/m_misc.h
+++ b/src/m_misc.h
@@ -96,19 +96,6 @@ void M_SetupMemcpy(void);
// counting bits, for weapon ammo code, usually
FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
-// Flags for AA trees.
-#define AATREE_ZUSER 1 // Treat values as z_zone-allocated blocks and set their user fields
-
-typedef struct aatree_s aatree_t;
-typedef void (*aatree_iter_t)(INT32 key, void *value);
-
-aatree_t *M_AATreeAlloc(UINT32 flags);
-void M_AATreeFree(aatree_t *aatree);
-void M_AATreeSet(aatree_t *aatree, INT32 key, void* value);
-void *M_AATreeGet(aatree_t *aatree, INT32 key);
-void M_AATreeIterate(aatree_t *aatree, aatree_iter_t callback);
-
-// Nasty cyclic dependency workaround. This must come after aatree stuff.
#include "w_wad.h"
extern char configfile[MAX_WADPATH];
diff --git a/src/sdl/Srb2SDL-vc10.vcxproj b/src/sdl/Srb2SDL-vc10.vcxproj
index d12a7efbf..820192649 100644
--- a/src/sdl/Srb2SDL-vc10.vcxproj
+++ b/src/sdl/Srb2SDL-vc10.vcxproj
@@ -167,6 +167,7 @@
+
@@ -308,6 +309,7 @@
+
diff --git a/src/sdl/Srb2SDL-vc10.vcxproj.filters b/src/sdl/Srb2SDL-vc10.vcxproj.filters
index 9396b4823..d04007dd7 100644
--- a/src/sdl/Srb2SDL-vc10.vcxproj.filters
+++ b/src/sdl/Srb2SDL-vc10.vcxproj.filters
@@ -294,6 +294,9 @@
M_Misc
+
+ M_Misc
+
M_Misc
@@ -666,6 +669,9 @@
M_Misc
+
+ M_Misc
+
M_Misc
diff --git a/src/w_wad.h b/src/w_wad.h
index c13f69338..b03e376bf 100644
--- a/src/w_wad.h
+++ b/src/w_wad.h
@@ -54,10 +54,8 @@ typedef struct
#define lumpcache_t void *
-// Annoying cyclic dependency workaround: this inlcusion must come after
-// the definition of MAX_WADPATH.
#ifdef HWRENDER
-#include "m_misc.h"
+#include "m_aatree.h"
#endif
typedef struct wadfile_s
diff --git a/src/win32/Srb2win-vc10.vcxproj b/src/win32/Srb2win-vc10.vcxproj
index 1e9d8241e..064f75d7d 100644
--- a/src/win32/Srb2win-vc10.vcxproj
+++ b/src/win32/Srb2win-vc10.vcxproj
@@ -145,6 +145,7 @@
+
@@ -300,6 +301,7 @@
+
diff --git a/src/win32/Srb2win-vc10.vcxproj.filters b/src/win32/Srb2win-vc10.vcxproj.filters
index 3f5b84bfb..b2647ea1c 100644
--- a/src/win32/Srb2win-vc10.vcxproj.filters
+++ b/src/win32/Srb2win-vc10.vcxproj.filters
@@ -255,6 +255,9 @@
LUA
+
+ M_Misc
+
M_Misc
@@ -662,6 +665,9 @@
M_Misc
+
+ M_Misc
+
M_Misc