Skip to content

Instantly share code, notes, and snippets.

@jsimmons
jsimmons / rast.cpp
Last active December 23, 2015 16:09
A nasty little rasteriser that does nothing interesting!
#include<stdio.h> // ./rast > test.ppm
#include<stdlib.h> // fgiesen.wordpress.com/2013/02/17/optimizing-sw-occlusion-culling-index/
#include<string.h>
#define W 800
#define H 600
#define X(a,b) (a)>(b)?(a):(b)
#define X3(a,b,c) X(X(a,b),(c))
#define N(a,b) (a)<(b)?(a):(b)
#define N3(a,b,c) N(N(a,b),(c))
typedef float f;typedef int i;char b[W*H]={};struct F{f x,y,z;};struct I
@jsimmons
jsimmons / example_marks.c
Created May 17, 2013 16:53
Performance monitor stuffs. The NULL and 0 parameters at the end of record are a pointer to and length of a block of data to be recorded alongside the event. The string name in the context description has support for printf style sequences to describe how said data should be interpreted by the viewer. Or something.
#include "perf_monster.h"
#include "example.h"
enum example_events
{
MARK_A,
MARK_B,
MARK_C,
MARK_D
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#ifndef M_PI
@jsimmons
jsimmons / tn_block_types.h
Created April 17, 2013 07:09
Block Types
enum tn_block_type
{
// This block is full of nothing!
TN_BLOCK_EMPTY,
// This block is full of its material. Chockers even!
TN_BLOCK_SOLID,
// Only the floor part (lowest 10th) filled with material. Walkable surface.
TN_BLOCK_FLOOR,
@jsimmons
jsimmons / jsb_map.h
Last active April 5, 2018 17:22
Quicky hash map in C
// We don't block multiple includes of this file since each inclusion should
// be for a different type. Be careful.
//
// A map using hopscotch hashing[1], an open-addressing scheme for resolving
// hash collisions.
//
// [1] Herlihy, Maurice and Shavit, Nir and Tzafrir, Moran (2008).
// "Hopscotch Hashing".
// DISC '08: Proceedings of the 22nd international symposium on
@jsimmons
jsimmons / indigo.js
Created March 30, 2013 04:25
Why you so slow JS???
var Interval = function(lower, upper) {
this.lower = lower;
this.upper = upper;
}
function interval_add(a, b) {
return new Interval(a.lower + b.lower, a.upper + b.upper);
}
@jsimmons
jsimmons / lets_play_wine
Created February 6, 2013 10:01
I ran thorough some games to see how wine goes for playing games on Linux.
SYSTEM SPECS
============
i7 2600k
Radeon HD 7970 GHz Edition
8GB DDR3
Plenty fast enough to run all these games smoothly on their highest settings in windows.
linux 3.7.5
@jsimmons
jsimmons / sem_futex.c
Created September 2, 2012 01:54
Wait shall I do with you.
// Playing around with what's necessary to implement a semaphore on top of Linux
// futexes.
static inline int my_sem_wait(struct semaphore *sem)
{
int new = __sync_sub_and_fetch(&sem->value, 1);
if(new < 0)
{
// This incorrectly handles the failure case where value is no longer
// new when the call executes. Not sure how to fix.
// If the new value is >= 0 then we've missed a wakeup
@jsimmons
jsimmons / sgl_example.c
Created July 28, 2012 07:56
SGL Example Code
// None of these include GL.h or anything like them. This is left to the user
// since there are myriad options. Also makes auto-generating LuaJIT FFI
// bindings roughly 9000 times easier.
#include <sgl/sgl.h>
#include <sgl/window.h>
#include <sgl/event.h>
// Windows, GL Contexts and Event handling is all the features we will ever
// have. Not going to add threading, image loading, timing or any other
// fluff like that. I'd like to ditch input even, but that's a bit tricky
@jsimmons
jsimmons / mpmc.c
Created July 9, 2012 02:58
Multiple Producer Multiple Consumer with two mutexes on FIFO
#include <pthread.h>
#include <stdio.h>
#define PRODUCER_COUNT 4
#define CONSUMER_COUNT 4
#define THREAD_COUNT (PRODUCER_COUNT + CONSUMER_COUNT)
#define WORK_ITERS 10000
#define WORK_COUNT 10000
#define QUEUE_SIZE 64