light: add transformers for color and mangle

This commit is contained in:
Eric Wasylishen 2016-07-22 14:02:43 -06:00
parent 191949e569
commit 8b8cc4a37a
4 changed files with 54 additions and 33 deletions

View File

@ -115,9 +115,6 @@ typedef struct entity_s {
#define MAX_LIGHTS 65536 #define MAX_LIGHTS 65536
extern entity_t *lights[MAX_LIGHTS]; extern entity_t *lights[MAX_LIGHTS];
/* detect colors with components in 0-1 and scale them to 0-255 */
void normalize_color_format(vec3_t color);
entity_t *FindEntityWithKeyPair(const char *key, const char *value); entity_t *FindEntityWithKeyPair(const char *key, const char *value);
const char *ValueForKey(const entity_t *ent, const char *key); const char *ValueForKey(const entity_t *ent, const char *key);
void GetVectorForKey(const entity_t *ent, const char *key, vec3_t vec); void GetVectorForKey(const entity_t *ent, const char *key, vec3_t vec);

View File

@ -306,34 +306,67 @@ public:
: lockable_vec_t(std::vector<std::string> { name }, v, minval, maxval) {} : lockable_vec_t(std::vector<std::string> { name }, v, minval, maxval) {}
}; };
enum class vec3_transformer_t {
NONE,
MANGLE_TO_VEC,
NORMALIZE_COLOR_TO_255
};
void vec_from_mangle(vec3_t v, const vec3_t m);
/* detect colors with components in 0-1 and scale them to 0-255 */
void normalize_color_format(vec3_t color);
class lockable_vec3_t : public lockable_setting_t { class lockable_vec3_t : public lockable_setting_t {
private: private:
vec3_t _value; vec3_t _value;
vec3_transformer_t _transformer;
public:
lockable_vec3_t(std::vector<std::string> names, vec_t a, vec_t b, vec_t c) void transformAndSetVec3Value(const vec3_t val) {
: lockable_setting_t(names) // apply transform
{ switch (_transformer) {
VectorSet(_value, a, b, c); case vec3_transformer_t::NONE:
VectorCopy(val, _value);
break;
case vec3_transformer_t::MANGLE_TO_VEC:
vec_from_mangle(_value, val);
break;
case vec3_transformer_t::NORMALIZE_COLOR_TO_255:
VectorCopy(val, _value);
normalize_color_format(_value);
break;
}
} }
lockable_vec3_t(std::string name, vec_t a, vec_t b, vec_t c) public:
: lockable_vec3_t(std::vector<std::string> { name }, a,b,c) {} lockable_vec3_t(std::vector<std::string> names, vec_t a, vec_t b, vec_t c,
vec3_transformer_t t = vec3_transformer_t::NONE)
: lockable_setting_t(names), _transformer(t)
{
vec3_t tmp = { a, b, c };
transformAndSetVec3Value(tmp);
}
lockable_vec3_t(std::string name, vec_t a, vec_t b, vec_t c,
vec3_transformer_t t = vec3_transformer_t::NONE)
: lockable_vec3_t(std::vector<std::string> { name }, a,b,c,t) {}
const vec3_t *vec3Value() const { const vec3_t *vec3Value() const {
return &_value; return &_value;
} }
void setVec3Value(const vec3_t val) { void setVec3Value(const vec3_t val) {
assert(_registered); assert(_registered);
if (!_locked) { if (!_locked) {
VectorCopy(val, _value); transformAndSetVec3Value(val);
} }
} }
void setVec3ValueLocked(const vec3_t val) { void setVec3ValueLocked(const vec3_t val) {
assert(_registered); assert(_registered);
VectorCopy(val, _value); transformAndSetVec3Value(val);
_locked = true; _locked = true;
} }

View File

@ -41,17 +41,17 @@ using strings = std::vector<std::string>;
/* temporary storage for sunlight settings before the sun_t objects are created. */ /* temporary storage for sunlight settings before the sun_t objects are created. */
lockable_vec_t sunlight { "sunlight", 0.0f }; /* main sun */ lockable_vec_t sunlight { "sunlight", 0.0f }; /* main sun */
lockable_vec3_t sunlight_color { "sunlight_color", 255.0f, 255.0f, 255.0f }; lockable_vec3_t sunlight_color { "sunlight_color", 255.0f, 255.0f, 255.0f, vec3_transformer_t::NORMALIZE_COLOR_TO_255 };
lockable_vec_t sun2 { "sun2", 0.0f }; /* second sun */ lockable_vec_t sun2 { "sun2", 0.0f }; /* second sun */
lockable_vec3_t sun2_color { "sun2_color", 255.0f, 255.0f, 255.0f }; lockable_vec3_t sun2_color { "sun2_color", 255.0f, 255.0f, 255.0f, vec3_transformer_t::NORMALIZE_COLOR_TO_255 };
lockable_vec_t sunlight2 { "sunlight2", 0.0f }; /* top sky dome */ lockable_vec_t sunlight2 { "sunlight2", 0.0f }; /* top sky dome */
lockable_vec3_t sunlight2_color { strings{"sunlight2_color", "sunlight_color2"}, 255.0f, 255.0f, 255.0f }; lockable_vec3_t sunlight2_color { strings{"sunlight2_color", "sunlight_color2"}, 255.0f, 255.0f, 255.0f, vec3_transformer_t::NORMALIZE_COLOR_TO_255 };
lockable_vec_t sunlight3 { "sunlight3", 0.0f }; /* bottom sky dome */ lockable_vec_t sunlight3 { "sunlight3", 0.0f }; /* bottom sky dome */
lockable_vec3_t sunlight3_color { strings{"sunlight3_color", "sunlight_color3"}, 255.0f, 255.0f, 255.0f }; lockable_vec3_t sunlight3_color { strings{"sunlight3_color", "sunlight_color3"}, 255.0f, 255.0f, 255.0f, vec3_transformer_t::NORMALIZE_COLOR_TO_255 };
lockable_vec_t sunlight_dirt { "sunlight_dirt", 0.0f }; lockable_vec_t sunlight_dirt { "sunlight_dirt", 0.0f };
lockable_vec_t sunlight2_dirt { "sunlight2_dirt", 0.0f }; lockable_vec_t sunlight2_dirt { "sunlight2_dirt", 0.0f };
lockable_vec3_t sunvec { strings{"sunlight_mangle", "sun_mangle"}, 0.0f, 0.0f, -1.0f }; /* defaults to straight down */ lockable_vec3_t sunvec { strings{"sunlight_mangle", "sun_mangle"}, 0.0f, -90.0f, 0.0f, vec3_transformer_t::MANGLE_TO_VEC }; /* defaults to straight down */
lockable_vec3_t sun2vec { "sun2_mangle", 0.0f, 0.0f, -1.0f }; /* defaults to straight down */ lockable_vec3_t sun2vec { "sun2_mangle", 0.0f, -90.0f, 0.0f, vec3_transformer_t::MANGLE_TO_VEC }; /* defaults to straight down */
lockable_vec_t sun_deviance { "sunlight_penumbra", 0.0f, 0.0f, 180.0f }; lockable_vec_t sun_deviance { "sunlight_penumbra", 0.0f, 0.0f, 180.0f };
// entity_t // entity_t
@ -180,7 +180,7 @@ scan_vec3(vec3_t dest, const char *buf, const char *name)
dest[i] = vec[i]; dest[i] = vec[i];
} }
static void void
vec_from_mangle(vec3_t v, const vec3_t m) vec_from_mangle(vec3_t v, const vec3_t m)
{ {
vec3_t tmp; vec3_t tmp;
@ -1026,26 +1026,20 @@ LoadEntities(const bsp2_t *bsp)
} else if (!strcmp(key, "_sunlight")) { } else if (!strcmp(key, "_sunlight")) {
sunlight.setFloatValue(atof(com_token)); sunlight.setFloatValue(atof(com_token));
} else if (!strcmp(key, "_sunlight_mangle") || !strcmp(key, "_sun_mangle")) { } else if (!strcmp(key, "_sunlight_mangle") || !strcmp(key, "_sun_mangle")) {
vec3_t tmp;
scan_vec3(vec, com_token, "_sun_mangle"); scan_vec3(vec, com_token, "_sun_mangle");
vec_from_mangle(tmp, vec); sunvec.setVec3Value(vec);
sunvec.setVec3Value(tmp);
} else if (!strcmp(key, "_sunlight_color")) { } else if (!strcmp(key, "_sunlight_color")) {
vec3_t tmp; vec3_t tmp;
scan_vec3(tmp, com_token, "_sunlight_color"); scan_vec3(tmp, com_token, "_sunlight_color");
normalize_color_format(tmp);
sunlight_color.setVec3Value(tmp); sunlight_color.setVec3Value(tmp);
} else if (!strcmp(key, "_sun2")) { } else if (!strcmp(key, "_sun2")) {
sun2.setFloatValue(atof(com_token)); sun2.setFloatValue(atof(com_token));
} else if (!strcmp(key, "_sun2_mangle")) { } else if (!strcmp(key, "_sun2_mangle")) {
scan_vec3(vec, com_token, "_sun2_mangle"); scan_vec3(vec, com_token, "_sun2_mangle");
vec3_t tmp; sun2vec.setVec3Value(vec);
vec_from_mangle(tmp, vec);
sun2vec.setVec3Value(tmp);
} else if (!strcmp(key, "_sun2_color")) { } else if (!strcmp(key, "_sun2_color")) {
vec3_t tmp; vec3_t tmp;
scan_vec3(tmp, com_token, "_sun2_color"); scan_vec3(tmp, com_token, "_sun2_color");
normalize_color_format(tmp);
sun2_color.setVec3Value(tmp); sun2_color.setVec3Value(tmp);
} else if (!strcmp(key, "_sunlight2")) { } else if (!strcmp(key, "_sunlight2")) {
sunlight2.setFloatValue(atof(com_token)); sunlight2.setFloatValue(atof(com_token));
@ -1054,17 +1048,14 @@ LoadEntities(const bsp2_t *bsp)
} else if (!strcmp(key, "_sunlight2_color") || !strcmp(key, "_sunlight_color2")) { } else if (!strcmp(key, "_sunlight2_color") || !strcmp(key, "_sunlight_color2")) {
vec3_t tmp; vec3_t tmp;
scan_vec3(tmp, com_token, key); scan_vec3(tmp, com_token, key);
normalize_color_format(tmp);
sunlight2_color.setVec3Value(tmp); sunlight2_color.setVec3Value(tmp);
} else if (!strcmp(key, "_sunlight3_color") || !strcmp(key, "_sunlight_color3")) { } else if (!strcmp(key, "_sunlight3_color") || !strcmp(key, "_sunlight_color3")) {
vec3_t tmp; vec3_t tmp;
scan_vec3(tmp, com_token, key); scan_vec3(tmp, com_token, key);
normalize_color_format(tmp);
sunlight3_color.setVec3Value(tmp); sunlight3_color.setVec3Value(tmp);
} else if (!strcmp(key, "_minlight_color")) { } else if (!strcmp(key, "_minlight_color")) {
vec3_t tmp; vec3_t tmp;
scan_vec3(tmp, com_token, "_minlight_color"); scan_vec3(tmp, com_token, "_minlight_color");
normalize_color_format(tmp);
minlight_color.setVec3Value(tmp); minlight_color.setVec3Value(tmp);
} else if (!strcmp(key, "_anglesense") || !strcmp(key, "_anglescale")) } else if (!strcmp(key, "_anglesense") || !strcmp(key, "_anglescale"))
entity->anglescale = atof(com_token); entity->anglescale = atof(com_token);

View File

@ -56,7 +56,7 @@ qboolean scaledonly = false;
lockable_vec_t addminlight {"addmin", 0}; lockable_vec_t addminlight {"addmin", 0};
lockable_vec_t minlight {"light", 0}; lockable_vec_t minlight {"light", 0};
lockable_vec3_t minlight_color {strings{"minlight_color", "min_color"}, 255.0f, 255.0f, 255.0f}; lockable_vec3_t minlight_color {strings{"minlight_color", "min_color"}, 255.0f, 255.0f, 255.0f, vec3_transformer_t::NORMALIZE_COLOR_TO_255};
sun_t *suns = NULL; sun_t *suns = NULL;