Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Metatiles #1421

Open
not-surt opened this issue Dec 28, 2016 · 10 comments

Comments

@not-surt
Copy link

commented Dec 28, 2016

Metatiles or Chunks are a single tilemap cell indexing a fixed-size block of tiles rather than just a single tile.
Functions both as a convenience for the developer and as a form of memory compression.

Metatiles were common in games on old memory limited tile-based hardware such a the 8/16-bit consoles. eg. Sonic the Hedgehog used 128x128 pixel metatiles composed of 16x16 8x8 pixel tiles.

Implement a MetaTileSet which takes a TileMap and metatile size in the place of the image and tile size of a regular TileSet and draw the metatile inplace of a single tile.
Ideally a MetaTileSet would be able to take a TileMap that in turn uses another MetaTileSet for multiple levels of metatile scale.

This would make Tiled much more friendly toward working within the limitations of older systems.

eg. NES-like use case:
NES uses 8x8 pixel hardware tiles, a game may use 16x16 pixel (2x2 hardware tile) metatiles.
Hardware TileSet: Regular TileSet for 8x8 pixel hardware tiles. Draws 8x8 pixel block from image for each tile.
Metatile TileMap: Regular TileMap for metatile tile data, using Hardware TileSet for tiles. Each 2x2 tile sector of Metatile TileMap defines a metatile.
Metatile TileSet: New MetaTileSet for 16x16 pixel metatiles. Has 2x2 metatile size. Draws 2x2 tile block from Metatile TileMap for each tile.
Level TileMap: Regular TileMap for game level, using Metatile TileSet for tiles.

@bjorn bjorn added the bounty label Dec 28, 2016

@not-surt

This comment has been minimized.

Copy link
Author

commented Jan 1, 2017

I've just thought now that this could also be used as a means to allow multilayer tiles, if the MetaTileSet's TileMap contains multiple layers.

@bjorn bjorn added the feature label Jan 2, 2017

@bjorn

This comment has been minimized.

Copy link
Owner

commented Jan 16, 2017

I think the idea is very interesting, but I'm not sure about how to execute it. In your example use-case, the metatiles in a single metatile-tileset would all need to use the same dimensions. Was that done to keep things simple or because the hardware worked in a similar way? It seems to me that in general, people may expect more flexibility.

Tiled already has a feature to store away chunks of tiles to make placement of multi-tile areas easier, which are called Tile Stamps. But it works only on the editor level, while keeping the tile map in the usual format. Maybe the Tile Stamps feature could be extended somehow to allow placement of a stamp to create a reference to the stamp as metatile in a metatile-tileset. But in that case I'm having some difficulty imagining how the various metatiles used on a map are managed and stored.

It's maybe interesting to consider, that when implemented as you described, it could also form the basis of supporting RPG Maker terrain transitions (#1022).

@not-surt

This comment has been minimized.

Copy link
Author

commented Jan 16, 2017

Metatiles/chunks use fixed sizes for the all the same reasons as regular tiles.
Without fixed sizes the grid becomes essentially meaningless, without the grid you lose all convenience of exact and regular placement.
If you want something that's freely placed and varying sized then that's something else altogether.

@bjorn

This comment has been minimized.

Copy link
Owner

commented Jan 16, 2017

@not-surt Alright, makes sense. Indeed, having fixed sizes reduces a lot the amount of data that needs to be stored as well as the amount of work required to set it up.

I could definitely imagine implementing such a thing, though I'd like to finish Tiled 1.0 first. Thanks for setting a bounty on the issue though! Maybe somebody else will notice the Bounty in the meantime, or I will eventually get around to it when 1.0 is done.

@no-identd

This comment has been minimized.

Copy link

commented Jan 24, 2019

Sounds like metatiling represents an instance of either:

or:

