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

31
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,7 +462,6 @@ 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)
@@ -473,11 +471,11 @@ Module OSM
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 And OSM\Moving = #False If nImage = -1
nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY) nImage = GetTileFromWeb(*Tile\OSMZoom, *Tile\OSMTileX, *Tile\OSMTileY)
EndIf EndIf
LockMutex(OSM\MemCache\Mutex) LockMutex(OSM\MemCache\Mutex)
If nImage <> -1 And OSM\Moving = #False If nImage <> -1
Debug "Adding tile " + Str(nImage) + " to mem cache" Debug "Adding tile " + Str(nImage) + " to mem cache"
;AddTileToMemCache(Zoom, XTile, YTile, nImage) ;AddTileToMemCache(Zoom, XTile, YTile, nImage)
OSM\MemCache\Image()\nImage = nImage OSM\MemCache\Image()\nImage = nImage
@@ -488,7 +486,6 @@ Module OSM
nImage = -1 nImage = -1
EndIf EndIf
UnlockMutex(OSM\MemCache\Mutex) UnlockMutex(OSM\MemCache\Mutex)
EndIf
*Tile\nImage = nImage *Tile\nImage = nImage
UnlockMutex(OSM\LoadingMutex) UnlockMutex(OSM\LoadingMutex)
@@ -503,7 +500,6 @@ 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)
@@ -515,7 +511,6 @@ Module OSM
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 EndIf
StopVectorDrawing() StopVectorDrawing()
EndIf
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,14 +629,11 @@ 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)
@@ -650,7 +643,7 @@ Module OSM
;- 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,6 +652,7 @@ Module OSM
UnlockMutex(OSM\Drawing\Mutex) UnlockMutex(OSM\Drawing\Mutex)
Until OSM\Drawing\End Until OSM\Drawing\End
EndProcedure EndProcedure
@@ -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