void Helpers::init(void) { initConfig(); prepareCache(); initPython(); }
int main() { _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // direction for player auto-moving int direction = ObjectWay::undefined; // init logic configuration Config config; initConfig(&config); // init render object Render* render = new Render(config.screen_width, config.screen_height); if(!render->init()) { delete render; return EXIT_FAILURE; } // init logic object Logic* logic = new Logic(); logic->flush(config); logic->init(config); sf::Clock clock; sf::Event event; while (render->getWindow()->isOpen()) { sf::Int32 msec = clock.getElapsedTime().asMilliseconds(); logic->setTime(msec); // check in loop for events while(render->getWindow()->pollEvent(event)) { if(event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) render->close(); if(event.type == sf::Event::KeyReleased) if (event.key.code == sf::Keyboard::Right || event.key.code == sf::Keyboard::Left) direction = ObjectWay::undefined; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) logic->spawnRocket(); // launch rocket if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) direction = ObjectWay::right; if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) direction = ObjectWay::left; if(direction != ObjectWay::undefined) { ObjectPosition pos = logic->getPlayer().position; if(direction == ObjectWay::right) pos.x += config.speed_player; else pos.x -= config.speed_player; if(pos.x > 0 && pos.x < (float)config.screen_width-25.0f) logic->setPlayerPosition(pos); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return) && logic->getLifes() <= 0) { logic->clearObjects(); logic->flush(config); } } // clear screen render->clear(); if(logic->getLifes() > 0) { if(logic->getEnemiesCount() == 0) { // set new round and respawn enemies logic->setNewRound(); logic->spawnEnemies(0.0f, 40.f, 10, 3); } logic->spawnBomb(); // fire bomb randomly logic->moveEnemies(); // move enemies logic->moveRockets(); // move rockets logic->moveBombs(); // move bombs logic->collideEnemies(); // collide with enemies logic->collideRockets(); // collide with rockets logic->collideBombs(); // collide with bombs // draw logic objects drawObjects(logic, render); } else { // logic is over, draw score render->drawFarewell(logic->getScore()); logic->clearObjects(); } // render screen render->display(); } delete logic; delete render; return EXIT_SUCCESS; }
Common::Error HugoEngine::run() { s_Engine = this; initGraphics(320, 200, false); _mouse = new MouseHandler(this); _inventory = new InventoryHandler(this); _route = new Route(this); _sound = new SoundHandler(this); // Setup mixer syncSoundSettings(); _text = new TextHandler(this); _topMenu = new TopMenu(this); switch (_gameVariant) { case kGameVariantH1Win: // H1 Win _file = new FileManager_v1w(this); _scheduler = new Scheduler_v1w(this); _intro = new intro_v1w(this); _screen = new Screen_v1w(this); _parser = new Parser_v1w(this); _object = new ObjectHandler_v1w(this); _normalTPS = 9; break; case kGameVariantH2Win: _file = new FileManager_v2w(this); _scheduler = new Scheduler_v1w(this); _intro = new intro_v2w(this); _screen = new Screen_v1w(this); _parser = new Parser_v1w(this); _object = new ObjectHandler_v1w(this); _normalTPS = 9; break; case kGameVariantH3Win: _file = new FileManager_v2w(this); _scheduler = new Scheduler_v1w(this); _intro = new intro_v3w(this); _screen = new Screen_v1w(this); _parser = new Parser_v1w(this); _object = new ObjectHandler_v1w(this); _normalTPS = 9; break; case kGameVariantH1Dos: // H1 DOS _file = new FileManager_v1d(this); _scheduler = new Scheduler_v1d(this); _intro = new intro_v1d(this); _screen = new Screen_v1d(this); _parser = new Parser_v1d(this); _object = new ObjectHandler_v1d(this); _normalTPS = 8; break; case kGameVariantH2Dos: _file = new FileManager_v2d(this); _scheduler = new Scheduler_v2d(this); _intro = new intro_v2d(this); _screen = new Screen_v1d(this); _parser = new Parser_v2d(this); _object = new ObjectHandler_v2d(this); _normalTPS = 8; break; case kGameVariantH3Dos: _file = new FileManager_v3d(this); _scheduler = new Scheduler_v3d(this); _intro = new intro_v3d(this); _screen = new Screen_v1d(this); _parser = new Parser_v3d(this); _object = new ObjectHandler_v3d(this); _normalTPS = 9; break; } if (!loadHugoDat()) return Common::kUnknownError; // Use Windows-looking mouse cursor _screen->setCursorPal(); _screen->resetInventoryObjId(); _scheduler->initCypher(); initStatus(); // Initialize game status initConfig(); // Initialize user's config if (!_status._doQuitFl) { initialize(); resetConfig(); // Reset user's config initMachine(); // Start the state machine _status._viewState = kViewIntroInit; int16 loadSlot = Common::ConfigManager::instance().getInt("save_slot"); if (loadSlot >= 0) { _status._skipIntroFl = true; _file->restoreGame(loadSlot); } else { _file->saveGame(0, "New Game"); } } while (!_status._doQuitFl) { _screen->drawBoundaries(); g_system->updateScreen(); runMachine(); // Handle input Common::Event event; while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: _parser->keyHandler(event); break; case Common::EVENT_MOUSEMOVE: _mouse->setMouseX(event.mouse.x); _mouse->setMouseY(event.mouse.y); break; case Common::EVENT_LBUTTONUP: _mouse->setLeftButton(); break; case Common::EVENT_RBUTTONUP: _mouse->setRightButton(); break; case Common::EVENT_QUIT: _status._doQuitFl = true; break; default: break; } } if (_status._helpFl) { _status._helpFl = false; _file->instructions(); } _mouse->mouseHandler(); // Mouse activity - adds to display list _screen->displayList(kDisplayDisplay); // Blit the display list to screen _status._doQuitFl |= shouldQuit(); // update game quit flag } return Common::kNoError; }
int main(int argc, char *argv[]) { struct configOption *confOpt; char tmpstr[ALLOW_PATH_SIZE] = {""}; pthread_t ntid; g_logdir = NULL; g_logF = stderr; g_logFInt = STDERR_FILENO; setlocale(LC_ALL,""); zmalloc_enable_thread_safeness(); snprintf(tmpstr, ALLOW_PATH_SIZE, "%s/../", argv[0]); if (NULL == realpath(tmpstr, g_basedir)) { trvExit(0, "获取当前路径失败"); } g_conf = initConfig(); snprintf(tmpstr, ALLOW_PATH_SIZE, "%s/../conf/default.conf", g_basedir); configRead(g_conf, tmpstr); if (argc > 1) configRead(g_conf, argv[1]); /* argv[1] 是配置文件路径 */ if (NULL == g_conf->contents) { trvExit(0, "请选择配置文件"); } confOpt = configGet(g_conf, "log", "dir"); if (confOpt) { g_logdir = (char *)zmalloc(confOpt->valueLen+1); memcpy(g_logdir, confOpt->value, confOpt->valueLen); g_logdir[confOpt->valueLen] = 0x00; g_logF = fopen(g_logdir, "a+"); g_logFInt = fileno(g_logF); } signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); setupSignalHandlers(); /** * 主线程睡眠,等待网络就绪 * 单独开一个线程处理网路 */ pthread_mutex_lock(&g_rootThreadMutex); pthread_create(&ntid, NULL, _NTInit, NULL); pthread_cond_wait(&g_rootThreadCond, &g_rootThreadMutex); pthread_mutex_unlock(&g_rootThreadMutex); _STInitPlanet(NULL); /* 主线程睡眠,避免退出进程 */ pthread_cond_wait(&g_rootThreadCond, &g_rootThreadMutex); pthread_mutex_unlock(&g_rootThreadMutex); return 0; }
JudgeConfig::JudgeConfig(const char* sFilePath) : m_config_file(sFilePath) { initConfig(); }
//--------------------------------------------------------------------------- void procArguments(int argc, char** argv) { const char* configFilename = NULL; int listenPort = -1; TinyString logLevel; bool debugMode = false; int c; while ((c = getopt(argc, argv, ":hdl:p:")) != -1) { switch(c) { case 'd': debugMode = true; break; case 'p': listenPort = atoi(optarg); break; case 'l': logLevel = optarg; break; case ':': printf("-%c is need more value\n", optopt); helpMsg(argv[0]); exit(0); break; case '?': if(optopt == '-') { if(strcmp(argv[optind-1], "--help") == 0) { helpMsg(argv[0]); exit(0); } } else { printf("Unknown arg %c\n", optopt); helpMsg(argv[0]); exit(0); } case 'h': helpMsg(argv[0]); exit(0); default: helpMsg(argv[0]); exit(0); } } if(optind < argc) { configFilename = argv[optind]; optind++; } if(configFilename == NULL) configFilename = defaultConfigFilename; if(initConfig(configFilename) < 0) { printf("컨피그 파일의 존재 및 설정값을 다시 확인해 주세요.\n"); exit(0); } if(debugMode) { Config::instance()->process.daemon = false; Config::instance()->log.outputType = LOT_STDOUT; Config::instance()->log.level = LLT_MEDIUM; } if(!logLevel.isEmpty()) { if(logLevel == "HIGH" || logLevel=="4") { Config::instance()->log.level = LLT_HIGH; } else if(logLevel == "MEDIUM" || logLevel=="3") { Config::instance()->log.level = LLT_MEDIUM; } else if(logLevel == "LOW" || logLevel=="2") { Config::instance()->log.level = LLT_LOW; } else if(logLevel == "VERYLOW" || logLevel == "1") { Config::instance()->log.level = LLT_VERYLOW; } } if(listenPort > 0) Config::instance()->network.listenPort = listenPort; }