eco2d/code/game/source/player.c

39 lines
943 B
C
Raw Normal View History

2021-05-05 07:55:45 +00:00
#include "player.h"
2021-05-08 09:05:15 +00:00
#include "entity.h"
2021-05-05 07:55:45 +00:00
#include "flecs/flecs.h"
#include "flecs/flecs_meta.h"
#include "librg.h"
2021-05-12 15:50:30 +00:00
#include "world/world.h"
2021-05-05 07:55:45 +00:00
#include "modules/general.h"
#include "modules/controllers.h"
2021-05-05 13:14:02 +00:00
#include "modules/net.h"
2021-05-07 14:43:54 +00:00
#include "modules/physics.h"
2021-05-06 18:24:01 +00:00
#include "zpl.h"
2021-05-05 07:55:45 +00:00
2021-05-08 09:05:15 +00:00
uint64_t player_spawn(char *name) {
ecs_entity_t e = entity_spawn(NULL);
2021-05-06 18:24:01 +00:00
if (!name) {
name = zpl_bprintf("player_%d", e);
}
2021-05-08 09:05:15 +00:00
ECS_IMPORT(world_ecs(), General);
ECS_IMPORT(world_ecs(), Controllers);
ECS_IMPORT(world_ecs(), Net);
2021-07-26 15:53:18 +00:00
2021-05-08 09:05:15 +00:00
ecs_set(world_ecs(), e, EcsName, {.alloc_value = name });
2021-05-05 13:14:02 +00:00
ecs_add(world_ecs(), e, EcsClient);
ecs_set(world_ecs(), e, ClientInfo, {0});
ecs_set(world_ecs(), e, Input, {0});
2021-05-07 20:48:15 +00:00
ecs_add(world_ecs(), e, Player);
2021-07-19 08:28:23 +00:00
2021-05-05 07:55:45 +00:00
librg_entity_owner_set(world_tracker(), e, (int64_t)e);
2021-07-19 08:28:23 +00:00
2021-05-05 07:55:45 +00:00
return (uint64_t)e;
}
void player_despawn(uint64_t ent_id) {
2021-07-26 15:53:18 +00:00
entity_despawn(ent_id);
2021-05-05 13:14:02 +00:00
}