GithubHelp home page GithubHelp logo

hastearcade / snowglobe Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 1.0 6.79 MB

A JS port of CrystalOrb

License: Other

JavaScript 0.77% TypeScript 98.99% Shell 0.24%
netcode networking multiplayer game prediction reconciliation rollback

snowglobe's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

typeofalex

snowglobe's Issues

Performance profling

Do some surface-level performance profiling to get a sense for how many concurrent clients snowglobe can support in a medium-sized simulation.

Evaluate `Cloneable` trait

  • Can we remove the concept of Cloneable all-together by enforcing snapshots and commands be JSON-serializable?
  • Can we eliminate any existing clones to reduce memory usage/GC events.

`Stage` and `ActiveClient` ergonomics

Getting the ActiveClient instance from a client is a little hairy and error-prone. You have to do stuff like:

if (client.state() === StageState.Ready) {
  client.stage().ready!...
}

Where we have to manually assert the presence of the ready property. We could take advantage of a union type/type narrowing to make this more intuitive and "safer".

Furthermore, getting deeply nested properties off of ActiveClient and company can be really nasty, e.g.

mockClientServer.client1.stage().ready!.timekeepingSimulations.stepper
          .lastReceivedSnapshotTimestamp!

By the looks of it, we didn't port over a few methods that would make this a bit cleaner, like this one from ready.rs:

    pub fn last_received_snapshot_timestamp(&self) -> &Option<Timestamp> {
        &self
            .0
            .borrow()
            .timekeeping_simulations
            .last_received_snapshot_timestamp
    }

The equivalent in snowglobe would let us rewrite the above TypeScript snippet as:

mockClientServer.client1.stage().ready!.lastReceivedSnapshotTimestamp()

Evaluate `Timestamped` decisions

I made a impulse decision to make Timestamped entities not "wrapped" like in CrystalOrb. Instead, snowglobe mutates the original object by adding a property with a Symbol key ($timestamp`). At the time, this seemed like it'd be more memory-efficient but may not be ideal.

`comparableRangeWithMidpoint` performance

This function originally tanked performance when we were still using objects for timestamps. I think it's still pretty slow. We should take a look at how it's used to see if we can replace it with a simple comparison, or consider memoizing the result to prevent excess memory allocations and CPU usage.

OOP best practices

Do a pass over our modules to ensure we're using access modifiers where necessary, using member initialization patterns consistently, naming variables consistently, etc.

Evaluate message types

CrystalOrb is able to generate unique type identifiers for network messages (clock-sync events, snapshots, commands) using some kind of reflection/metaprogramming feature that we don't have in TypeScript. I quickly decided to categorize message types using integer ids using a function called makeTypeId.

  • We should make sure this is the right way to go about categorizing message, and if so
  • We should expose these type ids to consumers, maybe as an enum.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.