Przeglądaj źródła

Rewrote room loading code

Thomas Buck 11 lat temu
rodzic
commit
552687f17f
6 zmienionych plików z 241 dodań i 270 usunięć
  1. 1
    0
      ChangeLog.md
  2. 3
    62
      include/Render.h
  3. 48
    1
      include/Room.h
  4. 4
    0
      include/WorldData.h
  5. 181
    207
      src/Game.cpp
  6. 4
    0
      src/Room.cpp

+ 1
- 0
ChangeLog.md Wyświetl plik

5
     [ 20140504 ]
5
     [ 20140504 ]
6
     * Forcing use of new Room and Sprite classes in World.
6
     * Forcing use of new Room and Sprite classes in World.
7
     * Rewrote Sprite loading code in Game
7
     * Rewrote Sprite loading code in Game
8
+    * Rewrote Room loading code in Game
8
 
9
 
9
     [ 20140503 ]
10
     [ 20140503 ]
10
     * Started big World-Data refactoring.
11
     * Started big World-Data refactoring.

+ 3
- 62
include/Render.h Wyświetl plik

21
 #include "Camera.h"
21
 #include "Camera.h"
22
 
22
 
23
 /*!
23
 /*!
24
- * \brief The GL light class
25
- */
26
-class Light {
27
-public:
28
-    /*!
29
-     * \brief Type a light can be of
30
-     */
31
-    typedef enum {
32
-        typePoint       = 1, //!< Point light
33
-        typeSpot        = 2, //!< Spot light
34
-        typeDirectional = 3  //!< Directional light
35
-    } LightType;
36
-
37
-    vec4_t mPos; //! Light position in 3 space
38
-    vec3_t mDir; //! Light direction
39
-    float mAtt;
40
-    vec4_t mColor; //! Color of light
41
-    vec_t mCutoff; //! Fade out distance
42
-    LightType mType; //! Type of light
43
-};
44
-
45
-/*!
46
- * \brief RenderRoom used by Renderer
47
- */
48
-class RenderRoom {
49
-public:
50
-
51
-    /*!
52
-     * \brief Constructs an object of RenderRoom
53
-     */
54
-    RenderRoom() {
55
-        room = 0x0;
56
-        dist = 0.0f;
57
-    }
58
-
59
-    /*!
60
-     * \brief Deconstructs an object of RenderRoom
61
-     */
62
-    ~RenderRoom() {
63
-        // \fixme Hangs when erasing - might be shared pointers somewhere
64
-        for (std::vector<Light *>::size_type i = 0; i != lights.size(); i++) {
65
-            if (lights[i])
66
-                delete lights[i];
67
-        }
68
-        lights.clear();
69
-    }
70
-
71
-    vec_t dist;             //!< Distance to near plane, move to room?
72
-    std::vector<Light *> lights; //!< List of lights in this room
73
-    Mesh mesh;              //!< OpenGL mesh that represents this room
74
-
75
-    //! \fixme very dangerous as allocated and used
76
-    room_mesh_t *room;      //!< Physical room stored in World
77
-};
78
-
79
-/*!
80
  * \brief OpenRaider Renderer class
24
  * \brief OpenRaider Renderer class
81
  */
25
  */
