From 01b6e1ac159a9506c850de483301a1ffe36afaf9 Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Wed, 3 Mar 2021 20:28:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drawer/AdasRecognizedResultDrawer.java | 108 ++++++++++-------- .../mogo/module/common/drawer/BaseDrawer.java | 4 +- .../com/mogo/module/common/kt/ScopeManager.kt | 9 ++ .../service/intent/MockIntentHandler.java | 10 +- 4 files changed, 75 insertions(+), 56 deletions(-) diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java index 6d69d86953..a0530faed4 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/AdasRecognizedResultDrawer.java @@ -2,6 +2,7 @@ package com.mogo.module.common.drawer; import android.content.Context; import android.text.TextUtils; +import android.util.Log; import com.mogo.commons.AbsMogoApplication; import com.mogo.map.MogoLatLng; @@ -10,6 +11,7 @@ import com.mogo.map.marker.MogoMarkerOptions; import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.R; import com.mogo.module.common.constants.DataTypes; +import com.mogo.module.common.kt.ScopeManager; import com.mogo.realtime.entity.ADASRecognizedResult; import com.mogo.utils.logger.Logger; @@ -82,56 +84,64 @@ class AdasRecognizedResultDrawer extends BaseDrawer { if ( recognizedListResult == null ) { continue; } - - // 暂时只显示车辆 - if ( !isCarType( recognizedListResult.type ) ) { - continue; - } - - String uniqueKey = recognizedListResult.uuid; - if ( TextUtils.isEmpty( uniqueKey ) ) { - continue; - } - - final long start = System.currentTimeMillis(); -// double[] matchedPoint = matchRoad( recognizedListResult.lon, -// recognizedListResult.lat, -// recognizedListResult.heading, -// recognizedListResult.dataAccuracy == 1 -// ); -// Log.i("match-road-timer", "cost " + (System.currentTimeMillis() - start) + "ms"); -// if ( matchedPoint != null ) { -// recognizedListResult.lon = matchedPoint[0]; -// recognizedListResult.lat = matchedPoint[1]; -// } - - IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey ); - ADASRecognizedResult lastPosition = mLastPositions.put( uniqueKey, recognizedListResult ); - - if ( marker == null || marker.isDestroyed() ) { - marker = drawAdasRecognizedDataMarker( recognizedListResult ); - if ( marker == null ) { - continue; - } - } - newAdasRecognizedMarkersCaches.put( uniqueKey, marker ); - if ( lastPosition != null ) { - MogoLatLng endLatLon = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon ); - long interval = computeAnimDuration( lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime ); - marker.addDynamicAnchorPosition( endLatLon, interval ); - Logger.d( TAG, "anim duration: %s", interval ); - } else { - marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) ); - marker.setPosition( recognizedListResult.lat, recognizedListResult.lon ); - } - showSelfSpeed( mContext, - marker, - recognizedListResult.speed, - MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() - ); + ScopeManager.INSTANCE.adasScope( () -> { + renderAdasOneFrame( recognizedListResult, newAdasRecognizedMarkersCaches ); + } ); } - sendMessage( MSG_REMOVE_DIRTY_MARKERS, mAdasRecognizedMarkersCaches ); - mAdasRecognizedMarkersCaches = newAdasRecognizedMarkersCaches; + + ScopeManager.INSTANCE.adasScope( () -> { + sendMessage( MSG_REMOVE_DIRTY_MARKERS, mAdasRecognizedMarkersCaches ); + mAdasRecognizedMarkersCaches = newAdasRecognizedMarkersCaches; + } ); + } + + private void renderAdasOneFrame( ADASRecognizedResult recognizedListResult, Map< String, IMogoMarker > newAdasRecognizedMarkersCaches ) { + // 暂时只显示车辆 + if ( !isCarType( recognizedListResult.type ) ) { + return; + } + + String uniqueKey = recognizedListResult.uuid; + if ( TextUtils.isEmpty( uniqueKey ) ) { + return; + } + + final long start = System.currentTimeMillis(); + double[] matchedPoint = matchRoad( recognizedListResult.lon, + recognizedListResult.lat, + recognizedListResult.heading, + recognizedListResult.dataAccuracy == 1 + ); + Log.i( "match-road-timer", "cost " + ( System.currentTimeMillis() - start ) + "ms" ); + if ( matchedPoint != null ) { + recognizedListResult.lon = matchedPoint[0]; + recognizedListResult.lat = matchedPoint[1]; + } + + IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( uniqueKey ); + ADASRecognizedResult lastPosition = mLastPositions.put( uniqueKey, recognizedListResult ); + + if ( marker == null || marker.isDestroyed() ) { + marker = drawAdasRecognizedDataMarker( recognizedListResult ); + if ( marker == null ) { + return; + } + } + newAdasRecognizedMarkersCaches.put( uniqueKey, marker ); + if ( lastPosition != null ) { + MogoLatLng endLatLon = new MogoLatLng( recognizedListResult.lat, recognizedListResult.lon ); + long interval = computeAnimDuration( lastPosition.systemTime, recognizedListResult.systemTime, lastPosition.satelliteTime, recognizedListResult.satelliteTime ); + marker.addDynamicAnchorPosition( endLatLon, interval ); + Logger.d( TAG, "anim duration: %s", interval ); + } else { + marker.setRotateAngle( ( ( float ) recognizedListResult.heading ) ); + marker.setPosition( recognizedListResult.lat, recognizedListResult.lon ); + } + showSelfSpeed( mContext, + marker, + recognizedListResult.speed, + MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() + ); } /** diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java index 20dc2362f8..57ab61534f 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java @@ -207,8 +207,8 @@ class BaseDrawer { * @return */ protected long computeAnimDuration( long lastSystemTime, long curSystemTime, long lastSatelliteTime, long curSatelliteTime ) { - long systemTimeInterval = curSystemTime - lastSystemTime - 25; - long satelliteTimeInterval = curSatelliteTime - lastSatelliteTime - 25; + long systemTimeInterval = curSystemTime - lastSystemTime; + long satelliteTimeInterval = curSatelliteTime - lastSatelliteTime; long interval = systemTimeInterval < satelliteTimeInterval || satelliteTimeInterval == 0 ? systemTimeInterval : satelliteTimeInterval; if ( interval < 45 ) { interval = 45; diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/kt/ScopeManager.kt b/modules/mogo-module-common/src/main/java/com/mogo/module/common/kt/ScopeManager.kt index 9a6ba2cf40..8909e4213b 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/kt/ScopeManager.kt +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/kt/ScopeManager.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.launch object ScopeManager { private var mScope = MainScope() + private var mAdasScope = MainScope() private var mThreadScope: RestrictTo.Scope? = null fun mainScope(runnable: Runnable?) { @@ -23,4 +24,12 @@ object ScopeManager { } } } + + fun adasScope(runnable: Runnable?) { + mAdasScope.launch(Dispatchers.Default) { + runnable?.apply { + run() + } + } + } } \ No newline at end of file diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java index 05d2271b41..2d5976e187 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java @@ -557,7 +557,7 @@ public class MockIntentHandler implements IntentHandler { break; case 47: mLocationMockHandler.sendEmptyMessageDelayed( 1, 200L ); - mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 ); +// mLocationMockHandler.sendEmptyMessageDelayed( 2, 0 ); // mLocationMockHandler.sendEmptyMessageDelayed( 3, 300L ); break; } @@ -652,12 +652,12 @@ public class MockIntentHandler implements IntentHandler { if ( br == null ) { br = new BufferedReader( new InputStreamReader( AbsMogoApplication.getApp().getAssets().open( "loc.txt" ) ) ); } + final long start = System.currentTimeMillis(); String line = br.readLine(); if ( line == null ) { throw new Exception( "end of file." ); } JSONObject jo = new JSONObject( line ); - final long start = System.currentTimeMillis(); MarkerServiceHandler.getApis().getMapServiceApi().getMapUIController().syncLocation2Map( jo ); Log.i( "mock-timer-loc", "cost " + ( System.currentTimeMillis() - start ) + "ms" ); mLocationMockHandler.sendEmptyMessageDelayed( 1, 100L ); @@ -680,9 +680,9 @@ public class MockIntentHandler implements IntentHandler { if ( cloudRoadData == null ) { return false; } - double[] coor = CoordinateUtils.transformWgsToGcj( cloudRoadData.getLat(), cloudRoadData.getLon() ); - cloudRoadData.setLon( coor[0] ); - cloudRoadData.setLat( coor[1] ); +// double[] coor = CoordinateUtils.transformWgsToGcj( cloudRoadData.getLat(), cloudRoadData.getLon() ); +// cloudRoadData.setLon( coor[0] ); +// cloudRoadData.setLat( coor[1] ); allList.add( cloudRoadData ); data.setAllList( allList );