ref: 8a202d6c1fd789cc56a3d6501105a09b041501da
parent: 3e193403431ad74311e85567526bc60f57cf4f53
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Dec 11 22:24:58 EST 2023
unlimited areanodes (thanks mh)
--- a/world.c
+++ b/world.c
@@ -159,19 +159,15 @@
typedef struct areanode_s
{
- int axis; // -1 = leaf node
- float dist;
- struct areanode_s *children[2];
- link_t trigger_edicts;
- link_t solid_edicts;
+ struct areanode_s *children[2];
+ link_t trigger_edicts;
+ link_t solid_edicts;
+ int axis; // -1 = leaf node
+ float dist;
} areanode_t;
-#define AREA_DEPTH 4
-#define AREA_NODES 32
+static areanode_t *sv_areanodes;
-static areanode_t sv_areanodes[AREA_NODES];
-static int sv_numareanodes;
-
/*
===============
SV_CreateAreaNode
@@ -184,35 +180,29 @@
vec3_t size;
vec3_t mins1, maxs1, mins2, maxs2;
- anode = &sv_areanodes[sv_numareanodes];
- sv_numareanodes++;
-
+ anode = Hunk_Alloc(sizeof(*anode));
ClearLink (&anode->trigger_edicts);
ClearLink (&anode->solid_edicts);
+ VectorSubtract(maxs, mins, size);
- if (depth == AREA_DEPTH)
- {
+ if(size[0] < 1024 && size[1] < 1024){
anode->axis = -1;
anode->children[0] = anode->children[1] = nil;
return anode;
}
- VectorSubtract (maxs, mins, size);
- if (size[0] > size[1])
- anode->axis = 0;
- else
- anode->axis = 1;
-
+ anode->axis = size[0] <= size[1];
anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]);
- VectorCopy (mins, mins1);
- VectorCopy (mins, mins2);
- VectorCopy (maxs, maxs1);
- VectorCopy (maxs, maxs2);
+ VectorCopy(mins, mins1);
+ VectorCopy(mins, mins2);
+ VectorCopy(maxs, maxs1);
+ VectorCopy(maxs, maxs2);
+
maxs1[anode->axis] = mins2[anode->axis] = anode->dist;
- anode->children[0] = SV_CreateAreaNode (depth+1, mins2, maxs2);
- anode->children[1] = SV_CreateAreaNode (depth+1, mins1, maxs1);
+ anode->children[0] = SV_CreateAreaNode(depth+1, mins2, maxs2);
+ anode->children[1] = SV_CreateAreaNode(depth+1, mins1, maxs1);
return anode;
}
@@ -227,9 +217,7 @@
{
SV_InitBoxHull();
- memset(sv_areanodes, 0, sizeof sv_areanodes);
- sv_numareanodes = 0;
- SV_CreateAreaNode (0, sv.worldmodel->mins, sv.worldmodel->maxs);
+ sv_areanodes = SV_CreateAreaNode(0, sv.worldmodel->mins, sv.worldmodel->maxs);
}