diff --git a/src/main.cpp b/src/main.cpp index b98da12..6f53a7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,7 @@ constexpr u64 clamp_to_width(const DrawState &ds, f64 val) (val - ds.bounds.lower_val); } -void draw_tree(const DrawState &ds) +void draw_tree(const DrawState &ds, const State &state) { // Number line DrawLine(0, HEIGHT / 2, WIDTH, HEIGHT / 2, WHITE); @@ -63,18 +63,29 @@ void draw_tree(const DrawState &ds) DrawLine(lower_x, LINE_TOP, lower_x, LINE_BOTTOM, WHITE); DrawLine(upper_x, LINE_TOP, upper_x, LINE_BOTTOM, WHITE); - std::stack stack; - stack.push(ds.state.allocator.get_val(0)); + std::stack> stack; + cw::node::Node n = state.allocator.get_val(0); + stack.push(std::make_pair(0, n.value.norm)); while (!stack.empty()) { - auto n = stack.top(); + u64 node_index; + f64 norm; + std::tie(node_index, norm) = stack.top(); stack.pop(); - u64 x = clamp_to_width(ds, n.value.norm); + u64 x = clamp_to_width(ds, norm); DrawLine(x, LINE_TOP, x, LINE_BOTTOM, RED); + + cw::node::Node n = state.allocator.get_val(node_index); if (n.left >= 0) - stack.push(ds.state.allocator.get_val(n.left)); + { + cw::node::Node left = state.allocator.get_val(n.left); + stack.push(std::make_pair(n.left, left.value.norm)); + } if (n.right >= 0) - stack.push(ds.state.allocator.get_val(n.right)); + { + cw::node::Node right = state.allocator.get_val(n.right); + stack.push(std::make_pair(n.right, right.value.norm)); + } } } @@ -145,7 +156,7 @@ int main(void) ClearBackground(BLACK); BeginDrawing(); - draw_tree(draw_state); + draw_tree(draw_state, state); DrawText(format_str.c_str(), WIDTH / 2 - format_str_width / 2, HEIGHT / 8, FONT_SIZE, WHITE); EndDrawing();