main.cpp 181 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830
  1. /**************************************************************************/
  2. /* main.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "main.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/core_globals.h"
  33. #include "core/crypto/crypto.h"
  34. #include "core/debugger/engine_debugger.h"
  35. #include "core/extension/extension_api_dump.h"
  36. #include "core/extension/gdextension_interface_dump.gen.h"
  37. #include "core/extension/gdextension_manager.h"
  38. #include "core/input/input.h"
  39. #include "core/input/input_map.h"
  40. #include "core/io/dir_access.h"
  41. #include "core/io/file_access_pack.h"
  42. #include "core/io/file_access_zip.h"
  43. #include "core/io/image.h"
  44. #include "core/io/image_loader.h"
  45. #include "core/io/ip.h"
  46. #include "core/io/resource_loader.h"
  47. #include "core/object/message_queue.h"
  48. #include "core/object/script_language.h"
  49. #include "core/os/os.h"
  50. #include "core/os/time.h"
  51. #include "core/register_core_types.h"
  52. #include "core/string/translation_server.h"
  53. #include "core/version.h"
  54. #include "drivers/register_driver_types.h"
  55. #include "main/app_icon.gen.h"
  56. #include "main/main_timer_sync.h"
  57. #include "main/performance.h"
  58. #include "main/splash.gen.h"
  59. #include "modules/register_module_types.h"
  60. #include "platform/register_platform_apis.h"
  61. #include "scene/main/scene_tree.h"
  62. #include "scene/main/window.h"
  63. #include "scene/property_list_helper.h"
  64. #include "scene/register_scene_types.h"
  65. #include "scene/resources/packed_scene.h"
  66. #include "scene/theme/theme_db.h"
  67. #include "servers/audio/audio_driver_dummy.h"
  68. #include "servers/audio_server.h"
  69. #include "servers/camera_server.h"
  70. #include "servers/display_server.h"
  71. #include "servers/movie_writer/movie_writer.h"
  72. #include "servers/movie_writer/movie_writer_mjpeg.h"
  73. #include "servers/navigation_server_3d.h"
  74. #include "servers/navigation_server_3d_dummy.h"
  75. #include "servers/register_server_types.h"
  76. #include "servers/rendering/rendering_server_default.h"
  77. #include "servers/text/text_server_dummy.h"
  78. #include "servers/text_server.h"
  79. // 2D
  80. #include "servers/navigation_server_2d.h"
  81. #include "servers/navigation_server_2d_dummy.h"
  82. #include "servers/physics_server_2d.h"
  83. #include "servers/physics_server_2d_dummy.h"
  84. #ifndef _3D_DISABLED
  85. #include "servers/physics_server_3d.h"
  86. #include "servers/physics_server_3d_dummy.h"
  87. #include "servers/xr_server.h"
  88. #endif // _3D_DISABLED
  89. #ifdef TESTS_ENABLED
  90. #include "tests/test_main.h"
  91. #endif
  92. #ifdef TOOLS_ENABLED
  93. #include "editor/debugger/debug_adapter/debug_adapter_server.h"
  94. #include "editor/debugger/editor_debugger_node.h"
  95. #include "editor/doc_data_class_path.gen.h"
  96. #include "editor/doc_tools.h"
  97. #include "editor/editor_file_system.h"
  98. #include "editor/editor_help.h"
  99. #include "editor/editor_node.h"
  100. #include "editor/editor_paths.h"
  101. #include "editor/editor_settings.h"
  102. #include "editor/editor_translation.h"
  103. #include "editor/progress_dialog.h"
  104. #include "editor/project_manager.h"
  105. #include "editor/register_editor_types.h"
  106. #if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
  107. #include "main/splash_editor.gen.h"
  108. #endif
  109. #ifndef DISABLE_DEPRECATED
  110. #include "editor/project_converter_3_to_4.h"
  111. #endif // DISABLE_DEPRECATED
  112. #endif // TOOLS_ENABLED
  113. #if defined(STEAMAPI_ENABLED)
  114. #include "main/steam_tracker.h"
  115. #endif
  116. #include "modules/modules_enabled.gen.h" // For mono.
  117. #if defined(MODULE_MONO_ENABLED) && defined(TOOLS_ENABLED)
  118. #include "modules/mono/editor/bindings_generator.h"
  119. #endif
  120. #ifdef MODULE_GDSCRIPT_ENABLED
  121. #include "modules/gdscript/gdscript.h"
  122. #if defined(TOOLS_ENABLED) && !defined(GDSCRIPT_NO_LSP)
  123. #include "modules/gdscript/language_server/gdscript_language_server.h"
  124. #endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
  125. #endif // MODULE_GDSCRIPT_ENABLED
  126. /* Static members */
  127. // Singletons
  128. // Initialized in setup()
  129. static Engine *engine = nullptr;
  130. static ProjectSettings *globals = nullptr;
  131. static Input *input = nullptr;
  132. static InputMap *input_map = nullptr;
  133. static TranslationServer *translation_server = nullptr;
  134. static Performance *performance = nullptr;
  135. static PackedData *packed_data = nullptr;
  136. #ifdef MINIZIP_ENABLED
  137. static ZipArchive *zip_packed_data = nullptr;
  138. #endif
  139. static MessageQueue *message_queue = nullptr;
  140. #if defined(STEAMAPI_ENABLED)
  141. static SteamTracker *steam_tracker = nullptr;
  142. #endif
  143. // Initialized in setup2()
  144. static AudioServer *audio_server = nullptr;
  145. static CameraServer *camera_server = nullptr;
  146. static DisplayServer *display_server = nullptr;
  147. static RenderingServer *rendering_server = nullptr;
  148. static TextServerManager *tsman = nullptr;
  149. static ThemeDB *theme_db = nullptr;
  150. static PhysicsServer2DManager *physics_server_2d_manager = nullptr;
  151. static PhysicsServer2D *physics_server_2d = nullptr;
  152. #ifndef _3D_DISABLED
  153. static PhysicsServer3DManager *physics_server_3d_manager = nullptr;
  154. static PhysicsServer3D *physics_server_3d = nullptr;
  155. static XRServer *xr_server = nullptr;
  156. #endif // _3D_DISABLED
  157. // We error out if setup2() doesn't turn this true
  158. static bool _start_success = false;
  159. // Drivers
  160. String display_driver = "";
  161. String tablet_driver = "";
  162. String text_driver = "";
  163. String rendering_driver = "";
  164. String rendering_method = "";
  165. static int text_driver_idx = -1;
  166. static int audio_driver_idx = -1;
  167. // Engine config/tools
  168. static bool single_window = false;
  169. static bool editor = false;
  170. static bool project_manager = false;
  171. static bool cmdline_tool = false;
  172. static String locale;
  173. static String log_file;
  174. static bool show_help = false;
  175. static uint64_t quit_after = 0;
  176. static OS::ProcessID editor_pid = 0;
  177. #ifdef TOOLS_ENABLED
  178. static bool found_project = false;
  179. static bool recovery_mode = false;
  180. static bool auto_build_solutions = false;
  181. static String debug_server_uri;
  182. static bool wait_for_import = false;
  183. static bool restore_editor_window_layout = true;
  184. #ifndef DISABLE_DEPRECATED
  185. static int converter_max_kb_file = 4 * 1024; // 4MB
  186. static int converter_max_line_length = 100000;
  187. #endif // DISABLE_DEPRECATED
  188. HashMap<Main::CLIScope, Vector<String>> forwardable_cli_arguments;
  189. #endif
  190. static bool single_threaded_scene = false;
  191. // Display
  192. static DisplayServer::WindowMode window_mode = DisplayServer::WINDOW_MODE_WINDOWED;
  193. static DisplayServer::ScreenOrientation window_orientation = DisplayServer::SCREEN_LANDSCAPE;
  194. static DisplayServer::VSyncMode window_vsync_mode = DisplayServer::VSYNC_ENABLED;
  195. static uint32_t window_flags = 0;
  196. static Size2i window_size = Size2i(1152, 648);
  197. static int init_screen = DisplayServer::SCREEN_PRIMARY;
  198. static bool init_fullscreen = false;
  199. static bool init_maximized = false;
  200. static bool init_windowed = false;
  201. static bool init_always_on_top = false;
  202. static bool init_use_custom_pos = false;
  203. static bool init_use_custom_screen = false;
  204. static Vector2 init_custom_pos;
  205. static int64_t init_embed_parent_window_id = 0;
  206. static bool use_custom_res = true;
  207. static bool force_res = false;
  208. // Debug
  209. static bool use_debug_profiler = false;
  210. #ifdef DEBUG_ENABLED
  211. static bool debug_collisions = false;
  212. static bool debug_paths = false;
  213. static bool debug_navigation = false;
  214. static bool debug_avoidance = false;
  215. static bool debug_canvas_item_redraw = false;
  216. #endif
  217. static int max_fps = -1;
  218. static int frame_delay = 0;
  219. static int audio_output_latency = 0;
  220. static bool disable_render_loop = false;
  221. static int fixed_fps = -1;
  222. static MovieWriter *movie_writer = nullptr;
  223. static bool disable_vsync = false;
  224. static bool print_fps = false;
  225. #ifdef TOOLS_ENABLED
  226. static bool editor_pseudolocalization = false;
  227. static bool dump_gdextension_interface = false;
  228. static bool dump_extension_api = false;
  229. static bool include_docs_in_extension_api_dump = false;
  230. static bool validate_extension_api = false;
  231. static String validate_extension_api_file;
  232. #endif
  233. bool profile_gpu = false;
  234. // Constants.
  235. static const String NULL_DISPLAY_DRIVER("headless");
  236. static const String NULL_AUDIO_DRIVER("Dummy");
  237. // The length of the longest column in the command-line help we should align to
  238. // (excluding the 2-space left and right margins).
  239. // Currently, this is `--export-release <preset> <path>`.
  240. static const int OPTION_COLUMN_LENGTH = 32;
  241. /* Helper methods */
  242. bool Main::is_cmdline_tool() {
  243. return cmdline_tool;
  244. }
  245. #ifdef TOOLS_ENABLED
  246. const Vector<String> &Main::get_forwardable_cli_arguments(Main::CLIScope p_scope) {
  247. return forwardable_cli_arguments[p_scope];
  248. }
  249. #endif
  250. static String unescape_cmdline(const String &p_str) {
  251. return p_str.replace("%20", " ");
  252. }
  253. static String get_full_version_string() {
  254. String hash = String(VERSION_HASH);
  255. if (!hash.is_empty()) {
  256. hash = "." + hash.left(9);
  257. }
  258. return String(VERSION_FULL_BUILD) + hash;
  259. }
  260. #if defined(TOOLS_ENABLED) && defined(MODULE_GDSCRIPT_ENABLED)
  261. static Vector<String> get_files_with_extension(const String &p_root, const String &p_extension) {
  262. Vector<String> paths;
  263. Ref<DirAccess> dir = DirAccess::open(p_root);
  264. if (dir.is_valid()) {
  265. dir->list_dir_begin();
  266. String fn = dir->get_next();
  267. while (!fn.is_empty()) {
  268. if (!dir->current_is_hidden() && fn != "." && fn != "..") {
  269. if (dir->current_is_dir()) {
  270. paths.append_array(get_files_with_extension(p_root.path_join(fn), p_extension));
  271. } else if (fn.get_extension() == p_extension) {
  272. paths.append(p_root.path_join(fn));
  273. }
  274. }
  275. fn = dir->get_next();
  276. }
  277. dir->list_dir_end();
  278. }
  279. return paths;
  280. }
  281. #endif
  282. // FIXME: Could maybe be moved to have less code in main.cpp.
  283. void initialize_physics() {
  284. #ifndef _3D_DISABLED
  285. /// 3D Physics Server
  286. physics_server_3d = PhysicsServer3DManager::get_singleton()->new_server(
  287. GLOBAL_GET(PhysicsServer3DManager::setting_property_name));
  288. if (!physics_server_3d) {
  289. // Physics server not found, Use the default physics
  290. physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
  291. }
  292. // Fall back to dummy if no default server has been registered.
  293. if (!physics_server_3d) {
  294. WARN_PRINT(vformat("Falling back to dummy PhysicsServer3D; 3D physics functionality will be disabled. If this is intended, set the %s project setting to Dummy.", PhysicsServer3DManager::setting_property_name));
  295. physics_server_3d = memnew(PhysicsServer3DDummy);
  296. }
  297. // Should be impossible, but make sure it's not null.
  298. ERR_FAIL_NULL_MSG(physics_server_3d, "Failed to initialize PhysicsServer3D.");
  299. physics_server_3d->init();
  300. #endif // _3D_DISABLED
  301. // 2D Physics server
  302. physics_server_2d = PhysicsServer2DManager::get_singleton()->new_server(
  303. GLOBAL_GET(PhysicsServer2DManager::get_singleton()->setting_property_name));
  304. if (!physics_server_2d) {
  305. // Physics server not found, Use the default physics
  306. physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
  307. }
  308. // Fall back to dummy if no default server has been registered.
  309. if (!physics_server_2d) {
  310. WARN_PRINT(vformat("Falling back to dummy PhysicsServer2D; 2D physics functionality will be disabled. If this is intended, set the %s project setting to Dummy.", PhysicsServer2DManager::setting_property_name));
  311. physics_server_2d = memnew(PhysicsServer2DDummy);
  312. }
  313. // Should be impossible, but make sure it's not null.
  314. ERR_FAIL_NULL_MSG(physics_server_2d, "Failed to initialize PhysicsServer2D.");
  315. physics_server_2d->init();
  316. }
  317. void finalize_physics() {
  318. #ifndef _3D_DISABLED
  319. physics_server_3d->finish();
  320. memdelete(physics_server_3d);
  321. #endif // _3D_DISABLED
  322. physics_server_2d->finish();
  323. memdelete(physics_server_2d);
  324. }
  325. void finalize_display() {
  326. rendering_server->finish();
  327. memdelete(rendering_server);
  328. memdelete(display_server);
  329. }
  330. void initialize_theme_db() {
  331. theme_db = memnew(ThemeDB);
  332. }
  333. void finalize_theme_db() {
  334. memdelete(theme_db);
  335. theme_db = nullptr;
  336. }
  337. //#define DEBUG_INIT
  338. #ifdef DEBUG_INIT
  339. #define MAIN_PRINT(m_txt) print_line(m_txt)
  340. #else
  341. #define MAIN_PRINT(m_txt)
  342. #endif
  343. void Main::print_header(bool p_rich) {
  344. if (VERSION_TIMESTAMP > 0) {
  345. // Version timestamp available.
  346. if (p_rich) {
  347. Engine::get_singleton()->print_header_rich("\u001b[38;5;39m" + String(VERSION_NAME) + "\u001b[0m v" + get_full_version_string() + " (" + Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC) - \u001b[4m" + String(VERSION_WEBSITE));
  348. } else {
  349. Engine::get_singleton()->print_header(String(VERSION_NAME) + " v" + get_full_version_string() + " (" + Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC) - " + String(VERSION_WEBSITE));
  350. }
  351. } else {
  352. if (p_rich) {
  353. Engine::get_singleton()->print_header_rich("\u001b[38;5;39m" + String(VERSION_NAME) + "\u001b[0m v" + get_full_version_string() + " - \u001b[4m" + String(VERSION_WEBSITE));
  354. } else {
  355. Engine::get_singleton()->print_header(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
  356. }
  357. }
  358. }
  359. /**
  360. * Prints a copyright notice in the command-line help with colored text. A newline is
  361. * automatically added at the end.
  362. */
  363. void Main::print_help_copyright(const char *p_notice) {
  364. OS::get_singleton()->print("\u001b[90m%s\u001b[0m\n", p_notice);
  365. }
  366. /**
  367. * Prints a title in the command-line help with colored text. A newline is
  368. * automatically added at beginning and at the end.
  369. */
  370. void Main::print_help_title(const char *p_title) {
  371. OS::get_singleton()->print("\n\u001b[1;93m%s:\u001b[0m\n", p_title);
  372. }
  373. /**
  374. * Returns the option string with required and optional arguments colored separately from the rest of the option.
  375. * This color replacement must be done *after* calling `rpad()` for the length padding to be done correctly.
  376. */
  377. String Main::format_help_option(const char *p_option) {
  378. return (String(p_option)
  379. .rpad(OPTION_COLUMN_LENGTH)
  380. .replace("[", "\u001b[96m[")
  381. .replace("]", "]\u001b[0m")
  382. .replace("<", "\u001b[95m<")
  383. .replace(">", ">\u001b[0m"));
  384. }
  385. /**
  386. * Prints an option in the command-line help with colored text. No newline is
  387. * added at the end. `p_availability` denotes which build types the argument is
  388. * available in. Support in release export templates implies support in debug
  389. * export templates and editor. Support in debug export templates implies
  390. * support in editor.
  391. */
  392. void Main::print_help_option(const char *p_option, const char *p_description, CLIOptionAvailability p_availability) {
  393. const bool option_empty = (p_option && !p_option[0]);
  394. if (!option_empty) {
  395. const char *availability_badge = "";
  396. switch (p_availability) {
  397. case CLI_OPTION_AVAILABILITY_EDITOR:
  398. availability_badge = "\u001b[1;91mE";
  399. break;
  400. case CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG:
  401. availability_badge = "\u001b[1;94mD";
  402. break;
  403. case CLI_OPTION_AVAILABILITY_TEMPLATE_RELEASE:
  404. availability_badge = "\u001b[1;92mR";
  405. break;
  406. case CLI_OPTION_AVAILABILITY_HIDDEN:
  407. // Use for multiline option names (but not when the option name is empty).
  408. availability_badge = " ";
  409. break;
  410. }
  411. OS::get_singleton()->print(
  412. " \u001b[92m%s %s\u001b[0m %s",
  413. format_help_option(p_option).utf8().ptr(),
  414. availability_badge,
  415. p_description);
  416. } else {
  417. // Make continuation lines for descriptions faint if the option name is empty.
  418. OS::get_singleton()->print(
  419. " \u001b[92m%s \u001b[0m \u001b[90m%s",
  420. format_help_option(p_option).utf8().ptr(),
  421. p_description);
  422. }
  423. }
  424. void Main::print_help(const char *p_binary) {
  425. print_header(true);
  426. print_help_copyright("Free and open source software under the terms of the MIT license.");
  427. print_help_copyright("(c) 2014-present Godot Engine contributors. (c) 2007-present Juan Linietsky, Ariel Manzur.");
  428. print_help_title("Usage");
  429. OS::get_singleton()->print(" %s \u001b[96m[options] [path to scene or \"project.godot\" file]\u001b[0m\n", p_binary);
  430. #if defined(TOOLS_ENABLED)
  431. print_help_title("Option legend (this build = editor)");
  432. #elif defined(DEBUG_ENABLED)
  433. print_help_title("Option legend (this build = debug export template)");
  434. #else
  435. print_help_title("Option legend (this build = release export template)");
  436. #endif
  437. OS::get_singleton()->print(" \u001b[1;92mR\u001b[0m Available in editor builds, debug export templates and release export templates.\n");
  438. #ifdef DEBUG_ENABLED
  439. OS::get_singleton()->print(" \u001b[1;94mD\u001b[0m Available in editor builds and debug export templates only.\n");
  440. #endif
  441. #ifdef TOOLS_ENABLED
  442. OS::get_singleton()->print(" \u001b[1;91mE\u001b[0m Only available in editor builds.\n");
  443. #endif
  444. print_help_title("General options");
  445. print_help_option("-h, --help", "Display this help message.\n");
  446. print_help_option("--version", "Display the version string.\n");
  447. print_help_option("-v, --verbose", "Use verbose stdout mode.\n");
  448. print_help_option("--quiet", "Quiet mode, silences stdout messages. Errors are still displayed.\n");
  449. print_help_option("--no-header", "Do not print engine version and rendering method header on startup.\n");
  450. print_help_title("Run options");
  451. print_help_option("--, ++", "Separator for user-provided arguments. Following arguments are not used by the engine, but can be read from `OS.get_cmdline_user_args()`.\n");
  452. #ifdef TOOLS_ENABLED
  453. print_help_option("-e, --editor", "Start the editor instead of running the scene.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  454. print_help_option("-p, --project-manager", "Start the project manager, even if a project is auto-detected.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  455. print_help_option("--recovery-mode", "Start the editor in recovery mode, which disables features that can typically cause startup crashes, such as tool scripts, editor plugins, GDExtension addons, and others.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  456. print_help_option("--debug-server <uri>", "Start the editor debug server (<protocol>://<host/IP>[:port], e.g. tcp://127.0.0.1:6007)\n", CLI_OPTION_AVAILABILITY_EDITOR);
  457. print_help_option("--dap-port <port>", "Use the specified port for the GDScript Debugger Adaptor protocol. Recommended port range [1024, 49151].\n", CLI_OPTION_AVAILABILITY_EDITOR);
  458. #if defined(MODULE_GDSCRIPT_ENABLED) && !defined(GDSCRIPT_NO_LSP)
  459. print_help_option("--lsp-port <port>", "Use the specified port for the GDScript language server protocol. Recommended port range [1024, 49151].\n", CLI_OPTION_AVAILABILITY_EDITOR);
  460. #endif // MODULE_GDSCRIPT_ENABLED && !GDSCRIPT_NO_LSP
  461. #endif
  462. print_help_option("--quit", "Quit after the first iteration.\n");
  463. print_help_option("--quit-after <int>", "Quit after the given number of iterations. Set to 0 to disable.\n");
  464. print_help_option("-l, --language <locale>", "Use a specific locale (<locale> being a two-letter code).\n");
  465. print_help_option("--path <directory>", "Path to a project (<directory> must contain a \"project.godot\" file).\n");
  466. print_help_option("-u, --upwards", "Scan folders upwards for project.godot file.\n");
  467. print_help_option("--main-pack <file>", "Path to a pack (.pck) file to load.\n");
  468. #ifdef DISABLE_DEPRECATED
  469. print_help_option("--render-thread <mode>", "Render thread mode (\"safe\", \"separate\").\n");
  470. #else
  471. print_help_option("--render-thread <mode>", "Render thread mode (\"unsafe\" [deprecated], \"safe\", \"separate\").\n");
  472. #endif
  473. print_help_option("--remote-fs <address>", "Remote filesystem (<host/IP>[:<port>] address).\n");
  474. print_help_option("--remote-fs-password <password>", "Password for remote filesystem.\n");
  475. print_help_option("--audio-driver <driver>", "Audio driver [");
  476. for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
  477. if (i > 0) {
  478. OS::get_singleton()->print(", ");
  479. }
  480. OS::get_singleton()->print("\"%s\"", AudioDriverManager::get_driver(i)->get_name());
  481. }
  482. OS::get_singleton()->print("].\n");
  483. print_help_option("--display-driver <driver>", "Display driver (and rendering driver) [");
  484. for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
  485. if (i > 0) {
  486. OS::get_singleton()->print(", ");
  487. }
  488. OS::get_singleton()->print("\"%s\" (", DisplayServer::get_create_function_name(i));
  489. Vector<String> rd = DisplayServer::get_create_function_rendering_drivers(i);
  490. for (int j = 0; j < rd.size(); j++) {
  491. if (j > 0) {
  492. OS::get_singleton()->print(", ");
  493. }
  494. OS::get_singleton()->print("\"%s\"", rd[j].utf8().get_data());
  495. }
  496. OS::get_singleton()->print(")");
  497. }
  498. OS::get_singleton()->print("].\n");
  499. print_help_option("--audio-output-latency <ms>", "Override audio output latency in milliseconds (default is 15 ms).\n");
  500. print_help_option("", "Lower values make sound playback more reactive but increase CPU usage, and may result in audio cracking if the CPU can't keep up.\n");
  501. print_help_option("--rendering-method <renderer>", "Renderer name. Requires driver support.\n");
  502. print_help_option("--rendering-driver <driver>", "Rendering driver (depends on display driver).\n");
  503. print_help_option("--gpu-index <device_index>", "Use a specific GPU (run with --verbose to get a list of available devices).\n");
  504. print_help_option("--text-driver <driver>", "Text driver (used for font rendering, bidirectional support and shaping).\n");
  505. print_help_option("--tablet-driver <driver>", "Pen tablet input driver.\n");
  506. print_help_option("--headless", "Enable headless mode (--display-driver headless --audio-driver Dummy). Useful for servers and with --script.\n");
  507. print_help_option("--log-file <file>", "Write output/error log to the specified path instead of the default location defined by the project.\n");
  508. print_help_option("", "<file> path should be absolute or relative to the project directory.\n");
  509. print_help_option("--write-movie <file>", "Write a video to the specified path (usually with .avi or .png extension).\n");
  510. print_help_option("", "--fixed-fps is forced when enabled, but it can be used to change movie FPS.\n");
  511. print_help_option("", "--disable-vsync can speed up movie writing but makes interaction more difficult.\n");
  512. print_help_option("", "--quit-after can be used to specify the number of frames to write.\n");
  513. print_help_title("Display options");
  514. print_help_option("-f, --fullscreen", "Request fullscreen mode.\n");
  515. print_help_option("-m, --maximized", "Request a maximized window.\n");
  516. print_help_option("-w, --windowed", "Request windowed mode.\n");
  517. print_help_option("-t, --always-on-top", "Request an always-on-top window.\n");
  518. print_help_option("--resolution <W>x<H>", "Request window resolution.\n");
  519. print_help_option("--position <X>,<Y>", "Request window position.\n");
  520. print_help_option("--screen <N>", "Request window screen.\n");
  521. print_help_option("--single-window", "Use a single window (no separate subwindows).\n");
  522. #ifndef _3D_DISABLED
  523. print_help_option("--xr-mode <mode>", "Select XR (Extended Reality) mode [\"default\", \"off\", \"on\"].\n");
  524. #endif
  525. print_help_option("--wid <window_id>", "Request parented to window.\n");
  526. print_help_title("Debug options");
  527. print_help_option("-d, --debug", "Debug (local stdout debugger).\n");
  528. print_help_option("-b, --breakpoints", "Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead).\n");
  529. print_help_option("--profiling", "Enable profiling in the script debugger.\n");
  530. print_help_option("--gpu-profile", "Show a GPU profile of the tasks that took the most time during frame rendering.\n");
  531. print_help_option("--gpu-validation", "Enable graphics API validation layers for debugging.\n");
  532. #ifdef DEBUG_ENABLED
  533. print_help_option("--gpu-abort", "Abort on graphics API usage errors (usually validation layer errors). May help see the problem if your system freezes.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG);
  534. #endif
  535. print_help_option("--generate-spirv-debug-info", "Generate SPIR-V debug information. This allows source-level shader debugging with RenderDoc.\n");
  536. #if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
  537. print_help_option("--extra-gpu-memory-tracking", "Enables additional memory tracking (see class reference for `RenderingDevice.get_driver_and_device_memory_report()` and linked methods). Currently only implemented for Vulkan. Enabling this feature may cause crashes on some systems due to buggy drivers or bugs in the Vulkan Loader. See https://github.com/godotengine/godot/issues/95967\n");
  538. print_help_option("--accurate-breadcrumbs", "Force barriers between breadcrumbs. Useful for narrowing down a command causing GPU resets. Currently only implemented for Vulkan.\n");
  539. #endif
  540. print_help_option("--remote-debug <uri>", "Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007).\n");
  541. print_help_option("--single-threaded-scene", "Force scene tree to run in single-threaded mode. Sub-thread groups are disabled and run on the main thread.\n");
  542. #if defined(DEBUG_ENABLED)
  543. print_help_option("--debug-collisions", "Show collision shapes when running the scene.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG);
  544. print_help_option("--debug-paths", "Show path lines when running the scene.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG);
  545. print_help_option("--debug-navigation", "Show navigation polygons when running the scene.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG);
  546. print_help_option("--debug-avoidance", "Show navigation avoidance debug visuals when running the scene.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG);
  547. print_help_option("--debug-stringnames", "Print all StringName allocations to stdout when the engine quits.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG);
  548. print_help_option("--debug-canvas-item-redraw", "Display a rectangle each time a canvas item requests a redraw (useful to troubleshoot low processor mode).\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG);
  549. #endif
  550. print_help_option("--max-fps <fps>", "Set a maximum number of frames per second rendered (can be used to limit power usage). A value of 0 results in unlimited framerate.\n");
  551. print_help_option("--frame-delay <ms>", "Simulate high CPU load (delay each frame by <ms> milliseconds). Do not use as a FPS limiter; use --max-fps instead.\n");
  552. print_help_option("--time-scale <scale>", "Force time scale (higher values are faster, 1.0 is normal speed).\n");
  553. print_help_option("--disable-vsync", "Forces disabling of vertical synchronization, even if enabled in the project settings. Does not override driver-level V-Sync enforcement.\n");
  554. print_help_option("--disable-render-loop", "Disable render loop so rendering only occurs when called explicitly from script.\n");
  555. print_help_option("--disable-crash-handler", "Disable crash handler when supported by the platform code.\n");
  556. print_help_option("--fixed-fps <fps>", "Force a fixed number of frames per second. This setting disables real-time synchronization.\n");
  557. print_help_option("--delta-smoothing <enable>", "Enable or disable frame delta smoothing [\"enable\", \"disable\"].\n");
  558. print_help_option("--print-fps", "Print the frames per second to the stdout.\n");
  559. #ifdef TOOLS_ENABLED
  560. print_help_option("--editor-pseudolocalization", "Enable pseudolocalization for the editor and the project manager.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  561. #endif
  562. print_help_title("Standalone tools");
  563. print_help_option("-s, --script <script>", "Run a script.\n");
  564. print_help_option("--main-loop <main_loop_name>", "Run a MainLoop specified by its global class name.\n");
  565. print_help_option("--check-only", "Only parse for errors and quit (use with --script).\n");
  566. #ifdef TOOLS_ENABLED
  567. print_help_option("--import", "Starts the editor, waits for any resources to be imported, and then quits.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  568. print_help_option("--export-release <preset> <path>", "Export the project in release mode using the given preset and output path. The preset name should match one defined in \"export_presets.cfg\".\n", CLI_OPTION_AVAILABILITY_EDITOR);
  569. print_help_option("", "<path> should be absolute or relative to the project directory, and include the filename for the binary (e.g. \"builds/game.exe\").\n");
  570. print_help_option("", "The target directory must exist.\n");
  571. print_help_option("--export-debug <preset> <path>", "Export the project in debug mode using the given preset and output path. See --export-release description for other considerations.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  572. print_help_option("--export-pack <preset> <path>", "Export the project data only using the given preset and output path. The <path> extension determines whether it will be in PCK or ZIP format.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  573. print_help_option("--export-patch <preset> <path>", "Export pack with changed files only. See --export-pack description for other considerations.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  574. print_help_option("--patches <paths>", "List of patches to use with --export-patch. The list is comma-separated.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  575. print_help_option("--install-android-build-template", "Install the Android build template. Used in conjunction with --export-release or --export-debug.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  576. #ifndef DISABLE_DEPRECATED
  577. // Commands are long; split the description to a second line.
  578. print_help_option("--convert-3to4 ", "\n", CLI_OPTION_AVAILABILITY_HIDDEN);
  579. print_help_option(" [max_file_kb] [max_line_size]", "Converts project from Godot 3.x to Godot 4.x.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  580. print_help_option("--validate-conversion-3to4 ", "\n", CLI_OPTION_AVAILABILITY_HIDDEN);
  581. print_help_option(" [max_file_kb] [max_line_size]", "Shows what elements will be renamed when converting project from Godot 3.x to Godot 4.x.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  582. #endif // DISABLE_DEPRECATED
  583. print_help_option("--doctool [path]", "Dump the engine API reference to the given <path> (defaults to current directory) in XML format, merging if existing files are found.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  584. print_help_option("--no-docbase", "Disallow dumping the base types (used with --doctool).\n", CLI_OPTION_AVAILABILITY_EDITOR);
  585. print_help_option("--gdextension-docs", "Rather than dumping the engine API, generate API reference from all the GDExtensions loaded in the current project (used with --doctool).\n", CLI_OPTION_AVAILABILITY_EDITOR);
  586. #ifdef MODULE_GDSCRIPT_ENABLED
  587. print_help_option("--gdscript-docs <path>", "Rather than dumping the engine API, generate API reference from the inline documentation in the GDScript files found in <path> (used with --doctool).\n", CLI_OPTION_AVAILABILITY_EDITOR);
  588. #endif
  589. print_help_option("--build-solutions", "Build the scripting solutions (e.g. for C# projects). Implies --editor and requires a valid project to edit.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  590. print_help_option("--dump-gdextension-interface", "Generate a GDExtension header file \"gdextension_interface.h\" in the current folder. This file is the base file required to implement a GDExtension.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  591. print_help_option("--dump-extension-api", "Generate a JSON dump of the Godot API for GDExtension bindings named \"extension_api.json\" in the current folder.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  592. print_help_option("--dump-extension-api-with-docs", "Generate JSON dump of the Godot API like the previous option, but including documentation.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  593. print_help_option("--validate-extension-api <path>", "Validate an extension API file dumped (with one of the two previous options) from a previous version of the engine to ensure API compatibility.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  594. print_help_option("", "If incompatibilities or errors are detected, the exit code will be non-zero.\n");
  595. print_help_option("--benchmark", "Benchmark the run time and print it to console.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  596. print_help_option("--benchmark-file <path>", "Benchmark the run time and save it to a given file in JSON format. The path should be absolute.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  597. #ifdef TESTS_ENABLED
  598. print_help_option("--test [--help]", "Run unit tests. Use --test --help for more information.\n", CLI_OPTION_AVAILABILITY_EDITOR);
  599. #endif
  600. #endif
  601. OS::get_singleton()->print("\n");
  602. }
  603. #ifdef TESTS_ENABLED
  604. // The order is the same as in `Main::setup()`, only core and some editor types
  605. // are initialized here. This also combines `Main::setup2()` initialization.
  606. Error Main::test_setup() {
  607. Thread::make_main_thread();
  608. set_current_thread_safe_for_nodes(true);
  609. OS::get_singleton()->initialize();
  610. engine = memnew(Engine);
  611. register_core_types();
  612. register_core_driver_types();
  613. packed_data = memnew(PackedData);
  614. globals = memnew(ProjectSettings);
  615. register_core_settings(); // Here globals are present.
  616. translation_server = memnew(TranslationServer);
  617. tsman = memnew(TextServerManager);
  618. if (tsman) {
  619. Ref<TextServerDummy> ts;
  620. ts.instantiate();
  621. tsman->add_interface(ts);
  622. }
  623. #ifndef _3D_DISABLED
  624. physics_server_3d_manager = memnew(PhysicsServer3DManager);
  625. #endif // _3D_DISABLED
  626. physics_server_2d_manager = memnew(PhysicsServer2DManager);
  627. // From `Main::setup2()`.
  628. register_early_core_singletons();
  629. initialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
  630. register_core_extensions();
  631. register_core_singletons();
  632. /** INITIALIZE SERVERS **/
  633. register_server_types();
  634. #ifndef _3D_DISABLED
  635. XRServer::set_xr_mode(XRServer::XRMODE_OFF); // Skip in tests.
  636. #endif // _3D_DISABLED
  637. initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
  638. GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
  639. translation_server->setup(); //register translations, load them, etc.
  640. if (!locale.is_empty()) {
  641. translation_server->set_locale(locale);
  642. }
  643. translation_server->load_translations();
  644. ResourceLoader::load_translation_remaps(); //load remaps for resources
  645. ResourceLoader::load_path_remaps();
  646. // Initialize ThemeDB early so that scene types can register their theme items.
  647. // Default theme will be initialized later, after modules and ScriptServer are ready.
  648. initialize_theme_db();
  649. NavigationServer3DManager::initialize_server(); // 3D server first because 2D depends on it.
  650. NavigationServer2DManager::initialize_server();
  651. register_scene_types();
  652. register_driver_types();
  653. register_scene_singletons();
  654. initialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
  655. GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SCENE);
  656. #ifdef TOOLS_ENABLED
  657. ClassDB::set_current_api(ClassDB::API_EDITOR);
  658. register_editor_types();
  659. initialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
  660. GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR);
  661. ClassDB::set_current_api(ClassDB::API_CORE);
  662. #endif
  663. register_platform_apis();
  664. // Theme needs modules to be initialized so that sub-resources can be loaded.
  665. theme_db->initialize_theme_noproject();
  666. ERR_FAIL_COND_V(TextServerManager::get_singleton()->get_interface_count() == 0, ERR_CANT_CREATE);
  667. /* Use one with the most features available. */
  668. int max_features = 0;
  669. for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
  670. uint32_t features = TextServerManager::get_singleton()->get_interface(i)->get_features();
  671. int feature_number = 0;
  672. while (features) {
  673. feature_number += features & 1;
  674. features >>= 1;
  675. }
  676. if (feature_number >= max_features) {
  677. max_features = feature_number;
  678. text_driver_idx = i;
  679. }
  680. }
  681. if (text_driver_idx >= 0) {
  682. Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(text_driver_idx);
  683. TextServerManager::get_singleton()->set_primary_interface(ts);
  684. if (ts->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) {
  685. ts->load_support_data("res://" + ts->get_support_data_filename());
  686. }
  687. } else {
  688. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "TextServer: Unable to create TextServer interface.");
  689. }
  690. ClassDB::set_current_api(ClassDB::API_NONE);
  691. _start_success = true;
  692. return OK;
  693. }
  694. // The order is the same as in `Main::cleanup()`.
  695. void Main::test_cleanup() {
  696. ERR_FAIL_COND(!_start_success);
  697. for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
  698. TextServerManager::get_singleton()->get_interface(i)->cleanup();
  699. }
  700. ResourceLoader::remove_custom_loaders();
  701. ResourceSaver::remove_custom_savers();
  702. PropertyListHelper::clear_base_helpers();
  703. #ifdef TOOLS_ENABLED
  704. GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR);
  705. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
  706. unregister_editor_types();
  707. #endif
  708. GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_SCENE);
  709. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
  710. unregister_platform_apis();
  711. unregister_driver_types();
  712. unregister_scene_types();
  713. finalize_theme_db();
  714. NavigationServer2DManager::finalize_server(); // 2D goes first as it uses the 3D server behind the scene.
  715. NavigationServer3DManager::finalize_server();
  716. GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
  717. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
  718. unregister_server_types();
  719. EngineDebugger::deinitialize();
  720. OS::get_singleton()->finalize();
  721. if (packed_data) {
  722. memdelete(packed_data);
  723. }
  724. if (translation_server) {
  725. memdelete(translation_server);
  726. }
  727. if (tsman) {
  728. memdelete(tsman);
  729. }
  730. #ifndef _3D_DISABLED
  731. if (physics_server_3d_manager) {
  732. memdelete(physics_server_3d_manager);
  733. }
  734. #endif // _3D_DISABLED
  735. if (physics_server_2d_manager) {
  736. memdelete(physics_server_2d_manager);
  737. }
  738. if (globals) {
  739. memdelete(globals);
  740. }
  741. unregister_core_driver_types();
  742. unregister_core_extensions();
  743. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
  744. if (engine) {
  745. memdelete(engine);
  746. }
  747. unregister_core_types();
  748. OS::get_singleton()->finalize_core();
  749. }
  750. #endif
  751. int Main::test_entrypoint(int argc, char *argv[], bool &tests_need_run) {
  752. for (int x = 0; x < argc; x++) {
  753. // Early return to ignore a possible user-provided "--test" argument.
  754. if ((strlen(argv[x]) == 2) && ((strncmp(argv[x], "--", 2) == 0) || (strncmp(argv[x], "++", 2) == 0))) {
  755. tests_need_run = false;
  756. return EXIT_SUCCESS;
  757. }
  758. if ((strncmp(argv[x], "--test", 6) == 0) && (strlen(argv[x]) == 6)) {
  759. tests_need_run = true;
  760. #ifdef TESTS_ENABLED
  761. // TODO: need to come up with different test contexts.
  762. // Not every test requires high-level functionality like `ClassDB`.
  763. test_setup();
  764. int status = test_main(argc, argv);
  765. test_cleanup();
  766. return status;
  767. #else
  768. ERR_PRINT(
  769. "`--test` was specified on the command line, but this Godot binary was compiled without support for unit tests. Aborting.\n"
  770. "To be able to run unit tests, use the `tests=yes` SCons option when compiling Godot.\n");
  771. return EXIT_FAILURE;
  772. #endif
  773. }
  774. }
  775. tests_need_run = false;
  776. return EXIT_SUCCESS;
  777. }
  778. /* Engine initialization
  779. *
  780. * Consists of several methods that are called by each platform's specific main(argc, argv).
  781. * To fully understand engine init, one should therefore start from the platform's main and
  782. * see how it calls into the Main class' methods.
  783. *
  784. * The initialization is typically done in 3 steps (with the setup2 step triggered either
  785. * automatically by setup, or manually in the platform's main).
  786. *
  787. * - setup(execpath, argc, argv, p_second_phase) is the main entry point for all platforms,
  788. * responsible for the initialization of all low level singletons and core types, and parsing
  789. * command line arguments to configure things accordingly.
  790. * If p_second_phase is true, it will chain into setup2() (default behavior). This is
  791. * disabled on some platforms (Android, iOS) which trigger the second step in their own time.
  792. *
  793. * - setup2(p_main_tid_override) registers high level servers and singletons, displays the
  794. * boot splash, then registers higher level types (scene, editor, etc.).
  795. *
  796. * - start() is the last step and that's where command line tools can run, or the main loop
  797. * can be created eventually and the project settings put into action. That's also where
  798. * the editor node is created, if relevant.
  799. * start() does it own argument parsing for a subset of the command line arguments described
  800. * in help, it's a bit messy and should be globalized with the setup() parsing somehow.
  801. */
  802. Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_phase) {
  803. Thread::make_main_thread();
  804. set_current_thread_safe_for_nodes(true);
  805. OS::get_singleton()->initialize();
  806. // Benchmark tracking must be done after `OS::get_singleton()->initialize()` as on some
  807. // platforms, it's used to set up the time utilities.
  808. OS::get_singleton()->benchmark_begin_measure("Startup", "Main::Setup");
  809. engine = memnew(Engine);
  810. MAIN_PRINT("Main: Initialize CORE");
  811. register_core_types();
  812. register_core_driver_types();
  813. MAIN_PRINT("Main: Initialize Globals");
  814. input_map = memnew(InputMap);
  815. globals = memnew(ProjectSettings);
  816. register_core_settings(); //here globals are present
  817. translation_server = memnew(TranslationServer);
  818. performance = memnew(Performance);
  819. GDREGISTER_CLASS(Performance);
  820. engine->add_singleton(Engine::Singleton("Performance", performance));
  821. // Only flush stdout in debug builds by default, as spamming `print()` will
  822. // decrease performance if this is enabled.
  823. GLOBAL_DEF_RST("application/run/flush_stdout_on_print", false);
  824. GLOBAL_DEF_RST("application/run/flush_stdout_on_print.debug", true);
  825. MAIN_PRINT("Main: Parse CMDLine");
  826. /* argument parsing and main creation */
  827. List<String> args;
  828. List<String> main_args;
  829. List<String> user_args;
  830. bool adding_user_args = false;
  831. List<String> platform_args = OS::get_singleton()->get_cmdline_platform_args();
  832. // Add command line arguments.
  833. for (int i = 0; i < argc; i++) {
  834. args.push_back(String::utf8(argv[i]));
  835. }
  836. // Add arguments received from macOS LaunchService (URL schemas, file associations).
  837. for (const String &arg : platform_args) {
  838. args.push_back(arg);
  839. }
  840. List<String>::Element *I = args.front();
  841. while (I) {
  842. I->get() = unescape_cmdline(I->get().strip_edges());
  843. I = I->next();
  844. }
  845. String audio_driver = "";
  846. String project_path = ".";
  847. bool upwards = false;
  848. String debug_uri = "";
  849. #if defined(TOOLS_ENABLED) && (defined(WINDOWS_ENABLED) || defined(LINUXBSD_ENABLED))
  850. bool test_rd_creation = false;
  851. bool test_rd_support = false;
  852. #endif
  853. bool skip_breakpoints = false;
  854. String main_pack;
  855. bool quiet_stdout = false;
  856. int separate_thread_render = -1; // Tri-state: -1 = not set, 0 = false, 1 = true.
  857. String remotefs;
  858. String remotefs_pass;
  859. Vector<String> breakpoints;
  860. bool delta_smoothing_override = false;
  861. String default_renderer = "";
  862. String default_renderer_mobile = "";
  863. String renderer_hints = "";
  864. packed_data = PackedData::get_singleton();
  865. if (!packed_data) {
  866. packed_data = memnew(PackedData);
  867. }
  868. #ifdef MINIZIP_ENABLED
  869. //XXX: always get_singleton() == 0x0
  870. zip_packed_data = ZipArchive::get_singleton();
  871. //TODO: remove this temporary fix
  872. if (!zip_packed_data) {
  873. zip_packed_data = memnew(ZipArchive);
  874. }
  875. packed_data->add_pack_source(zip_packed_data);
  876. #endif
  877. // Exit error code used in the `goto error` conditions.
  878. // It's returned as the program exit code. ERR_HELP is special cased and handled as success (0).
  879. Error exit_err = ERR_INVALID_PARAMETER;
  880. I = args.front();
  881. while (I) {
  882. List<String>::Element *N = I->next();
  883. const String &arg = I->get();
  884. #ifdef MACOS_ENABLED
  885. // Ignore the process serial number argument passed by macOS Gatekeeper.
  886. // Otherwise, Godot would try to open a non-existent project on the first start and abort.
  887. if (arg.begins_with("-psn_")) {
  888. I = N;
  889. continue;
  890. }
  891. #endif
  892. #ifdef TOOLS_ENABLED
  893. if (arg == "--debug" ||
  894. arg == "--verbose" ||
  895. arg == "--disable-crash-handler") {
  896. forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(arg);
  897. forwardable_cli_arguments[CLI_SCOPE_PROJECT].push_back(arg);
  898. }
  899. if (arg == "--single-window") {
  900. forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(arg);
  901. }
  902. if (arg == "--audio-driver" ||
  903. arg == "--display-driver" ||
  904. arg == "--rendering-method" ||
  905. arg == "--rendering-driver" ||
  906. arg == "--xr-mode") {
  907. if (N) {
  908. forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(arg);
  909. forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(N->get());
  910. }
  911. }
  912. // If gpu is specified, both editor and debug instances started from editor will inherit.
  913. if (arg == "--gpu-index") {
  914. if (N) {
  915. const String &next_arg = N->get();
  916. forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(arg);
  917. forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(next_arg);
  918. forwardable_cli_arguments[CLI_SCOPE_PROJECT].push_back(arg);
  919. forwardable_cli_arguments[CLI_SCOPE_PROJECT].push_back(next_arg);
  920. }
  921. }
  922. #endif
  923. if (adding_user_args) {
  924. user_args.push_back(arg);
  925. } else if (arg == "-h" || arg == "--help" || arg == "/?") { // display help
  926. show_help = true;
  927. exit_err = ERR_HELP; // Hack to force an early exit in `main()` with a success code.
  928. goto error;
  929. } else if (arg == "--version") {
  930. print_line(get_full_version_string());
  931. exit_err = ERR_HELP; // Hack to force an early exit in `main()` with a success code.
  932. goto error;
  933. } else if (arg == "-v" || arg == "--verbose") { // verbose output
  934. OS::get_singleton()->_verbose_stdout = true;
  935. } else if (arg == "-q" || arg == "--quiet") { // quieter output
  936. quiet_stdout = true;
  937. } else if (arg == "--no-header") {
  938. Engine::get_singleton()->_print_header = false;
  939. } else if (arg == "--audio-driver") { // audio driver
  940. if (N) {
  941. audio_driver = N->get();
  942. bool found = false;
  943. for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
  944. if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
  945. found = true;
  946. }
  947. }
  948. if (!found) {
  949. OS::get_singleton()->print("Unknown audio driver '%s', aborting.\nValid options are ",
  950. audio_driver.utf8().get_data());
  951. for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
  952. if (i == AudioDriverManager::get_driver_count() - 1) {
  953. OS::get_singleton()->print(" and ");
  954. } else if (i != 0) {
  955. OS::get_singleton()->print(", ");
  956. }
  957. OS::get_singleton()->print("'%s'", AudioDriverManager::get_driver(i)->get_name());
  958. }
  959. OS::get_singleton()->print(".\n");
  960. goto error;
  961. }
  962. N = N->next();
  963. } else {
  964. OS::get_singleton()->print("Missing audio driver argument, aborting.\n");
  965. goto error;
  966. }
  967. } else if (arg == "--audio-output-latency") {
  968. if (N) {
  969. audio_output_latency = N->get().to_int();
  970. N = N->next();
  971. } else {
  972. OS::get_singleton()->print("Missing audio output latency argument, aborting.\n");
  973. goto error;
  974. }
  975. } else if (arg == "--text-driver") {
  976. if (N) {
  977. text_driver = N->get();
  978. N = N->next();
  979. } else {
  980. OS::get_singleton()->print("Missing text driver argument, aborting.\n");
  981. goto error;
  982. }
  983. } else if (arg == "--display-driver") { // force video driver
  984. if (N) {
  985. display_driver = N->get();
  986. bool found = false;
  987. for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
  988. if (display_driver == DisplayServer::get_create_function_name(i)) {
  989. found = true;
  990. }
  991. }
  992. if (!found) {
  993. OS::get_singleton()->print("Unknown display driver '%s', aborting.\nValid options are ",
  994. display_driver.utf8().get_data());
  995. for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
  996. if (i == DisplayServer::get_create_function_count() - 1) {
  997. OS::get_singleton()->print(" and ");
  998. } else if (i != 0) {
  999. OS::get_singleton()->print(", ");
  1000. }
  1001. OS::get_singleton()->print("'%s'", DisplayServer::get_create_function_name(i));
  1002. }
  1003. OS::get_singleton()->print(".\n");
  1004. goto error;
  1005. }
  1006. N = N->next();
  1007. } else {
  1008. OS::get_singleton()->print("Missing display driver argument, aborting.\n");
  1009. goto error;
  1010. }
  1011. } else if (arg == "--rendering-method") {
  1012. if (N) {
  1013. rendering_method = N->get();
  1014. N = N->next();
  1015. } else {
  1016. OS::get_singleton()->print("Missing renderer name argument, aborting.\n");
  1017. goto error;
  1018. }
  1019. } else if (arg == "--rendering-driver") {
  1020. if (N) {
  1021. rendering_driver = N->get();
  1022. N = N->next();
  1023. } else {
  1024. OS::get_singleton()->print("Missing rendering driver argument, aborting.\n");
  1025. goto error;
  1026. }
  1027. } else if (arg == "-f" || arg == "--fullscreen") { // force fullscreen
  1028. init_fullscreen = true;
  1029. window_mode = DisplayServer::WINDOW_MODE_FULLSCREEN;
  1030. } else if (arg == "-m" || arg == "--maximized") { // force maximized window
  1031. init_maximized = true;
  1032. window_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
  1033. } else if (arg == "-w" || arg == "--windowed") { // force windowed window
  1034. init_windowed = true;
  1035. } else if (arg == "--gpu-index") {
  1036. if (N) {
  1037. Engine::singleton->gpu_idx = N->get().to_int();
  1038. N = N->next();
  1039. } else {
  1040. OS::get_singleton()->print("Missing GPU index argument, aborting.\n");
  1041. goto error;
  1042. }
  1043. } else if (arg == "--gpu-validation") {
  1044. Engine::singleton->use_validation_layers = true;
  1045. #ifdef DEBUG_ENABLED
  1046. } else if (arg == "--gpu-abort") {
  1047. Engine::singleton->abort_on_gpu_errors = true;
  1048. #endif
  1049. } else if (arg == "--generate-spirv-debug-info") {
  1050. Engine::singleton->generate_spirv_debug_info = true;
  1051. #if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
  1052. } else if (arg == "--extra-gpu-memory-tracking") {
  1053. Engine::singleton->extra_gpu_memory_tracking = true;
  1054. } else if (arg == "--accurate-breadcrumbs") {
  1055. Engine::singleton->accurate_breadcrumbs = true;
  1056. #endif
  1057. } else if (arg == "--tablet-driver") {
  1058. if (N) {
  1059. tablet_driver = N->get();
  1060. N = N->next();
  1061. } else {
  1062. OS::get_singleton()->print("Missing tablet driver argument, aborting.\n");
  1063. goto error;
  1064. }
  1065. } else if (arg == "--delta-smoothing") {
  1066. if (N) {
  1067. String string = N->get();
  1068. bool recognized = false;
  1069. if (string == "enable") {
  1070. OS::get_singleton()->set_delta_smoothing(true);
  1071. delta_smoothing_override = true;
  1072. recognized = true;
  1073. }
  1074. if (string == "disable") {
  1075. OS::get_singleton()->set_delta_smoothing(false);
  1076. delta_smoothing_override = false;
  1077. recognized = true;
  1078. }
  1079. if (!recognized) {
  1080. OS::get_singleton()->print("Delta-smoothing argument not recognized, aborting.\n");
  1081. goto error;
  1082. }
  1083. N = N->next();
  1084. } else {
  1085. OS::get_singleton()->print("Missing delta-smoothing argument, aborting.\n");
  1086. goto error;
  1087. }
  1088. } else if (arg == "--single-window") { // force single window
  1089. single_window = true;
  1090. } else if (arg == "-t" || arg == "--always-on-top") { // force always-on-top window
  1091. init_always_on_top = true;
  1092. } else if (arg == "--resolution") { // force resolution
  1093. if (N) {
  1094. String vm = N->get();
  1095. if (!vm.contains_char('x')) { // invalid parameter format
  1096. OS::get_singleton()->print("Invalid resolution '%s', it should be e.g. '1280x720'.\n",
  1097. vm.utf8().get_data());
  1098. goto error;
  1099. }
  1100. int w = vm.get_slice("x", 0).to_int();
  1101. int h = vm.get_slice("x", 1).to_int();
  1102. if (w <= 0 || h <= 0) {
  1103. OS::get_singleton()->print("Invalid resolution '%s', width and height must be above 0.\n",
  1104. vm.utf8().get_data());
  1105. goto error;
  1106. }
  1107. window_size.width = w;
  1108. window_size.height = h;
  1109. force_res = true;
  1110. N = N->next();
  1111. } else {
  1112. OS::get_singleton()->print("Missing resolution argument, aborting.\n");
  1113. goto error;
  1114. }
  1115. } else if (arg == "--screen") { // set window screen
  1116. if (N) {
  1117. init_screen = N->get().to_int();
  1118. init_use_custom_screen = true;
  1119. N = N->next();
  1120. } else {
  1121. OS::get_singleton()->print("Missing screen argument, aborting.\n");
  1122. goto error;
  1123. }
  1124. } else if (arg == "--position") { // set window position
  1125. if (N) {
  1126. String vm = N->get();
  1127. if (!vm.contains_char(',')) { // invalid parameter format
  1128. OS::get_singleton()->print("Invalid position '%s', it should be e.g. '80,128'.\n",
  1129. vm.utf8().get_data());
  1130. goto error;
  1131. }
  1132. int x = vm.get_slice(",", 0).to_int();
  1133. int y = vm.get_slice(",", 1).to_int();
  1134. init_custom_pos = Point2(x, y);
  1135. init_use_custom_pos = true;
  1136. N = N->next();
  1137. } else {
  1138. OS::get_singleton()->print("Missing position argument, aborting.\n");
  1139. goto error;
  1140. }
  1141. } else if (arg == "--headless") { // enable headless mode (no audio, no rendering).
  1142. audio_driver = NULL_AUDIO_DRIVER;
  1143. display_driver = NULL_DISPLAY_DRIVER;
  1144. } else if (arg == "--log-file") { // write to log file
  1145. if (N) {
  1146. log_file = N->get();
  1147. N = N->next();
  1148. } else {
  1149. OS::get_singleton()->print("Missing log file path argument, aborting.\n");
  1150. goto error;
  1151. }
  1152. } else if (arg == "--profiling") { // enable profiling
  1153. use_debug_profiler = true;
  1154. } else if (arg == "-l" || arg == "--language") { // language
  1155. if (N) {
  1156. locale = N->get();
  1157. N = N->next();
  1158. } else {
  1159. OS::get_singleton()->print("Missing language argument, aborting.\n");
  1160. goto error;
  1161. }
  1162. } else if (arg == "--remote-fs") { // remote filesystem
  1163. if (N) {
  1164. remotefs = N->get();
  1165. N = N->next();
  1166. } else {
  1167. OS::get_singleton()->print("Missing remote filesystem address, aborting.\n");
  1168. goto error;
  1169. }
  1170. } else if (arg == "--remote-fs-password") { // remote filesystem password
  1171. if (N) {
  1172. remotefs_pass = N->get();
  1173. N = N->next();
  1174. } else {
  1175. OS::get_singleton()->print("Missing remote filesystem password, aborting.\n");
  1176. goto error;
  1177. }
  1178. } else if (arg == "--render-thread") { // render thread mode
  1179. if (N) {
  1180. if (N->get() == "safe") {
  1181. separate_thread_render = 0;
  1182. #ifndef DISABLE_DEPRECATED
  1183. } else if (N->get() == "unsafe") {
  1184. OS::get_singleton()->print("The --render-thread unsafe option is unsupported in Godot 4 and will be removed.\n");
  1185. separate_thread_render = 0;
  1186. #endif
  1187. } else if (N->get() == "separate") {
  1188. separate_thread_render = 1;
  1189. } else {
  1190. OS::get_singleton()->print("Unknown render thread mode, aborting.\n");
  1191. #ifdef DISABLE_DEPRECATED
  1192. OS::get_singleton()->print("Valid options are 'safe' and 'separate'.\n");
  1193. #else
  1194. OS::get_singleton()->print("Valid options are 'unsafe', 'safe' and 'separate'.\n");
  1195. #endif
  1196. goto error;
  1197. }
  1198. N = N->next();
  1199. } else {
  1200. OS::get_singleton()->print("Missing render thread mode argument, aborting.\n");
  1201. goto error;
  1202. }
  1203. #ifdef TOOLS_ENABLED
  1204. } else if (arg == "-e" || arg == "--editor") { // starts editor
  1205. editor = true;
  1206. } else if (arg == "-p" || arg == "--project-manager") { // starts project manager
  1207. project_manager = true;
  1208. } else if (arg == "--recovery-mode") { // Enables recovery mode.
  1209. recovery_mode = true;
  1210. } else if (arg == "--debug-server") {
  1211. if (N) {
  1212. debug_server_uri = N->get();
  1213. if (!debug_server_uri.contains("://")) { // wrong address
  1214. OS::get_singleton()->print("Invalid debug server uri. It should be of the form <protocol>://<bind_address>:<port>.\n");
  1215. goto error;
  1216. }
  1217. N = N->next();
  1218. } else {
  1219. OS::get_singleton()->print("Missing remote debug server uri, aborting.\n");
  1220. goto error;
  1221. }
  1222. } else if (arg == "--single-threaded-scene") {
  1223. single_threaded_scene = true;
  1224. } else if (arg == "--build-solutions") { // Build the scripting solution such C#
  1225. auto_build_solutions = true;
  1226. editor = true;
  1227. cmdline_tool = true;
  1228. } else if (arg == "--dump-gdextension-interface") {
  1229. // Register as an editor instance to use low-end fallback if relevant.
  1230. editor = true;
  1231. cmdline_tool = true;
  1232. dump_gdextension_interface = true;
  1233. print_line("Dumping GDExtension interface header file");
  1234. // Hack. Not needed but otherwise we end up detecting that this should
  1235. // run the project instead of a cmdline tool.
  1236. // Needs full refactoring to fix properly.
  1237. main_args.push_back(arg);
  1238. } else if (arg == "--dump-extension-api") {
  1239. // Register as an editor instance to use low-end fallback if relevant.
  1240. editor = true;
  1241. cmdline_tool = true;
  1242. dump_extension_api = true;
  1243. print_line("Dumping Extension API");
  1244. // Hack. Not needed but otherwise we end up detecting that this should
  1245. // run the project instead of a cmdline tool.
  1246. // Needs full refactoring to fix properly.
  1247. main_args.push_back(arg);
  1248. } else if (arg == "--dump-extension-api-with-docs") {
  1249. // Register as an editor instance to use low-end fallback if relevant.
  1250. editor = true;
  1251. cmdline_tool = true;
  1252. dump_extension_api = true;
  1253. include_docs_in_extension_api_dump = true;
  1254. print_line("Dumping Extension API including documentation");
  1255. // Hack. Not needed but otherwise we end up detecting that this should
  1256. // run the project instead of a cmdline tool.
  1257. // Needs full refactoring to fix properly.
  1258. main_args.push_back(arg);
  1259. } else if (arg == "--validate-extension-api") {
  1260. // Register as an editor instance to use low-end fallback if relevant.
  1261. editor = true;
  1262. cmdline_tool = true;
  1263. validate_extension_api = true;
  1264. // Hack. Not needed but otherwise we end up detecting that this should
  1265. // run the project instead of a cmdline tool.
  1266. // Needs full refactoring to fix properly.
  1267. main_args.push_back(arg);
  1268. if (N) {
  1269. validate_extension_api_file = N->get();
  1270. N = N->next();
  1271. } else {
  1272. OS::get_singleton()->print("Missing file to load argument after --validate-extension-api, aborting.");
  1273. goto error;
  1274. }
  1275. } else if (arg == "--import") {
  1276. editor = true;
  1277. cmdline_tool = true;
  1278. wait_for_import = true;
  1279. quit_after = 1;
  1280. } else if (arg == "--export-release" || arg == "--export-debug" ||
  1281. arg == "--export-pack" || arg == "--export-patch") { // Export project
  1282. // Actually handling is done in start().
  1283. editor = true;
  1284. cmdline_tool = true;
  1285. wait_for_import = true;
  1286. main_args.push_back(arg);
  1287. } else if (arg == "--patches") {
  1288. if (N) {
  1289. // Actually handling is done in start().
  1290. main_args.push_back(arg);
  1291. main_args.push_back(N->get());
  1292. N = N->next();
  1293. } else {
  1294. OS::get_singleton()->print("Missing comma-separated list of patches after --patches, aborting.\n");
  1295. goto error;
  1296. }
  1297. #ifndef DISABLE_DEPRECATED
  1298. } else if (arg == "--export") { // For users used to 3.x syntax.
  1299. OS::get_singleton()->print("The Godot 3 --export option was changed to more explicit --export-release / --export-debug / --export-pack options.\nSee the --help output for details.\n");
  1300. goto error;
  1301. } else if (arg == "--convert-3to4") {
  1302. // Actually handling is done in start().
  1303. cmdline_tool = true;
  1304. main_args.push_back(arg);
  1305. if (N && !N->get().begins_with("-")) {
  1306. if (itos(N->get().to_int()) == N->get()) {
  1307. converter_max_kb_file = N->get().to_int();
  1308. }
  1309. if (N->next() && !N->next()->get().begins_with("-")) {
  1310. if (itos(N->next()->get().to_int()) == N->next()->get()) {
  1311. converter_max_line_length = N->next()->get().to_int();
  1312. }
  1313. }
  1314. }
  1315. } else if (arg == "--validate-conversion-3to4") {
  1316. // Actually handling is done in start().
  1317. cmdline_tool = true;
  1318. main_args.push_back(arg);
  1319. if (N && !N->get().begins_with("-")) {
  1320. if (itos(N->get().to_int()) == N->get()) {
  1321. converter_max_kb_file = N->get().to_int();
  1322. }
  1323. if (N->next() && !N->next()->get().begins_with("-")) {
  1324. if (itos(N->next()->get().to_int()) == N->next()->get()) {
  1325. converter_max_line_length = N->next()->get().to_int();
  1326. }
  1327. }
  1328. }
  1329. #endif // DISABLE_DEPRECATED
  1330. } else if (arg == "--doctool") {
  1331. // Actually handling is done in start().
  1332. cmdline_tool = true;
  1333. // `--doctool` implies `--headless` to avoid spawning an unnecessary window
  1334. // and speed up class reference generation.
  1335. audio_driver = NULL_AUDIO_DRIVER;
  1336. display_driver = NULL_DISPLAY_DRIVER;
  1337. main_args.push_back(arg);
  1338. #ifdef MODULE_GDSCRIPT_ENABLED
  1339. } else if (arg == "--gdscript-docs") {
  1340. if (N) {
  1341. project_path = N->get();
  1342. // Will be handled in start()
  1343. main_args.push_back(arg);
  1344. main_args.push_back(N->get());
  1345. N = N->next();
  1346. // GDScript docgen requires Autoloads, but loading those also creates a main loop.
  1347. // This forces main loop to quit without adding more GDScript-specific exceptions to setup.
  1348. quit_after = 1;
  1349. } else {
  1350. OS::get_singleton()->print("Missing relative or absolute path to project for --gdscript-docs, aborting.\n");
  1351. goto error;
  1352. }
  1353. #endif // MODULE_GDSCRIPT_ENABLED
  1354. #endif // TOOLS_ENABLED
  1355. } else if (arg == "--path") { // set path of project to start or edit
  1356. if (N) {
  1357. String p = N->get();
  1358. if (OS::get_singleton()->set_cwd(p) != OK) {
  1359. OS::get_singleton()->print("Invalid project path specified: \"%s\", aborting.\n", p.utf8().get_data());
  1360. goto error;
  1361. }
  1362. N = N->next();
  1363. } else {
  1364. OS::get_singleton()->print("Missing relative or absolute path, aborting.\n");
  1365. goto error;
  1366. }
  1367. } else if (arg == "-u" || arg == "--upwards") { // scan folders upwards
  1368. upwards = true;
  1369. } else if (arg == "--quit") { // Auto quit at the end of the first main loop iteration
  1370. quit_after = 1;
  1371. } else if (arg == "--quit-after") { // Quit after the given number of iterations
  1372. if (N) {
  1373. quit_after = N->get().to_int();
  1374. N = N->next();
  1375. } else {
  1376. OS::get_singleton()->print("Missing number of iterations, aborting.\n");
  1377. goto error;
  1378. }
  1379. } else if (arg.ends_with("project.godot")) {
  1380. String path;
  1381. String file = arg;
  1382. int sep = MAX(file.rfind_char('/'), file.rfind_char('\\'));
  1383. if (sep == -1) {
  1384. path = ".";
  1385. } else {
  1386. path = file.substr(0, sep);
  1387. }
  1388. if (OS::get_singleton()->set_cwd(path) == OK) {
  1389. // path already specified, don't override
  1390. } else {
  1391. project_path = path;
  1392. }
  1393. #ifdef TOOLS_ENABLED
  1394. editor = true;
  1395. #endif
  1396. } else if (arg == "-b" || arg == "--breakpoints") { // add breakpoints
  1397. if (N) {
  1398. String bplist = N->get();
  1399. breakpoints = bplist.split(",");
  1400. N = N->next();
  1401. } else {
  1402. OS::get_singleton()->print("Missing list of breakpoints, aborting.\n");
  1403. goto error;
  1404. }
  1405. } else if (arg == "--max-fps") { // set maximum rendered FPS
  1406. if (N) {
  1407. max_fps = N->get().to_int();
  1408. N = N->next();
  1409. } else {
  1410. OS::get_singleton()->print("Missing maximum FPS argument, aborting.\n");
  1411. goto error;
  1412. }
  1413. } else if (arg == "--frame-delay") { // force frame delay
  1414. if (N) {
  1415. frame_delay = N->get().to_int();
  1416. N = N->next();
  1417. } else {
  1418. OS::get_singleton()->print("Missing frame delay argument, aborting.\n");
  1419. goto error;
  1420. }
  1421. } else if (arg == "--time-scale") { // force time scale
  1422. if (N) {
  1423. Engine::get_singleton()->set_time_scale(N->get().to_float());
  1424. N = N->next();
  1425. } else {
  1426. OS::get_singleton()->print("Missing time scale argument, aborting.\n");
  1427. goto error;
  1428. }
  1429. } else if (arg == "--main-pack") {
  1430. if (N) {
  1431. main_pack = N->get();
  1432. N = N->next();
  1433. } else {
  1434. OS::get_singleton()->print("Missing path to main pack file, aborting.\n");
  1435. goto error;
  1436. }
  1437. } else if (arg == "-d" || arg == "--debug") {
  1438. debug_uri = "local://";
  1439. OS::get_singleton()->_debug_stdout = true;
  1440. #if defined(DEBUG_ENABLED)
  1441. } else if (arg == "--debug-collisions") {
  1442. debug_collisions = true;
  1443. } else if (arg == "--debug-paths") {
  1444. debug_paths = true;
  1445. } else if (arg == "--debug-navigation") {
  1446. debug_navigation = true;
  1447. } else if (arg == "--debug-avoidance") {
  1448. debug_avoidance = true;
  1449. } else if (arg == "--debug-canvas-item-redraw") {
  1450. debug_canvas_item_redraw = true;
  1451. } else if (arg == "--debug-stringnames") {
  1452. StringName::set_debug_stringnames(true);
  1453. #endif
  1454. #if defined(TOOLS_ENABLED) && (defined(WINDOWS_ENABLED) || defined(LINUXBSD_ENABLED))
  1455. } else if (arg == "--test-rd-support") {
  1456. test_rd_support = true;
  1457. } else if (arg == "--test-rd-creation") {
  1458. test_rd_creation = true;
  1459. #endif
  1460. } else if (arg == "--remote-debug") {
  1461. if (N) {
  1462. debug_uri = N->get();
  1463. if (!debug_uri.contains("://")) { // wrong address
  1464. OS::get_singleton()->print(
  1465. "Invalid debug host address, it should be of the form <protocol>://<host/IP>:<port>.\n");
  1466. goto error;
  1467. }
  1468. N = N->next();
  1469. } else {
  1470. OS::get_singleton()->print("Missing remote debug host address, aborting.\n");
  1471. goto error;
  1472. }
  1473. } else if (arg == "--editor-pid") { // not exposed to user
  1474. if (N) {
  1475. editor_pid = N->get().to_int();
  1476. N = N->next();
  1477. } else {
  1478. OS::get_singleton()->print("Missing editor PID argument, aborting.\n");
  1479. goto error;
  1480. }
  1481. } else if (arg == "--disable-render-loop") {
  1482. disable_render_loop = true;
  1483. } else if (arg == "--fixed-fps") {
  1484. if (N) {
  1485. fixed_fps = N->get().to_int();
  1486. N = N->next();
  1487. } else {
  1488. OS::get_singleton()->print("Missing fixed-fps argument, aborting.\n");
  1489. goto error;
  1490. }
  1491. } else if (arg == "--write-movie") {
  1492. if (N) {
  1493. Engine::get_singleton()->set_write_movie_path(N->get());
  1494. N = N->next();
  1495. if (fixed_fps == -1) {
  1496. fixed_fps = 60;
  1497. }
  1498. OS::get_singleton()->_writing_movie = true;
  1499. } else {
  1500. OS::get_singleton()->print("Missing write-movie argument, aborting.\n");
  1501. goto error;
  1502. }
  1503. } else if (arg == "--disable-vsync") {
  1504. disable_vsync = true;
  1505. } else if (arg == "--print-fps") {
  1506. print_fps = true;
  1507. #ifdef TOOLS_ENABLED
  1508. } else if (arg == "--editor-pseudolocalization") {
  1509. editor_pseudolocalization = true;
  1510. #endif // TOOLS_ENABLED
  1511. } else if (arg == "--profile-gpu") {
  1512. profile_gpu = true;
  1513. } else if (arg == "--disable-crash-handler") {
  1514. OS::get_singleton()->disable_crash_handler();
  1515. } else if (arg == "--skip-breakpoints") {
  1516. skip_breakpoints = true;
  1517. #ifndef _3D_DISABLED
  1518. } else if (arg == "--xr-mode") {
  1519. if (N) {
  1520. String xr_mode = N->get().to_lower();
  1521. N = N->next();
  1522. if (xr_mode == "default") {
  1523. XRServer::set_xr_mode(XRServer::XRMODE_DEFAULT);
  1524. } else if (xr_mode == "off") {
  1525. XRServer::set_xr_mode(XRServer::XRMODE_OFF);
  1526. } else if (xr_mode == "on") {
  1527. XRServer::set_xr_mode(XRServer::XRMODE_ON);
  1528. } else {
  1529. OS::get_singleton()->print("Unknown --xr-mode argument \"%s\", aborting.\n", xr_mode.ascii().get_data());
  1530. goto error;
  1531. }
  1532. } else {
  1533. OS::get_singleton()->print("Missing --xr-mode argument, aborting.\n");
  1534. goto error;
  1535. }
  1536. #endif // _3D_DISABLED
  1537. } else if (arg == "--benchmark") {
  1538. OS::get_singleton()->set_use_benchmark(true);
  1539. } else if (arg == "--benchmark-file") {
  1540. if (N) {
  1541. OS::get_singleton()->set_use_benchmark(true);
  1542. String benchmark_file = N->get();
  1543. OS::get_singleton()->set_benchmark_file(benchmark_file);
  1544. N = N->next();
  1545. } else {
  1546. OS::get_singleton()->print("Missing <path> argument for --benchmark-file <path>.\n");
  1547. goto error;
  1548. }
  1549. #if defined(TOOLS_ENABLED) && defined(MODULE_GDSCRIPT_ENABLED) && !defined(GDSCRIPT_NO_LSP)
  1550. } else if (arg == "--lsp-port") {
  1551. if (N) {
  1552. int port_override = N->get().to_int();
  1553. if (port_override < 0 || port_override > 65535) {
  1554. OS::get_singleton()->print("<port> argument for --lsp-port <port> must be between 0 and 65535.\n");
  1555. goto error;
  1556. }
  1557. GDScriptLanguageServer::port_override = port_override;
  1558. N = N->next();
  1559. } else {
  1560. OS::get_singleton()->print("Missing <port> argument for --lsp-port <port>.\n");
  1561. goto error;
  1562. }
  1563. #endif // TOOLS_ENABLED && MODULE_GDSCRIPT_ENABLED && !GDSCRIPT_NO_LSP
  1564. #if defined(TOOLS_ENABLED)
  1565. } else if (arg == "--dap-port") {
  1566. if (N) {
  1567. int port_override = N->get().to_int();
  1568. if (port_override < 0 || port_override > 65535) {
  1569. OS::get_singleton()->print("<port> argument for --dap-port <port> must be between 0 and 65535.\n");
  1570. goto error;
  1571. }
  1572. DebugAdapterServer::port_override = port_override;
  1573. N = N->next();
  1574. } else {
  1575. OS::get_singleton()->print("Missing <port> argument for --dap-port <port>.\n");
  1576. goto error;
  1577. }
  1578. #endif // TOOLS_ENABLED
  1579. } else if (arg == "--wid") {
  1580. if (N) {
  1581. init_embed_parent_window_id = N->get().to_int();
  1582. if (init_embed_parent_window_id == 0) {
  1583. OS::get_singleton()->print("<window_id> argument for --wid <window_id> must be different then 0.\n");
  1584. goto error;
  1585. }
  1586. OS::get_singleton()->_embedded_in_editor = true;
  1587. Engine::get_singleton()->set_embedded_in_editor(true);
  1588. N = N->next();
  1589. } else {
  1590. OS::get_singleton()->print("Missing <window_id> argument for --wid <window_id>.\n");
  1591. goto error;
  1592. }
  1593. } else if (arg == "--" || arg == "++") {
  1594. adding_user_args = true;
  1595. } else {
  1596. main_args.push_back(arg);
  1597. }
  1598. I = N;
  1599. }
  1600. #ifdef TOOLS_ENABLED
  1601. if (editor && project_manager) {
  1602. OS::get_singleton()->print(
  1603. "Error: Command line arguments implied opening both editor and project manager, which is not possible. Aborting.\n");
  1604. goto error;
  1605. }
  1606. #endif
  1607. // Network file system needs to be configured before globals, since globals are based on the
  1608. // 'project.godot' file which will only be available through the network if this is enabled
  1609. if (!remotefs.is_empty()) {
  1610. int port;
  1611. if (remotefs.contains_char(':')) {
  1612. port = remotefs.get_slicec(':', 1).to_int();
  1613. remotefs = remotefs.get_slicec(':', 0);
  1614. } else {
  1615. port = 6010;
  1616. }
  1617. Error err = OS::get_singleton()->setup_remote_filesystem(remotefs, port, remotefs_pass, project_path);
  1618. if (err) {
  1619. OS::get_singleton()->printerr("Could not connect to remotefs: %s:%i.\n", remotefs.utf8().get_data(), port);
  1620. goto error;
  1621. }
  1622. }
  1623. OS::get_singleton()->_in_editor = editor;
  1624. if (globals->setup(project_path, main_pack, upwards, editor) == OK) {
  1625. #ifdef TOOLS_ENABLED
  1626. found_project = true;
  1627. #endif
  1628. } else {
  1629. #ifdef TOOLS_ENABLED
  1630. editor = false;
  1631. #else
  1632. const String error_msg = "Error: Couldn't load project data at path \"" + project_path + "\". Is the .pck file missing?\nIf you've renamed the executable, the associated .pck file should also be renamed to match the executable's name (without the extension).\n";
  1633. OS::get_singleton()->print("%s", error_msg.utf8().get_data());
  1634. OS::get_singleton()->alert(error_msg);
  1635. goto error;
  1636. #endif
  1637. }
  1638. // Initialize WorkerThreadPool.
  1639. {
  1640. #ifdef THREADS_ENABLED
  1641. if (editor || project_manager) {
  1642. WorkerThreadPool::get_singleton()->init(-1, 0.75);
  1643. } else {
  1644. int worker_threads = GLOBAL_GET("threading/worker_pool/max_threads");
  1645. float low_priority_ratio = GLOBAL_GET("threading/worker_pool/low_priority_thread_ratio");
  1646. WorkerThreadPool::get_singleton()->init(worker_threads, low_priority_ratio);
  1647. }
  1648. #else
  1649. WorkerThreadPool::get_singleton()->init(0, 0);
  1650. #endif
  1651. }
  1652. #ifdef TOOLS_ENABLED
  1653. if (!project_manager && !editor) {
  1654. // If we didn't find a project, we fall back to the project manager.
  1655. project_manager = !found_project && !cmdline_tool;
  1656. }
  1657. {
  1658. // Synced with https://github.com/baldurk/renderdoc/blob/2b01465c7/renderdoc/driver/vulkan/vk_layer.cpp#L118-L165
  1659. LocalVector<String> layers_to_disable = {
  1660. "DISABLE_RTSS_LAYER", // GH-57937.
  1661. "DISABLE_VULKAN_OBS_CAPTURE", // GH-103800.
  1662. "DISABLE_VULKAN_OW_OBS_CAPTURE", // GH-104154.
  1663. "DISABLE_SAMPLE_LAYER", // GH-104154.
  1664. "DISABLE_GAMEPP_LAYER", // GH-104154.
  1665. "DISABLE_VK_LAYER_TENCENT_wegame_cross_overlay_1", // GH-104154.
  1666. // "NODEVICE_SELECT", // Kept as it's useful - GH-104592.
  1667. "VK_LAYER_bandicam_helper_DEBUG_1", // GH-101480.
  1668. "DISABLE_VK_LAYER_bandicam_helper_1", // GH-101480.
  1669. "DISABLE_VK_LAYER_reshade_1", // GH-70849.
  1670. "DISABLE_VK_LAYER_GPUOpen_GRS", // GH-104154.
  1671. "DISABLE_LAYER", // GH-104154 (fpsmon).
  1672. "DISABLE_MANGOHUD", // GH-57403.
  1673. "DISABLE_VKBASALT",
  1674. };
  1675. #if defined(WINDOWS_ENABLED) || defined(LINUXBSD_ENABLED)
  1676. if (editor || project_manager || test_rd_support || test_rd_creation) {
  1677. #else
  1678. if (editor || project_manager) {
  1679. #endif
  1680. // Disable Vulkan overlays in editor, they cause various issues.
  1681. for (const String &layer_disable : layers_to_disable) {
  1682. OS::get_singleton()->set_environment(layer_disable, "1");
  1683. }
  1684. } else {
  1685. // Re-allow using Vulkan overlays, disabled while using the editor.
  1686. for (const String &layer_disable : layers_to_disable) {
  1687. OS::get_singleton()->unset_environment(layer_disable);
  1688. }
  1689. }
  1690. }
  1691. #endif
  1692. #if defined(TOOLS_ENABLED) && (defined(WINDOWS_ENABLED) || defined(LINUXBSD_ENABLED))
  1693. if (test_rd_support) {
  1694. // Test Rendering Device creation and exit.
  1695. OS::get_singleton()->set_crash_handler_silent();
  1696. if (OS::get_singleton()->_test_create_rendering_device(display_driver)) {
  1697. exit_err = ERR_HELP;
  1698. } else {
  1699. exit_err = ERR_UNAVAILABLE;
  1700. }
  1701. goto error;
  1702. } else if (test_rd_creation) {
  1703. // Test OpenGL context and Rendering Device simultaneous creation and exit.
  1704. OS::get_singleton()->set_crash_handler_silent();
  1705. if (OS::get_singleton()->_test_create_rendering_device_and_gl(display_driver)) {
  1706. exit_err = ERR_HELP;
  1707. } else {
  1708. exit_err = ERR_UNAVAILABLE;
  1709. }
  1710. goto error;
  1711. }
  1712. #endif
  1713. #ifdef TOOLS_ENABLED
  1714. if (editor) {
  1715. Engine::get_singleton()->set_editor_hint(true);
  1716. Engine::get_singleton()->set_extension_reloading_enabled(true);
  1717. // Create initialization lock file to detect crashes during startup.
  1718. OS::get_singleton()->create_lock_file();
  1719. main_args.push_back("--editor");
  1720. if (!init_windowed && !init_fullscreen) {
  1721. init_maximized = true;
  1722. window_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
  1723. }
  1724. }
  1725. if (project_manager) {
  1726. Engine::get_singleton()->set_project_manager_hint(true);
  1727. }
  1728. if (recovery_mode) {
  1729. if (project_manager || !editor) {
  1730. OS::get_singleton()->print("Error: Recovery mode can only be used in the editor. Aborting.\n");
  1731. goto error;
  1732. }
  1733. Engine::get_singleton()->set_recovery_mode_hint(true);
  1734. }
  1735. #endif
  1736. OS::get_singleton()->set_cmdline(execpath, main_args, user_args);
  1737. Engine::get_singleton()->set_physics_ticks_per_second(GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "physics/common/physics_ticks_per_second", PROPERTY_HINT_RANGE, "1,1000,1"), 60));
  1738. Engine::get_singleton()->set_max_physics_steps_per_frame(GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "physics/common/max_physics_steps_per_frame", PROPERTY_HINT_RANGE, "1,100,1"), 8));
  1739. Engine::get_singleton()->set_physics_jitter_fix(GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/common/physics_jitter_fix", PROPERTY_HINT_RANGE, "0,2,0.001,or_greater"), 0.5));
  1740. Engine::get_singleton()->set_max_fps(GLOBAL_DEF(PropertyInfo(Variant::INT, "application/run/max_fps", PROPERTY_HINT_RANGE, "0,1000,1"), 0));
  1741. if (max_fps >= 0) {
  1742. Engine::get_singleton()->set_max_fps(max_fps);
  1743. }
  1744. // Initialize user data dir.
  1745. OS::get_singleton()->ensure_user_data_dir();
  1746. OS::get_singleton()->set_low_processor_usage_mode(GLOBAL_DEF("application/run/low_processor_mode", false));
  1747. OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(
  1748. GLOBAL_DEF(PropertyInfo(Variant::INT, "application/run/low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "0,33200,1,or_greater"), 6900)); // Roughly 144 FPS
  1749. GLOBAL_DEF("application/run/delta_smoothing", true);
  1750. if (!delta_smoothing_override) {
  1751. OS::get_singleton()->set_delta_smoothing(GLOBAL_GET("application/run/delta_smoothing"));
  1752. }
  1753. GLOBAL_DEF("debug/settings/stdout/print_fps", false);
  1754. GLOBAL_DEF("debug/settings/stdout/print_gpu_profile", false);
  1755. GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false);
  1756. GLOBAL_DEF("debug/settings/physics_interpolation/enable_warnings", true);
  1757. if (!OS::get_singleton()->_verbose_stdout) { // Not manually overridden.
  1758. OS::get_singleton()->_verbose_stdout = GLOBAL_GET("debug/settings/stdout/verbose_stdout");
  1759. }
  1760. register_early_core_singletons();
  1761. initialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
  1762. register_core_extensions(); // core extensions must be registered after globals setup and before display
  1763. ResourceUID::get_singleton()->load_from_cache(true); // load UUIDs from cache.
  1764. if (ProjectSettings::get_singleton()->has_custom_feature("dedicated_server")) {
  1765. audio_driver = NULL_AUDIO_DRIVER;
  1766. display_driver = NULL_DISPLAY_DRIVER;
  1767. }
  1768. GLOBAL_DEF(PropertyInfo(Variant::INT, "network/limits/debugger/max_chars_per_second", PROPERTY_HINT_RANGE, "256,4096,1,or_greater"), 32768);
  1769. GLOBAL_DEF(PropertyInfo(Variant::INT, "network/limits/debugger/max_queued_messages", PROPERTY_HINT_RANGE, "128,8192,1,or_greater"), 2048);
  1770. GLOBAL_DEF(PropertyInfo(Variant::INT, "network/limits/debugger/max_errors_per_second", PROPERTY_HINT_RANGE, "1,200,1,or_greater"), 400);
  1771. GLOBAL_DEF(PropertyInfo(Variant::INT, "network/limits/debugger/max_warnings_per_second", PROPERTY_HINT_RANGE, "1,200,1,or_greater"), 400);
  1772. EngineDebugger::initialize(debug_uri, skip_breakpoints, breakpoints, []() {
  1773. if (editor_pid) {
  1774. DisplayServer::get_singleton()->enable_for_stealing_focus(editor_pid);
  1775. }
  1776. });
  1777. #ifdef TOOLS_ENABLED
  1778. if (editor) {
  1779. packed_data->set_disabled(true);
  1780. }
  1781. #endif
  1782. GLOBAL_DEF("debug/file_logging/enable_file_logging", false);
  1783. // Only file logging by default on desktop platforms as logs can't be
  1784. // accessed easily on mobile/Web platforms (if at all).
  1785. // This also prevents logs from being created for the editor instance, as feature tags
  1786. // are disabled while in the editor (even if they should logically apply).
  1787. GLOBAL_DEF("debug/file_logging/enable_file_logging.pc", true);
  1788. GLOBAL_DEF("debug/file_logging/log_path", "user://logs/godot.log");
  1789. GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/file_logging/max_log_files", PROPERTY_HINT_RANGE, "0,20,1,or_greater"), 5);
  1790. // If `--log-file` is used to override the log path, allow creating logs for the project manager or editor
  1791. // and even if file logging is disabled in the Project Settings.
  1792. // `--log-file` can be used with any path (including absolute paths outside the project folder),
  1793. // so check for filesystem access if it's used.
  1794. if (FileAccess::get_create_func(!log_file.is_empty() ? FileAccess::ACCESS_FILESYSTEM : FileAccess::ACCESS_USERDATA) &&
  1795. (!log_file.is_empty() || (!project_manager && !editor && GLOBAL_GET("debug/file_logging/enable_file_logging")))) {
  1796. // Don't create logs for the project manager as they would be written to
  1797. // the current working directory, which is inconvenient.
  1798. String base_path;
  1799. int max_files;
  1800. if (!log_file.is_empty()) {
  1801. base_path = log_file;
  1802. // Ensure log file name respects the specified override by disabling log rotation.
  1803. max_files = 1;
  1804. } else {
  1805. base_path = GLOBAL_GET("debug/file_logging/log_path");
  1806. max_files = GLOBAL_GET("debug/file_logging/max_log_files");
  1807. }
  1808. OS::get_singleton()->add_logger(memnew(RotatedFileLogger(base_path, max_files)));
  1809. }
  1810. if (main_args.size() == 0 && String(GLOBAL_GET("application/run/main_scene")) == "") {
  1811. #ifdef TOOLS_ENABLED
  1812. if (!editor && !project_manager) {
  1813. #endif
  1814. const String error_msg = "Error: Can't run project: no main scene defined in the project.\n";
  1815. OS::get_singleton()->print("%s", error_msg.utf8().get_data());
  1816. OS::get_singleton()->alert(error_msg);
  1817. goto error;
  1818. #ifdef TOOLS_ENABLED
  1819. }
  1820. #endif
  1821. }
  1822. if (editor || project_manager) {
  1823. Engine::get_singleton()->set_editor_hint(true);
  1824. use_custom_res = false;
  1825. input_map->load_default(); //keys for editor
  1826. } else {
  1827. input_map->load_from_project_settings(); //keys for game
  1828. }
  1829. if (bool(GLOBAL_GET("application/run/disable_stdout"))) {
  1830. quiet_stdout = true;
  1831. }
  1832. if (bool(GLOBAL_GET("application/run/disable_stderr"))) {
  1833. CoreGlobals::print_error_enabled = false;
  1834. }
  1835. if (!bool(GLOBAL_GET("application/run/print_header"))) {
  1836. // --no-header option for project settings.
  1837. Engine::get_singleton()->_print_header = false;
  1838. }
  1839. if (quiet_stdout) {
  1840. CoreGlobals::print_line_enabled = false;
  1841. }
  1842. Logger::set_flush_stdout_on_print(GLOBAL_GET("application/run/flush_stdout_on_print"));
  1843. // Rendering drivers configuration.
  1844. // Always include all supported drivers as hint, as this is used by the editor host platform
  1845. // for project settings. For example, a Linux user should be able to configure that they want
  1846. // to export for D3D12 on Windows and Metal on macOS even if their host platform can't use those.
  1847. {
  1848. // RenderingDevice driver overrides per platform.
  1849. GLOBAL_DEF_RST("rendering/rendering_device/driver", "vulkan");
  1850. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.windows", PROPERTY_HINT_ENUM, "vulkan,d3d12"), "vulkan");
  1851. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.linuxbsd", PROPERTY_HINT_ENUM, "vulkan"), "vulkan");
  1852. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.android", PROPERTY_HINT_ENUM, "vulkan"), "vulkan");
  1853. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.ios", PROPERTY_HINT_ENUM, "metal,vulkan"), "metal");
  1854. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.macos", PROPERTY_HINT_ENUM, "metal,vulkan"), "metal");
  1855. GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_vulkan", true);
  1856. GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_d3d12", true);
  1857. GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_opengl3", true);
  1858. }
  1859. {
  1860. // GL Compatibility driver overrides per platform.
  1861. GLOBAL_DEF_RST("rendering/gl_compatibility/driver", "opengl3");
  1862. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.windows", PROPERTY_HINT_ENUM, "opengl3,opengl3_angle"), "opengl3");
  1863. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.linuxbsd", PROPERTY_HINT_ENUM, "opengl3,opengl3_es"), "opengl3");
  1864. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.web", PROPERTY_HINT_ENUM, "opengl3"), "opengl3");
  1865. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.android", PROPERTY_HINT_ENUM, "opengl3"), "opengl3");
  1866. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.ios", PROPERTY_HINT_ENUM, "opengl3"), "opengl3");
  1867. GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.macos", PROPERTY_HINT_ENUM, "opengl3,opengl3_angle"), "opengl3");
  1868. GLOBAL_DEF_RST("rendering/gl_compatibility/nvidia_disable_threaded_optimization", true);
  1869. GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_angle", true);
  1870. GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_native", true);
  1871. GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_gles", true);
  1872. Array device_blocklist;
  1873. #define BLOCK_DEVICE(m_vendor, m_name) \
  1874. { \
  1875. Dictionary device; \
  1876. device["vendor"] = m_vendor; \
  1877. device["name"] = m_name; \
  1878. device_blocklist.push_back(device); \
  1879. }
  1880. // AMD GPUs.
  1881. BLOCK_DEVICE("ATI", "Radeon 9"); // ATI Radeon 9000 Series
  1882. BLOCK_DEVICE("ATI", "Radeon X"); // ATI Radeon X500-X2000 Series
  1883. BLOCK_DEVICE("ATI", "Radeon HD 2"); // AMD/ATI (Mobility) Radeon HD 2xxx Series
  1884. BLOCK_DEVICE("ATI", "Radeon HD 3"); // AMD/ATI (Mobility) Radeon HD 3xxx Series
  1885. BLOCK_DEVICE("ATI", "Radeon HD 4"); // AMD/ATI (Mobility) Radeon HD 4xxx Series
  1886. BLOCK_DEVICE("ATI", "Radeon HD 5"); // AMD/ATI (Mobility) Radeon HD 5xxx Series
  1887. BLOCK_DEVICE("ATI", "Radeon HD 6"); // AMD/ATI (Mobility) Radeon HD 6xxx Series
  1888. BLOCK_DEVICE("ATI", "Radeon HD 7"); // AMD/ATI (Mobility) Radeon HD 7xxx Series
  1889. BLOCK_DEVICE("ATI", "Radeon HD 8"); // AMD/ATI (Mobility) Radeon HD 8xxx Series
  1890. BLOCK_DEVICE("ATI", "Radeon(TM) R2 Graphics"); // APUs
  1891. BLOCK_DEVICE("ATI", "Radeon(TM) R3 Graphics");
  1892. BLOCK_DEVICE("ATI", "Radeon(TM) R4 Graphics");
  1893. BLOCK_DEVICE("ATI", "Radeon(TM) R5 Graphics");
  1894. BLOCK_DEVICE("ATI", "Radeon(TM) R6 Graphics");
  1895. BLOCK_DEVICE("ATI", "Radeon(TM) R7 Graphics");
  1896. BLOCK_DEVICE("AMD", "Radeon(TM) R7 Graphics");
  1897. BLOCK_DEVICE("AMD", "Radeon(TM) R8 Graphics");
  1898. BLOCK_DEVICE("ATI", "Radeon R5 Graphics");
  1899. BLOCK_DEVICE("ATI", "Radeon R6 Graphics");
  1900. BLOCK_DEVICE("ATI", "Radeon R7 Graphics");
  1901. BLOCK_DEVICE("AMD", "Radeon R7 Graphics");
  1902. BLOCK_DEVICE("AMD", "Radeon R8 Graphics");
  1903. BLOCK_DEVICE("ATI", "Radeon R5 2"); // Rx 2xx Series
  1904. BLOCK_DEVICE("ATI", "Radeon R7 2");
  1905. BLOCK_DEVICE("ATI", "Radeon R9 2");
  1906. BLOCK_DEVICE("ATI", "Radeon R5 M2"); // Rx M2xx Series
  1907. BLOCK_DEVICE("ATI", "Radeon R7 M2");
  1908. BLOCK_DEVICE("ATI", "Radeon R9 M2");
  1909. BLOCK_DEVICE("ATI", "Radeon (TM) R9 Fury");
  1910. BLOCK_DEVICE("ATI", "Radeon (TM) R5 3"); // Rx 3xx Series
  1911. BLOCK_DEVICE("AMD", "Radeon (TM) R5 3");
  1912. BLOCK_DEVICE("ATI", "Radeon (TM) R7 3");
  1913. BLOCK_DEVICE("AMD", "Radeon (TM) R7 3");
  1914. BLOCK_DEVICE("ATI", "Radeon (TM) R9 3");
  1915. BLOCK_DEVICE("AMD", "Radeon (TM) R9 3");
  1916. BLOCK_DEVICE("ATI", "Radeon (TM) R5 M3"); // Rx M3xx Series
  1917. BLOCK_DEVICE("AMD", "Radeon (TM) R5 M3");
  1918. BLOCK_DEVICE("ATI", "Radeon (TM) R7 M3");
  1919. BLOCK_DEVICE("AMD", "Radeon (TM) R7 M3");
  1920. BLOCK_DEVICE("ATI", "Radeon (TM) R9 M3");
  1921. BLOCK_DEVICE("AMD", "Radeon (TM) R9 M3");
  1922. // Intel GPUs.
  1923. BLOCK_DEVICE("0x8086", "0x0042"); // HD Graphics, Gen5, Clarkdale
  1924. BLOCK_DEVICE("0x8086", "0x0046"); // HD Graphics, Gen5, Arrandale
  1925. BLOCK_DEVICE("0x8086", "0x010A"); // HD Graphics, Gen6, Sandy Bridge
  1926. BLOCK_DEVICE("Intel", "Intel HD Graphics 2000");
  1927. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 2000");
  1928. BLOCK_DEVICE("0x8086", "0x0102"); // HD Graphics 2000, Gen6, Sandy Bridge
  1929. BLOCK_DEVICE("0x8086", "0x0116"); // HD Graphics 3000, Gen6, Sandy Bridge
  1930. BLOCK_DEVICE("Intel", "Intel HD Graphics 3000");
  1931. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 3000");
  1932. BLOCK_DEVICE("0x8086", "0x0126"); // HD Graphics 3000, Gen6, Sandy Bridge
  1933. BLOCK_DEVICE("Intel", "Intel HD Graphics P3000");
  1934. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics P3000");
  1935. BLOCK_DEVICE("0x8086", "0x0112"); // HD Graphics P3000, Gen6, Sandy Bridge
  1936. BLOCK_DEVICE("0x8086", "0x0122");
  1937. BLOCK_DEVICE("0x8086", "0x015A"); // HD Graphics, Gen7, Ivy Bridge
  1938. BLOCK_DEVICE("Intel", "Intel HD Graphics 2500");
  1939. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 2500");
  1940. BLOCK_DEVICE("0x8086", "0x0152"); // HD Graphics 2500, Gen7, Ivy Bridge
  1941. BLOCK_DEVICE("Intel", "Intel HD Graphics 4000");
  1942. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 4000");
  1943. BLOCK_DEVICE("0x8086", "0x0162"); // HD Graphics 4000, Gen7, Ivy Bridge
  1944. BLOCK_DEVICE("0x8086", "0x0166");
  1945. BLOCK_DEVICE("Intel", "Intel HD Graphics P4000");
  1946. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics P4000");
  1947. BLOCK_DEVICE("0x8086", "0x016A"); // HD Graphics P4000, Gen7, Ivy Bridge
  1948. BLOCK_DEVICE("Intel", "Intel(R) Vallyview Graphics");
  1949. BLOCK_DEVICE("0x8086", "0x0F30"); // Intel(R) Vallyview Graphics, Gen7, Vallyview
  1950. BLOCK_DEVICE("0x8086", "0x0F31");
  1951. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 4200");
  1952. BLOCK_DEVICE("0x8086", "0x0A1E"); // Intel(R) HD Graphics 4200, Gen7.5, Haswell
  1953. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 4400");
  1954. BLOCK_DEVICE("0x8086", "0x0A16"); // Intel(R) HD Graphics 4400, Gen7.5, Haswell
  1955. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 4600");
  1956. BLOCK_DEVICE("0x8086", "0x0412"); // Intel(R) HD Graphics 4600, Gen7.5, Haswell
  1957. BLOCK_DEVICE("0x8086", "0x0416");
  1958. BLOCK_DEVICE("0x8086", "0x0426");
  1959. BLOCK_DEVICE("0x8086", "0x0D12");
  1960. BLOCK_DEVICE("0x8086", "0x0D16");
  1961. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics P4600/P4700");
  1962. BLOCK_DEVICE("0x8086", "0x041A"); // Intel(R) HD Graphics P4600/P4700, Gen7.5, Haswell
  1963. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 5000");
  1964. BLOCK_DEVICE("0x8086", "0x0422"); // Intel(R) HD Graphics 5000, Gen7.5, Haswell
  1965. BLOCK_DEVICE("0x8086", "0x042A");
  1966. BLOCK_DEVICE("0x8086", "0x0A26");
  1967. BLOCK_DEVICE("Intel", "Intel(R) Iris(TM) Graphics 5100");
  1968. BLOCK_DEVICE("0x8086", "0x0A22"); // Intel(R) Iris(TM) Graphics 5100, Gen7.5, Haswell
  1969. BLOCK_DEVICE("0x8086", "0x0A2A");
  1970. BLOCK_DEVICE("0x8086", "0x0A2B");
  1971. BLOCK_DEVICE("0x8086", "0x0A2E");
  1972. BLOCK_DEVICE("Intel", "Intel(R) Iris(TM) Pro Graphics 5200");
  1973. BLOCK_DEVICE("0x8086", "0x0D22"); // Intel(R) Iris(TM) Pro Graphics 5200, Gen7.5, Haswell
  1974. BLOCK_DEVICE("0x8086", "0x0D26");
  1975. BLOCK_DEVICE("0x8086", "0x0D2A");
  1976. BLOCK_DEVICE("0x8086", "0x0D2B");
  1977. BLOCK_DEVICE("0x8086", "0x0D2E");
  1978. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 400");
  1979. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 405");
  1980. BLOCK_DEVICE("0x8086", "0x22B0"); // Intel(R) HD Graphics, Gen8, Cherryview Braswell
  1981. BLOCK_DEVICE("0x8086", "0x22B1");
  1982. BLOCK_DEVICE("0x8086", "0x22B2");
  1983. BLOCK_DEVICE("0x8086", "0x22B3");
  1984. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 5300");
  1985. BLOCK_DEVICE("0x8086", "0x161E"); // Intel(R) HD Graphics 5300, Gen8, Broadwell
  1986. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 5500");
  1987. BLOCK_DEVICE("0x8086", "0x1616"); // Intel(R) HD Graphics 5500, Gen8, Broadwell
  1988. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 5600");
  1989. BLOCK_DEVICE("0x8086", "0x1612"); // Intel(R) HD Graphics 5600, Gen8, Broadwell
  1990. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 6000");
  1991. BLOCK_DEVICE("0x8086", "0x1626"); // Intel(R) HD Graphics 6000, Gen8, Broadwell
  1992. BLOCK_DEVICE("Intel", "Intel(R) Iris(TM) Graphics 6100");
  1993. BLOCK_DEVICE("0x8086", "0x162B"); // Intel(R) Iris(TM) Graphics 6100, Gen8, Broadwell
  1994. BLOCK_DEVICE("Intel", "Intel(R) Iris(TM) Pro Graphics 6200");
  1995. BLOCK_DEVICE("0x8086", "0x1622"); // Intel(R) Iris(TM) Pro Graphics 6200, Gen8, Broadwell
  1996. BLOCK_DEVICE("Intel", "Intel(R) Iris(TM) Pro Graphics P6300");
  1997. BLOCK_DEVICE("0x8086", "0x162A"); // Intel(R) Iris(TM) Pro Graphics P6300, Gen8, Broadwell
  1998. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 500");
  1999. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 505");
  2000. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 510");
  2001. BLOCK_DEVICE("0x8086", "0x1902"); // Intel(R) HD Graphics 510, Gen9, Skylake
  2002. BLOCK_DEVICE("0x8086", "0x1906");
  2003. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 520");
  2004. BLOCK_DEVICE("0x8086", "0x1916"); // Intel(R) HD Graphics 520, Gen9, Skylake
  2005. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 530");
  2006. BLOCK_DEVICE("0x8086", "0x1912"); // Intel(R) HD Graphics 530, Gen9, Skylake
  2007. BLOCK_DEVICE("0x8086", "0x191B");
  2008. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics P530");
  2009. BLOCK_DEVICE("0x8086", "0x191D"); // Intel(R) HD Graphics P530, Gen9, Skylake
  2010. BLOCK_DEVICE("Intel", "Intel(R) HD Graphics 515");
  2011. BLOCK_DEVICE("0x8086", "0x191E"); // Intel(R) HD Graphics 515, Gen9, Skylake
  2012. BLOCK_DEVICE("Intel", "Intel(R) Iris Graphics 540");
  2013. BLOCK_DEVICE("0x8086", "0x1926"); // Intel(R) Iris Graphics 540, Gen9, Skylake
  2014. BLOCK_DEVICE("0x8086", "0x1927");
  2015. BLOCK_DEVICE("Intel", "Intel(R) Iris Pro Graphics 580");
  2016. BLOCK_DEVICE("0x8086", "0x193B"); // Intel(R) Iris Pro Graphics 580, Gen9, Skylake
  2017. BLOCK_DEVICE("Intel", "Intel(R) Iris Pro Graphics P580");
  2018. BLOCK_DEVICE("0x8086", "0x193D"); // Intel(R) Iris Pro Graphics P580, Gen9, Skylake
  2019. #undef BLOCK_DEVICE
  2020. GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::ARRAY, "rendering/gl_compatibility/force_angle_on_devices", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::DICTIONARY, PROPERTY_HINT_NONE, String())), device_blocklist);
  2021. }
  2022. // Start with RenderingDevice-based backends.
  2023. #ifdef RD_ENABLED
  2024. renderer_hints = "forward_plus,mobile";
  2025. default_renderer_mobile = "mobile";
  2026. #endif
  2027. // And Compatibility next, or first if Vulkan is disabled.
  2028. #ifdef GLES3_ENABLED
  2029. if (!renderer_hints.is_empty()) {
  2030. renderer_hints += ",";
  2031. }
  2032. renderer_hints += "gl_compatibility";
  2033. if (default_renderer_mobile.is_empty()) {
  2034. default_renderer_mobile = "gl_compatibility";
  2035. }
  2036. // Default to Compatibility when using the project manager.
  2037. if (rendering_driver.is_empty() && rendering_method.is_empty() && project_manager) {
  2038. rendering_driver = "opengl3";
  2039. rendering_method = "gl_compatibility";
  2040. default_renderer_mobile = "gl_compatibility";
  2041. }
  2042. #endif
  2043. if (renderer_hints.is_empty()) {
  2044. ERR_PRINT("No renderers available.");
  2045. }
  2046. if (!rendering_method.is_empty()) {
  2047. if (rendering_method != "forward_plus" &&
  2048. rendering_method != "mobile" &&
  2049. rendering_method != "gl_compatibility") {
  2050. OS::get_singleton()->print("Unknown rendering method '%s', aborting.\nValid options are ",
  2051. rendering_method.utf8().get_data());
  2052. const Vector<String> rendering_method_hints = renderer_hints.split(",");
  2053. for (int i = 0; i < rendering_method_hints.size(); i++) {
  2054. if (i == rendering_method_hints.size() - 1) {
  2055. OS::get_singleton()->print(" and ");
  2056. } else if (i != 0) {
  2057. OS::get_singleton()->print(", ");
  2058. }
  2059. OS::get_singleton()->print("'%s'", rendering_method_hints[i].utf8().get_data());
  2060. }
  2061. OS::get_singleton()->print(".\n");
  2062. goto error;
  2063. }
  2064. }
  2065. if (!rendering_driver.is_empty()) {
  2066. // As the rendering drivers available may depend on the display driver and renderer
  2067. // selected, we can't do an exhaustive check here, but we can look through all
  2068. // the options in all the display drivers for a match.
  2069. bool found = false;
  2070. for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
  2071. Vector<String> r_drivers = DisplayServer::get_create_function_rendering_drivers(i);
  2072. for (int d = 0; d < r_drivers.size(); d++) {
  2073. if (rendering_driver == r_drivers[d]) {
  2074. found = true;
  2075. break;
  2076. }
  2077. }
  2078. }
  2079. if (!found) {
  2080. OS::get_singleton()->print("Unknown rendering driver '%s', aborting.\nValid options are ",
  2081. rendering_driver.utf8().get_data());
  2082. // Deduplicate driver entries, as a rendering driver may be supported by several display servers.
  2083. Vector<String> unique_rendering_drivers;
  2084. for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
  2085. Vector<String> r_drivers = DisplayServer::get_create_function_rendering_drivers(i);
  2086. for (int d = 0; d < r_drivers.size(); d++) {
  2087. if (!unique_rendering_drivers.has(r_drivers[d])) {
  2088. unique_rendering_drivers.append(r_drivers[d]);
  2089. }
  2090. }
  2091. }
  2092. for (int i = 0; i < unique_rendering_drivers.size(); i++) {
  2093. if (i == unique_rendering_drivers.size() - 1) {
  2094. OS::get_singleton()->print(" and ");
  2095. } else if (i != 0) {
  2096. OS::get_singleton()->print(", ");
  2097. }
  2098. OS::get_singleton()->print("'%s'", unique_rendering_drivers[i].utf8().get_data());
  2099. }
  2100. OS::get_singleton()->print(".\n");
  2101. goto error;
  2102. }
  2103. // Set a default renderer if none selected. Try to choose one that matches the driver.
  2104. if (rendering_method.is_empty()) {
  2105. if (rendering_driver == "opengl3" || rendering_driver == "opengl3_angle" || rendering_driver == "opengl3_es") {
  2106. rendering_method = "gl_compatibility";
  2107. } else {
  2108. rendering_method = "forward_plus";
  2109. }
  2110. }
  2111. // Now validate whether the selected driver matches with the renderer.
  2112. bool valid_combination = false;
  2113. Vector<String> available_drivers;
  2114. if (rendering_method == "forward_plus" || rendering_method == "mobile") {
  2115. #ifdef VULKAN_ENABLED
  2116. available_drivers.push_back("vulkan");
  2117. #endif
  2118. #ifdef D3D12_ENABLED
  2119. available_drivers.push_back("d3d12");
  2120. #endif
  2121. #ifdef METAL_ENABLED
  2122. available_drivers.push_back("metal");
  2123. #endif
  2124. }
  2125. #ifdef GLES3_ENABLED
  2126. if (rendering_method == "gl_compatibility") {
  2127. available_drivers.push_back("opengl3");
  2128. available_drivers.push_back("opengl3_angle");
  2129. available_drivers.push_back("opengl3_es");
  2130. }
  2131. #endif
  2132. if (available_drivers.is_empty()) {
  2133. OS::get_singleton()->print("Unknown renderer name '%s', aborting.\n", rendering_method.utf8().get_data());
  2134. goto error;
  2135. }
  2136. for (int i = 0; i < available_drivers.size(); i++) {
  2137. if (rendering_driver == available_drivers[i]) {
  2138. valid_combination = true;
  2139. break;
  2140. }
  2141. }
  2142. if (!valid_combination) {
  2143. OS::get_singleton()->print("Invalid renderer/driver combination '%s' and '%s', aborting. %s only supports the following drivers ", rendering_method.utf8().get_data(), rendering_driver.utf8().get_data(), rendering_method.utf8().get_data());
  2144. for (int d = 0; d < available_drivers.size(); d++) {
  2145. OS::get_singleton()->print("'%s', ", available_drivers[d].utf8().get_data());
  2146. }
  2147. OS::get_singleton()->print(".\n");
  2148. goto error;
  2149. }
  2150. }
  2151. default_renderer = renderer_hints.get_slice(",", 0);
  2152. GLOBAL_DEF_RST_BASIC(PropertyInfo(Variant::STRING, "rendering/renderer/rendering_method", PROPERTY_HINT_ENUM, renderer_hints), default_renderer);
  2153. GLOBAL_DEF_RST_BASIC("rendering/renderer/rendering_method.mobile", default_renderer_mobile);
  2154. GLOBAL_DEF_RST_BASIC("rendering/renderer/rendering_method.web", "gl_compatibility"); // This is a bit of a hack until we have WebGPU support.
  2155. // Default to ProjectSettings default if nothing set on the command line.
  2156. if (rendering_method.is_empty()) {
  2157. rendering_method = GLOBAL_GET("rendering/renderer/rendering_method");
  2158. }
  2159. if (rendering_driver.is_empty()) {
  2160. if (rendering_method == "gl_compatibility") {
  2161. rendering_driver = GLOBAL_GET("rendering/gl_compatibility/driver");
  2162. } else {
  2163. rendering_driver = GLOBAL_GET("rendering/rendering_device/driver");
  2164. }
  2165. }
  2166. // always convert to lower case for consistency in the code
  2167. rendering_driver = rendering_driver.to_lower();
  2168. OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
  2169. OS::get_singleton()->set_current_rendering_method(rendering_method);
  2170. #ifdef TOOLS_ENABLED
  2171. if (!force_res && project_manager) {
  2172. // Ensure splash screen size matches the project manager window size
  2173. // (see `editor/project_manager.cpp` for defaults).
  2174. window_size.width = ProjectManager::DEFAULT_WINDOW_WIDTH;
  2175. window_size.height = ProjectManager::DEFAULT_WINDOW_HEIGHT;
  2176. }
  2177. #endif
  2178. if (use_custom_res) {
  2179. if (!force_res) {
  2180. window_size.width = GLOBAL_GET("display/window/size/viewport_width");
  2181. window_size.height = GLOBAL_GET("display/window/size/viewport_height");
  2182. if (globals->has_setting("display/window/size/window_width_override") &&
  2183. globals->has_setting("display/window/size/window_height_override")) {
  2184. int desired_width = GLOBAL_GET("display/window/size/window_width_override");
  2185. if (desired_width > 0) {
  2186. window_size.width = desired_width;
  2187. }
  2188. int desired_height = GLOBAL_GET("display/window/size/window_height_override");
  2189. if (desired_height > 0) {
  2190. window_size.height = desired_height;
  2191. }
  2192. }
  2193. }
  2194. if (!bool(GLOBAL_GET("display/window/size/resizable"))) {
  2195. window_flags |= DisplayServer::WINDOW_FLAG_RESIZE_DISABLED_BIT;
  2196. }
  2197. if (bool(GLOBAL_GET("display/window/size/borderless"))) {
  2198. window_flags |= DisplayServer::WINDOW_FLAG_BORDERLESS_BIT;
  2199. }
  2200. if (bool(GLOBAL_GET("display/window/size/always_on_top"))) {
  2201. window_flags |= DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP_BIT;
  2202. }
  2203. if (bool(GLOBAL_GET("display/window/size/transparent"))) {
  2204. window_flags |= DisplayServer::WINDOW_FLAG_TRANSPARENT_BIT;
  2205. }
  2206. if (bool(GLOBAL_GET("display/window/size/extend_to_title"))) {
  2207. window_flags |= DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE_BIT;
  2208. }
  2209. if (bool(GLOBAL_GET("display/window/size/no_focus"))) {
  2210. window_flags |= DisplayServer::WINDOW_FLAG_NO_FOCUS_BIT;
  2211. }
  2212. if (bool(GLOBAL_GET("display/window/size/sharp_corners"))) {
  2213. window_flags |= DisplayServer::WINDOW_FLAG_SHARP_CORNERS_BIT;
  2214. }
  2215. window_mode = (DisplayServer::WindowMode)(GLOBAL_GET("display/window/size/mode").operator int());
  2216. int initial_position_type = GLOBAL_GET("display/window/size/initial_position_type").operator int();
  2217. if (initial_position_type == Window::WINDOW_INITIAL_POSITION_ABSOLUTE) { // Absolute.
  2218. if (!init_use_custom_pos) {
  2219. init_custom_pos = GLOBAL_GET("display/window/size/initial_position").operator Vector2i();
  2220. init_use_custom_pos = true;
  2221. }
  2222. } else if (initial_position_type == Window::WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN || initial_position_type == Window::WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN) { // Center of Primary Screen.
  2223. if (!init_use_custom_screen) {
  2224. init_screen = DisplayServer::SCREEN_PRIMARY;
  2225. init_use_custom_screen = true;
  2226. }
  2227. } else if (initial_position_type == Window::WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN) { // Center of Other Screen.
  2228. if (!init_use_custom_screen) {
  2229. init_screen = GLOBAL_GET("display/window/size/initial_screen").operator int();
  2230. init_use_custom_screen = true;
  2231. }
  2232. } else if (initial_position_type == Window::WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_MOUSE_FOCUS) { // Center of Screen With Mouse Pointer.
  2233. if (!init_use_custom_screen) {
  2234. init_screen = DisplayServer::SCREEN_WITH_MOUSE_FOCUS;
  2235. init_use_custom_screen = true;
  2236. }
  2237. } else if (initial_position_type == Window::WINDOW_INITIAL_POSITION_CENTER_SCREEN_WITH_KEYBOARD_FOCUS) { // Center of Screen With Keyboard Focus.
  2238. if (!init_use_custom_screen) {
  2239. init_screen = DisplayServer::SCREEN_WITH_KEYBOARD_FOCUS;
  2240. init_use_custom_screen = true;
  2241. }
  2242. }
  2243. }
  2244. GLOBAL_DEF_BASIC("internationalization/locale/include_text_server_data", false);
  2245. OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", true);
  2246. OS::get_singleton()->_allow_layered = GLOBAL_DEF_RST("display/window/per_pixel_transparency/allowed", false);
  2247. #ifdef TOOLS_ENABLED
  2248. if (editor || project_manager) {
  2249. // The editor and project manager always detect and use hiDPI if needed.
  2250. OS::get_singleton()->_allow_hidpi = true;
  2251. }
  2252. #endif
  2253. if (separate_thread_render == -1) {
  2254. separate_thread_render = (int)GLOBAL_DEF("rendering/driver/threads/thread_model", OS::RENDER_THREAD_SAFE) == OS::RENDER_SEPARATE_THREAD;
  2255. }
  2256. if (editor || project_manager) {
  2257. // Editor and project manager cannot run with rendering in a separate thread (they will crash on startup).
  2258. separate_thread_render = 0;
  2259. }
  2260. #if !defined(THREADS_ENABLED)
  2261. separate_thread_render = 0;
  2262. #endif
  2263. OS::get_singleton()->_separate_thread_render = separate_thread_render;
  2264. /* Determine audio and video drivers */
  2265. // Display driver, e.g. X11, Wayland.
  2266. // Make sure that headless is the last one, which it is assumed to be by design.
  2267. DEV_ASSERT(NULL_DISPLAY_DRIVER == DisplayServer::get_create_function_name(DisplayServer::get_create_function_count() - 1));
  2268. GLOBAL_DEF_NOVAL("display/display_server/driver", "default");
  2269. GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.windows", PROPERTY_HINT_ENUM_SUGGESTION, "default,windows,headless"), "default");
  2270. GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.linuxbsd", PROPERTY_HINT_ENUM_SUGGESTION, "default,x11,wayland,headless"), "default");
  2271. GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.android", PROPERTY_HINT_ENUM_SUGGESTION, "default,android,headless"), "default");
  2272. GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.ios", PROPERTY_HINT_ENUM_SUGGESTION, "default,iOS,headless"), "default");
  2273. GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.macos", PROPERTY_HINT_ENUM_SUGGESTION, "default,macos,headless"), "default");
  2274. GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name());
  2275. if (audio_driver.is_empty()) { // Specified in project.godot.
  2276. if (project_manager) {
  2277. // The project manager doesn't need to play sound (TTS audio output is not emitted by Godot, but by the system itself).
  2278. // Disable audio output so it doesn't appear in the list of applications outputting sound in the OS.
  2279. // On macOS, this also prevents the project manager from inhibiting suspend.
  2280. audio_driver = "Dummy";
  2281. } else {
  2282. audio_driver = GLOBAL_GET("audio/driver/driver");
  2283. }
  2284. }
  2285. // Make sure that dummy is the last one, which it is assumed to be by design.
  2286. DEV_ASSERT(NULL_AUDIO_DRIVER == AudioDriverManager::get_driver(AudioDriverManager::get_driver_count() - 1)->get_name());
  2287. for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
  2288. if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
  2289. audio_driver_idx = i;
  2290. break;
  2291. }
  2292. }
  2293. if (audio_driver_idx < 0) {
  2294. // If the requested driver wasn't found, pick the first entry.
  2295. // If all else failed it would be the dummy driver (no sound).
  2296. audio_driver_idx = 0;
  2297. }
  2298. if (Engine::get_singleton()->get_write_movie_path() != String()) {
  2299. // Always use dummy driver for audio driver (which is last), also in no threaded mode.
  2300. audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
  2301. AudioDriverDummy::get_dummy_singleton()->set_use_threads(false);
  2302. }
  2303. {
  2304. window_orientation = DisplayServer::ScreenOrientation(int(GLOBAL_DEF_BASIC("display/window/handheld/orientation", DisplayServer::ScreenOrientation::SCREEN_LANDSCAPE)));
  2305. }
  2306. {
  2307. window_vsync_mode = DisplayServer::VSyncMode(int(GLOBAL_DEF_BASIC("display/window/vsync/vsync_mode", DisplayServer::VSyncMode::VSYNC_ENABLED)));
  2308. if (disable_vsync) {
  2309. window_vsync_mode = DisplayServer::VSyncMode::VSYNC_DISABLED;
  2310. }
  2311. }
  2312. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/driver/output_latency", PROPERTY_HINT_RANGE, "1,100,1"), 15);
  2313. // Use a safer default output_latency for web to avoid audio cracking on low-end devices, especially mobile.
  2314. GLOBAL_DEF_RST("audio/driver/output_latency.web", 50);
  2315. Engine::get_singleton()->set_audio_output_latency(GLOBAL_GET("audio/driver/output_latency"));
  2316. #if defined(MACOS_ENABLED) || defined(IOS_ENABLED)
  2317. OS::get_singleton()->set_environment("MVK_CONFIG_LOG_LEVEL", OS::get_singleton()->_verbose_stdout ? "3" : "1"); // 1 = Errors only, 3 = Info
  2318. #endif
  2319. if (frame_delay == 0) {
  2320. frame_delay = GLOBAL_DEF(PropertyInfo(Variant::INT, "application/run/frame_delay_msec", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), 0);
  2321. if (Engine::get_singleton()->is_editor_hint()) {
  2322. frame_delay = 0;
  2323. }
  2324. }
  2325. if (audio_output_latency >= 1) {
  2326. Engine::get_singleton()->set_audio_output_latency(audio_output_latency);
  2327. }
  2328. GLOBAL_DEF("display/window/ios/allow_high_refresh_rate", true);
  2329. GLOBAL_DEF("display/window/ios/hide_home_indicator", true);
  2330. GLOBAL_DEF("display/window/ios/hide_status_bar", true);
  2331. GLOBAL_DEF("display/window/ios/suppress_ui_gesture", true);
  2332. #ifndef _3D_DISABLED
  2333. // XR project settings.
  2334. GLOBAL_DEF_RST_BASIC("xr/openxr/enabled", false);
  2335. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "xr/openxr/default_action_map", PROPERTY_HINT_FILE, "*.tres"), "res://openxr_action_map.tres");
  2336. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/form_factor", PROPERTY_HINT_ENUM, "Head Mounted,Handheld"), "0");
  2337. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/view_configuration", PROPERTY_HINT_ENUM, "Mono,Stereo"), "1"); // "Mono,Stereo,Quad,Observer"
  2338. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/reference_space", PROPERTY_HINT_ENUM, "Local,Stage,Local Floor"), "1");
  2339. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/environment_blend_mode", PROPERTY_HINT_ENUM, "Opaque,Additive,Alpha"), "0");
  2340. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/foveation_level", PROPERTY_HINT_ENUM, "Off,Low,Medium,High"), "0");
  2341. GLOBAL_DEF_BASIC("xr/openxr/foveation_dynamic", false);
  2342. GLOBAL_DEF_BASIC("xr/openxr/submit_depth_buffer", false);
  2343. GLOBAL_DEF_BASIC("xr/openxr/startup_alert", true);
  2344. // OpenXR project extensions settings.
  2345. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/extensions/debug_utils", PROPERTY_HINT_ENUM, "Disabled,Error,Warning,Info,Verbose"), "0");
  2346. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/extensions/debug_message_types", PROPERTY_HINT_FLAGS, "General,Validation,Performance,Conformance"), "15");
  2347. GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking", false);
  2348. GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_unobstructed_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT
  2349. GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_controller_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT
  2350. GLOBAL_DEF_RST_BASIC("xr/openxr/extensions/hand_interaction_profile", false);
  2351. GLOBAL_DEF_RST_BASIC("xr/openxr/extensions/eye_gaze_interaction", false);
  2352. // OpenXR Binding modifier settings
  2353. GLOBAL_DEF_BASIC("xr/openxr/binding_modifiers/analog_threshold", false);
  2354. GLOBAL_DEF_RST_BASIC("xr/openxr/binding_modifiers/dpad_binding", false);
  2355. #ifdef TOOLS_ENABLED
  2356. // Disabled for now, using XR inside of the editor we'll be working on during the coming months.
  2357. // editor settings (it seems we're too early in the process when setting up rendering, to access editor settings...)
  2358. // EDITOR_DEF_RST("xr/openxr/in_editor", false);
  2359. // GLOBAL_DEF("xr/openxr/in_editor", false);
  2360. #endif // TOOLS_ENABLED
  2361. #endif // _3D_DISABLED
  2362. Engine::get_singleton()->set_frame_delay(frame_delay);
  2363. message_queue = memnew(MessageQueue);
  2364. Thread::release_main_thread(); // If setup2() is called from another thread, that one will become main thread, so preventively release this one.
  2365. set_current_thread_safe_for_nodes(false);
  2366. #if defined(STEAMAPI_ENABLED)
  2367. if (editor || project_manager) {
  2368. steam_tracker = memnew(SteamTracker);
  2369. }
  2370. #endif
  2371. OS::get_singleton()->benchmark_end_measure("Startup", "Main::Setup");
  2372. if (p_second_phase) {
  2373. exit_err = setup2();
  2374. if (exit_err != OK) {
  2375. goto error;
  2376. }
  2377. }
  2378. return OK;
  2379. error:
  2380. text_driver = "";
  2381. display_driver = "";
  2382. audio_driver = "";
  2383. tablet_driver = "";
  2384. Engine::get_singleton()->set_write_movie_path(String());
  2385. project_path = "";
  2386. args.clear();
  2387. main_args.clear();
  2388. if (show_help) {
  2389. print_help(execpath);
  2390. }
  2391. if (editor) {
  2392. OS::get_singleton()->remove_lock_file();
  2393. }
  2394. EngineDebugger::deinitialize();
  2395. if (performance) {
  2396. memdelete(performance);
  2397. }
  2398. if (input_map) {
  2399. memdelete(input_map);
  2400. }
  2401. if (translation_server) {
  2402. memdelete(translation_server);
  2403. }
  2404. if (globals) {
  2405. memdelete(globals);
  2406. }
  2407. if (packed_data) {
  2408. memdelete(packed_data);
  2409. }
  2410. unregister_core_driver_types();
  2411. unregister_core_extensions();
  2412. if (engine) {
  2413. memdelete(engine);
  2414. }
  2415. unregister_core_types();
  2416. OS::get_singleton()->_cmdline.clear();
  2417. OS::get_singleton()->_user_args.clear();
  2418. if (message_queue) {
  2419. memdelete(message_queue);
  2420. }
  2421. OS::get_singleton()->benchmark_end_measure("Startup", "Main::Setup");
  2422. #if defined(STEAMAPI_ENABLED)
  2423. if (steam_tracker) {
  2424. memdelete(steam_tracker);
  2425. }
  2426. #endif
  2427. OS::get_singleton()->finalize_core();
  2428. locale = String();
  2429. return exit_err;
  2430. }
  2431. Error _parse_resource_dummy(void *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) {
  2432. VariantParser::Token token;
  2433. VariantParser::get_token(p_stream, token, line, r_err_str);
  2434. if (token.type != VariantParser::TK_NUMBER && token.type != VariantParser::TK_STRING) {
  2435. r_err_str = "Expected number (old style sub-resource index) or String (ext-resource ID)";
  2436. return ERR_PARSE_ERROR;
  2437. }
  2438. r_res.unref();
  2439. VariantParser::get_token(p_stream, token, line, r_err_str);
  2440. if (token.type != VariantParser::TK_PARENTHESIS_CLOSE) {
  2441. r_err_str = "Expected ')'";
  2442. return ERR_PARSE_ERROR;
  2443. }
  2444. return OK;
  2445. }
  2446. Error Main::setup2(bool p_show_boot_logo) {
  2447. OS::get_singleton()->benchmark_begin_measure("Startup", "Main::Setup2");
  2448. Thread::make_main_thread(); // Make whatever thread call this the main thread.
  2449. set_current_thread_safe_for_nodes(true);
  2450. // Don't use rich formatting to prevent ANSI escape codes from being written to log files.
  2451. print_header(false);
  2452. #ifdef TOOLS_ENABLED
  2453. if (editor || project_manager || cmdline_tool) {
  2454. OS::get_singleton()->benchmark_begin_measure("Startup", "Initialize Early Settings");
  2455. EditorPaths::create();
  2456. // Editor setting class is not available, load config directly.
  2457. if (!init_use_custom_screen && (editor || project_manager) && EditorPaths::get_singleton()->are_paths_valid()) {
  2458. ERR_FAIL_COND_V(!DirAccess::dir_exists_absolute(EditorPaths::get_singleton()->get_config_dir()), FAILED);
  2459. String config_file_path = EditorSettings::get_existing_settings_path();
  2460. if (FileAccess::exists(config_file_path)) {
  2461. Error err;
  2462. Ref<FileAccess> f = FileAccess::open(config_file_path, FileAccess::READ, &err);
  2463. if (f.is_valid()) {
  2464. VariantParser::StreamFile stream;
  2465. stream.f = f;
  2466. String assign;
  2467. Variant value;
  2468. VariantParser::Tag next_tag;
  2469. int lines = 0;
  2470. String error_text;
  2471. VariantParser::ResourceParser rp_new;
  2472. rp_new.ext_func = _parse_resource_dummy;
  2473. rp_new.sub_func = _parse_resource_dummy;
  2474. bool screen_found = false;
  2475. String screen_property;
  2476. bool prefer_wayland_found = false;
  2477. bool prefer_wayland = false;
  2478. if (editor) {
  2479. screen_property = "interface/editor/editor_screen";
  2480. } else if (project_manager) {
  2481. screen_property = "interface/editor/project_manager_screen";
  2482. } else {
  2483. // Skip.
  2484. screen_found = true;
  2485. }
  2486. if (!display_driver.is_empty()) {
  2487. // Skip.
  2488. prefer_wayland_found = true;
  2489. }
  2490. while (!screen_found || !prefer_wayland_found) {
  2491. assign = Variant();
  2492. next_tag.fields.clear();
  2493. next_tag.name = String();
  2494. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, &rp_new, true);
  2495. if (err == ERR_FILE_EOF) {
  2496. break;
  2497. }
  2498. if (err == OK && !assign.is_empty()) {
  2499. if (!screen_found && assign == screen_property) {
  2500. init_screen = value;
  2501. screen_found = true;
  2502. if (editor) {
  2503. restore_editor_window_layout = value.operator int() == EditorSettings::InitialScreen::INITIAL_SCREEN_AUTO;
  2504. }
  2505. }
  2506. if (!prefer_wayland_found && assign == "run/platforms/linuxbsd/prefer_wayland") {
  2507. prefer_wayland = value;
  2508. prefer_wayland_found = true;
  2509. }
  2510. }
  2511. }
  2512. if (display_driver.is_empty()) {
  2513. if (prefer_wayland) {
  2514. display_driver = "wayland";
  2515. } else {
  2516. display_driver = "default";
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. if (found_project && EditorPaths::get_singleton()->is_self_contained()) {
  2523. if (ProjectSettings::get_singleton()->get_resource_path() == OS::get_singleton()->get_executable_path().get_base_dir()) {
  2524. ERR_PRINT("You are trying to run a self-contained editor at the same location as a project. This is not allowed, since editor files will mix with project files.");
  2525. OS::get_singleton()->set_exit_code(EXIT_FAILURE);
  2526. return FAILED;
  2527. }
  2528. }
  2529. bool has_command_line_window_override = init_use_custom_pos || init_use_custom_screen || init_windowed;
  2530. if (editor && !has_command_line_window_override && restore_editor_window_layout) {
  2531. Ref<ConfigFile> config;
  2532. config.instantiate();
  2533. // Load and amend existing config if it exists.
  2534. Error err = config->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("editor_layout.cfg"));
  2535. if (err == OK) {
  2536. init_screen = config->get_value("EditorWindow", "screen", init_screen);
  2537. String mode = config->get_value("EditorWindow", "mode", "maximized");
  2538. window_size = config->get_value("EditorWindow", "size", window_size);
  2539. if (mode == "windowed") {
  2540. window_mode = DisplayServer::WINDOW_MODE_WINDOWED;
  2541. init_windowed = true;
  2542. } else if (mode == "fullscreen") {
  2543. window_mode = DisplayServer::WINDOW_MODE_FULLSCREEN;
  2544. init_fullscreen = true;
  2545. } else {
  2546. window_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
  2547. init_maximized = true;
  2548. }
  2549. if (init_windowed) {
  2550. init_use_custom_pos = true;
  2551. init_custom_pos = config->get_value("EditorWindow", "position", Vector2i(0, 0));
  2552. }
  2553. }
  2554. }
  2555. if (init_screen == EditorSettings::InitialScreen::INITIAL_SCREEN_AUTO) {
  2556. init_screen = DisplayServer::SCREEN_PRIMARY;
  2557. }
  2558. OS::get_singleton()->benchmark_end_measure("Startup", "Initialize Early Settings");
  2559. }
  2560. #endif
  2561. OS::get_singleton()->benchmark_begin_measure("Startup", "Servers");
  2562. tsman = memnew(TextServerManager);
  2563. if (tsman) {
  2564. Ref<TextServerDummy> ts;
  2565. ts.instantiate();
  2566. tsman->add_interface(ts);
  2567. }
  2568. #ifndef _3D_DISABLED
  2569. physics_server_3d_manager = memnew(PhysicsServer3DManager);
  2570. #endif // _3D_DISABLED
  2571. physics_server_2d_manager = memnew(PhysicsServer2DManager);
  2572. register_server_types();
  2573. {
  2574. OS::get_singleton()->benchmark_begin_measure("Servers", "Modules and Extensions");
  2575. initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
  2576. GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
  2577. OS::get_singleton()->benchmark_end_measure("Servers", "Modules and Extensions");
  2578. }
  2579. /* Initialize Input */
  2580. {
  2581. OS::get_singleton()->benchmark_begin_measure("Servers", "Input");
  2582. input = memnew(Input);
  2583. OS::get_singleton()->initialize_joypads();
  2584. OS::get_singleton()->benchmark_end_measure("Servers", "Input");
  2585. }
  2586. /* Initialize Display Server */
  2587. {
  2588. OS::get_singleton()->benchmark_begin_measure("Servers", "Display");
  2589. if (display_driver.is_empty()) {
  2590. display_driver = GLOBAL_GET("display/display_server/driver");
  2591. }
  2592. int display_driver_idx = -1;
  2593. if (display_driver.is_empty() || display_driver == "default") {
  2594. display_driver_idx = 0;
  2595. } else {
  2596. for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
  2597. String name = DisplayServer::get_create_function_name(i);
  2598. if (display_driver == name) {
  2599. display_driver_idx = i;
  2600. break;
  2601. }
  2602. }
  2603. if (display_driver_idx < 0) {
  2604. // If the requested driver wasn't found, pick the first entry.
  2605. // If all else failed it would be the headless server.
  2606. display_driver_idx = 0;
  2607. }
  2608. }
  2609. Vector2i *window_position = nullptr;
  2610. Vector2i position = init_custom_pos;
  2611. if (init_use_custom_pos) {
  2612. window_position = &position;
  2613. }
  2614. Color boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", boot_splash_bg_color);
  2615. DisplayServer::set_early_window_clear_color_override(true, boot_bg_color);
  2616. DisplayServer::Context context;
  2617. if (editor) {
  2618. context = DisplayServer::CONTEXT_EDITOR;
  2619. } else if (project_manager) {
  2620. context = DisplayServer::CONTEXT_PROJECTMAN;
  2621. } else {
  2622. context = DisplayServer::CONTEXT_ENGINE;
  2623. }
  2624. if (init_embed_parent_window_id) {
  2625. // Reset flags and other settings to be sure it's borderless and windowed. The position and size should have been initialized correctly
  2626. // from --position and --resolution parameters.
  2627. window_mode = DisplayServer::WINDOW_MODE_WINDOWED;
  2628. window_flags = DisplayServer::WINDOW_FLAG_BORDERLESS_BIT;
  2629. }
  2630. // rendering_driver now held in static global String in main and initialized in setup()
  2631. Error err;
  2632. display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_vsync_mode, window_flags, window_position, window_size, init_screen, context, init_embed_parent_window_id, err);
  2633. if (err != OK || display_server == nullptr) {
  2634. String last_name = DisplayServer::get_create_function_name(display_driver_idx);
  2635. // We can't use this display server, try other ones as fallback.
  2636. // Skip headless (always last registered) because that's not what users
  2637. // would expect if they didn't request it explicitly.
  2638. for (int i = 0; i < DisplayServer::get_create_function_count() - 1; i++) {
  2639. if (i == display_driver_idx) {
  2640. continue; // Don't try the same twice.
  2641. }
  2642. String name = DisplayServer::get_create_function_name(i);
  2643. WARN_PRINT(vformat("Display driver %s failed, falling back to %s.", last_name, name));
  2644. display_server = DisplayServer::create(i, rendering_driver, window_mode, window_vsync_mode, window_flags, window_position, window_size, init_screen, context, init_embed_parent_window_id, err);
  2645. if (err == OK && display_server != nullptr) {
  2646. break;
  2647. }
  2648. }
  2649. }
  2650. if (err != OK || display_server == nullptr) {
  2651. ERR_PRINT("Unable to create DisplayServer, all display drivers failed.\nUse \"--headless\" command line argument to run the engine in headless mode if this is desired (e.g. for continuous integration).");
  2652. if (display_server) {
  2653. memdelete(display_server);
  2654. }
  2655. GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
  2656. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
  2657. unregister_server_types();
  2658. if (input) {
  2659. memdelete(input);
  2660. }
  2661. if (tsman) {
  2662. memdelete(tsman);
  2663. }
  2664. #ifndef _3D_DISABLED
  2665. if (physics_server_3d_manager) {
  2666. memdelete(physics_server_3d_manager);
  2667. }
  2668. #endif // _3D_DISABLED
  2669. if (physics_server_2d_manager) {
  2670. memdelete(physics_server_2d_manager);
  2671. }
  2672. return err;
  2673. }
  2674. if (display_server->has_feature(DisplayServer::FEATURE_ORIENTATION)) {
  2675. display_server->screen_set_orientation(window_orientation);
  2676. }
  2677. OS::get_singleton()->benchmark_end_measure("Servers", "Display");
  2678. }
  2679. // Max FPS needs to be set after the DisplayServer is created.
  2680. RenderingDevice *rd = RenderingDevice::get_singleton();
  2681. if (rd) {
  2682. rd->_set_max_fps(engine->get_max_fps());
  2683. }
  2684. #ifdef TOOLS_ENABLED
  2685. // If the editor is running in windowed mode, ensure the window rect fits
  2686. // the screen in case screen count or position has changed.
  2687. if (editor && init_windowed) {
  2688. // We still need to check we are actually in windowed mode, because
  2689. // certain platform might only support one fullscreen window.
  2690. if (DisplayServer::get_singleton()->window_get_mode() == DisplayServer::WINDOW_MODE_WINDOWED) {
  2691. Vector2i current_size = DisplayServer::get_singleton()->window_get_size();
  2692. Vector2i current_pos = DisplayServer::get_singleton()->window_get_position();
  2693. int screen = DisplayServer::get_singleton()->window_get_current_screen();
  2694. Rect2i screen_rect = DisplayServer::get_singleton()->screen_get_usable_rect(screen);
  2695. Vector2i adjusted_end = screen_rect.get_end().min(current_pos + current_size);
  2696. Vector2i adjusted_pos = screen_rect.get_position().max(adjusted_end - current_size);
  2697. Vector2i adjusted_size = DisplayServer::get_singleton()->window_get_min_size().max(adjusted_end - adjusted_pos);
  2698. if (current_pos != adjusted_end || current_size != adjusted_size) {
  2699. DisplayServer::get_singleton()->window_set_position(adjusted_pos);
  2700. DisplayServer::get_singleton()->window_set_size(adjusted_size);
  2701. }
  2702. }
  2703. }
  2704. #endif
  2705. if (GLOBAL_GET("debug/settings/stdout/print_fps") || print_fps) {
  2706. // Print requested V-Sync mode at startup to diagnose the printed FPS not going above the monitor refresh rate.
  2707. switch (window_vsync_mode) {
  2708. case DisplayServer::VSyncMode::VSYNC_DISABLED:
  2709. print_line("Requested V-Sync mode: Disabled");
  2710. break;
  2711. case DisplayServer::VSyncMode::VSYNC_ENABLED:
  2712. print_line("Requested V-Sync mode: Enabled - FPS will likely be capped to the monitor refresh rate.");
  2713. break;
  2714. case DisplayServer::VSyncMode::VSYNC_ADAPTIVE:
  2715. print_line("Requested V-Sync mode: Adaptive");
  2716. break;
  2717. case DisplayServer::VSyncMode::VSYNC_MAILBOX:
  2718. print_line("Requested V-Sync mode: Mailbox");
  2719. break;
  2720. }
  2721. }
  2722. if (OS::get_singleton()->_separate_thread_render) {
  2723. WARN_PRINT("The separate rendering thread feature is experimental. Feel free to try it since it will eventually become a stable feature.\n"
  2724. "However, bear in mind that at the moment it can lead to project crashes or instability.\n"
  2725. "So, unless you want to test the engine, set the \"rendering/driver/threads/thread_model\" project setting to 'Safe'.");
  2726. }
  2727. /* Initialize Pen Tablet Driver */
  2728. {
  2729. OS::get_singleton()->benchmark_begin_measure("Servers", "Tablet Driver");
  2730. GLOBAL_DEF_RST_NOVAL("input_devices/pen_tablet/driver", "");
  2731. GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "input_devices/pen_tablet/driver.windows", PROPERTY_HINT_ENUM, "auto,winink,wintab,dummy"), "");
  2732. if (tablet_driver.is_empty()) { // specified in project.godot
  2733. tablet_driver = GLOBAL_GET("input_devices/pen_tablet/driver");
  2734. if (tablet_driver.is_empty()) {
  2735. tablet_driver = DisplayServer::get_singleton()->tablet_get_driver_name(0);
  2736. }
  2737. }
  2738. for (int i = 0; i < DisplayServer::get_singleton()->tablet_get_driver_count(); i++) {
  2739. if (tablet_driver == DisplayServer::get_singleton()->tablet_get_driver_name(i)) {
  2740. DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(i));
  2741. break;
  2742. }
  2743. }
  2744. if (DisplayServer::get_singleton()->tablet_get_current_driver().is_empty()) {
  2745. DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(0));
  2746. }
  2747. print_verbose("Using \"" + DisplayServer::get_singleton()->tablet_get_current_driver() + "\" pen tablet driver...");
  2748. OS::get_singleton()->benchmark_end_measure("Servers", "Tablet Driver");
  2749. }
  2750. /* Initialize Rendering Server */
  2751. {
  2752. OS::get_singleton()->benchmark_begin_measure("Servers", "Rendering");
  2753. rendering_server = memnew(RenderingServerDefault(OS::get_singleton()->is_separate_thread_rendering_enabled()));
  2754. rendering_server->init();
  2755. //rendering_server->call_set_use_vsync(OS::get_singleton()->_use_vsync);
  2756. rendering_server->set_render_loop_enabled(!disable_render_loop);
  2757. if (profile_gpu || (!editor && bool(GLOBAL_GET("debug/settings/stdout/print_gpu_profile")))) {
  2758. rendering_server->set_print_gpu_profile(true);
  2759. }
  2760. if (Engine::get_singleton()->get_write_movie_path() != String()) {
  2761. movie_writer = MovieWriter::find_writer_for_file(Engine::get_singleton()->get_write_movie_path());
  2762. if (movie_writer == nullptr) {
  2763. ERR_PRINT("Can't find movie writer for file type, aborting: " + Engine::get_singleton()->get_write_movie_path());
  2764. Engine::get_singleton()->set_write_movie_path(String());
  2765. }
  2766. }
  2767. OS::get_singleton()->benchmark_end_measure("Servers", "Rendering");
  2768. }
  2769. #ifdef UNIX_ENABLED
  2770. // Print warning after initializing the renderer but before initializing audio.
  2771. if (OS::get_singleton()->get_environment("USER") == "root" && !OS::get_singleton()->has_environment("GODOT_SILENCE_ROOT_WARNING")) {
  2772. WARN_PRINT("Started the engine as `root`/superuser. This is a security risk, and subsystems like audio may not work correctly.\nSet the environment variable `GODOT_SILENCE_ROOT_WARNING` to 1 to silence this warning.");
  2773. }
  2774. #endif
  2775. /* Initialize Audio Driver */
  2776. {
  2777. OS::get_singleton()->benchmark_begin_measure("Servers", "Audio");
  2778. AudioDriverManager::initialize(audio_driver_idx);
  2779. // Right moment to create and initialize the audio server.
  2780. audio_server = memnew(AudioServer);
  2781. audio_server->init();
  2782. OS::get_singleton()->benchmark_end_measure("Servers", "Audio");
  2783. }
  2784. #ifndef _3D_DISABLED
  2785. /* Initialize XR Server */
  2786. {
  2787. OS::get_singleton()->benchmark_begin_measure("Servers", "XR");
  2788. xr_server = memnew(XRServer);
  2789. OS::get_singleton()->benchmark_end_measure("Servers", "XR");
  2790. }
  2791. #endif // _3D_DISABLED
  2792. OS::get_singleton()->benchmark_end_measure("Startup", "Servers");
  2793. #ifndef WEB_ENABLED
  2794. // Add a blank line for readability.
  2795. Engine::get_singleton()->print_header("");
  2796. #endif // WEB_ENABLED
  2797. register_core_singletons();
  2798. /* Initialize the main window and boot screen */
  2799. {
  2800. OS::get_singleton()->benchmark_begin_measure("Startup", "Setup Window and Boot");
  2801. MAIN_PRINT("Main: Setup Logo");
  2802. if (!init_embed_parent_window_id) {
  2803. if (init_windowed) {
  2804. //do none..
  2805. } else if (init_maximized) {
  2806. DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_MAXIMIZED);
  2807. } else if (init_fullscreen) {
  2808. DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_FULLSCREEN);
  2809. }
  2810. if (init_always_on_top) {
  2811. DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP, true);
  2812. }
  2813. }
  2814. Color clear = GLOBAL_DEF_BASIC("rendering/environment/defaults/default_clear_color", Color(0.3, 0.3, 0.3));
  2815. RenderingServer::get_singleton()->set_default_clear_color(clear);
  2816. if (p_show_boot_logo) {
  2817. setup_boot_logo();
  2818. }
  2819. MAIN_PRINT("Main: Clear Color");
  2820. DisplayServer::set_early_window_clear_color_override(false);
  2821. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/icon", PROPERTY_HINT_FILE, "*.png,*.bmp,*.hdr,*.jpg,*.jpeg,*.svg,*.tga,*.exr,*.webp"), String());
  2822. GLOBAL_DEF(PropertyInfo(Variant::STRING, "application/config/macos_native_icon", PROPERTY_HINT_FILE, "*.icns"), String());
  2823. GLOBAL_DEF(PropertyInfo(Variant::STRING, "application/config/windows_native_icon", PROPERTY_HINT_FILE, "*.ico"), String());
  2824. MAIN_PRINT("Main: Touch Input");
  2825. Input *id = Input::get_singleton();
  2826. if (id) {
  2827. bool agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false);
  2828. id->set_agile_input_event_flushing(agile_input_event_flushing);
  2829. if (bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_touch_from_mouse", false)) &&
  2830. !(editor || project_manager)) {
  2831. if (!DisplayServer::get_singleton()->is_touchscreen_available()) {
  2832. //only if no touchscreen ui hint, set emulation
  2833. id->set_emulate_touch_from_mouse(true);
  2834. }
  2835. }
  2836. id->set_emulate_mouse_from_touch(bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_mouse_from_touch", true)));
  2837. if (editor) {
  2838. id->set_emulate_mouse_from_touch(true);
  2839. }
  2840. }
  2841. OS::get_singleton()->benchmark_end_measure("Startup", "Setup Window and Boot");
  2842. }
  2843. MAIN_PRINT("Main: Load Translations and Remaps");
  2844. /* Setup translations and remaps */
  2845. {
  2846. OS::get_singleton()->benchmark_begin_measure("Startup", "Translations and Remaps");
  2847. translation_server->setup(); //register translations, load them, etc.
  2848. if (!locale.is_empty()) {
  2849. translation_server->set_locale(locale);
  2850. }
  2851. translation_server->load_translations();
  2852. ResourceLoader::load_translation_remaps(); //load remaps for resources
  2853. ResourceLoader::load_path_remaps();
  2854. OS::get_singleton()->benchmark_end_measure("Startup", "Translations and Remaps");
  2855. }
  2856. MAIN_PRINT("Main: Load TextServer");
  2857. /* Setup Text Server */
  2858. {
  2859. OS::get_singleton()->benchmark_begin_measure("Startup", "Text Server");
  2860. /* Enum text drivers */
  2861. GLOBAL_DEF_RST("internationalization/rendering/text_driver", "");
  2862. String text_driver_options;
  2863. for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
  2864. const String driver_name = TextServerManager::get_singleton()->get_interface(i)->get_name();
  2865. if (driver_name == "Dummy") {
  2866. // Dummy text driver cannot draw any text, making the editor unusable if selected.
  2867. continue;
  2868. }
  2869. if (!text_driver_options.is_empty() && !text_driver_options.contains_char(',')) {
  2870. // Not the first option; add a comma before it as a separator for the property hint.
  2871. text_driver_options += ",";
  2872. }
  2873. text_driver_options += driver_name;
  2874. }
  2875. ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, "internationalization/rendering/text_driver", PROPERTY_HINT_ENUM, text_driver_options));
  2876. /* Determine text driver */
  2877. if (text_driver.is_empty()) {
  2878. text_driver = GLOBAL_GET("internationalization/rendering/text_driver");
  2879. }
  2880. if (!text_driver.is_empty()) {
  2881. /* Load user selected text server. */
  2882. for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
  2883. if (TextServerManager::get_singleton()->get_interface(i)->get_name() == text_driver) {
  2884. text_driver_idx = i;
  2885. break;
  2886. }
  2887. }
  2888. }
  2889. if (text_driver_idx < 0) {
  2890. /* If not selected, use one with the most features available. */
  2891. int max_features = 0;
  2892. for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
  2893. uint32_t features = TextServerManager::get_singleton()->get_interface(i)->get_features();
  2894. int feature_number = 0;
  2895. while (features) {
  2896. feature_number += features & 1;
  2897. features >>= 1;
  2898. }
  2899. if (feature_number >= max_features) {
  2900. max_features = feature_number;
  2901. text_driver_idx = i;
  2902. }
  2903. }
  2904. }
  2905. if (text_driver_idx >= 0) {
  2906. Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(text_driver_idx);
  2907. TextServerManager::get_singleton()->set_primary_interface(ts);
  2908. if (ts->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) {
  2909. ts->load_support_data("res://" + ts->get_support_data_filename());
  2910. }
  2911. } else {
  2912. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "TextServer: Unable to create TextServer interface.");
  2913. }
  2914. OS::get_singleton()->benchmark_end_measure("Startup", "Text Server");
  2915. }
  2916. MAIN_PRINT("Main: Load Scene Types");
  2917. OS::get_singleton()->benchmark_begin_measure("Startup", "Scene");
  2918. // Initialize ThemeDB early so that scene types can register their theme items.
  2919. // Default theme will be initialized later, after modules and ScriptServer are ready.
  2920. initialize_theme_db();
  2921. MAIN_PRINT("Main: Load Navigation");
  2922. NavigationServer3DManager::initialize_server(); // 3D server first because 2D depends on it.
  2923. NavigationServer2DManager::initialize_server();
  2924. register_scene_types();
  2925. register_driver_types();
  2926. register_scene_singletons();
  2927. {
  2928. OS::get_singleton()->benchmark_begin_measure("Scene", "Modules and Extensions");
  2929. initialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
  2930. GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SCENE);
  2931. OS::get_singleton()->benchmark_end_measure("Scene", "Modules and Extensions");
  2932. }
  2933. PackedStringArray extensions;
  2934. extensions.push_back("gd");
  2935. if (ClassDB::class_exists("CSharpScript")) {
  2936. extensions.push_back("cs");
  2937. }
  2938. extensions.push_back("gdshader");
  2939. GLOBAL_DEF_NOVAL(PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions"), extensions); // Note: should be defined after Scene level modules init to see .NET.
  2940. OS::get_singleton()->benchmark_end_measure("Startup", "Scene");
  2941. #ifdef TOOLS_ENABLED
  2942. ClassDB::set_current_api(ClassDB::API_EDITOR);
  2943. register_editor_types();
  2944. {
  2945. OS::get_singleton()->benchmark_begin_measure("Editor", "Modules and Extensions");
  2946. initialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
  2947. GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR);
  2948. OS::get_singleton()->benchmark_end_measure("Editor", "Modules and Extensions");
  2949. }
  2950. ClassDB::set_current_api(ClassDB::API_CORE);
  2951. #endif
  2952. MAIN_PRINT("Main: Load Platforms");
  2953. OS::get_singleton()->benchmark_begin_measure("Startup", "Platforms");
  2954. register_platform_apis();
  2955. OS::get_singleton()->benchmark_end_measure("Startup", "Platforms");
  2956. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/mouse_cursor/custom_image", PROPERTY_HINT_FILE, "*.png,*.bmp,*.hdr,*.jpg,*.jpeg,*.svg,*.tga,*.exr,*.webp"), String());
  2957. GLOBAL_DEF_BASIC("display/mouse_cursor/custom_image_hotspot", Vector2());
  2958. GLOBAL_DEF_BASIC("display/mouse_cursor/tooltip_position_offset", Point2(10, 10));
  2959. if (String(GLOBAL_GET("display/mouse_cursor/custom_image")) != String()) {
  2960. Ref<Texture2D> cursor = ResourceLoader::load(
  2961. GLOBAL_GET("display/mouse_cursor/custom_image"));
  2962. if (cursor.is_valid()) {
  2963. Vector2 hotspot = GLOBAL_GET("display/mouse_cursor/custom_image_hotspot");
  2964. Input::get_singleton()->set_custom_mouse_cursor(cursor, Input::CURSOR_ARROW, hotspot);
  2965. }
  2966. }
  2967. OS::get_singleton()->benchmark_begin_measure("Startup", "Finalize Setup");
  2968. camera_server = CameraServer::create();
  2969. MAIN_PRINT("Main: Load Physics");
  2970. initialize_physics();
  2971. register_server_singletons();
  2972. // This loads global classes, so it must happen before custom loaders and savers are registered
  2973. ScriptServer::init_languages();
  2974. #if TOOLS_ENABLED
  2975. // Setting up the callback to execute a scan for UIDs on disk when a UID
  2976. // does not exist in the UID cache on startup. This prevents invalid UID errors
  2977. // when opening a project without a UID cache file or with an invalid cache.
  2978. if (editor) {
  2979. ResourceUID::scan_for_uid_on_startup = EditorFileSystem::scan_for_uid;
  2980. }
  2981. #endif
  2982. theme_db->initialize_theme();
  2983. audio_server->load_default_bus_layout();
  2984. #if defined(MODULE_MONO_ENABLED) && defined(TOOLS_ENABLED)
  2985. // Hacky to have it here, but we don't have good facility yet to let modules
  2986. // register command line options to call at the right time. This needs to happen
  2987. // after init'ing the ScriptServer, but also after init'ing the ThemeDB,
  2988. // for the C# docs generation in the bindings.
  2989. List<String> cmdline_args = OS::get_singleton()->get_cmdline_args();
  2990. BindingsGenerator::handle_cmdline_args(cmdline_args);
  2991. #endif
  2992. if (use_debug_profiler && EngineDebugger::is_active()) {
  2993. // Start the "scripts" profiler, used in local debugging.
  2994. // We could add more, and make the CLI arg require a comma-separated list of profilers.
  2995. EngineDebugger::get_singleton()->profiler_enable("scripts", true);
  2996. }
  2997. if (!project_manager) {
  2998. // If not running the project manager, and now that the engine is
  2999. // able to load resources, load the global shader variables.
  3000. // If running on editor, don't load the textures because the editor
  3001. // may want to import them first. Editor will reload those later.
  3002. rendering_server->global_shader_parameters_load_settings(!editor);
  3003. }
  3004. OS::get_singleton()->benchmark_end_measure("Startup", "Finalize Setup");
  3005. _start_success = true;
  3006. ClassDB::set_current_api(ClassDB::API_NONE); //no more APIs are registered at this point
  3007. print_verbose("CORE API HASH: " + uitos(ClassDB::get_api_hash(ClassDB::API_CORE)));
  3008. print_verbose("EDITOR API HASH: " + uitos(ClassDB::get_api_hash(ClassDB::API_EDITOR)));
  3009. MAIN_PRINT("Main: Done");
  3010. OS::get_singleton()->benchmark_end_measure("Startup", "Main::Setup2");
  3011. return OK;
  3012. }
  3013. void Main::setup_boot_logo() {
  3014. MAIN_PRINT("Main: Load Boot Image");
  3015. #if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
  3016. bool show_logo = false;
  3017. #else
  3018. bool show_logo = true;
  3019. #endif
  3020. if (show_logo) { //boot logo!
  3021. const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true);
  3022. const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true);
  3023. const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true);
  3024. String boot_logo_path = GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String());
  3025. // If the UID cache is missing or invalid, it could be 'normal' for the UID to not exist in memory.
  3026. // It's too soon to scan the project files since the ResourceFormatImporter is not loaded yet,
  3027. // so to prevent printing errors, we will just skip the custom boot logo this time.
  3028. if (boot_logo_path.begins_with("uid://")) {
  3029. const ResourceUID::ID logo_id = ResourceUID::get_singleton()->text_to_id(boot_logo_path);
  3030. if (ResourceUID::get_singleton()->has_id(logo_id)) {
  3031. boot_logo_path = ResourceUID::get_singleton()->get_id_path(logo_id).strip_edges();
  3032. } else {
  3033. boot_logo_path = String();
  3034. }
  3035. }
  3036. Ref<Image> boot_logo;
  3037. if (boot_logo_image) {
  3038. if (!boot_logo_path.is_empty()) {
  3039. boot_logo.instantiate();
  3040. Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
  3041. if (load_err) {
  3042. String msg = (boot_logo_path.ends_with(".png") ? "" : "The only supported format is PNG.");
  3043. ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + +"'. " + msg + " Loading default splash.");
  3044. }
  3045. }
  3046. } else {
  3047. // Create a 1×1 transparent image. This will effectively hide the splash image.
  3048. boot_logo.instantiate();
  3049. boot_logo->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
  3050. boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0));
  3051. }
  3052. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  3053. #if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
  3054. boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", (editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color);
  3055. #endif
  3056. if (boot_logo.is_valid()) {
  3057. RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter);
  3058. } else {
  3059. #ifndef NO_DEFAULT_BOOT_LOGO
  3060. MAIN_PRINT("Main: Create bootsplash");
  3061. #if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
  3062. Ref<Image> splash = (editor || project_manager) ? memnew(Image(boot_splash_editor_png)) : memnew(Image(boot_splash_png));
  3063. #else
  3064. Ref<Image> splash = memnew(Image(boot_splash_png));
  3065. #endif
  3066. MAIN_PRINT("Main: ClearColor");
  3067. RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color);
  3068. MAIN_PRINT("Main: Image");
  3069. RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false);
  3070. #endif
  3071. }
  3072. #if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED)
  3073. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && OS::get_singleton()->get_bundle_icon_path().is_empty()) {
  3074. Ref<Image> icon = memnew(Image(app_icon_png));
  3075. DisplayServer::get_singleton()->set_icon(icon);
  3076. }
  3077. #endif
  3078. }
  3079. RenderingServer::get_singleton()->set_default_clear_color(
  3080. GLOBAL_GET("rendering/environment/defaults/default_clear_color"));
  3081. }
  3082. String Main::get_rendering_driver_name() {
  3083. return rendering_driver;
  3084. }
  3085. // everything the main loop needs to know about frame timings
  3086. static MainTimerSync main_timer_sync;
  3087. // Return value should be EXIT_SUCCESS if we start successfully
  3088. // and should move on to `OS::run`, and EXIT_FAILURE otherwise for
  3089. // an early exit with that error code.
  3090. int Main::start() {
  3091. OS::get_singleton()->benchmark_begin_measure("Startup", "Main::Start");
  3092. ERR_FAIL_COND_V(!_start_success, false);
  3093. bool has_icon = false;
  3094. String positional_arg;
  3095. String game_path;
  3096. String script;
  3097. String main_loop_type;
  3098. bool check_only = false;
  3099. #ifdef TOOLS_ENABLED
  3100. String doc_tool_path;
  3101. bool doc_tool_implicit_cwd = false;
  3102. BitField<DocTools::GenerateFlags> gen_flags;
  3103. String _export_preset;
  3104. Vector<String> patches;
  3105. bool export_debug = false;
  3106. bool export_pack_only = false;
  3107. bool install_android_build_template = false;
  3108. bool export_patch = false;
  3109. #ifdef MODULE_GDSCRIPT_ENABLED
  3110. String gdscript_docs_path;
  3111. #endif
  3112. #ifndef DISABLE_DEPRECATED
  3113. bool converting_project = false;
  3114. bool validating_converting_project = false;
  3115. #endif // DISABLE_DEPRECATED
  3116. #endif // TOOLS_ENABLED
  3117. main_timer_sync.init(OS::get_singleton()->get_ticks_usec());
  3118. List<String> args = OS::get_singleton()->get_cmdline_args();
  3119. for (List<String>::Element *E = args.front(); E; E = E->next()) {
  3120. // First check parameters that do not have an argument to the right.
  3121. // Doctest Unit Testing Handler
  3122. // Designed to override and pass arguments to the unit test handler.
  3123. if (E->get() == "--check-only") {
  3124. check_only = true;
  3125. #ifdef TOOLS_ENABLED
  3126. } else if (E->get() == "--no-docbase") {
  3127. gen_flags.set_flag(DocTools::GENERATE_FLAG_SKIP_BASIC_TYPES);
  3128. } else if (E->get() == "--gdextension-docs") {
  3129. gen_flags.set_flag(DocTools::GENERATE_FLAG_SKIP_BASIC_TYPES);
  3130. gen_flags.set_flag(DocTools::GENERATE_FLAG_EXTENSION_CLASSES_ONLY);
  3131. #ifndef DISABLE_DEPRECATED
  3132. } else if (E->get() == "--convert-3to4") {
  3133. converting_project = true;
  3134. } else if (E->get() == "--validate-conversion-3to4") {
  3135. validating_converting_project = true;
  3136. #endif // DISABLE_DEPRECATED
  3137. } else if (E->get() == "-e" || E->get() == "--editor") {
  3138. editor = true;
  3139. } else if (E->get() == "-p" || E->get() == "--project-manager") {
  3140. project_manager = true;
  3141. } else if (E->get() == "--recovery-mode") {
  3142. recovery_mode = true;
  3143. } else if (E->get() == "--install-android-build-template") {
  3144. install_android_build_template = true;
  3145. #endif // TOOLS_ENABLED
  3146. } else if (E->get().length() && E->get()[0] != '-' && positional_arg.is_empty()) {
  3147. positional_arg = E->get();
  3148. if (E->get().ends_with(".scn") ||
  3149. E->get().ends_with(".tscn") ||
  3150. E->get().ends_with(".escn") ||
  3151. E->get().ends_with(".res") ||
  3152. E->get().ends_with(".tres")) {
  3153. // Only consider the positional argument to be a scene path if it ends with
  3154. // a file extension associated with Godot scenes. This makes it possible
  3155. // for projects to parse command-line arguments for custom CLI arguments
  3156. // or other file extensions without trouble. This can be used to implement
  3157. // "drag-and-drop onto executable" logic, which can prove helpful
  3158. // for non-game applications.
  3159. game_path = E->get();
  3160. }
  3161. }
  3162. // Then parameters that have an argument to the right.
  3163. else if (E->next()) {
  3164. bool parsed_pair = true;
  3165. if (E->get() == "-s" || E->get() == "--script") {
  3166. script = E->next()->get();
  3167. } else if (E->get() == "--main-loop") {
  3168. main_loop_type = E->next()->get();
  3169. #ifdef TOOLS_ENABLED
  3170. } else if (E->get() == "--doctool") {
  3171. doc_tool_path = E->next()->get();
  3172. if (doc_tool_path.begins_with("-")) {
  3173. // Assuming other command line arg, so default to cwd.
  3174. doc_tool_path = ".";
  3175. doc_tool_implicit_cwd = true;
  3176. parsed_pair = false;
  3177. }
  3178. #ifdef MODULE_GDSCRIPT_ENABLED
  3179. } else if (E->get() == "--gdscript-docs") {
  3180. gdscript_docs_path = E->next()->get();
  3181. #endif
  3182. } else if (E->get() == "--export-release") {
  3183. ERR_FAIL_COND_V_MSG(!editor && !found_project, EXIT_FAILURE, "Please provide a valid project path when exporting, aborting.");
  3184. editor = true; //needs editor
  3185. _export_preset = E->next()->get();
  3186. } else if (E->get() == "--export-debug") {
  3187. ERR_FAIL_COND_V_MSG(!editor && !found_project, EXIT_FAILURE, "Please provide a valid project path when exporting, aborting.");
  3188. editor = true; //needs editor
  3189. _export_preset = E->next()->get();
  3190. export_debug = true;
  3191. } else if (E->get() == "--export-pack") {
  3192. ERR_FAIL_COND_V_MSG(!editor && !found_project, EXIT_FAILURE, "Please provide a valid project path when exporting, aborting.");
  3193. editor = true;
  3194. _export_preset = E->next()->get();
  3195. export_pack_only = true;
  3196. } else if (E->get() == "--export-patch") {
  3197. ERR_FAIL_COND_V_MSG(!editor && !found_project, EXIT_FAILURE, "Please provide a valid project path when exporting, aborting.");
  3198. editor = true;
  3199. _export_preset = E->next()->get();
  3200. export_pack_only = true;
  3201. export_patch = true;
  3202. } else if (E->get() == "--patches") {
  3203. patches = E->next()->get().split(",", false);
  3204. #endif
  3205. } else {
  3206. // The parameter does not match anything known, don't skip the next argument
  3207. parsed_pair = false;
  3208. }
  3209. if (parsed_pair) {
  3210. E = E->next();
  3211. }
  3212. } else if (E->get().begins_with("--export-")) {
  3213. ERR_FAIL_V_MSG(EXIT_FAILURE, "Missing export preset name, aborting.");
  3214. }
  3215. #ifdef TOOLS_ENABLED
  3216. // Handle case where no path is given to --doctool.
  3217. else if (E->get() == "--doctool") {
  3218. doc_tool_path = ".";
  3219. doc_tool_implicit_cwd = true;
  3220. }
  3221. #endif
  3222. }
  3223. uint64_t minimum_time_msec = GLOBAL_DEF(PropertyInfo(Variant::INT, "application/boot_splash/minimum_display_time", PROPERTY_HINT_RANGE, "0,100,1,or_greater,suffix:ms"), 0);
  3224. if (Engine::get_singleton()->is_editor_hint()) {
  3225. minimum_time_msec = 0;
  3226. }
  3227. #ifdef TOOLS_ENABLED
  3228. #ifdef MODULE_GDSCRIPT_ENABLED
  3229. if (!doc_tool_path.is_empty() && gdscript_docs_path.is_empty()) {
  3230. #else
  3231. if (!doc_tool_path.is_empty()) {
  3232. #endif
  3233. // Needed to instance editor-only classes for their default values
  3234. Engine::get_singleton()->set_editor_hint(true);
  3235. // Translate the class reference only when `-l LOCALE` parameter is given.
  3236. if (!locale.is_empty() && locale != "en") {
  3237. load_doc_translations(locale);
  3238. }
  3239. {
  3240. Ref<DirAccess> da = DirAccess::open(doc_tool_path);
  3241. ERR_FAIL_COND_V_MSG(da.is_null(), EXIT_FAILURE, "Argument supplied to --doctool must be a valid directory path.");
  3242. // Ensure that doctool is running in the root dir, but only if
  3243. // user did not manually specify a path as argument.
  3244. if (doc_tool_implicit_cwd) {
  3245. ERR_FAIL_COND_V_MSG(!da->dir_exists("doc"), EXIT_FAILURE, "--doctool must be run from the Godot repository's root folder, or specify a path that points there.");
  3246. }
  3247. }
  3248. #ifndef MODULE_MONO_ENABLED
  3249. // Hack to define .NET-specific project settings even on non-.NET builds,
  3250. // so that we don't lose their descriptions and default values in DocTools.
  3251. // Default values should be synced with mono_gd/gd_mono.cpp.
  3252. GLOBAL_DEF("dotnet/project/assembly_name", "");
  3253. GLOBAL_DEF("dotnet/project/solution_directory", "");
  3254. GLOBAL_DEF(PropertyInfo(Variant::INT, "dotnet/project/assembly_reload_attempts", PROPERTY_HINT_RANGE, "1,16,1,or_greater"), 3);
  3255. #endif
  3256. Error err;
  3257. DocTools doc;
  3258. doc.generate(gen_flags);
  3259. DocTools docsrc;
  3260. HashMap<String, String> doc_data_classes;
  3261. HashSet<String> checked_paths;
  3262. print_line("Loading docs...");
  3263. const bool gdextension_docs = gen_flags.has_flag(DocTools::GENERATE_FLAG_EXTENSION_CLASSES_ONLY);
  3264. if (!gdextension_docs) {
  3265. for (int i = 0; i < _doc_data_class_path_count; i++) {
  3266. // Custom modules are always located by absolute path.
  3267. String path = _doc_data_class_paths[i].path;
  3268. if (path.is_relative_path()) {
  3269. path = doc_tool_path.path_join(path);
  3270. }
  3271. String name = _doc_data_class_paths[i].name;
  3272. doc_data_classes[name] = path;
  3273. if (!checked_paths.has(path)) {
  3274. checked_paths.insert(path);
  3275. // Create the module documentation directory if it doesn't exist
  3276. Ref<DirAccess> da = DirAccess::create_for_path(path);
  3277. err = da->make_dir_recursive(path);
  3278. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error: Can't create directory: " + path + ": " + itos(err));
  3279. print_line("Loading docs from: " + path);
  3280. err = docsrc.load_classes(path);
  3281. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error loading docs from: " + path + ": " + itos(err));
  3282. }
  3283. }
  3284. }
  3285. // For GDExtension docs, use a path that is compatible with Godot modules.
  3286. String index_path = gdextension_docs ? doc_tool_path.path_join("doc_classes") : doc_tool_path.path_join("doc/classes");
  3287. // Create the main documentation directory if it doesn't exist
  3288. Ref<DirAccess> da = DirAccess::create_for_path(index_path);
  3289. err = da->make_dir_recursive(index_path);
  3290. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error: Can't create index directory: " + index_path + ": " + itos(err));
  3291. print_line("Loading classes from: " + index_path);
  3292. err = docsrc.load_classes(index_path);
  3293. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error loading classes from: " + index_path + ": " + itos(err));
  3294. checked_paths.insert(index_path);
  3295. print_line("Merging docs...");
  3296. doc.merge_from(docsrc);
  3297. for (const String &E : checked_paths) {
  3298. print_line("Erasing old docs at: " + E);
  3299. err = DocTools::erase_classes(E);
  3300. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error erasing old docs at: " + E + ": " + itos(err));
  3301. }
  3302. print_line("Generating new docs...");
  3303. err = doc.save_classes(index_path, doc_data_classes, !gdextension_docs);
  3304. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error saving new docs:" + itos(err));
  3305. print_line("Deleting docs cache...");
  3306. if (FileAccess::exists(EditorHelp::get_cache_full_path())) {
  3307. DirAccess::remove_file_or_error(EditorHelp::get_cache_full_path());
  3308. }
  3309. return EXIT_SUCCESS;
  3310. }
  3311. // GDExtension API and interface.
  3312. {
  3313. if (dump_gdextension_interface) {
  3314. GDExtensionInterfaceDump::generate_gdextension_interface_file("gdextension_interface.h");
  3315. }
  3316. if (dump_extension_api) {
  3317. Engine::get_singleton()->set_editor_hint(true); // "extension_api.json" should always contains editor singletons.
  3318. GDExtensionAPIDump::generate_extension_json_file("extension_api.json", include_docs_in_extension_api_dump);
  3319. }
  3320. if (dump_gdextension_interface || dump_extension_api) {
  3321. return EXIT_SUCCESS;
  3322. }
  3323. if (validate_extension_api) {
  3324. Engine::get_singleton()->set_editor_hint(true); // "extension_api.json" should always contains editor singletons.
  3325. bool valid = GDExtensionAPIDump::validate_extension_json_file(validate_extension_api_file) == OK;
  3326. return valid ? EXIT_SUCCESS : EXIT_FAILURE;
  3327. }
  3328. }
  3329. #ifndef DISABLE_DEPRECATED
  3330. if (converting_project) {
  3331. int ret = ProjectConverter3To4(converter_max_kb_file, converter_max_line_length).convert();
  3332. return ret ? EXIT_SUCCESS : EXIT_FAILURE;
  3333. }
  3334. if (validating_converting_project) {
  3335. bool ret = ProjectConverter3To4(converter_max_kb_file, converter_max_line_length).validate_conversion();
  3336. return ret ? EXIT_SUCCESS : EXIT_FAILURE;
  3337. }
  3338. #endif // DISABLE_DEPRECATED
  3339. #endif // TOOLS_ENABLED
  3340. if (script.is_empty() && game_path.is_empty()) {
  3341. game_path = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
  3342. }
  3343. #ifdef TOOLS_ENABLED
  3344. if (!editor && !project_manager && !cmdline_tool && script.is_empty() && game_path.is_empty()) {
  3345. // If we end up here, it means we didn't manage to detect what we want to run.
  3346. // Let's throw an error gently. The code leading to this is pretty brittle so
  3347. // this might end up triggered by valid usage, in which case we'll have to
  3348. // fine-tune further.
  3349. OS::get_singleton()->alert("Couldn't detect whether to run the editor, the project manager or a specific project. Aborting.");
  3350. ERR_FAIL_V_MSG(EXIT_FAILURE, "Couldn't detect whether to run the editor, the project manager or a specific project. Aborting.");
  3351. }
  3352. #endif
  3353. MainLoop *main_loop = nullptr;
  3354. if (editor) {
  3355. main_loop = memnew(SceneTree);
  3356. }
  3357. if (main_loop_type.is_empty()) {
  3358. main_loop_type = GLOBAL_GET("application/run/main_loop_type");
  3359. }
  3360. if (!script.is_empty()) {
  3361. Ref<Script> script_res = ResourceLoader::load(script);
  3362. ERR_FAIL_COND_V_MSG(script_res.is_null(), EXIT_FAILURE, "Can't load script: " + script);
  3363. if (check_only) {
  3364. return script_res->is_valid() ? EXIT_SUCCESS : EXIT_FAILURE;
  3365. }
  3366. if (script_res->can_instantiate()) {
  3367. StringName instance_type = script_res->get_instance_base_type();
  3368. Object *obj = ClassDB::instantiate(instance_type);
  3369. MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
  3370. if (!script_loop) {
  3371. if (obj) {
  3372. memdelete(obj);
  3373. }
  3374. OS::get_singleton()->alert(vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script));
  3375. ERR_FAIL_V_MSG(EXIT_FAILURE, vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script));
  3376. }
  3377. script_loop->set_script(script_res);
  3378. main_loop = script_loop;
  3379. } else {
  3380. return EXIT_FAILURE;
  3381. }
  3382. } else { // Not based on script path.
  3383. if (!editor && !ClassDB::class_exists(main_loop_type) && ScriptServer::is_global_class(main_loop_type)) {
  3384. String script_path = ScriptServer::get_global_class_path(main_loop_type);
  3385. Ref<Script> script_res = ResourceLoader::load(script_path);
  3386. if (script_res.is_null()) {
  3387. OS::get_singleton()->alert("Error: Could not load MainLoop script type: " + main_loop_type);
  3388. ERR_FAIL_V_MSG(EXIT_FAILURE, vformat("Could not load global class %s.", main_loop_type));
  3389. }
  3390. StringName script_base = script_res->get_instance_base_type();
  3391. Object *obj = ClassDB::instantiate(script_base);
  3392. MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
  3393. if (!script_loop) {
  3394. if (obj) {
  3395. memdelete(obj);
  3396. }
  3397. OS::get_singleton()->alert("Error: Invalid MainLoop script base type: " + script_base);
  3398. ERR_FAIL_V_MSG(EXIT_FAILURE, vformat("The global class %s does not inherit from SceneTree or MainLoop.", main_loop_type));
  3399. }
  3400. script_loop->set_script(script_res);
  3401. main_loop = script_loop;
  3402. }
  3403. }
  3404. if (!main_loop && main_loop_type.is_empty()) {
  3405. main_loop_type = "SceneTree";
  3406. }
  3407. if (!main_loop) {
  3408. if (!ClassDB::class_exists(main_loop_type)) {
  3409. OS::get_singleton()->alert("Error: MainLoop type doesn't exist: " + main_loop_type);
  3410. return EXIT_FAILURE;
  3411. } else {
  3412. Object *ml = ClassDB::instantiate(main_loop_type);
  3413. ERR_FAIL_NULL_V_MSG(ml, EXIT_FAILURE, "Can't instance MainLoop type.");
  3414. main_loop = Object::cast_to<MainLoop>(ml);
  3415. if (!main_loop) {
  3416. memdelete(ml);
  3417. ERR_FAIL_V_MSG(EXIT_FAILURE, "Invalid MainLoop type.");
  3418. }
  3419. }
  3420. }
  3421. OS::get_singleton()->set_main_loop(main_loop);
  3422. SceneTree *sml = Object::cast_to<SceneTree>(main_loop);
  3423. if (sml) {
  3424. #ifdef DEBUG_ENABLED
  3425. if (debug_collisions) {
  3426. sml->set_debug_collisions_hint(true);
  3427. }
  3428. if (debug_paths) {
  3429. sml->set_debug_paths_hint(true);
  3430. }
  3431. if (debug_navigation) {
  3432. sml->set_debug_navigation_hint(true);
  3433. NavigationServer3D::get_singleton()->set_debug_navigation_enabled(true);
  3434. }
  3435. if (debug_avoidance) {
  3436. NavigationServer3D::get_singleton()->set_debug_avoidance_enabled(true);
  3437. }
  3438. if (debug_navigation || debug_avoidance) {
  3439. NavigationServer3D::get_singleton()->set_active(true);
  3440. NavigationServer3D::get_singleton()->set_debug_enabled(true);
  3441. }
  3442. if (debug_canvas_item_redraw) {
  3443. RenderingServer::get_singleton()->canvas_item_set_debug_redraw(true);
  3444. }
  3445. #endif
  3446. if (single_threaded_scene) {
  3447. sml->set_disable_node_threading(true);
  3448. }
  3449. bool embed_subwindows = GLOBAL_GET("display/window/subwindows/embed_subwindows");
  3450. if (single_window || (!project_manager && !editor && embed_subwindows) || !DisplayServer::get_singleton()->has_feature(DisplayServer::Feature::FEATURE_SUBWINDOWS)) {
  3451. sml->get_root()->set_embedding_subwindows(true);
  3452. }
  3453. ResourceLoader::add_custom_loaders();
  3454. ResourceSaver::add_custom_savers();
  3455. if (!project_manager && !editor) { // game
  3456. if (!game_path.is_empty() || !script.is_empty()) {
  3457. //autoload
  3458. OS::get_singleton()->benchmark_begin_measure("Startup", "Load Autoloads");
  3459. HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
  3460. //first pass, add the constants so they exist before any script is loaded
  3461. for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) {
  3462. const ProjectSettings::AutoloadInfo &info = E.value;
  3463. if (info.is_singleton) {
  3464. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  3465. ScriptServer::get_language(i)->add_global_constant(info.name, Variant());
  3466. }
  3467. }
  3468. }
  3469. //second pass, load into global constants
  3470. List<Node *> to_add;
  3471. for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) {
  3472. const ProjectSettings::AutoloadInfo &info = E.value;
  3473. Node *n = nullptr;
  3474. if (ResourceLoader::get_resource_type(info.path) == "PackedScene") {
  3475. // Cache the scene reference before loading it (for cyclic references)
  3476. Ref<PackedScene> scn;
  3477. scn.instantiate();
  3478. scn->set_path(info.path);
  3479. scn->reload_from_file();
  3480. ERR_CONTINUE_MSG(scn.is_null(), vformat("Failed to instantiate an autoload, can't load from path: %s.", info.path));
  3481. if (scn.is_valid()) {
  3482. n = scn->instantiate();
  3483. }
  3484. } else {
  3485. Ref<Resource> res = ResourceLoader::load(info.path);
  3486. ERR_CONTINUE_MSG(res.is_null(), vformat("Failed to instantiate an autoload, can't load from path: %s.", info.path));
  3487. Ref<Script> script_res = res;
  3488. if (script_res.is_valid()) {
  3489. StringName ibt = script_res->get_instance_base_type();
  3490. bool valid_type = ClassDB::is_parent_class(ibt, "Node");
  3491. ERR_CONTINUE_MSG(!valid_type, vformat("Failed to instantiate an autoload, script '%s' does not inherit from 'Node'.", info.path));
  3492. Object *obj = ClassDB::instantiate(ibt);
  3493. ERR_CONTINUE_MSG(!obj, vformat("Failed to instantiate an autoload, cannot instantiate '%s'.", ibt));
  3494. n = Object::cast_to<Node>(obj);
  3495. n->set_script(script_res);
  3496. }
  3497. }
  3498. ERR_CONTINUE_MSG(!n, vformat("Failed to instantiate an autoload, path is not pointing to a scene or a script: %s.", info.path));
  3499. n->set_name(info.name);
  3500. //defer so references are all valid on _ready()
  3501. to_add.push_back(n);
  3502. if (info.is_singleton) {
  3503. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  3504. ScriptServer::get_language(i)->add_global_constant(info.name, n);
  3505. }
  3506. }
  3507. }
  3508. for (Node *E : to_add) {
  3509. sml->get_root()->add_child(E);
  3510. }
  3511. OS::get_singleton()->benchmark_end_measure("Startup", "Load Autoloads");
  3512. }
  3513. }
  3514. #ifdef TOOLS_ENABLED
  3515. #ifdef MODULE_GDSCRIPT_ENABLED
  3516. if (!doc_tool_path.is_empty() && !gdscript_docs_path.is_empty()) {
  3517. DocTools docs;
  3518. Error err;
  3519. Vector<String> paths = get_files_with_extension(gdscript_docs_path, "gd");
  3520. ERR_FAIL_COND_V_MSG(paths.is_empty(), EXIT_FAILURE, "Couldn't find any GDScript files under the given directory: " + gdscript_docs_path);
  3521. for (const String &path : paths) {
  3522. Ref<GDScript> gdscript = ResourceLoader::load(path);
  3523. for (const DocData::ClassDoc &class_doc : gdscript->get_documentation()) {
  3524. docs.add_doc(class_doc);
  3525. }
  3526. }
  3527. if (doc_tool_implicit_cwd) {
  3528. doc_tool_path = "./docs";
  3529. }
  3530. Ref<DirAccess> da = DirAccess::create_for_path(doc_tool_path);
  3531. err = da->make_dir_recursive(doc_tool_path);
  3532. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error: Can't create GDScript docs directory: " + doc_tool_path + ": " + itos(err));
  3533. HashMap<String, String> doc_data_classes;
  3534. err = docs.save_classes(doc_tool_path, doc_data_classes, false);
  3535. ERR_FAIL_COND_V_MSG(err != OK, EXIT_FAILURE, "Error saving GDScript docs:" + itos(err));
  3536. return EXIT_SUCCESS;
  3537. }
  3538. #endif // MODULE_GDSCRIPT_ENABLED
  3539. EditorNode *editor_node = nullptr;
  3540. if (editor) {
  3541. OS::get_singleton()->benchmark_begin_measure("Startup", "Editor");
  3542. sml->get_root()->set_translation_domain("godot.editor");
  3543. if (editor_pseudolocalization) {
  3544. translation_server->get_editor_domain()->set_pseudolocalization_enabled(true);
  3545. }
  3546. editor_node = memnew(EditorNode);
  3547. sml->get_root()->add_child(editor_node);
  3548. if (!_export_preset.is_empty()) {
  3549. editor_node->export_preset(_export_preset, positional_arg, export_debug, export_pack_only, install_android_build_template, export_patch, patches);
  3550. game_path = ""; // Do not load anything.
  3551. }
  3552. OS::get_singleton()->benchmark_end_measure("Startup", "Editor");
  3553. }
  3554. #endif
  3555. sml->set_auto_accept_quit(GLOBAL_GET("application/config/auto_accept_quit"));
  3556. sml->set_quit_on_go_back(GLOBAL_GET("application/config/quit_on_go_back"));
  3557. if (!editor && !project_manager) {
  3558. //standard helpers that can be changed from main config
  3559. String stretch_mode = GLOBAL_GET("display/window/stretch/mode");
  3560. String stretch_aspect = GLOBAL_GET("display/window/stretch/aspect");
  3561. Size2i stretch_size = Size2i(GLOBAL_GET("display/window/size/viewport_width"),
  3562. GLOBAL_GET("display/window/size/viewport_height"));
  3563. real_t stretch_scale = GLOBAL_GET("display/window/stretch/scale");
  3564. String stretch_scale_mode = GLOBAL_GET("display/window/stretch/scale_mode");
  3565. Window::ContentScaleMode cs_sm = Window::CONTENT_SCALE_MODE_DISABLED;
  3566. if (stretch_mode == "canvas_items") {
  3567. cs_sm = Window::CONTENT_SCALE_MODE_CANVAS_ITEMS;
  3568. } else if (stretch_mode == "viewport") {
  3569. cs_sm = Window::CONTENT_SCALE_MODE_VIEWPORT;
  3570. }
  3571. Window::ContentScaleAspect cs_aspect = Window::CONTENT_SCALE_ASPECT_IGNORE;
  3572. if (stretch_aspect == "keep") {
  3573. cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP;
  3574. } else if (stretch_aspect == "keep_width") {
  3575. cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_WIDTH;
  3576. } else if (stretch_aspect == "keep_height") {
  3577. cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_HEIGHT;
  3578. } else if (stretch_aspect == "expand") {
  3579. cs_aspect = Window::CONTENT_SCALE_ASPECT_EXPAND;
  3580. }
  3581. Window::ContentScaleStretch cs_stretch = Window::CONTENT_SCALE_STRETCH_FRACTIONAL;
  3582. if (stretch_scale_mode == "integer") {
  3583. cs_stretch = Window::CONTENT_SCALE_STRETCH_INTEGER;
  3584. }
  3585. sml->get_root()->set_content_scale_mode(cs_sm);
  3586. sml->get_root()->set_content_scale_aspect(cs_aspect);
  3587. sml->get_root()->set_content_scale_stretch(cs_stretch);
  3588. sml->get_root()->set_content_scale_size(stretch_size);
  3589. sml->get_root()->set_content_scale_factor(stretch_scale);
  3590. sml->set_auto_accept_quit(GLOBAL_GET("application/config/auto_accept_quit"));
  3591. sml->set_quit_on_go_back(GLOBAL_GET("application/config/quit_on_go_back"));
  3592. String appname = GLOBAL_GET("application/config/name");
  3593. appname = TranslationServer::get_singleton()->translate(appname);
  3594. #ifdef DEBUG_ENABLED
  3595. // Append a suffix to the window title to denote that the project is running
  3596. // from a debug build (including the editor). Since this results in lower performance,
  3597. // this should be clearly presented to the user.
  3598. DisplayServer::get_singleton()->window_set_title(vformat("%s (DEBUG)", appname));
  3599. #else
  3600. DisplayServer::get_singleton()->window_set_title(appname);
  3601. #endif
  3602. bool snap_controls = GLOBAL_GET("gui/common/snap_controls_to_pixels");
  3603. sml->get_root()->set_snap_controls_to_pixels(snap_controls);
  3604. bool font_oversampling = GLOBAL_GET("gui/fonts/dynamic_fonts/use_oversampling");
  3605. sml->get_root()->set_use_font_oversampling(font_oversampling);
  3606. int texture_filter = GLOBAL_GET("rendering/textures/canvas_textures/default_texture_filter");
  3607. int texture_repeat = GLOBAL_GET("rendering/textures/canvas_textures/default_texture_repeat");
  3608. sml->get_root()->set_default_canvas_item_texture_filter(
  3609. Viewport::DefaultCanvasItemTextureFilter(texture_filter));
  3610. sml->get_root()->set_default_canvas_item_texture_repeat(
  3611. Viewport::DefaultCanvasItemTextureRepeat(texture_repeat));
  3612. }
  3613. #ifdef TOOLS_ENABLED
  3614. if (editor) {
  3615. bool editor_embed_subwindows = EditorSettings::get_singleton()->get_setting(
  3616. "interface/editor/single_window_mode");
  3617. if (editor_embed_subwindows) {
  3618. sml->get_root()->set_embedding_subwindows(true);
  3619. }
  3620. restore_editor_window_layout = EditorSettings::get_singleton()->get_setting("interface/editor/editor_screen").operator int() == EditorSettings::InitialScreen::INITIAL_SCREEN_AUTO;
  3621. }
  3622. #endif
  3623. String local_game_path;
  3624. if (!game_path.is_empty() && !project_manager) {
  3625. local_game_path = game_path.replace("\\", "/");
  3626. if (!local_game_path.begins_with("res://")) {
  3627. bool absolute =
  3628. (local_game_path.size() > 1) && (local_game_path[0] == '/' || local_game_path[1] == ':');
  3629. if (!absolute) {
  3630. if (ProjectSettings::get_singleton()->is_using_datapack()) {
  3631. local_game_path = "res://" + local_game_path;
  3632. } else {
  3633. int sep = local_game_path.rfind_char('/');
  3634. if (sep == -1) {
  3635. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  3636. ERR_FAIL_COND_V(da.is_null(), EXIT_FAILURE);
  3637. local_game_path = da->get_current_dir().path_join(local_game_path);
  3638. } else {
  3639. Ref<DirAccess> da = DirAccess::open(local_game_path.substr(0, sep));
  3640. if (da.is_valid()) {
  3641. local_game_path = da->get_current_dir().path_join(
  3642. local_game_path.substr(sep + 1, local_game_path.length()));
  3643. }
  3644. }
  3645. }
  3646. }
  3647. }
  3648. local_game_path = ProjectSettings::get_singleton()->localize_path(local_game_path);
  3649. #ifdef TOOLS_ENABLED
  3650. if (editor) {
  3651. if (!recovery_mode && (game_path != ResourceUID::ensure_path(String(GLOBAL_GET("application/run/main_scene"))) || !editor_node->has_scenes_in_session())) {
  3652. Error serr = editor_node->load_scene(local_game_path);
  3653. if (serr != OK) {
  3654. ERR_PRINT("Failed to load scene");
  3655. }
  3656. }
  3657. if (!debug_server_uri.is_empty()) {
  3658. EditorDebuggerNode::get_singleton()->start(debug_server_uri);
  3659. EditorDebuggerNode::get_singleton()->set_keep_open(true);
  3660. }
  3661. }
  3662. #endif
  3663. }
  3664. if (!project_manager && !editor) { // game
  3665. OS::get_singleton()->benchmark_begin_measure("Startup", "Load Game");
  3666. // Load SSL Certificates from Project Settings (or builtin).
  3667. Crypto::load_default_certificates(GLOBAL_GET("network/tls/certificate_bundle_override"));
  3668. if (!game_path.is_empty()) {
  3669. Node *scene = nullptr;
  3670. Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path);
  3671. if (scenedata.is_valid()) {
  3672. scene = scenedata->instantiate();
  3673. }
  3674. ERR_FAIL_NULL_V_MSG(scene, EXIT_FAILURE, "Failed loading scene: " + local_game_path + ".");
  3675. sml->add_current_scene(scene);
  3676. #ifdef MACOS_ENABLED
  3677. String mac_icon_path = GLOBAL_GET("application/config/macos_native_icon");
  3678. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_ICON) && !mac_icon_path.is_empty()) {
  3679. DisplayServer::get_singleton()->set_native_icon(mac_icon_path);
  3680. has_icon = true;
  3681. }
  3682. #endif
  3683. #ifdef WINDOWS_ENABLED
  3684. String win_icon_path = GLOBAL_GET("application/config/windows_native_icon");
  3685. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_ICON) && !win_icon_path.is_empty()) {
  3686. DisplayServer::get_singleton()->set_native_icon(win_icon_path);
  3687. has_icon = true;
  3688. }
  3689. #endif
  3690. String icon_path = GLOBAL_GET("application/config/icon");
  3691. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && !icon_path.is_empty() && !has_icon) {
  3692. Ref<Image> icon;
  3693. icon.instantiate();
  3694. if (ImageLoader::load_image(icon_path, icon) == OK) {
  3695. DisplayServer::get_singleton()->set_icon(icon);
  3696. has_icon = true;
  3697. }
  3698. }
  3699. }
  3700. OS::get_singleton()->benchmark_end_measure("Startup", "Load Game");
  3701. }
  3702. #ifdef TOOLS_ENABLED
  3703. if (project_manager) {
  3704. OS::get_singleton()->benchmark_begin_measure("Startup", "Project Manager");
  3705. Engine::get_singleton()->set_editor_hint(true);
  3706. sml->get_root()->set_translation_domain("godot.editor");
  3707. if (editor_pseudolocalization) {
  3708. translation_server->get_editor_domain()->set_pseudolocalization_enabled(true);
  3709. }
  3710. ProjectManager *pmanager = memnew(ProjectManager(force_res || use_custom_res));
  3711. ProgressDialog *progress_dialog = memnew(ProgressDialog);
  3712. pmanager->add_child(progress_dialog);
  3713. sml->get_root()->add_child(pmanager);
  3714. OS::get_singleton()->benchmark_end_measure("Startup", "Project Manager");
  3715. }
  3716. if (project_manager || editor) {
  3717. // Load SSL Certificates from Editor Settings (or builtin)
  3718. Crypto::load_default_certificates(
  3719. EditorSettings::get_singleton()->get_setting("network/tls/editor_tls_certificates").operator String());
  3720. }
  3721. if (recovery_mode) {
  3722. Engine::get_singleton()->set_recovery_mode_hint(true);
  3723. }
  3724. #endif
  3725. }
  3726. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_ICON) && !has_icon && OS::get_singleton()->get_bundle_icon_path().is_empty()) {
  3727. Ref<Image> icon = memnew(Image(app_icon_png));
  3728. DisplayServer::get_singleton()->set_icon(icon);
  3729. }
  3730. if (movie_writer) {
  3731. movie_writer->begin(DisplayServer::get_singleton()->window_get_size(), fixed_fps, Engine::get_singleton()->get_write_movie_path());
  3732. }
  3733. if (minimum_time_msec) {
  3734. uint64_t minimum_time = 1000 * minimum_time_msec;
  3735. uint64_t elapsed_time = OS::get_singleton()->get_ticks_usec();
  3736. if (elapsed_time < minimum_time) {
  3737. OS::get_singleton()->delay_usec(minimum_time - elapsed_time);
  3738. }
  3739. }
  3740. OS::get_singleton()->benchmark_end_measure("Startup", "Main::Start");
  3741. OS::get_singleton()->benchmark_dump();
  3742. return EXIT_SUCCESS;
  3743. }
  3744. /* Main iteration
  3745. *
  3746. * This is the iteration of the engine's game loop, advancing the state of physics,
  3747. * rendering and audio.
  3748. * It's called directly by the platform's OS::run method, where the loop is created
  3749. * and monitored.
  3750. *
  3751. * The OS implementation can impact its draw step with the Main::force_redraw() method.
  3752. */
  3753. uint64_t Main::last_ticks = 0;
  3754. uint32_t Main::frames = 0;
  3755. uint32_t Main::hide_print_fps_attempts = 3;
  3756. uint32_t Main::frame = 0;
  3757. bool Main::force_redraw_requested = false;
  3758. int Main::iterating = 0;
  3759. bool Main::is_iterating() {
  3760. return iterating > 0;
  3761. }
  3762. // For performance metrics.
  3763. static uint64_t physics_process_max = 0;
  3764. static uint64_t process_max = 0;
  3765. static uint64_t navigation_process_max = 0;
  3766. // Return false means iterating further, returning true means `OS::run`
  3767. // will terminate the program. In case of failure, the OS exit code needs
  3768. // to be set explicitly here (defaults to EXIT_SUCCESS).
  3769. bool Main::iteration() {
  3770. iterating++;
  3771. const uint64_t ticks = OS::get_singleton()->get_ticks_usec();
  3772. Engine::get_singleton()->_frame_ticks = ticks;
  3773. main_timer_sync.set_cpu_ticks_usec(ticks);
  3774. main_timer_sync.set_fixed_fps(fixed_fps);
  3775. const uint64_t ticks_elapsed = ticks - last_ticks;
  3776. const int physics_ticks_per_second = Engine::get_singleton()->get_physics_ticks_per_second();
  3777. const double physics_step = 1.0 / physics_ticks_per_second;
  3778. const double time_scale = Engine::get_singleton()->get_time_scale();
  3779. MainFrameTime advance = main_timer_sync.advance(physics_step, physics_ticks_per_second);
  3780. double process_step = advance.process_step;
  3781. double scaled_step = process_step * time_scale;
  3782. Engine::get_singleton()->_process_step = process_step;
  3783. Engine::get_singleton()->_physics_interpolation_fraction = advance.interpolation_fraction;
  3784. uint64_t physics_process_ticks = 0;
  3785. uint64_t process_ticks = 0;
  3786. uint64_t navigation_process_ticks = 0;
  3787. frame += ticks_elapsed;
  3788. last_ticks = ticks;
  3789. const int max_physics_steps = Engine::get_singleton()->get_max_physics_steps_per_frame();
  3790. if (fixed_fps == -1 && advance.physics_steps > max_physics_steps) {
  3791. process_step -= (advance.physics_steps - max_physics_steps) * physics_step;
  3792. advance.physics_steps = max_physics_steps;
  3793. }
  3794. bool exit = false;
  3795. // process all our active interfaces
  3796. #ifndef _3D_DISABLED
  3797. XRServer::get_singleton()->_process();
  3798. #endif // _3D_DISABLED
  3799. NavigationServer2D::get_singleton()->sync();
  3800. NavigationServer3D::get_singleton()->sync();
  3801. for (int iters = 0; iters < advance.physics_steps; ++iters) {
  3802. if (Input::get_singleton()->is_agile_input_event_flushing()) {
  3803. Input::get_singleton()->flush_buffered_events();
  3804. }
  3805. Engine::get_singleton()->_in_physics = true;
  3806. Engine::get_singleton()->_physics_frames++;
  3807. uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();
  3808. // Prepare the fixed timestep interpolated nodes BEFORE they are updated
  3809. // by the physics server, otherwise the current and previous transforms
  3810. // may be the same, and no interpolation takes place.
  3811. OS::get_singleton()->get_main_loop()->iteration_prepare();
  3812. #ifndef _3D_DISABLED
  3813. PhysicsServer3D::get_singleton()->sync();
  3814. PhysicsServer3D::get_singleton()->flush_queries();
  3815. #endif // _3D_DISABLED
  3816. PhysicsServer2D::get_singleton()->sync();
  3817. PhysicsServer2D::get_singleton()->flush_queries();
  3818. if (OS::get_singleton()->get_main_loop()->physics_process(physics_step * time_scale)) {
  3819. #ifndef _3D_DISABLED
  3820. PhysicsServer3D::get_singleton()->end_sync();
  3821. #endif // _3D_DISABLED
  3822. PhysicsServer2D::get_singleton()->end_sync();
  3823. Engine::get_singleton()->_in_physics = false;
  3824. exit = true;
  3825. break;
  3826. }
  3827. uint64_t navigation_begin = OS::get_singleton()->get_ticks_usec();
  3828. NavigationServer3D::get_singleton()->process(physics_step * time_scale);
  3829. navigation_process_ticks = MAX(navigation_process_ticks, OS::get_singleton()->get_ticks_usec() - navigation_begin); // keep the largest one for reference
  3830. navigation_process_max = MAX(OS::get_singleton()->get_ticks_usec() - navigation_begin, navigation_process_max);
  3831. message_queue->flush();
  3832. #ifndef _3D_DISABLED
  3833. PhysicsServer3D::get_singleton()->end_sync();
  3834. PhysicsServer3D::get_singleton()->step(physics_step * time_scale);
  3835. #endif // _3D_DISABLED
  3836. PhysicsServer2D::get_singleton()->end_sync();
  3837. PhysicsServer2D::get_singleton()->step(physics_step * time_scale);
  3838. message_queue->flush();
  3839. OS::get_singleton()->get_main_loop()->iteration_end();
  3840. physics_process_ticks = MAX(physics_process_ticks, OS::get_singleton()->get_ticks_usec() - physics_begin); // keep the largest one for reference
  3841. physics_process_max = MAX(OS::get_singleton()->get_ticks_usec() - physics_begin, physics_process_max);
  3842. Engine::get_singleton()->_in_physics = false;
  3843. }
  3844. if (Input::get_singleton()->is_agile_input_event_flushing()) {
  3845. Input::get_singleton()->flush_buffered_events();
  3846. }
  3847. uint64_t process_begin = OS::get_singleton()->get_ticks_usec();
  3848. if (OS::get_singleton()->get_main_loop()->process(process_step * time_scale)) {
  3849. exit = true;
  3850. }
  3851. message_queue->flush();
  3852. RenderingServer::get_singleton()->sync(); //sync if still drawing from previous frames.
  3853. const bool has_pending_resources_for_processing = RD::get_singleton() && RD::get_singleton()->has_pending_resources_for_processing();
  3854. bool wants_present = (DisplayServer::get_singleton()->can_any_window_draw() ||
  3855. DisplayServer::get_singleton()->has_additional_outputs()) &&
  3856. RenderingServer::get_singleton()->is_render_loop_enabled();
  3857. if (wants_present || has_pending_resources_for_processing) {
  3858. wants_present |= force_redraw_requested;
  3859. if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
  3860. if (RenderingServer::get_singleton()->has_changed()) {
  3861. RenderingServer::get_singleton()->draw(wants_present, scaled_step); // flush visual commands
  3862. Engine::get_singleton()->increment_frames_drawn();
  3863. }
  3864. } else {
  3865. RenderingServer::get_singleton()->draw(wants_present, scaled_step); // flush visual commands
  3866. Engine::get_singleton()->increment_frames_drawn();
  3867. force_redraw_requested = false;
  3868. }
  3869. }
  3870. process_ticks = OS::get_singleton()->get_ticks_usec() - process_begin;
  3871. process_max = MAX(process_ticks, process_max);
  3872. uint64_t frame_time = OS::get_singleton()->get_ticks_usec() - ticks;
  3873. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  3874. ScriptServer::get_language(i)->frame();
  3875. }
  3876. AudioServer::get_singleton()->update();
  3877. if (EngineDebugger::is_active()) {
  3878. EngineDebugger::get_singleton()->iteration(frame_time, process_ticks, physics_process_ticks, physics_step);
  3879. }
  3880. frames++;
  3881. Engine::get_singleton()->_process_frames++;
  3882. if (frame > 1000000) {
  3883. // Wait a few seconds before printing FPS, as FPS reporting just after the engine has started is inaccurate.
  3884. if (hide_print_fps_attempts == 0) {
  3885. if (editor || project_manager) {
  3886. if (print_fps) {
  3887. print_line(vformat("Editor FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(2)));
  3888. }
  3889. } else if (print_fps || GLOBAL_GET("debug/settings/stdout/print_fps")) {
  3890. print_line(vformat("Project FPS: %d (%s mspf)", frames, rtos(1000.0 / frames).pad_decimals(2)));
  3891. }
  3892. } else {
  3893. hide_print_fps_attempts--;
  3894. }
  3895. Engine::get_singleton()->_fps = frames;
  3896. performance->set_process_time(USEC_TO_SEC(process_max));
  3897. performance->set_physics_process_time(USEC_TO_SEC(physics_process_max));
  3898. performance->set_navigation_process_time(USEC_TO_SEC(navigation_process_max));
  3899. process_max = 0;
  3900. physics_process_max = 0;
  3901. navigation_process_max = 0;
  3902. frame %= 1000000;
  3903. frames = 0;
  3904. }
  3905. iterating--;
  3906. if (movie_writer) {
  3907. movie_writer->add_frame();
  3908. }
  3909. #ifdef TOOLS_ENABLED
  3910. bool quit_after_timeout = false;
  3911. #endif
  3912. if ((quit_after > 0) && (Engine::get_singleton()->_process_frames >= quit_after)) {
  3913. #ifdef TOOLS_ENABLED
  3914. quit_after_timeout = true;
  3915. #endif
  3916. exit = true;
  3917. }
  3918. #ifdef TOOLS_ENABLED
  3919. if (wait_for_import && EditorFileSystem::get_singleton() && EditorFileSystem::get_singleton()->doing_first_scan()) {
  3920. exit = false;
  3921. }
  3922. #endif
  3923. if (fixed_fps != -1) {
  3924. return exit;
  3925. }
  3926. OS::get_singleton()->add_frame_delay(DisplayServer::get_singleton()->window_can_draw());
  3927. #ifdef TOOLS_ENABLED
  3928. if (auto_build_solutions) {
  3929. auto_build_solutions = false;
  3930. // Only relevant when running the editor.
  3931. if (!editor) {
  3932. OS::get_singleton()->set_exit_code(EXIT_FAILURE);
  3933. ERR_FAIL_V_MSG(true,
  3934. "Command line option --build-solutions was passed, but no project is being edited. Aborting.");
  3935. }
  3936. if (!EditorNode::get_singleton()->call_build()) {
  3937. OS::get_singleton()->set_exit_code(EXIT_FAILURE);
  3938. ERR_FAIL_V_MSG(true,
  3939. "Command line option --build-solutions was passed, but the build callback failed. Aborting.");
  3940. }
  3941. }
  3942. #endif
  3943. #ifdef TOOLS_ENABLED
  3944. if (exit && quit_after_timeout && EditorNode::get_singleton()) {
  3945. EditorNode::get_singleton()->unload_editor_addons();
  3946. }
  3947. #endif
  3948. return exit;
  3949. }
  3950. void Main::force_redraw() {
  3951. force_redraw_requested = true;
  3952. }
  3953. /* Engine deinitialization
  3954. *
  3955. * Responsible for freeing all the memory allocated by previous setup steps,
  3956. * so that the engine closes cleanly without leaking memory or crashing.
  3957. * The order matters as some of those steps are linked with each other.
  3958. */
  3959. void Main::cleanup(bool p_force) {
  3960. OS::get_singleton()->benchmark_begin_measure("Shutdown", "Main::Cleanup");
  3961. if (!p_force) {
  3962. ERR_FAIL_COND(!_start_success);
  3963. }
  3964. #ifdef DEBUG_ENABLED
  3965. if (input) {
  3966. input->flush_frame_parsed_events();
  3967. }
  3968. #endif
  3969. for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
  3970. TextServerManager::get_singleton()->get_interface(i)->cleanup();
  3971. }
  3972. if (movie_writer) {
  3973. movie_writer->end();
  3974. }
  3975. ResourceLoader::clear_thread_load_tasks();
  3976. ResourceLoader::remove_custom_loaders();
  3977. ResourceSaver::remove_custom_savers();
  3978. PropertyListHelper::clear_base_helpers();
  3979. // Flush before uninitializing the scene, but delete the MessageQueue as late as possible.
  3980. message_queue->flush();
  3981. OS::get_singleton()->delete_main_loop();
  3982. OS::get_singleton()->_cmdline.clear();
  3983. OS::get_singleton()->_user_args.clear();
  3984. OS::get_singleton()->_execpath = "";
  3985. OS::get_singleton()->_local_clipboard = "";
  3986. ResourceLoader::clear_translation_remaps();
  3987. ResourceLoader::clear_path_remaps();
  3988. WorkerThreadPool::get_singleton()->exit_languages_threads();
  3989. ScriptServer::finish_languages();
  3990. // Sync pending commands that may have been queued from a different thread during ScriptServer finalization
  3991. RenderingServer::get_singleton()->sync();
  3992. //clear global shader variables before scene and other graphics stuff are deinitialized.
  3993. rendering_server->global_shader_parameters_clear();
  3994. #ifndef _3D_DISABLED
  3995. if (xr_server) {
  3996. // Now that we're unregistering properly in plugins we need to keep access to xr_server for a little longer
  3997. // We do however unset our primary interface
  3998. xr_server->set_primary_interface(Ref<XRInterface>());
  3999. }
  4000. #endif // _3D_DISABLED
  4001. #ifdef TOOLS_ENABLED
  4002. GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR);
  4003. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
  4004. unregister_editor_types();
  4005. #endif
  4006. ImageLoader::cleanup();
  4007. GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_SCENE);
  4008. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
  4009. unregister_platform_apis();
  4010. unregister_driver_types();
  4011. unregister_scene_types();
  4012. finalize_theme_db();
  4013. // Before deinitializing server extensions, finalize servers which may be loaded as extensions.
  4014. NavigationServer2DManager::finalize_server(); // 2D goes first as it uses the 3D server behind the scene.
  4015. NavigationServer3DManager::finalize_server();
  4016. finalize_physics();
  4017. GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
  4018. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
  4019. unregister_server_types();
  4020. EngineDebugger::deinitialize();
  4021. #ifndef _3D_DISABLED
  4022. if (xr_server) {
  4023. memdelete(xr_server);
  4024. }
  4025. #endif // _3D_DISABLED
  4026. if (audio_server) {
  4027. audio_server->finish();
  4028. memdelete(audio_server);
  4029. }
  4030. if (camera_server) {
  4031. memdelete(camera_server);
  4032. }
  4033. OS::get_singleton()->finalize();
  4034. finalize_display();
  4035. if (input) {
  4036. memdelete(input);
  4037. }
  4038. if (packed_data) {
  4039. memdelete(packed_data);
  4040. }
  4041. if (performance) {
  4042. memdelete(performance);
  4043. }
  4044. if (input_map) {
  4045. memdelete(input_map);
  4046. }
  4047. if (translation_server) {
  4048. memdelete(translation_server);
  4049. }
  4050. if (tsman) {
  4051. memdelete(tsman);
  4052. }
  4053. #ifndef _3D_DISABLED
  4054. if (physics_server_3d_manager) {
  4055. memdelete(physics_server_3d_manager);
  4056. }
  4057. #endif // _3D_DISABLED
  4058. if (physics_server_2d_manager) {
  4059. memdelete(physics_server_2d_manager);
  4060. }
  4061. if (globals) {
  4062. memdelete(globals);
  4063. }
  4064. if (OS::get_singleton()->is_restart_on_exit_set()) {
  4065. //attempt to restart with arguments
  4066. List<String> args = OS::get_singleton()->get_restart_on_exit_arguments();
  4067. OS::get_singleton()->create_instance(args);
  4068. OS::get_singleton()->set_restart_on_exit(false, List<String>()); //clear list (uses memory)
  4069. }
  4070. // Now should be safe to delete MessageQueue (famous last words).
  4071. message_queue->flush();
  4072. memdelete(message_queue);
  4073. #if defined(STEAMAPI_ENABLED)
  4074. if (steam_tracker) {
  4075. memdelete(steam_tracker);
  4076. }
  4077. #endif
  4078. unregister_core_driver_types();
  4079. unregister_core_extensions();
  4080. uninitialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
  4081. if (engine) {
  4082. memdelete(engine);
  4083. }
  4084. unregister_core_types();
  4085. OS::get_singleton()->benchmark_end_measure("Shutdown", "Main::Cleanup");
  4086. OS::get_singleton()->benchmark_dump();
  4087. OS::get_singleton()->finalize_core();
  4088. }