Skip to content

Instantly share code, notes, and snippets.

@toyboot4e
toyboot4e / fps.rs
Created August 6, 2021 21:36
Simple FPS watcher
/// Simple FPS watchcer
#[derive(Debug, Clone, Default)]
pub struct Fps {
/// Average duration per frame in seconds
avg: f64,
/// Square of spike FPS in seconds
spike: f64,
}
impl Fps {
@toyboot4e
toyboot4e / cheat.rs
Last active August 11, 2021 15:32
Cheat the borrow checker
/*!
Cheat the borrow checker using raw pointer
*/
pub fn cheat<T>(x: &T) -> Cheat<T> {
unsafe { Cheat::new(x) }
}
/// Lifetime-free mutable reference to type `T`
///
@toyboot4e
toyboot4e / build.rs
Last active January 8, 2021 05:19
Generate asset path with build script
use std::{
env,
fmt::Write as _,
fs::{self, File},
io::prelude::*,
path::{Path, PathBuf},
};
use convert_case::{Case, Casing};
@toyboot4e
toyboot4e / fov.rs
Last active March 5, 2021 10:26
Field of view for orthogonal grid maps written in Rust
//! Field of view for orthogonal grid maps
// pub struct Vec2i { x: i32, y: i32 }
// impl Vec2i {
// pub fn new(x: i32, y: i32) -> Self { Self { x, y } }
// pub fn len_king(&self) -> u32 { std::cmp::max(self.x, self.y) }
// }
use crate::utils::grid2d::Vec2i;
/// Refreshes FoV data or maybe bundle of FoV and FoW