Debug commented

This commit is contained in:
djes
2016-07-28 22:31:29 +02:00
parent 489e9651b6
commit 6c6941108a

70
osm.pb
View File

@@ -136,13 +136,13 @@ Module OSM
If *ReceiveHTTPToMemoryBuffer = 0 If *ReceiveHTTPToMemoryBuffer = 0
*ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper) *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper)
If *ReceiveHTTPToMemoryBuffer = 0 If *ReceiveHTTPToMemoryBuffer = 0
Debug "Problem allocating memory" ; Debug "Problem allocating memory"
End End
EndIf EndIf
Else Else
*ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper) *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper)
If *ReceiveHTTPToMemoryBuffer = 0 If *ReceiveHTTPToMemoryBuffer = 0
Debug "Problem reallocating memory" ; Debug "Problem reallocating memory"
End End
EndIf EndIf
EndIf EndIf
@@ -179,7 +179,7 @@ Module OSM
If Len(ProxyPort$) If Len(ProxyPort$)
ProxyURL$ + ":" + ProxyPort$ ProxyURL$ + ":" + ProxyPort$
EndIf EndIf
Debug ProxyURL$ ; Debug ProxyURL$
curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$)) curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$))
If Len(ProxyUser$) If Len(ProxyUser$)
If Len(ProxyPassword$) If Len(ProxyPassword$)
@@ -201,22 +201,22 @@ Module OSM
*ReceiveHTTPToMemoryBuffer = #Null *ReceiveHTTPToMemoryBuffer = #Null
ReceiveHTTPToMemoryBufferPtr = 0 ReceiveHTTPToMemoryBufferPtr = 0
Else Else
Debug "Problem allocating buffer" ; Debug "Problem allocating buffer"
EndIf EndIf
;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me. ;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me.
Else Else
Debug "CURL NOT OK" ; Debug "CURL NOT OK"
EndIf EndIf
curl_easy_cleanup(curl) curl_easy_cleanup(curl)
Else Else
Debug "Can't Init CURL" ; Debug "Can't Init CURL"
EndIf EndIf
EndIf EndIf
Debug "Curl Buffer : " + Str(*Buffer) ; Debug "Curl Buffer : " + Str(*Buffer)
ProcedureReturn *Buffer ProcedureReturn *Buffer
@@ -289,8 +289,8 @@ Module OSM
Protected LatRad.d = Radian(*Location\Latitude) Protected LatRad.d = Radian(*Location\Latitude)
*Tile\x = n * ( (*Location\Longitude + 180.0) / 360.0) *Tile\x = n * ( (*Location\Longitude + 180.0) / 360.0)
*Tile\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0 *Tile\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0
Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude) ; Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude)
Debug "Tile X : " + Str(*Tile\x) + " ; Tile Y : " + Str(*Tile\y) ; Debug "Tile X : " + Str(*Tile\x) + " ; Tile Y : " + Str(*Tile\y)
EndProcedure EndProcedure
;*** Converts tile.decimal to coords ;*** Converts tile.decimal to coords
@@ -365,13 +365,13 @@ Module OSM
Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0") Protected key.s = "Z" + RSet(Str(Zoom), 4, "0") + "X" + RSet(Str(XTile), 8, "0") + "Y" + RSet(Str(YTile), 8, "0")
Debug "Check if we have this image in memory" ; Debug "Check if we have this image in memory"
If FindMapElement(OSM\MemCache\Images(), key) If FindMapElement(OSM\MemCache\Images(), key)
Debug "Key : " + key + " found !" ; Debug "Key : " + key + " found !"
ProcedureReturn OSM\MemCache\Images()\nImage ProcedureReturn OSM\MemCache\Images()\nImage
Else Else
Debug "Key : " + key + " not found !" ; Debug "Key : " + key + " not found !"
ProcedureReturn -1 ProcedureReturn -1
EndIf EndIf
@@ -382,14 +382,14 @@ Module OSM
Protected nImage.i Protected nImage.i
Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png"
Debug "Check if we have this image on HDD" ; Debug "Check if we have this image on HDD"
If FileSize(OSM\HDDCachePath + cacheFile) > 0 If FileSize(OSM\HDDCachePath + cacheFile) > 0
nImage = LoadImage(#PB_Any, OSM\HDDCachePath + CacheFile) nImage = LoadImage(#PB_Any, OSM\HDDCachePath + CacheFile)
If IsImage(nImage) If IsImage(nImage)
Debug "Load from HDD Tile " + CacheFile ; Debug "Load from HDD Tile " + CacheFile
ProcedureReturn nImage ProcedureReturn nImage
EndIf EndIf
@@ -407,7 +407,7 @@ Module OSM
Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png"
Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png"
Debug "Check if we have this image on Web" ; Debug "Check if we have this image on Web"
If Proxy If Proxy
;LockMutex(OSM\CurlMutex) ;Seems no more necessary ;LockMutex(OSM\CurlMutex) ;Seems no more necessary
@@ -416,21 +416,21 @@ Module OSM
Else Else
*Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous
EndIf EndIf
Debug "Image buffer " + Str(*Buffer) ; Debug "Image buffer " + Str(*Buffer)
If *Buffer If *Buffer
nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer))
If IsImage(nImage) If IsImage(nImage)
Debug "Load from web " + TileURL + " as Tile nb " + nImage ; Debug "Load from web " + TileURL + " as Tile nb " + nImage
SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG)
FreeMemory(*Buffer) FreeMemory(*Buffer)
Else Else
Debug "Can't catch image " + TileURL ; Debug "Can't catch image " + TileURL
nImage = -1 nImage = -1
;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer))
EndIf EndIf
Else Else
Debug "Problem loading from web " + TileURL ; Debug "Problem loading from web " + TileURL
EndIf EndIf
ProcedureReturn nImage ProcedureReturn nImage
@@ -450,10 +450,10 @@ Module OSM
EndIf EndIf
If nImage <> -1 If nImage <> -1
OSM\MemCache\Images(key)\nImage = nImage OSM\MemCache\Images(key)\nImage = nImage
Debug "Image nb " + Str(nImage) + " successfully added to mem cache" ; Debug "Image nb " + Str(nImage) + " successfully added to mem cache"
Debug "With the following key : " + key ; Debug "With the following key : " + key
Else Else
Debug "Error GetImageThread procedure, image not loaded - " + key ; Debug "Error GetImageThread procedure, image not loaded - " + key
nImage = -1 nImage = -1
EndIf EndIf
;Define this tile image nb ;Define this tile image nb
@@ -466,8 +466,8 @@ Module OSM
Protected x = *Tile\x Protected x = *Tile\x
Protected y = *Tile\y Protected y = *Tile\y
Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX) ; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX)
Debug " at coords " + Str(x) + "," + Str(y) ; Debug " at coords " + Str(x) + "," + Str(y)
If IsImage(*Tile\nImage) If IsImage(*Tile\nImage)
MovePathCursor(x, y) MovePathCursor(x, y)
@@ -475,7 +475,7 @@ Module OSM
MovePathCursor(x, y) MovePathCursor(x, y)
DrawVectorText(Str(x) + ", " + Str(y)) DrawVectorText(Str(x) + ", " + Str(y))
Else Else
Debug "Image missing" ; Debug "Image missing"
OSM\Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw OSM\Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw
EndIf EndIf
@@ -498,7 +498,7 @@ Module OSM
Protected DeltaX = *Drawing\x * OSM\TileSize - (tx * OSM\TileSize) Protected DeltaX = *Drawing\x * OSM\TileSize - (tx * OSM\TileSize)
Protected DeltaY = *Drawing\y * OSM\TileSize - (ty * OSM\TileSize) Protected DeltaY = *Drawing\y * OSM\TileSize - (ty * OSM\TileSize)
Debug "Drawing tiles" ; Debug "Drawing tiles"
For y = - ny - 1 To ny + 1 For y = - ny - 1 To ny + 1
For x = - nx - 1 To nx + 1 For x = - nx - 1 To nx + 1
@@ -529,7 +529,7 @@ Module OSM
;If not, load it in the background ;If not, load it in the background
\GetImageThread = CreateThread(@GetImageThread(), *NewTile) \GetImageThread = CreateThread(@GetImageThread(), *NewTile)
OSM\TilesThreads()\GetImageThread = \GetImageThread OSM\TilesThreads()\GetImageThread = \GetImageThread
Debug " Creating get image thread nb " + Str(\GetImageThread) ; Debug " Creating get image thread nb " + Str(\GetImageThread)
EndIf EndIf
DrawTile(*NewTile) DrawTile(*NewTile)
@@ -537,7 +537,7 @@ Module OSM
EndWith EndWith
Else Else
Debug" Error, can't create a new tile." ; Debug" Error, can't create a new tile."
Break 2 Break 2
EndIf EndIf
Next Next
@@ -635,7 +635,7 @@ Module OSM
WaitSemaphore(*Drawing\Semaphore) WaitSemaphore(*Drawing\Semaphore)
Debug "--------- Main drawing thread ------------" ; Debug "--------- Main drawing thread ------------"
Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterX = GadgetWidth(OSM\Gadget) / 2
Protected CenterY = GadgetHeight(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2
@@ -653,7 +653,7 @@ Module OSM
;If something was not correctly drawn, redraw after a while ;If something was not correctly drawn, redraw after a while
LockMutex(OSM\Drawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore) LockMutex(OSM\Drawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore)
If *Drawing\Dirty If *Drawing\Dirty
Debug "Something was dirty ! We try again to redraw" ; Debug "Something was dirty ! We try again to redraw"
;Delay(250) ;Delay(250)
*Drawing\PassNb + 1 *Drawing\PassNb + 1
SignalSemaphore(*Drawing\Semaphore) SignalSemaphore(*Drawing\Semaphore)
@@ -814,7 +814,7 @@ Module OSM
SelectElement(OSM\Marker(), OSM\EditMarkerIndex) SelectElement(OSM\Marker(), OSM\EditMarkerIndex)
Protected Tile.Tile Protected Tile.Tile
LatLon2XY(@OSM\Marker()\Location, @Tile) LatLon2XY(@OSM\Marker()\Location, @Tile)
Debug MouseX ; Debug MouseX
Tile\x + MouseX / OSM\TileSize Tile\x + MouseX / OSM\TileSize
Tile\y + MouseY / OSM\TileSize Tile\y + MouseY / OSM\TileSize
XY2LatLon(@Tile, @OSM\Marker()\Location) XY2LatLon(@Tile, @OSM\Marker()\Location)
@@ -852,10 +852,10 @@ Module OSM
Else ;Move Map Else ;Move Map
OSM\Drawing\x = OSM\Position\x / OSM\TileSize OSM\Drawing\x = OSM\Position\x / OSM\TileSize
OSM\Drawing\y = OSM\Position\y / OSM\TileSize OSM\Drawing\y = OSM\Position\y / OSM\TileSize
Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) ; Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y)
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
;Draw() ;Draw()
Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) ; Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y)
;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) ;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude))
;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) ;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude))
EndIf EndIf
@@ -1000,8 +1000,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x64) ; IDE Options = PureBasic 5.42 LTS (Windows - x64)
; CursorPosition = 850 ; CursorPosition = 840
; FirstLine = 771 ; FirstLine = 805
; Folding = ------ ; Folding = ------
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread