Skip to content

Instantly share code, notes, and snippets.

View revivalizer's full-sized avatar

Ralph Brorsen revivalizer

View GitHub Profile
@revivalizer
revivalizer / fpustate.h
Created July 26, 2013 12:05
C++ class to set FPU flags for denormal flushing
// RAII FPU state class, sets FTZ and DAZ and rounding, no exceptions
// Adapted from code by mystran @ kvraudio
// http://www.kvraudio.com/forum/viewtopic.php?t=312228&postdays=0&postorder=asc&start=0
class ZFPUState
{
private:
unsigned int sse_control_store;
public:
@revivalizer
revivalizer / gist:7937396
Last active December 31, 2015 04:59
Usage example for refonter 0.1
// Include font data
namespace cheri
{
#include "font_cheri.ttf.bin.h"
}
// Convenience font class
// This class uses OpenGL 3.3 array buffers to draw characters
class Font
{
@revivalizer
revivalizer / pipable-function-defence.md
Last active August 24, 2018 18:07
In defence of pipable functions in C++

Chaining function calls via the dot operator is a very common thing to do in C++. Of course, you chain things because it's nice, and easier to read than nested function calls. The prototypical use case is matrix composition:

auto m = Matrix::Indentity().RotateX(145.0).RotateY(-90.0).Scale(2.0);

Which seems preferable to

auto m = Scale(RotateY(RotateX(Matrix::Identity, 145.0), -90.0), 2.0).

Usually, dot chaining is implemented by return *this from Scale, RotateX, RotateY, and having those functions be part of the Matrix class. This is usually a brilliant way to work.

@revivalizer
revivalizer / gist:935dfcc345b009a0207a033caee0175f
Created August 18, 2022 10:55
Recursive descent calculator example
// Had to cut some stuff out that distracted from the main point, so maybe it doesn't compile, but...
struct calculator {
bool Succes;
const char* Start;
const char* FailAt;
const char* Error;
const char* C;
real Compute(const char* ExprStr) {
Succes = true;