From 54321455f7be147ef842d45f0f498c8920cfc7ca Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Fri, 26 Feb 2016 18:01:33 -0500 Subject: [PATCH] started work on efficient chunk search --- chunkymap-regen.py | 175 +++++++++++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 77 deletions(-) diff --git a/chunkymap-regen.py b/chunkymap-regen.py index 1508e1a..a347ff1 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -300,8 +300,10 @@ class MTChunks: world_blacklist = None run_count = None + todo_positions = None # list of tuples (locations) to render next (for fake recursion) def __init__(self): #formerly checkpaths() in global scope + self.todo_positions = list() self.run_count = 0 self.is_verbose = True self.loop_enable = True @@ -715,8 +717,95 @@ class MTChunks: if chunk_luid in self.chunks.keys(): result = self.chunks[chunk_luid].is_fresh return result + + def check_chunk(self, x, z): + result = False + chunk_luid = self.get_chunk_luid(x,z) + + #if (is_different_world): #instead, see above where all chunk files and player files are deleted + # self.remove_chunk(chunk_luid) + + is_player_in_this_chunk = self.is_player_at_luid(chunk_luid) #ok if stale, since is only used for whether empty chunk should be regenerated + + is_render_needed = False - def check_map(self): + if not self.is_chunk_fresh(chunk_luid): + if is_player_in_this_chunk: + if self.is_chunk_yaml_marked(chunk_luid): + if self.is_chunk_yaml_marked_empty(chunk_luid): + is_render_needed = True + if self.is_verbose: + print (chunk_luid+": RENDERING nonfresh previously marked empty (player in it)") + else: + sys.stdout.write('.') + else: + if self.is_verbose: + print (chunk_luid+": SKIPPING nonfresh previously marked (player in it)") + #else: + #sys.stdout.write('.') + else: + is_render_needed = True + if self.is_verbose: + print (chunk_luid+": RENDERING nonfresh unmarked (player in it)") + else: + sys.stdout.write('.') + else: + if (not self.is_chunk_yaml_marked(chunk_luid)): + is_render_needed = True + if self.is_verbose: + print (chunk_luid+": RENDERING nonfresh unmarked (simple check since has no player)") + else: + sys.stdout.write('.') + else: + if self.is_verbose: + print (chunk_luid+": SKIPPING nonfresh previously marked (simple check since has no player)") + else: + if self.is_verbose: + print (chunk_luid+": SKIPPING fresh chunk") + #if (not self.is_chunk_yaml_marked(chunk_luid)): + #is_render_needed = True + + # This should never happen since keeping the output of minetestmapper-numpy.py (after analyzing that output) is deprecated: + #if self.is_genresult_marked(chunk_luid) and not self.is_chunk_yaml_present(chunk_luid): + # tmp_chunk = MTChunk() + # genresult_path = self.get_chunk_genresult_tmp_path(chunk_luid) + # tmp_chunk.set_from_genresult(genresult_path) + # chunk_yaml_path = self.get_chunk_yaml_path(chunk_luid) + # tmp_chunk.save_yaml(chunk_yaml_path) + # print("(saved yaml to '"+chunk_yaml_path+"')") + + + if is_render_needed: + rendered_count += 1 + if (self.render_chunk(x,z)): + result = True + else: + if self.is_chunk_rendered_on_dest(chunk_luid): + result = True + tmp_png_path = self.get_chunk_image_path(chunk_luid) + if self.is_verbose: + print(chunk_luid+": Skipping existing map tile file " + tmp_png_path + " (delete it to re-render)") + #elif is_empty_chunk: + #print("Skipping empty chunk " + chunk_luid) + #else: + #print(chunk_luid+": Not rendered on dest.") + return result + + def check_map_pseudorecursion(self): + if os.path.isfile(self.mtmn_path) and os.path.isfile(self.colors_path): + rendered_count = 0 + self.todo_positions.clear() + self.todo_positions.append((0,0)) + todo_index = 0 + while (todo_index 0: - outline_generates_count = 0 + while this_iteration_generates_count > 0: + this_iteration_generates_count = 0 self.read_then_remove_signals() if not self.refresh_map_enable: break @@ -804,77 +893,9 @@ class MTChunks: #only generate the edges (since started with region 0 0 0 0) and expanding from there until no png is created: is_outline = (x==self.chunkx_min) or (x==self.chunkx_max) or (z==self.chunkz_min) or (z==self.chunkz_max) if is_outline: - chunk_luid = self.get_chunk_luid(x,z) - - #if (is_different_world): #instead, see above where all chunk files and player files are deleted - # self.remove_chunk(chunk_luid) - - is_player_in_this_chunk = self.is_player_at_luid(chunk_luid) - - is_render_needed = False - - if not self.is_chunk_fresh(chunk_luid): - if is_player_in_this_chunk: - if self.is_chunk_yaml_marked(chunk_luid): - if self.is_chunk_yaml_marked_empty(chunk_luid): - is_render_needed = True - if self.is_verbose: - print (chunk_luid+": RENDERING nonfresh previously marked empty (player in it)") - else: - sys.stdout.write('.') - else: - if self.is_verbose: - print (chunk_luid+": SKIPPING nonfresh previously marked (player in it)") - #else: - #sys.stdout.write('.') - else: - is_render_needed = True - if self.is_verbose: - print (chunk_luid+": RENDERING nonfresh unmarked (player in it)") - else: - sys.stdout.write('.') - else: - if (not self.is_chunk_yaml_marked(chunk_luid)): - is_render_needed = True - if self.is_verbose: - print (chunk_luid+": RENDERING nonfresh unmarked (simple check since has no player)") - else: - sys.stdout.write('.') - else: - if self.is_verbose: - print (chunk_luid+": SKIPPING nonfresh previously marked (simple check since has no player)") - else: - if self.is_verbose: - print (chunk_luid+": SKIPPING fresh chunk") - #if (not self.is_chunk_yaml_marked(chunk_luid)): - #is_render_needed = True - - # This should never happen since keeping the output of minetestmapper-numpy.py (after analyzing that output) is deprecated: - #if self.is_genresult_marked(chunk_luid) and not self.is_chunk_yaml_present(chunk_luid): - # tmp_chunk = MTChunk() - # genresult_path = self.get_chunk_genresult_tmp_path(chunk_luid) - # tmp_chunk.set_from_genresult(genresult_path) - # chunk_yaml_path = self.get_chunk_yaml_path(chunk_luid) - # tmp_chunk.save_yaml(chunk_yaml_path) - # print("(saved yaml to '"+chunk_yaml_path+"')") - - - if is_render_needed: - rendered_count += 1 - if (self.render_chunk(x,z)): - total_generated_count += 1 - outline_generates_count += 1 - else: - if self.is_chunk_rendered_on_dest(chunk_luid): - total_generated_count += 1 - outline_generates_count += 1 - tmp_png_path = self.get_chunk_image_path(chunk_luid) - if self.is_verbose: - print(chunk_luid+": Skipping existing map tile file " + tmp_png_path + " (delete it to re-render)") - #elif is_empty_chunk: - #print("Skipping empty chunk " + chunk_luid) - #else: - #print(chunk_luid+": Not rendered on dest.") + if self.check_chunk(x,z): + this_iteration_generates_count += 1 + total_generated_count += 1 if self.is_verbose: print ("") # blank line before next z so output is more readable self.chunkx_min -= 1 @@ -1013,7 +1034,7 @@ class MTChunks: #if self.last_map_refresh_second is not None: #print ("waited "+str(best_timer()-self.last_map_refresh_second)+"s for map update") self.last_map_refresh_second = best_timer() - self.check_map() + self.check_map_inefficient_squarepattern() else: print("waiting before doing map update") else: @@ -1030,7 +1051,7 @@ class MTChunks: if self.refresh_players_enable: self.check_players() if self.refresh_map_enable: - self.check_map() + self.check_map_inefficient_squarepattern() if __name__ == '__main__': mtchunks = MTChunks()