48 Bmp.Bitmap = Bmp.BitmapClr = Bmp.BitmapNormal =
nullptr;
68 if (Bmp.BitmapNormal) {
delete Bmp.BitmapNormal; Bmp.BitmapNormal=
nullptr; }
69 if (Bmp.BitmapClr) {
delete Bmp.BitmapClr; Bmp.BitmapClr=
nullptr; }
70 if (Bmp.Bitmap) {
delete Bmp.Bitmap; Bmp.Bitmap=
nullptr; }
73 if (Mesh) {
delete Mesh; Mesh =
nullptr; }
80 while ((pGrp2=pGrp2N)) { pGrp2N = pGrp2->
pNext; pGrp2->
pNext =
nullptr;
delete pGrp2; }
86 if (!szFilename)
return false;
89 if (!Bmp.Bitmap->Load(hGroup, szFilename,
false,
true,
C4SF_MipMap))
101 if (szOverlay && Bmp.BitmapClr->Load(hGroup, szOverlay,
false,
false,
C4SF_MipMap))
104 if (!Bmp.BitmapClr->SetAsClrByOwnerOf(Bmp.Bitmap))
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);
116 if (!Bmp.BitmapClr->CreateColorByOwner(Bmp.Bitmap))
128 if (Bmp.BitmapNormal->Load(hGroup, szNormal,
false,
true,
C4SF_MipMap))
131 if(Bmp.BitmapNormal->Wdt != Bmp.Bitmap->Wdt ||
132 Bmp.BitmapNormal->Hgt != Bmp.Bitmap->Hgt)
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);
141 Bmp.Bitmap->pNormalSfc = Bmp.BitmapNormal;
142 if(Bmp.BitmapClr) Bmp.BitmapClr->pNormalSfc = Bmp.BitmapNormal;
147 delete Bmp.BitmapNormal;
148 Bmp.BitmapNormal =
nullptr;
164 if(!hGroup.
LoadEntry(szFileName, &buf, &size, 1))
return false;
181 catch (
const std::runtime_error& ex)
183 DebugLogF(
"Failed to load mesh in definition %s: %s", hGroup.
GetName(), ex.what());
199 if (!hGroup.
LoadEntry(szFileName, &buf, &size, 1))
return false;
216 catch (
const std::runtime_error& ex)
218 DebugLogF(
"Failed to load skeleton in definition %s: %s", hGroup.
GetName(), ex.what());
232 while (hGroup.
FindNextEntry(
"*", Filename,
nullptr, !!*Filename))
248 while (hGroup.
FindNextEntry(
"*", Filename,
nullptr, !!*Filename))
250 for(
const char*
const* szWildcard = AdditionalGraphics; *szWildcard !=
nullptr; ++szWildcard)
259 const int32_t iWildcardPos =
SCharPos(
'*', *szWildcard);
263 int32_t extpos;
int scale;
265 if (sscanf(GrpName+extpos+1,
"%d", &scale) == 1)
266 GrpName[extpos] =
'\0';
271 pLastGraphics = pLastGraphics->
pNext;
272 if(*szWildcard == AdditionalGraphics[0])
280 OverlayFn[iOverlayWildcardPos]=0;
281 SAppend(Filename + iWildcardPos, OverlayFn);
288 NormalFn[iOverlayWildcardPos]=0;
289 SAppend(Filename + iWildcardPos, NormalFn);
293 if (!pLastGraphics->
LoadBitmap(hGroup, Filename, fColorByOwner ? OverlayFn :
nullptr, NormalFn, fColorByOwner))
298 if (!pLastGraphics->
LoadMesh(hGroup, Filename, loader))
310 if (!szGrpName || !szGrpName[0])
return this;
313 if (
SEqualNoCase(pGrp->GetName(), szGrpName))
return pGrp;
341 std::unique_ptr<StdMeshInstance> dummy;
352 dummy = std::make_unique<StdMeshInstance>(*Mesh, 1.0f);
353 instance = dummy.get();
374 if (pGfxOvrl->IsPicture())
375 pGfxOvrl->DrawPicture(cgo, pObj, trans);
382 C4Surface *pSfc = Bmp.BitmapClr ? Bmp.BitmapClr : Bmp.Bitmap;
if (!pSfc)
return;
384 fct.
DrawClr(cgo, fAspect, dwClr);
397 pComp->
excCorrupt(R
"(DefGraphics: expected "::")");
408 pComp->
excCorrupt(R
"(DefGraphics: could not find graphics "%s" in %s(%s)!)", Name.getData(), id.ToString(), pDef ? pDef->
GetName() :
"def not found");
446 UpdateAttachedMeshes();
454 if (pObj && pObj->Status)
461 assert(pObj->pMeshInstance !=
nullptr);
472 if (!pObj->SetGraphics(
Name, pObj->Def))
475 pObj->AssignRemoval(); pObj->pGraphics=
nullptr;
483 for (pGfxOverlay = pObj->pGfxOverlay; pGfxOverlay; pGfxOverlay = pGfxOverlay->
GetNext())
487 pObj->RemoveGraphicsOverlay(pGfxOverlay->
GetID());
491 if (!pGfxOverlay)
break;
495 if (
pDef && pObj->Menu && (pDeco = pObj->Menu->GetFrameDecoration()))
498 pObj->Menu->SetFrameDeco(
nullptr);
509 UpdateAttachedMeshes();
516 if (pObj && pObj->Status)
522 if(pObj->pMeshInstance)
526 pObj->AssignRemoval();
527 delete pObj->pMeshInstance;
528 pObj->pMeshInstance =
nullptr;
529 pObj->pGraphics =
nullptr;
532 else if (!pObj->SetGraphics()) { pObj->AssignRemoval(); pObj->pGraphics=
nullptr; }
538 for (pGfxOverlay = pObj->pGfxOverlay; pGfxOverlay; pGfxOverlay = pGfxOverlay->
GetNext())
542 pObj->RemoveGraphicsOverlay(pGfxOverlay->
GetID());
546 if (!pGfxOverlay)
break;
550 if (
pDef && pObj->Menu && (pDeco = pObj->Menu->GetFrameDecoration()))
552 pObj->Menu->SetFrameDeco(
nullptr);
559 void C4DefGraphicsPtrBackupEntry::UpdateAttachedMeshes()
563 if (pObj && pObj->Status)
565 if(pObj->pMeshInstance)
566 UpdateAttachedMesh(pObj->pMeshInstance);
568 if(pGfxOverlay->pMeshInstance)
569 UpdateAttachedMesh(pGfxOverlay->pMeshInstance);
574 void C4DefGraphicsPtrBackupEntry::UpdateAttachedMesh(
StdMeshInstance* instance)
599 std::vector<StdMeshInstance::AttachedMesh*> attached_meshes;
601 attached_meshes.push_back(*iter);
603 for(
auto & attached_mesh : attached_meshes)
605 UpdateAttachedMesh(attached_mesh->Child);
610 MeshAnimationUpdate(::
Definitions.GetSkeletonLoader())
618 for(
auto & Entry : Entries)
635 if(Filename == iter->FileName)
644 MeshMaterialUpdate.
Cancel();
647 for(
auto & Entry : Entries)
648 Entry->AssignRemoval();
658 MeshMaterialUpdate.
Update(iter.second->Graphics.Mesh);
661 for(
auto & Entry : Entries)
662 Entry->AssignUpdate();
667 if (pObj && pObj->Status)
669 if(pObj->pMeshInstance)
670 UpdateMesh(pObj->pMeshInstance);
672 if(pGfxOverlay->pMeshInstance)
673 UpdateMesh(pGfxOverlay->pMeshInstance);
682 MeshMaterialUpdate.
Update(instance);
683 MeshAnimationUpdate.
Update(instance);
687 if ((*iter)->OwnChild)
688 UpdateMesh((*iter)->Child);
700 while ((pOther = pNextOther))
702 pNextOther = pOther->
pNext;
703 pOther->
pNext =
nullptr;
763 if (!AnimationName)
return;
767 if (!Animation)
return;
1004 trf.
ScaleAt(fZoom, fZoom, offX, offY);
1019 trf.
ScaleAt(fZoom, fZoom, offX, offY);
1046 if (!rank_obj || !rank_obj->
Info)
return;
1086 if(trans) trf *= *trans;
1132 pComp->
Value(*pNext);
1138 delete pNext; pNext =
nullptr;
1155 pComp->
Value(fContinue);
1162 bool fContinue =
true;
1171 pComp->
Value(fContinue);
1174 pComp->
Value(*pPos);
1180 pComp->
Value(fContinue);
1191 Bmp.BitmapClr->
SetClr(dwClr);
1192 return Bmp.BitmapClr;
#define C4CFN_ClrByOwnerEx
#define C4CFN_DefGraphicsExMeshXml
#define C4CFN_DefGraphicsExMesh
#define C4CFN_NormalMapEx
#define C4CFN_DefGraphics
#define C4CFN_DefSkeletonXml
#define C4CFN_DefGraphicsEx
#define C4CFN_DefGraphicsScaled
#define C4CFN_DefSkeleton
bool C4ValueToMatrix(C4Value &value, StdMeshMatrix *matrix)
C4GraphicsResource GraphicsResource
bool DebugLogF(const char *strMessage ...)
C4RankSystem DefaultRanks
C4Fixed itofix(int32_t x)
@ P_PictureTransformation
int SCharPos(char cTarget, const char *szInStr, int iIndex)
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
int SCharLastPos(char cTarget, const char *szInStr)
void SAppend(const char *szSource, char *szTarget, int iMaxL)
bool SEqual(const char *szStr1, const char *szStr2)
StdDefaultAdapt< T, D > mkDefaultAdapt(T &&rValue, const D &rDefault)
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
StdIntAdapt< T > mkIntAdapt(T &rValue)
StdStringAdapt mkStringAdaptMIE(char(&szString)[size])
char * GetExtension(char *szFilename)
bool WildcardMatch(const char *szWildcard, const char *szString)
char * GetFilename(char *szPath)
void EnforceExtension(char *szFilename, const char *szExtension)
void RemoveExtension(char *szFilename)
StdMeshMatManager MeshMaterialManager
C4AdditionalDefGraphics(C4Def *pOwnDef, const char *szName)
C4DefGraphics *& pDefGraphics
void CompileFunc(StdCompiler *pComp)
C4DefGraphics * Get(const char *szGrpName)
virtual const char * GetName()
bool Load(C4Group &hGroup, StdMeshSkeletonLoader &loader, bool fColorByOwner)
bool fColorBitmapAutoCreated
C4Surface * GetBitmap(DWORD dwClr=0)
void DrawClr(C4Facet &cgo, bool fAspect=true, DWORD dwClr=0)
bool LoadBitmap(C4Group &hGroup, const char *szFilenamePNG, const char *szOverlayPNG, const char *szNormal, bool fColorByOwner)
void Draw(C4Facet &cgo, DWORD iColor, C4Object *pObj, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *trans)
C4DefGraphics(C4Def *pOwnDef=nullptr)
C4DefGraphics * GetLast()
C4AdditionalDefGraphics * pNext
bool LoadMesh(C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
bool LoadSkeleton(C4Group &hGroup, const char *szFilename, StdMeshSkeletonLoader &loader)
StdMeshUpdate * pMeshUpdate
~C4DefGraphicsPtrBackupEntry()
C4DefGraphicsPtrBackupEntry(C4DefGraphics *pSourceGraphics)
C4DefGraphics * pGraphicsPtr
void Add(C4DefGraphics *pGraphics)
~C4DefGraphicsPtrBackup()
char Filename[_MAX_FNAME_LEN]
C4FacetSurface * pRankSymbols
C4RankSystem * pRankNames
void SetBlitMode(DWORD dwBlitMode)
bool RenderMesh(StdMeshInstance &instance, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)
void DeactivateBlitModulation()
void SetMeshTransform(const StdMeshMatrix *Transform)
void ActivateBlitModulation(DWORD dwWithClr)
void SetPerspective(bool fSet)
void Set(C4Surface &rSfc)
void DrawT(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
void DrawTUnscaled(C4Surface *sfcTarget, float iX, float iY, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *pTransform)
void DrawClr(C4Facet &cgo, bool fAspect=true, DWORD dwClr=0)
void SetNext(C4GraphicsOverlay *paNext)
bool IsValid(const C4Object *pForObj) const
void DrawPicture(C4Facet &cgo, C4Object *pForObj, C4DrawTransform *trans)
void DrawRankSymbol(C4Facet &cgo, C4Object *rank_obj)
C4GraphicsOverlay * pNext
C4GraphicsOverlay * GetNext() const
C4DrawTransform Transform
void Set(Mode aMode, C4DefGraphics *pGfx, const char *szAction, DWORD dwBMode, C4Object *pOvrlObj)
StdMeshInstance * pMeshInstance
void Draw(C4TargetFacet &cgo, C4Object *pForObj, int32_t iByPlayer)
C4DefGraphics * pSourceGfx
void DenumeratePointers()
bool operator==(const C4GraphicsOverlay &rCmp) const
C4DefGraphics * GetGfx() const
void CompileFunc(StdCompiler *pComp)
void CompileFunc(StdCompiler *pComp)
C4GraphicsOverlay *& pOverlay
bool FindNextEntry(const char *wildcard, StdStrBuf *filename=nullptr, size_t *size=nullptr, bool start_at_filename=false)
const char * GetName() const
StdStrBuf GetFullName() const
bool LoadEntry(const char *entry_name, char **buffer, size_t *size_info=nullptr, int zeros_to_append=0)
void ResetSearch(bool reload_contents=false)
const char * ToString() const
bool GetDrawPosition(const C4TargetFacet &cgo, float &resultx, float &resulty, float &resultzoom) const
bool SetGraphics(const char *szGraphicsName=nullptr, C4Def *pSourceDef=nullptr)
class C4GraphicsOverlay * pGfxOverlay
void DrawPicture(C4Facet &cgo, bool fSelected=false, C4DrawTransform *transform=nullptr)
C4DrawTransform * pDrawTransform
void DrawTopFace(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)
void PrepareDrawing() const
bool HasGraphicsOverlayRecursion(const C4Object *pCheckObj) const
StdMeshInstance * pMeshInstance
void Draw(C4TargetFacet &cgo, int32_t iByPlayer=-1, DrawMode eDrawMode=ODM_Normal, float offX=0, float offY=0)
void FinishedDrawing() const
C4DefGraphics * GetGraphics() const
void DenumeratePointers()
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
C4String * GetPropertyStr(C4PropertyName k) const
bool GetProperty(C4PropertyName k, C4Value *pResult) const
const char * GetName() const override
int32_t GetBaseRankNum() const
static bool DrawRankSymbol(C4FacetSurface *fctSymbol, int32_t iRank, C4Facet *pfctRankSymbols, int32_t iRankSymbolCount, bool fOwnSurface, int32_t iXOff=0, C4Facet *cgoDrawDirect=nullptr)
StdStrBuf GetData() const
C4String * RegString(StdStrBuf String)
void Set(const C4Facet &cpy)
C4PropList * getPropList() const
virtual bool Separator(Sep eSep=SEP_SEP)
void excCorrupt(const char *szMessage,...)
void Value(const T &rStruct)
virtual bool isDeserializer()
void Update(StdMeshInstance *instance) const
AttachedMesh * GetAttachParent() const
bool DetachMesh(unsigned int number)
AttachedMeshIter AttachedMeshesBegin() const
AnimationNode * PlayAnimation(const StdStrBuf &animation_name, int slot, AnimationNode *sibling, ValueProvider *position, ValueProvider *weight, bool stop_previous_animation)
void SetFaceOrderingForClrModulation(uint32_t clrmod)
const StdMesh & GetMesh() const
AttachedMeshIter AttachedMeshesEnd() const
AttachedMeshList::const_iterator AttachedMeshIter
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)
void Remove(const StdStrBuf &name, class StdMeshMaterialUpdate *update)
void Update(StdMesh *mesh) const
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)
void Update(StdMeshInstance *instance, const StdMesh &new_mesh) const
const StdMesh & GetOldMesh() const
const char * getData() const
void Append(const char *pnData, size_t iChars)