adding collision layers
adding collision layers
For modders adding special functionality based on collision layers, it's a nightmare retaining compatibility with other mods.
Can you allow us to add more collision layers so each mod can add its own layer if he needs it?
Can you allow us to add more collision layers so each mod can add its own layer if he needs it?
creator of 53 mods
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
Re: adding collision layers
Collision masks are defined using a bitmask on a unsigned 16 bit integer. The 0 value is "none", the 0xFFFF value is "not defined" so that leaves 14 possible values for collision masks.
To make that bigger means every collision mask in the entire game is now bigger - even without mods using any of them.
I know there was talk of doing this but if we ever did increase it, it would only ever increase to a maximum of an unsinged 64 bit integer making for 62 possible collision masks.
To make that bigger means every collision mask in the entire game is now bigger - even without mods using any of them.
I know there was talk of doing this but if we ever did increase it, it would only ever increase to a maximum of an unsinged 64 bit integer making for 62 possible collision masks.
If you want to get ahold of me I'm almost always on Discord.
Re: adding collision layers
if you increase it, can you please allocate it from a mod-specified string to a bit in the integer so mods don't have to guess which one is free?
(i suggest doing it in the form of a really simple prototype?)
64 should be more than enough, even 32 would do the trick.
if a mod tries to create a collision layer that would exceed the limit, just throw an error at the user
(i suggest doing it in the form of a really simple prototype?)
Code: Select all
{type="collision-layer", name = "modxyz's-layer"}
if a mod tries to create a collision layer that would exceed the limit, just throw an error at the user
creator of 53 mods
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
Re: adding collision layers
What is it you're trying to do? Maybe I could help you come up with a solution that approaches it from a more compatibility-minded angle. There are always options!
I think I've observed a similar behaviour when mods add too many tiles.
Re: adding collision layers
- trees that are only plantable in non-desert with the normal "cannot build here" functionality ( https://mods.factorio.com/mod/robot_tree_farm )
- https://mods.factorio.com/mod/CanalBuilder
- https://mods.factorio.com/mod/Hovercrafts
and many more...
- https://mods.factorio.com/mod/CanalBuilder
- https://mods.factorio.com/mod/Hovercrafts
and many more...
creator of 53 mods
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
Re: adding collision layers
An API to request a unique collision layer would be useful even with the 5 layers we have. If more than 5 mods using the API are installed, the last mod shuts down with a warning instead of randomly breaking other mods.
Re: adding collision layers
I noticed that collision_mask can also include "collision options" that are strings but don't correspond to the layers. I tried but I couldn't find an event that perfectly fits this case in which you could easily check for the collision options as the player or bot or whatever attempts to place the tree entity. The only thing I have thought of is that you could do a small control code that kills trees after they are planted in the desert. Sorry couldn't be more helpful. I do know a code we could use that checks all the other mods for existing collision masks, and so you could at least ensure that way you're not racing another mod for the same collision mask. But I assume you have already thought of that, and it would not solve the problem in the case where all existing vanilla-unused layers are used by other mods.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: adding collision layers
+1
I think i've called the current implementation "completely unusable" on several occasions already. The problem is that because every mod author just randomly decides to use any of the free layers (most use the first or the last it seems) i can not guarantee that my code works *at all*, because i have no knowledge or control of other mods layers. Worst case i remember was a mod that wanted to add one of the "free" collision layers to 90% of all ground tiles so that one of their buildings can only be built on sand. (I've wanted tile-type-based placement restrictions since years ago too btw.)
If custom layers were named prototypes then it'd be unlikely enough that mods conflict with each other accidentially while still allowing cross-mod-compatibility if the participating authors so desire.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: adding collision layers
In case it is helpful for anyone, here is a bit of code. I confirmed that it doesn't cause a crash, but I haven't integrated it into a mod that uses layers, yet. But it should work fine. If it doesn't, it'll just be because of a typo or simple thing we can fix. For simplicity, it checks far more than just entities for collision_mask (in fact, it checks everything), since there are many data.raw.type types which refer to different types of entities. This shouldn't be a problem.
Run the function in your data_updates.lua or data_final_fixes.lua. It will return the lowest layer which is as yet unused. Then apply that layer to your entities. Something like
Not a perfect solution, but it'll get the job done, unless the layers are all used.
Code: Select all
function find_unused_layer()
local unused_layers = {
"layer-11",
"layer-12",
"layer-13",
"layer-14",
"layer-15",
}
for i,data_type in pairs(data.raw) do
for j,data_obj in pairs(data_type) do
for k,layer in pairs(data_obj.collision_mask or {}) do
for l,unused_layer in pairs(unused_layers) do
if layer == unused_layer then
unused_layers[l] = nil
end
end
end
end
end
for _,layer in pairs(unused_layers) do
return layer
end
return nil
end
Code: Select all
local layer_to_use = find_unused_layer()
if layer_to_use ~= nil then
if not data.raw.entity["my-entity-1"].collision_mask then
data.raw.entity["my-entity-1"].collision_mask = {}
end
table.insert(
data.raw.entity["my-entity-1"].collision_mask,
layer_to_use
)
if not data.raw.entity["my-entity-2"].collision_mask then
data.raw.entity["my-entity-2"].collision_mask = {}
end
table.insert(
data.raw.entity["my-entity-2"].collision_mask,
layer_to_use
)
...
And so on for any entities you want to mask with the layer
else
-- You're screwed because there are no free layers, act accordingly.
-- Pick one at random and hope for the best?
-- Make a forum thread where we share what layer we're using?
end
Last edited by Adamo on Thu Aug 22, 2019 5:12 pm, edited 4 times in total.
-
- Filter Inserter
- Posts: 587
- Joined: Sun Jun 09, 2019 10:40 pm
- Contact:
Re: adding collision layers
...and that'd be an in-memory representation concern, not an on-disk one, wouldn't it? I was trying to work out why, eg, a variable length representation for the value would be a problem since, as long as the collision mask space was dense, you would have the minimum number of bits required.
Then I worked out that you don't want a variable length encoding at runtime, since bitmask comparisons of the encoded values would probably be costly enough to not be worth it. Either you pay for decoding a variable length value first, which isn't super-cheap, or you pay for masking out the tag bits, which again isn't super-cheap. (Though I've not checked the cycle-cost of those, compared to memory latency.)
Yes?
Also, wube staff, if you can, is having "standard" code like this in multiple mods, and/or some sort of reusable library for same, a convincing argument for getting something done? I wonder some if having a proof of the concept is useful or not to convincing y'all to accept something?
Re: adding collision layers
In 1.1 there are now a total of 55 collision masks available to mods.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: adding collision layers
too late, too few.
send me a mail when you let mods add overlays for your game guis.
btw anybody have 0.18.25 for me?
send me a mail when you let mods add overlays for your game guis.
btw anybody have 0.18.25 for me?
creator of 53 mods
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
Re: adding collision layers
Overlays, or you mean, like attachments to the game GUIs?
We added the relative GUI system not too long ago:
https://lua-api.factorio.com/latest/Lua ... i.relative
https://lua-api.factorio.com/latest/Lua ... ent.anchor
https://lua-api.factorio.com/latest/Con ... #GuiAnchor
Re: adding collision layers
ah i see, you also implemented "luaguielement.bring_to_front()" ... thank youKlonan wrote: ↑Sun Jun 20, 2021 12:36 pmOverlays, or you mean, like attachments to the game GUIs?
We added the relative GUI system not too long ago:
https://lua-api.factorio.com/latest/Lua ... i.relative
https://lua-api.factorio.com/latest/Lua ... ent.anchor
https://lua-api.factorio.com/latest/Con ... #GuiAnchor
creator of 53 mods
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance