// Copyright (C) 2015 Jérôme Leclercq // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp #include #include #include #include #include #include namespace Ndk { RenderSystem::RenderSystem() { SetUpdateRate(0.f); } void RenderSystem::OnEntityRemoved(Entity* entity) { m_cameras.Remove(entity); m_drawables.Remove(entity); m_lights.Remove(entity); } void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded) { if (entity->HasComponent() && entity->HasComponent()) { m_cameras.Insert(entity); std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2) { return handle1->GetComponent().GetLayer() < handle2->GetComponent().GetLayer(); }); } else m_cameras.Remove(entity); if (entity->HasComponent() && entity->HasComponent()) m_drawables.Insert(entity); else m_drawables.Remove(entity); if (entity->HasComponent() && entity->HasComponent()) m_lights.Insert(entity); else m_lights.Remove(entity); } void RenderSystem::OnUpdate(float elapsedTime) { for (const Ndk::EntityHandle& camera : m_cameras) { CameraComponent& camComponent = camera->GetComponent(); camComponent.ApplyView(); NzAbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue(); renderQueue->Clear(); for (const Ndk::EntityHandle& light : m_drawables) { GraphicsComponent& graphicsComponent = light->GetComponent(); NodeComponent& drawableNode = light->GetComponent(); graphicsComponent.AddToRenderQueue(renderQueue); } for (const Ndk::EntityHandle& light : m_lights) { LightComponent& lightComponent = light->GetComponent(); NodeComponent& drawableNode = light->GetComponent(); lightComponent.AddToRenderQueue(renderQueue, drawableNode.GetTransformMatrix()); } NzColorBackground background; NzSceneData sceneData; sceneData.ambientColor = NzColor(25, 25, 25); sceneData.background = &background; sceneData.viewer = &camComponent; m_renderTechnique.Draw(sceneData); } } SystemIndex RenderSystem::systemIndex; }