CSEngine
Loading...
Searching...
No Matches
CSE::SPrefab Class Reference
Inheritance diagram for CSE::SPrefab:
CSE::SResource CSE::SObject CSE::VariableBinder CSE::ReflectionObject

Public Member Functions

 RESOURCE_DEFINE_CONSTRUCTOR (SPrefab)
 
SGameObjectClone (const vec3 &position, SGameObject *parent=nullptr)
 
SGameObjectClone (const vec3 &position, const vec3 &scale, Quaternion rotation, SGameObject *parent=nullptr)
 
bool SetGameObject (SGameObject *obj)
 
void Exterminate () override
 
SGameObjectGetRoot () const
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
- Public Member Functions inherited from CSE::SResource
 SResource (std::string classType)
 
 SResource (const SResource *resource, bool isRegister)
 
void SetName (std::string name)
 
void SetAbsoluteID (std::string id)
 
std::string GetName () const
 
std::string GetAbsoluteID () const
 
AssetMgr::AssetReferenceGetAssetReference (std::string hash="") const
 
void LinkResource (AssetMgr::AssetReference *asset)
 
void LinkResource (std::string name)
 
void SetHash (std::string &hash) override
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
std::string GetHash () const
 
- Public Member Functions inherited from CSE::VariableBinder
- Public Member Functions inherited from CSE::ReflectionObject
 ReflectionObject (std::string type)
 
void SetClassType (std::string type)
 
const char * GetClassType () const
 
bool IsSameClass (const char *classType) const
 

Protected Member Functions

void Init (const AssetMgr::AssetReference *asset) override
 
void GenerateResourceID (SGameObject *obj=nullptr)
 
- Protected Member Functions inherited from CSE::SResource
- Protected Member Functions inherited from CSE::VariableBinder

Additional Inherited Members

- Static Public Member Functions inherited from CSE::SResource
template<class T >
static T * Create (const std::string &name)
 
static SResourceCreate (const std::string &name, const std::string &classType)
 
template<class T >
static T * Create (const AssetMgr::AssetReference *asset)
 
static SResourceCreate (const AssetMgr::AssetReference *asset, const std::string &classType)
 
template<class T >
static T * Get (std::string name)
 
static SResourceGet (std::string &name)
 
- Static Public Member Functions inherited from CSE::ReflectionObject
static ReflectionObjectNewObject (const std::string &name)
 
- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 
- Protected Attributes inherited from CSE::ReflectionObject
std::string m_class
 

Detailed Description

Definition at line 15 of file SPrefab.h.

Member Function Documentation

◆ Clone() [1/2]

SGameObject * SPrefab::Clone ( const vec3 & position,
const vec3 & scale,
Quaternion rotation,
SGameObject * parent = nullptr )

Definition at line 33 of file SPrefab.cpp.

33 {
34 SGameObject* clone = SCloneFactory::Clone(m_root, parent);
35
36 clone->GetTransform()->m_position = vec3(position);
37 clone->GetTransform()->m_scale = vec3(scale);
38 clone->GetTransform()->m_rotation = Quaternion(rotation);
39 clone->SetIsPrefab(false);
40 clone->SetUndestroyable(false);
41
42 return clone;
43}

◆ Clone() [2/2]

SGameObject * SPrefab::Clone ( const vec3 & position,
SGameObject * parent = nullptr )

Definition at line 22 of file SPrefab.cpp.

22 {
23 SGameObject* clone = SCloneFactory::Clone(m_root, parent);
24
25 clone->GetTransform()->m_position = vec3(position);
26 clone->SetIsPrefab(false);
27 clone->SetUndestroyable(false);
28
29 return clone;
30}

◆ Exterminate()

void SPrefab::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 19 of file SPrefab.cpp.

19 {
20}

◆ GenerateResourceID()

void SPrefab::GenerateResourceID ( SGameObject * obj = nullptr)
protected

Definition at line 97 of file SPrefab.cpp.

97 {
98 if (obj == nullptr) {
99 obj = m_root;
100 obj->SetResourceID(GetHash());
101 } else {
102 std::string resultID = obj->GetID();
103 resultID = resultID.substr(resultID.find('/') + 1);
104 obj->SetResourceID(std::string(GetHash()) + "*" + resultID);
105 }
106
107 for (auto child : obj->GetChildren()) {
108 GenerateResourceID(child);
109 }
110}

◆ GetRoot()

SGameObject * CSE::SPrefab::GetRoot ( ) const
inline

Definition at line 29 of file SPrefab.h.

29 {
30 return m_root;
31 }

◆ Init()

void SPrefab::Init ( const AssetMgr::AssetReference * asset)
overrideprotectedvirtual

Implements CSE::SResource.

Definition at line 56 of file SPrefab.cpp.

56 {
57 AssetMgr::TYPE type = asset->type;
58 std::string path = asset->name_path;
59
60 switch (type) {
61 case AssetMgr::DAE:
62 DAELoader::GeneratePrefab(path.c_str(), nullptr, nullptr, nullptr, this);
63 break;
64 }
65
66 std::string hashRaw = AssetMgr::LoadAssetFile(path + ".meta");
67 if(!hashRaw.empty()) {
68 const XNode* root = XFILE().loadBuffer(hashRaw);
69 const auto& hashData = root->getNode("hash-data");
70 std::string hash = hashData.getAttribute("hash").value;
71 SetHash(hash);
72 const auto& hashChildren = hashData.children;
73
74 if(hashData.children.size() <= 0) {
75 hashRaw = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
76 "<CSEMETA version=\"1.0.0\">\n"
77 "<hash-data hash=\"" + m_hash + "\">\n"
78 + GenerateObjectMeta(*m_root) +
79 "\n</hash-data>\n</CSEMETA>";
80 SaveTxtFile(path + ".meta", hashRaw);
81 }
82 else {
83 for(const auto& child : hashChildren) {
84 const auto& id = child.getAttribute("id").value;
85 std::string hash = child.value;
86 const auto& obj = static_cast<SGameObjectFromSPrefab*>(m_root->FindLocalByID(id));
87 if(obj == nullptr) continue;
88 obj->SetHash(hash);
89 obj->SetRefHash(hash);
90 }
91 }
92 SAFE_DELETE(root);
93 }
94 GenerateResourceID();
95}
Definition XML.h:77
Definition XML.h:43

◆ PrintValue()

std::string SPrefab::PrintValue ( ) const
overridevirtual

Implements CSE::VariableBinder.

Definition at line 134 of file SPrefab.cpp.

134 {
135 return {};
136}

◆ SetGameObject()

bool SPrefab::SetGameObject ( SGameObject * obj)

Definition at line 45 of file SPrefab.cpp.

45 {
46 if (m_root != nullptr) return false;
47
48 m_root = obj;
49 m_root->SetUndestroyable(true);
50 m_root->SetIsPrefab(true);
51 m_root->SetResourceID(GetHash(), true);
52
53 return true;
54}

◆ SetValue()

void SPrefab::SetValue ( std::string name_str,
Arguments value )
overridevirtual

Used to get serialized values. All classes that inherit from VariableBinder will unconditionally call this function first during initialization.

Parameters
name_strName of values
valueSerialized values

Implements CSE::VariableBinder.

Definition at line 130 of file SPrefab.cpp.

130 {
131
132}

The documentation for this class was generated from the following files: