Brought in Amit's latest code and converted it to use either dumb lighting or his new torch lighting, then threw in the FPS counter from last night.

This commit is contained in:
Zed A. Shaw 2025-01-18 11:10:43 -05:00
parent 53a151511e
commit 831e15ca18
6 changed files with 500 additions and 247 deletions

View file

@ -3,14 +3,8 @@
#include <chrono>
#include <numeric>
#include <functional>
#define RAY_VIEW_WIDTH 960
#define RAY_VIEW_HEIGHT 720
#define RAY_VIEW_X (1280 - RAY_VIEW_WIDTH)
#define RAY_VIEW_Y 0
static const int SCREEN_HEIGHT=720;
static const int SCREEN_WIDTH=1280;
#include "constants.hpp"
#include "stats.hpp"
Matrix MAP{
{1,1,1,1,1,1,1,1,1},
@ -24,16 +18,27 @@ Matrix MAP{
{1,1,1,1,1,1,1,1,1}
};
void draw_gui(sf::RenderWindow &window) {
sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, 300});
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\nVSync? {}\nDebug? {}\n\nHit R to reset.",
stats.mean(), stats.stddev(), stats.min, stats.max, stats.n, VSYNC, DEBUG_BUILD));
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 = MAP.rows() / 2;
float player_y = MAP.cols() / 2;
@ -50,26 +55,16 @@ int main() {
window.close();
};
Stats stats;
std::size_t const max_count = 100;
std::vector<double> frames(max_count);
std::size_t it = 1;
while(window.isOpen()) {
auto start = std::chrono::high_resolution_clock::now();
rayview.render();
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration<double>(end - start);
auto frame = 1 / elapsed.count();
frames.push_back(frame);
if (it % max_count == 0) {
auto frame = std::accumulate(frames.begin(), frames.end(), 0., std::plus<>{}) / max_count;
std::cout << "Frame: " << frame << '\n';
frames.clear();
it = 1;
}
++it;
stats.sample(1/elapsed.count());
draw_gui(window);
draw_gui(window, text, stats);
window.display();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
@ -84,6 +79,10 @@ int main() {
rayview.rotate(rotSpeed, 1);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::R)) {
stats.reset();
}
window.handleEvents(onClose);
}