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-07-10 09:47:41 +08:00
|
|
|
https://axis-project.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_OBSERVER_H__
|
|
|
|
#define __AX_PU_PARTICLE_3D_OBSERVER_H__
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "math/CCMath.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
struct PUParticle3D;
|
|
|
|
class PUParticleSystem3D;
|
|
|
|
class PUEventHandler;
|
|
|
|
|
|
|
|
enum PUComparisionOperator
|
|
|
|
{
|
|
|
|
CO_LESS_THAN,
|
|
|
|
CO_EQUALS,
|
|
|
|
CO_GREATER_THAN
|
|
|
|
};
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PUObserver : public Ref
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
friend class PUParticleSystem3D;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
|
|
|
// Default values
|
|
|
|
static const bool DEFAULT_ENABLED;
|
|
|
|
static const PUParticle3D::ParticleType DEFAULT_PARTICLE_TYPE;
|
|
|
|
static const float DEFAULT_INTERVAL;
|
|
|
|
static const bool DEFAULT_UNTIL_EVENT;
|
|
|
|
|
|
|
|
typedef std::vector<PUEventHandler*>::iterator ParticleEventHandlerIterator;
|
|
|
|
typedef std::vector<PUEventHandler*>::const_iterator ParticleEventHandlerConstIterator;
|
|
|
|
typedef std::vector<PUEventHandler*> ParticleEventHandlerList;
|
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string_view getObserverType() const { return _observerType; };
|
|
|
|
void setObserverType(std::string_view observerType) { _observerType = observerType; };
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool isEnabled() const;
|
|
|
|
|
|
|
|
/** Returns the 'enabled' value that was set in setEnabled() and not altered during execution.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool _getOriginalEnabled() const;
|
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setEnabled(bool enabled);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Reset internal values for 'enabled'. This means that both the mEnabled and mOriginalEnabled can be set again
|
|
|
|
using setEnabled.
|
2019-11-23 20:27:39 +08:00
|
|
|
@remarks
|
2021-12-25 10:04:45 +08:00
|
|
|
Using _resetEnabled() makes it possible to use setEnabled() without the restriction of having a fixed
|
|
|
|
mOriginalEnabled value.
|
2019-11-23 20:27:39 +08:00
|
|
|
*/
|
|
|
|
void _resetEnabled();
|
|
|
|
|
|
|
|
///** Todo
|
|
|
|
//*/
|
2021-12-25 10:04:45 +08:00
|
|
|
// PUParticleSystem3D* getParentSystem() const {return mParentTechnique;};
|
|
|
|
// void setParentSystem(PUParticleSystem3D* parentTechnique){mParentTechnique = parentTechnique;};
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string_view getName() const { return _name; };
|
|
|
|
void setName(std::string_view name) { _name = name; };
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
const PUParticle3D::ParticleType& getParticleTypeToObserve() const { return _particleTypeToObserve; };
|
2019-11-23 20:27:39 +08:00
|
|
|
void setParticleTypeToObserve(const PUParticle3D::ParticleType particleTypeToObserve);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void notifyStart();
|
|
|
|
virtual void notifyStop(){/* Do nothing */};
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void notifyRescaled(const Vec3& scale);
|
|
|
|
virtual void preUpdateObserver(float deltaTime);
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void updateObserver(PUParticle3D* particle, float deltaTime, bool firstParticle);
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void postUpdateObserver(float deltaTime);
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void firstParticleUpdate(PUParticle3D* particle, float deltaTime);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** This function determines whether a condition (the event) is true or false.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
virtual bool observe(PUParticle3D* particle, float timeElapsed) = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
PUEventHandler* createEventHandler(std::string_view eventHandlerType);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void addEventHandler(PUEventHandler* eventHandler);
|
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void removeEventHandler(PUEventHandler* eventHandler);
|
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
PUEventHandler* getEventHandler(size_t index) const;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2021-12-31 12:12:40 +08:00
|
|
|
PUEventHandler* getEventHandler(std::string_view eventHandlerName) const;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
size_t getNumEventHandlers() const;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void destroyEventHandler(PUEventHandler* eventHandler);
|
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
void destroyEventHandler(size_t index);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Todo
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
void destroyAllEventHandlers();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Return the interval value, which defines at what interval the observer is called.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getObserverInterval() const;
|
|
|
|
|
|
|
|
/** Set the interval value, which defines at what interval the observer is called.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setObserverInterval(float observerInterval);
|
|
|
|
|
|
|
|
/** Return the value of mObserveUntilEvent.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool getObserveUntilEvent() const;
|
|
|
|
|
|
|
|
/** Sets the value of mObserveUntilEvent. This value determines whether observation must be continued
|
|
|
|
after an event occurred and the event handlers are called.
|
|
|
|
*/
|
|
|
|
void setObserveUntilEvent(bool observeUntilEvent);
|
|
|
|
|
|
|
|
/** Returns true if the particle type to observe specifically has been set.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool isParticleTypeToObserveSet() const;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void copyAttributesTo(PUObserver* observer);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
PUObserver();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUObserver();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PUParticleSystem3D* _particleSystem;
|
|
|
|
|
|
|
|
// Type of observer
|
|
|
|
std::string _observerType;
|
|
|
|
|
|
|
|
// Name of the observer (optional)
|
|
|
|
std::string _name;
|
|
|
|
|
|
|
|
/** Determines whether an observer is activated.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool _enabled;
|
|
|
|
bool _originalEnabled;
|
|
|
|
bool _originalEnabledSet;
|
|
|
|
|
|
|
|
/** Determines whether the _observe() function must be executed.
|
|
|
|
@remarks
|
|
|
|
This is independent of mEnabled, which means that an observer can be enabled, but if mObserve has
|
2021-12-25 10:04:45 +08:00
|
|
|
been set to false, it still doesn't observe. It is used to enable/disable execution of the _observe()
|
2019-11-23 20:27:39 +08:00
|
|
|
function in combination with the update interval.
|
|
|
|
*/
|
|
|
|
bool _observe;
|
|
|
|
|
|
|
|
/** Observes until an event takes place. If the event occurs, the event handlers are called and after that
|
|
|
|
the observer doesn't observe anymore.
|
|
|
|
*/
|
|
|
|
bool _observeUntilEvent;
|
|
|
|
|
|
|
|
/** Flag that is set if the event handler(s) are called at least once.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool _eventHandlersExecuted;
|
|
|
|
|
|
|
|
/** Although the scale is on a Particle System level, the observer can also be scaled.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
Vec3 _observerScale;
|
|
|
|
|
|
|
|
// Particle type to be observed. Default is that all particles are observed.
|
|
|
|
PUParticle3D::ParticleType _particleTypeToObserve;
|
|
|
|
|
|
|
|
/** Determines whether mParticleTypeToObserve is set. If true only that particles of the specified type
|
|
|
|
are observed. If false (= default), all particles are observed.
|
|
|
|
*/
|
|
|
|
bool _particleTypeToObserveSet;
|
|
|
|
|
|
|
|
// List with EventHandlers, which will be triggered if the condition that this observer validates occurs.
|
|
|
|
ParticleEventHandlerList _eventHandlers;
|
|
|
|
|
|
|
|
/** Values that determine that the observer is called after every interval.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float _observerInterval;
|
|
|
|
float _observerIntervalRemainder;
|
|
|
|
bool _observerIntervalSet;
|
|
|
|
|
|
|
|
/** Handle the observer implementation.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
virtual void handleObserve(PUParticle3D* particle, float timeElapsed);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Handle the event.
|
|
|
|
@remarks
|
2021-12-25 10:04:45 +08:00
|
|
|
This function iterates over all at the observer registered handlers and executes them.
|
2019-11-23 20:27:39 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void handleEvent(PUParticle3D* particle, float timeElapsed);
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif
|