holywyvern / mv-pixi-upgrade

A base project than uses PIXI V3 and not V2.
Creative Commons Zero v1.0 Universal
13 stars 3 forks source link

Tilemap implementation is laggy #2

Closed holywyvern closed 9 years ago

holywyvern commented 9 years ago

Tilemaps just plain don't work at the moment

holywyvern commented 9 years ago

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 commented 9 years ago

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

ivanpopelyshev commented 9 years ago

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 commented 9 years ago

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

ivanpopelyshev commented 9 years ago

The next step is migrate to pixi.js tilemap.

ivanpopelyshev commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

ivanpopelyshev commented 9 years ago

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 commented 9 years ago

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