]> marstr Code Repo - marstr/orthographic.git/commitdiff
Issue of incorrectly assigned resources appears to be fixed. Complete tile to be...
authorMarcus Str. <marcus@marstr.online>
Sat, 28 Dec 2024 18:59:26 +0000 (19:59 +0100)
committerMarcus Str. <marcus@marstr.online>
Sat, 28 Dec 2024 18:59:26 +0000 (19:59 +0100)
orthographic.py
tileprep.py

index e2b309ec86a10226014d935bdc22e13ef452c27a..daf59e1d9e84e8fc6ae8d67097a5b742d04b0dbc 100644 (file)
@@ -295,6 +295,11 @@ class mstr_orthographic:
     def _prepareTile(self):\r
         mstr_msg("orthographic", "Beginning construction of tile")\r
 \r
+        # Clear cache\r
+        tmp = glob.glob(mstr_datafolder + "_cache/*.*")\r
+        for t in range(0, len(tmp)):\r
+            os.remove(tmp[t])\r
+\r
         # We need to know which platform we are on\r
         os_platform = os.name\r
 \r
@@ -435,6 +440,7 @@ class mstr_orthographic:
 \r
         # We now need to "raytrace" the resources for correct placement\r
         mstr_msg("orthographic", "Performing resource plamement tracing for tile")\r
+        \r
         for lat_grid in range(1, maxlatlng[0]+1):\r
             for lng_grid in range(1, maxlatlng[1]+1):\r
                 mstr_msg("orthographic", "Placement tracing for " + str(lat_grid) + ":" + str(lng_grid))\r
@@ -447,7 +453,7 @@ class mstr_orthographic:
                     lyr = fnlines[l].split(" ")\r
                     tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, lyr[0], lyr[1], None, False)\r
                     tp._setLatLngFold(self._latlngfld)\r
-                    tp._placeTileSources(lat_grid, lng_grid)\r
+                    tp._placeTileSources(mlat, mlng)\r
 \r
 \r
     # Generates X-Plane 11/12 scenery with\r
index ef5f37ae1b76395f1c904a3257e8f1dfd4a61ce5..46a003eca5d912525e1c62df9a406bb246027ce3 100644 (file)
@@ -144,6 +144,7 @@ class mstr_tileprep:
             for ln in fnlines:
                 l = ln.split(" ")
                 if l[0] == self._tag and l[1] == self._value:
+                    l[3] = l[3].replace("\n", "")
                     touch = l[3]
 
         return touch
@@ -234,143 +235,117 @@ class mstr_tileprep:
         return [ (tv+1, th), (tv, th+1), (tv-1, th), (tv, th-1) ]
 
 
-    # Walk through the now existing data files and make sure we always pick the correct
-    # sources for every tile, thus evading previous edge detection errors
-    def _placeTileSources(self, mlat, mlng):
+    # Scan connections of a specific tile
+    def _scanConnections(self, tile):
+        # The array of visited tiles
+        visited = []
 
         # None of the edges have reached their end yet
         edge_end = [0,0,0,0] # top, right, bottom, left
-
-        # Array with info we need
-        resinfo = ["", ""] # Touch, Resource numbers
-
-        # Go through everything until the end is reached (no more options left)
         end_reached = False
         while end_reached == False:
-
             # Go north
-            tv = self._tile_v
-            th = self._tile_h
+            tv = tile[0]
+            th = tile[1]
 
             while edge_end[0] == 0:
