CScene: General tidying up
- Ranged for, sign conversion fixes, etc.
This commit is contained in:
parent
1adb20dc0b
commit
d7574a1965
|
@ -25,12 +25,12 @@ CScene::~CScene()
|
||||||
|
|
||||||
bool CScene::IsNodeIDUsed(uint32 ID) const
|
bool CScene::IsNodeIDUsed(uint32 ID) const
|
||||||
{
|
{
|
||||||
return (mNodeMap.find(ID) != mNodeMap.end());
|
return mNodeMap.find(ID) != mNodeMap.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 CScene::CreateNodeID(uint32 SuggestedID) const
|
uint32 CScene::CreateNodeID(uint32 SuggestedID) const
|
||||||
{
|
{
|
||||||
if (SuggestedID != -1)
|
if (SuggestedID != UINT32_MAX)
|
||||||
{
|
{
|
||||||
if (IsNodeIDUsed(SuggestedID))
|
if (IsNodeIDUsed(SuggestedID))
|
||||||
errorf("Suggested node ID is already being used! New ID will be created.");
|
errorf("Suggested node ID is already being used! New ID will be created.");
|
||||||
|
@ -48,51 +48,55 @@ uint32 CScene::CreateNodeID(uint32 SuggestedID) const
|
||||||
|
|
||||||
CModelNode* CScene::CreateModelNode(CModel *pModel, uint32 NodeID)
|
CModelNode* CScene::CreateModelNode(CModel *pModel, uint32 NodeID)
|
||||||
{
|
{
|
||||||
if (pModel == nullptr) return nullptr;
|
if (pModel == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
uint32 ID = CreateNodeID(NodeID);
|
const uint32 ID = CreateNodeID(NodeID);
|
||||||
CModelNode *pNode = new CModelNode(this, ID, mpAreaRootNode, pModel);
|
auto* pNode = new CModelNode(this, ID, mpAreaRootNode, pModel);
|
||||||
mNodes[ENodeType::Model].push_back(pNode);
|
mNodes[ENodeType::Model].push_back(pNode);
|
||||||
mNodeMap[ID] = pNode;
|
mNodeMap.insert_or_assign(ID, pNode);
|
||||||
mNumNodes++;
|
mNumNodes++;
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CStaticNode* CScene::CreateStaticNode(CStaticModel *pModel, uint32 NodeID)
|
CStaticNode* CScene::CreateStaticNode(CStaticModel *pModel, uint32 NodeID)
|
||||||
{
|
{
|
||||||
if (pModel == nullptr) return nullptr;
|
if (pModel == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
uint32 ID = CreateNodeID(NodeID);
|
const uint32 ID = CreateNodeID(NodeID);
|
||||||
CStaticNode *pNode = new CStaticNode(this, ID, mpAreaRootNode, pModel);
|
auto* pNode = new CStaticNode(this, ID, mpAreaRootNode, pModel);
|
||||||
mNodes[ENodeType::Static].push_back(pNode);
|
mNodes[ENodeType::Static].push_back(pNode);
|
||||||
mNodeMap[ID] = pNode;
|
mNodeMap.insert_or_assign(ID, pNode);
|
||||||
mNumNodes++;
|
mNumNodes++;
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCollisionNode* CScene::CreateCollisionNode(CCollisionMeshGroup *pMesh, uint32 NodeID)
|
CCollisionNode* CScene::CreateCollisionNode(CCollisionMeshGroup *pMesh, uint32 NodeID)
|
||||||
{
|
{
|
||||||
if (pMesh == nullptr) return nullptr;
|
if (pMesh == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
uint32 ID = CreateNodeID(NodeID);
|
const uint32 ID = CreateNodeID(NodeID);
|
||||||
CCollisionNode *pNode = new CCollisionNode(this, ID, mpAreaRootNode, pMesh);
|
auto* pNode = new CCollisionNode(this, ID, mpAreaRootNode, pMesh);
|
||||||
mNodes[ENodeType::Collision].push_back(pNode);
|
mNodes[ENodeType::Collision].push_back(pNode);
|
||||||
mNodeMap[ID] = pNode;
|
mNodeMap.insert_or_assign(ID, pNode);
|
||||||
mNumNodes++;
|
mNumNodes++;
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CScriptNode* CScene::CreateScriptNode(CScriptObject *pObj, uint32 NodeID)
|
CScriptNode* CScene::CreateScriptNode(CScriptObject *pObj, uint32 NodeID)
|
||||||
{
|
{
|
||||||
if (pObj == nullptr) return nullptr;
|
if (pObj == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
uint32 ID = CreateNodeID(NodeID);
|
const uint32 ID = CreateNodeID(NodeID);
|
||||||
uint32 InstanceID = pObj->InstanceID();
|
const uint32 InstanceID = pObj->InstanceID();
|
||||||
|
|
||||||
CScriptNode *pNode = new CScriptNode(this, ID, mpAreaRootNode, pObj);
|
auto *pNode = new CScriptNode(this, ID, mpAreaRootNode, pObj);
|
||||||
mNodes[ENodeType::Script].push_back(pNode);
|
mNodes[ENodeType::Script].push_back(pNode);
|
||||||
mNodeMap[ID] = pNode;
|
mNodeMap.insert_or_assign(ID, pNode);
|
||||||
mScriptMap[InstanceID] = pNode;
|
mScriptMap.insert_or_assign(InstanceID, pNode);
|
||||||
pNode->BuildLightList(mpArea);
|
pNode->BuildLightList(mpArea);
|
||||||
|
|
||||||
// AreaAttributes check
|
// AreaAttributes check
|
||||||
|
@ -100,7 +104,7 @@ CScriptNode* CScene::CreateScriptNode(CScriptObject *pObj, uint32 NodeID)
|
||||||
{
|
{
|
||||||
case 0x4E: // MP1 AreaAttributes ID
|
case 0x4E: // MP1 AreaAttributes ID
|
||||||
case FOURCC('REAA'): // MP2/MP3/DKCR AreaAttributes ID
|
case FOURCC('REAA'): // MP2/MP3/DKCR AreaAttributes ID
|
||||||
mAreaAttributesObjects.emplace_back( CAreaAttributes(pObj) );
|
mAreaAttributesObjects.emplace_back(pObj);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,21 +114,22 @@ CScriptNode* CScene::CreateScriptNode(CScriptObject *pObj, uint32 NodeID)
|
||||||
|
|
||||||
CLightNode* CScene::CreateLightNode(CLight *pLight, uint32 NodeID)
|
CLightNode* CScene::CreateLightNode(CLight *pLight, uint32 NodeID)
|
||||||
{
|
{
|
||||||
if (pLight == nullptr) return nullptr;
|
if (pLight == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
uint32 ID = CreateNodeID(NodeID);
|
const uint32 ID = CreateNodeID(NodeID);
|
||||||
CLightNode *pNode = new CLightNode(this, ID, mpAreaRootNode, pLight);
|
auto *pNode = new CLightNode(this, ID, mpAreaRootNode, pLight);
|
||||||
mNodes[ENodeType::Light].push_back(pNode);
|
mNodes[ENodeType::Light].push_back(pNode);
|
||||||
mNodeMap[ID] = pNode;
|
mNodeMap.insert_or_assign(ID, pNode);
|
||||||
mNumNodes++;
|
mNumNodes++;
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScene::DeleteNode(CSceneNode *pNode)
|
void CScene::DeleteNode(CSceneNode *pNode)
|
||||||
{
|
{
|
||||||
ENodeType Type = pNode->NodeType();
|
const ENodeType Type = pNode->NodeType();
|
||||||
|
|
||||||
for (auto it = mNodes[Type].begin(); it != mNodes[Type].end(); it++)
|
for (auto it = mNodes[Type].begin(); it != mNodes[Type].end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it == pNode)
|
if (*it == pNode)
|
||||||
{
|
{
|
||||||
|
@ -133,23 +138,21 @@ void CScene::DeleteNode(CSceneNode *pNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto MapIt = mNodeMap.find(pNode->ID());
|
if (const auto MapIt = mNodeMap.find(pNode->ID()); MapIt != mNodeMap.end())
|
||||||
if (MapIt != mNodeMap.end())
|
|
||||||
mNodeMap.erase(MapIt);
|
mNodeMap.erase(MapIt);
|
||||||
|
|
||||||
if (Type == ENodeType::Script)
|
if (Type == ENodeType::Script)
|
||||||
{
|
{
|
||||||
CScriptNode *pScript = static_cast<CScriptNode*>(pNode);
|
auto *pScript = static_cast<CScriptNode*>(pNode);
|
||||||
|
|
||||||
auto it = mScriptMap.find(pScript->Instance()->InstanceID());
|
if (const auto it = mScriptMap.find(pScript->Instance()->InstanceID()); it != mScriptMap.end())
|
||||||
if (it != mScriptMap.end())
|
|
||||||
mScriptMap.erase(it);
|
mScriptMap.erase(it);
|
||||||
|
|
||||||
switch (pScript->Instance()->ObjectTypeID())
|
switch (pScript->Instance()->ObjectTypeID())
|
||||||
{
|
{
|
||||||
case 0x4E:
|
case 0x4E:
|
||||||
case FOURCC('REAA'):
|
case FOURCC('REAA'):
|
||||||
for (auto it = mAreaAttributesObjects.begin(); it != mAreaAttributesObjects.end(); it++)
|
for (auto it = mAreaAttributesObjects.begin(); it != mAreaAttributesObjects.end(); ++it)
|
||||||
{
|
{
|
||||||
if ((*it).Instance() == pScript->Instance())
|
if ((*it).Instance() == pScript->Instance())
|
||||||
{
|
{
|
||||||
|
@ -275,8 +278,8 @@ void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInf
|
||||||
PostLoad();
|
PostLoad();
|
||||||
|
|
||||||
// Override show flags in game mode
|
// Override show flags in game mode
|
||||||
FShowFlags ShowFlags = (rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags);
|
const FShowFlags ShowFlags = rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags;
|
||||||
FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags);
|
const FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags);
|
||||||
|
|
||||||
for (CSceneIterator It(this, NodeFlags, false); It; ++It)
|
for (CSceneIterator It(this, NodeFlags, false); It; ++It)
|
||||||
{
|
{
|
||||||
|
@ -287,8 +290,8 @@ void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInf
|
||||||
|
|
||||||
SRayIntersection CScene::SceneRayCast(const CRay& rkRay, const SViewInfo& rkViewInfo)
|
SRayIntersection CScene::SceneRayCast(const CRay& rkRay, const SViewInfo& rkViewInfo)
|
||||||
{
|
{
|
||||||
FShowFlags ShowFlags = (rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags);
|
const FShowFlags ShowFlags = rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags;
|
||||||
FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags);
|
const FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags);
|
||||||
CRayCollisionTester Tester(rkRay);
|
CRayCollisionTester Tester(rkRay);
|
||||||
|
|
||||||
for (CSceneIterator It(this, NodeFlags, false); It; ++It)
|
for (CSceneIterator It(this, NodeFlags, false); It; ++It)
|
||||||
|
@ -302,18 +305,22 @@ SRayIntersection CScene::SceneRayCast(const CRay& rkRay, const SViewInfo& rkView
|
||||||
|
|
||||||
CSceneNode* CScene::NodeByID(uint32 NodeID)
|
CSceneNode* CScene::NodeByID(uint32 NodeID)
|
||||||
{
|
{
|
||||||
auto it = mNodeMap.find(NodeID);
|
const auto it = mNodeMap.find(NodeID);
|
||||||
|
|
||||||
if (it != mNodeMap.end()) return it->second;
|
if (it != mNodeMap.cend())
|
||||||
else return nullptr;
|
return it->second;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CScriptNode* CScene::NodeForInstanceID(uint32 InstanceID)
|
CScriptNode* CScene::NodeForInstanceID(uint32 InstanceID)
|
||||||
{
|
{
|
||||||
auto it = mScriptMap.find(InstanceID);
|
const auto it = mScriptMap.find(InstanceID);
|
||||||
|
|
||||||
if (it != mScriptMap.end()) return it->second;
|
if (it != mScriptMap.cend())
|
||||||
else return nullptr;
|
return it->second;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CScriptNode* CScene::NodeForInstance(CScriptObject *pObj)
|
CScriptNode* CScene::NodeForInstance(CScriptObject *pObj)
|
||||||
|
@ -326,23 +333,23 @@ CLightNode* CScene::NodeForLight(CLight *pLight)
|
||||||
// Slow. Is there a better way to do this?
|
// Slow. Is there a better way to do this?
|
||||||
std::vector<CSceneNode*>& rLights = mNodes[ENodeType::Light];
|
std::vector<CSceneNode*>& rLights = mNodes[ENodeType::Light];
|
||||||
|
|
||||||
for (auto it = rLights.begin(); it != rLights.end(); it++)
|
const auto iter = std::find_if(rLights.begin(), rLights.end(),
|
||||||
{
|
[pLight](const auto* entry) { return static_cast<const CLightNode*>(entry)->Light() == pLight; });
|
||||||
CLightNode *pNode = static_cast<CLightNode*>(*it);
|
|
||||||
if (pNode->Light() == pLight) return pNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (iter == rLights.cend())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
return static_cast<CLightNode*>(*iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
CModel* CScene::ActiveSkybox()
|
CModel* CScene::ActiveSkybox()
|
||||||
{
|
{
|
||||||
bool SkyEnabled = false;
|
bool SkyEnabled = false;
|
||||||
|
|
||||||
for (uint32 iAtt = 0; iAtt < mAreaAttributesObjects.size(); iAtt++)
|
for (auto& rkAttributes : mAreaAttributesObjects)
|
||||||
{
|
{
|
||||||
const CAreaAttributes& rkAttributes = mAreaAttributesObjects[iAtt];
|
if (rkAttributes.IsSkyEnabled())
|
||||||
if (rkAttributes.IsSkyEnabled()) SkyEnabled = true;
|
SkyEnabled = true;
|
||||||
|
|
||||||
if (rkAttributes.IsLayerEnabled())
|
if (rkAttributes.IsLayerEnabled())
|
||||||
{
|
{
|
||||||
|
@ -350,13 +357,16 @@ CModel* CScene::ActiveSkybox()
|
||||||
{
|
{
|
||||||
SkyEnabled = true;
|
SkyEnabled = true;
|
||||||
CModel *pSky = rkAttributes.SkyModel();
|
CModel *pSky = rkAttributes.SkyModel();
|
||||||
if (pSky) return pSky;
|
if (pSky != nullptr)
|
||||||
|
return pSky;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SkyEnabled) return mpWorld->DefaultSkybox();
|
if (SkyEnabled)
|
||||||
else return nullptr;
|
return mpWorld->DefaultSkybox();
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGameArea* CScene::ActiveArea()
|
CGameArea* CScene::ActiveArea()
|
||||||
|
@ -368,21 +378,21 @@ CGameArea* CScene::ActiveArea()
|
||||||
FShowFlags CScene::ShowFlagsForNodeFlags(FNodeFlags NodeFlags)
|
FShowFlags CScene::ShowFlagsForNodeFlags(FNodeFlags NodeFlags)
|
||||||
{
|
{
|
||||||
FShowFlags Out;
|
FShowFlags Out;
|
||||||
if (NodeFlags & ENodeType::Model) Out |= EShowFlag::SplitWorld;
|
if ((NodeFlags & ENodeType::Model) != 0) Out |= EShowFlag::SplitWorld;
|
||||||
if (NodeFlags & ENodeType::Static) Out |= EShowFlag::MergedWorld;
|
if ((NodeFlags & ENodeType::Static) != 0) Out |= EShowFlag::MergedWorld;
|
||||||
if (NodeFlags & ENodeType::Script) Out |= EShowFlag::Objects;
|
if ((NodeFlags & ENodeType::Script) != 0) Out |= EShowFlag::Objects;
|
||||||
if (NodeFlags & ENodeType::Collision) Out |= EShowFlag::WorldCollision;
|
if ((NodeFlags & ENodeType::Collision) != 0) Out |= EShowFlag::WorldCollision;
|
||||||
if (NodeFlags & ENodeType::Light) Out |= EShowFlag::Lights;
|
if ((NodeFlags & ENodeType::Light) != 0) Out |= EShowFlag::Lights;
|
||||||
return Out;
|
return Out;
|
||||||
}
|
}
|
||||||
|
|
||||||
FNodeFlags CScene::NodeFlagsForShowFlags(FShowFlags ShowFlags)
|
FNodeFlags CScene::NodeFlagsForShowFlags(FShowFlags ShowFlags)
|
||||||
{
|
{
|
||||||
FNodeFlags Out = ENodeType::Root;
|
FNodeFlags Out = ENodeType::Root;
|
||||||
if (ShowFlags & EShowFlag::SplitWorld) Out |= ENodeType::Model;
|
if ((ShowFlags & EShowFlag::SplitWorld) != 0) Out |= ENodeType::Model;
|
||||||
if (ShowFlags & EShowFlag::MergedWorld) Out |= ENodeType::Static;
|
if ((ShowFlags & EShowFlag::MergedWorld) != 0) Out |= ENodeType::Static;
|
||||||
if (ShowFlags & EShowFlag::WorldCollision) Out |= ENodeType::Collision;
|
if ((ShowFlags & EShowFlag::WorldCollision) != 0) Out |= ENodeType::Collision;
|
||||||
if (ShowFlags & EShowFlag::Objects) Out |= ENodeType::Script | ENodeType::ScriptExtra;
|
if ((ShowFlags & EShowFlag::Objects) != 0) Out |= ENodeType::Script | ENodeType::ScriptExtra;
|
||||||
if (ShowFlags & EShowFlag::Lights) Out |= ENodeType::Light;
|
if ((ShowFlags & EShowFlag::Lights) != 0) Out |= ENodeType::Light;
|
||||||
return Out;
|
return Out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue