OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4AdditionalDefGraphics Class Reference

#include <C4DefGraphics.h>

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

Public Types

enum  GraphicsType { TYPE_None, TYPE_Bitmap, TYPE_Mesh }
 

Public Member Functions

 C4AdditionalDefGraphics (C4Def *pOwnDef, const char *szName)
 
const char * GetName () override
 
C4SurfaceGetBitmap (DWORD dwClr=0)
 
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)
 
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

char Name [C4MaxName+1]
 
C4AdditionalDefGraphicspNext
 

Detailed Description

Definition at line 91 of file C4DefGraphics.h.

Member Enumeration Documentation

Enumerator
TYPE_None 
TYPE_Bitmap 
TYPE_Mesh 

Definition at line 41 of file C4DefGraphics.h.

Constructor & Destructor Documentation

C4AdditionalDefGraphics::C4AdditionalDefGraphics ( C4Def pOwnDef,
const char *  szName 
)

Definition at line 412 of file C4DefGraphics.cpp.

References C4MaxName, Name, and SCopy().

412  : C4DefGraphics(pOwnDef)
413 {
414  // store name
415  SCopy(szName, Name, C4MaxName);
416 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
C4DefGraphics(C4Def *pOwnDef=nullptr)
Definition: stub-handle.cpp:73
const unsigned int C4MaxName
char Name[C4MaxName+1]
Definition: C4DefGraphics.h:94

Here is the call graph for this function:

Member Function Documentation

void C4DefGraphics::Clear ( )
inherited

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

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

74 {}

Here is the caller graph for this function:

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

Definition at line 318 of file C4DefGraphics.cpp.

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

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

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 }
void SetMeshTransform(const StdMeshMatrix *Transform)
Definition: C4Draw.h:200
float Y
Definition: C4Facet.h:118
void FinishedDrawing() const
Definition: C4Object.cpp:4125
void DrawTUnscaled(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
Definition: C4Facet.cpp:115
bool GetProperty(C4PropertyName k, C4Value *pResult) const
Definition: C4PropList.h:101
C4Rect PictureRect
Definition: C4Def.h:107
C4Rect PictureRect
Definition: C4Object.h:151
Definition: C4Rect.h:27
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
int32_t Wdt
Definition: C4Rect.h:30
bool RenderMesh(StdMeshInstance &instance, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)
Definition: C4Draw.cpp:403
int32_t y
Definition: C4Rect.h:30
C4Surface * GetBitmap(DWORD dwClr=0)
void SetPerspective(bool fSet)
Definition: C4Draw.h:201
uint32_t Color
Definition: C4Object.h:120
C4Draw * pDraw
Definition: C4Draw.cpp:42
void PrepareDrawing() const
Definition: C4Object.cpp:4117
int32_t x
Definition: C4Rect.h:30
class C4GraphicsOverlay * pGfxOverlay
Definition: C4Object.h:170
float Hgt
Definition: C4Facet.h:118
GraphicsType Type
Definition: C4DefGraphics.h:48
int32_t Hgt
Definition: C4Rect.h:30
C4Surface * Surface
Definition: C4Facet.h:117
float Wdt
Definition: C4Facet.h:118
StdMeshInstance * pMeshInstance
Definition: C4Object.h:155
float X
Definition: C4Facet.h:118
bool C4ValueToMatrix(C4Value &value, StdMeshMatrix *matrix)
C4GraphicsOverlay * GetNext() const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 378 of file C4DefGraphics.cpp.

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

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
GraphicsType Type
Definition: C4DefGraphics.h:48

Here is the call graph for this function:

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

Definition at line 307 of file C4DefGraphics.cpp.

References C4DefGraphics::pNext, and SEqualNoCase().

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

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:207
C4AdditionalDefGraphics * pNext
Definition: C4DefGraphics.h:37

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1185 of file C4DefGraphics.cpp.

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

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

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 }
GraphicsType Type
Definition: C4DefGraphics.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

C4DefGraphics * C4DefGraphics::GetLast ( )
protectedinherited

Definition at line 53 of file C4DefGraphics.cpp.

References C4DefGraphics::pNext.

54 {
55  C4DefGraphics *pLast = this;
56  while (pLast->pNext) pLast = pLast->pNext;
57  return pLast;
58 }
C4AdditionalDefGraphics * pNext
Definition: C4DefGraphics.h:37
const char* C4AdditionalDefGraphics::GetName ( )
inlineoverridevirtual

Reimplemented from C4DefGraphics.

Definition at line 98 of file C4DefGraphics.h.

References Name.

98 { return Name; }
char Name[C4MaxName+1]
Definition: C4DefGraphics.h:94
C4AdditionalDefGraphics* C4DefGraphics::GetNext ( )
inlineinherited

Definition at line 81 of file C4DefGraphics.h.

References C4DefGraphics::pNext.

81 { return pNext; }
C4AdditionalDefGraphics * pNext
Definition: C4DefGraphics.h:37
bool C4DefGraphics::IsColorByOwner ( )
inlineinherited

Definition at line 74 of file C4DefGraphics.h.

References C4DefGraphics::TYPE_Bitmap, and C4DefGraphics::TYPE_Mesh.

Referenced by C4Object::UpdateGraphics().

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

