ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

create callback for Map.Uniform is being ignored? #162

Closed hexstr1p closed 5 years ago

hexstr1p commented 5 years ago

In my project, I can create a Map.Cellular like this without issue

    let map = [];
    let map_w = 800;
    let map_h = 240;
    for (let x = 0; x < map_w; ++x) {
      map.push([]);
      for (let y = 0; y < map_h; ++y) {
        map[x].push(Game.Tile.null_tile);
      }
    }
    let generator2 = new ROT.Map.Cellular(map_w, map_h);
    generator2.randomize(0.5);
    let total_iterations = 3;
    for (let i = 0; i < total_iterations - 1; ++i) { generator2.create(); }
    generator2.create((x, y, v) => {
      console.log("the celluar callback is running.");
      if (v === 1) map[x][y] = Game.Tile.floor_tile;
      else map[x][y] = Game.Tile.wall_tile;
    });

however, if I try to create a Map.Uniform instead, the create callback never runs

    let map = [];
    let map_w = 800;
    let map_h = 240;
    for (let x = 0; x < map_w; ++x) {
      map.push([]);
      for (let y = 0; y < map_h; ++y) {
        map[x].push(Game.Tile.null_tile);
      }
    }
    let generator = new ROT.Map.Uniform(
      map_w,
      map_h,
      {
        timeLimit: 500,
        roomDugPercentage: 0.5
      });
    generator.create((x, y, v) => {
      console.log("the unfiorm generator callback is running.");
      if (v === 0) map[x][y] = Game.Tile.floor_tile;
      else map[x][y] = Game.Tile.wall_tile;
    });
ondras commented 5 years ago

Looks like you are hitting the time limit. Increasing it is probably not going to fix your issue, though, because:

For a map of this size, I would suggest switching to ROT.Map.Digger. The Uniform algorithm apparently is not able to do this.

hexstr1p commented 5 years ago

I see. The ROT.Map.Digger does preform better. I should cut down my map size then.