Skip to content

Instantly share code, notes, and snippets.

View BtheDestroyer's full-sized avatar

Bryce "BtheDestroyer" Dixon BtheDestroyer

View GitHub Profile
@BtheDestroyer
BtheDestroyer / audio_callback_example.cpp
Last active May 20, 2022 05:53
STL-style circular buffer/array in C++. This is useful in certain applications where dynamic and contiguous memory can be useful, but memory reallocation isn't available; ie: audio programming
#include <algorithm>
#include <cmath>
#include <numbers>
#include "circular.hpp"
constexpr std::size_t k_audio_buffer_max_length{ 3000 };
using sample = float;
using audio_buffer = circular<sample, k_audio_buffer_max_length>;
void audio_callback_example(audio_buffer::iterator buffer_start, audio_buffer::iterator buffer_end)
{
// How much of this syntax is understandable?
int f1(int i)
{
return i * 5;
}
template <typename T>
T f2(T t1, T t2)
{
return t1 * t2;
version 3
emuVersion 20604
rerecordCount 8737
palFlag 0
romFilename Tetris (USA)
romChecksum base64:Ww5XFVjIx5aTe5avRpVhxg==
guid 3888A360-71BA-CBC6-B95C-A06268666AD4
fourscore 0
microphone 0
port0 1
@BtheDestroyer
BtheDestroyer / do_schema.hpp
Last active January 28, 2022 03:03
Formalized Data-Oriented Schema in C++
// Copyright 2022 Bryce Dixon
//
// Permission is hereby granted, free of charge,
// to any person obtaining a copy of this software
// and associated documentation files (the "Software"),
// to deal in the Software without restriction,
// including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so,
// This file is to showcase the use of the relatively new constexpr keyword to
// allow for processing of C-style strings at compile time.
// In turn, this allows for the use of C-style strings as cases in a switch
// statement. This is something that is typically impossible as C-style strings
// effectively degrade into void* in this situation as no string comparison
// is normally possible.
// An example of why this would be useful would be in an assembler or other
// simple language interpreter to improve interpretation time from O(n)
// in an if {} else if {} chain to O(log(n)).
// Another benefit over using enums is the lowered reliance on consistancy across