From a9d43a04713dd0342d675f3bbb5cbacd863b4118 Mon Sep 17 00:00:00 2001 From: Rob Blanckaert Date: Fri, 1 Sep 2017 23:12:15 -0700 Subject: [PATCH] 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. --- doc/lua_api.txt | 4 +++ src/content_cao.cpp | 6 ++++- src/content_cao.h | 1 + src/network/networkprotocol.h | 1 + src/object_properties.cpp | 41 +++++++++++++++++-------------- src/object_properties.h | 1 + src/script/common/c_content.cpp | 3 +++ src/script/common/c_converter.cpp | 13 ++++++++++ src/script/common/c_converter.h | 2 ++ 9 files changed, 52 insertions(+), 20 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 3c2278c8d..eac6f6697 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -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 = , -- sets color of nametag as ColorSpec infotext = "", -- by default empty, text to be shown when pointed at object diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 7659871b6..9a493daff 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -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") { diff --git a/src/content_cao.h b/src/content_cao.h index 93b532aad..575aad241 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -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 m_children; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 6d11dacc6..f4258e9cd 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -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 diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 172eec925..4171317de 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -33,31 +33,32 @@ ObjectProperties::ObjectProperties() std::string ObjectProperties::dump() { std::ostringstream os(std::ios::binary); - os<<"hp_max="<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); diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index e5d89dea9..8f88aeb60 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -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) { diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index f94996c88..18b8f6531 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -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,