OpenClonk
C4ParticleDef Class Reference

#include <C4Particles.h>

Inheritance diagram for C4ParticleDef:
[legend]
Collaboration diagram for C4ParticleDef:
[legend]

Public Member Functions

 C4ParticleDef ()
 
 ~C4ParticleDef ()
 
void Clear ()
 
bool Load (C4Group &group)
 
bool Reload ()
 
void CompileFunc (StdCompiler *compiler)
 
bool Compile (char *particle_source, const char *name)
 

Public Attributes

C4ParticleDefprevious
 
C4ParticleDefnext
 
StdStrBuf Filename
 
C4FacetSurface Gfx
 
int32_t Length
 
int32_t PhasesX
 
float Aspect
 
StdStrBuf Name
 
C4Rect GfxFace
 

Detailed Description

Definition at line 83 of file C4Particles.h.

Constructor & Destructor Documentation

◆ C4ParticleDef()

C4ParticleDef::C4ParticleDef ( )

Definition at line 56 of file C4Particles.cpp.

57 {
58  // zero fields
59  Gfx.Default();
60  // link into list
61  if (!Particles.definitions.first)
62  {
63  previous = nullptr;
64  Particles.definitions.first = this;
65  }
66  else
67  {
69  previous->next = this;
70  }
71  Particles.definitions.last = this;
72  next = 0;
73 }
C4ParticleSystem Particles
void Default()
Definition: C4FacetEx.h:43
C4ParticleDef * next
Definition: C4Particles.h:86
C4FacetSurface Gfx
Definition: C4Particles.h:90
C4ParticleDef * previous
Definition: C4Particles.h:86
C4ParticleSystemDefinitionList definitions
Definition: C4Particles.h:510

References C4FacetSurface::Default(), C4ParticleSystem::definitions, Gfx, next, Particles, and previous.

Here is the call graph for this function:

◆ ~C4ParticleDef()

C4ParticleDef::~C4ParticleDef ( )

Definition at line 75 of file C4Particles.cpp.

76 {
77  // clear
78  Clear();
79  // unlink from list
80  if (previous) previous->next = next; else Particles.definitions.first = next;
82 }

References Clear(), C4ParticleSystem::definitions, next, Particles, and previous.

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4ParticleDef::Clear ( )

Definition at line 84 of file C4Particles.cpp.

85 {
86  Name.Clear();
87 }
StdStrBuf Name
Definition: C4Particles.h:73
void Clear()
Definition: StdBuf.h:466

References StdStrBuf::Clear(), and C4ParticleDefCore::Name.

Referenced by Reload(), and ~C4ParticleDef().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Compile()

bool C4ParticleDefCore::Compile ( char *  particle_source,
const char *  name 
)
inherited

Definition at line 50 of file C4Particles.cpp.

51 {
52  return CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(*this, "Particle"),
53  StdStrBuf(particle_source), name);
54 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92

References mkNamingAdapt().

Referenced by Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4ParticleDefCore::CompileFunc ( StdCompiler compiler)
inherited

Definition at line 39 of file C4Particles.cpp.

40 {
41  pComp->Value(mkNamingAdapt(toC4CStrBuf(Name), "Name", ""));
42  pComp->Value(mkNamingAdapt(GfxFace, "Face"));
43 }
#define toC4CStrBuf(rBuf)
Definition: StdAdaptors.h:25

References C4ParticleDefCore::GfxFace, mkNamingAdapt(), C4ParticleDefCore::Name, toC4CStrBuf, and StdCompiler::Value().

Here is the call graph for this function:

◆ Load()

bool C4ParticleDef::Load ( C4Group group)

Definition at line 89 of file C4Particles.cpp.

