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

Initial take on belt optimization

This commit is contained in:
tobspr
2020-06-26 13:57:07 +02:00
parent 66eac93460
commit 192d1dbedb
9 changed files with 927 additions and 20 deletions

View File

@@ -6,6 +6,9 @@ import { Vector, enumDirection } from "../../core/vector";
import { Math_PI, Math_sin, Math_cos } from "../../core/builtins";
import { globalConfig } from "../../core/config";
import { Entity } from "../entity";
import { BeltPath } from "../belt_path";
export const curvedBeltLength = /* Math_PI / 4 */ 0.78;
export class BeltComponent extends Component {
static getId() {
@@ -39,6 +42,20 @@ export class BeltComponent extends Component {
/** @type {Entity} */
this.followUpCache = null;
/**
* The path this belt is contained in, not serialized
* @type {BeltPath}
*/
this.assignedPath = null;
}
/**
* Returns the effective length of this belt in tile space
* @returns {number}
*/
getEffectiveLengthTiles() {
return this.direction === enumDirection.top ? 1.0 : curvedBeltLength;
}
/**
@@ -50,14 +67,17 @@ export class BeltComponent extends Component {
transformBeltToLocalSpace(progress) {
switch (this.direction) {
case enumDirection.top:
assert(progress <= 1.02, "Invalid progress: " + progress);
return new Vector(0, 0.5 - progress);
case enumDirection.right: {
const arcProgress = progress * 0.5 * Math_PI;
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 2: " + progress);
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math_PI;
return new Vector(0.5 - 0.5 * Math_cos(arcProgress), 0.5 - 0.5 * Math_sin(arcProgress));
}
case enumDirection.left: {
const arcProgress = progress * 0.5 * Math_PI;
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 3: " + progress);
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math_PI;
return new Vector(-0.5 + 0.5 * Math_cos(arcProgress), 0.5 - 0.5 * Math_sin(arcProgress));
}
default:

View File

@@ -194,4 +194,17 @@ export class ItemEjectorComponent extends Component {
this.slots[slotIndex].progress = this.instantEject ? 1 : 0;
return true;
}
/**
* Clears the given slot and returns the item it had
* @param {number} slotIndex
* @returns {BaseItem|null}
*/
takeSlotItem(slotIndex) {
const slot = this.slots[slotIndex];
const item = slot.item;
slot.item = null;
slot.progress = 0.0;
return item;
}
}