Pārlūkot izejas kodu

Slimmed down Render

Thomas Buck 10 gadus atpakaļ
vecāks
revīzija
6afb071742
4 mainītis faili ar 38 papildinājumiem un 198 dzēšanām
  1. 2
    0
      ChangeLog.md
  2. 6
    11
      include/Render.h
  3. 0
    68
      src/Command.cpp
  4. 30
    119
      src/Render.cpp

+ 2
- 0
ChangeLog.md Parādīt failu

@@ -10,6 +10,8 @@
10 10
     * Re-Implemented the move command
11 11
     * Prevent crash (segfault) when resizing window while console is
12 12
       not fully scrolled to the bottom
13
+    * Removed Render flags fUsePortals, fAllRooms, fOneRoom,
14
+      fViewModel and fUpdateRoomListPerFrame
13 15
 
14 16
     [ 20140624 ]
15 17
     * Some changes to allow compilation with Ubuntu 14.04 / gcc

+ 6
- 11
include/Render.h Parādīt failu

@@ -31,17 +31,12 @@ public:
31 31
 
32 32
     typedef enum {
33 33
         fRoomAlpha              = (1 << 0),
34
-        fViewModel              = (1 << 1),
35
-        fEntityModels           = (1 << 2),
36
-        fFog                    = (1 << 3),
37
-        fUsePortals             = (1 << 4),
38
-        fGL_Lights              = (1 << 5),
39
-        fOneRoom                = (1 << 6),
40
-        fRenderPonytail         = (1 << 7),
41
-        // fMultiTexture           = (1 << 8), //! \todo Whats up with Multitexture stuff? Where is it needed?
42
-        fUpdateRoomListPerFrame = (1 << 9),
43
-        fAnimateAllModels       = (1 << 10),
44
-        fAllRooms               = (1 << 11)
34
+        fEntityModels           = (1 << 1),
35
+        fFog                    = (1 << 2),
36
+        fGL_Lights              = (1 << 3),
37
+        fRenderPonytail         = (1 << 4),
38
+        fAnimateAllModels       = (1 << 5),
39
+        // fMultiTexture           = (1 << 6), //! \todo Whats up with Multitexture stuff? Where is it needed?
45 40
     } RenderFlags;
46 41
 
