remove unused files

This commit is contained in:
2youyou2 2014-06-12 16:21:41 +08:00
parent 4d1bf0c1a2
commit f536020d26
9 changed files with 1135 additions and 427 deletions

View File

@ -63,6 +63,5 @@ THE SOFTWARE.
#include "cocostudio/TimelineAction/CCTimeLine.h"
#include "cocostudio/TimelineAction/CCTimelineAction.h"
#include "cocostudio/TimelineAction/CCTimelineActionCache.h"
#include "cocostudio/TimelineAction/CCAsyncReader.h"
#endif

View File

@ -1,165 +0,0 @@
#include "CCAsyncReader.h"
#include "cocos2d.h"
using namespace cocos2d;
namespace cocostudio {
static AsyncReader* _sharedAsyncReader = nullptr;
AsyncReader* AsyncReader::getInstance()
{
if (! _sharedAsyncReader)
{
_sharedAsyncReader = new AsyncReader();
}
return _sharedAsyncReader;
}
void AsyncReader::destroyInstance()
{
CC_SAFE_DELETE(_sharedAsyncReader);
}
AsyncReader::AsyncReader()
: _loadingThread(nullptr)
, _asyncStructQueue(nullptr)
, _refInfoQueue(nullptr)
, _needQuit(false)
, _asyncRefCount(0)
{
}
void AsyncReader::readFileAsync(const std::string &path, std::function<Ref*(std::string)> loadingCallBack, std::function<void(cocos2d::Ref*)> loadedCallback)
{
Ref *ref = nullptr;
// lazy init
if (_asyncStructQueue == nullptr)
{
_asyncStructQueue = new std::queue<AsyncStruct*>();
_refInfoQueue = new std::deque<RefInfo*>();
// create a new thread to load images
_loadingThread = new std::thread(&AsyncReader::loadFile, this);
_needQuit = false;
}
if (0 == _asyncRefCount)
{
Director::getInstance()->getScheduler()->schedule(schedule_selector(AsyncReader::loadFileAsyncCallBack), this, 0, false);
}
++_asyncRefCount;
// generate async struct
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path);
AsyncStruct *data = new AsyncStruct(fullpath, loadingCallBack, loadedCallback);
// add async struct into queue
_asyncStructQueueMutex.lock();
_asyncStructQueue->push(data);
_asyncStructQueueMutex.unlock();
_sleepCondition.notify_one();
}
void AsyncReader::loadFile()
{
AsyncStruct *asyncStruct = nullptr;
while (true)
{
std::queue<AsyncStruct*> *pQueue = _asyncStructQueue;
_asyncStructQueueMutex.lock();
if (pQueue->empty())
{
_asyncStructQueueMutex.unlock();
if (_needQuit) {
break;
}
else {
std::unique_lock<std::mutex> lk(_sleepMutex);
_sleepCondition.wait(lk);
continue;
}
}
else
{
asyncStruct = pQueue->front();
pQueue->pop();
_asyncStructQueueMutex.unlock();
}
Ref *ref = nullptr;
const std::string& filename = asyncStruct->filename;
// generate ref
ref = asyncStruct->loadingCallBack(filename);
if (!ref)
continue;
ref->retain();
// generate image info
RefInfo *refInfo = new RefInfo();
refInfo->asyncStruct = asyncStruct;
refInfo->ref = ref;
// put the image info into the queue
_refInfoMutex.lock();
_refInfoQueue->push_back(refInfo);
_refInfoMutex.unlock();
}
if(_asyncStructQueue != nullptr)
{
delete _asyncStructQueue;
_asyncStructQueue = nullptr;
delete _refInfoQueue;
_refInfoQueue = nullptr;
}
}
void AsyncReader::loadFileAsyncCallBack(float dt)
{
// the image is generated in loading thread
std::deque<RefInfo*> *refsQueue = _refInfoQueue;
_refInfoMutex.lock();
if (refsQueue->empty())
{
_refInfoMutex.unlock();
}
else
{
RefInfo *refInfo = refsQueue->front();
refsQueue->pop_front();
_refInfoMutex.unlock();
AsyncStruct *asyncStruct = refInfo->asyncStruct;
Ref *ref = refInfo->ref;
if (asyncStruct->loadedCallback)
{
asyncStruct->loadedCallback(ref);
}
ref->release();
delete asyncStruct;
delete refInfo;
--_asyncRefCount;
if (0 == _asyncRefCount)
{
Director::getInstance()->getScheduler()->unschedule(schedule_selector(AsyncReader::loadFileAsyncCallBack), this);
}
}
}
}

