Skip to content

Commit

Permalink
scent_block_defer: wait until committing modifications to test inbounds
Browse files Browse the repository at this point in the history
removed unnecessary 'assignable' member since we are now testing as
needed instead of all at once in the constructor.
  • Loading branch information
OrenAudeles authored and kevingranade committed Jul 8, 2019
1 parent e7ab273 commit 9d36f0d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/scent_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ struct scent_block {
data_mode mode;
int intensity;
};

data_block<bool> assignable;
data_block<datum> assignment;

tripoint origin;
Expand All @@ -34,7 +32,6 @@ struct scent_block {
: origin( subx * SEEX - 1, suby * SEEY - 1, subz ), scents( scents ), modification_count( 0 ) {
for( int x = 0; x < SEEX + 2; ++x ) {
for( int y = 0; y < SEEY + 2; ++y ) {
assignable[x][y] = scents.inbounds( origin + tripoint( x, y, 0 ) );
assignment[x][y] = { NONE, 0 };
}
}
Expand All @@ -46,19 +43,22 @@ struct scent_block {
}
for( int x = 0; x < SEEX + 2; ++x ) {
for( int y = 0; y < SEEY + 2; ++y ) {
if( assignable[x][y] ) {
switch( assignment[x][y].mode ) {
case NONE:
break;
case SET: {
scents.set_unsafe( origin + tripoint( x, y, 0 ), assignment[x][y].intensity );
break;
switch( assignment[x][y].mode ) {
case NONE:
break;
case SET: {
tripoint p = origin + tripoint( x, y, 0 );
if( scents.inbounds( p ) ) {
scents.set_unsafe( p, assignment[x][y].intensity );
}
case MAX: {
tripoint p = origin + tripoint( x, y, 0 );
break;
}
case MAX: {
tripoint p = origin + tripoint( x, y, 0 );
if( scents.inbounds( p ) ) {
scents.set_unsafe( p, std::max( assignment[x][y].intensity, scents.get_unsafe( p ) ) );
break;
}
break;
}
}
}
Expand Down

0 comments on commit 9d36f0d

Please sign in to comment.