1
0
forked from 0ad/0ad

large batch of Dehydra static code analysis fixes

(mostly passing arguments by const reference and checking LibError
return codes)

This was SVN commit r6214.
This commit is contained in:
janwas 2008-07-12 10:45:11 +00:00
parent 088f3b54be
commit 3c411dd174
41 changed files with 134 additions and 144 deletions

View File

@ -125,7 +125,10 @@ public:
// we deliberately pass invalid XML data) because the VFS caching
// logic warns when asked to load such.
if(writeBuffer.Size())
g_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size());
{
LibError ret = g_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size());
debug_assert(ret == INFO::OK);
}
return true;
}
@ -215,7 +218,8 @@ VfsPath CColladaManager::GetLoadableFilename(const CStr& sourceName, FileType ty
// realDaePath is "mods/whatever/art/meshes/whatever.dae"
Path realDaePath;
g_VFS->GetRealPath(dae, realDaePath);
LibError ret = g_VFS->GetRealPath(dae, realDaePath);
debug_assert(ret == INFO::OK);
// cachedPmdVfsPath is "cache/mods/whatever/art/meshes/whatever_{hash}.pmd"
VfsPath cachedPmdVfsPath = VfsPath("cache/") / realDaePath.string();

View File

@ -170,8 +170,8 @@ int CMapReader::UnpackTerrain()
}
// unpack tile data [3ms]
size_t tilesPerSide = m_MapSize*PATCH_SIZE;
m_Tiles.resize(SQR(tilesPerSide));
ssize_t tilesPerSide = m_MapSize*PATCH_SIZE;
m_Tiles.resize(size_t(SQR(tilesPerSide)));
unpacker.UnpackRaw(&m_Tiles[0], sizeof(STileDesc)*m_Tiles.size());
// reset generator state.

View File

