axmol/extensions/Effekseer/EffekseerForCocos2d-x/EffekseerForCocos2d-x.h

475 lines
12 KiB
C
Raw Normal View History

#pragma once
#include "cocos2d.h"
#include <Effekseer.h>
#include <EffekseerRendererCommon/EffekseerRenderer.Renderer.h>
//#ifdef AX_USE_METAL
//#include <EffekseerRendererMetal.h>
//#else
//#include <EffekseerRendererGL.h>
//#endif
namespace efk
{
class EffectManager;
class InternalManager;
/**
@brief
\~English Effect resource class
\~Japanese
@note
\~English
It is released automatically with autorelease after version1.41
\~Japanese
1.41autoreleaseにより自動的に解放されます
*/
class Effect : public cocos2d::Ref
{
private:
::Effekseer::EffectRef effect = nullptr;
InternalManager* internalManager_ = nullptr;
public:
static Effect* create(const std::string& filename, float maginification = 1.0f);
Effect(InternalManager* internalManager = nullptr);
virtual ~Effect();
/**
@brief
\~English Get the pointer of Effekseer::Effect
\~Japanese Effekseer::Effectのポインタを取得する
@return
\~English  The pointer of Effekseer::Effect
\~Japanese Effekseer::Effectのポインタ
*/
::Effekseer::EffectRef getInternalPtr() { return effect; }
};
/**
@brief
\~English Effect emitter class
\~Japanese
@note
\~English
It is released automatically with autorelease after version1.41
\~Japanese
1.41autoreleaseにより自動的に解放されます
*/
class EffectEmitter : public cocos2d::Node
{
friend class EffectManager;
private:
bool playOnEnter = false;
bool removeOnStop = true;
bool isLooping = false;
//! whether this effect is played once at least
bool isPlayedAtLeastOnce = false;
cocos2d::Vec3 targetPosition_;
float speed_ = 1.0f;
cocos2d::Color4B color_ = cocos2d::Color4B(255, 255, 255, 255);
std::array<float, 4> dynamicInputs_;
EffectManager* manager = nullptr;
Effect* effect_ = nullptr;
::Effekseer::Handle handle = -1;
// cocos2d::CallbackCommand renderCommand;
void beforeRender(EffekseerRenderer::RendererRef, Effekseer::RefPtr<EffekseerRenderer::CommandList>);
void afterRender(EffekseerRenderer::RendererRef, Effekseer::RefPtr<EffekseerRenderer::CommandList>);
public:
/**
@brief
\~English Create the instance of emitter class.
\~Japanese
@return
\~English Instance
\~Japanese
*/
static EffectEmitter* create(EffectManager* manager);
/**
@brief
\~English Create the instance of emitter class.
\~Japanese
@param filename
\~English An effect files's path
\~Japanese
@param magnification
\~English A maginification rate. Effects are loaded by enlarge with specified value
\~Japanese
@return
\~English Instance
\~Japanese
*/
static EffectEmitter* create(EffectManager* manager, const std::string& filename, float maginification = 1.0f);
/**
@brief
\~English Constructor
\~Japanese
*/
EffectEmitter(EffectManager* manager);
/**
@brief
\~English Destructor
\~Japanese
*/
virtual ~EffectEmitter();
/**
@brief
\~English Get an effect's resource
\~Japanese
@return
\~English An effect's resource
\~Japanese
*/
Effect* getEffect();
/**
@brief
\~English Set an effect's resource
\~Japanese
@param effect
\~English An effect's resource
\~Japanese
*/
void setEffect(Effect* effect);
/**
@brief
\~English Get an internal handle of Effekseer
\~Japanese Effekseerの内部のハンドルを取得する
@param effect
\~English An internal handle of Effekseer
\~Japanese Effekseerの内部のハンドル
*/
::Effekseer::Handle getInternalHandle() const;
/**
@brief
\~English Play the effect.
\~Japanese
*/
void play();
/**
@brief
\~English Play the effect.
\~Japanese
@param startFrame
\~English A time to play from middle
\~Japanese
*/
void play(int32_t startTime);
/**
@brief
\~English Get whether to start playing the effect when adding a node.
\~Japanese
@return value
\~English Flag
\~Japanese
*/
bool getPlayOnEnter();
/**
@brief
\~English Set whether to start playing the effect when adding a node.
\~Japanese
@return value
\~English Flag
\~Japanese
*/
void setPlayOnEnter(bool value);
/**
@brief
\~English Get whether to loop play the effect.
\~Japanese
@return value
\~English Flag
\~Japanese
*/
bool getIsLooping();
/**
@brief
\~English Set whether to loop play the effect.
\~Japanese
@return value
\~English Flag
\~Japanese
*/
void setIsLooping(bool value);
/**
@brief
\~English Get whether to discard the node at the end of playback.
\~Japanese
*/
bool getRemoveOnStop();
/**
@brief
\~English Set whether to discard the node at the end of playback.
\~Japanese
*/
void setRemoveOnStop(bool value);
/**
@brief
\~English Set the color which affects whole particles.
\~Japanese
*/
void setColor(cocos2d::Color4B color);
/**
@brief
\~English Get the playback speed
\~Japanese
*/
float getSpeed();
/**
@brief
\~English Set the playback speed
\~Japanese
*/
void setSpeed(float speed);
/**
@brief
\~English Set the position of target to gather
\~Japanese
*/
void setTargetPosition(cocos2d::Vec3 position);
/**
@brief
\~English get a dynamic parameter, which changes effect parameters dynamically while playing
\~Japanese
*/
float getDynamicInput(int32_t index);
/**
@brief
\~English specfiy a dynamic parameter, which changes effect parameters dynamically while playing
\~Japanese
*/
void setDynamicInput(int32_t index, float value);
/**
@brief
\~English Get whether or not playing the effect.
\~Japanese
*/
bool isPlaying();
/**
@brief
\~English Stop the effect.
\~Japanese
*/
void stop();
/**
@brief
\~English Stop only the effect's root.
\~Japanese
*/
void stopRoot();
void onEnter() override;
void onExit() override;
void update(float delta) override;
void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags) override;
};
class EffectManager : public cocos2d::Ref
{
friend class EffectEmitter;
private:
::Effekseer::ManagerRef manager2d = nullptr;
::EffekseerRenderer::RendererRef renderer2d = nullptr;
::EffekseerRenderer::DistortingCallback* distortingCallback = NULL;
::Effekseer::RefPtr<::EffekseerRenderer::SingleFrameMemoryPool> memoryPool_ = nullptr;
::Effekseer::RefPtr<::EffekseerRenderer::CommandList> commandList_ = nullptr;
bool isDistortionEnabled = false;
bool isDistorted = false;
float time_ = 0.0f;
InternalManager* internalManager_ = nullptr;
cocos2d::CustomCommand distortionCommand;
cocos2d::CustomCommand beginCommand;
cocos2d::CustomCommand endCommand;
::Effekseer::Handle play(Effect* effect, float x, float y, float z);
::Effekseer::Handle play(Effect* effect, float x, float y, float z, int startTime);
void setMatrix(::Effekseer::Handle handle, const cocos2d::Mat4& mat);
void setPotation(::Effekseer::Handle handle, float x, float y, float z);
void setRotation(::Effekseer::Handle handle, float x, float y, float z);
void setScale(::Effekseer::Handle handle, float x, float y, float z);
bool Initialize(cocos2d::Size visibleSize);
void CreateRenderer(int32_t spriteSize);
void onDestructor();
public:
/**
@brief
\~English Create the instance of manager class.
\~Japanese
@return
\~English Instance
\~Japanese
*/
static EffectManager* create(cocos2d::Size visibleSize);
/**
@brief
\~English Constructor
\~Japanese
*/
EffectManager();
/**
@brief
\~English Destructor
\~Japanese
*/
virtual ~EffectManager();
/**
@brief
\~English Set whether distortion is enabled.
\~Japanese
*/
void setIsDistortionEnabled(bool value);
/**
@brief
\~English Inherit visit and add a process before drawing the layer.
\~Japanese visitを継承してレイヤーの描画を行う前に実行する
*/
void begin(cocos2d::Renderer* renderer, float globalZOrder);
/**
@brief
\~English Inherit visit and add a process after drawing the layer.
\~Japanese visitを継承してレイヤーの描画を行った後に実行する
*/
void end(cocos2d::Renderer* renderer, float globalZOrder);
/**
@brief
\~English This is called within begin. For special behavioural handling of different graphic device
*/
void newFrame();
/**
@brief
\~English Update the manager every frame.
\~Japanese
@param delta
\~English In seconds.
\~Japanese
*/
void update(float delta = 1.0f / 60.0f);
/**
@brief
\~English Get the pointer of Effekseer::Manager
\~Japanese Effekseer::Managerのポインタを取得する
@return
\~English  The pointer of Effekseer::Manager
\~Japanese Effekseer::Managerのポインタ
*/
::Effekseer::ManagerRef getInternalManager() { return manager2d; }
/**
@brief
\~English Get the pointer of Effekseer::Renderer
\~Japanese Effekseer::Rendererのポインタを取得する
@return
\~English  The pointer of Effekseer::Renderer
\~Japanese Effekseer::Rendererのポインタ
*/
::EffekseerRenderer::RendererRef getInternalRenderer() { return renderer2d; }
void setCameraMatrix(const cocos2d::Mat4& mat);
void setProjectionMatrix(const cocos2d::Mat4& mat);
Effekseer::RefPtr<::EffekseerRenderer::CommandList> getInternalCommandList() { return commandList_; }
};
class NetworkServer : public cocos2d::Ref
{
private:
InternalManager* internalManager_ = nullptr;
public:
NetworkServer();
virtual ~NetworkServer();
/**
@brief
\~English Create the instance of network server class.
\~Japanese
@return
\~English Instance
\~Japanese
*/
static NetworkServer* create();
/**
@brief
\~English make network server enabled to edit effects from remote.
\~Japanese
*/
bool makeNetworkServerEnabled(uint16_t port);
/**
@brief
\~English Update the manager every frame.
\~Japanese
*/
void update();
};
} // namespace efk