Skip to content
Merged
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions cocos/terrain/terrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1815,11 +1815,11 @@ export class Terrain extends Component {
* @zh 获得纹理层
*/
public getLayer (id: number): TerrainLayer | null {
if (id === -1) {
if (id === -1 || id === undefined) {
return null;
}

return this._layerList[id];
return this._layerList[id] ?? null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polyfill of ?? will increase code size a bit.

The following code might have smaller size.

const v = this._layerList[id];
return v !== undefined ? v | null;

}

/**
Expand Down Expand Up @@ -2584,7 +2584,8 @@ export class Terrain extends Component {
const index1 = j * this.blockCount[0] + i;

for (let l = 0; l < TERRAIN_MAX_BLEND_LAYERS; ++l) {
layerBuffer[index0 * TERRAIN_MAX_BLEND_LAYERS + l] = this._layerBuffer[index1 * TERRAIN_MAX_BLEND_LAYERS + l];
const oldVal = this._layerBuffer[index1 * TERRAIN_MAX_BLEND_LAYERS + l];
layerBuffer[index0 * TERRAIN_MAX_BLEND_LAYERS + l] = oldVal !== undefined ? oldVal : -1;
}
}
}
Expand Down
Loading