Cleaned up how the camera is configured so that it can be easily queried in other parts like the autowalker.

master
Zed A. Shaw 10 months ago
parent b4569622a0
commit 4a2d8770d9
  1. 2
      gui/main_ui.cpp
  2. 22
      raycaster.cpp
  3. 3
      raycaster.hpp
  4. 1
      systems.cpp

@ -59,7 +59,7 @@ namespace gui {
if($rayview->play_move()) {
$needs_render = false;
return std::make_optional<Position>(
$rayview->camera_target(),
$rayview->camera_at,
$rayview->aiming_at);
} else {
$needs_render = true;

@ -66,6 +66,10 @@ Raycaster::Raycaster(int width, int height) :
$view_sprite.setPosition({0, 0});
$pixels = make_unique<RGBA[]>($width * $height);
$view_texture.setSmooth(false);
$camera.target_x = $pos_x;
$camera.target_y = $pos_y;
update_camera_aiming();
}
void Raycaster::set_position(int x, int y) {
@ -83,8 +87,7 @@ void Raycaster::position_camera(float player_x, float player_y) {
$plane_x = 0;
$plane_y = 0.66;
// BUG: make this a function?
aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) };
update_camera_aiming();
}
void Raycaster::draw_pixel_buffer() {
@ -474,8 +477,7 @@ bool Raycaster::play_rotate() {
$dir_y = std::lerp($dir_y, $camera.target_dir_y, $camera.t);
$plane_x = std::lerp($plane_x, $camera.target_plane_x, $camera.t);
$plane_y = std::lerp($plane_y, $camera.target_plane_y, $camera.t);
aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) };
update_camera_aiming();
return $camera.t >= 1.0;
}
@ -484,8 +486,7 @@ bool Raycaster::play_move() {
$camera.t += $camera.move_speed;
$pos_x = std::lerp($pos_x, $camera.target_x, $camera.t);
$pos_y = std::lerp($pos_y, $camera.target_y, $camera.t);
aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) };
update_camera_aiming();
return $camera.t >= 1.0;
}
@ -493,7 +494,7 @@ bool Raycaster::play_move() {
void Raycaster::abort_plan() {
$camera.target_x = $pos_x;
$camera.target_y = $pos_y;
aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) };
update_camera_aiming();
}
bool Raycaster::is_target(DinkyECS::Entity entity) {
@ -501,8 +502,7 @@ bool Raycaster::is_target(DinkyECS::Entity entity) {
return false;
}
Point Raycaster::camera_target() {
return {
size_t($camera.target_x),
size_t($camera.target_y)};
void Raycaster::update_camera_aiming() {
aiming_at = { size_t($pos_x + $dir_x), size_t($pos_y + $dir_y) };
camera_at = { size_t($camera.target_x), size_t($camera.target_y) };
}

@ -27,6 +27,7 @@ struct Raycaster {
sf::Texture $view_texture;
sf::Sprite $view_sprite;
Point aiming_at{0,0};
Point camera_at{0,0};
CameraLOL $camera;
std::unique_ptr<RGBA[]> $pixels = nullptr;
@ -74,5 +75,5 @@ struct Raycaster {
void abort_plan();
bool is_target(DinkyECS::Entity entity);
Point camera_target();
void update_camera_aiming();
};

@ -270,7 +270,6 @@ void System::combat(int attack_id) {
battle.set_all("enemy_found", true);
battle.set_all("in_combat", true);
battle.plan();
battle.dump();
}
while(auto act = battle.next()) {