82
 class Render {
26
 class Render {
137
      */
81
      */
138
     int getMode();
82
     int getMode();
139
 
83
 
140
-    void addRoom(RenderRoom *rRoom);
141
-
142
     /*!
84
     /*!
143
      * \brief Loads textures in a certain id slot
85
      * \brief Loads textures in a certain id slot
144
      * \param image Image to load
86
      * \param image Image to load
239
      * only considers its linked rooms and their linked rooms.
181
      * only considers its linked rooms and their linked rooms.
240
      * \param room First room in list
182
      * \param room First room in list
241
      */
183
      */
242
-    void buildRoomRenderList(RenderRoom *room);
184
+    void buildRoomRenderList(Room *room);
243
 
185
 
244
     /*!
186
     /*!
245
      * \brief Renders visible world object.
187
      * \brief Renders visible world object.
273
      * \param rRoom room to render
215
      * \param rRoom room to render
274
      * \param draw_alpha once false, once true
216
      * \param draw_alpha once false, once true
275
      */
217
      */
276
-    void drawRoom(RenderRoom *rRoom, bool draw_alpha);
218
+    void drawRoom(Room *rRoom, bool draw_alpha);
277
 
219
 
278
     /*!
220
     /*!
279
      * \brief Renders static room model.
221
      * \brief Renders static room model.
310
 
252
 
311
     Texture mTexture;                     //!< Texture subsystem
253
     Texture mTexture;                     //!< Texture subsystem
312
 
254
 
313
-    std::vector<RenderRoom *> mRoomRenderList;
314
-    std::vector<RenderRoom *> mRooms;
255
+    std::vector<Room *> mRoomRenderList;
315
 
256
 
316
     unsigned int mFlags;                  //!< Rendering flags
257
     unsigned int mFlags;                  //!< Rendering flags
317
     unsigned int mMode;                   //!< Rendering mode
258
     unsigned int mMode;                   //!< Rendering mode

+ 48
- 1
include/Room.h Wyświetl plik

11
 #include <vector>
11
 #include <vector>
12
 #include <memory>
12
 #include <memory>
13
 #include "math/math.h"
13
 #include "math/math.h"
14
+#include "Mesh.h"
14
 #include "Sprite.h"
15
 #include "Sprite.h"
15
 
16
 
17
+class Light {
18
+public:
19
+    /*!
20
+     * \brief Type a light can be of
21
+     */
22
+    typedef enum {
23
+        typePoint       = 1, //!< Point light
24
+        typeSpot        = 2, //!< Spot light
25
+        typeDirectional = 3  //!< Directional light
26
+    } LightType;
27
+
28
+    Light(vec4_t pos, vec3_t dir, vec_t att, vec4_t color, vec_t cutoff, LightType type);
29
+
30
+//private:
31
+    vec4_t mPos; //! Light position in 3 space
32
+    vec3_t mDir; //! Light direction
33
+    vec_t mAtt;
34
+    vec4_t mColor; //! Color of light
35
+    vec_t mCutoff; //! Fade out distance
36
+    LightType mType; //! Type of light
37
+};
38
+
16
 class StaticModel {
39
 class StaticModel {
17
 public:
40
 public:
18
     StaticModel(int _index, vec_t _yaw, vec3_t _pos);
41
     StaticModel(int _index, vec_t _yaw, vec3_t _pos);
72
     Room(int _id);
95
     Room(int _id);
73
     ~Room();
96
     ~Room();
74
 
97
 
98
+    void setFlags(unsigned int f);
75
     unsigned int getFlags();
99
     unsigned int getFlags();
100
+
101
+    void setNumXSectors(unsigned int n);
76
     unsigned int getNumXSectors();
102
     unsigned int getNumXSectors();
103
+
104
+    void setNumZSectors(unsigned int n);
77
     unsigned int getNumZSectors();
105
     unsigned int getNumZSectors();
78
-    void getPos(vec_t *target);
79
 
106
 
107
+    void setPos(vec3_t p);
108
+    void getPos(vec3_t p);
109
+
110
+    void setBoundingBox(vec3_t box[2]);
80
     bool inBox(vec_t x, vec_t y, vec_t z);
111
     bool inBox(vec_t x, vec_t y, vec_t z);
81
     bool inBoxPlane(vec_t x, vec_t z);
112
     bool inBoxPlane(vec_t x, vec_t z);
82
 
113
 
114
+    void addAdjacentRoom(int r);
115
+
83
     unsigned int sizePortals();
116
     unsigned int sizePortals();
84
     Portal &getPortal(unsigned int index);
117
     Portal &getPortal(unsigned int index);
118
+    void addPortal(Portal &p);
85
 
119
 
86
     unsigned int sizeSectors();
120
     unsigned int sizeSectors();
87
     Sector &getSector(unsigned int index);
121
     Sector &getSector(unsigned int index);
122
+    void addSector(Sector &s);
123
+
124
+    void addBox(Box &b);
125
+    void addModel(StaticModel &m);
126
+    void addSprite(Sprite &s);
127
+    void addLight(Light &l);
128
+
129
+    Mesh &getMesh();
88
 
130
 
89
 private:
131
 private:
90
     int id;
132
     int id;
100
     std::vector<Portal *> portals;
142
     std::vector<Portal *> portals;
101
     std::vector<Box *> boxes;
143
     std::vector<Box *> boxes;
102
     std::vector<Sector *> sectors;
144
     std::vector<Sector *> sectors;
145
+
146
+    // Was previously stored in RenderRoom
147
+    vec_t dist;                  //!< Distance to near plane, move to room?
148
+    std::vector<Light *> lights; //!< List of lights in this room
149
+    Mesh mesh;                   //!< OpenGL mesh that represents this room
103
 };
150
 };
104
 
151
 
105
 #endif
152
 #endif

+ 4
- 0
include/WorldData.h Wyświetl plik

33
     vec2_t st;
33
     vec2_t st;
34
 } texel_t;
34
 } texel_t;
35
 
35
 
36
+/*
36
 typedef struct {
37
 typedef struct {
37
     int num_verts;      //!< 4 == Quad, 3 == Triangle, rendered as triangles
38
     int num_verts;      //!< 4 == Quad, 3 == Triangle, rendered as triangles
38
     vertex_t vertex[4];
39
     vertex_t vertex[4];
46
     int num_sprites;
47
     int num_sprites;
47
     sprite_t *sprite;
48
     sprite_t *sprite;
48
 } sprite_seq_t;
49
 } sprite_seq_t;
50
+*/
49
 
51
 
50
 /*! \fixme For now shaders are textures on tex objects
52
 /*! \fixme For now shaders are textures on tex objects
51
  * and materials on color objects. If -1
53
  * and materials on color objects. If -1
102
     */
104
     */
103
 } entity_t;
105
 } entity_t;
104
 
106
 
107
+/*
105
 typedef struct {
108
 typedef struct {
106
     int index;    //!< model_mesh index
109
     int index;    //!< model_mesh index
107
     float yaw;    //!< angle of rotation on Y
110
     float yaw;    //!< angle of rotation on Y
148
     vec3_t bbox_min;
151
     vec3_t bbox_min;
149
     vec3_t bbox_max;
152
     vec3_t bbox_max;
150
 } room_mesh_t;
153
 } room_mesh_t;
154
+*/
151
 
155
 
152
 #endif
156
 #endif
153
 
157
 

+ 181
- 207
src/Game.cpp Wyświetl plik

177
 
177
 
178
     printf("Processing sprites: ");
178
     printf("Processing sprites: ");
179
 
179
 
