#pragma once #include "objects/annotation.h" #include "objects/base/service.h" #include "physics/world.h" #include "utils.h" #include #include #include #include #include class BasePart; class Snap; class Weld; class Rotate; class RotateV; struct ContactItem { std::shared_ptr part0; std::shared_ptr part1; enum { CONTACTITEM_TOUCHED, CONTACTITEM_TOUCHENDED, } action; }; class DEF_INST_SERVICE_(explorer_icon="workspace") Workspace : public Service { AUTOGEN_PREAMBLE std::queue contactQueue; std::mutex contactQueueLock; std::shared_ptr physicsWorld; friend PhysWorld; protected: void InitService() override; void OnRun() override; bool initialized = false; public: Workspace(); ~Workspace(); std::recursive_mutex queueLock; DEF_PROP float fallenPartsDestroyHeight = -500; // static inline std::shared_ptr New() { return std::make_shared(); }; static inline std::shared_ptr Create() { return std::make_shared(); }; inline void AddBody(std::shared_ptr part) { physicsWorld->addBody(part); } inline void RemoveBody(std::shared_ptr part) { physicsWorld->removeBody(part); } void SyncPartPhysics(std::shared_ptr part); inline PhysJoint CreateJoint(PhysJointInfo& info, std::shared_ptr part0, std::shared_ptr part1) { return physicsWorld->createJoint(info, part0, part1); } inline void DestroyJoint(PhysJoint joint) { physicsWorld->destroyJoint(joint); } void PhysicsStep(float deltaTime); inline std::optional CastRayNearest(glm::vec3 point, glm::vec3 rotation, float maxLength, std::optional filter = std::nullopt, unsigned short categoryMaskBits = 0xFFFF) { return physicsWorld->castRay(point, rotation, maxLength, filter, categoryMaskBits); } };