Unravel Engine C++ Reference
Loading...
Searching...
No Matches
loading_screen.cpp
Go to the documentation of this file.
1#include "loading_screen.h"
2
3#include <logging/logging.h>
4
5namespace unravel
6{
7
9{
10 visualizer_ = std::move(fn);
11}
12
14{
15 on_fail_ = std::move(fn);
16}
17
18void loading_screen::begin_module(const std::string& module_name)
19{
20 module_ = fmt::format("Loading [{}]", module_name);
21 completed_ = 0;
22 total_ = 0;
23 current_job_ = {};
24
25 APPLOG_TRACE("{}", module_);
26 notify_visualizer();
27}
28
29void loading_screen::progress(size_t comp, size_t tot, const std::string& job)
30{
31 completed_ = comp;
32 total_ = tot;
33 current_job_ = job;
34 notify_visualizer();
35}
36
37void loading_screen::log(const std::string& message)
38{
39 APPLOG_TRACE("{} {}", module_, message);
40 current_job_ = message;
41 notify_visualizer();
42}
43
44void loading_screen::fail(const std::string& message)
45{
46 failed_ = true;
47 error_msg_ = message;
48
49 APPLOG_CRITICAL("{} {}", module_, message);
50
51 if(on_fail_)
52 {
53 on_fail_(module_, message);
54 }
55}
56
57auto loading_screen::check(bool result) -> bool
58{
59 if(!result && !failed_)
60 {
61 fail(module_ + " Failed");
62 }
63 return result;
64}
65
66auto loading_screen::has_failed() const -> bool
67{
68 return failed_;
69}
70
71auto loading_screen::error_message() const -> const std::string&
72{
73 return error_msg_;
74}
75
76auto loading_screen::current_module() const -> const std::string&
77{
78 return module_;
79}
80
81auto loading_screen::completed() const -> size_t
82{
83 return completed_;
84}
85
86auto loading_screen::total() const -> size_t
87{
88 return total_;
89}
90
91auto loading_screen::current_job() const -> const std::string&
92{
93 return current_job_;
94}
95
96void loading_screen::notify_visualizer()
97{
98 if(visualizer_)
99 {
100 visualizer_(*this);
101 }
102}
103
104} // namespace unravel
#define APPLOG_CRITICAL(...)
Definition logging.h:21
#define APPLOG_TRACE(...)
Definition logging.h:17
Hash specialization for batch_key to enable use in std::unordered_map.
auto current_module() const -> const std::string &
void progress(size_t completed, size_t total, const std::string &current_job={})
std::function< void(const loading_screen &)> visualizer_fn
auto completed() const -> size_t
void begin_module(const std::string &module_name)
void set_visualizer(visualizer_fn fn)
void log(const std::string &message)
auto current_job() const -> const std::string &
auto error_message() const -> const std::string &
auto has_failed() const -> bool
std::function< void(const std::string &module, const std::string &message)> on_fail_fn
void set_on_fail(on_fail_fn fn)
auto check(bool result) -> bool
Convenience: if result is false and no error was set, auto-fails with the current module name.
auto total() const -> size_t
void fail(const std::string &message)