axmol/extensions/Particle3D/PU/CCPUDoPlacementParticleEven...

192 lines
8.2 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (C) 2013 Henry van Merode. All rights reserved.
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-25 10:04:45 +08:00
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2022-07-16 10:43:05 +08:00
#ifndef __AX_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
#define __AX_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
2019-11-23 20:27:39 +08:00
#include "base/CCRef.h"
#include "math/CCMath.h"
#include "extensions/Particle3D/PU/CCPUListener.h"
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
#include <vector>
#include <string>
NS_AX_BEGIN
2019-11-23 20:27:39 +08:00
struct PUParticle3D;
class PUObserver;
class PUEmitter;
class PUParticleSystem3D;
2022-07-16 10:43:05 +08:00
class AX_EX_DLL PUDoPlacementParticleEventHandler : public PUEventHandler, public PUListener
2019-11-23 20:27:39 +08:00
{
public:
// Constants
static const unsigned int DEFAULT_NUMBER_OF_PARTICLES;
static PUDoPlacementParticleEventHandler* create();
/** Getters/Setters
2021-12-25 10:04:45 +08:00
*/
bool isInheritPosition() const { return _inheritPosition; };
bool isInheritDirection() const { return _inheritDirection; };
bool isInheritOrientation() const { return _inheritOrientation; };
bool isInheritTimeToLive() const { return _inheritTimeToLive; };
bool isInheritMass() const { return _inheritMass; };
bool isInheritTextureCoordinate() const { return _inheritTextureCoordinate; };
bool isInheritColour() const { return _inheritColour; };
bool isInheritParticleWidth() const { return _inheritParticleWidth; };
bool isInheritParticleHeight() const { return _inheritParticleHeight; };
bool isInheritParticleDepth() const { return _inheritParticleDepth; };
void setInheritPosition(bool inheritPosition) { _inheritPosition = inheritPosition; };
void setInheritDirection(bool inheritDirection) { _inheritDirection = inheritDirection; };
void setInheritOrientation(bool inheritOrientation) { _inheritOrientation = inheritOrientation; };
void setInheritTimeToLive(bool inheritTimeToLive) { _inheritTimeToLive = inheritTimeToLive; };
void setInheritMass(bool inheritMass) { _inheritMass = inheritMass; };
void setInheritTextureCoordinate(bool inheritTextureCoordinate)
{
_inheritTextureCoordinate = inheritTextureCoordinate;
};
void setInheritColour(bool inheritColour) { _inheritColour = inheritColour; };
void setInheritParticleWidth(bool inheritParticleWidth) { _inheritParticleWidth = inheritParticleWidth; };
void setInheritParticleHeight(bool inheritParticleHeight) { _inheritParticleHeight = inheritParticleHeight; };
void setInheritParticleDepth(bool inheritParticleDepth) { _inheritParticleDepth = inheritParticleDepth; };
2019-11-23 20:27:39 +08:00
/** Get the name of the emitter that is used to emit its particles.
2021-12-25 10:04:45 +08:00
*/
std::string_view getForceEmitterName() const { return _forceEmitterName; };
2019-11-23 20:27:39 +08:00
/** Set the name of the emitter that is used to emit its particles.
2021-12-25 10:04:45 +08:00
*/
void setForceEmitterName(std::string_view forceEmitterName);
2019-11-23 20:27:39 +08:00
/** Returns a pointer to the emitter that is used as a force emitter.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
PUEmitter* getForceEmitter() const;
/** Remove this as a listener from the technique.
@remarks
2021-12-25 10:04:45 +08:00
If a new force-emitter name has been set, the removeAsListener must be called, to remove the
DoPlacementParticleEventHandler from the old technique (to which the force-emitter belongs. Only then the new
force-emitter is used. The reason why it is not called automatically in the setForceEmitterName() function is to
offer some flexibility on the moment the removeAsListener() is called.
2019-11-23 20:27:39 +08:00
*/
void removeAsListener();
/** Get the number of particles to emit.
2021-12-25 10:04:45 +08:00
*/
unsigned int getNumberOfParticles() const { return _numberOfParticles; };
2019-11-23 20:27:39 +08:00
/** Set the number of particles to emit.
2021-12-25 10:04:45 +08:00
*/
void setNumberOfParticles(unsigned int numberOfParticles) { _numberOfParticles = numberOfParticles; };
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/** Boolean that determines whether always the position of the particle that is handled must be used for emission of
2019-11-23 20:27:39 +08:00
the new particle.
*/
2021-12-25 10:04:45 +08:00
bool alwaysUsePosition() const { return _alwaysUsePosition; };
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/** Set the boolean to indicate whether the position of the particle that is handled must be used for emission of
the new particle or whether the contact point of the physics actor must be used. This only applies if a physics
engine is used, otherwise the default is used.
2019-11-23 20:27:39 +08:00
*/
2021-12-25 10:04:45 +08:00
void setAlwaysUsePosition(bool alwaysUsePosition) { _alwaysUsePosition = alwaysUsePosition; };
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/** If the _handle() function of this class is invoked (by an Observer), it searches the
ParticleEmitter defined by the mForceEmitterName. This ParticleEmitter is either part of
2019-11-23 20:27:39 +08:00
the ParticleTechnique in which the DoPlacementParticleEventHandler is defined, and if the ParticleEmitter
is not found, other ParticleTechniques are searched. The ParticleEmitter is 'forced' to emit the
requested number of particles.
*/
2021-12-25 10:04:45 +08:00
virtual void handle(PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
2019-11-23 20:27:39 +08:00
/** Initialise the emitted particle. This means that its position is set.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
/** No implementation.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
2021-12-25 10:04:45 +08:00
virtual void copyAttributesTo(PUEventHandler* eventHandler) override;
2019-11-23 20:27:39 +08:00
PUDoPlacementParticleEventHandler();
2019-11-23 20:27:39 +08:00
virtual ~PUDoPlacementParticleEventHandler();
protected:
// Identifies the name of emitter
std::string _forceEmitterName;
// The number of particles to emit
unsigned int _numberOfParticles;
/** Store the technique value to keep up to speed.
@remarks
If the ParticleTechnique has been destroyed, the DoPlacementParticleEventHandler isn't automatically
notified. Using the pointer causes an exception.
*/
PUParticleSystem3D* _system;
/** Store the emitter value to keep up to speed.
@remarks
If the ParticleEmitter has been destroyed, the DoPlacementParticleEventHandler isn't automatically
notified. Using the pointer causes an exception.
*/
PUEmitter* _emitter;
/** Used to determine whether the emitter used by the DoPlacementParticleEventHandler, is already found.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
bool _found;
2021-12-25 10:04:45 +08:00
/** By default the place where to put a new particle is on the position of the particle in the _handle function. If
mAlwaysUsePosition is set to false, it tries the contact point of the physics actor that is associated with the
2019-11-23 20:27:39 +08:00
particle.
*/
bool _alwaysUsePosition;
/** The base particle from which the attributes are inherited
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
PUParticle3D* _baseParticle;
/** These flags are used to determine which attributes must be inherited from the base particle.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
bool _inheritPosition;
bool _inheritDirection;
bool _inheritOrientation;
bool _inheritTimeToLive;
bool _inheritMass;
bool _inheritTextureCoordinate;
bool _inheritColour;
bool _inheritParticleWidth;
bool _inheritParticleHeight;
bool _inheritParticleDepth;
};
NS_AX_END
2019-11-23 20:27:39 +08:00
#endif