BOOL VPrefab::Instantiate(VPrefabInstanceInfo &info) { EnsureLoaded(); if (!IsLoaded()) return FALSE; // serialize from memory block (class VPrefabShapesArchive provides with transformation) VMemBlockWrapperStream inStream(m_BinaryBlock.GetBuffer(), m_iSize); VPrefabShapesArchive ar(&inStream, info); ar.SetLoadingVersion(m_Header.m_iArchiveVersion); if (info.m_bOutputInstances) info.m_Instances.EnsureSize(m_Header.m_iRootObjectCount); info.m_iInstanceCount = m_Header.m_iRootObjectCount; for (int i=0;i<m_Header.m_iRootObjectCount;i++) { VTypedObject *pObj = ar.ReadObject(NULL); if (info.m_bOutputInstances) info.m_Instances[i] = pObj; if (info.m_pParentObject!=NULL && pObj!=NULL && pObj->IsOfType(V_RUNTIME_CLASS(VisObject3D_cl))) { VisObject3D_cl *pObj3D = (VisObject3D_cl *)pObj; if (pObj3D->GetParent()==NULL) // this is how we identify the root elements pObj3D->AttachToParent(info.m_pParentObject); } } ar.Close(); return TRUE; }
/// \brief /// Returns the type of this instance if GetOwnerTypedObject is implemented for a typed object such as VisObject3D_cl. /// /// \return /// Returns the RTTI type of the child. Returns NULL if the GetOwnerTypedObject function is not re-implemented in the class that inherits. inline VType* GetOwnerTypeId() { VTypedObject* pObj = this->GetOwnerTypedObject(); if (pObj) { return pObj->GetTypeId(); } return NULL; }
//Called by the engine whenever it creates an entity VisBaseEntity_cl *VisionApp_cl::OnCreateEntity(const char *pszClassName) { VType *pType = Vision::GetTypeManager()->GetType(pszClassName); if (!pType) { Vision::Error.Warning("CreateEntity: Could not create entity of class %s, entity class is not registered", pszClassName); Vision::Error.AddReportGroupEntry(VIS_REPORTGROUPTYPE_MISSING_ENTITY_CLASS, pszClassName); return NULL; } VTypedObject *pInst = pType->CreateInstance(); if (!pInst->IsOfType(V_RUNTIME_CLASS(VisBaseEntity_cl))) { VASSERT_MSG(FALSE,"Specified class is no derived from VisBaseEntity_cl"); return NULL; } return (VisBaseEntity_cl *)pInst; }