Skip to content

Commit

Permalink
Revert "added debugoutput for inventory events"
Browse files Browse the repository at this point in the history
This reverts commit 2f5c591.

reverted some auto formatting
  • Loading branch information
JoBloess committed Dec 26, 2020
1 parent 2f5c591 commit 2ec1aa4
Showing 1 changed file with 66 additions and 74 deletions.
140 changes: 66 additions & 74 deletions Code/client/src/Services/Generic/CharacterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,69 @@
#include "Forms/TESWorldSpace.h"
#include "Messages/CharacterTravelRequest.h"


#include <Services/CharacterService.h>
#include <Services/QuestService.h>
#include <Services/TransportService.h>
#include <Services/QuestService.h>

#include <Games/References.h>

#include <ExtraData/ExtraLeveledCreature.h>
#include <Forms/TESNPC.h>
#include <Forms/TESQuest.h>
#include <ExtraData/ExtraLeveledCreature.h>

#include <Components.h>

#include <Systems/InterpolationSystem.h>
#include <Systems/AnimationSystem.h>
#include <Systems/CacheSystem.h>
#include <Systems/FaceGenSystem.h>
#include <Systems/InterpolationSystem.h>
#include <Systems/CacheSystem.h>

#include <Events/UpdateEvent.h>
#include <Events/ConnectedEvent.h>
#include <Events/DisconnectedEvent.h>
#include <Events/EquipmentChangeEvent.h>
#include <Events/UpdateEvent.h>

#include <Structs/ActionEvent.h>
#include <Messages/CancelAssignmentRequest.h>
#include <Messages/RemoveCharacterRequest.h>
#include <Messages/AssignCharacterRequest.h>
#include <Messages/AssignCharacterResponse.h>
#include <Messages/CancelAssignmentRequest.h>
#include <Messages/CharacterSpawnRequest.h>
#include <Messages/ServerReferencesMoveRequest.h>
#include <Messages/ClientReferencesMoveRequest.h>
#include <Messages/NotifyCharacterTravel.h>
#include <Messages/NotifyFactionsChanges.h>
#include <Messages/CharacterSpawnRequest.h>
#include <Messages/RequestInventoryChanges.h>
#include <Messages/RequestFactionsChanges.h>
#include <Messages/NotifyInventoryChanges.h>
#include <Messages/NotifyFactionsChanges.h>
#include <Messages/NotifyRemoveCharacter.h>
#include <Messages/RemoveCharacterRequest.h>
#include <Messages/RequestFactionsChanges.h>
#include <Messages/RequestInventoryChanges.h>
#include <Messages/ServerReferencesMoveRequest.h>
#include <Structs/ActionEvent.h>
#include <Messages/NotifyCharacterTravel.h>

#include <World.h>


CharacterService::CharacterService(World& aWorld, entt::dispatcher& aDispatcher, TransportService& aTransport) noexcept
: m_world(aWorld), m_dispatcher(aDispatcher), m_transport(aTransport)
: m_world(aWorld)
, m_dispatcher(aDispatcher)
, m_transport(aTransport)
{
m_formIdAddedConnection =
m_world.on_construct<FormIdComponent>().connect<&CharacterService::OnFormIdComponentAdded>(this);
m_formIdRemovedConnection =
m_world.on_destroy<FormIdComponent>().connect<&CharacterService::OnFormIdComponentRemoved>(this);
m_formIdAddedConnection = m_world.on_construct<FormIdComponent>().connect<&CharacterService::OnFormIdComponentAdded>(this);
m_formIdRemovedConnection = m_world.on_destroy<FormIdComponent>().connect<&CharacterService::OnFormIdComponentRemoved>(this);

m_updateConnection = m_dispatcher.sink<UpdateEvent>().connect<&CharacterService::OnUpdate>(this);
m_actionConnection = m_dispatcher.sink<ActionEvent>().connect<&CharacterService::OnActionEvent>(this);

m_connectedConnection = m_dispatcher.sink<ConnectedEvent>().connect<&CharacterService::OnConnected>(this);
m_disconnectedConnection = m_dispatcher.sink<DisconnectedEvent>().connect<&CharacterService::OnDisconnected>(this);

m_assignCharacterConnection =
m_dispatcher.sink<AssignCharacterResponse>().connect<&CharacterService::OnAssignCharacter>(this);
m_characterSpawnConnection =
m_dispatcher.sink<CharacterSpawnRequest>().connect<&CharacterService::OnCharacterSpawn>(this);
m_referenceMovementSnapshotConnection =
m_dispatcher.sink<ServerReferencesMoveRequest>().connect<&CharacterService::OnReferencesMoveRequest>(this);
m_equipmentConnection =
m_dispatcher.sink<EquipmentChangeEvent>().connect<&CharacterService::OnEquipmentChangeEvent>(this);
m_inventoryConnection =
m_dispatcher.sink<NotifyInventoryChanges>().connect<&CharacterService::OnInventoryChanges>(this);
m_factionsConnection =
m_dispatcher.sink<NotifyFactionsChanges>().connect<&CharacterService::OnFactionsChanges>(this);
m_removeCharacterConnection =
m_dispatcher.sink<NotifyRemoveCharacter>().connect<&CharacterService::OnRemoveCharacter>(this);
m_characterTravelConnection =
m_dispatcher.sink<NotifyCharacterTravel>().connect<&CharacterService::OnCharacterTravel>(this);
m_assignCharacterConnection = m_dispatcher.sink<AssignCharacterResponse>().connect<&CharacterService::OnAssignCharacter>(this);
m_characterSpawnConnection = m_dispatcher.sink<CharacterSpawnRequest>().connect<&CharacterService::OnCharacterSpawn>(this);
m_referenceMovementSnapshotConnection = m_dispatcher.sink<ServerReferencesMoveRequest>().connect<&CharacterService::OnReferencesMoveRequest>(this);
m_equipmentConnection = m_dispatcher.sink<EquipmentChangeEvent>().connect<&CharacterService::OnEquipmentChangeEvent>(this);
m_inventoryConnection = m_dispatcher.sink<NotifyInventoryChanges>().connect<&CharacterService::OnInventoryChanges>(this);
m_factionsConnection = m_dispatcher.sink<NotifyFactionsChanges>().connect<&CharacterService::OnFactionsChanges>(this);
m_removeCharacterConnection = m_dispatcher.sink<NotifyRemoveCharacter>().connect<&CharacterService::OnRemoveCharacter>(this);
m_characterTravelConnection = m_dispatcher.sink<NotifyCharacterTravel>().connect<&CharacterService::OnCharacterTravel>(this);
}

