eco2d/code/game/src/entity_view.h

97 lines
2.4 KiB
C
Raw Normal View History

2021-05-05 09:25:05 +00:00
#pragma once
#include "system.h"
2021-08-25 21:36:20 +00:00
#include "assets.h"
2021-08-30 15:50:05 +00:00
#include "items.h"
#include "modules/components.h"
2021-05-05 09:25:05 +00:00
#define ZPL_PICO
#include "zpl.h"
2021-05-06 18:24:01 +00:00
typedef enum {
2021-07-27 15:57:50 +00:00
EKIND_SERVER = 0,
EKIND_PLAYER,
2021-08-25 21:36:20 +00:00
EKIND_ITEM,
2021-08-09 13:35:47 +00:00
EKIND_VEHICLE,
2021-07-27 15:57:50 +00:00
EKIND_DEMO_NPC,
EKIND_MONSTER,
EKIND_MACRO_BOT,
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-09 22:40:25 +00:00
typedef enum {
ETRAN_NONE,
ETRAN_FADEOUT,
ETRAN_FADEIN,
ETRAN_REMOVE,
FORCE_ETRAN_UINT8 = UINT8_MAX
} entity_transition_effect;
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
2021-11-03 17:38:32 +00:00
uint16_t blocks_used;
uint16_t blocks[256];
uint16_t 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;
2021-08-09 18:58:52 +00:00
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;
// NOTE(zaklaus): inventory
uint8_t has_items;
ItemDrop items[ITEMS_INVENTORY_SIZE];
uint8_t selected_item;
2021-08-25 21:36:20 +00:00
// 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
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);
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);
void entity_view_remove_chunk_texture(entity_view_tbl *map, uint64_t ent_id);