Here is the caller graph for this function:

bool C4DefGraphics::IsMesh ( ) const
inlineinherited

Definition at line 73 of file C4DefGraphics.h.

References C4DefGraphics::TYPE_Mesh.

73 { return Type == TYPE_Mesh; }
GraphicsType Type
Definition: C4DefGraphics.h:48
bool C4DefGraphics::Load ( C4Group hGroup,
StdMeshSkeletonLoader loader,
bool  fColorByOwner 
)
inherited

Definition at line 226 of file C4DefGraphics.cpp.

References _MAX_PATH, 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(), C4DefGraphics::LoadBitmap(), C4DefGraphics::LoadMesh(), C4DefGraphics::LoadSkeleton(), C4DefGraphics::pDef, C4DefGraphics::pNext, RemoveExtension(), C4Group::ResetSearch(), SAppend(), SCharLastPos(), SCharPos(), SCopy(), SEqualNoCase(), and WildcardMatch().

227 {
228  char Filename[_MAX_PATH+1]; *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+1];
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+1];
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+1];
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 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
bool LoadSkeleton(C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
#define C4CFN_DefGraphicsExMesh
Definition: C4Components.h:96
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
#define C4CFN_ClrByOwnerEx
Definition: C4Components.h:103
#define C4CFN_DefGraphicsEx
Definition: C4Components.h:102
#define C4CFN_ClrByOwner
Definition: C4Components.h:100
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
#define C4CFN_NormalMap
Definition: C4Components.h:101
#define _MAX_PATH
#define C4CFN_DefMeshXml
Definition: C4Components.h:93
#define C4CFN_DefMesh
Definition: C4Components.h:92
int SCharLastPos(char cTarget, const char *szInStr)
Definition: Standard.cpp:247
#define C4CFN_DefGraphicsExMeshXml
Definition: C4Components.h:97
const unsigned int C4MaxName
#define C4CFN_DefSkeletonXml
Definition: C4Components.h:95
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:121
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:306
bool LoadMesh(C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
#define C4CFN_DefGraphics
Definition: C4Components.h:99
#define C4CFN_DefSkeleton
Definition: C4Components.h:94
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
void EnforceExtension(char *szFilename, const char *szExtension)
Definition: StdFile.cpp:289
C4AdditionalDefGraphics * pNext
Definition: C4DefGraphics.h:37
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:374
bool LoadBitmap(C4Group &hGroup, const char *szFilenamePNG, const char *szOverlayPNG, const char *szNormal, bool fColorByOwner)
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:233
#define C4CFN_DefGraphicsScaled
Definition: C4Components.h:106
#define C4CFN_NormalMapEx
Definition: C4Components.h:104

Here is the call graph for this function:

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

Definition at line 84 of file C4DefGraphics.cpp.

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

Referenced by C4DefGraphics::Load().

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 }
const char * getData() const
Definition: StdBuf.h:442
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:288
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
const int C4SF_MipMap
Definition: C4Surface.h:50
bool fColorBitmapAutoCreated
Definition: C4DefGraphics.h:59
GraphicsType Type
Definition: C4DefGraphics.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 157 of file C4DefGraphics.cpp.

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

Referenced by C4DefGraphics::Load().

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 }
C4ID id
Definition: C4Def.h:101
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
bool LoadEntry(const char *szEntryName, char **lpbpBuf, size_t *ipSize=nullptr, int iAppendZeros=0)
Definition: C4Group.cpp:1893
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:288
static StdMesh * LoadMeshBinary(const char *sourcefile, size_t size, const StdMeshMatManager &mat_mgr, StdMeshSkeletonLoader &loader, const char *filename=nullptr)
const char * GetName() const
Definition: C4Group.cpp:1845
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:121
void SetLabel(const std::string &label)
Definition: StdMesh.h:217
const char * ToString() const
Definition: C4Id.h:59
GraphicsType Type
Definition: C4DefGraphics.h:48
static StdMesh * LoadMeshXml(const char *sourcefile, size_t size, const StdMeshMatManager &mat_mgr, StdMeshSkeletonLoader &loader, const char *filename=nullptr)
StdMeshMatManager MeshMaterialManager

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 192 of file C4DefGraphics.cpp.

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

Referenced by C4DefGraphics::Load().

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 RemoveSkeleton(const StdCopyStrBuf &filepath)
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
bool LoadEntry(const char *szEntryName, char **lpbpBuf, size_t *ipSize=nullptr, int iAppendZeros=0)
Definition: C4Group.cpp:1893
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:288
const char * GetName() const
Definition: C4Group.cpp:1845
void LoadSkeletonBinary(const char *groupname, const char *filename, const char *sourcefile, size_t size)
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:121
void LoadSkeletonXml(const char *groupname, const char *filename, const char *sourcefile, size_t size)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

union { ... }
bool C4DefGraphics::fColorBitmapAutoCreated
inherited

Definition at line 59 of file C4DefGraphics.h.

Referenced by C4DefGraphics::LoadBitmap().

char C4AdditionalDefGraphics::Name[C4MaxName+1]
protected

Definition at line 94 of file C4DefGraphics.h.

Referenced by C4AdditionalDefGraphics(), and GetName().


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