Skip to content

Instantly share code, notes, and snippets.

View martindevans's full-sized avatar

Martin Evans martindevans

View GitHub Profile
public static void WriteVariableUint64(this BinaryWriter writer, UInt64 value)
{
for (int i = 0; i < sizeof(UInt64); i++)
{
byte writeByte = (byte)(value & 127);
value >>= 7;
if (value != 0)
writeByte |= 128;
void write(entity e, BinaryWriter w)
{
w.write(e.Template.Id);
foreach (Component c in e.Components) //e.Components is ordered in a specific way when it's constructed
{
Assert(e.Template.Contains(c));
c.Write(w); //Component writes out the data it needs
}
}
--Tags:[ui, message box]
--Author:Martin Evans
function Initialize(owner, initialisationData)
Scene.LoadService("UI.UiService");
local chatPipe = Pipes.GetPipe("General Chat", "String", true, true);
Ui.AddCallback("SendChatMessage", function(msg)
chatPipe.Send(msg);
//Use an object as a set
var set = {}
//Create an object, give it some property
var item = {}
item.Foo = function() {};
set[item] = item;
for (key in set}
{
for (stuff in things)
{
var foo = stuff.thing;
stuff.bar = function()
{
foo.bash(); //Probably not what you wanted!
};
//because all life problems can be solved with a little less readability
function()
int qlpShiftDivisor = 1 << qlpShift;
for (int i = order; i < sample.Length; i++)
{
int sum = 0;
for (int j = 0; j < order; j++)
sum += predictorCoefficients[j] * sample[i - j - 1];
sum /= qlpShiftDivisor;
sum += residuals[i - order];
sample[i] = sum;
}
@martindevans
martindevans / entry.c
Created November 30, 2012 23:01
C code
// File: entry.c
// Version: 1.0.0
// Author: Martin
//
int* screen = 0x8000;
int main()
{
print("Hello");
function try(f, catch_f, ...)
local status, exception = pcall(f, unpack(arg))
if not status then
catch_f(exception)
end
end
function foo(a, b)
return a < b;
end
switch (thingy):
case typeof(foo):
stuff();
break;
case typeof(bar):
stuff2();
break;
var newRoutes = Stars
.SelectMany(sink => Stars
.Where(s => Distance(s, sink) < DISTANCE_THRESHOLD) //Eliminate stars too far away
.Where(s => s.Desirability < sink.Desirability) //Ignore routes along a negative profitability gradient
.Where(s => !IsThereARouteAlreadyBetween(sink, s)) //Don't reconsider routes which already exist
.Where(s => RandomFloat(0, 1) > SomeValue) //Arbitrarily eliminate half the routes
.Select(source => new { Source = source, Sink = sink })
)
.Select(route => new { route.Source, route.Sink, Path = Pathfind(route.Source, route.Sink) } //We can precompute paths from every star to every other star, making this quite cheap
.Select(route => new { DeltaDesirability = route.Sink.Desirability - route.Source.Desirability, route.Source, route.Sink. route.Path })