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

multiplayer

v0.1.1

Published

Generic-ish multiplayer support for nodejs and browsers

Downloads

20

Readme

Multiplayer.js

A framework for multiplayer physics simulations (read: games)

Changelog

Version 0.1 - First release, pretty mediocre API but it works. Version 0.1.1 - Remove a bunch of extraneous dependencies

Description

The main feature of multiplayer.js is lag compensation. Using interpolation, extrapolation and client-side prediction, the apparent effects of network latency are minimised.

Since every game is different, multiplayer.js doesn't mandate any particular transport protocol or simulation engine. The only requirement is to be able to provide it with a simple JSON representation of player states and of user input. These objects need to be passed back and forth to instances of Server and Client.

The environment running the Server is responsible for running the canonical game simulation (physics). It will need to take any user commands (inputs) and generate a new game state every frame.

The environment(s) running the Client are responsible for presenting the game state to a player (rendering), and for running a local simulation of the game in order to predict the player's movement during the time between receiving input and the server acknowledging that input.

Usage

npm install multiplayer

There will be a downloadable browser-only package soon, but for now the easiest way to include multiplayer.js in your browser code is to use browserify. Check the example out for more info.

How does it work?

A framestamp is a decimal value of form m.n, where:

  • m is an integer referring to the frame number
  • n is a decimal in the range 0.0 <= n < 1.0, referring to a fraction of a frame's time

ie: framestamp 10.20 means frame 10, 20% of the way to frame 11

On the server: Set a constant fps, where fpsInterval = 1 / fps Each time a player command comes in: Advance the player based on the framestamp given in the command NOTE client framestamp must be <= server framestamp player.updatePhysics(dt (in milliseconds), inputs) @time += dt @position += @velocity * dt @velocity = getVelocity(inputs) Every fpsInterval: Advance the world by fpsInterval (non-player-controlled entities) Prepare and broadcast a snapshot Include entity positions, and player framestamps

On the client: Assuming the client knows server fps... Each time a snapshot comes in: Add it to a list Each graphics frame: Check for a new snapshot If there is one, set oldSnap = nextSnap, nextSnap = new snapshot If there isn't and time < nextSnap.time, don't do anything If there isn't and time > nextSnap.time, set oldSnap = nextSnap, nextSnap = null Run client-side prediction Run through the list of input commands: Remove and skip if command's framestamp <= oldSnap.players[this].frameStamp Otherwise, advance the player, using the same physics code as on the server Interpolate/extrapolate all other entities' positions Trigger events (a/v effects) Render frame