rs-tiled icon indicating copy to clipboard operation
rs-tiled copied to clipboard

Tileset helper for obtaining UVs

Open aleokdev opened this issue 3 years ago • 5 comments

Add a function for obtaining the UV of a tile given its ID.

aleokdev avatar Feb 20 '22 16:02 aleokdev

Perhaps it would be a good idea to also create a TileData and make Tile an encapsulation, which would avoid the extra index if the user already had the tile in question.

aleokdev avatar Feb 20 '22 16:02 aleokdev

Perhaps it would be a good idea to also create a TileData and make Tile an encapsulation, which would avoid the extra index if the user already had the tile in question.

I am for this, as it keeps the API flatter and more performant. It means, excluding Tileset and maybe some other types, that the user only needs to talk to the facade types rather than sometimes talking to Type1<'map> and sometimes talking to &'map Type2, which is a little inconsistent. (Perhaps, if the situation changes, Tileset may need its own wrapper, though I don't know of any usecases yet)

I like your suggestion in #164 of just returning a rect measured in pixels. I think we can also add a helper function to this new Tile<'map> type called uvs(flip_y: bool) -> ((f32, f32), (f32, f32)), which can make use of the rect function.

In the helper function:

  • If flip_y is true, then use OpenGL uvs.
  • If flip_y is false, then use DirectX, Metal, Vulkan uvs.

Anti-Alias avatar Feb 20 '22 21:02 Anti-Alias

It means, excluding Tileset and maybe some other types, that the user only needs to talk to the facade types rather than sometimes talking to Type1<'map> and sometimes talking to &'map Type2, which is a little inconsistent.

It would be inconsistent anyways. The lifetime of the suggested Tile facade would be of 'tileset, not map. But yes, the interface is very inconsistent right now, specially in terms of types and properties.

aleokdev avatar Feb 20 '22 21:02 aleokdev

Add a function for obtaining the UV of a tile given its ID.

Just to mention, personally I would find it more suitable to pre-calculate and store the UVs (or rather, the pixel location) of each tile and store it in the TileData. That way the rendering loop doesn't need to keep calculating this based on the margin and spacing and such. But, I guess with TileData wrapped in the public API, it would be possible to add that later as well.

bjorn avatar Mar 01 '22 10:03 bjorn

Postponing to 0.11 since the change is no longer breaking.

aleokdev avatar Mar 01 '22 13:03 aleokdev