Ejemplo n.º 1
0
void CDataManager::LoadPlayerData()
{
	FileUtils* Utils = FileUtils::sharedFileUtils();
	string fString = FileUtils::sharedFileUtils()->getWritablePath() + "player_data.json";
	string szData;

	ssize_t fileSize;
	const char* stream = (char*)Utils->getFileData(fString, "rb", &fileSize);

	if (stream == NULL)
	{
		m_PlayerData.m_szName = "Guest";
		m_PlayerData.m_nStage1Count = 0;
		m_PlayerData.m_nStage2Count = 0;
		m_PlayerData.m_nStage3Count = 0;
	}
	else
	{
		string data = string((const char*)stream, fileSize);
		CC_SAFE_DELETE_ARRAY(stream);

		//Document doc;

		/*if (doc.Parse<0>(data.c_str()).HasParseError())
			CCLOG(doc.GetParseError());*/
		/*else
		{
			m_PlayerData.m_szName = doc["PlayerName"].GetString();
			m_PlayerData.m_nStage1Count = doc["Stage1"].GetInt();
			m_PlayerData.m_nStage2Count = doc["Stage2"].GetInt();
			m_PlayerData.m_nStage3Count = doc["Stage3"].GetInt();
		}*/
	}
}
Ejemplo n.º 2
0
static void printFileUtils(int fd)
{
    FileUtils* fu = FileUtils::getInstance();

    mydprintf(fd, "\nSearch Paths:\n");
    auto list = fu->getSearchPaths();
    for( const auto &item : list) {
        mydprintf(fd, "%s\n", item.c_str());
    }

    mydprintf(fd, "\nResolution Order:\n");
    list = fu->getSearchResolutionsOrder();
    for( const auto &item : list) {
        mydprintf(fd, "%s\n", item.c_str());
    }

    mydprintf(fd, "\nWriteble Path:\n");
    mydprintf(fd, "%s\n", fu->getWritablePath().c_str());

    mydprintf(fd, "\nFull Path Cache:\n");
    auto cache = fu->getFullPathCache();
    for( const auto &item : cache) {
        mydprintf(fd, "%s -> %s\n", item.first.c_str(), item.second.c_str());
    }
}
void ActorManager::LoadResource(const vector<Name>& resNameList)
{
	//1.打开文件
	FileUtils* fin = FileUtils::getInstance();
	Data data = fin->getDataFromFile("data/Actor.json");
	CCASSERT(!data.isNull(), "[Actor.json] Lost!");

	//2.载入json
	string str = string((char*)data.getBytes(), data.getSize());
	rapidjson::Document root;
	root.Parse<0>(str.c_str());
	CCASSERT(root.IsObject() && root.HasMember("actordata"), "illegal [Actor.json]");

	//3.读取json数据
	int Size = root["actordata"].Size();
	for (int i = 0; i < Size; i++) {
		string name = root["actordata"][i]["name"].GetString();
		if (std::find(resNameList.begin(), resNameList.end(), name) != resNameList.end())
		{
			ActorData d;
			d.defaultanimate=root["actordata"][i]["defaultanimate"].GetString();
			int size = root["actordata"][i]["actioncount"].GetInt();
			CCASSERT(size != 0, "framecount must NOT equal 0");
			for (int j = 0; j < size; j++) {
				d.maps[root["actordata"][i]["actionName"][j].GetString()] = root["actordata"][i]["animateName"][j].GetString();
			}
			m_actordata[name] = d;
		}
	}
}
Ejemplo n.º 4
0
void AnnHelper::LoadResponsesForTraining_new(std::vector<std::string> _files, cv::Mat& _response)
{
	FileUtils futils;
	MathUtils mathUtils;
	MatUtils matutils;
	Mat responses;

	for (string filename : _files)
	{
		//获取图片信息文件路径
		string fileinfo = filename.substr(0, filename.find_last_of('\\'));//目录
		fileinfo += "\\training_data_new.txt";
		//读取结果矩阵
		vector<string> matNames;
		vector<string> matStrs;
		futils.ReadMatFile(matStrs, matNames, fileinfo);
		assert(matStrs.size() > 0);

		int bcodeIndex = 0;//数值矩阵
		int bitIndex = 0;//位数矩阵

		for (int i = 0; i < matNames.size(); i++)
		{
			if (matNames[i] == "code")
			{
				bcodeIndex = i;
			}
			if (matNames[i] == "bit")
			{
				bitIndex = i;
			}
		}

		string bcode = "";
		Mat decCodeMat = matutils.ToMat(matStrs[bcodeIndex]);
		Mat bitMat = matutils.ToMat(matStrs[bitIndex]);
		assert(decCodeMat.cols == bitMat.cols);
		int bitNum=0;
		int bit = 0;
		for (int i = 0; i < decCodeMat.cols; i++)
		{
			bitNum = decCodeMat.at<float>(0, i);
			bit = bitMat.at<float>(0, i);
			bcode += mathUtils.ConvertToBinary(bitNum, bit);
		}
		stringstream ss;
		Mat resMat(1, bcode.length(), CV_32F);
		for (int i = 0; i < resMat.cols; i++)
		{
			ss << bcode[i];
			float ib = 0.;
			ss >> ib;
			resMat.at<float>(0, i) = ib;
			ss.clear();
		}
		matutils.AddMatRow(responses, resMat, responses);
	}
	_response = responses;
}
Ejemplo n.º 5
0
void TestUnicodePath::onExit()
{
    
    FileUtils *sharedFileUtils = FileUtils::getInstance();
    sharedFileUtils->purgeCachedEntries();
    sharedFileUtils->setFilenameLookupDictionary(ValueMap());
    FileUtilsDemo::onExit();
}
Ejemplo n.º 6
0
void TestSearchPath::onExit()
{
    FileUtils *sharedFileUtils = FileUtils::getInstance();

    // reset search path
    sharedFileUtils->setSearchPaths(_defaultSearchPathArray);
    sharedFileUtils->setSearchResolutionsOrder(_defaultResolutionsOrderArray);
    FileUtilsDemo::onExit();
}
Ejemplo n.º 7
0
int LuaStack::executeScriptFile(const char* filename)
{
    CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");
    
    static const std::string BYTECODE_FILE_EXT    = ".luac";
    static const std::string NOT_BYTECODE_FILE_EXT = ".lua";
    
    std::string buf(filename);
    //
    // remove .lua or .luac
    //
    size_t pos = buf.rfind(BYTECODE_FILE_EXT);
    if (pos != std::string::npos)
    {
        buf = buf.substr(0, pos);
    }
    else
    {
        pos = buf.rfind(NOT_BYTECODE_FILE_EXT);
        if (pos == buf.length() - NOT_BYTECODE_FILE_EXT.length())
        {
            buf = buf.substr(0, pos);
        }
    }
    
    FileUtils *utils = FileUtils::getInstance();
    //
    // 1. check .lua suffix
    // 2. check .luac suffix
    //
    std::string tmpfilename = buf + NOT_BYTECODE_FILE_EXT;
    if (utils->isFileExist(tmpfilename))
    {
        buf = tmpfilename;
    }
    else
    {
        tmpfilename = buf + BYTECODE_FILE_EXT;
        if (utils->isFileExist(tmpfilename))
        {
            buf = tmpfilename;
        }
    }
    
    std::string fullPath = utils->fullPathForFilename(buf);
    Data data = utils->getDataFromFile(fullPath);
    int rn = 0;
    if (!data.isNull())
    {
        if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0)
        {
            rn = executeFunction(0);
        }
    }
    return rn;
}
Ejemplo n.º 8
0
void TestIsFileExist::onExit()
{

    FileUtils *sharedFileUtils = FileUtils::getInstance();

    // reset filename lookup
    sharedFileUtils->setFilenameLookupDictionary(ValueMap());

    FileUtilsDemo::onExit();
}
Ejemplo n.º 9
0
void TestIsDirectoryExist::onExit()
{
    
    FileUtils *sharedFileUtils = FileUtils::getInstance();
    
    // reset filename lookup
    sharedFileUtils->purgeCachedEntries();
    
    FileUtilsDemo::onExit();
}
Ejemplo n.º 10
0
void Application::setResourceRootPath(const std::string& rootResDir)
{
    _resourceRootPath = rootResDir;
    if (_resourceRootPath[_resourceRootPath.length() - 1] != '/')
    {
        _resourceRootPath += '/';
    }
    FileUtils* pFileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
    searchPaths.insert(searchPaths.begin(), _resourceRootPath);
    pFileUtils->setSearchPaths(searchPaths);
}
void AppDelegate::initResourcePath()
{
	FileUtils* sharedFileUtils = FileUtils::getInstance();
    std::string strBasePath = sharedFileUtils->getWritablePath();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)|| (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    sharedFileUtils->addSearchPath("res/");
#else
    sharedFileUtils->addSearchPath("../../res/");
#endif
    
    sharedFileUtils->addSearchPath(strBasePath + "upd/", true);
}
Ejemplo n.º 12
0
static jboolean FileUtils_createFile(JNIEnv* env,jobject thiz,jstring filePath)
{
	FileUtils* fileUtils = (FileUtils*)env->GetIntField(thiz,fileUtilsFieldID);
	if(fileUtils == NULL)
		return -1;
	const jchar* jFilePath = env->GetStringChars(filePath,NULL);
	jsize j_size = env->GetStringLength(filePath);
	char* s_filePath = UTF16toUTF8((jchar*)jFilePath,(size_t*)&j_size);
	bool ret = fileUtils->createFile(s_filePath);
	env->ReleaseStringChars(filePath,jFilePath);
	free(s_filePath);
	return ret;
}
Ejemplo n.º 13
0
void touch_file(bool single)
{
  FileUtils file;
  int ret = file.open("test1.txt", O_WRONLY | O_TRUNC | O_CREAT, 0644);
  ASSERT_NE(ret, 0);
  
  vector<string> v;
  gen_file(v, single);

  for (size_t i = 0;i < v.size();i++) {
    file.write(v[i].c_str(), v[i].size());
  }
  file.close();
}
Ejemplo n.º 14
0
bool AdjustBMParam::saveParameters(){

    FileUtils* fileUtils = new FileUtils();

    QString fileName = fileUtils->saveFile();

    int preFilterSz = this->ui->preFilterSz->value();
    int preFilterCap = this->ui->preFilterCap->value();
    int sadWndSz = this->ui->SADWndSz->value();
    int minDisp = this->ui->minDisp->value();
    int numDisp = 16*(this->ui->numDisp->value());
    int texture = this->ui->textureth->value();
    int uniquness = this->ui->uniq->value();
    int spkWndSz = this->ui->speckleWndSz->value();
    int spkRange = this->ui->specklerange->value();

    if(sadWndSz%2==0)
        sadWndSz++;
    if(sadWndSz<5)
        sadWndSz = 5;

    if(preFilterSz%2==0)
        preFilterSz++;
    if(preFilterSz<5)
        preFilterSz = 5;


    CvFileStorage* fstorage = cvOpenFileStorage(fileName.toLocal8Bit().data(), NULL, CV_STORAGE_WRITE);
    if(fstorage == NULL){
        fprintf(stderr,"ERROR: File storage NULL!\n");
        return false;
    }

    cvWriteInt(fstorage, "preFilterSize", preFilterSz);
    cvWriteInt(fstorage, "preFilterCap", preFilterCap);
    cvWriteInt(fstorage, "sadWindowSize", sadWndSz);
    cvWriteInt(fstorage, "minDisp", minDisp);
    cvWriteInt(fstorage, "numDisp", numDisp);
    cvWriteInt(fstorage, "textureThreshold", texture);
    cvWriteInt(fstorage, "uniquness", uniquness);
    cvWriteInt(fstorage, "spkWindowSize", spkWndSz);
    cvWriteInt(fstorage,"spkRange", spkRange);

    cvReleaseFileStorage(&fstorage);

    delete fileUtils;

    return true;

}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
  FileUtils tools;
  std::string root(argv[1]);
  
  if(argc != 2)
  {
    std::cerr << "Usage: file_utils <root_directory>\n";
    return 1;
  }
  
  // Find all duplicate files start at root directory
  tools.FindDups(root);
  
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    FileUtils *fu = FileUtils::getInstance();
    ValueMap vm = fu->getValueMapFromFile("data.plist");
    log("%s",vm["name"].asString().c_str());
    
    return true;
}
Ejemplo n.º 17
0
int LuaStack::executeScriptFile(const char* filename)
{
    CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");

    FileUtils *utils = FileUtils::getInstance();
    std::string fullPath = utils->fullPathForFilename(filename);
    Data data = utils->getDataFromFile(fullPath);
    int rn = 0;
    if (!data.isNull()) {
        if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0) {
            rn = executeFunction(0);
        }
    }
    return rn;
}
Ejemplo n.º 18
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("Bomberman", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("Bomberman");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0f / 60);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    auto frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }

    register_all_packages();
	FileUtils* fileUtils = FileUtils::getInstance();
	fileUtils->addSearchPath("res");
    // create a scene. it's an autorelease object
    auto scene = GameStartScene::createScene();
    // run
    director->runWithScene(scene);
	CCLOG("Animation Interval = %f", director->getAnimationInterval());
    return true;
}
      //test compatible between version2 && version2 compiled without -DCOMPATIBLE
      TEST_F(TestObSSTableTrailer, Compatible)
      {
        ObTrailerOffset trailer_offset;
        ObSSTableTrailer trailer;
        EXPECT_TRUE(default_range == trailer.get_range());
        FileUtils filesys;
        const char *compressor_name = "lzo1x_1_11_compress";
        int64_t file_len = FileDirectoryUtils::get_size(trailer_file_name);
        char *file_buf = reinterpret_cast<char*>(malloc(file_len));
        EXPECT_TRUE(NULL != file_buf);
        int64_t read_size = 0;
        filesys.open(trailer_file_name, O_RDONLY);
        read_size = filesys.read(file_buf, file_len);
        EXPECT_EQ(read_size, file_len);

        int64_t pos = 0;
        pos = trailer.get_serialize_size();
        trailer_offset.trailer_record_offset_ = 0;
        trailer_offset.deserialize(file_buf, file_len, pos);
        EXPECT_EQ(trailer_offset.trailer_record_offset_, 256 * 1024 - 1023);

        pos = 0;
        trailer.deserialize(file_buf, file_len, pos);
        EXPECT_EQ(0x300, trailer.get_trailer_version());
        EXPECT_EQ(1, trailer.get_table_version());
        EXPECT_EQ(0, trailer.get_first_block_data_offset());
        EXPECT_EQ(1, trailer.get_row_value_store_style());
        EXPECT_EQ(1023, trailer.get_block_count());
        EXPECT_EQ(2047, trailer.get_block_index_record_offset());
        EXPECT_EQ(1024, trailer.get_block_index_record_size());
        EXPECT_EQ(8, trailer.get_bloom_filter_hash_count());
        EXPECT_EQ(2047 + 1024, trailer.get_bloom_filter_record_offset());
        EXPECT_EQ(511, trailer.get_bloom_filter_record_size());
        EXPECT_EQ(2047+ 1024 + 511, trailer.get_schema_record_offset());
        EXPECT_EQ(1023, trailer.get_schema_record_size());
        EXPECT_EQ(64 * 1024, trailer.get_block_size());
        EXPECT_EQ(777, trailer.get_row_count());
        EXPECT_EQ(123456789, (int64_t)trailer.get_sstable_checksum());
        EXPECT_EQ(1001, (int64_t)trailer.get_first_table_id());
        EXPECT_EQ(123456789, trailer.get_frozen_time());
        int ret = memcmp(compressor_name, trailer.get_compressor_name(), strlen(compressor_name));
        EXPECT_EQ(0, ret);
        EXPECT_TRUE(default_range == trailer.get_range());
        free(file_buf);
        file_buf = NULL;
        filesys.close();
      }
      TEST_F(TestObSSTableTrailer, write_tariler_to_disk)
      {
        ObSSTableTrailer trailer;
        EXPECT_TRUE(default_range == trailer.get_range());
        FileUtils filesys;
        trailer.set_trailer_version(0x300);
        trailer.set_table_version(1);
        trailer.set_first_block_data_offset(0);
        trailer.set_row_value_store_style(1);
        trailer.set_block_count(1023);
        trailer.set_block_index_record_offset(2047);
        trailer.set_block_index_record_size(1024);
        trailer.set_bloom_filter_hash_count(8);
        trailer.set_bloom_filter_record_offset(2047 + 1024);
        trailer.set_bloom_filter_record_size(511);
        trailer.set_schema_record_offset(2047+ 1024 + 511);
        trailer.set_schema_record_size(1023);
        trailer.set_block_size(64 * 1024);
        trailer.set_row_count(777);
        trailer.set_sstable_checksum(123456789);
        trailer.set_first_table_id(1001);
        trailer.set_frozen_time(123456789);
        trailer.set_range_record_offset(2047+ 1024 + 511 +1023);
        trailer.set_range_record_size(0);
        const char *compressor_name = "lzo1x_1_11_compress";
        trailer.set_compressor_name(compressor_name);

        ObTrailerOffset trailer_offset;
        trailer_offset.trailer_record_offset_= 256 * 1024 - 1023;

        int64_t offset_len = trailer_offset.get_serialize_size();
        int64_t trailer_len = trailer.get_serialize_size();

        int64_t buf_size = offset_len + trailer_len;
        int64_t pos = 0;
        char *serialize_buf = reinterpret_cast<char*>(malloc(buf_size));
        EXPECT_TRUE(NULL != serialize_buf);
        trailer.serialize(serialize_buf, buf_size, pos);
        trailer_offset.serialize(serialize_buf, buf_size, pos);
        filesys.open(trailer_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        int64_t write_size;
        write_size = filesys.write(serialize_buf, buf_size);
        EXPECT_EQ(write_size, buf_size);
        free(serialize_buf);
        serialize_buf = NULL;
        filesys.close();
      }
Ejemplo n.º 21
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("My Game");
        director->setOpenGLView(glview);
    }

    glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::EXACT_FIT);

    FileUtils* futils = FileUtils::getInstance();

    auto screensize = glview->getFrameSize();
    if(screensize.width > 768) {
        vector<string> dirs(1, "hd");
        futils->setSearchResolutionsOrder(dirs);
        director->setContentScaleFactor(2);
    }
    else {
        vector<string> dirs(1, "sd");
        futils->setSearchResolutionsOrder(dirs);
        director->setContentScaleFactor(1);
    }

    SimpleAudioEngine* augine = SimpleAudioEngine::getInstance();

    augine->preloadEffect(futils->fullPathForFilename("hit.wav").c_str());
    augine->preloadEffect(futils->fullPathForFilename("score.wav").c_str());

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    auto scene = LogoLayer::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Ejemplo n.º 22
0
void AppDelegate::initResourcePath()
{
    FileUtils* sharedFileUtils = FileUtils::getInstance();
    //设置SearchPaths
    std::vector<std::string> oldSearchPaths = sharedFileUtils->getSearchPaths();
    std::vector<std::string> tempPaths(oldSearchPaths);
    std::vector<std::string> searchPaths;
    searchPaths.push_back(sharedFileUtils->getWritablePath() + "upd/");
    searchPaths.push_back("res/");
    searchPaths.push_back("src/");
    
    for (int i = 0; i < tempPaths.size(); ++i) {
        searchPaths.push_back(tempPaths[i]);
    }
    
    sharedFileUtils->setSearchPaths(searchPaths);
    
//    MyUnZip::getInstance()->UnZipFile("/Users/binW/Downloads/game.zip", "/Users/binW/Downloads/", PrintfText);
}
Ejemplo n.º 23
0
static jboolean FileUtils_move(JNIEnv* env,jobject thiz,jstring firstPath,jstring copyPath)
{
	FileUtils* fileUtils = (FileUtils*)env->GetIntField(thiz,fileUtilsFieldID);
	if(fileUtils == NULL)
		return -1;
	const jchar* j_file = env->GetStringChars(firstPath,NULL);
	jsize f_size = env->GetStringLength(firstPath);
	char* s_file = UTF16toUTF8((jchar*)j_file,(size_t*)&f_size);

	const jchar* j_cp = env->GetStringChars(copyPath,NULL);
	jsize f_size2 = env->GetStringLength(copyPath);
	char* s_cp_file = UTF16toUTF8((jchar*)j_cp,(size_t*)&f_size2);
	bool ret = fileUtils->copy(s_file,s_cp_file);
	env->ReleaseStringChars(firstPath,j_file);
	env->ReleaseStringChars(copyPath,j_cp);
	free(s_file);
	free(s_cp_file);
	return ret;
}
Ejemplo n.º 24
0
      TEST_F(TestObSSTableSchema, test_compatible)
      {
        ObSSTableSchema schema;
        const ObSSTableSchemaColumnDef *column      = NULL;

        int64_t file_len = FileDirectoryUtils::get_size(schema_file_name);
        char * file_buf = reinterpret_cast<char*>(malloc(file_len));
        int64_t pos = 0;
        FileUtils filesys;
        filesys.open(schema_file_name, O_RDONLY);
        int64_t read_size = filesys.read(file_buf, file_len);
        EXPECT_EQ(read_size, file_len);
        schema.deserialize(file_buf, file_len, pos);
        EXPECT_EQ(schema.get_column_count(), 550);
        int64_t index_find = 0;
        int64_t index = 0;
        int64_t table_schema_size = 0;
        int64_t group_schema_size = 0;
          
        for (uint64_t table_id = 1000; table_id < 1010; ++table_id)
        {
          schema.get_table_schema(table_id, table_schema_size);
          EXPECT_EQ(55, table_schema_size);
          for(uint64_t group_id = 1; group_id < 11; ++group_id)
          {
            schema.get_group_schema(table_id, group_id, group_schema_size);
            EXPECT_EQ(group_schema_size, (int64_t)group_id);
            for(uint64_t column_id = 0; column_id < group_id; ++column_id)
            {
              index_find  = schema.find_column_id(table_id, group_id, column_id);
              column = schema.get_column_def(index_find);
              EXPECT_EQ(index, index_find);
              EXPECT_EQ(column_id, column->column_name_id_);
              EXPECT_EQ(group_id,  column->column_group_id_);
              EXPECT_EQ(table_id,  column->table_id_);
              EXPECT_EQ(ObIntType, column->column_value_type_);
              ++index;
            }
          }
        }
        }
Ejemplo n.º 25
0
void PointsLoader::saveUserPoints()
{
    if(!m_userPointsDirty)
    {
        return;
    }
    std::string serialized;
    serializePoints(m_userPoints, serialized);
    
    FileUtils* fu = FileUtils::getInstance();
    
    std::string dir = fu->getFileDir(m_userConfigPath);
    if(dir.length())
    {
        if(!fu->isDirectoryExist(dir))
        {
            fu->createDirectory(dir);
        }
    }
    fu->writeStringToFile(serialized, m_userConfigPath);
    m_userPointsDirty = false;
}
Ejemplo n.º 26
0
void ShapeCache::addShapeWithFileToSprite(std::string plist, cocos2d::Sprite *s){
    FileUtils *fu = FileUtils::getInstance();
    ValueMap root = fu->getValueMapFromFile(plist);
    
    auto bodies = root["bodies"].asValueMap();
    ValueMap fixtureDef;
    for (auto iter=bodies.begin(); iter!=bodies.end(); iter++) {
        fixtureDef = iter->second.asValueMap();
    }
    
    ValueMap item = fixtureDef["fixtures"].asValueVector()[0].asValueMap();
    s->setPhysicsBody(PhysicsBody::create());
    for (auto iter=item.begin(); iter!=item.end(); iter++) {
        std::string key = iter->first;
        auto type = iter->second;
        if (key == "polygons") {
            auto value = type.asValueVector();
            for (int i=0; i<value.size(); i++) {
                auto _item = value[i].asValueVector();
                Vec2 *vec = new Vec2[_item.size()];
                for (int j=0; j<_item.size(); j++) {
                    Point p = PointFromString(_item[j].asString().c_str());
                    vec[j] = Vec2(p.x, p.y);
                }
                s->getPhysicsBody()->addShape(PhysicsShapePolygon::create(vec, _item.size()));
            }
        }else if (key == "mass"){
            s->getPhysicsBody()->setMass(type.asInt());
        }else if (key == "friction"){
            auto shapes = s->getPhysicsBody()->getShapes();
            for (int i=0; i<shapes.size(); i++) {
                shapes.at(i)->setFriction(type.asInt());
            }
        }
        
    }
    
}
Ejemplo n.º 27
0
void AnnHelper::LoadResponsesForTraining(std::vector<string> _files, cv::Mat& _response)
{
	FileUtils futils;
	MatUtils matutils;
	Mat responses;

	for (string filename : _files)
	{
		//获取图片信息文件路径
		string fileinfo = filename.substr(0, filename.find_last_of('\\'));//目录
		fileinfo += "\\training_data.txt";
		//读取结果矩阵
		vector<string> matNames;
		vector<string> matStrs;
		futils.ReadMatFile(matStrs, matNames, fileinfo);
		assert(matStrs.size()>0);
		
		Mat response = matutils.ToMat(matStrs[0]);
		matutils.AddMatRow(responses, response, responses);

	}
	_response = responses;
}
Ejemplo n.º 28
0
void drawCountry(Renderer* canvas, const Country &country, bool drawDescription) {
    /** Title area **/
    Font fontCountryName("resources/fonts/FreeSansBold.ttf", 30);
    fontCountryName.setColor(Color(0xf0, 0xff, 0xff));

    Text name(country.getName(), &fontCountryName);
    canvas->drawText(&name, Point(358, 105));
    
    /* Photo area */
    string photoPath = "data/countries/" + country.getIsoCode() + "/postal.png";
    FileUtils fileUtils;
    if (!fileUtils.fileExists(photoPath.c_str())) {
        photoPath = "data/countries/default-photo.jpg";
    }
    Surface photoSurface(photoPath);
    photoSurface.transform(4, 1, 1);
    Texture photoTexture(canvas->internal, photoSurface.toSDL());
    canvas->drawTexture(&photoTexture, Point(47, 115));

    Texture polaroidSurf(canvas->internal, "resources/images/game/polaroid.png");
    canvas->drawTexture(&polaroidSurf, Point(30, 108));

    string flagPath = "data/countries/" + country.getIsoCode() + "/flag.png";
    Surface flagSurface(flagPath);
    flagSurface.transform(0, .5, 1);
    Texture flagTexture(canvas->internal, flagSurface.toSDL());
    canvas->drawTexture(&flagTexture, Point(300, 110));

    if (drawDescription) {
        Font descFont("resources/fonts/FreeSansBold.ttf", 14);
        descFont.setColor(Color(0xd3, 0xba, 0xa4));

        Text description(country.getDescription(), &descFont);
        TextUtils textUtils;
        textUtils.drawLines(canvas, description, Point(358, 150), Dimension(360, 340));
    }
}
Ejemplo n.º 29
0
      TEST_F(TestObSSTableSchema, write_schema_to_disk)
      {
        ObSSTableSchema schema;
        ObSSTableSchemaColumnDef column_def;
        int ret = OB_SUCCESS;
        column_def.reserved_ = 0;

        for ( int table_id = 1000; table_id < 1010; ++table_id )
        {
          column_def.table_id_ = table_id;
          for ( int group_id = 1 ; group_id <= 10; ++group_id )
          {
            column_def.column_group_id_ = static_cast<uint16_t>(group_id);
            for ( int column_id = 0; column_id < group_id; ++column_id )
            {
              column_def.column_name_id_ = column_id;
              column_def.column_value_type_ = ObIntType;
              ret = schema.add_column_def(column_def);
              EXPECT_TRUE(OB_SUCCESS == ret);
            }
          }
        }

        EXPECT_EQ(550, schema.get_column_count());
        FileUtils filesys;
        filesys.open(schema_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        int64_t buf_size = schema.get_serialize_size();
        char * serialize_buf = reinterpret_cast<char *>(malloc(buf_size));
        EXPECT_TRUE(NULL != serialize_buf);
        int64_t pos = 0;
        schema.serialize(serialize_buf, buf_size, pos);
        
        int64_t write_size = filesys.write(serialize_buf, buf_size);
        EXPECT_EQ(write_size, buf_size);
        free(serialize_buf);
        serialize_buf = NULL;
      }
Ejemplo n.º 30
0
    void GameNode3DReader::setPropsWithFlatBuffers(cocos2d::Node *node,
                                                   const flatbuffers::Table* node3DOptions)
    {
        auto options = (GameNode3DOption*)node3DOptions;
        
        std::string name = options->name()->c_str();
        node->setName(name);

        _sceneBrushInstance = nullptr;
        bool skyBoxEnabled = options->skyBoxEnabled() != 0;
        if (skyBoxEnabled)
        {
            std::string leftFileData = options->leftFileData()->path()->c_str();
            std::string rightFileData = options->rightFileData()->path()->c_str();
            std::string upFileData = options->upFileData()->path()->c_str();
            std::string downFileData = options->downFileData()->path()->c_str();
            std::string forwardFileData = options->forwardFileData()->path()->c_str();
            std::string backFileData = options->backFileData()->path()->c_str();
            FileUtils *fileUtils = FileUtils::getInstance();

            if (fileUtils->isFileExist(leftFileData)
                && fileUtils->isFileExist(rightFileData)
                && fileUtils->isFileExist(upFileData)
                && fileUtils->isFileExist(downFileData)
                && fileUtils->isFileExist(forwardFileData)
                && fileUtils->isFileExist(backFileData))
            {
                _sceneBrushInstance = CameraBackgroundSkyBoxBrush::create(leftFileData, rightFileData, upFileData, downFileData, forwardFileData, backFileData);
            }
        }

        std::string customProperty = options->customProperty()->c_str();
        ComExtensionData* extensionData = ComExtensionData::create();
        extensionData->setCustomProperty(customProperty);
        if (node->getComponent(ComExtensionData::COMPONENT_NAME))
        {
            node->removeComponent(ComExtensionData::COMPONENT_NAME);
        }
        node->addComponent(extensionData);

        bool useDefaultLight = options->useDefaultLight();
        if (useDefaultLight)
        {
            AmbientLight* defaultLight = AmbientLight::create(Color3B::WHITE);
            defaultLight->setIntensity(0.5f);
            node->addChild(defaultLight);
        }
    }