hedgewars/hwengine.pas
changeset 2716 b9ca1bfca24f
parent 2715 0e4e0db79e2a
child 2717 2b75ef82676d
equal deleted inserted replaced
2715:0e4e0db79e2a 2716:b9ca1bfca24f
   131 				isTerminated:= true;
   131 				isTerminated:= true;
   132 				end;
   132 				end;
   133 		end;
   133 		end;
   134 
   134 
   135 	SDL_GL_SwapBuffers();
   135 	SDL_GL_SwapBuffers();
       
   136 {$IFDEF SDL13}
       
   137 	SDL_RenderPresent();
       
   138 {$ENDIF}
   136 {$IFNDEF IPHONEOS}
   139 {$IFNDEF IPHONEOS}
   137 	// not going to make captures on the iPhone
   140 	// not going to make captures on the iPhone
   138 	if flagMakeCapture then
   141 	if flagMakeCapture then
   139 	begin
   142 	begin
   140 		flagMakeCapture:= false;
   143 		flagMakeCapture:= false;
   154 	StoreRelease();
   157 	StoreRelease();
   155 	FreeLand();
   158 	FreeLand();
   156 	ControllerClose();
   159 	ControllerClose();
   157 	SendKB();
   160 	SendKB();
   158 	CloseIPC();
   161 	CloseIPC();
   159 	freeEverything();
       
   160 	TTF_Quit();
   162 	TTF_Quit();
   161 	{$IFDEF SDL13}SDL_VideoQuit();{$ENDIF}
   163 	{$IFDEF SDL13}SDL_VideoQuit();{$ENDIF}
   162 	SDL_Quit();
   164 	SDL_Quit();
       
   165 	freeEverything();
   163 	exit();
   166 	exit();
   164 end;
   167 end;
   165 
   168 
   166 ///////////////////
   169 ///////////////////
   167 procedure MainLoop; 
   170 procedure MainLoop; 
   168 var PrevTime,
   171 var PrevTime, CurrTime: Longword;
   169     CurrTime: Longword;
       
   170     {$IFNDEF IPHONEOS}event: TSDL_Event;{$ENDIF}
   172     {$IFNDEF IPHONEOS}event: TSDL_Event;{$ENDIF}
   171 begin
   173 begin
   172 
       
   173 	PrevTime:= SDL_GetTicks;
   174 	PrevTime:= SDL_GetTicks;
   174 	repeat
   175 	repeat
   175 {$IFNDEF IPHONEOS}
   176 {$IFNDEF IPHONEOS}
   176 // have to remove this cycle because otherwise it segfaults at exit
   177 // have to remove this cycle because otherwise it segfaults at exit
   177 		while SDL_PollEvent(@event) <> 0 do
   178 		while SDL_PollEvent(@event) <> 0 do
   233 	val('480', cScreenHeight);
   234 	val('480', cScreenHeight);
   234 	cInitWidth:= cScreenWidth;
   235 	cInitWidth:= cScreenWidth;
   235 	cInitHeight:= cScreenHeight;
   236 	cInitHeight:= cScreenHeight;
   236 	cBitsStr:= '32';
   237 	cBitsStr:= '32';
   237 	val(cBitsStr, cBits);
   238 	val(cBitsStr, cBits);
   238 	cFullScreen:= true;
   239 	cFullScreen:= false;
   239 	cVSyncInUse:= true;
   240 	cVSyncInUse:= true;
   240 	val('8', cTimerInterval);
   241 	val('8', cTimerInterval);
   241 	PathPrefix:= 'Data';
   242 	PathPrefix:= 'Data';
   242 	cReducedQuality:= false;
   243 	cReducedQuality:= false;
   243 	cShowFPS:= true;
   244 	cShowFPS:= true;
   259 	WriteLnToConsole(msgOK);
   260 	WriteLnToConsole(msgOK);
   260 
   261 
   261 	SDL_EnableUNICODE(1);
   262 	SDL_EnableUNICODE(1);
   262 
   263 
   263 	WriteToConsole('Init SDL_ttf... ');
   264 	WriteToConsole('Init SDL_ttf... ');
   264 	SDLTry(TTF_Init <> -1, true);
   265 	SDLTry(TTF_Init() <> -1, true);
   265 	WriteLnToConsole(msgOK);
   266 	WriteLnToConsole(msgOK);
   266 
   267 
   267 	ShowMainWindow;
   268 	ShowMainWindow();
   268 
   269 
   269 	AddProgress;
   270 	AddProgress();
   270 
   271 
   271 	ControllerInit; // has to happen before InitKbdKeyTable to map keys
   272 	ControllerInit(); // has to happen before InitKbdKeyTable to map keys
   272 	InitKbdKeyTable;
   273 	InitKbdKeyTable();
   273 
   274 
   274 	if recordFileName = '' then
   275 	if recordFileName = '' then
   275 		InitIPC;
   276 		InitIPC;
   276 	WriteLnToConsole(msgGettingConfig);
   277 	WriteLnToConsole(msgGettingConfig);
   277 
   278 
   285 		LoadRecordFromFile(recordFileName);
   286 		LoadRecordFromFile(recordFileName);
   286 
   287 
   287 	s:= 'eproto ' + inttostr(cNetProtoVersion);
   288 	s:= 'eproto ' + inttostr(cNetProtoVersion);
   288 	SendIPCRaw(@s[0], Length(s) + 1); // send proto version
   289 	SendIPCRaw(@s[0], Length(s) + 1); // send proto version
   289 
   290 
   290 	InitTeams;
   291 	InitTeams();
   291 	AssignStores;
   292 	AssignStores();
   292 
   293 
   293 	if isSoundEnabled then
   294 	if isSoundEnabled then
   294 		InitSound;
   295 		InitSound();
   295 
   296 
   296 	isDeveloperMode:= false;
   297 	isDeveloperMode:= false;
   297 
   298 
   298 	TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   299 	TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   299 
   300 
   305 procedure initEverything;
   306 procedure initEverything;
   306 begin
   307 begin
   307 	init_uConsts();
   308 	init_uConsts();
   308 	init_uMisc();
   309 	init_uMisc();
   309 	init_uConsole();	// MUST happen after uMisc
   310 	init_uConsole();	// MUST happen after uMisc
       
   311 	
       
   312 	init_uAI();
       
   313 	//uAIActions does not need initialization
       
   314 	//uAIAmmoTests does not need initialization
       
   315 	init_uAIMisc();
       
   316 	init_uAmmos();
       
   317 	init_uChat();
       
   318 	init_uCollisions();
       
   319 	//uFloat does not need initialization
       
   320 	//uGame does not need initialization
       
   321 	init_uGears();
       
   322 	init_uIO();
       
   323 	init_uKeys();
       
   324 	init_uLand();
       
   325 	//uLandGraphics does not need initialization
       
   326 	//uLandObjects does not need initialization
       
   327 	//uLandTemplates does not need initialization
       
   328 	//uLandTexture does not need initialization
       
   329 	//uLocale does not need initialization
       
   330 	init_uRandom();	
       
   331 	//uSHA does not need initialization
       
   332 	init_uSound();
       
   333 	init_uStats();
   310 	init_uStore();
   334 	init_uStore();
   311 	init_uTeams();
   335 	init_uTeams();
   312 	init_uGears();
   336 	init_uTriggers();
   313 	init_uVisualGears();
   337 	init_uVisualGears();
   314 	init_uLand();
       
   315 	init_uIO();
       
   316 	init_uWorld();
   338 	init_uWorld();
   317 	init_uRandom;
       
   318 	init_uTriggers;
       
   319 
       
   320 end;
   339 end;
   321 
   340 
   322 procedure freeEverything;
   341 procedure freeEverything;
   323 begin
   342 begin
   324 	//free_uConts(); not necessary
   343 	free_uWorld();
       
   344 	free_uVisualGears();	//stub
       
   345 	free_uTriggers();	//stub
       
   346 	free_uTeams();
       
   347 	free_uStore();
       
   348 	free_uStats();		//stub
       
   349 	free_uSound();		//stub
       
   350 	//uSHA does not need to be freed
       
   351 	free_uRandom();		//stub
       
   352 	//uLocale does not need to be freed
       
   353 	//uLandTemplates does not need to be freed
       
   354 	//uLandTexture does not need to be freed
       
   355 	//uLandObjects does not need to be freed
       
   356 	//uLandGraphics does not need to be freed
       
   357 	free_uLand();
       
   358 	free_uKeys();		//stub
       
   359 	free_uIO();
       
   360 	free_uGears();
       
   361 	//uGame does not need to be freed
       
   362 	//uFloat does not need to be freed
       
   363 	free_uCollisions();
       
   364 	free_uChat();
       
   365 	free_uAmmos();
       
   366 	free_uAIMisc();		//stub
       
   367 	//uAIAmmoTests does not need to be freed
       
   368 	//uAIActions does not need to be freed
       
   369 	free_uAI();		//stub
       
   370 
   325 	free_uConsole();
   371 	free_uConsole();
   326 	free_uMisc();
   372 	free_uMisc();
   327 	free_uTeams();
   373 	free_uConsts();		//stub
   328 	free_uAmmos();
       
   329 	free_uGears();
       
   330 	free_uVisualGears();
       
   331 	free_uLand();
       
   332 	//free_uWorld(); not necessary
       
   333 
   374 
   334 end;
   375 end;
   335 {$IFNDEF IPHONEOS}
   376 {$IFNDEF IPHONEOS}
   336 /////////////////////////
   377 /////////////////////////
   337 procedure GenLandPreview;
   378 procedure GenLandPreview;
   523 	GetParams();
   564 	GetParams();
   524 	Randomize();
   565 	Randomize();
   525 
   566 
   526 	if GameType = gmtLandPreview then GenLandPreview()
   567 	if GameType = gmtLandPreview then GenLandPreview()
   527 	else Game();
   568 	else Game();
   528 	ExitCode := 0;
   569 	ExitCode:= 0;
   529 {$ENDIF}
   570 {$ENDIF}
   530 end.
   571 end.