Skip to content

Instantly share code, notes, and snippets.

@pervognsen
pervognsen / sdl_debugoutput.c
Created September 26, 2014 07:29
SDL_DebugOutput
/**
* \brief Outputs an ASCII string that will be visible in a debugger.
* \note Uses OutputDebugStringA on Windows. Prints to stderr on all other platforms.
*/
extern DECLSPEC void SDLCALL SDL_DebugOutput(const char *str);
void SDL_DebugOutput(const char *str)
{
#if defined(__WIN32__) || defined(__WINRT__)
OutputDebugStringA(str);
@pervognsen
pervognsen / lazyfoo.cpp
Last active August 29, 2015 14:06
LazyFoo's SDL2/OpenGL 3.1 sample adapted from GLEW to my stuff
#include <SDL.h>
#include <SDL_opengl.h>
#include <stdio.h>
#include <string>
// PER_BEGIN
#define SDL_OPENGL_LOAD_IMPLEMENT
#include "SDL_opengl_load.h"
// PER_END
@pervognsen
pervognsen / SDL_stb.h
Last active August 29, 2015 14:07
SDL_stb
#ifndef _SDL_stb_h
#define _SDL_stb_h
// Memory buffers
typedef struct
{
Uint8 *data;
Uint32 size;
} SDL_MemoryBuffer;
In new(p) T(x) the C++ standard requires that placement new performs a null pointer check on p.
Unfortunately, this can add a pointless conditional to inner loops that use dynamic arrays implemented
in C++ via placement new. I don't expect the optimizer to perform a global analysis to conclude that p
can never be null, so I have to help it on its way. However, none of these three tricks convince Clang 3.5:
new(&*p) T(x);
(void) *p;
new(p) T(x);
@pervognsen
pervognsen / radix.cpp
Created October 18, 2014 00:54
radix packing
template<class U>
constexpr U static_pow(U base, U exponent)
{
return exponent == U(0) ? U(1) : base * static_pow(base, exponent - 1);
}
template<size_t N, size_t I, class U>
U radix_put(U w, U x)
{
constexpr U M = static_pow(N, I), MN = M * N;
@pervognsen
pervognsen / cdep.cpp
Created October 28, 2014 23:03
cdep.cpp
//
@pervognsen
pervognsen / emacscast.el
Last active August 29, 2015 14:10
emacscast.el
(require 'cl)
(require 'timer)
(defvar emacscast-events nil)
(defvar emacscast-recording-p nil)
(defvar emacscast-replay-events nil)
(defvar emacscast-replay-time nil)
(defun emacscast-forget-last-command ()
(when emacscast-recording-p
@pervognsen
pervognsen / asdf.el
Last active August 29, 2015 14:10
watch expressions with dbg.el
(defun dbg-watch (expression)
(interactive "sExpression: ")
(dbg-mi-command (list 'dbg-watch-handler expression) "-var-create - @ %s" (prin1-to-string expression)))
(defun dbg-watch-handler (status result expression)
(case status
((done)
(push (cons (cons 'expression expression) result) dbg-watches)))
(dbg-render-watches))
@pervognsen
pervognsen / autoeval.el
Last active August 29, 2015 14:10
autoeval.el
(defcustom autoeval-default-interval 1 "")
(defvar autoeval-sexps nil)
(defvar autoeval-interval autoeval-default-interval)
(defmacro autoeval (form)
`(progn
(push ',form autoeval-sexps)
(autoeval-start autoeval-interval)))
@pervognsen
pervognsen / inspector.el
Last active August 29, 2015 14:10
inspector.el
(require 'cl)
(defvar inspector-id 0)
(defvar inspector-keymap
(let ((keymap (make-sparse-keymap)))
(define-key keymap (kbd "<tab>")
(lambda ()
(interactive)
(save-excursion