diff Sprites.cpp @ 677:551f74425b17

Merge
author Nomad
date Fri, 15 Mar 2013 04:17:54 +0200
parents 9824e2eeee30
children 1d05543f522d
line wrap: on
line diff
--- a/Sprites.cpp	Fri Mar 15 04:13:24 2013 +0200
+++ b/Sprites.cpp	Fri Mar 15 04:17:54 2013 +0200
@@ -47,217 +47,180 @@
 }
 
 //----- (0044D513) --------------------------------------------------------
-void SpriteFrameTable::InitializeSprite(unsigned int uSpriteID)
-{
-  //SpriteFrameTable *v2; // esi@1
-  unsigned int v3; // ebx@3
-  //char *v4; // edx@3
-  //int v5; // eax@3
-  SpriteFrame *v6; // ecx@5
-  int v7; // eax@5
-  __int16 v8; // ax@6
-  //signed int v9; // edx@6
-  //int v10; // ecx@6
-  signed int v11; // edi@10
-  __int16 v12; // ax@16
-  int v13; // ecx@16
-  size_t v14; // eax@19
-  signed int v15; // edi@19
-  __int16 v16; // ax@27
-  int v17; // ecx@27
-  signed int v18; // edi@29
-  SpriteFrame *v19; // eax@30
-  __int16 v20; // ax@45
-  int v21; // ecx@45
-  const char *v22; // [sp-8h] [bp-50h]@12
-  const char *v23; // [sp-8h] [bp-50h]@21
-  const char *v24; // [sp-8h] [bp-50h]@37
-  const char *v25; // [sp-4h] [bp-4Ch]@12
-  char *v26; // [sp-4h] [bp-4Ch]@21
-  const char *v27; // [sp-4h] [bp-4Ch]@37
-  char v28[3]; // [sp+9h] [bp-3Fh]@19
-  char Str; // [sp+Ch] [bp-3Ch]@19
-  char Size[20]; // [sp+2Ch] [bp-1Ch]@15
-  char Source[4]; // [sp+40h] [bp-8h]@19
-  int v32; // [sp+44h] [bp-4h]@19
-  unsigned int uSpriteIDa; // [sp+50h] [bp+8h]@4
+void SpriteFrameTable::InitializeSprite( signed int uSpriteID )
+    {
+    //SpriteFrameTable *v2; // esi@1
+    unsigned int v3; // ebx@3
+    //char *v4; // edx@3
+    //int v5; // eax@3
+    SpriteFrame *v6; // ecx@5
+    int v7; // eax@5
+    __int16 v8; // ax@6
+    //signed int v9; // edx@6
+    //int v10; // ecx@6
+    signed int v11; // edi@10
+    __int16 v12; // ax@16
+    int v13; // ecx@16
+    size_t v14; // eax@19
+    signed int v15; // edi@19
+    __int16 v16; // ax@27
+    int v17; // ecx@27
+    signed int v18; // edi@29
+    SpriteFrame *v19; // eax@30
+    __int16 v20; // ax@45
+    int v21; // ecx@45
 
-  //v2 = this;
-  if ( (signed int)uSpriteID <= (signed int)this->uNumSpriteFrames )
-  {
-    if ( (uSpriteID & 0x80000000u) == 0 )
-    {
-      v3 = uSpriteID;
+    char Str[32]; // [sp+Ch] [bp-3Ch]@19
+    char sprite_name[20]; // [sp+2Ch] [bp-1Ch]@15
+    char Source[4]; // [sp+40h] [bp-8h]@19
 
-      auto uFlags = pSpriteSFrames[uSpriteID].uFlags;
-      if (uFlags & 0x7F)
-      {
-        pSpriteSFrames[uSpriteID].uFlags |= 0x80;
 
-        uSpriteIDa = 30 * uSpriteID + 12;
-        while ( 1 )
+    //v2 = this;
+    if ( uSpriteID <= this->uNumSpriteFrames )
         {
-          pSpriteSFrames[v3].uPaletteIndex = pPaletteManager->LoadPalette(pSpriteSFrames[uSpriteID].uPaletteID);
-          v6 = &pSpriteSFrames[uSpriteID];
-          v7 = v6->uFlags;
-          if ( v7 & 0x10 )
-          {
-            v8 = pSprites_LOD->LoadSprite(v6->pTextureName, v6->uPaletteID);
-
-            for (uint i = 0; i < 8; ++i)
-              pSpriteSFrames[v3].pHwSpriteIDs[i] = v8;
-            goto LABEL_46;
-          }
-          if ( v7 & 0x10000 )
-          {
-            v11 = 0;
-            do
+        if ( uSpriteID >= 0 )
             {
-              switch ( v11 )
-              {
-                case 3:
-                case 4:
-                case 5:
-                  v25 = pSpriteSFrames[v3].pTextureName;
-                  v22 = "%s4";
-                  goto LABEL_15;
-                case 2:
-                case 6:
-                  v25 = pSpriteSFrames[v3].pTextureName;
-                  v22 = "%s2";
-                  goto LABEL_15;
-                case 0:
-                case 1:
-                case 7:
-                  v25 = pSpriteSFrames[v3].pTextureName;
-                  v22 = "%s0";
-LABEL_15:
-                  sprintf(Size, v22, v25);
-                  break;
-                default:
-                  break;
-              }
-              v12 = pSprites_LOD->LoadSprite(Size, pSpriteSFrames[v3].uPaletteID);
-              v13 = v11++ + uSpriteIDa;
-              *(short *)&pSpriteSFrames->pIconName[2 * v13] = v12;
-            }
-            while ( v11 < 8 );
-            goto LABEL_46;
-          }
-          if ( !(v7 & 0x40) )
-            break;
-          strcpy(Source, "stA");
-          v32 = 0;
-          strcpy(&Str, v6->pTextureName);
-          v14 = strlen(&Str);
-          strcpy(&v28[v14], Source);
-          v15 = 0;
-          do
-          {
-            switch ( v15 )
-            {
-              case 0:
-                v26 = pSpriteSFrames[v3].pTextureName;
-                v23 = "%s0";
-                goto LABEL_26;
-              case 4:
-                v26 = &Str;
-                v23 = "%s4";
-                goto LABEL_26;
-              case 3:
-              case 5:
-                v26 = &Str;
-                v23 = "%s3";
-                goto LABEL_26;
-              case 2:
-              case 6:
-                v26 = pSpriteSFrames[v3].pTextureName;
-                v23 = "%s2";
-                goto LABEL_26;
-              case 1:
-              case 7:
-                v26 = pSpriteSFrames[v3].pTextureName;
-                v23 = "%s1";
-LABEL_26:
-                sprintf(Size, v23, v26);
-                break;
-              default:
-                break;
-            }
-            v16 = pSprites_LOD->LoadSprite(Size, pSpriteSFrames[v3].uPaletteID);
-            v17 = v15++ + uSpriteIDa;
-            *(short *)&pSpriteSFrames->pIconName[2 * v17] = v16;
-          }
-          while ( v15 < 8 );
-LABEL_46:
-          if ( !(pSpriteSFrames[v3].uFlags & 1) )
-            return;
-          uSpriteIDa += 30;
-          ++v3;
+            v3 = uSpriteID;
+
+            auto uFlags = pSpriteSFrames[v3].uFlags;
+            if (!(uFlags & 0x0080))  //not loaded
+                {
+                pSpriteSFrames[v3].uFlags |= 0x80; //set loaded
+                while ( 1 )
+                    {
+                    pSpriteSFrames[v3].uPaletteIndex = pPaletteManager->LoadPalette(pSpriteSFrames[v3].uPaletteID);
+                    if ( uFlags & 0x10 )  //single frame per frame sequence
+                        {
+                        v8 = pSprites_LOD->LoadSprite(pSpriteSFrames[v3].pTextureName, pSpriteSFrames[v3].uPaletteID);
+                        for (uint i = 0; i < 8; ++i)
+                            {
+
+                            pSpriteSFrames[v3].pHwSpriteIDs[i] = v8;
+                            }
+                            
+                        }
+                    else if ( uFlags & 0x10000 )
+                        {
+                        for (uint i = 0; i < 8; ++i)
+                            {
+                            switch ( i )
+                                {
+                            case 3:
+                            case 4:
+                            case 5:
+                                sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName);
+                                break;
+                            case 2:
+                            case 6:
+                                sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName);
+                                break;
+                            case 0:
+                            case 1:
+                            case 7:
+                                sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName);
+                                break;
+                                }
+                            v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID);
+
+                            pSpriteSFrames[v3].pHwSpriteIDs[i]=v12;
+                            }
+
+                        }
+                    else if ( uFlags & 0x40 ) //part of monster fidgeting seq
+                        {
+                        strcpy(Source, "stA");
+                        strcpy(Str, pSpriteSFrames[v3].pTextureName);
+                        v14 = strlen(Str);
+                        strcpy(&Str[v14-3], Source);
+                        for (uint i = 0; i < 8; ++i)
+                            {
+                            switch ( i )
+                                {
+                            case 0:
+                                sprintf(sprite_name, "%s0", pSpriteSFrames[v3].pTextureName);
+                                break;
+                            case 4:
+                                sprintf(sprite_name, "%s4",&Str );
+                                break;
+                            case 3:
+                            case 5:
+                                sprintf(sprite_name, "%s3",&Str );
+                                break;
+                            case 2:
+                            case 6:
+                                sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName);
+                                break;
+                            case 1:
+                            case 7:
+                                sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName);
+                                break;
+                                }
+                            v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID);
+                            pSpriteSFrames[v3].pHwSpriteIDs[i]=v12;
+                            }
+                        }
+
+                    else
+                        {
+                        for (uint i = 0; i < 8; ++i)
+
+                            {
+
+                            if (((0x0100 << i) & pSpriteSFrames[v3].uFlags) ) //mirrors
+                                {
+                                switch ( i )
+                                    {
+                                case 1:
+                                    sprintf(sprite_name, "%s7", pSpriteSFrames[v3].pTextureName);
+                                    break;
+                                case 2:
+                                    sprintf(sprite_name, "%s6", pSpriteSFrames[v3].pTextureName);
+                                    break;
+                                case 3:
+                                    sprintf(sprite_name, "%s5", pSpriteSFrames[v3].pTextureName);
+                                    break;
+                                case 4:
+                                    sprintf(sprite_name, "%s4", pSpriteSFrames[v3].pTextureName);
+                                    break;
+
+                                case 5:
+                                    sprintf(sprite_name, "%s3", pSpriteSFrames[v3].pTextureName);
+                                    break;
+
+                                case 6:
+                                    sprintf(sprite_name, "%s2", pSpriteSFrames[v3].pTextureName);
+                                    break;
+                                case 7:
+                                    sprintf(sprite_name, "%s1", pSpriteSFrames[v3].pTextureName);
+                                    break;
+                                    }
+                                }
+                            else
+                                {
+                                sprintf(sprite_name, "%s%i", pSpriteSFrames[v3].pTextureName, i);
+
+                                }
+                            v12 = pSprites_LOD->LoadSprite(sprite_name, pSpriteSFrames[v3].uPaletteID);
+                            pSpriteSFrames[v3].pHwSpriteIDs[i]=v12;
+
+                            }
+                        }
+
+                    if ( !(pSpriteSFrames[v3].uFlags & 1) )
+                        return;
+                    ++v3;
+                    }
+                }
+            } 
         }
