Coder Social home page Coder Social logo

yetanotherclown / yetanothernet Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 2.0 2.39 MB

A Data-Driven Networking Library, inspired by Bevy_Renet & BridgeNet2, made for ECS.

Home Page: https://yetanotherclown.github.io/YetAnotherNet/

License: MIT License

Lua 99.39% Shell 0.61%
ecs luau matter networking roblox roblox-library roblox-lua roblox-ts

yetanothernet's Introduction

YetAnotherNet โ€” A Data-Driven Networking Library, inspired by Bevy_Renet & BridgeNet2, made for ECS.

Quick Start

About

YetAnotherNet is a Networking Library for Roblox, which wraps around Roblox's RemoteEvents to improve developer experience, offer efficient networking, and provide other tools, utilities, and features relating to Networking on Roblox.

Features

  • Complete Typechecking & Intellisense
  • No Overhead from RemoteEvents
  • Ordered Networking
  • Middleware
  • Data-Driven Design
  • Simple Integration & API
  • Hot-reloading Support with Rewire

Data-driven by design

One thing that separates YetAnotherNet from other networking libraries on Roblox is this key design choice. YetAnotherNet was made to work with ECS, a Data-driven approach to game design, which has influenced the design of the library largely and makes it unique from the rest.

With inspiration from Bevy_Renet, a Networking crate for use with the Bevy ECS in Rust, and another networking library on Roblox, BridgeNet2, YetAnotherNet pushes to provide similar functionality to these two libraries for ECS on Roblox.

Why go for Data-Driven Design?

Data-driven design opposes Event-driven design, which is what you can commonly see on Roblox, such as RemoteEvents themselves. Event-driven design has it's woes, which is why we opt for ECS and generally Data-driven design.

Event-driven design is sensitive to ordering, this makes it difficult to know when you might get data from an event. To solve this, YetAnotherNet does not use Events, it encourages you to query and send data in an ordered manner frame-by-frame, preferably with ECS.

Since it's encouraged to use ECS with YetAnotherNet, though not required, we suggest reading Matter โ€” Why ECS? by Evaera.


To-do

Tasks to complete before version 1.0.0 is released.

  • Basic Functionality
  • Stable Core API
  • Strict Typing
  • Unreliable Channel
  • Middleware
  • Typescript Support
  • Unit + Integration Tests w/ Jest
  • Rate limiting
  • Internal Use of Buffers
  • Debugger

Other Tasks

  • Minimal Example
  • ECR Setup Guide
  • ECR Example
  • Docs Page for Technical Details

Basic Usage

Tip

See full documentation on How to Use Routes and How to Setup with Matter on the Documentation Site.

Setup

Basic Setup for Routes

local Net = require("Net.luau")

local Route = Net.Route
type Route<U...> = Net.Route<U...>;

-- You can specify the type(s) between the <> for Typechecking + Intellisense
local ExampleRoute: Route<any> = Route.new()

return {
    ExampleRoute = ExampleRoute
}

Example Use

Example of how to use YetAnotherNet in a Matter System

local routes = require("routes.luau")
local ExampleRoute = routes.ExampleOne

local function exampleSystem(world)
    -- Query through every networking call that frame on the Server
    for i, player, ...data in ExampleRoute:query() do
        -- Do something
    end

    -- Query through every networking call that frame on the Client
    for i, _, ...data in ExampleRoute:query() do
        -- Do something
    end

    -- Send data from the Client to the Server
    ExampleRoute:send(...)

    -- Send data to a Client from the Server
    ExampleRoute:send(...):to(Player)
end

Installation

Wally

Add YetAnotherNet to your project with Wally by adding the following to your wally.toml file:

[dependencies]
Net = "yetanotherclown/[email protected]"

Note

Wally does not export types automatically, if you wish to use Strict Typing with YetAnotherNet, install Wally Package Types with Aftman.

NPM for Roblox Typescript

You can find YetAnotherNet on NPM, or install it with the command line:

npm i @rbxts/yetanothernet

Building

To build yourself with Rojo, use:

rojo build -o "Net.rbxm"

