Load engine configuration from a JSON file, applying any present fields to the pre-Init config structs.
165{
167 auto result = ser.
read<EngineConfig>(path);
168 if (!result) {
169 MF_ERROR(Journal::Component::API, Journal::Context::Configuration,
170 "Failed to load config from {}: {}", path, ser.
last_error());
171 return false;
172 }
173 get_global_stream_info() = result->stream;
174 get_global_graphics_config() = result->graphics;
175 get_global_input_config() = result->input;
176 get_global_network_config() = result->network;
177
178 const auto& j = result->journal;
179
180 if (!j.severity.empty()) {
181 auto sev = Reflect::string_to_enum_case_insensitive<Journal::Severity>(j.severity);
182 if (sev) {
183 Config::set_journal_severity(*sev);
184 } else {
185 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
186 "Unknown journal severity: {}", j.severity);
187 }
188 }
189 if (j.sink_to_console)
190 Config::sink_journal_to_console();
191 if (!j.log_file.empty())
192 Config::store_journal_entries(j.log_file);
194 auto comp = Reflect::string_to_enum_case_insensitive<Journal::Component>(name);
195 if (comp) {
196 Config::set_journal_component_filter({ *comp }, false);
197 } else {
198 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
199 "Unknown journal component: {}", name);
200 }
201 }
202
204 auto ctx = Reflect::string_to_enum_case_insensitive<Journal::Context>(name);
205 if (ctx) {
206 Config::set_journal_context_filter({ *ctx }, false);
207 } else {
208 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
209 "Unknown journal context: {}", name);
210 }
211 }
212
213 return true;
214}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::vector< std::string > disable_contexts
std::vector< std::string > disable_components
std::optional< T > read(const std::string &path)
Read path and deserialize into T.
const std::string & last_error() const
Last error message, empty if no error.
Converts arbitrary C++ types to/from JSON strings and disk files.