Skip to content

Commit 7d270d7

Browse files
committed
bounds_t
1 parent 67812ef commit 7d270d7

31 files changed

+695
-625
lines changed

src/common/cm/cm_load.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ CM_BoundBrush
247247
*/
248248
void CM_BoundBrush( cbrush_t *b )
249249
{
250-
b->bounds[ 0 ][ 0 ] = -b->sides[ 0 ].plane->dist;
251-
b->bounds[ 1 ][ 0 ] = b->sides[ 1 ].plane->dist;
250+
b->bounds.mins[ 0 ] = -b->sides[ 0 ].plane->dist;
251+
b->bounds.maxs[ 0 ] = b->sides[ 1 ].plane->dist;
252252

253-
b->bounds[ 0 ][ 1 ] = -b->sides[ 2 ].plane->dist;
254-
b->bounds[ 1 ][ 1 ] = b->sides[ 3 ].plane->dist;
253+
b->bounds.mins[ 1 ] = -b->sides[ 2 ].plane->dist;
254+
b->bounds.maxs[ 1 ] = b->sides[ 3 ].plane->dist;
255255

256-
b->bounds[ 0 ][ 2 ] = -b->sides[ 4 ].plane->dist;
257-
b->bounds[ 1 ][ 2 ] = b->sides[ 5 ].plane->dist;
256+
b->bounds.mins[ 2 ] = -b->sides[ 4 ].plane->dist;
257+
b->bounds.maxs[ 2 ] = b->sides[ 5 ].plane->dist;
258258
}
259259

