Closed increpare closed 3 years ago
Because the matching functions can deal with objects in a same layer
longer explanation: matching a cell content like :
[ moving_A object_A moving_B object_B ]
needs to test the presence of (object_A && moving_A) && (object_B && moving_B). Now, if B is a property "C or D", the test becomes (object_A && moving_A) && ( (object_C && moving_C) || (object_D && moving_D) ).
If C and D are in the same layer, moving_C == moving_D and you can simplify the test into (object_A && moving_A) && ( (object_C || object_D) && moving_D), which is what the generated matching functions do (the attribute anyObjectPresent of the rule is a list of masks to encode things like (object_C || object_D) in this example).
If C and D are not in the same layer, you cannot do that optimization and the engine creates two rules (in the function concretizePropertyRule), one for dealing with C and one for dealing with D.
Yeah, that makes sense (disadvantage of runtime code generation: can't be bothered to see exactly what's getting generated right now ^^ ) - for single-layer stuff you can check if all the layers match in parallel, but multi-layer properties need more coordination between layers to determine if they match.
Thanks for reminding me how it works :)
https://www.puzzlescript.net/editor.html?hack=f913f440b9789b26401034d47a92d425
gets compiled to this:
Why?