|
5 | 5 | #include <sstream>
|
6 | 6 | #include <cmath>
|
7 | 7 | #include <vector>
|
| 8 | +#include <numeric> |
8 | 9 |
|
9 | 10 | #if 0
|
10 | 11 | #define WIDTH 1920
|
@@ -446,13 +447,16 @@ struct
|
446 | 447 | double distance, flatAngle, heightAngle;
|
447 | 448 | } Camera;
|
448 | 449 |
|
| 450 | +std::vector<Uint32> render_times(10); |
| 451 | +std::vector<Uint32>::iterator current_render_time = render_times.begin(); |
449 | 452 |
|
450 | 453 |
|
451 | 454 | int main( int argc, char* args[] )
|
452 | 455 | {
|
453 | 456 | Uint32 currentSec = 0;
|
454 | 457 | Uint32 currentSecFPS = 0;
|
455 | 458 | Uint8 previousSecFPS = 0;
|
| 459 | + Uint32 renderTimeAvg, renderStartTick, renderEndTick; |
456 | 460 |
|
457 | 461 | SDL_Init(SDL_INIT_VIDEO);
|
458 | 462 | if(TTF_Init() == -1)
|
@@ -683,18 +687,26 @@ int main( int argc, char* args[] )
|
683 | 687 | }
|
684 | 688 | }
|
685 | 689 |
|
| 690 | + renderStartTick = SDL_GetTicks(); |
686 | 691 | SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0, 0, 0));
|
687 |
| - |
688 | 692 | SU::render();
|
| 693 | + renderEndTick = SDL_GetTicks(); |
689 | 694 | currentSecFPS++;
|
690 | 695 |
|
| 696 | + (*current_render_time) = (renderEndTick-renderStartTick); |
| 697 | + current_render_time++; |
| 698 | + if (current_render_time == render_times.end()) |
| 699 | + current_render_time = render_times.begin(); |
| 700 | + |
| 701 | + renderTimeAvg = std::accumulate(render_times.begin(), render_times.end(), 0)/render_times.size(); |
| 702 | + |
691 | 703 | SDL_Color c = {150, 150, 150};
|
692 | 704 | if (fps_visible)
|
693 | 705 | {
|
694 | 706 | text.str(std::string());
|
695 | 707 | text.clear();
|
696 | 708 |
|
697 |
| - text << (int)previousSecFPS << " FPS --- Scene: " << (*currentScene)->name; |
| 709 | + text << renderTimeAvg << "ms --- Scene: " << (*currentScene)->name; |
698 | 710 |
|
699 | 711 | SDL_Surface *textSurface = TTF_RenderText_Solid(font, text.str().c_str(), c);
|
700 | 712 |
|
|
0 commit comments