Free up some unfreed memory. Needed for Koda's iphone lib work
authornemo
Tue, 26 Jan 2010 04:13:37 +0000
changeset 2715 0e4e0db79e2a
parent 2714 c85ffe57d971
child 2716 b9ca1bfca24f
Free up some unfreed memory. Needed for Koda's iphone lib work
hedgewars/hwengine.pas
hedgewars/uAmmos.pas
hedgewars/uConsts.pas
hedgewars/uMisc.pas
hedgewars/uTeams.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/hwengine.pas	Sun Jan 24 19:52:30 2010 +0000
+++ b/hedgewars/hwengine.pas	Tue Jan 26 04:13:37 2010 +0000
@@ -325,8 +325,9 @@
 	free_uConsole();
 	free_uMisc();
 	free_uTeams();
+	free_uAmmos();
 	free_uGears();
-	//free_uVisualGears(); not necessary
+	free_uVisualGears();
 	free_uLand();
 	//free_uWorld(); not necessary
 
--- a/hedgewars/uAmmos.pas	Sun Jan 24 19:52:30 2010 +0000
+++ b/hedgewars/uAmmos.pas	Tue Jan 26 04:13:37 2010 +0000
@@ -22,6 +22,7 @@
 interface
 uses uConsts, uTeams;
 
+procedure free_uAmmos;
 procedure AddAmmoStore(s: shortstring);
 procedure AssignStores;
 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
@@ -316,4 +317,11 @@
 	if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0
 end;
 
+procedure free_uAmmos;
+var i: LongWord;
+begin
+for i:= 0 to Pred(StoreCnt) do Dispose(StoresList[i]);
+StoreCnt:= 0
+end;
+
 end.
--- a/hedgewars/uConsts.pas	Sun Jan 24 19:52:30 2010 +0000
+++ b/hedgewars/uConsts.pas	Tue Jan 26 04:13:37 2010 +0000
@@ -152,13 +152,14 @@
 		X, Y: GLint;
 		end;
 
+	PTexture = ^TTexture;
 	TTexture = record
 			id: GLuint;
 			w, h: LongInt;
 			rx, ry: GLfloat;
 			vb, tb: array [0..3] of TVertex2f;
+            PrevTexture, NextTexture: PTexture;
 			end;
-	PTexture = ^TTexture;
 
 const
 	// message constants
--- a/hedgewars/uMisc.pas	Sun Jan 24 19:52:30 2010 +0000
+++ b/hedgewars/uMisc.pas	Tue Jan 26 04:13:37 2010 +0000
@@ -120,6 +120,8 @@
 	CursorPoint	: TPoint;
 	TargetPoint	: TPoint;
 
+    TextureList : PTexture;
+
 
 procedure init_uMisc;
 procedure free_uMisc;
@@ -348,6 +350,15 @@
 function NewTexture(width, height: Longword; buf: Pointer): PTexture;
 begin
 new(NewTexture);
+NewTexture^.PrevTexture:= nil;
+NewTexture^.NextTexture:= nil;
+if TextureList <> nil then
+    begin
+    TextureList^.PrevTexture:= NewTexture;
+    NewTexture^.NextTexture:= TextureList
+    end;
+TextureList:= NewTexture;
+
 NewTexture^.w:= width;
 NewTexture^.h:= height;
 NewTexture^.rx:= 1.0;
@@ -369,6 +380,15 @@
     fromP4, toP4: PLongWordArray;
 begin
 new(Surface2Tex);
+Surface2Tex^.PrevTexture:= nil;
+Surface2Tex^.NextTexture:= nil;
+if TextureList <> nil then
+    begin
+    TextureList^.PrevTexture:= Surface2Tex;
+    Surface2Tex^.NextTexture:= TextureList
+    end;
+TextureList:= Surface2Tex;
+
 Surface2Tex^.w:= surf^.w;
 Surface2Tex^.h:= surf^.h;
 
@@ -437,8 +457,11 @@
 begin
 if tex <> nil then
 	begin
+    if tex^.NextTexture <> nil then tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
+    if tex^.PrevTexture <> nil then tex^.PrevTexture^.NextTexture:= tex^.NextTexture
+       else TextureList:= tex^.NextTexture;
 	glDeleteTextures(1, @tex^.id);
-	dispose(tex)
+	Dispose(tex)
 	end
 end;
 
@@ -555,9 +578,10 @@
 	cDrownSpeed.QWordValue	:= 257698038;		// 0.06
 	cMaxWindSpeed.QWordValue:= 2147484;		// 0.0005
 	cWindSpeed.QWordValue	:= 429496;		// 0.0001
-	cGravity		:= cMaxWindSpeed;
-	cDamageModifier		:= _1;
-	TargetPoint		:= cTargetPointRef;
+	cGravity                := cMaxWindSpeed;
+	cDamageModifier         := _1;
+	TargetPoint             := cTargetPointRef;
+    TextureList             := nil;
 	
 	// int, longint longword and byte
 	CursorMovementX		:= 0;
@@ -665,6 +689,7 @@
 
 procedure free_uMisc;
 begin
+while TextureList <> nil do FreeTexture(TextureList);
 //uRandom.DumpBuffer;
 
 {$IFDEF DEBUGFILE}
--- a/hedgewars/uTeams.pas	Sun Jan 24 19:52:30 2010 +0000
+++ b/hedgewars/uTeams.pas	Tue Jan 26 04:13:37 2010 +0000
@@ -114,8 +114,6 @@
 uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat;
 const MaxTeamHealth: LongInt = 0;
 
-procedure FreeTeamsList; forward;
-
 function CheckForWin: boolean;
 var AliveClan: PClan;
     s: shortstring;
@@ -292,13 +290,6 @@
 AddTeam:= team;
 end;
 
-procedure FreeTeamsList;
-var t: LongInt;
-begin
-for t:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[t]);
-TeamsCount:= 0
-end;
-
 procedure RecountAllTeamsHealth;
 var t: LongInt;
 begin
@@ -415,8 +406,12 @@
 end;
 
 procedure free_uTeams;
+var i: LongWord;
 begin
-	FreeTeamsList()
+   for i:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[i]);
+   for i:= 0 to Pred(ClansCount) do Dispose(ClansArray[i]);
+   TeamsCount:= 0;
+   ClansCount:= 0
 end;
 
 end.
--- a/hedgewars/uVisualGears.pas	Sun Jan 24 19:52:30 2010 +0000
+++ b/hedgewars/uVisualGears.pas	Tue Jan 26 04:13:37 2010 +0000
@@ -48,6 +48,7 @@
 		end;
 
 procedure init_uVisualGears;
+procedure free_uVisualGears;
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;
 procedure ProcessVisualGears(Steps: Longword);
 procedure DrawVisualGears(Layer: LongWord);
@@ -558,5 +559,9 @@
 	VisualGearsList:= nil;
 end;
 
+procedure free_uVisualGears;
+begin
+while VisualGearsList <> nil do DeleteVisualGear(VisualGearsList);
+end;
 
 end.