summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-05-30 16:20:01 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-05-30 16:20:01 +0200
commit25acfd26024bf4d1ab806c1b3cbc885118b0eb7b (patch)
treea56047b16732eee9a689588970c5d61d296614b5 /src
parent64dcfaca1548a669c93fae686cacd634048cb2ea (diff)
add light entity serialization
Diffstat (limited to 'src')
-rw-r--r--src/light.cpp14
-rw-r--r--src/light.hpp3
2 files changed, 16 insertions, 1 deletions
diff --git a/src/light.cpp b/src/light.cpp
index 03fe4690..5c2c9145 100644
--- a/src/light.cpp
+++ b/src/light.cpp
@@ -22,7 +22,8 @@ light::light(object_id id, struct chunk& c, const light_proto& proto) :
entity{id, c, proto},
max_distance{proto.max_distance},
color{proto.color},
- falloff{proto.falloff}
+ falloff{proto.falloff},
+ enabled{proto.enabled}
{
}
@@ -38,6 +39,17 @@ Vector2 light::ordinal_offset(Vector2b) const
return ret;
}
+light::operator light_proto() const
+{
+ light_proto ret;
+ static_cast<entity_proto&>(ret) = entity_proto(*this);
+ ret.max_distance = max_distance;
+ ret.color = color;
+ ret.falloff = falloff;
+ ret.enabled = enabled;
+ return ret;
+}
+
entity_type light::type() const noexcept { return entity_type::light; }
bool light::update(size_t, float) { return false; }
bool light::is_dynamic() const { return true; }
diff --git a/src/light.hpp b/src/light.hpp
index 2202651a..1332efc3 100644
--- a/src/light.hpp
+++ b/src/light.hpp
@@ -18,6 +18,7 @@ struct light_proto : entity_proto
float max_distance = 0;
Color3ub color{255, 255, 255};
light_falloff falloff : 3 = light_falloff::linear;
+ uint8_t enabled : 1 = true;
};
struct light final : entity
@@ -36,6 +37,8 @@ struct light final : entity
bool is_dynamic() const override;
bool is_virtual() const override;
+ explicit operator light_proto() const;
+
friend struct world;
};