Skip to content

Add bounds_t with pre-aligned mins and maxs #1482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions cmake/DaemonFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@ macro(set_c_cxx_flag FLAG)
set_c_flag(${FLAG} ${ARGN})
set_cxx_flag(${FLAG} ${ARGN})
endmacro()

macro(set_kind_linker_flag KIND FLAG)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are random cmake changes in here by mistake

if (KIND STREQUAL "exe")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAG}")
else()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAG}")
endif()
endmacro()

macro(set_linker_flag FLAG)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAG}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAG}")
set_kind_linker_flag("exe" FLAG)
set_kind_linker_flag("shared" FLAG)
endmacro()

function(try_flag LIST FLAG)
Expand Down Expand Up @@ -142,6 +151,16 @@ macro(try_linker_flag PROP FLAG)
endif()
endmacro()

macro(try_kind_linker_flag KIND PROP FLAG)
# Check it with the C compiler
set(CMAKE_REQUIRED_FLAGS ${FLAG})
check_C_compiler_flag(${FLAG} FLAG_${KIND}_${PROP})
set(CMAKE_REQUIRED_FLAGS "")
if (FLAG_${KIND}_${PROP})
set_kind_linker_flag(${KIND} ${FLAG} ${ARGN})
endif()
endmacro()

if (BE_VERBOSE)
set(WARNMODE "no-error=")
else()
Expand Down Expand Up @@ -348,13 +367,19 @@ else()
try_c_cxx_flag(WSTACK_PROTECTOR "-Wstack-protector")

if (NOT NACL OR (NACL AND GAME_PIE))
try_c_cxx_flag(FPIE "-fPIE")
if (BUILD_GAME_NATIVE_DLL AND (BUILD_CGAME OR BUILD_SGAME))
try_c_cxx_flag(FPIC "-fPIC")
else()
try_c_cxx_flag(FPIE "-fPIE")
endif()

if (NOT APPLE)
try_linker_flag(LINKER_PIE "-pie")
try_kind_linker_flag("shared" LINKER_PIC "-pic")
try_kind_linker_flag("exe" LINKER_PIE "-pie")
endif()
endif()

