diff --git a/core/src/objects/part.cpp b/core/src/objects/part.cpp index 44caea9..d8921ce 100644 --- a/core/src/objects/part.cpp +++ b/core/src/objects/part.cpp @@ -259,6 +259,26 @@ SurfaceType Part::surfaceFromFace(NormalId face) { return SurfaceSmooth; // Unreachable } +bool Part::checkJointContinuinty(std::shared_ptr otherPart) { + // Make sure that the two parts don't depend on one another + + if (shared() == otherPart) return false; + + for (auto joint : primaryJoints) { + if (joint.expired() || joint.lock()->part1.expired()) continue; + if (!joint.lock()->part1.lock()->checkJointContinuinty(otherPart)) + return false; + } + + for (auto joint : secondaryJoints) { + if (joint.expired() || joint.lock()->part0.expired()) continue; + if (!joint.lock()->part0.lock()->checkJointContinuinty(otherPart)) + return false; + } + + return true; +} + void Part::MakeJoints() { // Algorithm: Find nearby parts // Make sure parts are not dependant on each other (via primary/secondaryJoints) @@ -290,6 +310,7 @@ void Part::MakeJoints() { float dot = myWorldNormal.Dot(otherWorldNormal); if (dot > -0.99) continue; // Surface is pointing opposite to ours if (abs(surfacePointLocalToMyFrame.Z()) > 0.05) continue; // Surfaces are within 0.05 studs of one another + if (!checkJointContinuinty(otherPart)) continue; SurfaceType mySurface = surfaceFromFace(faceFromNormal(myFace)); SurfaceType otherSurface = surfaceFromFace(faceFromNormal(otherFace)); @@ -307,7 +328,7 @@ void Part::MakeJoints() { dataModel().value()->GetService()->AddChild(joint); joint->UpdateProperty("Part0"); - printf("Made joint between %s and %s!\n", name.c_str(), otherPart->name.c_str()); + Logger::debugf("Made joint between %s and %s!\n", name.c_str(), otherPart->name.c_str()); } } } diff --git a/core/src/objects/part.h b/core/src/objects/part.h index 33092a4..8f5ecd0 100644 --- a/core/src/objects/part.h +++ b/core/src/objects/part.h @@ -37,6 +37,7 @@ protected: void untrackJoint(std::shared_ptr); SurfaceType surfaceFromFace(NormalId); + bool checkJointContinuinty(std::shared_ptr); friend Snap; diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 488ccb6..76d48a2 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -368,18 +368,18 @@ void MainWindow::connectActionHandlers() { connect(ui->actionSave, &QAction::triggered, this, [&]() { std::optional path; - if (!gDataModel->HasFile()) - path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save " + gDataModel->name)); - if (!gDataModel->HasFile() && (!path || path == "")) return; + if (!editModeDataModel->HasFile()) + path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save " + editModeDataModel->name)); + if (!editModeDataModel->HasFile() && (!path || path == "")) return; - gDataModel->SaveToFile(path); + editModeDataModel->SaveToFile(path); }); connect(ui->actionSaveAs, &QAction::triggered, this, [&]() { - std::optional path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save as " + gDataModel->name)); + std::optional path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save as " + editModeDataModel->name)); if (!path || path == "") return; - gDataModel->SaveToFile(path); + editModeDataModel->SaveToFile(path); }); connect(ui->actionOpen, &QAction::triggered, this, [&]() { @@ -391,6 +391,7 @@ void MainWindow::connectActionHandlers() { // simulationInit(); std::shared_ptr newModel = DataModel::LoadFromFile(path.value()); + editModeDataModel = newModel; gDataModel = newModel; newModel->Init(); ui->explorerView->updateRoot(newModel);