Refactor StepControl and GUI to return change status.
StepControl methods SetSpeed, SetNoiseParameters, and SetPauseState now return a boolean indicating whether the state was actually changed. The GUI functions NoiseGui and StepControlGui also return a boolean reflecting if any parameters were modified. Noise parameters are now directly managed by StepControl rather than being stored in UxState. The StepControlEvent message has been expanded to include all step control parameters. Keyboard event handling has been slightly refactored to better align with event-based updates. PiperOrigin-RevId: 940656342 Change-Id: I3701623a2fdcfc4c084b5db0ae19048669040de4
This commit is contained in:
committed by
Copybara-Service
parent
f4b2f76def
commit
58d6910afa
@@ -66,8 +66,11 @@ float StepControl::GetSpeedMeasured() const { return speed_measured_; }
|
||||
float StepControl::GetSpeed() const { return speed_; }
|
||||
|
||||
void StepControl::SetSpeed(float speed_percent_real_time) {
|
||||
float prev_speed = speed_;
|
||||
speed_ = std::clamp(speed_percent_real_time, .1f, 100.f);
|
||||
ForceSync();
|
||||
if (speed_ != prev_speed) {
|
||||
ForceSync();
|
||||
}
|
||||
}
|
||||
|
||||
void StepControl::ForceSync() { force_sync_ = true; }
|
||||
|
||||
@@ -482,8 +482,7 @@ ImVec4 ConfigureDockingLayout(bool show_toolbar, bool show_status_bar) {
|
||||
return ImVec4(workspace_x, workspace_y, workspace_w, workspace_h);
|
||||
}
|
||||
|
||||
void StepControlGui(const mjModel* model, StepControl* step_control,
|
||||
int& speed_index) {
|
||||
void StepControlGui(StepControl* step_control, int& speed_index) {
|
||||
platform::ScopedStyle style;
|
||||
|
||||
bool is_dark = ImGui::GetStyle().Colors[ImGuiCol_WindowBg].x < 0.5f;
|
||||
@@ -1215,13 +1214,15 @@ void GroupsGui(const mjModel* model, mjvOption* vis_options, float min_width) {
|
||||
GroupGui("Skins", vis_options->skingroup);
|
||||
}
|
||||
|
||||
void NoiseGui(const mjModel* model, const mjData* data, float& noise_scale,
|
||||
float& noise_rate) {
|
||||
void NoiseGui(StepControl* step_control) {
|
||||
float noise_scale, noise_rate;
|
||||
step_control->GetNoiseParameters(noise_scale, noise_rate);
|
||||
const float item_width = ImGui::GetWindowWidth() * .6f;
|
||||
ImGui::PushItemWidth(item_width);
|
||||
ImGui::SliderFloat("Noise scale", &noise_scale, 0, 1);
|
||||
ImGui::SliderFloat("Noise rate", &noise_rate, 0, 4);
|
||||
ImGui::PopItemWidth();
|
||||
step_control->SetNoiseParameters(noise_scale, noise_rate);
|
||||
}
|
||||
|
||||
void JointsGui(const mjModel* model, const mjData* data,
|
||||
|
||||
@@ -83,8 +83,7 @@ static constexpr std::array<const char*, 31> kPercentRealTime = {
|
||||
// UX for controlling the simulation stepping. `speed_index` is an index into
|
||||
// kPercentRealTime, an array of available speeds (indices in range [0, 30] map
|
||||
// to real-time percentages in range [100%, 0.1%]).
|
||||
void StepControlGui(const mjModel* model, StepControl* step_control,
|
||||
int& speed_index);
|
||||
void StepControlGui(StepControl* step_control, int& speed_index);
|
||||
|
||||
// Sets the simulation speed index and updates the StepControl object.
|
||||
void SetSpeedIndex(StepControl* step_control, int& speed_index,
|
||||
@@ -148,8 +147,7 @@ void WatchGui(const mjModel* model, const mjData* data, char* field_name,
|
||||
|
||||
// UX for controlling noise parameters which can then be applied to the
|
||||
// simulation via StepControl::SetNoiseParameters / StepControl::InjectNoise.
|
||||
void NoiseGui(const mjModel* model, const mjData* data, float& noise_scale,
|
||||
float& noise_rate);
|
||||
void NoiseGui(StepControl* step_control);
|
||||
|
||||
// UX for the solver convergence chart.
|
||||
void ConvergenceGui(const mjModel* model, mjData* data,
|
||||
|
||||
@@ -1509,11 +1509,7 @@ void App::DataInspectorGui() {
|
||||
|
||||
ImGui::BeginChild("ControlsGui", {0, 0}, child_flags);
|
||||
if (platform::SectionHeader("Controls", node_flags, 0.65f)) {
|
||||
float noise_scale = 0;
|
||||
float noise_rate = 0;
|
||||
step_control_.GetNoiseParameters(noise_scale, noise_rate);
|
||||
platform::NoiseGui(model(), data(), noise_scale, noise_rate);
|
||||
step_control_.SetNoiseParameters(noise_scale, noise_rate);
|
||||
platform::NoiseGui(&step_control_);
|
||||
ImGui::Separator();
|
||||
|
||||
platform::ControlsGui(model(), data(), &vis_options_);
|
||||
@@ -1889,7 +1885,7 @@ void App::ToolBarGui() {
|
||||
|
||||
// Combined (Normal Pause, Viscous Pause, Play) widget and Speed selection.
|
||||
ImGui::SameLine(0, separator_width);
|
||||
platform::StepControlGui(model(), &step_control_, tmp_.speed_index);
|
||||
platform::StepControlGui(&step_control_, tmp_.speed_index);
|
||||
|
||||
ImGui::SameLine(0, separator_width);
|
||||
ImGui::SetNextItemWidth(120);
|
||||
|
||||
Reference in New Issue
Block a user