OpenClonk
C4ParticleList Class Reference

#include <C4Particles.h>

Public Member Functions

 C4ParticleList (C4Object *obj=nullptr)
 
 C4ParticleList (const C4ParticleList &)=delete
 
C4ParticleListoperator= (const C4ParticleList &)=delete
 
 ~C4ParticleList ()
 
void Lock ()
 
void Unlock ()
 
void Clear ()
 
void Exec (float timeDelta=1.f)
 
void Draw (C4TargetFacet cgo, C4Object *obj)
 
C4ParticleChunkGetFittingParticleChunk (C4ParticleDef *def, uint32_t blitMode, uint32_t attachment, bool alreadyLocked)
 
C4ParticleAddNewParticle (C4ParticleDef *def, uint32_t blitMode, uint32_t attachment, bool alreadyLocked, int remaining=0)
 

Detailed Description

Definition at line 391 of file C4Particles.h.

Constructor & Destructor Documentation

◆ C4ParticleList() [1/2]

C4ParticleList::C4ParticleList ( C4Object obj = nullptr)
inline

Definition at line 405 of file C4Particles.h.

405  : targetObject(obj), lastAccessedChunk(nullptr)
406  {
407 
408  }

◆ C4ParticleList() [2/2]

C4ParticleList::C4ParticleList ( const C4ParticleList )
delete

◆ ~C4ParticleList()

C4ParticleList::~C4ParticleList ( )
inline

Definition at line 413 of file C4Particles.h.

413 { Clear(); }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AddNewParticle()

C4Particle* C4ParticleList::AddNewParticle ( C4ParticleDef def,
uint32_t  blitMode,
uint32_t  attachment,
bool  alreadyLocked,
int  remaining = 0 
)

◆ Clear()

void C4ParticleList::Clear ( )

Definition at line 1196 of file C4Particles.cpp.

1197 {
1198  accessMutex.Enter();
1199 
1200  for (std::list<C4ParticleChunk*>::iterator iter = particleChunks.begin(); iter != particleChunks.end(); ++iter)
1201  delete *iter;
1202  particleChunks.clear();
1203 
1204  if (targetObject)
1205  {
1206  if (this == targetObject->FrontParticles) targetObject->FrontParticles = nullptr;
1207  else if (this == targetObject->BackParticles) targetObject->BackParticles = nullptr;
1208  }
1209  else
1210  if(this == ::Particles.globalParticles) ::Particles.globalParticles = nullptr;
1211 
1212  accessMutex.Leave();
1213 }
C4ParticleSystem Particles
class C4ParticleList * BackParticles
Definition: C4Object.h:157
class C4ParticleList * FrontParticles
Definition: C4Object.h:157
virtual void Leave()
Definition: StdSync.h:151
virtual void Enter()
Definition: StdSync.h:150

References Particles.

Referenced by ~C4ParticleList().

Here is the caller graph for this function:

◆ Draw()

void C4ParticleList::Draw ( C4TargetFacet  cgo,
C4Object obj 
)

Definition at line 1151 of file C4Particles.cpp.

