From d8bf4f9cd87591329959816d9da958e4d681d205 Mon Sep 17 00:00:00 2001 From: tobspr Date: Sat, 27 Jun 2020 09:59:48 +0200 Subject: [PATCH] fix belt animation seeming to go 'backwards' on high belt speeds --- src/js/changelog.js | 2 +- src/js/game/systems/belt.js | 13 +++++++------ src/js/game/systems/item_acceptor.js | 11 +++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/js/changelog.js b/src/js/changelog.js index 6123ce59..60425a7b 100644 --- a/src/js/changelog.js +++ b/src/js/changelog.js @@ -7,7 +7,7 @@ export const CHANGELOG = [ "Preparations for the wires update", "Allow clicking on variants to select them", "Add 'copy key' button to shape viewer", - "Add more FPS to the belt animation", + "Add more FPS to the belt animation and fix belt animation seeming to go 'backwards' on high belt speeds", "Fix deconstruct sound being played when right clicking hub", "Allow clicking 'Q' over a shape or color patch to automatically select the miner building (by Gerdon262)", "Update belt placement performance on huge factories (by Phlosioneer)", diff --git a/src/js/game/systems/belt.js b/src/js/game/systems/belt.js index 462b7a3d..75d777f0 100644 --- a/src/js/game/systems/belt.js +++ b/src/js/game/systems/belt.js @@ -1,18 +1,18 @@ -import { Math_sqrt } from "../../core/builtins"; +import { Math_min } from "../../core/builtins"; import { globalConfig } from "../../core/config"; import { DrawParameters } from "../../core/draw_parameters"; +import { gMetaBuildingRegistry } from "../../core/global_registries"; import { Loader } from "../../core/loader"; import { createLogger } from "../../core/logging"; import { AtlasSprite } from "../../core/sprites"; +import { fastArrayDeleteValue } from "../../core/utils"; import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../../core/vector"; import { BeltPath } from "../belt_path"; +import { arrayBeltVariantToRotation, MetaBeltBaseBuilding } from "../buildings/belt_base"; import { BeltComponent } from "../components/belt"; import { Entity } from "../entity"; import { GameSystemWithFilter } from "../game_system_with_filter"; import { MapChunkView } from "../map_chunk_view"; -import { fastArrayDeleteValue } from "../../core/utils"; -import { gMetaBuildingRegistry } from "../../core/global_registries"; -import { MetaBeltBaseBuilding, arrayBeltVariantToRotation } from "../buildings/belt_base"; import { defaultBuildingVariant } from "../meta_building"; export const BELT_ANIM_COUNT = 28; @@ -469,12 +469,13 @@ export class BeltSystem extends GameSystemWithFilter { return; } - const speedMultiplier = this.root.hubGoals.getBeltBaseSpeed(); + // Limit speed to avoid belts going backwards + const speedMultiplier = Math_min(this.root.hubGoals.getBeltBaseSpeed(), 10); // SYNC with systems/item_acceptor.js:drawEntityUnderlays! // 126 / 42 is the exact animation speed of the png animation const animationIndex = Math.floor( - ((this.root.time.now() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) * + ((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) * globalConfig.itemSpacingOnBelts ); const contents = chunk.contents; diff --git a/src/js/game/systems/item_acceptor.js b/src/js/game/systems/item_acceptor.js index f583f116..6647ee9a 100644 --- a/src/js/game/systems/item_acceptor.js +++ b/src/js/game/systems/item_acceptor.js @@ -6,7 +6,7 @@ import { enumDirectionToVector, enumDirectionToAngle } from "../../core/vector"; import { ItemAcceptorComponent } from "../components/item_acceptor"; import { Loader } from "../../core/loader"; import { drawRotatedSprite } from "../../core/draw_utils"; -import { Math_radians } from "../../core/builtins"; +import { Math_radians, Math_min } from "../../core/builtins"; import { BELT_ANIM_COUNT } from "./belt"; export class ItemAcceptorSystem extends GameSystemWithFilter { @@ -94,6 +94,9 @@ export class ItemAcceptorSystem extends GameSystemWithFilter { return; } + // Limit speed to avoid belts going backwards + const speedMultiplier = Math_min(this.root.hubGoals.getBeltBaseSpeed(), 10); + const underlays = acceptorComp.beltUnderlays; for (let i = 0; i < underlays.length; ++i) { const { pos, direction } = underlays[i]; @@ -103,11 +106,7 @@ export class ItemAcceptorSystem extends GameSystemWithFilter { // SYNC with systems/belt.js:drawSingleEntity! const animationIndex = Math.floor( - ((this.root.time.now() * - this.root.hubGoals.getBeltBaseSpeed() * - this.underlayBeltSprites.length * - 126) / - 42) * + ((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) * globalConfig.itemSpacingOnBelts );