OpenClonk
C4DefGraphics Class Reference

#include <C4DefGraphics.h>

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

Public Types

enum  GraphicsType { TYPE_None , TYPE_Bitmap , TYPE_Mesh }
 

Public Member Functions

C4SurfaceGetBitmap (DWORD dwClr=0)
 
 C4DefGraphics (C4Def *pOwnDef=nullptr)
 
virtual ~C4DefGraphics ()
 
bool LoadBitmap (C4Group &hGroup, const char *szFilenamePNG, const char *szOverlayPNG, const char *szNormal, bool fColorByOwner)
 
bool LoadBitmaps (C4Group &hGroup, bool fColorByOwner)
 
bool LoadMesh (C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
 
bool LoadSkeleton (C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
 
bool Load (C4Group &hGroup, StdMeshSkeletonLoader &loader, bool fColorByOwner)
 
C4DefGraphicsGet (const char *szGrpName)
 
void Clear ()
 
bool IsMesh () const
 
bool IsColorByOwner ()
 
void Draw (C4Facet &cgo, DWORD iColor, C4Object *pObj, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *trans)
 
virtual const char * GetName ()
 
C4AdditionalDefGraphicsGetNext ()
 
void DrawClr (C4Facet &cgo, bool fAspect=true, DWORD dwClr=0)
 
void CompileFunc (StdCompiler *pComp)
 

Public Attributes

C4DefpDef
 
GraphicsType Type
 
union {
   struct {
C4SurfaceBitmap
 
C4SurfaceBitmapClr
 
C4SurfaceBitmapNormal
 
   } Bmp
 
StdMeshMesh
 
}; 
 
bool fColorBitmapAutoCreated
 

Protected Member Functions

C4DefGraphicsGetLast ()
 

Protected Attributes

C4AdditionalDefGraphicspNext
 

Friends

class C4DefGraphicsPtrBackup
 

Detailed Description

Definition at line 31 of file C4DefGraphics.h.

Member Enumeration Documentation

◆ GraphicsType

Enumerator
TYPE_None 
TYPE_Bitmap 
TYPE_Mesh 

Definition at line 41 of file C4DefGraphics.h.

42  {
43  TYPE_None,
45  TYPE_Mesh
46  };

Constructor & Destructor Documentation

◆ C4DefGraphics()

C4DefGraphics::C4DefGraphics ( C4Def pOwnDef = nullptr)

Definition at line 73 of file stub-handle.cpp.

73 {}

◆ ~C4DefGraphics()

virtual C4DefGraphics::~C4DefGraphics ( )
inlinevirtual

Definition at line 64 of file C4DefGraphics.h.

64 { Clear(); }; // dtor

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4DefGraphics::Clear ( )

Definition at line 74 of file stub-handle.cpp.

74 {}

Referenced by C4Def::Clear(), LoadBitmap(), and ~C4DefGraphics().

Here is the caller graph for this function:

◆ CompileFunc()

void C4DefGraphics::CompileFunc ( StdCompiler pComp)

◆ Draw()

void C4DefGraphics::Draw ( C4Facet cgo,
DWORD  iColor,
C4Object pObj,
int32_t  iPhaseX,
int32_t  iPhaseY,
C4DrawTransform trans 
)

Definition at line 318 of file C4DefGraphics.cpp.

319 {
320  // default: def picture rect
321  C4Rect fctPicRect = pDef->PictureRect;
322  C4Facet fctPicture;
323 
324  // if assigned: use object specific rect and graphics
325  if (pObj) if (pObj->PictureRect.Wdt) fctPicRect = pObj->PictureRect;
326 
327  // specific object color?
328  if (pObj) pObj->PrepareDrawing();
329 
330  switch(Type)
331  {
333  // Def has no graphics
334  break;
336  fctPicture.Set(GetBitmap(iColor),fctPicRect.x,fctPicRect.y,fctPicRect.Wdt,fctPicRect.Hgt);
337  fctPicture.DrawTUnscaled(cgo,true,iPhaseX,iPhaseY,trans);
338  break;
340  // TODO: Allow rendering of a mesh directly, without instance (to render pose; no animation)
341  std::unique_ptr<StdMeshInstance> dummy;
342  StdMeshInstance* instance;
343 
344  C4Value value;
345  if (pObj)
346  {
347  instance = pObj->pMeshInstance;
348  pObj->GetProperty(P_PictureTransformation, &value);
349  }
350  else
351  {
352  dummy = std::make_unique<StdMeshInstance>(*Mesh, 1.0f);
353  instance = dummy.get();
355  }
356 
357  StdMeshMatrix matrix;
358  if (C4ValueToMatrix(value, &matrix))
359  pDraw->SetMeshTransform(&matrix);
360 
361  pDraw->SetPerspective(true);
362  pDraw->RenderMesh(*instance, cgo.Surface, cgo.X,cgo.Y, cgo.Wdt, cgo.Hgt, pObj ? pObj->Color : iColor, trans);
363  pDraw->SetPerspective(false);
364  pDraw->SetMeshTransform(nullptr);
365 
366  break;
367  }
368 
369  if (pObj) pObj->FinishedDrawing();
370 
371  // draw overlays
372  if (pObj && pObj->pGfxOverlay)
373  for (C4GraphicsOverlay *pGfxOvrl = pObj->pGfxOverlay; pGfxOvrl; pGfxOvrl = pGfxOvrl->GetNext())
374  if (pGfxOvrl->IsPicture())
375  pGfxOvrl->DrawPicture(cgo, pObj, trans);
376 }
C4Draw * pDraw
Definition: C4Draw.cpp:42
bool C4ValueToMatrix(C4Value &value, StdMeshMatrix *matrix)
@ P_PictureTransformation
GraphicsType Type
Definition: C4DefGraphics.h:48
C4Surface * GetBitmap(DWORD dwClr=0)
C4Rect PictureRect
Definition: C4Def.h:107
bool RenderMesh(StdMeshInstance &instance, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)
Definition: C4Draw.cpp:397
void SetMeshTransform(const StdMeshMatrix *Transform)
Definition: C4Draw.h:200
void SetPerspective(bool fSet)
Definition: C4Draw.h:201
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
void DrawTUnscaled(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:115
float Wdt
Definition: C4Facet.h:118
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
C4GraphicsOverlay * GetNext() const
class C4GraphicsOverlay * pGfxOverlay
Definition: C4Object.h:169
C4Rect PictureRect
Definition: C4Object.h:150
void PrepareDrawing() const
StdMeshInstance * pMeshInstance
Definition: C4Object.h:154
void FinishedDrawing() const
uint32_t Color
Definition: C4Object.h:118
bool GetProperty(C4PropertyName k, C4Value *pResult) const
Definition: C4PropList.h:105
Definition: C4Rect.h:28
int32_t y
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30

References C4ValueToMatrix(), C4Object::Color, C4Facet::DrawTUnscaled(), C4Object::FinishedDrawing(), GetBitmap(), C4GraphicsOverlay::GetNext(), C4PropList::GetProperty(), C4Facet::Hgt, C4Rect::Hgt, P_PictureTransformation, pDef, pDraw, C4Object::pGfxOverlay, C4Def::PictureRect, C4Object::PictureRect, C4Object::pMeshInstance, C4Object::PrepareDrawing(), C4Draw::RenderMesh(), C4Facet::Set(), C4Draw::SetMeshTransform(), C4Draw::SetPerspective(), C4Facet::Surface, Type, TYPE_Bitmap, TYPE_Mesh, TYPE_None, C4Facet::Wdt, C4Rect::Wdt, C4Facet::X, C4Rect::x, C4Facet::Y, and C4Rect::y.

Referenced by C4Def::Draw(), C4GraphicsOverlay::Draw(), C4MenuItem::DrawElement(), C4GraphicsOverlay::DrawPicture(), and C4Game::DrawPropListSpecImage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawClr()

void C4DefGraphics::DrawClr ( C4Facet cgo,
bool  fAspect = true,
DWORD  dwClr = 0 
)

Definition at line 378 of file C4DefGraphics.cpp.

379 {
380  if (Type != TYPE_Bitmap) return; // TODO
381  // create facet and draw it
382  C4Surface *pSfc = Bmp.BitmapClr ? Bmp.BitmapClr : Bmp.Bitmap; if (!pSfc) return;
383  C4Facet fct(pSfc, 0,0,pSfc->Wdt, pSfc->Hgt);
384  fct.DrawClr(cgo, fAspect, dwClr);
385 }
int Wdt
Definition: C4Surface.h:65
int Hgt
Definition: C4Surface.h:65

References C4Facet::DrawClr(), C4Surface::Hgt, Type, TYPE_Bitmap, and C4Surface::Wdt.

Here is the call graph for this function:

◆ Get()

C4DefGraphics * C4DefGraphics::Get ( const char *  szGrpName)

Definition at line 307 of file C4DefGraphics.cpp.

308 {
309  // no group or empty string: base graphics
310  if (!szGrpName || !szGrpName[0]) return this;
311  // search additional graphics
312  for (C4AdditionalDefGraphics *pGrp = pNext; pGrp; pGrp=pGrp->pNext)
313  if (SEqualNoCase(pGrp->GetName(), szGrpName)) return pGrp;
314  // nothing found
315  return nullptr;
316 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
C4AdditionalDefGraphics * pNext
Definition: C4DefGraphics.h:37

References pNext, and SEqualNoCase().

Referenced by C4DefGraphicsPtrBackupEntry::AssignUpdate(), C4DefGraphicsAdapt::CompileFunc(), C4Def::Draw(), C4Game::DrawPropListSpecImage(), and C4Object::SetGraphics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBitmap()

C4Surface * C4DefGraphics::GetBitmap ( DWORD  dwClr = 0)

Definition at line 1185 of file C4DefGraphics.cpp.

1186 {
1187  if (Type != TYPE_Bitmap)
1188  return nullptr;
1189  if (Bmp.BitmapClr)
1190  {
1191  Bmp.BitmapClr->SetClr(dwClr);
1192  return Bmp.BitmapClr;
1193  }
1194  else
1195  return Bmp.Bitmap;
1196 }

References C4Surface::SetClr(), Type, and TYPE_Bitmap.

Referenced by Draw(), C4SolidMask::Draw(), C4Object::DrawFaceImpl(), C4Def::GetMainFace(), and C4GraphicsOverlay::UpdateFacet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLast()

C4DefGraphics * C4DefGraphics::GetLast ( )
protected

Definition at line 53 of file C4DefGraphics.cpp.

54 {
55  C4DefGraphics *pLast = this;
56  while (pLast->pNext) pLast = pLast->pNext;
57  return pLast;
58 }

References pNext.

◆ GetName()

virtual const char* C4DefGraphics::GetName ( )
inlinevirtual

Reimplemented in C4AdditionalDefGraphics.

Definition at line 79 of file C4DefGraphics.h.

79 { return nullptr; } // return name to be stored in safe game files

Referenced by C4DefGraphicsPtrBackupEntry::C4DefGraphicsPtrBackupEntry(), and C4DefGraphicsAdapt::CompileFunc().

Here is the caller graph for this function:

◆ GetNext()

C4AdditionalDefGraphics* C4DefGraphics::GetNext ( )
inline

Definition at line 81 of file C4DefGraphics.h.

81 { return pNext; }

References pNext.

◆ IsColorByOwner()

bool C4DefGraphics::IsColorByOwner ( )
inline

Definition at line 74 of file C4DefGraphics.h.

75  { return Type == TYPE_Mesh || (Type == TYPE_Bitmap && !!Bmp.BitmapClr); } // Mesh can always apply PlayerColor (if used in its material)

References Type, TYPE_Bitmap, and TYPE_Mesh.

Referenced by C4Object::UpdateGraphics().

Here is the caller graph for this function:

◆ IsMesh()

bool C4DefGraphics::IsMesh ( ) const
inline

Definition at line 73 of file C4DefGraphics.h.

73 { return Type == TYPE_Mesh; }

References Type, and TYPE_Mesh.

◆ Load()

bool C4DefGraphics::Load ( C4Group hGroup,
StdMeshSkeletonLoader loader,
bool  fColorByOwner 
)

Definition at line 226 of file C4DefGraphics.cpp.

227 {
228  char Filename[_MAX_PATH_LEN]; *Filename=0;
229 
230  // load skeletons
231  hGroup.ResetSearch();
232  while (hGroup.FindNextEntry("*", Filename, nullptr, !!*Filename))
233  {
234  if (!WildcardMatch(C4CFN_DefSkeleton, Filename) && !WildcardMatch(C4CFN_DefSkeletonXml, Filename)) continue;
235  LoadSkeleton(hGroup, Filename, loader);
236  }
237 
238  // Try from Mesh first
239  if (!LoadMesh(hGroup, C4CFN_DefMesh, loader))
240  if(!LoadMesh(hGroup, C4CFN_DefMeshXml, loader))
242 
243  // load additional graphics
244  C4DefGraphics *pLastGraphics = this;
245  const int32_t iOverlayWildcardPos = SCharPos('*', C4CFN_ClrByOwnerEx);
246  hGroup.ResetSearch(); *Filename=0;
247  const char* const AdditionalGraphics[] = { C4CFN_DefGraphicsEx, C4CFN_DefGraphicsExMesh, C4CFN_DefGraphicsExMeshXml, nullptr };
248  while (hGroup.FindNextEntry("*", Filename, nullptr, !!*Filename))
249  {
250  for(const char* const* szWildcard = AdditionalGraphics; *szWildcard != nullptr; ++szWildcard)
251  {
252  if(!WildcardMatch(*szWildcard, Filename)) continue;
253  // skip def graphics
254  if (SEqualNoCase(Filename, C4CFN_DefGraphics) || SEqualNoCase(Filename, C4CFN_DefMesh) || SEqualNoCase(Filename, C4CFN_DefMeshXml)) continue;
255  // skip scaled def graphics
256  if (WildcardMatch(C4CFN_DefGraphicsScaled, Filename)) continue;
257  // get name
258  char GrpName[_MAX_PATH_LEN];
259  const int32_t iWildcardPos = SCharPos('*', *szWildcard);
260  SCopy(Filename + iWildcardPos, GrpName, _MAX_PATH);
261  RemoveExtension(GrpName);
262  // remove trailing number for scaled graphics
263  int32_t extpos; int scale;
264  if ((extpos = SCharLastPos('.', GrpName)) > -1)
265  if (sscanf(GrpName+extpos+1, "%d", &scale) == 1)
266  GrpName[extpos] = '\0';
267  // clip to max length
268  GrpName[C4MaxName]=0;
269  // create new graphics
270  pLastGraphics->pNext = new C4AdditionalDefGraphics(pDef, GrpName);
271  pLastGraphics = pLastGraphics->pNext;
272  if(*szWildcard == AdditionalGraphics[0])
273  {
274  // create overlay-filename
275  char OverlayFn[_MAX_PATH_LEN];
276  if(fColorByOwner)
277  {
278  // GraphicsX.png -> OverlayX.png
279  SCopy(C4CFN_ClrByOwnerEx, OverlayFn, _MAX_PATH);
280  OverlayFn[iOverlayWildcardPos]=0;
281  SAppend(Filename + iWildcardPos, OverlayFn);
283  }
284 
285  // create normal filename
286  char NormalFn[_MAX_PATH_LEN];
287  SCopy(C4CFN_NormalMapEx, NormalFn, _MAX_PATH);
288  NormalFn[iOverlayWildcardPos]=0;
289  SAppend(Filename + iWildcardPos, NormalFn);
291 
292  // load them
293  if (!pLastGraphics->LoadBitmap(hGroup, Filename, fColorByOwner ? OverlayFn : nullptr, NormalFn, fColorByOwner))
294  return false;
295  }
296  else
297  {
298  if (!pLastGraphics->LoadMesh(hGroup, Filename, loader))
299  return false;
300  }
301  }
302  }
303  // done, success
304  return true;
305 }
#define C4CFN_DefMesh
Definition: C4Components.h:92
#define C4CFN_DefMeshXml
Definition: C4Components.h:93
#define C4CFN_ClrByOwnerEx
Definition: C4Components.h:103
#define C4CFN_ClrByOwner
Definition: C4Components.h:100
#define C4CFN_DefGraphicsExMeshXml
Definition: C4Components.h:97
#define C4CFN_DefGraphicsExMesh
Definition: C4Components.h:96
#define C4CFN_NormalMapEx
Definition: C4Components.h:104
#define C4CFN_DefGraphics
Definition: C4Components.h:99
#define C4CFN_DefSkeletonXml
Definition: C4Components.h:95
#define C4CFN_DefGraphicsEx
Definition: C4Components.h:102
#define C4CFN_DefGraphicsScaled
Definition: C4Components.h:106
#define C4CFN_NormalMap
Definition: C4Components.h:101
#define C4CFN_DefSkeleton
Definition: C4Components.h:94
const unsigned int C4MaxName
#define _MAX_PATH
#define _MAX_PATH_LEN
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:239
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
int SCharLastPos(char cTarget, const char *szInStr)
Definition: Standard.cpp:253
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:263
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:118
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:396
void EnforceExtension(char *szFilename, const char *szExtension)
Definition: StdFile.cpp:286
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:303
bool LoadBitmap(C4Group &hGroup, const char *szFilenamePNG, const char *szOverlayPNG, const char *szNormal, bool fColorByOwner)
bool LoadMesh(C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
bool LoadSkeleton(C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
bool FindNextEntry(const char *wildcard, StdStrBuf *filename=nullptr, size_t *size=nullptr, bool start_at_filename=false)
Definition: C4Group.cpp:2217
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1316

References _MAX_PATH, _MAX_PATH_LEN, C4CFN_ClrByOwner, C4CFN_ClrByOwnerEx, C4CFN_DefGraphics, C4CFN_DefGraphicsEx, C4CFN_DefGraphicsExMesh, C4CFN_DefGraphicsExMeshXml, C4CFN_DefGraphicsScaled, C4CFN_DefMesh, C4CFN_DefMeshXml, C4CFN_DefSkeleton, C4CFN_DefSkeletonXml, C4CFN_NormalMap, C4CFN_NormalMapEx, C4MaxName, EnforceExtension(), C4Group::FindNextEntry(), GetExtension(), LoadBitmap(), LoadMesh(), LoadSkeleton(), pDef, pNext, RemoveExtension(), C4Group::ResetSearch(), SAppend(), SCharLastPos(), SCharPos(), SCopy(), SEqualNoCase(), and WildcardMatch().

Here is the call graph for this function:

◆ LoadBitmap()

bool C4DefGraphics::LoadBitmap ( C4Group hGroup,
const char *  szFilenamePNG,
const char *  szOverlayPNG,
const char *  szNormal,
bool  fColorByOwner 
)

Definition at line 84 of file C4DefGraphics.cpp.

85 {
86  if (!szFilename) return false;
87  Type = TYPE_Bitmap; // will be reset to TYPE_None in Clear() if loading fails
88  Bmp.Bitmap = new C4Surface();
89  if (!Bmp.Bitmap->Load(hGroup, szFilename, false, true, C4SF_MipMap))
90  {
91  Clear();
92  return false;
93  }
94 
95  // Create owner color bitmaps
96  if (fColorByOwner)
97  {
98  // Create additionmal bitmap
99  Bmp.BitmapClr=new C4Surface();
100  // if overlay-surface is present, load from that
101  if (szOverlay && Bmp.BitmapClr->Load(hGroup, szOverlay, false, false, C4SF_MipMap))
102  {
103  // set as Clr-surface, also checking size
104  if (!Bmp.BitmapClr->SetAsClrByOwnerOf(Bmp.Bitmap))
105  {
106  DebugLogF(" Gfx loading error in %s: %s (%d x %d) doesn't match overlay %s (%d x %d) - invalid file or size mismatch",
107  hGroup.GetFullName().getData(), szFilename, Bmp.Bitmap ? Bmp.Bitmap->Wdt : -1, Bmp.Bitmap ? Bmp.Bitmap->Hgt : -1,
108  szOverlay, Bmp.BitmapClr->Wdt, Bmp.BitmapClr->Hgt);
109  Clear();
110  return false;
111  }
112  }
113  else
114  {
115  // otherwise, create by all blue shades
116  if (!Bmp.BitmapClr->CreateColorByOwner(Bmp.Bitmap))
117  {
118  Clear();
119  return false;
120  }
121  }
123  }
124 
125  if (szNormal)
126  {
127  Bmp.BitmapNormal = new C4Surface();
128  if (Bmp.BitmapNormal->Load(hGroup, szNormal, false, true, C4SF_MipMap))
129  {
130  // Normal map loaded. Sanity check and link.
131  if(Bmp.BitmapNormal->Wdt != Bmp.Bitmap->Wdt ||
132  Bmp.BitmapNormal->Hgt != Bmp.Bitmap->Hgt)
133  {
134  DebugLogF(" Gfx loading error in %s: %s (%d x %d) doesn't match normal %s (%d x %d) - invalid file or size mismatch",
135  hGroup.GetFullName().getData(), szFilename, Bmp.Bitmap ? Bmp.Bitmap->Wdt : -1, Bmp.Bitmap ? Bmp.Bitmap->Hgt : -1,
136  szNormal, Bmp.BitmapNormal->Wdt, Bmp.BitmapNormal->Hgt);
137  Clear();
138  return false;
139  }
140 
141  Bmp.Bitmap->pNormalSfc = Bmp.BitmapNormal;
142  if(Bmp.BitmapClr) Bmp.BitmapClr->pNormalSfc = Bmp.BitmapNormal;
143  }
144  else
145  {
146  // No normal map
147  delete Bmp.BitmapNormal;
148  Bmp.BitmapNormal = nullptr;
149  }
150  }
151 
152  Type = TYPE_Bitmap;
153  // success
154  return true;
155 }
bool DebugLogF(const char *strMessage ...)
Definition: C4Log.cpp:290
const int C4SF_MipMap
Definition: C4Surface.h:50
bool fColorBitmapAutoCreated
Definition: C4DefGraphics.h:59
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2638
const char * getData() const
Definition: StdBuf.h:442

References C4SF_MipMap, Clear(), DebugLogF(), fColorBitmapAutoCreated, StdStrBuf::getData(), C4Group::GetFullName(), Type, and TYPE_Bitmap.

Referenced by Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadBitmaps()

bool C4DefGraphics::LoadBitmaps ( C4Group hGroup,
bool  fColorByOwner 
)

◆ LoadMesh()

bool C4DefGraphics::LoadMesh ( C4Group hGroup,
const char *  szFilename,
StdMeshSkeletonLoader loader 
)

Definition at line 157 of file C4DefGraphics.cpp.

158 {
159  char* buf = nullptr;
160  size_t size;
161 
162  try
163  {
164  if(!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false;
165 
166  if (SEqualNoCase(GetExtension(szFileName), "xml"))
167  {
168  Mesh = StdMeshLoader::LoadMeshXml(buf, size, ::MeshMaterialManager, loader, hGroup.GetName());
169  }
170  else
171  {
172  Mesh = StdMeshLoader::LoadMeshBinary(buf, size, ::MeshMaterialManager, loader, hGroup.GetName());
173  }
174  delete[] buf;
175 
176  Mesh->SetLabel(pDef->id.ToString());
177 
178  // order submeshes
179  Mesh->PostInit();
180  }
181  catch (const std::runtime_error& ex)
182  {
183  DebugLogF("Failed to load mesh in definition %s: %s", hGroup.GetName(), ex.what());
184  delete[] buf;
185  return false;
186  }
187 
188  Type = TYPE_Mesh;
189  return true;
190 }
StdMeshMatManager MeshMaterialManager
C4ID id
Definition: C4Def.h:101
const char * GetName() const
Definition: C4Group.cpp:2309
bool LoadEntry(const char *entry_name, char **buffer, size_t *size_info=nullptr, int zeros_to_append=0)
Definition: C4Group.cpp:2375
const char * ToString() const
Definition: C4Id.h:56
static StdMesh * LoadMeshXml(const char *sourcefile, size_t size, const StdMeshMatManager &mat_mgr, StdMeshSkeletonLoader &loader, const char *filename=nullptr)
static StdMesh * LoadMeshBinary(const char *sourcefile, size_t size, const StdMeshMatManager &mat_mgr, StdMeshSkeletonLoader &loader, const char *filename=nullptr)

References DebugLogF(), GetExtension(), C4Group::GetName(), C4Def::id, C4Group::LoadEntry(), StdMeshLoader::LoadMeshBinary(), StdMeshLoader::LoadMeshXml(), MeshMaterialManager, pDef, SEqualNoCase(), C4ID::ToString(), Type, and TYPE_Mesh.

Referenced by Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadSkeleton()

bool C4DefGraphics::LoadSkeleton ( C4Group hGroup,
const char *  szFilename,
StdMeshSkeletonLoader loader 
)

Definition at line 192 of file C4DefGraphics.cpp.

193 {
194  char* buf = nullptr;
195  size_t size;
196 
197  try
198  {
199  if (!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false;
200 
201  // delete skeleton from the map for reloading, or else if you delete or rename
202  // a skeleton file in the folder the old skeleton will still exist in the map
203  loader.RemoveSkeleton(hGroup.GetName(), szFileName);
204 
205  if (SEqualNoCase(GetExtension(szFileName), "xml"))
206  {
207  loader.LoadSkeletonXml(hGroup.GetName(), szFileName, buf, size);
208  }
209  else
210  {
211  loader.LoadSkeletonBinary(hGroup.GetName(), szFileName, buf, size);
212  }
213 
214  delete[] buf;
215  }
216  catch (const std::runtime_error& ex)
217  {
218  DebugLogF("Failed to load skeleton in definition %s: %s", hGroup.GetName(), ex.what());
219  delete[] buf;
220  return false;
221  }
222 
223  return true;
224 }
void LoadSkeletonBinary(const char *groupname, const char *filename, const char *sourcefile, size_t size)
void LoadSkeletonXml(const char *groupname, const char *filename, const char *sourcefile, size_t size)
void RemoveSkeleton(const StdCopyStrBuf &filepath)

References DebugLogF(), GetExtension(), C4Group::GetName(), C4Group::LoadEntry(), StdMeshSkeletonLoader::LoadSkeletonBinary(), StdMeshSkeletonLoader::LoadSkeletonXml(), StdMeshSkeletonLoader::RemoveSkeleton(), and SEqualNoCase().

Referenced by Load().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4DefGraphicsPtrBackup

friend class C4DefGraphicsPtrBackup
friend

Definition at line 87 of file C4DefGraphics.h.

Member Data Documentation

◆ 

union { ... }

◆ fColorBitmapAutoCreated

bool C4DefGraphics::fColorBitmapAutoCreated

Definition at line 59 of file C4DefGraphics.h.

Referenced by LoadBitmap().

◆ pDef

◆ pNext

C4AdditionalDefGraphics* C4DefGraphics::pNext
protected

Definition at line 37 of file C4DefGraphics.h.

Referenced by C4DefGraphicsPtrBackup::Add(), Get(), GetLast(), GetNext(), and Load().

◆ Type


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