90 {
91  // store file
92  Filename.Copy(group.GetFullName());
93  // load
94  char *particle_source;
95  if (group.LoadEntry(C4CFN_ParticleCore,&particle_source,nullptr,1))
96  {
97  if (!Compile(particle_source, Filename.getData()))
98  {
99  DebugLogF("invalid particle def at '%s'", group.GetFullName().getData());
100  delete [] particle_source; return false;
101  }
102  delete [] particle_source;
103  // load graphics
105  {
106  DebugLogF("particle %s has no valid graphics defined", Name.getData());
107  return false;
108  }
109  // set facet, if assigned - otherwise, assume full surface
111  // set phase num
112  int32_t Q; Gfx.GetPhaseNum(PhasesX, Q);
113  Length = PhasesX * Q;
114  if (!Length)
115  {
116  DebugLogF("invalid facet for particle '%s'", Name.getData());
117  return false;
118  }
119  // calc aspect
120  Aspect=(float) Gfx.Hgt/Gfx.Wdt;
121 
122  // particle overloading
123  C4ParticleDef *def_overload;
124  if ((def_overload = Particles.definitions.GetDef(Name.getData(), this)))
125  {
127  { char ostr[250]; sprintf(ostr,LoadResStr("IDS_PRC_DEFOVERLOAD"),def_overload->Name.getData(),"<particle>"); Log(ostr); }
128  delete def_overload;
129  }
130  // success
131  return true;
132  }
133  return false;
134 }
#define C4CFN_ParticleCore
Definition: C4Components.h:48
#define C4CFN_DefGraphics
Definition: C4Components.h:99
C4Config Config
Definition: C4Config.cpp:930
const int C4FCT_Full
Definition: C4FacetEx.h:26
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
bool DebugLogF(const char *strMessage ...)
Definition: C4Log.cpp:290
const int C4SF_MipMap
Definition: C4Surface.h:50
#define sprintf
Definition: Standard.h:162
int32_t VerboseObjectLoading
Definition: C4Config.h:100
C4ConfigGraphics Graphics
Definition: C4Config.h:257
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
float Wdt
Definition: C4Facet.h:118
bool GetPhaseNum(int32_t &rX, int32_t &rY)
Definition: C4Facet.cpp:472
bool Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags)
Definition: C4FacetEx.cpp:84
void Set(const C4Facet &cpy)
Definition: C4FacetEx.h:46
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2638
bool LoadEntry(const char *entry_name, char **buffer, size_t *size_info=nullptr, int zeros_to_append=0)
Definition: C4Group.cpp:2375
bool Compile(char *particle_source, const char *name)
Definition: C4Particles.cpp:50
int32_t Length
Definition: C4Particles.h:91
StdStrBuf Filename
Definition: C4Particles.h:88
int32_t PhasesX
Definition: C4Particles.h:92
C4ParticleDef * GetDef(const char *name, C4ParticleDef *exclude=nullptr)
int32_t y
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30
const char * getData() const
Definition: StdBuf.h:442
void Copy()
Definition: StdBuf.h:467

References Aspect, C4CFN_DefGraphics, C4CFN_ParticleCore, C4FCT_Full, C4SF_MipMap, C4ParticleDefCore::Compile(), Config, StdStrBuf::Copy(), DebugLogF(), C4ParticleSystem::definitions, Filename, StdStrBuf::getData(), C4ParticleSystemDefinitionList::GetDef(), C4Group::GetFullName(), C4Facet::GetPhaseNum(), Gfx, C4ParticleDefCore::GfxFace, C4Config::Graphics, C4Facet::Hgt, C4Rect::Hgt, Length, C4FacetSurface::Load(), C4Group::LoadEntry(), LoadResStr(), Log(), C4ParticleDefCore::Name, Particles, PhasesX, C4FacetSurface::Set(), sprintf, C4Facet::Surface, C4ConfigGraphics::VerboseObjectLoading, C4Facet::Wdt, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by Reload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reload()

bool C4ParticleDef::Reload ( )

Definition at line 136 of file C4Particles.cpp.

137 {
138  // no file?
139  if (!Filename[0]) return false;
140  // open group
141  C4Group group;
142  if (!group.Open(Filename.getData())) return false;
143  // reset class
144  Clear();
145  // load
146  return Load(group);
147 }
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660
bool Load(C4Group &group)
Definition: C4Particles.cpp:89

References Clear(), Filename, StdStrBuf::getData(), Load(), and C4Group::Open().

Referenced by C4Game::ReloadParticle().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Aspect

float C4ParticleDef::Aspect

Definition at line 93 of file C4Particles.h.

Referenced by C4ParticleSystem::Create(), and Load().

◆ Filename

StdStrBuf C4ParticleDef::Filename

Definition at line 88 of file C4Particles.h.

Referenced by Load(), Reload(), and C4Game::ReloadParticle().

◆ Gfx

C4FacetSurface C4ParticleDef::Gfx

Definition at line 90 of file C4Particles.h.

Referenced by C4ParticleDef(), and Load().

◆ GfxFace

C4Rect C4ParticleDefCore::GfxFace
inherited

◆ Length

int32_t C4ParticleDef::Length

Definition at line 91 of file C4Particles.h.

Referenced by Load(), and C4Particle::DrawingData::SetPhase().

◆ Name

StdStrBuf C4ParticleDefCore::Name
inherited

◆ next

C4ParticleDef * C4ParticleDef::next

◆ PhasesX

int32_t C4ParticleDef::PhasesX

Definition at line 92 of file C4Particles.h.

Referenced by Load(), and C4Particle::DrawingData::SetPhase().

◆ previous

C4ParticleDef* C4ParticleDef::previous

Definition at line 86 of file C4Particles.h.

Referenced by C4ParticleDef(), and ~C4ParticleDef().


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