移除va_list和std::initializer_list两种添加多个对象的方法,统一为std::vector
This commit is contained in:
		
							parent
							
								
									01882e73d4
								
							
						
					
					
						commit
						77d064a0c4
					
				|  | @ -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<Action*>& actions) | ||||
| e2d::Sequence::Sequence(const std::vector<Action*>& 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<Action*>& actions) | ||||
| void e2d::Sequence::add(const std::vector<Action*>& actions) | ||||
| { | ||||
| 	for (const auto &action : actions) | ||||
| 	{ | ||||
| 		this->add(action); | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| e2d::Sequence * e2d::Sequence::clone() const | ||||
| { | ||||
|  |  | |||
|  | @ -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<Action*>& actions) | ||||
| e2d::Spawn::Spawn(const std::vector<Action*>& 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<Action*>& actions) | ||||
| void e2d::Spawn::add(const std::vector<Action*>& actions) | ||||
| { | ||||
| 	for (const auto &action : actions) | ||||
| 	{ | ||||
| 		this->add(action); | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| e2d::Spawn * e2d::Spawn::clone() const | ||||
| { | ||||
|  |  | |||
|  | @ -13,58 +13,15 @@ e2d::Animation::Animation(double interval) | |||
| e2d::Animation::Animation(double interval, const std::vector<Image*>& 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<Image*>& frames) | ||||
| e2d::Animation::Animation(const std::vector<Image*>& frames) | ||||
| 	: _interval(1) | ||||
| { | ||||
| 	this->add(frames); | ||||
| } | ||||
| 
 | ||||
| e2d::Animation::Animation(double interval, const std::initializer_list<Image*>& 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<Image*>& frames) | ||||
| void e2d::Animation::add(const std::vector<Image*>& frames) | ||||
| { | ||||
| 	for (const auto &image : frames) | ||||
| 	{ | ||||
| 		this->add(image); | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| double e2d::Animation::getInterval() const | ||||
| { | ||||
|  |  | |||
|  | @ -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<Node*>& nodes, int order) | ||||
| void e2d::Scene::add(const std::vector<Node*>& nodes, int order) | ||||
| { | ||||
| 	for (const auto &node : nodes) | ||||
| 	for (auto node : nodes) | ||||
| 	{ | ||||
| 		this->add(node, order); | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| bool e2d::Scene::remove(Node * child) | ||||
| { | ||||
|  |  | |||
|  | @ -5,31 +5,14 @@ e2d::Menu::Menu() | |||
| { | ||||
| } | ||||
| 
 | ||||
| e2d::Menu::Menu(int number, Button * button1, ...) | ||||
| e2d::Menu::Menu(const std::vector<Button*>& 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<Button*>& vButtons) | ||||
| 	: _enable(true) | ||||
| { | ||||
| 	for (auto button : vButtons) | ||||
| 	for (auto button : buttons) | ||||
| 	{ | ||||
| 		this->addButton(button); | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| bool e2d::Menu::isEnable() const | ||||
| { | ||||
|  |  | |||
|  | @ -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<String>& colliderNames) | ||||
| void e2d::Node::addColliableName(const std::vector<String>& 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<Node*>& nodes, int order) | ||||
| void e2d::Node::addChild(const std::vector<Node*>& nodes, int order) | ||||
| { | ||||
| 	for (const auto &node : nodes) | ||||
| 	for (auto node : nodes) | ||||
| 	{ | ||||
| 		this->addChild(node, order); | ||||
| 	} | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| e2d::Node * e2d::Node::getParent() const | ||||
| { | ||||
|  |  | |||
|  | @ -529,18 +529,9 @@ public: | |||
| 
 | ||||
| 	// 创建顺序动作
 | ||||
| 	Sequence( | ||||
| 		int number,			/* 动作数量 */ | ||||
| 		Action * action,	/* 第一个动作 */ | ||||
| 		... | ||||
| 		const std::vector<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 创建顺序动作
 | ||||
| 	Sequence( | ||||
| 		const std::initializer_list<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	virtual ~Sequence(); | ||||
| 
 | ||||
| 	// 在结尾添加动作
 | ||||
|  | @ -550,18 +541,9 @@ public: | |||
| 
 | ||||
| 	// 在结尾添加多个动作
 | ||||
| 	void add( | ||||
| 		int number,			/* 动作数量 */ | ||||
| 		Action * action,	/* 第一个动作 */ | ||||
| 		... | ||||
| 		const std::vector<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 在结尾添加多个动作
 | ||||
| 	void add( | ||||
| 		const std::initializer_list<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	// 获取该动作的拷贝对象
 | ||||
| 	virtual Sequence * clone() const override; | ||||
| 
 | ||||
|  | @ -600,18 +582,9 @@ public: | |||
| 
 | ||||
| 	// 创建同步动作
 | ||||
| 	Spawn( | ||||
| 		int number,			/* 动作数量 */ | ||||
| 		Action * action,	/* 第一个动作 */ | ||||
| 		... | ||||
| 		const std::vector<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 创建同步动作
 | ||||
| 	Spawn( | ||||
| 		const std::initializer_list<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	virtual ~Spawn(); | ||||
| 
 | ||||
| 	// 在结尾添加动作
 | ||||
|  | @ -621,18 +594,9 @@ public: | |||
| 
 | ||||
| 	// 在结尾添加多个动作
 | ||||
| 	void add( | ||||
| 		int number,			/* 动作数量 */ | ||||
| 		Action * action,	/* 第一个动作 */ | ||||
| 		... | ||||
| 		const std::vector<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 在结尾添加多个动作
 | ||||
| 	void add( | ||||
| 		const std::initializer_list<Action*>& actions	/* 动作列表 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	// 获取该动作的拷贝对象
 | ||||
| 	virtual Spawn * clone() const override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -559,8 +559,8 @@ public: | |||
| 
 | ||||
| 	template<typename Func, typename Object> | ||||
| 	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<Image*>& frames	/* 关键帧列表 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建特定帧间隔的帧动画
 | ||||
| 	Animation( | ||||
| 		double interval,	/* 帧间隔(秒) */ | ||||
| 		int number,			/* 帧数量 */ | ||||
| 		Image * frame,		/* 第一帧 */ | ||||
| 		... | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 创建帧动画
 | ||||
| 	Animation( | ||||
| 		const std::initializer_list<Image*>& frames	/* 关键帧列表 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建特定帧间隔的帧动画
 | ||||
| 	Animation( | ||||
| 		double interval,							/* 帧间隔(秒) */ | ||||
| 		const std::initializer_list<Image*>& frames	/* 关键帧列表 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	virtual ~Animation(); | ||||
| 
 | ||||
| 	// 添加关键帧
 | ||||
|  | @ -768,18 +745,9 @@ public: | |||
| 
 | ||||
| 	// 添加多个关键帧
 | ||||
| 	void add( | ||||
| 		int number,			/* 帧数量 */ | ||||
| 		Image * frame,		/* 第一帧 */ | ||||
| 		... | ||||
| 		const std::vector<Image*>& frames	/* 关键帧列表 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 添加多个关键帧
 | ||||
| 	void add( | ||||
| 		const std::initializer_list<Image*>& frames	/* 关键帧列表 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	// 获取帧间隔
 | ||||
| 	double getInterval() const; | ||||
| 
 | ||||
|  | @ -848,13 +816,11 @@ public: | |||
| 		int zOrder = 0	/* 渲染顺序 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 添加多个节点到场景
 | ||||
| 	virtual void add( | ||||
| 		const std::initializer_list<Node*>& nodes,	/* 节点列表 */ | ||||
| 		const std::vector<Node*>& nodes,	/* 节点数组 */ | ||||
| 		int order = 0						/* 渲染顺序 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	// 删除子节点
 | ||||
| 	bool remove( | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -340,18 +340,9 @@ public: | |||
| 
 | ||||
| 	// 添加多个可碰撞节点的名称
 | ||||
| 	virtual void addColliableName( | ||||
| 		int number,				/* 名称数量 */ | ||||
| 		String collliderName,	/* 第一个名称 */ | ||||
| 		... | ||||
| 		const std::vector<String>& colliderNames	/* 名称数组 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 添加多个可碰撞节点的名称
 | ||||
| 	virtual void addColliableName( | ||||
| 		const std::initializer_list<String>& 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<Node*>& nodes,	/* 节点列表 */ | ||||
| 		const std::vector<Node*>& nodes,	/* 节点数组 */ | ||||
| 		int order = 0						/* 渲染顺序 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	// 执行动作
 | ||||
| 	virtual void runAction( | ||||
|  | @ -967,18 +956,9 @@ public: | |||
| 
 | ||||
| 	// 创建菜单
 | ||||
| 	Menu( | ||||
| 		int number,			/* 菜单中按钮的数量 */ | ||||
| 		Button * button1,	/* 第一个按钮 */ | ||||
| 		... | ||||
| 		const std::vector<Button*>& buttons	/* 按钮数组 */ | ||||
| 	); | ||||
| 
 | ||||
| #ifdef HIGHER_THAN_VS2012 | ||||
| 	// 创建菜单
 | ||||
| 	Menu( | ||||
| 		const std::initializer_list<Button*>& vButtons	/* 按钮列表 */ | ||||
| 	); | ||||
| #endif | ||||
| 
 | ||||
| 	// 获取菜单是否禁用
 | ||||
| 	bool isEnable() const; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue