Example #1
0
void CPageDocuments::DisplayResearch(int index)
{
  assert(index >= 0 && index < RESEARCH_MAX);
  CString info;
  m_list.DeleteAllItems();
  DeleteAllColumns();
  m_list.InsertColumn(0 , "等级" , LVCFMT_LEFT ,     40);
  m_list.InsertColumn(1 , "升级金属" , LVCFMT_LEFT , 130);
  m_list.InsertColumn(2 , "升级晶体" , LVCFMT_LEFT , 130);
  m_list.InsertColumn(3 , "升级重氢" , LVCFMT_LEFT , 130);
  m_list.InsertColumn(4 , "升级时间" , LVCFMT_LEFT , 130); 

  for(int i = 0 ; i < MAX_LEVEL ; ++i)
  {
    info.Format("%d" , i);
    m_list.InsertItem(i , info);

   //metal
    info.Format("%.0f" , get_research_upgrade_resource(RESEARCH_RESOURCE_NEED_BASE[index][0] , i) );
    m_list.SetItemText(i , 1 , info);

    //crystal
    info.Format("%.0f" , get_research_upgrade_resource(RESEARCH_RESOURCE_NEED_BASE[index][1] , i) );
    m_list.SetItemText(i , 2 , info);

    //diplogen
    info.Format("%.0f" , get_research_upgrade_resource(RESEARCH_RESOURCE_NEED_BASE[index][2] , i));
    m_list.SetItemText(i , 3 , info);

    //time
    double t = get_research_upgrade_seconds(
                        GetDataPtr()->GetBuildingLevel(FACTORY_BUILDING_LAB),  //LabFactory level
                        GetDataPtr()->GetBuildingLevel(FACTORY_BUILDING_NANITE),         //nanitefactory level
                        get_research_upgrade_resource(RESEARCH_RESOURCE_NEED_BASE[index][0] , i)   , 
                        get_research_upgrade_resource(RESEARCH_RESOURCE_NEED_BASE[index][1] , i)   , 
                        1.0);
    ElapsedTimer timer;
    timer.Init(t);
    m_list.SetItemText(i , 4 , timer.ToCString());
   }
  m_list.SetItemBkColor(Researchs_Entry(index)->GetLevel() , -1 , RGB(0 , 255 , 0));
}
Example #2
0
FIBITMAP *GraphicsHelps::loadImage(std::string file, bool convertTo32bit)
{
#ifdef DEBUG_BUILD
    ElapsedTimer loadingTime;
    ElapsedTimer fReadTime;
    ElapsedTimer imgConvTime;
    loadingTime.start();
    fReadTime.start();
#endif
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
    FileMapper fileMap;

    if(!fileMap.open_file(file.c_str()))
        return NULL;

    FIMEMORY *imgMEM = FreeImage_OpenMemory(reinterpret_cast<unsigned char *>(fileMap.data()),
                                            static_cast<unsigned int>(fileMap.size()));
    FREE_IMAGE_FORMAT formato = FreeImage_GetFileTypeFromMemory(imgMEM);

    if(formato  == FIF_UNKNOWN)
        return NULL;

    FIBITMAP *img = FreeImage_LoadFromMemory(formato, imgMEM, 0);
    FreeImage_CloseMemory(imgMEM);
    fileMap.close_file();

    if(!img)
        return NULL;

#else
    FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(file.toUtf8().data(), 0);

    if(formato  == FIF_UNKNOWN)
        return NULL;

    FIBITMAP *img = FreeImage_Load(formato, file.toUtf8().data());

    if(!img)
        return NULL;

#endif
#ifdef DEBUG_BUILD
    long long fReadTimeElapsed = static_cast<long long>(fReadTime.elapsed());
    long long imgConvertElapsed = 0;
#endif

    if(convertTo32bit)
    {
#ifdef DEBUG_BUILD
        imgConvTime.start();
#endif
        FIBITMAP *temp;
        temp = FreeImage_ConvertTo32Bits(img);

        if(!temp)
            return NULL;

        FreeImage_Unload(img);
        img = temp;
#ifdef DEBUG_BUILD
        imgConvertElapsed = static_cast<long long>(imgConvTime.elapsed());
#endif
    }

#ifdef DEBUG_BUILD
    D_pLogDebug("File read of texture %s passed in %d milliseconds", file.c_str(), static_cast<int>(fReadTimeElapsed));
    D_pLogDebug("Conv to 32-bit of %s passed in %d milliseconds", file.c_str(), static_cast<int>(imgConvertElapsed));
    D_pLogDebug("Total Loading of image %s passed in %d milliseconds", file.c_str(), static_cast<int>(loadingTime.elapsed()));
#endif
    return img;
}
Example #3
0
void runSimpleRendering( string renderingFileName, string resourceDir, RenderingInfo* info) {
	SkColor defaultMapColor = SK_ColorLTGRAY;

	if (info->width > 10000 || info->height > 10000) {
		osmand_log_print(LOG_ERROR, "We don't rendering images more than 10000x10000 ");
		return;
	}

	osmand_log_print(LOG_INFO, "Rendering info bounds(%d, %d, %d, %d) zoom(%d), width/height(%d/%d) tilewidth/tileheight(%d/%d) fileName(%s)",
			info->left, info->top, info->right, info->bottom, info->zoom, info->width, info->height, info->tileWX, info->tileHY, info->tileFileName.c_str());
	RenderingRulesStorage* st = new RenderingRulesStorage(renderingFileName.c_str());
	st->parseRulesFromXmlInputStream(renderingFileName.c_str(), NULL);
	RenderingRuleSearchRequest* searchRequest = new RenderingRuleSearchRequest(st);
	ResultPublisher* publisher = new ResultPublisher();
	SearchQuery q(floor(info->left), floor(info->right), ceil(info->top), ceil(info->bottom), searchRequest, publisher);
	q.zoom = info->zoom;

	ResultPublisher* res = searchObjectsForRendering(&q, true, "Nothing found");
	osmand_log_print(LOG_INFO, "Found %d objects", res->result.size());

	SkBitmap* bitmap = new SkBitmap();
	bitmap->setConfig(SkBitmap::kRGB_565_Config, info->width, info->height);

	size_t bitmapDataSize = bitmap->getSize();
	void* bitmapData = malloc(bitmapDataSize);
	bitmap->setPixels(bitmapData);

	osmand_log_print(LOG_INFO, "Initializing rendering style and rendering context");
	ElapsedTimer initObjects;
	initObjects.start();

	RenderingContext rc;
	rc.setDefaultIconsDir(resourceDir);
	searchRequest->clearState();
	searchRequest->setIntFilter(st->PROPS.R_MINZOOM, info->zoom);
	if (searchRequest->searchRenderingAttribute(A_DEFAULT_COLOR)) {
		defaultMapColor = searchRequest->getIntPropertyValue(searchRequest->props()->R_ATTR_COLOR_VALUE);
	}
	searchRequest->clearState();
	searchRequest->setIntFilter(st->PROPS.R_MINZOOM, info->zoom);
	if (searchRequest->searchRenderingAttribute(A_SHADOW_RENDERING)) {
		rc.setShadowRenderingMode(searchRequest->getIntPropertyValue(searchRequest->props()->R_ATTR_INT_VALUE));
		//rc.setShadowRenderingColor(searchRequest->getIntPropertyValue(searchRequest->props()->R_SHADOW_COLOR));
	}
	rc.setLocation(
			((double)info->left)/getPowZoom(31-info->zoom),
			((double)info->top)/getPowZoom(31-info->zoom)
			);
	rc.setDimension(info->width, info->height);
	rc.setZoom(info->zoom);
	rc.setRotate(0);
	rc.setDensityScale(1);
	osmand_log_print(LOG_INFO, "Rendering image");
	initObjects.pause();
	SkCanvas* canvas = new SkCanvas(*bitmap);
	canvas->drawColor(defaultMapColor);
	doRendering(res->result, canvas, searchRequest, &rc);
	osmand_log_print(LOG_INFO, "End Rendering image");
	osmand_log_print(LOG_INFO, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(),
			rc.nativeOperations.getElapsedTime());
	SkImageEncoder* enc = SkImageEncoder::Create(SkImageEncoder::kPNG_Type);
	if (enc != NULL && !enc->encodeFile(info->tileFileName.c_str(), *bitmap, 100)) {
		osmand_log_print(LOG_ERROR, "FAIL to save tile to %s", info->tileFileName.c_str());
	} else {
		osmand_log_print(LOG_INFO, "Tile successfully saved to %s", info->tileFileName.c_str());
	}
	delete enc;
	delete publisher;
	delete searchRequest;
	delete st;
	delete canvas;
	delete bitmap;
	free(bitmapData);
	return;
}
Example #4
0
void ConfigManager::buildSoundIndex()
{
    int need_to_reserve = 0;
    int total_channels = 32;
    bool newBuild = main_sfx_index.empty();
#ifdef DEBUG_BUILD
    ElapsedTimer loadingTime;
    loadingTime.start();
#endif

    if(newBuild)
    {
        //build array table
        main_sfx_index.resize(static_cast<size_t>(main_sound.size()) - 1);

        for(unsigned long i = 1; i < main_sound.size(); i++)
        {
            obj_sound_index sound;

            if(main_sound.contains(i))
            {
                obj_sound &snd = main_sound[i];
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
                FileMapper fileMap;

                if(fileMap.open_file(snd.absPath.c_str()))
                {
                    sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(),
                                                 static_cast<int>(fileMap.size())), 1);
                    fileMap.close_file();
                }

#else
                sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data());
#endif
                sound.path = snd.absPath;

                if(!sound.chunk)
                    pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError());
                else
                    need_to_reserve += (snd.channel >= 0 ? 1 : 0);

                sound.channel = snd.channel;
            }

            main_sfx_index[static_cast<size_t>(i) - 1] = sound;
        }
    }
    else
    {
        for(unsigned long i = 1; (i < main_sound.size()) && (i <= static_cast<unsigned long>(main_sfx_index.size())); i++)
        {
            if(main_sound.contains(i))
            {
                obj_sound_index &sound = main_sfx_index[static_cast<size_t>(i) - 1];
                obj_sound &snd = main_sound[i];
                sound.setPath(snd.absPath);

                if(sound.need_reload)
                {
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
                    FileMapper fileMap;

                    if(fileMap.open_file(snd.absPath.c_str()))
                    {
                        sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(),
                                                     static_cast<int>(fileMap.size())),
                                                     static_cast<int>(fileMap.size()));
                        fileMap.close_file();
                    }

#else
                    sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data());
#endif
                }

                if(!sound.chunk)
                    pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError());
                else
                    need_to_reserve += (snd.channel >= 0 ? 1 : 0);

                sound.channel = snd.channel;
            }
        }
    }

    if(need_to_reserve > 0)
    {
        total_channels = (total_channels + need_to_reserve + 32);
        total_channels = Mix_AllocateChannels(total_channels);
    }

    //Final channel definition (use reserved channels at end of channels set)
    //int set_channel = (total_channels-1);
    //for(int i=0; i < main_sfx_index.size(); i++)
    //{
    //    obj_sound_index &sound = main_sfx_index[i];
    //    if(sound.channel>=0)
    //    {
    //        sound.channel = set_channel--;
    //    }
    //}

    if(need_to_reserve == total_channels)
        need_to_reserve = 0;

    //else
    //    need_to_reserve=set_channel;
