@@ -24,8 +24,7 @@ import { NodeFlags } from "../Const";
24
24
import { DIRTY_TYPES , DirtyFlagType , TileLayerSortMode , TileMapDirtyFlag } from "./TileMapEnum" ;
25
25
import { TileMapOccluderAgent } from "./TileMapOccluderAgent" ;
26
26
import { Event } from "../events/Event" ;
27
-
28
-
27
+ import { TileMapTerrainUtil } from "./terrain/TileMapTerrainUtils" ;
29
28
30
29
export enum TILEMAPLAYERDIRTYFLAG {
31
30
CELL_CHANGE = 1 << 0 , //add remove create...
@@ -64,6 +63,7 @@ export class TileMapLayer extends BaseRenderNode2D {
64
63
this . _inited = true ;
65
64
TileMapShaderInit . __init__ ( ) ;
66
65
TileMapPhysics . __init__ ( ) ;
66
+ TileMapTerrainUtil . __init__ ( ) ;
67
67
}
68
68
69
69
private _tileSet : TileSet ;
@@ -365,14 +365,14 @@ export class TileMapLayer extends BaseRenderNode2D {
365
365
this . _tileMapOccluder . _updateManager ( ) ;
366
366
this . _tileMapPhysics . enable && this . _tileMapPhysics . enableRigidBodys ( ) ;
367
367
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 ) ;
369
369
}
370
370
371
371
onDisable ( ) : void {
372
372
super . onDisable ( ) ;
373
373
this . _tileMapPhysics . enable && this . _tileMapPhysics . disableRigidBodys ( ) ;
374
374
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 ) ;
376
376
}
377
377
378
378
onDestroy ( ) : void {
@@ -381,10 +381,8 @@ export class TileMapLayer extends BaseRenderNode2D {
381
381
this . _tileMapOccluder . destroy ( ) ;
382
382
}
383
383
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 ;
388
386
}
389
387
390
388
/**
@@ -464,6 +462,7 @@ export class TileMapLayer extends BaseRenderNode2D {
464
462
465
463
let tileSize = this . tileSet . tileSize ;
466
464
465
+ let checkPoint = Vector2 . TEMP ;
467
466
let tempVec3 = Vector3 . TEMP ;
468
467
this . _chunk . _getChunkPosByPixel ( chuckLocalRect . x - tileSize . x , chuckLocalRect . y - tileSize . y , tempVec3 ) ;
469
468
let chuckstartRow = tempVec3 . x ;
@@ -472,11 +471,28 @@ export class TileMapLayer extends BaseRenderNode2D {
472
471
let chuckendRow = tempVec3 . x ;
473
472
let chuckendCol = tempVec3 . y ;
474
473
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
+ }
478
488
489
+ let needUpdatePhysics = this . _tileMapPhysics . enable && this . _needUpdateDirtys [ DirtyFlagType . PHYSICS ] ;
490
+ if ( needUpdatePhysics ) {
491
+ this . _tileMapPhysics . _updateTransfrom ( ) ;
492
+ this . _needUpdateDirtys [ DirtyFlagType . PHYSICS ] = false ;
493
+ }
479
494
495
+ // this._needUpdateDirtys.length = 0;
480
496
// let sprite = this._testSprite;
481
497
// if (!sprite) {
482
498
// sprite = this._testSprite = new Sprite();
@@ -492,26 +508,6 @@ export class TileMapLayer extends BaseRenderNode2D {
492
508
// chuckLocalRect.z + tileSize.x - chuckLocalRect.x + tileSize.x,
493
509
// chuckLocalRect.w + tileSize.y - chuckLocalRect.y + tileSize.y,
494
510
// "#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 ;
515
511
}
516
512
517
513
/**
0 commit comments