本文整理汇总了C++中Stopwatch::read方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::read方法的具体用法?C++ Stopwatch::read怎么用?C++ Stopwatch::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nNodes
BVH::BVH(std::vector<FastBVH::Object*>* objects, uint32_t leafSize)
: nNodes(0), nLeafs(0), leafSize(leafSize), build_prims(objects), flatTree(NULL) {
Stopwatch sw;
// Build the tree based on the input object data set.
build();
// Output tree build time and statistics
double constructionTime = sw.read();
LOG_STAT("Built BVH (%d nodes, with %d leafs) in %d ms", nNodes, nLeafs, (int)(1000*constructionTime));
}
示例2: Run
int Game::Run(){
win = new Window(1280,760);
//The gmae timers start and end
Stopwatch time;
//Calls the init function to initilise everything
if(init() == false){
return -1;
}
//Gets the surface of the screen
displaySurface = win->getGraphics();
//initialises SDLs event handler
SDL_Event event;
//Gets a timestamp for calculating delta times between ticks
double oldTime = GetTime();
//Start the timer
time.start();
//The main game loop
while(running){
//initialises the player entity velocity to 0,
//this resets velocity on each loop to prevent the player from carrying
// on in one direction after the movement keys have stopped being pressed
entity.velocityX = 0;
entity.velocityY = 0;
//Checks to see if an event has occured,
while(SDL_PollEvent(&event)){
onEvent(&event);
}
//Calculates the delta time for dealing with the tick since last loop
const double newTime = GetTime();
double dt = newTime - oldTime;
oldTime = newTime;
//Deals with all game state changes
loop(dt);
//deals with all rendering
win->setText(" Score: " + std::to_string(score) + " Time Left: " + std::to_string(60-(int)(time.read()/1000)) + "s");
render();
if(time.read() > 60000 && !theend){
theend = true;
time.stop();
std::ofstream score;
score.open("score.txt", std::ios::ate | std::ios::out);
score << "Last score: " << this->score << "\n" << scorestring;
score.flush();
score.close();
running=false;
while(SDL_WaitEvent(&event)){
if(event.key.keysym.sym == SDLK_RETURN)
break;
}
}
}
//this is only called when the game is exiting, makes sure the game exits cleanly with all memory cleared correctly
cleanUp();
return 0;
}