Bring in the gnu omni font for text, and rewrite my stats code to use c++ and then use that to calc FPS stats for an FPS display on the left. Debug build gets about 48, release gets about 500fps. Amit's code will probably do even better.
This commit is contained in:
parent
e3e0f0a322
commit
cf9682ed70
8 changed files with 85 additions and 95 deletions
29
main.cpp
29
main.cpp
|
@ -4,6 +4,7 @@
|
|||
#include <numeric>
|
||||
#include <functional>
|
||||
#include "constants.hpp"
|
||||
#include "stats.hpp"
|
||||
|
||||
Matrix MAP{
|
||||
{1,1,1,1,1,1,1,1,1},
|
||||
|
@ -17,16 +18,27 @@ Matrix MAP{
|
|||
{1,1,1,1,1,1,1,1,1}
|
||||
};
|
||||
|
||||
void draw_gui(sf::RenderWindow &window) {
|
||||
void draw_gui(sf::RenderWindow &window, sf::Text &text, Stats &stats) {
|
||||
sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT});
|
||||
|
||||
rect.setPosition({0,0});
|
||||
rect.setFillColor({100, 100, 100});
|
||||
rect.setFillColor({50, 50, 50});
|
||||
window.draw(rect);
|
||||
|
||||
text.setString(
|
||||
fmt::format("FPS\nmean:{:>8.5}\nsdev: {:>8.5}\nmin: {:>8.5}\nmax: {:>8.5}\ncount:{:<10}\n\nHit R to reset.",
|
||||
stats.mean(), stats.stddev(), stats.min, stats.max, stats.n));
|
||||
window.draw(text);
|
||||
}
|
||||
|
||||
int main() {
|
||||
sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Ray Caster Game Thing");
|
||||
|
||||
sf::Font font{"./assets/text.otf"};
|
||||
sf::Text text{font};
|
||||
text.setFillColor({255,255,255});
|
||||
text.setPosition({10,10});
|
||||
|
||||
//ZED this should set with a function
|
||||
float player_x = matrix::width(MAP) / 2;
|
||||
float player_y = matrix::height(MAP) / 2;
|
||||
|
@ -43,9 +55,16 @@ int main() {
|
|||
window.close();
|
||||
};
|
||||
|
||||
Stats stats;
|
||||
|
||||
while(window.isOpen()) {
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
rayview.render();
|
||||
draw_gui(window);
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto elapsed = std::chrono::duration<double>(end - start);
|
||||
stats.sample(1/elapsed.count());
|
||||
|
||||
draw_gui(window, text, stats);
|
||||
window.display();
|
||||
rayview.rotate(rotSpeed, -1);
|
||||
|
||||
|
@ -61,6 +80,10 @@ int main() {
|
|||
rayview.rotate(rotSpeed, 1);
|
||||
}
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::R)) {
|
||||
stats.reset();
|
||||
}
|
||||
|
||||
window.handleEvents(onClose);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue