Skip to content

Instantly share code, notes, and snippets.

View catchouli's full-sized avatar
💭
type 2 invested entity

Caitlin Wilks catchouli

💭
type 2 invested entity
View GitHub Profile
#include <functional>
/** Combine hash in seed with hash of t1 */
template <typename T1>
void hash_combine(size_t& seed, const T1& t1)
{
// Combine hashes
seed ^= std::hash<T1>()(t1) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
@catchouli
catchouli / input
Last active August 29, 2015 14:12
libclang c++ draw tree
namespace coment
{
class Component
{
};
}
struct Stuff
: public coment::Component
@catchouli
catchouli / test.cpp
Created January 4, 2015 03:32
coment_rewrite interface example
World world;
EntityManager& em = *world.getManager<EntityManager>();
ComponentManager& cm = *world.getManager<ComponentManager>();
Entity e = em.createEntity();
auto positionMap = cm.getEntityMap<Position>();
auto velocityMap = cm.getEntityMap<Velocity>();
auto radiusMap = cm.getEntityMap<Radius>();
auto moverMap = cm.getEntityMap<Position, Velocity>();
@catchouli
catchouli / offset
Created January 4, 2015 14:57
a relic from the deepest darkest corners of c++
template <typename T, typename F>
size_t offset(F T::* ptr)
{
T* typePtr = (T*)nullptr;
F* memberPtr = &(typePtr->*ptr);
uintptr_t offset = (uintptr_t)memberPtr - (uintptr_t)typePtr;
return offset;
}
@catchouli
catchouli / 1. usage
Last active August 29, 2015 14:14
Signal/Socket C++ test
Signal<int> sig;
sig.connect(staticFunctionTest);
sig.connect([](int i){ printf("lambda function test %d\n", i); });
sig.connect(&test, &Test::test);
sig.emit(5);
vec3 interpolate(vec3 tri[3], vec3 vals[3], vec3 intersection)
{
// Calculate barycentric coordinates
float one_over_tri_area = 2.0f / length(cross(tri[1] - tri[0], tri[2] - tri[1]));
float u = 0.5f * one_over_tri_area * length(cross(tri[1] - intersection, tri[2] - intersection));
float v = 0.5f * one_over_tri_area * length(cross(tri[0] - intersection, tri[2] - intersection));
float w = 0.5f * one_over_tri_area * length(cross(tri[0] - intersection, tri[1] - intersection));
return vals[0] * u + vals[1] * v + vals[2] * w;
@catchouli
catchouli / gist:68a91251009dcfcccfa8
Created June 14, 2015 16:45
WinMain w/o windows.h
#ifndef _INC_WINDOWS
struct HINSTANCE__;
typedef struct HINSTANCE__ *HINSTANCE;
#endif
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
char* lpCmdLine,
int nCmdShow);
@catchouli
catchouli / header.hpp
Created June 18, 2015 19:30
pimpl - dont forget your copy constructors and shit
#pragma once
class SomeClass
{
public:
SomeClass();
~SomeClass();
SomeClass(const SomeClass&);
SomeClass& SomeClass(const SomeClass&);
@catchouli
catchouli / example
Last active March 29, 2018 14:24
scala simple scenegraph
val hexapod = new AssemblyNode {
transform.scale(0.1f, 0.1f, 0.1f)
// Body
children += new AssemblyNode {
children += new ModelNode(assets.get("assets/Base.obj"))
}
// Legs
(1 to 6).foreach(i => {
module Main where
import Control.Monad.Random.Strict
import Data.Array.MArray
import Data.Array.IO
import Data.Char
-- | Swap two elements in an array
swap :: (MArray a e m, Ix i) => a i e -> i -> i -> m ()
swap arr i j = do