summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-15 15:30:51 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-15 15:30:51 +0200
commite04589e8b766882375a30c00fb715687a7cc9821 (patch)
treead7a05fbe76b3271a0a674795e66b88e6c6c2cbb
parent23c43903e65bcd03f5fa97874fa3cee74afda33a (diff)
downloadhurrycurry-e04589e8b766882375a30c00fb715687a7cc9821.tar
hurrycurry-e04589e8b766882375a30c00fb715687a7cc9821.tar.bz2
hurrycurry-e04589e8b766882375a30c00fb715687a7cc9821.tar.zst
atlas packing
-rw-r--r--light-client/src/main.rs4
-rw-r--r--light-client/textures/.gitignore3
-rw-r--r--light-client/textures/makefile5
-rw-r--r--light-client/tools/src/bin/tex_pack.rs16
4 files changed, 17 insertions, 11 deletions
diff --git a/light-client/src/main.rs b/light-client/src/main.rs
index 85254ef4..cb7e6caf 100644
--- a/light-client/src/main.rs
+++ b/light-client/src/main.rs
@@ -1,4 +1,3 @@
-use network::Network;
/*
Hurry Curry! - a game about cooking
Copyright 2024 metamuffin
@@ -16,6 +15,7 @@ use network::Network;
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+use network::Network;
use sdl2::{
event::Event,
image::InitFlag,
@@ -24,8 +24,8 @@ use sdl2::{
render::TextureAccess,
};
-pub mod network;
pub mod game;
+pub mod network;
fn main() {
let net = Network::connect("ws://127.0.0.1:27032/");
diff --git a/light-client/textures/.gitignore b/light-client/textures/.gitignore
index e33609d2..d235d3ec 100644
--- a/light-client/textures/.gitignore
+++ b/light-client/textures/.gitignore
@@ -1 +1,4 @@
*.png
+/atlas.ta
+/atlas.meta.csv
+
diff --git a/light-client/textures/makefile b/light-client/textures/makefile
index 1dd60ff4..d130ec97 100644
--- a/light-client/textures/makefile
+++ b/light-client/textures/makefile
@@ -6,11 +6,14 @@ ALL_PNG = $(patsubst %.ta,%.png,$(shell find -name '*.ta'))
.PHONY: tex_export tex_import clean
tex_import: $(ALL_TA)
tex_export: $(ALL_PNG)
+tex_pack: atlas.ta
clean:
- rm $(ALL_PNG)
+ rm -f $(ALL_PNG)
%.ta: %.png
../../target/release/tex_import $< $@
%.png: %.ta
../../target/release/tex_export $< $@
+atlas.ta atlas.meta.csv: $(ALL_TA)
+ ../../target/release/tex_pack $@ atlas.meta.csv $^
diff --git a/light-client/tools/src/bin/tex_pack.rs b/light-client/tools/src/bin/tex_pack.rs
index 23056608..7ac3346c 100644
--- a/light-client/tools/src/bin/tex_pack.rs
+++ b/light-client/tools/src/bin/tex_pack.rs
@@ -31,8 +31,11 @@ fn main() {
for path in inputs {
let file = BufReader::new(File::open(&path).unwrap());
let tex = file.lines().map(Result::unwrap).collect::<Vec<String>>();
+ let name = path.file_stem().unwrap().to_str().unwrap().to_string();
let (width, height) = (tex[0].len(), tex.len());
+ println!("adding {width}x{height} {name}");
+
if cursor_x + width > atlas_size {
cursor_y += row_height;
row_height = 0;
@@ -42,7 +45,7 @@ fn main() {
panic!("texture too big or atlas full")
}
row_height = row_height.max(atlas_size);
- let texcoord = [cursor_x, cursor_y];
+ let texcoord = [cursor_x, cursor_y, width, height];
for (y, line) in tex.iter().enumerate() {
if line.is_empty() {
@@ -53,12 +56,9 @@ fn main() {
}
}
- metadata.push((
- texcoord,
- path.file_stem().unwrap().to_str().unwrap().to_string(),
- ));
+ metadata.push((texcoord, name));
- cursor_x += atlas_size;
+ cursor_x += width;
}
let mut atlas_out = BufWriter::new(File::create(atlas_out).unwrap());
@@ -71,7 +71,7 @@ fn main() {
writeln!(atlas_out).unwrap();
}
- for ([x, y], name) in metadata {
- writeln!(atlas_meta_out, "{x},{y},{name}").unwrap();
+ for ([x, y, w, h], name) in metadata {
+ writeln!(atlas_meta_out, "{x},{y},{w},{h},{name}").unwrap();
}
}