summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--crates/teleia/src/state.rs9
-rw-r--r--crates/teleia_macros/Cargo.toml4
-rw-r--r--crates/teleia_macros/src/lib.rs23
-rw-r--r--flake.nix27
5 files changed, 54 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8223b30..d772325 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1419,6 +1419,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
[[package]]
+name = "litrs"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"
+
+[[package]]
name = "log"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2719,6 +2725,7 @@ name = "teleia_macros"
version = "0.1.0"
dependencies = [
"heck",
+ "litrs",
"walkdir",
]
diff --git a/crates/teleia/src/state.rs b/crates/teleia/src/state.rs
index 3df5d7c..4031421 100644
--- a/crates/teleia/src/state.rs
+++ b/crates/teleia/src/state.rs
@@ -6,7 +6,7 @@ use serde::{Serialize, Deserialize};
use crate::{audio, context, framebuffer, mesh, shader, utils};
-const DELTA_TIME: f64 = 1.0 / 61.0; // todo
+const DELTA_TIME: f64 = 0.016; // todo
pub struct WinitWaker {}
impl WinitWaker {
@@ -25,9 +25,10 @@ pub struct Response {
pub trait Game {
fn initialize(&self, ctx: &context::Context, st: &State) -> utils::Erm<()> { Ok(()) }
fn finalize(&self, ctx: &context::Context, st: &State) -> utils::Erm<()> { Ok(()) }
- fn initialize_audio(&self, ctx: &context::Context, st: &State, actx: &audio::Context) ->
- HashMap<String, audio::Audio>
- {
+ fn initialize_audio(
+ &self, ctx: &context::Context, st: &State,
+ actx: &audio::Context
+ ) -> HashMap<String, audio::Audio> {
HashMap::new()
}
fn finish_title(&mut self, st: &mut State) {}
diff --git a/crates/teleia_macros/Cargo.toml b/crates/teleia_macros/Cargo.toml
index b56494e..a3d4fe6 100644
--- a/crates/teleia_macros/Cargo.toml
+++ b/crates/teleia_macros/Cargo.toml
@@ -8,5 +8,7 @@ authors.workspace = true
proc-macro = true
[dependencies]
+env = "*"
walkdir = "*"
-heck = "*" \ No newline at end of file
+heck = "*"
+litrs = "*" \ No newline at end of file
diff --git a/crates/teleia_macros/src/lib.rs b/crates/teleia_macros/src/lib.rs
index d095873..664fc01 100644
--- a/crates/teleia_macros/src/lib.rs
+++ b/crates/teleia_macros/src/lib.rs
@@ -1,11 +1,9 @@
-use proc_macro::TokenStream;
+use proc_macro::{TokenStream};
use std::path::Path;
use std::collections::HashSet;
use walkdir::WalkDir;
use heck::ToUpperCamelCase;
-const BASE: &'static str = "src/assets/";
-
#[derive(Debug, Hash, PartialEq, Eq)]
struct Designator {
parts: Vec<String>,
@@ -26,7 +24,6 @@ impl Designator {
}
}
fn enum_entry(&self, _fnm: &str) -> String {
- let vs: Vec<_> = self.parts.iter().map(|s| s.to_uppercase()).collect();
format!("{}", self.parts.join(" ").to_upper_camel_case())
}
fn load_expr(&self, fnm: &str) -> Option<String> {
@@ -54,9 +51,9 @@ struct Field {
entries: HashSet<Designator>,
}
impl Field {
- fn new(nm: &str) -> Self {
+ fn new(base: &str, nm: &str) -> Self {
let mut entries = HashSet::new();
- let fbase = format!("{}{}", BASE, nm);
+ let fbase = format!("{}{}", base, nm);
for mf in WalkDir::new(&fbase) {
if let Ok(f) = mf {
if f.file_type().is_file() {
@@ -105,12 +102,12 @@ struct AssetData {
fields: Vec<Field>,
}
impl AssetData {
- fn new() -> Self {
+ fn new(base: &str) -> Self {
let mut fields = Vec::new();
- let dirs = std::fs::read_dir(BASE).expect("failed to read assets directory");
+ let dirs = std::fs::read_dir(base).expect(&format!("failed to read assets directory: {}", base));
for dir in dirs {
if let Ok(d) = dir {
- fields.push(Field::new(&d.file_name().into_string().unwrap()));
+ fields.push(Field::new(base, &d.file_name().into_string().unwrap()));
}
}
Self {
@@ -139,8 +136,12 @@ impl AssetData {
}
#[proc_macro]
-pub fn generate_assets(_s: TokenStream) -> TokenStream {
- let assets = AssetData::new();
+pub fn generate_assets(s: TokenStream) -> TokenStream {
+ let token = s.into_iter().next().expect("must pass asset base path as a string literal");
+ let lit = litrs::StringLit::try_from(token).expect("argument was not a string literal");
+ let base = lit.value();
+ let manifest = env::var("CARGO_MANIFEST_DIR").expect("failed to get manifest path");
+ let assets = AssetData::new(&format!("{}/{}", manifest, base));
// println!("{}", assets.generate());
format!("{}", assets.generate()).parse().expect("failed to parse generate_assets result")
}
diff --git a/flake.nix b/flake.nix
index 6a0b67c..cc05aeb 100644
--- a/flake.nix
+++ b/flake.nix
@@ -58,6 +58,30 @@
pkgs.libglvnd
pkgs.alsa-lib
];
+ deps = path: nm:
+ let
+ src = lib.cleanSourceWith {
+ src = path;
+ filter = path: type:
+ (lib.hasSuffix "\.html" path) ||
+ (lib.hasSuffix "\.js" path) ||
+ (lib.hasSuffix "\.css" path) ||
+ (lib.hasInfix "/assets/" path) ||
+ (craneLib.filterCargoSources path type)
+ ;
+ };
+ commonArgs = {
+ inherit src nativeBuildInputs buildInputs;
+ strictDeps = true;
+ CARGO_BUILD_TARGET = "x86_64-unknown-linux-gnu";
+ CARGO_BUILD_RUSTFLAGS="-L ${glfw}/lib";
+ inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
+ };
+ cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
+ doCheck = false;
+ });
+ in
+ cargoArtifacts;
build = path: nm:
let
src = lib.cleanSourceWith {
@@ -199,5 +223,8 @@
default = shell;
windows = windows.shell;
};
+ packages.${system} = {
+ default = native.deps ./. "teleia";
+ };
};
}