47 42
     /*!

+ 0
- 68
src/Command.cpp Parādīt failu

@@ -109,13 +109,9 @@ int OpenRaider::command(std::string &c) {
109 109
             getConsole().print("  fog       - BOOL - GL Fog");
110 110
             getConsole().print("  viewmodel - INT - Change Laras model");
111 111
             getConsole().print("  pos       - Print position info");
112
-            getConsole().print("  vmodel    - BOOL - View Model");
113 112
             getConsole().print("  ralpha    - BOOL - Room Alpha");
114
-            getConsole().print("  vis       - BOOL - Use Portals");
115 113
             getConsole().print("  upf       - BOOL - Update Room List Per Frame");
116 114
             getConsole().print("  entmodel  - BOOL");
117
-            getConsole().print("  oneroom   - BOOL");
118
-            getConsole().print("  allrooms  - BOOL");
119 115
             getConsole().print("  ponytail  - BOOL");
120 116
             getConsole().print("  pigtail   - BOOL");
121 117
             getConsole().print("  ponypos   - FLOAT FLOAT FLOAT FLOAT - x y z angle");
@@ -252,22 +248,6 @@ int OpenRaider::command(std::string &c) {
252 248
             getConsole().print("Invalid use of fog-command!");
253 249
             return -18;
254 250
         }
255
-    } else if (cmd.compare("vmodel") == 0) {
256
-        if (args->size() > 0) {
257
-            bool b;
258
-            if (readBool(args->at(0), &b) < 0) {
259
-                getConsole().print("Pass BOOL to vmodel command!");
260
-                return -22;
261
-            }
262
-            if (b)
263
-                getRender().setFlags(Render::fViewModel);
264
-            else
265
-                getRender().clearFlags(Render::fViewModel);
266
-            getConsole().print("Viewmodel is now %s", b ? "on" : "off");
267
-        } else {
268
-            getConsole().print("Invalid use of vmodel-command!");
269
-            return -23;
270
-        }
271 251
     } else if (cmd.compare("ralpha") == 0) {
272 252
         if (args->size() > 0) {
273 253
             bool b;
@@ -284,22 +264,6 @@ int OpenRaider::command(std::string &c) {
284 264
             getConsole().print("Invalid use of ralpha-command!");
285 265
             return -25;
286 266
         }
287
-    } else if (cmd.compare("vis") == 0) {
288
-        if (args->size() > 0) {
289
-            bool b;
290
-            if (readBool(args->at(0), &b) < 0) {
291
-                getConsole().print("Pass BOOL to vis command!");
292
-                return -28;
293
-            }
294
-            if (b)
295
-                getRender().setFlags(Render::fUsePortals);
296
-            else
297
-                getRender().clearFlags(Render::fUsePortals);
298
-            getConsole().print("Portals are now %s", b ? "on" : "off");
299
-        } else {
300
-            getConsole().print("Invalid use of vis-command!");
301
-            return -29;
302
-        }
303 267
     } else if (cmd.compare("upf") == 0) {
304 268
         if (args->size() > 0) {
305 269
             bool b;
@@ -332,38 +296,6 @@ int OpenRaider::command(std::string &c) {
332 296
             getConsole().print("Invalid use of entmodel-command!");
333 297
             return -39;
334 298
         }
335
-    } else if (cmd.compare("oneroom") == 0) {
336
-        if (args->size() > 0) {
337
-            bool b;
338
-            if (readBool(args->at(0), &b) < 0) {
339
-                getConsole().print("Pass BOOL to oneroom command!");
340
-                return -40;
341
-            }
342
-            if (b)
343
-                getRender().setFlags(Render::fOneRoom);
344
-            else
345
-                getRender().clearFlags(Render::fOneRoom);
346
-            getConsole().print("Rendering one room is now %s", b ? "on" : "off");
347
-        } else {
348
-            getConsole().print("Invalid use of oneroom-command!");
349
-            return -41;
350
-        }
351
-    } else if (cmd.compare("allrooms") == 0) {
352
-        if (args->size() > 0) {
353
-            bool b;
354
-            if (readBool(args->at(0), &b) < 0) {
355
-                getConsole().print("Pass BOOL to allrooms command!");
356
-                return -42;
357
-            }
358
-            if (b)
359
-                getRender().setFlags(Render::fAllRooms);
360
-            else
361
-                getRender().clearFlags(Render::fAllRooms);
362
-            getConsole().print("Rendering all rooms is now %s", b ? "on" : "off");
363
-        } else {
364
-            getConsole().print("Invalid use of allrooms-command!");
365
-            return -43;
366
-        }
367 299
     } else if (cmd.compare("ponytail") == 0) {
368 300
         if (args->size() > 0) {
369 301
             bool b;

+ 30
- 119
src/Render.cpp Parādīt failu

@@ -26,9 +26,7 @@ Render::Render() {
26 26
     mSkyMeshRotation = false;
27 27
     mMode = Render::modeDisabled;
28 28
     mLock = 0;
29
-    mFlags = (fRoomAlpha | fViewModel |
30
-            fEntityModels | fRenderPonytail |
31
-            fUsePortals | fUpdateRoomListPerFrame);
29
+    mFlags = (fRoomAlpha | fEntityModels | fRenderPonytail);
32 30
 }
33 31
 
34 32
 
@@ -78,48 +76,6 @@ unsigned int Render::getFlags() {
78 76
 }
79 77
 
80 78
 
81
-// Texture must be set to WHITE solid color texture
82
-void renderTrace(int color, vec3_t start, vec3_t end)
83
-{
84
-    const float widthStart = 10.0f; //5.0f;
85
-    const float widthEnd = 10.0f;
86
-    float delta = randomNum(0.01f, 0.16f); // for flicker fx
87
-
88
-
89
-    // Draw two long quads that skrink and fade the they go further out
90
-    glBegin(GL_QUADS);
91
-
92
-    switch (color)
93
-    {
94
-        case 0:
95
-            glColor3f(0.9f - delta, 0.2f, 0.2f);
96
-            break;
97
-        case 1:
98
-            glColor3f(0.2f, 0.9f - delta, 0.2f);
99
-            break;
100
-        case 2:
101
-        default:
102
-            glColor3f(0.2f, 0.2f, 0.9f - delta);
103
-    }
104
-
105
-    glVertex3f(start[0], start[1], start[2]);
106
-    glVertex3f(start[0], start[1] + widthStart, start[2] + widthStart);
107
-    glVertex3f(end[0], end[1] + widthEnd, end[2] + widthEnd);
108
-    glVertex3f(end[0], end[1], end[2]);
109
-
110
-    glVertex3f(start[0],  start[1], start[2]);
111
-    glVertex3f(start[0],  start[1] + widthStart, start[2] - widthStart);
112
-    glVertex3f(end[0], end[1] + widthEnd, end[2] - widthEnd);
113
-    glVertex3f(end[0], end[1], end[2]);
114
-
115
-    glVertex3f(start[0],  start[1] + widthStart, start[2] + widthStart);
116
-    glVertex3f(start[0],  start[1] + widthStart, start[2] - widthStart);
117
-    glVertex3f(end[0], end[1] + widthEnd, end[2] - widthEnd);
118
-    glVertex3f(end[0], end[1] + widthEnd, end[2] + widthEnd);
119
-    glEnd();
120
-}
121
-
122
-
123 79
 void setLighting(bool on)
124 80
 {
125 81
     if (on)
@@ -270,33 +226,31 @@ void Render::setMode(int n)
270 226
 // Replaced the deprecated gluLookAt with slightly modified code from here:
271 227
 // http://www.khronos.org/message_boards/showthread.php/4991
272 228
 void gluLookAt(float eyeX, float eyeY, float eyeZ,
273
-                            float lookAtX, float lookAtY, float lookAtZ,
274
-                            float upX, float upY, float upZ) {
275
-    float f[3];
276
-
229
+        float lookAtX, float lookAtY, float lookAtZ,
230
+        float upX, float upY, float upZ) {
277 231
     // calculating the viewing vector
278
-    f[0] = lookAtX - eyeX;
279
-    f[1] = lookAtY - eyeY;
280
-    f[2] = lookAtZ - eyeZ;
281
-
282
-    float fMag = sqrtf(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]);
283
-    //float upMag = sqrtf(upX * upX + upY * upY + upZ * upZ);
232
+    float f[3] = {
233
+        lookAtX - eyeX,
234
+        lookAtY - eyeY,
235
+        lookAtZ - eyeZ
236
+    };
284 237
 
285 238
     // normalizing the viewing vector
286
-    f[0] = f[0] / fMag;
287
-    f[1] = f[1] / fMag;
288
-    f[2] = f[2] / fMag;
239
+    float fMag = sqrtf(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]);
240
+    f[0] /= fMag;
241
+    f[1] /= fMag;
242
+    f[2] /= fMag;
289 243
 
290 244
     float s[3] = {
291
-        f[1] * upZ - upY * f[2],
292
-        upX * f[2] - f[0] * upZ,
293
-        f[0] * upY - upX * f[1]
245
+        (f[1] * upZ) - (upY * f[2]),
246
+        (upX * f[2]) - (f[0] * upZ),
247
+        (f[0] * upY) - (upX * f[1])
294 248
     };
295 249
 
296 250
     float u[3] = {
297
-        s[1] * f[2] - f[1] * s[2],
298
-        f[0] * s[2] - s[0] * f[2],
299
-        s[0] * f[1] - f[0] * s[1]
251
+        (s[1] * f[2]) - (f[1] * s[2]),
252
+        (f[0] * s[2]) - (s[0] * f[2]),
253
+        (s[0] * f[1]) - (f[0] * s[1])
300 254
     };
301 255
 
302 256
     float m[16] = {
@@ -433,8 +387,7 @@ void Render::display()
433 387
         glPushMatrix();
434 388
 
435 389
         // Draw lara or other player model ( move to entity rendering method )
436
-        if (mFlags & Render::fViewModel)
437
-            getGame().getLara().display();
390
+        getGame().getLara().display();
438 391
 
439 392
         // Draw sprites after player to handle alpha
440 393
         for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
@@ -445,9 +398,8 @@ void Render::display()
445 398
 
446 399
         glPopMatrix();
447 400
 
448
-        // Depth sort entityRenderList with qsort
401
+        // Depth sort entityRenderList and display each entity
449 402
         std::sort(entityRenderList.begin(), entityRenderList.end());
450
-
451 403
         for (unsigned int i = 0; i < entityRenderList.size(); i++) {
452 404
             entityRenderList[i]->display();
453 405
         }
@@ -514,37 +466,17 @@ void Render::newRoomRenderList(int index)
514 466
 {
515 467
     static int currentRoomId = -1;
516 468
 
517
-    if (mFlags & Render::fUsePortals)
469
+    if (index == -1) // -1 is error, so draw room 0, for the hell of it
518 470
     {
519
-        if (index == -1) // -1 is error, so draw room 0, for the hell of it
520
-        {
521
-            mRoomRenderList.clear();
522
-            mRoomRenderList.push_back(&getWorld().getRoom(0));
523
-        }
524
-        else
525
-        {
526
-            // Update room render list if needed
527
-            if (mFlags & Render::fUpdateRoomListPerFrame ||
528
-                    currentRoomId != index)
529
-            {
530
-                buildRoomRenderList(getWorld().getRoom(index));
531
-            }
532
-        }
471
+        mRoomRenderList.clear();
472
+        mRoomRenderList.push_back(&getWorld().getRoom(0));
533 473
     }
534
-    else // Render all rooms pretty much
474
+    else
535 475
     {
536
-        if (currentRoomId != index || index == -1)
476
+        // Update room render list if needed
477
+        if (currentRoomId != index)
537 478
         {
538
-            printf("*** Room render list -> %i\n", index);
539
-            mRoomRenderList.clear();
540
-
541
-            for (unsigned int i = 0; i < getWorld().sizeRoom(); i++)
542
-            {
543
-                if (!isVisible(getWorld().getRoom(i).getBoundingBox()))
544
-                    continue;
545
-
546
-                mRoomRenderList.push_back(&getWorld().getRoom(i));
547
-            }
479
+            buildRoomRenderList(getWorld().getRoom(index));
548 480
         }
549 481
     }
550 482
 
@@ -563,34 +495,15 @@ void Render::buildRoomRenderList(Room &room)
563 495
     // Must not already be cached
564 496
     for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
565 497
     {
566
-        Room &room2 = *mRoomRenderList[i];
498
+        Room *room2 = mRoomRenderList[i];
567 499
 
568
-        if (&room2 == &room)
500
+        if (room2 == &room)
569 501
             return;
570 502
     }
571 503
 
572 504
     /* Add current room to list */
