Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d86ceddd7 | ||
|
|
d934c843eb | ||
|
|
b283b69f74 | ||
|
|
828acebb89 | ||
|
|
466cf29eb7 | ||
|
|
c7628c42d8 | ||
|
|
2ce0edee76 | ||
|
|
d21cb4e5d0 | ||
|
|
6e36254203 | ||
|
|
5fd1957d74 | ||
|
|
19c595dd7d | ||
|
|
bb43c9aad8 | ||
|
|
9256c513da | ||
|
|
218a1764bc | ||
|
|
ea9ca614e9 | ||
|
|
dd9e04f636 |
Generated
+528
-1004
File diff suppressed because it is too large
Load Diff
+8
-8
@@ -4,18 +4,18 @@ description = "An emulator for the Virtual Boy."
|
|||||||
repository = "https://git.virtual-boy.com/PVB/lemur"
|
repository = "https://git.virtual-boy.com/PVB/lemur"
|
||||||
publish = false
|
publish = false
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
version = "0.12.2"
|
version = "0.13.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
atoi = "2"
|
atoi = "3"
|
||||||
audioadapter-buffers = "3"
|
audioadapter-buffers = "4"
|
||||||
atomic = "0.6"
|
atomic = "0.6"
|
||||||
bitflags = { version = "2", features = ["serde"] }
|
bitflags = { version = "2", features = ["serde"] }
|
||||||
bytemuck = { version = "1", features = ["derive"] }
|
bytemuck = { version = "1", features = ["derive"] }
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
cpal = { git = "https://github.com/sidit77/cpal.git", rev = "66ed6be" }
|
cpal = "0.18"
|
||||||
directories = "6"
|
directories = "6"
|
||||||
egui = { version = "0.34", features = ["persistence", "serde"] }
|
egui = { version = "0.34", features = ["persistence", "serde"] }
|
||||||
egui_extras = { version = "0.34", features = ["image"] }
|
egui_extras = { version = "0.34", features = ["image"] }
|
||||||
@@ -25,21 +25,21 @@ egui-wgpu = { version = "0.34", features = ["winit"] }
|
|||||||
fxprof-processed-profile = "0.8"
|
fxprof-processed-profile = "0.8"
|
||||||
fixed = { version = "1.28", features = ["num-traits"] }
|
fixed = { version = "1.28", features = ["num-traits"] }
|
||||||
gilrs = { version = "0.11", features = ["serde-serialize"] }
|
gilrs = { version = "0.11", features = ["serde-serialize"] }
|
||||||
gimli = "0.33"
|
gimli = "0.34"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
image = { version = "0.25", default-features = false, features = ["png"] }
|
image = { version = "0.25", default-features = false, features = ["png"] }
|
||||||
itertools = "0.14"
|
itertools = "0.15"
|
||||||
normpath = "1"
|
normpath = "1"
|
||||||
notify = "8"
|
notify = "8"
|
||||||
num-derive = "0.4"
|
num-derive = "0.4"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
object = "0.39"
|
object = "0.39"
|
||||||
oneshot = { version = "0.2", features = ["async", "std"] }
|
oneshot = { version = "0.2", features = ["async", "std"] }
|
||||||
pollster = "0.4"
|
pollster = "1"
|
||||||
rand = "0.10"
|
rand = "0.10"
|
||||||
rfd = "0.17"
|
rfd = "0.17"
|
||||||
rtrb = "0.3"
|
rtrb = "0.3"
|
||||||
rubato = "2"
|
rubato = "4"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
thread-priority = "3"
|
thread-priority = "3"
|
||||||
|
|||||||
+14
-18
@@ -1,7 +1,7 @@
|
|||||||
# This Dockerfile produces a base image for builds.
|
# This Dockerfile produces a base image for builds.
|
||||||
# It includes all dependencies necessary to cross-compile for Windows/MacOS/Linux.
|
# It includes all dependencies necessary to cross-compile for Windows/MacOS/Linux.
|
||||||
|
|
||||||
FROM debian:bookworm AS osxcross
|
FROM debian:trixie AS osxcross
|
||||||
ADD --chmod=644 "https://apt.llvm.org/llvm-snapshot.gpg.key" /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
ADD --chmod=644 "https://apt.llvm.org/llvm-snapshot.gpg.key" /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||||
WORKDIR /build/osxcross
|
WORKDIR /build/osxcross
|
||||||
ADD "https://github.com/tpoechtrager/osxcross.git#47936a512273bb3b414b5a2e83043c92eabc7ae7" .
|
ADD "https://github.com/tpoechtrager/osxcross.git#47936a512273bb3b414b5a2e83043c92eabc7ae7" .
|
||||||
@@ -9,35 +9,31 @@ ADD "https://github.com/joseluisq/macosx-sdks/releases/download/14.5/MacOSX14.5.
|
|||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y ca-certificates
|
apt-get install -y ca-certificates
|
||||||
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||||
COPY install-llvm.sh .
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
./install-llvm.sh && \
|
apt-get install -y bash bzip2 clang-22 git lld-22 llvm-22 make patch xz-utils && \
|
||||||
apt-get install -y bash bzip2 git make patch xz-utils && \
|
ln -s $(which clang-22) /usr/bin/clang && \
|
||||||
ln -s $(which clang-21) /usr/bin/clang && \
|
ln -s $(which clang++-22) /usr/bin/clang++ && \
|
||||||
ln -s $(which clang++-21) /usr/bin/clang++ && \
|
ln -s $(which ld64.lld-22) /usr/bin/ld64.lld && \
|
||||||
ln -s $(which ld64.lld-21) /usr/bin/ld64.lld && \
|
|
||||||
SDK_VERSION=14.5 UNATTENDED=1 ENABLE_COMPILER_RT_INSTALL=1 TARGET_DIR=/osxcross ./build.sh
|
SDK_VERSION=14.5 UNATTENDED=1 ENABLE_COMPILER_RT_INSTALL=1 TARGET_DIR=/osxcross ./build.sh
|
||||||
|
|
||||||
FROM rust:1.94-bookworm
|
FROM rust:1.97-trixie
|
||||||
ADD --chmod=644 "https://apt.llvm.org/llvm-snapshot.gpg.key" /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
ADD --chmod=644 "https://apt.llvm.org/llvm-snapshot.gpg.key" /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||||
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||||
COPY install-llvm.sh .
|
|
||||||
RUN rustup target add x86_64-pc-windows-msvc && \
|
RUN rustup target add x86_64-pc-windows-msvc && \
|
||||||
rustup target add x86_64-apple-darwin && \
|
rustup target add x86_64-apple-darwin && \
|
||||||
rustup target add aarch64-apple-darwin && \
|
rustup target add aarch64-apple-darwin && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
./install-llvm.sh && \
|
apt-get install -y clang-22 lld-22 libc6-dev libasound2-dev libudev-dev genisoimage mingw-w64 && \
|
||||||
apt-get install -y libc6-dev libasound2-dev libudev-dev genisoimage mingw-w64 && \
|
|
||||||
cargo install cargo-bundle xwin && \
|
cargo install cargo-bundle xwin && \
|
||||||
xwin --accept-license splat --output xwin && \
|
xwin --accept-license splat --output xwin && \
|
||||||
rm -rf .xwin-cache && \
|
rm -rf .xwin-cache && \
|
||||||
ln -s $(which clang-21) /usr/bin/clang && \
|
ln -s $(which clang-22) /usr/bin/clang && \
|
||||||
ln -s $(which clang++-21) /usr/bin/clang++
|
ln -s $(which clang++-22) /usr/bin/clang++
|
||||||
COPY --from=osxcross /osxcross /osxcross
|
COPY --from=osxcross /osxcross /osxcross
|
||||||
|
|
||||||
ENV PATH="/osxcross/bin:$PATH" \
|
ENV PATH="/osxcross/bin:$PATH" \
|
||||||
LD_LIBRARY_PATH="/osxcross/lib" \
|
LD_LIBRARY_PATH="/osxcross/lib" \
|
||||||
CC="clang-21" CXX="clang++-21" AR="llvm-ar-21" \
|
CC="clang-22" CXX="clang++-22" AR="llvm-ar-22" \
|
||||||
CC_x86_64-apple-darwin="o64-clang" \
|
CC_x86_64-apple-darwin="o64-clang" \
|
||||||
CXX_x86_64-apple-darwin="o64-clang++" \
|
CXX_x86_64-apple-darwin="o64-clang++" \
|
||||||
CC_aarch64-apple-darwin="oa64-clang" \
|
CC_aarch64-apple-darwin="oa64-clang" \
|
||||||
@@ -47,11 +43,11 @@ ENV PATH="/osxcross/bin:$PATH" \
|
|||||||
SHROOMS_CFLAGS_x86_64-pc-windows-msvc="-flto" \
|
SHROOMS_CFLAGS_x86_64-pc-windows-msvc="-flto" \
|
||||||
CFLAGS_x86_64-pc-windows-msvc="-I/xwin/crt/include -I/xwin/sdk/include/ucrt -I/xwin/sdk/include/um -I/xwin/sdk/include/shared" \
|
CFLAGS_x86_64-pc-windows-msvc="-I/xwin/crt/include -I/xwin/sdk/include/ucrt -I/xwin/sdk/include/um -I/xwin/sdk/include/shared" \
|
||||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-Lnative=/xwin/crt/lib/x86_64 -Lnative=/xwin/sdk/lib/um/x86_64 -Lnative=/xwin/sdk/lib/ucrt/x86_64 -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld" \
|
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-Lnative=/xwin/crt/lib/x86_64 -Lnative=/xwin/sdk/lib/um/x86_64 -Lnative=/xwin/sdk/lib/ucrt/x86_64 -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld" \
|
||||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER="lld-link-21" \
|
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER="lld-link-22" \
|
||||||
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="o64-clang" \
|
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="o64-clang" \
|
||||||
CARGO_TARGET_X86_64_APPLE_DARWIN_AR="llvm-ar-21" \
|
CARGO_TARGET_X86_64_APPLE_DARWIN_AR="llvm-ar-22" \
|
||||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER="oa64-clang" \
|
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER="oa64-clang" \
|
||||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-21" \
|
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-22" \
|
||||||
RC_PATH="llvm-rc-21" \
|
RC_PATH="llvm-rc-22" \
|
||||||
MACOSX_DEPLOYMENT_TARGET="14.5"
|
MACOSX_DEPLOYMENT_TARGET="14.5"
|
||||||
ENTRYPOINT ["bash"]
|
ENTRYPOINT ["bash"]
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Hopefully temporary script to manually install working llvm packages.
|
|
||||||
# The apt index for these is broken in bookworm, and upgrading to trixie
|
|
||||||
# would make them depend on too new of a libc version.
|
|
||||||
|
|
||||||
# https://apt.llvm.org/bookworm/pool/main/l/llvm-toolchain-21/clang-21_21.1.5~%2B%2B20251023083151%2B45afac62e373-1~exp1~20251023083333.51_amd64.deb
|
|
||||||
PACKAGES=('clang-21' 'clang-tools-21' 'libclang-common-21-dev' 'libclang-cpp21' 'libclang-rt-21-dev' 'libclang1-21' 'libllvm21' 'lld-21' 'llvm-21' 'llvm-21-dev' 'llvm-21-linker-tools' 'llvm-21-runtime' 'llvm-21-tools')
|
|
||||||
FILES=()
|
|
||||||
URL='https://apt.llvm.org/bookworm/pool/main/l/llvm-toolchain-21'
|
|
||||||
VERSION='21.1.5~%2B%2B20251023083151%2B45afac62e373-1~exp1~20251023083333.51_amd64.deb'
|
|
||||||
|
|
||||||
apt-get install -y curl python3
|
|
||||||
for package in "${PACKAGES[@]}"; do
|
|
||||||
curl -O -L "$URL/${package}_$VERSION"
|
|
||||||
FILES+=("./${package}_$VERSION")
|
|
||||||
done
|
|
||||||
|
|
||||||
apt-get install -y "${FILES[@]}"
|
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
Types: deb deb-src
|
Types: deb deb-src
|
||||||
URIs: http://apt.llvm.org/bookworm/
|
URIs: http://apt.llvm.org/trixie/
|
||||||
Suites: llvm-toolchain-bookworm-21
|
Suites: llvm-toolchain-trixie-22
|
||||||
Components: main
|
Components: main
|
||||||
|
|||||||
+1
-1
Submodule shrooms-vb-core updated: 29ade46a0a...31b7403252
+8
-5
@@ -288,6 +288,7 @@ impl Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let clipped_primitives = self.ctx.tessellate(output.shapes, output.pixels_per_point);
|
let clipped_primitives = self.ctx.tessellate(output.shapes, output.pixels_per_point);
|
||||||
|
viewport.window.pre_present_notify();
|
||||||
self.shared.painter.paint_and_update_textures(
|
self.shared.painter.paint_and_update_textures(
|
||||||
viewport.id,
|
viewport.id,
|
||||||
output.pixels_per_point,
|
output.pixels_per_point,
|
||||||
@@ -296,7 +297,6 @@ impl Application {
|
|||||||
&output.textures_delta,
|
&output.textures_delta,
|
||||||
vec![],
|
vec![],
|
||||||
);
|
);
|
||||||
viewport.window.pre_present_notify();
|
|
||||||
}
|
}
|
||||||
let mut active_viewports = ViewportIdSet::default();
|
let mut active_viewports = ViewportIdSet::default();
|
||||||
for (id, update) in updates {
|
for (id, update) in updates {
|
||||||
@@ -398,12 +398,15 @@ impl ApplicationHandler<UserEvent> for Application {
|
|||||||
if close_requested && viewport_id == ViewportId::ROOT {
|
if close_requested && viewport_id == ViewportId::ROOT {
|
||||||
event_loop.exit();
|
event_loop.exit();
|
||||||
}
|
}
|
||||||
|
if response.repaint {
|
||||||
|
viewport.window.request_redraw();
|
||||||
|
}
|
||||||
if !response.consumed {
|
if !response.consumed {
|
||||||
match event {
|
match event {
|
||||||
WindowEvent::KeyboardInput { event, .. } => {
|
WindowEvent::KeyboardInput { event, .. }
|
||||||
if !self.app.handle_key_event(viewport_id, &event) {
|
if !self.app.handle_key_event(viewport_id, &event) =>
|
||||||
self.controllers.handle_key_event(&event);
|
{
|
||||||
}
|
self.controllers.handle_key_event(&event);
|
||||||
}
|
}
|
||||||
WindowEvent::Focused(new_focused) => {
|
WindowEvent::Focused(new_focused) => {
|
||||||
self.focused = new_focused.then_some(viewport_id);
|
self.focused = new_focused.then_some(viewport_id);
|
||||||
|
|||||||
+9
-9
@@ -3,8 +3,8 @@ use std::time::Duration;
|
|||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use audioadapter_buffers::direct::InterleavedSlice;
|
use audioadapter_buffers::direct::InterleavedSlice;
|
||||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
use rubato::Resampler;
|
use rubato::{Adjustable as _, Resampler};
|
||||||
use tracing::error;
|
use tracing::warn;
|
||||||
|
|
||||||
pub struct Audio {
|
pub struct Audio {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
@@ -23,14 +23,14 @@ impl Audio {
|
|||||||
let Some(device) = host.default_output_device() else {
|
let Some(device) = host.default_output_device() else {
|
||||||
bail!("No output device available");
|
bail!("No output device available");
|
||||||
};
|
};
|
||||||
let Some(config) = device
|
let default_rate = device.default_output_config()?.sample_rate();
|
||||||
.supported_output_configs()?
|
let Some(config) = device.supported_output_configs()?.find(|c| {
|
||||||
.find(|c| c.channels() == 2 && c.sample_format().is_float())
|
c.channels() == 2 && c.sample_format().is_float() && c.contains_rate(default_rate)
|
||||||
else {
|
}) else {
|
||||||
bail!("No suitable output config available");
|
bail!("No suitable output config available");
|
||||||
};
|
};
|
||||||
let mut config = config.with_max_sample_rate().config();
|
let mut config = config.with_max_sample_rate().config();
|
||||||
let resample_ratio = config.sample_rate.0 as f64 / VB_FREQUENCY as f64;
|
let resample_ratio = config.sample_rate as f64 / VB_FREQUENCY as f64;
|
||||||
let chunk_size = (834.0 * resample_ratio) as usize;
|
let chunk_size = (834.0 * resample_ratio) as usize;
|
||||||
let sampler = rubato::Async::new_poly(
|
let sampler = rubato::Async::new_poly(
|
||||||
resample_ratio,
|
resample_ratio,
|
||||||
@@ -48,7 +48,7 @@ impl Audio {
|
|||||||
rtrb::RingBuffer::new(sampler.output_frames_max() * 4);
|
rtrb::RingBuffer::new(sampler.output_frames_max() * 4);
|
||||||
|
|
||||||
let stream = device.build_output_stream(
|
let stream = device.build_output_stream(
|
||||||
&config,
|
config,
|
||||||
move |data: &mut [f32], _| {
|
move |data: &mut [f32], _| {
|
||||||
let requested = data.len();
|
let requested = data.len();
|
||||||
let chunk = match sample_source.read_chunk(data.len()) {
|
let chunk = match sample_source.read_chunk(data.len()) {
|
||||||
@@ -66,7 +66,7 @@ impl Audio {
|
|||||||
}
|
}
|
||||||
chunk.commit_all();
|
chunk.commit_all();
|
||||||
},
|
},
|
||||||
move |error| error!(%error, "stream error"),
|
move |error| warn!(%error, "stream error"),
|
||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
stream.play()?;
|
stream.play()?;
|
||||||
|
|||||||
+117
-17
@@ -1,4 +1,7 @@
|
|||||||
use std::sync::{Arc, RwLock};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
sync::{Arc, RwLock},
|
||||||
|
};
|
||||||
|
|
||||||
use gilrs::{Event as GamepadEvent, EventType, GamepadId, ev::Code};
|
use gilrs::{Event as GamepadEvent, EventType, GamepadId, ev::Code};
|
||||||
use winit::{
|
use winit::{
|
||||||
@@ -8,12 +11,13 @@ use winit::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
emulator::{EmulatorClient, EmulatorCommand, SimId, VBKey},
|
emulator::{EmulatorClient, EmulatorCommand, SimId, VBKey},
|
||||||
input::{InputMapping, MappingProvider},
|
input::{AxisMapping, InputMapping, MappingProvider},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
pub sim_id: SimId,
|
pub sim_id: SimId,
|
||||||
state: VBKey,
|
state: VBKey,
|
||||||
|
axis_values: HashMap<(GamepadId, Code), f32>,
|
||||||
mapping: Arc<RwLock<InputMapping>>,
|
mapping: Arc<RwLock<InputMapping>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,6 +26,7 @@ impl Controller {
|
|||||||
Self {
|
Self {
|
||||||
sim_id,
|
sim_id,
|
||||||
state: VBKey::SGN,
|
state: VBKey::SGN,
|
||||||
|
axis_values: HashMap::new(),
|
||||||
mapping: mappings.for_sim(sim_id).clone(),
|
mapping: mappings.for_sim(sim_id).clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,20 +50,23 @@ impl Controller {
|
|||||||
(VBKey::empty(), mappings)
|
(VBKey::empty(), mappings)
|
||||||
}
|
}
|
||||||
EventType::AxisChanged(_, value, code) => {
|
EventType::AxisChanged(_, value, code) => {
|
||||||
let (neg, pos) = self.map_axis(&event.id, &code)?;
|
let mapping = self.map_axis(&event.id, &code)?;
|
||||||
let mut pressed = VBKey::empty();
|
self.axis_values.insert((event.id, code), value);
|
||||||
let mut released = VBKey::empty();
|
|
||||||
if value < -0.75 {
|
let pair_value = mapping
|
||||||
pressed = pressed.union(neg);
|
.pair
|
||||||
}
|
.and_then(|p| self.axis_values.get(&(event.id, p)))
|
||||||
if value > 0.75 {
|
.copied()
|
||||||
pressed = pressed.union(pos);
|
.unwrap_or_default();
|
||||||
}
|
let neg = mapping.neg;
|
||||||
if value > -0.65 {
|
let pos = mapping.pos;
|
||||||
released = released.union(neg);
|
|
||||||
}
|
let (mut pressed, mut released) = axis_presses(value, pair_value, neg, pos);
|
||||||
if value < 0.65 {
|
if let Some(other) = mapping.pair.and_then(|p| self.map_axis(&event.id, &p)) {
|
||||||
released = released.union(pos);
|
let (other_pressed, other_released) =
|
||||||
|
axis_presses(pair_value, value, other.neg, other.pos);
|
||||||
|
pressed = pressed.union(other_pressed);
|
||||||
|
released = released.union(other_released);
|
||||||
}
|
}
|
||||||
(pressed, released)
|
(pressed, released)
|
||||||
}
|
}
|
||||||
@@ -87,7 +95,7 @@ impl Controller {
|
|||||||
self.mapping.read().unwrap().map_button(id, code)
|
self.mapping.read().unwrap().map_button(id, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_axis(&self, id: &GamepadId, code: &Code) -> Option<(VBKey, VBKey)> {
|
fn map_axis(&self, id: &GamepadId, code: &Code) -> Option<AxisMapping> {
|
||||||
self.mapping.read().unwrap().map_axis(id, code)
|
self.mapping.read().unwrap().map_axis(id, code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,3 +134,95 @@ impl ControllerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn axis_presses(value: f32, pair_value: f32, neg: VBKey, pos: VBKey) -> (VBKey, VBKey) {
|
||||||
|
use std::f32::consts::FRAC_PI_3;
|
||||||
|
|
||||||
|
let mut pressed = VBKey::empty();
|
||||||
|
let mut released = VBKey::empty();
|
||||||
|
|
||||||
|
let magnitude = value.hypot(pair_value);
|
||||||
|
let abs_angle = pair_value.atan2(value).abs();
|
||||||
|
|
||||||
|
if magnitude < 0.65 {
|
||||||
|
released = released.union(neg).union(pos);
|
||||||
|
} else if abs_angle <= FRAC_PI_3 {
|
||||||
|
// stick tilted towards positive
|
||||||
|
released = released.union(neg);
|
||||||
|
|
||||||
|
if magnitude >= 0.75 {
|
||||||
|
pressed = pressed.union(pos);
|
||||||
|
}
|
||||||
|
} else if abs_angle >= 2.0 * FRAC_PI_3 {
|
||||||
|
// stick tilted towards negative
|
||||||
|
released = released.union(pos);
|
||||||
|
|
||||||
|
if magnitude >= 0.75 {
|
||||||
|
pressed = pressed.union(neg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
released = released.union(neg).union(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
(pressed, released)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::{VBKey, axis_presses};
|
||||||
|
|
||||||
|
const NEG: VBKey = VBKey::LL;
|
||||||
|
const POS: VBKey = VBKey::LR;
|
||||||
|
|
||||||
|
const NONE: VBKey = VBKey::empty();
|
||||||
|
const BOTH: VBKey = NEG.union(POS);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn detects_no_input() {
|
||||||
|
let (pressed, released) = axis_presses(0.0, 0.0, NEG, POS);
|
||||||
|
assert_eq!(pressed, NONE);
|
||||||
|
assert_eq!(released, BOTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn detects_pos_input() {
|
||||||
|
let (pressed, released) = axis_presses(1.0, 0.0, NEG, POS);
|
||||||
|
assert_eq!(pressed, POS);
|
||||||
|
assert_eq!(released, NEG);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn detects_neg_input() {
|
||||||
|
let (pressed, released) = axis_presses(-1.0, 0.0, NEG, POS);
|
||||||
|
assert_eq!(pressed, NEG);
|
||||||
|
assert_eq!(released, POS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn respects_dead_zone() {
|
||||||
|
let (pressed, released) = axis_presses(0.70, 0.0, NEG, POS);
|
||||||
|
assert_eq!(pressed, NONE);
|
||||||
|
assert_eq!(released, NEG);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn handles_diagonals_ok() {
|
||||||
|
let (pressed, released) = axis_presses(0.6, 0.6, NEG, POS);
|
||||||
|
assert_eq!(pressed, POS);
|
||||||
|
assert_eq!(released, NEG);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ignores_diagonal_noise() {
|
||||||
|
let (pressed, released) = axis_presses(-1.0, -0.1484245, NEG, POS);
|
||||||
|
assert_eq!(pressed, NEG);
|
||||||
|
assert_eq!(released, POS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ignores_small_values() {
|
||||||
|
let (pressed, released) = axis_presses(-0.1484245, -1.0, NEG, POS);
|
||||||
|
assert_eq!(pressed, NONE);
|
||||||
|
assert_eq!(released, BOTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -946,6 +946,9 @@ pub struct EmulatorClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EmulatorClient {
|
impl EmulatorClient {
|
||||||
|
pub fn has_player_2(&self) -> bool {
|
||||||
|
self.sim_state(SimId::Player2) != SimState::Uninitialized
|
||||||
|
}
|
||||||
pub fn sim_state(&self, sim_id: SimId) -> SimState {
|
pub fn sim_state(&self, sim_id: SimId) -> SimState {
|
||||||
self.sim_state[sim_id.to_index()].load(Ordering::Acquire)
|
self.sim_state[sim_id.to_index()].load(Ordering::Acquire)
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-23
@@ -52,12 +52,28 @@ pub trait Mappings {
|
|||||||
fn use_default_mappings(&mut self);
|
fn use_default_mappings(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Serialize, Deserialize)]
|
||||||
|
pub struct AxisMapping {
|
||||||
|
pub neg: VBKey,
|
||||||
|
pub pos: VBKey,
|
||||||
|
pub pair: Option<Code>,
|
||||||
|
}
|
||||||
|
impl Default for AxisMapping {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
neg: VBKey::empty(),
|
||||||
|
pos: VBKey::empty(),
|
||||||
|
pair: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct GamepadMapping {
|
pub struct GamepadMapping {
|
||||||
buttons: HashMap<Code, VBKey>,
|
buttons: HashMap<Code, VBKey>,
|
||||||
axes: HashMap<Code, (VBKey, VBKey)>,
|
axes: HashMap<Code, AxisMapping>,
|
||||||
default_buttons: HashMap<Code, VBKey>,
|
default_buttons: HashMap<Code, VBKey>,
|
||||||
default_axes: HashMap<Code, (VBKey, VBKey)>,
|
default_axes: HashMap<Code, AxisMapping>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GamepadMapping {
|
impl GamepadMapping {
|
||||||
@@ -78,7 +94,8 @@ impl GamepadMapping {
|
|||||||
let mut default_axes = HashMap::new();
|
let mut default_axes = HashMap::new();
|
||||||
let mut default_axis = |axis: Axis, neg: VBKey, pos: VBKey| {
|
let mut default_axis = |axis: Axis, neg: VBKey, pos: VBKey| {
|
||||||
if let Some(code) = gamepad.axis_code(axis) {
|
if let Some(code) = gamepad.axis_code(axis) {
|
||||||
default_axes.insert(code, (neg, pos));
|
let pair = axis.second_axis().and_then(|a| gamepad.axis_code(a));
|
||||||
|
default_axes.insert(code, AxisMapping { neg, pos, pair });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
default_axis(Axis::LeftStickX, VBKey::LL, VBKey::LR);
|
default_axis(Axis::LeftStickX, VBKey::LL, VBKey::LR);
|
||||||
@@ -102,19 +119,13 @@ impl GamepadMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_axis_neg_mapping(&mut self, key: VBKey, code: Code) {
|
pub fn add_axis_neg_mapping(&mut self, key: VBKey, code: Code) {
|
||||||
let entry = self
|
let entry = self.axes.entry(code).or_default();
|
||||||
.axes
|
entry.neg = entry.neg.union(key);
|
||||||
.entry(code)
|
|
||||||
.or_insert((VBKey::empty(), VBKey::empty()));
|
|
||||||
entry.0 = entry.0.union(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_axis_pos_mapping(&mut self, key: VBKey, code: Code) {
|
pub fn add_axis_pos_mapping(&mut self, key: VBKey, code: Code) {
|
||||||
let entry = self
|
let entry = self.axes.entry(code).or_default();
|
||||||
.axes
|
entry.pos = entry.pos.union(key);
|
||||||
.entry(code)
|
|
||||||
.or_insert((VBKey::empty(), VBKey::empty()));
|
|
||||||
entry.1 = entry.1.union(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_mappings(&self) -> PersistedGamepadMapping {
|
fn save_mappings(&self) -> PersistedGamepadMapping {
|
||||||
@@ -145,11 +156,11 @@ impl GamepadMapping {
|
|||||||
impl Mappings for GamepadMapping {
|
impl Mappings for GamepadMapping {
|
||||||
fn mapping_names(&self) -> HashMap<VBKey, Vec<String>> {
|
fn mapping_names(&self) -> HashMap<VBKey, Vec<String>> {
|
||||||
let mut results: HashMap<VBKey, Vec<String>> = HashMap::new();
|
let mut results: HashMap<VBKey, Vec<String>> = HashMap::new();
|
||||||
for (axis, (left_keys, right_keys)) in &self.axes {
|
for (axis, mapping) in &self.axes {
|
||||||
for key in left_keys.iter() {
|
for key in mapping.neg.iter() {
|
||||||
results.entry(key).or_default().push(format!("-{axis}"));
|
results.entry(key).or_default().push(format!("-{axis}"));
|
||||||
}
|
}
|
||||||
for key in right_keys.iter() {
|
for key in mapping.pos.iter() {
|
||||||
results.entry(key).or_default().push(format!("+{axis}"));
|
results.entry(key).or_default().push(format!("+{axis}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,10 +173,10 @@ impl Mappings for GamepadMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear_mappings(&mut self, key: VBKey) {
|
fn clear_mappings(&mut self, key: VBKey) {
|
||||||
self.axes.retain(|_, (left, right)| {
|
self.axes.retain(|_, mapping| {
|
||||||
*left = left.difference(key);
|
mapping.neg = mapping.neg.difference(key);
|
||||||
*right = right.difference(key);
|
mapping.pos = mapping.pos.difference(key);
|
||||||
!(left.is_empty() && right.is_empty())
|
!(mapping.neg.is_empty() && mapping.pos.is_empty())
|
||||||
});
|
});
|
||||||
self.buttons.retain(|_, keys| {
|
self.buttons.retain(|_, keys| {
|
||||||
*keys = keys.difference(key);
|
*keys = keys.difference(key);
|
||||||
@@ -200,7 +211,7 @@ impl InputMapping {
|
|||||||
mappings.buttons.get(code).copied()
|
mappings.buttons.get(code).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_axis(&self, id: &GamepadId, code: &Code) -> Option<(VBKey, VBKey)> {
|
pub fn map_axis(&self, id: &GamepadId, code: &Code) -> Option<AxisMapping> {
|
||||||
let mappings = self.gamepads.get(id)?.read().unwrap();
|
let mappings = self.gamepads.get(id)?.read().unwrap();
|
||||||
mappings.axes.get(code).copied()
|
mappings.axes.get(code).copied()
|
||||||
}
|
}
|
||||||
@@ -459,9 +470,9 @@ struct PersistedKeyboardMapping {
|
|||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct PersistedGamepadMapping {
|
struct PersistedGamepadMapping {
|
||||||
buttons: Vec<(Code, VBKey)>,
|
buttons: Vec<(Code, VBKey)>,
|
||||||
axes: Vec<(Code, (VBKey, VBKey))>,
|
axes: Vec<(Code, AxisMapping)>,
|
||||||
default_buttons: Vec<(Code, VBKey)>,
|
default_buttons: Vec<(Code, VBKey)>,
|
||||||
default_axes: Vec<(Code, (VBKey, VBKey))>,
|
default_axes: Vec<(Code, AxisMapping)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||||
|
|||||||
+3
-3
@@ -28,11 +28,11 @@ mod utils;
|
|||||||
mod vip;
|
mod vip;
|
||||||
|
|
||||||
pub trait AppWindow {
|
pub trait AppWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
SimId::Player1
|
None
|
||||||
}
|
}
|
||||||
fn image_url(&self, name: &str) -> String {
|
fn image_url(&self, name: &str) -> String {
|
||||||
format!("vip://{}/{name}", self.sim_id())
|
format!("vip://{}/{name}", self.sim_id().unwrap_or(SimId::Player1))
|
||||||
}
|
}
|
||||||
fn initial_viewport(&self) -> ViewportBuilder;
|
fn initial_viewport(&self) -> ViewportBuilder;
|
||||||
fn show(&mut self, ui: &mut Ui);
|
fn show(&mut self, ui: &mut Ui);
|
||||||
|
|||||||
+41
-6
@@ -53,6 +53,7 @@ pub struct GameWindow {
|
|||||||
children: ViewportIdMap<ChildWindowWrapper>,
|
children: ViewportIdMap<ChildWindowWrapper>,
|
||||||
child_states: UiData<ViewportIdMap<ChildState>>,
|
child_states: UiData<ViewportIdMap<ChildState>>,
|
||||||
queued_children: Vec<ChildWindow>,
|
queued_children: Vec<ChildWindow>,
|
||||||
|
show_player_name: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameWindow {
|
impl GameWindow {
|
||||||
@@ -94,6 +95,7 @@ impl GameWindow {
|
|||||||
children: ViewportIdMap::default(),
|
children: ViewportIdMap::default(),
|
||||||
child_states: UiData::new(),
|
child_states: UiData::new(),
|
||||||
queued_children: vec![],
|
queued_children: vec![],
|
||||||
|
show_player_name: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +178,8 @@ impl GameWindow {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut viewport = child.initial_viewport();
|
let mut viewport = child.initial_viewport();
|
||||||
|
let title = viewport.title.clone().unwrap();
|
||||||
|
let sim_id = child.sim_id();
|
||||||
if let Some(state) = self.child_states.get(&viewport_id) {
|
if let Some(state) = self.child_states.get(&viewport_id) {
|
||||||
viewport.position = Some(state.position);
|
viewport.position = Some(state.position);
|
||||||
viewport.inner_size = Some(state.size);
|
viewport.inner_size = Some(state.size);
|
||||||
@@ -184,6 +188,8 @@ impl GameWindow {
|
|||||||
viewport_id,
|
viewport_id,
|
||||||
ChildWindowWrapper {
|
ChildWindowWrapper {
|
||||||
app: Arc::new(Mutex::new(child)),
|
app: Arc::new(Mutex::new(child)),
|
||||||
|
title,
|
||||||
|
sim_id,
|
||||||
updates: Some(viewport),
|
updates: Some(viewport),
|
||||||
close_requested: Arc::new(AtomicBool::new(false)),
|
close_requested: Arc::new(AtomicBool::new(false)),
|
||||||
},
|
},
|
||||||
@@ -371,7 +377,7 @@ impl GameWindow {
|
|||||||
});
|
});
|
||||||
ui.menu_button("Options", |ui| self.show_options_menu(ui));
|
ui.menu_button("Options", |ui| self.show_options_menu(ui));
|
||||||
ui.menu_button("Multiplayer", |ui| {
|
ui.menu_button("Multiplayer", |ui| {
|
||||||
let has_player_2 = self.client.sim_state(SimId::Player2) != SimState::Uninitialized;
|
let has_player_2 = self.client.has_player_2();
|
||||||
if self.sim_id == SimId::Player1
|
if self.sim_id == SimId::Player1
|
||||||
&& !has_player_2
|
&& !has_player_2
|
||||||
&& ui.button("Open Player 2").clicked()
|
&& ui.button("Open Player 2").clicked()
|
||||||
@@ -623,8 +629,8 @@ impl GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for GameWindow {
|
impl AppWindow for GameWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
@@ -639,6 +645,30 @@ impl AppWindow for GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show(&mut self, ui: &mut Ui) {
|
fn show(&mut self, ui: &mut Ui) {
|
||||||
|
let has_player_2 = self.client.has_player_2();
|
||||||
|
if !self.show_player_name && has_player_2 {
|
||||||
|
ui.send_viewport_cmd(ViewportCommand::Title(format!("Lemur ({})", self.sim_id)));
|
||||||
|
for (viewport_id, child) in &self.children {
|
||||||
|
if let Some(sim_id) = child.sim_id {
|
||||||
|
ui.send_viewport_cmd_to(
|
||||||
|
*viewport_id,
|
||||||
|
ViewportCommand::Title(format!("{} ({sim_id})", child.title)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.show_player_name = true;
|
||||||
|
} else if self.show_player_name && !has_player_2 {
|
||||||
|
ui.send_viewport_cmd(ViewportCommand::Title("Lemur".to_string()));
|
||||||
|
for (viewport_id, child) in &self.children {
|
||||||
|
if child.sim_id.is_some() {
|
||||||
|
ui.send_viewport_cmd_to(
|
||||||
|
*viewport_id,
|
||||||
|
ViewportCommand::Title(child.title.clone()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.show_player_name = false;
|
||||||
|
}
|
||||||
self.child_states.load(ui);
|
self.child_states.load(ui);
|
||||||
let dimensions = {
|
let dimensions = {
|
||||||
let bounds = ui.content_rect();
|
let bounds = ui.content_rect();
|
||||||
@@ -690,12 +720,15 @@ impl AppWindow for GameWindow {
|
|||||||
let app = child.app.clone();
|
let app = child.app.clone();
|
||||||
let viewport_builder = child.updates.take().unwrap_or_default();
|
let viewport_builder = child.updates.take().unwrap_or_default();
|
||||||
let close_requested = child.close_requested.clone();
|
let close_requested = child.close_requested.clone();
|
||||||
if let Some(rect) = ui.input_for(*id, |inp| inp.viewport().outer_rect) {
|
if let (Some(outer), Some(inner)) = ui.input_for(*id, |inp| {
|
||||||
|
let viewport = inp.viewport();
|
||||||
|
(viewport.outer_rect, viewport.inner_rect)
|
||||||
|
}) {
|
||||||
self.child_states.insert(
|
self.child_states.insert(
|
||||||
*id,
|
*id,
|
||||||
ChildState {
|
ChildState {
|
||||||
position: rect.min,
|
position: outer.min,
|
||||||
size: rect.size(),
|
size: inner.size(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -742,6 +775,8 @@ struct ColorPickerState {
|
|||||||
|
|
||||||
struct ChildWindowWrapper {
|
struct ChildWindowWrapper {
|
||||||
app: Arc<Mutex<AppWrapper>>,
|
app: Arc<Mutex<AppWrapper>>,
|
||||||
|
title: String,
|
||||||
|
sim_id: Option<SimId>,
|
||||||
updates: Option<ViewportBuilder>,
|
updates: Option<ViewportBuilder>,
|
||||||
close_requested: Arc<AtomicBool>,
|
close_requested: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -42,13 +42,13 @@ impl GdbServerWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for GdbServerWindow {
|
impl AppWindow for GdbServerWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("GDB Server ({})", self.sim_id))
|
.with_title("GDB Server")
|
||||||
.with_inner_size((300.0, 200.0))
|
.with_inner_size((300.0, 200.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,13 +82,13 @@ impl ProfileWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for ProfileWindow {
|
impl AppWindow for ProfileWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("Profiler ({})", self.sim_id))
|
.with_title("Profiler")
|
||||||
.with_inner_size((300.0, 200.0))
|
.with_inner_size((300.0, 200.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ impl TerminalWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for TerminalWindow {
|
impl AppWindow for TerminalWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("Terminal ({})", self.sim_id))
|
.with_title("Terminal")
|
||||||
.with_inner_size((640.0, 480.0))
|
.with_inner_size((640.0, 480.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-6
@@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fmt::{Display, UpperHex},
|
fmt::{Display, UpperHex},
|
||||||
ops::{Bound, Deref, DerefMut, RangeBounds},
|
ops::{AddAssign, Bound, Deref, DerefMut, MulAssign, RangeBounds},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ use egui::{
|
|||||||
RichText, Sense, Shape, Stroke, StrokeKind, TextEdit, Ui, UiBuilder, Vec2, Widget, WidgetText,
|
RichText, Sense, Shape, Stroke, StrokeKind, TextEdit, Ui, UiBuilder, Vec2, Widget, WidgetText,
|
||||||
ecolor::HexColor, util::id_type_map::SerializableAny,
|
ecolor::HexColor, util::id_type_map::SerializableAny,
|
||||||
};
|
};
|
||||||
use num_traits::{CheckedAdd, CheckedSub, One};
|
use num_traits::{CheckedAdd, CheckedSub, One, Zero};
|
||||||
|
|
||||||
pub trait UiExt {
|
pub trait UiExt {
|
||||||
fn section(&mut self, title: impl Into<String>, add_contents: impl FnOnce(&mut Ui));
|
fn section(&mut self, title: impl Into<String>, add_contents: impl FnOnce(&mut Ui));
|
||||||
@@ -105,14 +105,16 @@ enum Direction {
|
|||||||
|
|
||||||
pub trait Number:
|
pub trait Number:
|
||||||
Copy
|
Copy
|
||||||
|
+ Zero
|
||||||
+ One
|
+ One
|
||||||
|
+ AddAssign
|
||||||
|
+ MulAssign
|
||||||
+ CheckedAdd
|
+ CheckedAdd
|
||||||
+ CheckedSub
|
+ CheckedSub
|
||||||
+ Eq
|
+ Eq
|
||||||
+ Ord
|
+ Ord
|
||||||
+ Display
|
+ Display
|
||||||
+ FromStr
|
+ FromStr
|
||||||
+ FromRadix16
|
|
||||||
+ UpperHex
|
+ UpperHex
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
@@ -121,14 +123,16 @@ pub trait Number:
|
|||||||
}
|
}
|
||||||
impl<
|
impl<
|
||||||
T: Copy
|
T: Copy
|
||||||
|
+ Zero
|
||||||
+ One
|
+ One
|
||||||
|
+ AddAssign
|
||||||
|
+ MulAssign
|
||||||
+ CheckedAdd
|
+ CheckedAdd
|
||||||
+ CheckedSub
|
+ CheckedSub
|
||||||
+ Eq
|
+ Eq
|
||||||
+ Ord
|
+ Ord
|
||||||
+ Display
|
+ Display
|
||||||
+ FromStr
|
+ FromStr
|
||||||
+ FromRadix16
|
|
||||||
+ UpperHex
|
+ UpperHex
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
@@ -209,8 +213,8 @@ impl<T: Number> Widget for NumberEdit<'_, T> {
|
|||||||
let from_string = |val: &str| {
|
let from_string = |val: &str| {
|
||||||
if self.hex {
|
if self.hex {
|
||||||
let bytes = val.as_bytes();
|
let bytes = val.as_bytes();
|
||||||
let (result, consumed) = T::from_radix_16(bytes);
|
let (result, consumed) = atoi::Integer::<T>::from_radix_16(bytes);
|
||||||
(consumed == bytes.len()).then_some(result)
|
(consumed == bytes.len()).then_some(result.0)
|
||||||
} else {
|
} else {
|
||||||
val.parse::<T>().ok()
|
val.parse::<T>().ok()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,13 +191,13 @@ impl BgMapWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for BgMapWindow {
|
impl AppWindow for BgMapWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("BG Map Data ({})", self.sim_id))
|
.with_title("BG Map Data")
|
||||||
.with_inner_size((640.0, 480.0))
|
.with_inner_size((640.0, 480.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -251,13 +251,13 @@ impl CharacterDataWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for CharacterDataWindow {
|
impl AppWindow for CharacterDataWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("Character Data ({})", self.sim_id))
|
.with_title("Character Data")
|
||||||
.with_inner_size((640.0, 480.0))
|
.with_inner_size((640.0, 480.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,13 +151,13 @@ impl FrameBufferWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for FrameBufferWindow {
|
impl AppWindow for FrameBufferWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("Frame Buffers ({})", self.sim_id))
|
.with_title("Frame Buffers")
|
||||||
.with_inner_size((640.0, 480.0))
|
.with_inner_size((640.0, 480.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -207,13 +207,13 @@ impl ObjectWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for ObjectWindow {
|
impl AppWindow for ObjectWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("Object Data ({})", self.sim_id))
|
.with_title("Object Data")
|
||||||
.with_inner_size((640.0, 500.0))
|
.with_inner_size((640.0, 500.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -630,13 +630,13 @@ fn read_address<T: MemoryValue>(registers: &MemoryRef, address: usize) -> T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for RegisterWindow {
|
impl AppWindow for RegisterWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("Registers ({})", self.sim_id))
|
.with_title("Registers")
|
||||||
.with_inner_size((800.0, 480.0))
|
.with_inner_size((800.0, 480.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -527,13 +527,13 @@ impl WorldWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppWindow for WorldWindow {
|
impl AppWindow for WorldWindow {
|
||||||
fn sim_id(&self) -> SimId {
|
fn sim_id(&self) -> Option<SimId> {
|
||||||
self.sim_id
|
Some(self.sim_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_viewport(&self) -> ViewportBuilder {
|
fn initial_viewport(&self) -> ViewportBuilder {
|
||||||
ViewportBuilder::default()
|
ViewportBuilder::default()
|
||||||
.with_title(format!("Worlds ({})", self.sim_id))
|
.with_title("Worlds")
|
||||||
.with_inner_size((640.0, 520.0))
|
.with_inner_size((640.0, 520.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1081,8 +1081,8 @@ impl<'a> SourceCoordCalculator<'a> {
|
|||||||
(sx, sy)
|
(sx, sy)
|
||||||
}
|
}
|
||||||
SourceParam::Affine(affine) => {
|
SourceParam::Affine(affine) => {
|
||||||
let sx = affine_coord(affine.src_x, x, affine.dx, affine.src_parallax.min(0));
|
let sx = affine_coord(affine.src_x, x, affine.dx, -(affine.src_parallax.min(0)));
|
||||||
let sy = affine_coord(affine.src_y, x, affine.dy, affine.src_parallax.min(0));
|
let sy = affine_coord(affine.src_y, x, affine.dy, -(affine.src_parallax.min(0)));
|
||||||
(sx, sy)
|
(sx, sy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user