Skip to content

Commit

Permalink
Change + optimize numericalAnalysis functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xShadowBlade committed May 21, 2024
1 parent abfeac2 commit 2702acd
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 265 deletions.
93 changes: 51 additions & 42 deletions dist/game/eMath.game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5511,7 +5511,7 @@ var import_reflect_metadata = require("reflect-metadata");
var import_class_transformer2 = require("class-transformer");

// src/classes/numericalAnalysis.ts
var DEFAULT_ITERATIONS = 35;
var DEFAULT_ITERATIONS = 30;
var DEFAULT_TOLERANCE = 1e-3;
function equalsTolerance(a, b, tolerance, config) {
config = Object.assign({}, {
Expand Down Expand Up @@ -5566,7 +5566,8 @@ function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_IT
const midValue = f(mid);
if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) {
break;
} else if (midValue.lt(n)) {
}
if (midValue.lt(n)) {
lowerBound = mid;
} else {
upperBound = mid;
Expand Down Expand Up @@ -5658,16 +5659,6 @@ function calculateUpgrade(value, upgrade, start, end = Infinity, mode, iteration
const maxLevelAffordableActual = maxLevelAffordable.sub(start).add(1).max(0);
return [maxLevelAffordableActual, cost];
}
function decimalToJSONString(n) {
n = E(n);
return `${n.sign}/${n.mag}/${n.layer}`;
}
function upgradeToCacheNameSum(start, end) {
return `sum/${decimalToJSONString(start)}/${decimalToJSONString(end)}}`;
}
function upgradeToCacheNameEL(level) {
return `el/${decimalToJSONString(level)}`;
}
var UpgradeData = class {
/**
* Constructs a new upgrade object with an initial level of 1 (or the provided level)
Expand All @@ -5688,7 +5679,7 @@ __decorateClass([
var UpgradeStatic = class _UpgradeStatic {
static {
/** The default size of the cache. Should be one less than a power of 2. */
this.cacheSize = 63;
this.cacheSize = 15;
}
/** @returns The data of the upgrade. */
get data() {
Expand All @@ -5711,7 +5702,7 @@ var UpgradeStatic = class _UpgradeStatic {
* Constructs a new static upgrade object.
* @param init - The upgrade object to initialize.
* @param dataPointer - A function or reference that returns the pointer of the data / frontend.
* @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}
* @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching.
*/
constructor(init, dataPointer, cacheSize) {
const data = typeof dataPointer === "function" ? dataPointer() : dataPointer;
Expand All @@ -5727,33 +5718,51 @@ var UpgradeStatic = class _UpgradeStatic {
this.el = init.el;
this.defaultLevel = init.level ?? E(1);
}
getCached(type, start, end) {
if (type === "sum") {
return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0)));
} else {
return this.cache.get(upgradeToCacheNameEL(start));
}
}
setCached(type, start, endOrStart, costSum) {
const data = type === "sum" ? {
id: this.id,
el: false,
start: E(start),
end: E(endOrStart),
cost: E(costSum)
} : {
id: this.id,
el: true,
level: E(start),
cost: E(endOrStart)
};
if (type === "sum") {
this.cache.set(upgradeToCacheNameSum(start, endOrStart), data);
} else {
this.cache.set(upgradeToCacheNameEL(start), data);
}
return data;
}
// /**
// * Gets the cached data of the upgrade.
// * @param type - The type of the cache. "sum" or "el"
// * @param start - The starting level of the upgrade.
// * @param end - The ending level or quantity to reach for the upgrade.
// * @returns The data of the upgrade.
// */
// public getCached (type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined;
// public getCached (type: "el", start: ESource): UpgradeCachedEL | undefined;
// public getCached (type: "sum" | "el", start: ESource, end?: ESource): UpgradeCachedEL | UpgradeCachedSum | undefined {
// if (type === "sum") {
// return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0)));
// } else {
// return this.cache.get(upgradeToCacheNameEL(start));
// }
// }
// /**
// * Sets the cached data of the upgrade.
// * @param type - The type of the cache. "sum" or "el"
// * @param start - The starting level of the upgrade.
// * @param end - The ending level or quantity to reach for the upgrade.
// * @param cost - The cost of the upgrade.
// */
// public setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum;
// public setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL;
// public setCached (type: "sum" | "el", start: ESource, endOrStart: ESource, costSum?: ESource): UpgradeCachedEL | UpgradeCachedSum {
// const data = type === "sum" ? {
// id: this.id,
// el: false,
// start: E(start),
// end: E(endOrStart),
// cost: E(costSum),
// } : {
// id: this.id,
// el: true,
// level: E(start),
// cost: E(endOrStart),
// };
// if (type === "sum") {
// this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum);
// } else {
// this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL);
// }
// return data as UpgradeCachedEL | UpgradeCachedSum;
// }
};

// src/classes/Currency.ts
Expand Down Expand Up @@ -6572,7 +6581,7 @@ var DataManager = class {
const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`);
let version;
try {
version = "8.3.0";
version = "8.4.0";
} catch (error) {
version = "8.3.0";
}
Expand Down
2 changes: 1 addition & 1 deletion dist/game/eMath.game.min.js

Large diffs are not rendered by default.

93 changes: 51 additions & 42 deletions dist/game/eMath.game.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5477,7 +5477,7 @@ import "reflect-metadata";
import { Type, Expose as Expose2 } from "class-transformer";

// src/classes/numericalAnalysis.ts
var DEFAULT_ITERATIONS = 35;
var DEFAULT_ITERATIONS = 30;
var DEFAULT_TOLERANCE = 1e-3;
function equalsTolerance(a, b, tolerance, config) {
config = Object.assign({}, {
Expand Down Expand Up @@ -5532,7 +5532,8 @@ function inverseFunctionApprox(f, n, mode = "geometric", iterations = DEFAULT_IT
const midValue = f(mid);
if (equalsTolerance(lowerBound, upperBound, tolerance, { verbose: false, mode: "geometric" })) {
break;
} else if (midValue.lt(n)) {
}
if (midValue.lt(n)) {
lowerBound = mid;
} else {
upperBound = mid;
Expand Down Expand Up @@ -5624,16 +5625,6 @@ function calculateUpgrade(value, upgrade, start, end = Infinity, mode, iteration
const maxLevelAffordableActual = maxLevelAffordable.sub(start).add(1).max(0);
return [maxLevelAffordableActual, cost];
}
function decimalToJSONString(n) {
n = E(n);
return `${n.sign}/${n.mag}/${n.layer}`;
}
function upgradeToCacheNameSum(start, end) {
return `sum/${decimalToJSONString(start)}/${decimalToJSONString(end)}}`;
}
function upgradeToCacheNameEL(level) {
return `el/${decimalToJSONString(level)}`;
}
var UpgradeData = class {
/**
* Constructs a new upgrade object with an initial level of 1 (or the provided level)
Expand All @@ -5654,7 +5645,7 @@ __decorateClass([
var UpgradeStatic = class _UpgradeStatic {
static {
/** The default size of the cache. Should be one less than a power of 2. */
this.cacheSize = 63;
this.cacheSize = 15;
}
/** @returns The data of the upgrade. */
get data() {
Expand All @@ -5677,7 +5668,7 @@ var UpgradeStatic = class _UpgradeStatic {
* Constructs a new static upgrade object.
* @param init - The upgrade object to initialize.
* @param dataPointer - A function or reference that returns the pointer of the data / frontend.
* @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}
* @param cacheSize - The size of the cache. Should be one less than a power of 2. See {@link cache}. Set to `0` to disable caching.
*/
constructor(init, dataPointer, cacheSize) {
const data = typeof dataPointer === "function" ? dataPointer() : dataPointer;
Expand All @@ -5693,33 +5684,51 @@ var UpgradeStatic = class _UpgradeStatic {
this.el = init.el;
this.defaultLevel = init.level ?? E(1);
}
getCached(type, start, end) {
if (type === "sum") {
return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0)));
} else {
return this.cache.get(upgradeToCacheNameEL(start));
}
}
setCached(type, start, endOrStart, costSum) {
const data = type === "sum" ? {
id: this.id,
el: false,
start: E(start),
end: E(endOrStart),
cost: E(costSum)
} : {
id: this.id,
el: true,
level: E(start),
cost: E(endOrStart)
};
if (type === "sum") {
this.cache.set(upgradeToCacheNameSum(start, endOrStart), data);
} else {
this.cache.set(upgradeToCacheNameEL(start), data);
}
return data;
}
// /**
// * Gets the cached data of the upgrade.
// * @param type - The type of the cache. "sum" or "el"
// * @param start - The starting level of the upgrade.
// * @param end - The ending level or quantity to reach for the upgrade.
// * @returns The data of the upgrade.
// */
// public getCached (type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined;
// public getCached (type: "el", start: ESource): UpgradeCachedEL | undefined;
// public getCached (type: "sum" | "el", start: ESource, end?: ESource): UpgradeCachedEL | UpgradeCachedSum | undefined {
// if (type === "sum") {
// return this.cache.get(upgradeToCacheNameSum(start, end ?? E(0)));
// } else {
// return this.cache.get(upgradeToCacheNameEL(start));
// }
// }
// /**
// * Sets the cached data of the upgrade.
// * @param type - The type of the cache. "sum" or "el"
// * @param start - The starting level of the upgrade.
// * @param end - The ending level or quantity to reach for the upgrade.
// * @param cost - The cost of the upgrade.
// */
// public setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum;
// public setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL;
// public setCached (type: "sum" | "el", start: ESource, endOrStart: ESource, costSum?: ESource): UpgradeCachedEL | UpgradeCachedSum {
// const data = type === "sum" ? {
// id: this.id,
// el: false,
// start: E(start),
// end: E(endOrStart),
// cost: E(costSum),
// } : {
// id: this.id,
// el: true,
// level: E(start),
// cost: E(endOrStart),
// };
// if (type === "sum") {
// this.cache.set(upgradeToCacheNameSum(start, endOrStart), data as UpgradeCachedSum);
// } else {
// this.cache.set(upgradeToCacheNameEL(start), data as UpgradeCachedEL);
// }
// return data as UpgradeCachedEL | UpgradeCachedSum;
// }
};

// src/classes/Currency.ts
Expand Down Expand Up @@ -6538,7 +6547,7 @@ var DataManager = class {
const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`);
let version;
try {
version = "8.3.0";
version = "8.4.0";
} catch (error) {
version = "8.3.0";
}
Expand Down
Loading

0 comments on commit 2702acd

Please sign in to comment.