Thomas Buck 10 лет назад
Родитель
Сommit
1de393f974
13 измененных файлов: 62 добавлений и 79 удалений
  1. 1
    0
      TODO.md
  2. 0
    2
      include/Console.h
  3. 0
    4
      include/Menu.h
  4. 1
    1
      include/Window.h
  5. 1
    1
      include/WindowSDL.h
  6. 3
    8
      src/Menu.cpp
  7. 1
    1
      src/OpenRaider.cpp
  8. 4
    5
      src/Render.cpp
  9. 2
    0
      src/Sprite.cpp
  10. 23
    39
      src/Texture.cpp
  11. 1
    2
      src/ViewVolume.cpp
  12. 15
    15
      src/WindowSDL.cpp
  13. 10
    1
      src/utils/pcx.cpp

+ 1
- 0
TODO.md Просмотреть файл

@@ -12,6 +12,7 @@ There are these DebugModel, DebugMap flags...?
12 12
         * Don't even new ... the data structures but use std::make_shared or allocate_shared?
13 13
         * Pass object references to all other objects that need it, completely remove gOpenRaider
14 14
     * Use streams for (file) I/O
15
+        * Does not need strtok() anymore
15 16
     * Use std::strings
16 17
 
17 18
 ## Changes

+ 0
- 2
include/Console.h Просмотреть файл

@@ -11,8 +11,6 @@
11 11
 #include <cstring>
12 12
 #include <vector>
13 13
 
14
-#include "Window.h"
15
-
16 14
 /*!
17 15
  * \brief Console 'overlay'
18 16
  */

+ 0
- 4
include/Menu.h Просмотреть файл

@@ -38,10 +38,6 @@ public:
38 38
 
39 39
 private:
40 40
 
41
-#ifdef WIN32
42
-    void loadPakFolderHelper(std::vector<char *> &list);
43
-#endif
44
-
45 41
     void loadPakFolderRecursive(const char *dir);
46 42
 
47 43
     void fillMapList();

+ 1
- 1
include/Window.h Просмотреть файл

@@ -61,7 +61,7 @@ public:
61 61
 
62 62
     virtual int initializeFont() = 0;
63 63
 
64
-    virtual void writeString(WindowString *s) = 0;
64
+    virtual void writeString(WindowString &s) = 0;
65 65
 
66 66
     virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
67 67
         __attribute__((format(printf, 6, 0))) = 0;

+ 1
- 1
include/WindowSDL.h Просмотреть файл

@@ -51,7 +51,7 @@ public:
51 51
 
52 52
     virtual int initializeFont();
53 53
 
54
-    virtual void writeString(WindowString *s);
54
+    virtual void writeString(WindowString &s);
55 55
 
56 56
     virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
57 57
         __attribute__((format(printf, 6, 0)));

+ 3
- 8
src/Menu.cpp Просмотреть файл

@@ -59,12 +59,6 @@ bool Menu::isVisible() {
59 59
     return mVisible;
60 60
 }
61 61
 
