Value types vs allocated types and SoA in Haxe

@javidcf to expand on implementing SoA and AoS with abstracts over plain byte buffers I’ve created a macro that does this for you, given a structure

Demo: Try Haxe !

For example, to create a SoA object pool you can do:

typedef Player = ObjectPool.SoA<'Player', {
	x: Float,
	y: Float,
	age: Int,
	eyeColor: EyeColor,
	alive: Bool,
	velocity: {
		x: Float,
		y: Float,
		q: {a: Int, b: Int},
	},
}>;

You can create instances with new Player(). This returns simply and Int, corresponding to the index in the SoA arrays

In AoS mode, nested structures are flattened so you have just one big chunk of bytes corresponding to each instance

Implementation is here:

7 Likes