-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ed80b3
commit 6904ce7
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "StdAfx.h" | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
#include "FPSCounter.hpp" | ||
|
||
using namespace RenderLibary; | ||
|
||
FPSCounter::FPSCounter() : _frame_count(0), _fps(0) | ||
{ | ||
_last_time = std::chrono::high_resolution_clock::now(); | ||
} | ||
|
||
void FPSCounter::update() | ||
{ | ||
_frame_count++; | ||
auto now = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> elapsed = now - _last_time; | ||
|
||
if (elapsed.count() >= 1.0) | ||
{ | ||
_fps = _frame_count / elapsed.count(); | ||
_frame_count = 0; | ||
_last_time = now; | ||
std::cout << "FPS: " << _fps << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
namespace RenderLibary | ||
{ | ||
class FPSCounter final | ||
{ | ||
public: | ||
FPSCounter(); | ||
~FPSCounter() = default; | ||
|
||
void update(); | ||
|
||
private: | ||
double _fps; | ||
int _frame_count; | ||
|
||
std::chrono::high_resolution_clock::time_point _last_time; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "StdAfx.h" | ||
|
||
#include <chrono> | ||
#include "Timer.hpp" | ||
|
||
using namespace RenderLibary; | ||
|
||
Timer::Timer() : _start_time(std::chrono::high_resolution_clock::now()) | ||
{ | ||
|
||
} | ||
|
||
void Timer::reset() | ||
{ | ||
_start_time = std::chrono::high_resolution_clock::now(); | ||
} | ||
|
||
double Timer::elapsed() const | ||
{ | ||
auto end_time = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> diff = end_time - _start_time; | ||
|
||
return diff.count(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
namespace RenderLibary | ||
{ | ||
class Timer final | ||
{ | ||
public: | ||
Timer(); | ||
~Timer() = default; | ||
|
||
void reset(); | ||
double elapsed() const; | ||
|
||
private: | ||
std::chrono::high_resolution_clock::time_point _start_time; | ||
}; | ||
} | ||
|