librg is a lightweight library that serves as a middleware between data-transferring libraries (networking, file-streaming, etc.) and core application/game logic.
The main responsibilities of the library include:
The library was born to solve the complexities of setting up and managing the flow of multi-player games and dedicated game servers. It came a long way in stripping out things that were non-essential, slowly sculpting into its current form, which you are able to see and use today.
Usually, the networked game world consists of a set of networked players and a bunch of networked entities. The typical variant of setting up the synchronization relations between entities and players is to set up Everything-to-Everyone connections.
This is the most basic setup to follow. However, with an increasing amount of entities, it becomes rather bandwidth-inefficient.
With librg, you can considerably decrease bandwidth usage by building radius & visibility-based entity relations. Entities will be synchronized only with the players they are visible to.
The overall interface of the library was made with the support of most network libraries in mind.
The networking library has to support:
char *
bufferAnd that is pretty much it!
A list of what kind of libraries are supported:
ENet
GameNetworkingSockets
yojimbo
SLikeNet
KCP
Raknet
Websocket
WebRTC
UDP
or TCP
based libraryNote: you can check an example for the network integration for enet.
librg
is a single-header library, which means to use it, you only need to get the latest (or specific) version of the said header file from the releases section of this repository, add it to your project, and start enjoying the benefits.
Alternatively, if you feel comfortable in your CLI, you can just do the following;
curl -L https://github.com/zpl-c/librg/releases/latest/download/librg.h > librg.h
# OR
wget https://github.com/zpl-c/librg/releases/latest/download/librg.h -O librg.h
Is this a networking library?
Can I use any networking library with it?
UDP
, and up to WebSocket
/WebRTC
.The repository contains a bunch of *.h
and *.c
files, and yet you suggest it is a single-header library, how is that possible?
Does librg offer an entity system?
How do I pack data, do you provide methods for that?
protobuf
, flatbuffers
, msgpack
, etc.), or make your own implementation.I see you mention chunks, does it mean my game/app should be chunk-based?
To read detailed documentation about the library, see examples, and a quick start guide, please visit our documentation page.
Additionally, you can check code/apps folder for actual code examples.
Here is a simple illustration that attempts to replicate how the library works on a simple 2D world of 4x4 chunks. For a 3D world of bigger size, everything would work in a very similar way, just in 3 dimensions.
And this picture showcases the structure of the underlying binary protocol that is used to encode and decode data from/to. The resulting binary buffer could be inserted into any other buffer, saved to disk as a file, or sent via the network using any available method. Putting custom data alongside every entity within the packet allows context-dependant data storage that extends capabilities and allows memory- and bandwidth-efficient entity replication.
If you've used the library before version v6.0.0
, it is recommended to read the migration guide located here.
We are testing the library for various platforms. This table provides some sort of description for compatibility. If you have tested it, and your result is different from the one in the table, please feel free to describe the issue in the issues.
Platform / Result | Windows | macOS | Linux | iOS | Android | Raspberry Pi | OpenBSD | FreeBSD | Emscripten |
---|---|---|---|---|---|---|---|---|---|
❔ | clang | clang | gcc, clang | gcc, clang | gcc, clang | ||||
✅ | msvc, mingw | gcc, clang | gcc, clang | emcc |
If you wish to contribute, add new features, optimizations, or overall improvements, here are the instructions on how to do that:
git clone https://github.com/zpl-c/librg.git
make
to build all projects and verify everything workscode/tests/
make test
again to checkIn case you are working from Windows, and/or are not able to use make
, you can also use the built-in cmake
config file to generate a Visual Studio solution, to do that:
mkdir build
cd build
cmake ../misc -G"Visual Studio 16 2019"
(or any configuration you have)cmake --open .
(opens VS with the solution)For developers, it offers nice benefits: