1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

fix belt animation seeming to go 'backwards' on high belt speeds

This commit is contained in:
tobspr
2020-06-27 09:59:48 +02:00
parent c844dd4798
commit d8bf4f9cd8
3 changed files with 13 additions and 13 deletions

View File

@@ -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;

View File

@@ -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
);