This commit is contained in:
djes
2016-07-25 21:32:50 +02:00
parent 0421511859
commit c32b604d13

99
osm.pb
View File

@@ -241,7 +241,6 @@ Module OSM
OSM\LoadingMutex = CreateMutex() OSM\LoadingMutex = CreateMutex()
OSM\DrawingMutex = CreateMutex() OSM\DrawingMutex = CreateMutex()
;OSM\CurlMutex = CreateMutex() ;OSM\CurlMutex = CreateMutex()
OSM\Moving = #False
OSM\Dirty = #False OSM\Dirty = #False
OSM\Drawing\Semaphore = CreateSemaphore() OSM\Drawing\Semaphore = CreateSemaphore()
OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Mutex = CreateMutex()
@@ -463,32 +462,30 @@ Module OSM
LockMutex(OSM\LoadingMutex) LockMutex(OSM\LoadingMutex)
If OSM\Moving = #False LockMutex(OSM\MemCache\Mutex)
LockMutex(OSM\MemCache\Mutex) *CacheImagePtr = AddElement(OSM\MemCache\Image())
*CacheImagePtr = AddElement(OSM\MemCache\Image()) Debug " CacheImagePtr : " + Str(*CacheImagePtr)
Debug " CacheImagePtr : " + Str(*CacheImagePtr) OSM\MemCache\Image()\xTile = *Tile\OSMTileX
OSM\MemCache\Image()\xTile = *Tile\OSMTileX OSM\MemCache\Image()\yTile = *Tile\OSMTileY
OSM\MemCache\Image()\yTile = *Tile\OSMTileY OSM\MemCache\Image()\Zoom = *Tile\OSMZoom
OSM\MemCache\Image()\Zoom = *Tile\OSMZoom OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro
OSM\MemCache\Image()\nImage = -1 ;By now, this tile is in "loading" state, for thread synchro UnlockMutex(OSM\MemCache\Mutex)
UnlockMutex(OSM\MemCache\Mutex) nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
nImage = GetTileFromHDD(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) If nImage = -1
If nImage = -1 And OSM\Moving = #False nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
EndIf
LockMutex(OSM\MemCache\Mutex)
If nImage <> -1 And OSM\Moving = #False
Debug "Adding tile " + Str(nImage) + " to mem cache"
;AddTileToMemCache(Zoom, XTile, YTile, nImage)
OSM\MemCache\Image()\nImage = nImage
Debug "Image nb " + Str(nImage) + " successfully added to mem cache"
Else
Debug "Error GetImageThread procedure, tile not loaded - Zoom:" + Str(*Tile\OSMZoom) + " X:" + Str(*Tile\OSMTileX) + " Y:" + Str(*Tile\OSMTileY)
DeleteElement(OSM\MemCache\Image())
nImage = -1
EndIf
UnlockMutex(OSM\MemCache\Mutex)
EndIf EndIf
LockMutex(OSM\MemCache\Mutex)
If nImage <> -1
Debug "Adding tile " + Str(nImage) + " to mem cache"
;AddTileToMemCache(Zoom, XTile, YTile, nImage)
OSM\MemCache\Image()\nImage = nImage
Debug "Image nb " + Str(nImage) + " successfully added to mem cache"
Else
Debug "Error GetImageThread procedure, tile not loaded - Zoom:" + Str(*Tile\OSMZoom) + " X:" + Str(*Tile\OSMTileX) + " Y:" + Str(*Tile\OSMTileY)
DeleteElement(OSM\MemCache\Image())
nImage = -1
EndIf
UnlockMutex(OSM\MemCache\Mutex)
*Tile\nImage = nImage *Tile\nImage = nImage
UnlockMutex(OSM\LoadingMutex) UnlockMutex(OSM\LoadingMutex)
@@ -503,19 +500,17 @@ Module OSM
Debug " at coords " + Str(x) + "," + Str(y) Debug " at coords " + Str(x) + "," + Str(y)
LockMutex(OSM\DrawingMutex) LockMutex(OSM\DrawingMutex)
If OSM\Moving = #False ;Quit before drawing StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) If IsImage(*Tile\nImage)
If IsImage(*Tile\nImage) MovePathCursor(x, y)
MovePathCursor(x, y) DrawVectorImage(ImageID(*Tile\nImage))
DrawVectorImage(ImageID(*Tile\nImage)) 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 ;Signal that this image is missing so we should have to redraw
OSM\Drawing\Dirty = #True ;Signal that this image is missing so we should have to redraw
EndIf
StopVectorDrawing()
EndIf EndIf
StopVectorDrawing()
UnlockMutex(OSM\DrawingMutex) UnlockMutex(OSM\DrawingMutex)
EndProcedure EndProcedure
@@ -538,9 +533,10 @@ Module OSM
For y = - ny To ny For y = - ny To ny
For x = - nx To nx For x = - nx To nx
If OSM\Moving ;Was quiting the loop if a move occured, giving maybe smoother movement
Break 2 ;If OSM\Moving
EndIf ; Break 2
;EndIf
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile)) Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
If *NewTile If *NewTile
@@ -633,24 +629,21 @@ Module OSM
Debug "--------- Main drawing thread ------------" Debug "--------- Main drawing thread ------------"
LockMutex(OSM\Drawing\Mutex) ; Only one main drawing thread at once LockMutex(OSM\Drawing\Mutex) ; Only one main drawing thread at once
OSM\Drawing\Dirty = #False OSM\Drawing\Dirty = #False
Protected CenterX = GadgetWidth(OSM\Gadget) / 2 Protected CenterX = GadgetWidth(OSM\Gadget) / 2
Protected CenterY = GadgetHeight(OSM\Gadget) / 2 Protected CenterY = GadgetHeight(OSM\Gadget) / 2
DrawTiles(*Drawing) DrawTiles(*Drawing)
LockMutex(OSM\DrawingMutex) LockMutex(OSM\DrawingMutex)
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
DrawTrack(*Drawing) DrawTrack(*Drawing)
Pointer(CenterX, CenterY, #Red) Pointer(CenterX, CenterY, #Red)
StopVectorDrawing() StopVectorDrawing()
UnlockMutex(OSM\DrawingMutex) UnlockMutex(OSM\DrawingMutex)
;- Redraw ;- Redraw
;If something was not correctly drawn, redraw after a while ;If something was not correctly drawn, redraw after a while
If OSM\Drawing\Dirty And OSM\Moving = #False If OSM\Drawing\Dirty
Debug "Something was dirty ! We try again to redraw" Debug "Something was dirty ! We try again to redraw"
;Delay(250) ;Delay(250)
OSM\Drawing\PassNb + 1 OSM\Drawing\PassNb + 1
@@ -659,12 +652,13 @@ Module OSM
UnlockMutex(OSM\Drawing\Mutex) UnlockMutex(OSM\Drawing\Mutex)
Until OSM\Drawing\End Until OSM\Drawing\End
EndProcedure EndProcedure
Procedure SetLocation(latitude.d, longitude.d, zoom = 15) Procedure SetLocation(latitude.d, longitude.d, zoom = 15)
If zoom > OSM\ZoomMax : zoom = OSM\ZoomMax : EndIf If zoom > OSM\ZoomMax : zoom = OSM\ZoomMax : EndIf
If zoom < OSM\ZoomMin : zoom = OSM\ZoomMin : EndIf If zoom < OSM\ZoomMin : zoom = OSM\ZoomMin : EndIf
OSM\Zoom = zoom OSM\Zoom = zoom
@@ -688,7 +682,7 @@ Module OSM
EndProcedure EndProcedure
Procedure SetZoom(Zoom.i, mode.i = #PB_Relative) Procedure SetZoom(Zoom.i, mode.i = #PB_Relative)
Select mode Select mode
Case #PB_Relative Case #PB_Relative
OSM\Zoom = OSM\Zoom + zoom OSM\Zoom = OSM\Zoom + zoom
@@ -738,10 +732,9 @@ Module OSM
OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY)
Case #PB_EventType_MouseMove Case #PB_EventType_MouseMove
If OSM\MoveStartingPoint\x <> - 1 If OSM\MoveStartingPoint\x <> - 1
;Need a refresh
OSM\Moving = #True
MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x
MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y
OSM\Moving = #True
;Old move values ;Old move values
OldX = OSM\Position\x OldX = OSM\Position\x
OldY = OSM\Position\y OldY = OSM\Position\y
@@ -759,8 +752,6 @@ Module OSM
;Moved to a new tile ? ;Moved to a new tile ?
;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) ;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize))
;Debug "--- New tile" ;Debug "--- New tile"
;*Drawing\x = TileX
;*Drawing\y = TileY
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)
Debug "OSM\TargetTile\x " + StrD(OSM\Drawing\x) + " ; OSM\TargetTile\y " + StrD(OSM\Drawing\y) Debug "OSM\TargetTile\x " + StrD(OSM\Drawing\x) + " ; OSM\TargetTile\y " + StrD(OSM\Drawing\y)
@@ -881,8 +872,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x64) ; IDE Options = PureBasic 5.42 LTS (Windows - x64)
; CursorPosition = 659 ; CursorPosition = 635
; FirstLine = 626 ; FirstLine = 614
; Folding = ----- ; Folding = -----
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread