4#include <glm/gtc/type_ptr.hpp>
10#include "Components/Core/MeshComponent.h"
12#include "Components/DataSetComponent.h"
13#include "Components/DataRefComponent.h"
14#include "Systems/DataSetSystem.h"
15#include "Foundation/Logging/Logger.h"
18#define ECHOSOUNDER_ASSERT_EQUAL(a,b) do { if(!((a)==(b))) EchosounderDump(#a, a, #b, b,"==", __FILE__, __LINE__);} while(0)
19#define ECHOSOUNDER_ASSERT_NOT_EQUAL(a,b) do { if(!((a)!=(b))) EchosounderDump(#a, a, #b, b,"!=", __FILE__, __LINE__);} while(0)
21#define ECHOSOUNDER_ASSERT_LESS(a,b) do { if(!((a)<(b))) EchosounderDump(#a, a, #b, b,"<", __FILE__, __LINE__);} while(0)
22#define ECHOSOUNDER_ASSERT_LESS_EQUAL(a,b) do { if(!((a)<=(b))) EchosounderDump(#a, a, #b, b,"<=", __FILE__, __LINE__);} while(0)
23#define ECHOSOUNDER_ASSERT_LESS_EQUAL_FLAG(a,b) do { if(!((a)<=(b))) {EchosounderDump(#a, a, #b, b,"<=", __FILE__, __LINE__); error = true;}} while(0)
24#define ECHOSOUNDER_ASSERT_EQUAL_FLAG(a,b) do { if(!((a)==(b))) {EchosounderDump(#a, a, #b, b,"==", __FILE__, __LINE__); error = true;}} while(0)
26#define ECHOSOUNDER_ASSERT_IS_FINITE(a) do { if(!std::isfinite(a)) { LOG_ERROR(Cogs::Logging::getLogger("EchoSounder"), "%s@%d: %s is not finite (=%f).", __FILE__, __LINE__, #a, a); } } while(0)
28#define ECHOSOUNDER_ASSERT_THROW_EQUAL(a,b) do { if(!((a)==(b))) throw std::runtime_error(EchosounderDumpString(#a, a, #b, b,"==", __FILE__, __LINE__));} while(0)
29#define ECHOSOUNDER_ASSERT_THROW_NOT_EQUAL(a,b) do { if(!((a)!=(b))) throw std::runtime_error(EchosounderDumpString(#a, a, #b, b,"!=", __FILE__, __LINE__));} while(0)
31#define ECHOSOUNDER_ASSERT_THROW_LESS(a,b) do { if(!((a)<(b))) throw std::runtime_error(EchosounderDumpString(#a, a, #b, b,"<", __FILE__, __LINE__));} while(0)
32#define ECHOSOUNDER_ASSERT_THROW_LESS_EQUAL(a,b) do { if(!((a)<=(b))) throw std::runtime_error(EchosounderDumpString(#a, a, #b, b,"<=", __FILE__, __LINE__));} while(0)
33#define ECHOSOUNDER_ASSERT_THROW_LESS_EQUAL_FLAG(a,b) do { if(!((a)<=(b))) {throw std::runtime_error(EchosounderDumpString(#a, a, #b, b,"<=", __FILE__, __LINE__)); error = true;}} while(0)
34#define ECHOSOUNDER_ASSERT_THROW_EQUAL_FLAG(a,b) do { if(!((a)==(b))) {throw std::runtime_error(EchosounderDumpString(#a, a, #b, b,"==", __FILE__, __LINE__)); error = true;}} while(0)
36#define ECHOSOUNDER_ASSERT_THROW_IS_FINITE(a) do { if(!std::isfinite(a)) {throw std::runtime_error(EchoSounderWhereString(__FILE__, __LINE__, "Is not finite.")); } } while(0)
41 std::string EchoSounderWhereString(
const std::string& file,
int line,
const std::string& msg)
44 o << file <<
'@' << line <<
": " << msg;
48 template<
typename S,
typename T>
49 std::string EchosounderDumpString(
const std::string& aStr,
const S& a,
50 const std::string& bStr,
const T& b,
51 const std::string& op,
52 const std::string& file,
int line)
55 o << file <<
'@' << line <<
": " << aStr <<
"(=" << a <<
") " << op <<
' ' << bStr <<
"(=" << b <<
") failed.";
59 template<
typename S,
typename T>
60 void EchosounderDump(
const std::string& aStr,
const S& a,
61 const std::string& bStr,
const T& b,
62 const std::string& op,
63 const std::string& file,
int line)
65 LOG_ERROR(
Cogs::Logging::getLogger(
"EchoSounder"),
"%s", EchosounderDumpString(aStr, a, bStr, b, op, file, line).c_str());
71 inline uint32_t unwrappedDistance(
const uint32_t hi,
const uint32_t lo,
const uint32_t wrap)
73 return hi - lo + (hi < lo ? wrap : 0);
76 template<
typename S,
typename D>
77 inline void wrappableMemCopy(D& dst,
const S& src,
int lo,
int hi,
int period,
int stride)
79 static_assert(std::is_same<S::value_type, D::value_type>::value,
"Source and destination types must match");
82 dst.resize(stride*(hi - lo));
85 auto n = (hi - lo)*stride;
86 debug_assert(o + n <= src.size());
87 std::memcpy(dst.data(), src.data() + o,
sizeof(S::value_type)*n);
90 dst.resize(stride*(hi - lo + period));
93 auto n = (period - lo)*stride;
94 debug_assert(o + n <= src.size());
95 std::memcpy(dst.data(), src.data() + o,
sizeof(S::value_type)*n);
97 o = (period - lo)*stride;
99 debug_assert(o + n <= src.size());
100 std::memcpy(dst.data() + o, src.data(),
sizeof(S::value_type)*n);
109 meshComp->setChanged();
114 template<
typename Container>
115 int locateContainingInterval(
const int fullIndexRange_a,
116 const int fullIndexRange_b,
118 const Container& timestamp,
121 auto currentIndexRange_a = fullIndexRange_a;
122 auto currentIndexRange_b = fullIndexRange_b;
123 auto currentTickRange_a = timestamp[currentIndexRange_a];
124 auto currentTickRange_b = timestamp[currentIndexRange_b % M];
126 int index = currentIndexRange_a;
129 if (time <= currentTickRange_a) {
130 index = currentIndexRange_a;
132 else if (currentTickRange_b <= time) {
133 index = currentIndexRange_b;
135 else if (currentIndexRange_b - currentIndexRange_a < 2) {
136 index = currentIndexRange_a;
141 int d = currentIndexRange_b - currentIndexRange_a - 2;
142 int i =
static_cast<int>(((time - currentTickRange_a)*d) / (currentTickRange_b - currentTickRange_a));
145 int mi = currentIndexRange_a + 1 + std::max(0, std::min(d, i));
147 int64_t mt = timestamp[mi % M];
150 currentIndexRange_b = mi;
151 currentTickRange_b = mt;
154 currentIndexRange_a = mi;
155 currentTickRange_a = mt;
160 if (fullIndexRange_a < index) {
161 ECHOSOUNDER_ASSERT_THROW_LESS_EQUAL(timestamp[index % M], time);
163 if (index + 2 <= fullIndexRange_b) {
164 ECHOSOUNDER_ASSERT_THROW_LESS(time, timestamp[(index + 1) % M]);
176 *dataCompOut =
nullptr;
177 *dataDataOut =
nullptr;
183 auto * dataData = &dataSetSystem->getData(dataComp);
185 if (1 <= dataData->persistent->buffer.sliceCount) {
186 *dataCompOut = dataComp;
187 *dataDataOut = dataData;
192 else if (dataComp->hasChanged() || refComp->hasChanged()) {
198 else if (refComp->hasChanged()) {
Base class for Component instances.
ComponentType * getComponent() const
Contains a handle to a Mesh resource to use when rendering using the MeshRenderComponent.
MeshHandle meshHandle
Handle to a Mesh resource to use when rendering.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.