本文整理汇总了C++中MessageHandler::getRaceState方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageHandler::getRaceState方法的具体用法?C++ MessageHandler::getRaceState怎么用?C++ MessageHandler::getRaceState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHandler
的用法示例。
在下文中一共展示了MessageHandler::getRaceState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// Open Message Handler
MessageHandler messageHandler = MessageHandler();
// Print some information on the console
printf("# TrakR %s - Based on CREST - CARS REST API\n", CREST_VERSION);
printf("# (c) 2015 Lars Rosenquist, Nick Garland\n\n");
printf("# Press ESC to terminate\n");
// Keep polling until ESC is hit
while (true) {
// Check for Race State change
if (prevRaceState != messageHandler.getRaceState()){
prevRaceState = messageHandler.getRaceState();
printf("\n\n Race State Changed: %d", messageHandler.getRaceState());
}
// Not started on the grid
if (messageHandler.getRaceState() == 1 && race_id.empty()){
race_id = messageHandler.createRace();
printf("\n\n Race Created: %s", race_id.data());
std::string parts = messageHandler.addParticipants(race_id);
printf("\n\n %s", parts.data());
printf("\n\n Laps Completed: %d", messageHandler.getCompletedLaps());
}
// 2 == RACESTATE_RACING
if (messageHandler.getRaceState() == 2){
// Check if we have completed a lap yet
if (completedLaps < messageHandler.getCompletedLaps()){
//Update complete laps
completedLaps = messageHandler.getCompletedLaps();
printf("\n\n Laps Completed: %d", completedLaps);
//Now ping that server!
printf("\n\n Updated Participants: %s", messageHandler.updateParticipants(race_id));
}
}
// Finish up!
if (messageHandler.getRaceState() == 3 || messageHandler.getRaceState() == 0){
race_id = "";
}
if (_kbhit() && _getch() == ESC_KEY) {
break;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
// We're done, free up the server and exit
return 0;
}