Skip to content

Instantly share code, notes, and snippets.

@pfirsich
pfirsich / Signal.hpp
Created August 22, 2016 10:23
Signals/Slots
#ifndef __SIGNAL_HPP_INCLUDED__
#define __SIGNAL_HPP_INCLUDED__
#include <cstdio>
#include <vector>
#include <functional>
// eraz on ##c++@freenode helped me with this, by pointing me to std::function!
// Here we use std::function like template syntax, by defining a generic Signal and
import os
import sys
cmd = 'ffmpeg -r 60 -i "{dirName}/%d.png" -y -c:v libx264 -vf "format=yuv420p" -r 60 "{dirName}.mp4"'
for dirName in os.listdir("."):
if os.path.isdir(dirName) and (len(sys.argv) <= 1 or dirName in sys.argv[1:]):
os.system(cmd.format(dirName=dirName))
@pfirsich
pfirsich / main.lua
Created July 6, 2018 22:15
Trace blobs in images to approximate polygons around them. Done for @MaChue on the löve Discord server. Images are here: https://imgur.com/a/sFQl7ax
local trace = require("trace")
local imageIndex = 1
local image
local outline
local boundingBox
function updateBoundingBox(padding)
-- minX, minY, maxX, maxY
boundingBox = {math.huge, math.huge, 0, 0}
@pfirsich
pfirsich / controlconfigscripts.md
Last active July 16, 2018 10:02
Documentation for Controll Config Scripts in Spectacular Shatter Buddies (http://shatterbuddies.net/)

Control Config Scripts (*.sbcs)

Notes

For syntax highlighting you can usually use JavaScript or C syntax highlighting.

The configs you find in the save directory in control_configs will be overwritten every time you restart the game. If you want to make a custom control script, you need to create a copy with a different name.

Sadly if there is a syntax error in these scripts, the script will be parsed up until that error without notifying you, so that you will have only partially working controls!

General Syntax

@pfirsich
pfirsich / _hybrid.lua
Last active August 23, 2018 21:39
Sketches for high-level library for kaun (chu)
-- resources (kaun)
local paddleMesh = kaun.newMesh("paddle.obj")
local paddleTexture = kaun.newTexture("paddle.png")
local ballMesh = kaun.newSphereMesh(1.0, 12, 12)
local ballTexture = kaun.newTexture("ball.png")
local level = kaun.newMesh("level.obj")
local skyboxMesh = kaun.newBoxMesh(1, 1, 1)
@pfirsich
pfirsich / pot_bench.lua
Created August 25, 2018 10:42
Power of Two function benchmark for luajit (löve used for timing)
local potLut = {}
potLut[0] = 1
for i = 1, 32 do
potLut[i] = potLut[i-1] * 2
end
-- compare this with lshift(2, n)
local function potA(n) -- power of two
return potLut[n]
end
@pfirsich
pfirsich / bitmask.lua
Created August 26, 2018 18:04
A LuaJIT bitmask class (like std::bitset)
local bit = require("bit")
local band, bor, bxor, bnot, lshift = bit.band, bit.bor, bit.bxor, bit.bnot, bit.lshift
local function pot(n) -- power of two
return lshift(1, n)
end
local BitMask = setmetatable({}, {__call = function(t, ...)
local self = setmetatable({}, t)
self:initialize(...)
@pfirsich
pfirsich / static_var_default.cpp
Last active October 1, 2018 01:42
A function `getVar` that gets the value of a static variable inside a class (template argument) and returns a default value, if that static variable is not present.
#include <iostream>
using VarType = int;
const VarType DEFAULT_VAR = 0;
struct doesHaveVar {
static const VarType var = 1;
};
struct doesNotHaveVar {
@pfirsich
pfirsich / setColor.lua
Created October 17, 2018 13:23
love.graphics.setColor compatibility monkeypatch for migrating from love 0.10.2 to 11+
do
local oldSetColor = love.graphics.setColor
function love.graphics.setColor(r, g, b, a)
if type(r) == "table" then
assert(#r == 3 or #r == 4)
assert(g == nil and b == nil and a == nil)
r, g, b, a = unpack(r)
end
assert(type(r) == "number" and type(g) == "number" and type(b) == "number")
@pfirsich
pfirsich / convertfont.py
Created March 22, 2020 20:28
BMFont XML to Text for löve
#!/usr/bin/python3
import argparse
import sys
import xml.etree.ElementTree as ET
# In general the attributes I copy are not the ones that BMFont allows, but the ones that löve will read:
# https://github.com/love2d/love/blob/fc4847c69d6c9ad7ed84501197427b23400ae1b4/src/modules/font/BMFontRasterizer.cpp
# That means in general this script might generate files that might not be fully compliant BMFont files
# but they should work with löve