refactor(workspace): physicsWorld is now never null
This commit is contained in:
parent
f2a7662b08
commit
b1c7eca289
7 changed files with 12 additions and 15 deletions
|
@ -20,7 +20,6 @@ void Rotate::buildJoint() {
|
|||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
if (!workspace->physicsWorld) return;
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
// used to be rather than specifying an anchor rotation, so whatever.
|
||||
|
@ -41,7 +40,7 @@ void Rotate::buildJoint() {
|
|||
// !!! REMINDER: This has to be called manually when parts are destroyed/removed from the workspace, or joints will linger
|
||||
void Rotate::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired() || !jointWorkspace.lock()->physicsWorld) return;
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->physicsWorld->destroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
|
|
|
@ -22,7 +22,6 @@ void RotateV::buildJoint() {
|
|||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
if (!workspace->physicsWorld) return;
|
||||
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
|
@ -47,7 +46,7 @@ void RotateV::buildJoint() {
|
|||
|
||||
void RotateV::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired() || !jointWorkspace.lock()->physicsWorld) return;
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->physicsWorld->destroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
|
|
|
@ -24,7 +24,6 @@ void Snap::buildJoint() {
|
|||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
if (!workspace->physicsWorld) return;
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
// used to be rather than specifying an anchor rotation, so whatever.
|
||||
|
@ -40,7 +39,7 @@ void Snap::buildJoint() {
|
|||
// !!! REMINDER: This has to be called manually when parts are destroyed/removed from the workspace, or joints will linger
|
||||
void Snap::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired() || !jointWorkspace.lock()->physicsWorld) return;
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->physicsWorld->destroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
|
|
|
@ -24,7 +24,6 @@ void Weld::buildJoint() {
|
|||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
if (!workspace->physicsWorld) return;
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
// used to be rather than specifying an anchor rotation, so whatever.
|
||||
|
@ -40,7 +39,7 @@ void Weld::buildJoint() {
|
|||
// !!! REMINDER: This has to be called manually when parts are destroyed/removed from the workspace, or joints will linger
|
||||
void Weld::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired() || !jointWorkspace.lock()->physicsWorld) return;
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->physicsWorld->destroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
rp::PhysicsCommon* Workspace::physicsCommon = new rp::PhysicsCommon;
|
||||
|
||||
Workspace::Workspace(): Service(&TYPE), physicsEventListener(this) {
|
||||
physicsWorld = physicsCommon->createPhysicsWorld();
|
||||
}
|
||||
|
||||
Workspace::~Workspace() {
|
||||
if (physicsWorld && physicsCommon)
|
||||
if (physicsCommon)
|
||||
physicsCommon->destroyPhysicsWorld(physicsWorld);
|
||||
}
|
||||
|
||||
|
@ -67,8 +68,6 @@ void Workspace::InitService() {
|
|||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
physicsWorld = physicsCommon->createPhysicsWorld();
|
||||
|
||||
physicsWorld->setGravity(rp::Vector3(0, -196.2, 0));
|
||||
// world->setContactsPositionCorrectionTechnique(rp3d::ContactsPositionCorrectionTechnique::BAUMGARTE_CONTACTS);
|
||||
physicsWorld->setNbIterationsPositionSolver(2000);
|
||||
|
@ -103,8 +102,6 @@ void Workspace::InitService() {
|
|||
}
|
||||
|
||||
void Workspace::SyncPartPhysics(std::shared_ptr<Part> part) {
|
||||
if (!physicsWorld) return;
|
||||
|
||||
rp::Transform transform = part->cframe;
|
||||
if (!part->rigidBody) {
|
||||
part->rigidBody = physicsWorld->createRigidBody(transform);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/service.h"
|
||||
#include "utils.h"
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <memory>
|
||||
#include <reactphysics3d/body/RigidBody.h>
|
||||
|
@ -50,7 +51,7 @@ class PhysicsEventListener : public rp::EventListener {
|
|||
class DEF_INST_SERVICE_(explorer_icon="workspace") Workspace : public Service {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
rp::PhysicsWorld* physicsWorld = nullptr;
|
||||
rp::PhysicsWorld* notnull physicsWorld;
|
||||
static rp::PhysicsCommon* physicsCommon;
|
||||
PhysicsEventListener physicsEventListener;
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __clang__
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic ignored "-Wnullability-extension"
|
||||
#define nullable _Nullable
|
||||
#define notnull _Nonnull
|
||||
#elif defined(__GNUC__)
|
||||
#define nullable
|
||||
#define notnull __attribute__((nonnull))
|
||||
#else
|
||||
#define nullable
|
||||
#define notnull
|
||||
|
|
Loading…
Add table
Reference in a new issue