Skip to content

Instantly share code, notes, and snippets.

View Vercidium's full-sized avatar

Vercidium Vercidium

View GitHub Profile
@Vercidium
Vercidium / sectorsedge-windbg-log.txt
Created January 23, 2022 01:56
WinDbg log from a Sector's Edge crash dump (.NET 6)
Microsoft (R) Windows Debugger Version 10.0.22473.1005 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.
Loading Dump File [C:\Users\verc\Downloads\sectorsedge.exe.13044.dmp]
User Mini Dump File: Only registers, stack and portions of memory are available
************* Path validation summary **************
@Vercidium
Vercidium / precalculatedTrig.cs
Last active February 20, 2020 21:48
Performance benchmark for using Math.Sin(...) and Math.Cos(...) vs accessing values from a precalculated sine wave array.
ModelHelper.InitialiseTrigonometry();
Random rand = new Random();
int count = 524288;
float[] randoms = new float[count];
float[] result = new float[count];
int[] mathTimes = new int[100];
int[] arrayTimes = new int[100];
/* Changes made:
* Using chunkXCounter and chunkZCounter to check when we have moved into a new chunk,
* rather than (x % Constants.ChunkSize) * Constants.ChunkSize each loop. This removes all %, / and * operators
* Comparisons against 0 in loops where possible
* Using .Reset() on the block, rather than getting a reference and modifying index and health on two different lines
* Previous benchmark: 100 runs in 5315ms.
* New benchmark: 100 runs in 4755ms
* */
byte[] fileData = r.ReadBytes(bytesRemaining);
byte[] fileData = r.ReadBytes(bytesRemaining);
var b = 0;
for (int x = 0; x < Constants.MapSizeX; x++)
{
int chunkX = x / Constants.ChunkSize;
for (int z = 0; z < Constants.MapSizeZ; z++)
{
int chunkZ = z / Constants.ChunkSize;
@Vercidium
Vercidium / greedyvoxelmeshing
Last active May 4, 2024 09:03
Greedy Voxel Meshing ported to C#
// Code ported from https://0fps.net/2012/06/30/meshing-in-a-minecraft-game/
// Note this implementation does not support different block types or block normals
// The original author describes how to do this here: https://0fps.net/2012/07/07/meshing-minecraft-part-2/
const int CHUNK_SIZE = 32;
// These variables store the location of the chunk in the world, e.g. (0,0,0), (32,0,0), (64,0,0)
static Matrix4F identityF = Matrix4.Identity.ToFloat();
// This is a combination of a scale, rotate and translate matrix. Rather than calculating three different matrices and multiplying
// them together, we can save float multiplications and additions by using this function
public static Matrix4F ParticleMatrix(float s, float rX, float rZ, Vector3 d)
{
var sX = GetArrayedSinCheap(rX);
var sZ = GetArrayedSinCheap(rZ);
var cX = GetArrayedCosCheap(rX);
var cZ = GetArrayedCosCheap(rZ);
@Vercidium
Vercidium / multiple Layers
Last active May 4, 2019 02:38
Multiple Arm Layers
// Create multiple layers
for (int o = 0; o < layers; o++)
{
// Create the arms
for (int i = 0; i < 100000; i++)
{
Vector3 position = GetPoint();
position.Y -= heightMagnitude * Math.Sin(position.Magnitude * heightFrequency);
// Colour and store each point
@Vercidium
Vercidium / colourInterpolation.cs
Last active May 4, 2019 02:20
Colour Interpolation
Vector3 position = GetPoint();
position.Y -= heightMagnitude * Math.Sin(position.Magnitude * heightFrequency);
// Colour each point based on their global angle around the axis
Color blendedColour;
var angle = Math.Atan2(position.X, position.Z);
// c1, c2, c3 and c4 are random colours generated at the start of the program
// Blend the colours of adjacent quadrants together
if (angle < -Math.PI / 2)
@Vercidium
Vercidium / verticalVariance
Last active May 3, 2019 03:44
Vertical Variance
Vector3 position = GetPoint();
position.Y -= heightMagnitude * Math.Sin(position.Magnitude * heightFrequency);
@Vercidium
Vercidium / armBending
Last active May 6, 2019 04:29
Arm Bending
Vector3 GetPoint()
{
// Generate the point
...
// Calculate arm scaling
...
// Rotate the point around the galaxy proportional to its magnitude
v *= Matrix4.CreateRotationY(-v.Magnitude * rotationStrength);