Issue of incorrectly assigned resources appears to be fixed. Complete tile to be tested.

This commit is contained in:
Marcus Str. 2024-12-28 19:59:26 +01:00
parent c2d4915114
commit 4ab426308b
2 changed files with 87 additions and 106 deletions

View File

@ -295,6 +295,11 @@ class mstr_orthographic:
def _prepareTile(self):
mstr_msg("orthographic", "Beginning construction of tile")
# Clear cache
tmp = glob.glob(mstr_datafolder + "_cache/*.*")
for t in range(0, len(tmp)):
os.remove(tmp[t])
# We need to know which platform we are on
os_platform = os.name
@ -435,6 +440,7 @@ class mstr_orthographic:
# We now need to "raytrace" the resources for correct placement
mstr_msg("orthographic", "Performing resource plamement tracing for tile")
for lat_grid in range(1, maxlatlng[0]+1):
for lng_grid in range(1, maxlatlng[1]+1):
mstr_msg("orthographic", "Placement tracing for " + str(lat_grid) + ":" + str(lng_grid))
@ -447,7 +453,7 @@ class mstr_orthographic:
lyr = fnlines[l].split(" ")
tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, lyr[0], lyr[1], None, False)
tp._setLatLngFold(self._latlngfld)
tp._placeTileSources(lat_grid, lng_grid)
tp._placeTileSources(mlat, mlng)
# Generates X-Plane 11/12 scenery with

View 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,139 +235,63 @@ 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
@ -374,3 +299,53 @@ class mstr_tileprep:
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
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()