Skip to content

Instantly share code, notes, and snippets.

View fenbf's full-sized avatar

Bartłomiej Filipek fenbf

View GitHub Profile
// compile at https://godbolt.org/g/yb47Aq
//
#include <iostream>
#include <memory>
class Widget
{
public:
void DoStuff() { }
// smart_ptr_deleters.cpp
// shows how to use custom deleters with unique_ptr and shared_ptr
// Bartlomiej Filipek, April 2016, bfilipek.com
#include <iostream>
#include <memory>
#include <functional>
#include <cassert>
// This class cannot be changed, might come from 3rd party library
template <typename T>
class HasToString
{
private:
typedef char YesType[1];
typedef char NoType[2];
template <typename C> static YesType& test( decltype(&C::ToString) ) ;
template <typename C> static NoType& test(...);
@fenbf
fenbf / sfinae_tostring_ex.cpp
Created February 9, 2016 20:33
C++ SFINAE example: how to detect if a class contains ToString method
// SFINAE, enable_if example
// based on http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
#include <iostream>
#include <type_traits>
class ClassWithToString
{
public:
// simple perf test for memory allocations
// bfilipek.com
#include <iostream>
#include <memory>
#include <vector>
#include <chrono>
int main()
{
@fenbf
fenbf / glParticleRenderer.cpp
Last active February 4, 2018 00:02
particle rendering 'system'.
#include "glParticleRenderer.h"
#include "particles.h"
#include <assert.h>
#include "gl_includes.h"
namespace particles
{
void GLParticleRenderer::generate(ParticleSystem *sys, bool)
{
@fenbf
fenbf / ParticleUpdaters.cpp
Created June 5, 2014 18:37
Particle Updaters
namespace updaters
{
void EulerUpdater::update(double dt, ParticleData *p)
{
const glm::vec4 globalA{ dt * m_globalAcceleration.x, dt * m_globalAcceleration.y, dt * m_globalAcceleration.z, 0.0 };
const float localDT = (float)dt;
const unsigned int endId = p->m_countAlive;
for (size_t i = 0; i < endId; ++i)
p->m_acc[i] += globalA;
@fenbf
fenbf / BasicParticleGenerators.cpp
Created May 12, 2014 15:48
Basic Particle Generators modules
#include "particleGenerators.h"
#include <assert.h>
#include <algorithm>
#include <glm/common.hpp>
#include <glm/gtc/random.hpp>
namespace particles
{
namespace generators
{
@fenbf
fenbf / BasicParticleUpdaters.cpp
Created May 12, 2014 15:44
Basic Particle Update modules
#include "particleUpdaters.h"
#include <assert.h>
#include <algorithm>
#include <glm/common.hpp>
#include <glm/gtc/random.hpp>
namespace particles
{
namespace updaters
{
@fenbf
fenbf / BasicParticles.cpp
Created April 27, 2014 05:47
Basic Particle classes design. Used as a starting point for my particle system. More details http://www.bfilipek.com
#include "particles.h"
#include <assert.h>
#include <algorithm>
namespace particles
{
void ParticleData::generate(size_t maxSize)
{
m_count = maxSize;
m_countAlive = 0;