feat: datamodel
This commit is contained in:
parent
5e6c18259f
commit
dc6e9180ff
11 changed files with 78 additions and 7 deletions
|
@ -41,6 +41,8 @@ int main() {
|
|||
glfwMakeContextCurrent(window);
|
||||
glewInit();
|
||||
|
||||
dataModel->Init();
|
||||
workspace = dataModel->workspace;
|
||||
simulationInit();
|
||||
renderInit(window, 1200, 900);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "objects/part.h"
|
||||
#include "qitemselectionmodel.h"
|
||||
#include "qobject.h"
|
||||
#include "qsysinfo.h"
|
||||
|
||||
SelectedTool selectedTool;
|
||||
|
||||
|
@ -25,6 +26,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
dataModel->Init();
|
||||
workspace = dataModel->workspace;
|
||||
|
||||
ui->setupUi(this);
|
||||
timer.start(33, this);
|
||||
setMouseTracking(true);
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
Camera camera(glm::vec3(0.0, 0.0, 3.0));
|
||||
//std::vector<Part> parts;
|
||||
std::shared_ptr<Workspace> workspace = Workspace::New();
|
||||
std::shared_ptr<DataModel> dataModel = DataModel::New();
|
||||
std::shared_ptr<Workspace> workspace = dataModel->workspace;
|
||||
// std::shared_ptr<Workspace> workspace = Workspace::New();
|
||||
std::optional<HierarchyPreUpdateHandler> hierarchyPreUpdateHandler;
|
||||
std::optional<HierarchyPostUpdateHandler> hierarchyPostUpdateHandler;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ typedef std::function<void(std::vector<InstanceRefWeak> oldSelection, std::vecto
|
|||
// TEMPORARY COMMON DATA FOR VARIOUS INTERNAL COMPONENTS
|
||||
|
||||
extern Camera camera;
|
||||
extern std::shared_ptr<DataModel> dataModel;
|
||||
extern std::shared_ptr<Workspace> workspace;
|
||||
extern std::optional<HierarchyPreUpdateHandler> hierarchyPreUpdateHandler;
|
||||
extern std::optional<HierarchyPostUpdateHandler> hierarchyPostUpdateHandler;
|
||||
|
|
|
@ -45,6 +45,8 @@ protected:
|
|||
virtual ~Instance();
|
||||
|
||||
virtual void OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent);
|
||||
|
||||
template <typename T> inline std::shared_ptr<T> shared() { return std::dynamic_pointer_cast<T>(this->shared_from_this()); }
|
||||
public:
|
||||
const static InstanceType TYPE;
|
||||
std::string name;
|
||||
|
|
4
src/objects/base/service.cpp
Normal file
4
src/objects/base/service.cpp
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include "service.h"
|
||||
#include <memory>
|
||||
|
||||
Service::Service(std::weak_ptr<DataModel> root) : dataModel(root) {}
|
12
src/objects/base/service.h
Normal file
12
src/objects/base/service.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
// Services are top-level singletons and belong to a specific DataModel
|
||||
// They serve one specific task and can be accessed using game:GetService
|
||||
#include "objects/datamodel.h"
|
||||
#include <memory>
|
||||
class Service {
|
||||
protected:
|
||||
std::weak_ptr<DataModel> dataModel;
|
||||
|
||||
Service(std::weak_ptr<DataModel> root);
|
||||
};
|
21
src/objects/datamodel.cpp
Normal file
21
src/objects/datamodel.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "datamodel.h"
|
||||
#include "workspace.h"
|
||||
#include <memory>
|
||||
|
||||
const InstanceType DataModel::TYPE = {
|
||||
.super = &Instance::TYPE,
|
||||
.className = "DataModel",
|
||||
.constructor = nullptr,
|
||||
};
|
||||
|
||||
const InstanceType* DataModel::GetClass() {
|
||||
return &TYPE;
|
||||
}
|
||||
|
||||
DataModel::DataModel()
|
||||
: Instance(&TYPE) {
|
||||
}
|
||||
|
||||
void DataModel::Init() {
|
||||
this->workspace = std::make_shared<Workspace>(shared<DataModel>());
|
||||
}
|
21
src/objects/datamodel.h
Normal file
21
src/objects/datamodel.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
#include <memory>
|
||||
|
||||
class Workspace;
|
||||
|
||||
// The root instance to all objects in the hierarchy
|
||||
class DataModel : public Instance {
|
||||
//private:
|
||||
public:
|
||||
const static InstanceType TYPE;
|
||||
|
||||
std::shared_ptr<Workspace> workspace;
|
||||
|
||||
DataModel();
|
||||
void Init();
|
||||
|
||||
static inline std::shared_ptr<DataModel> New() { return std::make_shared<DataModel>(); };
|
||||
virtual const InstanceType* GetClass() override;
|
||||
};
|
|
@ -3,12 +3,13 @@
|
|||
const InstanceType Workspace::TYPE = {
|
||||
.super = &Instance::TYPE,
|
||||
.className = "Workspace",
|
||||
.constructor = &Workspace::Create,
|
||||
// .constructor = &Workspace::Create,
|
||||
.explorerIcon = "workspace",
|
||||
};
|
||||
|
||||
const InstanceType* Workspace::GetClass() {
|
||||
return &TYPE;
|
||||
}
|
||||
|
||||
Workspace::Workspace(): Instance(&TYPE) {
|
||||
Workspace::Workspace(std::weak_ptr<DataModel> dataModel): Instance(&TYPE), Service(dataModel) {
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
#include "objects/base/service.h"
|
||||
#include <memory>
|
||||
|
||||
class Workspace : public Instance {
|
||||
class Workspace : public Instance, Service {
|
||||
//private:
|
||||
public:
|
||||
const static InstanceType TYPE;
|
||||
|
||||
Workspace();
|
||||
Workspace(std::weak_ptr<DataModel> dataModel);
|
||||
|
||||
static inline std::shared_ptr<Workspace> New() { return std::make_shared<Workspace>(); };
|
||||
static inline InstanceRef Create() { return std::make_shared<Workspace>(); };
|
||||
// static inline std::shared_ptr<Workspace> New() { return std::make_shared<Workspace>(); };
|
||||
// static inline InstanceRef Create() { return std::make_shared<Workspace>(); };
|
||||
virtual const InstanceType* GetClass() override;
|
||||
};
|
Loading…
Add table
Reference in a new issue