Skip to content

Instantly share code, notes, and snippets.

View zloedi's full-sized avatar

zloedi zloedi

  • Sofia Bulgaria
View GitHub Profile
@zloedi
zloedi / SDLPorts.cs
Created February 22, 2024 08:54
Ports some parts of the Unity API to SDL C#
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using GalliumMath;
using static SDL2.SDL;
using static SDL2.SDL.SDL_WindowFlags;
using static SDL2.SDL.SDL_EventType;
using static SDL2.SDL.SDL_TextureAccess;
using static SDL2.SDL.SDL_BlendMode;
@zloedi
zloedi / roguelike_FOV.c
Last active January 11, 2024 07:17
Efficient roguelike grid FOV / shadowcasting / line of sight in a single C function inspired by https://docs.microsoft.com/en-us/archive/blogs/ericlippert/shadowcasting-in-c-part-one
// Copyright (c) 2021 Stoiko Todorov
// This work is licensed under the terms of the MIT license.
// For a copy, see https://opensource.org/licenses/MIT.
// What this function does:
// Rasterizes a single Field Of View octant on a grid, similar to the way
// field of view / line of sight / shadowcasting is implemented in some
// roguelikes.
// Uses rays to define visible volumes instead of tracing lines from origin
// to pixels.
@zloedi
zloedi / QonsoleAmalgamated.cs
Last active October 19, 2023 13:34
Ingame and Ineditor debug console for Unity in a single source file: https://youtu.be/rtaWs_eZRDE
// THIS FILE WAS GENERATED
#if UNITY_STANDALONE || UNITY_2021_0_OR_NEWER
#define HAS_UNITY
#endif
#define QONSOLE_BOOTSTRAP // if this is defined, the console will try to bootstrap itself
#define QONSOLE_BOOTSTRAP_EDITOR // if this is defined, the console will try to bootstrap itself in the editor
namespace QON {
@zloedi
zloedi / crt-lottes-appleii.glsl
Last active August 2, 2022 19:19
old monochrome crt monitor (apple ii/pravetz) shader
#if defined(VERTEX)
varying vec4 v_color;
varying vec2 v_texCoord;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
v_color = gl_Color;
v_texCoord = vec2(gl_MultiTexCoord0);
}
@zloedi
zloedi / minimal size mingw exe example Makefile
Last active April 1, 2022 09:29
mingw minimal windows exe using SDL (exe size ~9K)
# Thanks goes to https://nullprogram.com/blog/2016/01/31/ -- Small, Freestanding Windows Executables
no_crt.exe: main.c
x86_64-w64-mingw32-gcc -o no_crt.exe main.c -pedantic-errors \
-std=c99 -Wall -Wextra \
-O3 \
-fno-tree-loop-distribute-patterns \
-fno-stack-protector -mno-stack-arg-probe \
-mconsole -DM_CONSOLE \
-I/usr/local/x86_64-w64-mingw32/include \
`sdl2-config --static-libs` \
@zloedi
zloedi / Nav.cs
Last active October 25, 2021 14:30
Flood fill pather in C#
//#define NAV_FOUR_WAY
public static class Nav {
public const int FREE = ( int )0x0fffffff;
public const int BLOC = ( int )0x40000000;
static int Min( int a, int b ) {
return a < b ? a : b;
@zloedi
zloedi / minilist.h
Last active August 27, 2020 13:18
Single header C library to turn your buffer into a generic doubly linked list, by sacrificing the first few elements. Provides some typesafety through the ML_Add() macro.
// Copyright (c) 2020 Stoiko Todorov
// This work is licensed under the terms of the MIT license.
// For a copy, see https://opensource.org/licenses/MIT.
// This lib turns an array into a linked list by sacrificing the first
// few elements of the array
#ifndef ML_TYPE
// by default max numItems is 65535, redefine ML_TYPE if needed
#define ML_TYPE unsigned short
@zloedi
zloedi / nav_flood.h
Created October 5, 2019 15:32
Tiny single header flood fill pathfinder
// #define FLOOD_NAV_IMPLEMENTATION before #include "nav_flood.h" to unwrap the implementation
// #define NAV_FOUR_WAY before #include "nav_flood.h" for four-way flood implementation
#define NAV_FREE 0x0fffffff
#define NAV_BLOC 0x40000000
// Internal struct used to hold flood front
typedef struct {
int capMask;
int *buf;
@zloedi
zloedi / DebugExtensions.cs
Last active April 5, 2019 09:20
Unity Debug.DrawImage and Debug.DrawText routines in single file/static class.
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
public static class DebugEx
{
public static float CharactersOffset = -4;