Compare commits

..

No commits in common. "a2715eafabd9e4e6e79a68e284517f1ca5a8fc00" and "c7f0412effab1a2794b37aa15e776a4b7f358d84" have entirely different histories.

22 changed files with 546 additions and 501 deletions

View file

@ -33,6 +33,7 @@ pub struct App {
game_state: Option<Box<dyn Any>>, game_state: Option<Box<dyn Any>>,
audio: Box<dyn Audio>, audio: Box<dyn Audio>,
scene: Scene, scene: Scene,
fullscreen: bool,
should_quit: bool, should_quit: bool,
} }
@ -50,6 +51,7 @@ impl App {
game_state: None, game_state: None,
audio: Box::new(KiraAudio::new()), audio: Box::new(KiraAudio::new()),
scene: Scene::new(), scene: Scene::new(),
fullscreen: false,
should_quit: false, should_quit: false,
} }
} }
@ -370,7 +372,6 @@ impl App {
} }
} }
#[allow(unused_variables)]
match event { match event {
Event::WindowEvent { Event::WindowEvent {
ref event, ref event,

View file

@ -2,12 +2,16 @@ extern crate proc_macro;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::quote; use quote::quote;
use syn::{parse_macro_input, Data, DeriveInput, Fields}; use syn::{parse_macro_input, DeriveInput, Data, Fields};
// This is the procedural macro for `derive(MyTrait)`
#[proc_macro_derive(Component)] #[proc_macro_derive(Component)]
pub fn component_derive(input: TokenStream) -> TokenStream { pub fn my_trait_derive(input: TokenStream) -> TokenStream {
// Parse the input tokens into a syntax tree (AST)
let input = parse_macro_input!(input as DeriveInput); let input = parse_macro_input!(input as DeriveInput);
// Get the name of the struct
let name = &input.ident;
let name = &input.ident; let name = &input.ident;
let fields = if let Data::Struct(data) = &input.data { let fields = if let Data::Struct(data) = &input.data {
@ -29,21 +33,19 @@ pub fn component_derive(input: TokenStream) -> TokenStream {
let default_fields = if let Data::Struct(data) = &input.data { let default_fields = if let Data::Struct(data) = &input.data {
match &data.fields { match &data.fields {
Fields::Named(fields) => fields Fields::Named(fields) => {
.named // Generate code to assign each field a default value
.iter() fields.named.iter().map(|field| {
.map(|field| {
let field_name = &field.ident; let field_name = &field.ident;
quote! { #field_name: Default::default() } quote! { #field_name: Default::default() }
}) }).collect::<Vec<_>>()
.collect::<Vec<_>>(), },
Fields::Unnamed(fields) => fields Fields::Unnamed(fields) => {
.unnamed // Generate default values for tuple structs
.iter() fields.unnamed.iter().map(|_field| {
.map(|_field| {
quote! { Default::default() } quote! { Default::default() }
}) }).collect::<Vec<_>>()
.collect::<Vec<_>>(), },
Fields::Unit => Vec::new(), Fields::Unit => Vec::new(),
} }
} else { } else {
@ -57,6 +59,13 @@ pub fn component_derive(input: TokenStream) -> TokenStream {
} }
}); });
for field in &fields {
if !is_copy_field(&field) {
panic!("All fields in the struct must implement Copy");
}
}
// Generate the implementation of MyTrait for the given struct
let expanded = quote! { let expanded = quote! {
impl Component for #name { impl Component for #name {
fn new() -> Self { fn new() -> Self {
@ -74,6 +83,7 @@ pub fn component_derive(input: TokenStream) -> TokenStream {
impl Default for #name { impl Default for #name {
fn default() -> Self { fn default() -> Self {
// Construct the struct with default values
Self { Self {
#(#default_fields),* #(#default_fields),*
} }
@ -105,5 +115,16 @@ pub fn component_derive(input: TokenStream) -> TokenStream {
} }
}; };
// Convert the generated code into a TokenStream and return it
TokenStream::from(expanded) TokenStream::from(expanded)
} }
fn is_copy_field(field: &syn::Field) -> bool {
// Logic to check if the field type implements Copy (this is simplified)
// You might need more sophisticated logic to check the actual type of the field.
let field_type = &field.ty;
// Implement a check for Copy trait for the field type if needed
// Return true if it implements Copy; false otherwise
true // Assuming it does, just for simplicity
}

View file

@ -1,15 +1,15 @@
use comet_structs::ComponentSet;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use comet_structs::ComponentSet;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Archetypes { pub struct Archetypes {
archetypes: HashMap<ComponentSet, HashSet<u32>>, archetypes: HashMap<ComponentSet, HashSet<u32>>
} }
impl Archetypes { impl Archetypes {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
archetypes: HashMap::new(), archetypes: HashMap::new()
} }
} }
@ -25,6 +25,10 @@ impl Archetypes {
self.archetypes.get(components) self.archetypes.get(components)
} }
pub fn get_archetype_mut(&mut self, components: &ComponentSet) -> Option<&mut HashSet<u32>> {
self.archetypes.get_mut(components)
}
pub fn add_entity_to_archetype(&mut self, components: &ComponentSet, entity: u32) { pub fn add_entity_to_archetype(&mut self, components: &ComponentSet, entity: u32) {
if let Some(archetype) = self.archetypes.get_mut(components) { if let Some(archetype) = self.archetypes.get_mut(components) {
archetype.insert(entity); archetype.insert(entity);
@ -44,4 +48,12 @@ impl Archetypes {
pub fn contains_archetype(&self, components: &ComponentSet) -> bool { pub fn contains_archetype(&self, components: &ComponentSet) -> bool {
self.archetypes.contains_key(components) self.archetypes.contains_key(components)
} }
pub fn archetype_contains_entity(&self, entity_id: u32, components: &ComponentSet) -> bool {
if self.contains_archetype(components) {
let archetype = self.get_archetype(components).unwrap();
return archetype.contains(&entity_id);
}
false
}
} }

View file

@ -1,12 +1,14 @@
use crate::keyboard::Key; use winit::event::{ElementState, WindowEvent, KeyEvent, Event};
use winit::event::{ElementState, Event, KeyEvent, WindowEvent}; use std::collections::HashSet;
use winit::event::WindowEvent::KeyboardInput;
use winit::keyboard::PhysicalKey; use winit::keyboard::PhysicalKey;
use crate::keyboard::Key;
#[derive(Debug)] #[derive(Debug)]
pub struct InputHandler { pub struct InputHandler {
keys_pressed: Vec<PhysicalKey>, keys_pressed: Vec<PhysicalKey>,
keys_held: Vec<PhysicalKey>, keys_held: Vec<PhysicalKey>,
keys_released: Vec<PhysicalKey>, keys_released: Vec<PhysicalKey>
} }
impl InputHandler { impl InputHandler {
@ -14,17 +16,15 @@ impl InputHandler {
Self { Self {
keys_pressed: Vec::new(), keys_pressed: Vec::new(),
keys_held: Vec::new(), keys_held: Vec::new(),
keys_released: Vec::new(), keys_released: Vec::new()
} }
} }
pub fn update<T>(&mut self, event: &Event<T>) { pub fn update<T>(&mut self, event: &Event<T>) {
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: event: WindowEvent::KeyboardInput {
WindowEvent::KeyboardInput { event: KeyEvent {
event:
KeyEvent {
state, state,
physical_key: PhysicalKey::Code(keycode), physical_key: PhysicalKey::Code(keycode),
.. ..
@ -32,12 +32,11 @@ impl InputHandler {
.. ..
}, },
.. ..
} => match state { } =>
ElementState::Pressed => {
if self
.keys_pressed
.contains(&PhysicalKey::Code(keycode.clone()))
{ {
match state {
ElementState::Pressed => {
if self.keys_pressed.contains(&PhysicalKey::Code(keycode.clone())) {
self.keys_held.push(PhysicalKey::Code(keycode.clone())); self.keys_held.push(PhysicalKey::Code(keycode.clone()));
} else { } else {
self.keys_pressed.push(PhysicalKey::Code(keycode.clone())); self.keys_pressed.push(PhysicalKey::Code(keycode.clone()));
@ -46,23 +45,16 @@ impl InputHandler {
} }
ElementState::Released => { ElementState::Released => {
self.keys_released = vec![]; self.keys_released = vec![];
if let Some(index) = self if let Some(index) = self.keys_pressed.iter().position(|&x| x == PhysicalKey::Code(keycode.clone())) {
.keys_pressed
.iter()
.position(|&x| x == PhysicalKey::Code(keycode.clone()))
{
self.keys_pressed.remove(index); self.keys_pressed.remove(index);
} }
if let Some(index) = self if let Some(index) = self.keys_held.iter().position(|&x| x == PhysicalKey::Code(keycode.clone())) {
.keys_held
.iter()
.position(|&x| x == PhysicalKey::Code(keycode.clone()))
{
self.keys_held.remove(index); self.keys_held.remove(index);
} }
self.keys_released.push(PhysicalKey::Code(keycode.clone())); self.keys_released.push(PhysicalKey::Code(keycode.clone()));
} }
}, }
}
_ => {} _ => {}
} }
} }

View file

@ -8,4 +8,3 @@ comet_log = { path = "../comet_log" }
rand = "0.9.0-beta.1" rand = "0.9.0-beta.1"
image = { version = "0.24", default_features = false, features = ["png", "jpeg", "hdr"] } image = { version = "0.24", default_features = false, features = ["png", "jpeg", "hdr"] }
chrono = "0.4.40" chrono = "0.4.40"
serde = { version = "1.0", features = ["derive"] }

View file

@ -1,4 +1,4 @@
use crate::InnerSpace; use crate::{InnerSpace, Point};
/// Representation of a Bezier curve of degree n in any (2-4) dimensions. /// Representation of a Bezier curve of degree n in any (2-4) dimensions.
pub struct Bezier<V: InnerSpace> { pub struct Bezier<V: InnerSpace> {

View file

@ -1,7 +1,6 @@
use crate::vector::{v2, v3, v4}; use crate::vector::{v2, v3, v4};
use std::ops::*; use std::ops::*;
#[allow(dead_code)]
trait LinearTransformation { trait LinearTransformation {
fn det(&self) -> f32; fn det(&self) -> f32;
} }
@ -13,7 +12,6 @@ trait LinearTransformation {
/// Representation of a 2x2 matrix. /// Representation of a 2x2 matrix.
#[repr(C)] #[repr(C)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[allow(non_camel_case_types)]
pub struct m2 { pub struct m2 {
x00: f32, x00: f32,
x01: f32, x01: f32,
@ -210,7 +208,6 @@ impl Into<[[f32; 2]; 2]> for m2 {
/// Representation of a 3x3 matrix. /// Representation of a 3x3 matrix.
#[repr(C)] #[repr(C)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[allow(non_camel_case_types)]
pub struct m3 { pub struct m3 {
x00: f32, x00: f32,
x01: f32, x01: f32,
@ -500,7 +497,6 @@ impl Into<[[f32; 3]; 3]> for m3 {
/// Representation of a 4x4 matrix. /// Representation of a 4x4 matrix.
#[repr(C)] #[repr(C)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[allow(non_camel_case_types)]
pub struct m4 { pub struct m4 {
x00: f32, x00: f32,
x01: f32, x01: f32,

View file

@ -323,12 +323,9 @@ impl ValueNoise {
let mut f = 0.0; let mut f = 0.0;
let mut amplitude = 0.5; let mut amplitude = 0.5;
for _ in 0..4 {
f += amplitude * self.noise(uv); f += amplitude * self.noise(uv);
uv = (uv.0 * 2.0, uv.1 * 2.0); uv = (uv.0 * 2.0, uv.1 * 2.0);
amplitude *= 0.5; amplitude *= 0.5;
}
f = ((f / max_amplitude) + 1.0) * 0.5; f = ((f / max_amplitude) + 1.0) * 0.5;
noise.push(f); noise.push(f);

View file

@ -7,7 +7,6 @@ pub trait Point {
} }
/// Representation of a 2D point. /// Representation of a 2D point.
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct p2 { pub struct p2 {
x: f32, x: f32,
@ -37,7 +36,6 @@ impl p2 {
} }
/// Representation of a 3D point. /// Representation of a 3D point.
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct p3 { pub struct p3 {
x: f32, x: f32,
@ -83,7 +81,7 @@ impl Point for p2 {
Self { x, y } Self { x, y }
} }
fn to_vec(&self) -> impl InnerSpace { fn to_vec(&self) -> v2 {
v2::new(self.x, self.y) v2::new(self.x, self.y)
} }
} }
@ -95,11 +93,23 @@ impl Point for p3 {
Self { x, y, z } Self { x, y, z }
} }
fn to_vec(&self) -> impl InnerSpace { fn to_vec(&self) -> v3 {
v3::new(self.x, self.y, self.z) v3::new(self.x, self.y, self.z)
} }
} }
impl Into<v2> for p2 {
fn into(self) -> v2 {
self.to_vec()
}
}
impl Into<v3> for p3 {
fn into(self) -> v3 {
self.to_vec()
}
}
impl From<v2> for p2 { impl From<v2> for p2 {
fn from(v: v2) -> Self { fn from(v: v2) -> Self {
Self::from_vec(v) Self::from_vec(v)

View file

@ -118,7 +118,7 @@ impl Div for Polynomial {
let divisor = other.coefficients.clone(); let divisor = other.coefficients.clone();
while dividend.len() >= divisor.len() { while dividend.len() >= divisor.len() {
let mut quotient = vec![0.0; dividend.len() - divisor.len() + 1]; let mut quotient = vec![0.0; dividend.len() - divisor.len() + 1];
let i = dividend.len() - divisor.len(); let mut i = dividend.len() - divisor.len();
quotient[i] = dividend.last().unwrap() / divisor.last().unwrap(); quotient[i] = dividend.last().unwrap() / divisor.last().unwrap();
for (j, &d) in divisor.iter().enumerate() { for (j, &d) in divisor.iter().enumerate() {
dividend[i + j] -= quotient[i] * d; dividend[i + j] -= quotient[i] * d;

View file

@ -11,7 +11,6 @@ pub struct Quat {
impl Quat { impl Quat {
/// The zero quaternion. /// The zero quaternion.
#[allow(unused)]
const ZERO: Self = Self { const ZERO: Self = Self {
s: 0.0, s: 0.0,
v: v3 { v: v3 {

View file

@ -1,9 +1,6 @@
use crate::{ use crate::point::{p2, p3};
point::{p2, p3}, use crate::quaternion::Quat;
quaternion::Quat, use crate::Point;
Point,
};
use serde::{Deserialize, Serialize};
use std::ops::*; use std::ops::*;
pub trait InnerSpace: pub trait InnerSpace:
@ -34,7 +31,8 @@ pub trait InnerSpace:
/// Representation of a 2D vector /// Representation of a 2D vector
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub struct v2 { pub struct v2 {
x: f32, x: f32,
@ -177,7 +175,8 @@ impl Into<v2> for [f32; 2] {
/// Representation of a 2D integer vector /// Representation of a 2D integer vector
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub struct v2i { pub struct v2i {
x: i64, x: i64,
@ -424,7 +423,8 @@ impl Into<[f32; 2]> for v2i {
/// Representation of a 3D vector /// Representation of a 3D vector
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub struct v3 { pub struct v3 {
pub x: f32, pub x: f32,
@ -620,7 +620,8 @@ impl Into<v3> for [f32; 3] {
/// Representation of a 3D integer vector /// Representation of a 3D integer vector
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub struct v3i { pub struct v3i {
pub x: i64, pub x: i64,
@ -823,7 +824,8 @@ impl From<v3> for v3i {
/// Representation of a 4D vector /// Representation of a 4D vector
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub struct v4 { pub struct v4 {
x: f32, x: f32,

View file

@ -1,4 +1,5 @@
use comet_ecs::{Camera2D, Transform2D}; use comet_ecs::{Camera2D, Transform2D};
use comet_log::fatal;
use comet_math::{m4, v2, v3}; use comet_math::{m4, v2, v3};
pub struct CameraManager { pub struct CameraManager {
@ -14,6 +15,16 @@ impl CameraManager {
} }
} }
pub fn set_cameras(&mut self, cameras: Vec<RenderCamera>) {
self.cameras = cameras
}
pub fn set_active(&mut self, active: usize) {
if active >= self.cameras.len() {
fatal!("Active camera index is out of range of the RenderCamera array!")
}
}
pub fn get_camera(&self) -> &RenderCamera { pub fn get_camera(&self) -> &RenderCamera {
self.cameras.get(self.active_camera).unwrap() self.cameras.get(self.active_camera).unwrap()
} }

View file

@ -1,6 +1,7 @@
use crate::texture_atlas::{TextureAtlas, TextureRegion};
use ab_glyph::{point, Font as AbFont, FontArc, Glyph, PxScale, ScaleFont};
use image::{DynamicImage, Rgba, RgbaImage}; use image::{DynamicImage, Rgba, RgbaImage};
use ab_glyph::{FontArc, PxScale, ScaleFont, Glyph, point, Font as AbFont};
use comet_log::debug;
use crate::texture_atlas::{TextureAtlas, TextureRegion};
pub struct GlyphData { pub struct GlyphData {
pub name: String, pub name: String,
@ -24,7 +25,7 @@ impl Font {
name: path.to_string(), name: path.to_string(),
size, size,
line_height, line_height,
glyphs, glyphs
} }
} }
@ -101,20 +102,19 @@ impl Font {
image.put_pixel(x, y, Rgba([255, 255, 255, alpha])); image.put_pixel(x, y, Rgba([255, 255, 255, alpha]));
}); });
glyphs.push(GlyphData { glyphs.push(
GlyphData {
name: ch.to_string(), name: ch.to_string(),
render: DynamicImage::ImageRgba8(image), render: DynamicImage::ImageRgba8(image),
advance: scaled_font.h_advance(glyph_id), advance: scaled_font.h_advance(glyph_id),
offset_x: bounds.min.x, offset_x: bounds.min.x,
offset_y: bounds.min.y, offset_y: bounds.min.y,
}) }
)
} }
} }
} }
( (TextureAtlas::from_glyphs(glyphs), scaled_font.ascent() - scaled_font.descent())
TextureAtlas::from_glyphs(glyphs),
scaled_font.ascent() - scaled_font.descent(),
)
} }
} }

View file

@ -1,20 +1,21 @@
use std::{collections::HashMap, path::Path}; use std::{
collections::HashMap, path::Path
use crate::{
texture,
texture_atlas::{TextureAtlas, TextureRegion},
}; };
use wgpu::{Device, FilterMode, Queue, TextureFormat, TextureUsages};
use crate::{texture, Texture};
use crate::texture_atlas::{TextureAtlas, TextureRegion};
pub struct ResourceManager { pub struct ResourceManager {
texture_atlas: TextureAtlas, texture_atlas: TextureAtlas,
data_files: HashMap<String, String>, data_files: HashMap<String, String>
} }
impl ResourceManager { impl ResourceManager {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
texture_atlas: TextureAtlas::empty(), texture_atlas: TextureAtlas::empty(),
data_files: HashMap::new(), data_files: HashMap::new()
} }
} }

View file

@ -334,7 +334,7 @@ impl TextureAtlas {
for glyph_name in glyph_names { for glyph_name in glyph_names {
let region = font.glyphs().textures().get(&glyph_name).unwrap(); let region = font.glyphs().textures().get(&glyph_name).unwrap();
let (u0, v0) = (region.u0(), region.v0()); let (u0, v0, u1, v1) = (region.u0(), region.v0(), region.u1(), region.v1());
let (width, height) = region.dimensions(); let (width, height) = region.dimensions();
let src_x = (u0 * font.glyphs().atlas().width() as f32) as u32; let src_x = (u0 * font.glyphs().atlas().width() as f32) as u32;

View file

@ -1,9 +1,11 @@
use wgpu::Color;
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable, PartialEq)] #[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable, PartialEq)]
pub struct Vertex { pub struct Vertex {
position: [f32; 3], position: [f32; 3],
tex_coords: [f32; 2], tex_coords: [f32; 2],
color: [f32; 4], color: [f32; 4]
} }
impl Vertex { impl Vertex {
@ -11,7 +13,7 @@ impl Vertex {
Self { Self {
position, position,
tex_coords, tex_coords,
color, color
} }
} }
@ -46,8 +48,8 @@ impl Vertex {
offset: std::mem::size_of::<[f32; 5]>() as wgpu::BufferAddress, offset: std::mem::size_of::<[f32; 5]>() as wgpu::BufferAddress,
shader_location: 2, shader_location: 2,
format: wgpu::VertexFormat::Float32x4, format: wgpu::VertexFormat::Float32x4,
}, }
], ]
} }
} }
} }

View file

@ -1,14 +1,16 @@
use crate::{FlatMap, SparseSet}; use std::any::{Any, TypeId};
use comet_log::*; use comet_log::*;
use std::any::TypeId; use crate::{FlatMap, SparseSet};
pub type ComponentStorage = FlatMap<TypeId, SparseSet>; pub type ComponentStorage = FlatMap<TypeId, SparseSet>;
impl ComponentStorage { impl ComponentStorage {
pub fn register_component<T: 'static>(&mut self, capacity: usize) { pub fn register_component<T: 'static>(&mut self, capacity: usize) {
if !self.contains(&TypeId::of::<T>()) { if !self.contains(&TypeId::of::<T>()) {
self.insert(TypeId::of::<T>(), SparseSet::new::<T>(capacity, 1000)); self.insert(TypeId::of::<T>(), SparseSet::new::<T>(capacity, 1000));
} else { }
else {
error!("Component {:?} already exists", TypeId::of::<T>()); error!("Component {:?} already exists", TypeId::of::<T>());
} }
} }
@ -16,7 +18,8 @@ impl ComponentStorage {
pub fn deregister_component<T: 'static>(&mut self) { pub fn deregister_component<T: 'static>(&mut self) {
if self.contains(&TypeId::of::<T>()) { if self.contains(&TypeId::of::<T>()) {
self.remove(&TypeId::of::<T>()); self.remove(&TypeId::of::<T>());
} else { }
else {
error!("Component {:?} does not exist", TypeId::of::<T>()); error!("Component {:?} does not exist", TypeId::of::<T>());
} }
} }
@ -24,7 +27,8 @@ impl ComponentStorage {
pub fn set_component<T: 'static>(&mut self, index: usize, element: T) { pub fn set_component<T: 'static>(&mut self, index: usize, element: T) {
if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) { if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) {
sparse_set.insert(index, element); sparse_set.insert(index, element);
} else { }
else {
error!("Component {:?} is not registered", TypeId::of::<T>()); error!("Component {:?} is not registered", TypeId::of::<T>());
} }
} }
@ -32,7 +36,8 @@ impl ComponentStorage {
pub fn remove_component<T: 'static>(&mut self, index: usize) -> Option<T> { pub fn remove_component<T: 'static>(&mut self, index: usize) -> Option<T> {
if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) { if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) {
sparse_set.remove(index) sparse_set.remove(index)
} else { }
else {
error!("Component {:?} is not registered", TypeId::of::<T>()); error!("Component {:?} is not registered", TypeId::of::<T>());
None None
} }
@ -41,7 +46,8 @@ impl ComponentStorage {
pub fn get_component<T: 'static>(&self, index: usize) -> Option<&T> { pub fn get_component<T: 'static>(&self, index: usize) -> Option<&T> {
if let Some(sparse_set) = self.get(&TypeId::of::<T>()) { if let Some(sparse_set) = self.get(&TypeId::of::<T>()) {
sparse_set.get(index) sparse_set.get(index)
} else { }
else {
error!("Component {:?} is not registered", TypeId::of::<T>()); error!("Component {:?} is not registered", TypeId::of::<T>());
None None
} }
@ -50,7 +56,8 @@ impl ComponentStorage {
pub fn get_component_mut<T: 'static>(&mut self, index: usize) -> Option<&mut T> { pub fn get_component_mut<T: 'static>(&mut self, index: usize) -> Option<&mut T> {
if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) { if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) {
sparse_set.get_mut(index) sparse_set.get_mut(index)
} else { }
else {
error!("Component {:?} is not registered", TypeId::of::<T>()); error!("Component {:?} is not registered", TypeId::of::<T>());
None None
} }

View file

@ -1,11 +1,9 @@
use comet::prelude::*; use comet::prelude::*;
// This function will only be called once before the event loop starts. // This function will only be called once before the event loop starts.
#[allow(unused_variables)]
fn setup(app: &mut App, renderer: &mut Renderer2D) {} fn setup(app: &mut App, renderer: &mut Renderer2D) {}
// This function will be called on every tick after the event loop starts. // This function will be called on every tick after the event loop starts.
#[allow(unused_variables)]
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {} fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {}
fn main() { fn main() {

View file

@ -43,7 +43,6 @@ fn setup(app: &mut App, renderer: &mut Renderer2D) {
} }
} }
#[allow(unused_variables)]
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {} fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {}
fn main() { fn main() {

View file

@ -26,7 +26,6 @@ fn setup(app: &mut App, renderer: &mut Renderer2D) {
); );
} }
#[allow(unused_variables)]
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) { fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
// Getting the windows size // Getting the windows size
let size = renderer.size(); let size = renderer.size();

View file

@ -18,7 +18,6 @@ fn setup(app: &mut App, renderer: &mut Renderer2D) {
app.add_component(e0, render); app.add_component(e0, render);
} }
#[allow(unused_variables)]
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) { fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
renderer.render_scene_2d(app.scene_mut()) renderer.render_scene_2d(app.scene_mut())
} }