180
-    for (unsigned int i = 0; i < (mTombRaider.NumItems() - 1); i++) {
180
+    for (int i = 0; i < (mTombRaider.NumItems() - 1); i++) {
181
         if ((mTombRaider.Engine() == TR_VERSION_1) && (item[i].intensity1 == -1))
181
         if ((mTombRaider.Engine() == TR_VERSION_1) && (item[i].intensity1 == -1))
182
             continue;
182
             continue;
183
 
183
 
184
         int id = item[i].object_id;
184
         int id = item[i].object_id;
185
-        for (unsigned int j = 0; j < mTombRaider.NumSpriteSequences(); j++) {
185
+        for (int j = 0; j < mTombRaider.NumSpriteSequences(); j++) {
186
             if (spriteSequence[j].object_id == id) {
186
             if (spriteSequence[j].object_id == id) {
187
                 SpriteSequence &sequence = *new SpriteSequence();
187
                 SpriteSequence &sequence = *new SpriteSequence();
188
-                for (unsigned int k = 0; k < (-spriteSequence[j].negative_length); k++) {
188
+                for (int k = 0; k < (-spriteSequence[j].negative_length); k++) {
189
                     tr2_sprite_texture_t *sprite = &spriteTextures[spriteSequence[j].offset];
189
                     tr2_sprite_texture_t *sprite = &spriteTextures[spriteSequence[j].offset];
190
 
190
 
191
                     int width = sprite->width >> 8;
191
                     int width = sprite->width >> 8;
192
                     int height = sprite->height >> 8;
192
                     int height = sprite->height >> 8;
193
                     int x = sprite->x;
193
                     int x = sprite->x;
194
                     int y = sprite->y;
194
                     int y = sprite->y;
195
-                    int width2 = width * scale;
196
-                    int height2 = height * scale;
195
+                    int width2 = (int)(width * scale);
196
+                    int height2 = (int)(height * scale);
197
 
197
 
198
                     vec3_t vertex[4];
198
                     vec3_t vertex[4];
199
                     vec2_t texel[4];
199
                     vec2_t texel[4];
244
     printf("Done! Found %d sprites.\n", mTombRaider.NumSpriteSequences());
244
     printf("Done! Found %d sprites.\n", mTombRaider.NumSpriteSequences());
245
 }
245
 }
246
 
246
 
247
-void Game::processRooms()
248
-{
247
+void Game::processRooms() {
249
     printf("Processing rooms: ");
248
     printf("Processing rooms: ");
249
+
250
     for (int index = 0; index < mTombRaider.NumRooms(); index++) {
250
     for (int index = 0; index < mTombRaider.NumRooms(); index++) {
251
-        unsigned int i, j, count;
252
-        room_mesh_t *r_mesh = NULL;
253
-        RenderRoom *rRoom = NULL;
254
         Matrix transform;
251
         Matrix transform;
252
+        Room &room = *new Room(index);
253
+        getWorld().addRoom(room);
255
 
254
 
256
-        if (!mTombRaider.isRoomValid(index))
257
-        {
255
+        if (!mTombRaider.isRoomValid(index)) {
258
             getConsole().print("WARNING: Handling invalid vertex array in room");
256
             getConsole().print("WARNING: Handling invalid vertex array in room");
259
-            getWorld().addRoom(0x0);
260
-            getRender().addRoom(0x0);
261
-
262
             //printf("x");
257
             //printf("x");
263
             //fflush(stdout);
258
             //fflush(stdout);
264
-            return;
259
+            //return; // ?
260
+            continue;
265
         }
261
         }
266
 
262
 
267
-        rRoom = new RenderRoom();
268
-        r_mesh = new room_mesh_t;
269
-        r_mesh->id = index;
263
+        unsigned int flags;
264
+        vec3_t pos;
265
+        vec3_t bbox[2];
266
+        mTombRaider.getRoomInfo(index, &flags, pos, bbox[0], bbox[1]);
267
+        room.setFlags(flags);
268
+        room.setPos(pos);
270
 
269
 
271
-        mTombRaider.getRoomInfo(index, &r_mesh->flags, r_mesh->pos,
272
-                r_mesh->bbox_min, r_mesh->bbox_max);
270
+        // Adjust positioning for OR world coordinate translation
271
+        bbox[0][0] += pos[0];
272
+        bbox[1][0] += pos[0];
273
+        bbox[0][2] += pos[2];
274
+        bbox[1][2] += pos[2];
273
 
275
 
274
-        // Adjust positioning for OR world coord translation
275
-        r_mesh->bbox_min[0] += r_mesh->pos[0];
276
-        r_mesh->bbox_max[0] += r_mesh->pos[0];
277
-        r_mesh->bbox_min[2] += r_mesh->pos[2];
278
-        r_mesh->bbox_max[2] += r_mesh->pos[2];
276
+        room.setBoundingBox(bbox);
279
 
277
 
280
-        // Mongoose 2002.04.03, Setup 3d transform
278
+        // Mongoose 2002.04.03, Setup 3D transform
281
         transform.setIdentity();
279
         transform.setIdentity();
282
-        transform.translate(r_mesh->pos);
280
+        transform.translate(pos);
283
 
281
 
284
         // Setup portals
282
         // Setup portals
285
         float portalVertices[12];
283
         float portalVertices[12];
286
-        count = mTombRaider.getRoomPortalCount(index);
287
-
288
-        //! \fixme OR wrongly uses a cached adj room list for rendering vis
289
-        r_mesh->adjacentRooms.reserve(count + 1);
284
+        unsigned int count = mTombRaider.getRoomPortalCount(index);
290
 
285
 
291
         // Current room is always first
286
         // Current room is always first
292
-        r_mesh->adjacentRooms.push_back(index);
293
-
294
-        for (i = 0; i < count; ++i)
295
-        {
296
-            portal_t *portal = new portal_t;
297
-
298
-            mTombRaider.getRoomPortal(index, i,
299
-                    &portal->adjoining_room, portal->normal,
300
-                    portalVertices);
301
-
302
-            for (j = 0; j < 4; ++j)
303
-            {
304
-                portal->vertices[j][0] = portalVertices[j*3];
305
-                portal->vertices[j][1] = portalVertices[j*3+1];
306
-                portal->vertices[j][2] = portalVertices[j*3+2];
287
+        room.addAdjacentRoom(index);
288
+
289
+        for (unsigned int i = 0; i < count; i++) {
290
+            vec3_t vertices[4];
291
+            vec3_t normal;
292
+            int adjoiningRoom;
293
+            mTombRaider.getRoomPortal(index, i, &adjoiningRoom, normal, portalVertices);
294
+            for (unsigned int j = 0; j < 4; ++j) {
295
+                vertices[j][0] = portalVertices[j*3];
296
+                vertices[j][1] = portalVertices[j*3+1];
297
+                vertices[j][2] = portalVertices[j*3+2];
307
 
298
 
308
                 // Relative coors in vis portals
299
                 // Relative coors in vis portals
309
-                transform.multiply3v(portal->vertices[j], portal->vertices[j]);
300
+                transform.multiply3v(vertices[j], vertices[j]);
310
             }
301
             }
311
-
312
-            r_mesh->adjacentRooms.push_back(portal->adjoining_room);
313
-            r_mesh->portals.push_back(portal);
302
+            Portal &portal = *new Portal(vertices, normal, adjoiningRoom);
303
+            room.addPortal(portal);
304
+            room.addAdjacentRoom(adjoiningRoom);
314
         }
305
         }
315
 
306
 
316
         // Physics/gameplay use /////////////////////////////
307
         // Physics/gameplay use /////////////////////////////
318
         //! \fixme Use more of sector structure, boxes, and floordata
309
         //! \fixme Use more of sector structure, boxes, and floordata
319
 
310
 
320
         // List of sectors in this room
311
         // List of sectors in this room
321
-        unsigned int sectorFlags;
322
-        int floorDataIndex, boxIndex, roomBelow, roomAbove;
323
-        count = mTombRaider.getRoomSectorCount(index, &r_mesh->numZSectors,
324
-                &r_mesh->numXSectors);
325
-        r_mesh->sectors.reserve(count);
326
-
327
-        for (i = 0; i < count; ++i)
328
-        {
329
-            sector_t *sector = new sector_t;
312
+        unsigned int numXSectors, numZSectors;
313
+        count = mTombRaider.getRoomSectorCount(index, &numZSectors, &numXSectors);
314
+        room.setNumXSectors(numXSectors);
315
+        room.setNumZSectors(numZSectors);
316
+        for (unsigned int i = 0; i < count; i++) {
317
+            unsigned int sectorFlags;
318
+            int floorDataIndex, boxIndex, roomBelow, roomAbove;
319
+            vec_t floor, ceiling;
320
+            bool wall = false;
330
 
321
 
331
             mTombRaider.getRoomSector(index, i, &sectorFlags,
322
             mTombRaider.getRoomSector(index, i, &sectorFlags,
332
-                    &sector->ceiling, &sector->floor,
333
-                    &floorDataIndex, &boxIndex, &roomBelow,
334
-                    &roomAbove);
323
+                    &ceiling, &floor, &floorDataIndex, &boxIndex,
324
+                    &roomBelow, &roomAbove);
335
 
325
 
336
             if (sectorFlags & tombraiderSector_wall)
326
             if (sectorFlags & tombraiderSector_wall)
337
-            {
338
-                sector->wall = true;
339
-            }
340
-            else
341
-            {
342
-                sector->wall = false;
343
-            }
327
+                wall = true;
344
 
328
 
345
-            r_mesh->sectors.push_back(sector);
329
+            room.addSector(*new Sector(floor, ceiling, wall));
346
         }
330
         }
347
 
331
 
348
-        // Setup collision boxes ( Should use sectors, but this is a test )
332
+        // Setup collision boxes
333
+        //! fixme Should use sectors, but this is a test
349
         count = mTombRaider.getRoomBoxCount(index);
334
         count = mTombRaider.getRoomBoxCount(index);
350
-        r_mesh->boxes.reserve(count);
351
 
335
 
352
         //! fixme Only to be done only on room[0]?  I don't think so...
336
         //! fixme Only to be done only on room[0]?  I don't think so...
353
-        for (i = 0; !index && i < count; ++i)
354
-        {
355
-            box_t *box = new box_t;
356
-
357
-            mTombRaider.getRoomBox(index, i,
358
-                    box->a.pos, box->b.pos, box->c.pos, box->d.pos);
359
-
360
-            r_mesh->boxes.push_back(box);
337
+        for (unsigned int i = 0; !index && i < count; i++) {
338
+            vec3_t a, b, c, d;
339
+            mTombRaider.getRoomBox(index, i, a, b, c, d);
340
+            room.addBox(*new Box(a, b, c, d));
361
         }
341
         }
362
 
342
 
363
         // Setup room lights /////////////////////////////////////
343
         // Setup room lights /////////////////////////////////////
364
-        unsigned int lightFlags, lightType;
365
         count = mTombRaider.getRoomLightCount(index);
344
         count = mTombRaider.getRoomLightCount(index);
366
-        rRoom->lights.reserve(count);
367
 
345
 
368
-        for (i = 0; i < count; ++i)
369
-        {
370
-            Light *light = new Light();
346
+        for (unsigned int i = 0; i < count; i++) {
347
+            unsigned int lightFlags, lightType;
348
+            vec4_t position;
349
+            vec3_t dir;
350
+            vec_t att;
351
+            vec4_t color;
352
+            vec_t cutoff;
353
+            Light::LightType type;
371
 
354
 
372
-            mTombRaider.getRoomLight(index, i,
373
-                    light->mPos, light->mColor, light->mDir,
374
-                    &light->mAtt, &light->mCutoff,
375
-                    &lightType, &lightFlags);
355
+            mTombRaider.getRoomLight(index, i, position, color,
356
+                    dir, &att, &cutoff, &lightType, &lightFlags);
376
 
357
 
377
-            switch (lightType)
378
-            {
358
+            switch (lightType) {
379
                 case tombraiderLight_typeDirectional:
359
                 case tombraiderLight_typeDirectional:
380
-                    light->mType = Light::typeDirectional;
360
+                    type = Light::typeDirectional;
381
                     break;
361
                     break;
382
                 case tombraiderLight_typeSpot:
362
                 case tombraiderLight_typeSpot:
383
-                    light->mType = Light::typeSpot;
363
+                    type = Light::typeSpot;
384
                     break;
364
                     break;
385
                 case tombraiderLight_typePoint:
365
                 case tombraiderLight_typePoint:
386
                 default:
366
                 default:
387
-                    light->mType = Light::typePoint;
367
+                    type = Light::typePoint;
388
             }
368
             }
389
 
369
 
390
-            rRoom->lights.push_back(light);
370
+            room.addLight(*new Light(position, dir, att, color, cutoff, type));
371
+
372
+            //! \todo Light flags?
391
         }
373
         }
392
 
374
 
393
         // Room geometery //////////////////////////////////
375
         // Room geometery //////////////////////////////////
407
                 &normalCount, &normalArray,
389
                 &normalCount, &normalArray,
408
                 &colorCount, &colorArray);
390
                 &colorCount, &colorArray);
409
 
391
 
410
-        rRoom->mesh.bufferVertexArray(vertexCount, (vec_t *)vertexArray);
411
-        rRoom->mesh.bufferNormalArray(normalCount, (vec_t *)normalArray);
412
-        rRoom->mesh.bufferColorArray(vertexCount, (vec_t *)colorArray);
392
+        room.getMesh().bufferVertexArray(vertexCount, (vec_t *)vertexArray);
393
+        room.getMesh().bufferNormalArray(normalCount, (vec_t *)normalArray);
394
+        room.getMesh().bufferColorArray(vertexCount, (vec_t *)colorArray);
413
 
395
 
414
         mTombRaider.getRoomTriangles(index, mTextureStart,
396
         mTombRaider.getRoomTriangles(index, mTextureStart,
415
                 &triCount, &indices, &texCoords, &textures,
397
                 &triCount, &indices, &texCoords, &textures,
416
                 &flags);
398
                 &flags);
417
 
399
 
418
-        rRoom->mesh.bufferTriangles(triCount, indices, texCoords, textures, flags);
400
+        room.getMesh().bufferTriangles(triCount, indices, texCoords, textures, flags);
419
 #else
401
 #else
420
         float rgba[4];
402
         float rgba[4];
421
         float xyz[3];
403
         float xyz[3];
422
 
404
 
423
         count = mTombRaider.getRoomVertexCount(index);
405
         count = mTombRaider.getRoomVertexCount(index);
424
-        rRoom->mesh.allocateVertices(count);
425
-        rRoom->mesh.allocateNormals(0); // count
426
-        rRoom->mesh.allocateColors(count);
406
+        room.getMesh().allocateVertices(count);
407
+        room.getMesh().allocateNormals(0); // count
408
+        room.getMesh().allocateColors(count);
427
 
409
 
428
-        for (i = 0; i < count; ++i)
410
+        for (unsigned int i = 0; i < count; ++i)
429
         {
411
         {
430
             mTombRaider.getRoomVertex(index, i, xyz, rgba);
412
             mTombRaider.getRoomVertex(index, i, xyz, rgba);
431
 
413
 
432
-            rRoom->mesh.setVertex(i, xyz[0], xyz[1], xyz[2]);
433
-            rRoom->mesh.setColor(i, rgba);
414
+            room.getMesh().setVertex(i, xyz[0], xyz[1], xyz[2]);
415
+            room.getMesh().setColor(i, rgba);
434
         }
416
         }
435
 
417
 
436
         // Mongoose 2002.06.09, Setup allocation of meshes and polygons
418
         // Mongoose 2002.06.09, Setup allocation of meshes and polygons
443
         int tris_mesh_map[TextureLimit];
425
         int tris_mesh_map[TextureLimit];
444
         int rect_mesh_map[TextureLimit];
426
         int rect_mesh_map[TextureLimit];
445
 
427
 
446
-        for (i = 0; i < TextureLimit; ++i)
428
+        for (unsigned int i = 0; i < TextureLimit; ++i)
447
         {
429
         {
448
             triangle_counter[i]        = 0;
430
             triangle_counter[i]        = 0;
449
             triangle_counter_alpha[i]  = 0;
431
             triangle_counter_alpha[i]  = 0;
458
         unsigned int numQuads = 0;
440
         unsigned int numQuads = 0;
459
 
441
 
460
         int texture;
442
         int texture;
461
-        unsigned int r, t, q, v, flags;
443
+        unsigned int r, t, q, v;
462
         unsigned int indices[4];
444
         unsigned int indices[4];
463
         float texCoords[8];
445
         float texCoords[8];
464
 
446
 
530
         }
512
         }
531
 
513
 
532
         // Allocate indexed polygon meshes
514
         // Allocate indexed polygon meshes
533
-        rRoom->mesh.allocateTriangles(numTris);
534
-        rRoom->mesh.allocateRectangles(numQuads);
515
+        room.getMesh().allocateTriangles(numTris);
516
+        room.getMesh().allocateRectangles(numQuads);
535
 
517
 
536
-        for (i = 0, j = 0; i < TextureLimit; ++i)
518
+        for (unsigned int i = 0, j = 0; i < TextureLimit; ++i)
537
         {
519
         {
538
             if (tris_mesh_map[i] > 0)
520
             if (tris_mesh_map[i] > 0)
539
             {
521
             {
541
 
523
 
542
                 t = triangle_counter[i];
524
                 t = triangle_counter[i];
543
 
525
 
544
-                rRoom->mesh.mTris[j].texture = i;
526
+                room.getMesh().mTris[j].texture = i;
545
 #ifdef MULTITEXTURE
527
 #ifdef MULTITEXTURE
546
-                rRoom->mesh.mTris[j].bumpmap = gMapTex2Bump[i];
528
+                room.getMesh().mTris[j].bumpmap = gMapTex2Bump[i];
547
 #endif
529
 #endif
548
-                rRoom->mesh.mTris[j].cnum_triangles = 0;
549
-                rRoom->mesh.mTris[j].num_triangles = 0;
550
-                rRoom->mesh.mTris[j].cnum_alpha_triangles = 0;
551
-                rRoom->mesh.mTris[j].num_alpha_triangles = 0;
552
-                rRoom->mesh.mTris[j].triangles = 0x0;
553
-                rRoom->mesh.mTris[j].alpha_triangles = 0x0;
554
-                rRoom->mesh.mTris[j].texcoors = 0x0;
555
-                rRoom->mesh.mTris[j].texcoors2 = 0x0;
530
+                room.getMesh().mTris[j].cnum_triangles = 0;
531
+                room.getMesh().mTris[j].num_triangles = 0;
532
+                room.getMesh().mTris[j].cnum_alpha_triangles = 0;
533
+                room.getMesh().mTris[j].num_alpha_triangles = 0;
534
+                room.getMesh().mTris[j].triangles = 0x0;
535
+                room.getMesh().mTris[j].alpha_triangles = 0x0;
536
+                room.getMesh().mTris[j].texcoors = 0x0;
537
+                room.getMesh().mTris[j].texcoors2 = 0x0;
556
 
538
 
557
                 if (t > 0)
539
                 if (t > 0)
558
                 {
540
                 {
559
-                    rRoom->mesh.mTris[j].num_triangles = t;
560
-                    rRoom->mesh.mTris[j].triangles = new unsigned int[t*3];
561
-                    rRoom->mesh.mTris[j].num_texcoors = t * 3;
562
-                    rRoom->mesh.mTris[j].texcoors = new vec2_t[t * 3];
541
+                    room.getMesh().mTris[j].num_triangles = t;
542
+                    room.getMesh().mTris[j].triangles = new unsigned int[t*3];
543
+                    room.getMesh().mTris[j].num_texcoors = t * 3;
544
+                    room.getMesh().mTris[j].texcoors = new vec2_t[t * 3];
563
                 }
545
                 }
564
 
546
 
565
                 t = triangle_counter_alpha[i];
547
                 t = triangle_counter_alpha[i];
566
 
548
 
567
                 if (t > 0)
549
                 if (t > 0)
568
                 {
550
                 {
569
-                    rRoom->mesh.mTris[j].num_alpha_triangles = t;
570
-                    rRoom->mesh.mTris[j].alpha_triangles = new unsigned int[t*3];
571
-                    rRoom->mesh.mTris[j].num_texcoors2 = t * 3;
572
-                    rRoom->mesh.mTris[j].texcoors2 = new vec2_t[t * 3];
551
+                    room.getMesh().mTris[j].num_alpha_triangles = t;
552
+                    room.getMesh().mTris[j].alpha_triangles = new unsigned int[t*3];
553
+                    room.getMesh().mTris[j].num_texcoors2 = t * 3;
554
+                    room.getMesh().mTris[j].texcoors2 = new vec2_t[t * 3];
573
                 }
555
                 }
574
             }
556
             }
575
 
557
 
581
 
563
 
582
                 r = rectangle_counter[i];
564
                 r = rectangle_counter[i];
583
 
565
 
584
-                rRoom->mesh.mQuads[j].texture = i;
566
+                room.getMesh().mQuads[j].texture = i;
585
 #ifdef MULTITEXTURE
567
 #ifdef MULTITEXTURE
586
-                rRoom->mesh.mQuads[j].bumpmap = gMapTex2Bump[i];
568
+                room.getMesh().mQuads[j].bumpmap = gMapTex2Bump[i];
587
 #endif
569
 #endif
588
-                rRoom->mesh.mQuads[j].cnum_quads = 0;
589
-                rRoom->mesh.mQuads[j].num_quads = 0;
590
-                rRoom->mesh.mQuads[j].cnum_alpha_quads = 0;
591
-                rRoom->mesh.mQuads[j].num_alpha_quads = 0;
592
-                rRoom->mesh.mQuads[j].quads = 0x0;
593
-                rRoom->mesh.mQuads[j].alpha_quads = 0x0;
594
-                rRoom->mesh.mQuads[j].texcoors = 0x0;
595
-                rRoom->mesh.mQuads[j].texcoors2 = 0x0;
570
+                room.getMesh().mQuads[j].cnum_quads = 0;
571
+                room.getMesh().mQuads[j].num_quads = 0;
572
+                room.getMesh().mQuads[j].cnum_alpha_quads = 0;
573
+                room.getMesh().mQuads[j].num_alpha_quads = 0;
574
+                room.getMesh().mQuads[j].quads = 0x0;
575
+                room.getMesh().mQuads[j].alpha_quads = 0x0;
576
+                room.getMesh().mQuads[j].texcoors = 0x0;
577
+                room.getMesh().mQuads[j].texcoors2 = 0x0;
596
 
578
 
597
                 if (r > 0)
579
                 if (r > 0)
598
                 {
580
                 {
599
-                    rRoom->mesh.mQuads[j].num_quads = r;
600
-                    rRoom->mesh.mQuads[j].quads = new unsigned int[r*4];
601
-                    rRoom->mesh.mQuads[j].num_texcoors = r * 4;
602
-                    rRoom->mesh.mQuads[j].texcoors = new vec2_t[r * 4];
581
+                    room.getMesh().mQuads[j].num_quads = r;
582
+                    room.getMesh().mQuads[j].quads = new unsigned int[r*4];
583
+                    room.getMesh().mQuads[j].num_texcoors = r * 4;
584
+                    room.getMesh().mQuads[j].texcoors = new vec2_t[r * 4];
603
                 }
585
                 }
604
 
586
 
605
                 r = rectangle_counter_alpha[i];
587
                 r = rectangle_counter_alpha[i];
606
 
588
 
607
                 if (r > 0)
589
                 if (r > 0)
608
                 {
590
                 {
609
-                    rRoom->mesh.mQuads[j].num_alpha_quads = r;
610
-                    rRoom->mesh.mQuads[j].alpha_quads = new unsigned int[r*4];
611
-                    rRoom->mesh.mQuads[j].num_texcoors2 = r * 4;
612
-                    rRoom->mesh.mQuads[j].texcoors2 = new vec2_t[r * 4];
591
+                    room.getMesh().mQuads[j].num_alpha_quads = r;
592
+                    room.getMesh().mQuads[j].alpha_quads = new unsigned int[r*4];
593
+                    room.getMesh().mQuads[j].num_texcoors2 = r * 4;
594
+                    room.getMesh().mQuads[j].texcoors2 = new vec2_t[r * 4];
613
                 }
595
                 }
614
             }
596
             }
615
         }
597
         }
626
             // correct textures
608
             // correct textures
627
             texture += mTextureStart;
609
             texture += mTextureStart;
628
 
610
 
629
-            j = tris_mesh_map[texture] - 1;
611
+            unsigned int j = tris_mesh_map[texture] - 1;
630
 
612
 
631
             // Setup per vertex
613
             // Setup per vertex
632
-            for (i = 0; i < 3; ++i)
614
+            for (unsigned int i = 0; i < 3; ++i)
633
             {
615
             {
634
                 // Get vertex index {(0, a), (1, b), (2, c)}
616
                 // Get vertex index {(0, a), (1, b), (2, c)}
635
                 v = indices[i];
617
                 v = indices[i];
636
 
618
 
637
                 if ((flags & tombraiderFace_Alpha ||
619
                 if ((flags & tombraiderFace_Alpha ||
638
                             flags & tombraiderFace_PartialAlpha) &&
620
                             flags & tombraiderFace_PartialAlpha) &&
639
-                        rRoom->mesh.mTris[j].num_alpha_triangles > 0)
621
+                        room.getMesh().mTris[j].num_alpha_triangles > 0)
640
                 {
622
                 {
641
-                    q = rRoom->mesh.mTris[j].cnum_alpha_triangles*3+i;
623
+                    q = room.getMesh().mTris[j].cnum_alpha_triangles*3+i;
642
 
624
 
643
-                    rRoom->mesh.mTris[j].alpha_triangles[q] = v;
625
+                    room.getMesh().mTris[j].alpha_triangles[q] = v;
644
 
626
 
645
-                    rRoom->mesh.mTris[j].texcoors2[q][0] = texCoords[i*2];
646
-                    rRoom->mesh.mTris[j].texcoors2[q][1] = texCoords[i*2+1];
627
+                    room.getMesh().mTris[j].texcoors2[q][0] = texCoords[i*2];
628
+                    room.getMesh().mTris[j].texcoors2[q][1] = texCoords[i*2+1];
647
                 }
629
                 }
648
-                else if (rRoom->mesh.mTris[j].num_triangles > 0)
630
+                else if (room.getMesh().mTris[j].num_triangles > 0)
649
                 {
631
                 {
650
-                    q = rRoom->mesh.mTris[j].cnum_triangles*3+i;
632
+                    q = room.getMesh().mTris[j].cnum_triangles*3+i;
651
 
633
 
652
-                    rRoom->mesh.mTris[j].triangles[q] = v;
634
+                    room.getMesh().mTris[j].triangles[q] = v;
653
 
635
 
654
-                    rRoom->mesh.mTris[j].texcoors[q][0] = texCoords[i*2];
655
-                    rRoom->mesh.mTris[j].texcoors[q][1] = texCoords[i*2+1];
636
+                    room.getMesh().mTris[j].texcoors[q][0] = texCoords[i*2];
637
+                    room.getMesh().mTris[j].texcoors[q][1] = texCoords[i*2+1];
656
                 }
638
                 }
657
 
639
 
658
                 // Partial alpha hack
640
                 // Partial alpha hack
659
                 if (flags & tombraiderFace_PartialAlpha)
641
                 if (flags & tombraiderFace_PartialAlpha)
660
                 {
642
                 {
661
-                    //rRoom->mesh.colors[v].rgba[3] = 0.45;
643
+                    //room.getMesh().colors[v].rgba[3] = 0.45;
662
                 }
644
                 }
663
             }
645
             }
664
 
646
 
665
             if (flags & tombraiderFace_Alpha ||
647
             if (flags & tombraiderFace_Alpha ||
666
                     flags & tombraiderFace_PartialAlpha)
648
                     flags & tombraiderFace_PartialAlpha)
667
             {
649
             {
668
-                rRoom->mesh.mTris[j].cnum_alpha_triangles++;
650
+                room.getMesh().mTris[j].cnum_alpha_triangles++;
669
             }
651
             }
670
             else
652
             else
671
             {
653
             {
672
-                rRoom->mesh.mTris[j].cnum_triangles++;
654
+                room.getMesh().mTris[j].cnum_triangles++;
673
             }
655
             }
674
         }
656
         }
675
 
657
 
690
                 texture = TextureLimit - 1;
672
                 texture = TextureLimit - 1;
691
             }
673
             }
692
 
674
 
693
-            j = rect_mesh_map[texture] - 1;
675
+            unsigned int j = rect_mesh_map[texture] - 1;
694
 
676
 
695
-            if (rRoom->mesh.mQuads[j].num_quads <= 0 &&
696
-                    rRoom->mesh.mQuads[j].num_alpha_quads <= 0)
677
+            if (room.getMesh().mQuads[j].num_quads <= 0 &&
678
+                    room.getMesh().mQuads[j].num_alpha_quads <= 0)
697
                 continue;
679
                 continue;
698
 
680
 
699
             // Setup per vertex
681
             // Setup per vertex
700
-            for (i = 0; i < 4; ++i)
682
+            for (unsigned int i = 0; i < 4; ++i)
701
             {
683
             {
702
                 // Get vertex index {(0, a), (1, b), (2, c), (3, d)}
684
                 // Get vertex index {(0, a), (1, b), (2, c), (3, d)}
703
                 v = indices[i];
685
                 v = indices[i];
704
 
686
 
705
                 if ((flags & tombraiderFace_Alpha ||
687
                 if ((flags & tombraiderFace_Alpha ||
706
                             flags & tombraiderFace_PartialAlpha) &&
688
                             flags & tombraiderFace_PartialAlpha) &&
707
-                        rRoom->mesh.mQuads[j].num_alpha_quads > 0)
689
+                        room.getMesh().mQuads[j].num_alpha_quads > 0)
708
                 {
690
                 {
709
-                    q = rRoom->mesh.mQuads[j].cnum_alpha_quads*4+i;
691
+                    q = room.getMesh().mQuads[j].cnum_alpha_quads*4+i;
710
 
692
 
711
-                    rRoom->mesh.mQuads[j].alpha_quads[q] = v;
693
+                    room.getMesh().mQuads[j].alpha_quads[q] = v;
712
 
694
 
713
-                    rRoom->mesh.mQuads[j].texcoors2[q][0] = texCoords[i*2];
714
-                    rRoom->mesh.mQuads[j].texcoors2[q][1] = texCoords[i*2+1];
695
+                    room.getMesh().mQuads[j].texcoors2[q][0] = texCoords[i*2];
696
+                    room.getMesh().mQuads[j].texcoors2[q][1] = texCoords[i*2+1];
715
                 }
697
                 }
716
-                else if (rRoom->mesh.mQuads[j].num_quads > 0)
698
+                else if (room.getMesh().mQuads[j].num_quads > 0)
717
                 {
699
                 {
718
-                    q = rRoom->mesh.mQuads[j].cnum_quads*4+i;
700
+                    q = room.getMesh().mQuads[j].cnum_quads*4+i;
719
 
701
 
720
-                    rRoom->mesh.mQuads[j].quads[q] = v;
702
+                    room.getMesh().mQuads[j].quads[q] = v;
721
 
703
 
722
-                    rRoom->mesh.mQuads[j].texcoors[q][0] = texCoords[i*2];
723
-                    rRoom->mesh.mQuads[j].texcoors[q][1] = texCoords[i*2+1];
704
+                    room.getMesh().mQuads[j].texcoors[q][0] = texCoords[i*2];
705
+                    room.getMesh().mQuads[j].texcoors[q][1] = texCoords[i*2+1];
724
                 }
706
                 }
725
 
707
 
726
                 // Partial alpha hack
708
                 // Partial alpha hack
733
             if (flags & tombraiderFace_Alpha ||
715
             if (flags & tombraiderFace_Alpha ||
734
                     flags & tombraiderFace_PartialAlpha)
716
                     flags & tombraiderFace_PartialAlpha)
735
             {
717
             {
736
-                rRoom->mesh.mQuads[j].cnum_alpha_quads++;
718
+                room.getMesh().mQuads[j].cnum_alpha_quads++;
737
             }
719
             }
738
             else
720
             else
739
             {
721
             {
740
-                rRoom->mesh.mQuads[j].cnum_quads++;
722
+                room.getMesh().mQuads[j].cnum_quads++;
741
             }
723
             }
742
         }
724
         }
743
 #endif
725
 #endif
744
 
726
 
745
         // Room models
727
         // Room models
746
         count = mTombRaider.getRoomModelCount(index);
728
         count = mTombRaider.getRoomModelCount(index);
747
-        r_mesh->models.reserve(count);
748
-
749
-        for (i = 0; i < count; ++i)
750
-        {
751
-            static_model_t *model = new static_model_t;
752
-
753
-            mTombRaider.getRoomModel(index, i,
754
-                    &model->index, model->pos, &model->yaw);
755
-
756
-            r_mesh->models.push_back(model);
729
+        for (unsigned int i = 0; i < count; i++) {
730
+            int ind;
731
+            vec_t yaw;
732
+            vec3_t position;
733
+            mTombRaider.getRoomModel(index, i, &ind, position, &yaw);
734
+            room.addModel(*new StaticModel(ind, yaw, position));
757
         }
735
         }
758
 
736
 
759
         // Room sprites
737
         // Room sprites
760
-        float spriteVertices[12];
761
-        float spriteTexCoords[8];
762
         count = mTombRaider.getRoomSpriteCount(index);
738
         count = mTombRaider.getRoomSpriteCount(index);
763
-        r_mesh->sprites.reserve(count);
764
-
765
-        for (i = 0; i < count; ++i)
766
-        {
767
-            sprite_t *sprite = new sprite_t;
739
+        for (unsigned int i = 0; i < count; i++) {
740
+            float spriteVertices[12];
741
+            float spriteTexCoords[8];
742
+            vec3_t vertex[4];
743
+            vec2_t texel[4];
744
+            vec3_t position;
745
+            int tex;
768
 
746
 
769
             mTombRaider.getRoomSprite(index, i,
747
             mTombRaider.getRoomSprite(index, i,
770
-                    10.0f, &sprite->texture, sprite->pos,
771
-                    spriteVertices, spriteTexCoords);
748
+                    10.0f, &tex, position, spriteVertices, spriteTexCoords);
772
 
749
 
773
-            sprite->texture += mTextureStart; // OpenRaider preloads some textures
750
+            tex += mTextureStart; // OpenRaider preloads some textures
774
 
751
 
775
-            for (j = 0; j < 12; j++)
776
-                sprite->vertex[j / 3].pos[j % 3] = spriteVertices[j];
752
+            for (unsigned int j = 0; j < 12; j++)
753
+                vertex[j / 3][j % 3] = spriteVertices[j];
777
 
754
 
778
-            for (j = 0; j < 8; j++)
779
-                sprite->texel[j / 2].st[j % 2] = spriteTexCoords[j];
755
+            for (unsigned int j = 0; j < 8; j++)
756
+                texel[j / 2][j % 2] = spriteTexCoords[j];
780
 
757
 
781
-            r_mesh->sprites.push_back(sprite);
758
+            room.addSprite(*new Sprite(vertex, texel, position, 0.0f, tex)); //! \fixme radius 0??
782
         }
759
         }
783
 
760
 
784
-        getWorld().addRoom(r_mesh);
785
-
786
-        rRoom->room = r_mesh;
787
-        getRender().addRoom(rRoom);
761
+        getWorld().addRoom(room);
788
 
762
 
789
         //printf(".");
763
         //printf(".");
790
         //fflush(stdout);
764
         //fflush(stdout);

+ 4
- 0
src/Room.cpp Wyświetl plik

67
 
67
 
68
     for (i = 0; i < sectors.size(); i++)
68
     for (i = 0; i < sectors.size(); i++)
69
         delete sectors[i];
69
         delete sectors[i];
70
+
71
+    for (i = 0; i < lights.size(); i++) {
72
+        delete lights[i];
73
+    }
70
 }
74
 }
71
 
75
 

Ładowanie…
Anuluj
Zapisz