Browse Source

Started world refactoring

Thomas Buck 10 years ago
parent
commit
404dd6b66e
8 changed files with 303 additions and 33 deletions
  1. 5
    0
      ChangeLog.md
  2. 9
    9
      include/Render.h
  3. 86
    0
      include/Room.h
  4. 28
    0
      include/Sprite.h
  5. 2
    0
      src/CMakeLists.txt
  6. 8
    24
      src/Game.cpp
  7. 71
    0
      src/Room.cpp
  8. 94
    0
      src/Sprite.cpp

+ 5
- 0
ChangeLog.md View File

@@ -2,6 +2,11 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140503 ]
6
+    * Started big World-Data refactoring.
7
+      - Created Sprite class with drawing code from Render
8
+      - Created Room, Portal, Box, Sector, StaticModel classes
9
+
5 10
 	[ 20140501 ]
6 11
 	* Fix compiling with gcc on Arch Linux
7 12
 	- carstene1ns <dev@f4ke.de>

+ 9
- 9
include/Render.h View File

@@ -192,15 +192,6 @@ public:
192 192
 
193 193
     unsigned int getFlags();
194 194
 
195
-    //! \fixme should be private
196
-
197
-    ViewVolume mViewVolume; //!< View Volume for frustum culling
198
-    std::vector<SkeletalModel *> mModels;
199
-
200
-private:
201
-
202
-    void drawLoadScreen();
203
-
204 195
     /*!
205 196
      * \brief Check if a bounding box is in the View Volume
206 197
      * \param bboxMin Start coordinates of a valid bounding box
@@ -228,6 +219,15 @@ private:
228 219
      */
229 220
     bool isVisible(float x, float y, float z, float radius);
230 221
 