260260
/*
@@ -999,8 +999,8 @@ clipHandle_t CM_TempBoxModel( const vec3_t mins, const vec3_t maxs, bool capsule
999999
box_planes[ 10 ].dist = mins[ 2 ];
10001000
box_planes[ 11 ].dist = -mins[ 2 ];
10011001

1002-
VectorCopy( mins, box_brush->bounds[ 0 ] );
1003-
VectorCopy( maxs, box_brush->bounds[ 1 ] );
1002+
VectorCopy( mins, box_brush->bounds.mins );
1003+
VectorCopy( maxs, box_brush->bounds.maxs );
10041004

10051005
return BOX_MODEL_HANDLE;
10061006
}

src/common/cm/cm_local.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct cbrushside_t
7777
struct cbrush_t
7878
{
7979
int contents;
80-
vec3_t bounds[ 2 ];
80+
bounds_t bounds;
8181
int numsides;
8282
cbrushside_t *sides;
8383
int checkcount; // to avoid repeated testings
@@ -129,7 +129,7 @@ struct cFacet_t
129129

130130
struct cSurfaceCollide_t
131131
{
132-
vec3_t bounds[ 2 ];
132+
bounds_t bounds;
133133
int numPlanes; // surface planes plus edge planes
134134
cPlane_t *planes;
135135

@@ -238,7 +238,7 @@ struct traceWork_t
238238
vec3_t offsets[ 8 ]; // [signbits][x] = either size[0][x] or size[1][x]
239239
float maxOffset; // longest corner length from origin
240240
vec3_t extents; // greatest of abs(size[0]) and abs(size[1])
241-
vec3_t bounds[ 2 ]; // enclosing box of start and end surrounding by size
241+
bounds_t bounds; // enclosing box of start and end surrounding by size
242242
vec3_t modelOrigin; // origin of the model tracing through
243243
int contents; // ored contents of the model tracing through
244244
int skipContents; // ored contents that shall be ignored
@@ -253,7 +253,7 @@ struct leafList_t
253253
int maxcount;
254254
bool overflowed;
255255
int *list;
256-
vec3_t bounds[ 2 ];
256+
bounds_t bounds; // for bounding box culling
257257
int lastLeaf; // for overflows where each leaf can't be stored individually
258258
void ( *storeLeafs )( leafList_t *ll, int nodenum );
259259
};

src/common/cm/cm_patch.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,13 @@ cSurfaceCollide_t *CM_GeneratePatchCollide( int width, int height, const vec3_t
822822
// the approximate surface defined by these points will be
823823
// collided against
824824
sc = ( cSurfaceCollide_t * ) CM_Alloc( sizeof( *sc ) );
825-
ClearBounds( sc->bounds[ 0 ], sc->bounds[ 1 ] );
825+
ClearBounds( sc->bounds );
826826

827827
for ( i = 0; i < grid.width; i++ )
828828
{
829829
for ( j = 0; j < grid.height; j++ )
830830
{
831-
AddPointToBounds( grid.points[ i ][ j ], sc->bounds[ 0 ], sc->bounds[ 1 ] );
831+
AddPointToBounds( grid.points[ i ][ j ], sc->bounds );
832832
}
833833
}
834834

@@ -838,13 +838,13 @@ cSurfaceCollide_t *CM_GeneratePatchCollide( int width, int height, const vec3_t
838838
CM_SurfaceCollideFromGrid( &grid, sc );
839839

840840
// expand by one unit for epsilon purposes
841-
sc->bounds[ 0 ][ 0 ] -= 1;
842-
sc->bounds[ 0 ][ 1 ] -= 1;
843-
sc->bounds[ 0 ][ 2 ] -= 1;
841+
sc->bounds.mins[ 0 ] -= 1;
842+
sc->bounds.mins[ 1 ] -= 1;
843+
sc->bounds.mins[ 2 ] -= 1;
844844

845-
sc->bounds[ 1 ][ 0 ] += 1;
846-
sc->bounds[ 1 ][ 1 ] += 1;
847-
sc->bounds[ 1 ][ 2 ] += 1;
845+
sc->bounds.maxs[ 0 ] += 1;
846+
sc->bounds.maxs[ 1 ] += 1;
847+
sc->bounds.maxs[ 2 ] += 1;
848848

849849
return sc;
850850
}

src/common/cm/cm_test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void CM_BoxLeafnums_r( leafList_t *ll, int nodenum )
140140

141141
node = &cm.nodes[ nodenum ];
142142
plane = node->plane;
143-
s = BoxOnPlaneSide( ll->bounds[ 0 ], ll->bounds[ 1 ], plane );
143+
s = BoxOnPlaneSide( ll->bounds, plane );
144144

145145
if ( s == 1 )
146146
{
@@ -170,8 +170,8 @@ int CM_BoxLeafnums( const vec3_t mins, const vec3_t maxs, int *list, int listsiz
170170

171171
cm.checkcount++;
172172

173-
VectorCopy( mins, ll.bounds[ 0 ] );
174-
VectorCopy( maxs, ll.bounds[ 1 ] );
173+
VectorCopy( mins, ll.bounds.mins );
174+
VectorCopy( maxs, ll.bounds.maxs );
175175
ll.count = 0;
176176
ll.maxcount = listsize;
177177
ll.list = list;
@@ -236,7 +236,7 @@ int CM_PointContents( const vec3_t p, clipHandle_t model )
236236
const cbrush_t *b = &cm.brushes[ *brushNum ];
237237

238238
// XreaL BEGIN
239-
if ( !CM_BoundsIntersectPoint( b->bounds[ 0 ], b->bounds[ 1 ], p ) )
239+
if ( !CM_BoundsIntersectPoint( b->bounds.mins, b->bounds.maxs, p ) )
240240
{
241241
continue;
242242
}

src/common/cm/cm_trace.cpp

+31-30
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,12 @@ static void CM_TestBoxInBrush( traceWork_t *tw, const cbrush_t *brush )
177177

178178
// special test for axial
179179
// the first 6 brush planes are always axial
180-
if ( tw->bounds[ 0 ][ 0 ] > brush->bounds[ 1 ][ 0 ]
181-
|| tw->bounds[ 0 ][ 1 ] > brush->bounds[ 1 ][ 1 ]
182-
|| tw->bounds[ 0 ][ 2 ] > brush->bounds[ 1 ][ 2 ]
183-
|| tw->bounds[ 1 ][ 0 ] < brush->bounds[ 0 ][ 0 ]
184-
|| tw->bounds[ 1 ][ 1 ] < brush->bounds[ 0 ][ 1 ] || tw->bounds[ 1 ][ 2 ] < brush->bounds[ 0 ][ 2 ] )
180+
if ( tw->bounds.mins[ 0 ] > brush->bounds.maxs[ 0 ]
181+
|| tw->bounds.mins[ 1 ] > brush->bounds.maxs[ 1 ]
182+
|| tw->bounds.mins[ 2 ] > brush->bounds.maxs[ 2 ]
183+
|| tw->bounds.maxs[ 0 ] < brush->bounds.mins[ 0 ]
184+
|| tw->bounds.maxs[ 1 ] < brush->bounds.mins[ 1 ]
185+
|| tw->bounds.maxs[ 2 ] < brush->bounds.mins[ 2 ] )
185186
{
186187
return;
187188
}
@@ -613,17 +614,17 @@ void CM_PositionTest( traceWork_t *tw )
613614
leafList_t ll;
614615

615616
// identify the leafs we are touching
616-
VectorAdd( tw->start, tw->size[ 0 ], ll.bounds[ 0 ] );
617-
VectorAdd( tw->start, tw->size[ 1 ], ll.bounds[ 1 ] );
617+
VectorAdd( tw->start, tw->size[ 0 ], ll.bounds.mins );
618+
VectorAdd( tw->start, tw->size[ 1 ], ll.bounds.maxs );
618619

619620
{
620-
ll.bounds[ 0 ][ 0 ] -= 1;
621-
ll.bounds[ 0 ][ 1 ] -= 1;
622-
ll.bounds[ 0 ][ 2 ] -= 1;
621+
ll.bounds.mins[ 0 ] -= 1;
622+
ll.bounds.mins[ 1 ] -= 1;
623+
ll.bounds.mins[ 2 ] -= 1;
623624

624-
ll.bounds[ 1 ][ 0 ] += 1;
625-
ll.bounds[ 1 ][ 1 ] += 1;
626-
ll.bounds[ 1 ][ 2 ] += 1;
625+
ll.bounds.maxs[ 0 ] += 1;
626+
ll.bounds.maxs[ 1 ] += 1;
627+
ll.bounds.maxs[ 2 ] += 1;
627628
}
628629

629630
ll.count = 0;
@@ -850,7 +851,7 @@ void CM_TraceThroughSurfaceCollide( traceWork_t *tw, const cSurfaceCollide_t *sc
850851
cFacet_t *facet;
851852
vec3_t startp, endp;
852853

853-
if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], sc->bounds[ 0 ], sc->bounds[ 1 ] ) )
854+
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, sc->bounds.mins, sc->bounds.maxs ) )
854855
{
855856
return;
856857
}
@@ -1290,7 +1291,7 @@ void CM_TraceThroughLeaf( traceWork_t *tw, const cLeaf_t *leaf )
12901291
continue;
12911292
}
12921293

1293-
if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], b->bounds[ 0 ], b->bounds[ 1 ] ) )
1294+
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, b->bounds.mins, b->bounds.maxs ) )
12941295
{
12951296
continue;
12961297
}
@@ -1338,7 +1339,7 @@ void CM_TraceThroughLeaf( traceWork_t *tw, const cLeaf_t *leaf )
13381339
continue;
13391340
}
13401341

1341-
if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], surface->sc->bounds[ 0 ], surface->sc->bounds[ 1 ] ) )
1342+
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, surface->sc->bounds.mins, surface->sc->bounds.maxs ) )
13421343
{
13431344
continue;
13441345
}
@@ -1590,12 +1591,12 @@ void CM_TraceCapsuleThroughCapsule( traceWork_t *tw, clipHandle_t model )
15901591
CM_ModelBounds( model, mins, maxs );
15911592

15921593
// test trace bounds vs. capsule bounds
1593-
if ( tw->bounds[ 0 ][ 0 ] > maxs[ 0 ] + RADIUS_EPSILON
1594-
|| tw->bounds[ 0 ][ 1 ] > maxs[ 1 ] + RADIUS_EPSILON
1595-
|| tw->bounds[ 0 ][ 2 ] > maxs[ 2 ] + RADIUS_EPSILON
1596-
|| tw->bounds[ 1 ][ 0 ] < mins[ 0 ] - RADIUS_EPSILON
1597-
|| tw->bounds[ 1 ][ 1 ] < mins[ 1 ] - RADIUS_EPSILON
1598-
|| tw->bounds[ 1 ][ 2 ] < mins[ 2 ] - RADIUS_EPSILON )
1594+
if ( tw->bounds.mins[ 0 ] > maxs[ 0 ] + RADIUS_EPSILON
1595+
|| tw->bounds.mins[ 1 ] > maxs[ 1 ] + RADIUS_EPSILON
1596+
|| tw->bounds.mins[ 2 ] > maxs[ 2 ] + RADIUS_EPSILON
1597+
|| tw->bounds.maxs[ 0 ] < mins[ 0 ] - RADIUS_EPSILON
1598+
|| tw->bounds.maxs[ 1 ] < mins[ 1 ] - RADIUS_EPSILON
1599+
|| tw->bounds.maxs[ 2 ] < mins[ 2 ] - RADIUS_EPSILON )
15991600
{
16001601
return;
16011602
}
@@ -1964,13 +1965,13 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
19641965
{
19651966
if ( tw.start[ i ] < tw.end[ i ] )
19661967
{
1967-
tw.bounds[ 0 ][ i ] = tw.start[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
1968-
tw.bounds[ 1 ][ i ] = tw.end[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
1968+
tw.bounds.mins[ i ] = tw.start[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
1969+
tw.bounds.maxs[ i ] = tw.end[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
19691970
}
19701971
else
19711972
{
1972-
tw.bounds[ 0 ][ i ] = tw.end[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
1973-
tw.bounds[ 1 ][ i ] = tw.start[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
1973+
tw.bounds.mins[ i ] = tw.end[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
1974+
tw.bounds.maxs[ i ] = tw.start[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
19741975
}
19751976
}
19761977
}
@@ -1980,13 +1981,13 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
19801981
{
19811982
if ( tw.start[ i ] < tw.end[ i ] )
19821983
{
1983-
tw.bounds[ 0 ][ i ] = tw.start[ i ] + tw.size[ 0 ][ i ];
1984-
tw.bounds[ 1 ][ i ] = tw.end[ i ] + tw.size[ 1 ][ i ];
1984+
tw.bounds.mins[ i ] = tw.start[ i ] + tw.size[ 0 ][ i ];
1985+
tw.bounds.maxs[ i ] = tw.end[ i ] + tw.size[ 1 ][ i ];
19851986
}
19861987
else
19871988
{
1988-
tw.bounds[ 0 ][ i ] = tw.end[ i ] + tw.size[ 0 ][ i ];
1989-
tw.bounds[ 1 ][ i ] = tw.start[ i ] + tw.size[ 1 ][ i ];
1989+
tw.bounds.mins[ i ] = tw.end[ i ] + tw.size[ 0 ][ i ];
1990+
tw.bounds.maxs[ i ] = tw.start[ i ] + tw.size[ 1 ][ i ];
19901991
}
19911992
}
19921993
}

src/common/cm/cm_trisoup.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,27 @@ cSurfaceCollide_t *CM_GenerateTriangleSoupCollide( int numVertexes, vec3_t *vert
318318
//for(i = 0; i < triSoup.num
319319

320320
sc = ( cSurfaceCollide_t * ) CM_Alloc( sizeof( *sc ) );
321-
ClearBounds( sc->bounds[ 0 ], sc->bounds[ 1 ] );
321+
ClearBounds( sc->bounds );
322322

323323
for ( i = 0; i < triSoup.numTriangles; i++ )
324324
{
325325
for ( j = 0; j < 3; j++ )
326326
{
327-
AddPointToBounds( triSoup.points[ i ][ j ], sc->bounds[ 0 ], sc->bounds[ 1 ] );
327+
AddPointToBounds( triSoup.points[ i ][ j ], sc->bounds );
328328
}
329329
}
330330

331331
// generate a bsp tree for the surface
332332
CM_SurfaceCollideFromTriangleSoup( &triSoup, sc );
333333

334334
// expand by one unit for epsilon purposes
335-
sc->bounds[ 0 ][ 0 ] -= 1;
336-
sc->bounds[ 0 ][ 1 ] -= 1;
337-
sc->bounds[ 0 ][ 2 ] -= 1;
335+
sc->bounds.mins[ 0 ] -= 1;
336+
sc->bounds.mins[ 1 ] -= 1;
337+
sc->bounds.mins[ 2 ] -= 1;
338338

339-
sc->bounds[ 1 ][ 0 ] += 1;
340-
sc->bounds[ 1 ][ 1 ] += 1;
341-
sc->bounds[ 1 ][ 2 ] += 1;
339+
sc->bounds.maxs[ 0 ] += 1;
340+
sc->bounds.maxs[ 1 ] += 1;
341+
sc->bounds.maxs[ 2 ] += 1;
342342

343343
cmLog.Debug( "CM_GenerateTriangleSoupCollide: %i planes %i facets", sc->numPlanes, sc->numFacets );
344344

src/engine/client/cg_msgdef.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ namespace Util {
6666
{
6767
stream.Write<uint32_t>(Util::ordinal(skel.type));
6868
stream.WriteSize(skel.numBones);
69-
for (int i = 0; i < 2; i++) {
70-
for (int j = 0; j < 3; j++) {
71-
stream.Write<float>(skel.bounds[i][j]);
72-
}
73-
}
69+
stream.Write<float>(skel.bounds.mins[0]);
70+
stream.Write<float>(skel.bounds.mins[1]);
71+
stream.Write<float>(skel.bounds.mins[2]);
72+
stream.Write<float>(skel.bounds.maxs[0]);
73+
stream.Write<float>(skel.bounds.maxs[1]);
74+
stream.Write<float>(skel.bounds.maxs[2]);
7475
stream.Write<float>(skel.scale);
7576
size_t length = sizeof(refBone_t) * skel.numBones;
7677
stream.WriteData(&skel.bones, length);
@@ -80,11 +81,12 @@ namespace Util {
8081
refSkeleton_t skel;
8182
skel.type = static_cast<refSkeletonType_t>(stream.Read<uint32_t>());
8283
skel.numBones = stream.ReadSize<refBone_t>();
83-
for (int i = 0; i < 2; i++) {
84-
for (int j = 0; j < 3; j++) {
85-
skel.bounds[i][j] = stream.Read<float>();
86-
}
87-
}
84+
skel.bounds.mins[0] = stream.Read<float>();
85+
skel.bounds.mins[1] = stream.Read<float>();
86+
skel.bounds.mins[2] = stream.Read<float>();
87+
skel.bounds.maxs[0] = stream.Read<float>();
88+
skel.bounds.maxs[1] = stream.Read<float>();
89+
skel.bounds.maxs[2] = stream.Read<float>();
8890
skel.scale = stream.Read<float>();
8991

9092
if (skel.numBones > sizeof(skel.bones) / sizeof(refBone_t)) {

src/engine/client/cl_cgame.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,10 @@ void CGameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& cha
12651265

12661266
case CG_R_MODELBOUNDS:
12671267
IPC::HandleMsg<Render::ModelBoundsMsg>(channel, std::move(reader), [this] (int handle, std::array<float, 3>& mins, std::array<float, 3>& maxs) {
1268-
re.ModelBounds(handle, mins.data(), maxs.data());
1268+
bounds_t bounds;
1269+
re.ModelBounds(handle, bounds);
1270+
VectorCopy(bounds.mins, mins);
1271+
VectorCopy(bounds.maxs, maxs);
12691272
});
12701273
break;
12711274

src/engine/null/null_renderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int R_LerpTag( orientation_t*, const refEntity_t*, const char*, int )
106106
{
107107
return 0;
108108
}
109-
void R_ModelBounds( qhandle_t, vec3_t, vec3_t ) { }
109+
void R_ModelBounds( qhandle_t, bounds_t& ) { }
110110
void R_RemapShader( const char*, const char*, const char* ) { }
111111
bool R_GetEntityToken( char*, int )
112112
{

0 commit comments

Comments
 (0)