ent: entity_set_position helper

isolation_bkp/dynres
Dominik Madarász 2022-08-01 11:28:54 +02:00
parent c7d251eb44
commit 16001c24b9
3 changed files with 12 additions and 3 deletions

View File

@ -45,6 +45,14 @@ void entity_despawn(uint64_t ent_id) {
ecs_delete(world_ecs(), ent_id);
}
void entity_set_position(uint64_t ent_id, float x, float y) {
Position *p = ecs_get_mut(world_ecs(), ent_id, Position);
p->x = x;
p->y = y;
entity_wake(ent_id);
}
void entity_wake(uint64_t ent_id) {
StreamInfo *si = ecs_get_mut(world_ecs(), ent_id, StreamInfo);
si->tick_delay = 0.0f;

View File

@ -6,6 +6,7 @@
uint64_t entity_spawn(uint16_t class_id /* 0 = no streaming */);
void entity_batch_despawn(uint64_t *ids, size_t num_ids);
void entity_despawn(uint64_t ent_id);
void entity_set_position(uint64_t ent_id, float x, float y);
// NOTE(zaklaus): action-based entity stream throttling
void entity_wake(uint64_t ent_id);

View File

@ -41,9 +41,9 @@ void PickItem(ecs_iter_t *it) {
}
}
} else if (range <= ITEM_ATTRACT_RADIUS) {
p2->x = zpl_lerp(p2->x, p[i].x, ITEM_ATTRACT_FORCE*it->delta_time);
p2->y = zpl_lerp(p2->y, p[i].y, ITEM_ATTRACT_FORCE*it->delta_time);
entity_wake(ents[j]);
entity_set_position(ents[j],
zpl_lerp(p2->x, p[i].x, ITEM_ATTRACT_FORCE*it->delta_time),
zpl_lerp(p2->y, p[i].y, ITEM_ATTRACT_FORCE*it->delta_time));
}
}
}