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

Get rid of 'builtins' file since its useless and causes performance issues

This commit is contained in:
tobspr
2020-06-27 10:51:52 +02:00
parent 14246929b3
commit 2e266f5f21
60 changed files with 256 additions and 403 deletions

View File

@@ -1,4 +1,3 @@
import { Math_radians } from "../../../core/builtins";
import { globalConfig } from "../../../core/config";
import { DrawParameters } from "../../../core/draw_parameters";
import { drawRotatedSprite } from "../../../core/draw_utils";
@@ -368,7 +367,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
sprite: this.lockIndicatorSprite,
x: worldPos.x,
y: worldPos.y,
angle: Math_radians(rotation),
angle: Math.radians(rotation),
size: 12,
offsetY:
-globalConfig.halfTileSize -
@@ -432,7 +431,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
sprite,
x: acceptorSlotWsPos.x,
y: acceptorSlotWsPos.y,
angle: Math_radians(enumDirectionToAngle[enumInvertedDirections[worldDirection]]),
angle: Math.radians(enumDirectionToAngle[enumInvertedDirections[worldDirection]]),
size: 13,
offsetY: offsetShift + 13,
});
@@ -478,7 +477,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
sprite,
x: ejectorSLotWsPos.x,
y: ejectorSLotWsPos.y,
angle: Math_radians(enumDirectionToAngle[ejectorSlotWsDirection]),
angle: Math.radians(enumDirectionToAngle[ejectorSlotWsDirection]),
size: 13,
offsetY: offsetShift,
});

View File

