Skip to content

Commit ab55f97

Browse files
committed
Merge branch 'Master3.0' of https://github.com/layabox/LayaAir into Master3.0
2 parents 65c83ad + 6006dc4 commit ab55f97

20 files changed

+1366
-151
lines changed

src/layaAir/laya/Light2D/Light2DConfig.ts

+24-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@ import { Vector3 } from "../maths/Vector3";
55
* 2D灯光全局配置参数
66
*/
77
export class Light2DConfig {
8-
lightDirection: Vector3 = new Vector3(-1, 0, 1); //灯光方向矢量(影响法线效果)
9-
ambientColor: Color = new Color(0.2, 0.2, 0.2, 0); //环境光颜色
10-
ambientLayerMask: number = -1; //环境光影响的层(默认影响所有层)
11-
multiSamples: number = 4; //光影图多重采样数(1或4,影响阴影边缘锯齿)
8+
9+
/**
10+
* @en Light direction vector (affects normal effect)
11+
* @zh 灯光方向矢量(影响法线效果)
12+
*/
13+
lightDirection: Vector3 = new Vector3(-1, 0, 1);
14+
15+
/**
16+
* @en ambient light color
17+
* @zh 环境光颜色
18+
*/
19+
ambientColor: Color = new Color(0.2, 0.2, 0.2, 0);
20+
21+
/**
22+
* @en Layers affected by ambient light (affects all layers by default)
23+
* @zh 环境光影响的层(默认影响所有层)
24+
*/
25+
ambientLayerMask: number = -1;
26+
27+
/**
28+
* @en Light and shadow map multisampling number (1 or 4, affects jagged shadow edges)
29+
* @zh 光影图多重采样数(1或4,影响阴影边缘锯齿)
30+
*/
31+
multiSamples: number = 4;
1232
}

src/layaAir/laya/Light2D/Light2DManager.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export class Light2DManager implements IElementComponentManager, ILight2DManager
5656
lsTargetSub: RenderTexture[] = []; //渲染目标(光影图),数量等于有灯光的层数,相减模式
5757
occluderAgent: Occluder2DAgent; //遮光器代理,便捷地创建和控制遮光器
5858

