Github Source Ensim5 explores compiler friendly SIMD expressions and cache locality for isentropic flow and kinematic equations. One can model a piston flow lane from plenum intake to exhaust as nine chambers (atmosphere, plenum, throttle, runner, piston, runner, exhaust, exhaust, atmosphere) and with eight nozzles, mapping parallel computation perfectly to floating point AVX256 or doubling point…
Github Source I wanted to determine what a dependency free embedded scripting language would need to mirror (a fraction) of what pytorch and python do in a machine learning context. Implemented is a tiny ~1000 line recursive descent compiler with basic matrix operators, matrices as types, and unary operators as functions. This yields some interesting concepts, mainly right to left syntaxing that…
Github Source I recently gained some curiosity on LLVM and attempted a recursive descent parser that (this time around) emits LLVM directly with printf. I set some limitations for myself while writing Nibble, namely no-malloc, no-free (and thus no AST), and no reliance on external libraries. The goal was to demystify compiler design for others, and have the compiler produce real tangible software…
Github Source Engine Simulator 4, or ensim4, is a rewrite of ensim3 with emphasis on cache locality and branchless 1D-CFD (Computational Fluid Dynamics) LF (Lax–Friedrichs). Seen here, an inline 8 engine with modeled fuel injection, combustion, isentropic mass flow, and two exhaust plenums, each output displacement vs. amplitude in their wave_0_pa and wave_1_pa widgets to the right: Having…
GitHub Source Engine Simulator 3, or ensim3, is my third attempt at modelling an open source internal combustion engine simulator. Built on graph theory fundamentals (Directed Cyclic Graphs and such), ensim3 executes node pairs connected by edge breadth-first as an isentropic flow transaction. Audio is sampled in the engine collector and convoluted with an impulse reverb. This video showcases some…
In this post I outline one way to simulate a four stroke Inline Internal Combustion Engine (IICE) with realistic and performant procedural audio. The engine core utilizes fundamentals of thermodynamics, fluid mechanics, classical dynamics, and (should you deviate from the above), high school chemistry. Applications include, but are not limited to, game development vehicular audio and physics:…
GitHub Source Let us use ANSI-C (C90) to compile (or transpile, for the pedantic) a target language to an intermediate ANSI-C file. The Target Language Our target language, dubbed switch , will be reminiscent of the B Programming Language, supporting a single type int , pointers thereto, operators doubly thereof, basic control flow and looping, and recursion, but of course, barring function…
GitHub Source Roman2 - otherwise known as Python with pointers and curly braces - is my first attempt at creating a dependency free programming language. Roman2 is comprised of a recursive descent parser, an assembler, virtual machine, and runtime garbage collector. The syntax is primitive, borrowing the feel of C and the expression of Python from the early 21st century. Included are lists, dicts,…
GitHub Source I recently took a detour exploring FM synthesis and MIDI parsers. FM waves, similar to that of generic DOS sound-card OPL waveforms, make for quite the neat little orchestra when fed directly to the sound-card through SDL2. The waveforms, mocking up various instruments like the piano, guitar, brass, and winds, are emulated by FM synthesizing either a triangle, sine, square, half…
GitHub Source A recent round of small projects left me rewriting the same set of linked lists and resizable arrays for a myriad of types. While enjoyable to most C programmers, rewriting the same data structure is definitely a time sink, and the conventional approach of encapsulating void pointers is slow and prone to type errors. The gist to effective compile time polymorphism lies within the…
Often times one needs to obfuscate game assets. If a game relies on BMP files, SDL2, and vim, the first step to obfuscating the assets without the need of cryptography is already done. SDL2 has out of the box support for Windows BMP files. The macro to load BMP files is declared in SDL_Surface.h and takes a file path string as an argument: #define SDL_LoadBMP(file)…
Github Source I recently stumbled upon a small bash script that calls feh --bg-fill in a loop over an array of PNG files to animate the desktop background. The performance was fairly poor. Cumulative CPU usage was close to 40% on my X230. As an alternative, I discovered SDL2 can provide a generic interface to create a window from a pixel array, including the base root X11 window used by desktop…
Generic C99 hash tables (or dicts for the python programmers) can be readily built upon pre-existing generic list data structures. The gist is that a generic portion of memory is hashed, and the hash retrieves a list from an array of lists (also known as buckets). In the case of an insertion, the data is pushed to the back of this hashed list. In the case of a get, a node pointer is returned from…
This post will outline a generic solution to lists, queues, and stacks in C99. Doubly Linked Lists The eternal memory allocator, malloc, being declared as: void* malloc(size_t size); yields a plugin to a generic node datatype: typedef struct Node { void* data; struct Node* a; struct Node* b; } Node; A node points to data allocated by malloc, and is doubly linked to data allocated by malloc with…
GitHub Source I ported a couple popular Shadertoy shaders to run on the CPU: Sea Scape, by Alex Alekseev (shadertoy.com/user/TDM) Creation, by Danilo Guanabara (shadertoy.com/user/Danguafer) Tunnel, by Inigo Quilez (shadertoy.com/user/iq) The shaders request a single uint32_t pointer from SDL2 and then proceeds to divide the screen into as many horizontal rows as there are logical cores on your…
This multi-part series is a walk-through on implementing an 8 player Real Time Strategy (RTS) lockstep engine using the assets from Trial version of Age of Empires II. Certain simplifications, like omitting terrain elevations and civilizations, will be made to reduce overall complexity of the source. This tool-set in this series will be using a standard ISO C99 compiler, a Makefile, and your…
Vim tabs, like chrome or firefox tabs, allow for a quicker streamlined work flow. vim -p Theme.c Timer.c World.c To switch between tabs use: gT gt Or, for the inclined, add the following to your .vimrc: set tabpagemax=128 map <C-h> gT map <C-l> gt And now you can switch between 128 open tabs with Ctrl + H and Ctrl + L. Some vim pundits argue this to be a misuse of vim’s tab system. Certainly, long…
Headerless C99. It can be done given a basic template: #ifndef __CLASS__ #define __CLASS__ #undef defines #ifdef CLASS #define defines(...); #else #define defines(...){__VA_ARGS__} #endif #endif Let us model a wristwatch as WATCH.c: #ifndef __WATCH__ #define __WATCH__ #include <stdio.h> #undef defines #ifdef WATCH #define defines(...); #else #define defines(...){__VA_ARGS__} #endif typedef struct…
GitHub Source Raycasting howto blogs are a dime a dozen, though little about ceiling or floor casting is ever mentioned. Wall Height The height of the wall is calculated by taking the normal ray to the wall (in this case, the x direction), and multiplying the focal length of the field of view. The normal is clamped to a small value in case the player gets too close to the screen. const float…
GitHub Source Chip8 is a rather obscure virtual machine written for the long forgotten COSMAC VIP. The virtual machine has 35 opcodes making it an ideal first emulation project. High level assemblers exist for the chip8, but not high level programming languages mainly due to limited stack space. Fortunately, with a bit of craftsmanship, a B-Like programming language is fully feasible, barring…
GitHub Source There are many dungeon generation algorithms out there, but my favorite by far is what Phi Dinh of Tiny Keep was able to do with Delaunay Triangulation and minimum spanning trees . ############################################################# ########### # # # ########### ## ## # # # ########### ## ## # # # # # ## ## # # # # # ## # ## ## # # # # # ## ## # # # # # ## ## # # # #####…
GitHub Source Weaver generates a spider tapestry with a two fold algorithm. The initial phase processes the image: The image is blurred with a Gaussian convolution blur, grey scaled, and then sobel filtered. A threshold is then applied to identify edges with a binary true or false. These points are pushed into list. The latter phase makes use of Delaunay Triangulation: A point from the list may…
GitHub Source An N64 like pipeline is obviously not as complicated as any modern day graphical pipeline, but the combination of z-buffering, Gouraud shading, and texture mapping yields some pretty nice results: This can be done in about 500 lines of pure C code without any graphic libraries. One just needs a 32 bit pointer to video memory, a strong understanding of linear algebra, and plenty of…