Skip to content

Instantly share code, notes, and snippets.

View RJ's full-sized avatar
💤

Richard Jones RJ

💤
View GitHub Profile
@RJ
RJ / edgegap regex.txt
Last active December 16, 2024 15:00
edgegap container image path regex bug
```
^(?:(?=[^:\\/]{4,253}) # Optional registry (non-capturing group)
(?!-) # Ensure no leading dash
[a-zA-Z0-9-]{1,63} # Allow alphanumeric and dashes (max 63 chars)
(?<!-) # Ensure no trailing dash
(?:\\.(?!-) # Allow dot-separated components, no dash after dot
[a-zA-Z0-9-]{1,63} # Same 63-char alphanumeric and dash rules
(?<!-))* # Zero or more of these subcomponents
(?::[0-9]{1,5})? # Optional port (e.g., :5000)
/)? # End of optional registry
@RJ
RJ / github-runner-build-wasm.yaml
Created December 1, 2024 14:42
Builds your wasm on a macos runner, which has more resources, then uses ubuntu-latest to dockerize it.
name: WASM build and nginxify
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version number in the format `v1.2.3`'
@RJ
RJ / bullet_plugin.rs
Last active November 23, 2024 11:14
spacepit bullet plugin, observer vs system ordering issue for PreSpawnedPlayerObject hashes
use crate::prelude::*;
use avian2d::prelude::*;
use bevy::prelude::*;
use lightyear::client::components::ComponentSyncMode;
use serde::{Deserialize, Serialize};
pub mod prelude {
pub const BULLET_SIZE: f32 = 1.5;
pub use super::Bullet;
pub use super::BulletBundle;
@RJ
RJ / player_commands.rs
Created November 21, 2024 13:22
bevy plugin managing mouse inputs etc
use std::ops::Mul;
/// Handles acting on player inputs. Moving and shooting.
use crate::prelude::*;
use avian2d::prelude::*;
use bevy::{ecs::query::QueryData, prelude::*};
use client::{is_in_rollback, Predicted};
use leafwing_input_manager::{Actionlike, InputControlKind};
use lightyear::client::input::leafwing::InputSystemSet;
use lightyear::{
@RJ
RJ / certgen.rs
Created October 14, 2024 08:40
WebTransport compatible self signed certificate generation in rust using openssl bindings
// Ended up not using this because i discovered `wtransport` lib has a SelfSigned builder which does it for me.
use openssl::asn1::Asn1Time;
use openssl::ec::{EcGroup, EcKey};
use openssl::hash::MessageDigest;
use openssl::nid::Nid;
use openssl::pkey::PKey;
use openssl::x509::extension::SubjectAlternativeName;
use openssl::x509::extension::{BasicConstraints, SubjectKeyIdentifier};
@RJ
RJ / bevy fn to return system.rs
Last active September 3, 2024 07:49
return a system from a function, enclosing something useful
/*
Sometimes you want to dump some component values in multiple different schedules
like when debugging network replication..
here's an example of a function you can use to enclose the schedule name you put it in:
```rust
app.add_systems(Update, dumper("Update"));
app.add_systems(Last, dumper("Last"));
```
@RJ
RJ / fixed_joint_2d.rs
Created September 2, 2024 12:29
Modified fixed_joint_2d example with rotation axes note
use avian2d::{math::*, prelude::*};
use bevy::{ecs::component::StorageType, prelude::*};
use examples_common_2d::ExampleCommonPlugin;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
ExampleCommonPlugin,
PhysicsPlugins::default(),
@RJ
RJ / renet_lag.markdown
Last active September 11, 2023 16:27
Testing multiple renet clients with varying simulated latency levels

Testing with varying levels of lag per Renet client

I want to run multiple clients locally, each with different amounts of lag.

Achieved by specifying the client's local port number when binding socket, and setting up a pf rule based on local port. (all connecting to renet's default port of 5000)

This is for Mac OS, but something similar would be possible on linux.

#!/bin/bash -ex
@RJ
RJ / main.rs
Created August 17, 2023 09:03
Example of passing a system set label to a bevy plugin so the plugin can configure sets as needed, using BoxedSystemSet
use bevy::{prelude::*, ecs::schedule::SystemSetConfig};
use bevy::ecs::schedule::BoxedSystemSet;
//// game:
#[derive(SystemSet, Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum MySets {
GameLogic,
}
#[derive(Resource)]
@RJ
RJ / Cargo.toml
Last active July 1, 2021 11:48
bevy span lifetime
[package]
name = "bevylog"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.5"