Проектная работа - WIP

This commit is contained in:
5 changed files with 304 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
/// Инициализация логирования
pub fn define_log_layer() -> Option<bevy::log::BoxedFmtLayer> {
use std::fs::File;
use tracing::Level;
use tracing_subscriber::{Layer, filter::Targets, fmt::layer};
let targets = Targets::new()
.with_target("bevy_asset", Level::INFO)
.with_target("bevy_app", Level::INFO)
.with_target("bevy_diagnostic", Level::WARN)
.with_target("bevy_render", Level::INFO)
.with_target("bevy_shader", Level::INFO)
.with_target("bevy_time", Level::INFO)
.with_target("bevy_winit", Level::INFO)
.with_target("gilrs", Level::INFO)
.with_target("naga", Level::INFO)
.with_target("wgpu_core", Level::INFO)
.with_target("wgpu_hal", Level::WARN)
.with_target("offset_allocator", Level::INFO)
.with_default(Level::TRACE);
let stdout = layer()
.compact()
.with_thread_names(true)
.with_file(false)
.with_line_number(false)
.with_filter(targets.clone())
.boxed();
let file = match File::options()
.write(true)
.create(true)
.append(true)
.open("snake-game.log")
{
Ok(file) => file,
Err(e) => {
eprintln!("No access to log file: {:?}", e);
return Some(stdout);
}
};
let log_file = layer()
.compact()
.with_ansi(false)
.with_thread_names(true)
.with_file(false)
.with_line_number(false)
.with_writer(file)
.with_filter(targets.clone())
.boxed();
Some(Box::new(vec![stdout, log_file]))
}
+28 -1
View File
@@ -1,3 +1,30 @@
use bevy::ecs::system::command::*;
use bevy::math::bounding::*;
use bevy::prelude::*;
fn main() {
println!("Hello, world!");
App::new()
.add_plugins(
DefaultPlugins
.build()
.set(bevy::log::LogPlugin {
fmt_layer: |_| snake_game::define_log_layer(),
..Default::default()
})
.set(TaskPoolPlugin {
task_pool_options: TaskPoolOptions::with_num_threads(1),
}),
)
.insert_resource(ClearColor(Color::srgb(0.8, 0.8, 1.0)))
.add_systems(Startup, setup)
// config
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2d);
}