Skip to content

Instantly share code, notes, and snippets.

View graphitemaster's full-sized avatar
🎩
Building my dream game

Dale Weiler graphitemaster

🎩
Building my dream game
View GitHub Profile
@graphitemaster
graphitemaster / zlib_compress.c
Created August 27, 2011 06:27
ZLIB compression in 200 LOC
// ~zlib compression in 200 LOC quality allowed (5-8), where 5 is lowest, and 8 is heighest, the lower
// the quality the smaller the file. By graphitemaster, licensed unded public domain.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* fast lookup tables for length and distance */
static const unsigned short zlib_lengthc[] = {
0x003, 0x004, 0x005, 0x006, 0x007, 0x008, 0x009, 0x00A, 0x00B, 0x00D,
0x00F, 0x011, 0x013, 0x017, 0x01B, 0x01F, 0x023, 0x02B, 0x033, 0x03B,
/*
* Bit twiddling hacks: By Dale Weiler (a.k.a graphitemaster)
* all code is public domain.
*/
#include <limits.h>
#include <stdio.h>
/*
* Simple utility to convert integer to binary string: it's a pity
* C doesn't support a format specifier for printf. Or binary constants
/*
* GCC and GCC-like compilers set this flag when -std=c++0x is set
* we can use these to make this code use some C++11 features.
*/
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#define SASSERT(X,Y) static_assert(X,Y)
#define NULLPTR nullptr
#else
/*
* Primitive static assert implementation:
@graphitemaster
graphitemaster / def.c
Created May 14, 2012 20:12
Deferred Renderer - 350LOC
/*
* A simple deferred renderer using OpenGL, C90 and SDL, plugin and use
* with no issue at all. All code is public domain -- Dale Weiler 2012
* a.k.a graphitemaster
*/
#include <SDL.h>
#include <SDL/SDL_opengl.h>
typedef struct {
GLuint fbo;
GLuint diffuse_target, diffuse_texture;
#if FOO_H == 1
#error Cyclic include
#endif
#ifndef FOO_H
#define FOO_H 1
stuff;
#undef FOO_H
#define FOO_H 0
This file has been truncated, but you can view the full file.
DEBUG: [COM] starting ...
Mode: progs.src
src: defs.qc
src: subs.qc
src: fight.qc
src: ai.qc
src: combat.qc
src: items.qc
src: weapons.qc
src: world.qc
#include "gmrast.h"
#include <math.h> /* acos, fabs, sqrtf */
#include <string.h> /* memset, memcpy */
#include <stdlib.h> /* malloc, calloc, free */
/*
* TODO:
* Fix up the rasterizer to use GM_* functions below
* for memory managment.
*/
@graphitemaster
graphitemaster / Makefile
Created October 14, 2012 00:17
gmbootloader
CFLAGS = -nostdinc -nostdlib -ffreestanding -m32 -fno-pic
CC ?= gcc
DD ?= dd
OBJDUMP = objdump
OBJCOPY = objcopy
HEXDUMP = hexdump
boot: main.S boot.c
$(CC) $(CFLAGS) -c boot.c
$(CC) $(CFLAGS) -c main.S
#include <string.h>
#define BLOCK_ITEMS 16 /* largest alloc 262272 bytes */
/*
* This is a blockade allocator, a new idea in the world of allocators for small short
* lived objects. This allocator creates a table of BLOCK_ITEM chunks, which all contain
* pieces of memory that are allocated for N instances (by blockade_init(N)). Unlike a
* traditional block allocator we use integer log base 2 to map the byte-size to a linear
* sequence: e.g
* 8 bytes = 0
* 16 bytes = 1
static unsigned long x[624];
static int n;
void seed(unsigned long s) {
x[0] = s & 0xFFFFFFFFUL;
for (n=1;n<624;n++){x[n]=(1812433253UL*(x[n-1]^(x[n-1]>>30))+n);}n=0;
}
unsigned long rand() {
unsigned long y[2];
if (n==624) {
for (n = 0; n < 624 - 1; n++)