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
6 changes: 3 additions & 3 deletions src/client/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void Effect::drawEffect(const Point& dest, uint32_t flags, int offsetX, int offs
yPattern += getNumPatternY();
}

if (g_app.isDrawingEffectsOnTop() && !m_drawBuffer)
m_drawBuffer = std::make_shared<DrawBuffer>(DrawPool::DrawOrder::FOURTH);
if (g_app.isDrawingEffectsOnTop())
m_drawConductor.agroup = true;

getThingType()->draw(dest, 0, xPattern, yPattern, 0, animationPhase, flags, TextureType::NONE, Color::white, lightView, m_drawBuffer);
getThingType()->draw(dest, 0, xPattern, yPattern, 0, animationPhase, flags, TextureType::NONE, Color::white, lightView, m_drawConductor);
}

void Effect::onAppear()
Expand Down
29 changes: 13 additions & 16 deletions src/client/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,31 @@ void Item::draw(const Point& dest, uint32_t flags, TextureType textureType, bool
drawAttachedEffect(dest, lightView, false); // On Bottom
if (textureType != TextureType::ALL_BLANK && m_shader)
g_drawPool.setShaderProgram(m_shader, true, m_shaderAction);
getThingType()->draw(dest, 0, m_numPatternX, m_numPatternY, m_numPatternZ, animationPhase, flags, textureType, m_color, lightView, m_drawBuffer);
getThingType()->draw(dest, 0, m_numPatternX, m_numPatternY, m_numPatternZ, animationPhase, flags, textureType, m_color, lightView, m_drawConductor);
drawAttachedEffect(dest, lightView, true); // On Top

if (isMarked) {
getThingType()->draw(dest, 0, m_numPatternX, m_numPatternY, m_numPatternZ, animationPhase, flags, TextureType::ALL_BLANK, getMarkedColor());
}
}

// Do not change if you do not understand what is being done.
void Item::createBuffer()
void Item::setConductor()
{
DrawPool::DrawOrder order = DrawPool::DrawOrder::NONE;
if (isSingleGround())
order = DrawPool::DrawOrder::FIRST;
else if (isSingleGroundBorder() && !hasElevation())
order = DrawPool::DrawOrder::SECOND;

m_drawBuffer = order != DrawPool::DrawOrder::NONE ? std::make_shared<DrawBuffer>(order) : nullptr;
if (isSingleGround()) {
m_drawConductor.agroup = true;
m_drawConductor.order = DrawOrder::FIRST;
} else if (isSingleGroundBorder() && !hasElevation()) {
m_drawConductor.agroup = true;
m_drawConductor.order = DrawOrder::SECOND;
}
}

void Item::setPosition(const Position& position, uint8_t stackPos, bool hasElevation)
{
Thing::setPosition(position, stackPos);

if (hasElevation)
m_drawBuffer = nullptr;
else if (m_drawBuffer)
m_drawBuffer->agroup(stackPos == 0);
if (hasElevation || m_drawConductor.agroup && stackPos > 0)
m_drawConductor.agroup = false;
}

int Item::getSubType()
Expand Down Expand Up @@ -244,7 +241,7 @@ void Item::setId(uint32_t id)

m_clientId = id;
m_thingType = g_things.getThingType(m_clientId, ThingCategoryItem).get();
createBuffer();
setConductor();

// Shader example on only items that can be marketed.
/*
Expand Down Expand Up @@ -289,7 +286,7 @@ void Item::setOtbId(uint16_t id)

m_clientId = id;
m_thingType = g_things.getThingType(m_clientId, ThingCategoryItem).get();
createBuffer();
setConductor();
}

void Item::unserializeItem(const BinaryTreePtr& in)
Expand Down
2 changes: 1 addition & 1 deletion src/client/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Item : public Thing
#endif

private:
void createBuffer();
void setConductor();

uint8_t m_countOrSubType{ 0 };

Expand Down
4 changes: 1 addition & 3 deletions src/client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ MapView::MapView() : m_pool(g_drawPool.get<DrawPoolFramed>(DrawPoolType::MAP))
g_painter->resetOpacity();
});

m_shadowBuffer = std::make_shared<DrawBuffer>(DrawPool::DrawOrder::FIFTH, false);

setVisibleDimension(Size(15, 11));
}

Expand Down Expand Up @@ -184,7 +182,7 @@ void MapView::drawFloor()

if (m_shadowFloorIntensity > 0 && z == cameraPosition.z + 1) {
g_drawPool.setOpacity(m_shadowFloorIntensity, true);
g_drawPool.addFilledRect(m_rectDimension, Color::black, m_shadowBuffer);
g_drawPool.addFilledRect(m_rectDimension, Color::black, m_shadowConductor);
}

if (canFloorFade())
Expand Down
2 changes: 1 addition & 1 deletion src/client/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,6 @@ class MapView : public LuaObject
TilePtr m_lastHighlightTile;
TexturePtr m_crosshairTexture;

DrawBufferPtr m_shadowBuffer;
DrawConductor m_shadowConductor{ false, DrawOrder::FIFTH };
DrawPoolFramed* m_pool;
};
5 changes: 2 additions & 3 deletions src/client/missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

void Missile::drawMissile(const Point& dest, LightView* lightView)
{
if (!canDraw() || !m_drawBuffer)
if (!canDraw())
return;

const float fraction = m_animationTimer.ticksElapsed() / m_duration;
getThingType()->draw(dest + m_delta * fraction * g_drawPool.getScaleFactor(), 0, m_numPatternX, m_numPatternY, 0, 0,
Otc::DrawThings | Otc::DrawLights, TextureType::NONE, Color::white, lightView, m_drawBuffer);
Otc::DrawThings | Otc::DrawLights, TextureType::NONE, Color::white, lightView, m_drawConductor);
}

void Missile::setPath(const Position& fromPosition, const Position& toPosition)
Expand All @@ -53,7 +53,6 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
m_delta *= SPRITE_SIZE;
m_animationTimer.restart();
m_distance = fromPosition.distance(toPosition);
m_drawBuffer = std::make_shared<DrawBuffer>(DrawPool::DrawOrder::FIFTH);

{ // Update Pattern
if (m_direction == Otc::NorthWest) {
Expand Down
1 change: 1 addition & 0 deletions src/client/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class Missile : public Thing
{
public:
Missile() { m_drawConductor = { true, DrawOrder::FIFTH }; };
void drawMissile(const Point& dest, LightView* lightView = nullptr);

void setId(uint32_t id) override;
Expand Down
5 changes: 0 additions & 5 deletions src/client/thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ int Thing::getStackPos()
return -1;
}

void Thing::onDisappear() {
if (m_drawBuffer)
m_drawBuffer->invalidate();
}

void Thing::setShader(const std::string_view name) { m_shader = g_shaders.getShader(name); }

void Thing::attachEffect(const AttachedEffectPtr& obj) {
Expand Down
7 changes: 3 additions & 4 deletions src/client/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,12 @@ class Thing : public LuaObject
void canDraw(bool canDraw) { m_canDraw = canDraw; }
inline bool canDraw() const { return m_canDraw && m_clientId > 0; }

void destroyBuffer() { m_drawBuffer = nullptr; }

void setShader(const std::string_view name);
void ungroup() { m_drawConductor.agroup = false; }

virtual void onPositionChange(const Position& /*newPos*/, const Position& /*oldPos*/) {}
virtual void onAppear() {}
virtual void onDisappear();
virtual void onDisappear() {};
const Color& getMarkedColor() { m_markedColor.setAlpha(0.1f + std::abs(500 - g_clock.millis() % 1000) / 1000.0f); return m_markedColor; }

void attachEffect(const AttachedEffectPtr& obj);
Expand Down Expand Up @@ -201,7 +200,7 @@ class Thing : public LuaObject

Position m_position;
ThingType* m_thingType{ nullptr };
DrawBufferPtr m_drawBuffer;
DrawConductor m_drawConductor{ false, DrawOrder::THIRD };

Color m_markedColor{ Color::yellow };

Expand Down
11 changes: 3 additions & 8 deletions src/client/thingtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ void ThingType::unserializeOtml(const OTMLNodePtr& node)
}
}

void ThingType::draw(const Point& dest, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, uint32_t flags, TextureType textureType, Color color, LightView* lightView, const DrawBufferPtr& drawBuffer)
void ThingType::draw(const Point& dest, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, uint32_t flags, TextureType textureType, const Color& color, LightView* lightView, const DrawConductor& conductor)
{
if (m_null)
return;
Expand All @@ -621,13 +621,8 @@ void ThingType::draw(const Point& dest, int layer, int xPattern, int yPattern, i
const Rect screenRect(dest + (textureOffset - m_displacement - (m_size.toPoint() - Point(1)) * SPRITE_SIZE) * g_drawPool.getScaleFactor(), textureRect.size() * g_drawPool.getScaleFactor());

if (flags & Otc::DrawThings) {
if (m_opacity < 1.0f)
color.setAlpha(m_opacity);

if (drawBuffer)
drawBuffer->validate(dest);

g_drawPool.addTexturedRect(screenRect, texture, textureRect, color, drawBuffer);
const Color& newColor = m_opacity < 1.0f ? Color(color, m_opacity) : color;
g_drawPool.addTexturedRect(screenRect, texture, textureRect, m_opacity < 1.0f ? Color(color) : color, conductor);
}

if (lightView && hasLight() && flags & Otc::DrawLights) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/thingtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class ThingType : public LuaObject
void exportImage(const std::string& fileName);
#endif

void draw(const Point& dest, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, uint32_t flags, TextureType textureType, Color color = Color::white, LightView* lightView = nullptr, const DrawBufferPtr& drawBuffer = nullptr);
void draw(const Point& dest, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, uint32_t flags, TextureType textureType, const Color& color, LightView* lightView = nullptr, const DrawConductor& conductor = DEFAULT_DRAW_CONDUCTOR);

uint16_t getId() { return m_id; }
ThingCategory getCategory() { return m_category; }
Expand Down
6 changes: 3 additions & 3 deletions src/client/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ void Tile::addThing(const ThingPtr& thing, int stackPos)
// Do not change if you do not understand what is being done.
{
if (const auto& ground = getGround()) {
--stackPos;
stackPos = std::max<int>(--stackPos, 0);
if (ground->isTopGround()) {
ground->destroyBuffer();
thing->destroyBuffer();
ground->ungroup();
thing->ungroup();
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/framework/graphics/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class SpriteSheet;
class DrawPool;
class DrawPoolFramed;
class DrawPoolManager;
class DrawBuffer;
class CoordsBuffer;

using ImagePtr = std::shared_ptr<Image>;
Expand All @@ -70,7 +69,6 @@ using ParticleEffectPtr = std::shared_ptr<ParticleEffect>;
using SpriteSheetPtr = std::shared_ptr<SpriteSheet>;
using ShaderList = std::vector<ShaderPtr>;

using DrawBufferPtr = std::shared_ptr<DrawBuffer>;
using CoordsBufferPtr = std::shared_ptr<CoordsBuffer>;

using ParticleEffectTypePtr = std::shared_ptr<ParticleEffectType>;
Loading