had to remove uint and ulong from lib/types.h due to conflict with other library.

this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).

it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.

after several hours, the code now requires fewer casts and less
guesswork.

other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.

This was SVN commit r5942.
This commit is contained in:
janwas 2008-05-11 18:48:32 +00:00
parent 9951af47c7
commit c0ed950657
316 changed files with 2142 additions and 2170 deletions

View File

@ -316,7 +316,7 @@ void CCamera::LookAlong( CVector3D camera, CVector3D orientation, CVector3D up )
///////////////////////////////////////////////////////////////////////////////////
// Render the camera's frustum
void CCamera::Render(uint intermediates) const
void CCamera::Render(int intermediates) const
{
CVector3D nearPoints[4];
CVector3D farPoints[4];
@ -361,7 +361,7 @@ void CCamera::Render(uint intermediates) const
// intermediate planes
CVector3D intermediatePoints[4];
for(uint i = 0; i < intermediates; ++i)
for(int i = 0; i < intermediates; ++i)
{
float t = (i+1.0)/(intermediates+1.0);

View File

@ -18,10 +18,10 @@ extern int g_mouse_x, g_mouse_y;
// view port
struct SViewPort
{
unsigned int m_X;
unsigned int m_Y;
unsigned int m_Width;
unsigned int m_Height;
size_t m_X;
size_t m_Y;
size_t m_Width;
size_t m_Height;
};
@ -97,7 +97,7 @@ class CCamera
* @param intermediates determines how many intermediate distance planes should
* be hinted at between the near and far planes
*/
void Render(uint intermediates = 0) const;
void Render(int intermediates = 0) const;
public:
// This is the orientation matrix. The inverse of this

View File

@ -28,22 +28,20 @@ CFrustum::~CFrustum ()
{
}
void CFrustum::SetNumPlanes (int num)
void CFrustum::SetNumPlanes (size_t num)
{
m_NumPlanes = num;
//clip it
if (m_NumPlanes >= MAX_NUM_FRUSTUM_PLANES)
m_NumPlanes = MAX_NUM_FRUSTUM_PLANES-1;
else if (m_NumPlanes < 0)
m_NumPlanes = 0;
}
bool CFrustum::IsPointVisible (const CVector3D &point) const
{
PLANESIDE Side;
for (int i=0; i<m_NumPlanes; i++)
for (size_t i=0; i<m_NumPlanes; i++)
{
Side = m_aPlanes[i].ClassifyPoint (point);
@ -62,7 +60,7 @@ bool CFrustum::DoesSegmentIntersect(const CVector3D& startRef, const CVector3D &
return true;
CVector3D intersect;
for ( int i = 0; i<m_NumPlanes; ++i )
for ( size_t i = 0; i<m_NumPlanes; ++i )
{
if ( m_aPlanes[i].FindLineSegIntersection(start, end, &intersect) )
{
@ -74,7 +72,7 @@ bool CFrustum::DoesSegmentIntersect(const CVector3D& startRef, const CVector3D &
}
bool CFrustum::IsSphereVisible (const CVector3D &center, float radius) const
{
for (int i=0; i<m_NumPlanes; i++)
for (size_t i=0; i<m_NumPlanes; i++)
{
float Dist = m_aPlanes[i].DistanceToPlane (center);
@ -102,7 +100,7 @@ bool CFrustum::IsBoxVisible (const CVector3D &position,const CBound &bounds) con
CVector3D Min = position+bounds[0];
CVector3D Max = position+bounds[1];
for (int i=0; i<m_NumPlanes; i++)
for (size_t i=0; i<m_NumPlanes; i++)
{
if (m_aPlanes[i].m_Norm.X > 0.0f)
{

View File

@ -32,9 +32,9 @@ public:
//Set the number of planes to use for
//calculations. This is clipped to
//[0,MAX_NUM_FRUSTUM_PLANES]
void SetNumPlanes (int num);
void SetNumPlanes (size_t num);
uint GetNumPlanes() const { return m_NumPlanes; }
size_t GetNumPlanes() const { return m_NumPlanes; }
//The following methods return true if the shape is
//partially or completely in front of the frustum planes
@ -43,15 +43,15 @@ public:
bool IsSphereVisible (const CVector3D &center, float radius) const;
bool IsBoxVisible (const CVector3D &position,const CBound &bounds) const;
CPlane& operator[](uint idx) { return m_aPlanes[idx]; }
const CPlane& operator[](uint idx) const { return m_aPlanes[idx]; }
CPlane& operator[](size_t idx) { return m_aPlanes[idx]; }
const CPlane& operator[](size_t idx) const { return m_aPlanes[idx]; }
public:
//make the planes public for ease of use
CPlane m_aPlanes[MAX_NUM_FRUSTUM_PLANES];
private:
int m_NumPlanes;
size_t m_NumPlanes;
};
#endif

View File

@ -306,11 +306,11 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
{
PROFILE_START( "submit terrain" );
CTerrain* pTerrain = m->Game->GetWorld()->GetTerrain();
u32 patchesPerSide = pTerrain->GetPatchesPerSide();
const ssize_t patchesPerSide = pTerrain->GetPatchesPerSide();
// findout, which patches will be drawn
for (uint j=0; j<patchesPerSide; j++) {
for (uint i=0; i<patchesPerSide; i++) {
// find out which patches will be drawn
for (ssize_t j=0; j<patchesPerSide; j++) {
for (ssize_t i=0; i<patchesPerSide; i++) {
CPatch* patch=pTerrain->GetPatch(i,j);
// If the patch is underwater, calculate a bounding box that also contains the water plane
@ -357,9 +357,9 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
}
// draw the patches
for (uint j=0; j<patchesPerSide; j++)
for (ssize_t j=0; j<patchesPerSide; j++)
{
for (uint i=0; i<patchesPerSide; i++)
for (ssize_t i=0; i<patchesPerSide; i++)
{
CPatch* patch=pTerrain->GetPatch(i,j);
if(patch->getDrawState() == true)
@ -378,7 +378,7 @@ void CGameView::EnumerateObjects(const CFrustum& frustum, SceneCollector* c)
CLOSManager* losMgr = world->GetLOSManager();
const std::vector<CUnit*>& units = unitMan.GetUnits();
for (uint i=0;i<units.size();++i)
for (size_t i=0;i<units.size();++i)
{
ogl_WarnIfError();
@ -469,7 +469,7 @@ static void MarkUpdateColorRecursive(CModel* model)
model->SetDirty(RENDERDATA_UPDATE_COLOR);
const std::vector<CModel::Prop>& props = model->GetProps();
for(uint i = 0; i < props.size(); ++i) {
for(size_t i = 0; i < props.size(); ++i) {
MarkUpdateColorRecursive(props[i].m_Model);
}
}
@ -928,14 +928,14 @@ InReaction CGameView::HandleEvent(const SDL_Event_* ev)
}
bool CGameViewImpl::JSI_StartCustomSelection(
JSContext* UNUSED(context), uint UNUSED(argc), jsval* UNUSED(argv))
JSContext* UNUSED(context), size_t UNUSED(argc), jsval* UNUSED(argv))
{
StartCustomSelection();
return true;
}
bool CGameViewImpl::JSI_EndCustomSelection(
JSContext* UNUSED(context), uint UNUSED(argc), jsval* UNUSED(argv))
JSContext* UNUSED(context), size_t UNUSED(argc), jsval* UNUSED(argv))
{
ResetInteraction();
return true;

View File

@ -39,7 +39,7 @@ private:
// the heightfield were tracing
const u16* m_Heightfield;
// size of the heightfield
u32 m_MapSize;
size_t m_MapSize;
// cell size - size of each cell in x and z
float m_CellSize;
// vertical scale - size of each cell in y

View File

@ -113,16 +113,13 @@ void CMapReader::UnpackLightEnv()
void CMapReader::UnpackObjects()
{
// unpack object types
u32 numObjTypes;
unpacker.UnpackRaw(&numObjTypes, sizeof(numObjTypes));
const size_t numObjTypes = unpacker.UnpackSize();
m_ObjectTypes.resize(numObjTypes);
for (u32 i=0; i<numObjTypes; i++) {
for (size_t i=0; i<numObjTypes; i++)
unpacker.UnpackString(m_ObjectTypes[i]);
}
// unpack object data
u32 numObjects;
unpacker.UnpackRaw(&numObjects, sizeof(numObjects));
const size_t numObjects = unpacker.UnpackSize();
m_Objects.resize(numObjects);
if (numObjects)
unpacker.UnpackRaw(&m_Objects[0], sizeof(SObjectDesc)*numObjects);
@ -140,16 +137,15 @@ int CMapReader::UnpackTerrain()
// i.e. when the loop below was interrupted)
if (cur_terrain_tex == 0)
{
// unpack map size
unpacker.UnpackRaw(&m_MapSize, sizeof(m_MapSize));
m_MapSize = (ssize_t)unpacker.UnpackSize();
// unpack heightmap [600us]
u32 verticesPerSide = m_MapSize*PATCH_SIZE+1;
size_t verticesPerSide = m_MapSize*PATCH_SIZE+1;
m_Heightmap.resize(SQR(verticesPerSide));
unpacker.UnpackRaw(&m_Heightmap[0], SQR(verticesPerSide)*sizeof(u16));
// unpack # textures
unpacker.UnpackRaw(&num_terrain_tex, sizeof(num_terrain_tex));
num_terrain_tex = unpacker.UnpackSize();
m_TerrainTextures.reserve(num_terrain_tex);
}
@ -174,9 +170,9 @@ int CMapReader::UnpackTerrain()
}
// unpack tile data [3ms]
u32 tilesPerSide = m_MapSize*PATCH_SIZE;
size_t tilesPerSide = m_MapSize*PATCH_SIZE;
m_Tiles.resize(SQR(tilesPerSide));
unpacker.UnpackRaw(&m_Tiles[0], (u32)(sizeof(STileDesc)*m_Tiles.size()));
unpacker.UnpackRaw(&m_Tiles[0], sizeof(STileDesc)*m_Tiles.size());
// reset generator state.
cur_terrain_tex = 0;
@ -192,10 +188,10 @@ int CMapReader::ApplyData()
// setup the textures on the minipatches
STileDesc* tileptr = &m_Tiles[0];
for (u32 j=0; j<m_MapSize; j++) {
for (u32 i=0; i<m_MapSize; i++) {
for (u32 m=0; m<(u32)PATCH_SIZE; m++) {
for (u32 k=0; k<(u32)PATCH_SIZE; k++) {
for (ssize_t j=0; j<m_MapSize; j++) {
for (ssize_t i=0; i<m_MapSize; i++) {
for (ssize_t m=0; m<PATCH_SIZE; m++) {
for (ssize_t k=0; k<PATCH_SIZE; k++) {
CMiniPatch& mp = pTerrain->GetPatch(i,j)->m_MiniPatches[m][k];
mp.Tex1 = m_TerrainTextures[tileptr->m_Tex1Index];

View File

@ -54,7 +54,7 @@ private:
int DelayLoadFinished();
// size of map
u32 m_MapSize;
ssize_t m_MapSize;
// heightmap for map
std::vector<u16> m_Heightmap;
// list of terrain textures used by map
@ -81,8 +81,8 @@ private:
CStr filename_xml;
// UnpackTerrain generator state
u32 cur_terrain_tex;
u32 num_terrain_tex;
size_t cur_terrain_tex;
size_t num_terrain_tex;
CXMLReader* xml_reader;
};

View File

@ -59,8 +59,8 @@ void CMapWriter::SaveMap(const char* filename, CTerrain* pTerrain,
// handle isn't in list
static u16 GetHandleIndex(const Handle handle, const std::vector<Handle>& handles)
{
const uint limit = std::min((uint)handles.size(), 0xFFFEu); // paranoia
for (uint i=0;i<limit;i++) {
const size_t limit = std::min(handles.size(), size_t(0xFFFEu)); // paranoia
for (size_t i=0;i<limit;i++) {
if (handles[i]==handle) {
return (u16)i;
}
@ -84,9 +84,9 @@ void CMapWriter::EnumTerrainTextures(CTerrain *pTerrain,
STileDesc* tileptr=&tiles[0];
// now iterate through all the tiles
u32 mapsize=pTerrain->GetPatchesPerSide();
for (u32 j=0;j<mapsize;j++) {
for (u32 i=0;i<mapsize;i++) {
ssize_t mapsize=pTerrain->GetPatchesPerSide();
for (ssize_t j=0;j<mapsize;j++) {
for (ssize_t i=0;i<mapsize;i++) {
for (u32 m=0;m<(u32)PATCH_SIZE;m++) {
for (u32 k=0;k<(u32)PATCH_SIZE;k++) {
CMiniPatch& mp=pTerrain->GetPatch(i,j)->m_MiniPatches[m][k];
@ -106,7 +106,7 @@ void CMapWriter::EnumTerrainTextures(CTerrain *pTerrain,
}
// now find the texture names for each handle
for (uint i=0;i<(uint)handles.size();i++) {
for (size_t i=0;i<handles.size();i++) {
CStr texturename;
CTextureEntry* texentry=g_TexMan.FindTexture(handles[i]);
if (!texentry) {
@ -133,8 +133,8 @@ void CMapWriter::PackMap(CFilePacker& packer, CTerrain* pTerrain)
void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain* pTerrain)
{
// pack map size
u32 mapsize=pTerrain->GetPatchesPerSide();
packer.PackRaw(&mapsize,sizeof(mapsize));
const ssize_t mapsize = pTerrain->GetPatchesPerSide();
packer.PackSize(mapsize);
// pack heightmap
packer.PackRaw(pTerrain->GetHeightMap(),sizeof(u16)*SQR(pTerrain->GetVerticesPerSide()));
@ -148,14 +148,13 @@ void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain* pTerrain)
EnumTerrainTextures(pTerrain, terrainTextures, tiles);
// pack texture names
u32 numTextures=(u32)terrainTextures.size();
packer.PackRaw(&numTextures,sizeof(numTextures));
for (uint i=0;i<numTextures;i++) {
const size_t numTextures = terrainTextures.size();
packer.PackSize(numTextures);
for (size_t i=0;i<numTextures;i++)
packer.PackString(terrainTextures[i]);
}
// pack tile data
packer.PackRaw(&tiles[0],(u32)(sizeof(STileDesc)*tiles.size()));
packer.PackRaw(&tiles[0],sizeof(STileDesc)*tiles.size());
}
void CMapWriter::WriteXML(const char* filename,
CUnitManager* pUnitMan, WaterManager* pWaterMan, SkyManager* pSkyMan,
@ -350,7 +349,7 @@ void CMapWriter::WriteXML(const char* filename,
XML_Attribute("switch", data->m_Switch);
}
for ( int j=(int)nodes.size()-1; j >= 0; --j )
for ( size_t j=nodes.size()-1; j >= 0; --j )
{
XML_Element("Node");

View File

@ -34,7 +34,7 @@ CMaterial::CMaterial()
m_Emissive(IdentityEmissive),
m_SpecularPower(0.0f),
m_Alpha(false),
m_PlayerID(PLAYER_NONE),
m_PlayerID(PLAYER_ID_NONE),
m_TextureColor(BrokenColor)
{
ComputeHash();
@ -115,13 +115,13 @@ SMaterialColor CMaterial::GetEmissive()
SMaterialColor CMaterial::GetPlayerColor()
{
debug_assert(m_PlayerID != PLAYER_NONE);
debug_assert(m_PlayerID != PLAYER_ID_NONE);
// because this should never be called unless IsPlayer returned true
if (m_PlayerID == PLAYER_OTHER /* TODO: or if player-colour is globally disabled */ )
if (m_PlayerID == PLAYER_ID_OTHER /* TODO: or if player-colour is globally disabled */ )
return m_TextureColor;
if (m_PlayerID >= 0)
if (m_PlayerID <= PLAYER_ID_LAST_VALID)
{
CPlayer* player = g_Game->GetPlayer(m_PlayerID);
if (player)
@ -135,9 +135,9 @@ SMaterialColor CMaterial::GetPlayerColor()
return BrokenColor;
}
void CMaterial::SetPlayerColor(int id)
void CMaterial::SetPlayerColor(size_t id)
{
if (m_PlayerID == PLAYER_COMINGSOON || m_PlayerID >= 0)
if (m_PlayerID == PLAYER_ID_COMING_SOON || m_PlayerID <= PLAYER_ID_LAST_VALID)
m_PlayerID = id;
}

View File

@ -67,15 +67,15 @@ public:
bool UsesAlpha() { return m_Alpha; }
// Determines whether or not the model goes into the PlayerRenderer
bool IsPlayer() { return (m_PlayerID != PLAYER_NONE); }
bool IsPlayer() { return (m_PlayerID != PLAYER_ID_NONE); }
// Get the player colour (in a non-zero amount of time, so don't call it
// an unreasonable number of times. But it's fairly close to zero, so
// don't worry too much about it.)
SMaterialColor GetPlayerColor();
void SetPlayerColor_PerPlayer() { m_PlayerID = PLAYER_COMINGSOON; }
void SetPlayerColor_PerObject() { m_PlayerID = PLAYER_OTHER; }
void SetPlayerColor(int id);
void SetPlayerColor_PerPlayer() { m_PlayerID = PLAYER_ID_COMING_SOON; }
void SetPlayerColor_PerObject() { m_PlayerID = PLAYER_ID_OTHER; }
void SetPlayerColor(size_t id);
void SetPlayerColor(CColor &colour);
void SetTexture(const CStr& texture);
@ -113,16 +113,20 @@ protected:
bool m_Alpha;
// Player-colour settings.
// If m_PlayerID >= 0, the colour is retrieved from g_Game whenever it's needed.
// If m_PlayerID <= PLAYER_ID_LAST_VALID, the colour is retrieved from
// g_Game whenever it's needed.
// (It's not cached, because the player might change colour.)
// If m_PlayerID == PLAYER_OTHER, or if player-colouring has been globally
// If m_PlayerID == PLAYER_ID_OTHER, or if player-colouring has been globally
// disabled, m_TextureColor is used instead. This allows per-model colours to
// be specified, instead of only a single colour per player.
// If m_PlayerID == PLAYER_NONE, there's no player colour at all.
// If m_PlayerID == PLAYER_COMINGSOON, it's going to be linked to a player,
// If m_PlayerID == PLAYER_ID_NONE, there's no player colour at all.
// If m_PlayerID == PLAYER_ID_COMING_SOON, it's going to be linked to a player,
// but hasn't yet.
enum { PLAYER_NONE = -1, PLAYER_OTHER = -2, PLAYER_COMINGSOON = -3 };
int m_PlayerID;
static const size_t PLAYER_ID_NONE = SIZE_MAX-1;
static const size_t PLAYER_ID_OTHER = SIZE_MAX-2;
static const size_t PLAYER_ID_COMING_SOON = SIZE_MAX-3;
static const size_t PLAYER_ID_LAST_VALID = SIZE_MAX-4;
size_t m_PlayerID;
SMaterialColor m_TextureColor; // used as an alternative to the per-player colour
};

View File

@ -28,12 +28,10 @@ CMiniPatch::~CMiniPatch()
///////////////////////////////////////////////////////////////////////////////
// GetTileIndex: get the index of this tile in the root terrain object;
// on return, parameters x,y contain index in [0,MapSize)
void CMiniPatch::GetTileIndex(u32& x,u32& z)
void CMiniPatch::GetTileIndex(ssize_t& x,ssize_t& z)
{
const ptrdiff_t tindex = this - &m_Parent->m_MiniPatches[0][0];
x=(m_Parent->m_X*PATCH_SIZE)+tindex%PATCH_SIZE;
z=(m_Parent->m_Z*PATCH_SIZE)+tindex/PATCH_SIZE;
}

View File

@ -24,7 +24,7 @@ public:
~CMiniPatch();
// get the index of this tile in the root terrain object; x,y in [0,MapSize)
void GetTileIndex(u32& x,u32& z);
void GetTileIndex(ssize_t& x,ssize_t& z);
public:
// texture applied to tile

View File

@ -295,7 +295,7 @@ void CModel::InvalidatePosition()
{
m_PositionValid = false;
for (uint i = 0; i < m_Props.size(); ++i)
for (size_t i = 0; i < m_Props.size(); ++i)
m_Props[i].m_Model->InvalidatePosition();
}
@ -430,8 +430,7 @@ void CModel::AddProp(SPropPoint* point, CModel* model, CObjectEntry* objectentry
// check if we're already using this point, and remove it if so
// (when a prop is removed it will also remove the prop point)
uint i;
for (i = 0; i < m_Props.size(); i++) {
for (size_t i = 0; i < m_Props.size(); i++) {
if (m_Props[i].m_Point == point) {
delete m_Props[i].m_Model;
break;
@ -450,8 +449,7 @@ void CModel::AddProp(SPropPoint* point, CModel* model, CObjectEntry* objectentry
// RemoveProp: remove a prop from the given point
void CModel::RemoveProp(SPropPoint* point)
{
uint i;
for (i=0;i<m_Props.size();i++) {
for (size_t i=0;i<m_Props.size();i++) {
if (m_Props[i].m_Point==point) {
delete m_Props[i].m_Model;
// (when a prop is removed it will automatically remove its prop point)
@ -473,7 +471,7 @@ CModel* CModel::Clone() const
clone->SetMaterial(m_Material);
clone->SetAnimation(m_Anim);
clone->SetFlags(m_Flags);
for (uint i=0;i<m_Props.size();i++) {
for (size_t i=0;i<m_Props.size();i++) {
// eek! TODO, RC - need to investigate shallow clone here
clone->AddProp(m_Props[i].m_Point, m_Props[i].m_Model->Clone(), m_Props[i].m_ObjectEntry);
}
@ -502,7 +500,7 @@ void CModel::SetMaterial(const CMaterial &material)
}
}
void CModel::SetPlayerID(int id)
void CModel::SetPlayerID(size_t id)
{
m_Material.SetPlayerColor(id);
for (std::vector<Prop>::iterator it = m_Props.begin(); it != m_Props.end(); ++it)

View File

@ -68,7 +68,7 @@ public:
void SetMaterial(const CMaterial &material);
// set the model's player ID, recursively through props. CUnit::SetPlayerID
// should normally be used instead.
void SetPlayerID(int id);
void SetPlayerID(size_t id);
// set the model's player colour
void SetPlayerColor(CColor& colour);
// set the models mod color
@ -91,12 +91,12 @@ public:
void CopyAnimationFrom(CModel* source);
// set object flags
void SetFlags(u32 flags) { m_Flags=flags; }
void SetFlags(int flags) { m_Flags=flags; }
// get object flags
u32 GetFlags() const { return m_Flags; }
int GetFlags() const { return m_Flags; }
// recurse down tree setting dirty bits
void SetDirtyRec(u32 dirtyflags) {
void SetDirtyRec(int dirtyflags) {
SetDirty(dirtyflags);
for (size_t i=0;i<m_Props.size();i++) {
m_Props[i].m_Model->SetDirtyRec(dirtyflags);
@ -169,7 +169,7 @@ private:
CModel* m_Parent;
// object flags
u32 m_Flags;
int m_Flags;
// texture used by model
CTexture m_Texture;
// model's material

View File

@ -98,7 +98,7 @@ CModelDef::~CModelDef()
// return null if no match (case insensitive search)
SPropPoint* CModelDef::FindPropPoint(const char* name) const
{
for (u32 i = 0; i < m_NumPropPoints; ++i)
for (size_t i = 0; i < m_NumPropPoints; ++i)
if (m_PropPoints[i].m_Name == name)
return &m_PropPoints[i];
@ -122,15 +122,15 @@ CModelDef* CModelDef::Load(const VfsPath& filename, const char* name)
mdef->m_Name = name;
// now unpack everything
unpacker.UnpackRaw(&mdef->m_NumVertices,sizeof(mdef->m_NumVertices));
mdef->m_NumVertices = unpacker.UnpackSize();
mdef->m_pVertices=new SModelVertex[mdef->m_NumVertices];
unpacker.UnpackRaw(mdef->m_pVertices,sizeof(SModelVertex)*mdef->m_NumVertices);
unpacker.UnpackRaw(&mdef->m_NumFaces,sizeof(mdef->m_NumFaces));
mdef->m_NumFaces = unpacker.UnpackSize();
mdef->m_pFaces=new SModelFace[mdef->m_NumFaces];
unpacker.UnpackRaw(mdef->m_pFaces,sizeof(SModelFace)*mdef->m_NumFaces);
unpacker.UnpackRaw(&mdef->m_NumBones,sizeof(mdef->m_NumBones));
mdef->m_NumBones = unpacker.UnpackSize();
if (mdef->m_NumBones)
{
mdef->m_Bones=new CBoneState[mdef->m_NumBones];
@ -140,10 +140,10 @@ CModelDef* CModelDef::Load(const VfsPath& filename, const char* name)
if (unpacker.GetVersion() >= 2)
{
// versions >=2 also have prop point data
unpacker.UnpackRaw(&mdef->m_NumPropPoints,sizeof(mdef->m_NumPropPoints));
mdef->m_NumPropPoints = unpacker.UnpackSize();
if (mdef->m_NumPropPoints) {
mdef->m_PropPoints=new SPropPoint[mdef->m_NumPropPoints];
for (u32 i=0;i<mdef->m_NumPropPoints;i++) {
for (size_t i=0;i<mdef->m_NumPropPoints;i++) {
unpacker.UnpackString(mdef->m_PropPoints[i].m_Name);
unpacker.UnpackRaw(&mdef->m_PropPoints[i].m_Position.X,sizeof(mdef->m_PropPoints[i].m_Position));
unpacker.UnpackRaw(&mdef->m_PropPoints[i].m_Rotation.m_V.X,sizeof(mdef->m_PropPoints[i].m_Rotation));
@ -172,14 +172,14 @@ CModelDef* CModelDef::Load(const VfsPath& filename, const char* name)
std::vector<CMatrix3D> bindPose (mdef->m_NumBones);
for (u32 i = 0; i < mdef->m_NumBones; ++i)
for (size_t i = 0; i < mdef->m_NumBones; ++i)
{
bindPose[i].SetIdentity();
bindPose[i].Rotate(mdef->m_Bones[i].m_Rotation);
bindPose[i].Translate(mdef->m_Bones[i].m_Translation);
}
for (u32 i = 0; i < mdef->m_NumVertices; ++i)
for (size_t i = 0; i < mdef->m_NumVertices; ++i)
{
mdef->m_pVertices[i].m_Coords = SkinPoint(mdef->m_pVertices[i], &bindPose[0], &identityBones[0]);
mdef->m_pVertices[i].m_Norm = SkinNormal(mdef->m_pVertices[i], &bindPose[0], &identityBones[0]);
@ -196,21 +196,22 @@ void CModelDef::Save(const VfsPath& filename,const CModelDef* mdef)
CFilePacker packer(FILE_VERSION, "PSMD");
// pack everything up
u32 numVertices=(u32)mdef->GetNumVertices();
packer.PackRaw(&numVertices,sizeof(numVertices));
const size_t numVertices = mdef->GetNumVertices();
packer.PackSize(numVertices);
packer.PackRaw(mdef->GetVertices(),sizeof(SModelVertex)*numVertices);
u32 numFaces=(u32)mdef->GetNumFaces();
packer.PackRaw(&numFaces,sizeof(numFaces));
const size_t numFaces = mdef->GetNumFaces();
packer.PackSize(numFaces);
packer.PackRaw(mdef->GetFaces(),sizeof(SModelFace)*numFaces);
packer.PackRaw(&mdef->m_NumBones,sizeof(mdef->m_NumBones));
if (mdef->m_NumBones) {
packer.PackRaw(mdef->m_Bones,sizeof(CBoneState)*mdef->m_NumBones);
}
const size_t numBones = mdef->m_NumBones;
packer.PackSize(numBones);
if (numBones)
packer.PackRaw(mdef->m_Bones,sizeof(CBoneState)*numBones);
packer.PackRaw(&mdef->m_NumPropPoints,sizeof(mdef->m_NumPropPoints));
for (u32 i=0;i<mdef->m_NumPropPoints;i++) {
const size_t numPropPoints = mdef->m_NumPropPoints;
packer.PackSize(numPropPoints);
for (size_t i=0;i<mdef->m_NumPropPoints;i++) {
packer.PackString(mdef->m_PropPoints[i].m_Name);
packer.PackRaw(&mdef->m_PropPoints[i].m_Position.X,sizeof(mdef->m_PropPoints[i].m_Position));
packer.PackRaw(&mdef->m_PropPoints[i].m_Rotation.m_V.X,sizeof(mdef->m_PropPoints[i].m_Rotation));

View File

@ -122,7 +122,7 @@ public:
CBoneState* GetBones() const { return m_Bones; }
// accessor: get prop data
int GetNumPropPoints() const { return m_NumPropPoints; }
size_t GetNumPropPoints() const { return m_NumPropPoints; }
SPropPoint* GetPropPoints() const { return m_PropPoints; }
// find and return pointer to prop point matching given name; return
@ -169,16 +169,16 @@ public:
public:
// vertex data
u32 m_NumVertices;
size_t m_NumVertices;
SModelVertex* m_pVertices;
// face data
u32 m_NumFaces;
size_t m_NumFaces;
SModelFace* m_pFaces;
// bone data - default model pose
u32 m_NumBones;
size_t m_NumBones;
CBoneState* m_Bones;
// prop point data
u32 m_NumPropPoints;
size_t m_NumPropPoints;
SPropPoint* m_PropPoints;
private:

View File

@ -440,7 +440,7 @@ std::set<CStr> CObjectBase::CalculateRandomVariation(const std::set<CStr>& initi
// Choose a random number in the interval [0..totalFreq).
// (It shouldn't be necessary to use a network-synchronised RNG,
// since actors are meant to have purely visual manifestations.)
int randNum = rand(0, totalFreq);
int randNum = (int)rand(0, (size_t)totalFreq);
// and use that to choose one of the variants
for (size_t i = 0; i < grp->size(); ++i)

View File

@ -229,7 +229,7 @@ CSkeletonAnim* CObjectEntry::GetRandomAnimation(const CStr& animationName)
else
{
// TODO: Do we care about network synchronisation of random animations?
int id = rand(0, (int)count);
size_t id = rand(0, count);
std::advance(lower, id);
return lower->second;
}

View File

@ -35,7 +35,7 @@ public:
short life; // How long it will last 2
// particle text stuff
CVector3D endPos; // For particle texture 12
CVector3D endPos; // For particle texture 12
bool inPos; // 1
tParticle* next; // pointer for link lists 4

View File

@ -66,7 +66,7 @@ bool CParticleEngine::InitParticleSystem()
CTexture pTex;
pTex.SetName("art/textures/particles/sprite.tga");
u32 flags = 0;
int flags = 0;
if(!(g_Renderer.LoadTexture(&pTex, flags)))
return false;

View File

@ -28,7 +28,7 @@ CPatch::~CPatch()
///////////////////////////////////////////////////////////////////////////////
// Initialize: setup patch data
void CPatch::Initialize(CTerrain* parent,u32 x,u32 z)
void CPatch::Initialize(CTerrain* parent,ssize_t x,ssize_t z)
{
delete m_RenderData;
m_RenderData=0;
@ -38,9 +38,9 @@ void CPatch::Initialize(CTerrain* parent,u32 x,u32 z)
m_Z=z;
// set parent of each patch
for (int j=0;j<PATCH_SIZE;j++)
for (size_t j=0;j<PATCH_SIZE;j++)
{
for (int i=0;i<PATCH_SIZE;i++)
for (size_t i=0;i<PATCH_SIZE;i++)
{
m_MiniPatches[j][i].m_Parent=this;
}
@ -55,9 +55,9 @@ void CPatch::CalcBounds()
{
m_Bounds.SetEmpty();
for (int j=0;j<PATCH_SIZE+1;j++)
for (ssize_t j=0;j<PATCH_SIZE+1;j++)
{
for (int i=0;i<PATCH_SIZE+1;i++)
for (ssize_t i=0;i<PATCH_SIZE+1;i++)
{
CVector3D pos;
m_Parent->CalcPosition(m_X*PATCH_SIZE+i,m_Z*PATCH_SIZE+j,pos);

View File

@ -18,7 +18,7 @@ class CTerrain;
// Terrain Constants:
//
// PATCH_SIZE: number of tiles in each patch
const int PATCH_SIZE = 16;
const ssize_t PATCH_SIZE = 16;
/// neighbor IDs for CPatch
enum CPatchNeighbors
@ -44,7 +44,7 @@ public:
~CPatch();
// initialize the patch
void Initialize(CTerrain* parent,u32 x,u32 z);
void Initialize(CTerrain* parent,ssize_t x,ssize_t z);
// calculate and store bounds of this patch
void CalcBounds();
@ -55,7 +55,7 @@ public:
// minipatches (tiles) making up the patch
CMiniPatch m_MiniPatches[PATCH_SIZE][PATCH_SIZE];
// position of patch in parent terrain grid
u32 m_X,m_Z;
int m_X,m_Z;
// parent terrain
CTerrain* m_Parent;

View File

@ -31,7 +31,7 @@ public:
CRenderData() : m_UpdateFlags(0) {}
virtual ~CRenderData() {}
u32 m_UpdateFlags;
int m_UpdateFlags;
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -32,12 +32,12 @@ CSkeletonAnimDef::~CSkeletonAnimDef()
void CSkeletonAnimDef::BuildBoneMatrices(float time, CMatrix3D* matrices, bool loop) const
{
float fstartframe = time/m_FrameTime;
u32 startframe = u32(time/m_FrameTime);
size_t startframe = (size_t)(int)(time/m_FrameTime);
float deltatime = fstartframe-startframe;
startframe %= m_NumFrames;
u32 endframe = startframe + 1;
size_t endframe = startframe + 1;
endframe %= m_NumFrames;
if (!loop && endframe == 0)
@ -46,7 +46,7 @@ void CSkeletonAnimDef::BuildBoneMatrices(float time, CMatrix3D* matrices, bool l
// between the final frame and the initial frame is wrong, because they're
// totally different. So if we've looped around to endframe==0, just display
// the animation's final frame with no interpolation.
for (u32 i = 0; i < m_NumKeys; i++)
for (size_t i = 0; i < m_NumKeys; i++)
{
const Key& key = GetKey(startframe, i);
matrices[i].SetIdentity();
@ -56,7 +56,7 @@ void CSkeletonAnimDef::BuildBoneMatrices(float time, CMatrix3D* matrices, bool l
}
else
{
for (u32 i = 0; i < m_NumKeys; i++)
for (size_t i = 0; i < m_NumKeys; i++)
{
const Key& startkey = GetKey(startframe, i);
const Key& endkey = GetKey(endframe, i);
@ -90,8 +90,8 @@ CSkeletonAnimDef* CSkeletonAnimDef::Load(const VfsPath& filename)
CStr name; // unused - just here to maintain compatibility with the animation files
unpacker.UnpackString(name);
unpacker.UnpackRaw(&anim->m_FrameTime,sizeof(anim->m_FrameTime));
unpacker.UnpackRaw(&anim->m_NumKeys,sizeof(anim->m_NumKeys));
unpacker.UnpackRaw(&anim->m_NumFrames,sizeof(anim->m_NumFrames));
anim->m_NumKeys = unpacker.UnpackSize();
anim->m_NumFrames = unpacker.UnpackSize();
anim->m_Keys=new Key[anim->m_NumKeys*anim->m_NumFrames];
unpacker.UnpackRaw(anim->m_Keys,anim->m_NumKeys*anim->m_NumFrames*sizeof(Key));
} catch (PSERROR_File&) {
@ -111,12 +111,12 @@ void CSkeletonAnimDef::Save(const char* filename,const CSkeletonAnimDef* anim)
// pack up all the data
packer.PackString("");
packer.PackRaw(&anim->m_FrameTime,sizeof(anim->m_FrameTime));
packer.PackRaw(&anim->m_NumKeys,sizeof(anim->m_NumKeys));
packer.PackRaw(&anim->m_NumFrames,sizeof(anim->m_NumFrames));
packer.PackRaw(anim->m_Keys,anim->m_NumKeys*anim->m_NumFrames*sizeof(Key));
const size_t numKeys = anim->m_NumKeys;
packer.PackSize(numKeys);
const size_t numFrames = anim->m_NumFrames;
packer.PackSize(numFrames);
packer.PackRaw(anim->m_Keys,numKeys*numFrames*sizeof(Key));
// now write it
packer.Write(filename);
}

View File

@ -50,8 +50,8 @@ public:
size_t GetNumKeys() const { return (size_t)m_NumKeys; }
// accessors: get a key for given bone at given time
Key& GetKey(u32 frame, u32 bone) { return m_Keys[frame*m_NumKeys+bone]; }
const Key& GetKey(u32 frame, u32 bone) const { return m_Keys[frame*m_NumKeys+bone]; }
Key& GetKey(size_t frame, size_t bone) { return m_Keys[frame*m_NumKeys+bone]; }
const Key& GetKey(size_t frame, size_t bone) const { return m_Keys[frame*m_NumKeys+bone]; }
// get duration of this anim, in ms
float GetDuration() const { return m_NumFrames*m_FrameTime; }
@ -72,9 +72,9 @@ public:
// frame time - time between successive frames, in ms
float m_FrameTime;
// number of keys in each frame - should match number of bones in the skeleton
u32 m_NumKeys;
size_t m_NumKeys;
// number of frames in the animation
u32 m_NumFrames;
size_t m_NumFrames;
// animation data - m_NumKeys*m_NumFrames total keys
Key* m_Keys;
};

View File

@ -52,13 +52,13 @@ void CTerrain::ReleaseData()
///////////////////////////////////////////////////////////////////////////////
// Initialise: initialise this terrain to the given size (in patches per side);
// using given heightmap to setup elevation data
bool CTerrain::Initialize(u32 size,const u16* data)
bool CTerrain::Initialize(ssize_t size,const u16* data)
{
// clean up any previous terrain
ReleaseData();
// store terrain size
m_MapSize=(size*PATCH_SIZE)+1;
m_MapSize=size*PATCH_SIZE+1;
m_MapSizePatches=size;
// allocate data for new terrain
m_Heightmap=new u16[m_MapSize*m_MapSize];
@ -106,10 +106,10 @@ bool CTerrain::IsPassable(const CVector2D &loc/*tile space*/, HEntity entity) co
///////////////////////////////////////////////////////////////////////////////
// CalcPosition: calculate the world space position of the vertex at (i,j)
void CTerrain::CalcPosition(i32 i, i32 j, CVector3D& pos) const
void CTerrain::CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const
{
u16 height;
if ((u32)i < m_MapSize && (u32)j < m_MapSize) // will reject negative coordinates
if ((size_t)i < (size_t)m_MapSize && (size_t)j < (size_t)m_MapSize) // will reject negative coordinates
height = m_Heightmap[j*m_MapSize + i];
else
height = 0;
@ -121,7 +121,7 @@ void CTerrain::CalcPosition(i32 i, i32 j, CVector3D& pos) const
///////////////////////////////////////////////////////////////////////////////
// CalcNormal: calculate the world space normal of the vertex at (i,j)
void CTerrain::CalcNormal(u32 i, u32 j, CVector3D& normal) const
void CTerrain::CalcNormal(ssize_t i, ssize_t j, CVector3D& normal) const
{
CVector3D left, right, up, down;
@ -169,10 +169,10 @@ void CTerrain::CalcNormal(u32 i, u32 j, CVector3D& normal) const
///////////////////////////////////////////////////////////////////////////////
// GetPatch: return the patch at (i,j) in patch space, or null if the patch is
// out of bounds
CPatch* CTerrain::GetPatch(i32 i, i32 j) const
CPatch* CTerrain::GetPatch(ssize_t i, ssize_t j) const
{
// range check: >= 0 and < m_MapSizePatches
if( (unsigned)i >= m_MapSizePatches || (unsigned)j >= m_MapSizePatches )
if( (size_t)i >= (size_t)m_MapSizePatches || (size_t)j >= (size_t)m_MapSizePatches )
return 0;
return &m_Patches[(j*m_MapSizePatches)+i];
@ -182,26 +182,26 @@ CPatch* CTerrain::GetPatch(i32 i, i32 j) const
///////////////////////////////////////////////////////////////////////////////
// GetPatch: return the tile at (i,j) in tile space, or null if the tile is out
// of bounds
CMiniPatch* CTerrain::GetTile(i32 i, i32 j) const
CMiniPatch* CTerrain::GetTile(ssize_t i, ssize_t j) const
{
// see above
if( (unsigned)i >= m_MapSize-1 || (unsigned)j >= m_MapSize-1 )
if( (size_t)i >= (size_t)(m_MapSize-1) || (size_t)j >= (size_t)(m_MapSize-1) )
return 0;
CPatch* patch=GetPatch(i/PATCH_SIZE, j/PATCH_SIZE);
return &patch->m_MiniPatches[j%PATCH_SIZE][i%PATCH_SIZE];
}
float CTerrain::GetVertexGroundLevel(int i, int j) const
float CTerrain::GetVertexGroundLevel(ssize_t i, ssize_t j) const
{
if (i < 0)
i = 0;
else if (i >= (int) m_MapSize)
else if ((size_t)i >= (size_t)m_MapSize)
i = m_MapSize - 1;
if (j < 0)
j = 0;
else if (j >= (int) m_MapSize)
else if ((size_t)j >= (size_t)m_MapSize)
j = m_MapSize - 1;
return HEIGHT_SCALE * m_Heightmap[j*m_MapSize + i];
@ -287,7 +287,7 @@ float CTerrain::GetExactGroundLevel(float x, float z) const
///////////////////////////////////////////////////////////////////////////////
// Resize: resize this terrain to the given size (in patches per side)
void CTerrain::Resize(u32 size)
void CTerrain::Resize(ssize_t size)
{
if (size==m_MapSizePatches) {
// inexplicable request to resize terrain to the same size .. ignore it
@ -301,7 +301,7 @@ void CTerrain::Resize(u32 size)
}
// allocate data for new terrain
u32 newMapSize=(size*PATCH_SIZE)+1;
ssize_t newMapSize=size*PATCH_SIZE+1;
u16* newHeightmap=new u16[newMapSize*newMapSize];
CPatch* newPatches=new CPatch[size*size];
@ -312,17 +312,16 @@ void CTerrain::Resize(u32 size)
}
// now copy over rows of data
u32 j;
u16* src=m_Heightmap;
u16* dst=newHeightmap;
u32 copysize=newMapSize>m_MapSize ? m_MapSize : newMapSize;
for (j=0;j<copysize;j++) {
ssize_t copysize=newMapSize>m_MapSize ? m_MapSize : newMapSize;
for (ssize_t j=0;j<copysize;j++) {
cpu_memcpy(dst,src,copysize*sizeof(u16));
dst+=copysize;
src+=m_MapSize;
if (newMapSize>m_MapSize) {
// entend the last height to the end of the row
for (u32 i=0;i<newMapSize-m_MapSize;i++) {
for (size_t i=0;i<newMapSize-(size_t)m_MapSize;i++) {
*dst++=*(src-1);
}
}
@ -333,15 +332,15 @@ void CTerrain::Resize(u32 size)
// copy over heights of the last row to any remaining rows
src=newHeightmap+((m_MapSize-1)*newMapSize);
dst=src+newMapSize;
for (u32 i=0;i<newMapSize-m_MapSize;i++) {
for (ssize_t i=0;i<newMapSize-m_MapSize;i++) {
cpu_memcpy(dst,src,newMapSize*sizeof(u16));
dst+=newMapSize;
}
}
// now build new patches
for (j=0;j<size;j++) {
for (u32 i=0;i<size;i++) {
for (ssize_t j=0;j<size;j++) {
for (ssize_t i=0;i<size;i++) {
// copy over texture data from existing tiles, if possible
if (i<m_MapSizePatches && j<m_MapSizePatches) {
cpu_memcpy(newPatches[j*size+i].m_MiniPatches,m_Patches[j*m_MapSizePatches+i].m_MiniPatches,sizeof(CMiniPatch)*PATCH_SIZE*PATCH_SIZE);
@ -350,10 +349,10 @@ void CTerrain::Resize(u32 size)
if (j<m_MapSizePatches && size>m_MapSizePatches) {
// copy over the last tile from each column
for (u32 n=0;n<size-m_MapSizePatches;n++) {
for (int m=0;m<PATCH_SIZE;m++) {
for (ssize_t n=0;n<size-m_MapSizePatches;n++) {
for (ssize_t m=0;m<PATCH_SIZE;m++) {
CMiniPatch& src=m_Patches[j*m_MapSizePatches+m_MapSizePatches-1].m_MiniPatches[m][15];
for (int k=0;k<PATCH_SIZE;k++) {
for (size_t k=0;k<PATCH_SIZE;k++) {
CMiniPatch& dst=newPatches[j*size+m_MapSizePatches+n].m_MiniPatches[m][k];
dst.Tex1=src.Tex1;
dst.Tex1Priority=src.Tex1Priority;
@ -367,10 +366,10 @@ void CTerrain::Resize(u32 size)
// copy over the last tile from each column
CPatch* srcpatch=&newPatches[(m_MapSizePatches-1)*size];
CPatch* dstpatch=srcpatch+size;
for (u32 p=0;p<size-m_MapSizePatches;p++) {
for (u32 n=0;n<size;n++) {
for (int m=0;m<PATCH_SIZE;m++) {
for (int k=0;k<PATCH_SIZE;k++) {
for (ssize_t p=0;p<(ssize_t)size-m_MapSizePatches;p++) {
for (ssize_t n=0;n<(ssize_t)size;n++) {
for (ssize_t m=0;m<PATCH_SIZE;m++) {
for (ssize_t k=0;k<PATCH_SIZE;k++) {
CMiniPatch& src=srcpatch->m_MiniPatches[15][k];
CMiniPatch& dst=dstpatch->m_MiniPatches[m][k];
dst.Tex1=src.Tex1;
@ -390,8 +389,8 @@ void CTerrain::Resize(u32 size)
// store new data
m_Heightmap=newHeightmap;
m_Patches=newPatches;
m_MapSize=newMapSize;
m_MapSizePatches=size;
m_MapSize=(ssize_t)newMapSize;
m_MapSizePatches=(ssize_t)size;
// initialise all the new patches
InitialisePatches();
@ -401,8 +400,8 @@ void CTerrain::Resize(u32 size)
// InitialisePatches: initialise patch data
void CTerrain::InitialisePatches()
{
for (u32 j=0;j<m_MapSizePatches;j++) {
for (u32 i=0;i<m_MapSizePatches;i++) {
for (ssize_t j=0;j<m_MapSizePatches;j++) {
for (ssize_t i=0;i<m_MapSizePatches;i++) {
CPatch* patch=GetPatch(i,j);
patch->Initialize(this,i,j);
}
@ -418,8 +417,8 @@ void CTerrain::SetHeightMap(u16* heightmap)
cpu_memcpy(m_Heightmap,heightmap,m_MapSize*m_MapSize*sizeof(u16));
// recalculate patch bounds, invalidate vertices
for (u32 j=0;j<m_MapSizePatches;j++) {
for (u32 i=0;i<m_MapSizePatches;i++) {
for (ssize_t j=0;j<m_MapSizePatches;j++) {
for (ssize_t i=0;i<m_MapSizePatches;i++) {
CPatch* patch=GetPatch(i,j);
patch->InvalidateBounds();
patch->SetDirty(RENDERDATA_UPDATE_VERTICES);
@ -433,23 +432,23 @@ void CTerrain::SetHeightMap(u16* heightmap)
// coords); return the average height of the flattened area
float CTerrain::FlattenArea(float x0, float x1, float z0, float z1)
{
u32 tx0=u32(clamp(int(float(x0/CELL_SIZE)), 0, int(m_MapSize)));
u32 tx1=u32(clamp(int(float(x1/CELL_SIZE)+1.0f), 0, int(m_MapSize)));
u32 tz0=u32(clamp(int(float(z0/CELL_SIZE)), 0, int(m_MapSize)));
u32 tz1=u32(clamp(int(float(z1/CELL_SIZE)+1.0f), 0, int(m_MapSize)));
ssize_t tx0=clamp(ssize_t((x0/CELL_SIZE)), ssize_t(0), m_MapSize);
ssize_t tx1=clamp(ssize_t((x1/CELL_SIZE)+1.0f), ssize_t(0), m_MapSize);
ssize_t tz0=clamp(ssize_t((z0/CELL_SIZE)), ssize_t(0), m_MapSize);
ssize_t tz1=clamp(ssize_t((z1/CELL_SIZE)+1.0f), ssize_t(0), m_MapSize);
u32 count=0;
u32 y=0;
for (u32 x=tx0;x<=tx1;x++) {
for (u32 z=tz0;z<=tz1;z++) {
size_t count=0;
size_t y=0;
for (ssize_t x=tx0;x<=tx1;x++) {
for (ssize_t z=tz0;z<=tz1;z++) {
y+=m_Heightmap[z*m_MapSize + x];
count++;
}
}
y/=count;
for (u32 x=tx0;x<=tx1;x++) {
for (u32 z=tz0;z<=tz1;z++) {
for (ssize_t x=tx0;x<=tx1;x++) {
for (ssize_t z=tz0;z<=tz1;z++) {
m_Heightmap[z*m_MapSize + x]=(u16)y;
CPatch* patch=GetPatch(x/PATCH_SIZE,z/PATCH_SIZE);
patch->SetDirty(RENDERDATA_UPDATE_VERTICES);
@ -461,15 +460,15 @@ float CTerrain::FlattenArea(float x0, float x1, float z0, float z1)
///////////////////////////////////////////////////////////////////////////////
void CTerrain::MakeDirty(int i0, int j0, int i1, int j1, int dirtyFlags)
void CTerrain::MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags)
{
// flag vertex data as dirty for affected patches, and rebuild bounds of these patches
int pi0 = clamp((i0/PATCH_SIZE)-1, 0, (int)m_MapSizePatches);
int pi1 = clamp((i1/PATCH_SIZE)+1, 0, (int)m_MapSizePatches);
int pj0 = clamp((j0/PATCH_SIZE)-1, 0, (int)m_MapSizePatches);
int pj1 = clamp((j1/PATCH_SIZE)+1, 0, (int)m_MapSizePatches);
for (int j = pj0; j < pj1; j++) {
for (int i = pi0; i < pi1; i++) {
ssize_t pi0 = clamp((i0/PATCH_SIZE)-1, ssize_t(0), m_MapSizePatches);
ssize_t pi1 = clamp((i1/PATCH_SIZE)+1, ssize_t(0), m_MapSizePatches);
ssize_t pj0 = clamp((j0/PATCH_SIZE)-1, ssize_t(0), m_MapSizePatches);
ssize_t pj1 = clamp((j1/PATCH_SIZE)+1, ssize_t(0), m_MapSizePatches);
for (ssize_t j = pj0; j < pj1; j++) {
for (ssize_t i = pi0; i < pi1; i++) {
CPatch* patch = GetPatch(i,j);
if (dirtyFlags & RENDERDATA_UPDATE_VERTICES)
patch->CalcBounds();
@ -480,8 +479,8 @@ void CTerrain::MakeDirty(int i0, int j0, int i1, int j1, int dirtyFlags)
void CTerrain::MakeDirty(int dirtyFlags)
{
for (u32 j = 0; j < m_MapSizePatches; j++) {
for (u32 i = 0; i < m_MapSizePatches; i++) {
for (ssize_t j = 0; j < m_MapSizePatches; j++) {
for (ssize_t i = 0; i < m_MapSizePatches; i++) {
CPatch* patch = GetPatch(i,j);
if (dirtyFlags & RENDERDATA_UPDATE_VERTICES)
patch->CalcBounds();

View File

@ -24,7 +24,7 @@ class CVector2D;
// Terrain Constants:
//
// CELL_SIZE: size of each tile in x and z
const int CELL_SIZE = 4;
const ssize_t CELL_SIZE = 4;
// HEIGHT_SCALE: vertical scale of terrain - terrain has a coordinate range of
// 0 to 65536*HEIGHT_SCALE
const float HEIGHT_SCALE = 0.35f/256.0f;
@ -39,16 +39,18 @@ public:
~CTerrain();
// Coordinate naming convention: world-space coordinates are float x,z;
// tile-space coordinates are int i,j.
// tile-space coordinates are ssize_t i,j. rationale: signed types can
// more efficiently be converted to/from floating point. use ssize_t
// instead of int/long because these are sizes.
bool Initialize(u32 size, const u16* ptr);
bool Initialize(ssize_t size, const u16* ptr);
// return number of vertices along edge of the terrain
u32 GetVerticesPerSide() const { return m_MapSize; }
ssize_t GetVerticesPerSide() const { return m_MapSize; }
// return number of tiles along edge of the terrain
u32 GetTilesPerSide() const { return GetVerticesPerSide()-1; }
ssize_t GetTilesPerSide() const { return GetVerticesPerSide()-1; }
// return number of patches along edge of the terrain
u32 GetPatchesPerSide() const { return m_MapSizePatches; }
ssize_t GetPatchesPerSide() const { return m_MapSizePatches; }
bool IsOnMap(float x, float z) const
{
@ -68,7 +70,7 @@ public:
index = m_MapSize - 2;
}
float GetVertexGroundLevel(int i, int j) const;
float GetVertexGroundLevel(ssize_t i, ssize_t j) const;
float GetExactGroundLevel(float x, float z) const;
float GetExactGroundLevel(const CVector2D& v) const;
@ -76,7 +78,7 @@ public:
//Find the slope of in X and Z axes depending on the way the entity is facing
CVector2D GetSlopeAngleFace(CEntity* entity) const;
// resize this terrain such that each side has given number of patches
void Resize(u32 size);
void Resize(ssize_t size);
// set up a new heightmap from 16 bit data; assumes heightmap matches current terrain size
void SetHeightMap(u16* heightmap);
@ -85,34 +87,34 @@ public:
// get patch at given coordinates, expressed in patch-space; return 0 if
// coordinates represent patch off the edge of the map
CPatch* GetPatch(i32 i, i32 j) const;
CPatch* GetPatch(ssize_t i, ssize_t j) const;
// get tile at given coordinates, expressed in tile-space; return 0 if
// coordinates represent tile off the edge of the map
CMiniPatch* GetTile(i32 i, i32 j) const;
CMiniPatch* GetTile(ssize_t i, ssize_t j) const;
// calculate the position of a given vertex
void CalcPosition(i32 i, i32 j, CVector3D& pos) const;
void CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const;
// calculate the vertex under a given position (rounding down coordinates)
static void CalcFromPosition(const CVector3D& pos, i32& i, i32& j)
static void CalcFromPosition(const CVector3D& pos, ssize_t& i, ssize_t& j)
{
i = cpu_i32FromFloat(pos.X/CELL_SIZE);
j = cpu_i32FromFloat(pos.Z/CELL_SIZE);
i = (ssize_t)(pos.X/CELL_SIZE);
j = (ssize_t)(pos.Z/CELL_SIZE);
}
// calculate the vertex under a given position (rounding down coordinates)
static void CalcFromPosition(float x, float z, i32& i, i32& j)
static void CalcFromPosition(float x, float z, ssize_t& i, ssize_t& j)
{
i = cpu_i32FromFloat(x/CELL_SIZE);
j = cpu_i32FromFloat(z/CELL_SIZE);
i = (ssize_t)(x/CELL_SIZE);
j = (ssize_t)(z/CELL_SIZE);
}
// calculate the normal at a given vertex
void CalcNormal(u32 i, u32 j, CVector3D& normal) const;
void CalcNormal(ssize_t i, ssize_t j, CVector3D& normal) const;
// flatten out an area of terrain (specified in world space coords); return
// the average height of the flattened area
float FlattenArea(float x0, float x1, float z0, float z1);
// mark a specific square of tiles as dirty - use this after modifying the heightmap
void MakeDirty(int i0, int j0, int i1, int j1, int dirtyFlags);
void MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags);
// mark the entire map as dirty
void MakeDirty(int dirtyFlags);
@ -129,9 +131,9 @@ private:
void InitialisePatches();
// size of this map in each direction, in vertices; ie. total tiles = sqr(m_MapSize-1)
u32 m_MapSize;
ssize_t m_MapSize;
// size of this map in each direction, in patches; total patches = sqr(m_MapSizePatches)
u32 m_MapSizePatches;
ssize_t m_MapSizePatches;
// the patches comprising this terrain
CPatch* m_Patches;
// 16-bit heightmap data

View File

@ -79,7 +79,7 @@ public:
}
// ScEd wants to sort textures by their group's index.
int GetType() const
size_t GetType() const
{ return m_Groups[0]->GetIndex(); }
const GroupVector &GetGroups() const
{ return m_Groups; }

View File

@ -50,7 +50,7 @@ CTextureEntry* CTextureManager::FindTexture(CStr tag)
{
tag = tag.substr(0, pos);
}
for (uint i=0;i<m_TextureEntries.size();i++)
for (size_t i=0;i<m_TextureEntries.size();i++)
{
if (m_TextureEntries[i]->GetTag() == tag)
return m_TextureEntries[i];
@ -158,7 +158,7 @@ void CTextureManager::RecurseDirectory(CTerrainPropertiesPtr parentProps, const
// Recurse once for each subdirectory
DirectoryNames subdirectoryNames;
g_VFS->GetDirectoryEntries(cur_dir_path, 0, &subdirectoryNames);
for (uint i=0;i<subdirectoryNames.size();i++)
for (size_t i=0;i<subdirectoryNames.size();i++)
{
char subdirectoryPath[PATH_MAX];
path_append(subdirectoryPath, cur_dir_path, subdirectoryNames[i].c_str(), PATH_APPEND_SLASH);

View File

@ -25,12 +25,12 @@ class CTerrainGroup
CStr m_Name;
// "index".. basically a bogus integer that can be used by ScEd to set texture
// priorities
int m_Index;
size_t m_Index;
// list of textures of this type (found from the texture directory)
std::vector<CTextureEntry*> m_Terrains;
public:
CTerrainGroup(CStr name, int index):
CTerrainGroup(CStr name, size_t index):
m_Name(name),
m_Index(index)
{}
@ -40,7 +40,7 @@ public:
// Remove a texture entry
void RemoveTerrain(CTextureEntry *);
int GetIndex() const
size_t GetIndex() const
{ return m_Index; }
CStr GetName() const
{ return m_Name; }
@ -63,7 +63,7 @@ private:
TerrainGroupMap m_TerrainGroups;
uint m_LastGroupIndex;
size_t m_LastGroupIndex;
// Find+load all textures in directory; check if
// there's an override XML with the same basename (if there is, load it)

View File

@ -10,12 +10,13 @@
#include "UnitAnimation.h"
#include "ps/Game.h"
#include "ps/Player.h"
#include "simulation/Entity.h"
CUnit::CUnit(CObjectEntry* object, CEntity* entity, CObjectManager& objectManager,
const std::set<CStr>& actorSelections)
: m_Object(object), m_Model(object->m_Model->Clone()), m_Entity(entity),
m_ID(-1), m_ActorSelections(actorSelections), m_PlayerID(-1),
m_ID(invalidId), m_ActorSelections(actorSelections), m_PlayerID(CPlayer::invalidId),
m_ObjectManager(objectManager)
{
m_Animation = new CUnitAnimation(*this);
@ -158,7 +159,7 @@ void CUnit::UpdateModel(float frameTime)
}
void CUnit::SetPlayerID(int id)
void CUnit::SetPlayerID(size_t id)
{
m_PlayerID = id;
m_Model->SetPlayerID(m_PlayerID);
@ -204,7 +205,7 @@ void CUnit::ReloadObject()
// Copy the old instance-specific settings from the old model to the new instance
newModel->SetTransform(m_Model->GetTransform());
if (m_PlayerID != -1)
if (m_PlayerID != CPlayer::invalidId)
newModel->SetPlayerID(m_PlayerID);
newModel->CopyAnimationFrom(m_Model);

View File

@ -66,16 +66,17 @@ public:
bool IsPlayingAnimation(const CStr& name);
// Set player ID of this unit (and the attached entity and actor)
void SetPlayerID(int id);
void SetPlayerID(size_t id);
// Get player ID of this unit
int GetPlayerID() { return m_PlayerID; }
size_t GetPlayerID() { return m_PlayerID; }
// Most units have a hopefully-unique ID number, so they can be referred to
// persistently despite saving/loading maps. Default for new units is -1; should
// usually be set to CUnitManager::GetNewID() after creation.
int GetID() const { return m_ID; }
void SetID(int id) { m_ID = id; }
static const size_t invalidId = ~(size_t)0;
size_t GetID() const { return m_ID; }
void SetID(size_t id) { m_ID = id; }
const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; }
@ -88,14 +89,14 @@ private:
CModel* m_Model;
// the entity that this actor represents, if any
CEntity* m_Entity;
// player id of this unit (only read for graphical effects), or -1 if unspecified
int m_PlayerID;
// player id of this unit (only read for graphical effects), or ~0 if unspecified
size_t m_PlayerID;
CUnitAnimation* m_Animation;
// unique (per map) ID number for units created in the editor, as a
// permanent way of referencing them. -1 for non-editor units.
int m_ID;
// permanent way of referencing them. ~0 for non-editor units.
size_t m_ID;
// actor-level selections for this unit
std::set<CStr> m_ActorSelections;

View File

@ -68,8 +68,7 @@ void CUnitManager::DeleteUnit(CUnit* unit)
// DeleteAll: remove and delete all units
void CUnitManager::DeleteAll()
{
uint i;
for (i=0;i<m_Units.size();i++) {
for (size_t i=0;i<m_Units.size();i++) {
delete m_Units[i];
}
m_Units.clear();
@ -90,7 +89,7 @@ CUnit* CUnitManager::PickUnit(const CVector3D& origin, const CVector3D& dir, boo
// closest approach offset (easier to pick small stuff in forests than standard ScEd style selection)
float minrel = FLT_MAX;
for (uint i=0; i<m_Units.size(); i++) {
for (size_t i=0; i<m_Units.size(); i++) {
CUnit* unit = m_Units[i];
float tmin, tmax;
@ -137,9 +136,9 @@ CUnit* CUnitManager::CreateUnit(const CStr& actorName, CEntity* entity, const st
///////////////////////////////////////////////////////////////////////////////
// FindByID
CUnit* CUnitManager::FindByID(int id) const
CUnit* CUnitManager::FindByID(size_t id) const
{
if (id < 0)
if (id == CUnit::invalidId)
return NULL;
for (size_t i = 0; i < m_Units.size(); ++i)

View File

@ -47,11 +47,11 @@ public:
// return the closest unit, or null if everything missed
CUnit* PickUnit(const CVector3D& origin, const CVector3D& dir, bool entitiesOnly) const;
CUnit* FindByID(int id) const;
CUnit* FindByID(size_t id) const;
int GetNewID() { return m_NextID++; }
size_t GetNewID() { return m_NextID++; }
void SetNextID(int n) { m_NextID = n; }
void SetNextID(size_t n) { m_NextID = n; }
void SetObjectManager(CObjectManager& objectManager) { m_ObjectManager = &objectManager; }
@ -59,7 +59,7 @@ private:
// list of all known units
std::vector<CUnit*> m_Units;
// next ID number to be assigned to a unit created in the editor
int m_NextID;
size_t m_NextID;
// graphical object manager; may be NULL if not set up
CObjectManager* m_ObjectManager;
};

View File

@ -214,7 +214,7 @@ JSBool JSI_Camera::setProperty( JSContext* cx, JSObject* obj, jsval id, jsval* v
#define GETVECTOR( jv ) ( ( JSVAL_IS_OBJECT( jv ) && NULL != ( v = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( g_ScriptingHost.getContext(), JSVAL_TO_OBJECT( jv ), &JSI_Vector3D::JSI_class, NULL ) ) ) ? *(v->vector) : CVector3D() )
JSBool JSI_Camera::lookAt( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
JSBool JSI_Camera::lookAt( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
{
JSI_Vector3D::Vector3D_Info* v = NULL;
Camera_Info* cameraInfo = (Camera_Info*)JS_GetPrivate( cx, obj );

View File

@ -72,11 +72,11 @@ namespace JSI_Camera
JSBool getCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
JSBool setCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
JSBool construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
JSBool construct( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
void finalize( JSContext* cx, JSObject* obj );
JSBool lookAt( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
JSBool getFocus( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
JSBool lookAt( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
JSBool getFocus( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
void init();
}

View File

@ -406,11 +406,11 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr& SpriteName, CRect
Call.m_TexHandle = h;
uint t_w = 0, t_h = 0;
size_t t_w = 0, t_h = 0;
(void)ogl_tex_get_size(h, &t_w, &t_h, 0);
float TexWidth = t_w, TexHeight = t_h;
uint flags = 0; // assume no alpha on failure
int flags = 0; // assume no alpha on failure
(void)ogl_tex_get_format(h, &flags, 0);
Call.m_EnableBlending = (flags & TEX_ALPHA) != 0;
@ -434,7 +434,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr& SpriteName, CRect
// Check whether this sprite has "cell_size" set
else if (cit->m_CellSize != CSize())
{
int cols = t_w / (int)cit->m_CellSize.cx;
int cols = (int)t_w / (int)cit->m_CellSize.cx;
int col = CellID % cols;
int row = CellID / cols;
BlockTex = CRect(cit->m_CellSize.cx*col, cit->m_CellSize.cy*row,

View File

@ -42,9 +42,9 @@ static float m_scaleX, m_scaleY;
static unsigned int ScaleColor(unsigned int color, float x)
{
unsigned int r = uint(float(color & 0xff) * x);
unsigned int g = uint(float((color>>8) & 0xff) * x);
unsigned int b = uint(float((color>>16) & 0xff) * x);
unsigned int r = unsigned int(float(color & 0xff) * x);
unsigned int g = unsigned int(float((color>>8) & 0xff) * x);
unsigned int b = unsigned int(float((color>>16) & 0xff) * x);
return (0xff000000 | r | g<<8 | b<<16);
}
@ -151,7 +151,7 @@ void CMiniMap::SetCameraPos()
}
m_Camera->UpdateFrustum();
}
void CMiniMap::FireWorldClickEvent(uint button, int clicks)
void CMiniMap::FireWorldClickEvent(int button, int clicks)
{
//debug_printf("FireWorldClickEvent: button %d, clicks %d\n", button, clicks);
@ -269,7 +269,7 @@ void CMiniMap::Draw()
last_time = cur_time;
CLOSManager* losMgr = g_Game->GetWorld()->GetLOSManager();
if(losMgr->m_LOSSetting != CLOSManager::ALL_VISIBLE)
if(losMgr->m_LOSSetting != LOS_SETTING_ALL_VISIBLE)
RebuildLOSTexture();
}
@ -457,7 +457,7 @@ void CMiniMap::CreateTextures()
Destroy();
// Create terrain texture
glGenTextures(1, (GLuint *)&m_TerrainTexture);
glGenTextures(1, &m_TerrainTexture);
g_Renderer.BindTexture(0, m_TerrainTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_TextureSize, m_TextureSize, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, 0);
m_TerrainData = new u32[(m_MapSize - 1) * (m_MapSize - 1)];
@ -467,7 +467,7 @@ void CMiniMap::CreateTextures()
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
// Create LOS texture
glGenTextures(1, (GLuint *)&m_LOSTexture);
glGenTextures(1, &m_LOSTexture);
g_Renderer.BindTexture(0, m_LOSTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, m_TextureSize, m_TextureSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, 0);
m_LOSData = new u8[(m_MapSize - 1) * (m_MapSize - 1)];
@ -541,28 +541,23 @@ void CMiniMap::RebuildLOSTexture()
CLOSManager* losMgr = g_Game->GetWorld()->GetLOSManager();
CPlayer* player = g_Game->GetLocalPlayer();
u32 x = 0;
u32 y = 0;
u32 w = m_MapSize - 1;
u32 h = m_MapSize - 1;
ssize_t x = 0;
ssize_t y = 0;
ssize_t w = m_MapSize - 1;
ssize_t h = m_MapSize - 1;
for(u32 j = 0; j < h; j++)
for(ssize_t j = 0; j < h; j++)
{
u8 *dataPtr = m_LOSData + ((y + j) * (m_MapSize - 1)) + x;
for(u32 i = 0; i < w; i++)
for(ssize_t i = 0; i < w; i++)
{
ELOSStatus status = losMgr->GetStatus((int) i, (int) j, player);
ELOSStatus status = losMgr->GetStatus(i, j, player);
if(status == LOS_UNEXPLORED)
{
*dataPtr++ = 0xff;
}
else if(status == LOS_EXPLORED)
{
*dataPtr++ = (u8) (0xff * 0.3f);
}
else {
else
*dataPtr++ = 0;
}
}
}
@ -576,10 +571,10 @@ void CMiniMap::RebuildLOSTexture()
void CMiniMap::Destroy()
{
if(m_TerrainTexture)
glDeleteTextures(1, (GLuint *)&m_TerrainTexture);
glDeleteTextures(1, &m_TerrainTexture);
if(m_LOSTexture)
glDeleteTextures(1, (GLuint *)&m_LOSTexture);
glDeleteTextures(1, &m_LOSTexture);
delete[] m_TerrainData; m_TerrainData = 0;
delete[] m_LOSData; m_LOSData = 0;

View File

@ -36,7 +36,7 @@ protected:
void SetCameraPos();
void FireWorldClickEvent(uint button, int clicks);
void FireWorldClickEvent(int button, int clicks);
// calculate the relative heightmap space coordinates
// for a units world position
@ -55,20 +55,20 @@ protected:
bool m_Clicking;
// minimap texture handles
u32 m_TerrainTexture;
u32 m_LOSTexture;
GLuint m_TerrainTexture;
GLuint m_LOSTexture;
// texture data
u32 *m_TerrainData;
u8 *m_LOSData;
u32* m_TerrainData;
u8* m_LOSData;
u32 m_Width, m_Height;
ssize_t m_Width, m_Height;
// map size
u32 m_MapSize;
ssize_t m_MapSize;
// texture size
u32 m_TextureSize;
GLsizei m_TextureSize;
void DrawViewRect(); // split out of Draw
};

View File

@ -33,7 +33,7 @@ JSFunctionSpec JSI_GUISize::JSI_methods[] =
{ 0 }
};
JSBool JSI_GUISize::construct(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* UNUSED(rval))
JSBool JSI_GUISize::construct(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* UNUSED(rval))
{
if (argc == 8)
{
@ -137,7 +137,7 @@ JSFunctionSpec JSI_GUIColor::JSI_methods[] =
{ 0 }
};
JSBool JSI_GUIColor::construct(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* UNUSED(rval))
JSBool JSI_GUIColor::construct(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* UNUSED(rval))
{
if (argc == 4)
{
@ -201,7 +201,7 @@ JSFunctionSpec JSI_GUIMouse::JSI_methods[] =
{ 0 }
};
JSBool JSI_GUIMouse::construct(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* UNUSED(rval))
JSBool JSI_GUIMouse::construct(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* UNUSED(rval))
{
if (argc == 3)
{

View File

@ -9,9 +9,9 @@
extern JSClass JSI_class; \
extern JSPropertySpec JSI_props[]; \
extern JSFunctionSpec JSI_methods[]; \
JSBool construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval ); \
JSBool getByName( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval ); \
JSBool toString( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval ); \
JSBool construct( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval ); \
JSBool getByName( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval ); \
JSBool toString( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval ); \
}
GUISTDTYPE(Size)

View File

@ -522,7 +522,7 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
}
JSBool JSI_IGUIObject::construct(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* UNUSED(rval))
JSBool JSI_IGUIObject::construct(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* UNUSED(rval))
{
if (argc == 0)
{
@ -540,7 +540,7 @@ JSBool JSI_IGUIObject::construct(JSContext* cx, JSObject* obj, uint argc, jsval*
}
JSBool JSI_IGUIObject::getByName(JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval)
JSBool JSI_IGUIObject::getByName(JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval)
{
debug_assert(argc == 1);

View File

@ -12,9 +12,9 @@ namespace JSI_IGUIObject
JSBool delProperty(JSContext* cx, JSObject* obj, jsval id, jsval* vp);
JSBool getProperty(JSContext* cx, JSObject* obj, jsval id, jsval* vp);
JSBool setProperty(JSContext* cx, JSObject* obj, jsval id, jsval* vp);
JSBool construct(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval);
JSBool getByName(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval);
JSBool toString(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval);
JSBool construct(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
JSBool getByName(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
JSBool toString(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
void init();
}

View File

@ -12,6 +12,7 @@
#define INCLUDED_ADTS
#include "lib/fnv_hash.h"
#include "lib/bits.h"
//-----------------------------------------------------------------------------
@ -59,7 +60,7 @@ class DynHashTbl
{
size_t hash = tr.hash(key);
debug_assert(max_entries != 0); // otherwise, mask will be incorrect
const uint mask = max_entries-1;
const size_t mask = max_entries-1;
for(;;)
{
T& t = tbl[hash & mask];
@ -228,9 +229,9 @@ public:
struct BitBuf
{
ulong buf;
ulong cur; // bit to be appended (toggled by add())
ulong len; // |buf| [bits]
uintptr_t buf;
uintptr_t cur; // bit to be appended (toggled by add())
size_t len; // |buf| [bits]
void reset()
{
@ -240,7 +241,7 @@ struct BitBuf
}
// toggle current bit if desired, and add to buffer (new bit is LSB)
void add(ulong toggle)
void add(uintptr_t toggle)
{
cur ^= toggle;
buf <<= 1;
@ -249,12 +250,12 @@ struct BitBuf
}
// extract LS n bits
uint extract(ulong n)
size_t extract(uintptr_t n)
{
ulong i = buf & ((1ul << n) - 1);
const uintptr_t bits = buf & bit_mask<uintptr_t>(n);
buf >>= n;
return i;
return bits;
}
};
@ -475,7 +476,7 @@ class MateiHashTbl
{
size_t hash = hashFunc(key);
//debug_assert(max_entries != 0); // otherwise, mask will be incorrect
const uint mask = max_entries-1;
const size_t mask = max_entries-1;
int stride = 1; // for quadratic probing
for(;;)
{

View File

@ -45,7 +45,7 @@ void page_aligned_free(void* p, size_t unaligned_size)
// matrix allocator
//-----------------------------------------------------------------------------
void** matrix_alloc(uint cols, uint rows, size_t el_size)
void** matrix_alloc(size_t cols, size_t rows, size_t el_size)
{
const size_t initial_align = 64;
// note: no provision for padding rows. this is a bit more work and
@ -68,7 +68,7 @@ void** matrix_alloc(uint cols, uint rows, size_t el_size)
debug_assert(data_addr >= (uintptr_t)p+ptr_array_size);
void** ptr_array = (void**)p;
for(uint i = 0; i < cols; i++)
for(size_t i = 0; i < cols; i++)
{
ptr_array[i] = (void*)data_addr;
data_addr += row_size;

View File

@ -65,7 +65,7 @@ LIB_API void page_aligned_free(void* p, size_t unaligned_size);
* @return 0 if out of memory, otherwise matrix that should be cast to
* type** (sizeof(type) == el_size). must be freed via matrix_free.
**/
extern void** matrix_alloc(uint cols, uint rows, size_t el_size);
extern void** matrix_alloc(size_t cols, size_t rows, size_t el_size);
/**
* free the given matrix.

View File

@ -46,7 +46,7 @@ struct LIB_API Bucket
/**
* records # buckets allocated; verifies the list of buckets is correct.
**/
uint num_buckets;
size_t num_buckets;
};

View File

@ -270,7 +270,7 @@ public:
void Insert(FreedBlock* freedBlock)
{
const uint sizeClass = SizeClass(freedBlock->Size());
const size_t sizeClass = SizeClass(freedBlock->Size());
m_rangeLists[sizeClass].Insert<AddressOrder>(freedBlock);
m_bitmap |= BIT(sizeClass);
@ -283,13 +283,13 @@ public:
{
// iterate over all large enough, non-empty size classes
// (zero overhead for empty size classes)
const uint minSizeClass = SizeClass(minSize);
uint sizeClassBits = m_bitmap & (~0u << minSizeClass);
const size_t minSizeClass = SizeClass(minSize);
size_t sizeClassBits = m_bitmap & (~0u << minSizeClass);
while(sizeClassBits)
{
const uint size = ValueOfLeastSignificantOneBit(sizeClassBits);
const size_t size = ValueOfLeastSignificantOneBit(sizeClassBits);
sizeClassBits &= ~size; // remove from sizeClassBits
const uint sizeClass = SizeClass(size);
const size_t sizeClass = SizeClass(size);
FreedBlock* freedBlock = m_rangeLists[sizeClass].Find(minSize);
if(freedBlock)
@ -304,7 +304,7 @@ public:
void Remove(FreedBlock* freedBlock)
{
const uint sizeClass = SizeClass(freedBlock->Size());
const size_t sizeClass = SizeClass(freedBlock->Size());
m_rangeLists[sizeClass].Remove(freedBlock);
// (masking with !IsEmpty() << sizeClass would probably be faster)
@ -344,9 +344,9 @@ private:
* @return "size class" of a given size.
* class i > 0 contains blocks of size (2**(i-1), 2**i].
**/
static uint SizeClass(size_t size)
static size_t SizeClass(size_t size)
{
return ceil_log2((uint)size);
return ceil_log2((size_t)size);
}
static uintptr_t ValueOfLeastSignificantOneBit(uintptr_t x)

View File

@ -68,7 +68,7 @@ const char* StringPool::RandomString() const
debug_assert(m_pool.da.pos != 0);
again:
const size_t start_ofs = (size_t)rand(0, (uint)m_pool.da.pos);
const size_t start_ofs = (size_t)rand(0, (size_t)m_pool.da.pos);
// scan back to start of string (don't scan ahead; this must
// work even if m_pool only contains one entry).

View File

@ -59,7 +59,7 @@ static void def_log(const wchar_t* text)
}
static ErrorReaction def_display_error(const wchar_t* UNUSED(text), uint UNUSED(flags))
static ErrorReaction def_display_error(const wchar_t* UNUSED(text), int UNUSED(flags))
{
return ER_NOT_IMPLEMENTED;
}
@ -153,7 +153,7 @@ void ah_log(const wchar_t* text)
ah.log(text);
}
ErrorReaction ah_display_error(const wchar_t* text, uint flags)
ErrorReaction ah_display_error(const wchar_t* text, int flags)
{
return ah.display_error(text, flags);
}

View File

@ -154,7 +154,7 @@ extern void ah_log(const wchar_t* text);
* the default implementation just returns ER_NOT_IMPLEMENTED, which
* causes the normal sys_display_error to be used.
**/
extern ErrorReaction ah_display_error(const wchar_t* text, uint flags);
extern ErrorReaction ah_display_error(const wchar_t* text, int flags);
/**
@ -169,7 +169,7 @@ struct AppHooks
const wchar_t* (*translate)(const wchar_t* text);
void (*translate_free)(const wchar_t* text);
void (*log)(const wchar_t* text);
ErrorReaction (*display_error)(const wchar_t* text, uint flags);
ErrorReaction (*display_error)(const wchar_t* text, int flags);
};
/**

View File

@ -15,7 +15,7 @@
void base32(const size_t in_len, const u8* in, u8* out)
{
u32 pool = 0; // of bits from buffer
uint pool_bits = 0; // # bits currently in buffer
size_t pool_bits = 0; // # bits currently in buffer
static const u8 tbl[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
@ -32,7 +32,7 @@ void base32(const size_t in_len, const u8* in, u8* out)
}
pool_bits -= 5;
const uint c = (pool >> pool_bits) & 31;
const size_t c = (pool >> pool_bits) & 31;
*out++ = tbl[c];
}

View File

@ -11,54 +11,9 @@
#include "precompiled.h"
#include "bits.h"
#if ARCH_IA32
# include "lib/sysdep/ia32/ia32_asm.h" // ia32_asm_log2_of_pow2
#endif
int log2_of_pow2(uint n)
{
int bit_index;
#if ARCH_IA32
bit_index = ia32_asm_log2_of_pow2(n);
#else
if(!is_pow2(n))
bit_index = -1;
else
{
bit_index = 0;
// note: compare against n directly because it is known to be a POT.
for(uint bit_value = 1; bit_value != n; bit_value *= 2)
bit_index++;
}
#endif
debug_assert(-1 <= bit_index && bit_index < (int)sizeof(int)*CHAR_BIT);
debug_assert(bit_index == -1 || n == (1u << bit_index));
return bit_index;
}
int floor_log2(const float x)
{
const u32 i = *(u32*)&x;
u32 biased_exp = (i >> 23) & 0xFF;
return (int)biased_exp - 127;
}
uint round_up_to_pow2(uint x)
{
// fold upper bit into lower bits; leaves same MSB set but
// everything below it 1. adding 1 yields next POT.
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
// if ints are 64 bits, add "x |= (x >> 32);"
cassert(sizeof(int)*CHAR_BIT == 32);
return x+1;
}

View File

@ -36,15 +36,12 @@
*
* @param num_bits number of bits in mask
**/
inline uint bit_mask(uint num_bits)
template<typename T>
T bit_mask(size_t num_bits)
{
return (1u << num_bits)-1;
return (T)(T(1) << num_bits)-1;
}
inline u64 bit_mask64(uint num_bits)
{
return (1ull << num_bits)-1;
}
/**
* extract the value of bits hi_idx:lo_idx within num
@ -56,57 +53,64 @@ inline u64 bit_mask64(uint num_bits)
* @param hi_idx bit index of highest bit to include
* @return value of extracted bits.
**/
inline uint bits(uint num, uint lo_idx, uint hi_idx)
template<typename T>
inline T bits(T num, size_t lo_idx, size_t hi_idx)
{
const uint count = (hi_idx - lo_idx)+1; // # bits to return
uint result = num >> lo_idx;
result &= bit_mask(count);
const size_t count = (hi_idx - lo_idx)+1; // # bits to return
T result = num >> lo_idx;
result &= bit_mask<T>(count);
return result;
}
inline u64 bits64(u64 num, uint lo_idx, uint hi_idx)
/**
* @return number of 1-bits in mask
**/
template<typename T>
size_t PopulationCount(T mask)
{
const uint count = (hi_idx - lo_idx)+1; // # bits to return
u64 result = num >> lo_idx;
result &= bit_mask64(count);
return result;
// note: a more complex but probably faster method is given at
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
size_t num1Bits = 0;
while(mask)
{
mask &= mask-1; // clear least significant 1-bit
num1Bits++;
}
return num1Bits;
}
/**
* @return whether the given number is a power of two.
**/
inline bool is_pow2(uint n)
template<typename T>
bool is_pow2(T n)
{
// 0 would pass the test below but isn't a POT.
if(n == 0)
return false;
return (n & (n-1ul)) == 0;
return (n & (n-1)) == 0;
}
/**
* @return the (integral) base 2 logarithm, or -1 if the number
* is not a power-of-two.
**/
extern int log2_of_pow2(uint n);
/**
* ceil(log2(n))
*
* @param n (integer) input; MUST be > 0, else results are undefined.
* @return ceiling of the base-2 logarithm (i.e. rounded up).
**/
inline uint ceil_log2(uint x)
template<typename T>
size_t ceil_log2(T x)
{
uint bit = 1;
uint l = 0;
T bit = 1;
size_t log = 0;
while(bit < x && bit != 0) // must detect overflow
{
l++;
bit += bit;
log++;
bit *= 2;
}
return l;
return log;
}
@ -122,7 +126,11 @@ extern int floor_log2(const float x);
/**
* round up to next larger power of two.
**/
extern uint round_up_to_pow2(uint x);
template<typename T>
T round_up_to_pow2(T x)
{
return T(1) << ceil_log2(x);
}
/**
* round number up/down to the next given multiple.
@ -132,7 +140,7 @@ extern uint round_up_to_pow2(uint x);
template<typename T>
T round_up(T n, T multiple)
{
debug_assert(is_pow2((uint)multiple));
debug_assert(is_pow2(multiple));
const T result = (n + multiple-1) & ~(multiple-1);
debug_assert(n <= result && result < n+multiple);
return result;
@ -141,7 +149,7 @@ T round_up(T n, T multiple)
template<typename T>
T round_down(T n, T multiple)
{
debug_assert(is_pow2((uint)multiple));
debug_assert(is_pow2(multiple));
const T result = n & ~(multiple-1);
debug_assert(result <= n && n < result+multiple);
return result;

View File

@ -167,7 +167,7 @@ void write_be64(void* p, u64 x)
u64 movzx_le64(const u8* p, size_t size_bytes)
{
u64 number = 0;
for(uint i = 0; i < std::min(size_bytes, (size_t)8u); i++)
for(size_t i = 0; i < std::min(size_bytes, (size_t)8u); i++)
number |= ((u64)p[i]) << (i*8);
return number;
@ -176,7 +176,7 @@ u64 movzx_le64(const u8* p, size_t size_bytes)
u64 movzx_be64(const u8* p, size_t size_bytes)
{
u64 number = 0;
for(uint i = 0; i < std::min(size_bytes, (size_t)8u); i++)
for(size_t i = 0; i < std::min(size_bytes, (size_t)8u); i++)
{
number <<= 8;
number |= p[i];

View File

@ -603,7 +603,7 @@ template<class Item, class Divider> struct CacheEntry
{
Item item;
size_t size;
uint cost;
size_t cost;
float credit;
Divider divider;
@ -613,7 +613,7 @@ template<class Item, class Divider> struct CacheEntry
{
}
CacheEntry(Item item_, size_t size_, uint cost_)
CacheEntry(Item item_, size_t size_, size_t cost_)
: item(item_), divider((float)size_)
{
size = size_;
@ -647,7 +647,7 @@ class Cache
public:
Cache() : mgr() {}
void add(Key key, Item item, size_t size, uint cost)
void add(Key key, Item item, size_t size, size_t cost)
{
return mgr.add(key, Entry(item, size, cost));
}

View File

@ -16,13 +16,6 @@
// configuration choices, so rebuilding them all is acceptable.
// use config.h when settings must apply to the entire project.
// (only applicable if ARCH_IA32) 64-bit values will be returned in EDX:EAX.
// this chiefly affects ia32_rdtsc. if not set, a safer but slower fallback
// will be used that doesn't assume anything about return convention.
#ifndef CONFIG2_IA32_RETURN64_EDX_EAX
# define CONFIG2_IA32_RETURN64_EDX_EAX 1
#endif
// allow use of RDTSC for raw tick counts (otherwise, the slower but
// more reliable on MP systems wall-clock will be used).
#ifndef CONFIG2_TIMER_ALLOW_RDTSC

View File

@ -86,16 +86,16 @@ void debug_wprintf_mem(const wchar_t* fmt, ...)
// rationale: static data instead of std::set to allow setting at any time.
// we store FNV hash of tag strings for fast comparison; collisions are
// extremely unlikely and can only result in displaying more/less text.
static const uint MAX_TAGS = 20;
static const size_t MAX_TAGS = 20;
static u32 tags[MAX_TAGS];
static uint num_tags;
static size_t num_tags;
void debug_filter_add(const char* tag)
{
const u32 hash = fnv_hash(tag);
// make sure it isn't already in the list
for(uint i = 0; i < MAX_TAGS; i++)
for(size_t i = 0; i < MAX_TAGS; i++)
if(tags[i] == hash)
return;
@ -113,7 +113,7 @@ void debug_filter_remove(const char* tag)
{
const u32 hash = fnv_hash(tag);
for(uint i = 0; i < MAX_TAGS; i++)
for(size_t i = 0; i < MAX_TAGS; i++)
// found it
if(tags[i] == hash)
{
@ -133,7 +133,7 @@ void debug_filter_clear()
bool debug_filter_allows(const char* text)
{
uint i;
size_t i;
for(i = 0; ; i++)
{
// no | found => no tag => should always be displayed
@ -252,7 +252,7 @@ void debug_error_message_free(ErrorMessageMem* emm)
const wchar_t* debug_error_message_build(
const wchar_t* description,
const char* fn_only, int line, const char* func,
uint skip, void* context,
size_t skip, void* context,
ErrorMessageMem* emm)
{
// rationale: see ErrorMessageMem
@ -324,7 +324,7 @@ fail:
return buf;
}
static ErrorReaction call_display_error(const wchar_t* text, uint flags)
static ErrorReaction call_display_error(const wchar_t* text, int flags)
{
// first try app hook implementation
ErrorReaction er = ah_display_error(text, flags);
@ -335,7 +335,7 @@ static ErrorReaction call_display_error(const wchar_t* text, uint flags)
return er;
}
static ErrorReaction carry_out_ErrorReaction(ErrorReaction er, uint flags, u8* suppress)
static ErrorReaction carry_out_ErrorReaction(ErrorReaction er, int flags, u8* suppress)
{
const bool manual_break = (flags & DE_MANUAL_BREAK) != 0;
@ -372,7 +372,7 @@ static ErrorReaction carry_out_ErrorReaction(ErrorReaction er, uint flags, u8* s
}
ErrorReaction debug_display_error(const wchar_t* description,
uint flags, uint skip, void* context,
int flags, size_t skip, void* context,
const char* file, int line, const char* func,
u8* suppress)
{
@ -471,7 +471,7 @@ ErrorReaction debug_assert_failed(const char* expr, u8* suppress,
{
if(should_skip_this_assert())
return ER_CONTINUE;
uint skip = 1; void* context = 0;
size_t skip = 1; void* context = 0;
wchar_t buf[400];
swprintf(buf, ARRAY_SIZE(buf), L"Assertion failed: \"%hs\"", expr);
return debug_display_error(buf, DE_MANUAL_BREAK, skip,context, file,line,func, suppress);
@ -484,7 +484,7 @@ ErrorReaction debug_warn_err(LibError err, u8* suppress,
if(should_skip_this_error(err))
return ER_CONTINUE;
uint skip = 1; void* context = 0;
size_t skip = 1; void* context = 0;
wchar_t buf[400];
char err_buf[200]; error_description_r(err, err_buf, ARRAY_SIZE(err_buf));
swprintf(buf, ARRAY_SIZE(buf), L"Function call failed: return value was %d (%hs)", err, err_buf);

View File

@ -147,7 +147,7 @@ enum ErrorReaction
* @return ErrorReaction (user's choice: continue running or stop?)
**/
LIB_API ErrorReaction debug_display_error(const wchar_t* description,
uint flags, uint skip, void* context,
int flags, size_t skip, void* context,
const char* file, int line, const char* func,
u8* suppress);
@ -436,7 +436,7 @@ LIB_API LibError debug_resolve_symbol(void* ptr_of_interest, char* sym_name, cha
* @return LibError; ERR::REENTERED if reentered via recursion or
* multithreading (not allowed since static data is used).
**/
LIB_API LibError debug_dump_stack(wchar_t* buf, size_t max_chars, uint skip, void* context);
LIB_API LibError debug_dump_stack(wchar_t* buf, size_t max_chars, size_t skip, void* context);
//-----------------------------------------------------------------------------
@ -461,7 +461,7 @@ LIB_API void debug_puts(const char* text);
*
* note: this does not access debug symbols and is therefore quite fast.
**/
LIB_API void* debug_get_nth_caller(uint skip, void* context);
LIB_API void* debug_get_nth_caller(size_t skip, void* context);
/**
* check if a pointer appears to be totally invalid.
@ -532,7 +532,7 @@ LIB_API void debug_error_message_free(ErrorMessageMem* emm);
LIB_API const wchar_t* debug_error_message_build(
const wchar_t* description,
const char* fn_only, int line, const char* func,
uint skip, void* context,
size_t skip, void* context,
ErrorMessageMem* emm);
#endif // #ifndef INCLUDED_DEBUG

View File

@ -109,7 +109,7 @@ char* debug_stl_simplify_name(char* name)
src += 7;
}
REPLACE("unsigned short", "u16")
REPLACE("unsigned int", "uint")
REPLACE("unsigned int", "size_t")
REPLACE("unsigned __int64", "u64")
STRIP(",0> ")
// early out: all tests after this start with s, so skip them

View File

@ -18,8 +18,8 @@
time_t time_t_from_FAT(u32 fat_timedate)
{
const uint fat_time = bits(fat_timedate, 0, 15);
const uint fat_date = bits(fat_timedate, 16, 31);
const u32 fat_time = bits(fat_timedate, 0, 15);
const u32 fat_date = bits(fat_timedate, 16, 31);
struct tm t; // struct tm format:
t.tm_sec = bits(fat_time, 0,4) * 2; // [0,59]

View File

@ -187,7 +187,7 @@ struct Connection
// repeated edges ("connections") are reflected in
// the 'occurrences' count; we optimize the ordering so that
// files with frequent connections are nearby.
uint occurrences;
size_t occurrences;
Connection(ConnectionId id_)
: id(id_), occurrences(1) {}
@ -267,7 +267,7 @@ class ConnectionBuilder
for(size_t r = 0; r < t.num_runs; r++)
{
const TraceRun& run = t.runs[r];
for(uint i = 0; i < run.num_ents; i++)
for(size_t i = 0; i < run.num_ents; i++)
{
const TraceEntry* te = &run.ents[i];
// improvement: postprocess the trace and remove all IOs that would be
@ -1090,7 +1090,7 @@ LibError trace_run(const char* osPathname)
{
Trace trace;
RETURN_ERR(trace.Load(osPathname));
for(uint i = 0; i < trace.NumEntries(); i++)
for(size_t i = 0; i < trace.NumEntries(); i++)
trace.Entries()[i]->Run();
return INFO::OK;
}

View File

@ -111,7 +111,7 @@ public:
m_usize = to_le32(u32_from_larger(fileInfo.Size()));
m_fn_len = to_le16(u16_from_larger(pathnameString.length()));
m_e_len = to_le16(0);
m_c_len = to_le16(u16_from_larger((uint)slack));
m_c_len = to_le16(u16_from_larger((size_t)slack));
m_x2 = to_le32(0);
m_x3 = to_le32(0);
m_lfh_ofs = to_le32(ofs);
@ -189,7 +189,7 @@ cassert(sizeof(CDFH) == 46);
class ECDR
{
public:
void Init(uint cd_numEntries, off_t cd_ofs, off_t cd_size)
void Init(size_t cd_numEntries, off_t cd_ofs, off_t cd_size)
{
m_magic = ecdr_magic;
memset(m_x1, 0, sizeof(m_x1));
@ -199,9 +199,9 @@ public:
m_comment_len = to_le16(0);
}
void Decompose(uint& cd_numEntries, off_t& cd_ofs, off_t& cd_size) const
void Decompose(size_t& cd_numEntries, off_t& cd_ofs, off_t& cd_size) const
{
cd_numEntries = (uint)read_le16(&m_cd_numEntries);
cd_numEntries = (size_t)read_le16(&m_cd_numEntries);
cd_ofs = (off_t)read_le32(&m_cd_ofs);
cd_size = (off_t)read_le32(&m_cd_size);
}
@ -234,7 +234,7 @@ public:
{
}
virtual unsigned Precedence() const
virtual size_t Precedence() const
{
return 2u;
}
@ -370,7 +370,7 @@ public:
virtual LibError ReadEntries(ArchiveEntryCallback cb, uintptr_t cbData)
{
// locate and read Central Directory
off_t cd_ofs; uint cd_numEntries; off_t cd_size;
off_t cd_ofs; size_t cd_numEntries; off_t cd_size;
RETURN_ERR(LocateCentralDirectory(m_file, m_fileSize, cd_ofs, cd_numEntries, cd_size));
shared_ptr<u8> buf = io_Allocate(cd_size, cd_ofs);
u8* cd;
@ -378,7 +378,7 @@ public:
// iterate over Central Directory
const u8* pos = cd;
for(uint i = 0; i < cd_numEntries; i++)
for(size_t i = 0; i < cd_numEntries; i++)
{
// scan for next CDFH
CDFH* cdfh = (CDFH*)FindRecord(cd, cd_size, pos, cdfh_magic, sizeof(CDFH));
@ -435,7 +435,7 @@ private:
// search for ECDR in the last <maxScanSize> bytes of the file.
// if found, fill <dst_ecdr> with a copy of the (little-endian) ECDR and
// return INFO::OK, otherwise IO error or ERR::CORRUPTED.
static LibError ScanForEcdr(PIFile file, off_t fileSize, u8* buf, off_t maxScanSize, uint& cd_numEntries, off_t& cd_ofs, off_t& cd_size)
static LibError ScanForEcdr(PIFile file, off_t fileSize, u8* buf, off_t maxScanSize, size_t& cd_numEntries, off_t& cd_ofs, off_t& cd_size)
{
// don't scan more than the entire file
const off_t scanSize = std::min(maxScanSize, fileSize);
@ -454,7 +454,7 @@ private:
return INFO::OK;
}
static LibError LocateCentralDirectory(PIFile file, off_t fileSize, off_t& cd_ofs, uint& cd_numEntries, off_t& cd_size)
static LibError LocateCentralDirectory(PIFile file, off_t fileSize, off_t& cd_ofs, size_t& cd_numEntries, off_t& cd_size)
{
const off_t maxScanSize = 66000u; // see below
shared_ptr<u8> buf = io_Allocate(maxScanSize, BLOCK_SIZE-1); // assume worst-case for alignment
@ -616,7 +616,7 @@ private:
"ogg", "mp3"
};
for(uint i = 0; i < ARRAY_SIZE(incompressibleExtensions); i++)
for(size_t i = 0; i < ARRAY_SIZE(incompressibleExtensions); i++)
{
if(!strcasecmp(extension, incompressibleExtensions[i]))
return true;
@ -630,7 +630,7 @@ private:
UnalignedWriter m_unalignedWriter;
Pool m_cdfhPool;
uint m_numEntries;
size_t m_numEntries;
};
PIArchiveWriter CreateArchiveWriter_Zip(const Path& archivePathname)

View File

@ -5,7 +5,7 @@ struct IFileLoader
{
virtual ~IFileLoader();
virtual unsigned Precedence() const = 0;
virtual size_t Precedence() const = 0;
virtual char LocationCode() const = 0;
virtual LibError Load(const std::string& name, shared_ptr<u8> buf, size_t size) const = 0;

View File

@ -17,37 +17,37 @@
// vfs
static uint vfs_files;
static size_t vfs_files;
static size_t vfs_size_total;
static double vfs_init_elapsed_time;
// file
static uint unique_names;
static size_t unique_names;
static size_t unique_name_len_total;
static uint open_files_cur, open_files_max; // total = opened_files.size()
static size_t open_files_cur, open_files_max; // total = opened_files.size()
// file_buf
static uint extant_bufs_cur, extant_bufs_max, extant_bufs_total;
static size_t extant_bufs_cur, extant_bufs_max, extant_bufs_total;
static double buf_size_total, buf_aligned_size_total;
// file_io
static uint user_ios;
static size_t user_ios;
static double user_io_size_total;
static double io_actual_size_total[FI_MAX_IDX][2];
static double io_elapsed_time[FI_MAX_IDX][2];
static double io_process_time_total;
static uint io_seeks;
static size_t io_seeks;
// file_cache
static uint cache_count[2];
static size_t cache_count[2];
static double cache_size_total[2];
static uint conflict_misses;
static size_t conflict_misses;
static double conflict_miss_size_total;
static uint block_cache_count[2];
static size_t block_cache_count[2];
// archive builder
static uint ab_connection_attempts; // total number of trace entries
static uint ab_repeated_connections; // how many of these were not unique
static size_t ab_connection_attempts; // total number of trace entries
static size_t ab_repeated_connections; // how many of these were not unique
// convenience functions for measuring elapsed time in an interval.

View File

@ -6,13 +6,13 @@
#include "lib/file/io/io.h"
RealDirectory::RealDirectory(const Path& path, unsigned priority, unsigned flags)
RealDirectory::RealDirectory(const Path& path, size_t priority, int flags)
: m_path(path), m_priority(priority), m_flags(flags)
{
}
/*virtual*/ unsigned RealDirectory::Precedence() const
/*virtual*/ size_t RealDirectory::Precedence() const
{
return 1u;
}

View File

@ -7,25 +7,25 @@
class RealDirectory : public IFileLoader
{
public:
RealDirectory(const Path& path, unsigned priority, unsigned flags);
RealDirectory(const Path& path, size_t priority, int flags);
const Path& GetPath() const
{
return m_path;
}
unsigned Priority() const
size_t Priority() const
{
return m_priority;
}
unsigned Flags() const
int Flags() const
{
return m_flags;
}
// IFileLoader
virtual unsigned Precedence() const;
virtual size_t Precedence() const;
virtual char LocationCode() const;
virtual LibError Load(const std::string& name, shared_ptr<u8> buf, size_t size) const;
@ -42,9 +42,9 @@ private:
// is not all too wasteful.
const Path m_path;
const unsigned m_priority;
const size_t m_priority;
const unsigned m_flags;
const int m_flags;
// note: watches are needed in each directory because some APIs
// (e.g. FAM) cannot watch entire trees with one call.

View File

@ -30,7 +30,7 @@ public:
break;
// out of room - remove a previous allocation
// .. choose one at random
size_t chosen_idx = (size_t)rand(0, (uint)allocations.size());
size_t chosen_idx = (size_t)rand(0, (size_t)allocations.size());
AllocMap::iterator it = allocations.begin();
for(; chosen_idx != 0; chosen_idx--)
++it;

View File

@ -63,7 +63,7 @@ void fs_SortDirectories(DirectoryNames& directories)
}
LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern, unsigned flags)
LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern, int flags)
{
debug_assert(vfs_path_IsDirectory(path));
@ -102,7 +102,7 @@ LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_
}
void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, unsigned& nextNumber, VfsPath& nextPathname)
void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname)
{
// (first call only:) scan directory and set nextNumber according to
// highest matching filename found. this avoids filling "holes" in
@ -114,12 +114,12 @@ void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, unsigned&
const std::string nameFormat = pathnameFormat.leaf();
const VfsPath path = pathnameFormat.branch_path()/"/";
unsigned maxNumber = 0;
size_t maxNumber = 0;
FileInfos files;
fs->GetDirectoryEntries(path, &files, 0);
for(size_t i = 0; i < files.size(); i++)
{
unsigned number;
size_t number;
if(sscanf(files[i].Name().c_str(), nameFormat.c_str(), &number) == 1)
maxNumber = std::max(number, maxNumber);
}

View File

@ -47,7 +47,7 @@ enum DirFlags
* @param flags see DirFlags
* @param LibError
**/
extern LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, uint flags = 0);
extern LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, int flags = 0);
/**
@ -56,12 +56,12 @@ extern LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, u
* ones (screenshots are a good example).
*
* @param pathnameFormat format string for the pathname; must contain one
* format specifier for an (unsigned) int.
* format specifier for a size_t.
* example: "screenshots/screenshot%04d.png"
* @param nextNumber in: the first number to try; out: the next number.
* if 0, numbers corresponding to existing files are skipped.
* @param nextPathname receives the output.
**/
extern void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, unsigned& nextNumber, VfsPath& nextPathname);
extern void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname);
#endif // #ifndef INCLUDED_FILE_SYSTEM_UTIL

View File

@ -18,7 +18,7 @@
#include "block_cache.h"
#include "io_align.h"
static const unsigned ioDepth = 8;
static const size_t ioDepth = 8;
// the underlying aio implementation likes buffer and offset to be

View File

@ -17,7 +17,7 @@ void WriteBuffer::Append(const void* data, size_t size)
{
if(m_size + size > m_capacity)
{
m_capacity = round_up_to_pow2((uint)(m_size + size));
m_capacity = round_up_to_pow2((size_t)(m_size + size));
shared_ptr<u8> newData = io_Allocate(m_capacity);
cpu_memcpy(newData.get(), m_data.get(), m_size);
m_data = newData;

View File

@ -171,7 +171,7 @@ public:
}
}
void Add(const VfsPath& pathname, shared_ptr<u8> data, size_t size, uint cost)
void Add(const VfsPath& pathname, shared_ptr<u8> data, size_t size, size_t cost)
{
// zero-copy cache => all users share the contents => must not
// allow changes. this will be reverted when deallocating.
@ -217,7 +217,7 @@ shared_ptr<u8> FileCache::Reserve(size_t size)
return impl->Reserve(size);
}
void FileCache::Add(const VfsPath& pathname, shared_ptr<u8> data, size_t size, uint cost)
void FileCache::Add(const VfsPath& pathname, shared_ptr<u8> data, size_t size, size_t cost)
{
impl->Add(pathname, data, size, cost);
}

View File

@ -61,7 +61,7 @@ public:
* @param cost is the expected cost of retrieving the file again and
* influences how/when it is evicted from the cache.
**/
void Add(const VfsPath& pathname, shared_ptr<u8> data, size_t size, uint cost = 1);
void Add(const VfsPath& pathname, shared_ptr<u8> data, size_t size, size_t cost = 1);
/**
* Remove a file's contents from the cache (if it exists).

View File

@ -31,7 +31,7 @@ public:
{
}
virtual LibError Mount(const VfsPath& mountPoint, const Path& path, uint flags /* = 0 */, uint priority /* = 0 */)
virtual LibError Mount(const VfsPath& mountPoint, const Path& path, int flags /* = 0 */, size_t priority /* = 0 */)
{
debug_assert(vfs_path_IsDirectory(mountPoint));
// note: mounting subdirectories is now allowed.

View File

@ -67,7 +67,7 @@ struct IVFS
* if files with archive extensions are seen, their contents are added
* as well.
**/
virtual LibError Mount(const VfsPath& mountPoint, const Path& path, uint flags = 0, uint priority = 0) = 0;
virtual LibError Mount(const VfsPath& mountPoint, const Path& path, int flags = 0, size_t priority = 0) = 0;
virtual LibError GetFileInfo(const VfsPath& pathname, FileInfo* pfileInfo) const = 0;

View File

@ -68,7 +68,7 @@ private:
// (we have to create missing subdirectoryNames because archivers
// don't always place directory entries before their files)
const unsigned flags = VFS_LOOKUP_ADD;
const int flags = VFS_LOOKUP_ADD;
VfsDirectory* directory;
WARN_ERR(vfs_Lookup(pathname, this_->m_directory, directory, 0, flags));
const VfsFile file(fileInfo.Name(), fileInfo.Size(), fileInfo.MTime(), this_->m_realDirectory->Priority(), archiveFile);
@ -135,7 +135,7 @@ static LibError Populate(VfsDirectory* directory)
//-----------------------------------------------------------------------------
LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDirectory*& directory, VfsFile** pfile, unsigned flags)
LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDirectory*& directory, VfsFile** pfile, int flags)
{
TIMER_ACCRUE(tc_lookup);

View File

@ -42,6 +42,6 @@ enum VfsLookupFlags
*
* to allow noiseless file-existence queries, this does not raise warnings.
**/
extern LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDirectory*& directory, VfsFile** pfile, unsigned flags = 0);
extern LibError vfs_Lookup(const VfsPath& pathname, VfsDirectory* startDirectory, VfsDirectory*& directory, VfsFile** pfile, int flags = 0);
#endif // #ifndef INCLUDED_VFS_LOOKUP

View File

@ -17,7 +17,7 @@
//-----------------------------------------------------------------------------
VfsFile::VfsFile(const std::string& name, off_t size, time_t mtime, unsigned priority, PIFileLoader loader)
VfsFile::VfsFile(const std::string& name, off_t size, time_t mtime, size_t priority, PIFileLoader loader)
: m_name(name), m_size(size), m_mtime(mtime), m_priority(priority), m_loader(loader)
{
}
@ -135,7 +135,7 @@ void VfsDirectory::GetEntries(FileInfos* files, DirectoryNames* subdirectoryName
}
void VfsDirectory::DisplayR(unsigned depth) const
void VfsDirectory::DisplayR(size_t depth) const
{
static const char indent[] = " ";
@ -151,7 +151,7 @@ void VfsDirectory::DisplayR(unsigned depth) const
char description[100];
file.GenerateDescription(description, ARRAY_SIZE(description));
for(unsigned i = 0; i < depth+1; i++)
for(size_t i = 0; i < depth+1; i++)
printf(indent);
printf(fmt, name.c_str(), description);
}
@ -161,7 +161,7 @@ void VfsDirectory::DisplayR(unsigned depth) const
const std::string& name = it->first;
const VfsDirectory& directory = it->second;
for(unsigned i = 0; i < depth+1; i++)
for(size_t i = 0; i < depth+1; i++)
printf(indent);
printf("[%s/]\n", name.c_str());

View File

@ -18,7 +18,7 @@
class VfsFile
{
public:
VfsFile(const std::string& name, off_t size, time_t mtime, unsigned priority, PIFileLoader provider);
VfsFile(const std::string& name, off_t size, time_t mtime, size_t priority, PIFileLoader provider);
const std::string& Name() const
{
@ -74,7 +74,7 @@ public:
void GetEntries(FileInfos* files, DirectoryNames* subdirectories) const;
void DisplayR(unsigned depth) const;
void DisplayR(size_t depth) const;
void ClearR();

View File

@ -17,9 +17,9 @@
#include "lib/external_libraries/sdl.h"
const uint MAX_HANDLERS = 8;
const size_t MAX_HANDLERS = 8;
static InHandler handler_stack[MAX_HANDLERS];
static uint handler_stack_top = 0;
static size_t handler_stack_top = 0;
void in_add_handler(InHandler handler)
{

View File

@ -86,7 +86,7 @@ u8 u8_from_double(double in)
}
int l = (int)(in * 255.0);
debug_assert((unsigned int)l <= 255u);
debug_assert((unsigned)l <= 255u);
return (u8)l;
}

View File

@ -52,9 +52,9 @@ scope
#include "config.h"
const size_t KiB = 1ul << 10;
const size_t MiB = 1ul << 20;
const size_t GiB = 1ul << 30;
const size_t KiB = size_t(1) << 10;
const size_t MiB = size_t(1) << 20;
const size_t GiB = size_t(1) << 30;
//

View File

@ -46,7 +46,7 @@ todo:
// total number of hazard pointers needed by each thread.
// determined by the algorithms using SMR; the LF list requires 2.
static const uint NUM_HPS = 2;
static const size_t NUM_HPS = 2;
// number of slots for the per-thread node freelist.
// this is a reasonable size and pads struct TLS to 64 bytes.
@ -631,7 +631,7 @@ LibError lfh_init(LFHash* hash, size_t num_entries)
hash->tbl = (LFList*)malloc(sizeof(LFList) * num_entries);
if(!hash->tbl)
return ERR::NO_MEM;
hash->mask = (uint)num_entries-1;
hash->mask = (size_t)num_entries-1;
for(int i = 0; i < (int)num_entries; i++)
{

View File

@ -131,7 +131,7 @@ extern LibError lfl_erase(LFList* list, uintptr_t key);
struct LFHash
{
LFList* tbl;
uint mask;
size_t mask;
};
// make ready a previously unused(!) hash object. table size will be

View File

@ -160,7 +160,7 @@ void path_copy(char* dst, const char* src)
// if necessary, a directory separator is added between the paths.
// each may be empty, filenames, or full paths.
// total path length (including '\0') must not exceed PATH_MAX.
LibError path_append(char* dst, const char* path1, const char* path2, uint flags)
LibError path_append(char* dst, const char* path1, const char* path2, int flags)
{
const size_t len1 = strlen(path1);
const size_t len2 = strlen(path2);

View File

@ -106,7 +106,7 @@ enum PathAppendFlags
* @param flags see PathAppendFlags.
* @return LibError
**/
extern LibError path_append(char* dst, const char* path1, const char* path2, uint flags = 0);
extern LibError path_append(char* dst, const char* path1, const char* path2, int flags = 0);
/**
* get the name component of a path.

View File

@ -46,7 +46,7 @@ float fmaxf(float a, float b)
}
uint fpclassifyd(double d)
size_t fpclassifyd(double d)
{
#if ARCH_IA32
return ia32_asm_fpclassifyd(d);
@ -60,7 +60,7 @@ uint fpclassifyd(double d)
#endif
}
uint fpclassifyf(float f)
size_t fpclassifyf(float f)
{
#if ARCH_IA32
return ia32_asm_fpclassifyf(f);

View File

@ -108,8 +108,8 @@ extern double rint(double d);
extern float fminf(float a, float b);
extern float fmaxf(float a, float b);
extern uint fpclassifyf(float f);
extern uint fpclassifyd(double d);
extern size_t fpclassifyf(float f);
extern size_t fpclassifyd(double d);
#define fpclassify(x) ( (sizeof(x) == sizeof(float))? fpclassifyf(x) : fpclassifyd(x) )
// these definitions "happen" to match IA32_FP_* and allow using

View File

@ -20,23 +20,23 @@
// folded down to a much smaller interval anyway. instead, a larger XRAND_MAX
// decreases the probability of having to repeat the loop.
#if RAND_MAX < 65536
static const uint XRAND_MAX = (RAND_MAX+1)*(RAND_MAX+1) - 1;
static uint xrand()
static const size_t XRAND_MAX = (RAND_MAX+1)*(RAND_MAX+1) - 1;
static size_t xrand()
{
return rand()*(RAND_MAX+1) + rand();
}
// rand() is already ok; no need to do anything.
#else
static const uint XRAND_MAX = RAND_MAX;
static uint xrand()
static const size_t XRAND_MAX = RAND_MAX;
static size_t xrand()
{
return rand();
}
#endif
uint rand(uint min_inclusive, uint max_exclusive)
size_t rand(size_t min_inclusive, size_t max_exclusive)
{
const uint range = (max_exclusive-min_inclusive);
const size_t range = (max_exclusive-min_inclusive);
// huge interval or min >= max
if(range == 0 || range > XRAND_MAX)
{
@ -44,15 +44,17 @@ uint rand(uint min_inclusive, uint max_exclusive)
return 0;
}
const uint inv_range = XRAND_MAX / range;
const size_t inv_range = XRAND_MAX / range;
// generate random number in [0, range)
// idea: avoid skewed distributions when <range> doesn't evenly divide
// XRAND_MAX by simply discarding values in the "remainder".
// not expected to run often since XRAND_MAX is large.
uint x;
size_t x;
do
x = xrand();
{
x = xrand();
}
while(x >= range * inv_range);
x /= inv_range;

View File

@ -16,6 +16,6 @@
* avoids several common pitfalls; see discussion at
* http://www.azillionmonkeys.com/qed/random.html
**/
extern uint rand(uint min_inclusive, uint max_exclusive);
extern size_t rand(size_t min_inclusive, size_t max_exclusive);
#endif // #ifndef INCLUDED_RAND

View File

@ -71,7 +71,7 @@ static void* load_sys_cursor(const VfsPath& pathname, int hx, int hy)
void* sys_cursor = 0; // return value
// convert to required BGRA format.
const uint flags = (t.flags | TEX_BGR) & ~TEX_DXT;
const int flags = (t.flags | TEX_BGR) & ~TEX_DXT;
if(tex_transform_to(&t, flags) < 0)
goto fail;
void* bgra_img = tex_get_data(&t);
@ -99,16 +99,19 @@ class GLCursor
{
Handle ht;
uint w, h;
uint hotspotx, hotspoty;
GLint w, h;
int hotspotx, hotspoty;
public:
LibError create(const VfsPath& pathname, uint hotspotx_, uint hotspoty_)
LibError create(const VfsPath& pathname, int hotspotx_, int hotspoty_)
{
ht = ogl_tex_load(pathname);
RETURN_ERR(ht);
(void)ogl_tex_get_size(ht, &w, &h, 0);
size_t width, height;
(void)ogl_tex_get_size(ht, &width, &height, 0);
w = (GLint)width;
h = (GLint)height;
hotspotx = hotspotx_; hotspoty = hotspoty_;
@ -124,7 +127,7 @@ public:
(void)ogl_tex_free(ht);
}
void draw(uint x, uint y) const
void draw(int x, int y) const
{
(void)ogl_tex_bind(ht);
glEnable(GL_TEXTURE_2D);
@ -146,7 +149,7 @@ public:
LibError validate() const
{
const uint A = 128; // no cursor is expected to get this big
const size_t A = 128; // no cursor is expected to get this big
if(w > A || h > A || hotspotx > A || hotspoty > A)
WARN_RETURN(ERR::_1);
if(ht < 0)
@ -189,7 +192,7 @@ static LibError Cursor_reload(Cursor* c, const VfsPath& name, Handle)
// read pixel offset of the cursor's hotspot [the bit of it that's
// drawn at (g_mouse_x,g_mouse_y)] from file.
uint hotspotx = 0, hotspoty = 0;
int hotspotx = 0, hotspoty = 0;
{
const VfsPath pathname(path / (basename + ".txt"));
shared_ptr<u8> buf; size_t size;

View File

@ -92,12 +92,12 @@ static bool fmt_is_s3tc(GLenum fmt)
// determine OpenGL texture format, given <bpp> and Tex <flags>.
static GLint choose_fmt(uint bpp, uint flags)
static GLint choose_fmt(size_t bpp, int flags)
{
const bool alpha = (flags & TEX_ALPHA) != 0;
const bool bgr = (flags & TEX_BGR ) != 0;
const bool grey = (flags & TEX_GREY ) != 0;
const uint dxt = flags & TEX_DXT;
const size_t dxt = flags & TEX_DXT;
// S3TC
if(dxt != 0)
@ -144,11 +144,11 @@ static GLint choose_fmt(uint bpp, uint flags)
//----------------------------------------------------------------------------
static GLint default_filter = GL_LINEAR; // one of the GL *minify* filters
static uint default_q_flags = OGL_TEX_FULL_QUALITY; // OglTexQualityFlags
static int default_q_flags = OGL_TEX_FULL_QUALITY; // OglTexQualityFlags
static bool q_flags_valid(uint q_flags)
static bool q_flags_valid(int q_flags)
{
const uint bits = OGL_TEX_FULL_QUALITY|OGL_TEX_HALF_BPP|OGL_TEX_HALF_RES;
const size_t bits = OGL_TEX_FULL_QUALITY|OGL_TEX_HALF_BPP|OGL_TEX_HALF_RES;
// unrecognized bits are set - invalid
if((q_flags & ~bits) != 0)
return false;
@ -166,7 +166,7 @@ static bool q_flags_valid(uint q_flags)
// pass 0 to keep the current setting; defaults and legal values are:
// - q_flags: OGL_TEX_FULL_QUALITY; combination of OglTexQualityFlags
// - filter: GL_LINEAR; any valid OpenGL minification filter
void ogl_tex_set_defaults(uint q_flags, GLint filter)
void ogl_tex_set_defaults(int q_flags, GLint filter)
{
if(q_flags)
{
@ -183,7 +183,7 @@ void ogl_tex_set_defaults(uint q_flags, GLint filter)
// choose an internal format for <fmt> based on the given q_flags.
static GLint choose_int_fmt(GLenum fmt, uint q_flags)
static GLint choose_int_fmt(GLenum fmt, int q_flags)
{
// true => 4 bits per component; otherwise, 8
const bool half_bpp = (q_flags & OGL_TEX_HALF_BPP) != 0;
@ -330,7 +330,7 @@ enum OglTexFlags
// "the enclosed Tex object is valid and holds a texture";
// reset in dtor and after ogl_tex_upload's tex_free.
OT_TEX_VALID = 2,
//uint tex_valid : 1;
//size_t tex_valid : 1;
// "reload() should automatically re-upload the texture" (because
// it had been uploaded before the reload); never reset.
@ -357,12 +357,12 @@ struct OglTex
OglTexState state;
// OglTexQualityFlags
uint q_flags : 8;
int q_flags : 8;
// to which Texture Mapping Unit was this bound?
uint tmu : 8;
size_t tmu : 8;
uint flags : 16;
int flags : 16;
};
H_TYPE_DEFINE(OglTex);
@ -475,7 +475,7 @@ static LibError OglTex_to_string(const OglTex* ot, char* buf)
// load and return a handle to the texture given in <pathname>.
// for a list of supported formats, see tex.h's tex_load.
Handle ogl_tex_load(const VfsPath& pathname, uint flags)
Handle ogl_tex_load(const VfsPath& pathname, int flags)
{
Tex* wrapped_tex = 0; // we're loading from file
return h_alloc(H_OglTex, pathname, flags, wrapped_tex);
@ -503,7 +503,7 @@ Handle ogl_tex_find(const VfsPath& pathname)
// note: because we cannot guarantee that callers will pass distinct
// "filenames", caching is disabled for the created object. this avoids
// mistakenly reusing previous objects that share the same comment.
Handle ogl_tex_wrap(Tex* t, const char* fn, uint flags)
Handle ogl_tex_wrap(Tex* t, const char* fn, int flags)
{
// this object may not be backed by a file ("may", because
// someone could do tex_load and then ogl_tex_wrap).
@ -694,7 +694,7 @@ static void detect_gl_upload_caps()
// whether mipmaps are needed and the quality settings).
// returns 0 to indicate success; otherwise, caller must disable
// mipmapping by switching filter to e.g. GL_LINEAR.
static LibError get_mipmaps(Tex* t, GLint filter, uint q_flags, int* plevels_to_skip)
static LibError get_mipmaps(Tex* t, GLint filter, int q_flags, int* plevels_to_skip)
{
// decisions:
// .. does filter call for uploading mipmaps?
@ -748,8 +748,8 @@ static LibError get_mipmaps(Tex* t, GLint filter, uint q_flags, int* plevels_to_
// note: we don't just use GL_TEXTURE_BASE_LEVEL because it would
// require uploading unused levels, which is wasteful.
// .. can be expanded to reduce to 1/4, 1/8 by encoding factor in q_flags.
const uint reduce = (q_flags & OGL_TEX_HALF_RES)? 2 : 1;
*plevels_to_skip = ceil_log2(reduce);
const size_t reduce = (q_flags & OGL_TEX_HALF_RES)? 2 : 1;
*plevels_to_skip = (int)ceil_log2(reduce);
}
return INFO::OK;
@ -764,18 +764,16 @@ struct UploadParams
GLint int_fmt;
};
static void upload_level(uint level, uint level_w, uint level_h, const u8* RESTRICT level_data, size_t UNUSED(level_data_size), void* RESTRICT cbData)
static void upload_level(size_t level, size_t level_w, size_t level_h, const u8* RESTRICT level_data, size_t UNUSED(level_data_size), void* RESTRICT cbData)
{
const UploadParams* up = (const UploadParams*)cbData;
glTexImage2D(GL_TEXTURE_2D, level, up->int_fmt, level_w, level_h, 0,
up->fmt, GL_UNSIGNED_BYTE, level_data);
glTexImage2D(GL_TEXTURE_2D, (GLint)level, up->int_fmt, (GLsizei)level_w, (GLsizei)level_h, 0, up->fmt, GL_UNSIGNED_BYTE, level_data);
}
static void upload_compressed_level(uint level, uint level_w, uint level_h, const u8* RESTRICT level_data, size_t level_data_size, void* RESTRICT cbData)
static void upload_compressed_level(size_t level, size_t level_w, size_t level_h, const u8* RESTRICT level_data, size_t level_data_size, void* RESTRICT cbData)
{
const UploadParams* up = (const UploadParams*)cbData;
pglCompressedTexImage2DARB(GL_TEXTURE_2D, level, up->fmt,
(GLsizei)level_w, (GLsizei)level_h, 0, (GLsizei)level_data_size, level_data);
pglCompressedTexImage2DARB(GL_TEXTURE_2D, (GLint)level, up->fmt, (GLsizei)level_w, (GLsizei)level_h, 0, (GLsizei)level_data_size, level_data);
}
// upload the texture in the specified (internal) format.
@ -786,7 +784,7 @@ static void upload_impl(Tex* t, GLenum fmt, GLint int_fmt, int levels_to_skip)
{
const GLsizei w = (GLsizei)t->w;
const GLsizei h = (GLsizei)t->h;
const uint bpp = t->bpp;
const size_t bpp = t->bpp;
const u8* data = (const u8*)tex_get_data(t);
const UploadParams up = { fmt, int_fmt };
@ -806,7 +804,7 @@ static void upload_impl(Tex* t, GLenum fmt, GLint int_fmt, int levels_to_skip)
// side effects:
// - enables texturing on TMU 0 and binds the texture to it;
// - frees the texel data! see ogl_tex_get_data.
LibError ogl_tex_upload(const Handle ht, GLenum fmt_ovr, uint q_flags_ovr, GLint int_fmt_ovr)
LibError ogl_tex_upload(const Handle ht, GLenum fmt_ovr, int q_flags_ovr, GLint int_fmt_ovr)
{
ONCE(detect_gl_upload_caps());
@ -873,7 +871,7 @@ LibError ogl_tex_upload(const Handle ht, GLenum fmt_ovr, uint q_flags_ovr, GLint
// retrieve texture dimensions and bits per pixel.
// all params are optional and filled if non-NULL.
LibError ogl_tex_get_size(Handle ht, uint* w, uint* h, uint* bpp)
LibError ogl_tex_get_size(Handle ht, size_t* w, size_t* h, size_t* bpp)
{
H_DEREF(ht, OglTex, ot);
@ -890,7 +888,7 @@ LibError ogl_tex_get_size(Handle ht, uint* w, uint* h, uint* bpp)
// retrieve TexFlags and the corresponding OpenGL format.
// the latter is determined during ogl_tex_upload and is 0 before that.
// all params are optional and filled if non-NULL.
LibError ogl_tex_get_format(Handle ht, uint* flags, GLenum* fmt)
LibError ogl_tex_get_format(Handle ht, int* flags, GLenum* fmt)
{
H_DEREF(ht, OglTex, ot);
@ -936,7 +934,7 @@ LibError ogl_tex_get_data(Handle ht, void** p)
// - assumes multitexturing is available.
// - not necessary before calling ogl_tex_upload!
// - on error, the unit's texture state is unchanged; see implementation.
LibError ogl_tex_bind(Handle ht, uint unit)
LibError ogl_tex_bind(Handle ht, size_t unit)
{
// note: there are many call sites of glActiveTextureARB, so caching
// those and ignoring redundant sets isn't feasible.
@ -968,7 +966,7 @@ LibError ogl_tex_bind(Handle ht, uint unit)
// apply the specified transforms (as in tex_transform) to the image.
// must be called before uploading (raises a warning if called afterwards).
LibError ogl_tex_transform(Handle ht, uint transforms)
LibError ogl_tex_transform(Handle ht, size_t transforms)
{
H_DEREF(ht, OglTex, ot);
LibError ret = tex_transform(&ot->t, transforms);
@ -978,7 +976,7 @@ LibError ogl_tex_transform(Handle ht, uint transforms)
// change the pixel format to that specified by <new_flags>.
// (note: this is equivalent to ogl_tex_transform(ht, ht_flags^new_flags).
LibError ogl_tex_transform_to(Handle ht, uint new_flags)
LibError ogl_tex_transform_to(Handle ht, size_t new_flags)
{
H_DEREF(ht, OglTex, ot);
LibError ret = tex_transform_to(&ot->t, new_flags);

View File

@ -108,7 +108,7 @@ the next function to fail, but real apps should check and report errors.
specify internal_format and use multitexturing.
Tex t;
const uint flags = 0; * image is plain RGB, default orientation
const int flags = 0; * image is plain RGB, default orientation
void* data = [pre-existing image]
(void)tex_wrap(w, h, 24, flags, data, &t);
Handle hCompositeAlphaMap = ogl_tex_wrap(&t, "(alpha map composite)");
@ -189,7 +189,7 @@ enum OglTexQualityFlags
* @param filter mag/minification filter. Pass 0 to keep the current setting
* (initially GL_LINEAR), or any valid OpenGL minification filter.
*/
extern void ogl_tex_set_defaults(uint q_flags, GLint filter);
extern void ogl_tex_set_defaults(int q_flags, GLint filter);
//
@ -203,7 +203,7 @@ extern void ogl_tex_set_defaults(uint q_flags, GLint filter);
* @return Handle to texture or negative LibError
* for a list of supported formats, see tex.h's tex_load.
*/
extern Handle ogl_tex_load(const VfsPath& pathname, uint flags = 0);
extern Handle ogl_tex_load(const VfsPath& pathname, int flags = 0);
/**
* Find and return an existing texture object, if it has already been
@ -232,7 +232,7 @@ extern Handle ogl_tex_find(const VfsPath& pathname);
* we need only add bookkeeping information and "wrap" it in
* a resource object (accessed via Handle), hence the name.
*/
extern Handle ogl_tex_wrap(Tex* t, const char* fn = 0, uint flags = 0);
extern Handle ogl_tex_wrap(Tex* t, const char* fn = 0, int flags = 0);
/**
* Release this texture reference. When the count reaches zero, all of
@ -316,7 +316,7 @@ extern void ogl_tex_override(OglTexOverrides what, OglTexAllow allow);
* <LI>frees the texel data! see ogl_tex_get_data.
* </UL>
*/
extern LibError ogl_tex_upload(const Handle ht, GLenum fmt_ovr = 0, uint q_flags_ovr = 0, GLint int_fmt_ovr = 0);
extern LibError ogl_tex_upload(const Handle ht, GLenum fmt_ovr = 0, int q_flags_ovr = 0, GLint int_fmt_ovr = 0);
//
@ -332,7 +332,7 @@ extern LibError ogl_tex_upload(const Handle ht, GLenum fmt_ovr = 0, uint q_flags
* @param bpp optional; will be filled with bits per pixel
* @return LibError
*/
extern LibError ogl_tex_get_size(Handle ht, uint* w, uint* h, uint* bpp);
extern LibError ogl_tex_get_size(Handle ht, size_t* w, size_t* h, size_t* bpp);
/**
* Retrieve pixel format of the texture.
@ -343,7 +343,7 @@ extern LibError ogl_tex_get_size(Handle ht, uint* w, uint* h, uint* bpp);
* (it is determined during ogl_tex_upload and 0 before then)
* @return LibError
*/
extern LibError ogl_tex_get_format(Handle ht, uint* flags, GLenum* fmt);
extern LibError ogl_tex_get_format(Handle ht, int* flags, GLenum* fmt);
/**
* Retrieve pixel data of the texture.
@ -382,7 +382,7 @@ extern LibError ogl_tex_get_data(Handle ht, void** p);
* - not necessary before calling ogl_tex_upload!
* - on error, the unit's texture state is unchanged; see implementation.
*/
extern LibError ogl_tex_bind(Handle ht, uint unit = 0);
extern LibError ogl_tex_bind(Handle ht, size_t unit = 0);
/**
* (partially) Transform pixel format of the texture.
@ -394,7 +394,7 @@ extern LibError ogl_tex_bind(Handle ht, uint unit = 0);
*
* Must be called before uploading (raises a warning if called afterwards).
*/
extern LibError ogl_tex_transform(Handle ht, uint flags);
extern LibError ogl_tex_transform(Handle ht, int flags);
/**
* Transform pixel format of the texture.
@ -408,6 +408,6 @@ extern LibError ogl_tex_transform(Handle ht, uint flags);
*
* Note: this is equivalent to ogl_tex_transform(ht, ht_flags^new_flags).
*/
extern LibError ogl_tex_transform_to(Handle ht, uint new_flags);
extern LibError ogl_tex_transform_to(Handle ht, size_t new_flags);
#endif // #ifndef INCLUDED_OGL_TEX

View File

@ -6,7 +6,7 @@
class TestTex : public CxxTest::TestSuite
{
void generate_encode_decode_compare(uint w, uint h, uint flags, uint bpp, const std::string& extension)
void generate_encode_decode_compare(size_t w, size_t h, int flags, size_t bpp, const std::string& extension)
{
// generate test data
const size_t size = w*h*bpp/8;
@ -60,14 +60,14 @@ public:
TS_ASSERT_EQUALS(c, correct_c);
// for each test width/height combination
const uint widths [] = { 4, 5, 4, 256, 384 };
const uint heights[] = { 4, 4, 5, 256, 256 };
const size_t widths [] = { 4, 5, 4, 256, 384 };
const size_t heights[] = { 4, 4, 5, 256, 256 };
for(size_t i = 0; i < ARRAY_SIZE(widths); i++)
{
// for each bit depth
for(uint bpp = 8; bpp <= 32; bpp += 8)
for(size_t bpp = 8; bpp <= 32; bpp += 8)
{
uint flags = 0;
int flags = 0;
if(!strcmp(extension, ".dds"))
flags |= (TEX_DXT&3); // DXT3
if(bpp == 8)

View File

@ -35,7 +35,7 @@ struct UniFont
glyphmap_id* glyphs_id; // Stored as pointers to keep the struct's size down. (sizeof(std::map)==12, though that's probably not enough to matter)
glyphmap_size* glyphs_size;
uint ListBase;
GLuint ListBase;
int LineSpacing;
int Height; // of a capital letter, roughly
};
@ -188,7 +188,7 @@ static LibError UniFont_to_string(const UniFont* f, char* buf)
}
Handle unifont_load(const VfsPath& pathname, uint flags)
Handle unifont_load(const VfsPath& pathname, int flags)
{
return h_alloc(H_UniFont, pathname, flags);
}

View File

@ -15,7 +15,7 @@
// Load and return a handle to the font defined
// in fn+".fnt" with texture fn+".tga"
extern Handle unifont_load(const VfsPath& pathname, uint flags = 0);
extern Handle unifont_load(const VfsPath& pathname, int flags = 0);
// Release a handle to a previously loaded font
extern LibError unifont_unload(Handle& h);

View File

@ -21,7 +21,7 @@
#include "lib/module_init.h"
static const uint MAX_EXTANT_HANDLES = 10000;
static const size_t MAX_EXTANT_HANDLES = 10000;
// rationale
//
@ -54,13 +54,13 @@ static const uint MAX_EXTANT_HANDLES = 10000;
// - tag (1-based) ensures the handle references a certain resource instance.
// (field width determines maximum unambiguous resource allocs)
#define TAG_BITS 32
const uint TAG_SHIFT = 0;
const size_t TAG_SHIFT = 0;
const u32 TAG_MASK = 0xFFFFFFFF; // safer than (1 << 32) - 1
// - index (0-based) of control block in our array.
// (field width determines maximum currently open handles)
#define IDX_BITS 16
const uint IDX_SHIFT = 32;
const size_t IDX_SHIFT = 32;
const u32 IDX_MASK = (1l << IDX_BITS) - 1;
// make sure both fields fit within a Handle variable
@ -103,10 +103,10 @@ static inline Handle handle(const u32 _idx, const u32 tag)
// determines maximum number of references to a resource.
static const uint REF_BITS = 16;
static const size_t REF_BITS = 16;
static const u32 REF_MAX = (1ul << REF_BITS)-1;
static const uint TYPE_BITS = 8;
static const size_t TYPE_BITS = 8;
// chosen so that all current resource structs are covered,
@ -137,7 +137,7 @@ struct HDATA
H_Type type;
// for statistics
uint num_derefs;
size_t num_derefs;
VfsPath pathname;
@ -146,20 +146,20 @@ struct HDATA
// max data array entries. compared to last_in_use => signed.
static const i32 hdata_cap = 1ul << IDX_BITS;
static const ssize_t hdata_cap = 1ul << IDX_BITS;
// allocate entries as needed so as not to waste memory
// (hdata_cap may be large). deque-style array of pages
// to balance locality, fragmentation, and waste.
static const size_t PAGE_SIZE = 4096;
static const uint hdata_per_page = PAGE_SIZE / sizeof(HDATA);
static const uint num_pages = hdata_cap / hdata_per_page;
static const size_t hdata_per_page = PAGE_SIZE / sizeof(HDATA);
static const size_t num_pages = hdata_cap / hdata_per_page;
static HDATA* pages[num_pages];
// these must be signed, because there won't always be a valid
// first or last element.
static i32 first_free = -1; // don't want to scan array every h_alloc
static i32 last_in_use = -1; // don't search unused entries
static ssize_t first_free = -1; // don't want to scan array every h_alloc
static ssize_t last_in_use = -1; // don't search unused entries
// error checking strategy:
@ -172,7 +172,7 @@ static i32 last_in_use = -1; // don't search unused entries
// for the first time, and there's not enough memory to allocate it.
//
// also used by h_data, and alloc_idx to find a free entry.
static HDATA* h_data_from_idx(const i32 idx)
static HDATA* h_data_from_idx(const ssize_t idx)
{
// don't compare against last_in_use - this is called before allocating
// new entries, and to check if the next (but possibly not yet valid)
@ -187,7 +187,7 @@ static HDATA* h_data_from_idx(const i32 idx)
return 0;
// Initialise all the VfsPath members
for(uint i = 0; i < hdata_per_page; ++i)
for(size_t i = 0; i < hdata_per_page; ++i)
new (&page[i].pathname) VfsPath;
}
@ -204,7 +204,7 @@ static HDATA* h_data_from_idx(const i32 idx)
// used by h_force_close (which must work regardless of tag).
static inline HDATA* h_data_no_tag(const Handle h)
{
i32 idx = (i32)h_idx(h);
ssize_t idx = (ssize_t)h_idx(h);
// need to verify it's in range - h_data_from_idx can only verify that
// it's < maximum allowable index.
if(0 > idx || idx > last_in_use)
@ -252,7 +252,7 @@ static HDATA* h_data_tag_type(const Handle h, const H_Type type)
// idx and hd are undefined if we fail.
// called by h_alloc only.
static LibError alloc_idx(i32& idx, HDATA*& hd)
static LibError alloc_idx(ssize_t& idx, HDATA*& hd)
{
// we already know the first free entry
if(first_free != -1)
@ -305,7 +305,7 @@ have_idx:;
}
static LibError free_idx(i32 idx)
static LibError free_idx(ssize_t idx)
{
if(first_free == -1 || idx < first_free)
first_free = idx;
@ -329,7 +329,7 @@ static LibError free_idx(i32 idx)
// that wasn't forseen here, so we'll just refrain from adding to the index.
// that means they won't be found via h_find - no biggie.
typedef STL_HASH_MULTIMAP<uintptr_t, i32> Key2Idx;
typedef STL_HASH_MULTIMAP<uintptr_t, ssize_t> Key2Idx;
typedef Key2Idx::iterator It;
static OverrunProtector<Key2Idx> key2idx_wrapper;
@ -350,7 +350,7 @@ static Handle key_find(uintptr_t key, H_Type type, KeyRemoveFlag remove_option =
std::pair<It, It> range = key2idx->equal_range(key);
for(It it = range.first; it != range.second; ++it)
{
i32 idx = it->second;
ssize_t idx = it->second;
HDATA* hd = h_data_from_idx(idx);
// found match
if(hd && hd->type == type && hd->key == key)
@ -373,7 +373,7 @@ static void key_add(uintptr_t key, Handle h)
if(!key2idx)
return;
const i32 idx = h_idx(h);
const ssize_t idx = h_idx(h);
// note: MSDN documentation of stdext::hash_multimap is incorrect;
// there is no overload of insert() that returns pair<iterator, bool>.
(void)key2idx->insert(std::make_pair(key, idx));
@ -444,7 +444,7 @@ static u32 gen_tag()
}
static Handle reuse_existing_handle(uintptr_t key, H_Type type, uint flags)
static Handle reuse_existing_handle(uintptr_t key, H_Type type, int flags)
{
if(flags & RES_NO_CACHE)
return 0;
@ -506,9 +506,9 @@ static LibError call_init_and_reload(Handle h, H_Type type, HDATA* hd, const Vfs
}
static Handle alloc_new_handle(H_Type type, const VfsPath& pathname, uintptr_t key, uint flags, va_list* init_args)
static Handle alloc_new_handle(H_Type type, const VfsPath& pathname, uintptr_t key, int flags, va_list* init_args)
{
i32 idx;
ssize_t idx;
HDATA* hd;
RETURN_ERR(alloc_idx(idx, hd));
@ -549,7 +549,7 @@ fail:
// any further params are passed to type's init routine
Handle h_alloc(H_Type type, const VfsPath& pathname, uint flags, ...)
Handle h_alloc(H_Type type, const VfsPath& pathname, int flags, ...)
{
RETURN_ERR(type_validate(type));
@ -575,7 +575,7 @@ Handle h_alloc(H_Type type, const VfsPath& pathname, uint flags, ...)
//-----------------------------------------------------------------------------
// currently cannot fail.
static LibError h_free_idx(i32 idx, HDATA* hd)
static LibError h_free_idx(ssize_t idx, HDATA* hd)
{
// debug_printf("free %s %s\n", type->name, hd->fn);
@ -623,7 +623,7 @@ static LibError h_free_idx(i32 idx, HDATA* hd)
LibError h_free(Handle& h, H_Type type)
{
i32 idx = h_idx(h);
ssize_t idx = h_idx(h);
HDATA* hd = h_data_tag_type(h, type);
// wipe out the handle to prevent reuse but keep a copy for below.
@ -690,7 +690,7 @@ LibError h_reload(const VfsPath& pathname)
// do this before reloading any of them, because we don't specify reload
// order (the parent resource may be reloaded first, and load the child,
// whose original data would leak).
for(i32 i = 0; i <= last_in_use; i++)
for(ssize_t i = 0; i <= last_in_use; i++)
{
HDATA* hd = h_data_from_idx(i);
if(!hd || hd->key != key || hd->disallow_reload)
@ -701,7 +701,7 @@ LibError h_reload(const VfsPath& pathname)
LibError ret = INFO::OK;
// now reload all affected handles
for(i32 i = 0; i <= last_in_use; i++)
for(ssize_t i = 0; i <= last_in_use; i++)
{
HDATA* hd = h_data_from_idx(i);
if(!hd || hd->key != key || hd->disallow_reload)
@ -805,7 +805,7 @@ void h_mgr_shutdown()
debug_printf("H_MGR| shutdown. any handle frees after this are leaks!\n");
// forcibly close all open handles
for(i32 i = 0; i <= last_in_use; i++)
for(ssize_t i = 0; i <= last_in_use; i++)
{
HDATA* hd = h_data_from_idx(i);
// can't fail - i is in bounds by definition, and
@ -829,10 +829,10 @@ void h_mgr_shutdown()
}
// free HDATA array
for(uint j = 0; j < num_pages; j++)
for(size_t j = 0; j < num_pages; j++)
{
if (pages[j])
for(uint k = 0; k < hdata_per_page; ++k)
for(size_t k = 0; k < hdata_per_page; ++k)
pages[j][k].pathname.~VfsPath(); // FIXME: ugly hack, but necessary to reclaim std::string memory
free(pages[j]);
pages[j] = 0;

View File

@ -67,7 +67,7 @@ your actual definition must match.
struct Res1
{
void* data; // data loaded from file
uint flags; // set when resource is created
int flags; // set when resource is created
};
Note that all control blocks are stored in fixed-size slots
@ -376,7 +376,7 @@ const size_t H_STRING_LEN = 256;
//// user_size is checked to make sure the user data fits in the handle data space.
// dtor is associated with type and called when the object is freed.
// handle data is initialized to 0; optionally, a pointer to it is returned.
extern Handle h_alloc(H_Type type, const VfsPath& pathname, uint flags = 0, ...);
extern Handle h_alloc(H_Type type, const VfsPath& pathname, int flags = 0, ...);
extern LibError h_free(Handle& h, H_Type type);

Some files were not shown because too many files have changed in this diff Show More