diff options
author | kwolekr <kwolekr@minetest.net> | 2014-02-08 17:50:26 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2014-02-08 17:50:59 -0500 |
commit | 83bafbe08b508266d31a6a76f1ffc2cddc662390 (patch) | |
tree | 555f877e367a8e1a00200c3fe3fa889538169291 /src/settings.h | |
parent | f4f98c9550325aa8178f99cd32ea8806669aa280 (diff) | |
download | minetest-83bafbe08b508266d31a6a76f1ffc2cddc662390.tar.gz minetest-83bafbe08b508266d31a6a76f1ffc2cddc662390.tar.bz2 minetest-83bafbe08b508266d31a6a76f1ffc2cddc662390.zip |
Make flag strings clear specified flag with 'no' prefix
Remove flagmask field from set_mapgen_params table
Add small bits of needed documentation
Diffstat (limited to 'src/settings.h')
-rw-r--r-- | src/settings.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/settings.h b/src/settings.h index cf698b0eb..2aa03074b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -572,12 +572,15 @@ public: return value; } - u32 getFlagStr(std::string name, FlagDesc *flagdesc) + u32 getFlagStr(std::string name, FlagDesc *flagdesc, u32 *flagmask) { std::string val = get(name); - return (isdigit(val[0])) ? stoi(val) : readFlagString(val, flagdesc); + return (isdigit(val[0])) ? stoi(val) : + readFlagString(val, flagdesc, flagmask); } + // N.B. if getStruct() is used to read a non-POD aggregate type, + // the behavior is undefined. bool getStruct(std::string name, std::string format, void *out, size_t olen) { size_t len = olen; @@ -755,10 +758,19 @@ fail: } } + // N.B. getFlagStrNoEx() does not set val, but merely modifies it. Thus, + // val must be initialized before using getFlagStrNoEx(). The intention of + // this is to simplify modifying a flags field from a default value. bool getFlagStrNoEx(std::string name, u32 &val, FlagDesc *flagdesc) { try { - val = getFlagStr(name, flagdesc); + u32 flags, flagmask; + + flags = getFlagStr(name, flagdesc, &flagmask); + + val &= ~flagmask; + val |= flags; + return true; } catch (SettingNotFoundException &e) { return false; @@ -856,6 +868,9 @@ fail: } //////////// Set setting + + // N.B. if setStruct() is used to write a non-POD aggregate type, + // the behavior is undefined. bool setStruct(std::string name, std::string format, void *value) { char sbuf[2048]; @@ -959,10 +974,11 @@ fail: set(name, std::string(sbuf)); return true; } - - void setFlagStr(std::string name, u32 flags, FlagDesc *flagdesc) + + void setFlagStr(std::string name, u32 flags, + FlagDesc *flagdesc, u32 flagmask) { - set(name, writeFlagString(flags, flagdesc)); + set(name, writeFlagString(flags, flagdesc, flagmask)); } void setBool(std::string name, bool value) |