Skip to content

Instantly share code, notes, and snippets.

View stoyannk's full-sized avatar

Stoyan Nikolov stoyannk

View GitHub Profile
@stoyannk
stoyannk / context_if.hlsl
Created December 4, 2012 16:19
CONTEXT_IF example
context.specular_color = GetSpecularColor();
CONTEXT_IFNOT(context.specular_color) {
context.specular_color = specularColor;
}
class Test {};
int main()
{
// create manually
Test *t = static_cast<Test*>(operator new(sizeof(Test)));
new(t) Test;
// destroy manually
t->~Test();
operator delete(t);
@stoyannk
stoyannk / arc_leak_refs
Last active December 16, 2015 07:09
Leaking ARC references in Objective-C++ (clang Apple clang version 4.1 / (tags/Apple/clang-421.11.66))
#include <iostream>
#import <Foundation/Foundation.h>
@interface TestObj : NSObject
@end
@implementation TestObj
-(id)init {
self = [super init];
@stoyannk
stoyannk / live_view.js
Created December 4, 2013 15:02
Unity3D Live View JS Sample
window.onload = function() {
var c = document.getElementById("myCanvas");
c.onEngineImageDataUpdated = function (name, image) {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
ctx.putImageData(image, 0, 0);
ctx.fillStyle = "white";
ctx.font = "16pt Consolas";
#include <stdlib.h>
#include <cassert>
#include <memory>
#include <thread>
#include <vector>
#include <string>
#include <chrono>
#include <iostream>
#include "stdafx.h"
#include <unordered_set>
#include <memory>
#include <chrono>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sparsehash/dense_hash_set>
@stoyannk
stoyannk / Data_oriented_example.cpp
Created November 14, 2015 09:20
Sample that shows different approaces in the desing of a problem. For the HPC course in FMI 2015.
// Data-oriented variant for drawing moving shapes
struct Positions
{
unsigned Count;
float* Xs; // Simplify SIMD-ification
float* Ys;
};
struct ShapePositions
template
void Unite2D(const Rectangle& other, bool allowEmpty = false)
{
static_assert(sizeof...(Components) >= sizeof...(RhsComponents), "Cannot assign to type with less components than operand!");
static_assert(meta_contains_types<meta_packer, meta_packer>::value, "Operand has components that are not part of this object!");
m_Value.Unite2D(other.m_Value, allowEmpty);
}
@stoyannk
stoyannk / BlendModesFuncSample.cpp
Last active December 10, 2016 09:37
Sample of the blend modes unoptimal function
inline BlendingState BlendingMode2State(BlendModes mode)
{
static BlendingState states[] = {
{ /* Clear */
true,
BC_Zero,
BC_Zero,
BLOP_Add,
BC_Zero,
BC_Zero,
@stoyannk
stoyannk / BlendModesFuncSample_Fix.cpp
Created December 10, 2016 09:53
Sample for fixed blend modes function
static const BlendingState s_BlendingModes2State[] = {
{ /* Clear */
true,
BC_Zero,
BC_Zero,
BLOP_Add,
BC_Zero,
BC_Zero,
BLOP_Add,
},