if ("${FLAG_LINKER_PIE}" AND MINGW)
if ("${FLAG_shared_LINKER_PIE}" AND MINGW)
# https://github.com/msys2/MINGW-packages/issues/4100
if (ARCH STREQUAL "i686")
set_linker_flag("-Wl,-e,_mainCRTStartup")
Expand Down
15 changes: 7 additions & 8 deletions src/common/cm/cm_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ CM_BoundBrush
*/
void CM_BoundBrush( cbrush_t *b )
{
b->bounds[ 0 ][ 0 ] = -b->sides[ 0 ].plane->dist;
b->bounds[ 1 ][ 0 ] = b->sides[ 1 ].plane->dist;
b->bounds.mins[ 0 ] = -b->sides[ 0 ].plane->dist;
b->bounds.maxs[ 0 ] = b->sides[ 1 ].plane->dist;

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

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

/*
Expand Down Expand Up @@ -999,8 +999,7 @@ clipHandle_t CM_TempBoxModel( const vec3_t mins, const vec3_t maxs, bool capsule
box_planes[ 10 ].dist = mins[ 2 ];
box_planes[ 11 ].dist = -mins[ 2 ];

VectorCopy( mins, box_brush->bounds[ 0 ] );
VectorCopy( maxs, box_brush->bounds[ 1 ] );
BoundsSet( box_brush->bounds, mins, maxs );

return BOX_MODEL_HANDLE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/common/cm/cm_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct cbrushside_t
struct cbrush_t
{
int contents;
vec3_t bounds[ 2 ];
bounds_t bounds;
int numsides;
cbrushside_t *sides;
int checkcount; // to avoid repeated testings
Expand Down Expand Up @@ -129,7 +129,7 @@ struct cFacet_t

struct cSurfaceCollide_t
{
vec3_t bounds[ 2 ];
bounds_t bounds;
int numPlanes; // surface planes plus edge planes
cPlane_t *planes;

Expand Down Expand Up @@ -238,7 +238,7 @@ struct traceWork_t
vec3_t offsets[ 8 ]; // [signbits][x] = either size[0][x] or size[1][x]
float maxOffset; // longest corner length from origin
vec3_t extents; // greatest of abs(size[0]) and abs(size[1])
vec3_t bounds[ 2 ]; // enclosing box of start and end surrounding by size
bounds_t bounds; // enclosing box of start and end surrounding by size
vec3_t modelOrigin; // origin of the model tracing through
int contents; // ored contents of the model tracing through
int skipContents; // ored contents that shall be ignored
Expand All @@ -253,7 +253,7 @@ struct leafList_t
int maxcount;
bool overflowed;
int *list;
vec3_t bounds[ 2 ];
bounds_t bounds; // for bounding box culling
int lastLeaf; // for overflows where each leaf can't be stored individually
void ( *storeLeafs )( leafList_t *ll, int nodenum );
};
Expand Down
16 changes: 8 additions & 8 deletions src/common/cm/cm_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,13 @@ cSurfaceCollide_t *CM_GeneratePatchCollide( int width, int height, const vec3_t
// the approximate surface defined by these points will be
// collided against
sc = ( cSurfaceCollide_t * ) CM_Alloc( sizeof( *sc ) );
ClearBounds( sc->bounds[ 0 ], sc->bounds[ 1 ] );
ClearBounds( sc->bounds );

for ( i = 0; i < grid.width; i++ )
{
for ( j = 0; j < grid.height; j++ )
{
AddPointToBounds( grid.points[ i ][ j ], sc->bounds[ 0 ], sc->bounds[ 1 ] );
AddPointToBounds( grid.points[ i ][ j ], sc->bounds );
}
}

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

// expand by one unit for epsilon purposes
sc->bounds[ 0 ][ 0 ] -= 1;
sc->bounds[ 0 ][ 1 ] -= 1;
sc->bounds[ 0 ][ 2 ] -= 1;
sc->bounds.mins[ 0 ] -= 1;
sc->bounds.mins[ 1 ] -= 1;
sc->bounds.mins[ 2 ] -= 1;

sc->bounds[ 1 ][ 0 ] += 1;
sc->bounds[ 1 ][ 1 ] += 1;
sc->bounds[ 1 ][ 2 ] += 1;
sc->bounds.maxs[ 0 ] += 1;
sc->bounds.maxs[ 1 ] += 1;
sc->bounds.maxs[ 2 ] += 1;

return sc;
}
7 changes: 3 additions & 4 deletions src/common/cm/cm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void CM_BoxLeafnums_r( leafList_t *ll, int nodenum )

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

if ( s == 1 )
{
Expand Down Expand Up @@ -170,8 +170,7 @@ int CM_BoxLeafnums( const vec3_t mins, const vec3_t maxs, int *list, int listsiz

cm.checkcount++;

VectorCopy( mins, ll.bounds[ 0 ] );
VectorCopy( maxs, ll.bounds[ 1 ] );
BoundsSet( ll.bounds, mins, maxs );
ll.count = 0;
ll.maxcount = listsize;
ll.list = list;
Expand Down Expand Up @@ -236,7 +235,7 @@ int CM_PointContents( const vec3_t p, clipHandle_t model )
const cbrush_t *b = &cm.brushes[ *brushNum ];

// XreaL BEGIN
if ( !CM_BoundsIntersectPoint( b->bounds[ 0 ], b->bounds[ 1 ], p ) )
if ( !CM_BoundsIntersectPoint( b->bounds.mins, b->bounds.maxs, p ) )
{
continue;
}
Expand Down
61 changes: 31 additions & 30 deletions src/common/cm/cm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ static void CM_TestBoxInBrush( traceWork_t *tw, const cbrush_t *brush )

// special test for axial
// the first 6 brush planes are always axial
if ( tw->bounds[ 0 ][ 0 ] > brush->bounds[ 1 ][ 0 ]
|| tw->bounds[ 0 ][ 1 ] > brush->bounds[ 1 ][ 1 ]
|| tw->bounds[ 0 ][ 2 ] > brush->bounds[ 1 ][ 2 ]
|| tw->bounds[ 1 ][ 0 ] < brush->bounds[ 0 ][ 0 ]
|| tw->bounds[ 1 ][ 1 ] < brush->bounds[ 0 ][ 1 ] || tw->bounds[ 1 ][ 2 ] < brush->bounds[ 0 ][ 2 ] )
if ( tw->bounds.mins[ 0 ] > brush->bounds.maxs[ 0 ]
|| tw->bounds.mins[ 1 ] > brush->bounds.maxs[ 1 ]
|| tw->bounds.mins[ 2 ] > brush->bounds.maxs[ 2 ]
|| tw->bounds.maxs[ 0 ] < brush->bounds.mins[ 0 ]
|| tw->bounds.maxs[ 1 ] < brush->bounds.mins[ 1 ]
|| tw->bounds.maxs[ 2 ] < brush->bounds.mins[ 2 ] )
{
return;
}
Expand Down Expand Up @@ -613,17 +614,17 @@ void CM_PositionTest( traceWork_t *tw )
leafList_t ll;

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

{
ll.bounds[ 0 ][ 0 ] -= 1;
ll.bounds[ 0 ][ 1 ] -= 1;
ll.bounds[ 0 ][ 2 ] -= 1;
ll.bounds.mins[ 0 ] -= 1;
ll.bounds.mins[ 1 ] -= 1;
ll.bounds.mins[ 2 ] -= 1;

ll.bounds[ 1 ][ 0 ] += 1;
ll.bounds[ 1 ][ 1 ] += 1;
ll.bounds[ 1 ][ 2 ] += 1;
ll.bounds.maxs[ 0 ] += 1;
ll.bounds.maxs[ 1 ] += 1;
ll.bounds.maxs[ 2 ] += 1;
}

ll.count = 0;
Expand Down Expand Up @@ -850,7 +851,7 @@ void CM_TraceThroughSurfaceCollide( traceWork_t *tw, const cSurfaceCollide_t *sc
cFacet_t *facet;
vec3_t startp, endp;

if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], sc->bounds[ 0 ], sc->bounds[ 1 ] ) )
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, sc->bounds.mins, sc->bounds.maxs ) )
{
return;
}
Expand Down Expand Up @@ -1290,7 +1291,7 @@ void CM_TraceThroughLeaf( traceWork_t *tw, const cLeaf_t *leaf )
continue;
}

if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], b->bounds[ 0 ], b->bounds[ 1 ] ) )
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, b->bounds.mins, b->bounds.maxs ) )
{
continue;
}
Expand Down Expand Up @@ -1338,7 +1339,7 @@ void CM_TraceThroughLeaf( traceWork_t *tw, const cLeaf_t *leaf )
continue;
}

if ( !CM_BoundsIntersect( tw->bounds[ 0 ], tw->bounds[ 1 ], surface->sc->bounds[ 0 ], surface->sc->bounds[ 1 ] ) )
if ( !CM_BoundsIntersect( tw->bounds.mins, tw->bounds.maxs, surface->sc->bounds.mins, surface->sc->bounds.maxs ) )
{
continue;
}
Expand Down Expand Up @@ -1590,12 +1591,12 @@ void CM_TraceCapsuleThroughCapsule( traceWork_t *tw, clipHandle_t model )
CM_ModelBounds( model, mins, maxs );

// test trace bounds vs. capsule bounds
if ( tw->bounds[ 0 ][ 0 ] > maxs[ 0 ] + RADIUS_EPSILON
|| tw->bounds[ 0 ][ 1 ] > maxs[ 1 ] + RADIUS_EPSILON
|| tw->bounds[ 0 ][ 2 ] > maxs[ 2 ] + RADIUS_EPSILON
|| tw->bounds[ 1 ][ 0 ] < mins[ 0 ] - RADIUS_EPSILON
|| tw->bounds[ 1 ][ 1 ] < mins[ 1 ] - RADIUS_EPSILON
|| tw->bounds[ 1 ][ 2 ] < mins[ 2 ] - RADIUS_EPSILON )
if ( tw->bounds.mins[ 0 ] > maxs[ 0 ] + RADIUS_EPSILON
|| tw->bounds.mins[ 1 ] > maxs[ 1 ] + RADIUS_EPSILON
|| tw->bounds.mins[ 2 ] > maxs[ 2 ] + RADIUS_EPSILON
|| tw->bounds.maxs[ 0 ] < mins[ 0 ] - RADIUS_EPSILON
|| tw->bounds.maxs[ 1 ] < mins[ 1 ] - RADIUS_EPSILON
|| tw->bounds.maxs[ 2 ] < mins[ 2 ] - RADIUS_EPSILON )
{
return;
}
Expand Down Expand Up @@ -1964,13 +1965,13 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
{
if ( tw.start[ i ] < tw.end[ i ] )
{
tw.bounds[ 0 ][ i ] = tw.start[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds[ 1 ][ i ] = tw.end[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
tw.bounds.mins[ i ] = tw.start[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds.maxs[ i ] = tw.end[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
}
else
{
tw.bounds[ 0 ][ i ] = tw.end[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds[ 1 ][ i ] = tw.start[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
tw.bounds.mins[ i ] = tw.end[ i ] - fabsf( tw.sphere.offset[ i ] ) - tw.sphere.radius;
tw.bounds.maxs[ i ] = tw.start[ i ] + fabsf( tw.sphere.offset[ i ] ) + tw.sphere.radius;
}
}
}
Expand All @@ -1980,13 +1981,13 @@ static void CM_Trace( trace_t *results, const vec3_t start, const vec3_t end, co
{
if ( tw.start[ i ] < tw.end[ i ] )
{
tw.bounds[ 0 ][ i ] = tw.start[ i ] + tw.size[ 0 ][ i ];
tw.bounds[ 1 ][ i ] = tw.end[ i ] + tw.size[ 1 ][ i ];
tw.bounds.mins[ i ] = tw.start[ i ] + tw.size[ 0 ][ i ];
tw.bounds.maxs[ i ] = tw.end[ i ] + tw.size[ 1 ][ i ];
}
else
{
tw.bounds[ 0 ][ i ] = tw.end[ i ] + tw.size[ 0 ][ i ];
tw.bounds[ 1 ][ i ] = tw.start[ i ] + tw.size[ 1 ][ i ];
tw.bounds.mins[ i ] = tw.end[ i ] + tw.size[ 0 ][ i ];
tw.bounds.maxs[ i ] = tw.start[ i ] + tw.size[ 1 ][ i ];
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/common/cm/cm_trisoup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,27 +318,27 @@ cSurfaceCollide_t *CM_GenerateTriangleSoupCollide( int numVertexes, vec3_t *vert
//for(i = 0; i < triSoup.num

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

for ( i = 0; i < triSoup.numTriangles; i++ )
{
for ( j = 0; j < 3; j++ )
{
AddPointToBounds( triSoup.points[ i ][ j ], sc->bounds[ 0 ], sc->bounds[ 1 ] );
AddPointToBounds( triSoup.points[ i ][ j ], sc->bounds );
}
}

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

// expand by one unit for epsilon purposes
sc->bounds[ 0 ][ 0 ] -= 1;
sc->bounds[ 0 ][ 1 ] -= 1;
sc->bounds[ 0 ][ 2 ] -= 1;
sc->bounds.mins[ 0 ] -= 1;
sc->bounds.mins[ 1 ] -= 1;
sc->bounds.mins[ 2 ] -= 1;

sc->bounds[ 1 ][ 0 ] += 1;
sc->bounds[ 1 ][ 1 ] += 1;
sc->bounds[ 1 ][ 2 ] += 1;
sc->bounds.maxs[ 0 ] += 1;
sc->bounds.maxs[ 1 ] += 1;
sc->bounds.maxs[ 2 ] += 1;

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

Expand Down
22 changes: 12 additions & 10 deletions src/engine/client/cg_msgdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ namespace Util {
{
stream.Write<uint32_t>(Util::ordinal(skel.type));
stream.WriteSize(skel.numBones);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
stream.Write<float>(skel.bounds[i][j]);
}
}
stream.Write<float>(skel.bounds.mins[0]);
stream.Write<float>(skel.bounds.mins[1]);
stream.Write<float>(skel.bounds.mins[2]);
stream.Write<float>(skel.bounds.maxs[0]);
stream.Write<float>(skel.bounds.maxs[1]);
stream.Write<float>(skel.bounds.maxs[2]);
stream.Write<float>(skel.scale);
size_t length = sizeof(refBone_t) * skel.numBones;
stream.WriteData(&skel.bones, length);
Expand All @@ -80,11 +81,12 @@ namespace Util {
refSkeleton_t skel;
skel.type = static_cast<refSkeletonType_t>(stream.Read<uint32_t>());
skel.numBones = stream.ReadSize<refBone_t>();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
skel.bounds[i][j] = stream.Read<float>();
}
}
skel.bounds.mins[0] = stream.Read<float>();
skel.bounds.mins[1] = stream.Read<float>();
skel.bounds.mins[2] = stream.Read<float>();
skel.bounds.maxs[0] = stream.Read<float>();
skel.bounds.maxs[1] = stream.Read<float>();
skel.bounds.maxs[2] = stream.Read<float>();
skel.scale = stream.Read<float>();

if (skel.numBones > sizeof(skel.bones) / sizeof(refBone_t)) {
Expand Down
Loading