2025-01-12 17:38:23 +00:00
|
|
|
#include "part.h"
|
2025-01-17 08:24:18 +00:00
|
|
|
#include "base/instance.h"
|
2025-01-12 17:38:23 +00:00
|
|
|
|
|
|
|
static InstanceType TYPE_ {
|
|
|
|
.super = Instance::TYPE,
|
|
|
|
.className = "Part",
|
|
|
|
.constructor = &Part::CreateGeneric,
|
2025-01-18 17:50:56 +00:00
|
|
|
.explorerIcon = "part",
|
2025-01-12 17:38:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
InstanceType* Part::TYPE = &TYPE_;
|
|
|
|
|
|
|
|
InstanceType* Part::GetClass() {
|
|
|
|
return &TYPE_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Part::Part(): Instance(&TYPE_) {
|
|
|
|
}
|
2025-01-17 08:24:18 +00:00
|
|
|
|
|
|
|
Part::Part(PartConstructParams params): Instance(&TYPE_), position(params.position), rotation(params.rotation),
|
|
|
|
scale(params.scale), material(params.material), anchored(params.anchored) {
|
2025-01-23 10:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This feels wrong. Get access to PhysicsWorld somehow else? Part will need access to this often though, most likely...
|
|
|
|
extern rp::PhysicsWorld* world;
|
|
|
|
Part::~Part() {
|
2025-01-23 21:58:01 +00:00
|
|
|
// This relies on physicsCommon still existing. Be very careful.
|
2025-01-23 21:38:24 +00:00
|
|
|
if (this->rigidBody)
|
|
|
|
world->destroyRigidBody(rigidBody);
|
2025-01-23 10:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Part::OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) {
|
|
|
|
if (this->rigidBody)
|
|
|
|
this->rigidBody->setIsActive(newParent.has_value());
|
|
|
|
|
|
|
|
// TODO: Sleeping bodies that touch this one also need to be updated
|
2025-01-17 08:24:18 +00:00
|
|
|
}
|