Browse Source

Fix possible gcc optimizations to binary reading

niczkx 7 years ago
parent
commit
a240429cb8

+ 17
- 0
src/framework/core/binarytree.cpp View File

@@ -163,6 +163,23 @@ std::string BinaryTree::getString()
163 163
     return ret;
164 164
 }
165 165
 
166
+Position BinaryTree::getPosition()
167
+{
168
+    Position ret;
169
+    ret.x = getU16();
170
+    ret.y = getU16();
171
+    ret.z = getU8();
172
+    return ret;
173
+}
174
+
175
+Point BinaryTree::getPoint()
176
+{
177
+    Point ret;
178
+    ret.x = getU8();
179
+    ret.y = getU8();
180
+    return ret;
181
+}
182
+
166 183
 BinaryTreePtr BinaryTree::makeChild(uint8 type)
167 184
 {
168 185
     BinaryTreePtr child(new BinaryTree(m_fin));

+ 2
- 2
src/framework/core/binarytree.h View File

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

+ 9
- 2
src/framework/xml/tinyxml.h View File

@@ -963,12 +963,19 @@ public:
963 963
 
964 964
     Position readPos(const std::string& base = std::string()) const
965 965
     {
966
-        return Position(readType<uint16>(base + "x"), readType<uint16>(base + "y"), readType<uint8>(base + "z"));
966
+        Position ret;
967
+        ret.x = readType<uint16>(base + "x");
968
+        ret.y = readType<uint16>(base + "y");
969
+        ret.z = readType<uint8>(base + "z");
970
+        return ret;
967 971
     }
968 972
 
969 973
     Point readPoint() const
970 974
     {
971
-        return Point(readType<int>("x"), readType<int>("y"));
975
+        Point ret;
976
+        ret.x = readType<int>("x");
977
+        ret.y = readType<int>("y");
978
+        return ret;
972 979
     }
973 980
 
974 981
     /** Template form of the attribute query which will try to read the

+ 0
- 3
src/otclient/map.cpp View File

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

+ 1
- 1
src/otclient/position.h View File

@@ -164,12 +164,12 @@ public:
164 164
     Position& operator-=(const Position& other) { x-=other.x; y-=other.y; z-=other.z; return *this; }
165 165
     // Point conversion(s)
166 166
     Position operator+(const Point& other) const { return Position(x + other.x, y + other.y, z); }
167
+    Position operator&(int a) const { return Position(x & a, y & a, z); }
167 168
     Position& operator+=(const Point& other) { x += other.x; y += other.y; return *this; }
168 169
 
169 170
     Position& operator=(const Position& other) { x = other.x; y = other.y; z = other.z; return *this; }
170 171
     bool operator==(const Position& other) const { return other.x == x && other.y == y && other.z == z; }
171 172
     bool operator!=(const Position& other) const { return other.x!=x || other.y!=y || other.z!=z; }
172
-
173 173
     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; }
174 174
     bool isInRange(const Position& pos, int minXRange, int maxXRange, int minYRange, int maxYRange) const {
175 175
         return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange && pos.z == z);

Loading…
Cancel
Save