code: refactor components

isolation_bkp/dynres
Dominik Madarász 2021-01-19 11:19:12 +01:00
parent 294d35c0c4
commit 8f44f5eec9
11 changed files with 92 additions and 81 deletions

View File

@ -1,3 +1,5 @@
file(GLOB COMPONENTS header/components/*.h source/components/*.c)
add_executable(eco2d-server add_executable(eco2d-server
source/main.c source/main.c
source/network.c source/network.c
@ -14,10 +16,7 @@ add_executable(eco2d-server
header/world/blocks.h header/world/blocks.h
header/world/blocks_info.h header/world/blocks_info.h
header/components/net.h ${COMPONENTS}
header/components/physics.h
header/components/general.h
header/components/controllers.h
) )
include_directories(eco2d-server header) include_directories(eco2d-server header)

View File

@ -2,9 +2,6 @@
#include "flecs/flecs.h" #include "flecs/flecs.h"
#include "flecs/flecs_meta.h" #include "flecs/flecs_meta.h"
#include "components/general.h"
#include "components/physics.h"
ECS_STRUCT(Input, { ECS_STRUCT(Input, {
double x; double x;
double y; double y;
@ -28,28 +25,4 @@ typedef struct {
ECS_IMPORT_ENTITY(handles, EcsPlayer);\ ECS_IMPORT_ENTITY(handles, EcsPlayer);\
ECS_IMPORT_ENTITY(handles, EcsBuilder);\ ECS_IMPORT_ENTITY(handles, EcsBuilder);\
static inline void ControllersImport(ecs_world_t *ecs) { void ControllersImport(ecs_world_t *ecs);
ECS_MODULE(ecs, Controllers);
ecs_set_name_prefix(ecs, "Controllers");
ECS_IMPORT(ecs, General);
ECS_IMPORT(ecs, Physics);
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, EcsActor);
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);
ECS_SET_TYPE(Player);
}

View File

@ -2,8 +2,6 @@
#include "flecs/flecs.h" #include "flecs/flecs.h"
#include "flecs/flecs_meta.h" #include "flecs/flecs_meta.h"
#include "assets.h"
ECS_STRUCT(Vector2D, { ECS_STRUCT(Vector2D, {
int16_t x; int16_t x;
int16_t y; int16_t y;
@ -29,20 +27,4 @@ typedef struct {
ECS_IMPORT_COMPONENT(handles, Position);\ ECS_IMPORT_COMPONENT(handles, Position);\
ECS_IMPORT_COMPONENT(handles, Drawable);\ ECS_IMPORT_COMPONENT(handles, Drawable);\
static inline void GeneralImport(ecs_world_t *ecs) { void GeneralImport(ecs_world_t *ecs);
ECS_MODULE(ecs, General);
ecs_set_name_prefix(ecs, "General");
ECS_COMPONENT(ecs, Chunk);
ECS_COMPONENT(ecs, Position);
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);
}

View File

@ -15,17 +15,4 @@ typedef struct {
ECS_IMPORT_ENTITY(handles, EcsClient);\ ECS_IMPORT_ENTITY(handles, EcsClient);\
ECS_IMPORT_COMPONENT(handles, ClientInfo);\ ECS_IMPORT_COMPONENT(handles, ClientInfo);\
static inline void NetImport(ecs_world_t *ecs) { void NetImport(ecs_world_t *ecs);
ECS_MODULE(ecs, Net);
ecs_set_name_prefix(ecs, "Net");
ECS_TAG(ecs, EcsClient);
ECS_IMPORT(ecs, FlecsMeta);
ECS_META(ecs, ClientInfo);
ECS_EXPORT_ENTITY(EcsClient);
ECS_EXPORT_COMPONENT(ClientInfo);
}

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "flecs/flecs.h" #include "flecs/flecs.h"
#include "components/general.h" #include "components/general.h"
typedef Vector2D Velocity; typedef Vector2D Velocity;
@ -17,18 +18,4 @@ typedef struct {
ECS_IMPORT_ENTITY(handles, Flying);\ ECS_IMPORT_ENTITY(handles, Flying);\
ECS_IMPORT_COMPONENT(handles, Velocity);\ ECS_IMPORT_COMPONENT(handles, Velocity);\
static inline void PhysicsImport(ecs_world_t *ecs) { void PhysicsImport(ecs_world_t *ecs);
ECS_MODULE(ecs, Physics);
ecs_set_name_prefix(ecs, "Physics");
ECS_TAG(ecs, Walking);
ECS_TAG(ecs, Flying);
ECS_TYPE(ecs, Movement, Walking, Flying);
ECS_COMPONENT(ecs, Velocity);
ECS_SET_TYPE(Movement);
ECS_SET_ENTITY(Walking);
ECS_SET_ENTITY(Flying);
ECS_SET_COMPONENT(Velocity);
}

View File

@ -0,0 +1,30 @@
#include "components/controllers.h"
#include "components/general.h"
#include "components/physics.h"
void ControllersImport(ecs_world_t *ecs) {
ECS_MODULE(ecs, Controllers);
ecs_set_name_prefix(ecs, "Controllers");
ECS_IMPORT(ecs, General);
ECS_IMPORT(ecs, Physics);
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, EcsActor);
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);
ECS_SET_TYPE(Player);
}

View File

@ -0,0 +1,19 @@
#include "components/general.h"
void GeneralImport(ecs_world_t *ecs) {
ECS_MODULE(ecs, General);
ecs_set_name_prefix(ecs, "General");
ECS_COMPONENT(ecs, Chunk);
ECS_COMPONENT(ecs, Position);
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);
}

View File

@ -0,0 +1,16 @@
#include "components/net.h"
void NetImport(ecs_world_t *ecs) {
ECS_MODULE(ecs, Net);
ecs_set_name_prefix(ecs, "Net");
ECS_TAG(ecs, EcsClient);
ECS_IMPORT(ecs, FlecsMeta);
ECS_META(ecs, ClientInfo);
ECS_EXPORT_ENTITY(EcsClient);
ECS_EXPORT_COMPONENT(ClientInfo);
}

View File

@ -0,0 +1,17 @@
#include "components/physics.h"
void PhysicsImport(ecs_world_t *ecs) {
ECS_MODULE(ecs, Physics);
ecs_set_name_prefix(ecs, "Physics");
ECS_TAG(ecs, Walking);
ECS_TAG(ecs, Flying);
ECS_TYPE(ecs, Movement, Walking, Flying);
ECS_COMPONENT(ecs, Velocity);
ECS_SET_TYPE(Movement);
ECS_SET_ENTITY(Walking);
ECS_SET_ENTITY(Flying);
ECS_SET_COMPONENT(Velocity);
}

View File

@ -15,6 +15,8 @@
#include "components/controllers.h" #include "components/controllers.h"
#include "components/net.h" #include "components/net.h"
#include "assets.h"
#define NETWORK_UPDATE_DELAY 0.100 #define NETWORK_UPDATE_DELAY 0.100
#define NETWORK_MAX_CLIENTS 32 #define NETWORK_MAX_CLIENTS 32

View File

@ -1,3 +1,2 @@
file(GLOB SRCS *.c *.h) file(GLOB SRCS *.c *.h)
add_library(flecs-bundle STATIC ${SRCS}) add_library(flecs-bundle STATIC ${SRCS})
include_directories(flecs-bundle .)