Generalize easing system (works for all components now)

This commit is contained in:
2023-12-29 20:03:01 +01:00
parent 69232cebf4
commit 3ec7505214
4 changed files with 17 additions and 40 deletions

View File

@@ -51,15 +51,14 @@ void updateAnimation(ecs_iter_t *it) {
}
void updateEasingSystem(ecs_iter_t *it) {
Easing *easing = ecs_field(it, Easing, 1);
Position *position = ecs_field(it, Position, 2);
Size *size = ecs_field(it, Size, 3);
Rotation *rotation = ecs_field(it, Rotation, 4);
Easing *easing = ecs_field(it, Easing, 1);
f32 dt = GetFrameTime();
for (i32 i = 0; i < it->count; i++) {
ecs_entity_t entity = it->entities[i];
if (!ecs_has_id(ECS, entity, easing[i].compID))
continue;
if (easing[i].elapsed > easing[i].duration) {
ecs_remove(ECS, entity, Easing);
continue;
@@ -76,22 +75,9 @@ void updateEasingSystem(ecs_iter_t *it) {
// Outer
x = e->start + e->target * x + e->offset;
switch (easing->type) {
case EASE_ROTATION:
rotation[i] = x;
break;
case EASE_POS_X:
position[i].x = x;
break;
case EASE_POS_Y:
position[i].y = x;
break;
case EASE_SIZE_X:
size[i].x = x;
break;
case EASE_SIZE_Y:
size[i].y = x;
break;
}
u8 *compData = ecs_get_mut_id(ECS, entity, easing[i].compID);
compData += easing[i].memberOffset;
*(f32 *) compData = x;
}
}