phys changes

isolation_bkp/dynres
Dominik Madarász 2021-05-08 10:03:18 +02:00
parent d5f150619d
commit 178ca92ff7
3 changed files with 12 additions and 2 deletions

View File

@ -151,13 +151,14 @@ static void world_tracker_update(void) {
world.tracker_update = zpl_time_rel_ms() + WORLD_TRACKER_UPDATE_MS; world.tracker_update = zpl_time_rel_ms() + WORLD_TRACKER_UPDATE_MS;
ECS_IMPORT(world.ecs, Net); ECS_IMPORT(world.ecs, Net);
ecs_query_t *query = ecs_query_new(world.ecs, "Net.ClientInfo"); ecs_query_t *query = ecs_query_new(world.ecs, "Net.ClientInfo, general.Position");
ecs_iter_t it = ecs_query_iter(query); ecs_iter_t it = ecs_query_iter(query);
static char buffer[WORLD_LIBRG_BUFSIZ] = {0}; static char buffer[WORLD_LIBRG_BUFSIZ] = {0};
while (ecs_query_next(&it)) { while (ecs_query_next(&it)) {
ClientInfo *p = ecs_column(&it, ClientInfo, 1); ClientInfo *p = ecs_column(&it, ClientInfo, 1);
Position *pos = ecs_column(&it, Position, 2);
for (int i = 0; i < it.count; i++) { for (int i = 0; i < it.count; i++) {
size_t datalen = WORLD_LIBRG_BUFSIZ; size_t datalen = WORLD_LIBRG_BUFSIZ;

View File

@ -12,6 +12,7 @@ typedef struct {
ECS_DECLARE_ENTITY(Flying); ECS_DECLARE_ENTITY(Flying);
ECS_DECLARE_COMPONENT(Velocity); ECS_DECLARE_COMPONENT(Velocity);
ECS_DECLARE_ENTITY(MoveWalk); ECS_DECLARE_ENTITY(MoveWalk);
ECS_DECLARE_ENTITY(UpdateTrackerPos);
} Physics; } Physics;
#define PhysicsImportHandles(handles)\ #define PhysicsImportHandles(handles)\
@ -20,5 +21,6 @@ typedef struct {
ECS_IMPORT_ENTITY(handles, Flying);\ ECS_IMPORT_ENTITY(handles, Flying);\
ECS_IMPORT_COMPONENT(handles, Velocity);\ ECS_IMPORT_COMPONENT(handles, Velocity);\
ECS_IMPORT_ENTITY(handles, MoveWalk);\ ECS_IMPORT_ENTITY(handles, MoveWalk);\
ECS_IMPORT_ENTITY(handles, UpdateTrackerPos);\
void PhysicsImport(ecs_world_t *ecs); void PhysicsImport(ecs_world_t *ecs);

View File

@ -21,7 +21,13 @@ void MoveWalk(ecs_iter_t *it) {
p[i].x = zpl_clamp(p[i].x, -w, w); p[i].x = zpl_clamp(p[i].x, -w, w);
p[i].y = zpl_clamp(p[i].y, -w, w); p[i].y = zpl_clamp(p[i].y, -w, w);
} }
}
}
void UpdateTrackerPos(ecs_iter_t *it) {
Position *p = ecs_column(it, Position, 1);
for (int i = 0; i < it->count; i++){
librg_entity_chunk_set(world_tracker(), it->entities[i], librg_chunk_from_realpos(world_tracker(), p[i].x, p[i].y, 0)); librg_entity_chunk_set(world_tracker(), it->entities[i], librg_chunk_from_realpos(world_tracker(), p[i].x, p[i].y, 0));
} }
} }
@ -37,6 +43,7 @@ void PhysicsImport(ecs_world_t *ecs) {
ECS_META(ecs, Velocity); ECS_META(ecs, Velocity);
ECS_SYSTEM(ecs, MoveWalk, EcsOnUpdate, general.Position, Velocity); ECS_SYSTEM(ecs, MoveWalk, EcsOnUpdate, general.Position, Velocity);
ECS_SYSTEM(ecs, UpdateTrackerPos, EcsOnValidate, general.Position);
ECS_SET_TYPE(Movement); ECS_SET_TYPE(Movement);
ECS_SET_ENTITY(Walking); ECS_SET_ENTITY(Walking);