Commit 5ec1ff96 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: add dynamics_type to observer callback

parent 607ef3d2
......@@ -230,6 +230,7 @@ struct plot_output
{}
void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s);
......@@ -252,8 +253,9 @@ struct file_output
{}
void operator()(const irt::observer& obs,
const irt::time t,
const irt::observer::status s);
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s);
editor* ed = nullptr;
std::ofstream ofs;
......
......@@ -29,6 +29,7 @@ namespace irt {
void
plot_output::operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s)
{
......@@ -63,6 +64,7 @@ plot_output::operator()(const irt::observer& obs,
void
file_output::operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s)
{
......
......@@ -34,6 +34,7 @@ struct file_output
}
void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s) noexcept
{
......
......@@ -34,6 +34,7 @@ struct file_output
}
void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s)
{
......
......@@ -34,6 +34,7 @@ struct file_output
}
void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s)
{
......
......@@ -2477,7 +2477,8 @@ struct observer
};
using update_fn =
function_ref<void(const observer&, const time, const observer::status)>;
function_ref<void(const observer&, const dynamics_type,
const time, const observer::status)>;
observer(const char* name_, update_fn cb_) noexcept
: cb(cb_)
......@@ -6475,9 +6476,11 @@ public:
irt::observer* obs = nullptr;
while (observers.next(obs)) {
obs->tl = t;
if (!obs->cb.empty())
obs->cb(*obs, t, observer::status::initialize);
if (auto* mdl = models.try_to_get(obs->model); mdl) {
obs->msg.reset();
obs->cb(*obs, mdl->type, t, observer::status::initialize);
obs->tl = t;
}
}
return status::success;
......@@ -6585,7 +6588,7 @@ public:
if (mdl.obs_id != static_cast<observer_id>(0)) {
if (auto* obs = observers.try_to_get(mdl.obs_id); obs) {
obs->msg = dyn.observation(t - mdl.tl);
obs->cb(*obs, t, observer::status::run);
obs->cb(*obs, mdl.type, t, observer::status::run);
obs->tl = t;
} else {
mdl.obs_id = static_cast<observer_id>(0);
......@@ -6625,7 +6628,7 @@ public:
{
if constexpr (is_detected_v<observation_function_t, Dynamics>) {
obs.msg = dyn.observation(t - mdl.tl);
obs.cb(obs, t, observer::status::finalize);
obs.cb(obs, mdl.type, t, observer::status::finalize);
obs.tl = t;
}
}
......@@ -6645,8 +6648,7 @@ public:
model* mdl = nullptr;
while (models.next(mdl)) {
if (mdl->obs_id != static_cast<observer_id>(0)) {
if (auto* obs = observers.try_to_get(mdl->obs_id);
obs && !obs->cb.empty()) {
if (auto* obs = observers.try_to_get(mdl->obs_id); obs) {
dispatch(mdl->type,
[this, mdl, obs, t]<typename DynamicsModels>(
DynamicsModels& dyn_models) {
......
......@@ -24,6 +24,7 @@ struct file_output
{}
void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s)
{
......
......@@ -33,6 +33,7 @@ struct file_output
}
void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t,
const irt::observer::status s) noexcept
{
......@@ -46,6 +47,7 @@ struct file_output
break;
case irt::observer::status::finalize:
fmt::print(os, "{},{}\n", t, obs.msg.real[0]);
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment