code: Add drawable component
parent
2500cbb101
commit
a2604b08a5
|
@ -13,6 +13,7 @@ ECS_STRUCT(Input, {
|
|||
|
||||
typedef struct {
|
||||
ECS_DECLARE_COMPONENT(Input);
|
||||
ECS_DECLARE_ENTITY(EcsActor);
|
||||
ECS_DECLARE_ENTITY(EcsPlayer);
|
||||
ECS_DECLARE_ENTITY(EcsBuilder);
|
||||
ECS_DECLARE_TYPE(Player);
|
||||
|
@ -23,6 +24,7 @@ typedef struct {
|
|||
ECS_IMPORT_COMPONENT(handles, Input);\
|
||||
ECS_IMPORT_TYPE(handles, Player);\
|
||||
ECS_IMPORT_TYPE(handles, Builder);\
|
||||
ECS_IMPORT_ENTITY(handles, EcsActor);\
|
||||
ECS_IMPORT_ENTITY(handles, EcsPlayer);\
|
||||
ECS_IMPORT_ENTITY(handles, EcsBuilder);\
|
||||
|
||||
|
@ -36,14 +38,16 @@ static inline void ControllersImport(ecs_world_t *ecs) {
|
|||
ECS_IMPORT(ecs, FlecsMeta);
|
||||
ECS_META(ecs, Input);
|
||||
|
||||
ECS_TAG(ecs, EcsActor);
|
||||
ECS_TAG(ecs, EcsPlayer);
|
||||
ECS_TAG(ecs, EcsBuilder);
|
||||
|
||||
ECS_PREFAB(ecs, Base, general.Position, physics.Velocity, Input);
|
||||
ECS_TYPE(ecs, Player, INSTANCEOF | Base, SWITCH | physics.Movement, CASE | physics.Walking, EcsPlayer);
|
||||
ECS_TYPE(ecs, Builder, INSTANCEOF | Base, SWITCH | physics.Movement, CASE | physics.Flying, EcsBuilder);
|
||||
ECS_TYPE(ecs, Player, INSTANCEOF | Base, SWITCH | physics.Movement, CASE | physics.Walking, EcsActor, EcsPlayer);
|
||||
ECS_TYPE(ecs, Builder, INSTANCEOF | Base, SWITCH | physics.Movement, CASE | physics.Flying, EcsActor, EcsBuilder);
|
||||
|
||||
ECS_SET_COMPONENT(Input);
|
||||
ECS_SET_ENTITY(EcsActor);
|
||||
ECS_SET_ENTITY(EcsPlayer);
|
||||
ECS_SET_ENTITY(EcsBuilder);
|
||||
ECS_SET_TYPE(Builder);
|
||||
|
|
|
@ -2,11 +2,17 @@
|
|||
#include "flecs/flecs.h"
|
||||
#include "flecs/flecs_meta.h"
|
||||
|
||||
#define DRAWABLE_MAX_FILENAME 80
|
||||
|
||||
ECS_STRUCT(Vector2D, {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
});
|
||||
|
||||
ECS_STRUCT(Drawable, {
|
||||
char filename[DRAWABLE_MAX_FILENAME];
|
||||
});
|
||||
|
||||
typedef Vector2D Chunk;
|
||||
typedef Vector2D Position;
|
||||
|
||||
|
@ -14,12 +20,14 @@ typedef struct {
|
|||
ECS_DECLARE_COMPONENT(Chunk);
|
||||
ECS_DECLARE_COMPONENT(Position);
|
||||
ECS_DECLARE_COMPONENT(Vector2D);
|
||||
ECS_DECLARE_COMPONENT(Drawable);
|
||||
} General;
|
||||
|
||||
#define GeneralImportHandles(handles)\
|
||||
ECS_IMPORT_COMPONENT(handles, Chunk);\
|
||||
ECS_IMPORT_COMPONENT(handles, Vector2D);\
|
||||
ECS_IMPORT_COMPONENT(handles, Position);
|
||||
ECS_IMPORT_COMPONENT(handles, Position);\
|
||||
ECS_IMPORT_COMPONENT(handles, Drawable);\
|
||||
|
||||
static inline void GeneralImport(ecs_world_t *ecs) {
|
||||
ECS_MODULE(ecs, General);
|
||||
|
@ -31,8 +39,10 @@ static inline void GeneralImport(ecs_world_t *ecs) {
|
|||
ECS_IMPORT(ecs, FlecsMeta);
|
||||
|
||||
ECS_META(ecs, Vector2D);
|
||||
ECS_META(ecs, Drawable);
|
||||
|
||||
ECS_SET_COMPONENT(Chunk);
|
||||
ECS_SET_COMPONENT(Vector2D);
|
||||
ECS_SET_COMPONENT(Position);
|
||||
ECS_SET_COMPONENT(Drawable);
|
||||
}
|
||||
|
|
|
@ -129,12 +129,14 @@ void network_server_update(void *data) {
|
|||
}
|
||||
|
||||
uint64_t network_client_create(uint16_t peer_id) {
|
||||
ECS_IMPORT(world_ecs(), General);
|
||||
ECS_IMPORT(world_ecs(), Controllers);
|
||||
ECS_IMPORT(world_ecs(), Net);
|
||||
|
||||
ecs_entity_t e = ecs_new(world_ecs(), Player);
|
||||
ecs_add(world_ecs(), e, EcsClient);
|
||||
ecs_set(world_ecs(), e, ClientInfo, {peer_id});
|
||||
ecs_set(world_ecs(), e, Drawable, {"player.png"});
|
||||
|
||||
librg_entity_track(world_tracker(), e);
|
||||
librg_entity_owner_set(world_tracker(), e, peer_id);
|
||||
|
|
Loading…
Reference in New Issue