mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Vastly improve belt performance
This commit is contained in:
@@ -7,6 +7,40 @@ import { enumLayer } from "../root";
|
||||
|
||||
export const curvedBeltLength = /* Math.PI / 4 */ 0.78;
|
||||
|
||||
/** @type {import("./item_acceptor").ItemAcceptorSlot} */
|
||||
export const FAKE_BELT_ACCEPTOR_SLOT = {
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
layer: enumLayer.regular,
|
||||
};
|
||||
|
||||
/** @type {Object<enumDirection, import("./item_ejector").ItemEjectorSlot>} */
|
||||
export const FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION = {
|
||||
[enumDirection.top]: {
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.top,
|
||||
item: null,
|
||||
layer: enumLayer.regular,
|
||||
progress: 0,
|
||||
},
|
||||
|
||||
[enumDirection.right]: {
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.right,
|
||||
item: null,
|
||||
layer: enumLayer.regular,
|
||||
progress: 0,
|
||||
},
|
||||
|
||||
[enumDirection.left]: {
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.left,
|
||||
item: null,
|
||||
layer: enumLayer.regular,
|
||||
progress: 0,
|
||||
},
|
||||
};
|
||||
|
||||
export class BeltComponent extends Component {
|
||||
static getId() {
|
||||
return "Belt";
|
||||
@@ -56,6 +90,27 @@ export class BeltComponent extends Component {
|
||||
return this.direction === enumDirection.top ? 1.0 : curvedBeltLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns fake acceptor slot used for matching
|
||||
* @returns {import("./item_acceptor").ItemAcceptorSlot}
|
||||
*/
|
||||
getFakeAcceptorSlot() {
|
||||
return FAKE_BELT_ACCEPTOR_SLOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns fake acceptor slot used for matching
|
||||
* @returns {import("./item_ejector").ItemEjectorSlot}
|
||||
*/
|
||||
getFakeEjectorSlots() {
|
||||
assert(
|
||||
FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION[this.direction],
|
||||
"Invalid belt direction: ",
|
||||
this.direction
|
||||
);
|
||||
return FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION[this.direction];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from belt space (0 = start of belt ... 1 = end of belt) to the local
|
||||
* belt coordinates (-0.5|-0.5 to 0.5|0.5)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { types } from "../../savegame/serialization";
|
||||
import { gItemRegistry } from "../../core/global_registries";
|
||||
import { Entity } from "../entity";
|
||||
import { enumLayer } from "../root";
|
||||
import { BeltPath } from "../belt_path";
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
@@ -14,6 +15,7 @@ import { enumLayer } from "../root";
|
||||
* layer: enumLayer,
|
||||
* progress: number?,
|
||||
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
|
||||
* cachedBeltPath?: BeltPath,
|
||||
* cachedTargetEntity?: Entity
|
||||
* }} ItemEjectorSlot
|
||||
*/
|
||||
@@ -24,7 +26,7 @@ export class ItemEjectorComponent extends Component {
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
// The cachedDestSlot, cachedTargetEntity, and cachedConnectedSlots fields
|
||||
// The cachedDestSlot, cachedTargetEntity fields
|
||||
// are not serialized.
|
||||
return {
|
||||
instantEject: types.bool,
|
||||
@@ -73,9 +75,6 @@ export class ItemEjectorComponent extends Component {
|
||||
|
||||
this.setSlots(slots);
|
||||
|
||||
/** @type {ItemEjectorSlot[]} */
|
||||
this.cachedConnectedSlots = null;
|
||||
|
||||
/**
|
||||
* Whether this ejector slot is enabled
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user