From edd6fe93c625f2dae2865caf8c93af78ee5937e1 Mon Sep 17 00:00:00 2001 From: CekisSWG Date: Tue, 21 Jan 2020 15:45:40 -0500 Subject: [PATCH] In Work - Trying to prevent flying into a portal/building --- .../shared/collision/CollisionCallbacks.cpp | 2 +- .../controller/PlayerShipController.cpp | 5 ++++- .../shared/controller/ServerController.cpp | 1 - .../collision/CollisionCallbackManager.cpp | 20 ++++++++++++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/engine/server/library/serverGame/src/shared/collision/CollisionCallbacks.cpp b/engine/server/library/serverGame/src/shared/collision/CollisionCallbacks.cpp index b3b21c41..6dc5e614 100755 --- a/engine/server/library/serverGame/src/shared/collision/CollisionCallbacks.cpp +++ b/engine/server/library/serverGame/src/shared/collision/CollisionCallbacks.cpp @@ -10,6 +10,7 @@ #include "serverGame/FirstServerGame.h" #include "serverGame/CollisionCallbacks.h" +#include "serverGame/ContainerInterface.h" #include "serverGame/ShipController.h" #include "serverGame/ShipObject.h" #include "sharedFoundation/CrcLowerString.h" @@ -144,5 +145,4 @@ bool CollisionCallbacksNamespace::onDoCollisionWithTerrain(Object * const object return false; } -// ====================================================================== diff --git a/engine/server/library/serverGame/src/shared/controller/PlayerShipController.cpp b/engine/server/library/serverGame/src/shared/controller/PlayerShipController.cpp index 921e3980..e2b072f6 100755 --- a/engine/server/library/serverGame/src/shared/controller/PlayerShipController.cpp +++ b/engine/server/library/serverGame/src/shared/controller/PlayerShipController.cpp @@ -35,6 +35,8 @@ #include "sharedNetworkMessages/ShipUpdateTransformMessage.h" #include "sharedObject/AlterResult.h" #include "sharedObject/NetworkIdManager.h" +#include "sharedMath/Capsule.h" +#include "sharedCollision/CollisionProperty.h" #include #include @@ -193,8 +195,9 @@ void PlayerShipController::receiveTransform(ShipUpdateTransformMessage const & s Vector const &velocity = shipUpdateTransformMessage.getVelocity(); float const speed = velocity.magnitude(); - if (!checkValidMove(transform, velocity, speed, syncStamp)) + if (!checkValidMove(transform, velocity, speed, syncStamp)) { teleport(m_lastVerifiedTransform, 0); + } else { m_shipDynamicsModel->setTransform(transform); diff --git a/engine/server/library/serverGame/src/shared/controller/ServerController.cpp b/engine/server/library/serverGame/src/shared/controller/ServerController.cpp index e5022b3e..60ef9c28 100755 --- a/engine/server/library/serverGame/src/shared/controller/ServerController.cpp +++ b/engine/server/library/serverGame/src/shared/controller/ServerController.cpp @@ -387,7 +387,6 @@ void ServerController::setGoal ( Transform const & newGoal, ServerObject * goalC bool changeCells(ServerObject &object, ServerObject *newCellObject) { bool result = false; - if (!object.isInWorld()) { if (!newCellObject) diff --git a/engine/shared/library/sharedGame/src/shared/collision/CollisionCallbackManager.cpp b/engine/shared/library/sharedGame/src/shared/collision/CollisionCallbackManager.cpp index a8dcf0d5..2526f1c4 100755 --- a/engine/shared/library/sharedGame/src/shared/collision/CollisionCallbackManager.cpp +++ b/engine/shared/library/sharedGame/src/shared/collision/CollisionCallbackManager.cpp @@ -23,6 +23,7 @@ #include "sharedMath/Capsule.h" #include "sharedObject/Object.h" #include "sharedTerrain/TerrainObject.h" +#include "sharedObject/CellProperty.h" #include // ====================================================================== @@ -227,11 +228,16 @@ bool CollisionCallbackManager::intersectAndReflectWithTerrain(Object * const obj { TerrainObject * terrainObject = TerrainObject::getInstance(); if(terrainObject) { - float const radius = queryCapsule_w.getRadius(); Vector const begin_w(queryCapsule_w.getPointA()); Vector const end_w(queryCapsule_w.getPointB() + direction_w * radius); CollisionInfo info; + float time = 0.f; + CellProperty const * wcell = CellProperty::getWorldCellProperty(); + CellProperty const * dcell = wcell->getDestinationCell(begin_w, end_w, time); + + REPORT_LOG(true,("Checking collision.\n")); + REPORT_LOG(CollisionUtils::testPortalVis(wcell, begin_w, dcell, end_w),("Possible Cell Collision.\n")); // Generate missing terrain between point A and point B and check collision. if(terrainObject->collideForceChunkCreation(begin_w, end_w, info)) { @@ -244,6 +250,18 @@ bool CollisionCallbackManager::intersectAndReflectWithTerrain(Object * const obj result.m_newReflection_p = result.m_normalOfSurface_p.reflectIncoming(direction_w); return true; } +// else if (dcell->getDestinationCell(begin_w, end_w, time)) { +// // We've collided with a cell between point A and point B so handle it. +// Vector const & pointOfCollision_w = end_w; +// +// result.m_pointOfCollision_p = pointOfCollision_w; +// // Assume any cells have a vertical entry (no known structure has a horizontal entry point). +// // Note: Starports don't have an entry point until you land in the middle - which is NOT a true cell. +// result.m_normalOfSurface_p = Vector(0.f,1.f,0.f); +// result.m_deltaToMoveBack_p = pointOfCollision_w - end_w; +// result.m_newReflection_p = result.m_normalOfSurface_p.reflectIncoming(direction_w); +// return true; +// } } } return false;