Converted first thing to shared pointers.
This commit is contained in:
@ -16,11 +16,7 @@ void AssetManager::update() {
|
||||
}
|
||||
|
||||
void AssetManager::queueLoad(const std::vector<std::shared_ptr<Asset>> assets) {
|
||||
std::merge(
|
||||
this->assetsToLoad.begin(), this->assetsToLoad.end(),
|
||||
assets.begin(), assets.end(),
|
||||
this->assetsToLoad.begin()
|
||||
);
|
||||
assetsToLoad.insert(this->assetsToLoad.end(), assets.begin(), assets.end());
|
||||
}
|
||||
|
||||
void AssetManager::queueLoad(const std::shared_ptr<Asset> &asset) {
|
||||
@ -33,11 +29,7 @@ void AssetManager::queueUnload(
|
||||
std::cout <<
|
||||
"Asset list was queued to unload, but is not yet implemented" <<
|
||||
std::endl;
|
||||
std::merge(
|
||||
this->assetsToUnload.begin(), this->assetsToUnload.end(),
|
||||
assets.begin(), assets.end(),
|
||||
this->assetsToUnload.begin()
|
||||
);
|
||||
assetsToUnload.insert(assetsToUnload.end(), assets.begin(), assets.end());
|
||||
}
|
||||
|
||||
void AssetManager::queueUnload(const std::shared_ptr<Asset> &asset) {
|
||||
@ -51,17 +43,17 @@ void AssetManager::queueSwap(
|
||||
const std::vector<std::shared_ptr<Asset>> &newAssets,
|
||||
const std::vector<std::shared_ptr<Asset>> &oldAssets
|
||||
) {
|
||||
std::vector<Asset*> unload;
|
||||
std::vector<Asset*> load;
|
||||
std::vector<std::shared_ptr<Asset>> unload;
|
||||
std::vector<std::shared_ptr<Asset>> load;
|
||||
|
||||
// Determine assets to unload.
|
||||
std::for_each(oldAssets.begin(), oldAssets.end(), [&](Asset *asset){
|
||||
std::for_each(oldAssets.begin(), oldAssets.end(), [&](const auto &asset){
|
||||
auto it = std::find(newAssets.begin(), newAssets.end(), asset);
|
||||
if(it == newAssets.end()) unload.push_back(asset);
|
||||
});
|
||||
|
||||
// Determine assets to load
|
||||
std::for_each(newAssets.begin(), newAssets.end(), [&](Asset *asset){
|
||||
std::for_each(newAssets.begin(), newAssets.end(), [&](const auto &asset){
|
||||
auto it = std::find(oldAssets.begin(), oldAssets.end(), asset);
|
||||
if(it == oldAssets.end()) load.push_back(asset);
|
||||
});
|
||||
|
@ -90,9 +90,9 @@ namespace Dawn {
|
||||
|
||||
auto existing = this->assets.find(name);
|
||||
if(existing != this->assets.end()) {
|
||||
return (T*)existing->second;
|
||||
return dynamic_pointer_cast<T>(existing->second);
|
||||
}
|
||||
auto asset = new T(name);
|
||||
auto asset = std::make_shared<T>(name);
|
||||
this->assets[name] = asset;
|
||||
return asset;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
||||
auto renderables = scene->findComponents<IRenderable>();
|
||||
auto itRenderables = renderables.begin();
|
||||
while(itRenderables != renderables.end()) {
|
||||
vectorAppend(&shaderPassItems, (*itRenderables)->getRenderPasses(context));
|
||||
vectorAppend(shaderPassItems, (*itRenderables)->getRenderPasses(context));
|
||||
++itRenderables;
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ namespace Dawn {
|
||||
DawnGame *game;
|
||||
LanguageAsset *asset;
|
||||
struct Locale locale;
|
||||
LanguageAsset *currentlyLoadedAsset = nullptr;
|
||||
LanguageAsset *loadingAsset = nullptr;
|
||||
std::shared_ptr<LanguageAsset> currentlyLoadedAsset;
|
||||
std::shared_ptr<LanguageAsset> loadingAsset;
|
||||
std::function<void()> eventTeardownLanguageLoaded;
|
||||
|
||||
/** Listens for when the pending language loads. */
|
||||
|
@ -18,7 +18,9 @@ namespace Dawn {
|
||||
* @param man Asset Manasger for getting required assets from.
|
||||
* @return List of required assets this prefab.
|
||||
*/
|
||||
static std::vector<Asset*> getRequiredAssets(AssetManager *man) {
|
||||
static std::vector<std::shared_ptr<Asset>>
|
||||
getRequiredAssets(AssetManager *man)
|
||||
{
|
||||
return P::prefabAssets(man);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ namespace Dawn {
|
||||
public:
|
||||
SimpleTexturedMaterial *material;
|
||||
|
||||
static std::vector<Asset*> prefabAssets(AssetManager *man) {
|
||||
return std::vector<Asset*>();
|
||||
static std::vector<std::shared_ptr<Asset>> prefabAssets(AssetManager *man) {
|
||||
return std::vector<std::shared_ptr<Asset>>();
|
||||
}
|
||||
|
||||
SimpleSpinningCubePrefab(Scene *s, sceneitemid_t i) :
|
||||
|
@ -78,7 +78,7 @@ namespace Dawn {
|
||||
*
|
||||
* @return List of assets required by this scene.
|
||||
*/
|
||||
virtual std::vector<Asset*> getRequiredAssets() = 0;
|
||||
virtual std::vector<std::shared_ptr<Asset>> getRequiredAssets() = 0;
|
||||
|
||||
/**
|
||||
* Method to begin the actual staging of the scene, typically called after
|
||||
|
@ -149,7 +149,7 @@ namespace Dawn {
|
||||
|
||||
while(transformsToCheck.size() > 0) {
|
||||
Transform *tras = *transformsToCheck.begin();
|
||||
vectorAppend(&transformsToCheck, tras->children);
|
||||
vectorAppend(transformsToCheck, tras->children);
|
||||
auto component = tras->item->getComponent<T>();
|
||||
if(component != nullptr) itemsFound.push_back(component);
|
||||
transformsToCheck.erase(transformsToCheck.begin());
|
||||
|
@ -17,7 +17,7 @@ namespace Dawn {
|
||||
flag_t style = 0;
|
||||
flag_t decorations = 0;
|
||||
uint32_t size = 16;
|
||||
TrueTypeAsset *font = nullptr;
|
||||
std::shared_ptr<TrueTypeAsset> font;
|
||||
};
|
||||
|
||||
struct UILabelText {
|
||||
|
@ -12,7 +12,7 @@ namespace Dawn {
|
||||
// @optional
|
||||
StateProperty<std::string> text;
|
||||
// @optional
|
||||
StateProperty<TrueTypeAsset*> font;
|
||||
StateProperty<std::shared_ptr<TrueTypeAsset>> font;
|
||||
// @optional
|
||||
StateProperty<uint32_t> size;
|
||||
// @optional
|
||||
|
@ -20,10 +20,10 @@ namespace Dawn {
|
||||
cube = SimpleSpinningCubePrefab::prefabCreate(this);
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
std::vector<std::shared_ptr<Asset>> getRequiredAssets() override {
|
||||
auto assMan = &this->game->assetManager;
|
||||
std::vector<Asset*> assets;
|
||||
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
||||
std::vector<std::shared_ptr<Asset>> assets;
|
||||
vectorAppend(assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
||||
return assets;
|
||||
}
|
||||
|
||||
|
@ -15,31 +15,7 @@ namespace Dawn {
|
||||
* @param append Pointer to list that will be appended.
|
||||
*/
|
||||
template<typename T>
|
||||
void vectorAppend(std::vector<T> *list, std::vector<T> *append) {
|
||||
assertNotNull(list, "vectorAppend: list cannot be null");
|
||||
assertNotNull(append, "vectorAppend: append cannot be null");
|
||||
|
||||
auto it = append->begin();
|
||||
while(it != append->end()) {
|
||||
list->push_back(*it);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a list on to another list.
|
||||
*
|
||||
* @param list Pointer to list that is being appended to.
|
||||
* @param append List that will be appended.
|
||||
*/
|
||||
template<typename T>
|
||||
void vectorAppend(std::vector<T> *list, std::vector<T> append) {
|
||||
assertNotNull(list, "vectorAppend: list cannot be null");
|
||||
|
||||
auto it = append.begin();
|
||||
while(it != append.end()) {
|
||||
list->push_back(*it);
|
||||
++it;
|
||||
}
|
||||
void vectorAppend(std::vector<T> &list, const std::vector<T> &append) {
|
||||
list.insert(list.end(), append.begin(), append.end());
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ namespace Dawn {
|
||||
canvas = UICanvas::create(this);
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
std::vector<std::shared_ptr<Asset>> getRequiredAssets() override {
|
||||
auto assMan = &this->game->assetManager;
|
||||
std::vector<Asset*> assets;
|
||||
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
||||
std::vector<std::shared_ptr<Asset>> assets;
|
||||
vectorAppend(assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
||||
return assets;
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,9 @@ namespace Dawn {
|
||||
canvas->camera = camera;
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
std::vector<std::shared_ptr<Asset>> getRequiredAssets() override {
|
||||
auto assMan = &this->game->assetManager;
|
||||
std::vector<Asset*> assets;
|
||||
std::vector<std::shared_ptr<Asset>> assets;
|
||||
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
||||
return assets;
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ void ScenePrologue8CustomEventForAfterCharacterFollowup::onStart() {
|
||||
ScenePrologue8::ScenePrologue8(DawnGame *game) : SceneMonologue(game) {
|
||||
}
|
||||
|
||||
std::vector<Asset*> ScenePrologue8::getRequiredAssets() {
|
||||
std::vector<std::shared_ptr<Asset>> ScenePrologue8::getRequiredAssets() {
|
||||
auto man = &this->game->assetManager;
|
||||
std::vector<Asset*> assets = SceneMonologue::getRequiredAssets();
|
||||
auto assets = SceneMonologue::getRequiredAssets();
|
||||
return assets;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace Dawn {
|
||||
|
||||
ScenePrologue8(DawnGame *game);
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override;
|
||||
std::vector<std::shared_ptr<Asset>> getRequiredAssets() override;
|
||||
|
||||
void stage() override;
|
||||
};
|
||||
|
@ -47,11 +47,11 @@ namespace Dawn {
|
||||
gameCamera->player = player->player;
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
std::vector<std::shared_ptr<Asset>> getRequiredAssets() override {
|
||||
auto assMan = &this->game->assetManager;
|
||||
std::vector<Asset*> assets;
|
||||
vectorAppend(&assets, Urchin::getRequiredAssets(assMan));
|
||||
vectorAppend(&assets, Player::getRequiredAssets(assMan));
|
||||
std::vector<std::shared_ptr<Asset>> assets;
|
||||
vectorAppend(assets, Urchin::getRequiredAssets(assMan));
|
||||
vectorAppend(assets, Player::getRequiredAssets(assMan));
|
||||
return assets;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user