Skip to content

Instantly share code, notes, and snippets.

View StagPoint's full-sized avatar

StagPoint Software StagPoint

  • StagPoint Software
  • Seattle, WA
View GitHub Profile
@StagPoint
StagPoint / ObjectPool.cs
Created April 2, 2017 14:21
Bare-bones generic object pooling. Object pools can improve application performance and memory footprint in many gamedev situations. When a client program requests a new object, the object pool first attempts to provide one that has already been created and returned to the pool. If none is available, only then is a new instance created.
// Copyright (c) 2017 StagPoint Software
namespace StagPoint.ObjectPooling
{
using System;
using System.Collections.Generic;
public class ObjectPool<T> where T : class
{
#region Static variables
@StagPoint
StagPoint / ListExtensions.cs
Created March 29, 2017 16:03
ListExtensions - Defines a set of extension methods to add commonly-used operations to every List instance.
// Copyright (c) 2017 StagPoint Software
namespace StagPoint.Collections
{
using System;
using System.Collections.Generic;
/// <summary>
/// Defines a set of extension methods to add commonly-used operations to every List instance.
/// </summary>
@StagPoint
StagPoint / PooledArray.CS
Created March 8, 2017 20:16
Implements an Array-like interface for paged data that is object pool friendly. The internal data is stored in small "pages", each of which are obtained from an object pool and later returned to the object pool when finished. This allows the PooledArray class to obtain as much space as needed on demand from the object pool rather than have to de…
// Copyright (c) 2017 StagPoint Software
namespace StagPoint.Collections
{
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Implements an Array-like interface for paged data that is object pool friendly.
@StagPoint
StagPoint / BinaryHeap.CS
Last active September 11, 2018 10:14
Basic Binary Min Heap implementation in C# that can be used to process items from lowest cost to highest cost, such as in A* pathfinding.
// Copyright (c) 2017 StagPoint Software
namespace StagPoint.Collections
{
using System;
/// <summary>
/// Implements a basic Binary Min Heap that can be used for A* pathfinding. Items are removed from
/// the list in order from lowest to highest cost
/// </summary>
@StagPoint
StagPoint / PackedIntArray.cs
Last active September 11, 2018 10:14
Packed Integer Array (C#) - When the range of values is known ahead of time, and that range of values can be expressed in fewer bits than a full int, this class allows you to store the elements in a smaller amount of memory by packing individual elements together into fewer array elements.
// Copyright (c) 2017 StagPoint Software
namespace StagPoint.Collections
{
using System;
using System.Threading;
public class PackedIntArray
{
#region Private instance variables
@StagPoint
StagPoint / StopPlayingOnRecompile.cs
Created June 7, 2016 16:53
Stop Play Mode in the Unity Editor when recompiling the code
using UnityEditor;
[InitializeOnLoad]
public class StopPlayingOnRecompile
{
static StopPlayingOnRecompile()
{
EditorApplication.update = () =>
{
if( EditorApplication.isCompiling )
@StagPoint
StagPoint / DisableXMLWarningsUnity.cs
Created September 27, 2018 16:10
Use "#pragma warning disable 1591" to suppress "Missing XML comment for publicly visible type or member" warnings in Visual Studio when using Unity
// Disable all XML Comment warnings in this file, because Unity won't allow us to turn this bullshit off and keeps overwriting our settings //
#pragma warning disable 1591
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Use this for initialization
@StagPoint
StagPoint / DustyNebula.shader
Created May 7, 2020 00:09
Unity Port of "Dusty Nebula 4" by Duke ( https://www.shadertoy.com/view/MsVXWW )
// "Dusty nebula 4" by Duke
// https://www.shadertoy.com/view/MsVXWW
//-------------------------------------------------------------------------------------
// Based on "Dusty nebula 3" (https://www.shadertoy.com/view/lsVSRW)
// and "Protoplanetary disk" (https://www.shadertoy.com/view/MdtGRl)
// otaviogood's "Alien Beacon" (https://www.shadertoy.com/view/ld2SzK)
// and Shane's "Cheap Cloud Flythrough" (https://www.shadertoy.com/view/Xsc3R4) shaders
// Some ideas came from other shaders from this wonderful site
// Press 1-2-3 to zoom in and zoom out.
// License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
@StagPoint
StagPoint / FloatConversion.cs
Last active May 19, 2021 17:49
Convert between floating point and integral types in C# / Unity
// Copyright (c) 2016 StagPoint Software
// NOTE: C#-style unions (structs using FieldOffset to cause multiple fields to 'overlap' in memory) may not be allowed on
// some IL2CPP platforms? If you get a compile error related to using FieldOffset on your target platform, comment the
// following #define to force this code to use another method.
//
// The UnityEngine.Networking code on BitBucket uses (#if !INCLUDE_IL2CPP) to control whether to use unions, but that code
// may be out of date (Unity has so far failed to respond), but testing confirms that this method does work on at least one
// of the IL2CPP target platforms, so we've chosen a more explicit #define instead.
#define USE_UNION_FOR_CONVERSION
@StagPoint
StagPoint / SimplePathSmoother.cs
Last active June 17, 2022 10:59
Implements a simplistic 3D curve smoother for Unity. Depending on the intended use case, best results might be achieved by preprocessing the curve to have equally-spaced points, or using the Ramer-Douglas-Peucker algorithm to remove unnecessary points. It wasn't needed for my use case, so I didn't include that code here. YMMV.
namespace StagPoint.Math
{
using Unity.Collections;
using Unity.Mathematics;
/// <summary>
/// Implements a simplistic 3D curve smoother
/// </summary>
public static class CurveSmoother
{