From 3174b8a3c34a3405dcab405f20bc98d4f29b3a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Tue, 17 Jan 2023 10:47:16 +0100 Subject: [PATCH] item router fix rolling counter --- code/foundation/src/gui/notifications.c | 2 +- code/foundation/src/gui/tooltip.c | 1 - code/foundation/src/models/components.h | 1 + .../src/systems/modules/system_logistics.c | 15 +++++++-------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/code/foundation/src/gui/notifications.c b/code/foundation/src/gui/notifications.c index db7c400..93c1559 100644 --- a/code/foundation/src/gui/notifications.c +++ b/code/foundation/src/gui/notifications.c @@ -46,7 +46,7 @@ void notification_draw(void) { for (zpl_isize i = cnt; i >= 0; --i) { notification *notif = (notifications + i); - if (nk_begin_titled(game_ui, zpl_bprintf("%dnotif%s", i, notif->title), notif->title, nk_rect(width - 320, ypos, 300, 1200), + if (nk_begin_titled(game_ui, zpl_bprintf("%d%fnotif%s", i, ypos, notif->title), notif->title, nk_rect(width - 320, ypos, 300, 1200), NK_WINDOW_DYNAMIC|NK_WINDOW_NO_SCROLLBAR)) { { if (nk_tree_push_id(game_ui, NK_TREE_TAB, notif->title, NK_MAXIMIZED, (int)i)) { diff --git a/code/foundation/src/gui/tooltip.c b/code/foundation/src/gui/tooltip.c index a2fdf3e..2c1e0e9 100644 --- a/code/foundation/src/gui/tooltip.c +++ b/code/foundation/src/gui/tooltip.c @@ -157,7 +157,6 @@ void tooltip__draw_node(tooltip_node *node) { nk_layout_row_dynamic(game_ui, 20, 2); for (zpl_isize i = 0; i < zpl_array_count(desc->links); ++i) { - // todo styling if (nk_button_label(game_ui, desc->links[i])) { if (node->next) tooltip__clear_node(node->next); if (!node->next) node->next = zpl_malloc(sizeof(tooltip_node)); diff --git a/code/foundation/src/models/components.h b/code/foundation/src/models/components.h index fc9a7c8..956d430 100644 --- a/code/foundation/src/models/components.h +++ b/code/foundation/src/models/components.h @@ -156,6 +156,7 @@ typedef struct { typedef struct { uint32_t push_qty; + uint8_t counter; } ItemRouter; typedef struct { diff --git a/code/foundation/src/systems/modules/system_logistics.c b/code/foundation/src/systems/modules/system_logistics.c index 85bc625..5e4b837 100644 --- a/code/foundation/src/systems/modules/system_logistics.c +++ b/code/foundation/src/systems/modules/system_logistics.c @@ -75,7 +75,6 @@ void PushItemsOnNodes(ecs_iter_t *it) { float push_dx[4], push_dy[4]; uint8_t nodes = CheckForNearbyBelts(&p[i], push_dx, push_dy); uint8_t num_nodes = (uint8_t)zpl_count_set_bits(nodes); - uint8_t counter = 0; if (num_nodes == 0) { // NOTE(zaklaus): We don't have any output nodes yet. @@ -105,22 +104,22 @@ void PushItemsOnNodes(ecs_iter_t *it) { while (item->quantity > 0 && num_nodes > 0) { // NOTE(zaklaus): Use a rolling counter to select an output node. - while (!(nodes & (1 << counter)) && counter < 4) ++counter; - if (counter > 3) { - counter = 0; + while (!(nodes & (1 << r[i].counter)) && r[i].counter < 4) ++r[i].counter; + if (r[i].counter > 3) { + r[i].counter = 0; continue; } uint64_t e = item_spawn(item->kind, zpl_min(r->push_qty, item->quantity)); - entity_set_position(e, p[i].x + push_dx[counter], p[i].y + push_dy[counter]); + entity_set_position(e, p[i].x + push_dx[r[i].counter], p[i].y + push_dy[r[i].counter]); Velocity *e_vel = ecs_get_mut_ex(it->world, e, Velocity); - e_vel->x = push_dx[counter]; - e_vel->y = push_dy[counter]; + e_vel->x = push_dx[r[i].counter]; + e_vel->y = push_dy[r[i].counter]; item->quantity -= zpl_min(r->push_qty, item->quantity); --num_nodes; - ++counter; + ++r[i].counter; if (item->quantity == 0) { item_despawn(item_slot_ent);