Support sharing native context and passing road id to native (to speed up search)

This commit is contained in:
Victor Shcherb 2020-07-12 23:29:11 +02:00
parent 7f1fd48455
commit d592736252
4 changed files with 24 additions and 2 deletions

View file

@ -153,6 +153,8 @@ public class NativeLibrary {
protected static native NativeRouteSearchResult loadRoutingData(RouteRegion reg, String regName, int regfp, RouteSubregion subreg,
boolean loadObjects);
public static native void deleteNativeRoutingContext(long handle);
protected static native void deleteRenderingContextHandle(long handle);
protected static native void deleteRouteSearchResult(long searchResultHandle);

View file

@ -217,6 +217,7 @@ public class RoutePlannerFrontEnd {
if (gctx.ctx.calculationProgress == null) {
gctx.ctx.calculationProgress = new RouteCalculationProgress();
}
gctx.ctx.keepNativeRoutingContext = true;
List<GpxPoint> gpxPoints = generageGpxPoints(points, gctx);
GpxPoint start = null;
GpxPoint prev = null;
@ -281,6 +282,7 @@ public class RoutePlannerFrontEnd {
if(gctx.ctx.calculationProgress != null) {
gctx.ctx.calculationProgress.timeToCalculate = System.nanoTime() - timeToCalculate;
}
gctx.ctx.deleteNativeRoutingContext();
BinaryRoutePlanner.printDebugMemoryInformation(gctx.ctx);
calculateGpxRoute(gctx, gpxPoints);
if (!gctx.res.isEmpty()) {
@ -538,6 +540,8 @@ public class RoutePlannerFrontEnd {
// for native routing this is possible when point lies on intersection of 2 lines
// solution here could be to pass to native routing id of the route
// though it should not create any issue
System.out.println("??? not found " + start.pnt.getRoad().getId() + " instead "
+ res.get(0).getObject().getId());
}
}
start.routeToTarget = res;

View file

@ -395,7 +395,7 @@ public class RouteResultPreparation {
List<RouteSegmentResult> result = new ArrayList<RouteSegmentResult>();
if (finalSegment != null) {
ctx.routingTime += finalSegment.distanceFromStart;
println("Routing calculated time distance " + finalSegment.distanceFromStart);
// println("Routing calculated time distance " + finalSegment.distanceFromStart);
// Get results from opposite direction roads
RouteSegment segment = finalSegment.reverseWaySearch ? finalSegment :
finalSegment.opposite.getParentRoute();

View file

@ -48,6 +48,10 @@ public class RoutingContext {
public final Map<BinaryMapIndexReader, List<RouteSubregion>> map = new LinkedHashMap<BinaryMapIndexReader, List<RouteSubregion>>();
public final Map<RouteRegion, BinaryMapIndexReader> reverseMap = new LinkedHashMap<RouteRegion, BinaryMapIndexReader>();
// 0. Reference to native routingcontext for multiple routes
public long nativeRoutingContext;
public boolean keepNativeRoutingContext;
// 1. Initial variables
public int startX;
public int startY;
@ -62,11 +66,13 @@ public class RoutingContext {
public boolean publicTransport;
public RouteCalculationProgress calculationProgress;
public boolean leftSideNavigation;
public List<RouteSegmentResult> previouslyCalculatedRoute;
public PrecalculatedRouteDirection precalculatedRouteDirection;
// 2. Routing memory cache (big objects)
TLongObjectHashMap<List<RoutingSubregionTile>> indexedSubregions = new TLongObjectHashMap<List<RoutingSubregionTile>>();
@ -812,7 +818,17 @@ public class RoutingContext {
return 0;
}
public synchronized void deleteNativeRoutingContext() {
if (nativeRoutingContext != 0) {
NativeLibrary.deleteNativeRoutingContext(nativeRoutingContext);
}
nativeRoutingContext = 0;
}
@Override
protected void finalize() throws Throwable {
deleteNativeRoutingContext();
super.finalize();
}
}