Merge remote-tracking branch 'origin/dev2_aiSdk' into dev2_aiSdk

# Conflicts:
#	modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/BaseDrawer.java
#	modules/mogo-module-service/src/main/java/com/mogo/module/service/intent/MockIntentHandler.java
This commit is contained in:
tongchenfei
2021-03-04 16:02:44 +08:00
4 changed files with 71 additions and 52 deletions

View File

@@ -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()
);
}
/**

View File

@@ -207,8 +207,8 @@ class BaseDrawer {
* @return
*/
public 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;

View File

@@ -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()
}
}
}
}

View File

@@ -664,12 +664,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 );