I have a Model(I use the MVC pattern), that holds an 2D Array with Tile objects.
A tile object have a member, whether it burns or not, a member how long it takes until the neighboring tiles get fire too and a member with the elapsed time how long the fire already burns on this tile.
My problem is, that my only solution is, to iterate threw all tiles and check whether the tile burns. If yes, count down the elapsed time. Than check, whether the maximum time is reached and set the fire member of the neighboring tiles to true.
In small maps it works, but in bigger maps not(Too many computing power). Whats the fastest way to filter the burning tiles out of the array, so I can do logic with them ?
A idea from me was to create a extra list that holds a reference to burning tiles, but that's difficult, because the list can be get out of sync with the array(Because the MVC pattern the array is public so it can be modified without to change the list with the fire tiles).
I have problems to implement this. So maybe someone can show me a code example. Here my current state: I have a class Tile:
public class Tile
{
public static final int TILE_NORMAL = 0;
private int type;
private boolean burning;
public Tile(int type)
{
this.type = type;
burning = false;
}
public int getType()
{
return type;
}
public void setType(int type)
{
this.type = type;
}
public boolean getBurning()
{
return burning;
}
public void setBurning(boolean burning)
{
this.burning = burning;
}
}
Than I have a class TileMap, too:
public class TileMap
{
private Tile[][] tiles;
public TileMap()
{
// That's only provisionally, later loading from a file
tiles = new Tile[2][2];
tiles[0] = new Tile[2];
tiles[1] = new Tile[2];
tiles[0][0] = new Tile(Tile.TILE_NORMAL);
tiles[1][0] = new Tile(Tile.TILE_NORMAL);
tiles[0][1] = new Tile(Tile.TILE_NORMAL);
tiles[1][1] = new Tile(Tile.TILE_NORMAL);
tiles[0][0].setBurning(true);
}
public Tile[][] getTiles()
{
return tiles;
}
public void setTiles(Tile[][] tiles)
{
this.tiles = tiles;
}
}
This class(TileMap) is placed into another class named "World". The world class is the big Model that contains all other models like players enemies .... To render the world I have a world renderer, that has a reference to the world object and every time I call the render method from the renderer, the renderer take for example the tile map from the world reference and iterate threw all tiles to draw them.
At last, I have a tile map controller. This class have a reference to the world, too. Every time the update method from it is called it do the logic for all world objects/models.
So now back to the actual question. How would you implement the event queue for the fire and maybe for such things like that? I am sorry and thanks for the patience :)