Object properties: Add 'glow', disables light's effect if negative

The 'glow' value is added to the ambient light value.
Negative 'glow' disables light's effect on object colour, for faking
self-lighting, UI-style entities, or programmatic colouring in mods.
This commit is contained in:
Rob Blanckaert 2017-09-01 23:12:15 -07:00 committed by paramat
parent 604fe2083d
commit a9d43a0471
9 changed files with 52 additions and 20 deletions

@ -4131,6 +4131,10 @@ Definition tables
-- ^ Limit automatic rotation to this value in degrees per second,
-- value < 0 no limit.
backface_culling = true, -- false to disable backface_culling for model
glow = 0,
-- ^ Add this much extra lighting when calculating texture color.
value < 0 disables light's effect on texture color.
For faking self-lighting, UI style entities, or programmatic coloring in mods.
nametag = "", -- by default empty, for players their name is shown if empty
nametag_color = <color>, -- sets color of nametag as ColorSpec
infotext = "", -- by default empty, text to be shown when pointed at object

@ -659,7 +659,10 @@ void GenericCAO::updateLight(u8 light_at_pos)
void GenericCAO::updateLightNoCheck(u8 light_at_pos)
{
u8 li = decode_light(light_at_pos);
if (m_glow < 0)
return;
u8 li = decode_light(light_at_pos + m_glow);
if (li != m_last_light) {
m_last_light = li;
video::SColor color(255,li,li,li);
@ -978,6 +981,7 @@ void GenericCAO::updateTextures(std::string mod)
m_previous_texture_modifier = m_current_texture_modifier;
m_current_texture_modifier = mod;
m_glow = m_prop.glow;
if (m_spritenode) {
if (m_prop.visual == "sprite") {

@ -106,6 +106,7 @@ private:
float m_step_distance_counter = 0.0f;
u8 m_last_light = 255;
bool m_is_visible = false;
s8 m_glow = 0;
std::vector<u16> m_children;

@ -179,6 +179,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
PROTOCOL VERSION 36:
Backwards compatibility drop
Add 'can_zoom' to player object properties
Add glow to object properties
*/
#define LATEST_PROTOCOL_VERSION 36

@ -58,6 +58,7 @@ std::string ObjectProperties::dump()
os << ", makes_footstep_sound=" << makes_footstep_sound;
os << ", automatic_rotate="<< automatic_rotate;
os << ", backface_culling="<< backface_culling;
os << ", glow=" << glow;
os << ", nametag=" << nametag;
os << ", nametag_color=" << "\"" << nametag_color.getAlpha() << "," << nametag_color.getRed()
<< "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" ";
@ -106,6 +107,7 @@ void ObjectProperties::serialize(std::ostream &os) const
os << serializeString(infotext);
os << serializeString(wield_item);
writeU8(os, can_zoom);
writeS8(os, glow);
// Add stuff only at the bottom.
// Never remove anything, because we don't want new versions of this
@ -153,4 +155,5 @@ void ObjectProperties::deSerialize(std::istream &is)
infotext = deSerializeString(is);
wield_item = deSerializeString(is);
can_zoom = readU8(is);
glow = readS8(is);
}

@ -50,6 +50,7 @@ struct ObjectProperties
bool automatic_face_movement_dir = false;
f32 automatic_face_movement_dir_offset = 0.0f;
bool backface_culling = true;
s8 glow = 0;
std::string nametag = "";
video::SColor nametag_color = video::SColor(255, 255, 255, 255);
f32 automatic_face_movement_max_rotation_per_sec = -1.0f;

@ -277,6 +277,7 @@ void read_object_properties(lua_State *L, int index,
}
lua_pop(L, 1);
getboolfield(L, -1, "backface_culling", prop->backface_culling);
getintfield(L, -1, "glow", prop->glow);
getstringfield(L, -1, "nametag", prop->nametag);
lua_getfield(L, -1, "nametag_color");
@ -362,6 +363,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
lua_setfield(L, -2, "automatic_face_movement_dir");
lua_pushboolean(L, prop->backface_culling);
lua_setfield(L, -2, "backface_culling");
lua_pushnumber(L, prop->glow);
lua_setfield(L, -2, "glow");
lua_pushlstring(L, prop->nametag.c_str(), prop->nametag.size());
lua_setfield(L, -2, "nametag");
push_ARGB8(L, prop->nametag_color);

@ -426,6 +426,19 @@ bool getintfield(lua_State *L, int table,
return got;
}
bool getintfield(lua_State *L, int table,
const char *fieldname, s8 &result)
{
lua_getfield(L, table, fieldname);
bool got = false;
if (lua_isnumber(L, -1)) {
result = lua_tointeger(L, -1);
got = true;
}
lua_pop(L, 1);
return got;
}
bool getintfield(lua_State *L, int table,
const char *fieldname, u16 &result)
{

@ -54,6 +54,8 @@ bool getintfield(lua_State *L, int table,
const char *fieldname, int &result);
bool getintfield(lua_State *L, int table,
const char *fieldname, u8 &result);
bool getintfield(lua_State *L, int table,
const char *fieldname, s8 &result);
bool getintfield(lua_State *L, int table,
const char *fieldname, u16 &result);
bool getintfield(lua_State *L, int table,