Skip to content

Instantly share code, notes, and snippets.

View anissen's full-sized avatar

Anders Nissen anissen

View GitHub Profile
@haxiomic
haxiomic / ObjectPool.hx
Last active September 21, 2023 12:48
Structure of Array and Array of Structures in Haxe
/**
* ObjectPool is a type building macro to create array-of-structure or structure-of-array pools.
* With the intention being to improve access performance, both in CPU cache coherence and by avoiding the GC
*
* This implementation is a minimal working proof of concept
*
* Improvements you may want to make
* - Support deallocation of instances and space reclaiming
* - Replace haxe.io.Bytes because field access has overhead
*
@haxiomic
haxiomic / show-errors.js
Created July 27, 2021 09:50
When you can't access the console, this script will display errors and warnings over the html (ensure this runs before your own code)
(() => {
let errorDisplayEl = document.createElement('div');
errorDisplayEl.classList.add('error-display');
errorDisplayEl.style.display = 'none';
errorDisplayEl.style.position = 'absolute';
errorDisplayEl.style.zIndex = '2000';
errorDisplayEl.style.backgroundColor = 'rgba(146, 0, 0, 0.6)';
errorDisplayEl.style.padding = '20px';
errorDisplayEl.style.fontFamily = 'monospace, sans-serif';
errorDisplayEl.style.color = '#fff5f5';
@KinoAR
KinoAR / DepotMacros.hx
Last active June 23, 2021 13:39
Macro for Depot that turns your database elements/spreadsheet rows into a part of your code base.
package macros;
#if macro
import haxe.DynamicAccess;
import Types.DepotFile;
import sys.io.File;
import sys.FileSystem;
import haxe.macro.Expr.Field;
import haxe.Json;
import haxe.macro.Context;
@haxiomic
haxiomic / UnitTestFramework.hx
Last active December 2, 2021 16:31
Super simple unit testing powered by haxe macros
#if macro
import haxe.macro.Context;
import haxe.macro.PositionTools;
import haxe.macro.Expr;
import haxe.macro.ComplexTypeTools;
#end
/**
Pass in a boolean expression, if test fails (expression evaluates to false) the expression itself will be printed with the line number and failure reason
@Calinou
Calinou / CHANGELOG.md
Last active May 25, 2023 19:07
Godot 4.0 preliminary changelog (does not list changes that were also backported to Godot 3.x)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog.

[4.0] - TBD

Added

@Calinou
Calinou / camera.gd
Last active July 12, 2019 05:27
Freelook camera script from my Sponza demo
# Copyright © 2017 Hugo Locurcio and contributors - MIT license
# See LICENSE.md included in the source distribution for more information.
extends Camera
const MOVE_SPEED = 0.5
const MOUSE_SENSITIVITY = 0.002
onready var speed = 1
onready var velocity = Vector3()
onready var initial_rotation = PI/2

Generating Procedural Game Worlds with Wave Function Collapse

Wave Function Collapse (WFC) by @exutumno is a new algorithm that can generate procedural patterns from a sample image. It's especially exciting for game designers, letting us draw our ideas instead of hand coding them. We'll take a look at the kinds of output WFC can produce and the meaning of the algorithm's parameters. Then we'll walk through setting up WFC in javascript and the Unity game engine.

sprites

The traditional approach to this sort of output is to hand code algorithms that generate features, and combine them to alter your game map. For example you could sprinkle some trees at random coordinates, draw roads with a brownian motion, and add rooms with a Binary Space Partition. This is powerful but time consuming, and your original vision can someti

@haxiomic
haxiomic / Partial.hx
Last active February 26, 2023 11:44
Haxe macro to make all fields of a type optional (similar to Typescript's Partial<T>)
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.TypeTools;
#if !macro
@:genericBuild(PartialMacro.build())
#end
class Partial<T> {}
class PartialMacro {
@RealyUniqueName
RealyUniqueName / KeyValueIterator.hx
Last active October 14, 2016 10:35
Key-value map iterator
class KeyValueIterator<K,V> {
var map:Map<K,V>;
var keys:Iterator<K>;
static public inline function pairs<K,V>(map:Map<K,V>) return new KeyValueIterator(map);
public inline function new(map:Map<K,V>) {
this.map = map;
this.keys = map.keys();
}
@byronhulcher
byronhulcher / starter.lua
Last active April 7, 2017 05:36
PICO-8 Starter LUA code (save this as starter.p8)
-- pico-8 starter code
-- by @hypirlink
-- _init() is called when
-- you 'run' the program
function _init()
-- states: menu, game, end
state = "menu"
end