aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:22 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:22 +0100
commit767b1c878532924775d5be7307e5aec10872e443 (patch)
treefcce38e88c3ffdb444095a1a90aee3c62c5afb68
parente8126750633fd9ed3e682a2c889740a1f51a86f7 (diff)
chore(all): fix lints
-rw-r--r--stockton-input/src/manager.rs18
-rw-r--r--stockton-render/src/draw/buffer.rs7
-rw-r--r--stockton-render/src/draw/context.rs39
-rw-r--r--stockton-render/src/draw/draw_buffers.rs5
-rw-r--r--stockton-render/src/draw/target.rs25
-rw-r--r--stockton-render/src/draw/texture/chunk.rs10
-rw-r--r--stockton-render/src/draw/texture/image.rs75
-rw-r--r--stockton-render/src/draw/texture/loader.rs16
-rw-r--r--stockton-render/src/draw/texture/mod.rs5
-rw-r--r--stockton-render/src/draw/texture/resolver.rs1
-rw-r--r--stockton-render/src/draw/ui/render.rs4
-rwxr-xr-xstockton-render/src/draw/ui/texture.rs41
-rw-r--r--stockton-render/src/draw/utils.rs18
-rw-r--r--stockton-render/src/lib.rs4
-rw-r--r--stockton-render/src/systems.rs4
-rw-r--r--stockton-render/src/types.rs2
-rw-r--r--stockton-render/src/window.rs48
17 files changed, 164 insertions, 158 deletions
diff --git a/stockton-input/src/manager.rs b/stockton-input/src/manager.rs
index 663b6b8..6169f3b 100644
--- a/stockton-input/src/manager.rs
+++ b/stockton-input/src/manager.rs
@@ -28,17 +28,18 @@ pub enum MouseButton {
Left,
Right,
Middle,
- Other(u8)
+ Other(u8),
}
impl MouseButton {
fn keycode(&self) -> u32 {
- u32::MAX - match self {
- MouseButton::Left => 0,
- MouseButton::Right => 1,
- MouseButton::Middle => 2,
- MouseButton::Other(x) => *x as u32
- }
+ u32::MAX
+ - match self {
+ MouseButton::Left => 0,
+ MouseButton::Right => 1,
+ MouseButton::Middle => 2,
+ MouseButton::Other(x) => *x as u32,
+ }
}
}
@@ -48,7 +49,7 @@ pub enum Action {
KeyPress(u32),
KeyRelease(u32),
MousePress(MouseButton),
- MouseRelease(MouseButton)
+ MouseRelease(MouseButton),
}
impl Action {
@@ -58,7 +59,6 @@ impl Action {
Action::KeyRelease(x) => *x,
Action::MousePress(x) => x.keycode(),
Action::MouseRelease(x) => x.keycode(),
-
}
}
pub fn is_down(&self) -> bool {
diff --git a/stockton-render/src/draw/buffer.rs b/stockton-render/src/draw/buffer.rs
index 5d88e25..1485c44 100644
--- a/stockton-render/src/draw/buffer.rs
+++ b/stockton-render/src/draw/buffer.rs
@@ -21,12 +21,7 @@ use std::iter::once;
use std::ops::{Index, IndexMut};
use hal::prelude::*;
-use hal::{
- buffer::Usage,
- memory::Properties,
- queue::Submission,
- MemoryTypeId,
-};
+use hal::{buffer::Usage, memory::Properties, queue::Submission, MemoryTypeId};
use crate::error::CreationError;
use crate::types::*;
diff --git a/stockton-render/src/draw/context.rs b/stockton-render/src/draw/context.rs
index 8f4b549..139c59a 100644
--- a/stockton-render/src/draw/context.rs
+++ b/stockton-render/src/draw/context.rs
@@ -25,8 +25,8 @@ use arrayvec::ArrayVec;
use hal::{pool::CommandPoolCreateFlags, prelude::*};
use log::debug;
use na::Mat4;
-use winit::window::Window;
use rendy_memory::DynamicConfig;
+use winit::window::Window;
use super::{
buffer::ModifiableBuffer,
@@ -161,9 +161,9 @@ impl<'a> RenderingContext<'a> {
// Memory allocators
let mut texture_allocator = unsafe {
use hal::{
- memory::Properties,
- image::{Kind, Tiling, Usage, ViewCapabilities},
format::Format,
+ image::{Kind, Tiling, Usage, ViewCapabilities},
+ memory::Properties,
};
// We create an empty image with the same format as used for textures
@@ -175,29 +175,32 @@ impl<'a> RenderingContext<'a> {
// TODO: Way to tune these options
- let img = device.create_image(
- Kind::D2(16 as u32, 16 as u32, 1, 1),
- 1,
- Format::Rgba8Srgb,
- Tiling::Optimal,
- Usage::SAMPLED,
- ViewCapabilities::empty()
- ).map_err(|_| error::CreationError::OutOfMemoryError)?;
+ let img = device
+ .create_image(
+ Kind::D2(16, 16, 1, 1),
+ 1,
+ Format::Rgba8Srgb,
+ Tiling::Optimal,
+ Usage::SAMPLED,
+ ViewCapabilities::empty(),
+ )
+ .map_err(|_| error::CreationError::OutOfMemoryError)?;
let type_mask = device.get_image_requirements(&img).type_mask;
device.destroy_image(img);
let props = Properties::DEVICE_LOCAL;
-
+
DynamicAllocator::new(
- find_memory_type_id(&adapter, type_mask, props).ok_or(error::CreationError::OutOfMemoryError)?,
+ find_memory_type_id(&adapter, type_mask, props)
+ .ok_or(error::CreationError::OutOfMemoryError)?,
props,
DynamicConfig {
block_size_granularity: 4 * 32 * 32, // 32x32 image
max_chunk_size: u64::pow(2, 63),
min_device_allocation: 4 * 32 * 32,
- }
+ },
)
};
@@ -276,7 +279,7 @@ impl<'a> RenderingContext<'a> {
ui_draw_buffers: ManuallyDrop::new(ui_draw_buffers),
ui_texture_store: ManuallyDrop::new(ui_texture_store),
-
+
texture_allocator: ManuallyDrop::new(texture_allocator),
vp_matrix: Mat4::identity(),
@@ -433,8 +436,10 @@ impl<'a> core::ops::Drop for RenderingContext<'a> {
ManuallyDrop::into_inner(read(&self.draw_buffers)).deactivate(&mut self.device);
ManuallyDrop::into_inner(read(&self.ui_draw_buffers)).deactivate(&mut self.device);
- ManuallyDrop::into_inner(read(&self.texture_store)).deactivate(&mut self.device, &mut self.texture_allocator);
- ManuallyDrop::into_inner(read(&self.ui_texture_store)).deactivate(&mut self.device, &mut self.texture_allocator);
+ ManuallyDrop::into_inner(read(&self.texture_store))
+ .deactivate(&mut self.device, &mut self.texture_allocator);
+ ManuallyDrop::into_inner(read(&self.ui_texture_store))
+ .deactivate(&mut self.device, &mut self.texture_allocator);
ManuallyDrop::into_inner(read(&self.texture_allocator)).dispose();
diff --git a/stockton-render/src/draw/draw_buffers.rs b/stockton-render/src/draw/draw_buffers.rs
index 837356a..02625ad 100644
--- a/stockton-render/src/draw/draw_buffers.rs
+++ b/stockton-render/src/draw/draw_buffers.rs
@@ -37,7 +37,10 @@ pub struct DrawBuffers<'a, T: Sized> {
}
impl<'a, T> DrawBuffers<'a, T> {
- pub fn new(device: &mut Device, adapter: &Adapter) -> Result<DrawBuffers<'a, T>, CreationError> {
+ pub fn new(
+ device: &mut Device,
+ adapter: &Adapter,
+ ) -> Result<DrawBuffers<'a, T>, CreationError> {
let vert = StagedBuffer::new(device, &adapter, Usage::VERTEX, INITIAL_VERT_SIZE)?;
let index = StagedBuffer::new(device, &adapter, Usage::INDEX, INITIAL_INDEX_SIZE)?;
diff --git a/stockton-render/src/draw/target.rs b/stockton-render/src/draw/target.rs
index 02a7f84..2183a90 100644
--- a/stockton-render/src/draw/target.rs
+++ b/stockton-render/src/draw/target.rs
@@ -31,8 +31,11 @@ use hal::{
use na::Mat4;
use super::{
- buffer::ModifiableBuffer, draw_buffers::{DrawBuffers, UVPoint}, pipeline::CompletePipeline,
- texture::image::DedicatedLoadedImage, ui::{UIPipeline, UIPoint},
+ buffer::ModifiableBuffer,
+ draw_buffers::{DrawBuffers, UVPoint},
+ pipeline::CompletePipeline,
+ texture::image::DedicatedLoadedImage,
+ ui::{UIPipeline, UIPoint},
};
use crate::types::*;
@@ -53,8 +56,18 @@ pub struct SwapchainProperties {
pub extent: Extent,
}
+/// Indicates the given property has no acceptable values
+pub enum NoSupportedValuesError {
+ DepthFormat,
+ PresentMode,
+ CompositeAlphaMode,
+}
+
impl SwapchainProperties {
- pub fn find_best(adapter: &Adapter, surface: &Surface) -> Result<SwapchainProperties, ()> {
+ pub fn find_best(
+ adapter: &Adapter,
+ surface: &Surface,
+ ) -> Result<SwapchainProperties, NoSupportedValuesError> {
let caps = surface.capabilities(&adapter.physical_device);
let formats = surface.supported_formats(&adapter.physical_device);
@@ -83,7 +96,7 @@ impl SwapchainProperties {
.optimal_tiling
.contains(ImageFeature::DEPTH_STENCIL_ATTACHMENT)
})
- .ok_or(())?;
+ .ok_or(NoSupportedValuesError::DepthFormat)?;
let present_mode = {
[
@@ -95,7 +108,7 @@ impl SwapchainProperties {
.iter()
.cloned()
.find(|pm| caps.present_modes.contains(*pm))
- .ok_or(())?
+ .ok_or(NoSupportedValuesError::PresentMode)?
};
let composite_alpha_mode = {
[
@@ -107,7 +120,7 @@ impl SwapchainProperties {
.iter()
.cloned()
.find(|ca| caps.composite_alpha_modes.contains(*ca))
- .ok_or(())?
+ .ok_or(NoSupportedValuesError::CompositeAlphaMode)?
};
let extent = caps.extents.end().to_extent(); // Size
diff --git a/stockton-render/src/draw/texture/chunk.rs b/stockton-render/src/draw/texture/chunk.rs
index b95e863..0cb6737 100644
--- a/stockton-render/src/draw/texture/chunk.rs
+++ b/stockton-render/src/draw/texture/chunk.rs
@@ -101,7 +101,15 @@ impl TextureChunk {
for tex in textures {
if let Some(img) = resolver.resolve(tex) {
store
- .put_texture(img, local_idx, device, adapter, allocator, command_queue, command_pool)
+ .put_texture(
+ img,
+ local_idx,
+ device,
+ adapter,
+ allocator,
+ command_queue,
+ command_pool,
+ )
.unwrap();
} else {
// Texture not found. For now, tear everything down.
diff --git a/stockton-render/src/draw/texture/image.rs b/stockton-render/src/draw/texture/image.rs
index bd8058b..7cf84a7 100644
--- a/stockton-render/src/draw/texture/image.rs
+++ b/stockton-render/src/draw/texture/image.rs
@@ -29,8 +29,8 @@ use hal::{
MemoryTypeId,
};
use image::RgbaImage;
-use std::{convert::TryInto, iter::once};
use rendy_memory::{Allocator, Block};
+use std::{convert::TryInto, iter::once};
use crate::draw::buffer::create_buffer;
use crate::types::*;
@@ -42,7 +42,7 @@ const PIXEL_SIZE: usize = size_of::<u8>() * 4;
pub trait LoadableImage {
fn width(&self) -> u32;
fn height(&self) -> u32;
- fn copy_row(&self, y: u32, ptr: *mut u8) -> ();
+ fn copy_row(&self, y: u32, ptr: *mut u8);
}
impl LoadableImage for RgbaImage {
@@ -54,7 +54,7 @@ impl LoadableImage for RgbaImage {
self.height()
}
- fn copy_row(&self, y: u32, ptr: *mut u8) -> () {
+ fn copy_row(&self, y: u32, ptr: *mut u8) {
let row_size_bytes = self.width() as usize * PIXEL_SIZE;
let raw: &Vec<u8> = self.as_raw();
let row = &raw[y as usize * row_size_bytes..(y as usize + 1) * row_size_bytes];
@@ -113,12 +113,9 @@ pub fn create_image_view(
let (block, _) = unsafe {
let requirements = device.get_image_requirements(&image_ref);
- allocator.alloc(
- device,
- requirements.size,
- requirements.alignment
- )
- }.map_err(|_| "Out of memory")?;
+ allocator.alloc(device, requirements.size, requirements.alignment)
+ }
+ .map_err(|_| "Out of memory")?;
unsafe {
device
@@ -140,7 +137,8 @@ impl LoadedImage {
width: usize,
height: usize,
) -> Result<LoadedImage, &'static str> {
- let (memory, image_ref) = create_image_view(device, adapter, allocator, format, usage, width, height)?;
+ let (memory, image_ref) =
+ create_image_view(device, adapter, allocator, format, usage, width, height)?;
// Create ImageView and sampler
let image_view = unsafe {
@@ -161,7 +159,6 @@ impl LoadedImage {
img: T,
device: &mut Device,
adapter: &Adapter,
- allocator: &mut DynamicAllocator,
command_queue: &mut CommandQueue,
command_pool: &mut CommandPool,
) -> Result<(), &'static str> {
@@ -186,9 +183,11 @@ impl LoadedImage {
// Copy everything into it
unsafe {
- let mapped_memory: *mut u8 = std::mem::transmute(device
- .map_memory(&staging_memory, 0..total_size)
- .map_err(|_| "Couldn't map buffer memory")?);
+ let mapped_memory: *mut u8 = std::mem::transmute(
+ device
+ .map_memory(&staging_memory, 0..total_size)
+ .map_err(|_| "Couldn't map buffer memory")?,
+ );
for y in 0..img.height() as usize {
let dest_base: isize = (y * row_size).try_into().unwrap();
@@ -303,36 +302,6 @@ impl LoadedImage {
Ok(())
}
- /// Load the given image into a new buffer
- pub fn load_into_new<T: LoadableImage>(
- img: T,
- device: &mut Device,
- adapter: &Adapter,
- allocator: &mut DynamicAllocator,
- command_queue: &mut CommandQueue,
- command_pool: &mut CommandPool,
- format: Format,
- usage: ImgUsage,
- ) -> Result<LoadedImage, &'static str> {
- let mut loaded_image = Self::new(
- device,
- adapter,
- allocator,
- format,
- usage | ImgUsage::TRANSFER_DST,
- SubresourceRange {
- aspects: Aspects::COLOR,
- levels: 0..1,
- layers: 0..1,
- },
- img.width() as usize,
- img.height() as usize,
- )?;
- loaded_image.load(img, device, adapter, allocator, command_queue, command_pool)?;
-
- Ok(loaded_image)
- }
-
/// Properly frees/destroys all the objects in this struct
/// Dropping without doing this is a bad idea
pub fn deactivate(self, device: &mut Device, allocator: &mut DynamicAllocator) {
@@ -410,7 +379,7 @@ impl SampledImage {
)?;
sampled_image
.image
- .load(img, device, adapter, allocator, command_queue, command_pool)?;
+ .load(img, device, adapter, command_queue, command_pool)?;
Ok(sampled_image)
}
@@ -438,7 +407,6 @@ pub struct DedicatedLoadedImage {
memory: ManuallyDrop<Memory>,
}
-
impl DedicatedLoadedImage {
pub fn new(
device: &mut Device,
@@ -455,7 +423,8 @@ impl DedicatedLoadedImage {
let limits = adapter.physical_device.limits();
let row_alignment_mask = limits.optimal_buffer_copy_pitch_alignment as u32 - 1;
- let row_size = ((initial_row_size as u32 + row_alignment_mask) & !row_alignment_mask) as usize;
+ let row_size =
+ ((initial_row_size as u32 + row_alignment_mask) & !row_alignment_mask) as usize;
debug_assert!(row_size as usize >= initial_row_size);
// Make the image
@@ -474,7 +443,7 @@ impl DedicatedLoadedImage {
.map_err(|_| "Couldn't create image")?;
// Allocate memory
-
+
// Allocate memory
let memory = unsafe {
let requirements = device.get_image_requirements(&image_ref);
@@ -549,9 +518,11 @@ impl DedicatedLoadedImage {
// Copy everything into it
unsafe {
- let mapped_memory: *mut u8 = std::mem::transmute(device
- .map_memory(&staging_memory, 0..total_size)
- .map_err(|_| "Couldn't map buffer memory")?);
+ let mapped_memory: *mut u8 = std::mem::transmute(
+ device
+ .map_memory(&staging_memory, 0..total_size)
+ .map_err(|_| "Couldn't map buffer memory")?,
+ );
for y in 0..img.height() as usize {
let dest_base: isize = (y * row_size).try_into().unwrap();
@@ -705,4 +676,4 @@ impl DedicatedLoadedImage {
device.free_memory(ManuallyDrop::into_inner(read(&self.memory)));
}
}
-} \ No newline at end of file
+}
diff --git a/stockton-render/src/draw/texture/loader.rs b/stockton-render/src/draw/texture/loader.rs
index 9385d96..0cfe0c3 100644
--- a/stockton-render/src/draw/texture/loader.rs
+++ b/stockton-render/src/draw/texture/loader.rs
@@ -64,9 +64,7 @@ impl TextureStore {
// Descriptor pool, where we get our sets from
let mut descriptor_pool = unsafe {
- use hal::pso::{
- DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType,
- };
+ use hal::pso::{DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType};
device
.create_descriptor_pool(
@@ -91,9 +89,7 @@ impl TextureStore {
// Layout of our descriptor sets
let descriptor_set_layout = unsafe {
- use hal::pso::{
- DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags,
- };
+ use hal::pso::{DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags};
device.create_descriptor_set_layout(
&[
@@ -171,9 +167,7 @@ impl TextureStore {
// Descriptor pool, where we get our sets from
let mut descriptor_pool = unsafe {
- use hal::pso::{
- DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType,
- };
+ use hal::pso::{DescriptorPoolCreateFlags, DescriptorRangeDesc, DescriptorType};
device
.create_descriptor_pool(
@@ -198,9 +192,7 @@ impl TextureStore {
// Layout of our descriptor sets
let descriptor_set_layout = unsafe {
- use hal::pso::{
- DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags,
- };
+ use hal::pso::{DescriptorSetLayoutBinding, DescriptorType, ShaderStageFlags};
device.create_descriptor_set_layout(
&[
diff --git a/stockton-render/src/draw/texture/mod.rs b/stockton-render/src/draw/texture/mod.rs
index ec36502..3878472 100644
--- a/stockton-render/src/draw/texture/mod.rs
+++ b/stockton-render/src/draw/texture/mod.rs
@@ -17,11 +17,14 @@
//! Everything related to loading textures into GPU memory
+// Since this is in the process of being rewritten, we ignore this for now
+#![allow(clippy::too_many_arguments)]
+
mod chunk;
pub mod image;
pub mod loader;
mod resolver;
+pub use self::image::LoadableImage;
pub use self::image::{LoadedImage, SampledImage};
pub use self::loader::TextureStore;
-pub use self::image::LoadableImage; \ No newline at end of file
diff --git a/stockton-render/src/draw/texture/resolver.rs b/stockton-render/src/draw/texture/resolver.rs
index 610d43a..668ea32 100644
--- a/stockton-render/src/draw/texture/resolver.rs
+++ b/stockton-render/src/draw/texture/resolver.rs
@@ -26,7 +26,6 @@ use std::path::Path;
/// An object that can be used to resolve a texture from a BSP File
pub trait TextureResolver<T: LoadableImage> {
-
/// Get the given texture, or None if it's corrupt/not there.
fn resolve(&mut self, texture: &Texture) -> Option<T>;
}
diff --git a/stockton-render/src/draw/ui/render.rs b/stockton-render/src/draw/ui/render.rs
index ad23dfb..02135e5 100644
--- a/stockton-render/src/draw/ui/render.rs
+++ b/stockton-render/src/draw/ui/render.rs
@@ -17,7 +17,6 @@
use crate::draw::texture::TextureStore;
use arrayvec::ArrayVec;
-use egui::Pos2;
use hal::prelude::*;
use hal::pso::ShaderStageFlags;
@@ -26,7 +25,6 @@ use crate::draw::draw_buffers::DrawBuffers;
use crate::types::*;
use crate::UIState;
use std::convert::TryInto;
-use std::mem::transmute;
use stockton_types::Vector2;
pub fn do_render(
@@ -45,7 +43,7 @@ pub fn do_render(
&pipeline_layout,
ShaderStageFlags::VERTEX,
0,
- &[transmute(screen.x), transmute(screen.y)],
+ &[screen.x.to_bits(), screen.y.to_bits()],
);
}
diff --git a/stockton-render/src/draw/ui/texture.rs b/stockton-render/src/draw/ui/texture.rs
index 52580e5..98688de 100755
--- a/stockton-render/src/draw/ui/texture.rs
+++ b/stockton-render/src/draw/ui/texture.rs
@@ -14,10 +14,10 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use egui::Texture;
+use crate::draw::texture::{LoadableImage, TextureStore};
use crate::types::*;
-use crate::draw::texture::{TextureStore, LoadableImage};
use crate::UIState;
+use egui::Texture;
impl LoadableImage for &Texture {
fn width(&self) -> u32 {
@@ -26,30 +26,43 @@ impl LoadableImage for &Texture {
fn height(&self) -> u32 {
self.height as u32
}
- fn copy_row(&self, y: u32, ptr: *mut u8) -> () {
+ fn copy_row(&self, y: u32, ptr: *mut u8) {
let row_size = self.width();
let pixels = &self.pixels[(y * row_size) as usize..((y + 1) * row_size) as usize];
- for (i,x) in pixels.iter().enumerate() {
+ for (i, x) in pixels.iter().enumerate() {
unsafe {
*ptr.offset(i as isize * 3) = *x;
*ptr.offset((i as isize * 3) + 1) = *x;
*ptr.offset((i as isize * 3) + 2) = *x;
}
- }
+ }
}
}
-pub fn ensure_textures(texture_store: &mut TextureStore, ui: &mut UIState,
- device: &mut Device,
- adapter: &mut Adapter,
- allocator: &mut DynamicAllocator,
- command_queue: &mut CommandQueue,
- command_pool: &mut CommandPool) {
+pub fn ensure_textures(
+ texture_store: &mut TextureStore,
+ ui: &mut UIState,
+ device: &mut Device,
+ adapter: &mut Adapter,
+ allocator: &mut DynamicAllocator,
+ command_queue: &mut CommandQueue,
+ command_pool: &mut CommandPool,
+) {
let tex = ui.ctx.texture();
if tex.version != ui.last_tex_ver {
- texture_store.put_texture(0, &*tex, device, adapter, allocator, command_queue, command_pool).unwrap(); // TODO
+ texture_store
+ .put_texture(
+ 0,
+ &*tex,
+ device,
+ adapter,
+ allocator,
+ command_queue,
+ command_pool,
+ )
+ .unwrap(); // TODO
ui.last_tex_ver = tex.version;
- }
-} \ No newline at end of file
+ }
+}
diff --git a/stockton-render/src/draw/utils.rs b/stockton-render/src/draw/utils.rs
index e175e47..97d303e 100644
--- a/stockton-render/src/draw/utils.rs
+++ b/stockton-render/src/draw/utils.rs
@@ -16,13 +16,13 @@
*/
use crate::types::*;
-use hal::{
- memory::{Properties as MemProperties},
- MemoryTypeId,
- prelude::*,
-};
+use hal::{memory::Properties as MemProperties, prelude::*, MemoryTypeId};
-pub fn find_memory_type_id(adapter: &Adapter, type_mask: u64, props: MemProperties) -> Option<MemoryTypeId> {
+pub fn find_memory_type_id(
+ adapter: &Adapter,
+ type_mask: u64,
+ props: MemProperties,
+) -> Option<MemoryTypeId> {
adapter
.physical_device
.memory_properties()
@@ -30,9 +30,7 @@ pub fn find_memory_type_id(adapter: &Adapter, type_mask: u64, props: MemProperti
.iter()
.enumerate()
.find(|&(id, memory_type)| {
- type_mask & (1 << id) != 0 &&
- memory_type.properties.contains(props)
+ type_mask & (1 << id) != 0 && memory_type.properties.contains(props)
})
.map(|(id, _)| MemoryTypeId(id))
-
-} \ No newline at end of file
+}
diff --git a/stockton-render/src/lib.rs b/stockton-render/src/lib.rs
index 221bdd5..fbbb329 100644
--- a/stockton-render/src/lib.rs
+++ b/stockton-render/src/lib.rs
@@ -26,9 +26,9 @@ extern crate legion;
mod culling;
pub mod draw;
mod error;
+pub mod systems;
mod types;
pub mod window;
-pub mod systems;
use culling::get_visible_faces;
use draw::RenderingContext;
@@ -37,7 +37,7 @@ use legion::IntoQuery;
use std::sync::mpsc::{Receiver, Sender};
use std::sync::Arc;
use std::sync::RwLock;
-pub use window::{WindowEvent, UIState};
+pub use window::{UIState, WindowEvent};
use stockton_levels::prelude::*;
use stockton_types::components::{CameraSettings, Transform};
diff --git a/stockton-render/src/systems.rs b/stockton-render/src/systems.rs
index 8001e1b..48c7b43 100644
--- a/stockton-render/src/systems.rs
+++ b/stockton-render/src/systems.rs
@@ -15,6 +15,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-pub use crate::window::process_window_events_system;
+pub use crate::do_render_system;
pub use crate::draw::calc_vp_matrix_system;
-pub use crate::do_render_system; \ No newline at end of file
+pub use crate::window::process_window_events_system;
diff --git a/stockton-render/src/types.rs b/stockton-render/src/types.rs
index f6187c2..cf0b025 100644
--- a/stockton-render/src/types.rs
+++ b/stockton-render/src/types.rs
@@ -43,4 +43,4 @@ pub type Adapter = hal::adapter::Adapter<back::Backend>;
pub type QueueGroup = hal::queue::QueueGroup<back::Backend>;
pub type DynamicAllocator = rendy_memory::DynamicAllocator<back::Backend>;
-pub type DynamicBlock = rendy_memory::DynamicBlock<back::Backend>; \ No newline at end of file
+pub type DynamicBlock = rendy_memory::DynamicBlock<back::Backend>;
diff --git a/stockton-render/src/window.rs b/stockton-render/src/window.rs
index e122dea..e6bd5b0 100644
--- a/stockton-render/src/window.rs
+++ b/stockton-render/src/window.rs
@@ -15,27 +15,29 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use log::debug;
-use std::sync::Arc;
-use egui::Context;
use crate::Renderer;
+use egui::Context;
use legion::systems::Runnable;
+use log::debug;
+use std::sync::Arc;
-use egui::{RawInput, Ui, Pos2, Output, PaintJobs};
+use egui::{Output, PaintJobs, Pos2, RawInput, Ui};
use stockton_input::{Action as KBAction, InputManager, Mouse};
-use winit::event::{ElementState, Event as WinitEvent, WindowEvent as WinitWindowEvent, MouseButton};
+use winit::event::{
+ ElementState, Event as WinitEvent, MouseButton, WindowEvent as WinitWindowEvent,
+};
use winit::event_loop::ControlFlow;
#[derive(Debug, Clone, Copy)]
pub enum WindowEvent {
- SizeChanged (u32, u32),
+ SizeChanged(u32, u32),
CloseRequested,
KeyboardAction(KBAction),
MouseAction(KBAction),
MouseMoved(f32, f32),
- MouseLeft
+ MouseLeft,
}
impl WindowEvent {
@@ -44,7 +46,9 @@ impl WindowEvent {
match winit_event {
WinitEvent::WindowEvent { event, .. } => match event {
WinitWindowEvent::CloseRequested => Some(WindowEvent::CloseRequested),
- WinitWindowEvent::Resized(size) => Some(WindowEvent::SizeChanged (size.width, size.height)),
+ WinitWindowEvent::Resized(size) => {
+ Some(WindowEvent::SizeChanged(size.width, size.height))
+ }
WinitWindowEvent::KeyboardInput { input, .. } => match input.state {
ElementState::Pressed => Some(WindowEvent::KeyboardAction(KBAction::KeyPress(
input.scancode,
@@ -63,14 +67,18 @@ impl WindowEvent {
MouseButton::Left => stockton_input::MouseButton::Left,
MouseButton::Right => stockton_input::MouseButton::Right,
MouseButton::Middle => stockton_input::MouseButton::Middle,
- MouseButton::Other(x) => stockton_input::MouseButton::Other(*x)
+ MouseButton::Other(x) => stockton_input::MouseButton::Other(*x),
};
match state {
- ElementState::Pressed => Some(WindowEvent::MouseAction(KBAction::MousePress(mb))),
- ElementState::Released => Some(WindowEvent::MouseAction(KBAction::MouseRelease(mb)))
+ ElementState::Pressed => {
+ Some(WindowEvent::MouseAction(KBAction::MousePress(mb)))
+ }
+ ElementState::Released => {
+ Some(WindowEvent::MouseAction(KBAction::MouseRelease(mb)))
+ }
}
- },
+ }
_ => None,
},
_ => None,
@@ -87,7 +95,7 @@ pub struct UIState {
}
impl UIState {
- pub fn ui<'a>(&'a mut self) -> &'a mut Ui {
+ pub fn ui(&mut self) -> &mut Ui {
if self.ui.is_none() {
self.ui = Some(self.begin_frame());
}
@@ -103,7 +111,7 @@ impl UIState {
}
fn set_mouse_pos(&mut self, x: f32, y: f32) {
- self.raw_input.mouse_pos = Some(Pos2 {x, y})
+ self.raw_input.mouse_pos = Some(Pos2 { x, y })
}
fn set_mouse_left(&mut self) {
@@ -112,7 +120,7 @@ impl UIState {
fn set_dimensions(&mut self, w: u32, h: u32) {
self.raw_input.screen_size = egui::math::Vec2 {
x: w as f32,
- y: h as f32
+ y: h as f32,
}
}
fn set_pixels_per_point(&mut self, ppp: Option<f32>) {
@@ -132,7 +140,7 @@ impl UIState {
KBAction::MouseRelease(stockton_input::MouseButton::Right) => {
self.raw_input.mouse_down = false;
}
- _ => ()
+ _ => (),
}
}
@@ -141,7 +149,7 @@ impl UIState {
ctx: Context::new(),
raw_input: RawInput::default(),
ui: None,
- last_tex_ver: 0
+ last_tex_ver: 0,
};
let props = &renderer.context.target_chain.properties;
@@ -169,7 +177,7 @@ pub fn _process_window_events<T: 'static + InputManager>(
WindowEvent::SizeChanged(w, h) => {
renderer.resize();
ui_state.set_dimensions(w, h);
- },
+ }
WindowEvent::CloseRequested => {
let mut flow = renderer.update_control_flow.write().unwrap();
// TODO: Let everything know this is our last frame
@@ -190,10 +198,10 @@ pub fn _process_window_events<T: 'static + InputManager>(
mouse_delta.y = y;
ui_state.set_mouse_pos(x, y);
- },
+ }
WindowEvent::MouseLeft => {
ui_state.set_mouse_left();
- },
+ }
WindowEvent::MouseAction(action) => {
if actions_buf_cursor >= actions_buf.len() {
actions_buf.push(action);