From 2926a42218ae83642423f2fc0c45461687f3dca0 Mon Sep 17 00:00:00 2001 From: XeroName <63216951+XeroName@users.noreply.github.com> Date: Wed, 16 Aug 2023 12:01:18 +0900 Subject: [PATCH] Add XeroName/Deltatime extension (#622) --- extensions/XeroName/Deltatime.js | 56 +++++++++++++++++++++++ images/README.md | 3 ++ images/XeroName/Deltatime.svg | 8 ++++ website/XeroName/Deltatime.html | 78 ++++++++++++++++++++++++++++++++ website/index.ejs | 6 +++ 5 files changed, 151 insertions(+) create mode 100644 extensions/XeroName/Deltatime.js create mode 100644 images/XeroName/Deltatime.svg create mode 100644 website/XeroName/Deltatime.html diff --git a/extensions/XeroName/Deltatime.js b/extensions/XeroName/Deltatime.js new file mode 100644 index 0000000000..705b90e13c --- /dev/null +++ b/extensions/XeroName/Deltatime.js @@ -0,0 +1,56 @@ +(function (Scratch) { + 'use strict'; + + const icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjAwIiBoZWlnaHQ9IjYwMCIgdmlld0JveD0iMCAwIDYwMCA2MDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxjaXJjbGUgY3g9IjMwMCIgY3k9IjMwMCIgcj0iMzAwIiBmaWxsPSIjMjAyMDIwIi8+CjxwYXRoIGQ9Ik04Ny44NjggNTEyLjEzMkM2MC4wMTA0IDQ4NC4yNzQgMzcuOTEyNSA0NTEuMjAzIDIyLjgzNjEgNDE0LjgwNUM3Ljc1OTcyIDM3OC40MDcgLTMuNDQ0MTZlLTA2IDMzOS4zOTcgMCAzMDBDMy40NDQxNmUtMDYgMjYwLjYwMyA3Ljc1OTc0IDIyMS41OTMgMjIuODM2MiAxODUuMTk1QzM3LjkxMjYgMTQ4Ljc5NyA2MC4wMTA0IDExNS43MjYgODcuODY4IDg3Ljg2NzlDMTE1LjcyNiA2MC4wMTA0IDE0OC43OTcgMzcuOTEyNSAxODUuMTk1IDIyLjgzNjFDMjIxL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jU0ODYgNDEzLjYyOUM4MC4yODU4IDQxNC4yODUgODAuNzY5NiA0MTUgODEuNDc3IDQxNUgyNzguNTIzQzI3OS4yMyA0MTUgMjc5LjcxNCA0MTQuMjg1IDI3OS40NTEgNDEzLjYyOVoiIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMzIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPgo8L3N2Zz4K'; + + if (!Scratch.extensions.unsandboxed) { + throw new Error('DeltaTime must be run unsandboxed'); + } + + const vm = Scratch.vm; + + let deltaTime = 0; + let previousTime = 0; + + vm.runtime.on('BEFORE_EXECUTE', () => { + const now = performance.now(); + deltaTime = previousTime === 0 ? 0 : (now - previousTime) / 1000; + previousTime = now; + }); + + class Dt { + getInfo() { + return { + id: 'dtbyxeroname', + name: 'Deltatime', + docsURI: 'https://extensions.turbowarp.org/XeroName/Deltatime.html', + color1: '#333333', + color2: '#444444', + color3: '#ffffff', + menuIconURI: icon, + blocks: [ + { + opcode: 'dt', + blockType: Scratch.BlockType.REPORTER, + text: 'ΔT' + }, + { + opcode: 'fps', + blockType: Scratch.BlockType.REPORTER, + text: 'fps' + } + ] + }; + } + + dt() { + return deltaTime; + } + + fps() { + return +(1 / deltaTime).toFixed(2); + } + } + + Scratch.extensions.register(new Dt()); +})(Scratch); diff --git a/images/README.md b/images/README.md index 0600c79be7..de3105dca5 100644 --- a/images/README.md +++ b/images/README.md @@ -252,3 +252,6 @@ All images in this folder are licensed under the [GNU General Public License ver - Created by [@LilyMakesThings](https://github.com/LilyMakesThings). - Dango based on dango from [Twemoji](https://twemoji.twitter.com/) under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). - Background "blobs" by Scratch. + +## XeroName/Deltatime.svg + - Created by [@XeroName](https://scratch.mit.edu/users/plant2014/) in https://github.com/TurboWarp/extensions/pull/622 diff --git a/images/XeroName/Deltatime.svg b/images/XeroName/Deltatime.svg new file mode 100644 index 0000000000..ed5d6c4ccb --- /dev/null +++ b/images/XeroName/Deltatime.svg @@ -0,0 +1,8 @@ + diff --git a/website/XeroName/Deltatime.html b/website/XeroName/Deltatime.html new file mode 100644 index 0000000000..c812040e1c --- /dev/null +++ b/website/XeroName/Deltatime.html @@ -0,0 +1,78 @@ +
FPS
and ΔT
value of dtbx have following properties :
FPS
block returns roundary integer value of current Framerate using Math.round()
.FPS
block starts to return real number of current Framerate by 2 decimal places using .toFixed(2)
.FPS
value is not grater than 0, ΔT
value will be also set to 0 until FPS
grater than 0.Filter Strength
(aka strength) is a value that directly determines the performance and stability of FPS. Cannot be smaller than 1.Set Calculator Standard to (NUM) FPS
block sets the standard FPS value that Calculator refers.Standard FPS of Calculator
block returns the standard FPS value of Calculator. Default set to 30.Value to Move (NUM) with ΔT
block returns multiply value of require value to move or rotate at Standard FPS of Calculator
, which equals to NUM*CalcStandardFPS.dtbx의 FPS
와 ΔT
값은 다음과 같은 속성을 가집니다.
FPS
블럭은 JS의 Math.round()
함수를 사용하여 현재 주사율을 정수로 반올림한 값을 반환합니다.FPS
블럭은 현재 주사율의 소수 이하 2번째 자릿수 까지의 실수 값을 반환하기 시작합니다. 해당 상황에서는 JS의 .toFixed(2)
함수를 사용합니다.FPS
값이 0보다 크지 않을 경우, FPS
값이 0보다 커질 때까지 ΔT
값 또한 0으로 설정됩니다.Filter Strength
(일명 필터 강도)는 FPS의 안정성 및 성능을 직접적으로 결정하는 값입니다. 1보다 작을 수 없습니다.FPS
및 ΔT
값에 다음과 같은 변화가 일어나게 됩니다.Set Calculator Standard to (NUM) FPS
블록은 계산기가 참조할 FPS의 표준 값을 설정합니다.Standard FPS of Calculator
블록은 계산기의 설정된 표준 FPS 값을 반환합니다. 기본값은 30입니다.Value to Move (NUM) with ΔT
블록은 표준 FPS값에서 ΔT 곱했을 때 일정하게 움직이거나 회전할 수 있는 값을 계산하여 반환합니다. 이 값은 NUM*CalcStandardFPS와 같습니다.Display notifications.
+Precise delta timing blocks. Created by XeroName.
+