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

World map compression and encoding #5

Open
djasnowski opened this issue Jan 3, 2018 · 3 comments
Open

World map compression and encoding #5

djasnowski opened this issue Jan 3, 2018 · 3 comments
Labels
canvas (Graphic) issues on the game canvas. core engine Issues on the client-side of the game engine. enhancement When functionality needs to be changed or updated. Hacktoberfest hard Advanced issues that require critical thinking, thought and depth. high priority Things we really want to have and need in the game.
Milestone

Comments

@djasnowski
Copy link
Member

djasnowski commented Jan 3, 2018

Currently, the world map is using arrays. Egads, right?

For even a 200x200 map, that's still a lot of data that can be compressed and encoded and a lot of bytes to save! Ideally, we can do

  • Gzip compression
  • Base64 encoded

And 200x200, or whichever, can be called upon as a nice, compressed string which would be decode and uncompressed. The map editor I am using is Tiled to do the encoding and compression.

There are tons of gzip and base64 libraries on NPM that we can use to get started.


No rush, as I don't see the need for the map to go over 100x100, yet... but there will come a time where this must be done.

@djasnowski djasnowski added canvas (Graphic) issues on the game canvas. core engine Issues on the client-side of the game engine. enhancement When functionality needs to be changed or updated. hard Advanced issues that require critical thinking, thought and depth. low priority Nice-to-have issues and features. labels Jan 3, 2018
@djasnowski djasnowski added high priority Things we really want to have and need in the game. and removed low priority Nice-to-have issues and features. labels Jan 15, 2018
@djasnowski
Copy link
Member Author

Compression and saving bytes is good. This has been moved up to high due to the performance it will bring once the world map (starting at 200) gets going.

@djasnowski djasnowski added this to the v0.0.1 milestone Feb 26, 2018
@djasnowski
Copy link
Member Author

What we'd want to look at is this:

https://developer.mozilla.org/en-US/docs/Games/Techniques/Tilemaps#Performance

Drawing scrolling tile maps can take a toll on performance. Usually, some techniques need to be implemented so scrolling can be smooth. The first approach, as discussed above, is to only draw tiles that will be visible. But sometimes, this is not enough.

One simple technique consists of pre-rendering the map in a canvas on its own (when using the Canvas API) or on a texture (when using WebGL), so tiles don't need to be re-drawn every frame and rendering can be done in just one blitting operation. Of course, if the map is large this doesn't really solve the problem — and some systems don't have a very generous limit on how big a texture can be.

One way consists of drawing the section that will be visible off-canvas (instead of the entire map.) That means that as long as there is no scrolling, the map doesn't need to be rendered.

A caveat of that approach is that when there is a scrolling, that technique is not very efficient. A better way would be to create a canvas that is 2x2 tiles bigger than the visible area, so there is one tile of "bleeding" around the edges. That means that the map only needs to be redrawn on canvas when the scrolling has advanced one full tile — instead of every frame — while scrolling.

In fast games that might still not be enough. An alternative method would be to split the tilemap into big sections (like a full map split into 10 x 10 chunks of tiles), pre-render each one off-canvas and then treat each rendered section as a "big tile" in combination with one of the algorithms discussed above.

Basically, performance wise drawing the canvas offscreen. Or perhaps, draw +3 of all four directions so when they go it, it's already loaded.

@gamecodesolver
Copy link

Compression and saving bytes is good. This has been moved up to high due to the performance it will bring once the world map but unable fix this issue freefx4u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
canvas (Graphic) issues on the game canvas. core engine Issues on the client-side of the game engine. enhancement When functionality needs to be changed or updated. Hacktoberfest hard Advanced issues that require critical thinking, thought and depth. high priority Things we really want to have and need in the game.
Projects
None yet
Development

No branches or pull requests

3 participants
@djasnowski @gamecodesolver and others