DensityCompiler 5.46.0
Compiles seed-bound density function graphs into straight-line PHP methods (no objects or closures in the evaluation path), so that the JIT can turn them into native float code.
The generated source only depends on the shape of the graph and on seed-independent constants (frequencies, amplitudes, spline points...). Seed-dependent data (noise permutations and offsets) is read from properties filled by the generated constructor, so one compiled file serves every seed.
Two forms are generated:
- scalar:
name(float $x, float $y, float $z) : float. Named functions and caches become memoized methods (per (x, z) column when the value does not depend on y, like vanilla's flat cache; per position otherwise); - batch:
name(float $x, float $z, array $Y) : array, evaluating a whole column of cell corners. Every node is a short loop over the active points, and lazy nodes split the point list instead of branching. This is the shape PHP's JIT compiles best, and it lets x/z dependent work be done once per column. Both keep vanilla's lazy evaluation and short-circuits (range_choice, interval_select, lerp, mul, min/max), so they compute exactly the same values as the interpreted graph (checked by tests).
Properties
$inlineOctaves
public static bool $inlineOctavesInline the octave sampling code instead of calling ImprovedNoise::sampleRaw(). PHP 8.4's tracing JIT fails to compile ("JIT compilation error") loops that contain the inlined sampler, while it compiles (and inlines) the call just fine; the function JIT prefers inlined code.
$unrollOctaves
public static bool $unrollOctavesGenerate octave stacks unrolled (one block of code per octave) instead of as loops. Unrolled code is faster without JIT, loops are faster with the tracing JIT (long linear traces get aborted).
Methods
addMethod()
public function addMethod(string $source) : voidAdds a hand-written method (e.g. a chunk filling loop using compileInline() fragments).
addProperty()
public function addProperty(string $declaration) : voidbuildClass()
public function buildClass(string $className, string $namespace) : stringReturns the full class source. The constructor takes the seed-bound data returned by getBindings().
compileBatchRoot()
public function compileBatchRoot(\pocketmine\world\generator\vanilla\density\DensityFunction $root, string $name) : voidCompiles $root into public function $name(float $x, float $z, array $Y) : array, returning the values for every y in $Y (keys 0..count-1).
compileInline()
public function compileInline(\pocketmine\world\generator\vanilla\density\DensityFunction $root, array $channelVars, string $prefix) : arrayCompiles an expression into a code fragment for inlining into a hand-written loop: returns [statements, result]. The fragment may use $x, $y, $z and the given channel variables (values of interpolated functions).
compileRoot()
public function compileRoot(\pocketmine\world\generator\vanilla\density\DensityFunction $root, string $name) : voidCompiles $root into a public method $name(float $x, float $y, float $z) : float.
float()
public static function float(float $v) : stringgetBindings()
public function getBindings() : \pocketmine\world\generator\vanilla\compiler\KernelBindings