mirror of
https://github.com/lisk77/comet.git
synced 2025-12-12 09:08:49 +00:00
chore(all): fix warnings
This commit is contained in:
parent
c7f0412eff
commit
81bc1cb790
14 changed files with 471 additions and 513 deletions
|
|
@ -33,7 +33,6 @@ pub struct App {
|
|||
game_state: Option<Box<dyn Any>>,
|
||||
audio: Box<dyn Audio>,
|
||||
scene: Scene,
|
||||
fullscreen: bool,
|
||||
should_quit: bool,
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +50,6 @@ impl App {
|
|||
game_state: None,
|
||||
audio: Box::new(KiraAudio::new()),
|
||||
scene: Scene::new(),
|
||||
fullscreen: false,
|
||||
should_quit: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -372,6 +370,7 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
ref event,
|
||||
|
|
|
|||
|
|
@ -2,16 +2,12 @@ extern crate proc_macro;
|
|||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, DeriveInput, Data, Fields};
|
||||
use syn::{parse_macro_input, Data, DeriveInput, Fields};
|
||||
|
||||
// This is the procedural macro for `derive(MyTrait)`
|
||||
#[proc_macro_derive(Component)]
|
||||
pub fn my_trait_derive(input: TokenStream) -> TokenStream {
|
||||
// Parse the input tokens into a syntax tree (AST)
|
||||
pub fn component_derive(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
|
||||
// Get the name of the struct
|
||||
let name = &input.ident;
|
||||
let name = &input.ident;
|
||||
|
||||
let fields = if let Data::Struct(data) = &input.data {
|
||||
|
|
@ -33,19 +29,21 @@ pub fn my_trait_derive(input: TokenStream) -> TokenStream {
|
|||
|
||||
let default_fields = if let Data::Struct(data) = &input.data {
|
||||
match &data.fields {
|
||||
Fields::Named(fields) => {
|
||||
// Generate code to assign each field a default value
|
||||
fields.named.iter().map(|field| {
|
||||
Fields::Named(fields) => fields
|
||||
.named
|
||||
.iter()
|
||||
.map(|field| {
|
||||
let field_name = &field.ident;
|
||||
quote! { #field_name: Default::default() }
|
||||
}).collect::<Vec<_>>()
|
||||
},
|
||||
Fields::Unnamed(fields) => {
|
||||
// Generate default values for tuple structs
|
||||
fields.unnamed.iter().map(|_field| {
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
Fields::Unnamed(fields) => fields
|
||||
.unnamed
|
||||
.iter()
|
||||
.map(|_field| {
|
||||
quote! { Default::default() }
|
||||
}).collect::<Vec<_>>()
|
||||
},
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
Fields::Unit => Vec::new(),
|
||||
}
|
||||
} else {
|
||||
|
|
@ -59,13 +57,6 @@ pub fn my_trait_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! {
|
||||
impl Component for #name {
|
||||
fn new() -> Self {
|
||||
|
|
@ -83,7 +74,6 @@ pub fn my_trait_derive(input: TokenStream) -> TokenStream {
|
|||
|
||||
impl Default for #name {
|
||||
fn default() -> Self {
|
||||
// Construct the struct with default values
|
||||
Self {
|
||||
#(#default_fields),*
|
||||
}
|
||||
|
|
@ -115,16 +105,5 @@ pub fn my_trait_derive(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
};
|
||||
|
||||
// Convert the generated code into a TokenStream and return it
|
||||
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
|
||||
}
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use comet_structs::ComponentSet;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Archetypes {
|
||||
archetypes: HashMap<ComponentSet, HashSet<u32>>
|
||||
archetypes: HashMap<ComponentSet, HashSet<u32>>,
|
||||
}
|
||||
|
||||
impl Archetypes {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
archetypes: HashMap::new()
|
||||
archetypes: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -25,10 +25,6 @@ impl Archetypes {
|
|||
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) {
|
||||
if let Some(archetype) = self.archetypes.get_mut(components) {
|
||||
archetype.insert(entity);
|
||||
|
|
@ -48,12 +44,4 @@ impl Archetypes {
|
|||
pub fn contains_archetype(&self, components: &ComponentSet) -> bool {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,12 @@
|
|||
use winit::event::{ElementState, WindowEvent, KeyEvent, Event};
|
||||
use std::collections::HashSet;
|
||||
use winit::event::WindowEvent::KeyboardInput;
|
||||
use winit::keyboard::PhysicalKey;
|
||||
use crate::keyboard::Key;
|
||||
use winit::event::{ElementState, Event, KeyEvent, WindowEvent};
|
||||
use winit::keyboard::PhysicalKey;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InputHandler {
|
||||
keys_pressed: Vec<PhysicalKey>,
|
||||
keys_held: Vec<PhysicalKey>,
|
||||
keys_released: Vec<PhysicalKey>
|
||||
keys_released: Vec<PhysicalKey>,
|
||||
}
|
||||
|
||||
impl InputHandler {
|
||||
|
|
@ -16,15 +14,17 @@ impl InputHandler {
|
|||
Self {
|
||||
keys_pressed: Vec::new(),
|
||||
keys_held: Vec::new(),
|
||||
keys_released: Vec::new()
|
||||
keys_released: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update<T>(&mut self, event: &Event<T>) {
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::KeyboardInput {
|
||||
event: KeyEvent {
|
||||
event:
|
||||
WindowEvent::KeyboardInput {
|
||||
event:
|
||||
KeyEvent {
|
||||
state,
|
||||
physical_key: PhysicalKey::Code(keycode),
|
||||
..
|
||||
|
|
@ -32,11 +32,12 @@ impl InputHandler {
|
|||
..
|
||||
},
|
||||
..
|
||||
} =>
|
||||
{
|
||||
match state {
|
||||
} => match state {
|
||||
ElementState::Pressed => {
|
||||
if self.keys_pressed.contains(&PhysicalKey::Code(keycode.clone())) {
|
||||
if self
|
||||
.keys_pressed
|
||||
.contains(&PhysicalKey::Code(keycode.clone()))
|
||||
{
|
||||
self.keys_held.push(PhysicalKey::Code(keycode.clone()));
|
||||
} else {
|
||||
self.keys_pressed.push(PhysicalKey::Code(keycode.clone()));
|
||||
|
|
@ -45,16 +46,23 @@ impl InputHandler {
|
|||
}
|
||||
ElementState::Released => {
|
||||
self.keys_released = vec![];
|
||||
if let Some(index) = self.keys_pressed.iter().position(|&x| x == PhysicalKey::Code(keycode.clone())) {
|
||||
if let Some(index) = self
|
||||
.keys_pressed
|
||||
.iter()
|
||||
.position(|&x| x == PhysicalKey::Code(keycode.clone()))
|
||||
{
|
||||
self.keys_pressed.remove(index);
|
||||
}
|
||||
if let Some(index) = self.keys_held.iter().position(|&x| x == PhysicalKey::Code(keycode.clone())) {
|
||||
if let Some(index) = self
|
||||
.keys_held
|
||||
.iter()
|
||||
.position(|&x| x == PhysicalKey::Code(keycode.clone()))
|
||||
{
|
||||
self.keys_held.remove(index);
|
||||
}
|
||||
self.keys_released.push(PhysicalKey::Code(keycode.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use comet_ecs::{Camera2D, Transform2D};
|
||||
use comet_log::fatal;
|
||||
use comet_math::{m4, v2, v3};
|
||||
|
||||
pub struct CameraManager {
|
||||
|
|
@ -15,16 +14,6 @@ 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 {
|
||||
self.cameras.get(self.active_camera).unwrap()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
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};
|
||||
use ab_glyph::{point, Font as AbFont, FontArc, Glyph, PxScale, ScaleFont};
|
||||
use image::{DynamicImage, Rgba, RgbaImage};
|
||||
|
||||
pub struct GlyphData {
|
||||
pub name: String,
|
||||
|
|
@ -25,7 +24,7 @@ impl Font {
|
|||
name: path.to_string(),
|
||||
size,
|
||||
line_height,
|
||||
glyphs
|
||||
glyphs,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,19 +101,20 @@ impl Font {
|
|||
image.put_pixel(x, y, Rgba([255, 255, 255, alpha]));
|
||||
});
|
||||
|
||||
glyphs.push(
|
||||
GlyphData {
|
||||
glyphs.push(GlyphData {
|
||||
name: ch.to_string(),
|
||||
render: DynamicImage::ImageRgba8(image),
|
||||
advance: scaled_font.h_advance(glyph_id),
|
||||
offset_x: bounds.min.x,
|
||||
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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,20 @@
|
|||
use std::{
|
||||
collections::HashMap, path::Path
|
||||
};
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
||||
use wgpu::{Device, FilterMode, Queue, TextureFormat, TextureUsages};
|
||||
use crate::{texture, Texture};
|
||||
use crate::texture_atlas::{TextureAtlas, TextureRegion};
|
||||
use crate::{
|
||||
texture,
|
||||
texture_atlas::{TextureAtlas, TextureRegion},
|
||||
};
|
||||
|
||||
pub struct ResourceManager {
|
||||
texture_atlas: TextureAtlas,
|
||||
data_files: HashMap<String, String>
|
||||
data_files: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl ResourceManager {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
texture_atlas: TextureAtlas::empty(),
|
||||
data_files: HashMap::new()
|
||||
data_files: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ impl TextureAtlas {
|
|||
for glyph_name in glyph_names {
|
||||
let region = font.glyphs().textures().get(&glyph_name).unwrap();
|
||||
|
||||
let (u0, v0, u1, v1) = (region.u0(), region.v0(), region.u1(), region.v1());
|
||||
let (u0, v0) = (region.u0(), region.v0());
|
||||
let (width, height) = region.dimensions();
|
||||
|
||||
let src_x = (u0 * font.glyphs().atlas().width() as f32) as u32;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
use wgpu::Color;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable, PartialEq)]
|
||||
pub struct Vertex {
|
||||
position: [f32; 3],
|
||||
tex_coords: [f32; 2],
|
||||
color: [f32; 4]
|
||||
color: [f32; 4],
|
||||
}
|
||||
|
||||
impl Vertex {
|
||||
|
|
@ -13,7 +11,7 @@ impl Vertex {
|
|||
Self {
|
||||
position,
|
||||
tex_coords,
|
||||
color
|
||||
color,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,8 +46,8 @@ impl Vertex {
|
|||
offset: std::mem::size_of::<[f32; 5]>() as wgpu::BufferAddress,
|
||||
shader_location: 2,
|
||||
format: wgpu::VertexFormat::Float32x4,
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
use std::any::{Any, TypeId};
|
||||
use comet_log::*;
|
||||
use crate::{FlatMap, SparseSet};
|
||||
use comet_log::*;
|
||||
use std::any::TypeId;
|
||||
|
||||
pub type ComponentStorage = FlatMap<TypeId, SparseSet>;
|
||||
|
||||
impl ComponentStorage {
|
||||
|
||||
pub fn register_component<T: 'static>(&mut self, capacity: usize) {
|
||||
if !self.contains(&TypeId::of::<T>()) {
|
||||
self.insert(TypeId::of::<T>(), SparseSet::new::<T>(capacity, 1000));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error!("Component {:?} already exists", TypeId::of::<T>());
|
||||
}
|
||||
}
|
||||
|
|
@ -18,8 +16,7 @@ impl ComponentStorage {
|
|||
pub fn deregister_component<T: 'static>(&mut self) {
|
||||
if self.contains(&TypeId::of::<T>()) {
|
||||
self.remove(&TypeId::of::<T>());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error!("Component {:?} does not exist", TypeId::of::<T>());
|
||||
}
|
||||
}
|
||||
|
|
@ -27,8 +24,7 @@ impl ComponentStorage {
|
|||
pub fn set_component<T: 'static>(&mut self, index: usize, element: T) {
|
||||
if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) {
|
||||
sparse_set.insert(index, element);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error!("Component {:?} is not registered", TypeId::of::<T>());
|
||||
}
|
||||
}
|
||||
|
|
@ -36,8 +32,7 @@ impl ComponentStorage {
|
|||
pub fn remove_component<T: 'static>(&mut self, index: usize) -> Option<T> {
|
||||
if let Some(sparse_set) = self.get_mut(&TypeId::of::<T>()) {
|
||||
sparse_set.remove(index)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error!("Component {:?} is not registered", TypeId::of::<T>());
|
||||
None
|
||||
}
|
||||
|
|
@ -46,8 +41,7 @@ impl ComponentStorage {
|
|||
pub fn get_component<T: 'static>(&self, index: usize) -> Option<&T> {
|
||||
if let Some(sparse_set) = self.get(&TypeId::of::<T>()) {
|
||||
sparse_set.get(index)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error!("Component {:?} is not registered", TypeId::of::<T>());
|
||||
None
|
||||
}
|
||||
|
|
@ -56,8 +50,7 @@ impl ComponentStorage {
|
|||
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>()) {
|
||||
sparse_set.get_mut(index)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error!("Component {:?} is not registered", TypeId::of::<T>());
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
use comet::prelude::*;
|
||||
|
||||
// This function will only be called once before the event loop starts.
|
||||
#[allow(unused_variables)]
|
||||
fn setup(app: &mut App, renderer: &mut Renderer2D) {}
|
||||
|
||||
// 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 main() {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
|||
);
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
// Getting the windows size
|
||||
let size = renderer.size();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ fn setup(app: &mut App, renderer: &mut Renderer2D) {
|
|||
app.add_component(e0, render);
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {
|
||||
renderer.render_scene_2d(app.scene_mut())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue