From 77d064a0c4145cbc5c1f0a0a90c72e46045de53d Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Thu, 10 May 2018 17:02:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4va=5Flist=E5=92=8Cstd::initia?= =?UTF-8?q?lizer=5Flist=E4=B8=A4=E7=A7=8D=E6=B7=BB=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E5=AF=B9=E8=B1=A1=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=B8=BAstd::vector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Action/Sequence.cpp | 37 ++------------------- core/Action/Spawn.cpp | 36 ++------------------- core/Common/Animation.cpp | 68 ++------------------------------------- core/Common/Scene.cpp | 6 ++-- core/Node/Menu.cpp | 21 ++---------- core/Node/Node.cpp | 24 ++------------ core/e2daction.h | 44 +++---------------------- core/e2dcommon.h | 46 ++++---------------------- core/e2dmacros.h | 14 -------- core/e2dnode.h | 28 +++------------- 10 files changed, 28 insertions(+), 296 deletions(-) diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index cecdd440..abf95430 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -5,28 +5,11 @@ e2d::Sequence::Sequence() { } -e2d::Sequence::Sequence(int number, Action * action, ...) : - _currIndex(0) -{ - va_list args; - va_start(args, action); - - this->add(action); - for (int i = 1; i < number; i++) - { - this->add(va_arg(args, Action*)); - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 -e2d::Sequence::Sequence(const std::initializer_list& actions) +e2d::Sequence::Sequence(const std::vector& actions) : _currIndex(0) { this->add(actions); } -#endif e2d::Sequence::~Sequence() { @@ -104,29 +87,13 @@ void e2d::Sequence::add(Action * action) } } -void e2d::Sequence::add(int number, Action * action, ...) -{ - va_list args; - va_start(args, action); - - this->add(action); - for (int i = 1; i < number; i++) - { - this->add(va_arg(args, Action*)); - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 -void e2d::Sequence::add(const std::initializer_list& actions) +void e2d::Sequence::add(const std::vector& actions) { for (const auto &action : actions) { this->add(action); } } -#endif e2d::Sequence * e2d::Sequence::clone() const { diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index 0e3b2c2a..d442322c 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -4,26 +4,10 @@ e2d::Spawn::Spawn() { } -e2d::Spawn::Spawn(int number, Action * action, ...) -{ - va_list args; - va_start(args, action); - - this->add(action); - for (int i = 1; i < number; i++) - { - this->add(va_arg(args, Action*)); - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 -e2d::Spawn::Spawn(const std::initializer_list& actions) +e2d::Spawn::Spawn(const std::vector& actions) { this->add(actions); } -#endif e2d::Spawn::~Spawn() { @@ -101,29 +85,13 @@ void e2d::Spawn::add(Action * action) } } -void e2d::Spawn::add(int number, Action * action, ...) -{ - va_list args; - va_start(args, action); - - this->add(action); - for (int i = 1; i < number; i++) - { - this->add(va_arg(args, Action*)); - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 -void e2d::Spawn::add(const std::initializer_list& actions) +void e2d::Spawn::add(const std::vector& actions) { for (const auto &action : actions) { this->add(action); } } -#endif e2d::Spawn * e2d::Spawn::clone() const { diff --git a/core/Common/Animation.cpp b/core/Common/Animation.cpp index 96c3733a..f4a62288 100644 --- a/core/Common/Animation.cpp +++ b/core/Common/Animation.cpp @@ -13,58 +13,15 @@ e2d::Animation::Animation(double interval) e2d::Animation::Animation(double interval, const std::vector& frames) : _interval(interval) { - for (auto frame : frames) - { - this->add(frame); - } + this->add(frames); } -e2d::Animation::Animation(int number, Image * frame, ...) - : _interval(1) -{ - va_list args; - va_start(args, frame); - - this->add(frame); - for (int i = 1; i < number; i++) - { - this->add(va_arg(args, Image*)); - } - - va_end(args); -} - -e2d::Animation::Animation(double interval, int number, Image * frame, ...) - : _interval(interval) -{ - va_list args; - va_start(args, frame); - - this->add(frame); - for (int i = 1; i < number; i++) - { - this->add(va_arg(args, Image*)); - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 - -e2d::Animation::Animation(const std::initializer_list& frames) +e2d::Animation::Animation(const std::vector& frames) : _interval(1) { this->add(frames); } -e2d::Animation::Animation(double interval, const std::initializer_list& frames) - : _interval(interval) -{ - this->add(frames); -} - -#endif - e2d::Animation::~Animation() { } @@ -91,32 +48,13 @@ void e2d::Animation::add(Image * frame) } } -void e2d::Animation::add(int number, Image * frame, ...) -{ - va_list args; - va_start(args, frame); - - this->add(frame); - --number; - - while (number > 0) - { - this->add(va_arg(args, Image*)); - --number; - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 -void e2d::Animation::add(const std::initializer_list& frames) +void e2d::Animation::add(const std::vector& frames) { for (const auto &image : frames) { this->add(image); } } -#endif double e2d::Animation::getInterval() const { diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index de3f3e3c..57ce530e 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -49,15 +49,13 @@ void e2d::Scene::add(Node * child, int order /* = 0 */) _root->addChild(child, order); } -#ifdef HIGHER_THAN_VS2012 -void e2d::Scene::add(const std::initializer_list& nodes, int order) +void e2d::Scene::add(const std::vector& nodes, int order) { - for (const auto &node : nodes) + for (auto node : nodes) { this->add(node, order); } } -#endif bool e2d::Scene::remove(Node * child) { diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index 1487c0c7..ca4aa46c 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -5,31 +5,14 @@ e2d::Menu::Menu() { } -e2d::Menu::Menu(int number, Button * button1, ...) +e2d::Menu::Menu(const std::vector& buttons) : _enable(true) { - va_list args; - va_start(args, button1); - - this->addButton(button1); - for (int i = 1; i < number; i++) - { - this->addButton(va_arg(args, Button*)); - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 -e2d::Menu::Menu(const std::initializer_list& vButtons) - : _enable(true) -{ - for (auto button : vButtons) + for (auto button : buttons) { this->addButton(button); } } -#endif bool e2d::Menu::isEnable() const { diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index c27d5a9e..72f9b04b 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -597,29 +597,13 @@ void e2d::Node::addColliableName(const String& collliderName) _colliders.insert(hash); } -void e2d::Node::addColliableName(int number, String collliderName, ...) -{ - va_list args; - va_start(args, collliderName); - - this->addColliableName(collliderName); - for (int i = 1; i < number; i++) - { - this->addColliableName(va_arg(args, String)); - } - - va_end(args); -} - -#ifdef HIGHER_THAN_VS2012 -void e2d::Node::addColliableName(const std::initializer_list& colliderNames) +void e2d::Node::addColliableName(const std::vector& colliderNames) { for (const auto &name : colliderNames) { this->addColliableName(name); } } -#endif void e2d::Node::removeColliableName(const String& collliderName) { @@ -662,15 +646,13 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */) } } -#ifdef HIGHER_THAN_VS2012 -void e2d::Node::addChild(const std::initializer_list& nodes, int order) +void e2d::Node::addChild(const std::vector& nodes, int order) { - for (const auto &node : nodes) + for (auto node : nodes) { this->addChild(node, order); } } -#endif e2d::Node * e2d::Node::getParent() const { diff --git a/core/e2daction.h b/core/e2daction.h index 5206db66..eddab87f 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -529,18 +529,9 @@ public: // 创建顺序动作 Sequence( - int number, /* 动作数量 */ - Action * action, /* 第一个动作 */ - ... + const std::vector& actions /* 动作列表 */ ); -#ifdef HIGHER_THAN_VS2012 - // 创建顺序动作 - Sequence( - const std::initializer_list& actions /* 动作列表 */ - ); -#endif - virtual ~Sequence(); // 在结尾添加动作 @@ -550,18 +541,9 @@ public: // 在结尾添加多个动作 void add( - int number, /* 动作数量 */ - Action * action, /* 第一个动作 */ - ... + const std::vector& actions /* 动作列表 */ ); -#ifdef HIGHER_THAN_VS2012 - // 在结尾添加多个动作 - void add( - const std::initializer_list& actions /* 动作列表 */ - ); -#endif - // 获取该动作的拷贝对象 virtual Sequence * clone() const override; @@ -600,18 +582,9 @@ public: // 创建同步动作 Spawn( - int number, /* 动作数量 */ - Action * action, /* 第一个动作 */ - ... + const std::vector& actions /* 动作列表 */ ); -#ifdef HIGHER_THAN_VS2012 - // 创建同步动作 - Spawn( - const std::initializer_list& actions /* 动作列表 */ - ); -#endif - virtual ~Spawn(); // 在结尾添加动作 @@ -621,18 +594,9 @@ public: // 在结尾添加多个动作 void add( - int number, /* 动作数量 */ - Action * action, /* 第一个动作 */ - ... + const std::vector& actions /* 动作列表 */ ); -#ifdef HIGHER_THAN_VS2012 - // 在结尾添加多个动作 - void add( - const std::initializer_list& actions /* 动作列表 */ - ); -#endif - // 获取该动作的拷贝对象 virtual Spawn * clone() const override; diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 9643e600..0760ea32 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -559,8 +559,8 @@ public: template Function( - Func&& func, - Object&& obj + Func&& func, /* 对象的成员函数 */ + Object&& obj /* 对象指针 */ ) { _func = std::bind(func, obj); @@ -733,32 +733,9 @@ public: // 创建帧动画 Animation( - int number, /* 帧数量 */ - Image * frame, /* 第一帧 */ - ... + const std::vector& frames /* 关键帧列表 */ ); - // 创建特定帧间隔的帧动画 - Animation( - double interval, /* 帧间隔(秒) */ - int number, /* 帧数量 */ - Image * frame, /* 第一帧 */ - ... - ); - -#ifdef HIGHER_THAN_VS2012 - // 创建帧动画 - Animation( - const std::initializer_list& frames /* 关键帧列表 */ - ); - - // 创建特定帧间隔的帧动画 - Animation( - double interval, /* 帧间隔(秒) */ - const std::initializer_list& frames /* 关键帧列表 */ - ); -#endif - virtual ~Animation(); // 添加关键帧 @@ -768,18 +745,9 @@ public: // 添加多个关键帧 void add( - int number, /* 帧数量 */ - Image * frame, /* 第一帧 */ - ... + const std::vector& frames /* 关键帧列表 */ ); -#ifdef HIGHER_THAN_VS2012 - // 添加多个关键帧 - void add( - const std::initializer_list& frames /* 关键帧列表 */ - ); -#endif - // 获取帧间隔 double getInterval() const; @@ -848,13 +816,11 @@ public: int zOrder = 0 /* 渲染顺序 */ ); -#ifdef HIGHER_THAN_VS2012 // 添加多个节点到场景 virtual void add( - const std::initializer_list& nodes, /* 节点列表 */ - int order = 0 /* 渲染顺序 */ + const std::vector& nodes, /* 节点数组 */ + int order = 0 /* 渲染顺序 */ ); -#endif // 删除子节点 bool remove( diff --git a/core/e2dmacros.h b/core/e2dmacros.h index 7cefc470..854c7831 100644 --- a/core/e2dmacros.h +++ b/core/e2dmacros.h @@ -72,17 +72,3 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase; #endif #endif - -#if _MSC_VER > 1700 - -#ifndef HIGHER_THAN_VS2012 -#define HIGHER_THAN_VS2012 -#endif - -#else - -#ifdef HIGHER_THAN_VS2012 -#undef HIGHER_THAN_VS2012 -#endif - -#endif diff --git a/core/e2dnode.h b/core/e2dnode.h index 9d6cc2d9..d4d71de0 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -340,18 +340,9 @@ public: // 添加多个可碰撞节点的名称 virtual void addColliableName( - int number, /* 名称数量 */ - String collliderName, /* 第一个名称 */ - ... + const std::vector& colliderNames /* 名称数组 */ ); -#ifdef HIGHER_THAN_VS2012 - // 添加多个可碰撞节点的名称 - virtual void addColliableName( - const std::initializer_list& colliderNames /* 名称列表 */ - ); -#endif - // 移除可碰撞节点的名称 virtual void removeColliableName( const String& collliderName @@ -363,13 +354,11 @@ public: int order = 0 /* 渲染顺序 */ ); -#ifdef HIGHER_THAN_VS2012 // 添加多个子节点 virtual void addChild( - const std::initializer_list& nodes, /* 节点列表 */ - int order = 0 /* 渲染顺序 */ + const std::vector& nodes, /* 节点数组 */ + int order = 0 /* 渲染顺序 */ ); -#endif // 执行动作 virtual void runAction( @@ -967,18 +956,9 @@ public: // 创建菜单 Menu( - int number, /* 菜单中按钮的数量 */ - Button * button1, /* 第一个按钮 */ - ... + const std::vector& buttons /* 按钮数组 */ ); -#ifdef HIGHER_THAN_VS2012 - // 创建菜单 - Menu( - const std::initializer_list& vButtons /* 按钮列表 */ - ); -#endif - // 获取菜单是否禁用 bool isEnable() const;