Skip to content

Instantly share code, notes, and snippets.

//by @sssmcgrath
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include <stdio.h>
#define isPowerOfTwo(v) (((v) & ((v) - 1)) == 0)
/*
I'm dropping this from the game in favour of a more dynamic system, but I wanted to keep this around somewhere because
I'll be using this 'pattern' for something similar again and didn't want to fuss with sytax. Maybe you'll find it useful
*/
#define ANIM_LIST \
/* EnumName, var_name, max */ \
ALF(Invalid, invalid, 1) \
ALF(Idle, idle, 4) \
ALF(Spawn, spawn, 4) \
ALF(Taunt, taunt, 2) \
#ifndef MG_LINKEDLIST_EXTERN
#define MG_LINKEDLIST_EXTERN extern
#endif
#ifndef MG_LINKEDLIST_INTERN
#define MG_LINKEDLIST_INTERN static
#endif
//mandatory
#ifndef MG_LINKEDLIST_TYPE
#ifndef MG_FREELIST_EXTERN
#define MG_FREELIST_EXTERN extern
#endif
#ifndef MG_FREELIST_INTERN
#define MG_FREELIST_INTERN static
#endif
//mandatory
#ifndef MG_FREELIST_FREE_FN_NAME
#define MG_PLATFORM_IMPLEMENTATION
#define MG_TOOL_IMPLEMENTATION
#define MGGL_IMPLEMENTATION
#define MG_PLATFORM_OPENGL
#define MG_PLATFORM_OPENGL_DEBUG
#define MGGL_DEBUG
#define MG_PLATFORM_LOOP gameLoop
#define MG_PLATFORM_INIT initGame
#define MG_PLATFORM_CONFIG configGame
#ifndef __MG_ED25519_H_INCLUDE_GUARD__
#define __MG_ED25519_H_INCLUDE_GUARD__
//#define MG_ED25519_IMPLEMENTATION exactly once, blah blah
/*
I completely ripped this off of Orson Peters' ed25519 implementation to make it a single file. I added mg_ed25519 prefixes
to everything so it wouldn't pollute the global namespace, but otherwise the code is the same.
The original implementation is here: https://github.com/orlp/ed25519
- Shawn McGrath <@sssmcgrath on twitter>
//this copies the logic of void ImDrawList::AddConvexPolyFilled()
static void imgui_fixQuadFilledVerts(ImDrawList *draw_list, int vert_offset, ImVec2 *points, mgColour opt_col) {
MG_ASSERT(draw_list->VtxBuffer.Size > vert_offset - 8);
const int points_count = 4;
ImDrawVert *vert_ptr = draw_list->VtxBuffer.Data + vert_offset;
if (draw_list->Flags & ImDrawListFlags_AntiAliasedFill) {
// Anti-aliased Fill
const float AA_SIZE = 1.0f;
// Compute normals
ImVec2 temp_normals[points_count];