chore: more changes to unique_ptr and shared_ptr

This commit is contained in:
Almamu 2025-04-26 00:23:21 +02:00
parent 176ffc2604
commit ea88eabb11
35 changed files with 108 additions and 99 deletions

View File

@ -59,21 +59,21 @@ CWallpaperApplication::~CWallpaperApplication () {
delete m_browserContext;
}
void CWallpaperApplication::setupContainer (CCombinedContainer& container, const std::string& bg) const {
void CWallpaperApplication::setupContainer (const std::shared_ptr<CCombinedContainer>& container, const std::string& bg) const {
const std::filesystem::path basepath = bg;
container.add (new CDirectory (basepath));
container.addPkg (basepath / "scene.pkg");
container.addPkg (basepath / "gifscene.pkg");
container->add (std::make_shared<CDirectory> (basepath));
container->addPkg (basepath / "scene.pkg");
container->addPkg (basepath / "gifscene.pkg");
try {
container.add (new CDirectory (this->m_context.settings.general.assets));
container->add (std::make_shared <CDirectory> (this->m_context.settings.general.assets));
} catch (CAssetLoadException&) {
sLog.exception ("Cannot find a valid assets folder, resolved to ", this->m_context.settings.general.assets);
}
// TODO: move this somewhere else?
auto* virtualContainer = new CVirtualContainer ();
auto virtualContainer = std::make_shared <CVirtualContainer> ();
//
// Had to get a little creative with the effects to achieve the same bloom effect without any custom code
@ -206,7 +206,7 @@ void CWallpaperApplication::setupContainer (CCombinedContainer& container, const
"}"
);
container.add (virtualContainer);
container->add (virtualContainer);
}
void CWallpaperApplication::loadBackgrounds () {
@ -227,9 +227,9 @@ void CWallpaperApplication::loadBackgrounds () {
}
Core::CProject* CWallpaperApplication::loadBackground (const std::string& bg) {
auto* container = new CCombinedContainer ();
const auto container = std::make_shared <CCombinedContainer> ();
this->setupContainer (*container, bg);
this->setupContainer (container, bg);
return Core::CProject::fromFile ("project.json", container);
}

View File

@ -79,7 +79,7 @@ class CWallpaperApplication {
* @param container
* @param bg
*/
void setupContainer (CCombinedContainer& container, const std::string& bg) const;
void setupContainer (const std::shared_ptr<CCombinedContainer>& container, const std::string& bg) const;
/**
* Loads projects based off the settings
*/

View File

@ -8,14 +8,14 @@ using namespace WallpaperEngine::Assets;
CCombinedContainer::CCombinedContainer () : CContainer () {}
void CCombinedContainer::add (CContainer* container) {
void CCombinedContainer::add (const std::shared_ptr<CContainer>& container) {
this->m_containers.emplace_back (container);
}
void CCombinedContainer::addPkg (const std::filesystem::path& path) {
try {
// add the package to the list
this->add (new CPackage (path));
this->add (std::make_shared<CPackage> (path));
sLog.out ("Detected ", path.filename (), " file at ", path, ". Adding to list of searchable paths");
} catch (CPackageLoadException&) {
// ignore this error, the package file was not found
@ -27,7 +27,7 @@ void CCombinedContainer::addPkg (const std::filesystem::path& path) {
}
std::filesystem::path CCombinedContainer::resolveRealFile (const std::filesystem::path& filename) const {
for (const auto cur : this->m_containers) {
for (const auto& cur : this->m_containers) {
try {
// try to read the file on the current container, if the file doesn't exists
// an exception will be thrown
@ -42,7 +42,7 @@ std::filesystem::path CCombinedContainer::resolveRealFile (const std::filesystem
}
std::shared_ptr<const uint8_t[]> CCombinedContainer::readFile (const std::filesystem::path& filename, uint32_t* length) const {
for (const auto cur : this->m_containers) {
for (const auto& cur : this->m_containers) {
try {
// try to read the file on the current container, if the file doesn't exists
// an exception will be thrown

View File

@ -19,7 +19,7 @@ class CCombinedContainer final : public CContainer {
*
* @param container
*/
void add (CContainer* container);
void add (const std::shared_ptr<CContainer>& container);
/**
* Adds the given package to the list
*
@ -34,6 +34,6 @@ class CCombinedContainer final : public CContainer {
private:
/** The list of containers to search files off from */
std::vector<CContainer*> m_containers;
std::vector<std::shared_ptr<CContainer>> m_containers;
};
}; // namespace WallpaperEngine::Assets

View File

@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <utility>
namespace WallpaperEngine::Assets {
/**
@ -9,7 +10,7 @@ namespace WallpaperEngine::Assets {
class CFileEntry {
public:
CFileEntry (std::shared_ptr<const uint8_t[]> content, uint32_t length) :
content (content),
content (std::move(content)),
length (length) {}
~CFileEntry() = default;

View File

@ -324,7 +324,7 @@ std::unique_ptr<CTexture::TextureHeader> CTexture::parseHeader (const char* file
mipmaps.emplace_back (parseMipmap (header.get (), &fileData));
// add the pixmaps back
header->images.insert (std::pair (image, mipmaps));
header->images.emplace (image, mipmaps);
pointer = reinterpret_cast<const uint32_t*> (fileData);
}

View File

@ -5,18 +5,22 @@
using namespace WallpaperEngine::Assets;
CVirtualContainer::CVirtualContainer () :
m_virtualFiles() {}
void CVirtualContainer::add (const std::filesystem::path& filename, const std::shared_ptr<const uint8_t[]>& contents, uint32_t length) {
this->m_virtualFiles.insert (std::pair (filename, std::make_unique<CFileEntry> (contents, length)));
this->m_virtualFiles.emplace (filename, std::make_unique<CFileEntry> (contents, length));
}
void CVirtualContainer::add (const std::filesystem::path& filename, const std::string& contents) {
std::shared_ptr<uint8_t[]> copy = std::shared_ptr<uint8_t[]> (new uint8_t [contents.length () + 1]);
size_t length = contents.length () + 1;
std::shared_ptr<uint8_t[]> copy = std::shared_ptr<uint8_t[]> (new uint8_t [length]);
// copy the text AND the \0
memcpy (copy.get(), contents.c_str (), contents.length () + 1);
memcpy (copy.get(), contents.c_str (), length);
// finally add to the container
this->add (filename, copy, contents.length () + 1);
this->add (filename, copy, length);
}
void CVirtualContainer::add (const std::filesystem::path& filename, const char* contents) {

View File

@ -16,6 +16,7 @@ using json = nlohmann::json;
*/
class CVirtualContainer final : public CContainer {
public:
CVirtualContainer ();
/**
* Adds a new file to the virtual container
*

View File

@ -32,7 +32,7 @@ CObject::CObject (
m_dependencies (std::move(dependencies)) {}
const CObject* CObject::fromJSON (
const json& data, const Wallpapers::CScene* scene, const CContainer* container
const json& data, const Wallpapers::CScene* scene, const std::shared_ptr<const CContainer>& container
) {
const auto id = jsonFindRequired <int> (data, "id", "Objects must have id");
const auto visible = jsonFindUserConfig<CUserSettingBoolean> (data, scene->getProject(), "visible", true);

View File

@ -29,7 +29,7 @@ class CObject {
friend class Wallpapers::CScene;
public:
static const CObject* fromJSON (const json& data, const Wallpapers::CScene* scene, const CContainer* container);
static const CObject* fromJSON (const json& data, const Wallpapers::CScene* scene, const std::shared_ptr<const CContainer>& container);
template <class T> [[nodiscard]] const T* as () const {
assert (is<T> ());

View File

@ -15,14 +15,14 @@ using namespace WallpaperEngine::Assets;
static int backgroundId = -1;
CProject::CProject (
std::string title, std::string type, std::string workshopid, const CContainer* container,
std::string title, std::string type, std::string workshopid, std::shared_ptr<const CContainer> container,
bool supportsaudioprocessing, const std::map<std::string, Projects::CProperty*>& properties
) :
m_workshopid(std::move(workshopid)),
m_title (std::move(title)),
m_type (std::move(type)),
m_wallpaper (nullptr),
m_container (container),
m_container (std::move(container)),
m_properties (properties),
m_supportsaudioprocessing (supportsaudioprocessing) {}
@ -34,7 +34,7 @@ CProject::~CProject () {
this->m_properties.clear ();
}
CProject* CProject::fromFile (const std::string& filename, const CContainer* container) {
CProject* CProject::fromFile (const std::string& filename, std::shared_ptr<const CContainer> container) {
json content = json::parse (container->readFileAsString (filename));
const auto dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
@ -66,7 +66,7 @@ CProject* CProject::fromFile (const std::string& filename, const CContainer* con
continue;
}
properties.insert (std::pair (property->getName (), property));
properties.emplace (property->getName (), property);
}
}
}
@ -118,7 +118,7 @@ const std::string& CProject::getWorkshopId () const {
return this->m_workshopid;
}
const CContainer* CProject::getContainer () const {
std::shared_ptr<const CContainer> CProject::getContainer () const {
return this->m_container;
}

View File

@ -22,7 +22,7 @@ class CWallpaper;
class CProject {
public:
~CProject();
static CProject* fromFile (const std::string& filename, const CContainer* container);
static CProject* fromFile (const std::string& filename, std::shared_ptr<const CContainer> container);
[[nodiscard]] const CWallpaper* getWallpaper () const;
@ -32,11 +32,11 @@ class CProject {
[[nodiscard]] const std::string& getWorkshopId () const;
[[nodiscard]] bool supportsAudioProcessing () const;
[[nodiscard]] const CContainer* getContainer () const;
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const;
protected:
CProject (
std::string title, std::string type, std::string workshopid, const CContainer* container,
std::string title, std::string type, std::string workshopid, std::shared_ptr<const CContainer> container,
bool supportsaudioprocessing, const std::map<std::string, Projects::CProperty*>& properties);
void setWallpaper (const CWallpaper* wallpaper);
@ -49,6 +49,6 @@ class CProject {
const std::string m_type;
const bool m_supportsaudioprocessing;
const CWallpaper* m_wallpaper;
const CContainer* m_container;
std::shared_ptr<const CContainer> m_container;
};
} // namespace WallpaperEngine::Core

View File

@ -37,7 +37,7 @@ CEffect::CEffect (
const CEffect* CEffect::fromJSON (
const json& data, const CUserSettingBoolean* visible, const CProject& project, const Images::CMaterial* material,
const CContainer* container
std::shared_ptr<const CContainer> container
) {
const auto file = jsonFindRequired <std::string> (data, "file", "Object effect must have a file");
const auto effectpasses_it = data.find ("passes");
@ -79,7 +79,7 @@ std::map<std::string, int> CEffect::combosFromJSON (const json::const_iterator&
auto uppercase = std::string (cur.key ());
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
combos.insert (std::pair (uppercase, cur.value ()));
combos.emplace (uppercase, cur.value ());
}
return combos;
@ -153,7 +153,7 @@ std::map<std::string, const Core::Objects::Effects::Constants::CShaderConstant*>
}
}
constants.insert (std::pair (cur.key (), constant));
constants.emplace (cur.key (), constant);
}
return constants;
@ -178,7 +178,7 @@ std::vector<std::string> CEffect::dependenciesFromJSON (const json::const_iterat
}
std::vector<const Images::CMaterial*> CEffect::materialsFromJSON (
const json::const_iterator& passes_it, const std::string& name, const CContainer* container,
const json::const_iterator& passes_it, const std::string& name, const std::shared_ptr<const CContainer>& container,
std::map<int, Images::CMaterial::OverrideInfo> overrides
) {
std::vector<const Images::CMaterial*> materials;
@ -203,7 +203,7 @@ std::vector<const Images::CMaterial*> CEffect::materialsFromJSON (
if (bind_it != cur.end ()) {
for (const auto& bindCur : (*bind_it)) {
const auto* bind = Effects::CBind::fromJSON (bindCur);
textureBindings.insert (std::pair (bind->getIndex (), bind));
textureBindings.emplace (bind->getIndex (), bind);
}
}
@ -278,11 +278,11 @@ std::map<int, Images::CMaterial::OverrideInfo> CEffect::overridesFromJSON (
name = texture;
}
override.textures.insert (std::pair (textureNumber, name));
override.textures.emplace (textureNumber, name);
}
}
result.insert (std::pair (materialNumber, override));
result.emplace (materialNumber, override);
}
return result;

View File

@ -33,7 +33,7 @@ class CEffect {
static const CEffect* fromJSON (
const json& data, const CUserSettingBoolean* visible, const CProject& object, const Images::CMaterial* material,
const CContainer* container);
std::shared_ptr<const CContainer> container);
/**
* @return List of dependencies for the effect to work
@ -71,8 +71,8 @@ class CEffect {
static std::vector<const Effects::CFBO*> fbosFromJSON (const json::const_iterator& fbos_it);
static std::vector<std::string> dependenciesFromJSON (const json::const_iterator& dependencies_it);
static std::vector<const Images::CMaterial*> materialsFromJSON (
const json::const_iterator& passes_it, const std::string& name, const CContainer* container,
std::map<int, Images::CMaterial::OverrideInfo>);
const json::const_iterator& passes_it, const std::string& name,
const std::shared_ptr<const CContainer>& container, std::map<int, Images::CMaterial::OverrideInfo>);
static std::map<int, Images::CMaterial::OverrideInfo> overridesFromJSON (
const json::const_iterator& passes_it, const Images::CMaterial* material, const CProject& project);

View File

@ -33,7 +33,7 @@ CImage::CImage (
m_effects (std::move(effects)) {}
const WallpaperEngine::Core::CObject* CImage::fromJSON (
const Wallpapers::CScene* scene, const json& data, const CContainer* container,
const Wallpapers::CScene* scene, const json& data, const std::shared_ptr<const CContainer>& container,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, const CUserSettingVector3* angles, const json::const_iterator& effects_it,
std::vector<int> dependencies

View File

@ -30,7 +30,7 @@ class CImage : public CObject {
public:
static const CObject* fromJSON (
const Wallpapers::CScene* scene, const json& data, const CContainer* container,
const Wallpapers::CScene* scene, const json& data, const std::shared_ptr<const CContainer>& container,
const CUserSettingBoolean* visible, int id, std::string name, const CUserSettingVector3* origin,
const CUserSettingVector3* scale, const CUserSettingVector3* angles, const json::const_iterator& effects_it,
std::vector<int> dependencies);

View File

@ -5,7 +5,7 @@
using namespace WallpaperEngine::Core::Objects;
const CParticle* CParticle::fromFile (
const Wallpapers::CScene* scene, const std::string& filename, const CContainer* container,
const Wallpapers::CScene* scene, const std::string& filename, std::shared_ptr<const CContainer> container,
const CUserSettingBoolean* visible, int id, const std::string& name, const CUserSettingVector3* origin,
const CUserSettingVector3* angles, const CUserSettingVector3* scale, std::vector<int> dependencies
) {

View File

@ -18,7 +18,7 @@ class CParticle : public CObject {
public:
static const CParticle* fromFile (
const Wallpapers::CScene* scene, const std::string& filename, const CContainer* container,
const Wallpapers::CScene* scene, const std::string& filename, std::shared_ptr<const CContainer> container,
const CUserSettingBoolean* visible, int id, const std::string& name, const CUserSettingVector3* origin,
const CUserSettingVector3* angles, const CUserSettingVector3* scale, std::vector<int> dependencies);

View File

@ -29,14 +29,14 @@ CMaterial::CMaterial (
m_solidlayer (solidlayer) {}
const CMaterial* CMaterial::fromFile (
const std::filesystem::path& filename, const CContainer* container, bool solidlayer,
const std::filesystem::path& filename, const std::shared_ptr<const CContainer>& container, bool solidlayer,
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
) {
return fromJSON (filename, json::parse (container->readFileAsString (filename)), solidlayer, std::move(textureBindings), overrides);
}
const CMaterial* CMaterial::fromFile (
const std::filesystem::path& filename, const std::string& target, const CContainer* container, bool solidlayer,
const std::filesystem::path& filename, const std::string& target, const std::shared_ptr<const CContainer>& container, bool solidlayer,
std::map<int, const Effects::CBind*> textureBindings, const OverrideInfo* overrides
) {
return fromJSON (filename, json::parse (container->readFileAsString (filename)), target, solidlayer, std::move(textureBindings), overrides);

View File

@ -26,10 +26,10 @@ class CMaterial {
};
static const CMaterial* fromFile (
const std::filesystem::path& filename, const Assets::CContainer* container, bool solidlayer = false,
const std::filesystem::path& filename, const std::shared_ptr<const CContainer>& container, bool solidlayer = false,
std::map<int, const Effects::CBind*> textureBindings = {}, const OverrideInfo* overrides = nullptr);
static const CMaterial* fromFile (
const std::filesystem::path& filename, const std::string& target, const Assets::CContainer* container,
const std::filesystem::path& filename, const std::string& target, const std::shared_ptr<const CContainer>& container,
bool solidlayer = false, std::map<int, const Effects::CBind*> textureBindings = {},
const OverrideInfo* overrides = nullptr);
static const CMaterial* fromJSON (

View File

@ -35,7 +35,7 @@ const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* o
int textureNumber = -1;
for (const auto& cur : (*textures_it))
textures.insert (std::pair (++textureNumber, cur.is_null () ? "" : cur));
textures.emplace (++textureNumber, cur.is_null () ? "" : cur);
}
if (combos_it != data.end ()) {
@ -44,7 +44,7 @@ const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* o
std::string uppercase = std::string (cur.key ());
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
combos.insert (std::pair (uppercase, cur.value ()));
combos.emplace (uppercase, cur.value ());
} else {
sLog.exception ("unexpected non-integer combo on pass");
}

View File

@ -1,4 +1,6 @@
#include "CScene.h"
#include <utility>
#include "WallpaperEngine/Core/CProject.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
@ -9,15 +11,15 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Wallpapers;
CScene::CScene (
const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor,
const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold,
bool cameraFade, bool cameraParallax, float cameraParallaxAmount, float cameraParallaxDelay,
float cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, float cameraShakeAmplitude,
float cameraShakeRoughness, float cameraShakeSpeed, const CUserSettingVector3* clearColor,
const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor
const CProject& project, std::shared_ptr<const CContainer> container, const Scenes::CCamera* camera,
glm::vec3 ambientColor, const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength,
const CUserSettingFloat* bloomThreshold, bool cameraFade, bool cameraParallax, float cameraParallaxAmount,
float cameraParallaxDelay, float cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake,
float cameraShakeAmplitude, float cameraShakeRoughness, float cameraShakeSpeed,
const CUserSettingVector3* clearColor, const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor
) :
CWallpaper (Type, project),
m_container (container),
m_container (std::move(container)),
m_camera (camera),
m_ambientColor (ambientColor),
m_bloom (bloom),
@ -37,7 +39,7 @@ CScene::CScene (
m_orthogonalProjection (orthogonalProjection),
m_skylightColor (skylightColor) {}
const CScene* CScene::fromFile (const std::string& filename, const CProject& project, const CContainer* container) {
const CScene* CScene::fromFile (const std::string& filename, const CProject& project, const std::shared_ptr<const CContainer>& container) {
json content = json::parse (container->readFileAsString (filename));
const auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
@ -85,12 +87,12 @@ const std::vector<const CObject*>& CScene::getObjectsByRenderOrder () const {
void CScene::insertObject (const CObject* object) {
/// TODO: XXXHACK -- TO REMOVE WHEN PARTICLE SUPPORT IS PROPERLY IMPLEMENTED
if (object != nullptr) {
this->m_objects.insert (std::pair (object->getId (), object));
this->m_objects.emplace (object->getId (), object);
this->m_objectsByRenderOrder.emplace_back (object);
}
}
const CContainer* CScene::getContainer () const {
std::shared_ptr<const CContainer> CScene::getContainer () const {
return this->m_container;
}

View File

@ -17,7 +17,7 @@ using json = nlohmann::json;
class CScene : public CWallpaper {
public:
static const CScene* fromFile (const std::string& filename, const CProject& project, const CContainer* container);
static const CScene* fromFile (const std::string& filename, const CProject& project, const std::shared_ptr<const CContainer>& container);
[[nodiscard]] const std::map<uint32_t, const CObject*>& getObjects () const;
[[nodiscard]] const std::vector<const CObject*>& getObjectsByRenderOrder () const;
@ -45,21 +45,21 @@ class CScene : public CWallpaper {
friend class CWallpaper;
CScene (
const CProject& project, const CContainer* container, const Scenes::CCamera* camera, glm::vec3 ambientColor,
const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength, const CUserSettingFloat* bloomThreshold,
bool cameraFade, bool cameraParallax, float cameraParallaxAmount, float cameraParallaxDelay,
float cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake, float cameraShakeAmplitude,
float cameraShakeRoughness, float cameraShakeSpeed, const CUserSettingVector3* clearColor,
const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor);
const CProject& project, std::shared_ptr<const CContainer> container, const Scenes::CCamera* camera,
glm::vec3 ambientColor, const CUserSettingBoolean* bloom, const CUserSettingFloat* bloomStrength,
const CUserSettingFloat* bloomThreshold, bool cameraFade, bool cameraParallax, float cameraParallaxAmount,
float cameraParallaxDelay, float cameraParallaxMouseInfluence, bool cameraPreview, bool cameraShake,
float cameraShakeAmplitude, float cameraShakeRoughness, float cameraShakeSpeed,
const CUserSettingVector3* clearColor, const Scenes::CProjection* orthogonalProjection, glm::vec3 skylightColor);
static const std::string Type;
void insertObject (const CObject* object);
const CContainer* getContainer () const;
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const;
private:
const CContainer* m_container;
const std::shared_ptr<const CContainer> m_container;
const Scenes::CCamera* m_camera;
// data from general section on the json

View File

@ -16,7 +16,7 @@ Wallpapers::CScene* CObject::getScene () const {
return this->m_scene;
}
const CContainer* CObject::getContainer () const {
std::shared_ptr<const CContainer> CObject::getContainer () const {
return this->getScene ()->getContainer ();
}

View File

@ -31,7 +31,7 @@ class CObject : public Helpers::CContextAware {
virtual void render () = 0;
[[nodiscard]] Wallpapers::CScene* getScene () const;
[[nodiscard]] const CContainer* getContainer () const;
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const;
[[nodiscard]] int getId () const;
protected:

View File

@ -52,7 +52,7 @@ CWallpaper::CWallpaper (
CWallpaper::~CWallpaper () = default;
const CContainer* CWallpaper::getContainer () const {
std::shared_ptr<const CContainer> CWallpaper::getContainer () const {
return this->m_wallpaperData->getProject ().getContainer ();
}
@ -260,13 +260,13 @@ std::shared_ptr<const CFBO> CWallpaper::createFBO (
) {
std::shared_ptr<const CFBO> fbo = std::make_shared <CFBO> (name, format, flags, scale, realWidth, realHeight, textureWidth, textureHeight);
this->m_fbos.insert (std::pair (name, fbo));
this->m_fbos.emplace (name, fbo);
return fbo;
}
void CWallpaper::aliasFBO (const std::string& alias, const std::shared_ptr<const CFBO>& original) {
this->m_fbos.insert (std::pair (alias, original));
this->m_fbos.emplace (alias, original);
}
const std::map<std::string, std::shared_ptr<const CFBO>>& CWallpaper::getFBOs () const {

View File

@ -59,7 +59,7 @@ class CWallpaper : public Helpers::CContextAware {
/**
* @return The container to resolve files for this wallpaper
*/
[[nodiscard]] const CContainer* getContainer () const;
[[nodiscard]] std::shared_ptr<const CContainer> getContainer () const;
/**
* @return The current audio context for this wallpaper

View File

@ -36,7 +36,7 @@ void CEffect::generatePasses () {
void CEffect::generateFBOs () {
for (const auto& cur : this->m_effect->getFbos ()) {
// TODO: IS THAT DIVISION OKAY? SHOULDN'T IT BE A MULTIPLICATION? WTF?
this->m_fbos.insert (std::pair (
this->m_fbos.emplace (
cur->getName(),
new CFBO (
// TODO: SET PROPER FLAGS AND FORMAT
@ -47,7 +47,7 @@ void CEffect::generateFBOs () {
this->m_image->getSize ().x / cur->getScale (),
this->m_image->getSize ().y / cur->getScale ()
)
));
);
}
}

View File

@ -263,7 +263,7 @@ void CImage::setup () {
if (this->m_image->getColorBlendMode () > 0) {
Core::Objects::Images::CMaterial::OverrideInfo overrides;
overrides.combos.insert (std::pair ("BLENDMODE", this->m_image->getColorBlendMode ()));
overrides.combos.emplace ("BLENDMODE", this->m_image->getColorBlendMode ());
const auto material =
Core::Objects::Images::CMaterial::fromFile ("materials/util/effectpassthrough.json", this->getContainer (), false, {}, &overrides);

View File

@ -18,7 +18,7 @@ using namespace WallpaperEngine::Assets;
namespace WallpaperEngine::Render::Shaders {
CShader::CShader (
const CContainer* container, std::string filename, const std::map<std::string, int>& combos,
std::shared_ptr<const CContainer> container, std::string filename, const std::map<std::string, int>& combos,
const std::map<int, std::string>& textures, const std::map<std::string, const CShaderConstant*>& constants
) :
m_file (std::move (filename)),

View File

@ -42,7 +42,7 @@ class CShader {
* @param recursive Whether the compiler should add base definitions or not
*/
CShader (
const CContainer* container, std::string filename,
std::shared_ptr<const CContainer> container, std::string filename,
const std::map<std::string, int>& combos, const std::map<int, std::string>& textures,
const std::map<std::string, const CShaderConstant*>& constants);
/**

View File

@ -55,12 +55,14 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Render::Shaders;
CShaderUnit::CShaderUnit (CGLSLContext::UnitType type, std::string file, std::string content,
const CContainer* container, const std::map<std::string, const CShaderConstant*>& constants,
const std::map<int, std::string>& passTextures, const std::map<std::string, int>& combos) :
CShaderUnit::CShaderUnit (
CGLSLContext::UnitType type, std::string file, std::string content, std::shared_ptr<const CContainer> container,
const std::map<std::string, const CShaderConstant*>& constants, const std::map<int, std::string>& passTextures,
const std::map<std::string, int>& combos
) :
m_type (type),
m_link (nullptr),
m_container (container),
m_container (std::move(container)),
m_file (std::move (file)),
m_constants (constants),
m_content (std::move(content)),
@ -334,7 +336,7 @@ void CShaderUnit::parseComboConfiguration (const std::string& content, int defau
const auto entry = this->m_combos.find (combo->get<std::string> ());
// add the combo to the found list
this->m_usedCombos.insert (std::pair (*combo, true));
this->m_usedCombos.emplace (*combo, true);
// if the combo was not found in the predefined values this means that the default value in the JSON data can be
// used so only define the ones that are not already defined
@ -343,11 +345,11 @@ void CShaderUnit::parseComboConfiguration (const std::string& content, int defau
// if no combo is defined just load the default settings
if (defvalue == data.end ()) {
// TODO: PROPERLY SUPPORT EMPTY COMBOS
this->m_discoveredCombos.insert (std::pair (*combo, (int) defaultValue));
this->m_discoveredCombos.emplace (*combo, (int) defaultValue);
} else if (defvalue->is_number_float ()) {
sLog.exception ("float combos are not supported in shader ", this->m_file, ". ", *combo);
} else if (defvalue->is_number_integer ()) {
this->m_discoveredCombos.insert (std::pair (*combo, defvalue->get<int> ()));
this->m_discoveredCombos.emplace (*combo, defvalue->get<int> ());
} else if (defvalue->is_string ()) {
sLog.exception ("string combos are not supported in shader ", this->m_file, ". ", *combo);
} else {
@ -475,16 +477,14 @@ void CShaderUnit::parseParameterConfiguration (
if (isRequired) {
// add the new combo to the list
this->m_discoveredCombos.insert (std::pair (*combo, comboValue));
this->m_discoveredCombos.emplace (*combo, comboValue);
// textures linked to combos need to be tracked too
if (this->m_usedCombos.find (*combo) == this->m_usedCombos.end ())
this->m_usedCombos.insert (std::pair (*combo, true));
this->m_usedCombos.emplace (*combo, true);
}
}
if (textureName != data.end ())
this->m_defaultTextures.insert (std::pair (index, *textureName));
this->m_defaultTextures.emplace (index, *textureName);
// samplers are not saved, we can ignore them for now
return;

View File

@ -20,7 +20,8 @@ using namespace WallpaperEngine::Core::Objects::Effects::Constants;
*/
class CShaderUnit {
public:
CShaderUnit (CGLSLContext::UnitType type, std::string file, std::string content, const CContainer* container,
CShaderUnit (
CGLSLContext::UnitType type, std::string file, std::string content, std::shared_ptr<const CContainer> container,
const std::map<std::string, const CShaderConstant*>& constants, const std::map<int, std::string>& passTextures,
const std::map<std::string, int>& combos);
~CShaderUnit () = default;
@ -150,6 +151,6 @@ class CShaderUnit {
/**
* The container to source files from
*/
const CContainer* m_container;
const std::shared_ptr<const CContainer> m_container;
};
}

View File

@ -194,7 +194,7 @@ Render::CObject* CScene::createObject (const Core::CObject* object) {
}
if (renderObject != nullptr)
this->m_objects.insert (std::pair (renderObject->getId (), renderObject));
this->m_objects.emplace (renderObject->getId (), renderObject);
return renderObject;
}

View File

@ -34,7 +34,7 @@ class CWPSchemeHandler : public CefResourceHandler {
private:
const Core::CProject* m_project;
const Assets::CContainer* m_container;
std::shared_ptr<const Assets::CContainer> m_container;
std::shared_ptr<const uint8_t[]> m_contents;
uint32_t m_filesize;
std::string m_mimeType;