Major speed up in rendering by only doing it when we move, but drawing the rendered 3d view texture constantly.

This commit is contained in:
Zed A. Shaw 2025-02-21 11:34:46 -05:00
parent 0260e3d345
commit b43553a563
7 changed files with 39 additions and 17 deletions

View file

@ -65,13 +65,15 @@ namespace gui {
$rayview.init_shaders();
$rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y);
$rayview.position_camera($player.x + 0.5, $player.y + 0.5);
$overlay_ui.render();
}
void MainUI::draw() {
auto start = std::chrono::high_resolution_clock::now();
if($needs_render) $rayview.render();
$rayview.draw($window);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration<double>(end - start);
$stats.sample(1/elapsed.count());
@ -85,16 +87,20 @@ namespace gui {
}
bool MainUI::play_rotate() {
return $camera.play_rotate($rayview);
bool done = $camera.play_rotate($rayview);
$needs_render = !done;
return done;
}
// this could be an optional that returs a Point
std::optional<Point> MainUI::play_move() {
if($camera.play_move($rayview)) {
$needs_render = false;
return std::make_optional<Point>({
size_t($camera.target_x),
size_t($camera.target_y)});
} else {
$needs_render = true;
return std::nullopt;
}
}