Skip to content

Instantly share code, notes, and snippets.

View TannerRogalsky's full-sized avatar
💯
P I X E L S

Tanner Rogalsky TannerRogalsky

💯
P I X E L S
View GitHub Profile
@TannerRogalsky
TannerRogalsky / p01.rs
Created November 28, 2022 12:41
AoC Problem01 2021 GBA
#![cfg_attr(not(test), no_std)]
#![cfg_attr(not(test), no_main)]
#[cfg(not(test))]
extern crate alloc;
#[cfg(not(test))]
type Vec<T> = alloc::vec::Vec<T>;
#[cfg(not(test))]
@TannerRogalsky
TannerRogalsky / main.cpp
Created February 11, 2018 00:23
Emscripten producing invalid JS when unary operator is applied to static const instance property.
#include <cstdio>
class UnaryTest {
public:
static const UnaryTest STATIC_TEST;
double p;
UnaryTest(double p);
};
@TannerRogalsky
TannerRogalsky / buffer.cpp
Created April 7, 2017 11:11
Subdivide a polyhedron and buffer it's vertices into a VBO.
template<int32_t N>
void buffer(GLuint *vbos) {
if constexpr(N >= 0) {
const auto vertices = subdivide<N>(indexedVertices, indices);
const auto wireframe = getWireframeGeometry(vertices);
glBindBuffer(GL_ARRAY_BUFFER, vbos[N]);
glBufferData(GL_ARRAY_BUFFER, wireframe.size() * sizeof(Vertex), wireframe.data(), GL_STATIC_DRAW);
buffer<N - 1>(vbos);
}
}
@TannerRogalsky
TannerRogalsky / main.lua
Created January 23, 2017 13:55
Fast vertex setting in Love using ImageData and the FFI
local num_verts = 100000
local vertices = {}
for i=1,num_verts do
vertices[i] = {0, 0, 0, 0, 255, 255, 255, 255}
end
local ffi = require('ffi')
ffi.cdef[[
typedef struct {
float x, y;
local _PACKAGE = (...):match("^(.+)[%./][^%.]+")
local Line = {}
Line.__index = Line
local Vector = require(_PACKAGE .. ".vector")
function Line.new(x1, y1, x2, y2)
local self = setmetatable({}, Line)
self.origin = Vector(x1, y1)
@TannerRogalsky
TannerRogalsky / generateSphereVertices.lua
Created June 24, 2016 23:38
Fake 2D Sphere Without A Shader
local function insertVertices(vertices, vert, ...)
if vert then
table.insert(vertices, vert)
insertVertices(vertices, ...)
end
end
local function createSphereVertex(radius, theta, phi, ox, oy)
local xb = math.cos(phi) * math.cos(theta)
local yb = math.sin(theta)
@TannerRogalsky
TannerRogalsky / genMesh.lua
Created June 23, 2016 19:48
Generate a circular mesh.
local function genMesh(num_verts, radius)
local verts = {}
local interval = math.pi * 2 / num_verts
for i=1,num_verts do
local phi = i * interval
local x = radius * math.cos(phi)
local y = radius * math.sin(phi)
local u = (x + radius) / (radius * 2)
local v = (y + radius) / (radius * 2)
table.insert(verts, {x, y, u, v})
@TannerRogalsky
TannerRogalsky / map.lua
Created January 7, 2016 20:14
Load encoded/compressed Tiled data
-- From https://github.com/karai17/Simple-Tiled-Implementation/blob/4ac519dbd5efdc0c6a70c35b9125faebe347772f/map.lua#L217
local ffi = require("ffi")
local function getDecompressedData(data)
local d = {}
local decoded = ffi.cast("uint32_t*", data)
for i=0, data:len() / ffi.sizeof("uint32_t") do
table.insert(d, tonumber(decoded[i]))
end
@TannerRogalsky
TannerRogalsky / stateful_with_proxy.js
Created March 23, 2015 15:26
Javascript Stateful
Stateful = {
extend: function(klass) {
var currentState = klass.prototype;
var states = {null: currentState};
klass.prototype.gotoState = function(stateName, ...args) {
currentState = states[stateName];
}
klass.addState = function(stateName, state) {
@TannerRogalsky
TannerRogalsky / test1.lua
Created January 24, 2015 01:49
Action Tracking Format
-- all timings in bpm
return {
file: 'sounds/music.mp3',
bpm: 100,
players: 2,
actions: [
{
player: 1,
start_time: 1,