Skip to content

Instantly share code, notes, and snippets.

View nilpunch's full-sized avatar

Daniil Pankevich nilpunch

View GitHub Profile
@nilpunch
nilpunch / Query.cs
Created March 14, 2026 11:21
New iteration algo
public void ForEach<T1, T2, T3, T4, TAction>(ref TAction action)
where TAction : IEntityAction<T1, T2, T3, T4>
{
NoDataException.ThrowIfHasNoData<T1>(World, DataAccessContext.View);
NoDataException.ThrowIfHasNoData<T2>(World, DataAccessContext.View);
NoDataException.ThrowIfHasNoData<T3>(World, DataAccessContext.View);
NoDataException.ThrowIfHasNoData<T4>(World, DataAccessContext.View);
var dataSet1 = World.DataSet<T1>();
var dataSet2 = World.DataSet<T2>();
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Massive
{
/// <summary>
/// 12-byte.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
@nilpunch
nilpunch / BitSet.cs
Last active September 2, 2025 09:13
BitSet iteration
public class BitSet
{
public ulong[] Bits0 { get; private set; } = Array.Empty<ulong>();
public ulong[] Bits1 { get; private set; } = Array.Empty<ulong>();
public void Add(int id)
{
var id0 = id >> 6;
var id1 = id >> 12;
@nilpunch
nilpunch / PhysicsUtils.cs
Last active August 1, 2025 12:02
Unity physics utility to find closest point on any type of collider, including concave (non-convex) colliders.
using System.Runtime.InteropServices;
using UnityEngine;
using Object = UnityEngine.Object;
public static class PhysicsUtils
{
private static readonly Collider[] _colliders = new Collider[512];
private static SphereCollider _probeSphere;
@nilpunch
nilpunch / Radix.cs
Last active June 30, 2025 07:15
C# Radix
public static class ListExtensions
{
public static void RadixSort<T>(this List<T> list, Func<T, uint> orderBy)
{
RadixCountBytesSort(list, orderBy);
}
private static void RadixCountBytesSort<T>(List<T> list, Func<T, uint> orderOf)
{
var count = list.Count;
@nilpunch
nilpunch / Sampe.cs
Last active May 13, 2025 16:02
WIP auto allocator syntax.
using UnityEngine;
namespace Tetris
{
public struct Block
{
public Vector2Int Offset;
}
public struct Tetromino
using System;
using System.Collections.Generic;
using System.Reflection;
using Plugins.InterfaceObjectField.Runtime;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using Object = UnityEngine.Object;
[CustomPropertyDrawer(typeof(InterfaceFieldAttribute))]
@nilpunch
nilpunch / Angle.cs
Last active May 1, 2024 17:59
Angle and 2D Rotation for Unity
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
public readonly struct Angle : IEquatable<Angle>
{
private const float PIRad = Mathf.PI;
private const float TwoPIRad = PIRad * 2f;
private const float HalfPIRad = PIRad * 0.5f;
@nilpunch
nilpunch / BlurImage.shader
Last active April 25, 2025 16:47
Blur for UI elements. Compatible with Built in RP, HDRP, URP and SRP.
Shader "UI/BlurImage"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[Space(50)]
_BlurX ("X Blur", Range(0.0, 0.5)) = 0.001
_BlurY ("Y Blur", Range(0.0, 0.5)) = 0.001
@nilpunch
nilpunch / KdTree.cs
Last active May 31, 2022 09:41 — forked from ditzel/KdTree.cs
Somewhat refactored k-d tree.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public interface IKdTreePosition
{
Vector3 Position { get; }
}