View Single Post
  #2  
Old 04-16-2011, 06:50 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
It's slow because you're sending a trigger for every tile.

It'd be faster if you just built the list of tiles that need to be changed, looped through the list altering each tile as required as well as find the top-left and bottom-right most tiles in the process, and updated the resulting rectangle.

Edit: This was fun.

PHP Code:
//#CLIENTSIDE

function onMouseDown() {
  
floodFill(int(mousex), int(mousey));
}

// Flooding Fill (Works better)
function floodFill(txty) {

  
temp.queue.add({txty});
  
temp.tile player.level.tiles[txty];
  
maxlooplimit 100000;
  
  while (
temp.queue.size() > 0) {
  
    
tx temp.queue[0][0];
    
ty temp.queue[0][1];
    
temp.queue.delete(0);
    
    for (
temp.0temp.4temp.i++) {
      
temp.nx tx vecx(temp.i);
      
temp.ny ty vecy(temp.i);
      if (
checkTile(nxnytemp.tile)) {
        if (!((@{
nxny}) in temp.queue)) {
          
temp.queue.add({nxny});
        }
      }
    }
    
    
floodTile(txty);
  }
}

// West-to-East then North-to-South method.
function floodFill2(txty) {

  
temp.queue.add({txty});
  
temp.tile player.level.tiles[txty];
  
maxlooplimit 100000;
  
  while (
temp.queue.size() > 0) {
  
    
tx temp.queue[0][0];
    
ty temp.queue[0][1];
    
temp.queue.delete(0);
    
    
temp.west tx 1;
    while (
checkTile(westtytemp.tile)) {  
      
temp.west--;
    }
    
    
temp.east tx 1;
    while (
checkTile(easttytemp.tile)) {
      
temp.east++;
    }
    
    for (
temp.tx temp.west 1temp.tx temp.easttemp.tx++) {
      if (
checkTile(txtytemp.tile)) {
        
floodTile(txty);
      }
      if (
checkTile(txty 1temp.tile)) {
        
temp.queue.add({txty 1});
      }
      if (
checkTile(txty 1temp.tile)) {
        
temp.queue.add({txty 1});
      }
    }
  }
}

function 
checkTile(txtytile) {
  if (
tx in |0,64| && ty in |0,64|) {
    if (
player.level.tiles[txty] == tile) return true;
  }
  return 
false;
}

function 
floodTile(txtynosleep) {
  
player.level.tiles[txty] = 322;
  
updateboard(txty11);
  if (!
nosleepsleep(0.05);

__________________
Quote:

Last edited by fowlplay4; 04-16-2011 at 08:41 AM..
Reply With Quote