add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
authornemo
Wed, 29 Dec 2010 16:21:30 -0500
changeset 4780 8571151411b3
parent 4778 1565a553d200
child 4782 603916ddf4b6
add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
hedgewars/uGears.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
hedgewars/uVisualGears.pas
misc/hedgewars.desktop
share/hedgewars/Data/misc/hedgewars-mimeinfo.xml
--- a/hedgewars/uGears.pas	Wed Dec 29 17:27:33 2010 +0100
+++ b/hedgewars/uGears.pas	Wed Dec 29 16:21:30 2010 -0500
@@ -595,6 +595,7 @@
 
 if CurAmmoGear = Gear then CurAmmoGear:= nil;
 if FollowGear = Gear then FollowGear:= nil;
+if lastGearByUID = Gear then lastGearByUID := nil;
 RemoveGearFromList(Gear);
 Dispose(Gear)
 end;
@@ -1778,13 +1779,20 @@
 var gear: PGear;
 begin
 GearByUID:= nil;
+if uid = 0 then exit;
+if (lastGearByUID <> nil) and (lastGearByUID^.uid = uid) then
+    begin
+    GearByUID:= lastGearByUID;
+    exit
+    end;
 gear:= GearsList;
 while gear <> nil do
     begin
     if gear^.uid = uid then
         begin
-            GearByUID:= gear;
-            exit
+        lastGearByUID:= gear;
+        GearByUID:= gear;
+        exit
         end;
     gear:= gear^.NextGear
     end
--- a/hedgewars/uScript.pas	Wed Dec 29 17:27:33 2010 +0100
+++ b/hedgewars/uScript.pas	Wed Dec 29 16:21:30 2010 -0500
@@ -272,6 +272,7 @@
         t:= lua_tointeger(L, 7);
 
         gear:= AddGear(x, y, gt, s, dx, dy, t);
+        lastGearByUID:= gear;
         lua_pushinteger(L, gear^.uid)
         end;
     lc_addgear:= 1; // 1 return value
@@ -311,8 +312,12 @@
         s:= lua_tointeger(L, 4);
         c:= lua_toboolean(L, 5);
 
-        vg:= AddVisualGear(x, y, vgt, s, c); 
-        if vg <> nil then lua_pushinteger(L, vg^.uid)
+        vg:= AddVisualGear(x, y, vgt, s, c);
+        if vg <> nil then 
+            begin
+            lastVisualGearByUID:= vg;
+            lua_pushinteger(L, vg^.uid)
+            end
         else lua_pushinteger(L, 0)
         end;
     lc_addvisualgear:= 1; // 1 return value
--- a/hedgewars/uVariables.pas	Wed Dec 29 17:27:33 2010 +0100
+++ b/hedgewars/uVariables.pas	Wed Dec 29 16:21:30 2010 -0500
@@ -2040,6 +2040,7 @@
     LandBackSurface: PSDL_Surface;
     digest: shortstring;
     CurAmmoGear: PGear;
+    lastGearByUID: PGear;
     GearsList: PGear;
     AllInactive: boolean;
     PrvInactive: boolean;
@@ -2097,6 +2098,7 @@
 
 
     VisualGearsList: PVisualGear;
+    lastVisualGearByUID: PVisualGear;
     vobFrameTicks, vobFramesCount, vobCount: Longword;
     vobVelocity, vobFallSpeed: LongInt;
 
@@ -2153,6 +2155,9 @@
 
 procedure initModule;
 begin
+    lastVisualGearByUID:= nil;
+    lastGearByUID:= nil;
+    
     Pathz:= cPathz;
         {*  REFERENCE
       4096 -> $FFFFF000
@@ -2160,19 +2165,19 @@
       1024 -> $FFFFFC00
        512 -> $FFFFFE00  *}
     if (cReducedQuality and rqLowRes) <> 0 then
-    begin
+        begin
         LAND_WIDTH:= 2048;
         LAND_HEIGHT:= 1024;
         LAND_WIDTH_MASK:= $FFFFF800;
         LAND_HEIGHT_MASK:= $FFFFFC00;
-    end
+        end
     else
-    begin
+        begin
         LAND_WIDTH:= 4096;
         LAND_HEIGHT:= 2048;
         LAND_WIDTH_MASK:= $FFFFF000;
         LAND_HEIGHT_MASK:= $FFFFF800
-    end;
+        end;
 
     SDWaterColorArray[0].r := 184;
     SDWaterColorArray[0].g := 152;
--- a/hedgewars/uVisualGears.pas	Wed Dec 29 17:27:33 2010 +0100
+++ b/hedgewars/uVisualGears.pas	Wed Dec 29 16:21:30 2010 -0500
@@ -328,6 +328,8 @@
     if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear
     else VisualGearsList:= Gear^.NextGear;
 
+    if lastVisualGearByUID = Gear then lastVisualGearByUID:= nil;
+
     Dispose(Gear);
 end;
 
@@ -524,13 +526,20 @@
 var vg: PVisualGear;
 begin
 VisualGearByUID:= nil;
+if uid = 0 then exit;
+if (lastVisualGearByUID <> nil) and (lastVisualGearByUID^.uid = uid) then
+    begin
+    VisualGearByUID:= lastVisualGearByUID;
+    exit
+    end;
 vg:= VisualGearsList;
 while vg <> nil do
     begin
     if vg^.uid = uid then
         begin
-            VisualGearByUID:= vg;
-            exit
+        lastVisualGearByUID:= vg;
+        VisualGearByUID:= vg;
+        exit
         end;
     vg:= vg^.NextGear
     end
--- a/misc/hedgewars.desktop	Wed Dec 29 17:27:33 2010 +0100
+++ b/misc/hedgewars.desktop	Wed Dec 29 16:21:30 2010 -0500
@@ -12,6 +12,7 @@
 GenericName[es]=Batallas entre erizos
 GenericName[it]=Ricci combattenti
 GenericName[pt]=Batalhas entre ouriços
+GenericName[ko]=고슴도치 싸우기
 Icon=hedgewars.png
 Exec=hedgewars
 Terminal=false
--- a/share/hedgewars/Data/misc/hedgewars-mimeinfo.xml	Wed Dec 29 17:27:33 2010 +0100
+++ b/share/hedgewars/Data/misc/hedgewars-mimeinfo.xml	Wed Dec 29 16:21:30 2010 -0500
@@ -15,6 +15,7 @@
     <comment xml:lang="es">Demo de Hedgewars</comment>
     <comment xml:lang="it">Demo di Hedgewars</comment>
 	<comment xml:lang="pt">Hedgewars Demo</comment>
+	<comment xml:lang="ko">헤즈와스 데모</comment>
     <magic priority="50">
       <match required="yes" type="byte" offset="0" value="2"/>
       <match required="yes" type="big16" offset="1" value="21572"/>
@@ -32,6 +33,7 @@
     <comment xml:lang="es">Partida guardada de Hedgewars</comment>
     <comment xml:lang="it">Partita salvata di Hedgewars</comment>
 	<comment xml:lang="pt">Partida guardada de Hedgewars</comment>
+	<comment xml:lang="ko">헤즈와스 저장된 게임</comment>
     <magic priority="50">
       <match required="yes" type="byte" offset="0" value="2"/>
       <match required="yes" type="big16" offset="1" value="21587"/>