573 505
     mRoomRenderList.push_back(&room);
574 506
 
575
-    if (mFlags & Render::fOneRoom)
576
-    {
577
-        return;
578
-    }
579
-    else if (mFlags & Render::fAllRooms) /* Are you serious? */
580
-    {
581
-        for (unsigned int i = 0; i < getWorld().sizeRoom(); i++)
582
-        {
583
-            Room &room2 = getWorld().getRoom(i);
584
-
585
-            if (&room2 != &room)
586
-            {
587
-                buildRoomRenderList(room2);
588
-            }
589
-        }
590
-
591
-        return;
592
-    }
593
-
594 507
     // Try to add adj rooms and their adj rooms, skip this room
595 508
     for (unsigned int i = 1; i < room.sizeAdjacentRooms(); i++)
596 509
     {
@@ -599,12 +512,10 @@ void Render::buildRoomRenderList(Room &room)
599 512
 
600 513
         Room &room2 = getWorld().getRoom(room.getAdjacentRoom(i));
601 514
 
602
-        // Mongoose 2002.03.22, Add portal visibility check here
515
+        //! \fixme Add portal visibility check here
603 516
 
604 517
         if (&room2 != &room)
605
-        {
606 518
             buildRoomRenderList(room2);
607
-        }
608 519
     }
609 520
 }
610 521
 

Notiek ielāde…
Atcelt
Saglabāt