void Terminate()
{		
	TwTerminate();

	glDeleteBuffers(1, &Material::UBO);
	glDeleteBuffers(1, &PointLight::UBO);
	glDeleteBuffers(1, &g_Camera.UBO);

	g_Spheres.shrink_to_fit();
	
	CleanMesh(g_SphereMesh);

	glDeleteTextures(3, g_Walls.textures);
	CleanMesh(g_WallMesh);

	g_BlinnPhongShader.Destroy();
	g_AmbientShader.Destroy();
}
示例#2
0
void BgLoader::ContinueLoading(bool waiting)
{  
    // Limit even while waiting - we want some frames.
    size_t i = 0;
    size_t count = 0;
    while(count < 10)
    {
        // True if at least one mesh finished load.
        bool finished = false;

        // Delete from delete queue (fairly expensive, so limited per update).
        if(!deleteQueue.IsEmpty())
        {
            CleanMesh(deleteQueue[0]);
            deleteQueue.DeleteIndexFast(0);
        }

        // Check if we need to reset i
        if (i == loadingMeshes.GetSize())
            i = 0;

        // Check already loading meshes.
        for(; i<(loadingMeshes.GetSize() < 20 ? loadingMeshes.GetSize() : 20); ++i)
        {
            if(LoadMesh(loadingMeshes[i]))
            {
                finished = true;
                finalisableMeshes.Push(loadingMeshes[i]);
                loadingMeshes.DeleteIndex(i);
            }
        }

        // Finalise loaded meshes (expensive, so limited per update).
        if(!finalisableMeshes.IsEmpty())
        {
            if(finished)
                engine->SyncEngineListsNow(tloader);

            FinishMeshLoad(finalisableMeshes[0]);
            finalisableMeshes.DeleteIndexFast(0);
        }

        // Load meshgens.
        for(size_t j=0; j<loadingMeshGen.GetSize(); ++j)
        {
            if(LoadMeshGen(loadingMeshGen[j]))
            {
                loadingMeshGen.DeleteIndex(j);
            }
        }

        ++count;
        if(!waiting || GetLoadingCount() == 0)
            break;
    }
}
示例#3
0
void BgLoader::CleanSector(Sector* sector)
{
    if(!sector->object.IsValid())
        return;

    for(size_t i=0; i<sector->meshes.GetSize(); i++)
    {
        if(sector->meshes[i]->object.IsValid())
        {
            sector->meshes[i]->object->GetMovable()->ClearSectors();
            sector->meshes[i]->object->GetMovable()->UpdateMove();
            engine->GetMeshes()->Remove(sector->meshes[i]->object);
            sector->meshes[i]->object.Invalidate();
            CleanMesh(sector->meshes[i]);
            --(sector->objectCount);
        }
    }

    for(size_t i=0; i<sector->meshgen.GetSize(); i++)
    {
        CleanMeshGen(sector->meshgen[i]);
        --(sector->objectCount);
    }

    for(size_t i=0; i<sector->portals.GetSize(); i++)
    {
        if(sector->portals[i]->mObject.IsValid())
        {
            engine->GetMeshes()->Remove(sector->portals[i]->mObject);
            sector->portals[i]->pObject = NULL;
            sector->portals[i]->mObject.Invalidate();
            sector->activePortals.Delete(sector->portals[i]);
            --(sector->objectCount);
        }
    }

    for(size_t i=0; i<sector->lights.GetSize(); i++)
    {
        if(sector->lights[i]->object.IsValid())
        {
            engine->RemoveLight(sector->lights[i]->object);
            sector->lights[i]->object.Invalidate();
            --(sector->objectCount);
        }

        for(size_t j=0; j<sector->lights[i]->sequences.GetSize(); ++j)
        {
            if(sector->lights[i]->sequences[j]->status.IsValid())
            {
                for(size_t k=0; k<sector->lights[i]->sequences[j]->triggers.GetSize(); ++k)
                {
                    if(sector->lights[i]->sequences[j]->triggers[k]->status.IsValid())
                    {
                        csRef<iSequenceTrigger> st = scfQueryInterface<iSequenceTrigger>(sector->lights[i]->sequences[j]->triggers[k]->status->GetResultRefPtr());
                        engseq->RemoveTrigger(st);
                        sector->lights[i]->sequences[j]->triggers[k]->status.Invalidate();
                    }
                }

                csRef<iSequenceWrapper> sw = scfQueryInterface<iSequenceWrapper>(sector->lights[i]->sequences[j]->status->GetResultRefPtr());
                engseq->RemoveSequence(sw);
                sector->lights[i]->sequences[j]->status.Invalidate();
            }
        }
    }

    // Unload all 'always loaded' meshes before destroying sector.
    if(sector->objectCount != 0)
    {
        for(size_t i=0; i<sector->alwaysLoaded.GetSize(); i++)
        {
            sector->alwaysLoaded[i]->object->GetMovable()->ClearSectors();
            sector->alwaysLoaded[i]->object->GetMovable()->UpdateMove();
            engine->GetMeshes()->Remove(sector->alwaysLoaded[i]->object);
            sector->alwaysLoaded[i]->object.Invalidate();
            CleanMesh(sector->alwaysLoaded[i]);
            --(sector->objectCount);
        }
    }

    // Remove sequences.
    for(size_t i=0; i<sector->sequences.GetSize(); ++i)
    {
        if(sector->sequences[i]->status.IsValid())
        {
            csRef<iSequenceWrapper> sw = scfQueryInterface<iSequenceWrapper>(sector->sequences[i]->status->GetResultRefPtr());
            engseq->RemoveSequence(sw);
            sector->sequences[i]->status.Invalidate();
        }
    }

    if(sector->objectCount != 0)
    {
        csString msg;
        msg.Format("Error cleaning sector. Sector still has %zu objects!", sector->objectCount);
        CS_ASSERT_MSG(msg.GetData(), false);
    }
    CS_ASSERT_MSG("Error cleaning sector. Sector is invalid!", sector->object.IsValid());

    // Remove the sector from the engine.
    sector->checked = false;
    sector->object->QueryObject()->SetObjectParent(0);
    engine->GetSectors()->Remove(sector->object);
    sector->object.Invalidate();
}