main.cpp 178 KB

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