Merge pull request 'input_test' (#1) from input_test into main

Reviewed-on: https://codeberg.org/Caznix/Zenyx/pulls/1
This commit is contained in:
Caznix 2025-03-24 22:13:44 +00:00
commit 36860b4fa5
11 changed files with 253 additions and 194 deletions

3
.gitignore vendored
View file

@ -2,4 +2,5 @@
.idea .idea
# Cargo.lock # Cargo.lock
*.log *.log
.direnv .direnv
**/result

120
Cargo.lock generated
View file

@ -103,6 +103,15 @@ version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
[[package]]
name = "approx"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.9" version = "0.3.9"
@ -213,16 +222,6 @@ dependencies = [
"objc2", "objc2",
] ]
[[package]]
name = "bstr"
version = "1.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "531a9155a481e2ee699d4f98f43c0ca4ff8ee1bfd55c31e9e98fb29d2b176fe0"
dependencies = [
"memchr",
"serde",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.17.0" version = "3.17.0"
@ -310,6 +309,16 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "cgmath"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"
dependencies = [
"approx",
"num-traits",
]
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.40" version = "0.4.40"
@ -514,24 +523,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53"
[[package]]
name = "either"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]] [[package]]
name = "endian-type" name = "endian-type"
version = "0.1.2" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
[[package]]
name = "env_home"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe"
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.2" version = "1.0.2"
@ -1154,25 +1151,6 @@ version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
[[package]]
name = "lua-src"
version = "547.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edaf29e3517b49b8b746701e5648ccb5785cde1c119062cbabbc5d5cd115e42"
dependencies = [
"cc",
]
[[package]]
name = "luajit-src"
version = "210.5.12+a4f56a4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671"
dependencies = [
"cc",
"which",
]
[[package]] [[package]]
name = "malloc_buf" name = "malloc_buf"
version = "0.0.6" version = "0.0.6"
@ -1221,34 +1199,6 @@ dependencies = [
"adler2", "adler2",
] ]
[[package]]
name = "mlua"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3f763c1041eff92ffb5d7169968a327e1ed2ebfe425dac0ee5a35f29082534b"
dependencies = [
"anyhow",
"bstr",
"either",
"mlua-sys",
"num-traits",
"parking_lot",
"rustc-hash 2.1.1",
]
[[package]]
name = "mlua-sys"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1901c1a635a22fe9250ffcc4fcc937c16b47c2e9e71adba8784af8bca1f69594"
dependencies = [
"cc",
"cfg-if",
"lua-src",
"luajit-src",
"pkg-config",
]
[[package]] [[package]]
name = "naga" name = "naga"
version = "24.0.0" version = "24.0.0"
@ -1263,7 +1213,7 @@ dependencies = [
"hexf-parse", "hexf-parse",
"indexmap", "indexmap",
"log", "log",
"rustc-hash 1.1.0", "rustc-hash",
"spirv", "spirv",
"strum", "strum",
"termcolor", "termcolor",
@ -1849,12 +1799,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hash"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.44" version = "0.38.44"
@ -2602,7 +2546,7 @@ dependencies = [
"parking_lot", "parking_lot",
"profiling", "profiling",
"raw-window-handle", "raw-window-handle",
"rustc-hash 1.1.0", "rustc-hash",
"smallvec", "smallvec",
"thiserror 2.0.12", "thiserror 2.0.12",
"wgpu-hal", "wgpu-hal",
@ -2645,7 +2589,7 @@ dependencies = [
"range-alloc", "range-alloc",
"raw-window-handle", "raw-window-handle",
"renderdoc-sys", "renderdoc-sys",
"rustc-hash 1.1.0", "rustc-hash",
"smallvec", "smallvec",
"thiserror 2.0.12", "thiserror 2.0.12",
"wasm-bindgen", "wasm-bindgen",
@ -2667,18 +2611,6 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "which"
version = "7.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2774c861e1f072b3aadc02f8ba886c26ad6321567ecc294c935434cad06f1283"
dependencies = [
"either",
"env_home",
"rustix 0.38.44",
"winsafe",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
@ -3055,12 +2987,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "winsafe"
version = "0.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
[[package]] [[package]]
name = "write16" name = "write16"
version = "1.0.0" version = "1.0.0"
@ -3176,6 +3102,7 @@ dependencies = [
"anyhow", "anyhow",
"backtrace", "backtrace",
"bytemuck", "bytemuck",
"cgmath",
"chrono", "chrono",
"colored 3.0.0", "colored 3.0.0",
"crashreport", "crashreport",
@ -3183,7 +3110,6 @@ dependencies = [
"futures", "futures",
"lazy_static", "lazy_static",
"log", "log",
"mlua",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
"regex", "regex",

View file

@ -1,30 +1,37 @@
{ lib, rustPlatform, nix-gitignore, bash, makeWrapper, dav1d, pkg-config }: {
let lib,
version = (builtins.fromTOML (builtins.readFile ./engine/Cargo.toml)).package.version; rustPlatform,
src = nix-gitignore.gitignoreSource [] ./.; nix-gitignore,
in bash,
rustPlatform.buildRustPackage rec { makeWrapper,
pname = "zenyx"; dav1d,
inherit src version; pkg-config,
cargoLock.lockFile = ./Cargo.lock; }: let
nativeBuildInputs = [ version = (builtins.fromTOML (builtins.readFile ./engine/Cargo.toml)).package.version;
makeWrapper src = nix-gitignore.gitignoreSource [] ./.;
pkg-config in
]; rustPlatform.buildRustPackage rec {
buildInputs = [ pname = "zenyx";
bash inherit src version;
dav1d cargoLock.lockFile = ./Cargo.lock;
]; nativeBuildInputs = [
doCheck = false; makeWrapper
pkg-config
];
buildInputs = [
bash
dav1d
];
doCheck = false;
fixupPhase = '' fixupPhase = ''
wrapProgram $out/bin/${pname} --set PATH ${bash}/bin:\$PATH wrapProgram $out/bin/${pname} --set PATH ${bash}/bin:\$PATH
''; '';
meta = { meta = {
description = "Test"; description = "Test";
license = lib.licenses.mit; license = lib.licenses.mit;
platforms = lib.platforms.linux; platforms = lib.platforms.linux;
mainProgram = "zenyx"; mainProgram = "zenyx";
}; };
} }

View file

@ -33,8 +33,6 @@ pub fn set_panic_hook() {
default_hook(info); default_hook(info);
std::process::exit(0); std::process::exit(0);
}); });
// Instead of using payload_as_str(), downcast the panic payload:
let payload = info.payload(); let payload = info.payload();
let payload_str = if let Some(s) = payload.downcast_ref::<&str>() { let payload_str = if let Some(s) = payload.downcast_ref::<&str>() {
*s *s
@ -65,7 +63,6 @@ https://github.com/Zenyx-Engine/Zenyx/issues
We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports. We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.
Thank you kindly!", log_path.display()); Thank you kindly!", log_path.display());
println!("{}", panic_msg.red().bold()); println!("{}", panic_msg.red().bold());
println!("\nFor future reference, the error summary is as follows:\n{}", payload_str.red().bold()); println!("\nFor future reference, the error summary is as follows:\n{}", payload_str.red().bold());
std::process::exit(0); std::process::exit(0);

View file

@ -78,7 +78,7 @@ impl Vertex {
} }
} }
const CUBE_VERTICES: &[Vertex] = &[ static CUBE_VERTICES: &[Vertex] = &[
Vertex { Vertex {
position: [-0.5, -0.5, 0.5], position: [-0.5, -0.5, 0.5],
normal: [0.0, 0.0, 1.0], normal: [0.0, 0.0, 1.0],
@ -235,6 +235,7 @@ pub struct WgpuCtx<'window> {
uniform_buffer: wgpu::Buffer, uniform_buffer: wgpu::Buffer,
vertex_buffer: wgpu::Buffer, vertex_buffer: wgpu::Buffer,
start_time: Instant, start_time: Instant,
bg_color: wgpu::Color,
} }
impl<'window> WgpuCtx<'window> { impl<'window> WgpuCtx<'window> {
@ -346,6 +347,12 @@ impl<'window> WgpuCtx<'window> {
render_pipeline, render_pipeline,
uniform_buffer, uniform_buffer,
vertex_buffer, vertex_buffer,
bg_color: wgpu::Color {
r: 0.1,
g: 0.1,
b: 0.1,
a: 1.0,
},
start_time: Instant::now(), start_time: Instant::now(),
}) })
} }
@ -362,7 +369,7 @@ impl<'window> WgpuCtx<'window> {
} }
pub fn draw(&mut self) { pub fn draw(&mut self) {
let elapsed = self.start_time.elapsed().as_secs_f32(); let elapsed = self.start_time.elapsed().as_secs_f32() * 0.80f32;
let model = Matrix4::from_angle_x(Rad(elapsed)) * Matrix4::from_angle_y(Rad(elapsed)); let model = Matrix4::from_angle_x(Rad(elapsed)) * Matrix4::from_angle_y(Rad(elapsed));
let view = Matrix4::look_at_rh( let view = Matrix4::look_at_rh(
Point3::new(0.0, 0.0, 3.0), Point3::new(0.0, 0.0, 3.0),
@ -399,12 +406,7 @@ impl<'window> WgpuCtx<'window> {
view: &view_texture, view: &view_texture,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color { load: wgpu::LoadOp::Clear(self.bg_color),
r: 0.1,
g: 0.1,
b: 0.1,
a: 1.0,
}),
store: wgpu::StoreOp::Store, store: wgpu::StoreOp::Store,
}, },
})], })],
@ -428,4 +430,11 @@ impl<'window> WgpuCtx<'window> {
self.queue.submit(Some(encoder.finish())); self.queue.submit(Some(encoder.finish()));
surface_texture.present(); surface_texture.present();
} }
pub fn change_bg_color(&mut self, color: wgpu::Color) {
self.bg_color = color;
}
pub fn bg_color(&self) -> wgpu::Color {
self.bg_color.clone()
}
} }

View file

@ -42,6 +42,28 @@ impl ApplicationHandler for App<'_> {
debug!("Window closed, exiting"); debug!("Window closed, exiting");
std::process::exit(0) std::process::exit(0)
} }
WindowEvent::KeyboardInput { device_id, event, is_synthetic } => {
match event.physical_key {
winit::keyboard::PhysicalKey::Code(code) => {
if event.state.is_pressed() == false {
return;
}
if code == winit::keyboard::KeyCode::Escape {
// event_loop.exit();
debug!("Window closed, exiting");
if let Some(ctx) = &mut self.ctx {
match ctx.bg_color() {
wgpu::Color::WHITE => ctx.change_bg_color(wgpu::Color::BLACK),
wgpu::Color::BLACK => ctx.change_bg_color(wgpu::Color::WHITE),
_ => ctx.change_bg_color(wgpu::Color::WHITE),
}
// std::process::exit(0)
}
}
}
_ => {}
}
}
WindowEvent::RedrawRequested => { WindowEvent::RedrawRequested => {
if let Some(ctx) = &mut self.ctx { if let Some(ctx) = &mut self.ctx {
ctx.draw(); ctx.draw();

View file

@ -33,7 +33,7 @@ impl Command for HelpCommand {
} }
} }
Ok(()) Ok(())
} }
fn undo(&self) {} fn undo(&self) {}

