From c68f5ecacbb1460b25010488d91bbdb022780938 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Mon, 7 Mar 2016 09:26:29 -0500 Subject: [PATCH] simplify decachunk math and change to floor so that chunks are spread evenly whereas plain truncation puts double the amount of files in "0" folders --- chunkymap-regen.py | 47 +++++++++++++++++++++++++--------- install-chunkymap-on-ubuntu.sh | 2 +- web/chunkymap.php | 13 +++++----- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/chunkymap-regen.py b/chunkymap-regen.py index 4c4cd7e..89f4f30 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -11,6 +11,7 @@ from timeit import default_timer as best_timer import time #copyfile etc: import shutil +import math #best_timer = timeit.default_timer #if sys.platform == "win32": @@ -353,6 +354,7 @@ class MTChunks: config_name = None config_path = None data_16px_path = None + data_160px_path = None def __init__(self): #formerly checkpaths() in global scope os_name="linux" @@ -560,7 +562,16 @@ class MTChunks: if not os.path.isfile(htaccess_path): self.deny_http_access(self.data_16px_path) print(" (created .htaccess)") - #TODO: deny access to each hundreds folder under self.data_16px_path? doesn't seem that important for security so maybe not. + + self.data_160px_path = os.path.join(self.chunkymap_data_path, "160px") + if not os.path.isdir(self.data_160px_path): + os.makedirs(self.data_160px_path) + print("Created '"+self.data_160px_path+"'") + if not os.path.isfile(htaccess_path): + self.deny_http_access(self.data_160px_path) + print(" (created .htaccess)") + + #TODO: deny recursively under these folders? doesn't seem that important for security so maybe not (no player info is there) self.install_website() @@ -699,20 +710,32 @@ class MTChunks: def get_signal_path(self): return os.path.join(os.path.dirname(os.path.abspath(__file__)), self.get_signal_name()) + + def get_chunk_folder_path(self, chunky_x, chunky_z): result = None - decachunk_x = None - decachunk_z = None - if chunky_x<0: - decachunk_x = chunky_x + chunky_x%10 - else: - decachunk_x = chunky_x - chunky_x%10 - if chunky_z<0: - decachunk_z = chunky_z + chunky_z%10 - else: - decachunk_z = chunky_z - chunky_z%10 - result = os.path.join( os.path.join(self.data_16px_path, str(decachunk_x)), str(decachunk_z) ) + decachunk_chunky_x = None + decachunk_chunky_z = None + #if chunky_x<0: + # decachunk_chunky_x = chunky_x + chunky_x%10 + #else: + # decachunk_chunky_x = chunky_x - chunky_x%10 + #if chunky_z<0: + # decachunk_chunky_z = chunky_z + chunky_z%10 + #else: + # decachunk_chunky_z = chunky_z - chunky_z%10 + #NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0 + decachunk_chunky_x = int(math.floor(chunky_x/10)) + decachunk_chunky_z = int(math.floor(chunky_z/10)) + result = os.path.join( os.path.join(self.data_16px_path, str(decachunk_chunky_x)), str(decachunk_chunky_z) ) + return result + + def get_decachunk_folder_path_from_chunk(self, chunky_x, chunky_z): + result = None + superchunky_x = int(math.floor(chunky_x/100)) + superchunky_x = int(math.floor(chunky_z/100)) + result = os.path.join( os.path.join(self.data_160px_path, str(superchunky_x)), str(superchunky_x) ) return result def create_chunk_folder(self, chunky_x, chunky_z): diff --git a/install-chunkymap-on-ubuntu.sh b/install-chunkymap-on-ubuntu.sh index a97f559..8c79421 100644 --- a/install-chunkymap-on-ubuntu.sh +++ b/install-chunkymap-on-ubuntu.sh @@ -47,7 +47,7 @@ cp -f "$CHUNKYMAP_INSTALLER_PATH/unused/set-minutely-crontab-job.sh" "$CHUNKYMAP if [ ! -d "$CHUNKYMAP_DEST/web" ]; then mkdir "$CHUNKYMAP_DEST/web" fi -cp -Rf $CHUNKYMAP_INSTALLER_PATH/web/* "$CHUNKYMAP_DEST/web/" +cp -Rf "$CHUNKYMAP_INSTALLER_PATH/web" "$CHUNKYMAP_DEST/" #if [ ! -d "$CHUNKYMAP_DEST/chunkymap" ]; then # mkdir "$CHUNKYMAP_DEST/chunkymap" diff --git a/web/chunkymap.php b/web/chunkymap.php index 5c4edf2..87612f5 100644 --- a/web/chunkymap.php +++ b/web/chunkymap.php @@ -244,12 +244,13 @@ function echo_map_heading_text() { // } function get_chunk_folder_path($x, $z) { global $chunkymapdata_path; - $decachunk_x = null; - $decachunk_z = null; - if ($x<0) { $decachunk_x = $x + $x%10; } - else { $decachunk_x = $x - $x%10; } - if ($z<0) { $decachunk_z = $z + $z%10; } - else { $decachunk_z = $z - $z%10; } + //NOTE: floor converts -.5 to -1 (and -1.5 to -2) but .5 to 0 + $decachunk_x = intval(floor($x/10)); + $decachunk_z = intval(floor($z/10)); + //if ($x<0) { $decachunk_x = $x + $x%10; } + //else { $decachunk_x = $x - $x%10; } + //if ($z<0) { $decachunk_z = $z + $z%10; } + //else { $decachunk_z = $z - $z%10; } $result = $chunkymapdata_path.'/16px/'.$decachunk_x.'/'.$decachunk_z; return $result; }