Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ private static Path resolveNativeDir() {
final Path gameDir = SableLoaderPlatform.INSTANCE.getGameDirectory();
if (gameDir != null) {
final Path gameDirRelativeDir = gameDir.resolve(".sable").resolve("natives").normalize();
Sable.LOGGER.info("Using game-dir-relative Rapier native directory {}", gameDirRelativeDir.toAbsolutePath());
Sable.LOGGER.info("Using game directory relative Sable Rapier native directory {}", gameDirRelativeDir.toAbsolutePath());
return gameDirRelativeDir;
}

final Path fallbackDir = Paths.get(System.getProperty("user.home", System.getProperty("user.dir")), ".sable", "natives");
Sable.LOGGER.info("Using fallback Rapier native directory {}", fallbackDir.toAbsolutePath());
Sable.LOGGER.info("Using fallback Sable Rapier native directory {}", fallbackDir.toAbsolutePath());
return fallbackDir;
}

Expand Down
Binary file not shown.
37 changes: 36 additions & 1 deletion sable_rapier/src/main/rust/rapier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use jni::sys::{jboolean, jdouble, jint, jlong};
use jni::{JNIEnv, JavaVM};
use rapier3d::glamx::{DVec3, Quat};
use std::collections::HashMap;
use std::io::ErrorKind::BrokenPipe;
use std::io::{self, Write};
use std::sync::{Arc, OnceLock, RwLock};

use fern::colors::{Color, ColoredLevelConfig};
Expand Down Expand Up @@ -303,6 +305,39 @@ pub fn get_rigid_body<'a>(
&sim.rigid_body_set[*handle]
}

struct LogWriter;

impl Write for LogWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut stdout = io::stdout().lock();
match stdout.write(buf) {
Err(error) => {
if error.kind() == BrokenPipe {
Ok(buf.len())
} else {
Err(error)
}
}
other => other,
}
}

fn flush(&mut self) -> io::Result<()> {
let mut stdout = io::stdout().lock();

match stdout.flush() {
Err(error) => {
if error.kind() == BrokenPipe {
Ok(())
} else {
Err(error)
}
}
other => other,
}
}
}

#[unsafe(no_mangle)]
pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_initialize<'local>(
env: JNIEnv<'local>,
Expand Down Expand Up @@ -330,7 +365,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_ini
})
.level(log::LevelFilter::Info)
.level_for("jni", log::LevelFilter::Error)
.chain(std::io::stdout())
.chain(fern::Output::writer(Box::new(LogWriter), "\n"))
.apply();

RwLock::new(PhysicsState {
Expand Down
Loading