mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-05-20 13:47:12 +01:00
c42610c5ae
* Initial wiki system * wiki organization and spoilers * hide belly chems * move ads to tgui * add search * . * load screen * error screen * 8 * center * . * . * make this more realistic * tgui errro col * move search to top * . * non NT theme * logo to common * base custom theme * . * wip refactor * almost halfway * reworked wiki data * easy fix * get data fix * Material Page in tgui * catch null supply points * . * forward crash * reset pages * . * canvas prep * fix icon stacking * . * colored outlined images * fix sm datum * fix material names * subType prep * only on crash * fix null crash * . * fix solgov * clean hiding * . * implement catalog page * . * particle smasher page * I'm lazy * unfuck some sins * ore page * botany page * allergen list * allergen returns null too * slime injection var * slime core data * fixed warning * wip * proper data list for chems * pass is_slime as null * chems * split that * . * . * . * . * donation for bingle, some cleanup * return types * partially colord icons for chemistry * . * more sillies * donation page * thaler * needs some variation * . * this will crash until implemented * handle it * fix that * dismiss donation banner button * . * fix that * donating procs * donation stuff for comp * - * drink glass for drinks * illegal iconstate pass * fixes * . * nuke drink fix * . * . * . * Drink reagent fix * more cleanup * adjust * . * simple food * . * food list * sending nulls, removed flavor from recipes * . * . * get_donation_current added * . * missing key * . * duped recipes fixed * . * . * wiki food reagent recipes * double list add * properly forbid remaining bad reagent * hide this too * stacky * enable eslint const * fix typing * update that * use proper donation proc * printing fixes * grinding * . * beaker fill volume * plant ore and mat grinding results * duped recipes fixed, unit test tweak * yes this is terrible * . * . * . * chem analyzer tgui mode, some subsystem changes to support it * redoce * . * , * . * small fixes, missing reagent volume * push * sort * catalog entries unlocked by explo * new chem stuff * . * fix byond code * fix scroll tracking * comment * alphabetical * also this * . * fallback icon * . * ... * rel path * that too * to defines * organ to define * . * . * . --------- Co-authored-by: Willburd <7099514+Willburd@users.noreply.github.com> Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
/**
|
|
* Ghetto performance measurement tools.
|
|
*
|
|
* Uses NODE_ENV to remove itself from production builds.
|
|
*
|
|
* @file
|
|
* @copyright 2020 Aleksej Komarov
|
|
* @license MIT
|
|
*/
|
|
|
|
const FPS = 60;
|
|
const FRAME_DURATION = 1000 / FPS;
|
|
|
|
// True if Performance API is supported
|
|
const supportsPerf = !!window.performance?.now;
|
|
// High precision markers
|
|
const hpMarkersByName: Record<string, number> = {};
|
|
// Low precision markers
|
|
const lpMarkersByName: Record<string, number> = {};
|
|
|
|
/**
|
|
* Marks a certain spot in the code for later measurements.
|
|
*/
|
|
function mark(name: string, timestamp?: number): void {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (supportsPerf && !timestamp) {
|
|
hpMarkersByName[name] = performance.now();
|
|
}
|
|
lpMarkersByName[name] = timestamp || Date.now();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Calculates and returns the difference between two markers as a string.
|
|
*
|
|
* Use logger.log() to print the measurement.
|
|
*/
|
|
function measure(markerNameA: string, markerNameB: string): string | undefined {
|
|
if (process.env.NODE_ENV === 'production') return;
|
|
|
|
let markerA = hpMarkersByName[markerNameA];
|
|
let markerB = hpMarkersByName[markerNameB];
|
|
|
|
if (!markerA || !markerB) {
|
|
markerA = lpMarkersByName[markerNameA];
|
|
markerB = lpMarkersByName[markerNameB];
|
|
}
|
|
|
|
const duration = Math.abs(markerB - markerA);
|
|
|
|
return formatDuration(duration);
|
|
}
|
|
|
|
/**
|
|
* Formats a duration in milliseconds and frames.
|
|
*/
|
|
function formatDuration(duration: number): string {
|
|
const durationInFrames = duration / FRAME_DURATION;
|
|
|
|
return (
|
|
duration.toFixed(duration < 10 ? 1 : 0) +
|
|
'ms ' +
|
|
'(' +
|
|
durationInFrames.toFixed(2) +
|
|
' frames)'
|
|
);
|
|
}
|
|
|
|
export const perf = {
|
|
mark,
|
|
measure,
|
|
};
|