mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Add correct lifetimes for Blend
This commit is contained in:
parent
9757f7ed54
commit
ce5641f5ef
|
@ -15,6 +15,8 @@
|
||||||
//! ```
|
//! ```
|
||||||
//! where `gba` is a mutable [Gba][crate::Gba] struct.
|
//! where `gba` is a mutable [Gba][crate::Gba] struct.
|
||||||
|
|
||||||
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use crate::{fixnum::Num, memory_mapped::set_bits};
|
use crate::{fixnum::Num, memory_mapped::set_bits};
|
||||||
|
|
||||||
use super::tiled::BackgroundID;
|
use super::tiled::BackgroundID;
|
||||||
|
@ -43,21 +45,22 @@ pub enum BlendMode {
|
||||||
|
|
||||||
/// Manages the blending, won't cause anything to change unless [Blend::commit]
|
/// Manages the blending, won't cause anything to change unless [Blend::commit]
|
||||||
/// is called.
|
/// is called.
|
||||||
pub struct Blend {
|
pub struct Blend<'a> {
|
||||||
targets: u16,
|
targets: u16,
|
||||||
blend_weights: u16,
|
blend_weights: u16,
|
||||||
fade_weight: u16,
|
fade_weight: u16,
|
||||||
|
phantom: PhantomData<&'a ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When making many modifications to a layer, it is convenient to operate on
|
/// When making many modifications to a layer, it is convenient to operate on
|
||||||
/// that layer directly. This is created by the [Blend::layer] function and
|
/// that layer directly. This is created by the [Blend::layer] function and
|
||||||
/// operates on that layer.
|
/// operates on that layer.
|
||||||
pub struct BlendLayer<'blend> {
|
pub struct BlendLayer<'blend, 'a> {
|
||||||
blend: &'blend mut Blend,
|
blend: &'blend mut Blend<'a>,
|
||||||
layer: Layer,
|
layer: Layer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlendLayer<'_> {
|
impl<'a> BlendLayer<'_, 'a> {
|
||||||
/// Set whether a background is enabled for blending on this layer.
|
/// Set whether a background is enabled for blending on this layer.
|
||||||
pub fn set_background_enable(&mut self, background: BackgroundID, enable: bool) -> &mut Self {
|
pub fn set_background_enable(&mut self, background: BackgroundID, enable: bool) -> &mut Self {
|
||||||
self.blend
|
self.blend
|
||||||
|
@ -95,12 +98,13 @@ const BLEND_ALPHAS: *mut u16 = 0x0400_0052 as *mut _;
|
||||||
|
|
||||||
const BLEND_FADES: *mut u16 = 0x0400_0054 as *mut _;
|
const BLEND_FADES: *mut u16 = 0x0400_0054 as *mut _;
|
||||||
|
|
||||||
impl Blend {
|
impl<'a> Blend<'a> {
|
||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
let blend = Self {
|
let blend = Self {
|
||||||
targets: 0,
|
targets: 0,
|
||||||
blend_weights: 0,
|
blend_weights: 0,
|
||||||
fade_weight: 0,
|
fade_weight: 0,
|
||||||
|
phantom: PhantomData,
|
||||||
};
|
};
|
||||||
blend.commit();
|
blend.commit();
|
||||||
|
|
||||||
|
@ -137,7 +141,7 @@ impl Blend {
|
||||||
/// Creates a layer object whose functions work only on that layer,
|
/// Creates a layer object whose functions work only on that layer,
|
||||||
/// convenient when performing multiple operations on that layer without the
|
/// convenient when performing multiple operations on that layer without the
|
||||||
/// need of specifying the layer every time.
|
/// need of specifying the layer every time.
|
||||||
pub fn layer(&mut self, layer: Layer) -> BlendLayer {
|
pub fn layer(&mut self, layer: Layer) -> BlendLayer<'_, 'a> {
|
||||||
BlendLayer { blend: self, layer }
|
BlendLayer { blend: self, layer }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +213,7 @@ impl Blend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Blend {
|
impl Drop for Blend<'_> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.reset().commit();
|
self.reset().commit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl WindowDist {
|
||||||
pub struct BlendDist;
|
pub struct BlendDist;
|
||||||
|
|
||||||
impl BlendDist {
|
impl BlendDist {
|
||||||
pub fn get(&mut self) -> Blend {
|
pub fn get(&mut self) -> Blend<'_> {
|
||||||
Blend::new()
|
Blend::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue