Push
This commit is contained in:
@ -15,7 +15,7 @@ void AssetManager::update() {
|
||||
this->syncTick();
|
||||
}
|
||||
|
||||
void AssetManager::queueLoad(const std::vector<Asset*> assets) {
|
||||
void AssetManager::queueLoad(const std::vector<std::shared_ptr<Asset>> assets) {
|
||||
std::merge(
|
||||
this->assetsToLoad.begin(), this->assetsToLoad.end(),
|
||||
assets.begin(), assets.end(),
|
||||
@ -23,11 +23,13 @@ void AssetManager::queueLoad(const std::vector<Asset*> assets) {
|
||||
);
|
||||
}
|
||||
|
||||
void AssetManager::queueLoad(Asset *asset) {
|
||||
void AssetManager::queueLoad(const std::shared_ptr<Asset> &asset) {
|
||||
this->assetsToLoad.push_back(asset);
|
||||
}
|
||||
|
||||
void AssetManager::queueUnload(const std::vector<Asset*> assets) {
|
||||
void AssetManager::queueUnload(
|
||||
const std::vector<std::shared_ptr<Asset>> &assets
|
||||
) {
|
||||
std::cout <<
|
||||
"Asset list was queued to unload, but is not yet implemented" <<
|
||||
std::endl;
|
||||
@ -38,7 +40,7 @@ void AssetManager::queueUnload(const std::vector<Asset*> assets) {
|
||||
);
|
||||
}
|
||||
|
||||
void AssetManager::queueUnload(Asset *asset) {
|
||||
void AssetManager::queueUnload(const std::shared_ptr<Asset> &asset) {
|
||||
std::cout <<
|
||||
"Asset was queued to unload, but is not yet implemented" <<
|
||||
std::endl;
|
||||
@ -46,8 +48,8 @@ void AssetManager::queueUnload(Asset *asset) {
|
||||
}
|
||||
|
||||
void AssetManager::queueSwap(
|
||||
const std::vector<Asset*> newAssets,
|
||||
const std::vector<Asset*> oldAssets
|
||||
const std::vector<std::shared_ptr<Asset>> &newAssets,
|
||||
const std::vector<std::shared_ptr<Asset>> &oldAssets
|
||||
) {
|
||||
std::vector<Asset*> unload;
|
||||
std::vector<Asset*> load;
|
||||
@ -94,7 +96,5 @@ void AssetManager::syncLoad() {
|
||||
}
|
||||
|
||||
AssetManager::~AssetManager() {
|
||||
std::for_each(this->assets.begin(), this->assets.end(), [&](auto &item){
|
||||
delete item.second;
|
||||
});
|
||||
this->assets.clear();
|
||||
}
|
@ -10,9 +10,9 @@ namespace Dawn {
|
||||
class AssetManager {
|
||||
private:
|
||||
/** List of pointers to assets, mapped by their asset key. */
|
||||
std::map<std::string, Asset*> assets;
|
||||
std::vector<Asset*> assetsToLoad;
|
||||
std::vector<Asset*> assetsToUnload;
|
||||
std::map<std::string, std::shared_ptr<Asset>> assets;
|
||||
std::vector<std::shared_ptr<Asset>> assetsToLoad;
|
||||
std::vector<std::shared_ptr<Asset>> assetsToUnload;
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -30,28 +30,28 @@ namespace Dawn {
|
||||
*
|
||||
* @param assets Assets to load.
|
||||
*/
|
||||
void queueLoad(const std::vector<Asset*> assets);
|
||||
void queueLoad(const std::vector<std::shared_ptr<Asset>> assets);
|
||||
|
||||
/**
|
||||
* Queue a loading of a single asset. Does not actually begin loading.
|
||||
*
|
||||
* @param assets Assets to load.
|
||||
* @param asset Asset to load.
|
||||
*/
|
||||
void queueLoad(Asset *assets);
|
||||
void queueLoad(const std::shared_ptr<Asset> &asset);
|
||||
|
||||
/**
|
||||
* Takes a list of lists to queue to unload. Does not immediately unload.
|
||||
*
|
||||
* @param assets Assets to unload.
|
||||
*/
|
||||
void queueUnload(const std::vector<Asset*> assets);
|
||||
void queueUnload(const std::vector<std::shared_ptr<Asset>> &assets);
|
||||
|
||||
/**
|
||||
* Takes a single asset to queue to unload. Does not immediately unload.
|
||||
*
|
||||
* @param assets Assets to unload.
|
||||
*/
|
||||
void queueUnload(Asset* assets);
|
||||
void queueUnload(const std::shared_ptr<Asset> &assets);
|
||||
|
||||
/**
|
||||
* Queues load and unload based on the difference between two sets of
|
||||
@ -61,8 +61,8 @@ namespace Dawn {
|
||||
* @param oldAssets Old list of assets to no longer maintain.
|
||||
*/
|
||||
void queueSwap(
|
||||
const std::vector<Asset*> newAssets,
|
||||
const std::vector<Asset*> oldAssets
|
||||
const std::vector<std::shared_ptr<Asset>> &newAssets,
|
||||
const std::vector<std::shared_ptr<Asset>> &oldAssets
|
||||
);
|
||||
|
||||
/**
|
||||
@ -83,7 +83,7 @@ namespace Dawn {
|
||||
* @return The asset element to be loaded.
|
||||
*/
|
||||
template<class T>
|
||||
T * get(std::string name) {
|
||||
std::shared_ptr<T> get(std::string name) {
|
||||
assertTrue(
|
||||
name.size() > 0, "AssetManager::get: name must be greater than 0"
|
||||
);
|
||||
@ -104,14 +104,14 @@ namespace Dawn {
|
||||
* @return The asset element to be loaded.
|
||||
*/
|
||||
template<class T>
|
||||
T * getAndLoad(std::string name) {
|
||||
std::shared_ptr<T> getAndLoad(std::string name) {
|
||||
auto asset = this->get<T>(name);
|
||||
this->queueLoad(asset);
|
||||
return asset;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void unload(T *asset) {
|
||||
void unload(std::shared_ptr<T> asset) {
|
||||
assertUnreachable("AssetManager::unload: NOT IMPLEMENTED");
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ ITimeManager::ITimeManager() {
|
||||
|
||||
}
|
||||
|
||||
void ITimeManager::update(float_t delta) {
|
||||
void ITimeManager::update(const float_t delta) {
|
||||
this->delta = delta;
|
||||
this->time += delta;
|
||||
|
||||
@ -19,28 +19,12 @@ void ITimeManager::update(float_t delta) {
|
||||
this->unpausedTime += delta;
|
||||
|
||||
// Timeout effect provider
|
||||
auto itEffect = this->timeoutProvider.listeners.begin();
|
||||
while(itEffect != this->timeoutProvider.listeners.end()) {
|
||||
itEffect->data -= delta;
|
||||
if(itEffect->data <= 0) {
|
||||
itEffect->callback();
|
||||
itEffect = this->timeoutProvider.listeners.erase(itEffect);
|
||||
continue;
|
||||
}
|
||||
++itEffect;
|
||||
}
|
||||
|
||||
|
||||
// Interval provider
|
||||
auto itInterval = this->intervalProvider.listeners.begin();
|
||||
while(itInterval != this->intervalProvider.listeners.end()) {
|
||||
itInterval->data.time += delta;
|
||||
if(itInterval->data.time >= itInterval->data.interval) {
|
||||
itInterval->callback();
|
||||
itInterval->data.time = 0;
|
||||
}
|
||||
++itInterval;
|
||||
}
|
||||
std::erase_if(this->timeoutProvider.listeners, [&](auto &listener) {
|
||||
listener.data -= delta;
|
||||
if(listener.data > 0) return false;
|
||||
listener.callback();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,6 @@
|
||||
#include "state/StateEvent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct IntervalProviderData {
|
||||
float_t interval;
|
||||
float_t time;
|
||||
};
|
||||
|
||||
class ITimeManager {
|
||||
public:
|
||||
float_t time = 0.0f;
|
||||
@ -22,7 +17,6 @@ namespace Dawn {
|
||||
bool_t isPaused = false;
|
||||
|
||||
StateProviderSet<float_t> timeoutProvider;
|
||||
StateProviderSet<struct IntervalProviderData> intervalProvider;
|
||||
StateEvent<> eventTimePaused;
|
||||
StateEvent<> eventTimeResumed;
|
||||
|
||||
@ -36,7 +30,7 @@ namespace Dawn {
|
||||
*
|
||||
* @param delta Time in seconds to tick the instance by.
|
||||
*/
|
||||
void update(float_t delta);
|
||||
void update(const float_t delta);
|
||||
|
||||
/**
|
||||
* Pauses the game.
|
||||
|
Reference in New Issue
Block a user