Oh, ok. I was looking through your code (I ripped it from the html file) and didn’t notice the default setting. Or what most of it was doing.
But I was thinking of a way to decrease the size of that array yet still retaining the same useful data. I see that in your code you’re using a regular Array that stores “pointers” to each platform. As far as I know, it only uses these pointers to get the class type of the platform. So a memory optimization I suggest is making an array of 4-byte integers, and each element would represent the class type of the platform. You would do this by using a Uint8Array
, then treating the lower and higher half of each byte as a separate element using bitwise operators. I’m sure 16 different recognizable class types is enough.
For example, to initialize the array you would write
this.table = new Uint8Array(Math.ceil(this.maxCol * this.maxRow / 2));
// divide by 2 since each byte holds 2 elements
and to extract the higher and lower 4 bits of each byte you would write
var byte = this.table[i];
var hi = (byte >> 4) & 15;
var lo = byte & 15;