Load engine configuration from a JSON file, applying any present fields to the pre-Init config structs.
163{
165 auto result = ser.
read<EngineConfig>(path);
166 if (!result) {
167 MF_ERROR(Journal::Component::API, Journal::Context::Configuration,
168 "Failed to load config from {}: {}", path, ser.
last_error());
169 return false;
170 }
171 get_global_stream_info() = result->stream;
172 get_global_graphics_config() = result->graphics;
173 get_global_input_config() = result->input;
174 get_global_network_config() = result->network;
175
176 const auto& j = result->journal;
177
178 if (!j.severity.empty()) {
179 auto sev = Reflect::string_to_enum_case_insensitive<Journal::Severity>(j.severity);
180 if (sev) {
181 Config::set_journal_severity(*sev);
182 } else {
183 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
184 "Unknown journal severity: {}", j.severity);
185 }
186 }
187 if (j.sink_to_console)
188 Config::sink_journal_to_console();
189 if (!j.log_file.empty())
190 Config::store_journal_entries(j.log_file);
192 auto comp = Reflect::string_to_enum_case_insensitive<Journal::Component>(name);
193 if (comp) {
194 Config::set_journal_component_filter({ *comp }, false);
195 } else {
196 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
197 "Unknown journal component: {}", name);
198 }
199 }
200
202 auto ctx = Reflect::string_to_enum_case_insensitive<Journal::Context>(name);
203 if (ctx) {
204 Config::set_journal_context_filter({ *ctx }, false);
205 } else {
206 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
207 "Unknown journal context: {}", name);
208 }
209 }
210
211 return true;
212}
#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.