Merging idle and mine

This commit is contained in:
djes
2016-08-30 12:44:23 +02:00
parent 108673b7f7
commit 2b2ffac2ee

161
PBMap.pb
View File

@@ -87,14 +87,11 @@ Module PBMap
GetImageThread.i
RetryNb.i
Layer.i
<<<<<<< HEAD
=======
EndStructure
Structure TileBounds
NorthWest.Position
SouthEast.Position
>>>>>>> refs/remotes/origin/idle
EndStructure
Structure DrawingParameters
@@ -167,10 +164,6 @@ Module PBMap
HDDCachePath.S ; Path where to load and save tiles downloaded from server
MemCache.TileMemCach ; Images in memory cache
;
<<<<<<< HEAD
=======
OnStage.i
>>>>>>> refs/remotes/origin/idle
Redraw.i
Moving.i
Dirty.i ; To signal that drawing need a refresh
@@ -189,10 +182,7 @@ Module PBMap
#PB_MAP_REDRAW = #PB_EventType_FirstCustomValue + 1
#PB_MAP_RETRY = #PB_EventType_FirstCustomValue + 2
<<<<<<< HEAD
#PB_MAP_TILE_CLEANUP = #PB_EventType_FirstCustomValue + 3
=======
>>>>>>> refs/remotes/origin/idle
;-Global variables
Global PBMap.PBMap, Null.i
@@ -359,12 +349,9 @@ Module PBMap
;Should not occur
KillThread(PBMap\MemCache\Images()\Tile\GetImageThread)
EndIf
<<<<<<< HEAD
Else
FreeMemory(PBMap\MemCache\Images()\Tile)
PBMap\MemCache\Images()\Tile = 0
=======
>>>>>>> refs/remotes/origin/idle
EndIf
Else
DeleteMapElement(PBMap\MemCache\Images())
@@ -531,11 +518,7 @@ Module PBMap
; SaveImage(timg, CacheFile, #PB_ImagePlugin_PNG)
; FreeImage(timg)
; Else
<<<<<<< HEAD
If SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG)
=======
If SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG,0,32)
>>>>>>> refs/remotes/origin/idle
If SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG, 0, 32)
MyDebug("Loaded from web " + TileURL + " as CacheFile " + CacheFile, 3)
Else
MyDebug("Loaded from web " + TileURL + " but cannot save to CacheFile " + CacheFile, 3)
@@ -559,39 +542,19 @@ Module PBMap
Repeat
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, *Tile\CacheFile, *Tile\Layer)
If nImage <> -1
<<<<<<< HEAD
MyDebug("Image key : " + *Tile\key + " web image loaded", 3)
=======
LockMutex(PBMap\TileThreadMutex)
PBMap\MemCache\Images(*Tile\key)\nImage = nImage
UnlockMutex(PBMap\TileThreadMutex)
MyDebug("Image key : " + *Tile\key + " web image loaded", 3)
PBMap\Dirty = #True
>>>>>>> refs/remotes/origin/idle
*Tile\RetryNb = 0
; PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_REDRAW, *Tile) ;If image is loaded from web, redraw
Else
MyDebug("Image key : " + *Tile\key + " web image not correctly loaded", 3)
<<<<<<< HEAD
Delay(1000)
=======
Delay(5000)
>>>>>>> refs/remotes/origin/idle
*Tile\RetryNb - 1
; PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_RETRY, *Tile) ;If image is not loaded, retry
EndIf
Until *Tile\RetryNb <= 0
<<<<<<< HEAD
*Tile\nImage = nImage
*Tile\RetryNb = -2 ;End of the thread
PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_TILE_CLEANUP, *Tile) ;To free memory outside the thread
=======
;End of the thread
LockMutex(PBMap\TileThreadMutex)
FreeMemory(PBMap\MemCache\Images(*Tile\key)\Tile)
PBMap\MemCache\Images(*Tile\key)\Tile = 0
UnlockMutex(PBMap\TileThreadMutex)
>>>>>>> refs/remotes/origin/idle
EndProcedure
Procedure.i GetTile(key.s, CacheFile.s, px.i, py.i, tilex.i, tiley.i, Layer.i)
@@ -607,7 +570,6 @@ Module PBMap
AddMapElement(PBMap\MemCache\Images(), key)
MyDebug("Key : " + key + " added in memory cache!", 3)
PBMap\MemCache\Images()\nImage = -1
<<<<<<< HEAD
EndIf
If PBMap\MemCache\Images()\Tile = 0 ;Check if a loading thread is not running
MyDebug("Trying to load from HDD " + CacheFile, 3)
@@ -618,19 +580,6 @@ Module PBMap
ProcedureReturn timg
EndIf
MyDebug("Key : " + key + " not found on HDD", 3)
=======
;UnlockMutex(PBMap\TileThreadMutex)
EndIf
If PBMap\MemCache\Images()\Tile = 0 ;Check if a loading thread is not running
MyDebug("Trying to load from HDD " + CacheFile)
timg = GetTileFromHDD(CacheFile.s)
If timg <> -1
MyDebug("Key : " + key + " found on HDD")
PBMap\MemCache\Images()\nImage = timg
ProcedureReturn timg
EndIf
MyDebug("Key : " + key + " not found on HDD")
>>>>>>> refs/remotes/origin/idle
;Launch a new thread
Protected *NewTile.Tile = AllocateMemory(SizeOf(Tile))
If *NewTile
@@ -646,7 +595,6 @@ Module PBMap
\CacheFile = CacheFile
\Layer = Layer
\RetryNb = 5
<<<<<<< HEAD
\nImage = -1
MyDebug(" Creating get image thread nb " + Str(\GetImageThread) + " to get " + CacheFile, 3)
\GetImageThread = CreateThread(@GetImageThread(), *NewTile)
@@ -658,35 +606,6 @@ Module PBMap
ProcedureReturn timg
EndProcedure
=======
\GetImageThread = CreateThread(@GetImageThread(), *NewTile)
myDebug(" Creating get image thread nb " + Str(\GetImageThread))
EndWith
Else
MyDebug(" Error, can't create a new tile loading thread")
EndIf
EndIf
ProcedureReturn timg
EndProcedure
; Procedure DrawTile(*Tile.Tile)
; Protected x = *Tile\Position\x
; Protected y = *Tile\Position\y
; MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX), 2)
; MyDebug(" at coords " + Str(x) + "," + Str(y), 2)
; MovePathCursor(x, y)
; DrawVectorImage(ImageID(*Tile\nImage))
; EndProcedure
;
; Procedure DrawLoading(*Tile.Tile)
; Protected x = *Tile\Position\x
; Protected y = *Tile\Position\y
; Protected Text$ = "Loading"
; MyDebug(" Drawing tile nb " + " X : " + Str(*Tile\PBMapTileX) + " Y : " + Str(*Tile\PBMapTileX), 2)
; MyDebug(" at coords " + Str(x) + "," + Str(y))
; EndProcedure
>>>>>>> refs/remotes/origin/idle
Procedure DrawTiles(*Drawing.DrawingParameters, Layer.i, alpha.i=255)
;DisableDebugger
Protected x.i, y.i,kq.q
@@ -696,12 +615,6 @@ Module PBMap
Protected ny = *Drawing\CenterY / PBMap\TileSize
Protected px, py, img, tilex,tiley, key.s, CacheFile.s
MyDebug("Drawing tiles")
*Drawing\Bounds\NorthWest\x = tx-nx-1
*Drawing\Bounds\NorthWest\y = ty-ny-1
*Drawing\Bounds\SouthEast\x = tx+nx+1
*Drawing\Bounds\SouthEast\y = ty+ny+1
For y = - ny - 1 To ny + 1
For x = - nx - 1 To nx + 1
; If PBMap\Moving ;If drawing was threaded, this would exit the loop when the user is moving
@@ -709,11 +622,7 @@ Module PBMap
; EndIf
px = *Drawing\CenterX + x * PBMap\TileSize - *Drawing\DeltaX
py = *Drawing\CenterY + y * PBMap\TileSize - *Drawing\DeltaY
<<<<<<< HEAD
tilex = ((tx+x) % (1<<PBMap\Zoom))
=======
tilex = ((tx+x) % (1<< PBMap\Zoom))
>>>>>>> refs/remotes/origin/idle
tiley = ty+y
kq = Layer | (pbmap\zoom << 8) | (tilex << 16) | (tiley << 36)
key = Str(kq)
@@ -729,20 +638,6 @@ Module PBMap
EndIf
Next
Next
<<<<<<< HEAD
=======
; ;Free tile memory
; ;TODO : maybe get out this proc from drawtiles in a special "free ressources" task
; ForEach PBMap\TilesThreads()
; ;Check if there's no more loading thread
; If IsThread(PBMap\TilesThreads()\GetImageThread) = 0
; FreeMemory(PBMap\TilesThreads()\Tile)
; DeleteElement(PBMap\TilesThreads())
; EndIf
; Next
>>>>>>> refs/remotes/origin/idle
EndProcedure
; ;-**** Clean Mem Cache
@@ -812,9 +707,7 @@ Module PBMap
StrokePath(1)
EndProcedure
<<<<<<< HEAD
=======
Procedure DrawDegrees(*Drawing.DrawingParameters,alpha=192)
Procedure DrawDegrees(*Drawing.DrawingParameters,alpha=192)
Protected nx,ny,nx1,ny1,x,y,n,cx,dperpixel.d
Protected pos1.PixelPosition,pos2.PixelPosition,Degrees1.Location,degrees2.Location
@@ -837,19 +730,17 @@ Module PBMap
For x = nx To nx1
Degrees1\Longitude =x
Degrees2\Longitude =x+ 1
GetPixelCoordFromLocation(@Degrees1,@pos1)
MovePathCursor(pos1\x,pos1\y)
AddPathLine(pos2\x,pos1\y)
MovePathCursor(pos1\x,pos1\y)
AddPathLine(pos1\x,pos2\y)
GetPixelCoordFromLocation(@Degrees1,@pos1)
MovePathCursor(pos1\x,pos1\y)
AddPathLine(pos2\x,pos1\y)
MovePathCursor(pos1\x,pos1\y)
AddPathLine(pos1\x,pos2\y)
Next
Next
StrokePath(1)
EndProcedure
>>>>>>> refs/remotes/origin/idle
Procedure TrackPointer(x.i, y.i,dist.l)
Protected color.l
color=RGBA(0, 0, 0, 255)
@@ -941,10 +832,6 @@ Module PBMap
Procedure Drawing()
Protected *Drawing.DrawingParameters = @PBMap\Drawing
Protected Px.d, Py.d,a
<<<<<<< HEAD
=======
PBMap\OnStage = #True
>>>>>>> refs/remotes/origin/idle
PBMap\Dirty = #False
PBMap\Redraw = #False
;Precalc some values
@@ -975,11 +862,7 @@ Module PBMap
Protected ThreadCounter = 0
ForEach PBMap\MemCache\Images()
If PBMap\MemCache\Images()\Tile <> 0
<<<<<<< HEAD
If IsThread(PBMap\MemCache\Images()\Tile\GetImageThread)
=======
If PBMap\MemCache\Images()\Tile\GetImageThread <> 0
>>>>>>> refs/remotes/origin/idle
ThreadCounter + 1
EndIf
EndIf
@@ -987,10 +870,7 @@ Module PBMap
DrawVectorText(Str(ThreadCounter))
;If PBMap\Options\ShowScale
DrawScale(*Drawing,10,GadgetHeight(PBMAP\Gadget)-20,192)
<<<<<<< HEAD
=======
DrawDegrees(*Drawing,192)
>>>>>>> refs/remotes/origin/idle
DrawDegrees(*Drawing, 192)
;EndIf
StopVectorDrawing()
;If there was a problem while drawing, redraw
@@ -998,10 +878,6 @@ Module PBMap
; PBMap\Redraw = #True
; ;PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_REDRAW)
; EndIf
<<<<<<< HEAD
=======
PBMap\OnStage = #False
>>>>>>> refs/remotes/origin/idle
EndProcedure
Procedure Refresh()
@@ -1161,11 +1037,7 @@ Module PBMap
Procedure CanvasEvents()
Protected MouseX.i, MouseY.i
<<<<<<< HEAD
Protected Marker.Position, *Tile.Tile
=======
Protected Marker.Position
>>>>>>> refs/remotes/origin/idle
PBMap\Moving = #False
Select EventType()
Case #PB_EventType_MouseWheel
@@ -1239,7 +1111,6 @@ Module PBMap
Case #PB_MAP_RETRY
Debug "Reload"
PBMap\Redraw = #True
<<<<<<< HEAD
Case #PB_MAP_TILE_CLEANUP
*Tile = EventData()
;If PBMap\MemCache\Images(*Tile\key)\Tile\RetryNb = -2 ;Check the end of the thread
@@ -1249,17 +1120,12 @@ Module PBMap
PBMap\MemCache\Images(*Tile\key)\Tile = 0
PBMap\Redraw = #True
;EndIf
=======
>>>>>>> refs/remotes/origin/idle
EndSelect
EndProcedure
Procedure TimerEvents()
<<<<<<< HEAD
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty)
=======
If EventTimer() = PBMap\Timer And (PBMap\Redraw Or PBMap\Dirty) And PBMap\OnStage = #False
>>>>>>> refs/remotes/origin/idle
Drawing()
EndIf
EndProcedure
@@ -1422,13 +1288,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64)
<<<<<<< HEAD
; CursorPosition = 600
; FirstLine = 680
=======
; CursorPosition = 1290
; FirstLine = 1275
>>>>>>> refs/remotes/origin/idle
; CursorPosition = 1264
; FirstLine = 1245
; Folding = ---------
; EnableThread
; EnableXP