-        v18 = 0;
-        while ( 1 )
-        {
-          v19 = &pSpriteSFrames[v3];
-          if ( !((256 << v18) & v19->uFlags) )
-          {
-            sprintf(Size, "%s%i", v19->pTextureName, v18);
-            goto LABEL_45;
-          }
-          if ( v18 == 1 )
-          {
-            v27 = v19->pTextureName;
-            v24 = "%s7";
-            goto LABEL_42;
-          }
-          if ( v18 == 2 )
-          {
-            v27 = v19->pTextureName;
-            v24 = "%s6";
-            goto LABEL_42;
-          }
-          if ( v18 == 3 )
-          {
-            v27 = v19->pTextureName;
-            v24 = "%s5";
-            goto LABEL_42;
-          }
-          if ( v18 == 5 )
-          {
-            v27 = v19->pTextureName;
-            v24 = "%s3";
-            goto LABEL_42;
-          }
-          if ( v18 == 6 )
-            break;
-          if ( v18 == 7 )
-          {
-            v27 = v19->pTextureName;
-            v24 = "%s1";
-LABEL_42:
-            sprintf(Size, v24, v27);
-          }
-LABEL_45:
-          v20 = pSprites_LOD->LoadSprite(Size, pSpriteSFrames[v3].uPaletteID);
-          v21 = v18++ + uSpriteIDa;
-          *(short *)&pSpriteSFrames->pIconName[2 * v21] = v20;
-          if ( v18 >= 8 )
-            goto LABEL_46;
-        }
-        v27 = v19->pTextureName;
-        v24 = "%s2";
-        goto LABEL_42;
-      }
     }
