update librg every 100ms
parent
ed3eaa2b89
commit
f5f35d0187
|
@ -15,6 +15,7 @@ typedef struct {
|
||||||
uint16_t block_size;
|
uint16_t block_size;
|
||||||
uint16_t chunk_size;
|
uint16_t chunk_size;
|
||||||
uint16_t world_size;
|
uint16_t world_size;
|
||||||
|
uint64_t tracker_update;
|
||||||
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;
|
||||||
|
@ -24,6 +25,8 @@ typedef struct {
|
||||||
|
|
||||||
static world_data world = {0};
|
static world_data world = {0};
|
||||||
|
|
||||||
|
#define WORLD_TRACKER_UPDATE_MS 100
|
||||||
|
|
||||||
int32_t world_gen();
|
int32_t world_gen();
|
||||||
|
|
||||||
int32_t world_write_update(librg_world *w, librg_event *e) {
|
int32_t world_write_update(librg_world *w, librg_event *e) {
|
||||||
|
@ -93,6 +96,7 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
|
||||||
world.seed = seed;
|
world.seed = seed;
|
||||||
world_init_minimal(block_size, chunk_size, world_size, reader_proc, writer_proc);
|
world_init_minimal(block_size, chunk_size, world_size, reader_proc, writer_proc);
|
||||||
world.data = zpl_malloc(sizeof(uint8_t)*world.size);
|
world.data = zpl_malloc(sizeof(uint8_t)*world.size);
|
||||||
|
world.tracker_update = 0;
|
||||||
|
|
||||||
if (!world.data) {
|
if (!world.data) {
|
||||||
return WORLD_ERROR_OUTOFMEM;
|
return WORLD_ERROR_OUTOFMEM;
|
||||||
|
@ -132,9 +136,9 @@ int32_t world_destroy(void) {
|
||||||
return WORLD_ERROR_NONE;
|
return WORLD_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t world_update() {
|
static void world_tracker_update(void) {
|
||||||
ecs_progress(world.ecs, 0);
|
if (world.tracker_update > zpl_time_rel_ms()) return;
|
||||||
|
world.tracker_update = zpl_time_rel_ms() + WORLD_TRACKER_UPDATE_MS;
|
||||||
ECS_IMPORT(world.ecs, Net);
|
ECS_IMPORT(world.ecs, Net);
|
||||||
ecs_query_t *query = ecs_query_new(world.ecs, "Net.ClientInfo");
|
ecs_query_t *query = ecs_query_new(world.ecs, "Net.ClientInfo");
|
||||||
|
|
||||||
|
@ -158,6 +162,12 @@ int32_t world_update() {
|
||||||
pkt_world_write(MSG_ID_LIBRG_UPDATE, pkt_send_librg_update_encode(buffer, datalen), 1, p[i].peer);
|
pkt_world_write(MSG_ID_LIBRG_UPDATE, pkt_send_librg_update_encode(buffer, datalen), 1, p[i].peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t world_update() {
|
||||||
|
ecs_progress(world.ecs, 0);
|
||||||
|
|
||||||
|
world_tracker_update();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue