Script QoL Improvements #203

Merged
Pycorax merged 2 commits from SP3-6-c-scripting into main 2022-11-14 17:57:54 +08:00
3 changed files with 55 additions and 4 deletions
Showing only changes of commit 9e8674859c - Show all commits

View File

@ -34,8 +34,11 @@ namespace SHADE
void SHRenderable::OnDestroy()
{
// Remove from SuperBatch
Handle<SHSuperBatch> superBatch = sharedMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
superBatch->Remove(this);
if (sharedMaterial)
{
Handle<SHSuperBatch> superBatch = sharedMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
superBatch->Remove(this);
}
// Free resources
if (material)

View File

@ -288,7 +288,15 @@ namespace YAML
{
YAML::Node node;
node[MESH_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHMesh>(rhs.GetMesh()).value_or(0);
node[MAT_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHMaterial>(rhs.GetMaterial()->GetBaseMaterial()).value_or(0);
auto mat = rhs.GetMaterial();
if (mat)
{
node[MAT_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHMaterial>(rhs.GetMaterial()->GetBaseMaterial()).value_or(0);
}
else
{
node[MAT_YAML_TAG.data()] = 0;
}
return node;
}
static bool decode(YAML::Node const& node, SHRenderable& rhs)

View File

@ -28,7 +28,47 @@ namespace SHADE
template<typename FieldType>
bool SerialisationUtilities::fieldInsertYaml(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, YAML::Node& fieldNode)
{
return varInsertYamlInternal<FieldType>(fieldInfo->GetValue(object), fieldNode);
// Handle null objects
System::Object^ fieldObject = fieldInfo->GetValue(object);
if (fieldObject == nullptr)
{
// Default construct if null
if (fieldInfo->FieldType == FieldType::typeid)
{
if constexpr (std::is_same_v<FieldType, System::Enum>)
{
fieldNode = 0;
}
else if constexpr (std::is_same_v<FieldType, System::String>)
{
fieldNode = "";
}
else if constexpr (std::is_same_v<FieldType, Vector2>)
{
fieldNode.SetStyle(YAML::EmitterStyle::Flow);
fieldNode.push_back(0.0f);
fieldNode.push_back(0.0f);
}
else if constexpr (std::is_same_v<FieldType, Vector3>)
{
fieldNode.SetStyle(YAML::EmitterStyle::Flow);
fieldNode.push_back(0.0f);
fieldNode.push_back(0.0f);
fieldNode.push_back(0.0f);
}
else if constexpr (std::is_same_v<FieldType, GameObject>)
{
fieldNode = MAX_EID;
}
else
{
fieldNode = FieldType();
}
return true;
}
return false;
}
return varInsertYamlInternal<FieldType>(fieldObject, fieldNode);
}
template<typename FieldType>
bool SerialisationUtilities::varInsertYamlInternal(System::Object^ object, YAML::Node& fieldNode)