hedgewars/uLandGenMaze.pas
branchwebgl
changeset 8026 4a4f21070479
parent 6580 6155187bf599
child 9127 e350500c4edb
--- a/hedgewars/uLandGenMaze.pas	Sun Nov 11 16:53:16 2012 +0100
+++ b/hedgewars/uLandGenMaze.pas	Sun Nov 11 17:15:19 2012 +0100
@@ -14,6 +14,10 @@
     DIR_S: direction = (x: 0; y: 1);
     DIR_W: direction = (x: -1; y: 0);
 
+{xymeng : make all dynamic arrays static }
+const max_num_cells_x = 4096 div 128;
+   max_num_cells_y    = 4096 div 128;
+   max_num_steps      = 3;
 
 operator = (const a, b: direction) c: Boolean;
 begin
@@ -25,28 +29,43 @@
     large_cell_size = 256;
     braidness = 10;
 
-var x, y: LongInt;
-    cellsize: LongInt; //selected by the user in the gui
-    seen_cells_x, seen_cells_y: LongInt; //number of cells that can be visited by the generator, that is every second cell in x and y direction. the cells between there are walls that will be removed when we move from one cell to another
-    num_edges_x, num_edges_y: LongInt; //number of resulting edges that need to be vertexificated
-    num_cells_x, num_cells_y: LongInt; //actual number of cells, depending on cell size
-    seen_list: array of array of LongInt;
-    xwalls: array of array of Boolean;
-    ywalls: array of array of Boolean;
-    x_edge_list: array of array of Boolean;
-    y_edge_list: array of array of Boolean;
-    maze: array of array of Boolean;
-    pa: TPixAr;
-    num_vertices: LongInt;
-    off_y: LongInt;
-    num_steps: LongInt;
-    current_step: LongInt;
-    step_done: array of Boolean;
-    done: Boolean;
-    last_cell: array of record x, y: LongInt; end;
-    came_from: array of array of record x, y: LongInt; end;
+type
+   cell_t = record x,y	       : LongInt
+	    end;
+   
+var x, y		       : LongInt;
+    cellsize		       : LongInt; //selected by the user in the gui
+    seen_cells_x, seen_cells_y : LongInt; //number of cells that can be visited by the generator, that is every second cell in x and y direction. the cells between there are walls that will be removed when we move from one cell to another
+    num_edges_x, num_edges_y   : LongInt; //number of resulting edges that need to be vertexificated
+    num_cells_x, num_cells_y   : LongInt; //actual number of cells, depending on cell size
+
+
+    seen_list		       : array of array of LongInt;
+    xwalls		       : array of array of Boolean;
+    ywalls		       : array of array of Boolean;
+    x_edge_list		       : array of array of Boolean;
+    y_edge_list		       : array of array of Boolean;
+    maze		       : array of array of Boolean;
+
+    pa			       : TPixAr;
+    num_vertices	       : LongInt;
+    off_y		       : LongInt;
+    num_steps		       : LongInt;
+    current_step	       : LongInt;
+   
+    step_done		       : array of Boolean;
+   
+    done		       : Boolean;
+
+{   last_cell		       : array 0..3 of record x, y :LongInt ; end;
+    came_from		       : array of array of record x, y: LongInt; end;
+    came_from_pos	       : array of LongInt;
+}
+    last_cell : array of cell_t;
+    came_from : array of array of cell_t;
     came_from_pos: array of LongInt;
-    maze_inverted: Boolean;
+   
+    maze_inverted					   : Boolean;
 
 function when_seen(x: LongInt; y: LongInt): LongInt;
 begin
@@ -102,7 +121,7 @@
     begin
         //we have already seen the target cell, decide if we should remove the wall anyway
         //(or put a wall there if maze_inverted, but we are not doing that right now)
-        if not maze_inverted and (GetRandom(braidness) = 0) then
+        if (not maze_inverted) and (GetRandom(braidness) = 0) then
         //or just warn that inverted+braid+indestructible terrain != good idea
         begin
             case dir.x of
@@ -178,7 +197,7 @@
     came_from_pos[current_step] := came_from_pos[current_step] - 1;
     
     if came_from_pos[current_step] >= 0 then
-        see_cell
+        see_cell()
         
     else
         step_done[current_step] := true;
@@ -336,14 +355,18 @@
 SetLength(last_cell, num_steps);
 SetLength(came_from_pos, num_steps);
 SetLength(came_from, num_steps, num_cells_x*num_cells_y);
+
 done := false;
 
 for current_step := 0 to num_steps - 1 do
+begin
     step_done[current_step] := false;
     came_from_pos[current_step] := 0;
-    
+end;
+
 current_step := 0;
 
+
 SetLength(seen_list, seen_cells_x, seen_cells_y);
 SetLength(xwalls, seen_cells_x, seen_cells_y - 1);
 SetLength(ywalls, seen_cells_x - 1, seen_cells_y);
@@ -351,6 +374,7 @@
 SetLength(y_edge_list, num_cells_x, num_edges_y);
 SetLength(maze, num_cells_x, num_cells_y);
 
+   
 num_vertices := 0;
 
 playHeight := num_cells_y * cellsize;