! * \brief Operation to perform when entity is validated for the system * * \param entity Pointer to the entity * \param justAdded Is the entity newly added */
| 74 | * \param justAdded Is the entity newly added |
| 75 | */ |
| 76 | void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded) |
| 77 | { |
| 78 | NazaraUnused(justAdded); |
| 79 | |
| 80 | if (entity->HasComponent<CameraComponent>() && entity->HasComponent<NodeComponent>()) |
| 81 | { |
| 82 | m_cameras.emplace_back(entity); |
| 83 | std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2) |
| 84 | { |
| 85 | return handle1->GetComponent<CameraComponent>().GetLayer() < handle2->GetComponent<CameraComponent>().GetLayer(); |
| 86 | }); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | for (auto it = m_cameras.begin(); it != m_cameras.end(); ++it) |
| 91 | { |
| 92 | if (it->GetObject() == entity) |
| 93 | { |
| 94 | m_cameras.erase(it); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>()) |
| 101 | { |
| 102 | m_drawables.Insert(entity); |
| 103 | |
| 104 | GraphicsComponent& gfxComponent = entity->GetComponent<GraphicsComponent>(); |
| 105 | if (justAdded) |
| 106 | gfxComponent.AddToCullingList(&m_drawableCulling); |
| 107 | |
| 108 | if (gfxComponent.DoesRequireRealTimeReflections()) |
| 109 | m_realtimeReflected.Insert(entity); |
| 110 | else |
| 111 | m_realtimeReflected.Remove(entity); |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | m_drawables.Remove(entity); |
| 116 | m_realtimeReflected.Remove(entity); |
| 117 | |
| 118 | if (entity->HasComponent<GraphicsComponent>()) |
| 119 | { |
| 120 | GraphicsComponent& gfxComponent = entity->GetComponent<GraphicsComponent>(); |
| 121 | gfxComponent.RemoveFromCullingList(&m_drawableCulling); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>()) |
| 126 | { |
| 127 | m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list |
| 128 | |
| 129 | LightComponent& lightComponent = entity->GetComponent<LightComponent>(); |
| 130 | if (lightComponent.GetLightType() == Nz::LightType_Directional) |
| 131 | { |
| 132 | m_directionalLights.Insert(entity); |
| 133 | m_pointSpotLights.Remove(entity); |