@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
26 lines (20 loc) • 711 B
JavaScript
import { assert } from "../../../../../core/assert.js";
import { split_by_2 } from "../../../../../core/binary/split_by_2.js";
/**
*
* @param {number} mip
* @param {number} x
* @param {number} y
* @returns {number}
*/
export function compose_tile_address(mip, x, y) {
// figure out resolution of this mip level
const mip_resolution = 1 << mip;
assert.lessThan(x, mip_resolution);
assert.lessThan(y, mip_resolution);
// this is basically converting something like 0100 to 0011;
const mip_mask = mip_resolution - 1;
// where data for this mip starts
const index_offset = split_by_2(mip_mask);
return index_offset + x + y * mip_resolution;
}