Getting rid of CylinderLarge, replacing with preview volume scaling support
This commit is contained in:
parent
2a38fb5b09
commit
6e3deb836c
Binary file not shown.
|
@ -319,6 +319,11 @@ public:
|
|||
memcpy(pOut + 8, &part2, 8);
|
||||
}
|
||||
|
||||
inline float ToFloat() const
|
||||
{
|
||||
return std::stof(mInternalString, nullptr);
|
||||
}
|
||||
|
||||
inline _TStdString ToStdString() const
|
||||
{
|
||||
return mInternalString;
|
||||
|
|
|
@ -320,7 +320,6 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString&
|
|||
case eAxisAlignedBoxShape: return "AxisAlignedBox";
|
||||
case eEllipsoidShape: return "Ellipsoid";
|
||||
case eCylinderShape: return "Cylinder";
|
||||
case eCylinderLargeShape: return "CylinderLarge";
|
||||
case eConditionalShape: return "Conditional";
|
||||
default: return "INVALID";
|
||||
}
|
||||
|
@ -328,6 +327,9 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString&
|
|||
|
||||
pVolume->SetAttribute("shape", *GetVolumeString(pTemp->mVolumeShape));
|
||||
|
||||
if (pTemp->mVolumeScale != 1.f)
|
||||
pVolume->SetAttribute("scale", pTemp->mVolumeScale);
|
||||
|
||||
if (pTemp->mVolumeShape == eConditionalShape)
|
||||
{
|
||||
pVolume->SetAttribute("propertyID", *pTemp->mVolumeConditionIDString);
|
||||
|
@ -355,6 +357,7 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp, const TString&
|
|||
XMLElement *pCondition = scriptXML.NewElement("condition");
|
||||
pCondition->SetAttribute("value", *strVal);
|
||||
pCondition->SetAttribute("shape", *GetVolumeString(it->Shape));
|
||||
if (it->Scale != 1.f) pCondition->SetAttribute("scale", it->Scale);
|
||||
pVolume->LinkEndChild(pCondition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -437,7 +437,6 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc
|
|||
if (strcmp(kpType, "AxisAlignedBox") == 0) return eAxisAlignedBoxShape;
|
||||
if (strcmp(kpType, "Ellipsoid") == 0) return eEllipsoidShape;
|
||||
if (strcmp(kpType, "Cylinder") == 0) return eCylinderShape;
|
||||
if (strcmp(kpType, "CylinderLarge") == 0) return eCylinderLargeShape;
|
||||
if (strcmp(kpType, "Conditional") == 0) return eConditionalShape;
|
||||
return eInvalidShape;
|
||||
};
|
||||
|
@ -447,6 +446,11 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc
|
|||
if (kpShape)
|
||||
pScript->mVolumeShape = GetVolumeType(kpShape);
|
||||
|
||||
const char *kpScale = pVolume->Attribute("scale");
|
||||
|
||||
if (kpScale)
|
||||
pScript->mVolumeScale = TString(kpScale).ToFloat();
|
||||
|
||||
// Conditional
|
||||
if (pScript->mVolumeShape == eConditionalShape)
|
||||
{
|
||||
|
@ -474,6 +478,12 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(tinyxml2::XMLDocument *pDoc
|
|||
else
|
||||
condition.Value = TString(kpConditionValue).ToInt32();
|
||||
|
||||
const char *kpConditionScale = pCondition->Attribute("scale");
|
||||
if (kpConditionScale)
|
||||
condition.Scale = TString(kpConditionScale).ToFloat();
|
||||
else
|
||||
condition.Scale = 1.f;
|
||||
|
||||
pScript->mVolumeConditions.push_back(condition);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ void CScriptObject::EvaluateProperties()
|
|||
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
|
||||
mHasInGameModel = mpTemplate->HasInGameModel(mpProperties);
|
||||
mVolumeShape = mpTemplate->VolumeShape(this);
|
||||
mVolumeScale = mpTemplate->VolumeScale(this);
|
||||
EvaluateDisplayModel();
|
||||
EvaluateBillboard();
|
||||
EvaluateCollisionModel();
|
||||
|
@ -224,3 +225,8 @@ EVolumeShape CScriptObject::VolumeShape() const
|
|||
{
|
||||
return mVolumeShape;
|
||||
}
|
||||
|
||||
float CScriptObject::VolumeScale() const
|
||||
{
|
||||
return mVolumeScale;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class CScriptObject
|
|||
bool mHasInGameModel;
|
||||
|
||||
EVolumeShape mVolumeShape;
|
||||
float mVolumeScale;
|
||||
|
||||
public:
|
||||
CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);
|
||||
|
@ -79,6 +80,7 @@ public:
|
|||
CTexture* GetBillboard() const;
|
||||
CCollisionMeshGroup* GetCollision() const;
|
||||
EVolumeShape VolumeShape() const;
|
||||
float VolumeScale() const;
|
||||
};
|
||||
|
||||
#endif // CSCRIPTOBJECT_H
|
||||
|
|
|
@ -13,6 +13,7 @@ CScriptTemplate::CScriptTemplate(CMasterTemplate *pMaster)
|
|||
mpMaster = pMaster;
|
||||
mVisible = true;
|
||||
mPreviewScale = 1.f;
|
||||
mVolumeScale = 1.f;
|
||||
mVolumeShape = eNoShape;
|
||||
}
|
||||
|
||||
|
@ -145,6 +146,35 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
|
|||
return eInvalidShape;
|
||||
}
|
||||
|
||||
if (mVolumeShape == eConditionalShape)
|
||||
{
|
||||
s32 index = CheckVolumeConditions(pObj, true);
|
||||
if (index == -1) return eInvalidShape;
|
||||
else return mVolumeConditions[index].Shape;
|
||||
}
|
||||
else return mVolumeShape;
|
||||
}
|
||||
|
||||
float CScriptTemplate::VolumeScale(CScriptObject *pObj)
|
||||
{
|
||||
if (pObj->Template() != this)
|
||||
{
|
||||
Log::Error(pObj->Template()->TemplateName() + " instance somehow called VolumeScale() on " + TemplateName() + " template");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mVolumeShape == eConditionalShape)
|
||||
{
|
||||
s32 index = CheckVolumeConditions(pObj, false);
|
||||
if (index == -1) return mVolumeScale;
|
||||
else return mVolumeConditions[index].Scale;
|
||||
}
|
||||
else return mVolumeScale;
|
||||
}
|
||||
|
||||
s32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors)
|
||||
{
|
||||
// Private function
|
||||
if (mVolumeShape == eConditionalShape)
|
||||
{
|
||||
CPropertyBase *pProp = pObj->Properties()->PropertyByIDString(mVolumeConditionIDString);
|
||||
|
@ -179,17 +209,17 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
|
|||
}
|
||||
|
||||
// Test and check whether any of the conditions are true
|
||||
for (auto it = mVolumeConditions.begin(); it != mVolumeConditions.end(); it++)
|
||||
for (u32 iCon = 0; iCon < mVolumeConditions.size(); iCon++)
|
||||
{
|
||||
if (it->Value == v)
|
||||
return it->Shape;
|
||||
if (mVolumeConditions[iCon].Value == v)
|
||||
return iCon;
|
||||
}
|
||||
|
||||
Log::Error(TemplateName() + " instance " + TString::HexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + TString::HexString((u32) v, true, true));
|
||||
return eInvalidShape;
|
||||
if (LogErrors)
|
||||
Log::Error(pObj->Template()->TemplateName() + " instance " + TString::HexString(pObj->InstanceID(), true, true, 8) + " has unexpected volume shape value of " + TString::HexString((u32) v, true, true));
|
||||
}
|
||||
|
||||
else return mVolumeShape;
|
||||
return -1;
|
||||
}
|
||||
|
||||
CStringProperty* CScriptTemplate::FindInstanceName(CPropertyStruct *pProperties)
|
||||
|
|
|
@ -81,11 +81,13 @@ private:
|
|||
|
||||
// Preview Volume
|
||||
EVolumeShape mVolumeShape;
|
||||
float mVolumeScale;
|
||||
TIDString mVolumeConditionIDString;
|
||||
|
||||
struct SVolumeCondition {
|
||||
int Value;
|
||||
EVolumeShape Shape;
|
||||
float Scale;
|
||||
};
|
||||
std::vector<SVolumeCondition> mVolumeConditions;
|
||||
|
||||
|
@ -111,6 +113,7 @@ public:
|
|||
CStructTemplate* BaseStructByCount(s32 propCount);
|
||||
CStructTemplate* BaseStructByIndex(u32 index);
|
||||
EVolumeShape VolumeShape(CScriptObject *pObj);
|
||||
float VolumeScale(CScriptObject *pObj);
|
||||
CStringProperty* FindInstanceName(CPropertyStruct *pProperties);
|
||||
CVector3Property* FindPosition(CPropertyStruct *pProperties);
|
||||
CVector3Property* FindRotation(CPropertyStruct *pProperties);
|
||||
|
@ -129,6 +132,9 @@ public:
|
|||
void AddObject(CScriptObject *pObject);
|
||||
void RemoveObject(CScriptObject *pObject);
|
||||
void SortObjects();
|
||||
|
||||
private:
|
||||
s32 CheckVolumeConditions(CScriptObject *pObj, bool LogErrors);
|
||||
};
|
||||
|
||||
#endif // CSCRIPTTEMPLATE_H
|
||||
|
|
|
@ -8,7 +8,6 @@ enum EVolumeShape
|
|||
eBoxShape,
|
||||
eEllipsoidShape,
|
||||
eCylinderShape,
|
||||
eCylinderLargeShape,
|
||||
eConditionalShape,
|
||||
eInvalidShape
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje
|
|||
: CSceneNode(pScene, pParent)
|
||||
{
|
||||
mpVolumePreviewNode = nullptr;
|
||||
mHasVolumePreview = false;
|
||||
|
||||
// Evaluate instance
|
||||
mpInstance = pObject;
|
||||
|
@ -42,29 +43,35 @@ CScriptNode::CScriptNode(CSceneManager *pScene, CSceneNode *pParent, CScriptObje
|
|||
|
||||
// Create preview volume node
|
||||
mHasValidPosition = pTemp->HasPosition();
|
||||
mHasVolumePreview = (pTemp->ScaleType() == CScriptTemplate::eScaleVolume);
|
||||
|
||||
if (mHasVolumePreview)
|
||||
if (pTemp->ScaleType() == CScriptTemplate::eScaleVolume)
|
||||
{
|
||||
EVolumeShape shape = mpInstance->VolumeShape();
|
||||
TResPtr<CModel> pVolumeModel = nullptr;
|
||||
|
||||
if ((shape == eAxisAlignedBoxShape) || (shape == eBoxShape))
|
||||
switch (shape)
|
||||
{
|
||||
case eAxisAlignedBoxShape:
|
||||
case eBoxShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeBox.cmdl");
|
||||
break;
|
||||
|
||||
else if (shape == eEllipsoidShape)
|
||||
case eEllipsoidShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeSphere.cmdl");
|
||||
break;
|
||||
|
||||
else if (shape == eCylinderShape)
|
||||
case eCylinderShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeCylinder.cmdl");
|
||||
break;
|
||||
}
|
||||
|
||||
else if (shape == eCylinderLargeShape)
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeCylinderLarge.cmdl");
|
||||
mHasVolumePreview = (pVolumeModel != nullptr);
|
||||
|
||||
if (pVolumeModel)
|
||||
if (mHasVolumePreview)
|
||||
{
|
||||
mpVolumePreviewNode = new CModelNode(pScene, this, pVolumeModel);
|
||||
mpVolumePreviewNode->SetInheritance(true, (shape != eAxisAlignedBoxShape), true);
|
||||
mpVolumePreviewNode->SetScale(mpInstance->VolumeScale());
|
||||
mpVolumePreviewNode->ForceAlphaEnabled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@
|
|||
<scale_type>volume</scale_type>
|
||||
<preview_volume shape="Conditional" propertyID="0xD5869B0B">
|
||||
<condition value="0x00" shape="Ellipsoid"/>
|
||||
<condition value="0x01" shape="CylinderLarge"/>
|
||||
<condition value="0x01" shape="Cylinder" scale="2"/>
|
||||
</preview_volume>
|
||||
</editor>
|
||||
</ScriptTemplate>
|
||||
|
|
Loading…
Reference in New Issue