From 3c229ff55b3ba1b618e00fb48f2b350709a58c02 Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Tue, 10 Dec 2024 16:06:06 -0500 Subject: Upgraded to Bevy 0.15 --- src/components.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/components.rs') diff --git a/src/components.rs b/src/components.rs index 8e25530..7ec88ba 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,19 +1,19 @@ -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; use bevy::{ecs::query::QueryItem, prelude::*, render::extract_component::ExtractComponent}; -use crate::render_assets::HeadlessRenderSource; +use crate::render_assets; /// Headless render destination. Contains the image which the rendered frame is copied to. #[derive(Component, Default, Clone)] pub struct HeadlessRenderDestination(pub Arc>); impl ExtractComponent for HeadlessRenderDestination { - type QueryData = (&'static Self, &'static Handle); + type QueryData = (&'static Self, &'static HeadlessRenderSource); type QueryFilter = (); - type Out = (Self, Handle); + type Out = (Self, HeadlessRenderSource); fn extract_component( (destination, source_handle): QueryItem<'_, Self::QueryData>, @@ -22,11 +22,21 @@ impl ExtractComponent for HeadlessRenderDestination { } } -/// Bundle containing both a source and destination for headless rendering. -#[derive(Bundle)] -pub struct HeadlessRenderBundle { - /// Source - pub source: Handle, - /// Destination - pub dest: HeadlessRenderDestination, +impl HeadlessRenderDestination { + /// Get lock on this destination's image + pub fn image(&self) -> Result, PoisonError>> { + self.0.lock() + } +} + +/// Headless render source +#[derive(Component, Debug, Clone, DerefMut, Deref)] +#[require(HeadlessRenderDestination, Camera3d)] +pub struct HeadlessRenderSource(pub Handle); + +impl HeadlessRenderSource { + /// Create a new headless render source from the provided image + pub fn new(asset_server: &AssetServer, image: Handle) -> Self { + Self(asset_server.add(render_assets::HeadlessRenderSource(image))) + } } -- cgit v1.2.3