Fix possible gcc optimizations to binary reading

This commit is contained in:
niczkx 2012-07-28 02:54:25 -06:00
parent 26e20da938
commit a240429cb8
5 changed files with 29 additions and 8 deletions

View File

@ -163,6 +163,23 @@ std::string BinaryTree::getString()
return ret; return ret;
} }
Position BinaryTree::getPosition()
{
Position ret;
ret.x = getU16();
ret.y = getU16();
ret.z = getU8();
return ret;
}
Point BinaryTree::getPoint()
{
Point ret;
ret.x = getU8();
ret.y = getU8();
return ret;
}
BinaryTreePtr BinaryTree::makeChild(uint8 type) BinaryTreePtr BinaryTree::makeChild(uint8 type)
{ {
BinaryTreePtr child(new BinaryTree(m_fin)); BinaryTreePtr child(new BinaryTree(m_fin));

View File

@ -49,8 +49,8 @@ public:
uint32 getU32(); uint32 getU32();
uint64 getU64(); uint64 getU64();
std::string getString(); std::string getString();
Position getPosition() { return Position(getU16(), getU16(), getU8()); } Position getPosition();
Point getPoint() { return Point(getU8(), getU8()); } Point getPoint();
void setType(uint8 type); void setType(uint8 type);
void writeU8(uint8 u8); void writeU8(uint8 u8);

View File

@ -963,12 +963,19 @@ public:
Position readPos(const std::string& base = std::string()) const Position readPos(const std::string& base = std::string()) const
{ {
return Position(readType<uint16>(base + "x"), readType<uint16>(base + "y"), readType<uint8>(base + "z")); Position ret;
ret.x = readType<uint16>(base + "x");
ret.y = readType<uint16>(base + "y");
ret.z = readType<uint8>(base + "z");
return ret;
} }
Point readPoint() const Point readPoint() const
{ {
return Point(readType<int>("x"), readType<int>("y")); Point ret;
ret.x = readType<int>("x");
ret.y = readType<int>("y");
return ret;
} }
/** Template form of the attribute query which will try to read the /** Template form of the attribute query which will try to read the

View File

@ -36,9 +36,6 @@
#include <framework/core/application.h> #include <framework/core/application.h>
#include <framework/xml/tinyxml.h> #include <framework/xml/tinyxml.h>
/// TODO: Move it to Position class if needed
static inline Position operator&(const Position& pos, int a) { return Position(pos.x & a, pos.y & a, pos.z); }
Map g_map; Map g_map;
void Map::terminate() void Map::terminate()

View File

@ -164,12 +164,12 @@ public:
Position& operator-=(const Position& other) { x-=other.x; y-=other.y; z-=other.z; return *this; } Position& operator-=(const Position& other) { x-=other.x; y-=other.y; z-=other.z; return *this; }
// Point conversion(s) // Point conversion(s)
Position operator+(const Point& other) const { return Position(x + other.x, y + other.y, z); } Position operator+(const Point& other) const { return Position(x + other.x, y + other.y, z); }
Position operator&(int a) const { return Position(x & a, y & a, z); }
Position& operator+=(const Point& other) { x += other.x; y += other.y; return *this; } Position& operator+=(const Point& other) { x += other.x; y += other.y; return *this; }
Position& operator=(const Position& other) { x = other.x; y = other.y; z = other.z; return *this; } Position& operator=(const Position& other) { x = other.x; y = other.y; z = other.z; return *this; }
bool operator==(const Position& other) const { return other.x == x && other.y == y && other.z == z; } bool operator==(const Position& other) const { return other.x == x && other.y == y && other.z == z; }
bool operator!=(const Position& other) const { return other.x!=x || other.y!=y || other.z!=z; } bool operator!=(const Position& other) const { return other.x!=x || other.y!=y || other.z!=z; }
bool isInRange(const Position& pos, int xRange, int yRange) const { return std::abs(x-pos.x) <= xRange && std::abs(y-pos.y) <= yRange && z == pos.z; } bool isInRange(const Position& pos, int xRange, int yRange) const { return std::abs(x-pos.x) <= xRange && std::abs(y-pos.y) <= yRange && z == pos.z; }
bool isInRange(const Position& pos, int minXRange, int maxXRange, int minYRange, int maxYRange) const { bool isInRange(const Position& pos, int minXRange, int maxXRange, int minYRange, int maxYRange) const {
return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange && pos.z == z); return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange && pos.z == z);