Skip to content

Instantly share code, notes, and snippets.

@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},
@tinkerer-red
tinkerer-red / buffer_surface.gml
Last active March 2, 2025 03:54
`buffer_create_from_surface` and `surface_create_from_buffer`
#region jsDoc
/// @func buffer_create_from_surface
/// @desc Creates a fixed-size buffer containing the pixel data from the given surface. The buffer size is determined
/// by the surface's dimensions and format. The buffer is populated with the surface's pixel data starting at byte offset 0.
/// @param {Id.Surface} _surf - The source surface from which to read pixel data.
/// @returns {Id.Buffer} A buffer containing the surface's pixel data.
#endregion
function buffer_create_from_surface(_surf) {
// Get surface properties
var _width = surface_get_width(_surf);
@tinkerer-red
tinkerer-red / Benchmarks.gml
Last active February 18, 2025 18:25
Custom Matrix Benchmarks
Benchmarks = [
new Benchmark("2D Data foreach (full)", [
new TestCase("Array", function(iterations) {
var _i=0; repeat(iterations){
arr.foreach(function(_cell, _x, _y){}, false)
_i++}
},
function(){
width = 32;
@tinkerer-red
tinkerer-red / benchmark.gml
Last active February 16, 2025 10:09
`array_contains_other` Attempt to search array for non default values
new Benchmark("array_contains_not", [
new TestCase("manually checked for()", function(iterations) {
repeat (iterations) {
var result = func(testArray, default_value);
}
},
function(){
//initiallizer (is not accounted for in the benchmark test)
default_value = undefined;
@tinkerer-red
tinkerer-red / gist:9ed172f0db46df862f0b667b9d27da72
Last active January 28, 2025 02:00
constructor_call() / constructor_call_ext()
function constructor_call(ind) {
static __arr = [];
var _i=1; repeat(argument_count-1) {
__arr = argument[_i];
_i++}
var _struct = constructor_call_ext(ind, __arr);
array_resize(__arr, 0)