Procházet zdrojové kódy

Sorting vectors now working

Thomas Buck před 10 roky
rodič
revize
89d4636222

+ 4
- 0
ChangeLog.md Zobrazit soubor

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140714 ]
6
+    * Fixed a bug where std::sort did not use the objects operator<
7
+      method, but instead sorted based on the objects address in memory
8
+
5 9
     [ 20140706 ]
6 10
     * Use cmake to check for sys/time.h availability
7 11
     * Use long nearly everywhere where STL containers are interfaced,

+ 4
- 3
cmake/travis_after_success_linux.sh Zobrazit soubor

@@ -10,13 +10,14 @@ echo "set datadir \"../../data\"" >> OpenRaider.ini
10 10
 echo "set font \"../../data/test.ttf\"" >> OpenRaider.ini
11 11
 
12 12
 xvfb-run -n 99 -s "-screen 0 640x480x24" ./OpenRaider &
13
-sleep 10 # Wait for OpenRaider to start
14
-import -window root -display :99.0 screenshot.png
15 13
 
14
+# Wait for OpenRaider to start
16 15
 wget http://imgur.com/tools/imgurbash.sh
17 16
 chmod a+x ./imgurbash.sh
18
-./imgurbash.sh screenshot.png > url
17
+sleep 10
19 18
 
19
+import -window root -display :99.0 screenshot.png
20
+./imgurbash.sh screenshot.png > url
20 21
 (
21 22
     echo "NICK OR-$(echo -n $TRAVIS_OS_NAME)-$(echo -n $CC)"
22 23
     echo "USER OR-$(echo -n $TRAVIS_OS_NAME)-$(echo -n $CC) 9 \* :OR-$(echo -n $TRAVIS_OS_NAME)-$(echo -n $CC)"

+ 1
- 0
include/Entity.h Zobrazit soubor

@@ -24,6 +24,7 @@ public:
24 24
     Entity(TombRaider &tr, unsigned int index, unsigned int i, unsigned int model);
25 25
 
26 26
     bool operator<(Entity &o);
27
+    static bool compare(Entity *a, Entity *b);
27 28
     void display();
28 29
     void move(char movement);
29 30
     void print();

+ 1
- 0
include/RoomData.h Zobrazit soubor

@@ -62,6 +62,7 @@ public:
62 62
 
63 63
     // Compares distance to ViewVolume for depth sorting
64 64
     bool operator<(const StaticModel &other);
65
+    static bool compare(StaticModel *a, StaticModel *b);
65 66
 
66 67
 private:
67 68
     int index;

+ 4
- 0
src/Entity.cpp Zobrazit soubor

@@ -41,6 +41,10 @@ bool Entity::operator<(Entity &o) {
41 41
     return (distA < distB);
42 42
 }
43 43
 
44
+bool Entity::compare(Entity *a, Entity *b) {
45
+    return (*b) < (*a);
46
+}
47
+
44 48
 void Entity::display() {
45 49
     glPushMatrix();
46 50
     glTranslatef(pos[0], pos[1], pos[2]);

+ 1
- 1
src/Render.cpp Zobrazit soubor

@@ -347,7 +347,7 @@ void Render::display()
347 347
         glPopMatrix();
348 348
 
349 349
         // Depth sort entityRenderList and display each entity
350
-        std::sort(entityRenderList.begin(), entityRenderList.end());
350
+        std::sort(entityRenderList.begin(), entityRenderList.end(), Entity::compare);
351 351
         for (unsigned int i = 0; i < entityRenderList.size(); i++) {
352 352
             entityRenderList[i]->display();
353 353
         }

+ 1
- 1
src/Room.cpp Zobrazit soubor

@@ -647,7 +647,7 @@ StaticModel &Room::getModel(unsigned long index) {
647 647
 }
648 648
 
649 649
 void Room::sortModels() {
650
-    std::sort(models.begin(), models.end());
650
+    std::sort(models.begin(), models.end(), StaticModel::compare);
651 651
 }
652 652
 
653 653
 unsigned long Room::sizeLights() {

+ 4
- 0
src/RoomData.cpp Zobrazit soubor

@@ -200,6 +200,10 @@ bool StaticModel::operator<(const StaticModel &other) {
200 200
     return (distA < distB);
201 201
 }
202 202
 
203
+bool StaticModel::compare(StaticModel *a, StaticModel *b) {
204
+    return (*b) < (*a);
205
+}
206
+
203 207
 // ----------------------------------------------------------------------------
204 208
 
205 209
 Portal::Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform) {

Loading…
Zrušit
Uložit