NEON_API int application_exec(const char *title, APP_STATE *states, size_t states_n) { allstates = states; states_num = states_n; if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { LOG_ERROR("%s\n", SDL_GetError()); return EXIT_FAILURE; } atexit(SDL_Quit); if (TTF_Init() < 0) { LOG_ERROR("%s\n", TTF_GetError()); return EXIT_FAILURE; } atexit(TTF_Quit); if ((states_stack = new_stack(sizeof(APP_STATE), states_n + 1)) == NULL) { LOG_ERROR("%s\n", "Can\'t create game states stack"); return EXIT_FAILURE; } LOG("%s launched...\n", title); LOG("Platform: %s\n", SDL_GetPlatform()); video_init(title); audio_init(); atexit(application_cleanup); application_next_state(0); if (is_stack_empty(states_stack)) { LOG_CRITICAL("%s\n", "No game states"); exit(EXIT_FAILURE); } SDL_Event event; Uint64 current = 0; Uint64 last = 0; float accumulator = 0.0f; while(running) { frame_begin(); while(SDL_PollEvent(&event)) { ((APP_STATE*)top_stack(states_stack))->on_event(&event); } asset_process(); resources_process(); last = current; current = SDL_GetPerformanceCounter(); Uint64 freq = SDL_GetPerformanceFrequency(); float delta = (double)(current - last) / (double)freq; accumulator += CLAMP(delta, 0.f, 0.2f); while(accumulator >= TIMESTEP) { accumulator -= TIMESTEP; ((APP_STATE*)top_stack(states_stack))->on_update(TIMESTEP); } ((APP_STATE*)top_stack(states_stack))->on_present(screen.width, screen.height, accumulator / TIMESTEP); video_swap_buffers(); frame_end(); SDL_Delay(1); } return EXIT_SUCCESS; }
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; }