Move DirtyRect to utility module
This commit is contained in:
parent
8cc95cce02
commit
a3e8b1387b
|
@ -13,6 +13,8 @@ use bevy::{
|
|||
};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::util::DirtyRect;
|
||||
|
||||
pub struct FallingSandPlugin;
|
||||
|
||||
impl Plugin for FallingSandPlugin {
|
||||
|
@ -58,57 +60,6 @@ fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
|||
});
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct DirtyRect {
|
||||
dirty: bool,
|
||||
rect: (usize, usize, usize, usize),
|
||||
}
|
||||
|
||||
impl DirtyRect {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
dirty: false,
|
||||
rect: (usize::MAX, usize::MAX, usize::MIN, usize::MIN),
|
||||
}
|
||||
}
|
||||
|
||||
fn range_x(&self) -> std::ops::RangeInclusive<usize> {
|
||||
self.rect.0..=self.rect.2
|
||||
}
|
||||
|
||||
fn range_y(&self) -> std::ops::RangeInclusive<usize> {
|
||||
self.rect.1..=self.rect.3
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
self.dirty = false;
|
||||
self.rect = (usize::MAX, usize::MAX, usize::MIN, usize::MIN);
|
||||
}
|
||||
|
||||
fn add_point(&mut self, x: usize, y: usize) {
|
||||
if x < self.rect.0 {
|
||||
self.rect.0 = x;
|
||||
self.dirty = true;
|
||||
}
|
||||
if x > self.rect.2 {
|
||||
self.rect.2 = x;
|
||||
self.dirty = true;
|
||||
}
|
||||
if y < self.rect.1 {
|
||||
self.rect.1 = y;
|
||||
self.dirty = true;
|
||||
}
|
||||
if y > self.rect.3 {
|
||||
self.rect.3 = y;
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn is_dirty(&self) -> bool {
|
||||
self.dirty
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Chunk {
|
||||
width: usize,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
mod falling_sand;
|
||||
mod util;
|
||||
|
||||
use bevy::{
|
||||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#[derive(Debug, Default)]
|
||||
pub struct DirtyRect {
|
||||
dirty: bool,
|
||||
rect: (usize, usize, usize, usize),
|
||||
}
|
||||
|
||||
impl DirtyRect {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
dirty: false,
|
||||
rect: (usize::MAX, usize::MAX, usize::MIN, usize::MIN),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn range_x(&self) -> std::ops::RangeInclusive<usize> {
|
||||
self.rect.0..=self.rect.2
|
||||
}
|
||||
|
||||
pub fn range_y(&self) -> std::ops::RangeInclusive<usize> {
|
||||
self.rect.1..=self.rect.3
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.dirty = false;
|
||||
self.rect = (usize::MAX, usize::MAX, usize::MIN, usize::MIN);
|
||||
}
|
||||
|
||||
pub fn add_point(&mut self, x: usize, y: usize) {
|
||||
if x < self.rect.0 {
|
||||
self.rect.0 = x;
|
||||
self.dirty = true;
|
||||
}
|
||||
if x > self.rect.2 {
|
||||
self.rect.2 = x;
|
||||
self.dirty = true;
|
||||
}
|
||||
if y < self.rect.1 {
|
||||
self.rect.1 = y;
|
||||
self.dirty = true;
|
||||
}
|
||||
if y > self.rect.3 {
|
||||
self.rect.3 = y;
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_dirty(&self) -> bool {
|
||||
self.dirty
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue