This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MMFNativeArray<T> where T : struct | |
{ | |
MemoryMappedFile mmf; | |
MemoryMappedViewAccessor accessor; | |
public NativeArray<T> native; | |
public MMFNativeArray(string path, FileMode mode, string mapName, int bytes) | |
{ | |
unsafe | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example usage: | |
shader.Dispatch("Advect", texWidth, texHeight, texDepth, | |
"_texture", texture, | |
"_separationPlane", Vector3.Scale(separationPlane.position, tscale), | |
"_advectFall", advectN == 0, | |
"_advectCapsuleCenter", Vector3.Scale(playerCapsule.transform.TransformPoint(playerCapsule.center), tscale)); | |
//Looks like a mess but is actually performant and is zero allocations: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//input RenderTexture 'rt3D' | |
Texture3D output = new Texture3D(width, height, depth, rt3D.graphicsFormat, TextureCreationFlags.None); | |
//assuming rt3D format to be 8 bits | |
var a = new NativeArray<byte>(width * height * depth, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); | |
AsyncGPUReadback.RequestIntoNativeArray(ref a, rt3D, 0, (_) => | |
{ | |
output.SetPixelData(a, 0); | |
output.Apply(updateMipmaps: false, makeNoLongerReadable: true); | |
AssetDatabase.CreateAsset(output, "Assets/3dtex.asset"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//will throw like "[0], [1], [0], [1], [2] [0..1]" | |
public sealed class LastNQueue<T> : Queue<T> | |
{ | |
public int HoldLastN { get; } | |
public LastNQueue(int holdLastN) | |
{ | |
HoldLastN = holdLastN; | |
} | |
/// <summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.Linq; | |
using System; | |
// TODO / WARNING: This script has some jenky behavior that needs ironing out. | |
// You probably want to use somebody else's back-button-in-unity implementation. | |
// TRY HERE: https://forum.unity.com/threads/feature-request-back-button-in-the-editor.653332/#post-4457944 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Diagnostics; | |
using UnityEditor; | |
using UnityEditor.Compilation; | |
using Debug = UnityEngine.Debug; | |
[InitializeOnLoad] | |
internal static class CompilationTimeTracker | |
{ | |
private static readonly Dictionary<string, Stopwatch> Dictionary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void p(string s, uint n) | |
{ | |
string ns = Convert.ToString(n, 2).PadLeft(32, '0'); | |
var list = Enumerable.Range(0, ns.Length / 8).Select(i => ns.Substring(i * 8, 8)); | |
var nsf = string.Join("_", list); | |
print(s + " ; " + nsf); | |
} | |
p("(1 << (32-7))", (1 << (32 - 7))); | |
p("((1 << (32-7)) - 1)", ((1 << (32 - 7)) - 1)); | |
p("((1 << (32 - 7)) - 1) >> (32 - 7) - 1 << (32 - 7) - 1", ((1 << (32 - 7)) - 1) >> (32 - 7) - 1 << (32 - 7) - 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
voxel temp; | |
vox.sunlight = id.y == resolution.y - 1 ? 15 : 0; | |
vox.torchlight = 0.; | |
//pull 6 neighbours and -1 | |
if (id.y < resolution.y - 1.) | |
{ | |
temp = getVoxel(id + int3(0,1,0)); | |
vox.sunlight = max(vox.sunlight, temp.sunlight); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SavePartMM(int offset = 0, int partSize = fullWidth * fullHeight * fullDepth, int chunkSizeDiv = 1024) | |
{ | |
//crashes if empty save file for some reason, too unreliable to use | |
var mmf = MemoryMappedFile.CreateFromFile(Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer ? "/Users/user/Downloads/test.bytes" : "C:\\test.bytes", FileMode.OpenOrCreate, "apoca_save"); | |
int chunkSize = fullWidth * fullHeight * fullDepth / chunkSizeDiv; //2 4 8 16 32 64 128 256 512 [1024] 2048 | |
//const int chunkSize = /*536_752_128*//*67_094_016*//*8_323_200*//*4_193_376*//*2_096_688*/520_200/*262_086*/; | |
saveLock = true; | |
var stopwatch = new Stopwatch(); stopwatch.Start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ContextMenuItem("Yo", "Yo")] | |
public Texture2D tex; | |
public void Yo() | |
{ | |
Texture2D DeCompress(Texture2D source) | |
{ | |
RenderTexture renderTex = RenderTexture.GetTemporary( | |
source.width, | |
source.height, | |
0, |