Skip to content

Instantly share code, notes, and snippets.

@bitnenfer
bitnenfer / img2dmg.c
Created January 30, 2019 03:26
Small program for transforming images to DMG (Game Boy) tile format.
// Everything except stb_image was made by Felipe Alfonso (@bitnenfer)
//
// This is a crappy software but it does what it needed from it. It just
// transform images (PNG, JPG, TGA, etc.) to DMG encoded tiles. It wont check
// for repeating tiles. Maybe in the future I can add that.
//
// Compile with GCC. gcc img2dmg.c -o img2dmg
// and it's done.
//
// Usage:
@bitnenfer
bitnenfer / TinyPool.h
Last active January 8, 2022 16:53
Fast tiny pool of 64 elements that allows random allocation and freeing
/* x64 Fast tiny pool of 64 elements that allows random allocation and freeing */
/* by Felipe Alfonso - http://voitptr.io */
#include <stdint.h>
#if _WIN32
#include <intrin.h>
#endif
template<typename T>
struct TinyPool
{
#if _WIN32
@bitnenfer
bitnenfer / pngb.c
Last active November 18, 2020 01:09
/*****************************************************************************
** pngb.c
**
** Code for the PNG GB Converter.
** Currently this module contains all the code for the converter except for
** the PNG loading routines (We are using LodePNG for that) and the program
** entry point (and command line parsing), which are in main.c.
**
** Copyright (c) 2015 Elias Zacarias
**
@bitnenfer
bitnenfer / X.js
Last active February 10, 2019 23:08
Commented code for the 2019 JS1K demo "X" (https://js1k.com/2019-x/demo/4039)
// This is the WebGL code:
// ======================
// GL function shortcuts taken from: http://xem.github.io/articles/archive.html#webgl_quest
for(i in g)g[i[0]+i[6]]=g[i];
// `with` helps us avoid doing g.xxx() and just do xxx()
with(g)
// Time variable.
@bitnenfer
bitnenfer / build_game.bat
Created January 30, 2019 03:25
A simple batch file that assembles, links and does a checksum fix using the RGBDS toolchain.
@echo off
cls
rem ================================================
rem ================================================
rem The project structure looks like this:
rem ROOT_PATH/
rem PROJECT_NAME/
rem code/
@bitnenfer
bitnenfer / fps.js
Created January 18, 2018 19:56
FPS
var fps = {
startTime : 0,
frameNumber : 0,
getFPS : function()
{
var d = Date.now();
var currentTime = (d - this.startTime) / 1000;
var result = Math.floor(++this.frameNumber / currentTime);
if(currentTime > 1)
{
@bitnenfer
bitnenfer / boilerplate-gl.js
Created November 22, 2017 20:23
WebGL 1.0 Simple Boilerplate
let canvas, gl;
let lastTime = 0;
const vShaderSource = `
precision mediump float;
attribute vec2 vtxPosition;
void main()
{
gl_Position = vec4(vtxPosition, 0.0, 1.0);
}
// three.js rev. 70 - Last version of three.js fails to run on cocoon.
// pixi.js v3.0.10
var canvas = document.getElementById('canvas'),
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'),
scene, camera, threeRenderer, geometry, hemiLight, dirLight,
material, cube, logoSprite, pixiRenderer, stage,
// Three.JS specific
setupThree = function () {
var d = 50;
scene = new THREE.Scene();
struct soa_vector4
{
union alignas(16)
{
struct
{
float x[4];
float y[4];
float z[4];
float w[4];
inline static void sse_mat4_add(__m128* m0, __m128* m1, __m128* dst)
{
dst[0] = _mm_add_ps(m0[0], m1[0]);
dst[1] = _mm_add_ps(m0[1], m1[1]);
dst[2] = _mm_add_ps(m0[2], m1[2]);
dst[3] = _mm_add_ps(m0[3], m1[3]);
}