Skip to content

Commit

Permalink
Fixed fragment queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ISeleznev-HORIS committed Dec 26, 2019
1 parent 947f2fa commit ffa57d6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun <T, OutT> QuadKey<T>.projectRect(rect: Rect<OutT>): Rect<OutT> {
return Rect(origin, dimension)
}

fun QuadKey<LonLat>.zoom() = ((length - 1) / 3 + 1) * 3
fun QuadKey<LonLat>.zoom() = length

fun <TypeT> QuadKey<TypeT>.computeOrigin(mapRect: Rect<TypeT>): Vec<TypeT> {
return projectOrigin(mapRect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ abstract class DemoModelBase(private val dimension: DoubleVector) {
loopY = false
}

params(
DevParams.DEBUG_GRID.key to true,
DevParams.MICRO_TASK_EXECUTOR.key to "ui_thread",
DevParams.PERF_STATS.key to true
)
// params(
// DevParams.DEBUG_GRID.key to true,
// DevParams.MICRO_TASK_EXECUTOR.key to "ui_thread",
// DevParams.PERF_STATS.key to true
// )

mapLocationConsumer = { Clipboard.copy(LiveMapLocation.getLocationString(it)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MapLocationInitializationSystem(
.run(myViewport::calculateBoundingBox)
.calculatePosition { zoom, coordinates ->
myCamera.get<CameraComponent>().apply {
this.zoom = floor(zoom)
//this.zoom = floor(zoom)
this.position = coordinates
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class EmptyFragmentsComponent : EcsComponent {
}
}

class ExistingRegionsComponent : EcsComponent {
val existingRegions = HashSet<String>()
}

class ChangedFragmentsComponent : EcsComponent {
private val myNewFragments = HashSet<FragmentKey>()
private val myObsoleteFragments = HashSet<FragmentKey>()
Expand Down Expand Up @@ -114,7 +118,7 @@ class DownloadingFragmentsComponent : EcsComponent {

fun reduceQueue(keys: Set<FragmentKey>) {
for (key in keys) {
queue[key.quadKey.zoom()]?.remove(key)
queue[key.zoom()]?.remove(key)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ class FragmentUpdateSystem(
.addComponents {
+ ChangedFragmentsComponent()
+ EmptyFragmentsComponent()
+ ExistingRegionsComponent()
}
}

override fun updateImpl(context: LiveMapContext, dt: Double) {
val cellStateComponent = getSingleton<CellStateComponent>()
val changedFragmentsComponent = getSingleton<ChangedFragmentsComponent>()
val emptyFragments = getSingleton<EmptyFragmentsComponent>()
val existingRegions = getSingleton<ExistingRegionsComponent>().existingRegions

val quadsToAdd = cellStateComponent.quadsToAdd
val quadsToRemove = cellStateComponent.quadsToRemove

val fragmentsToAdd = ArrayList<FragmentKey>()
Expand All @@ -45,6 +46,12 @@ class FragmentUpdateSystem(
val bbox = regionEntity.get<RegionBBoxComponent>().bbox
val regionId = regionEntity.get<RegionIdComponent>().regionId

var quadsToAdd = cellStateComponent.quadsToAdd
if (!existingRegions.contains(regionId)) {
quadsToAdd = cellStateComponent.visibleQuads
existingRegions.add(regionId)
}

for (quad in quadsToAdd) {
if (!emptyFragments.contains(regionId, quad) && bbox.intersect(quad)) {
fragmentsToAdd.add(FragmentKey(regionId, quad))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RegionEmitSystem(componentManager: EcsComponentManager) : LiveMapSystem(co
private var myPendingZoom = -1

override fun initImpl(context: LiveMapContext) {
createEntity("emitted_regions").addComponent(EmittedRegionsComponent())
createEntity("emitted_regions").add(EmittedRegionsComponent())
}

override fun updateImpl(context: LiveMapContext, dt: Double) {
Expand Down

0 comments on commit ffa57d6

Please sign in to comment.