UNPKG

@hastearcade/snowglobe

Version:

A TypeScript port of CrystalOrb, a high-level Rust game networking library

47 lines 1.96 kB
export function makeConfig(config = {}) { return Object.assign({ serverTimeDelayLatency: 0.3, blendLatency: 0.1, timestepSeconds: 1.0 / 60.0, clockSyncNeededSampleCount: 8, clockSyncRequestPeriod: 0.2, clockSyncAssumedOutlierRate: 0.2, maxTolerableClockDeviation: 0.1, snapshotSendPeriod: 0.1, updateDeltaSecondsMax: 0.25, timestampSkipThresholdSeconds: 1.0, fastForwardMaxPerStep: 10, tweeningMethod: TweeningMethod.Interpolated, serverCommandHistoryFrameBufferSize: 60, lagCompensateCommands: false // this variable is used to delay commands for "other" players in the system so they see everything in the past }, config); } export var TweeningMethod; (function (TweeningMethod) { TweeningMethod[TweeningMethod["MostRecentlyPassed"] = 0] = "MostRecentlyPassed"; TweeningMethod[TweeningMethod["Nearest"] = 1] = "Nearest"; TweeningMethod[TweeningMethod["Interpolated"] = 2] = "Interpolated"; })(TweeningMethod || (TweeningMethod = {})); export function shapeInterpolationT(method, t) { switch (method) { case TweeningMethod.MostRecentlyPassed: return Math.floor(t); case TweeningMethod.Nearest: return Math.round(t); case TweeningMethod.Interpolated: return t; } } export function serverTimeDelayFrameCount(config) { return Math.round(config.serverTimeDelayLatency / (1 / 60)); } export function clockSyncSamplesToDiscardPerExtreme(config) { return Math.ceil(Math.max((config.clockSyncNeededSampleCount * config.clockSyncAssumedOutlierRate) / 2, 1)); } export function clockSyncSamplesNeededToStore(config) { return (config.clockSyncNeededSampleCount + clockSyncSamplesToDiscardPerExtreme(config) * 2); } export function blendProgressPerFrame(config) { return config.timestepSeconds / config.blendLatency; } //# sourceMappingURL=lib.js.map