Load engine configuration from a JSON file, applying any present fields to the pre-Init config structs.
190{
192 auto result = ser.
read<EngineConfig>(path);
193 if (!result) {
194 MF_ERROR(Journal::Component::API, Journal::Context::Configuration,
195 "Failed to load config from {}: {}", path, ser.
last_error());
196 return false;
197 }
198 get_global_stream_info() = result->stream;
199 get_global_graphics_config() = result->graphics;
200 get_global_input_config() = result->input;
201 get_global_network_config() = result->network;
202
203 const auto& j = result->journal;
204
205 if (!j.severity.empty()) {
206 auto sev = Reflect::string_to_enum_case_insensitive<Journal::Severity>(j.severity);
207 if (sev) {
208 Config::set_journal_severity(*sev);
209 } else {
210 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
211 "Unknown journal severity: {}", j.severity);
212 }
213 }
214 if (j.sink_to_console)
215 Config::sink_journal_to_console();
216 if (!j.log_file.empty())
217 Config::store_journal_entries(j.log_file);
219 auto comp = Reflect::string_to_enum_case_insensitive<Journal::Component>(
name);
220 if (comp) {
221 Config::set_journal_component_filter({ *comp }, false);
222 } else {
223 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
224 "Unknown journal component: {}",
name);
225 }
226 }
227
229 auto ctx = Reflect::string_to_enum_case_insensitive<Journal::Context>(
name);
230 if (ctx) {
231 Config::set_journal_context_filter({ *ctx }, false);
232 } else {
233 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
234 "Unknown journal context: {}",
name);
235 }
236 }
237
238 std::vector<Journal::Component> included_components;
240 auto comp = Reflect::string_to_enum_case_insensitive<Journal::Component>(
name);
241 if (comp) {
242 included_components.push_back(*comp);
243 } else {
244 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
245 "Unknown journal component: {}",
name);
246 }
247 }
248 Config::set_journal_component_includes(included_components);
249
250 std::vector<Journal::Context> included_contexts;
252 auto ctx = Reflect::string_to_enum_case_insensitive<Journal::Context>(
name);
253 if (ctx) {
254 included_contexts.push_back(*ctx);
255 } else {
256 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
257 "Unknown journal context: {}",
name);
258 }
259 }
260 Config::set_journal_context_includes(included_contexts);
261
262 return true;
263}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::vector< std::string > include_contexts
std::vector< std::string > disable_contexts
std::vector< std::string > disable_components
std::vector< std::string > include_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.