Skip to content

Instantly share code, notes, and snippets.

Forever working on Smile

seanofw seanofw

Forever working on Smile
View GitHub Profile
View HighPrecisionSleep.cs
using System;
using System.Runtime.InteropServices;
public class HighPrecisionSleep : IDisposable
private IntPtr _waitableTimerHandle;
public HighPrecisionSleep()
_waitableTimerHandle = Win32.CreateWaitableTimer(IntPtr.Zero, true, null);
View TimedGameWindow.cs
using System;
using System.Runtime.InteropServices;
using System.Threading;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
// Define this if you're running on Microsoft Windows, which supports
// high-precision sleep timers. Enabling this can result in better CPU usage
// and power usage if your program doesn't need the CPU fully in every frame.
View rand.cs
private static volatile int RandomSeed = 1;
private static int FastRand()
int oldSeed = RandomSeed;
int newSeed = unchecked(oldSeed * 1103515245 + 12345);
if (Interlocked.CompareExchange(ref RandomSeed, newSeed, oldSeed) != oldSeed)
goto retry;