Skip to content

Commit

Permalink
keep it simple
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Dec 22, 2023
1 parent 4232c3f commit fb54db4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 68 deletions.
24 changes: 10 additions & 14 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ How to build netcode

## Building on Windows

Download [premake 5](https://premake.github.io/download.html) and copy the **premake5** executable somewhere in your path. Please make sure you have at least premake5 alpha 13.
Download [premake 5](https://premake.github.io/download.html) and copy the **premake5** executable somewhere in your path.

You need Visual Studio to build the source code. If you don't have Visual Studio 2019 you can [download the community edition for free](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16).
You need Visual Studio to build the source code. If you don't have Visual Studio you can [download the community edition for free](https://visualstudio.microsoft.com/downloads/).

Once you have Visual Studio installed, go to the command line under the netcode directory and type:

Expand All @@ -17,23 +17,21 @@ Now you can build the library and run individual test programs as you would for

## Building on MacOS and Linux

First, download and install [premake 5](https://premake.github.io/download.html). Please make sure you have at least premake5 alpha 13.

Next, install libsodium.

On MacOS X, this can be done most easily with `brew install libsodium`.

If you don't have Brew, you can install it from <http://brew.sh>.

On Linux, depending on your particular distribution there may be prebuilt packages for libsodium, or you may have to build from source from here [libsodium](https://github.com/jedisct1/libsodium/releases).
First, download and install [premake 5](https://premake.github.io/download.html).

Now go to the command line under the netcode directory and enter:

premake5 gmake

Which creates makefiles which you can use to build the source via:

make all
make

Then you can run binaries like this:

./bin/test
./bin/client
./bin/server

Alternatively, you can use the following shortcuts to build and run test programs directly:

Expand All @@ -42,8 +40,6 @@ Alternatively, you can use the following shortcuts to build and run test program
premake5 server // build run a netcode server on localhost on UDP port 40000

premake5 client // build and run a netcode client that connects to the server running on localhost

premake5 stress // connect 256 netcode clients to a running server as a stress test

If you have questions please create an issue at https://github.com/networkprotocol/netcode and I'll do my best to help you out.

Expand Down
71 changes: 17 additions & 54 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,19 @@ else
description = "Build and run all unit tests",
execute = function ()
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j32 test" then
if os.execute "make -j test" then
os.execute "./bin/test"
end
end
}

newaction
{
trigger = "soak",
description = "Build and run soak test",
execute = function ()
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j32 soak" then
os.execute "./bin/soak"
end
end
}

newaction
{
trigger = "profile",
description = "Build and run profile tet",
execute = function ()
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j32 profile" then
os.execute "./bin/profile"
end
end
}

newaction
{
trigger = "client",
description = "Build and run the client",
execute = function ()
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j32 client" then
if os.execute "make -j client" then
os.execute "./bin/client"
end
end
Expand All @@ -126,7 +102,7 @@ else
description = "Build and run the server",
execute = function ()
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j32 server" then
if os.execute "make -j server" then
os.execute "./bin/server"
end
end
Expand All @@ -138,28 +114,33 @@ else
description = "Build and run the client/server testbed",
execute = function ()
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j32 client_server" then
if os.execute "make -j client_server" then
os.execute "./bin/client_server"
end
end
}

newaction
{
trigger = "docker",
description = "Build and run a netcode server inside a docker container",
trigger = "soak",
description = "Build and run soak test",
execute = function ()
os.execute "docker run --rm --privileged alpine hwclock -s" -- workaround for clock getting out of sync on macos. see https://docs.docker.com/docker-for-mac/troubleshoot/#issues
os.execute "rm -rf docker/netcode && mkdir -p docker/netcode && cp *.h docker/netcode && cp *.c docker/netcode && cp *.cpp docker/netcode && cp premake5.lua docker/netcode && cd docker && docker build -t \"networkprotocol:netcode-server\" . && rm -rf netcode && docker run -ti -p 40000:40000/udp networkprotocol:netcode-server"
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j soak" then
os.execute "./bin/soak"
end
end
}

newaction
{
trigger = "valgrind",
description = "Run valgrind over tests inside docker",
trigger = "profile",
description = "Build and run profile",
execute = function ()
os.execute "rm -rf valgrind/netcode && mkdir -p valgrind/netcode && cp *.h valgrind/netcode && cp *.c valgrind/netcode && cp *.cpp valgrind/netcode && cp premake5.lua valgrind/netcode && cd valgrind && docker build -t \"networkprotocol:netcode-valgrind\" . && rm -rf netcode && docker run -ti networkprotocol:netcode-valgrind"
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j profile" then
os.execute "./bin/profile"
end
end
}

Expand All @@ -169,32 +150,14 @@ else
description = "Launch 256 client instances to stress test the server",
execute = function ()
os.execute "test ! -e Makefile && premake5 gmake"
if os.execute "make -j32 client" then
if os.execute "make -j client" then
for i = 0, 255 do
os.execute "./bin/client &"
end
end
end
}

newaction
{
trigger = "cppcheck",
description = "Run cppcheck over the source code",
execute = function ()
os.execute "cppcheck netcode.c"
end
}

newaction
{
trigger = "scan-build",
description = "Run clang scan-build over the project",
execute = function ()
os.execute "premake5 clean && premake5 gmake && scan-build make all -j32"
end
}

newaction
{
trigger = "loc",
Expand Down

0 comments on commit fb54db4

Please sign in to comment.