Browse Source

Simplified Render Texture loading

Thomas Buck 10 years ago
parent
commit
6eba26fb03
4 changed files with 13 additions and 36 deletions
  1. 0
    1
      include/Game.h
  2. 3
    8
      include/Render.h
  3. 6
    7
      src/Game.cpp
  4. 4
    20
      src/Render.cpp

+ 0
- 1
include/Game.h View File

@@ -60,7 +60,6 @@ private:
60 60
     TombRaider mTombRaider;
61 61
 
62 62
     unsigned int mTextureStart;
63
-    unsigned int mTextureLevelOffset;
64 63
     unsigned int mTextureOffset;
65 64
 };
66 65
 

+ 3
- 8
include/Render.h View File

@@ -152,14 +152,11 @@ public:
152 152
                           unsigned int id);
153 153
 
154 154
     /*!
155
-     * \brief Sets up textures for OpenRaider.
155
+     * \brief Sets up textures for OpenRaider
156 156
      * \param textureDir Is valid and exists with textures
157
-     * \param numLoaded returns number of loaded textures and will update
158
-     * number of external textures loaded
159
-     * \param nextId will update next level texture id
157
+     * \returns number of loaded textures
160 158
      */
161
-    void initTextures(char *textureDir, unsigned int *numLoaded,
162
-                            unsigned int *nextId);
159
+    int initTextures(char *textureDir);
163 160
 
164 161
     /*!
165 162
      * Removes current world/entity/etc geometry
@@ -318,8 +315,6 @@ private:
318 315
 
319 316
     unsigned int mFlags;                  //!< Rendering flags
320 317
     unsigned int mMode;                   //!< Rendering mode
321
-    unsigned int *mNumTexturesLoaded;
322
-    unsigned int *mNextTextureId;
323 318
     int mLock;
324 319
     int mSkyMesh;                         //!< Skymesh model id
325 320
     bool mSkyMeshRotation;                //!< Should Skymesh be rotated?

+ 6
- 7
src/Game.cpp View File

@@ -43,7 +43,6 @@ Game::Game() {
43 43
     mLara = NULL;
44 44
 
45 45
     mTextureStart = 0;
46
-    mTextureLevelOffset = 0;
47 46
     mTextureOffset = 0;
48 47
 }
49 48
 
@@ -53,7 +52,7 @@ Game::~Game() {
53 52
 
54 53
 int Game::initialize() {
55 54
     // Enable Renderer
56
-    getRender().initTextures(getOpenRaider().mDataDir, &mTextureStart, &mTextureLevelOffset);
55
+    mTextureStart = getRender().initTextures(getOpenRaider().mDataDir);
57 56
     getRender().setMode(Render::modeLoadScreen);
58 57
 
59 58
     // Enable World Hopping
@@ -235,19 +234,19 @@ void Game::processTextures()
235 234
         mTombRaider.Texture(i, &image, &bumpmap);
236 235
 
237 236
         // Overwrite any previous level textures on load
238
-        getRender().loadTexture(image, 256, 256, mTextureLevelOffset + i);
237
+        getRender().loadTexture(image, 256, 256, (mTextureStart - 1) + i);
239 238
 
240 239
 #ifdef MULTITEXTURE
241
-        gMapTex2Bump[mTextureLevelOffset + i] = -1;
240
+        gMapTex2Bump[(mTextureStart - 1) + i] = -1;
242 241
 #endif
243 242
 
244 243
         if (bumpmap)
245 244
         {
246 245
 #ifdef MULTITEXTURE
247
-            gMapTex2Bump[mTextureLevelOffset + i] = mTextureLevelOffset + i +
246
+            gMapTex2Bump[(mTextureStart - 1) + i] = (mTextureStart - 1) + i +
248 247
                     mTombRaider.NumTextures();
249 248
 #endif
250
-            getRender().loadTexture(bumpmap, 256, 256, mTextureLevelOffset + i +
249
+            getRender().loadTexture(bumpmap, 256, 256, (mTextureStart - 1) + i +
251 250
                     mTombRaider.NumTextures());
252 251
         }
253 252
 
@@ -261,7 +260,7 @@ void Game::processTextures()
261 260
         //fflush(stdout);
262 261
     }
263 262
 
264
-    mTextureOffset = mTextureLevelOffset + mTombRaider.NumTextures();
263
+    mTextureOffset = (mTextureStart - 1) + mTombRaider.NumTextures();
265 264
 
266 265
     printf("Done! Found %d textures.\n", mTombRaider.NumTextures());
267 266
 }

+ 4
- 20
src/Render.cpp View File

@@ -92,9 +92,6 @@ Render::Render()
92 92
     mFlags = (fRoomAlpha | fViewModel | fSprites |
93 93
             fRoomModels | fEntityModels |
94 94
             fUsePortals | fUpdateRoomListPerFrame);
95
-
96
-    mNextTextureId = NULL;
97
-    mNumTexturesLoaded = NULL;
98 95
 }
99 96
 
100 97
 
@@ -137,26 +134,17 @@ void Render::loadTexture(unsigned char *image,
137 134
 }
138 135
 
139 136
 
140
-void Render::initTextures(char *textureDir, unsigned int *numLoaded,
141
-        unsigned int *nextId)
142
-{
137
+int Render::initTextures(char *textureDir) {
143 138
     char filename[128];
144
-    int bg;
145 139
     unsigned int numTextures = 0;
146 140
     unsigned char color[4];
147 141
 
148
-    // We want to update as needed later
149
-    mNumTexturesLoaded = numLoaded;
150
-    mNextTextureId = nextId;
151
-
152 142
     mTexture.reset();
153 143
     mTexture.setMaxTextureCount(128);  /* TR never needs more than 32 iirc
154 144
                                           However, color texturegen is a lot */
155 145
 
156 146
     mTexture.setFlag(Texture::fUseMipmaps);
157 147
 
158
-    printf("Processing Textures:\n");
159
-
160 148
     color[0] = 0xff;
161 149
     color[1] = 0xff;
162 150
     color[2] = 0xff;
@@ -165,17 +153,13 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
165 153
     if (mTexture.loadColorTexture(color, 32, 32) > -1)
166 154
         numTextures++;
167 155
 
156
+    //! \fixme Error Checking. Return negative error code, check in calling place too
168 157
     snprintf(filename, 126, "%s/%s", textureDir, "splash.tga");
169 158
     filename[127] = 0;
170
-
171
-    if ((bg = mTexture.loadTGA(filename)) > -1)
159
+    if (mTexture.loadTGA(filename) > -1)
172 160
         numTextures++;
173 161
 
174
-    // Weird that it isn't linear, must be some storage deal in Texture
175
-    // I forgot about Id allocation
176
-    *nextId = bg;
177
-
178
-    *numLoaded = numTextures;
162
+    return numTextures;
179 163
 }
180 164
 
181 165
 

Loading…
Cancel
Save