Merge branch 'MihailRis:main' into main
This commit is contained in:
commit
6a0bdde3b9
@ -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
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
# Documentation
|
# Documentation
|
||||||
|
|
||||||
Documentation for stable release 0.24.x.
|
Documentation for in-development version 0.26.
|
||||||
|
|
||||||
|
[Documentation for stable release 0.25.x.](https://github.com/MihailRis/VoxelEngine-Cpp/blob/release-0.25/doc/en/main-page.md)
|
||||||
|
|
||||||
## Sections
|
## Sections
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ The Socket class has the following methods:
|
|||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Sends a byte array
|
-- Sends a byte array
|
||||||
socket:send(table|ByteArray)
|
socket:send(table|ByteArray|str)
|
||||||
|
|
||||||
-- Reads the received data
|
-- Reads the received data
|
||||||
socket:recv(
|
socket:recv(
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
# Документация
|
# Документация
|
||||||
|
|
||||||
Документация стабильной версии 0.25.x.
|
Документация разрабатываемой версии 0.26.
|
||||||
|
|
||||||
|
[Документация стабильной версии 0.25.x.](https://github.com/MihailRis/VoxelEngine-Cpp/blob/release-0.25/doc/ru/main-page.md)
|
||||||
|
|
||||||
## Разделы
|
## Разделы
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ network.tcp_connect(
|
|||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Отправляет массив байт
|
-- Отправляет массив байт
|
||||||
socket:send(table|ByteArray)
|
socket:send(table|ByteArray|str)
|
||||||
|
|
||||||
-- Читает полученные данные
|
-- Читает полученные данные
|
||||||
socket:recv(
|
socket:recv(
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"id": "base",
|
"id": "base",
|
||||||
"title": "Base",
|
"title": "Base",
|
||||||
"version": "0.25",
|
"version": "0.26",
|
||||||
"description": "basic content package"
|
"description": "basic content package"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
static debug::Logger logger("png-coder");
|
static debug::Logger logger("png-coder");
|
||||||
|
|
||||||
// returns 0 if all-right, 1 otherwise
|
// returns 0 if all-right, 1 otherwise
|
||||||
int _png_write(
|
static int png_write(
|
||||||
const char* filename, uint width, uint height, const ubyte* data, bool alpha
|
const char* filename, uint width, uint height, const ubyte* data, bool alpha
|
||||||
) {
|
) {
|
||||||
uint pixsize = alpha ? 4 : 3;
|
uint pixsize = alpha ? 4 : 3;
|
||||||
@ -112,7 +112,7 @@ static void read_in_memory(png_structp pngPtr, png_bytep dst, png_size_t toread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ImageData> png::load_image(const ubyte* bytes, size_t size) {
|
std::unique_ptr<ImageData> png::load_image(const ubyte* bytes, size_t size) {
|
||||||
if (!png_check_sig(bytes, size)) {
|
if (size < 8 || !png_check_sig(bytes, 8)) {
|
||||||
throw std::runtime_error("invalid png signature");
|
throw std::runtime_error("invalid png signature");
|
||||||
}
|
}
|
||||||
png_structp pngPtr = nullptr;
|
png_structp pngPtr = nullptr;
|
||||||
@ -223,7 +223,7 @@ std::unique_ptr<Texture> png::load_texture(const std::string& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void png::write_image(const std::string& filename, const ImageData* image) {
|
void png::write_image(const std::string& filename, const ImageData* image) {
|
||||||
_png_write(
|
png_write(
|
||||||
filename.c_str(),
|
filename.c_str(),
|
||||||
image->getWidth(),
|
image->getWidth(),
|
||||||
image->getHeight(),
|
image->getHeight(),
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
inline constexpr int ENGINE_VERSION_MAJOR = 0;
|
inline constexpr int ENGINE_VERSION_MAJOR = 0;
|
||||||
inline constexpr int ENGINE_VERSION_MINOR = 25;
|
inline constexpr int ENGINE_VERSION_MINOR = 26;
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
inline constexpr bool ENGINE_DEBUG_BUILD = false;
|
inline constexpr bool ENGINE_DEBUG_BUILD = false;
|
||||||
@ -14,7 +14,7 @@ inline constexpr bool ENGINE_DEBUG_BUILD = false;
|
|||||||
inline constexpr bool ENGINE_DEBUG_BUILD = true;
|
inline constexpr bool ENGINE_DEBUG_BUILD = true;
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
||||||
inline const std::string ENGINE_VERSION_STRING = "0.25";
|
inline const std::string ENGINE_VERSION_STRING = "0.26";
|
||||||
|
|
||||||
/// @brief world regions format version
|
/// @brief world regions format version
|
||||||
inline constexpr uint REGION_FORMAT_VERSION = 3;
|
inline constexpr uint REGION_FORMAT_VERSION = 3;
|
||||||
|
|||||||
@ -20,7 +20,9 @@ std::shared_ptr<Inventory> Inventories::create(size_t size) {
|
|||||||
std::shared_ptr<Inventory> Inventories::createVirtual(size_t size) {
|
std::shared_ptr<Inventory> Inventories::createVirtual(size_t size) {
|
||||||
int64_t id;
|
int64_t id;
|
||||||
do {
|
do {
|
||||||
id = -std::max<int64_t>(1LL, std::llabs(random.rand64()));
|
// lua does not support long integers because Number is floating-point
|
||||||
|
// type. Changing int_consumer to use 64 bit integer does not change anything
|
||||||
|
id = -std::max<int64_t>(1LL, std::llabs(random.rand64() % 1000'000'000));
|
||||||
} while (map.find(id) != map.end());
|
} while (map.find(id) != map.end());
|
||||||
|
|
||||||
auto inv = std::make_shared<Inventory>(id, size);
|
auto inv = std::make_shared<Inventory>(id, size);
|
||||||
|
|||||||
@ -87,6 +87,9 @@ static int l_send(lua::State* L) {
|
|||||||
connection->send(
|
connection->send(
|
||||||
reinterpret_cast<char*>(bytes->data().data()), bytes->data().size()
|
reinterpret_cast<char*>(bytes->data().data()), bytes->data().size()
|
||||||
);
|
);
|
||||||
|
} else if (lua::isstring(L, 2)) {
|
||||||
|
auto string = lua::tolstring(L, 2);
|
||||||
|
connection->send(string.data(), string.length());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -98,7 +101,8 @@ static int l_recv(lua::State* L) {
|
|||||||
if (connection == nullptr) {
|
if (connection == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
util::Buffer<char> buffer(glm::min(length, connection->available()));
|
length = glm::min(length, connection->available());
|
||||||
|
util::Buffer<char> buffer(length);
|
||||||
|
|
||||||
int size = connection->recv(buffer.data(), length);
|
int size = connection->recv(buffer.data(), length);
|
||||||
if (size == -1) {
|
if (size == -1) {
|
||||||
|
|||||||
@ -293,12 +293,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void connect(runnable callback) override {
|
void startListen() {
|
||||||
thread = std::make_unique<std::thread>([this, callback]() {
|
|
||||||
connectSocket();
|
|
||||||
if (state == ConnectionState::CONNECTED) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
while (state == ConnectionState::CONNECTED) {
|
while (state == ConnectionState::CONNECTED) {
|
||||||
int size = recvsocket(descriptor, buffer.data(), buffer.size());
|
int size = recvsocket(descriptor, buffer.data(), buffer.size());
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
@ -307,7 +302,7 @@ public:
|
|||||||
state = ConnectionState::CLOSED;
|
state = ConnectionState::CLOSED;
|
||||||
break;
|
break;
|
||||||
} else if (size < 0) {
|
} else if (size < 0) {
|
||||||
logger.info() << "an error ocurred while receiving from "
|
logger.warning() << "an error ocurred while receiving from "
|
||||||
<< to_string(addr);
|
<< to_string(addr);
|
||||||
auto error = handle_socket_error("recv(...) error");
|
auto error = handle_socket_error("recv(...) error");
|
||||||
closesocket(descriptor);
|
closesocket(descriptor);
|
||||||
@ -322,8 +317,22 @@ public:
|
|||||||
}
|
}
|
||||||
totalDownload += size;
|
totalDownload += size;
|
||||||
}
|
}
|
||||||
logger.info() << "read " << size << " bytes from " << to_string(addr);
|
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 {
|
||||||
|
thread = std::make_unique<std::thread>([this, callback]() {
|
||||||
|
connectSocket();
|
||||||
|
if (state == ConnectionState::CONNECTED) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
startListen();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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…
x
Reference in New Issue
Block a user