Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/client/lightview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
LightView::LightView(const Size& size) : m_pool(g_drawPool.get(DrawPoolType::LIGHT)) {
g_mainDispatcher.addEvent([this, size] {
m_texture = std::make_shared<Texture>(size);
m_texture->setCached(true);
m_texture->setSmooth(true);
});
}
Expand Down
1 change: 1 addition & 0 deletions src/client/thingtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ void ThingType::loadTexture(const int animationPhase)
m_opaque = !fullImage->hasTransparentPixel();

textureData.source = std::make_shared<Texture>(fullImage, true, false);
textureData.source->setCached(true);
}

Size ThingType::getBestTextureDimension(int w, int h, const int count)
Expand Down
4 changes: 3 additions & 1 deletion src/client/thingtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,10 @@ class ThingType final : public LuaObject
const Timer getLastTimeUsage() const { return m_lastTimeUsage; }

void unload() {
for (auto& data : m_textureData)
for (auto& data : m_textureData) {
if (data.source) data.source->setCached(false);
data.source = nullptr;
}
}

PLAYER_ACTION getDefaultAction() { return m_defaultAction; }
Expand Down
2 changes: 2 additions & 0 deletions src/client/uisprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ void UISprite::setSpriteId(const int id)
}

const auto& image = g_sprites.getSpriteImage(id);
if (m_sprite) m_sprite->setCached(false);
m_sprite = image ? std::make_shared<Texture>(image) : nullptr;
m_sprite->setCached(true);
}

void UISprite::onStyleApply(const std::string_view styleName, const OTMLNodePtr& styleNode)
Expand Down
5 changes: 5 additions & 0 deletions src/framework/graphics/animatedtexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class AnimatedTexture final : public Texture

void setSmooth(bool smooth) override;
void setRepeat(bool repeat) override;
void setCached(bool v) override {
Texture::setCached(v);
for (const auto& frame : m_frames)
frame->setCached(v);
}

uint32_t getNumPlays() const { return m_numPlays; }
void setNumPlays(const uint32_t n) { m_numPlays = n; }
Expand Down
51 changes: 33 additions & 18 deletions src/framework/graphics/drawpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ DrawPool* DrawPool::create(const DrawPoolType type)
if (type == DrawPoolType::MAP) {
pool->m_framebuffer->m_useAlphaWriting = false;
pool->m_framebuffer->disableBlend();
} else if (type == DrawPoolType::FOREGROUND) {
}
else if (type == DrawPoolType::FOREGROUND) {
pool->setFPS(10);

// creates a temporary framebuffer with smoothing.
pool->m_temporaryFramebuffers.emplace_back(std::make_shared<FrameBuffer>());
}
} else if (type == DrawPoolType::LIGHT) {
}
else if (type == DrawPoolType::LIGHT) {
pool->m_hashCtrl = true;
} else {
}
else {
pool->m_alwaysGroupDrawings = true; // CREATURE_INFORMATION & TEXT
pool->setFPS(60);
}
Expand All @@ -58,7 +61,8 @@ void DrawPool::add(const Color& color, const TexturePtr& texture, DrawMethod&& m
if (m_type == DrawPoolType::FOREGROUND) {
order = FIRST;
agroup = false;
} else if (m_type == DrawPoolType::MAP && order == FIRST && !conductor.agroup)
}
else if (m_type == DrawPoolType::MAP && order == FIRST && !conductor.agroup)
order = THIRD;

