<commit_before>#include "Zenderer/Graphics/Scene.hpp"

using namespace zen;
using namespace gfx;

using util::CLog;
using util::LogMode;
using gfxcore::CRenderer;
using gfxcore::BlendFunc;

CScene::CScene(const uint16_t w, const uint16_t h, asset::CAssetManager& Mgr) :
    CSubsystem("Scene"), m_Assets(Mgr),
    m_Log(util::CLog::GetEngineLog()), m_FBO1(w, h), m_FBO2(w, h),
    m_lighting(false), m_ppfx(false), m_through(false)
{
}

CScene::~CScene()
{
    this->Destroy();
}

bool CScene::Init()
{
    return  m_Assets.IsInit()   && m_Geometry.Init() &&
            m_FBO1.Init()       && m_FBO2.Init();
}

/// @bug A crash occurs deleting entities.
bool CScene::Destroy()
{
    return this->Clear()    && m_FBO1.Destroy() &&
           m_FBO2.Destroy() && m_Geometry.Destroy();
}

obj::CEntity& CScene::AddEntity()
{
    obj::CEntity* pNew = new obj::CEntity(m_Assets);
    m_allEntities.push_back(pNew);
    return *m_allEntities.back();
}

CLight& CScene::AddLight(const LightType& Type)
{
    CLight* pNew = new CLight(m_Assets, Type, m_FBO1.GetHeight());
    pNew->Init();
    m_allLights.push_back(pNew);
    return *m_allLights.back();
}

CEffect& CScene::AddEffect(const EffectType& Type)
{
    CEffect* pNew = new CEffect(Type, m_Assets);
    if(pNew->Init())
    {
        pNew->Enable();
        pNew->SetParameter("mv", math::matrix4x4_t::GetIdentityMatrix());
        pNew->SetParameter("proj", CRenderer::GetProjectionMatrix());
        pNew->Disable();
    }

    m_allPPFX.push_back(pNew);
    return *m_allPPFX.back();
}

obj::CEntity& CScene::InsertEntity(const uint32_t index)
{
    obj::CEntity* pNew = new obj::CEntity(m_Assets);
    auto i = m_allEntities.begin();
    for(size_t j = 0, s = m_allEntities.size();
        j < s && j != index; ++j, ++i);
        // No -op

    m_allEntities.insert(i, pNew);
    return *pNew;
}

bool CScene::RemoveEntity(const obj::CEntity& Obj)
{
    auto i = m_allEntities.begin(),
         j = m_allEntities.end();

    for( ; i != j; ++i)
    {
        if(*i == &Obj)
        {
            delete *i;
            m_allEntities.erase(i);
            return true;
        }
    }

    return false;
}

bool CScene::RemoveEntity(const uint32_t index)
{
    if(!this->IsValidEntityIndex(index)) return false;

    auto i = m_allEntities.begin();
    for(size_t j = 0; j <= index; ++j, ++i);
        // No-op

    delete *i;
    m_allEntities.erase(i);
    return true;
}

bool CScene::Clear()
{
    for(auto i : m_allEntities) delete i;
    for(auto i : m_allLights) delete i;
    for(auto i : m_allPPFX) delete i;

    m_allEntities.clear();
    m_allLights.clear();
    m_allPPFX.clear();

    return m_Geometry.Clear();
}

bool CScene::Render()
{
    // Called every frame because there is no more appropriate
    // time to call it. Things won't be offloaded multiple times.
    for(auto& i : m_allEntities)
    {
        // If any are offloaded, the rest probably are too.
        if(i->Offloaded()) break;
        i->Offload(m_Geometry, false);
    }<commit_msg>Always check all offloads for scene.<commit_after>#include "Zenderer/Graphics/Scene.hpp"

using namespace zen;
using namespace gfx;

using util::CLog;
using util::LogMode;
using gfxcore::CRenderer;
using gfxcore::BlendFunc;

CScene::CScene(const uint16_t w, const uint16_t h, asset::CAssetManager& Mgr) :
    CSubsystem("Scene"), m_Assets(Mgr),
    m_Log(util::CLog::GetEngineLog()), m_FBO1(w, h), m_FBO2(w, h),
    m_lighting(false), m_ppfx(false), m_through(false)
{
}

CScene::~CScene()
{
    this->Destroy();
}

bool CScene::Init()
{
    return  m_Assets.IsInit()   && m_Geometry.Init() &&
            m_FBO1.Init()       && m_FBO2.Init();
}

/// @bug A crash occurs deleting entities.
bool CScene::Destroy()
{
    return this->Clear()    && m_FBO1.Destroy() &&
           m_FBO2.Destroy() && m_Geometry.Destroy();
}

obj::CEntity& CScene::AddEntity()
{
    obj::CEntity* pNew = new obj::CEntity(m_Assets);
    m_allEntities.push_back(pNew);
    return *m_allEntities.back();
}

CLight& CScene::AddLight(const LightType& Type)
{
    CLight* pNew = new CLight(m_Assets, Type, m_FBO1.GetHeight());
    pNew->Init();
    m_allLights.push_back(pNew);
    return *m_allLights.back();
}

CEffect& CScene::AddEffect(const EffectType& Type)
{
    CEffect* pNew = new CEffect(Type, m_Assets);
    if(pNew->Init())
    {
        pNew->Enable();
        pNew->SetParameter("mv", math::matrix4x4_t::GetIdentityMatrix());
        pNew->SetParameter("proj", CRenderer::GetProjectionMatrix());
        pNew->Disable();
    }

    m_allPPFX.push_back(pNew);
    return *m_allPPFX.back();
}

obj::CEntity& CScene::InsertEntity(const uint32_t index)
{
    obj::CEntity* pNew = new obj::CEntity(m_Assets);
    auto i = m_allEntities.begin();
    for(size_t j = 0, s = m_allEntities.size();
        j < s && j != index; ++j, ++i);
        // No -op

    m_allEntities.insert(i, pNew);
    return *pNew;
}

bool CScene::RemoveEntity(const obj::CEntity& Obj)
{
    auto i = m_allEntities.begin(),
         j = m_allEntities.end();

    for( ; i != j; ++i)
    {
        if(*i == &Obj)
        {
            delete *i;
            m_allEntities.erase(i);
            return true;
        }
    }

    return false;
}

bool CScene::RemoveEntity(const uint32_t index)
{
    if(!this->IsValidEntityIndex(index)) return false;

    auto i = m_allEntities.begin();
    for(size_t j = 0; j <= index; ++j, ++i);
        // No-op

    delete *i;
    m_allEntities.erase(i);
    return true;
}

bool CScene::Clear()
{
    for(auto i : m_allEntities) delete i;
    for(auto i : m_allLights) delete i;
    for(auto i : m_allPPFX) delete i;

    m_allEntities.clear();
    m_allLights.clear();
    m_allPPFX.clear();

    return m_Geometry.Clear();
}

bool CScene::Render()
{
    // Called every frame because there is no more appropriate
    // time to call it. Things won't be offloaded multiple times.
    for(auto& i : m_allEntities)
    {
        // If any are offloaded, the rest probably are too.
        if(i->Offloaded()) continue;
        i->Offload(m_Geometry, false);
    }
{'fraction_non_alphanumeric': 0.15537652088128906, 'fraction_numerical': 0.006247944755014798, 'mean_word_length': 3.0472388556220893, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7424167', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2260, 'n_words': 465}