hedgewars/hwengine.pas
changeset 2699 249adefa9c1c
parent 2698 90585aba87ad
child 2702 48fc46a922fd
equal deleted inserted replaced
2698:90585aba87ad 2699:249adefa9c1c
    51 	uAmmos in 'uAmmos.pas',
    51 	uAmmos in 'uAmmos.pas',
    52 	uSHA in 'uSHA.pas',
    52 	uSHA in 'uSHA.pas',
    53 	uFloat in 'uFloat.pas',
    53 	uFloat in 'uFloat.pas',
    54 	uStats in 'uStats.pas',
    54 	uStats in 'uStats.pas',
    55 	uChat in 'uChat.pas',
    55 	uChat in 'uChat.pas',
       
    56 	uTriggers in 'uTriggers.pas',
    56 	uLandTexture in 'uLandTexture.pas'
    57 	uLandTexture in 'uLandTexture.pas'
    57 	{$IFDEF IPHONEOS}
    58 	{$IFDEF IPHONEOS}
    58 	, PascalExports in 'PascalExports.pas'
    59 	, PascalExports in 'PascalExports.pas'
    59 	{$ENDIF}
    60 	{$ENDIF}
    60 	;
    61 	;
    69 procedure DoTimer(Lag: LongInt);
    70 procedure DoTimer(Lag: LongInt);
    70 procedure OnDestroy;
    71 procedure OnDestroy;
    71 procedure MainLoop;
    72 procedure MainLoop;
    72 procedure ShowMainWindow;
    73 procedure ShowMainWindow;
    73 procedure Game; cdecl; export;
    74 procedure Game; cdecl; export;
       
    75 procedure initEverything;
       
    76 procedure freeEverything;
    74 
    77 
    75 implementation
    78 implementation
    76 
    79 
    77 {$ELSE}
    80 {$ELSE}
    78 procedure OnDestroy; forward;
    81 procedure OnDestroy; forward;
       
    82 procedure freeEverything; forward;
    79 {$ENDIF}
    83 {$ENDIF}
    80 
    84 
    81 ////////////////////////////////
    85 ////////////////////////////////
    82 procedure DoTimer(Lag: LongInt);
    86 procedure DoTimer(Lag: LongInt);
    83 {$IFNDEF IPHONEOS}
    87 {$IFNDEF IPHONEOS}
   149 	StoreRelease();
   153 	StoreRelease();
   150 	FreeLand();
   154 	FreeLand();
   151 	ControllerClose();
   155 	ControllerClose();
   152 	SendKB();
   156 	SendKB();
   153 	CloseIPC();
   157 	CloseIPC();
       
   158 	freeEverything();
   154 	TTF_Quit();
   159 	TTF_Quit();
       
   160 	{$IFDEF SDL13}SDL_VideoQuit();{$ENDIF}
   155 	SDL_Quit();
   161 	SDL_Quit();
   156 	exit();
   162 	exit();
   157 end;
   163 end;
   158 
   164 
   159 ///////////////////
   165 ///////////////////
   213 procedure Game;{$IFDEF IPHONEOS}cdecl; export;{$ENDIF}
   219 procedure Game;{$IFDEF IPHONEOS}cdecl; export;{$ENDIF}
   214 var	p: TPathType;
   220 var	p: TPathType;
   215 	s: shortstring;
   221 	s: shortstring;
   216 begin
   222 begin
   217 {$IFDEF IPHONEOS}
   223 {$IFDEF IPHONEOS}
   218 	Randomize;
   224 	initEverything();
       
   225 	Randomize();
   219 
   226 
   220 	val('320', cScreenWidth);
   227 	val('320', cScreenWidth);
   221 	val('480', cScreenHeight);
   228 	val('480', cScreenHeight);
   222 	cInitWidth:= cScreenWidth;
   229 	cInitWidth:= cScreenWidth;
   223 	cInitHeight:= cScreenHeight;
   230 	cInitHeight:= cScreenHeight;
   287 	MainLoop();
   294 	MainLoop();
   288 	OnDestroy();
   295 	OnDestroy();
   289 	exit();
   296 	exit();
   290 end;
   297 end;
   291 
   298 
       
   299 procedure initEverything;
       
   300 begin
       
   301 	init_uConsts();
       
   302 	init_uMisc();
       
   303 	init_uConsole();	// MUST happen after uMisc
       
   304 	init_uStore();
       
   305 	init_uTeams();
       
   306 	init_uGears();
       
   307 	init_uVisualGears();
       
   308 	init_uLand();
       
   309 	init_uIO();
       
   310 	init_uWorld();
       
   311 	init_uRandom;
       
   312 	init_uTriggers;
       
   313 
       
   314 end;
       
   315 
       
   316 procedure freeEverything;
       
   317 begin
       
   318 	//free_uConts(); not necessary
       
   319 	free_uConsole();
       
   320 	free_uMisc();
       
   321 	free_uTeams();
       
   322 	free_uGears();
       
   323 	//free_uVisualGears(); not necessary
       
   324 	free_uLand();
       
   325 	//free_uWorld(); not necessary
       
   326 
       
   327 end;
   292 {$IFNDEF IPHONEOS}
   328 {$IFNDEF IPHONEOS}
   293 /////////////////////////
   329 /////////////////////////
   294 procedure GenLandPreview;
   330 procedure GenLandPreview;
   295 var Preview: TPreview;
   331 var Preview: TPreview;
   296 	h: byte;
   332     h: byte;
   297 begin
   333 begin
   298 	InitIPC;
   334 	InitIPC;
   299 	IPCWaitPongEvent;
   335 	IPCWaitPongEvent;
   300 	TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   336 	TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   301 
   337 
   342 	halt(1);
   378 	halt(1);
   343 end;
   379 end;
   344 
   380 
   345 ////////////////////
   381 ////////////////////
   346 procedure GetParams;
   382 procedure GetParams;
   347 var
       
   348 {$IFDEF DEBUGFILE}
   383 {$IFDEF DEBUGFILE}
   349     i: LongInt;
   384 var i: LongInt;
   350 {$ENDIF}
   385 {$ENDIF}
   351     p: TPathType;
       
   352 begin
   386 begin
   353 
   387 
   354 	case ParamCount of
   388 	case ParamCount of
   355 		17: begin
   389 		17: begin
   356 			val(ParamStr(2), cScreenWidth);
   390 			val(ParamStr(2), cScreenWidth);
   474 ////////////////////////////////////////////////////////////////////////////////
   508 ////////////////////////////////////////////////////////////////////////////////
   475 /////////////////////////////// m a i n ////////////////////////////////////////
   509 /////////////////////////////// m a i n ////////////////////////////////////////
   476 ////////////////////////////////////////////////////////////////////////////////
   510 ////////////////////////////////////////////////////////////////////////////////
   477 
   511 
   478 begin
   512 begin
       
   513 	initEverything();
   479 	WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   514 	WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   480 	GetParams;
   515 	
   481 
   516 	GetParams();
   482 	Randomize;
   517 	Randomize();
   483 
   518 
   484 	if GameType = gmtLandPreview	then GenLandPreview
   519 	if GameType = gmtLandPreview then GenLandPreview()
   485 					else Game;
   520 	else Game();
   486 //	ExitCode := 100;
   521 	ExitCode := 0;
   487 {$ENDIF}
   522 {$ENDIF}
   488 
       
   489 end.
   523 end.
   490