2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 2004 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
// graphics used by object definitions (object and portraits)
# ifndef INC_C4DefGraphics
# define INC_C4DefGraphics
2016-10-22 11:19:22 +00:00
# include "graphics/C4Facet.h"
2016-04-03 18:07:56 +00:00
# include "object/C4ObjectPtr.h"
# include "lib/C4InputValidation.h"
# include "lib/StdMeshUpdate.h"
2016-10-20 16:30:05 +00:00
# include "object/C4Id.h"
2009-05-08 13:28:41 +00:00
// defintion graphics
class C4AdditionalDefGraphics ;
class C4DefGraphicsPtrBackup ;
class C4DefGraphics
2010-03-28 17:58:21 +00:00
{
public :
C4Def * pDef ; // underlying definition
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
protected :
C4AdditionalDefGraphics * pNext ; // next graphics
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
C4DefGraphics * GetLast ( ) ; // get last graphics in list
public :
enum GraphicsType
{
2015-01-17 17:10:21 +00:00
TYPE_None ,
2010-03-28 17:58:21 +00:00
TYPE_Bitmap ,
TYPE_Mesh
} ;
2009-07-10 23:10:18 +00:00
2010-03-28 17:58:21 +00:00
GraphicsType Type ;
2009-07-10 23:10:18 +00:00
2010-03-28 17:58:21 +00:00
union
{
struct
{
2014-11-07 20:28:52 +00:00
C4Surface * Bitmap , * BitmapClr , * BitmapNormal ;
2010-03-28 17:58:21 +00:00
} Bmp ;
StdMesh * Mesh ;
} ;
2009-07-10 23:10:18 +00:00
2010-03-28 17:58:21 +00:00
bool fColorBitmapAutoCreated ; // if set, the color-by-owner-bitmap has been created automatically by all blue shades of the bitmap
2009-05-08 13:28:41 +00:00
2016-10-22 11:19:22 +00:00
C4Surface * GetBitmap ( DWORD dwClr = 0 ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
C4DefGraphics ( C4Def * pOwnDef = NULL ) ; // ctor
virtual ~ C4DefGraphics ( ) { Clear ( ) ; } ; // dtor
2009-05-08 13:28:41 +00:00
2014-11-07 20:28:52 +00:00
bool LoadBitmap ( C4Group & hGroup , const char * szFilenamePNG , const char * szOverlayPNG , const char * szNormal , bool fColorByOwner ) ; // load specified graphics from group
2010-03-28 17:58:21 +00:00
bool LoadBitmaps ( C4Group & hGroup , bool fColorByOwner ) ; // load graphics from group
2012-10-14 12:37:45 +00:00
bool LoadMesh ( C4Group & hGroup , const char * szFilename , StdMeshSkeletonLoader & loader ) ;
2014-12-16 04:42:34 +00:00
bool LoadSkeleton ( C4Group & hGroup , const char * szFilename , StdMeshSkeletonLoader & loader ) ;
2014-12-26 13:46:31 +00:00
bool Load ( C4Group & hGroup , StdMeshSkeletonLoader & loader , bool fColorByOwner ) ; // load graphics from group
2010-03-28 17:58:21 +00:00
C4DefGraphics * Get ( const char * szGrpName ) ; // get graphics by name
void Clear ( ) ; // clear fields; delete additional graphics
2014-04-18 12:09:49 +00:00
bool IsMesh ( ) const { return Type = = TYPE_Mesh ; }
2010-03-28 17:58:21 +00:00
bool IsColorByOwner ( ) // returns whether ColorByOwner-surfaces have been created
2015-01-17 17:10:21 +00:00
{ return Type = = TYPE_Mesh | | ( Type = = TYPE_Bitmap & & ! ! Bmp . BitmapClr ) ; } // Mesh can always apply PlayerColor (if used in its material)
2009-05-08 13:28:41 +00:00
2012-02-26 20:09:42 +00:00
void Draw ( C4Facet & cgo , DWORD iColor , C4Object * pObj , int32_t iPhaseX , int32_t iPhaseY , C4DrawTransform * trans ) ;
2010-03-28 17:58:21 +00:00
virtual const char * GetName ( ) { return NULL ; } // return name to be stored in safe game files
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
C4AdditionalDefGraphics * GetNext ( ) { return pNext ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void DrawClr ( C4Facet & cgo , bool fAspect = true , DWORD dwClr = 0 ) ; // set surface color and draw
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void CompileFunc ( StdCompiler * pComp ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
friend class C4DefGraphicsPtrBackup ;
} ;
2009-05-08 13:28:41 +00:00
// additional definition graphics
class C4AdditionalDefGraphics : public C4DefGraphics
2010-03-28 17:58:21 +00:00
{
protected :
char Name [ C4MaxName + 1 ] ; // graphics name
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
C4AdditionalDefGraphics ( C4Def * pOwnDef , const char * szName ) ; // ctor
virtual const char * GetName ( ) { return Name ; }
} ;
2009-05-08 13:28:41 +00:00
// backup class holding dead graphics pointers and names
2014-12-26 12:46:14 +00:00
class C4DefGraphicsPtrBackupEntry
2010-03-28 17:58:21 +00:00
{
protected :
C4DefGraphics * pGraphicsPtr ; // dead graphics ptr
C4Def * pDef ; // definition of dead graphics
char Name [ C4MaxName + 1 ] ; // name of graphics
2011-08-19 22:01:08 +00:00
StdMeshUpdate * pMeshUpdate ; // Dead mesh
2010-03-28 17:58:21 +00:00
public :
2014-12-26 12:46:14 +00:00
C4DefGraphicsPtrBackupEntry ( C4DefGraphics * pSourceGraphics ) ; // ctor
~ C4DefGraphicsPtrBackupEntry ( ) ; // dtor
2010-03-28 17:58:21 +00:00
2014-12-26 12:46:14 +00:00
void AssignUpdate ( ) ; // update all game objects with new graphics pointers
void AssignRemoval ( ) ; // remove graphics of this def from all game objects
private :
void UpdateAttachedMeshes ( ) ;
void UpdateAttachedMesh ( StdMeshInstance * instance ) ;
} ;
// On definition reload, all graphics updates need to be performed in one
// batch using this class.
class C4DefGraphicsPtrBackup
{
public :
C4DefGraphicsPtrBackup ( ) ;
~ C4DefGraphicsPtrBackup ( ) ;
// Add a def graphics to the list of graphics to be updated.
// Also adds additional graphics linked from pGraphics.
void Add ( C4DefGraphics * pGraphics ) ;
void AssignUpdate ( ) ; // update all game objects with new graphics pointers
void AssignRemoval ( ) ; // remove graphics of all defs from all game objects
2011-08-17 21:50:33 +00:00
2016-04-02 20:54:54 +00:00
StdMeshMaterialUpdate & GetUpdater ( ) { return MeshMaterialUpdate ; }
2011-08-17 21:50:33 +00:00
private :
2011-08-19 22:01:08 +00:00
void UpdateMesh ( StdMeshInstance * instance ) ;
2014-12-26 12:46:14 +00:00
StdMeshMaterialUpdate MeshMaterialUpdate ; // Backup of dead mesh materials
StdMeshAnimationUpdate MeshAnimationUpdate ; // Backup of animation names in the animation tree
std : : list < C4DefGraphicsPtrBackupEntry * > Entries ;
bool fApplied ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
// Helper to compile C4DefGraphics-Pointer
class C4DefGraphicsAdapt
2010-03-28 17:58:21 +00:00
{
protected :
C4DefGraphics * & pDefGraphics ;
public :
C4DefGraphicsAdapt ( C4DefGraphics * & pDefGraphics ) : pDefGraphics ( pDefGraphics ) { }
void CompileFunc ( StdCompiler * pComp ) ;
// Default checking / setting
bool operator = = ( C4DefGraphics * pDef2 ) { return pDefGraphics = = pDef2 ; }
void operator = ( C4DefGraphics * pDef2 ) { pDefGraphics = pDef2 ; }
} ;
2009-05-08 13:28:41 +00:00
// graphics overlay used to attach additional graphics to objects
class C4GraphicsOverlay
2010-03-28 17:58:21 +00:00
{
2014-12-26 12:46:14 +00:00
friend class C4DefGraphicsPtrBackupEntry ;
2011-08-17 21:50:33 +00:00
friend class C4DefGraphicsPtrBackup ;
2010-03-28 17:58:21 +00:00
public :
enum Mode
2009-05-08 13:28:41 +00:00
{
2010-03-28 17:58:21 +00:00
MODE_None = 0 ,
MODE_Base = 1 , // display base facet
MODE_Action = 2 , // display action facet specified in Action
MODE_Picture = 3 , // overlay picture to this picture only
MODE_IngamePicture = 4 , // draw picture of source def
MODE_Object = 5 , // draw another object gfx
MODE_ExtraGraphics = 6 , // draw like this were a ClrByOwner-surface
MODE_Rank = 7 , // draw rank symbol
MODE_ObjectPicture = 8 // draw the picture of source object
} ;
protected :
Mode eMode ; // overlay mode
C4DefGraphics * pSourceGfx ; // source graphics - used for savegame saving and comparisons in ReloadDef
char Action [ C4MaxName + 1 ] ; // action used as overlay in source gfx
C4TargetFacet fctBlit ; // current blit data for bitmap graphics
2010-04-01 21:00:05 +00:00
StdMeshInstance * pMeshInstance ; // NoSave // - current blit data for mesh graphics
2010-03-28 17:58:21 +00:00
uint32_t dwBlitMode ; // extra parameters for additive blits, etc.
uint32_t dwClrModulation ; // colormod for this overlay
2010-03-30 21:08:15 +00:00
C4ObjectPtr OverlayObj ; // object to be drawn as overlay in MODE_Object
2010-03-28 17:58:21 +00:00
C4DrawTransform Transform ; // drawing transformation: Rotation, zoom, etc.
int32_t iPhase ; // action face for MODE_Action
bool fZoomToShape ; // if true, overlay will be zoomed to match the target object shape
int32_t iID ; // identification number for Z-ordering and script identification
C4GraphicsOverlay * pNext ; // singly linked list
void UpdateFacet ( ) ; // update fctBlit to reflect current data
void Set ( Mode aMode , C4DefGraphics * pGfx , const char * szAction , DWORD dwBMode , C4Object * pOvrlObj ) ;
public :
C4GraphicsOverlay ( ) : eMode ( MODE_None ) , pSourceGfx ( NULL ) , fctBlit ( ) , pMeshInstance ( NULL ) , dwBlitMode ( 0 ) , dwClrModulation ( 0xffffff ) ,
2010-03-30 21:08:15 +00:00
OverlayObj ( NULL ) , Transform ( + 1 ) ,
2009-05-08 13:28:41 +00:00
iPhase ( 0 ) , fZoomToShape ( false ) , iID ( 0 ) , pNext ( NULL ) { * Action = 0 ; } // std ctor
2010-03-28 17:58:21 +00:00
~ C4GraphicsOverlay ( ) ; // dtor
void CompileFunc ( StdCompiler * pComp ) ;
// object pointer management
void DenumeratePointers ( ) ;
void SetAsBase ( C4DefGraphics * pBaseGfx , DWORD dwBMode ) // set in MODE_Base
{ Set ( MODE_Base , pBaseGfx , NULL , dwBMode , NULL ) ; }
void SetAsAction ( C4DefGraphics * pBaseGfx , const char * szAction , DWORD dwBMode )
{ Set ( MODE_Action , pBaseGfx , szAction , dwBMode , NULL ) ; }
void SetAsPicture ( C4DefGraphics * pBaseGfx , DWORD dwBMode )
{ Set ( MODE_Picture , pBaseGfx , NULL , dwBMode , NULL ) ; }
void SetAsIngamePicture ( C4DefGraphics * pBaseGfx , DWORD dwBMode )
{ Set ( MODE_IngamePicture , pBaseGfx , NULL , dwBMode , NULL ) ; }
void SetAsObject ( C4Object * pOverlayObj , DWORD dwBMode )
{ Set ( MODE_Object , NULL , NULL , dwBMode , pOverlayObj ) ; }
void SetAsObjectPicture ( C4Object * pOverlayObj , DWORD dwBMode )
{ Set ( MODE_ObjectPicture , NULL , NULL , dwBMode , pOverlayObj ) ; }
void SetAsExtraGraphics ( C4DefGraphics * pGfx , DWORD dwBMode )
{ Set ( MODE_ExtraGraphics , pGfx , NULL , dwBMode , NULL ) ; }
void SetAsRank ( DWORD dwBMode , C4Object * rank_obj )
{ Set ( MODE_Rank , NULL , NULL , dwBMode , rank_obj ) ; }
bool IsValid ( const C4Object * pForObj ) const ;
C4DrawTransform * GetTransform ( ) { return & Transform ; }
2010-03-30 21:08:15 +00:00
C4Object * GetOverlayObject ( ) const { return OverlayObj ; }
2010-03-28 17:58:21 +00:00
int32_t GetID ( ) const { return iID ; }
void SetID ( int32_t aID ) { iID = aID ; }
void SetPhase ( int32_t iToPhase ) ;
C4GraphicsOverlay * GetNext ( ) const { return pNext ; }
void SetNext ( C4GraphicsOverlay * paNext ) { pNext = paNext ; }
bool IsPicture ( ) { return eMode = = MODE_Picture ; }
C4DefGraphics * GetGfx ( ) const { return pSourceGfx ; }
void Draw ( C4TargetFacet & cgo , C4Object * pForObj , int32_t iByPlayer ) ;
2010-06-28 22:12:52 +00:00
void DrawPicture ( C4Facet & cgo , C4Object * pForObj , C4DrawTransform * trans ) ;
2010-03-28 17:58:21 +00:00
void DrawRankSymbol ( C4Facet & cgo , C4Object * rank_obj ) ;
bool operator = = ( const C4GraphicsOverlay & rCmp ) const ; // comparison operator
uint32_t GetClrModulation ( ) const { return dwClrModulation ; }
void SetClrModulation ( uint32_t dwToMod ) { dwClrModulation = dwToMod ; }
uint32_t GetBlitMode ( ) const { return dwBlitMode ; }
void SetBlitMode ( uint32_t dwToMode ) { dwBlitMode = dwToMode ; }
} ;
2009-05-08 13:28:41 +00:00
// Helper to compile lists of C4GraphicsOverlay
class C4GraphicsOverlayListAdapt
2010-03-28 17:58:21 +00:00
{
protected :
C4GraphicsOverlay * & pOverlay ;
public :
C4GraphicsOverlayListAdapt ( C4GraphicsOverlay * & pOverlay ) : pOverlay ( pOverlay ) { }
void CompileFunc ( StdCompiler * pComp ) ;
// Default checking / setting
bool operator = = ( C4GraphicsOverlay * pDefault ) { return pOverlay = = pDefault ; }
void operator = ( C4GraphicsOverlay * pDefault ) { delete pOverlay ; pOverlay = pDefault ; }
} ;
2009-05-08 13:28:41 +00:00
# endif // INC_C4DefGraphics