Skip to content
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
8 changes: 4 additions & 4 deletions src/CompositeTilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export class CompositeTilemap extends Container
* The animation frame vector specifies which animation frame texture to use. If the x/y coordinate is
* larger than the `animCountX` or `animCountY` for a specific tile, the modulus is taken.
*/
public tileAnim: [number, number] = null;
public tileAnim: [number, number] | null = null;

/** The last modified tilemap. */
protected lastModifiedTilemap: Tilemap = null;
protected lastModifiedTilemap: Tilemap | null = null;

private modificationMarker = 0;
// private shadowColor = new Float32Array([0.0, 0.0, 0.0, 0.5]);
Expand All @@ -103,7 +103,7 @@ export class CompositeTilemap extends Container
*
* @param tileTextures - The list of tile textures that make up the tileset.
*/
tileset(tileTextures: Array<TextureSource>): this
tileset(tileTextures?: Array<TextureSource>): this
{
if (!tileTextures)
{
Expand Down Expand Up @@ -233,7 +233,7 @@ export class CompositeTilemap extends Container
} = {}
): this
{
let tilemap: Tilemap = null;
let tilemap: Tilemap | null = null;
const children = this.children;

this.lastModifiedTilemap = null;
Expand Down
6 changes: 3 additions & 3 deletions src/TileTextureArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export class TileTextureArray
count = 0;
dirty = false;
dirty_gpu = false;
bind_group: BindGroup = null;
bind_group: BindGroup | null = null;
bind_group_resources: any = {};
tex_sizes: Float32Array = null;
tex_sizes: Float32Array;
null_color: Float32Array = new Float32Array([0, 0, 0, 0.5]);
tex_buf: Buffer = null;
tex_buf: Buffer;

get length()
{
Expand Down
16 changes: 8 additions & 8 deletions src/Tilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Tilemap extends ViewContainer
*
* @see CompositeTilemap.tileAnim
*/
public tileAnim: [number, number] = null;
public tileAnim: [number, number] | null = null;

/**
* This is the last uploaded size of the tilemap geometry.
Expand Down Expand Up @@ -134,7 +134,7 @@ export class Tilemap extends ViewContainer
this._bounds.maxY = bounds.maxY;
}

public batched: boolean;
public batched = false;

/**
* @param tileset - The tileset to use for the tilemap. This can be reset later with {@link Tilemap.setTileset}. The
Expand Down Expand Up @@ -401,10 +401,10 @@ export class Tilemap extends ViewContainer
}

private vbId = 0;
vb: TilemapGeometry = null;
private vbBuffer: ArrayBuffer = null;
private vbArray: Float32Array = null;
private vbInts: Uint32Array = null;
vb: TilemapGeometry | null = null;
private vbBuffer: ArrayBuffer | null = null;
private vbArray: Float32Array | null = null;
private vbInts: Uint32Array | null = null;

private destroyVb(): void
{
Expand Down Expand Up @@ -459,8 +459,8 @@ export class Tilemap extends ViewContainer
this.vbInts = new Uint32Array(this.vbBuffer);
}

const arr = this.vbArray;
const ints = this.vbInts;
const arr = this.vbArray ?? new Float32Array(this.vbBuffer);
const ints = this.vbInts ?? new Uint32Array(this.vbBuffer);
let sz = 0;
let textureId = 0;

Expand Down
10 changes: 5 additions & 5 deletions src/TilemapPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export class TilemapPipe implements RenderPipe<Tilemap>, InstructionPipe<Tilemap
private ibLen = 0;// index buffer length

/** The index buffer for the tilemaps to share. */
private indexBuffer: Buffer = null;
private readonly indexBuffer: Buffer;

/** The shader used to render tilemaps. */
private shader: TilemapGeometry;
private shader: TilemapGeometry | null = null;

private adaptor: TilemapAdaptor;

Expand Down Expand Up @@ -98,7 +98,7 @@ export class TilemapPipe implements RenderPipe<Tilemap>, InstructionPipe<Tilemap
}

/** @return The {@link TilemapGeometry} shader that this rendering pipeline is using. */
getShader(): TilemapGeometry { return this.shader; }
getShader(): TilemapGeometry | null { return this.shader; }

destroy(): void
{
Expand Down Expand Up @@ -130,7 +130,7 @@ export class TilemapPipe implements RenderPipe<Tilemap>, InstructionPipe<Tilemap

destroyRenderable(_renderable: Tilemap): void
{
_renderable.vb.destroy(true);
_renderable.vb?.destroy(true);
_renderable.vb = null;
}

Expand All @@ -142,7 +142,7 @@ export class TilemapPipe implements RenderPipe<Tilemap>, InstructionPipe<Tilemap
tilemap.checkValid();
tilemap.getTileset().update();

if (tilemap.is_valid)
if (tilemap.is_valid && instructionSet)
{
batcher.break(instructionSet);
instructionSet.add(tilemap._instruction);
Expand Down
8 changes: 5 additions & 3 deletions src/gl_tilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export class GlTilemapAdaptor extends TilemapAdaptor
name: 'tilemap',
} as const;

_shader: Shader = null;
_shader: Shader | null = null;
max_textures: number = settings.TEXTURES_PER_TILEMAP;

destroy(): void
{
this._shader.destroy(true);
this._shader?.destroy(true);
this._shader = null;
}

Expand All @@ -83,7 +83,7 @@ export class GlTilemapAdaptor extends TilemapAdaptor
const shader = this._shader;
const tileset = tilemap.getTileset();

const tu = shader.resources.texture_uniforms;
const tu = shader?.resources.texture_uniforms;

if (tu.uniforms.u_texture_size !== tileset.tex_sizes)
{
Expand All @@ -96,6 +96,8 @@ export class GlTilemapAdaptor extends TilemapAdaptor
renderer.texture.bind(tileset.arr[i], i);
}

if (!shader || !tilemap.vb) return;

renderer.encoder.draw({
geometry: tilemap.vb,
shader,
Expand Down
22 changes: 17 additions & 5 deletions src/gpu_tilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,37 @@ export class GpuTilemapAdaptor extends TilemapAdaptor
name: 'tilemap',
} as const;

_shader: Shader = null;
_shader: Shader | null = null;
max_textures: number = settings.TEXTURES_PER_TILEMAP;
bind_group: BindGroup = null;
bind_group: BindGroup | null = null;

destroy(): void
{
this._shader.destroy(true);
this._shader?.destroy(true);
this._shader = null;
}

execute(pipe: TilemapPipe, tilemap: Tilemap): void
{
const renderer = pipe.renderer;
const shader = this._shader;

if (!shader || !tilemap.vb) return;

// GPU..

shader.groups[0] = renderer.globalUniforms.bindGroup;
shader.groups[1] = tilemap.getTileset().getBindGroup();
shader.groups[2] = this.bind_group;

const tilesetBindGroup = tilemap.getTileset().getBindGroup();

if (tilesetBindGroup)
{
shader.groups[1] = tilesetBindGroup;
}
if (this.bind_group)
{
shader.groups[2] = this.bind_group;
}

renderer.encoder.draw({
geometry: tilemap.vb,
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "@pixi/extension-scripts/tsconfig",
"compilerOptions": {
// TODO: Remove this when null checks are strict
"strictNullChecks": false
"strictNullChecks":true
},
"include": [
"src/**/*"
Expand Down