forked from 0ad/0ad
Adds safe bool operator to ICmpPtr, replacing the null() method, based on patch by leper. Also changes bool operator in AtSmartPtr to safe bool. Fixes #1077.
Changes some CmpPtr variable names for consistency. This was SVN commit r11036.
This commit is contained in:
parent
046729dfa7
commit
08bd07ddd6
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -726,7 +726,7 @@ void CGameView::Update(float DeltaTime)
|
||||
if (m->FollowEntity)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(*(m->Game->GetSimulation2()), m->FollowEntity);
|
||||
if (!cmpPosition.null() && cmpPosition->IsInWorld())
|
||||
if (cmpPosition && cmpPosition->IsInWorld())
|
||||
{
|
||||
// Get the most recent interpolated position
|
||||
float frameOffset = m->Game->GetSimulation2()->GetLastFrameOffset();
|
||||
@ -800,7 +800,7 @@ void CGameView::Update(float DeltaTime)
|
||||
CVector3D desiredPivot = pivot;
|
||||
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(*m->Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpRangeManager.null() && cmpRangeManager->GetLosCircular())
|
||||
if (cmpRangeManager && cmpRangeManager->GetLosCircular())
|
||||
{
|
||||
// Clamp to a circular region around the center of the map
|
||||
float r = pTerrain->GetMaxX() / 2;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -106,7 +106,7 @@ const float* CLOSTexture::GetMinimapTextureMatrix()
|
||||
void CLOSTexture::ConstructTexture(int unit)
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return;
|
||||
|
||||
m_MapSize = cmpTerrain->GetVerticesPerSide();
|
||||
@ -162,7 +162,7 @@ void CLOSTexture::RecomputeTexture(int unit)
|
||||
if (m_Texture)
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null() && m_MapSize != (ssize_t)cmpTerrain->GetVerticesPerSide())
|
||||
if (cmpTerrain && m_MapSize != (ssize_t)cmpTerrain->GetVerticesPerSide())
|
||||
DeleteTexture();
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ void CLOSTexture::RecomputeTexture(int unit)
|
||||
losData.resize(GetBitmapSize(m_MapSize, m_MapSize));
|
||||
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(m_Simulation, SYSTEM_ENTITY);
|
||||
if (cmpRangeManager.null())
|
||||
if (!cmpRangeManager)
|
||||
return;
|
||||
|
||||
ICmpRangeManager::CLosQuerier los (cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID()));
|
||||
|
@ -288,14 +288,14 @@ int CMapReader::ApplyData()
|
||||
|
||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(*pSimContext, SYSTEM_ENTITY);
|
||||
|
||||
if (pGameView && !cmpPlayerManager.null())
|
||||
if (pGameView && cmpPlayerManager)
|
||||
{
|
||||
// Default to global camera (with constraints)
|
||||
pGameView->ResetCameraTarget(pGameView->GetCamera()->GetFocus());
|
||||
|
||||
// TODO: Starting rotation?
|
||||
CmpPtr<ICmpPlayer> cmpPlayer(*pSimContext, cmpPlayerManager->GetPlayerByID(m_PlayerID));
|
||||
if (!cmpPlayer.null() && cmpPlayer->HasStartingCamera())
|
||||
if (cmpPlayer && cmpPlayer->HasStartingCamera())
|
||||
{
|
||||
// Use player starting camera
|
||||
CFixedVector3D pos = cmpPlayer->GetStartingCameraPos();
|
||||
@ -305,7 +305,7 @@ int CMapReader::ApplyData()
|
||||
{
|
||||
// Point camera at entity
|
||||
CmpPtr<ICmpPosition> cmpPosition(*pSimContext, m_StartingCameraTarget);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
CFixedVector3D pos = cmpPosition->GetPosition();
|
||||
pGameView->ResetCameraTarget(CVector3D(pos.X.ToFloat(), pos.Y.ToFloat(), pos.Z.ToFloat()));
|
||||
@ -314,7 +314,7 @@ int CMapReader::ApplyData()
|
||||
}
|
||||
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*pSimContext, SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->ReloadTerrain();
|
||||
|
||||
return 0;
|
||||
@ -634,9 +634,9 @@ void CXMLReader::ReadEnvironment(XMBElement parent)
|
||||
int element_name = waterelement.GetNodeName();
|
||||
if (element_name == el_height)
|
||||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*m_MapReader.pSimContext, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpWaterMan.null());
|
||||
cmpWaterMan->SetWaterLevel(entity_pos_t::FromString(waterelement.GetText()));
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*m_MapReader.pSimContext, SYSTEM_ENTITY);
|
||||
ENSURE(cmpWaterManager);
|
||||
cmpWaterManager->SetWaterLevel(entity_pos_t::FromString(waterelement.GetText()));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -931,16 +931,16 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
|
||||
else
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(sim, ent);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
cmpPosition->JumpTo(Position.X, Position.Z);
|
||||
cmpPosition->SetYRotation(Orientation.Y);
|
||||
// TODO: other parts of the position
|
||||
}
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner(sim, ent);
|
||||
if (!cmpOwner.null())
|
||||
cmpOwner->SetOwner(PlayerID);
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, ent);
|
||||
if (cmpOwnership)
|
||||
cmpOwnership->SetOwner(PlayerID);
|
||||
|
||||
if (PlayerID == m_MapReader.m_PlayerID && (boost::algorithm::ends_with(TemplateName, L"civil_centre") || m_MapReader.m_StartingCameraTarget == INVALID_ENTITY))
|
||||
{
|
||||
@ -1252,16 +1252,16 @@ int CMapReader::ParseEntities()
|
||||
else
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(sim, ent);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
cmpPosition->JumpTo(currEnt.position.X, currEnt.position.Z);
|
||||
cmpPosition->SetYRotation(currEnt.rotation.Y);
|
||||
// TODO: other parts of the position
|
||||
}
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner(sim, ent);
|
||||
if (!cmpOwner.null())
|
||||
cmpOwner->SetOwner(currEnt.playerID);
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, ent);
|
||||
if (cmpOwnership)
|
||||
cmpOwnership->SetOwner(currEnt.playerID);
|
||||
|
||||
if (currEnt.playerID == m_PlayerID && (boost::algorithm::ends_with(currEnt.templateName, L"civil_centre") || m_StartingCameraTarget == INVALID_ENTITY))
|
||||
{
|
||||
@ -1326,9 +1326,9 @@ int CMapReader::ParseEnvironment()
|
||||
float waterHeight;
|
||||
GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Height, waterHeight)
|
||||
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*pSimulation2, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpWaterMan.null());
|
||||
cmpWaterMan->SetWaterLevel(entity_pos_t::FromFloat(waterHeight));
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*pSimulation2, SYSTEM_ENTITY);
|
||||
ENSURE(cmpWaterManager);
|
||||
cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(waterHeight));
|
||||
|
||||
// If we have graphics, get rest of settings
|
||||
if (pWaterMan)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -229,9 +229,9 @@ void CMapWriter::WriteXML(const VfsPath& filename,
|
||||
XML_Attribute("g", pWaterMan->m_WaterColor.g);
|
||||
XML_Attribute("b", pWaterMan->m_WaterColor.b);
|
||||
}
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*pSimulation2, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpWaterMan.null());
|
||||
XML_Setting("Height", cmpWaterMan->GetExactWaterLevel(0, 0));
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*pSimulation2, SYSTEM_ENTITY);
|
||||
ENSURE(cmpWaterManager);
|
||||
XML_Setting("Height", cmpWaterManager->GetExactWaterLevel(0, 0));
|
||||
XML_Setting("Shininess", pWaterMan->m_Shininess);
|
||||
XML_Setting("Waviness", pWaterMan->m_Waviness);
|
||||
XML_Setting("Murkiness", pWaterMan->m_Murkiness);
|
||||
@ -294,7 +294,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
|
||||
CSimulation2& sim = *pSimulation2;
|
||||
|
||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpTemplateManager.null());
|
||||
ENSURE(cmpTemplateManager);
|
||||
|
||||
// This will probably need to be changed in the future, but for now we'll
|
||||
// just save all entities that have a position
|
||||
@ -312,12 +312,12 @@ void CMapWriter::WriteXML(const VfsPath& filename,
|
||||
|
||||
XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(ent));
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner(sim, ent);
|
||||
if (!cmpOwner.null())
|
||||
XML_Setting("Player", (int)cmpOwner->GetOwner());
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, ent);
|
||||
if (cmpOwnership)
|
||||
XML_Setting("Player", (int)cmpOwnership->GetOwner());
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(sim, ent);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
CFixedVector3D pos = cmpPosition->GetPosition();
|
||||
CFixedVector3D rot = cmpPosition->GetRotation();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -159,7 +159,7 @@ CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, const std::
|
||||
CTerrain* CObjectManager::GetTerrain()
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return NULL;
|
||||
return cmpTerrain->GetCTerrain();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -52,7 +52,7 @@ void CTerritoryTexture::DeleteTexture()
|
||||
bool CTerritoryTexture::UpdateDirty()
|
||||
{
|
||||
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(m_Simulation, SYSTEM_ENTITY);
|
||||
if (cmpTerritoryManager.null())
|
||||
if (!cmpTerritoryManager)
|
||||
return false;
|
||||
|
||||
return cmpTerritoryManager->NeedUpdate(&m_DirtyID);
|
||||
@ -89,7 +89,7 @@ const float* CTerritoryTexture::GetMinimapTextureMatrix()
|
||||
void CTerritoryTexture::ConstructTexture(int unit)
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return;
|
||||
|
||||
m_MapSize = cmpTerrain->GetVerticesPerSide() - 1;
|
||||
@ -145,7 +145,7 @@ void CTerritoryTexture::RecomputeTexture(int unit)
|
||||
if (m_Texture)
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null() && m_MapSize != (ssize_t)cmpTerrain->GetVerticesPerSide())
|
||||
if (cmpTerrain && m_MapSize != (ssize_t)cmpTerrain->GetVerticesPerSide())
|
||||
DeleteTexture();
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ void CTerritoryTexture::RecomputeTexture(int unit)
|
||||
bitmap.resize(m_MapSize * m_MapSize * 4);
|
||||
|
||||
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(m_Simulation, SYSTEM_ENTITY);
|
||||
if (cmpTerritoryManager.null())
|
||||
if (!cmpTerritoryManager)
|
||||
return;
|
||||
|
||||
const Grid<u8> territories = cmpTerritoryManager->GetTerritoryGrid();
|
||||
@ -182,7 +182,7 @@ void CTerritoryTexture::GenerateBitmap(const Grid<u8>& territories, u8* bitmap,
|
||||
{
|
||||
CColor color(1, 0, 1, 1);
|
||||
CmpPtr<ICmpPlayer> cmpPlayer(m_Simulation, cmpPlayerManager->GetPlayerByID(p));
|
||||
if (!cmpPlayer.null())
|
||||
if (cmpPlayer)
|
||||
color = cmpPlayer->GetColour();
|
||||
colors.push_back(color);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -186,7 +186,7 @@ void CUnitAnimation::Update(float time)
|
||||
if (!m_ActionSound.empty())
|
||||
{
|
||||
CmpPtr<ICmpSoundManager> cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpSoundManager.null())
|
||||
if (cmpSoundManager)
|
||||
cmpSoundManager->PlaySoundGroup(m_ActionSound, m_Entity);
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ void CMiniMap::Draw()
|
||||
|
||||
CSimulation2* sim = g_Game->GetSimulation2();
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpRangeManager.null());
|
||||
ENSURE(cmpRangeManager);
|
||||
|
||||
// Set our globals in case they hadn't been set before
|
||||
m_Camera = g_Game->GetView()->GetCamera();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -95,8 +95,8 @@ CScriptVal GuiInterfaceCall(void* cbdata, std::wstring name, CScriptVal data)
|
||||
CSimulation2* sim = g_Game->GetSimulation2();
|
||||
ENSURE(sim);
|
||||
|
||||
CmpPtr<ICmpGuiInterface> gui(*sim, SYSTEM_ENTITY);
|
||||
if (gui.null())
|
||||
CmpPtr<ICmpGuiInterface> cmpGuiInterface(*sim, SYSTEM_ENTITY);
|
||||
if (!cmpGuiInterface)
|
||||
return JSVAL_VOID;
|
||||
|
||||
int player = -1;
|
||||
@ -104,7 +104,7 @@ CScriptVal GuiInterfaceCall(void* cbdata, std::wstring name, CScriptVal data)
|
||||
player = g_Game->GetPlayerID();
|
||||
|
||||
CScriptValRooted arg (sim->GetScriptInterface().GetContext(), sim->GetScriptInterface().CloneValueFromOtherContext(guiManager->GetScriptInterface(), data.get()));
|
||||
CScriptVal ret (gui->ScriptCall(player, name, arg.get()));
|
||||
CScriptVal ret (cmpGuiInterface->ScriptCall(player, name, arg.get()));
|
||||
return guiManager->GetScriptInterface().CloneValueFromOtherContext(sim->GetScriptInterface(), ret.get());
|
||||
}
|
||||
|
||||
@ -117,13 +117,13 @@ void PostNetworkCommand(void* cbdata, CScriptVal cmd)
|
||||
CSimulation2* sim = g_Game->GetSimulation2();
|
||||
ENSURE(sim);
|
||||
|
||||
CmpPtr<ICmpCommandQueue> queue(*sim, SYSTEM_ENTITY);
|
||||
if (queue.null())
|
||||
CmpPtr<ICmpCommandQueue> cmpCommandQueue(*sim, SYSTEM_ENTITY);
|
||||
if (!cmpCommandQueue)
|
||||
return;
|
||||
|
||||
jsval cmd2 = sim->GetScriptInterface().CloneValueFromOtherContext(guiManager->GetScriptInterface(), cmd.get());
|
||||
|
||||
queue->PostNetworkCommand(cmd2);
|
||||
cmpCommandQueue->PostNetworkCommand(cmd2);
|
||||
}
|
||||
|
||||
std::vector<entity_id_t> PickEntitiesAtPoint(void* UNUSED(cbdata), int x, int y)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -328,7 +328,7 @@ void CGame::CachePlayerColours()
|
||||
m_PlayerColours.clear();
|
||||
|
||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(*m_Simulation2, SYSTEM_ENTITY);
|
||||
if (cmpPlayerManager.null())
|
||||
if (!cmpPlayerManager)
|
||||
return;
|
||||
|
||||
int numPlayers = cmpPlayerManager->GetNumPlayers();
|
||||
@ -337,7 +337,7 @@ void CGame::CachePlayerColours()
|
||||
for (int i = 0; i < numPlayers; ++i)
|
||||
{
|
||||
CmpPtr<ICmpPlayer> cmpPlayer(*m_Simulation2, cmpPlayerManager->GetPlayerByID(i));
|
||||
if (cmpPlayer.null())
|
||||
if (!cmpPlayer)
|
||||
m_PlayerColours[i] = BrokenColor;
|
||||
else
|
||||
m_PlayerColours[i] = cmpPlayer->GetColour();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -139,7 +139,7 @@ void CDecalRData::BuildArrays()
|
||||
CVector3D pos;
|
||||
m_Decal->m_Terrain->CalcPosition(i, j, pos);
|
||||
|
||||
if (decal.m_Floating && !cmpWaterManager.null())
|
||||
if (decal.m_Floating && cmpWaterManager)
|
||||
pos.Y = std::max(pos.Y, cmpWaterManager->GetExactWaterLevel(pos.X, pos.Z));
|
||||
|
||||
*Position = pos;
|
||||
|
@ -581,7 +581,7 @@ void CPatchRData::BuildSide(std::vector<SSideVertex>& vertices, CPatchSideFlags
|
||||
|
||||
// Clamp the height to the water level
|
||||
float waterHeight = 0.f;
|
||||
if (!cmpWaterManager.null())
|
||||
if (cmpWaterManager)
|
||||
waterHeight = cmpWaterManager->GetExactWaterLevel(pos.X, pos.Z);
|
||||
pos.Y = std::max(pos.Y, waterHeight);
|
||||
|
||||
@ -1203,7 +1203,7 @@ void CPatchRData::BuildWater()
|
||||
// We need to use this to access the water manager or we may not have the
|
||||
// actual values but some compiled-in defaults
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (cmpWaterManager.null())
|
||||
if (!cmpWaterManager)
|
||||
return;
|
||||
|
||||
// Build data for water
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -448,7 +448,7 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
|
||||
|
||||
// Start computing AI for the next turn
|
||||
CmpPtr<ICmpAIManager> cmpAIManager(m_SimContext, SYSTEM_ENTITY);
|
||||
if (!cmpAIManager.null())
|
||||
if (cmpAIManager)
|
||||
cmpAIManager->StartComputation();
|
||||
|
||||
++m_TurnNumber;
|
||||
@ -465,20 +465,20 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt
|
||||
componentManager.BroadcastMessage(msgTurnStart);
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(simContext, SYSTEM_ENTITY);
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
cmpPathfinder->FinishAsyncRequests();
|
||||
|
||||
// Push AI commands onto the queue before we use them
|
||||
CmpPtr<ICmpAIManager> cmpAIManager(simContext, SYSTEM_ENTITY);
|
||||
if (!cmpAIManager.null())
|
||||
if (cmpAIManager)
|
||||
cmpAIManager->PushCommands();
|
||||
|
||||
CmpPtr<ICmpCommandQueue> cmpCommandQueue(simContext, SYSTEM_ENTITY);
|
||||
if (!cmpCommandQueue.null())
|
||||
if (cmpCommandQueue)
|
||||
cmpCommandQueue->FlushTurn(commands);
|
||||
|
||||
// Process newly generated move commands so the UI feels snappy
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
cmpPathfinder->ProcessSameTurnMoves();
|
||||
|
||||
// Send all the update phases
|
||||
@ -492,7 +492,7 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt
|
||||
}
|
||||
|
||||
// Process move commands for formations (group proxy)
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
cmpPathfinder->ProcessSameTurnMoves();
|
||||
|
||||
{
|
||||
@ -505,7 +505,7 @@ void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengt
|
||||
}
|
||||
|
||||
// Process moves resulting from group proxy movement (unit needs to catch up or realign) and any others
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
cmpPathfinder->ProcessSameTurnMoves();
|
||||
|
||||
// Clean up any entities destroyed during the simulation update
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -592,7 +592,7 @@ public:
|
||||
// their implementation.
|
||||
// (TODO: maybe cleverer AIs should be able to optionally retain FoW/SoD)
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpRangeManager.null())
|
||||
if (cmpRangeManager)
|
||||
cmpRangeManager->SetLosRevealAll(player, true);
|
||||
}
|
||||
|
||||
@ -605,7 +605,7 @@ public:
|
||||
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
|
||||
|
||||
CmpPtr<ICmpAIInterface> cmpAIInterface(GetSimContext(), SYSTEM_ENTITY);
|
||||
ENSURE(!cmpAIInterface.null());
|
||||
ENSURE(cmpAIInterface);
|
||||
|
||||
// Get the game state from AIInterface
|
||||
CScriptVal state = cmpAIInterface->GetRepresentation();
|
||||
@ -614,7 +614,7 @@ public:
|
||||
Grid<u16> dummyGrid;
|
||||
const Grid<u16>* passabilityMap = &dummyGrid;
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
passabilityMap = &cmpPathfinder->GetPassabilityGrid();
|
||||
|
||||
// Get the territory data
|
||||
@ -623,7 +623,7 @@ public:
|
||||
Grid<u8> dummyGrid2;
|
||||
const Grid<u8>* territoryMap = &dummyGrid2;
|
||||
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpTerritoryManager.null() && cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
|
||||
if (cmpTerritoryManager && cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
|
||||
{
|
||||
territoryMap = &cmpTerritoryManager->GetTerritoryGrid();
|
||||
territoryMapDirty = true;
|
||||
@ -642,7 +642,7 @@ public:
|
||||
m_Worker.GetCommands(commands);
|
||||
|
||||
CmpPtr<ICmpCommandQueue> cmpCommandQueue(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpCommandQueue.null())
|
||||
if (!cmpCommandQueue)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < commands.size(); ++i)
|
||||
@ -664,7 +664,7 @@ private:
|
||||
void StartLoadEntityTemplates()
|
||||
{
|
||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
ENSURE(!cmpTemplateManager.null());
|
||||
ENSURE(cmpTemplateManager);
|
||||
|
||||
m_TemplateNames = cmpTemplateManager->FindAllTemplates(false);
|
||||
m_TemplateLoadedIdx = 0;
|
||||
@ -678,7 +678,7 @@ private:
|
||||
return false;
|
||||
|
||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
ENSURE(!cmpTemplateManager.null());
|
||||
ENSURE(cmpTemplateManager);
|
||||
|
||||
const CParamNode* node = cmpTemplateManager->GetTemplateWithoutValidation(m_TemplateNames[m_TemplateLoadedIdx]);
|
||||
if (node)
|
||||
@ -703,7 +703,7 @@ private:
|
||||
void LoadPathfinderClasses(CScriptVal state)
|
||||
{
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return;
|
||||
|
||||
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -123,7 +123,7 @@ public:
|
||||
const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
{
|
||||
// If there's no position (this usually shouldn't happen), destroy the unit immediately
|
||||
GetSimContext().GetComponentManager().DestroyComponentsSoon(GetEntityId());
|
||||
@ -138,7 +138,7 @@ public:
|
||||
m_TotalSinkDepth = 1.f; // minimum so we always sink at least a little
|
||||
|
||||
CmpPtr<ICmpVisual> cmpVisual(GetSimContext(), GetEntityId());
|
||||
if (!cmpVisual.null())
|
||||
if (cmpVisual)
|
||||
{
|
||||
CBoundingBoxAligned bound = cmpVisual->GetBounds();
|
||||
m_TotalSinkDepth = std::max(m_TotalSinkDepth, bound[1].Y - bound[0].Y);
|
||||
@ -150,7 +150,7 @@ public:
|
||||
CFixedVector3D pos = cmpPosition->GetPosition();
|
||||
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
{
|
||||
fixed ground = cmpTerrain->GetGroundLevel(pos.X, pos.Z);
|
||||
m_TotalSinkDepth += std::max(0.f, (pos.Y - ground).ToFloat());
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -131,18 +131,18 @@ public:
|
||||
const CFixedVector3D error(fixed::FromInt(-1), fixed::FromInt(-1), fixed::FromInt(-1));
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return error;
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return error;
|
||||
|
||||
entity_pos_t spawnedRadius;
|
||||
ICmpObstructionManager::tag_t spawnedTag;
|
||||
|
||||
CmpPtr<ICmpObstruction> cmpSpawnedObstruction(GetSimContext(), spawned);
|
||||
if (!cmpSpawnedObstruction.null())
|
||||
if (cmpSpawnedObstruction)
|
||||
{
|
||||
spawnedRadius = cmpSpawnedObstruction->GetUnitRadius();
|
||||
spawnedTag = cmpSpawnedObstruction->GetObstruction();
|
||||
@ -151,12 +151,12 @@ public:
|
||||
|
||||
// Get passability class from UnitMotion
|
||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), spawned);
|
||||
if (cmpUnitMotion.null())
|
||||
if (!cmpUnitMotion)
|
||||
return error;
|
||||
|
||||
ICmpPathfinder::pass_class_t spawnedPass = cmpUnitMotion->GetPassabilityClass();
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return error;
|
||||
|
||||
CFixedVector2D initialPos = cmpPosition->GetPosition2D();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -170,10 +170,10 @@ public:
|
||||
|
||||
// Find the new player's colour
|
||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPlayerManager.null())
|
||||
if (!cmpPlayerManager)
|
||||
break;
|
||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(msgData.to));
|
||||
if (cmpPlayer.null())
|
||||
if (!cmpPlayer)
|
||||
break;
|
||||
CColor colour = cmpPlayer->GetColour();
|
||||
m_R = (u8)(colour.r*255.0);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -85,7 +85,7 @@ public:
|
||||
void CCmpMotionBall::Move(fixed dt)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return;
|
||||
|
||||
// TODO: this is all FP-unsafe
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -182,7 +182,7 @@ public:
|
||||
break; // nothing needs to change
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
break; // error
|
||||
|
||||
if (data.inWorld && m_Tag.valid())
|
||||
@ -211,7 +211,7 @@ public:
|
||||
if (m_Tag.valid())
|
||||
{
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
break; // error
|
||||
|
||||
cmpObstructionManager->RemoveShape(m_Tag);
|
||||
@ -231,11 +231,11 @@ public:
|
||||
// Construct the obstruction shape
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return; // error
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return; // error
|
||||
|
||||
if (!cmpPosition->IsInWorld())
|
||||
@ -258,7 +258,7 @@ public:
|
||||
if (m_Tag.valid())
|
||||
{
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return; // error
|
||||
|
||||
cmpObstructionManager->RemoveShape(m_Tag);
|
||||
@ -305,11 +305,11 @@ public:
|
||||
virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare& out)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return false; // error
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return false; // error
|
||||
|
||||
if (!cmpPosition->IsInWorld())
|
||||
@ -334,7 +334,7 @@ public:
|
||||
virtual bool CheckFoundation(std::string className)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return false; // error
|
||||
|
||||
if (!cmpPosition->IsInWorld())
|
||||
@ -343,7 +343,7 @@ public:
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return false; // error
|
||||
|
||||
// Get passability class
|
||||
@ -363,7 +363,7 @@ public:
|
||||
std::vector<entity_id_t> ret;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return ret; // error
|
||||
|
||||
if (!cmpPosition->IsInWorld())
|
||||
@ -372,7 +372,7 @@ public:
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return ret; // error
|
||||
|
||||
// Ignore collisions with self, or with non-construction-blocking obstructions
|
||||
@ -393,7 +393,7 @@ public:
|
||||
if (m_Tag.valid() && m_Type == UNIT)
|
||||
{
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpObstructionManager.null())
|
||||
if (cmpObstructionManager)
|
||||
cmpObstructionManager->SetUnitMovingFlag(m_Tag, m_Moving);
|
||||
}
|
||||
}
|
||||
@ -405,7 +405,7 @@ public:
|
||||
if (m_Tag.valid() && m_Type == UNIT)
|
||||
{
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpObstructionManager.null())
|
||||
if (cmpObstructionManager)
|
||||
cmpObstructionManager->SetUnitControlGroup(m_Tag, m_ControlGroup);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -124,7 +124,7 @@ public:
|
||||
|
||||
// Disable rendering of the unit if it has no position
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
{
|
||||
m_Enabled = false;
|
||||
return;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -307,7 +307,7 @@ const Grid<u16>& CCmpPathfinder::GetPassabilityGrid()
|
||||
void CCmpPathfinder::UpdateGrid()
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return; // error
|
||||
|
||||
// If the terrain was resized then delete the old grid data
|
||||
@ -372,7 +372,7 @@ void CCmpPathfinder::UpdateGrid()
|
||||
// Obstructions or terrain changed - we need to recompute passability
|
||||
// TODO: only bother recomputing the region that has actually changed
|
||||
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(GetSimContext(), SYSTEM_ENTITY);
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
|
||||
// TOOD: these bits should come from ICmpTerrain
|
||||
CTerrain& terrain = GetSimContext().GetTerrain();
|
||||
@ -389,7 +389,7 @@ void CCmpPathfinder::UpdateGrid()
|
||||
fixed x, z;
|
||||
TileCenter(i, j, x, z);
|
||||
|
||||
bool underWater = !cmpWaterMan.null() && (cmpWaterMan->GetWaterLevel(x, z) > terrain.GetExactGroundLevelFixed(x, z));
|
||||
bool underWater = cmpWaterManager && (cmpWaterManager->GetWaterLevel(x, z) > terrain.GetExactGroundLevelFixed(x, z));
|
||||
waterGrid.set(i, j, underWater);
|
||||
}
|
||||
}
|
||||
@ -494,8 +494,8 @@ void CCmpPathfinder::UpdateGrid()
|
||||
fixed height = terrain.GetExactGroundLevelFixed(x, z);
|
||||
|
||||
fixed water;
|
||||
if (!cmpWaterMan.null())
|
||||
water = cmpWaterMan->GetWaterLevel(x, z);
|
||||
if (cmpWaterManager)
|
||||
water = cmpWaterManager->GetWaterLevel(x, z);
|
||||
|
||||
fixed depth = water - height;
|
||||
|
||||
@ -661,7 +661,7 @@ bool CCmpPathfinder::CheckUnitPlacement(const IObstructionTestFilter& filter,
|
||||
{
|
||||
// Check unit obstruction
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return false;
|
||||
|
||||
if (cmpObstructionManager->TestUnitShape(filter, x, z, r, NULL))
|
||||
@ -693,7 +693,7 @@ bool CCmpPathfinder::CheckBuildingPlacement(const IObstructionTestFilter& filter
|
||||
{
|
||||
// Check unit obstruction
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return false;
|
||||
|
||||
if (cmpObstructionManager->TestStaticShape(filter, x, z, a, w, h, NULL))
|
||||
@ -704,7 +704,7 @@ bool CCmpPathfinder::CheckBuildingPlacement(const IObstructionTestFilter& filter
|
||||
UpdateGrid();
|
||||
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), id);
|
||||
if (cmpObstruction.null())
|
||||
if (!cmpObstruction)
|
||||
return false;
|
||||
|
||||
ICmpObstructionManager::ObstructionSquare square;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -855,7 +855,7 @@ bool CCmpPathfinder::CheckMovement(const IObstructionTestFilter& filter,
|
||||
pass_class_t passClass)
|
||||
{
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return false;
|
||||
|
||||
if (cmpObstructionManager->TestLine(filter, x0, z0, x1, z1, r))
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -253,14 +253,14 @@ public:
|
||||
if (m_RelativeToGround)
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
baseY = cmpTerrain->GetGroundLevel(m_X, m_Z);
|
||||
|
||||
if (m_Floating)
|
||||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpWaterMan.null())
|
||||
baseY = std::max(baseY, cmpWaterMan->GetWaterLevel(m_X, m_Z));
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpWaterManager)
|
||||
baseY = std::max(baseY, cmpWaterManager->GetWaterLevel(m_X, m_Z));
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,14 +348,14 @@ public:
|
||||
if (m_RelativeToGround)
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
baseY = cmpTerrain->GetExactGroundLevel(x, z);
|
||||
|
||||
if (m_Floating || forceFloating)
|
||||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpWaterMan.null())
|
||||
baseY = std::max(baseY, cmpWaterMan->GetExactWaterLevel(x, z));
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpWaterManager)
|
||||
baseY = std::max(baseY, cmpWaterManager->GetExactWaterLevel(x, z));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -141,26 +141,26 @@ void CCmpProjectileManager::LaunchProjectile(entity_id_t source, CFixedVector3D
|
||||
if (!GetSimContext().HasUnitManager())
|
||||
return; // do nothing if graphics are disabled
|
||||
|
||||
CmpPtr<ICmpVisual> sourceVisual(GetSimContext(), source);
|
||||
if (sourceVisual.null())
|
||||
CmpPtr<ICmpVisual> cmpSourceVisual(GetSimContext(), source);
|
||||
if (!cmpSourceVisual)
|
||||
return;
|
||||
|
||||
std::wstring name = sourceVisual->GetProjectileActor();
|
||||
std::wstring name = cmpSourceVisual->GetProjectileActor();
|
||||
if (name.empty())
|
||||
{
|
||||
// If the actor was actually loaded, complain that it doesn't have a projectile
|
||||
if (!sourceVisual->GetActorShortName().empty())
|
||||
LOGERROR(L"Unit with actor '%ls' launched a projectile but has no actor on 'projectile' attachpoint", sourceVisual->GetActorShortName().c_str());
|
||||
if (!cmpSourceVisual->GetActorShortName().empty())
|
||||
LOGERROR(L"Unit with actor '%ls' launched a projectile but has no actor on 'projectile' attachpoint", cmpSourceVisual->GetActorShortName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
CVector3D sourceVec(sourceVisual->GetProjectileLaunchPoint());
|
||||
CVector3D sourceVec(cmpSourceVisual->GetProjectileLaunchPoint());
|
||||
if (!sourceVec)
|
||||
{
|
||||
// If there's no explicit launch point, take a guess based on the entity position
|
||||
|
||||
CmpPtr<ICmpPosition> sourcePos(GetSimContext(), source);
|
||||
if (sourcePos.null())
|
||||
if (!sourcePos)
|
||||
return;
|
||||
|
||||
sourceVec = sourcePos->GetPosition();
|
||||
@ -175,11 +175,11 @@ void CCmpProjectileManager::LaunchProjectile(entity_id_t source, CFixedVector3D
|
||||
}
|
||||
else
|
||||
{
|
||||
CmpPtr<ICmpPosition> targetPos(GetSimContext(), targetEnt);
|
||||
if (targetPos.null())
|
||||
CmpPtr<ICmpPosition> cmpTargetPosition(GetSimContext(), targetEnt);
|
||||
if (!cmpTargetPosition)
|
||||
return;
|
||||
|
||||
targetVec = CVector3D(targetPos->GetPosition());
|
||||
targetVec = CVector3D(cmpTargetPosition->GetPosition());
|
||||
}
|
||||
|
||||
Projectile projectile;
|
||||
@ -229,10 +229,10 @@ void CCmpProjectileManager::AdvanceProjectile(Projectile& projectile, float dt,
|
||||
// Track the target entity (if there is one, and it's still alive)
|
||||
if (projectile.targetEnt != INVALID_ENTITY)
|
||||
{
|
||||
CmpPtr<ICmpPosition> targetPos(GetSimContext(), projectile.targetEnt);
|
||||
if (!targetPos.null() && targetPos->IsInWorld())
|
||||
CmpPtr<ICmpPosition> cmpTargetPosition(GetSimContext(), projectile.targetEnt);
|
||||
if (cmpTargetPosition && cmpTargetPosition->IsInWorld())
|
||||
{
|
||||
CMatrix3D t = targetPos->GetInterpolatedTransform(frameOffset, false);
|
||||
CMatrix3D t = cmpTargetPosition->GetInterpolatedTransform(frameOffset, false);
|
||||
projectile.target = t.GetTranslation();
|
||||
projectile.target.Y += 2.f; // TODO: ought to aim towards a random point in the solid body of the target
|
||||
|
||||
@ -260,7 +260,7 @@ void CCmpProjectileManager::AdvanceProjectile(Projectile& projectile, float dt,
|
||||
if (projectile.timeLeft <= 0)
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
{
|
||||
float h = cmpTerrain->GetExactGroundLevel(projectile.pos.X, projectile.pos.Z);
|
||||
if (projectile.pos.Y < h)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -426,7 +426,7 @@ void CCmpRallyPointRenderer::UpdateMarker()
|
||||
LOGERROR(L"Failed to create rally point marker entity");
|
||||
|
||||
CmpPtr<ICmpPosition> markerCmpPosition(GetSimContext(), m_MarkerEntityId);
|
||||
if (!markerCmpPosition.null())
|
||||
if (markerCmpPosition)
|
||||
{
|
||||
if (m_Displayed && IsSet())
|
||||
{
|
||||
@ -440,7 +440,7 @@ void CCmpRallyPointRenderer::UpdateMarker()
|
||||
|
||||
// set rally point flag selection based on player civilization
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId());
|
||||
if (!cmpOwnership.null())
|
||||
if (cmpOwnership)
|
||||
{
|
||||
player_id_t ownerId = cmpOwnership->GetOwner();
|
||||
if (ownerId != INVALID_PLAYER && ownerId != m_LastOwner)
|
||||
@ -449,13 +449,13 @@ void CCmpRallyPointRenderer::UpdateMarker()
|
||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
// cmpPlayerManager should not be null as long as this method is called on-demand instead of at Init() time
|
||||
// (we can't rely on component initialization order in Init())
|
||||
if (!cmpPlayerManager.null())
|
||||
if (cmpPlayerManager)
|
||||
{
|
||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(ownerId));
|
||||
if (!cmpPlayer.null())
|
||||
if (cmpPlayer)
|
||||
{
|
||||
CmpPtr<ICmpVisual> cmpVisualActor(GetSimContext(), m_MarkerEntityId);
|
||||
if (!cmpVisualActor.null())
|
||||
if (cmpVisualActor)
|
||||
{
|
||||
cmpVisualActor->SetUnitEntitySelection(CStrW(cmpPlayer->GetCiv()).ToUTF8());
|
||||
}
|
||||
@ -474,7 +474,7 @@ void CCmpRallyPointRenderer::RecomputeRallyPointPath()
|
||||
return; // no use computing a path if the rally point isn't set
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return; // no point going on if this entity doesn't have a position or is outside of the world
|
||||
|
||||
CmpPtr<ICmpFootprint> cmpFootprint(GetSimContext(), GetEntityId());
|
||||
@ -533,7 +533,7 @@ void CCmpRallyPointRenderer::RecomputeRallyPointPath()
|
||||
m_Path[i] = (m_Path[i] + m_Path[i-1]) / 2.0f;
|
||||
|
||||
// if there's a footprint, remove any points returned by the pathfinder that may be on obstructed footprint tiles
|
||||
if (!cmpFootprint.null())
|
||||
if (cmpFootprint)
|
||||
FixFootprintWaypoints(m_Path, cmpPosition, cmpFootprint);
|
||||
|
||||
// Eliminate some consecutive waypoints that are visible from eachother. Reduce across a maximum distance of approx. 6 tiles
|
||||
@ -737,8 +737,8 @@ void CCmpRallyPointRenderer::UpdateOverlayLines()
|
||||
|
||||
void CCmpRallyPointRenderer::FixFootprintWaypoints(std::vector<CVector2D>& coords, CmpPtr<ICmpPosition> cmpPosition, CmpPtr<ICmpFootprint> cmpFootprint)
|
||||
{
|
||||
ENSURE(!cmpPosition.null());
|
||||
ENSURE(!cmpFootprint.null());
|
||||
ENSURE(cmpPosition);
|
||||
ENSURE(cmpFootprint);
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// TODO: nasty fixed/float conversions everywhere
|
||||
@ -851,7 +851,7 @@ void CCmpRallyPointRenderer::ReduceSegmentsByVisibility(std::vector<CVector2D>&
|
||||
CmpPtr<ICmpPathfinder> cmpPathFinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
ENSURE(!cmpPathFinder.null() && !cmpTerrain.null() && !cmpWaterManager.null());
|
||||
ENSURE(cmpPathFinder && cmpTerrain && cmpWaterManager);
|
||||
|
||||
if (coords.size() < 3)
|
||||
return;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -293,7 +293,7 @@ public:
|
||||
|
||||
// Ignore non-positional entities
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), ent);
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
break;
|
||||
|
||||
// The newly-created entity will have owner -1 and position out-of-world
|
||||
@ -303,7 +303,7 @@ public:
|
||||
|
||||
// Store the LOS data, if any
|
||||
CmpPtr<ICmpVision> cmpVision(GetSimContext(), ent);
|
||||
if (!cmpVision.null())
|
||||
if (cmpVision)
|
||||
{
|
||||
entdata.visionRange = cmpVision->GetRange();
|
||||
entdata.retainInFog = (cmpVision->GetRetainInFog() ? 1 : 0);
|
||||
@ -570,7 +570,7 @@ public:
|
||||
std::vector<entity_id_t> r;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpSourcePosition(GetSimContext(), q.source);
|
||||
if (cmpSourcePosition.null() || !cmpSourcePosition->IsInWorld())
|
||||
if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld())
|
||||
{
|
||||
// If the source doesn't have a position, then the result is just the empty list
|
||||
return r;
|
||||
@ -602,7 +602,7 @@ public:
|
||||
q.enabled = true;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpSourcePosition(GetSimContext(), q.source);
|
||||
if (cmpSourcePosition.null() || !cmpSourcePosition->IsInWorld())
|
||||
if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld())
|
||||
{
|
||||
// If the source doesn't have a position, then the result is just the empty list
|
||||
q.lastMatch = r;
|
||||
@ -663,7 +663,7 @@ public:
|
||||
continue;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpSourcePosition(GetSimContext(), q.source);
|
||||
if (cmpSourcePosition.null() || !cmpSourcePosition->IsInWorld())
|
||||
if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld())
|
||||
continue;
|
||||
|
||||
std::vector<entity_id_t> r;
|
||||
@ -726,7 +726,7 @@ public:
|
||||
void PerformQuery(const Query& q, std::vector<entity_id_t>& r)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpSourcePosition(GetSimContext(), q.source);
|
||||
if (cmpSourcePosition.null() || !cmpSourcePosition->IsInWorld())
|
||||
if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld())
|
||||
return;
|
||||
CFixedVector2D pos = cmpSourcePosition->GetPosition2D();
|
||||
|
||||
@ -816,7 +816,7 @@ public:
|
||||
Query& q = it->second;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpSourcePosition(GetSimContext(), q.source);
|
||||
if (cmpSourcePosition.null() || !cmpSourcePosition->IsInWorld())
|
||||
if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld())
|
||||
continue;
|
||||
CFixedVector2D pos = cmpSourcePosition->GetPosition2D();
|
||||
|
||||
@ -837,7 +837,7 @@ public:
|
||||
for (size_t i = 0; i < q.lastMatch.size(); ++i)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpTargetPosition(GetSimContext(), q.lastMatch[i]);
|
||||
if (cmpTargetPosition.null() || !cmpTargetPosition->IsInWorld())
|
||||
if (!cmpTargetPosition || !cmpTargetPosition->IsInWorld())
|
||||
continue;
|
||||
CFixedVector2D targetPos = cmpTargetPosition->GetPosition2D();
|
||||
|
||||
@ -878,7 +878,7 @@ public:
|
||||
|
||||
// Entities not with positions in the world are never visible
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), ent);
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return VIS_HIDDEN;
|
||||
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
@ -906,7 +906,7 @@ public:
|
||||
if (los.IsExplored(i, j))
|
||||
{
|
||||
CmpPtr<ICmpVision> cmpVision(GetSimContext(), ent);
|
||||
if (forceRetainInFog || (!cmpVision.null() && cmpVision->GetRetainInFog()))
|
||||
if (forceRetainInFog || (cmpVision && cmpVision->GetRetainInFog()))
|
||||
return VIS_FOGGED;
|
||||
}
|
||||
|
||||
@ -951,7 +951,7 @@ public:
|
||||
void UpdateTerritoriesLos()
|
||||
{
|
||||
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpTerritoryManager.null() || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
|
||||
if (!cmpTerritoryManager || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
|
||||
return;
|
||||
|
||||
const Grid<u8>& grid = cmpTerritoryManager->GetTerritoryGrid();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -131,7 +131,7 @@ public:
|
||||
void ConstructShape(float frameOffset)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return;
|
||||
|
||||
if (!cmpPosition->IsInWorld())
|
||||
@ -141,7 +141,7 @@ public:
|
||||
cmpPosition->GetInterpolatedPosition2D(frameOffset, x, z, rotY);
|
||||
|
||||
CmpPtr<ICmpFootprint> cmpFootprint(GetSimContext(), GetEntityId());
|
||||
if (cmpFootprint.null())
|
||||
if (!cmpFootprint)
|
||||
{
|
||||
// Default (this probably shouldn't happen) - just render an arbitrary-sized circle
|
||||
SimRender::ConstructCircleOnGround(GetSimContext(), x, z, 2.f, m_Overlay, cmpPosition->IsFloating());
|
||||
@ -171,7 +171,7 @@ public:
|
||||
if (!m_DebugSelectionBoxOverlay) m_DebugSelectionBoxOverlay = new SOverlayLine;
|
||||
|
||||
CmpPtr<ICmpVisual> cmpVisual(GetSimContext(), GetEntityId());
|
||||
if (!cmpVisual.null())
|
||||
if (cmpVisual)
|
||||
{
|
||||
SimRender::ConstructBoxOutline(cmpVisual->GetBounds(), *m_DebugBoundingBoxOverlay);
|
||||
m_DebugBoundingBoxOverlay->m_Thickness = 2;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -121,7 +121,7 @@ public:
|
||||
if (source != INVALID_ENTITY)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), source);
|
||||
if (!cmpPosition.null() && cmpPosition->IsInWorld())
|
||||
if (cmpPosition && cmpPosition->IsInWorld())
|
||||
sourcePos = CVector3D(cmpPosition->GetPosition());
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -111,7 +111,7 @@ public:
|
||||
u16 vertices = GetVerticesPerSide();
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpObstructionManager.null())
|
||||
if (cmpObstructionManager)
|
||||
{
|
||||
cmpObstructionManager->SetBounds(entity_pos_t::Zero(), entity_pos_t::Zero(),
|
||||
entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE),
|
||||
@ -119,7 +119,7 @@ public:
|
||||
}
|
||||
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpRangeManager.null())
|
||||
if (cmpRangeManager)
|
||||
{
|
||||
cmpRangeManager->SetBounds(entity_pos_t::Zero(), entity_pos_t::Zero(),
|
||||
entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE),
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -197,11 +197,11 @@ public:
|
||||
void MakeDirtyIfRelevantEntity(entity_id_t ent)
|
||||
{
|
||||
CmpPtr<ICmpSettlement> cmpSettlement(GetSimContext(), ent);
|
||||
if (!cmpSettlement.null())
|
||||
if (cmpSettlement)
|
||||
MakeDirty();
|
||||
|
||||
CmpPtr<ICmpTerritoryInfluence> cmpTerritoryInfluence(GetSimContext(), ent);
|
||||
if (!cmpTerritoryInfluence.null())
|
||||
if (cmpTerritoryInfluence)
|
||||
MakeDirty();
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ void CCmpTerritoryManager::CalculateTerritories()
|
||||
continue;
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), it->first);
|
||||
if (cmpOwnership.null())
|
||||
if (!cmpOwnership)
|
||||
continue;
|
||||
|
||||
// Ignore Gaia and unassigned
|
||||
@ -393,7 +393,7 @@ void CCmpTerritoryManager::CalculateTerritories()
|
||||
|
||||
// Ignore if invalid position
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), it->first);
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
continue;
|
||||
|
||||
influenceEntities[owner].push_back(it->first);
|
||||
@ -559,7 +559,7 @@ void CCmpTerritoryManager::RasteriseInfluences(CComponentManager::InterfaceList&
|
||||
continue;
|
||||
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), it->first);
|
||||
if (cmpObstruction.null())
|
||||
if (!cmpObstruction)
|
||||
continue;
|
||||
|
||||
ICmpObstructionManager::ObstructionSquare square;
|
||||
@ -619,12 +619,12 @@ void CCmpTerritoryManager::UpdateBoundaryLines()
|
||||
CTexturePtr textureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask);
|
||||
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return;
|
||||
CTerrain* terrain = cmpTerrain->GetCTerrain();
|
||||
|
||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPlayerManager.null())
|
||||
if (!cmpPlayerManager)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < boundaries.size(); ++i)
|
||||
@ -634,7 +634,7 @@ void CCmpTerritoryManager::UpdateBoundaryLines()
|
||||
|
||||
CColor color(1, 0, 1, 1);
|
||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(boundaries[i].owner));
|
||||
if (!cmpPlayer.null())
|
||||
if (cmpPlayer)
|
||||
color = cmpPlayer->GetColour();
|
||||
|
||||
m_BoundaryLines.push_back(SBoundaryLine());
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -289,14 +289,14 @@ public:
|
||||
}
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
{
|
||||
m_PassClass = cmpPathfinder->GetPassabilityClass(paramNode.GetChild("PassabilityClass").ToUTF8());
|
||||
m_CostClass = cmpPathfinder->GetCostClass(paramNode.GetChild("CostClass").ToUTF8());
|
||||
}
|
||||
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), GetEntityId());
|
||||
if (!cmpObstruction.null())
|
||||
if (cmpObstruction)
|
||||
m_Radius = cmpObstruction->GetUnitRadius();
|
||||
|
||||
m_State = STATE_IDLE;
|
||||
@ -453,7 +453,7 @@ private:
|
||||
m_State = STATE_IDLE; // don't go through the STOPPING state since we never even started
|
||||
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), GetEntityId());
|
||||
if (!cmpObstruction.null())
|
||||
if (cmpObstruction)
|
||||
cmpObstruction->SetMovingFlag(false);
|
||||
|
||||
CMessageMotionChanged msg(true, true);
|
||||
@ -465,7 +465,7 @@ private:
|
||||
StopMoving();
|
||||
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), GetEntityId());
|
||||
if (!cmpObstruction.null())
|
||||
if (cmpObstruction)
|
||||
cmpObstruction->SetMovingFlag(false);
|
||||
|
||||
CMessageMotionChanged msg(false, true);
|
||||
@ -481,7 +481,7 @@ private:
|
||||
void MoveSucceeded()
|
||||
{
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), GetEntityId());
|
||||
if (!cmpObstruction.null())
|
||||
if (cmpObstruction)
|
||||
cmpObstruction->SetMovingFlag(false);
|
||||
|
||||
CMessageMotionChanged msg(false, false);
|
||||
@ -596,7 +596,7 @@ void CCmpUnitMotion::PathResult(u32 ticket, const ICmpPathfinder::Path& path)
|
||||
}
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
{
|
||||
StartFailed();
|
||||
return;
|
||||
@ -625,7 +625,7 @@ void CCmpUnitMotion::PathResult(u32 ticket, const ICmpPathfinder::Path& path)
|
||||
}
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
{
|
||||
StartFailed();
|
||||
return;
|
||||
@ -653,7 +653,7 @@ void CCmpUnitMotion::PathResult(u32 ticket, const ICmpPathfinder::Path& path)
|
||||
}
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
{
|
||||
StopMoving();
|
||||
return;
|
||||
@ -755,11 +755,11 @@ void CCmpUnitMotion::Move(fixed dt)
|
||||
// that problem.
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder (GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return;
|
||||
|
||||
CFixedVector2D initialPos = cmpPosition->GetPosition2D();
|
||||
@ -942,7 +942,7 @@ bool CCmpUnitMotion::ComputeTargetPosition(CFixedVector2D& out)
|
||||
return false;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_TargetEntity);
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return false;
|
||||
|
||||
if (m_TargetOffset.IsZero())
|
||||
@ -971,7 +971,7 @@ bool CCmpUnitMotion::TryGoingStraightToTargetEntity(CFixedVector2D from)
|
||||
return false;
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder (GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return false;
|
||||
|
||||
// Move the goal to match the target entity's new position
|
||||
@ -1017,10 +1017,10 @@ bool CCmpUnitMotion::CheckTargetMovement(CFixedVector2D from, entity_pos_t minDe
|
||||
// (in which case we'll continue moving to its last known location,
|
||||
// unless it comes back into view before we reach that location)
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId());
|
||||
if (!cmpOwnership.null())
|
||||
if (cmpOwnership)
|
||||
{
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (!cmpRangeManager.null())
|
||||
if (cmpRangeManager)
|
||||
{
|
||||
if (cmpRangeManager->GetLosVisibility(m_TargetEntity, cmpOwnership->GetOwner()) == ICmpRangeManager::VIS_HIDDEN)
|
||||
return false;
|
||||
@ -1062,7 +1062,7 @@ bool CCmpUnitMotion::PathIsShort(const ICmpPathfinder::Path& path, CFixedVector2
|
||||
void CCmpUnitMotion::FaceTowardsPoint(entity_pos_t x, entity_pos_t z)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return;
|
||||
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
@ -1078,7 +1078,7 @@ void CCmpUnitMotion::FaceTowardsPointFromPos(CFixedVector2D pos, entity_pos_t x,
|
||||
entity_angle_t angle = atan2_approx(offset.X, offset.Y);
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return;
|
||||
cmpPosition->TurnTo(angle);
|
||||
}
|
||||
@ -1104,7 +1104,7 @@ void CCmpUnitMotion::BeginPathing(CFixedVector2D from, const ICmpPathfinder::Goa
|
||||
|
||||
// Set our 'moving' flag, so other units pathfinding now will ignore us
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), GetEntityId());
|
||||
if (!cmpObstruction.null())
|
||||
if (cmpObstruction)
|
||||
cmpObstruction->SetMovingFlag(true);
|
||||
|
||||
// If we're aiming at a target entity and it's close and we can reach
|
||||
@ -1131,7 +1131,7 @@ void CCmpUnitMotion::BeginPathing(CFixedVector2D from, const ICmpPathfinder::Goa
|
||||
void CCmpUnitMotion::RequestLongPath(CFixedVector2D from, const ICmpPathfinder::Goal& goal)
|
||||
{
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return;
|
||||
|
||||
cmpPathfinder->SetDebugPath(from.X, from.Y, goal, m_PassClass, m_CostClass);
|
||||
@ -1142,7 +1142,7 @@ void CCmpUnitMotion::RequestLongPath(CFixedVector2D from, const ICmpPathfinder::
|
||||
void CCmpUnitMotion::RequestShortPath(CFixedVector2D from, const ICmpPathfinder::Goal& goal, bool avoidMovingUnits)
|
||||
{
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return;
|
||||
|
||||
m_ExpectedPathTicket = cmpPathfinder->ComputeShortPathAsync(from.X, from.Y, m_Radius, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, avoidMovingUnits, m_TargetEntity, GetEntityId());
|
||||
@ -1190,7 +1190,7 @@ bool CCmpUnitMotion::PickNextLongWaypoint(const CFixedVector2D& pos, bool avoidM
|
||||
}
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpPathfinder.null())
|
||||
if (!cmpPathfinder)
|
||||
return false;
|
||||
|
||||
m_ExpectedPathTicket = cmpPathfinder->ComputeShortPathAsync(pos.X, pos.Y, m_Radius, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, avoidMovingUnits, GetEntityId(), GetEntityId());
|
||||
@ -1204,7 +1204,7 @@ bool CCmpUnitMotion::MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos
|
||||
PROFILE("MoveToPointRange");
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return false;
|
||||
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
@ -1218,7 +1218,7 @@ bool CCmpUnitMotion::MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos
|
||||
// Check whether this point is in an obstruction
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return false;
|
||||
|
||||
ICmpObstructionManager::ObstructionSquare obstruction;
|
||||
@ -1303,19 +1303,19 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange
|
||||
PROFILE("MoveToTargetRange");
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return false;
|
||||
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return false;
|
||||
|
||||
bool hasObstruction = false;
|
||||
ICmpObstructionManager::ObstructionSquare obstruction;
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), target);
|
||||
if (!cmpObstruction.null())
|
||||
if (cmpObstruction)
|
||||
hasObstruction = cmpObstruction->GetObstructionSquare(obstruction);
|
||||
|
||||
/*
|
||||
@ -1433,7 +1433,7 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange
|
||||
// The target didn't have an obstruction or obstruction shape, so treat it as a point instead
|
||||
|
||||
CmpPtr<ICmpPosition> cmpTargetPosition(GetSimContext(), target);
|
||||
if (cmpTargetPosition.null() || !cmpTargetPosition->IsInWorld())
|
||||
if (!cmpTargetPosition || !cmpTargetPosition->IsInWorld())
|
||||
return false;
|
||||
|
||||
CFixedVector2D targetPos = cmpTargetPosition->GetPosition2D();
|
||||
@ -1448,19 +1448,19 @@ bool CCmpUnitMotion::IsInTargetRange(entity_id_t target, entity_pos_t minRange,
|
||||
// after that Move has completed
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return false;
|
||||
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager.null())
|
||||
if (!cmpObstructionManager)
|
||||
return false;
|
||||
|
||||
bool hasObstruction = false;
|
||||
ICmpObstructionManager::ObstructionSquare obstruction;
|
||||
CmpPtr<ICmpObstruction> cmpObstruction(GetSimContext(), target);
|
||||
if (!cmpObstruction.null())
|
||||
if (cmpObstruction)
|
||||
hasObstruction = cmpObstruction->GetObstructionSquare(obstruction);
|
||||
|
||||
if (hasObstruction)
|
||||
@ -1494,7 +1494,7 @@ bool CCmpUnitMotion::IsInTargetRange(entity_id_t target, entity_pos_t minRange,
|
||||
else
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpTargetPosition(GetSimContext(), target);
|
||||
if (cmpTargetPosition.null() || !cmpTargetPosition->IsInWorld())
|
||||
if (!cmpTargetPosition || !cmpTargetPosition->IsInWorld())
|
||||
return false;
|
||||
|
||||
CFixedVector2D targetPos = cmpTargetPosition->GetPosition2D();
|
||||
@ -1511,7 +1511,7 @@ bool CCmpUnitMotion::IsInTargetRange(entity_id_t target, entity_pos_t minRange,
|
||||
void CCmpUnitMotion::MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return;
|
||||
|
||||
CFixedVector2D pos = cmpPosition->GetPosition2D();
|
||||
@ -1539,7 +1539,7 @@ void CCmpUnitMotion::RenderPath(const ICmpPathfinder::Path& path, std::vector<SO
|
||||
{
|
||||
bool floating = false;
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
floating = cmpPosition->IsFloating();
|
||||
|
||||
lines.clear();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -239,7 +239,7 @@ public:
|
||||
if (m_Unit)
|
||||
{
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId());
|
||||
if (!cmpOwnership.null())
|
||||
if (cmpOwnership)
|
||||
m_Unit->GetModel().SetPlayerID(cmpOwnership->GetOwner());
|
||||
}
|
||||
}
|
||||
@ -494,7 +494,7 @@ void CCmpVisualActor::InitSelectionShapeDescriptor(CModelAbstract& model, const
|
||||
else if (shapeNode.GetChild("Footprint").IsOk())
|
||||
{
|
||||
CmpPtr<ICmpFootprint> cmpFootprint(GetSimContext(), GetEntityId());
|
||||
if (!cmpFootprint.null())
|
||||
if (cmpFootprint)
|
||||
{
|
||||
ICmpFootprint::EShape fpShape; // fp stands for "footprint"
|
||||
entity_pos_t fpSize0, fpSize1, fpHeight; // fp stands for "footprint"
|
||||
@ -558,7 +558,7 @@ void CCmpVisualActor::Update(fixed turnLength)
|
||||
if (!m_AnimRunThreshold.IsZero())
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
||||
if (!cmpPosition || !cmpPosition->IsInWorld())
|
||||
return;
|
||||
|
||||
float speed = cmpPosition->GetDistanceTravelled().ToFloat() / turnLength.ToFloat();
|
||||
@ -590,7 +590,7 @@ void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
||||
return;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return;
|
||||
|
||||
// Disable rendering of the unit if it has no position
|
||||
@ -603,7 +603,7 @@ void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
||||
// The 'always visible' flag means we should always render the unit
|
||||
// (regardless of whether the LOS system thinks it's visible)
|
||||
CmpPtr<ICmpVision> cmpVision(GetSimContext(), GetEntityId());
|
||||
if (!cmpVision.null() && cmpVision->GetAlwaysVisible())
|
||||
if (cmpVision && cmpVision->GetAlwaysVisible())
|
||||
{
|
||||
m_Visibility = ICmpRangeManager::VIS_VISIBLE;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -39,7 +39,7 @@ void SimRender::ConstructLineOnGround(const CSimContext& context, const std::vec
|
||||
overlay.m_Coords.clear();
|
||||
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(context, SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return;
|
||||
|
||||
if (xz.size() < 2)
|
||||
@ -48,9 +48,9 @@ void SimRender::ConstructLineOnGround(const CSimContext& context, const std::vec
|
||||
float water = 0.f;
|
||||
if (floating)
|
||||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(context, SYSTEM_ENTITY);
|
||||
if (!cmpWaterMan.null())
|
||||
water = cmpWaterMan->GetExactWaterLevel(xz[0], xz[1]);
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(context, SYSTEM_ENTITY);
|
||||
if (cmpWaterManager)
|
||||
water = cmpWaterManager->GetExactWaterLevel(xz[0], xz[1]);
|
||||
}
|
||||
|
||||
overlay.m_Coords.reserve(xz.size()/2 * 3);
|
||||
@ -72,15 +72,15 @@ void SimRender::ConstructCircleOnGround(const CSimContext& context, float x, flo
|
||||
overlay.m_Coords.clear();
|
||||
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(context, SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return;
|
||||
|
||||
float water = 0.f;
|
||||
if (floating)
|
||||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(context, SYSTEM_ENTITY);
|
||||
if (!cmpWaterMan.null())
|
||||
water = cmpWaterMan->GetExactWaterLevel(x, z);
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(context, SYSTEM_ENTITY);
|
||||
if (cmpWaterManager)
|
||||
water = cmpWaterManager->GetExactWaterLevel(x, z);
|
||||
}
|
||||
|
||||
// Adapt the circle resolution to look reasonable for small and largeish radiuses
|
||||
@ -123,15 +123,15 @@ void SimRender::ConstructSquareOnGround(const CSimContext& context, float x, flo
|
||||
overlay.m_Coords.clear();
|
||||
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(context, SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
return;
|
||||
|
||||
float water = 0.f;
|
||||
if (floating)
|
||||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(context, SYSTEM_ENTITY);
|
||||
if (!cmpWaterMan.null())
|
||||
water = cmpWaterMan->GetExactWaterLevel(x, z);
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(context, SYSTEM_ENTITY);
|
||||
if (cmpWaterManager)
|
||||
water = cmpWaterManager->GetExactWaterLevel(x, z);
|
||||
}
|
||||
|
||||
float c = cosf(a);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -34,7 +34,7 @@ std::vector<entity_id_t> EntitySelection::PickEntitiesAtPoint(CSimulation2& simu
|
||||
camera.BuildCameraRay(screenX, screenY, origin, dir);
|
||||
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(simulation, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpRangeManager.null());
|
||||
ENSURE(cmpRangeManager);
|
||||
|
||||
std::vector<std::pair<float, entity_id_t> > hits; // (dist^2, entity) pairs
|
||||
|
||||
@ -48,7 +48,7 @@ std::vector<entity_id_t> EntitySelection::PickEntitiesAtPoint(CSimulation2& simu
|
||||
continue;
|
||||
|
||||
CmpPtr<ICmpVisual> cmpVisual(simulation.GetSimContext(), ent);
|
||||
if (cmpVisual.null())
|
||||
if (!cmpVisual)
|
||||
continue;
|
||||
|
||||
CBoundingBoxOriented selectionBox = cmpVisual->GetSelectionBox();
|
||||
@ -87,7 +87,7 @@ std::vector<entity_id_t> EntitySelection::PickEntitiesInRect(CSimulation2& simul
|
||||
std::swap(sy0, sy1);
|
||||
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(simulation, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpRangeManager.null());
|
||||
ENSURE(cmpRangeManager);
|
||||
|
||||
std::vector<entity_id_t> hitEnts;
|
||||
|
||||
@ -102,7 +102,7 @@ std::vector<entity_id_t> EntitySelection::PickEntitiesInRect(CSimulation2& simul
|
||||
|
||||
// Ignore entities not owned by 'owner'
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(simulation.GetSimContext(), ent);
|
||||
if (cmpOwnership.null() || cmpOwnership->GetOwner() != owner)
|
||||
if (!cmpOwnership || cmpOwnership->GetOwner() != owner)
|
||||
continue;
|
||||
|
||||
// Find the current interpolated model position.
|
||||
@ -110,7 +110,7 @@ std::vector<entity_id_t> EntitySelection::PickEntitiesInRect(CSimulation2& simul
|
||||
// that's better for users trying to select objects in busy areas)
|
||||
|
||||
CmpPtr<ICmpVisual> cmpVisual(simulation.GetSimContext(), ent);
|
||||
if (cmpVisual.null())
|
||||
if (!cmpVisual)
|
||||
continue;
|
||||
|
||||
CVector3D position = cmpVisual->GetPosition();
|
||||
@ -158,7 +158,7 @@ std::vector<entity_id_t> EntitySelection::PickSimilarEntities(CSimulation2& simu
|
||||
|
||||
// Ignore entities not owned by 'owner'
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(simulation.GetSimContext(), ent);
|
||||
if (cmpOwnership.null() || cmpOwnership->GetOwner() != owner)
|
||||
if (!cmpOwnership || cmpOwnership->GetOwner() != owner)
|
||||
continue;
|
||||
|
||||
// Ignore off screen entities
|
||||
@ -166,7 +166,7 @@ std::vector<entity_id_t> EntitySelection::PickSimilarEntities(CSimulation2& simu
|
||||
{
|
||||
// Find the current interpolated model position.
|
||||
CmpPtr<ICmpVisual> cmpVisual(simulation.GetSimContext(), ent);
|
||||
if (cmpVisual.null())
|
||||
if (!cmpVisual)
|
||||
continue;
|
||||
CVector3D position = cmpVisual->GetPosition();
|
||||
|
||||
@ -180,7 +180,7 @@ std::vector<entity_id_t> EntitySelection::PickSimilarEntities(CSimulation2& simu
|
||||
// Match by selection group name
|
||||
// (This is relatively expensive since it involves script calls, so do it after all other tests)
|
||||
CmpPtr<ICmpIdentity> cmpIdentity(simulation.GetSimContext(), ent);
|
||||
if (cmpIdentity.null() || cmpIdentity->GetSelectionGroupName() != templateName)
|
||||
if (!cmpIdentity || cmpIdentity->GetSelectionGroupName() != templateName)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -34,7 +34,7 @@ IComponent* QueryInterface(const CSimulation2& simulation, entity_id_t ent, int
|
||||
*
|
||||
* @code
|
||||
* CmpPtr<ICmpPosition> cmpPosition(context, ent);
|
||||
* if (cmpPosition.null())
|
||||
* if (!cmpPosition)
|
||||
* // do something (maybe just silently abort; you should never crash if the
|
||||
* // component is missing, even if you're sure it should never be missing)
|
||||
* @endcode
|
||||
@ -54,6 +54,11 @@ IComponent* QueryInterface(const CSimulation2& simulation, entity_id_t ent, int
|
||||
template<typename T>
|
||||
class CmpPtr
|
||||
{
|
||||
private:
|
||||
T* m;
|
||||
typedef void (CmpPtr::*bool_type)() const;
|
||||
void this_type_does_not_support_comparisions() const {}
|
||||
|
||||
public:
|
||||
CmpPtr(const CSimContext& context, entity_id_t ent)
|
||||
{
|
||||
@ -67,10 +72,23 @@ public:
|
||||
|
||||
T* operator->() { return m; }
|
||||
|
||||
bool null() { return (m == NULL); }
|
||||
|
||||
private:
|
||||
T* m;
|
||||
operator bool_type() const
|
||||
{
|
||||
return (m != NULL) ? &CmpPtr::this_type_does_not_support_comparisions : 0;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
bool operator!=(const CmpPtr<T>& lhs, const U& rhs)
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisions();
|
||||
return false;
|
||||
}
|
||||
template<typename T, typename U>
|
||||
bool operator==(const CmpPtr<T>& lhs, const U& rhs)
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisions();
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // INCLUDED_CMPPTR
|
||||
|
@ -645,8 +645,8 @@ void CComponentManager::AddMockComponent(entity_id_t ent, InterfaceId iid, IComp
|
||||
|
||||
entity_id_t CComponentManager::AddEntity(const std::wstring& templateName, entity_id_t ent)
|
||||
{
|
||||
ICmpTemplateManager *tempMan = static_cast<ICmpTemplateManager*> (QueryInterface(SYSTEM_ENTITY, IID_TemplateManager));
|
||||
if (!tempMan)
|
||||
ICmpTemplateManager *cmpTemplateManager = static_cast<ICmpTemplateManager*> (QueryInterface(SYSTEM_ENTITY, IID_TemplateManager));
|
||||
if (!cmpTemplateManager)
|
||||
{
|
||||
debug_warn(L"No ICmpTemplateManager loaded");
|
||||
return INVALID_ENTITY;
|
||||
@ -654,7 +654,7 @@ entity_id_t CComponentManager::AddEntity(const std::wstring& templateName, entit
|
||||
|
||||
// TODO: should assert that ent doesn't exist
|
||||
|
||||
const CParamNode* tmpl = tempMan->LoadTemplate(ent, utf8_from_wstring(templateName), -1);
|
||||
const CParamNode* tmpl = cmpTemplateManager->LoadTemplate(ent, utf8_from_wstring(templateName), -1);
|
||||
if (!tmpl)
|
||||
return INVALID_ENTITY; // LoadTemplate will have reported the error
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -241,15 +241,15 @@ public:
|
||||
sim.LoadDefaultScripts();
|
||||
sim.ResetState();
|
||||
|
||||
CmpPtr<ICmpTemplateManager> cmpTempMan(sim, SYSTEM_ENTITY);
|
||||
TS_ASSERT(!cmpTempMan.null());
|
||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
|
||||
TS_ASSERT(cmpTemplateManager);
|
||||
|
||||
std::vector<std::string> templates = cmpTempMan->FindAllTemplates(true);
|
||||
std::vector<std::string> templates = cmpTemplateManager->FindAllTemplates(true);
|
||||
for (size_t i = 0; i < templates.size(); ++i)
|
||||
{
|
||||
std::string name = templates[i];
|
||||
printf("# %s\n", name.c_str());
|
||||
const CParamNode* p = cmpTempMan->GetTemplate(name);
|
||||
const CParamNode* p = cmpTemplateManager->GetTemplate(name);
|
||||
TS_ASSERT(p != NULL);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -43,6 +43,12 @@ template<class ConstSmPtr, class T> struct ConstCastHelper<ConstSmPtr, const T>
|
||||
template<class T> class AtSmartPtr : public ConstCastHelper<AtSmartPtr<const T>, T>
|
||||
{
|
||||
friend struct ConstCastHelper<AtSmartPtr<const T>, T>;
|
||||
private:
|
||||
void inc_ref();
|
||||
void dec_ref();
|
||||
T* ptr;
|
||||
typedef void (AtSmartPtr::*bool_type)() const;
|
||||
void this_type_does_not_support_comparisions() const {}
|
||||
public:
|
||||
// Constructors
|
||||
AtSmartPtr() : ptr(NULL) {}
|
||||
@ -58,15 +64,23 @@ public:
|
||||
//operator AtSmartPtr<const T> () { return AtSmartPtr<const T>(ptr); } // (actually provided by ConstCastHelper)
|
||||
// Override ->
|
||||
T* operator->() const { return ptr; }
|
||||
// Test whether the pointer is pointing to anything
|
||||
operator bool() const { return ptr!=NULL; }
|
||||
bool operator!() const { return ptr==NULL; }
|
||||
private:
|
||||
void inc_ref();
|
||||
void dec_ref();
|
||||
T* ptr;
|
||||
// Test whether the pointer is pointing to anything using safe bool
|
||||
operator bool_type() const { return (ptr!=NULL) == true ? &AtSmartPtr::this_type_does_not_support_comparisions : 0; }
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
bool operator!=(const AtSmartPtr<T>& lhs, const U& rhs)
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisions();
|
||||
return false;
|
||||
}
|
||||
template<typename T, typename U>
|
||||
bool operator==(const AtSmartPtr<T>& lhs, const U& rhs)
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisions();
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class ConstSmPtr, class T>
|
||||
ConstCastHelper<ConstSmPtr, T>::operator ConstSmPtr ()
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -113,7 +113,7 @@ public:
|
||||
}
|
||||
|
||||
CmpPtr<ICmpVisual> cmpVisual(Simulation2, Entity);
|
||||
if (!cmpVisual.null())
|
||||
if (cmpVisual)
|
||||
{
|
||||
// add selection box outlines manually
|
||||
if (SelectionBoxEnabled)
|
||||
@ -210,7 +210,7 @@ void ActorViewerImpl::UpdatePropList()
|
||||
Props.clear();
|
||||
|
||||
CmpPtr<ICmpVisual> cmpVisual(Simulation2, Entity);
|
||||
if (!cmpVisual.null())
|
||||
if (cmpVisual)
|
||||
{
|
||||
CUnit* unit = cmpVisual->GetUnit();
|
||||
if (unit)
|
||||
@ -285,11 +285,11 @@ ActorViewer::ActorViewer()
|
||||
|
||||
// Tell the simulation we've already loaded the terrain
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(m.Simulation2, SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->ReloadTerrain();
|
||||
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(m.Simulation2, SYSTEM_ENTITY);
|
||||
if (!cmpRangeManager.null())
|
||||
if (cmpRangeManager)
|
||||
cmpRangeManager->SetLosRevealAll(-1, true);
|
||||
}
|
||||
|
||||
@ -342,7 +342,7 @@ void ActorViewer::SetActor(const CStrW& name, const CStrW& animation)
|
||||
return;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(m.Simulation2, m.Entity);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
ssize_t c = TERRAIN_TILE_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2;
|
||||
cmpPosition->JumpTo(entity_pos_t::FromInt(c), entity_pos_t::FromInt(c));
|
||||
@ -365,7 +365,7 @@ void ActorViewer::SetActor(const CStrW& name, const CStrW& animation)
|
||||
if (anim == "walk")
|
||||
{
|
||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(m.Simulation2, m.Entity);
|
||||
if (!cmpUnitMotion.null())
|
||||
if (cmpUnitMotion)
|
||||
speed = cmpUnitMotion->GetWalkSpeed().ToFloat();
|
||||
else
|
||||
speed = 7.f; // typical unit speed
|
||||
@ -375,7 +375,7 @@ void ActorViewer::SetActor(const CStrW& name, const CStrW& animation)
|
||||
else if (anim == "run")
|
||||
{
|
||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(m.Simulation2, m.Entity);
|
||||
if (!cmpUnitMotion.null())
|
||||
if (cmpUnitMotion)
|
||||
speed = cmpUnitMotion->GetRunSpeed().ToFloat();
|
||||
else
|
||||
speed = 12.f; // typical unit speed
|
||||
@ -415,7 +415,7 @@ void ActorViewer::SetActor(const CStrW& name, const CStrW& animation)
|
||||
}
|
||||
|
||||
CmpPtr<ICmpVisual> cmpVisual(m.Simulation2, m.Entity);
|
||||
if (!cmpVisual.null())
|
||||
if (cmpVisual)
|
||||
{
|
||||
// TODO: SetEntitySelection(anim)
|
||||
cmpVisual->SelectAnimation(anim, false, fixed::FromFloat(speed), soundgroup);
|
||||
@ -474,7 +474,7 @@ void ActorViewer::Render()
|
||||
// and half way up the model (assuming there is one)
|
||||
CVector3D centre;
|
||||
CmpPtr<ICmpVisual> cmpVisual(m.Simulation2, m.Entity);
|
||||
if (!cmpVisual.null())
|
||||
if (cmpVisual)
|
||||
cmpVisual->GetBounds().GetCentre(centre);
|
||||
else
|
||||
centre.Y = 0.f;
|
||||
@ -535,7 +535,7 @@ void ActorViewer::Update(float dt)
|
||||
if (m.WalkEnabled && m.CurrentSpeed)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(m.Simulation2, m.Entity);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
// Move the model by speed*dt forwards
|
||||
float z = cmpPosition->GetPosition().Z.ToFloat();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -112,7 +112,7 @@ BEGIN_COMMAND(AlterElevation)
|
||||
{
|
||||
g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ BEGIN_COMMAND(SmoothElevation)
|
||||
{
|
||||
g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
||||
}
|
||||
|
||||
@ -306,7 +306,7 @@ BEGIN_COMMAND(FlattenElevation)
|
||||
{
|
||||
g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES);
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -38,10 +38,10 @@ sEnvironmentSettings GetSettings()
|
||||
{
|
||||
sEnvironmentSettings s;
|
||||
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
ENSURE(!cmpWaterMan.null());
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
ENSURE(cmpWaterManager);
|
||||
|
||||
s.waterheight = cmpWaterMan->GetExactWaterLevel(0, 0) / (65536.f * HEIGHT_SCALE);
|
||||
s.waterheight = cmpWaterManager->GetExactWaterLevel(0, 0) / (65536.f * HEIGHT_SCALE);
|
||||
|
||||
WaterManager* wm = g_Renderer.GetWaterManager();
|
||||
s.watershininess = wm->m_Shininess;
|
||||
@ -85,10 +85,10 @@ sEnvironmentSettings GetSettings()
|
||||
|
||||
void SetSettings(const sEnvironmentSettings& s)
|
||||
{
|
||||
CmpPtr<ICmpWaterManager> cmpWaterMan(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
ENSURE(!cmpWaterMan.null());
|
||||
CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
ENSURE(cmpWaterManager);
|
||||
|
||||
cmpWaterMan->SetWaterLevel(entity_pos_t::FromFloat(s.waterheight * (65536.f * HEIGHT_SCALE)));
|
||||
cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(s.waterheight * (65536.f * HEIGHT_SCALE)));
|
||||
|
||||
WaterManager* wm = g_Renderer.GetWaterManager();
|
||||
wm->m_Shininess = s.watershininess;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -68,7 +68,7 @@ namespace
|
||||
|
||||
// Disable fog-of-war
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpRangeManager.null())
|
||||
if (cmpRangeManager)
|
||||
cmpRangeManager->SetLosRevealAll(-1, true);
|
||||
}
|
||||
}
|
||||
@ -212,7 +212,7 @@ BEGIN_COMMAND(ResizeMap)
|
||||
void MakeDirty()
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->ReloadTerrain();
|
||||
|
||||
// The LOS texture won't normally get updated when running Atlas
|
||||
@ -232,7 +232,7 @@ BEGIN_COMMAND(ResizeMap)
|
||||
void Do()
|
||||
{
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (cmpTerrain.null())
|
||||
if (!cmpTerrain)
|
||||
{
|
||||
m_OldTiles = m_NewTiles = 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -62,7 +62,7 @@ namespace
|
||||
return false;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), unit->GetID());
|
||||
if (cmpPosition.null())
|
||||
if (!cmpPosition)
|
||||
return false;
|
||||
return cmpPosition->IsFloating();
|
||||
}
|
||||
@ -77,10 +77,10 @@ QUERYHANDLER(GetObjectsList)
|
||||
{
|
||||
std::vector<sObjectsListItem> objects;
|
||||
|
||||
CmpPtr<ICmpTemplateManager> cmp(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmp.null())
|
||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (cmpTemplateManager)
|
||||
{
|
||||
std::vector<std::string> names = cmp->FindAllTemplates(true);
|
||||
std::vector<std::string> names = cmpTemplateManager->FindAllTemplates(true);
|
||||
|
||||
for (std::vector<std::string>::iterator it = names.begin(); it != names.end(); ++it)
|
||||
{
|
||||
@ -114,7 +114,7 @@ MESSAGEHANDLER(SetSelectionPreview)
|
||||
for (size_t i = 0; i < g_Selection.size(); ++i)
|
||||
{
|
||||
CmpPtr<ICmpSelectable> cmpSelectable(*g_Game->GetSimulation2(), g_Selection[i]);
|
||||
if (!cmpSelectable.null())
|
||||
if (cmpSelectable)
|
||||
cmpSelectable->SetSelectionHighlight(CColor(1, 1, 1, 0));
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ MESSAGEHANDLER(SetSelectionPreview)
|
||||
for (size_t i = 0; i < g_Selection.size(); ++i)
|
||||
{
|
||||
CmpPtr<ICmpSelectable> cmpSelectable(*g_Game->GetSimulation2(), g_Selection[i]);
|
||||
if (!cmpSelectable.null())
|
||||
if (cmpSelectable)
|
||||
cmpSelectable->SetSelectionHighlight(CColor(1, 1, 1, 1));
|
||||
}
|
||||
}
|
||||
@ -136,10 +136,10 @@ QUERYHANDLER(GetObjectSettings)
|
||||
sObjectSettings settings;
|
||||
settings.player = 0;
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner (*simulation, view->GetEntityId(msg->id));
|
||||
if (!cmpOwner.null())
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(*simulation, view->GetEntityId(msg->id));
|
||||
if (cmpOwnership)
|
||||
{
|
||||
int32_t player = cmpOwner->GetOwner();
|
||||
int32_t player = cmpOwnership->GetOwner();
|
||||
if (player != -1)
|
||||
settings.player = player;
|
||||
}
|
||||
@ -201,11 +201,11 @@ BEGIN_COMMAND(SetObjectSettings)
|
||||
View* view = View::GetView(msg->view);
|
||||
CSimulation2* simulation = view->GetSimulation2();
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner (*simulation, view->GetEntityId(msg->id));
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(*simulation, view->GetEntityId(msg->id));
|
||||
m_PlayerOld = 0;
|
||||
if (!cmpOwner.null())
|
||||
if (cmpOwnership)
|
||||
{
|
||||
int32_t player = cmpOwner->GetOwner();
|
||||
int32_t player = cmpOwnership->GetOwner();
|
||||
if (player != -1)
|
||||
m_PlayerOld = player;
|
||||
}
|
||||
@ -240,9 +240,9 @@ private:
|
||||
View* view = View::GetView(msg->view);
|
||||
CSimulation2* simulation = view->GetSimulation2();
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner (*simulation, view->GetEntityId(msg->id));
|
||||
if (!cmpOwner.null())
|
||||
cmpOwner->SetOwner(player);
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(*simulation, view->GetEntityId(msg->id));
|
||||
if (cmpOwnership)
|
||||
cmpOwnership->SetOwner(player);
|
||||
|
||||
// TODO: selections
|
||||
// unit->SetActorSelections(selections);
|
||||
@ -304,11 +304,11 @@ MESSAGEHANDLER(ObjectPreview)
|
||||
{
|
||||
// Update the unit's position and orientation:
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPos (*g_Game->GetSimulation2(), g_PreviewEntityID);
|
||||
if (!cmpPos.null())
|
||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), g_PreviewEntityID);
|
||||
if (cmpPosition)
|
||||
{
|
||||
CVector3D pos = GetUnitPos(msg->pos, cmpPos->IsFloating());
|
||||
cmpPos->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
|
||||
CVector3D pos = GetUnitPos(msg->pos, cmpPosition->IsFloating());
|
||||
cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
|
||||
|
||||
float angle;
|
||||
if (msg->usetarget)
|
||||
@ -322,14 +322,14 @@ MESSAGEHANDLER(ObjectPreview)
|
||||
angle = msg->angle;
|
||||
}
|
||||
|
||||
cmpPos->SetYRotation(entity_angle_t::FromFloat(angle));
|
||||
cmpPosition->SetYRotation(entity_angle_t::FromFloat(angle));
|
||||
}
|
||||
|
||||
// TODO: handle random variations somehow
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner (*g_Game->GetSimulation2(), g_PreviewEntityID);
|
||||
if (!cmpOwner.null())
|
||||
cmpOwner->SetOwner((player_id_t)msg->settings->player);
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID);
|
||||
if (cmpOwnership)
|
||||
cmpOwnership->SetOwner((player_id_t)msg->settings->player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,16 +370,16 @@ BEGIN_COMMAND(CreateObject)
|
||||
if (m_EntityID == INVALID_ENTITY)
|
||||
return;
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPos (*g_Game->GetSimulation2(), m_EntityID);
|
||||
if (!cmpPos.null())
|
||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), m_EntityID);
|
||||
if (cmpPosition)
|
||||
{
|
||||
cmpPos->JumpTo(entity_pos_t::FromFloat(m_Pos.X), entity_pos_t::FromFloat(m_Pos.Z));
|
||||
cmpPos->SetYRotation(entity_angle_t::FromFloat(m_Angle));
|
||||
cmpPosition->JumpTo(entity_pos_t::FromFloat(m_Pos.X), entity_pos_t::FromFloat(m_Pos.Z));
|
||||
cmpPosition->SetYRotation(entity_angle_t::FromFloat(m_Angle));
|
||||
}
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner (*g_Game->GetSimulation2(), m_EntityID);
|
||||
if (!cmpOwner.null())
|
||||
cmpOwner->SetOwner(m_Player);
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), m_EntityID);
|
||||
if (cmpOwnership)
|
||||
cmpOwnership->SetOwner(m_Player);
|
||||
|
||||
// TODO: handle random variations somehow
|
||||
}
|
||||
@ -442,17 +442,17 @@ BEGIN_COMMAND(MoveObject)
|
||||
|
||||
void Do()
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (cmpPos.null())
|
||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (!cmpPosition)
|
||||
{
|
||||
// error
|
||||
m_PosOld = m_PosNew = CVector3D(0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_PosNew = GetUnitPos(msg->pos, cmpPos->IsFloating());
|
||||
m_PosNew = GetUnitPos(msg->pos, cmpPosition->IsFloating());
|
||||
|
||||
CFixedVector3D pos = cmpPos->GetPosition();
|
||||
CFixedVector3D pos = cmpPosition->GetPosition();
|
||||
m_PosOld = CVector3D(pos.X.ToFloat(), pos.Y.ToFloat(), pos.Z.ToFloat());
|
||||
}
|
||||
|
||||
@ -461,11 +461,11 @@ BEGIN_COMMAND(MoveObject)
|
||||
|
||||
void SetPos(CVector3D& pos)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (cmpPos.null())
|
||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (!cmpPosition)
|
||||
return;
|
||||
|
||||
cmpPos->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
|
||||
cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
|
||||
}
|
||||
|
||||
void Redo()
|
||||
@ -494,14 +494,14 @@ BEGIN_COMMAND(RotateObject)
|
||||
|
||||
void Do()
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (cmpPos.null())
|
||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (!cmpPosition)
|
||||
return;
|
||||
|
||||
m_AngleOld = cmpPos->GetRotation().Y.ToFloat();
|
||||
m_AngleOld = cmpPosition->GetRotation().Y.ToFloat();
|
||||
if (msg->usetarget)
|
||||
{
|
||||
CMatrix3D transform = cmpPos->GetInterpolatedTransform(0.f, false);
|
||||
CMatrix3D transform = cmpPosition->GetInterpolatedTransform(0.f, false);
|
||||
CVector3D pos = transform.GetTranslation();
|
||||
CVector3D target = msg->target->GetWorldSpace(pos.Y);
|
||||
m_AngleNew = atan2(target.X-pos.X, target.Z-pos.Z);
|
||||
@ -516,11 +516,11 @@ BEGIN_COMMAND(RotateObject)
|
||||
|
||||
void SetAngle(float angle)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (cmpPos.null())
|
||||
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)msg->id);
|
||||
if (!cmpPosition)
|
||||
return;
|
||||
|
||||
cmpPos->SetYRotation(entity_angle_t::FromFloat(angle));
|
||||
cmpPosition->SetYRotation(entity_angle_t::FromFloat(angle));
|
||||
}
|
||||
|
||||
void Redo()
|
||||
@ -570,7 +570,7 @@ BEGIN_COMMAND(DeleteObjects)
|
||||
{
|
||||
CSimulation2& sim = *g_Game->GetSimulation2();
|
||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
|
||||
ENSURE(!cmpTemplateManager.null());
|
||||
ENSURE(cmpTemplateManager);
|
||||
|
||||
std::vector<ObjectID> ids = *msg->ids;
|
||||
for (size_t i = 0; i < ids.size(); ++i)
|
||||
@ -580,12 +580,12 @@ BEGIN_COMMAND(DeleteObjects)
|
||||
obj.entityID = (entity_id_t)ids[i];
|
||||
obj.templateName = cmpTemplateManager->GetCurrentTemplateName(obj.entityID);
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner(sim, obj.entityID);
|
||||
if (!cmpOwner.null())
|
||||
obj.owner = cmpOwner->GetOwner();
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, obj.entityID);
|
||||
if (cmpOwnership)
|
||||
obj.owner = cmpOwnership->GetOwner();
|
||||
|
||||
CmpPtr<ICmpPosition> cmpPosition(sim, obj.entityID);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
obj.pos = cmpPosition->GetPosition();
|
||||
obj.rot = cmpPosition->GetRotation();
|
||||
@ -610,16 +610,16 @@ BEGIN_COMMAND(DeleteObjects)
|
||||
else
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(sim, oldObjects[i].entityID);
|
||||
if (!cmpPosition.null())
|
||||
if (cmpPosition)
|
||||
{
|
||||
cmpPosition->JumpTo(oldObjects[i].pos.X, oldObjects[i].pos.Z);
|
||||
cmpPosition->SetXZRotation(oldObjects[i].rot.X, oldObjects[i].rot.Z);
|
||||
cmpPosition->SetYRotation(oldObjects[i].rot.Y);
|
||||
}
|
||||
|
||||
CmpPtr<ICmpOwnership> cmpOwner(sim, oldObjects[i].entityID);
|
||||
if (!cmpOwner.null())
|
||||
cmpOwner->SetOwner(oldObjects[i].owner);
|
||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, oldObjects[i].entityID);
|
||||
if (cmpOwnership)
|
||||
cmpOwnership->SetOwner(oldObjects[i].owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -126,7 +126,7 @@ QUERYHANDLER(GetTerrainGroupPreviews)
|
||||
QUERYHANDLER(GetTerrainPassabilityClasses)
|
||||
{
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(*View::GetView_Game()->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
{
|
||||
std::map<std::string, ICmpPathfinder::pass_class_t> classes = cmpPathfinder->GetPassabilityClasses();
|
||||
|
||||
@ -236,7 +236,7 @@ BEGIN_COMMAND(PaintTerrain)
|
||||
{
|
||||
g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES);
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
||||
}
|
||||
|
||||
@ -325,7 +325,7 @@ BEGIN_COMMAND(ReplaceTerrain)
|
||||
{
|
||||
g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES);
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
||||
}
|
||||
|
||||
@ -404,7 +404,7 @@ BEGIN_COMMAND(FillTerrain)
|
||||
{
|
||||
g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES);
|
||||
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpTerrain.null())
|
||||
if (cmpTerrain)
|
||||
cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -240,14 +240,14 @@ void ViewGame::Render()
|
||||
// Update the pathfinder display if necessary
|
||||
if (!m_DisplayPassability.empty())
|
||||
{
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionMan(*GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpObstructionMan.null())
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(*GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager)
|
||||
{
|
||||
cmpObstructionMan->SetDebugOverlay(true);
|
||||
cmpObstructionManager->SetDebugOverlay(true);
|
||||
}
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(*GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
{
|
||||
cmpPathfinder->SetDebugOverlay(true);
|
||||
// Kind of a hack to make it update the terrain grid
|
||||
@ -274,12 +274,12 @@ void ViewGame::SetParam(const std::wstring& name, const std::wstring& value)
|
||||
{
|
||||
m_DisplayPassability = CStrW(value).ToUTF8();
|
||||
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionMan(*GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpObstructionMan.null())
|
||||
cmpObstructionMan->SetDebugOverlay(!value.empty());
|
||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(*GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (cmpObstructionManager)
|
||||
cmpObstructionManager->SetDebugOverlay(!value.empty());
|
||||
|
||||
CmpPtr<ICmpPathfinder> cmpPathfinder(*GetSimulation2(), SYSTEM_ENTITY);
|
||||
if (!cmpPathfinder.null())
|
||||
if (cmpPathfinder)
|
||||
cmpPathfinder->SetDebugOverlay(!value.empty());
|
||||
}
|
||||
else if (name == L"renderpath")
|
||||
|
Loading…
Reference in New Issue
Block a user