void CharacterService::OnFormIdComponentAdded(entt::registry& aRegistry, const entt::entity aEntity) const noexcept
Expand All @@ -96,24 +90,22 @@ void CharacterService::OnFormIdComponentAdded(entt::registry& aRegistry, const e
pActor->SetInventory(pRemoteComponent->SpawnRequest.InventoryContent);
}

if (aRegistry.has<RemoteComponent>(aEntity) || aRegistry.has<LocalComponent>(aEntity) ||
aRegistry.has<WaitingForAssignmentComponent>(aEntity))
if (aRegistry.has<RemoteComponent>(aEntity) || aRegistry.has<LocalComponent>(aEntity) || aRegistry.has<WaitingForAssignmentComponent>(aEntity))
return;

CacheSystem::Setup(World::Get(), aEntity, pActor);

auto* const pNpc = RTTI_CAST(pActor->baseForm, TESForm, TESNPC);

auto* pExtra =
static_cast<ExtraLeveledCreature*>(pActor->GetExtraDataList()->GetByType(ExtraData::LeveledCreature));
auto* pExtra = static_cast<ExtraLeveledCreature*>(pActor->GetExtraDataList()->GetByType(ExtraData::LeveledCreature));

auto* const pOwner = pNpc->actorData.owner;
if (pOwner)
{
// spdlog::info("\tOwner: type {}, id {:X}", static_cast<uint32_t>(pOwner->formType), pOwner->formID);
// spdlog::info("\tOwner: type {}, id {:X}", static_cast<uint32_t>(pOwner->formType), pOwner->formID);
}

if (pNpc)
if(pNpc)
{
RequestServerAssignment(aRegistry, aEntity);
}
Expand All @@ -137,7 +129,7 @@ void CharacterService::OnUpdate(const UpdateEvent& acUpdateEvent) noexcept