59-
private _config: Light2DConfig; //2D灯光全局配置
59+
static _config: Light2DConfig = new Light2DConfig(); //2D灯光全局配置
6060
get config(): Light2DConfig {
61-
return this._config;
61+
return Light2DManager._config;
6262
}
6363
set config(value: Light2DConfig) {
64-
this._config = value;
64+
Light2DManager._config = value;
6565
for (let i = this._updateMark.length - 1; i > -1; i--)
6666
this._updateMark[i]++;
6767
}
@@ -128,11 +128,11 @@ export class Light2DManager implements IElementComponentManager, ILight2DManager
128128
constructor(scene: Scene) {
129129
if (PlayerConfig.light2D) {
130130
let light2DConfig = PlayerConfig.light2D;
131-
this._config = new Light2DConfig();
132-
this._config.ambientColor = new Color(light2DConfig.ambientColor.r, light2DConfig.ambientColor.g, light2DConfig.ambientColor.b, light2DConfig.ambientColor.a);
133-
this._config.ambientLayerMask = light2DConfig.ambientLayerMask;
134-
this._config.lightDirection = new Vector3(light2DConfig.lightDirection.x, light2DConfig.lightDirection.y, light2DConfig.lightDirection.z);
135-
this._config.multiSamples = light2DConfig.multiSamples;
131+
Light2DManager._config = new Light2DConfig();
132+
Light2DManager._config.ambientColor = new Color(light2DConfig.ambientColor.r, light2DConfig.ambientColor.g, light2DConfig.ambientColor.b, light2DConfig.ambientColor.a);
133+
Light2DManager._config.ambientLayerMask = light2DConfig.ambientLayerMask;
134+
Light2DManager._config.lightDirection = new Vector3(light2DConfig.lightDirection.x, light2DConfig.lightDirection.y, light2DConfig.lightDirection.z);
135+
Light2DManager._config.multiSamples = light2DConfig.multiSamples;
136136
}
137137
this._scene = scene;
138138
this._scene._light2DManager = this;

src/layaAir/laya/display/Input.ts

+2
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ export class Input extends Text {
401401

402402
// PC浏览器隐藏文字
403403
if (!(LayaEnv.isConch && Input.isAppUseNewInput) && !ILaya.Browser.onMiniGame && !ILaya.Browser.onBDMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame && !ILaya.Browser.onBLMiniGame && !ILaya.Browser.onTTMiniGame && !ILaya.Browser.onHWMiniGame && !ILaya.Browser.onTBMiniGame) {
404+
if (this._bgDrawCmd)
405+
this.graphics.removeCmd(this._bgDrawCmd);
404406
this.graphics.clear(true);
405407
this.drawBg();
406408
this._hideText = true;

src/layaAir/laya/display/Node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class Node extends EventDispatcher {
213213
if ((bit & NodeFlags.DISPLAY) !== 0) {
214214
let ele: Node = this._parent;
215215
let stage: Node = ILaya.stage;
216-
let displayedInStage: boolean = false;
216+
let displayedInStage: boolean = this === stage;
217217
while (ele) {
218218
if ((ele._bits & NodeFlags.DISPLAY) !== 0) {
219219
displayedInStage = (ele._bits & NodeFlags.DISPLAYED_INSTAGE) !== 0;

src/layaAir/laya/display/Scene2DSpecial/RenderCMD2D/CommandBuffer2D.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,16 @@ export class CommandBuffer2D {
276276
* @param cmd
277277
*/
278278
addCacheCommand(cmd: Command2D) {
279-
if (cmd instanceof Set2DShaderDataCMD) {
280-
if (cmd._commandBuffer)
281-
cmd.setDest(this._scene._specialManager._shaderData);
282-
}
283-
if (cmd instanceof Set2DDefineCMD) {
284-
if (cmd._commandBuffer)
285-
cmd.setDest(this._scene._specialManager._shaderData);
279+
//TODO
280+
if (this._scene) {
281+
if (cmd instanceof Set2DShaderDataCMD) {
282+
if (cmd._commandBuffer)
283+
cmd.setDest(this._scene._specialManager._shaderData);
284+
}
285+
if (cmd instanceof Set2DDefineCMD) {
286+
if (cmd._commandBuffer)
287+
cmd.setDest(this._scene._specialManager._shaderData);
288+
}
286289
}
287290
this._commands.push(cmd);
288291
cmd._commandBuffer = this;

src/layaAir/laya/display/Sprite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class Sprite extends Node {
424424
}
425425

426426
set skewX(value: number) {
427-
this.skew(value, this._skewX);
427+
this.skew(value, this._skewY);
428428
}
429429

430430
/**

src/layaAir/laya/display/Text.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,8 @@ export class Text extends Sprite {
10001000
}
10011001

10021002
if (!text) {
1003+
if (this._bgDrawCmd)
1004+
this.graphics.removeCmd(this._bgDrawCmd);
10031005
this.graphics.clear(true);
10041006
this.drawBg();
10051007

@@ -1689,6 +1691,8 @@ export class Text extends Sprite {
16891691
*/
16901692
protected renderText(): void {
16911693
let graphics = this.graphics;
1694+
if (this._bgDrawCmd)
1695+
this.graphics.removeCmd(this._bgDrawCmd);
16921696
graphics.clear(true);
16931697
this.drawBg();
16941698

src/layaAir/laya/tilemap/ModuleDef.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TileSetCustomDataLayer } from "./layers/TileSetCustomDataLayer";
33
import { TileMapNavigationLayer } from "./layers/TileSetNavigationLayer";
44
import { TileSetOcclusionLayer } from "./layers/TileSetOcclusionLayer";
55
import { TileSetPhysicsLayer } from "./layers/TileSetPhysicsLayer";
6-
import { TileSetTerrainLayer , TileSetTerrain } from "./layers/TileSetTerrainLayer";
6+
import { TileSetTerrainSet , TileSetTerrain } from "./layers/TileSetTerrainSet";
77
import { TileAlternativesData } from "./TileAlternativesData";
88
import { TileMapChunkData } from "./TileMapChunkData";
99
import { TileMapLayer } from "./TileMapLayer";
@@ -25,7 +25,7 @@ c("TileMapPhysics", TileMapPhysics);
2525

2626
c("TileSetPhysicsLayer", TileSetPhysicsLayer);
2727
c("TileSetOcclusionLayer", TileSetOcclusionLayer);
28-
c("TileSetTerrainLayer", TileSetTerrainLayer);
28+
c("TileSetTerrainSet", TileSetTerrainSet);
2929
c("TileSetTerrain", TileSetTerrain);
3030
c("TileMapNavigationLayer", TileMapNavigationLayer);
3131
c("TileSetCustomDataLayer", TileSetCustomDataLayer);

src/layaAir/laya/tilemap/TileMapChunkData.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface ITileMapRenderElement {
2727

2828

2929
//用于存储格子的数据
30-
class ChunkCellInfo {
30+
export class ChunkCellInfo {
3131
//单元格引用贴图的id
3232
cell: TileSetCellData;
3333
//按照X轴排序 chuckLocalindex
@@ -445,9 +445,9 @@ export class TileMapChunkData {
445445

446446
let layerCount = physicsLayers.length;
447447
let chunk = this._tileLayer._chunk;
448-
let matrix = this._tileLayer._globalTransfrom();
449448
let pos: Vector2 = Vector2.TEMP;
450-
449+
let scaleX = this._tileLayer.owner.scaleX;
450+
let scaleY = this._tileLayer.owner.scaleY;
451451
dirtyFlag.forEach((value, key) => {
452452
//cell posOri extends
453453
let cellDataUseArray = this._cellDataRefMap[key];
@@ -487,11 +487,8 @@ export class TileMapChunkData {
487487
let nShape: Array<number> = new Array(shapeLength);
488488

489489
for (let j = 0; j < shapeLength; j += 2) {
490-
let x = shape[j];
491-
let y = shape[j + 1];
492-
TileMapUtils.transfromPointByValue(matrix, x + ofx, y + ofy, pos);
493-
nShape[j] = pos.x;
494-
nShape[j + 1] = pos.y;
490+
nShape[j] = (shape[j] + ofx) * scaleX;
491+
nShape[j + 1] = (shape[j + 1] + ofy) * scaleY;
495492
}
496493

497494
data = physics.createFixture(rigidBody, physicslayer, nShape);

src/layaAir/laya/tilemap/TileMapLayer.ts

+27-31
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import { NodeFlags } from "../Const";
2424
import { DIRTY_TYPES, DirtyFlagType, TileLayerSortMode, TileMapDirtyFlag } from "./TileMapEnum";
2525
import { TileMapOccluderAgent } from "./TileMapOccluderAgent";
2626
import { Event } from "../events/Event";
27-
28-
27+
import { TileMapTerrainUtil } from "./terrain/TileMapTerrainUtils";
2928

3029
export enum TILEMAPLAYERDIRTYFLAG {
3130
CELL_CHANGE = 1 << 0,//add remove create...
@@ -64,6 +63,7 @@ export class TileMapLayer extends BaseRenderNode2D {
6463
this._inited = true;
6564
TileMapShaderInit.__init__();
6665
TileMapPhysics.__init__();
66+
TileMapTerrainUtil.__init__();
6767
}
6868

6969
private _tileSet: TileSet;
@@ -365,14 +365,14 @@ export class TileMapLayer extends BaseRenderNode2D {
365365
this._tileMapOccluder._updateManager();
366366
this._tileMapPhysics.enable && this._tileMapPhysics.enableRigidBodys();
367367
this._tileMapOccluder.enable && this._tileMapOccluder.enableAllOccluders();
368-
this.owner.on(Event.TRANSFORM_CHANGED, this, this._refreshLayer , [[DirtyFlagType.PHYSICS]]);
368+
this.owner.on(Event.TRANSFORM_CHANGED, this, this._globalChangeHandler);
369369
}
370370

371371
onDisable(): void {
372372
super.onDisable();
373373
this._tileMapPhysics.enable && this._tileMapPhysics.disableRigidBodys();
374374
this._tileMapOccluder.enable && this._tileMapOccluder._removeAllOccluders();
375-
this.owner.off(Event.TRANSFORM_CHANGED, this, this._refreshLayer);
375+
this.owner.off(Event.TRANSFORM_CHANGED, this, this._globalChangeHandler);
376376
}
377377

378378
onDestroy(): void {
@@ -381,10 +381,8 @@ export class TileMapLayer extends BaseRenderNode2D {
381381
this._tileMapOccluder.destroy();
382382
}
383383

384-
_refreshLayer(layers:number[]) {
385-
for (let i = 1 , len = layers.length; i < len; i++) {
386-
this._needUpdateDirtys[layers[i]] = true;
387-
}
384+
_globalChangeHandler() {
385+
this._needUpdateDirtys[DirtyFlagType.PHYSICS] = true;
388386
}
389387

390388
/**
@@ -464,6 +462,7 @@ export class TileMapLayer extends BaseRenderNode2D {
464462

465463
let tileSize = this.tileSet.tileSize;
466464

465+
let checkPoint = Vector2.TEMP;
467466
let tempVec3 = Vector3.TEMP;
468467
this._chunk._getChunkPosByPixel(chuckLocalRect.x - tileSize.x, chuckLocalRect.y - tileSize.y, tempVec3);
469468
let chuckstartRow = tempVec3.x;
@@ -472,11 +471,28 @@ export class TileMapLayer extends BaseRenderNode2D {
472471
let chuckendRow = tempVec3.x;
473472
let chuckendCol = tempVec3.y;
474473

475-
let checkPoint = Vector2.TEMP;
476-
477-
let needUpdateDirty = !!this._needUpdateDirtys.length;
474+
for (let j = chuckstartCol; j <= chuckendCol; j++) {
475+
if (!this._chunkDatas[j]) { continue; }
476+
let rowData = this._chunkDatas[j];
477+
for (let i = chuckstartRow; i <= chuckendRow; i++) {
478+
let chunkData = rowData[i];
479+
if (!chunkData) { continue; }
480+
this._chunk._getChunkLeftTop(i, j, checkPoint);
481+
//是否需要渲染
482+
if (!this._cliper.isClipper(checkPoint.x, checkPoint.y)) {
483+
chunkData._update();//更新数据
484+
chunkData._mergeToElement(this._renderElements);//更新渲染元素
485+
}
486+
}
487+
}
478488

489+
let needUpdatePhysics = this._tileMapPhysics.enable && this._needUpdateDirtys[DirtyFlagType.PHYSICS];
490+
if (needUpdatePhysics) {
491+
this._tileMapPhysics._updateTransfrom();
492+
this._needUpdateDirtys[DirtyFlagType.PHYSICS] = false;
493+
}
479494

495+
// this._needUpdateDirtys.length = 0;
480496
// let sprite = this._testSprite;
481497
// if (!sprite) {
482498
// sprite = this._testSprite = new Sprite();
@@ -492,26 +508,6 @@ export class TileMapLayer extends BaseRenderNode2D {
492508
// chuckLocalRect.z + tileSize.x - chuckLocalRect.x + tileSize.x,
493509
// chuckLocalRect.w + tileSize.y - chuckLocalRect.y + tileSize.y,
494510
// "#ff0000");
495-
496-
for (var j = chuckstartCol; j <= chuckendCol; j++) {
497-
if (!this._chunkDatas[j]) { continue; }
498-
let rowData = this._chunkDatas[j];
499-
for (var i = chuckstartRow; i <= chuckendRow; i++) {
500-
let chunkData = rowData[i];
501-
if (!chunkData) { continue; }
502-
//更新dirty类型
503-
needUpdateDirty && chunkData._forceUpdateDrity(this._needUpdateDirtys);
504-
505-
this._chunk._getChunkLeftTop(i, j, checkPoint);
506-
//是否需要渲染
507-
if (!this._cliper.isClipper(checkPoint.x, checkPoint.y)) {
508-
chunkData._update();//更新数据
509-
chunkData._mergeToElement(this._renderElements);//更新渲染元素
510-
}
511-
}
512-
}
513-
514-
this._needUpdateDirtys.length = 0;
515511
}
516512

517513
/**

src/layaAir/laya/tilemap/TileMapPhysics.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Laya } from "../../Laya";
22
import { FixtureBox2DDef, PhysicsShape, RigidBody2DInfo } from "../physics/IPhysiscs2DFactory";
3+
import { Utils } from "../utils/Utils";
34
import { TileSetPhysicsLayer } from "./layers/TileSetPhysicsLayer";
45
import { TileMapLayer } from "./TileMapLayer";
56

@@ -52,6 +53,13 @@ export class TileMapPhysics {
5253
defRigidBodyDef.angularVelocity = 0;
5354
defRigidBodyDef.linearVelocity.setValue(0, 0);
5455
let rigidBody = factory.rigidBodyDef_Create(defRigidBodyDef);
56+
57+
let trans = this._layer.owner.globalTrans;
58+
let x = trans.x;
59+
let y = trans.y;
60+
let angle = Utils.toRadian(trans.rotation);
61+
Laya.physics2D.set_RigibBody_Transform(rigidBody, x, y, angle);
62+
5563
this._rigidBodys.push(rigidBody);
5664
return rigidBody;
5765
}
@@ -105,7 +113,19 @@ export class TileMapPhysics {
105113
return fixture;
106114
}
107115

108-
116+
/** @internal */
117+
_updateTransfrom(){
118+
let len = this._rigidBodys.length;
119+
if (!len) return;
120+
121+
let trans = this._layer.owner.globalTrans;
122+
let x = trans.x;
123+
let y = trans.y;
124+
let angle = Utils.toRadian(trans.rotation);
125+
for (let i = 0 ; i < len; i++) {
126+
Laya.physics2D.set_RigibBody_Transform(this._rigidBodys[i], x, y, angle);
127+
}
128+
}
109129

110130
/**
111131
* 移除物理形状

0 commit comments

Comments
 (0)