mirror of
https://github.com/ptitSeb/Serious-Engine
synced 2024-12-26 15:44:51 +01:00
Resolved some 64bit issues, marked/commented some others
introduced PLATFORM_32BIT and PLATFORM_64BIT macros, so you can do #ifdef PLATFORM_64BIT if you need to. I needed that for CDrawPort::GetID() to properly CRC a pointer. Also added a sanity check in Engine/Base/Types.h that makes sure that uintprt_t and size_t have the same size, as the code uses size_t to store pointers (or cast from pointer to int) all over the place. Made some "tags" from Engine/Templates/BSP_internal.h size_t instead of ULONG - they're used to store pointers to identify vertices and such, so they'd better be big enough to actually store a pointer. Some more are still missing.
This commit is contained in:
parent
8d26863a51
commit
599f644328
|
@ -44,6 +44,18 @@ inline void CRC_AddLONG( ULONG &ulCRC, ULONG ul)
|
|||
CRC_AddBYTE(ulCRC, UBYTE(ul>> 0));
|
||||
};
|
||||
|
||||
inline void CRC_AddLONGLONG( ULONG &ulCRC, __uint64 x)
|
||||
{
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>>56));
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>>48));
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>>40));
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>>32));
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>>24));
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>>16));
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>> 8));
|
||||
CRC_AddBYTE(ulCRC, UBYTE(x>> 0));
|
||||
}
|
||||
|
||||
inline void CRC_AddFLOAT(ULONG &ulCRC, FLOAT f)
|
||||
{
|
||||
CRC_AddLONG(ulCRC, *(ULONG*)&f);
|
||||
|
|
|
@ -704,6 +704,7 @@ INDEX CShell::GetINDEX(const CTString &strName)
|
|||
return -666;
|
||||
}
|
||||
// get it
|
||||
STUBBED("64-bit issue"); // the return value is used as a pointer a lot!
|
||||
return *(INDEX*)pss->ss_pvValue;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
// get/set symbols
|
||||
FLOAT GetFLOAT(const CTString &strName);
|
||||
void SetFLOAT(const CTString &strName, FLOAT fValue);
|
||||
INDEX GetINDEX(const CTString &strName);
|
||||
INDEX GetINDEX(const CTString &strName); // FIXME DG: maybe this should return size_t or uintptr_t? return value is casted to ptr all the time!
|
||||
void SetINDEX(const CTString &strName, INDEX iValue);
|
||||
CTString GetString(const CTString &strName);
|
||||
void SetString(const CTString &strName, const CTString &strValue);
|
||||
|
|
|
@ -61,6 +61,37 @@ typedef unsigned int UINT;
|
|||
#define PLATFORM_LITTLEENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#ifdef _WIN64
|
||||
#define PLATFORM_64BIT 1
|
||||
#else
|
||||
#define PLATFORM_32BIT 1
|
||||
#endif
|
||||
#else
|
||||
// AFAIK there were versions of MSVC where UINTPTR_MAX was incorrect,
|
||||
// so I use different code for Windows above
|
||||
#include <stdint.h> // UINTPTR_MAX
|
||||
#ifdef UINTPTR_MAX
|
||||
#if UINTPTR_MAX == 0xffffffffuL
|
||||
#define PLATFORM_32BIT 1
|
||||
#elif UINTPTR_MAX == 0xffffffffffffffffuLL
|
||||
#define PLATFORM_64BIT 1
|
||||
#else
|
||||
#error WTF, your system seems to be neither 32bit nor 64bit?!
|
||||
#endif
|
||||
#else
|
||||
#error Your system does not provide UINTPRT_MAX, find another way!
|
||||
#endif
|
||||
|
||||
#if UINTPTR_MAX != SIZE_MAX
|
||||
// the code uses size_t to store pointers all over the place, so if size_t and uintptr_t
|
||||
// don't have the same size on your system, you're in real trouble.
|
||||
// (before panicking however make sure your headers don't just contain bullshit values for UINTPTR_MAX or SIZE_MAX)
|
||||
#error Seems like on your system sizeof(size_t) != sizeof(uintptr_t) - that is *very* bad.
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Mac symbols have an underscore prepended...
|
||||
#if PLATFORM_MACOSX
|
||||
#define ASMSYM(x) "_" #x
|
||||
|
|
|
@ -84,7 +84,7 @@ void CBrushPolygon::CreateBSPPolygon(BSPPolygon<DOUBLE, 3> &bspo)
|
|||
|
||||
// set the plane of the bsp polygon
|
||||
((DOUBLEplane3D &)bspo) = *brpo.bpo_pbplPlane->bpl_ppldPreciseAbsolute;
|
||||
bspo.bpo_ulPlaneTag = (ULONG)brpo.bpo_pbscSector->bsc_abplPlanes.Index(brpo.bpo_pbplPlane);
|
||||
bspo.bpo_ulPlaneTag = (size_t)brpo.bpo_pbscSector->bsc_abplPlanes.Index(brpo.bpo_pbplPlane);
|
||||
|
||||
// create the array of edges in the bsp polygon
|
||||
INDEX ctEdges = brpo.bpo_abpePolygonEdges.Count();
|
||||
|
@ -109,7 +109,7 @@ void CBrushPolygon::CreateBSPPolygonNonPrecise(BSPPolygon<DOUBLE, 3> &bspo)
|
|||
|
||||
// set the plane of the bsp polygon
|
||||
((DOUBLEplane3D &)bspo) = FLOATtoDOUBLE(brpo.bpo_pbplPlane->bpl_plAbsolute);
|
||||
bspo.bpo_ulPlaneTag = (ULONG)brpo.bpo_pbscSector->bsc_abplPlanes.Index(brpo.bpo_pbplPlane);
|
||||
bspo.bpo_ulPlaneTag = (size_t)brpo.bpo_pbscSector->bsc_abplPlanes.Index(brpo.bpo_pbplPlane);
|
||||
// calculate offset for points
|
||||
DOUBLE3D vOffset = FLOATtoDOUBLE(((FLOAT3D&)brpo.bpo_pbplPlane->bpl_plAbsolute))*-fOffset;
|
||||
// offset the plane
|
||||
|
|
|
@ -221,8 +221,11 @@ ULONG CDrawPort::GetID(void)
|
|||
{
|
||||
ULONG ulCRC;
|
||||
CRC_Start( ulCRC);
|
||||
STUBBED("64-bit issue");
|
||||
#ifdef PLATFORM_64BIT
|
||||
CRC_AddLONGLONG( ulCRC, (__uint64)(size_t)dp_Raster);
|
||||
#else
|
||||
CRC_AddLONG( ulCRC, (ULONG)(size_t)dp_Raster);
|
||||
#endif
|
||||
CRC_AddLONG( ulCRC, (ULONG)dp_MinI);
|
||||
CRC_AddLONG( ulCRC, (ULONG)dp_MinJ);
|
||||
CRC_AddLONG( ulCRC, (ULONG)dp_MaxI);
|
||||
|
|
|
@ -1367,7 +1367,8 @@ void CTextureData::SetAsCurrent( INDEX iFrameNo/*=0*/, BOOL bForceUpload/*=FALSE
|
|||
for( INDEX iFr=0; iFr<td_ctFrames; iFr++)
|
||||
{ // determine frame offset and upload texture frame
|
||||
ULONG *pulCurrentFrame = td_pulFrames + (iFr * td_slFrameSize/BYTES_PER_TEXEL);
|
||||
gfxSetTexture( ((ULONG*)td_ulObject)[iFr], td_tpLocal);
|
||||
STUBBED("64-bit issue");
|
||||
gfxSetTexture( ((ULONG*)td_ulObject)[iFr], td_tpLocal); // FIXME DG: use that union properly or something?!
|
||||
gfxUploadTexture( pulCurrentFrame, pixWidth, pixHeight, td_ulInternalFormat, bNoDiscard);
|
||||
}
|
||||
} else {
|
||||
|
@ -1401,11 +1402,13 @@ void CTextureData::SetAsCurrent( INDEX iFrameNo/*=0*/, BOOL bForceUpload/*=FALSE
|
|||
// must reset local texture parameters for each frame of animated texture
|
||||
for( INDEX iFr=0; iFr<td_ctFrames; iFr++) {
|
||||
td_tpLocal.Clear();
|
||||
gfxSetTexture( ((ULONG*)td_ulObject)[iFr], td_tpLocal);
|
||||
STUBBED("64-bit issue");
|
||||
gfxSetTexture( ((ULONG*)td_ulObject)[iFr], td_tpLocal); // FIXME DG: use that union properly or something?!
|
||||
}
|
||||
}
|
||||
// set corresponding probe or texture frame as current
|
||||
ULONG ulTexObject = td_ulObject; // single-frame
|
||||
STUBBED("64-bit issue"); // FIXME DG: same here...
|
||||
if( td_ctFrames>1) ulTexObject = ((ULONG*)td_ulObject)[iFrameNo]; // animation
|
||||
if( bUseProbe) {
|
||||
// set probe if burst value doesn't allow real texture
|
||||
|
|
|
@ -323,16 +323,14 @@ void CObjectCSG::PolygonEdgesToBSPEdges(
|
|||
// if it is reversed
|
||||
if (ope.ope_Backward) {
|
||||
// add bsp edge with reverse vertices
|
||||
STUBBED("64-bit issue"); // we're casting ope.ope_Edge to a 32-bit value. Code really only cares if this is zero or !zero, but one could totally have a non-NULL 64-bit pointer that truncates down to zero!
|
||||
abed[iEdge] = DOUBLEbspedge3D(*ope.ope_Edge->oed_Vertex1,
|
||||
*ope.ope_Edge->oed_Vertex0, (ULONG)(size_t)ope.ope_Edge);
|
||||
*ope.ope_Edge->oed_Vertex0, (size_t)ope.ope_Edge);
|
||||
|
||||
// if it is not reversed
|
||||
} else{
|
||||
// add bsp edge with normal vertices
|
||||
STUBBED("64-bit issue"); // we're casting ope.ope_Edge to a 32-bit value. Code really only cares if this is zero or !zero, but one could totally have a non-NULL 64-bit pointer that truncates down to zero!
|
||||
abed[iEdge] = DOUBLEbspedge3D(*ope.ope_Edge->oed_Vertex0,
|
||||
*ope.ope_Edge->oed_Vertex1, (ULONG)(size_t)ope.ope_Edge);
|
||||
*ope.ope_Edge->oed_Vertex1, (size_t)ope.ope_Edge);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -544,8 +542,7 @@ void CObjectCSG::DoCSGSplitting(
|
|||
oc_popoPortalB1B2 = NULL;
|
||||
|
||||
// create a bsp polygon from first temporary array
|
||||
STUBBED("64-bit issue");
|
||||
DOUBLEbsppolygon3D bpoA(*itopoA->opo_Plane, abedRemaining, (ULONG)(size_t)itopoA->opo_Plane);
|
||||
DOUBLEbsppolygon3D bpoA(*itopoA->opo_Plane, abedRemaining, (size_t)itopoA->opo_Plane);
|
||||
|
||||
// create a BSP cutter for B's sector BSP and A's polygon
|
||||
DOUBLEbspcutter3D bcCutter(bpoA, *itoscB->osc_BSPTree.bt_pbnRoot);
|
||||
|
|
|
@ -1844,8 +1844,7 @@ void CObjectSector::CreateBSP(void)
|
|||
|
||||
// copy the plane
|
||||
(DOUBLEplane3D &)bpo = *opo.opo_Plane;
|
||||
STUBBED("64-bit issue");
|
||||
bpo.bpo_ulPlaneTag = (ULONG)(size_t)opo.opo_Plane;
|
||||
bpo.bpo_ulPlaneTag = (size_t)opo.opo_Plane;
|
||||
|
||||
// get count of edges in this polygon
|
||||
const INDEX ctEdges = opo.opo_PolygonEdges.Count();
|
||||
|
@ -1860,13 +1859,11 @@ void CObjectSector::CreateBSP(void)
|
|||
// if the edge is reversed
|
||||
if(ope.ope_Backward) {
|
||||
// add bsp edge with reversed vertices
|
||||
STUBBED("64-bit issue");
|
||||
pbed[iEdge] = DOUBLEbspedge3D(*oed.oed_Vertex1, *oed.oed_Vertex0, (ULONG)(size_t)&oed);
|
||||
pbed[iEdge] = DOUBLEbspedge3D(*oed.oed_Vertex1, *oed.oed_Vertex0, (size_t)&oed);
|
||||
// otherwise
|
||||
} else {
|
||||
// add normal bsp edge
|
||||
STUBBED("64-bit issue");
|
||||
pbed[iEdge] = DOUBLEbspedge3D(*oed.oed_Vertex0, *oed.oed_Vertex1, (ULONG)(size_t)&oed);
|
||||
pbed[iEdge] = DOUBLEbspedge3D(*oed.oed_Vertex0, *oed.oed_Vertex1, (size_t)&oed);
|
||||
}
|
||||
}
|
||||
opo.opo_PolygonEdges.Unlock();
|
||||
|
|
|
@ -481,7 +481,7 @@ ModelTextureVertex::ModelTextureVertex(void)
|
|||
//------------------------------------------ WRITE
|
||||
void ModelPolygonVertex::Write_t( CTStream *pFile) // throw char *
|
||||
{
|
||||
STUBBED("64-bit issue");
|
||||
STUBBED("64-bit issue"); // DG: probably ok, because PtrToIndices() should have been called before this
|
||||
(*pFile) << (INDEX) (size_t) mpv_ptvTransformedVertex;
|
||||
(*pFile) << (INDEX) (size_t) mpv_ptvTextureVertex;
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ void ModelPolygonVertex::Read_t( CTStream *pFile) // throw char *
|
|||
{
|
||||
INDEX itmp;
|
||||
|
||||
STUBBED("64-bit issue");
|
||||
STUBBED("64-bit issue"); // DG: probably ok, because IndicesToPtrs() should be called afterwards
|
||||
(*pFile) >> itmp;
|
||||
mpv_ptvTransformedVertex = (struct TransformedVertexData *) (size_t) itmp;
|
||||
(*pFile) >> itmp;
|
||||
|
@ -1040,14 +1040,14 @@ void CModelData::PtrsToIndices()
|
|||
if( it2.Current().mpv_ptvTransformedVertex == &md_TransformedVertices[ j])
|
||||
break;
|
||||
}
|
||||
it2.Current().mpv_ptvTransformedVertex = (struct TransformedVertexData *) j;
|
||||
it2.Current().mpv_ptvTransformedVertex = (struct TransformedVertexData *)(size_t)j;
|
||||
|
||||
for( j=0; j<md_MipInfos[ i].mmpi_TextureVertices.Count(); j++)
|
||||
{
|
||||
if( it2.Current().mpv_ptvTextureVertex == &md_MipInfos[ i].mmpi_TextureVertices[ j])
|
||||
break;
|
||||
}
|
||||
it2.Current().mpv_ptvTextureVertex = (ModelTextureVertex *) j;
|
||||
it2.Current().mpv_ptvTextureVertex = (ModelTextureVertex *)(size_t)j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1068,10 +1068,10 @@ void CModelData::IndicesToPtrs()
|
|||
FOREACHINSTATICARRAY(it1.Current().mp_PolygonVertices, ModelPolygonVertex, it2)
|
||||
{
|
||||
struct ModelPolygonVertex * pMPV = &it2.Current();
|
||||
STUBBED("64-bit issue");
|
||||
STUBBED("64-bit issue"); // DG: probably ok, the pointers really contain indices from PtrToIndices()
|
||||
j = (INDEX) (size_t) it2.Current().mpv_ptvTransformedVertex;
|
||||
it2.Current().mpv_ptvTransformedVertex = &md_TransformedVertices[ j];
|
||||
STUBBED("64-bit issue");
|
||||
STUBBED("64-bit issue"); // DG: probably ok, the pointers really contain indices from PtrToIndices()
|
||||
j = (INDEX) (size_t) it2.Current().mpv_ptvTextureVertex;
|
||||
it2.Current().mpv_ptvTextureVertex = &md_MipInfos[ i].mmpi_TextureVertices[ j];
|
||||
}
|
||||
|
|
|
@ -254,6 +254,7 @@ extern void CacheShadows(void)
|
|||
{
|
||||
// mute all sounds
|
||||
_pSound->Mute();
|
||||
STUBBED("64-bit issue"); // GetINDEX() returns int32!
|
||||
CWorld *pwo = (CWorld*)_pShell->GetINDEX("pwoCurrentWorld");
|
||||
if( pwo!=NULL) {
|
||||
pwo->wo_baBrushes.CacheAllShadowmaps();
|
||||
|
@ -522,6 +523,7 @@ static void StockInfo(void)
|
|||
INDEX ctEntities=0, ctShadowLayers=0, ctPolys=0, ctPlanes=0, ctEdges=0, ctVertices=0, ctSectors=0;
|
||||
SLONG slEntBytes=0, slLyrBytes=0, slPlyBytes=0, slPlnBytes=0, slEdgBytes=0, slVtxBytes=0, slSecBytes=0;
|
||||
SLONG slCgrBytes=0;
|
||||
STUBBED("64-bit issue"); // GetINDEX() returns int32!
|
||||
CWorld *pwo = (CWorld*)_pShell->GetINDEX("pwoCurrentWorld");
|
||||
|
||||
if( pwo!=NULL)
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
TIME pe_tmTick;
|
||||
ULONG pe_ulEntityID;
|
||||
ULONG pe_ulTypeID;
|
||||
ULONG pe_ulEventID;
|
||||
ULONG pe_ulEventID; // FIXME: make this void* or uintptr_t/size_t
|
||||
|
||||
CPredictedEvent(void);
|
||||
void Clear(void) {};
|
||||
|
|
|
@ -1139,11 +1139,13 @@ void BSPTree<Type, iDimensions>::MoveSubTreeToArray(BSPNode<Type, iDimensions> *
|
|||
if (pbnSubtree->bn_pbnFront==NULL) {
|
||||
bnInArray.bn_pbnFront = NULL;
|
||||
} else {
|
||||
STUBBED("64-bit issue"); // bn_ulPlaneTag is uint32!
|
||||
bnInArray.bn_pbnFront = (BSPNode<Type, iDimensions>*)pbnSubtree->bn_pbnFront->bn_ulPlaneTag;
|
||||
}
|
||||
if (pbnSubtree->bn_pbnBack==NULL) {
|
||||
bnInArray.bn_pbnBack = NULL;
|
||||
} else {
|
||||
STUBBED("64-bit issue"); // basically the same as above but for back!
|
||||
bnInArray.bn_pbnBack = (BSPNode<Type, iDimensions>*)pbnSubtree->bn_pbnBack->bn_ulPlaneTag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,12 +87,12 @@ class BSPEdge {
|
|||
public:
|
||||
Vector<Type, iDimensions> bed_vVertex0; // edge vertices
|
||||
Vector<Type, iDimensions> bed_vVertex1;
|
||||
ULONG bed_ulEdgeTag; // tags for BSPs with tagged edges/planes
|
||||
size_t bed_ulEdgeTag; // tags for BSPs with tagged edges/planes - FIXME DG: or uintprt_t?
|
||||
|
||||
/* Default constructor. */
|
||||
inline BSPEdge(void) {};
|
||||
/* Constructor with two vectors. */
|
||||
inline BSPEdge(const Vector<Type, iDimensions> &vVertex0, const Vector<Type, iDimensions> &vVertex1, ULONG ulTag)
|
||||
inline BSPEdge(const Vector<Type, iDimensions> &vVertex0, const Vector<Type, iDimensions> &vVertex1, size_t ulTag)
|
||||
: bed_vVertex0(vVertex0), bed_vVertex1(vVertex1), bed_ulEdgeTag(ulTag) {}
|
||||
|
||||
/* Clear the object. */
|
||||
|
@ -110,7 +110,7 @@ template<class Type, int iDimensions>
|
|||
class BSPPolygon : public Plane<Type, iDimensions> {
|
||||
public:
|
||||
CDynamicArray<BSPEdge<Type, iDimensions> > bpo_abedPolygonEdges; // array of edges in the polygon
|
||||
ULONG bpo_ulPlaneTag; // tags for BSPs with tagged planes (-1 for no tag)
|
||||
size_t bpo_ulPlaneTag; // tags for BSPs with tagged planes (-1 for no tag)
|
||||
|
||||
/* Add an edge to the polygon. */
|
||||
inline void AddEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, ULONG ulTag);
|
||||
|
@ -119,7 +119,7 @@ public:
|
|||
inline BSPPolygon(void) : bpo_ulPlaneTag(-1) {};
|
||||
/* Constructor with array of edges and plane. */
|
||||
inline BSPPolygon(
|
||||
Plane<Type, iDimensions> &plPlane, CDynamicArray<BSPEdge<Type, iDimensions> > abedPolygonEdges, ULONG ulPlaneTag)
|
||||
Plane<Type, iDimensions> &plPlane, CDynamicArray<BSPEdge<Type, iDimensions> > abedPolygonEdges, size_t ulPlaneTag)
|
||||
: Plane<Type, iDimensions>(plPlane)
|
||||
, bpo_abedPolygonEdges(abedPolygonEdges)
|
||||
, bpo_ulPlaneTag(ulPlaneTag)
|
||||
|
|
Loading…
Reference in New Issue
Block a user