mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix darkroom: fix template operator() member-function call -> calcurate() free-function
This commit is contained in:
parent
3cb882ce91
commit
dfcb6bcf31
25 changed files with 494 additions and 129 deletions
138
sprout/darkroom/lights/calculate.hpp
Normal file
138
sprout/darkroom/lights/calculate.hpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP
|
||||
#define SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/indexes.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/darkroom/access/traits.hpp>
|
||||
#include <sprout/darkroom/access/access.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace darkroom {
|
||||
namespace lights {
|
||||
template<typename Light, typename Intersection, typename Objects>
|
||||
struct calculate_result;
|
||||
|
||||
namespace detail {
|
||||
template<typename Light, typename Intersection, typename Objects, bool IsTuple>
|
||||
struct calculate_result;
|
||||
|
||||
template<typename Light, typename Intersection, typename Objects>
|
||||
struct calculate_result<Light, Intersection, Objects, false>
|
||||
: public sprout::identity<typename Light::color_type>
|
||||
{};
|
||||
template<typename Light, typename Intersection, typename Objects>
|
||||
struct calculate_result<Light, Intersection, Objects, true>
|
||||
: public sprout::darkroom::lights::calculate_result<typename sprout::darkroom::access::unit<Light>::type, Intersection, Objects>
|
||||
{};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// calculate_result
|
||||
//
|
||||
template<typename Light, typename Intersection, typename Objects>
|
||||
struct calculate_result
|
||||
: public sprout::darkroom::lights::detail::calculate_result<
|
||||
Light, Intersection, Objects,
|
||||
sprout::darkroom::access::is_tuple<Light>::value
|
||||
>
|
||||
{};
|
||||
template<typename Light, typename Intersection, typename Objects>
|
||||
struct calculate_result<Light const, Intersection, Objects>
|
||||
: public sprout::darkroom::lights::calculate_result<Light, Intersection, Objects>
|
||||
{};
|
||||
template<typename Light, typename Intersection, typename Objects>
|
||||
struct calculate_result<Light volatile, Intersection, Objects>
|
||||
: public sprout::darkroom::lights::calculate_result<Light, Intersection, Objects>
|
||||
{};
|
||||
template<typename Light, typename Intersection, typename Objects>
|
||||
struct calculate_result<Light const volatile, Intersection, Objects>
|
||||
: public sprout::darkroom::lights::calculate_result<Light, Intersection, Objects>
|
||||
{};
|
||||
|
||||
//
|
||||
// calculate
|
||||
//
|
||||
template<
|
||||
typename Light, typename Intersection, typename Objects,
|
||||
typename sprout::enabler_if<!sprout::darkroom::access::is_tuple<Light>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Light, Intersection, Objects>::type
|
||||
calculate(Light const& light, Intersection const& inter, Objects const& objs);
|
||||
template<
|
||||
typename Light, typename Intersection, typename Objects,
|
||||
typename sprout::enabler_if<sprout::darkroom::access::is_tuple<Light>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Light, Intersection, Objects>::type
|
||||
calculate(Light const& light, Intersection const& inter, Objects const& objs);
|
||||
|
||||
namespace detail {
|
||||
template<typename Lights, typename Intersection, typename Objects, typename Color>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Lights, Intersection, Objects>::type
|
||||
calculate_2(Color const& col) {
|
||||
return col;
|
||||
}
|
||||
template<typename Lights, typename Intersection, typename Objects, typename Color1, typename Color2, typename... Tail>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Lights, Intersection, Objects>::type
|
||||
calculate_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) {
|
||||
return sprout::darkroom::lights::detail::calculate_2<Lights, Intersection, Objects>(
|
||||
sprout::darkroom::colors::add(col1, col2),
|
||||
tail...
|
||||
);
|
||||
}
|
||||
template<typename Lights, typename Intersection, typename Objects, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Lights, Intersection, Objects>::type
|
||||
calculate_1(
|
||||
Lights const& lights, Intersection const& inter, Objects const& objs,
|
||||
sprout::index_tuple<Indexes...>
|
||||
)
|
||||
{
|
||||
return sprout::darkroom::lights::detail::calculate_2<Lights, Intersection, Objects>(
|
||||
sprout::darkroom::lights::calculate(sprout::darkroom::access::get<Indexes>(lights), inter, objs)...
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// calculate_list
|
||||
//
|
||||
template<typename Lights, typename Intersection, typename Objects>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Lights, Intersection, Objects>::type
|
||||
calculate_list(Lights const& lights, Intersection const& inter, Objects const& objs) {
|
||||
return sprout::darkroom::lights::detail::calculate_1(
|
||||
lights, inter, objs,
|
||||
sprout::tuple_indexes<Lights>::make()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// calculate
|
||||
//
|
||||
template<
|
||||
typename Light, typename Intersection, typename Objects,
|
||||
typename sprout::enabler_if<!sprout::darkroom::access::is_tuple<Light>::value>::type
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Light, Intersection, Objects>::type
|
||||
calculate(Light const& light, Intersection const& inter, Objects const& objs) {
|
||||
return light(inter, objs);
|
||||
}
|
||||
template<
|
||||
typename Light, typename Intersection, typename Objects,
|
||||
typename sprout::enabler_if<sprout::darkroom::access::is_tuple<Light>::value>::type
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::lights::calculate_result<Light, Intersection, Objects>::type
|
||||
calculate(Light const& light, Intersection const& inter, Objects const& objs) {
|
||||
return sprout::darkroom::lights::calculate_list(light, inter, objs);
|
||||
}
|
||||
} // namespace lights
|
||||
} // namespace darkroom
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DARKROOM_LIGHTS_CALCULATE_HPP
|
|
@ -9,66 +9,21 @@
|
|||
#define SPROUT_DARKROOM_LIGHTS_LIGHT_LIST_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
#include <sprout/index_tuple/metafunction.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/darkroom/access/access.hpp>
|
||||
#include <sprout/darkroom/colors/rgb.hpp>
|
||||
#include <sprout/tuple/tuple/make_tuple.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace darkroom {
|
||||
namespace lights {
|
||||
//
|
||||
// light_list
|
||||
// make_object_list
|
||||
//
|
||||
template<typename... Lights>
|
||||
class light_list {
|
||||
public:
|
||||
typedef sprout::tuples::tuple<Lights...> lights_type;
|
||||
typedef typename sprout::darkroom::access::unit<lights_type>::type::color_type color_type;
|
||||
private:
|
||||
lights_type lights_;
|
||||
private:
|
||||
template<typename Color>
|
||||
SPROUT_CONSTEXPR color_type
|
||||
shade_2(Color const& col) const {
|
||||
return col;
|
||||
}
|
||||
template<typename Color1, typename Color2, typename... Tail>
|
||||
SPROUT_CONSTEXPR color_type
|
||||
shade_2(Color1 const& col1, Color2 const& col2, Tail const&... tail) const {
|
||||
return shade_2(
|
||||
sprout::darkroom::colors::add(col1, col2),
|
||||
tail...
|
||||
);
|
||||
}
|
||||
template<typename Intersection, typename Objects, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR color_type
|
||||
shade_1(
|
||||
Intersection const& inter, Objects const& objs,
|
||||
sprout::index_tuple<Indexes...>
|
||||
) const
|
||||
{
|
||||
return shade_2(sprout::darkroom::access::get<Indexes>(lights_).template operator()(inter, objs)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR light_list(Lights const&... lights)
|
||||
: lights_(lights...)
|
||||
{}
|
||||
template<typename Intersection, typename Objects>
|
||||
SPROUT_CONSTEXPR color_type
|
||||
operator()(Intersection const& inter, Objects const& objs) const {
|
||||
return shade_1(inter, objs, sprout::index_pack<Lights...>::make());
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// make_light_list
|
||||
//
|
||||
template<typename... Lights>
|
||||
inline SPROUT_CONSTEXPR sprout::darkroom::lights::light_list<Lights...>
|
||||
make_light_list(Lights const&... lights) {
|
||||
return sprout::darkroom::lights::light_list<Lights...>(lights...);
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
make_light_list(Lights&&... lights)
|
||||
-> decltype(sprout::make_tuple(sprout::forward<Lights>(lights)...))
|
||||
{
|
||||
return sprout::make_tuple(sprout::forward<Lights>(lights)...);
|
||||
}
|
||||
} // namespace lights
|
||||
} // namespace darkroom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue