Browse Source

debugging decachunk and chunk generation

and border chunk detection
master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
4c81c2c636
  1. 88
      chunkymap-regen.py
  2. 8
      expertmm.py

88
chunkymap-regen.py

@ -17,7 +17,7 @@ from minetestinfo import *
from expertmm import * from expertmm import *
from PIL import Image, ImageDraw, ImageFont, ImageColor from PIL import Image, ImageDraw, ImageFont, ImageColor
mode_to_bpp = {'1':1, 'L':8, 'P':8, 'RGB':24, 'RGBA':32, 'CMYK':32, 'YCbCr':24, 'I':32, 'F':32}
#best_timer = timeit.default_timer #best_timer = timeit.default_timer
#if sys.platform == "win32": #if sys.platform == "win32":
# on Windows, the best timer is time.clock() # on Windows, the best timer is time.clock()
@ -243,6 +243,7 @@ class MTChunks:
data_16px_path = None data_16px_path = None
data_160px_path = None data_160px_path = None
FLAG_EMPTY_HEXCOLOR = "#010000" FLAG_EMPTY_HEXCOLOR = "#010000"
FLAG_COLORS_LIST = None
world_name = None world_name = None
chunkymap_thisworld_data_path = None chunkymap_thisworld_data_path = None
genresult_name_opener_string = "chunk_" genresult_name_opener_string = "chunk_"
@ -251,7 +252,12 @@ class MTChunks:
def __init__(self): #formerly checkpaths() in global scope def __init__(self): #formerly checkpaths() in global scope
#self.force_rerender_decachunks_enable = True #self.force_rerender_decachunks_enable = True
self.min_indent = " " self.FLAG_COLORS_LIST = list()
self.FLAG_COLOR_CHANNELS = get_list_from_hex(self.FLAG_EMPTY_HEXCOLOR)
self.FLAG_COLORS_LIST.append(self.FLAG_COLOR_CHANNELS)
self.FLAG_COLORS_LIST.append((255,255,255)) #for compatibility with maps generated by earlier versions ONLY
self.FLAG_COLORS_LIST.append((0,0,0)) #for compatibility with maps generated by earlier versions ONLY
min_indent = " "
self.decachunks = {} self.decachunks = {}
self.rendered_this_session_count = 0 self.rendered_this_session_count = 0
self.is_backend_detected = False self.is_backend_detected = False
@ -585,24 +591,27 @@ class MTChunks:
#-1 becomes -10 #-1 becomes -10
return int(decachunky_x*10) return int(decachunky_x*10)
def is_worldborder_chunk(self, chunky_x, chunky_z): def is_worldborder_chunk(self, chunky_x, chunky_z):
result = False result = False
image_path = get_chunk_image_path(chunky_x, chunky_z) image_path = self.get_chunk_image_path(chunky_x, chunky_z)
border_pixel_count = 0
if os.path.isfile(image_path): if os.path.isfile(image_path):
original_im = Image.open(image_path) original_im = Image.open(image_path)
im = original_im im = original_im
if im.bits<24: bit_count = 24
try:
bit_count = mode_to_bpp[im.mode]
except:
print("ERROR in is_worldborder_chunk: unknown image mode "+str(im.mode)+" so can't get bitdepth of chunk")
if bit_count<24:#if im.bits<24:
im = original_im.convert('RGB') im = original_im.convert('RGB')
width, height = im.size width, height = im.size
pixel_count = width*height pixel_count = width*height
pixel_count_f = float(pixel_count) pixel_count_f = float(pixel_count)
border_count = 0 border_count = 0
FLAG_COLORS_LIST = list() for FLAG_COLOR in self.FLAG_COLORS_LIST:
FLAG_COLOR_CHANNELS = get_list_from_hex(self.FLAG_EMPTY_HEXCOLOR)
FLAG_COLORS_LIST.append(FLAG_COLOR_CHANNELS)
FLAG_COLORS_LIST.append((255,255,255)) #for compatibility with maps generated by earlier versions ONLY
FLAG_COLORS_LIST.append((0,0,0)) #for compatibility with maps generated by earlier versions ONLY
for FLAG_COLOR in FLAG_COLORS_LIST:
if len(FLAG_COLOR)==3 or len(FLAG_COLOR)==4: if len(FLAG_COLOR)==3 or len(FLAG_COLOR)==4:
for y in range(0,height): for y in range(0,height):
for x in range(0,width): for x in range(0,width):
@ -616,8 +625,9 @@ class MTChunks:
raw_input("ERROR: FLAG_COLOR (obtained from FLAG_EMPTY_HEXCOLOR) has "+len(FLAG_COLOR)+" element(s) (3 or 4 expected)") raw_input("ERROR: FLAG_COLOR (obtained from FLAG_EMPTY_HEXCOLOR) has "+len(FLAG_COLOR)+" element(s) (3 or 4 expected)")
return result return result
def is_chunk_on_todo_list(self, chunky_pos): def get_index_of_chunk_on_todo_list(self, chunky_pos):
result = -1 result = -1
if self.todo_index > -1:
if self.todo_index<len(self.todo_positions): if self.todo_index<len(self.todo_positions):
for index in range(self.todo_index,len(self.todo_positions)): for index in range(self.todo_index,len(self.todo_positions)):
if ivec2_equals(self.todo_positions[index], chunky_pos): if ivec2_equals(self.todo_positions[index], chunky_pos):
@ -627,6 +637,7 @@ class MTChunks:
def check_decachunk_containing_chunk(self, chunky_x, chunky_z): def check_decachunk_containing_chunk(self, chunky_x, chunky_z):
try:
chunky_coord_list = list() chunky_coord_list = list()
decachunky_x = self.get_decachunky_coord_from_chunky_coord(chunky_x) decachunky_x = self.get_decachunky_coord_from_chunky_coord(chunky_x)
decachunky_z = self.get_decachunky_coord_from_chunky_coord(chunky_z) decachunky_z = self.get_decachunky_coord_from_chunky_coord(chunky_z)
@ -649,7 +660,8 @@ class MTChunks:
while chunky_x <= chunky_max_x: while chunky_x <= chunky_max_x:
coords = (chunky_x, chunky_z) coords = (chunky_x, chunky_z)
chunky_coord_list.append( coords ) chunky_coord_list.append( coords )
is_any_part_queued = is_chunk_on_todo_list(coords) queued_index = self.get_index_of_chunk_on_todo_list(coords)
is_any_part_queued = queued_index > -1
if is_any_part_queued: if is_any_part_queued:
if queued_chunk_coords is None: if queued_chunk_coords is None:
queued_chunk_coords = list() queued_chunk_coords = list()
@ -662,7 +674,7 @@ class MTChunks:
chunky_offset_z += 1 chunky_offset_z += 1
if not is_any_part_queued: if not is_any_part_queued:
is_chunk_complete = True is_chunk_complete = True
unfinished_chunky_coord = None
if is_chunk_complete: if is_chunk_complete:
### NOTE: a chunk is incomplete if any rendered nonworldborder chunk touches a nonrendered chunk ### NOTE: a chunk is incomplete if any rendered nonworldborder chunk touches a nonrendered chunk
for chunky_pos in chunky_coord_list: for chunky_pos in chunky_coord_list:
@ -680,15 +692,16 @@ class MTChunks:
elif self.is_worldborder_chunk(nearby_chunky_x, nearby_chunky_z): elif self.is_worldborder_chunk(nearby_chunky_x, nearby_chunky_z):
this_is_worldborder_chunk = True this_is_worldborder_chunk = True
self.prepare_chunk_meta(nearby_chunky_x, nearby_chunky_z) self.prepare_chunk_meta(nearby_chunky_x, nearby_chunky_z)
if "is_worldborder" not in self.chunks[nearby_chunk_luid].metadata or (self.chunks[nearby_chunk_luid].metadata["is_worldborder"] != True) if ("is_worldborder" not in self.chunks[nearby_chunk_luid].metadata) or (self.chunks[nearby_chunk_luid].metadata["is_worldborder"] != True):
self.chunks[nearby_chunk_luid].metadata["is_worldborder"] = True self.chunks[nearby_chunk_luid].metadata["is_worldborder"] = True
self.save_chunk_meta(nearby_chunky_x, nearby_chunky_z) self.save_chunk_meta(nearby_chunky_x, nearby_chunky_z)
if not this_is_worldborder_chunk: if not this_is_worldborder_chunk:
#empty chunk would not touch NON-worldborder chunk if decachunk was complete #empty chunk would not touch NON-worldborder chunk if decachunk was complete
is_chunk_complete = False is_chunk_complete = False
unfinished_chunky_coord = nearby_chunky_x, nearby_chunky_z
break break
else: else:
print(self.min_indent+"ERROR in check_decachunk_containing_chunk: no outline of chunks could be found around "+str(chunky_pos)) print(min_indent+"ERROR in check_decachunk_containing_chunk: no outline of chunks could be found around "+str(chunky_pos))
if not is_chunk_complete: if not is_chunk_complete:
break break
@ -734,35 +747,35 @@ class MTChunks:
im.paste(chunk_im, offset) im.paste(chunk_im, offset)
contains_chunk_luids.append(self.get_chunk_luid(chunky_x, chunky_z)) contains_chunk_luids.append(self.get_chunk_luid(chunky_x, chunky_z))
except: except:
print(self.min_indent+"Could not finish "+participle+" in check_decachunk_containing_chunk:") print(min_indent+"Could not finish "+participle+" in check_decachunk_containing_chunk:")
view_traceback() view_traceback()
else: else:
preview_strings[chunky_offset_z] += "0" preview_strings[chunky_offset_z] += "0"
chunky_offset_z = z_chunky_count - 1 chunky_offset_z = z_chunky_count - 1
try: try:
print(self.min_indent+"Usable chunk images mask (height:"+str(z_chunky_count)+"):") print(min_indent+"Decachunk available chunk mask (height:"+str(z_chunky_count)+"):")
while chunky_offset_z>=0: while chunky_offset_z>=0:
if preview_strings[chunky_offset_z] is None: if preview_strings[chunky_offset_z] is None:
preview_strings[chunky_offset_z] = "<None>" preview_strings[chunky_offset_z] = "<None>"
print(self.min_indent+" "+str(chunky_offset_z)+":"+preview_strings[chunky_offset_z]) print(min_indent+" "+str(chunky_offset_z)+":"+preview_strings[chunky_offset_z])
chunky_offset_z -= 1 chunky_offset_z -= 1
except: except:
print(self.min_indent+"Could not finish showing mask (this should never happen)") print(min_indent+"Could not finish showing mask (this should never happen)")
print(self.min_indent+" z_chunky_count:"+str(z_chunky_count)) print(min_indent+" z_chunky_count:"+str(z_chunky_count))
print(self.min_indent+" len(preview_strings):"+str(len(preview_strings))) print(min_indent+" len(preview_strings):"+str(len(preview_strings)))
print(self.min_indent+" chunky_min_x:"+str(chunky_min_x)) print(min_indent+" chunky_min_x:"+str(chunky_min_x))
print(self.min_indent+" chunky_max_x:"+str(chunky_max_x)) print(min_indent+" chunky_max_x:"+str(chunky_max_x))
print(self.min_indent+" chunky_min_z:"+str(chunky_min_z)) print(min_indent+" chunky_min_z:"+str(chunky_min_z))
print(self.min_indent+" chunky_max_z:"+str(chunky_max_z)) print(min_indent+" chunky_max_z:"+str(chunky_max_z))
view_traceback() view_traceback()
print("") print("")
decachunk_folder_path = self.get_decachunk_folder_path_from_decachunk(decachunky_x, decachunky_z) decachunk_folder_path = self.get_decachunk_folder_path_from_decachunk(decachunky_x, decachunky_z)
if not os.path.isdir(decachunk_folder_path): if not os.path.isdir(decachunk_folder_path):
os.makedirs(decachunk_folder_path) os.makedirs(decachunk_folder_path)
print(self.min_indent+"Made folder '"+decachunk_folder_path+"'") print(min_indent+"Made folder '"+decachunk_folder_path+"'")
else: else:
print(self.min_indent+"Found folder '"+decachunk_folder_path+"'") print(min_indent+"Found folder '"+decachunk_folder_path+"'")
print(self.min_indent+"Saving '"+decachunk_image_path+"'") print(min_indent+"Saving '"+decachunk_image_path+"'")
im.save(decachunk_image_path) im.save(decachunk_image_path)
decachunk_luid = self.get_decachunk_luid_from_decachunk(decachunky_x, decachunky_z) decachunk_luid = self.get_decachunk_luid_from_decachunk(decachunky_x, decachunky_z)
self.prepare_decachunk_meta_from_decachunk(decachunky_x, decachunky_z) self.prepare_decachunk_meta_from_decachunk(decachunky_x, decachunky_z)
@ -775,8 +788,14 @@ class MTChunks:
self.decachunks[decachunk_luid].metadata["contains_chunk_luids"] = None self.decachunks[decachunk_luid].metadata["contains_chunk_luids"] = None
self.decachunks[decachunk_luid].save_yaml(decachunk_yaml_path) self.decachunks[decachunk_luid].save_yaml(decachunk_yaml_path)
else: else:
print(self.min_indent+"Not rendering decachunk "+str((decachunky_x,decachunky_z))+" yet since contains queued chunk "+str(queued_chunk_coords)) if is_any_part_queued:
print(self.min_indent+" (index:["+str(queued_index)+"]; len:"+str(len(self.todo_positions))+") .") print(min_indent+"Not rendering decachunk "+str((decachunky_x,decachunky_z))+" yet since contains queued chunk {found_index:["+str(queued_index)+"]; current_index:["+str(self.todo_index)+"]; len(todo_positions):"+str(len(self.todo_positions))+"; chunky_position:"+str(queued_chunk_coords)+"}")
else:
print(min_indent+"Not rendering decachunk "+str((decachunky_x,decachunky_z))+" yet since unfinished chunks (world border not between empty and closed area) such as empty chunk "+str(unfinished_chunky_coord))
print(min_indent+" (index:["+str(queued_index)+"]; len:"+str(len(self.todo_positions))+") .")
except:
print(min_indent+"Could not finish check_decachunk_containing_chunk:")
view_traceback(min_indent)
def get_chunk_folder_path(self, chunky_x, chunky_z): def get_chunk_folder_path(self, chunky_x, chunky_z):
result = None result = None
@ -900,7 +919,7 @@ class MTChunks:
def remove_chunk(self, chunky_x, chunky_z): def remove_chunk(self, chunky_x, chunky_z):
result = False result = False
chunk_luid = get_chunk_luid(chunky_x, chunky_z) chunk_luid = self.get_chunk_luid(chunky_x, chunky_z)
out_path = self.get_chunk_genresult_tmp_path(chunky_x, chunky_z) out_path = self.get_chunk_genresult_tmp_path(chunky_x, chunky_z)
tmp_png_path = self.get_chunk_image_path(chunky_x, chunky_z) tmp_png_path = self.get_chunk_image_path(chunky_x, chunky_z)
yml_path = self.get_chunk_yaml_path(chunky_x, chunky_z) yml_path = self.get_chunk_yaml_path(chunky_x, chunky_z)
@ -1109,7 +1128,7 @@ class MTChunks:
self.prepare_chunk_meta(chunky_x, chunky_z) self.prepare_chunk_meta(chunky_x, chunky_z)
self.create_chunk_folder(chunky_x, chunky_z) self.create_chunk_folder(chunky_x, chunky_z)
self.chunks[chunk_luid].save_yaml(chunk_yaml_path) self.chunks[chunk_luid].save_yaml(chunk_yaml_path)
print(self.min_indent+"(saved yaml to '"+chunk_yaml_path+"')") print(min_indent+"(saved yaml to '"+chunk_yaml_path+"')")
def check_players(self): def check_players(self):
print("PROCESSING PLAYERS") print("PROCESSING PLAYERS")
@ -1519,7 +1538,7 @@ class MTChunks:
results = tmp results = tmp
return results return results
def get_outline_coords_list(x_int, y_int, restrict_to_decachunk_enable=False): def get_outline_coords_list(self, x_int, y_int, restrict_to_decachunk_enable=False):
results = None results = None
if x_int is not None and y_int is not None: if x_int is not None and y_int is not None:
tmp = list() tmp = list()
@ -1569,6 +1588,9 @@ class MTChunks:
return result return result
def check_map_pseudorecursion_start(self): def check_map_pseudorecursion_start(self):
if self.todo_positions is not None and self.todo_index>=len(self.todo_positions):
print("WARNING in check_map_pseudorecursion_start: todo index was ["+str(self.todo_index)+"] in "+str(len(self.todo_positions))+"-length list, so resetting todo_list")
self.todo_index = -1
if self.todo_index<0: if self.todo_index<0:
print("PROCESSING MAP DATA (BRANCH PATTERN)") print("PROCESSING MAP DATA (BRANCH PATTERN)")
if os.path.isfile(self.minetestmapper_py_path) and os.path.isfile(self.colors_path): if os.path.isfile(self.minetestmapper_py_path) and os.path.isfile(self.colors_path):

