Skip to content

Instantly share code, notes, and snippets.

View thebirk's full-sized avatar

Aleksander Birkeland thebirk

View GitHub Profile
@thebirk
thebirk / annotations.go
Last active February 7, 2019 16:44
Odin annotations proposal
// This example has some faults, the most important one is how are you gonna know what data
// the annotation actually annotates. The best way would probably be to tag it with
// {entity_id: typeid, entity_ptr: rawptr}, this would allow you to switch on the type
// and cast the ptr. That way you can ensure the annotation was added to the correct type
// and not some random entity
package main
// Proposed change for existing compiler attributes
Go src: https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-go-3.html
Odin src: https://gist.github.com/thebirk/e02df1b94ef07fb62b50d64ba2f5328e
$ go build
$ timemem gotest.exe 50000000
-0.169075164
-0.169059907
Exit code : 0
Elapsed time : 3.76
Kernel time : 0.00 (0.0%)
package main
import "core:fmt";
import "core:math";
FloatType :: f64;
Vec3 :: distinct [3]FloatType;
Body :: struct {
pos: Vec3,
@thebirk
thebirk / huffman.go
Last active November 9, 2018 08:08
Basic huffman tree in Odin
package huffman
import "core:fmt"
import "core:strings"
import "core:mem"
import "core:math"
using import "arraylist"
HuffmanNode :: struct {
freq: int,
@thebirk
thebirk / arraylist.go
Created November 9, 2018 07:51
Polymorphic ArrayList - Odin
package arraylist
import "core:mem"
ArrayList :: struct(T: typeid) {
data: []T,
size: int,
allocator: mem.Allocator,
}
package bed
using import "core:c"
import "core:os"
//foreign import ftlib "freetype271.lib";
when os.OS == "windows" do foreign import ftlib "freetype.lib";
else when os.OS == "linux" do foreign import ftlib "system:freetype";
else {
#assert(false);
package bed
using import "core:c"
import "core:os"
//foreign import ftlib "freetype271.lib";
when os.OS == "windows" do foreign import ftlib "freetype271.lib";
else {
#assert(false);
}
#include <SDL2/SDL_image.h>
SDL_Texture *fontTexture = 0;
const char *layout =
"ABCDEFGHIJKLMNOP"
"QRSTUVWXYZ!?. "
"1234567890"
;
void initText() {
@thebirk
thebirk / math.go
Last active August 10, 2018 20:29
/*
Most of the code here will be taken from HandmadeMath,
which is covered under the CC0 1.0 Universal license,
see LICENSE for more information
*/
package math
import omath "core:math"
PI :: omath.PI;
@thebirk
thebirk / html.odin
Created August 2, 2018 14:41
Odin issue #208
/*
Copyright (C) - Aleksander B. Birkeland 2018
Very basic HTML generator
TODO(Some way to generate xml instead of html)
Closes all tags including empty ones
*/