PageRenderTime 10ms CodeModel.GetById 16ms app.highlight 306ms RepoModel.GetById 1ms app.codeStats 1ms

/main/main.cpp

https://github.com/Hubich/godot
C++ | 1437 lines | 974 code | 395 blank | 68 comment | 311 complexity | 716678d6488d672c09e1208b4b06a7c7 MD5 | raw file
   1/*************************************************************************/
   2/*  main.cpp                                                             */
   3/*************************************************************************/
   4/*                       This file is part of:                           */
   5/*                           GODOT ENGINE                                */
   6/*                    http://www.godotengine.org                         */
   7/*************************************************************************/
   8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                 */
   9/*                                                                       */
  10/* Permission is hereby granted, free of charge, to any person obtaining */
  11/* a copy of this software and associated documentation files (the       */
  12/* "Software"), to deal in the Software without restriction, including   */
  13/* without limitation the rights to use, copy, modify, merge, publish,   */
  14/* distribute, sublicense, and/or sell copies of the Software, and to    */
  15/* permit persons to whom the Software is furnished to do so, subject to */
  16/* the following conditions:                                             */
  17/*                                                                       */
  18/* The above copyright notice and this permission notice shall be        */
  19/* included in all copies or substantial portions of the Software.       */
  20/*                                                                       */
  21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
  22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
  23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
  25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
  26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
  27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
  28/*************************************************************************/
  29#include "main.h"
  30#include "os/os.h"
  31#include "globals.h"
  32#include "splash.h"
  33#include "core/register_core_types.h"
  34#include "scene/register_scene_types.h"
  35#include "drivers/register_driver_types.h"
  36#include "servers/register_server_types.h"
  37#include "modules/register_module_types.h"
  38#include "script_debugger_local.h"
  39#include "script_debugger_remote.h"
  40#include "message_queue.h"
  41#include "path_remap.h"
  42#include "input_map.h"
  43#include "io/resource_loader.h"
  44#include "scene/main/scene_main_loop.h"
  45
  46#include "scene/io/scene_loader.h"
  47#include "script_language.h"
  48#include "io/resource_loader.h"
  49
  50#include "bin/tests/test_main.h"
  51#include "os/dir_access.h"
  52#include "core/io/ip.h"
  53#include "scene/resources/packed_scene.h"
  54#include "scene/main/viewport.h"
  55
  56#ifdef TOOLS_ENABLED
  57#include "tools/editor/editor_node.h"
  58#include "tools/editor/project_manager.h"
  59#include "tools/editor/console.h"
  60#endif
  61
  62#include "io/file_access_network.h"
  63#include "tools/doc/doc_data.h"
  64
  65
  66#include "servers/spatial_sound_server.h"
  67#include "servers/spatial_sound_2d_server.h"
  68#include "servers/physics_2d_server.h"
  69
  70
  71#include "core/io/stream_peer_tcp.h"
  72#include "core/os/thread.h"
  73#include "core/io/file_access_pack.h"
  74#include "core/io/file_access_zip.h"
  75#include "translation.h"
  76#include "version.h"
  77
  78#include "performance.h"
  79
  80static Globals *globals=NULL;
  81static InputMap *input_map=NULL;
  82static bool _start_success=false;
  83static ScriptDebugger *script_debugger=NULL;
  84
  85static MessageQueue *message_queue=NULL;
  86static Performance *performance = NULL;
  87static PathRemap *path_remap;
  88static PackedData *packed_data=NULL;
  89static FileAccessNetworkClient *file_access_network_client=NULL;
  90static TranslationServer *translation_server = NULL;
  91
  92static OS::VideoMode video_mode;
  93static int video_driver_idx=-1;
  94static int audio_driver_idx=-1;
  95static String locale;
  96
  97static String unescape_cmdline(const String& p_str) {
  98
  99	return p_str.replace("%20"," ");
 100}
 101
 102
 103//#define DEBUG_INIT
 104
 105#ifdef DEBUG_INIT
 106#define MAIN_PRINT(m_txt) print_line(m_txt)
 107#else
 108#define MAIN_PRINT(m_txt)
 109#endif
 110
 111void Main::print_help(const char* p_binary) {
 112
 113	OS::get_singleton()->print(VERSION_FULL_NAME" (c) 2008-2010 Juan Linietsky, Ariel Manzur.\n");
 114	OS::get_singleton()->print("Usage: %s [options] [scene]\n",p_binary);
 115	OS::get_singleton()->print("Options:\n");
 116	OS::get_singleton()->print("\t-path [dir] : Path to a game, containing engine.cfg\n");
 117#ifdef TOOLS_ENABLED
 118	OS::get_singleton()->print("\t-e,-editor : Bring up the editor instead of running the scene.\n");
 119#endif
 120	OS::get_singleton()->print("\t-test [test] : Run a test.\n");
 121	OS::get_singleton()->print("\t\t(");
 122	const char **test_names=tests_get_names();
 123	const char* coma = "";
 124	while(*test_names) {
 125	
 126		OS::get_singleton()->print("%s%s", coma, *test_names);
 127		test_names++;
 128		coma = ", ";
 129	}
 130	OS::get_singleton()->print(")\n");
 131	
 132	OS::get_singleton()->print("\t-r WIDTHxHEIGHT\t : Request Screen Resolution\n");
 133	OS::get_singleton()->print("\t-f\t\t : Request Fullscreen\n");
 134	OS::get_singleton()->print("\t-vd DRIVER\t : Video Driver (");
 135	for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) {
 136		
 137		if (i!=0)
 138			OS::get_singleton()->print(", ");
 139		OS::get_singleton()->print("%s",OS::get_singleton()->get_video_driver_name(i));
 140	}
 141	OS::get_singleton()->print(")\n");
 142	OS::get_singleton()->print("\t-ad DRIVER\t : Audio Driver (");
 143	for (int i=0;i<OS::get_singleton()->get_audio_driver_count();i++) {
 144		
 145		if (i!=0)
 146			OS::get_singleton()->print(", ");
 147		OS::get_singleton()->print("%s",OS::get_singleton()->get_audio_driver_name(i));
 148	}
 149	OS::get_singleton()->print("\t-rthread <mode>\t : Render Thread Mode ('unsafe', 'safe', 'separate).");
 150	OS::get_singleton()->print(")\n");
 151	OS::get_singleton()->print("\t-s,-script [script] : Run a script.\n");	
 152	OS::get_singleton()->print("\t-d,-debug : Debug (local stdout debugger).\n");
 153	OS::get_singleton()->print("\t-rdebug ADDRESS : Remote debug (<ip>:<port> host address).\n");
 154	OS::get_singleton()->print("\t-fdelay [msec]: Simulate high CPU load (delay each frame by [msec]).\n");
 155	OS::get_singleton()->print("\t-bp : breakpoint list as source::line comma separated pairs, no spaces (%%20,%%2C,etc instead).\n");
 156	OS::get_singleton()->print("\t-v : Verbose stdout mode\n");
 157	OS::get_singleton()->print("\t-lang [locale]: Use a specific locale\n");
 158	OS::get_singleton()->print("\t-rfs <host/ip>[:<port>] : Remote FileSystem.\n");
 159	OS::get_singleton()->print("\t-rfs_pass <password> : Password for Remote FileSystem.\n");
 160#ifdef TOOLS_ENABLED
 161	OS::get_singleton()->print("\t-doctool FILE: Dump the whole engine api to FILE in XML format. If FILE exists, it will be merged.\n");
 162	OS::get_singleton()->print("\t-nodocbase: Disallow dump the base types (used with -doctool).\n");
 163	OS::get_singleton()->print("\t-optimize FILE Save an optimized copy of scene to FILE.\n");
 164	OS::get_singleton()->print("\t-optimize_preset [preset] Use a given preset for optimization.\n");
 165	OS::get_singleton()->print("\t-export [target] Export the project using given export target.\n");
 166#endif
 167}
 168
 169
 170Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phase) {
 171
 172	RID_OwnerBase::init_rid();
 173
 174	OS::get_singleton()->initialize_core();
 175	ObjectTypeDB::init();
 176
 177	MAIN_PRINT("Main: Initialize CORE");
 178
 179	register_core_types();
 180	register_core_driver_types();
 181
 182	MAIN_PRINT("Main: Initialize Globals");
 183
 184
 185	Thread::_main_thread_id = Thread::get_caller_ID();
 186
 187	globals = memnew( Globals );
 188	input_map = memnew( InputMap );
 189
 190
 191	path_remap = memnew( PathRemap );
 192	translation_server = memnew( TranslationServer );
 193	performance = memnew( Performance );
 194	globals->add_singleton(Globals::Singleton("Performance",performance));
 195
 196	MAIN_PRINT("Main: Parse CMDLine");
 197
 198	/* argument parsing and main creation */
 199	List<String> args;
 200	List<String> main_args;
 201	
 202	for(int i=0;i<argc;i++) {
 203
 204		args.push_back(String::utf8(argv[i]));
 205	}
 206
 207	List<String>::Element *I=args.front();
 208
 209	I=args.front();
 210
 211	while (I) {
 212
 213		I->get()=unescape_cmdline(I->get().strip_escapes());
 214		I=I->next();
 215	}
 216
 217	I=args.front();
 218	
 219	video_mode = OS::get_singleton()->get_default_video_mode();
 220
 221	String video_driver="";
 222	String audio_driver="";
 223	String game_path=".";
 224	String debug_mode;
 225	String debug_host;
 226	int rtm=-1;
 227
 228	String remotefs;
 229	String remotefs_pass;
 230
 231	String screen = "";
 232
 233	List<String> pack_list;
 234	Vector<String> breakpoints;
 235	bool use_custom_res=true;
 236	bool force_res=false;
 237
 238	I=args.front();
 239
 240    packed_data = PackedData::get_singleton();
 241    if (!packed_data)
 242        packed_data = memnew(PackedData);
 243
 244#ifdef MINIZIP_ENABLED
 245	packed_data->add_pack_source(ZipArchive::get_singleton());
 246#endif
 247
 248	bool editor=false;
 249
 250	while(I) {
 251
 252		List<String>::Element *N=I->next();
 253
 254		if (I->get() == "-noop") {
 255
 256			// no op
 257		} else if (I->get()=="-h" || I->get()=="--help" || I->get()=="/?") { // resolution
 258			
 259			goto error;
 260			
 261			
 262		} else if (I->get()=="-r") { // resolution
 263		
 264			if (I->next()) {
 265			
 266				String vm=I->next()->get();
 267				
 268				if (vm.find("x")==-1) { // invalid parameter format
 269				
 270					goto error;
 271					
 272				
 273				}
 274				
 275				int w=vm.get_slice("x",0).to_int();
 276				int h=vm.get_slice("x",1).to_int();
 277				
 278				if (w==0 || h==0) {
 279				
 280					goto error;
 281					
 282				}
 283				
 284				video_mode.width=w;
 285				video_mode.height=h;
 286				force_res=true;
 287				
 288				N=I->next()->next();
 289			} else {
 290				goto error;
 291				
 292			
 293			}
 294			
 295		} else if (I->get()=="-vd") { // video driver
 296		
 297			if (I->next()) {
 298			
 299				video_driver=I->next()->get();
 300				N=I->next()->next();
 301			} else {
 302				goto error;
 303				
 304			}
 305		} else if (I->get()=="-lang") { // language
 306
 307			if (I->next()) {
 308
 309				locale=I->next()->get();
 310				N=I->next()->next();
 311			} else {
 312				goto error;
 313
 314			}
 315		} else if (I->get()=="-rfs") { // language
 316
 317			if (I->next()) {
 318
 319				remotefs=I->next()->get();
 320				N=I->next()->next();
 321			} else {
 322				goto error;
 323
 324			}
 325		} else if (I->get()=="-rfs_pass") { // language
 326
 327			if (I->next()) {
 328
 329				remotefs_pass=I->next()->get();
 330				N=I->next()->next();
 331			} else {
 332				goto error;
 333
 334			}
 335		} else if (I->get()=="-rthread") { // language
 336
 337			if (I->next()) {
 338
 339				if (I->next()->get()=="safe")
 340					rtm=OS::RENDER_THREAD_SAFE;
 341				else if (I->next()->get()=="unsafe")
 342					rtm=OS::RENDER_THREAD_UNSAFE;
 343				else if (I->next()->get()=="separate")
 344					rtm=OS::RENDER_SEPARATE_THREAD;
 345
 346
 347				N=I->next()->next();
 348			} else {
 349				goto error;
 350
 351			}
 352
 353		} else if (I->get()=="-ad") { // video driver
 354		
 355			if (I->next()) {
 356			
 357				audio_driver=I->next()->get();
 358				N=I->next()->next();
 359			} else {
 360				goto error;
 361				
 362			}
 363			
 364		} else if (I->get()=="-f") { // fullscreen
 365		
 366			video_mode.fullscreen=true;
 367		} else if (I->get()=="-e" || I->get()=="-editor") { // fonud editor
 368
 369			editor=true;
 370
 371		} else if (I->get()=="-nowindow") { // fullscreen
 372
 373			OS::get_singleton()->set_no_window_mode(true);
 374		} else if (I->get()=="-v") { // fullscreen
 375			OS::get_singleton()->_verbose_stdout=true;
 376		} else if (I->get()=="-path") { // resolution
 377		
 378			if (I->next()) {
 379			
 380				String p = I->next()->get();
 381				if (OS::get_singleton()->set_cwd(p)==OK) {
 382					//nothing
 383				} else {
 384					game_path=I->next()->get(); //use game_path instead
 385				}
 386
 387				N=I->next()->next();
 388			} else {
 389				goto error;
 390				
 391			}
 392		} else if (I->get()=="-bp") { // /breakpoints
 393
 394			if (I->next()) {
 395
 396				String bplist = I->next()->get();
 397				breakpoints= bplist.split(",");
 398				N=I->next()->next();
 399			} else {
 400				goto error;
 401
 402			}
 403
 404
 405		} else if (I->get()=="-fdelay") { // resolution
 406
 407			if (I->next()) {
 408
 409				OS::get_singleton()->set_frame_delay(I->next()->get().to_int());
 410				N=I->next()->next();
 411			} else {
 412				goto error;
 413
 414			}
 415
 416
 417		} else if (I->get() == "-pack") {
 418
 419			if (I->next()) {
 420
 421				pack_list.push_back(I->next()->get());
 422				N = I->next()->next();
 423			} else {
 424
 425				goto error;
 426			};
 427
 428		} else if (I->get()=="-debug" || I->get()=="-d") {
 429			debug_mode="local";
 430		} else if (I->get()=="-editor_scene") {
 431
 432			if (I->next()) {
 433
 434				Globals::get_singleton()->set("editor_scene",game_path=I->next()->get());
 435			} else {
 436				goto error;
 437
 438			}
 439
 440		} else if (I->get()=="-rdebug") {
 441			if (I->next()) {
 442
 443				debug_mode="remote";
 444				debug_host=I->next()->get();
 445				if (debug_host.find(":")==-1) //wrong host
 446					goto error;
 447				N=I->next()->next();
 448			} else {
 449				goto error;
 450
 451			}
 452		} else {
 453
 454			//test for game path
 455			bool gpfound=false;
 456
 457			if (!I->get().begins_with("-") && game_path=="") {
 458				DirAccess* da = DirAccess::open(I->get());
 459				if (da!=NULL) {
 460					game_path=I->get();
 461					gpfound=true;
 462					memdelete(da);
 463				}
 464
 465			}
 466
 467			if (!gpfound) {
 468				main_args.push_back(I->get());
 469			}
 470		}
 471			
 472		I=N;
 473	}
 474
 475
 476
 477	if (debug_mode == "remote") {
 478
 479		ScriptDebuggerRemote *sdr = memnew( ScriptDebuggerRemote );
 480		uint16_t debug_port = GLOBAL_DEF("debug/remote_port",6007);
 481		if (debug_host.find(":")!=-1) {
 482		    debug_port=debug_host.get_slice(":",1).to_int();
 483		    debug_host=debug_host.get_slice(":",0);
 484		}
 485		Error derr = sdr->connect_to_host(debug_host,debug_port);
 486
 487		if (derr!=OK) {
 488			memdelete(sdr);
 489		} else {
 490			script_debugger=sdr;
 491
 492		}
 493	} else if (debug_mode=="local") {
 494
 495		script_debugger = memnew( ScriptDebuggerLocal );
 496	}
 497
 498
 499	if (remotefs!="") {
 500
 501		file_access_network_client=memnew(FileAccessNetworkClient);
 502		int port;
 503		if (remotefs.find(":")!=-1) {
 504			port=remotefs.get_slice(":",1).to_int();
 505			remotefs=remotefs.get_slice(":",0);
 506		} else {
 507			port=6010;
 508		}
 509
 510		Error err = file_access_network_client->connect(remotefs,port,remotefs_pass);
 511		if (err) {
 512			OS::get_singleton()->printerr("Could not connect to remotefs: %s:%i\n",remotefs.utf8().get_data(),port);
 513			goto error;
 514		}
 515
 516		FileAccess::make_default<FileAccessNetwork>(FileAccess::ACCESS_RESOURCES);
 517	}
 518	if (script_debugger) {
 519		//there is a debugger, parse breakpoints
 520
 521		for(int i=0;i<breakpoints.size();i++) {
 522
 523			String bp = breakpoints[i];
 524			int sp=bp.find_last(":");
 525			if (sp==-1) {
 526				ERR_EXPLAIN("Invalid breakpoint: '"+bp+"', expected file:line format.");
 527				ERR_CONTINUE(sp==-1);
 528			}
 529
 530			script_debugger->insert_breakpoint(bp.substr(sp+1,bp.length()).to_int(),bp.substr(0,sp));
 531		}
 532	}
 533
 534
 535#ifdef TOOLS_ENABLED
 536	if (editor) {
 537		packed_data->set_disabled(true);
 538		globals->set_disable_platform_override(true);
 539	}
 540
 541#endif
 542
 543
 544	if (globals->setup(game_path)!=OK) {
 545		
 546#ifdef TOOLS_ENABLED
 547		editor=false;
 548#else
 549		OS::get_singleton()->print("error: Couldn't load game path '%s'\n",game_path.ascii().get_data());
 550
 551		goto error;
 552#endif
 553	}
 554
 555	if (editor) {
 556		main_args.push_back("-editor");
 557		use_custom_res=false;
 558	}
 559
 560	OS::get_singleton()->set_cmdline(execpath, main_args);
 561
 562#ifdef TOOLS_ENABLED
 563
 564	if (main_args.size()==0 && (!Globals::get_singleton()->has("application/main_loop_type")) && (!Globals::get_singleton()->has("application/main_scene") || String(Globals::get_singleton()->get("application/main_scene"))==""))
 565		use_custom_res=false; //project manager (run without arguments)
 566
 567#endif
 568
 569	input_map->load_from_globals();
 570
 571	if (video_driver=="") // specified in engine.cfg
 572		video_driver=_GLOBAL_DEF("display/driver",Variant((const char*)OS::get_singleton()->get_video_driver_name(0)));
 573
 574	if (!force_res && use_custom_res && globals->has("display/width"))
 575		video_mode.width=globals->get("display/width");
 576	if (!force_res &&use_custom_res && globals->has("display/height"))
 577		video_mode.height=globals->get("display/height");
 578	if (use_custom_res && globals->has("display/fullscreen"))
 579		video_mode.fullscreen=globals->get("display/fullscreen");
 580	if (use_custom_res && globals->has("display/resizable"))
 581		video_mode.resizable=globals->get("display/resizable");
 582
 583
 584
 585	GLOBAL_DEF("display/width",video_mode.width);
 586	GLOBAL_DEF("display/height",video_mode.height);
 587	GLOBAL_DEF("display/fullscreen",video_mode.fullscreen);
 588	GLOBAL_DEF("display/resizable",video_mode.resizable);
 589	if (rtm==-1) {
 590		rtm=GLOBAL_DEF("render/thread_model",OS::RENDER_THREAD_SAFE);
 591	}
 592
 593	if (rtm>=0 && rtm<3)
 594		OS::get_singleton()->_render_thread_mode=OS::RenderThreadMode(rtm);
 595
 596
 597
 598	/* Determine Video Driver */
 599
 600	if (audio_driver=="") // specified in engine.cfg
 601		audio_driver=GLOBAL_DEF("audio/driver",OS::get_singleton()->get_audio_driver_name(0));
 602		
 603	
 604	for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) {
 605
 606		if (video_driver==OS::get_singleton()->get_video_driver_name(i)) {
 607		
 608			video_driver_idx=i;
 609			break;
 610		}
 611	}
 612
 613	if (video_driver_idx<0) {
 614	
 615		OS::get_singleton()->alert( "Invalid Video Driver: "+video_driver );
 616		video_driver_idx = 0;
 617		//goto error;
 618	}
 619
 620	for (int i=0;i<OS::get_singleton()->get_audio_driver_count();i++) {
 621	
 622		if (audio_driver==OS::get_singleton()->get_audio_driver_name(i)) {
 623		
 624			audio_driver_idx=i;
 625			break;
 626		}
 627	}
 628
 629	if (audio_driver_idx<0) {
 630	
 631		OS::get_singleton()->alert( "Invalid Audio Driver: "+audio_driver );
 632		goto error;
 633	}
 634
 635	{
 636		String orientation = GLOBAL_DEF("display/orientation","landscape");
 637
 638		if (orientation=="portrait")
 639			OS::get_singleton()->set_screen_orientation(OS::SCREEN_PORTRAIT);
 640		else if (orientation=="reverse_landscape")
 641			OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_LANDSCAPE);
 642		else if (orientation=="reverse_portrait")
 643			OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_PORTRAIT);
 644		else if (orientation=="sensor_landscape")
 645			OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_LANDSCAPE);
 646		else if (orientation=="sensor_portrait")
 647			OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_PORTRAIT);
 648		else if (orientation=="sensor")
 649			OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR);
 650		else
 651			OS::get_singleton()->set_screen_orientation(OS::SCREEN_LANDSCAPE);
 652	}
 653
 654	OS::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/fixed_fps",60));
 655	OS::get_singleton()->set_target_fps(GLOBAL_DEF("application/target_fps",0));
 656
 657	if (!OS::get_singleton()->_verbose_stdout) //overrided
 658		OS::get_singleton()->_verbose_stdout=GLOBAL_DEF("debug/verbose_stdout",false);
 659
 660	message_queue = memnew( MessageQueue );
 661
 662	Globals::get_singleton()->register_global_defaults();
 663
 664	if (p_second_phase)
 665		return setup2();
 666
 667	return OK;
 668
 669	error:
 670	
 671	video_driver="";	
 672	audio_driver="";
 673	game_path="";
 674		
 675	args.clear(); 
 676	main_args.clear();
 677	
 678	print_help(execpath);
 679	
 680
 681	if (performance)
 682		memdelete(performance);
 683	if (input_map)
 684		memdelete(input_map);
 685	if (translation_server)
 686		memdelete( translation_server );
 687	if (globals)
 688		memdelete(globals);
 689	if (script_debugger)
 690		memdelete(script_debugger);
 691	if (packed_data)
 692		memdelete(packed_data);
 693	if (file_access_network_client)
 694		memdelete(file_access_network_client);
 695	unregister_core_types();
 696	
 697	OS::get_singleton()->_cmdline.clear();
 698
 699	if (message_queue)
 700		memdelete( message_queue);
 701	OS::get_singleton()->finalize_core();
 702	locale=String();
 703	
 704	return ERR_INVALID_PARAMETER;
 705}
 706
 707Error Main::setup2() {
 708
 709
 710	OS::get_singleton()->initialize(video_mode,video_driver_idx,audio_driver_idx);
 711
 712	register_core_singletons();
 713
 714	MAIN_PRINT("Main: Setup Logo");
 715
 716	bool show_logo=true;
 717#ifdef JAVASCRIPT_ENABLED
 718	show_logo=false;
 719#endif
 720
 721	if (show_logo) { //boot logo!
 722		Image boot_logo=GLOBAL_DEF("application/boot_logo",Image());
 723
 724		if (!boot_logo.empty()) {
 725			Color clear = GLOBAL_DEF("render/default_clear_color",Color(0.3,0.3,0.3));
 726			VisualServer::get_singleton()->set_default_clear_color(clear);
 727			Color boot_bg = GLOBAL_DEF("application/boot_bg_color", clear);
 728			VisualServer::get_singleton()->set_boot_image(boot_logo, boot_bg);
 729#ifndef TOOLS_ENABLED
 730			//no tools, so free the boot logo (no longer needed)
 731			Globals::get_singleton()->set("application/boot_logo",Image());
 732#endif
 733
 734		} else {
 735#ifndef NO_DEFAULT_BOOT_LOGO
 736
 737			MAIN_PRINT("Main: Create botsplash");
 738			Image splash(boot_splash_png);
 739
 740			MAIN_PRINT("Main: ClearColor");
 741			VisualServer::get_singleton()->set_default_clear_color(boot_splash_bg_color);
 742			MAIN_PRINT("Main: Image");
 743			VisualServer::get_singleton()->set_boot_image(splash, boot_splash_bg_color);
 744#endif
 745			MAIN_PRINT("Main: DCC");
 746			VisualServer::get_singleton()->set_default_clear_color(GLOBAL_DEF("render/default_clear_color",Color(0.3,0.3,0.3)));
 747			MAIN_PRINT("Main: END");
 748		}
 749
 750		Image icon(app_icon_png);
 751		OS::get_singleton()->set_icon(icon);
 752	}
 753	GLOBAL_DEF("application/icon",String());
 754	Globals::get_singleton()->set_custom_property_info("application/icon",PropertyInfo(Variant::STRING,"application/icon",PROPERTY_HINT_FILE,"*.png,*.webp"));
 755
 756	MAIN_PRINT("Main: Load Remaps");
 757
 758	path_remap->load_remaps();
 759
 760	MAIN_PRINT("Main: Load Scene Types");
 761
 762	register_scene_types();
 763	register_server_types();
 764
 765#ifdef TOOLS_ENABLED
 766	EditorNode::register_editor_types();
 767#endif
 768
 769	MAIN_PRINT("Main: Load Scripts, Modules, Drivers");
 770
 771	register_module_types();
 772	register_driver_types();
 773
 774	MAIN_PRINT("Main: Load Translations");
 775
 776	translation_server->setup(); //register translations, load them, etc.
 777	if (locale!="") {
 778
 779		translation_server->set_locale(locale);
 780	}
 781	translation_server->load_translations();
 782
 783
 784
 785	_start_success=true;
 786	locale=String();
 787
 788	MAIN_PRINT("Main: Done");
 789
 790	return OK;
 791
 792}
 793
 794
 795
 796bool Main::start() {
 797
 798	ERR_FAIL_COND_V(!_start_success,false);
 799
 800	bool editor=false;
 801	String doc_tool;
 802	bool doc_base=true;
 803	String game_path;
 804	String script;
 805	String test;
 806	String screen;
 807	String optimize;
 808	String optimize_preset;
 809	String _export_platform;
 810	String _import;
 811	String _import_script;
 812	String dumpstrings;
 813	bool noquit=false;
 814	bool convert_old=false;
 815	bool export_debug=false;
 816	List<String> args = OS::get_singleton()->get_cmdline_args();
 817	for (int i=0;i<args.size();i++) {
 818		
 819
 820		if (args[i]=="-doctool" && i <(args.size()-1)) {
 821
 822			doc_tool=args[i+1];
 823			i++;
 824		}else if (args[i]=="-nodocbase") {
 825
 826			doc_base=false;
 827		} else if ((args[i]=="-script" || args[i]=="-s") && i <(args.size()-1)) {
 828		
 829			script=args[i+1];
 830			i++;
 831		} else if ((args[i]=="-level" || args[i]=="-l") && i <(args.size()-1)) {
 832
 833			OS::get_singleton()->_custom_level=args[i+1];
 834			i++;
 835		} else if (args[i]=="-test" && i <(args.size()-1)) {
 836			test=args[i+1];
 837			i++;
 838		} else if (args[i]=="-optimize" && i <(args.size()-1)) {
 839			optimize=args[i+1];
 840			i++;
 841		} else if (args[i]=="-optimize_preset" && i <(args.size()-1)) {
 842			optimize_preset=args[i+1];
 843			i++;
 844		} else if (args[i]=="-export" && i <(args.size()-1)) {
 845			editor=true; //needs editor
 846			_export_platform=args[i+1];
 847			i++;
 848		} else if (args[i]=="-export_debug" && i <(args.size()-1)) {
 849			editor=true; //needs editor
 850			_export_platform=args[i+1];
 851			export_debug=true;
 852			i++;
 853		} else if (args[i]=="-import" && i <(args.size()-1)) {
 854			editor=true; //needs editor
 855			_import=args[i+1];
 856			i++;
 857		} else if (args[i]=="-import_script" && i <(args.size()-1)) {
 858			editor=true; //needs editor
 859			_import_script=args[i+1];
 860			i++;
 861		} else if (args[i]=="-noquit" ) {
 862			noquit=true;
 863		} else if (args[i]=="-dumpstrings" && i <(args.size()-1)) {
 864			editor=true; //needs editor
 865			dumpstrings=args[i+1];
 866			i++;
 867		} else if (args[i]=="-editor" || args[i]=="-e") {
 868			editor=true;
 869		} else if (args[i]=="-convert_old") {
 870			convert_old=true;
 871		} else if (args[i].length() && args[i][0] != '-' && game_path == "") {
 872
 873			game_path=args[i];
 874		}
 875	}
 876
 877	if (editor)
 878		Globals::get_singleton()->set("editor_active",true);
 879
 880
 881	String main_loop_type;
 882#ifdef TOOLS_ENABLED
 883	if(doc_tool!="") {
 884
 885		DocData doc;
 886		doc.generate(doc_base);
 887
 888		DocData docsrc;
 889		if (docsrc.load(doc_tool)==OK) {
 890			print_line("Doc exists. Merging..");
 891			doc.merge_from(docsrc);
 892		} else {
 893			print_line("No Doc exists. Generating empty.");
 894
 895		}
 896
 897		doc.save(doc_tool);
 898
 899		return false;
 900	}
 901
 902	if (optimize!="")
 903		editor=true; //need editor
 904
 905
 906
 907#endif
 908
 909	if(script=="" && game_path=="" && !editor && String(GLOBAL_DEF("application/main_scene",""))!="") {
 910		game_path=GLOBAL_DEF("application/main_scene","");
 911	}
 912
 913
 914	MainLoop *main_loop=NULL;
 915	if (editor) {
 916		main_loop = memnew(SceneMainLoop);
 917	};
 918
 919	if (test!="") {
 920#ifdef DEBUG_ENABLED
 921		main_loop = test_main(test,args);
 922
 923		if (!main_loop)
 924			return false;
 925
 926#endif
 927
 928	} else if (script!="") {
 929
 930		Ref<Script> script_res = ResourceLoader::load(script);
 931		ERR_EXPLAIN("Can't load script: "+script);
 932		ERR_FAIL_COND_V(script_res.is_null(),false);
 933		
 934		if( script_res->can_instance() /*&& script_res->inherits_from("SceneMainLoopScripted")*/) {
 935		
 936
 937			StringName instance_type=script_res->get_instance_base_type();
 938			Object *obj = ObjectTypeDB::instance(instance_type);
 939			MainLoop *script_loop = obj?obj->cast_to<MainLoop>():NULL;
 940			if (!script_loop) {
 941				if (obj)
 942					memdelete(obj);
 943				ERR_EXPLAIN("Can't load script '"+script+"', it does not inherit from a MainLoop type");
 944				ERR_FAIL_COND_V(!script_loop,false);
 945			}
 946
 947
 948			script_loop->set_init_script(script_res);
 949			main_loop=script_loop;
 950		} else {
 951
 952			return false;
 953		}
 954
 955	} else {
 956		main_loop_type=GLOBAL_DEF("application/main_loop_type","");
 957	}
 958	
 959	if (!main_loop && main_loop_type=="")
 960		main_loop_type="SceneMainLoop";
 961	
 962	if (!main_loop) {
 963		if (!ObjectTypeDB::type_exists(main_loop_type)) {
 964			OS::get_singleton()->alert("godot: error: MainLoop type doesn't exist: "+main_loop_type);
 965			return false;
 966		} else {
 967
 968			Object *ml = ObjectTypeDB::instance(main_loop_type);
 969			if (!ml) {
 970				ERR_EXPLAIN("Can't instance MainLoop type");
 971				ERR_FAIL_V(false);
 972			}
 973
 974			main_loop=ml->cast_to<MainLoop>();
 975			if (!main_loop) {
 976				
 977				memdelete(ml);
 978				ERR_EXPLAIN("Invalid MainLoop type");
 979				ERR_FAIL_V(false);
 980				
 981			}
 982		}
 983	}
 984
 985	if (main_loop->is_type("SceneMainLoop")) {
 986		
 987		SceneMainLoop *sml = main_loop->cast_to<SceneMainLoop>();
 988
 989#ifdef TOOLS_ENABLED
 990
 991		EditorNode *editor_node=NULL;
 992		if (editor) {
 993
 994			editor_node = memnew( EditorNode );			
 995			sml->get_root()->add_child(editor_node);
 996
 997			//root_node->set_editor(editor);
 998			//startup editor
 999
1000			if (_export_platform!="") {
1001
1002				editor_node->export_platform(_export_platform,game_path,export_debug,"",true);
1003				game_path=""; //no load anything
1004			}
1005		}
1006#endif
1007
1008		if (!editor) {
1009			//standard helpers that can be changed from main config
1010
1011			String stretch_mode = GLOBAL_DEF("display/stretch_mode","disabled");
1012			String stretch_aspect = GLOBAL_DEF("display/stretch_aspect","ignore");
1013			Size2i stretch_size = Size2(GLOBAL_DEF("display/width",0),GLOBAL_DEF("display/height",0));
1014
1015			SceneMainLoop::StretchMode sml_sm=SceneMainLoop::STRETCH_MODE_DISABLED;
1016			if (stretch_mode=="2d")
1017				sml_sm=SceneMainLoop::STRETCH_MODE_2D;
1018			else if (stretch_mode=="viewport")
1019				sml_sm=SceneMainLoop::STRETCH_MODE_VIEWPORT;
1020
1021			SceneMainLoop::StretchAspect sml_aspect=SceneMainLoop::STRETCH_ASPECT_IGNORE;
1022			if (stretch_aspect=="keep")
1023				sml_aspect=SceneMainLoop::STRETCH_ASPECT_KEEP;
1024			else if (stretch_aspect=="keep_width")
1025				sml_aspect=SceneMainLoop::STRETCH_ASPECT_KEEP_WIDTH;
1026			else if (stretch_aspect=="keep_height")
1027				sml_aspect=SceneMainLoop::STRETCH_ASPECT_KEEP_HEIGHT;
1028
1029			sml->set_screen_stretch(sml_sm,sml_aspect,stretch_size);
1030
1031			sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true));
1032			String appname = Globals::get_singleton()->get("application/name");
1033			appname = TranslationServer::get_singleton()->translate(appname);
1034			OS::get_singleton()->set_window_title(appname);
1035
1036
1037		} else {
1038			GLOBAL_DEF("display/stretch_mode","disabled");
1039			Globals::get_singleton()->set_custom_property_info("display/stretch_mode",PropertyInfo(Variant::STRING,"display/stretch_mode",PROPERTY_HINT_ENUM,"disabled,2d,viewport"));
1040			GLOBAL_DEF("display/stretch_aspect","ignore");
1041			Globals::get_singleton()->set_custom_property_info("display/stretch_aspect",PropertyInfo(Variant::STRING,"display/stretch_aspect",PROPERTY_HINT_ENUM,"ignore,keep,keep_width,keep_height"));
1042			sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true));
1043
1044
1045		}
1046
1047
1048		if (game_path!="") {
1049
1050			String local_game_path=game_path.replace("\\","/");
1051
1052			if (!local_game_path.begins_with("res://")) {
1053				bool absolute=(local_game_path.size()>1) && (local_game_path[0]=='/' || local_game_path[1]==':');
1054
1055				if (!absolute) {
1056
1057					if (Globals::get_singleton()->is_using_datapack()) {
1058
1059						local_game_path="res://"+local_game_path;
1060
1061					} else {
1062						int sep=local_game_path.find_last("/");
1063
1064						if (sep==-1) {
1065							DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
1066							local_game_path=da->get_current_dir()+"/"+local_game_path;
1067							memdelete(da)						;
1068						} else {
1069
1070							DirAccess *da = DirAccess::open(local_game_path.substr(0,sep));
1071							if (da) {
1072								local_game_path=da->get_current_dir()+"/"+local_game_path.substr(sep+1,local_game_path.length());;
1073								memdelete(da);
1074							}
1075						}
1076					}
1077
1078				}
1079			}
1080
1081			local_game_path=Globals::get_singleton()->localize_path(local_game_path);
1082
1083#ifdef TOOLS_ENABLED
1084			if (editor) {
1085
1086#ifdef OLD_SCENE_FORMAT_ENABLED
1087				if (convert_old)
1088					editor_node->set_convert_old_scene(true);
1089#endif
1090
1091				if (_import!="") {
1092
1093					//editor_node->import_scene(_import,local_game_path,_import_script);
1094					if (!noquit)
1095						sml->quit();
1096					game_path=""; //no load anything
1097				} else {
1098
1099					Error serr = editor_node->load_scene(local_game_path);
1100
1101					if (serr==OK) {
1102
1103						if (optimize!="") {
1104
1105							editor_node->save_optimized_copy(optimize,optimize_preset);
1106							if (!noquit)
1107								sml->quit();
1108						}
1109
1110						if (dumpstrings!="") {
1111
1112							editor_node->save_translatable_strings(dumpstrings);
1113							if (!noquit)
1114								sml->quit();
1115						}
1116					}
1117				}
1118
1119				//editor_node->set_edited_scene(game);
1120			} else {
1121#endif
1122
1123				{
1124					//autoload
1125					List<PropertyInfo> props;
1126					Globals::get_singleton()->get_property_list(&props);
1127					for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
1128
1129						String s = E->get().name;
1130						if (!s.begins_with("autoload/"))
1131							continue;
1132						String name = s.get_slice("/",1);
1133						String path = Globals::get_singleton()->get(s);
1134						RES res = ResourceLoader::load(path);
1135						ERR_EXPLAIN("Can't autoload: "+path);
1136						ERR_CONTINUE(res.is_null());
1137						Node *n=NULL;
1138						if (res->is_type("PackedScene")) {
1139							Ref<PackedScene> ps = res;
1140							n=ps->instance();
1141						} else if (res->is_type("Script")) {
1142							Ref<Script> s = res;
1143							StringName ibt = s->get_instance_base_type();
1144							ERR_EXPLAIN("Script does not inherit a Node: "+path);
1145							ERR_CONTINUE( !ObjectTypeDB::is_type(ibt,"Node") );
1146
1147							Object *obj = ObjectTypeDB::instance(ibt);
1148
1149							ERR_EXPLAIN("Cannot instance node for autoload type: "+String(ibt));
1150							ERR_CONTINUE( obj==NULL );
1151
1152							n = obj->cast_to<Node>();
1153							n->set_script(s.get_ref_ptr());
1154						}
1155
1156						ERR_EXPLAIN("Path in autoload not a node or script: "+path);
1157						ERR_CONTINUE(!n);
1158						n->set_name(name);
1159						sml->get_root()->add_child(n);
1160					}
1161
1162				}
1163
1164				Node *scene=NULL;
1165				Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path);
1166				if (scenedata.is_valid())
1167					scene=scenedata->instance();
1168
1169#ifdef OLD_SCENE_FORMAT_ENABLED
1170
1171				if (!scene) {
1172					scene = SceneLoader::load(local_game_path,true);
1173				}
1174
1175#endif
1176
1177				ERR_EXPLAIN("Failed loading scene: "+local_game_path);
1178				ERR_FAIL_COND_V(!scene,false)
1179				sml->get_root()->add_child(scene);
1180
1181				String iconpath = GLOBAL_DEF("application/icon","Variant()""");
1182				if (iconpath!="") {
1183					Image icon;
1184					if (icon.load(iconpath)==OK)
1185						OS::get_singleton()->set_icon(icon);
1186				}
1187
1188
1189				//singletons
1190#ifdef TOOLS_ENABLED
1191			}
1192#endif
1193		}
1194
1195#ifdef TOOLS_ENABLED
1196
1197		/*if (_export_platform!="") {
1198
1199			sml->quit();
1200		}*/
1201
1202		/*
1203		if (sml->get_root_node()) {
1204
1205			Console *console = memnew( Console );
1206
1207			sml->get_root_node()->cast_to<RootNode>()->set_console(console);
1208			if (GLOBAL_DEF("console/visible_default",false).operator bool()) {
1209
1210				console->show();
1211			} else {P
1212
1213				console->hide();
1214			};
1215		}
1216*/
1217		if (script=="" && test=="" && game_path=="" && !editor) {
1218
1219			ProjectManager *pmanager = memnew( ProjectManager );
1220			sml->get_root()->add_child(pmanager);
1221		}
1222
1223#endif
1224	}
1225
1226	OS::get_singleton()->set_main_loop( main_loop );
1227
1228	return true;
1229}
1230
1231uint64_t Main::last_ticks=0;
1232uint64_t Main::target_ticks=0;
1233float Main::time_accum=0;
1234uint32_t Main::frames=0;
1235uint32_t Main::frame=0;
1236bool Main::force_redraw_requested = false;
1237
1238static uint64_t fixed_process_max=0;
1239static uint64_t idle_process_max=0;
1240
1241
1242bool Main::iteration() {
1243
1244	uint64_t ticks=OS::get_singleton()->get_ticks_usec();
1245	uint64_t ticks_elapsed=ticks-last_ticks;
1246
1247	frame+=ticks_elapsed;
1248
1249	last_ticks=ticks;
1250	double step=(double)ticks_elapsed / 1000000.0;
1251
1252	float frame_slice=1.0/OS::get_singleton()->get_iterations_per_second();
1253
1254	if (step>frame_slice*8)
1255		step=frame_slice*8;
1256
1257	time_accum+=step;
1258
1259	bool exit=false;
1260
1261
1262	int iters = 0;
1263
1264	while(time_accum>frame_slice) {
1265
1266		uint64_t fixed_begin = OS::get_singleton()->get_ticks_usec();
1267
1268		PhysicsServer::get_singleton()->sync();
1269		PhysicsServer::get_singleton()->flush_queries();
1270
1271		Physics2DServer::get_singleton()->sync();
1272		Physics2DServer::get_singleton()->flush_queries();
1273
1274		if (OS::get_singleton()->get_main_loop()->iteration( frame_slice )) {
1275			exit=true;
1276			break;
1277		}
1278
1279		message_queue->flush();
1280
1281		PhysicsServer::get_singleton()->step(frame_slice);
1282		Physics2DServer::get_singleton()->step(frame_slice);
1283
1284		time_accum-=frame_slice;
1285		message_queue->flush();
1286		//if (AudioServer::get_singleton())
1287		//	AudioServer::get_singleton()->update();
1288
1289		fixed_process_max=MAX(OS::get_singleton()->get_ticks_usec()-fixed_begin,fixed_process_max);
1290		iters++;
1291	}
1292
1293	uint64_t idle_begin = OS::get_singleton()->get_ticks_usec();
1294
1295	OS::get_singleton()->get_main_loop()->idle( step );
1296	message_queue->flush();
1297
1298	if (SpatialSoundServer::get_singleton())
1299		SpatialSoundServer::get_singleton()->update( step );
1300	if (SpatialSound2DServer::get_singleton())
1301		SpatialSound2DServer::get_singleton()->update( step );
1302
1303
1304	if (OS::get_singleton()->can_draw()) {
1305
1306		if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
1307			if (VisualServer::get_singleton()->has_changed()) {
1308				VisualServer::get_singleton()->draw(); // flush visual commands
1309				OS::get_singleton()->frames_drawn++;
1310			}
1311		} else {
1312			VisualServer::get_singleton()->draw(); // flush visual commands
1313			OS::get_singleton()->frames_drawn++;
1314			force_redraw_requested = false;
1315		}
1316	} else {
1317		VisualServer::get_singleton()->flush(); // flush visual commands
1318	}
1319
1320	if (AudioServer::get_singleton())
1321		AudioServer::get_singleton()->update();
1322
1323	for(int i=0;i<ScriptServer::get_language_count();i++) {
1324		ScriptServer::get_language(i)->frame();
1325	}
1326
1327	idle_process_max=MAX(OS::get_singleton()->get_ticks_usec()-idle_begin,idle_process_max);
1328
1329	if (script_debugger)
1330		script_debugger->idle_poll();
1331
1332
1333	//	x11_delay_usec(10000);
1334	frames++;
1335
1336	if (frame>1000000) {
1337
1338		if (GLOBAL_DEF("debug/print_fps", OS::get_singleton()->is_stdout_verbose())) {
1339			print_line("FPS: "+itos(frames));
1340		};
1341
1342		OS::get_singleton()->_fps=frames;
1343		performance->set_process_time(idle_process_max/1000000.0);
1344		performance->set_fixed_process_time(fixed_process_max/1000000.0);
1345		idle_process_max=0;
1346		fixed_process_max=0;
1347
1348		if (GLOBAL_DEF("debug/print_metrics", false)) {
1349
1350			//PerformanceMetrics::print();
1351		};
1352
1353		frame%=1000000;
1354		frames=0;
1355	}
1356
1357	if (OS::get_singleton()->is_in_low_processor_usage_mode() || !OS::get_singleton()->can_draw())
1358		OS::get_singleton()->delay_usec(25000); //apply some delay to force idle time
1359	else {
1360		uint32_t frame_delay = OS::get_singleton()->get_frame_delay();
1361		if (frame_delay)
1362			OS::get_singleton()->delay_usec( OS::get_singleton()->get_frame_delay()*1000 );
1363	}
1364
1365	int taret_fps = OS::get_singleton()->get_target_fps();
1366	if (taret_fps>0) {
1367		uint64_t time_step = 1000000L/taret_fps;
1368		target_ticks += time_step;
1369		uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
1370		if (current_ticks<target_ticks) OS::get_singleton()->delay_usec(target_ticks-current_ticks);
1371		current_ticks = OS::get_singleton()->get_ticks_usec();
1372		target_ticks = MIN(MAX(target_ticks,current_ticks-time_step),current_ticks+time_step);
1373	}
1374
1375	return exit;
1376}
1377
1378void Main::force_redraw() {
1379
1380	force_redraw_requested = true;
1381};
1382
1383
1384void Main::cleanup() {
1385
1386	ERR_FAIL_COND(!_start_success);
1387
1388	if (script_debugger)
1389		memdelete(script_debugger);
1390
1391	OS::get_singleton()->delete_main_loop();
1392
1393	OS::get_singleton()->_cmdline.clear();
1394	OS::get_singleton()->_execpath="";
1395	OS::get_singleton()->_local_clipboard="";
1396
1397#ifdef TOOLS_ENABLED
1398	EditorNode::unregister_editor_types();
1399#endif
1400
1401	unregister_driver_types();	
1402	unregister_module_types();
1403	unregister_scene_types();	
1404	unregister_server_types();
1405
1406	OS::get_singleton()->finalize();
1407				
1408	if (packed_data)
1409		memdelete(packed_data);
1410	if (file_access_network_client)
1411		memdelete(file_access_network_client);
1412	if (performance)
1413		memdelete(performance);
1414	if (input_map)
1415		memdelete(input_map);
1416	if (translation_server)
1417		memdelete( translation_server );
1418	if (path_remap)
1419		memdelete(path_remap);
1420	if (globals)
1421		memdelete(globals);
1422
1423
1424
1425
1426	memdelete( message_queue );
1427
1428	unregister_core_driver_types();
1429	unregister_core_types();
1430
1431	//PerformanceMetrics::finish();
1432	OS::get_singleton()->clear_last_error();
1433	OS::get_singleton()->finalize_core();
1434
1435
1436}
1437