#ifndef DEBUG_BUILD
    Mix_ReserveChannels(need_to_reserve)
#endif
#define RESERVE_CHANS_COMMAND Mix_ReserveChannels(need_to_reserve)
    D_pLogDebug("Loading of sounds passed in %d milliseconds", static_cast<int>(loadingTime.elapsed()));
    D_pLogDebug("Reserved audio channels: %d", RESERVE_CHANS_COMMAND);
    D_pLogDebug("SFX Index entries: %d", main_sfx_index.size());
#undef RESERVE_CHANS_COMMAND
    SDL_ClearError();
}
Example #5
0
int main()
{
    //cout << FileFormats::WriteExtendedLvlFile(FileFormats::dummyLvlDataArray()) << endl;
    LevelData level;
    printLine();
    cout << "\n\nSMBX64 Level Read Header test:" << endl;
    FileFormats::ReadSMBX64LvlFileHeader("test.lvl", level);
    cout << level.meta.filename << "\n";
    cout << level.meta.path << "\n";
    if(!level.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printLevelInfo(level);
    }
    printLine();

    cout << "\n\nSMBX64 Level Read test:" << endl;
    FileFormats::OpenLevelFile("test.lvl", level);
    cout << level.meta.filename << "\n";
    cout << level.meta.path << "\n";
    if(!level.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printLevelInfo(level);
    }

    FileFormats::SaveLevelFile(level, "test_out_64.lvl", FileFormats::LVL_SMBX64, 64);
    FileFormats::SaveLevelFile(level, "test_out_45.lvl", FileFormats::LVL_SMBX64, 45);
    FileFormats::SaveLevelFile(level, "test_out_1.lvl", FileFormats::LVL_SMBX64, 1);


    printLine();
    cout << "\n\nSMBX65-38A Level Read Header test:" << endl;
    FileFormats::ReadSMBX38ALvlFileHeader("test_65-38a.lvl", level);
    cout << level.meta.filename << "\n";
    cout << level.meta.path << "\n";
    if(!level.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printLevelInfo(level);
    }



    printLine();
    cout << "\n\nSMBX65-38A Level Read test:" << endl;
    FileFormats::OpenLevelFile("test_65-38a.lvl", level);
    cout << level.meta.filename << "\n";
    cout << level.meta.path << "\n";
    if(!level.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printLevelInfo(level);
    }



    printLine();
    cout << "\n\nPGE-X Level Read Header test:" << endl;
    FileFormats::ReadExtendedLvlFileHeader("test.lvlx", level);
    cout << level.meta.filename << "\n";
    cout << level.meta.path << "\n";
    if(!level.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printLevelInfo(level);
    }

    printLine();
    cout << "\n\nPGE-X Level Read test:" << endl;
    FileFormats::OpenLevelFile("test.lvlx", level);
    cout << level.meta.filename << "\n";
    cout << level.meta.path << "\n";
    if(!level.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printLevelInfo(level);
    }

    FileFormats::smbx64LevelPrepare(level);
    FileFormats::smbx64LevelSortBlocks(level);
    FileFormats::smbx64LevelSortBGOs(level);

    FileFormats::WriteExtendedLvlFileF("test_out.lvlx", level);


    WorldData world;
    printLine();
    cout << "\n\nSMBX64 World Read Header test:" << endl;
    FileFormats::ReadSMBX64WldFileHeader("test.wld", world);
    cout << world.meta.filename << "\n";
    cout << world.meta.path << "\n";
    if(!world.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printWorldInfo(world);
    }

    printLine();
    cout << "\n\nSMBX64 World Read test:" << endl;
    FileFormats::OpenWorldFile("test.wld", world);
    cout << world.meta.filename << "\n";
    cout << world.meta.path << "\n";
    if(!world.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printWorldInfo(world);
    }

    FileFormats::WriteSMBX64WldFileF("test_out_64.wld", world, 64);

    printLine();
    cout << "\n\nPGE-X World Read Header test:" << endl;
    FileFormats::ReadExtendedWldFileHeader("test.wldx", world);
    cout << world.meta.filename << "\n";
    cout << world.meta.path << "\n";
    if(!world.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printWorldInfo(world);
    }

    printLine();
    cout << "\n\nPGE-X World Read test:" << endl;
    FileFormats::OpenWorldFile("test.wldx", world);
    cout << world.meta.filename << "\n";
    cout << world.meta.path << "\n";
    if(!world.meta.ReadFileValid)
    {
        cout << "Invalid file\n" << FileFormats::errorString;
    } else {
        printWorldInfo(world);
    }

    FileFormats::WriteExtendedWldFileF("test_out.wldx", world);

    PGE_FileFormats_misc::FileInfo x("shit.txt");
    cout << "\n\n\n";
    cout << "Name: " << x.filename() << endl;
    cout << "FPat: " << x.fullPath() << endl;
    cout << "BNam: " << x.basename() << endl;
    cout << "Sufx: " << x.suffix() << endl;
    cout << "Dirt: " << x.dirpath() << endl;



    //Deep tests of the level file formats
    #define ENABLE_SMBX64_DEEPTEST
    #define ENABLE_SMBX38A_DEEPTEST
    #define ENABLE_PGEX_DEEPTEST //required SMBX64 deeptest to pre-generate LVLX files!

    #ifdef ENABLE_SMBX64_DEEPTEST
    /**********************DEEP TEST OF SMBX64 files*********************/
    {
        //#define GENERATE_LVLX_FILES
        cout << "==================DEEP TEST OF SMBX64==================\n";
        std::string path = "../PGEFileLib_test_files/smbx64/";
        std::string wpath = "../PGEFileLib_test_files/smbx64_out/";
        #ifdef GENERATE_LVLX_FILES
        QString xpath = "../PGEFileLib_test_files/pgex/";
        #endif
        TheDir testDir(path);
        testDir.mkdir("../smbx64_out/");
        #ifdef GENERATE_LVLX_FILES
        testDir.mkdir("../pgex/");
        #endif
        vector<string> files = testDir.entryList();

        std::ofstream niout;
        niout.open("invalid_s64.log", std::ios::out);

        std::ofstream timesout;
        timesout.open("times_s64.log", std::ios::out);

        ElapsedTimer meter;
        meter.start();

        for(size_t i=0; i<files.size(); i++)
        {
            std::string file = files[i];
            PGE_FileFormats_misc::TextFileInput fileI(path+file, false);
            LevelData FileDataNew;

            FileDataNew = FileFormats::CreateLevelData();
            fileI.seek(0, PGE_FileFormats_misc::TextInput::begin);

            meter.restart();
            if(FileFormats::ReadSMBX64LvlFile(fileI, FileDataNew))
            {
                clock_t got = meter.elapsed();
                timesout << flString(file, 30) << " READ -> " << flString(std::to_string(got), 20);

                meter.restart();
                FileFormats::smbx64LevelPrepare(FileDataNew);
                FileFormats::WriteSMBX64LvlFileF(wpath+file, FileDataNew, FileDataNew.meta.RecentFormatVersion);
                got = meter.elapsed();
                timesout << " WRITE -> " << got << "\n";
                timesout.flush();
                #ifdef GENERATE_LVLX_FILES
                FileFormats::WriteExtendedLvlFileF(xpath+file+"x", FileDataNew);
                #endif
            } else {
                cout << "NEW PARSER FAILED: Invalid file\n" << FileFormats::errorString;
                niout << path+file << "\r\nInfo: "
                      << FileDataNew.meta.ERROR_info << "\r\nlinedata" << FileDataNew.meta.ERROR_linedata
                      << "\r\nline:" << FileDataNew.meta.ERROR_linenum << "\r\n\r\n";
                niout.flush();
            }
            cout.flush();
        }
        niout.close();
        cout << "==================DEEP TEST OF SMBX64=END==============\n";
        cout.flush();
    }
    /*********************************************************************/
    #endif //ENABLE_SMBX64_DEEPTEST

    #ifdef ENABLE_SMBX38A_DEEPTEST
    /**********************DEEP TEST OF SMBX38A files*********************/
    {
        cout << "==================DEEP TEST OF SMBX38A==================\n";
        std::string path = "../PGEFileLib_test_files/smbx38a/";
        string opath = "../PGEFileLib_test_files/smbx38a_lvlx_diffs/";
        string wpath = "../PGEFileLib_test_files/smbx38a_out/";
        TheDir testDir(path);
        testDir.mkdir("../smbx38a_lvlx_diffs");
        testDir.mkdir("../smbx38a_out");
        vector<string> files = testDir.entryList();

        std::ofstream niout;
        niout.open("invalid_new.log", std::ios::out);

        std::ofstream  oiout;
        oiout.open("invalid_old.log", std::ios::out);

        std::ofstream diout;
        diout.open("differents.log", std::ios::out);

        std::ofstream timesout;
        timesout.open("times.log", std::ios::out);

        ElapsedTimer meter;
        meter.start();

        for(int i=0; i<(signed)files.size(); i++)
        {
            std::string file=files[i];
            PGE_FileFormats_misc::TextFileInput fileI(path+file, false);
            string raw_old;
            string raw_new;
            LevelData FileDataNew;
            LevelData FileDataOld;

            clock_t time_old=0;
            clock_t time_new=0;

            FileDataNew = FileFormats::CreateLevelData();
            fileI.seek(0, PGE_FileFormats_misc::TextInput::begin);

            meter.restart();
            if(FileFormats::ReadSMBX38ALvlFile(fileI, FileDataNew))
            {
                clock_t got = meter.elapsed();
                time_new=got;
                timesout << flString(file, 30) << " NEW -> " <<  flString(std::to_string(got), 20);
                FileFormats::smbx64CountStars( FileDataNew );
                meter.restart();
                FileFormats::WriteExtendedLvlFileRaw(FileDataNew, raw_new);
                got = meter.elapsed();
                timesout << " WRITE -> " << flString(std::to_string(got), 20);

                FileFormats::WriteSMBX38ALvlFileF(wpath+file, FileDataNew);
            } else {
                cout << "NEW PARSER FAILED: Invalid file\n" << FileFormats::errorString;
                niout << path+file << "\r\nInfo: "
                      << FileDataNew.meta.ERROR_info << "\r\nlinedata" << FileDataNew.meta.ERROR_linedata
                      << "\r\nline:" << FileDataNew.meta.ERROR_linenum << "\r\n\r\n";
                niout.flush();
            }

            FileDataOld = FileFormats::CreateLevelData();
            fileI.close();

            fileI.open(path+file, false);
            meter.restart();
            if(FileFormats::ReadSMBX38ALvlFile_OLD(fileI, FileDataOld))
            {
                clock_t got = meter.elapsed();
                time_old=got;
                timesout << " OLD -> " << flString(std::to_string(got), 20);
                if(time_old>time_new)
                    timesout << " NEW READS FASTER";
                else if(time_old<time_new)
                    timesout << " OLD READS FASTER";
                else
                    timesout << " BOTH ARE SAME";
                timesout << "\n";
                FileFormats::smbx64CountStars( FileDataOld );
                FileFormats::WriteExtendedLvlFileRaw(FileDataOld, raw_old);
            } else {
                cout << "OLD PARSER FAILED: Invalid file\n" << FileFormats::errorString;
                oiout << path+file << "\r\nInfo: "
                      << FileDataOld.meta.ERROR_info << "\r\nlinedata" << FileDataOld.meta.ERROR_linedata
                      << "\r\nline:" << FileDataOld.meta.ERROR_linenum << "\r\n\r\n";
                oiout.flush();
            }

            if(raw_old.empty())
                continue;
            if(raw_new.empty())
                continue;
            if(raw_old != raw_new)
            {
                cout << "FILES ARE DIFFERENT\n";
                diout << path+file << "\r\n";
                diout.flush();
                FileFormats::WriteExtendedLvlFileF(opath+file+".old.lvlx", FileDataNew);
                FileFormats::WriteExtendedLvlFileF(opath+file+".new.lvlx", FileDataOld);
            } else {
                //Remove similar files!
                //QFile(opath+file+".old.lvlx").remove();
                //QFile(opath+file+".new.lvlx").remove();
            }
            cout.flush();
        }
        oiout.close();
        niout.close();
        diout.close();
        cout << "==================DEEP TEST OF SMBX38A=END==============\n";
        cout.flush();
    }
    /*********************************************************************/
    #endif//ENABLE_SMBX38A_DEEPTEST


    #if defined(ENABLE_SMBX64_DEEPTEST) && defined(ENABLE_PGEX_DEEPTEST)
    /**********************DEEP TEST OF PGE-X files*********************/
    {
        cout << "==================DEEP TEST OF PGE-X==================\n";
        string path = "../PGEFileLib_test_files/pgex/";
        string wpath = "../PGEFileLib_test_files/pgex_out/";
        TheDir testDir(path);
        testDir.mkdir("../pgex_out");
        vector<string> files = testDir.entryList();

        std::ofstream niout;
        niout.open("invalid_pgex.log", std::ios::out);

        std::ofstream timesout;
        timesout.open("times_pgex.log", std::ios::out);

        ElapsedTimer meter;
        meter.start();

        for(size_t i=0; i<files.size(); i++)
        {
            string file=files[i];
            PGE_FileFormats_misc::TextFileInput fileI(path+file, false);
            LevelData FileDataNew;

            FileDataNew = FileFormats::CreateLevelData();
            fileI.seek(0, PGE_FileFormats_misc::TextInput::begin);

            meter.restart();
            if(FileFormats::ReadExtendedLvlFile(fileI, FileDataNew))
            {
                clock_t got = meter.elapsed();
                timesout << flString(file, 30) << " READ -> " << flString(std::to_string(got), 20);

                meter.restart();
                FileFormats::smbx64CountStars( FileDataNew );
                FileFormats::WriteExtendedLvlFileF(wpath+file, FileDataNew);
                got = meter.elapsed();
                timesout << " WRITE -> " << got << "\n";
                timesout.flush();

            } else {
                cout << "NEW PARSER FAILED: Invalid file\n" << FileFormats::errorString;
                niout << path+file << "\r\nInfo: "
                      << FileDataNew.meta.ERROR_info << "\r\nlinedata" << FileDataNew.meta.ERROR_linedata
                      << "\r\nline:" << FileDataNew.meta.ERROR_linenum << "\r\n\r\n";
                niout.flush();
            }
            cout.flush();
        }
        niout.close();
        cout << "==================DEEP TEST OF PGE-X=END==============\n";
        cout.flush();
    }
    /*********************************************************************/
    #endif

    cout << "!!!!!!!!!!!!!!!!!!!!!EVERYTHING HAS BEEN DONE!!!!!!!!!!!!!!!!!!!!!\n";


    return 0;
}
Example #6
0
void CPageDocuments::DisplayFactory(int index)
{
  assert(index >= 0 && index < FACTORY_BUILDINGS_MAX);
  CString info;
  m_list.DeleteAllItems();
  DeleteAllColumns();
  m_list.InsertColumn(0 , "等级" , LVCFMT_LEFT , 40);
  m_list.InsertColumn(1 , "升级金属" , LVCFMT_LEFT , 90);
  m_list.InsertColumn(2 , "升级晶体" , LVCFMT_LEFT , 90);
  m_list.InsertColumn(3 , "升级重氢" , LVCFMT_LEFT , 90);
  m_list.InsertColumn(4 , "产生能量" , LVCFMT_LEFT , 90);
  m_list.InsertColumn(5 , "升级时间" , LVCFMT_LEFT , 100); 
  m_list.InsertColumn(6 , "生产金属" , LVCFMT_LEFT , 90); 
  m_list.InsertColumn(7 , "生产晶体" , LVCFMT_LEFT , 90); 
  m_list.InsertColumn(8 , "生产重氢" , LVCFMT_LEFT , 90); 
  for(int i = 0 ; i < MAX_LEVEL ; ++i)
  {
    info.Format("%d" , i);
    m_list.InsertItem(i , info);
    double m = 0.0;
    double c = 0.0;
    double d = 0.0;

    if(index > FACTORY_BUILDING_PRODUCE_MAX)
    {
      m = get_other_factory_upgrade_resource(FACTORY_DATA[index][FACTORY_TBL_N_METAL] , i);
      c = get_other_factory_upgrade_resource(FACTORY_DATA[index][FACTORY_TBL_N_CRYSTAL] , i);
      d = get_other_factory_upgrade_resource(FACTORY_DATA[index][FACTORY_TBL_N_DIPLOGEN] , i);
    }
    else
    {
      m = get_produce_factory_upgrade_resource(FACTORY_DATA[index][FACTORY_TBL_N_METAL] , i);
      c = get_produce_factory_upgrade_resource(FACTORY_DATA[index][FACTORY_TBL_N_CRYSTAL] , i);
      d = get_produce_factory_upgrade_resource(FACTORY_DATA[index][FACTORY_TBL_N_DIPLOGEN] , i);
    }
    //metal
    info.Format("%.0f" ,  m);
    m_list.SetItemText(i , 1 , info);

    //crystal
    info.Format("%.0f" ,  c);
    m_list.SetItemText(i , 2 , info);

    //diplogen
    info.Format("%.0f" ,  d);
    m_list.SetItemText(i , 3 , info);

    //sun power factory
    int p = get_produce_factory_consume_power(FACTORY_DATA[index][FACTORY_TBL_POWER] , i , 1.0);
    info.Format("%d" , p );
    if(index != FACTORY_BUILDING_SUNPOWER && p != 0)
    { 
      info.Format("-%d" , p );
    }
    m_list.SetItemText(i , 4 , info);

    //time
    double t = get_factory_upgrade_seconds(GetDataPtr()->GetBuildingLevel(FACTORY_BUILDING_ROBOT) , GetDataPtr()->GetBuildingLevel(FACTORY_BUILDING_NANITE) , m , c , 1.0);
    ElapsedTimer timer;
    timer.Init(t);
    m_list.SetItemText(i , 5 , timer.ToCString());

    //produce metal
    ulong a = 0;
    if(index == FACTORY_BUILDING_MINAL)
      a = 20;
    m = get_produce_factory_produce_resource_per_minute(a , FACTORY_DATA[index][FACTORY_TBL_P_METAL] , i , 1.0 , 1.0) * 
      pow(2 , GetDataPtr()->GET_STAR_DOUBLE_RES_HERO());
    info.Format("%.0f" , m * 60);
    m_list.SetItemText(i , 6 , info);

    //produce crystal
    a = 0;
    if(index == FACTORY_BUILDING_CRYSTAL)
      a = 10;
    c = get_produce_factory_produce_resource_per_minute(a , FACTORY_DATA[index][FACTORY_TBL_P_CRYSTAL] , i , 1.0 , 1.0) * 
      pow(2 , GetDataPtr()->GET_STAR_DOUBLE_RES_HERO());
    info.Format("%.0f" , c * 60);
    m_list.SetItemText(i , 7 , info);

    //produce diplogen
    d = (-0.002 * GetDataPtr()->STAR_TEMP() + 1.28 ) * 
      get_produce_factory_produce_resource_per_minute(0 , FACTORY_DATA[index][FACTORY_TBL_P_DIPLOGEN] , i , 1.0 , 1.0) * 
      pow(2 , GetDataPtr()->GET_STAR_DOUBLE_RES_HERO());
    info.Format("%.0f" , d * 60);
    m_list.SetItemText(i , 8 , info);
  }
  m_list.SetItemBkColor(Buildings_Entry(index)->GetLevel() , -1 , RGB(0 , 255 , 0));
}