mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-07-03 03:36:10 +00:00
CScriptTemplate: Make use of ranged for where applicable
This commit is contained in:
parent
d93810568b
commit
731e34b90b
@ -93,11 +93,14 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
|
|||||||
|
|
||||||
if (mVolumeShape == EVolumeShape::ConditionalShape)
|
if (mVolumeShape == EVolumeShape::ConditionalShape)
|
||||||
{
|
{
|
||||||
int32 Index = CheckVolumeConditions(pObj, true);
|
const int32 Index = CheckVolumeConditions(pObj, true);
|
||||||
if (Index == -1) return EVolumeShape::InvalidShape;
|
if (Index == -1)
|
||||||
else return mVolumeConditions[Index].Shape;
|
return EVolumeShape::InvalidShape;
|
||||||
|
|
||||||
|
return mVolumeConditions[Index].Shape;
|
||||||
}
|
}
|
||||||
else return mVolumeShape;
|
|
||||||
|
return mVolumeShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CScriptTemplate::VolumeScale(CScriptObject *pObj)
|
float CScriptTemplate::VolumeScale(CScriptObject *pObj)
|
||||||
@ -110,11 +113,14 @@ float CScriptTemplate::VolumeScale(CScriptObject *pObj)
|
|||||||
|
|
||||||
if (mVolumeShape == EVolumeShape::ConditionalShape)
|
if (mVolumeShape == EVolumeShape::ConditionalShape)
|
||||||
{
|
{
|
||||||
int32 Index = CheckVolumeConditions(pObj, false);
|
const int32 Index = CheckVolumeConditions(pObj, false);
|
||||||
if (Index == -1) return mVolumeScale;
|
if (Index == -1)
|
||||||
else return mVolumeConditions[Index].Scale;
|
return mVolumeScale;
|
||||||
|
|
||||||
|
return mVolumeConditions[Index].Scale;
|
||||||
}
|
}
|
||||||
else return mVolumeScale;
|
|
||||||
|
return mVolumeScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors)
|
int32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors)
|
||||||
@ -122,12 +128,12 @@ int32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors
|
|||||||
// Private function
|
// Private function
|
||||||
if (mVolumeShape == EVolumeShape::ConditionalShape)
|
if (mVolumeShape == EVolumeShape::ConditionalShape)
|
||||||
{
|
{
|
||||||
TIDString PropID = mVolumeConditionIDString;
|
const TIDString PropID = mVolumeConditionIDString;
|
||||||
IProperty* pProp = pObj->Template()->Properties()->ChildByIDString( PropID );
|
IProperty* pProp = pObj->Template()->Properties()->ChildByIDString(PropID);
|
||||||
|
|
||||||
// Get value of the condition test property (only boolean, integral, and enum types supported)
|
// Get value of the condition test property (only boolean, integral, and enum types supported)
|
||||||
void* pData = pObj->PropertyData();
|
void* pData = pObj->PropertyData();
|
||||||
int Val;
|
int Val = 0;
|
||||||
|
|
||||||
switch (pProp->Type())
|
switch (pProp->Type())
|
||||||
{
|
{
|
||||||
@ -136,11 +142,11 @@ int32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EPropertyType::Byte:
|
case EPropertyType::Byte:
|
||||||
Val = (int) TPropCast<CByteProperty>(pProp)->Value(pData);
|
Val = static_cast<int>(TPropCast<CByteProperty>(pProp)->Value(pData));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EPropertyType::Short:
|
case EPropertyType::Short:
|
||||||
Val = (int) TPropCast<CShortProperty>(pProp)->Value(pData);
|
Val = static_cast<int>(TPropCast<CShortProperty>(pProp)->Value(pData));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EPropertyType::Int:
|
case EPropertyType::Int:
|
||||||
@ -174,34 +180,36 @@ int32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors
|
|||||||
|
|
||||||
CResource* CScriptTemplate::FindDisplayAsset(void* pPropertyData, uint32& rOutCharIndex, uint32& rOutAnimIndex, bool& rOutIsInGame)
|
CResource* CScriptTemplate::FindDisplayAsset(void* pPropertyData, uint32& rOutCharIndex, uint32& rOutAnimIndex, bool& rOutIsInGame)
|
||||||
{
|
{
|
||||||
rOutCharIndex = -1;
|
rOutCharIndex = UINT32_MAX;
|
||||||
rOutAnimIndex = -1;
|
rOutAnimIndex = UINT32_MAX;
|
||||||
rOutIsInGame = false;
|
rOutIsInGame = false;
|
||||||
|
|
||||||
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
|
for (const auto& asset : mAssets)
|
||||||
{
|
{
|
||||||
if (it->AssetType == SEditorAsset::EAssetType::Collision) continue;
|
if (asset.AssetType == SEditorAsset::EAssetType::Collision)
|
||||||
|
continue;
|
||||||
|
|
||||||
CResource *pRes = nullptr;
|
CResource *pRes = nullptr;
|
||||||
|
|
||||||
// File
|
// File
|
||||||
if (it->AssetSource == SEditorAsset::EAssetSource::File)
|
if (asset.AssetSource == SEditorAsset::EAssetSource::File)
|
||||||
pRes = gpEditorStore->LoadResource(it->AssetLocation);
|
|
||||||
|
|
||||||
// Property
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
IProperty* pProp = mpProperties->ChildByIDString(it->AssetLocation);
|
pRes = gpEditorStore->LoadResource(asset.AssetLocation);
|
||||||
|
}
|
||||||
|
else // Property
|
||||||
|
{
|
||||||
|
IProperty* pProp = mpProperties->ChildByIDString(asset.AssetLocation);
|
||||||
|
|
||||||
if (it->AssetType == SEditorAsset::EAssetType::AnimParams && pProp->Type() == EPropertyType::AnimationSet)
|
if (asset.AssetType == SEditorAsset::EAssetType::AnimParams && pProp->Type() == EPropertyType::AnimationSet)
|
||||||
{
|
{
|
||||||
CAnimationSetProperty* pAnimSet = TPropCast<CAnimationSetProperty>(pProp);
|
auto* pAnimSet = TPropCast<CAnimationSetProperty>(pProp);
|
||||||
CAnimationParameters Params = pAnimSet->Value(pPropertyData);
|
const CAnimationParameters Params = pAnimSet->Value(pPropertyData);
|
||||||
pRes = Params.AnimSet();
|
pRes = Params.AnimSet();
|
||||||
|
|
||||||
if (pRes)
|
if (pRes != nullptr)
|
||||||
{
|
{
|
||||||
uint32 MaxNumChars = static_cast<CAnimSet*>(pRes)->NumCharacters();
|
const uint32 MaxNumChars = static_cast<const CAnimSet*>(pRes)->NumCharacters();
|
||||||
rOutCharIndex = (it->ForceNodeIndex >= 0 && it->ForceNodeIndex < (int32) MaxNumChars ? it->ForceNodeIndex : Params.CharacterIndex());
|
rOutCharIndex = (asset.ForceNodeIndex >= 0 && asset.ForceNodeIndex < static_cast<int32>(MaxNumChars) ? asset.ForceNodeIndex : Params.CharacterIndex());
|
||||||
rOutAnimIndex = Params.AnimIndex();
|
rOutAnimIndex = Params.AnimIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,17 +217,17 @@ CResource* CScriptTemplate::FindDisplayAsset(void* pPropertyData, uint32& rOutCh
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ASSERT(pProp->Type() == EPropertyType::Asset);
|
ASSERT(pProp->Type() == EPropertyType::Asset);
|
||||||
CAssetProperty* pAsset = TPropCast<CAssetProperty>(pProp);
|
auto* pAsset = TPropCast<CAssetProperty>(pProp);
|
||||||
CAssetID ID = pAsset->Value(pPropertyData);
|
const CAssetID ID = pAsset->Value(pPropertyData);
|
||||||
CResourceEntry *pEntry = gpResourceStore->FindEntry( ID );
|
if (CResourceEntry* pEntry = gpResourceStore->FindEntry(ID))
|
||||||
if (pEntry) pRes = pEntry->Load();
|
pRes = pEntry->Load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a valid resource, return
|
// If we have a valid resource, return
|
||||||
if (pRes)
|
if (pRes != nullptr)
|
||||||
{
|
{
|
||||||
rOutIsInGame = (pRes->Type() != EResourceType::Texture && it->AssetSource == SEditorAsset::EAssetSource::Property);
|
rOutIsInGame = (pRes->Type() != EResourceType::Texture && asset.AssetSource == SEditorAsset::EAssetSource::Property);
|
||||||
return pRes;
|
return pRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,29 +238,31 @@ CResource* CScriptTemplate::FindDisplayAsset(void* pPropertyData, uint32& rOutCh
|
|||||||
|
|
||||||
CCollisionMeshGroup* CScriptTemplate::FindCollision(void* pPropertyData)
|
CCollisionMeshGroup* CScriptTemplate::FindCollision(void* pPropertyData)
|
||||||
{
|
{
|
||||||
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
|
for (const auto& asset : mAssets)
|
||||||
{
|
{
|
||||||
if (it->AssetType != SEditorAsset::EAssetType::Collision) continue;
|
if (asset.AssetType != SEditorAsset::EAssetType::Collision)
|
||||||
|
continue;
|
||||||
|
|
||||||
CResource *pRes = nullptr;
|
CResource *pRes = nullptr;
|
||||||
|
|
||||||
// File
|
// File
|
||||||
if (it->AssetSource == SEditorAsset::EAssetSource::File)
|
if (asset.AssetSource == SEditorAsset::EAssetSource::File)
|
||||||
pRes = gpResourceStore->LoadResource(it->AssetLocation);
|
|
||||||
|
|
||||||
// Property
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
IProperty* pProp = mpProperties->ChildByIDString(it->AssetLocation);
|
pRes = gpResourceStore->LoadResource(asset.AssetLocation);
|
||||||
|
}
|
||||||
|
else // Property
|
||||||
|
{
|
||||||
|
IProperty* pProp = mpProperties->ChildByIDString(asset.AssetLocation);
|
||||||
|
|
||||||
if (pProp->Type() == EPropertyType::Asset)
|
if (pProp->Type() == EPropertyType::Asset)
|
||||||
{
|
{
|
||||||
CAssetProperty* pAsset = TPropCast<CAssetProperty>(pProp);
|
auto* pAsset = TPropCast<CAssetProperty>(pProp);
|
||||||
pRes = gpResourceStore->LoadResource( pAsset->Value(pPropertyData), EResourceType::DynamicCollision );
|
pRes = gpResourceStore->LoadResource( pAsset->Value(pPropertyData), EResourceType::DynamicCollision );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify resource exists + is correct type
|
// Verify resource exists + is correct type
|
||||||
if (pRes && (pRes->Type() == EResourceType::DynamicCollision))
|
if (pRes != nullptr && (pRes->Type() == EResourceType::DynamicCollision))
|
||||||
return static_cast<CCollisionMeshGroup*>(pRes);
|
return static_cast<CCollisionMeshGroup*>(pRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user