Skip to content

Instantly share code, notes, and snippets.

#[allow(unused_imports)]
use tracing::{info,warn,debug,error};
use std::{io, fs};
use std::path::Path;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter };
/// Sets up logging to both stdout and files
pub fn setup<P: AsRef<Path> + Clone>(crate_name: &str, dir: P) -> WorkerGuard {
use bevy::prelude::*;
use bevy::reflect::{GetTypeRegistration, ReflectMut, Typed, TypeInfo};
fn main() {
let mut app = App::new();
app
.add_plugins(MinimalPlugins)
.register_type_data::<String, ReflectFoo>()
.register_type_data::<usize, ReflectFoo>()
.register_type_data::<bool, ReflectFoo>()
@thebluefish
thebluefish / index.html
Created March 20, 2024 19:53
bevy WASM MVCE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>BEVY</title>
<link data-trunk rel="copy-dir" href="assets" />
<style>
body, html {
height: 100%;
}
use bevy::app::prelude::*;
use dyn_clone::DynClone;
pub trait AppExt {
fn add_all_plugins(&mut self);
}
impl AppExt for App {
fn add_all_plugins(&mut self) {
for plugin in inventory::iter::<AutoPlugin> {
@thebluefish
thebluefish / Cargo.toml
Last active February 24, 2024 00:26
Example for setting up a minimal logger to both file and stdout with tracing
[features]
default = ["tracy"]
tracy = []
[dependencies]
tracing = "0.1"
tracing-appender = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-tracy = "0.11.0"
use std::fs::File;
use std::io::{BufWriter, Read};
use walkdir::WalkDir;
use foo::Foo;
/// Converts postcard `.post` files to bincode `.bin` files assuming they represent `Foo` data
fn main() -> anyhow::Result<()> {
let root = std::env::current_dir()?.join("data");
for entry in WalkDir::new(&root).sort_by_file_name().into_iter().filter_map(|e| e.ok()) {
let path = entry.into_path();
use bevy::prelude::*;
fn main() {
divan::main();
}
#[divan::bench]
fn reflect() {
let mut input: Box<dyn MovementField> = Box::new(PlayerInput::default());
for n in 1..=1000 {
use bevy::app::AppExit;
use bevy::prelude::*;
use bevy::window::WindowCloseRequested;
fn main() {
App::new()
.init_state::<ExitState>()
.add_plugins(DefaultPlugins.set(WindowPlugin {
close_when_requested: false,
..default()
use bevy::prelude::*;
use std::collections::HashSet;
/// Example demonstrating despawning all entities that were spawned during a specific state
fn main() {
let mut app = App::new();
app
.add_state::<AppState>()
.insert_resource(EntityRecord(HashSet::new()))
use bevy::prelude::*;
use bevy::reflect::{ReflectFromPtr, ReflectMut};
/// Example demonstrating how to print and mutate the resources of a world using reflection
fn main() {
App::new()
.init_resource::<AppTypeRegistry>()
.register_type::<Foo>()
.register_type::<Bar>()
.insert_resource(Foo::A)