project-navigation
Personal tools

Author Topic: computing surface- and contentflags  (Read 7059 times)

Offline ShipIt

  • Project Artist
  • Captain
  • ***
  • Posts: 906
    • View Profile
computing surface- and contentflags
« on: December 20, 2014, 10:31:50 am »
What should be my general approach when I try to find out if a certain flag is set, based on the number given in the .map file?

So, if the value for surfaceflags given in the .map file is 24059. How do I know whether the flag for 'light' (1) is set or not?

Right now I am using a quite excessive method:subtract the highest value and check the result, next value, ... for each single value down from high to low. Somehow I have the feeling there should be an easier way.

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: computing surface- and contentflags
« Reply #1 on: December 20, 2014, 06:04:16 pm »
Open your windows calculator, set it to scientific mode, then you can use the 'and' operator on the surface flags and the value for the flag you are checking (like: 24059 'and' 1), if the result is the flag's value (in this case 1) then the flag is set, if it is zero then the flag is not set.

Offline ShipIt

  • Project Artist
  • Captain
  • ***
  • Posts: 906
    • View Profile
Re: computing surface- and contentflags
« Reply #2 on: January 09, 2015, 06:28:02 am »
Somehow I missed the reply. Sorry and thank you.

What I am looking for is a way to do that in a script. Is there a name for this kind of encoding that I could ask my favourite www-search-engine for? Or an easy way to do this in ..., well ..., let's say ..., Python?  :-[

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: computing surface- and contentflags
« Reply #3 on: January 09, 2015, 07:30:21 am »
bit operations. especially the logical and and the right shifting for the level flags.

Offline ShipIt

  • Project Artist
  • Captain
  • ***
  • Posts: 906
    • View Profile
Re: computing surface- and contentflags
« Reply #4 on: January 10, 2015, 08:08:01 am »
So surfaceflags is 'bitwise and' ?

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: computing surface- and contentflags
« Reply #5 on: January 14, 2015, 05:56:22 am »
To check a flag you use the 'bitwise and' say: surfaceflags & someflag == someflag  (like the example I gave with windows' calculator — which does precisely a bitwise and)

You can get the flag for a given level by *left* shifting like this: 1 << n where n is the level number (starts from zero)

Additionally you can add flags together with 'bitwise or' so for example to get the flags for the two bottom levels in a single value: levelflags = (1 << 0) | (1 << 1)

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: computing surface- and contentflags
« Reply #6 on: January 14, 2015, 12:59:25 pm »
oh sorry, yes, left shifting of course.