@@ -1,4 +1,3 @@
import { Math_abs, Math_degrees, Math_round } from "../../../core/builtins";
import { globalConfig } from "../../../core/config";
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
@@ -565,10 +564,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
// Place from start to corner
const pathToCorner = this.currentDirectionLockCorner.sub(startTile);
const deltaToCorner = pathToCorner.normalize().round();
const lengthToCorner = Math_round(pathToCorner.length());
const lengthToCorner = Math.round(pathToCorner.length());
let currentPos = startTile.copy();
let rotation = (Math.round(Math_degrees(deltaToCorner.angle()) / 90) * 90 + 360) % 360;
let rotation = (Math.round(Math.degrees(deltaToCorner.angle()) / 90) * 90 + 360) % 360;
if (lengthToCorner > 0) {
for (let i = 0; i < lengthToCorner; ++i) {
@@ -583,10 +582,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
// Place from corner to end
const pathFromCorner = mouseTile.sub(this.currentDirectionLockCorner);
const deltaFromCorner = pathFromCorner.normalize().round();
const lengthFromCorner = Math_round(pathFromCorner.length());
const lengthFromCorner = Math.round(pathFromCorner.length());
if (lengthFromCorner > 0) {
rotation = (Math.round(Math_degrees(deltaFromCorner.angle()) / 90) * 90 + 360) % 360;
rotation = (Math.round(Math.degrees(deltaFromCorner.angle()) / 90) * 90 + 360) % 360;
for (let i = 0; i < lengthFromCorner + 1; ++i) {
result.push({
tile: currentPos.copy(),
@@ -722,7 +721,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
).pressed
) {
const delta = newPos.sub(oldPos);
const angleDeg = Math_degrees(delta.angle());
const angleDeg = Math.degrees(delta.angle());
this.currentBaseRotation = (Math.round(angleDeg / 90) * 90 + 360) % 360;
// Holding alt inverts the placement
@@ -737,8 +736,8 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
let x1 = newPos.x;
let y1 = newPos.y;
var dx = Math_abs(x1 - x0);
var dy = Math_abs(y1 - y0);
var dx = Math.abs(x1 - x0);
var dy = Math.abs(y1 - y0);
var sx = x0 < x1 ? 1 : -1;
var sy = y0 < y1 ? 1 : -1;
var err = dx - dy;

View File

@@ -1,6 +1,5 @@
import { BaseHUDPart } from "../base_hud_part";
import { makeDiv, round3Digits, round2Digits } from "../../../core/utils";
import { Math_round } from "../../../core/builtins";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { KEYMAPPINGS } from "../../key_action_mapper";
@@ -34,7 +33,7 @@ export class HUDDebugInfo extends BaseHUDPart {
this.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate;
this.fpsElement.innerText =
"FPS: " +
Math_round(this.root.dynamicTickrate.averageFps) +
Math.round(this.root.dynamicTickrate.averageFps) +
" (" +
round2Digits(1000 / this.root.dynamicTickrate.averageFps) +
" ms)";

View File

@@ -1,4 +1,3 @@
import { Math_max } from "../../../core/builtins";
import { ClickDetector } from "../../../core/click_detector";
import { formatBigNumber, makeDiv, arrayDelete, arrayDeleteValue } from "../../../core/utils";
import { ShapeDefinition } from "../../shape_definition";

View File

@@ -1,6 +1,5 @@
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { BaseHUDPart } from "../base_hud_part";
import { performanceNow } from "../../../core/builtins";
import { makeDiv } from "../../../core/utils";
import { Signal } from "../../../core/signal";
import { InputReceiver } from "../../../core/input_receiver";
@@ -62,15 +61,15 @@ export class HUDProcessingOverlay extends BaseHUDPart {
}
processSync() {
const now = performanceNow();
const now = performance.now();
while (this.tasks.length > 0) {
const workload = this.tasks[0];
workload.call();
this.tasks.shift();
}
const duration = performanceNow() - now;
const duration = performance.now() - now;
if (duration > 100) {
logger.log("Tasks done slow (SYNC!) within", (performanceNow() - now).toFixed(2), "ms");
logger.log("Tasks done slow (SYNC!) within", (performance.now() - now).toFixed(2), "ms");
}
}
@@ -89,15 +88,15 @@ export class HUDProcessingOverlay extends BaseHUDPart {
}
this.computeTimeout = setTimeout(() => {
const now = performanceNow();
const now = performance.now();
while (this.tasks.length > 0) {
const workload = this.tasks[0];
workload.call();
this.tasks.shift();
}
const duration = performanceNow() - now;
const duration = performance.now() - now;
if (duration > 100) {
logger.log("Tasks done slow within", (performanceNow() - now).toFixed(2), "ms");
logger.log("Tasks done slow within", (performance.now() - now).toFixed(2), "ms");
}
this.domWatcher.update(false);

View File

@@ -5,7 +5,6 @@ import { T } from "../../../translations";
import { createLogger } from "../../../core/logging";
import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { Vector } from "../../../core/vector";
import { Math_max, Math_min, Math_floor } from "../../../core/builtins";
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
import { DrawParameters } from "../../../core/draw_parameters";
import { Rectangle } from "../../../core/rectangle";
@@ -43,11 +42,11 @@ export class HUDScreenshotExporter extends BaseHUDPart {
const maxTile = new Vector(0, 0);
for (let i = 0; i < staticEntities.length; ++i) {
const bounds = staticEntities[i].components.StaticMapEntity.getTileSpaceBounds();
minTile.x = Math_min(minTile.x, bounds.x);
minTile.y = Math_min(minTile.y, bounds.y);
minTile.x = Math.min(minTile.x, bounds.x);
minTile.y = Math.min(minTile.y, bounds.y);
maxTile.x = Math_max(maxTile.x, bounds.x + bounds.w);
maxTile.y = Math_max(maxTile.y, bounds.y + bounds.h);
maxTile.x = Math.max(maxTile.x, bounds.x + bounds.w);
maxTile.y = Math.max(maxTile.y, bounds.y + bounds.h);
}
const minChunk = minTile.divideScalar(globalConfig.mapChunkSize).floor();
@@ -57,10 +56,10 @@ export class HUDScreenshotExporter extends BaseHUDPart {
logger.log("Dimensions:", dimensions);
let chunkSizePixels = 128;
const maxDimensions = Math_max(dimensions.x, dimensions.y);
const maxDimensions = Math.max(dimensions.x, dimensions.y);
if (maxDimensions > 128) {
chunkSizePixels = Math_max(1, Math_floor(128 * (128 / maxDimensions)));
chunkSizePixels = Math.max(1, Math.floor(128 * (128 / maxDimensions)));
}
logger.log("ChunkSizePixels:", chunkSizePixels);

View File

@@ -1,4 +1,3 @@
import { Math_min } from "../../../core/builtins";
import { ClickDetector } from "../../../core/click_detector";
import { InputReceiver } from "../../../core/input_receiver";
import { formatBigNumber, makeDiv } from "../../../core/utils";
@@ -178,7 +177,7 @@ export class HUDShop extends BaseHUDPart {
const { progressLabel, progressBar, definition, required } = handle.requireIndexToElement[i];
const haveAmount = this.root.hubGoals.getShapesStored(definition);
const progress = Math_min(haveAmount / required, 1.0);
const progress = Math.min(haveAmount / required, 1.0);
progressLabel.innerText = formatBigNumber(haveAmount) + " / " + formatBigNumber(required);
progressBar.style.width = progress * 100.0 + "%";

View File

@@ -1,4 +1,3 @@
import { Math_min } from "../../../core/builtins";
import { InputReceiver } from "../../../core/input_receiver";
import { makeButton, makeDiv, removeAllChildren, capitalizeFirstLetter } from "../../../core/utils";
import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper";
@@ -179,7 +178,7 @@ export class HUDStatistics extends BaseHUDPart {
let rendered = new Set();
for (let i = 0; i < Math_min(entries.length, 200); ++i) {
for (let i = 0; i < Math.min(entries.length, 200); ++i) {
const entry = entries[i];
const shapeKey = entry[0];

View File

@@ -1,5 +1,4 @@
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
import { Math_max, Math_PI, Math_radians } from "../../../core/builtins";
import { globalConfig, IS_DEMO } from "../../../core/config";
import { DrawParameters } from "../../../core/draw_parameters";
import { Loader } from "../../../core/loader";
@@ -270,7 +269,7 @@ export class HUDWaypoints extends BaseHUDPart {
center: { x: position.x, y: position.y },
// Make sure the zoom is *just* a bit above the zoom level where the map overview
// starts, so you always see all buildings
zoomLevel: Math_max(this.root.camera.zoomLevel, globalConfig.mapChunkOverviewMinZoom + 0.05),
zoomLevel: Math.max(this.root.camera.zoomLevel, globalConfig.mapChunkOverviewMinZoom + 0.05),
});
// Sort waypoints by name
@@ -419,7 +418,7 @@ export class HUDWaypoints extends BaseHUDPart {
if (this.currentCompassOpacity > 0.01) {
context.globalAlpha = this.currentCompassOpacity;
const angle = cameraPos.angle() + Math_radians(45) + Math_PI / 2;
const angle = cameraPos.angle() + Math.radians(45) + Math.PI / 2;
context.translate(dims / 2, dims / 2);
context.rotate(angle);
this.directionIndicatorSprite.drawCentered(context, 0, 0, indicatorSize);

View File

@@ -1,7 +1,6 @@
import { GameRoot } from "../root";
import { globalConfig } from "../../core/config";
import { Vector, mixVector } from "../../core/vector";
import { performanceNow } from "../../core/builtins";
import { lerp } from "../../core/utils";
/* dev:start */
@@ -87,7 +86,7 @@ export class TrailerMaker {
if (!nextMarker.startTime) {
console.log("Starting to approach", nextMarker.pos);
nextMarker.startTime = performanceNow() / 1000.0;
nextMarker.startTime = performance.now() / 1000.0;
}
const speed =
@@ -98,7 +97,7 @@ export class TrailerMaker {
// this.currentPlaybackOrigin.distance(Vector.fromSerializedObject(nextMarker.pos)) / speed;
const time = nextMarker.time;
const progress = (performanceNow() / 1000.0 - nextMarker.startTime) / time;
const progress = (performance.now() / 1000.0 - nextMarker.startTime) / time;
if (progress > 1.0) {
if (nextMarker.wait > 0) {