Improve smoothness by protecting visible tiles
This commit is contained in:
69
PBMap.pb
69
PBMap.pb
@@ -1423,6 +1423,53 @@ Module PBMap
|
|||||||
LockMutex(*PBMap\MemoryCacheAccessMutex) ; Prevents threads to start or finish
|
LockMutex(*PBMap\MemoryCacheAccessMutex) ; Prevents threads to start or finish
|
||||||
Protected CacheSize = MapSize(*PBMap\MemCache\Images()) * Pow(*PBMap\TileSize, 2) * 4 ; Size of a tile = TileSize * TileSize * 4 bytes (RGBA)
|
Protected CacheSize = MapSize(*PBMap\MemCache\Images()) * Pow(*PBMap\TileSize, 2) * 4 ; Size of a tile = TileSize * TileSize * 4 bytes (RGBA)
|
||||||
Protected CacheLimit = *PBMap\Options\MaxMemCache * 1024
|
Protected CacheLimit = *PBMap\Options\MaxMemCache * 1024
|
||||||
|
Protected EnabledLayers.i
|
||||||
|
Protected MinTiles.i
|
||||||
|
Protected MinCacheBytes.i
|
||||||
|
Protected nx.i = DesktopScaledX(GadgetWidth(*PBMap\Gadget)) / 2 / *PBMap\TileSize
|
||||||
|
Protected ny.i = DesktopScaledY(GadgetHeight(*PBMap\Gadget)) / 2 / *PBMap\TileSize
|
||||||
|
Protected NewMap ProtectedTiles.i()
|
||||||
|
Protected TileCoords.Coordinates
|
||||||
|
Protected tx.i, ty.i, tilex.i, tiley.i, x.i, y.i
|
||||||
|
Protected kq.q
|
||||||
|
Protected key.s
|
||||||
|
Protected tilemax.i = 1 << *PBMap\Zoom
|
||||||
|
|
||||||
|
ForEach *PBMap\LayersList()
|
||||||
|
If *PBMap\LayersList()\Enabled
|
||||||
|
EnabledLayers + 1
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
|
||||||
|
If EnabledLayers > 0
|
||||||
|
MinTiles = (2 * nx + 3) * (2 * ny + 3) * EnabledLayers
|
||||||
|
MinCacheBytes = MinTiles * Pow(*PBMap\TileSize, 2) * 4
|
||||||
|
CacheLimit = Max(CacheLimit, MinCacheBytes)
|
||||||
|
|
||||||
|
LatLon2TileXY(@*PBMap\GeographicCoordinates, @TileCoords, *PBMap\Zoom)
|
||||||
|
tx = Int(TileCoords\x)
|
||||||
|
ty = Int(TileCoords\y)
|
||||||
|
|
||||||
|
ForEach *PBMap\LayersList()
|
||||||
|
If *PBMap\LayersList()\Enabled
|
||||||
|
For y = -ny - 1 To ny + 1
|
||||||
|
For x = -nx - 1 To nx + 1
|
||||||
|
tilex = (tx + x) % tilemax
|
||||||
|
If tilex < 0
|
||||||
|
tilex + tilemax
|
||||||
|
EndIf
|
||||||
|
tiley = ty + y
|
||||||
|
If tiley >= 0 And tiley < tilemax
|
||||||
|
kq = (*PBMap\Zoom << 8) | (tilex << 16) | (tiley << 36)
|
||||||
|
key = *PBMap\LayersList()\Name + Str(kq)
|
||||||
|
ProtectedTiles(key) = 1
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
EndIf
|
||||||
|
|
||||||
MyDebug(*PBMap, "Cache size : " + Str(CacheSize/1024) + " / CacheLimit : " + Str(CacheLimit/1024), 5)
|
MyDebug(*PBMap, "Cache size : " + Str(CacheSize/1024) + " / CacheLimit : " + Str(CacheLimit/1024), 5)
|
||||||
If CacheSize > CacheLimit
|
If CacheSize > CacheLimit
|
||||||
MyDebug(*PBMap, " Cache full. Trying cache cleaning", 5)
|
MyDebug(*PBMap, " Cache full. Trying cache cleaning", 5)
|
||||||
@@ -1432,14 +1479,16 @@ Module PBMap
|
|||||||
Protected CacheMapKey.s = *PBMap\MemCache\ImagesTimeStack()\MapKey
|
Protected CacheMapKey.s = *PBMap\MemCache\ImagesTimeStack()\MapKey
|
||||||
; Is the loading over
|
; Is the loading over
|
||||||
If *PBMap\MemCache\Images(CacheMapKey)\Tile <= 0 ;TODO Should not verify this var directly
|
If *PBMap\MemCache\Images(CacheMapKey)\Tile <= 0 ;TODO Should not verify this var directly
|
||||||
MyDebug(*PBMap, " Delete " + CacheMapKey, 5)
|
If FindMapElement(ProtectedTiles(), CacheMapKey) = 0
|
||||||
If *PBMap\MemCache\Images(CacheMapKey)\nImage;IsImage(*PBMap\MemCache\Images(CacheMapKey)\nImage)
|
MyDebug(*PBMap, " Delete " + CacheMapKey, 5)
|
||||||
FreeImage(*PBMap\MemCache\Images(CacheMapKey)\nImage)
|
If *PBMap\MemCache\Images(CacheMapKey)\nImage;IsImage(*PBMap\MemCache\Images(CacheMapKey)\nImage)
|
||||||
MyDebug(*PBMap, " and free image nb " + Str(*PBMap\MemCache\Images(CacheMapKey)\nImage), 5)
|
FreeImage(*PBMap\MemCache\Images(CacheMapKey)\nImage)
|
||||||
*PBMap\MemCache\Images(CacheMapKey)\nImage = 0
|
MyDebug(*PBMap, " and free image nb " + Str(*PBMap\MemCache\Images(CacheMapKey)\nImage), 5)
|
||||||
|
*PBMap\MemCache\Images(CacheMapKey)\nImage = 0
|
||||||
|
EndIf
|
||||||
|
DeleteMapElement(*PBMap\MemCache\Images(), CacheMapKey)
|
||||||
|
DeleteElement(*PBMap\MemCache\ImagesTimeStack(), 1)
|
||||||
EndIf
|
EndIf
|
||||||
DeleteMapElement(*PBMap\MemCache\Images(), CacheMapKey)
|
|
||||||
DeleteElement(*PBMap\MemCache\ImagesTimeStack(), 1)
|
|
||||||
; ElseIf *PBMap\MemCache\Images(CacheMapKey)\Tile = 0
|
; ElseIf *PBMap\MemCache\Images(CacheMapKey)\Tile = 0
|
||||||
; MyDebug(*PBMap, " Delete " + CacheMapKey, 5)
|
; MyDebug(*PBMap, " Delete " + CacheMapKey, 5)
|
||||||
; DeleteMapElement(*PBMap\MemCache\Images(), CacheMapKey)
|
; DeleteMapElement(*PBMap\MemCache\Images(), CacheMapKey)
|
||||||
@@ -3313,9 +3362,9 @@ EndModule
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
; IDE Options = PureBasic 6.21 (Windows - x64)
|
; IDE Options = PureBasic 6.12 LTS (Windows - x86)
|
||||||
; CursorPosition = 53
|
; CursorPosition = 484
|
||||||
; FirstLine = 40
|
; FirstLine = 468
|
||||||
; Folding = ---------------------
|
; Folding = ---------------------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
Reference in New Issue
Block a user