@ -87,8 +87,8 @@ void CMapWriter::EnumTerrainTextures(CTerrain *pTerrain,
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++) {
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];
u16 index=u16(GetHandleIndex(mp.Tex1,handles));
if (index==0xFFFF) {
@ -516,7 +516,7 @@ void CMapWriter::RewriteAllMaps(CTerrain* pTerrain, CUnitManager* pUnitMan,
CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema)
{
VfsPaths pathnames;
fs_GetPathnames(g_VFS, "maps/scenarios", "*.pmp", pathnames);
(void)fs_GetPathnames(g_VFS, "maps/scenarios", "*.pmp", pathnames);
for (size_t i = 0; i < pathnames.size(); i++)
{
const char* pathname = pathnames[i].string().c_str();

View File

@ -17,7 +17,7 @@ static SMaterialColor IdentityEmissive(0.0f, 0.0f, 0.0f, 1.0f);
static SMaterialColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f);
bool SMaterialColor::operator ==(const SMaterialColor color)
bool SMaterialColor::operator==(const SMaterialColor& color)
{
return (
r == color.r &&
@ -40,7 +40,7 @@ CMaterial::CMaterial()
ComputeHash();
}
CMaterial::CMaterial(const CMaterial &material)
CMaterial::CMaterial(const CMaterial& material)
{
(*this) = material;
}
@ -49,7 +49,7 @@ CMaterial::~CMaterial()
{
}
void CMaterial::operator =(const CMaterial &material)
void CMaterial::operator=(const CMaterial& material)
{
m_Diffuse = material.m_Diffuse;
m_Ambient = material.m_Ambient;
@ -63,7 +63,7 @@ void CMaterial::operator =(const CMaterial &material)
ComputeHash();
}
bool CMaterial::operator ==(const CMaterial &material)
bool CMaterial::operator==(const CMaterial& material)
{
return(
m_Texture == m_Texture &&
@ -141,13 +141,13 @@ void CMaterial::SetPlayerColor(size_t id)
m_PlayerID = id;
}
void CMaterial::SetPlayerColor(CColor &colour)
void CMaterial::SetPlayerColor(CColor& colour)
{
m_TextureColor = SMaterialColor(colour.r, colour.g, colour.b, colour.a);
}
void CMaterial::SetTexture(const CStr& texture)
void CMaterial::SetTexture(const CStr& texture)
{
m_Texture = texture;
ComputeHash();
@ -165,25 +165,25 @@ void CMaterial::SetFragmentProgram(const CStr& prog)
ComputeHash();
}
void CMaterial::SetDiffuse(const SMaterialColor &color)
void CMaterial::SetDiffuse(const SMaterialColor& color)
{
m_Diffuse = color;
ComputeHash();
}
void CMaterial::SetAmbient(const SMaterialColor &color)
void CMaterial::SetAmbient(const SMaterialColor& color)
{
m_Ambient = color;
ComputeHash();
}
void CMaterial::SetSpecular(const SMaterialColor &color)
void CMaterial::SetSpecular(const SMaterialColor& color)
{
m_Specular = color;
ComputeHash();
}
void CMaterial::SetEmissive(const SMaterialColor &color)
void CMaterial::SetEmissive(const SMaterialColor& color)
{
m_Emissive = color;
ComputeHash();

View File

@ -21,7 +21,7 @@ public:
b = _b;
a = _a;
}
SMaterialColor(const SMaterialColor &color)
SMaterialColor(const SMaterialColor& color)
{
r = color.r;
g = color.g;
@ -29,14 +29,14 @@ public:
a = color.a;
}
void operator =(const SMaterialColor color)
void operator=(const SMaterialColor& color)
{
r = color.r;
g = color.g;
b = color.b;
a = color.a;
}
bool operator ==(const SMaterialColor color);
bool operator==(const SMaterialColor& color);
float Sum()
{
@ -48,7 +48,7 @@ class CMaterial
{
public:
CMaterial();
CMaterial(const CMaterial &material);
CMaterial(const CMaterial& material);
virtual ~CMaterial();
void Bind();
@ -81,15 +81,15 @@ public:
void SetTexture(const CStr& texture);
void SetVertexProgram(const CStr& prog);
void SetFragmentProgram(const CStr& prog);
void SetDiffuse(const SMaterialColor &color);
void SetAmbient(const SMaterialColor &color);
void SetSpecular(const SMaterialColor &color);
void SetEmissive(const SMaterialColor &color);
void SetDiffuse(const SMaterialColor& color);
void SetAmbient(const SMaterialColor& color);
void SetSpecular(const SMaterialColor& color);
void SetEmissive(const SMaterialColor& color);
void SetSpecularPower(float power);
void SetUsesAlpha(bool flag);
void operator =(const CMaterial &material);
bool operator ==(const CMaterial &material);
void operator=(const CMaterial& material);
bool operator==(const CMaterial& material);
protected:
void ComputeHash();

View File

@ -13,11 +13,11 @@ static float ClampFloat(float value, float min, float max)
return value;
}
static SMaterialColor ParseColor(CStr colorStr)
static SMaterialColor ParseColor(const CStr& colorStr_)
{
SMaterialColor color;
colorStr = colorStr.Trim(PS_TRIM_BOTH);
CStr colorStr(colorStr_.Trim(PS_TRIM_BOTH));
CStr tmp;
int idx = 0;
long pos = colorStr.Find(' ');

View File

@ -160,10 +160,10 @@ static LibError GetObjectName_ThunkCb(const VfsPath& pathname, const FileInfo& U
void CObjectManager::GetAllObjectNames(std::vector<CStr>& names)
{
fs_ForEachFile(g_VFS, "art/actors/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE);
(void)fs_ForEachFile(g_VFS, "art/actors/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE);
}
void CObjectManager::GetPropObjectNames(std::vector<CStr>& names)
{
fs_ForEachFile(g_VFS, "art/actors/props/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE);
(void)fs_ForEachFile(g_VFS, "art/actors/props/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE);
}

View File

@ -38,9 +38,9 @@ void CPatch::Initialize(CTerrain* parent,ssize_t x,ssize_t z)
m_Z=z;
// set parent of each patch
for (size_t j=0;j<PATCH_SIZE;j++)
for (ssize_t j=0;j<PATCH_SIZE;j++)
{
for (size_t i=0;i<PATCH_SIZE;i++)
for (ssize_t i=0;i<PATCH_SIZE;i++)
{
m_MiniPatches[j][i].m_Parent=this;
}

View File

@ -47,7 +47,7 @@ void CSprite::Render()
glDisable(GL_CULL_FACE);
if ( m_texture && m_texture->GetHandle() != 0 )
ogl_tex_bind(m_texture->GetHandle());
(void)ogl_tex_bind(m_texture->GetHandle());
glColor4fv(m_colour);

View File

@ -27,7 +27,7 @@ CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent):
m_Groups = m_pParent->m_Groups;
}
CTerrainPropertiesPtr CTerrainProperties::FromXML(CTerrainPropertiesPtr parent, const char* path)
CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& parent, const char* path)
{
CXeromyces XeroFile;
if (XeroFile.Load(path) != PSRETURN_OK)

View File

@ -66,7 +66,7 @@ public:
// Create a new object and load the XML file specified. Returns NULL upon
// failure
// The parent pointer may be NULL, for the "root" terrainproperties object.
static CTerrainPropertiesPtr FromXML(CTerrainPropertiesPtr parent, const char* path);
static CTerrainPropertiesPtr FromXML(const CTerrainPropertiesPtr& parent, const char* path);
// Save the object to an XML file. Implement when needed! ;-)
// bool WriteXML(const CStr& path);

View File

@ -54,7 +54,7 @@ CTextureEntry::~CTextureEntry()
m_LoadedTextures.erase(it);
if (m_Handle > 0)
ogl_tex_free(m_Handle);
(void)ogl_tex_free(m_Handle);
for (GroupVector::iterator it=m_Groups.begin();it!=m_Groups.end();++it)
(*it)->RemoveTerrain(this);
@ -87,7 +87,8 @@ void CTextureEntry::BuildBaseColor()
return;
}
ogl_tex_bind(GetHandle());
LibError ret = ogl_tex_bind(GetHandle());
debug_assert(ret == INFO::OK);
// get root colour for coloring minimap by querying root level of the texture
// (this should decompress any compressed textures for us),

View File

@ -42,8 +42,9 @@ void CTextureManager::UnloadTerrainTextures()
m_LastGroupIndex = 0;
}
CTextureEntry* CTextureManager::FindTexture(CStr tag)
CTextureEntry* CTextureManager::FindTexture(const CStr& tag_)
{
CStr tag(tag_);
// Strip extension off of tag
long pos=tag.ReverseFind(".");
if (pos != -1)
@ -65,12 +66,12 @@ CTextureEntry* CTextureManager::FindTexture(Handle handle)
return CTextureEntry::GetByHandle(handle);
}
CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(CTerrainPropertiesPtr props, const char* path)
CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(const CTerrainPropertiesPtr& props, const char* path)
{
return CTerrainProperties::FromXML(props, path);
}
CTextureEntry *CTextureManager::AddTexture(CTerrainPropertiesPtr props, const CStr& path)
CTextureEntry *CTextureManager::AddTexture(const CTerrainPropertiesPtr& props, const CStr& path)
{
CTextureEntry *entry = new CTextureEntry(props, path);
m_TextureEntries.push_back(entry);
@ -93,7 +94,7 @@ void CTextureManager::DeleteTexture(CTextureEntry* entry)
// jw: indeed this is inefficient and RecurseDirectory should be implemented
// via VFSUtil::EnumFiles, but it works fine and "only" takes 25ms for
// typical maps. therefore, we'll leave it for now.
void CTextureManager::LoadTextures(CTerrainPropertiesPtr props, const char* dir)
void CTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, const char* dir)
{
VfsPaths pathnames;
if(fs_GetPathnames(g_VFS, dir, 0, pathnames) < 0)
@ -134,7 +135,7 @@ void CTextureManager::LoadTextures(CTerrainPropertiesPtr props, const char* dir)
}
}
void CTextureManager::RecurseDirectory(CTerrainPropertiesPtr parentProps, const char* cur_dir_path)
void CTextureManager::RecurseDirectory(const CTerrainPropertiesPtr& parentProps, const char* cur_dir_path)
{
//LOG(CLogger::Normal, LOG_CATEGORY, "CTextureManager::RecurseDirectory(%s)", path.c_str());
@ -157,7 +158,7 @@ void CTextureManager::RecurseDirectory(CTerrainPropertiesPtr parentProps, const
// Recurse once for each subdirectory
DirectoryNames subdirectoryNames;
g_VFS->GetDirectoryEntries(cur_dir_path, 0, &subdirectoryNames);
(void)g_VFS->GetDirectoryEntries(cur_dir_path, 0, &subdirectoryNames);
for (size_t i=0;i<subdirectoryNames.size();i++)
{
char subdirectoryPath[PATH_MAX];

View File

@ -67,12 +67,12 @@ private:
// Find+load all textures in directory; check if
// there's an override XML with the same basename (if there is, load it)
void LoadTextures(CTerrainPropertiesPtr props, const char* dir);
void LoadTextures(const CTerrainPropertiesPtr& props, const char* dir);
// Load all terrains below path, using props as the parent property sheet.
void RecurseDirectory(CTerrainPropertiesPtr props, const char* dir);
void RecurseDirectory(const CTerrainPropertiesPtr& props, const char* dir);
CTerrainPropertiesPtr GetPropertiesFromFile(CTerrainPropertiesPtr props, const char* path);
CTerrainPropertiesPtr GetPropertiesFromFile(const CTerrainPropertiesPtr& props, const char* path);
public:
// constructor, destructor
@ -85,12 +85,12 @@ public:
void UnloadTerrainTextures();
CTextureEntry* FindTexture(CStr tag);
CTextureEntry* FindTexture(const CStr& tag);
CTextureEntry* FindTexture(Handle handle);
// Create a texture object for a new terrain texture at path, using the
// property sheet props.
CTextureEntry *AddTexture(CTerrainPropertiesPtr props, const CStr& path);
CTextureEntry *AddTexture(const CTerrainPropertiesPtr& props, const CStr& path);
// Remove the texture from all our maps and lists and delete it afterwards.
void DeleteTexture(CTextureEntry* entry);

View File

@ -17,7 +17,7 @@
#include "lib/path_util.h"
#include "lib/regex.h"
LibError fs_GetPathnames(PIVFS fs, const VfsPath& path, const char* filter, VfsPaths& pathnames)
LibError fs_GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames)
{
std::vector<FileInfo> files;
RETURN_ERR(fs->GetDirectoryEntries(path, &files, 0));
@ -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, int flags)
LibError fs_ForEachFile(const 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, size_t& nextNumber, VfsPath& nextPathname)
void fs_NextNumberedFilename(const 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

View File

@ -16,7 +16,7 @@
extern void fs_SortFiles(FileInfos& files);
extern void fs_SortDirectories(DirectoryNames& directories);
extern LibError fs_GetPathnames(PIVFS fs, const VfsPath& path, const char* filter, VfsPaths& pathnames);
extern LibError fs_GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames);
/**
@ -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, int flags = 0);
extern LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, int flags = 0);
/**
@ -62,6 +62,6 @@ extern LibError fs_ForEachFile(PIVFS fs, const VfsPath& path, FileCallback cb, u
* if 0, numbers corresponding to existing files are skipped.
* @param nextPathname receives the output.
**/
extern void fs_NextNumberedFilename(PIVFS fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname);
extern void fs_NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname);
#endif // #ifndef INCLUDED_FILE_SYSTEM_UTIL

View File

@ -189,7 +189,7 @@ void VfsDirectory::ClearR()
}
void VfsDirectory::Attach(PRealDirectory realDirectory)
void VfsDirectory::Attach(const PRealDirectory& realDirectory)
{
if(!cpu_CAS(&m_shouldPopulate, 0, 1))
{

View File

@ -78,7 +78,7 @@ public:
void ClearR();
void Attach(PRealDirectory realDirectory);
void Attach(const PRealDirectory& realDirectory);
PRealDirectory AssociatedDirectory() const
{

View File

@ -132,7 +132,7 @@ private:
const int vote = (value >= m_history[i])? 1 : -1;
sum += vote;
}
return abs(sum) == m_historySize;
return abs(sum) == (int)m_historySize;
}
static double Change(double from, double to)

View File

@ -76,7 +76,7 @@ char* error_description_r(LibError err, char* buf, size_t max_chars)
}
// unknown
snprintf(buf, max_chars, "Unknown error (%d, 0x%X)", err, err);
snprintf(buf, max_chars, "Unknown error (%d, 0x%X)", (int)err, (unsigned int)err);
return buf;
}

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, int flags)
void path_append(char* dst, const char* path1, const char* path2, int flags)
{
const size_t len1 = strlen(path1);
const size_t len2 = strlen(path2);
@ -189,7 +189,11 @@ LibError path_append(char* dst, const char* path1, const char* path2, int flags)
}
if(total_len > PATH_MAX)
WARN_RETURN(ERR::PATH_LENGTH);
{
DEBUG_WARN_ERR(ERR::PATH_LENGTH);
*dst = 0;
return;
}
SAFE_STRCPY(dst, path1);
dst += len1;
@ -198,8 +202,6 @@ LibError path_append(char* dst, const char* path1, const char* path2, int flags)
SAFE_STRCPY(dst, path2);
if(need_terminator)
SAFE_STRCPY(dst+len2, "/");
return INFO::OK;
}

View File

@ -104,9 +104,8 @@ enum PathAppendFlags
* @param path1, path2 strings: empty, filenames, or full paths.
* total resulting string must not exceed PATH_MAX chars.
* @param flags see PathAppendFlags.
* @return LibError
**/
extern LibError path_append(char* dst, const char* path1, const char* path2, int flags = 0);
extern void path_append(char* dst, const char* path1, const char* path2, int flags = 0);
/**
* get the name component of a path.

View File

@ -7,7 +7,7 @@
#define TEST_APPEND(path1, path2, flags, correct_result) \
{ \
char dst[PATH_MAX] = {0}; \
TS_ASSERT_OK(path_append(dst, path1, path2, flags)); \
path_append(dst, path1, path2, flags); \
TS_ASSERT_STR_EQUALS(dst, correct_result); \
}

View File

@ -24,7 +24,6 @@
#include "simulation/Simulation.h"
// DECLARATIONS
#pragma warning( disable : 4100 )
#define LOG_CAT_NET "net"
@ -130,7 +129,7 @@ void CNetClient::ScriptingInit()
// Name: Run()
// Desc: Connect to server and start main loop
//-----------------------------------------------------------------------------
bool CNetClient::SetupConnection( JSContext* pContext, uintN argc, jsval* argv )
bool CNetClient::SetupConnection( JSContext* UNUSED(pContext), uintN argc, jsval* argv )
{
uint port = DEFAULT_HOST_PORT;
@ -340,6 +339,7 @@ bool CNetClient::OnAuthenticate( void* pContext, CFsmEvent* pEvent )
if ( !pEvent || !pContext ) return false;
CNetClient* pClient = ( CNetClient* )( ( FsmActionCtx* )pContext )->pHost;
UNUSED2(pClient);
CNetSession* pSession = ( ( FsmActionCtx* )pContext )->pSession;
assert( pClient );

View File

@ -17,8 +17,6 @@
// DECLARATIONS
#pragma warning( disable : 4100 )
CNetServer* g_NetServer = NULL;
//-----------------------------------------------------------------------------
@ -97,7 +95,7 @@ void CNetServer::ScriptingInit( void )
// Name: Start()
// Desc: Initialize the server
//-----------------------------------------------------------------------------
bool CNetServer::Start( JSContext* pContext, uintN argc, jsval* argv )
bool CNetServer::Start( JSContext* UNUSED(pContext), uintN UNUSED(argc), jsval* UNUSED(argv) )
{
// Setup initial state
m_State = SERVER_STATE_PREGAME;
@ -378,7 +376,9 @@ bool CNetServer::OnError( void* pContext, CFsmEvent* pEvent )
if ( pEvent->GetType() != NMT_ERROR ) return true;
CNetServer* pServer = ( CNetServer* )( ( FsmActionCtx* )pContext )->pHost;
UNUSED2(pServer);
CNetSession* pSession = ( ( FsmActionCtx* )pContext )->pSession;
UNUSED2(pSession);
CErrorMessage* pMessage = ( CErrorMessage* )pEvent->GetParamRef();
if ( pMessage )

View File

@ -13,8 +13,6 @@
//#include "NetServer.h"
#include "NetLog.h"
#pragma warning( disable : 4100 )
// DECLARATIONS
//-----------------------------------------------------------------------------
@ -447,7 +445,7 @@ void CNetHost::Broadcast( const CNetMessage* pMessage )
// Name: ResizeBuffer()
// Desc: Resizes the internal buffer
//-----------------------------------------------------------------------------
void CNetHost::ResizeBuffer( uint size )
void CNetHost::ResizeBuffer( size_t size )
{
// Already enough space?
if ( size <= m_BufferSize ) return;
@ -486,7 +484,7 @@ bool CNetHost::SendMessage(
assert( pSession->m_Peer );
assert( m_Host );
uint size = pMessage->GetSerializedLength();
size_t size = pMessage->GetSerializedLength();
// Adjust buffer for message
ResizeBuffer( size );
@ -546,7 +544,7 @@ CNetMessage* CNetHost::ReceiveMessage( const CNetSession* pSession )
// Name: SetupSession()
// Desc: Setup new session upon creation
//-----------------------------------------------------------------------------
bool CNetHost::SetupSession( CNetSession* pSession )
bool CNetHost::SetupSession( CNetSession* UNUSED(pSession) )
{
return true;
}
@ -555,7 +553,7 @@ bool CNetHost::SetupSession( CNetSession* pSession )
// Name: HandleConnect()
// Desc: Allow application to handle client connect
//-----------------------------------------------------------------------------
bool CNetHost::HandleConnect( CNetSession* pSession )
bool CNetHost::HandleConnect( CNetSession* UNUSED(pSession) )
{
return true;
}
@ -564,7 +562,7 @@ bool CNetHost::HandleConnect( CNetSession* pSession )
// Name: HandleDisconnect()
// Desc: Allow application to handle client disconnect
//-----------------------------------------------------------------------------
bool CNetHost::HandleDisconnect( CNetSession* pSession )
bool CNetHost::HandleDisconnect( CNetSession* UNUSED(pSession) )
{
return true;
}
@ -726,7 +724,7 @@ void CNetSession::ScriptingInit( void )
// Name: JSI_Close()
// Desc:
//-----------------------------------------------------------------------------
bool CNetSession::JSI_Close( JSContext* cx, uintN argc, jsval* argv )
bool CNetSession::JSI_Close( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
{
return false;
}

View File

@ -143,7 +143,7 @@ protected:
*
* @param size The new size for the buffer
*/
void ResizeBuffer( uint size );
void ResizeBuffer( size_t size );
// Allow application to handle new client connect
virtual bool SetupSession ( CNetSession* pSession );
@ -168,7 +168,7 @@ private:
CNetHost& operator=( const CNetHost& );
u8* m_Buffer; // Serialize out messages buffer
uint m_BufferSize; // Output buffer size
size_t m_BufferSize; // Output buffer size
ENetHost* m_Host; // Represents this host
PeerSessionList m_PeerSessions; // Session list of connected peers
//pthread_t m_WorkerID; // Worker thread

View File

@ -81,14 +81,12 @@ struct DurationAdder: public std::binary_function<double, const LoadRequest&, do
// this routine is provided so we can prevent 2 simultaneous load operations,
// which is bogus. that can happen by clicking the load button quickly,
// or issuing via console while already loading.
LibError LDR_BeginRegistering()
void LDR_BeginRegistering()
{
if(state != IDLE)
return ERR::LOGIC;
debug_assert(state == IDLE);
state = REGISTERING;
load_requests.clear();
return INFO::OK;
}
@ -100,56 +98,43 @@ LibError LDR_BeginRegistering()
// <estimated_duration_ms>: used to calculate progress, and when checking
// whether there is enough of the time budget left to process this task
// (reduces timeslice overruns, making the main loop more responsive).
LibError LDR_Register(LoadFunc func, void* param, const wchar_t* description,
void LDR_Register(LoadFunc func, void* param, const wchar_t* description,
int estimated_duration_ms)
{
if(state != REGISTERING)
{
debug_warn("not called between LDR_(Begin|End)Register - why?!");
// warn here instead of relying on the caller to CHECK_ERR because
// there will be lots of call sites spread around.
return ERR::LOGIC;
}
debug_assert(state == REGISTERING); // must be called between LDR_(Begin|End)Register
const LoadRequest lr(func, param, description, estimated_duration_ms);
load_requests.push_back(lr);
return INFO::OK;
}
// call when finished registering tasks; subsequent calls to
// LDR_ProgressiveLoad will then work off the queued entries.
LibError LDR_EndRegistering()
void LDR_EndRegistering()
{
if(state != REGISTERING)
return ERR::LOGIC;
if(load_requests.empty())
debug_warn("no LoadRequests queued");
debug_assert(state == REGISTERING);
debug_assert(!load_requests.empty());
state = FIRST_LOAD;
estimated_duration_tally = 0.0;
task_elapsed_time = 0.0;
total_estimated_duration = std::accumulate(load_requests.begin(), load_requests.end(), 0.0, DurationAdder());
return INFO::OK;
}
// immediately cancel this load; no further tasks will be processed.
// used to abort loading upon user request or failure.
// note: no special notification will be returned by LDR_ProgressiveLoad.
LibError LDR_Cancel()
void LDR_Cancel()
{
// note: calling during registering doesn't make sense - that
// should be an atomic sequence of begin, register [..], end.
if(state != LOADING)
return ERR::LOGIC;
debug_assert(state == LOADING);
state = IDLE;
// the queue doesn't need to be emptied now; that'll happen during the
// next LDR_StartRegistering. for now, it is sufficient to set the
// state, so that LDR_ProgressiveLoad is a no-op.
return INFO::OK;
state = IDLE;
}

View File

@ -84,7 +84,7 @@ registering member functions, which would otherwise be messy.
// this routine is provided so we can prevent 2 simultaneous load operations,
// which is bogus. that can happen by clicking the load button quickly,
// or issuing via console while already loading.
extern LibError LDR_BeginRegistering();
extern void LDR_BeginRegistering();
// callback function of a task; performs the actual work.
@ -109,19 +109,19 @@ typedef int (*LoadFunc)(void* param, double time_left);
// <estimated_duration_ms>: used to calculate progress, and when checking
// whether there is enough of the time budget left to process this task
// (reduces timeslice overruns, making the main loop more responsive).
extern LibError LDR_Register(LoadFunc func, void* param, const wchar_t* description,
extern void LDR_Register(LoadFunc func, void* param, const wchar_t* description,
int estimated_duration_ms);
// call when finished registering tasks; subsequent calls to
// LDR_ProgressiveLoad will then work off the queued entries.
extern LibError LDR_EndRegistering();
extern void LDR_EndRegistering();
// immediately cancel this load; no further tasks will be processed.
// used to abort loading upon user request or failure.
// note: no special notification will be returned by LDR_ProgressiveLoad.
extern LibError LDR_Cancel();
extern void LDR_Cancel();
// process as many of the queued tasks as possible within <time_budget> [s].

View File

@ -46,7 +46,7 @@ template<class T> void RegMemFun(T* this_, int(T::*func)(void),
const wchar_t* description, int estimated_duration_ms)
{
void* param = new MemFun_t<T>(this_, func);
THROW_ERR(LDR_Register(MemFunThunk<T>, param, description, estimated_duration_ms));
LDR_Register(MemFunThunk<T>, param, description, estimated_duration_ms);
}
@ -75,5 +75,5 @@ template<class T, class Arg> void RegMemFun1(T* this_, int(T::*func)(Arg), Arg a
const wchar_t* description, int estimated_duration_ms)
{
void* param = new MemFun1_t<T, Arg>(this_, func, arg);
THROW_ERR(LDR_Register(MemFun1Thunk<T, Arg>, param, description, estimated_duration_ms));
LDR_Register(MemFun1Thunk<T, Arg>, param, description, estimated_duration_ms);
}

View File

@ -121,7 +121,7 @@ public:
XMLWriter_Element(XMLWriter_File& file, const char* name);
~XMLWriter_Element();
template <typename T> void Text(T text);
template <typename constCharPtr> void Text(constCharPtr text);
template <typename T> void Attribute(const char* name, T value) { m_File->ElementAttribute(name, value, false); }
template <typename T> void Setting(const char* name, T value) { m_File->ElementAttribute(name, value, true); }
void Close(int type);

View File

@ -533,12 +533,12 @@ void TerrainRenderer::RenderWater()
{
CPatch* patch = m->visiblePatches[i];
for(int dx=0; dx<PATCH_SIZE; dx++)
for(ssize_t dx=0; dx<PATCH_SIZE; dx++)
{
for(int dz=0; dz<PATCH_SIZE; dz++)
for(ssize_t dz=0; dz<PATCH_SIZE; dz++)
{
int x = (patch->m_X*PATCH_SIZE + dx);
int z = (patch->m_Z*PATCH_SIZE + dz);
ssize_t x = (patch->m_X*PATCH_SIZE + dx);
ssize_t z = (patch->m_Z*PATCH_SIZE + dz);
// is any corner of the tile below the water height? if not, no point rendering it
bool shouldRender = false;

View File

@ -814,7 +814,7 @@ void CEntity::PopOrder()
m_orderQueue.pop_front();
}
void CEntity::PushOrder( CEntityOrder& order )
void CEntity::PushOrder( const CEntityOrder& order )
{
CEventPrepareOrder evt( order.m_target_entity, order.m_type, order.m_action, order.m_produce_name );
if( DispatchEvent(&evt) )
@ -827,7 +827,7 @@ void CEntity::PushOrder( CEntityOrder& order )
}
}
void CEntity::DispatchNotification( CEntityOrder order, int type )
void CEntity::DispatchNotification( const CEntityOrder& order, int type )
{
CEventNotification evt( order, type );
DispatchEvent( &evt );

View File

@ -374,9 +374,9 @@ public:
void ClearOrders();
void PopOrder(); //Use this if an order has finished instead of m_orderQueue.pop_front()
void PushOrder( CEntityOrder& order );
void PushOrder( const CEntityOrder& order );
void DispatchNotification( CEntityOrder order, int type );
void DispatchNotification( const CEntityOrder& order, int type );
int DestroyNotifier( CEntity* target ); //Stop notifier from sending to us
void DestroyAllNotifiers();

View File

@ -108,7 +108,7 @@ CEventOrderTransition::CEventOrderTransition( int orderPrevious, int orderCurren
AddLocalProperty( L"target", &m_target );
AddLocalProperty( L"position", &m_worldPosition );
}
CEventNotification::CEventNotification( CEntityOrder order, int notifyType ) : CScriptEvent( L"notification", EVENT_NOTIFICATION, true )
CEventNotification::CEventNotification( const CEntityOrder& order, int notifyType ) : CScriptEvent( L"notification", EVENT_NOTIFICATION, true )
{
m_notifyType = notifyType;
m_target = order.m_target_entity;
@ -124,7 +124,7 @@ CFormationEvent::CFormationEvent( int type ) : CScriptEvent( L"formationEvent",
(int&) m_formationEvent = type;
AddLocalProperty( L"formationEvent", &m_formationEvent );
}
CIdleEvent::CIdleEvent( CEntityOrder order, int notifyType ) : CScriptEvent( L"idleEvent", EVENT_IDLE, false )
CIdleEvent::CIdleEvent( const CEntityOrder& order, int notifyType ) : CScriptEvent( L"idleEvent", EVENT_IDLE, false )
{
m_notifyType = notifyType;
m_orderType = order.m_type;

View File

@ -120,7 +120,7 @@ class CEventNotification : public CScriptEvent
int m_notifyType;
CVector3D m_location; //No real use for y, but CVector2D unsupported
public:
CEventNotification( CEntityOrder order, int notifyType );
CEventNotification( const CEntityOrder& order, int notifyType );
};
class CFormationEvent : public CScriptEvent
{
@ -147,6 +147,6 @@ class CIdleEvent : public CScriptEvent
CVector3D m_location;
CEntity* m_target;
public:
CIdleEvent( CEntityOrder order, int notifyType );
CIdleEvent( const CEntityOrder& order, int notifyType );
};
#endif

View File

@ -193,7 +193,7 @@ void CSimulation::Simulate()
// Task them all to a point within a radius of the target, radius depends upon
// the number of units in the group.
void RandomizeLocations(CEntityOrder order, const std::vector<HEntity> &entities, bool isQueued)
void RandomizeLocations(const CEntityOrder& order, const std::vector<HEntity> &entities, bool isQueued)
{
std::vector<HEntity>::const_iterator it;
float radius = 2.0f * sqrt( (float)entities.size() - 1 );
@ -226,7 +226,7 @@ void RandomizeLocations(CEntityOrder order, const std::vector<HEntity> &entities
}
}
void FormationLocations(CEntityOrder order, const std::vector<HEntity> &entities, bool isQueued)
void FormationLocations(const CEntityOrder& order, const std::vector<HEntity> &entities, bool isQueued)
{
CVector2D upvec(0.0f, 1.0f);
std::vector<HEntity>::const_iterator it = entities.begin();
@ -261,7 +261,7 @@ void FormationLocations(CEntityOrder order, const std::vector<HEntity> &entities
}
}
void QueueOrder(CEntityOrder order, const std::vector<HEntity> &entities, bool isQueued)
void QueueOrder(const CEntityOrder& order, const std::vector<HEntity> &entities, bool isQueued)
{
std::vector<HEntity>::const_iterator it;

View File

@ -62,7 +62,7 @@ struct MapTrigger
struct MapTriggerGroup
{
MapTriggerGroup() { }
MapTriggerGroup(CStrW _name, CStrW _parentName) : name(_name), parentName(_parentName) {}
MapTriggerGroup(const CStrW& _name, const CStrW& _parentName) : name(_name), parentName(_parentName) {}
std::list<MapTrigger> triggers;
std::list<CStrW> childGroups; //Indices of children

View File

@ -26,12 +26,12 @@ JSI_Sound::JSI_Sound(const CStr& Filename)
if (m_Handle < 0)
throw std::exception(); // caught by JSI_Sound::Construct.
snd_set_pos(m_Handle, 0,0,0, true);
(void)snd_set_pos(m_Handle, 0,0,0, true);
}
JSI_Sound::~JSI_Sound()
{
this->Free(0, 0, 0);
(void)this->Free(0, 0, 0);
}
@ -45,7 +45,7 @@ bool JSI_Sound::SetGain(JSContext* cx, uintN argc, jsval* argv)
if (! ToPrimitive<float>(cx, argv[0], gain))
return false;
snd_set_gain(m_Handle, gain);
(void)snd_set_gain(m_Handle, gain);
return true;
}
@ -59,7 +59,7 @@ bool JSI_Sound::SetPitch(JSContext* cx, uintN argc, jsval* argv)
if (! ToPrimitive<float>(cx, argv[0], pitch))
return false;
snd_set_pitch(m_Handle, pitch);
(void)snd_set_pitch(m_Handle, pitch);
return true;
}
@ -73,11 +73,11 @@ bool JSI_Sound::SetPosition(JSContext* cx, uintN argc, jsval* argv)
CVector3D pos;
// absolute world coords
if (ToPrimitive<CVector3D>(cx, argv[0], pos))
snd_set_pos(m_Handle, pos[0], pos[1], pos[2]);
(void)snd_set_pos(m_Handle, pos[0], pos[1], pos[2]);
// relative, 0 offset - right on top of the listener
// (we don't need displacement from the listener, e.g. always behind)
else
snd_set_pos(m_Handle, 0,0,0, true);
(void)snd_set_pos(m_Handle, 0,0,0, true);
return true;
}
@ -96,7 +96,7 @@ bool JSI_Sound::Fade(JSContext* cx, uintN argc, jsval* argv)
&& ToPrimitive<float>(cx, argv[2], length)))
return false;
snd_fade(m_Handle, initial_gain, final_gain, length, FT_S_CURVE);
(void)snd_fade(m_Handle, initial_gain, final_gain, length, FT_S_CURVE);
// HACK: snd_fade causes <m_Handle> to be automatically freed when a
// fade to 0 has completed. however, we're still holding on to a
@ -116,7 +116,7 @@ bool JSI_Sound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(ar
if (! m_Handle)
return false;
snd_play(m_Handle);
(void)snd_play(m_Handle);
// We can't do anything else with this sound now, since it's impossible to
// know whether or not it's still valid (since it might have finished playing
// already). So set it to 0, so we don't try doing anything (like freeing it)
@ -131,8 +131,8 @@ bool JSI_Sound::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(ar
if (! m_Handle)
return false;
snd_set_loop(m_Handle, true);
snd_play(m_Handle);
(void)snd_set_loop(m_Handle, true);
(void)snd_play(m_Handle);
return true;
}
@ -144,7 +144,7 @@ bool JSI_Sound::Free(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(ar
if (! m_Handle)
return false;
snd_free(m_Handle); // resets it to 0
(void)snd_free(m_Handle); // resets it to 0
return true;
}

View File

@ -82,9 +82,9 @@ ActorViewer::ActorViewer()
if (tex)
{
CPatch* patch = m.Terrain.GetPatch(0, 0);
for (int i = 0; i < PATCH_SIZE; ++i)
for (ssize_t i = 0; i < PATCH_SIZE; ++i)
{
for (int j = 0; j < PATCH_SIZE; ++j)
for (ssize_t j = 0; j < PATCH_SIZE; ++j)
{
CMiniPatch& mp = patch->m_MiniPatches[i][j];
mp.Tex1 = tex->GetHandle();

View File

@ -98,9 +98,9 @@ MESSAGEHANDLER(GenerateMap)
{
CPatch* patch = terrain->GetPatch(px, pz);
for (int z = 0; z < PATCH_SIZE; ++z)
for (ssize_t z = 0; z < PATCH_SIZE; ++z)
{
for (int x = 0; x < PATCH_SIZE; ++x)
for (ssize_t x = 0; x < PATCH_SIZE; ++x)
{
patch->m_MiniPatches[z][x].Tex1 = tex;
patch->m_MiniPatches[z][x].Tex1Priority = 0;