diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-04-24 10:21:44 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-04-24 10:21:44 +0800 |
commit | 01b77ec83a7e24afcf4a5000b241bcf11dccfc2c (patch) | |
tree | 69098a54a28ab01953b5539c52c5754288a52f75 /features/waypoints/index.js | |
parent | c7f709952353678af315cd388a76ed0e41626784 (diff) | |
download | SoopyV2-01b77ec83a7e24afcf4a5000b241bcf11dccfc2c.tar.gz SoopyV2-01b77ec83a7e24afcf4a5000b241bcf11dccfc2c.tar.bz2 SoopyV2-01b77ec83a7e24afcf4a5000b241bcf11dccfc2c.zip |
waypoint optimisations
Diffstat (limited to 'features/waypoints/index.js')
-rw-r--r-- | features/waypoints/index.js | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/features/waypoints/index.js b/features/waypoints/index.js index 47806ec..d0d526d 100644 --- a/features/waypoints/index.js +++ b/features/waypoints/index.js @@ -21,8 +21,10 @@ class Waypoints extends Feature { new SettingBase("/savewaypoints", "Copys the waypoints to your clipboard", undefined, "save_waypoints", this) new SettingBase("/loadwaypoints", "Loads waypoints from your clipboard", undefined, "load_waypoints", this) - this.waypoints = [] this.userWaypoints = JSON.parse(FileLib.read("soopyAddonsData", "soopyv2userwaypoints.json") || "{}") + this.userWaypointsHash = {} + this.userWaypointsAll = [] + this.updateWaypointsHashes() this.userWaypointsArr = Object.values(this.userWaypoints) this.waypointsChanged = false @@ -57,6 +59,7 @@ class Waypoints extends Feature { this.userWaypointsArr = Object.values(this.userWaypoints) this.waypointsChanged = true + this.updateWaypointsHashes() ChatLib.chat(this.FeatureManager.messagePrefix + "Added waypoint " + name + "!") }) @@ -64,12 +67,14 @@ class Waypoints extends Feature { delete this.userWaypoints[name] this.userWaypointsArr = Object.values(this.userWaypoints) this.waypointsChanged = true + this.updateWaypointsHashes() ChatLib.chat(this.FeatureManager.messagePrefix + "Deleted waypoint " + name + "!") }) this.registerCommand("clearwaypoints", () => { this.userWaypoints = {} this.userWaypointsArr = [] this.waypointsChanged = true + this.updateWaypointsHashes() ChatLib.chat(this.FeatureManager.messagePrefix + "Cleared waypoints!") }) this.registerCommand("savewaypoints", () => { @@ -82,6 +87,7 @@ class Waypoints extends Feature { this.userWaypointsArr = Object.values(this.userWaypoints) this.waypointsChanged = true + this.updateWaypointsHashes() ChatLib.chat(this.FeatureManager.messagePrefix + "Loaded waypoints from clipboard!") } catch (e) { ChatLib.chat(this.FeatureManager.messagePrefix + "Error loading from clipboard!") @@ -89,31 +95,32 @@ class Waypoints extends Feature { }) } - addWaypoint(x, y, z, r, g, b, options) { - this.waypoints.push({ - x: x, - y: y, - z: z, - r: r, - g: g, - b: b, - options: options - }) + updateWaypointsHashes() { + this.userWaypointsAll = [] + this.userWaypointsHash = {} + for (let waypoint of this.userWaypointsArr) { + if (!waypoint.area) { + this.userWaypointsAll.push(waypoint) + } else { + if (!this.userWaypointsHash[waypoint.area]) this.userWaypointsHash[waypoint.area] = [] + this.userWaypointsHash[waypoint.area].push(waypoint) + } + } } renderWorldLast() { - for (let waypoint of this.waypoints) { + for (let waypoint of this.userWaypointsAll) { drawCoolWaypoint(waypoint.x, waypoint.y, waypoint.z, waypoint.r, waypoint.g, waypoint.b, waypoint.options) } - for (let waypoint of this.userWaypointsArr) { //TODO: Performance optimisation: Make hash from waypoint.area -> waypoints[] - if (!waypoint.area || this.FeatureManager.features["dataLoader"].class.area === waypoint.area) { - drawCoolWaypoint(waypoint.x, waypoint.y, waypoint.z, waypoint.r, waypoint.g, waypoint.b, { ...waypoint.options }) + if (this.userWaypointsHash[this.FeatureManager.features["dataLoader"].class.area]) { + for (let waypoint of this.userWaypointsHash[this.FeatureManager.features["dataLoader"].class.area]) { + drawCoolWaypoint(waypoint.x, waypoint.y, waypoint.z, waypoint.r, waypoint.g, waypoint.b, waypoint.options) } } } initVariables() { - this.waypoints = undefined + } onDisable() { |