mirror of
https://github.com/edubart/otclient.git
synced 2025-11-03 12:16:23 +01:00
Merge with 'master'
This commit is contained in:
@@ -200,29 +200,24 @@ void Creature::drawOutfit(const Rect& destRect, bool resize)
|
||||
else
|
||||
exactSize = g_things.rawGetThingType(m_outfit.getAuxId(), m_outfit.getCategory())->getExactSize();
|
||||
|
||||
int frameSize;
|
||||
if(!resize)
|
||||
frameSize = std::max<int>(exactSize * 0.75f, 2 * Otc::TILE_PIXELS * 0.75f);
|
||||
else if(!(frameSize = exactSize))
|
||||
return;
|
||||
|
||||
if(g_graphics.canUseFBO()) {
|
||||
const FrameBufferPtr& outfitBuffer = g_framebuffers.getTemporaryFrameBuffer();
|
||||
outfitBuffer->resize(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS));
|
||||
outfitBuffer->resize(Size(frameSize, frameSize));
|
||||
outfitBuffer->bind();
|
||||
g_painter->setAlphaWriting(true);
|
||||
g_painter->clear(Color::alpha);
|
||||
internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South);
|
||||
internalDrawOutfit(Point(frameSize - Otc::TILE_PIXELS, frameSize - Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South);
|
||||
outfitBuffer->release();
|
||||
|
||||
Rect srcRect;
|
||||
if(resize)
|
||||
srcRect.resize(exactSize, exactSize);
|
||||
else
|
||||
srcRect.resize(2*Otc::TILE_PIXELS*0.75f, 2*Otc::TILE_PIXELS*0.75f);
|
||||
srcRect.moveBottomRight(Point(2*Otc::TILE_PIXELS - 1, 2*Otc::TILE_PIXELS - 1));
|
||||
outfitBuffer->draw(destRect, srcRect);
|
||||
outfitBuffer->draw(destRect, Rect(0,0,frameSize,frameSize));
|
||||
} else {
|
||||
float scaleFactor;
|
||||
if(resize)
|
||||
scaleFactor = destRect.width() / (float)exactSize;
|
||||
else
|
||||
scaleFactor = destRect.width() / (float)(2*Otc::TILE_PIXELS*0.75f);
|
||||
Point dest = destRect.bottomRight() - (Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) - getDisplacement())*scaleFactor;
|
||||
float scaleFactor = destRect.width() / (float)frameSize;
|
||||
Point dest = destRect.bottomRight() - (Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) - getDisplacement()) * scaleFactor;
|
||||
internalDrawOutfit(dest, scaleFactor, false, true, Otc::South);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,6 +394,14 @@ void Map::setZoneColor(tileflags_t zone, const Color& color)
|
||||
m_zoneColors[zone] = color;
|
||||
}
|
||||
|
||||
Color Map::getZoneColor(tileflags_t flag)
|
||||
{
|
||||
auto it = m_zoneColors.find(flag);
|
||||
if(it == m_zoneColors.end())
|
||||
return Color::alpha;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void Map::setForceShowAnimations(bool force)
|
||||
{
|
||||
if(force) {
|
||||
|
||||
@@ -196,7 +196,7 @@ public:
|
||||
void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; }
|
||||
|
||||
float getZoneOpacity() { return m_zoneOpacity; }
|
||||
Color getZoneColor(tileflags_t flag) { return m_zoneColors[flag]; }
|
||||
Color getZoneColor(tileflags_t flag);
|
||||
tileflags_t getZoneFlags() { return (tileflags_t)m_zoneFlags; }
|
||||
bool showZones() { return m_zoneFlags != 0; }
|
||||
bool showZone(tileflags_t zone) { return (m_zoneFlags & zone) == zone; }
|
||||
@@ -257,7 +257,7 @@ private:
|
||||
|
||||
uint8 m_animationFlags;
|
||||
uint32 m_zoneFlags;
|
||||
std::array<Color, TILESTATE_LAST> m_zoneColors;
|
||||
std::map<uint32, Color> m_zoneColors;
|
||||
float m_zoneOpacity;
|
||||
|
||||
Light m_light;
|
||||
@@ -272,5 +272,3 @@ private:
|
||||
extern Map g_map;
|
||||
|
||||
#endif
|
||||
|
||||
/* vim: set ts=4 sw=4 et: */
|
||||
|
||||
@@ -333,6 +333,7 @@ bool Minimap::loadOtmm(const std::string& fileName)
|
||||
|
||||
uint blockSize = MMBLOCK_SIZE * MMBLOCK_SIZE * sizeof(MinimapTile);
|
||||
std::vector<uchar> compressBuffer(compressBound(blockSize));
|
||||
std::vector<uchar> decompressBuffer(blockSize);
|
||||
|
||||
while(true) {
|
||||
Position pos;
|
||||
@@ -340,17 +341,19 @@ bool Minimap::loadOtmm(const std::string& fileName)
|
||||
pos.y = fin->getU16();
|
||||
pos.z = fin->getU8();
|
||||
|
||||
// end of file
|
||||
if(!pos.isValid())
|
||||
// end of file or file is corrupted
|
||||
if(!pos.isValid() || pos.z >= Otc::MAX_Z+1)
|
||||
break;
|
||||
|
||||
MinimapBlock& block = getBlock(pos);
|
||||
ulong len = fin->getU16();
|
||||
ulong destLen = blockSize;
|
||||
fin->read(compressBuffer.data(), len);
|
||||
int ret = uncompress((uchar*)&block.getTiles(), &destLen, compressBuffer.data(), len);
|
||||
assert(ret == Z_OK);
|
||||
assert(destLen == blockSize);
|
||||
int ret = uncompress(decompressBuffer.data(), &destLen, compressBuffer.data(), len);
|
||||
if(ret != Z_OK || destLen != blockSize)
|
||||
break;
|
||||
|
||||
memcpy((uchar*)&block.getTiles(), decompressBuffer.data(), blockSize);
|
||||
block.mustUpdate();
|
||||
block.justSaw();
|
||||
}
|
||||
|
||||
@@ -583,10 +583,8 @@ void ProtocolGame::sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseMod
|
||||
msg->addU8(fightMode);
|
||||
msg->addU8(chaseMode);
|
||||
msg->addU8(safeFight ? 0x01: 0x00);
|
||||
|
||||
if(g_game.getFeature(Otc::GamePVPMode))
|
||||
msg->addU8(pvpMode);
|
||||
|
||||
send(msg);
|
||||
}
|
||||
|
||||
@@ -595,7 +593,8 @@ void ProtocolGame::sendAttack(uint creatureId, uint seq)
|
||||
OutputMessagePtr msg(new OutputMessage);
|
||||
msg->addU8(Proto::ClientAttack);
|
||||
msg->addU32(creatureId);
|
||||
msg->addU32(seq);
|
||||
if(g_game.getFeature(Otc::GameAttackSeq))
|
||||
msg->addU32(seq);
|
||||
send(msg);
|
||||
}
|
||||
|
||||
@@ -604,7 +603,8 @@ void ProtocolGame::sendFollow(uint creatureId, uint seq)
|
||||
OutputMessagePtr msg(new OutputMessage);
|
||||
msg->addU8(Proto::ClientFollow);
|
||||
msg->addU32(creatureId);
|
||||
msg->addU32(seq);
|
||||
if(g_game.getFeature(Otc::GameAttackSeq))
|
||||
msg->addU32(seq);
|
||||
send(msg);
|
||||
}
|
||||
|
||||
@@ -652,10 +652,8 @@ void ProtocolGame::sendShareExperience(bool active)
|
||||
OutputMessagePtr msg(new OutputMessage);
|
||||
msg->addU8(Proto::ClientShareExperience);
|
||||
msg->addU8(active ? 0x01 : 0x00);
|
||||
|
||||
if(g_game.getClientVersion() < 910)
|
||||
msg->addU8(0);
|
||||
|
||||
send(msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -244,12 +244,12 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
|
||||
m_attribs.set(attr, market);
|
||||
break;
|
||||
}
|
||||
case ThingAttrUsable:
|
||||
case ThingAttrElevation: {
|
||||
m_elevation = fin->getU16();
|
||||
m_attribs.set(attr, m_elevation);
|
||||
break;
|
||||
}
|
||||
case ThingAttrUsable:
|
||||
case ThingAttrGround:
|
||||
case ThingAttrWritable:
|
||||
case ThingAttrWritableOnce:
|
||||
|
||||
@@ -174,7 +174,7 @@ set(CMAKE_CXX_FLAGS_COMPILESPEED "-O0")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
|
||||
set(CMAKE_CXX_FLAGS_PERFORMANCE "-Ofast -mmmx -msse -msse2")
|
||||
set(CMAKE_CXX_FLAGS_PERFORMANCE "-Ofast -march=native")
|
||||
|
||||
if(USE_LTO)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwhole-program -flto")
|
||||
|
||||
@@ -135,6 +135,12 @@ void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
#endif
|
||||
}
|
||||
|
||||
void PainterOGL1::drawFillCoords(CoordsBuffer& coordsBuffer)
|
||||
{
|
||||
setTexture(nullptr);
|
||||
drawCoords(coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL1::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||
{
|
||||
if(texture->isEmpty())
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
void refreshState();
|
||||
|
||||
void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles);
|
||||
void drawFillCoords(CoordsBuffer& coordsBuffer);
|
||||
void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture);
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
void drawUpsideDownTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
|
||||
@@ -120,6 +120,13 @@ void PainterOGL2::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
PainterShaderProgram::enableAttributeArray(PainterShaderProgram::TEXCOORD_ATTR);
|
||||
}
|
||||
|
||||
void PainterOGL2::drawFillCoords(CoordsBuffer& coordsBuffer)
|
||||
{
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : m_drawSolidColorProgram.get());
|
||||
setTexture(nullptr);
|
||||
drawCoords(coordsBuffer);
|
||||
}
|
||||
|
||||
void PainterOGL2::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||
{
|
||||
if(texture && texture->isEmpty())
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
void unbind();
|
||||
|
||||
void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles);
|
||||
void drawFillCoords(CoordsBuffer& coordsBuffer);
|
||||
void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture);
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
void drawUpsideDownTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
virtual void clear(const Color& color) = 0;
|
||||
|
||||
virtual void drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode = Triangles) = 0;
|
||||
virtual void drawFillCoords(CoordsBuffer& coordsBuffer) = 0;
|
||||
virtual void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture) = 0;
|
||||
virtual void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src) = 0;
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture) { drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize())); }
|
||||
|
||||
@@ -49,6 +49,9 @@ UITextEdit::UITextEdit()
|
||||
m_updatesEnabled = true;
|
||||
m_selectionColor = Color::white;
|
||||
m_selectionBackgroundColor = Color::black;
|
||||
m_glyphsTextCoordsBuffer.enableHardwareCaching();
|
||||
m_glyphsSelectCoordsBuffer.enableHardwareCaching();
|
||||
m_glyphsMustRecache = true;
|
||||
blinkCursor();
|
||||
}
|
||||
|
||||
@@ -62,38 +65,36 @@ void UITextEdit::drawSelf(Fw::DrawPane drawPane)
|
||||
drawImage(m_rect);
|
||||
drawIcon(m_rect);
|
||||
|
||||
//TODO: text rendering could be much optimized by using vertex buffer or caching the render into a texture
|
||||
|
||||
int textLength = m_text.length();
|
||||
const TexturePtr& texture = m_font->getTexture();
|
||||
if(!texture)
|
||||
return;
|
||||
|
||||
if(hasSelection()) {
|
||||
if(m_color != Color::alpha) {
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=0;i<m_selectionStart;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
}
|
||||
bool glyphsMustRecache = m_glyphsMustRecache;
|
||||
if(glyphsMustRecache)
|
||||
m_glyphsMustRecache = false;
|
||||
|
||||
for(int i=m_selectionStart;i<m_selectionEnd;++i) {
|
||||
g_painter->setColor(m_selectionBackgroundColor);
|
||||
g_painter->drawFilledRect(m_glyphsCoords[i]);
|
||||
g_painter->setColor(m_selectionColor);
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
if(m_color != Color::alpha) {
|
||||
if(glyphsMustRecache) {
|
||||
m_glyphsTextCoordsBuffer.clear();
|
||||
for(int i=0;i<textLength;++i)
|
||||
m_glyphsTextCoordsBuffer.addRect(m_glyphsCoords[i], m_glyphsTexCoords[i]);
|
||||
}
|
||||
|
||||
if(m_color != Color::alpha) {
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=m_selectionEnd;i<textLength;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
}
|
||||
} else if(m_color != Color::alpha) {
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=0;i<textLength;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
g_painter->drawTextureCoords(m_glyphsTextCoordsBuffer, texture);
|
||||
}
|
||||
|
||||
if(hasSelection()) {
|
||||
if(glyphsMustRecache) {
|
||||
m_glyphsSelectCoordsBuffer.clear();
|
||||
for(int i=m_selectionStart;i<m_selectionEnd;++i)
|
||||
m_glyphsSelectCoordsBuffer.addRect(m_glyphsCoords[i], m_glyphsTexCoords[i]);
|
||||
}
|
||||
g_painter->setColor(m_selectionBackgroundColor);
|
||||
g_painter->drawFillCoords(m_glyphsSelectCoordsBuffer);
|
||||
g_painter->setColor(m_selectionColor);
|
||||
g_painter->drawTextureCoords(m_glyphsSelectCoordsBuffer, texture);
|
||||
}
|
||||
|
||||
// render cursor
|
||||
if(isExplicitlyEnabled() && m_cursorVisible && m_cursorInRange && isActive() && m_cursorPos >= 0) {
|
||||
@@ -136,6 +137,9 @@ void UITextEdit::update(bool focusCursor)
|
||||
if(m_rect.isEmpty())
|
||||
return;
|
||||
|
||||
// recache coords buffers
|
||||
recacheGlyphs();
|
||||
|
||||
// map glyphs positions
|
||||
Size textBoxSize;
|
||||
const std::vector<Point>& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize);
|
||||
@@ -360,6 +364,7 @@ void UITextEdit::setSelection(int start, int end)
|
||||
|
||||
m_selectionStart = stdext::clamp<int>(start, 0, (int)m_text.length());
|
||||
m_selectionEnd = stdext::clamp<int>(end, 0, (int)m_text.length());
|
||||
recacheGlyphs();
|
||||
}
|
||||
|
||||
void UITextEdit::setTextHidden(bool hidden)
|
||||
@@ -654,7 +659,7 @@ void UITextEdit::onFocusChange(bool focused, Fw::FocusReason reason)
|
||||
else
|
||||
blinkCursor();
|
||||
update(true);
|
||||
} else
|
||||
} else if(m_selectable)
|
||||
clearSelection();
|
||||
UIWidget::onFocusChange(focused, reason);
|
||||
}
|
||||
@@ -796,7 +801,6 @@ bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -807,6 +811,9 @@ bool UITextEdit::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
|
||||
bool UITextEdit::onMouseMove(const Point& mousePos, const Point& mouseMoved)
|
||||
{
|
||||
if(UIWidget::onMouseMove(mousePos, mouseMoved))
|
||||
return true;
|
||||
|
||||
if(m_selectable && isPressed()) {
|
||||
int pos = getTextPos(mousePos);
|
||||
if(pos >= 0) {
|
||||
@@ -815,7 +822,7 @@ bool UITextEdit::onMouseMove(const Point& mousePos, const Point& mouseMoved)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return UIWidget::onMouseMove(mousePos, mouseMoved);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UITextEdit::onDoubleClick(const Point& mousePos)
|
||||
|
||||
@@ -108,6 +108,7 @@ protected:
|
||||
private:
|
||||
void disableUpdates() { m_updatesEnabled = false; }
|
||||
void enableUpdates() { m_updatesEnabled = true; }
|
||||
void recacheGlyphs() { m_glyphsMustRecache = true; }
|
||||
|
||||
Rect m_drawArea;
|
||||
int m_cursorPos;
|
||||
@@ -137,6 +138,10 @@ private:
|
||||
|
||||
std::vector<Rect> m_glyphsCoords;
|
||||
std::vector<Rect> m_glyphsTexCoords;
|
||||
|
||||
CoordsBuffer m_glyphsTextCoordsBuffer;
|
||||
CoordsBuffer m_glyphsSelectCoordsBuffer;
|
||||
bool m_glyphsMustRecache;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user