layered streaming

isolation_bkp/dynres
Dominik Madarász 2021-05-09 16:41:19 +02:00
parent 7c39e51a07
commit 30da3e9a1b
5 changed files with 42 additions and 14 deletions

View File

@ -4,7 +4,7 @@
#include "game.h" #include "game.h"
#define PREDICT_SMOOTH_FACTOR_LO 0.80 #define PREDICT_SMOOTH_FACTOR_LO 0.80
#define PREDICT_SMOOTH_FACTOR_HI 0.007 #define PREDICT_SMOOTH_FACTOR_HI 0.12
static inline float map_factor(float x) { static inline float map_factor(float x) {
x = 1.0f - zpl_clamp01(x); x = 1.0f - zpl_clamp01(x);

View File

@ -1,20 +1,15 @@
#include "zpl.h"
#include "world_view.h" #include "world_view.h"
#include "entity_view.h" #include "entity_view.h"
#include "prediction.h" #include "prediction.h"
#include "librg.h" #include "librg.h"
#include "zpl.h" #include "world/world.h"
int32_t tracker_read_remove(librg_world *w, librg_event *e) { int32_t tracker_read_remove(librg_world *w, librg_event *e) {
int64_t owner_id = librg_event_owner_get(w, e); int64_t owner_id = librg_event_owner_get(w, e);
int64_t entity_id = librg_event_entity_get(w, e); int64_t entity_id = librg_event_entity_get(w, e);
zpl_printf("[INFO] An entity %d was removed for owner: %d\n", (int)entity_id, (int)owner_id); zpl_printf("[INFO] An entity %d was removed for owner: %d\n", (int)entity_id, (int)owner_id);
world_view *view = (world_view*)librg_world_userdata_get(w); world_view *view = (world_view*)librg_world_userdata_get(w);
entity_view *d = entity_view_get(&view->entities, entity_id);
if (d && d->layer_id < view->active_layer_id) {
// NOTE(zaklaus): reject updates from slower layers
return 0;
}
entity_view_destroy(&view->entities, entity_id); entity_view_destroy(&view->entities, entity_id);
return 0; return 0;
} }
@ -27,11 +22,18 @@ int32_t tracker_read_update(librg_world *w, librg_event *e) {
entity_view data = entity_view_unpack_struct(buffer, actual_length); entity_view data = entity_view_unpack_struct(buffer, actual_length);
entity_view *d = entity_view_get(&view->entities, entity_id); entity_view *d = entity_view_get(&view->entities, entity_id);
data.layer_id = view->active_layer_id; #if 1
if (d && d->layer_id < data.layer_id) { if (d && d->layer_id < view->active_layer_id) {
// NOTE(zaklaus): reject updates from slower layers if (zpl_time_rel_ms() - d->last_update > WORLD_TRACKER_UPDATE_NORMAL_MS) {
return 0; d->layer_id = zpl_min(WORLD_TRACKER_LAYERS-1, d->layer_id+1);
} }
// NOTE(zaklaus): reject updates from slower layers
else return 0;
}
#endif
data.last_update = zpl_time_rel_ms();
data.layer_id = view->active_layer_id;
predict_receive_update(d, &data); predict_receive_update(d, &data);
entity_view_update_or_create(&view->entities, entity_id, data); entity_view_update_or_create(&view->entities, entity_id, data);
return 0; return 0;
@ -44,7 +46,12 @@ int32_t tracker_read_create(librg_world *w, librg_event *e) {
size_t actual_length = librg_event_size_get(w, e); size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e); char *buffer = librg_event_buffer_get(w, e);
world_view *view = (world_view*)librg_world_userdata_get(w); world_view *view = (world_view*)librg_world_userdata_get(w);
#ifdef WORLD_LAYERING
if (view->active_layer_id != WORLD_TRACKER_LAYERS-1) {
// NOTE(zaklaus): reject updates from smaller layers
return 0;
}
#endif
entity_view data = entity_view_unpack_struct(buffer, actual_length); entity_view data = entity_view_unpack_struct(buffer, actual_length);
data.layer_id = view->active_layer_id; data.layer_id = view->active_layer_id;
if (data.flag & EFLAG_INTERP) { if (data.flag & EFLAG_INTERP) {

View File

@ -30,6 +30,7 @@ typedef struct entity_view {
// NOTE(zaklaus): internals // NOTE(zaklaus): internals
uint8_t layer_id; uint8_t layer_id;
uint64_t last_update;
} entity_view; } entity_view;
ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view); ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view);

View File

@ -17,6 +17,7 @@ typedef struct {
uint16_t chunk_amount; uint16_t chunk_amount;
uint16_t dim; uint16_t dim;
uint64_t tracker_update[3]; uint64_t tracker_update[3];
uint8_t active_layer_id;
ecs_world_t *ecs; ecs_world_t *ecs;
librg_world *tracker; librg_world *tracker;
world_pkt_reader_proc *reader_proc; world_pkt_reader_proc *reader_proc;
@ -61,6 +62,12 @@ entity_view world_build_entity_view(int64_t e) {
int32_t tracker_write_create(librg_world *w, librg_event *e) { int32_t tracker_write_create(librg_world *w, librg_event *e) {
int64_t owner_id = librg_event_owner_get(w, e); int64_t owner_id = librg_event_owner_get(w, e);
int64_t entity_id = librg_event_entity_get(w, e); int64_t entity_id = librg_event_entity_get(w, e);
#ifdef WORLD_LAYERING
if (world.active_layer_id != WORLD_TRACKER_LAYERS-1) {
// NOTE(zaklaus): reject updates from smaller layers
return LIBRG_WRITE_REJECT;
}
#endif
size_t actual_length = librg_event_size_get(w, e); size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e); char *buffer = librg_event_buffer_get(w, e);
@ -68,6 +75,12 @@ int32_t tracker_write_create(librg_world *w, librg_event *e) {
} }
int32_t tracker_write_remove(librg_world *w, librg_event *e) { int32_t tracker_write_remove(librg_world *w, librg_event *e) {
#ifdef WORLD_LAYERING
if (world.active_layer_id != WORLD_TRACKER_LAYERS-1) {
// NOTE(zaklaus): reject updates from smaller layers
return LIBRG_WRITE_REJECT;
}
#endif
return 0; return 0;
} }
@ -161,6 +174,7 @@ static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius)
ecs_iter_t it = ecs_query_iter(query); ecs_iter_t it = ecs_query_iter(query);
static char buffer[WORLD_LIBRG_BUFSIZ] = {0}; static char buffer[WORLD_LIBRG_BUFSIZ] = {0};
world.active_layer_id = ticker;
while (ecs_query_next(&it)) { while (ecs_query_next(&it)) {
ClientInfo *p = ecs_column(&it, ClientInfo, 1); ClientInfo *p = ecs_column(&it, ClientInfo, 1);
@ -169,6 +183,11 @@ static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius)
for (int i = 0; i < it.count; i++) { for (int i = 0; i < it.count; i++) {
size_t datalen = WORLD_LIBRG_BUFSIZ; size_t datalen = WORLD_LIBRG_BUFSIZ;
// TODO(zaklaus): SUPER TEMPORARY HOT !!! simulate variable radius queries
{
librg_entity_radius_set(world_tracker(), p[i].peer, radius);
}
// TODO(zaklaus): push radius once librg patch comes in // TODO(zaklaus): push radius once librg patch comes in
int32_t result = librg_world_write(world_tracker(), p[i].peer, buffer, &datalen, NULL); int32_t result = librg_world_write(world_tracker(), p[i].peer, buffer, &datalen, NULL);
@ -186,9 +205,9 @@ static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius)
int32_t world_update() { int32_t world_update() {
ecs_progress(world.ecs, 0); ecs_progress(world.ecs, 0);
//world_tracker_update(0, WORLD_TRACKER_UPDATE_FAST_MS, 2); world_tracker_update(0, WORLD_TRACKER_UPDATE_FAST_MS, 2);
world_tracker_update(1, WORLD_TRACKER_UPDATE_NORMAL_MS, 4); world_tracker_update(1, WORLD_TRACKER_UPDATE_NORMAL_MS, 4);
//world_tracker_update(2, WORLD_TRACKER_UPDATE_SLOW_MS, 6); world_tracker_update(2, WORLD_TRACKER_UPDATE_SLOW_MS, 6);
return 0; return 0;
} }

View File

@ -11,6 +11,7 @@
#define WORLD_ERROR_INVALID_BUFFER -0x0004 #define WORLD_ERROR_INVALID_BUFFER -0x0004
#define WORLD_ERROR_TRACKER_FAILED -0x0005 #define WORLD_ERROR_TRACKER_FAILED -0x0005
#define WORLD_LAYERING 0
#define WORLD_TRACKER_LAYERS 3 #define WORLD_TRACKER_LAYERS 3
#define WORLD_TRACKER_UPDATE_FAST_MS 10 #define WORLD_TRACKER_UPDATE_FAST_MS 10
#define WORLD_TRACKER_UPDATE_NORMAL_MS 100 #define WORLD_TRACKER_UPDATE_NORMAL_MS 100