mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-07 01:54:10 +00:00
Get rid of 'builtins' file since its useless and causes performance issues
This commit is contained in:
parent
14246929b3
commit
2e266f5f21
@ -105,6 +105,8 @@ module.exports = ({
|
|||||||
passes: 2,
|
passes: 2,
|
||||||
module: true,
|
module: true,
|
||||||
pure_funcs: [
|
pure_funcs: [
|
||||||
|
"Math.radians",
|
||||||
|
"Math.degrees",
|
||||||
"Math.round",
|
"Math.round",
|
||||||
"Math.ceil",
|
"Math.ceil",
|
||||||
"Math.floor",
|
"Math.floor",
|
||||||
@ -119,21 +121,6 @@ module.exports = ({
|
|||||||
"Math.sign",
|
"Math.sign",
|
||||||
"Math.pow",
|
"Math.pow",
|
||||||
"Math.atan2",
|
"Math.atan2",
|
||||||
|
|
||||||
"Math_round",
|
|
||||||
"Math_ceil",
|
|
||||||
"Math_floor",
|
|
||||||
"Math_sqrt",
|
|
||||||
"Math_hypot",
|
|
||||||
"Math_abs",
|
|
||||||
"Math_max",
|
|
||||||
"Math_min",
|
|
||||||
"Math_sin",
|
|
||||||
"Math_cos",
|
|
||||||
"Math_tan",
|
|
||||||
"Math_sign",
|
|
||||||
"Math_pow",
|
|
||||||
"Math_atan2",
|
|
||||||
],
|
],
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe_math: true,
|
unsafe_math: true,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { AnimationFrame } from "./core/animation_frame";
|
import { AnimationFrame } from "./core/animation_frame";
|
||||||
import { BackgroundResourcesLoader } from "./core/background_resources_loader";
|
import { BackgroundResourcesLoader } from "./core/background_resources_loader";
|
||||||
import { performanceNow } from "./core/builtins";
|
|
||||||
import { IS_MOBILE } from "./core/config";
|
import { IS_MOBILE } from "./core/config";
|
||||||
import { GameState } from "./core/game_state";
|
import { GameState } from "./core/game_state";
|
||||||
import { GLOBAL_APP, setGlobalApp } from "./core/globals";
|
import { GLOBAL_APP, setGlobalApp } from "./core/globals";
|
||||||
@ -356,7 +355,7 @@ export class Application {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const time = performanceNow();
|
const time = performance.now();
|
||||||
|
|
||||||
// Periodically check for resizes, this is expensive (takes 2-3ms so only do it once in a while!)
|
// Periodically check for resizes, this is expensive (takes 2-3ms so only do it once in a while!)
|
||||||
if (!this.lastResizeCheck || time - this.lastResizeCheck > 1000) {
|
if (!this.lastResizeCheck || time - this.lastResizeCheck > 1000) {
|
||||||
|
@ -4,8 +4,6 @@ import { Signal } from "./signal";
|
|||||||
import BackgroundAnimationFrameEmitterWorker from "../webworkers/background_animation_frame_emittter.worker";
|
import BackgroundAnimationFrameEmitterWorker from "../webworkers/background_animation_frame_emittter.worker";
|
||||||
|
|
||||||
import { createLogger } from "./logging";
|
import { createLogger } from "./logging";
|
||||||
import { performanceNow } from "./builtins";
|
|
||||||
|
|
||||||
const logger = createLogger("animation_frame");
|
const logger = createLogger("animation_frame");
|
||||||
|
|
||||||
const maxDtMs = 1000;
|
const maxDtMs = 1000;
|
||||||
@ -34,7 +32,7 @@ export class AnimationFrame {
|
|||||||
* @param {MessageEvent} event
|
* @param {MessageEvent} event
|
||||||
*/
|
*/
|
||||||
handleBackgroundTick(event) {
|
handleBackgroundTick(event) {
|
||||||
const time = performanceNow();
|
const time = performance.now();
|
||||||
if (!this.bgLastTime) {
|
if (!this.bgLastTime) {
|
||||||
// First update, first delta is always 16ms
|
// First update, first delta is always 16ms
|
||||||
this.bgFrameEmitted.dispatch(1000 / 60);
|
this.bgFrameEmitted.dispatch(1000 / 60);
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
import CompressionWorker from "../webworkers/compression.worker";
|
import CompressionWorker from "../webworkers/compression.worker";
|
||||||
import { createLogger } from "./logging";
|
import { createLogger } from "./logging";
|
||||||
import { compressX64 } from "./lzstring";
|
import { compressX64 } from "./lzstring";
|
||||||
import { performanceNow, JSON_stringify } from "./builtins";
|
|
||||||
|
|
||||||
const logger = createLogger("async_compression");
|
const logger = createLogger("async_compression");
|
||||||
|
|
||||||
export let compressionPrefix = String.fromCodePoint(1);
|
export let compressionPrefix = String.fromCodePoint(1);
|
||||||
@ -53,7 +51,7 @@ class AsynCompression {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const duration = performanceNow() - jobData.startTime;
|
const duration = performance.now() - jobData.startTime;
|
||||||
// log(this, "Got response from worker within", duration.toFixed(2), "ms");
|
// log(this, "Got response from worker within", duration.toFixed(2), "ms");
|
||||||
const resolver = jobData.resolver;
|
const resolver = jobData.resolver;
|
||||||
delete this.currentJobs[jobId];
|
delete this.currentJobs[jobId];
|
||||||
@ -100,7 +98,7 @@ class AsynCompression {
|
|||||||
this.currentJobs[jobId] = {
|
this.currentJobs[jobId] = {
|
||||||
errorHandler,
|
errorHandler,
|
||||||
resolver: resolve,
|
resolver: resolve,
|
||||||
startTime: performanceNow(),
|
startTime: performance.now(),
|
||||||
};
|
};
|
||||||
this.worker.postMessage({ jobId, job, data });
|
this.worker.postMessage({ jobId, job, data });
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { globalConfig } from "./config";
|
import { globalConfig } from "./config";
|
||||||
import { Math_max, Math_floor, Math_abs } from "./builtins";
|
|
||||||
import { fastArrayDelete } from "./utils";
|
import { fastArrayDelete } from "./utils";
|
||||||
import { createLogger } from "./logging";
|
import { createLogger } from "./logging";
|
||||||
|
|
||||||
@ -70,8 +69,8 @@ export function makeOffscreenBuffer(w, h, { smooth = true, reusable = true, labe
|
|||||||
}
|
}
|
||||||
if (w < 1 || h < 1) {
|
if (w < 1 || h < 1) {
|
||||||
logger.error("Offscreen buffer size < 0:", w, "x", h);
|
logger.error("Offscreen buffer size < 0:", w, "x", h);
|
||||||
w = Math_max(1, w);
|
w = Math.max(1, w);
|
||||||
h = Math_max(1, h);
|
h = Math.max(1, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
const recommendedSize = 1024 * 1024;
|
const recommendedSize = 1024 * 1024;
|
||||||
@ -79,8 +78,8 @@ export function makeOffscreenBuffer(w, h, { smooth = true, reusable = true, labe
|
|||||||
logger.warn("Creating huge buffer:", w, "x", h, "with label", label);
|
logger.warn("Creating huge buffer:", w, "x", h, "with label", label);
|
||||||
}
|
}
|
||||||
|
|
||||||
w = Math_floor(w);
|
w = Math.floor(w);
|
||||||
h = Math_floor(h);
|
h = Math.floor(h);
|
||||||
|
|
||||||
let canvas = null;
|
let canvas = null;
|
||||||
let context = null;
|
let context = null;
|
||||||
@ -103,7 +102,7 @@ export function makeOffscreenBuffer(w, h, { smooth = true, reusable = true, labe
|
|||||||
}
|
}
|
||||||
|
|
||||||
const otherPixels = useableCanvas.width * useableCanvas.height;
|
const otherPixels = useableCanvas.width * useableCanvas.height;
|
||||||
const diff = Math_abs(otherPixels - currentPixels);
|
const diff = Math.abs(otherPixels - currentPixels);
|
||||||
if (diff < bestMatchingPixelsDiff) {
|
if (diff < bestMatchingPixelsDiff) {
|
||||||
bestMatchingPixelsDiff = diff;
|
bestMatchingPixelsDiff = diff;
|
||||||
bestMatchingOne = {
|
bestMatchingOne = {
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
// Store the original version of all builtins to prevent modification
|
|
||||||
|
|
||||||
export const JSON_stringify = JSON.stringify.bind(JSON);
|
|
||||||
export const JSON_parse = JSON.parse.bind(JSON);
|
|
||||||
|
|
||||||
export function Math_radians(degrees) {
|
|
||||||
return (degrees * Math_PI) / 180.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Math_degrees(radians) {
|
|
||||||
return (radians * 180.0) / Math_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const performanceNow = performance.now.bind(performance);
|
|
||||||
|
|
||||||
export const Math_abs = Math.abs.bind(Math);
|
|
||||||
export const Math_ceil = Math.ceil.bind(Math);
|
|
||||||
export const Math_floor = Math.floor.bind(Math);
|
|
||||||
export const Math_round = Math.round.bind(Math);
|
|
||||||
export const Math_sign = Math.sign.bind(Math);
|
|
||||||
export const Math_sqrt = Math.sqrt.bind(Math);
|
|
||||||
export const Math_min = Math.min.bind(Math);
|
|
||||||
export const Math_max = Math.max.bind(Math);
|
|
||||||
export const Math_sin = Math.sin.bind(Math);
|
|
||||||
export const Math_cos = Math.cos.bind(Math);
|
|
||||||
export const Math_tan = Math.tan.bind(Math);
|
|
||||||
export const Math_hypot = Math.hypot.bind(Math);
|
|
||||||
export const Math_atan2 = Math.atan2.bind(Math);
|
|
||||||
export const Math_pow = Math.pow.bind(Math);
|
|
||||||
export const Math_random = Math.random.bind(Math);
|
|
||||||
export const Math_exp = Math.exp.bind(Math);
|
|
||||||
export const Math_log10 = Math.log10.bind(Math);
|
|
||||||
|
|
||||||
export const Math_PI = 3.1415926;
|
|
@ -1,4 +1,3 @@
|
|||||||
import { performanceNow } from "../core/builtins";
|
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { Signal } from "../core/signal";
|
import { Signal } from "../core/signal";
|
||||||
import { fastArrayDelete, fastArrayDeleteValueIfContained } from "./utils";
|
import { fastArrayDelete, fastArrayDeleteValueIfContained } from "./utils";
|
||||||
@ -246,7 +245,7 @@ export class ClickDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window.TouchEvent && event instanceof TouchEvent) {
|
if (window.TouchEvent && event instanceof TouchEvent) {
|
||||||
clickDetectorGlobals.lastTouchTime = performanceNow();
|
clickDetectorGlobals.lastTouchTime = performance.now();
|
||||||
|
|
||||||
// console.log("Got touches", event.targetTouches.length, "vs", expectedRemainingTouches);
|
// console.log("Got touches", event.targetTouches.length, "vs", expectedRemainingTouches);
|
||||||
if (event.targetTouches.length !== expectedRemainingTouches) {
|
if (event.targetTouches.length !== expectedRemainingTouches) {
|
||||||
@ -255,7 +254,7 @@ export class ClickDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event instanceof MouseEvent) {
|
if (event instanceof MouseEvent) {
|
||||||
if (performanceNow() - clickDetectorGlobals.lastTouchTime < 1000.0) {
|
if (performance.now() - clickDetectorGlobals.lastTouchTime < 1000.0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,7 +339,7 @@ export class ClickDetector {
|
|||||||
|
|
||||||
// Store where the touch started
|
// Store where the touch started
|
||||||
this.clickDownPosition = position;
|
this.clickDownPosition = position;
|
||||||
this.clickStartTime = performanceNow();
|
this.clickStartTime = performance.now();
|
||||||
this.touchstartSimple.dispatch(this.clickDownPosition.x, this.clickDownPosition.y);
|
this.touchstartSimple.dispatch(this.clickDownPosition.x, this.clickDownPosition.y);
|
||||||
|
|
||||||
// If we are not currently within a click, register it
|
// If we are not currently within a click, register it
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { Math_ceil, Math_floor, Math_round } from "./builtins";
|
|
||||||
import { round1Digit, round2Digits } from "./utils";
|
import { round1Digit, round2Digits } from "./utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +22,7 @@ export function smoothenDpi(dpi) {
|
|||||||
} else if (dpi < 1) {
|
} else if (dpi < 1) {
|
||||||
return round1Digit(dpi);
|
return round1Digit(dpi);
|
||||||
} else {
|
} else {
|
||||||
return round1Digit(Math_round(dpi / 0.5) * 0.5);
|
return round1Digit(Math.round(dpi / 0.5) * 0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +58,11 @@ export function prepareHighDPIContext(context, smooth = true) {
|
|||||||
export function resizeHighDPICanvas(canvas, w, h, smooth = true) {
|
export function resizeHighDPICanvas(canvas, w, h, smooth = true) {
|
||||||
const dpi = getDeviceDPI();
|
const dpi = getDeviceDPI();
|
||||||
|
|
||||||
const wNumber = Math_floor(w);
|
const wNumber = Math.floor(w);
|
||||||
const hNumber = Math_floor(h);
|
const hNumber = Math.floor(h);
|
||||||
|
|
||||||
const targetW = Math_floor(wNumber * dpi);
|
const targetW = Math.floor(wNumber * dpi);
|
||||||
const targetH = Math_floor(hNumber * dpi);
|
const targetH = Math.floor(hNumber * dpi);
|
||||||
|
|
||||||
if (targetW !== canvas.width || targetH !== canvas.height) {
|
if (targetW !== canvas.width || targetH !== canvas.height) {
|
||||||
// console.log("Resize Canvas from", canvas.width, canvas.height, "to", targetW, targetH)
|
// console.log("Resize Canvas from", canvas.width, canvas.height, "to", targetW, targetH)
|
||||||
@ -82,8 +81,8 @@ export function resizeHighDPICanvas(canvas, w, h, smooth = true) {
|
|||||||
* @param {number} h
|
* @param {number} h
|
||||||
*/
|
*/
|
||||||
export function resizeCanvas(canvas, w, h, setStyle = true) {
|
export function resizeCanvas(canvas, w, h, setStyle = true) {
|
||||||
const actualW = Math_ceil(w);
|
const actualW = Math.ceil(w);
|
||||||
const actualH = Math_ceil(h);
|
const actualH = Math.ceil(h);
|
||||||
if (actualW !== canvas.width || actualH !== canvas.height) {
|
if (actualW !== canvas.width || actualH !== canvas.height) {
|
||||||
canvas.width = actualW;
|
canvas.width = actualW;
|
||||||
canvas.height = actualH;
|
canvas.height = actualH;
|
||||||
@ -103,8 +102,8 @@ export function resizeCanvas(canvas, w, h, setStyle = true) {
|
|||||||
* @param {number} h
|
* @param {number} h
|
||||||
*/
|
*/
|
||||||
export function resizeCanvasAndClear(canvas, context, w, h) {
|
export function resizeCanvasAndClear(canvas, context, w, h) {
|
||||||
const actualW = Math_ceil(w);
|
const actualW = Math.ceil(w);
|
||||||
const actualH = Math_ceil(h);
|
const actualH = Math.ceil(h);
|
||||||
if (actualW !== canvas.width || actualH !== canvas.height) {
|
if (actualW !== canvas.width || actualH !== canvas.height) {
|
||||||
canvas.width = actualW;
|
canvas.width = actualW;
|
||||||
canvas.height = actualH;
|
canvas.height = actualH;
|
||||||
|
@ -3,7 +3,6 @@ import { AtlasSprite } from "./sprites";
|
|||||||
import { DrawParameters } from "./draw_parameters";
|
import { DrawParameters } from "./draw_parameters";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
import { Math_PI, Math_round, Math_atan2, Math_hypot, Math_floor } from "./builtins";
|
|
||||||
import { Vector } from "./vector";
|
import { Vector } from "./vector";
|
||||||
import { Rectangle } from "./rectangle";
|
import { Rectangle } from "./rectangle";
|
||||||
import { createLogger } from "./logging";
|
import { createLogger } from "./logging";
|
||||||
@ -40,7 +39,7 @@ export function initDrawUtils() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.beginPath();
|
this.beginPath();
|
||||||
this.arc(x, y, r, 0, 2.0 * Math_PI);
|
this.arc(x, y, r, 0, 2.0 * Math.PI);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,8 +67,8 @@ export function drawLineFast(context, { x1, x2, y1, y2, color = null, lineSize =
|
|||||||
const dX = x2 - x1;
|
const dX = x2 - x1;
|
||||||
const dY = y2 - y1;
|
const dY = y2 - y1;
|
||||||
|
|
||||||
const angle = Math_atan2(dY, dX) + 0.0 * Math_PI;
|
const angle = Math.atan2(dY, dX) + 0.0 * Math.PI;
|
||||||
const len = Math_hypot(dX, dY);
|
const len = Math.hypot(dX, dY);
|
||||||
|
|
||||||
context.translate(x1, y1);
|
context.translate(x1, y1);
|
||||||
context.rotate(angle);
|
context.rotate(angle);
|
||||||
@ -247,7 +246,7 @@ export function hslToRgb(h, s, l) {
|
|||||||
b = hue2rgb(p, q, h - 1 / 3);
|
b = hue2rgb(p, q, h - 1 / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [Math_round(r * 255), Math_round(g * 255), Math_round(b * 255)];
|
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function wrapText(context, text, x, y, maxWidth, lineHeight, stroke = false) {
|
export function wrapText(context, text, x, y, maxWidth, lineHeight, stroke = false) {
|
||||||
@ -306,7 +305,7 @@ export function rotateTrapezRightFaced(x, y, w, h, leftHeight, angle) {
|
|||||||
*/
|
*/
|
||||||
export function mapClampedColorValueToHex(value) {
|
export function mapClampedColorValueToHex(value) {
|
||||||
const hex = "0123456789abcdef";
|
const hex = "0123456789abcdef";
|
||||||
return hex[Math_floor(value / 16)] + hex[value % 16];
|
return hex[Math.floor(value / 16)] + hex[value % 16];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { Math_floor, performanceNow } from "./builtins";
|
|
||||||
|
|
||||||
const circularJson = require("circular-json");
|
const circularJson = require("circular-json");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -231,7 +229,7 @@ function logInternal(handle, consoleMethod, args) {
|
|||||||
const labelColor = handle && handle.LOG_LABEL_COLOR ? handle.LOG_LABEL_COLOR : "#aaa";
|
const labelColor = handle && handle.LOG_LABEL_COLOR ? handle.LOG_LABEL_COLOR : "#aaa";
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.logTimestamps) {
|
if (G_IS_DEV && globalConfig.debug.logTimestamps) {
|
||||||
const timestamp = "⏱ %c" + (Math_floor(performanceNow()) + "").padEnd(6, " ") + "";
|
const timestamp = "⏱ %c" + (Math.floor(performance.now()) + "").padEnd(6, " ") + "";
|
||||||
consoleMethod.call(
|
consoleMethod.call(
|
||||||
console,
|
console,
|
||||||
timestamp + " %c" + context,
|
timestamp + " %c" + context,
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
function mathPolyfills() {
|
function mathPolyfills() {
|
||||||
// Converts from degrees to radians.
|
// Converts from degrees to radians.
|
||||||
Math.radians = function (degrees) {
|
Math.radians = function (degrees) {
|
||||||
return (degrees * Math_PI) / 180.0;
|
return (degrees * Math.PI) / 180.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Converts from radians to degrees.
|
// Converts from radians to degrees.
|
||||||
Math.degrees = function (radians) {
|
Math.degrees = function (radians) {
|
||||||
return (radians * 180.0) / Math_PI;
|
return (radians * 180.0) / Math.PI;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +98,6 @@ function initExtensions() {
|
|||||||
|
|
||||||
// Fetch polyfill
|
// Fetch polyfill
|
||||||
import "whatwg-fetch";
|
import "whatwg-fetch";
|
||||||
import { Math_PI } from "./builtins";
|
|
||||||
|
|
||||||
// Other polyfills
|
// Other polyfills
|
||||||
initPolyfills();
|
initPolyfills();
|
||||||
initExtensions();
|
initExtensions();
|
||||||
|
@ -7,7 +7,6 @@ import { createLogger } from "./logging";
|
|||||||
import { FILE_NOT_FOUND } from "../platform/storage";
|
import { FILE_NOT_FOUND } from "../platform/storage";
|
||||||
import { accessNestedPropertyReverse } from "./utils";
|
import { accessNestedPropertyReverse } from "./utils";
|
||||||
import { IS_DEBUG, globalConfig } from "./config";
|
import { IS_DEBUG, globalConfig } from "./config";
|
||||||
import { JSON_stringify, JSON_parse } from "./builtins";
|
|
||||||
import { ExplainedResult } from "./explained_result";
|
import { ExplainedResult } from "./explained_result";
|
||||||
import { decompressX64, compressX64 } from ".//lzstring";
|
import { decompressX64, compressX64 } from ".//lzstring";
|
||||||
import { asyncCompressor, compressionPrefix } from "./async_compression";
|
import { asyncCompressor, compressionPrefix } from "./async_compression";
|
||||||
@ -84,7 +83,7 @@ export class ReadWriteProxy {
|
|||||||
* @param {object} obj
|
* @param {object} obj
|
||||||
*/
|
*/
|
||||||
static serializeObject(obj) {
|
static serializeObject(obj) {
|
||||||
const jsonString = JSON_stringify(compressObject(obj));
|
const jsonString = JSON.stringify(compressObject(obj));
|
||||||
const checksum = sha1(jsonString + salt);
|
const checksum = sha1(jsonString + salt);
|
||||||
return compressionPrefix + compressX64(checksum + jsonString);
|
return compressionPrefix + compressX64(checksum + jsonString);
|
||||||
}
|
}
|
||||||
@ -129,7 +128,7 @@ export class ReadWriteProxy {
|
|||||||
logger.error("Tried to write invalid data to", this.filename, "reason:", verifyResult.reason);
|
logger.error("Tried to write invalid data to", this.filename, "reason:", verifyResult.reason);
|
||||||
return Promise.reject(verifyResult.reason);
|
return Promise.reject(verifyResult.reason);
|
||||||
}
|
}
|
||||||
const jsonString = JSON_stringify(compressObject(this.currentData));
|
const jsonString = JSON.stringify(compressObject(this.currentData));
|
||||||
|
|
||||||
// if (!this.app.pageVisible || this.app.unloaded) {
|
// if (!this.app.pageVisible || this.app.unloaded) {
|
||||||
// logger.log("Saving file sync because in unload handler");
|
// logger.log("Saving file sync because in unload handler");
|
||||||
@ -189,7 +188,7 @@ export class ReadWriteProxy {
|
|||||||
.then(rawData => {
|
.then(rawData => {
|
||||||
if (rawData == null) {
|
if (rawData == null) {
|
||||||
// So, the file has not been found, use default data
|
// So, the file has not been found, use default data
|
||||||
return JSON_stringify(compressObject(this.getDefaultData()));
|
return JSON.stringify(compressObject(this.getDefaultData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawData.startsWith(compressionPrefix)) {
|
if (rawData.startsWith(compressionPrefix)) {
|
||||||
@ -223,7 +222,7 @@ export class ReadWriteProxy {
|
|||||||
// Parse JSON, this could throw but thats fine
|
// Parse JSON, this could throw but thats fine
|
||||||
.then(res => {
|
.then(res => {
|
||||||
try {
|
try {
|
||||||
return JSON_parse(res);
|
return JSON.parse(res);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
logger.error(
|
logger.error(
|
||||||
"Failed to parse file content of",
|
"Failed to parse file content of",
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { globalConfig } from "./config";
|
import { globalConfig } from "./config";
|
||||||
import { Math_ceil, Math_floor, Math_max, Math_min } from "./builtins";
|
|
||||||
import { clamp, epsilonCompare, round2Digits } from "./utils";
|
import { clamp, epsilonCompare, round2Digits } from "./utils";
|
||||||
import { Vector } from "./vector";
|
import { Vector } from "./vector";
|
||||||
|
|
||||||
@ -38,10 +37,10 @@ export class Rectangle {
|
|||||||
* @param {Vector} p2
|
* @param {Vector} p2
|
||||||
*/
|
*/
|
||||||
static fromTwoPoints(p1, p2) {
|
static fromTwoPoints(p1, p2) {
|
||||||
const left = Math_min(p1.x, p2.x);
|
const left = Math.min(p1.x, p2.x);
|
||||||
const top = Math_min(p1.y, p2.y);
|
const top = Math.min(p1.y, p2.y);
|
||||||
const right = Math_max(p1.x, p2.x);
|
const right = Math.max(p1.x, p2.x);
|
||||||
const bottom = Math_max(p1.y, p2.y);
|
const bottom = Math.max(p1.y, p2.y);
|
||||||
return new Rectangle(left, top, right - left, bottom - top);
|
return new Rectangle(left, top, right - left, bottom - top);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +66,10 @@ export class Rectangle {
|
|||||||
let maxY = -1e10;
|
let maxY = -1e10;
|
||||||
for (let i = 0; i < points.length; ++i) {
|
for (let i = 0; i < points.length; ++i) {
|
||||||
const rotated = points[i].rotated(angle);
|
const rotated = points[i].rotated(angle);
|
||||||
minX = Math_min(minX, rotated.x);
|
minX = Math.min(minX, rotated.x);
|
||||||
minY = Math_min(minY, rotated.y);
|
minY = Math.min(minY, rotated.y);
|
||||||
maxX = Math_max(maxX, rotated.x);
|
maxX = Math.max(maxX, rotated.x);
|
||||||
maxY = Math_max(maxY, rotated.y);
|
maxY = Math.max(maxY, rotated.y);
|
||||||
}
|
}
|
||||||
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
||||||
}
|
}
|
||||||
@ -98,10 +97,10 @@ export class Rectangle {
|
|||||||
this.w = halfWidth * 2;
|
this.w = halfWidth * 2;
|
||||||
this.h = halfHeight * 2;
|
this.h = halfHeight * 2;
|
||||||
} else {
|
} else {
|
||||||
this.setLeft(Math_min(this.x, centerX - halfWidth));
|
this.setLeft(Math.min(this.x, centerX - halfWidth));
|
||||||
this.setRight(Math_max(this.right(), centerX + halfWidth));
|
this.setRight(Math.max(this.right(), centerX + halfWidth));
|
||||||
this.setTop(Math_min(this.y, centerY - halfHeight));
|
this.setTop(Math.min(this.y, centerY - halfHeight));
|
||||||
this.setBottom(Math_max(this.bottom(), centerY + halfHeight));
|
this.setBottom(Math.max(this.bottom(), centerY + halfHeight));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,11 +325,11 @@ export class Rectangle {
|
|||||||
* @returns {Rectangle|null}
|
* @returns {Rectangle|null}
|
||||||
*/
|
*/
|
||||||
getIntersection(rect) {
|
getIntersection(rect) {
|
||||||
const left = Math_max(this.x, rect.x);
|
const left = Math.max(this.x, rect.x);
|
||||||
const top = Math_max(this.y, rect.y);
|
const top = Math.max(this.y, rect.y);
|
||||||
|
|
||||||
const right = Math_min(this.x + this.w, rect.x + rect.w);
|
const right = Math.min(this.x + this.w, rect.x + rect.w);
|
||||||
const bottom = Math_min(this.y + this.h, rect.y + rect.h);
|
const bottom = Math.min(this.y + this.h, rect.y + rect.h);
|
||||||
|
|
||||||
if (right <= left || bottom <= top) {
|
if (right <= left || bottom <= top) {
|
||||||
return null;
|
return null;
|
||||||
@ -354,10 +353,10 @@ export class Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find contained area
|
// Find contained area
|
||||||
const left = Math_min(this.x, rect.x);
|
const left = Math.min(this.x, rect.x);
|
||||||
const top = Math_min(this.y, rect.y);
|
const top = Math.min(this.y, rect.y);
|
||||||
const right = Math_max(this.right(), rect.right());
|
const right = Math.max(this.right(), rect.right());
|
||||||
const bottom = Math_max(this.bottom(), rect.bottom());
|
const bottom = Math.max(this.bottom(), rect.bottom());
|
||||||
|
|
||||||
return Rectangle.fromTRBL(top, right, bottom, left);
|
return Rectangle.fromTRBL(top, right, bottom, left);
|
||||||
}
|
}
|
||||||
@ -388,10 +387,10 @@ export class Rectangle {
|
|||||||
if (includeHalfTiles) {
|
if (includeHalfTiles) {
|
||||||
// Increase rectangle size
|
// Increase rectangle size
|
||||||
scaled = Rectangle.fromTRBL(
|
scaled = Rectangle.fromTRBL(
|
||||||
Math_floor(scaled.y),
|
Math.floor(scaled.y),
|
||||||
Math_ceil(scaled.right()),
|
Math.ceil(scaled.right()),
|
||||||
Math_ceil(scaled.bottom()),
|
Math.ceil(scaled.bottom()),
|
||||||
Math_floor(scaled.x)
|
Math.floor(scaled.x)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { Math_random } from "./builtins";
|
|
||||||
|
|
||||||
// ALEA RNG
|
// ALEA RNG
|
||||||
|
|
||||||
function Mash() {
|
function Mash() {
|
||||||
@ -72,7 +70,7 @@ export class RandomNumberGenerator {
|
|||||||
* @param {number|string=} seed
|
* @param {number|string=} seed
|
||||||
*/
|
*/
|
||||||
constructor(seed) {
|
constructor(seed) {
|
||||||
this.internalRng = makeNewRng(seed || Math_random());
|
this.internalRng = makeNewRng(seed || Math.random());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,7 +78,7 @@ export class RandomNumberGenerator {
|
|||||||
* @param {number|string} seed
|
* @param {number|string} seed
|
||||||
*/
|
*/
|
||||||
reseed(seed) {
|
reseed(seed) {
|
||||||
this.internalRng = makeNewRng(seed || Math_random());
|
this.internalRng = makeNewRng(seed || Math.random());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { DrawParameters } from "./draw_parameters";
|
import { DrawParameters } from "./draw_parameters";
|
||||||
import { Math_floor } from "./builtins";
|
|
||||||
import { Rectangle } from "./rectangle";
|
import { Rectangle } from "./rectangle";
|
||||||
import { epsilonCompare, round3Digits } from "./utils";
|
import { epsilonCompare, round3Digits } from "./utils";
|
||||||
|
|
||||||
@ -195,20 +194,20 @@ export class AtlasSprite extends BaseSprite {
|
|||||||
link.atlas,
|
link.atlas,
|
||||||
|
|
||||||
// atlas src pos
|
// atlas src pos
|
||||||
Math_floor(srcX),
|
Math.floor(srcX),
|
||||||
Math_floor(srcY),
|
Math.floor(srcY),
|
||||||
|
|
||||||
// atlas src size
|
// atlas src size
|
||||||
Math_floor(srcW),
|
Math.floor(srcW),
|
||||||
Math_floor(srcH),
|
Math.floor(srcH),
|
||||||
|
|
||||||
// dest pos
|
// dest pos
|
||||||
Math_floor(destX),
|
Math.floor(destX),
|
||||||
Math_floor(destY),
|
Math.floor(destY),
|
||||||
|
|
||||||
// dest size
|
// dest size
|
||||||
Math_floor(destW),
|
Math.floor(destW),
|
||||||
Math_floor(destH)
|
Math.floor(destH)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
parameters.context.drawImage(
|
parameters.context.drawImage(
|
||||||
|
@ -1,19 +1,4 @@
|
|||||||
import { globalConfig, IS_DEBUG } from "./config";
|
import { globalConfig, IS_DEBUG } from "./config";
|
||||||
import {
|
|
||||||
Math_abs,
|
|
||||||
Math_atan2,
|
|
||||||
Math_ceil,
|
|
||||||
Math_floor,
|
|
||||||
Math_log10,
|
|
||||||
Math_max,
|
|
||||||
Math_min,
|
|
||||||
Math_PI,
|
|
||||||
Math_pow,
|
|
||||||
Math_random,
|
|
||||||
Math_round,
|
|
||||||
Math_sin,
|
|
||||||
performanceNow,
|
|
||||||
} from "./builtins";
|
|
||||||
import { Vector } from "./vector";
|
import { Vector } from "./vector";
|
||||||
import { T } from "../translations";
|
import { T } from "../translations";
|
||||||
|
|
||||||
@ -212,7 +197,7 @@ export function newEmptyMap() {
|
|||||||
* @param {number} end
|
* @param {number} end
|
||||||
*/
|
*/
|
||||||
export function randomInt(start, end) {
|
export function randomInt(start, end) {
|
||||||
return start + Math_round(Math_random() * (end - start));
|
return start + Math.round(Math.random() * (end - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,7 +218,7 @@ export function accessNestedPropertyReverse(obj, keys) {
|
|||||||
* @param {Array | string} arr
|
* @param {Array | string} arr
|
||||||
*/
|
*/
|
||||||
export function randomChoice(arr) {
|
export function randomChoice(arr) {
|
||||||
return arr[Math_floor(Math_random() * arr.length)];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -327,12 +312,12 @@ export function arrayDeleteValue(array, value) {
|
|||||||
* @returns {number} in range [0, 7]
|
* @returns {number} in range [0, 7]
|
||||||
*/
|
*/
|
||||||
export function angleToSpriteIndex(offset, inverse = false) {
|
export function angleToSpriteIndex(offset, inverse = false) {
|
||||||
const twoPi = 2.0 * Math_PI;
|
const twoPi = 2.0 * Math.PI;
|
||||||
const factor = inverse ? -1 : 1;
|
const factor = inverse ? -1 : 1;
|
||||||
const offs = inverse ? 2.5 : 3.5;
|
const offs = inverse ? 2.5 : 3.5;
|
||||||
const angle = (factor * Math_atan2(offset.y, offset.x) + offs * Math_PI) % twoPi;
|
const angle = (factor * Math.atan2(offset.y, offset.x) + offs * Math.PI) % twoPi;
|
||||||
|
|
||||||
const index = Math_round((angle / twoPi) * 8) % 8;
|
const index = Math.round((angle / twoPi) * 8) % 8;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +328,7 @@ export function angleToSpriteIndex(offset, inverse = false) {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export function epsilonCompare(a, b, epsilon = 1e-5) {
|
export function epsilonCompare(a, b, epsilon = 1e-5) {
|
||||||
return Math_abs(a - b) < epsilon;
|
return Math.abs(a - b) < epsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,15 +379,15 @@ export function findNiceValue(num) {
|
|||||||
roundAmount = 5;
|
roundAmount = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
const niceValue = Math_floor(num / roundAmount) * roundAmount;
|
const niceValue = Math.floor(num / roundAmount) * roundAmount;
|
||||||
if (num >= 10) {
|
if (num >= 10) {
|
||||||
return Math_round(niceValue);
|
return Math.round(niceValue);
|
||||||
}
|
}
|
||||||
if (num >= 1) {
|
if (num >= 1) {
|
||||||
return Math_round(niceValue * 10) / 10;
|
return Math.round(niceValue * 10) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math_round(niceValue * 100) / 100;
|
return Math.round(niceValue * 100) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -411,7 +396,7 @@ export function findNiceValue(num) {
|
|||||||
* @param {number} num
|
* @param {number} num
|
||||||
*/
|
*/
|
||||||
export function findNiceIntegerValue(num) {
|
export function findNiceIntegerValue(num) {
|
||||||
return Math_ceil(findNiceValue(num));
|
return Math.ceil(findNiceValue(num));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -422,7 +407,7 @@ function roundSmart(n) {
|
|||||||
if (n < 100) {
|
if (n < 100) {
|
||||||
return n.toFixed(1);
|
return n.toFixed(1);
|
||||||
}
|
}
|
||||||
return Math_round(n);
|
return Math.round(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -433,7 +418,7 @@ function roundSmart(n) {
|
|||||||
*/
|
*/
|
||||||
export function formatBigNumber(num, divider = ".") {
|
export function formatBigNumber(num, divider = ".") {
|
||||||
const sign = num < 0 ? "-" : "";
|
const sign = num < 0 ? "-" : "";
|
||||||
num = Math_abs(num);
|
num = Math.abs(num);
|
||||||
|
|
||||||
if (num > 1e54) {
|
if (num > 1e54) {
|
||||||
return sign + T.global.infinite;
|
return sign + T.global.infinite;
|
||||||
@ -445,7 +430,7 @@ export function formatBigNumber(num, divider = ".") {
|
|||||||
if (num < 50 && !Number.isInteger(num)) {
|
if (num < 50 && !Number.isInteger(num)) {
|
||||||
return sign + num.toFixed(1);
|
return sign + num.toFixed(1);
|
||||||
}
|
}
|
||||||
num = Math_floor(num);
|
num = Math.floor(num);
|
||||||
|
|
||||||
if (num < 1000) {
|
if (num < 1000) {
|
||||||
return sign + "" + num;
|
return sign + "" + num;
|
||||||
@ -482,7 +467,7 @@ export function formatBigNumberFull(num, divider = T.global.thousandsDivider) {
|
|||||||
let out = "";
|
let out = "";
|
||||||
while (rest >= 1000) {
|
while (rest >= 1000) {
|
||||||
out = (rest % 1000).toString().padStart(3, "0") + divider + out;
|
out = (rest % 1000).toString().padStart(3, "0") + divider + out;
|
||||||
rest = Math_floor(rest / 1000);
|
rest = Math.floor(rest / 1000);
|
||||||
}
|
}
|
||||||
out = rest + divider + out;
|
out = rest + divider + out;
|
||||||
|
|
||||||
@ -500,11 +485,11 @@ export function artificialDelayedPromise(promise, minTimeMs = 500) {
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
const startTime = performanceNow();
|
const startTime = performance.now();
|
||||||
return promise.then(
|
return promise.then(
|
||||||
result => {
|
result => {
|
||||||
const timeTaken = performanceNow() - startTime;
|
const timeTaken = performance.now() - startTime;
|
||||||
const waitTime = Math_floor(minTimeMs - timeTaken);
|
const waitTime = Math.floor(minTimeMs - timeTaken);
|
||||||
if (waitTime > 0) {
|
if (waitTime > 0) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -516,8 +501,8 @@ export function artificialDelayedPromise(promise, minTimeMs = 500) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
const timeTaken = performanceNow() - startTime;
|
const timeTaken = performance.now() - startTime;
|
||||||
const waitTime = Math_floor(minTimeMs - timeTaken);
|
const waitTime = Math.floor(minTimeMs - timeTaken);
|
||||||
if (waitTime > 0) {
|
if (waitTime > 0) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -539,7 +524,7 @@ export function artificialDelayedPromise(promise, minTimeMs = 500) {
|
|||||||
* @param {number} seed Seed to offset the animation
|
* @param {number} seed Seed to offset the animation
|
||||||
*/
|
*/
|
||||||
export function pulseAnimation(time, duration = 1.0, seed = 0.0) {
|
export function pulseAnimation(time, duration = 1.0, seed = 0.0) {
|
||||||
return Math_sin((time * Math_PI * 2.0) / duration + seed * 5642.86729349) * 0.5 + 0.5;
|
return Math.sin((time * Math.PI * 2.0) / duration + seed * 5642.86729349) * 0.5 + 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -549,7 +534,7 @@ export function pulseAnimation(time, duration = 1.0, seed = 0.0) {
|
|||||||
* @returns {number} 0 .. 2 PI
|
* @returns {number} 0 .. 2 PI
|
||||||
*/
|
*/
|
||||||
export function smallestAngle(a, b) {
|
export function smallestAngle(a, b) {
|
||||||
return safeMod(a - b + Math_PI, 2.0 * Math_PI) - Math_PI;
|
return safeMod(a - b + Math.PI, 2.0 * Math.PI) - Math.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -566,7 +551,7 @@ export function safeMod(n, m) {
|
|||||||
* @param {number} angle
|
* @param {number} angle
|
||||||
*/
|
*/
|
||||||
export function wrapAngle(angle) {
|
export function wrapAngle(angle) {
|
||||||
return safeMod(angle, 2.0 * Math_PI);
|
return safeMod(angle, 2.0 * Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -589,7 +574,7 @@ export function waitNextFrame() {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
export function round1Digit(n) {
|
export function round1Digit(n) {
|
||||||
return Math_floor(n * 10.0) / 10.0;
|
return Math.floor(n * 10.0) / 10.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -598,7 +583,7 @@ export function round1Digit(n) {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
export function round2Digits(n) {
|
export function round2Digits(n) {
|
||||||
return Math_floor(n * 100.0) / 100.0;
|
return Math.floor(n * 100.0) / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -607,7 +592,7 @@ export function round2Digits(n) {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
export function round3Digits(n) {
|
export function round3Digits(n) {
|
||||||
return Math_floor(n * 1000.0) / 1000.0;
|
return Math.floor(n * 1000.0) / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -616,7 +601,7 @@ export function round3Digits(n) {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
export function round4Digits(n) {
|
export function round4Digits(n) {
|
||||||
return Math_floor(n * 10000.0) / 10000.0;
|
return Math.floor(n * 10000.0) / 10000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -626,7 +611,7 @@ export function round4Digits(n) {
|
|||||||
* @param {number=} maximum Default 1
|
* @param {number=} maximum Default 1
|
||||||
*/
|
*/
|
||||||
export function clamp(v, minimum = 0, maximum = 1) {
|
export function clamp(v, minimum = 0, maximum = 1) {
|
||||||
return Math_max(minimum, Math_min(maximum, v));
|
return Math.max(minimum, Math.min(maximum, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -635,11 +620,11 @@ export function clamp(v, minimum = 0, maximum = 1) {
|
|||||||
* @param {function():void} target
|
* @param {function():void} target
|
||||||
*/
|
*/
|
||||||
export function measure(name, target) {
|
export function measure(name, target) {
|
||||||
const now = performanceNow();
|
const now = performance.now();
|
||||||
for (let i = 0; i < 25; ++i) {
|
for (let i = 0; i < 25; ++i) {
|
||||||
target();
|
target();
|
||||||
}
|
}
|
||||||
const dur = (performanceNow() - now) / 25.0;
|
const dur = (performance.now() - now) / 25.0;
|
||||||
console.warn("->", name, "took", dur.toFixed(2), "ms");
|
console.warn("->", name, "took", dur.toFixed(2), "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -889,10 +874,10 @@ export function fastRotateMultipleOf90(x, y, deg) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function formatSecondsToTimeAgo(secs) {
|
export function formatSecondsToTimeAgo(secs) {
|
||||||
const seconds = Math_floor(secs);
|
const seconds = Math.floor(secs);
|
||||||
const minutes = Math_floor(seconds / 60);
|
const minutes = Math.floor(seconds / 60);
|
||||||
const hours = Math_floor(minutes / 60);
|
const hours = Math.floor(minutes / 60);
|
||||||
const days = Math_floor(hours / 24);
|
const days = Math.floor(hours / 24);
|
||||||
|
|
||||||
if (seconds <= 60) {
|
if (seconds <= 60) {
|
||||||
if (seconds <= 1) {
|
if (seconds <= 1) {
|
||||||
@ -924,18 +909,18 @@ export function formatSecondsToTimeAgo(secs) {
|
|||||||
*/
|
*/
|
||||||
export function formatSeconds(secs) {
|
export function formatSeconds(secs) {
|
||||||
const trans = T.global.time;
|
const trans = T.global.time;
|
||||||
secs = Math_ceil(secs);
|
secs = Math.ceil(secs);
|
||||||
if (secs < 60) {
|
if (secs < 60) {
|
||||||
return trans.secondsShort.replace("<seconds>", "" + secs);
|
return trans.secondsShort.replace("<seconds>", "" + secs);
|
||||||
} else if (secs < 60 * 60) {
|
} else if (secs < 60 * 60) {
|
||||||
const minutes = Math_floor(secs / 60);
|
const minutes = Math.floor(secs / 60);
|
||||||
const seconds = secs % 60;
|
const seconds = secs % 60;
|
||||||
return trans.minutesAndSecondsShort
|
return trans.minutesAndSecondsShort
|
||||||
.replace("<seconds>", "" + seconds)
|
.replace("<seconds>", "" + seconds)
|
||||||
.replace("<minutes>", "" + minutes);
|
.replace("<minutes>", "" + minutes);
|
||||||
} else {
|
} else {
|
||||||
const hours = Math_floor(secs / 3600);
|
const hours = Math.floor(secs / 3600);
|
||||||
const minutes = Math_floor(secs / 60) % 60;
|
const minutes = Math.floor(secs / 60) % 60;
|
||||||
return trans.hoursAndMinutesShort.replace("<minutes>", "" + minutes).replace("<hours>", "" + hours);
|
return trans.hoursAndMinutesShort.replace("<minutes>", "" + minutes).replace("<hours>", "" + hours);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
import { globalConfig } from "./config";
|
import { globalConfig } from "./config";
|
||||||
import {
|
|
||||||
Math_abs,
|
|
||||||
Math_floor,
|
|
||||||
Math_PI,
|
|
||||||
Math_max,
|
|
||||||
Math_min,
|
|
||||||
Math_round,
|
|
||||||
Math_hypot,
|
|
||||||
Math_atan2,
|
|
||||||
Math_sin,
|
|
||||||
Math_cos,
|
|
||||||
Math_ceil,
|
|
||||||
} from "./builtins";
|
|
||||||
|
|
||||||
const tileSize = globalConfig.tileSize;
|
const tileSize = globalConfig.tileSize;
|
||||||
const halfTileSize = globalConfig.halfTileSize;
|
const halfTileSize = globalConfig.halfTileSize;
|
||||||
@ -158,7 +145,7 @@ export class Vector {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
length() {
|
length() {
|
||||||
return Math_hypot(this.x, this.y);
|
return Math.hypot(this.x, this.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -226,7 +213,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
maxScalar(f) {
|
maxScalar(f) {
|
||||||
return new Vector(Math_max(f, this.x), Math_max(f, this.y));
|
return new Vector(Math.max(f, this.x), Math.max(f, this.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,7 +231,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
min(v) {
|
min(v) {
|
||||||
return new Vector(Math_min(v.x, this.x), Math_min(v.y, this.y));
|
return new Vector(Math.min(v.x, this.x), Math.min(v.y, this.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -253,14 +240,14 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
max(v) {
|
max(v) {
|
||||||
return new Vector(Math_max(v.x, this.x), Math_max(v.y, this.y));
|
return new Vector(Math.max(v.x, this.x), Math.max(v.y, this.y));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Computes the component wise absolute
|
* Computes the component wise absolute
|
||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
abs() {
|
abs() {
|
||||||
return new Vector(Math_abs(this.x), Math_abs(this.y));
|
return new Vector(Math.abs(this.x), Math.abs(this.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,7 +265,7 @@ export class Vector {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
distance(v) {
|
distance(v) {
|
||||||
return Math_hypot(this.x - v.x, this.y - v.y);
|
return Math.hypot(this.x - v.x, this.y - v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -308,7 +295,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
floor() {
|
floor() {
|
||||||
return new Vector(Math_floor(this.x), Math_floor(this.y));
|
return new Vector(Math.floor(this.x), Math.floor(this.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -316,7 +303,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
ceil() {
|
ceil() {
|
||||||
return new Vector(Math_ceil(this.x), Math_ceil(this.y));
|
return new Vector(Math.ceil(this.x), Math.ceil(this.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,7 +311,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
round() {
|
round() {
|
||||||
return new Vector(Math_round(this.x), Math_round(this.y));
|
return new Vector(Math.round(this.x), Math.round(this.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -332,7 +319,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
toTileSpace() {
|
toTileSpace() {
|
||||||
return new Vector(Math_floor(this.x / tileSize), Math_floor(this.y / tileSize));
|
return new Vector(Math.floor(this.x / tileSize), Math.floor(this.y / tileSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -340,7 +327,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
toStreetSpace() {
|
toStreetSpace() {
|
||||||
return new Vector(Math_floor(this.x / halfTileSize + 0.25), Math_floor(this.y / halfTileSize + 0.25));
|
return new Vector(Math.floor(this.x / halfTileSize + 0.25), Math.floor(this.y / halfTileSize + 0.25));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -364,7 +351,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
snapWorldToTile() {
|
snapWorldToTile() {
|
||||||
return new Vector(Math_floor(this.x / tileSize) * tileSize, Math_floor(this.y / tileSize) * tileSize);
|
return new Vector(Math.floor(this.x / tileSize) * tileSize, Math.floor(this.y / tileSize) * tileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -372,7 +359,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
normalize() {
|
normalize() {
|
||||||
const len = Math_max(1e-5, Math_hypot(this.x, this.y));
|
const len = Math.max(1e-5, Math.hypot(this.x, this.y));
|
||||||
return new Vector(this.x / len, this.y / len);
|
return new Vector(this.x / len, this.y / len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +368,7 @@ export class Vector {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
normalizeIfGreaterOne() {
|
normalizeIfGreaterOne() {
|
||||||
const len = Math_max(1, Math_hypot(this.x, this.y));
|
const len = Math.max(1, Math.hypot(this.x, this.y));
|
||||||
return new Vector(this.x / len, this.y / len);
|
return new Vector(this.x / len, this.y / len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +380,7 @@ export class Vector {
|
|||||||
normalizedDirection(v) {
|
normalizedDirection(v) {
|
||||||
const dx = v.x - this.x;
|
const dx = v.x - this.x;
|
||||||
const dy = v.y - this.y;
|
const dy = v.y - this.y;
|
||||||
const len = Math_max(1e-5, Math_hypot(dx, dy));
|
const len = Math.max(1e-5, Math.hypot(dx, dy));
|
||||||
return new Vector(dx / len, dy / len);
|
return new Vector(dx / len, dy / len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,8 +424,8 @@ export class Vector {
|
|||||||
* @returns {Vector} new vector
|
* @returns {Vector} new vector
|
||||||
*/
|
*/
|
||||||
rotated(angle) {
|
rotated(angle) {
|
||||||
const sin = Math_sin(angle);
|
const sin = Math.sin(angle);
|
||||||
const cos = Math_cos(angle);
|
const cos = Math.cos(angle);
|
||||||
return new Vector(this.x * cos - this.y * sin, this.x * sin + this.y * cos);
|
return new Vector(this.x * cos - this.y * sin, this.x * sin + this.y * cos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,8 +435,8 @@ export class Vector {
|
|||||||
* @returns {Vector} this vector
|
* @returns {Vector} this vector
|
||||||
*/
|
*/
|
||||||
rotateInplaceFastMultipleOf90(angle) {
|
rotateInplaceFastMultipleOf90(angle) {
|
||||||
// const sin = Math_sin(angle);
|
// const sin = Math.sin(angle);
|
||||||
// const cos = Math_cos(angle);
|
// const cos = Math.cos(angle);
|
||||||
// let sin = 0, cos = 1;
|
// let sin = 0, cos = 1;
|
||||||
assert(angle >= 0 && angle <= 360, "Invalid angle, please clamp first: " + angle);
|
assert(angle >= 0 && angle <= 360, "Invalid angle, please clamp first: " + angle);
|
||||||
|
|
||||||
@ -598,7 +585,7 @@ export class Vector {
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
equalsEpsilon(v, epsilon = 1e-5) {
|
equalsEpsilon(v, epsilon = 1e-5) {
|
||||||
return Math_abs(this.x - v.x) < 1e-5 && Math_abs(this.y - v.y) < epsilon;
|
return Math.abs(this.x - v.x) < 1e-5 && Math.abs(this.y - v.y) < epsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -606,7 +593,7 @@ export class Vector {
|
|||||||
* @returns {number} 0 .. 2 PI
|
* @returns {number} 0 .. 2 PI
|
||||||
*/
|
*/
|
||||||
angle() {
|
angle() {
|
||||||
return Math_atan2(this.y, this.x) + Math_PI / 2;
|
return Math.atan2(this.y, this.x) + Math.PI / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -638,7 +625,7 @@ export class Vector {
|
|||||||
*/
|
*/
|
||||||
static deserializeTileFromInt(i) {
|
static deserializeTileFromInt(i) {
|
||||||
const x = i % 256;
|
const x = i % 256;
|
||||||
const y = Math_floor(i / 256);
|
const y = Math.floor(i / 256);
|
||||||
return new Vector(x, y);
|
return new Vector(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { globalConfig, IS_DEBUG } from "../core/config";
|
import { globalConfig, IS_DEBUG } from "../core/config";
|
||||||
import { Math_max } from "../core/builtins";
|
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
|
|
||||||
// How important it is that a savegame is created
|
// How important it is that a savegame is created
|
||||||
@ -29,7 +28,7 @@ export class AutomaticSave {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setSaveImportance(importance) {
|
setSaveImportance(importance) {
|
||||||
this.saveImportance = Math_max(this.saveImportance, importance);
|
this.saveImportance = Math.max(this.saveImportance, importance);
|
||||||
}
|
}
|
||||||
|
|
||||||
doSave() {
|
doSave() {
|
||||||
@ -54,7 +53,7 @@ export class AutomaticSave {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check when the last save was, but make sure that if it fails, we don't spam
|
// Check when the last save was, but make sure that if it fails, we don't spam
|
||||||
const lastSaveTime = Math_max(this.lastSaveAttempt, this.root.savegame.getRealLastUpdate());
|
const lastSaveTime = Math.max(this.lastSaveAttempt, this.root.savegame.getRealLastUpdate());
|
||||||
|
|
||||||
const secondsSinceLastSave = (Date.now() - lastSaveTime) / 1000.0;
|
const secondsSinceLastSave = (Date.now() - lastSaveTime) / 1000.0;
|
||||||
let shouldSave = false;
|
let shouldSave = false;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_min, Math_max } from "../core/builtins";
|
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
@ -538,7 +537,7 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
} else {
|
} else {
|
||||||
// Seems this item is on the first path (so all good), so just make sure it doesn't
|
// Seems this item is on the first path (so all good), so just make sure it doesn't
|
||||||
// have a nextDistance which is bigger than the total path length
|
// have a nextDistance which is bigger than the total path length
|
||||||
const clampedDistanceToNext = Math_min(itemPos + distanceToNext, firstPathLength) - itemPos;
|
const clampedDistanceToNext = Math.min(itemPos + distanceToNext, firstPathLength) - itemPos;
|
||||||
if (clampedDistanceToNext < distanceToNext) {
|
if (clampedDistanceToNext < distanceToNext) {
|
||||||
DEBUG &&
|
DEBUG &&
|
||||||
logger.log(
|
logger.log(
|
||||||
@ -938,9 +937,9 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
const nextDistanceAndItem = this.items[i];
|
const nextDistanceAndItem = this.items[i];
|
||||||
const minimumSpacing = minimumDistance;
|
const minimumSpacing = minimumDistance;
|
||||||
|
|
||||||
const takeAway = Math_max(
|
const takeAway = Math.max(
|
||||||
0,
|
0,
|
||||||
Math_min(remainingAmount, nextDistanceAndItem[_nextDistance] - minimumSpacing)
|
Math.min(remainingAmount, nextDistanceAndItem[_nextDistance] - minimumSpacing)
|
||||||
);
|
);
|
||||||
|
|
||||||
remainingAmount -= takeAway;
|
remainingAmount -= takeAway;
|
||||||
@ -984,7 +983,7 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
|
|
||||||
if (currentLength + localLength >= progress || i === this.entityPath.length - 1) {
|
if (currentLength + localLength >= progress || i === this.entityPath.length - 1) {
|
||||||
// Min required here due to floating point issues
|
// Min required here due to floating point issues
|
||||||
const localProgress = Math_min(1.0, progress - currentLength);
|
const localProgress = Math.min(1.0, progress - currentLength);
|
||||||
|
|
||||||
assert(localProgress >= 0.0, "Invalid local progress: " + localProgress);
|
assert(localProgress >= 0.0, "Invalid local progress: " + localProgress);
|
||||||
const localSpace = beltComp.transformBeltToLocalSpace(localProgress);
|
const localSpace = beltComp.transformBeltToLocalSpace(localProgress);
|
||||||
|
@ -5,7 +5,6 @@ import { Vector } from "../core/vector";
|
|||||||
import { Entity } from "./entity";
|
import { Entity } from "./entity";
|
||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { findNiceIntegerValue } from "../core/utils";
|
import { findNiceIntegerValue } from "../core/utils";
|
||||||
import { Math_pow } from "../core/builtins";
|
|
||||||
import { blueprintShape } from "./upgrades";
|
import { blueprintShape } from "./upgrades";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ export class Blueprint {
|
|||||||
if (G_IS_DEV && globalConfig.debug.blueprintsNoCost) {
|
if (G_IS_DEV && globalConfig.debug.blueprintsNoCost) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return findNiceIntegerValue(4 * Math_pow(this.entities.length, 1.1));
|
return findNiceIntegerValue(4 * Math.pow(this.entities.length, 1.1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
import {
|
|
||||||
Math_abs,
|
|
||||||
Math_ceil,
|
|
||||||
Math_floor,
|
|
||||||
Math_max,
|
|
||||||
Math_min,
|
|
||||||
Math_random,
|
|
||||||
performanceNow,
|
|
||||||
} from "../core/builtins";
|
|
||||||
import { clickDetectorGlobals } from "../core/click_detector";
|
import { clickDetectorGlobals } from "../core/click_detector";
|
||||||
import { globalConfig, SUPPORT_TOUCH } from "../core/config";
|
import { globalConfig, SUPPORT_TOUCH } from "../core/config";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
@ -137,8 +128,8 @@ export class Camera extends BasicSerializableObject {
|
|||||||
addScreenShake(amount) {
|
addScreenShake(amount) {
|
||||||
const currentShakeAmount = this.currentShake.length();
|
const currentShakeAmount = this.currentShake.length();
|
||||||
const scale = 1 / (1 + 3 * currentShakeAmount);
|
const scale = 1 / (1 + 3 * currentShakeAmount);
|
||||||
this.currentShake.x = this.currentShake.x + 2 * (Math_random() - 0.5) * scale * amount;
|
this.currentShake.x = this.currentShake.x + 2 * (Math.random() - 0.5) * scale * amount;
|
||||||
this.currentShake.y = this.currentShake.y + 2 * (Math_random() - 0.5) * scale * amount;
|
this.currentShake.y = this.currentShake.y + 2 * (Math.random() - 0.5) * scale * amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,7 +172,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
const zoomLevelX = this.root.gameWidth / desiredWorldSpaceWidth;
|
const zoomLevelX = this.root.gameWidth / desiredWorldSpaceWidth;
|
||||||
const zoomLevelY = this.root.gameHeight / desiredWorldSpaceWidth;
|
const zoomLevelY = this.root.gameHeight / desiredWorldSpaceWidth;
|
||||||
|
|
||||||
const finalLevel = Math_min(zoomLevelX, zoomLevelY);
|
const finalLevel = Math.min(zoomLevelX, zoomLevelY);
|
||||||
assert(
|
assert(
|
||||||
Number.isFinite(finalLevel) && finalLevel > 0,
|
Number.isFinite(finalLevel) && finalLevel > 0,
|
||||||
"Invalid zoom level computed for initial zoom: " + finalLevel
|
"Invalid zoom level computed for initial zoom: " + finalLevel
|
||||||
@ -292,10 +283,10 @@ export class Camera extends BasicSerializableObject {
|
|||||||
*/
|
*/
|
||||||
getVisibleRect() {
|
getVisibleRect() {
|
||||||
return Rectangle.fromTRBL(
|
return Rectangle.fromTRBL(
|
||||||
Math_floor(this.getViewportTop()),
|
Math.floor(this.getViewportTop()),
|
||||||
Math_ceil(this.getViewportRight()),
|
Math.ceil(this.getViewportRight()),
|
||||||
Math_ceil(this.getViewportBottom()),
|
Math.ceil(this.getViewportBottom()),
|
||||||
Math_floor(this.getViewportLeft())
|
Math.floor(this.getViewportLeft())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,7 +417,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
* should get ignored
|
* should get ignored
|
||||||
*/
|
*/
|
||||||
checkPreventDoubleMouse() {
|
checkPreventDoubleMouse() {
|
||||||
if (performanceNow() - clickDetectorGlobals.lastTouchTime < 1000.0) {
|
if (performance.now() - clickDetectorGlobals.lastTouchTime < 1000.0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -531,7 +522,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
// event.stopPropagation();
|
// event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
clickDetectorGlobals.lastTouchTime = performanceNow();
|
clickDetectorGlobals.lastTouchTime = performance.now();
|
||||||
this.touchPostMoveVelocity = new Vector(0, 0);
|
this.touchPostMoveVelocity = new Vector(0, 0);
|
||||||
|
|
||||||
if (event.touches.length === 1) {
|
if (event.touches.length === 1) {
|
||||||
@ -565,7 +556,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
// event.stopPropagation();
|
// event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
clickDetectorGlobals.lastTouchTime = performanceNow();
|
clickDetectorGlobals.lastTouchTime = performance.now();
|
||||||
|
|
||||||
if (event.touches.length === 1) {
|
if (event.touches.length === 1) {
|
||||||
const touch = event.touches[0];
|
const touch = event.touches[0];
|
||||||
@ -585,7 +576,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
const thisDistance = newPinchPositions[0].distance(newPinchPositions[1]);
|
const thisDistance = newPinchPositions[0].distance(newPinchPositions[1]);
|
||||||
|
|
||||||
// IMPORTANT to do math max here to avoid NaN and causing an invalid zoom level
|
// IMPORTANT to do math max here to avoid NaN and causing an invalid zoom level
|
||||||
const difference = thisDistance / Math_max(0.001, lastDistance);
|
const difference = thisDistance / Math.max(0.001, lastDistance);
|
||||||
|
|
||||||
// Find old center of zoom
|
// Find old center of zoom
|
||||||
let oldCenter = this.lastPinchPositions[0].centerPoint(this.lastPinchPositions[1]);
|
let oldCenter = this.lastPinchPositions[0].centerPoint(this.lastPinchPositions[1]);
|
||||||
@ -645,7 +636,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clickDetectorGlobals.lastTouchTime = performanceNow();
|
clickDetectorGlobals.lastTouchTime = performance.now();
|
||||||
if (event.changedTouches.length === 0) {
|
if (event.changedTouches.length === 0) {
|
||||||
logger.warn("Touch end without changed touches");
|
logger.warn("Touch end without changed touches");
|
||||||
}
|
}
|
||||||
@ -753,7 +744,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
* @param {number} dt Delta time in milliseconds
|
* @param {number} dt Delta time in milliseconds
|
||||||
*/
|
*/
|
||||||
update(dt) {
|
update(dt) {
|
||||||
dt = Math_min(dt, 33);
|
dt = Math.min(dt, 33);
|
||||||
this.cameraUpdateTimeBucket += dt;
|
this.cameraUpdateTimeBucket += dt;
|
||||||
|
|
||||||
// Simulate movement of N FPS
|
// Simulate movement of N FPS
|
||||||
@ -861,7 +852,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
internalUpdateZooming(now, dt) {
|
internalUpdateZooming(now, dt) {
|
||||||
if (!this.currentlyPinching && this.desiredZoom !== null) {
|
if (!this.currentlyPinching && this.desiredZoom !== null) {
|
||||||
const diff = this.zoomLevel - this.desiredZoom;
|
const diff = this.zoomLevel - this.desiredZoom;
|
||||||
if (Math_abs(diff) > 0.0001) {
|
if (Math.abs(diff) > 0.0001) {
|
||||||
let fade = 0.94;
|
let fade = 0.94;
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
// Zoom out faster than in
|
// Zoom out faster than in
|
||||||
@ -889,7 +880,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
const length = diff.length();
|
const length = diff.length();
|
||||||
const tolerance = 1 / this.zoomLevel;
|
const tolerance = 1 / this.zoomLevel;
|
||||||
if (length > tolerance) {
|
if (length > tolerance) {
|
||||||
const movement = diff.multiplyScalar(Math_min(1, dt * 0.008));
|
const movement = diff.multiplyScalar(Math.min(1, dt * 0.008));
|
||||||
this.center.x += movement.x;
|
this.center.x += movement.x;
|
||||||
this.center.y += movement.y;
|
this.center.y += movement.y;
|
||||||
} else {
|
} else {
|
||||||
@ -905,7 +896,7 @@ export class Camera extends BasicSerializableObject {
|
|||||||
*/
|
*/
|
||||||
internalUpdateKeyboardForce(now, dt) {
|
internalUpdateKeyboardForce(now, dt) {
|
||||||
if (!this.currentlyMoving && this.desiredCenter == null) {
|
if (!this.currentlyMoving && this.desiredCenter == null) {
|
||||||
const limitingDimension = Math_min(this.root.gameWidth, this.root.gameHeight);
|
const limitingDimension = Math.min(this.root.gameWidth, this.root.gameHeight);
|
||||||
|
|
||||||
const moveAmount = ((limitingDimension / 2048) * dt) / this.zoomLevel;
|
const moveAmount = ((limitingDimension / 2048) * dt) / this.zoomLevel;
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { Math_cos, Math_PI, Math_sin } from "../../core/builtins";
|
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { enumDirection, Vector } from "../../core/vector";
|
||||||
import { types } from "../../savegame/serialization";
|
import { types } from "../../savegame/serialization";
|
||||||
import { BeltPath } from "../belt_path";
|
import { BeltPath } from "../belt_path";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
|
|
||||||
export const curvedBeltLength = /* Math_PI / 4 */ 0.78;
|
export const curvedBeltLength = /* Math.PI / 4 */ 0.78;
|
||||||
|
|
||||||
export class BeltComponent extends Component {
|
export class BeltComponent extends Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
@ -65,13 +64,13 @@ export class BeltComponent extends Component {
|
|||||||
|
|
||||||
case enumDirection.right: {
|
case enumDirection.right: {
|
||||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 2: " + progress);
|
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 2: " + progress);
|
||||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math_PI;
|
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));
|
return new Vector(0.5 - 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
||||||
}
|
}
|
||||||
case enumDirection.left: {
|
case enumDirection.left: {
|
||||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 3: " + progress);
|
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 3: " + progress);
|
||||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math_PI;
|
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));
|
return new Vector(-0.5 + 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assertAlways(false, "Invalid belt direction: " + this.direction);
|
assertAlways(false, "Invalid belt direction: " + this.direction);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_radians } from "../../core/builtins";
|
|
||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { DrawParameters } from "../../core/draw_parameters";
|
import { DrawParameters } from "../../core/draw_parameters";
|
||||||
import { Rectangle } from "../../core/rectangle";
|
import { Rectangle } from "../../core/rectangle";
|
||||||
@ -253,7 +252,7 @@ export class StaticMapEntityComponent extends Component {
|
|||||||
const rotationCenterY = worldY + globalConfig.halfTileSize;
|
const rotationCenterY = worldY + globalConfig.halfTileSize;
|
||||||
|
|
||||||
parameters.context.translate(rotationCenterX, rotationCenterY);
|
parameters.context.translate(rotationCenterX, rotationCenterY);
|
||||||
parameters.context.rotate(Math_radians(this.rotation));
|
parameters.context.rotate(Math.radians(this.rotation));
|
||||||
|
|
||||||
sprite.drawCached(
|
sprite.drawCached(
|
||||||
parameters,
|
parameters,
|
||||||
@ -264,7 +263,7 @@ export class StaticMapEntityComponent extends Component {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
parameters.context.rotate(-Math_radians(this.rotation));
|
parameters.context.rotate(-Math.radians(this.rotation));
|
||||||
parameters.context.translate(-rotationCenterX, -rotationCenterY);
|
parameters.context.translate(-rotationCenterX, -rotationCenterY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import { Application } from "../application";
|
|||||||
|
|
||||||
import { BufferMaintainer } from "../core/buffer_maintainer";
|
import { BufferMaintainer } from "../core/buffer_maintainer";
|
||||||
import { disableImageSmoothing, enableImageSmoothing, registerCanvas } from "../core/buffer_utils";
|
import { disableImageSmoothing, enableImageSmoothing, registerCanvas } from "../core/buffer_utils";
|
||||||
import { Math_random } from "../core/builtins";
|
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { getDeviceDPI, resizeHighDPICanvas } from "../core/dpi_manager";
|
import { getDeviceDPI, resizeHighDPICanvas } from "../core/dpi_manager";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
@ -443,7 +442,7 @@ export class GameCore {
|
|||||||
for (let i = 0; i < 1e8; ++i) {
|
for (let i = 0; i < 1e8; ++i) {
|
||||||
sum += i;
|
sum += i;
|
||||||
}
|
}
|
||||||
if (Math_random() > 0.95) {
|
if (Math.random() > 0.95) {
|
||||||
console.log(sum);
|
console.log(sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { performanceNow, Math_min, Math_round, Math_max } from "../core/builtins";
|
|
||||||
import { round3Digits } from "../core/utils";
|
import { round3Digits } from "../core/utils";
|
||||||
|
|
||||||
const logger = createLogger("dynamic_tickrate");
|
const logger = createLogger("dynamic_tickrate");
|
||||||
@ -35,7 +34,7 @@ export class DynamicTickrate {
|
|||||||
onFrameRendered() {
|
onFrameRendered() {
|
||||||
++this.accumulatedFps;
|
++this.accumulatedFps;
|
||||||
|
|
||||||
const now = performanceNow();
|
const now = performance.now();
|
||||||
const timeDuration = now - this.accumulatedFpsLastUpdate;
|
const timeDuration = now - this.accumulatedFpsLastUpdate;
|
||||||
if (timeDuration > fpsAccumulationTime) {
|
if (timeDuration > fpsAccumulationTime) {
|
||||||
const avgFps = (this.accumulatedFps / fpsAccumulationTime) * 1000;
|
const avgFps = (this.accumulatedFps / fpsAccumulationTime) * 1000;
|
||||||
@ -65,7 +64,7 @@ export class DynamicTickrate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const desiredFps = this.root.app.settings.getDesiredFps();
|
const desiredFps = this.root.app.settings.getDesiredFps();
|
||||||
this.setTickRate(Math_round(Math_min(desiredFps, this.currentTickRate * 1.2)));
|
this.setTickRate(Math.round(Math.min(desiredFps, this.currentTickRate * 1.2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +76,7 @@ export class DynamicTickrate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const desiredFps = this.root.app.settings.getDesiredFps();
|
const desiredFps = this.root.app.settings.getDesiredFps();
|
||||||
this.setTickRate(Math_round(Math_max(desiredFps / 2, this.currentTickRate * 0.8)));
|
this.setTickRate(Math.round(Math.max(desiredFps / 2, this.currentTickRate * 0.8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,7 +84,7 @@ export class DynamicTickrate {
|
|||||||
*/
|
*/
|
||||||
beginTick() {
|
beginTick() {
|
||||||
assert(this.currentTickStart === null, "BeginTick called twice");
|
assert(this.currentTickStart === null, "BeginTick called twice");
|
||||||
this.currentTickStart = performanceNow();
|
this.currentTickStart = performance.now();
|
||||||
|
|
||||||
if (this.capturedTicks.length > this.currentTickRate * 2) {
|
if (this.capturedTicks.length > this.currentTickRate * 2) {
|
||||||
// Take only a portion of the ticks
|
// Take only a portion of the ticks
|
||||||
@ -119,7 +118,7 @@ export class DynamicTickrate {
|
|||||||
*/
|
*/
|
||||||
endTick() {
|
endTick() {
|
||||||
assert(this.currentTickStart !== null, "EndTick called without BeginTick");
|
assert(this.currentTickStart !== null, "EndTick called without BeginTick");
|
||||||
const duration = performanceNow() - this.currentTickStart;
|
const duration = performance.now() - this.currentTickStart;
|
||||||
this.capturedTicks.push(duration);
|
this.capturedTicks.push(duration);
|
||||||
this.currentTickStart = null;
|
this.currentTickStart = null;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import { BasicSerializableObject, types } from "../savegame/serialization";
|
|||||||
import { EntityComponentStorage } from "./entity_components";
|
import { EntityComponentStorage } from "./entity_components";
|
||||||
import { Loader } from "../core/loader";
|
import { Loader } from "../core/loader";
|
||||||
import { drawRotatedSprite } from "../core/draw_utils";
|
import { drawRotatedSprite } from "../core/draw_utils";
|
||||||
import { Math_radians } from "../core/builtins";
|
|
||||||
import { gComponentRegistry } from "../core/global_registries";
|
import { gComponentRegistry } from "../core/global_registries";
|
||||||
|
|
||||||
export class Entity extends BasicSerializableObject {
|
export class Entity extends BasicSerializableObject {
|
||||||
@ -166,7 +165,7 @@ export class Entity extends BasicSerializableObject {
|
|||||||
const slotTile = staticComp.localTileToWorld(slot.pos);
|
const slotTile = staticComp.localTileToWorld(slot.pos);
|
||||||
const direction = staticComp.localDirectionToWorld(slot.direction);
|
const direction = staticComp.localDirectionToWorld(slot.direction);
|
||||||
const directionVector = enumDirectionToVector[direction];
|
const directionVector = enumDirectionToVector[direction];
|
||||||
const angle = Math_radians(enumDirectionToAngle[direction]);
|
const angle = Math.radians(enumDirectionToAngle[direction]);
|
||||||
|
|
||||||
context.globalAlpha = slot.item ? 1 : 0.2;
|
context.globalAlpha = slot.item ? 1 : 0.2;
|
||||||
drawRotatedSprite({
|
drawRotatedSprite({
|
||||||
@ -189,7 +188,7 @@ export class Entity extends BasicSerializableObject {
|
|||||||
for (let k = 0; k < slot.directions.length; ++k) {
|
for (let k = 0; k < slot.directions.length; ++k) {
|
||||||
const direction = staticComp.localDirectionToWorld(slot.directions[k]);
|
const direction = staticComp.localDirectionToWorld(slot.directions[k]);
|
||||||
const directionVector = enumDirectionToVector[direction];
|
const directionVector = enumDirectionToVector[direction];
|
||||||
const angle = Math_radians(enumDirectionToAngle[direction] + 180);
|
const angle = Math.radians(enumDirectionToAngle[direction] + 180);
|
||||||
context.globalAlpha = 0.4;
|
context.globalAlpha = 0.4;
|
||||||
drawRotatedSprite({
|
drawRotatedSprite({
|
||||||
parameters,
|
parameters,
|
||||||
|
@ -8,8 +8,6 @@ import { GameSystem } from "./game_system";
|
|||||||
import { arrayDelete, arrayDeleteValue } from "../core/utils";
|
import { arrayDelete, arrayDeleteValue } from "../core/utils";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { Math_floor, Math_ceil } from "../core/builtins";
|
|
||||||
|
|
||||||
export class GameSystemWithFilter extends GameSystem {
|
export class GameSystemWithFilter extends GameSystem {
|
||||||
/**
|
/**
|
||||||
* Constructs a new game system with the given component filter. It will process
|
* Constructs a new game system with the given component filter. It will process
|
||||||
@ -71,11 +69,11 @@ export class GameSystemWithFilter extends GameSystem {
|
|||||||
|
|
||||||
let seenUids = new Set();
|
let seenUids = new Set();
|
||||||
|
|
||||||
const chunkStartX = Math_floor(minX / globalConfig.mapChunkSize);
|
const chunkStartX = Math.floor(minX / globalConfig.mapChunkSize);
|
||||||
const chunkStartY = Math_floor(minY / globalConfig.mapChunkSize);
|
const chunkStartY = Math.floor(minY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
const chunkEndX = Math_ceil(maxX / globalConfig.mapChunkSize);
|
const chunkEndX = Math.ceil(maxX / globalConfig.mapChunkSize);
|
||||||
const chunkEndY = Math_ceil(maxY / globalConfig.mapChunkSize);
|
const chunkEndY = Math.ceil(maxY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
const requiredComponents = this.requiredComponentIds;
|
const requiredComponents = this.requiredComponentIds;
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_random } from "../core/builtins";
|
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { queryParamOptions } from "../core/query_parameters";
|
import { queryParamOptions } from "../core/query_parameters";
|
||||||
import { clamp, findNiceIntegerValue, randomChoice, randomInt } from "../core/utils";
|
import { clamp, findNiceIntegerValue, randomChoice, randomInt } from "../core/utils";
|
||||||
@ -336,14 +335,14 @@ export class HubGoals extends BasicSerializableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sometimes shapes are missing
|
// Sometimes shapes are missing
|
||||||
if (Math_random() > 0.85) {
|
if (Math.random() > 0.85) {
|
||||||
layer[randomInt(0, 3)] = null;
|
layer[randomInt(0, 3)] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sometimes they actually are missing *two* ones!
|
// Sometimes they actually are missing *two* ones!
|
||||||
// Make sure at max only one layer is missing it though, otherwise we could
|
// Make sure at max only one layer is missing it though, otherwise we could
|
||||||
// create an uncreateable shape
|
// create an uncreateable shape
|
||||||
if (Math_random() > 0.95 && !anyIsMissingTwo) {
|
if (Math.random() > 0.95 && !anyIsMissingTwo) {
|
||||||
layer[randomInt(0, 3)] = null;
|
layer[randomInt(0, 3)] = null;
|
||||||
anyIsMissingTwo = true;
|
anyIsMissingTwo = true;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_radians } from "../../../core/builtins";
|
|
||||||
import { globalConfig } from "../../../core/config";
|
import { globalConfig } from "../../../core/config";
|
||||||
import { DrawParameters } from "../../../core/draw_parameters";
|
import { DrawParameters } from "../../../core/draw_parameters";
|
||||||
import { drawRotatedSprite } from "../../../core/draw_utils";
|
import { drawRotatedSprite } from "../../../core/draw_utils";
|
||||||
@ -368,7 +367,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
sprite: this.lockIndicatorSprite,
|
sprite: this.lockIndicatorSprite,
|
||||||
x: worldPos.x,
|
x: worldPos.x,
|
||||||
y: worldPos.y,
|
y: worldPos.y,
|
||||||
angle: Math_radians(rotation),
|
angle: Math.radians(rotation),
|
||||||
size: 12,
|
size: 12,
|
||||||
offsetY:
|
offsetY:
|
||||||
-globalConfig.halfTileSize -
|
-globalConfig.halfTileSize -
|
||||||
@ -432,7 +431,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
sprite,
|
sprite,
|
||||||
x: acceptorSlotWsPos.x,
|
x: acceptorSlotWsPos.x,
|
||||||
y: acceptorSlotWsPos.y,
|
y: acceptorSlotWsPos.y,
|
||||||
angle: Math_radians(enumDirectionToAngle[enumInvertedDirections[worldDirection]]),
|
angle: Math.radians(enumDirectionToAngle[enumInvertedDirections[worldDirection]]),
|
||||||
size: 13,
|
size: 13,
|
||||||
offsetY: offsetShift + 13,
|
offsetY: offsetShift + 13,
|
||||||
});
|
});
|
||||||
@ -478,7 +477,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
sprite,
|
sprite,
|
||||||
x: ejectorSLotWsPos.x,
|
x: ejectorSLotWsPos.x,
|
||||||
y: ejectorSLotWsPos.y,
|
y: ejectorSLotWsPos.y,
|
||||||
angle: Math_radians(enumDirectionToAngle[ejectorSlotWsDirection]),
|
angle: Math.radians(enumDirectionToAngle[ejectorSlotWsDirection]),
|
||||||
size: 13,
|
size: 13,
|
||||||
offsetY: offsetShift,
|
offsetY: offsetShift,
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_abs, Math_degrees, Math_round } from "../../../core/builtins";
|
|
||||||
import { globalConfig } from "../../../core/config";
|
import { globalConfig } from "../../../core/config";
|
||||||
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
||||||
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
|
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
|
||||||
@ -565,10 +564,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
// Place from start to corner
|
// Place from start to corner
|
||||||
const pathToCorner = this.currentDirectionLockCorner.sub(startTile);
|
const pathToCorner = this.currentDirectionLockCorner.sub(startTile);
|
||||||
const deltaToCorner = pathToCorner.normalize().round();
|
const deltaToCorner = pathToCorner.normalize().round();
|
||||||
const lengthToCorner = Math_round(pathToCorner.length());
|
const lengthToCorner = Math.round(pathToCorner.length());
|
||||||
let currentPos = startTile.copy();
|
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) {
|
if (lengthToCorner > 0) {
|
||||||
for (let i = 0; i < lengthToCorner; ++i) {
|
for (let i = 0; i < lengthToCorner; ++i) {
|
||||||
@ -583,10 +582,10 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
// Place from corner to end
|
// Place from corner to end
|
||||||
const pathFromCorner = mouseTile.sub(this.currentDirectionLockCorner);
|
const pathFromCorner = mouseTile.sub(this.currentDirectionLockCorner);
|
||||||
const deltaFromCorner = pathFromCorner.normalize().round();
|
const deltaFromCorner = pathFromCorner.normalize().round();
|
||||||
const lengthFromCorner = Math_round(pathFromCorner.length());
|
const lengthFromCorner = Math.round(pathFromCorner.length());
|
||||||
|
|
||||||
if (lengthFromCorner > 0) {
|
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) {
|
for (let i = 0; i < lengthFromCorner + 1; ++i) {
|
||||||
result.push({
|
result.push({
|
||||||
tile: currentPos.copy(),
|
tile: currentPos.copy(),
|
||||||
@ -722,7 +721,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
).pressed
|
).pressed
|
||||||
) {
|
) {
|
||||||
const delta = newPos.sub(oldPos);
|
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;
|
this.currentBaseRotation = (Math.round(angleDeg / 90) * 90 + 360) % 360;
|
||||||
|
|
||||||
// Holding alt inverts the placement
|
// Holding alt inverts the placement
|
||||||
@ -737,8 +736,8 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
let x1 = newPos.x;
|
let x1 = newPos.x;
|
||||||
let y1 = newPos.y;
|
let y1 = newPos.y;
|
||||||
|
|
||||||
var dx = Math_abs(x1 - x0);
|
var dx = Math.abs(x1 - x0);
|
||||||
var dy = Math_abs(y1 - y0);
|
var dy = Math.abs(y1 - y0);
|
||||||
var sx = x0 < x1 ? 1 : -1;
|
var sx = x0 < x1 ? 1 : -1;
|
||||||
var sy = y0 < y1 ? 1 : -1;
|
var sy = y0 < y1 ? 1 : -1;
|
||||||
var err = dx - dy;
|
var err = dx - dy;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
import { makeDiv, round3Digits, round2Digits } from "../../../core/utils";
|
import { makeDiv, round3Digits, round2Digits } from "../../../core/utils";
|
||||||
import { Math_round } from "../../../core/builtins";
|
|
||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ export class HUDDebugInfo extends BaseHUDPart {
|
|||||||
this.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate;
|
this.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate;
|
||||||
this.fpsElement.innerText =
|
this.fpsElement.innerText =
|
||||||
"FPS: " +
|
"FPS: " +
|
||||||
Math_round(this.root.dynamicTickrate.averageFps) +
|
Math.round(this.root.dynamicTickrate.averageFps) +
|
||||||
" (" +
|
" (" +
|
||||||
round2Digits(1000 / this.root.dynamicTickrate.averageFps) +
|
round2Digits(1000 / this.root.dynamicTickrate.averageFps) +
|
||||||
" ms)";
|
" ms)";
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_max } from "../../../core/builtins";
|
|
||||||
import { ClickDetector } from "../../../core/click_detector";
|
import { ClickDetector } from "../../../core/click_detector";
|
||||||
import { formatBigNumber, makeDiv, arrayDelete, arrayDeleteValue } from "../../../core/utils";
|
import { formatBigNumber, makeDiv, arrayDelete, arrayDeleteValue } from "../../../core/utils";
|
||||||
import { ShapeDefinition } from "../../shape_definition";
|
import { ShapeDefinition } from "../../shape_definition";
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
import { performanceNow } from "../../../core/builtins";
|
|
||||||
import { makeDiv } from "../../../core/utils";
|
import { makeDiv } from "../../../core/utils";
|
||||||
import { Signal } from "../../../core/signal";
|
import { Signal } from "../../../core/signal";
|
||||||
import { InputReceiver } from "../../../core/input_receiver";
|
import { InputReceiver } from "../../../core/input_receiver";
|
||||||
@ -62,15 +61,15 @@ export class HUDProcessingOverlay extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processSync() {
|
processSync() {
|
||||||
const now = performanceNow();
|
const now = performance.now();
|
||||||
while (this.tasks.length > 0) {
|
while (this.tasks.length > 0) {
|
||||||
const workload = this.tasks[0];
|
const workload = this.tasks[0];
|
||||||
workload.call();
|
workload.call();
|
||||||
this.tasks.shift();
|
this.tasks.shift();
|
||||||
}
|
}
|
||||||
const duration = performanceNow() - now;
|
const duration = performance.now() - now;
|
||||||
if (duration > 100) {
|
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(() => {
|
this.computeTimeout = setTimeout(() => {
|
||||||
const now = performanceNow();
|
const now = performance.now();
|
||||||
while (this.tasks.length > 0) {
|
while (this.tasks.length > 0) {
|
||||||
const workload = this.tasks[0];
|
const workload = this.tasks[0];
|
||||||
workload.call();
|
workload.call();
|
||||||
this.tasks.shift();
|
this.tasks.shift();
|
||||||
}
|
}
|
||||||
const duration = performanceNow() - now;
|
const duration = performance.now() - now;
|
||||||
if (duration > 100) {
|
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);
|
this.domWatcher.update(false);
|
||||||
|
@ -5,7 +5,6 @@ import { T } from "../../../translations";
|
|||||||
import { createLogger } from "../../../core/logging";
|
import { createLogger } from "../../../core/logging";
|
||||||
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
||||||
import { Vector } from "../../../core/vector";
|
import { Vector } from "../../../core/vector";
|
||||||
import { Math_max, Math_min, Math_floor } from "../../../core/builtins";
|
|
||||||
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
||||||
import { DrawParameters } from "../../../core/draw_parameters";
|
import { DrawParameters } from "../../../core/draw_parameters";
|
||||||
import { Rectangle } from "../../../core/rectangle";
|
import { Rectangle } from "../../../core/rectangle";
|
||||||
@ -43,11 +42,11 @@ export class HUDScreenshotExporter extends BaseHUDPart {
|
|||||||
const maxTile = new Vector(0, 0);
|
const maxTile = new Vector(0, 0);
|
||||||
for (let i = 0; i < staticEntities.length; ++i) {
|
for (let i = 0; i < staticEntities.length; ++i) {
|
||||||
const bounds = staticEntities[i].components.StaticMapEntity.getTileSpaceBounds();
|
const bounds = staticEntities[i].components.StaticMapEntity.getTileSpaceBounds();
|
||||||
minTile.x = Math_min(minTile.x, bounds.x);
|
minTile.x = Math.min(minTile.x, bounds.x);
|
||||||
minTile.y = Math_min(minTile.y, bounds.y);
|
minTile.y = Math.min(minTile.y, bounds.y);
|
||||||
|
|
||||||
maxTile.x = Math_max(maxTile.x, bounds.x + bounds.w);
|
maxTile.x = Math.max(maxTile.x, bounds.x + bounds.w);
|
||||||
maxTile.y = Math_max(maxTile.y, bounds.y + bounds.h);
|
maxTile.y = Math.max(maxTile.y, bounds.y + bounds.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
const minChunk = minTile.divideScalar(globalConfig.mapChunkSize).floor();
|
const minChunk = minTile.divideScalar(globalConfig.mapChunkSize).floor();
|
||||||
@ -57,10 +56,10 @@ export class HUDScreenshotExporter extends BaseHUDPart {
|
|||||||
logger.log("Dimensions:", dimensions);
|
logger.log("Dimensions:", dimensions);
|
||||||
|
|
||||||
let chunkSizePixels = 128;
|
let chunkSizePixels = 128;
|
||||||
const maxDimensions = Math_max(dimensions.x, dimensions.y);
|
const maxDimensions = Math.max(dimensions.x, dimensions.y);
|
||||||
|
|
||||||
if (maxDimensions > 128) {
|
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);
|
logger.log("ChunkSizePixels:", chunkSizePixels);
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_min } from "../../../core/builtins";
|
|
||||||
import { ClickDetector } from "../../../core/click_detector";
|
import { ClickDetector } from "../../../core/click_detector";
|
||||||
import { InputReceiver } from "../../../core/input_receiver";
|
import { InputReceiver } from "../../../core/input_receiver";
|
||||||
import { formatBigNumber, makeDiv } from "../../../core/utils";
|
import { formatBigNumber, makeDiv } from "../../../core/utils";
|
||||||
@ -178,7 +177,7 @@ export class HUDShop extends BaseHUDPart {
|
|||||||
const { progressLabel, progressBar, definition, required } = handle.requireIndexToElement[i];
|
const { progressLabel, progressBar, definition, required } = handle.requireIndexToElement[i];
|
||||||
|
|
||||||
const haveAmount = this.root.hubGoals.getShapesStored(definition);
|
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);
|
progressLabel.innerText = formatBigNumber(haveAmount) + " / " + formatBigNumber(required);
|
||||||
progressBar.style.width = progress * 100.0 + "%";
|
progressBar.style.width = progress * 100.0 + "%";
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_min } from "../../../core/builtins";
|
|
||||||
import { InputReceiver } from "../../../core/input_receiver";
|
import { InputReceiver } from "../../../core/input_receiver";
|
||||||
import { makeButton, makeDiv, removeAllChildren, capitalizeFirstLetter } from "../../../core/utils";
|
import { makeButton, makeDiv, removeAllChildren, capitalizeFirstLetter } from "../../../core/utils";
|
||||||
import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper";
|
import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
@ -179,7 +178,7 @@ export class HUDStatistics extends BaseHUDPart {
|
|||||||
|
|
||||||
let rendered = new Set();
|
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 entry = entries[i];
|
||||||
const shapeKey = entry[0];
|
const shapeKey = entry[0];
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
|
||||||
import { Math_max, Math_PI, Math_radians } from "../../../core/builtins";
|
|
||||||
import { globalConfig, IS_DEMO } from "../../../core/config";
|
import { globalConfig, IS_DEMO } from "../../../core/config";
|
||||||
import { DrawParameters } from "../../../core/draw_parameters";
|
import { DrawParameters } from "../../../core/draw_parameters";
|
||||||
import { Loader } from "../../../core/loader";
|
import { Loader } from "../../../core/loader";
|
||||||
@ -270,7 +269,7 @@ export class HUDWaypoints extends BaseHUDPart {
|
|||||||
center: { x: position.x, y: position.y },
|
center: { x: position.x, y: position.y },
|
||||||
// Make sure the zoom is *just* a bit above the zoom level where the map overview
|
// Make sure the zoom is *just* a bit above the zoom level where the map overview
|
||||||
// starts, so you always see all buildings
|
// 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
|
// Sort waypoints by name
|
||||||
@ -419,7 +418,7 @@ export class HUDWaypoints extends BaseHUDPart {
|
|||||||
|
|
||||||
if (this.currentCompassOpacity > 0.01) {
|
if (this.currentCompassOpacity > 0.01) {
|
||||||
context.globalAlpha = this.currentCompassOpacity;
|
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.translate(dims / 2, dims / 2);
|
||||||
context.rotate(angle);
|
context.rotate(angle);
|
||||||
this.directionIndicatorSprite.drawCentered(context, 0, 0, indicatorSize);
|
this.directionIndicatorSprite.drawCentered(context, 0, 0, indicatorSize);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { GameRoot } from "../root";
|
import { GameRoot } from "../root";
|
||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { Vector, mixVector } from "../../core/vector";
|
import { Vector, mixVector } from "../../core/vector";
|
||||||
import { performanceNow } from "../../core/builtins";
|
|
||||||
import { lerp } from "../../core/utils";
|
import { lerp } from "../../core/utils";
|
||||||
|
|
||||||
/* dev:start */
|
/* dev:start */
|
||||||
@ -87,7 +86,7 @@ export class TrailerMaker {
|
|||||||
|
|
||||||
if (!nextMarker.startTime) {
|
if (!nextMarker.startTime) {
|
||||||
console.log("Starting to approach", nextMarker.pos);
|
console.log("Starting to approach", nextMarker.pos);
|
||||||
nextMarker.startTime = performanceNow() / 1000.0;
|
nextMarker.startTime = performance.now() / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const speed =
|
const speed =
|
||||||
@ -98,7 +97,7 @@ export class TrailerMaker {
|
|||||||
// this.currentPlaybackOrigin.distance(Vector.fromSerializedObject(nextMarker.pos)) / speed;
|
// this.currentPlaybackOrigin.distance(Vector.fromSerializedObject(nextMarker.pos)) / speed;
|
||||||
const time = nextMarker.time;
|
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 (progress > 1.0) {
|
||||||
if (nextMarker.wait > 0) {
|
if (nextMarker.wait > 0) {
|
||||||
|
@ -7,8 +7,6 @@ import { Application } from "../application";
|
|||||||
import { Signal, STOP_PROPAGATION } from "../core/signal";
|
import { Signal, STOP_PROPAGATION } from "../core/signal";
|
||||||
import { IS_MOBILE } from "../core/config";
|
import { IS_MOBILE } from "../core/config";
|
||||||
import { T } from "../translations";
|
import { T } from "../translations";
|
||||||
import { JSON_stringify } from "../core/builtins";
|
|
||||||
|
|
||||||
function key(str) {
|
function key(str) {
|
||||||
return str.toUpperCase().charCodeAt(0);
|
return str.toUpperCase().charCodeAt(0);
|
||||||
}
|
}
|
||||||
@ -446,7 +444,7 @@ export class KeyActionMapper {
|
|||||||
getBinding(binding) {
|
getBinding(binding) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const id = binding.id;
|
const id = binding.id;
|
||||||
assert(id, "Not a valid keybinding: " + JSON_stringify(binding));
|
assert(id, "Not a valid keybinding: " + JSON.stringify(binding));
|
||||||
assert(this.keybindings[id], "Keybinding " + id + " not known!");
|
assert(this.keybindings[id], "Keybinding " + id + " not known!");
|
||||||
return this.keybindings[id];
|
return this.keybindings[id];
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { Entity } from "./entity";
|
|||||||
import { Vector, enumDirectionToVector, enumDirection } from "../core/vector";
|
import { Vector, enumDirectionToVector, enumDirection } from "../core/vector";
|
||||||
import { MetaBuilding } from "./meta_building";
|
import { MetaBuilding } from "./meta_building";
|
||||||
import { StaticMapEntityComponent } from "./components/static_map_entity";
|
import { StaticMapEntityComponent } from "./components/static_map_entity";
|
||||||
import { Math_abs, performanceNow } from "../core/builtins";
|
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { MetaBeltBaseBuilding, arrayBeltVariantToRotation } from "./buildings/belt_base";
|
import { MetaBeltBaseBuilding, arrayBeltVariantToRotation } from "./buildings/belt_base";
|
||||||
import { SOUNDS } from "../platform/sound";
|
import { SOUNDS } from "../platform/sound";
|
||||||
@ -199,9 +198,9 @@ export class GameLogic {
|
|||||||
logger.warn("Running bulk operation ...");
|
logger.warn("Running bulk operation ...");
|
||||||
assert(!this.root.bulkOperationRunning, "Can not run two bulk operations twice");
|
assert(!this.root.bulkOperationRunning, "Can not run two bulk operations twice");
|
||||||
this.root.bulkOperationRunning = true;
|
this.root.bulkOperationRunning = true;
|
||||||
const now = performanceNow();
|
const now = performance.now();
|
||||||
const returnValue = operation();
|
const returnValue = operation();
|
||||||
const duration = performanceNow() - now;
|
const duration = performance.now() - now;
|
||||||
logger.log("Done in", round2Digits(duration), "ms");
|
logger.log("Done in", round2Digits(duration), "ms");
|
||||||
assert(this.root.bulkOperationRunning, "Bulk operation = false while bulk operation was running");
|
assert(this.root.bulkOperationRunning, "Bulk operation = false while bulk operation was running");
|
||||||
this.root.bulkOperationRunning = false;
|
this.root.bulkOperationRunning = false;
|
||||||
@ -244,7 +243,7 @@ export class GameLogic {
|
|||||||
|
|
||||||
for (let dx = -1; dx <= 1; ++dx) {
|
for (let dx = -1; dx <= 1; ++dx) {
|
||||||
for (let dy = -1; dy <= 1; ++dy) {
|
for (let dy = -1; dy <= 1; ++dy) {
|
||||||
if (Math_abs(dx) + Math_abs(dy) !== 1) {
|
if (Math.abs(dx) + Math.abs(dy) !== 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import { GameRoot } from "./root";
|
|||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { Vector } from "../core/vector";
|
import { Vector } from "../core/vector";
|
||||||
import { Entity } from "./entity";
|
import { Entity } from "./entity";
|
||||||
import { Math_floor } from "../core/builtins";
|
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { BaseItem } from "./base_item";
|
import { BaseItem } from "./base_item";
|
||||||
import { MapChunkView } from "./map_chunk_view";
|
import { MapChunkView } from "./map_chunk_view";
|
||||||
@ -71,8 +70,8 @@ export class BaseMap extends BasicSerializableObject {
|
|||||||
* @returns {MapChunkView}
|
* @returns {MapChunkView}
|
||||||
*/
|
*/
|
||||||
getOrCreateChunkAtTile(tileX, tileY) {
|
getOrCreateChunkAtTile(tileX, tileY) {
|
||||||
const chunkX = Math_floor(tileX / globalConfig.mapChunkSize);
|
const chunkX = Math.floor(tileX / globalConfig.mapChunkSize);
|
||||||
const chunkY = Math_floor(tileY / globalConfig.mapChunkSize);
|
const chunkY = Math.floor(tileY / globalConfig.mapChunkSize);
|
||||||
return this.getChunk(chunkX, chunkY, true);
|
return this.getChunk(chunkX, chunkY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +82,8 @@ export class BaseMap extends BasicSerializableObject {
|
|||||||
* @returns {MapChunkView?}
|
* @returns {MapChunkView?}
|
||||||
*/
|
*/
|
||||||
getChunkAtTileOrNull(tileX, tileY) {
|
getChunkAtTileOrNull(tileX, tileY) {
|
||||||
const chunkX = Math_floor(tileX / globalConfig.mapChunkSize);
|
const chunkX = Math.floor(tileX / globalConfig.mapChunkSize);
|
||||||
const chunkY = Math_floor(tileY / globalConfig.mapChunkSize);
|
const chunkY = Math.floor(tileY / globalConfig.mapChunkSize);
|
||||||
return this.getChunk(chunkX, chunkY, false);
|
return this.getChunk(chunkX, chunkY, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
import { Math_ceil, Math_max, Math_min, Math_round } from "../core/builtins";
|
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { clamp, fastArrayDeleteValueIfContained, make2DUndefinedArray } from "../core/utils";
|
import { clamp, fastArrayDeleteValueIfContained, make2DUndefinedArray } from "../core/utils";
|
||||||
@ -66,7 +65,7 @@ export class MapChunk {
|
|||||||
* @param {number=} overrideY Override the Y position of the patch
|
* @param {number=} overrideY Override the Y position of the patch
|
||||||
*/
|
*/
|
||||||
internalGeneratePatch(rng, patchSize, item, overrideX = null, overrideY = null) {
|
internalGeneratePatch(rng, patchSize, item, overrideX = null, overrideY = null) {
|
||||||
const border = Math_ceil(patchSize / 2 + 3);
|
const border = Math.ceil(patchSize / 2 + 3);
|
||||||
|
|
||||||
// Find a position within the chunk which is not blocked
|
// Find a position within the chunk which is not blocked
|
||||||
let patchX = rng.nextIntRange(border, globalConfig.mapChunkSize - border - 1);
|
let patchX = rng.nextIntRange(border, globalConfig.mapChunkSize - border - 1);
|
||||||
@ -88,7 +87,7 @@ export class MapChunk {
|
|||||||
|
|
||||||
for (let i = 0; i <= numCircles; ++i) {
|
for (let i = 0; i <= numCircles; ++i) {
|
||||||
// Determine circle parameters
|
// Determine circle parameters
|
||||||
const circleRadius = Math_min(1 + i, patchSize);
|
const circleRadius = Math.min(1 + i, patchSize);
|
||||||
const circleRadiusSquare = circleRadius * circleRadius;
|
const circleRadiusSquare = circleRadius * circleRadius;
|
||||||
const circleOffsetRadius = (numCircles - i) / 2 + 2;
|
const circleOffsetRadius = (numCircles - i) / 2 + 2;
|
||||||
|
|
||||||
@ -101,8 +100,8 @@ export class MapChunk {
|
|||||||
|
|
||||||
for (let dx = -circleRadius * circleScaleX - 2; dx <= circleRadius * circleScaleX + 2; ++dx) {
|
for (let dx = -circleRadius * circleScaleX - 2; dx <= circleRadius * circleScaleX + 2; ++dx) {
|
||||||
for (let dy = -circleRadius * circleScaleY - 2; dy <= circleRadius * circleScaleY + 2; ++dy) {
|
for (let dy = -circleRadius * circleScaleY - 2; dy <= circleRadius * circleScaleY + 2; ++dy) {
|
||||||
const x = Math_round(circleX + dx);
|
const x = Math.round(circleX + dx);
|
||||||
const y = Math_round(circleY + dy);
|
const y = Math.round(circleY + dy);
|
||||||
if (x >= 0 && x < globalConfig.mapChunkSize && y >= 0 && y <= globalConfig.mapChunkSize) {
|
if (x >= 0 && x < globalConfig.mapChunkSize && y >= 0 && y <= globalConfig.mapChunkSize) {
|
||||||
const originalDx = dx / circleScaleX;
|
const originalDx = dx / circleScaleX;
|
||||||
const originalDy = dy / circleScaleY;
|
const originalDy = dy / circleScaleY;
|
||||||
@ -158,9 +157,9 @@ export class MapChunk {
|
|||||||
// Later there is a mix of everything
|
// Later there is a mix of everything
|
||||||
weights = {
|
weights = {
|
||||||
[enumSubShape.rect]: 100,
|
[enumSubShape.rect]: 100,
|
||||||
[enumSubShape.circle]: Math_round(50 + clamp(distanceToOriginInChunks * 2, 0, 50)),
|
[enumSubShape.circle]: Math.round(50 + clamp(distanceToOriginInChunks * 2, 0, 50)),
|
||||||
[enumSubShape.star]: Math_round(20 + clamp(distanceToOriginInChunks, 0, 30)),
|
[enumSubShape.star]: Math.round(20 + clamp(distanceToOriginInChunks, 0, 30)),
|
||||||
[enumSubShape.windmill]: Math_round(6 + clamp(distanceToOriginInChunks / 2, 0, 20)),
|
[enumSubShape.windmill]: Math.round(6 + clamp(distanceToOriginInChunks / 2, 0, 20)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (distanceToOriginInChunks < 7) {
|
if (distanceToOriginInChunks < 7) {
|
||||||
@ -239,20 +238,20 @@ export class MapChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const chunkCenter = new Vector(this.x, this.y).addScalar(0.5);
|
const chunkCenter = new Vector(this.x, this.y).addScalar(0.5);
|
||||||
const distanceToOriginInChunks = Math_round(chunkCenter.length());
|
const distanceToOriginInChunks = Math.round(chunkCenter.length());
|
||||||
|
|
||||||
// Determine how likely it is that there is a color patch
|
// Determine how likely it is that there is a color patch
|
||||||
const colorPatchChance = 0.9 - clamp(distanceToOriginInChunks / 25, 0, 1) * 0.5;
|
const colorPatchChance = 0.9 - clamp(distanceToOriginInChunks / 25, 0, 1) * 0.5;
|
||||||
|
|
||||||
if (rng.next() < colorPatchChance / 4) {
|
if (rng.next() < colorPatchChance / 4) {
|
||||||
const colorPatchSize = Math_max(2, Math_round(1 + clamp(distanceToOriginInChunks / 8, 0, 4)));
|
const colorPatchSize = Math.max(2, Math.round(1 + clamp(distanceToOriginInChunks / 8, 0, 4)));
|
||||||
this.internalGenerateColorPatch(rng, colorPatchSize, distanceToOriginInChunks);
|
this.internalGenerateColorPatch(rng, colorPatchSize, distanceToOriginInChunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine how likely it is that there is a shape patch
|
// Determine how likely it is that there is a shape patch
|
||||||
const shapePatchChance = 0.9 - clamp(distanceToOriginInChunks / 25, 0, 1) * 0.5;
|
const shapePatchChance = 0.9 - clamp(distanceToOriginInChunks / 25, 0, 1) * 0.5;
|
||||||
if (rng.next() < shapePatchChance / 4) {
|
if (rng.next() < shapePatchChance / 4) {
|
||||||
const shapePatchSize = Math_max(2, Math_round(1 + clamp(distanceToOriginInChunks / 8, 0, 4)));
|
const shapePatchSize = Math.max(2, Math.round(1 + clamp(distanceToOriginInChunks / 8, 0, 4)));
|
||||||
this.internalGenerateShapePatch(rng, shapePatchSize, distanceToOriginInChunks);
|
this.internalGenerateShapePatch(rng, shapePatchSize, distanceToOriginInChunks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { GameRoot } from "./root";
|
|||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { round1Digit } from "../core/utils";
|
import { round1Digit } from "../core/utils";
|
||||||
import { Math_max, Math_round } from "../core/builtins";
|
|
||||||
import { Rectangle } from "../core/rectangle";
|
import { Rectangle } from "../core/rectangle";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { smoothenDpi } from "../core/dpi_manager";
|
import { smoothenDpi } from "../core/dpi_manager";
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_max, Math_min, Math_floor, Math_ceil } from "../core/builtins";
|
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { BaseMap } from "./map";
|
import { BaseMap } from "./map";
|
||||||
@ -142,11 +141,11 @@ export class MapView extends BaseMap {
|
|||||||
const minX = left - border;
|
const minX = left - border;
|
||||||
const maxX = right + border - 1;
|
const maxX = right + border - 1;
|
||||||
|
|
||||||
const chunkStartX = Math_floor(minX / globalConfig.mapChunkSize);
|
const chunkStartX = Math.floor(minX / globalConfig.mapChunkSize);
|
||||||
const chunkStartY = Math_floor(minY / globalConfig.mapChunkSize);
|
const chunkStartY = Math.floor(minY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
const chunkEndX = Math_ceil(maxX / globalConfig.mapChunkSize);
|
const chunkEndX = Math.ceil(maxX / globalConfig.mapChunkSize);
|
||||||
const chunkEndY = Math_ceil(maxY / globalConfig.mapChunkSize);
|
const chunkEndY = Math.ceil(maxY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
// Render y from top down for proper blending
|
// Render y from top down for proper blending
|
||||||
for (let chunkX = chunkStartX; chunkX <= chunkEndX; ++chunkX) {
|
for (let chunkX = chunkStartX; chunkX <= chunkEndX; ++chunkX) {
|
||||||
@ -196,11 +195,11 @@ export class MapView extends BaseMap {
|
|||||||
const minX = left - border;
|
const minX = left - border;
|
||||||
const maxX = right + border - 1;
|
const maxX = right + border - 1;
|
||||||
|
|
||||||
const chunkStartX = Math_floor(minX / globalConfig.mapChunkSize);
|
const chunkStartX = Math.floor(minX / globalConfig.mapChunkSize);
|
||||||
const chunkStartY = Math_floor(minY / globalConfig.mapChunkSize);
|
const chunkStartY = Math.floor(minY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
const chunkEndX = Math_ceil(maxX / globalConfig.mapChunkSize);
|
const chunkEndX = Math.ceil(maxX / globalConfig.mapChunkSize);
|
||||||
const chunkEndY = Math_ceil(maxY / globalConfig.mapChunkSize);
|
const chunkEndY = Math.ceil(maxY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
// Render y from top down for proper blending
|
// Render y from top down for proper blending
|
||||||
for (let chunkX = chunkStartX; chunkX <= chunkEndX; ++chunkX) {
|
for (let chunkX = chunkStartX; chunkX <= chunkEndX; ++chunkX) {
|
||||||
@ -223,11 +222,11 @@ export class MapView extends BaseMap {
|
|||||||
const minX = left - border;
|
const minX = left - border;
|
||||||
const maxX = right + border - 1;
|
const maxX = right + border - 1;
|
||||||
|
|
||||||
const chunkStartX = Math_floor(minX / globalConfig.mapChunkSize);
|
const chunkStartX = Math.floor(minX / globalConfig.mapChunkSize);
|
||||||
const chunkStartY = Math_floor(minY / globalConfig.mapChunkSize);
|
const chunkStartY = Math.floor(minY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
const chunkEndX = Math_ceil(maxX / globalConfig.mapChunkSize);
|
const chunkEndX = Math.ceil(maxX / globalConfig.mapChunkSize);
|
||||||
const chunkEndY = Math_ceil(maxY / globalConfig.mapChunkSize);
|
const chunkEndY = Math.ceil(maxY / globalConfig.mapChunkSize);
|
||||||
|
|
||||||
// Render y from top down for proper blending
|
// Render y from top down for proper blending
|
||||||
for (let chunkX = chunkStartX; chunkX <= chunkEndX; ++chunkX) {
|
for (let chunkX = chunkStartX; chunkX <= chunkEndX; ++chunkX) {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { makeOffscreenBuffer } from "../core/buffer_utils";
|
import { makeOffscreenBuffer } from "../core/buffer_utils";
|
||||||
import { JSON_parse, JSON_stringify, Math_max, Math_PI, Math_radians } from "../core/builtins";
|
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { smoothenDpi } from "../core/dpi_manager";
|
import { smoothenDpi } from "../core/dpi_manager";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
@ -235,7 +234,7 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
* @returns {Array<ShapeLayer>}
|
* @returns {Array<ShapeLayer>}
|
||||||
*/
|
*/
|
||||||
internalCloneLayers() {
|
internalCloneLayers() {
|
||||||
return JSON_parse(JSON_stringify(this.layers));
|
return JSON.parse(JSON.stringify(this.layers));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -340,7 +339,7 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
for (let layerIndex = 0; layerIndex < this.layers.length; ++layerIndex) {
|
for (let layerIndex = 0; layerIndex < this.layers.length; ++layerIndex) {
|
||||||
const quadrants = this.layers[layerIndex];
|
const quadrants = this.layers[layerIndex];
|
||||||
|
|
||||||
const layerScale = Math_max(0.1, 0.9 - layerIndex * 0.22);
|
const layerScale = Math.max(0.1, 0.9 - layerIndex * 0.22);
|
||||||
|
|
||||||
for (let quadrantIndex = 0; quadrantIndex < 4; ++quadrantIndex) {
|
for (let quadrantIndex = 0; quadrantIndex < 4; ++quadrantIndex) {
|
||||||
if (!quadrants[quadrantIndex]) {
|
if (!quadrants[quadrantIndex]) {
|
||||||
@ -352,7 +351,7 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
const centerQuadrantX = quadrantPos.x * quadrantHalfSize;
|
const centerQuadrantX = quadrantPos.x * quadrantHalfSize;
|
||||||
const centerQuadrantY = quadrantPos.y * quadrantHalfSize;
|
const centerQuadrantY = quadrantPos.y * quadrantHalfSize;
|
||||||
|
|
||||||
const rotation = Math_radians(quadrantIndex * 90);
|
const rotation = Math.radians(quadrantIndex * 90);
|
||||||
|
|
||||||
context.translate(centerQuadrantX, centerQuadrantY);
|
context.translate(centerQuadrantX, centerQuadrantY);
|
||||||
context.rotate(rotation);
|
context.rotate(rotation);
|
||||||
@ -414,7 +413,7 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
insetPadding + -quadrantHalfSize,
|
insetPadding + -quadrantHalfSize,
|
||||||
-insetPadding + quadrantHalfSize,
|
-insetPadding + quadrantHalfSize,
|
||||||
quadrantSize * layerScale,
|
quadrantSize * layerScale,
|
||||||
-Math_PI * 0.5,
|
-Math.PI * 0.5,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
context.closePath();
|
context.closePath();
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_min } from "../../core/builtins";
|
|
||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { DrawParameters } from "../../core/draw_parameters";
|
import { DrawParameters } from "../../core/draw_parameters";
|
||||||
import { gMetaBuildingRegistry } from "../../core/global_registries";
|
import { gMetaBuildingRegistry } from "../../core/global_registries";
|
||||||
@ -482,7 +481,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Limit speed to avoid belts going backwards
|
// Limit speed to avoid belts going backwards
|
||||||
const speedMultiplier = Math_min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
||||||
|
|
||||||
// SYNC with systems/item_acceptor.js:drawEntityUnderlays!
|
// SYNC with systems/item_acceptor.js:drawEntityUnderlays!
|
||||||
// 126 / 42 is the exact animation speed of the png animation
|
// 126 / 42 is the exact animation speed of the png animation
|
||||||
|
@ -6,7 +6,6 @@ import { enumDirectionToVector, enumDirectionToAngle } from "../../core/vector";
|
|||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { Loader } from "../../core/loader";
|
import { Loader } from "../../core/loader";
|
||||||
import { drawRotatedSprite } from "../../core/draw_utils";
|
import { drawRotatedSprite } from "../../core/draw_utils";
|
||||||
import { Math_radians, Math_min } from "../../core/builtins";
|
|
||||||
import { BELT_ANIM_COUNT } from "./belt";
|
import { BELT_ANIM_COUNT } from "./belt";
|
||||||
|
|
||||||
export class ItemAcceptorSystem extends GameSystemWithFilter {
|
export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||||
@ -98,7 +97,7 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Limit speed to avoid belts going backwards
|
// Limit speed to avoid belts going backwards
|
||||||
const speedMultiplier = Math_min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
||||||
|
|
||||||
const underlays = acceptorComp.beltUnderlays;
|
const underlays = acceptorComp.beltUnderlays;
|
||||||
for (let i = 0; i < underlays.length; ++i) {
|
for (let i = 0; i < underlays.length; ++i) {
|
||||||
@ -118,7 +117,7 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
|||||||
sprite: this.underlayBeltSprites[animationIndex % this.underlayBeltSprites.length],
|
sprite: this.underlayBeltSprites[animationIndex % this.underlayBeltSprites.length],
|
||||||
x: (transformedPos.x + 0.5) * globalConfig.tileSize,
|
x: (transformedPos.x + 0.5) * globalConfig.tileSize,
|
||||||
y: (transformedPos.y + 0.5) * globalConfig.tileSize,
|
y: (transformedPos.y + 0.5) * globalConfig.tileSize,
|
||||||
angle: Math_radians(angle),
|
angle: Math.radians(angle),
|
||||||
size: globalConfig.tileSize,
|
size: globalConfig.tileSize,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_min } from "../../core/builtins";
|
|
||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { DrawParameters } from "../../core/draw_parameters";
|
import { DrawParameters } from "../../core/draw_parameters";
|
||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
@ -207,7 +206,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
const targetEntity = sourceSlot.cachedTargetEntity;
|
const targetEntity = sourceSlot.cachedTargetEntity;
|
||||||
|
|
||||||
// Advance items on the slot
|
// Advance items on the slot
|
||||||
sourceSlot.progress = Math_min(1, sourceSlot.progress + progressGrowth);
|
sourceSlot.progress = Math.min(1, sourceSlot.progress + progressGrowth);
|
||||||
|
|
||||||
// Check if we are still in the process of ejecting, can't proceed then
|
// Check if we are still in the process of ejecting, can't proceed then
|
||||||
if (sourceSlot.progress < 1.0) {
|
if (sourceSlot.progress < 1.0) {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_max } from "../../core/builtins";
|
|
||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { enumColorMixingResults } from "../colors";
|
import { enumColorMixingResults } from "../colors";
|
||||||
@ -21,7 +20,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
|||||||
const ejectorComp = entity.components.ItemEjector;
|
const ejectorComp = entity.components.ItemEjector;
|
||||||
|
|
||||||
// First of all, process the current recipe
|
// First of all, process the current recipe
|
||||||
processorComp.secondsUntilEject = Math_max(
|
processorComp.secondsUntilEject = Math.max(
|
||||||
0,
|
0,
|
||||||
processorComp.secondsUntilEject - this.root.dynamicTickrate.deltaSeconds
|
processorComp.secondsUntilEject - this.root.dynamicTickrate.deltaSeconds
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_max } from "../../core/builtins";
|
|
||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { Loader } from "../../core/loader";
|
import { Loader } from "../../core/loader";
|
||||||
import {
|
import {
|
||||||
@ -40,7 +39,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
// Decrease remaining time of all items in belt
|
// Decrease remaining time of all items in belt
|
||||||
for (let k = 0; k < pendingItems.length; ++k) {
|
for (let k = 0; k < pendingItems.length; ++k) {
|
||||||
const item = pendingItems[k];
|
const item = pendingItems[k];
|
||||||
item[1] = Math_max(0, item[1] - delta);
|
item[1] = Math.max(0, item[1] - delta);
|
||||||
if (G_IS_DEV && globalConfig.debug.instantBelts) {
|
if (G_IS_DEV && globalConfig.debug.instantBelts) {
|
||||||
item[1] = 0;
|
item[1] = 0;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import { types, BasicSerializableObject } from "../../savegame/serialization";
|
|||||||
import { RegularGameSpeed } from "./regular_game_speed";
|
import { RegularGameSpeed } from "./regular_game_speed";
|
||||||
import { BaseGameSpeed } from "./base_game_speed";
|
import { BaseGameSpeed } from "./base_game_speed";
|
||||||
import { PausedGameSpeed } from "./paused_game_speed";
|
import { PausedGameSpeed } from "./paused_game_speed";
|
||||||
import { performanceNow, Math_max } from "../../core/builtins";
|
|
||||||
import { FastForwardGameSpeed } from "./fast_forward_game_speed";
|
import { FastForwardGameSpeed } from "./fast_forward_game_speed";
|
||||||
import { gGameSpeedRegistry } from "../../core/global_registries";
|
import { gGameSpeedRegistry } from "../../core/global_registries";
|
||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
@ -55,7 +54,7 @@ export class GameTime extends BasicSerializableObject {
|
|||||||
* Fetches the new "real" time, called from the core once per frame, since performance now() is kinda slow
|
* Fetches the new "real" time, called from the core once per frame, since performance now() is kinda slow
|
||||||
*/
|
*/
|
||||||
updateRealtimeNow() {
|
updateRealtimeNow() {
|
||||||
this.realtimeSeconds = performanceNow() / 1000.0 + this.realtimeAdjust;
|
this.realtimeSeconds = performance.now() / 1000.0 + this.realtimeAdjust;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +103,7 @@ export class GameTime extends BasicSerializableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for too big pile of updates -> reduce it to 1
|
// Check for too big pile of updates -> reduce it to 1
|
||||||
let maxLogicSteps = Math_max(
|
let maxLogicSteps = Math.max(
|
||||||
3,
|
3,
|
||||||
(this.speed.getMaxLogicStepsInQueue() * this.root.dynamicTickrate.currentTickRate) / 60
|
(this.speed.getMaxLogicStepsInQueue() * this.root.dynamicTickrate.currentTickRate) / 60
|
||||||
);
|
);
|
||||||
@ -209,7 +208,7 @@ export class GameTime extends BasicSerializableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adjust realtime now difference so they match
|
// Adjust realtime now difference so they match
|
||||||
this.realtimeAdjust = this.realtimeSeconds - performanceNow() / 1000.0;
|
this.realtimeAdjust = this.realtimeSeconds - performance.now() / 1000.0;
|
||||||
this.updateRealtimeNow();
|
this.updateRealtimeNow();
|
||||||
|
|
||||||
// Make sure we have a quantizied time
|
// Make sure we have a quantizied time
|
||||||
|
@ -5,7 +5,6 @@ import { Application } from "../../application";
|
|||||||
import { AdProviderInterface } from "../ad_provider";
|
import { AdProviderInterface } from "../ad_provider";
|
||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
import { ClickDetector } from "../../core/click_detector";
|
import { ClickDetector } from "../../core/click_detector";
|
||||||
import { performanceNow } from "../../core/builtins";
|
|
||||||
import { clamp } from "../../core/utils";
|
import { clamp } from "../../core/utils";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ export class AdinplayAdProvider extends AdProviderInterface {
|
|||||||
return (
|
return (
|
||||||
this.getHasAds() &&
|
this.getHasAds() &&
|
||||||
!this.videoAdResolveFunction &&
|
!this.videoAdResolveFunction &&
|
||||||
performanceNow() - this.lastVideoAdShowTime > minimumTimeBetweenVideoAdsMs
|
performance.now() - this.lastVideoAdShowTime > minimumTimeBetweenVideoAdsMs
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +140,7 @@ export class AdinplayAdProvider extends AdProviderInterface {
|
|||||||
showVideoAd() {
|
showVideoAd() {
|
||||||
assert(this.getHasAds(), "Called showVideoAd but ads are not supported!");
|
assert(this.getHasAds(), "Called showVideoAd but ads are not supported!");
|
||||||
assert(!this.videoAdResolveFunction, "Video ad still running, can not show again!");
|
assert(!this.videoAdResolveFunction, "Video ad still running, can not show again!");
|
||||||
this.lastVideoAdShowTime = performanceNow();
|
this.lastVideoAdShowTime = performance.now();
|
||||||
document.body.appendChild(this.adContainerMainElement);
|
document.body.appendChild(this.adContainerMainElement);
|
||||||
this.adContainerMainElement.classList.add("visible");
|
this.adContainerMainElement.classList.add("visible");
|
||||||
this.adContainerMainElement.classList.remove("waitingForFinish");
|
this.adContainerMainElement.classList.remove("waitingForFinish");
|
||||||
@ -167,7 +166,7 @@ export class AdinplayAdProvider extends AdProviderInterface {
|
|||||||
this.videoAdResolveTimer = null;
|
this.videoAdResolveTimer = null;
|
||||||
|
|
||||||
// When the ad closed, also set the time
|
// When the ad closed, also set the time
|
||||||
this.lastVideoAdShowTime = performanceNow();
|
this.lastVideoAdShowTime = performance.now();
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import { Application } from "../../application";
|
|||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
import { AdProviderInterface } from "../ad_provider";
|
import { AdProviderInterface } from "../ad_provider";
|
||||||
import { performanceNow } from "../../core/builtins";
|
|
||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
|
|
||||||
const minimumTimeBetweenVideoAdsMs = G_IS_DEV ? 1 : 5 * 60 * 1000;
|
const minimumTimeBetweenVideoAdsMs = G_IS_DEV ? 1 : 5 * 60 * 1000;
|
||||||
@ -45,7 +44,7 @@ export class GamedistributionAdProvider extends AdProviderInterface {
|
|||||||
return (
|
return (
|
||||||
this.getHasAds() &&
|
this.getHasAds() &&
|
||||||
!this.videoAdResolveFunction &&
|
!this.videoAdResolveFunction &&
|
||||||
performanceNow() - this.lastVideoAdShowTime > minimumTimeBetweenVideoAdsMs
|
performance.now() - this.lastVideoAdShowTime > minimumTimeBetweenVideoAdsMs
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ export class GamedistributionAdProvider extends AdProviderInterface {
|
|||||||
showVideoAd() {
|
showVideoAd() {
|
||||||
assert(this.getHasAds(), "Called showVideoAd but ads are not supported!");
|
assert(this.getHasAds(), "Called showVideoAd but ads are not supported!");
|
||||||
assert(!this.videoAdResolveFunction, "Video ad still running, can not show again!");
|
assert(!this.videoAdResolveFunction, "Video ad still running, can not show again!");
|
||||||
this.lastVideoAdShowTime = performanceNow();
|
this.lastVideoAdShowTime = performance.now();
|
||||||
|
|
||||||
console.log("🎬 Gamedistribution: Start ad");
|
console.log("🎬 Gamedistribution: Start ad");
|
||||||
try {
|
try {
|
||||||
@ -104,7 +103,7 @@ export class GamedistributionAdProvider extends AdProviderInterface {
|
|||||||
this.videoAdResolveTimer = null;
|
this.videoAdResolveTimer = null;
|
||||||
|
|
||||||
// When the ad closed, also set the time
|
// When the ad closed, also set the time
|
||||||
this.lastVideoAdShowTime = performanceNow();
|
this.lastVideoAdShowTime = performance.now();
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { AnalyticsInterface } from "../analytics";
|
import { AnalyticsInterface } from "../analytics";
|
||||||
import { Math_random, performanceNow } from "../../core/builtins";
|
|
||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
|
|
||||||
const logger = createLogger("ga");
|
const logger = createLogger("ga");
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Math_min } from "../../core/builtins";
|
|
||||||
import { globalConfig, IS_DEMO, IS_MOBILE } from "../../core/config";
|
import { globalConfig, IS_DEMO, IS_MOBILE } from "../../core/config";
|
||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
import { queryParamOptions } from "../../core/query_parameters";
|
import { queryParamOptions } from "../../core/query_parameters";
|
||||||
@ -130,7 +129,7 @@ export class PlatformWrapperImplBrowser extends PlatformWrapperInterface {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const avgDims = Math_min(this.app.screenWidth, this.app.screenHeight);
|
const avgDims = Math.min(this.app.screenWidth, this.app.screenHeight);
|
||||||
return clamp((avgDims / 1000.0) * 1.9, 0.1, 10);
|
return clamp((avgDims / 1000.0) * 1.9, 0.1, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ export class Savegame extends ReadWriteProxy {
|
|||||||
// Construct a new serializer
|
// Construct a new serializer
|
||||||
const serializer = new SavegameSerializer();
|
const serializer = new SavegameSerializer();
|
||||||
|
|
||||||
// let timer = performanceNow();
|
// let timer = performance.now();
|
||||||
const dump = serializer.generateDumpFromGameRoot(root);
|
const dump = serializer.generateDumpFromGameRoot(root);
|
||||||
if (!dump) {
|
if (!dump) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -3,8 +3,6 @@ import { createLogger } from "../core/logging";
|
|||||||
import { ReadWriteProxy } from "../core/read_write_proxy";
|
import { ReadWriteProxy } from "../core/read_write_proxy";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { Savegame } from "./savegame";
|
import { Savegame } from "./savegame";
|
||||||
import { Math_floor } from "../core/builtins";
|
|
||||||
|
|
||||||
const logger = createLogger("savegame_manager");
|
const logger = createLogger("savegame_manager");
|
||||||
|
|
||||||
const Rusha = require("rusha");
|
const Rusha = require("rusha");
|
||||||
|
@ -3,7 +3,6 @@ import { Component } from "../game/component";
|
|||||||
import { GameRoot } from "../game/root";
|
import { GameRoot } from "../game/root";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
import { JSON_stringify } from "../core/builtins";
|
|
||||||
import { ExplainedResult } from "../core/explained_result";
|
import { ExplainedResult } from "../core/explained_result";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
// import { BuildingComponent } from "../components/impl/building";
|
// import { BuildingComponent } from "../components/impl/building";
|
||||||
@ -88,7 +87,7 @@ export class SavegameSerializer {
|
|||||||
// Verify components
|
// Verify components
|
||||||
if (!entity.components) {
|
if (!entity.components) {
|
||||||
return ExplainedResult.bad(
|
return ExplainedResult.bad(
|
||||||
"Entity is missing key 'components': " + JSON_stringify(entity)
|
"Entity is missing key 'components': " + JSON.stringify(entity)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const components = entity.components;
|
const components = entity.components;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { JSON_stringify } from "../core/builtins";
|
|
||||||
import {
|
import {
|
||||||
BaseDataType,
|
BaseDataType,
|
||||||
TypeArray,
|
TypeArray,
|
||||||
@ -223,7 +222,7 @@ export function serializeSchema(obj, schema, mergeWith = {}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!schema[key]) {
|
if (!schema[key]) {
|
||||||
assert(false, "Invalid schema (bad key '" + key + "'): " + JSON_stringify(schema));
|
assert(false, "Invalid schema (bad key '" + key + "'): " + JSON.stringify(schema));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G_IS_DEV) {
|
if (G_IS_DEV) {
|
||||||
|
@ -5,8 +5,6 @@ import { BasicSerializableObject } from "./serialization";
|
|||||||
|
|
||||||
import { Vector } from "../core/vector";
|
import { Vector } from "../core/vector";
|
||||||
import { round4Digits, schemaObject, accessNestedPropertyReverse } from "../core/utils";
|
import { round4Digits, schemaObject, accessNestedPropertyReverse } from "../core/utils";
|
||||||
import { JSON_stringify } from "../core/builtins";
|
|
||||||
|
|
||||||
export const globalJsonSchemaDefs = {};
|
export const globalJsonSchemaDefs = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,7 +126,7 @@ export class BaseDataType {
|
|||||||
"serialization verify failed: " +
|
"serialization verify failed: " +
|
||||||
errorCode +
|
errorCode +
|
||||||
" [value " +
|
" [value " +
|
||||||
JSON_stringify(value).substr(0, 100) +
|
JSON.stringify(value).substr(0, 100) +
|
||||||
"]"
|
"]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user