Compare commits
No commits in common. "4b441adff3856a7887d2698272083334c83e2a77" and "3f51b9a28b8afe3959215ac2b95ed0e1cfd8013b" have entirely different histories.
4b441adff3
...
3f51b9a28b
9 changed files with 5 additions and 177 deletions
|
@ -1,20 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
enum ValueType {
|
|
||||||
OB_NIL = 0,
|
|
||||||
OB_BOOLEAN,
|
|
||||||
OB_INTEGER,
|
|
||||||
OB_FLOAT,
|
|
||||||
OB_STRING,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Value {
|
|
||||||
ValueType type;
|
|
||||||
union {
|
|
||||||
bool b;
|
|
||||||
int i;
|
|
||||||
float f;
|
|
||||||
std::string str;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,53 +0,0 @@
|
||||||
#include "instance.h"
|
|
||||||
#include "instancetype.h"
|
|
||||||
#include <algorithm>
|
|
||||||
#include <memory>
|
|
||||||
#include <optional>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
InstanceType TYPE_INSTANCE {
|
|
||||||
.superClass = nullptr,
|
|
||||||
.className = "Instance",
|
|
||||||
.flags = OB_INST_NOT_CREATABLE,
|
|
||||||
};
|
|
||||||
|
|
||||||
std::optional<std::shared_ptr<Instance>> Instance::GetParent() {
|
|
||||||
if (!this->Parent.has_value() || this->Parent.value().expired())
|
|
||||||
return std::nullopt;
|
|
||||||
return this->Parent.value().lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instance::SetParent(std::optional<std::shared_ptr<Instance>> newParent) {
|
|
||||||
// Remove this instance from the existing parent
|
|
||||||
if (this->Parent.has_value() && !this->Parent.value().expired()) {
|
|
||||||
std::shared_ptr<Instance> parent = this->Parent.value().lock();
|
|
||||||
parent->children.erase(std::remove_if(parent->children.begin(), parent->children.end(), [this](std::shared_ptr<Instance> ptr) {
|
|
||||||
return ptr.get() == this;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add self to
|
|
||||||
if (newParent.has_value()) {
|
|
||||||
newParent.value()->children.push_back(this->shared_from_this());
|
|
||||||
}
|
|
||||||
|
|
||||||
this->Parent = newParent;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Instance>> Instance::GetChildren() {
|
|
||||||
return this->children;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Instance> Instance::CloneInternal() {
|
|
||||||
// TODO: Implement refs
|
|
||||||
|
|
||||||
std::unique_ptr<Instance> clone = this->__copy();
|
|
||||||
clone->children = std::vector<std::shared_ptr<Instance>>();
|
|
||||||
clone->children.reserve(this->children.size());
|
|
||||||
|
|
||||||
for (std::shared_ptr<Instance> child : this->children) {
|
|
||||||
clone->children.push_back(child->CloneInternal());
|
|
||||||
}
|
|
||||||
|
|
||||||
return clone;
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "instancetype.h"
|
|
||||||
|
|
||||||
#define INSTANCE_COPY_IMPL(CLASS_NAME) std::unique_ptr<Instance> CLASS_NAME::__copy() { return std::make_unique<CLASS_NAME>(CLASS_NAME(*this)); }
|
|
||||||
#define INSTANCE_PRELUDE(CLASS_NAME) protected: virtual std::unique_ptr<Instance> __copy() override; virtual InstanceType& GetType() const override;
|
|
||||||
// #define INSTANCE_TYPE(CLASS_NAME, TYPE_DEFINITION) InstanceType& CLASS_NAME::GetType() const { \
|
|
||||||
// static InstanceType type = TYPE_DEFINITION; \
|
|
||||||
// return type; \
|
|
||||||
// };
|
|
||||||
#define INSTANCE_TYPE(CLASS_NAME, TYPE_CONSTANT) InstanceType& CLASS_NAME::GetType() const { return TYPE_CONSTANT; };
|
|
||||||
|
|
||||||
extern InstanceType TYPE_INSTANCE;
|
|
||||||
|
|
||||||
// The base class for all objects in the data model
|
|
||||||
class Instance : std::enable_shared_from_this<Instance> {
|
|
||||||
private:
|
|
||||||
std::optional<std::weak_ptr<Instance>> Parent;
|
|
||||||
std::vector<std::shared_ptr<Instance>> children;
|
|
||||||
protected:
|
|
||||||
virtual std::unique_ptr<Instance> __copy();
|
|
||||||
public:
|
|
||||||
std::string Name;
|
|
||||||
std::optional<std::shared_ptr<Instance>> GetParent();
|
|
||||||
void SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
|
||||||
std::vector<std::shared_ptr<Instance>> GetChildren();
|
|
||||||
|
|
||||||
virtual void Init();
|
|
||||||
std::unique_ptr<Instance> CloneInternal();
|
|
||||||
virtual InstanceType& GetType() const = 0;
|
|
||||||
|
|
||||||
virtual Value GetProperty(std::string key);
|
|
||||||
virtual void SetProperty(std::string key, Value newValue);
|
|
||||||
virtual Value CallMethod(std::string key, std::vector<Value> arguments);
|
|
||||||
};
|
|
|
@ -1,39 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "../core/value.h"
|
|
||||||
|
|
||||||
enum PropertyFlags {
|
|
||||||
OB_PROP_READ_ONLY = 1, // The property cannot be set
|
|
||||||
// OB_PROP_CALLBACK = 2, // The proeprty is get/set through a function instead of directly to a field
|
|
||||||
};
|
|
||||||
|
|
||||||
enum MethodFlags {
|
|
||||||
// OB_METHOD_OVERLOADED = 1, // The method has multiple definitions with different parameters suffixed by __ followed by a number
|
|
||||||
};
|
|
||||||
|
|
||||||
enum InstanceFlags {
|
|
||||||
OB_INST_NOT_CREATABLE = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PropertyInfo {
|
|
||||||
PropertyFlags flags;
|
|
||||||
void* fieldPointer;
|
|
||||||
ValueType valueType;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MethodInfo {
|
|
||||||
MethodFlags flags;
|
|
||||||
void* functionPointer;
|
|
||||||
ValueType returnType;
|
|
||||||
std::vector<ValueType> parameterTypes;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct InstanceType {
|
|
||||||
InstanceType* superClass = nullptr;
|
|
||||||
std::string className;
|
|
||||||
InstanceFlags flags;
|
|
||||||
std::map<std::string, PropertyInfo> properties;
|
|
||||||
std::map<std::string, MethodInfo> methods;
|
|
||||||
};
|
|
|
@ -1,15 +0,0 @@
|
||||||
#include "part.h"
|
|
||||||
#include "instance.h"
|
|
||||||
#include "instancetype.h"
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
INSTANCE_COPY_IMPL(Part)
|
|
||||||
|
|
||||||
InstanceType TYPE_PART {
|
|
||||||
.superClass = &TYPE_INSTANCE,
|
|
||||||
.className = "Part",
|
|
||||||
.properties = std::map<std::string, PropertyInfo>(),
|
|
||||||
.methods = std::map<std::string, MethodInfo>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
INSTANCE_TYPE(Part, TYPE_PART)
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "datamodel/part.h"
|
#include "part.h"
|
||||||
#include "rendering/renderer.h"
|
#include "rendering/renderer.h"
|
||||||
#include "physics/simulation.h"
|
#include "physics/simulation.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
|
|
@ -3,17 +3,11 @@
|
||||||
#include <glm/fwd.hpp>
|
#include <glm/fwd.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <reactphysics3d/body/RigidBody.h>
|
#include <reactphysics3d/body/RigidBody.h>
|
||||||
#include "../rendering/material.h"
|
#include "rendering/material.h"
|
||||||
#include "instance.h"
|
|
||||||
#include "instancetype.h"
|
|
||||||
|
|
||||||
namespace rp = reactphysics3d;
|
namespace rp = reactphysics3d;
|
||||||
|
|
||||||
extern InstanceType TYPE_PART;
|
struct Part {
|
||||||
|
|
||||||
class Part : public Instance {
|
|
||||||
INSTANCE_PRELUDE(Part)
|
|
||||||
public:
|
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::quat rotation = glm::identity<glm::quat>();
|
glm::quat rotation = glm::identity<glm::quat>();
|
||||||
glm::vec3 scale;
|
glm::vec3 scale;
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../datamodel/part.h"
|
#include "../part.h"
|
||||||
|
|
||||||
void simulationInit();
|
void simulationInit();
|
||||||
void syncPartPhysics(Part& part);
|
void syncPartPhysics(Part& part);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "defaultmeshes.h"
|
#include "defaultmeshes.h"
|
||||||
#include "../camera.h"
|
#include "../camera.h"
|
||||||
#include "../datamodel/part.h"
|
#include "../part.h"
|
||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue