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