recast and detour patch now builds again with GCC

- rearrange structs to work for 64bit
- define all vars before goto's
- ifdefs for qsort_r/qsort_s
- dont cast pointers to int only for NULL checks
- dont printf STR_String directly, get the char pointer from it

also minor change to gpu py module, no need to pass empty tuple to PyObject_CallObject, can just be NULL
This commit is contained in:
Campbell Barton 2011-09-10 03:07:26 +00:00
parent 23b843130b
commit 0128218254
8 changed files with 61 additions and 46 deletions

View File

@ -188,7 +188,7 @@ bool rcBuildCompactHeightfield(const int walkableHeight, const int walkableClimb
if (s->flags == flags)
{
const int bot = (int)s->smax;
const int top = (int)s->next ? (int)s->next->smin : MAX_HEIGHT;
const int top = s->next ? (int)s->next->smin : MAX_HEIGHT;
chf.spans[idx].y = (unsigned short)rcClamp(bot, 0, 0xffff);
chf.spans[idx].h = (unsigned char)rcClamp(top - bot, 0, 0xff);
idx++;

View File

@ -46,7 +46,7 @@ void rcFilterLedgeSpans(const int walkableHeight,
continue;
const int bot = (int)s->smax;
const int top = (int)s->next ? (int)s->next->smin : MAX_HEIGHT;
const int top = s->next ? (int)s->next->smin : MAX_HEIGHT;
// Find neighbours minimum height.
int minh = MAX_HEIGHT;
@ -74,7 +74,7 @@ void rcFilterLedgeSpans(const int walkableHeight,
for (ns = solid.spans[dx + dy*w]; ns; ns = ns->next)
{
nbot = (int)ns->smax;
ntop = (int)ns->next ? (int)ns->next->smin : MAX_HEIGHT;
ntop = ns->next ? (int)ns->next->smin : MAX_HEIGHT;
// Skip neightbour if the gap between the spans is too small.
if (rcMin(top,ntop) - rcMax(bot,nbot) > walkableHeight)
minh = rcMin(minh, nbot - bot);
@ -115,7 +115,7 @@ void rcFilterWalkableLowHeightSpans(int walkableHeight,
for (rcSpan* s = solid.spans[x + y*w]; s; s = s->next)
{
const int bot = (int)s->smax;
const int top = (int)s->next ? (int)s->next->smin : MAX_HEIGHT;
const int top = s->next ? (int)s->next->smin : MAX_HEIGHT;
if ((top - bot) <= walkableHeight)
s->flags &= ~RC_WALKABLE;
}
@ -194,7 +194,7 @@ bool rcMarkReachableSpans(const int walkableHeight,
rcReachableSeed cur = stack[stackSize];
const int bot = (int)cur.s->smax;
const int top = (int)cur.s->next ? (int)cur.s->next->smin : MAX_HEIGHT;
const int top = cur.s->next ? (int)cur.s->next->smin : MAX_HEIGHT;
// Visit neighbours in all 4 directions.
for (int dir = 0; dir < 4; ++dir)
@ -214,7 +214,7 @@ bool rcMarkReachableSpans(const int walkableHeight,
continue;
const int nbot = (int)ns->smax;
const int ntop = (int)ns->next ? (int)ns->next->smin : MAX_HEIGHT;
const int ntop = ns->next ? (int)ns->next->smin : MAX_HEIGHT;
// Skip neightbour if the gap between the spans is too small.
if (rcMin(top,ntop) - rcMax(bot,nbot) < walkableHeight)
continue;

View File

@ -489,6 +489,9 @@ static void pushBack(int v, int* arr, int& an)
static bool removeVertex(rcPolyMesh& mesh, const unsigned short rem, const int maxTris)
{
unsigned short* tmpPoly;
int ntris;
static const int nvp = mesh.nvp;
int* edges = 0;
@ -671,7 +674,7 @@ static bool removeVertex(rcPolyMesh& mesh, const unsigned short rem, const int m
}
// Triangulate the hole.
int ntris = triangulate(nhole, &tverts[0], &thole[0], tris);
ntris = triangulate(nhole, &tverts[0], &thole[0], tris);
// Merge the hole triangles back to polygons.
polys = new unsigned short[(ntris+1)*nvp];
@ -689,7 +692,7 @@ static bool removeVertex(rcPolyMesh& mesh, const unsigned short rem, const int m
goto failure;
}
unsigned short* tmpPoly = &polys[ntris*nvp];
tmpPoly = &polys[ntris*nvp];
// Build initial polygons.
memset(polys, 0xff, ntris*nvp*sizeof(unsigned short));
@ -793,7 +796,9 @@ failure:
bool rcBuildPolyMesh(rcContourSet& cset, int nvp, rcPolyMesh& mesh)
{
unsigned short* tmpPoly;
rcTimeVal startTime = rcGetPerformanceTimer();
rcTimeVal endTime;
vcopy(mesh.bmin, cset.bmin);
vcopy(mesh.bmax, cset.bmax);
@ -902,7 +907,7 @@ bool rcBuildPolyMesh(rcContourSet& cset, int nvp, rcPolyMesh& mesh)
rcGetLog()->log(RC_LOG_ERROR, "rcBuildPolyMesh: Out of memory 'polys' (%d).", maxVertsPerCont*nvp);
goto failure;
}
unsigned short* tmpPoly = &polys[maxVertsPerCont*nvp];
tmpPoly = &polys[maxVertsPerCont*nvp];
for (int i = 0; i < cset.nconts; ++i)
{
@ -1050,7 +1055,7 @@ bool rcBuildPolyMesh(rcContourSet& cset, int nvp, rcPolyMesh& mesh)
return false;
}
rcTimeVal endTime = rcGetPerformanceTimer();
endTime = rcGetPerformanceTimer();
// if (rcGetLog())
// rcGetLog()->log(RC_LOG_PROGRESS, "Build polymesh: %.3f ms", rcGetDeltaTimeUsec(startTime, endTime)/1000.0f);
@ -1076,6 +1081,7 @@ bool rcMergePolyMeshes(rcPolyMesh** meshes, const int nmeshes, rcPolyMesh& mesh)
return true;
rcTimeVal startTime = rcGetPerformanceTimer();
rcTimeVal endTime;
int* nextVert = 0;
int* firstVert = 0;
@ -1196,7 +1202,7 @@ bool rcMergePolyMeshes(rcPolyMesh** meshes, const int nmeshes, rcPolyMesh& mesh)
delete [] nextVert;
delete [] vremap;
rcTimeVal endTime = rcGetPerformanceTimer();
endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->mergePolyMesh += rcGetDeltaTimeUsec(startTime, endTime);

View File

@ -95,7 +95,11 @@ static int circumCircle(const float xp, const float yp,
return (drsqr <= rsqr) ? 1 : 0;
}
#if defined(_MSC_VER)
static int ptcmp(void* up, const void *v1, const void *v2)
#else
static int ptcmp(const void *v1, const void *v2, void* up)
#endif
{
const float* verts = (const float*)up;
const float* p1 = &verts[(*(const int*)v1)*3];
@ -116,10 +120,10 @@ static void delaunay(const int nv, float *verts, rcIntArray& idx, rcIntArray& tr
idx.resize(nv);
for (int i = 0; i < nv; ++i)
idx[i] = i;
#ifdef WIN32
#if defined(_MSC_VER)
qsort_s(&idx[0], idx.size(), sizeof(int), ptcmp, verts);
#else
qsort_r(&idx[0], idx.size(), sizeof(int), verts, ptcmp);
qsort_r(&idx[0], idx.size(), sizeof(int), ptcmp, verts);
#endif
// Find the maximum and minimum vertex bounds.
@ -673,11 +677,15 @@ bool rcBuildPolyMeshDetail(const rcPolyMesh& mesh, const rcCompactHeightfield& c
const float sampleDist, const float sampleMaxError,
rcPolyMeshDetail& dmesh)
{
rcTimeVal startTime = rcGetPerformanceTimer();
if (mesh.nverts == 0 || mesh.npolys == 0)
return true;
rcTimeVal startTime = rcGetPerformanceTimer();
rcTimeVal endTime;
int vcap;
int tcap;
const int nvp = mesh.nvp;
const float cs = mesh.cs;
const float ch = mesh.ch;
@ -760,8 +768,8 @@ bool rcBuildPolyMeshDetail(const rcPolyMesh& mesh, const rcCompactHeightfield& c
goto failure;
}
int vcap = nPolyVerts+nPolyVerts/2;
int tcap = vcap*2;
vcap = nPolyVerts+nPolyVerts/2;
tcap = vcap*2;
dmesh.nverts = 0;
dmesh.verts = new float[vcap*3];
@ -882,7 +890,7 @@ bool rcBuildPolyMeshDetail(const rcPolyMesh& mesh, const rcCompactHeightfield& c
delete [] bounds;
delete [] poly;
rcTimeVal endTime = rcGetPerformanceTimer();
endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->buildDetailMesh += rcGetDeltaTimeUsec(startTime, endTime);

View File

@ -146,7 +146,6 @@ bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys,
const float* verts, const unsigned short* dtris,
const int* dtrisToPolysMap)
{
bool res = false;
int capacity = vertsPerPoly;
unsigned short* newPoly = new unsigned short[capacity];
memset(newPoly, 0xff, sizeof(unsigned short)*capacity);
@ -268,7 +267,6 @@ bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys,
}
}
}
res = true;
returnLabel:
delete newPoly;
@ -280,8 +278,13 @@ struct SortContext
const int* recastData;
const int* trisToFacesMap;
};
static int compareByData(void* data, const void * a, const void * b){
SortContext* context = (SortContext*)data;
#if defined(_MSC_VER)
static int compareByData(const void* data, void * a, void * b)
#else
static int compareByData(const void * a, const void * b, void* data)
#endif
{
const SortContext* context = (const SortContext*)data;
return ( context->recastData[context->trisToFacesMap[*(int*)a]] -
context->recastData[context->trisToFacesMap[*(int*)b]] );
}
@ -307,8 +310,11 @@ bool buildNavMeshData(const int nverts, const float* verts,
SortContext context;
context.recastData = recastData;
context.trisToFacesMap = trisToFacesMap;
#if defined(_MSC_VER)
qsort_s(trisMapping, ntris, sizeof(int), compareByData, &context);
#else
qsort_r(trisMapping, ntris, sizeof(int), compareByData, &context);
#endif
//search first valid triangle - triangle of convex polygon
int validTriStart = -1;
for (int i=0; i< ntris; i++)

View File

@ -445,6 +445,19 @@ typedef struct RecastData
typedef struct GameData {
/* standalone player */
struct GameFraming framing;
short fullscreen, xplay, yplay, freqplay;
short depth, attrib, rt1, rt2;
/* stereo/dome mode */
struct GameDome dome;
short stereoflag, stereomode;
short pad2, pad3;
float eyeseparation, pad1;
RecastData recastData;
/* physics (it was in world)*/
float gravity; /*Gravitation constant for the game world*/
@ -463,19 +476,6 @@ typedef struct GameData {
short ticrate, maxlogicstep, physubstep, maxphystep;
short obstacleSimulation;
float levelHeight;
/* standalone player */
struct GameFraming framing;
short fullscreen, xplay, yplay, freqplay;
short depth, attrib, rt1, rt2;
/* stereo/dome mode */
struct GameDome dome;
short stereoflag, stereomode;
short pad2, pad3;
float eyeseparation, pad1;
RecastData recastData;
} GameData;
#define STEREO_NOSTEREO 1

View File

@ -147,7 +147,6 @@ static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObj
PyObject* pymat;
PyObject* as_pointer;
PyObject* pointer;
PyObject* noargs;
PyObject* result;
PyObject* dict;
PyObject* val;
@ -170,9 +169,7 @@ static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObj
(as_pointer = PyObject_GetAttrString(pyscene, "as_pointer")) != NULL &&
PyCallable_Check(as_pointer)) {
// must be a scene object
noargs = PyTuple_New(0);
pointer = PyObject_CallObject(as_pointer, noargs);
Py_DECREF(noargs);
pointer = PyObject_CallObject(as_pointer, NULL);
if (!pointer) {
PyErr_SetString(PyExc_SystemError, "scene.as_pointer() failed");
return NULL;
@ -192,9 +189,7 @@ static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObj
(as_pointer = PyObject_GetAttrString(pymat, "as_pointer")) != NULL &&
PyCallable_Check(as_pointer)) {
// must be a material object
noargs = PyTuple_New(0);
pointer = PyObject_CallObject(as_pointer, noargs);
Py_DECREF(noargs);
pointer = PyObject_CallObject(as_pointer, NULL);
if (!pointer) {
PyErr_SetString(PyExc_SystemError, "scene.as_pointer() failed");
return NULL;

View File

@ -282,7 +282,7 @@ bool KX_NavMeshObject::BuildNavMesh()
if (GetMeshCount()==0)
{
printf("Can't find mesh for navmesh object: %s \n", m_name);
printf("Can't find mesh for navmesh object: %s \n", m_name.ReadPtr());
return false;
}
@ -294,7 +294,7 @@ bool KX_NavMeshObject::BuildNavMesh()
dmeshes, dvertices, ndvertsuniq, dtris, ndtris, vertsPerPoly )
|| vertsPerPoly<3)
{
printf("Can't build navigation mesh data for object:%s \n", m_name);
printf("Can't build navigation mesh data for object:%s \n", m_name.ReadPtr());
return false;
}