diff LOD.h @ 1669:bd28d08e2c75

Merge
author Ritor1
date Tue, 17 Sep 2013 22:55:48 +0600
parents 69ab7593e7af
children 9bd7522cdbbb
line wrap: on
line diff
--- a/LOD.h	Tue Sep 17 22:55:34 2013 +0600
+++ b/LOD.h	Tue Sep 17 22:55:48 2013 +0600
@@ -2,11 +2,16 @@
 #include <stdio.h>
 #include <memory.h>
 
+#include "Log.h"
 #include "Texture.h"
 #include "ErrorHandling.h"
 
 class Sprite;
 
+
+#define MAX_LOD_TEXTURES 1000
+#define MAX_LOD_SPRITES  1500
+
 /*  354 */
 enum TEXTURE_TYPE
 {
@@ -164,12 +169,23 @@
   void _inlined_sub1();
   void _inlined_sub2();
 
-  inline struct Texture *GetTexture(int idx)
+  inline int LoadDummyTexture()
   {
-    Assert(idx < 1000, "Texture index out of bounds (%u)", idx);
+    for (unsigned int i = 0; i < uNumLoadedFiles; ++i)
+      if (!strcmp(pTextures[i].pName, "pending"))
+        return i;
+    return LoadTextureFromLOD(&pTextures[uNumLoadedFiles], "pending", TEXTURE_16BIT_PALETTE);
+  }
+
+  inline Texture *GetTexture(int idx)
+  {
+    Assert(idx < MAX_LOD_TEXTURES, "Texture index out of bounds (%u)", idx);
     if (idx == -1) 
-      return nullptr; // we need to return dummy texture here
-    return &pTextures[idx];
+    {
+      //Log::Warning(L"Texture id = %d missing", idx);
+      return pTextures + LoadDummyTexture();
+    }
+    return pTextures + idx;
   }
 
 
@@ -187,7 +203,7 @@
   struct LOD::Directory *pSubIndices;
   unsigned int uOffsetToSubIndex;
   FILE *pOutputFileHandle;*/
-  struct Texture pTextures[1000];
+  Texture pTextures[MAX_LOD_TEXTURES];
   unsigned int uNumLoadedFiles;
   int dword_11B80;
   int dword_11B84;
@@ -278,7 +294,7 @@
   struct LOD::Directory *pSubIndices;
   unsigned int uOffsetToSubIndex;
   FILE *pOutputFileHandle;*/
-  struct LODSprite pSpriteHeaders[1500];
+  struct LODSprite pSpriteHeaders[MAX_LOD_SPRITES];
   signed int uNumLoadedSprites;
   int field_ECA0;
   int field_ECA4;