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)
 
virtual const char * GetName ()
 
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 416 of file C4DefGraphics.cpp.

References C4MaxName, Name, and SCopy().

416  : C4DefGraphics(pOwnDef)
417 {
418  // store name
419  SCopy(szName, Name, C4MaxName);
420 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
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 322 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().

323 {
324  // default: def picture rect
325  C4Rect fctPicRect = pDef->PictureRect;
326  C4Facet fctPicture;
327 
328  // if assigned: use object specific rect and graphics
329  if (pObj) if (pObj->PictureRect.Wdt) fctPicRect = pObj->PictureRect;
330 
331  // specific object color?
332  if (pObj) pObj->PrepareDrawing();
333 
334  switch(Type)
335  {
337  // Def has no graphics
338  break;
340  fctPicture.Set(GetBitmap(iColor),fctPicRect.x,fctPicRect.y,fctPicRect.Wdt,fctPicRect.Hgt);
341  fctPicture.DrawTUnscaled(cgo,true,iPhaseX,iPhaseY,trans);
342  break;
344  // TODO: Allow rendering of a mesh directly, without instance (to render pose; no animation)
345  std::unique_ptr<StdMeshInstance> dummy;
346  StdMeshInstance* instance;
347 
348  C4Value value;
349  if (pObj)
350  {
351  instance = pObj->pMeshInstance;
352  pObj->GetProperty(P_PictureTransformation, &value);
353  }
354  else
355  {
356  dummy.reset(new StdMeshInstance(*Mesh, 1.0f));
357  instance = dummy.get();
359  }
360 
361  StdMeshMatrix matrix;
362  if (C4ValueToMatrix(value, &matrix))
363  pDraw->SetMeshTransform(&matrix);
364 
365  pDraw->SetPerspective(true);
366  pDraw->RenderMesh(*instance, cgo.Surface, cgo.X,cgo.Y, cgo.Wdt, cgo.Hgt, pObj ? pObj->Color : iColor, trans);
367  pDraw->SetPerspective(false);
368  pDraw->SetMeshTransform(nullptr);
369 
370  break;
371  }
372 
373  if (pObj) pObj->FinishedDrawing();
374 
375  // draw overlays
376  if (pObj && pObj->pGfxOverlay)
377  for (C4GraphicsOverlay *pGfxOvrl = pObj->pGfxOverlay; pGfxOvrl; pGfxOvrl = pGfxOvrl->GetNext())
378  if (pGfxOvrl->IsPicture())
379  pGfxOvrl->DrawPicture(cgo, pObj, trans);
380 }
void SetMeshTransform(const StdMeshMatrix *Transform)
Definition: C4Draw.h:200
float Y
Definition: C4Facet.h:120
void FinishedDrawing() const
Definition: C4Object.cpp:4132
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:103
C4Rect PictureRect
Definition: C4Def.h:109
C4Rect PictureRect
Definition: C4Object.h:151
Definition: C4Rect.h:29
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
int32_t Wdt
Definition: C4Rect.h:32
bool RenderMesh(StdMeshInstance &instance, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)
Definition: C4Draw.cpp:406
int32_t y
Definition: C4Rect.h:32
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:45
void PrepareDrawing() const
Definition: C4Object.cpp:4124
int32_t x
Definition: C4Rect.h:32
class C4GraphicsOverlay * pGfxOverlay
Definition: C4Object.h:170
float Hgt
Definition: C4Facet.h:120
GraphicsType Type
Definition: C4DefGraphics.h:48
int32_t Hgt
Definition: C4Rect.h:32
C4Surface * Surface
Definition: C4Facet.h:119
float Wdt
Definition: C4Facet.h:120
StdMeshInstance * pMeshInstance
Definition: C4Object.h:155
float X
Definition: C4Facet.h:120
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 382 of file C4DefGraphics.cpp.

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

383 {
384  if (Type != TYPE_Bitmap) return; // TODO
385  // create facet and draw it
386  C4Surface *pSfc = Bmp.BitmapClr ? Bmp.BitmapClr : Bmp.Bitmap; if (!pSfc) return;
387  C4Facet fct(pSfc, 0,0,pSfc->Wdt, pSfc->Hgt);
388  fct.DrawClr(cgo, fAspect, dwClr);
389 }
int Wdt
Definition: C4Surface.h:67
int Hgt
Definition: C4Surface.h:67
GraphicsType Type
Definition: C4DefGraphics.h:48

Here is the call graph for this function:

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

Definition at line 311 of file C4DefGraphics.cpp.

References C4DefGraphics::pNext, and SEqualNoCase().

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

312 {
313  // no group or empty string: base graphics
314  if (!szGrpName || !szGrpName[0]) return this;
315  // search additional graphics
316  for (C4AdditionalDefGraphics *pGrp = pNext; pGrp; pGrp=pGrp->pNext)
317  if (SEqualNoCase(pGrp->GetName(), szGrpName)) return pGrp;
318  // nothing found
319  return nullptr;
320 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
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 1190 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().

1191 {
1192  if (Type != TYPE_Bitmap)
1193  return nullptr;
1194  if (Bmp.BitmapClr)
1195  {
1196  Bmp.BitmapClr->SetClr(dwClr);
1197  return Bmp.BitmapClr;
1198  }
1199  else
1200  return Bmp.Bitmap;
1201 }
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 57 of file C4DefGraphics.cpp.

References C4DefGraphics::pNext.

58 {
59  C4DefGraphics *pLast = this;
60  while (pLast->pNext) pLast = pLast->pNext;
61  return pLast;
62 }
C4AdditionalDefGraphics * pNext
Definition: C4DefGraphics.h:37
virtual const char* C4AdditionalDefGraphics::GetName ( )
inlinevirtual

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 230 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().

231 {
232  char Filename[_MAX_PATH+1]; *Filename=0;
233 
234  // load skeletons
235  hGroup.ResetSearch();
236  while (hGroup.FindNextEntry("*", Filename, nullptr, !!*Filename))
237  {
238  if (!WildcardMatch(C4CFN_DefSkeleton, Filename) && !WildcardMatch(C4CFN_DefSkeletonXml, Filename)) continue;
239  LoadSkeleton(hGroup, Filename, loader);
240  }
241 
242  // Try from Mesh first
243  if (!LoadMesh(hGroup, C4CFN_DefMesh, loader))
244  if(!LoadMesh(hGroup, C4CFN_DefMeshXml, loader))
246 
247  // load additional graphics
248  C4DefGraphics *pLastGraphics = this;
249  const int32_t iOverlayWildcardPos = SCharPos('*', C4CFN_ClrByOwnerEx);
250  hGroup.ResetSearch(); *Filename=0;
251  const char* const AdditionalGraphics[] = { C4CFN_DefGraphicsEx, C4CFN_DefGraphicsExMesh, C4CFN_DefGraphicsExMeshXml, nullptr };
252  while (hGroup.FindNextEntry("*", Filename, nullptr, !!*Filename))
253  {
254  for(const char* const* szWildcard = AdditionalGraphics; *szWildcard != nullptr; ++szWildcard)
255  {
256  if(!WildcardMatch(*szWildcard, Filename)) continue;
257  // skip def graphics
258  if (SEqualNoCase(Filename, C4CFN_DefGraphics) || SEqualNoCase(Filename, C4CFN_DefMesh) || SEqualNoCase(Filename, C4CFN_DefMeshXml)) continue;
259  // skip scaled def graphics
260  if (WildcardMatch(C4CFN_DefGraphicsScaled, Filename)) continue;
261  // get name
262  char GrpName[_MAX_PATH+1];
263  const int32_t iWildcardPos = SCharPos('*', *szWildcard);
264  SCopy(Filename + iWildcardPos, GrpName, _MAX_PATH);
265  RemoveExtension(GrpName);
266  // remove trailing number for scaled graphics
267  int32_t extpos; int scale;
268  if ((extpos = SCharLastPos('.', GrpName)) > -1)
269  if (sscanf(GrpName+extpos+1, "%d", &scale) == 1)
270  GrpName[extpos] = '\0';
271  // clip to max length
272  GrpName[C4MaxName]=0;
273  // create new graphics
274  pLastGraphics->pNext = new C4AdditionalDefGraphics(pDef, GrpName);
275  pLastGraphics = pLastGraphics->pNext;
276  if(*szWildcard == AdditionalGraphics[0])
277  {
278  // create overlay-filename
279  char OverlayFn[_MAX_PATH+1];
280  if(fColorByOwner)
281  {
282  // GraphicsX.png -> OverlayX.png
283  SCopy(C4CFN_ClrByOwnerEx, OverlayFn, _MAX_PATH);
284  OverlayFn[iOverlayWildcardPos]=0;
285  SAppend(Filename + iWildcardPos, OverlayFn);
287  }
288 
289  // create normal filename
290  char NormalFn[_MAX_PATH+1];
291  SCopy(C4CFN_NormalMapEx, NormalFn, _MAX_PATH);
292  NormalFn[iOverlayWildcardPos]=0;
293  SAppend(Filename + iWildcardPos, NormalFn);
295 
296  // load them
297  if (!pLastGraphics->LoadBitmap(hGroup, Filename, fColorByOwner ? OverlayFn : nullptr, NormalFn, fColorByOwner))
298  return false;
299  }
300  else
301  {
302  if (!pLastGraphics->LoadMesh(hGroup, Filename, loader))
303  return false;
304  }
305  }
306  }
307  // done, success
308  return true;
309 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
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:234
#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:184
#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:224
#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:131
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:316
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:299
C4AdditionalDefGraphics * pNext
Definition: C4DefGraphics.h:37
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384
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:210
#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 88 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().

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

162 {
163  char* buf = nullptr;
164  size_t size;
165 
166  try
167  {
168  if(!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false;
169 
170  if (SEqualNoCase(GetExtension(szFileName), "xml"))
171  {
172  Mesh = StdMeshLoader::LoadMeshXml(buf, size, ::MeshMaterialManager, loader, hGroup.GetName());
173  }
174  else
175  {
176  Mesh = StdMeshLoader::LoadMeshBinary(buf, size, ::MeshMaterialManager, loader, hGroup.GetName());
177  }
178  delete[] buf;
179 
180  Mesh->SetLabel(pDef->id.ToString());
181 
182  // order submeshes
183  Mesh->PostInit();
184  }
185  catch (const std::runtime_error& ex)
186  {
187  DebugLogF("Failed to load mesh in definition %s: %s", hGroup.GetName(), ex.what());
188  delete[] buf;
189  return false;
190  }
191 
192  Type = TYPE_Mesh;
193  return true;
194 }
static StdMesh * LoadMeshXml(const char *sourcefile, size_t size, const StdMeshMatManager &mat_mgr, StdMeshSkeletonLoader &loader, const char *filename=0)
C4ID id
Definition: C4Def.h:103
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
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:281
const char * GetName() const
Definition: C4Group.cpp:1845
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:131
void SetLabel(const std::string &label)
Definition: StdMesh.h:219
const char * ToString() const
Definition: C4Id.h:62
GraphicsType Type
Definition: C4DefGraphics.h:48
static StdMesh * LoadMeshBinary(const char *sourcefile, size_t size, const StdMeshMatManager &mat_mgr, StdMeshSkeletonLoader &loader, const char *filename=0)
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 196 of file C4DefGraphics.cpp.

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

Referenced by C4DefGraphics::Load().

197 {
198  char* buf = nullptr;
199  size_t size;
200 
201  try
202  {
203  if (!hGroup.LoadEntry(szFileName, &buf, &size, 1)) return false;
204 
205  // delete skeleton from the map for reloading, or else if you delete or rename
206  // a skeleton file in the folder the old skeleton will still exist in the map
207  loader.RemoveSkeleton(hGroup.GetName(), szFileName);
208 
209  if (SEqualNoCase(GetExtension(szFileName), "xml"))
210  {
211  loader.LoadSkeletonXml(hGroup.GetName(), szFileName, buf, size);
212  }
213  else
214  {
215  loader.LoadSkeletonBinary(hGroup.GetName(), szFileName, buf, size);
216  }
217 
218  delete[] buf;
219  }
220  catch (const std::runtime_error& ex)
221  {
222  DebugLogF("Failed to load skeleton in definition %s: %s", hGroup.GetName(), ex.what());
223  delete[] buf;
224  return false;
225  }
226 
227  return true;
228 }
void RemoveSkeleton(const StdCopyStrBuf &filepath)
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:184
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:281
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:131
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: