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

Tilemap implementation is laggy #2

Closed
holywyvern opened this issue Oct 25, 2015 · 10 comments
Closed

Tilemap implementation is laggy #2

holywyvern opened this issue Oct 25, 2015 · 10 comments
Labels
bug

Comments

@holywyvern
Copy link
Owner

@holywyvern holywyvern commented Oct 25, 2015

Tilemaps just plain don't work at the moment

@holywyvern
Copy link
Owner Author

@holywyvern holywyvern commented Oct 25, 2015

It's laggy, but it works, even at 50-40 fps on my pc with hardware acceleration.
So it's fine if this works... but still open.

@holywyvern holywyvern changed the title Tilemap implementation is completely broken Tilemap implementation is laggy Oct 26, 2015
@holywyvern
Copy link
Owner Author

@holywyvern holywyvern commented Oct 26, 2015

The implementation lags a lot event at small maps, but it works.

@ivanpopelyshev
Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev commented Oct 28, 2015

Look at that

Bitmap.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
    dw = dw || sw;
    dh = dh || sh;
    if (sx >= 0 && sy >= 0 && sw > 0 && sh > 0 && dw > 0 && dh > 0 &&
            sx + sw <= source.width && sy + sh <= source.height) {
        this._context.globalCompositeOperation = 'source-over';
        this._context.drawImage(source._canvas, sx, sy, sw, sh, dx, dy, dw, dh);
        this._setDirty();
    }
};

aaaand lets change source._canvas to source._image || source._canvas:

Bitmap.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
    dw = dw || sw;
    dh = dh || sh;
    if (sx >= 0 && sy >= 0 && sw > 0 && sh > 0 && dw > 0 && dh > 0 &&
            sx + sw <= source.width && sy + sh <= source.height) {
        this._context.globalCompositeOperation = 'source-over';
        this._context.drawImage(source._image || source._canvas, sx, sy, sw, sh, dx, dy, dw, dh);
        this._setDirty();
    }
};

Chrome v46: 5-10x performance boost in Tilemap._drawAutoTile.
Didnt test in other browsers, but that's optimization that I use in gameofbombs.com for 2 years.

@ivanpopelyshev
Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev commented Oct 28, 2015

Ok, in this test its only 2.5x in chrome: http://jsperf.com/tilemap-optimization . I saw 5x-10x in chrome profiler.

@ivanpopelyshev
Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev commented Oct 29, 2015

The next step is migrate to pixi.js tilemap.

@ivanpopelyshev
Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev commented Oct 29, 2015

Ok, now I see that rpgmaker uses very specific tilemaps, which are more close to gameofbombs.com model than tiled. Im going to port my implementation :)

@holywyvern
Copy link
Owner Author

@holywyvern holywyvern commented Oct 29, 2015

The problem may be that if you edit the bitmap after loading (almost nobody does that anyway) The blt won't reflect changes if I'm not mistaken.
This may not be the problem about tilemap, because tilemap right now only draw the tileset once inside a bigger texture

@ivanpopelyshev
Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev commented Oct 29, 2015

Yep. I used that approach too, I changed some canvases just after loading the image. Now I use pre-generated stuff :)

@ivanpopelyshev
Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev commented Oct 29, 2015

I looked at other performance problems, and I dont like it at all. They actually do things like "traits.filter(...).filter(...)" directly in the rendering loop, its awful :(

@ivanpopelyshev
Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev commented Nov 4, 2015

Ok, it is fixed. We have "ShaderTilemap" plugin. For performance reasons I use vanilla implementation for canvas fallback.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.