16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 18:19:19 +02:00

texture garbage collection, removed fixed binding with world camera in world render, cap on minimal volume held by reservoirs

This commit is contained in:
tmj-fstate
2017-07-02 21:24:29 +02:00
parent 534a49b636
commit d3b812ee9f
13 changed files with 301 additions and 199 deletions

View File

@@ -7,14 +7,11 @@ obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H 1
#pragma once
/*
#include <vector>
#include <algorithm>
#pragma hdrstop
class Resource
{
@@ -57,5 +54,63 @@ class ResourceManager
static Resources _resources;
};
*/
#endif
template <class Container_>
class garbage_collector {
public:
// constructor:
garbage_collector( Container_ &Container, int const Secondstolive, int const Sweepsize, std::string const Resourcename = "resource" ) :
m_container( Container ),
m_unusedresourcetimetolive { std::chrono::seconds( Secondstolive ) },
m_unusedresourcesweepsize( Sweepsize ),
m_resourcename( Resourcename )
{}
// methods:
// performs resource sweep. returns: number of released resources
int
sweep() {
m_resourcetimestamp = std::chrono::steady_clock::now();
// garbage collection sweep is limited to a number of records per call, to reduce impact on framerate
auto const sweeplastindex =
std::min(
m_resourcesweepindex + m_unusedresourcesweepsize,
m_container.size() );
auto const blanktimestamp { std::chrono::steady_clock::time_point() };
int releasecount{ 0 };
for( auto resourceindex = m_resourcesweepindex; resourceindex < sweeplastindex; ++resourceindex ) {
if( ( m_container[ resourceindex ].second != blanktimestamp )
&& ( m_resourcetimestamp - m_container[ resourceindex ].second > m_unusedresourcetimetolive ) ) {
m_container[ resourceindex ].first->release();
m_container[ resourceindex ].second = blanktimestamp;
++releasecount;
}
}
/*
if( releasecount ) {
WriteLog( "Resource garbage sweep released " + std::to_string( releasecount ) + " " + ( releasecount == 1 ? m_resourcename : m_resourcename + "s" ) );
}
*/
m_resourcesweepindex = (
m_resourcesweepindex + m_unusedresourcesweepsize >= m_container.size() ?
0 : // if the next sweep chunk is beyond actual data, so start anew
m_resourcesweepindex + m_unusedresourcesweepsize );
return releasecount; }
std::chrono::steady_clock::time_point
timestamp() const {
return m_resourcetimestamp; }
private:
// members:
std::chrono::nanoseconds const m_unusedresourcetimetolive;
typename Container_::size_type const m_unusedresourcesweepsize;
std::string const m_resourcename;
typename Container_ &m_container;
typename Container_::size_type m_resourcesweepindex { 0 };
std::chrono::steady_clock::time_point m_resourcetimestamp { std::chrono::steady_clock::now() };
};