Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zpl-c/librg
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Sep 18, 2022
2 parents 3f2cbb4 + 7855060 commit 4bff059
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Folders
build/*
build_web/*
emsdk
misc/deploy/
node_modules/
pkg/
Expand Down
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,37 @@ Main responsibilities of the library include:
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.

## Why you need it

#### Without librg

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.

![world_without_librg](https://user-images.githubusercontent.com/2182108/189517945-afa096dd-f2f5-42cb-a0b9-22c2b81bc03b.png)

#### With librg

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.

![world_with_librg](https://user-images.githubusercontent.com/2182108/189517948-afb2dfc9-f632-4a87-bf63-47e3bab5cc42.png)

## Features

* cross-platform support
* lightweight, single-header
* supports 2d/3d worlds of various sizes
* compile- and run-time configurable
* written in C99 (portability reasons)
* no external dependencies
* built-in unit test coverage
* 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

## Networking integration

The overall interface of the library was made in such a way that majority of the networking libraries are supported.
The overall interface of the library was made with support of majority of network libraries in mind

All you would need to have from a library is:
The networking library has to support:

1. Ability to send and receive a `char *` buffer
2. Ability to read or set that buffer size
Expand Down Expand Up @@ -109,7 +125,7 @@ Additionally you can check [code/apps](code/apps) folder for actual code example

### World Replication

Here is a simple illustration that attempts to describe how the library works on a simple 2d world of 4x4 chunks.
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.

<a href="https://user-images.githubusercontent.com/2182108/83945607-87d64400-a814-11ea-8897-3c268b26b0f7.png" target="_blank">
Expand Down Expand Up @@ -170,3 +186,10 @@ In case you are working from **Windows**, and/or are not able to use `make`, you
4. `cmake --open .` (opens VS with the solution)
5. 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

2 changes: 1 addition & 1 deletion code/librg.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@

#define LIBRG_VERSION_MAJOR 7
#define LIBRG_VERSION_MINOR 0
#define LIBRG_VERSION_PATCH 2
#define LIBRG_VERSION_PATCH 3
#define LIBRG_VERSION_PRE ""

#include "librg_hedley.h"
Expand Down
6 changes: 3 additions & 3 deletions code/source/general.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ int8_t librg_config_chunkamount_get(librg_world *world, uint16_t *x, uint16_t *y
int8_t librg_config_chunksize_set(librg_world *world, uint16_t x, uint16_t y, uint16_t z) {
LIBRG_ASSERT(world); if (!world) return LIBRG_WORLD_INVALID;
librg_world_t *wld = (librg_world_t *)world;
wld->chunksize.x = x;
wld->chunksize.y = y;
wld->chunksize.z = z;
wld->chunksize.x = x == 0 ? 1 : x;
wld->chunksize.y = y == 0 ? 1 : y;
wld->chunksize.z = z == 0 ? 1 : z;
return LIBRG_OK;
}

Expand Down
6 changes: 6 additions & 0 deletions misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ foreach(apps_source ${apps})
add_executable(${apps_name} ${apps_source})
endforeach()

if (EMSCRIPTEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g --profiling -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1")
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
endif ()

add_executable(unit ../code/tests/unit.c)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "librg.c",
"version": "7.0.2",
"version": "7.0.3",
"author": "Inlife",
"description": "Pure C library for building simple and elegant cross-platform multiplayer client-server solutions.",
"homepage": "https://github.com/zpl-c/librg#readme",
Expand Down
5 changes: 5 additions & 0 deletions web/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -xe

cmake --build build_web --target clean
20 changes: 20 additions & 0 deletions web/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -xe

# Setup emsdk
if [ ! -d "emsdk" ]; then
wget https://github.com/emscripten-core/emsdk/archive/refs/heads/main.zip -O emscripten.zip
unzip emscripten.zip
mv emsdk-main emsdk
rm -rf emscripten.zip
fi

source ./emsdk/emsdk_env.sh
emsdk update
emsdk install latest
emsdk activate latest
source ./emsdk/emsdk_env.sh

# Setup web build
emcmake cmake -S misc -B build_web -DCMAKE_BUILD_TYPE=Release

0 comments on commit 4bff059

Please sign in to comment.