17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 13:19:20 +02:00
Files
maszyna/model/ResourceManager.cpp
maj00r ce5ee288ff fix the clang CI build
Every module unit now includes the standard headers it uses. Declarations
reaching a unit only through an imported module's global module fragment
are reachable but not visible, so ADL misses the free operators older
libstdc++ declares beside a type - reproduced on ubuntu 24.04 (libstdc++
13), where gl/vao.cpp could not compare vector iterators.

Also drops a stale editor/editorSettings.hpp from the MSVC source list,
which broke the Windows configure step, silences the deliberate
include-in-purview warning in the glm wrapper, and removes GCC support:
clang or MSVC only.
2026-09-09 22:52:28 +02:00

94 lines
2.1 KiB
C++

module;
#include <utility>
#include <chrono>
#include <cstddef>
#include <sstream>
#include <string>
module eu07.model.resourcemanager;
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
ResourceManager::Resources ResourceManager::_resources;
double ResourceManager::_expiry = 5.0f;
double ResourceManager::_lastUpdate = 0.0f;
double ResourceManager::_lastReport = 0.0f;
void ResourceManager::Register(Resource *resource)
{
_resources.emplace_back(resource);
};
void ResourceManager::Unregister(Resource *resource)
{
Resources::iterator iter = std::find(_resources.begin(), _resources.end(), resource);
if (iter != _resources.end())
_resources.erase(iter);
resource->Release();
};
class ResourceExpired
{
public:
ResourceExpired(double time) : _time(time){};
bool operator()(Resource *resource)
{
return (resource->GetLastUsage() < _time);
}
private:
double _time;
};
void ResourceManager::Sweep(double currentTime)
{
if (currentTime - _lastUpdate < _expiry)
return;
Resources::iterator begin = std::remove_if(_resources.begin(), _resources.end(),
ResourceExpired(currentTime - _expiry));
#ifdef RESOURCE_REPORTING
if (begin != _resources.end())
WriteLog("Releasing resources");
#endif
for (Resources::iterator iter = begin; iter != _resources.end(); ++iter)
(*iter)->Release();
#ifdef RESOURCE_REPORTING
if (begin != _resources.end())
{
std::ostringstream msg;
msg << "Released " << (_resources.end() - begin) << " resources";
WriteLog(msg.str().c_str());
};
#endif
_resources.erase(begin, _resources.end());
#ifdef RESOURCE_REPORTING
if (currentTime - _lastReport > 30.0f)
{
std::ostringstream msg;
msg << "Resources count: " << _resources.size();
WriteLog(msg.str().c_str());
_lastReport = currentTime;
};
#endif
_lastUpdate = currentTime;
};
*/