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

game-space

v0.0.1

Published

GameSpace is a fast spatial database optimized for games with a large number of moving entities. It supports indexing and querying over combinations of arbitrary oject fields and spatial bounding boxes. It's an ideal backbone for *broad phase collision de

Downloads

19

Readme

Motivation

GameSpace is a fast spatial database optimized for games with a large number of moving entities. It supports indexing and querying over combinations of arbitrary oject fields and spatial bounding boxes. It's an ideal backbone for broad phase collision detection systems.

Central to the design of GameSpace and it's API is the minimization of allocations - this allows for tens of thousands of queries per second while minimizing garbage collecor invocations and reducing game stutter.

Installation

npm install game-space

Usage

Vision Culling

Often, you'll want to implement a camera system in a game that only renders objects that are within the view of a virtual "camera". We can do that easily with GameSpace.

const { GameSpace, GameEntity } = require("game-space");

// create a basic enemy class with hp and attack
// Note that GameSpace provides the GameEntity base class to get you started,
// but you can easily write your own.
class Enemy extends GameEntity {
  constructor(hp, attack) {
    this.hp = hp;
  }
}

// create a basic 100 x 100 unit camera
const camera = new GameEntity({ top: 0, left: 0, width: 100, height: 100 });

// construct or gamespace db
const space = new GameSpace();

// create some enemies and insert them into the db
[
  { left: 10, top: 20, width: 10, height: 10, hp: 5, attack: 10 },
  { x: 100, y: 30, width: 10, height: 10, hp: 3, attack: 7 }
].map(enemy => new Enemeny(enemy)).forEach(enemy => {
  space.insert(enemy);
});

// create an array to hold results of subsequent queries
// this allows us to reduce allocations and keep GC stutter down
const visibleEntities = [];

// rendering / game loop, you really want to use requestAnimationFrame() here, but we're keeping things simple
while(true) {
  space.search({ bounds: camera.getSpatialHandle() }, visibleEntities);
  visibleEntities.forEach(entity => drawEntity(entity)); // you obviously need to implement drawEntity yourself
}

Full API Docs

The full public API is documented in JSDoc comments in /src/game-space.js

Developing

Running tests

npm run test