]> Untitled Git - axy/ft/a-maze-ing.git/commitdiff
maze_make_empty and layout runspeed improvements
authorAxy <gilliardmarthey.axel@gmail.com>
Fri, 6 Mar 2026 00:30:48 +0000 (01:30 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Fri, 6 Mar 2026 00:30:48 +0000 (01:30 +0100)
__main__.py
amazeing/maze_display/TTYdisplay.py
amazeing/maze_display/layout.py
amazeing/maze_make_empty.py [new file with mode: 0644]
example.conf

index 21eed848680b9468761f171a925a0468471a8294..851ac1a7a480ef8868024131eaf6f857477831f4 100644 (file)
@@ -14,6 +14,7 @@ from amazeing.config.config_parser import Config
 from amazeing.maze_class.maze_walls import Cardinal, CellCoord
 from amazeing.maze_display.TTYdisplay import Tile, TileMaps, extract_pairs
 from amazeing.maze_display.backend import BackendEvent, CloseRequested, IVec2
+from amazeing.maze_make_empty import maze_make_empty
 
 config = Config.parse(open("./example.conf").read())
 
@@ -72,7 +73,7 @@ def display_maze(maze: Maze) -> None:
             backend.draw_tile(pixel)
     maze.clear_dirty()
     backend.present()
-    poll_events(0)
+    poll_events(2)
 
 
 def poll_events(timeout_ms: int = -1) -> None:
@@ -95,6 +96,9 @@ maze_make_perfect(maze, callback=display_maze)
 maze_make_pacman(maze, walls_const, callback=display_maze)
 while True:
     maze_make_perfect(maze, callback=display_maze)
-    maze_make_pacman(maze, walls_const, callback=display_maze)
+    poll_events(200)
+    # maze_make_pacman(maze, walls_const, callback=display_maze)
+    maze_make_empty(maze, walls_const, callback=display_maze)
+    poll_events(200)
     maze._rebuild()
 poll_events()
index d51607be2406367aa6f2ea5bb5760c657e5f5ba2..a9fa9e15c028a4df8cada9d7c92b165883d5e0bb 100644 (file)
@@ -4,6 +4,7 @@ from ..config.config_parser import Color, Config, ColoredLine, ColorPair
 from amazeing.maze_display.layout import (
     BInt,
     Box,
+    DBox,
     FBox,
     HBox,
     VBox,
@@ -61,7 +62,6 @@ class Tile:
     ) -> None:
         if size.x <= 0 or size.y <= 0:
             return
-        print(src, dst, size, window.getmaxyx(), file=stderr)
         self.__pad.overwrite(
             window, *src.yx(), *dst.yx(), *(dst + size - IVec2.splat(1)).yx()
         )
@@ -322,16 +322,26 @@ class TTYBackend(Backend[int]):
             IVec2(BInt(dims.x), BInt(dims.y)),
             lambda at, into: self.__pad.present(at, into, self.__scratch),
         )
