main.cpp 176 KB

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