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,6 +5,9 @@
5 5
  * \author Mongoose
6 6
  */
7 7
 
8
+#include <stdlib.h>
9
+#include <assert.h>
10
+
8 11
 #ifdef __APPLE__
9 12
 #include <OpenGL/gl.h>
10 13
 #else
@@ -571,10 +574,7 @@ void Mesh::bufferVertexArray(unsigned int vertexCount, vec_t *vertices)
571 574
 void Mesh::setColor(unsigned int index,
572 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 579
     mColors[index][0] = r;
580 580
     mColors[index][1] = g;
@@ -585,10 +585,7 @@ void Mesh::setColor(unsigned int index,
585 585
 
586 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 590
     mColors[index][0] = rgba[0];
594 591
     mColors[index][1] = rgba[1];
@@ -599,10 +596,7 @@ void Mesh::setColor(unsigned int index, float rgba[4])
599 596
 
600 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 601
     mNormals[index][0] = i;
608 602
     mNormals[index][1] = j;
@@ -612,10 +606,7 @@ void Mesh::setNormal(unsigned int index, float i, float j, float k)
612 606
 
613 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 611
     mVertices[index][0] = x;
621 612
     mVertices[index][1] = y;

+ 9
- 0
src/Particle.cpp View File

@@ -7,6 +7,7 @@
7 7
 
8 8
 #include <stdlib.h>
9 9
 #include <stdio.h>
10
+#include <assert.h>
10 11
 
11 12
 #include "Particle.h"
12 13
 
@@ -98,6 +99,10 @@ void Particle::Reset()
98 99
 
99 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 106
     *x = _pos[0];
102 107
     *y = _pos[1];
103 108
     *z = _pos[2];
@@ -106,6 +111,10 @@ void Particle::Pos(float *x, float *y, float *z)
106 111
 
107 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 118
     *r = _color[0];
110 119
     *g = _color[1];
111 120
     *b = _color[2];

+ 7
- 11
src/SDLSystem.cpp View File

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

+ 6
- 7
src/System.cpp View File

@@ -183,17 +183,16 @@ int System::loadResourceFile(const char *filename) {
183 183
 }
184 184
 
185 185
 void System::setDriverGL(const char *driver) {
186
-    unsigned int len;
186
+    assert(driver != NULL);
187
+    assert(driver[0] != '\0');
187 188
 
188 189
     if (m_driver)
189 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 198
 void System::resizeGL(unsigned int w, unsigned int h) {

+ 0
- 3
src/Texture.cpp View File

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

Loading…
Cancel
Save