fix bug of cloud data reslove

This commit is contained in:
zhongchao
2021-07-14 20:55:12 +08:00
parent 715f0059d7
commit c72e9beed7
12 changed files with 26 additions and 63 deletions

View File

View File

View File

@@ -133,7 +133,6 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
mMarkersCaches.clear();
mMarkersCaches = newAdasRecognizedMarkersCaches;
// Log.d(TAG, "更新缓存marker, size : " + mMarkersCaches.size());
Log.d("ADAS数据延时绘制", "render 接收数据 -> 处理结束 " + TimeUnit.NANOSECONDS.toMillis((System.nanoTime() - start)) + "ms");
}

View File

@@ -35,6 +35,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/**
* @author congtaowang
@@ -173,44 +174,18 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
IMogoMarker marker = mMarkersCaches.remove(uniqueKey);
if (marker != null && !marker.isDestroyed()) {
updateCacheMarkerRes(marker, cloudRoadData);
renderSnapshotOneFrame(true, marker, uniqueKey, cloudRoadData, newMarkersCaches);
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
} else {
newDiffSet.add(cloudRoadData);
}
}
removeUselessMarker(mMarkersCaches);
removeUselessLastRecord();
// 能复用的 marker 数量
// int cachedMarkerSize = mMarkersCaches.size();
// 需要新增的 marker 数量
int newDiffSetSize = newDiffSet.size();
// 能复用的数量
// int size = Math.min(cachedMarkerSize, newDiffSetSize);
// 复用过期 marker
if (newDiffSetSize > 0) {
// Iterator<Map.Entry<String, IMogoMarker>> entryIterator = mMarkersCaches.entrySet().iterator();
// for (int i = 0; i < size; i++) {
// SocketDownData.CloudRoadDataProto cloudRoadData = newDiffSet.get(i);
// String uniqueKey = cloudRoadData.getUuid();
// Map.Entry<String, IMogoMarker> entry = entryIterator.next();
// entryIterator.remove();
// SocketDownData.CloudRoadDataProto old = mLastPositions.remove(entry.getKey());
// IMogoMarker marker = entry.getValue();
// if (marker == null) {
// continue;
// }
//
// // 更新资源内容
// if (old == null || old.getType() != cloudRoadData.getType()) {
// updateCacheMarkerRes(marker, cloudRoadData);
// }
// renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
// }
// 复用过后还需新增的 marker
for (int i = 0; i < newDiffSetSize; i++) {
SocketDownData.CloudRoadDataProto cloudRoadData = newDiffSet.get(i);
String uniqueKey = cloudRoadData.getUuid();
@@ -218,17 +193,13 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
if (marker == null) {
continue;
}
renderSnapshotOneFrame(false, marker, uniqueKey, cloudRoadData, newMarkersCaches);
Log.d("云端融合数据", "新增marker id : " + uniqueKey);
renderSnapshotOneFrame(marker, uniqueKey, cloudRoadData, newMarkersCaches);
}
}
// if (cachedMarkerSize - size > 0) {
// sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
// }
sendMessage(MSG_REMOVE_DIRTY_MARKERS, mMarkersCaches);
mMarkersCaches.clear();
mMarkersCaches = newMarkersCaches;
}
/**
@@ -295,41 +266,34 @@ public class SnapshotSetDataDrawer extends BaseDrawer implements IMogoMarkerClic
* @param cloudRoadData {@link SocketDownData.CloudRoadDataProto}
* @param newSnapshotCaches 缓存数据
*/
private void renderSnapshotOneFrame(boolean useCache, IMogoMarker marker, String uniqueKey, SocketDownData.CloudRoadDataProto cloudRoadData, Map<String, IMogoMarker> newSnapshotCaches) {
private void renderSnapshotOneFrame(IMogoMarker marker, String uniqueKey, SocketDownData.CloudRoadDataProto cloudRoadData, Map<String, IMogoMarker> newSnapshotCaches) {
Logger.d(TAG, "renderSnapshotOneFrame");
final long start = System.currentTimeMillis();
Log.d("云端融合数据", " uuid : " + uniqueKey + " type : " + cloudRoadData.getType() + " fromType : " + cloudRoadData.getFromType());
final long start = System.nanoTime();
SocketDownData.CloudRoadDataProto lastPosition = mLastPositions.remove(uniqueKey);
double lastLon = -1;
double lastLat = -1;
if (lastPosition != null) {
lastLon = lastPosition.getWgslon();
lastLat = lastPosition.getWgslat();
}
double[] matchLonLat = getMatchLonLat(cloudRoadData.getUuid(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat);
SocketDownData.CloudRoadDataProto.Builder builder = cloudRoadData.toBuilder();
builder.setWgslon(matchLonLat[0]);
builder.setWgslat(matchLonLat[1]);
cloudRoadData = builder.build();
// 道路吸附
// double lastLon = -1;
// double lastLat = -1;
// if (lastPosition != null) {
// lastLon = lastPosition.getWgslon();
// lastLat = lastPosition.getWgslat();
// }
// double[] matchLonLat = getMatchLonLat(cloudRoadData.getUuid(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading(), lastLon, lastLat);
// SocketDownData.CloudRoadDataProto.Builder builder = cloudRoadData.toBuilder();
// builder.setWgslon(matchLonLat[0]);
// builder.setWgslat(matchLonLat[1]);
// cloudRoadData = builder.build();
mLastPositions.put(uniqueKey, cloudRoadData);
if (useCache) {
long interval = computeAnimDuration(lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
final MogoLatLng point = new MogoLatLng(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long cost = System.currentTimeMillis() - start;
final long intervalRef = interval - cost;
marker.addDynamicAnchorPosition(point, (float) cloudRoadData.getHeading(), intervalRef);
} else {
marker.setRotateAngle(((float) cloudRoadData.getHeading()));
marker.setPosition(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long interval = 45;
if (lastPosition != null) {
interval = computeAnimDuration(lastPosition.getSatelliteTime(), cloudRoadData.getSatelliteTime());
}
final MogoLatLng point = new MogoLatLng(cloudRoadData.getWgslat(), cloudRoadData.getWgslon());
long cost = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
final long intervalRef = interval - cost;
marker.addDynamicAnchorPosition(point, (float) cloudRoadData.getHeading(), intervalRef);
marker.setAnchorColor(getModelRenderColor(cloudRoadData.getType(), cloudRoadData.getFromType(), cloudRoadData.getSpeed(), cloudRoadData.getWgslon(), cloudRoadData.getWgslat(), cloudRoadData.getHeading()));
newSnapshotCaches.put(uniqueKey, marker);

View File

View File

View File