62
-#ifdef WIN32
63
-void Menu::loadPakFolderHelper(std::vector<char *> &list) {
64
-
65
-}
66
-#endif
67
-
68 62
 void Menu::loadPakFolderRecursive(const char *dir) {
69 63
     assert(dir != NULL);
70 64
     assert(dir[0] != '\0');
@@ -210,9 +204,10 @@ void Menu::display() {
210 204
         glRecti(0, 0, getWindow().mWidth, getWindow().mHeight);
211 205
         glEnable(GL_TEXTURE_2D);
212 206
 
213
-        // Draw heading text
207
+        // Draw heading text, using WindowString so we can get the
208
+        // width of the drawn text to center it
214 209
         mainText.x = (getWindow().mWidth / 2) - (mainText.w / 2);
215
-        getWindow().writeString(&mainText);
210
+        getWindow().writeString(mainText);
216 211
 
217 212
         if (!mMapListFilled) {
218 213
             getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");

+ 1
- 1
src/OpenRaider.cpp Просмотреть файл

@@ -205,7 +205,7 @@ int OpenRaider::set(const char *var, const char *value) {
205 205
     if (strcmp(var, "size") == 0) {
206 206
         // value has format like "\"1024x768\""
207 207
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
208
-        if (sscanf(value, "\"%5dx%5d\"", &w, &h) != 2) {
208
+        if (sscanf(value, "\"%5ux%5u\"", &w, &h) != 2) {
209 209
             getConsole().print("set-size-Error: Invalid value (%s)", value);
210 210
             return -2;
211 211
         }

+ 4
- 5
src/Render.cpp Просмотреть файл

@@ -37,7 +37,6 @@ Render::~Render() {
37 37
 
38 38
 void Render::screenShot(char *filenameBase)
39 39
 {
40
-    FILE *f;
41 40
     int sz = getWindow().mWidth * getWindow().mHeight;
42 41
     unsigned char *image = new unsigned char[sz * 3];
43 42
     char *filename = NULL;
@@ -50,7 +49,7 @@ void Render::screenShot(char *filenameBase)
50 49
     while (!done) {
51 50
         filename = bufferString("%s-%04i.tga", filenameBase, count++);
52 51
 
53
-        f = fopen(filename, "rb");
52
+        FILE *f = fopen(filename, "rb");
54 53
 
55 54
         if (f)
56 55
             fclose(f);
@@ -307,9 +306,9 @@ void gluLookAt(float eyeX, float eyeY, float eyeZ,
307 306
     f[0] = lookAtX - eyeX;
308 307
     f[1] = lookAtY - eyeY;
309 308
     f[2] = lookAtZ - eyeZ;
310
-    float fMag, upMag;
311
-    fMag = sqrtf(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]);
312
-    upMag = sqrtf(upX * upX + upY * upY + upZ * upZ);
309
+
310
+    float fMag = sqrtf(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]);
311
+    //float upMag = sqrtf(upX * upX + upY * upY + upZ * upZ);
313 312
 
314 313
     // normalizing the viewing vector
315 314
     f[0] = f[0] / fMag;

+ 2
- 0
src/Sprite.cpp Просмотреть файл

@@ -96,6 +96,8 @@ Sprite::Sprite(TombRaider &tr, unsigned int room, unsigned int index) {
96 96
 
97 97
     for (unsigned int j = 0; j < 8; j++)
98 98
         texel[j / 2][j % 2] = spriteTexCoords[j];
99
+
100
+    radius = 0.0f;
99 101
 }
100 102
 
101 103
 void Sprite::display() {

+ 23
- 39
src/Texture.cpp Просмотреть файл

@@ -167,7 +167,6 @@ int Texture::loadBuffer(unsigned char *image,
167 167
 void convertARGB32bppToRGBA32bpp(unsigned char *image,
168 168
         unsigned int w, unsigned int h) {
169 169
     unsigned int i, size = w * h;
170
-    unsigned char swap;
171 170
 
172 171
     assert(image != NULL);
173 172
     assert(w > 0);
@@ -175,7 +174,7 @@ void convertARGB32bppToRGBA32bpp(unsigned char *image,
175 174
 
176 175
     for (i = 0; i < size; ++i) {
177 176
         /* 32-bit ARGB to RGBA */
178
-        swap = image[(i * 4) + 3];
177
+        unsigned char swap = image[(i * 4) + 3];
179 178
         image[(i * 4)] = image[(i * 4) + 1];
180 179
         image[(i * 4) + 1] = image[(i * 4) + 2];
181 180
         image[(i * 4) + 2] = image[(i * 4) + 3];
@@ -397,82 +396,67 @@ unsigned char *Texture::scaleBuffer(unsigned char *image,
397 396
 
398 397
     if (sx < 1.0 && sy < 1.0) {
399 398
         /* Magnify both width and height:  use weighted sample of 4 pixels */
400
-        int i0, i1, j0, j1;
401
-        float alpha, beta;
402
-        float* src00;
403
-        float* src01;
404
-        float* src10;
405
-        float* src11;
406
-        float s1, s2;
407
-        float* dst;
408
-
409 399
         for (i = 0; i < height; ++i) {
410
-            i0 = (int)(i * sy);
411
-            i1 = i0 + 1;
400
+            int i0 = (int)(i * sy);
401
+            int i1 = i0 + 1;
412 402
 
413 403
             if (i1 >= original_height) {
414 404
                 i1 = original_height - 1;
415 405
             }
416 406
 
417
-            alpha = i * sy - i0;
407
+            float alpha = i * sy - i0;
418 408
 
419 409
             for (j = 0; j < width; ++j) {
420
-                j0 = (int) (j * sx);
421
-                j1 = j0 + 1;
410
+                int j0 = (int) (j * sx);
411
+                int j1 = j0 + 1;
422 412
 
423 413
                 if (j1 >= original_width) {
424 414
                     j1 = original_width - 1;
425 415
                 }
426 416
 
427
-                beta = j * sx - j0;
417
+                float beta = j * sx - j0;
428 418
 
429 419
                 /* Compute weighted average of pixels in rect (i0,j0)-(i1,j1) */
430
-                src00 = tempin + (i0 * original_width + j0) * components;
431
-                src01 = tempin + (i0 * original_width + j1) * components;
432
-                src10 = tempin + (i1 * original_width + j0) * components;
433
-                src11 = tempin + (i1 * original_width + j1) * components;
420
+                float *src00 = tempin + (i0 * original_width + j0) * components;
421
+                float *src01 = tempin + (i0 * original_width + j1) * components;
422
+                float *src10 = tempin + (i1 * original_width + j0) * components;
423
+                float *src11 = tempin + (i1 * original_width + j1) * components;
434 424
 
435
-                dst = tempout + (i * width + j) * components;
425
+                float *dst = tempout + (i * width + j) * components;
436 426
 
437 427
                 for (k = 0; k < components; ++k) {
438
-                    s1 = *src00++ * (1.0f - beta) + *src01++ * beta;
439
-                    s2 = *src10++ * (1.0f - beta) + *src11++ * beta;
428
+                    float s1 = *src00++ * (1.0f - beta) + *src01++ * beta;
429
+                    float s2 = *src10++ * (1.0f - beta) + *src11++ * beta;
440 430
                     *dst++ = s1 * (1.0f - alpha) + s2 * alpha;
441 431
                 }
442 432
             }
443 433
         }
444 434
     } else {
445 435
         /* Shrink width and/or height:  use an unweighted box filter */
446
-        int i0, i1;
447
-        int j0, j1;
448
-        int ii, jj;
449
-        float sum;
450
-        float* dst;
451
-
452 436
         for (i = 0; i < height; ++i) {
453
-            i0 = (int) (i * sy);
454
-            i1 = i0 + 1;
437
+            int i0 = (int) (i * sy);
438
+            int i1 = i0 + 1;
455 439
 
456 440
             if (i1 >= original_height) {
457 441
                 i1 = original_height - 1;
458 442
             }
459 443
 
460 444
             for (j = 0; j < width; ++j) {
461
-                j0 = (int) (j * sx);
462
-                j1 = j0 + 1;
445
+                int j0 = (int) (j * sx);
446
+                int j1 = j0 + 1;
463 447
 
464 448
                 if (j1 >= original_width) {
465 449
                     j1 = original_width - 1;
466 450
                 }
467 451
 
468
-                dst = tempout + (i * width + j) * components;
452
+                float *dst = tempout + (i * width + j) * components;
469 453
 
470 454
                 /* Compute average of pixels in the rectangle (i0,j0)-(i1,j1) */
471 455
                 for (k = 0; k < components; ++k) {
472
-                    sum = 0.0;
456
+                    float sum = 0.0;
473 457
 
474
-                    for (ii = i0; ii <= i1; ++ii) {
475
-                        for (jj = j0; jj <= j1; ++jj) {
458
+                    for (int ii = i0; ii <= i1; ++ii) {
459
+                        for (int jj = j0; jj <= j1; ++jj) {
476 460
                             sum += *(tempin + (ii * original_width + jj)
477 461
                                     * components + k);
478 462
                         }
@@ -486,7 +470,7 @@ unsigned char *Texture::scaleBuffer(unsigned char *image,
486 470
     }
487 471
 
488 472
     // Copy to our results.
489
-    for( i = 0; i < height * width * components; ++i) {
473
+    for (i = 0; i < height * width * components; ++i) {
490 474
         timage[i] = (unsigned char)tempout[i];
491 475
     }
492 476
 

+ 1
- 2
src/ViewVolume.cpp Просмотреть файл

@@ -32,9 +32,8 @@ bool ViewVolume::isPointInFrustum(vec_t x, vec_t y, vec_t z) {
32 32
 }
33 33
 
34 34
 bool ViewVolume::isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius) {
35
-    vec_t d;
36 35
     for (unsigned int p = 0; p < 6; ++p) {
37
-        d = mFrustum[p][0] * x + mFrustum[p][1] * y + mFrustum[p][2] * z + mFrustum[p][3];
36
+        vec_t d = mFrustum[p][0] * x + mFrustum[p][1] * y + mFrustum[p][2] * z + mFrustum[p][3];
38 37
         if (d <= -radius)
39 38
             return false;
40 39
     }

+ 15
- 15
src/WindowSDL.cpp Просмотреть файл

@@ -27,6 +27,7 @@ WindowSDL::WindowSDL() {
27 27
     mFontInit = false;
28 28
     mFontName = NULL;
29 29
     mFont = NULL;
30
+    mFontTexture = 0;
30 31
 
31 32
 #ifdef WIN32
32 33
     setDriver("libGL32.dll");
@@ -539,25 +540,24 @@ int WindowSDL::initializeFont() {
539 540
     return 0;
540 541
 }
541 542
 
542
-void WindowSDL::writeString(WindowString *s) {
543
-    assert(s != NULL);
544
-    assert(s->text != NULL);
543
+void WindowSDL::writeString(WindowString &s) {
544
+    assert(s.text != NULL);
545 545
     assert(mInit == true);
546 546
 
547 547
     SDL_Color color;
548
-    color.r = (unsigned char)(s->color[0] * 255.0f);
549
-    color.g = (unsigned char)(s->color[1] * 255.0f);
550
-    color.b = (unsigned char)(s->color[2] * 255.0f);
551
-    color.a = (unsigned char)(s->color[3] * 255.0f);
548
+    color.r = (unsigned char)(s.color[0] * 255.0f);
549
+    color.g = (unsigned char)(s.color[1] * 255.0f);
550
+    color.b = (unsigned char)(s.color[2] * 255.0f);
551
+    color.a = (unsigned char)(s.color[3] * 255.0f);
552 552
 
553
-    SDL_Surface *surface = TTF_RenderUTF8_Blended(mFont, s->text, color);
553
+    SDL_Surface *surface = TTF_RenderUTF8_Blended(mFont, s.text, color);
554 554
     if (surface == NULL) {
555 555
         printf("TTF_RenderUTF8_Blended Error: %s\n", TTF_GetError());
556 556
         return;
557 557
     }
558 558
 
559
-    s->w = (int)((float)surface->w * s->scale);
560
-    s->h = (int)((float)surface->h * s->scale);
559
+    s.w = (int)((float)surface->w * s.scale);
560
+    s.h = (int)((float)surface->h * s.scale);
561 561
 
562 562
     GLenum textureFormat;
563 563
     if (surface->format->BytesPerPixel == 4) {
@@ -577,10 +577,10 @@ void WindowSDL::writeString(WindowString *s) {
577 577
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
578 578
     glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
579 579
 
580
-    GLuint xMin = s->x;
581
-    GLuint yMin = s->y;
582
-    GLuint xMax = xMin + (int)((float)surface->w * s->scale);
583
-    GLuint yMax = yMin + (int)((float)surface->h * s->scale);
580
+    GLuint xMin = s.x;
581
+    GLuint yMin = s.y;
582
+    GLuint xMax = xMin + s.w;
583
+    GLuint yMax = yMin + s.h;
584 584
 
585 585
     glColor4f(color.r / 256.0f, color.g / 256.0f, color.b / 256.0f, color.a / 256.0f);
586 586
 
@@ -617,6 +617,6 @@ void WindowSDL::drawText(unsigned int x, unsigned int y, float scale, const floa
617 617
         tempText.color[2] = color[2];
618 618
         tempText.color[3] = color[3];
619 619
     }
620
-    writeString(&tempText);
620
+    writeString(tempText);
621 621
 }
622 622
 

+ 10
- 1
src/utils/pcx.cpp Просмотреть файл

@@ -98,7 +98,7 @@ int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, un
98 98
         int c = file.get();
99 99
         if (!file) {
100 100
             pcxPrint("Could not read data (%lu%s)", i, (file.eof() ? " EOF" : ""));
101
-            delete buffer;
101
+            delete [] buffer;
102 102
             return -7;
103 103
         }
104 104
 
@@ -109,6 +109,7 @@ int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, un
109 109
                 c = file.get();
110 110
                 if (!file) {
111 111
                     pcxPrint("Could not read data rle (%lu%s)", i, (file.eof() ? " EOF" : ""));
112
+                    delete [] buffer;
112 113
                     return -8;
113 114
                 }
114 115
             }
@@ -130,6 +131,8 @@ int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, un
130 131
                 palette[i] = (unsigned char)file.get();
131 132
                 if (!file) {
132 133
                     pcxPrint("Could not read 256 color palette (%d)", i);
134
+                    delete [] buffer;
135
+                    delete [] palette;
133 136
                     return -9;
134 137
                 }
135 138
             }
@@ -153,6 +156,8 @@ int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, un
153 156
                     pcxPrint("Unsupported number of planes (%d)", nPlanes);
154 157
                     delete [] buffer;
155 158
                     delete [] *image;
159
+                    if (palette != NULL)
160
+                        delete [] palette;
156 161
                     return -10;
157 162
                 }
158 163
             } else {
@@ -168,6 +173,8 @@ int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, un
168 173
                     pcxPrint("Unsupported number of planes (%d)", nPlanes);
169 174
                     delete [] buffer;
170 175
                     delete [] *image;
176
+                    if (palette != NULL)
177
+                        delete [] palette;
171 178
                     return -11;
172 179
                 }
173 180
             }
@@ -179,6 +186,8 @@ int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, un
179 186
         }
180 187
     }
181 188
 
189
+    delete [] buffer;
190
+
182 191
     if (palette != NULL)
183 192
         delete [] palette;
184 193
 

Загрузка…
Отмена
Сохранить