Ignoring interpolation and rendering for local player entities!
This commit is contained in:
@@ -5,6 +5,9 @@ const EntityWrapper EntityWrapper::Invalid = EntityWrapper(nullptr, EntityID_Inv
|
||||
|
||||
bool EntityWrapper::HasComponent(const std::string& componentName)
|
||||
{
|
||||
if (!Valid()) {
|
||||
return false;
|
||||
}
|
||||
return World->HasComponent(ID, componentName);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ RenderSystem::RenderSystem(World* world, EventBroker* eventBroker, const IRender
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &RenderSystem::OnPlayerSpawned);
|
||||
|
||||
m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
}
|
||||
@@ -46,6 +47,18 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityWrapper entity(m_World, modelComponent.EntityID);
|
||||
bool isLocalPlayer = entity == m_LocalPlayer;
|
||||
while (entity.Parent().Valid()) {
|
||||
entity = entity.Parent();
|
||||
if (entity == m_LocalPlayer) {
|
||||
isLocalPlayer = true;
|
||||
}
|
||||
}
|
||||
if (isLocalPlayer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(resource);
|
||||
@@ -68,6 +81,14 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
{
|
||||
if (e.PlayerID == -1) {
|
||||
m_LocalPlayer = e.Player;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderSystem::fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world)
|
||||
{
|
||||
auto pointLights = m_World->GetComponents("PointLight");
|
||||
@@ -128,6 +149,18 @@ void RenderSystem::fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World*
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityWrapper entity(m_World, textComponent.EntityID);
|
||||
bool isLocalPlayer = entity == m_LocalPlayer;
|
||||
while (entity.Parent().Valid()) {
|
||||
entity = entity.Parent();
|
||||
if (entity == m_LocalPlayer) {
|
||||
isLocalPlayer = true;
|
||||
}
|
||||
}
|
||||
if (isLocalPlayer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Font* font;
|
||||
try {
|
||||
font = ResourceManager::Load<Font>(resource);
|
||||
@@ -169,7 +202,7 @@ void RenderSystem::Update(double dt)
|
||||
fillModels(scene.ForwardJobs);
|
||||
fillPointLights(scene.PointLightJobs, m_World);
|
||||
fillDirectionalLights(scene.DirectionalLightJobs, m_World);
|
||||
fillText(scene.TextJobs, world);
|
||||
fillText(scene.TextJobs, m_World);
|
||||
m_RenderFrame->Add(scene);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,15 @@
|
||||
#include "Systems/InterpolationSystem.h"
|
||||
|
||||
InterpolationSystem::InterpolationSystem(World* world, EventBroker* eventBroker)
|
||||
: System(world, eventBroker)
|
||||
, PureSystem("Transform")
|
||||
{
|
||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_SnapshotInterval = config->Get<float>("Networking.SnapshotInterval", 0.05);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInterpolate, &InterpolationSystem::OnInterpolate);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &InterpolationSystem::OnPlayerSpawned);
|
||||
}
|
||||
|
||||
void InterpolationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& transform, double dt)
|
||||
{
|
||||
if (m_NextTransform.find(transform.EntityID) != m_NextTransform.end()) { // Exists in map
|
||||
@@ -17,14 +27,21 @@ void InterpolationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
|
||||
}
|
||||
}
|
||||
if (transform.Info.Name == "Transform") {
|
||||
bool isLocalPlayer = entity == m_LocalPlayer || entity.Parent() == m_LocalPlayer;
|
||||
// Position
|
||||
glm::vec3 nextPosition = sTransform.Position;
|
||||
glm::vec3 currentPosition = static_cast<glm::vec3>(transform["Position"]);
|
||||
if (isLocalPlayer && glm::length(nextPosition - currentPosition) < 1.f) {
|
||||
return;
|
||||
}
|
||||
(glm::vec3&)transform["Position"] += vectorInterpolation<glm::vec3>(currentPosition, nextPosition, sTransform.interpolationTime);
|
||||
// Orientation
|
||||
glm::quat nextOrientation = sTransform.Orientation;
|
||||
glm::quat currentOrientation = glm::quat(static_cast<glm::vec3>(transform["Orientation"]));
|
||||
(glm::vec3&)transform["Orientation"] = glm::eulerAngles(glm::slerp<float>(currentOrientation, nextOrientation, sTransform.interpolationTime / m_SnapshotInterval));
|
||||
//bool isPlayer = entity.HasComponent("Player") || entity.Parent().HasComponent("Player");
|
||||
if (!isLocalPlayer) {
|
||||
glm::quat nextOrientation = sTransform.Orientation;
|
||||
glm::quat currentOrientation = glm::quat(static_cast<glm::vec3>(transform["Orientation"]));
|
||||
(glm::vec3&)transform["Orientation"] = glm::eulerAngles(glm::slerp<float>(currentOrientation, nextOrientation, sTransform.interpolationTime / m_SnapshotInterval));
|
||||
}
|
||||
// Scale
|
||||
glm::vec3 nextScale = sTransform.Scale;
|
||||
glm::vec3 currentScale = static_cast<glm::vec3>(transform["Scale"]);
|
||||
@@ -33,6 +50,12 @@ void InterpolationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrappe
|
||||
}
|
||||
}
|
||||
|
||||
bool InterpolationSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
{
|
||||
m_LocalPlayer = e.Player;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InterpolationSystem::OnInterpolate(const Events::Interpolate & e)
|
||||
{
|
||||
Transform transform;
|
||||
|
||||
Reference in New Issue
Block a user