librg is a lightweight library that serves as a middleware between data-transferring libraries (networking, file-streaming, etc.) and core application/game logic.
Main responsibilities of the library include:
- entity tracking (tracks which entity belongs to what world, and what states do they have)
- owner tracking (tracks which participant owns what entity)
- area of interest management (controls what can and cannot be seen a participant)
- world replication (re-creates a limited representation in a destination world of what is considered visible to a participant in the source world)
The library was born to solve complexities of setting up and managing the flow of multi-player games and dedicated game servers. It came a long way of 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.
- Support for 2d/3d worlds of various sizes
- Virtual world support
- Custom entity visibility methods
- Advanced entity querying
- Events for entity-to-entity status changes
- Networked LOD support (based on variable radius)
- Cross-platform, lightweight, single-header
The overall interface of the library was made with support of majority of network libraries in mind
The networking library has to support:
- Ability to send and receive a
char *
buffer - Ability to read or set that buffer size
- Ability to indentify who is the receiver or sender of the data with an integer id
And that is pretty much it!
A list of what kind of libraries are supported:
ENet
GameNetworkingSockets
yojimbo
SLikeNet
KCP
Raknet
Websocket
WebRTC
- Any other
UDP
orTCP
based library
Note: you can check an example for network integration for enet.
-
Is this a networking library?
- Not really, no. It is intended to be used with netwoking in mind, but it does not have any networking capabilities on its own.
-
Can I use any networking library with it?
- Yes. All you need is an ability to read data to and from the buffer, and most libraries do support that. Theoretically it can be anything as low level as pure
UDP
, and up toWebsocket
/WebRTC
.
- Yes. All you need is an ability to read data to and from the buffer, and most libraries do support that. Theoretically it can be anything as low level as pure
-
The repository contains a bunch of
*.h
and*.c
files, and yet you suggest it is a single-header library, how is that possible?- The library is spread into multiple files so it is easier to work with it while developing, however each time a new release is created, a "bundled" version of the header file is created and pushed directly to the releases page.
-
Does librg offer an entity system?
- No, the library does not manage nor actually create its own entities, it rather expects you to provide your own entity/object handle to attach some internal data onto it, which in context of the library is called "tracking".
-
How do I pack data, do you provide methods for that?
- No, the library does not provide any data-packing/serialization methods. It's recommended you use some existing library for that (
protobuf
,flatbuffers
,msgpack
, etc.), or make your own implementation.
- No, the library does not provide any data-packing/serialization methods. It's recommended you use some existing library for that (
-
I see you mention chunks, does it mean my game/app should be chunk-based?
- No. Chunks are only used internally, to artificially divide the space of the world on statically sized squares/cubes so that querying would work efficiently. Even if your game does use chunks, their amount/sizes/offsets are not required to much and be the same.
To read detailed documentation about the library, see examples and 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 |
- ❔ - Library was not tested on this platform/compiler yet
- ✅ - Library successfully compiles and all tests are executed properly
If you wish to contribute, add new feature, optimizations, or overall improvements, here are the instructions on how to do that:
- Clone the repo, f.e.:
git clone https://github.com/zpl-c/librg.git
- Run
make
to build all projects, and verify everything works - Develop a feature, add tests for it in
code/tests/
- And eventually run
make test
again to check
In case you are working from Windows, and/or are not able to use make
, you can also use 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)- And repeat steps from above
For developers it offers nice benefits:
- compile- and run-time configurable
- written in C99 (portability reasons)
- no external dependencies
- built-in unit test coverage