summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-05-30 11:24:46 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-05-30 11:24:46 +0200
commit49e8918e20d9cce86a7a136a231e400c2680e88f (patch)
treebe8efc9f7d13b667a4e225b8dfa5f2c348b7ec10 /src
parent2970f407be7dd7aec13cf4733bf93b700abd2b0f (diff)
wip light inspect & serialize stuff
Diffstat (limited to 'src')
-rw-r--r--src/light-falloff.hpp4
-rw-r--r--src/light.cpp17
-rw-r--r--src/light.hpp15
-rw-r--r--src/pass-mode.hpp2
4 files changed, 13 insertions, 25 deletions
diff --git a/src/light-falloff.hpp b/src/light-falloff.hpp
index b9b1c4bf..3d047731 100644
--- a/src/light-falloff.hpp
+++ b/src/light-falloff.hpp
@@ -6,4 +6,8 @@ enum class light_falloff : uint8_t {
constant = 1, linear = 0, quadratic = 2,
};
+constexpr inline light_falloff light_falloff_COUNT{3};
+constexpr inline uint8_t light_falloff_BITS = 2;
+constexpr inline uint8_t light_falloff_MASK = (1 << 2)-1;
+
} // namespace floormat
diff --git a/src/light.cpp b/src/light.cpp
index ed9469f2..03fe4690 100644
--- a/src/light.cpp
+++ b/src/light.cpp
@@ -20,7 +20,7 @@ bool light_proto::operator==(const light_proto&) const = default;
light::light(object_id id, struct chunk& c, const light_proto& proto) :
entity{id, c, proto},
- half_dist{proto.half_dist},
+ max_distance{proto.max_distance},
color{proto.color},
falloff{proto.falloff}
{
@@ -43,19 +43,4 @@ bool light::update(size_t, float) { return false; }
bool light::is_dynamic() const { return true; }
bool light::is_virtual() const { return true; }
-Vector2 light::intensity(Vector2 half_dist, light_falloff falloff)
-{
- switch (falloff)
- {
- case light_falloff::linear: return 2 * half_dist;
- case light_falloff::quadratic: return Vector2{std::sqrt(2 * half_dist.x()), std::sqrt(2 * half_dist.y())};
- default: case light_falloff::constant: return Vector2{1, 1};
- }
-}
-
-Vector2 light::intensity() const
-{
- return intensity(half_dist, falloff);
-}
-
} // namespace floormat
diff --git a/src/light.hpp b/src/light.hpp
index e228c8b5..2202651a 100644
--- a/src/light.hpp
+++ b/src/light.hpp
@@ -15,18 +15,17 @@ struct light_proto : entity_proto
~light_proto() noexcept override;
bool operator==(const light_proto&) const;
- Vector2 half_dist{3};
+ float max_distance = 0;
Color3ub color{255, 255, 255};
light_falloff falloff : 3 = light_falloff::linear;
- uint8_t symmetric : 1 = true;
};
struct light final : entity
{
- Vector2 half_dist;
+ float max_distance;
Color3ub color;
- light_falloff falloff : 3;
- uint8_t symmetric : 1 = true;
+ light_falloff falloff : 2;
+ uint8_t enabled : 1 = true;
light(object_id id, struct chunk& c, const light_proto& proto);
@@ -37,10 +36,10 @@ struct light final : entity
bool is_dynamic() const override;
bool is_virtual() const override;
- static Vector2 intensity(Vector2 half_dist, light_falloff falloff);
- Vector2 intensity() const;
-
friend struct world;
};
+template<> struct entity_type_<struct light> : std::integral_constant<entity_type, entity_type::light> {};
+template<> struct entity_type_<struct light_proto> : std::integral_constant<entity_type, entity_type::light> {};
+
} // namespace floormat
diff --git a/src/pass-mode.hpp b/src/pass-mode.hpp
index 876466d7..0bf8d867 100644
--- a/src/pass-mode.hpp
+++ b/src/pass-mode.hpp
@@ -3,7 +3,7 @@
namespace floormat {
enum class pass_mode : unsigned char { blocked, see_through, shoot_through, pass, };
-constexpr inline unsigned char pass_mode_COUNT = 4;
+constexpr inline pass_mode pass_mode_COUNT{4};
constexpr inline unsigned char pass_mode_BITS = 2;
} // namespace floormat