npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@deltasnare/core

v1.0.2

Published

Single-chunk core piece of the Deltasnare engine

Downloads

2

Readme

Core module of Deltasnare, contains basic tick management and executes the delta function.

Usage

const core = require('@deltasnare/core')

// const delta = function (state, inputs, options) { ... }
// const options = { ... }

const chunk = core(delta, options)

chunk.setControl(1, {
  'deltasnare/peers': ['foo']
})
chunk.setInput(3, 'foo', 'bar')
chunk.setCurrent(4)

chunk.getTick(4)

The Deltasnare core is built around the delta function, a simple, repeatable representation of the gamecode. It holds all future and past ticks for a given window size, along with their inputs and control messages. It can be created by calling the exported function

core(delta, options)

with the following parameters:

  • delta: Delta function, describes the gamecode
  • options: An object, specifiying several parameters to the core. It has the following fields:
    • environment: Environment object, it is passed to the delta function.
    • maskSize: Number of bits truncated from floating point numbers, used to mask floating point error. Defaults to 4, maximum supported value is 16. Passed to the normalizer.
    • startingPoint: ID of first tick, 0 by default.
    • state: Initial state at the starting tick. Either this or sync must be provided.
    • sync: The synchronization data, contains multiple ticks. Either this or state must be provided.
    • windowSize: Deltasnare window size, defines how many ticks are stored forward and backwards. 128 by default, more details here.

The returned object is the core, with the following methods and properties:

getTick(tickID)

Returns a tick object representing the tick with the given ID. If the requested tick is in the future or older than windowSize a RangeError is thrown.

Due to lazy evaluation, this is where the delta function is ran if anything invalidated the currently calculated tick.

setInput(tickID, peer, input)

Sets the input for a given peer and tick. Allowed range is windowSize forward and backward from the current tick.

setControl(tickID, control)

Sets the server-defined control message for a specific tick, similarly to setInput()

setCurrent(tickID)

Sets the current tickID. Allowed range is windowSize forward from current.

current

ID of the current tick. Read-only.

environment

The environment object passed to the delta function.

windowSize

The window size for the current core. Read-only.

The Delta Function

The delta is the representation of the gamecode. It receives the game state, the peer inputs, and the options, and returns the next state. It must be deterministic, repeatable, across machines. It has the following form:

delta(state, inputs, options)

where the parameters are the following:

state

This is the game state. It is a custom object, entirely user-defined. Must be JSON-serializable, and safe to transmit over the network (although it is only done so on synchronization).

inputs

An object, where the key-value pairs correspond to peerID and the input of the given peer. Inputs are user-defined, although the same restrictions apply as on the state.

options

An object, containing the following fields:

  • control: control variable from the server. User defined, with the same restrictions as on state.
  • environment: the environment variables passed to the delta
  • previous: the full previous tick, in case it's required
  • seed: a seed that is derived from an earlier tick, it is safe to use for pseudorandom operations
  • tickId: the ID of the current tick