mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 17:39:26 +02:00
Merge pull request #5942 from ZappoMan/flickeringLightScript
Change the update rate of the flickering light to 30hz
This commit is contained in:
commit
166d267022
1 changed files with 14 additions and 5 deletions
|
@ -39,11 +39,13 @@ var ZERO_VEC = {
|
||||||
};
|
};
|
||||||
|
|
||||||
var totalTime = 0;
|
var totalTime = 0;
|
||||||
|
var lastUpdate = 0;
|
||||||
|
var UPDATE_INTERVAL = 1 / 30; // 30fps
|
||||||
|
|
||||||
var MINIMUM_LIGHT_INTENSITY = 0.75;
|
var MINIMUM_LIGHT_INTENSITY = 0.75;
|
||||||
var MAXIMUM_LIGHT_INTENSITY = 2.75;
|
var MAXIMUM_LIGHT_INTENSITY = 2.75;
|
||||||
var LIGHT_INTENSITY_RANDOMNESS = 0.3;
|
var LIGHT_INTENSITY_RANDOMNESS = 0.3;
|
||||||
var EPHEMERAL_LIFETIME = 10; // ephemeral entities will live for 10 seconds after script stops running
|
var EPHEMERAL_LIFETIME = 60; // ephemeral entities will live for 60 seconds after script stops running
|
||||||
|
|
||||||
var LightMaker = {
|
var LightMaker = {
|
||||||
light: null,
|
light: null,
|
||||||
|
@ -74,10 +76,17 @@ function update(deltaTime) {
|
||||||
LightMaker.spawnLight();
|
LightMaker.spawnLight();
|
||||||
} else {
|
} else {
|
||||||
totalTime += deltaTime;
|
totalTime += deltaTime;
|
||||||
var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY)));
|
|
||||||
intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS);
|
// We don't want to edit the entity EVERY update cycle, because that's just a lot
|
||||||
var properties = Entities.getEntityProperties(LightMaker.light, "age");
|
// of wasted bandwidth and extra effort on the server for very little visual gain
|
||||||
Entities.editEntity(LightMaker.light, { intensity: intensity, lifetime: properties.age + EPHEMERAL_LIFETIME });
|
if (totalTime - lastUpdate > UPDATE_INTERVAL) {
|
||||||
|
var intensity = (MINIMUM_LIGHT_INTENSITY + (MAXIMUM_LIGHT_INTENSITY + (Math.sin(totalTime) * MAXIMUM_LIGHT_INTENSITY)));
|
||||||
|
intensity += randFloat(-LIGHT_INTENSITY_RANDOMNESS, LIGHT_INTENSITY_RANDOMNESS);
|
||||||
|
var properties = Entities.getEntityProperties(LightMaker.light, "age");
|
||||||
|
var newLifetime = properties.age + EPHEMERAL_LIFETIME;
|
||||||
|
Entities.editEntity(LightMaker.light, { type: "Light", intensity: intensity, lifetime: newLifetime });
|
||||||
|
lastUpdate = totalTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue