Browse Source

debugging result analysis

master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
551d90048f
  1. 208
      chunkymap-regen.py

208
chunkymap-regen.py

@ -71,24 +71,28 @@ def get_dict_deepcopy(old_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"):
is_changed = False is_changed = False
if old_dict is not None: try:
if new_dict is not None: if old_dict is not None:
old_dict_keys = self.old_dict.keys() if new_dict is not None:
for this_key in self.new_dict.iterkeys(): old_dict_keys = self.old_dict.keys()
if (this_key not in old_dict_keys): for this_key in self.new_dict.iterkeys():
is_changed = True if (this_key not in old_dict_keys):
if verbose_messages_enable: is_changed = True
print("SAVING '"+verbose_dest_description+"' since "+str(this_key)+" not in saved version.") if verbose_messages_enable:
break print("SAVING '"+verbose_dest_description+"' since "+str(this_key)+" not in saved version.")
elif new_dict[this_key] != old_dict[this_key]: break
is_changed = True elif new_dict[this_key] != old_dict[this_key]:
if verbose_messages_enable: is_changed = True
print("SAVING '"+verbose_dest_description+"' since "+str(this_key)+" not same as saved version.") if verbose_messages_enable:
break print("SAVING '"+verbose_dest_description+"' since "+str(this_key)+" not same as saved version.")
#else new_dict is None so no change detected (no new information) break
else: #else new_dict is None so no change detected (no new information)
if new_dict is not None: else:
is_changed = True if new_dict is not None:
is_changed = True
except:
print("Could not finish is_dict_subset:")
view_traceback()
return is_changed return is_changed
def ivec2_equals(pos1, pos2): def ivec2_equals(pos1, pos2):
@ -281,88 +285,98 @@ class MTChunk:
#returns whether save is needed (whether metadata was changed) #returns whether save is needed (whether metadata was changed)
def set_from_genresult(self, this_genresult_path): def set_from_genresult(self, this_genresult_path):
#this_genresult_path = mtchunks.get_chunk_genresult_path(chunk_luid) #this_genresult_path = mtchunks.get_chunk_genresult_path(chunk_luid)
is_changed = False participle = "getting copy of dict"
old_meta = get_dict_deepcopy(self.metadata) try:
if os.path.isfile(this_genresult_path): is_changed = False
#may have data such as: old_meta = get_dict_deepcopy(self.metadata)
#Result image (w=16 h=16) will be written to chunk_x0z0.png if os.path.isfile(this_genresult_path):
#Unknown node names: meze:meze default:stone_with_iron air default:dirt_with_snow default:stone_with_copper default:snow #may have data such as:
#Unknown node ids: 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 #Result image (w=16 h=16) will be written to chunk_x0z0.png
#Drawing image #Unknown node names: meze:meze default:stone_with_iron air default:dirt_with_snow default:stone_with_copper default:snow
#Saving to: chunk_x0z0.png #Unknown node ids: 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
#('PNG Region: ', [0, 64, 0, 64]) #Drawing image
#('Pixels PerNode: ', 1) #Saving to: chunk_x0z0.png
#('border: ', 0) #('PNG Region: ', [0, 64, 0, 64])
self.metadata["is_marked"] = True #('Pixels PerNode: ', 1)
ins = open(this_genresult_path, 'r') #('border: ', 0)
line = True self.metadata["is_marked"] = True
while line: participle = "opening '"+this_genresult_path+"'"
line = ins.readline() ins = open(this_genresult_path, 'r')
if line: line = True
line_strip = line.strip() counting_number = 1
try: while line:
if ("does not exist" in line_strip): # official minetestmapper.py says "World does not exist" but expertmm fork and minetestmapper-numpy.py say "data does not exist" participle = "reading line "+str(counting_number)
self.metadata["is_empty"] = True line = ins.readline()
break if line:
elif "Result image" in line_strip: line_strip = line.strip()
oparen_index = line_strip.find("(") try:
if (oparen_index>-1): if ("does not exist" in line_strip): # official minetestmapper.py says "World does not exist" but expertmm fork and minetestmapper-numpy.py say "data does not exist"
cparen_index = line_strip.find(")", oparen_index+1) self.metadata["is_empty"] = True
if (cparen_index>-1): break
operations_string = line_strip[oparen_index+1:cparen_index] elif "Result image" in line_strip:
operation_list = operations_string.split(" ") oparen_index = line_strip.find("(")
#if len(operation_list)==2: if (oparen_index>-1):
for operation_string in operation_list: cparen_index = line_strip.find(")", oparen_index+1)
if "=" in operation_string: if (cparen_index>-1):
chunks = operation_string.split("=") operations_string = line_strip[oparen_index+1:cparen_index]
if len(chunks)==2: operation_list = operations_string.split(" ")
if chunks[0].strip()=="w": #if len(operation_list)==2:
try: for operation_string in operation_list:
self.metadata["image_w"]=int(chunks[1].strip()) if "=" in operation_string:
except: chunks = operation_string.split("=")
print("Bad value for image w:"+str(chunks[1])) if len(chunks)==2:
elif chunks[0].strip()=="h": if chunks[0].strip()=="w":
try: try:
self.metadata["image_h"]=int(chunks[1].strip()) self.metadata["image_w"]=int(chunks[1].strip())
except: except:
print("Bad value for image h:"+str(chunks[1])) print("Bad value for image w:"+str(chunks[1]))
elif chunks[0].strip()=="h":
try:
self.metadata["image_h"]=int(chunks[1].strip())
except:
print("Bad value for image h:"+str(chunks[1]))
else:
print("Bad name for image variable so ignoring variable named '"+str(chunks[0])+"'")
else: else:
print("Bad name for image variable so ignoring variable named '"+str(chunks[0])+"'") print("Bad assignment (not 2 sides) so ignoring command '"+operation_string+"'")
else: else:
print("Bad assignment (not 2 sides) so ignoring command '"+operation_string+"'") print("Bad assignment (operator) so ignoring command '"+operation_string+"'")
#else:
# print("Bad assignment count so ignoring operations string '"+operations_string+"'")
elif "PNG Region" in line_strip:
obracket_index = line_strip.find("[")
if obracket_index>-1:
cbracket_index = line_strip.find("]", obracket_index+1)
if cbracket_index>-1:
rect_values_string = line_strip[obracket_index+1:cbracket_index]
rect_values_list = rect_values_string.split(",")
if len(rect_values_list)==4:
#pngregion=[pngminx, pngmaxx, pngminz, pngmaxz] #from minetestmapper-numpy.py
self.metadata["image_left"]=int(rect_values_list[0].strip())
self.metadata["image_right"]=int(rect_values_list[1].strip())
self.metadata["image_top"]=int(rect_values_list[2].strip())
self.metadata["image_bottom"]=int(rect_values_list[3].strip())
else: else:
print("Bad assignment (operator) so ignoring command '"+operation_string+"'") print("Bad map rect, so ignoring: "+rect_values_string)
#else: elif (len(line_strip)>5) and (line_strip[:5]=="xmin:"):
# print("Bad assignment count so ignoring operations string '"+operations_string+"'") self.metadata["image_left"] = int(line_strip[5:].strip())
elif "PNG Region" in line_strip: elif (len(line_strip)>5) and (line_strip[:5]=="xmax:"):
obracket_index = line_strip.find("[") self.metadata["image_right"] = int(line_strip[5:].strip())
if obracket_index>-1: elif (len(line_strip)>5) and (line_strip[:5]=="zmin:"):
cbracket_index = line_strip.find("]", obracket_index+1) #(zmin is bottom since cartesian)
if cbracket_index>-1: self.metadata["image_bottom"] = int(line_strip[5:].strip())
rect_values_string = line_strip[obracket_index+1:cbracket_index] elif (len(line_strip)>5) and (line_strip[:5]=="zmax:"):
rect_values_list = rect_values_string.split(",") #(zmax is top since cartesian)
if len(rect_values_list)==4: self.metadata["image_top"] = int(line_strip[5:].strip())
#pngregion=[pngminx, pngmaxx, pngminz, pngmaxz] #from minetestmapper-numpy.py except:
self.metadata["image_left"]=int(rect_values_list[0].strip()) print("#failed to parse line:"+str(line_strip))
self.metadata["image_right"]=int(rect_values_list[1].strip()) counting_number += 1
self.metadata["image_top"]=int(rect_values_list[2].strip()) ins.close()
self.metadata["image_bottom"]=int(rect_values_list[3].strip()) participle = "checking for changes"
else: is_changed = is_dict_subset(self.metadata, old_meta, False)
print("Bad map rect, so ignoring: "+rect_values_string) except:
elif (len(line_strip)>5) and (line_strip[:5]=="xmin:"): print("Could not finish "+participle+" in set_from_genresult:")
self.metadata["image_left"] = int(line_strip[5:].strip()) view_traceback()
elif (len(line_strip)>5) and (line_strip[:5]=="xmax:"):
self.metadata["image_right"] = int(line_strip[5:].strip())
elif (len(line_strip)>5) and (line_strip[:5]=="zmin:"):
#(zmin is bottom since cartesian)
self.metadata["image_bottom"] = int(line_strip[5:].strip())
elif (len(line_strip)>5) and (line_strip[:5]=="zmax:"):
#(zmax is top since cartesian)
self.metadata["image_top"] = int(line_strip[5:].strip())
except:
print("#failed to parse line:"+str(line_strip))
ins.close()
is_changed = is_dict_subset(self.metadata, old_meta, False)
return is_changed return is_changed
class MTChunks: class MTChunks:

Loading…
Cancel
Save