本文整理汇总了C++中CData::GetChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CData::GetChild方法的具体用法?C++ CData::GetChild怎么用?C++ CData::GetChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CData
的用法示例。
在下文中一共展示了CData::GetChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateEntitiesFromData
void CLevel::CreateEntitiesFromData(const CData* pData)
{
m_aLevelEntities.clear();
m_iNextHandle = 0;
for (size_t i = 0; i < pData->GetNumChildren(); i++)
{
CData* pChildData = pData->GetChild(i);
if (pChildData->GetKey() != "Entity")
continue;
m_aLevelEntities.push_back(CLevelEntity(m_iNextHandle++, pChildData->GetValueString()));
CLevelEntity* pEntity = &m_aLevelEntities.back();
pEntity->m_iHandle = m_aLevelEntities.size()-1;
for (size_t k = 0; k < pChildData->GetNumChildren(); k++)
{
CData* pField = pChildData->GetChild(k);
tstring sHandle = pField->GetKey();
tstring sValue = pField->GetValueString();
if (sHandle == "Output")
{
tstring sTarget;
tstring sInput;
tstring sArgs;
bool bKill = false;
for (size_t o = 0; o < pField->GetNumChildren(); o++)
{
CData* pOutputData = pField->GetChild(o);
if (pOutputData->GetKey() == "Target")
sTarget = pOutputData->GetValueString();
else if (pOutputData->GetKey() == "Input")
sInput = pOutputData->GetValueString();
else if (pOutputData->GetKey() == "Args")
sArgs = pOutputData->GetValueString();
else if (pOutputData->GetKey() == "Kill")
bKill = pOutputData->GetValueBool();
}
CLevelEntity::CLevelEntityOutput& oOutput = pEntity->GetOutputs().push_back();
oOutput.m_sOutput = sValue;
oOutput.m_sTargetName = sTarget;
oOutput.m_sInput = sInput;
oOutput.m_sArgs = sArgs;
oOutput.m_bKill = bKill;
}
else
{
pEntity->SetParameterValue(sHandle, sValue);
}
}
}
}
示例2: BuildFromInputScript
bool CGeppetto::BuildFromInputScript(const tstring& sScript)
{
FILE* fp = tfopen_asset(GetPath(sScript), "r");
if (!fp)
{
TError("Could not read input script '" + sScript + "'\n");
return false;
}
std::shared_ptr<CData> pData(new CData());
CDataSerializer::Read(fp, pData.get());
CData* pOutput = pData->FindChild("Output");
if (!pOutput)
{
TError("Could not find Output section in input script '" + sScript + "'\n");
return false;
}
CData* pGame = pData->FindChild("Game");
if (!pGame)
{
TError("Could not find Game section in input script '" + sScript + "'\n");
return false;
}
t.SetGameDirectory(FindAbsolutePath(GetPath(pGame->GetValueString())));
tstring sOutputDir = ToForwardSlashes(pOutput->GetValueString());
t.SetOutputDirectory(GetDirectory(sOutputDir));
t.SetOutputFile(GetFilename(sOutputDir));
t.SetScriptDirectory(GetDirectory((GetPath(sScript))));
m_sOutput = FindAbsolutePath(t.GetGameDirectory() + T_DIR_SEP + pOutput->GetValueString());
CData* pSceneAreas = pData->FindChild("SceneAreas");
CData* pMesh = pData->FindChild("Mesh");
CData* pPhysics = pData->FindChild("Physics");
CData* pPhysicsShapes = pData->FindChild("PhysicsShapes");
// Find all file modification times.
time_t iScriptModificationTime = GetFileModificationTime(sScript.c_str());
time_t iOutputModificationTime = GetFileModificationTime(m_sOutput.c_str());
tmap<tstring, time_t> aiSceneModificationTimes;
if (pSceneAreas)
{
for (size_t i = 0; i < pSceneAreas->GetNumChildren(); i++)
{
CData* pArea = pSceneAreas->GetChild(i);
if (pArea->GetKey() != "Area")
continue;
tstring sFile = pArea->FindChildValueString("File");
TAssert(sFile.length());
if (!sFile.length())
continue;
auto it = aiSceneModificationTimes.find(sFile);
if (it == aiSceneModificationTimes.end())
aiSceneModificationTimes[sFile] = GetFileModificationTime(sFile.c_str());
}
}
time_t iInputModificationTime = 0;
if (pMesh)
iInputModificationTime = GetFileModificationTime(pMesh->GetValueString().c_str());
time_t iPhysicsModificationTime = 0;
if (pPhysics)
iPhysicsModificationTime = GetFileModificationTime(pPhysics->GetValueString().c_str());
bool bRecompile = false;
if (iScriptModificationTime > iOutputModificationTime)
bRecompile = true;
else if (iInputModificationTime > iOutputModificationTime)
bRecompile = true;
else if (iPhysicsModificationTime > iOutputModificationTime)
bRecompile = true;
else if (m_iBinaryModificationTime > iOutputModificationTime)
bRecompile = true;
else
{
for (auto it = aiSceneModificationTimes.begin(); it != aiSceneModificationTimes.end(); it++)
{
if (it->second > iOutputModificationTime)
{
bRecompile = true;
break;
}
}
}
if (!bRecompile)
{
if (m_bForceCompile)
{
TMsg("Forcing rebuild even though no changes detected.\n");
}
//.........这里部分代码省略.........
示例3: LoadSceneAreas
bool CGeppetto::LoadSceneAreas(CData* pData)
{
tmap<tstring, std::shared_ptr<CConversionScene> > asScenes;
tmap<tstring, size_t> aiSceneIDs;
size_t iSceneArea = 0;
for (size_t i = 0; i < pData->GetNumChildren(); i++)
{
CData* pArea = pData->GetChild(i);
if (pArea->GetKey() == "NeighborDistance")
{
t.SetNeighborDistance(pArea->GetValueFloat());
continue;
}
if (pArea->GetKey() == "UseGlobalTransforms")
{
t.UseGlobalTransformations();
continue;
}
if (pArea->GetKey() == "UseLocalTransforms")
{
t.UseLocalTransformations();
continue;
}
TAssert(pArea->GetKey() == "Area");
if (pArea->GetKey() != "Area")
continue;
tstring sFile = pArea->FindChildValueString("File");
TAssert(sFile.length());
if (!sFile.length())
continue;
tstring sMesh = pArea->FindChildValueString("Mesh");
TAssert(sMesh.length());
if (!sMesh.length())
continue;
tstring sPhysics = pArea->FindChildValueString("Physics");
auto it = asScenes.find(sFile);
if (it == asScenes.end())
{
TMsg("Reading model '" + GetPath(sFile) + "' ...");
std::shared_ptr<CConversionScene> pScene(new CConversionScene());
CModelConverter c(pScene.get());
if (!c.ReadModel(GetPath(sFile)))
{
TError("Couldn't read '" + GetPath(sFile) + "'.\n");
return false;
}
TMsg(" Done.\n");
asScenes[sFile] = pScene;
}
iSceneArea++;
CToyUtil ts;
if (t.IsUsingUV())
ts.UseUV();
if (t.IsUsingNormals())
ts.UseNormals();
ts.SetGameDirectory(t.GetGameDirectory());
ts.SetOutputDirectory(t.GetOutputDirectory());
ts.SetOutputFile(tsprintf(t.GetOutputFile() + "_sa%d_" + pArea->GetValueString().tolower(), iSceneArea));
ts.UseLocalTransformations(t.IsUsingLocalTransformations());
CConversionSceneNode* pMeshNode = asScenes[sFile]->FindSceneNode(sMesh);
CConversionSceneNode* pPhysicsNode = nullptr;
if (sPhysics.length())
{
pPhysicsNode = asScenes[sFile]->FindSceneNode(sPhysics);
if (!pPhysicsNode)
TError("Couldn't find a scene node in '" + sFile + "' named '" + sMesh + "'\n");
}
TAssert(pMeshNode);
TMsg("Building scene area toy ...");
Matrix4x4 mUpLeftSwap(Vector(1, 0, 0), Vector(0, 0, 1), Vector(0, -1, 0));
if (pMeshNode)
LoadSceneNodeIntoToy(asScenes[sFile].get(), pMeshNode, mUpLeftSwap, &ts);
else
TError("Couldn't find a scene node in '" + sFile + "' named '" + sMesh + "'\n");
if (pPhysicsNode)
LoadSceneNodeIntoToyPhysics(asScenes[sFile].get(), pPhysicsNode, mUpLeftSwap, &ts);
//.........这里部分代码省略.........
示例4: AddShader
void CShaderLibrary::AddShader(const string& sFile)
{
TAssert(!Get()->m_bCompiled);
if (Get()->m_bCompiled)
return;
std::basic_ifstream<char> f(sFile.c_str());
if (!f.is_open())
{
TAssert(false);
// Couldn't open shader file
return;
}
std::shared_ptr<CData> pData(new CData());
CDataSerializer::Read(f, pData.get());
CData* pName = pData->FindChild("Name");
CData* pVertex = pData->FindChild("Vertex");
CData* pFragment = pData->FindChild("Fragment");
TAssert(pName);
if (!pName)
return;
TAssert(pVertex);
if (!pVertex)
return;
TAssert(pFragment);
if (!pFragment)
return;
Get()->m_aShaders.push_back(CShader(pName->GetValueString(), pVertex->GetValueString(), pFragment->GetValueString()));
Get()->m_aShaderNames[pName->GetValueString()] = Get()->m_aShaders.size()-1;
auto& oShader = Get()->m_aShaders.back();
for (size_t i = 0; i < pData->GetNumChildren(); i++)
{
CData* pChild = pData->GetChild(i);
if (pChild->GetKey() == "Parameter")
{
auto& oParameter = oShader.m_aParameters[pChild->GetValueString()];
oParameter.m_sName = pChild->GetValueString();
for (size_t j = 0; j < pChild->GetNumChildren(); j++)
{
CData* pUniform = pChild->GetChild(j);
if (pUniform->GetKey() == "Uniform")
{
oParameter.m_aActions.push_back(CShader::CParameter::CUniform());
auto& oUniform = oParameter.m_aActions.back();
oUniform.m_sName = pUniform->GetValueString();
oUniform.m_bTexture = false;
CData* pValue = pUniform->FindChild("Value");
CData* pTexture = pUniform->FindChild("Texture");
TAssert(!(pValue && pTexture));
TAssert(pValue || pTexture);
if (pValue)
oUniform.m_sValue = pValue->GetValueString();
else if (pTexture)
{
oUniform.m_sValue = pTexture->GetValueString();
oShader.m_asTextures.push_back(pUniform->GetValueString());
oUniform.m_bTexture = true;
}
}
else if (pUniform->GetKey() == "Blend")
{
string& sBlend = oParameter.m_sBlend;
sBlend = pUniform->GetValueString();
}
}
}
else if (pChild->GetKey() == "Defaults")
{
for (size_t j = 0; j < pChild->GetNumChildren(); j++)
{
CData* pUniform = pChild->GetChild(j);
auto& oDefault = oShader.m_aDefaults[pUniform->GetKey()];
oDefault.m_sName = pUniform->GetKey();
oDefault.m_sValue = pUniform->GetValueString();
}
}
}
}
示例5: Open
void CToySource::Open(const tstring& sFile)
{
Clear();
FILE* fp = tfopen_asset(sFile, "r");
if (!fp)
{
TError("Could not read input script '" + sFile + "'\n");
return;
}
m_sFilename = sFile;
std::shared_ptr<CData> pData(new CData());
CDataSerializer::Read(fp, pData.get());
CData* pOutput = pData->FindChild("Output");
CData* pSceneAreas = pData->FindChild("SceneAreas");
CData* pMesh = pData->FindChild("Mesh");
CData* pPhysics = pData->FindChild("Physics");
CData* pPhysicsShapes = pData->FindChild("PhysicsShapes");
if (pOutput)
m_sToyFile = pOutput->GetValueString();
else
m_sToyFile = "";
if (pMesh)
m_sMesh = pMesh->GetValueString();
else
m_sMesh = "";
if (pPhysics)
m_sPhys = pPhysics->GetValueString();
else
m_sPhys = "";
CData* pGlobalTransforms = pData->FindChild("UseGlobalTransforms");
m_bUseLocalTransforms = !pGlobalTransforms;
if (pPhysicsShapes)
{
for (size_t i = 0; i < pPhysicsShapes->GetNumChildren(); i++)
{
CData* pChild = pPhysicsShapes->GetChild(i);
TAssert(pChild->GetKey() == "Box");
if (pChild->GetKey() != "Box")
continue;
tvector<tstring> asTokens;
strtok(pChild->GetValueString(), asTokens);
TAssert(asTokens.size() == 9);
if (asTokens.size() != 9)
continue;
CPhysicsShape& oShape = m_aShapes.push_back();
oShape.m_trsTransform = pChild->GetValueTRS();
}
}
if (pSceneAreas)
{
for (size_t i = 0; i < pSceneAreas->GetNumChildren(); i++)
{
CData* pChild = pSceneAreas->GetChild(i);
if (pChild->GetKey() == "NeighborDistance")
{
m_flNeighborDistance = pChild->GetValueFloat();
continue;
}
if (pChild->GetKey() == "UseGlobalTransforms")
{
m_bUseLocalTransforms = false;
continue;
}
if (pChild->GetKey() == "UseLocalTransforms")
{
m_bUseLocalTransforms = true;
continue;
}
TAssert(pChild->GetKey() == "Area");
if (pChild->GetKey() != "Area")
continue;
auto& oArea = m_aAreas.push_back();
oArea.m_sName = pChild->GetValueString();
CData* pFile = pChild->FindChild("File");
CData* pMesh = pChild->FindChild("Mesh");
CData* pPhysics = pChild->FindChild("Physics");
if (pFile)
oArea.m_sFilename = pFile->GetValueString();
//.........这里部分代码省略.........
示例6: Open
void CToySource::Open(const tstring& sFile)
{
std::basic_ifstream<tchar> f((sFile).c_str());
if (!f.is_open())
{
TError("Could not read input script '" + sFile + "'\n");
return;
}
m_sFilename = sFile;
std::shared_ptr<CData> pData(new CData());
CDataSerializer::Read(f, pData.get());
CData* pOutput = pData->FindChild("Output");
CData* pSceneAreas = pData->FindChild("SceneAreas");
CData* pMesh = pData->FindChild("Mesh");
CData* pPhysics = pData->FindChild("Physics");
CData* pPhysicsShapes = pData->FindChild("PhysicsShapes");
TAssert(!pSceneAreas); // This is unimplemented.
if (pOutput)
m_sToyFile = pOutput->GetValueString();
else
m_sToyFile = "";
if (pMesh)
m_sMesh = pMesh->GetValueString();
else
m_sMesh = "";
if (pPhysics)
m_sPhys = pPhysics->GetValueString();
else
m_sPhys = "";
if (pPhysicsShapes)
{
for (size_t i = 0; i < pPhysicsShapes->GetNumChildren(); i++)
{
CData* pChild = pPhysicsShapes->GetChild(i);
TAssert(pChild->GetKey() == "Box");
if (pChild->GetKey() != "Box")
continue;
tvector<tstring> asTokens;
strtok(pChild->GetValueString(), asTokens);
TAssert(asTokens.size() == 9);
if (asTokens.size() != 9)
continue;
CPhysicsShape& oShape = m_aShapes.push_back();
oShape.m_trsTransform = pChild->GetValueTRS();
}
}
ToyEditor()->MarkSaved();
}