Browse Source

Sorting vectors now working

Thomas Buck 10 years ago
parent
commit
89d4636222
8 changed files with 20 additions and 5 deletions
  1. 4
    0
      ChangeLog.md
  2. 4
    3
      cmake/travis_after_success_linux.sh
  3. 1
    0
      include/Entity.h
  4. 1
    0
      include/RoomData.h
  5. 4
    0
      src/Entity.cpp
  6. 1
    1
      src/Render.cpp
  7. 1
    1
      src/Room.cpp
  8. 4
    0
      src/RoomData.cpp

+ 4
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
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
     [ 20140706 ]
9
     [ 20140706 ]
6
     * Use cmake to check for sys/time.h availability
10
     * Use cmake to check for sys/time.h availability
7
     * Use long nearly everywhere where STL containers are interfaced,
11
     * Use long nearly everywhere where STL containers are interfaced,

+ 4
- 3
cmake/travis_after_success_linux.sh View File

10
 echo "set font \"../../data/test.ttf\"" >> OpenRaider.ini
10
 echo "set font \"../../data/test.ttf\"" >> OpenRaider.ini
11
 
11
 
12
 xvfb-run -n 99 -s "-screen 0 640x480x24" ./OpenRaider &
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
 wget http://imgur.com/tools/imgurbash.sh
15
 wget http://imgur.com/tools/imgurbash.sh
17
 chmod a+x ./imgurbash.sh
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
     echo "NICK OR-$(echo -n $TRAVIS_OS_NAME)-$(echo -n $CC)"
22
     echo "NICK OR-$(echo -n $TRAVIS_OS_NAME)-$(echo -n $CC)"
22
     echo "USER OR-$(echo -n $TRAVIS_OS_NAME)-$(echo -n $CC) 9 \* :OR-$(echo -n $TRAVIS_OS_NAME)-$(echo -n $CC)"
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 View File

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

+ 1
- 0
include/RoomData.h View File

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

+ 4
- 0
src/Entity.cpp View File

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

+ 1
- 1
src/Render.cpp View File

347
         glPopMatrix();
347
         glPopMatrix();
348
 
348
 
349
         // Depth sort entityRenderList and display each entity
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
         for (unsigned int i = 0; i < entityRenderList.size(); i++) {
351
         for (unsigned int i = 0; i < entityRenderList.size(); i++) {
352
             entityRenderList[i]->display();
352
             entityRenderList[i]->display();
353
         }
353
         }

+ 1
- 1
src/Room.cpp View File

647
 }
647
 }
648
 
648
 
649
 void Room::sortModels() {
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
 unsigned long Room::sizeLights() {
653
 unsigned long Room::sizeLights() {

+ 4
- 0
src/RoomData.cpp View File

200
     return (distA < distB);
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
 Portal::Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform) {
209
 Portal::Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform) {

Loading…
Cancel
Save