Skip to content

Commit

Permalink
Add vent-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Jun 28, 2024
1 parent 7695631 commit cb72a3a
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 148 deletions.
184 changes: 64 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion crates/vent-assets/src/model/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ impl GLTFLoader {
meshes: all_meshes,
};


if cached_pipeline.contains_key(&pipeline_info) {
pipelines.push(ModelPipeline {
pipeline: *cached_pipeline.get(&pipeline_info).unwrap(),
Expand Down
2 changes: 0 additions & 2 deletions crates/vent-editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ log = "0.4"

# rfd = { version="0.12.1", default-features = false, features = ["xdg-portal"]}

[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies]
simple_logger = "5.0"
2 changes: 0 additions & 2 deletions crates/vent-editor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// use crate::render::EditorRenderer;

// use simple_logger::SimpleLogger;

// use vent_common::util::crash::init_panic_hook;
// use vent_common::window::VentWindow;
// use vent_runtime::render::camera::{Camera, Camera3D};
Expand Down
14 changes: 14 additions & 0 deletions crates/vent-logging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "vent-logging"
version.workspace = true
edition.workspace = true

[dependencies]
log = { version="0.4", features = ["std"] }
colored = "2.1.0"

[target.'cfg(target_family = "wasm")'.dependencies]
web-sys = { version = "0.3.69", features = ["console"] }

[target.'cfg(target_os = "android")'.dependencies]
ndk-sys = "0.6"
68 changes: 68 additions & 0 deletions crates/vent-logging/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use colored::Colorize;
use log::{Level, LevelFilter, Log};

///
/// Cross Platform Logger
///
pub struct Logger {
}

impl Logger {
pub fn new() {
log::set_max_level(LevelFilter::Trace);
log::set_boxed_logger(Box::new(Self {})).expect("failed to set boxed logger");
}
}

impl Log for Logger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
true // TODO
}

fn log(&self, record: &log::Record) {
// Default
#[cfg(not(any(target_arch = "wasm32", target_os = "android")))]
{
let level = match record.level() {
Level::Error => format!("{:<5}", record.level().to_string().red()),
Level::Warn => format!("{:<5}", record.level().to_string().yellow()),
Level::Info => format!("{:<5}", record.level().to_string().cyan()),
Level::Debug => format!("{:<5}", record.level().to_string().purple()),
Level::Trace => format!("{:<5}", record.level().to_string().normal()),
};
println!("{} {}", level, record.args())
}
// Wasm
#[cfg(target_family = "wasm")]
{
match record.level() {
Level::Error => web_sys::console::error_1(&format!("{}", record.args()).into()),
Level::Warn => web_sys::console::warn_1(&format!("{}", record.args()).into()),
Level::Info => web_sys::console::info_1(&format!("{}", record.args()).into()),
Level::Debug => web_sys::console::debug_1(&format!("{}", record.args()).into()),
Level::Trace => web_sys::console::trace_1(&format!("{}", record.args()).into()),
}
}
// Android
#[cfg(target_os = "android")]
{
use std::ffi::{c_int, CStr, CString};
let prio = match record.level() {
Level::Error => ndk_sys::android_LogPriority::ANDROID_LOG_ERROR,
Level::Warn => ndk_sys::android_LogPriority::ANDROID_LOG_WARN,
Level::Info => ndk_sys::android_LogPriority::ANDROID_LOG_INFO,
Level::Debug => ndk_sys::android_LogPriority::ANDROID_LOG_DEBUG,
Level::Trace => ndk_sys::android_LogPriority::ANDROID_LOG_VERBOSE,
};
unsafe {
ndk_sys::__android_log_write(
prio.0 as c_int,
CStr::from("").as_ptr(),
record.args().as_ptr(),
);
}
}
}

fn flush(&self) {}
}
22 changes: 14 additions & 8 deletions crates/vent-rendering/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,20 @@ impl VulkanInstance {
tiling: vk::ImageTiling,
features: vk::FormatFeatureFlags,
) -> Option<vk::Format> {
candidates.iter().find(|f| {
let properties = unsafe { instance.get_physical_device_format_properties(pdevice, **f) };
match tiling {
vk::ImageTiling::LINEAR => properties.linear_tiling_features.contains(features),
vk::ImageTiling::OPTIMAL => properties.optimal_tiling_features.contains(features),
_ => false,
}
}).copied()
candidates
.iter()
.find(|f| {
let properties =
unsafe { instance.get_physical_device_format_properties(pdevice, **f) };
match tiling {
vk::ImageTiling::LINEAR => properties.linear_tiling_features.contains(features),
vk::ImageTiling::OPTIMAL => {
properties.optimal_tiling_features.contains(features)
}
_ => false,
}
})
.copied()
}

fn create_frame_buffers(
Expand Down
5 changes: 1 addition & 4 deletions crates/vent-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ vent-rendering = { path = "../vent-rendering"}
vent-assets = { path = "../vent-assets" }
vent-ecs = { path = "../vent-ecs"}
vent-window = { path = "../vent-window"}
vent-logging = { path = "../vent-logging"}

ash = { version= "0.38", default-features = false, features = ["linked", "debug"] }

Expand All @@ -28,10 +29,6 @@ android_logger = "0.14"
android-activity = { version = "0.6", features = [ "game-activity" ] }
ndk = "0.9.0"

[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies]
simple_logger = "5.0"



[build-dependencies]
fs_extra = "1.3.0"
10 changes: 2 additions & 8 deletions crates/vent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::process::exit;
use crate::render::Dimension;

use render::{camera::camera_controller3d::CameraController3D, DefaultRuntimeRenderer};
use simple_logger::SimpleLogger;
use vent_common::project::VentApplicationProject;

use vent_common::util::crash::init_panic_hook;
use vent_logging::Logger;
use vent_window::{EventLoop, Window, WindowAttribs, WindowEvent};

pub mod render;
Expand All @@ -18,13 +18,7 @@ pub struct VentApplication {
impl VentApplication {
pub fn default() {
init_panic_hook();
#[cfg(not(target_arch = "wasm32"))]
{
SimpleLogger::new()
.with_level(log::LevelFilter::Info)
.init()
.unwrap();
};
Logger::new();

let project = VentApplicationProject {
name: "Placeholder".to_string(),
Expand Down
6 changes: 3 additions & 3 deletions crates/vent-window/src/platform/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl SeatHandler for WaylandWindow {
capability: sctk::seat::Capability,
) {
if capability == Capability::Keyboard && self.keyboard.is_none() {
println!("Set keyboard capability");
log::debug!("Set keyboard capability");
let keyboard = self
.seat_state
.get_keyboard(qh, &seat, None)
Expand Down Expand Up @@ -522,12 +522,12 @@ impl SeatHandler for WaylandWindow {
capability: sctk::seat::Capability,
) {
if capability == Capability::Keyboard && self.keyboard.is_some() {
println!("Unset keyboard capability");
log::debug!("Unset keyboard capability");
self.keyboard.take().unwrap().release();
}

if capability == Capability::Pointer && self.themed_pointer.is_some() {
println!("Unset pointer capability");
log::debug!("Unset pointer capability");
self.themed_pointer.take().unwrap().pointer().release();
}
}
Expand Down

0 comments on commit cb72a3a

Please sign in to comment.