For more help, check out the Rojo documentation.

yetanothernet's People

Contributors

atk422 avatar integralsgetyouarea avatar littletsu avatar yetanotherclown avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

yetanothernet's Issues

Rojo live-syncing breaks Net

The issue is that the parent of the remote event is under the script, which Rojo overwrites.
To fix this simply move the replicated event outside of the script and somewhere where Rojo can't touch it.
I'll draft a PR tomorrow unless someone else wants to do this.

Add Roblox-TS Types

The Matter ECS has a large user base of Typescript users, we should provide them an opportunity to use Net as well.

Personally, I have not ever used Typescript and currently do not have time to learn it and work on Roblox-TS Types for Net, this issue exists in case anyone would like to help out with Roblox-TS Types. Resources on the process would be appreciated, I'd be interested in supporting Roblox-TS myself in the future.

Matter setup routes does not compile in roblox-ts

In the typescript documentation for Matter setup the following routes.ts is recommended:

import { Route } from "@rbxts/yetanothernet";

const defaultConfiguration = {
  Channel: "Reliable",
  Event: "default",
}

// Replicate Matter Components
const MatterReplication = new Route(defaultConfiguration);

// Signal that the Player has loaded
const PlayerLoaded: Route<[boolean]> = new Route(defaultConfiguration);

export = {
  MatterReplication: MatterReplication,
  PlayerLoaded: PlayerLoaded,
}

This results in the following error by default: Argument of type '{ Channel: string; Event: string; }' is not assignable to parameter of type 'Configuration'. Types of property 'Channel' are incompatible. Type 'string' is not assignable to type '"Reliable" | "Unreliable" | undefined'.

I fixed this by moving the Configuration type to the Net namespace

declare namespace Net {
    const server: "NET_SERVER";
    
    type Configuration = {
        Channel: "Reliable" | "Unreliable" | undefined,
        Event: string | undefined,
    }
...

and make the defaultConfiguration use this type

import { Route, Configuration } from "@rbxts/yetanothernet";

const defaultConfiguration: Configuration = {
	Channel: "Reliable",
	Event: "default",
};

// Replicate Matter Components
const MatterReplication = new Route(defaultConfiguration);

// Signal that the Player has loaded
const PlayerLoaded: Route<[boolean]> = new Route(defaultConfiguration);

export = {
	MatterReplication: MatterReplication,
	PlayerLoaded: PlayerLoaded,
};

Incorrect `routes` type in `Net.start` and `Net.createHook` for roblox-ts

As of now the definition for Net.start is the following:

    function start<T extends Array<any>>(loop: any, routes: Array<Route<T>>): void

This expects an Array, which only allows numeric indexes unlike Luau's tables, it also forces all routes to be the same type T and because of this the recommended matter setup route definition cannot be used:

import { Route } from "@rbxts/yetanothernet";

const defaultConfiguration = {
  Channel: "Reliable",
  Event: "default",
}

// Replicate Matter Components
const MatterReplication = new Route(defaultConfiguration);

// Signal that the Player has loaded
const PlayerLoaded: Route<[boolean]> = new Route(defaultConfiguration);

export = {
  MatterReplication: MatterReplication,
  PlayerLoaded: PlayerLoaded,
}

I fixed this by turning the routes Array in the type into an object and removing the type parameter and for this to work we also have to give the Route a default value:

    // on index.d.ts Route definition
    class Route<T extends Array<any> = Array<any>> {
        public constructor(configuration: Configuration | null);
    // on index.d.ts start definition
    function start(loop: any, routes: {[index: string]: Route}): void

``Route:query()`` return values are not typed when using generalized iteration

This is a Luau bug, but since this affects Net this issue will serve as a guide for how to workaround this and provide information on it.
If you would like to track the Luau Issue, it is here luau-lang/luau#819.

In order to workaround this bug, you can do this when querying:

for pos, sender, str, num in route:query():__iter() do
     -- Do something
end

In the meantime, there is nothing we can do to fix this for Net, you will either have to use the workaround or wait until the new Luau Type Solver comes out.

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.