1152 {
1153  if (particleChunks.empty()) return;
1154 
1156  pDraw->ResetBlitMode();
1157 
1158  glPrimitiveRestartIndex(0xffffffff);
1159  glEnable(GL_PRIMITIVE_RESTART);
1160 
1161  // enable shader
1162  C4ShaderCall call(pGL->GetSpriteShader(true, false, false));
1163  // apply zoom and upload shader uniforms
1165  pGL->SetupMultiBlt(call, nullptr, 0, 0, 0, 0, &modelview);
1166  // go to correct output position (note the normal matrix is unaffected
1167  // by this)
1168  Translate(modelview, cgo.X-cgo.TargetX, cgo.Y-cgo.TargetY, 0.0f);
1169  // allocate texture unit for particle texture, and remember allocated
1170  // texture unit. Will be used for each particle chunk to bind
1171  // their texture to this unit.
1172  const GLint texUnit = call.AllocTexUnit(C4SSU_BaseTex);
1173 
1174  accessMutex.Enter();
1175 
1176  for (std::list<C4ParticleChunk*>::iterator iter = particleChunks.begin(); iter != particleChunks.end(); )
1177  {
1178  if ((*iter)->IsEmpty())
1179  {
1180  delete *iter;
1181  iter = particleChunks.erase(iter);
1182  lastAccessedChunk = 0;
1183  }
1184  else
1185  {
1186  (*iter)->Draw(cgo, obj, call, texUnit, modelview);
1187  ++iter;
1188  }
1189  }
1190 
1191  accessMutex.Leave();
1192 
1193  glDisable(GL_PRIMITIVE_RESTART);
1194 }
C4Draw * pDraw
Definition: C4Draw.cpp:42
CStdGL * pGL
Definition: C4DrawGL.cpp:907
@ C4SSU_BaseTex
Definition: C4DrawGL.h:60
void Translate(MatrixType &mat, float dx, float dy, float dz)
Definition: StdMeshMath.h:185
void DeactivateBlitModulation()
Definition: C4Draw.h:189
void ResetBlitMode()
Definition: C4Draw.h:192
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
void Draw(C4TargetFacet cgo, C4Object *obj, C4ShaderCall &call, int texUnit, const StdProjectionMatrix &modelview)
float TargetY
Definition: C4Facet.h:165
float TargetX
Definition: C4Facet.h:165
void SetupMultiBlt(C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
Definition: C4DrawGL.cpp:356
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:673
static StdProjectionMatrix Identity()

References C4ShaderCall::AllocTexUnit(), C4SSU_BaseTex, C4Draw::DeactivateBlitModulation(), CStdGL::GetSpriteShader(), StdProjectionMatrix::Identity(), pDraw, pGL, C4Draw::ResetBlitMode(), CStdGL::SetupMultiBlt(), C4TargetFacet::TargetX, C4TargetFacet::TargetY, Translate(), C4Facet::X, and C4Facet::Y.

Referenced by C4Object::Draw(), and C4ParticleSystem::DrawGlobalParticles().

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

◆ Exec()

void C4ParticleList::Exec ( float  timeDelta = 1.f)

Definition at line 1136 of file C4Particles.cpp.

1137 {
1138  if (particleChunks.empty()) return;
1139 
1140  accessMutex.Enter();
1141 
1142  for (std::list<C4ParticleChunk*>::iterator iter = particleChunks.begin(); iter != particleChunks.end();++iter)
1143  {
1144  C4ParticleChunk *chunk = *iter;
1145  chunk->Exec(targetObject, timeDelta);
1146  }
1147 
1148  accessMutex.Leave();
1149 }
bool Exec(C4Object *obj, float timeDelta)

References C4ParticleChunk::Exec().

Here is the call graph for this function:

◆ GetFittingParticleChunk()

C4ParticleChunk * C4ParticleList::GetFittingParticleChunk ( C4ParticleDef def,
uint32_t  blitMode,
uint32_t  attachment,
bool  alreadyLocked 
)

Definition at line 1215 of file C4Particles.cpp.

1216 {
1217  if (!alreadyLocked)
1218  accessMutex.Enter();
1219 
1220  // if not cached, find correct chunk in list
1221  C4ParticleChunk *chunk = 0;
1222  if (lastAccessedChunk && lastAccessedChunk->IsOfType(def, blitMode, attachment))
1223  chunk = lastAccessedChunk;
1224  else
1225  {
1226  for (std::list<C4ParticleChunk*>::iterator iter = particleChunks.begin(); iter != particleChunks.end(); ++iter)
1227  {
1228  C4ParticleChunk *current = *iter;
1229  if (!current->IsOfType(def, blitMode, attachment)) continue;
1230  chunk = current;
1231  break;
1232  }
1233  }
1234 
1235  // add new chunk?
1236  if (!chunk)
1237  {
1238  particleChunks.push_back(new C4ParticleChunk());
1239  chunk = particleChunks.back();
1240  chunk->sourceDefinition = def;
1241  chunk->blitMode = blitMode;
1242  chunk->attachment = attachment;
1243  }
1244 
1245  assert(chunk && "No suitable particle chunk could be found or created.");
1246  lastAccessedChunk = chunk;
1247 
1248  if (!alreadyLocked)
1249  accessMutex.Leave();
1250 
1251  return chunk;
1252 }
bool IsOfType(C4ParticleDef *def, uint32_t _blitMode, uint32_t attachment) const

References C4Particle::C4ParticleChunk, and C4ParticleChunk::IsOfType().

Referenced by C4ParticleSystem::Create().

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

◆ Lock()

void C4ParticleList::Lock ( )
inline

Definition at line 416 of file C4Particles.h.

416 { accessMutex.Enter(); }

References CStdCSec::Enter().

Referenced by C4ParticleSystem::Create().

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

◆ operator=()

C4ParticleList& C4ParticleList::operator= ( const C4ParticleList )
delete

◆ Unlock()

void C4ParticleList::Unlock ( )
inline

Definition at line 417 of file C4Particles.h.

417 { accessMutex.Leave(); }

References CStdCSec::Leave().

Referenced by C4ParticleSystem::Create().

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

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