Skip to content

Commit f10a8b0

Browse files
authored
Merge pull request #104 from TimonPost/docs
Added styleguides and release notes doc also improved readme.md
2 parents 2dc7017 + 9ecfd7b commit f10a8b0

6 files changed

Lines changed: 136 additions & 36 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ authors = [
99
description = "A simple semi-reliable UDP protocol for multiplayer games"
1010
keywords = ["gamedev", "networking", "udp", "amethyst"]
1111
categories = ["game-engines", "network-programming"]
12+
exclude = ["examples/*", "docs/*", "benches/*"]
1213

1314
readme = "README.md"
1415
license = "MIT/Apache-2.0"

README.md

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,80 @@
1515
[s6]: https://tokei.rs/b1/github/amethyst/laminar?category=code
1616
[s7]: https://codecov.io/gh/amethyst/laminar/branch/master/graphs/badge.svg
1717

18-
A UDP-based protocol that provides partial reliability. Coming soon!
18+
This library implements some TCP-like features on top of an UDP-socket.
19+
It will provide a lightweight message-based interface with certain guarantees like reliability, fragmentation congestion monitoring.
1920

20-
## Note
21+
Laminar was designed to be used in the [Amethyst][amethyst] game engine and is loosely based on articles from [gaffer on games](https://gafferongames.com/).
2122

22-
This library is not yet stable. It is experimental and things may change frequently.
23+
[amethyst]: https://github.com/amethyst/amethyst
2324

2425
## Table of contents:
25-
- [Useful links](https://github.com/amethyst/laminar#useful-links)
26-
- [Features](https://github.com/amethyst/laminar#features)
27-
- [Examples](https://github.com/amethyst/laminar#examples)
28-
- [Udp](https://github.com/amethyst/laminar#udp)
29-
- [Notice](https://github.com/amethyst/laminar#notice)
30-
- [Contributing](https://github.com/amethyst/laminar#contributing)
31-
- [Authors](https://github.com/amethyst/laminar/#authors)
26+
- [Useful links](#useful-links)
27+
- [Features](#features)
28+
- [Getting Started](#getting-stated)
29+
- [Examples](#examples)
30+
- [Notice](#notice)
31+
- [Contributing](#contribution)
32+
- [Authors](#authors)
3233
- [License](#license)
3334

35+
## Features
36+
These are the features this crate provides:
37+
38+
- UDP-based protocol
39+
- Connection tracking
40+
- Automatic Fragmentation
41+
- Unreliable and Reliable packets
42+
- Protocol versioning
43+
- RTT estimation
44+
- Link conditioner to simulate packet loss and latency
45+
- Well tested by integration tests and unit tests
46+
- Good error handling
47+
- Benchmarks
48+
49+
## Getting Stated
3450
Add the laminar package to your `Cargo.toml` file.
3551

3652
```toml
3753
[dependencies]
38-
laminar = "0.0.0"
54+
laminar = "0.1"
3955
```
40-
And import the laminar modules you want to use.
4156

42-
```rust
43-
extern crate laminar;
44-
45-
// this module contains all socket related logic.
46-
use laminar::net::{UdpSocket, SocketAddr, NetworkConfig, Connection, Quality};
47-
// this module contains packet related logic.
48-
use laminar::packet::{Packet};
49-
```
50-
51-
## Useful Links
57+
### Useful Links
5258

5359
- [Documentation](https://docs.rs/laminar/).
54-
- [Cargo Page](https://crates.io/crates/laminar)
60+
- [Crates.io](https://crates.io/crates/laminar)
5561
- [Examples](https://github.com/amethyst/laminar/tree/master/examples)
56-
57-
## Features
58-
These are the features from this crate:
59-
60-
- Semi-reliable UDP
61-
- Fragmentation
62-
- RTT estimation
63-
- Virtual connection management.
62+
- [Contributing](https://github.com/amethyst/laminar/blob/master/docs/CONTRIBUTING)
6463

6564
## Examples
66-
These are some basic examples demonstrating how to use this crate. See [examples](https://github.com/amethyst/laminar/tree/master/examples) for more.
65+
These are some basic examples demonstrating how to use this crate.
66+
Please checkout our [examples](https://github.com/amethyst/laminar/tree/master/examples) for more.
6767

68-
### Udp API | [see more](https://github.com/amethyst/laminar/blob/master/examples/udp.rs)
68+
### UDP API | [see more](https://github.com/amethyst/laminar/blob/master/examples/udp.rs)
6969
This is an example of how to use the UDP API.
7070

7171
_Send packets_
7272

7373
```rust
74+
use laminar::{DeliveryMethod, Packet};
75+
use laminar::net::{UdpSocket, NetworkConfig};
76+
7477
// Create the necessarily config, you can edit it or just use the default.
7578
let config = NetworkConfig::default();
7679

7780
// Setup an udp socket and bind it to the client address.
7881
let mut udp_socket = UdpSocket::bind("127.0.0.1:12346", config).unwrap();
7982

83+
// our data
84+
let bytes = vec![...];
85+
8086
// Create a packet that can be send with the given destination and raw data.
81-
let packet = Packet::new(destination, vec![1,2,3]);
87+
let packet = Packet::new(destination, bytes, DeliveryMethod::Unreliable);
88+
89+
// Or we could also use the function syntax for more clarity:
90+
let packet = Packet::unreliable(destination, bytes);
91+
let packet = Packet::reliable_unordered(destination, bytes);
8292

8393
// Send the packet to the endpoint we earlier placed into the packet.
8494
udp_socket.send(packet);
@@ -87,13 +97,15 @@ udp_socket.send(packet);
8797
_Receive Packets_
8898

8999
```rust
100+
use laminar::net::{UdpSocket, NetworkConfig};
101+
use std::net::SocketAddr;
90102
// Create the necessarily config, you can edit it or just use the default.
91103
let config = NetworkConfig::default();
92104

93105
// Setup an udp socket and bind it to the client address.
94106
let mut udp_socket = UdpSocket::bind("127.0.0.1:12345", config).unwrap();
95107

96-
// Start receiving (blocks the current thread)
108+
// Start receiving (blocks the current thread), use `udp_socket.set_nonblocking()` for not blocking the current thread.
97109
let result = udp_socket.recv();
98110

99111
match result {
@@ -124,6 +136,12 @@ match result {
124136

125137
We want to give credit to [gaffer on games](https://gafferongames.com/) as we have used his guide to building a game networking protocol to build this library.
126138

139+
## Note
140+
141+
This library is not fully stable yet.
142+
Although version 0.1.0 is released we might have to change some of the existing API.
143+
Laminar is used in [Amethyst-Network](https://github.com/amethyst/amethyst/tree/master/amethyst_network), you could give that a look if you want to see some more advanced use-cases.
144+
127145
## Contribution
128146

129147
Unless you explicitly state otherwise, any contribution intentionally submitted

docs/CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Change Log
2+
This document contains information about the releases of this crate.
3+
4+
## [0.1.0] - 2018-11-12
5+
The Networking team is happy to announce the release of `0.1.0`` of the [laminar crate](https://github.com/amethyst/laminar).
6+
It provides UDP networking modified for the needs of game networking.
7+
Most of the techniques used were published and detailed by [Glenn Fiedler](https://gafferongames.com/).
8+
We’d like to extend a special thanks to him and his articles.
9+
10+
### Added
11+
12+
- UDP-based protocol
13+
- Automatic Fragmentation
14+
- RTT estimation
15+
- Connection tracking
16+
- Unreliable and Reliable sending of packets
17+
- Protocol version monitoring
18+
- A link conditioner to simulate packet loss and latency
19+
- Good error handling with **zero** panics
20+
- Well tested by integration and unit tests
21+
- Benchmarks

docs/CONTRIBUTING.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Workflow
2+
3+
As a team, we adopted the following the workflow agreements. When we begin work on the amethyst_network crate, we’ll use the same agreements. They are focused on maintaining a high level of quality in the code, and for working with a highly distributed team. We’re including them here as some of the other teams may find them of use.
4+
5+
- All warnings produced by `cargo test` are treated as errors by the CI/CD system
6+
- All `clippy` warnings are treated as errors by the CI/CD system
7+
- We use `kcov` to track our code coverage; we do not have a required minimum, rather we use this as a potential indicator of issues
8+
- We included sample code about using the library
9+
- Setting up a benchmarking framework so we can track regressions
10+
- Unit and integration tests, as well as release testing with docker-compose
11+
12+
## Style Guidelines
13+
14+
As a team, we (eventually) agreed on a coherent style for all our work. See this [document](https://github.com/amethyst/laminar/blob/master/docs/CONTRIBUTING.md#code-style) for more information.
15+
Some of the most helpful ones have been:
16+
17+
- Keep PRs small, preferably under 200 lines of code when possible
18+
- Comments should explain why, not what
19+
- You must provide comments for public API
20+
- No hard-coded values
21+
- No panics nor unwraps in non-test code
22+
- `rustfmt` stable release must be used
23+
- `rustfmt` should be done as its own PR, to avoid generating giant PRs that are impossible to review
24+
- We make use of the [forking workflow](https://nl.atlassian.com/git/tutorials/comparing-workflows/forking-workflow)
25+
26+
## Code style
27+
28+
Some code guidelines to keep in mind when contributing to laminar or amethyst-networking
29+
1. Comments
30+
- Comment all code you’ve added. Things you should comment: types, methods/functions public fields of structs.
31+
- Calculations should be documented. Whether it would be in a PR or code. But it must be clear what is done.
32+
- Public things should get docstring comments using `///`. Non-public things may use `//` comments
33+
- Keep comments small
34+
- Don’t create unnecessary comments. They must add value
35+
- Comments should explain the “why” not the “what”
36+
2. Hard Coding
37+
- Don't hard code values anywhere
38+
- Use the ‘NetworkConfig’ type for common network settings, use consts or parameter input
39+
- Use of lazy_static is acceptable but first make sure you can’t fix the issue in other ways
40+
3. Code markup
41+
- Keep files small. Better have small files with small pieces of logic than having one file with 1000 lines of logic with multiple types/structs etc. Note that I speak of logic, tests not included
42+
- No panics/unwraps in the main codebase, but they are accepted in tests

docs/FEATURES.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Features
2+
These are all the features we have and don't have.
3+
## Added
4+
5+
* [x] Fragmentation
6+
* [x] Unreliable packets
7+
* [x] Reliable unordered packets
8+
* [x] Fragmentation
9+
* [x] Rtt estimations
10+
* [x] Protocol version monitoring
11+
* [x] Virtual connection management
12+
13+
## Planned
14+
15+
* [ ] Reliable Ordered packets
16+
* [ ] Unreliable Ordered packets
17+
* [ ] Sequenced packets
18+
* [ ] Cryptography

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Laminar semi-reliable UDP protocol for multiplayer games. This library implements wraps around a UDP
2-
//! and provides light weight stream based interface that provides certain guarentees like reliablity.
2+
//! and provides light weight stream based interface that provides certain guarantees like reliability.
33
//!
44
//! Laminar was designed to be used within the [Amethyst][amethyst] game engine.
55
//!

0 commit comments

Comments
 (0)