Further corrections in resource allocation code

This commit is contained in:
Marcus Str. 2024-12-31 16:22:52 +01:00
parent 4ab426308b
commit f460964722
3 changed files with 52 additions and 2 deletions

View File

@ -294,6 +294,16 @@ class mstr_layergen:
if s < len(src)-1:
srcstr = srcstr + ","
# Failsafe
if srcstr == "0":
srcstr = ""
numbers = list(range(1, 16))
src = random.sample(numbers, 5)
for s in range(len(src)):
srcstr = srcstr + str(src[s])
if s < len(src)-1:
srcstr = srcstr + ","
# Patch and border sources. There can only be one for each.
brd_src = None
ptc_src = []

View File

@ -37,6 +37,7 @@ class mstr_orthographic:
self._vstep = self._findVerticalStepping()
self._latlngfld = self.latlng_folder([lat,lng])
self._prep = prep
self._tiles_visited = []
mstr_msg("orthographic", "Initiated with LAT: " + str(lat) + ", LNG: " + str(lng))
@ -441,6 +442,11 @@ class mstr_orthographic:
# We now need to "raytrace" the resources for correct placement
mstr_msg("orthographic", "Performing resource plamement tracing for tile")
# Let's set up an array which keeps track of all used tiles, per resource
for l in mstr_ortho_layers:
self._tiles_visited.append([(l[0], l[1])]) # Store tag and value as tuple for each possible resource
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))
@ -451,11 +457,37 @@ class mstr_orthographic:
for l in range(0, len(fnlines)):
lyr = fnlines[l].split(" ")
vstidx = -1
for vst in range(0, len(self._tiles_visited)):
if self._tiles_visited[vst][0][0] == lyr[0] and self._tiles_visited[vst][0][1] == lyr[1]:
vstidx = vst
break
tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, lyr[0], lyr[1], None, False)
tp._setLatLngFold(self._latlngfld)
tp._setAlreadyVisitedTiles(self._tiles_visited[vstidx])
tp._placeTileSources(mlat, mlng)
self.adjust_tiles_visited(lyr[0], lyr[1], tp._all_visited)
# Adjust the tiles visited for one resource
def adjust_tiles_visited(self, tag, value, tiles):
lyridx = -1
for v in range(0, len(self._tiles_visited)):
if self._tiles_visited[v][0][0] == tag and self._tiles_visited[v][0][1] == value:
lyridx = v
break
for t in range(1, len(tiles)):
fnd = False
for v in range(1, len(self._tiles_visited[lyridx])):
if self._tiles_visited[lyridx][v][0] == tiles[t][0] and self._tiles_visited[lyridx][v][1] == tiles[t][1]:
fnd = True
break
if fnd == False:
self._tiles_visited[lyridx].append((tiles[t][0], tiles[t][1]))
# Generates X-Plane 11/12 scenery with
# - the finished orthos
# - a current LIDAR scan of the terrain

View File

@ -39,6 +39,8 @@ class mstr_tileprep:
self._mask = mask
latlngfld = xplane_latlng_folder([lat, lng])
self._tileinfo = mstr_tileinfo(lat, lng, v, h, latlngfld)
self._already_visited = [] # To be filled later
self._all_visited = []
# Special case for the final step of an ortho
self._is_completion = is_completion
@ -303,6 +305,11 @@ class mstr_tileprep:
return visited
# Let the orthographic class pass all visited tiles for this resource
def _setAlreadyVisitedTiles(self, tiles):
self._already_visited = tiles
# 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):
@ -316,13 +323,14 @@ class mstr_tileprep:
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]))
self._all_visited = visited
# 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()
resstring = self._selectResources()
for v in range(0, len(visited)):
self._storeResourceInfo(visited[v][0], visited[v][1], resstring)