From 25acfd26024bf4d1ab806c1b3cbc885118b0eb7b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 30 May 2023 16:20:01 +0200 Subject: add light entity serialization --- src/light.cpp | 14 +++++++++++++- src/light.hpp | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') 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(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; }; -- cgit v1.2.3