OpenClonk
C4MeshDenumerator Class Reference

#include <C4MeshDenumerator.h>

Inheritance diagram for C4MeshDenumerator:
[legend]
Collaboration diagram for C4MeshDenumerator:
[legend]

Public Member Functions

 C4MeshDenumerator ()
 
 C4MeshDenumerator (C4Def *def)
 
 C4MeshDenumerator (C4Object *object)
 
C4ObjectGetObject ()
 
void CompileFunc (StdCompiler *pComp, StdMeshInstance::AttachedMesh *attach) override
 
void DenumeratePointers (StdMeshInstance::AttachedMesh *attach) override
 
bool ClearPointers (C4Object *pObj) override
 

Detailed Description

Definition at line 25 of file C4MeshDenumerator.h.

Constructor & Destructor Documentation

◆ C4MeshDenumerator() [1/3]

C4MeshDenumerator::C4MeshDenumerator ( )
inline

Definition at line 32 of file C4MeshDenumerator.h.

32 : Object(nullptr) {}

References Object().

Here is the call graph for this function:

◆ C4MeshDenumerator() [2/3]

C4MeshDenumerator::C4MeshDenumerator ( C4Def def)
inline

Definition at line 33 of file C4MeshDenumerator.h.

33 : Def(def), Object(nullptr) {}

References Object().

Here is the call graph for this function:

◆ C4MeshDenumerator() [3/3]

C4MeshDenumerator::C4MeshDenumerator ( C4Object object)
inline

Definition at line 34 of file C4MeshDenumerator.h.

34 : Def(nullptr), Object(object) {}

References Object().

Here is the call graph for this function:

Member Function Documentation

◆ ClearPointers()

bool C4MeshDenumerator::ClearPointers ( C4Object pObj)
overridevirtual

Reimplemented from StdMeshInstance::AttachedMesh::Denumerator.

Definition at line 97 of file C4MeshDenumerator.cpp.

98 {
99  if (Object == pObj)
100  {
101  Object = nullptr;
102  // Return false causes the attached mesh to be deleted by StdMeshInstance
103  return false;
104  }
105 
106  return true;
107 }

◆ CompileFunc()

void C4MeshDenumerator::CompileFunc ( StdCompiler pComp,
StdMeshInstance::AttachedMesh attach 
)
overridevirtual

Implements StdMeshInstance::AttachedMesh::Denumerator.

Definition at line 26 of file C4MeshDenumerator.cpp.

27 {
28  if (pComp->isDeserializer())
29  {
30  int32_t def;
31  pComp->Value(mkNamingCountAdapt(def, "ChildInstance"));
32 
33  if (def)
34  {
35  C4DefGraphics* pGfx = nullptr;
36  pComp->Value(mkNamingAdapt(C4DefGraphicsAdapt(pGfx), "ChildMesh"));
37  Def = pGfx->pDef;
38 
39  if (pGfx->Type != C4DefGraphics::TYPE_Mesh)
40  {
41  pComp->excCorrupt("ChildMesh points to non-mesh graphics");
42  }
43  assert(!attach->Child);
44  pComp->Value(mkParAdapt(mkNamingContextPtrAdapt(attach->Child, *pGfx->Mesh, "ChildInstance"), C4MeshDenumeratorFactory));
45  assert(attach->Child != nullptr);
46  attach->OwnChild = true; // Delete the newly allocated child instance when the parent instance is gone
47 
48  // TODO: Do we leak pGfx?
49  }
50  else
51  {
52  pComp->Value(mkNamingAdapt(Object, "ChildObject"));
53  attach->OwnChild = false; // Keep child instance when parent instance is gone since it belongs to a different object
54  }
55  }
56  else
57  {
58  int32_t def = 0;
59  if (Def)
60  {
61  ++def;
62  }
63  pComp->Value(mkNamingCountAdapt(def, "ChildInstance"));
64 
65  if (Def)
66  {
67  assert(attach->OwnChild);
68  C4DefGraphics* pGfx = &Def->Graphics;
69  assert(pGfx->Type == C4DefGraphics::TYPE_Mesh);
70  pComp->Value(mkNamingAdapt(C4DefGraphicsAdapt(pGfx), "ChildMesh"));
71  pComp->Value(mkParAdapt(mkNamingContextPtrAdapt(attach->Child, *pGfx->Mesh, "ChildInstance"), C4MeshDenumeratorFactory));
72  }
73  else
74  {
75  assert(!attach->OwnChild);
76  pComp->Value(mkNamingAdapt(Object, "ChildObject"));
77  }
78  }
79 }
const StdMeshInstance::AttachedMesh::DenumeratorFactoryFunc C4MeshDenumeratorFactory
StdContextPtrAdapt< T, ContextT > mkNamingContextPtrAdapt(T *&rpObj, const ContextT &ctx, const char *szNaming)
Definition: StdAdaptors.h:643
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:1008
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
GraphicsType Type
Definition: C4DefGraphics.h:48
C4DefGraphics Graphics
Definition: C4Def.h:191
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
StdMeshInstance * Child
Definition: StdMesh.h:511

References C4MeshDenumeratorFactory, StdMeshInstance::AttachedMesh::Child, StdCompiler::excCorrupt(), C4Def::Graphics, StdCompiler::isDeserializer(), mkNamingAdapt(), mkNamingContextPtrAdapt(), mkNamingCountAdapt(), mkParAdapt(), StdMeshInstance::AttachedMesh::OwnChild, C4DefGraphics::pDef, C4DefGraphics::Type, C4DefGraphics::TYPE_Mesh, and StdCompiler::Value().

Here is the call graph for this function:

◆ DenumeratePointers()

void C4MeshDenumerator::DenumeratePointers ( StdMeshInstance::AttachedMesh attach)
overridevirtual

Reimplemented from StdMeshInstance::AttachedMesh::Denumerator.

Definition at line 81 of file C4MeshDenumerator.cpp.

82 {
83  Object.DenumeratePointers();
84 
85  // Set child instance of attach after denumeration
86  if (Object)
87  {
88  assert(!attach->OwnChild);
89  assert(!attach->Child || attach->Child == Object->pMeshInstance);
90  if (!attach->Child)
91  {
92  attach->Child = Object->pMeshInstance;
93  }
94  }
95 }
StdMeshInstance * pMeshInstance
Definition: C4Object.h:154
void DenumeratePointers()
Definition: C4ObjectPtr.cpp:49

References StdMeshInstance::AttachedMesh::Child, C4ObjectPtr::DenumeratePointers(), StdMeshInstance::AttachedMesh::OwnChild, and C4Object::pMeshInstance.

Here is the call graph for this function:

◆ GetObject()

C4Object* C4MeshDenumerator::GetObject ( )
inline

Definition at line 36 of file C4MeshDenumerator.h.

36 { return Object; }

References Object().

Here is the call graph for this function:

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