summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-20 19:44:23 +0200
committerHampusM <hampus@hampusmat.com>2024-08-20 19:44:23 +0200
commit8b724c9f988289c69c46071f46260b6b7aebd812 (patch)
treed62ffea29390e25ba2fcc66675c262b98fdff375 /engine/src
parent681e6f98b6dc21208f702dd33d268e95dae05732 (diff)
refactor(engine): replace Camera current field with Active component
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/camera.rs6
-rw-r--r--engine/src/renderer/opengl.rs8
2 files changed, 7 insertions, 7 deletions
diff --git a/engine/src/camera.rs b/engine/src/camera.rs
index 46b7293..66150af 100644
--- a/engine/src/camera.rs
+++ b/engine/src/camera.rs
@@ -10,7 +10,6 @@ pub struct Camera
{
pub target: Vec3<f32>,
pub global_up: Vec3<f32>,
- pub current: bool,
pub projection: Projection,
}
@@ -21,8 +20,11 @@ impl Default for Camera
Self {
target: Vec3::default(),
global_up: Vec3::UP,
- current: false,
projection: Projection::Perspective(Perspective::default()),
}
}
}
+
+/// Marker component for cameras that are active.
+#[derive(Debug, Default, Clone, Copy, Component)]
+pub struct Active;
diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs
index a90c069..292fd94 100644
--- a/engine/src/renderer/opengl.rs
+++ b/engine/src/renderer/opengl.rs
@@ -13,7 +13,7 @@ use ecs::sole::Single;
use ecs::system::{Into as _, System};
use ecs::{Component, Query};
-use crate::camera::Camera;
+use crate::camera::{Active as ActiveCamera, Camera};
use crate::color::Color;
use crate::data_types::dimens::Dimens;
use crate::draw_flags::{DrawFlags, NoDraw, PolygonModeConfig};
@@ -115,16 +115,14 @@ fn render(
query: Query<RenderableEntity, Not<With<NoDraw>>>,
point_light_query: Query<(PointLight,)>,
directional_lights: Query<(DirectionalLight,)>,
- camera_query: Query<(Camera, Position)>,
+ camera_query: Query<(Camera, Position, ActiveCamera)>,
window: Single<Window>,
global_light: Single<GlobalLight>,
mut gl_objects: Local<GlobalGlObjects>,
mut actions: Actions,
)
{
- let Some((camera, camera_pos)) =
- camera_query.iter().find(|(camera, _)| camera.current)
- else {
+ let Some((camera, camera_pos, _)) = camera_query.iter().next() else {
#[cfg(feature = "debug")]
tracing::warn!("No current camera. Nothing will be rendered");
return;