|
3 | 3 | A JavaScript plugin that adds a div based RPG style dialogue system. Which includes animation, audio, images and function call logic.
|
4 | 4 | Originally made for SpiritAxolotl's birthday.
|
5 | 5 |
|
6 |
| -Version : 2f - Raw |
| 6 | +Version : 2.1f - Raw |
7 | 7 |
|
8 | 8 | By CalmBubbles :)
|
9 | 9 |
|
@@ -86,7 +86,8 @@ class DialogueLoop
|
86 | 86 | static #deltaTime = 0;
|
87 | 87 | static #calls = [];
|
88 | 88 |
|
89 |
| - static targetFrameRate = 60; |
| 89 | + static targetFrameRate = -1; |
| 90 | + static vSyncCount = 1; |
90 | 91 | static timeScale = 1;
|
91 | 92 | static maximumDeltaTime = 0.1111111;
|
92 | 93 |
|
@@ -114,36 +115,47 @@ class DialogueLoop
|
114 | 115 | {
|
115 | 116 | return this.#deltaTime;
|
116 | 117 | }
|
117 |
| - |
| 118 | + |
118 | 119 | static #RequestUpdate ()
|
119 | 120 | {
|
120 |
| - requestAnimationFrame(this.#Update.bind(this)); |
| 121 | + if (this.targetFrameRate === 0 || this.vSyncCount === 1) requestAnimationFrame(this.#Update.bind(this)); |
| 122 | + else if (this.vSyncCount === 2) requestAnimationFrame(() => requestAnimationFrame(this.#Update.bind(this))); |
| 123 | + else setTimeout(this.#Update.bind(this), 0); |
121 | 124 | }
|
122 | 125 |
|
123 |
| - static #Update () |
| 126 | + static #UpdateBase () |
124 | 127 | {
|
125 |
| - const slice = (1 / this.targetFrameRate) - 5e-3; |
| 128 | + this.#uDeltaTime = (1e-3 * performance.now()) - this.#uTime; |
| 129 | + this.#uTime += this.#uDeltaTime; |
| 130 | + |
| 131 | + let deltaT = this.#uDeltaTime; |
| 132 | + |
| 133 | + if (deltaT > this.maximumDeltaTime) deltaT = this.maximumDeltaTime; |
| 134 | + |
| 135 | + this.#deltaTime = deltaT * this.timeScale; |
| 136 | + this.#time += this.#deltaTime; |
126 | 137 |
|
127 |
| - let accumulator = (1e-3 * performance.now()) - this.#uTime; |
| 138 | + this.#Invoke(); |
128 | 139 |
|
129 |
| - while (accumulator >= slice) |
| 140 | + if (this.timeScale !== 0) this.#frameIndex++; |
| 141 | + } |
| 142 | + |
| 143 | + static #Update () |
| 144 | + { |
| 145 | + if (this.targetFrameRate > 0 && this.vSyncCount === 0) |
130 | 146 | {
|
131 |
| - this.#uDeltaTime = (1e-3 * performance.now()) - this.#uTime; |
132 |
| - this.#uTime += this.#uDeltaTime; |
133 |
| - |
134 |
| - let deltaT = this.#uDeltaTime; |
135 |
| - |
136 |
| - if (deltaT > this.maximumDeltaTime) deltaT = this.maximumDeltaTime; |
137 |
| - |
138 |
| - this.#deltaTime = deltaT * this.timeScale; |
139 |
| - this.#time += this.#deltaTime; |
140 |
| - |
141 |
| - this.#Invoke(); |
142 |
| - |
143 |
| - this.#frameIndex++; |
144 |
| - |
145 |
| - accumulator -= slice; |
| 147 | + const slice = (1 / this.targetFrameRate) - 5e-3; |
| 148 | + |
| 149 | + let accumulator = (1e-3 * performance.now()) - this.#uTime; |
| 150 | + |
| 151 | + while (accumulator >= slice) |
| 152 | + { |
| 153 | + this.#UpdateBase(); |
| 154 | + |
| 155 | + accumulator -= slice; |
| 156 | + } |
146 | 157 | }
|
| 158 | + else this.#UpdateBase(); |
147 | 159 |
|
148 | 160 | this.#RequestUpdate();
|
149 | 161 | }
|
|
0 commit comments