优化显示逻辑
This commit is contained in:
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user