Browse Source

Removed useless global variables.

Also added more asserts()
Thomas Buck 10 years ago
parent
commit
2e9c1855c3
5 changed files with 29 additions and 37 deletions
  1. 7
    16
      src/Mesh.cpp
  2. 9
    0
      src/Particle.cpp
  3. 7
    11
      src/SDLSystem.cpp
  4. 6
    7
      src/System.cpp
  5. 0
    3
      src/Texture.cpp

+ 7
- 16
src/Mesh.cpp View File

5
  * \author Mongoose
5
  * \author Mongoose
6
  */
6
  */
7
 
7
 
8
+#include <stdlib.h>
9
+#include <assert.h>
10
+
8
 #ifdef __APPLE__
11
 #ifdef __APPLE__
9
 #include <OpenGL/gl.h>
12
 #include <OpenGL/gl.h>
10
 #else
13
 #else
571
 void Mesh::setColor(unsigned int index,
574
 void Mesh::setColor(unsigned int index,
572
         float r, float g, float b, float a)
575
         float r, float g, float b, float a)
573
 {
576
 {
574
-    if (index > mNumColors)
575
-    {
576
-        return;
577
-    }
577
+    assert(index < mNumColors);
578
 
578
 
579
     mColors[index][0] = r;
579
     mColors[index][0] = r;
580
     mColors[index][1] = g;
580
     mColors[index][1] = g;
585
 
585
 
586
 void Mesh::setColor(unsigned int index, float rgba[4])
586
 void Mesh::setColor(unsigned int index, float rgba[4])
587
 {
587
 {
588
-    if (index > mNumColors)
589
-    {
590
-        return;
591
-    }
588
+    assert(index < mNumColors);
592
 
589
 
593
     mColors[index][0] = rgba[0];
590
     mColors[index][0] = rgba[0];
594
     mColors[index][1] = rgba[1];
591
     mColors[index][1] = rgba[1];
599
 
596
 
600
 void Mesh::setNormal(unsigned int index, float i, float j, float k)
597
 void Mesh::setNormal(unsigned int index, float i, float j, float k)
601
 {
598
 {
602
-    if (index > mNumNormals)
603
-    {
604
-        return;
605
-    }
599
+    assert(index < mNumNormals);
606
 
600
 
607
     mNormals[index][0] = i;
601
     mNormals[index][0] = i;
608
     mNormals[index][1] = j;
602
     mNormals[index][1] = j;
612
 
606
 
613
 void Mesh::setVertex(unsigned int index, float x, float y, float z)
607
 void Mesh::setVertex(unsigned int index, float x, float y, float z)
614
 {
608
 {
615
-    if (index > mNumVertices)
616
-    {
617
-        return;
618
-    }
609
+    assert(index < mNumVertices);
619
 
610
 
620
     mVertices[index][0] = x;
611
     mVertices[index][0] = x;
621
     mVertices[index][1] = y;
612
     mVertices[index][1] = y;

+ 9
- 0
src/Particle.cpp View File

7
 
7
 
8
 #include <stdlib.h>
8
 #include <stdlib.h>
9
 #include <stdio.h>
9
 #include <stdio.h>
10
+#include <assert.h>
10
 
11
 
11
 #include "Particle.h"
12
 #include "Particle.h"
12
 
13
 
98
 
99
 
99
 void Particle::Pos(float *x, float *y, float *z)
100
 void Particle::Pos(float *x, float *y, float *z)
100
 {
101
 {
102
+    assert(x != NULL);
103
+    assert(y != NULL);
104
+    assert(z != NULL);
105
+
101
     *x = _pos[0];
106
     *x = _pos[0];
102
     *y = _pos[1];
107
     *y = _pos[1];
103
     *z = _pos[2];
108
     *z = _pos[2];
106
 
111
 
107
 void Particle::Color(float *r, float *g, float *b)
112
 void Particle::Color(float *r, float *g, float *b)
108
 {
113
 {
114
+    assert(r != NULL);
115
+    assert(g != NULL);
116
+    assert(b != NULL);
117
+
109
     *r = _color[0];
118
     *r = _color[0];
110
     *g = _color[1];
119
     *g = _color[1];
111
     *b = _color[2];
120
     *b = _color[2];

+ 7
- 11
src/SDLSystem.cpp View File

9
 #include <stdio.h>
9
 #include <stdio.h>
10
 #include <string.h>
10
 #include <string.h>
11
 #include <cmath>
11
 #include <cmath>
12
+#include <assert.h>
12
 
13
 
13
 #include "SDL_opengl.h"
14
 #include "SDL_opengl.h"
14
 
15
 
15
 #include "utils/math.h"
16
 #include "utils/math.h"
16
 #include "SDLSystem.h"
17
 #include "SDLSystem.h"
17
 
18
 
18
-unsigned int *gWidth = 0x0;
19
-unsigned int *gHeight = 0x0;
20
-
21
 SDLSystem::SDLSystem() : System() {
19
 SDLSystem::SDLSystem() : System() {
22
     mWindow = 0x0;
20
     mWindow = 0x0;
23
-    gWidth = &m_width;
24
-    gHeight = &m_height;
25
     mFullscreen = false;
21
     mFullscreen = false;
26
 }
22
 }
27
 
23
 
28
 SDLSystem::~SDLSystem() {
24
 SDLSystem::~SDLSystem() {
29
 }
25
 }
30
 
26
 
31
-/*
32
-unsigned int SDLSystem::getTicks() {
33
-    return SDL_GetTicks();
34
-}
35
-*/
36
-
37
 #ifdef FIXME
27
 #ifdef FIXME
38
 void SDLSystem::bindKeyCommand(const char *cmd, int key, int event) {
28
 void SDLSystem::bindKeyCommand(const char *cmd, int key, int event) {
39
     if (key > 255) {
29
     if (key > 255) {
56
 void SDLSystem::initVideo(unsigned int width, unsigned int height, bool fullscreen) {
46
 void SDLSystem::initVideo(unsigned int width, unsigned int height, bool fullscreen) {
57
     int flags = 0; //, x, y;
47
     int flags = 0; //, x, y;
58
 
48
 
49
+    assert(width > 0);
50
+    assert(height > 0);
51
+
59
     // Create GL context
52
     // Create GL context
60
     SDL_Init(SDL_INIT_VIDEO);
53
     SDL_Init(SDL_INIT_VIDEO);
61
     printf("Created OpenGL Context\n");
54
     printf("Created OpenGL Context\n");
105
 }
98
 }
106
 
99
 
107
 void SDLSystem::resize(unsigned int width, unsigned int height) {
100
 void SDLSystem::resize(unsigned int width, unsigned int height) {
101
+    assert(width > 0);
102
+    assert(height > 0);
103
+
108
     m_width = width;
104
     m_width = width;
109
     m_height = height;
105
     m_height = height;
110
 
106
 

+ 6
- 7
src/System.cpp View File

183
 }
183
 }
184
 
184
 
185
 void System::setDriverGL(const char *driver) {
185
 void System::setDriverGL(const char *driver) {
186
-    unsigned int len;
186
+    assert(driver != NULL);
187
+    assert(driver[0] != '\0');
187
 
188
 
188
     if (m_driver)
189
     if (m_driver)
189
         delete [] m_driver;
190
         delete [] m_driver;
190
 
191
 
191
-    if (driver && driver[0]) {
192
-        len = strlen(driver);
193
-        m_driver = new char[len+1];
194
-        strncpy(m_driver, driver, len);
195
-        m_driver[len] = 0;
196
-    }
192
+    unsigned int len = strlen(driver);
193
+    m_driver = new char[len + 1];
194
+    strncpy(m_driver, driver, len);
195
+    m_driver[len] = 0;
197
 }
196
 }
198
 
197
 
199
 void System::resizeGL(unsigned int w, unsigned int h) {
198
 void System::resizeGL(unsigned int w, unsigned int h) {

+ 0
- 3
src/Texture.cpp View File

23
 #include "utils/tga.h"
23
 #include "utils/tga.h"
24
 #include "Texture.h"
24
 #include "Texture.h"
25
 
25
 
26
-//Texture *gTextureManager = 0x0;
27
 gl_font_t *gFontTest = 0x0;
26
 gl_font_t *gFontTest = 0x0;
28
 
27
 
29
 
28
 
41
     mTextureCount = 0;
40
     mTextureCount = 0;
42
     mTextureLimit = 0;
41
     mTextureLimit = 0;
43
 
42
 
44
-    //gTextureManager = this;
45
-
46
     initSDL_TTF();
43
     initSDL_TTF();
47
 
44
 
48
     textureDebug = -1;
45
     textureDebug = -1;

Loading…
Cancel
Save