"Proper" handling of conditional rendering of entities parented to camera or entities that should be hidden from the active local player perspective
This commit is contained in:
@@ -35,17 +35,19 @@ private:
|
|||||||
|
|
||||||
EventRelay<RenderSystem, Events::SetCamera> m_ESetCamera;
|
EventRelay<RenderSystem, Events::SetCamera> m_ESetCamera;
|
||||||
bool OnSetCamera(Events::SetCamera &event);
|
bool OnSetCamera(Events::SetCamera &event);
|
||||||
|
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
||||||
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
|
EventRelay<RenderSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||||
|
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||||
|
|
||||||
void fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
void fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
void fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
|
||||||
bool OnInputCommand(const Events::InputCommand& e);
|
|
||||||
|
|
||||||
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs);
|
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs);
|
||||||
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs);
|
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs);
|
||||||
|
bool isChildOfACamera(EntityWrapper entity);
|
||||||
|
bool isChildOfCurrentCamera(EntityWrapper entity);
|
||||||
|
|
||||||
EventRelay<RenderSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
|
||||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -27,4 +27,5 @@
|
|||||||
<xs:include schemaLocation="Components/Animation.xsd"/>
|
<xs:include schemaLocation="Components/Animation.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Fill.xsd"/>
|
<xs:include schemaLocation="Components/Fill.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Lifetime.xsd"/>
|
<xs:include schemaLocation="Components/Lifetime.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/HiddenForLocalPlayer.xsd"/>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<HiddenForLocalPlayer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="HiddenForLocalPlayer.xsd"/>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="HiddenForLocalPlayer">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>Used to make the entity invisible if it's parented to the current local player entity (for first person player model and such)</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
<Lifetime xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Animation.xsd">
|
<Lifetime xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Lifetime.xsd">
|
||||||
<Lifetime>0</Lifetime>
|
<Lifetime>0</Lifetime>
|
||||||
</Animation>
|
</Lifetime>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<xs:annotation><xs:documentation>Color tint</xs:documentation></xs:annotation>
|
<xs:annotation><xs:documentation>Color tint</xs:documentation></xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
<xs:element name="Visible" type="t:bool" minOccurs="0">
|
<xs:element name="Visible" type="t:bool" minOccurs="0">
|
||||||
<xs:annotation><xs:documentation>Wether the model is visible or not</xs:documentation></xs:annotation>
|
<xs:annotation><xs:documentation>Whether the model is visible or not</xs:documentation></xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
</Team>
|
</Team>
|
||||||
</c:Team>
|
</c:Team>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="2.24449515" Z="0"/>
|
<Position X="8.60201447e-23" Y="0" Z="3.9201616e-23"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
|
|
||||||
@@ -141,9 +141,10 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<c:Animation>
|
<c:Animation>
|
||||||
<Name>Hold Pos</Name>
|
<Name>Hold Pos</Name>
|
||||||
<Time>0.9779997896222552</Time>
|
<Time>0.73515426169631848</Time>
|
||||||
<Speed>1</Speed>
|
<Speed>1</Speed>
|
||||||
</c:Animation>
|
</c:Animation>
|
||||||
|
<c:HiddenForLocalPlayer/>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>Models/AssaultAnimated.mesh</Resource>
|
<Resource>Models/AssaultAnimated.mesh</Resource>
|
||||||
<Color A="1" B="0" G="0" R="1"/>
|
<Color A="1" B="0" G="0" R="1"/>
|
||||||
|
|||||||
@@ -33,6 +33,9 @@
|
|||||||
<xs:element ref="c:UniformScale" minOccurs="0"/>
|
<xs:element ref="c:UniformScale" minOccurs="0"/>
|
||||||
<xs:element ref="c:EditorWidget" minOccurs="0"/>
|
<xs:element ref="c:EditorWidget" minOccurs="0"/>
|
||||||
<xs:element ref="c:Lifetime" minOccurs="0"/>
|
<xs:element ref="c:Lifetime" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:HiddenForLocalPlayer" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:Fill" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:Animation" minOccurs="0"/>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ void EntityFilePreprocessor::parseComponentInfo()
|
|||||||
|
|
||||||
// Name
|
// Name
|
||||||
compInfo.Name = XS::ToString(element->getName());
|
compInfo.Name = XS::ToString(element->getName());
|
||||||
|
bool brk = compInfo.Name == "HiddenForLocalPlayer";
|
||||||
// Known allocation
|
// Known allocation
|
||||||
compInfo.Meta->Allocation = m_ComponentCounts[compInfo.Name];
|
compInfo.Meta->Allocation = m_ComponentCounts[compInfo.Name];
|
||||||
// Annotation
|
// Annotation
|
||||||
@@ -90,7 +91,7 @@ void EntityFilePreprocessor::parseComponentInfo()
|
|||||||
// <xs:all>
|
// <xs:all>
|
||||||
auto modelGroupParticle = complexTypeDefinition->getParticle();
|
auto modelGroupParticle = complexTypeDefinition->getParticle();
|
||||||
if (modelGroupParticle == nullptr || modelGroupParticle->getTermType() != XSParticle::TERM_MODELGROUP) {
|
if (modelGroupParticle == nullptr || modelGroupParticle->getTermType() != XSParticle::TERM_MODELGROUP) {
|
||||||
//LOG_ERROR("Failed to parse component definition for \"%s\": Model group particle was null or wasn't TERM_MODELGROUP!", compInfo.Name.c_str());
|
LOG_ERROR("Failed to parse component definition for \"%s\": Model group particle was null or wasn't TERM_MODELGROUP!", compInfo.Name.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto modelGroup = modelGroupParticle->getModelGroupTerm();
|
auto modelGroup = modelGroupParticle->getModelGroupTerm();
|
||||||
|
|||||||
@@ -54,8 +54,12 @@ ComponentWrapper World::AttachComponent(EntityID entity, const std::string& comp
|
|||||||
|
|
||||||
bool World::HasComponent(EntityID entity, const std::string& componentType) const
|
bool World::HasComponent(EntityID entity, const std::string& componentType) const
|
||||||
{
|
{
|
||||||
ComponentPool* pool = m_ComponentPools.at(componentType);
|
auto it = m_ComponentPools.find(componentType);
|
||||||
return pool->KnowsEntity(entity);
|
if (it == m_ComponentPools.end()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return it->second->KnowsEntity(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentWrapper World::GetComponent(EntityID entity, const std::string& componentType)
|
ComponentWrapper World::GetComponent(EntityID entity, const std::string& componentType)
|
||||||
|
|||||||
@@ -31,6 +31,16 @@ bool RenderSystem::OnSetCamera(Events::SetCamera& e)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderSystem::isChildOfACamera(EntityWrapper entity)
|
||||||
|
{
|
||||||
|
return entity.FirstParentWithComponent("Camera").Valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderSystem::isChildOfCurrentCamera(EntityWrapper entity)
|
||||||
|
{
|
||||||
|
return entity == m_CurrentCamera || entity.IsChildOf(m_CurrentCamera);
|
||||||
|
}
|
||||||
|
|
||||||
void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
||||||
{
|
{
|
||||||
auto models = m_World->GetComponents("Model");
|
auto models = m_World->GetComponents("Model");
|
||||||
@@ -38,26 +48,25 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& modelComponent : *models) {
|
for (auto& cModel : *models) {
|
||||||
bool visible = modelComponent["Visible"];
|
bool visible = cModel["Visible"];
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::string resource = modelComponent["Resource"];
|
std::string resource = cModel["Resource"];
|
||||||
if (resource.empty()) {
|
if (resource.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityWrapper entity(m_World, modelComponent.EntityID);
|
EntityWrapper entity(m_World, cModel.EntityID);
|
||||||
|
|
||||||
// Don't render the local player
|
// Only render children of a camera if that camera is currently active
|
||||||
if (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer)) {
|
if (isChildOfACamera(entity) && !isChildOfCurrentCamera(entity)) {
|
||||||
if (!entity.HasComponent("HealthHUD") && entity.Name() != "Crosshair" && entity.Name() != "Weapon") { //Should work but needs to be fixed. Should only render the things "childed" to the local player camera
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((entity.Name() == "Weapon" || entity.HasComponent("HealthHUD")) && !entity.IsChildOf(m_LocalPlayer)) {
|
// Hide things parented to local player if they have the HiddenFromLocalPlayer component
|
||||||
|
if (entity.HasComponent("HiddenForLocalPlayer") && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,17 +88,17 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
|||||||
float fillPercentage = 0.f;
|
float fillPercentage = 0.f;
|
||||||
glm::vec4 fillColor = glm::vec4(0);
|
glm::vec4 fillColor = glm::vec4(0);
|
||||||
|
|
||||||
if(m_World->HasComponent(modelComponent.EntityID, "Fill")) {
|
if(m_World->HasComponent(cModel.EntityID, "Fill")) {
|
||||||
auto fillComponent = m_World->GetComponent(modelComponent.EntityID, "Fill");
|
auto fillComponent = m_World->GetComponent(cModel.EntityID, "Fill");
|
||||||
fillPercentage = (float)(double)fillComponent["Percentage"];
|
fillPercentage = (float)(double)fillComponent["Percentage"];
|
||||||
fillColor = (glm::vec4)fillComponent["Color"];
|
fillColor = (glm::vec4)fillComponent["Color"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 modelMatrix = Transform::ModelMatrix(modelComponent.EntityID, m_World);
|
glm::mat4 modelMatrix = Transform::ModelMatrix(cModel.EntityID, m_World);
|
||||||
for (auto matGroup : model->MaterialGroups()) {
|
for (auto matGroup : model->MaterialGroups()) {
|
||||||
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(model, m_Camera, modelMatrix, matGroup, modelComponent, m_World, fillColor, fillPercentage));
|
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(model, m_Camera, modelMatrix, matGroup, cModel, m_World, fillColor, fillPercentage));
|
||||||
jobs.push_back(modelJob);
|
jobs.push_back(modelJob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user