Implement reverse otb items table

This commit is contained in:
Eduardo Bart 2012-08-19 18:49:24 -03:00
parent 0af783b5cf
commit b349ff2620
8 changed files with 38 additions and 38 deletions

View File

@ -159,10 +159,6 @@ void Painter::setAlphaWriting(bool enable)
void Painter::setResolution(const Size& resolution) 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 // 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's viewport is 2x2, Painter's is width x height
// * GL has +y -> -y going from bottom -> top, Painter is the other way round // * GL has +y -> -y going from bottom -> top, Painter is the other way round

View File

@ -702,14 +702,17 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
break; break;
} }
case WM_SIZE: { case WM_SIZE: {
bool forceResize = false;
switch(wParam) { switch(wParam) {
case SIZE_MAXIMIZED: case SIZE_MAXIMIZED:
m_maximized = true; m_maximized = true;
m_visible = true; m_visible = true;
forceResize = true;
break; break;
case SIZE_RESTORED: case SIZE_RESTORED:
m_maximized = false; m_maximized = false;
m_visible = true; m_visible = true;
forceResize = true;
break; break;
case SIZE_MINIMIZED: case SIZE_MINIMIZED:
m_visible = false; 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.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())); 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_size = size;
m_onResize(m_size); m_onResize(m_size);
} }

View File

@ -793,6 +793,7 @@ void X11Window::poll()
} }
case MapNotify: case MapNotify:
m_visible = true; m_visible = true;
needsResizeUpdate = true;
break; break;
case UnmapNotify: case UnmapNotify:
m_visible = false; m_visible = false;

View File

@ -38,8 +38,8 @@
#include <framework/core/binarytree.h> #include <framework/core/binarytree.h>
Item::Item() : Item::Item() :
m_id(0), m_clientId(0),
m_otbId(0), m_serverId(0),
m_countOrSubType(1) m_countOrSubType(1)
{ {
} }
@ -60,7 +60,7 @@ ItemPtr Item::createFromOtb(int id)
void Item::draw(const Point& dest, float scaleFactor, bool animate) void Item::draw(const Point& dest, float scaleFactor, bool animate)
{ {
if(m_id == 0) if(m_clientId == 0)
return; return;
// determine animation phase // determine animation phase
@ -179,9 +179,8 @@ void Item::setId(uint32 id)
{ {
if(!g_things.isValidDatId(id, ThingCategoryItem)) if(!g_things.isValidDatId(id, ThingCategoryItem))
id = 0; id = 0;
//m_otbId = g_things.findItemTypeByClientId(id)->getServerId(); m_serverId = g_things.findItemTypeByClientId(id)->getServerId();
m_id = id; m_clientId = id;
m_otbId = 0;
} }
void Item::setOtbId(uint16 id) void Item::setOtbId(uint16 id)
@ -189,17 +188,17 @@ void Item::setOtbId(uint16 id)
if(!g_things.isValidOtbId(id)) if(!g_things.isValidOtbId(id))
id = 0; id = 0;
auto itemType = g_things.getItemType(id); auto itemType = g_things.getItemType(id);
m_otbId = id; m_serverId = id;
id = itemType->getClientId(); id = itemType->getClientId();
if(!g_things.isValidDatId(id, ThingCategoryItem)) if(!g_things.isValidDatId(id, ThingCategoryItem))
id = 0; id = 0;
m_id = id; m_clientId = id;
} }
bool Item::isValid() bool Item::isValid()
{ {
return g_things.isValidDatId(m_id, ThingCategoryItem); return g_things.isValidDatId(m_clientId, ThingCategoryItem);
} }
void Item::unserializeItem(const BinaryTreePtr &in) void Item::unserializeItem(const BinaryTreePtr &in)
@ -344,10 +343,10 @@ ItemPtr Item::clone()
const ThingTypePtr& Item::getThingType() const ThingTypePtr& Item::getThingType()
{ {
return g_things.getThingType(m_id, ThingCategoryItem); return g_things.getThingType(m_clientId, ThingCategoryItem);
} }
ThingType* Item::rawGetThingType() ThingType* Item::rawGetThingType()
{ {
return g_things.rawGetThingType(m_id, ThingCategoryItem); return g_things.rawGetThingType(m_clientId, ThingCategoryItem);
} }

View File

@ -92,8 +92,9 @@ public:
int getCountOrSubType() { return m_countOrSubType; } int getCountOrSubType() { return m_countOrSubType; }
int getSubType(); int getSubType();
int getCount(); int getCount();
uint32 getId() { return m_id; } uint32 getId() { return m_clientId; }
uint16 getServerId() { return m_otbId; } uint16 getClientId() { return m_clientId; }
uint16 getServerId() { return m_serverId; }
bool isValid(); bool isValid();
ItemPtr clone(); ItemPtr clone();
@ -127,8 +128,8 @@ public:
ThingType *rawGetThingType(); ThingType *rawGetThingType();
private: private:
uint16 m_id; uint16 m_clientId;
uint16 m_otbId; uint16 m_serverId;
uint8 m_countOrSubType; uint8 m_countOrSubType;
stdext::packed_storage<uint8> m_attribs; stdext::packed_storage<uint8> m_attribs;
std::vector<ItemPtr> m_containerItems; std::vector<ItemPtr> m_containerItems;

