CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RepeatPath.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10
11#include "Edge.hpp"
12#include "PathVertex.hpp"
13#include "Utility.hpp"
14
16
18 template<typename Path> class RepeatPath {
19 public:
20 class Edges {
21 public:
23
24 [[nodiscard]] Edge generate() const {
25 Edge temp = mEdges.generate();
26 temp.vertices += mDelta;
27 return temp;
28 }
29
30 void next() noexcept {
31 mEdges.next();
32
33 if(mEdges.done()) {
34 ++mIndex;
36 mEdges = mRepeatPath->mPath.edges();
37 }
38 }
39
40 private:
42
44 int mIndex;
45 int mDelta;
46
48 : mRepeatPath{repeatPath}, mEdges{repeatPath->mPath.edges()}, mIndex{repeatPath->mVertexCount > 0 ? 0 : repeatPath->mInstances}, mDelta{0} {}
49
50 friend class RepeatPath;
51 };
52
53 class Vertices {
54 public:
56
58 PathVertex temp = mVertices.generate();
59 temp.position += mDelta;
60 return temp;
61 }
62
63 void next() {
64 mVertices.next();
65
66 if(mVertices.done()) {
67 ++mIndex;
69 mVertices = mRepeatPath->mPath.vertices();
70 }
71 }
72
73 private:
77
80 int mIndex;
82
84 if(mRepeatPath->mInstances < 1)
85 return 0;
86
88 }
89
90 friend int count(const Vertices& generator) noexcept { return generator.countVertices(); }
91
92 friend class RepeatPath;
93 };
94
98 explicit RepeatPath(Path path, const int instances, const Vector3& delta) noexcept
99 : mPath{std::move(path)}, mInstances{instances}, mDelta{delta}, mVertexCount{count(mPath.vertices())} {}
100
101 [[nodiscard]] Edges edges() const noexcept { return Edges{this}; }
103
104 private:
109 };
110
111 template<typename Path> RepeatPath<Path> repeatPath(Path path, int instances, const Vector3& delta) noexcept {
112 return RepeatPath<Path>{std::move(path), instances, delta};
113 }
114
115} // namespace CeresEngine::MeshGenerator
decltype(std::declval< const Primitive * >() ->edges()) Type
Definition Utility.hpp:25
Definition Edge.hpp:14
Definition PathVertex.hpp:14
EdgeGeneratorType< Path >::Type mEdges
Definition RepeatPath.hpp:43
bool done() const noexcept
Definition RepeatPath.hpp:22
void next() noexcept
Definition RepeatPath.hpp:30
Edge generate() const
Definition RepeatPath.hpp:24
const RepeatPath * mRepeatPath
Definition RepeatPath.hpp:41
Edges(const RepeatPath *repeatPath) noexcept
Definition RepeatPath.hpp:47
int mDelta
Definition RepeatPath.hpp:45
int mIndex
Definition RepeatPath.hpp:44
int countVertices() const noexcept
Definition RepeatPath.hpp:83
int mIndex
Definition RepeatPath.hpp:80
VertexGeneratorType< Path >::Type mVertices
Definition RepeatPath.hpp:79
bool done() const noexcept
Definition RepeatPath.hpp:55
Vertices(const RepeatPath *repeatPath)
Definition RepeatPath.hpp:74
Vector3 mDelta
Definition RepeatPath.hpp:81
PathVertex generate() const
Definition RepeatPath.hpp:57
friend int count(const Vertices &generator) noexcept
Definition RepeatPath.hpp:90
const RepeatPath * mRepeatPath
Definition RepeatPath.hpp:78
void next()
Definition RepeatPath.hpp:63
Repeats the same path a given number of time at given intervals.
Definition RepeatPath.hpp:18
Vertices vertices() const noexcept
Definition RepeatPath.hpp:102
int mInstances
Definition RepeatPath.hpp:106
Vector3 mDelta
Definition RepeatPath.hpp:107
int mVertexCount
Definition RepeatPath.hpp:108
Path mPath
Definition RepeatPath.hpp:105
RepeatPath(Path path, const int instances, const Vector3 &delta) noexcept
Definition RepeatPath.hpp:98
Edges edges() const noexcept
Definition RepeatPath.hpp:101
decltype(std::declval< const Primitive * >() ->vertices()) Type
Definition Utility.hpp:39
Definition AnyGenerator.hpp:12
RepeatPath< Path > repeatPath(Path path, int instances, const Vector3 &delta) noexcept
Definition RepeatPath.hpp:111
constexpr CountAlgorithmFunctor count
Returns the number of elements matching an element.
Definition Count.hpp:82
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25