Skip to content

Instantly share code, notes, and snippets.

@pfirsich
pfirsich / physfs_io.cpp
Created May 17, 2023 17:41
An example of a C++ wrapper for `PHYSFS_Io`
#include <cstdio>
#include <fmt/format.h>
#include <physfs.h>
template <typename Derived>
struct PhysfsIo : PHYSFS_Io {
protected:
PhysfsIo()
: PHYSFS_Io {
#pragma once
#include <string>
#include <spdlog/spdlog.h>
template <typename Derived>
struct DebugLogging {
DebugLogging() { spdlog::info("{} constructed", debugId()); }
@pfirsich
pfirsich / radiopanel.txt
Created September 13, 2015 13:22
Custom radio panels (used in conjunction with my autoexec) for CS:GO. Found in csgo/resource/ui. It's a little messy, since toggle, incrementvar, exec and some other commands are prohibited from being executed from a radio command.
"RadioPanel.txt"
{
//"SFUI_StandardRadio"
//"SFUI_GroupRadio"
//"SFUI_ReportRadio"
"Groups"
{
"standard"
{
@pfirsich
pfirsich / mpsc_queue.cpp
Last active April 26, 2022 10:59
Dmitry Vyukov's thread-safe multiple producer single consumer queue with wait free production ported to C++. I read the source code carefully and added lots of comments explaining what it does (it took me a while to figure it all out).
// g++ -Wall -Wextra -O0 -g -o log_test
#include <atomic>
#include <optional>
// Vyukov MPSC (wait-free multiple producers, single consumer) queue
// https://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-mpsc-node-based-queue
template <typename T>
class MpscQueue {
public:
@pfirsich
pfirsich / autoexec.cfg
Last active January 15, 2021 07:53
CS:GO autoexec.cfg
// Launch options: -console -novid -threads 4 -high -nojoy
echo " ___ _ _ ___ _
echo " |_ | | |( ) / _ \ | | "
echo " | | ___ ___ | ||/ ___ / /_\ \ _ _ | |_ ___ ___ __ __ ___ ___ "
echo " | | / _ \ / _ \| | / __| | _ || | | || __| / _ \ / _ \\ \/ / / _ \ / __|"
echo "/\__/ /| (_) || __/| | \__ \ | | | || |_| || |_ | (_) || __/ > < | __/| (__ "
echo "\____/ \___/ \___||_| |___/ \_| |_/ \__,_| \__| \___/ \___|/_/\_\ \___| \___|"
echo ""
echo "Saved in <Steam Library>\SteamApps\common\Counter-Strike Global Offensive\csgo\cfg"
@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
@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 / 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 / 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 / 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