This repository has been archived by the owner on May 7, 2022. It is now read-only.
Replies: 1 comment 5 replies
-
I'd actually suggest having the TileMapLayer be generic rather than the full map - that would allow you to, for example, have a standard sprite layer and have a layer with additional data on top of it without needing to manage 2 maps. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I started playing around with potential solutions to both #4 and #143. In my mind, these issues are linked by the following idea: a
Tilemap
should simply be a generic container that stores arbitrary objects which are able to return a sprite atlas index and an optional tint color. It is up to the user how much data space should be stored across each tile. For example, users might choose to haveBox
s for larger / dynamically sized data attached to only some tiles (aTileEntity
). It might look something like this:And a user might implement it as
There are a couple problems here (in no particular order):
Perhaps there should be support for having
TileEntity
s as actual Bevy entities so it's easier to interact with them from systems. This would involve spawning and despawning the appropriate entities with the chunks, which would involve some more complicated way of storing tile entites. Probably just each layer could have aHashMap<Point2, SomeTileEntityHandle>
.In order to be useful, the
get_index
must be passed in a reference to theTilemap
or at least a structure containing its neighbors (for autotile support and or more complex use cases). I could see this potentially getting finnicky with the borrow checker which is a good indicator that there might be some more fundamental problems with this sort of architecture.There would need to be some way to cache the render parts obtained from each tile and to regenerate each tile individually if it updates. Similarly there would need to be a way to signal that a tile should be updated. Most probably either a
TileEntity
or a regular old system could issue an Event that a tile should be updated.This sort of data layout is less efficient for conversion to its render parts. Although this is not a big deal if the render parts are only initially calculated on spawn then individually updated per tile update.
We then have the issue with autotiles needing to update if their neighbors change. If we are simply passing in a whole
&Tilemap
toget_index
, then there is no way to know what sort of changes this tile needs to listen for (without some much more complex event listener system). If instead we pass only the neighbors (some sort ofNeighbors
struct), then it is much easier -- we can just callget_index
again for each neighbor tile of an updated tile. But now we're more restricted in what we can do inget_index
. I don't think this is an issue though because I think the vast majority of games only have immediate neighbor-based autotiling systems.I noticed that removing a tile in some cases simply sets its tint alpha to 0 for efficiency reasons. I don't love this approach as it exposes this sort of implementation detail to user implementors of the
Tile
trait. Perhaps afn hide()
with a default implementation is in order?Any thoughts on any of this? Should a different approach be considered? Overall, I like this approach because it makes the tilemap way more flexible for user needs and doesn't assume too much about user use case.
Beta Was this translation helpful? Give feedback.
All reactions