瀏覽代碼

Various little fixes

Thomas Buck 11 年之前
父節點
當前提交
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
         * Don't even new ... the data structures but use std::make_shared or allocate_shared?
12
         * Don't even new ... the data structures but use std::make_shared or allocate_shared?
13
         * Pass object references to all other objects that need it, completely remove gOpenRaider
13
         * Pass object references to all other objects that need it, completely remove gOpenRaider
14
     * Use streams for (file) I/O
14
     * Use streams for (file) I/O
15
+        * Does not need strtok() anymore
15
     * Use std::strings
16
     * Use std::strings
16
 
17
 
17
 ## Changes
18
 ## Changes

+ 0
- 2
include/Console.h 查看文件

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

+ 0
- 4
include/Menu.h 查看文件

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

+ 1
- 1
include/Window.h 查看文件

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

+ 1
- 1
include/WindowSDL.h 查看文件

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

+ 3
- 8
src/Menu.cpp 查看文件

59
     return mVisible;
59
     return mVisible;
60
 }
60
 }
61
 
61
 
62
-#ifdef WIN32
63
-void Menu::loadPakFolderHelper(std::vector<char *> &list) {
64
-
65
-}
66
-#endif
67
-
68
 void Menu::loadPakFolderRecursive(const char *dir) {
62
 void Menu::loadPakFolderRecursive(const char *dir) {
69
     assert(dir != NULL);
63
     assert(dir != NULL);
70
     assert(dir[0] != '\0');
64
     assert(dir[0] != '\0');
210
         glRecti(0, 0, getWindow().mWidth, getWindow().mHeight);
204
         glRecti(0, 0, getWindow().mWidth, getWindow().mHeight);
211
         glEnable(GL_TEXTURE_2D);
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
         mainText.x = (getWindow().mWidth / 2) - (mainText.w / 2);
209
         mainText.x = (getWindow().mWidth / 2) - (mainText.w / 2);
215
-        getWindow().writeString(&mainText);
210
+        getWindow().writeString(mainText);
216
 
211
 
217
         if (!mMapListFilled) {
212
         if (!mMapListFilled) {
218
             getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
213
             getWindow().drawText(25, (getWindow().mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");

+ 1
- 1
src/OpenRaider.cpp 查看文件

205
     if (strcmp(var, "size") == 0) {
205
     if (strcmp(var, "size") == 0) {
206
         // value has format like "\"1024x768\""
206
         // value has format like "\"1024x768\""
207
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
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
             getConsole().print("set-size-Error: Invalid value (%s)", value);
209
             getConsole().print("set-size-Error: Invalid value (%s)", value);
210
             return -2;
210
             return -2;
211
         }
211
         }

+ 4
- 5
src/Render.cpp 查看文件

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

+ 2
- 0
src/Sprite.cpp 查看文件

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

+ 23
- 39
src/Texture.cpp 查看文件

167
 void convertARGB32bppToRGBA32bpp(unsigned char *image,
167
 void convertARGB32bppToRGBA32bpp(unsigned char *image,
168
         unsigned int w, unsigned int h) {
168
         unsigned int w, unsigned int h) {
169
     unsigned int i, size = w * h;
169
     unsigned int i, size = w * h;
170
-    unsigned char swap;
171
 
170
 
172
     assert(image != NULL);
171
     assert(image != NULL);
173
     assert(w > 0);
172
     assert(w > 0);
175
 
174
 
176
     for (i = 0; i < size; ++i) {
175
     for (i = 0; i < size; ++i) {
177
         /* 32-bit ARGB to RGBA */
176
         /* 32-bit ARGB to RGBA */
178
-        swap = image[(i * 4) + 3];
177
+        unsigned char swap = image[(i * 4) + 3];
179
         image[(i * 4)] = image[(i * 4) + 1];
178
         image[(i * 4)] = image[(i * 4) + 1];
180
         image[(i * 4) + 1] = image[(i * 4) + 2];
179
         image[(i * 4) + 1] = image[(i * 4) + 2];
181
         image[(i * 4) + 2] = image[(i * 4) + 3];
180
         image[(i * 4) + 2] = image[(i * 4) + 3];
397
 
396
 
398
     if (sx < 1.0 && sy < 1.0) {
397
     if (sx < 1.0 && sy < 1.0) {
399
         /* Magnify both width and height:  use weighted sample of 4 pixels */
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
         for (i = 0; i < height; ++i) {
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
             if (i1 >= original_height) {
403
             if (i1 >= original_height) {
414
                 i1 = original_height - 1;
404
                 i1 = original_height - 1;
415
             }
405
             }
416
 
406
 
417
-            alpha = i * sy - i0;
407
+            float alpha = i * sy - i0;
418
 
408
 
419
             for (j = 0; j < width; ++j) {
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
                 if (j1 >= original_width) {
413
                 if (j1 >= original_width) {
424
                     j1 = original_width - 1;
414
                     j1 = original_width - 1;
425
                 }
415
                 }
426
 
416
 
427
-                beta = j * sx - j0;
417
+                float beta = j * sx - j0;
428
 
418
 
429
                 /* Compute weighted average of pixels in rect (i0,j0)-(i1,j1) */
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
                 for (k = 0; k < components; ++k) {
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
                     *dst++ = s1 * (1.0f - alpha) + s2 * alpha;
430
                     *dst++ = s1 * (1.0f - alpha) + s2 * alpha;
441
                 }
431
                 }
442
             }
432
             }
443
         }
433
         }
444
     } else {
434
     } else {
445
         /* Shrink width and/or height:  use an unweighted box filter */
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
         for (i = 0; i < height; ++i) {
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
             if (i1 >= original_height) {
440
             if (i1 >= original_height) {
457
                 i1 = original_height - 1;
441
                 i1 = original_height - 1;
458
             }
442
             }
459
 
443
 
460
             for (j = 0; j < width; ++j) {
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
                 if (j1 >= original_width) {
448
                 if (j1 >= original_width) {
465
                     j1 = original_width - 1;
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
                 /* Compute average of pixels in the rectangle (i0,j0)-(i1,j1) */
454
                 /* Compute average of pixels in the rectangle (i0,j0)-(i1,j1) */
471
                 for (k = 0; k < components; ++k) {
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
                             sum += *(tempin + (ii * original_width + jj)
460
                             sum += *(tempin + (ii * original_width + jj)
477
                                     * components + k);
461
                                     * components + k);
478
                         }
462
                         }
486
     }
470
     }
487
 
471
 
488
     // Copy to our results.
472
     // Copy to our results.
489
-    for( i = 0; i < height * width * components; ++i) {
473
+    for (i = 0; i < height * width * components; ++i) {
490
         timage[i] = (unsigned char)tempout[i];
474
         timage[i] = (unsigned char)tempout[i];
491
     }
475
     }
492
 
476
 

+ 1
- 2
src/ViewVolume.cpp 查看文件

32
 }
32
 }
33
 
33
 
34
 bool ViewVolume::isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius) {
34
 bool ViewVolume::isSphereInFrustum(vec_t x, vec_t y, vec_t z, vec_t radius) {
35
-    vec_t d;
36
     for (unsigned int p = 0; p < 6; ++p) {
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
         if (d <= -radius)
37
         if (d <= -radius)
39
             return false;
38
             return false;
40
     }
39
     }

+ 15
- 15
src/WindowSDL.cpp 查看文件

27
     mFontInit = false;
27
     mFontInit = false;
28
     mFontName = NULL;
28
     mFontName = NULL;
29
     mFont = NULL;
29
     mFont = NULL;
30
+    mFontTexture = 0;
30
 
31
 
31
 #ifdef WIN32
32
 #ifdef WIN32
32
     setDriver("libGL32.dll");
33
     setDriver("libGL32.dll");
539
     return 0;
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
     assert(mInit == true);
545
     assert(mInit == true);
546
 
546
 
547
     SDL_Color color;
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
     if (surface == NULL) {
554
     if (surface == NULL) {
555
         printf("TTF_RenderUTF8_Blended Error: %s\n", TTF_GetError());
555
         printf("TTF_RenderUTF8_Blended Error: %s\n", TTF_GetError());
556
         return;
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
     GLenum textureFormat;
562
     GLenum textureFormat;
563
     if (surface->format->BytesPerPixel == 4) {
563
     if (surface->format->BytesPerPixel == 4) {
577
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
577
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
578
     glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
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
     glColor4f(color.r / 256.0f, color.g / 256.0f, color.b / 256.0f, color.a / 256.0f);
585
     glColor4f(color.r / 256.0f, color.g / 256.0f, color.b / 256.0f, color.a / 256.0f);
586
 
586
 
617
         tempText.color[2] = color[2];
617
         tempText.color[2] = color[2];
618
         tempText.color[3] = color[3];
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
         int c = file.get();
98
         int c = file.get();
99
         if (!file) {
99
         if (!file) {
100
             pcxPrint("Could not read data (%lu%s)", i, (file.eof() ? " EOF" : ""));
100
             pcxPrint("Could not read data (%lu%s)", i, (file.eof() ? " EOF" : ""));
101
-            delete buffer;
101
+            delete [] buffer;
102
             return -7;
102
             return -7;
103
         }
103
         }
104
 
104
 
109
                 c = file.get();
109
                 c = file.get();
110
                 if (!file) {
110
                 if (!file) {
111
                     pcxPrint("Could not read data rle (%lu%s)", i, (file.eof() ? " EOF" : ""));
111
                     pcxPrint("Could not read data rle (%lu%s)", i, (file.eof() ? " EOF" : ""));
112
+                    delete [] buffer;
112
                     return -8;
113
                     return -8;
113
                 }
114
                 }
114
             }
115
             }
130
                 palette[i] = (unsigned char)file.get();
131
                 palette[i] = (unsigned char)file.get();
131
                 if (!file) {
132
                 if (!file) {
132
                     pcxPrint("Could not read 256 color palette (%d)", i);
133
                     pcxPrint("Could not read 256 color palette (%d)", i);
134
+                    delete [] buffer;
135
+                    delete [] palette;
133
                     return -9;
136
                     return -9;
134
                 }
137
                 }
135
             }
138
             }
153
                     pcxPrint("Unsupported number of planes (%d)", nPlanes);
156
                     pcxPrint("Unsupported number of planes (%d)", nPlanes);
154
                     delete [] buffer;
157
                     delete [] buffer;
155
                     delete [] *image;
158
                     delete [] *image;
159
+                    if (palette != NULL)
160
+                        delete [] palette;
156
                     return -10;
161
                     return -10;
157
                 }
162
                 }
158
             } else {
163
             } else {
168
                     pcxPrint("Unsupported number of planes (%d)", nPlanes);
173
                     pcxPrint("Unsupported number of planes (%d)", nPlanes);
169
                     delete [] buffer;
174
                     delete [] buffer;
170
                     delete [] *image;
175
                     delete [] *image;
176
+                    if (palette != NULL)
177
+                        delete [] palette;
171
                     return -11;
178
                     return -11;
172
                 }
179
                 }
173
             }
180
             }
179
         }
186
         }
180
     }
187
     }
181
 
188
 
189
+    delete [] buffer;
190
+
182
     if (palette != NULL)
191
     if (palette != NULL)
183
         delete [] palette;
192
         delete [] palette;
184
 
193
 

Loading…
取消
儲存