diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6cd0612..20b5585 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: run: cp Content/win32_plugins.cfg build/dist/plugins.cfg && mkdir build/dist/plugins/ && cat build/dist/plugins.cfg | grep "Plugin=" | sed -e "s/Plugin=//" | xargs -I '{}' cp -v '/${{ matrix.sys }}/bin/{}.dll' build/dist/plugins/ - name: Add OGRE shaders - run: mkdir build/dist/shaders && cp -R /${{ matrix.sys }}/share/OGRE/Media/Main/* build/dist/shaders && cp -R /${{ matrix.sys }}/share/OGRE/Media/RTShaderLib/* build/dist/shaders + run: mkdir build/dist/shaders && cp -R /${{ matrix.sys }}/share/OGRE/Media/Main/* build/dist/shaders && cp -R /${{ matrix.sys }}/share/OGRE/Media/RTShaderLib/* build/dist/shaders && mv build/dist/shaders/GLSL/* build/dist/shaders && rm -rf build/dist/shaders/GLSL - name: Add additional runtime dependencies run: ldd build/dist/*.exe | grep "=> /" | awk '{print $3}' | grep "${{ matrix.sys }}" | xargs -I '{}' cp -v '{}' build/dist diff --git a/Content/win32_plugins.cfg b/Content/win32_plugins.cfg index 36d176b..a4d5072 100644 --- a/Content/win32_plugins.cfg +++ b/Content/win32_plugins.cfg @@ -1,6 +1,5 @@ PluginFolder=plugins -Plugin=RenderSystem_GL Plugin=RenderSystem_GL3Plus Plugin=RenderSystem_GLES2 Plugin=Plugin_ParticleFX @@ -8,4 +7,4 @@ Plugin=Plugin_BSPSceneManager Plugin=Codec_STBI Plugin=Plugin_PCZSceneManager Plugin=Plugin_OctreeZone -Plugin=Plugin_OctreeSceneManager +Plugin=Plugin_OctreeSceneManager \ No newline at end of file diff --git a/Dependencies/Luau b/Dependencies/Luau index e25de95..2181591 160000 --- a/Dependencies/Luau +++ b/Dependencies/Luau @@ -1 +1 @@ -Subproject commit e25de95445f2d635a125ab463426bb7fda017093 +Subproject commit 218159140c7d79ae745e646da721d12331f536f5 diff --git a/Projects/Client/Common/Header/QtInputManager.hpp b/Projects/Client/Common/Header/QtInputManager.hpp index ddf0d03..be774ad 100644 --- a/Projects/Client/Common/Header/QtInputManager.hpp +++ b/Projects/Client/Common/Header/QtInputManager.hpp @@ -12,6 +12,8 @@ namespace RNR { private: QPointF last_position; + QPoint grab_position; + bool m_grabbed; OgreWidget* widget; bool reset; public: @@ -21,5 +23,7 @@ namespace RNR void mouseEvent(QMouseEvent* e); virtual void resetMouse(); + virtual void grab(); + virtual void ungrab(); }; } diff --git a/Projects/Client/Common/Source/QtInputManager.cpp b/Projects/Client/Common/Source/QtInputManager.cpp index 01cbaf0..9398c2c 100644 --- a/Projects/Client/Common/Source/QtInputManager.cpp +++ b/Projects/Client/Common/Source/QtInputManager.cpp @@ -7,6 +7,7 @@ namespace RNR { last_position = QPointF(); this->widget = widget; + m_grabbed = false; } void QtInputManager::keyEvent(QKeyEvent* e) @@ -56,10 +57,30 @@ namespace RNR void QtInputManager::resetMouse() { widget->clearFocus(); - QPoint glob = widget->mapToGlobal(QPoint(widget->width()/2,widget->height()/2)); - QCursor::setPos(glob); - last_position = QPoint(widget->width()/2,widget->height()/2); - widget->setFocus(); + if(!m_grabbed) + { + QPoint glob = widget->mapToGlobal(QPoint(widget->width()/2,widget->height()/2)); + QCursor::setPos(glob); + last_position = QPoint(widget->width()/2,widget->height()/2); + } + else + { + QCursor::setPos(widget->mapToGlobal(grab_position)); + last_position = grab_position; + } reset = true; + widget->setFocus(); + } + + void QtInputManager::grab() + { + grab_position = widget->mapFromGlobal(QCursor::pos()); + last_position = grab_position; + m_grabbed = true; + } + + void QtInputManager::ungrab() + { + m_grabbed = false; } } \ No newline at end of file diff --git a/Projects/Client/Player/CMakeLists.txt b/Projects/Client/Player/CMakeLists.txt index 2639461..ada3a06 100644 --- a/Projects/Client/Player/CMakeLists.txt +++ b/Projects/Client/Player/CMakeLists.txt @@ -21,9 +21,11 @@ qt_add_executable(Player ${SOURCE} ${HEADER}) target_include_directories(Player PRIVATE Header) target_link_libraries(Player PRIVATE Common Engine) -set_target_properties(Player PROPERTIES - OUTPUT_NAME "RNR.Player" - - WIN32_EXECUTABLE ON - MACOSX_BUNDLE ON -) \ No newline at end of file +set_target_properties(Player PROPERTIES OUTPUT_NAME "RNR.Player") + +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + set_target_properties(Player PROPERTIES + WIN32_EXECUTABLE ON + MACOSX_BUNDLE ON + ) +endif() \ No newline at end of file diff --git a/Projects/Client/Studio/CMakeLists.txt b/Projects/Client/Studio/CMakeLists.txt index 7ca8ff9..9d1fb2c 100644 --- a/Projects/Client/Studio/CMakeLists.txt +++ b/Projects/Client/Studio/CMakeLists.txt @@ -23,9 +23,11 @@ qt_add_executable(Studio ${SOURCE} ${HEADER}) target_include_directories(Studio PRIVATE Header) target_link_libraries(Studio PRIVATE Common Engine) -set_target_properties(Studio PROPERTIES - OUTPUT_NAME "RNR.Studio" - - WIN32_EXECUTABLE ON - MACOSX_BUNDLE ON -) \ No newline at end of file +set_target_properties(Studio PROPERTIES OUTPUT_NAME "RNR.Studio") + +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + set_target_properties(Studio PROPERTIES + WIN32_EXECUTABLE ON + MACOSX_BUNDLE ON + ) +endif() \ No newline at end of file diff --git a/Projects/Client/Studio/Source/main.cpp b/Projects/Client/Studio/Source/main.cpp index 0a1d5d2..662a7e5 100644 --- a/Projects/Client/Studio/Source/main.cpp +++ b/Projects/Client/Studio/Source/main.cpp @@ -30,9 +30,11 @@ int main(int argc, char** argv) window.updateTree(world->getDatamodel()); window.ogreWidget->setWorld(world); + RNR::ComPlicitNgine* ngine = world->getComPlicitNgine(); + while (window.isVisible()) { - window.statusBar()->showMessage(QString::asprintf("Dt=%f, Rt=%f, Pt=%f, FPS=%f, pFPS=%f", window.ogreWidget->delta, window.ogreWidget->render_time, window.ogreWidget->world->getPhysicsTime(), 1 / window.ogreWidget->delta, 1 / window.ogreWidget->world->getLastPhysicsDelta())); + window.statusBar()->showMessage(QString::asprintf("Dt=%f, Rt=%f, Pt=%f, FPS=%f, pFPS=%f", window.ogreWidget->delta, window.ogreWidget->render_time, ngine->getPhysicsTime(), 1 / window.ogreWidget->delta, 1 / ngine->getLastPhysicsDelta())); app.processEvents(); window.ogreWidget->render(); world->update(); diff --git a/Projects/Engine/CMakeLists.txt b/Projects/Engine/CMakeLists.txt index dddd4cd..26a1592 100644 --- a/Projects/Engine/CMakeLists.txt +++ b/Projects/Engine/CMakeLists.txt @@ -27,6 +27,8 @@ add_library(Engine STATIC Header/App/V8/Tree/PVInstance.hpp Header/App/V8/Tree/ModelInstance.hpp Header/App/V8/World/World.hpp + Header/App/V8/World/Weld.hpp + Header/App/V8/World/ComPlicitNgine.hpp Header/App/CoordinateFrame.hpp Header/App/BrickColor.hpp Header/App/InputManager.hpp @@ -64,6 +66,8 @@ add_library(Engine STATIC Source/App/BrickColor.cpp Source/App/InputManager.cpp Source/App/V8/World/World.cpp + Source/App/V8/World/Weld.cpp + Source/App/V8/World/ComPlicitNgine.cpp Source/Network/GUID.cpp Source/Network/Player.cpp Source/Network/Players.cpp diff --git a/Projects/Engine/Header/App/InputManager.hpp b/Projects/Engine/Header/App/InputManager.hpp index d4dc866..02b6031 100644 --- a/Projects/Engine/Header/App/InputManager.hpp +++ b/Projects/Engine/Header/App/InputManager.hpp @@ -23,6 +23,8 @@ namespace RNR IInputManager(); virtual void resetMouse() {}; + virtual void grab() {}; + virtual void ungrab() {}; void setWorld(World* world) { m_world = world; world->setInputManager(this); } diff --git a/Projects/Engine/Header/App/V8/DataModel/FaceInstance.hpp b/Projects/Engine/Header/App/V8/DataModel/FaceInstance.hpp index 531f5e1..faaf2a1 100644 --- a/Projects/Engine/Header/App/V8/DataModel/FaceInstance.hpp +++ b/Projects/Engine/Header/App/V8/DataModel/FaceInstance.hpp @@ -5,7 +5,7 @@ namespace RNR { - class FaceInstance : public Instance, Ogre::ManualObject + class FaceInstance : public Instance { private: NormalId m_face; diff --git a/Projects/Engine/Header/App/V8/World/ComPlicitNgine.hpp b/Projects/Engine/Header/App/V8/World/ComPlicitNgine.hpp new file mode 100644 index 0000000..64a3bcb --- /dev/null +++ b/Projects/Engine/Header/App/V8/World/ComPlicitNgine.hpp @@ -0,0 +1,40 @@ +#pragma once +#include +#include +#include +#include "LinearMath/btVector3.h" +#include "btBulletDynamicsCommon.h" +#include + +namespace RNR +{ + class World; + + class ComPlicitNgine + { + std::thread m_physicsThread; + Ogre::Timer* m_physicsTimer; + float m_lastPhysicsDelta; + float m_physicsTime; + btDiscreteDynamicsWorld* m_dynamicsWorld; + World* m_world; + std::map m_physicsParts; + + void thread(); + public: + ComPlicitNgine(World* world); + ~ComPlicitNgine(); + + void updateTree(); + void updateTreeRender(); + + Ogre::Timer* getPhysicsTimer() { return m_physicsTimer; } + float getLastPhysicsDelta() { return m_lastPhysicsDelta; } + float getPhysicsTime() { return m_physicsTime; } + + btRigidBody* getBody(PartInstance* part) { return m_physicsParts[part]; }; + + void registerPhysicsPart(PartInstance* partRegistered); + void deletePhysicsPart(PartInstance* partDelete); + }; +} \ No newline at end of file diff --git a/Projects/Engine/Header/App/V8/World/Weld.hpp b/Projects/Engine/Header/App/V8/World/Weld.hpp new file mode 100644 index 0000000..2a57949 --- /dev/null +++ b/Projects/Engine/Header/App/V8/World/Weld.hpp @@ -0,0 +1,28 @@ +#pragma once +#include +#include +#include + +namespace RNR +{ + class Weld : public Instance + { + btRigidBody* m_aBody; + PartInstance* m_aInstance; + + btRigidBody* m_bBody; + PartInstance* m_bInstance; + + btFixedConstraint* m_constraint; + public: + Weld(); + ~Weld(); + virtual std::string getClassName() { return "Weld"; } + + void weld(PartInstance* a, PartInstance* b); + void create(); + void destroy(); + + bool getBroken(); + }; +} \ No newline at end of file diff --git a/Projects/Engine/Header/App/V8/World/World.hpp b/Projects/Engine/Header/App/V8/World/World.hpp index 3ab28f7..f2877da 100644 --- a/Projects/Engine/Header/App/V8/World/World.hpp +++ b/Projects/Engine/Header/App/V8/World/World.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -14,7 +15,6 @@ #include "LinearMath/btVector3.h" #include "btBulletDynamicsCommon.h" - namespace RNR { class IInputManager; @@ -30,9 +30,6 @@ namespace RNR class World { private: - std::thread m_physicsThread; - Ogre::Timer* m_physicsTimer; - bool m_runPhysics; std::map m_refs; std::stack m_undeserialized; @@ -47,8 +44,7 @@ namespace RNR InstanceFactory* m_instanceFactory; IInputManager* m_inputManager; float m_lastDelta; - float m_lastPhysicsDelta; - float m_physicsTime; + ComPlicitNgine* m_ngine; void xmlAddItem(pugi::xml_node node, Instance* parent); public: @@ -65,8 +61,9 @@ namespace RNR void update(); btDiscreteDynamicsWorld* getDynamicsWorld() { return m_dynamicsWorld; } + ComPlicitNgine* getComPlicitNgine() { return m_ngine; } float getLastDelta() { return m_lastDelta; } - float getLastPhysicsDelta() { return m_lastPhysicsDelta; } + float getLastPhysicsDelta() { return m_ngine->getLastPhysicsDelta(); } DataModel* getDatamodel() { return m_datamodel; } void setInputManager(IInputManager* inputManager) { m_inputManager = inputManager; } IInputManager* getInputManager() { return m_inputManager; } @@ -77,14 +74,8 @@ namespace RNR void setRunService(RunService* runService) { m_runService = runService; } Ogre::Root* getOgreRoot() { return m_ogreRoot; } Ogre::SceneManager* getOgreSceneManager() { return m_ogreSceneManager; } - Ogre::Timer* getPhysicsTimer() { return m_physicsTimer; } - float getPhysicsTime() { return m_physicsTime; } - void setPhysicsTime(float newTime) { m_physicsTime = newTime; } // should only be used by physicsThread bool getPhysicsShouldBeRunningPleaseStopIfItIsStillRunning() { return m_runPhysics; } - void registerPhysicsPart(PartInstance* partRegistered); - void deletePhysicsPart(PartInstance* partDelete); - Lock physicsIterateLock; }; } \ No newline at end of file diff --git a/Projects/Engine/Source/App/GUI/TopMenuBar.cpp b/Projects/Engine/Source/App/GUI/TopMenuBar.cpp index f52ef2d..590dc8a 100644 --- a/Projects/Engine/Source/App/GUI/TopMenuBar.cpp +++ b/Projects/Engine/Source/App/GUI/TopMenuBar.cpp @@ -3,8 +3,17 @@ namespace RNR { + // sub_60D330 TopMenuBar::TopMenuBar(World* world) { + /* + if ( v30 ) + { + *(float *)(v30 + 260) = 100.0; + *(float *)(v30 + 264) = 20.0; + } + */ + m_world = world; m_overlayManager = Ogre::OverlayManager::getSingletonPtr(); @@ -20,53 +29,53 @@ namespace RNR Ogre::OverlayContainer* panel = static_cast(m_overlayManager->createOverlayElement("Panel", "TopMenuBarPanel")); panel->setMetricsMode(Ogre::GMM_PIXELS); panel->setPosition(0,0); - panel->setDimensions(128 * 5, 20); + panel->setDimensions(100 * 5, 20); panel->setMaterial(material); - Ogre::ColourValue text_color = Ogre::ColourValue(0.25, 0.25, 0.25); + Ogre::ColourValue text_color = Ogre::ColourValue(0.25, 0.25, 0.25, 0.95); Ogre::TextAreaOverlayElement* toolsTextArea = static_cast(m_overlayManager->createOverlayElement("TextArea", "TopMenuBarTools")); toolsTextArea->setMetricsMode(Ogre::GMM_PIXELS); toolsTextArea->setPosition(0, 0); - toolsTextArea->setDimensions(128, 24); + toolsTextArea->setDimensions(100, 20); toolsTextArea->setCaption("Tools"); - toolsTextArea->setCharHeight(24); + toolsTextArea->setCharHeight(20); toolsTextArea->setFontName("ComicSans"); toolsTextArea->setColour(text_color); Ogre::TextAreaOverlayElement* insertTextArea = static_cast(m_overlayManager->createOverlayElement("TextArea", "TopMenuBarInsert")); insertTextArea->setMetricsMode(Ogre::GMM_PIXELS); - insertTextArea->setPosition(128, 0); - insertTextArea->setDimensions(128, 24); + insertTextArea->setPosition(100, 0); + insertTextArea->setDimensions(100, 20); insertTextArea->setCaption("Insert"); - insertTextArea->setCharHeight(24); + insertTextArea->setCharHeight(20); insertTextArea->setFontName("ComicSans"); insertTextArea->setColour(text_color); Ogre::TextAreaOverlayElement* fullscreenTextArea = static_cast(m_overlayManager->createOverlayElement("TextArea", "TopMenuBarFullscreen")); fullscreenTextArea->setMetricsMode(Ogre::GMM_PIXELS); - fullscreenTextArea->setPosition(128*2, 0); - fullscreenTextArea->setDimensions(128, 24); + fullscreenTextArea->setPosition(100*2, 0); + fullscreenTextArea->setDimensions(100, 20); fullscreenTextArea->setCaption("Fullscreen"); - fullscreenTextArea->setCharHeight(24); + fullscreenTextArea->setCharHeight(20); fullscreenTextArea->setFontName("ComicSans"); fullscreenTextArea->setColour(text_color); Ogre::TextAreaOverlayElement* helpTextArea = static_cast(m_overlayManager->createOverlayElement("TextArea", "TopMenuBarHelp")); helpTextArea->setMetricsMode(Ogre::GMM_PIXELS); - helpTextArea->setPosition(128*3, 0); - helpTextArea->setDimensions(128, 24); + helpTextArea->setPosition(100*3, 0); + helpTextArea->setDimensions(100, 20); helpTextArea->setCaption("Help..."); - helpTextArea->setCharHeight(24); + helpTextArea->setCharHeight(20); helpTextArea->setFontName("ComicSans"); helpTextArea->setColour(text_color); Ogre::TextAreaOverlayElement* exitTextArea = static_cast(m_overlayManager->createOverlayElement("TextArea", "TopMenuBarExit")); exitTextArea->setMetricsMode(Ogre::GMM_PIXELS); - exitTextArea->setPosition(128*4, 0); - exitTextArea->setDimensions(128, 24); - exitTextArea->setCaption("Exit"); - exitTextArea->setCharHeight(24); + exitTextArea->setPosition(100*4, 0); + exitTextArea->setDimensions(100, 20); + exitTextArea->setCaption(" Exit"); // ... apparently spacing is how it was done in the original client + exitTextArea->setCharHeight(20); exitTextArea->setFontName("ComicSans"); exitTextArea->setColour(text_color); @@ -89,7 +98,7 @@ namespace RNR m_playerPanel = static_cast(m_overlayManager->createOverlayElement("Panel", "PlayerListPanel")); m_playerPanel->setMetricsMode(Ogre::GMM_PIXELS); - m_playerPanel->setDimensions(128, 20); + m_playerPanel->setDimensions(100, 20); m_playerPanel->setMaterial(material); m_playerList = static_cast(m_overlayManager->createOverlayElement("TextArea", "PlayerListTextArea")); @@ -97,7 +106,7 @@ namespace RNR m_playerList->setPosition(0, 0); m_playerList->setDimensions(1000, 1000); m_playerList->setCaption("Player List"); - m_playerList->setCharHeight(24); + m_playerList->setCharHeight(20); m_playerList->setFontName("ComicSans"); m_playerList->setColour(Ogre::ColourValue(1.0f, 1.0f, 1.0f)); @@ -146,14 +155,14 @@ namespace RNR else { m_playerPanel->setVisible(true); - m_playerPanel->setPosition(m_overlayManager->getViewportWidth() - 128 - 5,5); + m_playerPanel->setPosition(m_overlayManager->getViewportWidth() - 100 - 5,5); std::string player_list_text = "Player List\n"; for(auto player : *player_list) { player_list_text += player->getName() + "\n"; } m_playerList->setCaption(player_list_text); - m_playerPanel->setDimensions(128, 20 * (player_list->size() + 1)); + m_playerPanel->setDimensions(100, 20 * (player_list->size() + 1)); } } } \ No newline at end of file diff --git a/Projects/Engine/Source/App/Humanoid/Humanoid.cpp b/Projects/Engine/Source/App/Humanoid/Humanoid.cpp index e708461..e0fcaef 100644 --- a/Projects/Engine/Source/App/Humanoid/Humanoid.cpp +++ b/Projects/Engine/Source/App/Humanoid/Humanoid.cpp @@ -1,5 +1,6 @@ #include #include +#include #include namespace RNR @@ -24,7 +25,13 @@ namespace RNR void Humanoid::buildJoints() { - // + if(getTorso() && getHead()) + { + Weld* headWeld = new Weld(); + headWeld->weld(getTorso(), getHead()); + headWeld->create(); + headWeld->setParent(getTorso()); + } } void Humanoid::checkForJointDeath() @@ -118,7 +125,7 @@ namespace RNR move *= world->getLastDelta(); bool move_valid = true; - + // TODO: collision checking if(!move_valid) diff --git a/Projects/Engine/Source/App/InputManager.cpp b/Projects/Engine/Source/App/InputManager.cpp index 28c6b1b..9a4c5e8 100644 --- a/Projects/Engine/Source/App/InputManager.cpp +++ b/Projects/Engine/Source/App/InputManager.cpp @@ -91,6 +91,10 @@ namespace RNR void IInputManager::mouseSecondaryState(bool down) { + if(down) + grab(); + else if(!down) + ungrab(); state.mouse_secondary = down; } diff --git a/Projects/Engine/Source/App/V8/DataModel/FaceInstance.cpp b/Projects/Engine/Source/App/V8/DataModel/FaceInstance.cpp index 228dbcd..c4ec6df 100644 --- a/Projects/Engine/Source/App/V8/DataModel/FaceInstance.cpp +++ b/Projects/Engine/Source/App/V8/DataModel/FaceInstance.cpp @@ -6,10 +6,11 @@ namespace RNR { - FaceInstance::FaceInstance() : Ogre::ManualObject(Strings::random_hex(8)) + FaceInstance::FaceInstance() { setNode(world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode()); - getNode()->attachObject(this); + + build(); } } \ No newline at end of file diff --git a/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp b/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp index 9e545d5..441bf13 100644 --- a/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp +++ b/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp @@ -60,7 +60,7 @@ namespace RNR child_node->setVisible(true); break; } - world->registerPhysicsPart(part); + world->getComPlicitNgine()->registerPhysicsPart(part); } } @@ -81,7 +81,7 @@ namespace RNR { PartInstance* part = dynamic_cast(childRemoved); if(part) - world->deletePhysicsPart(part); + world->getComPlicitNgine()->deletePhysicsPart(part); m_geomDirty = true; } diff --git a/Projects/Engine/Source/App/V8/World/ComPlicitNgine.cpp b/Projects/Engine/Source/App/V8/World/ComPlicitNgine.cpp new file mode 100644 index 0000000..d59cb8f --- /dev/null +++ b/Projects/Engine/Source/App/V8/World/ComPlicitNgine.cpp @@ -0,0 +1,117 @@ +#include +#include +#include + +namespace RNR +{ + void ComPlicitNgine::thread() + { + float delta; + float time; + while(m_world->getPhysicsShouldBeRunningPleaseStopIfItIsStillRunning()) + { + delta = m_physicsTimer->getMicroseconds() / 1000000.0; + time += m_physicsTimer->getMilliseconds() / 1000.0; + m_physicsTimer->reset(); + + m_lastPhysicsDelta = delta; + m_physicsTime = time; + + m_world->preStep(); + m_world->step(delta); + + m_lastPhysicsDelta = delta; + } + } + + ComPlicitNgine::ComPlicitNgine(World* world) + { + m_physicsTimer = new Ogre::Timer(); + m_physicsTime = 0.0; + m_physicsThread = std::thread(&ComPlicitNgine::thread, this); + m_dynamicsWorld = world->getDynamicsWorld(); + m_world = world; + } + + ComPlicitNgine::~ComPlicitNgine() + { + m_physicsThread.join(); + } + + void ComPlicitNgine::updateTreeRender() + { + for(int j = m_dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) + { + btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[j]; + if(!obj->isActive()) + continue; + PartInstance* part = (PartInstance*)obj->getUserPointer(); + part->updateMatrix(); + } + } + + void ComPlicitNgine::updateTree() + { + for(int j = m_dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) + { + btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[j]; + if(!obj->isActive()) + continue; + btRigidBody* body = btRigidBody::upcast(obj); + btTransform trans; + if(body && body->getMotionState()) + { + body->getMotionState()->getWorldTransform(trans); + } + else + { + trans = obj->getWorldTransform(); + } + PartInstance* part = (PartInstance*)obj->getUserPointer(); + part->getCFrame().setPosition(Bullet::v3ToOgre(trans.getOrigin())); + Ogre::Matrix3 partRot; + Ogre::Quaternion transOgre = Bullet::qtToOgre(trans.getRotation()); + transOgre.ToRotationMatrix(partRot); + part->getCFrame().setRotation(partRot); + } + } + + void ComPlicitNgine::registerPhysicsPart(PartInstance* partRegistered) + { + btCollisionShape* partShape = new btBoxShape(Bullet::v3ToBullet(partRegistered->getSize() / 2.f)); + partShape->setUserPointer(partRegistered); + + btTransform partTransform; + partTransform.setIdentity(); + partTransform.setOrigin(Bullet::v3ToBullet(partRegistered->getPosition())); + partTransform.setRotation(Bullet::qtToBullet(partRegistered->getRotation())); + + btScalar mass = partRegistered->getSize().length(); + if(partRegistered->getAnchored()) + mass = 0; + + btVector3 localInertia = btVector3(0,0,0); + if(mass) + partShape->calculateLocalInertia(mass, localInertia); + + btDefaultMotionState* partMotionState = new btDefaultMotionState(partTransform); + btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, partMotionState, partShape, localInertia); + btRigidBody* body = new btRigidBody(rbInfo); + body->setUserPointer(partRegistered); + + m_world->physicsIterateLock.lock(); + m_dynamicsWorld->addRigidBody(body); + m_world->physicsIterateLock.unlock(); + + m_physicsParts[partRegistered] = body; + } + + void ComPlicitNgine::deletePhysicsPart(PartInstance* partDelete) + { + btRigidBody* toDelete = m_physicsParts[partDelete]; + if(toDelete) + { + + } + } +} \ No newline at end of file diff --git a/Projects/Engine/Source/App/V8/World/Weld.cpp b/Projects/Engine/Source/App/V8/World/Weld.cpp new file mode 100644 index 0000000..48742d0 --- /dev/null +++ b/Projects/Engine/Source/App/V8/World/Weld.cpp @@ -0,0 +1,45 @@ +#include +#include + +namespace RNR +{ + Weld::Weld() + { + setName("Weld"); + } + + Weld::~Weld() + { + destroy(); + } + + void Weld::weld(PartInstance* a, PartInstance* b) + { + m_aInstance = a; + m_bInstance = b; + + m_aBody = world->getComPlicitNgine()->getBody(a); + m_bBody = world->getComPlicitNgine()->getBody(b); + } + + void Weld::create() + { + if(!m_aBody || !m_bBody) + return; + + m_constraint = new btFixedConstraint(*m_aBody, *m_bBody, m_aBody->getWorldTransform(), m_bBody->getWorldTransform()); + } + + void Weld::destroy() + { + delete m_constraint; + } + + bool Weld::getBroken() + { + if(!m_constraint) + return true; + + return false; + } +} \ No newline at end of file diff --git a/Projects/Engine/Source/App/V8/World/World.cpp b/Projects/Engine/Source/App/V8/World/World.cpp index 547f605..ef940ce 100644 --- a/Projects/Engine/Source/App/V8/World/World.cpp +++ b/Projects/Engine/Source/App/V8/World/World.cpp @@ -12,21 +12,6 @@ namespace RNR { - void physicsThread(World* world) - { - float delta; - float time; - while(world->getPhysicsShouldBeRunningPleaseStopIfItIsStillRunning()) - { - delta = world->getPhysicsTimer()->getMicroseconds() / 1000000.0; - time += world->getPhysicsTimer()->getMilliseconds() / 1000.0; - world->setPhysicsTime(time); - world->getPhysicsTimer()->reset(); - world->preStep(); - world->step(delta); - } - } - World::World(Ogre::Root* ogre, Ogre::SceneManager* ogreSceneManager) { Instance::setWorld(this); @@ -62,10 +47,7 @@ namespace RNR m_players = (Players*)m_datamodel->getService("Players"); m_runPhysics = true; - m_physicsTimer = new Ogre::Timer(); - m_physicsThread = std::thread(physicsThread, this); - m_physicsTime = 0.0; - + m_ngine = new ComPlicitNgine(this); m_tmb = new TopMenuBar(this); Camera* start_cam = new Camera(); @@ -76,7 +58,7 @@ namespace RNR World::~World() { m_runPhysics = false; - m_physicsThread.join(); + delete m_ngine; } void World::xmlAddItem(pugi::xml_node node, Instance* parent) @@ -170,19 +152,8 @@ namespace RNR m_tmb->frame(); m_lastDelta = timestep; if(m_runService && m_runService->getRunning() && !m_runService->getPaused()) - { - physicsIterateLock.lock(); - for(int j = m_dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) - { - btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[j]; - if(!obj->isActive()) - continue; - PartInstance* part = (PartInstance*)obj->getUserPointer(); - part->updateMatrix(); - } - update(); - physicsIterateLock.unlock(); - } + m_ngine->updateTreeRender(); + update(); } void World::preStep() @@ -195,34 +166,9 @@ namespace RNR if(m_runService && m_runService->getRunning() && !m_runService->getPaused()) { m_runService->step(timestep); - m_dynamicsWorld->stepSimulation(timestep, 2); - - physicsIterateLock.lock(); - for(int j = m_dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) - { - btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[j]; - if(!obj->isActive()) - continue; - btRigidBody* body = btRigidBody::upcast(obj); - btTransform trans; - if(body && body->getMotionState()) - { - body->getMotionState()->getWorldTransform(trans); - } - else - { - trans = obj->getWorldTransform(); - } - PartInstance* part = (PartInstance*)obj->getUserPointer(); - part->getCFrame().setPosition(Bullet::v3ToOgre(trans.getOrigin())); - Ogre::Matrix3 partRot; - Ogre::Quaternion transOgre = Bullet::qtToOgre(trans.getRotation()); - transOgre.ToRotationMatrix(partRot); - part->getCFrame().setRotation(partRot); - } - physicsIterateLock.unlock(); + m_dynamicsWorld->stepSimulation(timestep, 1); + m_ngine->updateTree(); } - m_lastPhysicsDelta = timestep; return 0.0; } @@ -231,34 +177,4 @@ namespace RNR m_workspace->buildGeom(); } - void World::registerPhysicsPart(PartInstance* partRegistered) - { - btCollisionShape* partShape = new btBoxShape(Bullet::v3ToBullet(partRegistered->getSize() / 2.f)); - partShape->setUserPointer(partRegistered); - - btTransform partTransform; - partTransform.setIdentity(); - partTransform.setOrigin(Bullet::v3ToBullet(partRegistered->getPosition())); - partTransform.setRotation(Bullet::qtToBullet(partRegistered->getRotation())); - - btScalar mass = partRegistered->getSize().length(); - if(partRegistered->getAnchored()) - mass = 0; - - btVector3 localInertia = btVector3(0,0,0); - if(mass) - partShape->calculateLocalInertia(mass, localInertia); - - btDefaultMotionState* partMotionState = new btDefaultMotionState(partTransform); - btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, partMotionState, partShape, localInertia); - btRigidBody* body = new btRigidBody(rbInfo); - body->setUserPointer(partRegistered); - - m_dynamicsWorld->addRigidBody(body); - } - - void World::deletePhysicsPart(PartInstance* partDelete) - { - - } } \ No newline at end of file diff --git a/Projects/Engine/Source/Network/Player.cpp b/Projects/Engine/Source/Network/Player.cpp index 1a01c5c..2c9ec5f 100644 --- a/Projects/Engine/Source/Network/Player.cpp +++ b/Projects/Engine/Source/Network/Player.cpp @@ -53,6 +53,8 @@ namespace RNR Humanoid* character_humanoid = new Humanoid(); character_humanoid->setParent(m_character); m_character->setParent(world->getWorkspace()); + + character_humanoid->buildJoints(); Camera* player_camera = world->getWorkspace()->getCurrentCamera(); player_camera->setCFrame(CoordinateFrame());