Automapper: Difference between revisions

From DDraceNetwork
Created page with "{{MigrateTranslation}} <languages /> <translate> <!--T:1--> The '''Automapper''' is a tool to make mapping easier for mappers. Instead of placing the round edges of freeze by hand you could make a simple automapper rule that applies a few rules to a entire tile layer. Every automapper is made for a specific tileset. A tileset can have more than one automapper. All automapper rules are located in your teeworlds path at ''data/editor/automap/''<ref name="Au..."
 
m Add more unknown syntax to the random rule
 
(9 intermediate revisions by the same user not shown)
Line 4: Line 4:
<translate>
<translate>
<!--T:1-->
<!--T:1-->
The '''Automapper''' is a tool to make mapping easier for mappers. Instead of placing the round edges of freeze by hand you could make a simple [[Rules File|automapper rule]] that applies a few rules to a entire tile layer. Every automapper is made for a specific tileset. A tileset can have more than one automapper. All automapper rules are located in your teeworlds path at ''data/editor/automap/''<ref name="Automapper">[https://forum.ddnet.org/viewtopic.php?t=2428 Automapper Tutorial]</ref><ref name="ddnet-automapperfiles">[https://github.com/ddnet/ddnet/tree/master/data/editor/automap Automapper files]</ref>.
The '''Automapper''' is a tool to make mapping easier for mappers. Instead of placing the round edges of freeze by hand you could make a simple [[#Rules File|automapper rule]] that applies a few rules to a entire tile layer. Every automapper is made for a specific tileset. A tileset can have more than one automapper. All automapper rules are located in your teeworlds path at ''data/editor/automap/''<ref name="Automapper">[https://forum.ddnet.org/viewtopic.php?t=2428 Automapper Tutorial]</ref><ref name="ddnet-automapperfiles">[https://github.com/ddnet/ddnet/tree/master/data/editor/automap Automapper files]</ref>.
</translate>
</translate>


Line 22: Line 22:
Index 16
Index 16
Pos 0 -1 EMPTY
Pos 0 -1 EMPTY
...
</pre>
</pre>


Line 27: Line 28:


The automapper will read the rules file.
The automapper will read the rules file.
Afterwards it scans each '''position''' of the layer. If every rule of a selected tile applies, the tile will be placed at the scanning position of the automapper. If multiple tiles and their rules match, only the latest rule will apply (because it will be overwritten).
Afterwards it scans each '''position''' of the layer. If every rule of a selected tile applies, the tile will be placed at the scanning position of the automapper. If multiple tiles and their rules match, only the latest rule will apply (because it will be overwritten). [[#Syntax|Unless deactivated]], the automapper will put it's changes into a buffer first and apply them afterwards.
[[File:Indices.png|thumb|227x227px|Tileset indices overview]]


==Tile indices==
==Tile indices==


Every tileset has 16 rows and 16 columns and each tile can be addressed by its index. The index of a tile can be calculated by <code>index = 16 * row + column</code>, where row and column is between 0 and 15. The tile at index 0 is always considered <code>EMPTY</code>. Usually this part doesn't contain textures in tilesets. Each other tile is always considered <code>FULL</code>, even if it doesn't contain any textures and is fully transparent.
Every tileset has 16 rows and 16 columns and each tile can be addressed by its index. The index of a tile is a direct result of it's position and can be calculated by <code>index = 16 * row + column</code>, where row and column is between 0 and 15. The tile at index 0 is always considered <code>EMPTY</code>. Usually this part doesn't contain textures in tilesets. Each other tile is always considered <code>FULL</code>, even if it doesn't contain any textures and is fully transparent.


This is used for the <code>Index</code> keyword, where you select a tile that you
The index is used for the <code>INDEX</code> keyword of the automapper.


==Syntax==
==Syntax==
Line 51: Line 53:
'''Selecting a tile you want to place''':
'''Selecting a tile you want to place''':


<code>INDEX 42</code> This '''selects''' tile 42 (meaning the 2nd row and 10th column. Multiple indices can be selected by adding an <code>OR</code> between each index:
<code>INDEX 42</code>  
 
This '''selects''' tile 42 (meaning the 3rd row and 11th column. Multiple indices can be selected by adding an <code>OR</code> between each index:


<code>INDEX 42 OR 43</code>
<code>INDEX 42 OR 43</code>
Line 74: Line 78:
<code>POS 0 -1 FULL</code>
<code>POS 0 -1 FULL</code>


This rule selects the tile with ''X'' coordinate 0 and ''Y'' coordinate -1 '''relative to the''' [[Processing|scanning position]] of the automapper. If the tile '''above''' the scanning position is <code>FULL</code>, the '''selected tile''' will be placed (if all following rules apply). If it's <code>EMPTY</code>, it won't be placed.
This rule selects the tile with ''X'' coordinate 0 and ''Y'' coordinate -1 '''relative to the''' [[#Processing|scanning position]] of the automapper. If the tile '''above''' the scanning position is <code>FULL</code>, the '''selected tile''' will be placed (if all following rules apply). If it's <code>EMPTY</code>, it won't be placed.


Instead of using <code>FULL</code> or <code>EMPTY</code>, you can select another tile with the <code>INDEX</code> keyword:
Instead of using <code>FULL</code> or <code>EMPTY</code>, you can select another tile with the <code>INDEX</code> keyword:
Line 80: Line 84:
<code>POS 0 -1 INDEX 12</code>
<code>POS 0 -1 INDEX 12</code>


If the tile above the [[Processing|scanning position]] has index 12, it will be placed. Multiple indices can be selected by adding an <code>OR</code> between each index:
If the tile above the [[#Processing|scanning position]] has index 12, it will be placed. Multiple indices can be selected by adding an <code>OR</code> between each index:


<code>POS 0 -1 INDEX 12 OR 13</code>
<code>POS 0 -1 INDEX 12 OR 13</code>
Line 90: Line 94:
You can make a selected tile randomly apply to rules by adding a random rule:
You can make a selected tile randomly apply to rules by adding a random rule:


<code>RANDOM 20</code>
<code>RANDOM 20%</code>
 
The random rule expects a value between 0% and 100%. This value represents the probability, that a tile is placed<ref name="RandomRule">[https://github.com/ddnet/ddnet/blob/0abb32514b6e9643154dc6bcdc4a754defbf2321/src/game/editor/auto_map.cpp#L312 Random rule implementation]</ref>.
 
If you put a ''value'' into it '''without''' a <code>%</code> symbol, the probability will not be parsed in terms of percentages, but with this formula:


The random rule expects a value between 0 and 100. This value represents the probability, that a tile is placed<ref name="RandomRule">[https://github.com/ddnet/ddnet/blob/0abb32514b6e9643154dc6bcdc4a754defbf2321/src/game/editor/auto_map.cpp#L312]</ref>.
<code>percentage = 1.0 / value</code>
 
This allows for rarer tile placements with probabilities between 0% and 1% and a ''value'' > 100.
 
For example <code>RANDOM 150</code> will have a probability of <code>1.0 / 150 ≈ 0.67</code> (percent).


'''Default condition rule''':
'''Default condition rule''':
Line 110: Line 122:
'''NoLayerCopy''':
'''NoLayerCopy''':


Adding <code>NoLayerCopy</code> in a section will cause it to run [https://de.wikipedia.org/wiki/In_situ#Technik in situ]. This can drastically improve performance, because the automapper doesn't copy it's changes into buffer memory before applying it. But it can cause unintended side effects!
Adding <code>NoLayerCopy</code> in a section will cause it to run [https://en.wikipedia.org/wiki/In-place_algorithm in-place]. This can drastically improve performance, because the automapper doesn't copy it's changes into buffer memory before applying it. But it can cause unintended side effects!
 
==Tools==
 
Some tools in order to create automapper rules exist:
* [https://github.com/AssassinTee/SimpleDDNetAutomapper SimpleDDNetAutomapper] - a small UI application, which tries a more user friendly approach for very basic rules and tilesets. It does not support randomness, or <code>POS INDEX</code> rules, but <code>EMPTY</code> and <code>FULL</code>.
* [https://github.com/k2d222/twwe Teeworlds Web Editor] - Automapper edit and live-preview<ref name="twwe">[https://github.com/k2d222/twwe/blob/main/README.md#unique-features Teeworlds web editor unique features]</ref>.
* [https://github.com/Aerll/rpp rpp] - rules++ is a small experiment, aiming to make mappers utterly lazy, by unlocking the full potential of DDNet's rules. It is meant to be simple, readable and most importantly correct, everything else is irrelevant<ref name="rpp">[https://github.com/Aerll/rpp/blob/main/README.md#about rules++ about]</ref>.


==Resources==
==Resources==
<references />

Latest revision as of 08:18, 11 December 2024

The Automapper is a tool to make mapping easier for mappers. Instead of placing the round edges of freeze by hand you could make a simple automapper rule that applies a few rules to a entire tile layer. Every automapper is made for a specific tileset. A tileset can have more than one automapper. All automapper rules are located in your teeworlds path at data/editor/automap/[1][2].

Rules File

There is a tileset.rules textfile for every tileset, that has an automapper. Each tileset.rules file can contains one or more automappers. The rules file loosely follows the INI-file-format. Inside a file every automapper starts with the line [automapper_name]. For example in the file grass_main.rules there is a automapper called Grass it starts at the line [Grass] inside the file. To use it, you have to create a tilelayer with the tileset grass_main in the mapeditor. Rightclick on the layer and click on "Auto map". To start automapping click "Grass".

The filename of the automapper has to follow the filename of the tileset.

Grass automapper[3]:

[Default]
Index 1

#top
Index 16
Pos 0 -1 EMPTY
...

Processing

The automapper will read the rules file. Afterwards it scans each position of the layer. If every rule of a selected tile applies, the tile will be placed at the scanning position of the automapper. If multiple tiles and their rules match, only the latest rule will apply (because it will be overwritten). Unless deactivated, the automapper will put it's changes into a buffer first and apply them afterwards.

Tileset indices overview

Tile indices

Every tileset has 16 rows and 16 columns and each tile can be addressed by its index. The index of a tile is a direct result of it's position and can be calculated by index = 16 * row + column, where row and column is between 0 and 15. The tile at index 0 is always considered EMPTY. Usually this part doesn't contain textures in tilesets. Each other tile is always considered FULL, even if it doesn't contain any textures and is fully transparent.

The index is used for the INDEX keyword of the automapper.

Syntax

Naming your automapper-rule:

Similar to ini-files, you can create your own section for your automapper rule:

[your-automapper-rule]

Multiple index selections followed by rules can be part of a section.

Writing a comment:

#this is a comment

Selecting a tile you want to place:

INDEX 42

This selects tile 42 (meaning the 3rd row and 11th column. Multiple indices can be selected by adding an OR between each index:

INDEX 42 OR 43

Modifying the tile:

Index 42 XFLIP YFLIP ROTATE

XFLIP mirrors the tile vertically and YFLIP mirrors the tile horizontally. ROTATE rotates the tile a single time by 90°.

IF you want to rotate a tile by 180°, you only need to set XFLIP and YFLIP but not ROTATE.

If you want to rotate by 270°, you need to set XFLIP, YFLIP and ROTATE.

Tile modifications are always in the same line as the selection.

Rule for placing the tile:

The selected tile gets placed if all following rules apply. A rule for placing the tile always starts with coordinates followed by a rule:

POS 0 -1 FULL

This rule selects the tile with X coordinate 0 and Y coordinate -1 relative to the scanning position of the automapper. If the tile above the scanning position is FULL, the selected tile will be placed (if all following rules apply). If it's EMPTY, it won't be placed.

Instead of using FULL or EMPTY, you can select another tile with the INDEX keyword:

POS 0 -1 INDEX 12

If the tile above the scanning position has index 12, it will be placed. Multiple indices can be selected by adding an OR between each index:

POS 0 -1 INDEX 12 OR 13

Similarly NOTINDEX can be used to exclude a tile.

Random rule:

You can make a selected tile randomly apply to rules by adding a random rule:

RANDOM 20%

The random rule expects a value between 0% and 100%. This value represents the probability, that a tile is placed[4].

If you put a value into it without a % symbol, the probability will not be parsed in terms of percentages, but with this formula:

percentage = 1.0 / value

This allows for rarer tile placements with probabilities between 0% and 1% and a value > 100.

For example RANDOM 150 will have a probability of 1.0 / 150 ≈ 0.67 (percent).

Default condition rule:

By default the game assumes, that you want to apply each rule to a full tile, meaning that the following rule is always implied:

POS 0 0 FULL

You can deactivate this by adding the following line under the tile selection:

NoDefaultRule

NewRun:

Adding NewRun in a section will make the section run an additional time for each time this keyword gets added to the section. This can be used to set some basic tiles in the first run, and more complex ones in the second.

NoLayerCopy:

Adding NoLayerCopy in a section will cause it to run in-place. This can drastically improve performance, because the automapper doesn't copy it's changes into buffer memory before applying it. But it can cause unintended side effects!

Tools

Some tools in order to create automapper rules exist:

  • SimpleDDNetAutomapper - a small UI application, which tries a more user friendly approach for very basic rules and tilesets. It does not support randomness, or POS INDEX rules, but EMPTY and FULL.
  • Teeworlds Web Editor - Automapper edit and live-preview[5].
  • rpp - rules++ is a small experiment, aiming to make mappers utterly lazy, by unlocking the full potential of DDNet's rules. It is meant to be simple, readable and most importantly correct, everything else is irrelevant[6].

Resources