Skip to content

Instantly share code, notes, and snippets.

View gamemachine's full-sized avatar

Chris Ochs gamemachine

View GitHub Profile
pub struct Broadcast<T: Clone> {
senders: ArrayQueue<Vec<crossbeam::channel::Sender<T>>>,
pending_senders: ArrayQueue<crossbeam::channel::Sender<T>>,
pending_signal: Arc<AtomicBool>
}
impl<T: Clone> Broadcast<T> {
pub fn new() -> Arc<Self> {
let senders: ArrayQueue<Vec<crossbeam::channel::Sender<T>>> = ArrayQueue::new(1);
use glam::DVec2;
use rustc_hash::{FxHashMap};
#[derive(Clone, Copy, Debug)]
pub struct SpatialHash {
cell_size: u32,
conv_factor: f32,
use std::num::Wrapping;
use bincode::{Encode, Decode};
// Time is monotonic time (OS ticks) not clock time. The difference is precision vs accuracy.
// clock time can have huge variances, be different by over 100ms even when queried within a few ms of each other. Accurate but not precise.
// OS ticks are very precise over short intervals. But can drift very quickly over longer periods.
// We consume snapshots in sequence order, possibly skipping missing sequences.
// The interpolation state time represents our progression through the server timeline. Our server timeline is based on received snapshots. We advance through this timeline using local delta time.
using Unity.Collections;
using UnityEngine;
[ExecuteAlways]
public class TempAllocTest : MonoBehaviour
{
private NativeHashMap<int, int> Map;
private void OnEnable()
using ClientServer.Shared;
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Physics;
using UnityEngine;
namespace CombatServer
@gamemachine
gamemachine / TerrainMod.cs
Last active December 12, 2021 20:19
TerrainMod
using GameCommon.Models;
using ProtoBuf;
using System;
using System.Collections.Generic;
using Unity.Mathematics;
namespace GameCommon.Features.Land
{
[Serializable]
[ProtoContract]
namespace ClientServerShared
{
public class BinaryAsset
{
public static BinaryAssetFolder AssetFolder(string path1, string path2 = null)
{
return new BinaryAssetFolder(FolderType.Asset, path1, path2);
}
public static BinaryAssetFolder PersistentFolder(string path1, string path2 = null)
public struct ProjectedBody
{
public const float DampingDefault = 0.01f;
public const float TimeStep = 1f / 60f;
public static readonly float3 Gravity = new float3(0f, -9.81f, 0f);
public float3 StartPosition;
public float Damping;
public float3 Velocity;
public float3 Position;
@gamemachine
gamemachine / SpatialHash.cs
Created May 29, 2021 20:10
Spatial Hash
using Unity.Mathematics;
namespace GameCommon.Spatial
{
public struct SpatialHash
{
public const int Goffset = 10000;
public const int Max = 20480;
public int CellSize;
namespace UnityEngine.Rendering
{
public class VolumeInstanceHelper : MonoBehaviour
{
[HideInInspector]
public Volume Volume;
private void OnValidate()
{
if (Volume == null)