|
|
@ -14,24 +14,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
const double PI = 3.141592653589793238463;
|
|
|
|
const double PI = 3.141592653589793238463;
|
|
|
|
const float PI_F = 3.14159265358979f;
|
|
|
|
const float PI_F = 3.14159265358979f;
|
|
|
|
|
|
|
|
|
|
|
|
struct fps_counter {
|
|
|
|
struct fps_counter {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
fps_counter(){
|
|
|
|
fps_counter() :
|
|
|
|
if(!f.loadFromFile("../assets/fonts/Arial.ttf")){
|
|
|
|
backdrop(sf::Vector2f(200, 100)), vertex_array(sf::LinesStrip) {
|
|
|
|
std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
backdrop.setFillColor(sf::Color(0x0000003F));
|
|
|
|
t.setFont(f);
|
|
|
|
|
|
|
|
|
|
|
|
if (!f.loadFromFile("../assets/fonts/Arial.ttf")) {
|
|
|
|
|
|
|
|
std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
t.setFont(f);
|
|
|
|
|
|
|
|
t.setCharacterSize(18);
|
|
|
|
|
|
|
|
t.setColor(sf::Color::White);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void frame(double delta_time){
|
|
|
|
void frame(double delta_time) {
|
|
|
|
if (frame_count == 100){
|
|
|
|
// Apply 100 units of smoothing
|
|
|
|
|
|
|
|
if (frame_count == 100) {
|
|
|
|
frame_count = 0;
|
|
|
|
frame_count = 0;
|
|
|
|
fps_average = 0;
|
|
|
|
fps_average = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frame_count++;
|
|
|
|
frame_count++;
|
|
|
|
fps_average += (delta_time - fps_average) / frame_count;
|
|
|
|
fps_average += (delta_time - fps_average) / frame_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void flip_units() {
|
|
|
|
void flip_units() {
|
|
|
@ -40,9 +47,36 @@ public:
|
|
|
|
else
|
|
|
|
else
|
|
|
|
milliseconds = true;
|
|
|
|
milliseconds = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void draw(sf::RenderWindow *r){
|
|
|
|
void set_position(sf::Vector2f position) {
|
|
|
|
|
|
|
|
backdrop.setPosition(position);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::Vector2f get_position() {
|
|
|
|
|
|
|
|
return backdrop.getPosition();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void draw(sf::RenderWindow *r) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FPS Line graph
|
|
|
|
|
|
|
|
r->draw(backdrop);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (vertex_position == 200)
|
|
|
|
|
|
|
|
vertex_position = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::Vector2f origin = backdrop.getPosition();
|
|
|
|
|
|
|
|
sf::Vector2f point = origin + sf::Vector2f(vertex_position, backdrop.getSize().y - (1.0 / fps_average));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (vertex_array.getVertexCount() < 200)
|
|
|
|
|
|
|
|
vertex_array.append(sf::Vertex(point, sf::Color::Red));
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
vertex_array[vertex_position] = sf::Vertex(point, sf::Color::Red);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r->draw(vertex_array);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vertex_position++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FPS Text
|
|
|
|
std::string out;
|
|
|
|
std::string out;
|
|
|
|
|
|
|
|
|
|
|
|
if (milliseconds)
|
|
|
|
if (milliseconds)
|
|
|
@ -50,16 +84,24 @@ public:
|
|
|
|
else
|
|
|
|
else
|
|
|
|
out = std::to_string(floor(1 / fps_average));
|
|
|
|
out = std::to_string(floor(1 / fps_average));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.setPosition(origin);
|
|
|
|
t.setString(out);
|
|
|
|
t.setString(out);
|
|
|
|
r->draw(t);
|
|
|
|
r->draw(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
bool milliseconds = false;
|
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape backdrop;
|
|
|
|
|
|
|
|
sf::VertexArray vertex_array;
|
|
|
|
|
|
|
|
|
|
|
|
sf::Font f;
|
|
|
|
sf::Font f;
|
|
|
|
sf::Text t;
|
|
|
|
sf::Text t;
|
|
|
|
|
|
|
|
|
|
|
|
int frame_count = 0;
|
|
|
|
int frame_count = 0;
|
|
|
|
double fps_average = 0;
|
|
|
|
double fps_average = 0;
|
|
|
|
|
|
|
|
bool milliseconds = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int vertex_position = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct debug_text {
|
|
|
|
struct debug_text {
|
|
|
|