本文整理汇总了C++中Stage::addEventHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ Stage::addEventHandler方法的具体用法?C++ Stage::addEventHandler怎么用?C++ Stage::addEventHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stage
的用法示例。
在下文中一共展示了Stage::addEventHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runNewMatch
//.........这里部分代码省略.........
engine_ = 0;
}
if (restarting_) {
stageConsole_->clear();
guiPrintHandler_->restartMode();
} else {
destroyStageConsole();
stageConsole_ = new OutputConsole(stageName, CONSOLE_SHIP_STAGE,
menuBarMaker_);
stageConsole_->Hide();
if (guiPrintHandler_ != 0) {
delete guiPrintHandler_;
guiPrintHandler_ = 0;
}
guiPrintHandler_ = new GuiPrintHandler(stageConsole_, 0, menuBarMaker_);
}
engine_ = new BerryBotsEngine(guiPrintHandler_, fileManager_,
resourcePath().c_str());
Stage *stage = engine_->getStage();
if (restarting_) {
stage->setGfxEnabled(stageConsole_->isChecked());
}
stageConsole_->setListener(new StageConsoleListener(stage));
try {
engine_->initStage(getStagesDir().c_str(), stageName,
getCacheDir().c_str());
engine_->initShips(getShipsDir().c_str(), teamNames, numUserTeams,
getCacheDir().c_str());
teamConsoles_ = guiPrintHandler_->getTeamConsoles();
} catch (EngineException *e) {
errorConsole_->print(stageName);
errorConsole_->print(": ");
errorConsole_->println(e->what());
wxMessageDialog errorMessage(NULL, e->what(),
"BerryBots engine init failed", wxOK | wxICON_EXCLAMATION);
errorMessage.ShowModal();
delete engine_;
engine_ = 0;
restarting_ = false;
newMatchDialog_->Show();
delete e;
return;
}
viewWidth_ = stage->getWidth() + (STAGE_MARGIN * 2);
viewHeight_ = stage->getHeight() + (STAGE_MARGIN * 2);
double windowScale;
if (restarting_ && maintainWindowScale) {
windowScale = prevScale;
} else {
windowScale =
std::min(backingScale, std::min(
((double) screenWidth - dockSize) / viewWidth_,
((double) screenHeight) / viewHeight_));
}
unsigned int targetWidth = round(windowScale * viewWidth_) + dockSize;
unsigned int targetHeight = round(windowScale * viewHeight_);
window->setSize(sf::Vector2u(targetWidth, targetHeight));
interrupted_ = false;
paused_ = false;
newMatchDialog_->Hide();
packageStageDialog_->Hide();
packageShipDialog_->Hide();
gfxHandler_ = new GfxEventHandler();
stage->addEventHandler((EventHandler*) gfxHandler_);
// TODO: If/when SFML getPosition() works, adjust the window position to
// keep the whole window on the screen (if necessary). Might be worth
// platform-specific implementations using getSystemHandle() if that
// doesn't happen in a reasonable timeframe.
// We could just set it to (0, 0) or centered on screen every time, but
// that seems potentially super annoying to a user - less annoying than
// having to move the window occasionally if you switch to a bigger
// stage that goes off-screen.
gfxManager_->initBbGfx(window, backingScale, viewHeight_, stage,
engine_->getTeams(), engine_->getNumTeams(),
engine_->getShips(), engine_->getNumShips());
gfxManager_->initViews(window, viewWidth_, viewHeight_);
window->setVisible(true);
drawFrame(window);
#ifdef __WXOSX__
// SFML 2.1+ has a weird scaling issue. Some of it is documented here:
// https://github.com/SFML/SFML/issues/474
// Basically, OS X caps the window height, but SFML reports the requested
// height instead of the actual height. My work-around is to manually trigger
// a resize after drawing one frame.
processMainWindowEvents(window, gfxManager_, viewWidth_, viewHeight_);
gfxManager_->onResize(window, viewWidth_, viewHeight_);
#endif
runCurrentMatch();
}
示例2: main
//.........这里部分代码省略.........
int numTeams = argc - firstTeam;
char **teams = new char*[numTeams];
for (int x = 0; x < numTeams; x++) {
char *teamAbsName = fileManager->getAbsFilePath(argv[x + firstTeam]);
char *teamName =
fileManager->parseRelativeFilePath(shipsBaseDir, teamAbsName);
if (teamName == 0) {
std::cout << "Ship must be located under " << SHIPS_SUBDIR
<< "/ subdirectory: " << argv[x + firstTeam] << std::endl;
return 0;
}
teams[x] = teamName;
delete teamAbsName;
}
printHandler->setNumTeams(numTeams);
try {
engine->initShips(shipsBaseDir, teams, numTeams, CACHE_SUBDIR);
} catch (EngineException *e) {
std::cout << "BerryBots initialization failed:" << std::endl;
std::cout << " " << e->what() << std::endl;
delete e;
return 0;
}
printHandler->updateTeams(engine->getTeams());
GfxManager *gfxManager;
sf::RenderWindow *window = 0;
GfxEventHandler *gfxHandler = 0;
unsigned int viewWidth = stage->getWidth() + (STAGE_MARGIN * 2);
unsigned int viewHeight = stage->getHeight() + (STAGE_MARGIN * 2);
if (!nodisplay) {
gfxHandler = new GfxEventHandler();
stage->addEventHandler((EventHandler*) gfxHandler);
unsigned int screenWidth = sf::VideoMode::getDesktopMode().width;
unsigned int screenHeight = sf::VideoMode::getDesktopMode().height;
double windowScale = std::min(1.0,
std::min(((double) screenWidth) / viewWidth,
((double) screenHeight) / viewHeight));
unsigned int targetWidth = round(windowScale * viewWidth);
unsigned int targetHeight = round(windowScale * viewHeight);
gfxManager = new GfxManager(false);
window = new sf::RenderWindow(sf::VideoMode(targetWidth, targetHeight),
"BerryBots", sf::Style::Default, sf::ContextSettings(0, 0, 16, 2, 0));
gfxManager->initViews(window, viewWidth, viewHeight);
gfxManager->initBbGfx(window, viewHeight, stage, engine->getTeams(),
engine->getNumTeams(), engine->getShips(), engine->getNumShips(),
resourcePath());
window->clear();
gfxManager->drawGame(window, stage, engine->getShips(),
engine->getNumShips(), engine->getGameTime(), gfxHandler, false, false,
0);
window->display();
}
time_t realTime1;
time_t realTime2;
time(&realTime1);
int realSeconds = 0;
try {
while ((nodisplay || window->isOpen()) && !engine->isGameOver()) {
engine->processTick();