Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSdlVector3Array.h
Go to the documentation of this file.
1#pragma once
2
4#include "SDL/sdl_helpers.h"
7#include "Math/TVector3.h"
8
9#include <Common/assertion.h>
10#include <Common/primitive_type.h>
11
12#include <type_traits>
13#include <string>
14#include <vector>
15
16namespace ph
17{
18
19template<typename Owner, typename Element = real, typename SdlValueType = TSdlValue<std::vector<math::TVector3<Element>>, Owner>>
20class TSdlVector3Array : public SdlValueType
21{
22 static_assert(std::is_base_of_v<TSdlAbstractValue<std::vector<math::TVector3<Element>>, Owner>, SdlValueType>,
23 "SdlValueType should be a subclass of TSdlAbstractValue.");
24
25 static_assert(std::is_same_v<Element, real>,
26 "Currently supports only ph::real");
27
28public:
29 template<typename ValueType>
30 TSdlVector3Array(std::string valueName, ValueType Owner::* const valuePtr) :
31 SdlValueType("vector3-array", std::move(valueName), valuePtr)
32 {}
33
34 std::string valueAsString(const std::vector<math::TVector3<Element>>& vec3Array) const override
35 {
36 return "[" + std::to_string(vec3Array.size()) + " vector3 values...]";
37 }
38
39 SdlNativeData ownedNativeData(Owner& owner) const override
40 {
41 std::vector<math::TVector3<Element>>* const vec3Vec = this->getValue(owner);
42
43 SdlNativeData data;
44 if(vec3Vec)
45 {
46 math::TVector3<Element>* const vec3Data = vec3Vec->data();
47 data = SdlNativeData(
48 [vec3Data](std::size_t elementIdx) -> SdlGetterVariant
49 {
50 const auto vec3Idx = elementIdx / 3;
51 const auto compIdx = elementIdx - vec3Idx * 3;
52 return SdlNativeData::permissiveElementGetter(&(vec3Data[vec3Idx][compIdx]));
53 },
54 [vec3Data](std::size_t elementIdx, SdlSetterVariant input) -> bool
55 {
56 const auto vec3Idx = elementIdx / 3;
57 const auto compIdx = elementIdx - vec3Idx * 3;
58 return SdlNativeData::permissiveElementSetter(input, &(vec3Data[vec3Idx][compIdx]));
59 },
60 AnyNonConstPtr(vec3Vec));
61
62 data.numElements = vec3Vec->size() * 3;
63 }
66 data.tupleSize = 3;
67 return data;
68 }
69
70protected:
72 Owner& owner,
73 const SdlInputClause& clause,
74 const SdlInputContext& ctx) const override
75 {
76 // TODO: resource file
77
78 this->setValue(owner, sdl::load_vector3_array<Element>(clause.value));
79 }
80
82 const Owner& owner,
83 SdlOutputClause& out_clause,
84 const SdlOutputContext& ctx) const override
85 {
86 // TODO: resource file
87
88 if(const std::vector<math::TVector3<Element>>* const vec3Arr = this->getConstValue(owner); vec3Arr)
89 {
90 sdl::save_vector3_array<Element>(*vec3Arr, out_clause.value);
91 }
92 }
93};
94
95}// end namespace ph
Carries SDL representation of various data during the input process. Helps to read input data such as...
Definition SdlInputClause.h:15
std::string value
Loaded stringified data of a clause. All potential SDL value prefixes or suffixes (e....
Definition SdlInputClause.h:25
Data that SDL input process can rely on.
Definition SdlInputContext.h:19
Definition SdlNativeData.h:88
static auto permissiveElementSetter(SdlSetterVariant input, ElementType *out_elementPtr) -> bool
Given a valid target element, set its value in a permissive way (with auto conversions).
Definition SdlNativeData.ipp:349
std::size_t numElements
Hint for number of elements in this block of native data. For example, numElements would be 12 for an...
Definition SdlNativeData.h:99
std::size_t tupleSize
Hint for number of elements that form a natural group. For an array of 10 vec3s, tupleSize may have a...
Definition SdlNativeData.h:105
static auto permissiveElementGetter(ElementType *elementPtr) -> SdlGetterVariant
Given a valid target element, get its value in a permissive way (with auto conversions).
Definition SdlNativeData.ipp:312
ESdlDataType elementType
Hint for the type of elements.
Definition SdlNativeData.h:113
ESdlDataFormat elementContainer
Hint for the type that encapsulates elements.
Definition SdlNativeData.h:109
Carries SDL representation of various data during the output process. Helps to write output data such...
Definition SdlOutputClause.h:14
std::string value
Stores stringified data of a clause. As the output clause generator knows best how its data look like...
Definition SdlOutputClause.h:29
Data that SDL output process can rely on.
Definition SdlOutputContext.h:19
Definition SdlNativeData.h:24
Definition TSdlVector3Array.h:21
void saveToSdl(const Owner &owner, SdlOutputClause &out_clause, const SdlOutputContext &ctx) const override
Definition TSdlVector3Array.h:81
SdlNativeData ownedNativeData(Owner &owner) const override
Definition TSdlVector3Array.h:39
std::string valueAsString(const std::vector< math::TVector3< Element > > &vec3Array) const override
Definition TSdlVector3Array.h:34
void loadFromSdl(Owner &owner, const SdlInputClause &clause, const SdlInputContext &ctx) const override
Definition TSdlVector3Array.h:71
TSdlVector3Array(std::string valueName, ValueType Owner::*const valuePtr)
Definition TSdlVector3Array.h:30
Represents a 3-D vector.
Definition TVector3.h:17
std::vector< math::TVector3< Element > > load_vector3_array(std::string_view sdlVec3ArrayStr)
Definition sdl_helpers.ipp:200
void save_vector3_array(TSpanView< math::TVector3< Element > > values, std::string &out_str)
Definition sdl_helpers.ipp:383
constexpr ESdlDataType number_type_of()
Definition sdl_helpers.ipp:478
The root for all renderer implementations.
Definition EEngineProject.h:6
TAnyPtr< false > AnyNonConstPtr
A type-safe, lightweight wrapper for any non-const raw pointer type.
Definition TAnyPtr.h:47
Definition TAABB2D.h:96
Low-level helpers for SDL. Helpers are in an additional sdl namespace.