Clean up Sprite's file hierarchy

This commit is contained in:
Steins7 2022-10-22 20:47:27 +02:00
parent d5d36cfadc
commit c2e884f68c
4 changed files with 144 additions and 94 deletions

View File

@ -9,9 +9,7 @@ use canvas::{
utils::Position,
};
use std::{
time::Instant, arch::x86_64::_mm_sub_epi8,
};
use std::time::Instant;
fn setup_logger() -> Result<(), fern::InitError> {
use fern::colors::{Color, ColoredLevelConfig};

View File

@ -1,108 +1,45 @@
#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
use crate::{
renderer::WgpuRenderer,
shape::Shape,
utils::{Pixel, Position, Size},
};
use cgmath::Matrix4;
//--Internal imports--------------------------------------------------------------------------------
mod texture_sprite;
pub use texture_sprite::TextureSprite;
mod text_sprite;
pub use text_sprite::TextSprite;
mod shape_sprite;
pub use shape_sprite::ShapeSprite;
use crate::{
utils::Position,
renderer::WgpuRenderer,
};
//--External imports--------------------------------------------------------------------------------
//--Sprite trait------------------------------------------------------------------------------------
/// The interface for everything that can be rendered by the engine.
///
/// This trait provides a few generic functions to have basic controls over the rendered object as
/// well as the unique function necessary for it to be rendered
pub trait Sprite {
/// Set the position of the [Sprite] on the screen
fn set_position(&mut self, pos: Position);
/// Set the rotation of the [Sprite] on the screen
fn set_rotation(&mut self, rot: f32);
/// Set the alpha of the [Sprite] on the screen
fn set_alpha(&mut self, alpha: u8);
/// Set the scale of the [Sprite] on the screen
fn set_scale(&mut self, scale: f32);
/// Renders the [Sprite] using the given rendering context
fn render(&mut self, renderer: &mut WgpuRenderer);
}
//--TextSprite struct-------------------------------------------------------------------------------
#[allow(dead_code)]
pub struct TextSprite {
matrix: Matrix4<f32>,
size: Size,
text: &'static str, //TODO: temporary
}
impl TextSprite {
pub fn set_text(&mut self, _text: &'static str) {
unimplemented!();
}
pub fn set_color(&mut self, _color: Pixel) {
unimplemented!();
}
}
impl Sprite for TextSprite {
fn set_position(&mut self, _pos: Position) {
unimplemented!();
}
fn set_rotation(&mut self, _rot: f32) {
unimplemented!();
}
fn set_alpha(&mut self, _alpha: u8) {
unimplemented!();
}
fn set_scale(&mut self, _scale: f32) {
unimplemented!();
}
fn render(&mut self, _renderer: &mut WgpuRenderer) {
todo!();
}
}
//--ShapeSprite struct-------------------------------------------------------------------------------
#[allow(dead_code)]
pub struct ShapeSprite {
matrix: Matrix4<f32>,
size: Size,
shape: Shape,
}
impl ShapeSprite {
pub fn set_shape(&mut self, _shape: Shape) {
unimplemented!();
}
pub fn set_color(&mut self, _color: Pixel) {
unimplemented!();
}
}
impl Sprite for ShapeSprite {
fn set_position(&mut self, _pos: Position) {
unimplemented!();
}
fn set_rotation(&mut self, _rot: f32) {
unimplemented!();
}
fn set_alpha(&mut self, _alpha: u8) {
unimplemented!();
}
fn set_scale(&mut self, _scale: f32) {
unimplemented!();
}
fn render(&mut self, _renderer: &mut WgpuRenderer) {
todo!();
}
}

View File

@ -0,0 +1,58 @@
#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
//--Internal imports--------------------------------------------------------------------------------
use crate::{
renderer::WgpuRenderer,
sprite::Sprite,
shape::Shape,
utils::{Pixel, Position, Size},
};
//--External imports--------------------------------------------------------------------------------
use cgmath::Matrix4;
//--ShapeSprite struct-------------------------------------------------------------------------------
#[allow(dead_code)]
pub struct ShapeSprite {
matrix: Matrix4<f32>,
size: Size,
shape: Shape,
}
impl ShapeSprite {
pub fn set_shape(&mut self, _shape: Shape) {
todo!();
}
pub fn set_color(&mut self, _color: Pixel) {
todo!();
}
}
impl Sprite for ShapeSprite {
fn set_position(&mut self, _pos: Position) {
todo!();
}
fn set_rotation(&mut self, _rot: f32) {
todo!();
}
fn set_alpha(&mut self, _alpha: u8) {
todo!();
}
fn set_scale(&mut self, _scale: f32) {
todo!();
}
fn render(&mut self, _renderer: &mut WgpuRenderer) {
todo!();
}
}

57
src/sprite/text_sprite.rs Normal file
View File

@ -0,0 +1,57 @@
#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
//--Internal imports--------------------------------------------------------------------------------
use crate::{
renderer::WgpuRenderer,
sprite::Sprite,
utils::{Pixel, Position, Size},
};
//--External imports--------------------------------------------------------------------------------
use cgmath::Matrix4;
//--TextSprite struct-------------------------------------------------------------------------------
#[allow(dead_code)]
pub struct TextSprite {
matrix: Matrix4<f32>,
size: Size,
text: &'static str, //TODO: temporary
}
impl TextSprite {
pub fn set_text(&mut self, _text: &'static str) {
todo!();
}
pub fn set_color(&mut self, _color: Pixel) {
todo!();
}
}
impl Sprite for TextSprite {
fn set_position(&mut self, _pos: Position) {
todo!();
}
fn set_rotation(&mut self, _rot: f32) {
todo!();
}
fn set_alpha(&mut self, _alpha: u8) {
todo!();
}
fn set_scale(&mut self, _scale: f32) {
todo!();
}
fn render(&mut self, _renderer: &mut WgpuRenderer) {
todo!();
}
}