From 65ced2e44dde8a556de3a8fa516c23d9cb20b2be Mon Sep 17 00:00:00 2001 From: isaisstillalive Date: Wed, 15 Jul 2020 23:20:15 +0900 Subject: [PATCH] Changed to consider floating point error in the process of subtracting time --- src/js/game/systems/item_ejector.js | 3 ++- src/js/game/systems/item_processor.js | 3 ++- src/js/game/systems/underground_belt.js | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 316dc053..bf62d854 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -8,6 +8,7 @@ import { ItemEjectorComponent } from "../components/item_ejector"; import { Entity } from "../entity"; import { GameSystemWithFilter } from "../game_system_with_filter"; import { enumLayer } from "../root"; +import { quantizeFloat } from "../../core/utils"; const logger = createLogger("systems/ejector"); @@ -225,7 +226,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter { ); // Check if we are still in the process of ejecting, can't proceed then - if (sourceSlot.progress < 1.0) { + if (quantizeFloat(sourceSlot.progress) < 1.0) { continue; } diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 8713f599..143e0cef 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -6,6 +6,7 @@ import { Entity } from "../entity"; import { GameSystemWithFilter } from "../game_system_with_filter"; import { ColorItem } from "../items/color_item"; import { ShapeItem } from "../items/shape_item"; +import { quantizeFloat } from "../../core/utils"; export class ItemProcessorSystem extends GameSystemWithFilter { constructor(root) { @@ -31,7 +32,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { // Check if we have any finished items we can eject if ( - processorComp.secondsUntilEject === 0 && // it was processed in time + quantizeFloat(processorComp.secondsUntilEject) == 0 && // it was processed in time processorComp.itemsToEject.length > 0 // we have some items left to eject ) { for (let itemIndex = 0; itemIndex < processorComp.itemsToEject.length; ++itemIndex) { diff --git a/src/js/game/systems/underground_belt.js b/src/js/game/systems/underground_belt.js index f5e1b0ab..70e51a5c 100644 --- a/src/js/game/systems/underground_belt.js +++ b/src/js/game/systems/underground_belt.js @@ -12,7 +12,7 @@ import { import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt"; import { Entity } from "../entity"; import { GameSystemWithFilter } from "../game_system_with_filter"; -import { fastArrayDelete } from "../../core/utils"; +import { fastArrayDelete, quantizeFloat } from "../../core/utils"; import { enumLayer } from "../root"; const logger = createLogger("tunnels"); @@ -362,7 +362,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter { const nextItem = nextItemAndDuration[0]; // Check if the item is ready to be emitted - if (remainingTime === 0) { + if (quantizeFloat(remainingTime) == 0) { // Check if the receiver can accept it if ( receiver.entity.components.UndergroundBelt.tryAcceptTunneledItem( @@ -392,7 +392,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter { const remainingTime = nextItemAndDuration[1]; const nextItem = nextItemAndDuration[0]; - if (remainingTime <= 0) { + if (quantizeFloat(remainingTime) == 0) { const ejectorComp = entity.components.ItemEjector; const nextSlotIndex = ejectorComp.getFirstFreeSlot(entity.layer);