Пример #1
0
void level_processing()
{
    uint32_t modifyTime = 0;
    StringArray level_file_list;
    std::string folder = remove_top_folder(g_config->m_inputDir);
    scan_dir(level_file_list, g_config->m_inputDir.c_str(), EngineNames::LEVEL, SCAN_FILES, true);

    LOGI("level file num = %d", level_file_list.size());
    for (size_t i=0; i<level_file_list.size(); ++i)
    {
        LOGI("level %s", level_file_list[i].c_str());
    }

    for (size_t i=0; i<level_file_list.size(); ++i)
    {
        const std::string& input = level_file_list[i];
        std::string output = input_to_output(input);
        if(!g_config->is_file_changed(input, modifyTime) && isFileExist(output))
            continue;
        LevelCompiler* level = new LevelCompiler;
        g_config->m_levels.push_back(level);
        level->m_input = input;
        level->m_output = output;
        level->m_modifyTime = modifyTime;
        level->preProcess();
        level->go();
    }
}
Пример #2
0
void resources_process()
{
    StringArray input_file_list;
    scan_dir(input_file_list, g_config->m_inputDir.c_str(), "*", SCAN_FILES, true);

    LOGI("input file num = %d.", input_file_list.size());
    bool shaderIncludedAdded = false;

    for (size_t i=0; i<input_file_list.size(); ++i)
    {
        const std::string& input = input_file_list[i];
        std::string ext = getFileExt(input);
        if(ext == EngineNames::LEVEL)
            continue;
        BaseCompiler* compiler = g_config->create_compiler(ext);
        if(!compiler)
        {
            LOGW("can not find any compiler for this resource %s.", input.c_str());
            continue;
        }
        std::string output = input_to_output(input);
        if(ext == "dds") output =
            replaceExtension(output, EngineNames::TEXTURE);
        compiler->m_input = input;
        compiler->m_output = output;
        if(!compiler->checkProcessing())
        {
            delete compiler;
            continue;
        }
        LOGI("data compile %s --> %s", input.c_str(), output.c_str());
        g_config->m_compilers.push_back(compiler);
    }
    for(size_t i=0; i<g_config->m_compilers.size(); ++i)
    {
        g_config->m_compilers[i]->preProcess();
    }
}
Пример #3
0
int main(int argc, char *argv[])
{
	int iOS = 0;
	char *pInputFile = NULL;
	char *pOutputFile = NULL;

	/*      Figure out arguments.
	 *      [REQUIRED] First argument is input file.
	 *      [OPTIONAL] Second argument is output file.
	 */
	if(argc > 1)    {
		FILE *pInputStream = NULL;
		FILE *pOutputStream = NULL;

		/*      Form respective filenames.
		 */
		pInputFile = input_filename(argv[1]);
		pOutputFile = output_filename(pInputFile, argc > 2 ? argv[2] : NULL);

		if(pInputFile == NULL)  {
			fprintf(stderr, "MANTOMAK:  Unable to form input filename\n");
			iOS = 1;
		}
		else    {
			pInputStream = fopen(pInputFile, "rb");
			if(pInputStream == NULL)        {
				fprintf(stderr, "MANTOMAK:  Unable to open input file %s\n", pInputFile);
				iOS = 1;
			}
		}
		if(pOutputFile == NULL) {
			fprintf(stderr, "MANTOMAK:  Unable to form output filename\n");
			iOS = 1;
		}
		else if(pInputStream != NULL)   {
			pOutputStream = fopen(pOutputFile, "wt");
			if(pOutputStream == NULL)       {
				fprintf(stderr, "MANTOMAK:  Unable to open output file %s\n", pOutputFile);
				iOS = 1;
			}
		}

		/*      Only do the real processing if our error code is not
		 *              already set.
		 */
		if(iOS == 0)    {
			iOS = input_to_output(pInputStream, pOutputStream);
		}

		if(pInputStream != NULL)        {
			fclose(pInputStream);
			pInputStream = NULL;
		}
		if(pOutputStream != NULL)       {
			fclose(pOutputStream);
			pOutputStream = NULL;
		}
	}
	else    {
		help();
		iOS = 1;
	}

	if(pInputFile)  {
		free(pInputFile);
		pInputFile = NULL;
	}
	if(pOutputFile) {
		free(pOutputFile);
		pOutputFile = NULL;
	}

	return(iOS);
}
Пример #4
0
int data_compiler_main(bx::CommandLine* cmdline)
{
    delete_file(DC_RESULT);

    int err = kErrorSuccess;
    uint32_t timeMS = ::GetTickCount();

    LOG_INIT("DataCompilerLog.html", "Data Compiler");
    MemoryConfig cfg;
    memset(&cfg, 0, sizeof cfg);
    cfg.m_debugMemSize = SIZE_MB(2);
    g_memoryMgr.init(cfg);

#ifdef DC_DUMP_PROFILE
    g_profiler.init(TOTAL_BLOCK_NUM);
#endif

    register_engine_factories();

    g_config = new DC_Config;
    const char* inputChar = cmdline->findOption('i');
    if(!inputChar) inputChar = "intermediate";
    const char* outputFolderChar = cmdline->findOption('o');
    if(!outputFolderChar) outputFolderChar = "data";
    const char* threadChar = cmdline->findOption('t');
    if(threadChar) g_config->m_numThreads = atoi(threadChar);
    g_config->m_ignoreTextures = cmdline->hasArg("ignore_texture");
    g_config->m_slient = cmdline->hasArg("slient");
    g_config->m_bundled = cmdline->hasArg("bundle");
    g_config->m_forceRecompile = cmdline->hasArg('b');

    create_folder("data");
    g_config->m_database.load(DC_DATABASE);

    g_config->m_inputDir = inputChar;
    string_replace(g_config->m_inputDir, "\\", "/");
    add_trailing_slash(g_config->m_inputDir);
    g_config->m_topFolder = get_top_folder(g_config->m_inputDir);
    g_config->m_outputDir = input_to_output(g_config->m_inputDir);

    ENGINE_ASSERT(g_config->m_topFolder.length(), "top folder error.");
    string_replace(g_config->m_outputDir, "\\", "/");
    add_trailing_slash(g_config->m_outputDir);
    std::string secondFolder = remove_top_folder(g_config->m_outputDir);
    if(secondFolder.length()) g_config->m_packageName = get_top_folder(secondFolder);
    LOGI("input = %s, output = %s, top-folder = %s, package-name=%s",
        g_config->m_inputDir.c_str(),
        g_config->m_outputDir.c_str(),
        g_config->m_topFolder.c_str(),
        g_config->m_packageName.c_str());

    level_processing();
    resources_process();
    if(g_config->m_compilers.size() < 10) g_config->m_numThreads = 0;
    if(g_config->m_numThreads < 2)
    {
        for(size_t i=0; i<g_config->m_compilers.size(); ++i)
        {
            g_config->m_compilers[i]->go();
        }
    }
    else
    {
        const int maxThreads = 8;
        if(g_config->m_numThreads > maxThreads) g_config->m_numThreads = maxThreads;
        uint32_t totalNum = g_config->m_compilers.size();
        uint32_t numPerThread = totalNum / g_config->m_numThreads + 1;
        bx::Thread* threads[maxThreads];
        std::vector<BaseCompiler*> compilers[maxThreads];
        uint32_t currIndex = 0;

        for (int i=0; i<g_config->m_numThreads; ++i)
        {
            uint32_t elementNum = numPerThread;
            uint32_t numLeft = totalNum - currIndex;
            if(numLeft < elementNum) elementNum = numLeft;
            if(elementNum == 0) continue;
            std::vector<BaseCompiler*>& comArray = compilers[i];
            comArray.resize(elementNum);
            memcpy(&comArray[0], &g_config->m_compilers[currIndex], elementNum*sizeof(void*));
            currIndex += elementNum;
            if(i == 0) continue;
            threads[i] = new bx::Thread();
            threads[i]->init(thread_compile, &comArray);
        }
        //main thread with other threads.
        thread_compile(&compilers[0]);
        for (int i=1; i<g_config->m_numThreads; ++i)
        {
            delete threads[i];
        }
    }
    g_config->post_process();
    package_processing();

    timeMS = ::GetTickCount() - timeMS;
    if(!g_config->m_slient) g_config->m_error.show_error();
    g_config->m_database.save(DC_DATABASE);
    g_config->m_database.m_files.clear();
    SAFE_DELETE(g_config);

#ifdef DC_DUMP_PROFILE
    g_profiler.dump_to_file("data_compiler_profile.txt", true, true);
    g_profiler.shutdown();
#endif

    g_memoryMgr.shutdown();

    LOGD("******************************************************");
    LOGD("******************************************************");
    LOGD("* TOTAL TIME COST = %d[MS] *", timeMS);
    LOGD("******************************************************");
    LOGD("******************************************************");
    LOG_TERM();

	return err;
}