Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SdlCommandGenerator.h
Go to the documentation of this file.
1#pragma once
2
3#include "SDL/sdl_fwd.h"
6#include "Utility/TSpan.h"
7
8#include <string_view>
9#include <string>
10#include <cstddef>
11#include <unordered_set>
12#include <memory>
13#include <vector>
14#include <utility>
15
16namespace ph
17{
18
19class SemanticVersion;
20
22{
23public:
24 explicit SdlCommandGenerator(TSpanView<const SdlClass*> targetClasses);
25 SdlCommandGenerator(TSpanView<const SdlClass*> targetClasses, const Path& sceneWorkingDirectory);
27
28 // TODO: parameters like binary form? multi-thread?
29 // TODO: command types, e.g., phantom
30
32 const ISdlResource* resource,
33 std::string_view resourceName);
34
36 const SdlNamedOutputClauses& namedClauses);
37
38 void generateVersionCommand(const SemanticVersion& version);
39
40 void setPacketInterface(std::unique_ptr<SdlDataPacketInterface> interface);
41 void setSceneWorkingDirectory(const Path& directory);
43 const Path& getSceneWorkingDirectory() const;
44 std::size_t numGeneratedCommands() const;
45 std::size_t numGenerationErrors() const;
46 void clearStats();
47 bool hasTarget(const SdlClass* clazz) const;
48
49protected:
56 virtual bool beginCommand(
57 const SdlClass* targetClass,
58 SdlOutputContext* out_ctx) = 0;
59
64 virtual void endCommand() = 0;
65
71 virtual void saveResource(
72 const ISdlResource* resource,
73 const SdlOutputContext& ctx,
74 SdlOutputClauses& clauses) = 0;
75
80 virtual void commandGenerated(
81 std::string_view commandStr,
82 const SdlOutputContext& ctx) = 0;
83
84private:
87 void generateLoadCommand(
88 const ISdlResource& resource,
89 const SdlOutputContext& ctx,
90 std::string_view resourceName,
91 const SdlOutputClauses& clauses,
92 std::string& out_commandStr);
93
94 std::string borrowStringBuffer();
95 void returnStringBuffer(std::string&& buffer);
96
97 static void appendFullSdlType(
98 const SdlClass* clazz,
99 std::string& out_commandStr);
100
101private:
102 std::unordered_set<const SdlClass*> m_targetClasses;
103 std::unique_ptr<SdlDataPacketInterface> m_packetInterface;
104 Path m_sceneWorkingDirectory;
105 std::size_t m_numGeneratedCommands;
106 std::size_t m_numGenerationErrors;
107 std::vector<std::string> m_stringBuffers;
108};
109
111{
112 return m_sceneWorkingDirectory;
113}
114
116{
117 return m_numGeneratedCommands;
118}
119
121{
122 return m_numGenerationErrors;
123}
124
125inline std::string SdlCommandGenerator::borrowStringBuffer()
126{
127 if(m_stringBuffers.empty())
128 {
129 m_stringBuffers.push_back(std::string());
130 }
131
132 std::string buffer = std::move(m_stringBuffers.back());
133 m_stringBuffers.pop_back();
134 return buffer;
135}
136
137inline void SdlCommandGenerator::returnStringBuffer(std::string&& buffer)
138{
139 buffer.clear();
140 m_stringBuffers.push_back(std::move(buffer));
141}
142
143}// end namespace ph
Interface for all SDL resource.
Definition ISdlResource.h:22
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
Definition SdlClass.h:25
Definition SdlCommandGenerator.h:22
bool hasTarget(const SdlClass *clazz) const
Definition SdlCommandGenerator.cpp:204
virtual bool beginCommand(const SdlClass *targetClass, SdlOutputContext *out_ctx)=0
Called when the generator starts producing a command.
virtual ~SdlCommandGenerator()
void setPacketInterface(std::unique_ptr< SdlDataPacketInterface > interface)
Definition SdlCommandGenerator.cpp:188
virtual void endCommand()=0
Called when the generator finishes producing a command. This is called last in the sequence of handle...
void generateResourceCommand(const ISdlResource *resource, std::string_view resourceName)
Definition SdlCommandGenerator.cpp:44
virtual void commandGenerated(std::string_view commandStr, const SdlOutputContext &ctx)=0
Called when one or more commands are generated.
const Path & getSceneWorkingDirectory() const
Definition SdlCommandGenerator.h:110
std::size_t numGeneratedCommands() const
Definition SdlCommandGenerator.h:115
void setSceneWorkingDirectory(const Path &directory)
Definition SdlCommandGenerator.cpp:193
std::size_t numGenerationErrors() const
Definition SdlCommandGenerator.h:120
void clearStats()
Definition SdlCommandGenerator.cpp:198
void generateVersionCommand(const SemanticVersion &version)
Definition SdlCommandGenerator.cpp:159
void generateCachedNamedDataPacketCommand(const SdlNamedOutputClauses &namedClauses)
Definition SdlCommandGenerator.cpp:108
virtual void saveResource(const ISdlResource *resource, const SdlOutputContext &ctx, SdlOutputClauses &clauses)=0
Save target resource into output clauses.
SdlDataPacketInterface & getPacketInterface()
Definition SdlCommandGenerator.cpp:38
SdlCommandGenerator(TSpanView< const SdlClass * > targetClasses)
Definition SdlCommandGenerator.cpp:20
Parsing & generating a group of SDL clauses.
Definition SdlDataPacketInterface.h:14
Definition SdlNamedOutputClauses.h:18
Definition SdlOutputClauses.h:14
Data that SDL output process can rely on.
Definition SdlOutputContext.h:19
Convenient software version handling routines. See https://semver.org/ for a detailed explaination of...
Definition SemanticVersion.h:16
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19