eco2d/code/foundation/src/world/entity_view.h

132 lines
3.1 KiB
C
Raw Normal View History

2021-05-05 09:25:05 +00:00
#pragma once
#include "platform/system.h"
2022-09-29 18:11:47 +00:00
#include "models/assets.h"
2022-09-29 14:16:06 +00:00
#include "models/items.h"
2021-08-30 15:50:05 +00:00
2021-05-05 09:25:05 +00:00
#define ZPL_PICO
#include "zpl.h"
#define MAX_CRAFTABLES 32
2023-01-15 16:44:48 +00:00
#define _CLASSES\
X(EKIND_SERVER)\
X(EKIND_PLAYER)\
X(EKIND_ITEM)\
X(EKIND_DEVICE)\
2023-02-02 14:40:48 +00:00
X(EKIND_SPRITE)\
X(EKIND_WEAPON)\
2023-01-15 16:44:48 +00:00
X(EKIND_VEHICLE)\
X(EKIND_DEMO_NPC)\
X(EKIND_MONSTER)\
X(EKIND_MACRO_BOT)\
X(EKIND_CHUNK)
2021-05-06 18:24:01 +00:00
typedef enum {
2023-01-15 16:44:48 +00:00
#define X(id) id,
_CLASSES
#undef X
FORCE_EKIND_UINT16 = UINT16_MAX
2021-05-06 18:24:01 +00:00
} entity_kind;
typedef enum {
EFLAG_INTERP = (1 << 0),
FORCE_EFLAG_UINT16 = UINT16_MAX
} entity_flag;
2021-05-09 22:40:25 +00:00
typedef enum {
ETRAN_NONE,
ETRAN_FADEOUT,
ETRAN_FADEIN,
ETRAN_REMOVE,
FORCE_ETRAN_UINT8 = UINT8_MAX
} entity_transition_effect;
2023-01-15 16:44:48 +00:00
extern const char *class_names[];
2021-05-05 09:25:05 +00:00
typedef struct entity_view {
2021-05-09 22:40:25 +00:00
int64_t ent_id;
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;
2021-07-27 16:34:31 +00:00
float hp;
float max_hp;
// TODO(zaklaus): Find a way to stream dynamic arrays
2022-10-16 10:30:50 +00:00
uint32_t chk_id;
2021-11-03 18:04:34 +00:00
uint8_t blocks_used;
block_id blocks[256];
block_id outer_blocks[256];
2021-07-27 11:30:43 +00:00
uint32_t color;
uint8_t is_dirty;
2021-07-18 18:30:27 +00:00
int64_t tex;
2021-08-09 18:58:52 +00:00
// NOTE(zaklaus): vehicle
float heading, theading;
2021-09-09 07:54:02 +00:00
bool inside_vehicle;
2022-09-29 15:35:43 +00:00
uint32_t veh_kind;
2021-08-25 21:36:20 +00:00
// NOTE(zaklaus): items, ...
asset_id asset;
2021-08-30 15:50:05 +00:00
uint32_t quantity;
2022-09-29 20:49:40 +00:00
float durability;
2022-09-29 16:06:08 +00:00
// NOTE(zaklaus): device progress bar
bool is_producer;
2022-09-29 16:06:08 +00:00
uint32_t progress_active;
float progress_value;
2023-02-02 14:40:48 +00:00
// sprite index
int spritesheet;
int frame;
2021-08-30 15:50:05 +00:00
// NOTE(zaklaus): inventory
uint8_t has_items;
2022-09-28 13:17:33 +00:00
Item items[ITEMS_INVENTORY_SIZE];
2021-08-30 15:50:05 +00:00
uint8_t selected_item;
2022-08-09 14:46:23 +00:00
// NOTE(zaklaus): storage interface
uint8_t has_storage_items;
2022-09-28 13:17:33 +00:00
Item storage_items[ITEMS_CONTAINER_SIZE];
2022-08-09 14:46:23 +00:00
uint8_t storage_selected_item;
// NOTE(zaklaus): craftable recipes
2023-01-15 17:43:03 +00:00
uint16_t craftables[MAX_CRAFTABLES];
2022-08-09 14:46:23 +00:00
// NOTE(zaklaus): entity picking
uint64_t pick_ent;
uint64_t sel_ent;
// NOTE(zaklaus): internals
uint8_t layer_id;
2021-05-09 14:41:19 +00:00
uint64_t last_update;
2021-05-09 22:40:25 +00:00
// NOTE(zaklaus): fade in-out effect
entity_transition_effect tran_effect;
float tran_time;
2021-05-05 09:25:05 +00:00
} entity_view;
ZPL_TABLE_DECLARE(, entity_view_tbl, entity_view_tbl_, entity_view);
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);
2021-07-18 18:30:27 +00:00
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
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);
2021-05-09 22:40:25 +00:00
void entity_view_mark_for_removal(entity_view_tbl *map, uint64_t ent_id);
2021-05-10 11:27:01 +00:00
void entity_view_mark_for_fadein(entity_view_tbl *map, uint64_t ent_id);
2021-07-18 18:30:27 +00:00
void entity_view_update_chunk_texture(entity_view_tbl *map, uint64_t ent_id, void *view);
2022-07-31 14:34:47 +00:00
void entity_view_remove_chunk_texture(entity_view_tbl *map, uint64_t ent_id);