Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Jesse

This class compresses level data so that it's much smaller. I can't put a number on the level of compression, but it seems to be about 5% of the original size, only because the level has so many entities taking up space . Entities are now the only costly occurrence in a level file as far as filesize goes.

The plugin looks for repeated values in the data and then shortens the data by formatting it in a way that any repeated values are stored as a repetitive value. The algorithm that is coded into this plugin is based on RLE, or run-length encoding.

To use this plugin, you need to add one line of code into Weltmeister so that it can save and load compressed levels. Then you need to add a line to your game&039;s #init function so that the loadLevel method is overridden (by this plugin, automatically) and compressed levels can be detected and then loaded.

You do not have to compress all of your levels in your game if you want to use this plugin, the code knows the difference between compressed and not compressed.

To install in a Game class, put this in the init function


ig.MapMinifier.enableForGame();


To install in Weltmeister, put this in Weltmeister&039;s #init function:


ig.MapMinifier.enableForWeltmeister();


View the source

1 decade ago by paularmstrong

Is 5% savings really worth the effort to have this at all? -- On a 15KB level, you're only saving 750 bytes.

1 decade ago by Jesse

It's not 5% savings, it's 5% - 10% of original size.

It turned a 116 KB level into 11 KB. It turned 40 KB levels into 5 KB. It will take a map that normally takes up tens of thousands of characters and convert it to a something that takes something like a couple hundred.

It all depends how many repeated tiles there are in your maps. Large spaces in a map and repetitive sections of the same tile are what drive the space savings of this RLE compressor. It's better to say that there are 50 of the same tile in a row using 5 bytes instead of 100.

If space and loading speed is a concern to all you game devs out there, and it should be, then this is something you should try because this makes a huge difference.

1 decade ago by Hareesun

I'll be totally honest. That's damn impressive and I wouldn't be surprised if Dominic works something like that in as standard.

1 decade ago by paularmstrong

Quote from Jesse
It's not 5% savings, it's 5% - 10% of original size.


Ah... once again, I read a post incorrectly :)

Unfortunately, my maps do not have very many repeated tiles.

1 decade ago by fugufish

this is amazing!

naysayers, they don't understand the importance of filesize in game dev :D

1 decade ago by dominic

That is indeed pretty impressive! I never thought about RLE compression for the levels. It could work especially well for the collision maps.

However, the size difference is not that big anymore, if you configure your host to send .js files gzipped. E.g. Biolab's .js file is only 46kb (220kb uncompressed). But if you have a lot of big levels, this RLE compression is certainly a big improvement. Nice work :)

1 decade ago by nutbutter

To make this work for Box2D games you need to add the following line to the ig.MapMinifier.enableForGame function in the map-minifier plugin.

if (ig.Box2DGame) ig.Game = ig.Box2DGame;

1 decade ago by monkeyArms

I was just thinking about writing something like this yesterday - glad I found this thread.

This is really, really nice, especially for development - I'm working on a giant map that was saving at around 162kb, and this plugin got it down to 4k. It also saves out of Welmeister approximately 10 times faster, and the game load much faster as well (I was already using gzip compression).

Big kudos, Jesse.

1 decade ago by PaulManjarres

HI,
i was trying to use this plugin, that would really come in handy for me, but I'm having problems in the Weltmeister. When i try to load a level I'm getting this error:

Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'toJSON' 

map-minifier.js:254

When I check the plugin file, the line is:
this.parent($.toJSON(pj)); 

Do i need a dependency to run this plugin?.

Thanks!.

1 decade ago by PaulManjarres

In order to fix the problem that I'm mentioning, my solution was to modify the method: ig.MapMinifier.enableForWeltmeister

	//this.parent($.toJSON(pj));
	this.parent(JSON.stringify(pj));

I found another problem, in order to use this plugin with a Box2dGame class, is better to change the enableForGame method like this.

ig.MapMinifier.enableForGame = function() {
        if (ig.MapMinifier.isGameEnabled) {
            return;
        }
        ig.MapMinifier.isGameEnabled = true;
        // Select the appropiate class to inject
        var game = ig.Box2DGame ? ig.Box2DGame : ig.Game; 
        game.inject({
            loadLevel: function(level) {
                for (var i = 0; i < level.layer.length; i++) {
                    ig.MapMinifier.decompressLayer(level.layer[i]);
                }
                this.parent(level);
            }
        });
    };

Otherwise, you'll break the ability to call ig.system.setGame() from a Box2dGame class.
Page 1 of 1
« first « previous next › last »