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)
{
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

View File

@ -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);
}

View File

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

View File

@ -38,8 +38,8 @@
#include <framework/core/binarytree.h>
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);
}

View File

@ -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<uint8> m_attribs;
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!");
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<Item>();
fin->addU16(item->getId());

View File

@ -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)

View File

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