8
expertmm.py

@ -1,6 +1,7 @@
import os import os
import sys import sys
import traceback import traceback
import copy
verbose_enable = False verbose_enable = False
@ -21,6 +22,7 @@ alpha_chars = alpha_upper_chars+alpha_lower_chars
alnum_chars = alpha_chars+digit_chars alnum_chars = alpha_chars+digit_chars
identifier_chars = alnum_chars+"_" identifier_chars = alnum_chars+"_"
identifier_and_dot_chars = identifier_chars+"." identifier_and_dot_chars = identifier_chars+"."
min_indent = ""
class InstalledFile: class InstalledFile:
source_dir_path = None source_dir_path = None
@ -111,7 +113,7 @@ def get_dict_deepcopy(old_dict):
if type(old_dict) is dict: if type(old_dict) is dict:
new_dict = {} new_dict = {}
for this_key in old_dict.iterkeys(): for this_key in old_dict.iterkeys():
new_dict[this_key] = old_dict[this_key] new_dict[this_key] = copy.deepcopy(old_dict[this_key])
return new_dict return new_dict
def is_dict_subset(new_dict, old_dict, verbose_messages_enable, verbose_dest_description="unknown file"): def is_dict_subset(new_dict, old_dict, verbose_messages_enable, verbose_dest_description="unknown file"):
@ -173,8 +175,8 @@ def RepresentsFloat(s):
def view_traceback(): def view_traceback():
ex_type, ex, tb = sys.exc_info() ex_type, ex, tb = sys.exc_info()
print(str(ex_type)) print(min_indent+str(ex_type))
print(str(ex)) print(min_indent+str(ex))
traceback.print_tb(tb) traceback.print_tb(tb)
del tb del tb

Loading…
Cancel
Save