Skip to content

Instantly share code, notes, and snippets.

@danprince
Last active August 29, 2015 14:25
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danprince/7f4174a11378dc29dcd8 to your computer and use it in GitHub Desktop.
Save danprince/7f4174a11378dc29dcd8 to your computer and use it in GitHub Desktop.
Tile Memory Test
<!DOCTYPE html>
<html>
<head>
<!-- Object Format Tests -->
<script src='tiles.js'></script>
<!-- Binary Format Tests -->
<!--<script src='tiles-binary.js'></script>-->
</head>
<body>
</body>
</html>
var MAP_WIDTH = 512,
MAP_HEIGHT = MAP_WIDTH;
function makeTile(type, height, veg) {
var tile = 0;
tile |= type;
tile <<= 8;
tile |= height;
tile <<= 1;
tile |= veg;
return tile;
}
function populateMap(map) {
for(var x = 0; x < map.length; x++) {
for(var y = 0; y < map[x].length; y++) {
map[x][y] = makeTile(
Math.floor(Math.random() * 128),
Math.floor(Math.random() * 100),
Math.round(Math.random())
);
}
}
}
function makeMap(width, height) {
var map = Array(width);
for(var x = 0; x < width; x++) {
map[x] = Array(height);
for(var y = 0; y < height; y++) {
map[x][y] = undefined;
}
}
return map;
}
function init() {
var map = makeMap(MAP_WIDTH, MAP_HEIGHT);
populateMap(map);
setInterval(function() {
console.log('Aint no garbage, gettin collected.');
console.log(void map);
}, 1000);
}
window.addEventListener('load', init);
var MAP_WIDTH = 512,
MAP_HEIGHT = MAP_WIDTH;
function makeTile(type, height, veg) {
return {
type: type,
height: height,
veg: veg
};
}
function populateMap(map) {
for(var x = 0; x < map.length; x++) {
for(var y = 0; y < map[x].length; y++) {
map[x][y] = makeTile(
Math.floor(Math.random() * 10),
Math.random(),
Math.round(Math.random())
);
}
}
}
function makeMap(width, height) {
var map = Array(width);
for(var x = 0; x < width; x++) {
map[x] = Array(height);
for(var y = 0; y < height; y++) {
map[x][y] = undefined;
}
}
return map;
}
function init() {
var map = makeMap(MAP_WIDTH, MAP_HEIGHT);
populateMap(map);
setInterval(function() {
console.log('Aint no garbage, gettin collected.');
console.log(void map);
}, 1000);
}
window.addEventListener('load', init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment