eco2d/code/common/entity_view.h

51 lines
1.2 KiB
C
Raw Normal View History

2021-05-05 09:25:05 +00:00
#pragma once
#include "system.h"
#define ZPL_PICO
#include "zpl.h"
2021-05-06 16:26:52 +00:00
#include "packet_utils.h"
2021-05-06 18:24:01 +00:00
typedef enum {
EKIND_PLAYER = 0,
2021-05-08 09:05:15 +00:00
EKIND_THING,
2021-05-06 18:24:01 +00:00
EKIND_CHUNK,
FORCE_EKIND_UINT16 = UINT16_MAX
} entity_kind;
typedef enum {
EFLAG_INTERP = (1 << 0),
FORCE_EFLAG_UINT16 = UINT16_MAX
} entity_flag;
2021-05-05 09:25:05 +00:00
typedef struct entity_view {
2021-05-06 18:24:01 +00:00
entity_kind kind;
entity_flag flag;
2021-05-08 15:42:47 +00:00
float x;
float y;
float vx;
float vy;
float tx;
float ty;
// NOTE(zaklaus): internals
uint8_t layer_id;
2021-05-09 14:41:19 +00:00
uint64_t last_update;
2021-05-05 09:25:05 +00:00
} entity_view;
ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view);
2021-05-06 16:26:52 +00:00
pkt_desc pkt_entity_view_desc[];
2021-05-06 15:30:38 +00:00
void entity_view_init(entity_view_tbl *map);
void entity_view_free(entity_view_tbl *map);
2021-05-05 09:25:05 +00:00
2021-05-06 15:30:38 +00:00
void entity_view_update_or_create(entity_view_tbl *map, uint64_t ent_id, entity_view data);
void entity_view_destroy(entity_view_tbl *map, uint64_t ent_id);
2021-05-05 09:25:05 +00:00
2021-05-06 15:30:38 +00:00
entity_view *entity_view_get(entity_view_tbl *map, uint64_t ent_id);
void entity_view_map(entity_view_tbl *map, void (*map_proc)(uint64_t key, entity_view value));
2021-05-06 16:26:52 +00:00
2021-05-06 18:24:01 +00:00
size_t entity_view_pack_struct(void *data, size_t len, entity_view view);
2021-05-06 16:26:52 +00:00
entity_view entity_view_unpack_struct(void *data, size_t len);