2021-12-31 12:12:40 +08:00
|
|
|
/****************************************************************************
|
2019-11-23 20:27:39 +08:00
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
2022-02-24 18:51:36 +08:00
|
|
|
https://adxeproject.github.io/
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCTIMELINE_ACTION_CACHE_H__
|
|
|
|
#define __CCTIMELINE_ACTION_CACHE_H__
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "base/CCMap.h"
|
|
|
|
#include "base/CCData.h"
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "DictionaryHelper.h"
|
|
|
|
#include "ActionTimeline/CCTimelineMacro.h"
|
|
|
|
#include "CocosStudioExport.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
namespace flatbuffers
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
class FlatBufferBuilder;
|
|
|
|
|
|
|
|
struct NodeAction;
|
|
|
|
struct TimeLine;
|
|
|
|
struct PointFrame;
|
|
|
|
struct ScaleFrame;
|
|
|
|
struct ColorFrame;
|
|
|
|
struct TextureFrame;
|
|
|
|
struct EventFrame;
|
|
|
|
struct IntFrame;
|
|
|
|
struct BoolFrame;
|
|
|
|
struct InnerActionFrame;
|
|
|
|
struct EasingData;
|
|
|
|
struct BlendFrame;
|
|
|
|
} // namespace flatbuffers
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
NS_TIMELINE_BEGIN
|
|
|
|
|
|
|
|
class ActionTimeline;
|
|
|
|
class Timeline;
|
|
|
|
class Frame;
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
class CCS_DLL ActionTimelineCache
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
public:
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Gets the singleton */
|
|
|
|
static ActionTimelineCache* getInstance();
|
|
|
|
|
|
|
|
/** Destroys the singleton */
|
|
|
|
static void destroyInstance();
|
|
|
|
|
|
|
|
void purge();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
/** Remove action with filename, and also remove other resource relate with this file */
|
2021-12-31 12:12:40 +08:00
|
|
|
void removeAction(std::string_view fileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
static ActionTimeline* createAction(std::string_view fileName);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Clone a action with the specified name from the container. */
|
2021-12-31 12:12:40 +08:00
|
|
|
ActionTimeline* createActionFromJson(std::string_view fileName);
|
|
|
|
ActionTimeline* createActionFromContent(std::string_view fileName, std::string_view content);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
ActionTimeline* loadAnimationActionWithFile(std::string_view fileName);
|
|
|
|
ActionTimeline* loadAnimationActionWithContent(std::string_view fileName, std::string_view content);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
ActionTimeline* createActionWithFlatBuffersFile(std::string_view fileName);
|
|
|
|
ActionTimeline* createActionWithDataBuffer(cocos2d::Data data, std::string_view fileName);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
ActionTimeline* loadAnimationActionWithFlatBuffersFile(std::string_view fileName);
|
|
|
|
ActionTimeline* loadAnimationWithDataBuffer(const cocos2d::Data& data, std::string_view fileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
ActionTimeline* createActionWithFlatBuffersForSimulator(std::string_view fileName);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
protected:
|
2019-11-23 20:27:39 +08:00
|
|
|
Timeline* loadTimeline(const rapidjson::Value& json);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* loadVisibleFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadPositionFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadScaleFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadSkewFrame(const rapidjson::Value& json);
|
2019-11-23 20:27:39 +08:00
|
|
|
Frame* loadRotationSkewFrame(const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* loadRotationFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadAnchorPointFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadInnerActionFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadColorFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadTextureFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadEventFrame(const rapidjson::Value& json);
|
|
|
|
Frame* loadZOrderFrame(const rapidjson::Value& json);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Timeline* loadTimelineWithFlatBuffers(const flatbuffers::TimeLine* flatbuffers);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* loadVisibleFrameWithFlatBuffers(const flatbuffers::BoolFrame* flatbuffers);
|
|
|
|
Frame* loadPositionFrameWithFlatBuffers(const flatbuffers::PointFrame* flatbuffers);
|
|
|
|
Frame* loadScaleFrameWithFlatBuffers(const flatbuffers::ScaleFrame* flatbuffers);
|
|
|
|
Frame* loadRotationSkewFrameWithFlatBuffers(const flatbuffers::ScaleFrame* flatbuffers);
|
|
|
|
Frame* loadColorFrameWithFlatBuffers(const flatbuffers::ColorFrame* flatbuffers);
|
|
|
|
Frame* loadTextureFrameWithFlatBuffers(const flatbuffers::TextureFrame* flatbuffers);
|
|
|
|
Frame* loadEventFrameWithFlatBuffers(const flatbuffers::EventFrame* flatbuffers);
|
|
|
|
Frame* loadAlphaFrameWithFlatBuffers(const flatbuffers::IntFrame* flatbuffers);
|
|
|
|
Frame* loadAnchorPointFrameWithFlatBuffers(const flatbuffers::ScaleFrame* flatbuffers);
|
|
|
|
Frame* loadZOrderFrameWithFlatBuffers(const flatbuffers::IntFrame* flatbuffers);
|
|
|
|
Frame* loadInnerActionFrameWithFlatBuffers(const flatbuffers::InnerActionFrame* flatbuffers);
|
|
|
|
Frame* loadBlendFrameWithFlatBuffers(const flatbuffers::BlendFrame* flatbuffers);
|
2019-11-23 20:27:39 +08:00
|
|
|
void loadEasingDataWithFlatBuffers(Frame* frame, const flatbuffers::EasingData* flatbuffers);
|
|
|
|
|
|
|
|
inline ActionTimeline* createActionWithDataBuffer(const cocos2d::Data& data);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
protected:
|
2019-11-23 20:27:39 +08:00
|
|
|
typedef std::function<Frame*(const rapidjson::Value& json)> FrameCreateFunc;
|
|
|
|
typedef std::pair<std::string, FrameCreateFunc> Pair;
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
hlookup::string_map<FrameCreateFunc> _funcs;
|
|
|
|
cocos2d::StringMap<ActionTimeline*> _animationActions;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_TIMELINE_END
|
|
|
|
|
|
|
|
#endif /*__CCTIMELINE_ACTION_CACHE_H__*/
|