OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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::C4ParticleList ( C4Object obj = nullptr)
inline

Definition at line 405 of file C4Particles.h.

405  : targetObject(obj), lastAccessedChunk(nullptr)
406  {
407 
408  }
C4ParticleList::C4ParticleList ( const C4ParticleList )
delete
C4ParticleList::~C4ParticleList ( )
inline

Definition at line 413 of file C4Particles.h.

References Clear().

413 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 1196 of file C4Particles.cpp.

References Particles.

Referenced by ~C4ParticleList().

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:158
virtual void Leave()
Definition: StdSync.h:151
virtual void Enter()
Definition: StdSync.h:150
class C4ParticleList * FrontParticles
Definition: C4Object.h:158

Here is the caller graph for this function:

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

Definition at line 1151 of file C4Particles.cpp.

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

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

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
1164  StdProjectionMatrix modelview = StdProjectionMatrix::Identity();
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 }
void Draw(C4TargetFacet cgo, C4Object *obj, C4ShaderCall &call, int texUnit, const StdProjectionMatrix &modelview)
float Y
Definition: C4Facet.h:118
void ResetBlitMode()
Definition: C4Draw.h:192
void SetupMultiBlt(C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
Definition: C4DrawGL.cpp:361
C4Draw * pDraw
Definition: C4Draw.cpp:42
virtual void Leave()
Definition: StdSync.h:151
float TargetX
Definition: C4Facet.h:165
virtual void Enter()
Definition: StdSync.h:150
void DeactivateBlitModulation()
Definition: C4Draw.h:189
CStdGL * pGL
Definition: C4DrawGL.cpp:905
float TargetY
Definition: C4Facet.h:165
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:674
float X
Definition: C4Facet.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1136 of file C4Particles.cpp.

References C4ParticleChunk::Exec().

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)
virtual void Leave()
Definition: StdSync.h:151
virtual void Enter()
Definition: StdSync.h:150

Here is the call graph for this function:

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

Definition at line 1215 of file C4Particles.cpp.

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

Referenced by C4ParticleSystem::Create().

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
virtual void Leave()
Definition: StdSync.h:151
virtual void Enter()
Definition: StdSync.h:150

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ParticleList::Lock ( )
inline

Definition at line 416 of file C4Particles.h.

References CStdCSec::Enter().

Referenced by C4ParticleSystem::Create().

416 { accessMutex.Enter(); }
virtual void Enter()
Definition: StdSync.h:150

Here is the call graph for this function:

Here is the caller graph for this function:

C4ParticleList& C4ParticleList::operator= ( const C4ParticleList )
delete
void C4ParticleList::Unlock ( )
inline

Definition at line 417 of file C4Particles.h.

References CStdCSec::Leave().

Referenced by C4ParticleSystem::Create().

417 { accessMutex.Leave(); }
virtual void Leave()
Definition: StdSync.h:151

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: