fix darkroom: add make_object_list

This commit is contained in:
bolero-MURAKAMI 2013-09-24 10:05:47 +09:00
parent abfa6082b4
commit 3cb882ce91
13 changed files with 128 additions and 14 deletions

View file

@ -9,6 +9,7 @@
#define SPROUT_DARKROOM_ACCESS_HPP
#include <sprout/config.hpp>
#include <sprout/darkroom/access/traits.hpp>
#include <sprout/darkroom/access/access.hpp>
#endif // #ifndef SPROUT_DARKROOM_ACCESS_HPP

View file

@ -11,6 +11,7 @@
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/darkroom/access/traits.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {

View file

@ -0,0 +1,45 @@
/*=============================================================================
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_ACCESS_TRAITS_HPP
#define SPROUT_DARKROOM_ACCESS_TRAITS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
namespace sprout {
namespace darkroom {
namespace access {
//
// is_tuple
//
template<typename T>
struct is_tuple
: public std::false_type
{};
template<typename T>
struct is_tuple<T const>
: public sprout::darkroom::access::is_tuple<T>
{};
template<typename T>
struct is_tuple<T volatile>
: public sprout::darkroom::access::is_tuple<T>
{};
template<typename T>
struct is_tuple<T const volatile>
: public sprout::darkroom::access::is_tuple<T>
{};
template<typename... Types>
struct is_tuple<sprout::tuples::tuple<Types...> >
: public std::true_type
{};
} // namespace access
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_ACCESS_TRAITS_HPP

View file

@ -61,6 +61,7 @@ namespace sprout {
return shade_1(inter, objs, sprout::index_pack<Lights...>::make());
}
};
//
// make_light_list
//

View file

@ -77,7 +77,7 @@ namespace sprout {
operator()(Intersection const& inter, Objects const& objs) const {
return shade_1(
inter,
sprout::darkroom::objects::intersect_list(
sprout::darkroom::objects::intersect(
objs,
sprout::darkroom::rays::make_ray(
sprout::darkroom::coords::add(

View file

@ -81,7 +81,7 @@ namespace sprout {
inter,
diff,
direction,
sprout::darkroom::objects::intersect_list(
sprout::darkroom::objects::intersect(
objs,
sprout::darkroom::rays::make_ray(
sprout::darkroom::coords::add(

View file

@ -10,6 +10,7 @@
#include <sprout/config.hpp>
#include <sprout/darkroom/objects/intersect.hpp>
#include <sprout/darkroom/objects/object_list.hpp>
#include <sprout/darkroom/objects/sphere.hpp>
#include <sprout/darkroom/objects/aa_plane.hpp>
#include <sprout/darkroom/objects/polygon.hpp>

View file

@ -10,6 +10,7 @@
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
@ -19,15 +20,19 @@ namespace sprout {
//
// intersect
//
template<typename Object, typename Ray>
template<
typename Object, typename Ray,
typename sprout::enabler_if<!sprout::darkroom::access::is_tuple<Object>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename Object::template intersection<Ray>::type
intersect(Object const& obj, Ray const& ray) {
return obj.intersect(ray);
}
intersect(Object const& obj, Ray const& ray);
template<
typename Object, typename Ray,
typename sprout::enabler_if<sprout::darkroom::access::is_tuple<Object>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename Object::template intersection<Ray>::type
intersect(Object const& obj, Ray const& ray);
//
// intersect_list
//
namespace detail {
template<std::size_t N>
struct intersect_list_impl {
@ -65,6 +70,9 @@ namespace sprout {
}
};
} // namespace detail
//
// intersect_list
//
template<typename Objects, typename Ray>
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Objects>::type::template intersection<Ray>::type
intersect_list(Objects const& objs, Ray const& ray) {
@ -72,6 +80,26 @@ namespace sprout {
sprout::darkroom::access::size<Objects>::value - 1
>()(objs, ray);
}
//
// intersect
//
template<
typename Object, typename Ray,
typename sprout::enabler_if<!sprout::darkroom::access::is_tuple<Object>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename Object::template intersection<Ray>::type
intersect(Object const& obj, Ray const& ray) {
return obj.intersect(ray);
}
template<
typename Object, typename Ray,
typename sprout::enabler_if<sprout::darkroom::access::is_tuple<Object>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Object>::type::template intersection<Ray>::type
intersect(Object const& obj, Ray const& ray) {
return sprout::darkroom::objects::intersect_list(obj, ray);
}
} // namespace objects
} // namespace darkroom
} // namespace sprout

View file

@ -0,0 +1,32 @@
/*=============================================================================
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_OBJECTS_OBJECT_LIST_HPP
#define SPROUT_DARKROOM_OBJECTS_OBJECT_LIST_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple/make_tuple.hpp>
#include <sprout/darkroom/intersects/intersection.hpp>
namespace sprout {
namespace darkroom {
namespace objects {
//
// make_object_list
//
template<typename... Objects>
inline SPROUT_CONSTEXPR auto
make_object_list(Objects&&... objs)
-> decltype(sprout::make_tuple(sprout::forward<Objects>(objs)...))
{
return sprout::make_tuple(sprout::forward<Objects>(objs)...);
}
} // namespace objects
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_OBJECTS_OBJECT_LIST_HPP

View file

@ -186,7 +186,7 @@ namespace sprout {
return color_1<Color>(
camera, objs, lights,
ray, depth_max,
sprout::darkroom::objects::intersect_list(objs, ray)
sprout::darkroom::objects::intersect(objs, ray)
);
}
};