Skip to content

Instantly share code, notes, and snippets.

View r-lyeh-archived's full-sized avatar

r-lyeh-archived

View GitHub Profile
@r-lyeh-archived
r-lyeh-archived / grid.hpp
Last active December 14, 2015 22:48
A 2D/3D collision grid
// A 2D/3D collision grid. MIT licensed
// - rlyeh, 2012
#pragma once
#include <map>
#include <set>
#include <cassert>
#include <tuple>
@r-lyeh-archived
r-lyeh-archived / compo.cpp
Last active December 9, 2019 06:28
Component-entity system in 16 lines of C++11. extract from kult engine (https://github.com/r-lyeh/kult)
#include <map> // Component-entity system in 16 lines of C++11. 2013 rlyeh, MIT licensed
#include <set> // Code fragment from kult engine - https://github.com/r-lyeh/kult
enum {JOIN,MERGE,EXCLUDE};using set=std::set<unsigned>;template<typename T> set&system(){
static set entities;return entities;}template<typename T,int MODE>set subsystem(const set
&B){set newset;const set&A=system<T>();if(MODE==MERGE){newset=B;for(auto&id:A)newset.ins\
ert(id);}else if(MODE==EXCLUDE){newset=B;for(auto&id:A)newset.erase(id);}else if(A.size()
<B.size()){for(auto&id:A)if(B.find(id)!=B.end())newset.insert(id);}else{for(auto&id:B)if(
A.find(id)!=A.end())newset.insert(id);}return newset;}template<typename T>std::map<unsig\
ned,T>&components(){static std::map<unsigned,T>objects;return objects;}template<typename\
T>bool has(unsigned id){return components<T>().find(id)!=components<T>().end();}templat\
#define USE_ROBIN_HOOD_HASH 1
#define USE_SEPARATE_HASH_ARRAY 1
template<class Key, class Value>
class hash_table
{
static const int INITIAL_SIZE = 256;
static const int LOAD_FACTOR_PERCENT = 90;
struct elem
@r-lyeh-archived
r-lyeh-archived / splaytree.cpp
Created June 26, 2014 09:20
splaytree from wikipedia
// [ref] http://en.wikipedia.org/wiki/Splay_tree
#include <functional>
#ifndef SPLAY_TREE
#define SPLAY_TREE
template< typename T, typename Comp = std::less< T > >
class splay_tree {
private:
/*(utf8)
1€ Filter, template-compliant version
Jonathan Aceituno <join@oin.name>
25/04/14: fixed bug with last_time_ never updated on line 40
For details, see http://www.lifl.fr/~casiez/1euro
*/
#include <cmath>
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
# define __WINDOWS__
// simple every() function
// - rlyeh. mit licensed
// @todo: during, in, when,
#pragma once
#include <map>
#ifdef EVERY_USE_OMP
#include <omp.h>
@r-lyeh-archived
r-lyeh-archived / when.cpp
Last active August 29, 2015 14:13
when/unless/go keywords
// when/unless go/unless keywords
// - rlyeh
#include <functional>
#include <iostream>
#define when(...) for( std::function<void()> fn; !fn && (__VA_ARGS__ +0); fn() ) fn = [&]
#define unless(...) , !(__VA_ARGS__) ? fn : fn = [&]
#define go when(true)
@r-lyeh-archived
r-lyeh-archived / lispy90.cpp
Created February 3, 2015 15:10
Scheme Interpreter in 90 lines of C++. Made by Anthony C. Hay in 2010.
// Scheme Interpreter in 90 lines of C++ (not counting lines after the first 90).
// Inspired by Peter Norvig's Lis.py.
// Made by Anthony C. Hay in 2010. See http://howtowriteaprogram.blogspot.co.uk/
// This is free and unencumbered public domain software, see http://unlicense.org/
// This code is known to have faults. E.g. it leaks memory. Use at your own risk.
#include <iostream>
#include <sstream>
#include <string>
@r-lyeh-archived
r-lyeh-archived / gist:f403dcb87f7b97883b62
Last active August 29, 2015 14:14
on compiling boost
rem 'cos I always forget how to do it
boostrap.bat
.\bjam2 runtime-link=static --with-serialization --toolset=msvc-11 && :: vs2012
.\bjam2 runtime-link=static --with-serialization --toolset=msvc-12.0 && :: vs2013, also: architecture=x86 address-model=64
rem also, extracting a lib:
bjam tools\bcp
dist\bin\bcp.exe algorithm/string.hpp [outdir]