Brought in Amit's latest and will now merge in my fixing from last night into his to get them synced up.

This commit is contained in:
Zed A. Shaw 2025-01-17 11:00:49 -05:00
parent adfb6367d7
commit c91e8fc543
8 changed files with 116 additions and 68 deletions

View file

@ -1,4 +1,8 @@
#include "amt/raycaster.hpp"
#include <iostream>
#include <chrono>
#include <numeric>
#include <functional>
#define RAY_VIEW_WIDTH 960
#define RAY_VIEW_HEIGHT 720
@ -8,8 +12,6 @@
static const int SCREEN_HEIGHT=720;
static const int SCREEN_WIDTH=1280;
using Matrix = amt::Matrix<int>;
Matrix MAP{
{8,8,8,8,8,8,8,8,8},
{8,0,2,0,0,0,0,0,8},
@ -28,8 +30,8 @@ int main() {
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Zed's Ray Caster Game Thing");
//ZED this should set with a function
float player_x = MAP.cols() / 2;
float player_y = MAP.rows() / 2;
float player_x = MAP.rows() / 2;
float player_y = MAP.cols() / 2;
Raycaster rayview(window, MAP, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT);
rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y);
@ -38,8 +40,23 @@ int main() {
double moveSpeed = 0.1;
double rotSpeed = 0.1;
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;
// DRAW GUI
window.display();