Skip to content

Commit

Permalink
Server/Ship: (re-)Apply ship linear velocity to exiting players
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Dec 13, 2024
1 parent 211abd0 commit 9e84008
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace tsom

struct ServerEnvironmentSwitchComponent
{
void Switch(entt::handle entity, ServerEnvironment* previousEnvironment, ServerEnvironment* newEnvironment, const EnvironmentTransform& relativeTransform);
entt::handle Switch(entt::handle entity, ServerEnvironment* previousEnvironment, ServerEnvironment* newEnvironment, const EnvironmentTransform& relativeTransform);

std::function<void(entt::handle previousEntity, entt::handle newEntity, const EnvironmentTransform& /*relativeTransform*/)> handleEnvironmentSwitch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace tsom
{
void ServerEnvironmentSwitchComponent::Switch(entt::handle oldEntity, ServerEnvironment* previousEnvironment, ServerEnvironment* newEnvironment, const EnvironmentTransform& relativeTransform)
entt::handle ServerEnvironmentSwitchComponent::Switch(entt::handle oldEntity, ServerEnvironment* previousEnvironment, ServerEnvironment* newEnvironment, const EnvironmentTransform& relativeTransform)
{
// Disable old entity to not take it into account in the callbacks (for example when changing root environment)
oldEntity.emplace<Nz::DisabledComponent>();
Expand Down Expand Up @@ -53,5 +53,7 @@ namespace tsom
handleEnvironmentSwitch(oldEntity, newEntity, relativeTransform);
OnEntitySwitchedEnvironment(oldEntity, newEntity, newEnvironment, relativeTransform);
oldEntity.destroy();

return newEntity;
}
}
8 changes: 6 additions & 2 deletions src/ServerLib/ServerShipEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,13 @@ namespace tsom
// No longer colliding with the interior
auto& outsideNode = m_exteriorEntity.get<Nz::NodeComponent>();
EnvironmentTransform outsideTransform(outsideNode.GetPosition(), outsideNode.GetRotation());
Nz::Vector3f outsideVelocity = m_exteriorEntity.get<Nz::RigidBody3DComponent>().GetLinearVelocity();
Nz::Vector3f shipLinearVelocity = m_exteriorEntity.get<Nz::RigidBody3DComponent>().GetLinearVelocity();

controlledEntity.get<ServerEnvironmentSwitchComponent>().Switch(controlledEntity, this, m_exteriorEnvironment, outsideTransform);
controlledEntity = controlledEntity.get<ServerEnvironmentSwitchComponent>().Switch(controlledEntity, this, m_exteriorEnvironment, outsideTransform);
if (Nz::PhysCharacter3DComponent* controlledCharacter = controlledEntity.try_get<Nz::PhysCharacter3DComponent>())
controlledCharacter->AddLinearVelocity(shipLinearVelocity);
else if (Nz::RigidBody3DComponent* controlledRigidbody = controlledEntity.try_get<Nz::RigidBody3DComponent>())
controlledRigidbody->AddLinearVelocity(shipLinearVelocity);
});
}

Expand Down

0 comments on commit 9e84008

Please sign in to comment.