mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
Merge branch 'main' into animation
This commit is contained in:
commit
856f678315
14 changed files with 125 additions and 9 deletions
|
|
@ -13,6 +13,7 @@ for i=1,3 do
|
|||
print("client-listener started")
|
||||
local received_text = ""
|
||||
while client:is_alive() and #received_text < #text do
|
||||
client:peek(math.random(0, 100))
|
||||
local received = client:recv(512)
|
||||
if received then
|
||||
received_text = received_text .. utf8.tostring(received)
|
||||
|
|
|
|||
|
|
@ -172,7 +172,9 @@ app.start_background_instance(
|
|||
-- script file
|
||||
app_script: string,
|
||||
-- log file
|
||||
output_file: string | nil
|
||||
output_file: string,
|
||||
-- project parameters (can be read with vc.get_project_arg(name))
|
||||
project_args: table<string, string> | nil
|
||||
) -> int
|
||||
|
||||
-- Checks if the engine sub-instance is alive.
|
||||
|
|
|
|||
|
|
@ -63,6 +63,13 @@ input.get_mouse_delta() --> {int, int}
|
|||
|
||||
Returns cursor movement delta.
|
||||
|
||||
```lua
|
||||
input.get_mouse_scroll() --> int
|
||||
```
|
||||
|
||||
Returns the vertical mouse wheel offset accumulated during the current frame.
|
||||
A positive value indicates scrolling up; a negative value indicates scrolling down.
|
||||
|
||||
```lua
|
||||
input.get_bindings() --> strings array
|
||||
```
|
||||
|
|
|
|||
|
|
@ -92,6 +92,21 @@ socket:recv_async(
|
|||
[optional] usetable: bool=false
|
||||
) -> nil|table|Bytearray
|
||||
|
||||
-- `peek` and `peek_async` are analogous to the `recv` and `recv_async` methods
|
||||
-- with the exception that `peek` and `peek_async` do not advance the socket buffer position
|
||||
-- This means they do not remove bytes from the socket, so the bytes can be received after
|
||||
socket:peek(
|
||||
length: int,
|
||||
[optional] usetable: boolean=false
|
||||
) -> nil|table|Bytearray
|
||||
|
||||
socket:peek_async(
|
||||
length: int,
|
||||
[optional] usetable: boolean=false
|
||||
) -> nil|table|Bytearray
|
||||
|
||||
Translated with DeepL.com (free version)
|
||||
|
||||
-- Closes the connection
|
||||
socket:close()
|
||||
|
||||
|
|
|
|||
|
|
@ -162,7 +162,9 @@ app.start_background_instance(
|
|||
-- файл сценария
|
||||
app_script: string,
|
||||
-- файл лога
|
||||
output_file: string | nil
|
||||
output_file: string,
|
||||
-- параметры проекта, что будут доступны через vc.get_project_arg(name)
|
||||
project_args: table<string, string> | nil,
|
||||
) -> int
|
||||
|
||||
-- Проверяет, жив ли под-экземпляр движка.
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ input.get_mouse_pos() -> {number, number}
|
|||
|
||||
-- Возращает дельту позиции курсора.
|
||||
input.get_mouse_delta() -> {number, number}
|
||||
|
||||
-- Возвращает вертикальное смещение колеса мыши, накопленное за текущий кадр.
|
||||
-- Положительное значение соответствует прокрутке вверх, отрицательное - вниз.
|
||||
input.get_mouse_scroll() -> number
|
||||
```
|
||||
|
||||
## Создание обработчиков
|
||||
|
|
|
|||
|
|
@ -92,6 +92,19 @@ socket:recv_async(
|
|||
[опционально] usetable: boolean=false
|
||||
) -> nil|table|Bytearray
|
||||
|
||||
-- `peek` и `peek_async` являются аналогами методов `recv` и `recv_async`
|
||||
-- за тем исключением, что `peek` и `peek_async` не двигают позицию буфера сокета
|
||||
-- Это означает, что они не удаляют байты из сокета, а значит байты могут быть прочитаны после
|
||||
socket:peek(
|
||||
length: int,
|
||||
[опционально] usetable: boolean=false
|
||||
) -> nil|table|Bytearray
|
||||
|
||||
socket:peek_async(
|
||||
length: int,
|
||||
[опционально] usetable: boolean=false
|
||||
) -> nil|table|Bytearray
|
||||
|
||||
-- Оборачивает сокет в io_stream (см. ../io_stream.md)
|
||||
socket:as_stream(
|
||||
[опционально] binary_mode: boolean=true
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ end
|
|||
local Socket = {__index={
|
||||
send=function(self, ...) return network.__send(self.id, ...) end,
|
||||
recv=function(self, ...) return network.__recv(self.id, ...) end,
|
||||
peek=function(self, ...) return network.__peek(self.id, ...) end,
|
||||
recv_async=function(self, length, usetable)
|
||||
while self:is_alive() do
|
||||
local available = self:available()
|
||||
|
|
@ -49,6 +50,16 @@ local Socket = {__index={
|
|||
end
|
||||
return self:recv(length, usetable)
|
||||
end,
|
||||
peek_async=function(self, length, usetable)
|
||||
while self:is_alive() do
|
||||
local available = self:available()
|
||||
if available >= length then
|
||||
return self:peek(length, usetable)
|
||||
end
|
||||
coroutine.yield()
|
||||
end
|
||||
return self:peek(length, usetable)
|
||||
end,
|
||||
as_stream=network.__as_stream,
|
||||
close=function(self) return network.__close(self.id) end,
|
||||
available=function(self) return network.__available(self.id) or 0 end,
|
||||
|
|
|
|||
|
|
@ -405,6 +405,20 @@ static int l_start_background_instance(lua::State* L) {
|
|||
|
||||
auto scriptPath = lua::require_lstring(L, 1);
|
||||
io::path outputPath = lua::isstring(L, 2) ? lua::require_lstring(L, 2) : "";
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> projectArgs;
|
||||
if (lua::istable(L, 3)) {
|
||||
lua::pushnil(L);
|
||||
while (lua::next(L, 3)) {
|
||||
lua::pushvalue(L, -2);
|
||||
auto key = lua::tolstring(L, -1);
|
||||
auto value = lua::tolstring(L, -2);
|
||||
projectArgs.emplace_back(key, value);
|
||||
lua::pop(L, 2);
|
||||
}
|
||||
lua::pop(L);
|
||||
}
|
||||
|
||||
const auto& paths = engine->getPaths();
|
||||
|
||||
std::vector<std::string> args {
|
||||
|
|
@ -419,6 +433,17 @@ static int l_start_background_instance(lua::State* L) {
|
|||
args.emplace_back("--project");
|
||||
args.emplace_back(io::resolve(engine->getProject().path).u8string());
|
||||
|
||||
if (!projectArgs.empty()) {
|
||||
args.emplace_back("--");
|
||||
for (const auto& [key, value] : projectArgs) {
|
||||
if (key.empty()) {
|
||||
throw std::runtime_error("empty project argument name passed");
|
||||
}
|
||||
args.emplace_back("--" + key);
|
||||
args.emplace_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
int handle = -1;
|
||||
for (int i = 0; i < ::processes.size(); i++) {
|
||||
if (!::processes[i] || !::processes[i]->isActive()) {
|
||||
|
|
|
|||
|
|
@ -91,6 +91,12 @@ static int l_get_mouse_delta(lua::State* L) {
|
|||
return lua::pushvec2(L, engine->getInput().getCursor().delta);
|
||||
}
|
||||
|
||||
static int l_get_mouse_scroll(lua::State* L) {
|
||||
if (engine->isHeadless())
|
||||
return 0;
|
||||
return lua::pushinteger(L, engine->getInput().getScroll());
|
||||
}
|
||||
|
||||
static int l_get_bindings(lua::State* L) {
|
||||
if (engine->isHeadless())
|
||||
return 0;
|
||||
|
|
@ -181,6 +187,7 @@ const luaL_Reg inputlib[] = {
|
|||
{"add_callback", lua::wrap<l_add_callback>},
|
||||
{"get_mouse_pos", lua::wrap<l_get_mouse_pos>},
|
||||
{"get_mouse_delta", lua::wrap<l_get_mouse_delta>},
|
||||
{"get_mouse_scroll", lua::wrap<l_get_mouse_scroll>},
|
||||
{"get_bindings", lua::wrap<l_get_bindings>},
|
||||
{"get_binding_text", lua::wrap<l_get_binding_text>},
|
||||
{"is_active", lua::wrap<l_is_active>},
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ static int l_udp_server_send_to(lua::State* L, network::Network& network) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_recv(lua::State* L, network::Network& network) {
|
||||
static int read(lua::State* L, network::Network& network, int (*fn)(network::TcpConnection*, char*, int)) {
|
||||
u64id_t id = lua::tointeger(L, 1);
|
||||
int length = lua::tointeger(L, 2);
|
||||
|
||||
|
|
@ -248,11 +248,12 @@ static int l_recv(lua::State* L, network::Network& network) {
|
|||
}
|
||||
|
||||
auto tcpConnection = dynamic_cast<network::TcpConnection*>(connection);
|
||||
auto tcp = dynamic_cast<network::TcpConnection*>(connection);
|
||||
|
||||
length = glm::min(length, tcpConnection->available());
|
||||
util::Buffer<char> buffer(length);
|
||||
|
||||
int size = tcpConnection->recv(buffer.data(), length);
|
||||
|
||||
int size = fn(tcp, buffer.data(), length);
|
||||
if (size == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -268,6 +269,18 @@ static int l_recv(lua::State* L, network::Network& network) {
|
|||
}
|
||||
}
|
||||
|
||||
static int l_recv(lua::State* L, network::Network& network) {
|
||||
return read(L, network, [](auto* tcp, char* buf, int len) {
|
||||
return tcp->recv(buf, len);
|
||||
});
|
||||
}
|
||||
|
||||
static int l_peek(lua::State* L, network::Network& network) {
|
||||
return read(L, network, [](auto* tcp, char* buf, int len) {
|
||||
return tcp->peek(buf, len);
|
||||
});
|
||||
}
|
||||
|
||||
static int l_available(lua::State* L, network::Network& network) {
|
||||
u64id_t id = lua::tointeger(L, 1);
|
||||
|
||||
|
|
@ -566,6 +579,7 @@ const luaL_Reg networklib[] = {
|
|||
{"__close", wrap<l_close>},
|
||||
{"__send", wrap<l_send>},
|
||||
{"__recv", wrap<l_recv>},
|
||||
{"__peek", wrap<l_peek>},
|
||||
{"__available", wrap<l_available>},
|
||||
{"__is_alive", wrap<l_is_alive>},
|
||||
{"__is_connected", wrap<l_is_connected>},
|
||||
|
|
|
|||
|
|
@ -196,15 +196,26 @@ public:
|
|||
});
|
||||
}
|
||||
|
||||
int recv(char* buffer, size_t length) override {
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
int read(char* buffer, size_t length) {
|
||||
if (state != ConnectionState::CONNECTED && readBatch.empty()) {
|
||||
return -1;
|
||||
}
|
||||
int size = std::min(readBatch.size(), length);
|
||||
std::memcpy(buffer, readBatch.data(), size);
|
||||
readBatch.erase(readBatch.begin(), readBatch.begin() + size);
|
||||
return size;
|
||||
}
|
||||
|
||||
int peek(char* buffer, size_t length) override {
|
||||
std::lock_guard lock(mutex);
|
||||
return read(buffer, length);
|
||||
}
|
||||
|
||||
int recv(char* buffer, size_t length) override {
|
||||
std::lock_guard lock(mutex);
|
||||
int size = read(buffer, length);
|
||||
if (size != -1) {
|
||||
readBatch.erase(readBatch.begin(), readBatch.begin() + size);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ namespace network {
|
|||
class ReadableConnection : public Connection {
|
||||
public:
|
||||
virtual int recv(char* buffer, size_t length) = 0;
|
||||
virtual int peek(char* buffer, size_t length) = 0;
|
||||
virtual int available() = 0;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -281,6 +281,9 @@ public:
|
|||
return exitCode == STILL_ACTIVE;
|
||||
}
|
||||
return false;
|
||||
#elif defined(__APPLE__)
|
||||
// FIXME: completely implement SystemProcess for MacOS
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue