41#include <guichan/color.hpp>
45#define SIN45 0.707106781f
113 dist.
x * dist.
x + dist.
y * dist.
y + dist.
z * dist.
z);
116 invHypotenuse = 2.0f /
117 fabs(dist.
x) + fabs(dist.
y) + fabs(dist.
z);
120 invHypotenuse = 1.0f / sqrt(
121 dist.
x * dist.
x + dist.
y * dist.
y + dist.
z * dist.
z);
182 for (
auto &newParticle : newParticles)
184 newParticle->moveBy(
mPos);
210 if (particle->doesFollow())
212 particle->moveBy(change);
214 if (particle->update())
233 if (childParticle->doesFollow())
234 childParticle->moveBy(change);
250 int pixelX,
int pixelY,
int rotation)
254 std::string::size_type pos = particleEffectFile.find(
'|');
255 std::string dyePalettes;
256 if (pos != std::string::npos)
257 dyePalettes = particleEffectFile.substr(pos + 1);
262 if (!rootNode || rootNode.
name() !=
"effect")
264 Log::info(
"Error loading particle: %s", particleEffectFile.c_str());
271 for (
auto effectChildNode : rootNode.
children())
274 if (effectChildNode.name() !=
"particle")
294 if (!imageSrc.empty() && !dyePalettes.empty())
297 auto img = resman->
getImage(imageSrc);
307 float offsetX = effectChildNode.getFloatProperty(
"position-x", 0);
308 float offsetY = effectChildNode.getFloatProperty(
"position-y", 0);
309 float offsetZ = effectChildNode.getFloatProperty(
"position-z", 0);
311 mPos.
y + (
float)pixelY + offsetY,
313 newParticle->
moveTo(position);
315 int lifetime = effectChildNode.getProperty(
"lifetime", -1);
317 bool resizeable =
"false" != effectChildNode.getProperty(
"size-adjustable",
"false");
321 for (
auto emitterNode : effectChildNode.children())
323 if (emitterNode.name() ==
"emitter")
327 rotation, dyePalettes);
330 else if (emitterNode.name() ==
"deatheffect")
332 std::string deathEffect { emitterNode.textContent() };
333 char deathEffectConditions = 0x00;
334 if (emitterNode.getBoolProperty(
"on-floor",
true))
338 if (emitterNode.getBoolProperty(
"on-sky",
true))
342 if (emitterNode.getBoolProperty(
"on-other",
false))
346 if (emitterNode.getBoolProperty(
"on-impact",
true))
350 if (emitterNode.getBoolProperty(
"on-timeout",
true))
365 const gcn::Color *color,
366 gcn::Font *font,
bool outline)
369 newParticle->
moveTo(x, y);
370 newParticle->
setVelocity(((rand() % 100) - 50) / 200.0f,
371 ((rand() % 100) - 50) / 200.0f,
372 ((rand() % 100) / 200.0f) + 4.0f);
385 const gcn::Color *color,
386 gcn::Font *font,
bool outline)
389 newParticle->
moveTo(x, y);
407 childEmitter->adjustSize(w, h);
virtual void setMap(Map *map)
Vector mPos
Position in pixels relative to map.
const Vector & getPosition() const
Returns the pixel position of this actor.
static void instantiate(std::string &target, const std::string &palettes)
Fills the blank in a dye placeholder with some palette names.
A central point of control for graphics.
A particle that uses an image for its visualization.
Defines a class for loading and storing images.
Every Particle can have one or more particle emitters that create new particles when they are updated...
A particle spawned by a ParticleEmitter.
Particles mChildParticles
List of particles controlled by this particle.
float mBounce
How much the particle bounces off when hitting the ground.
float getCurrentAlpha() const
Calculates the current alpha transparency taking current fade status into account.
void setAllowSizeAdjust(bool adjust)
void setVelocity(float x, float y, float z)
Sets the current velocity in 3 dimensional space.
float mMomentum
How much speed the particle retains after each game tick.
float mGravity
Downward acceleration in pixels per game-tick.
virtual void setDeathEffect(const std::string &effectFile, char conditions)
AliveStatus mAlive
Is the particle supposed to be drawn and updated?
int mRandomness
Ammount of random vector change.
static void setupEngine()
Gives a particle the properties of an engine root particle and loads the particle-related config sett...
static const float PARTICLE_SKY
Maximum Z position of particles.
static int particleCount
Current number of particles.
static int maxCount
Maximum number of particles.
void moveBy(const Vector &change)
Changes the particle position relative.
void addEmitter(ParticleEmitter *emitter)
Adds an emitter to the particle.
int mFadeIn
Age in game ticks where fading in is finished.
void setFadeIn(int fadeIn)
Sets the remaining particle lifetime where the particle starts to fade out.
float mAcceleration
Acceleration towards the target particle in pixels per game-tick.
bool draw(Graphics *graphics, int offsetX, int offsetY) const override
Draws the particle image.
Particle(Map *map)
Constructor.
Particle * mTarget
The particle that attracts this particle.
bool mAutoDelete
May the particle request its deletion by the parent particle?
Particle * createChild()
Creates a blank particle as a child of the current particle Useful for creating target particles.
Particle * addTextRiseFadeOutEffect(const std::string &text, int x, int y, const gcn::Color *color, gcn::Font *font, bool outline=false)
Creates a standalone text particle.
std::string mDeathEffect
Particle effect file to be spawned when the particle dies.
float mInvDieDistance
Distance in pixels from the target particle that causes the destruction of the particle.
int mLifetimePast
Age of the particle in game ticks.
float mAlpha
Opacity of the graphical representation of the particle.
void setGravity(float gravity)
Sets the downward acceleration.
int mLifetimeLeft
Lifetime left in game ticks.
static int fastPhysics
Mode of squareroot calculation.
virtual bool update()
Updates particle position, returns false when the particle should be deleted.
void moveTo(const Vector &pos)
Sets the position in 3 dimensional space in pixels relative to map.
static int emitterSkip
Duration of pause between two emitter updates in ticks.
void setLifetime(int lifetime)
Sets the time in game ticks until the particle is destroyed.
void clear()
Deletes all child particles and emitters.
bool mAllowSizeAdjust
Can the effect size be adjusted by the object props in the map file?
char mDeathEffectConditions
Bitfield of death conditions which trigger spawning of the death particle.
int mFadeOut
Lifetime in game ticks left where fading out begins.
Vector mVelocity
Speed in pixels per game-tick.
void setBounce(float bouncieness)
Sets the ammount of velocity particles retain after hitting the ground.
Particle * addTextSplashEffect(const std::string &text, int x, int y, const gcn::Color *color, gcn::Font *font, bool outline=false)
Creates a standalone text particle.
Emitters mChildEmitters
List of child emitters.
void setFadeOut(int fadeOut)
Sets the age of the pixel in game ticks where the particle has faded in completely.
Particle * addEffect(const std::string &particleEffectFile, int pixelX, int pixelY, int rotation=0)
Creates a child particle that hosts some emitters described in the particleEffectFile.
void adjustEmitterSize(int w, int h)
Changes the size of the emitters so that the effect fills a rectangle of this size.
static bool enabled
true when non-crucial particle effects are disabled
A class for loading and managing resources.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
ResourceRef< Image > getImage(const std::string &idPath)
Loads the Image resource found at the given identifier path.
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
std::string_view name() const
Node findFirstChildByName(const char *name) const
Children children() const
std::string_view textContent() const
Config config
Global settings (config.xml)
void delete_all(Container &c)
float fastInvSqrt(float x)
void info(const char *log_text,...) LOG_PRINTF_ATTR
Particle * particleEngine
std::list< Particle * > Particles