-  }
-}
 
 //----- (0044D813) --------------------------------------------------------
-unsigned int SpriteFrameTable::FastFindSprite(char *pSpriteName)
-{
+signed int SpriteFrameTable::FastFindSprite( char *pSpriteName )
+    {
   SpriteFrameTable *v2; // esi@1
   int v3; // eax@1
-  unsigned int result; // eax@2
+  signed int result; // eax@2
 
   v2 = this;
   BinarySearch(0, this->uNumEFrames, pSpriteName);
@@ -511,14 +474,8 @@
   }
   v2->uNumSpriteFrames = v4;
   v2->pSpriteSFrames = (SpriteFrame *)pAllocator->AllocNamedChunk(v2->pSpriteSFrames, 60 * v4, "S Frames");
-  v2->pSpriteEFrames = (__int16 *)pAllocator->AllocNamedChunk(
-                                    v2->pSpriteEFrames,
-                                    2 * v2->uNumSpriteFrames,
-                                    "E Frames");
-  v2->pSpritePFrames = (SpriteFrame **)pAllocator->AllocNamedChunk(
-                                         v2->pSpritePFrames,
-                                         4 * v2->uNumSpriteFrames,
-                                         "P Frames");
+  v2->pSpriteEFrames = (__int16 *)pAllocator->AllocNamedChunk(  v2->pSpriteEFrames, 2 * v2->uNumSpriteFrames,   "E Frames");
+  v2->pSpritePFrames = (SpriteFrame **)pAllocator->AllocNamedChunk(  v2->pSpritePFrames, 4 * v2->uNumSpriteFrames, "P Frames");
   if ( v2->pSpriteSFrames )
   {
     v6 = File;