(See also https://en.wikipedia.org/wiki/Prototile)

@Phlosioneer

This comment has been minimized.

Copy link
Contributor

commented May 22, 2019

I'd like to tackle this problem. Before I start, though, here's what it would look like:

  • In the current spec, <tileset> tags can either have a "source" attribute or have a <data> tag to specify an image. I would like to add the <map> tag as a way to specify an image.
  • A <map> tag nested this way cannot include <objectlayer>s.
  • The rendered map is used as the "image" that the tileset uses.
  • An additional restriction is that the nested map's tilewidth and tileheight must be an even divisor of the tileset's tilewidth and tileheight.
  • The nested map tag may use a "source" attribute to refer to an external map file.

This setup has a few nice properties:

  • It allows the full power of the layer system to be used.
  • It allows images to be mixed with tiles via imagelayers.
  • It allows the inner tilesets to be defined using <tileset> tags themselves, which allows for arbitrary tileset nesting.
  • It allows the UI for metatile editing to work simply: instead of using an image file, we just render the source map into an image, and then everything works the exact same in the UI.
  • The UI for embedding the external map can just use a checkbox, much like the existing tileset-embedding option
  • Transparency, tile rotation, and all that nice stuff is supported for free.
  • Because the inner map's tiles must be an even divisor, parsers can use shortcuts while storing tile info. Given a tile in the metatile set, it's trivial to find the square nested-tiles that compose it. For example, if the outer tileset has tilewidth=16, tileheight=16, and the inner tileset has tilewidth=4, tileheight=4, then the parser can choose to store the tiles in a 16-length array for quick lookups.
  • Inner tilesets can be image collections, embedded, or external, without additional effort.
  • Multiple tilesets can be used, without extra effort.
  • The <group> tag works as expected for grouping layers.

I'm not familiar with the tiled codebase. However, I don't think this would be a difficult thing to implement, because it leverages existing components.

I'm asking here before I do anything to see if there's interest in this approach, and if people have ideas to add or critiques.

@bjorn

This comment has been minimized.

Copy link
Owner

commented Aug 23, 2019

@Phlosioneer That definitely sounds like a doable approach. I would only say, that the map referenced by the tileset should never be stored embedded, but needs to be an external map file. That is because the option to embed tilesets is really causing a lot of painful edge-cases and I'd really want to avoid dealing with similar issues with maps embedded in tilesets.

Sorry for the late reply. I had written one before but it was lost when I closed my browser. It took me much too long to get back to this topic.

See also the recent related discussion on the Tiled Forum.

@Phlosioneer

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2019

Thanks for the reply! I'm still interested in doing this. I'll start poking around in the Tiled codebase to see what I can do.

Also, @bjorn , I don't see any bounties for this issue on https://www.bountysource.com/teams/tiled/bounties ? Unless I'm misunderstanding what the bounty tag means.

@Phlosioneer

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2019

I am not able to set up a coding environment. I'm getting error messages like Module "Qt.core" cannot be loaded, same for .gui and others. It's a Qbs configuration issue somewhere. There's no online help or documentation about the issue, and I've tried re-installing. The .pro file doesn't work for windows, so I can't build anything.

So I won't be working on this feature.

@bjorn bjorn removed the bounty label Aug 28, 2019

@bjorn

This comment has been minimized.

Copy link
Owner

commented Aug 28, 2019

Also, @bjorn , I don't see any bounties for this issue on https://www.bountysource.com/teams/tiled/bounties ? Unless I'm misunderstanding what the bounty tag means.

Well, I'm quite sure there was a $50-100 bounty from @not-surt on this feature, but it appears to have disappeared. It's weird how Bountysource seems to show no record of this at all.

I am not able to set up a coding environment. I'm getting error messages like Module "Qt.core" cannot be loaded, same for .gui and others. It's a Qbs configuration issue somewhere. There's no online help or documentation about the issue, and I've tried re-installing. The .pro file doesn't work for windows, so I can't build anything.

So I won't be working on this feature.

Hmm, did you try following the Contributing to Tiled page? Where did it go wrong? I realize the qmake command-line instructions are outdated, but using the Qt installer to install Qt Creator and some recent Qt version (either MinGW or Visual Studio based) should definitely just work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.