19 #define SET_CRT_DEBUG_FIELD(a) \
20 _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
21 #define CLEAR_CRT_DEBUG_FIELD(a) \
22 _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
24 #define SET_CRT_DEBUG_FIELD(a) ((void) 0)
25 #define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
36 const float ooMax = 1.0f / (
float)(RAND_MAX+1);
38 float retValue = ( (
float)rand() * ooMax * (a_max - a_min) + a_min);
40 ASSERT(retValue >= a_min && retValue < a_max);
53 Vec3(
float a_x,
float a_y,
float a_z)
63 return Vec3(
v[0] + a_other.
v[0],
73 const Vec3& a_boxMinB,
const Vec3& a_boxMaxB)
75 for(
int axis=0; axis<3; ++axis)
77 if(a_boxMinA.
v[axis] > a_boxMaxB.
v[axis] ||
78 a_boxMaxA.
v[axis] < a_boxMinB.
v[axis])
118 int main(
int argc,
char* argv[])
120 const int NUM_OBJECTS = 40;
121 const int FRAC_OBJECTS = 4;
122 const float MAX_WORLDSIZE = 10.0f;
123 const float FRAC_WORLDSIZE = MAX_WORLDSIZE / 2;
128 ASSERT( NUM_OBJECTS > FRAC_OBJECTS );
133 memset(thingArray, 0,
sizeof(thingArray));
143 for( index = 0; index < NUM_OBJECTS; ++index )
152 thingArray[counter-1] = newThing;
154 tree.Insert(newThing->
m_min.
v, newThing->
m_max.
v, newThing);
158 printf(
"tree count = %d\n", tree.Count());
160 int numToDelete = NUM_OBJECTS / FRAC_OBJECTS;
161 int numToStep = FRAC_OBJECTS;
164 for( index = 0; index < NUM_OBJECTS; index += numToStep )
170 tree.Remove(curThing->
m_min.
v, curThing->
m_max.
v, curThing);
174 thingArray[index] = NULL;
178 printf(
"tree count = %d\n", tree.Count());
181 for( index = 0; index < numToDelete; ++index )
190 thingArray[counter-1] = newThing;
192 tree.Insert(newThing->
m_min.
v, newThing->
m_max.
v, newThing);
196 printf(
"tree count = %d\n", tree.Count());
198 Vec3 searchMin(0,0,0);
199 Vec3 searchMax(FRAC_WORLDSIZE, FRAC_WORLDSIZE, FRAC_WORLDSIZE);
207 SomeThingTree::Iterator it;
208 for( tree.GetFirst(it); !tree.IsNull(it); tree.GetNext(it) )
220 for( tree.GetFirst(it); !tree.IsNull(it); tree.GetNext(it) )
233 if(SomeThing::s_outstandingAllocs > 0)
235 printf(
"Memory leak!\n");
236 printf(
"s_outstandingAllocs = %d\n", SomeThing::s_outstandingAllocs);
240 printf(
"No memory leaks detected by app\n");
248 SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF );