开发者

Check to see if a variable doesn't have Bitwise & X?

I have been using a bitwise comparison to check if entities and maptiles have flags in a roguelike game, but I've run into a problem - I need to check in an if() if a tile/ent doesn't have a flag, but I can't figure out how to do it without using an empty if() {} and else { condition; }, an example being:

if(Tile->Flags & TILE_INVIEW) {} else { attron(A_DIM); }

or

if(Tile->Flags & TILE_RENDER) {} else { SetTileFlags(Get开发者_如何学CTileFlags() + TILE_RENDER); }

Is there a cleaner way to do this?


Just reverse your condition:

if(!(Tile->Flags & TILE_INVIEW)) {
    attron(A_DIM);
}

There is a not operator :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