Skip to content

Commit

Permalink
refactor(back): renaming Tickrates to TickIntervals, fround 32bit FP …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
tsa96 committed Dec 20, 2024
1 parent b275e6d commit d42eff3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
RunValidationError,
RunValidationErrorType as ErrorType,
Segment,
Tickrates,
TickIntervals,
TrackType,
RunSplits
} from '@momentum/constants';
Expand Down Expand Up @@ -260,7 +260,7 @@ export class RunProcessor {
if (header.gamemode !== session.gamemode)
throw new RunValidationError(ErrorType.BAD_META);

if (!approxEq(header.tickInterval, Tickrates.get(session.gamemode)))
if (header.tickInterval !== TickIntervals.get(session.gamemode))
throw new RunValidationError(ErrorType.OUT_OF_SYNC);

const {
Expand Down
2 changes: 1 addition & 1 deletion libs/constants/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export * from './enums/leaderboard-type.enum';
export * from './enums/killswitch.enum';
export * from './maps/gamemodes.map';
export * from './maps/map-credit-name.map';
export * from './maps/tickrates.map';
export * from './maps/tick-intervals.map';
export * from './maps/map-status-name.map';
export * from './maps/incompatible-gamemodes.map';
export * from './maps/map-status-change-rules.map';
Expand Down
32 changes: 32 additions & 0 deletions libs/constants/src/maps/tick-intervals.map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Gamemode } from '../enums/gamemode.enum';
import { float } from '../types/utils/numeric.type';

/**
* The tick intervals (inverse of tickrate) each gamemode uses. In Source
* they're floats (32-bit), so take care to use f32 rounded values in JS.
*
* @see (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
*
* | Tick Rate | Tick Interval |
* |-----------|---------------|
* | 66 | 0.015 |
* | 100 | 0.01 |
* | 125 | 0.008 |
* | 128 | 0.0078125 |
*/
// prettier-ignore
export const TickIntervals: ReadonlyMap<Gamemode, float> = new Map([
[Gamemode.AHOP, Math.fround(0.015)],
[Gamemode.BHOP, Math.fround(0.01)],
[Gamemode.BHOP_HL1, Math.fround(0.004)],
[Gamemode.CLIMB_MOM, Math.fround(0.01)],
[Gamemode.CLIMB_KZT, Math.fround(0.01)],
[Gamemode.CLIMB_16, Math.fround(0.01)],
[Gamemode.CONC, Math.fround(0.01)],
[Gamemode.DEFRAG_CPM, Math.fround(0.008)],
[Gamemode.DEFRAG_VQ3, Math.fround(0.008)],
[Gamemode.DEFRAG_VTG, Math.fround(0.008)],
[Gamemode.RJ, Math.fround(0.015)],
[Gamemode.SJ, Math.fround(0.015)],
[Gamemode.SURF, Math.fround(0.015)]
]);
25 changes: 0 additions & 25 deletions libs/constants/src/maps/tickrates.map.ts

This file was deleted.

3 changes: 1 addition & 2 deletions libs/formats/replay/src/replay-reader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ describe('Replay Reader', () => {
gamemode: Gamemode.BHOP,
playerSteamID: 76561198039308694n,
playerName: 'fingerprince',
tickInterval: expect.any(Number),
tickInterval: Math.fround(0.01),
trackType: TrackType.MAIN,
trackNum: 1,
runTime: 30.584999316371977
};

const header = readHeader(buffer);
expect(header).toEqual(expectedHeader);
expect(header.tickInterval).toBeCloseTo(0.01, 5);
});

it('should throw ReplayReadError on invalid buffer', () => {
Expand Down
4 changes: 2 additions & 2 deletions libs/test-utils/src/utils/run-tester.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
Gamemode,
RunSplits,
Tickrates,
TickIntervals,
TrackType
} from '@momentum/constants';
import { sleep } from '@momentum/util-fn';
Expand Down Expand Up @@ -207,7 +207,7 @@ export class RunTester {
mapName: this.props.mapName,
mapHash: this.props.mapHash,
gamemode: this.props.gamemode,
tickInterval: Tickrates.get(this.props.gamemode),
tickInterval: TickIntervals.get(this.props.gamemode),
playerSteamID: this.props.steamID,
playerName: this.props.playerName,
trackType: this.props.trackType,
Expand Down

0 comments on commit d42eff3

Please sign in to comment.