Skip to content

Commit 594a034

Browse files
committed
e
1 parent f931a1a commit 594a034

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

DialogueSystem.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Originally made for [SpiritAxolotl](https://spax.zone/)'s birthday.
2323
- [View code](https://calmbubbles.github.io/js-plugins/DialogueSystem.js) ([View on GitHub](https://github.com/calmbubbles/js-plugins/blob/main/DialogueSystem.js))
2424
- [View raw code](https://calmbubbles.github.io/js-plugins/raw/DialogueSystem.js) ([View on GitHub](https://github.com/calmbubbles/js-plugins/blob/main/raw/DialogueSystem.js))
2525

26-
Version: 2f<br>
27-
Last Updated: July 6, 2024
26+
Version: 2.1f<br>
27+
Last Updated: April 25, 2025
2828

2929

3030
## CookieJar.js

raw/DialogueSystem.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A JavaScript plugin that adds a div based RPG style dialogue system. Which includes animation, audio, images and function call logic.
44
Originally made for SpiritAxolotl's birthday.
55
6-
Version : 2f - Raw
6+
Version : 2.1f - Raw
77
88
By CalmBubbles :)
99
@@ -86,7 +86,8 @@ class DialogueLoop
8686
static #deltaTime = 0;
8787
static #calls = [];
8888

89-
static targetFrameRate = 60;
89+
static targetFrameRate = -1;
90+
static vSyncCount = 1;
9091
static timeScale = 1;
9192
static maximumDeltaTime = 0.1111111;
9293

@@ -114,36 +115,47 @@ class DialogueLoop
114115
{
115116
return this.#deltaTime;
116117
}
117-
118+
118119
static #RequestUpdate ()
119120
{
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);
121124
}
122125

123-
static #Update ()
126+
static #UpdateBase ()
124127
{
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;
126137

127-
let accumulator = (1e-3 * performance.now()) - this.#uTime;
138+
this.#Invoke();
128139

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)
130146
{
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+
}
146157
}
158+
else this.#UpdateBase();
147159

148160
this.#RequestUpdate();
149161
}

0 commit comments

Comments
 (0)