mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Updated actor references to use filenames instead of names, to allow more efficient loading. Added backward-compatible file support to the Actor Editor.
This was SVN commit r2049.
This commit is contained in:
@@ -15,8 +15,6 @@ CObjectBase::CObjectBase()
|
||||
|
||||
bool CObjectBase::Load(const char* filename)
|
||||
{
|
||||
//static int x=0; debug_out("load %s %d\n", filename, ++x);
|
||||
|
||||
m_Variants.clear();
|
||||
|
||||
CXeromyces XeroFile;
|
||||
@@ -185,10 +183,10 @@ bool CObjectBase::Load(const char* filename)
|
||||
m_Variants.back().back().m_Frequency = CStr(option.getText()).ToInt();
|
||||
|
||||
else if (option_name == el_mesh)
|
||||
m_Variants.back().back().m_ModelFilename = option.getText();
|
||||
m_Variants.back().back().m_ModelFilename = "art/meshes/" + CStr(option.getText());
|
||||
|
||||
else if (option_name == el_texture)
|
||||
m_Variants.back().back().m_TextureFilename = option.getText();
|
||||
m_Variants.back().back().m_TextureFilename = "art/textures/" + CStr(option.getText());
|
||||
|
||||
else if (option_name == el_animations)
|
||||
{
|
||||
@@ -202,7 +200,7 @@ bool CObjectBase::Load(const char* filename)
|
||||
if (ae_name == el_name)
|
||||
anim.m_AnimName = ae.getText();
|
||||
else if (ae_name == el_file)
|
||||
anim.m_FileName = ae.getText();
|
||||
anim.m_FileName = "art/animation/" + CStr(ae.getText());
|
||||
else if (ae_name == el_speed)
|
||||
{
|
||||
anim.m_Speed = CStr(ae.getText()).ToInt() / 100.f;
|
||||
@@ -247,7 +245,7 @@ bool CObjectBase::Load(const char* filename)
|
||||
}
|
||||
else if (child_name == el_material)
|
||||
{
|
||||
m_Material = child.getText();
|
||||
m_Material = "art/materials/" + CStr(child.getText());
|
||||
}
|
||||
else
|
||||
; // unrecognised element
|
||||
@@ -265,77 +263,6 @@ bool CObjectBase::Load(const char* filename)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* // TODO: Allow saving? (Maybe not necessary)
|
||||
|
||||
bool CObjectBase::Save(const char* filename)
|
||||
{
|
||||
Handle h = vfs_open(filename, FILE_WRITE|FILE_NO_AIO);
|
||||
if (h <= 0)
|
||||
{
|
||||
debug_warn("actor open failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
XML_Start("iso-8859-1");
|
||||
XML_Doctype("Object", "/art/actors/object.dtd");
|
||||
|
||||
XML_Comment("File automatically generated by ScEd");
|
||||
|
||||
{
|
||||
XML_Element("Object");
|
||||
|
||||
XML_Setting("Name", m_Name);
|
||||
XML_Setting("ModelName", m_ModelName);
|
||||
XML_Setting("TextureName", m_TextureName);
|
||||
|
||||
if(m_Material.Trim(PS_TRIM_BOTH).Length())
|
||||
XML_Setting("Material", m_Material);
|
||||
|
||||
{
|
||||
XML_Element("Properties");
|
||||
XML_Attribute("autoflatten", m_Properties.m_AutoFlatten ? 1 : 0);
|
||||
XML_Attribute("castshadows", m_Properties.m_CastShadows ? 1 : 0);
|
||||
}
|
||||
|
||||
if (m_Animations.size()>0)
|
||||
{
|
||||
XML_Element("Animations");
|
||||
|
||||
for (uint i=0;i<m_Animations.size();i++)
|
||||
{
|
||||
XML_Element("Animation");
|
||||
XML_Attribute("name", m_Animations[i].m_AnimName);
|
||||
XML_Attribute("file", m_Animations[i].m_FileName);
|
||||
XML_Attribute("speed", int(m_Animations[i].m_Speed*100));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Props.size()>0)
|
||||
{
|
||||
XML_Element("Props");
|
||||
|
||||
for (uint i=0;i<m_Props.size();i++)
|
||||
{
|
||||
XML_Element("Prop");
|
||||
XML_Attribute("attachpoint", m_Props[i].m_PropPointName);
|
||||
XML_Attribute("model", m_Props[i].m_ModelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! XML_StoreVFS(h))
|
||||
{
|
||||
// Error occurred while saving data
|
||||
debug_warn("actor save failed");
|
||||
vfs_close(h);
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs_close(h);
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
void CObjectBase::CalculateVariation(std::set<CStr>& strings, variation_key& choices)
|
||||
{
|
||||
// Calculate a complete list of choices, one per group. In each group,
|
||||
@@ -424,47 +351,3 @@ void CObjectBase::CalculateVariation(std::set<CStr>& strings, variation_key& cho
|
||||
|
||||
assert(choices.size() == m_Variants.size());
|
||||
}
|
||||
|
||||
|
||||
// TODO: Remove this, once all the actors are renamed properly
|
||||
bool CObjectBase::LoadName(const CStr& filename, CStr& out)
|
||||
{
|
||||
CXeromyces XeroFile;
|
||||
if (XeroFile.Load(filename) != PSRETURN_OK)
|
||||
return false;
|
||||
|
||||
XMBElement root = XeroFile.getRoot();
|
||||
|
||||
if (root.getNodeName() == XeroFile.getElementID("object"))
|
||||
{
|
||||
//// Old-format actor file ////
|
||||
|
||||
#define EL(x) int el_##x = XeroFile.getElementID(#x)
|
||||
EL(name);
|
||||
#undef EL
|
||||
|
||||
XERO_ITER_EL(root, child)
|
||||
{
|
||||
if (child.getNodeName() == el_name)
|
||||
{
|
||||
out = child.getText();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
LOG(ERROR, LOG_CATEGORY, "Invalid actor format (couldn't find 'name')");
|
||||
return false;
|
||||
}
|
||||
else if (root.getNodeName() == XeroFile.getElementID("actor"))
|
||||
{
|
||||
//// New-format actor file ////
|
||||
|
||||
// Use the filename for the model's name
|
||||
out = CStr(filename).AfterLast("/").BeforeLast(".xml");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR, LOG_CATEGORY, "Invalid actor format (unrecognised root element '%s')", XeroFile.getElementString(root.getNodeName()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user