Compare commits
No commits in common. "10999be3b60cfebf0ade89a5d473c6931e56a038" and "b10abd38001ce98663eb5dd545cc2a47b1db9097" have entirely different histories.
10999be3b6
...
b10abd3800
7 changed files with 10 additions and 85 deletions
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "lldb",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Debug",
|
|
||||||
"program": "${workspaceFolder}/bin/editor",
|
|
||||||
"args": [],
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -5,14 +5,11 @@
|
||||||
#include "qimage.h"
|
#include "qimage.h"
|
||||||
#include "qnamespace.h"
|
#include "qnamespace.h"
|
||||||
#include "qobject.h"
|
#include "qobject.h"
|
||||||
#include "qstringview.h"
|
|
||||||
#include "qwidget.h"
|
#include "qwidget.h"
|
||||||
#include "qmimedata.h"
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
|
||||||
#include "objects/base/instance.h"
|
#include "objects/base/instance.h"
|
||||||
|
|
||||||
// https://doc.qt.io/qt-6/qtwidgets-itemviews-simpletreemodel-example.html#testing-the-model
|
// https://doc.qt.io/qt-6/qtwidgets-itemviews-simpletreemodel-example.html#testing-the-model
|
||||||
|
@ -26,7 +23,7 @@ ExplorerModel::ExplorerModel(InstanceRef dataRoot, QWidget *parent)
|
||||||
hierarchyPreUpdateHandler = [&](InstanceRef object, std::optional<InstanceRef> oldParent, std::optional<InstanceRef> newParent) {
|
hierarchyPreUpdateHandler = [&](InstanceRef object, std::optional<InstanceRef> oldParent, std::optional<InstanceRef> newParent) {
|
||||||
if (oldParent.has_value()) {
|
if (oldParent.has_value()) {
|
||||||
auto children = oldParent.value()->GetChildren();
|
auto children = oldParent.value()->GetChildren();
|
||||||
size_t idx = std::find(children.begin(), children.end(), object) - children.begin();
|
size_t idx = std::find(children.begin(), children.end(), object) - children.end();
|
||||||
beginRemoveRows(toIndex(oldParent.value()), idx, idx);
|
beginRemoveRows(toIndex(oldParent.value()), idx, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,50 +197,7 @@ Qt::DropActions ExplorerModel::supportedDropActions() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InstanceRef ExplorerModel::fromIndex(const QModelIndex index) const {
|
InstanceRef ExplorerModel::fromIndex(const QModelIndex index) {
|
||||||
if (!index.isValid()) return workspace;
|
if (!index.isValid()) return workspace;
|
||||||
return static_cast<Instance*>(index.internalPointer())->shared_from_this();
|
return static_cast<Instance*>(index.internalPointer())->shared_from_this();
|
||||||
}
|
|
||||||
|
|
||||||
struct DragDropSlot {
|
|
||||||
std::vector<InstanceRef> instances;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool ExplorerModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) {
|
|
||||||
// if (action != Qt::InternalMove) return;
|
|
||||||
QByteArray byteData = data->data("application/x-openblocks-instance-pointers");
|
|
||||||
uintptr_t slotPtr = byteData.toULongLong();
|
|
||||||
DragDropSlot* slot = (DragDropSlot*)slotPtr;
|
|
||||||
|
|
||||||
if (!parent.isValid()) {
|
|
||||||
delete slot;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceRef parentInst = fromIndex(parent);
|
|
||||||
for (InstanceRef instance : slot->instances) {
|
|
||||||
instance->SetParent(parentInst);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete slot;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMimeData* ExplorerModel::mimeData(const QModelIndexList& indexes) const {
|
|
||||||
// application/x-openblocks-instance-pointers
|
|
||||||
DragDropSlot* slot = new DragDropSlot();
|
|
||||||
|
|
||||||
for (const QModelIndex& index : indexes) {
|
|
||||||
slot->instances.push_back(fromIndex(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
// uintptr_t ptr = (uintptr_t)&slot;
|
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData();
|
|
||||||
mimeData->setData("application/x-openblocks-instance-pointers", QByteArray::number((qulonglong)slot));
|
|
||||||
return mimeData;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList ExplorerModel::mimeTypes() const {
|
|
||||||
return QStringList("application/x-openblocks-instance-pointers");
|
|
||||||
}
|
}
|
|
@ -35,12 +35,9 @@ public:
|
||||||
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
|
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
|
||||||
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()) override;
|
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()) override;
|
||||||
bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex()) override;
|
bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex()) override;
|
||||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
|
||||||
QMimeData* mimeData(const QModelIndexList& indexes) const override;
|
|
||||||
QStringList mimeTypes() const override;
|
|
||||||
Qt::DropActions supportedDragActions() const override;
|
Qt::DropActions supportedDragActions() const override;
|
||||||
Qt::DropActions supportedDropActions() const override;
|
Qt::DropActions supportedDropActions() const override;
|
||||||
InstanceRef fromIndex(const QModelIndex index) const;
|
InstanceRef fromIndex(const QModelIndex index);
|
||||||
private:
|
private:
|
||||||
InstanceRef rootItem;
|
InstanceRef rootItem;
|
||||||
QModelIndex toIndex(InstanceRef item);
|
QModelIndex toIndex(InstanceRef item);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "explorerview.h"
|
#include "explorerview.h"
|
||||||
#include "explorermodel.h"
|
#include "explorermodel.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "qabstractitemmodel.h"
|
|
||||||
#include "qaction.h"
|
#include "qaction.h"
|
||||||
#include "qnamespace.h"
|
#include "qnamespace.h"
|
||||||
|
|
||||||
|
@ -10,11 +9,7 @@ ExplorerView::ExplorerView(QWidget* parent):
|
||||||
model(ExplorerModel(std::dynamic_pointer_cast<Instance>(workspace))) {
|
model(ExplorerModel(std::dynamic_pointer_cast<Instance>(workspace))) {
|
||||||
|
|
||||||
this->setModel(&model);
|
this->setModel(&model);
|
||||||
// Disabling the root decoration will cause the expand/collapse chevrons to be hidden too, we don't want that
|
this->setRootIsDecorated(false);
|
||||||
// https://stackoverflow.com/a/4687016/16255372
|
|
||||||
// this->setRootIsDecorated(false);
|
|
||||||
// The branches can be customized like this if you want:
|
|
||||||
// this->setStyleSheet(QString("QTreeView::branch { border: none; }"));
|
|
||||||
this->setDragDropMode(QAbstractItemView::InternalMove);
|
this->setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
this->setDragEnabled(true);
|
this->setDragEnabled(true);
|
||||||
|
|
|
@ -17,9 +17,7 @@ class ExplorerView : public QTreeView {
|
||||||
public:
|
public:
|
||||||
ExplorerView(QWidget* parent = nullptr);
|
ExplorerView(QWidget* parent = nullptr);
|
||||||
~ExplorerView() override;
|
~ExplorerView() override;
|
||||||
|
void keyPressEvent(QKeyEvent* evt) override;
|
||||||
void keyPressEvent(QKeyEvent*) override;
|
|
||||||
// void dropEvent(QDropEvent*) override;
|
|
||||||
private:
|
private:
|
||||||
ExplorerModel model;
|
ExplorerModel model;
|
||||||
QMenu contextMenu;
|
QMenu contextMenu;
|
||||||
|
|
|
@ -24,9 +24,8 @@ Part::Part(PartConstructParams params): Instance(&TYPE_), position(params.positi
|
||||||
// This feels wrong. Get access to PhysicsWorld somehow else? Part will need access to this often though, most likely...
|
// This feels wrong. Get access to PhysicsWorld somehow else? Part will need access to this often though, most likely...
|
||||||
extern rp::PhysicsWorld* world;
|
extern rp::PhysicsWorld* world;
|
||||||
Part::~Part() {
|
Part::~Part() {
|
||||||
// This relies on physicsCommon still existing. Be very careful.
|
world->destroyRigidBody(rigidBody);
|
||||||
if (this->rigidBody)
|
Instance::~Instance();
|
||||||
world->destroyRigidBody(rigidBody);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include <reactphysics3d/collision/shapes/CollisionShape.h>
|
#include <reactphysics3d/collision/shapes/CollisionShape.h>
|
||||||
#include <reactphysics3d/components/RigidBodyComponents.h>
|
#include <reactphysics3d/components/RigidBodyComponents.h>
|
||||||
#include <reactphysics3d/engine/EventListener.h>
|
#include <reactphysics3d/engine/EventListener.h>
|
||||||
#include <reactphysics3d/engine/PhysicsCommon.h>
|
|
||||||
#include <reactphysics3d/mathematics/Quaternion.h>
|
#include <reactphysics3d/mathematics/Quaternion.h>
|
||||||
#include <reactphysics3d/mathematics/Transform.h>
|
#include <reactphysics3d/mathematics/Transform.h>
|
||||||
#include <reactphysics3d/mathematics/Vector3.h>
|
#include <reactphysics3d/mathematics/Vector3.h>
|
||||||
|
@ -27,13 +26,12 @@ class PhysicsListener : public rp::EventListener {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
rp::PhysicsCommon* physicsCommon;
|
rp::PhysicsCommon physicsCommon;
|
||||||
rp::PhysicsWorld* world;
|
rp::PhysicsWorld* world;
|
||||||
PhysicsListener eventListener;
|
PhysicsListener eventListener;
|
||||||
|
|
||||||
void simulationInit() {
|
void simulationInit() {
|
||||||
physicsCommon = new rp::PhysicsCommon; // I allocate this on the heap to ensure it exists while Parts are getting destructed. This is probably not great
|
world = physicsCommon.createPhysicsWorld();
|
||||||
world = physicsCommon->createPhysicsWorld();
|
|
||||||
|
|
||||||
world->setGravity(rp::Vector3(0, -196.2, 0));
|
world->setGravity(rp::Vector3(0, -196.2, 0));
|
||||||
}
|
}
|
||||||
|
@ -48,7 +46,7 @@ void syncPartPhysics(std::shared_ptr<Part> part) {
|
||||||
part->rigidBody->setTransform(transform);
|
part->rigidBody->setTransform(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
rp::BoxShape* shape = physicsCommon->createBoxShape(glmToRp(part->scale * glm::vec3(0.5f)));
|
rp::BoxShape* shape = physicsCommon.createBoxShape(glmToRp(part->scale * glm::vec3(0.5f)));
|
||||||
|
|
||||||
if (part->rigidBody->getNbColliders() > 0) {
|
if (part->rigidBody->getNbColliders() > 0) {
|
||||||
part->rigidBody->removeCollider(part->rigidBody->getCollider(0));
|
part->rigidBody->removeCollider(part->rigidBody->getCollider(0));
|
||||||
|
|
Loading…
Add table
Reference in a new issue