View File

@ -49,18 +49,13 @@ void Map::loadOtbm(const std::string& fileName)
stdext::throw_exception("could not read root property!"); stdext::throw_exception("could not read root property!");
uint32 headerVersion = root->getU32(); uint32 headerVersion = root->getU32();
if(!headerVersion || headerVersion > 3) if(headerVersion > 3)
stdext::throw_exception(stdext::format("Unknown OTBM version detected: %u.", headerVersion)); stdext::throw_exception(stdext::format("Unknown OTBM version detected: %u.", headerVersion));
setWidth(root->getU16()); setWidth(root->getU16());
setHeight(root->getU16()); setHeight(root->getU16());
uint32 headerMajorItems = root->getU8(); 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()) { 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", 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())); headerMajorItems, g_things.getOtbMajorVersion()));
@ -213,7 +208,7 @@ void Map::loadOtbm(const std::string& fileName)
g_logger.debug("OTBM read successfully."); g_logger.debug("OTBM read successfully.");
fin->close(); fin->close();
loadSpawns(getSpawnFile()); //loadSpawns(getSpawnFile());
// m_houses.load(getHouseFile()); // m_houses.load(getHouseFile());
} }
@ -223,6 +218,7 @@ void Map::saveOtbm(const std::string &fileName)
if(!fin) if(!fin)
stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName)); stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));
fin->cache();
std::string dir; std::string dir;
if(fileName.find_last_of('/') == std::string::npos) if(fileName.find_last_of('/') == std::string::npos)
dir = g_resources.getWorkDir(); dir = g_resources.getWorkDir();
@ -568,10 +564,7 @@ void Map::saveOtcm(const std::string& fileName)
fin->addU16(pos.y); fin->addU16(pos.y);
fin->addU8(pos.z); fin->addU8(pos.z);
const auto& list = tile->getThings(); for(const ThingPtr& thing : 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;
if(thing->isItem()) { if(thing->isItem()) {
ItemPtr item = thing->static_self_cast<Item>(); ItemPtr item = thing->static_self_cast<Item>();
fin->addU16(item->getId()); fin->addU16(item->getId());

View File

@ -55,6 +55,7 @@ void ThingTypeManager::terminate()
for(int i = 0; i < ThingLastCategory; ++i) for(int i = 0; i < ThingLastCategory; ++i)
m_thingTypes[i].clear(); m_thingTypes[i].clear();
m_itemTypes.clear(); m_itemTypes.clear();
m_reverseItemTypes.clear();
m_nullThingType = nullptr; m_nullThingType = nullptr;
m_nullItemType = nullptr; m_nullItemType = nullptr;
} }
@ -115,11 +116,18 @@ void ThingTypeManager::loadOtb(const std::string& file)
root->getU32(); // build number root->getU32(); // build number
root->skip(128); // description root->skip(128); // description
m_reverseItemTypes.clear();
m_itemTypes.resize(root->getChildren().size(), m_nullItemType); m_itemTypes.resize(root->getChildren().size(), m_nullItemType);
for(const BinaryTreePtr& node : root->getChildren()) { for(const BinaryTreePtr& node : root->getChildren()) {
ItemTypePtr itemType(new ItemType); ItemTypePtr itemType(new ItemType);
itemType->unserialize(node); itemType->unserialize(node);
addItemType(itemType); addItemType(itemType);
uint16 clientId = itemType->getClientId();
if(clientId >= m_reverseItemTypes.size())
m_reverseItemTypes.resize(clientId+1);
m_reverseItemTypes[clientId] = itemType;
} }
m_otbLoaded = true; m_otbLoaded = true;
@ -237,15 +245,13 @@ void ThingTypeManager::addItemType(const ItemTypePtr& itemType)
const ItemTypePtr& ThingTypeManager::findItemTypeByClientId(uint16 id) const ItemTypePtr& ThingTypeManager::findItemTypeByClientId(uint16 id)
{ {
if(m_itemTypes.empty()) if(id == 0 || id >= m_reverseItemTypes.size())
return m_nullItemType; return m_nullItemType;
for(const ItemTypePtr& itemType : m_itemTypes) { if(m_reverseItemTypes[id])
if(itemType->getClientId() == id) return m_reverseItemTypes[id];
return itemType; else
} return m_nullItemType;
return m_nullItemType;
} }
const ThingTypePtr& ThingTypeManager::getThingType(uint16 id, ThingCategory category) const ThingTypePtr& ThingTypeManager::getThingType(uint16 id, ThingCategory category)

View File

@ -71,6 +71,7 @@ public:
private: private:
ThingTypeList m_thingTypes[ThingLastCategory]; ThingTypeList m_thingTypes[ThingLastCategory];
ItemTypeList m_reverseItemTypes;
ItemTypeList m_itemTypes; ItemTypeList m_itemTypes;
ThingTypePtr m_nullThingType; ThingTypePtr m_nullThingType;