Browse Source

fixed issue of player previous states not loading

was looking for id instead of playerid in yml files
master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
a71fbace5a
  1. 119
      generator.py

119
generator.py

@ -72,7 +72,7 @@ class MTChunks:
colors_path = None colors_path = None
python_exe_path = None python_exe_path = None
chunks = None chunks = None
players = None # dict with id as subscript, each containing player metadata dict players = None # dict with playerid as subscript, each containing player metadata dict
decachunks = None decachunks = None
rendered_this_session_count = None rendered_this_session_count = None
#force_rerender_decachunks_enable = None #force_rerender_decachunks_enable = None
@ -89,6 +89,7 @@ class MTChunks:
loop_enable = None loop_enable = None
verbose_enable = None verbose_enable = None
is_verbose_explicit = None
run_count = None run_count = None
todo_positions = None # list of tuples (locations) to render next (for fake recursion) todo_positions = None # list of tuples (locations) to render next (for fake recursion)
@ -135,6 +136,7 @@ class MTChunks:
self.todo_positions = list() self.todo_positions = list()
self.run_count = 0 self.run_count = 0
self.verbose_enable = True self.verbose_enable = True
self.is_verbose_explicit = False
self.loop_enable = True self.loop_enable = True
self.refresh_map_enable = False self.refresh_map_enable = False
self.refresh_players_enable = True self.refresh_players_enable = True
@ -1026,15 +1028,47 @@ class MTChunks:
self.chunks[chunk_luid].save_yaml(chunk_yaml_path) self.chunks[chunk_luid].save_yaml(chunk_yaml_path)
print(min_indent+"(saved yaml to '"+chunk_yaml_path+"')") print(min_indent+"(saved yaml to '"+chunk_yaml_path+"')")
def is_used_player_index(self, index):
result = False
if self.players is not None:
for this_key in self.players.keys():
this_player = self.players[this_key]
if "index" in this_player:
if this_player["index"]==index:
result = True
break
return result
def get_new_player_index(self): def get_new_player_index(self):
result = None result = None
max_player_index = None
index = 0
try:
while (self.is_used_player_index(index)):
index += 1
result = index
except:
print(min_indent+"Could not finish get_new_player_index:")
view_traceback()
return result
def get_new_player_index_faster(self):
result = None
max_player_index = None
if self.players is not None: if self.players is not None:
result = 0
for this_key in self.players.keys(): for this_key in self.players.keys():
this_player = self.players[this_key] this_player = self.players[this_key]
if "index" in this_player: if "index" in this_player:
if this_player["index"]==result: if (max_player_index is None) or (int(this_player["index"])>max_player_index):
result = this_player["index"] + 1 max_player_index = int(this_player["index"])
else:
print("WARNING: player with playerid '"+this_key+"' has no public index (programmer or admin error)")
if max_player_index is not None:
result = max_player_index + 1
else:
result = 0
return result return result
def save_player(self, playerid): def save_player(self, playerid):
@ -1051,7 +1085,7 @@ class MTChunks:
else: else:
print("ERROR: cannot save player since missing 'index' ('index' is used for filename on map)") print("ERROR: cannot save player since missing 'index' ('index' is used for filename on map)")
else: else:
print("ERROR: tried to save nonexistant player id '"+str(playerid)+"'") print("ERROR: tried to save nonexistant playerid '"+str(playerid)+"'")
else: else:
print("ERROR: save_player(None) was attempted.") print("ERROR: save_player(None) was attempted.")
else: else:
@ -1063,6 +1097,7 @@ class MTChunks:
#NOTE: time.gmtime converts long timestamp to 9-long tuple #NOTE: time.gmtime converts long timestamp to 9-long tuple
self.first_mtime_string = time.strftime(INTERNAL_TIME_FORMAT_STRING, first_mtime) self.first_mtime_string = time.strftime(INTERNAL_TIME_FORMAT_STRING, first_mtime)
print("PROCESSING PLAYERS") print("PROCESSING PLAYERS")
player_markers_count = 0
if self.players is None: if self.players is None:
self.players = {} self.players = {}
if os.path.isdir(self.chunkymap_players_path): if os.path.isdir(self.chunkymap_players_path):
@ -1072,19 +1107,27 @@ class MTChunks:
if os.path.isfile(sub_path): if os.path.isfile(sub_path):
if (sub_name[:1]!="."): if (sub_name[:1]!="."):
if len(sub_name)>4 and sub_name[-4:]==".yml": if len(sub_name)>4 and sub_name[-4:]==".yml":
player_markers_count += 1
player_dict = get_dict_from_conf_file(sub_path,":") player_dict = get_dict_from_conf_file(sub_path,":")
if player_dict is not None: if player_dict is not None:
if "id" in player_dict: player_dict["index"] = sub_name[:-4] # repair index
if (player_dict["id"] is not None) and (len(player_dict["id"])>0): if "playerid" in player_dict:
self.players[player_dict["id"]] = player_dict if (player_dict["playerid"] is not None) and (len(player_dict["playerid"])>0):
self.players[player_dict["playerid"]] = player_dict
if self.verbose_enable:
print("Adding playerid '"+str(player_dict["playerid"])+"'")
else: else:
print("ERROR: no 'id' in chunkymap player entry '"+sub_path+"'") print("ERROR: no 'playerid' in chunkymap player entry '"+sub_path+"'")
else:
print("WARNING: dangling player marker (no playerid) in '"+sub_path+"' so cannot be updated")
else: else:
print("ERROR: could not read any yaml values from '"+sub_path+"'") print("ERROR: could not read any yaml values from '"+sub_path+"'")
else: else:
os.makedirs(self.chunkymap_players_path) os.makedirs(self.chunkymap_players_path)
self.deny_http_access(self.chunkymap_players_path) self.deny_http_access(self.chunkymap_players_path)
if self.verbose_enable:
print("player_markers_count: "+str(player_markers_count))
#this could be huge: print("players:"+str(self.players.keys()))
players_path = os.path.join(minetestinfo.get_var("primary_world_path"), "players") players_path = os.path.join(minetestinfo.get_var("primary_world_path"), "players")
player_count = 0 player_count = 0
player_written_count = 0 player_written_count = 0
@ -1133,18 +1176,24 @@ class MTChunks:
#this_player = self.players[file_name] #this_player = self.players[file_name]
if ("utc_mtime" not in self.players[file_name]): if ("utc_mtime" not in self.players[file_name]):
#or (self.players[file_name]["utc_mtime"]!=this_mtime_string): #or (self.players[file_name]["utc_mtime"]!=this_mtime_string):
if self.verbose_enable:
print("no modified time for player '"+file_name+"' so marking for resave.")
self.players[file_name]["utc_mtime"]=this_mtime_string self.players[file_name]["utc_mtime"]=this_mtime_string
is_changed = True is_changed = True
#not necessarily moved--even if resaved by server, may not have moved a whole block or at all #not necessarily moved--even if resaved by server, may not have moved a whole block or at all
if "index" in self.players[file_name]: if "index" in self.players[file_name]:
player_index = self.players[file_name]["index"] player_index = self.players[file_name]["index"]
else: else:
print(min_indent+"WARNING: missing index in yml file for playerid '"+file_name+"' so making a new one.")
player_index = self.get_new_player_index() player_index = self.get_new_player_index()
self.players[file_name]["index"] = player_index self.players[file_name]["index"] = player_index
is_changed = True is_changed = True
else: else:
#if self.verbose_enable:
#this could be huge: print(file_name+" is not in "+str(self.players.keys()))
self.players[file_name] = {} self.players[file_name] = {}
player_index = self.get_new_player_index() player_index = self.get_new_player_index()
print(min_indent+"Creating map entry "+str(player_index)+" for playerid '"+file_name+"'")
self.players[file_name]["index"] = player_index self.players[file_name]["index"] = player_index
self.players[file_name]["playerid"] = file_name self.players[file_name]["playerid"] = file_name
self.players[file_name]["utc_mtime"] = this_mtime_string self.players[file_name]["utc_mtime"] = this_mtime_string
@ -1155,7 +1204,7 @@ class MTChunks:
if player_index is not None: if player_index is not None:
player_dest_path = os.path.join(self.chunkymap_players_path, str(player_index)+".yml") player_dest_path = os.path.join(self.chunkymap_players_path, str(player_index)+".yml")
else: else:
print("ERROR: player_index is None for '"+file_name+"' (this should never happen)") print(min_indent+"ERROR: player_index is still None for '"+file_name+"' (this should never happen), so skipped writing map entry")
player_x = None player_x = None
player_y = None player_y = None
player_z = None player_z = None
@ -1186,60 +1235,82 @@ class MTChunks:
#map_player_position_tuple = None #map_player_position_tuple = None
saved_player_x = None saved_player_x = None
saved_player_y = None saved_player_y = None
saved_player_y = None saved_player_z = None
#map_player_position_tuple = saved_player_x, saved_player_y, saved_player_z #map_player_position_tuple = saved_player_x, saved_player_y, saved_player_z
is_moved = False is_moved = False
if "x" in self.players[file_name].keys(): if "x" in self.players[file_name].keys():
saved_player_x = float(self.players[file_name]["x"]) saved_player_x = float(self.players[file_name]["x"])
if int(saved_player_x) != int(player_x): if int(saved_player_x) != int(player_x):
is_moved = True is_moved = True
if self.verbose_enable:
print(min_indent+"x changed for playerid '"+file_name+"' so marking for save.")
else: else:
self.players[file_name]["x"] = player_x self.players[file_name]["x"] = player_x
is_moved = True is_moved = True
if self.verbose_enable:
print(min_indent+"No x for playerid '"+file_name+"' so marking for save.")
if "y" in self.players[file_name].keys(): if "y" in self.players[file_name].keys():
saved_player_y = float(self.players[file_name]["y"]) saved_player_y = float(self.players[file_name]["y"])
if int(saved_player_y) != int(player_y): if int(saved_player_y) != int(player_y):
is_moved = True is_moved = True
if self.verbose_enable:
print(min_indent+"y changed for playerid '"+file_name+"' so marking for save.")
else: else:
self.players[file_name]["y"] = player_y self.players[file_name]["y"] = player_y
is_moved = True is_moved = True
if self.verbose_enable:
print(min_indent+"No y for playerid '"+file_name+"' so marking for save.")
if "z" in self.players[file_name].keys(): if "z" in self.players[file_name].keys():
saved_player_z = float(self.players[file_name]["z"]) saved_player_z = float(self.players[file_name]["z"])
if int(saved_player_z) != int(player_z): if int(saved_player_z) != int(player_z):
is_moved = True is_moved = True
if self.verbose_enable:
print(min_indent+"z changed for playerid '"+file_name+"' so marking for save.")
else: else:
self.players[file_name]["z"] = player_z self.players[file_name]["z"] = player_z
is_moved = True is_moved = True
if self.verbose_enable:
print(min_indent+"No z for playerid '"+file_name+"' so marking for save.")
if is_moved: if is_moved:
if self.verbose_enable:
print(min_indent+"Moved so marking as changed")
is_changed = True is_changed = True
#if (self.players[file_name] is None) or not is_same_fvec3( map_player_position_tuple, player_position_tuple): #if (self.players[file_name] is None) or not is_same_fvec3( map_player_position_tuple, player_position_tuple):
#if (self.players[file_name] is None) or (saved_player_x is None) or (saved_player_z is None) or (int(saved_player_x)!=int(player_x)) or (int(saved_player_y)!=int(player_y)) or (int(saved_player_z)!=int(player_z)): #if (self.players[file_name] is None) or (saved_player_x is None) or (saved_player_z is None) or (int(saved_player_x)!=int(player_x)) or (int(saved_player_y)!=int(player_y)) or (int(saved_player_z)!=int(player_z)):
if is_changed: if is_changed:
if self.verbose_enable:
print(min_indent+player_name+" changed.")
# don't check y since y is elevation in minetest, don't use float since subblock position doesn't matter to map # don't check y since y is elevation in minetest, don't use float since subblock position doesn't matter to map
#if self.players[file_name] is not None and saved_player_x is not None and saved_player_y is not None and saved_player_z is not None: #if self.players[file_name] is not None and saved_player_x is not None and saved_player_y is not None and saved_player_z is not None:
if is_moved: if is_moved:
#print("PLAYER MOVED: "+str(player_name)+" moved from "+str(map_player_position_tuple)+" to "+str(player_position_tuple)) #print("PLAYER MOVED: "+str(player_name)+" moved from "+str(map_player_position_tuple)+" to "+str(player_position_tuple))
if self.verbose_enable: if self.verbose_enable:
print("PLAYER MOVED: "+str(player_name)+" moved from "+str(saved_player_x)+","+str(saved_player_y)+","+str(saved_player_z)+" to "+str(player_x)+","+str(player_y)+","+str(player_z)) print(min_indent+"PLAYER MOVED: "+str(player_name)+" moved from "+str(saved_player_x)+","+str(saved_player_y)+","+str(saved_player_z)+" to "+str(player_x)+","+str(player_y)+","+str(player_z))
self.last_player_move_mtime_string = this_mtime_string self.last_player_move_mtime_string = this_mtime_string
players_moved_count += 1 players_moved_count += 1
self.players[file_name]["utc_mtime"]=this_mtime_string self.players[file_name]["utc_mtime"]=this_mtime_string
else: else:
if self.verbose_enable: if self.verbose_enable:
print("SAVING YAML for player '"+str(player_name)+"'") print(min_indent+"SAVING map entry for player '"+str(player_name)+"'")
players_saved_count += 1 players_saved_count += 1
save_conf_from_dict(player_dest_path, self.players[file_name], ":", save_nulls_enable=False) #set BEFORE saving to prevent unecessary resaving on successive runs:
#prevent resaving over and over:
self.players[file_name]["x"] = player_x self.players[file_name]["x"] = player_x
self.players[file_name]["y"] = player_y self.players[file_name]["y"] = player_y
self.players[file_name]["z"] = player_z self.players[file_name]["z"] = player_z
if player_dest_path is not None:
if self.verbose_enable:
print(min_indent+"saving '"+player_dest_path+"'")
save_conf_from_dict(player_dest_path, self.players[file_name], ":", save_nulls_enable=False)
else:
print(min_indent+"Could not save playerid '"+file_name+"' since generating map entry path failed")
#outs = open(player_dest_path, 'w') #outs = open(player_dest_path, 'w')
#outs.write("id:"+file_name) #outs.write("playerid:"+file_name)
#if player_name is not None: #if player_name is not None:
# outs.write("name:"+player_name+"\n") # python automatically uses correct newline for your os when you put "\n" # outs.write("name:"+player_name+"\n") # python automatically uses correct newline for your os when you put "\n"
##if player_position is not None: ##if player_position is not None:
@ -1254,8 +1325,8 @@ class MTChunks:
#outs.close() #outs.close()
player_written_count += 1 player_written_count += 1
else: else:
#if self.verbose_enable: if self.verbose_enable:
#print("DIDN'T MOVE: "+str(player_name)) print("DIDN'T MOVE: "+str(player_name))
players_didntmove_count += 1 players_didntmove_count += 1
player_count += 1 player_count += 1
#if not self.verbose_enable: #if not self.verbose_enable:
@ -1904,6 +1975,7 @@ class MTChunks:
elif this_key=="verbose_enable": elif this_key=="verbose_enable":
if type(signals[this_key]) is bool: if type(signals[this_key]) is bool:
self.verbose_enable = signals[this_key] self.verbose_enable = signals[this_key]
self.is_verbose_explicit = self.verbose_enable
else: else:
is_signal_ok = False is_signal_ok = False
print("ERROR: expected true or false after colon for "+this_key) print("ERROR: expected true or false after colon for "+this_key)
@ -1924,7 +1996,8 @@ class MTChunks:
def run_loop(self): def run_loop(self):
#self.last_run_second = best_timer() #self.last_run_second = best_timer()
self.loop_enable = True self.loop_enable = True
self.verbose_enable = False if not self.is_verbose_explicit:
self.verbose_enable = False
is_first_iteration = True is_first_iteration = True
while self.loop_enable: while self.loop_enable:
before_second = best_timer() before_second = best_timer()

Loading…
Cancel
Save