code cleanup

This commit is contained in:
djes
2016-08-25 12:52:36 +02:00
parent 46d4a37c98
commit a4f2ea5bb7

View File

@@ -26,7 +26,7 @@ UsePNGImageEncoder()
DeclareModule PBMap DeclareModule PBMap
;-Show debug infos ;-Show debug infos
Global Verbose = #True Global Verbose = #True
Global MyDebugLevel = 1 Global MyDebugLevel = 3
Global Proxy = #False Global Proxy = #False
Declare InitPBMap() Declare InitPBMap()
Declare SetMapServer(ServerURL.s="http://tile.openstreetmap.org/",TileSize.l=256,ZoomMin.l=0,ZoomMax.l=18) Declare SetMapServer(ServerURL.s="http://tile.openstreetmap.org/",TileSize.l=256,ZoomMin.l=0,ZoomMax.l=18)
@@ -103,8 +103,8 @@ Module PBMap
Structure ImgMemCach Structure ImgMemCach
nImage.i nImage.i
Location.Location ;Location.Location
Mutex.i ;Mutex.i
EndStructure EndStructure
Structure TileMemCach Structure TileMemCach
@@ -184,8 +184,8 @@ Module PBMap
Procedure.i CurlReceiveHTTPToFile(URL$, DestFileName$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="") Procedure.i CurlReceiveHTTPToFile(URL$, DestFileName$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="")
Protected *Buffer, curl.i, Timeout.i, res.i Protected *Buffer, curl.i, Timeout.i, res.i
Protected FileHandle.i Protected FileHandle.i
MyDebug("ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$) MyDebug("ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$, 3)
MyDebug(" to file : " + DestFileName$) MyDebug(" to file : " + DestFileName$, 3)
FileHandle = CreateFile(#PB_Any, DestFileName$) FileHandle = CreateFile(#PB_Any, DestFileName$)
If FileHandle And Len(URL$) If FileHandle And Len(URL$)
curl = curl_easy_init() curl = curl_easy_init()
@@ -218,11 +218,11 @@ Module PBMap
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction()) curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction())
res = curl_easy_perform(curl) res = curl_easy_perform(curl)
If res <> #CURLE_OK If res <> #CURLE_OK
MyDebug("CURL problem") MyDebug("CURL problem", 3)
EndIf EndIf
curl_easy_cleanup(curl) curl_easy_cleanup(curl)
Else Else
MyDebug("Can't init CURL") MyDebug("Can't init CURL", 3)
EndIf EndIf
CloseFile(FileHandle) CloseFile(FileHandle)
ProcedureReturn FileSize(DestFileName$) ProcedureReturn FileSize(DestFileName$)
@@ -245,7 +245,7 @@ Module PBMap
PBMap\Dirty = #False PBMap\Dirty = #False
PBMap\Drawing\Mutex = CreateMutex() PBMap\Drawing\Mutex = CreateMutex()
PBMap\Drawing\Semaphore = CreateSemaphore() PBMap\Drawing\Semaphore = CreateSemaphore()
PBMap\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected PBMap\EditMarkerIndex = -1 ;Initialised with "no marker selected"
PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold) PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
;-Options ;-Options
PBMap\Options\WheelMouseRelative = #True PBMap\Options\WheelMouseRelative = #True
@@ -289,10 +289,12 @@ Module PBMap
EndProcedure EndProcedure
Procedure Quit() Procedure Quit()
;kill main drawing thread (nicer than KillThread(PBMap\MainDrawingThread)) ;Ask main drawing thread to stop and wait for it (nicer than KillThread(PBMap\MainDrawingThread))
LockMutex(PBMap\Drawing\Mutex) LockMutex(PBMap\Drawing\Mutex)
PBMap\Drawing\End = #True PBMap\Drawing\End = #True
;KillThread(PBMap\MainDrawingThread)
UnlockMutex(PBMap\Drawing\Mutex) UnlockMutex(PBMap\Drawing\Mutex)
Repeat : Until Not IsThread(PBMap\MainDrawingThread)
;wait for loading threads to finish nicely ;wait for loading threads to finish nicely
ResetList(PBMap\TilesThreads()) ResetList(PBMap\TilesThreads())
While NextElement(PBMap\TilesThreads()) While NextElement(PBMap\TilesThreads())
@@ -547,7 +549,7 @@ Module PBMap
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
If *NewTile If *NewTile
With *NewTile With *NewTile
;Keep a track of tiles and eventually threads associated (to free memory) ;Keep a track of tiles, and eventually associated threads, to free memory
AddElement(PBMap\TilesThreads()) AddElement(PBMap\TilesThreads())
PBMap\TilesThreads()\Tile = *NewTile PBMap\TilesThreads()\Tile = *NewTile
;New tile parameters ;New tile parameters
@@ -556,12 +558,12 @@ Module PBMap
\PBMapTileX = tx + x \PBMapTileX = tx + x
\PBMapTileY = ty + y \PBMapTileY = ty + y
\PBMapZoom = PBMap\Zoom \PBMapZoom = PBMap\Zoom
\key = "Z" + RSet(Str(\PBMapZoom), 4, "0") + "X" + RSet(Str(\PBMapTileX), 8, "0") + "Y" + RSet(Str(\PBMapTileY), 8, "0") \key = "Z" + RSet(Str(\PBMapZoom), 4, "0") + "X" + RSet(Str(\PBMapTileX), 8, "0") + "Y" + RSet(Str(\PBMapTileY), 8, "0") ;Unique identifier
;Check if the image exists ;Check if the image exists
\nImage = GetTileFromMem(\key) \nImage = GetTileFromMem(\key)
If \nImage = -1 If \nImage = -1
;If not, load it in the background ;If not, load it in the background
If AddMapElement(PBMap\MemCache\Images(), \key) ;Add the image to the cache *only* in this loop If AddMapElement(PBMap\MemCache\Images(), \key) ;Add the image to the cache, once in this loop
\GetImageThread = CreateThread(@GetImageThread(), *NewTile) \GetImageThread = CreateThread(@GetImageThread(), *NewTile)
PBMap\TilesThreads()\GetImageThread = \GetImageThread PBMap\TilesThreads()\GetImageThread = \GetImageThread
MyDebug(" Creating get image thread nb " + Str(\GetImageThread), 2) MyDebug(" Creating get image thread nb " + Str(\GetImageThread), 2)
@@ -771,6 +773,8 @@ Module PBMap
VectorSourceColor(RGBA(0, 0, 0, 80)) VectorSourceColor(RGBA(0, 0, 0, 80))
MovePathCursor(50,50) MovePathCursor(50,50)
DrawVectorText(Str(MapSize(PBMap\MemCache\Images()))) DrawVectorText(Str(MapSize(PBMap\MemCache\Images())))
MovePathCursor(50,60)
DrawVectorText(Str(ListSize(PBMap\TilesThreads())))
StopVectorDrawing() StopVectorDrawing()
;Redraw ;Redraw
; If something was not correctly drawn, redraw after a while ; If something was not correctly drawn, redraw after a while
@@ -1187,8 +1191,6 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; ExecutableFormat = Console ; ExecutableFormat = Console
; CursorPosition = 445
; FirstLine = 442
; Folding = --------- ; Folding = ---------
; EnableThread ; EnableThread
; EnableXP ; EnableXP