No more flickering, bugfix

This commit is contained in:
djes
2016-07-26 20:46:18 +02:00
parent 8c2f59801b
commit b5ae9895a6

23
osm.pb
View File

@@ -112,7 +112,6 @@ Module OSM
Moving.i Moving.i
Dirty.i ;To signal that drawing need a refresh Dirty.i ;To signal that drawing need a refresh
LoadingMutex.i LoadingMutex.i
DrawingMutex.i
;CurlMutex.i ;seems that I can't thread curl ! :((((( ;CurlMutex.i ;seems that I can't thread curl ! :(((((
List TilesThreads.TileThread() List TilesThreads.TileThread()
@@ -236,7 +235,6 @@ Module OSM
OSM\TileSize = 256 OSM\TileSize = 256
OSM\MemCache\Mutex = CreateMutex() OSM\MemCache\Mutex = CreateMutex()
OSM\LoadingMutex = CreateMutex() OSM\LoadingMutex = CreateMutex()
OSM\DrawingMutex = CreateMutex()
;OSM\CurlMutex = CreateMutex() ;OSM\CurlMutex = CreateMutex()
OSM\Dirty = #False OSM\Dirty = #False
OSM\Drawing\Semaphore = CreateSemaphore() OSM\Drawing\Semaphore = CreateSemaphore()
@@ -429,15 +427,10 @@ Module OSM
Debug "Image buffer " + Str(*Buffer) Debug "Image buffer " + Str(*Buffer)
If *Buffer If *Buffer
LockMutex(OSM\LoadingMutex)
nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer))
UnlockMutex(OSM\LoadingMutex)
If IsImage(nImage) If IsImage(nImage)
Debug "Load from web " + TileURL + " as Tile nb " + nImage Debug "Load from web " + TileURL + " as Tile nb " + nImage
LockMutex(OSM\LoadingMutex)
SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG)
UnlockMutex(OSM\LoadingMutex)
FreeMemory(*Buffer) FreeMemory(*Buffer)
Else Else
Debug "Can't catch image " + TileURL Debug "Can't catch image " + TileURL
@@ -458,7 +451,6 @@ Module OSM
Protected nImage.i = -1 Protected nImage.i = -1
LockMutex(OSM\LoadingMutex) LockMutex(OSM\LoadingMutex)
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)
@@ -496,8 +488,6 @@ Module OSM
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)
LockMutex(OSM\DrawingMutex)
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))
@@ -507,8 +497,6 @@ Module OSM
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 EndIf
StopVectorDrawing()
UnlockMutex(OSM\DrawingMutex)
EndProcedure EndProcedure
@@ -642,13 +630,11 @@ Module OSM
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)
LockMutex(OSM\DrawingMutex)
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
DrawTiles(*Drawing)
DrawTrack(*Drawing) DrawTrack(*Drawing)
Pointer(CenterX, CenterY, #Red) Pointer(CenterX, CenterY, #Red)
StopVectorDrawing() StopVectorDrawing()
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
@@ -755,10 +741,7 @@ Module OSM
OSM\Drawing\PassNb = 1 OSM\Drawing\PassNb = 1
;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 "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\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y)
;EndIf ;EndIf
UnlockMutex(OSM\Drawing\Mutex) UnlockMutex(OSM\Drawing\Mutex)
;Start drawing ;Start drawing
@@ -877,8 +860,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x64) ; IDE Options = PureBasic 5.42 LTS (Windows - x64)
; CursorPosition = 332 ; CursorPosition = 635
; FirstLine = 531 ; FirstLine = 613
; Folding = ----- ; Folding = -----
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread