|
1997 | 1997 | })(); |
1998 | 1998 | (() => { |
1999 | 1999 | function _() { |
2000 | | - let u = 0, a = true, i = document.createElement("div"), r = [], p = () => (performance || Date).now(); |
| 2000 | + let u = 0, a = true, i = document.createElement("div"), n = [], p = () => (performance || Date).now(); |
2001 | 2001 | i.style.cssText = "position:absolute;top:0;right:0;cursor:pointer;opacity:0.8;z-index:10000", i.addEventListener("click", function(e) { |
2002 | 2002 | e.preventDefault(), o(++u % i.children.length); |
2003 | 2003 | }, false); |
2004 | | - function l(e, n, v, t) { |
2005 | | - let w = new P(e, n, v, i, t); |
2006 | | - return r.push(w), w; |
| 2004 | + function l(e, r, x, t) { |
| 2005 | + let g = new T(e, r, x, i, t); |
| 2006 | + return n.push(g), g; |
2007 | 2007 | } |
2008 | 2008 | function o(e) { |
2009 | | - for (let n = 0; n < i.children.length; n++) i.children[n].style.display = n === e ? "block" : "none"; |
| 2009 | + for (let r = 0; r < i.children.length; r++) i.children[r].style.display = r === e ? "block" : "none"; |
2010 | 2010 | u = e; |
2011 | 2011 | } |
2012 | 2012 | function f() { |
2013 | 2013 | u++, u >= i.children.length && (u = 0), o(u); |
2014 | 2014 | } |
2015 | 2015 | function s(e = "all") { |
2016 | | - if (e === "all") for (let n = 0; n < r.length; n++) r[n].reset(); |
2017 | | - else r[e] && r[e].reset(); |
| 2016 | + if (e === "all") for (let r = 0; r < n.length; r++) n[r].reset(); |
| 2017 | + else n[e] && n[e].reset(); |
2018 | 2018 | h = p(), y = 0; |
2019 | 2019 | } |
2020 | | - function g(e = true) { |
| 2020 | + function w(e = true) { |
2021 | 2021 | a = !!e, i.style.display = a ? "" : "none"; |
2022 | 2022 | } |
2023 | 2023 | let b = p(), h = b, y = 0, c = l("FPS", "#0ff", "#002"), d = l("MS", "#0f0", "#020"), m; |
2024 | | - return self.performance && self.performance.memory && (m = l("MB", "#f08", "#201")), o(0), { dom: i, addPanel: l, showPanel: o, nextPanel: f, resetPanel: s, display: g, get hidden() { |
| 2024 | + return self.performance && self.performance.memory && (m = l("MB", "#f08", "#201")), o(0), { dom: i, addPanel: l, showPanel: o, nextPanel: f, resetPanel: s, display: w, get hidden() { |
2025 | 2025 | return !a; |
2026 | 2026 | }, begin: function() { |
2027 | 2027 | b = p(); |
2028 | 2028 | }, end: function() { |
2029 | 2029 | y++; |
2030 | 2030 | let e = p(); |
2031 | 2031 | if (d.update(e - b, 200), e >= h + 1e3 && (c.update(y * 1e3 / (e - h), 100), h = e, y = 0, m)) { |
2032 | | - let n = performance.memory; |
2033 | | - m.update(n.usedJSHeapSize / 1048576, n.jsHeapSizeLimit / 1048576); |
| 2032 | + let r = performance.memory; |
| 2033 | + m.update(r.usedJSHeapSize / 1048576, r.jsHeapSizeLimit / 1048576); |
2034 | 2034 | } |
2035 | 2035 | return e; |
2036 | 2036 | }, update: function() { |
2037 | 2037 | b = this.end(); |
2038 | 2038 | } }; |
2039 | 2039 | } |
2040 | | - function P(u, a, i, r, p = {}) { |
2041 | | - let l = Math.round, o = 1 / 0, f = 0, s = l(window.devicePixelRatio || 1), g = (p.width || 80) * s, b = 48 * s, h = 3 * s, y = 2 * s, c = 3 * s, d = 15 * s, m = (g - 6) * s, e = 30 * s, n = document.createElement("canvas"); |
2042 | | - n.width = g, n.height = b; |
2043 | | - let v = r.children.length; |
2044 | | - r.appendChild(n); |
2045 | | - let t = n.getContext("2d"); |
| 2040 | + function T(u, a, i, n, p = {}) { |
| 2041 | + let l = Math.round, o = 1 / 0, f = 0, s = l(window.devicePixelRatio || 1), w = (p.width || 80) * s, b = 48 * s, h = 3 * s, y = 2 * s, c = 3 * s, d = 15 * s, m = (w - 6) * s, e = 30 * s, r = document.createElement("canvas"); |
| 2042 | + r.width = w, r.height = b; |
| 2043 | + let x = n.children.length; |
| 2044 | + n.appendChild(r); |
| 2045 | + let t = r.getContext("2d"); |
2046 | 2046 | t.font = "bold " + 9 * s + "px Helvetica,Arial,sans-serif", t.textBaseline = "top"; |
2047 | | - function w() { |
2048 | | - t.fillStyle = i, t.fillRect(0, 0, g, b), t.fillStyle = a, t.fillText(u, h, y), t.fillRect(c, d, m, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c, d, m, e); |
| 2047 | + function g() { |
| 2048 | + t.fillStyle = i, t.fillRect(0, 0, w, b), t.fillStyle = a, t.fillText(u, h, y), t.fillRect(c, d, m, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c, d, m, e); |
2049 | 2049 | } |
2050 | | - return w(), { id: v, dom: n, reset: w, update: function(x, E) { |
2051 | | - o = Math.min(o, x), f = Math.max(f, x), t.fillStyle = i, t.globalAlpha = 1, t.fillRect(0, 0, g, d), t.fillStyle = a; |
2052 | | - let T = [l(x), u]; |
2053 | | - p.labelBefore && T.reverse(), t.fillText(T.join(" ") + " (" + l(o) + "-" + l(f) + ")", h, y), t.drawImage(n, c + s, d, m - s, e, c, d, m - s, e), t.fillRect(c + m - s, d, s, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c + m - s, d, s, l((1 - x / E) * e)); |
| 2050 | + return g(), { id: x, dom: r, reset: g, update: function(v, P) { |
| 2051 | + o = Math.min(o, v), f = Math.max(f, v), t.fillStyle = i, t.globalAlpha = 1, t.fillRect(0, 0, w, d), t.fillStyle = a; |
| 2052 | + let E = [l(v), u]; |
| 2053 | + p.labelBefore && E.reverse(), t.fillText(E.join(" ") + " (" + l(o) + "-" + l(f) + ")", h, y), t.drawImage(r, c + s, d, m - s, e, c, d, m - s, e), t.fillRect(c + m - s, d, s, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c + m - s, d, s, l((1 - v / P) * e)); |
2054 | 2054 | } }; |
2055 | 2055 | } |
2056 | 2056 | var k = { hotkeyShow: "F1", hotkeyNext: "F2", css: {}, hidden: false, id: "" }; |
2057 | 2057 | function A(u, a = {}) { |
2058 | 2058 | a = Object.assign({}, k, a); |
2059 | | - let i = u.stat(0), r = new _(), p = r.display, l = (o = true) => { |
2060 | | - a.hidden = !o, p(o), r.resetPanel(); |
| 2059 | + let i = u.stat(0), n = new _(), p = n.display, l = (o = true) => { |
| 2060 | + a.hidden = !o, p(o), n.resetPanel(); |
2061 | 2061 | }; |
2062 | | - a.id && (r.dom.id = a.id); |
2063 | | - for (let [o, f] of Object.entries(a.css || {})) r.dom.style[o] = f; |
2064 | | - return u.canvas().parentElement.appendChild(r.dom), l(!a.hidden), i.keyboardEvents && listen("update", () => { |
2065 | | - a.hotkeyShow && u.iskeypressed(a.hotkeyShow) && l(a.hidden), a.hotkeyNext && u.iskeypressed(a.hotkeyNext) && r.nextPanel(); |
| 2062 | + a.id && (n.dom.id = a.id); |
| 2063 | + for (let [o, f] of Object.entries(a.css || {})) n.dom.style[o] = f; |
| 2064 | + return u.canvas().parentElement.appendChild(n.dom), l(!a.hidden), i.keyboardEvents && listen("update", () => { |
| 2065 | + a.hotkeyShow && u.iskeypressed(a.hotkeyShow) && l(a.hidden), a.hotkeyNext && u.iskeypressed(a.hotkeyNext) && n.nextPanel(); |
2066 | 2066 | }), listen("before:update", (o, f = 1) => { |
2067 | | - a.hidden || f === 1 && r.begin(); |
| 2067 | + a.hidden || f === 1 && n.begin(); |
2068 | 2068 | }), listen("after:draw", () => { |
2069 | | - a.hidden || r.end(); |
2070 | | - }), r.display = l, { FPS_METER: r }; |
| 2069 | + a.hidden || n.end(); |
| 2070 | + }), listen("quit", () => { |
| 2071 | + n.dom.remove(); |
| 2072 | + }), n.display = l, { FPS_METER: n }; |
2071 | 2073 | } |
2072 | 2074 | window.pluginFrameRateMeter = A; |
2073 | 2075 | })(); |
|
0 commit comments