mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 13:31:49 +00:00
Merge branch 'main' into release-0.25
This commit is contained in:
commit
f0a07cbdca
2 changed files with 41 additions and 25 deletions
|
|
@ -62,6 +62,12 @@ If you use Wayland
|
||||||
sudo pacman -S glfw-wayland glew glm libpng libvorbis openal luajit libcurl
|
sudo pacman -S glfw-wayland glew glm libpng libvorbis openal luajit libcurl
|
||||||
```
|
```
|
||||||
|
|
||||||
|
And you need entt. In yay you can use
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yay -S entt
|
||||||
|
```
|
||||||
|
|
||||||
### Build engine with CMake
|
### Build engine with CMake
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|
|
||||||
|
|
@ -293,37 +293,46 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startListen() {
|
||||||
|
while (state == ConnectionState::CONNECTED) {
|
||||||
|
int size = recvsocket(descriptor, buffer.data(), buffer.size());
|
||||||
|
if (size == 0) {
|
||||||
|
logger.info() << "closed connection with " << to_string(addr);
|
||||||
|
closesocket(descriptor);
|
||||||
|
state = ConnectionState::CLOSED;
|
||||||
|
break;
|
||||||
|
} else if (size < 0) {
|
||||||
|
logger.warning() << "an error ocurred while receiving from "
|
||||||
|
<< to_string(addr);
|
||||||
|
auto error = handle_socket_error("recv(...) error");
|
||||||
|
closesocket(descriptor);
|
||||||
|
state = ConnectionState::CLOSED;
|
||||||
|
logger.error() << error.what();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::lock_guard lock(mutex);
|
||||||
|
for (size_t i = 0; i < size; i++) {
|
||||||
|
readBatch.emplace_back(buffer[i]);
|
||||||
|
}
|
||||||
|
totalDownload += size;
|
||||||
|
}
|
||||||
|
logger.debug() << "read " << size << " bytes from " << to_string(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startClient() {
|
||||||
|
state = ConnectionState::CONNECTED;
|
||||||
|
thread = std::make_unique<std::thread>([this]() { startListen();});
|
||||||
|
}
|
||||||
|
|
||||||
void connect(runnable callback) override {
|
void connect(runnable callback) override {
|
||||||
thread = std::make_unique<std::thread>([this, callback]() {
|
thread = std::make_unique<std::thread>([this, callback]() {
|
||||||
connectSocket();
|
connectSocket();
|
||||||
if (state == ConnectionState::CONNECTED) {
|
if (state == ConnectionState::CONNECTED) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
while (state == ConnectionState::CONNECTED) {
|
startListen();
|
||||||
int size = recvsocket(descriptor, buffer.data(), buffer.size());
|
|
||||||
if (size == 0) {
|
|
||||||
logger.info() << "closed connection with " << to_string(addr);
|
|
||||||
closesocket(descriptor);
|
|
||||||
state = ConnectionState::CLOSED;
|
|
||||||
break;
|
|
||||||
} else if (size < 0) {
|
|
||||||
logger.info() << "an error ocurred while receiving from "
|
|
||||||
<< to_string(addr);
|
|
||||||
auto error = handle_socket_error("recv(...) error");
|
|
||||||
closesocket(descriptor);
|
|
||||||
state = ConnectionState::CLOSED;
|
|
||||||
logger.error() << error.what();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::lock_guard lock(mutex);
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
|
||||||
readBatch.emplace_back(buffer[i]);
|
|
||||||
}
|
|
||||||
totalDownload += size;
|
|
||||||
}
|
|
||||||
logger.info() << "read " << size << " bytes from " << to_string(addr);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -459,6 +468,7 @@ public:
|
||||||
auto socket = std::make_shared<SocketConnection>(
|
auto socket = std::make_shared<SocketConnection>(
|
||||||
clientDescriptor, address
|
clientDescriptor, address
|
||||||
);
|
);
|
||||||
|
socket->startClient();
|
||||||
u64id_t id = network->addConnection(socket);
|
u64id_t id = network->addConnection(socket);
|
||||||
{
|
{
|
||||||
std::lock_guard lock(clientsMutex);
|
std::lock_guard lock(clientsMutex);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue