#include <boost/thread/thread.hpp>
#include "LoadingLayer.h"
#include "FlutterLayer.h"
#include "CombatReportParser.h"
#include "JsonObject.h"
#include "CommonInclude.h"
#include "JavaLib.h"
//#include "MemoryPool/SingtonMemoryPool.h"
//using namespace MemPool;
using namespace std;
//"网络错误" utf-8码
//static char prompt[] = {231,189,145,231,187,156,233,148,153,232,175,175,0};
//"战报获取错误" utf-8码
//static char prompt1[] = {230,136,152,230,138,165,232,142,183,229,143,150,233,148,153,232,175,175,0};
CCScene* LoadingLayer::scene()
{
CCScene* scene = CCScene::node();
LoadingLayer* layer = new LoadingLayer();
scene->addChild(layer);
layer->release();
return scene;
}
void LoadingLayer::ScheduleUpdateLoadingLabel(ccTime dt)
{
if(error != 0) return;
char msg[32];
sprintf(msg,"Loading...%d%%",(int)(curPngLoadingNum*1.0/totalPngNum*100));
loadingLabel->setString(msg);
loadingAnimation->tick(dt);
}
LoadingLayer::LoadingLayer()
{
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite* loadingBk = CCSprite::spriteWithFile(PListCollect::sharedPListCollect().GetFilePath("loadingbk.png")->m_sString.c_str());
loadingBk->setPosition(ccp(0,0));
loadingBk->setAnchorPoint(ccp(0,0));
loadingBk->setScale(2.0);
addChild(loadingBk);
loadingLabel = CCLabelTTF::labelWithString("Loading...", "Arial", 32);
loadingLabel->setPosition(ccp(size.width/2,size.height/2));
addChild(loadingLabel);
loadingAnimation = new CCMWSprite;
vector<string> imageList;
imageList.push_back(PNG_FILE_PATH("loading.png"));
loadingAnimation->initWithMWFile(PListCollect::sharedPListCollect().GetFilePath("loading.anu")->m_sString,imageList,0);
loadingAnimation->setPosition(ccp(size.width/2,size.height/2));
loadingAnimation->shouldLoop = true;
loadingAnimation->setScale(2.0);
addChild(loadingAnimation);
loadingAnimation->release();
int skipCount = 0, pvpCount = 0;
#ifdef ANDROID
{
JavaStaticMethodCaller caller;
skipCount = caller.CallV_I("org/tools/Application","QueryPassCount");
LOG(2,"cocos2d","skip Count = %d",skipCount);
}
{
JavaStaticMethodCaller caller;
pvpCount = caller.CallV_I("org/tools/Application","QueryFightCount");
LOG(2,"cocos2d","pvp Count = %d",pvpCount);
}
#endif
//跳过动画次数
char const1[19] = {232,183,179,232,191,135,229,138,168,231,148,187,230,172,161,230,149,176,'\0'};
char msg1[64];
sprintf(msg1,"%s %d",const1,skipCount);
CCLabelTTF* skipCountLabel = CCLabelTTF::labelWithString(msg1, "Arial", 36);
//skipCount->setAnchorPoint(ccp(0,0.5));
skipCountLabel->setPosition(ccp(size.width/2 ,size.height/2 - 180));
addChild(skipCountLabel);
//剩余挑刺次数
char const2[19] = {229,137,169,228,189,153,230,140,145,230,136,152,230,172,161,230,149,176,'\0'};
char msg2[64];
sprintf(msg2,"%s %d",const2,pvpCount);
CCLabelTTF* pvpCountLabel = CCLabelTTF::labelWithString(msg2, "Arial", 36);
//pvpCount->setAnchorPoint(ccp(0,0.5));
pvpCountLabel->setPosition(ccp(size.width/2 ,size.height/2 - 230));
addChild(pvpCountLabel);
totalPngNum = 1;
curPngLoadingNum = 0;
error = 0;
errorPrompt = NULL;
}
void LoadingLayer::onEnter()
{
CCNode::onEnter(); //must be called
//open a thread
boost::thread thread(boost::bind(&LoadingLayer::LoadingData, this));
//registher the schedule
schedule(schedule_selector(LoadingLayer::ScheduleCreateSpritesAfterLoadingData), 0.03f);
schedule(schedule_selector(LoadingLayer::ScheduleUpdateLoadingLabel), 0.03f);
}
void LoadingLayer::LoadingData()
{
bLoadingCompleted = false;
error = 0;
//CCDirectorState::SharedCCDirectorState().isPVE = true;
LOG(2,"cocos2d","LoadingData enter\n");
#ifdef ANDROID
//Get combat report and parse
{
char* buffer = NULL;
int bufSize;
int result;
JavaStaticMethodCaller caller;
if(!CCDirectorState::SharedCCDirectorState().isPVE)
{
LOG(2,"cocos2d","GetPVP combat report");
result = caller.CallL_I("org/tools/Application","GetBattleXml",&buffer,&bufSize);
}
else
{
LOG(2,"cocos2d","GetPVE combat report");
result = caller.CallL_I("org/tools/Application","GetPveBattleXml",&buffer,&bufSize);
}
//各种失败,包括网络失败及“战斗次数不足"
if(result != 0)
{
//LOG(6,"cocos2d","caller get combatreport from nework failure");
//JavaMethodCaller caller;
//caller.CallV_V("org/cocos2dx/application/VSActivity","Finish");
//LOG(2,"cocos2d","call VSActivity::Finish after");
error = result;
errorMsg = string(buffer);
return ;
}
//#ifdef LOG_ON_ANDROID
// LOG(2,"cocos2d","boost get system before");
// char fileName[64];
// boost::xtime xt;
// boost::xtime_get(&xt, boost::TIME_UTC); // initialize xt with current time
// sprintf(fileName,"sdcard/report/report%ld.txt",xt.sec);
// LOG(2,"cocos2d","boost get system after");
// //FILE* fp = fopen("sdcard/report/report.txt","w");
// FILE* fp = fopen(fileName,"w");
// LOG(2,"cocos2d","fopen after");
// fprintf(fp,"%s",buffer);
// LOG(2,"cocos2d","fprintf after");
// fclose(fp);
// LOG(2,"cocos2d","fclose");
//#endif
bool parse = CombatReportParser::sharedCombatReportParser().ParseCombatReport(buffer,bufSize);
if(!parse)
{
//LOG(6,"cocos2d","ParseCombatReport failure");
//JavaMethodCaller caller;
//caller.CallV_V("org/cocos2dx/application/VSActivity","Finish");
error = 2;
//战报解析错误
char prompt1[19] = {230,136,152,230,138,165,232,167,163,230,158,144,233,148,153,232,175,175,'\0'};
errorMsg = string(prompt1);
return ;
}
}
//Get Combat reward and parse
{
LOG(2,"cocos2d","Get Battle Reward before");
JavaStaticMethodCaller caller;
int bufSize;
char* buffer;
int result = caller.CallL_I("org/tools/Application","GetBattleReward",&buffer,&bufSize);
LOG(2,"cocos2d","org/tools/Application GetBattleReward after");
if(result == 0 && bufSize > 0)
{
LOG(2,"cocos2d","bufSize = %d, buffer = %s",bufSize,buffer);
JsonObject conf((const char*)buffer);
boost::shared_ptr<double> param1 = conf.GetParam<double>("nExpAdd");
boost::shared_ptr<double> param2 = conf.GetParam<double>("nSilverAdd");
boost::shared_ptr<double> param3 = conf.GetParam<double>("nWin");
boost::shared_ptr<double> param4 = conf.GetParam<double>("nItemId");
if(param1) CombatResultAndReward::GetInstance().nExpAdd = (int)*param1;
if(param2) CombatResultAndReward::GetInstance().nSilverAdd = (int)*param2;
if(param3) CombatResultAndReward::GetInstance().nWin = (int)*param3;
if(param4) CombatResultAndReward::GetInstance().nItemId = (int)*param4;
LOG(2,"cocos2d","nWin in combatreport = %s, nWin in result = %d",CombatReportParser::sharedCombatReportParser().GetCombatReport()->result.winSide.c_str(),
CombatResultAndReward::GetInstance().nWin);
}
else
{
//LOG(2,"cocos2d","GetBattleReward from network failure");
//JavaMethodCaller caller;
//caller.CallV_V("org/cocos2dx/application/VSActivity","Finish");
error = 2;
//网络错误
char prompt[13] = {231,189,145,231,187,156,233,148,153,232,175,175,'\0'};
errorMsg = string(prompt);
return ;
}
}
#else
bool result = CombatReportParser::sharedCombatReportParser().ParseCombatReport("xml/report1326272943.txt");
if(!result)
{
//LOG(6,"cocos2d","Parse report.xml Failure!");
//exit(0);
error = 2;
char prompt1[19] = {230,136,152,230,138,165,232,167,163,230,158,144,233,148,153,232,175,175,'\0'};
errorMsg = string(prompt1);
return;
}
#endif
LOG(2,"cocos2d","ParseFromXml after\n");
//初始化imageCache
CCImageCache::GetInstance()->init();
totalPngNum = 5 + CombatReportParser::sharedCombatReportParser().GetTotalImageListNum();
//PVE的时候,可能会继续攻城,因此�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
cocos2d-x多线程异步加载程序.zip (9个子文件)
cocos2d-x多线程异步加载程序
LoadingLayer.cpp 25KB
JavaLib.cpp 8KB
Jni.cpp 5KB
JavaLib.h 2KB
LoadingLayer.h 915B
CCImageCache.h 904B
NativeBitmapCache.h 1KB
CCImageCache.cpp 2KB
NativeBitmapCache.cpp 12KB
共 9 条
- 1
资源评论
- wangshiwuhack2018-01-05写的挺好的,看了
- 毅然是我2014-10-10写的挺好的,看了,学习哦~
- iamxiaobei2017-11-09写的挺好的,看了
- asap0102016-01-23我看不懂,刚学习
travi
- 粉丝: 870
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功