Selaa lähdekoodia

World static, more debug infos, portal rendering.

Thomas Buck 9 vuotta sitten
vanhempi
commit
ea91c9484a

+ 6
- 0
ChangeLog.md Näytä tiedosto

@@ -2,6 +2,12 @@
2 2
 
3 3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20150404 ]
6
+    * World is now static
7
+    * Can display debug informations about Rooms and StaticMeshes
8
+    * Can now render portal outlines
9
+    * Building rendering list now also based on portal visibility
10
+
5 11
     [ 20150330 ]
6 12
     * Removed custom Font support
7 13
     * Some GL performance improvements

+ 2
- 0
include/Room.h Näytä tiedosto

@@ -51,6 +51,8 @@ class Room {
51 51
     unsigned long sizePortals() { return portals.size(); }
52 52
     Portal& getPortal(unsigned long index) { return *portals.at(index); }
53 53
 
54
+    void displayUI();
55
+
54 56
     static void setShowBoundingBox(bool s) { showBoundingBox = s; }
55 57
     static bool getShowBoundingBox() { return showBoundingBox; }
56 58
 

+ 13
- 1
include/RoomData.h Näytä tiedosto

@@ -52,6 +52,7 @@ class StaticModel {
52 52
   public:
53 53
     StaticModel(glm::vec3 pos, float angle, int i);
54 54
     void display(glm::mat4 VP);
55
+    void displayUI();
55 56
 
56 57
   private:
57 58
     int id;
@@ -76,12 +77,17 @@ class RoomSprite {
76 77
 class Portal {
77 78
   public:
78 79
     Portal(int adj, glm::vec3 n, glm::vec3 v1, glm::vec3 v2, glm::vec3 v3,
79
-           glm::vec3 v4) : adjoiningRoom(adj), normal(n) {
80
+           glm::vec3 v4) : adjoiningRoom(adj), normal(n), bbox(v1, v3) {
80 81
         vert[0] = v1; vert[1] = v2;
81 82
         vert[2] = v3; vert[3] = v4;
82 83
     }
84
+
83 85
     int getAdjoiningRoom() { return adjoiningRoom; }
84 86
     glm::vec3 getNormal() { return normal; }
87
+    BoundingBox getBoundingBox() { return bbox; }
88
+
89
+    void display(glm::mat4 VP);
90
+    void displayUI();
85 91
 
86 92
     glm::vec3 getVertex(int i) {
87 93
         orAssertGreaterThanEqual(i, 0);
@@ -89,10 +95,16 @@ class Portal {
89 95
         return vert[i];
90 96
     }
91 97
 
98
+    static void setShowBoundingBox(bool s) { showBoundingBox = s; }
99
+    static bool getShowBoundingBox() { return showBoundingBox; }
100
+
92 101
   private:
93 102
     int adjoiningRoom;
94 103
     glm::vec3 normal;
95 104
     glm::vec3 vert[4];
105
+    BoundingBox bbox;
106
+
107
+    static bool showBoundingBox;
96 108
 };
97 109
 
98 110
 // --------------------------------------

+ 1
- 0
include/StaticMesh.h Näytä tiedosto

@@ -17,6 +17,7 @@ class StaticMesh {
17 17
     StaticMesh(int i, int m, BoundingBox* b1, BoundingBox* b2)
18 18
         : id(i), mesh(m), bbox1(b1), bbox2(b2) { }
19 19
     void display(glm::mat4 MVP);
20
+    void displayUI();
20 21
 
21 22
     int getID() { return id; }
22 23
 

+ 31
- 39
include/World.h Näytä tiedosto

@@ -24,55 +24,47 @@
24 24
  */
25 25
 class World {
26 26
   public:
27
+    static void destroy();
27 28
 
28
-    /*!
29
-     * \brief Deconstructs an object of World
30
-     */
31
-    ~World();
29
+    static void addRoom(Room* room);
30
+    static unsigned long sizeRoom();
31
+    static Room& getRoom(unsigned long index);
32 32
 
33
-    /*!
34
-     * \brief Clears all data in world
35
-     */
36
-    void destroy();
33
+    static void addSprite(Sprite* sprite);
34
+    static unsigned long sizeSprite();
35
+    static Sprite& getSprite(unsigned long index);
37 36
 
38
-    void addRoom(Room* room);
39
-    unsigned long sizeRoom();
40
-    Room& getRoom(unsigned long index);
37
+    static void addSpriteSequence(SpriteSequence* sprite);
38
+    static unsigned long sizeSpriteSequence();
39
+    static SpriteSequence& getSpriteSequence(unsigned long index);
41 40
 
42
-    void addSprite(Sprite* sprite);
43
-    unsigned long sizeSprite();
44
-    Sprite& getSprite(unsigned long index);
41
+    static void addEntity(Entity* entity);
42
+    static unsigned long sizeEntity();
43
+    static Entity& getEntity(unsigned long index);
45 44
 
46
-    void addSpriteSequence(SpriteSequence* sprite);
47
-    unsigned long sizeSpriteSequence();
48
-    SpriteSequence& getSpriteSequence(unsigned long index);
45
+    static void addSkeletalModel(SkeletalModel* model);
46
+    static unsigned long sizeSkeletalModel();
47
+    static SkeletalModel& getSkeletalModel(unsigned long index);
49 48
 
50
-    void addEntity(Entity* entity);
51
-    unsigned long sizeEntity();
52
-    Entity& getEntity(unsigned long index);
49
+    static void addStaticMesh(StaticMesh* model);
50
+    static unsigned long sizeStaticMesh();
51
+    static StaticMesh& getStaticMesh(unsigned long index);
53 52
 
54
-    void addSkeletalModel(SkeletalModel* model);
55
-    unsigned long sizeSkeletalModel();
56
-    SkeletalModel& getSkeletalModel(unsigned long index);
53
+    static void addMesh(Mesh* mesh);
54
+    static unsigned long sizeMesh();
55
+    static Mesh& getMesh(unsigned long index);
57 56
 
58
-    void addStaticMesh(StaticMesh* model);
59
-    unsigned long sizeStaticMesh();
60
-    StaticMesh& getStaticMesh(unsigned long index);
61
-
62
-    void addMesh(Mesh* mesh);
63
-    unsigned long sizeMesh();
64
-    Mesh& getMesh(unsigned long index);
57
+    static void displayUI();
65 58
 
66 59
   private:
67
-    std::vector<std::unique_ptr<Room>> mRooms;
68
-    std::vector<std::unique_ptr<Sprite>> mSprites;
69
-    std::vector<std::unique_ptr<SpriteSequence>> mSpriteSequences;
70
-    std::vector<std::unique_ptr<Entity>> mEntities;
71
-    std::vector<std::unique_ptr<SkeletalModel>> mModels;
72
-    std::vector<std::unique_ptr<StaticMesh>> mStaticMeshes;
73
-    std::vector<std::unique_ptr<Mesh>> mMeshes;
60
+    static std::vector<std::unique_ptr<Room>> rooms;
61
+    static std::vector<std::unique_ptr<Sprite>> sprites;
62
+    static std::vector<std::unique_ptr<SpriteSequence>> spriteSequences;
63
+    static std::vector<std::unique_ptr<Entity>> entities;
64
+    static std::vector<std::unique_ptr<SkeletalModel>> models;
65
+    static std::vector<std::unique_ptr<StaticMesh>> staticMeshes;
66
+    static std::vector<std::unique_ptr<Mesh>> meshes;
74 67
 };
75 68
 
76
-World& getWorld();
77
-
78 69
 #endif
70
+

+ 9
- 9
src/Entity.cpp Näytä tiedosto

@@ -30,8 +30,8 @@ void Entity::display(glm::mat4 VP) {
30 30
          * be displayed wrong (eg. 'bad guy' becomes 'clothes' in tr2/boat)...
31 31
          */
32 32
 
33
-        for (int i = 0; (i < getWorld().sizeSkeletalModel()) && (cache == -1); i++) {
34
-            auto& s = getWorld().getSkeletalModel(i);
33
+        for (int i = 0; (i < World::sizeSkeletalModel()) && (cache == -1); i++) {
34
+            auto& s = World::getSkeletalModel(i);
35 35
             if (s.getID() == id) {
36 36
                 cacheType = CACHE_MODEL;
37 37
                 cache = i;
@@ -39,8 +39,8 @@ void Entity::display(glm::mat4 VP) {
39 39
             }
40 40
         }
41 41
 
42
-        for (int i = 0; (i < getWorld().sizeStaticMesh()) && (cache == -1); i++) {
43
-            auto& s = getWorld().getStaticMesh(i);
42
+        for (int i = 0; (i < World::sizeStaticMesh()) && (cache == -1); i++) {
43
+            auto& s = World::getStaticMesh(i);
44 44
             if (s.getID() == id) {
45 45
                 cacheType = CACHE_MESH;
46 46
                 cache = i;
@@ -48,8 +48,8 @@ void Entity::display(glm::mat4 VP) {
48 48
             }
49 49
         }
50 50
 
51
-        for (int i = 0; i < getWorld().sizeSpriteSequence(); i++) {
52
-            auto& s = getWorld().getSpriteSequence(i);
51
+        for (int i = 0; i < World::sizeSpriteSequence(); i++) {
52
+            auto& s = World::getSpriteSequence(i);
53 53
             if (s.getID() == id) {
54 54
                 cacheType = CACHE_SPRITE;
55 55
                 cache = i;
@@ -73,13 +73,13 @@ void Entity::display(glm::mat4 VP) {
73 73
 
74 74
     if (cacheType == CACHE_SPRITE) {
75 75
         if (showEntitySprites)
76
-            getWorld().getSpriteSequence(cache).display(MVP, sprite);
76
+            World::getSpriteSequence(cache).display(MVP, sprite);
77 77
     } else if (cacheType == CACHE_MESH) {
78 78
         if (showEntityMeshes)
79
-            getWorld().getStaticMesh(cache).display(MVP);
79
+            World::getStaticMesh(cache).display(MVP);
80 80
     } else if (cacheType == CACHE_MODEL) {
81 81
         if (showEntityModels)
82
-            getWorld().getSkeletalModel(cache).display(MVP, animation, frame);
82
+            World::getSkeletalModel(cache).display(MVP, animation, frame);
83 83
     }
84 84
 }
85 85
 

+ 8
- 8
src/Game.cpp Näytä tiedosto

@@ -35,7 +35,7 @@ void Game::destroy() {
35 35
     Render::clearRoomList();
36 36
     SoundManager::clear();
37 37
     TextureManager::clear();
38
-    getWorld().destroy();
38
+    World::destroy();
39 39
 }
40 40
 
41 41
 int Game::loadLevel(std::string level) {
@@ -51,12 +51,12 @@ int Game::loadLevel(std::string level) {
51 51
             return -2;
52 52
         }
53 53
 
54
-        for (int i = 0; i < getWorld().sizeMesh(); i++) {
55
-            getWorld().getMesh(i).prepare();
54
+        for (int i = 0; i < World::sizeMesh(); i++) {
55
+            World::getMesh(i).prepare();
56 56
         }
57 57
 
58
-        for (int i = 0; i < getWorld().sizeRoom(); i++) {
59
-            getWorld().getRoom(i).prepare();
58
+        for (int i = 0; i < World::sizeRoom(); i++) {
59
+            World::getRoom(i).prepare();
60 60
         }
61 61
 
62 62
         SoundManager::prepareSources();
@@ -114,13 +114,13 @@ void Game::handleControllerAxis(float value, KeyboardButton axis) {
114 114
 
115 115
 Entity& Game::getLara() {
116 116
     orAssertGreaterThanEqual(mLara, 0);
117
-    orAssertLessThan(mLara, getWorld().sizeEntity());
118
-    return getWorld().getEntity(mLara);
117
+    orAssertLessThan(mLara, World::sizeEntity());
118
+    return World::getEntity(mLara);
119 119
 }
120 120
 
121 121
 void Game::setLara(long lara) {
122 122
     orAssertGreaterThanEqual(lara, 0);
123
-    orAssertLessThan(lara, getWorld().sizeEntity());
123
+    orAssertLessThan(lara, World::sizeEntity());
124 124
     mLara = lara;
125 125
 }
126 126
 

+ 33
- 17
src/Render.cpp Näytä tiedosto

@@ -68,8 +68,8 @@ void Render::display() {
68 68
     for (int r = roomList.size() - 1; r >= 0; r--) {
69 69
         roomList.at(r)->display(VP);
70 70
 
71
-        for (int i = 0; i < getWorld().sizeEntity(); i++) {
72
-            auto& e = getWorld().getEntity(i);
71
+        for (int i = 0; i < World::sizeEntity(); i++) {
72
+            auto& e = World::getEntity(i);
73 73
             if (roomList.at(r)->getIndex() == e.getRoom()) {
74 74
                 e.display(VP);
75 75
             }
@@ -87,8 +87,8 @@ void Render::display() {
87 87
 void Render::buildRoomList(int room, int budget) {
88 88
     if (room < -1) {
89 89
         // Check if the camera currently is in a room...
90
-        for (int i = 0; i < getWorld().sizeRoom(); i++) {
91
-            if (getWorld().getRoom(i).getBoundingBox().inBox(Camera::getPosition())) {
90
+        for (int i = 0; i < World::sizeRoom(); i++) {
91
+            if (World::getRoom(i).getBoundingBox().inBox(Camera::getPosition())) {
92 92
                 buildRoomList(i, budget);
93 93
                 return;
94 94
             }
@@ -96,27 +96,37 @@ void Render::buildRoomList(int room, int budget) {
96 96
         buildRoomList(-1, budget);
97 97
     } else if (room == -1) {
98 98
         // Check visibility for all rooms!
99
-        for (int i = 0; i < getWorld().sizeRoom(); i++) {
100
-            if (Camera::boxInFrustum(getWorld().getRoom(i).getBoundingBox())) {
101
-                roomList.push_back(&getWorld().getRoom(i));
99
+        for (int i = 0; i < World::sizeRoom(); i++) {
100
+            if (Camera::boxInFrustum(World::getRoom(i).getBoundingBox())) {
101
+                roomList.push_back(&World::getRoom(i));
102 102
             }
103 103
         }
104 104
     } else {
105 105
         // Check visibility of room and connected rooms, recursively
106
-        if (Camera::boxInFrustum(getWorld().getRoom(room).getBoundingBox())) {
107
-            roomList.push_back(&getWorld().getRoom(room));
108
-            for (int i = 0; i < getWorld().getRoom(room).sizePortals(); i++) {
109
-                int r = getWorld().getRoom(room).getPortal(i).getAdjoiningRoom();
106
+        if (Camera::boxInFrustum(World::getRoom(room).getBoundingBox())) {
107
+            roomList.push_back(&World::getRoom(room));
108
+            for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
109
+                auto& portal = World::getRoom(room).getPortal(i);
110
+
111
+                // Check if portal is visible / can be seen through
112
+                bool visible = Camera::boxInFrustum(portal.getBoundingBox());
113
+                if (!visible) {
114
+                    continue;
115
+                }
116
+
117
+                // Check if already in list...
110 118
                 bool found = false;
111 119
                 for (int n = 0; n < roomList.size(); n++) {
112
-                    if (roomList.at(n) == &getWorld().getRoom(r)) {
120
+                    if (roomList.at(n) == &World::getRoom(portal.getAdjoiningRoom())) {
113 121
                         found = true;
114 122
                         break;
115 123
                     }
116 124
                 }
125
+
126
+                // ...only render if not
117 127
                 if (!found) {
118 128
                     if (budget > 0) {
119
-                        buildRoomList(r, --budget);
129
+                        buildRoomList(portal.getAdjoiningRoom(), --budget);
120 130
                     }
121 131
                 }
122 132
             }
@@ -201,21 +211,27 @@ void Render::displayUI() {
201 211
         if (ImGui::Checkbox("Overlay", &showOverlay)) {
202 212
             Camera::setShowOverlay(showOverlay);
203 213
         }
204
-        if (ImGui::Button("Reset Room ID")) {
205
-            Camera::setRoom(-1);
214
+        glm::vec3 camPos = Camera::getPosition();
215
+        if (ImGui::SliderFloat3("Position", &camPos.x, -100000, 100000)) {
216
+            Camera::setPosition(camPos);
206 217
         }
207 218
 
208 219
         ImGui::Separator();
209 220
         ImGui::Text("Bounding Boxes:");
210 221
         bool showBoundingBox = Room::getShowBoundingBox();
211
-        if (ImGui::Checkbox("Room##bbox", &showBoundingBox)) {
222
+        if (ImGui::Checkbox("Rooms##bbox", &showBoundingBox)) {
212 223
             Room::setShowBoundingBox(showBoundingBox);
213 224
         }
214 225
         ImGui::SameLine();
215 226
         bool showBoundingBox2 = StaticMesh::getShowBoundingBox();
216
-        if (ImGui::Checkbox("StaticMesh##bbox", &showBoundingBox2)) {
227
+        if (ImGui::Checkbox("StaticMeshes##bbox", &showBoundingBox2)) {
217 228
             StaticMesh::setShowBoundingBox(showBoundingBox2);
218 229
         }
230
+        ImGui::SameLine();
231
+        bool showBoundingBox3 = Portal::getShowBoundingBox();
232
+        if (ImGui::Checkbox("Portals##bbox", &showBoundingBox3)) {
233
+            Portal::setShowBoundingBox(showBoundingBox3);
234
+        }
219 235
 
220 236
         ImGui::Separator();
221 237
         ImGui::Text("Renderable Objects:");

+ 46
- 5
src/Room.cpp Näytä tiedosto

@@ -9,6 +9,8 @@
9 9
 #include "Log.h"
10 10
 #include "Room.h"
11 11
 
12
+#include "imgui/imgui.h"
13
+
12 14
 #include <glm/gtc/matrix_transform.hpp>
13 15
 #include <glm/gtx/intersect.hpp>
14 16
 
@@ -24,10 +26,9 @@ Room::Room(glm::vec3 _pos, BoundingBox* _bbox, RoomMesh* _mesh, unsigned int f,
24 26
 }
25 27
 
26 28
 void Room::display(glm::mat4 VP) {
27
-    glm::mat4 MVP = VP * model;
28
-
29
-    if (showRoomGeometry)
30
-        mesh->display(MVP);
29
+    if (showRoomGeometry) {
30
+        mesh->display(VP * model);
31
+    }
31 32
 
32 33
     if (showRoomModels) {
33 34
         for (auto& m : models) {
@@ -41,8 +42,15 @@ void Room::display(glm::mat4 VP) {
41 42
         }
42 43
     }
43 44
 
44
-    if (showBoundingBox)
45
+    if (showBoundingBox) {
45 46
         bbox->display(VP, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 1.0f));
47
+    }
48
+
49
+    if (Portal::getShowBoundingBox()) {
50
+        for (auto& p : portals) {
51
+            p->display(VP);
52
+        }
53
+    }
46 54
 }
47 55
 
48 56
 bool Room::isWall(unsigned long sector) {
@@ -101,3 +109,36 @@ int Room::getAdjoiningRoom(float x, float y, float z,
101 109
     return -1;
102 110
 }
103 111
 
112
+void Room::displayUI() {
113
+    ImGui::PushID(roomIndex);
114
+    ImGui::Text("%03d", roomIndex);
115
+    ImGui::NextColumn();
116
+    ImGui::Text("%03d", alternateRoom);
117
+    ImGui::NextColumn();
118
+    ImGui::Text("0x%04X", flags);
119
+    ImGui::NextColumn();
120
+    if (models.size() > 0) {
121
+        if (ImGui::TreeNode("...##model")) {
122
+            for (auto& m : models) {
123
+                m->displayUI();
124
+            }
125
+            ImGui::TreePop();
126
+        }
127
+    } else {
128
+        ImGui::Text("None");
129
+    }
130
+    ImGui::NextColumn();
131
+    if (portals.size() > 0) {
132
+        if (ImGui::TreeNode("...##portal")) {
133
+            for (auto& p : portals) {
134
+                p->displayUI();
135
+            }
136
+            ImGui::TreePop();
137
+        }
138
+    } else {
139
+        ImGui::Text("None");
140
+    }
141
+    ImGui::NextColumn();
142
+    ImGui::PopID();
143
+}
144
+

+ 24
- 4
src/RoomData.cpp Näytä tiedosto

@@ -11,6 +11,8 @@
11 11
 #include "system/Shader.h"
12 12
 #include "RoomData.h"
13 13
 
14
+#include "imgui/imgui.h"
15
+
14 16
 #include <glbinding/gl/gl33.h>
15 17
 #include <glm/gtc/matrix_transform.hpp>
16 18
 
@@ -64,15 +66,19 @@ StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
64 66
 
65 67
 void StaticModel::display(glm::mat4 VP) {
66 68
     if (cache < 0) {
67
-        for (int i = 0; i < getWorld().sizeStaticMesh(); i++) {
68
-            if (getWorld().getStaticMesh(i).getID() == id) {
69
+        for (int i = 0; i < World::sizeStaticMesh(); i++) {
70
+            if (World::getStaticMesh(i).getID() == id) {
69 71
                 cache = i;
70 72
             }
71 73
         }
72 74
         orAssertGreaterThanEqual(cache, 0);
73 75
     }
74 76
 
75
-    getWorld().getStaticMesh(cache).display(VP * model);
77
+    World::getStaticMesh(cache).display(VP * model);
78
+}
79
+
80
+void StaticModel::displayUI() {
81
+    ImGui::Text("ID %d; No. %d", id, cache);
76 82
 }
77 83
 
78 84
 // ----------------------------------------------------------------------------
@@ -83,7 +89,21 @@ void RoomSprite::display(glm::mat4 VP) {
83 89
                                    0.0f));
84 90
     glm::mat4 model = translate * rotate;
85 91
 
86
-    getWorld().getSprite(sprite).display(VP * model);
92
+    World::getSprite(sprite).display(VP * model);
93
+}
94
+
95
+// ----------------------------------------------------------------------------
96
+
97
+bool Portal::showBoundingBox = false;
98
+
99
+void Portal::display(glm::mat4 VP) {
100
+    if (showBoundingBox) {
101
+        bbox.display(VP, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
102
+    }
103
+}
104
+
105
+void Portal::displayUI() {
106
+    ImGui::Text("To %03d", adjoiningRoom);
87 107
 }
88 108
 
89 109
 // ----------------------------------------------------------------------------

+ 1
- 1
src/SkeletalModel.cpp Näytä tiedosto

@@ -14,7 +14,7 @@
14 14
 #include <glm/gtc/matrix_transform.hpp>
15 15
 
16 16
 void BoneTag::display(glm::mat4 MVP, ShaderTexture* shaderTexture) {
17
-    getWorld().getMesh(mesh).display(MVP, shaderTexture);
17
+    World::getMesh(mesh).display(MVP, shaderTexture);
18 18
 }
19 19
 
20 20
 // ----------------------------------------------------------------------------

+ 1
- 1
src/Sprite.cpp Näytä tiedosto

@@ -49,6 +49,6 @@ void Sprite::display(glm::mat4 MVP) {
49 49
 void SpriteSequence::display(glm::mat4 MVP, int index) {
50 50
     orAssertGreaterThanEqual(index, 0);
51 51
     orAssertLessThan(index, length);
52
-    getWorld().getSprite(start + index).display(MVP);
52
+    World::getSprite(start + index).display(MVP);
53 53
 }
54 54
 

+ 10
- 1
src/StaticMesh.cpp Näytä tiedosto

@@ -9,10 +9,12 @@
9 9
 #include "World.h"
10 10
 #include "StaticMesh.h"
11 11
 
12
+#include "imgui/imgui.h"
13
+
12 14
 bool StaticMesh::showBoundingBox = false;
13 15
 
14 16
 void StaticMesh::display(glm::mat4 MVP) {
15
-    getWorld().getMesh(mesh).display(MVP);
17
+    World::getMesh(mesh).display(MVP);
16 18
 
17 19
     if (showBoundingBox) {
18 20
         bbox1->display(MVP, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
@@ -20,3 +22,10 @@ void StaticMesh::display(glm::mat4 MVP) {
20 22
     }
21 23
 }
22 24
 
25
+void StaticMesh::displayUI() {
26
+    ImGui::Text("%03d", id);
27
+    ImGui::NextColumn();
28
+    ImGui::Text("%03d // and two bboxes", mesh);
29
+    ImGui::NextColumn();
30
+}
31
+

+ 9
- 9
src/TextureManager.cpp Näytä tiedosto

@@ -543,17 +543,17 @@ void TextureManager::display() {
543 543
     }
544 544
 
545 545
     if (ImGui::CollapsingHeader("Sprite Sequence Viewer")) {
546
-        if (getWorld().sizeSprite() <= 0) {
546
+        if (World::sizeSprite() <= 0) {
547 547
             ImGui::Text("Please load a level containing sprites!");
548 548
         } else {
549 549
             static int index = 0;
550 550
             static int sprite = 0;
551
-            if (ImGui::SliderInt("##spriteslide", &index, 0, getWorld().sizeSpriteSequence() - 1)) {
551
+            if (ImGui::SliderInt("##spriteslide", &index, 0, World::sizeSpriteSequence() - 1)) {
552 552
                 sprite = 0;
553 553
             }
554 554
             ImGui::SameLine();
555 555
             if (ImGui::Button("+##spriteplus", ImVec2(0, 0), true)) {
556
-                if (index < (getWorld().sizeSpriteSequence() - 1))
556
+                if (index < (World::sizeSpriteSequence() - 1))
557 557
                     index++;
558 558
                 else
559 559
                     index = 0;
@@ -564,23 +564,23 @@ void TextureManager::display() {
564 564
                 if (index > 0)
565 565
                     index--;
566 566
                 else
567
-                    index = getWorld().sizeSpriteSequence() - 1;
567
+                    index = World::sizeSpriteSequence() - 1;
568 568
                 sprite = 0;
569 569
             }
570 570
 
571
-            if (index >= getWorld().sizeSpriteSequence()) {
571
+            if (index >= World::sizeSpriteSequence()) {
572 572
                 index = 0;
573 573
                 sprite = 0;
574 574
             }
575 575
 
576
-            if (sprite >= getWorld().getSpriteSequence(index).size()) {
576
+            if (sprite >= World::getSpriteSequence(index).size()) {
577 577
                 sprite = 0;
578 578
             }
579 579
 
580 580
             ImGui::SameLine();
581
-            ImGui::Text("Sprite %d/%d", sprite + 1, getWorld().getSpriteSequence(index).size());
581
+            ImGui::Text("Sprite %d/%d", sprite + 1, World::getSpriteSequence(index).size());
582 582
 
583
-            auto& s = getWorld().getSprite(getWorld().getSpriteSequence(index).getStart() + sprite);
583
+            auto& s = World::getSprite(World::getSpriteSequence(index).getStart() + sprite);
584 584
             auto bm = getBufferManager(s.getTexture(), TextureStorage::GAME);
585 585
             ImVec2 size(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3);
586 586
             auto uv = s.getUVs();
@@ -593,7 +593,7 @@ void TextureManager::display() {
593 593
                 fr--;
594 594
             } else {
595 595
                 fr = RunTime::getFPS() / 10;
596
-                if (sprite < (getWorld().getSpriteSequence(index).size() - 1))
596
+                if (sprite < (World::getSpriteSequence(index).size() - 1))
597 597
                     sprite++;
598 598
                 else
599 599
                     sprite = 0;

+ 4
- 3
src/UI.cpp Näytä tiedosto

@@ -255,6 +255,7 @@ void UI::display() {
255 255
         RunTime::display();
256 256
         TextureManager::display();
257 257
         SoundManager::display();
258
+        World::displayUI();
258 259
 
259 260
         if (ImGui::CollapsingHeader("Library Versions")) {
260 261
             ImGui::TextWrapped("%s", VERSION);
@@ -287,7 +288,7 @@ void UI::display() {
287 288
         if (ImGui::CollapsingHeader("ShaderTexture Test")) {
288 289
             static ShaderTexture* st = nullptr;
289 290
             static int index = 0;
290
-            ImGui::SliderInt("SkeletalModel", &index, 0, getWorld().sizeSkeletalModel() - 1);
291
+            ImGui::SliderInt("SkeletalModel", &index, 0, World::sizeSkeletalModel() - 1);
291 292
 
292 293
             static glm::mat4 MVP(1.0f);
293 294
             static bool dirty = true, redraw = false;
@@ -322,8 +323,8 @@ void UI::display() {
322 323
                 dirty = false;
323 324
             }
324 325
 
325
-            if ((index >= 0) && (index < getWorld().sizeSkeletalModel())) {
326
-                auto& sm = getWorld().getSkeletalModel(index);
326
+            if ((index >= 0) && (index < World::sizeSkeletalModel())) {
327
+                auto& sm = World::getSkeletalModel(index);
327 328
                 if ((sm.size() > 0) && (sm.get(0).size() > 0)) {
328 329
                     if (ImGui::Button("(Re)Create ShaderTexture...")) {
329 330
                         if (st != nullptr) {

+ 103
- 38
src/World.cpp Näytä tiedosto

@@ -8,108 +8,173 @@
8 8
 #include "global.h"
9 9
 #include "World.h"
10 10
 
11
-World::~World() {
12
-    destroy();
13
-}
11
+#include "imgui/imgui.h"
12
+
13
+std::vector<std::unique_ptr<Room>> World::rooms;
14
+std::vector<std::unique_ptr<Sprite>> World::sprites;
15
+std::vector<std::unique_ptr<SpriteSequence>> World::spriteSequences;
16
+std::vector<std::unique_ptr<Entity>> World::entities;
17
+std::vector<std::unique_ptr<SkeletalModel>> World::models;
18
+std::vector<std::unique_ptr<StaticMesh>> World::staticMeshes;
19
+std::vector<std::unique_ptr<Mesh>> World::meshes;
14 20
 
15 21
 void World::destroy() {
16
-    mRooms.clear();
17
-    mSprites.clear();
18
-    mSpriteSequences.clear();
19
-    mEntities.clear();
20
-    mModels.clear();
21
-    mStaticMeshes.clear();
22
-    mMeshes.clear();
22
+    rooms.clear();
23
+    sprites.clear();
24
+    spriteSequences.clear();
25
+    entities.clear();
26
+    models.clear();
27
+    staticMeshes.clear();
28
+    meshes.clear();
23 29
 }
24 30
 
25 31
 void World::addRoom(Room* room) {
26
-    mRooms.emplace_back(std::unique_ptr<Room>(room));
32
+    rooms.emplace_back(std::unique_ptr<Room>(room));
27 33
 }
28 34
 
29 35
 unsigned long World::sizeRoom() {
30
-    return mRooms.size();
36
+    return rooms.size();
31 37
 }
32 38
 
33 39
 Room& World::getRoom(unsigned long index) {
34
-    orAssertLessThan(index, mRooms.size());
35
-    return *mRooms.at(index);
40
+    orAssertLessThan(index, rooms.size());
41
+    return *rooms.at(index);
36 42
 }
37 43
 
38 44
 void World::addSprite(Sprite* sprite) {
39
-    mSprites.emplace_back(std::unique_ptr<Sprite>(sprite));
45
+    sprites.emplace_back(std::unique_ptr<Sprite>(sprite));
40 46
 }
41 47
 
42 48
 unsigned long World::sizeSprite() {
43
-    return mSprites.size();
49
+    return sprites.size();
44 50
 }
45 51
 
46 52
 Sprite& World::getSprite(unsigned long index) {
47
-    orAssertLessThan(index, mSprites.size());
48
-    return *mSprites.at(index);
53
+    orAssertLessThan(index, sprites.size());
54
+    return *sprites.at(index);
49 55
 }
50 56
 
51 57
 void World::addSpriteSequence(SpriteSequence* sprite) {
52
-    mSpriteSequences.emplace_back(std::unique_ptr<SpriteSequence>(sprite));
58
+    spriteSequences.emplace_back(std::unique_ptr<SpriteSequence>(sprite));
53 59
 }
54 60
 
55 61
 unsigned long World::sizeSpriteSequence() {
56
-    return mSpriteSequences.size();
62
+    return spriteSequences.size();
57 63
 }
58 64
 
59 65
 SpriteSequence& World::getSpriteSequence(unsigned long index) {
60
-    orAssertLessThan(index, mSpriteSequences.size());
61
-    return *mSpriteSequences.at(index);
66
+    orAssertLessThan(index, spriteSequences.size());
67
+    return *spriteSequences.at(index);
62 68
 }
63 69
 
64 70
 void World::addEntity(Entity* entity) {
65
-    mEntities.emplace_back(std::unique_ptr<Entity>(entity));
71
+    entities.emplace_back(std::unique_ptr<Entity>(entity));
66 72
 }
67 73
 
68 74
 unsigned long World::sizeEntity() {
69
-    return mEntities.size();
75
+    return entities.size();
70 76
 }
71 77
 
72 78
 Entity& World::getEntity(unsigned long index) {
73
-    orAssertLessThan(index, mEntities.size());
74
-    return *mEntities.at(index);
79
+    orAssertLessThan(index, entities.size());
80
+    return *entities.at(index);
75 81
 }
76 82
 
77 83
 void World::addSkeletalModel(SkeletalModel* model) {
78
-    mModels.emplace_back(std::unique_ptr<SkeletalModel>(model));
84
+    models.emplace_back(std::unique_ptr<SkeletalModel>(model));
79 85
 }
80 86
 
81 87
 unsigned long World::sizeSkeletalModel() {
82
-    return mModels.size();
88
+    return models.size();
83 89
 }
84 90
 
85 91
 SkeletalModel& World::getSkeletalModel(unsigned long index) {
86
-    orAssertLessThan(index, mModels.size());
87
-    return *mModels.at(index);
92
+    orAssertLessThan(index, models.size());
93
+    return *models.at(index);
88 94
 }
89 95
 
90 96
 void World::addStaticMesh(StaticMesh* model) {
91
-    mStaticMeshes.emplace_back(std::unique_ptr<StaticMesh>(model));
97
+    staticMeshes.emplace_back(std::unique_ptr<StaticMesh>(model));
92 98
 }
93 99
 
94 100
 unsigned long World::sizeStaticMesh() {
95
-    return mStaticMeshes.size();
101
+    return staticMeshes.size();
96 102
 }
97 103
 
98 104
 StaticMesh& World::getStaticMesh(unsigned long index) {
99
-    orAssertLessThan(index, mStaticMeshes.size());
100
-    return *mStaticMeshes.at(index);
105
+    orAssertLessThan(index, staticMeshes.size());
106
+    return *staticMeshes.at(index);
101 107
 }
102 108
 
103 109
 void World::addMesh(Mesh* mesh) {
104
-    mMeshes.emplace_back(mesh);
110
+    meshes.emplace_back(mesh);
105 111
 }
106 112
 
107 113
 unsigned long World::sizeMesh() {
108
-    return mMeshes.size();
114
+    return meshes.size();
109 115
 }
110 116
 
111 117
 Mesh& World::getMesh(unsigned long index) {
112
-    orAssertLessThan(index, mMeshes.size());
113
-    return *mMeshes.at(index);
118
+    orAssertLessThan(index, meshes.size());
119
+    return *meshes.at(index);
120
+}
121
+
122
+void World::displayUI() {
123
+    // Rooms
124
+    static bool offsets = false;
125
+    if (ImGui::CollapsingHeader("Rooms")) {
126
+        ImGui::Columns(6, "rooms");
127
+        ImGui::Text("No");
128
+        ImGui::NextColumn();
129
+        ImGui::Text("Ind.");
130
+        ImGui::NextColumn();
131
+        ImGui::Text("Alt.");
132
+        ImGui::NextColumn();
133
+        ImGui::Text("Flags");
134
+        ImGui::NextColumn();
135
+        ImGui::Text("Models");
136
+        ImGui::NextColumn();
137
+        ImGui::Text("Portals");
138
+        ImGui::NextColumn();
139
+        ImGui::Separator();
140
+        if (!offsets) {
141
+            ImGui::SetColumnOffset(1, 40.0f);
142
+            ImGui::SetColumnOffset(2, 80.0f);
143
+            ImGui::SetColumnOffset(3, 120.0f);
144
+            ImGui::SetColumnOffset(4, 180.0f);
145
+            ImGui::SetColumnOffset(5, 300.0f);
146
+            offsets = true;
147
+        }
148
+        for (int i = 0; i < rooms.size(); i++) {
149
+            ImGui::Text("%03d", i);
150
+            ImGui::NextColumn();
151
+            rooms.at(i)->displayUI();
152
+        }
153
+        ImGui::Columns(1);
154
+    }
155
+
156
+    // Static Meshes
157
+    static bool offsets2 = false;
158
+    if (ImGui::CollapsingHeader("StaticMeshes")) {
159
+        ImGui::Columns(3, "staticmeshes");
160
+        ImGui::Text("No");
161
+        ImGui::NextColumn();
162
+        ImGui::Text("ID");
163
+        ImGui::NextColumn();
164
+        ImGui::Text("Mesh");
165
+        ImGui::NextColumn();
166
+        ImGui::Separator();
167
+        if (!offsets2) {
168
+            ImGui::SetColumnOffset(1, 40.0f);
169
+            ImGui::SetColumnOffset(2, 80.0f);
170
+            offsets2 = true;
171
+        }
172
+        for (int i = 0; i < staticMeshes.size(); i++) {
173
+            ImGui::Text("%03d", i);
174
+            ImGui::NextColumn();
175
+            staticMeshes.at(i)->displayUI();
176
+        }
177
+        ImGui::Columns(1);
178
+    }
114 179
 }
115 180
 

+ 2
- 2
src/loader/LoaderTR1.cpp Näytä tiedosto

@@ -179,10 +179,10 @@ void LoaderTR1::loadItems() {
179 179
         );
180 180
 
181 181
         Entity* e = new Entity(objectID, room, pos, rot);
182
-        getWorld().addEntity(e);
182
+        World::addEntity(e);
183 183
 
184 184
         if (objectID == 0) {
185
-            Game::setLara(getWorld().sizeEntity() - 1);
185
+            Game::setLara(World::sizeEntity() - 1);
186 186
         }
187 187
     }
188 188
 

+ 14
- 14
src/loader/LoaderTR2.cpp Näytä tiedosto

@@ -384,11 +384,11 @@ void LoaderTR2::loadRooms() {
384 384
             // TODO translate vertices by room offset!
385 385
 
386 386
             portals.push_back(new Portal(adjoiningRoom,
387
-                                         glm::vec3(xNormal, yNormal, zNormal),
388
-                                         glm::vec3(xCorner1, yCorner1, zCorner1),
389
-                                         glm::vec3(xCorner2, yCorner2, zCorner2),
390
-                                         glm::vec3(xCorner3, yCorner3, zCorner3),
391
-                                         glm::vec3(xCorner4, yCorner4, zCorner4)));
387
+                                         glm::vec3(xNormal, yNormal, zNormal) + pos,
388
+                                         glm::vec3(xCorner1, yCorner1, zCorner1) + pos,
389
+                                         glm::vec3(xCorner2, yCorner2, zCorner2) + pos,
390
+                                         glm::vec3(xCorner3, yCorner3, zCorner3) + pos,
391
+                                         glm::vec3(xCorner4, yCorner4, zCorner4) + pos));
392 392
         }
393 393
 
394 394
         uint16_t numZSectors = file.readU16();
@@ -446,7 +446,7 @@ void LoaderTR2::loadRooms() {
446 446
         for (auto s : roomSprites)
447 447
             room->addSprite(s);
448 448
 
449
-        getWorld().addRoom(room);
449
+        World::addRoom(room);
450 450
 
451 451
         // Sanity check
452 452
         if ((numPortals == 0) && (numVertices == 0)
@@ -493,7 +493,7 @@ void LoaderTR2::loadSprites() {
493 493
         int16_t bottomSide = file.read16();
494 494
 
495 495
         Sprite* sp = new Sprite(tile, x, y, width, height);
496
-        getWorld().addSprite(sp);
496
+        World::addSprite(sp);
497 497
     }
498 498
 
499 499
     uint32_t numSpriteSequences = file.readU32();
@@ -507,7 +507,7 @@ void LoaderTR2::loadSprites() {
507 507
         orAssertLessThanEqual(offset + (negativeLength * -1), numSpriteTextures);
508 508
 
509 509
         SpriteSequence* ss = new SpriteSequence(objectID, offset, (negativeLength * -1));
510
-        getWorld().addSpriteSequence(ss);
510
+        World::addSpriteSequence(ss);
511 511
     }
512 512
 
513 513
     if ((numSpriteTextures > 0) || (numSpriteSequences > 0))
@@ -636,7 +636,7 @@ void LoaderTR2::loadMeshes() {
636 636
 
637 637
         Mesh* mesh = new Mesh(vertices, texturedRectangles, texturedTriangles,
638 638
                               coloredRectangles, coloredTriangles);
639
-        getWorld().addMesh(mesh);
639
+        World::addMesh(mesh);
640 640
     }
641 641
 
642 642
     if (numMeshPointers > 0)
@@ -675,7 +675,7 @@ void LoaderTR2::loadStaticMeshes() {
675 675
 
676 676
         BoundingBox* bbox1 = new BoundingBox(glm::vec3(x11, y11, z11), glm::vec3(x12, y12, z12));
677 677
         BoundingBox* bbox2 = new BoundingBox(glm::vec3(x21, y21, z21), glm::vec3(x22, y22, z22));
678
-        getWorld().addStaticMesh(new StaticMesh(objectID, mesh, bbox1, bbox2));
678
+        World::addStaticMesh(new StaticMesh(objectID, mesh, bbox1, bbox2));
679 679
     }
680 680
 
681 681
     if (numStaticMeshes > 0)
@@ -944,7 +944,7 @@ void LoaderTR2::loadMoveables() {
944 944
 
945 945
         SkeletalModel* sm = new SkeletalModel(objectID);
946 946
         sm->add(af);
947
-        getWorld().addSkeletalModel(sm);
947
+        World::addSkeletalModel(sm);
948 948
         /*
949 949
         } else {
950 950
             // TODO Add the whole animation hierarchy
@@ -962,7 +962,7 @@ void LoaderTR2::loadMoveables() {
962 962
 
963 963
             SkeletalModel* sm = new SkeletalModel(objectID);
964 964
             sm->add(af);
965
-            getWorld().addSkeletalModel(sm);
965
+            World::addSkeletalModel(sm);
966 966
         }
967 967
         */
968 968
     }
@@ -1005,10 +1005,10 @@ void LoaderTR2::loadItems() {
1005 1005
         );
1006 1006
 
1007 1007
         Entity* e = new Entity(objectID, room, pos, rot);
1008
-        getWorld().addEntity(e);
1008
+        World::addEntity(e);
1009 1009
 
1010 1010
         if (objectID == 0) {
1011
-            Game::setLara(getWorld().sizeEntity() - 1);
1011
+            Game::setLara(World::sizeEntity() - 1);
1012 1012
         }
1013 1013
     }
1014 1014
 

+ 1
- 7
src/main.cpp Näytä tiedosto

@@ -28,11 +28,6 @@
28 28
 #include <glbinding/Binding.h>
29 29
 
30 30
 static std::string configFileToUse;
31
-static std::shared_ptr<World> gWorld;
32
-
33
-World& getWorld() {
34
-    return *gWorld;
35
-}
36 31
 
37 32
 int main(int argc, char* argv[]) {
38 33
     command_t cmd;
@@ -48,8 +43,6 @@ int main(int argc, char* argv[]) {
48 43
     Log::initialize();
49 44
     RunTime::initialize(); // RunTime is required by other constructors
50 45
 
51
-    gWorld.reset(new World());
52
-
53 46
     Command::fillCommandList();
54 47
 
55 48
     Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
@@ -127,6 +120,7 @@ int main(int argc, char* argv[]) {
127 120
         renderFrame();
128 121
     }
129 122
 
123
+    World::destroy();
130 124
     Menu::shutdown();
131 125
     UI::shutdown();
132 126
     Sound::shutdown();

Loading…
Peruuta
Tallenna