Skip to content

Instantly share code, notes, and snippets.

@dmlary
dmlary / fzf-cscope.vim
Last active January 6, 2023 14:31
fzf-vim cscope integration
" Requires the fzf-vim plugin to work. Performs cscope queries against
" cscope.out, uses fzf-vim to display results and previews.
" specify multiple cscope databases to search.
" " short form, list of directories containing cscope.out
" let g:fzf_cscope_databases = [".", "~/kernels/2.6.12"]
"
" " long form database in separate directory from sources
" let g:fzf_cscope_databases = [
" [".", "build/cscope.out"],
@dmlary
dmlary / picking_raycast_multiple.rs
Last active May 23, 2023 02:52
`bevy_mod_picking` raycast backend with support for multiple raycasting sets
// This is a rough & dirty fork of `bevy_picking_raycast` that supports multiple raycast sets.
// This is needed when you have multiple cameras you want to raycast from at the same time.
// The key change is making the `Backend` generic for raycast sets. It's harder to work
// with as it requires an understanding of `bevy_mod_raycast`.
//
// Other changes: removed `Picking` component management; added enable/disable via config
//! A raycasting backend for `bevy_mod_picking` that uses `bevy_mod_raycast` for raycasting.
use bevy::{prelude::*, utils::HashMap, window::PrimaryWindow};
@dmlary
dmlary / scene_aabb.rs
Last active June 3, 2024 07:46
Bevy v0.10 draw Axis-Aligned Bounding-Boxes (AABB) around Scenes after they've been loaded
//! Load a GLB Scene, and draw an Axis-Aligned Bounding-Box around the entire
//! scene
//!
//! Works in Bevy v0.10
#![allow(clippy::type_complexity)]
use bevy::{
core_pipeline::tonemapping::Tonemapping, prelude::*, render::primitives::Aabb,
scene::SceneInstance, transform::TransformSystem::TransformPropagate,
};
@dmlary
dmlary / egui_tile_palette.rs
Created May 29, 2023 01:28
Bevy egui 3d tile palette demo
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use bevy::{
core_pipeline::tonemapping::Tonemapping, prelude::*, render::view::RenderLayers,
scene::SceneInstance,
};
use bevy_dolly::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin, EguiUserTextures};
use bevy_inspector_egui::quick::WorldInspectorPlugin;
@dmlary
dmlary / cscope.lua
Last active July 13, 2023 16:25
neovim cscope telescope integration
--[[
Navigate cscope in neovim using telescope with multiple databases
Setup:
local cscope = require('cscope')
-- look for cscope.out in the current working directory
cscope.add_database { path = "." }
-- add a second database and set the top-level path for files in that db
cscope.add_database {
path = "/project/altitude/src",
@dmlary
dmlary / stun_test.rs
Created July 21, 2023 00:16
bevy 0.10.1 stun race-condition resolution
//! Example workaround for ecs-based race-conditions when used in muds.
//! The key problem is two characters stunning each other in the same
//! frame, only one of them should end up stunned.
//!
//! This solution in bevy uses an exclusive system that runs without
//! world deferment.
#[allow(unused)]
use anyhow::{bail, Result};
use bevy::{log::LogPlugin, prelude::*};
@dmlary
dmlary / main.rs
Last active June 23, 2024 07:51
minimal example of adding a custom render pipeline in bevy 0.11
/// minimal example of adding a custom render pipeline in bevy 0.11.
///
/// When this example runs, you should only see a blue screen. There are no
/// vertex buffers, or anything else in this example. Effectively it is
/// shader-toy written in bevy.
///
/// This revision adds a post-processing node to the RenderGraph to
/// execute the shader. Thanks to @Jasmine on the bevy discord for
/// suggesting I take a second look at the bevy post-processing example
///
@dmlary
dmlary / widget_system.rs
Last active August 18, 2023 23:42
Bevy v0.10 SystemParam-based egui Widgets
/// implemention of SystemParam-based egui Widgets for bevy 0.10
/// adapted from: https://github.com/bevyengine/bevy/discussions/5522
///
/// Effectively widgets can access world components/resources similar
/// to systems.
#![allow(clippy::type_complexity)]
use bevy::ecs::system::{SystemParam, SystemState};
use bevy::prelude::*;
use bevy_egui::egui;
@dmlary
dmlary / render-duplicate.rs
Created December 24, 2023 16:57
bevy v0.12 demo of rendering a single entity at multiple locations
/// bevy v0.12 demo of rendering a single entity at multiple locations
///
/// Motivation:
/// I have a use-case in my game where I have a single entity (with various
/// components) that must be visible at two places on the screen at the same
/// time (non-euclidean grid shenanigans). I didn't want to duplicate a
/// subset of the entity's components then manage the duplicate's lifetime.
/// Through conversations in the bevy discord, the idea came up of making
/// modifications to the render pipeline to achive this.
///
@dmlary
dmlary / spawn_gltf_node.rs
Created December 29, 2023 01:58
bevy 0.12 system for spawning a `GltfNode` from `Handle<GltfNode>`
fn gltf_node_spawner(
mut commands: Commands,
node_handles: Query<(Entity, &Handle<GltfNode>), Added<Handle<GltfNode>>>,
assets_gltf_nodes: Res<Assets<GltfNode>>,
assets_gltf_mesh: Res<Assets<GltfMesh>>,
) {
for (parent, handle) in &node_handles {
let Some(node) = assets_gltf_nodes.get(handle) else {
warn!("GltfNode not found: entity {:?}, {:?}", parent, handle);
continue;