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 425 of file C4DefGraphics.cpp.

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

425  :
426  pMeshUpdate(nullptr)
427 {
428  // assign graphics + def
429  pGraphicsPtr = pSourceGraphics;
430  pDef = pSourceGraphics->pDef;
431  // assign name
432  const char *szName = pGraphicsPtr->GetName();
433  if (szName) SCopy(szName, Name, C4MaxName); else *Name=0;
434 
435  // assign mesh update
436  if(pSourceGraphics->Type == C4DefGraphics::TYPE_Mesh)
437  pMeshUpdate = new StdMeshUpdate(*pSourceGraphics->Mesh);
438 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:129
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 440 of file C4DefGraphics.cpp.

References AssignRemoval(), pGraphicsPtr, and pMeshUpdate.

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

Here is the call graph for this function:

Member Function Documentation

void C4DefGraphicsPtrBackupEntry::AssignRemoval ( )

Definition at line 510 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().

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

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