Alpha apparition + img loading update

This commit is contained in:
djes
2016-10-03 17:08:48 +02:00
parent a1f593c89b
commit 2fa810fb88

View File

@@ -908,18 +908,19 @@ Module PBMap
Procedure.i GetTile(key.s, URL.s, CacheFile.s) Procedure.i GetTile(key.s, URL.s, CacheFile.s)
; Try to find the tile in memory cache. If not found, add it, try To load it from the ; Try to find the tile in memory cache. If not found, add it, try To load it from the
; HDD, or launch a loading thread, and try again on the next drawing loop. ; HDD, or launch a loading thread, and try again on the next drawing loop.
Protected timg = -1 Protected img.i
If FindMapElement(PBMap\MemCache\Images(), key) Protected *timg.ImgMemCach = FindMapElement(PBMap\MemCache\Images(), key)
If *timg
MyDebug("Key : " + key + " found in memory cache!", 3) MyDebug("Key : " + key + " found in memory cache!", 3)
timg = PBMap\MemCache\Images()\nImage img = PBMap\MemCache\Images()\nImage
If timg <> -1 If img <> -1
MyDebug("Image : " + timg + " found in memory cache!", 3) MyDebug("Image : " + img + " found in memory cache!", 3)
;*** Cache management ;*** Cache management
; Move the newly used element to the last position of the time stack ; Move the newly used element to the last position of the time stack
SelectElement(PBMap\MemCache\ImagesTimeStack(), PBMap\MemCache\Images()\TimeStackPosition) SelectElement(PBMap\MemCache\ImagesTimeStack(), PBMap\MemCache\Images()\TimeStackPosition)
MoveElement(PBMap\MemCache\ImagesTimeStack(), #PB_List_Last) MoveElement(PBMap\MemCache\ImagesTimeStack(), #PB_List_Last)
;*** ;***
ProcedureReturn timg ProcedureReturn *timg
EndIf EndIf
Else Else
AddMapElement(PBMap\MemCache\Images(), key) AddMapElement(PBMap\MemCache\Images(), key)
@@ -948,20 +949,23 @@ Module PBMap
MyDebug("Key : " + key + " added in memory cache!", 3) MyDebug("Key : " + key + " added in memory cache!", 3)
PBMap\MemCache\Images()\nImage = -1 PBMap\MemCache\Images()\nImage = -1
EndIf EndIf
*timg = PBMap\MemCache\Images()
If PBMap\MemCache\Images()\Tile = 0 ; Check if a loading thread is not running If PBMap\MemCache\Images()\Tile = 0 ; Check if a loading thread is not running
MyDebug("Trying to load from HDD " + CacheFile, 3) MyDebug("Trying to load from HDD " + CacheFile, 3)
timg = GetTileFromHDD(CacheFile.s) img = GetTileFromHDD(CacheFile.s)
If timg <> -1 If img <> -1
MyDebug("Key : " + key + " found on HDD", 3) MyDebug("Key : " + key + " found on HDD", 3)
PBMap\MemCache\Images()\nImage = timg *timg\nImage = img
ProcedureReturn timg *timg\Alpha = 0
ProcedureReturn *timg
EndIf EndIf
MyDebug("Key : " + key + " not found on HDD", 3) MyDebug("Key : " + key + " not found on HDD", 3)
;Launch a new thread ;Launch a new thread
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
If *NewTile If *NewTile
With *NewTile With *NewTile
PBMap\MemCache\Images()\Tile = *NewTile *timg\Tile = *NewTile
*timg\Alpha = 0
;New tile parameters ;New tile parameters
\key = key \key = key
\URL = URL \URL = URL
@@ -975,16 +979,16 @@ Module PBMap
MyDebug(" Error, can't create a new tile loading thread", 3) MyDebug(" Error, can't create a new tile loading thread", 3)
EndIf EndIf
EndIf EndIf
ProcedureReturn timg ProcedureReturn *timg
EndProcedure EndProcedure
Procedure DrawTiles(*Drawing.DrawingParameters, Layer, alpha.i=255) Procedure DrawTiles(*Drawing.DrawingParameters, Layer)
Protected x.i, y.i,kq.q Protected x.i, y.i,kq.q
Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() ! Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() !
Protected ty = Int(*Drawing\TileCoordinates\y) Protected ty = Int(*Drawing\TileCoordinates\y)
Protected nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point Protected nx = *Drawing\CenterX / PBMap\TileSize ;How many tiles around the point
Protected ny = *Drawing\CenterY / PBMap\TileSize Protected ny = *Drawing\CenterY / PBMap\TileSize
Protected px, py, img, tilex,tiley, key.s Protected px, py, *timg.ImgMemCach, tilex, tiley, key.s
Protected URL.s, CacheFile.s Protected URL.s, CacheFile.s
Protected tilemax = 1<<PBMap\Zoom Protected tilemax = 1<<PBMap\Zoom
SelectElement(PBMap\Layers(), Layer) SelectElement(PBMap\Layers(), Layer)
@@ -1019,13 +1023,18 @@ Module PBMap
; Tile cache name based on y ; Tile cache name based on y
URL = PBMap\Layers()\ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png" URL = PBMap\Layers()\ServerURL + Str(PBMap\Zoom) + "/" + Str(tilex) + "/" + Str(tiley) + ".png"
CacheFile = DirName + "\" + Str(tiley) + ".png" CacheFile = DirName + "\" + Str(tiley) + ".png"
img = GetTile(key, URL, CacheFile) *timg = GetTile(key, URL, CacheFile)
If img <> -1 If *timg\nImage <> -1
MovePathCursor(px, py) MovePathCursor(px, py)
DrawVectorImage(ImageID(img), alpha) DrawVectorImage(ImageID(*timg\nImage), *timg\Alpha)
If *timg\Alpha < 240
*timg\Alpha + 16
Else
*timg\Alpha = 255
EndIf
Else Else
MovePathCursor(px, py) MovePathCursor(px, py)
DrawVectorImage(ImageID(PBMap\ImgLoading), alpha) DrawVectorImage(ImageID(PBMap\ImgLoading))
EndIf EndIf
Else Else
;If PBMap\Layers()\Name = "" ;If PBMap\Layers()\Name = ""
@@ -1073,7 +1082,7 @@ Module PBMap
sunit = " Km" sunit = " Km"
EndSelect EndSelect
VectorFont(FontID(PBMap\Font), 10) VectorFont(FontID(PBMap\Font), 10)
VectorSourceColor(RGBA(0, 0, 0,alpha)) VectorSourceColor(RGBA(0, 0, 0, alpha))
MovePathCursor(x,y) MovePathCursor(x,y)
DrawVectorText(StrD(Scale,3)+sunit) DrawVectorText(StrD(Scale,3)+sunit)
MovePathCursor(x,y+12) MovePathCursor(x,y+12)
@@ -2322,8 +2331,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 911 ; CursorPosition = 1037
; FirstLine = 895 ; FirstLine = 997
; Folding = ---------------- ; Folding = ----------------
; EnableThread ; EnableThread
; EnableXP ; EnableXP