code: refactor components
parent
294d35c0c4
commit
8f44f5eec9
|
@ -1,3 +1,5 @@
|
|||
file(GLOB COMPONENTS header/components/*.h source/components/*.c)
|
||||
|
||||
add_executable(eco2d-server
|
||||
source/main.c
|
||||
source/network.c
|
||||
|
@ -14,10 +16,7 @@ add_executable(eco2d-server
|
|||
header/world/blocks.h
|
||||
header/world/blocks_info.h
|
||||
|
||||
header/components/net.h
|
||||
header/components/physics.h
|
||||
header/components/general.h
|
||||
header/components/controllers.h
|
||||
${COMPONENTS}
|
||||
)
|
||||
|
||||
include_directories(eco2d-server header)
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
#include "flecs/flecs.h"
|
||||
#include "flecs/flecs_meta.h"
|
||||
|
||||
#include "components/general.h"
|
||||
#include "components/physics.h"
|
||||
|
||||
ECS_STRUCT(Input, {
|
||||
double x;
|
||||
double y;
|
||||
|
@ -28,28 +25,4 @@ typedef struct {
|
|||
ECS_IMPORT_ENTITY(handles, EcsPlayer);\
|
||||
ECS_IMPORT_ENTITY(handles, EcsBuilder);\
|
||||
|
||||
static inline 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);
|
||||
}
|
||||
void ControllersImport(ecs_world_t *ecs);
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#include "flecs/flecs.h"
|
||||
#include "flecs/flecs_meta.h"
|
||||
|
||||
#include "assets.h"
|
||||
|
||||
ECS_STRUCT(Vector2D, {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
|
@ -29,20 +27,4 @@ typedef struct {
|
|||
ECS_IMPORT_COMPONENT(handles, Position);\
|
||||
ECS_IMPORT_COMPONENT(handles, Drawable);\
|
||||
|
||||
static inline 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);
|
||||
}
|
||||
void GeneralImport(ecs_world_t *ecs);
|
||||
|
|
|
@ -15,17 +15,4 @@ typedef struct {
|
|||
ECS_IMPORT_ENTITY(handles, EcsClient);\
|
||||
ECS_IMPORT_COMPONENT(handles, ClientInfo);\
|
||||
|
||||
static inline 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);
|
||||
}
|
||||
void NetImport(ecs_world_t *ecs);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "flecs/flecs.h"
|
||||
|
||||
#include "components/general.h"
|
||||
|
||||
typedef Vector2D Velocity;
|
||||
|
@ -17,18 +18,4 @@ typedef struct {
|
|||
ECS_IMPORT_ENTITY(handles, Flying);\
|
||||
ECS_IMPORT_COMPONENT(handles, Velocity);\
|
||||
|
||||
static inline 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);
|
||||
}
|
||||
void PhysicsImport(ecs_world_t *ecs);
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -15,6 +15,8 @@
|
|||
#include "components/controllers.h"
|
||||
#include "components/net.h"
|
||||
|
||||
#include "assets.h"
|
||||
|
||||
#define NETWORK_UPDATE_DELAY 0.100
|
||||
#define NETWORK_MAX_CLIENTS 32
|
||||
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
file(GLOB SRCS *.c *.h)
|
||||
add_library(flecs-bundle STATIC ${SRCS})
|
||||
include_directories(flecs-bundle .)
|
||||
|
|
Loading…
Reference in New Issue