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

#include <C4DefGraphics.h>

Collaboration diagram for C4DefGraphicsPtrBackupEntry:
[legend]

Public Member Functions

 C4DefGraphicsPtrBackupEntry (C4DefGraphics *pSourceGraphics)
 
 ~C4DefGraphicsPtrBackupEntry ()
 
void AssignUpdate ()
 
void AssignRemoval ()
 

Protected Attributes

C4DefGraphicspGraphicsPtr
 
C4DefpDef
 
char Name [C4MaxName+1]
 
StdMeshUpdatepMeshUpdate
 

Detailed Description

Definition at line 102 of file C4DefGraphics.h.

Constructor & Destructor Documentation

C4DefGraphicsPtrBackupEntry::C4DefGraphicsPtrBackupEntry ( C4DefGraphics pSourceGraphics)

Definition at line 421 of file C4DefGraphics.cpp.

References C4MaxName, C4DefGraphics::GetName(), Name, C4DefGraphics::pDef, pDef, pGraphicsPtr, pMeshUpdate, SCopy(), C4DefGraphics::Type, and C4DefGraphics::TYPE_Mesh.

421  :
422  pMeshUpdate(nullptr)
423 {
424  // assign graphics + def
425  pGraphicsPtr = pSourceGraphics;
426  pDef = pSourceGraphics->pDef;
427  // assign name
428  const char *szName = pGraphicsPtr->GetName();
429  if (szName) SCopy(szName, Name, C4MaxName); else *Name=0;
430 
431  // assign mesh update
432  if(pSourceGraphics->Type == C4DefGraphics::TYPE_Mesh)
433  pMeshUpdate = new StdMeshUpdate(*pSourceGraphics->Mesh);
434 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
StdMeshUpdate * pMeshUpdate
char Name[C4MaxName+1]
C4Def * pDef
virtual const char * GetName()
Definition: C4DefGraphics.h:79
const unsigned int C4MaxName
C4DefGraphics * pGraphicsPtr
GraphicsType Type
Definition: C4DefGraphics.h:48

Here is the call graph for this function:

C4DefGraphicsPtrBackupEntry::~C4DefGraphicsPtrBackupEntry ( )

Definition at line 436 of file C4DefGraphics.cpp.

References AssignRemoval(), pGraphicsPtr, and pMeshUpdate.

437 {
438  // graphics ptr still assigned? then remove dead graphics pointers from objects
440  delete pMeshUpdate;
441 }
StdMeshUpdate * pMeshUpdate
void AssignRemoval()
C4DefGraphics * pGraphicsPtr

Here is the call graph for this function:

Member Function Documentation

void C4DefGraphicsPtrBackupEntry::AssignRemoval ( )

Definition at line 506 of file C4DefGraphics.cpp.

References C4GraphicsOverlay::GetGfx(), C4GraphicsOverlay::GetID(), C4GraphicsOverlay::GetNext(), StdMeshUpdate::GetOldMesh(), C4Def::id, C4GUI::FrameDecoration::idSourceDef, Objects, pDef, pGraphicsPtr, and pMeshUpdate.

Referenced by ~C4DefGraphicsPtrBackupEntry().

507 {
508  // Remove all attached meshes that were using this mesh
509  UpdateAttachedMeshes();
510 
511  // only if graphics are assigned
512  if (pGraphicsPtr)
513  {
514  // check all objects
515  for (C4Object *pObj : Objects)
516  if (pObj && pObj->Status)
517  {
518  if (pObj->pGraphics == pGraphicsPtr)
519  {
520  // same graphics found. If these are mesh graphics then remove
521  // the object because the StdMesh has already been unloaded.
522  if(pObj->pMeshInstance)
523  {
524  assert(&pObj->pMeshInstance->GetMesh() == &pMeshUpdate->GetOldMesh());
525 
526  pObj->AssignRemoval();
527  delete pObj->pMeshInstance;
528  pObj->pMeshInstance = nullptr;
529  pObj->pGraphics = nullptr;
530  }
531  // sprite graphics; reset them
532  else if (!pObj->SetGraphics()) { pObj->AssignRemoval(); pObj->pGraphics=nullptr; }
533  }
534  // remove any overlay graphics
535  for (;;)
536  {
537  C4GraphicsOverlay *pGfxOverlay;
538  for (pGfxOverlay = pObj->pGfxOverlay; pGfxOverlay; pGfxOverlay = pGfxOverlay->GetNext())
539  if (pGfxOverlay->GetGfx() == pGraphicsPtr)
540  {
541  // then remove this overlay and redo the loop, because iterator has become invalid
542  pObj->RemoveGraphicsOverlay(pGfxOverlay->GetID());
543  break;
544  }
545  // looped through w/o removal?
546  if (!pGfxOverlay) break;
547  }
548  // remove menu frame decorations
549  C4GUI::FrameDecoration *pDeco;
550  if (pDef && pObj->Menu && (pDeco = pObj->Menu->GetFrameDecoration()))
551  if (pDeco->idSourceDef == pDef->id)
552  pObj->Menu->SetFrameDeco(nullptr);
553  }
554  // done; reset field to indicate finished update
555  pGraphicsPtr = nullptr;
556  }
557 }
C4ID id
Definition: C4Def.h:101
StdMeshUpdate * pMeshUpdate
C4Def * pDef
C4DefGraphics * pGraphicsPtr
C4DefGraphics * GetGfx() const
int32_t GetID() const
const StdMesh & GetOldMesh() const
Definition: StdMeshUpdate.h:56
C4GameObjects Objects
Definition: C4Globals.cpp:48
C4GraphicsOverlay * GetNext() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4DefGraphicsPtrBackupEntry::AssignUpdate ( )

Definition at line 443 of file C4DefGraphics.cpp.

References C4DefGraphics::Get(), C4GraphicsOverlay::GetGfx(), C4GraphicsOverlay::GetID(), C4GraphicsOverlay::GetNext(), StdMeshUpdate::GetOldMesh(), C4Def::Graphics, C4Def::id, C4GUI::FrameDecoration::idSourceDef, Name, Objects, pDef, pGraphicsPtr, pMeshUpdate, C4DefGraphics::TYPE_Mesh, StdMeshUpdate::Update(), and C4GUI::FrameDecoration::UpdateGfx().

444 {
445  // Update all attached meshes that were using this mesh
446  UpdateAttachedMeshes();
447 
448  // only if graphics are assigned
449  if (pGraphicsPtr)
450  {
451  // check all objects
452  for (C4Object *pObj : Objects)
453  {
454  if (pObj && pObj->Status)
455  {
456  if (pObj->pGraphics == pGraphicsPtr)
457  {
458  // same graphics found. Update mesh graphics if any.
459  if(pMeshUpdate)
460  {
461  assert(pObj->pMeshInstance != nullptr); // object had mesh graphics, so mesh instance should be present
462  assert(&pObj->pMeshInstance->GetMesh() == &pMeshUpdate->GetOldMesh()); // mesh instance of correct type even
463 
464  // Get new mesh from reloaded graphics
465  C4DefGraphics *pGrp = pDef->Graphics.Get(Name);
466  if(pGrp && pGrp->Type == C4DefGraphics::TYPE_Mesh)
467  pMeshUpdate->Update(pObj->pMeshInstance, *pGrp->Mesh);
468  }
469 
470  // try to set new graphics
471  if (!pObj->SetGraphics(Name, pDef))
472  if (!pObj->SetGraphics(Name, pObj->Def))
473  {
474  // shouldn't happen
475  pObj->AssignRemoval(); pObj->pGraphics=nullptr;
476  }
477  }
478 
479  // remove any overlay graphics
480  for (;;)
481  {
482  C4GraphicsOverlay *pGfxOverlay;
483  for (pGfxOverlay = pObj->pGfxOverlay; pGfxOverlay; pGfxOverlay = pGfxOverlay->GetNext())
484  if (pGfxOverlay->GetGfx() == pGraphicsPtr)
485  {
486  // then remove this overlay and redo the loop, because iterator has become invalid
487  pObj->RemoveGraphicsOverlay(pGfxOverlay->GetID());
488  break;
489  }
490  // looped through w/o removal?
491  if (!pGfxOverlay) break;
492  }
493  // update menu frame decorations - may do multiple updates to the same deco if multiple menus share it...
494  C4GUI::FrameDecoration *pDeco;
495  if (pDef && pObj->Menu && (pDeco = pObj->Menu->GetFrameDecoration()))
496  if (pDeco->idSourceDef == pDef->id)
497  if (!pDeco->UpdateGfx())
498  pObj->Menu->SetFrameDeco(nullptr);
499  }
500  }
501  // done; reset field to indicate finished update
502  pGraphicsPtr = nullptr;
503  }
504 }
C4ID id
Definition: C4Def.h:101
StdMeshUpdate * pMeshUpdate
C4DefGraphics * Get(const char *szGrpName)
char Name[C4MaxName+1]
C4Def * pDef
void Update(StdMeshInstance *instance, const StdMesh &new_mesh) const
C4DefGraphics * pGraphicsPtr
C4DefGraphics * GetGfx() const
int32_t GetID() const
const StdMesh & GetOldMesh() const
Definition: StdMeshUpdate.h:56
C4DefGraphics Graphics
Definition: C4Def.h:191
C4GameObjects Objects
Definition: C4Globals.cpp:48
C4GraphicsOverlay * GetNext() const

Here is the call graph for this function:

Member Data Documentation

char C4DefGraphicsPtrBackupEntry::Name[C4MaxName+1]
protected

Definition at line 107 of file C4DefGraphics.h.

Referenced by AssignUpdate(), and C4DefGraphicsPtrBackupEntry().

C4Def* C4DefGraphicsPtrBackupEntry::pDef
protected

Definition at line 106 of file C4DefGraphics.h.

Referenced by AssignRemoval(), AssignUpdate(), and C4DefGraphicsPtrBackupEntry().

C4DefGraphics* C4DefGraphicsPtrBackupEntry::pGraphicsPtr
protected
StdMeshUpdate* C4DefGraphicsPtrBackupEntry::pMeshUpdate
protected

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