move logging hooks out to raylib itself
This commit is contained in:
parent
b650083bcb
commit
df6425c306
@ -16,7 +16,7 @@ serde_json = "1.0.64"
|
|||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
rust-embed = "6.2.0"
|
rust-embed = "6.2.0"
|
||||||
raylib = "3.5"
|
raylib = { version = "3.5", git = "https://github.com/ewpratten/raylib-rs", rev = "bdee38594356478a11a95a48b336a97150749334" }
|
||||||
puffin = "0.9"
|
puffin = "0.9"
|
||||||
puffin_http = "0.6"
|
puffin_http = "0.6"
|
||||||
dirty-fsm = "^0.2.2"
|
dirty-fsm = "^0.2.2"
|
||||||
@ -29,7 +29,6 @@ pkg-version = "1.0"
|
|||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
num-derive = "0.3"
|
num-derive = "0.3"
|
||||||
num = "0.4"
|
num = "0.4"
|
||||||
printf = "0.1"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
puffin_viewer = "0.6"
|
puffin_viewer = "0.6"
|
||||||
|
@ -76,10 +76,15 @@ use raylib::prelude::*;
|
|||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use utilities::discord::DiscordConfig;
|
use utilities::discord::DiscordConfig;
|
||||||
|
|
||||||
use crate::{context::GameContext, discord_rpc::{maybe_set_discord_presence, try_connect_to_local_discord}, scenes::{build_screen_state_machine, Scenes}, utilities::{ffi_logging::hook_raylib_logging, shaders::{
|
use crate::{
|
||||||
|
context::GameContext,
|
||||||
|
discord_rpc::{maybe_set_discord_presence, try_connect_to_local_discord},
|
||||||
|
scenes::{build_screen_state_machine, Scenes},
|
||||||
|
utilities::shaders::{
|
||||||
shader::ShaderWrapper,
|
shader::ShaderWrapper,
|
||||||
util::{dynamic_screen_texture::DynScreenTexture, render_texture::render_to_texture},
|
util::{dynamic_screen_texture::DynScreenTexture, render_texture::render_to_texture},
|
||||||
}}};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate thiserror;
|
extern crate thiserror;
|
||||||
@ -133,7 +138,7 @@ pub async fn game_begin(game_config: &GameConfig) -> Result<(), Box<dyn std::err
|
|||||||
let raylib_thread;
|
let raylib_thread;
|
||||||
{
|
{
|
||||||
// Set up FFI access to raylib
|
// Set up FFI access to raylib
|
||||||
hook_raylib_logging();
|
// hook_raylib_logging();
|
||||||
let (mut rl, thread) = raylib::init()
|
let (mut rl, thread) = raylib::init()
|
||||||
.size(
|
.size(
|
||||||
game_config.base_window_size.0,
|
game_config.base_window_size.0,
|
||||||
@ -143,6 +148,7 @@ pub async fn game_begin(game_config: &GameConfig) -> Result<(), Box<dyn std::err
|
|||||||
.vsync()
|
.vsync()
|
||||||
.msaa_4x()
|
.msaa_4x()
|
||||||
.resizable()
|
.resizable()
|
||||||
|
.replace_logger()
|
||||||
.build();
|
.build();
|
||||||
rl.set_exit_key(None);
|
rl.set_exit_key(None);
|
||||||
raylib_thread = thread;
|
raylib_thread = thread;
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
use std::{convert::TryInto, ffi::c_void};
|
|
||||||
|
|
||||||
use num_traits::FromPrimitive;
|
|
||||||
use printf::printf;
|
|
||||||
|
|
||||||
/// Direct mapping of Raylib's log levels
|
|
||||||
/// See: https://github.com/raysan5/raylib/blob/d875891a3c2621ab40733ca3569eca9e054a6506/parser/raylib_api.json#L985-L1026
|
|
||||||
#[derive(FromPrimitive)]
|
|
||||||
enum RaylibLogLevel {
|
|
||||||
All = 0,
|
|
||||||
Trace = 1,
|
|
||||||
Debug = 2,
|
|
||||||
Info = 3,
|
|
||||||
Warning = 4,
|
|
||||||
Error = 5,
|
|
||||||
Fatal = 6,
|
|
||||||
None = 7,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Callback that is called by the FFI code
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
#[no_mangle]
|
|
||||||
unsafe extern "C" fn raylib_log_callback(
|
|
||||||
level: i32,
|
|
||||||
message: *const i8,
|
|
||||||
args: *mut raylib::ffi::__va_list_tag,
|
|
||||||
) {
|
|
||||||
// Get the message as a string
|
|
||||||
let formatted_message = printf(message, args as *mut c_void);
|
|
||||||
|
|
||||||
// Handle the log level
|
|
||||||
match RaylibLogLevel::from_u32(level.try_into().unwrap()) {
|
|
||||||
Some(level) => match level {
|
|
||||||
RaylibLogLevel::Trace => tracing::trace!("{}", formatted_message),
|
|
||||||
RaylibLogLevel::Debug => tracing::debug!("{}", formatted_message),
|
|
||||||
RaylibLogLevel::Warning => tracing::warn!("{}", formatted_message),
|
|
||||||
RaylibLogLevel::Error => tracing::error!("{}", formatted_message),
|
|
||||||
RaylibLogLevel::Fatal => tracing::error!("{}", formatted_message),
|
|
||||||
_ => tracing::info!("{}", formatted_message),
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
println!("{:?}", formatted_message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Call this to replace raylib's logger with the rust logging system
|
|
||||||
pub fn hook_raylib_logging() {
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe {
|
|
||||||
raylib::ffi::SetTraceLogCallback(Some(raylib_log_callback));
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,4 +6,3 @@ pub mod shaders;
|
|||||||
pub mod non_ref_raylib;
|
pub mod non_ref_raylib;
|
||||||
pub mod render_layer;
|
pub mod render_layer;
|
||||||
pub mod game_version;
|
pub mod game_version;
|
||||||
pub mod ffi_logging;
|
|
||||||
|
@ -1,21 +1,15 @@
|
|||||||
use game::{game_begin, GameConfig, StaticGameData};
|
use game::{GameConfig, StaticGameData, game_begin};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Enable logging
|
// Enable logging
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt::init();
|
||||||
.compact()
|
|
||||||
.with_thread_names(true)
|
|
||||||
.with_ansi(true)
|
|
||||||
.with_max_level(tracing::Level::INFO)
|
|
||||||
.init();
|
|
||||||
|
|
||||||
// Load the general config for the game
|
// Load the general config for the game
|
||||||
// This happens here so we can properly track sentry events
|
// This happens here so we can properly track sentry events
|
||||||
let game_config = GameConfig::load(
|
let game_config = GameConfig::load(
|
||||||
StaticGameData::get("configs/application.json").expect("Failed to load application.json"),
|
StaticGameData::get("configs/application.json").expect("Failed to load application.json"),
|
||||||
)
|
).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Connect to sentry
|
// Connect to sentry
|
||||||
let _sentry_guard = sentry::init((
|
let _sentry_guard = sentry::init((
|
||||||
|
Reference in New Issue
Block a user