diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index a58bb06759..1b3657eb64 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -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 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 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; diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp index 0cb1707e96..0da01f810e 100644 --- a/source/graphics/LOSTexture.cpp +++ b/source/graphics/LOSTexture.cpp @@ -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 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 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 cmpRangeManager(m_Simulation, SYSTEM_ENTITY); - if (cmpRangeManager.null()) + if (!cmpRangeManager) return; ICmpRangeManager::CLosQuerier los (cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID())); diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index fa799907db..0262f2f90a 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -288,14 +288,14 @@ int CMapReader::ApplyData() CmpPtr 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 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 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 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 cmpWaterMan(*m_MapReader.pSimContext, SYSTEM_ENTITY); - ENSURE(!cmpWaterMan.null()); - cmpWaterMan->SetWaterLevel(entity_pos_t::FromString(waterelement.GetText())); + CmpPtr 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 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 cmpOwner(sim, ent); - if (!cmpOwner.null()) - cmpOwner->SetOwner(PlayerID); + CmpPtr 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 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 cmpOwner(sim, ent); - if (!cmpOwner.null()) - cmpOwner->SetOwner(currEnt.playerID); + CmpPtr 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 cmpWaterMan(*pSimulation2, SYSTEM_ENTITY); - ENSURE(!cmpWaterMan.null()); - cmpWaterMan->SetWaterLevel(entity_pos_t::FromFloat(waterHeight)); + CmpPtr cmpWaterManager(*pSimulation2, SYSTEM_ENTITY); + ENSURE(cmpWaterManager); + cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(waterHeight)); // If we have graphics, get rest of settings if (pWaterMan) diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index e7f0c51c3a..f2fad569b5 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -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 cmpWaterMan(*pSimulation2, SYSTEM_ENTITY); - ENSURE(!cmpWaterMan.null()); - XML_Setting("Height", cmpWaterMan->GetExactWaterLevel(0, 0)); + CmpPtr 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 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 cmpOwner(sim, ent); - if (!cmpOwner.null()) - XML_Setting("Player", (int)cmpOwner->GetOwner()); + CmpPtr cmpOwnership(sim, ent); + if (cmpOwnership) + XML_Setting("Player", (int)cmpOwnership->GetOwner()); CmpPtr cmpPosition(sim, ent); - if (!cmpPosition.null()) + if (cmpPosition) { CFixedVector3D pos = cmpPosition->GetPosition(); CFixedVector3D rot = cmpPosition->GetRotation(); diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index d75832df0f..e1117721fe 100644 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -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 cmpTerrain(m_Simulation, SYSTEM_ENTITY); - if (cmpTerrain.null()) + if (!cmpTerrain) return NULL; return cmpTerrain->GetCTerrain(); } diff --git a/source/graphics/TerritoryTexture.cpp b/source/graphics/TerritoryTexture.cpp index 336be12aae..2c303cac35 100644 --- a/source/graphics/TerritoryTexture.cpp +++ b/source/graphics/TerritoryTexture.cpp @@ -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 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 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 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 cmpTerritoryManager(m_Simulation, SYSTEM_ENTITY); - if (cmpTerritoryManager.null()) + if (!cmpTerritoryManager) return; const Grid territories = cmpTerritoryManager->GetTerritoryGrid(); @@ -182,7 +182,7 @@ void CTerritoryTexture::GenerateBitmap(const Grid& territories, u8* bitmap, { CColor color(1, 0, 1, 1); CmpPtr cmpPlayer(m_Simulation, cmpPlayerManager->GetPlayerByID(p)); - if (!cmpPlayer.null()) + if (cmpPlayer) color = cmpPlayer->GetColour(); colors.push_back(color); } diff --git a/source/graphics/UnitAnimation.cpp b/source/graphics/UnitAnimation.cpp index e4942af7ec..98972d5c30 100644 --- a/source/graphics/UnitAnimation.cpp +++ b/source/graphics/UnitAnimation.cpp @@ -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 cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - if (!cmpSoundManager.null()) + if (cmpSoundManager) cmpSoundManager->PlaySoundGroup(m_ActionSound, m_Entity); } diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp index 9f4a9f4c2d..0c9e289250 100644 --- a/source/gui/MiniMap.cpp +++ b/source/gui/MiniMap.cpp @@ -271,7 +271,7 @@ void CMiniMap::Draw() CSimulation2* sim = g_Game->GetSimulation2(); CmpPtr 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(); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 38fc2c9f17..38ad32224a 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -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 gui(*sim, SYSTEM_ENTITY); - if (gui.null()) + CmpPtr 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 queue(*sim, SYSTEM_ENTITY); - if (queue.null()) + CmpPtr cmpCommandQueue(*sim, SYSTEM_ENTITY); + if (!cmpCommandQueue) return; jsval cmd2 = sim->GetScriptInterface().CloneValueFromOtherContext(guiManager->GetScriptInterface(), cmd.get()); - queue->PostNetworkCommand(cmd2); + cmpCommandQueue->PostNetworkCommand(cmd2); } std::vector PickEntitiesAtPoint(void* UNUSED(cbdata), int x, int y) diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index afcab01f7a..83ec259cb4 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -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 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 cmpPlayer(*m_Simulation2, cmpPlayerManager->GetPlayerByID(i)); - if (cmpPlayer.null()) + if (!cmpPlayer) m_PlayerColours[i] = BrokenColor; else m_PlayerColours[i] = cmpPlayer->GetColour(); diff --git a/source/renderer/DecalRData.cpp b/source/renderer/DecalRData.cpp index bd960a15fd..93d31dac79 100644 --- a/source/renderer/DecalRData.cpp +++ b/source/renderer/DecalRData.cpp @@ -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; diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index d6b3bb368f..b7270b64a5 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -581,7 +581,7 @@ void CPatchRData::BuildSide(std::vector& 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 cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - if (cmpWaterManager.null()) + if (!cmpWaterManager) return; // Build data for water diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 55868051e7..893b6545e5 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -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 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 cmpPathfinder(simContext, SYSTEM_ENTITY); - if (!cmpPathfinder.null()) + if (cmpPathfinder) cmpPathfinder->FinishAsyncRequests(); // Push AI commands onto the queue before we use them CmpPtr cmpAIManager(simContext, SYSTEM_ENTITY); - if (!cmpAIManager.null()) + if (cmpAIManager) cmpAIManager->PushCommands(); CmpPtr 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 diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index e555d9e7eb..b991d80270 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -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 cmpRangeManager(GetSimContext(), SYSTEM_ENTITY); - if (!cmpRangeManager.null()) + if (cmpRangeManager) cmpRangeManager->SetLosRevealAll(player, true); } @@ -605,7 +605,7 @@ public: ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); CmpPtr 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 dummyGrid; const Grid* passabilityMap = &dummyGrid; CmpPtr cmpPathfinder(GetSimContext(), SYSTEM_ENTITY); - if (!cmpPathfinder.null()) + if (cmpPathfinder) passabilityMap = &cmpPathfinder->GetPassabilityGrid(); // Get the territory data @@ -623,7 +623,7 @@ public: Grid dummyGrid2; const Grid* territoryMap = &dummyGrid2; CmpPtr 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 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 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 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 cmpPathfinder(GetSimContext(), SYSTEM_ENTITY); - if (cmpPathfinder.null()) + if (!cmpPathfinder) return; ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); diff --git a/source/simulation2/components/CCmpDecay.cpp b/source/simulation2/components/CCmpDecay.cpp index a9d33a1ee4..af756614d1 100644 --- a/source/simulation2/components/CCmpDecay.cpp +++ b/source/simulation2/components/CCmpDecay.cpp @@ -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 (msg); CmpPtr 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 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 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()); diff --git a/source/simulation2/components/CCmpFootprint.cpp b/source/simulation2/components/CCmpFootprint.cpp index ffc5c1854f..019aea33c7 100644 --- a/source/simulation2/components/CCmpFootprint.cpp +++ b/source/simulation2/components/CCmpFootprint.cpp @@ -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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null() || !cmpPosition->IsInWorld()) + if (!cmpPosition || !cmpPosition->IsInWorld()) return error; CmpPtr cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); - if (cmpObstructionManager.null()) + if (!cmpObstructionManager) return error; entity_pos_t spawnedRadius; ICmpObstructionManager::tag_t spawnedTag; CmpPtr 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 cmpUnitMotion(GetSimContext(), spawned); - if (cmpUnitMotion.null()) + if (!cmpUnitMotion) return error; ICmpPathfinder::pass_class_t spawnedPass = cmpUnitMotion->GetPassabilityClass(); CmpPtr cmpPathfinder(GetSimContext(), SYSTEM_ENTITY); - if (cmpPathfinder.null()) + if (!cmpPathfinder) return error; CFixedVector2D initialPos = cmpPosition->GetPosition2D(); diff --git a/source/simulation2/components/CCmpMinimap.cpp b/source/simulation2/components/CCmpMinimap.cpp index 8040c00668..ac8004d4e0 100644 --- a/source/simulation2/components/CCmpMinimap.cpp +++ b/source/simulation2/components/CCmpMinimap.cpp @@ -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 cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY); - if (cmpPlayerManager.null()) + if (!cmpPlayerManager) break; CmpPtr cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(msgData.to)); - if (cmpPlayer.null()) + if (!cmpPlayer) break; CColor colour = cmpPlayer->GetColour(); m_R = (u8)(colour.r*255.0); diff --git a/source/simulation2/components/CCmpMotionBall.cpp b/source/simulation2/components/CCmpMotionBall.cpp index 6487665eff..66cbb64343 100644 --- a/source/simulation2/components/CCmpMotionBall.cpp +++ b/source/simulation2/components/CCmpMotionBall.cpp @@ -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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null()) + if (!cmpPosition) return; // TODO: this is all FP-unsafe diff --git a/source/simulation2/components/CCmpObstruction.cpp b/source/simulation2/components/CCmpObstruction.cpp index 81eda03dff..92325ba3c0 100644 --- a/source/simulation2/components/CCmpObstruction.cpp +++ b/source/simulation2/components/CCmpObstruction.cpp @@ -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 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 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 cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); - if (cmpObstructionManager.null()) + if (!cmpObstructionManager) return; // error CmpPtr cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null()) + if (!cmpPosition) return; // error if (!cmpPosition->IsInWorld()) @@ -258,7 +258,7 @@ public: if (m_Tag.valid()) { CmpPtr 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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null()) + if (!cmpPosition) return false; // error CmpPtr 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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null()) + if (!cmpPosition) return false; // error if (!cmpPosition->IsInWorld()) @@ -343,7 +343,7 @@ public: CFixedVector2D pos = cmpPosition->GetPosition2D(); CmpPtr cmpPathfinder(GetSimContext(), SYSTEM_ENTITY); - if (cmpPathfinder.null()) + if (!cmpPathfinder) return false; // error // Get passability class @@ -363,7 +363,7 @@ public: std::vector ret; CmpPtr cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null()) + if (!cmpPosition) return ret; // error if (!cmpPosition->IsInWorld()) @@ -372,7 +372,7 @@ public: CFixedVector2D pos = cmpPosition->GetPosition2D(); CmpPtr 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 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 cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); - if (!cmpObstructionManager.null()) + if (cmpObstructionManager) cmpObstructionManager->SetUnitControlGroup(m_Tag, m_ControlGroup); } } diff --git a/source/simulation2/components/CCmpOverlayRenderer.cpp b/source/simulation2/components/CCmpOverlayRenderer.cpp index eb73ddba4e..f0b63a0626 100644 --- a/source/simulation2/components/CCmpOverlayRenderer.cpp +++ b/source/simulation2/components/CCmpOverlayRenderer.cpp @@ -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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null() || !cmpPosition->IsInWorld()) + if (!cmpPosition || !cmpPosition->IsInWorld()) { m_Enabled = false; return; diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index 4ebdf08c9f..d91eb06e3f 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -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& CCmpPathfinder::GetPassabilityGrid() void CCmpPathfinder::UpdateGrid() { CmpPtr 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 cmpWaterMan(GetSimContext(), SYSTEM_ENTITY); + CmpPtr 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 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 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 cmpObstruction(GetSimContext(), id); - if (cmpObstruction.null()) + if (!cmpObstruction) return false; ICmpObstructionManager::ObstructionSquare square; diff --git a/source/simulation2/components/CCmpPathfinder_Vertex.cpp b/source/simulation2/components/CCmpPathfinder_Vertex.cpp index 89d7622f4c..b2f01712a0 100644 --- a/source/simulation2/components/CCmpPathfinder_Vertex.cpp +++ b/source/simulation2/components/CCmpPathfinder_Vertex.cpp @@ -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 cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); - if (cmpObstructionManager.null()) + if (!cmpObstructionManager) return false; if (cmpObstructionManager->TestLine(filter, x0, z0, x1, z1, r)) diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp index b566c58130..94e0385721 100644 --- a/source/simulation2/components/CCmpPosition.cpp +++ b/source/simulation2/components/CCmpPosition.cpp @@ -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 cmpTerrain(GetSimContext(), SYSTEM_ENTITY); - if (!cmpTerrain.null()) + if (cmpTerrain) baseY = cmpTerrain->GetGroundLevel(m_X, m_Z); if (m_Floating) { - CmpPtr cmpWaterMan(GetSimContext(), SYSTEM_ENTITY); - if (!cmpWaterMan.null()) - baseY = std::max(baseY, cmpWaterMan->GetWaterLevel(m_X, m_Z)); + CmpPtr 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 cmpTerrain(GetSimContext(), SYSTEM_ENTITY); - if (!cmpTerrain.null()) + if (cmpTerrain) baseY = cmpTerrain->GetExactGroundLevel(x, z); if (m_Floating || forceFloating) { - CmpPtr cmpWaterMan(GetSimContext(), SYSTEM_ENTITY); - if (!cmpWaterMan.null()) - baseY = std::max(baseY, cmpWaterMan->GetExactWaterLevel(x, z)); + CmpPtr cmpWaterManager(GetSimContext(), SYSTEM_ENTITY); + if (cmpWaterManager) + baseY = std::max(baseY, cmpWaterManager->GetExactWaterLevel(x, z)); } } diff --git a/source/simulation2/components/CCmpProjectileManager.cpp b/source/simulation2/components/CCmpProjectileManager.cpp index df413301b4..ccd569f715 100644 --- a/source/simulation2/components/CCmpProjectileManager.cpp +++ b/source/simulation2/components/CCmpProjectileManager.cpp @@ -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 sourceVisual(GetSimContext(), source); - if (sourceVisual.null()) + CmpPtr 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 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 targetPos(GetSimContext(), targetEnt); - if (targetPos.null()) + CmpPtr 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 targetPos(GetSimContext(), projectile.targetEnt); - if (!targetPos.null() && targetPos->IsInWorld()) + CmpPtr 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 cmpTerrain(GetSimContext(), SYSTEM_ENTITY); - if (!cmpTerrain.null()) + if (cmpTerrain) { float h = cmpTerrain->GetExactGroundLevel(projectile.pos.X, projectile.pos.Z); if (projectile.pos.Y < h) diff --git a/source/simulation2/components/CCmpRallyPointRenderer.cpp b/source/simulation2/components/CCmpRallyPointRenderer.cpp index 7e5a8c9ced..bc6e3606c3 100644 --- a/source/simulation2/components/CCmpRallyPointRenderer.cpp +++ b/source/simulation2/components/CCmpRallyPointRenderer.cpp @@ -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 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 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 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 cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(ownerId)); - if (!cmpPlayer.null()) + if (cmpPlayer) { CmpPtr 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 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 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& coords, CmpPtr cmpPosition, CmpPtr 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& CmpPtr cmpPathFinder(GetSimContext(), SYSTEM_ENTITY); CmpPtr cmpTerrain(GetSimContext(), SYSTEM_ENTITY); CmpPtr cmpWaterManager(GetSimContext(), SYSTEM_ENTITY); - ENSURE(!cmpPathFinder.null() && !cmpTerrain.null() && !cmpWaterManager.null()); + ENSURE(cmpPathFinder && cmpTerrain && cmpWaterManager); if (coords.size() < 3) return; diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 488307338f..efaf69c23f 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -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 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 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 r; CmpPtr 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 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 cmpSourcePosition(GetSimContext(), q.source); - if (cmpSourcePosition.null() || !cmpSourcePosition->IsInWorld()) + if (!cmpSourcePosition || !cmpSourcePosition->IsInWorld()) continue; std::vector r; @@ -726,7 +726,7 @@ public: void PerformQuery(const Query& q, std::vector& r) { CmpPtr 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 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 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 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 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 cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY); - if (cmpTerritoryManager.null() || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID)) + if (!cmpTerritoryManager || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID)) return; const Grid& grid = cmpTerritoryManager->GetTerritoryGrid(); diff --git a/source/simulation2/components/CCmpSelectable.cpp b/source/simulation2/components/CCmpSelectable.cpp index 7b41e02a86..fdf715897c 100644 --- a/source/simulation2/components/CCmpSelectable.cpp +++ b/source/simulation2/components/CCmpSelectable.cpp @@ -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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null()) + if (!cmpPosition) return; if (!cmpPosition->IsInWorld()) @@ -141,7 +141,7 @@ public: cmpPosition->GetInterpolatedPosition2D(frameOffset, x, z, rotY); CmpPtr 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 cmpVisual(GetSimContext(), GetEntityId()); - if (!cmpVisual.null()) + if (cmpVisual) { SimRender::ConstructBoxOutline(cmpVisual->GetBounds(), *m_DebugBoundingBoxOverlay); m_DebugBoundingBoxOverlay->m_Thickness = 2; diff --git a/source/simulation2/components/CCmpSoundManager.cpp b/source/simulation2/components/CCmpSoundManager.cpp index 993a3e15f4..a81239b45e 100644 --- a/source/simulation2/components/CCmpSoundManager.cpp +++ b/source/simulation2/components/CCmpSoundManager.cpp @@ -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 cmpPosition(GetSimContext(), source); - if (!cmpPosition.null() && cmpPosition->IsInWorld()) + if (cmpPosition && cmpPosition->IsInWorld()) sourcePos = CVector3D(cmpPosition->GetPosition()); } diff --git a/source/simulation2/components/CCmpTerrain.cpp b/source/simulation2/components/CCmpTerrain.cpp index 1a1c4f83d6..f1476f2be9 100644 --- a/source/simulation2/components/CCmpTerrain.cpp +++ b/source/simulation2/components/CCmpTerrain.cpp @@ -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 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 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), diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index fe911d46d6..0ffdd62c4b 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -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 cmpSettlement(GetSimContext(), ent); - if (!cmpSettlement.null()) + if (cmpSettlement) MakeDirty(); CmpPtr cmpTerritoryInfluence(GetSimContext(), ent); - if (!cmpTerritoryInfluence.null()) + if (cmpTerritoryInfluence) MakeDirty(); } @@ -379,7 +379,7 @@ void CCmpTerritoryManager::CalculateTerritories() continue; CmpPtr 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 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 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 cmpTerrain(GetSimContext(), SYSTEM_ENTITY); - if (cmpTerrain.null()) + if (!cmpTerrain) return; CTerrain* terrain = cmpTerrain->GetCTerrain(); CmpPtr 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 cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(boundaries[i].owner)); - if (!cmpPlayer.null()) + if (cmpPlayer) color = cmpPlayer->GetColour(); m_BoundaryLines.push_back(SBoundaryLine()); diff --git a/source/simulation2/components/CCmpUnitMotion.cpp b/source/simulation2/components/CCmpUnitMotion.cpp index 9309b3e93b..65deeaa9eb 100644 --- a/source/simulation2/components/CCmpUnitMotion.cpp +++ b/source/simulation2/components/CCmpUnitMotion.cpp @@ -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 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 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 cmpObstruction(GetSimContext(), GetEntityId()); - if (!cmpObstruction.null()) + if (cmpObstruction) cmpObstruction->SetMovingFlag(false); CMessageMotionChanged msg(true, true); @@ -465,7 +465,7 @@ private: StopMoving(); CmpPtr cmpObstruction(GetSimContext(), GetEntityId()); - if (!cmpObstruction.null()) + if (cmpObstruction) cmpObstruction->SetMovingFlag(false); CMessageMotionChanged msg(false, true); @@ -481,7 +481,7 @@ private: void MoveSucceeded() { CmpPtr 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 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 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 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 cmpPathfinder (GetSimContext(), SYSTEM_ENTITY); - if (cmpPathfinder.null()) + if (!cmpPathfinder) return; CmpPtr 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 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 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 cmpOwnership(GetSimContext(), GetEntityId()); - if (!cmpOwnership.null()) + if (cmpOwnership) { CmpPtr 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 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 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 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 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 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 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 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 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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null() || !cmpPosition->IsInWorld()) + if (!cmpPosition || !cmpPosition->IsInWorld()) return false; CFixedVector2D pos = cmpPosition->GetPosition2D(); CmpPtr cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); - if (cmpObstructionManager.null()) + if (!cmpObstructionManager) return false; bool hasObstruction = false; ICmpObstructionManager::ObstructionSquare obstruction; CmpPtr 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 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 cmpPosition(GetSimContext(), GetEntityId()); - if (cmpPosition.null() || !cmpPosition->IsInWorld()) + if (!cmpPosition || !cmpPosition->IsInWorld()) return false; CFixedVector2D pos = cmpPosition->GetPosition2D(); CmpPtr cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); - if (cmpObstructionManager.null()) + if (!cmpObstructionManager) return false; bool hasObstruction = false; ICmpObstructionManager::ObstructionSquare obstruction; CmpPtr 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 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 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 cmpPosition(GetSimContext(), GetEntityId()); - if (!cmpPosition.null()) + if (cmpPosition) floating = cmpPosition->IsFloating(); lines.clear(); diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp index 4285666e3b..33163db7c2 100644 --- a/source/simulation2/components/CCmpVisualActor.cpp +++ b/source/simulation2/components/CCmpVisualActor.cpp @@ -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 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 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 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 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 cmpVision(GetSimContext(), GetEntityId()); - if (!cmpVision.null() && cmpVision->GetAlwaysVisible()) + if (cmpVision && cmpVision->GetAlwaysVisible()) { m_Visibility = ICmpRangeManager::VIS_VISIBLE; } diff --git a/source/simulation2/helpers/Render.cpp b/source/simulation2/helpers/Render.cpp index a8d9b3431d..450a28d00f 100644 --- a/source/simulation2/helpers/Render.cpp +++ b/source/simulation2/helpers/Render.cpp @@ -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 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 cmpWaterMan(context, SYSTEM_ENTITY); - if (!cmpWaterMan.null()) - water = cmpWaterMan->GetExactWaterLevel(xz[0], xz[1]); + CmpPtr 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 cmpTerrain(context, SYSTEM_ENTITY); - if (cmpTerrain.null()) + if (!cmpTerrain) return; float water = 0.f; if (floating) { - CmpPtr cmpWaterMan(context, SYSTEM_ENTITY); - if (!cmpWaterMan.null()) - water = cmpWaterMan->GetExactWaterLevel(x, z); + CmpPtr 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 cmpTerrain(context, SYSTEM_ENTITY); - if (cmpTerrain.null()) + if (!cmpTerrain) return; float water = 0.f; if (floating) { - CmpPtr cmpWaterMan(context, SYSTEM_ENTITY); - if (!cmpWaterMan.null()) - water = cmpWaterMan->GetExactWaterLevel(x, z); + CmpPtr cmpWaterManager(context, SYSTEM_ENTITY); + if (cmpWaterManager) + water = cmpWaterManager->GetExactWaterLevel(x, z); } float c = cosf(a); diff --git a/source/simulation2/helpers/Selection.cpp b/source/simulation2/helpers/Selection.cpp index 87836203eb..84077508e3 100644 --- a/source/simulation2/helpers/Selection.cpp +++ b/source/simulation2/helpers/Selection.cpp @@ -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 EntitySelection::PickEntitiesAtPoint(CSimulation2& simu camera.BuildCameraRay(screenX, screenY, origin, dir); CmpPtr cmpRangeManager(simulation, SYSTEM_ENTITY); - ENSURE(!cmpRangeManager.null()); + ENSURE(cmpRangeManager); std::vector > hits; // (dist^2, entity) pairs @@ -48,7 +48,7 @@ std::vector EntitySelection::PickEntitiesAtPoint(CSimulation2& simu continue; CmpPtr cmpVisual(simulation.GetSimContext(), ent); - if (cmpVisual.null()) + if (!cmpVisual) continue; CBoundingBoxOriented selectionBox = cmpVisual->GetSelectionBox(); @@ -87,7 +87,7 @@ std::vector EntitySelection::PickEntitiesInRect(CSimulation2& simul std::swap(sy0, sy1); CmpPtr cmpRangeManager(simulation, SYSTEM_ENTITY); - ENSURE(!cmpRangeManager.null()); + ENSURE(cmpRangeManager); std::vector hitEnts; @@ -102,7 +102,7 @@ std::vector EntitySelection::PickEntitiesInRect(CSimulation2& simul // Ignore entities not owned by 'owner' CmpPtr 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 EntitySelection::PickEntitiesInRect(CSimulation2& simul // that's better for users trying to select objects in busy areas) CmpPtr cmpVisual(simulation.GetSimContext(), ent); - if (cmpVisual.null()) + if (!cmpVisual) continue; CVector3D position = cmpVisual->GetPosition(); @@ -158,7 +158,7 @@ std::vector EntitySelection::PickSimilarEntities(CSimulation2& simu // Ignore entities not owned by 'owner' CmpPtr 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 EntitySelection::PickSimilarEntities(CSimulation2& simu { // Find the current interpolated model position. CmpPtr cmpVisual(simulation.GetSimContext(), ent); - if (cmpVisual.null()) + if (!cmpVisual) continue; CVector3D position = cmpVisual->GetPosition(); @@ -180,7 +180,7 @@ std::vector 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 cmpIdentity(simulation.GetSimContext(), ent); - if (cmpIdentity.null() || cmpIdentity->GetSelectionGroupName() != templateName) + if (!cmpIdentity || cmpIdentity->GetSelectionGroupName() != templateName) continue; } diff --git a/source/simulation2/system/CmpPtr.h b/source/simulation2/system/CmpPtr.h index 19176b5d03..e3d836067a 100644 --- a/source/simulation2/system/CmpPtr.h +++ b/source/simulation2/system/CmpPtr.h @@ -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 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 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 + bool operator!=(const CmpPtr& lhs, const U& rhs) + { + lhs.this_type_does_not_support_comparisions(); + return false; + } +template + bool operator==(const CmpPtr& lhs, const U& rhs) + { + lhs.this_type_does_not_support_comparisions(); + return false; + } + #endif // INCLUDED_CMPPTR diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index 251c6893dd..a2e244f920 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -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 (QueryInterface(SYSTEM_ENTITY, IID_TemplateManager)); - if (!tempMan) + ICmpTemplateManager *cmpTemplateManager = static_cast (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 diff --git a/source/simulation2/tests/test_CmpTemplateManager.h b/source/simulation2/tests/test_CmpTemplateManager.h index 7581b73fc0..486da7a87c 100644 --- a/source/simulation2/tests/test_CmpTemplateManager.h +++ b/source/simulation2/tests/test_CmpTemplateManager.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 @@ -241,15 +241,15 @@ public: sim.LoadDefaultScripts(); sim.ResetState(); - CmpPtr cmpTempMan(sim, SYSTEM_ENTITY); - TS_ASSERT(!cmpTempMan.null()); + CmpPtr cmpTemplateManager(sim, SYSTEM_ENTITY); + TS_ASSERT(cmpTemplateManager); - std::vector templates = cmpTempMan->FindAllTemplates(true); + std::vector 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); } } diff --git a/source/tools/atlas/AtlasObject/AtlasObject.h b/source/tools/atlas/AtlasObject/AtlasObject.h index bb2702a4e5..59338c7539 100644 --- a/source/tools/atlas/AtlasObject/AtlasObject.h +++ b/source/tools/atlas/AtlasObject/AtlasObject.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 @@ -43,6 +43,12 @@ template struct ConstCastHelper template class AtSmartPtr : public ConstCastHelper, T> { friend struct ConstCastHelper, 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 () { return AtSmartPtr(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 + bool operator!=(const AtSmartPtr& lhs, const U& rhs) + { + lhs.this_type_does_not_support_comparisions(); + return false; + } +template + bool operator==(const AtSmartPtr& lhs, const U& rhs) + { + lhs.this_type_does_not_support_comparisions(); + return false; + } + template ConstCastHelper::operator ConstSmPtr () { diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index 188d6af8d7..78b8acadb6 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -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 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 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 cmpTerrain(m.Simulation2, SYSTEM_ENTITY); - if (!cmpTerrain.null()) + if (cmpTerrain) cmpTerrain->ReloadTerrain(); CmpPtr 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 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 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 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 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 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 cmpPosition(m.Simulation2, m.Entity); - if (!cmpPosition.null()) + if (cmpPosition) { // Move the model by speed*dt forwards float z = cmpPosition->GetPosition().Z.ToFloat(); diff --git a/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp index acd0c3344e..cb7883bd29 100644 --- a/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp @@ -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 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 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 cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - if (!cmpTerrain.null()) + if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } diff --git a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp index 139357cdd6..d302e0d940 100644 --- a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp @@ -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 cmpWaterMan(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - ENSURE(!cmpWaterMan.null()); + CmpPtr 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 cmpWaterMan(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - ENSURE(!cmpWaterMan.null()); + CmpPtr 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; diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index 4e31d83c8c..e7099d808f 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -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 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 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 cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - if (cmpTerrain.null()) + if (!cmpTerrain) { m_OldTiles = m_NewTiles = 0; } diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index f9a4ac3c7e..1a0bb6b788 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -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 cmpPosition(*g_Game->GetSimulation2(), unit->GetID()); - if (cmpPosition.null()) + if (!cmpPosition) return false; return cmpPosition->IsFloating(); } @@ -77,10 +77,10 @@ QUERYHANDLER(GetObjectsList) { std::vector objects; - CmpPtr cmp(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - if (!cmp.null()) + CmpPtr cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + if (cmpTemplateManager) { - std::vector names = cmp->FindAllTemplates(true); + std::vector names = cmpTemplateManager->FindAllTemplates(true); for (std::vector::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 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 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 cmpOwner (*simulation, view->GetEntityId(msg->id)); - if (!cmpOwner.null()) + CmpPtr 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 cmpOwner (*simulation, view->GetEntityId(msg->id)); + CmpPtr 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 cmpOwner (*simulation, view->GetEntityId(msg->id)); - if (!cmpOwner.null()) - cmpOwner->SetOwner(player); + CmpPtr 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 cmpPos (*g_Game->GetSimulation2(), g_PreviewEntityID); - if (!cmpPos.null()) + CmpPtr 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 cmpOwner (*g_Game->GetSimulation2(), g_PreviewEntityID); - if (!cmpOwner.null()) - cmpOwner->SetOwner((player_id_t)msg->settings->player); + CmpPtr 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 cmpPos (*g_Game->GetSimulation2(), m_EntityID); - if (!cmpPos.null()) + CmpPtr 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 cmpOwner (*g_Game->GetSimulation2(), m_EntityID); - if (!cmpOwner.null()) - cmpOwner->SetOwner(m_Player); + CmpPtr 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 cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id); - if (cmpPos.null()) + CmpPtr 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 cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id); - if (cmpPos.null()) + CmpPtr 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 cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id); - if (cmpPos.null()) + CmpPtr 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 cmpPos(*g_Game->GetSimulation2(), (entity_id_t)msg->id); - if (cmpPos.null()) + CmpPtr 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 cmpTemplateManager(sim, SYSTEM_ENTITY); - ENSURE(!cmpTemplateManager.null()); + ENSURE(cmpTemplateManager); std::vector 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 cmpOwner(sim, obj.entityID); - if (!cmpOwner.null()) - obj.owner = cmpOwner->GetOwner(); + CmpPtr cmpOwnership(sim, obj.entityID); + if (cmpOwnership) + obj.owner = cmpOwnership->GetOwner(); CmpPtr 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 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 cmpOwner(sim, oldObjects[i].entityID); - if (!cmpOwner.null()) - cmpOwner->SetOwner(oldObjects[i].owner); + CmpPtr cmpOwnership(sim, oldObjects[i].entityID); + if (cmpOwnership) + cmpOwnership->SetOwner(oldObjects[i].owner); } } diff --git a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp index 584d8b14f7..7203dcf0c8 100644 --- a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp @@ -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 cmpPathfinder(*View::GetView_Game()->GetSimulation2(), SYSTEM_ENTITY); - if (!cmpPathfinder.null()) + if (cmpPathfinder) { std::map 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 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 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 cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); - if (!cmpTerrain.null()) + if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 1e4b1d5604..3970b9aa1e 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -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 cmpObstructionMan(*GetSimulation2(), SYSTEM_ENTITY); - if (!cmpObstructionMan.null()) + CmpPtr cmpObstructionManager(*GetSimulation2(), SYSTEM_ENTITY); + if (cmpObstructionManager) { - cmpObstructionMan->SetDebugOverlay(true); + cmpObstructionManager->SetDebugOverlay(true); } CmpPtr 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 cmpObstructionMan(*GetSimulation2(), SYSTEM_ENTITY); - if (!cmpObstructionMan.null()) - cmpObstructionMan->SetDebugOverlay(!value.empty()); + CmpPtr cmpObstructionManager(*GetSimulation2(), SYSTEM_ENTITY); + if (cmpObstructionManager) + cmpObstructionManager->SetDebugOverlay(!value.empty()); CmpPtr cmpPathfinder(*GetSimulation2(), SYSTEM_ENTITY); - if (!cmpPathfinder.null()) + if (cmpPathfinder) cmpPathfinder->SetDebugOverlay(!value.empty()); } else if (name == L"renderpath")