src/core/TargetSystem.js
/**
	* Updates the target system internal state.
	*
	* @return {TargetSystem} A reference to this target system.
	*/
Updates the target system internal state.
@return {TargetSystem} A reference to this target system.
Updates the target system internal state . @return { TargetSystem } A reference to this target system .
update() {
		const records = this.owner.memoryRecords;
		this._currentRecord = null;
		visibleRecords.length = 0;
		invisibleRecords.length = 0;
		for ( let i = 0, l = records.length; i < l; i ++ ) {
			const record = records[ i ];
			if ( record.visible ) {
				visibleRecords.push( record );
			} else {
				invisibleRecords.push( record );
			}
		}
		if ( visibleRecords.length > 0 ) {
			let minDistance = Infinity;
			for ( let i = 0, l = visibleRecords.length; i < l; i ++ ) {
				const record = visibleRecords[ i ];
				const distance = this.owner.position.squaredDistanceTo( record.lastSensedPosition );
				if ( distance < minDistance ) {
					minDistance = distance;
					this._currentRecord = record;
				}
			}
		} else if ( invisibleRecords.length > 0 ) {
			let maxTimeLastSensed = - Infinity;
			for ( let i = 0, l = invisibleRecords.length; i < l; i ++ ) {
				const record = invisibleRecords[ i ];
				if ( record.timeLastSensed > maxTimeLastSensed ) {
					maxTimeLastSensed = record.timeLastSensed;
					this._currentRecord = record;
				}
			}
		}
		return this;
	}
update ( ) { const records = this . owner . memoryRecords ; this . _currentRecord = null ; visibleRecords . length = 0 ; invisibleRecords . length = 0 ; for ( let i = 0 , l = records . length ; i < l ; i ++ ) { const record = records [ i ] ; if ( record . visible ) { visibleRecords . push ( record ) ; } else { invisibleRecords . push ( record ) ; } } if ( visibleRecords . length > 0 ) { let minDistance = Infinity ; for ( let i = 0 , l = visibleRecords . length ; i < l ; i ++ ) { const record = visibleRecords [ i ] ; const distance = this . owner . position . squaredDistanceTo ( record . lastSensedPosition ) ; if ( distance < minDistance ) { minDistance = distance ; this . _currentRecord = record ; } } } else if ( invisibleRecords . length > 0 ) { let maxTimeLastSensed = - Infinity ; for ( let i = 0 , l = invisibleRecords . length ; i < l ; i ++ ) { const record = invisibleRecords [ i ] ; if ( record . timeLastSensed > maxTimeLastSensed ) maxTimeLastSensed = record . timeLastSensed ; this . _currentRecord = record ; } } } return this ; }
Updates the target system internal state.
Updates the target system internal state .
// reset // sort records according to their visibility // record selection // if there are visible records, select the closest one // if there are invisible records, select the one that was last sensed