@@ -3,6 +3,7 @@ import { PositionComponent } from '../component/PositionComponent'
33import { MAP_MARKER_CHANGE , MapMarkerComponent } from '../component/MapMarkerComponent'
44import { UpdateRadarEntityEvent } from '../../event/LocalEvents'
55import { EventBroker } from '../../event/EventBroker'
6+ import { MAP_MAX_UPDATE_INTERVAL , TILESIZE } from '../../params'
67
78export class MapMarkerUpdateSystem extends AbstractGameSystem {
89 readonly componentsRequired : Set < Function > = new Set ( [ PositionComponent , MapMarkerComponent ] )
@@ -12,9 +13,15 @@ export class MapMarkerUpdateSystem extends AbstractGameSystem {
1213 for ( const entity of dirty ) {
1314 try {
1415 const components = this . ecs . getComponents ( entity )
15- const mapMarkerType = components . get ( MapMarkerComponent ) . mapMarkerType
16+ const mapMarkerComponent = components . get ( MapMarkerComponent )
17+ const mapMarkerType = mapMarkerComponent . mapMarkerType
18+ mapMarkerComponent . lastUpdateMs += elapsedMs
1619 const position = components . get ( PositionComponent ) . position
17- EventBroker . publish ( new UpdateRadarEntityEvent ( mapMarkerType , entity , MAP_MARKER_CHANGE . update , position ) )
20+ if ( mapMarkerComponent . lastUpdateMs > MAP_MAX_UPDATE_INTERVAL && position . distanceToSquared ( mapMarkerComponent . lastPos ) / TILESIZE * 15 > 2 ) {
21+ EventBroker . publish ( new UpdateRadarEntityEvent ( mapMarkerType , entity , MAP_MARKER_CHANGE . update , position ) )
22+ mapMarkerComponent . lastUpdateMs = 0
23+ mapMarkerComponent . lastPos . copy ( position )
24+ }
1825 } catch ( e ) {
1926 console . error ( e )
2027 }
0 commit comments