All Projects → nxrighthere → Netstack

nxrighthere / Netstack

Licence: mit
Lightweight toolset for creating concurrent networking systems for multiplayer games

Projects that are alternatives of or similar to Netstack

Valvesockets Csharp
Managed C# abstraction of GameNetworkingSockets library by Valve Software
Stars: ✭ 273 (+73.89%)
Mutual labels:  unity, gamedev, networking
Smmalloc Csharp
Blazing fast memory allocator designed for video games meets .NET
Stars: ✭ 81 (-48.41%)
Mutual labels:  multi-threading, gamedev, high-performance
Game Networking Resources
A Curated List of Game Network Programming Resources
Stars: ✭ 4,208 (+2580.25%)
Mutual labels:  unity, gamedev, networking
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-37.58%)
Mutual labels:  unity, gamedev, networking
Enet Csharp
Reliable UDP networking library
Stars: ✭ 464 (+195.54%)
Mutual labels:  unity, gamedev, networking
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+7350.96%)
Mutual labels:  unity, gamedev
Lance
Multiplayer game server based on Node.JS
Stars: ✭ 1,161 (+639.49%)
Mutual labels:  gamedev, networking
Projectfieldwarning
Project: Field Warning is a community-made RTS game centered around lethal regiment and division-scale warfare.
Stars: ✭ 86 (-45.22%)
Mutual labels:  unity, gamedev
Succ
Sexy and Utilitarian Code Configuration
Stars: ✭ 100 (-36.31%)
Mutual labels:  serialization, unity
Unity Package Tools
A set of developer tools to make it easier to create and distribute packages for the native Unity Package Manager.
Stars: ✭ 44 (-71.97%)
Mutual labels:  unity, gamedev
Forgenetworkingremastered
In short, Forge Networking is a free and open source multiplayer game (multi-user) networking system that has a very good integration with the Unity game engine. You wanna make a multiplayer game or real time multi-user application? This is the library for you.
Stars: ✭ 1,338 (+752.23%)
Mutual labels:  unity, networking
Mofuw
mofuw is *MO*re *F*aster, *U*ltra minimal *W*ebserver.
Stars: ✭ 107 (-31.85%)
Mutual labels:  multi-threading, high-performance
Netdynamics
Data-oriented networking playground for the reliable UDP transports
Stars: ✭ 65 (-58.6%)
Mutual labels:  gamedev, networking
Netmap Tutorial
Netmap tutorial at SIGCOMM 2017 and AsiaBSDCon 2018
Stars: ✭ 60 (-61.78%)
Mutual labels:  networking, high-performance
Batchman
This library for Android will take any set of events and batch them up before sending it to the server. It also supports persisting the events on disk so that no event gets lost because of an app crash. Typically used for developing any in-house analytics sdk where you have to make a single api call to push events to the server but you want to optimize the calls so that the api call happens only once per x events, or say once per x minutes. It also supports exponential backoff in case of network failures
Stars: ✭ 50 (-68.15%)
Mutual labels:  serialization, networking
Sock.lua
A Lua networking library for LÖVE games.
Stars: ✭ 121 (-22.93%)
Mutual labels:  gamedev, networking
Self Driving Vehicle
Simulation of self-driving vehicles in Unity. This is also an implementation of the Hybrid A* pathfinding algorithm which is useful if you are interested in pathfinding for vehicles.
Stars: ✭ 112 (-28.66%)
Mutual labels:  unity, gamedev
Reliablenetcode.net
A pure managed C# socket-agnostic reliability layer inspired by reliable.io and yojimbo
Stars: ✭ 122 (-22.29%)
Mutual labels:  gamedev, networking
Ecs
ECS for Unity with full game state automatic rollbacks
Stars: ✭ 151 (-3.82%)
Mutual labels:  unity, networking
Evolutionary Neural Networks On Unity For Bots
Neural networks + Genetic algorithm on unity
Stars: ✭ 38 (-75.8%)
Mutual labels:  unity, gamedev

alt logo

PayPal Coinbase

Lightweight toolset for creating concurrent networking systems for multiplayer games.

NetStack is self-contained and has no dependencies.

Modules:

  • Buffers
  • Quantization
  • Serialization
  • Threading
    • Array queue
      • Single-producer single-consumer first-in-first-out non-blocking queue
    • Concurrent buffer
      • Multi-producer multi-consumer first-in-first-out non-blocking queue
    • Concurrent pool
      • Self-stabilizing semi-lockless circular buffer
  • Unsafe
    • Fast memory copying

Building

By default, all scripts are compiled for .NET Framework 3.5. Define NET_4_6 directive to build the assembly for .NET Framework 4.6 or higher. Define NET_STANDARD_2_0 to build the assembly for .NET Core 2.1 or higher.

Define NETSTACK_SPAN to enable support for Span.

Define NETSTACK_BUFFERS_LOG to enable buffers logging.

Usage

Thread-safe buffers pool:
// Create a new array pool with a maximum size of 1024 bytes per array, 50 arrays per bucket
ArrayPool<byte> buffers = ArrayPool<byte>.Create(1024, 50);

// Rent buffer from the pool with a minimum size of 64 bytes, the returned buffer might be larger
byte[] buffer = buffers.Rent(64);

// Do some stuff
byte data = 0;

for (int i = 0; i < buffer.Length; i++) {
	buffer[i] = data++;
}

// Return buffer back to the pool
buffers.Return(buffer);
Concurrent objects pool:
// Define a message object
class MessageObject {
	public uint id;
	public byte[] data;
}

