using shorter for-loops in examples master
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 29 Nov 2021 20:25:16 +0000 (14:25 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 29 Nov 2021 20:25:16 +0000 (14:25 -0600)
tests/minesweeper.onyx
tests/simp.onyx
tests/snake.onyx

index 96b5d57344b7dc82df04829ee6bf55738bbd6942..ca8513a7f20dd71000f03c418c608b51cae0847f 100644 (file)
@@ -49,19 +49,19 @@ generate_board :: (use this: ^Board, mine_count: i32) {
     for ^cell: true_cells    do *cell = .Empty;
 
     memory.alloc_slice(^mine_locations, mine_count);
     for ^cell: true_cells    do *cell = .Empty;
 
     memory.alloc_slice(^mine_locations, mine_count);
-    for i: mine_count {
+    for mine_count {
         while true {
             mx, my := random.between(0, width - 1), random.between(0, height - 1);
             if get_true_cell(this, mx, my) != .Mine {
                 set_true_cell(this, mx, my, .Mine);
         while true {
             mx, my := random.between(0, width - 1), random.between(0, height - 1);
             if get_true_cell(this, mx, my) != .Mine {
                 set_true_cell(this, mx, my, .Mine);
-                mine_locations[i] = .{mx, my};
+                mine_locations[it] = .{mx, my};
                 break;
             }
         }
     }
 
                 break;
             }
         }
     }
 
-    for ^mine_pos: mine_locations {
-        for neighbor: neighbors(this, mine_pos.x, mine_pos.y) {
+    for ^ mine_locations {
+        for neighbor: neighbors(this, it.x, it.y) {
             cell := get_true_cell(this, neighbor.x, neighbor.y);
             if     cell == .Empty  do cell = .Number1;
             elseif cell&.Is_Number do cell += 1;
             cell := get_true_cell(this, neighbor.x, neighbor.y);
             if     cell == .Empty  do cell = .Number1;
             elseif cell&.Is_Number do cell += 1;
@@ -145,19 +145,19 @@ flood_reveal :: (use this: ^Board, x, y: i32) => {
         reveal_cell(this, p.x, p.y);
         if get_true_cell(this, p.x, p.y) & .Is_Number do continue;
 
         reveal_cell(this, p.x, p.y);
         if get_true_cell(this, p.x, p.y) & .Is_Number do continue;
 
-        for n: neighbors(this, p.x, p.y, include_corners=true) {
-            true_cell    := get_true_cell(this, n.x, n.y);
-            visible_cell := get_visible_cell(this, n.x, n.y);
+        for neighbors(this, p.x, p.y, include_corners=true) {
+            true_cell    := get_true_cell(this, it.x, it.y);
+            visible_cell := get_visible_cell(this, it.x, it.y);
             if true_cell != .Mine && visible_cell == .Covered {
             if true_cell != .Mine && visible_cell == .Covered {
-                positions << n;
+                positions << it;
             }
         }
     }
 }
 
 reveal_mines :: (use this: ^Board) {
             }
         }
     }
 }
 
 reveal_mines :: (use this: ^Board) {
-    for ^mine: mine_locations {
-        reveal_cell(this, mine.x, mine.y);
+    for ^ mine_locations {
+        reveal_cell(this, it.x, it.y);
     }
 }
 
     }
 }
 
index 26133d8bda0ac6a6395ab55a2ae8b57a1e42cd4d..ba0e2bc1866a897fa4b2fedb632e80b95cbbe7d5 100644 (file)
@@ -145,7 +145,7 @@ draw :: () {
     hb.graphics.drawImage(dummy, 100, 100, 100, 100);
     hb.graphics.newQuad(4, 4, 8, 8, dummy) |> hb.graphics.drawQuad(200, 100, 100, 100);
 
     hb.graphics.drawImage(dummy, 100, 100, 100, 100);
     hb.graphics.newQuad(4, 4, 8, 8, dummy) |> hb.graphics.drawQuad(200, 100, 100, 100);
 
-    for it: squares {
+    for squares {
         hb.graphics.setColor(it.r, it.g, it.b, it.a);
         hb.graphics.rectangle(.Fill, it.x, it.y, it.w, it.h);
     }
         hb.graphics.setColor(it.r, it.g, it.b, it.a);
         hb.graphics.rectangle(.Fill, it.x, it.y, it.w, it.h);
     }
index 46583eb7d43203c07c39e26bfae6492db78ac162..1d12f173c85a987c432234245738003cb720f225 100644 (file)
@@ -44,8 +44,8 @@ snake_make :: (head: Vec2i) -> Snake {
 }
 
 snake_move :: (use this: ^Snake) {
 }
 
 snake_move :: (use this: ^Snake) {
-    for i: iter.as_iterator(range.{ body.count - 1, 1, -1 }) {
-        body[i] = body[i - 1];
+    for iter.as_iterator(range.{ body.count - 1, 1, -1 }) {
+        body[it] = body[it - 1];
     }
     body[0] = head;
 
     }
     body[0] = head;
 
@@ -54,11 +54,11 @@ snake_move :: (use this: ^Snake) {
 
 snake_grow :: (use this: ^Snake, amount := 1) {
     last := body[body.count - 1];
 
 snake_grow :: (use this: ^Snake, amount := 1) {
     last := body[body.count - 1];
-    for i: amount do body << last;
+    for amount do body << last;
 }
 
 snake_draw :: (use this: ^Snake, cell_size: f32) {
 }
 
 snake_draw :: (use this: ^Snake, cell_size: f32) {
-    for it: iter.enumerate(body) {
+    for iter.enumerate(body) {
         hb.graphics.setColor(0, 0.6 - 0.4 * (~~it.index / cast(f32) body.count), 0);
         hb.graphics.rectangle(.Fill, ~~it.value.x * cell_size, ~~it.value.y * cell_size, cell_size, cell_size);
     }
         hb.graphics.setColor(0, 0.6 - 0.4 * (~~it.index / cast(f32) body.count), 0);
         hb.graphics.rectangle(.Fill, ~~it.value.x * cell_size, ~~it.value.y * cell_size, cell_size, cell_size);
     }
@@ -142,7 +142,7 @@ reset_game :: () {
 }
 
 cell_contains_snake_body :: (p: Vec2i) => {
 }
 
 cell_contains_snake_body :: (p: Vec2i) => {
-    for ^it: the_snake.body {
+    for ^ the_snake.body {
         if *it == p do return true;
     }
     return false;
         if *it == p do return true;
     }
     return false;
@@ -294,7 +294,7 @@ draw_menu :: (y: f32) {
     menu_info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(active_menu.options);
     if menu_info.kind != .Struct do return;
 
     menu_info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(active_menu.options);
     if menu_info.kind != .Struct do return;
 
-    for it: iter.enumerate(menu_info.members) {
+    for iter.enumerate(menu_info.members) {
         text := *(cast(^str) array.first(it.value.tags, (t) => t.type == str).data);
         height := hb.graphics.getTextHeight(text);
 
         text := *(cast(^str) array.first(it.value.tags, (t) => t.type == str).data);
         height := hb.graphics.getTextHeight(text);