Skip to content

Commit b0abf43

Browse files
committed
fix: adjust particle speed based on actual frame rate
- Add real-time frame rate measurement to normalize particle speed - Update frame rate calculation every 500ms for better performance - Apply frame rate adjustment (60/fps) to maintain consistent particle movement speed across different devices
1 parent dc0b017 commit b0abf43

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

example/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# example
22

3+
## 0.3.5
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- cesium-wind-layer@0.5.1
9+
310
## 0.3.4
411

512
### Patch Changes

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example",
33
"private": true,
4-
"version": "0.3.4",
4+
"version": "0.3.5",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

packages/cesium-wind-layer/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# cesium-wind-layer
22

3+
## 0.5.1
4+
5+
### Patch Changes
6+
7+
- fix: adjust particle speed based on actual frame rate
8+
9+
- Add real-time frame rate measurement to normalize particle speed
10+
- Update frame rate calculation every 500ms for better performance
11+
- Apply frame rate adjustment (60/fps) to maintain consistent particle movement speed across different devices
12+
313
## 0.5.0
414

515
### Minor Changes

packages/cesium-wind-layer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cesium-wind-layer",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"publishConfig": {
55
"access": "public"
66
},

packages/cesium-wind-layer/src/windParticlesComputing.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export class WindParticlesComputing {
2525
};
2626
private bounds: WindData['bounds'];
2727
windData: Required<WindData>;
28+
private frameRate: number = 60;
29+
private lastFrameTime: number = 0;
30+
private frameRateUpdateInterval: number = 500; // Update frame rate every 500ms
31+
private frameCount: number = 0;
32+
private frameRateStartTime: number = 0;
2833

2934
constructor(context: any, windData: Required<WindData>, options: WindLayerOptions, viewerParameters: any) {
3035
this.context = context;
@@ -33,11 +38,24 @@ export class WindParticlesComputing {
3338
this.bounds = windData.bounds;
3439
this.windData = windData;
3540

41+
this.frameRateStartTime = performance.now();
3642
this.createWindTextures();
3743
this.createParticlesTextures();
3844
this.createComputingPrimitives();
3945
}
4046

47+
private updateFrameRate() {
48+
const currentTime = performance.now();
49+
this.frameCount++;
50+
51+
// Update frame rate every 500ms
52+
if (currentTime - this.frameRateStartTime >= this.frameRateUpdateInterval) {
53+
this.frameRate = Math.round((this.frameCount * 1000) / (currentTime - this.frameRateStartTime));
54+
this.frameCount = 0;
55+
this.frameRateStartTime = currentTime;
56+
}
57+
}
58+
4159
createWindTextures() {
4260
const options = {
4361
context: this.context,
@@ -107,7 +125,6 @@ export class WindParticlesComputing {
107125
(maximum.y - minimum.y) / (dimension.y - 1)
108126
);
109127

110-
111128
this.primitives = {
112129
calculateSpeed: new CustomPrimitive({
113130
commandType: 'Compute',
@@ -118,7 +135,11 @@ export class WindParticlesComputing {
118135
vRange: () => new Cartesian2(this.windData.v.min, this.windData.v.max),
119136
speedRange: () => new Cartesian2(this.windData.speed.min, this.windData.speed.max),
120137
currentParticlesPosition: () => this.particlesTextures.currentParticlesPosition,
121-
speedScaleFactor: () => (this.viewerParameters.pixelSize + 50) * this.options.speedFactor,
138+
speedScaleFactor: () => {
139+
this.updateFrameRate();
140+
const frameRateAdjustment = 60 / this.frameRate;
141+
return (this.viewerParameters.pixelSize + 50) * this.options.speedFactor * frameRateAdjustment;
142+
},
122143
dimension: () => dimension,
123144
minimum: () => minimum,
124145
maximum: () => maximum,

0 commit comments

Comments
 (0)