Skip to content

Instantly share code, notes, and snippets.

View TerensTare's full-sized avatar
🏠
Working from home

Terens TerensTare

🏠
Working from home
View GitHub Profile
#pragma once
#include "core.hh"
//
// Entities
//
using Entity = entt::entity;
inline constexpr auto nullEntity = entt::null;
@gvanem
gvanem / Asan-test.c
Created July 26, 2020 09:15
Test the new ASAN feature of MSVC
/*
* Test the new ASAN feature of MSVC (ripped from clang presumably).
*
* Ref:
* https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-windows-with-msvc/
*/
#include <stdlib.h>
/*
* Ref 'https://github.com/google/sanitizers/wiki/AddressSanitizerFlags'
@TheCherno
TheCherno / Instrumentor.h
Last active April 6, 2024 12:44
Basic Instrumentation Profiler
//
// Basic instrumentation profiler by Cherno
// Usage: include this header file somewhere in your code (eg. precompiled header), and then use like:
//
// Instrumentor::Get().BeginSession("Session Name"); // Begin session
// {
// InstrumentationTimer timer("Profiled Scope Name"); // Place code like this in scopes you'd like to include in profiling
// // Code
// }
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active April 24, 2024 03:49
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@niklas-ourmachinery
niklas-ourmachinery / identifying-controls-in-an-imgui.md
Last active January 24, 2023 06:09
Identifying controls in an IMGUI

Identifying controls in an IMGUI

In an IMGUI we need a way to identify which control is active or hot. For example, when we press a key, which text box does the text go to.

Possible options:

  1. Sequential number (Unity)

Each control drawn gets a sequentially increasing number.

@Alynva
Alynva / SDL Message Box.cpp
Created April 8, 2017 12:38
A little example of SDL Message Box
#include "SDL.h"
#include <windows.h>
int main(int argc, char *argv[]) {
const SDL_MessageBoxButtonData buttons[] = {
{ /* .flags, .buttonid, .text */ 0, 0, "no" },
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "yes" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "cancel" },
};
const SDL_MessageBoxColorScheme colorScheme = {
@GorNishanov
GorNishanov / recursive_generator.h
Created March 15, 2017 16:03
recursive_generator implementation
#ifndef RECURSIVE_recursive_generator
#define RECURSIVE_recursive_generator
#include <experimental/coroutine>
// This class implements delegating (potentially recursive) recursive_generator.
// It supports two kind of yield expressions:
//
// co_yield V;
// co_yield G_of_T;
@zlash
zlash / main.cpp
Created February 19, 2017 04:57
Minimal bgfx + SDL2
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#include <bgfx/bgfx.h>
#include <bgfx/platform.h>
#include <bx/bx.h>
#include <bx/mutex.h>
#include <bx/thread.h>
void threadInit()
{
@cswiercz
cswiercz / cached_factory.cpp
Last active June 15, 2022 03:04
Herb Sutter's favorite sub-10 line C++ snippet: Factory w/Cache
/*
Cached Factory
Sometimes you want to make objects with a lifetime managed
by their target owner but you also want to hold reference
to them in a custom cache. The target owner, naturally, will
be given a shared_ptr to the output object. However, we don't
want the lifetime of the output object to be tied to the
internal cache. I.e. if the owner dies then the object should
die even if referenced in the cache.