Skip to content

Instantly share code, notes, and snippets.

@DanielGibson
DanielGibson / imgLoadBench.c
Last active August 29, 2015 14:17
Crappy benchmark for stb_image, lodepng, libjpeg and libpng
// The Results: http://wp.me/pEPJ4-4S
// you can define USE_LIBPNG to decode with libpng XOR USE_LODEPNG to decode with lodepng
// XOR USE_LIBJPEG to decode with libjpeg or libjpeg-turbo XOR nothing to use stb_image.
// you'll have to provide the corresponding headers and (for libjpeg and libpng) libs to link against
// for lodepng also compile lodepng.c into the binary
// ex: gcc -O4 -DUSE_LODEPNG imgLoadBench.c lodepng.c -o imgLoadBench_lodepng_gcc_O4
// or: gcc -O0 -DUSE_LIBPNG imgLoadBench.c -o imgLoadBench_libpng_gcc_O0 -lpng
// or: gcc -O2 -DUSE_LIBJPEG imgLoadBench.c -o imgLoadBench_libjpeg_gcc_O2 -ljpeg
// or: clang -O3 imgLoadBench.c -o imgLoadBench_stb_clang_O3
@DanielGibson
DanielGibson / FrameAlloc.hpp
Last active August 29, 2015 14:22
Simple C++ Allocator that doesn't reuse memory until it's Reset()
/*
* A simple allocator that uses a fixed sized memory buffer and doesn't reuse
* memory until it's Reset()
* It's untested and not thread-safe (achieving that shouldn't be hard, though,
* see comment at AllocBlock())
*
*
* (C) 2015 Daniel Gibson
*
* License:
@DanielGibson
DanielGibson / gist:4526283
Created January 13, 2013 21:25
try to fix longnecks
diff --git a/neo/d3xp/anim/Anim_Blend.cpp b/neo/d3xp/anim/Anim_Blend.cpp
index cacf5f1..4215336 100644
--- a/neo/d3xp/anim/Anim_Blend.cpp
+++ b/neo/d3xp/anim/Anim_Blend.cpp
@@ -5490,19 +5490,19 @@ bool idAnimator::GetJointLocalTransform( jointHandle_t jointHandle, int currentT
// FIXME: overkill
CreateFrame( currentTime, false );
- if( jointHandle > 0 )
- {
@DanielGibson
DanielGibson / gist:5595590
Last active December 17, 2015 10:29
idGameLocal::CalcFov from dhewm3/neo/game/Game_local.cpp - modified with additional assertions and debug-prints and some comments on how [https://github.com/dhewm/dhewm3/issues/70] shouldn't happen (my guess is that renderSystem->GetScreenWidth() and/or renderSystem->GetScreenHeight() return 0 or a negative value)
void idGameLocal::CalcFov( float base_fov, float &fov_x, float &fov_y ) const {
float x;
float y;
float ratio_x;
float ratio_y;
assert(base_fov > 0);
// first, calculate the vertical fov based on a 640x480 view
// XXX: will be positive because tan() is positive if the given value is positive as asserted above
@DanielGibson
DanielGibson / Makefile
Created September 25, 2013 23:14
Makefile for Deep Impact: Freefall
# Makefile for Deep Impact: Freefall
# (C) 2013 Daniel Gibson, do whatever you want with it
#
# needs GNU make, tested on Linux, should work on other unix-like systems as well
# also needs SDL2, SDL2 image and SDL2 ttf + development headers etc
# and a C++11 and GCC compatible C++ compiler (tested g++ 4.7 and clang++ 3.3)
# CC := clang
# CXX := clang++
@DanielGibson
DanielGibson / daikatana-pak.txt
Last active April 1, 2016 19:32
Description of Daikatana .pak format
// Daikatana .pak format. It's similar to Quake/Quake2 format, but supports compressed files as well.
// I think that only the following file types are compressed: .tga .bmp .wal .pcx .bsp
// I wouldn't rely on this list when unpacking, but when packing, only compress those.
// the structs are based on pakextract.c from https://github.com/yquake2/pakextract
// all ints are 32bit Little Endian.
struct pak_header
{
char signature[4]; // {'P','A','C','K'}, like in Quake/Quake2
@DanielGibson
DanielGibson / parse_dk_wal_and_8bit_bmp.c
Last active April 4, 2016 01:28
Hacky code that parses and displays Daikatana .wal files and 8bit BMP files
/*
* Kinda messy code to parse and display 8bit BMPs and Daikatana wals
* Can also be compiled to check whether the colormaps of textures in a
* directory match that of the corresponding colormap.bmp
*
* Note that it currently only displays the first mipmap level of a .wal texture
* and ignores the animname, flags, contents and value fields of the header.
*
* (C) 2016 Daniel Gibson
*
@DanielGibson
DanielGibson / daikatana_entities.json
Last active May 1, 2016 23:12
Daikatana Entity Definitions as .json
[
[
[
"classname",
"worldspawn"
],
[
"color",
"0 0 0"
],
@DanielGibson
DanielGibson / testrapidjson.cpp
Created August 2, 2016 21:56
Test rapidjson parsing speed, like in http://computers-are-fast.github.io/
// this is hacky and assumes messages.json is <64k bytes. that's the case for
// https://github.com/kamalmarhubi/one-second/blob/master/setup/protobuf/message.json
#include "rapidjson/document.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
size_t numIterations = 1;
@DanielGibson
DanielGibson / SDL_mouse.c
Last active December 6, 2017 16:03
test sdl relative mouse input with mouse warping
// in src/events/SDL_mouse.c added some SDL_Log() calls to SDL_PrivateSendMouseMotion():
#include "SDL_log.h"
static int
SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
int posted;
int xrel;
int yrel;