Skip to content

Instantly share code, notes, and snippets.

@tinkerer-red
tinkerer-red / benchmark.gml
Last active August 17, 2025 08:15
`*_foreach` benchmark
new Benchmark("*_foreach comparasons", [
new TestCase("array_foreach()", function(iterations) {
array_foreach(array, function(_element, _index){})
},
function(iterations) {
array = array_create(iterations);
}),
new TestCase("array for loop", function(iterations) {
for (var _index=0; _index<array_length(array); _index++) {
var _element = array[_index];
@tinkerer-red
tinkerer-red / Pose-to-Point-Matrix.py
Created August 13, 2025 10:25
Initial attempts at generating point clouds for mesh collisions based of poses. With the intent to assist modders to automatically create non-convex Hull collisions using only Boxes, Spheres, or Cylinders
# Pose-to-Point-Matrix (Empties) with Precision, BVH-inside, and KDTree distance pruning
# - Inside/Outside by BVH ray-parity on the remeshed surface
# - Precision decimation via striding per axis
# - Exactly two extra nodes per axis AFTER precision
# - Drop points whose nearest vertex is farther than 32 * spacing
#
# ASCII-only. Blender 4.2.
import bpy
import bmesh
@tinkerer-red
tinkerer-red / string_keep.gml
Last active May 30, 2025 15:37
An example of how to efficiently parse a string for whitelisted characters, in this example it uses a supplied font
function string_keep(_text, _font) {
static __input_buff = buffer_create(1, buffer_grow, 1);
static __output_buff = buffer_create(1, buffer_grow, 1);
static __glyph_cache = ds_map_create();
var _input_buff = __input_buff;
var _output_buff = __output_buff;
var _glyph_cache = __glyph_cache;
//write data into input buffer
buffer_write(_input_buff, buffer_string, _text)
@tinkerer-red
tinkerer-red / string_grapheme_length.gml
Created May 11, 2025 15:49
A Latin based implementation of how to count grapheme char count in a string.
/// @func string_grapheme_length(_unicode)
/// @desc Counts the number of grapheme clusters (visible characters) in a UTF-8 encoded string
/// @param {string} _unicode - A string potentially containing UTF-8 encoded content
/// @return {int} The number of visible grapheme clusters
function string_grapheme_length(_unicode) {
static _cache = {};
// If this has been parsed before, return the data
var _hash = variable_get_hash(_unicode);
if (struct_exists_from_hash(_cache, _hash)) {
@tinkerer-red
tinkerer-red / convert_to_array_map.gml
Created April 12, 2025 15:11
Tries buffer implementation in gml
function convert_to_array_map(_map) {
static __buff = buffer_create(0, buffer_grow, 1);
var root = array_create(256, undefined); // Root node
var _names = struct_get_names(_map);
var _length = array_length(_names);
for (var _i = 0; _i < _length; _i++) {
var _find = _names[_i];
@tinkerer-red
tinkerer-red / logging.gml
Created April 10, 2025 19:39
Red's `pprint()` and `log()`
#macro pprint repeat (__pprint_pre(_GMFILE_, _GMFUNCTION_, string(_GMLINE_))) __pprint
/// @param ...args
function __pprint() {
var _str = $"PRINTER :: {
string_replace(string_replace(__pprint.__file, "gml_Object_", ""), "gml_GlobalScript_", "")
}/{
string_replace(string_replace(__pprint.__func, "gml_Object_", ""), "gml_Script_", "")
}:{__pprint.__line}:\n"
var _i=0; repeat(argument_count) {
@tinkerer-red
tinkerer-red / CompileTime_VS_RunTime_TestGenerator.py
Created April 2, 2025 02:40
BasicCompileEvalConsistencyTestSuite
import os
from itertools import product
script_dir = os.path.dirname(os.path.abspath(__file__))
# Operand types with example values
operands = {
"0b": "0b1011", # 11
"0x": "0xA7", # 167
"Unsigned-real": "167", # int
@tinkerer-red
tinkerer-red / CacheSystem.gml
Created March 17, 2025 23:52
A Simply Cache System for internal use in functions
function CacheSystem() constructor {
data = {};
static __string_hash = {} //explicetly used to improve the speed at which we hash strings
static save = function(_value) {
var _data = data;
var _cache_ref_key_count = argument_count;
var _last_index = _cache_ref_key_count-1;
for(var _i=1; _i<_cache_ref_key_count; _i++) {
function string_format_human_readable(_num) {
if (_num == 0) return "zero";
static __ones = [
"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"
];
static __tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
@tinkerer-red
tinkerer-red / Emoji_Names_on_Discord.json
Last active March 6, 2025 12:35
Collection of names and synonyms for Emojis of Discord
{
"people":[
{"names":["grinning","grinning_face"],"surrogates":"\uD83D\uDE00","unicodeVersion":6.1},
{"names":["smiley"],"surrogates":"\uD83D\uDE03","unicodeVersion":6},
{"names":["smile"],"surrogates":"\uD83D\uDE04","unicodeVersion":6},
{"names":["grin"],"surrogates":"\uD83D\uDE01","unicodeVersion":6},
{"names":["laughing","satisfied"],"surrogates":"\uD83D\uDE06","unicodeVersion":6},
{"names":["face_holding_back_tears"],"surrogates":"\uD83E\uDD79","unicodeVersion":14},
{"names":["sweat_smile"],"surrogates":"\uD83D\uDE05","unicodeVersion":6},
{"names":["joy"],"surrogates":"\uD83D\uDE02","unicodeVersion":6},