feat(editor): basics for run/edit mode
This commit is contained in:
parent
be3c7bd6b2
commit
c4ad7d5620
4 changed files with 92 additions and 15 deletions
|
@ -6,6 +6,7 @@
|
|||
Camera camera(glm::vec3(0.0, 0.0, 3.0));
|
||||
//std::vector<Part> parts;
|
||||
std::shared_ptr<DataModel> gDataModel = DataModel::New();
|
||||
std::shared_ptr<DataModel> editModeDataModel = gDataModel;
|
||||
std::optional<HierarchyPreUpdateHandler> hierarchyPreUpdateHandler;
|
||||
std::optional<HierarchyPostUpdateHandler> hierarchyPostUpdateHandler;
|
||||
std::shared_ptr<Handles> editorToolHandles = Handles::New();
|
||||
|
|
|
@ -111,7 +111,7 @@ std::optional<std::shared_ptr<Workspace>> Snap::jointWorkspace() {
|
|||
if (workspace()) return workspace();
|
||||
|
||||
if (GetParent() && GetParent().value()->GetClass() == &JointsService::TYPE)
|
||||
return std::dynamic_pointer_cast<DataModel>(GetParent().value()->GetParent().value())->GetService<Workspace>("Workspace");
|
||||
return std::dynamic_pointer_cast<DataModel>(GetParent().value()->GetParent().value())->GetService<Workspace>();
|
||||
|
||||
return {};
|
||||
}
|
|
@ -17,7 +17,13 @@
|
|||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
bool simulationPlaying = false;
|
||||
enum RunState {
|
||||
RUN_STOPPED,
|
||||
RUN_RUNNING,
|
||||
RUN_PAUSED
|
||||
};
|
||||
|
||||
RunState runState = RUN_STOPPED;
|
||||
|
||||
bool worldSpaceTransforms = false;
|
||||
|
||||
|
@ -171,7 +177,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
snap->c1 = part0->cframe;
|
||||
|
||||
// gWorkspace()->AddChild(snap);
|
||||
gDataModel->GetService<JointsService>("JointsService").expect()->AddChild(snap);
|
||||
gDataModel->GetService<JointsService>().expect()->AddChild(snap);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* evt) {
|
||||
|
@ -217,7 +223,7 @@ void MainWindow::timerEvent(QTimerEvent* evt) {
|
|||
float deltaTime = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastTime).count();
|
||||
lastTime = std::chrono::steady_clock::now();
|
||||
|
||||
if (simulationPlaying)
|
||||
if (runState == RUN_RUNNING)
|
||||
gWorkspace()->PhysicsStep(deltaTime);
|
||||
ui->mainWidget->update();
|
||||
ui->mainWidget->updateCycle();
|
||||
|
@ -254,19 +260,45 @@ void MainWindow::connectActionHandlers() {
|
|||
});
|
||||
ui->actionToggleEditSounds->setChecked(true);
|
||||
|
||||
connect(ui->actionToggleSimulation, &QAction::triggered, this, [&]() {
|
||||
simulationPlaying = !simulationPlaying;
|
||||
if (simulationPlaying) {
|
||||
ui->actionToggleSimulation->setText("Pause simulation");
|
||||
ui->actionToggleSimulation->setToolTip("Pause the simulation");
|
||||
ui->actionToggleSimulation->setIcon(QIcon::fromTheme("media-playback-pause"));
|
||||
} else {
|
||||
ui->actionToggleSimulation->setText("Resume simulation");
|
||||
ui->actionToggleSimulation->setToolTip("Resume the simulation");
|
||||
ui->actionToggleSimulation->setIcon(QIcon::fromTheme("media-playback-start"));
|
||||
connect(ui->actionRunSimulation, &QAction::triggered, this, [&]() {
|
||||
if (runState == RUN_RUNNING) return;
|
||||
|
||||
if (runState == RUN_PAUSED) {
|
||||
runState = RUN_RUNNING;
|
||||
ui->actionRunSimulation->setEnabled(false);
|
||||
ui->actionPauseSimulation->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
runState = RUN_RUNNING;
|
||||
ui->actionRunSimulation->setEnabled(false);
|
||||
ui->actionPauseSimulation->setEnabled(true);
|
||||
ui->actionStopSimulation->setEnabled(true);
|
||||
});
|
||||
|
||||
connect(ui->actionPauseSimulation, &QAction::triggered, this, [&]() {
|
||||
if (runState != RUN_RUNNING) return;
|
||||
|
||||
runState = RUN_PAUSED;
|
||||
ui->actionRunSimulation->setEnabled(true);
|
||||
ui->actionPauseSimulation->setEnabled(false);
|
||||
return;
|
||||
});
|
||||
|
||||
connect(ui->actionStopSimulation, &QAction::triggered, this, [&]() {
|
||||
if (runState == RUN_STOPPED) return;
|
||||
|
||||
runState = RUN_STOPPED;
|
||||
ui->actionRunSimulation->setEnabled(true);
|
||||
ui->actionPauseSimulation->setEnabled(false);
|
||||
ui->actionStopSimulation->setEnabled(false);
|
||||
return;
|
||||
});
|
||||
|
||||
ui->actionRunSimulation->setEnabled(true);
|
||||
ui->actionPauseSimulation->setEnabled(false);
|
||||
ui->actionStopSimulation->setEnabled(false);
|
||||
|
||||
connect(ui->actionToggleSpace, &QAction::triggered, this, [&]() {
|
||||
worldSpaceTransforms = !worldSpaceTransforms;
|
||||
updateToolbars();
|
||||
|
|
|
@ -188,7 +188,9 @@
|
|||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionToggleSimulation"/>
|
||||
<addaction name="actionRunSimulation"/>
|
||||
<addaction name="actionPauseSimulation"/>
|
||||
<addaction name="actionStopSimulation"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="surfaceTools">
|
||||
<property name="windowTitle">
|
||||
|
@ -675,6 +677,48 @@
|
|||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRunSimulation">
|
||||
<property name="icon">
|
||||
<iconset theme="media-playback-start"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Run</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Run simulation</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPauseSimulation">
|
||||
<property name="icon">
|
||||
<iconset theme="media-playback-pause"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Pause</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Pause simulation</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionStopSimulation">
|
||||
<property name="icon">
|
||||
<iconset theme="media-playback-stop"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Stop simulation</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
Loading…
Add table
Reference in a new issue