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

addedAll event incorrectly emitted for *each* texture when loading 2nd pack #2

Closed
deathcap opened this issue Apr 10, 2014 · 2 comments
Labels

Comments

@deathcap
Copy link
Member

Test with game-shell-voxel, press P to invoke voxel-artpacks UI, drag another pack (MC175.zip) into the list -> the pack reloads very slowly, because voxel-stitch is emitting the addedAll event for each and every texture loaded.

It is supposed to only emit when all of the pending textures have loaded, so gl-tile-map can calculate all the mipmaps quickly all at once (instead of recalculating continuously). To do this it maintains this.countLoading and this.countLoaded, loading set to textureNames.length in stitch(), and loaded incremented in each addTexturePixels() (async callback from addTextureName, from artpacks getTextureNdarray). If loaded >= loading, then addedAll is emitted; loading isn't being reset for some reason so this condition is always true for all the textures loaded in the second pack.

@deathcap
Copy link
Member Author

Use https://github.com/caolan/async#each? Calls back when all of the function calls (for each iterated element) complete. Instead of:

for (var j = 0; j < textureNames.length; j += 1) {
var textureName = textureNames[j];

this.addTextureName(textureName, this.nextY, this.nextX);
this.incrementSlot();

}

Something like: async.each(textureNames, function(name, done) { // include Y, X in item
self.addTextureName(name); // pass and call done()

@deathcap
Copy link
Member Author

Changed to use async module on 'async' branch but curiously, loading a second pack fails with "Callback was already called.", at:

this.artpacks.getTextureNdarray(textureName, function(pixels) {
  console.log('addTextureName callback',textureName,'calling addTexturePixels',tileY,tileX);
  self.addTexturePixels(pixels, tileY, tileX);
  callback(); // here

something broken with getTextureNdarray()?

deathcap added a commit to deathcap/artpacks that referenced this issue Apr 14, 2014
deathcap added a commit to deathcap/artpacks that referenced this issue Apr 14, 2014
This reverts commit e48be215d1ca1b4f5c88ec62fa7a7fd9fbbf32ab.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant