Noise Expressions

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
klugemonkey
Inserter
Inserter
Posts: 23
Joined: Tue Jun 12, 2018 5:07 am
Contact:

Noise Expressions

Post by klugemonkey »

Is it possible to add an API method that would allow creating a noise expression / noise function that could be accessed at runtime?

I'd like to offload a lot of noise generation in my scenario to code running natively rather than in lua, and I understand there is some built-in stuff for this with noise expressions, but its not clear to me how to use it from runtime stage.

I understand there are some functions in lualib that are related to noise expressions, but don't think they are exposed.

I'm planning to place additional items during chunk generation based on these custom noise functions, so can't use existing autoplace specification because properties afaik are not extensible from the runtime.

Thanks for the consideration.

Koub
Global Moderator
Global Moderator
Posts: 7203
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: Noise Expressions

Post by Koub »

[Koub] I guess this belongs to the Modding Interface requests subforum, assuming this is not already in the game.
Koub - Please consider English is not my native language.

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Noise Expressions

Post by Honktown »

surface.map_gen_settings is writable at run-time, with the "gotcha" that the entire table has to be written at once.

Resources are "entities", so they can be edited under the property_expressions table.

https://lua-api.factorio.com/latest/Con ... enSettings

Particularly the last line before examples:

Code: Select all

All other MapGenSettings feed into named noise expressions, and therefore placement can be overridden by including the name of a property in this dictionary. The probability and richness functions for placing specific tiles, entities, and decoratives can be overridden by including an entry named {tile|entity|decorative}:(prototype name):{probability|richness}.
Unfortunately I think all probability expressions must be defined in the data stage... but you can disable the resource on surface generation (default_enabled = false in the autoplace spec, which is probably required to change the PRE/PDE), add them to the map_gen_settings table, and then surface.regenerate_entity("my-revealed-resource"), if the goal is to add a resource that becomes "discovered".

https://lua-api.factorio.com/latest/Lua ... ate_entity

Code: Select all

Regenerate autoplacement of some entities on this surface. This can be used to autoplace newly-added entities.
Was helping someone regenerate a mod resource the other day (mod added after start). We just brute-force regenerated all entities, but we weren't concerned with accidentally replacing trees, biters etc.

One may not be able to access or edit probability expressions, but for most practical purposes, they can be used as if they were editable.
I have mods! I guess!
Link

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

Re: Noise Expressions

Post by Rseding91 »

I don't realistically see this happening. the guy who write the logic for the noise expressions no longer works at Wube (he left to work on other things) and I'm not a fan of the noise logic itself so I don't want to work on it :P
If you want to get ahold of me I'm almost always on Discord.

klugemonkey
Inserter
Inserter
Posts: 23
Joined: Tue Jun 12, 2018 5:07 am
Contact:

Re: Noise Expressions

Post by klugemonkey »

Seems like if something doesn't work well, a redesign or rewrite would be in order. But then again I suppose sometimes you have to favor the schedule over perfection.

If needed I could make a mod for the scenario that contains the game specific noise values to generate. But putting game play specific noise parameters in a mod seems odd to me, and would have to make a mod for each game.

Frankly, all I really wanted was a fast noise function that can be called from the API in the runtime. Something where I can provide a couple of simple parameters and create multi-octave noise for placing objects on a map or other functionality within a scenario. Doesn't have to expose a noise expression syntax, just needs to be more performant than using Lua based Perlin noise generation. Suppose part of this is because its an O(N^2) algorithm.

I'm not even sure that an API will be any faster. Is Lua implementation in the runtime stage interpreted using LuaJIT or is it compiled to byte-code in advance? Would it be possible to provide pre-compiled bytecode chunks from the mod/scenario to improve performance?

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

Re: Noise Expressions

Post by Rseding91 »

The Lua runtime logic is just the BOG standard Lua + modified so iteration order is determnistic.

So if anything, it's Lua, but slower in some areas.
If you want to get ahold of me I'm almost always on Discord.

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Noise Expressions

Post by Honktown »

klugemonkey wrote:
Sat Feb 15, 2020 12:22 pm
...[1]But putting game play specific noise parameters in a mod seems odd to me, and would have to make a mod for each game.

...[2]Suppose part of this is because its an O(N^2) algorithm.

...[3]Would it be possible to provide pre-compiled bytecode chunks from the mod/scenario to improve performance?
[1] Second mod, dependency, add a remote interface.

[2] Some nerd has always figured out a crazy way to do it faster : P One example Never be afraid to do weird hacks if it works well enough.

[3] Unless I'm mistaken, that's already what happens by assigning the function to a variable. Only in the case of anonymous functions would there be a reason to compile the chunk again. If not, you can always try out "load". There's a number of compacted/compiled "(loadstring or load)" functions in the _G (actual global) scope.
I have mods! I guess!
Link

Post Reply

Return to “Modding interface requests”