-                resinfo[0] = self._getResourceTouch(tv, th)
-                resinfo[1] = self._getResourceInfo(tv, th)
-
-                # Only do the following steps if we have nothing stored
-                if resinfo[1] == "0":
-                    neighbors = self._findNeighbors(tv, th)
-                    neighborinfo = ["",""]
-                    for n in range(0, len(neighbors)):
-                        neighborinfo[0] = self._getResourceTouch(neighbors[n][0], neighbors[n][1])
-                        neighborinfo[1] = self._getResourceInfo(neighbors[n][0], neighbors[n][1])
-                        if "b" in neighborinfo[0] and neighborinfo[1] != "0":
-                            resinfo[1] = neighborinfo[1]
-                            break
-                
-                # Store info. At this point we either have neighboring data, or
-                # we need to select something
-                if resinfo[1] == "0": resinfo[1] = self._selectResources()
-                self._storeResourceInfo(tv, th, resinfo[1])
-
-                # Move forward
-                if "t" in resinfo[0]:
+                owntouch = self._getResourceTouch(tv, th)
+                if "t" in owntouch:
+                    if self._checkVisited(visited, (tv, th))   == False: visited.append((tv, th))
+                    if self._checkVisited(visited, (tv+1, th)) == False: visited.append((tv+1, th))
                     tv=tv+1
                 else:
                     edge_end[0] = 1
 
-            
             # Go east
-            tv = self._tile_v
-            th = self._tile_h
+            tv = tile[0]
+            th = tile[1]
 
             while edge_end[1] == 0:
-                resinfo[0] = self._getResourceTouch(tv, th)
-                resinfo[1] = self._getResourceInfo(tv, th)
-
-                # Only do the following steps if we have nothing stored
-                if resinfo[1] == "0":
-                    neighbors = self._findNeighbors(tv, th)
-                    neighborinfo = ["",""]
-                    for n in range(0, len(neighbors)):
-                        neighborinfo[0] = self._getResourceTouch(neighbors[n][0], neighbors[n][1])
-                        neighborinfo[1] = self._getResourceInfo(neighbors[n][0], neighbors[n][1])
-                        if "l" in neighborinfo[0] and neighborinfo[1] != "0":
-                            resinfo[1] = neighborinfo[1]
-                            break
-                
-                # Store info. At this point we either have neighboring data, or
-                # we need to select something
-                if resinfo[1] == "0": resinfo[1] = self._selectResources()
-                self._storeResourceInfo(tv, th, resinfo[1])
-
-                # Move forward
-                if "r" in resinfo[0]:
+                owntouch = self._getResourceTouch(tv, th)
+                if "r" in owntouch:
+                    if self._checkVisited(visited, (tv, th))   == False: visited.append((tv, th))
+                    if self._checkVisited(visited, (tv, th+1)) == False: visited.append((tv, th+1))
                     th=th+1
                 else:
                     edge_end[1] = 1
 
-
             # Go south
-            tv = self._tile_v
-            th = self._tile_h
+            tv = tile[0]
+            th = tile[1]
 
             while edge_end[2] == 0:
-                resinfo[0] = self._getResourceTouch(tv, th)
-                resinfo[1] = self._getResourceInfo(tv, th)
-
-                # Only do the following steps if we have nothing stored
-                if resinfo[1] == "0":
-                    neighbors = self._findNeighbors(tv, th)
-                    neighborinfo = ["",""]
-                    for n in range(0, len(neighbors)):
-                        neighborinfo[0] = self._getResourceTouch(neighbors[n][0], neighbors[n][1])
-                        neighborinfo[1] = self._getResourceInfo(neighbors[n][0], neighbors[n][1])
-                        if "t" in neighborinfo[0] and neighborinfo[1] != "0":
-                            resinfo[1] = neighborinfo[1]
-                            break
-                
-                # Store info. At this point we either have neighboring data, or
-                # we need to select something
-                if resinfo[1] == "0": resinfo[1] = self._selectResources()
-                self._storeResourceInfo(tv, th, resinfo[1])
-
-                # Move forward
-                if "b" in resinfo[0]:
+                owntouch = self._getResourceTouch(tv, th)
+                if "b" in owntouch:
+                    if self._checkVisited(visited, (tv, th))   == False: visited.append((tv, th))
+                    if self._checkVisited(visited, (tv-1, th)) == False: visited.append((tv-1, th))
                     tv=tv-1
                 else:
                     edge_end[2] = 1
 
