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=0)
 
 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 = 0)
inline

Definition at line 405 of file C4Particles.h.

405  : targetObject(obj), lastAccessedChunk(0)
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 1198 of file C4Particles.cpp.

References Particles.

Referenced by ~C4ParticleList().

1199 {
1200  accessMutex.Enter();
1201 
1202  for (std::list<C4ParticleChunk*>::iterator iter = particleChunks.begin(); iter != particleChunks.end(); ++iter)
1203  delete *iter;
1204  particleChunks.clear();
1205 
1206  if (targetObject)
1207  {
1208  if (this == targetObject->FrontParticles) targetObject->FrontParticles = nullptr;
1209  else if (this == targetObject->BackParticles) targetObject->BackParticles = nullptr;
1210  }
1211  else
1212  if(this == ::Particles.globalParticles) ::Particles.globalParticles = nullptr;
1213 
1214  accessMutex.Leave();
1215 }
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 1153 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().

1154 {
1155  if (particleChunks.empty()) return;
1156 
1158  pDraw->ResetBlitMode();
1159 
1160  glPrimitiveRestartIndex(0xffffffff);
1161  glEnable(GL_PRIMITIVE_RESTART);
1162 
1163  // enable shader
1164  C4ShaderCall call(pGL->GetSpriteShader(true, false, false));
1165  // apply zoom and upload shader uniforms
1166  StdProjectionMatrix modelview = StdProjectionMatrix::Identity();
1167  pGL->SetupMultiBlt(call, nullptr, 0, 0, 0, 0, &modelview);
1168  // go to correct output position (note the normal matrix is unaffected
1169  // by this)
1170  Translate(modelview, cgo.X-cgo.TargetX, cgo.Y-cgo.TargetY, 0.0f);
1171  // allocate texture unit for particle texture, and remember allocated
1172  // texture unit. Will be used for each particle chunk to bind
1173  // their texture to this unit.
1174  const GLint texUnit = call.AllocTexUnit(C4SSU_BaseTex);
1175 
1176  accessMutex.Enter();
1177 
1178  for (std::list<C4ParticleChunk*>::iterator iter = particleChunks.begin(); iter != particleChunks.end(); )
1179  {
1180  if ((*iter)->IsEmpty())
1181  {
1182  delete *iter;
1183  iter = particleChunks.erase(iter);
1184  lastAccessedChunk = 0;
1185  }
1186  else
1187  {
1188  (*iter)->Draw(cgo, obj, call, texUnit, modelview);
1189  ++iter;
1190  }
1191  }
1192 
1193  accessMutex.Leave();
1194 
1195  glDisable(GL_PRIMITIVE_RESTART);
1196 }
void Draw(C4TargetFacet cgo, C4Object *obj, C4ShaderCall &call, int texUnit, const StdProjectionMatrix &modelview)
float Y
Definition: C4Facet.h:120
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:370
C4Draw * pDraw
Definition: C4Draw.cpp:45
virtual void Leave()
Definition: StdSync.h:151
float TargetX
Definition: C4Facet.h:167
virtual void Enter()
Definition: StdSync.h:150
void DeactivateBlitModulation()
Definition: C4Draw.h:189
CStdGL * pGL
Definition: C4DrawGL.cpp:914
float TargetY
Definition: C4Facet.h:167
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:683
float X
Definition: C4Facet.h:120

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 1138 of file C4Particles.cpp.

References C4ParticleChunk::Exec().

1139 {
1140  if (particleChunks.empty()) return;
1141 
1142  accessMutex.Enter();
1143 
1144  for (std::list<C4ParticleChunk*>::iterator iter = particleChunks.begin(); iter != particleChunks.end();++iter)
1145  {
1146  C4ParticleChunk *chunk = *iter;
1147  chunk->Exec(targetObject, timeDelta);
1148  }
1149 
1150  accessMutex.Leave();
1151 }
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 1217 of file C4Particles.cpp.

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

Referenced by C4ParticleSystem::Create().

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