Skip to content

Commit 3780f36

Browse files
committed
Tmp (compiling)
1 parent b644089 commit 3780f36

File tree

13 files changed

+55
-49
lines changed

13 files changed

+55
-49
lines changed

include/luxrays/core/namedobject.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,17 @@ class NamedObject {
6464
std::string name;
6565
};
6666

67+
68+
inline bool operator==(const NamedObject& lhs, const NamedObject& rhs) {
69+
return std::addressof(lhs) == std::addressof(rhs);
70+
}
71+
72+
inline bool operator!=(const NamedObject& lhs, const NamedObject& rhs) {
73+
return not (lhs == rhs);
6774
}
6875

76+
} // namespace luxrays
77+
6978
BOOST_SERIALIZATION_ASSUME_ABSTRACT(luxrays::NamedObject)
7079

7180
BOOST_CLASS_VERSION(luxrays::NamedObject, 3)

include/luxrays/core/namedobjectvector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline bool operator==(
5353
luxrays::NamedObjectRefWrapper const& lhs,
5454
luxrays::NamedObjectRefWrapper const& rhs
5555
) {
56-
return lhs.get().GetName() == rhs.get().GetName();
56+
return std::addressof(lhs.get()) == std::addressof(rhs.get());
5757
}
5858

5959
struct UndefinedNamedObjectError : public std::runtime_error {

include/luxrays/core/trianglemesh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class InstanceTriangleMesh : virtual public Mesh {
268268
cachedArea = -1.f;
269269
}
270270

271-
TriangleMeshRef GetTriangleMesh() const { return *mesh; };
271+
TriangleMeshConstRef GetTriangleMesh() const { return *mesh; };
272272

273273
friend class boost::serialization::access;
274274

@@ -356,7 +356,7 @@ class MotionTriangleMesh : virtual public Mesh {
356356

357357
virtual void ApplyTransform(const Transform &t);
358358

359-
TriangleMeshRef GetTriangleMesh() const { return *mesh; };
359+
TriangleMeshConstRef GetTriangleMesh() const { return *mesh; };
360360
const MotionSystem &GetMotionSystem() const { return motionSystem; }
361361

362362
friend class boost::serialization::access;

include/luxrays/usings.h

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,46 @@ namespace std {
3737

3838

3939

40-
// OptionalPtr is a template to build an optional reference (meaning a
41-
// reference that can be null) from a given type.
42-
// It is especially suitable for reference that are not initialized during
43-
// construction, but later.
44-
// Reference, if exists, can be access by operator(), among other methods.
40+
// OptionalPtr is a template to build an optional pointer from a given type.
41+
// OptionalPtr differs from a raw pointer in at least two ways:
42+
// - The absence of a pointed object is represented by std::nullopt. Dereferencing
43+
// the pointer in this case will raise a std::bad_optional_access exception, rather
44+
// than the infamous segmentation fault.
45+
// - By convention, OptionalPtr is explicitely a *non-owning pointer*.
46+
//
4547
template<typename T>
4648
struct OptionalPtr : public std::optional<std::reference_wrapper<T>> {
4749
using parent = std::optional<std::reference_wrapper<T>>;
4850

4951
using parent::operator=;
5052
using parent::parent;
5153

52-
T& operator*() const noexcept {
54+
const T& operator*() const {
5355
return this->value().get();
5456
}
55-
56-
const T* operator->(void) const {
57-
return &this->value().get();
57+
T& operator*() {
58+
return this->value().get();
5859
}
59-
T* operator->(void) {
60-
return &this->value().get();
60+
61+
T* operator->(void) const {
62+
return std::pointer_traits<T*>::pointer_to(this->value().get());
6163
}
6264

63-
inline bool operator==(const OptionalPtr<T>& rhs) const {
64-
if (bool(*this) xor bool(rhs)) return false;
65-
if (!*this and !rhs) return true;
66-
return &this->value() == &rhs.value();
65+
inline bool operator==(const OptionalPtr<T>& other) const {
66+
if (bool(*this) xor bool(other)) return false;
67+
if (!*this and !other) return true;
68+
69+
T& lhs = this->value().get();
70+
T& rhs = other.value().get();
71+
72+
return lhs == rhs; // Rely on underlying type operator
6773
}
68-
inline bool operator==(const T& rhs) const {
74+
inline bool operator==(const T& other) const {
6975
if (not this->has_value()) return false;
70-
return &this->value().get() == &rhs;
76+
77+
T& lhs = this->value().get();
78+
T& rhs = other;
79+
return lhs == rhs;
7180
}
7281

7382

include/slg/imagemap/imagemap.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,6 @@ struct std::hash<OptionalPtr<const slg::ImageMap>> {
11141114
}
11151115
};
11161116

1117-
//bool operator==(slg::ImageMapConstRef im1, slg::ImageMapConstRef im2);
1118-
//bool operator==(const slg::ImageMap im1, const slg::ImageMap im2);
1119-
bool operator==(
1120-
const OptionalPtr<const slg::ImageMap>, const OptionalPtr<const slg::ImageMap>
1121-
);
1122-
11231117

11241118
BOOST_SERIALIZATION_ASSUME_ABSTRACT(slg::ImageMapStorage)
11251119

include/slg/lights/strategies/distributionlightstrategy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class DistributionLightStrategy : public LightStrategy {
3131
public:
3232
virtual ~DistributionLightStrategy() { delete lightsDistribution; }
3333

34-
virtual void Preprocess(SceneConstRef scn, const LightStrategyTask taskType) {}
34+
virtual void Preprocess(SceneConstRef scn, const LightStrategyTask taskType) {
35+
scene = scn;
36+
}
3537

3638
// Used for direct light sampling
3739
virtual OptionalPtr<LightSource> SampleLights(

include/slg/lights/strategies/lightstrategy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class LightStrategy {
9393

9494
LightStrategy(const LightStrategyType t) : type(t) { }
9595

96+
OptionalPtr<const Scene> scene; // I think this could be a (mandatory) reference but
97+
// for now, I keep it as a (optional) pointer
98+
9699
private:
97100
const LightStrategyType type;
98101
};

include/slg/textures/texture.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,7 @@ inline float Noise(const luxrays::Point &P) {
121121
return Noise(P.x, P.y, P.z);
122122
}
123123

124-
inline bool operator==(TextureConstRef lhs, TextureConstRef rhs) {
125-
return &lhs == &rhs;
126-
}
127-
128-
inline bool operator!=(TextureConstRef lhs, TextureConstRef rhs) {
129-
return &lhs != &rhs;
130-
}
131-
132-
133-
134-
}
124+
} // namespace slg
135125

136126

137127

include/slg/volumes/volume.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,7 @@ class SchlickScatter {
118118
};
119119

120120

121-
inline bool operator==(VolumeConstRef v1, VolumeConstRef v2) {
122-
return std::addressof(v1) == std::addressof(v2);
123-
}
124-
125-
126-
127-
}
121+
} // namespace slg
128122

129123
#endif /* _SLG_VOLUME_H */
130124
// vim: autoindent noexpandtab tabstop=4 shiftwidth=4

scenes/albedo/luxball-albedo.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
native.threads.count = 1
12
debug.scene.parse.print = 1
23
debug.renderconfig.parse.print = 1
34
scene.file = scenes/albedo/luxball-albedo.scn

0 commit comments

Comments
 (0)