Compare commits
3 Commits
main
...
feature/ne
| Author | SHA1 | Date | |
|---|---|---|---|
| f509833262 | |||
| db19b9c416 | |||
| 25896a5a92 |
186
Cargo.lock
generated
186
Cargo.lock
generated
@ -81,6 +81,71 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aeronet"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "745a8013cf5cf00933422a43ddd500bcdf50e48de2f5ddfa54b89e80ca98b176"
|
||||
dependencies = [
|
||||
"aeronet_io",
|
||||
"aeronet_transport",
|
||||
"bevy_app",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aeronet_io"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f05b43f128690e5eb9636b8a227078b2a4e577450da145d26ea1cd14688d80bc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
"bevy_platform",
|
||||
"bevy_reflect",
|
||||
"bytes",
|
||||
"derive_more",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aeronet_replicon"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4970822b3030b79c6dcba0933929176c5310836e67d707cc80cac6d29fe90c5a"
|
||||
dependencies = [
|
||||
"aeronet_io",
|
||||
"aeronet_transport",
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
"bevy_platform",
|
||||
"bevy_reflect",
|
||||
"bevy_replicon",
|
||||
"bevy_state",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aeronet_transport"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd63172db760f378f31e1d546fc581b79c2ba3f084a9dfe73ce65c07c4527b9b"
|
||||
dependencies = [
|
||||
"aeronet_io",
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
"bevy_platform",
|
||||
"bevy_reflect",
|
||||
"bevy_time",
|
||||
"bit-vec",
|
||||
"derive_more",
|
||||
"either",
|
||||
"log",
|
||||
"octs",
|
||||
"ringbuf",
|
||||
"typesize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
@ -173,6 +238,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.101"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea"
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.5.1"
|
||||
@ -1291,6 +1362,26 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_replicon"
|
||||
version = "0.38.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aee12260a021e0d9e4437ba9a325deb4ca05c98ef29d670fc63b366799ecaad0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bitflags 2.10.0",
|
||||
"bytes",
|
||||
"deterministic-hash",
|
||||
"log",
|
||||
"petgraph",
|
||||
"postcard",
|
||||
"serde",
|
||||
"smallbitvec",
|
||||
"typeid",
|
||||
"variadics_please",
|
||||
"xxhash-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_scene"
|
||||
version = "0.18.0"
|
||||
@ -1773,6 +1864,9 @@ name = "bytes"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop"
|
||||
@ -1850,6 +1944,15 @@ dependencies = [
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cobs"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1"
|
||||
dependencies = [
|
||||
"thiserror 2.0.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.12.0"
|
||||
@ -2198,6 +2301,12 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deterministic-hash"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11277822c27bde750de02c5dc5159b91e88bf2661a2c1d98106f2fb1c5c6f590"
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
@ -3818,6 +3927,15 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "octs"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3beef54705459f4a421ff43b6c9b8381f5b84769e4ae69942783dd8918837b7"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "offset-allocator"
|
||||
version = "0.2.0"
|
||||
@ -4070,6 +4188,28 @@ dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "postcard"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24"
|
||||
dependencies = [
|
||||
"cobs",
|
||||
"postcard-derive",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "postcard-derive"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0232bd009a197ceec9cc881ba46f727fcd8060a2d8d6a9dde7a69030a6fe2bb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pp-rs"
|
||||
version = "0.2.1"
|
||||
@ -4351,6 +4491,17 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
||||
|
||||
[[package]]
|
||||
name = "ringbuf"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe47b720588c8702e34b5979cb3271a8b1842c7cb6f57408efa70c779363488c"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "robust"
|
||||
version = "1.2.0"
|
||||
@ -4622,6 +4773,12 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallbitvec"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d31d263dd118560e1a492922182ab6ca6dc1d03a3bf54e7699993f31a4150e3f"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.1"
|
||||
@ -4844,8 +5001,11 @@ dependencies = [
|
||||
name = "time_travel"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aeronet",
|
||||
"aeronet_replicon",
|
||||
"avian2d",
|
||||
"bevy",
|
||||
"bevy_replicon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -5029,6 +5189,26 @@ version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
||||
|
||||
[[package]]
|
||||
name = "typesize"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da66c62c5b7017a2787e77373c03e6a5aafde77a73bff1ff96e91cd2e128179"
|
||||
dependencies = [
|
||||
"typesize-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typesize-derive"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "536b6812192bda8551cfa0e52524e328c6a951b48e66529ee4522d6c721243d6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typewit"
|
||||
version = "1.14.2"
|
||||
@ -6094,6 +6274,12 @@ version = "0.8.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ae8337f8a065cfc972643663ea4279e04e7256de865aa66fe25cec5fb912d3f"
|
||||
|
||||
[[package]]
|
||||
name = "xxhash-rust"
|
||||
version = "0.8.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3"
|
||||
|
||||
[[package]]
|
||||
name = "yazi"
|
||||
version = "0.2.1"
|
||||
|
||||
@ -4,5 +4,8 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
aeronet = "0.19.0"
|
||||
aeronet_replicon = { version = "0.19.0", features = ["client", "server"] }
|
||||
avian2d = "0.5.0"
|
||||
bevy = "0.18.0"
|
||||
bevy = { version = "0.18.0", features = ["debug"] }
|
||||
bevy_replicon = "0.38.2"
|
||||
|
||||
BIN
assets/FiraSans-Bold.ttf
Normal file
BIN
assets/FiraSans-Bold.ttf
Normal file
Binary file not shown.
1
assets/logo.png
Symbolic link
1
assets/logo.png
Symbolic link
@ -0,0 +1 @@
|
||||
/home/mitchell/Pictures/time_travel_logo.png
|
||||
61
assets/shaders/bezier.wgsl
Normal file
61
assets/shaders/bezier.wgsl
Normal file
@ -0,0 +1,61 @@
|
||||
struct Material {
|
||||
p0: vec2<f32>,
|
||||
c0: vec2<f32>,
|
||||
c1: vec2<f32>,
|
||||
p1: vec2<f32>,
|
||||
width: f32,
|
||||
color: vec4<f32>,
|
||||
};
|
||||
|
||||
@group(2) @binding(0)
|
||||
var<uniform> mat: Material;
|
||||
|
||||
fn bezier(p0: vec2<f32>, c0: vec2<f32>, c1: vec2<f32>, p1: vec2<f32>, t: f32) -> vec2<f32> {
|
||||
let u = 1.0 - t;
|
||||
return
|
||||
u*u*u*p0 +
|
||||
3.0*u*u*t*c0 +
|
||||
3.0*u*t*t*c1 +
|
||||
t*t*t*p1;
|
||||
}
|
||||
|
||||
fn distance_to_bezier(p: vec2<f32>) -> f32 {
|
||||
var min_d = 1e9;
|
||||
let steps = 32;
|
||||
|
||||
var prev = mat.p0;
|
||||
for (var i = 1; i <= steps; i++) {
|
||||
let t = f32(i) / f32(steps);
|
||||
let cur = bezier(mat.p0, mat.c0, mat.c1, mat.p1, t);
|
||||
|
||||
// distance to segment
|
||||
let v = cur - prev;
|
||||
let w = p - prev;
|
||||
let t_seg = clamp(dot(w, v) / dot(v, v), 0.0, 1.0);
|
||||
let proj = prev + t_seg * v;
|
||||
|
||||
min_d = min(min_d, distance(p, proj));
|
||||
prev = cur;
|
||||
}
|
||||
|
||||
return min_d;
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn fragment(
|
||||
@location(0) world_pos: vec3<f32>,
|
||||
) -> @location(0) vec4<f32> {
|
||||
let d = distance_to_bezier(world_pos.xy);
|
||||
|
||||
let half_w = mat.width * 0.5;
|
||||
let aa = fwidth(d);
|
||||
|
||||
let alpha = smoothstep(half_w + aa, half_w - aa, d);
|
||||
|
||||
if (alpha <= 0.001) {
|
||||
discard;
|
||||
}
|
||||
|
||||
return vec4(mat.color.rgb, mat.color.a * alpha);
|
||||
}
|
||||
|
||||
154
src/main.rs
154
src/main.rs
@ -1,12 +1,26 @@
|
||||
use crate::avian::{CharacterControllerBundle, CharacterControllerPlugin};
|
||||
use crate::{
|
||||
avian::{CharacterControllerBundle, CharacterControllerPlugin},
|
||||
shaders::BezierMaterial,
|
||||
};
|
||||
use avian2d::{
|
||||
PhysicsPlugins,
|
||||
math::Vector,
|
||||
prelude::{Collider, Gravity, RigidBody},
|
||||
};
|
||||
use bevy::{camera::ScalingMode, color::palettes::css::GREEN, prelude::*};
|
||||
use bevy::{
|
||||
camera::ScalingMode,
|
||||
color::palettes::css::{GREEN, RED, WHITE},
|
||||
input_focus::InputFocus,
|
||||
prelude::*,
|
||||
sprite_render::Material2dPlugin,
|
||||
};
|
||||
|
||||
pub mod avian;
|
||||
pub mod shaders;
|
||||
|
||||
const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15);
|
||||
const HOVERED_BUTTON: Color = Color::srgb(0.25, 0.25, 0.25);
|
||||
const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35);
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
@ -15,14 +29,63 @@ fn main() {
|
||||
// Add physics plugins and specify a units-per-meter scaling factor, 1 meter = 20 pixels.
|
||||
// The unit allows the engine to tune its parameters for the scale of the world, improving stability.
|
||||
PhysicsPlugins::default().with_length_unit(20.0),
|
||||
Material2dPlugin::<BezierMaterial>::default(),
|
||||
CharacterControllerPlugin,
|
||||
))
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, debug_border)
|
||||
.init_resource::<InputFocus>()
|
||||
.add_systems(Startup, (setup, setup_ui))
|
||||
.add_systems(Update, (debug_border, do_menu, move_bezier))
|
||||
.insert_resource(Gravity(Vector::ZERO))
|
||||
.run();
|
||||
}
|
||||
|
||||
fn do_menu(
|
||||
mut input_focus: ResMut<InputFocus>,
|
||||
mut interaction_query: Query<
|
||||
(
|
||||
Entity,
|
||||
&Interaction,
|
||||
&mut BackgroundColor,
|
||||
&mut BorderColor,
|
||||
&mut Button,
|
||||
&Children,
|
||||
),
|
||||
Changed<Interaction>,
|
||||
>,
|
||||
mut text_query: Query<&mut Text>,
|
||||
) {
|
||||
for (entity, interaction, mut color, mut border_color, mut button, children) in
|
||||
&mut interaction_query
|
||||
{
|
||||
let mut text = text_query.get_mut(children[0]).unwrap();
|
||||
|
||||
match *interaction {
|
||||
Interaction::Pressed => {
|
||||
input_focus.set(entity);
|
||||
**text = "Press".to_string();
|
||||
*color = PRESSED_BUTTON.into();
|
||||
*border_color = BorderColor::all(RED);
|
||||
|
||||
// The accessibility system's only update the button's state when the `Button` component is marked as changed.
|
||||
button.set_changed();
|
||||
}
|
||||
Interaction::Hovered => {
|
||||
input_focus.set(entity);
|
||||
**text = "Hover".to_string();
|
||||
*color = HOVERED_BUTTON.into();
|
||||
*border_color = BorderColor::all(Color::WHITE);
|
||||
button.set_changed();
|
||||
}
|
||||
Interaction::None => {
|
||||
input_focus.clear();
|
||||
**text = "Button".to_string();
|
||||
*color = NORMAL_BUTTON.into();
|
||||
*border_color = BorderColor::all(Color::BLACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
let mut projection = OrthographicProjection::default_2d();
|
||||
projection.scaling_mode = ScalingMode::AutoMin {
|
||||
@ -51,6 +114,89 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
));
|
||||
}
|
||||
|
||||
fn setup_ui(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<BezierMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
Node {
|
||||
width: percent(100),
|
||||
height: percent(100),
|
||||
align_items: AlignItems::Center,
|
||||
justify_content: JustifyContent::Center,
|
||||
..default()
|
||||
},
|
||||
children![(
|
||||
Button,
|
||||
Node {
|
||||
width: px(150),
|
||||
height: px(65),
|
||||
border: UiRect::all(px(5)),
|
||||
// horizontally center child text
|
||||
justify_content: JustifyContent::Center,
|
||||
// vertically center child text
|
||||
align_items: AlignItems::Center,
|
||||
border_radius: BorderRadius::MAX,
|
||||
..default()
|
||||
},
|
||||
BorderColor::all(Color::WHITE),
|
||||
BackgroundColor(Color::BLACK),
|
||||
children![(
|
||||
Text::new("Button"),
|
||||
TextFont {
|
||||
font: asset_server.load("FiraSans-Bold.ttf"),
|
||||
font_size: 33.0,
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9)),
|
||||
TextShadow::default(),
|
||||
)]
|
||||
)],
|
||||
));
|
||||
|
||||
// Curve points (world-space)
|
||||
let p0 = Vec2::new(-200.0, -100.0);
|
||||
let p1 = Vec2::new(200.0, 100.0);
|
||||
let c0 = p0 + Vec2::new(150.0, 0.0);
|
||||
let c1 = p1 + Vec2::new(-150.0, 0.0);
|
||||
|
||||
// Bounding quad (must contain entire curve + width)
|
||||
let center = (p0 + p1) * 0.5;
|
||||
let size = Vec2::new(500.0, 300.0);
|
||||
|
||||
commands.spawn((
|
||||
Mesh2d(meshes.add(Rectangle::new(size.x, size.y))),
|
||||
MeshMaterial2d(materials.add(BezierMaterial {
|
||||
p0,
|
||||
c0,
|
||||
c1,
|
||||
p1,
|
||||
width: 12.0,
|
||||
color: WHITE.into(),
|
||||
})),
|
||||
Transform::from_translation(center.extend(0.0)),
|
||||
));
|
||||
}
|
||||
|
||||
fn move_bezier(mut materials: ResMut<Assets<BezierMaterial>>, windows: Query<&Window>) {
|
||||
let Ok(window) = windows.single() else {
|
||||
return;
|
||||
};
|
||||
let Some(mouse_pos) = window.cursor_position() else {
|
||||
return;
|
||||
};
|
||||
|
||||
for (_, mat) in materials.iter_mut() {
|
||||
mat.p0 = mouse_pos;
|
||||
}
|
||||
|
||||
// pos: Vec2, in logical pixels
|
||||
// (0, 0) is bottom-left of the window
|
||||
println!("Mouse window position: {:?}", mouse_pos);
|
||||
}
|
||||
|
||||
fn debug_border(mut gizmos: Gizmos) {
|
||||
gizmos.rect_2d(Isometry2d::IDENTITY, Vec2::new(1920., 1080.), GREEN);
|
||||
}
|
||||
|
||||
33
src/shaders/mod.rs
Normal file
33
src/shaders/mod.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::render_resource::*;
|
||||
use bevy::shader::ShaderRef;
|
||||
use bevy::sprite_render::{AlphaMode2d, Material2d};
|
||||
|
||||
// This is the struct that will be passed to your shader
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct BezierMaterial {
|
||||
#[uniform(0)]
|
||||
pub p0: Vec2,
|
||||
#[uniform(0)]
|
||||
pub c0: Vec2,
|
||||
#[uniform(0)]
|
||||
pub c1: Vec2,
|
||||
#[uniform(0)]
|
||||
pub p1: Vec2,
|
||||
#[uniform(0)]
|
||||
pub width: f32,
|
||||
#[uniform(0)]
|
||||
pub color: LinearRgba,
|
||||
}
|
||||
|
||||
/// The Material2d trait is very configurable, but comes with sensible defaults for all methods.
|
||||
/// You only need to implement functions for features that need non-default behavior. See the Material2d api docs for details!
|
||||
impl Material2d for BezierMaterial {
|
||||
fn fragment_shader() -> ShaderRef {
|
||||
"shaders/bezier.wgsl".into()
|
||||
}
|
||||
|
||||
fn alpha_mode(&self) -> AlphaMode2d {
|
||||
AlphaMode2d::Blend
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user