![]() |
Botcraft 1.21.10
|
#include <PhysicsManager.hpp>
Public Member Functions | |
PhysicsManager ()=delete | |
PhysicsManager (const std::shared_ptr< Renderer::RenderingManager > &rendering_manager_, const std::shared_ptr< InventoryManager > &inventory_manager_, const std::shared_ptr< EntityManager > &entity_manager_, const std::shared_ptr< NetworkManager > &network_manager_, const std::shared_ptr< World > &world_) | |
~PhysicsManager () | |
void | StartPhysics () |
void | StopPhysics () |
void | SetDoubleTapCauseSprint (const bool b) |
Enable/disable auto triggering of sprint when press/unpress/press forward key in less than 7 ticks (enabled by default) | |
double | GetMsPerTick () const |
Protected Member Functions | |
virtual void | Handle (ProtocolCraft::ClientboundLoginPacket &packet) override |
virtual void | Handle (ProtocolCraft::ClientboundPlayerPositionPacket &packet) override |
virtual void | Handle (ProtocolCraft::ClientboundTickingStatePacket &packet) override |
virtual void | Handle (ProtocolCraft::ClientboundPlayerRotationPacket &packet) override |
Private Member Functions | |
void | Physics () |
void | PhysicsTick () |
Follow minecraft physics related flow in LocalPlayer tick function. | |
void | UpdateSwimming () const |
void | FluidPhysics (const bool water) |
Perform fluid physics on the player, and set in_water/lava boolean accordingly. | |
void | InputsToCrouch () const |
void | InputsToSprint () const |
void | SetSprinting (const bool b) const |
void | InputsToFly () const |
void | InputsToJump () const |
void | ApplyInputs (const float strength) const |
void | SendPosition () |
Send position/rotation/on_ground to server. | |
Vector3< double > | CollideBoundingBox (const AABB &aabb, const Vector3< double > &movement) const |
Check collisions of an AABB with a given movement. | |
void | CollideOneAxis (AABB &aabb, Vector3< double > &movement, const unsigned int axis, const std::vector< AABB > &colliders) const |
bool | IsSwimmingAndNotFlying () const |
bool | IsInClimbable () const |
void | MovePlayer () const |
void | ApplyMovement () const |
void | OnUpdateAbilities () const |
void | CheckInsideBlocks () const |
Position | GetBlockBelowAffectingMovement () const |
Private Attributes | |
std::shared_ptr< Renderer::RenderingManager > | rendering_manager |
std::shared_ptr< EntityManager > | entity_manager |
std::shared_ptr< InventoryManager > | inventory_manager |
std::shared_ptr< LocalPlayer > | player |
std::shared_ptr< NetworkManager > | network_manager |
std::shared_ptr< World > | world |
std::atomic< bool > | should_run |
std::optional< int > | teleport_id |
int | ticks_since_last_position_sent |
std::thread | thread_physics |
const Item * | elytra_item |
std::atomic< double > | ms_per_tick = 50.0 |
std::atomic< bool > | double_tap_cause_sprint |
Definition at line 30 of file PhysicsManager.hpp.
|
delete |
Botcraft::PhysicsManager::PhysicsManager | ( | const std::shared_ptr< Renderer::RenderingManager > & | rendering_manager_, |
const std::shared_ptr< InventoryManager > & | inventory_manager_, | ||
const std::shared_ptr< EntityManager > & | entity_manager_, | ||
const std::shared_ptr< NetworkManager > & | network_manager_, | ||
const std::shared_ptr< World > & | world_ | ||
) |
Definition at line 22 of file PhysicsManager.cpp.
References double_tap_cause_sprint, elytra_item, entity_manager, Botcraft::AssetsManager::getInstance(), Botcraft::AssetsManager::GetItem(), inventory_manager, network_manager, player, rendering_manager, should_run, teleport_id, ticks_since_last_position_sent, and world.
Botcraft::PhysicsManager::~PhysicsManager | ( | ) |
Definition at line 52 of file PhysicsManager.cpp.
References StopPhysics().
|
private |
Definition at line 918 of file PhysicsManager.cpp.
References Botcraft::Vector3< T >::Normalize(), player, Botcraft::Vector3< T >::SqrNorm(), Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.
Referenced by MovePlayer().
|
private |
Definition at line 1383 of file PhysicsManager.cpp.
References Botcraft::Vector3< T >::Abs(), CheckInsideBlocks(), CollideBoundingBox(), GetBlockBelowAffectingMovement(), Botcraft::AABB::GetCenter(), Botcraft::Utilities::GetEnchantmentLvl(), Botcraft::AABB::GetHalfSize(), Botcraft::Window::INVENTORY_FEET_ARMOR, inventory_manager, Botcraft::Blockstate::IsBed(), Botcraft::Blockstate::IsHoney(), Botcraft::Blockstate::IsSlime(), Botcraft::Blockstate::IsSoulSand(), player, Botcraft::SoulSpeed, Botcraft::Spectator, Botcraft::Vector3< T >::SqrNorm(), world, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.
Referenced by MovePlayer().
|
private |
Definition at line 1593 of file PhysicsManager.cpp.
References Botcraft::AABB::GetMax(), Botcraft::AABB::GetMin(), Botcraft::AABB::Inflate(), Botcraft::Blockstate::IsAir(), Botcraft::Blockstate::IsBerryBush(), Botcraft::Blockstate::IsBubbleColumn(), Botcraft::Blockstate::IsCobweb(), Botcraft::Blockstate::IsDownBubbleColumn(), Botcraft::Blockstate::IsHoney(), Botcraft::Blockstate::IsPowderSnow(), player, world, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.
Referenced by ApplyMovement().
|
private |
Check collisions of an AABB with a given movement.
Definition at line 1086 of file PhysicsManager.cpp.
References CollideOneAxis(), world, Botcraft::Vector3< T >::x, and Botcraft::Vector3< T >::z.
Referenced by ApplyMovement().
|
private |
Definition at line 1117 of file PhysicsManager.cpp.
References Botcraft::AABB::GetMax(), Botcraft::AABB::GetMin(), and Botcraft::AABB::Translate().
Referenced by CollideBoundingBox().
|
private |
Perform fluid physics on the player, and set in_water/lava boolean accordingly.
water | If true, will push with water, lava otherwise |
Definition at line 524 of file PhysicsManager.cpp.
References Botcraft::Blockstate::GetFluidHeight(), Botcraft::AABB::GetMax(), Botcraft::AABB::GetMin(), Botcraft::AABB::Inflate(), Botcraft::Blockstate::IsFluid(), Botcraft::Blockstate::IsLava(), Botcraft::Blockstate::IsWater(), player, Botcraft::Vector3< T >::SqrNorm(), world, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.
Referenced by PhysicsTick().
|
private |
Definition at line 1673 of file PhysicsManager.cpp.
References player, and Botcraft::Vector3< T >::y.
Referenced by ApplyMovement(), InputsToJump(), and MovePlayer().
double Botcraft::PhysicsManager::GetMsPerTick | ( | ) | const |
Definition at line 85 of file PhysicsManager.cpp.
References ms_per_tick.
|
overrideprotectedvirtual |
Definition at line 91 of file PhysicsManager.cpp.
References entity_manager, and player.
|
overrideprotectedvirtual |
Definition at line 108 of file PhysicsManager.cpp.
References LOG_WARNING, player, teleport_id, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.
|
overrideprotectedvirtual |
Definition at line 215 of file PhysicsManager.cpp.
References LOG_WARNING, and player.
|
overrideprotectedvirtual |
Definition at line 199 of file PhysicsManager.cpp.
References ms_per_tick.
|
private |
Definition at line 635 of file PhysicsManager.cpp.
References Botcraft::Blindness, Botcraft::Crouching, Botcraft::FallFlying, Botcraft::Utilities::GetEnchantmentLvl(), Botcraft::Window::INVENTORY_LEGS_ARMOR, inventory_manager, IsSwimmingAndNotFlying(), player, SetSprinting(), Botcraft::Standing, Botcraft::SwiftSneak, Botcraft::Swimming, and world.
Referenced by PhysicsTick().
|
private |
Definition at line 779 of file PhysicsManager.cpp.
References elytra_item, Botcraft::FallFlying, Botcraft::Utilities::GetDamageCount(), Botcraft::Item::GetId(), Botcraft::Item::GetMaxDurability(), Botcraft::Window::INVENTORY_CHEST_ARMOR, inventory_manager, ProtocolCraft::Slot::IsEmptySlot(), IsSwimmingAndNotFlying(), Botcraft::Levitation, network_manager, OnUpdateAbilities(), player, Botcraft::Spectator, and Botcraft::StartFallFlying.
Referenced by PhysicsTick().
|
private |
Definition at line 844 of file PhysicsManager.cpp.
References GetBlockBelowAffectingMovement(), Botcraft::Blockstate::IsHoney(), Botcraft::JumpBoost, player, Botcraft::Sprinting, and world.
Referenced by PhysicsTick().
|
private |
Definition at line 691 of file PhysicsManager.cpp.
References Botcraft::Blindness, double_tap_cause_sprint, Botcraft::FallFlying, IsSwimmingAndNotFlying(), player, SetSprinting(), Botcraft::Sprinting, and Botcraft::Swimming.
Referenced by PhysicsTick().
|
private |
Definition at line 1159 of file PhysicsManager.cpp.
References Botcraft::Blockstate::IsClimbable(), player, Botcraft::Spectator, and world.
Referenced by PhysicsTick().
|
private |
Definition at line 1152 of file PhysicsManager.cpp.
References player, Botcraft::Spectator, and Botcraft::Swimming.
Referenced by InputsToCrouch(), InputsToFly(), InputsToSprint(), and PhysicsTick().
|
private |
Definition at line 1177 of file PhysicsManager.cpp.
References ApplyInputs(), ApplyMovement(), Botcraft::DepthStrider, Botcraft::DolphinsGrace, Botcraft::FallFlying, GetBlockBelowAffectingMovement(), Botcraft::Utilities::GetEnchantmentLvl(), Botcraft::Blockstate::GetFriction(), Botcraft::Window::INVENTORY_FEET_ARMOR, inventory_manager, Botcraft::Blockstate::IsScaffolding(), Botcraft::Levitation, player, Botcraft::SlowFalling, Botcraft::Sprinting, and world.
Referenced by PhysicsTick().
|
private |
Definition at line 1581 of file PhysicsManager.cpp.
References network_manager, and player.
Referenced by InputsToFly(), and PhysicsTick().
|
private |
Definition at line 236 of file PhysicsManager.cpp.
References Botcraft::Logger::GetInstance(), ms_per_tick, network_manager, PhysicsTick(), player, Botcraft::Logger::RegisterThread(), should_run, Botcraft::Utilities::SleepUntil(), and teleport_id.
Referenced by StartPhysics().
|
private |
Follow minecraft physics related flow in LocalPlayer tick function.
Definition at line 294 of file PhysicsManager.cpp.
References Botcraft::Crouching, entity_manager, Botcraft::FallFlying, Botcraft::FireworkRocketEntity, FluidPhysics(), InputsToCrouch(), InputsToFly(), InputsToJump(), InputsToSprint(), Botcraft::Blockstate::IsFluid(), IsInClimbable(), IsSwimmingAndNotFlying(), MovePlayer(), OnUpdateAbilities(), player, SendPosition(), Botcraft::Sleeping, Botcraft::Spectator, Botcraft::Entity::speed, Botcraft::SpinAttack, Botcraft::Standing, Botcraft::Swimming, UpdateSwimming(), and world.
Referenced by Physics().
|
private |
Send position/rotation/on_ground to server.
Definition at line 939 of file PhysicsManager.cpp.
References network_manager, player, rendering_manager, Botcraft::Sprinting, Botcraft::StartSprinting, Botcraft::StopSprinting, and ticks_since_last_position_sent.
Referenced by PhysicsTick().
void Botcraft::PhysicsManager::SetDoubleTapCauseSprint | ( | const bool | b | ) |
Enable/disable auto triggering of sprint when press/unpress/press forward key in less than 7 ticks (enabled by default)
b | Double tap will start sprinting if b is true |
Definition at line 74 of file PhysicsManager.cpp.
References double_tap_cause_sprint, and player.
|
private |
Definition at line 764 of file PhysicsManager.cpp.
References Botcraft::EntityAttribute::MovementSpeed, Botcraft::EntityAttribute::Modifier::MultiplyTotal, player, Botcraft::LivingEntity::speed_modifier_sprinting_key, and Botcraft::Sprinting.
Referenced by InputsToCrouch(), and InputsToSprint().
void Botcraft::PhysicsManager::StartPhysics | ( | ) |
Definition at line 57 of file PhysicsManager.cpp.
References Physics(), should_run, and thread_physics.
void Botcraft::PhysicsManager::StopPhysics | ( | ) |
Definition at line 65 of file PhysicsManager.cpp.
References should_run, and thread_physics.
Referenced by ~PhysicsManager().
|
private |
Definition at line 494 of file PhysicsManager.cpp.
References Botcraft::Blockstate::IsWater(), player, Botcraft::Sprinting, Botcraft::Swimming, and world.
Referenced by PhysicsTick().
|
private |
Definition at line 125 of file PhysicsManager.hpp.
Referenced by InputsToSprint(), PhysicsManager(), and SetDoubleTapCauseSprint().
|
private |
Definition at line 117 of file PhysicsManager.hpp.
Referenced by InputsToFly(), and PhysicsManager().
|
private |
Definition at line 104 of file PhysicsManager.hpp.
Referenced by Handle(), PhysicsManager(), and PhysicsTick().
|
private |
Definition at line 105 of file PhysicsManager.hpp.
Referenced by ApplyMovement(), InputsToCrouch(), InputsToFly(), MovePlayer(), and PhysicsManager().
|
private |
Definition at line 120 of file PhysicsManager.hpp.
Referenced by GetMsPerTick(), Handle(), and Physics().
|
private |
Definition at line 107 of file PhysicsManager.hpp.
Referenced by InputsToFly(), OnUpdateAbilities(), Physics(), PhysicsManager(), and SendPosition().
|
private |
Definition at line 106 of file PhysicsManager.hpp.
Referenced by ApplyInputs(), ApplyMovement(), CheckInsideBlocks(), FluidPhysics(), GetBlockBelowAffectingMovement(), Handle(), Handle(), Handle(), InputsToCrouch(), InputsToFly(), InputsToJump(), InputsToSprint(), IsInClimbable(), IsSwimmingAndNotFlying(), MovePlayer(), OnUpdateAbilities(), Physics(), PhysicsManager(), PhysicsTick(), SendPosition(), SetDoubleTapCauseSprint(), SetSprinting(), and UpdateSwimming().
|
private |
Definition at line 102 of file PhysicsManager.hpp.
Referenced by PhysicsManager(), and SendPosition().
|
private |
Definition at line 110 of file PhysicsManager.hpp.
Referenced by Physics(), PhysicsManager(), StartPhysics(), and StopPhysics().
|
private |
Definition at line 111 of file PhysicsManager.hpp.
Referenced by Handle(), Physics(), and PhysicsManager().
|
private |
Definition at line 115 of file PhysicsManager.hpp.
Referenced by StartPhysics(), and StopPhysics().
|
private |
Definition at line 113 of file PhysicsManager.hpp.
Referenced by PhysicsManager(), and SendPosition().
|
private |
Definition at line 108 of file PhysicsManager.hpp.
Referenced by ApplyMovement(), CheckInsideBlocks(), CollideBoundingBox(), FluidPhysics(), InputsToCrouch(), InputsToJump(), IsInClimbable(), MovePlayer(), PhysicsManager(), PhysicsTick(), and UpdateSwimming().