From 849b7cfef7d7ac5f7d74b0d5373c5f527bccaf39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 21 Aug 2023 18:35:22 +0200 Subject: [PATCH] allow for polling methods to return events --- engine/bind/v4k.lua | 22 +++++------ engine/joint/v4k.h | 37 ++++++++++-------- engine/split/v4k_netsync.c | 15 +++++--- engine/split/v4k_netsync.h | 22 +++++------ engine/v4k.c | 15 +++++--- engine/v4k.h | 22 +++++------ engine/v4k.html | 78 +++++++++++++++++++------------------- 7 files changed, 113 insertions(+), 98 deletions(-) diff --git a/engine/bind/v4k.lua b/engine/bind/v4k.lua index f236a3f..4d4fca0 100644 --- a/engine/bind/v4k.lua +++ b/engine/bind/v4k.lua @@ -2124,17 +2124,17 @@ enum { NETWORK_USERID = 5, NETWORK_COUNT , NETWORK_CAPACITY }; void network_rpc(const char *signature, void *function); void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline); void network_rpc_send(unsigned id, const char *cmdline); - bool server_bind(int max_clients, int port); - void server_poll(unsigned timeout_ms); - void client_poll(unsigned timeout_ms); - void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); - void server_broadcast_bin(const void *ptr, int len); - void server_broadcast_flags(const char *msg, uint64_t flags); - void server_broadcast(const char *msg); - void server_terminate(); - void server_send(int64_t handle, const char *msg); - void server_send_bin(int64_t handle, const void *ptr, int len); - void server_drop(int64_t handle); + bool server_bind(int max_clients, int port); + char** server_poll(unsigned timeout_ms); + char** client_poll(unsigned timeout_ms); + void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); + void server_broadcast_bin(const void *ptr, int len); + void server_broadcast_flags(const char *msg, uint64_t flags); + void server_broadcast(const char *msg); + void server_terminate(); + void server_send(int64_t handle, const char *msg); + void server_send_bin(int64_t handle, const void *ptr, int len); + void server_drop(int64_t handle); int64_t client_join(const char *ip, int port); void* obj_malloc( int sz, ... ); void* obj_calloc( int sz, ... ); diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 4175b5e..c469157 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -15959,17 +15959,17 @@ API void network_rpc_send(unsigned id, const char *cmdline); // ----------------------------------------------------------------------------- // low-level api (sockets based) -API bool server_bind(int max_clients, int port); -API void server_poll(unsigned timeout_ms); -API void client_poll(unsigned timeout_ms); -API void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); -API void server_broadcast_bin(const void *ptr, int len); -API void server_broadcast_flags(const char *msg, uint64_t flags); -API void server_broadcast(const char *msg); -API void server_terminate(); -API void server_send(int64_t handle, const char *msg); -API void server_send_bin(int64_t handle, const void *ptr, int len); -API void server_drop(int64_t handle); +API bool server_bind(int max_clients, int port); +API char** server_poll(unsigned timeout_ms); +API char** client_poll(unsigned timeout_ms); +API void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); +API void server_broadcast_bin(const void *ptr, int len); +API void server_broadcast_flags(const char *msg, uint64_t flags); +API void server_broadcast(const char *msg); +API void server_terminate(); +API void server_send(int64_t handle, const char *msg); +API void server_send_bin(int64_t handle, const void *ptr, int len); +API void server_drop(int64_t handle); API int64_t client_join(const char *ip, int port); #define client_send_flags(msg,flags) server_broadcast(msg, flags) @@ -338834,8 +338834,6 @@ int enet_event_to_netsync(int ev) { } char** network_sync(unsigned timeout_ms) { - array_clear(events); - int64_t whoami = network_get(NETWORK_RANK); bool is_server = whoami == 0; bool is_client = !is_server; @@ -338875,12 +338873,12 @@ char** network_sync(unsigned timeout_ms) { client_poll(timeout_ms); } - array_push(events, NULL); return events; } -void server_poll(unsigned timeout_ms) { +char** server_poll(unsigned timeout_ms) { + array_clear(events); if(timeout_ms < 2) timeout_ms = 2; // network poll @@ -339012,9 +339010,13 @@ void server_poll(unsigned timeout_ms) { if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg)); } + + array_push(events, NULL); + return events; } -void client_poll(unsigned timeout_ms) { +char** client_poll(unsigned timeout_ms) { + array_clear(events); int64_t whoami = network_get(NETWORK_RANK); if(timeout_ms < 2) timeout_ms = 2; @@ -339118,6 +339120,9 @@ void client_poll(unsigned timeout_ms) { if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg)); } + + array_push(events, NULL); + return events; } int network_event(const char *msg, int *errcode, char **errstr) { diff --git a/engine/split/v4k_netsync.c b/engine/split/v4k_netsync.c index d2a2a42..5b587c9 100644 --- a/engine/split/v4k_netsync.c +++ b/engine/split/v4k_netsync.c @@ -372,8 +372,6 @@ int enet_event_to_netsync(int ev) { } char** network_sync(unsigned timeout_ms) { - array_clear(events); - int64_t whoami = network_get(NETWORK_RANK); bool is_server = whoami == 0; bool is_client = !is_server; @@ -413,12 +411,12 @@ char** network_sync(unsigned timeout_ms) { client_poll(timeout_ms); } - array_push(events, NULL); return events; } -void server_poll(unsigned timeout_ms) { +char** server_poll(unsigned timeout_ms) { + array_clear(events); if(timeout_ms < 2) timeout_ms = 2; // network poll @@ -550,9 +548,13 @@ void server_poll(unsigned timeout_ms) { if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg)); } + + array_push(events, NULL); + return events; } -void client_poll(unsigned timeout_ms) { +char** client_poll(unsigned timeout_ms) { + array_clear(events); int64_t whoami = network_get(NETWORK_RANK); if(timeout_ms < 2) timeout_ms = 2; @@ -656,6 +658,9 @@ void client_poll(unsigned timeout_ms) { if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg)); } + + array_push(events, NULL); + return events; } int network_event(const char *msg, int *errcode, char **errstr) { diff --git a/engine/split/v4k_netsync.h b/engine/split/v4k_netsync.h index b487adf..5dcbb45 100644 --- a/engine/split/v4k_netsync.h +++ b/engine/split/v4k_netsync.h @@ -56,17 +56,17 @@ API void network_rpc_send(unsigned id, const char *cmdline); // ----------------------------------------------------------------------------- // low-level api (sockets based) -API bool server_bind(int max_clients, int port); -API void server_poll(unsigned timeout_ms); -API void client_poll(unsigned timeout_ms); -API void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); -API void server_broadcast_bin(const void *ptr, int len); -API void server_broadcast_flags(const char *msg, uint64_t flags); -API void server_broadcast(const char *msg); -API void server_terminate(); -API void server_send(int64_t handle, const char *msg); -API void server_send_bin(int64_t handle, const void *ptr, int len); -API void server_drop(int64_t handle); +API bool server_bind(int max_clients, int port); +API char** server_poll(unsigned timeout_ms); +API char** client_poll(unsigned timeout_ms); +API void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); +API void server_broadcast_bin(const void *ptr, int len); +API void server_broadcast_flags(const char *msg, uint64_t flags); +API void server_broadcast(const char *msg); +API void server_terminate(); +API void server_send(int64_t handle, const char *msg); +API void server_send_bin(int64_t handle, const void *ptr, int len); +API void server_drop(int64_t handle); API int64_t client_join(const char *ip, int port); #define client_send_flags(msg,flags) server_broadcast(msg, flags) diff --git a/engine/v4k.c b/engine/v4k.c index 87679b8..d6d8d2f 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -9849,8 +9849,6 @@ int enet_event_to_netsync(int ev) { } char** network_sync(unsigned timeout_ms) { - array_clear(events); - int64_t whoami = network_get(NETWORK_RANK); bool is_server = whoami == 0; bool is_client = !is_server; @@ -9890,12 +9888,12 @@ char** network_sync(unsigned timeout_ms) { client_poll(timeout_ms); } - array_push(events, NULL); return events; } -void server_poll(unsigned timeout_ms) { +char** server_poll(unsigned timeout_ms) { + array_clear(events); if(timeout_ms < 2) timeout_ms = 2; // network poll @@ -10027,9 +10025,13 @@ void server_poll(unsigned timeout_ms) { if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg)); } + + array_push(events, NULL); + return events; } -void client_poll(unsigned timeout_ms) { +char** client_poll(unsigned timeout_ms) { + array_clear(events); int64_t whoami = network_get(NETWORK_RANK); if(timeout_ms < 2) timeout_ms = 2; @@ -10133,6 +10135,9 @@ void client_poll(unsigned timeout_ms) { if(msg) array_push(events, stringf("%d %s", enet_event_to_netsync(event.type), msg)); } + + array_push(events, NULL); + return events; } int network_event(const char *msg, int *errcode, char **errstr) { diff --git a/engine/v4k.h b/engine/v4k.h index bbeb7cb..870bf2e 100644 --- a/engine/v4k.h +++ b/engine/v4k.h @@ -2042,17 +2042,17 @@ API void network_rpc_send(unsigned id, const char *cmdline); // ----------------------------------------------------------------------------- // low-level api (sockets based) -API bool server_bind(int max_clients, int port); -API void server_poll(unsigned timeout_ms); -API void client_poll(unsigned timeout_ms); -API void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); -API void server_broadcast_bin(const void *ptr, int len); -API void server_broadcast_flags(const char *msg, uint64_t flags); -API void server_broadcast(const char *msg); -API void server_terminate(); -API void server_send(int64_t handle, const char *msg); -API void server_send_bin(int64_t handle, const void *ptr, int len); -API void server_drop(int64_t handle); +API bool server_bind(int max_clients, int port); +API char** server_poll(unsigned timeout_ms); +API char** client_poll(unsigned timeout_ms); +API void server_broadcast_bin_flags(const void *ptr, int len, uint64_t flags); +API void server_broadcast_bin(const void *ptr, int len); +API void server_broadcast_flags(const char *msg, uint64_t flags); +API void server_broadcast(const char *msg); +API void server_terminate(); +API void server_send(int64_t handle, const char *msg); +API void server_send_bin(int64_t handle, const void *ptr, int len); +API void server_drop(int64_t handle); API int64_t client_join(const char *ip, int port); #define client_send_flags(msg,flags) server_broadcast(msg, flags) diff --git a/engine/v4k.html b/engine/v4k.html index de916d8..fd956b4 100644 --- a/engine/v4k.html +++ b/engine/v4k.html @@ -596,7 +596,7 @@ details > summary::-webkit-details-marker { |Version: | 2023.7 | |:--------------|:------------| |Branch: | main | -|Commit: | 55 | +|Commit: | 56 | # [Vยท4ยทK 2023.7 ](https://dev.v4.games/zaklaus/v4k) @@ -6693,7 +6693,7 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str -
๐Ÿ„ต API void server_poll(unsigned timeout_ms); +
๐Ÿ„ต API char** server_poll(unsigned timeout_ms); Under construction. Yet to be documented. @@ -6702,7 +6702,7 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
-
๐Ÿ„ต API void client_poll(unsigned timeout_ms); +
๐Ÿ„ต API char** client_poll(unsigned timeout_ms); Under construction. Yet to be documented. @@ -8644,8 +8644,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str ## shaders - -
extern const char* const fs_0_0_shadowmap_lit; + +
๐Ÿ„ด extern const char* const fs_0_0_shadowmap_lit; Under construction. Yet to be documented. @@ -8653,8 +8653,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_0_0_shadowmap_unlit; + +
๐Ÿ„ด extern const char* const fs_0_0_shadowmap_unlit; Under construction. Yet to be documented. @@ -8662,8 +8662,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_24_4_sprite; + +
๐Ÿ„ด extern const char* const fs_24_4_sprite; Under construction. Yet to be documented. @@ -8671,8 +8671,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_2_4_preamble; + +
๐Ÿ„ด extern const char* const fs_2_4_preamble; Under construction. Yet to be documented. @@ -8680,8 +8680,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_2_4_texel_inv_gamma; + +
๐Ÿ„ด extern const char* const fs_2_4_texel_inv_gamma; Under construction. Yet to be documented. @@ -8689,8 +8689,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_2_4_texel_ycbr_gamma_saturation; + +
๐Ÿ„ด extern const char* const fs_2_4_texel_ycbr_gamma_saturation; Under construction. Yet to be documented. @@ -8698,8 +8698,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_32_4_model; + +
๐Ÿ„ด extern const char* const fs_32_4_model; Under construction. Yet to be documented. @@ -8707,8 +8707,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_32_4_model_basic; + +
๐Ÿ„ด extern const char* const fs_32_4_model_basic; Under construction. Yet to be documented. @@ -8716,8 +8716,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_3_4_skybox; + +
๐Ÿ„ด extern const char* const fs_3_4_skybox; Under construction. Yet to be documented. @@ -8725,8 +8725,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_3_4_skybox_rayleigh; + +
๐Ÿ„ด extern const char* const fs_3_4_skybox_rayleigh; Under construction. Yet to be documented. @@ -8734,8 +8734,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const fs_main_shadertoy; + +
๐Ÿ„ด extern const char* const fs_main_shadertoy; Under construction. Yet to be documented. @@ -8743,8 +8743,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const vs_0_2_fullscreen_quad_A; + +
๐Ÿ„ด extern const char* const vs_0_2_fullscreen_quad_A; Under construction. Yet to be documented. @@ -8752,8 +8752,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const vs_0_2_fullscreen_quad_B; + +
๐Ÿ„ด extern const char* const vs_0_2_fullscreen_quad_B; Under construction. Yet to be documented. @@ -8761,8 +8761,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const vs_0_2_fullscreen_quad_B_flipped; + +
๐Ÿ„ด extern const char* const vs_0_2_fullscreen_quad_B_flipped; Under construction. Yet to be documented. @@ -8770,8 +8770,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const vs_323444143_16_332_model; + +
๐Ÿ„ด extern const char* const vs_323444143_16_332_model; Under construction. Yet to be documented. @@ -8779,8 +8779,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const vs_324_24_sprite; + +
๐Ÿ„ด extern const char* const vs_324_24_sprite; Under construction. Yet to be documented. @@ -8788,8 +8788,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const vs_332_32; + +
๐Ÿ„ด extern const char* const vs_332_32; Under construction. Yet to be documented. @@ -8797,8 +8797,8 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
- -
extern const char* const vs_3_3_skybox; + +
๐Ÿ„ด extern const char* const vs_3_3_skybox; Under construction. Yet to be documented.