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

Big tilemap/map rework #861

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

Daft-Freak
Copy link
Collaborator

TileMaps being slow and a bit hard to use finally annoyed me enough... Requires 32blit/32blit-tools#105 for layer names.

Adds a new TiledMap, which covers most of the functionality of TileMap and Map. (TileMap is kept as a deprecated alias of what is now TransformedTileLayer for some level of compatibility)

New features:

  • Can load the 16-bit tile output from the tools
  • Also improved handling of multiple layers (don't need to load_tmx each layer, layer names from Tiled)
  • Easier (and much faster) support of just scrolling a map
  • Removes the power of two bounds and 16 column tileset restrictions unless you specifically request the transformed variant (TiledMap(..., LAYER_TRANSFORMS))
  • Doesn't leak memory (at least, if the map allocated it)
  • Supports loading maps from files as well as embedded assets

Most basic usage is:

sprites = Surface::load(asset_tileset);
map = new TiledMap(asset_tilemap, sprites);
...
map->set_scroll_position(scroll_position);
...
map->draw();

But also:

// from a file
map = new TiledMap("tilemap.blah", sprites);
// remove COPY_TILES/COPY_TRANSFORMS flags (read-only, less ram)
map = new TiledMap(asset_tilemap, sprites, 0);
// old TileMap behaviour, more restrictions, scanline transforms supported (+ anything other than a translate in general)
map = new TiledMap(asset_tilemap, sprites, COPY_TILES | COPY_TRANSFORMS | LAYER_TRANSFORMS);

For the affected examples:

  • flight is now significantly faster (22 -> 12 ms)
  • platformer is a little faster (38 -> 36ms)
  • raycaster and tilemap-test are about the same

Anything that used Map probably also has a lower memory usage during init due to less copying vectors around.

Has a circular dependency on the examples branch that ports everything. (Deleted the Map code, can't find any uses outside of the three examples using it)

Shouldn't be a breaking change as I can't find anything outside the SDK using these
... and some more helpers for common cases. Will improve naming Soon(TM)
In preparation for "fancy" and "un-fancy" variants
With an alias for compat
… power-of-two restriction for non-transformed
TransformedTileLayer::texture_span is now templated to not lose perf
This is used by the mode7 code (or would be if it used this class).
... and make texture_span more compatible with the old code, plus consistent with mipmap_texture_span
Don't bother drawining next mip level if alpha is 0
Will be useful for lua/other interpreters that can't easily embed assets
Requires a tools patch to generate them
Apparently only some of my VS Code installs have the editorconfig plugin...
Breaks flight example for now
... but with less vectors
I'm not aware of anything outside the examples ever using this
This now uses level 0 for a 1:1 scale and seems to end up faster (probably due to not blending when not scaled/slightly scaled up)
@Gadgetoid
Copy link
Contributor

Niiice! I should drag my brain kicking and screaming back into the world of the productive and try to port Rocks & Diamonds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants