Remove deps from dNet (#1401)

This commit is contained in:
David Markowitz
2024-01-06 23:05:57 -08:00
committed by GitHub
parent 14c20fbd62
commit b683413a60
11 changed files with 411 additions and 496 deletions

View File

@@ -25,6 +25,7 @@
#include "eMissionTaskType.h"
#include "eTriggerEventType.h"
#include "eObjectBits.h"
#include "PositionUpdate.h"
//Component includes:
#include "Component.h"
@@ -2056,3 +2057,75 @@ uint8_t Entity::GetCollectibleID() const {
auto* collectible = GetComponent<CollectibleComponent>();
return collectible ? collectible->GetCollectibleId() : 0;
}
void Entity::ProcessPositionUpdate(PositionUpdate& update) {
if (!IsPlayer()) return;
auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
auto* possessorComponent = GetComponent<PossessorComponent>();
bool updateChar = true;
if (possessorComponent) {
auto* possassableEntity = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
if (possassableEntity) {
auto* possessableComponent = possassableEntity->GetComponent<PossessableComponent>();
// While possessing something, only update char if we are attached to the thing we are possessing
updateChar = possessableComponent && possessableComponent->GetPossessionType() == ePossessionType::ATTACHED_VISIBLE;
auto* havokVehiclePhysicsComponent = possassableEntity->GetComponent<HavokVehiclePhysicsComponent>();
if (havokVehiclePhysicsComponent) {
havokVehiclePhysicsComponent->SetPosition(update.position);
havokVehiclePhysicsComponent->SetRotation(update.rotation);
havokVehiclePhysicsComponent->SetIsOnGround(update.onGround);
havokVehiclePhysicsComponent->SetIsOnRail(update.onRail);
havokVehiclePhysicsComponent->SetVelocity(update.velocity);
havokVehiclePhysicsComponent->SetDirtyVelocity(update.velocity != NiPoint3::ZERO);
havokVehiclePhysicsComponent->SetAngularVelocity(update.angularVelocity);
havokVehiclePhysicsComponent->SetDirtyAngularVelocity(update.angularVelocity != NiPoint3::ZERO);
havokVehiclePhysicsComponent->SetRemoteInputInfo(update.remoteInputInfo);
} else {
// Need to get the mount's controllable physics
auto* possessedControllablePhysicsComponent = possassableEntity->GetComponent<ControllablePhysicsComponent>();
if (!possessedControllablePhysicsComponent) return;
possessedControllablePhysicsComponent->SetPosition(update.position);
possessedControllablePhysicsComponent->SetRotation(update.rotation);
possessedControllablePhysicsComponent->SetIsOnGround(update.onGround);
possessedControllablePhysicsComponent->SetIsOnRail(update.onRail);
possessedControllablePhysicsComponent->SetVelocity(update.velocity);
possessedControllablePhysicsComponent->SetDirtyVelocity(update.velocity != NiPoint3::ZERO);
possessedControllablePhysicsComponent->SetAngularVelocity(update.angularVelocity);
possessedControllablePhysicsComponent->SetDirtyAngularVelocity(update.angularVelocity != NiPoint3::ZERO);
}
Game::entityManager->SerializeEntity(possassableEntity);
}
}
if (!updateChar) {
update.velocity = NiPoint3::ZERO;
update.angularVelocity = NiPoint3::ZERO;
}
// Handle statistics
auto* characterComponent = GetComponent<CharacterComponent>();
if (characterComponent) {
characterComponent->TrackPositionUpdate(update.position);
}
controllablePhysicsComponent->SetPosition(update.position);
controllablePhysicsComponent->SetRotation(update.rotation);
controllablePhysicsComponent->SetIsOnGround(update.onGround);
controllablePhysicsComponent->SetIsOnRail(update.onRail);
controllablePhysicsComponent->SetVelocity(update.velocity);
controllablePhysicsComponent->SetDirtyVelocity(update.velocity != NiPoint3::ZERO);
controllablePhysicsComponent->SetAngularVelocity(update.angularVelocity);
controllablePhysicsComponent->SetDirtyAngularVelocity(update.angularVelocity != NiPoint3::ZERO);
auto* player = static_cast<Player*>(this);
player->SetGhostReferencePoint(update.position);
Game::entityManager->QueueGhostUpdate(player->GetObjectID());
if (updateChar) Game::entityManager->SerializeEntity(this);
}

View File

@@ -31,6 +31,7 @@ class Component;
class Item;
class Character;
class EntityCallbackTimer;
class PositionUpdate;
enum class eTriggerEventType;
enum class eGameMasterLevel : uint8_t;
enum class eReplicaComponentType : uint32_t;
@@ -296,6 +297,8 @@ public:
Entity* GetScheduledKiller() { return m_ScheduleKiller; }
void ProcessPositionUpdate(PositionUpdate& update);
protected:
LWOOBJID m_ObjectID;

View File

@@ -216,7 +216,52 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) {
chars.push_back(character);
}
WorldPackets::SendCharacterList(sysAddr, u);
RakNet::BitStream bitStream;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::CHARACTER_LIST_RESPONSE);
std::vector<Character*> characters = u->GetCharacters();
bitStream.Write<uint8_t>(characters.size());
bitStream.Write<uint8_t>(0); //TODO: Pick the most recent played index. character index in front, just picking 0
for (uint32_t i = 0; i < characters.size(); ++i) {
bitStream.Write(characters[i]->GetObjectID());
bitStream.Write<uint32_t>(0);
bitStream.Write(LUWString(characters[i]->GetName()));
bitStream.Write(LUWString(characters[i]->GetUnapprovedName()));
bitStream.Write<uint8_t>(characters[i]->GetNameRejected());
bitStream.Write<uint8_t>(false);
bitStream.Write(LUString("", 10));
bitStream.Write(characters[i]->GetShirtColor());
bitStream.Write(characters[i]->GetShirtStyle());
bitStream.Write(characters[i]->GetPantsColor());
bitStream.Write(characters[i]->GetHairStyle());
bitStream.Write(characters[i]->GetHairColor());
bitStream.Write(characters[i]->GetLeftHand());
bitStream.Write(characters[i]->GetRightHand());
bitStream.Write(characters[i]->GetEyebrows());
bitStream.Write(characters[i]->GetEyes());
bitStream.Write(characters[i]->GetMouth());
bitStream.Write<uint32_t>(0);
bitStream.Write<uint16_t>(characters[i]->GetZoneID());
bitStream.Write<uint16_t>(characters[i]->GetZoneInstance());
bitStream.Write(characters[i]->GetZoneClone());
bitStream.Write(characters[i]->GetLastLogin());
const auto& equippedItems = characters[i]->GetEquippedItems();
bitStream.Write<uint16_t>(equippedItems.size());
for (uint32_t j = 0; j < equippedItems.size(); ++j) {
bitStream.Write(equippedItems[j]);
}
}
SEND_PACKET;
}
void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) {
@@ -322,7 +367,7 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::SUCCESS);
UserManager::RequestCharacterList(sysAddr);
});
});
}
void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet) {

View File

@@ -4,31 +4,7 @@
#include "Entity.h"
#include "PhysicsComponent.h"
#include "eReplicaComponentType.h"
struct RemoteInputInfo {
RemoteInputInfo() {
m_RemoteInputX = 0;
m_RemoteInputY = 0;
m_IsPowersliding = false;
m_IsModified = false;
}
void operator=(const RemoteInputInfo& other) {
m_RemoteInputX = other.m_RemoteInputX;
m_RemoteInputY = other.m_RemoteInputY;
m_IsPowersliding = other.m_IsPowersliding;
m_IsModified = other.m_IsModified;
}
bool operator==(const RemoteInputInfo& other) {
return m_RemoteInputX == other.m_RemoteInputX && m_RemoteInputY == other.m_RemoteInputY && m_IsPowersliding == other.m_IsPowersliding && m_IsModified == other.m_IsModified;
}
float m_RemoteInputX;
float m_RemoteInputY;
bool m_IsPowersliding;
bool m_IsModified;
};
#include "PositionUpdate.h"
/**
* Physics component for vehicles.