tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Probability object property on rule_options layer does not work as expected

Open vchelaru opened this issue 1 year ago • 2 comments

Describe the bug The Probability variable does not seem to properly apply whether a rule is applied in auto mapping. Specifically, values inbetween 0 and 1 (such as 0.5) act as if the value is 0, and the rule never appears.

To Reproduce

  1. Download and unzip the attached zip - it includes a simple setup for reproducing the problem. ProbabilityBug.zip
  2. Open FRBPlatformerDemoExterior.tmx
  3. Click Map->Auto Map, or press the CTRL+M hotkey. Observe that the green tiles remain on screen. image
  4. Open RulesMap.tmx - this is the TMX that contains the rules
  5. Observe that there are two possible rules which could apply to the middle tiles: image
  6. Select the rule_options layer, and notice that a rectangle overlaps rule 2 and sets the probability to 0.5. Therefore, roughly half of the tiles should be blue
  7. To verify that this rule is in fact correct, move the rectangle so it does not overlap a rule and apply AutoMap back on FRBPlatformerDemoExterior.tmx. Observe that the blue grass appears. 25_16 27 04
  8. Move the rectangle back and auto map again. Observe that no blue tiles appear: 25_16 28 05

Expected behavior I expect that blue tiles appear when applying AutoMap with a probability of 0.5. Even increasing the probability to larger numbers such as .9 does not produce any blue tiles.

Additional Information

Strangely, using the eraser tool below the strip of tiles will sometimes cause blue tiles to appear. I haven't been able to figure out specifically what causes this to happen. It seems somewhat random, but at times this will produce a consecutive strip of blue tiles, rather, rather than a random set of blue tiles. I don't know if this is related but I thought I'd mention this in case it helps solve the problem.

25_16 32 06

Media See above

Specifications:

  • OS: Windows 10
  • Tiled Version: 1.9

vchelaru avatar Jul 25 '22 22:07 vchelaru

Update - thanks to @eishiya for mentioning that the regions layer is not necessary for AutoMap in 1.9. I removed this and tested again - the bug continues to reproduce. The presence of this layer has no impact on the bug, but I thought I'd mention it in case this comes up as a possible cause.

25_16 47 27

vchelaru avatar Jul 25 '22 22:07 vchelaru

Strangely, using the eraser tool below the strip of tiles will sometimes cause blue tiles to appear.

This prompted me to take a look at the test files again, to see if perhaps Automap While Drawing works correctly while Automap does not, and made some discoveries.

  • I am able to get blue results sometimes with Automap While Drawing, and haven't gotten them even once with Automap.
  • Erasing produces blue much more often than painting (at least with the settings in the provided map, I don't think I ever got blue while painting).
  • I thought perhaps it's because the rules are applied in different orders - as of 1.9, rules apply simultaneously, so green could apply to a tile after blue, overwriting the blue result. However, even with MatchInOrder set to true, this issue happens.
  • I tried resetting the AutomappingRadius property (from 3), and this helped! Automap While Drawing now randomises as expected both on drawing and erasing. However, Automap from the menu and drawing many tiles at once (e.g. with Shift+Brush or filling a selection) still gives all greens.

I don't know what's going on, but the fact that the behaviour is seems to depend on how large the region is implies the issue is with Tiled and not with the rules or map/rule options. The rules work fine when the affected region is just a rule's worth, but don't seem to work correctly when the affected region is larger.

On an unrelated note: you don't need DeleteTiles set on your rules map. This also makes no difference to the probability issue (I tested xP), but I thought I'd mention it. DeleteTiles was needed in older versions to erase tiles, but since all your rules have an output, DeleteTiles does nothing useful. It's also generally unintuitive, and like regions, is still there mainly for backwards compatibility.

Edit: Had another look. I tried adding an inputnot_GroundLayer layer to make the green rule never overwrite blue tiles. I wouldn't expect this to make a difference with MatchInOrder still in play, but it does, though not in a way I expected: With AutomappingRadius 0, Automap While Drawing works as expected and as before, but filling a larger region all at once (drawing lines, in this case) seems to concentrate all the blue on the left: image With AutomappingRadius set to 3, the behaviour gets weird. Drawing freehand near the top of the map works correctly, but drawing lines right below (1 tile away, minimum required for the rules to match) is all green: image However, drawing the subsequent lines 3 away modifies the line above to be correct (each line is initially drawn all-green): image The above images were drawn freehand. When using line-drawing, everything is green, except tiles that are 3 away from the start or end of the line...? image I can't even find a pattern here.

eishiya avatar Jul 25 '22 23:07 eishiya

Following up from Discord discussion. I'm seeing the same (or very similar) issues when using the Probability Map property on a rule map.

Issue 1: This property does not appear to work correctly when used with Shape Fill or Bucket Fill tools. Tiles within the space are properly modified by rules until one of them fails due to the Probability value, at which point no other tiles within the space will be checked.

I'm using a very simple test case, one rule map with one input tile that maps to a few output tiles using indexed output layers. I set the Probability on the Map Properties to 0.2 which per the docs will apply that to all the inputs in the map. If I freehand draw tiles using the Stamp Brush they apply the random output tiles ~20% of the time as intended. If I draw a rectangle with Shape Fill or just fill the whole layer with Bucket Fill they will only fill up until the first tile fails the Probability test.

With Probability set to 1 (or the map property removed) image

With Probability set to 0.75 image

Note that in the second case, it seems to be checking the tiles from left-to-right, top-to-bottom, and once the Probability chance fails the first time none of the remaining tiles are ever modified. This can be repeated as often as desired and the same behavior will be seen.

Issue 2: This property doesn't appear to work when not using "AutoMap While Drawing". Using the same test case as above, no matter how I place the tiles initially (using Stamp Brush, Shape Fill, or Bucket Fill) when applying AutoMap to the map manually no tiles are changed if Probability property is present. Even set to something extremely high like 0.99 none of the tiles are modified by the rule. Removing the Probability property allows manual AutoMap to work as expected.

slaygeist avatar Aug 25 '22 22:08 slaygeist

This was broken by a small optimization I made in 029395c7fff14348a8e3f03c6766cec3629ef4c5, where the return should have been changed to a continue. :-/ Thanks for the detailed report!

bjorn avatar Aug 26 '22 08:08 bjorn