Page 1 of 1
Noise expression system hooks
Posted: Sun Jan 21, 2018 8:26 am
by Reika
I spent a good deal of the past week digging through the noise expression system, and I believe I understand it and know how to use it, but right now everything worth doing is impossible because the system is effectively hardcoded.
In particular, the noise-expression's "expression" objects (in the prototype) operate on functions of a sort, which seem to be evaluated in the internal C++ engine. So, for example, when my custom function is passed "x, y, tile props, map props", it is being passed custom objects which have custom handling (done via metatables) to allow things like simple arithmetic. However, these "function-application" calls appear to be internally defined - I found no mention of them anywhere in the base or core folders, and data.raw["function-application"] is nil - and the four basic operators plus exponents is simply not sufficient to do anything meaningful.
The easiest way to make this usable would be to add some sort of hook to allow the getting of the "raw value", at least for X and Y, so that modders could then manipulate and calculate as they wish. Ideally, there would also be some sort of "get value by name" system on the other two parameters, for things like map seed.
A more complex and frankly less sensible idea would be to hardcode more functions, but the sheer number that are necessary - in my case, I needed bitwise operations, array index use, math.floor(), and modulo, and others likely need other functions - makes that not a realistic means to achieve proper moddability.
Re: Noise expression system hooks
Posted: Mon Jan 22, 2018 5:45 pm
by Rseding91
The noise expression system is compiled and runs as C++ after game startup. So, at best you might get more hard coded functions.
Making it do Lua callbacks to generate noise would be abysmal for performance. It already has a measurable overhead when you load a save to re-compile the in-save version of the expressions.
Re: Noise expression system hooks
Posted: Fri Feb 02, 2018 11:06 pm
by TOGoS
I wrote up some documentation about the new system, but have neglected to put it in the Wiki, which it turns out I don't even have write access to (!), so in the meantime:
https://gist.github.com/TOGoS/97c0b905e ... ba6092bad6. The list of available functions is towards the end, there.
noise.lua, which you've probably already scraped through, gives a convenient way to construct expression trees using most of the functions. If there's others that would be useful to you (floor, etc), let me know and I can probably add them.
As Robert pointed out, allowing callbacks into Lua isn't going to fly for performance reasons, but also because it'd be a pain in the neck to implement.
![Wink ;)](./images/smilies/icon_e_wink.gif)
The way the system is designed is as a branchless register-based SIMD machine, so things like conditionals and array lookups don't really fit with that model. If you want to do complex structure-building, it's probably better to do that in a chunk load callback.
Re: Noise expression system hooks
Posted: Fri Feb 02, 2018 11:25 pm
by Bilka
Just FYI ToGoS, your account was already confirmed when you posted this
![Razz :P](./images/smilies/icon_razz.gif)
If you want to make new pages, I'd prefer prior communication through discord so that they end up in the right place from the get go.
Oh and the links in the gist go nowhere (not even the source code repo) since you just copied it 1 to 1 from the source.
Re: Noise expression system hooks
Posted: Tue Sep 01, 2020 8:04 am
by Bilka
Reika wrote: Sun Jan 21, 2018 8:26 am
A more complex and frankly less sensible idea would be to hardcode more functions, but the sheer number that are necessary - in my case, I needed bitwise operations, array index use, math.floor(), and modulo, and others likely need other functions - makes that not a realistic means to achieve proper moddability.
More functions have been hardcoded, including math.floor(), modulo and bitwise operators. Could you explain what you mean with "array index use" and what other functions you need?
Re: Noise expression system hooks
Posted: Fri Sep 04, 2020 4:08 am
by Reika
Bilka wrote: Tue Sep 01, 2020 8:04 am
Reika wrote: Sun Jan 21, 2018 8:26 am
A more complex and frankly less sensible idea would be to hardcode more functions, but the sheer number that are necessary - in my case, I needed bitwise operations, array index use, math.floor(), and modulo, and others likely need other functions - makes that not a realistic means to achieve proper moddability.
More functions have been hardcoded, including math.floor(), modulo and bitwise operators. Could you explain what you mean with "array index use" and what other functions you need?
I moved on from this long ago - this was during the very early days of me developing my "Chokepoint" mod, before I just moved onto control-based script.
But basically I wanted to be able to use the noise system to implement my own noise functions based on simplex (or now, with the 2020 version of the mod) voronoi noise.
Re: Noise expression system hooks
Posted: Fri Sep 04, 2020 9:56 am
by Bilka
Reika wrote: Fri Sep 04, 2020 4:08 am
I moved on from this long ago - this was during the very early days of me developing my "Chokepoint" mod, before I just moved onto control-based script.
But basically I wanted to be able to use the noise system to implement my own noise functions based on simplex (or now, with the 2020 version of the mod) voronoi noise.
Okay, considering that
https://mods.factorio.com/mod/fractured-world implements a noise expression based voronoi noise, I would consider your original request achieveable/achieved and move this to implemented. However, if you decide to convert your mod from control.lua to noise expressions again and/or need new noise expressions in another context, please don't hesitate to open another modding interface request.