// Create a new objects pool with 8 objects in the head
ConcurrentPool messages = new ConcurrentPool<MessageObject>(8, () => new MessageObject());

// Acquire an object in the pool
MessageObject message = messages.Acquire();

// Do some stuff
message.id = 1;
message.data = buffers.Rent(64);

byte data = 0;

for (int i = 0; i < buffer.Length; i++) {
	message.data[i] = data++;
}

buffers.Return(message.data);

// Release pooled object
messages.Release(message);
Concurrent objects buffer:
// Create a new concurrent buffer limited to 8192 cells
ConcurrentBuffer conveyor = new ConcurrentBuffer(8192);

// Enqueue an object
conveyor.Enqueue(message);

// Dequeue object
MessageObject message = (MessageObject)conveyor.Dequeue();
Quantize float:
ushort quantizedSpeed = HalfPrecision.Quantize(speed);

float speed = HalfPrecision.Dequantize(quantizedSpeed);
Quantize vector:
// Create a new BoundedRange array for Vector3 position, each entry has bounds and precision
BoundedRange[] worldBounds = new BoundedRange[3];

worldBounds[0] = new BoundedRange(-50f, 50f, 0.05f); // X axis
worldBounds[1] = new BoundedRange(0f, 25f, 0.05f); // Y axis
worldBounds[2] = new BoundedRange(-50f, 50f, 0.05f); // Z axis

// Quantize position data ready for compact bit-packing 
QuantizedVector3 quantizedPosition = BoundedRange.Quantize(position, worldBounds);

// Read quantized data
Console.WriteLine("Quantized position - X: " + quantizedPosition.x + ", Y:" + quantizedPosition.y + ", Z:" + quantizedPosition.z);

// Dequantize position data ready for reconstruction after bit-packing
Vector3 dequantizedPosition = BoundedRange.Dequantize(quantizedPosition, worldBounds);
Quantize quaternion:
// Quantize rotation data ready for compact bit-packing 
QuantizedQuaternion quantizedRotation = SmallestThree.Quantize(rotation);

// Read quantized data
Console.WriteLine("Quantized rotation - M: " + quantizedRotation.m + ", A:" + quantizedRotation.a + ", B:" + quantizedRotation.b + ", C:" + quantizedRotation.c);

// Dequantize rotation data ready for reconstruction after bit-packing
Quaternion rotation = SmallestThree.Dequantize(quantizedRotation);
Serialize/deserialize data:
// Create a new bit buffer with 1024 chunks, the buffer can grow automatically if required
BitBuffer data = new BitBuffer(1024);

// Fill bit buffer and serialize data to a byte array
data.AddUInt(peer)
.AddString(name)
.AddBool(accelerated)
.AddUShort(speed)
.AddUInt(quantizedPosition.x)
.AddUInt(quantizedPosition.y)
.AddUInt(quantizedPosition.z)
.AddUInt(quantizedRotation.m)
.AddUInt(quantizedRotation.a)
.AddUInt(quantizedRotation.b)
.AddUInt(quantizedRotation.c)
.ToArray(buffer);

// Get a length of actual data in bit buffer for sending through the network
Console.WriteLine("Data length: " + data.Length);

// Reset bit buffer for further reusing
data.Clear();

// Deserialize data from a byte array
data.FromArray(buffer, length);

// Unload bit buffer in the same order
uint peer = data.ReadUInt();
string name = data.ReadString();
bool accelerated = data.ReadBool();
ushort speed = data.ReadUShort();
QuantizedVector3 position = new QuantizedVector3(data.ReadUInt(), data.ReadUInt(), data.ReadUInt());
QuantizedQuaternion rotation = new QuantizedQuaternion(data.ReadUInt(), data.ReadUInt(), data.ReadUInt(), data.ReadUInt());

// Check if bit buffer is fully unloaded
Console.WriteLine("Bit buffer is empty: " + data.IsFinished);
Bit-level operations:
/*
Bits   Min Dec    Max Dec     Max Hex     Bytes Used
0-7    0          127         0x0000007F  1 byte
8-14   128        1023        0x00003FFF  2 bytes
15-21  1024       2097151     0x001FFFFF  3 bytes
22-28  2097152    268435455   0x0FFFFFFF  4 bytes
29-32  268435456  4294967295  0xFFFFFFFF  5 bytes
*/

data.Add(9, 256);

uint value = data.Read(9);
Abstract data serialization with Span:
// Create a one-time allocation buffer pool
static class BufferPool {
	[ThreadStatic]
	private static BitBuffer bitBuffer;

	public static BitBuffer GetBitBuffer() {
		if (bitBuffer == null)
			bitBuffer = new BitBuffer(1024);

		return bitBuffer;
	}
}

// Define a networking message
struct MessageObject {
	public const ushort id = 1; // Used to identify the message, can be packed or sent as packet header
	public uint peer;
	public byte race;
	public ushort skin;

	public void Serialize(ref Span<byte> packet) {
		BitBuffer data = BufferPool.GetBitBuffer();

		data.AddUInt(peer)
		.AddByte(race)
		.AddUShort(skin)
		.ToSpan(ref packet);

		data.Clear();
	}

	public void Deserialize(ref ReadOnlySpan<byte> packet, int length) {
		BitBuffer data = BufferPool.GetBitBuffer();

		data.FromSpan(ref packet, length);

		peer = data.ReadUInt();
		race = data.ReadByte();
		skin = data.ReadUShort();

		data.Clear();
	}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].