-
             # Go west
-            tv = self._tile_v
-            th = self._tile_h
+            tv = tile[0]
+            th = tile[1]
 
             while edge_end[3] == 0:
-                resinfo[0] = self._getResourceTouch(tv, th)
-                resinfo[1] = self._getResourceInfo(tv, th)
-
-                # Only do the following steps if we have nothing stored
-                if resinfo[1] == "0":
-                    neighbors = self._findNeighbors(tv, th)
-                    neighborinfo = ["",""]
-                    for n in range(0, len(neighbors)):
-                        neighborinfo[0] = self._getResourceTouch(neighbors[n][0], neighbors[n][1])
-                        neighborinfo[1] = self._getResourceInfo(neighbors[n][0], neighbors[n][1])
-                        if "r" in neighborinfo[0] and neighborinfo[1] != "0":
-                            resinfo[1] = neighborinfo[1]
-                            break
-                
-                # Store info. At this point we either have neighboring data, or
-                # we need to select something
-                if resinfo[1] == "0": resinfo[1] = self._selectResources()
-                self._storeResourceInfo(tv, th, resinfo[1])
-
-                # Move forward
-                if "l" in resinfo[0]:
+                owntouch = self._getResourceTouch(tv, th)
+                if "b" in owntouch:
+                    if self._checkVisited(visited, (tv, th))   == False: visited.append((tv, th))
+                    if self._checkVisited(visited, (tv, th-1)) == False: visited.append((tv, th-1))
                     th=th-1
                 else:
                     edge_end[3] = 1
 
 
             if edge_end[0] == 1 and edge_end[1] == 1 and edge_end[2] == 1 and edge_end[3] == 1:
-                end_reached = True # <- Break loop
\ No newline at end of file
+                end_reached = True # <- Break loop
+
+        return visited
+
+
+    # Walk through the now existing data files and make sure we always pick the correct
+    # sources for every tile, thus evading previous edge detection errors
+    def _placeTileSources(self, mlat, mlng):
+        
+        # Initial scan "cross"
+        visited = self._scanConnections((self._tile_v, self._tile_h))
+
+        # Recursive scan of initial cross
+        for v in range(len(visited)):
+            vst = self._scanConnections((visited[v][0], visited[v][1]))
+            for l in range(len(vst)):
+                if self._checkVisited(visited, (vst[l][0], vst[l][1])) == False: visited.append((vst[l][0], vst[l][1]))
+        
+        # We will take the resource of the original tile we have started
+        # our scan from. If there is nothing, we can choose.
+        # This is then used for all visited tiles.
+        tv = self._tile_v
+        th = self._tile_h
+        resstring = self._getResourceInfo(tv, th)
+        if resstring == "0" or resstring == "": resstring = self._selectResources()
+        for v in range(0, len(visited)):
+            self._storeResourceInfo(visited[v][0], visited[v][1], resstring)
+
+
+
+    # Check if a tile was visited
+    def _checkVisited(self, visited, tile):
+        v = False
+        for t in range(0, len(visited)):
+            if visited[t][0] == tile[0] and visited[t][1] == tile[1]:
+                v = True
+                break
+        return v
+
+
+    # Show result of path tracing - DEBUG ONLY
+    def _debugRender(self, visited, mlat, mlng):
+        rmap = Image.new("RGBA", (mlng*10, mlat*10), color="#FFFFFF")
+        draw = ImageDraw.Draw(rmap)
+        for v in range(len(visited)):
+            sx, sy = (visited[v][1]-1)*10, (rmap.height-(visited[v][0]-1)*10)-10
+            dx, dy = ((visited[v][1]-1)*10)+10, (rmap.height-(visited[v][0]-1)*10)+10
+            shape = [ (sx, sy), (dx, dy) ]
+            fill = (0,0,0,255)
+            draw.rectangle(shape, fill=fill)
+        rmap.show()