Skip to content

Commit aa129bb

Browse files
committed
Add multiplayer abstractions
Add multi-platform socket abstractions Add Udp and Tcp client/server socket handlers Add RingBuffer Add zip::bits marshaling tests Add RingBuffer tests Add IpAddress tests Add UdpServer tests Add ReliableUdpServer tess Add TcpServer tests Add mas-bandwidth/reliable@57b0c90 Add eyalz800/zpp_bits@e5ff2b2
1 parent e3dba06 commit aa129bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+6192
-16
lines changed

.clang-format

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ InsertBraces: true
7272
MaxEmptyLinesToKeep: 2
7373
RequiresClausePosition: OwnLine
7474
IncludeCategories:
75+
- Regex: ^<zpp_bits\.h>
76+
Priority: 9
7577
- Regex: <[[:alnum:]_]+>
7678
Priority: 1
7779
- Regex: <[[:alnum:]_]+[.]h>
@@ -89,6 +91,6 @@ IncludeCategories:
8991
- Regex: ^<range
9092
Priority: 8
9193
- Regex: ^"openvic-simulation/
92-
Priority: 9
93-
- Regex: .*
9494
Priority: 10
95+
- Regex: .*
96+
Priority: 11

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@
3030
path = deps/memory
3131
url = https://github.com/foonathan/memory
3232
ignore = dirty
33+
[submodule "deps/reliable"]
34+
path = deps/reliable
35+
url = https://github.com/mas-bandwidth/reliable
36+
[submodule "deps/zpp_bits"]
37+
path = deps/zpp_bits
38+
url = https://github.com/eyalz800/zpp_bits

COPYRIGHT

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Comment: plf::colony
3838
Copyright: 2019, mattreecebentley
3939
License: Zlib
4040

41+
Files: deps/reliable/*
42+
Comment: reliable
43+
Copyright: 2017-2024, Mas Bandwidth LLC
44+
License: BSD-3-Clause
45+
46+
Files: deps/zpp_bits/*
47+
Comment: zpp_bits
48+
Copyright: 2021, Eyal Z
49+
License: Expat
50+
4151
Files: src/openvic-simulation/types/Signal.hpp
4252
Comment: sigslot
4353
Copyright: 2017, Pierre-Antoine Lacaze
@@ -53,6 +63,15 @@ Comment: nanobench
5363
Copyright: 2019-2023 Martin Leitner-Ankerl
5464
License: Expat
5565

66+
License: BSD-3-Clause
67+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
68+
.
69+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
70+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
71+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
72+
.
73+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74+
5675
License: BSL-1.0
5776
Boost Software License - Version 1.0 - August 17th, 2003
5877
.

deps/SCsub

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,50 @@ def build_memory(env):
111111

112112
env.exposed_includes += env.memory["INCPATH"]
113113

114+
def build_reliable(env):
115+
import os
116+
117+
if env["optimize"] in ["none", "debug"]:
118+
env.Append(CPPDEFINES=["RELIABLE_DEBUG"])
119+
else:
120+
env.Append(CPPDEFINES=["RELIABLE_RELEASE"])
121+
reliable_env = env.Clone()
122+
123+
include_path = "reliable"
124+
include_dir = reliable_env.Dir(include_path)
125+
sources = [os.path.join(include_path, "reliable.c")]
126+
env.reliable_sources = sources
127+
library_name = "libreliable" + env["LIBSUFFIX"]
128+
library = reliable_env.StaticLibrary(target=os.path.join(include_path, library_name), source=sources)
129+
Default(library)
130+
131+
env.reliable = {}
132+
env.reliable["INCPATH"] = [include_dir]
133+
134+
env.Append(CPPPATH=env.reliable["INCPATH"])
135+
if env.get("is_msvc", False):
136+
env.Append(CXXFLAGS=["/external:I", include_dir, "/external:W0"])
137+
else:
138+
env.Append(CXXFLAGS=["-isystem", include_dir])
139+
env.Append(LIBPATH=include_dir)
140+
env.Prepend(LIBS=[library_name])
141+
142+
env.exposed_includes += env.reliable["INCPATH"]
143+
144+
def build_zpp_bits(env):
145+
if env["optimize"] in ["none", "debug"]:
146+
env.Append(CPPDEFINES=[("ZPP_BITS_INLINE_MODE", 0)])
147+
elif env["optimize"] == "speed":
148+
env.Append(CPPDEFINES=[("ZPP_BITS_INLINE_DECODE_VARINT", 1)])
149+
150+
include_path = "zpp_bits"
151+
include_dir = env.Dir(include_path)
152+
153+
env.zpp_bits = {}
154+
env.zpp_bits["INCPATH"] = [include_dir]
155+
156+
env.Append(CPPPATH=env.zpp_bits["INCPATH"])
157+
114158
def link_tbb(env):
115159
import sys
116160
if not env.get("is_msvc", False) and not env.get("use_mingw", False) and sys.platform != "darwin":
@@ -123,4 +167,6 @@ build_colony(env)
123167
build_function2(env)
124168
build_std_function(env)
125169
build_memory(env)
170+
build_reliable(env)
171+
build_zpp_bits(env)
126172
link_tbb(env)

deps/reliable

Submodule reliable added at 57b0c90

deps/zpp_bits

Submodule zpp_bits added at e5ff2b2
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#include "HostnameAddress.hpp"
3+
4+
#include <charconv>
5+
#include <system_error>
6+
7+
#include "openvic-simulation/multiplayer/lowlevel/IpAddress.hpp"
8+
#include "openvic-simulation/multiplayer/lowlevel/NetworkResolver.hpp"
9+
10+
using namespace OpenVic;
11+
12+
HostnameAddress::HostnameAddress() = default;
13+
14+
HostnameAddress::HostnameAddress(IpAddress const& address) : _resolved_address(address) {}
15+
16+
HostnameAddress::HostnameAddress(std::string_view name_or_address) : HostnameAddress() {
17+
std::from_chars_result result =
18+
_resolved_address.from_chars(name_or_address.data(), name_or_address.data() + name_or_address.size());
19+
if (result.ec != std::errc {}) {
20+
_resolved_address = NetworkResolver::singleton().resolve_hostname(name_or_address);
21+
}
22+
}
23+
24+
IpAddress const& HostnameAddress::resolved_address() const {
25+
return _resolved_address;
26+
}
27+
28+
void HostnameAddress::set_resolved_address(IpAddress const& address) {
29+
_resolved_address = address;
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <string_view>
4+
5+
#include "openvic-simulation/multiplayer/lowlevel/IpAddress.hpp"
6+
7+
namespace OpenVic {
8+
struct HostnameAddress {
9+
HostnameAddress();
10+
HostnameAddress(IpAddress const& address);
11+
HostnameAddress(std::string_view name_or_address);
12+
13+
IpAddress const& resolved_address() const;
14+
void set_resolved_address(IpAddress const& address);
15+
16+
private:
17+
IpAddress _resolved_address;
18+
};
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "IpAddress.hpp"
2+
3+
#include "openvic-simulation/utility/Containers.hpp"
4+
5+
using namespace OpenVic;
6+
7+
memory::string IpAddress::to_string(bool prefer_ipv4, to_chars_option option) const {
8+
stack_string result = to_array(prefer_ipv4, option);
9+
if (OV_unlikely(result.empty())) {
10+
return {};
11+
}
12+
13+
return result;
14+
}
15+
16+
IpAddress::operator memory::string() const {
17+
return to_string();
18+
}

0 commit comments

Comments
 (0)