main.cpp 186 KB

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