summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Blanckaert <rob@withpiper.com>2017-09-01 23:12:15 -0700
committerparamat <mat.gregory@virginmedia.com>2017-09-14 04:06:05 +0100
commita9d43a04713dd0342d675f3bbb5cbacd863b4118 (patch)
treedde4ca88964a67c1a27211eca6f6fcf96fc246d0
parent604fe2083d70fea92b6c53c9a9d1c1ffdcb36610 (diff)
downloadminetest-a9d43a04713dd0342d675f3bbb5cbacd863b4118.tar.gz
minetest-a9d43a04713dd0342d675f3bbb5cbacd863b4118.tar.bz2
minetest-a9d43a04713dd0342d675f3bbb5cbacd863b4118.zip
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.
-rw-r--r--doc/lua_api.txt4
-rw-r--r--src/content_cao.cpp6
-rw-r--r--src/content_cao.h1
-rw-r--r--src/network/networkprotocol.h1
-rw-r--r--src/object_properties.cpp41
-rw-r--r--src/object_properties.h1
-rw-r--r--src/script/common/c_content.cpp3
-rw-r--r--src/script/common/c_converter.cpp13
-rw-r--r--src/script/common/c_converter.h2
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 = <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<u16> 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="<<hp_max;
- os<<", physical="<<physical;
- os<<", collideWithObjects="<<collideWithObjects;
- os<<", weight="<<weight;
- os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
- os<<", visual="<<visual;
- os<<", mesh="<<mesh;
- os<<", visual_size="<<PP2(visual_size);
- os<<", textures=[";
+ os << "hp_max=" << hp_max;
+ os << ", physical=" << physical;
+ os << ", collideWithObjects=" << collideWithObjects;
+ os << ", weight=" << weight;
+ os << ", collisionbox=" << PP(collisionbox.MinEdge) << "," << PP(collisionbox.MaxEdge);
+ os << ", visual=" << visual;
+ os << ", mesh=" << mesh;
+ os << ", visual_size=" << PP2(visual_size);
+ os << ", textures=[";
for (const std::string &texture : textures) {
- os<<"\""<< texture <<"\" ";
+ os << "\"" << texture << "\" ";
}
- os<<"]";
- os<<", colors=[";
+ os << "]";
+ os << ", colors=[";
for (const video::SColor &color : colors) {
os << "\"" << color.getAlpha() << "," << color.getRed() << ","
<< color.getGreen() << "," << color.getBlue() << "\" ";
}
- os<<"]";
- os<<", spritediv="<<PP2(spritediv);
- os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
- os<<", is_visible="<<is_visible;
- os<<", makes_footstep_sound="<<makes_footstep_sound;
- os<<", automatic_rotate="<<automatic_rotate;
- os<<", backface_culling="<<backface_culling;
+ os << "]";
+ os << ", spritediv=" << PP2(spritediv);
+ os << ", initial_sprite_basepos=" << PP2(initial_sprite_basepos);
+ os << ", is_visible=" << is_visible;
+ 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);
}
diff --git a/src/object_properties.h b/src/object_properties.h
index bd519e9ee..8ab1fa7fd 100644
--- a/src/object_properties.h
+++ b/src/object_properties.h
@@ -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;
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index ad92741f8..206ca55d0 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -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);
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
@@ -427,6 +427,19 @@ bool getintfield(lua_State *L, int table,
}
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)
{
lua_getfield(L, table, fieldname);
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
@@ -55,6 +55,8 @@ bool getintfield(lua_State *L, int table,
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,
const char *fieldname, u32 &result);