Commit 95e171e6 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: rename variables in generator/buffer

parent abccb34f
......@@ -1595,14 +1595,12 @@ static void
show_dynamics_values(const buffer& dyn)
{
ImGui::Text("next %.3f", dyn.sigma);
ImGui::Text("value %.3f", dyn.value);
}
static void
show_dynamics_values(const generator& dyn)
{
ImGui::Text("next %.3f", dyn.sigma);
ImGui::Text("value %.3f", dyn.value);
}
static void
......@@ -1917,22 +1915,21 @@ show_dynamics_inputs(buffer& dyn)
ImGui::OpenPopup(title);
ImGui::SameLine();
if (dyn.default_lambda_source.data == nullptr) {
if (dyn.default_ta_source.data == nullptr) {
ImGui::TextUnformatted("<None>");
} else {
ImGui::Text("%" PRIu32 "-%" PRIu32,
dyn.default_lambda_source.type,
dyn.default_lambda_source.id);
dyn.default_ta_source.type,
dyn.default_ta_source.id);
}
app.srcs.show_menu(title, dyn.default_lambda_source);
app.srcs.show_menu(title, dyn.default_ta_source);
}
}
static void
show_dynamics_inputs(generator& dyn)
{
ImGui::InputDouble("value", &dyn.default_value);
ImGui::InputDouble("offset", &dyn.default_offset);
{
......@@ -1958,15 +1955,15 @@ show_dynamics_inputs(generator& dyn)
ImGui::OpenPopup(title);
ImGui::SameLine();
if (dyn.default_lambda_source.data == nullptr) {
if (dyn.default_ta_source.data == nullptr) {
ImGui::TextUnformatted("<None>");
} else {
ImGui::Text("%" PRIu32 "-%" PRIu32,
dyn.default_lambda_source.type,
dyn.default_lambda_source.id);
dyn.default_ta_source.type,
dyn.default_ta_source.id);
}
app.srcs.show_menu(title, dyn.default_lambda_source);
app.srcs.show_menu(title, dyn.default_ta_source);
}
}
......
......@@ -4612,16 +4612,19 @@ struct external_source
external_source() noexcept = default;
bool next(double& value) noexcept
bool next() noexcept
{
irt_assert(data);
if (index >= size) {
if (expand.empty() || !expand(*this))
return false;
index = 0;
} else {
++index;
}
value = data[index++];
return true;
}
};
......@@ -4632,17 +4635,17 @@ struct buffer
input_port_id x[1];
output_port_id y[1];
time sigma;
message msg_list;
external_source default_lambda_source;
external_source default_ta_source;
double default_offset = 0.0;
double default_value = 0.0;
double value;
status initialize() noexcept
{
sigma = default_offset;
value = default_value;
if (!default_ta_source.data)
irt_bad_return(status::model_buffer_null_ta_source);
return status::success;
}
......@@ -4650,19 +4653,42 @@ struct buffer
status transition(data_array<input_port, input_port_id>& input_ports,
time /*t*/,
time /*e*/,
time r) noexcept;
time r) noexcept
{
bool have_message = false;
auto& port = input_ports.get(x[0]);
for (const auto& msg : port.messages) {
msg_list = msg;
have_message = true;
}
if (time_domain<time>::is_zero(r)) {
if (!default_ta_source.data)
irt_bad_return(status::model_buffer_null_ta_source);
if (!default_ta_source.next())
irt_bad_return(status::model_buffer_empty_ta_source);
sigma = *default_ta_source.data;
} else {
sigma = r;
}
return status::success;
}
status lambda(
data_array<output_port, output_port_id>& output_ports) noexcept
{
output_ports.get(y[0]).messages.emplace_front(value);
output_ports.get(y[0]).messages.emplace_front(msg_list);
return status::success;
}
message observation(const time /*e*/) const noexcept
{
return { value };
return msg_list;
}
};
......@@ -4672,17 +4698,20 @@ struct generator
output_port_id y[1];
time sigma;
external_source default_lambda_source;
external_source default_ta_source;
external_source default_value_source;
double default_offset = 1.0;
double default_value = 0.0;
double value;
status initialize() noexcept
{
sigma = default_offset;
value = default_value;
if (!default_ta_source.data)
irt_bad_return(status::model_generator_empty_ta_source);
if (!default_value_source.data)
irt_bad_return(status::model_generator_empty_value_source);
return status::success;
}
......@@ -4690,19 +4719,37 @@ struct generator
status transition(data_array<input_port, input_port_id>& /*input_ports*/,
time /*t*/,
time /*e*/,
time /*r*/) noexcept;
time /*r*/) noexcept
{
if (!default_ta_source.data)
irt_bad_return(status::model_generator_null_ta_source);
if (!default_ta_source.next())
irt_bad_return(status::model_generator_empty_ta_source);
if (!default_value_source.data)
irt_bad_return(status::model_generator_null_value_source);
if (!default_value_source.next())
irt_bad_return(status::model_generator_empty_value_source);
sigma = *default_ta_source.data;
return status::success;
}
status lambda(
data_array<output_port, output_port_id>& output_ports) noexcept
{
output_ports.get(y[0]).messages.emplace_front(value);
output_ports.get(y[0]).messages.emplace_front(
*default_value_source.data);
return status::success;
}
message observation(const time /*e*/) const noexcept
{
return { value };
return { *default_value_source.data };
}
};
......@@ -6621,7 +6668,7 @@ public:
if constexpr (is_detected_v<initialize_function_t, Dynamics>)
irt_return_if_bad(dyn.initialize());
//if constexpr (is_detected_v<has_sim_attribute_t, Dynamics>)
// if constexpr (is_detected_v<has_sim_attribute_t, Dynamics>)
// dyn.sim = this;
mdl.tl = t;
......@@ -6749,54 +6796,6 @@ public:
}
};
inline status
buffer::transition(data_array<input_port, input_port_id>& input_ports,
time /*t*/,
time /*e*/,
time r) noexcept
{
bool have_message = false;
auto& port = input_ports.get(x[0]);
for (const auto& msg : port.messages) {
value = msg[0];
have_message = true;
}
if (time_domain<time>::is_zero(r)) {
if (!default_lambda_source.data)
irt_bad_return(status::model_buffer_null_ta_source);
if (!default_lambda_source.next(sigma))
irt_bad_return(status::model_buffer_empty_ta_source);
} else {
sigma = r;
}
return status::success;
}
inline status
generator::transition(data_array<input_port, input_port_id>& /*input_ports*/,
time /*t*/,
time /*e*/,
time /*r*/) noexcept
{
if (!default_lambda_source.data)
irt_bad_return(status::model_generator_null_ta_source);
if (!default_lambda_source.next(sigma))
irt_bad_return(status::model_generator_empty_ta_source);
if (!default_value_source.data)
irt_bad_return(status::model_generator_null_value_source);
if (!default_value_source.next(value))
irt_bad_return(status::model_generator_empty_value_source);
return status::success;
}
} // namespace irt
#endif
......@@ -976,7 +976,7 @@ private:
bool read(generator& dyn) noexcept
{
return !!(is >> dyn.default_value >> dyn.default_offset);
return !!(is >> dyn.default_offset);
}
bool read(constant& dyn) noexcept
......@@ -1351,7 +1351,7 @@ private:
void write(const generator& dyn) noexcept
{
os << "generator " << dyn.default_value << ' ' << dyn.default_offset
os << "generator " << ' ' << dyn.default_offset
<< '\n';
}
......
......@@ -961,10 +961,10 @@ main()
}
{
gen.default_lambda_source.data = &data[1];
gen.default_lambda_source.index = 0;
gen.default_lambda_source.size = 1;
gen.default_lambda_source.expand = [](auto& src) {
gen.default_ta_source.data = &data[1];
gen.default_ta_source.index = 0;
gen.default_ta_source.size = 1;
gen.default_ta_source.expand = [](auto& src) {
src.index = 0;
return true;
};
......
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