View file

@ -1,8 +1,4 @@
use core::{ use core::{panic::set_panic_hook, repl::setup, splash, workspace};
panic::set_panic_hook,
repl::setup,
splash, workspace,
};
use colored::Colorize; use colored::Colorize;
use log::info; use log::info;
@ -22,7 +18,10 @@ async fn main() -> anyhow::Result<()> {
info!("Type 'help' for a list of commands."); info!("Type 'help' for a list of commands.");
let repl_thread = std::thread::spawn(|| { let repl_thread = std::thread::spawn(|| {
let rt = runtime::Builder::new_current_thread().enable_all().build().unwrap(); let rt = runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
rt.block_on(core::repl::input::handle_repl()) rt.block_on(core::repl::input::handle_repl())
}); });

79
flake.lock generated
View file

@ -1,5 +1,50 @@
{ {
"nodes": { "nodes": {
"alejandra": {
"inputs": {
"fenix": "fenix",
"flakeCompat": "flakeCompat",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1730688725,
"narHash": "sha256-g0SSfTWZ5mtMOpQic+eqq9sXMy1E/7yKxxfupZd9V4A=",
"owner": "kamadorueda",
"repo": "alejandra",
"rev": "2bb91e309ca99656addff5c74545acbf5813636d",
"type": "github"
},
"original": {
"owner": "kamadorueda",
"ref": "3.1.0",
"repo": "alejandra",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"alejandra",
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1730615655,
"narHash": "sha256-2HBR3zLn57LXKNRtxBb+O+uDqHM4n0pz51rPayMl4cg=",
"owner": "nix-community",
"repo": "fenix",
"rev": "efeb50e2535b17ffd4a135e6e3e5fd60a525180c",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-compat": { "flake-compat": {
"locked": { "locked": {
"lastModified": 1733328505, "lastModified": 1733328505,
@ -14,6 +59,22 @@
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
} }
}, },
"flakeCompat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1742422364, "lastModified": 1742422364,
@ -48,12 +109,30 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"alejandra": "alejandra",
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay", "rust-overlay": "rust-overlay",
"utils": "utils" "utils": "utils"
} }
}, },
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1730555913,
"narHash": "sha256-KNHZUlqsEibg3YtfUyOFQSofP8hp1HKoY+laoesBxRM=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "f17a5bbfd0969ba2e63a74505a80e55ecb174ed9",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"

103
flake.nix
View file

@ -1,50 +1,67 @@
{ {
description = "Zenyx - A WSYWIG game engine written in rust "; description = "Zenyx - A WSYWIG game engine written in rust ";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.url = "github:oxalica/rust-overlay";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
}; alejandra.url = "github:kamadorueda/alejandra/3.1.0";
alejandra.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, utils,rust-overlay, ... }: { outputs = {
overlays.default = final: prev: { self,
zenyx = final.callPackage ./build.nix {}; nixpkgs,
}; utils,
} rust-overlay,
// alejandra,
utils.lib.eachDefaultSystem (system: ...
let pkgs = import nixpkgs { }:
inherit system; {
overlays = [self.overlays.default (import rust-overlay) ]; overlays.default = final: prev: {
}; zenyx = final.callPackage ./build.nix {};
in { };
packages = { }
inherit (pkgs) zenyx; // utils.lib.eachDefaultSystem (
default = pkgs.zenyx; system: let
}; pkgs = import nixpkgs {
inherit system;
devShells.default = pkgs.mkShell { overlays = [
name = "zenyx"; self.overlays.default
nativeBuildInputs = with pkgs; [ (import rust-overlay)
(rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { ];
extensions = [ "cargo" "clippy" ]; };
# targets = [ "arm-unknown-linux-gnueabihf" ];
}))
pkg-config
];
buildInputs = with pkgs; [ buildInputs = with pkgs; [
vulkan-loader vulkan-loader
wayland wayland
libxkbcommon libxkbcommon
xorg.libXcursor xorg.libXcursor
xorg.libXrandr xorg.libXrandr
xorg.libXi xorg.libXi
xorg.libX11 xorg.libX11
xorg.libxcb xorg.libxcb
pkg-config pkg-config
]; ];
}; in {
} packages = {
); inherit (pkgs) zenyx;
default = pkgs.zenyx;
};
devShells.default = pkgs.mkShell {
name = "zenyx";
nativeBuildInputs = with pkgs; [
rust-bin.stable.latest.default
pkg-config
];
buildInputs = buildInputs;
shellHook = ''
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}";
echo "Rust version: $(rustc --version)";
'';
};
formatter = alejandra.packages.${system}.default;
}
);
} }

View file

@ -1,13 +1,15 @@
(import (
import
( (
let let
lock = builtins.fromJSON (builtins.readFile ./flake.lock); lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat; nodeName = lock.nodes.root.inputs.flake-compat;
in in
fetchTarball { fetchTarball {
url = lock.nodes.${nodeName}.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz"; url = lock.nodes.${nodeName}.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash; sha256 = lock.nodes.${nodeName}.locked.narHash;
} }
) )
{ src = ./.; } {src = ./.;}
).shellNix )
.shellNix