WIP typhoon cache cleaning
This commit is contained in:
34
PBMap.pb
34
PBMap.pb
@@ -102,6 +102,7 @@ Module PBMap
|
|||||||
Structure ImgMemCach
|
Structure ImgMemCach
|
||||||
nImage.i
|
nImage.i
|
||||||
Location.Location
|
Location.Location
|
||||||
|
Mutex.i
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure TileMemCach
|
Structure TileMemCach
|
||||||
@@ -481,23 +482,26 @@ Module PBMap
|
|||||||
Protected Tile.position
|
Protected Tile.position
|
||||||
;Adding the image to the cache if possible
|
;Adding the image to the cache if possible
|
||||||
AddMapElement(PBMap\MemCache\Images(), key)
|
AddMapElement(PBMap\MemCache\Images(), key)
|
||||||
|
PBMap\MemCache\Images(key)\Mutex = CreateMutex()
|
||||||
|
LockMutex(PBMap\MemCache\Images(key)\Mutex)
|
||||||
nImage = GetTileFromHDD(CacheFile)
|
nImage = GetTileFromHDD(CacheFile)
|
||||||
If nImage = -1
|
If nImage = -1
|
||||||
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, CacheFile)
|
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, CacheFile)
|
||||||
|
If nImage = -1
|
||||||
|
MyDebug("Error GetImageThread procedure, image not loaded - " + key)
|
||||||
|
*Tile\nImage = -1
|
||||||
|
ProcedureReturn
|
||||||
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
If nImage <> -1
|
|
||||||
PBMap\MemCache\Images(key)\nImage = nImage
|
PBMap\MemCache\Images(key)\nImage = nImage
|
||||||
Tile\x=*Tile\PBMapTileX
|
Tile\x=*Tile\PBMapTileX
|
||||||
Tile\y=*Tile\PBMapTiley
|
Tile\y=*Tile\PBMapTiley
|
||||||
XY2LatLon(@Tile,@PBMap\MemCache\Images(key)\Location)
|
XY2LatLon(@Tile,@PBMap\MemCache\Images(key)\Location)
|
||||||
MyDebug("Image nb " + Str(nImage) + " successfully added to mem cache")
|
MyDebug("Image nb " + Str(nImage) + " successfully added to mem cache")
|
||||||
MyDebug("With the following key : " + key)
|
MyDebug("With the following key : " + key)
|
||||||
Else
|
|
||||||
MyDebug("Error GetImageThread procedure, image not loaded - " + key)
|
|
||||||
nImage = -1
|
|
||||||
EndIf
|
|
||||||
;Define this tile image nb
|
;Define this tile image nb
|
||||||
*Tile\nImage = nImage
|
*Tile\nImage = nImage
|
||||||
|
UnlockMutex(PBMap\MemCache\Images(key)\Mutex)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure DrawTile(*Tile.Tile)
|
Procedure DrawTile(*Tile.Tile)
|
||||||
@@ -584,7 +588,7 @@ Module PBMap
|
|||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
;-**** Clean Mem Cache
|
;-**** Clean Mem Cache
|
||||||
ForEach PBMap\MemCache\Images()
|
;TODO in development, by now there's many cache problem as the loading thread could be perturbed
|
||||||
;GadgetWidth(PBMap\Gadget)/PBMap\TileSize
|
;GadgetWidth(PBMap\Gadget)/PBMap\TileSize
|
||||||
Protected MaxNbTile.l
|
Protected MaxNbTile.l
|
||||||
If GadgetWidth(PBMap\Gadget)>GadgetHeight(PBMap\Gadget)
|
If GadgetWidth(PBMap\Gadget)>GadgetHeight(PBMap\Gadget)
|
||||||
@@ -594,10 +598,17 @@ Module PBMap
|
|||||||
EndIf
|
EndIf
|
||||||
Protected Scale.d= 40075*Cos(Radian(PBMap\TargetLocation\Latitude))/Pow(2,PBMap\Zoom)
|
Protected Scale.d= 40075*Cos(Radian(PBMap\TargetLocation\Latitude))/Pow(2,PBMap\Zoom)
|
||||||
Protected Limit.d=Scale*(MaxNbTile)*1.5
|
Protected Limit.d=Scale*(MaxNbTile)*1.5
|
||||||
|
Debug "Cache cleaning"
|
||||||
|
ForEach PBMap\MemCache\Images()
|
||||||
Protected Distance.d = HaversineInKM(@PBMap\MemCache\Images()\Location, @PBMap\TargetLocation)
|
Protected Distance.d = HaversineInKM(@PBMap\MemCache\Images()\Location, @PBMap\TargetLocation)
|
||||||
Debug "Limit:"+StrD(Limit)+" Distance:"+StrD(Distance)
|
Debug "Limit:"+StrD(Limit)+" Distance:"+StrD(Distance)
|
||||||
If Distance>Limit
|
If Distance>Limit And IsImage(PBMap\MemCache\Images()\nImage)
|
||||||
|
LockMutex(PBMap\MemCache\Images()\Mutex)
|
||||||
Debug "delete"
|
Debug "delete"
|
||||||
|
Debug PBMap\MemCache\Images()
|
||||||
|
FreeImage(PBMap\MemCache\Images()\nImage)
|
||||||
|
UnlockMutex(PBMap\MemCache\Images()\Mutex)
|
||||||
|
FreeMutex(PBMap\MemCache\Images()\Mutex)
|
||||||
DeleteMapElement(PBMap\MemCache\Images())
|
DeleteMapElement(PBMap\MemCache\Images())
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
@@ -984,7 +995,7 @@ Module PBMap
|
|||||||
;New move values
|
;New move values
|
||||||
PBMap\Position\x - MouseX
|
PBMap\Position\x - MouseX
|
||||||
PBMap\Position\y - MouseY
|
PBMap\Position\y - MouseY
|
||||||
;Fill parameters and signal the drawing thread
|
;Fill parameters and send a signal to the drawing thread
|
||||||
LockMutex(PBMap\Drawing\Mutex)
|
LockMutex(PBMap\Drawing\Mutex)
|
||||||
;PBMap tile position in tile.decimal
|
;PBMap tile position in tile.decimal
|
||||||
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
|
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
|
||||||
@@ -992,9 +1003,9 @@ Module PBMap
|
|||||||
PBMap\Drawing\PassNb = 1
|
PBMap\Drawing\PassNb = 1
|
||||||
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
|
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
|
||||||
UnlockMutex(PBMap\Drawing\Mutex)
|
UnlockMutex(PBMap\Drawing\Mutex)
|
||||||
EndIf
|
|
||||||
;Start drawing
|
;Start drawing
|
||||||
SignalSemaphore(PBMap\Drawing\Semaphore)
|
SignalSemaphore(PBMap\Drawing\Semaphore)
|
||||||
|
EndIf
|
||||||
;If CallBackLocation send Location to function
|
;If CallBackLocation send Location to function
|
||||||
If PBMap\CallBackLocation > 0
|
If PBMap\CallBackLocation > 0
|
||||||
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
||||||
@@ -1167,8 +1178,9 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
EndIf
|
EndIf
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; CursorPosition = 1132
|
; ExecutableFormat = Console
|
||||||
; FirstLine = 1123
|
; CursorPosition = 595
|
||||||
|
; FirstLine = 581
|
||||||
; Folding = ---------
|
; Folding = ---------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user