From ba56bf6ecdd71881292be5b734e08de5d65249f7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Dec 2013 14:28:37 +0800 Subject: [PATCH] issue #2790: Updates Tests. --- .../Classes/ActionsTest/ActionsTest.cpp | 6 ++---- .../TestCpp/Classes/ActionsTest/ActionsTest.h | 2 +- .../Classes/PhysicsTest/PhysicsTest.cpp | 11 +++++------ .../Classes/SchedulerTest/SchedulerTest.cpp | 18 +++++++----------- .../Classes/SchedulerTest/SchedulerTest.h | 4 ++-- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 66e8e6edb1..cde2c87f2c 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -2137,14 +2137,13 @@ string ActionCardinalSpline::subtitle() */ PauseResumeActions::PauseResumeActions() -: _pausedTargets(NULL) { } PauseResumeActions::~PauseResumeActions() { - CC_SAFE_RELEASE(_pausedTargets); + } void PauseResumeActions::onEnter() @@ -2176,9 +2175,7 @@ void PauseResumeActions::pause(float dt) log("Pausing"); auto director = Director::getInstance(); - CC_SAFE_RELEASE(_pausedTargets); _pausedTargets = director->getActionManager()->pauseAllRunningActions(); - CC_SAFE_RETAIN(_pausedTargets); } void PauseResumeActions::resume(float dt) @@ -2186,6 +2183,7 @@ void PauseResumeActions::resume(float dt) log("Resuming"); auto director = Director::getInstance(); director->getActionManager()->resumeTargets(_pausedTargets); + _pausedTargets.clear(); } //------------------------------------------------------------------ diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index 9a601b5212..0cb8ce0f20 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -553,7 +553,7 @@ public: void pause(float dt); void resume(float dt); private: - Set *_pausedTargets; + Vector _pausedTargets; }; #endif diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index ed291dc5ff..4865b81352 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -360,14 +360,14 @@ Sprite* PhysicsDemo::makeTriangle(Point point, Size size, PhysicsMaterial materi bool PhysicsDemo::onTouchBegan(Touch* touch, Event* event) { auto location = touch->getLocation(); - Array* arr = _scene->getPhysicsWorld()->getShapes(location); + auto arr = _scene->getPhysicsWorld()->getShapes(location); PhysicsBody* body = nullptr; - for (Object* obj : *arr) + for (auto& obj : arr) { - if ((dynamic_cast(obj)->getBody()->getTag() & DRAG_BODYS_TAG) != 0) + if ((obj->getBody()->getTag() & DRAG_BODYS_TAG) != 0) { - body = dynamic_cast(obj)->getBody(); + body = obj->getBody(); break; } } @@ -1017,9 +1017,8 @@ void PhysicsDemoPump::onEnter() void PhysicsDemoPump::update(float delta) { - for (auto obj : *_scene->getPhysicsWorld()->getAllBodies()) + for (const auto& body : _scene->getPhysicsWorld()->getAllBodies()) { - PhysicsBody* body = dynamic_cast(obj); if (body->getTag() == DRAG_BODYS_TAG && body->getPosition().y < 0.0f) { body->getNode()->setPosition(VisibleRect::leftTop() + Point(75 + CCRANDOM_0_1() * 90, 0)); diff --git a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp index 867f58f98e..e03e7d7943 100644 --- a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp @@ -195,14 +195,13 @@ std::string SchedulerPauseResume::subtitle() //------------------------------------------------------------------ SchedulerPauseResumeAll::SchedulerPauseResumeAll() -: _pausedTargets(NULL) { } SchedulerPauseResumeAll::~SchedulerPauseResumeAll() { - CC_SAFE_RELEASE(_pausedTargets); + } void SchedulerPauseResumeAll::onEnter() @@ -227,7 +226,7 @@ void SchedulerPauseResumeAll::update(float delta) void SchedulerPauseResumeAll::onExit() { - if(_pausedTargets != NULL) + if (!_pausedTargets.empty()) { Director::getInstance()->getScheduler()->resumeTargets(_pausedTargets); } @@ -249,9 +248,8 @@ void SchedulerPauseResumeAll::pause(float dt) log("Pausing"); auto director = Director::getInstance(); _pausedTargets = director->getScheduler()->pauseAllTargets(); - CC_SAFE_RETAIN(_pausedTargets); - unsigned int c = _pausedTargets->count(); + int c = _pausedTargets.size(); if (c > 2) { @@ -265,7 +263,7 @@ void SchedulerPauseResumeAll::resume(float dt) log("Resuming"); auto director = Director::getInstance(); director->getScheduler()->resumeTargets(_pausedTargets); - CC_SAFE_RELEASE_NULL(_pausedTargets); + _pausedTargets.clear(); } std::string SchedulerPauseResumeAll::title() @@ -285,14 +283,13 @@ std::string SchedulerPauseResumeAll::subtitle() //------------------------------------------------------------------ SchedulerPauseResumeAllUser::SchedulerPauseResumeAllUser() -: _pausedTargets(NULL) { } SchedulerPauseResumeAllUser::~SchedulerPauseResumeAllUser() { - CC_SAFE_RELEASE(_pausedTargets); + } void SchedulerPauseResumeAllUser::onEnter() @@ -314,7 +311,7 @@ void SchedulerPauseResumeAllUser::onEnter() void SchedulerPauseResumeAllUser::onExit() { - if(_pausedTargets != NULL) + if (!_pausedTargets.empty()) { Director::getInstance()->getScheduler()->resumeTargets(_pausedTargets); } @@ -336,7 +333,6 @@ void SchedulerPauseResumeAllUser::pause(float dt) log("Pausing"); auto director = Director::getInstance(); _pausedTargets = director->getScheduler()->pauseAllTargetsWithMinPriority(Scheduler::PRIORITY_NON_SYSTEM_MIN); - CC_SAFE_RETAIN(_pausedTargets); } void SchedulerPauseResumeAllUser::resume(float dt) @@ -344,7 +340,7 @@ void SchedulerPauseResumeAllUser::resume(float dt) log("Resuming"); auto director = Director::getInstance(); director->getScheduler()->resumeTargets(_pausedTargets); - CC_SAFE_RELEASE_NULL(_pausedTargets); + _pausedTargets.clear(); } std::string SchedulerPauseResumeAllUser::title() diff --git a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h index 226136cb9c..b77e798a83 100644 --- a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h +++ b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h @@ -79,7 +79,7 @@ public: void pause(float dt); void resume(float dt); private: - Set* _pausedTargets; + Vector _pausedTargets; }; class SchedulerPauseResumeAllUser : public SchedulerTestLayer @@ -99,7 +99,7 @@ public: void pause(float dt); void resume(float dt); private: - Set* _pausedTargets; + Vector _pausedTargets; }; class SchedulerUnscheduleAll : public SchedulerTestLayer