Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed May 16, 2023
1 parent d6680ea commit 7ad2f57
Show file tree
Hide file tree
Showing 30 changed files with 1,694 additions and 1,458 deletions.
2,780 changes: 1,468 additions & 1,312 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions gamercade_audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ repository = "https://github.com/gamercade-io/gamercade_audio"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.144", features = ["derive"] }
serde = { version = "1.0.163", features = ["derive"] }
strum = { version = "0.24.1", features = ["derive"] }
arrayvec = { version = "0.7.2", features = ["serde"] }
tinystr = "0.6.2"
rtrb = "0.2.2"
fastrand = "1.8.0"
base64 = "0.13.0"
tinystr = "0.7.1"
rtrb = "0.2.3"
fastrand = "1.9.0"
base64 = "0.21.0"
9 changes: 7 additions & 2 deletions gamercade_audio/src/instruments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub use instrument_data_definition::*;
pub use sampler::*;
pub use wavetable::*;

use base64::{engine::GeneralPurpose, Engine};
const BASE64ENGINE: GeneralPurpose = base64::engine::general_purpose::STANDARD;

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum InstrumentKind {
Sampler,
Expand All @@ -23,7 +26,9 @@ where
{
let bytes = if deserializer.is_human_readable() {
let text: String = serde::Deserialize::deserialize(deserializer)?;
base64::decode(text).map_err(serde::de::Error::custom)?
BASE64ENGINE
.decode(text)
.map_err(serde::de::Error::custom)?
} else {
serde::Deserialize::deserialize(deserializer)?
};
Expand All @@ -40,7 +45,7 @@ where
{
let data: Vec<u8> = data.iter().flat_map(|x| x.to_be_bytes()).collect();
if serializer.is_human_readable() {
let data = base64::encode(data);
let data = BASE64ENGINE.encode(data);
serializer.serialize_str(&data)
} else {
serializer.serialize_bytes(&data)
Expand Down
4 changes: 2 additions & 2 deletions gamercade_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ keywords = ["gamedev"]
[dependencies]
gamercade_fs = { path = "../gamercade_fs" }

clap = { version = "3.2.22", features = ["derive"] }
notify = "5.0.0"
clap = { version = "4.2.7", features = ["derive"] }
notify = "5.1.0"
36 changes: 18 additions & 18 deletions gamercade_console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,44 @@ gamercade_audio = { path = "../gamercade_audio" }
gamercade_sound_engine = { path = "../gamercade_sound_engine" }

# General Improvements
hashbrown = { version = "0.12.3", features = ["serde"] }
hashbrown = { version = "0.13.2", features = ["serde"] }
parking_lot = "0.12.1"

# Windowing & Graphics
winit = { version = "0.26.1", features = ["serde"] }
pixels = "0.9.0"
winit_input_helper = "0.12.0"
winit = { version = "0.28.6", features = ["serde"] }
pixels = "0.12.1"
winit_input_helper = "0.14.1"

# GUI Stuff
egui = "0.17"
egui_wgpu_backend = "0.17"
egui-winit = "0.17"
egui = "0.21.0"
egui-wgpu = "0.21.0"
egui-winit = { version = "0.21.1", default-features = false, features = ["links"] }

# Macros & Helpers
paste = "1.0.8"
paste = "1.0.12"

# Serialization / File Loading etc
serde = { version = "1.0.144", features = ["derive"] }
serde_json = "1.0.85"
bytemuck = "1.12.1"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
bytemuck = "1.13.1"

# Scripting
wasmtime = { version = "0.40.1", features = ["cranelift"] }
wasmtime = { version = "8.0.1", features = ["cranelift"] }

# Random
fastrand = "1.8.0"
fastrand = "1.9.0"

# Audio
cpal = "0.13.5"
cpal = "0.15.2"

# Networking
ggrs = "0.9.2"
ggrs = "0.9.4"

# File Picker Dialog
rfd = "0.10.0"
rfd = "0.11.3"

# Input
gilrs = "0.9.0"
gilrs = "0.10.2"

# Cli
clap = { version = "3.2.22", features = ["derive"] }
clap = { version = "4.2.7", features = ["derive"] }
6 changes: 3 additions & 3 deletions gamercade_console/src/console/bindings/draw_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::api::{DrawApi, DrawApiBinding};
use crate::console::Contexts;
use gamercade_core::BYTES_PER_PIXEL;
use paste::paste;
use wasmtime::{Caller, Extern, Linker, Trap};
use wasmtime::{Caller, Extern, Linker};

macro_rules! derive_draw_api_binding {
($($ident:ident ($($name:ident:$args:ty $(,)? )*) $(,)?)*) => {
Expand All @@ -26,7 +26,7 @@ macro_rules! derive_draw_api_binding {
|mut caller: Caller<'_, Contexts>, start_index: i32, parameters_ptr: i32, len: i32| {
let mem = match caller.get_export("memory") {
Some(Extern::Memory(mem)) => mem,
_ => return Err(Trap::new("failed to find host memory")),
_ => return Err(wasmtime::Error::msg("Failed to find hose memory")),
};

let (data, store) = mem.data_and_store_mut(&mut caller);
Expand All @@ -36,7 +36,7 @@ macro_rules! derive_draw_api_binding {
.and_then(|arr| arr.get(..len as u32 as usize * BYTES_PER_PIXEL))
{
Some(data) => bytemuck::cast_slice(data),
None => return Err(Trap::new("invalid data")),
None => return Err(wasmtime::Error::msg("Invalid data"),)
};

Ok(store.draw_context.write_pixel_buffer(start_index as usize, data))
Expand Down
14 changes: 7 additions & 7 deletions gamercade_console/src/console/bindings/text_binding.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::api::{TextApi, TextApiBinding};
use paste::paste;
use std::str;
use wasmtime::{Caller, Extern, Linker, Trap};
use wasmtime::{Caller, Extern, Linker};

use crate::console::Contexts;

Expand All @@ -17,7 +17,7 @@ macro_rules! derive_text_api_binding {
|mut caller: Caller<'_, Contexts>, text_ptr: i32, len: i32, $($name: $args,)*| {
let mem = match caller.get_export("memory") {
Some(Extern::Memory(mem)) => mem,
_ => return Err(Trap::new("failed to find host memory")),
_ => return Err(wasmtime::Error::msg("failed to find host memory")),
};

let data = match mem
Expand All @@ -26,12 +26,12 @@ macro_rules! derive_text_api_binding {
.and_then(|arr| arr.get(..len as u32 as usize))
{
Some(data) => data,
None => return Err(Trap::new("invalid data")),
None => return Err(wasmtime::Error::msg("invalid data")),
};

let text = match str::from_utf8(data) {
Ok(text) => text,
Err(_) => return Err(Trap::new("string is not valid utf-8")),
Err(_) => return Err(wasmtime::Error::msg("string is not valid utf-8")),
};

Ok(caller.data().text_context.$ident(text, $($name as $args,)*))
Expand All @@ -45,7 +45,7 @@ macro_rules! derive_text_api_binding {
|mut caller: Caller<'_, Contexts>, text_ptr: i32, len: i32, $($name: $args,)*| {
let mem = match caller.get_export("memory") {
Some(Extern::Memory(mem)) => mem,
_ => return Err(Trap::new("failed to find host memory")),
_ => return Err(wasmtime::Error::msg("failed to find host memory")),
};

let data = match mem
Expand All @@ -54,14 +54,14 @@ macro_rules! derive_text_api_binding {
.and_then(|arr| arr.get(..len as u32 as usize))
{
Some(data) => data,
None => return Err(Trap::new("invalid data")),
None => return Err(wasmtime::Error::msg("invalid data")),
};

let data = bytemuck::cast_slice(data);

let text = match String::from_utf16(data) {
Ok(text) => text,
Err(_) => return Err(Trap::new("string is not valid utf-16")),
Err(_) => return Err(wasmtime::Error::msg("string is not valid utf-16")),
};

Ok(caller.data().text_context.$ident(&text, $($name as $args,)*))
Expand Down
15 changes: 12 additions & 3 deletions gamercade_console/src/console/wasm_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::sync::Arc;
use gamercade_sound_engine::{SoundEngine, SoundEngineData, SoundRomInstance};
use ggrs::GGRSRequest;
use wasmtime::{Engine, ExternType, Instance, Linker, Module, Mutability, Store, TypedFunc};
use winit::{dpi::PhysicalPosition, window::Window};
use winit::{
dpi::PhysicalPosition,
window::{CursorGrabMode, Window},
};

type GameFunc = TypedFunc<(), ()>;

Expand Down Expand Up @@ -247,11 +250,17 @@ impl WasmConsole {
position.height / 2,
))
.unwrap();
window.set_cursor_grab(true).unwrap();
if window.set_cursor_grab(CursorGrabMode::Confined).is_err()
&& window.set_cursor_grab(CursorGrabMode::Locked).is_err()
{
println!("Error: Failed to lock mouse");
}
window.set_cursor_visible(false);
}
false => {
window.set_cursor_grab(false).unwrap();
if let Err(e) = window.set_cursor_grab(CursorGrabMode::None) {
println!("{e}");
}
window.set_cursor_visible(true);
}
}
Expand Down
76 changes: 46 additions & 30 deletions gamercade_console/src/gui/framework.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use egui::{ClippedMesh, Context, TexturesDelta};
use egui_wgpu_backend::{BackendError, RenderPass, ScreenDescriptor};
use egui::{ClippedPrimitive, Context, TexturesDelta};
use egui_wgpu::renderer::{Renderer, ScreenDescriptor};
use ggrs::P2PSession;
use gilrs::Gilrs;
use pixels::{wgpu, Pixels, PixelsContext};
use winit::event_loop::EventLoopWindowTarget;
use winit::window::Window;

use crate::console::{LocalInputManager, WasmConsole};
Expand All @@ -15,8 +16,8 @@ pub(crate) struct Framework {
egui_ctx: Context,
egui_state: egui_winit::State,
screen_descriptor: ScreenDescriptor,
rpass: RenderPass,
paint_jobs: Vec<ClippedMesh>,
renderer: Renderer,
paint_jobs: Vec<ClippedPrimitive>,
textures: TexturesDelta,

// Our stuff
Expand All @@ -25,7 +26,8 @@ pub(crate) struct Framework {

impl Framework {
/// Create egui.
pub(crate) fn new(
pub(crate) fn new<T>(
event_loop: &EventLoopWindowTarget<T>,
width: u32,
height: u32,
scale_factor: f32,
Expand All @@ -35,20 +37,21 @@ impl Framework {
let max_texture_size = pixels.device().limits().max_texture_dimension_2d as usize;

let egui_ctx = Context::default();
let egui_state = egui_winit::State::from_pixels_per_point(max_texture_size, scale_factor);
let mut egui_state = egui_winit::State::new(event_loop);
egui_state.set_max_texture_side(max_texture_size);
egui_state.set_pixels_per_point(scale_factor);
let screen_descriptor = ScreenDescriptor {
physical_width: width,
physical_height: height,
scale_factor,
size_in_pixels: [width, height],
pixels_per_point: scale_factor,
};
let rpass = RenderPass::new(pixels.device(), pixels.render_texture_format(), 1);
let renderer = Renderer::new(pixels.device(), pixels.render_texture_format(), None, 1);
let textures = TexturesDelta::default();

Self {
egui_ctx,
egui_state,
screen_descriptor,
rpass,
renderer,
paint_jobs: Vec::new(),
textures,
gui,
Expand All @@ -57,20 +60,19 @@ impl Framework {

/// Handle input events from the window manager.
pub(crate) fn handle_event(&mut self, event: &winit::event::WindowEvent) {
self.egui_state.on_event(&self.egui_ctx, event);
let _ = self.egui_state.on_event(&self.egui_ctx, event);
}

/// Resize egui.
pub(crate) fn resize(&mut self, width: u32, height: u32) {
if width > 0 && height > 0 {
self.screen_descriptor.physical_width = width;
self.screen_descriptor.physical_height = height;
self.screen_descriptor.size_in_pixels = [width, height];
}
}

/// Update scaling factor.
pub(crate) fn scale_factor(&mut self, scale_factor: f64) {
self.screen_descriptor.scale_factor = scale_factor as f32;
self.screen_descriptor.pixels_per_point = scale_factor as f32;
}

/// Prepare egui.
Expand All @@ -85,7 +87,7 @@ impl Framework {
// Run the egui frame and create all paint jobs to prepare for rendering.
let raw_input = self.egui_state.take_egui_input(window);
let output = self.egui_ctx.run(raw_input, |egui_ctx| {
// Draw the demo application.
// Draw the application.
self.gui.ui(pixels, window, session, egui_ctx, input, gilrs);
});

Expand All @@ -101,29 +103,43 @@ impl Framework {
encoder: &mut wgpu::CommandEncoder,
render_target: &wgpu::TextureView,
context: &PixelsContext,
) -> Result<(), BackendError> {
) {
// Upload all resources to the GPU.
self.rpass
.add_textures(&context.device, &context.queue, &self.textures)?;

self.rpass.update_buffers(
for (id, image_delta) in &self.textures.set {
self.renderer
.update_texture(&context.device, &context.queue, *id, image_delta);
}
self.renderer.update_buffers(
&context.device,
&context.queue,
encoder,
&self.paint_jobs,
&self.screen_descriptor,
);

// Record all render passes.
self.rpass.execute(
encoder,
render_target,
&self.paint_jobs,
&self.screen_descriptor,
None,
)?;
// Render egui with WGPU
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("egui"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: render_target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
})],
depth_stencil_attachment: None,
});

self.renderer
.render(&mut rpass, &self.paint_jobs, &self.screen_descriptor);
}

// Cleanup
let textures = std::mem::take(&mut self.textures);
self.rpass.remove_textures(textures)
for id in &textures.free {
self.renderer.free_texture(id);
}
}
}
4 changes: 3 additions & 1 deletion gamercade_console/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ impl Gui {
window: &Window,
session_descriptor: SessionDescriptor,
) -> P2PSession<WasmConsole> {
pixels.resize_buffer(rom.width() as u32, rom.height() as u32);
pixels
.resize_buffer(rom.width() as u32, rom.height() as u32)
.expect("Failed to resize buffer");
window.set_inner_size(PhysicalSize::new(
rom.width().max(DEFAULT_WINDOW_RESOLUTION.width()),
rom.height().max(DEFAULT_WINDOW_RESOLUTION.height()),
Expand Down
Loading

0 comments on commit 7ad2f57

Please sign in to comment.