diff --git a/src/frontend/ContentGfxCache.cpp b/src/frontend/ContentGfxCache.cpp index 7d3944b7d..c6ba4e1c3 100644 --- a/src/frontend/ContentGfxCache.cpp +++ b/src/frontend/ContentGfxCache.cpp @@ -11,25 +11,25 @@ #include "maths/UVRegion.hpp" #include "voxels/Block.hpp" -ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets) +ContentGfxCache::ContentGfxCache(const Content* content, const Assets& assets) : content(content) { auto indices = content->getIndices(); sideregions = std::make_unique(indices->blocks.count() * 6); - auto atlas = assets->get("blocks"); + const auto& atlas = assets.require("blocks"); const auto& blocks = indices->blocks.getIterable(); for (blockid_t i = 0; i < blocks.size(); i++) { auto def = blocks[i]; for (uint side = 0; side < 6; side++) { const std::string& tex = def->textureFaces[side]; - if (atlas->has(tex)) { - sideregions[i * 6 + side] = atlas->get(tex); - } else if (atlas->has(TEXTURE_NOTFOUND)) { - sideregions[i * 6 + side] = atlas->get(TEXTURE_NOTFOUND); + if (atlas.has(tex)) { + sideregions[i * 6 + side] = atlas.get(tex); + } else if (atlas.has(TEXTURE_NOTFOUND)) { + sideregions[i * 6 + side] = atlas.get(TEXTURE_NOTFOUND); } } if (def->model == BlockModel::custom) { - auto model = assets->require(def->modelName); + auto model = assets.require(def->modelName); // temporary dirty fix tbh if (def->modelName.find(':') == std::string::npos) { for (auto& mesh : model.meshes) { @@ -37,7 +37,7 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets) if (pos == std::string::npos) { continue; } - if (auto region = atlas->getIf(mesh.texture.substr(pos+1))) { + if (auto region = atlas.getIf(mesh.texture.substr(pos+1))) { for (auto& vertex : mesh.vertices) { vertex.uv = region->apply(vertex.uv); } diff --git a/src/frontend/ContentGfxCache.hpp b/src/frontend/ContentGfxCache.hpp index 3d3161d3c..96d46ea59 100644 --- a/src/frontend/ContentGfxCache.hpp +++ b/src/frontend/ContentGfxCache.hpp @@ -22,7 +22,7 @@ class ContentGfxCache { std::unique_ptr sideregions; std::unordered_map models; public: - ContentGfxCache(const Content* content, Assets* assets); + ContentGfxCache(const Content* content, const Assets& assets); ~ContentGfxCache(); inline const UVRegion& getRegion(blockid_t id, int side) const { @@ -30,6 +30,6 @@ class ContentGfxCache { } const model::Model& getModel(blockid_t id) const; - + const Content* getContent() const; }; diff --git a/src/frontend/LevelFrontend.cpp b/src/frontend/LevelFrontend.cpp index 977a0350a..79784375d 100644 --- a/src/frontend/LevelFrontend.cpp +++ b/src/frontend/LevelFrontend.cpp @@ -14,25 +14,28 @@ #include "world/Level.hpp" LevelFrontend::LevelFrontend( - Player* currentPlayer, LevelController* controller, Assets* assets -) : level(controller->getLevel()), + Player* currentPlayer, LevelController* controller, Assets& assets +) : level(*controller->getLevel()), controller(controller), assets(assets), - contentCache(std::make_unique(level->content, assets)) + contentCache(std::make_unique(level.content, assets)) { - assets->store( - BlocksPreview::build(contentCache.get(), assets, level->content), + assets.store( + BlocksPreview::build( + *contentCache, assets, *level.content->getIndices() + ), "block-previews" ); controller->getBlocksController()->listenBlockInteraction( - [=](auto player, const auto& pos, const auto& def, BlockInteraction type) { - auto material = level->content->findBlockMaterial(def.material); + [currentPlayer, controller, &assets](auto player, const auto& pos, const auto& def, BlockInteraction type) { + const auto& level = *controller->getLevel(); + auto material = level.content->findBlockMaterial(def.material); if (material == nullptr) { return; } if (type == BlockInteraction::step) { - auto sound = assets->get(material->stepsSound); + auto sound = assets.get(material->stepsSound); glm::vec3 pos {}; auto soundsCamera = currentPlayer->currentCamera.get(); if (soundsCamera == currentPlayer->spCamera.get() || @@ -58,10 +61,10 @@ LevelFrontend::LevelFrontend( audio::Sound* sound = nullptr; switch (type) { case BlockInteraction::placing: - sound = assets->get(material->placeSound); + sound = assets.get(material->placeSound); break; case BlockInteraction::destruction: - sound = assets->get(material->breakSound); + sound = assets.get(material->breakSound); break; default: break; @@ -83,16 +86,20 @@ LevelFrontend::LevelFrontend( LevelFrontend::~LevelFrontend() = default; -Level* LevelFrontend::getLevel() const { +Level& LevelFrontend::getLevel() { return level; } -Assets* LevelFrontend::getAssets() const { +const Level& LevelFrontend::getLevel() const { + return level; +} + +const Assets& LevelFrontend::getAssets() const { return assets; } -ContentGfxCache* LevelFrontend::getContentGfxCache() const { - return contentCache.get(); +const ContentGfxCache& LevelFrontend::getContentGfxCache() const { + return *contentCache; } LevelController* LevelFrontend::getController() const { diff --git a/src/frontend/LevelFrontend.hpp b/src/frontend/LevelFrontend.hpp index ed149598b..163fc678f 100644 --- a/src/frontend/LevelFrontend.hpp +++ b/src/frontend/LevelFrontend.hpp @@ -9,16 +9,17 @@ class ContentGfxCache; class LevelController; class LevelFrontend { - Level* level; + Level& level; LevelController* controller; - Assets* assets; + const Assets& assets; std::unique_ptr contentCache; public: - LevelFrontend(Player* currentPlayer, LevelController* controller, Assets* assets); + LevelFrontend(Player* currentPlayer, LevelController* controller, Assets& assets); ~LevelFrontend(); - Level* getLevel() const; - Assets* getAssets() const; - ContentGfxCache* getContentGfxCache() const; + Level& getLevel(); + const Level& getLevel() const; + const Assets& getAssets() const; + const ContentGfxCache& getContentGfxCache() const; LevelController* getController() const; }; diff --git a/src/frontend/debug_panel.cpp b/src/frontend/debug_panel.cpp index a8d205b36..9043f5b9d 100644 --- a/src/frontend/debug_panel.cpp +++ b/src/frontend/debug_panel.cpp @@ -42,8 +42,8 @@ static std::shared_ptr