--- a/hedgewars/hwengine.pas Sun Oct 28 04:00:07 2012 +0100
+++ b/hedgewars/hwengine.pas Sun Oct 28 04:28:39 2012 +0100
@@ -50,7 +50,7 @@
procedure freeEverything(complete:boolean); forward;
{$ENDIF}
-////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
function DoTimer(Lag: LongInt): boolean;
var s: shortstring;
begin
@@ -61,9 +61,9 @@
gsLandGen:
begin
GenMap;
- uLandTexture.initModule;
- UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT, false);
- uAILandMarks.initModule;
+ SetLandTexture;
+ UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT, false);
+ setAILandMarks;
ParseCommand('sendlanddigest', true);
GameState:= gsStart;
end;
@@ -138,7 +138,7 @@
end;
end;
-///////////////////
+////////////////////////////////////////////////////////////////////////////////
procedure MainLoop;
var event: TSDL_Event;
PrevTime, CurrTime: Longword;
@@ -310,7 +310,7 @@
end;
{$ENDIF}
-///////////////
+////////////////////////////////////////////////////////////////////////////////
procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF};
var p: TPathType;
s: shortstring;
@@ -443,40 +443,42 @@
freeEverything(true);
end;
+////////////////////////////////////////////////////////////////////////////////
+// As a rule of thumb, every module that is listed in either initEverything or
+// freeEverything should come in pair, even if they are stubs. Only use this
+// section for inialising variables and remeber that game args overwrite these,
+// so handle this section with care. Pay attention to the init/free order too!
procedure initEverything (complete:boolean);
begin
Randomize();
- uUtils.initModule(complete); // this opens the debug file, must be the first
- uMisc.initModule;
- uVariables.initModule;
- uConsole.initModule;
- uCommands.initModule;
- uCommandHandlers.initModule;
+ uUtils.initModule(complete); // opens the debug file, must be the first
+ uVariables.initModule; // inits all global variables
+ uConsole.initModule; // opens stdout
+ uCommands.initModule; // helps below
+ uCommandHandlers.initModule; // registers all messages from frontend
- uLand.initModule;
- uLandPainted.initModule;
- uIO.initModule;
+ uLand.initModule; // computes land
+ uLandPainted.initModule; // computes drawn land
+ uIO.initModule; // sets up sockets
if complete then
begin
-{$IFDEF ANDROID}GLUnit.init;{$ENDIF}
+{$IFDEF ANDROID}GLUnit.initModule;{$ENDIF}
{$IFDEF USE_TOUCH_INTERFACE}uTouch.initModule;{$ENDIF}
+{$IFDEF USE_VIDEO_RECORDING}uVideoRec.initModule;{$ENDIF} //stub
uAI.initModule;
- //uAIActions does not need initialization
- //uAIAmmoTests does not need initialization
uAIMisc.initModule;
+ uAILandMarks.initModule; //stub
uAmmos.initModule;
+ uCaptions.initModule;
+
uChat.initModule;
uCollisions.initModule;
- //uFloat does not need initialization
- //uGame does not need initialization
uGears.initModule;
- uInputHandler.initModule;
- //uLandGraphics does not need initialization
- //uLandObjects does not need initialization
- //uLandTemplates does not need initialization
- //uLocale does not need initialization
+ uInputHandler.initModule; //stub
+ uMisc.initModule;
+ uLandTexture.initModule; //stub
uScript.initModule;
uSound.initModule;
uStats.initModule;
@@ -484,7 +486,6 @@
uTeams.initModule;
uVisualGears.initModule;
uWorld.initModule;
- uCaptions.initModule;
end;
end;
@@ -493,9 +494,9 @@
if complete then
begin
WriteLnToConsole('Freeing resources...');
- uAI.freeModule;
+ uAI.freeModule; // AI things need to be freed first
+ uAIMisc.freeModule; //stub
uAILandMarks.freeModule;
- uAIMisc.freeModule; //stub
uCaptions.freeModule;
uWorld.freeModule;
uVisualGears.freeModule;
@@ -504,22 +505,16 @@
uStats.freeModule; //stub
uSound.freeModule;
uScript.freeModule;
- //uRandom does not need to be freed
- //uLocale does not need to be freed
- //uLandTemplates does not need to be freed
+ uMisc.freeModule;
uLandTexture.freeModule;
- //uLandObjects does not need to be freed
- //uLandGraphics does not need to be freed
uGears.freeModule;
- //uGame does not need to be freed
- //uFloat does not need to be freed
uCollisions.freeModule; //stub
uChat.freeModule;
uAmmos.freeModule;
- //uAIAmmoTests does not need to be freed
- //uAIActions does not need to be freed
- uStore.freeModule;
+ uStore.freeModule; // closes SDL
{$IFDEF USE_VIDEO_RECORDING}uVideoRec.freeModule;{$ENDIF}
+{$IFDEF USE_TOUCH_INTERFACE}uTouch.freeModule;{$ENDIF} //stub
+{$IFDEF ANDROID}GLUnit.freeModule;{$ENDIF}
end;
uIO.freeModule;
@@ -528,13 +523,12 @@
uCommandHandlers.freeModule;
uCommands.freeModule;
- uConsole.freeModule;
+ uConsole.freeModule; // closes stdout
uVariables.freeModule;
- uUtils.freeModule;
- uMisc.freeModule; // uMisc closes the debug log.
+ uUtils.freeModule; // closes debug file
end;
-/////////////////////////
+////////////////////////////////////////////////////////////////////////////////
procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
var Preview: TPreview;
begin
@@ -557,7 +551,7 @@
end;
{$IFNDEF HWLIBRARY}
-/////////////////////
+////////////////////////////////////////////////////////////////////////////////
procedure DisplayUsage;
var i: LongInt;
begin
@@ -583,7 +577,7 @@
WriteLn(stdout, '');
end;
-////////////////////
+////////////////////////////////////////////////////////////////////////////////
{$INCLUDE "ArgParsers.inc"}
procedure GetParams;