Beispiel #1
0
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));
  }
Beispiel #2
0
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;
}