update Assets container - template-based now
This commit is contained in:
@@ -126,8 +126,8 @@ std::unique_ptr<Atlas> BlocksPreview::build(
|
||||
size_t count = indices->countBlockDefs();
|
||||
size_t iconSize = ITEM_ICON_SIZE;
|
||||
|
||||
Shader* shader = assets->getShader("ui3d");
|
||||
Atlas* atlas = assets->getAtlas("blocks");
|
||||
auto shader = assets->get<Shader>("ui3d");
|
||||
auto atlas = assets->get<Atlas>("blocks");
|
||||
|
||||
Viewport viewport(iconSize, iconSize);
|
||||
DrawContext pctx(nullptr, viewport, nullptr);
|
||||
|
||||
@@ -60,7 +60,7 @@ void ModelBatch::draw(const model::Model& model) {
|
||||
Lightmap::extract(light, 3) / 15.0f
|
||||
);
|
||||
for (const auto& mesh : model.meshes) {
|
||||
auto texture = assets->getTexture(mesh.texture);
|
||||
auto texture = assets->get<Texture>(mesh.texture);
|
||||
if (texture) {
|
||||
texture->bind();
|
||||
} else {
|
||||
|
||||
@@ -59,7 +59,7 @@ Skybox::~Skybox() {
|
||||
}
|
||||
|
||||
void Skybox::drawBackground(Camera* camera, Assets* assets, int width, int height) {
|
||||
Shader* backShader = assets->getShader("background");
|
||||
auto backShader = assets->get<Shader>("background");
|
||||
backShader->use();
|
||||
backShader->uniformMatrix("u_view", camera->getView(false));
|
||||
backShader->uniform1f("u_zoom", camera->zoom*camera->getFov()/(M_PI*0.5f));
|
||||
@@ -107,7 +107,7 @@ void Skybox::draw(
|
||||
DrawContext ctx = pctx.sub();
|
||||
ctx.setBlendMode(BlendMode::addition);
|
||||
|
||||
Shader* shader = assets->getShader("ui3d");
|
||||
auto shader = assets->get<Shader>("ui3d");
|
||||
shader->use();
|
||||
shader->uniformMatrix("u_projview", camera->getProjView(false));
|
||||
shader->uniformMatrix("u_apply", glm::mat4(1.0f));
|
||||
@@ -117,7 +117,7 @@ void Skybox::draw(
|
||||
float opacity = glm::pow(1.0f-fog, 7.0f);
|
||||
|
||||
for (auto& sprite : sprites) {
|
||||
batch3d->texture(assets->getTexture(sprite.texture));
|
||||
batch3d->texture(assets->get<Texture>(sprite.texture));
|
||||
|
||||
float sangle = daytime * M_PI*2 + sprite.phase;
|
||||
float distance = sprite.distance;
|
||||
|
||||
@@ -68,7 +68,7 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
|
||||
auto assets = engine->getAssets();
|
||||
skybox = std::make_unique<Skybox>(
|
||||
settings.graphics.skyboxResolution.get(),
|
||||
assets->getShader("skybox_gen")
|
||||
assets->get<Shader>("skybox_gen")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -154,9 +154,9 @@ void WorldRenderer::renderLevel(
|
||||
Camera* camera,
|
||||
const EngineSettings& settings
|
||||
) {
|
||||
Assets* assets = engine->getAssets();
|
||||
Atlas* atlas = assets->getAtlas("blocks");
|
||||
Shader* shader = assets->getShader("main");
|
||||
auto assets = engine->getAssets();
|
||||
auto atlas = assets->get<Atlas>("blocks");
|
||||
auto shader = assets->get<Shader>("main");
|
||||
|
||||
auto indices = level->content->getIndices();
|
||||
|
||||
@@ -292,8 +292,8 @@ void WorldRenderer::draw(
|
||||
const EngineSettings& settings = engine->getSettings();
|
||||
skybox->refresh(pctx, world->daytime, 1.0f+world->fog*2.0f, 4);
|
||||
|
||||
Assets* assets = engine->getAssets();
|
||||
Shader* linesShader = assets->getShader("lines");
|
||||
auto assets = engine->getAssets();
|
||||
auto linesShader = assets->get<Shader>("lines");
|
||||
|
||||
// World render scope with diegetic HUD included
|
||||
{
|
||||
@@ -323,7 +323,7 @@ void WorldRenderer::draw(
|
||||
}
|
||||
|
||||
// Rendering fullscreen quad with
|
||||
auto screenShader = assets->getShader("screen");
|
||||
auto screenShader = assets->get<Shader>("screen");
|
||||
screenShader->use();
|
||||
screenShader->uniform1f("u_timer", Window::time());
|
||||
screenShader->uniform1f("u_dayTime", level->getWorld()->daytime);
|
||||
|
||||
@@ -205,7 +205,7 @@ void GUI::draw(const DrawContext* pctx, Assets* assets) {
|
||||
menu->setPos((wsize - menu->getSize()) / 2.0f);
|
||||
uicamera->setFov(wsize.y);
|
||||
|
||||
Shader* uishader = assets->getShader("ui");
|
||||
auto uishader = assets->get<Shader>("ui");
|
||||
uishader->use();
|
||||
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ void Image::draw(const DrawContext* pctx, Assets* assets) {
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
|
||||
auto texture = assets->getTexture(this->texture);
|
||||
auto texture = assets->get<Texture>(this->texture);
|
||||
if (texture && autoresize) {
|
||||
setSize(glm::vec2(texture->getWidth(), texture->getHeight()));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../../core/Font.hpp"
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Shader.hpp"
|
||||
#include "../../core/Texture.hpp"
|
||||
#include "../../render/BlocksPreview.hpp"
|
||||
#include "../GUI.hpp"
|
||||
|
||||
@@ -155,7 +156,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
|
||||
batch->setColor(glm::vec4(1.0f));
|
||||
|
||||
auto previews = assets->getAtlas("block-previews");
|
||||
auto previews = assets->get<Atlas>("block-previews");
|
||||
auto indices = content->getIndices();
|
||||
|
||||
ItemDef* item = indices->getItemDef(stack.getItemId());
|
||||
@@ -177,10 +178,10 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
std::string name = item->icon.substr(index+1);
|
||||
UVRegion region(0.0f, 0.0, 1.0f, 1.0f);
|
||||
if (index == std::string::npos) {
|
||||
batch->texture(assets->getTexture(name));
|
||||
batch->texture(assets->get<Texture>(name));
|
||||
} else {
|
||||
std::string atlasname = item->icon.substr(0, index);
|
||||
Atlas* atlas = assets->getAtlas(atlasname);
|
||||
auto atlas = assets->get<Atlas>(atlasname);
|
||||
if (atlas && atlas->has(name)) {
|
||||
region = atlas->get(name);
|
||||
batch->texture(atlas->getTexture());
|
||||
@@ -194,7 +195,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
}
|
||||
|
||||
if (stack.getCount() > 1) {
|
||||
auto font = assets->getFont("normal");
|
||||
auto font = assets->get<Font>("normal");
|
||||
std::wstring text = std::to_wstring(stack.getCount());
|
||||
|
||||
int x = pos.x+slotSize-text.length()*8;
|
||||
|
||||
@@ -158,7 +158,7 @@ uint Label::getLinesNumber() const {
|
||||
|
||||
void Label::draw(const DrawContext* pctx, Assets* assets) {
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto font = assets->getFont(fontName);
|
||||
auto font = assets->get<Font>(fontName);
|
||||
cache.prepare(font, static_cast<size_t>(glm::abs(getSize().x)));
|
||||
|
||||
if (supplier) {
|
||||
|
||||
@@ -37,7 +37,7 @@ void Plotter::draw(const DrawContext* pctx, Assets* assets) {
|
||||
}
|
||||
|
||||
int current_point = static_cast<int>(points[index % dmwidth]);
|
||||
auto font = assets->getFont("normal");
|
||||
auto font = assets->get<Font>("normal");
|
||||
for (int y = 0; y < dmheight; y += labelsInterval) {
|
||||
std::wstring string;
|
||||
if (current_point/16 == y/labelsInterval) {
|
||||
|
||||
@@ -33,7 +33,7 @@ TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
||||
void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
||||
Panel::draw(pctx, assets);
|
||||
|
||||
font = assets->getFont(label->getFontName());
|
||||
font = assets->get<Font>(label->getFontName());
|
||||
|
||||
if (!isFocused()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user