void CharacterService::OnConnected(const ConnectedEvent& acConnectedEvent) const noexcept
{
// m_world.clear<WaitingForAssignmentComponent, LocalComponent, RemoteComponent>();
//m_world.clear<WaitingForAssignmentComponent, LocalComponent, RemoteComponent>();

// Go through all the forms that were previously detected
auto view = m_world.view<FormIdComponent>();
Expand Down Expand Up @@ -167,7 +159,8 @@ void CharacterService::OnAssignCharacter(const AssignCharacterResponse& acMessag
spdlog::info("Received for cookie {:X}", acMessage.Cookie);

auto view = m_world.view<WaitingForAssignmentComponent>();
const auto itor = std::find_if(std::begin(view), std::end(view), [view, cookie = acMessage.Cookie](auto entity) {
const auto itor = std::find_if(std::begin(view), std::end(view), [view, cookie = acMessage.Cookie](auto entity)
{
return view.get(entity).Cookie == cookie;
});

Expand Down Expand Up @@ -226,7 +219,7 @@ void CharacterService::OnCharacterSpawn(const CharacterSpawnRequest& acMessage)
if (acMessage.BaseId != GameId{})
{
const auto cNpcId = World::Get().GetModSystem().GetGameId(acMessage.BaseId);
if (cNpcId == 0)
if(cNpcId == 0)
{
spdlog::error("Failed to retrieve NPC, it will not be spawned, possibly missing mod");
return;
Expand Down Expand Up @@ -296,7 +289,8 @@ void CharacterService::OnReferencesMoveRequest(const ServerReferencesMoveRequest

for (const auto& [serverId, update] : acMessage.Updates)
{
auto itor = std::find_if(std::begin(view), std::end(view), [serverId = serverId, view](entt::entity entity) {
auto itor = std::find_if(std::begin(view), std::end(view), [serverId = serverId, view](entt::entity entity)
{
return view.get<RemoteComponent>(entity).Id == serverId;
});

Expand Down Expand Up @@ -327,12 +321,12 @@ void CharacterService::OnActionEvent(const ActionEvent& acActionEvent) const noe
{
auto view = m_world.view<LocalAnimationComponent, FormIdComponent>();

const auto itor =
std::find_if(std::begin(view), std::end(view), [id = acActionEvent.ActorId, view](entt::entity entity) {
return view.get<FormIdComponent>(entity).Id == id;
});
const auto itor = std::find_if(std::begin(view), std::end(view), [id = acActionEvent.ActorId, view](entt::entity entity)
{
return view.get<FormIdComponent>(entity).Id == id;
});

if (itor != std::end(view))
if(itor != std::end(view))
{
auto& localComponent = view.get<LocalAnimationComponent>(*itor);

Expand All @@ -352,7 +346,8 @@ void CharacterService::OnInventoryChanges(const NotifyInventoryChanges& acEvent)

for (const auto& [id, inventory] : acEvent.Changes)
{
const auto itor = std::find_if(std::begin(view), std::end(view), [id = id, view](entt::entity entity) {
const auto itor = std::find_if(std::begin(view), std::end(view), [id = id, view](entt::entity entity)
{
return view.get<RemoteComponent>(entity).Id == id;
});

Expand All @@ -377,7 +372,8 @@ void CharacterService::OnFactionsChanges(const NotifyFactionsChanges& acEvent) c

for (const auto& [id, factions] : acEvent.Changes)
{
const auto itor = std::find_if(std::begin(view), std::end(view), [id = id, view](entt::entity entity) {
const auto itor = std::find_if(std::begin(view), std::end(view), [id = id, view](entt::entity entity)
{
return view.get<RemoteComponent>(entity).Id == id;
});

Expand All @@ -401,8 +397,7 @@ void CharacterService::OnRemoveCharacter(const NotifyRemoveCharacter& acEvent) c
{
auto view = m_world.view<RemoteComponent>();

const auto itor =
std::find_if(std::begin(view), std::end(view), [id = acEvent.ServerId, view](entt::entity entity) {
const auto itor = std::find_if(std::begin(view), std::end(view), [id = acEvent.ServerId, view](entt::entity entity) {
return view.get<RemoteComponent>(entity).Id == id;
});

Expand All @@ -411,7 +406,7 @@ void CharacterService::OnRemoveCharacter(const NotifyRemoveCharacter& acEvent) c
if (auto* pFormIdComponent = m_world.try_get<FormIdComponent>(*itor))
{
spdlog::info("\tformid: {:X}", pFormIdComponent->Id);

const auto pActor = RTTI_CAST(TESForm::GetById(pFormIdComponent->Id), TESForm, Actor);
if (!pActor)
return;
Expand Down Expand Up @@ -491,21 +486,21 @@ void CharacterService::RequestServerAssignment(entt::registry& aRegistry, const
message.CellId.ModId = cellModId;

message.Position = pActor->position;
message.Rotation.X = pActor->rotation.m_x;
message.Rotation.X= pActor->rotation.m_x;
message.Rotation.Y = pActor->rotation.m_z;

// Serialize the base form
const auto isPlayer = (formIdComponent.Id == 0x14);
const auto isTemporary = pActor->formID >= 0xFF000000;

if (isPlayer)
if(isPlayer)
{
pNpc->MarkChanged(0x2000800);
}

const auto changeFlags = pNpc->GetChangeFlags();

if (isPlayer || pNpc->formID >= 0xFF000000 || changeFlags != 0)
if(isPlayer || pNpc->formID >= 0xFF000000 || changeFlags != 0)
{
message.ChangeFlags = changeFlags;
pNpc->Serialize(&message.AppearanceBuffer);
Expand All @@ -526,7 +521,7 @@ void CharacterService::RequestServerAssignment(entt::registry& aRegistry, const
entries[i].Color = tints[i]->color;
entries[i].Type = tints[i]->type;

if (tints[i]->texture)
if(tints[i]->texture)
entries[i].Name = tints[i]->texture->name.AsAscii();
}
}
Expand Down Expand Up @@ -564,7 +559,7 @@ void CharacterService::RequestServerAssignment(entt::registry& aRegistry, const
message.InventoryContent = pActor->GetInventory();
message.FactionsContent = pActor->GetFactions();

if (isTemporary)
if(isTemporary)
{
if (!World::Get().GetModSystem().GetServerModId(pNpc->formID, message.FormId))
return;
Expand All @@ -586,8 +581,7 @@ void CharacterService::RequestServerAssignment(entt::registry& aRegistry, const
}
}

void CharacterService::CancelServerAssignment(entt::registry& aRegistry, const entt::entity aEntity,
const uint32_t aFormId) const noexcept
void CharacterService::CancelServerAssignment(entt::registry& aRegistry, const entt::entity aEntity, const uint32_t aFormId) const noexcept
{
if (aRegistry.has<RemoteComponent>(aEntity))
{
Expand All @@ -607,7 +601,7 @@ void CharacterService::CancelServerAssignment(entt::registry& aRegistry, const e
pActor->Delete();

aRegistry.remove_if_exists<FaceGenComponent, InterpolationComponent, RemoteAnimationComponent,
RemoteComponent, CacheComponent, WaitingFor3D>(aEntity);
RemoteComponent, CacheComponent, WaitingFor3D>(aEntity);
}
}

Expand Down Expand Up @@ -653,7 +647,7 @@ void CharacterService::CancelServerAssignment(entt::registry& aRegistry, const e
m_transport.Send(message);
}
}

if (!actorWasMoved)
{
RemoveCharacterRequest message;
Expand Down Expand Up @@ -750,9 +744,9 @@ void CharacterService::RunRemoteUpdates() const noexcept
// Delay by 120ms to let the interpolation system accumulate interpolation points
const auto tick = m_transport.GetClock().GetCurrentTick() - 120;

// Interpolation has to keep running even if the actor is not in view, otherwise we will never know if we need to
// spawn it
auto interpolatedEntities = m_world.view<RemoteComponent, InterpolationComponent>();
// Interpolation has to keep running even if the actor is not in view, otherwise we will never know if we need to spawn it
auto interpolatedEntities =
m_world.view<RemoteComponent, InterpolationComponent>();

for (auto entity : interpolatedEntities)
{
Expand All @@ -765,7 +759,7 @@ void CharacterService::RunRemoteUpdates() const noexcept
auto* pForm = TESForm::GetById(pFormIdComponent->Id);
pActor = RTTI_CAST(pForm, TESForm, Actor);
}

InterpolationSystem::Update(pActor, interpolationComponent, tick);
}

Expand All @@ -786,7 +780,7 @@ void CharacterService::RunRemoteUpdates() const noexcept

auto facegenView = m_world.view<FormIdComponent, FaceGenComponent>();

for (auto entity : facegenView)
for(auto entity : facegenView)
{
auto& formIdComponent = facegenView.get<FormIdComponent>(entity);
auto& faceGenComponent = facegenView.get<FaceGenComponent>(entity);
Expand Down Expand Up @@ -819,7 +813,7 @@ void CharacterService::RunRemoteUpdates() const noexcept
pActor->SetFactions(remoteComponent.SpawnRequest.FactionsContent);
pActor->LoadAnimationVariables(remoteComponent.SpawnRequest.LatestAction.Variables);

toRemove.push_back(entity);
toRemove.push_back(entity);
}

for (auto entity : toRemove)
Expand Down Expand Up @@ -859,7 +853,6 @@ void CharacterService::RunInventoryUpdates() noexcept
spdlog::info("Sending RequestInventoryChanges event, ID: {:X}", localComponent.Id);
}


m_transport.Send(message);

m_charactersWithInventoryChanges.clear();
Expand Down Expand Up @@ -903,14 +896,13 @@ void CharacterService::RunFactionsUpdates() const noexcept
message.Changes[localComponent.Id] = factions;
}

if (!message.Changes.empty())
if(!message.Changes.empty())
m_transport.Send(message);
}

void CharacterService::RunSpawnUpdates() const noexcept
{
auto invisibleView =
m_world.view<RemoteComponent, InterpolationComponent, RemoteAnimationComponent>(entt::exclude<FormIdComponent>);
auto invisibleView = m_world.view<RemoteComponent, InterpolationComponent, RemoteAnimationComponent>(entt::exclude<FormIdComponent>);

for (auto entity : invisibleView)
{
Expand Down

0 comments on commit 2ec1aa4

Please sign in to comment.