From 16001c24b9e0af8521b7086cf95a70edf5addb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 1 Aug 2022 11:28:54 +0200 Subject: [PATCH] ent: entity_set_position helper --- code/game/src/entity.c | 8 ++++++++ code/game/src/entity.h | 1 + code/modules/source/system_items.c | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/code/game/src/entity.c b/code/game/src/entity.c index cd66789..ad71a26 100644 --- a/code/game/src/entity.c +++ b/code/game/src/entity.c @@ -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; diff --git a/code/game/src/entity.h b/code/game/src/entity.h index 848c946..941825f 100644 --- a/code/game/src/entity.h +++ b/code/game/src/entity.h @@ -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); diff --git a/code/modules/source/system_items.c b/code/modules/source/system_items.c index fd6ef45..aa6605b 100644 --- a/code/modules/source/system_items.c +++ b/code/modules/source/system_items.c @@ -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)); } } }