From cf3c2bc9680a014df7c9193f0e764dec7af913cc Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Fri, 16 Oct 2020 10:28:08 +0200 Subject: [PATCH] revamp app with async/await --- .../minetest/world/worldmods/emerger/init.lua | 9 +- dev/docker-compose.yml | 2 + package-lock.json | 368 +----------------- package.json | 1 - src/.jshintrc | 2 +- src/app.js | 6 - src/bounds.js | 19 + src/checkchunk.js | 3 +- src/checkmapblock.js | 4 + src/events.js | 6 - src/index.js | 12 +- src/iterator.js | 118 ------ src/mapblockparser.js | 2 + src/postostring.js | 4 - src/removechunk.js | 1 - src/worker.js | 81 ++-- 16 files changed, 93 insertions(+), 545 deletions(-) delete mode 100644 src/app.js create mode 100644 src/bounds.js delete mode 100644 src/events.js delete mode 100644 src/iterator.js delete mode 100644 src/postostring.js diff --git a/dev/data/minetest/world/worldmods/emerger/init.lua b/dev/data/minetest/world/worldmods/emerger/init.lua index 066525e..3421759 100644 --- a/dev/data/minetest/world/worldmods/emerger/init.lua +++ b/dev/data/minetest/world/worldmods/emerger/init.lua @@ -6,7 +6,7 @@ local function execute_mapgen(callback) end local function execute_test(callback) - execute_mapgen(function(blockpos, action, calls_remaining) + execute_mapgen(function(blockpos, _, calls_remaining) print("Emerged: " .. minetest.pos_to_string(blockpos)) if calls_remaining == 0 then callback() @@ -14,12 +14,17 @@ local function execute_test(callback) end) end +local chunks = 0 +minetest.register_on_generated(function(minp) + chunks = chunks + 1 +end) + minetest.register_on_mods_loaded(function() minetest.after(1, function() execute_test(function() -- place bones minetest.set_node({ x=0, y=0, z=0 }, {name="bones:bones"}) - print("Done emerging!") + print("Done emerging " .. chunks .. " chunks") end) end) end) diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml index 58cd3fa..b1e8ead 100644 --- a/dev/docker-compose.yml +++ b/dev/docker-compose.yml @@ -15,6 +15,8 @@ services: postgres: image: postgres:12.4 + ports: + - "5432:5432" environment: POSTGRES_PASSWORD: enter volumes: diff --git a/package-lock.json b/package-lock.json index 2710019..8fcebce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,15 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "accepts": { - "version": "1.3.7", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", - "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", - "requires": { - "mime-types": "~2.1.24", - "negotiator": "0.6.2" - } - }, "ansi-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", @@ -53,11 +44,6 @@ "sprintf-js": "~1.0.2" } }, - "array-flatten": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" - }, "array.prototype.map": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/array.prototype.map/-/array.prototype.map-1.0.2.tgz", @@ -87,23 +73,6 @@ "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==", "dev": true }, - "body-parser": { - "version": "1.19.0", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", - "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", - "requires": { - "bytes": "3.1.0", - "content-type": "~1.0.4", - "debug": "2.6.9", - "depd": "~1.1.2", - "http-errors": "1.7.2", - "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", - "qs": "6.7.0", - "raw-body": "2.4.0", - "type-is": "~1.6.17" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -134,11 +103,6 @@ "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" }, - "bytes": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", - "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" - }, "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", @@ -250,29 +214,6 @@ "date-now": "^0.1.4" } }, - "content-disposition": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", - "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", - "requires": { - "safe-buffer": "5.1.2" - } - }, - "content-type": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", - "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" - }, - "cookie": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", - "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" - }, - "cookie-signature": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" - }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -285,14 +226,6 @@ "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", "dev": true }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -312,16 +245,6 @@ "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" }, - "depd": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" - }, - "destroy": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" - }, "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -377,22 +300,12 @@ "domelementtype": "1" } }, - "ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" - }, "emoji-regex": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", "dev": true }, - "encodeurl": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" - }, "entities": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", @@ -486,11 +399,6 @@ "is-symbol": "^1.0.2" } }, - "escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" - }, "escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -503,54 +411,12 @@ "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, - "etag": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" - }, "exit": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", "dev": true }, - "express": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", - "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", - "requires": { - "accepts": "~1.3.7", - "array-flatten": "1.1.1", - "body-parser": "1.19.0", - "content-disposition": "0.5.3", - "content-type": "~1.0.4", - "cookie": "0.4.0", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "~1.1.2", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "~1.1.2", - "fresh": "0.5.2", - "merge-descriptors": "1.0.1", - "methods": "~1.1.2", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "path-to-regexp": "0.1.7", - "proxy-addr": "~2.0.5", - "qs": "6.7.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.1.2", - "send": "0.17.1", - "serve-static": "1.14.1", - "setprototypeof": "1.1.1", - "statuses": "~1.5.0", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" - } - }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -560,20 +426,6 @@ "to-regex-range": "^5.0.1" } }, - "finalhandler": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", - "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", - "requires": { - "debug": "2.6.9", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "statuses": "~1.5.0", - "unpipe": "~1.0.0" - } - }, "find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -593,16 +445,6 @@ "is-buffer": "~2.0.3" } }, - "forwarded": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", - "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" - }, - "fresh": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -694,26 +536,6 @@ "readable-stream": "1.1" } }, - "http-errors": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", - "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", - "requires": { - "depd": "~1.1.2", - "inherits": "2.0.3", - "setprototypeof": "1.1.1", - "statuses": ">= 1.5.0 < 2", - "toidentifier": "1.0.0" - } - }, - "iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "requires": { - "safer-buffer": ">= 2.1.2 < 3" - } - }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -727,12 +549,8 @@ "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "ipaddr.js": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true }, "is-arguments": { "version": "1.0.4", @@ -903,12 +721,6 @@ "p-locate": "^5.0.0" } }, - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "log-symbols": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz", @@ -918,39 +730,6 @@ "chalk": "^4.0.0" } }, - "media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" - }, - "merge-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" - }, - "methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" - }, - "mime": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", - "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" - }, - "mime-db": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", - "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" - }, - "mime-types": { - "version": "2.1.27", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", - "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", - "requires": { - "mime-db": "1.44.0" - } - }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -1016,16 +795,6 @@ } } }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "negotiator": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", - "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" - }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -1054,14 +823,6 @@ "object-keys": "^1.0.11" } }, - "on-finished": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", - "requires": { - "ee-first": "1.1.1" - } - }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -1100,11 +861,6 @@ "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz", "integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" }, - "parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" - }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -1117,11 +873,6 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, - "path-to-regexp": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" - }, "pg": { "version": "8.4.0", "resolved": "https://registry.npmjs.org/pg/-/pg-8.4.0.tgz", @@ -1227,20 +978,6 @@ "iterate-value": "^1.0.0" } }, - "proxy-addr": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", - "integrity": "sha512-dh/frvCBVmSsDYzw6n926jv974gddhkFPfiN8hPOi30Wax25QZyZEGveluCgliBnqmuM+UJmBErbAUFIoDbjOw==", - "requires": { - "forwarded": "~0.1.2", - "ipaddr.js": "1.9.1" - } - }, - "qs": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", - "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" - }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -1250,22 +987,6 @@ "safe-buffer": "^5.1.0" } }, - "range-parser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", - "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" - }, - "raw-body": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", - "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==", - "requires": { - "bytes": "3.1.0", - "http-errors": "1.7.2", - "iconv-lite": "0.4.24", - "unpipe": "1.0.0" - } - }, "readable-stream": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", @@ -1331,39 +1052,8 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, - "safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" - }, - "send": { - "version": "0.17.1", - "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", - "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", - "requires": { - "debug": "2.6.9", - "depd": "~1.1.2", - "destroy": "~1.0.4", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "fresh": "0.5.2", - "http-errors": "~1.7.2", - "mime": "1.6.0", - "ms": "2.1.1", - "on-finished": "~2.3.0", - "range-parser": "~1.2.1", - "statuses": "~1.5.0" - }, - "dependencies": { - "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" - } - } + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true }, "serialize-javascript": { "version": "4.0.0", @@ -1374,28 +1064,12 @@ "randombytes": "^2.1.0" } }, - "serve-static": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", - "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", - "requires": { - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "parseurl": "~1.3.3", - "send": "0.17.1" - } - }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, - "setprototypeof": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", - "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" - }, "shelljs": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", @@ -1416,11 +1090,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "statuses": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -1493,35 +1162,6 @@ "is-number": "^7.0.0" } }, - "toidentifier": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", - "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" - }, - "type-is": { - "version": "1.6.18", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", - "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", - "requires": { - "media-typer": "0.3.0", - "mime-types": "~2.1.24" - } - }, - "unpipe": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" - }, - "utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" - }, - "vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" - }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 860c31e..5d8e595 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ }, "homepage": "https://github.com/BuckarooBanzay/mapcleaner#readme", "dependencies": { - "express": "^4.17.1", "pg": "^8.4.0", "pq": "0.0.3" }, diff --git a/src/.jshintrc b/src/.jshintrc index ce3b662..5ab1103 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -1,7 +1,7 @@ { "undef": true, "unused": true, - "esversion": 6, + "esversion": 8, "node": true, "globals": { } diff --git a/src/app.js b/src/app.js deleted file mode 100644 index 9cc2146..0000000 --- a/src/app.js +++ /dev/null @@ -1,6 +0,0 @@ -const express = require('express'); - -const app = express(); -app.use(express.static('public')); - -module.exports = app; diff --git a/src/bounds.js b/src/bounds.js new file mode 100644 index 0000000..7039b1c --- /dev/null +++ b/src/bounds.js @@ -0,0 +1,19 @@ +const executor = require("./executor"); + +module.exports.find_y_bounds = function(){ + return executor(` + select + min(posy) as miny, max(posy) as maxy + from blocks + `, [], { single_row: true }); +}; + +module.exports.find_z_bounds = function(minx, maxx, miny, maxy){ + return executor(` + select + min(posz) as minz, max(posz) as maxz + from blocks + where posx >= $1 and posx <= $2 + and posy >= $3 and posy <= $4 + `, [minx, maxx, miny, maxy], { single_row: true }); +}; diff --git a/src/checkchunk.js b/src/checkchunk.js index ddd5465..8705d64 100644 --- a/src/checkchunk.js +++ b/src/checkchunk.js @@ -1,5 +1,4 @@ -const postostring = require("./postostring"); const coordinates = require("./coordinates"); const checkmapblock = require("./checkmapblock"); const areas = require("./areas"); @@ -7,7 +6,7 @@ const areas = require("./areas"); const cache = {}; module.exports = function(pos){ - const str = postostring(pos); + const str = `${pos.x}/${pos.y}/${pos.z}`; if (cache[str]){ return Promise.resolve(cache[str]); diff --git a/src/checkmapblock.js b/src/checkmapblock.js index 0136551..185b096 100644 --- a/src/checkmapblock.js +++ b/src/checkmapblock.js @@ -27,5 +27,9 @@ module.exports = function(pos){ generated: false }; } + }) + .catch(e => { + console.error("mapblock error", pos, e); + process.exit(); }); }; diff --git a/src/events.js b/src/events.js deleted file mode 100644 index 2d1263d..0000000 --- a/src/events.js +++ /dev/null @@ -1,6 +0,0 @@ -const EventEmitter = require('events'); - - -class MyEmitter extends EventEmitter {} - -module.exports = new MyEmitter(); \ No newline at end of file diff --git a/src/index.js b/src/index.js index 032f47f..b280bcb 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,11 @@ -const app = require("./app"); const worker = require("./worker"); const areas = require("./areas"); -const port = process.env.PORT || 8080; - -app.listen(+port, () => { - console.log(`Listening on http://127.0.0.1:${port}`); -}); - if (process.env.AREAS_FILE) { areas.parse(process.env.AREAS_FILE); } -worker(); +worker() +.then(result => { + console.log(`processed ${result.chunkcount} chunks, removed ${result.removecount} chunks`); +}); diff --git a/src/iterator.js b/src/iterator.js deleted file mode 100644 index 18a9636..0000000 --- a/src/iterator.js +++ /dev/null @@ -1,118 +0,0 @@ -const executor = require("./executor"); - -function find_y_bounds(){ - return executor(` - select - min(posy) as miny, max(posy) as maxy - from blocks - `, [], { single_row: true }); -} - -function find_z_bounds(posx, posy){ - return executor(` - select - min(posz) as minz, max(posz) as maxz - from blocks - where posx = $1 and posy = $2 - `, [posx, posy], { single_row: true }); -} - - -function shift_x(ctx){ - return new Promise(resolve => { - if (ctx.pos.x > 400){ - // end - ctx.pos.x = -400; - resolve(true); - - } else { - // shift - ctx.pos.x++; - resolve(false); - } - }); -} - -function shift_y(ctx){ - if (!ctx.maxy){ - // initialize - - } else if (ctx.pos.y >= ctx.maxy) { - // end - return true; - - } else { - // shift - ctx.pos.y++; - - } -} - -function shift_z(ctx){ - if (!ctx.maxz){ - // initialize - return find_z_bounds(ctx.pos.x * 5, ctx.pos.y * 5) - .then(bounds => { - if (!bounds.maxz){ - // end - return true; - - } else { - ctx.maxz = bounds.maxz; - ctx.pos.z = bounds.minz; - return false; - } - }); - } else if (ctx.pos.z > ctx.maxz) { - // reset - ctx.maxz = null; - ctx.pos.z = null; - return Promise.resolve(true); - - } else { - // shift - ctx.pos.z++; - return Promise.resolve(false); - } -} - -module.exports = function(){ - const ctx = { - pos: { x: -400, y: null, z: -400 }, - maxy: null - }; - - return function(){ - if (!ctx.maxy){ - return find_y_bounds() - .then(bounds => { - ctx.maxy = Math.floor(bounds.maxy / 5) + 1; - ctx.pos.y = Math.floor(bounds.miny / 5) - 1; - - return find_z_bounds(ctx.pos.x * 5, ctx.pos.y * 5); - }) - .then(bounds => { - ctx.pos.z = Math.floor(bounds.minz / 5) - 1; - ctx.maxz = Math.floor(bounds.maxz / 5) + 1; - return ctx.pos; - }); - } - - return shift_z(ctx) - .then(endz => { - - if (endz){ - return shift_x(ctx) - .then(endx => { - - if (endx) { - return shift_y(ctx); - } - }); - } - - }) - .then(endy => endy ? null : ctx.pos); - - }; -}; diff --git a/src/mapblockparser.js b/src/mapblockparser.js index 3049674..d1af171 100644 --- a/src/mapblockparser.js +++ b/src/mapblockparser.js @@ -1,6 +1,7 @@ const zlib = require("zlib"); module.exports.parse = data => new Promise(function(resolve, reject) { + try { const buffer = Buffer.from(data); @@ -98,5 +99,6 @@ module.exports.parse = data => new Promise(function(resolve, reject) { inflate.write(mapdata_buffer); } catch (e) { console.error("possible mapblock corruption detected!", e); + reject(e); } }); diff --git a/src/postostring.js b/src/postostring.js deleted file mode 100644 index 8ba19b6..0000000 --- a/src/postostring.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = function(pos){ - return `${pos.x}/${pos.y}/${pos.z}`; -}; diff --git a/src/removechunk.js b/src/removechunk.js index 790894d..0a10844 100644 --- a/src/removechunk.js +++ b/src/removechunk.js @@ -3,7 +3,6 @@ const coordinates = require("./coordinates"); module.exports = function(pos){ const mapblocks = coordinates.get_mapblocks_from_chunk(pos); - console.log("removechunk", pos, mapblocks); return executor(` delete diff --git a/src/worker.js b/src/worker.js index 09e9f7b..7af89bb 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,44 +1,61 @@ -const iterator = require("./iterator"); const checkchunkwithneighbours = require("./checkchunkwithneighbours"); const removechunk = require("./removechunk"); +const bounds = require("./bounds"); -const it = iterator(); +async function worker() { -function worker() { - it() - .then(pos => { - if (pos){ - if (!pos.z){ - // no data in row, skip - setTimeout(worker, 0); - return; - } - console.log("worker-chunk", pos); - checkchunkwithneighbours(pos) - .then(result => { - console.log("check-chunk", pos, result); + const ybounds = await bounds.find_y_bounds(); + const minychunk = Math.floor((ybounds.miny + 2) / 5); + const maxychunk = Math.floor((ybounds.maxy + 2) / 5); + let chunkcount = 0; + let removecount = 0; + for (let chunky = minychunk; chunky <= maxychunk; chunky++){ + const miny = (chunky * 5) - 2; + const maxy = miny + 4; + const progress = Math.floor( (chunky - minychunk) / (maxychunk - minychunk) * 100 ); + + console.log(`chunky: ${chunky} y-mablocks: ${miny} to ${maxy} progress: ${progress}%`); + + for (let chunkx = -400; chunkx <= 400; chunkx++){ + const minx = (chunkx * 5) - 2; + const maxx = minx + 4; + + const zbounds = await bounds.find_z_bounds(minx, maxx, miny, maxy); + if (zbounds.minz === null) + // no data in this stride + continue; + + //console.log(" zbounds", zbounds); + + const minzchunk = Math.floor((zbounds.minz + 2) / 5); + const maxzchunk = Math.floor((zbounds.maxz + 2) / 5); + + for (let chunkz = minzchunk; chunkz <= maxzchunk; chunkz++){ + const chunkpos = { + x: chunkx, + y: chunky, + z: chunkz + }; + + const result = await checkchunkwithneighbours(chunkpos); if (!result.protected && result.generated){ //not protected and generated, remove - console.log("removing chunk", pos); - removechunk(pos) - .then(() => { - //proceed with next chunk - setTimeout(worker, 500); - }); - } else { - //proceed with next chunk - setTimeout(worker, 0); + console.log("removing chunk", chunkpos); + await removechunk(chunkpos); + removecount++; } - }); - } else { - //done - console.log("done!"); + + chunkcount++; + } + } - }) - .catch(e => { - console.log(e); - }); + } + + return { + chunkcount: chunkcount, + removecount: removecount + }; } module.exports = worker;