222
+    //! \fixme should be private
223
+
224
+    ViewVolume mViewVolume; //!< View Volume for frustum culling
225
+    std::vector<SkeletalModel *> mModels;
226
+
227
+private:
228
+
229
+    void drawLoadScreen();
230
+
231 231
     /*!
232 232
      * \brief Build a visible room list starting at index
233 233
      * \param index valid room index where to start the list

+ 86
- 0
include/Room.h View File

@@ -0,0 +1,86 @@
1
+/*!
2
+ * \file include/Room.h
3
+ * \brief World Room Mesh
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _ROOM_H_
9
+#define _ROOM_H_
10
+
11
+#include <vector>
12
+#include <memory>
13
+#include "math/math.h"
14
+#include "Sprite.h"
15
+
16
+class StaticModel {
17
+public:
18
+    StaticModel(int _index, vec_t _yaw, vec3_t _pos);
19
+
20
+private:
21
+    int index;
22
+    vec_t yaw;
23
+    vec3_t pos;
24
+
25
+    // ?
26
+    //vec3_t bbox[2];
27
+};
28
+
29
+class Portal {
30
+public:
31
+    Portal(vec3_t _vertices[4], vec3_t _normal, int _adjoiningRoom);
32
+
33
+private:
34
+    vec3_t vertices[4];
35
+    vec3_t normal;
36
+    int adjoiningRoom;
37
+};
38
+
39
+class Box {
40
+public:
41
+    Box(vec3_t _a, vec3_t _b, vec3_t _c, vec3_t _d);
42
+
43
+private:
44
+    vec3_t a;
45
+    vec3_t b;
46
+    vec3_t c;
47
+    vec3_t d;
48
+};
49
+
50
+class Sector {
51
+public:
52
+    Sector(vec_t _floor, vec_t _ceiling, bool _wall);
53
+
54
+private:
55
+    vec_t floor;
56
+    vec_t ceiling;
57
+    bool wall;
58
+};
59
+
60
+typedef enum {
61
+    RoomFlagUnderWater = (1 << 0)
62
+} RoomFlags;
63
+
64
+class Room {
65
+public:
66
+    Room(int _id);
67
+    ~Room();
68
+
69
+private:
70
+    int id;
71
+    unsigned int flags;
72
+    unsigned int numXSectors;
73
+    unsigned int numZSectors;
74
+    vec3_t pos;
75
+    vec3_t bbox[2];
76
+
77
+    std::vector<int> adjacentRooms;
78
+    std::vector<Sprite *> sprites;
79
+    std::vector<StaticModel *> models;
80
+    std::vector<Portal *> portals;
81
+    std::vector<Box *> boxes;
82
+    std::vector<Sector *> sectors;
83
+};
84
+
85
+#endif
86
+

+ 28
- 0
include/Sprite.h View File

@@ -0,0 +1,28 @@
1
+/*!
2
+ * \file include/Sprite.h
3
+ * \brief World Sprite
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _SPRITE_H_
9
+#define _SPRITE_H_
10
+
11
+#include "math/math.h"
12
+
13
+class Sprite {
14
+public:
15
+    Sprite(int _numVerts, vec3_t _vertex[4], vec2_t _texel[4], vec3_t _pos, vec_t _radius, int _texture);
16
+    void display();
17
+
18
+private:
19
+    int numVerts;     //!< 4 == Quad, 3 == Triangle, rendered as triangles
20
+    vec3_t vertex[4];
21
+    vec2_t texel[4];
22
+    vec3_t pos;
23
+    vec_t radius;     //!< \fixme yeah, I know (I don't? --xythobuz)
24
+    int texture;
25
+};
26
+
27
+#endif
28
+

+ 2
- 0
src/CMakeLists.txt View File

@@ -48,8 +48,10 @@ set (SRCS ${SRCS} "Menu.cpp")
48 48
 set (SRCS ${SRCS} "Mesh.cpp")
49 49
 set (SRCS ${SRCS} "OpenRaider.cpp")
50 50
 set (SRCS ${SRCS} "Render.cpp")
51
+set (SRCS ${SRCS} "Room.cpp")
51 52
 set (SRCS ${SRCS} "SkeletalModel.cpp")
52 53
 set (SRCS ${SRCS} "Sound.cpp")
54
+set (SRCS ${SRCS} "Sprite.cpp")
53 55
 set (SRCS ${SRCS} "Texture.cpp")
54 56
 set (SRCS ${SRCS} "TombRaider.cpp")
55 57
 set (SRCS ${SRCS} "ViewVolume.cpp")

+ 8
- 24
src/Game.cpp View File

@@ -25,7 +25,7 @@
25 25
 // Old Code compatibility
26 26
 #define TexelScale 256.0f
27 27
 
28
-#ifndef EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
28
+#ifndef EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
29 29
 #define TextureLimit 24
30 30
 #endif
31 31
 
@@ -1300,8 +1300,8 @@ void Game::processRooms()
1300 1300
 
1301 1301
         // Room geometery //////////////////////////////////
1302 1302
 
1303
-        //#define EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
1304
-#ifdef EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
1303
+//#define EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
1304
+#ifdef EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
1305 1305
         unsigned int vertexCount, normalCount, colorCount, triCount;
1306 1306
         vec_t *vertexArray;
1307 1307
         vec_t *normalArray;
@@ -1680,27 +1680,11 @@ void Game::processRooms()
1680 1680
 
1681 1681
             sprite->texture += mTextureStart; // OpenRaider preloads some textures
1682 1682
 
1683
-            sprite->vertex[0].pos[0] = spriteVertices[0];
1684
-            sprite->vertex[0].pos[1] = spriteVertices[1];
1685
-            sprite->vertex[0].pos[2] = spriteVertices[2];
1686
-            sprite->vertex[1].pos[0] = spriteVertices[3];
1687
-            sprite->vertex[1].pos[1] = spriteVertices[4];
1688
-            sprite->vertex[1].pos[2] = spriteVertices[5];
1689
-            sprite->vertex[2].pos[0] = spriteVertices[6];
1690
-            sprite->vertex[2].pos[1] = spriteVertices[7];
1691
-            sprite->vertex[2].pos[2] = spriteVertices[8];
1692
-            sprite->vertex[3].pos[0] = spriteVertices[9];
1693
-            sprite->vertex[3].pos[1] = spriteVertices[10];
1694
-            sprite->vertex[3].pos[2] = spriteVertices[11];
1695
-
1696
-            sprite->texel[0].st[0] = spriteTexCoords[0];
1697
-            sprite->texel[0].st[1] = spriteTexCoords[1];
1698
-            sprite->texel[1].st[0] = spriteTexCoords[2];
1699
-            sprite->texel[1].st[1] = spriteTexCoords[3];
1700
-            sprite->texel[2].st[0] = spriteTexCoords[4];
1701
-            sprite->texel[2].st[1] = spriteTexCoords[5];
1702
-            sprite->texel[3].st[0] = spriteTexCoords[6];
1703
-            sprite->texel[3].st[1] = spriteTexCoords[7];
1683
+            for (j = 0; j < 12; j++)
1684
+                sprite->vertex[j / 3].pos[j % 3] = spriteVertices[j];
1685
+
1686
+            for (j = 0; j < 8; j++)
1687
+                sprite->texel[j / 2].st[j % 2] = spriteTexCoords[j];
1704 1688
 
1705 1689
             r_mesh->sprites.push_back(sprite);
1706 1690
         }

+ 71
- 0
src/Room.cpp View File

@@ -0,0 +1,71 @@
1
+/*!
2
+ * \file src/Room.cpp
3
+ * \brief World Room Mesh
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "Room.h"
9
+
10
+StaticModel::StaticModel(int _index, vec_t _yaw, vec3_t _pos) {
11
+    index = _index;
12
+    yaw = _yaw;
13
+    for (unsigned int i = 0; i < 3; i++)
14
+        pos[i] = _pos[i];
15
+}
16
+
17
+Portal::Portal(vec3_t _vertices[4], vec3_t _normal, int _adjoiningRoom) {
18
+    for (unsigned int i = 0; i < 3; i++) {
19
+        vertices[0][i] = _vertices[0][i];
20
+        vertices[1][i] = _vertices[1][i];
21
+        vertices[2][i] = _vertices[2][i];
22
+        vertices[3][i] = _vertices[3][i];
23
+        normal[i] = _normal[i];
24
+    }
25
+    adjoiningRoom = _adjoiningRoom;
26
+}
27
+
28
+Box::Box(vec3_t _a, vec3_t _b, vec3_t _c, vec3_t _d) {
29
+    for (unsigned int i = 0; i < 3; i++) {
30
+        a[i] = _a[i];
31
+        b[i] = _b[i];
32
+        c[i] = _c[i];
33
+        d[i] = _d[i];
34
+    }
35
+}
36
+
37
+Sector::Sector(vec_t _floor, vec_t _ceiling, bool _wall) {
38
+    floor = _floor;
39
+    ceiling = _ceiling;
40
+    wall = _wall;
41
+}
42
+
43
+Room::Room(int _id) {
44
+    id = _id;
45
+    flags = 0;
46
+    numXSectors = 0;
47
+    numZSectors = 0;
48
+    pos[0] = pos[1] = pos[2] = 0.0f;
49
+    bbox[0][0] = bbox[0][1] = bbox[0][2] = 0.0f;
50
+    bbox[1][0] = bbox[1][1] = bbox[1][2] = 0.0f;
51
+}
52
+
53
+Room::~Room() {
54
+    unsigned long i;
55
+
56
+    for (i = 0; i < sprites.size(); i++)
57
+        delete sprites[i];
58
+
59
+    for (i = 0; i < models.size(); i++)
60
+        delete models[i];
61
+
62
+    for (i = 0; i < portals.size(); i++)
63
+        delete portals[i];
64
+
65
+    for (i = 0; i < boxes.size(); i++)
66
+        delete boxes[i];
67
+
68
+    for (i = 0; i < sectors.size(); i++)
69
+        delete sectors[i];
70
+}
71
+

+ 94
- 0
src/Sprite.cpp View File

@@ -0,0 +1,94 @@
1
+/*!
2
+ * \file src/Sprite.cpp
3
+ * \brief World Sprite
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifdef __APPLE__
9
+#include <OpenGL/gl.h>
10
+#include <OpenGL/glu.h>
11
+#else
12
+#include <GL/gl.h>
13
+#include <GL/glu.h>
14
+#endif
15
+
16
+#include "main.h"
17
+#include "Sprite.h"
18
+
19
+Sprite::Sprite(int _numVerts, vec3_t _vertex[4], vec2_t _texel[4], vec3_t _pos, vec_t _radius, int _texture) {
20
+    numVerts = _numVerts;
21
+    radius = _radius;
22
+    texture = _texture;
23
+    for (unsigned int i = 0; i < 3; i++) {
24
+        vertex[0][i] = _vertex[0][i];
25
+        vertex[1][i] = _vertex[1][i];
26
+        vertex[2][i] = _vertex[2][i];
27
+        vertex[3][i] = _vertex[3][i];
28
+        pos[i] = _pos[i];
29
+        if (i < 2) {
30
+            texel[0][i] = _texel[0][i];
31
+            texel[1][i] = _texel[1][i];
32
+            texel[2][i] = _texel[2][i];
33
+            texel[3][i] = _texel[3][i];
34
+        }
35
+    }
36
+}
37
+
38
+void Sprite::display() {
39
+    if (!getRender().isVisible(pos[0], pos[1], pos[2],
40
+                radius))
41
+        return;
42
+
43
+    glPushMatrix();
44
+    glTranslated(pos[0], pos[1], pos[2]);
45
+
46
+    // Sprites must always face camera, because they have no depth =)
47
+    glRotated(OR_RAD_TO_DEG(getCamera().getRadianYaw()), 0, 1, 0);
48
+
49
+    switch (getRender().getMode()) {
50
+        // No vertex lighting on sprites, as far as I see in specs
51
+        // So just draw normal texture, no case 2
52
+        case Render::modeSolid:
53
+            glBegin(GL_TRIANGLE_STRIP);
54
+            glColor3f(texel[0][0], texel[0][1], 0.5);
55
+            glVertex3fv(vertex[0]);
56
+
57
+            glColor3f(texel[1][0], texel[1][1], 0.5);
58
+            glVertex3fv(vertex[1]);
59
+
60
+            glColor3f(texel[3][0], texel[3][1], 0.5);
61
+            glVertex3fv(vertex[3]);
62
+
63
+            glColor3f(texel[2][0], texel[2][1], 0.5);
64
+            glVertex3fv(vertex[2]);
65
+            glEnd();
66
+            break;
67
+        case Render::modeWireframe:
68
+            glColor3fv(CYAN);
69
+            glBegin(GL_LINE_LOOP);
70
+            glVertex3fv(vertex[0]);
71
+            glVertex3fv(vertex[1]);
72
+            glVertex3fv(vertex[2]);
73
+            glVertex3fv(vertex[3]);
74
+            glEnd();
75
+            glColor3fv(WHITE);
76
+            break;
77
+        default:
78
+            glBindTexture(GL_TEXTURE_2D, texture+1);
79
+
80
+            glBegin(GL_TRIANGLE_STRIP);
81
+            glTexCoord2fv(texel[0]);
82
+            glVertex3fv(vertex[0]);
83
+            glTexCoord2fv(texel[1]);
84
+            glVertex3fv(vertex[1]);
85
+            glTexCoord2fv(texel[3]);
86
+            glVertex3fv(vertex[3]);
87
+            glTexCoord2fv(texel[2]);
88
+            glVertex3fv(vertex[2]);
89
+            glEnd();
90
+    }
91
+
92
+    glPopMatrix();
93
+}
94
+

Loading…
Cancel
Save