Moved my silly nested directives experiment to a new branch
This commit is contained in:
parent
6832c10ed5
commit
179f220bb4
@ -38,7 +38,6 @@ SET (star_game_HEADERS
|
||||
StarDamageManager.hpp
|
||||
StarDamageTypes.hpp
|
||||
StarDanceDatabase.hpp
|
||||
StarDirectives.hpp
|
||||
StarDrawable.hpp
|
||||
StarDungeonGenerator.hpp
|
||||
StarDungeonImagePart.hpp
|
||||
@ -297,7 +296,6 @@ SET (star_game_SOURCES
|
||||
StarDamageManager.cpp
|
||||
StarDamageTypes.cpp
|
||||
StarDanceDatabase.cpp
|
||||
StarDirectives.cpp
|
||||
StarDrawable.cpp
|
||||
StarDungeonGenerator.cpp
|
||||
StarDungeonImagePart.cpp
|
||||
|
@ -1,51 +0,0 @@
|
||||
#include "StarImage.hpp"
|
||||
#include "StarImageProcessing.hpp"
|
||||
#include "StarDirectives.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
||||
NestedDirectives::NestedDirectives() {}
|
||||
NestedDirectives::NestedDirectives(String const& string) : m_root{ Leaf{ parseImageOperations(string), string} } {}
|
||||
|
||||
void NestedDirectives::addBranch(const Branch& newBranch) {
|
||||
convertToBranches();
|
||||
|
||||
m_root.value.get<Branches>().emplace_back(newBranch);
|
||||
}
|
||||
|
||||
String NestedDirectives::toString() const {
|
||||
String string;
|
||||
buildString(string, m_root);
|
||||
return string;
|
||||
}
|
||||
|
||||
void NestedDirectives::forEach() const {
|
||||
|
||||
}
|
||||
|
||||
Image NestedDirectives::apply(Image& image) const {
|
||||
Image current = image;
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
void NestedDirectives::buildString(String& string, const Cell& cell) const {
|
||||
if (auto leaf = cell.value.ptr<Leaf>())
|
||||
string += leaf->string;
|
||||
else {
|
||||
for (auto& branch : cell.value.get<Branches>())
|
||||
buildString(string, *branch);
|
||||
}
|
||||
}
|
||||
|
||||
void NestedDirectives::convertToBranches() {
|
||||
if (m_root.value.is<Branches>())
|
||||
return;
|
||||
|
||||
Leaf& leaf = m_root.value.get<Leaf>();
|
||||
Branches newBranches;
|
||||
newBranches.emplace_back(std::make_shared<Cell const>(move(leaf)));
|
||||
m_root.value = move(newBranches);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
#ifndef STAR_DIRECTIVES_HPP
|
||||
#define STAR_DIRECTIVES_HPP
|
||||
|
||||
#include "StarImageProcessing.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
||||
STAR_CLASS(NestedDirectives);
|
||||
|
||||
// Attempt at reducing memory allocation and per-frame string parsing for extremely long directives
|
||||
class NestedDirectives {
|
||||
public:
|
||||
struct Leaf {
|
||||
List<ImageOperation> operations;
|
||||
String string;
|
||||
};
|
||||
|
||||
struct Cell;
|
||||
typedef std::shared_ptr<Cell const> Branch;
|
||||
typedef List<Branch> Branches;
|
||||
|
||||
struct Cell {
|
||||
Variant<Leaf, Branches> value;
|
||||
|
||||
Cell() : value(Leaf()) {};
|
||||
Cell(Leaf&& leaf) : value(move(leaf)) {};
|
||||
Cell(Branches&& branches) : value(move(branches)) {};
|
||||
Cell(const Leaf& leaf) : value(leaf) {};
|
||||
Cell(const Branches& branches) : value(branches) {};
|
||||
};
|
||||
|
||||
|
||||
NestedDirectives();
|
||||
NestedDirectives(String const& string);
|
||||
|
||||
void addBranch(const Branch& newBranch);
|
||||
const Branch& branch() const;
|
||||
String toString() const;
|
||||
void forEach() const;
|
||||
Image apply(Image& image) const;
|
||||
private:
|
||||
void buildString(String& string, const Cell& cell) const;
|
||||
void convertToBranches();
|
||||
|
||||
Cell m_root;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user