warning fixes: mostly size_t vs. specialized API type and other type conversion.

added player_id_t typedef and INVALID_PLAYER, use that instead of -1.
also added sanity checks to cpu.cpp to ensure ARCH_* is correct (see
http://www.wildfiregames.com/forum/index.php?showtopic=13327&hl=)
and further predefined macros to arch.h just to be sure.

This was SVN commit r8079.
This commit is contained in:
janwas 2010-09-05 09:38:30 +00:00
parent 178d45d0e2
commit 2e7436434d
29 changed files with 110 additions and 71 deletions

View File

@ -200,7 +200,7 @@ void Skeleton::LoadSkeletonDataFromXml(const char* xmlData, size_t xmlLength, st
try
{
xmlSetGenericErrorFunc(&xmlErrors, &errorHandler);
doc = xmlParseMemory(xmlData, xmlLength);
doc = xmlParseMemory(xmlData, (int)xmlLength);
if (doc)
{
xmlNode* root = xmlDocGetRootElement(doc);

View File

@ -410,9 +410,9 @@ void CXMLReader::ReadPlayers()
// TODO: we ought to read at least some of this data from the map file.
// For now, just always use the defaults.
std::map<int, CStrW> playerDefaultNames;
std::map<int, CStrW> playerDefaultCivs;
std::map<int, SColor3ub> playerDefaultColours;
std::map<player_id_t, CStrW> playerDefaultNames;
std::map<player_id_t, CStrW> playerDefaultCivs;
std::map<player_id_t, SColor3ub> playerDefaultColours;
CXeromyces playerDefaultFile;
if (playerDefaultFile.Load(g_VFS, L"simulation/data/players.xml") != PSRETURN_OK)
@ -440,9 +440,9 @@ void CXMLReader::ReadPlayers()
playerDefaultColours[id] = colour;
}
size_t numPlayers = 9; // including Gaia
player_id_t numPlayers = 9; // including Gaia
for (size_t i = 0; i < numPlayers; ++i)
for (player_id_t i = 0; i < numPlayers; ++i)
{
int uid = ++max_uid;
entity_id_t ent = m_MapReader.pSimulation2->AddEntity(L"special/player", uid);

View File

@ -29,7 +29,7 @@
CUnit::CUnit(CObjectEntry* object, CObjectManager& objectManager,
const std::set<CStr>& actorSelections)
: m_Object(object), m_Model(object->m_Model->Clone()),
m_ID(invalidUnitId), m_ActorSelections(actorSelections),
m_ID(INVALID_ENTITY), m_ActorSelections(actorSelections),
m_ObjectManager(objectManager)
{
m_Animation = new CUnitAnimation(*this);

View File

@ -21,6 +21,7 @@
#include <set>
#include "ps/CStr.h"
#include "simulation2/system/Entity.h" // entity_id_t
class CModel;
class CObjectEntry;
@ -28,13 +29,6 @@ class CObjectManager;
class CSkeletonAnim;
class CUnitAnimation;
// note: we can't declare as static const size_t invalidId = ~size_t(0) in
// the class because it seems to be a grey area in the C++ standard whether
// or not the constant is propagated or needs an external definition.
// an enum causes conversion warnings in MSC, so we go with a file-scope
// constant.
const size_t invalidUnitId = ~size_t(0);
/////////////////////////////////////////////////////////////////////////////////////////////
// CUnit: simple "actor" definition - defines a sole object within the world
@ -75,8 +69,8 @@ public:
// 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.
size_t GetID() const { return m_ID; }
void SetID(size_t id) { m_ID = id; }
entity_id_t GetID() const { return m_ID; }
void SetID(entity_id_t id) { m_ID = id; }
const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; }
@ -91,8 +85,8 @@ private:
CUnitAnimation* m_Animation;
// unique (per map) ID number for units created in the editor, as a
// permanent way of referencing them. ~0 for non-editor units.
size_t m_ID;
// permanent way of referencing them.
entity_id_t m_ID;
// actor-level selections for this unit
std::set<CStr> m_ActorSelections;

View File

@ -47,7 +47,7 @@ public:
TS_ASSERT_EQUALS(read_le32(buf), (u32)0x78563412); // read correct value
debug_SkipErrors(ERR::FAIL);
TS_ASSERT(da_read(&da, buf, 1) < 0); // no more data left
TS_ASSERT_EQUALS(debug_StopSkippingErrors(), (size_t)1);
TS_ASSERT_EQUALS((uint32_t)debug_StopSkippingErrors(), (uint32_t)1);
TS_ASSERT_OK(da_free(&da));
}

View File

@ -29,7 +29,7 @@
// detect target CPU architecture via predefined macros
// .. IA-32
#if defined(_M_IX86) || defined(i386) || defined(_X86_)
#if defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__i386__) || defined(__i386) || defined(i386)
# define ARCH_IA32 1
#else
# define ARCH_IA32 0
@ -41,7 +41,7 @@
# define ARCH_IA64 0
#endif
// .. AMD64
#if defined(_M_X64) || defined(__amd64__) || defined(__amd64)
#if defined(_M_X64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
# define ARCH_AMD64 1
#else
# define ARCH_AMD64 0

View File

@ -32,6 +32,19 @@ ERROR_ASSOCIATE(ERR::CPU_UNKNOWN_OPCODE, L"Disassembly failed", -1);
ERROR_ASSOCIATE(ERR::CPU_UNKNOWN_VENDOR, L"CPU vendor unknown", -1);
// ensure the actual pointer size matches expectations on the most common
// architectures (IA-32 and AMD64) - just in case the predefined macros
// are wrong or misleading.
#if ARCH_IA32
cassert(sizeof(void*) == 4);
#elif ARCH_AMD64
cassert(sizeof(void*) == 8);
cassert(sizeof(i64) == sizeof(intptr_t)); // required by cpu_CAS64
#endif
cassert(sizeof(void*) == sizeof(intptr_t));
static void TestCAS64()
{
volatile i64 var = 1;

View File

@ -601,6 +601,6 @@ CStrW CNetServer::DeduplicatePlayerName(const CStrW& original)
if (unique)
return name;
name = original + L" (" + CStrW(id++) + L")";
name = original + L" (" + CStrW((unsigned long)id++) + L")";
}
}

View File

@ -72,7 +72,7 @@ const std::vector<ProfileColumn>& CNetStatsTable::GetColumns()
if (m_Host)
{
for (size_t i = 0; i < m_Host->peerCount; ++i)
m_ColumnDescriptions.push_back(ProfileColumn("Peer "+CStr(i), 80));
m_ColumnDescriptions.push_back(ProfileColumn("Peer "+CStr((unsigned long)i), 80));
}
else if (m_Peer)
{

View File

@ -39,7 +39,7 @@
// does this return code indicate the coroutine yielded and
// wasn't yet finished?
static bool ldr_was_interrupted(int ret)
static inline bool ldr_was_interrupted(int ret)
{
return (0 < ret && ret <= 100);
}

View File

@ -44,7 +44,7 @@ bool RelaxNGValidator::LoadGrammar(const std::string& grammar)
debug_assert(m_Schema == NULL);
xmlRelaxNGParserCtxtPtr ctxt = xmlRelaxNGNewMemParserCtxt(grammar.c_str(), grammar.size());
xmlRelaxNGParserCtxtPtr ctxt = xmlRelaxNGNewMemParserCtxt(grammar.c_str(), (int)grammar.size());
m_Schema = xmlRelaxNGParse(ctxt);
xmlRelaxNGFreeParserCtxt(ctxt);
@ -69,7 +69,7 @@ bool RelaxNGValidator::Validate(const std::wstring& filename, const std::wstring
std::string docutf8 = "<?xml version='1.0' encoding='utf-8'?>" + utf8_from_wstring(document);
xmlDocPtr doc = xmlReadMemory(docutf8.c_str(), docutf8.size(), utf8_from_wstring(filename).c_str(), NULL, XML_PARSE_NONET);
xmlDocPtr doc = xmlReadMemory(docutf8.c_str(), (int)docutf8.size(), utf8_from_wstring(filename).c_str(), NULL, XML_PARSE_NONET);
if (doc == NULL)
{
LOGERROR(L"RelaxNGValidator: Failed to parse document");

View File

@ -73,7 +73,7 @@ void OverlayRenderer::RenderOverlays()
glLineWidth((float)line->m_Thickness);
glInterleavedArrays(GL_V3F, sizeof(float)*3, &line->m_Coords[0]);
glDrawArrays(GL_LINE_STRIP, 0, line->m_Coords.size()/3);
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)line->m_Coords.size()/3);
}
glLineWidth(1.f);

View File

@ -500,7 +500,7 @@ bool ScriptInterface::CallFunction_(jsval val, const char* name, size_t argc, js
return false;
}
JSBool ok = JS_CallFunctionName(m->m_cx, obj, name, argc, argv, &ret);
JSBool ok = JS_CallFunctionName(m->m_cx, obj, name, (uintN)argc, argv, &ret);
JS_RemoveRoot(m->m_cx, &obj);
return ok ? true : false;
@ -682,7 +682,7 @@ CScriptValRooted ScriptInterface::ParseJSON(const utf16string& string)
return CScriptValRooted();
}
if (!JS_ConsumeJSONText(m->m_cx, parser, string.c_str(), string.size()))
if (!JS_ConsumeJSONText(m->m_cx, parser, string.c_str(), (uint32)string.size()))
{
LOGERROR(L"ParseJSON failed to consume");
return CScriptValRooted();

View File

@ -73,7 +73,7 @@ public:
"</optional>";
}
virtual void Init(const CSimContext& context, const CParamNode& paramNode)
virtual void Init(const CSimContext& UNUSED(context), const CParamNode& paramNode)
{
m_Active = true;

View File

@ -35,7 +35,7 @@ public:
DEFAULT_COMPONENT_ALLOCATOR(Ownership)
int32_t m_Owner;
player_id_t m_Owner;
static std::string GetSchema()
{
@ -47,7 +47,7 @@ public:
virtual void Init(const CSimContext& UNUSED(context), const CParamNode& UNUSED(paramNode))
{
m_Owner = -1;
m_Owner = INVALID_PLAYER;
}
virtual void Deinit(const CSimContext& UNUSED(context))
@ -71,23 +71,23 @@ public:
case MT_Destroy:
{
// Reset the owner so this entity is e.g. removed from population counts
SetOwner(-1);
SetOwner(INVALID_PLAYER);
break;
}
}
}
virtual int32_t GetOwner()
virtual player_id_t GetOwner()
{
return m_Owner;
}
virtual void SetOwner(int32_t playerID)
virtual void SetOwner(player_id_t playerID)
{
if (playerID == m_Owner)
return;
int32_t old = m_Owner;
player_id_t old = m_Owner;
m_Owner = playerID;
CMessageOwnershipChanged msg(GetEntityId(), old, playerID);

View File

@ -56,7 +56,7 @@ void CCmpPathfinder::Init(const CSimContext& UNUSED(context), const CParamNode&
{
std::string name = it->first;
debug_assert((int)m_PassClasses.size() <= PASS_CLASS_BITS);
u8 mask = (1 << (m_PassClasses.size() + 1));
u8 mask = (u8)(1u << (m_PassClasses.size() + 1));
m_PassClasses.push_back(PathfinderPassability(mask, it->second));
m_PassClassMasks[name] = mask;
}
@ -89,7 +89,7 @@ void CCmpPathfinder::Init(const CSimContext& UNUSED(context), const CParamNode&
size_t i = 0;
for (std::set<std::string>::const_iterator nit = unitClassNames.begin(); nit != unitClassNames.end(); ++nit)
{
m_UnitCostClassTags[*nit] = i;
m_UnitCostClassTags[*nit] = (u8)i;
++i;
std::vector<u32> costs;
@ -241,9 +241,9 @@ void CCmpPathfinder::UpdateGrid()
// Obstructions or terrain changed - we need to recompute passability
// TODO: only bother recomputing the region that has actually changed
for (size_t j = 0; j < m_MapSize; ++j)
for (u16 j = 0; j < m_MapSize; ++j)
{
for (size_t i = 0; i < m_MapSize; ++i)
for (u16 i = 0; i < m_MapSize; ++i)
{
fixed x, z;
TileCenter(i, j, x, z);

View File

@ -115,7 +115,7 @@ const int COST_CLASS_BITS = 8 - (PASS_CLASS_BITS + 1);
#define IS_TERRAIN_PASSABLE(item, classmask) (((item) & (classmask)) == 0)
#define IS_PASSABLE(item, classmask) (((item) & ((classmask) | 1)) == 0)
#define GET_COST_CLASS(item) ((item) >> (PASS_CLASS_BITS + 1))
#define COST_CLASS_TAG(id) ((id) << (PASS_CLASS_BITS + 1))
#define COST_CLASS_TAG(id) ( (u8) ((id) << (PASS_CLASS_BITS + 1)) )
struct AsyncLongPathRequest
{

View File

@ -789,7 +789,7 @@ void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter, enti
// Remember the heuristically best vertex we've seen so far, in case we never actually reach the target
if (vertexes[n].h < hBest)
{
idBest = n;
idBest = (u16)n;
hBest = vertexes[n].h;
}
}

View File

@ -257,7 +257,7 @@ public:
size_t id = m_QueryNext++;
m_Queries[id] = ConstructQuery(source, maxRange, owners, requiredInterface);
return id;
return (tag_t)id;
}
virtual void DestroyActiveQuery(tag_t tag)

View File

@ -201,7 +201,7 @@ public:
}
}
virtual void HandleMessage(const CSimContext& context, const CMessage& msg, bool UNUSED(global))
virtual void HandleMessage(const CSimContext& UNUSED(context), const CMessage& msg, bool UNUSED(global))
{
switch (msg.GetType())
{

View File

@ -22,6 +22,6 @@
#include "simulation2/system/InterfaceScripted.h"
BEGIN_INTERFACE_WRAPPER(Ownership)
DEFINE_INTERFACE_METHOD_0("GetOwner", int32_t, ICmpOwnership, GetOwner)
DEFINE_INTERFACE_METHOD_1("SetOwner", void, ICmpOwnership, SetOwner, int32_t)
DEFINE_INTERFACE_METHOD_0("GetOwner", player_id_t, ICmpOwnership, GetOwner)
DEFINE_INTERFACE_METHOD_1("SetOwner", void, ICmpOwnership, SetOwner, player_id_t)
END_INTERFACE_WRAPPER(Ownership)

View File

@ -19,18 +19,19 @@
#define INCLUDED_ICMPOWNERSHIP
#include "simulation2/system/Interface.h"
#include "simulation2/helpers/Player.h"
/**
* Player ownership.
* Owner values are either a player ID (if >= 0), or unassigned (-1).
* Owner values are either a player ID (if >= 0), or unassigned (INVALID_PLAYER).
* Sends message OwnershipChanged after it changes.
*/
class ICmpOwnership : public IComponent
{
public:
virtual int32_t GetOwner() = 0;
virtual player_id_t GetOwner() = 0;
virtual void SetOwner(int32_t playerID) = 0;
virtual void SetOwner(player_id_t playerID) = 0;
DECLARE_INTERFACE_TYPE(Ownership)
};

View File

@ -0,0 +1,28 @@
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_PLAYER
#define INCLUDED_PLAYER
/**
* valid player IDs are non-negative (see ICmpOwnership)
*/
typedef int32_t player_id_t;
static const player_id_t INVALID_PLAYER = -1;
#endif // INCLUDED_PLAYER

View File

@ -37,7 +37,7 @@ CStdDeserializer::~CStdDeserializer()
void CStdDeserializer::Get(u8* data, size_t len)
{
m_Stream.read((char*)data, len);
m_Stream.read((char*)data, (std::streamsize)len);
if (!m_Stream.good()) // hit eof before len, or other errors
throw PSERROR_Deserialize_ReadFailed();
}

View File

@ -37,7 +37,7 @@ public:
#else
UNUSED2(name);
#endif
m_Stream.write((const char*)data, len);
m_Stream.write((const char*)data, (std::streamsize)len);
}
private:

View File

@ -306,7 +306,7 @@ void CComponentManager::Script_RegisterInterface(void* cbdata, std::string name)
// IIDs start at 1, so size+1 is the next unused one
size_t id = componentManager->m_InterfaceIdsByName.size() + 1;
componentManager->m_InterfaceIdsByName[name] = id;
componentManager->m_InterfaceIdsByName[name] = (InterfaceId)id;
componentManager->m_ScriptInterface.SetGlobal(("IID_" + name).c_str(), (int)id);
}
@ -326,7 +326,7 @@ void CComponentManager::Script_RegisterMessageType(void* cbdata, std::string nam
// MTIDs start at 1, so size+1 is the next unused one
size_t id = componentManager->m_MessageTypeIdsByName.size() + 1;
componentManager->RegisterMessageType(id, name.c_str());
componentManager->RegisterMessageType((MessageTypeId)id, name.c_str());
componentManager->m_ScriptInterface.SetGlobal(("MT_" + name).c_str(), (int)id);
}

View File

@ -714,7 +714,7 @@ bool ScriptInterface::CallFunction(jsval val, const char* name)
bool ScriptInterface::CallFunction_(jsval val, const char* name, std::vector<jsval>& args, jsval& ret)
{
const uintN argc = args.size();
const uintN argc = (uintN)args.size();
jsval* argv = NULL;
if (argc)
argv = &args[0];
@ -730,14 +730,13 @@ bool ScriptInterface::CallFunction_(jsval val, const char* name, std::vector<jsv
bool ScriptInterface::Eval(const wxString& script)
{
jsval rval;
JSBool ok = JS_EvaluateScript(m->m_cx, m->m_glob, script.mb_str(), script.length(), NULL, 0, &rval);
JSBool ok = JS_EvaluateScript(m->m_cx, m->m_glob, script.mb_str(), (uintN)script.length(), NULL, 0, &rval);
return ok ? true : false;
}
bool ScriptInterface::Eval_(const wxString& script, jsval& rval)
{
JSBool ok = JS_EvaluateScript(m->m_cx, m->m_glob,
script.mb_str(), script.length(), NULL, 0, &rval);
JSBool ok = JS_EvaluateScript(m->m_cx, m->m_glob, script.mb_str(), (uintN)script.length(), NULL, 0, &rval);
return ok ? true : false;
}

View File

@ -49,8 +49,12 @@ AtlasMessage::sObjectSettings ObjectSettings::GetSettings() const
void ObjectSettings::OnSelectionChange(const std::vector<AtlasMessage::ObjectID>& selection)
{
// Convert to ints so they can be passed to JS
std::vector<int> objs (selection.begin(), selection.end());
// Convert to int so they can be passed to JS
// (manual loop instead of vector range ctor avoids conversion warning)
std::vector<int> objs;
objs.reserve(selection.size());
for(std::vector<AtlasMessage::ObjectID>::const_iterator it = selection.begin(); it != selection.end(); ++it)
objs.push_back((int)*it);
m_ScriptInterface.SetValue(_T("Atlas.State.objectSettings.selectedObjects"), objs);
m_ScriptInterface.Eval(_T("Atlas.State.objectSettings.onSelectionChange()"));

View File

@ -190,7 +190,7 @@ QUERYHANDLER(GetObjectSettings)
BEGIN_COMMAND(SetObjectSettings)
{
size_t m_PlayerOld, m_PlayerNew;
player_id_t m_PlayerOld, m_PlayerNew;
std::set<CStr> m_SelectionsOld, m_SelectionsNew;
void Do()
@ -212,7 +212,7 @@ BEGIN_COMMAND(SetObjectSettings)
// TODO: selections
// m_SelectionsOld = unit->GetActorSelections();
m_PlayerNew = (size_t)settings.player;
m_PlayerNew = (player_id_t)settings.player;
std::vector<std::wstring> selections = *settings.selections;
for (std::vector<std::wstring>::iterator it = selections.begin(); it != selections.end(); ++it)
@ -234,7 +234,7 @@ BEGIN_COMMAND(SetObjectSettings)
}
private:
void Set(size_t player, const std::set<CStr>& selections)
void Set(player_id_t player, const std::set<CStr>& selections)
{
View* view = View::GetView(msg->view);
CSimulation2* simulation = view->GetSimulation2();
@ -328,7 +328,7 @@ MESSAGEHANDLER(ObjectPreview)
CmpPtr<ICmpOwnership> cmpOwner (*g_Game->GetSimulation2(), g_PreviewEntityID);
if (!cmpOwner.null())
cmpOwner->SetOwner(msg->settings->player);
cmpOwner->SetOwner((player_id_t)msg->settings->player);
}
}
@ -337,7 +337,7 @@ BEGIN_COMMAND(CreateObject)
CVector3D m_Pos;
float m_Angle;
size_t m_ID; // old simulation system
size_t m_Player;
player_id_t m_Player;
entity_id_t m_EntityID; // new simulation system
void Do()
@ -358,7 +358,7 @@ BEGIN_COMMAND(CreateObject)
}
// TODO: variations too
m_Player = msg->settings->player;
m_Player = (player_id_t)msg->settings->player;
Redo();
}
@ -408,7 +408,7 @@ QUERYHANDLER(PickObject)
if (target)
msg->id = target->GetID();
else
msg->id = invalidUnitId;
msg->id = INVALID_ENTITY;
if (target)
{
@ -442,7 +442,7 @@ BEGIN_COMMAND(MoveObject)
void Do()
{
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), msg->id);
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
if (cmpPos.null())
{
// error
@ -461,7 +461,7 @@ BEGIN_COMMAND(MoveObject)
void SetPos(CVector3D& pos)
{
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), msg->id);
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
if (cmpPos.null())
return;
@ -494,7 +494,7 @@ BEGIN_COMMAND(RotateObject)
void Do()
{
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), msg->id);
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
if (cmpPos.null())
return;
@ -516,7 +516,7 @@ BEGIN_COMMAND(RotateObject)
void SetAngle(float angle)
{
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), msg->id);
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
if (cmpPos.null())
return;
@ -569,7 +569,7 @@ BEGIN_COMMAND(DeleteObject)
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
debug_assert(!cmpTemplateManager.null());
m_EntityID = msg->id;
m_EntityID = (entity_id_t)msg->id;
m_TemplateName = cmpTemplateManager->GetCurrentTemplateName(m_EntityID);
CmpPtr<ICmpOwnership> cmpOwner(sim, m_EntityID);