mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-24 06:27:24 +00:00
fix: laggy property models (and probably more) (#1646)
* fix laggy property models (and probably more) global fix correcting the initial physics motion state from 0 to 5 (confirm in client). packet captures from a few worlds (didnt scan more than 5 files) show that the value for simple physics was either 5, or 4 for property models, or 1 for property models with behaviors. properties with pre-built models no longer lag and values of physics types should be correct across the board * will test this briefly
This commit is contained in:
parent
c7dd8205a4
commit
112c2367cc
@ -7,6 +7,7 @@
|
|||||||
#include "BehaviorStates.h"
|
#include "BehaviorStates.h"
|
||||||
#include "ControlBehaviorMsgs.h"
|
#include "ControlBehaviorMsgs.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
#include "SimplePhysicsComponent.h"
|
||||||
|
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
|
|
||||||
@ -95,12 +96,24 @@ void ModelComponent::AddBehavior(AddMessage& msg) {
|
|||||||
for (auto& behavior : m_Behaviors) if (behavior.GetBehaviorId() == msg.GetBehaviorId()) return;
|
for (auto& behavior : m_Behaviors) if (behavior.GetBehaviorId() == msg.GetBehaviorId()) return;
|
||||||
m_Behaviors.insert(m_Behaviors.begin() + msg.GetBehaviorIndex(), PropertyBehavior());
|
m_Behaviors.insert(m_Behaviors.begin() + msg.GetBehaviorIndex(), PropertyBehavior());
|
||||||
m_Behaviors.at(msg.GetBehaviorIndex()).HandleMsg(msg);
|
m_Behaviors.at(msg.GetBehaviorIndex()).HandleMsg(msg);
|
||||||
|
auto* const simplePhysComponent = m_Parent->GetComponent<SimplePhysicsComponent>();
|
||||||
|
if (simplePhysComponent) {
|
||||||
|
simplePhysComponent->SetPhysicsMotionState(1);
|
||||||
|
Game::entityManager->SerializeEntity(m_Parent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelComponent::MoveToInventory(MoveToInventoryMessage& msg) {
|
void ModelComponent::MoveToInventory(MoveToInventoryMessage& msg) {
|
||||||
if (msg.GetBehaviorIndex() >= m_Behaviors.size() || m_Behaviors.at(msg.GetBehaviorIndex()).GetBehaviorId() != msg.GetBehaviorId()) return;
|
if (msg.GetBehaviorIndex() >= m_Behaviors.size() || m_Behaviors.at(msg.GetBehaviorIndex()).GetBehaviorId() != msg.GetBehaviorId()) return;
|
||||||
m_Behaviors.erase(m_Behaviors.begin() + msg.GetBehaviorIndex());
|
m_Behaviors.erase(m_Behaviors.begin() + msg.GetBehaviorIndex());
|
||||||
// TODO move to the inventory
|
// TODO move to the inventory
|
||||||
|
if (m_Behaviors.empty()) {
|
||||||
|
auto* const simplePhysComponent = m_Parent->GetComponent<SimplePhysicsComponent>();
|
||||||
|
if (simplePhysComponent) {
|
||||||
|
simplePhysComponent->SetPhysicsMotionState(4);
|
||||||
|
Game::entityManager->SerializeEntity(m_Parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<std::pair<int32_t, std::string>, 5> ModelComponent::GetBehaviorsForSave() const {
|
std::array<std::pair<int32_t, std::string>, 5> ModelComponent::GetBehaviorsForSave() const {
|
||||||
|
@ -27,6 +27,7 @@ SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, uint32_t componen
|
|||||||
} else {
|
} else {
|
||||||
SetClimbableType(eClimbableType::CLIMBABLE_TYPE_NOT);
|
SetClimbableType(eClimbableType::CLIMBABLE_TYPE_NOT);
|
||||||
}
|
}
|
||||||
|
m_PhysicsMotionState = m_Parent->GetVarAs<uint32_t>(u"motionType");
|
||||||
}
|
}
|
||||||
|
|
||||||
SimplePhysicsComponent::~SimplePhysicsComponent() {
|
SimplePhysicsComponent::~SimplePhysicsComponent() {
|
||||||
@ -47,11 +48,10 @@ void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIs
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Physics motion state
|
// Physics motion state
|
||||||
if (m_PhysicsMotionState != 0) {
|
outBitStream.Write(m_DirtyPhysicsMotionState || bIsInitialUpdate);
|
||||||
outBitStream.Write1();
|
if (m_DirtyPhysicsMotionState || bIsInitialUpdate) {
|
||||||
outBitStream.Write<uint32_t>(m_PhysicsMotionState);
|
outBitStream.Write<uint32_t>(m_PhysicsMotionState);
|
||||||
} else {
|
m_DirtyPhysicsMotionState = false;
|
||||||
outBitStream.Write0();
|
|
||||||
}
|
}
|
||||||
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
|
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
|
||||||
}
|
}
|
||||||
@ -61,5 +61,6 @@ uint32_t SimplePhysicsComponent::GetPhysicsMotionState() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SimplePhysicsComponent::SetPhysicsMotionState(uint32_t value) {
|
void SimplePhysicsComponent::SetPhysicsMotionState(uint32_t value) {
|
||||||
|
m_DirtyPhysicsMotionState = m_PhysicsMotionState != value;
|
||||||
m_PhysicsMotionState = value;
|
m_PhysicsMotionState = value;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,9 @@ private:
|
|||||||
/**
|
/**
|
||||||
* The current physics motion state
|
* The current physics motion state
|
||||||
*/
|
*/
|
||||||
uint32_t m_PhysicsMotionState = 0;
|
uint32_t m_PhysicsMotionState = 5;
|
||||||
|
|
||||||
|
bool m_DirtyPhysicsMotionState = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the entity is climbable
|
* Whether or not the entity is climbable
|
||||||
|
@ -61,6 +61,7 @@ void SGCannon::OnStartup(Entity* self) {
|
|||||||
if (simplePhysicsComponent != nullptr) {
|
if (simplePhysicsComponent != nullptr) {
|
||||||
simplePhysicsComponent->SetPhysicsMotionState(5);
|
simplePhysicsComponent->SetPhysicsMotionState(5);
|
||||||
}
|
}
|
||||||
|
Game::entityManager->SerializeEntity(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SGCannon::OnPlayerLoaded(Entity* self, Entity* player) {
|
void SGCannon::OnPlayerLoaded(Entity* self, Entity* player) {
|
||||||
|
Loading…
Reference in New Issue
Block a user