-        filler_box = FBox(
-            IVec2(BInt(0, True), BInt(0, True)),
-            lambda at, into: (
-                None
-                if self.__filler is None
-                else self.__tilemap.draw_at_wrapping(
-                    at, at, into, self.__filler, self.__scratch
+
+        self.__filler_boxes: list[DBox] = []
+
+        def filler_box() -> Box:
+            self.__filler_boxes.append(
+                res := DBox(
+                    FBox(
+                        IVec2(BInt(0, True), BInt(0, True)),
+                        lambda at, into: (
+                            None
+                            if self.__filler is None
+                            else self.__tilemap.draw_at_wrapping(
+                                at, at, into, self.__filler, self.__scratch
+                            )
+                        ),
+                    )
                 )
-            ),
-        )
+            )
+            return res
+
         f: Callable[[int], int] = lambda e: e
         layout = layout_split(
             layout_fair, layout_sort_chunked(layout_fair, layout_priority, f)
@@ -339,15 +349,15 @@ class TTYBackend(Backend[int]):
         self.__layout: Box = VBox(
             layout,
             [
-                (filler_box, 0),
+                (filler_box(), 0),
                 (
                     HBox(
                         layout,
-                        [(filler_box, 0), (maze_box, 1), (filler_box, 0)],
+                        [(filler_box(), 0), (maze_box, 1), (filler_box(), 0)],
                     ),
                     1,
                 ),
-                (filler_box, 0),
+                (filler_box(), 0),
             ],
         )
 
@@ -364,6 +374,8 @@ class TTYBackend(Backend[int]):
 
     def set_filler(self, style: int) -> None:
         self.__filler = style
+        for box in self.__filler_boxes:
+            box.mark_dirty()
 
     def add_style(self, style: Tile) -> int:
         return self.__tilemap.add_tile(style)
@@ -381,6 +393,8 @@ class TTYBackend(Backend[int]):
         if self.__resize:
             self.__resize = False
             self.__screen.erase()
+            for box in self.__filler_boxes:
+                box.mark_dirty()
         self.__screen.refresh()
         y, x = self.__screen.getmaxyx()
         self.__scratch.resize(y, x)
index 16fc870ebfac983714fde8b1aefe587654e679a9..45118cefe4aa684ad55f759c3dffbfdfc2b5aba9 100644 (file)
@@ -226,7 +226,8 @@ class HBox[T](Box):
         heights = [(get_height(dim.y), assoc) for dim, assoc in dims]
 
         for (height, _), width, (box, _) in zip(heights, widths, self.boxes):
-            box.laid_out(at, IVec2(width, height))
+            # ditto error that i forgot to fix :>
+            box.laid_out(at.copy(), IVec2(width, height))
             at.x += width
 
 
@@ -247,6 +248,24 @@ class FBox(Box):
         self.__cb(at, into)
 
 
+class DBox(Box):
+    def __init__(self, inner: Box) -> None:
+        self.__inner: Box = inner
+        self.__prev: tuple[IVec2, IVec2] | None = None
+
+    def mark_dirty(self) -> None:
+        self.__prev = None
+
+    def dims(self) -> BVec2:
+        return self.__inner.dims()
+
+    def laid_out(self, at: IVec2, into: IVec2) -> None:
+        if self.__prev == (at, into):
+            return
+        self.__prev = (at, into)
+        self.__inner.laid_out(at, into)
+
+
 def vpad_box(min_pad: int = 0, cb=lambda _at, _into: None) -> FBox:
     return FBox(IVec2(BInt(0), BInt(min_pad, True)), cb)
 
diff --git a/amazeing/maze_make_empty.py b/amazeing/maze_make_empty.py
new file mode 100644 (file)
index 0000000..7acb5ef
--- /dev/null
@@ -0,0 +1,16 @@
+from collections.abc import Callable
+from amazeing.maze_class.maze import Maze
+from amazeing.maze_class.maze_walls import WallCoord
+import random
+
+
+def maze_make_empty(
+    maze: Maze,
+    walls_const: set[WallCoord],
+    callback: Callable[[Maze], None] = lambda _: None,
+) -> None:
+    walls = [wall for wall in maze.walls_full() if wall not in walls_const]
+    random.shuffle(walls)
+    for wall in walls:
+        maze._remove_wall(wall)
+        callback(maze)
index 8a415634429ceb2624c5de2c0be46d420e00b9c5..dc3427d2a05f50f9293875fce471e6cbf89b84b0 100644 (file)
@@ -1,5 +1,5 @@
-WIDTH=50
-HEIGHT=50
+WIDTH=25
+HEIGHT=25
 ENTRY=2,5
 #EXIT=100,100
 OUTPUT_FILE=test
@@ -13,11 +13,11 @@ TILEMAP_FULL="{100,100,1000:1000,1000,1000}###{1000,1000,1000:1000,1000,1000}###
 TILEMAP_EMPTY="{0,0,0:0,0,0}      "
 TILEMAP_EMPTY="{0,0,0:0,0,0}      "
 TILEMAP_EMPTY="{0,0,0:0,0,0}      "
-TILEMAP_BACKGROUND_SIZE=4,4
-TILEMAP_BACKGROUND="{100,100,100:0,0,0}#   "
-TILEMAP_BACKGROUND="{100,100,100:0,0,0}### "
-TILEMAP_BACKGROUND="{100,100,100:0,0,0}  # "
-TILEMAP_BACKGROUND="{100,100,100:0,0,0}# # "
+TILEMAP_BACKGROUND_SIZE=8,4
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0}##      "
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0}######  "
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0}    ##  "
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0}##  ##  "
 MAZE_PATTERN=" #   # "
 MAZE_PATTERN="  # #  "
 MAZE_PATTERN="   #   "