More refactoring of the gui. Now most things are out of the FSM and MainUI is responsible for the rayvew and its overlay.

This commit is contained in:
Zed A. Shaw 2025-02-21 00:50:54 -05:00
parent 23ed1594f2
commit dd4f77a106
6 changed files with 89 additions and 45 deletions

View file

@ -8,7 +8,8 @@ namespace gui {
$window(window),
$level(level),
$textures(textures),
$overlay_ui($level, $textures)
$overlay_ui($level, $textures),
$rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)
{
$window.setVerticalSyncEnabled(VSYNC);
$window.setFramerateLimit(FRAME_LIMIT);
@ -61,14 +62,63 @@ namespace gui {
}
}
void MainUI::render() {
void MainUI::init() {
$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();
$rayview.draw($window);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration<double>(end - start);
$stats.sample(1/elapsed.count());
$overlay_ui.draw($window);
auto debug = $level.world->get_the<Debug>();
if(debug.FPS) draw_stats();
draw_blood();
}
bool MainUI::play_rotate() {
return $camera.play_rotate($rayview);
}
// this could be an optional that returs a Point
bool MainUI::play_move() {
return $camera.play_move($rayview);
}
void MainUI::plan_rotate(int dir) {
$camera.plan_rotate($rayview, dir);
}
Point MainUI::plan_move(int dir, bool strafe) {
return $camera.plan_move($rayview, dir, strafe);
}
void MainUI::abort_plan() {
$camera.abort_plan($rayview);
}
void MainUI::generate_map() {
auto& player = $level.world->get_the<Player>();
auto& player_position = $level.world->get<Position>(player.entity);
$player = player_position.location;
$rayview.set_level($level);
}
void MainUI::dead_entity(DinkyECS::Entity entity) {
auto &sprite = $level.world->get<Sprite>(entity);
$rayview.update_sprite(entity, sprite);
}
void MainUI::mouse(int x, int y) {
$overlay_ui.$gui.mouse(x, y);
}
}