Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/more typescript #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/geometries/Flat.js → src/geometries/Flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import cmp from '../util/cmp';
import type from '../util/type';
import { vec2 as vec2 } from 'gl-matrix';
import { vec4 as vec4 } from 'gl-matrix';
import { Size, Tile } from '../jsdoc-extras';

var neighborsCacheSize = 64;

Expand All @@ -44,6 +45,14 @@ var neighborOffsets = [
* A tile in a {@link FlatGeometry}.
*/
class FlatTile {
x: any;
y: any;
z: any;
_geometry: any;
_level: any;
type = 'flat';
Tile = FlatTile;

constructor(x, y, z, geometry) {
this.x = x;
this.y = y;
Expand Down Expand Up @@ -170,7 +179,7 @@ class FlatTile {
var numX = level.numHorizontalTiles() - 1;
var numY = level.numVerticalTiles() - 1;

var result = [];
var result: Tile[] = [];

for (var i = 0; i < neighborOffsets.length; i++) {
var xOffset = neighborOffsets[i][0];
Expand Down Expand Up @@ -205,10 +214,14 @@ class FlatTile {
return cmp(this.z, that.z) || cmp(this.y, that.y) || cmp(this.x, that.x);
}
str() {
return 'FlatTile(' + tile.x + ', ' + tile.y + ', ' + tile.z + ')';
return 'FlatTile(' + this.x + ', ' + this.y + ', ' + this.z + ')';
}
}
class FlatLevel extends Level {
_width: any;
_height: any;
_tileWidth: any;
_tileHeight: any;
constructor(levelProperties) {
super(levelProperties);

Expand All @@ -229,6 +242,8 @@ class FlatLevel extends Level {
tileHeight() {
return this._tileHeight;
}
// TODO: figure out if it's better to return something
// @ts-ignore
_validateWithParentLevel(parentLevel) {
var width = this.width();
var height = this.height();
Expand Down Expand Up @@ -301,6 +316,14 @@ class FlatLevel extends Level {
* square tiles
*/
class FlatGeometry {
levelList: any[];
selectableLevelList: unknown[];
_tileSearcher: TileSearcher;
_neighborsCache: LruMap;
_vec: vec4;
_viewSize: Size;
static Tile: typeof FlatTile;
static type: string;
constructor(levelPropertiesList) {
if (type(levelPropertiesList) !== 'array') {
throw new Error('Level list must be an array');
Expand All @@ -313,13 +336,13 @@ class FlatGeometry {
this.levelList[i]._validateWithParentLevel(this.levelList[i - 1]);
}

this._tileSearcher = new TileSearcher(this);
this._tileSearcher = new TileSearcher();

this._neighborsCache = new LruMap(neighborsCacheSize);

this._vec = vec4.create();

this._viewSize = {};
this._viewSize = { width: 0, height: 0 };
}
maxTileSize() {
var maxTileSize = 0;
Expand Down Expand Up @@ -394,8 +417,13 @@ class FlatGeometry {
}
}

// TODO: remove these when exports are used
// @ts-ignore
FlatGeometry.Tile = FlatGeometry.prototype.Tile = FlatTile;
// @ts-ignore
FlatGeometry.type = FlatGeometry.prototype.type = 'flat';
// @ts-ignore
FlatTile.type = FlatTile.prototype.type = 'flat';

export { FlatTile };
export default FlatGeometry;
12 changes: 10 additions & 2 deletions src/renderers/WebGlBase.js → src/renderers/WebGlBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ var uniformList = [
];

class WebGlBaseRenderer {
constructor(gl) {
gl: any;
projMatrix: mat4;
viewportMatrix: mat4;
translateVector: vec3;
scaleVector: vec3;
constantBuffers: { vertexIndices: any; vertexPositions: any; textureCoords: any; };
shaderProgram: any;

constructor(gl: WebGLRenderingContext) {
this.gl = gl;

// The projection matrix positions the tiles in world space.
Expand Down Expand Up @@ -125,7 +133,7 @@ class WebGlBaseRenderer {
colorMatrix: shaderProgram.uColorMatrix,
});
}
endLayer(layer, rect) {
endLayer() {
var gl = this.gl;
var shaderProgram = this.shaderProgram;
disableAttributes(gl, shaderProgram);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var scaleVector = vec3.create();
// Therefore, when the scene's rect is not fully contained in the rendering
// area, we clamp the viewport to the rendering area, and return a compensation
// matrix to scale and translate vertices accordingly.
function setViewport(gl, layer, rect, viewportMatrix) {
function setViewport(gl, _layer, rect, viewportMatrix) {
if (rect.x === 0 && rect.width === 1 && rect.y === 0 && rect.height === 1) {
// Fast path for full rect.
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/WebGlCube.js → src/renderers/WebGlCube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import WebGlBaseRenderer from './WebGlBase';
* destroyed by {@link Stage} as necessary.
*/
class WebGlCubeRenderer extends WebGlBaseRenderer {
constructor(...args) {
super(...args);
constructor(gl: WebGLRenderingContext) {
super(gl);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ var uniformList = [
* destroyed by {@link Stage} as necessary.
*/
class WebGlEquirectRenderer {
constructor(gl) {
gl: any;
invProjMatrix: mat4;
viewportMatrix: mat4;
constantBuffers: { vertexIndices: any; vertexPositions: any; textureCoords: any; };
shaderProgram: any;
constructor(gl: WebGLRenderingContext) {
this.gl = gl;

// The inverse projection matrix.
Expand Down Expand Up @@ -144,12 +149,12 @@ class WebGlEquirectRenderer {
colorMatrix: shaderProgram.uColorMatrix,
});
}
endLayer(layer, rect) {
endLayer() {
var gl = this.gl;
var shaderProgram = this.shaderProgram;
disableAttributes(gl, shaderProgram);
}
renderTile(tile, texture, layer, layerZ) {
renderTile(tile, texture, _layer, layerZ) {
var gl = this.gl;
var shaderProgram = this.shaderProgram;
var constantBuffers = this.constantBuffers;
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/WebGlFlat.js → src/renderers/WebGlFlat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import WebGlBaseRenderer from './WebGlBase';
* destroyed by {@link Stage} as necessary.
*/
class WebGlFlatRenderer extends WebGlBaseRenderer {
constructor(...args) {
super(...args);
constructor(gl: WebGLRenderingContext) {
super(gl);
}
}

Expand Down