diff --git a/src/framework/graphics/painter.cpp b/src/framework/graphics/painter.cpp index ed02931a..a41b6dba 100644 --- a/src/framework/graphics/painter.cpp +++ b/src/framework/graphics/painter.cpp @@ -159,10 +159,6 @@ void Painter::setAlphaWriting(bool enable) void Painter::setResolution(const Size& resolution) { - if(m_resolution == resolution) - return; - - // The projection matrix converts from Painter's coordinate system to GL's coordinate system // * GL's viewport is 2x2, Painter's is width x height // * GL has +y -> -y going from bottom -> top, Painter is the other way round diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index 93c6b1d9..4491ef5a 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -702,14 +702,17 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar break; } case WM_SIZE: { + bool forceResize = false; switch(wParam) { case SIZE_MAXIMIZED: m_maximized = true; m_visible = true; + forceResize = true; break; case SIZE_RESTORED: m_maximized = false; m_visible = true; + forceResize = true; break; case SIZE_MINIMIZED: m_visible = false; @@ -723,7 +726,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar size.setWidth(std::max(std::min((int)LOWORD(lParam), 7680), m_minimumSize.width())); size.setHeight(std::max(std::min((int)HIWORD(lParam), 4320), m_minimumSize.height())); - if(m_visible && m_size != size) { + if(m_visible && (forceResize || m_size != size)) { m_size = size; m_onResize(m_size); } diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index aa978eb2..5724fbc5 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -793,6 +793,7 @@ void X11Window::poll() } case MapNotify: m_visible = true; + needsResizeUpdate = true; break; case UnmapNotify: m_visible = false; diff --git a/src/otclient/item.cpp b/src/otclient/item.cpp index 80dbf045..89b7b9f9 100644 --- a/src/otclient/item.cpp +++ b/src/otclient/item.cpp @@ -38,8 +38,8 @@ #include Item::Item() : - m_id(0), - m_otbId(0), + m_clientId(0), + m_serverId(0), m_countOrSubType(1) { } @@ -60,7 +60,7 @@ ItemPtr Item::createFromOtb(int id) void Item::draw(const Point& dest, float scaleFactor, bool animate) { - if(m_id == 0) + if(m_clientId == 0) return; // determine animation phase @@ -179,9 +179,8 @@ void Item::setId(uint32 id) { if(!g_things.isValidDatId(id, ThingCategoryItem)) id = 0; - //m_otbId = g_things.findItemTypeByClientId(id)->getServerId(); - m_id = id; - m_otbId = 0; + m_serverId = g_things.findItemTypeByClientId(id)->getServerId(); + m_clientId = id; } void Item::setOtbId(uint16 id) @@ -189,17 +188,17 @@ void Item::setOtbId(uint16 id) if(!g_things.isValidOtbId(id)) id = 0; auto itemType = g_things.getItemType(id); - m_otbId = id; + m_serverId = id; id = itemType->getClientId(); if(!g_things.isValidDatId(id, ThingCategoryItem)) id = 0; - m_id = id; + m_clientId = id; } bool Item::isValid() { - return g_things.isValidDatId(m_id, ThingCategoryItem); + return g_things.isValidDatId(m_clientId, ThingCategoryItem); } void Item::unserializeItem(const BinaryTreePtr &in) @@ -344,10 +343,10 @@ ItemPtr Item::clone() const ThingTypePtr& Item::getThingType() { - return g_things.getThingType(m_id, ThingCategoryItem); + return g_things.getThingType(m_clientId, ThingCategoryItem); } ThingType* Item::rawGetThingType() { - return g_things.rawGetThingType(m_id, ThingCategoryItem); + return g_things.rawGetThingType(m_clientId, ThingCategoryItem); } diff --git a/src/otclient/item.h b/src/otclient/item.h index 1f86e1eb..8cadd880 100644 --- a/src/otclient/item.h +++ b/src/otclient/item.h @@ -92,8 +92,9 @@ public: int getCountOrSubType() { return m_countOrSubType; } int getSubType(); int getCount(); - uint32 getId() { return m_id; } - uint16 getServerId() { return m_otbId; } + uint32 getId() { return m_clientId; } + uint16 getClientId() { return m_clientId; } + uint16 getServerId() { return m_serverId; } bool isValid(); ItemPtr clone(); @@ -127,8 +128,8 @@ public: ThingType *rawGetThingType(); private: - uint16 m_id; - uint16 m_otbId; + uint16 m_clientId; + uint16 m_serverId; uint8 m_countOrSubType; stdext::packed_storage m_attribs; std::vector m_containerItems; diff --git a/src/otclient/mapio.cpp b/src/otclient/mapio.cpp index 36f126fe..d5099837 100644 --- a/src/otclient/mapio.cpp +++ b/src/otclient/mapio.cpp @@ -49,18 +49,13 @@ void Map::loadOtbm(const std::string& fileName) stdext::throw_exception("could not read root property!"); uint32 headerVersion = root->getU32(); - if(!headerVersion || headerVersion > 3) + if(headerVersion > 3) stdext::throw_exception(stdext::format("Unknown OTBM version detected: %u.", headerVersion)); setWidth(root->getU16()); setHeight(root->getU16()); uint32 headerMajorItems = root->getU8(); - if(headerMajorItems < 3) { - stdext::throw_exception(stdext::format("This map needs to be upgraded. read %d what it's supposed to be: %u", - headerMajorItems, g_things.getOtbMajorVersion())); - } - if(headerMajorItems > g_things.getOtbMajorVersion()) { stdext::throw_exception(stdext::format("This map was saved with different OTB version. read %d what it's supposed to be: %d", headerMajorItems, g_things.getOtbMajorVersion())); @@ -213,7 +208,7 @@ void Map::loadOtbm(const std::string& fileName) g_logger.debug("OTBM read successfully."); fin->close(); - loadSpawns(getSpawnFile()); + //loadSpawns(getSpawnFile()); // m_houses.load(getHouseFile()); } @@ -223,6 +218,7 @@ void Map::saveOtbm(const std::string &fileName) if(!fin) stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName)); + fin->cache(); std::string dir; if(fileName.find_last_of('/') == std::string::npos) dir = g_resources.getWorkDir(); @@ -568,10 +564,7 @@ void Map::saveOtcm(const std::string& fileName) fin->addU16(pos.y); fin->addU8(pos.z); - const auto& list = tile->getThings(); - auto first = std::find_if(list.begin(), list.end(), [](const ThingPtr& thing) { return thing->isItem(); }); - for(auto it = first, end = list.end(); it != end; ++it) { - const ThingPtr& thing = *it; + for(const ThingPtr& thing : tile->getThings()) { if(thing->isItem()) { ItemPtr item = thing->static_self_cast(); fin->addU16(item->getId()); diff --git a/src/otclient/thingtypemanager.cpp b/src/otclient/thingtypemanager.cpp index e64fd80b..6879e7d7 100644 --- a/src/otclient/thingtypemanager.cpp +++ b/src/otclient/thingtypemanager.cpp @@ -55,6 +55,7 @@ void ThingTypeManager::terminate() for(int i = 0; i < ThingLastCategory; ++i) m_thingTypes[i].clear(); m_itemTypes.clear(); + m_reverseItemTypes.clear(); m_nullThingType = nullptr; m_nullItemType = nullptr; } @@ -115,11 +116,18 @@ void ThingTypeManager::loadOtb(const std::string& file) root->getU32(); // build number root->skip(128); // description + m_reverseItemTypes.clear(); m_itemTypes.resize(root->getChildren().size(), m_nullItemType); + for(const BinaryTreePtr& node : root->getChildren()) { ItemTypePtr itemType(new ItemType); itemType->unserialize(node); addItemType(itemType); + + uint16 clientId = itemType->getClientId(); + if(clientId >= m_reverseItemTypes.size()) + m_reverseItemTypes.resize(clientId+1); + m_reverseItemTypes[clientId] = itemType; } m_otbLoaded = true; @@ -237,15 +245,13 @@ void ThingTypeManager::addItemType(const ItemTypePtr& itemType) const ItemTypePtr& ThingTypeManager::findItemTypeByClientId(uint16 id) { - if(m_itemTypes.empty()) + if(id == 0 || id >= m_reverseItemTypes.size()) return m_nullItemType; - for(const ItemTypePtr& itemType : m_itemTypes) { - if(itemType->getClientId() == id) - return itemType; - } - - return m_nullItemType; + if(m_reverseItemTypes[id]) + return m_reverseItemTypes[id]; + else + return m_nullItemType; } const ThingTypePtr& ThingTypeManager::getThingType(uint16 id, ThingCategory category) diff --git a/src/otclient/thingtypemanager.h b/src/otclient/thingtypemanager.h index 56f1d80f..12e258e3 100644 --- a/src/otclient/thingtypemanager.h +++ b/src/otclient/thingtypemanager.h @@ -71,6 +71,7 @@ public: private: ThingTypeList m_thingTypes[ThingLastCategory]; + ItemTypeList m_reverseItemTypes; ItemTypeList m_itemTypes; ThingTypePtr m_nullThingType;