Noise expression system hooks

Post Reply
User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Noise expression system hooks

Post 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.
Image

Rseding91
Factorio Staff
Factorio Staff
Posts: 13175
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Noise expression system hooks

Post 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.
If you want to get ahold of me I'm almost always on Discord.

TOGoS
Former Staff
Former Staff
Posts: 93
Joined: Fri Jun 24, 2016 2:29 pm
Contact:

Re: Noise expression system hooks

Post 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. ;) 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.

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Noise expression system hooks

Post by Bilka »

Just FYI ToGoS, your account was already confirmed when you posted this :P 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Noise expression system hooks

Post 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?
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

Re: Noise expression system hooks

Post 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.
Image

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Noise expression system hooks

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”