View File

@ -1,83 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
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 __CCASYNCREADER_H__
#define __CCASYNCREADER_H__
#include "cocos2d.h"
namespace cocostudio {
class AsyncReader : cocos2d::Ref
{
public:
static AsyncReader* getInstance();
static void destroyInstance();
AsyncReader();
virtual void readFileAsync(const std::string &filepath, std::function<Ref*(std::string)> loadingCallBack, std::function<void(cocos2d::Ref*)> loadedCallback);
private:
void loadFile();
void loadFileAsyncCallBack(float dt);
public:
struct AsyncStruct
{
public:
AsyncStruct(const std::string& fn, std::function<Ref*(std::string)> lc, std::function<void(cocos2d::Ref*)> ec)
: filename(fn), loadingCallBack(lc), loadedCallback(ec) {}
std::string filename;
std::function<Ref*(std::string)> loadingCallBack;
std::function<void(cocos2d::Ref*)> loadedCallback;
};
protected:
typedef struct _RefInfo
{
AsyncStruct *asyncStruct;
Ref *ref;
} RefInfo;
std::thread* _loadingThread;
std::queue<AsyncStruct*>* _asyncStructQueue;
std::deque<RefInfo*>* _refInfoQueue;
std::mutex _asyncStructQueueMutex;
std::mutex _refInfoMutex;
std::mutex _sleepMutex;
std::condition_variable _sleepCondition;
bool _needQuit;
int _asyncRefCount;
};
}
#endif /*__CCASYNCREADER_H__*/

View File

@ -182,8 +182,8 @@ cocos2d::Node* NodeCache::createNode(const std::string& filename)
cocos2d::Node* NodeCache::loadNodeWithFile(const std::string& fileName)
{
// Read content from file
std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fullPath);
//std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fileName);
cocos2d::Node* node = loadNodeWithContent(contentStr);
@ -214,7 +214,10 @@ cocos2d::Node* NodeCache::loadNodeWithContent(const std::string& content)
// decode node tree
const rapidjson::Value& subJson = DICTOOL->getSubDictionary_json(doc, NODE);
return loadNode(subJson);
cocos2d::Node* root = loadNode(subJson);
root->release();
return root;
}
cocos2d::Node* NodeCache::loadNode(const rapidjson::Value& json)
@ -239,6 +242,7 @@ cocos2d::Node* NodeCache::loadNode(const rapidjson::Value& json)
if (child)
{
node->addChild(child);
child->release();
}
}
}
@ -307,6 +311,7 @@ void NodeCache::initNode(cocos2d::Node* node, const rapidjson::Value& json)
Node* NodeCache::loadSimpleNode(const rapidjson::Value& json)
{
Node* node = Node::create();
node->retain();
initNode(node, json);
return node;
@ -326,6 +331,8 @@ cocos2d::Node* NodeCache::loadSubGraph(const rapidjson::Value& json)
node = Node::create();
}
node->retain();
initNode(node, json);
return node;
@ -362,6 +369,8 @@ Node* NodeCache::loadSprite(const rapidjson::Value& json)
sprite = Sprite::create();
}
sprite->retain();
initNode(sprite, json);
return sprite;
@ -374,6 +383,7 @@ Node* NodeCache::loadParticle(const rapidjson::Value& json)
ParticleSystemQuad* particle = ParticleSystemQuad::create(filePath);
particle->setTotalParticles(num);
particle->retain();
initNode(particle, json);
@ -388,6 +398,8 @@ cocos2d::Node* NodeCache::loadWidget(const rapidjson::Value& json)
readerName.append("Reader");
Widget* widget = dynamic_cast<Widget*>(ObjectFactory::getInstance()->createObject(classname));
widget->retain();
WidgetReaderProtocol* reader = dynamic_cast<WidgetReaderProtocol*>(ObjectFactory::getInstance()->createObject(readerName));
_guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json);

View File