if (agroup) {
Expand All @@ -72,7 +76,8 @@ void DrawPool::add(const Color& color, const TexturePtr& texture, DrawMethod&& m
coords->append(coordsBuffer.get());
else
addCoords(coords, method);
} else {
}
else {
bool addNewObj = true;

auto& list = m_objects[order];
Expand All @@ -94,7 +99,8 @@ void DrawPool::add(const Color& color, const TexturePtr& texture, DrawMethod&& m

if (coordsBuffer) {
draw.coords->append(coordsBuffer.get());
} else
}
else
addCoords(draw.coords.get(), method);
}
}
Expand All @@ -106,13 +112,17 @@ void DrawPool::addCoords(CoordsBuffer* buffer, const DrawMethod& method)
{
if (method.type == DrawMethodType::BOUNDING_RECT) {
buffer->addBoudingRect(method.dest, method.intValue);
} else if (method.type == DrawMethodType::RECT) {
}
else if (method.type == DrawMethodType::RECT) {
buffer->addRect(method.dest, method.src);
} else if (method.type == DrawMethodType::TRIANGLE) {
}
else if (method.type == DrawMethodType::TRIANGLE) {
buffer->addTriangle(method.a, method.b, method.c);
} else if (method.type == DrawMethodType::UPSIDEDOWN_RECT) {
}
else if (method.type == DrawMethodType::UPSIDEDOWN_RECT) {
buffer->addUpsideDownRect(method.dest, method.src);
} else if (method.type == DrawMethodType::REPEATED_RECT) {
}
else if (method.type == DrawMethodType::REPEATED_RECT) {
buffer->addRepeatedRects(method.dest, method.src);
}
}
Expand Down Expand Up @@ -157,9 +167,11 @@ bool DrawPool::updateHash(const DrawMethod& method, const TexturePtr& texture, c
if (!method.a.isNull()) stdext::hash_union(hash, method.a.hash());
if (!method.b.isNull()) stdext::hash_union(hash, method.b.hash());
if (!method.c.isNull()) stdext::hash_union(hash, method.c.hash());
} else if (method.type == DrawMethodType::BOUNDING_RECT) {
}
else if (method.type == DrawMethodType::BOUNDING_RECT) {
if (method.intValue) stdext::hash_combine(hash, method.intValue);
} else {
}
else {
if (method.dest.isValid()) stdext::hash_union(hash, method.dest.hash());
if (method.src.isValid()) stdext::hash_union(hash, method.src.hash());
}
Expand All @@ -179,9 +191,10 @@ DrawPool::PoolState DrawPool::getState(const TexturePtr& texture, const Color& c
PoolState copy = getCurrentState();
if (copy.color != color) copy.color = color;
if (texture) {
if (texture->isEmpty() || m_type == DrawPoolType::FOREGROUND) {
if (texture->isEmpty() || !texture->isCached()) {
copy.texture = texture;
} else {
}
else {
copy.textureId = texture->getId();
copy.textureMatrixId = texture->getTransformMatrixId();
}
Expand Down Expand Up @@ -225,7 +238,8 @@ void DrawPool::setShaderProgram(const PainterShaderProgramPtr& shaderProgram, co

getCurrentState().shaderProgram = shaderProgram.get();
getCurrentState().action = action;
} else {
}
else {
getCurrentState().shaderProgram = nullptr;
getCurrentState().action = nullptr;
}
Expand Down Expand Up @@ -332,7 +346,8 @@ void DrawPool::PoolState::execute() const {
if (texture) {
texture->create();
g_painter->setTexture(texture->getId(), texture->getTransformMatrixId());
} else
}
else
g_painter->setTexture(textureId, textureMatrixId);
}

Expand Down Expand Up @@ -377,7 +392,7 @@ void DrawPool::bindFrameBuffer(const Size& size, const Color& color)
const auto& frame = getTemporaryFrameBuffer(frameIndex);
frame->resize(size);
frame->bind();
});
});
}
void DrawPool::releaseFrameBuffer(const Rect& dest)
{
Expand All @@ -388,7 +403,7 @@ void DrawPool::releaseFrameBuffer(const Rect& dest)
frame->release();
drawState.execute();
frame->draw(dest);
});
});

if (hasFrameBuffer() && !dest.isNull()) m_hashCtrl.put(dest.hash());
--m_bindedFramebuffers;
Expand Down
5 changes: 4 additions & 1 deletion src/framework/graphics/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Texture
bool isEmpty() const { return m_id == 0; }
bool hasRepeat() const { return getProp(repeat); }
bool hasMipmaps() const { return getProp(hasMipMaps); }
bool isCached() const { return getProp(cached); }
virtual void setCached(bool v) { setProp(cached, v); }
virtual bool isAnimatedTexture() const { return false; }
bool setupSize(const Size& size);

Expand Down Expand Up @@ -91,7 +93,8 @@ class Texture
upsideDown = 1 << 2,
repeat = 1 << 3,
compress = 1 << 4,
buildMipmaps = 1 << 5
buildMipmaps = 1 << 5,
cached = 1 << 6
};

uint16_t m_props{ 0 };
Expand Down
9 changes: 6 additions & 3 deletions src/framework/graphics/texturemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void TextureManager::liveReload()
tex->uploadPixels(image, tex->hasMipmaps());
tex->setTime(stdext::time());
}
}, 1000);
}, 1000);
}

TexturePtr TextureManager::getTexture(const std::string& fileName, const bool smooth)
Expand Down Expand Up @@ -131,14 +131,16 @@ TexturePtr TextureManager::getTexture(const std::string& fileName, const bool sm
std::stringstream fin;
g_resources.readFileStream(filePathEx, fin);
texture = loadTexture(fin);
} catch (const stdext::exception& e) {
}
catch (const stdext::exception& e) {
g_logger.error("Unable to load texture '{}': {}", fileName, e.what());
texture = g_textures.getEmptyTexture();
}

if (texture) {
texture->setTime(stdext::time());
texture->setSmooth(smooth);
texture->setCached(true);
std::unique_lock l(m_mutex);
m_textures[filePath] = texture;
}
Expand Down Expand Up @@ -171,7 +173,8 @@ TexturePtr TextureManager::loadTexture(std::stringstream& file)
const auto& animatedTexture = std::make_shared<AnimatedTexture>(imageSize, frames, framesDelay, apng.num_plays);
std::scoped_lock l(m_mutex);
texture = m_animatedTextures.emplace_back(animatedTexture);
} else {
}
else {
const auto& image = std::make_shared<Image>(imageSize, apng.bpp, apng.pdata);
texture = std::make_shared<Texture>(image, false, false);
}
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/uiqrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ void UIQrCode::setCode(const std::string& code, const int border)
}

m_qrCode = code;
if (m_imageTexture) m_imageTexture->setCached(false);
m_imageTexture = std::make_shared<Texture>(Image::fromQRCode(code, border));
m_imageTexture->setCached(true);

if (m_imageTexture && (!m_rect.isValid() || isImageAutoResize())) {
const auto& imageSize = m_imageTexture->getSize();
Expand Down
Loading