From 0223ad2b9302f148f82d3eb28c590672834f0005 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Sun, 1 Apr 2018 13:16:07 +0800 Subject: [PATCH] vs2012 supported --- core/Action/ActionSequence.cpp | 35 +++++++- core/Action/Animation.cpp | 57 +++++++++++- core/Common/Scene.cpp | 4 +- core/Node/Node.cpp | 8 +- core/eactions.h | 159 ++++++++++++++++++++++++++------- core/ecommon.h | 45 ++++++---- core/emacros.h | 7 ++ core/enodes.h | 8 +- 8 files changed, 266 insertions(+), 57 deletions(-) diff --git a/core/Action/ActionSequence.cpp b/core/Action/ActionSequence.cpp index 265fde84..f5dcebfe 100644 --- a/core/Action/ActionSequence.cpp +++ b/core/Action/ActionSequence.cpp @@ -5,11 +5,27 @@ e2d::ActionSequence::ActionSequence() { } -e2d::ActionSequence::ActionSequence(const std::initializer_list& vActions) +#if HIGHER_THAN_VS2012 +e2d::ActionSequence::ActionSequence(const InitList& vActions) : m_nActionIndex(0) { this->add(vActions); } +#else +e2d::ActionSequence::ActionSequence(int number, Action * action1, ...) : + m_nActionIndex(0) +{ + Action ** ppAction = &action1; + + while (number > 0) + { + WARN_IF((*ppAction) == nullptr, "ActionSequence NULL pointer exception!"); + this->add(*ppAction); + ppAction++; + number--; + } +} +#endif e2d::ActionSequence::~ActionSequence() { @@ -82,13 +98,28 @@ void e2d::ActionSequence::add(Action * action) } } -void e2d::ActionSequence::add(const std::initializer_list& vActions) +#if HIGHER_THAN_VS2012 +void e2d::ActionSequence::add(const InitList& vActions) { for (const auto &action : vActions) { this->add(action); } } +#else +void e2d::ActionSequence::add(int number, Action * action, ...) +{ + Action ** ppAction = &action; + + while (number > 0) + { + WARN_IF((*ppAction) == nullptr, "ActionSequence NULL pointer exception!"); + this->add(*ppAction); + ppAction++; + number--; + } +} +#endif e2d::ActionSequence * e2d::ActionSequence::clone() const { diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index 612cf9dc..fde05399 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -12,20 +12,56 @@ e2d::Animation::Animation(double interval) { } -e2d::Animation::Animation(const std::initializer_list& vImages) +#if HIGHER_THAN_VS2012 + +e2d::Animation::Animation(const InitList& vImages) : m_nFrameIndex(0) , m_fInterval(1) { this->add(vImages); } -e2d::Animation::Animation(double interval, const std::initializer_list& vImages) +e2d::Animation::Animation(double interval, const InitList& vImages) : m_nFrameIndex(0) , m_fInterval(interval) { this->add(vImages); } +#else + +e2d::Animation::Animation(int number, Image * frame, ...) + : m_nFrameIndex(0) + , m_fInterval(1) +{ + Image ** ppImage = &frame; + + while (number > 0) + { + WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!"); + this->add(*ppImage); + ppImage++; + number--; + } +} + +e2d::Animation::Animation(double interval, int number, Image * frame, ...) + : m_nFrameIndex(0) + , m_fInterval(interval) +{ + Image ** ppImage = &frame; + + while (number > 0) + { + WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!"); + this->add(*ppImage); + ppImage++; + number--; + } +} + +#endif + e2d::Animation::~Animation() { for (auto frame : m_vFrames) @@ -86,13 +122,28 @@ void e2d::Animation::add(Image * frame) } } -void e2d::Animation::add(const std::initializer_list& vImages) +#if HIGHER_THAN_VS2012 +void e2d::Animation::add(const InitList& vImages) { for (const auto &image : vImages) { this->add(image); } } +#else +void e2d::Animation::add(int number, Image * frame, ...) +{ + Image ** ppImage = &frame; + + while (number > 0) + { + WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!"); + this->add(*ppImage); + ppImage++; + number--; + } +} +#endif e2d::Animation * e2d::Animation::clone() const { diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 59b544ae..62a5ad84 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -53,13 +53,15 @@ void e2d::Scene::add(Node * child, int order /* = 0 */) m_pRoot->addChild(child, order); } -void e2d::Scene::add(const std::initializer_list& vNodes, int order) +#if HIGHER_THAN_VS2012 +void e2d::Scene::add(const InitList& vNodes, int order) { for (const auto &node : vNodes) { this->add(node, order); } } +#endif bool e2d::Scene::remove(Node * child) { diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 2d5a72ef..1d43e90e 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -602,13 +602,15 @@ void e2d::Node::addCollider(String collliderName) m_vColliders.insert(hash); } -void e2d::Node::addCollider(const std::initializer_list& vCollliderName) +#if HIGHER_THAN_VS2012 +void e2d::Node::addCollider(const InitList& vCollliderName) { for (const auto &name : vCollliderName) { this->addCollider(name); } } +#endif void e2d::Node::removeCollider(String collliderName) { @@ -656,13 +658,15 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */) } } -void e2d::Node::addChild(const std::initializer_list& vNodes, int order) +#if HIGHER_THAN_VS2012 +void e2d::Node::addChild(const InitList& vNodes, int order) { for (const auto &node : vNodes) { this->addChild(node, order); } } +#endif e2d::Node * e2d::Node::getParent() const { diff --git a/core/eactions.h b/core/eactions.h index 7dbbb7c1..8dc1671e 100644 --- a/core/eactions.h +++ b/core/eactions.h @@ -400,10 +400,19 @@ public: // 创建顺序动作 ActionSequence(); +#if HIGHER_THAN_VS2012 // 创建顺序动作 ActionSequence( - const std::initializer_list& vActions /* 动作数组 */ + const InitList& vActions /* 动作数组 */ ); +#else + // 创建顺序动作 + ActionSequence( + int number, /* 动作数量 */ + Action * action, /* 第一个动作 */ + ... + ); +#endif virtual ~ActionSequence(); @@ -412,10 +421,19 @@ public: Action * action ); +#if HIGHER_THAN_VS2012 // 在结尾添加多个动作 void add( - const std::initializer_list& vActions /* 动作数组 */ + const InitList& vActions /* 动作数组 */ ); +#else + // 在结尾添加多个动作 + void add( + int number, /* 动作数量 */ + Action * action, /* 第一个动作 */ + ... + ); +#endif // 获取该动作的拷贝对象 virtual ActionSequence * clone() const override; @@ -515,16 +533,33 @@ public: double interval /* 帧间隔(秒) */ ); +#if HIGHER_THAN_VS2012 // 创建帧动画 Animation( - const std::initializer_list& vImages /* 关键帧数组 */ + const InitList& vImages /* 关键帧数组 */ + ); + + // 创建特定帧间隔的帧动画 + Animation( + double interval, /* 帧间隔(秒) */ + const InitList& vImages /* 关键帧数组 */ + ); +#else + // 创建帧动画 + Animation( + int number, /* 帧数量 */ + Image * frame, /* 第一帧 */ + ... ); // 创建特定帧间隔的帧动画 Animation( double interval, /* 帧间隔(秒) */ - const std::initializer_list& vImages /* 关键帧数组 */ + int number, /* 帧数量 */ + Image * frame, /* 第一帧 */ + ... ); +#endif virtual ~Animation(); @@ -533,10 +568,19 @@ public: Image * frame /* 关键帧 */ ); +#if HIGHER_THAN_VS2012 // 添加多个关键帧 void add( - const std::initializer_list& vImages /* 关键帧数组 */ + const InitList& vImages /* 关键帧数组 */ ); +#else + // 添加多个关键帧 + void add( + int number, /* 帧数量 */ + Image * frame, /* 第一帧 */ + ... + ); +#endif // 设置每一帧的时间间隔 void setInterval( @@ -647,12 +691,12 @@ namespace e2d // 创建淡入动画 ActionFadeIn* FadeIn( - double duration /* 动画持续时长 */ + double duration /* 动画持续时长 */ ); // 创建淡出动画 ActionFadeOut* FadeOut( - double duration /* 动画持续时长 */ + double duration /* 动画持续时长 */ ); // 创建相对旋转动画 @@ -674,14 +718,9 @@ namespace e2d bool bAtSameTime = false /* 同时开始 */ ); - // 创建顺序动作 - ActionSequence* Sequence( - const std::initializer_list& vActions /* 动作数组 */ - ); - // 创建延时动作 ActionDelay* Delay( - double duration /* 延迟时长(秒) */ + double duration /* 延迟时长(秒) */ ); // 创建循环动作 @@ -690,16 +729,38 @@ namespace e2d int times = -1 /* 循环次数 */ ); - // 创建特定帧间隔的帧动画 - Animation* Animate( - double interval, /* 帧间隔(秒) */ - const std::initializer_list& vFrames /* 关键帧数组 */ - ); - // 创建执行函数对象的动作 ActionFunc* Func( - Function func /* 函数对象 */ + Function func /* 函数对象 */ ); + +#if HIGHER_THAN_VS2012 + // 创建顺序动作 + ActionSequence* Sequence( + const InitList& vActions /* 动作数组 */ + ); + + // 创建特定帧间隔的帧动画 + Animation* Animate( + double interval, /* 帧间隔(秒) */ + const InitList& vFrames /* 关键帧数组 */ + ); +#else + // 创建顺序动作 + ActionSequence* Sequence( + int number, /* 动作数量 */ + Action * action1, /* 第一个动作 */ + ... + ); + + // 创建特定帧间隔的帧动画 + Animation* Animate( + double interval, /* 帧间隔(秒) */ + int number, /* 帧数量 */ + Image * frame, /* 第一帧 */ + ... + ); +#endif } inline e2d::ActionMoveBy * e2d::action::MoveBy(double duration, Vector vector) @@ -767,11 +828,6 @@ namespace e2d return new (std::nothrow) ActionTwo(pActionFirst, pActionSecond, bAtSameTime); } - inline e2d::ActionSequence * e2d::action::Sequence(const std::initializer_list& vActions) - { - return new (std::nothrow) ActionSequence(vActions); - } - inline e2d::ActionDelay * e2d::action::Delay(double duration) { return new (std::nothrow) ActionDelay(duration); @@ -782,13 +838,56 @@ namespace e2d return new (std::nothrow) ActionLoop(action, times); } - inline e2d::Animation * e2d::action::Animate(double interval, const std::initializer_list& vFrames) - { - return new (std::nothrow) Animation(interval, vFrames); - } - inline e2d::ActionFunc * e2d::action::Func(Function func) { return new (std::nothrow) ActionFunc(func); } + +#if HIGHER_THAN_VS2012 + inline e2d::ActionSequence * e2d::action::Sequence(const InitList& vActions) + { + return new (std::nothrow) ActionSequence(vActions); + } + + inline e2d::Animation * e2d::action::Animate(double interval, const InitList& vFrames) + { + return new (std::nothrow) Animation(interval, vFrames); + } +#else + inline e2d::ActionSequence * e2d::action::Sequence(int number, Action * action1, ...) + { + auto action = new (std::nothrow) ActionSequence(); + if (action) + { + Action ** ppAction = &action1; + + while (number > 0) + { + WARN_IF((*ppAction) == nullptr, "ActionSequence NULL pointer exception!"); + action->add(*ppAction); + ppAction++; + number--; + } + } + return action; + } + + inline e2d::Animation * e2d::action::Animate(double interval, int number, Image * frame, ...) + { + auto animation = new (std::nothrow) Animation(interval); + if (animation) + { + Image ** ppImage = &frame; + + while (number > 0) + { + WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!"); + animation->add(*ppImage); + ppImage++; + number--; + } + } + return animation; + } +#endif } \ No newline at end of file diff --git a/core/ecommon.h b/core/ecommon.h index a68ffd67..d961f65f 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -10,6 +10,26 @@ namespace e2d { +// 函数对象 +typedef std::function Function; + +// 创建函数对象 +template +inline Function CreateFunc(Object&& obj, Func&& func) +{ + return std::bind(func, obj); +} + + +#if HIGHER_THAN_VS2012 + +// 初始化列表 +template +using InitList = std::initializer_list; + +#endif + + struct Size; // 表示坐标的结构体 @@ -54,17 +74,6 @@ struct Size }; -// 函数对象 -typedef std::function Function; - -// 创建函数对象 -template -inline Function CreateFunc(Object&& obj, Func&& func) -{ - return std::bind(func, obj); -} - - // 字符串 class String { @@ -558,11 +567,13 @@ public: int zOrder = 0 /* 渲染顺序 */ ); - // 添加节点到场景 +#if HIGHER_THAN_VS2012 + // 添加多个节点到场景 virtual void add( - const std::initializer_list& vNodes, /* 节点数组 */ - int order = 0 /* 渲染顺序 */ + const InitList& vNodes, /* 节点数组 */ + int order = 0 /* 渲染顺序 */ ); +#endif // 删除子节点 bool remove( @@ -572,9 +583,9 @@ public: // 获取根节点 Node * getRoot() const; - // 开启几何图形的渲染 - void setShapeVisiable( - bool visiable + // 开启或关闭节点轮廓渲染 + void showOutline( + bool visiable = true ); protected: diff --git a/core/emacros.h b/core/emacros.h index b5a4e330..0a150c7f 100644 --- a/core/emacros.h +++ b/core/emacros.h @@ -70,4 +70,11 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase; #else #define WARN_IF(expression, message, ...) ((void)0) #endif //DEBUG || _DEBUG +#endif + + +#if _MSC_VER <= 1700 +#define HIGHER_THAN_VS2012 1 +#else +#define HIGHER_THAN_VS2012 0 #endif \ No newline at end of file diff --git a/core/enodes.h b/core/enodes.h index ff657a95..4dc1cd23 100644 --- a/core/enodes.h +++ b/core/enodes.h @@ -326,10 +326,12 @@ public: String collliderName ); +#if HIGHER_THAN_VS2012 // 添加多个可碰撞节点的名称 virtual void addCollider( - const std::initializer_list& vCollliderName /* 名称数组 */ + const InitList& vCollliderName /* 名称数组 */ ); +#endif // 移除可碰撞节点的名称 virtual void removeCollider( @@ -342,11 +344,13 @@ public: int order = 0 /* 渲染顺序 */ ); +#if HIGHER_THAN_VS2012 // 添加多个子节点 virtual void addChild( - const std::initializer_list& vNodes, /* 节点数组 */ + const InitList& vNodes, /* 节点数组 */ int order = 0 /* 渲染顺序 */ ); +#endif // 执行动画 virtual void runAction(