@ -42,7 +42,6 @@
<ClCompile Include="..\CCTween.cpp" />
<ClCompile Include="..\CCUtilMath.cpp" />
<ClCompile Include="..\DictionaryHelper.cpp" />
<ClCompile Include="..\TimelineAction\CCAsyncReader.cpp" />
<ClCompile Include="..\TimelineAction\CCFrame.cpp" />
<ClCompile Include="..\TimelineAction\CCNodeCache.cpp" />
<ClCompile Include="..\TimelineAction\CCTimeLine.cpp" />
@ -109,7 +108,6 @@
<ClInclude Include="..\CCTween.h" />
<ClInclude Include="..\CCUtilMath.h" />
<ClInclude Include="..\DictionaryHelper.h" />
<ClInclude Include="..\TimelineAction\CCAsyncReader.h" />
<ClInclude Include="..\TimelineAction\CCFrame.h" />
<ClInclude Include="..\TimelineAction\CCNodeCache.h" />
<ClInclude Include="..\TimelineAction\CCTimeLine.h" />

View File

@ -246,9 +246,6 @@
<ClCompile Include="..\TimelineAction\CCTimelineActionCache.cpp">
<Filter>TimelineAction</Filter>
</ClCompile>
<ClCompile Include="..\TimelineAction\CCAsyncReader.cpp">
<Filter>TimelineAction</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\CCComAttribute.h">
@ -446,8 +443,5 @@
<ClInclude Include="..\TimelineAction\CCTimelineActionCache.h">
<Filter>TimelineAction</Filter>
</ClInclude>
<ClInclude Include="..\TimelineAction\CCAsyncReader.h">
<Filter>TimelineAction</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -163,73 +163,38 @@ void TimelineActionTestLayer::restartCallback(Ref *pSender)
s->release();
}
Node* node = nullptr;
TimelineAction* action = nullptr;
void TimelineActionTestLayer::nextCallback(Ref *pSender)
{
// Scene *s = new TimelineActionTestScene();
// s->addChild( NextAnimationTest() );
// Director::getInstance()->replaceScene(s);
// s->release();
int frameIndex = action->getCurrentFrame();
int duration = action->getDuration();
++frameIndex;
frameIndex = frameIndex == duration ? 0 : frameIndex;
action->gotoFrameAndPause(frameIndex);
Scene *s = new TimelineActionTestScene();
s->addChild( NextAnimationTest() );
Director::getInstance()->replaceScene(s);
s->release();
}
void TimelineActionTestLayer::backCallback(Ref *pSender)
{
// Scene *s = new TimelineActionTestScene();
// s->addChild( BackAnimationTest() );
// Director::getInstance()->replaceScene(s);
// s->release();
int frameIndex = action->getCurrentFrame();
int duration = action->getDuration();
--frameIndex;
frameIndex = frameIndex == -1 ? duration-1 : frameIndex;
action->gotoFrameAndPause(frameIndex);
Scene *s = new TimelineActionTestScene();
s->addChild( BackAnimationTest() );
Director::getInstance()->replaceScene(s);
s->release();
}
void TestTimelineAction::onEnter()
{
TimelineActionTestLayer::onEnter();
Node* node = NodeCache::getInstance()->createNode("TimelineAction/boy_1.ExportJson");
TimelineAction* action = TimelineActionCache::getInstance()->createAction("TimelineAction/boy_1.ExportJson");
for(int i=0; i<100; i++)
{
AsyncReader::getInstance()->readFileAsync("TimelineAction/boy_1.ExportJson", CC_CALLBACK_1(TestTimelineAction::loadingRef, this), CC_CALLBACK_1(TestTimelineAction::loadedRef, this));
}
node->runAction(action);
action->gotoFrameAndPlay(0, 60, true);
node->setScale(0.4f);
node->setPosition(0,0);
addChild(node);
}
std::string TestTimelineAction::title() const
{
return "Test AnimationElement";
}
cocos2d::Ref* TestTimelineAction::loadingRef(std::string filename)
{
return NodeCache::getInstance()->createNode(filename);
}
void TestTimelineAction::loadedRef(cocos2d::Ref* ref)
{
if(cocos2d::Node* node = dynamic_cast<cocos2d::Node*>(ref))
{
TimelineAction* action = TimelineActionCache::getInstance()->createAction("TimelineAction/boy_1.ExportJson");
node->runAction(action);
action->gotoFrameAndPlay(0, 60, true);
node->setScale(0.4f);
node->setPosition(-200/*+i*5*/,0);
addChild(node);
}
}

View File

@ -52,9 +52,6 @@ class TestTimelineAction : public TimelineActionTestLayer
public:
virtual void onEnter();
virtual std::string title() const override;
cocos2d::Ref* loadingRef(std::string filename);
void loadedRef(cocos2d::Ref* ref);
};
#endif // __ANIMATION_SCENE_H__

File diff suppressed because it is too large Load Diff