limit the range of certain entity attributes

For example, direction angle values can be reduced to +- 360 degree.
(0..360 would be sufficient, but some people like their angles negative)

This is not a reduction of functionality or a security measure - it's for
convenience only: values now wrap around at the borders of their useful
ranges.
This commit is contained in:
ac-stef
2015-05-27 15:47:05 +02:00
parent 2349c7e508
commit f3904724d7
5 changed files with 27 additions and 3 deletions
+19
View File
@@ -662,3 +662,22 @@ void syncentchanges(bool force)
changedents.setsize(0);
lastentsync = lastmillis;
}
void clampentityattributes(persistent_entity &e)
{
if(e.type < MAXENTTYPES)
{
int c;
#define CLAMPATTR(x) \
c = entwraparound[e.type][x - 1]; \
if(c > 0) e.attr##x = (e.attr##x % c + c) % c; /* fold value into range 0..c */ \
else if(c < 0) e.attr##x = e.attr##x % (-c) /* fold value into range -c..c */
CLAMPATTR(1);
CLAMPATTR(2);
CLAMPATTR(3);
CLAMPATTR(4);
CLAMPATTR(5);
CLAMPATTR(6);
CLAMPATTR(7);
}
}