Added tests. Made network spawnable to serialize in binary
Signed-off-by: pereslav <pereslav@amazon.com>monroegm-disable-blank-issue-2
parent
fc72a1a327
commit
b1a76feead
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<Component
|
||||
Name="TestMultiplayerComponent"
|
||||
Namespace="MultiplayerTest"
|
||||
OverrideComponent="true"
|
||||
OverrideController="true"
|
||||
OverrideInclude="Tests/TestMultiplayerComponent.h"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<NetworkInput Type="uint64_t" Name="OwnerId" Init="0" />
|
||||
|
||||
</Component>
|
||||
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <Tests/TestMultiplayerComponent.h>
|
||||
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
|
||||
namespace MultiplayerTest
|
||||
{
|
||||
void TestInputDriverComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<TestInputDriverComponent, AZ::Component>()
|
||||
->Version(1);
|
||||
}
|
||||
}
|
||||
|
||||
void TestMultiplayerComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<TestMultiplayerComponent, TestMultiplayerComponentBase>()
|
||||
->Version(1);
|
||||
}
|
||||
TestMultiplayerComponentBase::Reflect(context);
|
||||
}
|
||||
|
||||
void TestMultiplayerComponent::OnInit()
|
||||
{
|
||||
}
|
||||
|
||||
void TestMultiplayerComponent::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
}
|
||||
|
||||
void TestMultiplayerComponent::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
}
|
||||
|
||||
TestMultiplayerComponentController::TestMultiplayerComponentController(TestMultiplayerComponent& parent)
|
||||
: TestMultiplayerComponentControllerBase(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TestMultiplayerComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
}
|
||||
|
||||
void TestMultiplayerComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
}
|
||||
|
||||
void TestMultiplayerComponentController::CreateInput(Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime)
|
||||
{
|
||||
auto* networkInput = input.FindComponentInput<TestMultiplayerComponentNetworkInput>();
|
||||
networkInput->m_ownerId = GetParent().GetId();
|
||||
}
|
||||
|
||||
void TestMultiplayerComponentController::ProcessInput(Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime)
|
||||
{
|
||||
auto& component = GetParent();
|
||||
auto* networkInput = input.FindComponentInput<TestMultiplayerComponentNetworkInput>();
|
||||
AZ_Assert(networkInput->m_ownerId == component.GetId(), "Input Id doesn't match the owner component Id");
|
||||
|
||||
if (component.m_processInputCallback)
|
||||
{
|
||||
component.m_processInputCallback(GetNetEntityId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <Tests/AutoGen/TestMultiplayerComponent.AutoComponent.h>
|
||||
|
||||
namespace MultiplayerTest
|
||||
{
|
||||
// Dummy class for satisfying "MultiplayerInputDriver" component dependency
|
||||
class TestInputDriverComponent : public AZ::Component
|
||||
{
|
||||
public:
|
||||
AZ_COMPONENT(TestInputDriverComponent, "{C3877905-3B61-45AE-A636-9845C3AAA39D}");
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
||||
{
|
||||
provided.emplace_back(AZ_CRC_CE("MultiplayerInputDriver"));
|
||||
}
|
||||
|
||||
void Activate(){};
|
||||
void Deactivate(){};
|
||||
};
|
||||
|
||||
// Test multiplayer component with ability to create and process network input
|
||||
class TestMultiplayerComponent
|
||||
: public TestMultiplayerComponentBase
|
||||
{
|
||||
public:
|
||||
AZ_MULTIPLAYER_COMPONENT(MultiplayerTest::TestMultiplayerComponent, s_testMultiplayerComponentConcreteUuid, MultiplayerTest::TestMultiplayerComponentBase);
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
void OnInit() override;
|
||||
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
|
||||
AZStd::function<void(Multiplayer::NetEntityId)> m_processInputCallback;
|
||||
};
|
||||
|
||||
// Multiplayer controller for the test component
|
||||
class TestMultiplayerComponentController
|
||||
: public TestMultiplayerComponentControllerBase
|
||||
{
|
||||
public:
|
||||
TestMultiplayerComponentController(TestMultiplayerComponent& parent);
|
||||
|
||||
//! TestMultiplayerComponentControllerBase
|
||||
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
|
||||
//! MultiplayerController interface
|
||||
void CreateInput(Multiplayer::NetworkInput& input, float deltaTime) override;
|
||||
void ProcessInput(Multiplayer::NetworkInput& input, float deltaTime) override;
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue