diff Sprites.cpp @ 1028:fbde7d8fcdb1

Merge
author Nomad
date Tue, 21 May 2013 11:24:35 +0200
parents af20650a052f
children 5d5c78088274
line wrap: on
line diff
--- a/Sprites.cpp	Tue May 21 11:24:26 2013 +0200
+++ b/Sprites.cpp	Tue May 21 11:24:35 2013 +0200
@@ -1,4 +1,5 @@
 #include <string.h>
+#include <algorithm>
 
 #include "Allocator.h"
 #include "Sprites.h"
@@ -217,75 +218,43 @@
 
 //----- (0044D813) --------------------------------------------------------
 signed int SpriteFrameTable::FastFindSprite( char *pSpriteName )
-    {
-  SpriteFrameTable *v2; // esi@1
-  int v3; // eax@1
+{
   signed int result; // eax@2
 
-  v2 = this;
-  BinarySearch(0, this->uNumEFrames, pSpriteName);
-  v3 = v2->field_8;
-  if ( v3 < 0 )
+  int searchResult = BinarySearch(pSpriteName);
+  if ( searchResult < 0 )
     result = 0;
   else
-    result = v2->pSpriteEFrames[v3];
+      result = this->pSpriteEFrames[searchResult];
   return result;
 }
 
 //----- (0044D83A) --------------------------------------------------------
-void SpriteFrameTable::BinarySearch(int a2, int a3, const char *pSpriteName)
+int SpriteFrameTable::BinarySearch( const char *pSpriteName )
 {
-  int v4; // ebx@1
-  SpriteFrameTable *v5; // edi@1
-  int v6; // esi@2
-  int v7; // eax@2
-  int a2a; // [sp+14h] [bp+8h]@2
-
-  v4 = a2;
-  v5 = this;
-  while ( 1 )
-  {
-    a2a = a3 - v4;
-    v6 = (a3 - v4) / 2 + v4;
-    v7 = _strcmpi(pSpriteName, v5->pSpritePFrames[v6]->pIconName);
-    if ( !v7 )
-      v5->field_8 = v6;
-    if ( v4 == a3 )
-      break;
-    if ( v7 >= 0 )
+    int startPos = 0;
+    int endPos = uNumEFrames;
+    while ( 1 )
     {
-      if ( a2a <= 4 )
-      {
-        while ( v4 < a3 )
+        int searchRange = endPos - startPos;
+        int middleFrameIndex = (endPos - startPos) / 2 + startPos;
+        int comparisonResult = _stricmp(pSpriteName, this->pSpritePFrames[middleFrameIndex]->pIconName);
+        if ( !comparisonResult )
         {
-          if ( !_strcmpi(pSpriteName, v5->pSpritePFrames[v4]->pIconName) )
-          {
-LABEL_19:
-            v5->field_8 = v4;
-            return;
-          }
-          ++v4;
+            return middleFrameIndex;
+        }
+        if ( startPos == endPos )
+        {
+            return -1;
         }
-        break;
-      }
-      v4 += (a3 - v4) / 2;
+        if ( comparisonResult >= 0 )
+        {
+            startPos += max(((endPos - startPos) / 2), 1);
+        }
+        else{
+            endPos = max(((endPos - startPos) / 2), 1) + startPos;
+        }
     }
-    else
-    {
-      if ( a2a <= 4 )
-      {
-        while ( v4 < a3 )
-        {
-          if ( !_strcmpi(pSpriteName, v5->pSpritePFrames[v4]->pIconName) )
-            goto LABEL_19;
-          ++v4;
-        }
-        break;
-      }
-      a3 = (a3 - v4) / 2 + v4;
-    }
-  }
-  v5->field_8 = -1;
 }
 
 //----- (0044D8D0) --------------------------------------------------------