laya.core.js 990 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896
  1. window.Laya= (function (exports) {
  2. 'use strict';
  3. class Config {
  4. }
  5. Config.animationInterval = 50;
  6. Config.isAntialias = false;
  7. Config.isAlpha = false;
  8. Config.premultipliedAlpha = true;
  9. Config.isStencil = true;
  10. Config.preserveDrawingBuffer = false;
  11. Config.webGL2D_MeshAllocMaxMem = true;
  12. Config.is2DPixelArtGame = false;
  13. Config.useWebGL2 = false;
  14. Config.allowGPUInstanceDynamicBatch = true;
  15. Config.useRetinalCanvas = false;
  16. window.Config = Config;
  17. class ILaya {
  18. static regClass(c) {
  19. ILaya.__classMap[c.name] = c;
  20. }
  21. }
  22. ILaya.Laya = null;
  23. ILaya.Timer = null;
  24. ILaya.WorkerLoader = null;
  25. ILaya.Dragging = null;
  26. ILaya.GraphicsBounds = null;
  27. ILaya.Sprite = null;
  28. ILaya.TextRender = null;
  29. ILaya.TextAtlas = null;
  30. ILaya.timer = null;
  31. ILaya.systemTimer = null;
  32. ILaya.startTimer = null;
  33. ILaya.updateTimer = null;
  34. ILaya.lateTimer = null;
  35. ILaya.physicsTimer = null;
  36. ILaya.stage = null;
  37. ILaya.Loader = null;
  38. ILaya.loader = null;
  39. ILaya.TTFLoader = null;
  40. ILaya.SoundManager = null;
  41. ILaya.WebAudioSound = null;
  42. ILaya.AudioSound = null;
  43. ILaya.ShaderCompile = null;
  44. ILaya.ClassUtils = null;
  45. ILaya.SceneUtils = null;
  46. ILaya.Context = null;
  47. ILaya.Render = null;
  48. ILaya.MouseManager = null;
  49. ILaya.Text = null;
  50. ILaya.Browser = null;
  51. ILaya.WebGL = null;
  52. ILaya.Pool = null;
  53. ILaya.Utils = null;
  54. ILaya.Graphics = null;
  55. ILaya.Submit = null;
  56. ILaya.Stage = null;
  57. ILaya.Resource = null;
  58. ILaya.__classMap = {};
  59. class Pool {
  60. static getPoolBySign(sign) {
  61. return Pool._poolDic[sign] || (Pool._poolDic[sign] = []);
  62. }
  63. static clearBySign(sign) {
  64. if (Pool._poolDic[sign])
  65. Pool._poolDic[sign].length = 0;
  66. }
  67. static recover(sign, item) {
  68. if (item[Pool.POOLSIGN])
  69. return;
  70. item[Pool.POOLSIGN] = true;
  71. Pool.getPoolBySign(sign).push(item);
  72. }
  73. static recoverByClass(instance) {
  74. if (instance) {
  75. var className = instance["__className"] || instance.constructor._$gid;
  76. if (className)
  77. Pool.recover(className, instance);
  78. }
  79. }
  80. static _getClassSign(cla) {
  81. var className = cla["__className"] || cla["_$gid"];
  82. if (!className) {
  83. cla["_$gid"] = className = Pool._CLSID + "";
  84. Pool._CLSID++;
  85. }
  86. return className;
  87. }
  88. static createByClass(cls) {
  89. return Pool.getItemByClass(Pool._getClassSign(cls), cls);
  90. }
  91. static getItemByClass(sign, cls) {
  92. if (!Pool._poolDic[sign])
  93. return new cls();
  94. var pool = Pool.getPoolBySign(sign);
  95. if (pool.length) {
  96. var rst = pool.pop();
  97. rst[Pool.POOLSIGN] = false;
  98. }
  99. else {
  100. rst = new cls();
  101. }
  102. return rst;
  103. }
  104. static getItemByCreateFun(sign, createFun, caller = null) {
  105. var pool = Pool.getPoolBySign(sign);
  106. var rst = pool.length ? pool.pop() : createFun.call(caller);
  107. rst[Pool.POOLSIGN] = false;
  108. return rst;
  109. }
  110. static getItem(sign) {
  111. var pool = Pool.getPoolBySign(sign);
  112. var rst = pool.length ? pool.pop() : null;
  113. if (rst) {
  114. rst[Pool.POOLSIGN] = false;
  115. }
  116. return rst;
  117. }
  118. }
  119. Pool._CLSID = 0;
  120. Pool.POOLSIGN = "__InPool";
  121. Pool._poolDic = {};
  122. class AlphaCmd {
  123. static create(alpha) {
  124. var cmd = Pool.getItemByClass("AlphaCmd", AlphaCmd);
  125. cmd.alpha = alpha;
  126. return cmd;
  127. }
  128. recover() {
  129. Pool.recover("AlphaCmd", this);
  130. }
  131. run(context, gx, gy) {
  132. context.alpha(this.alpha);
  133. }
  134. get cmdID() {
  135. return AlphaCmd.ID;
  136. }
  137. }
  138. AlphaCmd.ID = "Alpha";
  139. class DrawCircleCmd {
  140. static create(x, y, radius, fillColor, lineColor, lineWidth, vid) {
  141. var cmd = Pool.getItemByClass("DrawCircleCmd", DrawCircleCmd);
  142. cmd.x = x;
  143. cmd.y = y;
  144. cmd.radius = radius;
  145. cmd.fillColor = fillColor;
  146. cmd.lineColor = lineColor;
  147. cmd.lineWidth = lineWidth;
  148. cmd.vid = vid;
  149. return cmd;
  150. }
  151. recover() {
  152. this.fillColor = null;
  153. this.lineColor = null;
  154. Pool.recover("DrawCircleCmd", this);
  155. }
  156. run(context, gx, gy) {
  157. context._drawCircle(this.x + gx, this.y + gy, this.radius, this.fillColor, this.lineColor, this.lineWidth, this.vid);
  158. }
  159. get cmdID() {
  160. return DrawCircleCmd.ID;
  161. }
  162. }
  163. DrawCircleCmd.ID = "DrawCircle";
  164. class DrawCurvesCmd {
  165. static create(x, y, points, lineColor, lineWidth) {
  166. var cmd = Pool.getItemByClass("DrawCurvesCmd", DrawCurvesCmd);
  167. cmd.x = x;
  168. cmd.y = y;
  169. cmd.points = points;
  170. cmd.lineColor = lineColor;
  171. cmd.lineWidth = lineWidth;
  172. return cmd;
  173. }
  174. recover() {
  175. this.points = null;
  176. this.lineColor = null;
  177. Pool.recover("DrawCurvesCmd", this);
  178. }
  179. run(context, gx, gy) {
  180. if (this.points)
  181. context.drawCurves(this.x + gx, this.y + gy, this.points, this.lineColor, this.lineWidth);
  182. }
  183. get cmdID() {
  184. return DrawCurvesCmd.ID;
  185. }
  186. }
  187. DrawCurvesCmd.ID = "DrawCurves";
  188. class DrawImageCmd {
  189. static create(texture, x, y, width, height) {
  190. var cmd = Pool.getItemByClass("DrawImageCmd", DrawImageCmd);
  191. cmd.texture = texture;
  192. texture._addReference();
  193. cmd.x = x;
  194. cmd.y = y;
  195. cmd.width = width;
  196. cmd.height = height;
  197. return cmd;
  198. }
  199. recover() {
  200. this.texture && this.texture._removeReference();
  201. this.texture = null;
  202. Pool.recover("DrawImageCmd", this);
  203. }
  204. run(context, gx, gy) {
  205. if (this.texture)
  206. context.drawTexture(this.texture, this.x + gx, this.y + gy, this.width, this.height);
  207. }
  208. get cmdID() {
  209. return DrawImageCmd.ID;
  210. }
  211. }
  212. DrawImageCmd.ID = "DrawImage";
  213. class DrawLineCmd {
  214. static create(fromX, fromY, toX, toY, lineColor, lineWidth, vid) {
  215. var cmd = Pool.getItemByClass("DrawLineCmd", DrawLineCmd);
  216. cmd.fromX = fromX;
  217. cmd.fromY = fromY;
  218. cmd.toX = toX;
  219. cmd.toY = toY;
  220. cmd.lineColor = lineColor;
  221. cmd.lineWidth = lineWidth;
  222. cmd.vid = vid;
  223. return cmd;
  224. }
  225. recover() {
  226. Pool.recover("DrawLineCmd", this);
  227. }
  228. run(context, gx, gy) {
  229. context._drawLine(gx, gy, this.fromX, this.fromY, this.toX, this.toY, this.lineColor, this.lineWidth, this.vid);
  230. }
  231. get cmdID() {
  232. return DrawLineCmd.ID;
  233. }
  234. }
  235. DrawLineCmd.ID = "DrawLine";
  236. class DrawLinesCmd {
  237. static create(x, y, points, lineColor, lineWidth, vid) {
  238. var cmd = Pool.getItemByClass("DrawLinesCmd", DrawLinesCmd);
  239. cmd.x = x;
  240. cmd.y = y;
  241. cmd.points = points;
  242. cmd.lineColor = lineColor;
  243. cmd.lineWidth = lineWidth;
  244. cmd.vid = vid;
  245. return cmd;
  246. }
  247. recover() {
  248. this.points = null;
  249. this.lineColor = null;
  250. Pool.recover("DrawLinesCmd", this);
  251. }
  252. run(context, gx, gy) {
  253. this.points && context._drawLines(this.x + gx, this.y + gy, this.points, this.lineColor, this.lineWidth, this.vid);
  254. }
  255. get cmdID() {
  256. return DrawLinesCmd.ID;
  257. }
  258. }
  259. DrawLinesCmd.ID = "DrawLines";
  260. class DrawPathCmd {
  261. static create(x, y, paths, brush, pen) {
  262. var cmd = Pool.getItemByClass("DrawPathCmd", DrawPathCmd);
  263. cmd.x = x;
  264. cmd.y = y;
  265. cmd.paths = paths;
  266. cmd.brush = brush;
  267. cmd.pen = pen;
  268. return cmd;
  269. }
  270. recover() {
  271. this.paths = null;
  272. this.brush = null;
  273. this.pen = null;
  274. Pool.recover("DrawPathCmd", this);
  275. }
  276. run(context, gx, gy) {
  277. this.paths && context._drawPath(this.x + gx, this.y + gy, this.paths, this.brush, this.pen);
  278. }
  279. get cmdID() {
  280. return DrawPathCmd.ID;
  281. }
  282. }
  283. DrawPathCmd.ID = "DrawPath";
  284. class DrawPieCmd {
  285. static create(x, y, radius, startAngle, endAngle, fillColor, lineColor, lineWidth, vid) {
  286. var cmd = Pool.getItemByClass("DrawPieCmd", DrawPieCmd);
  287. cmd.x = x;
  288. cmd.y = y;
  289. cmd.radius = radius;
  290. cmd._startAngle = startAngle;
  291. cmd._endAngle = endAngle;
  292. cmd.fillColor = fillColor;
  293. cmd.lineColor = lineColor;
  294. cmd.lineWidth = lineWidth;
  295. cmd.vid = vid;
  296. return cmd;
  297. }
  298. recover() {
  299. this.fillColor = null;
  300. this.lineColor = null;
  301. Pool.recover("DrawPieCmd", this);
  302. }
  303. run(context, gx, gy) {
  304. context._drawPie(this.x + gx, this.y + gy, this.radius, this._startAngle, this._endAngle, this.fillColor, this.lineColor, this.lineWidth, this.vid);
  305. }
  306. get cmdID() {
  307. return DrawPieCmd.ID;
  308. }
  309. get startAngle() {
  310. return this._startAngle * 180 / Math.PI;
  311. }
  312. set startAngle(value) {
  313. this._startAngle = value * Math.PI / 180;
  314. }
  315. get endAngle() {
  316. return this._endAngle * 180 / Math.PI;
  317. }
  318. set endAngle(value) {
  319. this._endAngle = value * Math.PI / 180;
  320. }
  321. }
  322. DrawPieCmd.ID = "DrawPie";
  323. class DrawPolyCmd {
  324. static create(x, y, points, fillColor, lineColor, lineWidth, isConvexPolygon, vid) {
  325. var cmd = Pool.getItemByClass("DrawPolyCmd", DrawPolyCmd);
  326. cmd.x = x;
  327. cmd.y = y;
  328. cmd.points = points;
  329. cmd.fillColor = fillColor;
  330. cmd.lineColor = lineColor;
  331. cmd.lineWidth = lineWidth;
  332. cmd.isConvexPolygon = isConvexPolygon;
  333. cmd.vid = vid;
  334. return cmd;
  335. }
  336. recover() {
  337. this.points = null;
  338. this.fillColor = null;
  339. this.lineColor = null;
  340. Pool.recover("DrawPolyCmd", this);
  341. }
  342. run(context, gx, gy) {
  343. this.points && context._drawPoly(this.x + gx, this.y + gy, this.points, this.fillColor, this.lineColor, this.lineWidth, this.isConvexPolygon, this.vid);
  344. }
  345. get cmdID() {
  346. return DrawPolyCmd.ID;
  347. }
  348. }
  349. DrawPolyCmd.ID = "DrawPoly";
  350. class DrawRectCmd {
  351. static create(x, y, width, height, fillColor, lineColor, lineWidth) {
  352. var cmd = Pool.getItemByClass("DrawRectCmd", DrawRectCmd);
  353. cmd.x = x;
  354. cmd.y = y;
  355. cmd.width = width;
  356. cmd.height = height;
  357. cmd.fillColor = fillColor;
  358. cmd.lineColor = lineColor;
  359. cmd.lineWidth = lineWidth;
  360. return cmd;
  361. }
  362. recover() {
  363. this.fillColor = null;
  364. this.lineColor = null;
  365. Pool.recover("DrawRectCmd", this);
  366. }
  367. run(context, gx, gy) {
  368. context.drawRect(this.x + gx, this.y + gy, this.width, this.height, this.fillColor, this.lineColor, this.lineWidth);
  369. }
  370. get cmdID() {
  371. return DrawRectCmd.ID;
  372. }
  373. }
  374. DrawRectCmd.ID = "DrawRect";
  375. class Matrix {
  376. constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0, nums = 0) {
  377. this._bTransform = false;
  378. if (Matrix._createFun != null) {
  379. return Matrix._createFun(a, b, c, d, tx, ty, nums);
  380. }
  381. this.a = a;
  382. this.b = b;
  383. this.c = c;
  384. this.d = d;
  385. this.tx = tx;
  386. this.ty = ty;
  387. this._checkTransform();
  388. }
  389. identity() {
  390. this.a = this.d = 1;
  391. this.b = this.tx = this.ty = this.c = 0;
  392. this._bTransform = false;
  393. return this;
  394. }
  395. _checkTransform() {
  396. return this._bTransform = (this.a !== 1 || this.b !== 0 || this.c !== 0 || this.d !== 1);
  397. }
  398. setTranslate(x, y) {
  399. this.tx = x;
  400. this.ty = y;
  401. return this;
  402. }
  403. translate(x, y) {
  404. this.tx += x;
  405. this.ty += y;
  406. return this;
  407. }
  408. scale(x, y) {
  409. this.a *= x;
  410. this.d *= y;
  411. this.c *= x;
  412. this.b *= y;
  413. this.tx *= x;
  414. this.ty *= y;
  415. this._bTransform = true;
  416. return this;
  417. }
  418. rotate(angle) {
  419. var cos = Math.cos(angle);
  420. var sin = Math.sin(angle);
  421. var a1 = this.a;
  422. var c1 = this.c;
  423. var tx1 = this.tx;
  424. this.a = a1 * cos - this.b * sin;
  425. this.b = a1 * sin + this.b * cos;
  426. this.c = c1 * cos - this.d * sin;
  427. this.d = c1 * sin + this.d * cos;
  428. this.tx = tx1 * cos - this.ty * sin;
  429. this.ty = tx1 * sin + this.ty * cos;
  430. this._bTransform = true;
  431. return this;
  432. }
  433. skew(x, y) {
  434. var tanX = Math.tan(x);
  435. var tanY = Math.tan(y);
  436. var a1 = this.a;
  437. var b1 = this.b;
  438. this.a += tanY * this.c;
  439. this.b += tanY * this.d;
  440. this.c += tanX * a1;
  441. this.d += tanX * b1;
  442. return this;
  443. }
  444. invertTransformPoint(out) {
  445. var a1 = this.a;
  446. var b1 = this.b;
  447. var c1 = this.c;
  448. var d1 = this.d;
  449. var tx1 = this.tx;
  450. var n = a1 * d1 - b1 * c1;
  451. var a2 = d1 / n;
  452. var b2 = -b1 / n;
  453. var c2 = -c1 / n;
  454. var d2 = a1 / n;
  455. var tx2 = (c1 * this.ty - d1 * tx1) / n;
  456. var ty2 = -(a1 * this.ty - b1 * tx1) / n;
  457. return out.setTo(a2 * out.x + c2 * out.y + tx2, b2 * out.x + d2 * out.y + ty2);
  458. }
  459. transformPoint(out) {
  460. return out.setTo(this.a * out.x + this.c * out.y + this.tx, this.b * out.x + this.d * out.y + this.ty);
  461. }
  462. transformPointN(out) {
  463. return out.setTo(this.a * out.x + this.c * out.y, this.b * out.x + this.d * out.y);
  464. }
  465. getScaleX() {
  466. return this.b === 0 ? this.a : Math.sqrt(this.a * this.a + this.b * this.b);
  467. }
  468. getScaleY() {
  469. return this.c === 0 ? this.d : Math.sqrt(this.c * this.c + this.d * this.d);
  470. }
  471. invert() {
  472. var a1 = this.a;
  473. var b1 = this.b;
  474. var c1 = this.c;
  475. var d1 = this.d;
  476. var tx1 = this.tx;
  477. var n = a1 * d1 - b1 * c1;
  478. this.a = d1 / n;
  479. this.b = -b1 / n;
  480. this.c = -c1 / n;
  481. this.d = a1 / n;
  482. this.tx = (c1 * this.ty - d1 * tx1) / n;
  483. this.ty = -(a1 * this.ty - b1 * tx1) / n;
  484. return this;
  485. }
  486. setTo(a, b, c, d, tx, ty) {
  487. this.a = a, this.b = b, this.c = c, this.d = d, this.tx = tx, this.ty = ty;
  488. return this;
  489. }
  490. concat(matrix) {
  491. var a = this.a;
  492. var c = this.c;
  493. var tx = this.tx;
  494. this.a = a * matrix.a + this.b * matrix.c;
  495. this.b = a * matrix.b + this.b * matrix.d;
  496. this.c = c * matrix.a + this.d * matrix.c;
  497. this.d = c * matrix.b + this.d * matrix.d;
  498. this.tx = tx * matrix.a + this.ty * matrix.c + matrix.tx;
  499. this.ty = tx * matrix.b + this.ty * matrix.d + matrix.ty;
  500. return this;
  501. }
  502. static mul(m1, m2, out) {
  503. var aa = m1.a, ab = m1.b, ac = m1.c, ad = m1.d, atx = m1.tx, aty = m1.ty;
  504. var ba = m2.a, bb = m2.b, bc = m2.c, bd = m2.d, btx = m2.tx, bty = m2.ty;
  505. if (bb !== 0 || bc !== 0) {
  506. out.a = aa * ba + ab * bc;
  507. out.b = aa * bb + ab * bd;
  508. out.c = ac * ba + ad * bc;
  509. out.d = ac * bb + ad * bd;
  510. out.tx = ba * atx + bc * aty + btx;
  511. out.ty = bb * atx + bd * aty + bty;
  512. }
  513. else {
  514. out.a = aa * ba;
  515. out.b = ab * bd;
  516. out.c = ac * ba;
  517. out.d = ad * bd;
  518. out.tx = ba * atx + btx;
  519. out.ty = bd * aty + bty;
  520. }
  521. return out;
  522. }
  523. static mul16(m1, m2, out) {
  524. var aa = m1.a, ab = m1.b, ac = m1.c, ad = m1.d, atx = m1.tx, aty = m1.ty;
  525. var ba = m2.a, bb = m2.b, bc = m2.c, bd = m2.d, btx = m2.tx, bty = m2.ty;
  526. if (bb !== 0 || bc !== 0) {
  527. out[0] = aa * ba + ab * bc;
  528. out[1] = aa * bb + ab * bd;
  529. out[4] = ac * ba + ad * bc;
  530. out[5] = ac * bb + ad * bd;
  531. out[12] = ba * atx + bc * aty + btx;
  532. out[13] = bb * atx + bd * aty + bty;
  533. }
  534. else {
  535. out[0] = aa * ba;
  536. out[1] = ab * bd;
  537. out[4] = ac * ba;
  538. out[5] = ad * bd;
  539. out[12] = ba * atx + btx;
  540. out[13] = bd * aty + bty;
  541. }
  542. return out;
  543. }
  544. scaleEx(x, y) {
  545. var ba = this.a, bb = this.b, bc = this.c, bd = this.d;
  546. if (bb !== 0 || bc !== 0) {
  547. this.a = x * ba;
  548. this.b = x * bb;
  549. this.c = y * bc;
  550. this.d = y * bd;
  551. }
  552. else {
  553. this.a = x * ba;
  554. this.b = 0 * bd;
  555. this.c = 0 * ba;
  556. this.d = y * bd;
  557. }
  558. this._bTransform = true;
  559. }
  560. rotateEx(angle) {
  561. var cos = Math.cos(angle);
  562. var sin = Math.sin(angle);
  563. var ba = this.a, bb = this.b, bc = this.c, bd = this.d;
  564. if (bb !== 0 || bc !== 0) {
  565. this.a = cos * ba + sin * bc;
  566. this.b = cos * bb + sin * bd;
  567. this.c = -sin * ba + cos * bc;
  568. this.d = -sin * bb + cos * bd;
  569. }
  570. else {
  571. this.a = cos * ba;
  572. this.b = sin * bd;
  573. this.c = -sin * ba;
  574. this.d = cos * bd;
  575. }
  576. this._bTransform = true;
  577. }
  578. clone() {
  579. var dec = Matrix.create();
  580. dec.a = this.a;
  581. dec.b = this.b;
  582. dec.c = this.c;
  583. dec.d = this.d;
  584. dec.tx = this.tx;
  585. dec.ty = this.ty;
  586. dec._bTransform = this._bTransform;
  587. return dec;
  588. }
  589. copyTo(dec) {
  590. dec.a = this.a;
  591. dec.b = this.b;
  592. dec.c = this.c;
  593. dec.d = this.d;
  594. dec.tx = this.tx;
  595. dec.ty = this.ty;
  596. dec._bTransform = this._bTransform;
  597. return dec;
  598. }
  599. toString() {
  600. return this.a + "," + this.b + "," + this.c + "," + this.d + "," + this.tx + "," + this.ty;
  601. }
  602. destroy() {
  603. this.recover();
  604. }
  605. recover() {
  606. Pool.recover("Matrix", this.identity());
  607. }
  608. static create() {
  609. return Pool.getItemByClass("Matrix", Matrix);
  610. }
  611. }
  612. Matrix.EMPTY = new Matrix();
  613. Matrix.TEMP = new Matrix();
  614. Matrix._createFun = null;
  615. class Point {
  616. constructor(x = 0, y = 0) {
  617. this.x = x;
  618. this.y = y;
  619. }
  620. static create() {
  621. return Pool.getItemByClass("Point", Point);
  622. }
  623. setTo(x, y) {
  624. this.x = x;
  625. this.y = y;
  626. return this;
  627. }
  628. reset() {
  629. this.x = this.y = 0;
  630. return this;
  631. }
  632. recover() {
  633. Pool.recover("Point", this.reset());
  634. }
  635. distance(x, y) {
  636. return Math.sqrt((this.x - x) * (this.x - x) + (this.y - y) * (this.y - y));
  637. }
  638. toString() {
  639. return this.x + "," + this.y;
  640. }
  641. normalize() {
  642. var d = Math.sqrt(this.x * this.x + this.y * this.y);
  643. if (d > 0) {
  644. var id = 1.0 / d;
  645. this.x *= id;
  646. this.y *= id;
  647. }
  648. }
  649. copy(point) {
  650. return this.setTo(point.x, point.y);
  651. }
  652. }
  653. Point.TEMP = new Point();
  654. Point.EMPTY = new Point();
  655. class Rectangle {
  656. constructor(x = 0, y = 0, width = 0, height = 0) {
  657. this.x = x;
  658. this.y = y;
  659. this.width = width;
  660. this.height = height;
  661. }
  662. get right() {
  663. return this.x + this.width;
  664. }
  665. get bottom() {
  666. return this.y + this.height;
  667. }
  668. setTo(x, y, width, height) {
  669. this.x = x;
  670. this.y = y;
  671. this.width = width;
  672. this.height = height;
  673. return this;
  674. }
  675. reset() {
  676. this.x = this.y = this.width = this.height = 0;
  677. return this;
  678. }
  679. recover() {
  680. if (this == Rectangle.TEMP || this == Rectangle.EMPTY) {
  681. console.log("recover Temp or Empty:", this);
  682. return;
  683. }
  684. Pool.recover("Rectangle", this.reset());
  685. }
  686. static create() {
  687. return Pool.getItemByClass("Rectangle", Rectangle);
  688. }
  689. copyFrom(source) {
  690. this.x = source.x;
  691. this.y = source.y;
  692. this.width = source.width;
  693. this.height = source.height;
  694. return this;
  695. }
  696. contains(x, y) {
  697. if (this.width <= 0 || this.height <= 0)
  698. return false;
  699. if (x >= this.x && x < this.right) {
  700. if (y >= this.y && y < this.bottom) {
  701. return true;
  702. }
  703. }
  704. return false;
  705. }
  706. intersects(rect) {
  707. return !(rect.x > (this.x + this.width) || (rect.x + rect.width) < this.x || rect.y > (this.y + this.height) || (rect.y + rect.height) < this.y);
  708. }
  709. intersection(rect, out = null) {
  710. if (!this.intersects(rect))
  711. return null;
  712. out || (out = new Rectangle());
  713. out.x = Math.max(this.x, rect.x);
  714. out.y = Math.max(this.y, rect.y);
  715. out.width = Math.min(this.right, rect.right) - out.x;
  716. out.height = Math.min(this.bottom, rect.bottom) - out.y;
  717. return out;
  718. }
  719. union(source, out = null) {
  720. out || (out = new Rectangle());
  721. this.clone(out);
  722. if (source.width <= 0 || source.height <= 0)
  723. return out;
  724. out.addPoint(source.x, source.y);
  725. out.addPoint(source.right, source.bottom);
  726. return this;
  727. }
  728. clone(out = null) {
  729. out || (out = new Rectangle());
  730. out.x = this.x;
  731. out.y = this.y;
  732. out.width = this.width;
  733. out.height = this.height;
  734. return out;
  735. }
  736. toString() {
  737. return this.x + "," + this.y + "," + this.width + "," + this.height;
  738. }
  739. equals(rect) {
  740. if (!rect || rect.x !== this.x || rect.y !== this.y || rect.width !== this.width || rect.height !== this.height)
  741. return false;
  742. return true;
  743. }
  744. addPoint(x, y) {
  745. this.x > x && (this.width += this.x - x, this.x = x);
  746. this.y > y && (this.height += this.y - y, this.y = y);
  747. if (this.width < x - this.x)
  748. this.width = x - this.x;
  749. if (this.height < y - this.y)
  750. this.height = y - this.y;
  751. return this;
  752. }
  753. _getBoundPoints() {
  754. var rst = Rectangle._temB;
  755. rst.length = 0;
  756. if (this.width == 0 || this.height == 0)
  757. return rst;
  758. rst.push(this.x, this.y, this.x + this.width, this.y, this.x, this.y + this.height, this.x + this.width, this.y + this.height);
  759. return rst;
  760. }
  761. static _getBoundPointS(x, y, width, height) {
  762. var rst = Rectangle._temA;
  763. rst.length = 0;
  764. if (width == 0 || height == 0)
  765. return rst;
  766. rst.push(x, y, x + width, y, x, y + height, x + width, y + height);
  767. return rst;
  768. }
  769. static _getWrapRec(pointList, rst = null) {
  770. if (!pointList || pointList.length < 1)
  771. return rst ? rst.setTo(0, 0, 0, 0) : Rectangle.TEMP.setTo(0, 0, 0, 0);
  772. rst = rst ? rst : Rectangle.create();
  773. var i, len = pointList.length, minX, maxX, minY, maxY, tPoint = Point.TEMP;
  774. minX = minY = 99999;
  775. maxX = maxY = -minX;
  776. for (i = 0; i < len; i += 2) {
  777. tPoint.x = pointList[i];
  778. tPoint.y = pointList[i + 1];
  779. minX = minX < tPoint.x ? minX : tPoint.x;
  780. minY = minY < tPoint.y ? minY : tPoint.y;
  781. maxX = maxX > tPoint.x ? maxX : tPoint.x;
  782. maxY = maxY > tPoint.y ? maxY : tPoint.y;
  783. }
  784. return rst.setTo(minX, minY, maxX - minX, maxY - minY);
  785. }
  786. isEmpty() {
  787. if (this.width <= 0 || this.height <= 0)
  788. return true;
  789. return false;
  790. }
  791. }
  792. Rectangle.EMPTY = new Rectangle();
  793. Rectangle.TEMP = new Rectangle();
  794. Rectangle._temB = [];
  795. Rectangle._temA = [];
  796. class LayaGL {
  797. }
  798. LayaGL.ARRAY_BUFFER_TYPE_DATA = 0;
  799. LayaGL.ARRAY_BUFFER_TYPE_CMD = 1;
  800. LayaGL.ARRAY_BUFFER_REF_REFERENCE = 0;
  801. LayaGL.ARRAY_BUFFER_REF_COPY = 1;
  802. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID = 0;
  803. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA = 1;
  804. class WebGLContext {
  805. static __init__() {
  806. var gl = LayaGL.instance;
  807. WebGLContext._depthFunc = gl.LESS;
  808. WebGLContext._blendEquation = gl.FUNC_ADD;
  809. WebGLContext._blendEquationRGB = gl.FUNC_ADD;
  810. WebGLContext._blendEquationAlpha = gl.FUNC_ADD;
  811. WebGLContext._sFactor = gl.ONE;
  812. WebGLContext._dFactor = gl.ZERO;
  813. WebGLContext._sFactorAlpha = gl.ONE;
  814. WebGLContext._dFactorAlpha = gl.ZERO;
  815. WebGLContext._activedTextureID = gl.TEXTURE0;
  816. WebGLContext._glTextureIDs = [gl.TEXTURE0, gl.TEXTURE1, gl.TEXTURE2, gl.TEXTURE3, gl.TEXTURE4, gl.TEXTURE5, gl.TEXTURE6, gl.TEXTURE7];
  817. }
  818. static useProgram(gl, program) {
  819. if (WebGLContext._useProgram === program)
  820. return false;
  821. gl.useProgram(program);
  822. WebGLContext._useProgram = program;
  823. return true;
  824. }
  825. static setDepthTest(gl, value) {
  826. value !== WebGLContext._depthTest && (WebGLContext._depthTest = value, value ? gl.enable(gl.DEPTH_TEST) : gl.disable(gl.DEPTH_TEST));
  827. }
  828. static setDepthMask(gl, value) {
  829. value !== WebGLContext._depthMask && (WebGLContext._depthMask = value, gl.depthMask(value));
  830. }
  831. static setDepthFunc(gl, value) {
  832. value !== WebGLContext._depthFunc && (WebGLContext._depthFunc = value, gl.depthFunc(value));
  833. }
  834. static setBlend(gl, value) {
  835. value !== WebGLContext._blend && (WebGLContext._blend = value, value ? gl.enable(gl.BLEND) : gl.disable(gl.BLEND));
  836. }
  837. static setBlendEquation(gl, blendEquation) {
  838. if (blendEquation !== WebGLContext._blendEquation) {
  839. WebGLContext._blendEquation = blendEquation;
  840. WebGLContext._blendEquationRGB = WebGLContext._blendEquationAlpha = null;
  841. gl.blendEquation(blendEquation);
  842. }
  843. }
  844. static setBlendEquationSeparate(gl, blendEquationRGB, blendEquationAlpha) {
  845. if (blendEquationRGB !== WebGLContext._blendEquationRGB || blendEquationAlpha !== WebGLContext._blendEquationAlpha) {
  846. WebGLContext._blendEquationRGB = blendEquationRGB;
  847. WebGLContext._blendEquationAlpha = blendEquationAlpha;
  848. WebGLContext._blendEquation = null;
  849. gl.blendEquationSeparate(blendEquationRGB, blendEquationAlpha);
  850. }
  851. }
  852. static setBlendFunc(gl, sFactor, dFactor, force = false) {
  853. if (force || sFactor !== WebGLContext._sFactor || dFactor !== WebGLContext._dFactor) {
  854. WebGLContext._sFactor = sFactor;
  855. WebGLContext._dFactor = dFactor;
  856. WebGLContext._sFactorRGB = null;
  857. WebGLContext._dFactorRGB = null;
  858. WebGLContext._sFactorAlpha = null;
  859. WebGLContext._dFactorAlpha = null;
  860. gl.blendFunc(sFactor, dFactor);
  861. }
  862. }
  863. static setBlendFuncSeperate(gl, srcRGB, dstRGB, srcAlpha, dstAlpha) {
  864. if (srcRGB !== WebGLContext._sFactorRGB || dstRGB !== WebGLContext._dFactorRGB || srcAlpha !== WebGLContext._sFactorAlpha || dstAlpha !== WebGLContext._dFactorAlpha) {
  865. WebGLContext._sFactorRGB = srcRGB;
  866. WebGLContext._dFactorRGB = dstRGB;
  867. WebGLContext._sFactorAlpha = srcAlpha;
  868. WebGLContext._dFactorAlpha = dstAlpha;
  869. WebGLContext._sFactor = null;
  870. WebGLContext._dFactor = null;
  871. gl.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
  872. }
  873. }
  874. static setCullFace(gl, value) {
  875. value !== WebGLContext._cullFace && (WebGLContext._cullFace = value, value ? gl.enable(gl.CULL_FACE) : gl.disable(gl.CULL_FACE));
  876. }
  877. static setFrontFace(gl, value) {
  878. value !== WebGLContext._frontFace && (WebGLContext._frontFace = value, gl.frontFace(value));
  879. }
  880. static activeTexture(gl, textureID) {
  881. if (WebGLContext._activedTextureID !== textureID) {
  882. gl.activeTexture(textureID);
  883. WebGLContext._activedTextureID = textureID;
  884. }
  885. }
  886. static bindTexture(gl, target, texture) {
  887. if (WebGLContext._activeTextures[WebGLContext._activedTextureID - gl.TEXTURE0] !== texture) {
  888. gl.bindTexture(target, texture);
  889. WebGLContext._activeTextures[WebGLContext._activedTextureID - gl.TEXTURE0] = texture;
  890. }
  891. }
  892. static __init_native() {
  893. if (!ILaya.Render.supportWebGLPlusRendering)
  894. return;
  895. var webGLContext = WebGLContext;
  896. webGLContext.activeTexture = webGLContext.activeTextureForNative;
  897. webGLContext.bindTexture = webGLContext.bindTextureForNative;
  898. }
  899. static useProgramForNative(gl, program) {
  900. gl.useProgram(program);
  901. return true;
  902. }
  903. static setDepthTestForNative(gl, value) {
  904. if (value)
  905. gl.enable(gl.DEPTH_TEST);
  906. else
  907. gl.disable(gl.DEPTH_TEST);
  908. }
  909. static setDepthMaskForNative(gl, value) {
  910. gl.depthMask(value);
  911. }
  912. static setDepthFuncForNative(gl, value) {
  913. gl.depthFunc(value);
  914. }
  915. static setBlendForNative(gl, value) {
  916. if (value)
  917. gl.enable(gl.BLEND);
  918. else
  919. gl.disable(gl.BLEND);
  920. }
  921. static setBlendFuncForNative(gl, sFactor, dFactor) {
  922. gl.blendFunc(sFactor, dFactor);
  923. }
  924. static setCullFaceForNative(gl, value) {
  925. if (value)
  926. gl.enable(gl.CULL_FACE);
  927. else
  928. gl.disable(gl.CULL_FACE);
  929. }
  930. static setFrontFaceForNative(gl, value) {
  931. gl.frontFace(value);
  932. }
  933. static activeTextureForNative(gl, textureID) {
  934. gl.activeTexture(textureID);
  935. }
  936. static bindTextureForNative(gl, target, texture) {
  937. gl.bindTexture(target, texture);
  938. }
  939. static bindVertexArrayForNative(gl, vertexArray) {
  940. gl.bindVertexArray(vertexArray);
  941. }
  942. }
  943. WebGLContext._activeTextures = new Array(8);
  944. WebGLContext._useProgram = null;
  945. WebGLContext._depthTest = true;
  946. WebGLContext._depthMask = true;
  947. WebGLContext._blend = false;
  948. WebGLContext._cullFace = false;
  949. WebGLContext.mainContext = null;
  950. class Handler {
  951. constructor(caller = null, method = null, args = null, once = false) {
  952. this.once = false;
  953. this._id = 0;
  954. this.setTo(caller, method, args, once);
  955. }
  956. setTo(caller, method, args, once = false) {
  957. this._id = Handler._gid++;
  958. this.caller = caller;
  959. this.method = method;
  960. this.args = args;
  961. this.once = once;
  962. return this;
  963. }
  964. run() {
  965. if (this.method == null)
  966. return null;
  967. var id = this._id;
  968. var result = this.method.apply(this.caller, this.args);
  969. this._id === id && this.once && this.recover();
  970. return result;
  971. }
  972. runWith(data) {
  973. if (this.method == null)
  974. return null;
  975. var id = this._id;
  976. if (data == null)
  977. var result = this.method.apply(this.caller, this.args);
  978. else if (!this.args && !data.unshift)
  979. result = this.method.call(this.caller, data);
  980. else if (this.args)
  981. result = this.method.apply(this.caller, this.args.concat(data));
  982. else
  983. result = this.method.apply(this.caller, data);
  984. this._id === id && this.once && this.recover();
  985. return result;
  986. }
  987. clear() {
  988. this.caller = null;
  989. this.method = null;
  990. this.args = null;
  991. return this;
  992. }
  993. recover() {
  994. if (this._id > 0) {
  995. this._id = 0;
  996. Handler._pool.push(this.clear());
  997. }
  998. }
  999. static create(caller, method, args = null, once = true) {
  1000. if (Handler._pool.length)
  1001. return Handler._pool.pop().setTo(caller, method, args, once);
  1002. return new Handler(caller, method, args, once);
  1003. }
  1004. }
  1005. Handler._pool = [];
  1006. Handler._gid = 1;
  1007. class EventDispatcher {
  1008. hasListener(type) {
  1009. var listener = this._events && this._events[type];
  1010. return !!listener;
  1011. }
  1012. event(type, data = null) {
  1013. if (!this._events || !this._events[type])
  1014. return false;
  1015. var listeners = this._events[type];
  1016. if (listeners.run) {
  1017. if (listeners.once)
  1018. delete this._events[type];
  1019. data != null ? listeners.runWith(data) : listeners.run();
  1020. }
  1021. else {
  1022. for (var i = 0, n = listeners.length; i < n; i++) {
  1023. var listener = listeners[i];
  1024. if (listener) {
  1025. (data != null) ? listener.runWith(data) : listener.run();
  1026. }
  1027. if (!listener || listener.once) {
  1028. listeners.splice(i, 1);
  1029. i--;
  1030. n--;
  1031. }
  1032. }
  1033. if (listeners.length === 0 && this._events)
  1034. delete this._events[type];
  1035. }
  1036. return true;
  1037. }
  1038. on(type, caller, listener, args = null) {
  1039. return this._createListener(type, caller, listener, args, false);
  1040. }
  1041. once(type, caller, listener, args = null) {
  1042. return this._createListener(type, caller, listener, args, true);
  1043. }
  1044. _createListener(type, caller, listener, args, once, offBefore = true) {
  1045. offBefore && this.off(type, caller, listener, once);
  1046. var handler = EventHandler.create(caller || this, listener, args, once);
  1047. this._events || (this._events = {});
  1048. var events = this._events;
  1049. if (!events[type])
  1050. events[type] = handler;
  1051. else {
  1052. if (!events[type].run)
  1053. events[type].push(handler);
  1054. else
  1055. events[type] = [events[type], handler];
  1056. }
  1057. return this;
  1058. }
  1059. off(type, caller, listener, onceOnly = false) {
  1060. if (!this._events || !this._events[type])
  1061. return this;
  1062. var listeners = this._events[type];
  1063. if (listeners != null) {
  1064. if (listeners.run) {
  1065. if ((!caller || listeners.caller === caller) && (listener == null || listeners.method === listener) && (!onceOnly || listeners.once)) {
  1066. delete this._events[type];
  1067. listeners.recover();
  1068. }
  1069. }
  1070. else {
  1071. var count = 0;
  1072. for (var i = 0, n = listeners.length; i < n; i++) {
  1073. var item = listeners[i];
  1074. if (!item) {
  1075. count++;
  1076. continue;
  1077. }
  1078. if (item && (!caller || item.caller === caller) && (listener == null || item.method === listener) && (!onceOnly || item.once)) {
  1079. count++;
  1080. listeners[i] = null;
  1081. item.recover();
  1082. }
  1083. }
  1084. if (count === n)
  1085. delete this._events[type];
  1086. }
  1087. }
  1088. return this;
  1089. }
  1090. offAll(type = null) {
  1091. var events = this._events;
  1092. if (!events)
  1093. return this;
  1094. if (type) {
  1095. this._recoverHandlers(events[type]);
  1096. delete events[type];
  1097. }
  1098. else {
  1099. for (var name in events) {
  1100. this._recoverHandlers(events[name]);
  1101. }
  1102. this._events = null;
  1103. }
  1104. return this;
  1105. }
  1106. offAllCaller(caller) {
  1107. if (caller && this._events) {
  1108. for (var name in this._events) {
  1109. this.off(name, caller, null);
  1110. }
  1111. }
  1112. return this;
  1113. }
  1114. _recoverHandlers(arr) {
  1115. if (!arr)
  1116. return;
  1117. if (arr.run) {
  1118. arr.recover();
  1119. }
  1120. else {
  1121. for (var i = arr.length - 1; i > -1; i--) {
  1122. if (arr[i]) {
  1123. arr[i].recover();
  1124. arr[i] = null;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. isMouseEvent(type) {
  1130. return EventDispatcher.MOUSE_EVENTS[type] || false;
  1131. }
  1132. }
  1133. EventDispatcher.MOUSE_EVENTS = { "rightmousedown": true, "rightmouseup": true, "rightclick": true, "mousedown": true, "mouseup": true, "mousemove": true, "mouseover": true, "mouseout": true, "click": true, "doubleclick": true };
  1134. class EventHandler extends Handler {
  1135. constructor(caller, method, args, once) {
  1136. super(caller, method, args, once);
  1137. }
  1138. recover() {
  1139. if (this._id > 0) {
  1140. this._id = 0;
  1141. EventHandler._pool.push(this.clear());
  1142. }
  1143. }
  1144. static create(caller, method, args = null, once = true) {
  1145. if (EventHandler._pool.length)
  1146. return EventHandler._pool.pop().setTo(caller, method, args, once);
  1147. return new EventHandler(caller, method, args, once);
  1148. }
  1149. }
  1150. EventHandler._pool = [];
  1151. class URL {
  1152. constructor(url) {
  1153. this._url = URL.formatURL(url);
  1154. this._path = URL.getPath(url);
  1155. }
  1156. get url() {
  1157. return this._url;
  1158. }
  1159. get path() {
  1160. return this._path;
  1161. }
  1162. static set basePath(value) {
  1163. URL._basePath = ILaya.Laya._getUrlPath();
  1164. URL._basePath = URL.formatURL(value);
  1165. }
  1166. static get basePath() {
  1167. return URL._basePath;
  1168. }
  1169. static formatURL(url) {
  1170. if (!url)
  1171. return "null path";
  1172. if (url.indexOf(":") > 0)
  1173. return url;
  1174. if (URL.customFormat != null)
  1175. url = URL.customFormat(url);
  1176. if (url.indexOf(":") > 0)
  1177. return url;
  1178. var char1 = url.charAt(0);
  1179. if (char1 === ".") {
  1180. return URL._formatRelativePath(URL._basePath + url);
  1181. }
  1182. else if (char1 === '~') {
  1183. return URL.rootPath + url.substring(1);
  1184. }
  1185. else if (char1 === "d") {
  1186. if (url.indexOf("data:image") === 0)
  1187. return url;
  1188. }
  1189. else if (char1 === "/") {
  1190. return url;
  1191. }
  1192. return URL._basePath + url;
  1193. }
  1194. static _formatRelativePath(value) {
  1195. var parts = value.split("/");
  1196. for (var i = 0, len = parts.length; i < len; i++) {
  1197. if (parts[i] == '..') {
  1198. parts.splice(i - 1, 2);
  1199. i -= 2;
  1200. }
  1201. }
  1202. return parts.join('/');
  1203. }
  1204. static getPath(url) {
  1205. var ofs = url.lastIndexOf('/');
  1206. return ofs > 0 ? url.substr(0, ofs + 1) : "";
  1207. }
  1208. static getFileName(url) {
  1209. var ofs = url.lastIndexOf('/');
  1210. return ofs > 0 ? url.substr(ofs + 1) : url;
  1211. }
  1212. static getAdptedFilePath(url) {
  1213. if (!URL.exportSceneToJson || !url)
  1214. return url;
  1215. var i, len;
  1216. len = URL._adpteTypeList.length;
  1217. var tArr;
  1218. for (i = 0; i < len; i++) {
  1219. tArr = URL._adpteTypeList[i];
  1220. url = url.replace(tArr[0], tArr[1]);
  1221. }
  1222. return url;
  1223. }
  1224. }
  1225. URL.version = {};
  1226. URL.exportSceneToJson = false;
  1227. URL._basePath = "";
  1228. URL.rootPath = "";
  1229. URL.customFormat = function (url) {
  1230. var newUrl = URL.version[url];
  1231. if (!window.conch && newUrl)
  1232. url += "?v=" + newUrl;
  1233. return url;
  1234. };
  1235. URL._adpteTypeList = [[".scene3d", ".json"], [".scene", ".json"], [".taa", ".json"], [".prefab", ".json"]];
  1236. class Resource extends EventDispatcher {
  1237. constructor() {
  1238. super();
  1239. this._id = 0;
  1240. this._url = null;
  1241. this._cpuMemory = 0;
  1242. this._gpuMemory = 0;
  1243. this._destroyed = false;
  1244. this._referenceCount = 0;
  1245. this.lock = false;
  1246. this.name = null;
  1247. this._id = ++Resource._uniqueIDCounter;
  1248. this._destroyed = false;
  1249. this._referenceCount = 0;
  1250. Resource._idResourcesMap[this.id] = this;
  1251. this.lock = false;
  1252. }
  1253. static get cpuMemory() {
  1254. return Resource._cpuMemory;
  1255. }
  1256. static get gpuMemory() {
  1257. return Resource._gpuMemory;
  1258. }
  1259. static _addCPUMemory(size) {
  1260. Resource._cpuMemory += size;
  1261. }
  1262. static _addGPUMemory(size) {
  1263. Resource._gpuMemory += size;
  1264. }
  1265. static _addMemory(cpuSize, gpuSize) {
  1266. Resource._cpuMemory += cpuSize;
  1267. Resource._gpuMemory += gpuSize;
  1268. }
  1269. static getResourceByID(id) {
  1270. return Resource._idResourcesMap[id];
  1271. }
  1272. static getResourceByURL(url, index = 0) {
  1273. return Resource._urlResourcesMap[url][index];
  1274. }
  1275. static destroyUnusedResources() {
  1276. for (var k in Resource._idResourcesMap) {
  1277. var res = Resource._idResourcesMap[k];
  1278. if (!res.lock && res._referenceCount === 0)
  1279. res.destroy();
  1280. }
  1281. }
  1282. get id() {
  1283. return this._id;
  1284. }
  1285. get url() {
  1286. return this._url;
  1287. }
  1288. get cpuMemory() {
  1289. return this._cpuMemory;
  1290. }
  1291. get gpuMemory() {
  1292. return this._gpuMemory;
  1293. }
  1294. get destroyed() {
  1295. return this._destroyed;
  1296. }
  1297. get referenceCount() {
  1298. return this._referenceCount;
  1299. }
  1300. _setCPUMemory(value) {
  1301. var offsetValue = value - this._cpuMemory;
  1302. this._cpuMemory = value;
  1303. Resource._addCPUMemory(offsetValue);
  1304. }
  1305. _setGPUMemory(value) {
  1306. var offsetValue = value - this._gpuMemory;
  1307. this._gpuMemory = value;
  1308. Resource._addGPUMemory(offsetValue);
  1309. }
  1310. _setCreateURL(url) {
  1311. url = URL.formatURL(url);
  1312. if (this._url !== url) {
  1313. var resList;
  1314. if (this._url) {
  1315. resList = Resource._urlResourcesMap[this._url];
  1316. resList.splice(resList.indexOf(this), 1);
  1317. (resList.length === 0) && (delete Resource._urlResourcesMap[this._url]);
  1318. }
  1319. if (url) {
  1320. resList = Resource._urlResourcesMap[url];
  1321. (resList) || (Resource._urlResourcesMap[url] = resList = []);
  1322. resList.push(this);
  1323. }
  1324. this._url = url;
  1325. }
  1326. }
  1327. _addReference(count = 1) {
  1328. this._referenceCount += count;
  1329. }
  1330. _removeReference(count = 1) {
  1331. this._referenceCount -= count;
  1332. }
  1333. _clearReference() {
  1334. this._referenceCount = 0;
  1335. }
  1336. _recoverResource() {
  1337. }
  1338. _disposeResource() {
  1339. }
  1340. _activeResource() {
  1341. }
  1342. destroy() {
  1343. if (this._destroyed)
  1344. return;
  1345. this._destroyed = true;
  1346. this.lock = false;
  1347. this._disposeResource();
  1348. delete Resource._idResourcesMap[this.id];
  1349. var resList;
  1350. if (this._url) {
  1351. resList = Resource._urlResourcesMap[this._url];
  1352. if (resList) {
  1353. resList.splice(resList.indexOf(this), 1);
  1354. (resList.length === 0) && (delete Resource._urlResourcesMap[this._url]);
  1355. }
  1356. var resou = ILaya.Loader.loadedMap[this._url];
  1357. (resou == this) && (delete ILaya.Loader.loadedMap[this._url]);
  1358. }
  1359. }
  1360. }
  1361. Resource._uniqueIDCounter = 0;
  1362. Resource._idResourcesMap = {};
  1363. Resource._urlResourcesMap = {};
  1364. Resource._cpuMemory = 0;
  1365. Resource._gpuMemory = 0;
  1366. class Bitmap extends Resource {
  1367. constructor() {
  1368. super();
  1369. this._width = -1;
  1370. this._height = -1;
  1371. }
  1372. get width() {
  1373. return this._width;
  1374. }
  1375. set width(width) {
  1376. this._width = width;
  1377. }
  1378. get height() {
  1379. return this._height;
  1380. }
  1381. set height(height) {
  1382. this._height = height;
  1383. }
  1384. _getSource() {
  1385. throw "Bitmap: must override it.";
  1386. }
  1387. }
  1388. (function (FilterMode) {
  1389. FilterMode[FilterMode["Point"] = 0] = "Point";
  1390. FilterMode[FilterMode["Bilinear"] = 1] = "Bilinear";
  1391. FilterMode[FilterMode["Trilinear"] = 2] = "Trilinear";
  1392. })(exports.FilterMode || (exports.FilterMode = {}));
  1393. (function (TextureFormat) {
  1394. TextureFormat[TextureFormat["R8G8B8"] = 0] = "R8G8B8";
  1395. TextureFormat[TextureFormat["R8G8B8A8"] = 1] = "R8G8B8A8";
  1396. TextureFormat[TextureFormat["R5G6B5"] = 16] = "R5G6B5";
  1397. TextureFormat[TextureFormat["Alpha8"] = 2] = "Alpha8";
  1398. TextureFormat[TextureFormat["DXT1"] = 3] = "DXT1";
  1399. TextureFormat[TextureFormat["DXT5"] = 4] = "DXT5";
  1400. TextureFormat[TextureFormat["ETC1RGB"] = 5] = "ETC1RGB";
  1401. TextureFormat[TextureFormat["PVRTCRGB_2BPPV"] = 9] = "PVRTCRGB_2BPPV";
  1402. TextureFormat[TextureFormat["PVRTCRGBA_2BPPV"] = 10] = "PVRTCRGBA_2BPPV";
  1403. TextureFormat[TextureFormat["PVRTCRGB_4BPPV"] = 11] = "PVRTCRGB_4BPPV";
  1404. TextureFormat[TextureFormat["PVRTCRGBA_4BPPV"] = 12] = "PVRTCRGBA_4BPPV";
  1405. TextureFormat[TextureFormat["R32G32B32A32"] = 15] = "R32G32B32A32";
  1406. })(exports.TextureFormat || (exports.TextureFormat = {}));
  1407. (function (WarpMode) {
  1408. WarpMode[WarpMode["Repeat"] = 0] = "Repeat";
  1409. WarpMode[WarpMode["Clamp"] = 1] = "Clamp";
  1410. })(exports.WarpMode || (exports.WarpMode = {}));
  1411. class BaseTexture extends Bitmap {
  1412. constructor(format, mipMap) {
  1413. super();
  1414. this._wrapModeU = exports.WarpMode.Repeat;
  1415. this._wrapModeV = exports.WarpMode.Repeat;
  1416. this._filterMode = exports.FilterMode.Bilinear;
  1417. this._readyed = false;
  1418. this._width = -1;
  1419. this._height = -1;
  1420. this._format = format;
  1421. this._mipmap = mipMap;
  1422. this._anisoLevel = 1;
  1423. this._glTexture = LayaGL.instance.createTexture();
  1424. }
  1425. get mipmap() {
  1426. return this._mipmap;
  1427. }
  1428. get format() {
  1429. return this._format;
  1430. }
  1431. get wrapModeU() {
  1432. return this._wrapModeU;
  1433. }
  1434. set wrapModeU(value) {
  1435. if (this._wrapModeU !== value) {
  1436. this._wrapModeU = value;
  1437. (this._width !== -1) && (this._setWarpMode(LayaGL.instance.TEXTURE_WRAP_S, value));
  1438. }
  1439. }
  1440. get wrapModeV() {
  1441. return this._wrapModeV;
  1442. }
  1443. set wrapModeV(value) {
  1444. if (this._wrapModeV !== value) {
  1445. this._wrapModeV = value;
  1446. (this._height !== -1) && (this._setWarpMode(LayaGL.instance.TEXTURE_WRAP_T, value));
  1447. }
  1448. }
  1449. get filterMode() {
  1450. return this._filterMode;
  1451. }
  1452. set filterMode(value) {
  1453. if (value !== this._filterMode) {
  1454. this._filterMode = value;
  1455. ((this._width !== -1) && (this._height !== -1)) && (this._setFilterMode(value));
  1456. }
  1457. }
  1458. get anisoLevel() {
  1459. return this._anisoLevel;
  1460. }
  1461. set anisoLevel(value) {
  1462. if (value !== this._anisoLevel) {
  1463. this._anisoLevel = Math.max(1, Math.min(16, value));
  1464. ((this._width !== -1) && (this._height !== -1)) && (this._setAnisotropy(value));
  1465. }
  1466. }
  1467. get mipmapCount() {
  1468. return this._mipmapCount;
  1469. }
  1470. get defaulteTexture() {
  1471. throw "BaseTexture:must override it.";
  1472. }
  1473. _getFormatByteCount() {
  1474. switch (this._format) {
  1475. case exports.TextureFormat.R8G8B8:
  1476. return 3;
  1477. case exports.TextureFormat.R8G8B8A8:
  1478. return 4;
  1479. case exports.TextureFormat.R5G6B5:
  1480. return 1;
  1481. case exports.TextureFormat.Alpha8:
  1482. return 1;
  1483. case exports.TextureFormat.R32G32B32A32:
  1484. return 4;
  1485. default:
  1486. throw "Texture2D: unknown format.";
  1487. }
  1488. }
  1489. _isPot(size) {
  1490. return (size & (size - 1)) === 0;
  1491. }
  1492. _getGLFormat() {
  1493. var glFormat;
  1494. var gl = LayaGL.instance;
  1495. var gpu = LayaGL.layaGPUInstance;
  1496. switch (this._format) {
  1497. case exports.TextureFormat.R8G8B8:
  1498. case exports.TextureFormat.R5G6B5:
  1499. glFormat = gl.RGB;
  1500. break;
  1501. case exports.TextureFormat.R8G8B8A8:
  1502. glFormat = gl.RGBA;
  1503. break;
  1504. case exports.TextureFormat.Alpha8:
  1505. glFormat = gl.ALPHA;
  1506. break;
  1507. case exports.TextureFormat.R32G32B32A32:
  1508. glFormat = gl.RGBA;
  1509. break;
  1510. case exports.TextureFormat.DXT1:
  1511. if (gpu._compressedTextureS3tc)
  1512. glFormat = gpu._compressedTextureS3tc.COMPRESSED_RGB_S3TC_DXT1_EXT;
  1513. else
  1514. throw "BaseTexture: not support DXT1 format.";
  1515. break;
  1516. case exports.TextureFormat.DXT5:
  1517. if (gpu._compressedTextureS3tc)
  1518. glFormat = gpu._compressedTextureS3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  1519. else
  1520. throw "BaseTexture: not support DXT5 format.";
  1521. break;
  1522. case exports.TextureFormat.ETC1RGB:
  1523. if (gpu._compressedTextureEtc1)
  1524. glFormat = gpu._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL;
  1525. else
  1526. throw "BaseTexture: not support ETC1RGB format.";
  1527. break;
  1528. case exports.TextureFormat.PVRTCRGB_2BPPV:
  1529. if (gpu._compressedTexturePvrtc)
  1530. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  1531. else
  1532. throw "BaseTexture: not support PVRTCRGB_2BPPV format.";
  1533. break;
  1534. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  1535. if (gpu._compressedTexturePvrtc)
  1536. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  1537. else
  1538. throw "BaseTexture: not support PVRTCRGBA_2BPPV format.";
  1539. break;
  1540. case exports.TextureFormat.PVRTCRGB_4BPPV:
  1541. if (gpu._compressedTexturePvrtc)
  1542. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  1543. else
  1544. throw "BaseTexture: not support PVRTCRGB_4BPPV format.";
  1545. break;
  1546. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  1547. if (gpu._compressedTexturePvrtc)
  1548. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  1549. else
  1550. throw "BaseTexture: not support PVRTCRGBA_4BPPV format.";
  1551. break;
  1552. default:
  1553. throw "BaseTexture: unknown texture format.";
  1554. }
  1555. return glFormat;
  1556. }
  1557. _setFilterMode(value) {
  1558. var gl = LayaGL.instance;
  1559. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1560. switch (value) {
  1561. case exports.FilterMode.Point:
  1562. if (this._mipmap)
  1563. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
  1564. else
  1565. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  1566. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  1567. break;
  1568. case exports.FilterMode.Bilinear:
  1569. if (this._mipmap)
  1570. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
  1571. else
  1572. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1573. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1574. break;
  1575. case exports.FilterMode.Trilinear:
  1576. if (this._mipmap)
  1577. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
  1578. else
  1579. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1580. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1581. break;
  1582. default:
  1583. throw new Error("BaseTexture:unknown filterMode value.");
  1584. }
  1585. }
  1586. _setWarpMode(orientation, mode) {
  1587. var gl = LayaGL.instance;
  1588. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1589. if (this._isPot(this._width) && this._isPot(this._height)) {
  1590. switch (mode) {
  1591. case exports.WarpMode.Repeat:
  1592. gl.texParameteri(this._glTextureType, orientation, gl.REPEAT);
  1593. break;
  1594. case exports.WarpMode.Clamp:
  1595. gl.texParameteri(this._glTextureType, orientation, gl.CLAMP_TO_EDGE);
  1596. break;
  1597. }
  1598. }
  1599. else {
  1600. gl.texParameteri(this._glTextureType, orientation, gl.CLAMP_TO_EDGE);
  1601. }
  1602. }
  1603. _setAnisotropy(value) {
  1604. var anisotropic = LayaGL.layaGPUInstance._extTextureFilterAnisotropic;
  1605. if (anisotropic) {
  1606. value = Math.max(value, 1);
  1607. var gl = LayaGL.instance;
  1608. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1609. value = Math.min(gl.getParameter(anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT), value);
  1610. gl.texParameterf(this._glTextureType, anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, value);
  1611. }
  1612. }
  1613. _disposeResource() {
  1614. if (this._glTexture) {
  1615. LayaGL.instance.deleteTexture(this._glTexture);
  1616. this._glTexture = null;
  1617. this._setGPUMemory(0);
  1618. }
  1619. }
  1620. _getSource() {
  1621. if (this._readyed)
  1622. return this._glTexture;
  1623. else
  1624. return null;
  1625. }
  1626. generateMipmap() {
  1627. if (this._isPot(this.width) && this._isPot(this.height))
  1628. LayaGL.instance.generateMipmap(this._glTextureType);
  1629. }
  1630. }
  1631. BaseTexture._rgbmRange = 5.0;
  1632. BaseTexture.FORMAT_R8G8B8 = 0;
  1633. BaseTexture.FORMAT_R8G8B8A8 = 1;
  1634. BaseTexture.FORMAT_ALPHA8 = 2;
  1635. BaseTexture.FORMAT_DXT1 = 3;
  1636. BaseTexture.FORMAT_DXT5 = 4;
  1637. BaseTexture.FORMAT_ETC1RGB = 5;
  1638. BaseTexture.FORMAT_PVRTCRGB_2BPPV = 9;
  1639. BaseTexture.FORMAT_PVRTCRGBA_2BPPV = 10;
  1640. BaseTexture.FORMAT_PVRTCRGB_4BPPV = 11;
  1641. BaseTexture.FORMAT_PVRTCRGBA_4BPPV = 12;
  1642. BaseTexture.RENDERTEXTURE_FORMAT_RGBA_HALF_FLOAT = 14;
  1643. BaseTexture.FORMAT_R32G32B32A32 = 15;
  1644. BaseTexture.FORMAT_DEPTH_16 = 0;
  1645. BaseTexture.FORMAT_STENCIL_8 = 1;
  1646. BaseTexture.FORMAT_DEPTHSTENCIL_16_8 = 2;
  1647. BaseTexture.FORMAT_DEPTHSTENCIL_NONE = 3;
  1648. BaseTexture.FILTERMODE_POINT = 0;
  1649. BaseTexture.FILTERMODE_BILINEAR = 1;
  1650. BaseTexture.FILTERMODE_TRILINEAR = 2;
  1651. BaseTexture.WARPMODE_REPEAT = 0;
  1652. BaseTexture.WARPMODE_CLAMP = 1;
  1653. class Texture2D extends BaseTexture {
  1654. constructor(width = 0, height = 0, format = exports.TextureFormat.R8G8B8A8, mipmap = true, canRead = false) {
  1655. super(format, mipmap);
  1656. var gl = LayaGL.instance;
  1657. this._glTextureType = gl.TEXTURE_2D;
  1658. this._width = width;
  1659. this._height = height;
  1660. this._canRead = canRead;
  1661. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  1662. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  1663. this._setFilterMode(this._filterMode);
  1664. this._setAnisotropy(this._anisoLevel);
  1665. var compress = this._gpuCompressFormat();
  1666. if (mipmap) {
  1667. var mipCount = Math.max(Math.ceil(Math.log2(width)) + 1, Math.ceil(Math.log2(height)) + 1);
  1668. if (!compress) {
  1669. for (var i = 0; i < mipCount; i++)
  1670. this._setPixels(null, i, Math.max(width >> i, 1), Math.max(height >> i, 1));
  1671. }
  1672. this._mipmapCount = mipCount;
  1673. this._setGPUMemory(width * height * 4 * (1 + 1 / 3));
  1674. }
  1675. else {
  1676. if (!compress)
  1677. this._setPixels(null, 0, width, height);
  1678. this._mipmapCount = 1;
  1679. this._setGPUMemory(width * height * 4);
  1680. }
  1681. }
  1682. static __init__() {
  1683. var pixels = new Uint8Array(3);
  1684. pixels[0] = 128;
  1685. pixels[1] = 128;
  1686. pixels[2] = 128;
  1687. Texture2D.grayTexture = new Texture2D(1, 1, exports.TextureFormat.R8G8B8, false, false);
  1688. Texture2D.grayTexture.setPixels(pixels);
  1689. Texture2D.grayTexture.lock = true;
  1690. pixels[0] = 255;
  1691. pixels[1] = 255;
  1692. pixels[2] = 255;
  1693. Texture2D.whiteTexture = new Texture2D(1, 1, exports.TextureFormat.R8G8B8, false, false);
  1694. Texture2D.whiteTexture.setPixels(pixels);
  1695. Texture2D.whiteTexture.lock = true;
  1696. pixels[0] = 0;
  1697. pixels[1] = 0;
  1698. pixels[2] = 0;
  1699. Texture2D.blackTexture = new Texture2D(1, 1, exports.TextureFormat.R8G8B8, false, false);
  1700. Texture2D.blackTexture.setPixels(pixels);
  1701. Texture2D.blackTexture.lock = true;
  1702. }
  1703. static _parse(data, propertyParams = null, constructParams = null) {
  1704. var texture = constructParams ? new Texture2D(constructParams[0], constructParams[1], constructParams[2], constructParams[3], constructParams[4]) : new Texture2D(0, 0);
  1705. if (propertyParams) {
  1706. texture.wrapModeU = propertyParams.wrapModeU;
  1707. texture.wrapModeV = propertyParams.wrapModeV;
  1708. texture.filterMode = propertyParams.filterMode;
  1709. texture.anisoLevel = propertyParams.anisoLevel;
  1710. }
  1711. switch (texture._format) {
  1712. case exports.TextureFormat.R8G8B8:
  1713. case exports.TextureFormat.R8G8B8A8:
  1714. texture.loadImageSource(data);
  1715. break;
  1716. case exports.TextureFormat.DXT1:
  1717. case exports.TextureFormat.DXT5:
  1718. case exports.TextureFormat.ETC1RGB:
  1719. case exports.TextureFormat.PVRTCRGB_2BPPV:
  1720. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  1721. case exports.TextureFormat.PVRTCRGB_4BPPV:
  1722. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  1723. texture.setCompressData(data);
  1724. break;
  1725. default:
  1726. throw "Texture2D:unkonwn format.";
  1727. }
  1728. return texture;
  1729. }
  1730. static load(url, complete) {
  1731. ILaya.loader.create(url, complete, null, ILaya.Loader.TEXTURE2D);
  1732. }
  1733. get defaulteTexture() {
  1734. return Texture2D.grayTexture;
  1735. }
  1736. _gpuCompressFormat() {
  1737. return this._format == exports.TextureFormat.DXT1 || this._format == exports.TextureFormat.DXT5 ||
  1738. this._format == exports.TextureFormat.ETC1RGB ||
  1739. this._format == exports.TextureFormat.PVRTCRGB_2BPPV || this._format == exports.TextureFormat.PVRTCRGBA_2BPPV ||
  1740. this._format == exports.TextureFormat.PVRTCRGB_4BPPV || this._format == exports.TextureFormat.PVRTCRGBA_4BPPV;
  1741. }
  1742. _setPixels(pixels, miplevel, width, height) {
  1743. var gl = LayaGL.instance;
  1744. var textureType = this._glTextureType;
  1745. var glFormat = this._getGLFormat();
  1746. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1747. switch (this.format) {
  1748. case exports.TextureFormat.R8G8B8:
  1749. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  1750. gl.texImage2D(textureType, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels);
  1751. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  1752. break;
  1753. case exports.TextureFormat.R5G6B5:
  1754. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 2);
  1755. gl.texImage2D(textureType, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_SHORT_5_6_5, pixels);
  1756. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  1757. break;
  1758. case exports.TextureFormat.R32G32B32A32:
  1759. if (LayaGL.layaGPUInstance._isWebGL2)
  1760. gl.texImage2D(textureType, miplevel, gl.RGBA32F, width, height, 0, glFormat, gl.FLOAT, pixels);
  1761. else
  1762. gl.texImage2D(textureType, miplevel, gl.RGBA, width, height, 0, glFormat, gl.FLOAT, pixels);
  1763. break;
  1764. default:
  1765. gl.texImage2D(textureType, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels);
  1766. }
  1767. }
  1768. _calcualatesCompressedDataSize(format, width, height) {
  1769. switch (format) {
  1770. case exports.TextureFormat.DXT1:
  1771. case exports.TextureFormat.ETC1RGB:
  1772. return ((width + 3) >> 2) * ((height + 3) >> 2) * 8;
  1773. case exports.TextureFormat.DXT5:
  1774. return ((width + 3) >> 2) * ((height + 3) >> 2) * 16;
  1775. case exports.TextureFormat.PVRTCRGB_4BPPV:
  1776. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  1777. return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);
  1778. case exports.TextureFormat.PVRTCRGB_2BPPV:
  1779. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  1780. return Math.floor((Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8);
  1781. default:
  1782. return 0;
  1783. }
  1784. }
  1785. _pharseDDS(arrayBuffer) {
  1786. const FOURCC_DXT1 = 827611204;
  1787. const FOURCC_DXT5 = 894720068;
  1788. const DDPF_FOURCC = 0x4;
  1789. const DDSD_MIPMAPCOUNT = 0x20000;
  1790. const DDS_MAGIC = 0x20534444;
  1791. const DDS_HEADER_LENGTH = 31;
  1792. const DDS_HEADER_MAGIC = 0;
  1793. const DDS_HEADER_SIZE = 1;
  1794. const DDS_HEADER_FLAGS = 2;
  1795. const DDS_HEADER_HEIGHT = 3;
  1796. const DDS_HEADER_WIDTH = 4;
  1797. const DDS_HEADER_MIPMAPCOUNT = 7;
  1798. const DDS_HEADER_PF_FLAGS = 20;
  1799. const DDS_HEADER_PF_FOURCC = 21;
  1800. var header = new Int32Array(arrayBuffer, 0, DDS_HEADER_LENGTH);
  1801. if (header[DDS_HEADER_MAGIC] != DDS_MAGIC)
  1802. throw "Invalid magic number in DDS header";
  1803. if (!(header[DDS_HEADER_PF_FLAGS] & DDPF_FOURCC))
  1804. throw "Unsupported format, must contain a FourCC code";
  1805. var compressedFormat = header[DDS_HEADER_PF_FOURCC];
  1806. switch (this._format) {
  1807. case exports.TextureFormat.DXT1:
  1808. if (compressedFormat !== FOURCC_DXT1)
  1809. throw "the FourCC code is not same with texture format.";
  1810. break;
  1811. case exports.TextureFormat.DXT5:
  1812. if (compressedFormat !== FOURCC_DXT5)
  1813. throw "the FourCC code is not same with texture format.";
  1814. break;
  1815. default:
  1816. throw "unknown texture format.";
  1817. }
  1818. var mipLevels = 1;
  1819. if (header[DDS_HEADER_FLAGS] & DDSD_MIPMAPCOUNT) {
  1820. mipLevels = Math.max(1, header[DDS_HEADER_MIPMAPCOUNT]);
  1821. if (!this._mipmap)
  1822. throw "the mipmap is not same with Texture2D.";
  1823. }
  1824. else {
  1825. if (this._mipmap)
  1826. throw "the mipmap is not same with Texture2D.";
  1827. }
  1828. var width = header[DDS_HEADER_WIDTH];
  1829. var height = header[DDS_HEADER_HEIGHT];
  1830. this._width = width;
  1831. this._height = height;
  1832. var dataOffset = header[DDS_HEADER_SIZE] + 4;
  1833. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 0);
  1834. }
  1835. _pharseKTX(arrayBuffer) {
  1836. const ETC_HEADER_LENGTH = 13;
  1837. const ETC_HEADER_FORMAT = 4;
  1838. const ETC_HEADER_HEIGHT = 7;
  1839. const ETC_HEADER_WIDTH = 6;
  1840. const ETC_HEADER_MIPMAPCOUNT = 11;
  1841. const ETC_HEADER_METADATA = 12;
  1842. var id = new Uint8Array(arrayBuffer, 0, 12);
  1843. if (id[0] != 0xAB || id[1] != 0x4B || id[2] != 0x54 || id[3] != 0x58 || id[4] != 0x20 || id[5] != 0x31 || id[6] != 0x31 || id[7] != 0xBB || id[8] != 0x0D || id[9] != 0x0A || id[10] != 0x1A || id[11] != 0x0A)
  1844. throw ("Invalid fileIdentifier in KTX header");
  1845. var header = new Int32Array(id.buffer, id.length, ETC_HEADER_LENGTH);
  1846. var compressedFormat = header[ETC_HEADER_FORMAT];
  1847. switch (compressedFormat) {
  1848. case LayaGL.layaGPUInstance._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL:
  1849. this._format = exports.TextureFormat.ETC1RGB;
  1850. break;
  1851. default:
  1852. throw "unknown texture format.";
  1853. }
  1854. var mipLevels = header[ETC_HEADER_MIPMAPCOUNT];
  1855. var width = header[ETC_HEADER_WIDTH];
  1856. var height = header[ETC_HEADER_HEIGHT];
  1857. this._width = width;
  1858. this._height = height;
  1859. var dataOffset = 64 + header[ETC_HEADER_METADATA];
  1860. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 4);
  1861. }
  1862. _pharsePVR(arrayBuffer) {
  1863. const PVR_FORMAT_2BPP_RGB = 0;
  1864. const PVR_FORMAT_2BPP_RGBA = 1;
  1865. const PVR_FORMAT_4BPP_RGB = 2;
  1866. const PVR_FORMAT_4BPP_RGBA = 3;
  1867. const PVR_MAGIC = 0x03525650;
  1868. const PVR_HEADER_LENGTH = 13;
  1869. const PVR_HEADER_MAGIC = 0;
  1870. const PVR_HEADER_FORMAT = 2;
  1871. const PVR_HEADER_HEIGHT = 6;
  1872. const PVR_HEADER_WIDTH = 7;
  1873. const PVR_HEADER_MIPMAPCOUNT = 11;
  1874. const PVR_HEADER_METADATA = 12;
  1875. var header = new Int32Array(arrayBuffer, 0, PVR_HEADER_LENGTH);
  1876. if (header[PVR_HEADER_MAGIC] != PVR_MAGIC)
  1877. throw ("Invalid magic number in PVR header");
  1878. var compressedFormat = header[PVR_HEADER_FORMAT];
  1879. switch (compressedFormat) {
  1880. case PVR_FORMAT_2BPP_RGB:
  1881. this._format = exports.TextureFormat.PVRTCRGB_2BPPV;
  1882. break;
  1883. case PVR_FORMAT_4BPP_RGB:
  1884. this._format = exports.TextureFormat.PVRTCRGB_4BPPV;
  1885. break;
  1886. case PVR_FORMAT_2BPP_RGBA:
  1887. this._format = exports.TextureFormat.PVRTCRGBA_2BPPV;
  1888. break;
  1889. case PVR_FORMAT_4BPP_RGBA:
  1890. this._format = exports.TextureFormat.PVRTCRGBA_4BPPV;
  1891. break;
  1892. default:
  1893. throw "Texture2D:unknown PVR format.";
  1894. }
  1895. var mipLevels = header[PVR_HEADER_MIPMAPCOUNT];
  1896. var width = header[PVR_HEADER_WIDTH];
  1897. var height = header[PVR_HEADER_HEIGHT];
  1898. this._width = width;
  1899. this._height = height;
  1900. var dataOffset = header[PVR_HEADER_METADATA] + 52;
  1901. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 0);
  1902. }
  1903. _upLoadCompressedTexImage2D(data, width, height, miplevelCount, dataOffset, imageSizeOffset) {
  1904. var gl = LayaGL.instance;
  1905. var textureType = this._glTextureType;
  1906. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1907. var glFormat = this._getGLFormat();
  1908. var offset = dataOffset;
  1909. for (var i = 0; i < miplevelCount; i++) {
  1910. offset += imageSizeOffset;
  1911. var mipDataSize = this._calcualatesCompressedDataSize(this._format, width, height);
  1912. var mipData = new Uint8Array(data, offset, mipDataSize);
  1913. gl.compressedTexImage2D(textureType, i, glFormat, width, height, 0, mipData);
  1914. width = Math.max(width >> 1, 1.0);
  1915. height = Math.max(height >> 1, 1.0);
  1916. offset += mipDataSize;
  1917. }
  1918. var memory = offset;
  1919. this._setGPUMemory(memory);
  1920. this._readyed = true;
  1921. this._activeResource();
  1922. }
  1923. loadImageSource(source, premultiplyAlpha = false) {
  1924. var gl = LayaGL.instance;
  1925. var width = source.width;
  1926. var height = source.height;
  1927. this._width = width;
  1928. this._height = height;
  1929. if (!(this._isPot(width) && this._isPot(height)))
  1930. this._mipmap = false;
  1931. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  1932. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  1933. this._setFilterMode(this._filterMode);
  1934. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1935. var glFormat = this._getGLFormat();
  1936. if (ILaya.Render.isConchApp) {
  1937. if (source.setPremultiplyAlpha) {
  1938. source.setPremultiplyAlpha(premultiplyAlpha);
  1939. }
  1940. gl.texImage2D(this._glTextureType, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
  1941. }
  1942. else {
  1943. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true));
  1944. if (this.format == exports.TextureFormat.R5G6B5)
  1945. gl.texImage2D(this._glTextureType, 0, gl.RGB, gl.RGB, gl.UNSIGNED_SHORT_5_6_5, source);
  1946. else
  1947. gl.texImage2D(this._glTextureType, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source);
  1948. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false));
  1949. }
  1950. if (this._mipmap) {
  1951. gl.generateMipmap(this._glTextureType);
  1952. this._setGPUMemory(width * height * 4 * (1 + 1 / 3));
  1953. }
  1954. else {
  1955. this._setGPUMemory(width * height * 4);
  1956. }
  1957. if (this._canRead) {
  1958. if (ILaya.Render.isConchApp) {
  1959. this._pixels = new Uint8Array(source._nativeObj.getImageData(0, 0, width, height));
  1960. }
  1961. else {
  1962. ILaya.Browser.canvas.size(width, height);
  1963. ILaya.Browser.canvas.clear();
  1964. ILaya.Browser.context.drawImage(source, 0, 0, width, height);
  1965. this._pixels = new Uint8Array(ILaya.Browser.context.getImageData(0, 0, width, height).data.buffer);
  1966. }
  1967. }
  1968. this._readyed = true;
  1969. this._activeResource();
  1970. }
  1971. setPixels(pixels, miplevel = 0) {
  1972. if (this._gpuCompressFormat())
  1973. throw "Texture2D:the format is GPU compression format.";
  1974. if (!pixels)
  1975. throw "Texture2D:pixels can't be null.";
  1976. var width = Math.max(this._width >> miplevel, 1);
  1977. var height = Math.max(this._height >> miplevel, 1);
  1978. var pixelsCount = width * height * this._getFormatByteCount();
  1979. if (pixels.length < pixelsCount)
  1980. throw "Texture2D:pixels length should at least " + pixelsCount + ".";
  1981. this._setPixels(pixels, miplevel, width, height);
  1982. if (this._canRead)
  1983. this._pixels = pixels;
  1984. this._readyed = true;
  1985. this._activeResource();
  1986. }
  1987. setSubPixels(x, y, width, height, pixels, miplevel = 0) {
  1988. if (this._gpuCompressFormat())
  1989. throw "Texture2D:the format is GPU compression format.";
  1990. if (!pixels)
  1991. throw "Texture2D:pixels can't be null.";
  1992. var gl = LayaGL.instance;
  1993. var textureType = this._glTextureType;
  1994. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1995. var glFormat = this._getGLFormat();
  1996. switch (this.format) {
  1997. case exports.TextureFormat.R8G8B8:
  1998. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  1999. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  2000. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  2001. break;
  2002. case exports.TextureFormat.R5G6B5:
  2003. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 2);
  2004. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.UNSIGNED_SHORT_5_6_5, pixels);
  2005. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  2006. break;
  2007. case exports.TextureFormat.R32G32B32A32:
  2008. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.FLOAT, pixels);
  2009. break;
  2010. default:
  2011. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  2012. }
  2013. this._readyed = true;
  2014. this._activeResource();
  2015. }
  2016. setCompressData(data) {
  2017. switch (this._format) {
  2018. case exports.TextureFormat.DXT1:
  2019. case exports.TextureFormat.DXT5:
  2020. this._pharseDDS(data);
  2021. break;
  2022. case exports.TextureFormat.ETC1RGB:
  2023. this._pharseKTX(data);
  2024. break;
  2025. case exports.TextureFormat.PVRTCRGB_2BPPV:
  2026. case exports.TextureFormat.PVRTCRGBA_2BPPV:
  2027. case exports.TextureFormat.PVRTCRGB_4BPPV:
  2028. case exports.TextureFormat.PVRTCRGBA_4BPPV:
  2029. this._pharsePVR(data);
  2030. break;
  2031. default:
  2032. throw "Texture2D:unkonwn format.";
  2033. }
  2034. }
  2035. getPixels() {
  2036. if (this._canRead)
  2037. return this._pixels;
  2038. else
  2039. throw new Error("Texture2D: must set texture canRead is true.");
  2040. }
  2041. }
  2042. Texture2D.TEXTURE2D = "TEXTURE2D";
  2043. Texture2D.grayTexture = null;
  2044. Texture2D.whiteTexture = null;
  2045. Texture2D.blackTexture = null;
  2046. class BaseShader extends Resource {
  2047. constructor() {
  2048. super();
  2049. }
  2050. }
  2051. class RenderState2D {
  2052. static mat2MatArray(mat, matArray) {
  2053. var m = mat;
  2054. var m4 = matArray;
  2055. m4[0] = m.a;
  2056. m4[1] = m.b;
  2057. m4[2] = RenderState2D.EMPTYMAT4_ARRAY[2];
  2058. m4[3] = RenderState2D.EMPTYMAT4_ARRAY[3];
  2059. m4[4] = m.c;
  2060. m4[5] = m.d;
  2061. m4[6] = RenderState2D.EMPTYMAT4_ARRAY[6];
  2062. m4[7] = RenderState2D.EMPTYMAT4_ARRAY[7];
  2063. m4[8] = RenderState2D.EMPTYMAT4_ARRAY[8];
  2064. m4[9] = RenderState2D.EMPTYMAT4_ARRAY[9];
  2065. m4[10] = RenderState2D.EMPTYMAT4_ARRAY[10];
  2066. m4[11] = RenderState2D.EMPTYMAT4_ARRAY[11];
  2067. m4[12] = m.tx;
  2068. m4[13] = m.ty;
  2069. m4[14] = RenderState2D.EMPTYMAT4_ARRAY[14];
  2070. m4[15] = RenderState2D.EMPTYMAT4_ARRAY[15];
  2071. return matArray;
  2072. }
  2073. static restoreTempArray() {
  2074. RenderState2D.TEMPMAT4_ARRAY[0] = 1;
  2075. RenderState2D.TEMPMAT4_ARRAY[1] = 0;
  2076. RenderState2D.TEMPMAT4_ARRAY[4] = 0;
  2077. RenderState2D.TEMPMAT4_ARRAY[5] = 1;
  2078. RenderState2D.TEMPMAT4_ARRAY[12] = 0;
  2079. RenderState2D.TEMPMAT4_ARRAY[13] = 0;
  2080. }
  2081. static clear() {
  2082. RenderState2D.worldScissorTest = false;
  2083. RenderState2D.worldAlpha = 1;
  2084. }
  2085. }
  2086. RenderState2D._MAXSIZE = 99999999;
  2087. RenderState2D.EMPTYMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  2088. RenderState2D.TEMPMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  2089. RenderState2D.worldMatrix4 = RenderState2D.TEMPMAT4_ARRAY;
  2090. RenderState2D.worldMatrix = new Matrix();
  2091. RenderState2D.matWVP = null;
  2092. RenderState2D.worldAlpha = 1.0;
  2093. RenderState2D.worldScissorTest = false;
  2094. RenderState2D.width = 0;
  2095. RenderState2D.height = 0;
  2096. (function (RenderTextureFormat) {
  2097. RenderTextureFormat[RenderTextureFormat["R8G8B8"] = 0] = "R8G8B8";
  2098. RenderTextureFormat[RenderTextureFormat["R8G8B8A8"] = 1] = "R8G8B8A8";
  2099. RenderTextureFormat[RenderTextureFormat["Alpha8"] = 2] = "Alpha8";
  2100. RenderTextureFormat[RenderTextureFormat["R16G16B16A16"] = 14] = "R16G16B16A16";
  2101. RenderTextureFormat[RenderTextureFormat["Depth"] = 15] = "Depth";
  2102. RenderTextureFormat[RenderTextureFormat["ShadowMap"] = 16] = "ShadowMap";
  2103. })(exports.RenderTextureFormat || (exports.RenderTextureFormat = {}));
  2104. (function (RenderTextureDepthFormat) {
  2105. RenderTextureDepthFormat[RenderTextureDepthFormat["DEPTH_16"] = 0] = "DEPTH_16";
  2106. RenderTextureDepthFormat[RenderTextureDepthFormat["STENCIL_8"] = 1] = "STENCIL_8";
  2107. RenderTextureDepthFormat[RenderTextureDepthFormat["DEPTHSTENCIL_24_8"] = 2] = "DEPTHSTENCIL_24_8";
  2108. RenderTextureDepthFormat[RenderTextureDepthFormat["DEPTHSTENCIL_NONE"] = 3] = "DEPTHSTENCIL_NONE";
  2109. RenderTextureDepthFormat[RenderTextureDepthFormat["DEPTHSTENCIL_16_8"] = 2] = "DEPTHSTENCIL_16_8";
  2110. })(exports.RenderTextureDepthFormat || (exports.RenderTextureDepthFormat = {}));
  2111. class RenderTexture2D extends BaseTexture {
  2112. constructor(width, height, format = exports.RenderTextureFormat.R8G8B8, depthStencilFormat = exports.RenderTextureDepthFormat.DEPTH_16) {
  2113. super(format, false);
  2114. this._mgrKey = 0;
  2115. this._glTextureType = LayaGL.instance.TEXTURE_2D;
  2116. this._width = width;
  2117. this._height = height;
  2118. this._depthStencilFormat = depthStencilFormat;
  2119. this._create(width, height);
  2120. this.lock = true;
  2121. }
  2122. static get currentActive() {
  2123. return RenderTexture2D._currentActive;
  2124. }
  2125. get depthStencilFormat() {
  2126. return this._depthStencilFormat;
  2127. }
  2128. get defaulteTexture() {
  2129. return Texture2D.grayTexture;
  2130. }
  2131. getIsReady() {
  2132. return true;
  2133. }
  2134. get sourceWidth() {
  2135. return this._width;
  2136. }
  2137. get sourceHeight() {
  2138. return this._height;
  2139. }
  2140. get offsetX() {
  2141. return 0;
  2142. }
  2143. get offsetY() {
  2144. return 0;
  2145. }
  2146. _create(width, height) {
  2147. var gl = LayaGL.instance;
  2148. this._frameBuffer = gl.createFramebuffer();
  2149. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  2150. var glFormat = this._getGLFormat();
  2151. gl.texImage2D(this._glTextureType, 0, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, null);
  2152. this._setGPUMemory(width * height * 4);
  2153. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2154. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, 0);
  2155. if (this._depthStencilFormat !== exports.RenderTextureDepthFormat.DEPTHSTENCIL_NONE) {
  2156. this._depthStencilBuffer = gl.createRenderbuffer();
  2157. gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthStencilBuffer);
  2158. switch (this._depthStencilFormat) {
  2159. case exports.RenderTextureDepthFormat.DEPTH_16:
  2160. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
  2161. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2162. break;
  2163. case exports.RenderTextureDepthFormat.STENCIL_8:
  2164. gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height);
  2165. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2166. break;
  2167. case exports.RenderTextureDepthFormat.DEPTHSTENCIL_24_8:
  2168. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
  2169. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2170. break;
  2171. default:
  2172. }
  2173. }
  2174. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2175. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  2176. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  2177. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  2178. this._setFilterMode(this._filterMode);
  2179. this._setAnisotropy(this._anisoLevel);
  2180. this._readyed = true;
  2181. this._activeResource();
  2182. }
  2183. generateMipmap() {
  2184. if (this._isPot(this.width) && this._isPot(this.height)) {
  2185. this._mipmap = true;
  2186. LayaGL.instance.generateMipmap(this._glTextureType);
  2187. this._setFilterMode(this._filterMode);
  2188. this._setGPUMemory(this.width * this.height * 4 * (1 + 1 / 3));
  2189. }
  2190. else {
  2191. this._mipmap = false;
  2192. this._setGPUMemory(this.width * this.height * 4);
  2193. }
  2194. }
  2195. static pushRT() {
  2196. RenderTexture2D.rtStack.push({ rt: RenderTexture2D._currentActive, w: RenderState2D.width, h: RenderState2D.height });
  2197. }
  2198. static popRT() {
  2199. var gl = LayaGL.instance;
  2200. var top = RenderTexture2D.rtStack.pop();
  2201. if (top) {
  2202. if (RenderTexture2D._currentActive != top.rt) {
  2203. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, top.rt ? top.rt._frameBuffer : null);
  2204. RenderTexture2D._currentActive = top.rt;
  2205. }
  2206. gl.viewport(0, 0, top.w, top.h);
  2207. RenderState2D.width = top.w;
  2208. RenderState2D.height = top.h;
  2209. }
  2210. }
  2211. start() {
  2212. var gl = LayaGL.instance;
  2213. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2214. this._lastRT = RenderTexture2D._currentActive;
  2215. RenderTexture2D._currentActive = this;
  2216. this._readyed = true;
  2217. gl.viewport(0, 0, this._width, this._height);
  2218. this._lastWidth = RenderState2D.width;
  2219. this._lastHeight = RenderState2D.height;
  2220. RenderState2D.width = this._width;
  2221. RenderState2D.height = this._height;
  2222. BaseShader.activeShader = null;
  2223. }
  2224. end() {
  2225. var gl = LayaGL.instance;
  2226. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2227. RenderTexture2D._currentActive = null;
  2228. this._readyed = true;
  2229. }
  2230. restore() {
  2231. var gl = LayaGL.instance;
  2232. if (this._lastRT != RenderTexture2D._currentActive) {
  2233. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, this._lastRT ? this._lastRT._frameBuffer : null);
  2234. RenderTexture2D._currentActive = this._lastRT;
  2235. }
  2236. this._readyed = true;
  2237. gl.viewport(0, 0, this._lastWidth, this._lastHeight);
  2238. RenderState2D.width = this._lastWidth;
  2239. RenderState2D.height = this._lastHeight;
  2240. BaseShader.activeShader = null;
  2241. }
  2242. clear(r = 0.0, g = 0.0, b = 0.0, a = 1.0) {
  2243. var gl = LayaGL.instance;
  2244. gl.clearColor(r, g, b, a);
  2245. var clearFlag = gl.COLOR_BUFFER_BIT;
  2246. switch (this._depthStencilFormat) {
  2247. case gl.DEPTH_COMPONENT16:
  2248. clearFlag |= gl.DEPTH_BUFFER_BIT;
  2249. break;
  2250. case gl.STENCIL_INDEX8:
  2251. clearFlag |= gl.STENCIL_BUFFER_BIT;
  2252. break;
  2253. case gl.DEPTH_STENCIL:
  2254. clearFlag |= gl.DEPTH_BUFFER_BIT;
  2255. clearFlag |= gl.STENCIL_BUFFER_BIT;
  2256. break;
  2257. }
  2258. gl.clear(clearFlag);
  2259. }
  2260. getData(x, y, width, height) {
  2261. if (ILaya.Render.isConchApp && window.conchConfig.threadMode == 2) {
  2262. throw "native 2 thread mode use getDataAsync";
  2263. }
  2264. var gl = LayaGL.instance;
  2265. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2266. var canRead = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);
  2267. if (!canRead) {
  2268. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2269. return null;
  2270. }
  2271. var pixels = new Uint8Array(this._width * this._height * 4);
  2272. var glFormat = this._getGLFormat();
  2273. gl.readPixels(x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  2274. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2275. return pixels;
  2276. }
  2277. getDataAsync(x, y, width, height, callBack) {
  2278. var gl = LayaGL.instance;
  2279. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2280. gl.readPixelsAsync(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, function (data) {
  2281. callBack(new Uint8Array(data));
  2282. });
  2283. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2284. }
  2285. recycle() {
  2286. }
  2287. _disposeResource() {
  2288. if (this._frameBuffer) {
  2289. var gl = LayaGL.instance;
  2290. gl.deleteTexture(this._glTexture);
  2291. gl.deleteFramebuffer(this._frameBuffer);
  2292. gl.deleteRenderbuffer(this._depthStencilBuffer);
  2293. this._glTexture = null;
  2294. this._frameBuffer = null;
  2295. this._depthStencilBuffer = null;
  2296. this._setGPUMemory(0);
  2297. }
  2298. }
  2299. }
  2300. RenderTexture2D.rtStack = [];
  2301. RenderTexture2D.defuv = [0, 0, 1, 0, 1, 1, 0, 1];
  2302. RenderTexture2D.flipyuv = [0, 1, 1, 1, 1, 0, 0, 0];
  2303. class WebGLRTMgr {
  2304. static getRT(w, h) {
  2305. w = w | 0;
  2306. h = h | 0;
  2307. if (w >= 10000) {
  2308. console.error('getRT error! w too big');
  2309. }
  2310. var ret;
  2311. ret = new RenderTexture2D(w, h, exports.RenderTextureFormat.R8G8B8A8, -1);
  2312. return ret;
  2313. }
  2314. static releaseRT(rt) {
  2315. rt.destroy();
  2316. return;
  2317. }
  2318. }
  2319. WebGLRTMgr.dict = {};
  2320. class BlendMode {
  2321. static _init_(gl) {
  2322. BlendMode.fns = [BlendMode.BlendNormal, BlendMode.BlendAdd, BlendMode.BlendMultiply, BlendMode.BlendScreen, BlendMode.BlendOverlay, BlendMode.BlendLight, BlendMode.BlendMask, BlendMode.BlendDestinationOut];
  2323. BlendMode.targetFns = [BlendMode.BlendNormalTarget, BlendMode.BlendAddTarget, BlendMode.BlendMultiplyTarget, BlendMode.BlendScreenTarget, BlendMode.BlendOverlayTarget, BlendMode.BlendLightTarget, BlendMode.BlendMask, BlendMode.BlendDestinationOut];
  2324. }
  2325. static BlendNormal(gl) {
  2326. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA, true);
  2327. }
  2328. static BlendAdd(gl) {
  2329. WebGLContext.setBlendFunc(gl, gl.ONE, gl.DST_ALPHA, true);
  2330. }
  2331. static BlendMultiply(gl) {
  2332. WebGLContext.setBlendFunc(gl, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, true);
  2333. }
  2334. static BlendScreen(gl) {
  2335. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE, true);
  2336. }
  2337. static BlendOverlay(gl) {
  2338. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_COLOR, true);
  2339. }
  2340. static BlendLight(gl) {
  2341. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE, true);
  2342. }
  2343. static BlendNormalTarget(gl) {
  2344. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA, true);
  2345. }
  2346. static BlendAddTarget(gl) {
  2347. WebGLContext.setBlendFunc(gl, gl.ONE, gl.DST_ALPHA, true);
  2348. }
  2349. static BlendMultiplyTarget(gl) {
  2350. WebGLContext.setBlendFunc(gl, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, true);
  2351. }
  2352. static BlendScreenTarget(gl) {
  2353. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE, true);
  2354. }
  2355. static BlendOverlayTarget(gl) {
  2356. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_COLOR, true);
  2357. }
  2358. static BlendLightTarget(gl) {
  2359. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE, true);
  2360. }
  2361. static BlendMask(gl) {
  2362. WebGLContext.setBlendFunc(gl, gl.ZERO, gl.SRC_ALPHA, true);
  2363. }
  2364. static BlendDestinationOut(gl) {
  2365. WebGLContext.setBlendFunc(gl, gl.ZERO, gl.ZERO, true);
  2366. }
  2367. }
  2368. BlendMode.activeBlendFunction = null;
  2369. BlendMode.NAMES = ["normal", "add", "multiply", "screen", "overlay", "light", "mask", "destination-out"];
  2370. BlendMode.TOINT = { "normal": 0, "add": 1, "multiply": 2, "screen": 3, "overlay": 4, "light": 5, "mask": 6, "destination-out": 7, "lighter": 1 };
  2371. BlendMode.NORMAL = "normal";
  2372. BlendMode.ADD = "add";
  2373. BlendMode.MULTIPLY = "multiply";
  2374. BlendMode.SCREEN = "screen";
  2375. BlendMode.OVERLAY = "overlay";
  2376. BlendMode.LIGHT = "light";
  2377. BlendMode.MASK = "mask";
  2378. BlendMode.DESTINATIONOUT = "destination-out";
  2379. BlendMode.LIGHTER = "lighter";
  2380. BlendMode.fns = [];
  2381. BlendMode.targetFns = [];
  2382. class ShaderDefinesBase {
  2383. constructor(name2int, int2name, int2nameMap) {
  2384. this._value = 0;
  2385. this._name2int = name2int;
  2386. this._int2name = int2name;
  2387. this._int2nameMap = int2nameMap;
  2388. }
  2389. add(value) {
  2390. if (typeof (value) == 'string') {
  2391. this._value |= this._name2int[value];
  2392. }
  2393. else {
  2394. this._value |= value;
  2395. }
  2396. return this._value;
  2397. }
  2398. addInt(value) {
  2399. this._value |= value;
  2400. return this._value;
  2401. }
  2402. remove(value) {
  2403. if (typeof (value) == 'string') {
  2404. this._value &= ~(this._name2int[value]);
  2405. }
  2406. else {
  2407. this._value &= (~value);
  2408. }
  2409. return this._value;
  2410. }
  2411. isDefine(def) {
  2412. return (this._value & def) === def;
  2413. }
  2414. getValue() {
  2415. return this._value;
  2416. }
  2417. setValue(value) {
  2418. this._value = value;
  2419. }
  2420. toNameDic() {
  2421. var r = this._int2nameMap[this._value];
  2422. return r ? r : ShaderDefinesBase._toText(this._value, this._int2name, this._int2nameMap);
  2423. }
  2424. static _reg(name, value, _name2int, _int2name) {
  2425. _name2int[name] = value;
  2426. _int2name[value] = name;
  2427. }
  2428. static _toText(value, _int2name, _int2nameMap) {
  2429. var r = _int2nameMap[value];
  2430. if (r)
  2431. return r;
  2432. var o = {};
  2433. var d = 1;
  2434. for (var i = 0; i < 32; i++) {
  2435. d = 1 << i;
  2436. if (d > value)
  2437. break;
  2438. if (value & d) {
  2439. var name = _int2name[d];
  2440. name && (o[name] = "");
  2441. }
  2442. }
  2443. _int2nameMap[value] = o;
  2444. return o;
  2445. }
  2446. static _toInt(names, _name2int) {
  2447. var words = names.split('.');
  2448. var num = 0;
  2449. for (var i = 0, n = words.length; i < n; i++) {
  2450. var value = _name2int[words[i]];
  2451. if (!value)
  2452. throw new Error("Defines to int err:" + names + "/" + words[i]);
  2453. num |= value;
  2454. }
  2455. return num;
  2456. }
  2457. }
  2458. class ShaderDefines2D extends ShaderDefinesBase {
  2459. constructor() {
  2460. super(ShaderDefines2D.__name2int, ShaderDefines2D.__int2name, ShaderDefines2D.__int2nameMap);
  2461. }
  2462. static __init__() {
  2463. ShaderDefines2D.reg("TEXTURE2D", ShaderDefines2D.TEXTURE2D);
  2464. ShaderDefines2D.reg("PRIMITIVE", ShaderDefines2D.PRIMITIVE);
  2465. ShaderDefines2D.reg("GLOW_FILTER", ShaderDefines2D.FILTERGLOW);
  2466. ShaderDefines2D.reg("BLUR_FILTER", ShaderDefines2D.FILTERBLUR);
  2467. ShaderDefines2D.reg("COLOR_FILTER", ShaderDefines2D.FILTERCOLOR);
  2468. ShaderDefines2D.reg("COLOR_ADD", ShaderDefines2D.COLORADD);
  2469. ShaderDefines2D.reg("WORLDMAT", ShaderDefines2D.WORLDMAT);
  2470. ShaderDefines2D.reg("FILLTEXTURE", ShaderDefines2D.FILLTEXTURE);
  2471. ShaderDefines2D.reg('MVP3D', ShaderDefines2D.MVP3D);
  2472. }
  2473. static reg(name, value) {
  2474. this._reg(name, value, ShaderDefines2D.__name2int, ShaderDefines2D.__int2name);
  2475. }
  2476. static toText(value, int2name, int2nameMap) {
  2477. return this._toText(value, int2name, int2nameMap);
  2478. }
  2479. static toInt(names) {
  2480. return this._toInt(names, ShaderDefines2D.__name2int);
  2481. }
  2482. }
  2483. ShaderDefines2D.TEXTURE2D = 0x01;
  2484. ShaderDefines2D.PRIMITIVE = 0x04;
  2485. ShaderDefines2D.FILTERGLOW = 0x08;
  2486. ShaderDefines2D.FILTERBLUR = 0x10;
  2487. ShaderDefines2D.FILTERCOLOR = 0x20;
  2488. ShaderDefines2D.COLORADD = 0x40;
  2489. ShaderDefines2D.WORLDMAT = 0x80;
  2490. ShaderDefines2D.FILLTEXTURE = 0x100;
  2491. ShaderDefines2D.SKINMESH = 0x200;
  2492. ShaderDefines2D.MVP3D = 0x800;
  2493. ShaderDefines2D.NOOPTMASK = ShaderDefines2D.FILTERGLOW | ShaderDefines2D.FILTERBLUR | ShaderDefines2D.FILTERCOLOR | ShaderDefines2D.FILLTEXTURE;
  2494. ShaderDefines2D.__name2int = {};
  2495. ShaderDefines2D.__int2name = [];
  2496. ShaderDefines2D.__int2nameMap = [];
  2497. class Stat {
  2498. static show(x = 0, y = 0) {
  2499. Stat._StatRender.show(x, y);
  2500. }
  2501. static enable() {
  2502. Stat._StatRender.enable();
  2503. }
  2504. static hide() {
  2505. Stat._StatRender.hide();
  2506. }
  2507. static clear() {
  2508. Stat.trianglesFaces = Stat.renderBatches = Stat.savedRenderBatches = Stat.shaderCall = Stat.spriteRenderUseCacheCount = Stat.frustumCulling = Stat.octreeNodeCulling = Stat.canvasNormal = Stat.canvasBitmap = Stat.canvasReCache = 0;
  2509. }
  2510. static set onclick(fn) {
  2511. Stat._StatRender.set_onclick(fn);
  2512. }
  2513. }
  2514. Stat.FPS = 0;
  2515. Stat.loopCount = 0;
  2516. Stat.shaderCall = 0;
  2517. Stat.renderBatches = 0;
  2518. Stat.savedRenderBatches = 0;
  2519. Stat.trianglesFaces = 0;
  2520. Stat.spriteCount = 0;
  2521. Stat.spriteRenderUseCacheCount = 0;
  2522. Stat.frustumCulling = 0;
  2523. Stat.octreeNodeCulling = 0;
  2524. Stat.canvasNormal = 0;
  2525. Stat.canvasBitmap = 0;
  2526. Stat.canvasReCache = 0;
  2527. Stat.renderSlow = false;
  2528. Stat._fpsData = [];
  2529. Stat._timer = 0;
  2530. Stat._count = 0;
  2531. Stat._StatRender = null;
  2532. class StringKey {
  2533. constructor() {
  2534. this._strsToID = {};
  2535. this._idToStrs = [];
  2536. this._length = 0;
  2537. }
  2538. add(str) {
  2539. var index = this._strsToID[str];
  2540. if (index != null)
  2541. return index;
  2542. this._idToStrs[this._length] = str;
  2543. return this._strsToID[str] = this._length++;
  2544. }
  2545. getID(str) {
  2546. var index = this._strsToID[str];
  2547. return index == null ? -1 : index;
  2548. }
  2549. getName(id) {
  2550. var str = this._idToStrs[id];
  2551. return str == null ? undefined : str;
  2552. }
  2553. }
  2554. class Shader extends BaseShader {
  2555. constructor(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2556. super();
  2557. this._attribInfo = null;
  2558. this.customCompile = false;
  2559. this._curActTexIndex = 0;
  2560. this.tag = {};
  2561. this._program = null;
  2562. this._params = null;
  2563. this._paramsMap = {};
  2564. if ((!vs) || (!ps))
  2565. throw "Shader Error";
  2566. this._attribInfo = bindAttrib;
  2567. this._id = ++Shader._count;
  2568. this._vs = vs;
  2569. this._ps = ps;
  2570. this._nameMap = nameMap ? nameMap : {};
  2571. saveName != null && (Shader.sharders[saveName] = this);
  2572. this.recreateResource();
  2573. this.lock = true;
  2574. }
  2575. static getShader(name) {
  2576. return Shader.sharders[name];
  2577. }
  2578. static create(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2579. return new Shader(vs, ps, saveName, nameMap, bindAttrib);
  2580. }
  2581. static withCompile(nameID, define, shaderName, createShader) {
  2582. if (shaderName && Shader.sharders[shaderName])
  2583. return Shader.sharders[shaderName];
  2584. var pre = Shader._preCompileShader[Shader.SHADERNAME2ID * nameID];
  2585. if (!pre)
  2586. throw new Error("withCompile shader err!" + nameID);
  2587. return pre.createShader(define, shaderName, createShader, null);
  2588. }
  2589. static withCompile2D(nameID, mainID, define, shaderName, createShader, bindAttrib = null) {
  2590. if (shaderName && Shader.sharders[shaderName])
  2591. return Shader.sharders[shaderName];
  2592. var pre = Shader._preCompileShader[Shader.SHADERNAME2ID * nameID + mainID];
  2593. if (!pre)
  2594. throw new Error("withCompile shader err!" + nameID + " " + mainID);
  2595. return pre.createShader(define, shaderName, createShader, bindAttrib);
  2596. }
  2597. static addInclude(fileName, txt) {
  2598. ILaya.ShaderCompile.addInclude(fileName, txt);
  2599. }
  2600. static preCompile(nameID, vs, ps, nameMap) {
  2601. var id = Shader.SHADERNAME2ID * nameID;
  2602. Shader._preCompileShader[id] = new ILaya.ShaderCompile(vs, ps, nameMap);
  2603. }
  2604. static preCompile2D(nameID, mainID, vs, ps, nameMap) {
  2605. var id = Shader.SHADERNAME2ID * nameID + mainID;
  2606. Shader._preCompileShader[id] = new ILaya.ShaderCompile(vs, ps, nameMap);
  2607. }
  2608. recreateResource() {
  2609. this._compile();
  2610. this._setGPUMemory(0);
  2611. }
  2612. _disposeResource() {
  2613. WebGLContext.mainContext.deleteShader(this._vshader);
  2614. WebGLContext.mainContext.deleteShader(this._pshader);
  2615. WebGLContext.mainContext.deleteProgram(this._program);
  2616. this._vshader = this._pshader = this._program = null;
  2617. this._params = null;
  2618. this._paramsMap = {};
  2619. this._setGPUMemory(0);
  2620. this._curActTexIndex = 0;
  2621. }
  2622. _compile() {
  2623. if (!this._vs || !this._ps || this._params)
  2624. return;
  2625. this._reCompile = true;
  2626. this._params = [];
  2627. var result;
  2628. if (this.customCompile)
  2629. result = ILaya.ShaderCompile.preGetParams(this._vs, this._ps);
  2630. var gl = WebGLContext.mainContext;
  2631. this._program = gl.createProgram();
  2632. this._vshader = Shader._createShader(gl, this._vs, gl.VERTEX_SHADER);
  2633. this._pshader = Shader._createShader(gl, this._ps, gl.FRAGMENT_SHADER);
  2634. gl.attachShader(this._program, this._vshader);
  2635. gl.attachShader(this._program, this._pshader);
  2636. var one, i, n, location;
  2637. var attribDescNum = this._attribInfo ? this._attribInfo.length : 0;
  2638. for (i = 0; i < attribDescNum; i += 2) {
  2639. gl.bindAttribLocation(this._program, this._attribInfo[i + 1], this._attribInfo[i]);
  2640. }
  2641. gl.linkProgram(this._program);
  2642. if (!this.customCompile && !gl.getProgramParameter(this._program, gl.LINK_STATUS)) {
  2643. throw gl.getProgramInfoLog(this._program);
  2644. }
  2645. var nUniformNum = this.customCompile ? result.uniforms.length : gl.getProgramParameter(this._program, gl.ACTIVE_UNIFORMS);
  2646. for (i = 0; i < nUniformNum; i++) {
  2647. var uniform = this.customCompile ? result.uniforms[i] : gl.getActiveUniform(this._program, i);
  2648. location = gl.getUniformLocation(this._program, uniform.name);
  2649. one = { vartype: "uniform", glfun: null, ivartype: 1, location: location, name: uniform.name, type: uniform.type, isArray: false, isSame: false, preValue: null, indexOfParams: 0 };
  2650. if (one.name.indexOf('[0]') > 0) {
  2651. one.name = one.name.substr(0, one.name.length - 3);
  2652. one.isArray = true;
  2653. one.location = gl.getUniformLocation(this._program, one.name);
  2654. }
  2655. this._params.push(one);
  2656. }
  2657. for (i = 0, n = this._params.length; i < n; i++) {
  2658. one = this._params[i];
  2659. one.indexOfParams = i;
  2660. one.index = 1;
  2661. one.value = [one.location, null];
  2662. one.codename = one.name;
  2663. one.name = this._nameMap[one.codename] ? this._nameMap[one.codename] : one.codename;
  2664. this._paramsMap[one.name] = one;
  2665. one._this = this;
  2666. one.uploadedValue = [];
  2667. switch (one.type) {
  2668. case gl.INT:
  2669. one.fun = one.isArray ? this._uniform1iv : this._uniform1i;
  2670. break;
  2671. case gl.FLOAT:
  2672. one.fun = one.isArray ? this._uniform1fv : this._uniform1f;
  2673. break;
  2674. case gl.FLOAT_VEC2:
  2675. one.fun = one.isArray ? this._uniform_vec2v : this._uniform_vec2;
  2676. break;
  2677. case gl.FLOAT_VEC3:
  2678. one.fun = one.isArray ? this._uniform_vec3v : this._uniform_vec3;
  2679. break;
  2680. case gl.FLOAT_VEC4:
  2681. one.fun = one.isArray ? this._uniform_vec4v : this._uniform_vec4;
  2682. break;
  2683. case gl.SAMPLER_2D:
  2684. one.fun = this._uniform_sampler2D;
  2685. break;
  2686. case gl.SAMPLER_CUBE:
  2687. one.fun = this._uniform_samplerCube;
  2688. break;
  2689. case gl.FLOAT_MAT4:
  2690. one.glfun = gl.uniformMatrix4fv;
  2691. one.fun = this._uniformMatrix4fv;
  2692. break;
  2693. case gl.BOOL:
  2694. one.fun = this._uniform1i;
  2695. break;
  2696. case gl.FLOAT_MAT2:
  2697. case gl.FLOAT_MAT3:
  2698. throw new Error("compile shader err!");
  2699. default:
  2700. throw new Error("compile shader err!");
  2701. }
  2702. }
  2703. }
  2704. static _createShader(gl, str, type) {
  2705. var shader = gl.createShader(type);
  2706. gl.shaderSource(shader, str);
  2707. gl.compileShader(shader);
  2708. if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  2709. return shader;
  2710. }
  2711. else {
  2712. console.log(gl.getShaderInfoLog(shader));
  2713. return null;
  2714. }
  2715. }
  2716. getUniform(name) {
  2717. return this._paramsMap[name];
  2718. }
  2719. _uniform1f(one, value) {
  2720. var uploadedValue = one.uploadedValue;
  2721. if (uploadedValue[0] !== value) {
  2722. WebGLContext.mainContext.uniform1f(one.location, uploadedValue[0] = value);
  2723. return 1;
  2724. }
  2725. return 0;
  2726. }
  2727. _uniform1fv(one, value) {
  2728. if (value.length < 4) {
  2729. var uploadedValue = one.uploadedValue;
  2730. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2731. WebGLContext.mainContext.uniform1fv(one.location, value);
  2732. uploadedValue[0] = value[0];
  2733. uploadedValue[1] = value[1];
  2734. uploadedValue[2] = value[2];
  2735. uploadedValue[3] = value[3];
  2736. return 1;
  2737. }
  2738. return 0;
  2739. }
  2740. else {
  2741. WebGLContext.mainContext.uniform1fv(one.location, value);
  2742. return 1;
  2743. }
  2744. }
  2745. _uniform_vec2(one, value) {
  2746. var uploadedValue = one.uploadedValue;
  2747. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  2748. WebGLContext.mainContext.uniform2f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  2749. return 1;
  2750. }
  2751. return 0;
  2752. }
  2753. _uniform_vec2v(one, value) {
  2754. if (value.length < 2) {
  2755. var uploadedValue = one.uploadedValue;
  2756. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2757. WebGLContext.mainContext.uniform2fv(one.location, value);
  2758. uploadedValue[0] = value[0];
  2759. uploadedValue[1] = value[1];
  2760. uploadedValue[2] = value[2];
  2761. uploadedValue[3] = value[3];
  2762. return 1;
  2763. }
  2764. return 0;
  2765. }
  2766. else {
  2767. WebGLContext.mainContext.uniform2fv(one.location, value);
  2768. return 1;
  2769. }
  2770. }
  2771. _uniform_vec3(one, value) {
  2772. var uploadedValue = one.uploadedValue;
  2773. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  2774. WebGLContext.mainContext.uniform3f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  2775. return 1;
  2776. }
  2777. return 0;
  2778. }
  2779. _uniform_vec3v(one, value) {
  2780. WebGLContext.mainContext.uniform3fv(one.location, value);
  2781. return 1;
  2782. }
  2783. _uniform_vec4(one, value) {
  2784. var uploadedValue = one.uploadedValue;
  2785. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2786. WebGLContext.mainContext.uniform4f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  2787. return 1;
  2788. }
  2789. return 0;
  2790. }
  2791. _uniform_vec4v(one, value) {
  2792. WebGLContext.mainContext.uniform4fv(one.location, value);
  2793. return 1;
  2794. }
  2795. _uniformMatrix2fv(one, value) {
  2796. WebGLContext.mainContext.uniformMatrix2fv(one.location, false, value);
  2797. return 1;
  2798. }
  2799. _uniformMatrix3fv(one, value) {
  2800. WebGLContext.mainContext.uniformMatrix3fv(one.location, false, value);
  2801. return 1;
  2802. }
  2803. _uniformMatrix4fv(one, value) {
  2804. WebGLContext.mainContext.uniformMatrix4fv(one.location, false, value);
  2805. return 1;
  2806. }
  2807. _uniform1i(one, value) {
  2808. var uploadedValue = one.uploadedValue;
  2809. if (uploadedValue[0] !== value) {
  2810. WebGLContext.mainContext.uniform1i(one.location, uploadedValue[0] = value);
  2811. return 1;
  2812. }
  2813. return 0;
  2814. }
  2815. _uniform1iv(one, value) {
  2816. WebGLContext.mainContext.uniform1iv(one.location, value);
  2817. return 1;
  2818. }
  2819. _uniform_ivec2(one, value) {
  2820. var uploadedValue = one.uploadedValue;
  2821. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  2822. WebGLContext.mainContext.uniform2i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  2823. return 1;
  2824. }
  2825. return 0;
  2826. }
  2827. _uniform_ivec2v(one, value) {
  2828. WebGLContext.mainContext.uniform2iv(one.location, value);
  2829. return 1;
  2830. }
  2831. _uniform_vec3i(one, value) {
  2832. var uploadedValue = one.uploadedValue;
  2833. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  2834. WebGLContext.mainContext.uniform3i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  2835. return 1;
  2836. }
  2837. return 0;
  2838. }
  2839. _uniform_vec3vi(one, value) {
  2840. WebGLContext.mainContext.uniform3iv(one.location, value);
  2841. return 1;
  2842. }
  2843. _uniform_vec4i(one, value) {
  2844. var uploadedValue = one.uploadedValue;
  2845. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2846. WebGLContext.mainContext.uniform4i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  2847. return 1;
  2848. }
  2849. return 0;
  2850. }
  2851. _uniform_vec4vi(one, value) {
  2852. WebGLContext.mainContext.uniform4iv(one.location, value);
  2853. return 1;
  2854. }
  2855. _uniform_sampler2D(one, value) {
  2856. var gl = WebGLContext.mainContext;
  2857. var uploadedValue = one.uploadedValue;
  2858. if (uploadedValue[0] == null) {
  2859. uploadedValue[0] = this._curActTexIndex;
  2860. gl.uniform1i(one.location, this._curActTexIndex);
  2861. WebGLContext.activeTexture(gl, gl.TEXTURE0 + this._curActTexIndex);
  2862. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  2863. this._curActTexIndex++;
  2864. return 1;
  2865. }
  2866. else {
  2867. WebGLContext.activeTexture(gl, gl.TEXTURE0 + uploadedValue[0]);
  2868. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  2869. return 0;
  2870. }
  2871. }
  2872. _uniform_samplerCube(one, value) {
  2873. var gl = WebGLContext.mainContext;
  2874. var uploadedValue = one.uploadedValue;
  2875. if (uploadedValue[0] == null) {
  2876. uploadedValue[0] = this._curActTexIndex;
  2877. gl.uniform1i(one.location, this._curActTexIndex);
  2878. WebGLContext.activeTexture(gl, gl.TEXTURE0 + this._curActTexIndex);
  2879. WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  2880. this._curActTexIndex++;
  2881. return 1;
  2882. }
  2883. else {
  2884. WebGLContext.activeTexture(gl, gl.TEXTURE0 + uploadedValue[0]);
  2885. WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  2886. return 0;
  2887. }
  2888. }
  2889. _noSetValue(one) {
  2890. console.log("no....:" + one.name);
  2891. }
  2892. uploadOne(name, value) {
  2893. WebGLContext.useProgram(WebGLContext.mainContext, this._program);
  2894. var one = this._paramsMap[name];
  2895. one.fun.call(this, one, value);
  2896. }
  2897. uploadTexture2D(value) {
  2898. var CTX = WebGLContext;
  2899. if (CTX._activeTextures[0] !== value) {
  2900. CTX.bindTexture(WebGLContext.mainContext, LayaGL.instance.TEXTURE_2D, value);
  2901. CTX._activeTextures[0] = value;
  2902. }
  2903. }
  2904. upload(shaderValue, params = null) {
  2905. BaseShader.activeShader = BaseShader.bindShader = this;
  2906. var gl = WebGLContext.mainContext;
  2907. WebGLContext.useProgram(gl, this._program);
  2908. if (this._reCompile) {
  2909. params = this._params;
  2910. this._reCompile = false;
  2911. }
  2912. else {
  2913. params = params || this._params;
  2914. }
  2915. var one, value, n = params.length, shaderCall = 0;
  2916. for (var i = 0; i < n; i++) {
  2917. one = params[i];
  2918. if ((value = shaderValue[one.name]) !== null)
  2919. shaderCall += one.fun.call(this, one, value);
  2920. }
  2921. Stat.shaderCall += shaderCall;
  2922. }
  2923. uploadArray(shaderValue, length, _bufferUsage) {
  2924. BaseShader.activeShader = this;
  2925. BaseShader.bindShader = this;
  2926. WebGLContext.useProgram(WebGLContext.mainContext, this._program);
  2927. var params = this._params, value;
  2928. var one, shaderCall = 0;
  2929. for (var i = length - 2; i >= 0; i -= 2) {
  2930. one = this._paramsMap[shaderValue[i]];
  2931. if (!one)
  2932. continue;
  2933. value = shaderValue[i + 1];
  2934. if (value != null) {
  2935. _bufferUsage && _bufferUsage[one.name] && _bufferUsage[one.name].bind();
  2936. shaderCall += one.fun.call(this, one, value);
  2937. }
  2938. }
  2939. Stat.shaderCall += shaderCall;
  2940. }
  2941. getParams() {
  2942. return this._params;
  2943. }
  2944. setAttributesLocation(attribDesc) {
  2945. this._attribInfo = attribDesc;
  2946. }
  2947. }
  2948. Shader._count = 0;
  2949. Shader._preCompileShader = {};
  2950. Shader.SHADERNAME2ID = 0.0002;
  2951. Shader.nameKey = new StringKey();
  2952. Shader.sharders = new Array(0x20);
  2953. class Shader2X extends Shader {
  2954. constructor(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2955. super(vs, ps, saveName, nameMap, bindAttrib);
  2956. this._params2dQuick2 = null;
  2957. this._shaderValueWidth = 0;
  2958. this._shaderValueHeight = 0;
  2959. }
  2960. _disposeResource() {
  2961. super._disposeResource();
  2962. this._params2dQuick2 = null;
  2963. }
  2964. upload2dQuick2(shaderValue) {
  2965. this.upload(shaderValue, this._params2dQuick2 || this._make2dQuick2());
  2966. }
  2967. _make2dQuick2() {
  2968. if (!this._params2dQuick2) {
  2969. this._params2dQuick2 = [];
  2970. var params = this._params, one;
  2971. for (var i = 0, n = params.length; i < n; i++) {
  2972. one = params[i];
  2973. if (one.name !== "size")
  2974. this._params2dQuick2.push(one);
  2975. }
  2976. }
  2977. return this._params2dQuick2;
  2978. }
  2979. static create(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2980. return new Shader2X(vs, ps, saveName, nameMap, bindAttrib);
  2981. }
  2982. }
  2983. class Value2D {
  2984. constructor(mainID, subID) {
  2985. this.defines = new ShaderDefines2D();
  2986. this.size = [0, 0];
  2987. this.alpha = 1.0;
  2988. this.ALPHA = 1.0;
  2989. this.subID = 0;
  2990. this.ref = 1;
  2991. this._cacheID = 0;
  2992. this.clipMatDir = [ILaya.Context._MAXSIZE, 0, 0, ILaya.Context._MAXSIZE];
  2993. this.clipMatPos = [0, 0];
  2994. this.clipOff = [0, 0];
  2995. this.mainID = mainID;
  2996. this.subID = subID;
  2997. this.textureHost = null;
  2998. this.texture = null;
  2999. this.color = null;
  3000. this.colorAdd = null;
  3001. this.u_mmat2 = null;
  3002. this._cacheID = mainID | subID;
  3003. this._inClassCache = Value2D._cache[this._cacheID];
  3004. if (mainID > 0 && !this._inClassCache) {
  3005. this._inClassCache = Value2D._cache[this._cacheID] = [];
  3006. this._inClassCache._length = 0;
  3007. }
  3008. this.clear();
  3009. }
  3010. static _initone(type, classT) {
  3011. Value2D._typeClass[type] = classT;
  3012. Value2D._cache[type] = [];
  3013. Value2D._cache[type]._length = 0;
  3014. }
  3015. static __init__() {
  3016. }
  3017. setValue(value) { }
  3018. _ShaderWithCompile() {
  3019. var ret = Shader.withCompile2D(0, this.mainID, this.defines.toNameDic(), this.mainID | this.defines._value, Shader2X.create, this._attribLocation);
  3020. return ret;
  3021. }
  3022. upload() {
  3023. var renderstate2d = RenderState2D;
  3024. RenderState2D.worldMatrix4 === RenderState2D.TEMPMAT4_ARRAY || this.defines.addInt(ShaderDefines2D.WORLDMAT);
  3025. this.mmat = renderstate2d.worldMatrix4;
  3026. if (RenderState2D.matWVP) {
  3027. this.defines.addInt(ShaderDefines2D.MVP3D);
  3028. this.u_MvpMatrix = RenderState2D.matWVP.elements;
  3029. }
  3030. var sd = Shader.sharders[this.mainID | this.defines._value] || this._ShaderWithCompile();
  3031. if (sd._shaderValueWidth !== renderstate2d.width || sd._shaderValueHeight !== renderstate2d.height) {
  3032. this.size[0] = renderstate2d.width;
  3033. this.size[1] = renderstate2d.height;
  3034. sd._shaderValueWidth = renderstate2d.width;
  3035. sd._shaderValueHeight = renderstate2d.height;
  3036. sd.upload(this, null);
  3037. }
  3038. else {
  3039. sd.upload(this, sd._params2dQuick2 || sd._make2dQuick2());
  3040. }
  3041. }
  3042. setFilters(value) {
  3043. this.filters = value;
  3044. if (!value)
  3045. return;
  3046. var n = value.length, f;
  3047. for (var i = 0; i < n; i++) {
  3048. f = value[i];
  3049. if (f) {
  3050. this.defines.add(f.type);
  3051. f.action.setValue(this);
  3052. }
  3053. }
  3054. }
  3055. clear() {
  3056. this.defines._value = this.subID;
  3057. this.clipOff[0] = 0;
  3058. }
  3059. release() {
  3060. if ((--this.ref) < 1) {
  3061. this._inClassCache && (this._inClassCache[this._inClassCache._length++] = this);
  3062. this.clear();
  3063. this.filters = null;
  3064. this.ref = 1;
  3065. this.clipOff[0] = 0;
  3066. }
  3067. }
  3068. static create(mainType, subType) {
  3069. var types = Value2D._cache[mainType | subType];
  3070. if (types._length)
  3071. return types[--types._length];
  3072. else
  3073. return new Value2D._typeClass[mainType | subType](subType);
  3074. }
  3075. }
  3076. Value2D._cache = [];
  3077. Value2D._typeClass = [];
  3078. Value2D.TEMPMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  3079. class SubmitKey {
  3080. constructor() {
  3081. this.clear();
  3082. }
  3083. clear() {
  3084. this.submitType = -1;
  3085. this.blendShader = this.other = 0;
  3086. }
  3087. copyFrom(src) {
  3088. this.other = src.other;
  3089. this.blendShader = src.blendShader;
  3090. this.submitType = src.submitType;
  3091. }
  3092. copyFrom2(src, submitType, other) {
  3093. this.other = other;
  3094. this.submitType = submitType;
  3095. }
  3096. equal3_2(next, submitType, other) {
  3097. return this.submitType === submitType && this.other === other && this.blendShader === next.blendShader;
  3098. }
  3099. equal4_2(next, submitType, other) {
  3100. return this.submitType === submitType && this.other === other && this.blendShader === next.blendShader;
  3101. }
  3102. equal_3(next) {
  3103. return this.submitType === next.submitType && this.blendShader === next.blendShader;
  3104. }
  3105. equal(next) {
  3106. return this.other === next.other && this.submitType === next.submitType && this.blendShader === next.blendShader;
  3107. }
  3108. }
  3109. class SubmitCMD {
  3110. constructor() {
  3111. this._ref = 1;
  3112. this._key = new SubmitKey();
  3113. }
  3114. renderSubmit() {
  3115. this.fun.apply(this._this, this.args);
  3116. return 1;
  3117. }
  3118. getRenderType() {
  3119. return 0;
  3120. }
  3121. releaseRender() {
  3122. if ((--this._ref) < 1) {
  3123. var pool = SubmitCMD.POOL;
  3124. pool[pool._length++] = this;
  3125. }
  3126. }
  3127. static create(args, fun, thisobj) {
  3128. var o = SubmitCMD.POOL._length ? SubmitCMD.POOL[--SubmitCMD.POOL._length] : new SubmitCMD();
  3129. o.fun = fun;
  3130. o.args = args;
  3131. o._this = thisobj;
  3132. o._ref = 1;
  3133. o._key.clear();
  3134. return o;
  3135. }
  3136. }
  3137. SubmitCMD.POOL = [];
  3138. {
  3139. SubmitCMD.POOL._length = 0;
  3140. }
  3141. class Filter {
  3142. constructor() {
  3143. }
  3144. get type() { return -1; }
  3145. }
  3146. Filter.BLUR = 0x10;
  3147. Filter.COLOR = 0x20;
  3148. Filter.GLOW = 0x08;
  3149. Filter._filter = function (sprite, context, x, y) {
  3150. var webglctx = context;
  3151. var next = this._next;
  3152. if (next) {
  3153. var filters = sprite.filters, len = filters.length;
  3154. if (len == 1 && (filters[0].type == Filter.COLOR)) {
  3155. context.save();
  3156. context.setColorFilter(filters[0]);
  3157. next._fun.call(next, sprite, context, x, y);
  3158. context.restore();
  3159. return;
  3160. }
  3161. var svCP = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  3162. var b;
  3163. var p = Point.TEMP;
  3164. var tMatrix = webglctx._curMat;
  3165. var mat = Matrix.create();
  3166. tMatrix.copyTo(mat);
  3167. var tPadding = 0;
  3168. var tHalfPadding = 0;
  3169. var tIsHaveGlowFilter = false;
  3170. var source = null;
  3171. var out = sprite._cacheStyle.filterCache || null;
  3172. if (!out || sprite.getRepaint() != 0) {
  3173. tIsHaveGlowFilter = sprite._isHaveGlowFilter();
  3174. if (tIsHaveGlowFilter) {
  3175. tPadding = 50;
  3176. tHalfPadding = 25;
  3177. }
  3178. b = new Rectangle();
  3179. b.copyFrom(sprite.getSelfBounds());
  3180. b.x += sprite.x;
  3181. b.y += sprite.y;
  3182. b.x -= sprite.pivotX + 4;
  3183. b.y -= sprite.pivotY + 4;
  3184. var tSX = b.x;
  3185. var tSY = b.y;
  3186. b.width += (tPadding + 8);
  3187. b.height += (tPadding + 8);
  3188. p.x = b.x * mat.a + b.y * mat.c;
  3189. p.y = b.y * mat.d + b.x * mat.b;
  3190. b.x = p.x;
  3191. b.y = p.y;
  3192. p.x = b.width * mat.a + b.height * mat.c;
  3193. p.y = b.height * mat.d + b.width * mat.b;
  3194. b.width = p.x;
  3195. b.height = p.y;
  3196. if (b.width <= 0 || b.height <= 0) {
  3197. return;
  3198. }
  3199. out && WebGLRTMgr.releaseRT(out);
  3200. source = WebGLRTMgr.getRT(b.width, b.height);
  3201. var outRT = out = WebGLRTMgr.getRT(b.width, b.height);
  3202. sprite._getCacheStyle().filterCache = out;
  3203. webglctx.pushRT();
  3204. webglctx.useRT(source);
  3205. var tX = sprite.x - tSX + tHalfPadding;
  3206. var tY = sprite.y - tSY + tHalfPadding;
  3207. next._fun.call(next, sprite, context, tX, tY);
  3208. webglctx.useRT(outRT);
  3209. for (var i = 0; i < len; i++) {
  3210. if (i != 0) {
  3211. webglctx.useRT(source);
  3212. webglctx.drawTarget(outRT, 0, 0, b.width, b.height, Matrix.TEMP.identity(), svCP, null, BlendMode.TOINT.overlay);
  3213. webglctx.useRT(outRT);
  3214. }
  3215. var fil = filters[i];
  3216. switch (fil.type) {
  3217. case Filter.BLUR:
  3218. fil._glRender && fil._glRender.render(source, context, b.width, b.height, fil);
  3219. break;
  3220. case Filter.GLOW:
  3221. fil._glRender && fil._glRender.render(source, context, b.width, b.height, fil);
  3222. break;
  3223. case Filter.COLOR:
  3224. webglctx.setColorFilter(fil);
  3225. webglctx.drawTarget(source, 0, 0, b.width, b.height, Matrix.EMPTY.identity(), Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  3226. webglctx.setColorFilter(null);
  3227. break;
  3228. }
  3229. }
  3230. webglctx.popRT();
  3231. }
  3232. else {
  3233. tIsHaveGlowFilter = sprite._cacheStyle.hasGlowFilter || false;
  3234. if (tIsHaveGlowFilter) {
  3235. tPadding = 50;
  3236. tHalfPadding = 25;
  3237. }
  3238. b = sprite.getBounds();
  3239. if (b.width <= 0 || b.height <= 0) {
  3240. return;
  3241. }
  3242. b.width += tPadding;
  3243. b.height += tPadding;
  3244. p.x = b.x * mat.a + b.y * mat.c;
  3245. p.y = b.y * mat.d + b.x * mat.b;
  3246. b.x = p.x;
  3247. b.y = p.y;
  3248. p.x = b.width * mat.a + b.height * mat.c;
  3249. p.y = b.height * mat.d + b.width * mat.b;
  3250. b.width = p.x;
  3251. b.height = p.y;
  3252. }
  3253. x = x - tHalfPadding - sprite.x;
  3254. y = y - tHalfPadding - sprite.y;
  3255. p.setTo(x, y);
  3256. mat.transformPoint(p);
  3257. x = p.x + b.x;
  3258. y = p.y + b.y;
  3259. webglctx._drawRenderTexture(out, x, y, b.width, b.height, Matrix.TEMP.identity(), 1.0, RenderTexture2D.defuv);
  3260. if (source) {
  3261. var submit = SubmitCMD.create([source], function (s) {
  3262. s.destroy();
  3263. }, this);
  3264. source = null;
  3265. context.addRenderObject(submit);
  3266. }
  3267. mat.destroy();
  3268. }
  3269. };
  3270. class Utils {
  3271. static toRadian(angle) {
  3272. return angle * Utils._pi2;
  3273. }
  3274. static toAngle(radian) {
  3275. return radian * Utils._pi;
  3276. }
  3277. static toHexColor(color) {
  3278. if (color < 0 || isNaN(color))
  3279. return null;
  3280. var str = color.toString(16);
  3281. while (str.length < 6)
  3282. str = "0" + str;
  3283. return "#" + str;
  3284. }
  3285. static getGID() {
  3286. return Utils._gid++;
  3287. }
  3288. static concatArray(source, array) {
  3289. if (!array)
  3290. return source;
  3291. if (!source)
  3292. return array;
  3293. var i, len = array.length;
  3294. for (i = 0; i < len; i++) {
  3295. source.push(array[i]);
  3296. }
  3297. return source;
  3298. }
  3299. static clearArray(array) {
  3300. if (!array)
  3301. return array;
  3302. array.length = 0;
  3303. return array;
  3304. }
  3305. static copyArray(source, array) {
  3306. source || (source = []);
  3307. if (!array)
  3308. return source;
  3309. source.length = array.length;
  3310. var i, len = array.length;
  3311. for (i = 0; i < len; i++) {
  3312. source[i] = array[i];
  3313. }
  3314. return source;
  3315. }
  3316. static getGlobalRecByPoints(sprite, x0, y0, x1, y1) {
  3317. var newLTPoint;
  3318. newLTPoint = Point.create().setTo(x0, y0);
  3319. newLTPoint = sprite.localToGlobal(newLTPoint);
  3320. var newRBPoint;
  3321. newRBPoint = Point.create().setTo(x1, y1);
  3322. newRBPoint = sprite.localToGlobal(newRBPoint);
  3323. var rst = Rectangle._getWrapRec([newLTPoint.x, newLTPoint.y, newRBPoint.x, newRBPoint.y]);
  3324. newLTPoint.recover();
  3325. newRBPoint.recover();
  3326. return rst;
  3327. }
  3328. static getGlobalPosAndScale(sprite) {
  3329. return Utils.getGlobalRecByPoints(sprite, 0, 0, 1, 1);
  3330. }
  3331. static bind(fun, scope) {
  3332. var rst = fun;
  3333. rst = fun.bind(scope);
  3334. return rst;
  3335. }
  3336. static updateOrder(array) {
  3337. if (!array || array.length < 2)
  3338. return false;
  3339. var i = 1, j, len = array.length, key, c;
  3340. while (i < len) {
  3341. j = i;
  3342. c = array[j];
  3343. key = array[j]._zOrder;
  3344. while (--j > -1) {
  3345. if (array[j]._zOrder > key)
  3346. array[j + 1] = array[j];
  3347. else
  3348. break;
  3349. }
  3350. array[j + 1] = c;
  3351. i++;
  3352. }
  3353. return true;
  3354. }
  3355. static transPointList(points, x, y) {
  3356. var i, len = points.length;
  3357. for (i = 0; i < len; i += 2) {
  3358. points[i] += x;
  3359. points[i + 1] += y;
  3360. }
  3361. }
  3362. static parseInt(str, radix = 0) {
  3363. var result = parseInt(str, radix);
  3364. if (isNaN(result))
  3365. return 0;
  3366. return result;
  3367. }
  3368. static getFileExtension(path) {
  3369. Utils._extReg.lastIndex = path.lastIndexOf(".");
  3370. var result = Utils._extReg.exec(path);
  3371. if (result && result.length > 1) {
  3372. return result[1].toLowerCase();
  3373. }
  3374. return null;
  3375. }
  3376. static getFilecompatibleExtension(path) {
  3377. var result = path.split(".");
  3378. var resultlen = result.length;
  3379. if (result.length > 2)
  3380. return result[resultlen - 2] + "." + result[resultlen - 1];
  3381. else
  3382. return null;
  3383. }
  3384. static getTransformRelativeToWindow(coordinateSpace, x, y) {
  3385. var stage = Utils.gStage;
  3386. var globalTransform = Utils.getGlobalPosAndScale(coordinateSpace);
  3387. var canvasMatrix = stage._canvasTransform.clone();
  3388. var canvasLeft = canvasMatrix.tx;
  3389. var canvasTop = canvasMatrix.ty;
  3390. canvasMatrix.rotate(-Math.PI / 180 * stage.canvasDegree);
  3391. canvasMatrix.scale(stage.clientScaleX, stage.clientScaleY);
  3392. var perpendicular = (stage.canvasDegree % 180 != 0);
  3393. var tx, ty;
  3394. if (perpendicular) {
  3395. tx = y + globalTransform.y;
  3396. ty = x + globalTransform.x;
  3397. tx *= canvasMatrix.d;
  3398. ty *= canvasMatrix.a;
  3399. if (stage.canvasDegree == 90) {
  3400. tx = canvasLeft - tx;
  3401. ty += canvasTop;
  3402. }
  3403. else {
  3404. tx += canvasLeft;
  3405. ty = canvasTop - ty;
  3406. }
  3407. }
  3408. else {
  3409. tx = x + globalTransform.x;
  3410. ty = y + globalTransform.y;
  3411. tx *= canvasMatrix.a;
  3412. ty *= canvasMatrix.d;
  3413. tx += canvasLeft;
  3414. ty += canvasTop;
  3415. }
  3416. ty += stage['_safariOffsetY'];
  3417. var domScaleX, domScaleY;
  3418. if (perpendicular) {
  3419. domScaleX = canvasMatrix.d * globalTransform.height;
  3420. domScaleY = canvasMatrix.a * globalTransform.width;
  3421. }
  3422. else {
  3423. domScaleX = canvasMatrix.a * globalTransform.width;
  3424. domScaleY = canvasMatrix.d * globalTransform.height;
  3425. }
  3426. return { x: tx, y: ty, scaleX: domScaleX, scaleY: domScaleY };
  3427. }
  3428. static fitDOMElementInArea(dom, coordinateSpace, x, y, width, height) {
  3429. if (!dom._fitLayaAirInitialized) {
  3430. dom._fitLayaAirInitialized = true;
  3431. dom.style.transformOrigin = dom.style.webKittransformOrigin = "left top";
  3432. dom.style.position = "absolute";
  3433. }
  3434. var transform = Utils.getTransformRelativeToWindow(coordinateSpace, x, y);
  3435. dom.style.transform = dom.style.webkitTransform = "scale(" + transform.scaleX + "," + transform.scaleY + ") rotate(" + (Utils.gStage.canvasDegree) + "deg)";
  3436. dom.style.width = width + 'px';
  3437. dom.style.height = height + 'px';
  3438. dom.style.left = transform.x + 'px';
  3439. dom.style.top = transform.y + 'px';
  3440. }
  3441. static isOkTextureList(textureList) {
  3442. if (!textureList)
  3443. return false;
  3444. var i, len = textureList.length;
  3445. var tTexture;
  3446. for (i = 0; i < len; i++) {
  3447. tTexture = textureList[i];
  3448. if (!tTexture || !tTexture._getSource())
  3449. return false;
  3450. }
  3451. return true;
  3452. }
  3453. static isOKCmdList(cmds) {
  3454. if (!cmds)
  3455. return false;
  3456. var i, len = cmds.length;
  3457. var cmd;
  3458. for (i = 0; i < len; i++) {
  3459. cmd = cmds[i];
  3460. }
  3461. return true;
  3462. }
  3463. static getQueryString(name) {
  3464. if (ILaya.Browser.onMiniGame)
  3465. return null;
  3466. if (!window.location || !window.location.search)
  3467. return null;
  3468. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  3469. var r = window.location.search.substr(1).match(reg);
  3470. if (r != null)
  3471. return unescape(r[2]);
  3472. return null;
  3473. }
  3474. }
  3475. Utils.gStage = null;
  3476. Utils._gid = 1;
  3477. Utils._pi = 180 / Math.PI;
  3478. Utils._pi2 = Math.PI / 180;
  3479. Utils._extReg = /\.(\w+)\??/g;
  3480. Utils.parseXMLFromString = function (value) {
  3481. var rst;
  3482. value = value.replace(/>\s+</g, '><');
  3483. rst = (new DOMParser()).parseFromString(value, 'text/xml');
  3484. if (rst.firstChild.textContent.indexOf("This page contains the following errors") > -1) {
  3485. throw new Error(rst.firstChild.firstChild.textContent);
  3486. }
  3487. return rst;
  3488. };
  3489. class ColorUtils {
  3490. constructor(value) {
  3491. this.arrColor = [];
  3492. if (value == null) {
  3493. this.strColor = "#00000000";
  3494. this.numColor = 0;
  3495. this.arrColor = [0, 0, 0, 0];
  3496. return;
  3497. }
  3498. var i, len;
  3499. var color;
  3500. if (typeof (value) == 'string') {
  3501. if (value.indexOf("rgba(") >= 0 || value.indexOf("rgb(") >= 0) {
  3502. var tStr = value;
  3503. var beginI, endI;
  3504. beginI = tStr.indexOf("(");
  3505. endI = tStr.indexOf(")");
  3506. tStr = tStr.substring(beginI + 1, endI);
  3507. this.arrColor = tStr.split(",");
  3508. len = this.arrColor.length;
  3509. for (i = 0; i < len; i++) {
  3510. this.arrColor[i] = parseFloat(this.arrColor[i]);
  3511. if (i < 3) {
  3512. this.arrColor[i] = Math.round(this.arrColor[i]);
  3513. }
  3514. }
  3515. if (this.arrColor.length == 4) {
  3516. color = ((this.arrColor[0] * 256 + this.arrColor[1]) * 256 + this.arrColor[2]) * 256 + Math.round(this.arrColor[3] * 255);
  3517. }
  3518. else {
  3519. color = ((this.arrColor[0] * 256 + this.arrColor[1]) * 256 + this.arrColor[2]);
  3520. }
  3521. this.strColor = value;
  3522. }
  3523. else {
  3524. this.strColor = value;
  3525. value.charAt(0) === '#' && (value = value.substr(1));
  3526. len = value.length;
  3527. if (len === 3 || len === 4) {
  3528. var temp = "";
  3529. for (i = 0; i < len; i++) {
  3530. temp += (value[i] + value[i]);
  3531. }
  3532. value = temp;
  3533. }
  3534. color = parseInt(value, 16);
  3535. }
  3536. }
  3537. else {
  3538. color = value;
  3539. this.strColor = Utils.toHexColor(color);
  3540. }
  3541. if (this.strColor.indexOf("rgba") >= 0 || this.strColor.length === 9) {
  3542. this.arrColor = [((0xFF000000 & color) >>> 24) / 255, ((0xFF0000 & color) >> 16) / 255, ((0xFF00 & color) >> 8) / 255, (0xFF & color) / 255];
  3543. this.numColor = (0xff000000 & color) >>> 24 | (color & 0xff0000) >> 8 | (color & 0x00ff00) << 8 | ((color & 0xff) << 24);
  3544. }
  3545. else {
  3546. this.arrColor = [((0xFF0000 & color) >> 16) / 255, ((0xFF00 & color) >> 8) / 255, (0xFF & color) / 255, 1];
  3547. this.numColor = 0xff000000 | (color & 0xff0000) >> 16 | (color & 0x00ff00) | (color & 0xff) << 16;
  3548. }
  3549. this.arrColor.__id = ++ColorUtils._COLODID;
  3550. }
  3551. static _initDefault() {
  3552. ColorUtils._DEFAULT = {};
  3553. for (var i in ColorUtils._COLOR_MAP)
  3554. ColorUtils._SAVE[i] = ColorUtils._DEFAULT[i] = new ColorUtils(ColorUtils._COLOR_MAP[i]);
  3555. return ColorUtils._DEFAULT;
  3556. }
  3557. static _initSaveMap() {
  3558. ColorUtils._SAVE_SIZE = 0;
  3559. ColorUtils._SAVE = {};
  3560. for (var i in ColorUtils._DEFAULT)
  3561. ColorUtils._SAVE[i] = ColorUtils._DEFAULT[i];
  3562. }
  3563. static create(value) {
  3564. var key = value + "";
  3565. var color = ColorUtils._SAVE[key];
  3566. if (color != null)
  3567. return color;
  3568. if (ColorUtils._SAVE_SIZE < 1000)
  3569. ColorUtils._initSaveMap();
  3570. return ColorUtils._SAVE[key] = new ColorUtils(value);
  3571. }
  3572. }
  3573. ColorUtils._SAVE = {};
  3574. ColorUtils._SAVE_SIZE = 0;
  3575. ColorUtils._COLOR_MAP = { "purple": "#800080", "orange": "#ffa500", "white": '#FFFFFF', "red": '#FF0000', "green": '#00FF00', "blue": '#0000FF', "black": '#000000', "yellow": '#FFFF00', 'gray': '#808080' };
  3576. ColorUtils._DEFAULT = ColorUtils._initDefault();
  3577. ColorUtils._COLODID = 1;
  3578. class ColorFilter extends Filter {
  3579. constructor(mat = null) {
  3580. super();
  3581. if (!mat)
  3582. mat = this._copyMatrix(ColorFilter.IDENTITY_MATRIX);
  3583. this._mat = new Float32Array(16);
  3584. this._alpha = new Float32Array(4);
  3585. this.setByMatrix(mat);
  3586. }
  3587. gray() {
  3588. return this.setByMatrix(ColorFilter.GRAY_MATRIX);
  3589. }
  3590. color(red = 0, green = 0, blue = 0, alpha = 1) {
  3591. return this.setByMatrix([1, 0, 0, 0, red, 0, 1, 0, 0, green, 0, 0, 1, 0, blue, 0, 0, 0, 1, alpha]);
  3592. }
  3593. setColor(color) {
  3594. var arr = ColorUtils.create(color).arrColor;
  3595. var mt = [0, 0, 0, 0, 256 * arr[0], 0, 0, 0, 0, 256 * arr[1], 0, 0, 0, 0, 256 * arr[2], 0, 0, 0, 1, 0];
  3596. return this.setByMatrix(mt);
  3597. }
  3598. setByMatrix(matrix) {
  3599. if (this._matrix != matrix)
  3600. this._copyMatrix(matrix);
  3601. var j = 0;
  3602. var z = 0;
  3603. for (var i = 0; i < 20; i++) {
  3604. if (i % 5 != 4) {
  3605. this._mat[j++] = matrix[i];
  3606. }
  3607. else {
  3608. this._alpha[z++] = matrix[i];
  3609. }
  3610. }
  3611. return this;
  3612. }
  3613. get type() {
  3614. return Filter.COLOR;
  3615. }
  3616. adjustColor(brightness, contrast, saturation, hue) {
  3617. this.adjustHue(hue);
  3618. this.adjustContrast(contrast);
  3619. this.adjustBrightness(brightness);
  3620. this.adjustSaturation(saturation);
  3621. return this;
  3622. }
  3623. adjustBrightness(brightness) {
  3624. brightness = this._clampValue(brightness, 100);
  3625. if (brightness == 0 || isNaN(brightness))
  3626. return this;
  3627. return this._multiplyMatrix([1, 0, 0, 0, brightness, 0, 1, 0, 0, brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3628. }
  3629. adjustContrast(contrast) {
  3630. contrast = this._clampValue(contrast, 100);
  3631. if (contrast == 0 || isNaN(contrast))
  3632. return this;
  3633. var x;
  3634. if (contrast < 0) {
  3635. x = 127 + contrast / 100 * 127;
  3636. }
  3637. else {
  3638. x = contrast % 1;
  3639. if (x == 0) {
  3640. x = ColorFilter.DELTA_INDEX[contrast];
  3641. }
  3642. else {
  3643. x = ColorFilter.DELTA_INDEX[(contrast << 0)] * (1 - x) + ColorFilter.DELTA_INDEX[(contrast << 0) + 1] * x;
  3644. }
  3645. x = x * 127 + 127;
  3646. }
  3647. var x1 = x / 127;
  3648. var x2 = (127 - x) * 0.5;
  3649. return this._multiplyMatrix([x1, 0, 0, 0, x2, 0, x1, 0, 0, x2, 0, 0, x1, 0, x2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3650. }
  3651. adjustSaturation(saturation) {
  3652. saturation = this._clampValue(saturation, 100);
  3653. if (saturation == 0 || isNaN(saturation))
  3654. return this;
  3655. var x = 1 + ((saturation > 0) ? 3 * saturation / 100 : saturation / 100);
  3656. var dx = 1 - x;
  3657. var r = 0.3086 * dx;
  3658. var g = 0.6094 * dx;
  3659. var b = 0.0820 * dx;
  3660. return this._multiplyMatrix([r + x, g, b, 0, 0, r, g + x, b, 0, 0, r, g, b + x, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3661. }
  3662. adjustHue(hue) {
  3663. hue = this._clampValue(hue, 180) / 180 * Math.PI;
  3664. if (hue == 0 || isNaN(hue))
  3665. return this;
  3666. var cos = Math.cos(hue);
  3667. var sin = Math.sin(hue);
  3668. var r = 0.213;
  3669. var g = 0.715;
  3670. var b = 0.072;
  3671. return this._multiplyMatrix([r + cos * (1 - r) + sin * (-r), g + cos * (-g) + sin * (-g), b + cos * (-b) + sin * (1 - b), 0, 0, r + cos * (-r) + sin * (0.143), g + cos * (1 - g) + sin * (0.140), b + cos * (-b) + sin * (-0.283), 0, 0, r + cos * (-r) + sin * (-(1 - r)), g + cos * (-g) + sin * (g), b + cos * (1 - b) + sin * (b), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
  3672. }
  3673. reset() {
  3674. return this.setByMatrix(this._copyMatrix(ColorFilter.IDENTITY_MATRIX));
  3675. }
  3676. _multiplyMatrix(matrix) {
  3677. var col = [];
  3678. this._matrix = this._fixMatrix(this._matrix);
  3679. for (var i = 0; i < 5; i++) {
  3680. for (var j = 0; j < 5; j++) {
  3681. col[j] = this._matrix[j + i * 5];
  3682. }
  3683. for (j = 0; j < 5; j++) {
  3684. var val = 0;
  3685. for (var k = 0; k < 5; k++) {
  3686. val += matrix[j + k * 5] * col[k];
  3687. }
  3688. this._matrix[j + i * 5] = val;
  3689. }
  3690. }
  3691. return this.setByMatrix(this._matrix);
  3692. }
  3693. _clampValue(val, limit) {
  3694. return Math.min(limit, Math.max(-limit, val));
  3695. }
  3696. _fixMatrix(matrix = null) {
  3697. if (matrix == null)
  3698. return ColorFilter.IDENTITY_MATRIX;
  3699. if (matrix.length < ColorFilter.LENGTH)
  3700. matrix = matrix.slice(0, matrix.length).concat(ColorFilter.IDENTITY_MATRIX.slice(matrix.length, ColorFilter.LENGTH));
  3701. else if (matrix.length > ColorFilter.LENGTH)
  3702. matrix = matrix.slice(0, ColorFilter.LENGTH);
  3703. return matrix;
  3704. }
  3705. _copyMatrix(matrix) {
  3706. var len = ColorFilter.LENGTH;
  3707. if (!this._matrix)
  3708. this._matrix = [];
  3709. for (var i = 0; i < len; i++) {
  3710. this._matrix[i] = matrix[i];
  3711. }
  3712. return this._matrix;
  3713. }
  3714. }
  3715. ColorFilter.DELTA_INDEX = [0, 0.01, 0.02, 0.04, 0.05, 0.06, 0.07, 0.08, 0.1, 0.11, 0.12, 0.14, 0.15, 0.16, 0.17, 0.18, 0.20, 0.21, 0.22, 0.24, 0.25, 0.27, 0.28, 0.30, 0.32, 0.34, 0.36, 0.38, 0.40, 0.42, 0.44, 0.46, 0.48, 0.5, 0.53, 0.56, 0.59, 0.62, 0.65, 0.68, 0.71, 0.74, 0.77, 0.80, 0.83, 0.86, 0.89, 0.92, 0.95, 0.98, 1.0, 1.06, 1.12, 1.18, 1.24, 1.30, 1.36, 1.42, 1.48, 1.54, 1.60, 1.66, 1.72, 1.78, 1.84, 1.90, 1.96, 2.0, 2.12, 2.25, 2.37, 2.50, 2.62, 2.75, 2.87, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.3, 4.7, 4.9, 5.0, 5.5, 6.0, 6.5, 6.8, 7.0, 7.3, 7.5, 7.8, 8.0, 8.4, 8.7, 9.0, 9.4, 9.6, 9.8, 10.0];
  3716. ColorFilter.GRAY_MATRIX = [0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0, 0, 0, 1, 0];
  3717. ColorFilter.IDENTITY_MATRIX = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
  3718. ColorFilter.LENGTH = 25;
  3719. class DrawTextureCmd {
  3720. constructor() {
  3721. this.colorFlt = null;
  3722. this.uv = null;
  3723. }
  3724. static create(texture, x, y, width, height, matrix, alpha, color, blendMode, uv) {
  3725. var cmd = Pool.getItemByClass("DrawTextureCmd", DrawTextureCmd);
  3726. cmd.texture = texture;
  3727. texture._addReference();
  3728. cmd.x = x;
  3729. cmd.y = y;
  3730. cmd.width = width;
  3731. cmd.height = height;
  3732. cmd.matrix = matrix;
  3733. cmd.alpha = alpha;
  3734. cmd.color = color;
  3735. cmd.blendMode = blendMode;
  3736. cmd.uv = uv == undefined ? null : uv;
  3737. if (color) {
  3738. cmd.colorFlt = new ColorFilter();
  3739. cmd.colorFlt.setColor(color);
  3740. }
  3741. return cmd;
  3742. }
  3743. recover() {
  3744. this.texture && this.texture._removeReference();
  3745. this.texture = null;
  3746. this.matrix = null;
  3747. Pool.recover("DrawTextureCmd", this);
  3748. }
  3749. run(context, gx, gy) {
  3750. this.texture && context.drawTextureWithTransform(this.texture, this.x, this.y, this.width, this.height, this.matrix, gx, gy, this.alpha, this.blendMode, this.colorFlt, this.uv);
  3751. }
  3752. get cmdID() {
  3753. return DrawTextureCmd.ID;
  3754. }
  3755. }
  3756. DrawTextureCmd.ID = "DrawTexture";
  3757. class FillTextureCmd {
  3758. static create(texture, x, y, width, height, type, offset, other) {
  3759. var cmd = Pool.getItemByClass("FillTextureCmd", FillTextureCmd);
  3760. cmd.texture = texture;
  3761. cmd.x = x;
  3762. cmd.y = y;
  3763. cmd.width = width;
  3764. cmd.height = height;
  3765. cmd.type = type;
  3766. cmd.offset = offset;
  3767. cmd.other = other;
  3768. return cmd;
  3769. }
  3770. recover() {
  3771. this.texture = null;
  3772. this.offset = null;
  3773. this.other = null;
  3774. Pool.recover("FillTextureCmd", this);
  3775. }
  3776. run(context, gx, gy) {
  3777. context.fillTexture(this.texture, this.x + gx, this.y + gy, this.width, this.height, this.type, this.offset, this.other);
  3778. }
  3779. get cmdID() {
  3780. return FillTextureCmd.ID;
  3781. }
  3782. }
  3783. FillTextureCmd.ID = "FillTexture";
  3784. class RestoreCmd {
  3785. static create() {
  3786. var cmd = Pool.getItemByClass("RestoreCmd", RestoreCmd);
  3787. return cmd;
  3788. }
  3789. recover() {
  3790. Pool.recover("RestoreCmd", this);
  3791. }
  3792. run(context, gx, gy) {
  3793. context.restore();
  3794. }
  3795. get cmdID() {
  3796. return RestoreCmd.ID;
  3797. }
  3798. }
  3799. RestoreCmd.ID = "Restore";
  3800. class RotateCmd {
  3801. static create(angle, pivotX, pivotY) {
  3802. var cmd = Pool.getItemByClass("RotateCmd", RotateCmd);
  3803. cmd.angle = angle;
  3804. cmd.pivotX = pivotX;
  3805. cmd.pivotY = pivotY;
  3806. return cmd;
  3807. }
  3808. recover() {
  3809. Pool.recover("RotateCmd", this);
  3810. }
  3811. run(context, gx, gy) {
  3812. context._rotate(this.angle, this.pivotX + gx, this.pivotY + gy);
  3813. }
  3814. get cmdID() {
  3815. return RotateCmd.ID;
  3816. }
  3817. }
  3818. RotateCmd.ID = "Rotate";
  3819. class ScaleCmd {
  3820. static create(scaleX, scaleY, pivotX, pivotY) {
  3821. var cmd = Pool.getItemByClass("ScaleCmd", ScaleCmd);
  3822. cmd.scaleX = scaleX;
  3823. cmd.scaleY = scaleY;
  3824. cmd.pivotX = pivotX;
  3825. cmd.pivotY = pivotY;
  3826. return cmd;
  3827. }
  3828. recover() {
  3829. Pool.recover("ScaleCmd", this);
  3830. }
  3831. run(context, gx, gy) {
  3832. context._scale(this.scaleX, this.scaleY, this.pivotX + gx, this.pivotY + gy);
  3833. }
  3834. get cmdID() {
  3835. return ScaleCmd.ID;
  3836. }
  3837. }
  3838. ScaleCmd.ID = "Scale";
  3839. class TransformCmd {
  3840. static create(matrix, pivotX, pivotY) {
  3841. var cmd = Pool.getItemByClass("TransformCmd", TransformCmd);
  3842. cmd.matrix = matrix;
  3843. cmd.pivotX = pivotX;
  3844. cmd.pivotY = pivotY;
  3845. return cmd;
  3846. }
  3847. recover() {
  3848. this.matrix = null;
  3849. Pool.recover("TransformCmd", this);
  3850. }
  3851. run(context, gx, gy) {
  3852. context._transform(this.matrix, this.pivotX + gx, this.pivotY + gy);
  3853. }
  3854. get cmdID() {
  3855. return TransformCmd.ID;
  3856. }
  3857. }
  3858. TransformCmd.ID = "Transform";
  3859. class TranslateCmd {
  3860. static create(tx, ty) {
  3861. var cmd = Pool.getItemByClass("TranslateCmd", TranslateCmd);
  3862. cmd.tx = tx;
  3863. cmd.ty = ty;
  3864. return cmd;
  3865. }
  3866. recover() {
  3867. Pool.recover("TranslateCmd", this);
  3868. }
  3869. run(context, gx, gy) {
  3870. context.translate(this.tx, this.ty);
  3871. }
  3872. get cmdID() {
  3873. return TranslateCmd.ID;
  3874. }
  3875. }
  3876. TranslateCmd.ID = "Translate";
  3877. class Bezier {
  3878. constructor() {
  3879. this._controlPoints = [new Point(), new Point(), new Point()];
  3880. this._calFun = this.getPoint2;
  3881. }
  3882. _switchPoint(x, y) {
  3883. var tPoint = this._controlPoints.shift();
  3884. tPoint.setTo(x, y);
  3885. this._controlPoints.push(tPoint);
  3886. }
  3887. getPoint2(t, rst) {
  3888. var p1 = this._controlPoints[0];
  3889. var p2 = this._controlPoints[1];
  3890. var p3 = this._controlPoints[2];
  3891. var lineX = Math.pow((1 - t), 2) * p1.x + 2 * t * (1 - t) * p2.x + Math.pow(t, 2) * p3.x;
  3892. var lineY = Math.pow((1 - t), 2) * p1.y + 2 * t * (1 - t) * p2.y + Math.pow(t, 2) * p3.y;
  3893. rst.push(lineX, lineY);
  3894. }
  3895. getPoint3(t, rst) {
  3896. var p1 = this._controlPoints[0];
  3897. var p2 = this._controlPoints[1];
  3898. var p3 = this._controlPoints[2];
  3899. var p4 = this._controlPoints[3];
  3900. var lineX = Math.pow((1 - t), 3) * p1.x + 3 * p2.x * t * (1 - t) * (1 - t) + 3 * p3.x * t * t * (1 - t) + p4.x * Math.pow(t, 3);
  3901. var lineY = Math.pow((1 - t), 3) * p1.y + 3 * p2.y * t * (1 - t) * (1 - t) + 3 * p3.y * t * t * (1 - t) + p4.y * Math.pow(t, 3);
  3902. rst.push(lineX, lineY);
  3903. }
  3904. insertPoints(count, rst) {
  3905. var i;
  3906. count = count > 0 ? count : 5;
  3907. var dLen;
  3908. dLen = 1 / count;
  3909. for (i = 0; i <= 1; i += dLen) {
  3910. this._calFun(i, rst);
  3911. }
  3912. }
  3913. getBezierPoints(pList, inSertCount = 5, count = 2) {
  3914. var i, len;
  3915. len = pList.length;
  3916. if (len < (count + 1) * 2)
  3917. return [];
  3918. var rst = [];
  3919. switch (count) {
  3920. case 2:
  3921. this._calFun = this.getPoint2;
  3922. break;
  3923. case 3:
  3924. this._calFun = this.getPoint3;
  3925. break;
  3926. default:
  3927. return [];
  3928. }
  3929. while (this._controlPoints.length <= count) {
  3930. this._controlPoints.push(Point.create());
  3931. }
  3932. for (i = 0; i < count * 2; i += 2) {
  3933. this._switchPoint(pList[i], pList[i + 1]);
  3934. }
  3935. for (i = count * 2; i < len; i += 2) {
  3936. this._switchPoint(pList[i], pList[i + 1]);
  3937. if ((i / 2) % count == 0)
  3938. this.insertPoints(inSertCount, rst);
  3939. }
  3940. return rst;
  3941. }
  3942. }
  3943. Bezier.I = new Bezier();
  3944. class GrahamScan {
  3945. static multiply(p1, p2, p0) {
  3946. return ((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y));
  3947. }
  3948. static dis(p1, p2) {
  3949. return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
  3950. }
  3951. static _getPoints(count, tempUse = false, rst = null) {
  3952. if (!GrahamScan._mPointList)
  3953. GrahamScan._mPointList = [];
  3954. while (GrahamScan._mPointList.length < count)
  3955. GrahamScan._mPointList.push(new Point());
  3956. if (!rst)
  3957. rst = [];
  3958. rst.length = 0;
  3959. if (tempUse) {
  3960. GrahamScan.getFrom(rst, GrahamScan._mPointList, count);
  3961. }
  3962. else {
  3963. GrahamScan.getFromR(rst, GrahamScan._mPointList, count);
  3964. }
  3965. return rst;
  3966. }
  3967. static getFrom(rst, src, count) {
  3968. var i;
  3969. for (i = 0; i < count; i++) {
  3970. rst.push(src[i]);
  3971. }
  3972. return rst;
  3973. }
  3974. static getFromR(rst, src, count) {
  3975. var i;
  3976. for (i = 0; i < count; i++) {
  3977. rst.push(src.pop());
  3978. }
  3979. return rst;
  3980. }
  3981. static pListToPointList(pList, tempUse = false) {
  3982. var i, len = pList.length / 2, rst = GrahamScan._getPoints(len, tempUse, GrahamScan._tempPointList);
  3983. for (i = 0; i < len; i++) {
  3984. rst[i].setTo(pList[i + i], pList[i + i + 1]);
  3985. }
  3986. return rst;
  3987. }
  3988. static pointListToPlist(pointList) {
  3989. var i, len = pointList.length, rst = GrahamScan._temPList, tPoint;
  3990. rst.length = 0;
  3991. for (i = 0; i < len; i++) {
  3992. tPoint = pointList[i];
  3993. rst.push(tPoint.x, tPoint.y);
  3994. }
  3995. return rst;
  3996. }
  3997. static scanPList(pList) {
  3998. return Utils.copyArray(pList, GrahamScan.pointListToPlist(GrahamScan.scan(GrahamScan.pListToPointList(pList, true))));
  3999. }
  4000. static scan(PointSet) {
  4001. var i, j, k = 0, tmp, n = PointSet.length, ch;
  4002. var _tmpDic = {};
  4003. var key;
  4004. ch = GrahamScan._temArr;
  4005. ch.length = 0;
  4006. n = PointSet.length;
  4007. for (i = n - 1; i >= 0; i--) {
  4008. tmp = PointSet[i];
  4009. key = tmp.x + "_" + tmp.y;
  4010. if (!(key in _tmpDic)) {
  4011. _tmpDic[key] = true;
  4012. ch.push(tmp);
  4013. }
  4014. }
  4015. n = ch.length;
  4016. Utils.copyArray(PointSet, ch);
  4017. for (i = 1; i < n; i++)
  4018. if ((PointSet[i].y < PointSet[k].y) || ((PointSet[i].y == PointSet[k].y) && (PointSet[i].x < PointSet[k].x)))
  4019. k = i;
  4020. tmp = PointSet[0];
  4021. PointSet[0] = PointSet[k];
  4022. PointSet[k] = tmp;
  4023. for (i = 1; i < n - 1; i++) {
  4024. k = i;
  4025. for (j = i + 1; j < n; j++)
  4026. if ((GrahamScan.multiply(PointSet[j], PointSet[k], PointSet[0]) > 0) || ((GrahamScan.multiply(PointSet[j], PointSet[k], PointSet[0]) == 0) && (GrahamScan.dis(PointSet[0], PointSet[j]) < GrahamScan.dis(PointSet[0], PointSet[k]))))
  4027. k = j;
  4028. tmp = PointSet[i];
  4029. PointSet[i] = PointSet[k];
  4030. PointSet[k] = tmp;
  4031. }
  4032. ch = GrahamScan._temArr;
  4033. ch.length = 0;
  4034. if (PointSet.length < 3) {
  4035. return Utils.copyArray(ch, PointSet);
  4036. }
  4037. ch.push(PointSet[0], PointSet[1], PointSet[2]);
  4038. for (i = 3; i < n; i++) {
  4039. while (ch.length >= 2 && GrahamScan.multiply(PointSet[i], ch[ch.length - 1], ch[ch.length - 2]) >= 0)
  4040. ch.pop();
  4041. PointSet[i] && ch.push(PointSet[i]);
  4042. }
  4043. return ch;
  4044. }
  4045. }
  4046. GrahamScan._tempPointList = [];
  4047. GrahamScan._temPList = [];
  4048. GrahamScan._temArr = [];
  4049. class DrawStyle {
  4050. constructor(value) {
  4051. this.setValue(value);
  4052. }
  4053. static create(value) {
  4054. if (value) {
  4055. var color = (value instanceof ColorUtils) ? value : ColorUtils.create(value);
  4056. return color._drawStyle || (color._drawStyle = new DrawStyle(value));
  4057. }
  4058. return DrawStyle.DEFAULT;
  4059. }
  4060. setValue(value) {
  4061. if (value) {
  4062. this._color = (value instanceof ColorUtils) ? value : ColorUtils.create(value);
  4063. }
  4064. else
  4065. this._color = ColorUtils.create("#000000");
  4066. }
  4067. reset() {
  4068. this._color = ColorUtils.create("#000000");
  4069. }
  4070. toInt() {
  4071. return this._color.numColor;
  4072. }
  4073. equal(value) {
  4074. if (typeof (value) == 'string')
  4075. return this._color.strColor === value;
  4076. if (value instanceof ColorUtils)
  4077. return this._color.numColor === value.numColor;
  4078. return false;
  4079. }
  4080. toColorStr() {
  4081. return this._color.strColor;
  4082. }
  4083. }
  4084. DrawStyle.DEFAULT = new DrawStyle("#000000");
  4085. class Path {
  4086. constructor() {
  4087. this._lastOriX = 0;
  4088. this._lastOriY = 0;
  4089. this.paths = [];
  4090. this._curPath = null;
  4091. }
  4092. beginPath(convex) {
  4093. this.paths.length = 1;
  4094. this._curPath = this.paths[0] = new renderPath();
  4095. this._curPath.convex = convex;
  4096. }
  4097. closePath() {
  4098. this._curPath.loop = true;
  4099. }
  4100. newPath() {
  4101. this._curPath = new renderPath();
  4102. this.paths.push(this._curPath);
  4103. }
  4104. addPoint(pointX, pointY) {
  4105. this._curPath.path.push(pointX, pointY);
  4106. }
  4107. push(points, convex) {
  4108. if (!this._curPath) {
  4109. this._curPath = new renderPath();
  4110. this.paths.push(this._curPath);
  4111. }
  4112. else if (this._curPath.path.length > 0) {
  4113. this._curPath = new renderPath();
  4114. this.paths.push(this._curPath);
  4115. }
  4116. var rp = this._curPath;
  4117. rp.path = points.slice();
  4118. rp.convex = convex;
  4119. }
  4120. reset() {
  4121. this.paths.length = 0;
  4122. }
  4123. }
  4124. class renderPath {
  4125. constructor() {
  4126. this.path = [];
  4127. this.loop = false;
  4128. this.convex = false;
  4129. }
  4130. }
  4131. class SubmitBase {
  4132. constructor(renderType = SubmitBase.TYPE_2D) {
  4133. this.clipInfoID = -1;
  4134. this._mesh = null;
  4135. this._blendFn = null;
  4136. this._id = 0;
  4137. this._renderType = 0;
  4138. this._parent = null;
  4139. this._key = new SubmitKey();
  4140. this._startIdx = 0;
  4141. this._numEle = 0;
  4142. this._ref = 1;
  4143. this.shaderValue = null;
  4144. this._renderType = renderType;
  4145. this._id = ++SubmitBase.ID;
  4146. }
  4147. static __init__() {
  4148. var s = SubmitBase.RENDERBASE = new SubmitBase(-1);
  4149. s.shaderValue = new Value2D(0, 0);
  4150. s.shaderValue.ALPHA = 1;
  4151. s._ref = 0xFFFFFFFF;
  4152. }
  4153. getID() {
  4154. return this._id;
  4155. }
  4156. getRenderType() {
  4157. return this._renderType;
  4158. }
  4159. toString() {
  4160. return "ibindex:" + this._startIdx + " num:" + this._numEle + " key=" + this._key;
  4161. }
  4162. renderSubmit() { return 1; }
  4163. releaseRender() { }
  4164. }
  4165. SubmitBase.TYPE_2D = 10000;
  4166. SubmitBase.TYPE_CANVAS = 10003;
  4167. SubmitBase.TYPE_CMDSETRT = 10004;
  4168. SubmitBase.TYPE_CUSTOM = 10005;
  4169. SubmitBase.TYPE_BLURRT = 10006;
  4170. SubmitBase.TYPE_CMDDESTORYPRERT = 10007;
  4171. SubmitBase.TYPE_DISABLESTENCIL = 10008;
  4172. SubmitBase.TYPE_OTHERIBVB = 10009;
  4173. SubmitBase.TYPE_PRIMITIVE = 10010;
  4174. SubmitBase.TYPE_RT = 10011;
  4175. SubmitBase.TYPE_BLUR_RT = 10012;
  4176. SubmitBase.TYPE_TARGET = 10013;
  4177. SubmitBase.TYPE_CHANGE_VALUE = 10014;
  4178. SubmitBase.TYPE_SHAPE = 10015;
  4179. SubmitBase.TYPE_TEXTURE = 10016;
  4180. SubmitBase.TYPE_FILLTEXTURE = 10017;
  4181. SubmitBase.KEY_ONCE = -1;
  4182. SubmitBase.KEY_FILLRECT = 1;
  4183. SubmitBase.KEY_DRAWTEXTURE = 2;
  4184. SubmitBase.KEY_VG = 3;
  4185. SubmitBase.KEY_TRIANGLES = 4;
  4186. SubmitBase.ID = 1;
  4187. SubmitBase.preRender = null;
  4188. class SaveBase {
  4189. constructor() {
  4190. }
  4191. static _createArray() {
  4192. var value = [];
  4193. value._length = 0;
  4194. return value;
  4195. }
  4196. static _init() {
  4197. var namemap = SaveBase._namemap = {};
  4198. namemap[SaveBase.TYPE_ALPHA] = "ALPHA";
  4199. namemap[SaveBase.TYPE_FILESTYLE] = "fillStyle";
  4200. namemap[SaveBase.TYPE_FONT] = "font";
  4201. namemap[SaveBase.TYPE_LINEWIDTH] = "lineWidth";
  4202. namemap[SaveBase.TYPE_STROKESTYLE] = "strokeStyle";
  4203. namemap[SaveBase.TYPE_ENABLEMERGE] = "_mergeID";
  4204. namemap[SaveBase.TYPE_MARK] = namemap[SaveBase.TYPE_TRANSFORM] = namemap[SaveBase.TYPE_TRANSLATE] = [];
  4205. namemap[SaveBase.TYPE_TEXTBASELINE] = "textBaseline";
  4206. namemap[SaveBase.TYPE_TEXTALIGN] = "textAlign";
  4207. namemap[SaveBase.TYPE_GLOBALCOMPOSITEOPERATION] = "_nBlendType";
  4208. namemap[SaveBase.TYPE_SHADER] = "shader";
  4209. namemap[SaveBase.TYPE_FILTERS] = "filters";
  4210. namemap[SaveBase.TYPE_COLORFILTER] = '_colorFiler';
  4211. return namemap;
  4212. }
  4213. isSaveMark() { return false; }
  4214. restore(context) {
  4215. this._dataObj[this._valueName] = this._value;
  4216. SaveBase.POOL[SaveBase.POOL._length++] = this;
  4217. this._newSubmit && (context._curSubmit = SubmitBase.RENDERBASE);
  4218. }
  4219. static save(context, type, dataObj, newSubmit) {
  4220. if ((context._saveMark._saveuse & type) !== type) {
  4221. context._saveMark._saveuse |= type;
  4222. var cache = SaveBase.POOL;
  4223. var o = cache._length > 0 ? cache[--cache._length] : (new SaveBase());
  4224. o._value = dataObj[o._valueName = SaveBase._namemap[type]];
  4225. o._dataObj = dataObj;
  4226. o._newSubmit = newSubmit;
  4227. var _save = context._save;
  4228. _save[_save._length++] = o;
  4229. }
  4230. }
  4231. }
  4232. SaveBase.TYPE_ALPHA = 0x1;
  4233. SaveBase.TYPE_FILESTYLE = 0x2;
  4234. SaveBase.TYPE_FONT = 0x8;
  4235. SaveBase.TYPE_LINEWIDTH = 0x100;
  4236. SaveBase.TYPE_STROKESTYLE = 0x200;
  4237. SaveBase.TYPE_MARK = 0x400;
  4238. SaveBase.TYPE_TRANSFORM = 0x800;
  4239. SaveBase.TYPE_TRANSLATE = 0x1000;
  4240. SaveBase.TYPE_ENABLEMERGE = 0x2000;
  4241. SaveBase.TYPE_TEXTBASELINE = 0x4000;
  4242. SaveBase.TYPE_TEXTALIGN = 0x8000;
  4243. SaveBase.TYPE_GLOBALCOMPOSITEOPERATION = 0x10000;
  4244. SaveBase.TYPE_CLIPRECT = 0x20000;
  4245. SaveBase.TYPE_CLIPRECT_STENCIL = 0x40000;
  4246. SaveBase.TYPE_IBVB = 0x80000;
  4247. SaveBase.TYPE_SHADER = 0x100000;
  4248. SaveBase.TYPE_FILTERS = 0x200000;
  4249. SaveBase.TYPE_FILTERS_TYPE = 0x400000;
  4250. SaveBase.TYPE_COLORFILTER = 0x800000;
  4251. SaveBase.POOL = SaveBase._createArray();
  4252. SaveBase._namemap = SaveBase._init();
  4253. class SaveClipRect {
  4254. constructor() {
  4255. this._globalClipMatrix = new Matrix();
  4256. this._clipInfoID = -1;
  4257. this._clipRect = new Rectangle();
  4258. this.incache = false;
  4259. }
  4260. isSaveMark() { return false; }
  4261. restore(context) {
  4262. this._globalClipMatrix.copyTo(context._globalClipMatrix);
  4263. this._clipRect.clone(context._clipRect);
  4264. context._clipInfoID = this._clipInfoID;
  4265. SaveClipRect.POOL[SaveClipRect.POOL._length++] = this;
  4266. context._clipInCache = this.incache;
  4267. }
  4268. static save(context) {
  4269. if ((context._saveMark._saveuse & SaveBase.TYPE_CLIPRECT) == SaveBase.TYPE_CLIPRECT)
  4270. return;
  4271. context._saveMark._saveuse |= SaveBase.TYPE_CLIPRECT;
  4272. var cache = SaveClipRect.POOL;
  4273. var o = cache._length > 0 ? cache[--cache._length] : (new SaveClipRect());
  4274. context._globalClipMatrix.copyTo(o._globalClipMatrix);
  4275. context._clipRect.clone(o._clipRect);
  4276. o._clipInfoID = context._clipInfoID;
  4277. o.incache = context._clipInCache;
  4278. var _save = context._save;
  4279. _save[_save._length++] = o;
  4280. }
  4281. }
  4282. SaveClipRect.POOL = SaveBase._createArray();
  4283. class SaveMark {
  4284. constructor() {
  4285. this._saveuse = 0;
  4286. }
  4287. isSaveMark() {
  4288. return true;
  4289. }
  4290. restore(context) {
  4291. context._saveMark = this._preSaveMark;
  4292. SaveMark.POOL[SaveMark.POOL._length++] = this;
  4293. }
  4294. static Create(context) {
  4295. var no = SaveMark.POOL;
  4296. var o = no._length > 0 ? no[--no._length] : (new SaveMark());
  4297. o._saveuse = 0;
  4298. o._preSaveMark = context._saveMark;
  4299. context._saveMark = o;
  4300. return o;
  4301. }
  4302. }
  4303. SaveMark.POOL = SaveBase._createArray();
  4304. class SaveTransform {
  4305. constructor() {
  4306. this._matrix = new Matrix();
  4307. }
  4308. isSaveMark() { return false; }
  4309. restore(context) {
  4310. context._curMat = this._savematrix;
  4311. SaveTransform.POOL[SaveTransform.POOL._length++] = this;
  4312. }
  4313. static save(context) {
  4314. var _saveMark = context._saveMark;
  4315. if ((_saveMark._saveuse & SaveBase.TYPE_TRANSFORM) === SaveBase.TYPE_TRANSFORM)
  4316. return;
  4317. _saveMark._saveuse |= SaveBase.TYPE_TRANSFORM;
  4318. var no = SaveTransform.POOL;
  4319. var o = no._length > 0 ? no[--no._length] : (new SaveTransform());
  4320. o._savematrix = context._curMat;
  4321. context._curMat = context._curMat.copyTo(o._matrix);
  4322. var _save = context._save;
  4323. _save[_save._length++] = o;
  4324. }
  4325. }
  4326. SaveTransform.POOL = SaveBase._createArray();
  4327. class SaveTranslate {
  4328. constructor() {
  4329. this._mat = new Matrix();
  4330. }
  4331. isSaveMark() { return false; }
  4332. restore(context) {
  4333. this._mat.copyTo(context._curMat);
  4334. SaveTranslate.POOL[SaveTranslate.POOL._length++] = this;
  4335. }
  4336. static save(context) {
  4337. var no = SaveTranslate.POOL;
  4338. var o = no._length > 0 ? no[--no._length] : (new SaveTranslate());
  4339. context._curMat.copyTo(o._mat);
  4340. var _save = context._save;
  4341. _save[_save._length++] = o;
  4342. }
  4343. }
  4344. SaveTranslate.POOL = SaveBase._createArray();
  4345. class BufferStateBase {
  4346. constructor() {
  4347. this._nativeVertexArrayObject = LayaGL.layaGPUInstance.createVertexArray();
  4348. }
  4349. bind() {
  4350. if (BufferStateBase._curBindedBufferState !== this) {
  4351. LayaGL.layaGPUInstance.bindVertexArray(this._nativeVertexArrayObject);
  4352. BufferStateBase._curBindedBufferState = this;
  4353. }
  4354. }
  4355. unBind() {
  4356. if (BufferStateBase._curBindedBufferState === this) {
  4357. LayaGL.layaGPUInstance.bindVertexArray(null);
  4358. BufferStateBase._curBindedBufferState = null;
  4359. }
  4360. else {
  4361. throw "BufferState: must call bind() function first.";
  4362. }
  4363. }
  4364. destroy() {
  4365. LayaGL.layaGPUInstance.deleteVertexArray(this._nativeVertexArrayObject);
  4366. }
  4367. bindForNative() {
  4368. LayaGL.instance.bindVertexArray(this._nativeVertexArrayObject);
  4369. BufferStateBase._curBindedBufferState = this;
  4370. }
  4371. unBindForNative() {
  4372. LayaGL.instance.bindVertexArray(null);
  4373. BufferStateBase._curBindedBufferState = null;
  4374. }
  4375. }
  4376. class BufferState2D extends BufferStateBase {
  4377. constructor() {
  4378. super();
  4379. }
  4380. }
  4381. class Buffer {
  4382. constructor() {
  4383. this._byteLength = 0;
  4384. this._glBuffer = LayaGL.instance.createBuffer();
  4385. }
  4386. get bufferUsage() {
  4387. return this._bufferUsage;
  4388. }
  4389. _bindForVAO() {
  4390. }
  4391. bind() {
  4392. return false;
  4393. }
  4394. destroy() {
  4395. if (this._glBuffer) {
  4396. LayaGL.instance.deleteBuffer(this._glBuffer);
  4397. this._glBuffer = null;
  4398. }
  4399. }
  4400. }
  4401. class RenderInfo {
  4402. }
  4403. RenderInfo.loopStTm = 0;
  4404. RenderInfo.loopCount = 0;
  4405. class Buffer2D extends Buffer {
  4406. constructor() {
  4407. super();
  4408. this._maxsize = 0;
  4409. this._upload = true;
  4410. this._uploadSize = 0;
  4411. this._bufferSize = 0;
  4412. this._u8Array = null;
  4413. }
  4414. static __int__(gl) {
  4415. }
  4416. get bufferLength() {
  4417. return this._buffer.byteLength;
  4418. }
  4419. set byteLength(value) {
  4420. this.setByteLength(value);
  4421. }
  4422. setByteLength(value) {
  4423. if (this._byteLength !== value) {
  4424. value <= this._bufferSize || (this._resizeBuffer(value * 2 + 256, true));
  4425. this._byteLength = value;
  4426. }
  4427. }
  4428. needSize(sz) {
  4429. var old = this._byteLength;
  4430. if (sz) {
  4431. var needsz = this._byteLength + sz;
  4432. needsz <= this._bufferSize || (this._resizeBuffer(needsz << 1, true));
  4433. this._byteLength = needsz;
  4434. }
  4435. return old;
  4436. }
  4437. _bufferData() {
  4438. this._maxsize = Math.max(this._maxsize, this._byteLength);
  4439. if (RenderInfo.loopCount % 30 == 0) {
  4440. if (this._buffer.byteLength > (this._maxsize + 64)) {
  4441. this._buffer = this._buffer.slice(0, this._maxsize + 64);
  4442. this._bufferSize = this._buffer.byteLength;
  4443. this._checkArrayUse();
  4444. }
  4445. this._maxsize = this._byteLength;
  4446. }
  4447. if (this._uploadSize < this._buffer.byteLength) {
  4448. this._uploadSize = this._buffer.byteLength;
  4449. LayaGL.instance.bufferData(this._bufferType, this._uploadSize, this._bufferUsage);
  4450. }
  4451. LayaGL.instance.bufferSubData(this._bufferType, 0, new Uint8Array(this._buffer, 0, this._byteLength));
  4452. }
  4453. _bufferSubData(offset = 0, dataStart = 0, dataLength = 0) {
  4454. this._maxsize = Math.max(this._maxsize, this._byteLength);
  4455. if (RenderInfo.loopCount % 30 == 0) {
  4456. if (this._buffer.byteLength > (this._maxsize + 64)) {
  4457. this._buffer = this._buffer.slice(0, this._maxsize + 64);
  4458. this._bufferSize = this._buffer.byteLength;
  4459. this._checkArrayUse();
  4460. }
  4461. this._maxsize = this._byteLength;
  4462. }
  4463. if (this._uploadSize < this._buffer.byteLength) {
  4464. this._uploadSize = this._buffer.byteLength;
  4465. LayaGL.instance.bufferData(this._bufferType, this._uploadSize, this._bufferUsage);
  4466. }
  4467. if (dataStart || dataLength) {
  4468. var subBuffer = this._buffer.slice(dataStart, dataLength);
  4469. LayaGL.instance.bufferSubData(this._bufferType, offset, subBuffer);
  4470. }
  4471. else {
  4472. LayaGL.instance.bufferSubData(this._bufferType, offset, this._buffer);
  4473. }
  4474. }
  4475. _checkArrayUse() {
  4476. }
  4477. _bind_uploadForVAO() {
  4478. if (!this._upload)
  4479. return false;
  4480. this._upload = false;
  4481. this._bindForVAO();
  4482. this._bufferData();
  4483. return true;
  4484. }
  4485. _bind_upload() {
  4486. if (!this._upload)
  4487. return false;
  4488. this._upload = false;
  4489. this.bind();
  4490. this._bufferData();
  4491. return true;
  4492. }
  4493. _bind_subUpload(offset = 0, dataStart = 0, dataLength = 0) {
  4494. if (!this._upload)
  4495. return false;
  4496. this._upload = false;
  4497. this.bind();
  4498. this._bufferSubData(offset, dataStart, dataLength);
  4499. return true;
  4500. }
  4501. _resizeBuffer(nsz, copy) {
  4502. var buff = this._buffer;
  4503. if (nsz <= buff.byteLength)
  4504. return this;
  4505. var u8buf = this._u8Array;
  4506. if (copy && buff && buff.byteLength > 0) {
  4507. var newbuffer = new ArrayBuffer(nsz);
  4508. var oldU8Arr = (u8buf && u8buf.buffer == buff) ? u8buf : new Uint8Array(buff);
  4509. u8buf = this._u8Array = new Uint8Array(newbuffer);
  4510. u8buf.set(oldU8Arr, 0);
  4511. buff = this._buffer = newbuffer;
  4512. }
  4513. else {
  4514. buff = this._buffer = new ArrayBuffer(nsz);
  4515. this._u8Array = null;
  4516. }
  4517. this._checkArrayUse();
  4518. this._upload = true;
  4519. this._bufferSize = buff.byteLength;
  4520. return this;
  4521. }
  4522. append(data) {
  4523. this._upload = true;
  4524. var byteLen, n;
  4525. byteLen = data.byteLength;
  4526. if (data instanceof Uint8Array) {
  4527. this._resizeBuffer(this._byteLength + byteLen, true);
  4528. n = new Uint8Array(this._buffer, this._byteLength);
  4529. }
  4530. else if (data instanceof Uint16Array) {
  4531. this._resizeBuffer(this._byteLength + byteLen, true);
  4532. n = new Uint16Array(this._buffer, this._byteLength);
  4533. }
  4534. else if (data instanceof Float32Array) {
  4535. this._resizeBuffer(this._byteLength + byteLen, true);
  4536. n = new Float32Array(this._buffer, this._byteLength);
  4537. }
  4538. n.set(data, 0);
  4539. this._byteLength += byteLen;
  4540. this._checkArrayUse();
  4541. }
  4542. appendU16Array(data, len) {
  4543. this._resizeBuffer(this._byteLength + len * 2, true);
  4544. var u = new Uint16Array(this._buffer, this._byteLength, len);
  4545. if (len == 6) {
  4546. u[0] = data[0];
  4547. u[1] = data[1];
  4548. u[2] = data[2];
  4549. u[3] = data[3];
  4550. u[4] = data[4];
  4551. u[5] = data[5];
  4552. }
  4553. else if (len >= 100) {
  4554. u.set(new Uint16Array(data.buffer, 0, len));
  4555. }
  4556. else {
  4557. for (var i = 0; i < len; i++) {
  4558. u[i] = data[i];
  4559. }
  4560. }
  4561. this._byteLength += len * 2;
  4562. this._checkArrayUse();
  4563. }
  4564. appendEx(data, type) {
  4565. this._upload = true;
  4566. var byteLen, n;
  4567. byteLen = data.byteLength;
  4568. this._resizeBuffer(this._byteLength + byteLen, true);
  4569. n = new type(this._buffer, this._byteLength);
  4570. n.set(data, 0);
  4571. this._byteLength += byteLen;
  4572. this._checkArrayUse();
  4573. }
  4574. appendEx2(data, type, dataLen, perDataLen = 1) {
  4575. this._upload = true;
  4576. var byteLen, n;
  4577. byteLen = dataLen * perDataLen;
  4578. this._resizeBuffer(this._byteLength + byteLen, true);
  4579. n = new type(this._buffer, this._byteLength);
  4580. var i;
  4581. for (i = 0; i < dataLen; i++) {
  4582. n[i] = data[i];
  4583. }
  4584. this._byteLength += byteLen;
  4585. this._checkArrayUse();
  4586. }
  4587. getBuffer() {
  4588. return this._buffer;
  4589. }
  4590. setNeedUpload() {
  4591. this._upload = true;
  4592. }
  4593. getNeedUpload() {
  4594. return this._upload;
  4595. }
  4596. upload() {
  4597. var gl = LayaGL.instance;
  4598. var scuess = this._bind_upload();
  4599. gl.bindBuffer(this._bufferType, null);
  4600. if (this._bufferType == gl.ARRAY_BUFFER)
  4601. Buffer._bindedVertexBuffer = null;
  4602. if (this._bufferType == gl.ELEMENT_ARRAY_BUFFER)
  4603. Buffer._bindedIndexBuffer = null;
  4604. BaseShader.activeShader = null;
  4605. return scuess;
  4606. }
  4607. subUpload(offset = 0, dataStart = 0, dataLength = 0) {
  4608. var gl = LayaGL.instance;
  4609. var scuess = this._bind_subUpload();
  4610. gl.bindBuffer(this._bufferType, null);
  4611. if (this._bufferType == gl.ARRAY_BUFFER)
  4612. Buffer._bindedVertexBuffer = null;
  4613. if (this._bufferType == gl.ELEMENT_ARRAY_BUFFER)
  4614. Buffer._bindedIndexBuffer = null;
  4615. BaseShader.activeShader = null;
  4616. return scuess;
  4617. }
  4618. _disposeResource() {
  4619. this._upload = true;
  4620. this._uploadSize = 0;
  4621. }
  4622. clear() {
  4623. this._byteLength = 0;
  4624. this._upload = true;
  4625. }
  4626. }
  4627. Buffer2D.FLOAT32 = 4;
  4628. Buffer2D.SHORT = 2;
  4629. class IndexBuffer2D extends Buffer2D {
  4630. constructor(bufferUsage = 0x88e4) {
  4631. super();
  4632. this._bufferUsage = bufferUsage;
  4633. this._bufferType = LayaGL.instance.ELEMENT_ARRAY_BUFFER;
  4634. this._buffer = new ArrayBuffer(8);
  4635. }
  4636. _checkArrayUse() {
  4637. this._uint16Array && (this._uint16Array = new Uint16Array(this._buffer));
  4638. }
  4639. getUint16Array() {
  4640. return this._uint16Array || (this._uint16Array = new Uint16Array(this._buffer));
  4641. }
  4642. _bindForVAO() {
  4643. var gl = LayaGL.instance;
  4644. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  4645. }
  4646. bind() {
  4647. if (Buffer._bindedIndexBuffer !== this._glBuffer) {
  4648. var gl = LayaGL.instance;
  4649. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  4650. Buffer._bindedIndexBuffer = this._glBuffer;
  4651. return true;
  4652. }
  4653. return false;
  4654. }
  4655. destory() {
  4656. this._uint16Array = null;
  4657. this._buffer = null;
  4658. }
  4659. disposeResource() {
  4660. this._disposeResource();
  4661. }
  4662. }
  4663. IndexBuffer2D.create = function (bufferUsage = 0x88e4) {
  4664. return new IndexBuffer2D(bufferUsage);
  4665. };
  4666. class VertexBuffer2D extends Buffer2D {
  4667. constructor(vertexStride, bufferUsage) {
  4668. super();
  4669. this._vertexStride = vertexStride;
  4670. this._bufferUsage = bufferUsage;
  4671. this._bufferType = LayaGL.instance.ARRAY_BUFFER;
  4672. this._buffer = new ArrayBuffer(8);
  4673. this._floatArray32 = new Float32Array(this._buffer);
  4674. this._uint32Array = new Uint32Array(this._buffer);
  4675. }
  4676. get vertexStride() {
  4677. return this._vertexStride;
  4678. }
  4679. getFloat32Array() {
  4680. return this._floatArray32;
  4681. }
  4682. appendArray(data) {
  4683. var oldoff = this._byteLength >> 2;
  4684. this.setByteLength(this._byteLength + data.length * 4);
  4685. var vbdata = this.getFloat32Array();
  4686. vbdata.set(data, oldoff);
  4687. this._upload = true;
  4688. }
  4689. _checkArrayUse() {
  4690. this._floatArray32 && (this._floatArray32 = new Float32Array(this._buffer));
  4691. this._uint32Array && (this._uint32Array = new Uint32Array(this._buffer));
  4692. }
  4693. deleteBuffer() {
  4694. super._disposeResource();
  4695. }
  4696. _bindForVAO() {
  4697. var gl = LayaGL.instance;
  4698. gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
  4699. }
  4700. bind() {
  4701. if (Buffer._bindedVertexBuffer !== this._glBuffer) {
  4702. var gl = LayaGL.instance;
  4703. gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
  4704. Buffer._bindedVertexBuffer = this._glBuffer;
  4705. return true;
  4706. }
  4707. return false;
  4708. }
  4709. destroy() {
  4710. super.destroy();
  4711. this._byteLength = 0;
  4712. this._upload = true;
  4713. this._buffer = null;
  4714. this._floatArray32 = null;
  4715. }
  4716. }
  4717. VertexBuffer2D.create = function (vertexStride, bufferUsage = 0x88e8) {
  4718. return new VertexBuffer2D(vertexStride, bufferUsage);
  4719. };
  4720. class Mesh2D {
  4721. constructor(stride, vballoc, iballoc) {
  4722. this._stride = 0;
  4723. this.vertNum = 0;
  4724. this.indexNum = 0;
  4725. this._applied = false;
  4726. this._quadNum = 0;
  4727. this.canReuse = false;
  4728. this._stride = stride;
  4729. this._vb = new VertexBuffer2D(stride, LayaGL.instance.DYNAMIC_DRAW);
  4730. if (vballoc) {
  4731. this._vb._resizeBuffer(vballoc, false);
  4732. }
  4733. else {
  4734. Config.webGL2D_MeshAllocMaxMem && this._vb._resizeBuffer(64 * 1024 * stride, false);
  4735. }
  4736. this._ib = new IndexBuffer2D();
  4737. if (iballoc) {
  4738. this._ib._resizeBuffer(iballoc, false);
  4739. }
  4740. }
  4741. cloneWithNewVB() {
  4742. var mesh = new Mesh2D(this._stride, 0, 0);
  4743. mesh._ib = this._ib;
  4744. mesh._quadNum = this._quadNum;
  4745. mesh._attribInfo = this._attribInfo;
  4746. return mesh;
  4747. }
  4748. cloneWithNewVBIB() {
  4749. var mesh = new Mesh2D(this._stride, 0, 0);
  4750. mesh._attribInfo = this._attribInfo;
  4751. return mesh;
  4752. }
  4753. getVBW() {
  4754. this._vb.setNeedUpload();
  4755. return this._vb;
  4756. }
  4757. getVBR() {
  4758. return this._vb;
  4759. }
  4760. getIBR() {
  4761. return this._ib;
  4762. }
  4763. getIBW() {
  4764. this._ib.setNeedUpload();
  4765. return this._ib;
  4766. }
  4767. createQuadIB(QuadNum) {
  4768. this._quadNum = QuadNum;
  4769. this._ib._resizeBuffer(QuadNum * 6 * 2, false);
  4770. this._ib.byteLength = this._ib.bufferLength;
  4771. var bd = this._ib.getUint16Array();
  4772. var idx = 0;
  4773. var curvert = 0;
  4774. for (var i = 0; i < QuadNum; i++) {
  4775. bd[idx++] = curvert;
  4776. bd[idx++] = curvert + 2;
  4777. bd[idx++] = curvert + 1;
  4778. bd[idx++] = curvert;
  4779. bd[idx++] = curvert + 3;
  4780. bd[idx++] = curvert + 2;
  4781. curvert += 4;
  4782. }
  4783. this._ib.setNeedUpload();
  4784. }
  4785. setAttributes(attribs) {
  4786. this._attribInfo = attribs;
  4787. if (this._attribInfo.length % 3 != 0) {
  4788. throw 'Mesh2D setAttributes error!';
  4789. }
  4790. }
  4791. configVAO(gl) {
  4792. if (this._applied)
  4793. return;
  4794. this._applied = true;
  4795. if (!this._vao) {
  4796. this._vao = new BufferState2D();
  4797. }
  4798. this._vao.bind();
  4799. this._vb._bindForVAO();
  4800. this._ib.setNeedUpload();
  4801. this._ib._bind_uploadForVAO();
  4802. var attribNum = this._attribInfo.length / 3;
  4803. var idx = 0;
  4804. for (var i = 0; i < attribNum; i++) {
  4805. var _size = this._attribInfo[idx + 1];
  4806. var _type = this._attribInfo[idx];
  4807. var _off = this._attribInfo[idx + 2];
  4808. gl.enableVertexAttribArray(i);
  4809. gl.vertexAttribPointer(i, _size, _type, false, this._stride, _off);
  4810. idx += 3;
  4811. }
  4812. this._vao.unBind();
  4813. }
  4814. useMesh(gl) {
  4815. this._applied || this.configVAO(gl);
  4816. this._vao.bind();
  4817. this._vb.bind();
  4818. this._ib._bind_upload() || this._ib.bind();
  4819. this._vb._bind_upload() || this._vb.bind();
  4820. }
  4821. getEleNum() {
  4822. return this._ib.getBuffer().byteLength / 2;
  4823. }
  4824. releaseMesh() { }
  4825. destroy() {
  4826. }
  4827. clearVB() {
  4828. this._vb.clear();
  4829. }
  4830. }
  4831. Mesh2D._gvaoid = 0;
  4832. class MeshQuadTexture extends Mesh2D {
  4833. constructor() {
  4834. super(MeshQuadTexture.const_stride, 4, 4);
  4835. this.canReuse = true;
  4836. this.setAttributes(MeshQuadTexture._fixattriInfo);
  4837. if (!MeshQuadTexture._fixib) {
  4838. this.createQuadIB(MeshQuadTexture._maxIB);
  4839. MeshQuadTexture._fixib = this._ib;
  4840. }
  4841. else {
  4842. this._ib = MeshQuadTexture._fixib;
  4843. this._quadNum = MeshQuadTexture._maxIB;
  4844. }
  4845. }
  4846. static __int__() {
  4847. MeshQuadTexture._fixattriInfo = [5126, 4, 0,
  4848. 5121, 4, 16,
  4849. 5121, 4, 20];
  4850. }
  4851. static getAMesh(mainctx) {
  4852. var ret = null;
  4853. if (MeshQuadTexture._POOL.length) {
  4854. ret = MeshQuadTexture._POOL.pop();
  4855. }
  4856. else
  4857. ret = new MeshQuadTexture();
  4858. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshQuadTexture.const_stride, false);
  4859. return ret;
  4860. }
  4861. releaseMesh() {
  4862. this._vb.setByteLength(0);
  4863. this.vertNum = 0;
  4864. this.indexNum = 0;
  4865. MeshQuadTexture._POOL.push(this);
  4866. }
  4867. destroy() {
  4868. this._vb.destroy();
  4869. this._vb.deleteBuffer();
  4870. }
  4871. addQuad(pos, uv, color, useTex) {
  4872. var vb = this._vb;
  4873. var vpos = (vb._byteLength >> 2);
  4874. vb.setByteLength((vpos + MeshQuadTexture.const_stride) << 2);
  4875. var vbdata = vb._floatArray32 || vb.getFloat32Array();
  4876. var vbu32Arr = vb._uint32Array;
  4877. var cpos = vpos;
  4878. var useTexVal = useTex ? 0xff : 0;
  4879. vbdata[cpos++] = pos[0];
  4880. vbdata[cpos++] = pos[1];
  4881. vbdata[cpos++] = uv[0];
  4882. vbdata[cpos++] = uv[1];
  4883. vbu32Arr[cpos++] = color;
  4884. vbu32Arr[cpos++] = useTexVal;
  4885. vbdata[cpos++] = pos[2];
  4886. vbdata[cpos++] = pos[3];
  4887. vbdata[cpos++] = uv[2];
  4888. vbdata[cpos++] = uv[3];
  4889. vbu32Arr[cpos++] = color;
  4890. vbu32Arr[cpos++] = useTexVal;
  4891. vbdata[cpos++] = pos[4];
  4892. vbdata[cpos++] = pos[5];
  4893. vbdata[cpos++] = uv[4];
  4894. vbdata[cpos++] = uv[5];
  4895. vbu32Arr[cpos++] = color;
  4896. vbu32Arr[cpos++] = useTexVal;
  4897. vbdata[cpos++] = pos[6];
  4898. vbdata[cpos++] = pos[7];
  4899. vbdata[cpos++] = uv[6];
  4900. vbdata[cpos++] = uv[7];
  4901. vbu32Arr[cpos++] = color;
  4902. vbu32Arr[cpos++] = useTexVal;
  4903. vb._upload = true;
  4904. }
  4905. }
  4906. MeshQuadTexture.const_stride = 24;
  4907. MeshQuadTexture._maxIB = 16 * 1024;
  4908. MeshQuadTexture._POOL = [];
  4909. class MeshTexture extends Mesh2D {
  4910. constructor() {
  4911. super(MeshTexture.const_stride, 4, 4);
  4912. this.canReuse = true;
  4913. this.setAttributes(MeshTexture._fixattriInfo);
  4914. }
  4915. static __init__() {
  4916. MeshTexture._fixattriInfo = [5126, 4, 0,
  4917. 5121, 4, 16,
  4918. 5121, 4, 20];
  4919. }
  4920. static getAMesh(mainctx) {
  4921. var ret;
  4922. if (MeshTexture._POOL.length) {
  4923. ret = MeshTexture._POOL.pop();
  4924. }
  4925. else
  4926. ret = new MeshTexture();
  4927. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshTexture.const_stride, false);
  4928. return ret;
  4929. }
  4930. addData(vertices, uvs, idx, matrix, rgba) {
  4931. var vb = this._vb;
  4932. var ib = this._ib;
  4933. var vertsz = vertices.length >> 1;
  4934. var startpos = vb.needSize(vertsz * MeshTexture.const_stride);
  4935. var f32pos = startpos >> 2;
  4936. var vbdata = vb._floatArray32 || vb.getFloat32Array();
  4937. var vbu32Arr = vb._uint32Array;
  4938. var ci = 0;
  4939. var m00 = matrix.a;
  4940. var m01 = matrix.b;
  4941. var m10 = matrix.c;
  4942. var m11 = matrix.d;
  4943. var tx = matrix.tx;
  4944. var ty = matrix.ty;
  4945. var i = 0;
  4946. for (i = 0; i < vertsz; i++) {
  4947. var x = vertices[ci], y = vertices[ci + 1];
  4948. vbdata[f32pos] = x * m00 + y * m10 + tx;
  4949. vbdata[f32pos + 1] = x * m01 + y * m11 + ty;
  4950. vbdata[f32pos + 2] = uvs[ci];
  4951. vbdata[f32pos + 3] = uvs[ci + 1];
  4952. vbu32Arr[f32pos + 4] = rgba;
  4953. vbu32Arr[f32pos + 5] = 0xff;
  4954. f32pos += 6;
  4955. ci += 2;
  4956. }
  4957. vb.setNeedUpload();
  4958. var vertN = this.vertNum;
  4959. var sz = idx.length;
  4960. var stib = ib.needSize(idx.byteLength);
  4961. var cidx = ib.getUint16Array();
  4962. var stibid = stib >> 1;
  4963. if (vertN > 0) {
  4964. var end = stibid + sz;
  4965. var si = 0;
  4966. for (i = stibid; i < end; i++, si++) {
  4967. cidx[i] = idx[si] + vertN;
  4968. }
  4969. }
  4970. else {
  4971. cidx.set(idx, stibid);
  4972. }
  4973. ib.setNeedUpload();
  4974. this.vertNum += vertsz;
  4975. this.indexNum += idx.length;
  4976. }
  4977. releaseMesh() {
  4978. this._vb.setByteLength(0);
  4979. this._ib.setByteLength(0);
  4980. this.vertNum = 0;
  4981. this.indexNum = 0;
  4982. MeshTexture._POOL.push(this);
  4983. }
  4984. destroy() {
  4985. this._ib.destroy();
  4986. this._vb.destroy();
  4987. this._ib.disposeResource();
  4988. this._vb.deleteBuffer();
  4989. }
  4990. }
  4991. MeshTexture.const_stride = 24;
  4992. MeshTexture._POOL = [];
  4993. class MeshVG extends Mesh2D {
  4994. constructor() {
  4995. super(MeshVG.const_stride, 4, 4);
  4996. this.canReuse = true;
  4997. this.setAttributes(MeshVG._fixattriInfo);
  4998. }
  4999. static __init__() {
  5000. MeshVG._fixattriInfo = [5126, 2, 0,
  5001. 5121, 4, 8];
  5002. }
  5003. static getAMesh(mainctx) {
  5004. var ret;
  5005. if (MeshVG._POOL.length) {
  5006. ret = MeshVG._POOL.pop();
  5007. }
  5008. else
  5009. ret = new MeshVG();
  5010. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshVG.const_stride, false);
  5011. return ret;
  5012. }
  5013. addVertAndIBToMesh(ctx, points, rgba, ib) {
  5014. var startpos = this._vb.needSize(points.length / 2 * MeshVG.const_stride);
  5015. var f32pos = startpos >> 2;
  5016. var vbdata = this._vb._floatArray32 || this._vb.getFloat32Array();
  5017. var vbu32Arr = this._vb._uint32Array;
  5018. var ci = 0;
  5019. var sz = points.length / 2;
  5020. for (var i = 0; i < sz; i++) {
  5021. vbdata[f32pos++] = points[ci];
  5022. vbdata[f32pos++] = points[ci + 1];
  5023. ci += 2;
  5024. vbu32Arr[f32pos++] = rgba;
  5025. }
  5026. this._vb.setNeedUpload();
  5027. this._ib.append(new Uint16Array(ib));
  5028. this._ib.setNeedUpload();
  5029. this.vertNum += sz;
  5030. this.indexNum += ib.length;
  5031. }
  5032. releaseMesh() {
  5033. this._vb.setByteLength(0);
  5034. this._ib.setByteLength(0);
  5035. this.vertNum = 0;
  5036. this.indexNum = 0;
  5037. MeshVG._POOL.push(this);
  5038. }
  5039. destroy() {
  5040. this._ib.destroy();
  5041. this._vb.destroy();
  5042. this._ib.disposeResource();
  5043. this._vb.deleteBuffer();
  5044. }
  5045. }
  5046. MeshVG.const_stride = 12;
  5047. MeshVG._POOL = [];
  5048. class WebGLCacheAsNormalCanvas {
  5049. constructor(ctx, sp) {
  5050. this.submitStartPos = 0;
  5051. this.submitEndPos = 0;
  5052. this.touches = [];
  5053. this.submits = [];
  5054. this.sprite = null;
  5055. this.meshlist = [];
  5056. this.cachedClipInfo = new Matrix();
  5057. this.oldTx = 0;
  5058. this.oldTy = 0;
  5059. this.invMat = new Matrix();
  5060. this.context = ctx;
  5061. this.sprite = sp;
  5062. ctx._globalClipMatrix.copyTo(this.cachedClipInfo);
  5063. }
  5064. startRec() {
  5065. let context = this.context;
  5066. if (context._charSubmitCache && context._charSubmitCache._enable) {
  5067. context._charSubmitCache.enable(false, context);
  5068. context._charSubmitCache.enable(true, context);
  5069. }
  5070. context._incache = true;
  5071. this.touches.length = 0;
  5072. context.touches = this.touches;
  5073. context._globalClipMatrix.copyTo(this.cachedClipInfo);
  5074. this.submits.length = 0;
  5075. this.submitStartPos = context._submits._length;
  5076. for (var i = 0, sz = this.meshlist.length; i < sz; i++) {
  5077. var curm = this.meshlist[i];
  5078. curm.canReuse ? (curm.releaseMesh()) : (curm.destroy());
  5079. }
  5080. this.meshlist.length = 0;
  5081. this._mesh = MeshQuadTexture.getAMesh(false);
  5082. this._pathMesh = MeshVG.getAMesh(false);
  5083. this._triangleMesh = MeshTexture.getAMesh(false);
  5084. this.meshlist.push(this._mesh);
  5085. this.meshlist.push(this._pathMesh);
  5086. this.meshlist.push(this._triangleMesh);
  5087. context._curSubmit = SubmitBase.RENDERBASE;
  5088. this._oldMesh = context._mesh;
  5089. this._oldPathMesh = context._pathMesh;
  5090. this._oldTriMesh = context._triangleMesh;
  5091. this._oldMeshList = context.meshlist;
  5092. context._mesh = this._mesh;
  5093. context._pathMesh = this._pathMesh;
  5094. context._triangleMesh = this._triangleMesh;
  5095. context.meshlist = this.meshlist;
  5096. this.oldTx = context._curMat.tx;
  5097. this.oldTy = context._curMat.ty;
  5098. context._curMat.tx = 0;
  5099. context._curMat.ty = 0;
  5100. context._curMat.copyTo(this.invMat);
  5101. this.invMat.invert();
  5102. }
  5103. endRec() {
  5104. let context = this.context;
  5105. if (context._charSubmitCache && context._charSubmitCache._enable) {
  5106. context._charSubmitCache.enable(false, context);
  5107. context._charSubmitCache.enable(true, context);
  5108. }
  5109. var parsubmits = context._submits;
  5110. this.submitEndPos = parsubmits._length;
  5111. var num = this.submitEndPos - this.submitStartPos;
  5112. for (var i = 0; i < num; i++) {
  5113. this.submits.push(parsubmits[this.submitStartPos + i]);
  5114. }
  5115. parsubmits._length -= num;
  5116. context._mesh = this._oldMesh;
  5117. context._pathMesh = this._oldPathMesh;
  5118. context._triangleMesh = this._oldTriMesh;
  5119. context.meshlist = this._oldMeshList;
  5120. context._curSubmit = SubmitBase.RENDERBASE;
  5121. context._curMat.tx = this.oldTx;
  5122. context._curMat.ty = this.oldTy;
  5123. context.touches = null;
  5124. context._incache = false;
  5125. }
  5126. isCacheValid() {
  5127. var curclip = this.context._globalClipMatrix;
  5128. if (curclip.a != this.cachedClipInfo.a || curclip.b != this.cachedClipInfo.b || curclip.c != this.cachedClipInfo.c
  5129. || curclip.d != this.cachedClipInfo.d || curclip.tx != this.cachedClipInfo.tx || curclip.ty != this.cachedClipInfo.ty)
  5130. return false;
  5131. return true;
  5132. }
  5133. flushsubmit() {
  5134. var curSubmit = SubmitBase.RENDERBASE;
  5135. this.submits.forEach(function (subm) {
  5136. if (subm == SubmitBase.RENDERBASE)
  5137. return;
  5138. SubmitBase.preRender = curSubmit;
  5139. curSubmit = subm;
  5140. subm.renderSubmit();
  5141. });
  5142. }
  5143. releaseMem() {
  5144. }
  5145. }
  5146. WebGLCacheAsNormalCanvas.matI = new Matrix();
  5147. var texture_vs = "/*\r\n\ttexture和fillrect使用的。\r\n*/\r\nattribute vec4 posuv;\r\nattribute vec4 attribColor;\r\nattribute vec4 attribFlags;\r\n//attribute vec4 clipDir;\r\n//attribute vec2 clipRect;\r\nuniform vec4 clipMatDir;\r\nuniform vec2 clipMatPos;\t\t// 这个是全局的,不用再应用矩阵了。\r\nvarying vec2 cliped;\r\nuniform vec2 size;\r\nuniform vec2 clipOff;\t\t\t// 使用要把clip偏移。cacheas normal用. 只用了[0]\r\n#ifdef WORLDMAT\r\n\tuniform mat4 mmat;\r\n#endif\r\n#ifdef MVP3D\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\nvarying vec4 v_texcoordAlpha;\r\nvarying vec4 v_color;\r\nvarying float v_useTex;\r\n\r\nvoid main() {\r\n\r\n\tvec4 pos = vec4(posuv.xy,0.,1.);\r\n#ifdef WORLDMAT\r\n\tpos=mmat*pos;\r\n#endif\r\n\tvec4 pos1 =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,0.,1.0);\r\n#ifdef MVP3D\r\n\tgl_Position=u_MvpMatrix*pos1;\r\n#else\r\n\tgl_Position=pos1;\r\n#endif\r\n\tv_texcoordAlpha.xy = posuv.zw;\r\n\t//v_texcoordAlpha.z = attribColor.a/255.0;\r\n\tv_color = attribColor/255.0;\r\n\tv_color.xyz*=v_color.w;//反正后面也要预乘\r\n\t\r\n\tv_useTex = attribFlags.r/255.0;\r\n\tfloat clipw = length(clipMatDir.xy);\r\n\tfloat cliph = length(clipMatDir.zw);\r\n\t\r\n\tvec2 clpos = clipMatPos.xy;\r\n\t#ifdef WORLDMAT\r\n\t\t// 如果有mmat,需要修改clipMatPos,因为 这是cacheas normal (如果不是就错了), clipMatPos被去掉了偏移\r\n\t\tif(clipOff[0]>0.0){\r\n\t\t\tclpos.x+=mmat[3].x;\t//tx\t最简单处理\r\n\t\t\tclpos.y+=mmat[3].y;\t//ty\r\n\t\t}\r\n\t#endif\r\n\tvec2 clippos = pos.xy - clpos;\t//pos已经应用矩阵了,为了减的有意义,clip的位置也要缩放\r\n\tif(clipw>20000. && cliph>20000.)\r\n\t\tcliped = vec2(0.5,0.5);\r\n\telse {\r\n\t\t//转成0到1之间。/clipw/clipw 表示clippos与normalize之后的clip朝向点积之后,再除以clipw\r\n\t\tcliped=vec2( dot(clippos,clipMatDir.xy)/clipw/clipw, dot(clippos,clipMatDir.zw)/cliph/cliph);\r\n\t}\r\n\r\n}";
  5148. var texture_ps = "/*\r\n\ttexture和fillrect使用的。\r\n*/\r\n#ifdef GL_FRAGMENT_PRECISION_HIGH\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n\r\nvarying vec4 v_texcoordAlpha;\r\nvarying vec4 v_color;\r\nvarying float v_useTex;\r\nuniform sampler2D texture;\r\nvarying vec2 cliped;\r\n\r\n#ifdef BLUR_FILTER\r\nuniform vec4 strength_sig2_2sig2_gauss1;\r\nuniform vec2 blurInfo;\r\n\r\n#define PI 3.141593\r\n\r\nfloat getGaussian(float x, float y){\r\n return strength_sig2_2sig2_gauss1.w*exp(-(x*x+y*y)/strength_sig2_2sig2_gauss1.z);\r\n}\r\n\r\nvec4 blur(){\r\n const float blurw = 9.0;\r\n vec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\r\n vec2 halfsz=vec2(blurw,blurw)/2.0/blurInfo; \r\n vec2 startpos=v_texcoordAlpha.xy-halfsz;\r\n vec2 ctexcoord = startpos;\r\n vec2 step = 1.0/blurInfo; //每个像素 \r\n \r\n for(float y = 0.0;y<=blurw; ++y){\r\n ctexcoord.x=startpos.x;\r\n for(float x = 0.0;x<=blurw; ++x){\r\n //TODO 纹理坐标的固定偏移应该在vs中处理\r\n vec4Color += texture2D(texture, ctexcoord)*getGaussian(x-blurw/2.0,y-blurw/2.0);\r\n ctexcoord.x+=step.x;\r\n }\r\n ctexcoord.y+=step.y;\r\n }\r\n return vec4Color;\r\n}\r\n#endif\r\n\r\n#ifdef COLOR_FILTER\r\nuniform vec4 colorAlpha;\r\nuniform mat4 colorMat;\r\n#endif\r\n\r\n#ifdef GLOW_FILTER\r\nuniform vec4 u_color;\r\nuniform vec4 u_blurInfo1;\r\nuniform vec4 u_blurInfo2;\r\n#endif\r\n\r\n#ifdef COLOR_ADD\r\nuniform vec4 colorAdd;\r\n#endif\r\n\r\n#ifdef FILLTEXTURE\t\r\nuniform vec4 u_TexRange;//startu,startv,urange, vrange\r\n#endif\r\nvoid main() {\r\n\tif(cliped.x<0.) discard;\r\n\tif(cliped.x>1.) discard;\r\n\tif(cliped.y<0.) discard;\r\n\tif(cliped.y>1.) discard;\r\n\t\r\n#ifdef FILLTEXTURE\t\r\n vec4 color= texture2D(texture, fract(v_texcoordAlpha.xy)*u_TexRange.zw + u_TexRange.xy);\r\n#else\r\n vec4 color= texture2D(texture, v_texcoordAlpha.xy);\r\n#endif\r\n\r\n if(v_useTex<=0.)color = vec4(1.,1.,1.,1.);\r\n color.a*=v_color.w;\r\n //color.rgb*=v_color.w;\r\n color.rgb*=v_color.rgb;\r\n gl_FragColor=color;\r\n \r\n #ifdef COLOR_ADD\r\n\tgl_FragColor = vec4(colorAdd.rgb,colorAdd.a*gl_FragColor.a);\r\n\tgl_FragColor.xyz *= colorAdd.a;\r\n #endif\r\n \r\n #ifdef BLUR_FILTER\r\n\tgl_FragColor = blur();\r\n\tgl_FragColor.w*=v_color.w; \r\n #endif\r\n \r\n #ifdef COLOR_FILTER\r\n\tmat4 alphaMat =colorMat;\r\n\r\n\talphaMat[0][3] *= gl_FragColor.a;\r\n\talphaMat[1][3] *= gl_FragColor.a;\r\n\talphaMat[2][3] *= gl_FragColor.a;\r\n\r\n\tgl_FragColor = gl_FragColor * alphaMat;\r\n\tgl_FragColor += colorAlpha/255.0*gl_FragColor.a;\r\n #endif\r\n \r\n #ifdef GLOW_FILTER\r\n\tconst float c_IterationTime = 10.0;\r\n\tfloat floatIterationTotalTime = c_IterationTime * c_IterationTime;\r\n\tvec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\r\n\tvec2 vec2FilterDir = vec2(-(u_blurInfo1.z)/u_blurInfo2.x,-(u_blurInfo1.w)/u_blurInfo2.y);\r\n\tvec2 vec2FilterOff = vec2(u_blurInfo1.x/u_blurInfo2.x/c_IterationTime * 2.0,u_blurInfo1.y/u_blurInfo2.y/c_IterationTime * 2.0);\r\n\tfloat maxNum = u_blurInfo1.x * u_blurInfo1.y;\r\n\tvec2 vec2Off = vec2(0.0,0.0);\r\n\tfloat floatOff = c_IterationTime/2.0;\r\n\tfor(float i = 0.0;i<=c_IterationTime; ++i){\r\n\t\tfor(float j = 0.0;j<=c_IterationTime; ++j){\r\n\t\t\tvec2Off = vec2(vec2FilterOff.x * (i - floatOff),vec2FilterOff.y * (j - floatOff));\r\n\t\t\tvec4Color += texture2D(texture, v_texcoordAlpha.xy + vec2FilterDir + vec2Off)/floatIterationTotalTime;\r\n\t\t}\r\n\t}\r\n\tgl_FragColor = vec4(u_color.rgb,vec4Color.a * u_blurInfo2.z);\r\n\tgl_FragColor.rgb *= gl_FragColor.a; \r\n #endif\r\n \r\n}";
  5149. var prime_vs = "attribute vec4 position;\r\nattribute vec4 attribColor;\r\n//attribute vec4 clipDir;\r\n//attribute vec2 clipRect;\r\nuniform vec4 clipMatDir;\r\nuniform vec2 clipMatPos;\r\n#ifdef WORLDMAT\r\n\tuniform mat4 mmat;\r\n#endif\r\nuniform mat4 u_mmat2;\r\n//uniform vec2 u_pos;\r\nuniform vec2 size;\r\nvarying vec4 color;\r\n//vec4 dirxy=vec4(0.9,0.1, -0.1,0.9);\r\n//vec4 clip=vec4(100.,30.,300.,600.);\r\nvarying vec2 cliped;\r\nvoid main(){\r\n\t\r\n#ifdef WORLDMAT\r\n\tvec4 pos=mmat*vec4(position.xy,0.,1.);\r\n\tgl_Position =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\r\n#else\r\n\tgl_Position =vec4((position.x/size.x-0.5)*2.0,(0.5-position.y/size.y)*2.0,position.z,1.0);\r\n#endif\t\r\n\tfloat clipw = length(clipMatDir.xy);\r\n\tfloat cliph = length(clipMatDir.zw);\r\n\tvec2 clippos = position.xy - clipMatPos.xy;\t//pos已经应用矩阵了,为了减的有意义,clip的位置也要缩放\r\n\tif(clipw>20000. && cliph>20000.)\r\n\t\tcliped = vec2(0.5,0.5);\r\n\telse {\r\n\t\t//clipdir是带缩放的方向,由于上面clippos是在缩放后的空间计算的,所以需要把方向先normalize一下\r\n\t\tcliped=vec2( dot(clippos,clipMatDir.xy)/clipw/clipw, dot(clippos,clipMatDir.zw)/cliph/cliph);\r\n\t}\r\n //pos2d.x = dot(clippos,dirx);\r\n color=attribColor/255.;\r\n}";
  5150. var prime_ps = "precision mediump float;\r\n//precision mediump float;\r\nvarying vec4 color;\r\n//uniform float alpha;\r\nvarying vec2 cliped;\r\nvoid main(){\r\n\t//vec4 a=vec4(color.r, color.g, color.b, 1);\r\n\t//a.a*=alpha;\r\n gl_FragColor= color;// vec4(color.r, color.g, color.b, alpha);\r\n\tgl_FragColor.rgb*=color.a;\r\n\tif(cliped.x<0.) discard;\r\n\tif(cliped.x>1.) discard;\r\n\tif(cliped.y<0.) discard;\r\n\tif(cliped.y>1.) discard;\r\n}";
  5151. var skin_vs = "attribute vec2 position;\r\nattribute vec2 texcoord;\r\nattribute vec4 color;\r\nuniform vec2 size;\r\nuniform float offsetX;\r\nuniform float offsetY;\r\nuniform mat4 mmat;\r\nuniform mat4 u_mmat2;\r\nvarying vec2 v_texcoord;\r\nvarying vec4 v_color;\r\nvoid main() {\r\n vec4 pos=mmat*u_mmat2*vec4(offsetX+position.x,offsetY+position.y,0,1 );\r\n gl_Position = vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\r\n v_color = color;\r\n v_color.rgb *= v_color.a;\r\n v_texcoord = texcoord; \r\n}";
  5152. var skin_ps = "precision mediump float;\r\nvarying vec2 v_texcoord;\r\nvarying vec4 v_color;\r\nuniform sampler2D texture;\r\nuniform float alpha;\r\nvoid main() {\r\n\tvec4 t_color = texture2D(texture, v_texcoord);\r\n\tgl_FragColor = t_color.rgba * v_color;\r\n\tgl_FragColor *= alpha;\r\n}";
  5153. class Shader2D {
  5154. constructor() {
  5155. this.ALPHA = 1;
  5156. this.defines = new ShaderDefines2D();
  5157. this.shaderType = 0;
  5158. this.fillStyle = DrawStyle.DEFAULT;
  5159. this.strokeStyle = DrawStyle.DEFAULT;
  5160. }
  5161. destroy() {
  5162. this.defines = null;
  5163. this.filters = null;
  5164. }
  5165. static __init__() {
  5166. Shader.preCompile2D(0, ShaderDefines2D.TEXTURE2D, texture_vs, texture_ps, null);
  5167. Shader.preCompile2D(0, ShaderDefines2D.PRIMITIVE, prime_vs, prime_ps, null);
  5168. Shader.preCompile2D(0, ShaderDefines2D.SKINMESH, skin_vs, skin_ps, null);
  5169. }
  5170. }
  5171. class SkinMeshBuffer {
  5172. constructor() {
  5173. var gl = LayaGL.instance;
  5174. this.ib = IndexBuffer2D.create(gl.DYNAMIC_DRAW);
  5175. this.vb = VertexBuffer2D.create(8);
  5176. }
  5177. static getInstance() {
  5178. return SkinMeshBuffer.instance = SkinMeshBuffer.instance || new SkinMeshBuffer();
  5179. }
  5180. addSkinMesh(skinMesh) {
  5181. skinMesh.getData2(this.vb, this.ib, this.vb._byteLength / 32);
  5182. }
  5183. reset() {
  5184. this.vb.clear();
  5185. this.ib.clear();
  5186. }
  5187. }
  5188. class BasePoly {
  5189. static createLine2(p, indices, lineWidth, indexBase, outVertex, loop) {
  5190. if (p.length < 4)
  5191. return null;
  5192. var points = BasePoly.tempData.length > (p.length + 2) ? BasePoly.tempData : new Array(p.length + 2);
  5193. points[0] = p[0];
  5194. points[1] = p[1];
  5195. var newlen = 2;
  5196. var i = 0;
  5197. var length = p.length;
  5198. for (i = 2; i < length; i += 2) {
  5199. if (Math.abs(p[i] - p[i - 2]) + Math.abs(p[i + 1] - p[i - 1]) > 0.01) {
  5200. points[newlen++] = p[i];
  5201. points[newlen++] = p[i + 1];
  5202. }
  5203. }
  5204. if (loop && Math.abs(p[0] - points[newlen - 2]) + Math.abs(p[1] - points[newlen - 1]) > 0.01) {
  5205. points[newlen++] = p[0];
  5206. points[newlen++] = p[1];
  5207. }
  5208. var result = outVertex;
  5209. length = newlen / 2;
  5210. var w = lineWidth / 2;
  5211. var px, py, p1x, p1y, p2x, p2y, p3x, p3y;
  5212. var perpx, perpy, perp2x, perp2y;
  5213. var a1, b1, c1, a2, b2, c2;
  5214. var denom, dist;
  5215. p1x = points[0];
  5216. p1y = points[1];
  5217. p2x = points[2];
  5218. p2y = points[3];
  5219. perpx = -(p1y - p2y);
  5220. perpy = p1x - p2x;
  5221. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5222. perpx = perpx / dist * w;
  5223. perpy = perpy / dist * w;
  5224. result.push(p1x - perpx, p1y - perpy, p1x + perpx, p1y + perpy);
  5225. for (i = 1; i < length - 1; i++) {
  5226. p1x = points[(i - 1) * 2];
  5227. p1y = points[(i - 1) * 2 + 1];
  5228. p2x = points[(i) * 2];
  5229. p2y = points[(i) * 2 + 1];
  5230. p3x = points[(i + 1) * 2];
  5231. p3y = points[(i + 1) * 2 + 1];
  5232. perpx = -(p1y - p2y);
  5233. perpy = p1x - p2x;
  5234. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5235. perpx = perpx / dist * w;
  5236. perpy = perpy / dist * w;
  5237. perp2x = -(p2y - p3y);
  5238. perp2y = p2x - p3x;
  5239. dist = Math.sqrt(perp2x * perp2x + perp2y * perp2y);
  5240. perp2x = perp2x / dist * w;
  5241. perp2y = perp2y / dist * w;
  5242. a1 = (-perpy + p1y) - (-perpy + p2y);
  5243. b1 = (-perpx + p2x) - (-perpx + p1x);
  5244. c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y);
  5245. a2 = (-perp2y + p3y) - (-perp2y + p2y);
  5246. b2 = (-perp2x + p2x) - (-perp2x + p3x);
  5247. c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y);
  5248. denom = a1 * b2 - a2 * b1;
  5249. if (Math.abs(denom) < 0.1) {
  5250. denom += 10.1;
  5251. result.push(p2x - perpx, p2y - perpy, p2x + perpx, p2y + perpy);
  5252. continue;
  5253. }
  5254. px = (b1 * c2 - b2 * c1) / denom;
  5255. py = (a2 * c1 - a1 * c2) / denom;
  5256. result.push(px, py, p2x - (px - p2x), p2y - (py - p2y));
  5257. }
  5258. p1x = points[newlen - 4];
  5259. p1y = points[newlen - 3];
  5260. p2x = points[newlen - 2];
  5261. p2y = points[newlen - 1];
  5262. perpx = -(p1y - p2y);
  5263. perpy = p1x - p2x;
  5264. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5265. perpx = perpx / dist * w;
  5266. perpy = perpy / dist * w;
  5267. result.push(p2x - perpx, p2y - perpy, p2x + perpx, p2y + perpy);
  5268. for (i = 1; i < length; i++) {
  5269. indices.push(indexBase + (i - 1) * 2, indexBase + (i - 1) * 2 + 1, indexBase + i * 2 + 1, indexBase + i * 2 + 1, indexBase + i * 2, indexBase + (i - 1) * 2);
  5270. }
  5271. return result;
  5272. }
  5273. static createLineTriangle(path, color, width, loop, outvb, vbstride, outib) {
  5274. var points = path.slice();
  5275. var ptlen = points.length;
  5276. var p1x = points[0], p1y = points[1];
  5277. var p2x = points[2], p2y = points[2];
  5278. var len = 0;
  5279. var rp = 0;
  5280. var dx = 0, dy = 0;
  5281. var pointnum = ptlen / 2;
  5282. if (pointnum <= 1)
  5283. return;
  5284. if (pointnum == 2) {
  5285. return;
  5286. }
  5287. var tmpData = new Array(pointnum * 4);
  5288. var realPtNum = 0;
  5289. var ci = 0;
  5290. for (var i = 0; i < pointnum - 1; i++) {
  5291. p1x = points[ci++], p1y = points[ci++];
  5292. p2x = points[ci++], p2y = points[ci++];
  5293. dx = p2x - p1x, dy = p2y - p1y;
  5294. if (dx != 0 && dy != 0) {
  5295. len = Math.sqrt(dx * dx + dy * dy);
  5296. if (len > 1e-3) {
  5297. rp = realPtNum * 4;
  5298. tmpData[rp] = p1x;
  5299. tmpData[rp + 1] = p1y;
  5300. tmpData[rp + 2] = dx / len;
  5301. tmpData[rp + 3] = dy / len;
  5302. realPtNum++;
  5303. }
  5304. }
  5305. }
  5306. if (loop) {
  5307. p1x = points[ptlen - 2], p1y = points[ptlen - 1];
  5308. p2x = points[0], p2y = points[1];
  5309. dx = p2x - p1x, dy = p2y - p1y;
  5310. if (dx != 0 && dy != 0) {
  5311. len = Math.sqrt(dx * dx + dy * dy);
  5312. if (len > 1e-3) {
  5313. rp = realPtNum * 4;
  5314. tmpData[rp] = p1x;
  5315. tmpData[rp + 1] = p1y;
  5316. tmpData[rp + 2] = dx / len;
  5317. tmpData[rp + 3] = dy / len;
  5318. realPtNum++;
  5319. }
  5320. }
  5321. }
  5322. else {
  5323. rp = realPtNum * 4;
  5324. tmpData[rp] = p1x;
  5325. tmpData[rp + 1] = p1y;
  5326. tmpData[rp + 2] = dx / len;
  5327. tmpData[rp + 3] = dy / len;
  5328. realPtNum++;
  5329. }
  5330. ci = 0;
  5331. for (i = 0; i < pointnum; i++) {
  5332. p1x = points[ci], p1y = points[ci + 1];
  5333. p2x = points[ci + 2], p2y = points[ci + 3];
  5334. }
  5335. }
  5336. }
  5337. BasePoly.tempData = new Array(256);
  5338. class EarcutNode {
  5339. constructor(i, x, y) {
  5340. this.i = i;
  5341. this.x = x;
  5342. this.y = y;
  5343. this.prev = null;
  5344. this.next = null;
  5345. this.z = null;
  5346. this.prevZ = null;
  5347. this.nextZ = null;
  5348. this.steiner = false;
  5349. }
  5350. }
  5351. class Earcut {
  5352. static earcut(data, holeIndices, dim) {
  5353. dim = dim || 2;
  5354. var hasHoles = holeIndices && holeIndices.length, outerLen = hasHoles ? holeIndices[0] * dim : data.length, outerNode = Earcut.linkedList(data, 0, outerLen, dim, true), triangles = [];
  5355. if (!outerNode)
  5356. return triangles;
  5357. var minX, minY, maxX, maxY, x, y, invSize;
  5358. if (hasHoles)
  5359. outerNode = Earcut.eliminateHoles(data, holeIndices, outerNode, dim);
  5360. if (data.length > 80 * dim) {
  5361. minX = maxX = data[0];
  5362. minY = maxY = data[1];
  5363. for (var i = dim; i < outerLen; i += dim) {
  5364. x = data[i];
  5365. y = data[i + 1];
  5366. if (x < minX)
  5367. minX = x;
  5368. if (y < minY)
  5369. minY = y;
  5370. if (x > maxX)
  5371. maxX = x;
  5372. if (y > maxY)
  5373. maxY = y;
  5374. }
  5375. invSize = Math.max(maxX - minX, maxY - minY);
  5376. invSize = invSize !== 0 ? 1 / invSize : 0;
  5377. }
  5378. Earcut.earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  5379. return triangles;
  5380. }
  5381. static linkedList(data, start, end, dim, clockwise) {
  5382. var i, last;
  5383. if (clockwise === (Earcut.signedArea(data, start, end, dim) > 0)) {
  5384. for (i = start; i < end; i += dim)
  5385. last = Earcut.insertNode(i, data[i], data[i + 1], last);
  5386. }
  5387. else {
  5388. for (i = end - dim; i >= start; i -= dim)
  5389. last = Earcut.insertNode(i, data[i], data[i + 1], last);
  5390. }
  5391. if (last && Earcut.equals(last, last.next)) {
  5392. Earcut.removeNode(last);
  5393. last = last.next;
  5394. }
  5395. return last;
  5396. }
  5397. static filterPoints(start, end) {
  5398. if (!start)
  5399. return start;
  5400. if (!end)
  5401. end = start;
  5402. var p = start, again;
  5403. do {
  5404. again = false;
  5405. if (!p.steiner && (Earcut.equals(p, p.next) || Earcut.area(p.prev, p, p.next) === 0)) {
  5406. Earcut.removeNode(p);
  5407. p = end = p.prev;
  5408. if (p === p.next)
  5409. break;
  5410. again = true;
  5411. }
  5412. else {
  5413. p = p.next;
  5414. }
  5415. } while (again || p !== end);
  5416. return end;
  5417. }
  5418. static earcutLinked(ear, triangles, dim, minX, minY, invSize, pass = null) {
  5419. if (!ear)
  5420. return;
  5421. if (!pass && invSize)
  5422. Earcut.indexCurve(ear, minX, minY, invSize);
  5423. var stop = ear, prev, next;
  5424. while (ear.prev !== ear.next) {
  5425. prev = ear.prev;
  5426. next = ear.next;
  5427. if (invSize ? Earcut.isEarHashed(ear, minX, minY, invSize) : Earcut.isEar(ear)) {
  5428. triangles.push(prev.i / dim);
  5429. triangles.push(ear.i / dim);
  5430. triangles.push(next.i / dim);
  5431. Earcut.removeNode(ear);
  5432. ear = next.next;
  5433. stop = next.next;
  5434. continue;
  5435. }
  5436. ear = next;
  5437. if (ear === stop) {
  5438. if (!pass) {
  5439. Earcut.earcutLinked(Earcut.filterPoints(ear, null), triangles, dim, minX, minY, invSize, 1);
  5440. }
  5441. else if (pass === 1) {
  5442. ear = Earcut.cureLocalIntersections(ear, triangles, dim);
  5443. Earcut.earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
  5444. }
  5445. else if (pass === 2) {
  5446. Earcut.splitEarcut(ear, triangles, dim, minX, minY, invSize);
  5447. }
  5448. break;
  5449. }
  5450. }
  5451. }
  5452. static isEar(ear) {
  5453. var a = ear.prev, b = ear, c = ear.next;
  5454. if (Earcut.area(a, b, c) >= 0)
  5455. return false;
  5456. var p = ear.next.next;
  5457. while (p !== ear.prev) {
  5458. if (Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5459. Earcut.area(p.prev, p, p.next) >= 0)
  5460. return false;
  5461. p = p.next;
  5462. }
  5463. return true;
  5464. }
  5465. static isEarHashed(ear, minX, minY, invSize) {
  5466. var a = ear.prev, b = ear, c = ear.next;
  5467. if (Earcut.area(a, b, c) >= 0)
  5468. return false;
  5469. var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x), minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y), maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x), maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
  5470. var minZ = Earcut.zOrder(minTX, minTY, minX, minY, invSize), maxZ = Earcut.zOrder(maxTX, maxTY, minX, minY, invSize);
  5471. var p = ear.nextZ;
  5472. while (p && p.z <= maxZ) {
  5473. if (p !== ear.prev && p !== ear.next &&
  5474. Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5475. Earcut.area(p.prev, p, p.next) >= 0)
  5476. return false;
  5477. p = p.nextZ;
  5478. }
  5479. p = ear.prevZ;
  5480. while (p && p.z >= minZ) {
  5481. if (p !== ear.prev && p !== ear.next &&
  5482. Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5483. Earcut.area(p.prev, p, p.next) >= 0)
  5484. return false;
  5485. p = p.prevZ;
  5486. }
  5487. return true;
  5488. }
  5489. static cureLocalIntersections(start, triangles, dim) {
  5490. var p = start;
  5491. do {
  5492. var a = p.prev, b = p.next.next;
  5493. if (!Earcut.equals(a, b) && Earcut.intersects(a, p, p.next, b) && Earcut.locallyInside(a, b) && Earcut.locallyInside(b, a)) {
  5494. triangles.push(a.i / dim);
  5495. triangles.push(p.i / dim);
  5496. triangles.push(b.i / dim);
  5497. Earcut.removeNode(p);
  5498. Earcut.removeNode(p.next);
  5499. p = start = b;
  5500. }
  5501. p = p.next;
  5502. } while (p !== start);
  5503. return p;
  5504. }
  5505. static splitEarcut(start, triangles, dim, minX, minY, invSize) {
  5506. var a = start;
  5507. do {
  5508. var b = a.next.next;
  5509. while (b !== a.prev) {
  5510. if (a.i !== b.i && Earcut.isValidDiagonal(a, b)) {
  5511. var c = Earcut.splitPolygon(a, b);
  5512. a = Earcut.filterPoints(a, a.next);
  5513. c = Earcut.filterPoints(c, c.next);
  5514. Earcut.earcutLinked(a, triangles, dim, minX, minY, invSize);
  5515. Earcut.earcutLinked(c, triangles, dim, minX, minY, invSize);
  5516. return;
  5517. }
  5518. b = b.next;
  5519. }
  5520. a = a.next;
  5521. } while (a !== start);
  5522. }
  5523. static eliminateHoles(data, holeIndices, outerNode, dim) {
  5524. var queue = [], i, len, start, end, list;
  5525. for (i = 0, len = holeIndices.length; i < len; i++) {
  5526. start = holeIndices[i] * dim;
  5527. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  5528. list = Earcut.linkedList(data, start, end, dim, false);
  5529. if (list === list.next)
  5530. list.steiner = true;
  5531. queue.push(Earcut.getLeftmost(list));
  5532. }
  5533. queue.sort(Earcut.compareX);
  5534. for (i = 0; i < queue.length; i++) {
  5535. Earcut.eliminateHole(queue[i], outerNode);
  5536. outerNode = Earcut.filterPoints(outerNode, outerNode.next);
  5537. }
  5538. return outerNode;
  5539. }
  5540. static compareX(a, b) {
  5541. return a.x - b.x;
  5542. }
  5543. static eliminateHole(hole, outerNode) {
  5544. outerNode = Earcut.findHoleBridge(hole, outerNode);
  5545. if (outerNode) {
  5546. var b = Earcut.splitPolygon(outerNode, hole);
  5547. Earcut.filterPoints(b, b.next);
  5548. }
  5549. }
  5550. static findHoleBridge(hole, outerNode) {
  5551. var p = outerNode, hx = hole.x, hy = hole.y, qx = -Infinity, m;
  5552. do {
  5553. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  5554. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  5555. if (x <= hx && x > qx) {
  5556. qx = x;
  5557. if (x === hx) {
  5558. if (hy === p.y)
  5559. return p;
  5560. if (hy === p.next.y)
  5561. return p.next;
  5562. }
  5563. m = p.x < p.next.x ? p : p.next;
  5564. }
  5565. }
  5566. p = p.next;
  5567. } while (p !== outerNode);
  5568. if (!m)
  5569. return null;
  5570. if (hx === qx)
  5571. return m.prev;
  5572. var stop = m, mx = m.x, my = m.y, tanMin = Infinity, tan;
  5573. p = m.next;
  5574. while (p !== stop) {
  5575. if (hx >= p.x && p.x >= mx && hx !== p.x &&
  5576. Earcut.pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  5577. tan = Math.abs(hy - p.y) / (hx - p.x);
  5578. if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && Earcut.locallyInside(p, hole)) {
  5579. m = p;
  5580. tanMin = tan;
  5581. }
  5582. }
  5583. p = p.next;
  5584. }
  5585. return m;
  5586. }
  5587. static indexCurve(start, minX, minY, invSize) {
  5588. var p = start;
  5589. do {
  5590. if (p.z === null)
  5591. p.z = Earcut.zOrder(p.x, p.y, minX, minY, invSize);
  5592. p.prevZ = p.prev;
  5593. p.nextZ = p.next;
  5594. p = p.next;
  5595. } while (p !== start);
  5596. p.prevZ.nextZ = null;
  5597. p.prevZ = null;
  5598. Earcut.sortLinked(p);
  5599. }
  5600. static sortLinked(list) {
  5601. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  5602. do {
  5603. p = list;
  5604. list = null;
  5605. tail = null;
  5606. numMerges = 0;
  5607. while (p) {
  5608. numMerges++;
  5609. q = p;
  5610. pSize = 0;
  5611. for (i = 0; i < inSize; i++) {
  5612. pSize++;
  5613. q = q.nextZ;
  5614. if (!q)
  5615. break;
  5616. }
  5617. qSize = inSize;
  5618. while (pSize > 0 || (qSize > 0 && q)) {
  5619. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  5620. e = p;
  5621. p = p.nextZ;
  5622. pSize--;
  5623. }
  5624. else {
  5625. e = q;
  5626. q = q.nextZ;
  5627. qSize--;
  5628. }
  5629. if (tail)
  5630. tail.nextZ = e;
  5631. else
  5632. list = e;
  5633. e.prevZ = tail;
  5634. tail = e;
  5635. }
  5636. p = q;
  5637. }
  5638. tail.nextZ = null;
  5639. inSize *= 2;
  5640. } while (numMerges > 1);
  5641. return list;
  5642. }
  5643. static zOrder(x, y, minX, minY, invSize) {
  5644. x = 32767 * (x - minX) * invSize;
  5645. y = 32767 * (y - minY) * invSize;
  5646. x = (x | (x << 8)) & 0x00FF00FF;
  5647. x = (x | (x << 4)) & 0x0F0F0F0F;
  5648. x = (x | (x << 2)) & 0x33333333;
  5649. x = (x | (x << 1)) & 0x55555555;
  5650. y = (y | (y << 8)) & 0x00FF00FF;
  5651. y = (y | (y << 4)) & 0x0F0F0F0F;
  5652. y = (y | (y << 2)) & 0x33333333;
  5653. y = (y | (y << 1)) & 0x55555555;
  5654. return x | (y << 1);
  5655. }
  5656. static getLeftmost(start) {
  5657. var p = start, leftmost = start;
  5658. do {
  5659. if (p.x < leftmost.x)
  5660. leftmost = p;
  5661. p = p.next;
  5662. } while (p !== start);
  5663. return leftmost;
  5664. }
  5665. static pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  5666. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
  5667. (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
  5668. (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  5669. }
  5670. static isValidDiagonal(a, b) {
  5671. return a.next.i !== b.i && a.prev.i !== b.i && !Earcut.intersectsPolygon(a, b) &&
  5672. Earcut.locallyInside(a, b) && Earcut.locallyInside(b, a) && Earcut.middleInside(a, b);
  5673. }
  5674. static area(p, q, r) {
  5675. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  5676. }
  5677. static equals(p1, p2) {
  5678. return p1.x === p2.x && p1.y === p2.y;
  5679. }
  5680. static intersects(p1, q1, p2, q2) {
  5681. if ((Earcut.equals(p1, q1) && Earcut.equals(p2, q2)) ||
  5682. (Earcut.equals(p1, q2) && Earcut.equals(p2, q1)))
  5683. return true;
  5684. return Earcut.area(p1, q1, p2) > 0 !== Earcut.area(p1, q1, q2) > 0 &&
  5685. Earcut.area(p2, q2, p1) > 0 !== Earcut.area(p2, q2, q1) > 0;
  5686. }
  5687. static intersectsPolygon(a, b) {
  5688. var p = a;
  5689. do {
  5690. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  5691. Earcut.intersects(p, p.next, a, b))
  5692. return true;
  5693. p = p.next;
  5694. } while (p !== a);
  5695. return false;
  5696. }
  5697. static locallyInside(a, b) {
  5698. return Earcut.area(a.prev, a, a.next) < 0 ?
  5699. Earcut.area(a, b, a.next) >= 0 && Earcut.area(a, a.prev, b) >= 0 :
  5700. Earcut.area(a, b, a.prev) < 0 || Earcut.area(a, a.next, b) < 0;
  5701. }
  5702. static middleInside(a, b) {
  5703. var p = a, inside = false, px = (a.x + b.x) / 2, py = (a.y + b.y) / 2;
  5704. do {
  5705. if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
  5706. (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  5707. inside = !inside;
  5708. p = p.next;
  5709. } while (p !== a);
  5710. return inside;
  5711. }
  5712. static splitPolygon(a, b) {
  5713. var a2 = new EarcutNode(a.i, a.x, a.y), b2 = new EarcutNode(b.i, b.x, b.y), an = a.next, bp = b.prev;
  5714. a.next = b;
  5715. b.prev = a;
  5716. a2.next = an;
  5717. an.prev = a2;
  5718. b2.next = a2;
  5719. a2.prev = b2;
  5720. bp.next = b2;
  5721. b2.prev = bp;
  5722. return b2;
  5723. }
  5724. static insertNode(i, x, y, last) {
  5725. var p = new EarcutNode(i, x, y);
  5726. if (!last) {
  5727. p.prev = p;
  5728. p.next = p;
  5729. }
  5730. else {
  5731. p.next = last.next;
  5732. p.prev = last;
  5733. last.next.prev = p;
  5734. last.next = p;
  5735. }
  5736. return p;
  5737. }
  5738. static removeNode(p) {
  5739. p.next.prev = p.prev;
  5740. p.prev.next = p.next;
  5741. if (p.prevZ)
  5742. p.prevZ.nextZ = p.nextZ;
  5743. if (p.nextZ)
  5744. p.nextZ.prevZ = p.prevZ;
  5745. }
  5746. static signedArea(data, start, end, dim) {
  5747. var sum = 0;
  5748. for (var i = start, j = end - dim; i < end; i += dim) {
  5749. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  5750. j = i;
  5751. }
  5752. return sum;
  5753. }
  5754. }
  5755. class CONST3D2D {
  5756. }
  5757. CONST3D2D.BYTES_PE = 4;
  5758. CONST3D2D.BYTES_PIDX = 2;
  5759. CONST3D2D.defaultMatrix4 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  5760. CONST3D2D.defaultMinusYMatrix4 = [1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  5761. CONST3D2D.uniformMatrix3 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0];
  5762. CONST3D2D._TMPARRAY = [];
  5763. CONST3D2D._OFFSETX = 0;
  5764. CONST3D2D._OFFSETY = 0;
  5765. class Submit extends SubmitBase {
  5766. constructor(renderType = SubmitBase.TYPE_2D) {
  5767. super(renderType);
  5768. }
  5769. renderSubmit() {
  5770. if (this._numEle === 0 || !this._mesh || this._numEle == 0)
  5771. return 1;
  5772. var _tex = this.shaderValue.textureHost;
  5773. if (_tex) {
  5774. var source = _tex._getSource();
  5775. if (!source)
  5776. return 1;
  5777. this.shaderValue.texture = source;
  5778. }
  5779. var gl = WebGLContext.mainContext;
  5780. this._mesh.useMesh(gl);
  5781. this.shaderValue.upload();
  5782. if (BlendMode.activeBlendFunction !== this._blendFn) {
  5783. WebGLContext.setBlend(gl, true);
  5784. this._blendFn(gl);
  5785. BlendMode.activeBlendFunction = this._blendFn;
  5786. }
  5787. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5788. Stat.renderBatches++;
  5789. Stat.trianglesFaces += this._numEle / 3;
  5790. return 1;
  5791. }
  5792. releaseRender() {
  5793. if (SubmitBase.RENDERBASE == this)
  5794. return;
  5795. if ((--this._ref) < 1) {
  5796. Submit.POOL[Submit._poolSize++] = this;
  5797. this.shaderValue.release();
  5798. this.shaderValue = null;
  5799. this._mesh = null;
  5800. this._parent && (this._parent.releaseRender(), this._parent = null);
  5801. }
  5802. }
  5803. static create(context, mesh, sv) {
  5804. var o = Submit._poolSize ? Submit.POOL[--Submit._poolSize] : new Submit();
  5805. o._ref = 1;
  5806. o._mesh = mesh;
  5807. o._key.clear();
  5808. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5809. o._numEle = 0;
  5810. var blendType = context._nBlendType;
  5811. o._blendFn = context._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5812. o.shaderValue = sv;
  5813. o.shaderValue.setValue(context._shader2D);
  5814. var filters = context._shader2D.filters;
  5815. filters && o.shaderValue.setFilters(filters);
  5816. return o;
  5817. }
  5818. static createShape(ctx, mesh, numEle, sv) {
  5819. var o = Submit._poolSize ? Submit.POOL[--Submit._poolSize] : (new Submit());
  5820. o._mesh = mesh;
  5821. o._numEle = numEle;
  5822. o._startIdx = mesh.indexNum * 2;
  5823. o._ref = 1;
  5824. o.shaderValue = sv;
  5825. o.shaderValue.setValue(ctx._shader2D);
  5826. var blendType = ctx._nBlendType;
  5827. o._key.blendShader = blendType;
  5828. o._blendFn = ctx._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5829. return o;
  5830. }
  5831. }
  5832. Submit._poolSize = 0;
  5833. Submit.POOL = [];
  5834. class SubmitCanvas extends SubmitBase {
  5835. constructor() {
  5836. super(SubmitBase.TYPE_2D);
  5837. this._matrix = new Matrix();
  5838. this._matrix4 = CONST3D2D.defaultMatrix4.concat();
  5839. this.shaderValue = new Value2D(0, 0);
  5840. }
  5841. static create(canvas, alpha, filters) {
  5842. var o = (!SubmitCanvas.POOL._length) ? (new SubmitCanvas()) : SubmitCanvas.POOL[--SubmitCanvas.POOL._length];
  5843. o.canv = canvas;
  5844. o._ref = 1;
  5845. o._numEle = 0;
  5846. var v = o.shaderValue;
  5847. v.alpha = alpha;
  5848. v.defines.setValue(0);
  5849. filters && filters.length && v.setFilters(filters);
  5850. return o;
  5851. }
  5852. renderSubmit() {
  5853. var preAlpha = RenderState2D.worldAlpha;
  5854. var preMatrix4 = RenderState2D.worldMatrix4;
  5855. var preMatrix = RenderState2D.worldMatrix;
  5856. var preFilters = RenderState2D.worldFilters;
  5857. var preWorldShaderDefines = RenderState2D.worldShaderDefines;
  5858. var v = this.shaderValue;
  5859. var m = this._matrix;
  5860. var m4 = this._matrix4;
  5861. var mout = Matrix.TEMP;
  5862. Matrix.mul(m, preMatrix, mout);
  5863. m4[0] = mout.a;
  5864. m4[1] = mout.b;
  5865. m4[4] = mout.c;
  5866. m4[5] = mout.d;
  5867. m4[12] = mout.tx;
  5868. m4[13] = mout.ty;
  5869. RenderState2D.worldMatrix = mout.clone();
  5870. RenderState2D.worldMatrix4 = m4;
  5871. RenderState2D.worldAlpha = RenderState2D.worldAlpha * v.alpha;
  5872. if (v.filters && v.filters.length) {
  5873. RenderState2D.worldFilters = v.filters;
  5874. RenderState2D.worldShaderDefines = v.defines;
  5875. }
  5876. this.canv['flushsubmit']();
  5877. RenderState2D.worldAlpha = preAlpha;
  5878. RenderState2D.worldMatrix4 = preMatrix4;
  5879. RenderState2D.worldMatrix.destroy();
  5880. RenderState2D.worldMatrix = preMatrix;
  5881. RenderState2D.worldFilters = preFilters;
  5882. RenderState2D.worldShaderDefines = preWorldShaderDefines;
  5883. return 1;
  5884. }
  5885. releaseRender() {
  5886. if ((--this._ref) < 1) {
  5887. var cache = SubmitCanvas.POOL;
  5888. this._mesh = null;
  5889. cache[cache._length++] = this;
  5890. }
  5891. }
  5892. getRenderType() {
  5893. return SubmitBase.TYPE_CANVAS;
  5894. }
  5895. ;
  5896. }
  5897. SubmitCanvas.POOL = [];
  5898. {
  5899. SubmitCanvas.POOL._length = 0;
  5900. }
  5901. class SubmitTarget {
  5902. constructor() {
  5903. this.blendType = 0;
  5904. this._ref = 1;
  5905. this._key = new SubmitKey();
  5906. }
  5907. renderSubmit() {
  5908. var gl = WebGLContext.mainContext;
  5909. this._mesh.useMesh(gl);
  5910. var target = this.srcRT;
  5911. if (target) {
  5912. this.shaderValue.texture = target._getSource();
  5913. this.shaderValue.upload();
  5914. this.blend();
  5915. Stat.renderBatches++;
  5916. Stat.trianglesFaces += this._numEle / 3;
  5917. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5918. }
  5919. return 1;
  5920. }
  5921. blend() {
  5922. if (BlendMode.activeBlendFunction !== BlendMode.fns[this.blendType]) {
  5923. var gl = WebGLContext.mainContext;
  5924. gl.enable(gl.BLEND);
  5925. BlendMode.fns[this.blendType](gl);
  5926. BlendMode.activeBlendFunction = BlendMode.fns[this.blendType];
  5927. }
  5928. }
  5929. getRenderType() {
  5930. return 0;
  5931. }
  5932. releaseRender() {
  5933. if ((--this._ref) < 1) {
  5934. var pool = SubmitTarget.POOL;
  5935. pool[pool._length++] = this;
  5936. }
  5937. }
  5938. static create(context, mesh, sv, rt) {
  5939. var o = SubmitTarget.POOL._length ? SubmitTarget.POOL[--SubmitTarget.POOL._length] : new SubmitTarget();
  5940. o._mesh = mesh;
  5941. o.srcRT = rt;
  5942. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5943. o._ref = 1;
  5944. o._key.clear();
  5945. o._numEle = 0;
  5946. o.blendType = context._nBlendType;
  5947. o._key.blendShader = o.blendType;
  5948. o.shaderValue = sv;
  5949. o.shaderValue.setValue(context._shader2D);
  5950. if (context._colorFiler) {
  5951. var ft = context._colorFiler;
  5952. sv.defines.add(ft.type);
  5953. sv.colorMat = ft._mat;
  5954. sv.colorAlpha = ft._alpha;
  5955. }
  5956. return o;
  5957. }
  5958. }
  5959. SubmitTarget.POOL = [];
  5960. {
  5961. SubmitTarget.POOL._length = 0;
  5962. }
  5963. class SubmitTexture extends SubmitBase {
  5964. constructor(renderType = SubmitBase.TYPE_2D) {
  5965. super(renderType);
  5966. }
  5967. releaseRender() {
  5968. if ((--this._ref) < 1) {
  5969. SubmitTexture.POOL[SubmitTexture._poolSize++] = this;
  5970. this.shaderValue.release();
  5971. this._mesh = null;
  5972. this._parent && (this._parent.releaseRender(), this._parent = null);
  5973. }
  5974. }
  5975. renderSubmit() {
  5976. if (this._numEle === 0)
  5977. return 1;
  5978. var tex = this.shaderValue.textureHost;
  5979. if (tex) {
  5980. var source = tex ? tex._getSource() : null;
  5981. if (!source)
  5982. return 1;
  5983. }
  5984. var gl = WebGLContext.mainContext;
  5985. this._mesh.useMesh(gl);
  5986. var lastSubmit = SubmitBase.preRender;
  5987. var prekey = SubmitBase.preRender._key;
  5988. if (this._key.blendShader === 0 && (this._key.submitType === prekey.submitType && this._key.blendShader === prekey.blendShader) && BaseShader.activeShader &&
  5989. SubmitBase.preRender.clipInfoID == this.clipInfoID &&
  5990. lastSubmit.shaderValue.defines._value === this.shaderValue.defines._value &&
  5991. (this.shaderValue.defines._value & ShaderDefines2D.NOOPTMASK) == 0) {
  5992. BaseShader.activeShader.uploadTexture2D(source);
  5993. }
  5994. else {
  5995. if (BlendMode.activeBlendFunction !== this._blendFn) {
  5996. WebGLContext.setBlend(gl, true);
  5997. this._blendFn(gl);
  5998. BlendMode.activeBlendFunction = this._blendFn;
  5999. }
  6000. this.shaderValue.texture = source;
  6001. this.shaderValue.upload();
  6002. }
  6003. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  6004. Stat.renderBatches++;
  6005. Stat.trianglesFaces += this._numEle / 3;
  6006. return 1;
  6007. }
  6008. static create(context, mesh, sv) {
  6009. var o = SubmitTexture._poolSize ? SubmitTexture.POOL[--SubmitTexture._poolSize] : new SubmitTexture(SubmitBase.TYPE_TEXTURE);
  6010. o._mesh = mesh;
  6011. o._key.clear();
  6012. o._key.submitType = SubmitBase.KEY_DRAWTEXTURE;
  6013. o._ref = 1;
  6014. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  6015. o._numEle = 0;
  6016. var blendType = context._nBlendType;
  6017. o._key.blendShader = blendType;
  6018. o._blendFn = context._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  6019. o.shaderValue = sv;
  6020. if (context._colorFiler) {
  6021. var ft = context._colorFiler;
  6022. sv.defines.add(ft.type);
  6023. sv.colorMat = ft._mat;
  6024. sv.colorAlpha = ft._alpha;
  6025. }
  6026. return o;
  6027. }
  6028. }
  6029. SubmitTexture._poolSize = 0;
  6030. SubmitTexture.POOL = [];
  6031. class CharSubmitCache {
  6032. constructor() {
  6033. this._data = [];
  6034. this._ndata = 0;
  6035. this._clipid = -1;
  6036. this._clipMatrix = new Matrix();
  6037. this._enable = false;
  6038. }
  6039. clear() {
  6040. this._tex = null;
  6041. this._imgId = -1;
  6042. this._ndata = 0;
  6043. this._enable = false;
  6044. this._colorFiler = null;
  6045. }
  6046. destroy() {
  6047. this.clear();
  6048. this._data.length = 0;
  6049. this._data = null;
  6050. }
  6051. add(ctx, tex, imgid, pos, uv, color) {
  6052. if (this._ndata > 0 && (this._tex != tex || this._imgId != imgid ||
  6053. (this._clipid >= 0 && this._clipid != ctx._clipInfoID))) {
  6054. this.submit(ctx);
  6055. }
  6056. this._clipid = ctx._clipInfoID;
  6057. ctx._globalClipMatrix.copyTo(this._clipMatrix);
  6058. this._tex = tex;
  6059. this._imgId = imgid;
  6060. this._colorFiler = ctx._colorFiler;
  6061. this._data[this._ndata] = pos;
  6062. this._data[this._ndata + 1] = uv;
  6063. this._data[this._ndata + 2] = color;
  6064. this._ndata += 3;
  6065. }
  6066. getPos() {
  6067. if (CharSubmitCache.__nPosPool == 0)
  6068. return new Array(8);
  6069. return CharSubmitCache.__posPool[--CharSubmitCache.__nPosPool];
  6070. }
  6071. enable(value, ctx) {
  6072. if (value === this._enable)
  6073. return;
  6074. this._enable = value;
  6075. this._enable || this.submit(ctx);
  6076. }
  6077. submit(ctx) {
  6078. var n = this._ndata;
  6079. if (!n)
  6080. return;
  6081. var _mesh = ctx._mesh;
  6082. var colorFiler = ctx._colorFiler;
  6083. ctx._colorFiler = this._colorFiler;
  6084. var submit = SubmitTexture.create(ctx, _mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  6085. ctx._submits[ctx._submits._length++] = ctx._curSubmit = submit;
  6086. submit.shaderValue.textureHost = this._tex;
  6087. submit._key.other = this._imgId;
  6088. ctx._colorFiler = colorFiler;
  6089. ctx._copyClipInfo(submit, this._clipMatrix);
  6090. submit.clipInfoID = this._clipid;
  6091. for (var i = 0; i < n; i += 3) {
  6092. _mesh.addQuad(this._data[i], this._data[i + 1], this._data[i + 2], true);
  6093. CharSubmitCache.__posPool[CharSubmitCache.__nPosPool++] = this._data[i];
  6094. }
  6095. n /= 3;
  6096. submit._numEle += n * 6;
  6097. _mesh.indexNum += n * 6;
  6098. _mesh.vertNum += n * 4;
  6099. ctx._drawCount += n;
  6100. this._ndata = 0;
  6101. if (RenderInfo.loopCount % 100 == 0)
  6102. this._data.length = 0;
  6103. }
  6104. }
  6105. CharSubmitCache.__posPool = [];
  6106. CharSubmitCache.__nPosPool = 0;
  6107. class AtlasGrid {
  6108. constructor(width = 0, height = 0, id = 0) {
  6109. this.atlasID = 0;
  6110. this._width = 0;
  6111. this._height = 0;
  6112. this._texCount = 0;
  6113. this._rowInfo = null;
  6114. this._cells = null;
  6115. this._used = 0;
  6116. this._cells = null;
  6117. this._rowInfo = null;
  6118. this.atlasID = id;
  6119. this._init(width, height);
  6120. }
  6121. addRect(type, width, height, pt) {
  6122. if (!this._get(width, height, pt))
  6123. return false;
  6124. this._fill(pt.x, pt.y, width, height, type);
  6125. this._texCount++;
  6126. return true;
  6127. }
  6128. _release() {
  6129. this._cells = null;
  6130. this._rowInfo = null;
  6131. }
  6132. _init(width, height) {
  6133. this._width = width;
  6134. this._height = height;
  6135. this._release();
  6136. if (this._width == 0)
  6137. return false;
  6138. this._cells = new Uint8Array(this._width * this._height * 3);
  6139. this._rowInfo = new Uint8Array(this._height);
  6140. this._used = 0;
  6141. this._clear();
  6142. return true;
  6143. }
  6144. _get(width, height, pt) {
  6145. if (width > this._width || height > this._height) {
  6146. return false;
  6147. }
  6148. var rx = -1;
  6149. var ry = -1;
  6150. var nWidth = this._width;
  6151. var nHeight = this._height;
  6152. var pCellBox = this._cells;
  6153. for (var y = 0; y < nHeight; y++) {
  6154. if (this._rowInfo[y] < width)
  6155. continue;
  6156. for (var x = 0; x < nWidth;) {
  6157. var tm = (y * nWidth + x) * 3;
  6158. if (pCellBox[tm] != 0 || pCellBox[tm + 1] < width || pCellBox[tm + 2] < height) {
  6159. x += pCellBox[tm + 1];
  6160. continue;
  6161. }
  6162. rx = x;
  6163. ry = y;
  6164. for (var xx = 0; xx < width; xx++) {
  6165. if (pCellBox[3 * xx + tm + 2] < height) {
  6166. rx = -1;
  6167. break;
  6168. }
  6169. }
  6170. if (rx < 0) {
  6171. x += pCellBox[tm + 1];
  6172. continue;
  6173. }
  6174. pt.x = rx;
  6175. pt.y = ry;
  6176. return true;
  6177. }
  6178. }
  6179. return false;
  6180. }
  6181. _fill(x, y, w, h, type) {
  6182. var nWidth = this._width;
  6183. var nHeghit = this._height;
  6184. this._check((x + w) <= nWidth && (y + h) <= nHeghit);
  6185. for (var yy = y; yy < (h + y); ++yy) {
  6186. this._check(this._rowInfo[yy] >= w);
  6187. this._rowInfo[yy] -= w;
  6188. for (var xx = 0; xx < w; xx++) {
  6189. var tm = (x + yy * nWidth + xx) * 3;
  6190. this._check(this._cells[tm] == 0);
  6191. this._cells[tm] = type;
  6192. this._cells[tm + 1] = w;
  6193. this._cells[tm + 2] = h;
  6194. }
  6195. }
  6196. if (x > 0) {
  6197. for (yy = 0; yy < h; ++yy) {
  6198. var s = 0;
  6199. for (xx = x - 1; xx >= 0; --xx, ++s) {
  6200. if (this._cells[((y + yy) * nWidth + xx) * 3] != 0)
  6201. break;
  6202. }
  6203. for (xx = s; xx > 0; --xx) {
  6204. this._cells[((y + yy) * nWidth + x - xx) * 3 + 1] = xx;
  6205. this._check(xx > 0);
  6206. }
  6207. }
  6208. }
  6209. if (y > 0) {
  6210. for (xx = x; xx < (x + w); ++xx) {
  6211. s = 0;
  6212. for (yy = y - 1; yy >= 0; --yy, s++) {
  6213. if (this._cells[(xx + yy * nWidth) * 3] != 0)
  6214. break;
  6215. }
  6216. for (yy = s; yy > 0; --yy) {
  6217. this._cells[(xx + (y - yy) * nWidth) * 3 + 2] = yy;
  6218. this._check(yy > 0);
  6219. }
  6220. }
  6221. }
  6222. this._used += (w * h) / (this._width * this._height);
  6223. }
  6224. _check(ret) {
  6225. if (ret == false) {
  6226. console.log("xtexMerger 错误啦");
  6227. }
  6228. }
  6229. _clear() {
  6230. this._texCount = 0;
  6231. for (var y = 0; y < this._height; y++) {
  6232. this._rowInfo[y] = this._width;
  6233. }
  6234. for (var i = 0; i < this._height; i++) {
  6235. for (var j = 0; j < this._width; j++) {
  6236. var tm = (i * this._width + j) * 3;
  6237. this._cells[tm] = 0;
  6238. this._cells[tm + 1] = this._width - j;
  6239. this._cells[tm + 2] = this._width - i;
  6240. }
  6241. }
  6242. }
  6243. }
  6244. class TextTexture extends Resource {
  6245. constructor(textureW, textureH) {
  6246. super();
  6247. this._texW = 0;
  6248. this._texH = 0;
  6249. this.__destroyed = false;
  6250. this._discardTm = 0;
  6251. this.genID = 0;
  6252. this.bitmap = { id: 0, _glTexture: null };
  6253. this.curUsedCovRate = 0;
  6254. this.curUsedCovRateAtlas = 0;
  6255. this.lastTouchTm = 0;
  6256. this.ri = null;
  6257. this._texW = textureW || TextTexture.gTextRender.atlasWidth;
  6258. this._texH = textureH || TextTexture.gTextRender.atlasWidth;
  6259. this.bitmap.id = this.id;
  6260. this.lock = true;
  6261. }
  6262. recreateResource() {
  6263. if (this._source)
  6264. return;
  6265. var gl = LayaGL.instance;
  6266. var glTex = this._source = gl.createTexture();
  6267. this.bitmap._glTexture = glTex;
  6268. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, glTex);
  6269. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._texW, this._texH, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  6270. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  6271. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  6272. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  6273. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  6274. if (TextTexture.gTextRender.debugUV) {
  6275. this.fillWhite();
  6276. }
  6277. }
  6278. addChar(data, x, y, uv = null) {
  6279. if (TextTexture.gTextRender.isWan1Wan) {
  6280. return this.addCharCanvas(data, x, y, uv);
  6281. }
  6282. !this._source && this.recreateResource();
  6283. var gl = LayaGL.instance;
  6284. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, this._source);
  6285. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  6286. var dt = data.data;
  6287. if (data.data instanceof Uint8ClampedArray)
  6288. dt = new Uint8Array(dt.buffer);
  6289. gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, data.width, data.height, gl.RGBA, gl.UNSIGNED_BYTE, dt);
  6290. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  6291. var u0;
  6292. var v0;
  6293. var u1;
  6294. var v1;
  6295. u0 = x / this._texW;
  6296. v0 = y / this._texH;
  6297. u1 = (x + data.width) / this._texW;
  6298. v1 = (y + data.height) / this._texH;
  6299. uv = uv || new Array(8);
  6300. uv[0] = u0, uv[1] = v0;
  6301. uv[2] = u1, uv[3] = v0;
  6302. uv[4] = u1, uv[5] = v1;
  6303. uv[6] = u0, uv[7] = v1;
  6304. return uv;
  6305. }
  6306. addCharCanvas(canv, x, y, uv = null) {
  6307. !this._source && this.recreateResource();
  6308. var gl = LayaGL.instance;
  6309. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, this._source);
  6310. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  6311. gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, gl.RGBA, gl.UNSIGNED_BYTE, canv);
  6312. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  6313. var u0;
  6314. var v0;
  6315. var u1;
  6316. var v1;
  6317. if (ILaya.Render.isConchApp) {
  6318. u0 = x / this._texW;
  6319. v0 = y / this._texH;
  6320. u1 = (x + canv.width) / this._texW;
  6321. v1 = (y + canv.height) / this._texH;
  6322. }
  6323. else {
  6324. u0 = (x + 1) / this._texW;
  6325. v0 = (y + 1) / this._texH;
  6326. u1 = (x + canv.width - 1) / this._texW;
  6327. v1 = (y + canv.height - 1) / this._texH;
  6328. }
  6329. uv = uv || new Array(8);
  6330. uv[0] = u0, uv[1] = v0;
  6331. uv[2] = u1, uv[3] = v0;
  6332. uv[4] = u1, uv[5] = v1;
  6333. uv[6] = u0, uv[7] = v1;
  6334. return uv;
  6335. }
  6336. fillWhite() {
  6337. !this._source && this.recreateResource();
  6338. var gl = LayaGL.instance;
  6339. var dt = new Uint8Array(this._texW * this._texH * 4);
  6340. dt.fill(0xff);
  6341. gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this._texW, this._texH, gl.RGBA, gl.UNSIGNED_BYTE, dt);
  6342. }
  6343. discard() {
  6344. ILaya.stage.setGlobalRepaint();
  6345. this.destroy();
  6346. return;
  6347. if (this._texW != TextTexture.gTextRender.atlasWidth || this._texH != TextTexture.gTextRender.atlasWidth) {
  6348. this.destroy();
  6349. return;
  6350. }
  6351. this.genID++;
  6352. if (TextTexture.poolLen >= TextTexture.pool.length) {
  6353. TextTexture.pool = TextTexture.pool.concat(new Array(10));
  6354. }
  6355. this._discardTm = RenderInfo.loopStTm;
  6356. TextTexture.pool[TextTexture.poolLen++] = this;
  6357. }
  6358. static getTextTexture(w, h) {
  6359. return new TextTexture(w, h);
  6360. if (w != TextTexture.gTextRender.atlasWidth || w != TextTexture.gTextRender.atlasWidth)
  6361. return new TextTexture(w, h);
  6362. if (TextTexture.poolLen > 0) {
  6363. var ret = TextTexture.pool[--TextTexture.poolLen];
  6364. if (TextTexture.poolLen > 0)
  6365. TextTexture.clean();
  6366. return ret;
  6367. }
  6368. return new TextTexture(w, h);
  6369. }
  6370. destroy() {
  6371. this.__destroyed = true;
  6372. var gl = LayaGL.instance;
  6373. this._source && gl.deleteTexture(this._source);
  6374. this._source = null;
  6375. }
  6376. static clean() {
  6377. var curtm = RenderInfo.loopStTm;
  6378. if (TextTexture.cleanTm === 0)
  6379. TextTexture.cleanTm = curtm;
  6380. if (curtm - TextTexture.cleanTm >= TextTexture.gTextRender.checkCleanTextureDt) {
  6381. for (var i = 0; i < TextTexture.poolLen; i++) {
  6382. var p = TextTexture.pool[i];
  6383. if (curtm - p._discardTm >= TextTexture.gTextRender.destroyUnusedTextureDt) {
  6384. p.destroy();
  6385. TextTexture.pool[i] = TextTexture.pool[TextTexture.poolLen - 1];
  6386. TextTexture.poolLen--;
  6387. i--;
  6388. }
  6389. }
  6390. TextTexture.cleanTm = curtm;
  6391. }
  6392. }
  6393. touchRect(ri, curloop) {
  6394. if (this.lastTouchTm != curloop) {
  6395. this.curUsedCovRate = 0;
  6396. this.curUsedCovRateAtlas = 0;
  6397. this.lastTouchTm = curloop;
  6398. }
  6399. var texw2 = TextTexture.gTextRender.atlasWidth * TextTexture.gTextRender.atlasWidth;
  6400. var gridw2 = ILaya.TextAtlas.atlasGridW * ILaya.TextAtlas.atlasGridW;
  6401. this.curUsedCovRate += (ri.bmpWidth * ri.bmpHeight) / texw2;
  6402. this.curUsedCovRateAtlas += (Math.ceil(ri.bmpWidth / ILaya.TextAtlas.atlasGridW) * Math.ceil(ri.bmpHeight / ILaya.TextAtlas.atlasGridW)) / (texw2 / gridw2);
  6403. }
  6404. get texture() {
  6405. return this;
  6406. }
  6407. _getSource() {
  6408. return this._source;
  6409. }
  6410. drawOnScreen(x, y) {
  6411. }
  6412. }
  6413. TextTexture.gTextRender = null;
  6414. TextTexture.pool = new Array(10);
  6415. TextTexture.poolLen = 0;
  6416. TextTexture.cleanTm = 0;
  6417. class TextAtlas {
  6418. constructor() {
  6419. this.texWidth = 1024;
  6420. this.texHeight = 1024;
  6421. this.texture = null;
  6422. this.charMaps = {};
  6423. this.texHeight = this.texWidth = ILaya.TextRender.atlasWidth;
  6424. this.texture = TextTexture.getTextTexture(this.texWidth, this.texHeight);
  6425. if (this.texWidth / TextAtlas.atlasGridW > 256) {
  6426. TextAtlas.atlasGridW = Math.ceil(this.texWidth / 256);
  6427. }
  6428. this.atlasgrid = new AtlasGrid(this.texWidth / TextAtlas.atlasGridW, this.texHeight / TextAtlas.atlasGridW, this.texture.id);
  6429. }
  6430. setProtecteDist(d) {
  6431. }
  6432. getAEmpty(w, h, pt) {
  6433. var find = this.atlasgrid.addRect(1, Math.ceil(w / TextAtlas.atlasGridW), Math.ceil(h / TextAtlas.atlasGridW), pt);
  6434. if (find) {
  6435. pt.x *= TextAtlas.atlasGridW;
  6436. pt.y *= TextAtlas.atlasGridW;
  6437. }
  6438. return find;
  6439. }
  6440. get usedRate() {
  6441. return this.atlasgrid._used;
  6442. }
  6443. destroy() {
  6444. for (var k in this.charMaps) {
  6445. var ri = this.charMaps[k];
  6446. ri.deleted = true;
  6447. }
  6448. this.texture.discard();
  6449. }
  6450. printDebugInfo() {
  6451. }
  6452. }
  6453. TextAtlas.atlasGridW = 16;
  6454. class Event {
  6455. setTo(type, currentTarget, target) {
  6456. this.type = type;
  6457. this.currentTarget = currentTarget;
  6458. this.target = target;
  6459. return this;
  6460. }
  6461. stopPropagation() {
  6462. this._stoped = true;
  6463. }
  6464. get touches() {
  6465. if (!this.nativeEvent)
  6466. return null;
  6467. var arr = this.nativeEvent.touches;
  6468. if (arr) {
  6469. var stage = ILaya.stage;
  6470. for (var i = 0, n = arr.length; i < n; i++) {
  6471. var e = arr[i];
  6472. var point = Point.TEMP;
  6473. point.setTo(e.clientX, e.clientY);
  6474. stage._canvasTransform.invertTransformPoint(point);
  6475. stage.transform.invertTransformPoint(point);
  6476. e.stageX = point.x;
  6477. e.stageY = point.y;
  6478. }
  6479. }
  6480. return arr;
  6481. }
  6482. get altKey() {
  6483. return this.nativeEvent.altKey;
  6484. }
  6485. get ctrlKey() {
  6486. return this.nativeEvent.ctrlKey;
  6487. }
  6488. get shiftKey() {
  6489. return this.nativeEvent.shiftKey;
  6490. }
  6491. get charCode() {
  6492. return this.nativeEvent.charCode;
  6493. }
  6494. get keyLocation() {
  6495. return this.nativeEvent.location || this.nativeEvent.keyLocation;
  6496. }
  6497. get stageX() {
  6498. return ILaya.stage.mouseX;
  6499. }
  6500. get stageY() {
  6501. return ILaya.stage.mouseY;
  6502. }
  6503. }
  6504. Event.EMPTY = new Event();
  6505. Event.MOUSE_DOWN = "mousedown";
  6506. Event.MOUSE_UP = "mouseup";
  6507. Event.CLICK = "click";
  6508. Event.RIGHT_MOUSE_DOWN = "rightmousedown";
  6509. Event.RIGHT_MOUSE_UP = "rightmouseup";
  6510. Event.RIGHT_CLICK = "rightclick";
  6511. Event.MOUSE_MOVE = "mousemove";
  6512. Event.MOUSE_OVER = "mouseover";
  6513. Event.MOUSE_OUT = "mouseout";
  6514. Event.MOUSE_WHEEL = "mousewheel";
  6515. Event.ROLL_OVER = "mouseover";
  6516. Event.ROLL_OUT = "mouseout";
  6517. Event.DOUBLE_CLICK = "doubleclick";
  6518. Event.CHANGE = "change";
  6519. Event.CHANGED = "changed";
  6520. Event.RESIZE = "resize";
  6521. Event.ADDED = "added";
  6522. Event.REMOVED = "removed";
  6523. Event.DISPLAY = "display";
  6524. Event.UNDISPLAY = "undisplay";
  6525. Event.ERROR = "error";
  6526. Event.COMPLETE = "complete";
  6527. Event.LOADED = "loaded";
  6528. Event.READY = "ready";
  6529. Event.PROGRESS = "progress";
  6530. Event.INPUT = "input";
  6531. Event.RENDER = "render";
  6532. Event.OPEN = "open";
  6533. Event.MESSAGE = "message";
  6534. Event.CLOSE = "close";
  6535. Event.KEY_DOWN = "keydown";
  6536. Event.KEY_PRESS = "keypress";
  6537. Event.KEY_UP = "keyup";
  6538. Event.FRAME = "enterframe";
  6539. Event.DRAG_START = "dragstart";
  6540. Event.DRAG_MOVE = "dragmove";
  6541. Event.DRAG_END = "dragend";
  6542. Event.ENTER = "enter";
  6543. Event.SELECT = "select";
  6544. Event.BLUR = "blur";
  6545. Event.FOCUS = "focus";
  6546. Event.VISIBILITY_CHANGE = "visibilitychange";
  6547. Event.FOCUS_CHANGE = "focuschange";
  6548. Event.PLAYED = "played";
  6549. Event.PAUSED = "paused";
  6550. Event.STOPPED = "stopped";
  6551. Event.START = "start";
  6552. Event.END = "end";
  6553. Event.COMPONENT_ADDED = "componentadded";
  6554. Event.COMPONENT_REMOVED = "componentremoved";
  6555. Event.RELEASED = "released";
  6556. Event.LINK = "link";
  6557. Event.LABEL = "label";
  6558. Event.FULL_SCREEN_CHANGE = "fullscreenchange";
  6559. Event.DEVICE_LOST = "devicelost";
  6560. Event.TRANSFORM_CHANGED = "transformchanged";
  6561. Event.ANIMATION_CHANGED = "animationchanged";
  6562. Event.TRAIL_FILTER_CHANGE = "trailfilterchange";
  6563. Event.TRIGGER_ENTER = "triggerenter";
  6564. Event.TRIGGER_STAY = "triggerstay";
  6565. Event.TRIGGER_EXIT = "triggerexit";
  6566. class Texture extends EventDispatcher {
  6567. constructor(bitmap = null, uv = null, sourceWidth = 0, sourceHeight = 0) {
  6568. super();
  6569. this.uvrect = [0, 0, 1, 1];
  6570. this._destroyed = false;
  6571. this._referenceCount = 0;
  6572. this.$_GID = 0;
  6573. this.offsetX = 0;
  6574. this.offsetY = 0;
  6575. this._w = 0;
  6576. this._h = 0;
  6577. this.sourceWidth = 0;
  6578. this.sourceHeight = 0;
  6579. this.url = null;
  6580. this.scaleRate = 1;
  6581. this.setTo(bitmap, uv, sourceWidth, sourceHeight);
  6582. }
  6583. static moveUV(offsetX, offsetY, uv) {
  6584. for (var i = 0; i < 8; i += 2) {
  6585. uv[i] += offsetX;
  6586. uv[i + 1] += offsetY;
  6587. }
  6588. return uv;
  6589. }
  6590. static create(source, x, y, width, height, offsetX = 0, offsetY = 0, sourceWidth = 0, sourceHeight = 0) {
  6591. return Texture._create(source, x, y, width, height, offsetX, offsetY, sourceWidth, sourceHeight);
  6592. }
  6593. static _create(source, x, y, width, height, offsetX = 0, offsetY = 0, sourceWidth = 0, sourceHeight = 0, outTexture = null) {
  6594. var btex = source instanceof Texture;
  6595. var uv = btex ? source.uv : Texture.DEF_UV;
  6596. var bitmap = btex ? source.bitmap : source;
  6597. if (bitmap.width && (x + width) > bitmap.width)
  6598. width = bitmap.width - x;
  6599. if (bitmap.height && (y + height) > bitmap.height)
  6600. height = bitmap.height - y;
  6601. var tex;
  6602. if (outTexture) {
  6603. tex = outTexture;
  6604. tex.setTo(bitmap, null, sourceWidth || width, sourceHeight || height);
  6605. }
  6606. else {
  6607. tex = new Texture(bitmap, null, sourceWidth || width, sourceHeight || height);
  6608. }
  6609. tex.width = width;
  6610. tex.height = height;
  6611. tex.offsetX = offsetX;
  6612. tex.offsetY = offsetY;
  6613. var dwidth = 1 / bitmap.width;
  6614. var dheight = 1 / bitmap.height;
  6615. x *= dwidth;
  6616. y *= dheight;
  6617. width *= dwidth;
  6618. height *= dheight;
  6619. var u1 = tex.uv[0], v1 = tex.uv[1], u2 = tex.uv[4], v2 = tex.uv[5];
  6620. var inAltasUVWidth = (u2 - u1), inAltasUVHeight = (v2 - v1);
  6621. var oriUV = Texture.moveUV(uv[0], uv[1], [x, y, x + width, y, x + width, y + height, x, y + height]);
  6622. tex.uv = new Float32Array([u1 + oriUV[0] * inAltasUVWidth, v1 + oriUV[1] * inAltasUVHeight,
  6623. u2 - (1 - oriUV[2]) * inAltasUVWidth, v1 + oriUV[3] * inAltasUVHeight,
  6624. u2 - (1 - oriUV[4]) * inAltasUVWidth, v2 - (1 - oriUV[5]) * inAltasUVHeight,
  6625. u1 + oriUV[6] * inAltasUVWidth, v2 - (1 - oriUV[7]) * inAltasUVHeight]);
  6626. var bitmapScale = bitmap.scaleRate;
  6627. if (bitmapScale && bitmapScale != 1) {
  6628. tex.sourceWidth /= bitmapScale;
  6629. tex.sourceHeight /= bitmapScale;
  6630. tex.width /= bitmapScale;
  6631. tex.height /= bitmapScale;
  6632. tex.scaleRate = bitmapScale;
  6633. }
  6634. else {
  6635. tex.scaleRate = 1;
  6636. }
  6637. return tex;
  6638. }
  6639. static createFromTexture(texture, x, y, width, height) {
  6640. var texScaleRate = texture.scaleRate;
  6641. if (texScaleRate != 1) {
  6642. x *= texScaleRate;
  6643. y *= texScaleRate;
  6644. width *= texScaleRate;
  6645. height *= texScaleRate;
  6646. }
  6647. var rect = Rectangle.TEMP.setTo(x - texture.offsetX, y - texture.offsetY, width, height);
  6648. var result = rect.intersection(Texture._rect1.setTo(0, 0, texture.width, texture.height), Texture._rect2);
  6649. if (result)
  6650. var tex = Texture.create(texture, result.x, result.y, result.width, result.height, result.x - rect.x, result.y - rect.y, width, height);
  6651. else
  6652. return null;
  6653. return tex;
  6654. }
  6655. get uv() {
  6656. return this._uv;
  6657. }
  6658. set uv(value) {
  6659. this.uvrect[0] = Math.min(value[0], value[2], value[4], value[6]);
  6660. this.uvrect[1] = Math.min(value[1], value[3], value[5], value[7]);
  6661. this.uvrect[2] = Math.max(value[0], value[2], value[4], value[6]) - this.uvrect[0];
  6662. this.uvrect[3] = Math.max(value[1], value[3], value[5], value[7]) - this.uvrect[1];
  6663. this._uv = value;
  6664. }
  6665. get width() {
  6666. if (this._w)
  6667. return this._w;
  6668. if (!this.bitmap)
  6669. return 0;
  6670. return (this.uv && this.uv !== Texture.DEF_UV) ? (this.uv[2] - this.uv[0]) * this.bitmap.width : this.bitmap.width;
  6671. }
  6672. set width(value) {
  6673. this._w = value;
  6674. this.sourceWidth || (this.sourceWidth = value);
  6675. }
  6676. get height() {
  6677. if (this._h)
  6678. return this._h;
  6679. if (!this.bitmap)
  6680. return 0;
  6681. return (this.uv && this.uv !== Texture.DEF_UV) ? (this.uv[5] - this.uv[1]) * this.bitmap.height : this.bitmap.height;
  6682. }
  6683. set height(value) {
  6684. this._h = value;
  6685. this.sourceHeight || (this.sourceHeight = value);
  6686. }
  6687. get bitmap() {
  6688. return this._bitmap;
  6689. }
  6690. set bitmap(value) {
  6691. this._bitmap && this._bitmap._removeReference(this._referenceCount);
  6692. this._bitmap = value;
  6693. value && (value._addReference(this._referenceCount));
  6694. }
  6695. get destroyed() {
  6696. return this._destroyed;
  6697. }
  6698. _addReference() {
  6699. this._bitmap && this._bitmap._addReference();
  6700. this._referenceCount++;
  6701. }
  6702. _removeReference() {
  6703. this._bitmap && this._bitmap._removeReference();
  6704. this._referenceCount--;
  6705. }
  6706. _getSource(cb = null) {
  6707. if (this._destroyed || !this._bitmap)
  6708. return null;
  6709. this.recoverBitmap(cb);
  6710. return this._bitmap.destroyed ? null : this.bitmap._getSource();
  6711. }
  6712. _onLoaded(complete, context) {
  6713. if (!context) ;
  6714. else if (context == this) ;
  6715. else if (context instanceof Texture) {
  6716. var tex = context;
  6717. Texture._create(context, 0, 0, tex.width, tex.height, 0, 0, tex.sourceWidth, tex.sourceHeight, this);
  6718. }
  6719. else {
  6720. this.bitmap = context;
  6721. this.sourceWidth = this._w = context.width;
  6722. this.sourceHeight = this._h = context.height;
  6723. }
  6724. complete && complete.run();
  6725. this.event(Event.READY, this);
  6726. }
  6727. getIsReady() {
  6728. return this._destroyed ? false : (this._bitmap ? true : false);
  6729. }
  6730. setTo(bitmap = null, uv = null, sourceWidth = 0, sourceHeight = 0) {
  6731. this.bitmap = bitmap;
  6732. this.sourceWidth = sourceWidth;
  6733. this.sourceHeight = sourceHeight;
  6734. if (bitmap) {
  6735. this._w = bitmap.width;
  6736. this._h = bitmap.height;
  6737. this.sourceWidth = this.sourceWidth || bitmap.width;
  6738. this.sourceHeight = this.sourceHeight || bitmap.height;
  6739. }
  6740. this.uv = uv || Texture.DEF_UV;
  6741. }
  6742. load(url, complete = null) {
  6743. if (!this._destroyed)
  6744. ILaya.loader.load(url, Handler.create(this, this._onLoaded, [complete]), null, "htmlimage", 1, true);
  6745. }
  6746. getTexturePixels(x, y, width, height) {
  6747. var st, dst, i;
  6748. var tex2d = this.bitmap;
  6749. var texw = this._w;
  6750. var texh = this._h;
  6751. var sourceWidth = this.sourceWidth;
  6752. var sourceHeight = this.sourceHeight;
  6753. var tex2dw = tex2d.width;
  6754. var tex2dh = tex2d.height;
  6755. var offsetX = this.offsetX;
  6756. var offsetY = this.offsetY;
  6757. let draww = width;
  6758. let drawh = height;
  6759. if (x + width > texw + offsetX)
  6760. draww -= (x + width) - texw - offsetX;
  6761. if (x + width > sourceWidth)
  6762. width -= (x + width) - sourceWidth;
  6763. if (y + height > texh + offsetY)
  6764. drawh -= (y + height) - texh - offsetY;
  6765. if (y + height > sourceHeight)
  6766. height -= (y + height) - sourceHeight;
  6767. if (width <= 0 || height <= 0)
  6768. return null;
  6769. let marginL = offsetX > x ? offsetX - x : 0;
  6770. let marginT = offsetY > y ? offsetY - y : 0;
  6771. let rePosX = x > offsetX ? x - offsetX : 0;
  6772. let rePosY = y > offsetY ? y - offsetY : 0;
  6773. draww -= marginL;
  6774. drawh -= marginT;
  6775. var wstride = width * 4;
  6776. var pix = null;
  6777. try {
  6778. pix = tex2d.getPixels();
  6779. }
  6780. catch (e) {
  6781. }
  6782. if (pix) {
  6783. if (x == 0 && y == 0 && width == tex2dw && height == tex2dh)
  6784. return pix;
  6785. let uv = this._uv.slice();
  6786. let atlasPosX = Math.round(uv[0] * tex2dw);
  6787. let atlasPosY = Math.round(uv[1] * tex2dh);
  6788. var ret = new Uint8Array(width * height * 4);
  6789. wstride = tex2dw * 4;
  6790. dst = (atlasPosY + rePosY) * wstride;
  6791. st = atlasPosX * 4 + rePosX * 4 + dst;
  6792. for (i = 0; i < drawh; i++) {
  6793. ret.set(pix.slice(st, st + draww * 4), width * 4 * (i + marginT) + marginL * 4);
  6794. st += wstride;
  6795. }
  6796. return ret;
  6797. }
  6798. var ctx = new ILaya.Context();
  6799. ctx.size(width, height);
  6800. ctx.asBitmap = true;
  6801. var uv = null;
  6802. if (x != 0 || y != 0 || width != tex2dw || height != tex2dh) {
  6803. uv = this._uv.slice();
  6804. var stu = uv[0];
  6805. var stv = uv[1];
  6806. var uvw = uv[2] - stu;
  6807. var uvh = uv[7] - stv;
  6808. var uk = uvw / texw;
  6809. var vk = uvh / texh;
  6810. uv = [stu + rePosX * uk, stv + rePosY * vk,
  6811. stu + (rePosX + draww) * uk, stv + rePosY * vk,
  6812. stu + (rePosX + draww) * uk, stv + (rePosY + drawh) * vk,
  6813. stu + rePosX * uk, stv + (rePosY + drawh) * vk];
  6814. }
  6815. ctx._drawTextureM(this, marginL, marginT, draww, drawh, null, 1.0, uv);
  6816. ctx._targets.start();
  6817. ctx.flush();
  6818. ctx._targets.end();
  6819. ctx._targets.restore();
  6820. var dt = ctx._targets.getData(0, 0, width, height);
  6821. ctx.destroy();
  6822. ret = new Uint8Array(width * height * 4);
  6823. st = 0;
  6824. dst = (height - 1) * wstride;
  6825. for (i = height - 1; i >= 0; i--) {
  6826. ret.set(dt.slice(dst, dst + wstride), st);
  6827. st += wstride;
  6828. dst -= wstride;
  6829. }
  6830. return ret;
  6831. }
  6832. getPixels(x, y, width, height) {
  6833. if (window.conch) {
  6834. return this._nativeObj.getImageData(x, y, width, height);
  6835. }
  6836. else {
  6837. return this.getTexturePixels(x, y, width, height);
  6838. }
  6839. }
  6840. recoverBitmap(onok = null) {
  6841. var url = this._bitmap.url;
  6842. if (!this._destroyed && (!this._bitmap || this._bitmap.destroyed) && url) {
  6843. ILaya.loader.load(url, Handler.create(this, function (bit) {
  6844. this.bitmap = bit;
  6845. onok && onok();
  6846. }), null, "htmlimage", 1, true);
  6847. }
  6848. }
  6849. disposeBitmap() {
  6850. if (!this._destroyed && this._bitmap) {
  6851. this._bitmap.destroy();
  6852. }
  6853. }
  6854. destroy(force = false) {
  6855. if (!this._destroyed) {
  6856. this._destroyed = true;
  6857. var bit = this._bitmap;
  6858. if (bit) {
  6859. bit._removeReference(this._referenceCount);
  6860. if (bit.referenceCount === 0 || force)
  6861. bit.destroy();
  6862. bit = null;
  6863. }
  6864. if (this.url && this === ILaya.loader.getRes(this.url))
  6865. ILaya.Loader.clearRes(this.url);
  6866. }
  6867. }
  6868. }
  6869. Texture.DEF_UV = new Float32Array([0, 0, 1.0, 0, 1.0, 1.0, 0, 1.0]);
  6870. Texture.NO_UV = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]);
  6871. Texture.INV_UV = new Float32Array([0, 1, 1.0, 1, 1.0, 0.0, 0, 0.0]);
  6872. Texture._rect1 = new Rectangle();
  6873. Texture._rect2 = new Rectangle();
  6874. class FontInfo {
  6875. constructor(font) {
  6876. this._font = "14px Arial";
  6877. this._family = "Arial";
  6878. this._size = 14;
  6879. this._italic = false;
  6880. this._bold = false;
  6881. this._id = FontInfo._gfontID++;
  6882. this.setFont(font || this._font);
  6883. }
  6884. static Parse(font) {
  6885. if (font === FontInfo._lastFont) {
  6886. return FontInfo._lastFontInfo;
  6887. }
  6888. var r = FontInfo._cache[font];
  6889. if (!r) {
  6890. r = FontInfo._cache[font] = new FontInfo(font);
  6891. }
  6892. FontInfo._lastFont = font;
  6893. FontInfo._lastFontInfo = r;
  6894. return r;
  6895. }
  6896. setFont(value) {
  6897. this._font = value;
  6898. var _words = value.split(' ');
  6899. var l = _words.length;
  6900. if (l < 2) {
  6901. if (l == 1) {
  6902. if (_words[0].indexOf('px') > 0) {
  6903. this._size = parseInt(_words[0]);
  6904. }
  6905. }
  6906. return;
  6907. }
  6908. var szpos = -1;
  6909. for (var i = 0; i < l; i++) {
  6910. if (_words[i].indexOf('px') > 0 || _words[i].indexOf('pt') > 0) {
  6911. szpos = i;
  6912. this._size = parseInt(_words[i]);
  6913. if (this._size <= 0) {
  6914. console.error('font parse error:' + value);
  6915. this._size = 14;
  6916. }
  6917. break;
  6918. }
  6919. }
  6920. var fpos = szpos + 1;
  6921. var familys = _words[fpos];
  6922. fpos++;
  6923. for (; fpos < l; fpos++) {
  6924. familys += ' ' + _words[fpos];
  6925. }
  6926. this._family = (familys.split(','))[0];
  6927. this._italic = _words.indexOf('italic') >= 0;
  6928. this._bold = _words.indexOf('bold') >= 0;
  6929. }
  6930. }
  6931. FontInfo.EMPTY = new FontInfo(null);
  6932. FontInfo._cache = {};
  6933. FontInfo._gfontID = 0;
  6934. FontInfo._lastFont = '';
  6935. class WordText {
  6936. constructor() {
  6937. this.save = [];
  6938. this.toUpperCase = null;
  6939. this.width = -1;
  6940. this.pageChars = [];
  6941. this.startID = 0;
  6942. this.startIDStroke = 0;
  6943. this.lastGCCnt = 0;
  6944. this.splitRender = false;
  6945. this.scalex = 1;
  6946. this.scaley = 1;
  6947. }
  6948. setText(txt) {
  6949. this.changed = true;
  6950. this._text = txt;
  6951. this.width = -1;
  6952. this.cleanCache();
  6953. }
  6954. toString() {
  6955. return this._text;
  6956. }
  6957. get length() {
  6958. return this._text ? this._text.length : 0;
  6959. }
  6960. charCodeAt(i) {
  6961. return this._text ? this._text.charCodeAt(i) : NaN;
  6962. }
  6963. charAt(i) {
  6964. return this._text ? this._text.charAt(i) : null;
  6965. }
  6966. cleanCache() {
  6967. this.pageChars.forEach(function (p) {
  6968. var tex = p.tex;
  6969. var words = p.words;
  6970. if (p.words.length == 1 && tex && tex.ri) {
  6971. tex.destroy();
  6972. }
  6973. });
  6974. this.pageChars = [];
  6975. this.startID = 0;
  6976. this.scalex = 1;
  6977. this.scaley = 1;
  6978. }
  6979. }
  6980. class CharRenderInfo {
  6981. constructor() {
  6982. this.char = '';
  6983. this.deleted = false;
  6984. this.uv = new Array(8);
  6985. this.pos = 0;
  6986. this.orix = 0;
  6987. this.oriy = 0;
  6988. this.touchTick = 0;
  6989. this.isSpace = false;
  6990. }
  6991. touch() {
  6992. var curLoop = RenderInfo.loopCount;
  6993. if (this.touchTick != curLoop) {
  6994. this.tex.touchRect(this, curLoop);
  6995. }
  6996. this.touchTick = curLoop;
  6997. }
  6998. }
  6999. class ICharRender {
  7000. constructor() {
  7001. this.fontsz = 16;
  7002. }
  7003. getWidth(font, str) { return 0; }
  7004. scale(sx, sy) {
  7005. }
  7006. get canvasWidth() {
  7007. return 0;
  7008. }
  7009. set canvasWidth(w) {
  7010. }
  7011. getCharBmp(char, font, lineWidth, colStr, strokeColStr, size, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  7012. return null;
  7013. }
  7014. }
  7015. class Browser {
  7016. static __init__() {
  7017. var Laya = window.Laya || ILaya.Laya;
  7018. if (Browser._window)
  7019. return Browser._window;
  7020. var win = Browser._window = window;
  7021. var doc = Browser._document = win.document;
  7022. var u = Browser.userAgent = win.navigator.userAgent;
  7023. var maxTouchPoints = win.navigator.maxTouchPoints || 0;
  7024. var platform = win.navigator.platform;
  7025. if (u.indexOf('AlipayMiniGame') > -1 && "my" in Browser.window) {
  7026. window.aliPayMiniGame(Laya, Laya);
  7027. if (!Laya["ALIMiniAdapter"]) {
  7028. console.error("请先添加阿里小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?language=zh&nav=zh-ts-5-6-0");
  7029. }
  7030. else {
  7031. Laya["ALIMiniAdapter"].enable();
  7032. }
  7033. }
  7034. if (u.indexOf('OPPO') == -1 && u.indexOf("MiniGame") > -1 && "wx" in Browser.window) {
  7035. if ("tt" in Browser.window) {
  7036. window.ttMiniGame(Laya, Laya);
  7037. if (!Laya["TTMiniAdapter"]) {
  7038. console.error("请引入字节跳动小游戏的适配库");
  7039. }
  7040. else {
  7041. Laya["TTMiniAdapter"].enable();
  7042. }
  7043. }
  7044. else if ("bl" in Browser.window) {
  7045. window.biliMiniGame(Laya, Laya);
  7046. if (!Laya["BLMiniAdapter"]) {
  7047. console.error("请引入bilibili小游戏的适配库,详细教程:https://ldc2.layabox.com/doc/?language=zh&nav=zh-ts-5-7-0");
  7048. }
  7049. else {
  7050. Laya["BLMiniAdapter"].enable();
  7051. }
  7052. }
  7053. else if ("qq" in Browser.window) {
  7054. window.qqMiniGame(Laya, Laya);
  7055. if (!Laya["QQMiniAdapter"]) {
  7056. console.error("请引入手机QQ小游戏的适配库,详细教程:https://ldc2.layabox.com/doc/?language=zh&nav=zh-ts-5-0-0");
  7057. }
  7058. else {
  7059. Laya["QQMiniAdapter"].enable();
  7060. }
  7061. }
  7062. else {
  7063. window.wxMiniGame(Laya, Laya);
  7064. if (!Laya["MiniAdpter"]) {
  7065. console.error("请先添加小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  7066. }
  7067. else {
  7068. Laya["MiniAdpter"].enable();
  7069. }
  7070. }
  7071. }
  7072. if ("hbs" in Browser.window) {
  7073. window.hwMiniGame(Laya, Laya);
  7074. if (!Laya["HWMiniAdapter"]) {
  7075. console.error("请先添加小游戏适配库!");
  7076. }
  7077. else {
  7078. Laya["HWMiniAdapter"].enable();
  7079. }
  7080. }
  7081. if (u.indexOf("SwanGame") > -1) {
  7082. window.bdMiniGame(Laya, Laya);
  7083. if (!Laya["BMiniAdapter"]) {
  7084. console.error("请先添加百度小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?language=zh&nav=zh-ts-5-1-0");
  7085. }
  7086. else {
  7087. Laya["BMiniAdapter"].enable();
  7088. }
  7089. }
  7090. if (u.indexOf('QuickGame') > -1) {
  7091. window.miMiniGame(Laya, Laya);
  7092. if (!Laya["KGMiniAdapter"]) {
  7093. console.error("请先添加小米小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?language=zh&nav=zh-ts-5-2-0");
  7094. }
  7095. else {
  7096. Laya["KGMiniAdapter"].enable();
  7097. }
  7098. }
  7099. if (u.indexOf('OPPO') > -1 && u.indexOf('MiniGame') > -1) {
  7100. window.qgMiniGame(Laya, Laya);
  7101. if (!Laya["QGMiniAdapter"]) {
  7102. console.error("请先添加OPPO小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?language=zh&nav=zh-ts-5-3-0");
  7103. }
  7104. else {
  7105. Laya["QGMiniAdapter"].enable();
  7106. }
  7107. }
  7108. if (u.indexOf('VVGame') > -1) {
  7109. window.vvMiniGame(Laya, Laya);
  7110. if (!Laya["VVMiniAdapter"]) {
  7111. console.error("请先添加VIVO小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?language=zh&nav=zh-ts-5-4-0");
  7112. }
  7113. else {
  7114. Laya["VVMiniAdapter"].enable();
  7115. }
  7116. }
  7117. win.trace = console.log;
  7118. win.requestAnimationFrame = win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || win.oRequestAnimationFrame || win.msRequestAnimationFrame || function (fun) {
  7119. return win.setTimeout(fun, 1000 / 60);
  7120. };
  7121. var bodyStyle = doc.body.style;
  7122. bodyStyle.margin = 0;
  7123. bodyStyle.overflow = 'hidden';
  7124. bodyStyle['-webkit-user-select'] = 'none';
  7125. bodyStyle['-webkit-tap-highlight-color'] = 'rgba(200,200,200,0)';
  7126. var metas = doc.getElementsByTagName('meta');
  7127. var i = 0, flag = false, content = 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no';
  7128. while (i < metas.length) {
  7129. var meta = metas[i];
  7130. if (meta.name == 'viewport') {
  7131. meta.content = content;
  7132. flag = true;
  7133. break;
  7134. }
  7135. i++;
  7136. }
  7137. if (!flag) {
  7138. meta = doc.createElement('meta');
  7139. meta.name = 'viewport', meta.content = content;
  7140. doc.getElementsByTagName('head')[0].appendChild(meta);
  7141. }
  7142. Browser.onMobile = window.isConchApp ? true : u.indexOf("Mobile") > -1;
  7143. Browser.onIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  7144. Browser.onIPhone = u.indexOf("iPhone") > -1;
  7145. Browser.onMac = u.indexOf("Mac OS X") > -1;
  7146. Browser.onIPad = u.indexOf("iPad") > -1 || (platform === 'MacIntel' && maxTouchPoints > 1);
  7147. Browser.onAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
  7148. Browser.onWP = u.indexOf("Windows Phone") > -1;
  7149. Browser.onQQBrowser = u.indexOf("QQBrowser") > -1;
  7150. Browser.onMQQBrowser = u.indexOf("MQQBrowser") > -1 || (u.indexOf("Mobile") > -1 && u.indexOf("QQ") > -1);
  7151. Browser.onIE = !!win.ActiveXObject || "ActiveXObject" in win;
  7152. Browser.onWeiXin = u.indexOf('MicroMessenger') > -1;
  7153. Browser.onSafari = u.indexOf("Safari") > -1;
  7154. Browser.onPC = !Browser.onMobile;
  7155. Browser.onMiniGame = u.indexOf('MiniGame') > -1;
  7156. Browser.onBDMiniGame = u.indexOf('SwanGame') > -1;
  7157. Browser.onLayaRuntime = !!Browser.window.conch;
  7158. if (u.indexOf('OPPO') > -1 && u.indexOf('MiniGame') > -1) {
  7159. Browser.onQGMiniGame = true;
  7160. Browser.onMiniGame = false;
  7161. }
  7162. else if ("qq" in Browser.window && u.indexOf('MiniGame') > -1) {
  7163. Browser.onQQMiniGame = true;
  7164. Browser.onMiniGame = false;
  7165. }
  7166. else if ("bl" in Browser.window && u.indexOf('MiniGame') > -1) {
  7167. Browser.onBLMiniGame = true;
  7168. Browser.onMiniGame = false;
  7169. }
  7170. else if ("tt" in Browser.window && u.indexOf('MiniGame') > -1) {
  7171. Browser.onTTMiniGame = true;
  7172. Browser.onMiniGame = false;
  7173. }
  7174. Browser.onHWMiniGame = "hbs" in Browser.window;
  7175. Browser.onVVMiniGame = u.indexOf('VVGame') > -1;
  7176. Browser.onKGMiniGame = u.indexOf('QuickGame') > -1;
  7177. if (u.indexOf('AlipayMiniGame') > -1) {
  7178. Browser.onAlipayMiniGame = true;
  7179. Browser.onMiniGame = false;
  7180. }
  7181. return win;
  7182. }
  7183. static createElement(type) {
  7184. Browser.__init__();
  7185. return Browser._document.createElement(type);
  7186. }
  7187. static getElementById(type) {
  7188. Browser.__init__();
  7189. return Browser._document.getElementById(type);
  7190. }
  7191. static removeElement(ele) {
  7192. if (ele && ele.parentNode)
  7193. ele.parentNode.removeChild(ele);
  7194. }
  7195. static now() {
  7196. return Date.now();
  7197. }
  7198. static get clientWidth() {
  7199. Browser.__init__();
  7200. return Browser._window.innerWidth || Browser._document.body.clientWidth;
  7201. }
  7202. static get clientHeight() {
  7203. Browser.__init__();
  7204. return Browser._window.innerHeight || Browser._document.body.clientHeight || Browser._document.documentElement.clientHeight;
  7205. }
  7206. static get width() {
  7207. Browser.__init__();
  7208. return ((ILaya.stage && ILaya.stage.canvasRotation) ? Browser.clientHeight : Browser.clientWidth) * Browser.pixelRatio;
  7209. }
  7210. static get height() {
  7211. Browser.__init__();
  7212. return ((ILaya.stage && ILaya.stage.canvasRotation) ? Browser.clientWidth : Browser.clientHeight) * Browser.pixelRatio;
  7213. }
  7214. static get pixelRatio() {
  7215. if (Browser._pixelRatio < 0) {
  7216. Browser.__init__();
  7217. if (Browser.userAgent.indexOf("Mozilla/6.0(Linux; Android 6.0; HUAWEI NXT-AL10 Build/HUAWEINXT-AL10)") > -1)
  7218. Browser._pixelRatio = 2;
  7219. else {
  7220. Browser._pixelRatio = (Browser._window.devicePixelRatio || 1);
  7221. if (Browser._pixelRatio < 1)
  7222. Browser._pixelRatio = 1;
  7223. }
  7224. }
  7225. return Browser._pixelRatio;
  7226. }
  7227. static get container() {
  7228. if (!Browser._container) {
  7229. Browser.__init__();
  7230. Browser._container = Browser.createElement("div");
  7231. Browser._container.id = "layaContainer";
  7232. Browser._document.body.appendChild(Browser._container);
  7233. }
  7234. return Browser._container;
  7235. }
  7236. static set container(value) {
  7237. Browser._container = value;
  7238. }
  7239. static get window() {
  7240. return Browser._window || Browser.__init__();
  7241. }
  7242. static get document() {
  7243. Browser.__init__();
  7244. return Browser._document;
  7245. }
  7246. }
  7247. Browser._pixelRatio = -1;
  7248. Browser.mainCanvas = null;
  7249. Browser.hanzi = new RegExp("^[\u4E00-\u9FA5]$");
  7250. Browser.fontMap = [];
  7251. Browser.measureText = function (txt, font) {
  7252. var isChinese = Browser.hanzi.test(txt);
  7253. if (isChinese && Browser.fontMap[font]) {
  7254. return Browser.fontMap[font];
  7255. }
  7256. var ctx = Browser.context;
  7257. ctx.font = font;
  7258. var r = ctx.measureText(txt);
  7259. if (isChinese)
  7260. Browser.fontMap[font] = r;
  7261. return r;
  7262. };
  7263. class CharRender_Canvas extends ICharRender {
  7264. constructor(maxw, maxh, scalefont = true, useImageData = true, showdbg = false) {
  7265. super();
  7266. this.ctx = null;
  7267. this.lastScaleX = 1.0;
  7268. this.lastScaleY = 1.0;
  7269. this.maxTexW = 0;
  7270. this.maxTexH = 0;
  7271. this.scaleFontSize = true;
  7272. this.showDbgInfo = false;
  7273. this.supportImageData = true;
  7274. this.maxTexW = maxw;
  7275. this.maxTexH = maxh;
  7276. this.scaleFontSize = scalefont;
  7277. this.supportImageData = useImageData;
  7278. this.showDbgInfo = showdbg;
  7279. if (!CharRender_Canvas.canvas) {
  7280. CharRender_Canvas.canvas = Browser.createElement('canvas');
  7281. CharRender_Canvas.canvas.width = 1024;
  7282. CharRender_Canvas.canvas.height = 512;
  7283. CharRender_Canvas.canvas.style.left = "-10000px";
  7284. CharRender_Canvas.canvas.style.position = "absolute";
  7285. document.body.appendChild(CharRender_Canvas.canvas);
  7286. this.ctx = CharRender_Canvas.canvas.getContext('2d');
  7287. }
  7288. }
  7289. get canvasWidth() {
  7290. return CharRender_Canvas.canvas.width;
  7291. }
  7292. set canvasWidth(w) {
  7293. if (CharRender_Canvas.canvas.width == w)
  7294. return;
  7295. CharRender_Canvas.canvas.width = w;
  7296. if (w > 2048) {
  7297. console.warn("画文字设置的宽度太大,超过2048了");
  7298. }
  7299. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  7300. this.ctx.scale(this.lastScaleX, this.lastScaleY);
  7301. }
  7302. getWidth(font, str) {
  7303. if (!this.ctx)
  7304. return 0;
  7305. if (this.ctx._lastFont != font) {
  7306. this.ctx.font = font;
  7307. this.ctx._lastFont = font;
  7308. }
  7309. return this.ctx.measureText(str).width;
  7310. }
  7311. scale(sx, sy) {
  7312. if (!this.supportImageData) {
  7313. this.lastScaleX = sx;
  7314. this.lastScaleY = sy;
  7315. return;
  7316. }
  7317. if (this.lastScaleX != sx || this.lastScaleY != sy) {
  7318. this.ctx.setTransform(sx, 0, 0, sy, 0, 0);
  7319. this.lastScaleX = sx;
  7320. this.lastScaleY = sy;
  7321. }
  7322. }
  7323. getCharBmp(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  7324. if (!this.supportImageData)
  7325. return this.getCharCanvas(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom);
  7326. var ctx = this.ctx;
  7327. var sz = this.fontsz;
  7328. if (ctx.font != font) {
  7329. ctx.font = font;
  7330. ctx._lastFont = font;
  7331. }
  7332. cri.width = ctx.measureText(char).width;
  7333. var w = cri.width * this.lastScaleX;
  7334. var h = cri.height * this.lastScaleY;
  7335. w += (margin_left + margin_right) * this.lastScaleX;
  7336. h += (margin_top + margin_bottom) * this.lastScaleY;
  7337. w = Math.ceil(w);
  7338. h = Math.ceil(h);
  7339. w = Math.min(w, CharRender_Canvas.canvas.width);
  7340. h = Math.min(h, CharRender_Canvas.canvas.height);
  7341. var clearW = w + lineWidth * 2 + 1;
  7342. var clearH = h + lineWidth * 2 + 1;
  7343. if (rect) {
  7344. clearW = Math.max(clearW, rect[0] + rect[2] + 1);
  7345. clearH = Math.max(clearH, rect[1] + rect[3] + 1);
  7346. }
  7347. ctx.clearRect(0, 0, clearW / this.lastScaleX + 1, clearH / this.lastScaleY + 1);
  7348. ctx.save();
  7349. ctx.textBaseline = "middle";
  7350. if (lineWidth > 0) {
  7351. ctx.strokeStyle = strokeColStr;
  7352. ctx.lineWidth = lineWidth;
  7353. ctx.strokeText(char, margin_left, margin_top + sz / 2);
  7354. }
  7355. if (colStr) {
  7356. ctx.fillStyle = colStr;
  7357. ctx.fillText(char, margin_left, margin_top + sz / 2);
  7358. }
  7359. if (this.showDbgInfo) {
  7360. ctx.strokeStyle = '#ff0000';
  7361. ctx.strokeRect(1, 1, w - 2, h - 2);
  7362. ctx.strokeStyle = '#00ff00';
  7363. ctx.strokeRect(margin_left, margin_top, cri.width, cri.height);
  7364. }
  7365. if (rect) {
  7366. if (rect[2] == -1)
  7367. rect[2] = Math.ceil((cri.width + lineWidth * 2) * this.lastScaleX);
  7368. if (rect[2] <= 0)
  7369. rect[2] = 1;
  7370. }
  7371. var imgdt = rect ? (ctx.getImageData(rect[0], rect[1], rect[2], rect[3] + 1)) : (ctx.getImageData(0, 0, w, h + 1));
  7372. ctx.restore();
  7373. cri.bmpWidth = imgdt.width;
  7374. cri.bmpHeight = imgdt.height;
  7375. return imgdt;
  7376. }
  7377. getCharCanvas(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom) {
  7378. var ctx = this.ctx;
  7379. if (ctx.font != font) {
  7380. ctx.font = font;
  7381. ctx._lastFont = font;
  7382. }
  7383. cri.width = ctx.measureText(char).width;
  7384. var w = cri.width * this.lastScaleX;
  7385. var h = cri.height * this.lastScaleY;
  7386. w += (margin_left + margin_right) * this.lastScaleX;
  7387. h += ((margin_top + margin_bottom) * this.lastScaleY + 1);
  7388. w = Math.min(w, this.maxTexW);
  7389. h = Math.min(h, this.maxTexH);
  7390. CharRender_Canvas.canvas.width = Math.min(w + 1, this.maxTexW);
  7391. CharRender_Canvas.canvas.height = Math.min(h + 1, this.maxTexH);
  7392. ctx.font = font;
  7393. ctx.clearRect(0, 0, w + 1 + lineWidth, h + 1 + lineWidth);
  7394. ctx.setTransform(1, 0, 0, 1, 0, 0);
  7395. ctx.save();
  7396. if (this.scaleFontSize) {
  7397. ctx.scale(this.lastScaleX, this.lastScaleY);
  7398. }
  7399. ctx.translate(margin_left, margin_top);
  7400. ctx.textAlign = "left";
  7401. var sz = this.fontsz;
  7402. ctx.textBaseline = "middle";
  7403. if (lineWidth > 0) {
  7404. ctx.strokeStyle = strokeColStr;
  7405. ctx.fillStyle = colStr;
  7406. ctx.lineWidth = lineWidth;
  7407. if (ctx.fillAndStrokeText) {
  7408. ctx.fillAndStrokeText(char, 0, sz / 2);
  7409. }
  7410. else {
  7411. ctx.strokeText(char, 0, sz / 2);
  7412. ctx.fillText(char, 0, sz / 2);
  7413. }
  7414. }
  7415. else if (colStr) {
  7416. ctx.fillStyle = colStr;
  7417. ctx.fillText(char, 0, sz / 2);
  7418. }
  7419. if (this.showDbgInfo) {
  7420. ctx.strokeStyle = '#ff0000';
  7421. ctx.strokeRect(0, 0, w, h);
  7422. ctx.strokeStyle = '#00ff00';
  7423. ctx.strokeRect(0, 0, cri.width, cri.height);
  7424. }
  7425. ctx.restore();
  7426. cri.bmpWidth = CharRender_Canvas.canvas.width;
  7427. cri.bmpHeight = CharRender_Canvas.canvas.height;
  7428. return CharRender_Canvas.canvas;
  7429. }
  7430. }
  7431. CharRender_Canvas.canvas = null;
  7432. class CharRender_Native extends ICharRender {
  7433. constructor() {
  7434. super();
  7435. this.lastFont = '';
  7436. this.lastScaleX = 1.0;
  7437. this.lastScaleY = 1.0;
  7438. }
  7439. getWidth(font, str) {
  7440. if (!window.conchTextCanvas)
  7441. return 0;
  7442. window.conchTextCanvas.font = font;
  7443. this.lastFont = font;
  7444. return window.conchTextCanvas.measureText(str).width;
  7445. }
  7446. scale(sx, sy) {
  7447. this.lastScaleX = sx;
  7448. this.lastScaleY = sy;
  7449. }
  7450. getCharBmp(char, font, lineWidth, colStr, strokeColStr, size, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  7451. if (!window.conchTextCanvas)
  7452. return null;
  7453. window.conchTextCanvas.font = font;
  7454. this.lastFont = font;
  7455. var w = size.width = window.conchTextCanvas.measureText(char).width;
  7456. var h = size.height;
  7457. w += (margin_left + margin_right);
  7458. h += (margin_top + margin_bottom);
  7459. window.conchTextCanvas.scale && window.conchTextCanvas.scale(this.lastScaleX, this.lastScaleY);
  7460. var c1 = ColorUtils.create(strokeColStr);
  7461. var nStrokeColor = c1.numColor;
  7462. var c2 = ColorUtils.create(colStr);
  7463. var nTextColor = c2.numColor;
  7464. var textInfo = window.conchTextCanvas.getTextBitmapData(char, nTextColor, lineWidth > 2 ? 2 : lineWidth, nStrokeColor);
  7465. size.bmpWidth = textInfo.width;
  7466. size.bmpHeight = textInfo.height;
  7467. return textInfo;
  7468. }
  7469. }
  7470. class TextRender {
  7471. constructor() {
  7472. this.fontSizeInfo = {};
  7473. this.mapFont = {};
  7474. this.fontID = 0;
  7475. this.mapColor = [];
  7476. this.colorID = 0;
  7477. this.fontScaleX = 1.0;
  7478. this.fontScaleY = 1.0;
  7479. this._curStrPos = 0;
  7480. this.textAtlases = [];
  7481. this.isoTextures = [];
  7482. this.lastFont = null;
  7483. this.fontSizeW = 0;
  7484. this.fontSizeH = 0;
  7485. this.fontSizeOffX = 0;
  7486. this.fontSizeOffY = 0;
  7487. this.renderPerChar = true;
  7488. this.tmpAtlasPos = new Point();
  7489. this.textureMem = 0;
  7490. ILaya.TextAtlas = TextAtlas;
  7491. var bugIOS = false;
  7492. var miniadp = ILaya.Laya['MiniAdpter'];
  7493. if (miniadp && miniadp.systemInfo && miniadp.systemInfo.system) {
  7494. bugIOS = miniadp.systemInfo.system.toLowerCase() === 'ios 10.1.1';
  7495. }
  7496. if ((ILaya.Browser.onMiniGame || ILaya.Browser.onTTMiniGame || ILaya.Browser.onBLMiniGame || ILaya.Browser.onAlipayMiniGame) && !bugIOS)
  7497. TextRender.isWan1Wan = true;
  7498. this.charRender = ILaya.Render.isConchApp ? (new CharRender_Native()) : (new CharRender_Canvas(2048, 2048, TextRender.scaleFontWithCtx, !TextRender.isWan1Wan, false));
  7499. TextRender.textRenderInst = this;
  7500. ILaya.Laya['textRender'] = this;
  7501. TextRender.atlasWidth2 = TextRender.atlasWidth * TextRender.atlasWidth;
  7502. }
  7503. setFont(font) {
  7504. if (this.lastFont == font)
  7505. return;
  7506. this.lastFont = font;
  7507. var fontsz = this.getFontSizeInfo(font._family);
  7508. var offx = fontsz >> 24;
  7509. var offy = (fontsz >> 16) & 0xff;
  7510. var fw = (fontsz >> 8) & 0xff;
  7511. var fh = fontsz & 0xff;
  7512. var k = font._size / TextRender.standardFontSize;
  7513. this.fontSizeOffX = Math.ceil(offx * k);
  7514. this.fontSizeOffY = Math.ceil(offy * k);
  7515. this.fontSizeW = Math.ceil(fw * k);
  7516. this.fontSizeH = Math.ceil(fh * k);
  7517. if (font._font.indexOf('italic') >= 0) {
  7518. this.fontStr = font._font.replace('italic', '');
  7519. }
  7520. else {
  7521. this.fontStr = font._font;
  7522. }
  7523. }
  7524. getNextChar(str) {
  7525. var len = str.length;
  7526. var start = this._curStrPos;
  7527. if (start >= len)
  7528. return null;
  7529. var i = start;
  7530. var state = 0;
  7531. for (; i < len; i++) {
  7532. var c = str.charCodeAt(i);
  7533. if ((c >>> 11) == 0x1b) {
  7534. if (state == 1)
  7535. break;
  7536. state = 1;
  7537. i++;
  7538. }
  7539. else if (c === 0xfe0e || c === 0xfe0f) ;
  7540. else if (c == 0x200d) {
  7541. state = 2;
  7542. }
  7543. else {
  7544. if (state == 0)
  7545. state = 1;
  7546. else if (state == 1)
  7547. break;
  7548. }
  7549. }
  7550. this._curStrPos = i;
  7551. return str.substring(start, i);
  7552. }
  7553. filltext(ctx, data, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  7554. if (data.length <= 0)
  7555. return;
  7556. var font = FontInfo.Parse(fontStr);
  7557. var nTextAlign = 0;
  7558. switch (textAlign) {
  7559. case 'center':
  7560. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  7561. break;
  7562. case 'right':
  7563. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  7564. break;
  7565. }
  7566. this._fast_filltext(ctx, data, null, x, y, font, color, strokeColor, lineWidth, nTextAlign, underLine);
  7567. }
  7568. fillWords(ctx, data, x, y, fontStr, color, strokeColor, lineWidth) {
  7569. if (!data)
  7570. return;
  7571. if (data.length <= 0)
  7572. return;
  7573. var font = typeof (fontStr) === 'string' ? FontInfo.Parse(fontStr) : fontStr;
  7574. this._fast_filltext(ctx, null, data, x, y, font, color, strokeColor, lineWidth, 0, 0);
  7575. }
  7576. _fast_filltext(ctx, data, htmlchars, x, y, font, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  7577. if (data && data.length < 1)
  7578. return;
  7579. if (htmlchars && htmlchars.length < 1)
  7580. return;
  7581. if (lineWidth < 0)
  7582. lineWidth = 0;
  7583. this.setFont(font);
  7584. this.fontScaleX = this.fontScaleY = 1.0;
  7585. if (TextRender.scaleFontWithCtx) {
  7586. var sx = 1;
  7587. var sy = 1;
  7588. if (!ILaya.Render.isConchApp || (window.conchTextCanvas.scale)) {
  7589. sx = ctx.getMatScaleX();
  7590. sy = ctx.getMatScaleY();
  7591. }
  7592. if (sx < 1e-4 || sy < 1e-1)
  7593. return;
  7594. if (sx > 1)
  7595. this.fontScaleX = sx;
  7596. if (sy > 1)
  7597. this.fontScaleY = sy;
  7598. }
  7599. font._italic && (ctx._italicDeg = 13);
  7600. var wt = data;
  7601. var isWT = !htmlchars && (data instanceof WordText);
  7602. var str = data;
  7603. var isHtmlChar = !!htmlchars;
  7604. var sameTexData = isWT ? wt.pageChars : [];
  7605. var strWidth = 0;
  7606. if (isWT) {
  7607. str = wt._text;
  7608. strWidth = wt.width;
  7609. if (strWidth < 0) {
  7610. strWidth = wt.width = this.charRender.getWidth(this.fontStr, str);
  7611. }
  7612. }
  7613. else {
  7614. strWidth = str ? this.charRender.getWidth(this.fontStr, str) : 0;
  7615. }
  7616. switch (textAlign) {
  7617. case ILaya.Context.ENUM_TEXTALIGN_CENTER:
  7618. x -= strWidth / 2;
  7619. break;
  7620. case ILaya.Context.ENUM_TEXTALIGN_RIGHT:
  7621. x -= strWidth;
  7622. break;
  7623. }
  7624. if (wt && sameTexData) {
  7625. if (this.hasFreedText(sameTexData)) {
  7626. sameTexData = wt.pageChars = [];
  7627. }
  7628. }
  7629. var ri = null;
  7630. var splitTex = this.renderPerChar = (!isWT) || TextRender.forceSplitRender || isHtmlChar || (isWT && wt.splitRender);
  7631. if (!sameTexData || sameTexData.length < 1) {
  7632. if (isWT) {
  7633. wt.scalex = this.fontScaleX;
  7634. wt.scaley = this.fontScaleY;
  7635. }
  7636. if (splitTex) {
  7637. var stx = 0;
  7638. var sty = 0;
  7639. this._curStrPos = 0;
  7640. var curstr;
  7641. while (true) {
  7642. if (htmlchars) {
  7643. var chc = htmlchars[this._curStrPos++];
  7644. if (chc) {
  7645. curstr = chc.char;
  7646. stx = chc.x;
  7647. sty = chc.y;
  7648. }
  7649. else {
  7650. curstr = null;
  7651. }
  7652. }
  7653. else {
  7654. curstr = this.getNextChar(str);
  7655. }
  7656. if (!curstr)
  7657. break;
  7658. ri = this.getCharRenderInfo(curstr, font, color, strokeColor, lineWidth, false);
  7659. if (!ri) {
  7660. break;
  7661. }
  7662. if (ri.isSpace) ;
  7663. else {
  7664. var add = sameTexData[ri.tex.id];
  7665. if (!add) {
  7666. var o1 = { texgen: ri.tex.genID, tex: ri.tex, words: [] };
  7667. sameTexData[ri.tex.id] = o1;
  7668. add = o1.words;
  7669. }
  7670. else {
  7671. add = add.words;
  7672. }
  7673. add.push({ ri: ri, x: stx, y: sty, w: ri.bmpWidth / this.fontScaleX, h: ri.bmpHeight / this.fontScaleY });
  7674. stx += ri.width;
  7675. }
  7676. }
  7677. }
  7678. else {
  7679. var margin = ILaya.Render.isConchApp ? 0 : (font._size / 3 | 0);
  7680. var isotex = TextRender.noAtlas || (strWidth + margin + margin) * this.fontScaleX > TextRender.atlasWidth;
  7681. ri = this.getCharRenderInfo(str, font, color, strokeColor, lineWidth, isotex);
  7682. sameTexData[0] = { texgen: ri.tex.genID, tex: ri.tex, words: [{ ri: ri, x: 0, y: 0, w: ri.bmpWidth / this.fontScaleX, h: ri.bmpHeight / this.fontScaleY }] };
  7683. }
  7684. }
  7685. this._drawResortedWords(ctx, x, y, sameTexData);
  7686. ctx._italicDeg = 0;
  7687. }
  7688. _drawResortedWords(ctx, startx, starty, samePagesData) {
  7689. var isLastRender = ctx._charSubmitCache ? ctx._charSubmitCache._enable : false;
  7690. var mat = ctx._curMat;
  7691. var slen = samePagesData.length;
  7692. for (var id in samePagesData) {
  7693. var dt = samePagesData[id];
  7694. if (!dt)
  7695. continue;
  7696. var pri = dt.words;
  7697. var pisz = pri.length;
  7698. if (pisz <= 0)
  7699. continue;
  7700. var tex = samePagesData[id].tex;
  7701. for (var j = 0; j < pisz; j++) {
  7702. var riSaved = pri[j];
  7703. var ri = riSaved.ri;
  7704. if (ri.isSpace)
  7705. continue;
  7706. ri.touch();
  7707. ctx.drawTexAlign = true;
  7708. if (ILaya.Render.isConchApp) {
  7709. ctx._drawTextureM(tex.texture, startx + riSaved.x - ri.orix, starty + riSaved.y - ri.oriy, riSaved.w, riSaved.h, null, 1.0, ri.uv);
  7710. }
  7711. else {
  7712. let t = tex;
  7713. ctx._inner_drawTexture(t.texture, t.id, startx + riSaved.x - ri.orix, starty + riSaved.y - ri.oriy, riSaved.w, riSaved.h, mat, ri.uv, 1.0, isLastRender);
  7714. }
  7715. if (ctx.touches) {
  7716. ctx.touches.push(ri);
  7717. }
  7718. }
  7719. }
  7720. }
  7721. hasFreedText(txts) {
  7722. var sz = txts.length;
  7723. for (var i = 0; i < sz; i++) {
  7724. var pri = txts[i];
  7725. if (!pri)
  7726. continue;
  7727. var tex = pri.tex;
  7728. if (tex.__destroyed || tex.genID != pri.texgen) {
  7729. return true;
  7730. }
  7731. }
  7732. return false;
  7733. }
  7734. getCharRenderInfo(str, font, color, strokeColor, lineWidth, isoTexture = false) {
  7735. var fid = this.mapFont[font._family];
  7736. if (fid == undefined) {
  7737. this.mapFont[font._family] = fid = this.fontID++;
  7738. }
  7739. var key = str + '_' + fid + '_' + font._size + '_' + color;
  7740. if (lineWidth > 0)
  7741. key += '_' + strokeColor + lineWidth;
  7742. if (font._bold)
  7743. key += 'P';
  7744. if (this.fontScaleX != 1 || this.fontScaleY != 1) {
  7745. key += (this.fontScaleX * 20 | 0) + '_' + (this.fontScaleY * 20 | 0);
  7746. }
  7747. var i = 0;
  7748. var sz = this.textAtlases.length;
  7749. var ri;
  7750. var atlas;
  7751. if (!isoTexture) {
  7752. for (i = 0; i < sz; i++) {
  7753. atlas = this.textAtlases[i];
  7754. ri = atlas.charMaps[key];
  7755. if (ri) {
  7756. ri.touch();
  7757. return ri;
  7758. }
  7759. }
  7760. }
  7761. ri = new CharRenderInfo();
  7762. this.charRender.scale(this.fontScaleX, this.fontScaleY);
  7763. ri.char = str;
  7764. ri.height = font._size;
  7765. var margin = ILaya.Render.isConchApp ? 0 : (font._size / 3 | 0);
  7766. var imgdt = null;
  7767. if (!lineWidth) {
  7768. lineWidth = 0;
  7769. }
  7770. var w1 = Math.ceil((this.charRender.getWidth(this.fontStr, str) + 2 * lineWidth) * this.fontScaleX);
  7771. if (w1 > this.charRender.canvasWidth) {
  7772. this.charRender.canvasWidth = Math.min(2048, w1 + margin * 2);
  7773. }
  7774. if (isoTexture) {
  7775. this.charRender.fontsz = font._size;
  7776. imgdt = this.charRender.getCharBmp(str, this.fontStr, lineWidth, color, strokeColor, ri, margin, margin, margin, margin, null);
  7777. if (imgdt) {
  7778. var tex = TextTexture.getTextTexture(imgdt.width, imgdt.height);
  7779. tex.addChar(imgdt, 0, 0, ri.uv);
  7780. ri.tex = tex;
  7781. ri.orix = margin;
  7782. ri.oriy = margin;
  7783. tex.ri = ri;
  7784. this.isoTextures.push(tex);
  7785. }
  7786. }
  7787. else {
  7788. var len = str.length;
  7789. var lineExt = lineWidth * 1;
  7790. var fw = Math.ceil((this.fontSizeW + lineExt * 2) * this.fontScaleX);
  7791. var fh = Math.ceil((this.fontSizeH + lineExt * 2) * this.fontScaleY);
  7792. TextRender.imgdtRect[0] = ((margin - this.fontSizeOffX - lineExt) * this.fontScaleX) | 0;
  7793. TextRender.imgdtRect[1] = ((margin - this.fontSizeOffY - lineExt) * this.fontScaleY) | 0;
  7794. if (this.renderPerChar || len == 1) {
  7795. TextRender.imgdtRect[2] = Math.max(w1, fw);
  7796. TextRender.imgdtRect[3] = Math.max(w1, fh);
  7797. }
  7798. else {
  7799. TextRender.imgdtRect[2] = -1;
  7800. TextRender.imgdtRect[3] = fh;
  7801. }
  7802. this.charRender.fontsz = font._size;
  7803. imgdt = this.charRender.getCharBmp(str, this.fontStr, lineWidth, color, strokeColor, ri, margin, margin, margin, margin, TextRender.imgdtRect);
  7804. if (imgdt) {
  7805. atlas = this.addBmpData(imgdt, ri);
  7806. if (TextRender.isWan1Wan) {
  7807. ri.orix = margin;
  7808. ri.oriy = margin;
  7809. }
  7810. else {
  7811. ri.orix = (this.fontSizeOffX + lineExt);
  7812. ri.oriy = (this.fontSizeOffY + lineExt);
  7813. }
  7814. atlas.charMaps[key] = ri;
  7815. }
  7816. }
  7817. return ri;
  7818. }
  7819. addBmpData(data, ri) {
  7820. var w = data.width;
  7821. var h = data.height;
  7822. var sz = this.textAtlases.length;
  7823. var atlas;
  7824. var find = false;
  7825. for (var i = 0; i < sz; i++) {
  7826. atlas = this.textAtlases[i];
  7827. find = atlas.getAEmpty(w, h, this.tmpAtlasPos);
  7828. if (find) {
  7829. break;
  7830. }
  7831. }
  7832. if (!find) {
  7833. atlas = new TextAtlas();
  7834. this.textAtlases.push(atlas);
  7835. find = atlas.getAEmpty(w, h, this.tmpAtlasPos);
  7836. if (!find) {
  7837. throw 'err1';
  7838. }
  7839. this.cleanAtlases();
  7840. }
  7841. if (find) {
  7842. atlas.texture.addChar(data, this.tmpAtlasPos.x, this.tmpAtlasPos.y, ri.uv);
  7843. ri.tex = atlas.texture;
  7844. }
  7845. return atlas;
  7846. }
  7847. GC() {
  7848. var i = 0;
  7849. var sz = this.textAtlases.length;
  7850. var dt = 0;
  7851. var destroyDt = TextRender.destroyAtlasDt;
  7852. var totalUsedRate = 0;
  7853. var totalUsedRateAtlas = 0;
  7854. var curloop = RenderInfo.loopCount;
  7855. var maxWasteRateID = -1;
  7856. var maxWasteRate = 0;
  7857. var tex = null;
  7858. var curatlas = null;
  7859. for (; i < sz; i++) {
  7860. curatlas = this.textAtlases[i];
  7861. tex = curatlas.texture;
  7862. if (tex) {
  7863. totalUsedRate += tex.curUsedCovRate;
  7864. totalUsedRateAtlas += tex.curUsedCovRateAtlas;
  7865. var waste = curatlas.usedRate - tex.curUsedCovRateAtlas;
  7866. if (maxWasteRate < waste) {
  7867. maxWasteRate = waste;
  7868. maxWasteRateID = i;
  7869. }
  7870. }
  7871. dt = curloop - curatlas.texture.lastTouchTm;
  7872. if (dt > destroyDt) {
  7873. TextRender.showLog && console.log('TextRender GC delete atlas ' + tex ? curatlas.texture.id : 'unk');
  7874. curatlas.destroy();
  7875. this.textAtlases[i] = this.textAtlases[sz - 1];
  7876. sz--;
  7877. i--;
  7878. maxWasteRateID = -1;
  7879. }
  7880. }
  7881. this.textAtlases.length = sz;
  7882. sz = this.isoTextures.length;
  7883. for (i = 0; i < sz; i++) {
  7884. tex = this.isoTextures[i];
  7885. dt = curloop - tex.lastTouchTm;
  7886. if (dt > TextRender.destroyUnusedTextureDt) {
  7887. tex.ri.deleted = true;
  7888. tex.ri.tex = null;
  7889. tex.destroy();
  7890. this.isoTextures[i] = this.isoTextures[sz - 1];
  7891. sz--;
  7892. i--;
  7893. }
  7894. }
  7895. this.isoTextures.length = sz;
  7896. var needGC = this.textAtlases.length > 1 && this.textAtlases.length - totalUsedRateAtlas >= 2;
  7897. if (TextRender.atlasWidth * TextRender.atlasWidth * 4 * this.textAtlases.length > TextRender.cleanMem || needGC || TextRender.simClean) {
  7898. TextRender.simClean = false;
  7899. TextRender.showLog && console.log('清理使用率低的贴图。总使用率:', totalUsedRateAtlas, ':', this.textAtlases.length, '最差贴图:' + maxWasteRateID);
  7900. if (maxWasteRateID >= 0) {
  7901. curatlas = this.textAtlases[maxWasteRateID];
  7902. curatlas.destroy();
  7903. this.textAtlases[maxWasteRateID] = this.textAtlases[this.textAtlases.length - 1];
  7904. this.textAtlases.length = this.textAtlases.length - 1;
  7905. }
  7906. }
  7907. TextTexture.clean();
  7908. }
  7909. cleanAtlases() {
  7910. }
  7911. getCharBmp(c) {
  7912. }
  7913. checkBmpLine(data, l, sx, ex) {
  7914. if (this.bmpData32.buffer != data.data.buffer) {
  7915. this.bmpData32 = new Uint32Array(data.data.buffer);
  7916. }
  7917. var stpos = data.width * l + sx;
  7918. for (var x = sx; x < ex; x++) {
  7919. if (this.bmpData32[stpos++] != 0)
  7920. return true;
  7921. }
  7922. return false;
  7923. }
  7924. updateBbx(data, curbbx, onlyH = false) {
  7925. var w = data.width;
  7926. var h = data.height;
  7927. var x = 0;
  7928. var sy = curbbx[1];
  7929. var ey = 0;
  7930. var y = sy;
  7931. if (this.checkBmpLine(data, sy, 0, w)) {
  7932. while (true) {
  7933. y = (sy + ey) / 2 | 0;
  7934. if (y + 1 >= sy) {
  7935. curbbx[1] = y;
  7936. break;
  7937. }
  7938. if (this.checkBmpLine(data, y, 0, w)) {
  7939. sy = y;
  7940. }
  7941. else {
  7942. ey = y;
  7943. }
  7944. }
  7945. }
  7946. if (curbbx[3] > h)
  7947. curbbx[3] = h;
  7948. else {
  7949. y = sy = curbbx[3];
  7950. ey = h;
  7951. if (this.checkBmpLine(data, sy, 0, w)) {
  7952. while (true) {
  7953. y = (sy + ey) / 2 | 0;
  7954. if (y - 1 <= sy) {
  7955. curbbx[3] = y;
  7956. break;
  7957. }
  7958. if (this.checkBmpLine(data, y, 0, w)) {
  7959. sy = y;
  7960. }
  7961. else {
  7962. ey = y;
  7963. }
  7964. }
  7965. }
  7966. }
  7967. if (onlyH)
  7968. return;
  7969. var minx = curbbx[0];
  7970. var stpos = w * curbbx[1];
  7971. for (y = curbbx[1]; y < curbbx[3]; y++) {
  7972. for (x = 0; x < minx; x++) {
  7973. if (this.bmpData32[stpos + x] != 0) {
  7974. minx = x;
  7975. break;
  7976. }
  7977. }
  7978. stpos += w;
  7979. }
  7980. curbbx[0] = minx;
  7981. var maxx = curbbx[2];
  7982. stpos = w * curbbx[1];
  7983. for (y = curbbx[1]; y < curbbx[3]; y++) {
  7984. for (x = maxx; x < w; x++) {
  7985. if (this.bmpData32[stpos + x] != 0) {
  7986. maxx = x;
  7987. break;
  7988. }
  7989. }
  7990. stpos += w;
  7991. }
  7992. curbbx[2] = maxx;
  7993. }
  7994. getFontSizeInfo(font) {
  7995. var finfo = this.fontSizeInfo[font];
  7996. if (finfo != undefined)
  7997. return finfo;
  7998. var fontstr = 'bold ' + TextRender.standardFontSize + 'px ' + font;
  7999. if (TextRender.isWan1Wan) {
  8000. this.fontSizeW = this.charRender.getWidth(fontstr, '有') * 1.5;
  8001. this.fontSizeH = TextRender.standardFontSize * 1.5;
  8002. var szinfo = this.fontSizeW << 8 | this.fontSizeH;
  8003. this.fontSizeInfo[font] = szinfo;
  8004. return szinfo;
  8005. }
  8006. TextRender.pixelBBX[0] = TextRender.standardFontSize / 2;
  8007. TextRender.pixelBBX[1] = TextRender.standardFontSize / 2;
  8008. TextRender.pixelBBX[2] = TextRender.standardFontSize;
  8009. TextRender.pixelBBX[3] = TextRender.standardFontSize;
  8010. var orix = 16;
  8011. var oriy = 16;
  8012. var marginr = 16;
  8013. var marginb = 16;
  8014. this.charRender.scale(1, 1);
  8015. TextRender.tmpRI.height = TextRender.standardFontSize;
  8016. this.charRender.fontsz = TextRender.standardFontSize;
  8017. var bmpdt = this.charRender.getCharBmp('g', fontstr, 0, 'red', null, TextRender.tmpRI, orix, oriy, marginr, marginb);
  8018. if (ILaya.Render.isConchApp) {
  8019. bmpdt.data = new Uint8ClampedArray(bmpdt.data);
  8020. }
  8021. this.bmpData32 = new Uint32Array(bmpdt.data.buffer);
  8022. this.updateBbx(bmpdt, TextRender.pixelBBX, false);
  8023. bmpdt = this.charRender.getCharBmp('有', fontstr, 0, 'red', null, TextRender.tmpRI, oriy, oriy, marginr, marginb);
  8024. if (ILaya.Render.isConchApp) {
  8025. bmpdt.data = new Uint8ClampedArray(bmpdt.data);
  8026. }
  8027. this.bmpData32 = new Uint32Array(bmpdt.data.buffer);
  8028. if (TextRender.pixelBBX[2] < orix + TextRender.tmpRI.width)
  8029. TextRender.pixelBBX[2] = orix + TextRender.tmpRI.width;
  8030. this.updateBbx(bmpdt, TextRender.pixelBBX, false);
  8031. if (ILaya.Render.isConchApp) {
  8032. orix = 0;
  8033. oriy = 0;
  8034. }
  8035. var xoff = Math.max(orix - TextRender.pixelBBX[0], 0);
  8036. var yoff = Math.max(oriy - TextRender.pixelBBX[1], 0);
  8037. var bbxw = TextRender.pixelBBX[2] - TextRender.pixelBBX[0];
  8038. var bbxh = TextRender.pixelBBX[3] - TextRender.pixelBBX[1];
  8039. var sizeinfo = xoff << 24 | yoff << 16 | bbxw << 8 | bbxh;
  8040. this.fontSizeInfo[font] = sizeinfo;
  8041. return sizeinfo;
  8042. }
  8043. printDbgInfo() {
  8044. console.log('图集个数:' + this.textAtlases.length + ',每个图集大小:' + TextRender.atlasWidth + 'x' + TextRender.atlasWidth, ' 用canvas:', TextRender.isWan1Wan);
  8045. console.log('图集占用空间:' + (TextRender.atlasWidth * TextRender.atlasWidth * 4 / 1024 / 1024 * this.textAtlases.length) + 'M');
  8046. console.log('缓存用到的字体:');
  8047. for (var f in this.mapFont) {
  8048. var fontsz = this.getFontSizeInfo(f);
  8049. var offx = fontsz >> 24;
  8050. var offy = (fontsz >> 16) & 0xff;
  8051. var fw = (fontsz >> 8) & 0xff;
  8052. var fh = fontsz & 0xff;
  8053. console.log(' ' + f, ' off:', offx, offy, ' size:', fw, fh);
  8054. }
  8055. var num = 0;
  8056. console.log('缓存数据:');
  8057. var totalUsedRate = 0;
  8058. var totalUsedRateAtlas = 0;
  8059. this.textAtlases.forEach(function (a) {
  8060. var id = a.texture.id;
  8061. var dt = RenderInfo.loopCount - a.texture.lastTouchTm;
  8062. var dtstr = dt > 0 ? ('' + dt + '帧以前') : '当前帧';
  8063. totalUsedRate += a.texture.curUsedCovRate;
  8064. totalUsedRateAtlas += a.texture.curUsedCovRateAtlas;
  8065. console.log('--图集(id:' + id + ',当前使用率:' + (a.texture.curUsedCovRate * 1000 | 0) + '‰', '当前图集使用率:', (a.texture.curUsedCovRateAtlas * 100 | 0) + '%', '图集使用率:', (a.usedRate * 100 | 0), '%, 使用于:' + dtstr + ')--:');
  8066. for (var k in a.charMaps) {
  8067. var ri = a.charMaps[k];
  8068. console.log(' off:', ri.orix, ri.oriy, ' bmp宽高:', ri.bmpWidth, ri.bmpHeight, '无效:', ri.deleted, 'touchdt:', (RenderInfo.loopCount - ri.touchTick), '位置:', ri.uv[0] * TextRender.atlasWidth | 0, ri.uv[1] * TextRender.atlasWidth | 0, '字符:', ri.char, 'key:', k);
  8069. num++;
  8070. }
  8071. });
  8072. console.log('独立贴图文字(' + this.isoTextures.length + '个):');
  8073. this.isoTextures.forEach(function (tex) {
  8074. console.log(' size:', tex._texW, tex._texH, 'touch间隔:', (RenderInfo.loopCount - tex.lastTouchTm), 'char:', tex.ri.char);
  8075. });
  8076. console.log('总缓存:', num, '总使用率:', totalUsedRate, '总当前图集使用率:', totalUsedRateAtlas);
  8077. }
  8078. showAtlas(n, bgcolor, x, y, w, h) {
  8079. if (!this.textAtlases[n]) {
  8080. console.log('没有这个图集');
  8081. return null;
  8082. }
  8083. var sp = new ILaya.Sprite();
  8084. var texttex = this.textAtlases[n].texture;
  8085. var texture = {
  8086. width: TextRender.atlasWidth,
  8087. height: TextRender.atlasWidth,
  8088. sourceWidth: TextRender.atlasWidth,
  8089. sourceHeight: TextRender.atlasWidth,
  8090. offsetX: 0,
  8091. offsetY: 0,
  8092. getIsReady: function () { return true; },
  8093. _addReference: function () { },
  8094. _removeReference: function () { },
  8095. _getSource: function () { return texttex._getSource(); },
  8096. bitmap: { id: texttex.id },
  8097. _uv: Texture.DEF_UV
  8098. };
  8099. sp.size = function (w, h) {
  8100. this.width = w;
  8101. this.height = h;
  8102. sp.graphics.clear();
  8103. sp.graphics.drawRect(0, 0, sp.width, sp.height, bgcolor);
  8104. sp.graphics.drawTexture(texture, 0, 0, sp.width, sp.height);
  8105. return this;
  8106. };
  8107. sp.graphics.drawRect(0, 0, w, h, bgcolor);
  8108. sp.graphics.drawTexture(texture, 0, 0, w, h);
  8109. sp.pos(x, y);
  8110. ILaya.stage.addChild(sp);
  8111. return sp;
  8112. }
  8113. filltext_native(ctx, data, htmlchars, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  8114. if (data && data.length <= 0)
  8115. return;
  8116. if (htmlchars && htmlchars.length < 1)
  8117. return;
  8118. var font = FontInfo.Parse(fontStr);
  8119. var nTextAlign = 0;
  8120. switch (textAlign) {
  8121. case 'center':
  8122. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  8123. break;
  8124. case 'right':
  8125. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  8126. break;
  8127. }
  8128. return this._fast_filltext(ctx, data, htmlchars, x, y, font, color, strokeColor, lineWidth, nTextAlign, underLine);
  8129. }
  8130. }
  8131. TextRender.useOldCharBook = false;
  8132. TextRender.atlasWidth = 1024;
  8133. TextRender.noAtlas = false;
  8134. TextRender.forceSplitRender = false;
  8135. TextRender.forceWholeRender = false;
  8136. TextRender.scaleFontWithCtx = true;
  8137. TextRender.standardFontSize = 32;
  8138. TextRender.destroyAtlasDt = 10;
  8139. TextRender.checkCleanTextureDt = 2000;
  8140. TextRender.destroyUnusedTextureDt = 3000;
  8141. TextRender.cleanMem = 100 * 1024 * 1024;
  8142. TextRender.isWan1Wan = false;
  8143. TextRender.showLog = false;
  8144. TextRender.debugUV = false;
  8145. TextRender.tmpRI = new CharRenderInfo();
  8146. TextRender.pixelBBX = [0, 0, 0, 0];
  8147. TextRender.imgdtRect = [0, 0, 0, 0];
  8148. TextRender.simClean = false;
  8149. TextTexture.gTextRender = TextRender;
  8150. class Context {
  8151. constructor() {
  8152. this._tmpMatrix = new Matrix();
  8153. this._drawTexToDrawTri_Vert = new Float32Array(8);
  8154. this._drawTexToDrawTri_Index = new Uint16Array([0, 1, 2, 0, 2, 3]);
  8155. this._tempUV = new Float32Array(8);
  8156. this._drawTriUseAbsMatrix = false;
  8157. this._id = ++Context._COUNT;
  8158. this._other = null;
  8159. this._renderNextSubmitIndex = 0;
  8160. this._path = null;
  8161. this._drawCount = 1;
  8162. this._width = Context._MAXSIZE;
  8163. this._height = Context._MAXSIZE;
  8164. this._renderCount = 0;
  8165. this._submits = null;
  8166. this._curSubmit = null;
  8167. this._submitKey = new SubmitKey();
  8168. this._mesh = null;
  8169. this._pathMesh = null;
  8170. this._triangleMesh = null;
  8171. this.meshlist = [];
  8172. this._transedPoints = new Array(8);
  8173. this._temp4Points = new Array(8);
  8174. this._clipRect = Context.MAXCLIPRECT;
  8175. this._globalClipMatrix = new Matrix(Context._MAXSIZE, 0, 0, Context._MAXSIZE, 0, 0);
  8176. this._clipInCache = false;
  8177. this._clipInfoID = 0;
  8178. this._clipID_Gen = 0;
  8179. this._lastMatScaleX = 1.0;
  8180. this._lastMatScaleY = 1.0;
  8181. this._lastMat_a = 1.0;
  8182. this._lastMat_b = 0.0;
  8183. this._lastMat_c = 0.0;
  8184. this._lastMat_d = 1.0;
  8185. this._nBlendType = 0;
  8186. this._save = null;
  8187. this._targets = null;
  8188. this._charSubmitCache = null;
  8189. this._saveMark = null;
  8190. this._shader2D = new Shader2D();
  8191. this.sprite = null;
  8192. this._italicDeg = 0;
  8193. this._lastTex = null;
  8194. this._fillColor = 0;
  8195. this._flushCnt = 0;
  8196. this.defTexture = null;
  8197. this._colorFiler = null;
  8198. this.drawTexAlign = false;
  8199. this._incache = false;
  8200. this.isMain = false;
  8201. Context._contextcount++;
  8202. Context._textRender = Context._textRender || new TextRender();
  8203. if (!this.defTexture) {
  8204. var defTex2d = new Texture2D(2, 2);
  8205. defTex2d.setPixels(new Uint8Array(16));
  8206. defTex2d.lock = true;
  8207. this.defTexture = new Texture(defTex2d);
  8208. }
  8209. this._lastTex = this.defTexture;
  8210. this.clear();
  8211. }
  8212. static __init__() {
  8213. Context.MAXCLIPRECT = new Rectangle(0, 0, Context._MAXSIZE, Context._MAXSIZE);
  8214. ContextParams.DEFAULT = new ContextParams();
  8215. }
  8216. drawImage(...args) {
  8217. }
  8218. getImageData(...args) {
  8219. }
  8220. measureText(text) {
  8221. return null;
  8222. }
  8223. setTransform(...args) {
  8224. }
  8225. $transform(a, b, c, d, tx, ty) {
  8226. }
  8227. get lineJoin() {
  8228. return '';
  8229. }
  8230. set lineJoin(value) {
  8231. }
  8232. get lineCap() {
  8233. return '';
  8234. }
  8235. set lineCap(value) {
  8236. }
  8237. get miterLimit() {
  8238. return '';
  8239. }
  8240. set miterLimit(value) {
  8241. }
  8242. clearRect(x, y, width, height) {
  8243. }
  8244. _drawRect(x, y, width, height, style) {
  8245. Stat.renderBatches++;
  8246. style && (this.fillStyle = style);
  8247. this.fillRect(x, y, width, height, null);
  8248. }
  8249. drawTexture2(x, y, pivotX, pivotY, m, args2) {
  8250. }
  8251. transformByMatrix(matrix, tx, ty) {
  8252. this.transform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx + tx, matrix.ty + ty);
  8253. }
  8254. saveTransform(matrix) {
  8255. this.save();
  8256. }
  8257. restoreTransform(matrix) {
  8258. this.restore();
  8259. }
  8260. drawRect(x, y, width, height, fillColor, lineColor, lineWidth) {
  8261. var ctx = this;
  8262. if (fillColor != null) {
  8263. ctx.fillStyle = fillColor;
  8264. ctx.fillRect(x, y, width, height);
  8265. }
  8266. if (lineColor != null) {
  8267. ctx.strokeStyle = lineColor;
  8268. ctx.lineWidth = lineWidth;
  8269. ctx.strokeRect(x, y, width, height);
  8270. }
  8271. }
  8272. alpha(value) {
  8273. this.globalAlpha *= value;
  8274. }
  8275. _transform(mat, pivotX, pivotY) {
  8276. this.translate(pivotX, pivotY);
  8277. this.transform(mat.a, mat.b, mat.c, mat.d, mat.tx, mat.ty);
  8278. this.translate(-pivotX, -pivotY);
  8279. }
  8280. _rotate(angle, pivotX, pivotY) {
  8281. this.translate(pivotX, pivotY);
  8282. this.rotate(angle);
  8283. this.translate(-pivotX, -pivotY);
  8284. }
  8285. _scale(scaleX, scaleY, pivotX, pivotY) {
  8286. this.translate(pivotX, pivotY);
  8287. this.scale(scaleX, scaleY);
  8288. this.translate(-pivotX, -pivotY);
  8289. }
  8290. _drawLine(x, y, fromX, fromY, toX, toY, lineColor, lineWidth, vid) {
  8291. this.beginPath();
  8292. this.strokeStyle = lineColor;
  8293. this.lineWidth = lineWidth;
  8294. this.moveTo(x + fromX, y + fromY);
  8295. this.lineTo(x + toX, y + toY);
  8296. this.stroke();
  8297. }
  8298. _drawLines(x, y, points, lineColor, lineWidth, vid) {
  8299. this.beginPath();
  8300. this.strokeStyle = lineColor;
  8301. this.lineWidth = lineWidth;
  8302. this.addPath(points.slice(), false, false, x, y);
  8303. this.stroke();
  8304. }
  8305. drawCurves(x, y, points, lineColor, lineWidth) {
  8306. this.beginPath();
  8307. this.strokeStyle = lineColor;
  8308. this.lineWidth = lineWidth;
  8309. this.moveTo(x + points[0], y + points[1]);
  8310. var i = 2, n = points.length;
  8311. while (i < n) {
  8312. this.quadraticCurveTo(x + points[i++], y + points[i++], x + points[i++], y + points[i++]);
  8313. }
  8314. this.stroke();
  8315. }
  8316. _fillAndStroke(fillColor, strokeColor, lineWidth, isConvexPolygon = false) {
  8317. if (fillColor != null) {
  8318. this.fillStyle = fillColor;
  8319. this.fill();
  8320. }
  8321. if (strokeColor != null && lineWidth > 0) {
  8322. this.strokeStyle = strokeColor;
  8323. this.lineWidth = lineWidth;
  8324. this.stroke();
  8325. }
  8326. }
  8327. _drawCircle(x, y, radius, fillColor, lineColor, lineWidth, vid) {
  8328. Stat.renderBatches++;
  8329. this.beginPath(true);
  8330. this.arc(x, y, radius, 0, Context.PI2);
  8331. this.closePath();
  8332. this._fillAndStroke(fillColor, lineColor, lineWidth);
  8333. }
  8334. _drawPie(x, y, radius, startAngle, endAngle, fillColor, lineColor, lineWidth, vid) {
  8335. this.beginPath();
  8336. this.moveTo(x, y);
  8337. this.arc(x, y, radius, startAngle, endAngle);
  8338. this.closePath();
  8339. this._fillAndStroke(fillColor, lineColor, lineWidth);
  8340. }
  8341. _drawPoly(x, y, points, fillColor, lineColor, lineWidth, isConvexPolygon, vid) {
  8342. this.beginPath();
  8343. this.addPath(points.slice(), true, isConvexPolygon, x, y);
  8344. this.closePath();
  8345. this._fillAndStroke(fillColor, lineColor, lineWidth, isConvexPolygon);
  8346. }
  8347. _drawPath(x, y, paths, brush, pen) {
  8348. this.beginPath();
  8349. for (var i = 0, n = paths.length; i < n; i++) {
  8350. var path = paths[i];
  8351. switch (path[0]) {
  8352. case "moveTo":
  8353. this.moveTo(x + path[1], y + path[2]);
  8354. break;
  8355. case "lineTo":
  8356. this.lineTo(x + path[1], y + path[2]);
  8357. break;
  8358. case "arcTo":
  8359. this.arcTo(x + path[1], y + path[2], x + path[3], y + path[4], path[5]);
  8360. break;
  8361. case "closePath":
  8362. this.closePath();
  8363. break;
  8364. }
  8365. }
  8366. if (brush != null) {
  8367. this.fillStyle = brush.fillStyle;
  8368. this.fill();
  8369. }
  8370. if (pen != null) {
  8371. this.strokeStyle = pen.strokeStyle;
  8372. this.lineWidth = pen.lineWidth || 1;
  8373. this.lineJoin = pen.lineJoin;
  8374. this.lineCap = pen.lineCap;
  8375. this.miterLimit = pen.miterLimit;
  8376. this.stroke();
  8377. }
  8378. }
  8379. static set2DRenderConfig() {
  8380. var gl = LayaGL.instance;
  8381. WebGLContext.setBlend(gl, true);
  8382. WebGLContext.setBlendEquation(gl, gl.FUNC_ADD);
  8383. BlendMode.activeBlendFunction = null;
  8384. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  8385. WebGLContext.setDepthTest(gl, false);
  8386. WebGLContext.setCullFace(gl, false);
  8387. WebGLContext.setDepthMask(gl, true);
  8388. WebGLContext.setFrontFace(gl, gl.CCW);
  8389. gl.viewport(0, 0, RenderState2D.width, RenderState2D.height);
  8390. }
  8391. clearBG(r, g, b, a) {
  8392. var gl = WebGLContext.mainContext;
  8393. gl.clearColor(r, g, b, a);
  8394. gl.clear(gl.COLOR_BUFFER_BIT);
  8395. }
  8396. _getSubmits() {
  8397. return this._submits;
  8398. }
  8399. _releaseMem(keepRT = false) {
  8400. if (!this._submits)
  8401. return;
  8402. this._curMat && this._curMat.destroy();
  8403. this._curMat = null;
  8404. this._shader2D.destroy();
  8405. this._shader2D = null;
  8406. this._charSubmitCache.clear();
  8407. for (var i = 0, n = this._submits._length; i < n; i++) {
  8408. this._submits[i].releaseRender();
  8409. }
  8410. this._submits.length = 0;
  8411. this._submits._length = 0;
  8412. this._submits = null;
  8413. this._curSubmit = null;
  8414. this._path = null;
  8415. this._save = null;
  8416. var sz;
  8417. for (i = 0, sz = this.meshlist.length; i < sz; i++) {
  8418. var curm = this.meshlist[i];
  8419. curm.destroy();
  8420. }
  8421. this.meshlist.length = 0;
  8422. this.sprite = null;
  8423. if (!keepRT) {
  8424. this._targets && (this._targets.destroy());
  8425. this._targets = null;
  8426. }
  8427. }
  8428. destroy(keepRT = false) {
  8429. --Context._contextcount;
  8430. this.sprite = null;
  8431. this._releaseMem(keepRT);
  8432. this._charSubmitCache.destroy();
  8433. this._mesh.destroy();
  8434. if (!keepRT) {
  8435. this._targets && this._targets.destroy();
  8436. this._targets = null;
  8437. }
  8438. }
  8439. clear() {
  8440. if (!this._submits) {
  8441. this._other = ContextParams.DEFAULT;
  8442. this._curMat = Matrix.create();
  8443. this._charSubmitCache = new CharSubmitCache();
  8444. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8445. this.meshlist.push(this._mesh);
  8446. this._pathMesh = MeshVG.getAMesh(this.isMain);
  8447. this.meshlist.push(this._pathMesh);
  8448. this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  8449. this.meshlist.push(this._triangleMesh);
  8450. this._submits = [];
  8451. this._save = [SaveMark.Create(this)];
  8452. this._save.length = 10;
  8453. this._shader2D = new Shader2D();
  8454. }
  8455. this._submitKey.clear();
  8456. this._mesh.clearVB();
  8457. this._drawCount = 1;
  8458. this._other = ContextParams.DEFAULT;
  8459. this._other.lineWidth = this._shader2D.ALPHA = 1.0;
  8460. this._nBlendType = 0;
  8461. this._clipRect = Context.MAXCLIPRECT;
  8462. this._curSubmit = SubmitBase.RENDERBASE;
  8463. SubmitBase.RENDERBASE._ref = 0xFFFFFF;
  8464. SubmitBase.RENDERBASE._numEle = 0;
  8465. this._shader2D.fillStyle = this._shader2D.strokeStyle = DrawStyle.DEFAULT;
  8466. for (var i = 0, n = this._submits._length; i < n; i++)
  8467. this._submits[i].releaseRender();
  8468. this._submits._length = 0;
  8469. this._curMat.identity();
  8470. this._other.clear();
  8471. this._saveMark = this._save[0];
  8472. this._save._length = 1;
  8473. }
  8474. size(w, h) {
  8475. if (this._width != w || this._height != h) {
  8476. this._width = w;
  8477. this._height = h;
  8478. if (this._targets) {
  8479. this._targets.destroy();
  8480. this._targets = new RenderTexture2D(w, h, exports.RenderTextureFormat.R8G8B8A8, -1);
  8481. }
  8482. if (this.isMain) {
  8483. WebGLContext.mainContext.viewport(0, 0, w, h);
  8484. RenderState2D.width = w;
  8485. RenderState2D.height = h;
  8486. }
  8487. }
  8488. if (w === 0 && h === 0)
  8489. this._releaseMem();
  8490. }
  8491. set asBitmap(value) {
  8492. if (value) {
  8493. let rt = this._targets;
  8494. if (!this._width || !this._height)
  8495. throw Error("asBitmap no size!");
  8496. if (!rt || rt.width != this._width || rt.height != this._height) {
  8497. if (rt) {
  8498. rt.destroy();
  8499. }
  8500. this._targets = new RenderTexture2D(this._width, this._height, exports.RenderTextureFormat.R8G8B8A8, -1);
  8501. }
  8502. }
  8503. else {
  8504. this._targets && this._targets.destroy();
  8505. this._targets = null;
  8506. }
  8507. }
  8508. getMatScaleX() {
  8509. if (this._lastMat_a == this._curMat.a && this._lastMat_b == this._curMat.b)
  8510. return this._lastMatScaleX;
  8511. this._lastMatScaleX = this._curMat.getScaleX();
  8512. this._lastMat_a = this._curMat.a;
  8513. this._lastMat_b = this._curMat.b;
  8514. return this._lastMatScaleX;
  8515. }
  8516. getMatScaleY() {
  8517. if (this._lastMat_c == this._curMat.c && this._lastMat_d == this._curMat.d)
  8518. return this._lastMatScaleY;
  8519. this._lastMatScaleY = this._curMat.getScaleY();
  8520. this._lastMat_c = this._curMat.c;
  8521. this._lastMat_d = this._curMat.d;
  8522. return this._lastMatScaleY;
  8523. }
  8524. setFillColor(color) {
  8525. this._fillColor = color;
  8526. }
  8527. getFillColor() {
  8528. return this._fillColor;
  8529. }
  8530. set fillStyle(value) {
  8531. if (!this._shader2D.fillStyle.equal(value)) {
  8532. SaveBase.save(this, SaveBase.TYPE_FILESTYLE, this._shader2D, false);
  8533. this._shader2D.fillStyle = DrawStyle.create(value);
  8534. this._submitKey.other = -this._shader2D.fillStyle.toInt();
  8535. }
  8536. }
  8537. get fillStyle() {
  8538. return this._shader2D.fillStyle;
  8539. }
  8540. set globalAlpha(value) {
  8541. value = Math.floor(value * 1000) / 1000;
  8542. if (value != this._shader2D.ALPHA) {
  8543. SaveBase.save(this, SaveBase.TYPE_ALPHA, this._shader2D, false);
  8544. this._shader2D.ALPHA = value;
  8545. }
  8546. }
  8547. get globalAlpha() {
  8548. return this._shader2D.ALPHA;
  8549. }
  8550. set textAlign(value) {
  8551. (this._other.textAlign === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_TEXTALIGN, this._other, false), this._other.textAlign = value);
  8552. }
  8553. get textAlign() {
  8554. return this._other.textAlign;
  8555. }
  8556. set textBaseline(value) {
  8557. (this._other.textBaseline === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_TEXTBASELINE, this._other, false), this._other.textBaseline = value);
  8558. }
  8559. get textBaseline() {
  8560. return this._other.textBaseline;
  8561. }
  8562. set globalCompositeOperation(value) {
  8563. var n = BlendMode.TOINT[value];
  8564. n == null || (this._nBlendType === n) || (SaveBase.save(this, SaveBase.TYPE_GLOBALCOMPOSITEOPERATION, this, true), this._curSubmit = SubmitBase.RENDERBASE, this._nBlendType = n);
  8565. }
  8566. get globalCompositeOperation() {
  8567. return BlendMode.NAMES[this._nBlendType];
  8568. }
  8569. set strokeStyle(value) {
  8570. this._shader2D.strokeStyle.equal(value) || (SaveBase.save(this, SaveBase.TYPE_STROKESTYLE, this._shader2D, false), this._shader2D.strokeStyle = DrawStyle.create(value), this._submitKey.other = -this._shader2D.strokeStyle.toInt());
  8571. }
  8572. get strokeStyle() {
  8573. return this._shader2D.strokeStyle;
  8574. }
  8575. translate(x, y) {
  8576. if (x !== 0 || y !== 0) {
  8577. SaveTranslate.save(this);
  8578. if (this._curMat._bTransform) {
  8579. SaveTransform.save(this);
  8580. this._curMat.tx += (x * this._curMat.a + y * this._curMat.c);
  8581. this._curMat.ty += (x * this._curMat.b + y * this._curMat.d);
  8582. }
  8583. else {
  8584. this._curMat.tx = x;
  8585. this._curMat.ty = y;
  8586. }
  8587. }
  8588. }
  8589. set lineWidth(value) {
  8590. (this._other.lineWidth === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_LINEWIDTH, this._other, false), this._other.lineWidth = value);
  8591. }
  8592. get lineWidth() {
  8593. return this._other.lineWidth;
  8594. }
  8595. save() {
  8596. this._save[this._save._length++] = SaveMark.Create(this);
  8597. }
  8598. restore() {
  8599. var sz = this._save._length;
  8600. var lastBlend = this._nBlendType;
  8601. if (sz < 1)
  8602. return;
  8603. for (var i = sz - 1; i >= 0; i--) {
  8604. var o = this._save[i];
  8605. o.restore(this);
  8606. if (o.isSaveMark()) {
  8607. this._save._length = i;
  8608. return;
  8609. }
  8610. }
  8611. if (lastBlend != this._nBlendType) {
  8612. this._curSubmit = SubmitBase.RENDERBASE;
  8613. }
  8614. }
  8615. set font(str) {
  8616. this._other = this._other.make();
  8617. SaveBase.save(this, SaveBase.TYPE_FONT, this._other, false);
  8618. }
  8619. fillText(txt, x, y, fontStr, color, align, lineWidth = 0, borderColor = "") {
  8620. Context._textRender.filltext(this, txt, x, y, fontStr, color, borderColor, lineWidth, align);
  8621. }
  8622. drawText(text, x, y, font, color, textAlign) {
  8623. Context._textRender.filltext(this, text, x, y, font, color, null, 0, textAlign);
  8624. }
  8625. fillWords(words, x, y, fontStr, color) {
  8626. Context._textRender.fillWords(this, words, x, y, fontStr, color, null, 0);
  8627. }
  8628. strokeWord(text, x, y, font, color, lineWidth, textAlign) {
  8629. Context._textRender.filltext(this, text, x, y, font, null, color, lineWidth, textAlign);
  8630. }
  8631. fillBorderText(txt, x, y, font, color, borderColor, lineWidth, textAlign) {
  8632. Context._textRender.filltext(this, txt, x, y, font, color, borderColor, lineWidth, textAlign);
  8633. }
  8634. fillBorderWords(words, x, y, font, color, borderColor, lineWidth) {
  8635. Context._textRender.fillWords(this, words, x, y, font, color, borderColor, lineWidth);
  8636. }
  8637. _fast_filltext(data, x, y, fontObj, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  8638. Context._textRender._fast_filltext(this, data, null, x, y, fontObj, color, strokeColor, lineWidth, textAlign, underLine);
  8639. }
  8640. _fillRect(x, y, width, height, rgba) {
  8641. var submit = this._curSubmit;
  8642. var sameKey = submit && (submit._key.submitType === SubmitBase.KEY_DRAWTEXTURE && submit._key.blendShader === this._nBlendType);
  8643. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8644. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8645. this.meshlist.push(this._mesh);
  8646. sameKey = false;
  8647. }
  8648. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  8649. this.transformQuad(x, y, width, height, 0, this._curMat, this._transedPoints);
  8650. if (!this.clipedOff(this._transedPoints)) {
  8651. this._mesh.addQuad(this._transedPoints, Texture.NO_UV, rgba, false);
  8652. if (!sameKey) {
  8653. submit = this._curSubmit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8654. this._submits[this._submits._length++] = submit;
  8655. this._copyClipInfo(submit, this._globalClipMatrix);
  8656. submit.shaderValue.textureHost = this._lastTex;
  8657. submit._key.other = (this._lastTex && this._lastTex.bitmap) ? this._lastTex.bitmap.id : -1;
  8658. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8659. }
  8660. this._curSubmit._numEle += 6;
  8661. this._mesh.indexNum += 6;
  8662. this._mesh.vertNum += 4;
  8663. }
  8664. }
  8665. fillRect(x, y, width, height, fillStyle) {
  8666. var drawstyle = fillStyle ? DrawStyle.create(fillStyle) : this._shader2D.fillStyle;
  8667. var rgba = this.mixRGBandAlpha(drawstyle.toInt());
  8668. this._fillRect(x, y, width, height, rgba);
  8669. }
  8670. fillTexture(texture, x, y, width, height, type, offset, other) {
  8671. if (!texture._getSource()) {
  8672. this.sprite && ILaya.systemTimer.callLater(this, this._repaintSprite);
  8673. return;
  8674. }
  8675. this._fillTexture(texture, texture.width, texture.height, texture.uvrect, x, y, width, height, type, offset.x, offset.y);
  8676. }
  8677. _fillTexture(texture, texw, texh, texuvRect, x, y, width, height, type, offsetx, offsety) {
  8678. var submit = this._curSubmit;
  8679. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8680. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8681. this.meshlist.push(this._mesh);
  8682. }
  8683. var repeatx = true;
  8684. var repeaty = true;
  8685. switch (type) {
  8686. case "repeat": break;
  8687. case "repeat-x":
  8688. repeaty = false;
  8689. break;
  8690. case "repeat-y":
  8691. repeatx = false;
  8692. break;
  8693. case "no-repeat":
  8694. repeatx = repeaty = false;
  8695. break;
  8696. default: break;
  8697. }
  8698. var uv = this._temp4Points;
  8699. var stu = 0;
  8700. var stv = 0;
  8701. var stx = 0, sty = 0, edx = 0, edy = 0;
  8702. if (offsetx < 0) {
  8703. stx = x;
  8704. stu = (-offsetx % texw) / texw;
  8705. }
  8706. else {
  8707. stx = x + offsetx;
  8708. }
  8709. if (offsety < 0) {
  8710. sty = y;
  8711. stv = (-offsety % texh) / texh;
  8712. }
  8713. else {
  8714. sty = y + offsety;
  8715. }
  8716. edx = x + width;
  8717. edy = y + height;
  8718. (!repeatx) && (edx = Math.min(edx, x + offsetx + texw));
  8719. (!repeaty) && (edy = Math.min(edy, y + offsety + texh));
  8720. if (edx < x || edy < y)
  8721. return;
  8722. if (stx > edx || sty > edy)
  8723. return;
  8724. var edu = (edx - x - offsetx) / texw;
  8725. var edv = (edy - y - offsety) / texh;
  8726. this.transformQuad(stx, sty, edx - stx, edy - sty, 0, this._curMat, this._transedPoints);
  8727. uv[0] = stu;
  8728. uv[1] = stv;
  8729. uv[2] = edu;
  8730. uv[3] = stv;
  8731. uv[4] = edu;
  8732. uv[5] = edv;
  8733. uv[6] = stu;
  8734. uv[7] = edv;
  8735. if (!this.clipedOff(this._transedPoints)) {
  8736. var rgba = this._mixRGBandAlpha(0xffffffff, this._shader2D.ALPHA);
  8737. this._mesh.addQuad(this._transedPoints, uv, rgba, true);
  8738. var sv = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  8739. sv.defines.add(ShaderDefines2D.FILLTEXTURE);
  8740. sv.u_TexRange = texuvRect.concat();
  8741. submit = this._curSubmit = SubmitTexture.create(this, this._mesh, sv);
  8742. this._submits[this._submits._length++] = submit;
  8743. this._copyClipInfo(submit, this._globalClipMatrix);
  8744. submit.shaderValue.textureHost = texture;
  8745. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8746. this._curSubmit._numEle += 6;
  8747. this._mesh.indexNum += 6;
  8748. this._mesh.vertNum += 4;
  8749. }
  8750. this.breakNextMerge();
  8751. }
  8752. setColorFilter(filter) {
  8753. SaveBase.save(this, SaveBase.TYPE_COLORFILTER, this, true);
  8754. this._colorFiler = filter;
  8755. this._curSubmit = SubmitBase.RENDERBASE;
  8756. }
  8757. drawTexture(tex, x, y, width, height) {
  8758. this._drawTextureM(tex, x, y, width, height, null, 1, null);
  8759. }
  8760. drawTextures(tex, pos, tx, ty) {
  8761. if (!tex._getSource()) {
  8762. this.sprite && ILaya.systemTimer.callLater(this, this._repaintSprite);
  8763. return;
  8764. }
  8765. var n = pos.length / 2;
  8766. var ipos = 0;
  8767. var bmpid = tex.bitmap.id;
  8768. for (var i = 0; i < n; i++) {
  8769. this._inner_drawTexture(tex, bmpid, pos[ipos++] + tx, pos[ipos++] + ty, 0, 0, null, null, 1.0, false);
  8770. }
  8771. }
  8772. _drawTextureAddSubmit(imgid, tex) {
  8773. var submit = null;
  8774. submit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8775. this._submits[this._submits._length++] = submit;
  8776. submit.shaderValue.textureHost = tex;
  8777. submit._key.other = imgid;
  8778. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8779. this._curSubmit = submit;
  8780. }
  8781. _drawTextureM(tex, x, y, width, height, m, alpha, uv) {
  8782. var cs = this.sprite;
  8783. if (!tex._getSource(function () {
  8784. if (cs) {
  8785. cs.repaint();
  8786. }
  8787. })) {
  8788. return false;
  8789. }
  8790. return this._inner_drawTexture(tex, tex.bitmap.id, x, y, width, height, m, uv, alpha, false);
  8791. }
  8792. _drawRenderTexture(tex, x, y, width, height, m, alpha, uv) {
  8793. return this._inner_drawTexture(tex, -1, x, y, width, height, m, uv, 1.0, false);
  8794. }
  8795. submitDebugger() {
  8796. this._submits[this._submits._length++] = SubmitCMD.create([], function () { debugger; }, this);
  8797. }
  8798. _copyClipInfo(submit, clipInfo) {
  8799. var cm = submit.shaderValue.clipMatDir;
  8800. cm[0] = clipInfo.a;
  8801. cm[1] = clipInfo.b;
  8802. cm[2] = clipInfo.c;
  8803. cm[3] = clipInfo.d;
  8804. var cmp = submit.shaderValue.clipMatPos;
  8805. cmp[0] = clipInfo.tx;
  8806. cmp[1] = clipInfo.ty;
  8807. submit.clipInfoID = this._clipInfoID;
  8808. if (this._clipInCache) {
  8809. submit.shaderValue.clipOff[0] = 1;
  8810. }
  8811. }
  8812. isSameClipInfo(submit) {
  8813. return (submit.clipInfoID === this._clipInfoID);
  8814. }
  8815. _useNewTex2DSubmit(tex, minVertNum) {
  8816. if (this._mesh.vertNum + minVertNum > Context._MAXVERTNUM) {
  8817. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8818. this.meshlist.push(this._mesh);
  8819. }
  8820. var submit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8821. this._submits[this._submits._length++] = this._curSubmit = submit;
  8822. submit.shaderValue.textureHost = tex;
  8823. this._copyClipInfo(submit, this._globalClipMatrix);
  8824. }
  8825. _drawTexRect(x, y, w, h, uv) {
  8826. this.transformQuad(x, y, w, h, this._italicDeg, this._curMat, this._transedPoints);
  8827. var ops = this._transedPoints;
  8828. ops[0] = (ops[0] + 0.5) | 0;
  8829. ops[1] = (ops[1] + 0.5) | 0;
  8830. ops[2] = (ops[2] + 0.5) | 0;
  8831. ops[3] = (ops[3] + 0.5) | 0;
  8832. ops[4] = (ops[4] + 0.5) | 0;
  8833. ops[5] = (ops[5] + 0.5) | 0;
  8834. ops[6] = (ops[6] + 0.5) | 0;
  8835. ops[7] = (ops[7] + 0.5) | 0;
  8836. if (!this.clipedOff(this._transedPoints)) {
  8837. this._mesh.addQuad(this._transedPoints, uv, this._fillColor, true);
  8838. this._curSubmit._numEle += 6;
  8839. this._mesh.indexNum += 6;
  8840. this._mesh.vertNum += 4;
  8841. }
  8842. }
  8843. drawCallOptimize(enable) {
  8844. this._charSubmitCache.enable(enable, this);
  8845. return enable;
  8846. }
  8847. _inner_drawTexture(tex, imgid, x, y, width, height, m, uv, alpha, lastRender) {
  8848. if (width <= 0 || height <= 0) {
  8849. return;
  8850. }
  8851. var preKey = this._curSubmit._key;
  8852. uv = uv || tex._uv;
  8853. if (preKey.submitType === SubmitBase.KEY_TRIANGLES && preKey.other === imgid) {
  8854. var tv = this._drawTexToDrawTri_Vert;
  8855. tv[0] = x;
  8856. tv[1] = y;
  8857. tv[2] = x + width, tv[3] = y, tv[4] = x + width, tv[5] = y + height, tv[6] = x, tv[7] = y + height;
  8858. this._drawTriUseAbsMatrix = true;
  8859. var tuv = this._tempUV;
  8860. tuv[0] = uv[0];
  8861. tuv[1] = uv[1];
  8862. tuv[2] = uv[2];
  8863. tuv[3] = uv[3];
  8864. tuv[4] = uv[4];
  8865. tuv[5] = uv[5];
  8866. tuv[6] = uv[6];
  8867. tuv[7] = uv[7];
  8868. this.drawTriangles(tex, 0, 0, tv, tuv, this._drawTexToDrawTri_Index, m, alpha, null, null);
  8869. this._drawTriUseAbsMatrix = false;
  8870. return true;
  8871. }
  8872. var mesh = this._mesh;
  8873. var submit = this._curSubmit;
  8874. var ops = lastRender ? this._charSubmitCache.getPos() : this._transedPoints;
  8875. this.transformQuad(x, y, width || tex.width, height || tex.height, this._italicDeg, m || this._curMat, ops);
  8876. if (this.drawTexAlign) {
  8877. var round = Math.round;
  8878. ops[0] = round(ops[0]);
  8879. ops[1] = round(ops[1]);
  8880. ops[2] = round(ops[2]);
  8881. ops[3] = round(ops[3]);
  8882. ops[4] = round(ops[4]);
  8883. ops[5] = round(ops[5]);
  8884. ops[6] = round(ops[6]);
  8885. ops[7] = round(ops[7]);
  8886. this.drawTexAlign = false;
  8887. }
  8888. var rgba = this._mixRGBandAlpha(0xffffffff, this._shader2D.ALPHA * alpha);
  8889. if (lastRender) {
  8890. this._charSubmitCache.add(this, tex, imgid, ops, uv, rgba);
  8891. return true;
  8892. }
  8893. this._drawCount++;
  8894. var sameKey = imgid >= 0 && preKey.submitType === SubmitBase.KEY_DRAWTEXTURE && preKey.other === imgid;
  8895. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  8896. this._lastTex = tex;
  8897. if (mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8898. mesh = this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8899. this.meshlist.push(mesh);
  8900. sameKey = false;
  8901. }
  8902. {
  8903. mesh.addQuad(ops, uv, rgba, true);
  8904. if (!sameKey) {
  8905. this._submits[this._submits._length++] = this._curSubmit = submit = SubmitTexture.create(this, mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8906. submit.shaderValue.textureHost = tex;
  8907. submit._key.other = imgid;
  8908. this._copyClipInfo(submit, this._globalClipMatrix);
  8909. }
  8910. submit._numEle += 6;
  8911. mesh.indexNum += 6;
  8912. mesh.vertNum += 4;
  8913. return true;
  8914. }
  8915. return false;
  8916. }
  8917. transform4Points(a, m, out) {
  8918. var tx = m.tx;
  8919. var ty = m.ty;
  8920. var ma = m.a;
  8921. var mb = m.b;
  8922. var mc = m.c;
  8923. var md = m.d;
  8924. var a0 = a[0];
  8925. var a1 = a[1];
  8926. var a2 = a[2];
  8927. var a3 = a[3];
  8928. var a4 = a[4];
  8929. var a5 = a[5];
  8930. var a6 = a[6];
  8931. var a7 = a[7];
  8932. if (m._bTransform) {
  8933. out[0] = a0 * ma + a1 * mc + tx;
  8934. out[1] = a0 * mb + a1 * md + ty;
  8935. out[2] = a2 * ma + a3 * mc + tx;
  8936. out[3] = a2 * mb + a3 * md + ty;
  8937. out[4] = a4 * ma + a5 * mc + tx;
  8938. out[5] = a4 * mb + a5 * md + ty;
  8939. out[6] = a6 * ma + a7 * mc + tx;
  8940. out[7] = a6 * mb + a7 * md + ty;
  8941. }
  8942. else {
  8943. out[0] = a0 + tx;
  8944. out[1] = a1 + ty;
  8945. out[2] = a2 + tx;
  8946. out[3] = a3 + ty;
  8947. out[4] = a4 + tx;
  8948. out[5] = a5 + ty;
  8949. out[6] = a6 + tx;
  8950. out[7] = a7 + ty;
  8951. }
  8952. }
  8953. clipedOff(pt) {
  8954. if (this._clipRect.width <= 0 || this._clipRect.height <= 0)
  8955. return true;
  8956. return false;
  8957. }
  8958. transformQuad(x, y, w, h, italicDeg, m, out) {
  8959. var xoff = 0;
  8960. if (italicDeg != 0) {
  8961. xoff = Math.tan(italicDeg * Math.PI / 180) * h;
  8962. }
  8963. var maxx = x + w;
  8964. var maxy = y + h;
  8965. var tx = m.tx;
  8966. var ty = m.ty;
  8967. var ma = m.a;
  8968. var mb = m.b;
  8969. var mc = m.c;
  8970. var md = m.d;
  8971. var a0 = x + xoff;
  8972. var a1 = y;
  8973. var a2 = maxx + xoff;
  8974. var a3 = y;
  8975. var a4 = maxx;
  8976. var a5 = maxy;
  8977. var a6 = x;
  8978. var a7 = maxy;
  8979. if (m._bTransform) {
  8980. out[0] = a0 * ma + a1 * mc + tx;
  8981. out[1] = a0 * mb + a1 * md + ty;
  8982. out[2] = a2 * ma + a3 * mc + tx;
  8983. out[3] = a2 * mb + a3 * md + ty;
  8984. out[4] = a4 * ma + a5 * mc + tx;
  8985. out[5] = a4 * mb + a5 * md + ty;
  8986. out[6] = a6 * ma + a7 * mc + tx;
  8987. out[7] = a6 * mb + a7 * md + ty;
  8988. }
  8989. else {
  8990. out[0] = a0 + tx;
  8991. out[1] = a1 + ty;
  8992. out[2] = a2 + tx;
  8993. out[3] = a3 + ty;
  8994. out[4] = a4 + tx;
  8995. out[5] = a5 + ty;
  8996. out[6] = a6 + tx;
  8997. out[7] = a7 + ty;
  8998. }
  8999. }
  9000. pushRT() {
  9001. this.addRenderObject(SubmitCMD.create(null, RenderTexture2D.pushRT, this));
  9002. }
  9003. popRT() {
  9004. this.addRenderObject(SubmitCMD.create(null, RenderTexture2D.popRT, this));
  9005. this.breakNextMerge();
  9006. }
  9007. useRT(rt) {
  9008. function _use(rt) {
  9009. if (!rt) {
  9010. throw 'error useRT';
  9011. }
  9012. else {
  9013. rt.start();
  9014. rt.clear(0, 0, 0, 0);
  9015. }
  9016. }
  9017. this.addRenderObject(SubmitCMD.create([rt], _use, this));
  9018. this.breakNextMerge();
  9019. }
  9020. RTRestore(rt) {
  9021. function _restore(rt) {
  9022. rt.restore();
  9023. }
  9024. this.addRenderObject(SubmitCMD.create([rt], _restore, this));
  9025. this.breakNextMerge();
  9026. }
  9027. breakNextMerge() {
  9028. this._curSubmit = SubmitBase.RENDERBASE;
  9029. }
  9030. _repaintSprite() {
  9031. this.sprite && this.sprite.repaint();
  9032. }
  9033. drawTextureWithTransform(tex, x, y, width, height, transform, tx, ty, alpha, blendMode, colorfilter = null, uv) {
  9034. var oldcomp;
  9035. var curMat = this._curMat;
  9036. if (blendMode) {
  9037. oldcomp = this.globalCompositeOperation;
  9038. this.globalCompositeOperation = blendMode;
  9039. }
  9040. var oldColorFilter = this._colorFiler;
  9041. if (colorfilter) {
  9042. this.setColorFilter(colorfilter);
  9043. }
  9044. if (!transform) {
  9045. this._drawTextureM(tex, x + tx, y + ty, width, height, curMat, alpha, uv);
  9046. if (blendMode) {
  9047. this.globalCompositeOperation = oldcomp;
  9048. }
  9049. if (colorfilter) {
  9050. this.setColorFilter(oldColorFilter);
  9051. }
  9052. return;
  9053. }
  9054. var tmpMat = this._tmpMatrix;
  9055. tmpMat.a = transform.a;
  9056. tmpMat.b = transform.b;
  9057. tmpMat.c = transform.c;
  9058. tmpMat.d = transform.d;
  9059. tmpMat.tx = transform.tx + tx;
  9060. tmpMat.ty = transform.ty + ty;
  9061. tmpMat._bTransform = transform._bTransform;
  9062. if (transform && curMat._bTransform) {
  9063. Matrix.mul(tmpMat, curMat, tmpMat);
  9064. transform = tmpMat;
  9065. transform._bTransform = true;
  9066. }
  9067. else {
  9068. tmpMat.tx += curMat.tx;
  9069. tmpMat.ty += curMat.ty;
  9070. transform = tmpMat;
  9071. }
  9072. this._drawTextureM(tex, x, y, width, height, transform, alpha, uv);
  9073. if (blendMode) {
  9074. this.globalCompositeOperation = oldcomp;
  9075. }
  9076. if (colorfilter) {
  9077. this.setColorFilter(oldColorFilter);
  9078. }
  9079. }
  9080. _flushToTarget(context, target) {
  9081. RenderState2D.worldScissorTest = false;
  9082. var gl = LayaGL.instance;
  9083. gl.disable(gl.SCISSOR_TEST);
  9084. var preAlpha = RenderState2D.worldAlpha;
  9085. var preMatrix4 = RenderState2D.worldMatrix4;
  9086. var preMatrix = RenderState2D.worldMatrix;
  9087. RenderState2D.worldMatrix = Matrix.EMPTY;
  9088. RenderState2D.restoreTempArray();
  9089. RenderState2D.worldMatrix4 = RenderState2D.TEMPMAT4_ARRAY;
  9090. RenderState2D.worldAlpha = 1;
  9091. BaseShader.activeShader = null;
  9092. target.start();
  9093. if (context._submits._length > 0)
  9094. target.clear(0, 0, 0, 0);
  9095. context._curSubmit = SubmitBase.RENDERBASE;
  9096. context.flush();
  9097. context.clear();
  9098. target.restore();
  9099. context._curSubmit = SubmitBase.RENDERBASE;
  9100. BaseShader.activeShader = null;
  9101. RenderState2D.worldAlpha = preAlpha;
  9102. RenderState2D.worldMatrix4 = preMatrix4;
  9103. RenderState2D.worldMatrix = preMatrix;
  9104. }
  9105. drawCanvas(canvas, x, y, width, height) {
  9106. if (!canvas)
  9107. return;
  9108. var src = canvas.context;
  9109. var submit;
  9110. if (src._targets) {
  9111. if (src._submits._length > 0) {
  9112. submit = SubmitCMD.create([src, src._targets], this._flushToTarget, this);
  9113. this._submits[this._submits._length++] = submit;
  9114. }
  9115. this._drawRenderTexture(src._targets, x, y, width, height, null, 1.0, RenderTexture2D.flipyuv);
  9116. this._curSubmit = SubmitBase.RENDERBASE;
  9117. }
  9118. else {
  9119. var canv = canvas;
  9120. if (canv.touches) {
  9121. canv.touches.forEach(function (v) { v.touch(); });
  9122. }
  9123. submit = SubmitCanvas.create(canvas, this._shader2D.ALPHA, this._shader2D.filters);
  9124. this._submits[this._submits._length++] = submit;
  9125. submit._key.clear();
  9126. var mat = submit._matrix;
  9127. this._curMat.copyTo(mat);
  9128. var tx = mat.tx, ty = mat.ty;
  9129. mat.tx = mat.ty = 0;
  9130. mat.transformPoint(Point.TEMP.setTo(x, y));
  9131. mat.translate(Point.TEMP.x + tx, Point.TEMP.y + ty);
  9132. Matrix.mul(canv.invMat, mat, mat);
  9133. this._curSubmit = SubmitBase.RENDERBASE;
  9134. }
  9135. }
  9136. drawTarget(rt, x, y, width, height, m, shaderValue, uv = null, blend = -1) {
  9137. this._drawCount++;
  9138. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  9139. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  9140. this.meshlist.push(this._mesh);
  9141. }
  9142. this.transformQuad(x, y, width, height, 0, m || this._curMat, this._transedPoints);
  9143. if (!this.clipedOff(this._transedPoints)) {
  9144. this._mesh.addQuad(this._transedPoints, uv || Texture.DEF_UV, 0xffffffff, true);
  9145. var submit = this._curSubmit = SubmitTarget.create(this, this._mesh, shaderValue, rt);
  9146. submit.blendType = (blend == -1) ? this._nBlendType : blend;
  9147. this._copyClipInfo(submit, this._globalClipMatrix);
  9148. submit._numEle = 6;
  9149. this._mesh.indexNum += 6;
  9150. this._mesh.vertNum += 4;
  9151. this._submits[this._submits._length++] = submit;
  9152. this._curSubmit = SubmitBase.RENDERBASE;
  9153. return true;
  9154. }
  9155. this._curSubmit = SubmitBase.RENDERBASE;
  9156. return false;
  9157. }
  9158. drawTriangles(tex, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode, colorNum = 0xffffffff) {
  9159. if (!tex._getSource()) {
  9160. if (this.sprite) {
  9161. ILaya.systemTimer.callLater(this, this._repaintSprite);
  9162. }
  9163. return;
  9164. }
  9165. var oldcomp = null;
  9166. if (blendMode) {
  9167. oldcomp = this.globalCompositeOperation;
  9168. this.globalCompositeOperation = blendMode;
  9169. }
  9170. this._drawCount++;
  9171. var tmpMat = this._tmpMatrix;
  9172. var triMesh = this._triangleMesh;
  9173. var oldColorFilter = null;
  9174. var needRestorFilter = false;
  9175. if (color) {
  9176. oldColorFilter = this._colorFiler;
  9177. this._colorFiler = color;
  9178. this._curSubmit = SubmitBase.RENDERBASE;
  9179. needRestorFilter = oldColorFilter != color;
  9180. }
  9181. var webGLImg = tex.bitmap;
  9182. var preKey = this._curSubmit._key;
  9183. var sameKey = preKey.submitType === SubmitBase.KEY_TRIANGLES && preKey.other === webGLImg.id && preKey.blendShader == this._nBlendType;
  9184. if (triMesh.vertNum + vertices.length / 2 > Context._MAXVERTNUM) {
  9185. triMesh = this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  9186. this.meshlist.push(triMesh);
  9187. sameKey = false;
  9188. }
  9189. if (!sameKey) {
  9190. var submit = this._curSubmit = SubmitTexture.create(this, triMesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  9191. submit.shaderValue.textureHost = tex;
  9192. submit._renderType = SubmitBase.TYPE_TEXTURE;
  9193. submit._key.submitType = SubmitBase.KEY_TRIANGLES;
  9194. submit._key.other = webGLImg.id;
  9195. this._copyClipInfo(submit, this._globalClipMatrix);
  9196. this._submits[this._submits._length++] = submit;
  9197. }
  9198. var rgba = this._mixRGBandAlpha(colorNum, this._shader2D.ALPHA * alpha);
  9199. if (!this._drawTriUseAbsMatrix) {
  9200. if (!matrix) {
  9201. tmpMat.a = 1;
  9202. tmpMat.b = 0;
  9203. tmpMat.c = 0;
  9204. tmpMat.d = 1;
  9205. tmpMat.tx = x;
  9206. tmpMat.ty = y;
  9207. }
  9208. else {
  9209. tmpMat.a = matrix.a;
  9210. tmpMat.b = matrix.b;
  9211. tmpMat.c = matrix.c;
  9212. tmpMat.d = matrix.d;
  9213. tmpMat.tx = matrix.tx + x;
  9214. tmpMat.ty = matrix.ty + y;
  9215. }
  9216. Matrix.mul(tmpMat, this._curMat, tmpMat);
  9217. triMesh.addData(vertices, uvs, indices, tmpMat || this._curMat, rgba);
  9218. }
  9219. else {
  9220. triMesh.addData(vertices, uvs, indices, matrix, rgba);
  9221. }
  9222. this._curSubmit._numEle += indices.length;
  9223. if (needRestorFilter) {
  9224. this._colorFiler = oldColorFilter;
  9225. this._curSubmit = SubmitBase.RENDERBASE;
  9226. }
  9227. if (blendMode) {
  9228. this.globalCompositeOperation = oldcomp;
  9229. }
  9230. }
  9231. transform(a, b, c, d, tx, ty) {
  9232. SaveTransform.save(this);
  9233. Matrix.mul(Matrix.TEMP.setTo(a, b, c, d, tx, ty), this._curMat, this._curMat);
  9234. this._curMat._checkTransform();
  9235. }
  9236. _transformByMatrix(matrix, tx, ty) {
  9237. matrix.setTranslate(tx, ty);
  9238. Matrix.mul(matrix, this._curMat, this._curMat);
  9239. matrix.setTranslate(0, 0);
  9240. this._curMat._bTransform = true;
  9241. }
  9242. setTransformByMatrix(value) {
  9243. value.copyTo(this._curMat);
  9244. }
  9245. rotate(angle) {
  9246. SaveTransform.save(this);
  9247. this._curMat.rotateEx(angle);
  9248. }
  9249. scale(scaleX, scaleY) {
  9250. SaveTransform.save(this);
  9251. this._curMat.scaleEx(scaleX, scaleY);
  9252. }
  9253. clipRect(x, y, width, height) {
  9254. SaveClipRect.save(this);
  9255. if (this._clipRect == Context.MAXCLIPRECT) {
  9256. this._clipRect = new Rectangle(x, y, width, height);
  9257. }
  9258. else {
  9259. this._clipRect.width = width;
  9260. this._clipRect.height = height;
  9261. this._clipRect.x = x;
  9262. this._clipRect.y = y;
  9263. }
  9264. this._clipID_Gen++;
  9265. this._clipID_Gen %= 10000;
  9266. this._clipInfoID = this._clipID_Gen;
  9267. var cm = this._globalClipMatrix;
  9268. var minx = cm.tx;
  9269. var miny = cm.ty;
  9270. var maxx = minx + cm.a;
  9271. var maxy = miny + cm.d;
  9272. if (this._clipRect.width >= Context._MAXSIZE) {
  9273. cm.a = cm.d = Context._MAXSIZE;
  9274. cm.b = cm.c = cm.tx = cm.ty = 0;
  9275. }
  9276. else {
  9277. if (this._curMat._bTransform) {
  9278. cm.tx = this._clipRect.x * this._curMat.a + this._clipRect.y * this._curMat.c + this._curMat.tx;
  9279. cm.ty = this._clipRect.x * this._curMat.b + this._clipRect.y * this._curMat.d + this._curMat.ty;
  9280. cm.a = this._clipRect.width * this._curMat.a;
  9281. cm.b = this._clipRect.width * this._curMat.b;
  9282. cm.c = this._clipRect.height * this._curMat.c;
  9283. cm.d = this._clipRect.height * this._curMat.d;
  9284. }
  9285. else {
  9286. cm.tx = this._clipRect.x + this._curMat.tx;
  9287. cm.ty = this._clipRect.y + this._curMat.ty;
  9288. cm.a = this._clipRect.width;
  9289. cm.b = cm.c = 0;
  9290. cm.d = this._clipRect.height;
  9291. }
  9292. if (this._incache) {
  9293. this._clipInCache = true;
  9294. }
  9295. }
  9296. if (cm.a > 0 && cm.d > 0) {
  9297. var cmaxx = cm.tx + cm.a;
  9298. var cmaxy = cm.ty + cm.d;
  9299. if (cmaxx <= minx || cmaxy <= miny || cm.tx >= maxx || cm.ty >= maxy) {
  9300. cm.a = -0.1;
  9301. cm.d = -0.1;
  9302. }
  9303. else {
  9304. if (cm.tx < minx) {
  9305. cm.a -= (minx - cm.tx);
  9306. cm.tx = minx;
  9307. }
  9308. if (cmaxx > maxx) {
  9309. cm.a -= (cmaxx - maxx);
  9310. }
  9311. if (cm.ty < miny) {
  9312. cm.d -= (miny - cm.ty);
  9313. cm.ty = miny;
  9314. }
  9315. if (cmaxy > maxy) {
  9316. cm.d -= (cmaxy - maxy);
  9317. }
  9318. if (cm.a <= 0)
  9319. cm.a = -0.1;
  9320. if (cm.d <= 0)
  9321. cm.d = -0.1;
  9322. }
  9323. }
  9324. }
  9325. drawMesh(x, y, ib, vb, numElement, mat, shader, shaderValues, startIndex = 0) {
  9326. }
  9327. addRenderObject(o) {
  9328. this._submits[this._submits._length++] = o;
  9329. }
  9330. submitElement(start, end) {
  9331. var mainCtx = this.isMain;
  9332. var renderList = this._submits;
  9333. var ret = renderList._length;
  9334. end < 0 && (end = renderList._length);
  9335. var submit = SubmitBase.RENDERBASE;
  9336. while (start < end) {
  9337. this._renderNextSubmitIndex = start + 1;
  9338. if (renderList[start] === SubmitBase.RENDERBASE) {
  9339. start++;
  9340. continue;
  9341. }
  9342. SubmitBase.preRender = submit;
  9343. submit = renderList[start];
  9344. start += submit.renderSubmit();
  9345. }
  9346. return ret;
  9347. }
  9348. flush() {
  9349. this._clipID_Gen = 0;
  9350. var ret = this.submitElement(0, this._submits._length);
  9351. this._path && this._path.reset();
  9352. SkinMeshBuffer.instance && SkinMeshBuffer.getInstance().reset();
  9353. this._curSubmit = SubmitBase.RENDERBASE;
  9354. for (var i = 0, sz = this.meshlist.length; i < sz; i++) {
  9355. var curm = this.meshlist[i];
  9356. curm.canReuse ? (curm.releaseMesh()) : (curm.destroy());
  9357. }
  9358. this.meshlist.length = 0;
  9359. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  9360. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9361. this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  9362. this.meshlist.push(this._mesh, this._pathMesh, this._triangleMesh);
  9363. this._flushCnt++;
  9364. if (this._flushCnt % 60 == 0 && this.isMain) {
  9365. if (TextRender.textRenderInst) {
  9366. TextRender.textRenderInst.GC();
  9367. }
  9368. }
  9369. return ret;
  9370. }
  9371. beginPath(convex = false) {
  9372. var tPath = this._getPath();
  9373. tPath.beginPath(convex);
  9374. }
  9375. closePath() {
  9376. this._path.closePath();
  9377. }
  9378. addPath(points, close, convex, dx, dy) {
  9379. var ci = 0;
  9380. for (var i = 0, sz = points.length / 2; i < sz; i++) {
  9381. var x1 = points[ci] + dx, y1 = points[ci + 1] + dy;
  9382. points[ci] = x1;
  9383. points[ci + 1] = y1;
  9384. ci += 2;
  9385. }
  9386. this._getPath().push(points, convex);
  9387. }
  9388. fill() {
  9389. var m = this._curMat;
  9390. var tPath = this._getPath();
  9391. var submit = this._curSubmit;
  9392. var sameKey = (submit._key.submitType === SubmitBase.KEY_VG && submit._key.blendShader === this._nBlendType);
  9393. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  9394. if (!sameKey) {
  9395. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9396. }
  9397. var rgba = this.mixRGBandAlpha(this.fillStyle.toInt());
  9398. var curEleNum = 0;
  9399. var idx;
  9400. for (var i = 0, sz = tPath.paths.length; i < sz; i++) {
  9401. var p = tPath.paths[i];
  9402. var vertNum = p.path.length / 2;
  9403. if (vertNum < 3 || (vertNum == 3 && !p.convex))
  9404. continue;
  9405. var cpath = p.path.concat();
  9406. var pi = 0;
  9407. var xp, yp;
  9408. var _x, _y;
  9409. if (m._bTransform) {
  9410. for (pi = 0; pi < vertNum; pi++) {
  9411. xp = pi << 1;
  9412. yp = xp + 1;
  9413. _x = cpath[xp];
  9414. _y = cpath[yp];
  9415. cpath[xp] = m.a * _x + m.c * _y + m.tx;
  9416. cpath[yp] = m.b * _x + m.d * _y + m.ty;
  9417. }
  9418. }
  9419. else {
  9420. for (pi = 0; pi < vertNum; pi++) {
  9421. xp = pi << 1;
  9422. yp = xp + 1;
  9423. _x = cpath[xp];
  9424. _y = cpath[yp];
  9425. cpath[xp] = _x + m.tx;
  9426. cpath[yp] = _y + m.ty;
  9427. }
  9428. }
  9429. if (this._pathMesh.vertNum + vertNum > Context._MAXVERTNUM) {
  9430. this._curSubmit._numEle += curEleNum;
  9431. curEleNum = 0;
  9432. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9433. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9434. }
  9435. var curvert = this._pathMesh.vertNum;
  9436. if (p.convex) {
  9437. var faceNum = vertNum - 2;
  9438. idx = new Array(faceNum * 3);
  9439. var idxpos = 0;
  9440. for (var fi = 0; fi < faceNum; fi++) {
  9441. idx[idxpos++] = curvert;
  9442. idx[idxpos++] = fi + 1 + curvert;
  9443. idx[idxpos++] = fi + 2 + curvert;
  9444. }
  9445. }
  9446. else {
  9447. idx = Earcut.earcut(cpath, null, 2);
  9448. if (curvert > 0) {
  9449. for (var ii = 0; ii < idx.length; ii++) {
  9450. idx[ii] += curvert;
  9451. }
  9452. }
  9453. }
  9454. this._pathMesh.addVertAndIBToMesh(this, cpath, rgba, idx);
  9455. curEleNum += idx.length;
  9456. }
  9457. this._curSubmit._numEle += curEleNum;
  9458. }
  9459. addVGSubmit(mesh) {
  9460. var submit = Submit.createShape(this, mesh, 0, Value2D.create(ShaderDefines2D.PRIMITIVE, 0));
  9461. submit._key.submitType = SubmitBase.KEY_VG;
  9462. this._submits[this._submits._length++] = submit;
  9463. this._copyClipInfo(submit, this._globalClipMatrix);
  9464. return submit;
  9465. }
  9466. stroke() {
  9467. if (this.lineWidth > 0) {
  9468. var rgba = this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  9469. var tPath = this._getPath();
  9470. var submit = this._curSubmit;
  9471. var sameKey = (submit._key.submitType === SubmitBase.KEY_VG && submit._key.blendShader === this._nBlendType);
  9472. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  9473. if (!sameKey) {
  9474. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9475. }
  9476. var curEleNum = 0;
  9477. for (var i = 0, sz = tPath.paths.length; i < sz; i++) {
  9478. var p = tPath.paths[i];
  9479. if (p.path.length <= 0)
  9480. continue;
  9481. var idx = [];
  9482. var vertex = [];
  9483. var maxVertexNum = p.path.length * 2;
  9484. if (maxVertexNum < 2)
  9485. continue;
  9486. if (this._pathMesh.vertNum + maxVertexNum > Context._MAXVERTNUM) {
  9487. this._curSubmit._numEle += curEleNum;
  9488. curEleNum = 0;
  9489. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9490. this.meshlist.push(this._pathMesh);
  9491. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9492. }
  9493. BasePoly.createLine2(p.path, idx, this.lineWidth, this._pathMesh.vertNum, vertex, p.loop);
  9494. var ptnum = vertex.length / 2;
  9495. var m = this._curMat;
  9496. var pi = 0;
  9497. var xp, yp;
  9498. var _x, _y;
  9499. if (m._bTransform) {
  9500. for (pi = 0; pi < ptnum; pi++) {
  9501. xp = pi << 1;
  9502. yp = xp + 1;
  9503. _x = vertex[xp];
  9504. _y = vertex[yp];
  9505. vertex[xp] = m.a * _x + m.c * _y + m.tx;
  9506. vertex[yp] = m.b * _x + m.d * _y + m.ty;
  9507. }
  9508. }
  9509. else {
  9510. for (pi = 0; pi < ptnum; pi++) {
  9511. xp = pi << 1;
  9512. yp = xp + 1;
  9513. _x = vertex[xp];
  9514. _y = vertex[yp];
  9515. vertex[xp] = _x + m.tx;
  9516. vertex[yp] = _y + m.ty;
  9517. }
  9518. }
  9519. this._pathMesh.addVertAndIBToMesh(this, vertex, rgba, idx);
  9520. curEleNum += idx.length;
  9521. }
  9522. this._curSubmit._numEle += curEleNum;
  9523. }
  9524. }
  9525. moveTo(x, y) {
  9526. var tPath = this._getPath();
  9527. tPath.newPath();
  9528. tPath._lastOriX = x;
  9529. tPath._lastOriY = y;
  9530. tPath.addPoint(x, y);
  9531. }
  9532. lineTo(x, y) {
  9533. var tPath = this._getPath();
  9534. if (Math.abs(x - tPath._lastOriX) < 1e-3 && Math.abs(y - tPath._lastOriY) < 1e-3)
  9535. return;
  9536. tPath._lastOriX = x;
  9537. tPath._lastOriY = y;
  9538. tPath.addPoint(x, y);
  9539. }
  9540. arcTo(x1, y1, x2, y2, r) {
  9541. var i = 0;
  9542. var x = 0, y = 0;
  9543. var dx = this._path._lastOriX - x1;
  9544. var dy = this._path._lastOriY - y1;
  9545. var len1 = Math.sqrt(dx * dx + dy * dy);
  9546. if (len1 <= 0.000001) {
  9547. return;
  9548. }
  9549. var ndx = dx / len1;
  9550. var ndy = dy / len1;
  9551. var dx2 = x2 - x1;
  9552. var dy2 = y2 - y1;
  9553. var len22 = dx2 * dx2 + dy2 * dy2;
  9554. var len2 = Math.sqrt(len22);
  9555. if (len2 <= 0.000001) {
  9556. return;
  9557. }
  9558. var ndx2 = dx2 / len2;
  9559. var ndy2 = dy2 / len2;
  9560. var odx = ndx + ndx2;
  9561. var ody = ndy + ndy2;
  9562. var olen = Math.sqrt(odx * odx + ody * ody);
  9563. if (olen <= 0.000001) {
  9564. return;
  9565. }
  9566. var nOdx = odx / olen;
  9567. var nOdy = ody / olen;
  9568. var alpha = Math.acos(nOdx * ndx + nOdy * ndy);
  9569. var halfAng = Math.PI / 2 - alpha;
  9570. len1 = r / Math.tan(halfAng);
  9571. var ptx1 = len1 * ndx + x1;
  9572. var pty1 = len1 * ndy + y1;
  9573. var orilen = Math.sqrt(len1 * len1 + r * r);
  9574. var orix = x1 + nOdx * orilen;
  9575. var oriy = y1 + nOdy * orilen;
  9576. var dir = ndx * ndy2 - ndy * ndx2;
  9577. var fChgAng = 0;
  9578. var sinx = 0.0;
  9579. var cosx = 0.0;
  9580. if (dir >= 0) {
  9581. fChgAng = halfAng * 2;
  9582. var fda = fChgAng / Context.SEGNUM;
  9583. sinx = Math.sin(fda);
  9584. cosx = Math.cos(fda);
  9585. }
  9586. else {
  9587. fChgAng = -halfAng * 2;
  9588. fda = fChgAng / Context.SEGNUM;
  9589. sinx = Math.sin(fda);
  9590. cosx = Math.cos(fda);
  9591. }
  9592. var lastx = this._path._lastOriX, lasty = this._path._lastOriY;
  9593. var _x1 = ptx1, _y1 = pty1;
  9594. if (Math.abs(_x1 - this._path._lastOriX) > 0.1 || Math.abs(_y1 - this._path._lastOriY) > 0.1) {
  9595. x = _x1;
  9596. y = _y1;
  9597. lastx = _x1;
  9598. lasty = _y1;
  9599. this._path._lastOriX = x;
  9600. this._path._lastOriY = y;
  9601. this._path.addPoint(x, y);
  9602. }
  9603. var cvx = ptx1 - orix;
  9604. var cvy = pty1 - oriy;
  9605. for (i = 0; i < Context.SEGNUM; i++) {
  9606. var cx = cvx * cosx + cvy * sinx;
  9607. var cy = -cvx * sinx + cvy * cosx;
  9608. x = cx + orix;
  9609. y = cy + oriy;
  9610. if (Math.abs(lastx - x) > 0.1 || Math.abs(lasty - y) > 0.1) {
  9611. this._path._lastOriX = x;
  9612. this._path._lastOriY = y;
  9613. this._path.addPoint(x, y);
  9614. lastx = x;
  9615. lasty = y;
  9616. }
  9617. cvx = cx;
  9618. cvy = cy;
  9619. }
  9620. }
  9621. arc(cx, cy, r, startAngle, endAngle, counterclockwise = false, b = true) {
  9622. var a = 0, da = 0;
  9623. var dx = 0, dy = 0, x = 0, y = 0;
  9624. var i, ndivs;
  9625. da = endAngle - startAngle;
  9626. if (!counterclockwise) {
  9627. if (Math.abs(da) >= Math.PI * 2) {
  9628. da = Math.PI * 2;
  9629. }
  9630. else {
  9631. while (da < 0.0) {
  9632. da += Math.PI * 2;
  9633. }
  9634. }
  9635. }
  9636. else {
  9637. if (Math.abs(da) >= Math.PI * 2) {
  9638. da = -Math.PI * 2;
  9639. }
  9640. else {
  9641. while (da > 0.0) {
  9642. da -= Math.PI * 2;
  9643. }
  9644. }
  9645. }
  9646. var sx = this.getMatScaleX();
  9647. var sy = this.getMatScaleY();
  9648. var sr = r * (sx > sy ? sx : sy);
  9649. var cl = 2 * Math.PI * sr;
  9650. ndivs = (Math.max(cl / 10, 10)) | 0;
  9651. var tPath = this._getPath();
  9652. for (i = 0; i <= ndivs; i++) {
  9653. a = startAngle + da * (i / ndivs);
  9654. dx = Math.cos(a);
  9655. dy = Math.sin(a);
  9656. x = cx + dx * r;
  9657. y = cy + dy * r;
  9658. if (x != this._path._lastOriX || y != this._path._lastOriY) {
  9659. tPath.addPoint(x, y);
  9660. }
  9661. }
  9662. dx = Math.cos(endAngle);
  9663. dy = Math.sin(endAngle);
  9664. x = cx + dx * r;
  9665. y = cy + dy * r;
  9666. if (x != this._path._lastOriX || y != this._path._lastOriY) {
  9667. tPath.addPoint(x, y);
  9668. }
  9669. }
  9670. quadraticCurveTo(cpx, cpy, x, y) {
  9671. var tBezier = Bezier.I;
  9672. var tArray = tBezier.getBezierPoints([this._path._lastOriX, this._path._lastOriY, cpx, cpy, x, y], 30, 2);
  9673. for (var i = 0, n = tArray.length / 2; i < n; i++) {
  9674. this.lineTo(tArray[i * 2], tArray[i * 2 + 1]);
  9675. }
  9676. this.lineTo(x, y);
  9677. }
  9678. mixRGBandAlpha(color) {
  9679. return this._mixRGBandAlpha(color, this._shader2D.ALPHA);
  9680. }
  9681. _mixRGBandAlpha(color, alpha) {
  9682. if (alpha >= 1) {
  9683. return color;
  9684. }
  9685. var a = ((color & 0xff000000) >>> 24);
  9686. if (a != 0) {
  9687. a *= alpha;
  9688. }
  9689. else {
  9690. a = alpha * 255;
  9691. }
  9692. return (color & 0x00ffffff) | (a << 24);
  9693. }
  9694. strokeRect(x, y, width, height, parameterLineWidth) {
  9695. if (this.lineWidth > 0) {
  9696. var rgba = this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  9697. var hw = this.lineWidth / 2;
  9698. this._fillRect(x - hw, y - hw, width + this.lineWidth, this.lineWidth, rgba);
  9699. this._fillRect(x - hw, y - hw + height, width + this.lineWidth, this.lineWidth, rgba);
  9700. this._fillRect(x - hw, y + hw, this.lineWidth, height - this.lineWidth, rgba);
  9701. this._fillRect(x - hw + width, y + hw, this.lineWidth, height - this.lineWidth, rgba);
  9702. }
  9703. }
  9704. clip() {
  9705. }
  9706. drawParticle(x, y, pt) {
  9707. pt.x = x;
  9708. pt.y = y;
  9709. this._submits[this._submits._length++] = pt;
  9710. }
  9711. _getPath() {
  9712. return this._path || (this._path = new Path());
  9713. }
  9714. get canvas() {
  9715. return this._canvas;
  9716. }
  9717. _fillTexture_h(tex, imgid, uv, oriw, orih, x, y, w) {
  9718. if (oriw <= 0)
  9719. console.error('_fillTexture_h error: oriw must>0');
  9720. var stx = x;
  9721. var num = Math.floor(w / oriw);
  9722. var left = w % oriw;
  9723. for (var i = 0; i < num; i++) {
  9724. this._inner_drawTexture(tex, imgid, stx, y, oriw, orih, this._curMat, uv, 1, false);
  9725. stx += oriw;
  9726. }
  9727. if (left > 0) {
  9728. var du = uv[2] - uv[0];
  9729. var uvr = uv[0] + du * (left / oriw);
  9730. var tuv = Context.tmpuv1;
  9731. tuv[0] = uv[0];
  9732. tuv[1] = uv[1];
  9733. tuv[2] = uvr;
  9734. tuv[3] = uv[3];
  9735. tuv[4] = uvr;
  9736. tuv[5] = uv[5];
  9737. tuv[6] = uv[6];
  9738. tuv[7] = uv[7];
  9739. this._inner_drawTexture(tex, imgid, stx, y, left, orih, this._curMat, tuv, 1, false);
  9740. }
  9741. }
  9742. _fillTexture_v(tex, imgid, uv, oriw, orih, x, y, h) {
  9743. if (orih <= 0)
  9744. console.error('_fillTexture_v error: orih must>0');
  9745. var sty = y;
  9746. var num = Math.floor(h / orih);
  9747. var left = h % orih;
  9748. for (var i = 0; i < num; i++) {
  9749. this._inner_drawTexture(tex, imgid, x, sty, oriw, orih, this._curMat, uv, 1, false);
  9750. sty += orih;
  9751. }
  9752. if (left > 0) {
  9753. var dv = uv[7] - uv[1];
  9754. var uvb = uv[1] + dv * (left / orih);
  9755. var tuv = Context.tmpuv1;
  9756. tuv[0] = uv[0];
  9757. tuv[1] = uv[1];
  9758. tuv[2] = uv[2];
  9759. tuv[3] = uv[3];
  9760. tuv[4] = uv[4];
  9761. tuv[5] = uvb;
  9762. tuv[6] = uv[6];
  9763. tuv[7] = uvb;
  9764. this._inner_drawTexture(tex, imgid, x, sty, oriw, left, this._curMat, tuv, 1, false);
  9765. }
  9766. }
  9767. drawTextureWithSizeGrid(tex, tx, ty, width, height, sizeGrid, gx, gy) {
  9768. if (!tex._getSource())
  9769. return;
  9770. tx += gx;
  9771. ty += gy;
  9772. var uv = tex.uv, w = tex.bitmap.width, h = tex.bitmap.height;
  9773. var top = sizeGrid[0];
  9774. var left = sizeGrid[3];
  9775. var right = sizeGrid[1];
  9776. var bottom = sizeGrid[2];
  9777. var repeat = sizeGrid[4];
  9778. var needClip = false;
  9779. if (width == w) {
  9780. left = right = 0;
  9781. }
  9782. if (height == h) {
  9783. top = bottom = 0;
  9784. }
  9785. var d_top = top / h;
  9786. var d_left = left / w;
  9787. var d_right = right / w;
  9788. var d_bottom = bottom / h;
  9789. if (left + right > width) {
  9790. var clipWidth = width;
  9791. needClip = true;
  9792. width = left + right;
  9793. this.save();
  9794. this.clipRect(0 + tx, 0 + ty, clipWidth, height);
  9795. }
  9796. var imgid = tex.bitmap.id;
  9797. var mat = this._curMat;
  9798. var tuv = this._tempUV;
  9799. var uvl = uv[0];
  9800. var uvt = uv[1];
  9801. var uvr = uv[4];
  9802. var uvb = uv[5];
  9803. var uvl_ = uvl;
  9804. var uvt_ = uvt;
  9805. var uvr_ = uvr;
  9806. var uvb_ = uvb;
  9807. if (left && top) {
  9808. uvr_ = uvl + d_left;
  9809. uvb_ = uvt + d_top;
  9810. tuv[0] = uvl, tuv[1] = uvt, tuv[2] = uvr_, tuv[3] = uvt,
  9811. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl, tuv[7] = uvb_;
  9812. this._inner_drawTexture(tex, imgid, tx, ty, left, top, mat, tuv, 1, false);
  9813. }
  9814. if (right && top) {
  9815. uvl_ = uvr - d_right;
  9816. uvt_ = uvt;
  9817. uvr_ = uvr;
  9818. uvb_ = uvt + d_top;
  9819. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9820. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9821. this._inner_drawTexture(tex, imgid, width - right + tx, 0 + ty, right, top, mat, tuv, 1, false);
  9822. }
  9823. if (left && bottom) {
  9824. uvl_ = uvl;
  9825. uvt_ = uvb - d_bottom;
  9826. uvr_ = uvl + d_left;
  9827. uvb_ = uvb;
  9828. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9829. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9830. this._inner_drawTexture(tex, imgid, 0 + tx, height - bottom + ty, left, bottom, mat, tuv, 1, false);
  9831. }
  9832. if (right && bottom) {
  9833. uvl_ = uvr - d_right;
  9834. uvt_ = uvb - d_bottom;
  9835. uvr_ = uvr;
  9836. uvb_ = uvb;
  9837. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9838. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9839. this._inner_drawTexture(tex, imgid, width - right + tx, height - bottom + ty, right, bottom, mat, tuv, 1, false);
  9840. }
  9841. if (top) {
  9842. uvl_ = uvl + d_left;
  9843. uvt_ = uvt;
  9844. uvr_ = uvr - d_right;
  9845. uvb_ = uvt + d_top;
  9846. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9847. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9848. if (repeat) {
  9849. this._fillTexture_h(tex, imgid, tuv, tex.width - left - right, top, left + tx, ty, width - left - right);
  9850. }
  9851. else {
  9852. this._inner_drawTexture(tex, imgid, left + tx, ty, width - left - right, top, mat, tuv, 1, false);
  9853. }
  9854. }
  9855. if (bottom) {
  9856. uvl_ = uvl + d_left;
  9857. uvt_ = uvb - d_bottom;
  9858. uvr_ = uvr - d_right;
  9859. uvb_ = uvb;
  9860. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9861. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9862. if (repeat) {
  9863. this._fillTexture_h(tex, imgid, tuv, tex.width - left - right, bottom, left + tx, height - bottom + ty, width - left - right);
  9864. }
  9865. else {
  9866. this._inner_drawTexture(tex, imgid, left + tx, height - bottom + ty, width - left - right, bottom, mat, tuv, 1, false);
  9867. }
  9868. }
  9869. if (left) {
  9870. uvl_ = uvl;
  9871. uvt_ = uvt + d_top;
  9872. uvr_ = uvl + d_left;
  9873. uvb_ = uvb - d_bottom;
  9874. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9875. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9876. if (repeat) {
  9877. this._fillTexture_v(tex, imgid, tuv, left, tex.height - top - bottom, tx, top + ty, height - top - bottom);
  9878. }
  9879. else {
  9880. this._inner_drawTexture(tex, imgid, tx, top + ty, left, height - top - bottom, mat, tuv, 1, false);
  9881. }
  9882. }
  9883. if (right) {
  9884. uvl_ = uvr - d_right;
  9885. uvt_ = uvt + d_top;
  9886. uvr_ = uvr;
  9887. uvb_ = uvb - d_bottom;
  9888. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9889. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9890. if (repeat) {
  9891. this._fillTexture_v(tex, imgid, tuv, right, tex.height - top - bottom, width - right + tx, top + ty, height - top - bottom);
  9892. }
  9893. else {
  9894. this._inner_drawTexture(tex, imgid, width - right + tx, top + ty, right, height - top - bottom, mat, tuv, 1, false);
  9895. }
  9896. }
  9897. uvl_ = uvl + d_left;
  9898. uvt_ = uvt + d_top;
  9899. uvr_ = uvr - d_right;
  9900. uvb_ = uvb - d_bottom;
  9901. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9902. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9903. if (repeat) {
  9904. var tuvr = Context.tmpUVRect;
  9905. tuvr[0] = uvl_;
  9906. tuvr[1] = uvt_;
  9907. tuvr[2] = uvr_ - uvl_;
  9908. tuvr[3] = uvb_ - uvt_;
  9909. this._fillTexture(tex, tex.width - left - right, tex.height - top - bottom, tuvr, left + tx, top + ty, width - left - right, height - top - bottom, 'repeat', 0, 0);
  9910. }
  9911. else {
  9912. this._inner_drawTexture(tex, imgid, left + tx, top + ty, width - left - right, height - top - bottom, mat, tuv, 1, false);
  9913. }
  9914. if (needClip)
  9915. this.restore();
  9916. }
  9917. }
  9918. Context.ENUM_TEXTALIGN_DEFAULT = 0;
  9919. Context.ENUM_TEXTALIGN_CENTER = 1;
  9920. Context.ENUM_TEXTALIGN_RIGHT = 2;
  9921. Context._SUBMITVBSIZE = 32000;
  9922. Context._MAXSIZE = 99999999;
  9923. Context._MAXVERTNUM = 65535;
  9924. Context.MAXCLIPRECT = null;
  9925. Context._COUNT = 0;
  9926. Context.SEGNUM = 32;
  9927. Context._contextcount = 0;
  9928. Context.PI2 = 2 * Math.PI;
  9929. Context._textRender = null;
  9930. Context.tmpuv1 = [0, 0, 0, 0, 0, 0, 0, 0];
  9931. Context.tmpUV = [0, 0, 0, 0, 0, 0, 0, 0];
  9932. Context.tmpUVRect = [0, 0, 0, 0];
  9933. class ContextParams {
  9934. constructor() {
  9935. this.lineWidth = 1;
  9936. }
  9937. clear() {
  9938. this.lineWidth = 1;
  9939. this.textAlign = this.textBaseline = null;
  9940. }
  9941. make() {
  9942. return this === ContextParams.DEFAULT ? new ContextParams() : this;
  9943. }
  9944. }
  9945. class WebGL {
  9946. static _uint8ArraySlice() {
  9947. var _this = this;
  9948. var sz = _this.length;
  9949. var dec = new Uint8Array(_this.length);
  9950. for (var i = 0; i < sz; i++)
  9951. dec[i] = _this[i];
  9952. return dec;
  9953. }
  9954. static _float32ArraySlice() {
  9955. var _this = this;
  9956. var sz = _this.length;
  9957. var dec = new Float32Array(_this.length);
  9958. for (var i = 0; i < sz; i++)
  9959. dec[i] = _this[i];
  9960. return dec;
  9961. }
  9962. static _uint16ArraySlice(...arg) {
  9963. var _this = this;
  9964. var sz;
  9965. var dec;
  9966. var i;
  9967. if (arg.length === 0) {
  9968. sz = _this.length;
  9969. dec = new Uint16Array(sz);
  9970. for (i = 0; i < sz; i++)
  9971. dec[i] = _this[i];
  9972. }
  9973. else if (arg.length === 2) {
  9974. var start = arg[0];
  9975. var end = arg[1];
  9976. if (end > start) {
  9977. sz = end - start;
  9978. dec = new Uint16Array(sz);
  9979. for (i = start; i < end; i++)
  9980. dec[i - start] = _this[i];
  9981. }
  9982. else {
  9983. dec = new Uint16Array(0);
  9984. }
  9985. }
  9986. return dec;
  9987. }
  9988. static _nativeRender_enable() {
  9989. }
  9990. static enable() {
  9991. return true;
  9992. }
  9993. static inner_enable() {
  9994. Float32Array.prototype.slice || (Float32Array.prototype.slice = WebGL._float32ArraySlice);
  9995. Uint16Array.prototype.slice || (Uint16Array.prototype.slice = WebGL._uint16ArraySlice);
  9996. Uint8Array.prototype.slice || (Uint8Array.prototype.slice = WebGL._uint8ArraySlice);
  9997. return true;
  9998. }
  9999. static onStageResize(width, height) {
  10000. if (WebGLContext.mainContext == null)
  10001. return;
  10002. WebGLContext.mainContext.viewport(0, 0, width, height);
  10003. RenderState2D.width = width;
  10004. RenderState2D.height = height;
  10005. }
  10006. }
  10007. WebGL._isWebGL2 = false;
  10008. WebGL.isNativeRender_enable = false;
  10009. class VertexArrayObject {
  10010. constructor() {
  10011. }
  10012. }
  10013. (function () {
  10014. var glErrorShadow = {};
  10015. function error(msg) {
  10016. if (window.console && window.console.error) {
  10017. window.console.error(msg);
  10018. }
  10019. }
  10020. function log(msg) {
  10021. if (window.console && window.console.log) {
  10022. window.console.log(msg);
  10023. }
  10024. }
  10025. function synthesizeGLError(err, opt_msg) {
  10026. glErrorShadow[err] = true;
  10027. if (opt_msg !== undefined) {
  10028. error(opt_msg);
  10029. }
  10030. }
  10031. function wrapGLError(gl) {
  10032. var f = gl.getError;
  10033. gl.getError = function () {
  10034. var err;
  10035. do {
  10036. err = f.apply(gl);
  10037. if (err != gl.NO_ERROR) {
  10038. glErrorShadow[err] = true;
  10039. }
  10040. } while (err != gl.NO_ERROR);
  10041. for (var err1 in glErrorShadow) {
  10042. if (glErrorShadow[err1]) {
  10043. delete glErrorShadow[err1];
  10044. return parseInt(err1);
  10045. }
  10046. }
  10047. return gl.NO_ERROR;
  10048. };
  10049. }
  10050. var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES(ext) {
  10051. var gl = ext.gl;
  10052. this.ext = ext;
  10053. this.isAlive = true;
  10054. this.hasBeenBound = false;
  10055. this.elementArrayBuffer = null;
  10056. this.attribs = new Array(ext.maxVertexAttribs);
  10057. for (var n = 0; n < this.attribs.length; n++) {
  10058. var attrib = new WebGLVertexArrayObjectOES.VertexAttrib(gl);
  10059. this.attribs[n] = attrib;
  10060. }
  10061. this.maxAttrib = 0;
  10062. };
  10063. WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
  10064. this.enabled = false;
  10065. this.buffer = null;
  10066. this.size = 4;
  10067. this.type = gl.FLOAT;
  10068. this.normalized = false;
  10069. this.stride = 16;
  10070. this.offset = 0;
  10071. this.cached = "";
  10072. this.recache();
  10073. };
  10074. WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
  10075. this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
  10076. };
  10077. var OESVertexArrayObject = function OESVertexArrayObject(gl) {
  10078. var self = this;
  10079. this.gl = gl;
  10080. wrapGLError(gl);
  10081. var original = this.original = {
  10082. getParameter: gl.getParameter,
  10083. enableVertexAttribArray: gl.enableVertexAttribArray,
  10084. disableVertexAttribArray: gl.disableVertexAttribArray,
  10085. bindBuffer: gl.bindBuffer,
  10086. getVertexAttrib: gl.getVertexAttrib,
  10087. vertexAttribPointer: gl.vertexAttribPointer
  10088. };
  10089. gl.getParameter = function getParameter(pname) {
  10090. if (pname == self.VERTEX_ARRAY_BINDING_OES) {
  10091. if (self.currentVertexArrayObject == self.defaultVertexArrayObject) {
  10092. return null;
  10093. }
  10094. else {
  10095. return self.currentVertexArrayObject;
  10096. }
  10097. }
  10098. return original.getParameter.apply(this, arguments);
  10099. };
  10100. gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
  10101. var vao = self.currentVertexArrayObject;
  10102. vao.maxAttrib = Math.max(vao.maxAttrib, index);
  10103. var attrib = vao.attribs[index];
  10104. attrib.enabled = true;
  10105. return original.enableVertexAttribArray.apply(this, arguments);
  10106. };
  10107. gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
  10108. var vao = self.currentVertexArrayObject;
  10109. vao.maxAttrib = Math.max(vao.maxAttrib, index);
  10110. var attrib = vao.attribs[index];
  10111. attrib.enabled = false;
  10112. return original.disableVertexAttribArray.apply(this, arguments);
  10113. };
  10114. gl.bindBuffer = function bindBuffer(target, buffer) {
  10115. switch (target) {
  10116. case gl.ARRAY_BUFFER:
  10117. self.currentArrayBuffer = buffer;
  10118. break;
  10119. case gl.ELEMENT_ARRAY_BUFFER:
  10120. self.currentVertexArrayObject.elementArrayBuffer = buffer;
  10121. break;
  10122. }
  10123. return original.bindBuffer.apply(this, arguments);
  10124. };
  10125. gl.getVertexAttrib = function getVertexAttrib(index, pname) {
  10126. var vao = self.currentVertexArrayObject;
  10127. var attrib = vao.attribs[index];
  10128. switch (pname) {
  10129. case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
  10130. return attrib.buffer;
  10131. case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
  10132. return attrib.enabled;
  10133. case gl.VERTEX_ATTRIB_ARRAY_SIZE:
  10134. return attrib.size;
  10135. case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
  10136. return attrib.stride;
  10137. case gl.VERTEX_ATTRIB_ARRAY_TYPE:
  10138. return attrib.type;
  10139. case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
  10140. return attrib.normalized;
  10141. default:
  10142. return original.getVertexAttrib.apply(this, arguments);
  10143. }
  10144. };
  10145. gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
  10146. var vao = self.currentVertexArrayObject;
  10147. vao.maxAttrib = Math.max(vao.maxAttrib, indx);
  10148. var attrib = vao.attribs[indx];
  10149. attrib.buffer = self.currentArrayBuffer;
  10150. attrib.size = size;
  10151. attrib.type = type;
  10152. attrib.normalized = normalized;
  10153. attrib.stride = stride;
  10154. attrib.offset = offset;
  10155. attrib.recache();
  10156. return original.vertexAttribPointer.apply(this, arguments);
  10157. };
  10158. if (gl.instrumentExtension) {
  10159. gl.instrumentExtension(this, "OES_vertex_array_object");
  10160. }
  10161. gl.canvas.addEventListener('webglcontextrestored', function () {
  10162. log("OESVertexArrayObject emulation library context restored");
  10163. self.reset_();
  10164. }, true);
  10165. this.reset_();
  10166. };
  10167. OESVertexArrayObject.prototype.VERTEX_ARRAY_BINDING_OES = 0x85B5;
  10168. OESVertexArrayObject.prototype.reset_ = function reset_() {
  10169. var contextWasLost = this.vertexArrayObjects !== undefined;
  10170. if (contextWasLost) {
  10171. for (var ii = 0; ii < this.vertexArrayObjects.length; ++ii) {
  10172. this.vertexArrayObjects.isAlive = false;
  10173. }
  10174. }
  10175. var gl = this.gl;
  10176. this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
  10177. this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
  10178. this.currentVertexArrayObject = null;
  10179. this.currentArrayBuffer = null;
  10180. this.vertexArrayObjects = [this.defaultVertexArrayObject];
  10181. this.bindVertexArrayOES(null);
  10182. };
  10183. OESVertexArrayObject.prototype.createVertexArrayOES = function createVertexArrayOES() {
  10184. var arrayObject = new WebGLVertexArrayObjectOES(this);
  10185. this.vertexArrayObjects.push(arrayObject);
  10186. return arrayObject;
  10187. };
  10188. OESVertexArrayObject.prototype.deleteVertexArrayOES = function deleteVertexArrayOES(arrayObject) {
  10189. arrayObject.isAlive = false;
  10190. this.vertexArrayObjects.splice(this.vertexArrayObjects.indexOf(arrayObject), 1);
  10191. if (this.currentVertexArrayObject == arrayObject) {
  10192. this.bindVertexArrayOES(null);
  10193. }
  10194. };
  10195. OESVertexArrayObject.prototype.isVertexArrayOES = function isVertexArrayOES(arrayObject) {
  10196. if (arrayObject && arrayObject instanceof WebGLVertexArrayObjectOES) {
  10197. if (arrayObject.hasBeenBound && arrayObject.ext == this) {
  10198. return true;
  10199. }
  10200. }
  10201. return false;
  10202. };
  10203. OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
  10204. var gl = this.gl;
  10205. if (arrayObject && !arrayObject.isAlive) {
  10206. synthesizeGLError(gl.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
  10207. return;
  10208. }
  10209. var original = this.original;
  10210. var oldVAO = this.currentVertexArrayObject;
  10211. this.currentVertexArrayObject = arrayObject || this.defaultVertexArrayObject;
  10212. this.currentVertexArrayObject.hasBeenBound = true;
  10213. var newVAO = this.currentVertexArrayObject;
  10214. if (oldVAO == newVAO) {
  10215. return;
  10216. }
  10217. if (!oldVAO || newVAO.elementArrayBuffer != oldVAO.elementArrayBuffer) {
  10218. original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
  10219. }
  10220. var currentBinding = this.currentArrayBuffer;
  10221. var maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
  10222. for (var n = 0; n <= maxAttrib; n++) {
  10223. var attrib = newVAO.attribs[n];
  10224. var oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
  10225. if (!oldVAO || attrib.enabled != oldAttrib.enabled) {
  10226. if (attrib.enabled) {
  10227. original.enableVertexAttribArray.call(gl, n);
  10228. }
  10229. else {
  10230. original.disableVertexAttribArray.call(gl, n);
  10231. }
  10232. }
  10233. if (attrib.enabled) {
  10234. var bufferChanged = false;
  10235. if (!oldVAO || attrib.buffer != oldAttrib.buffer) {
  10236. if (currentBinding != attrib.buffer) {
  10237. original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
  10238. currentBinding = attrib.buffer;
  10239. }
  10240. bufferChanged = true;
  10241. }
  10242. if (bufferChanged || attrib.cached != oldAttrib.cached) {
  10243. original.vertexAttribPointer.call(gl, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
  10244. }
  10245. }
  10246. }
  10247. if (this.currentArrayBuffer != currentBinding) {
  10248. original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
  10249. }
  10250. };
  10251. window._setupVertexArrayObject = function (gl) {
  10252. var original_getSupportedExtensions = gl.getSupportedExtensions;
  10253. gl.getSupportedExtensions = function getSupportedExtensions() {
  10254. var list = original_getSupportedExtensions.call(this) || [];
  10255. if (list.indexOf("OES_vertex_array_object") < 0) {
  10256. list.push("OES_vertex_array_object");
  10257. }
  10258. return list;
  10259. };
  10260. var original_getExtension = gl.getExtension;
  10261. gl.getExtension = function getExtension(name) {
  10262. var ext = original_getExtension.call(this, name);
  10263. if (ext) {
  10264. return ext;
  10265. }
  10266. if (name !== "OES_vertex_array_object") {
  10267. return null;
  10268. }
  10269. if (!this.__OESVertexArrayObject) {
  10270. console.log("Setup OES_vertex_array_object polyfill");
  10271. this.__OESVertexArrayObject = new OESVertexArrayObject(this);
  10272. }
  10273. return this.__OESVertexArrayObject;
  10274. };
  10275. };
  10276. }());
  10277. class SystemUtils {
  10278. static get maxTextureCount() {
  10279. return this._maxTextureCount;
  10280. }
  10281. static get maxTextureSize() {
  10282. return this._maxTextureSize;
  10283. }
  10284. static get shaderCapailityLevel() {
  10285. return this._shaderCapailityLevel;
  10286. }
  10287. static supportTextureFormat(format) {
  10288. switch (format) {
  10289. case exports.TextureFormat.R32G32B32A32:
  10290. return (!LayaGL.layaGPUInstance._oesTextureFloat) ? false : true;
  10291. default:
  10292. return true;
  10293. }
  10294. }
  10295. static supportRenderTextureFormat(format) {
  10296. switch (format) {
  10297. case exports.RenderTextureFormat.R16G16B16A16:
  10298. return (((!!LayaGL.layaGPUInstance._isWebGL2) && (!!LayaGL.layaGPUInstance._oesTextureFloat)) || LayaGL.layaGPUInstance._oesTextureHalfFloat && LayaGL.layaGPUInstance._oesTextureHalfFloatLinear) ? true : false;
  10299. case exports.RenderTextureFormat.Depth:
  10300. return (LayaGL.layaGPUInstance._isWebGL2 || LayaGL.layaGPUInstance._webgl_depth_texture) ? true : false;
  10301. case exports.RenderTextureFormat.ShadowMap:
  10302. return LayaGL.layaGPUInstance._isWebGL2 ? true : false;
  10303. default:
  10304. return true;
  10305. }
  10306. }
  10307. }
  10308. class LayaGPU {
  10309. constructor(gl, isWebGL2) {
  10310. this._gl = null;
  10311. this._vaoExt = null;
  10312. this._angleInstancedArrays = null;
  10313. this._isWebGL2 = false;
  10314. this._oesTextureHalfFloat = null;
  10315. this._oes_element_index_uint = null;
  10316. this._oesTextureHalfFloatLinear = null;
  10317. this._oesTextureFloat = null;
  10318. this._extShaderTextureLod = null;
  10319. this._extTextureFilterAnisotropic = null;
  10320. this._compressedTextureS3tc = null;
  10321. this._compressedTexturePvrtc = null;
  10322. this._compressedTextureEtc1 = null;
  10323. this._webgl_depth_texture = null;
  10324. this._gl = gl;
  10325. this._isWebGL2 = isWebGL2;
  10326. var maxTextureFS = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
  10327. var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
  10328. if (!isWebGL2) {
  10329. if (!ILaya.Render.isConchApp) {
  10330. if (window._setupVertexArrayObject)
  10331. window._setupVertexArrayObject(gl);
  10332. }
  10333. this._vaoExt = this._getExtension("OES_vertex_array_object");
  10334. this._angleInstancedArrays = this._getExtension("ANGLE_instanced_arrays");
  10335. this._oesTextureHalfFloat = this._getExtension("OES_texture_half_float");
  10336. this._oesTextureHalfFloatLinear = this._getExtension("OES_texture_half_float_linear");
  10337. this._oesTextureFloat = this._getExtension("OES_texture_float");
  10338. this._oes_element_index_uint = this._getExtension("OES_element_index_uint");
  10339. this._extShaderTextureLod = this._getExtension("EXT_shader_texture_lod");
  10340. this._webgl_depth_texture = this._getExtension("WEBGL_depth_texture");
  10341. SystemUtils._shaderCapailityLevel = 30;
  10342. }
  10343. else {
  10344. this._oesTextureFloat = this._getExtension("EXT_color_buffer_float");
  10345. SystemUtils._shaderCapailityLevel = 35;
  10346. }
  10347. this._extTextureFilterAnisotropic = this._getExtension("EXT_texture_filter_anisotropic");
  10348. this._compressedTextureS3tc = this._getExtension("WEBGL_compressed_texture_s3tc");
  10349. this._compressedTexturePvrtc = this._getExtension("WEBGL_compressed_texture_pvrtc");
  10350. this._compressedTextureEtc1 = this._getExtension("WEBGL_compressed_texture_etc1");
  10351. SystemUtils._maxTextureCount = maxTextureFS;
  10352. SystemUtils._maxTextureSize = maxTextureSize;
  10353. }
  10354. _getExtension(name) {
  10355. var prefixes = LayaGPU._extentionVendorPrefixes;
  10356. for (var k in prefixes) {
  10357. var ext = this._gl.getExtension(prefixes[k] + name);
  10358. if (ext)
  10359. return ext;
  10360. }
  10361. return null;
  10362. }
  10363. createVertexArray() {
  10364. if (this._isWebGL2)
  10365. return this._gl.createVertexArray();
  10366. else
  10367. return this._vaoExt.createVertexArrayOES();
  10368. }
  10369. bindVertexArray(vertexArray) {
  10370. if (this._isWebGL2)
  10371. this._gl.bindVertexArray(vertexArray);
  10372. else
  10373. this._vaoExt.bindVertexArrayOES(vertexArray);
  10374. }
  10375. deleteVertexArray(vertexArray) {
  10376. if (this._isWebGL2)
  10377. this._gl.deleteVertexArray(vertexArray);
  10378. else
  10379. this._vaoExt.deleteVertexArrayOES(vertexArray);
  10380. }
  10381. isVertexArray(vertexArray) {
  10382. if (this._isWebGL2)
  10383. this._gl.isVertexArray(vertexArray);
  10384. else
  10385. this._vaoExt.isVertexArrayOES(vertexArray);
  10386. }
  10387. drawElementsInstanced(mode, count, type, offset, instanceCount) {
  10388. if (this._isWebGL2)
  10389. this._gl.drawElementsInstanced(mode, count, type, offset, instanceCount);
  10390. else
  10391. this._angleInstancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount);
  10392. }
  10393. drawArraysInstanced(mode, first, count, instanceCount) {
  10394. if (this._isWebGL2)
  10395. this._gl.drawArraysInstanced(mode, first, count, instanceCount);
  10396. else
  10397. this._angleInstancedArrays.drawArraysInstancedANGLE(mode, first, count, instanceCount);
  10398. }
  10399. vertexAttribDivisor(index, divisor) {
  10400. if (this._isWebGL2)
  10401. this._gl.vertexAttribDivisor(index, divisor);
  10402. else
  10403. this._angleInstancedArrays.vertexAttribDivisorANGLE(index, divisor);
  10404. }
  10405. supportInstance() {
  10406. if ((this._isWebGL2 || this._angleInstancedArrays) && Config.allowGPUInstanceDynamicBatch)
  10407. return true;
  10408. else
  10409. return false;
  10410. }
  10411. supportElementIndexUint32() {
  10412. return this._isWebGL2 || this._oes_element_index_uint ? true : false;
  10413. }
  10414. }
  10415. LayaGPU._extentionVendorPrefixes = ["", "WEBKIT_", "MOZ_"];
  10416. class Render {
  10417. constructor(width, height, mainCanv) {
  10418. this._timeId = 0;
  10419. Render._mainCanvas = mainCanv;
  10420. let source = Render._mainCanvas.source;
  10421. source.id = "layaCanvas";
  10422. source.width = width;
  10423. source.height = height;
  10424. if (Render.isConchApp) {
  10425. document.body.appendChild(source);
  10426. }
  10427. this.initRender(Render._mainCanvas, width, height);
  10428. window.requestAnimationFrame(loop);
  10429. function loop(stamp) {
  10430. ILaya.stage._loop();
  10431. window.requestAnimationFrame(loop);
  10432. }
  10433. ILaya.stage.on("visibilitychange", this, this._onVisibilitychange);
  10434. }
  10435. _onVisibilitychange() {
  10436. if (!ILaya.stage.isVisibility) {
  10437. this._timeId = window.setInterval(this._enterFrame, 1000);
  10438. }
  10439. else if (this._timeId != 0) {
  10440. window.clearInterval(this._timeId);
  10441. }
  10442. }
  10443. initRender(canvas, w, h) {
  10444. function getWebGLContext(canvas) {
  10445. var gl;
  10446. var names = ["webgl2", "webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
  10447. if (!Config.useWebGL2 || Browser.onBDMiniGame) {
  10448. names.shift();
  10449. }
  10450. for (var i = 0; i < names.length; i++) {
  10451. try {
  10452. gl = canvas.getContext(names[i], { stencil: Config.isStencil, alpha: Config.isAlpha, antialias: Config.isAntialias, premultipliedAlpha: Config.premultipliedAlpha, preserveDrawingBuffer: Config.preserveDrawingBuffer });
  10453. }
  10454. catch (e) {
  10455. }
  10456. if (gl) {
  10457. (names[i] === 'webgl2') && (WebGL._isWebGL2 = true);
  10458. return gl;
  10459. }
  10460. }
  10461. return null;
  10462. }
  10463. var gl = LayaGL.instance = WebGLContext.mainContext = getWebGLContext(Render._mainCanvas.source);
  10464. if (!gl)
  10465. return false;
  10466. LayaGL.instance = gl;
  10467. LayaGL.layaGPUInstance = new LayaGPU(gl, WebGL._isWebGL2);
  10468. canvas.size(w, h);
  10469. Context.__init__();
  10470. SubmitBase.__init__();
  10471. var ctx = new Context();
  10472. ctx.isMain = true;
  10473. Render._context = ctx;
  10474. canvas._setContext(ctx);
  10475. ShaderDefines2D.__init__();
  10476. Value2D.__init__();
  10477. Shader2D.__init__();
  10478. Buffer2D.__int__(gl);
  10479. BlendMode._init_(gl);
  10480. return true;
  10481. }
  10482. _enterFrame(e = null) {
  10483. ILaya.stage._loop();
  10484. }
  10485. static get context() {
  10486. return Render._context;
  10487. }
  10488. static get canvas() {
  10489. return Render._mainCanvas.source;
  10490. }
  10491. }
  10492. Render.supportWebGLPlusCulling = false;
  10493. Render.supportWebGLPlusAnimation = false;
  10494. Render.supportWebGLPlusRendering = false;
  10495. Render.isConchApp = false;
  10496. {
  10497. Render.isConchApp = (window.conch != null);
  10498. if (Render.isConchApp) {
  10499. Render.supportWebGLPlusCulling = false;
  10500. Render.supportWebGLPlusAnimation = false;
  10501. Render.supportWebGLPlusRendering = false;
  10502. }
  10503. else if (window.qq != null && window.qq.webglPlus != null) {
  10504. Render.supportWebGLPlusCulling = false;
  10505. Render.supportWebGLPlusAnimation = false;
  10506. Render.supportWebGLPlusRendering = false;
  10507. }
  10508. }
  10509. class DrawTrianglesCmd {
  10510. static create(texture, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode, colorNum) {
  10511. var cmd = Pool.getItemByClass("DrawTrianglesCmd", DrawTrianglesCmd);
  10512. cmd.texture = texture;
  10513. cmd.x = x;
  10514. cmd.y = y;
  10515. cmd.vertices = vertices;
  10516. cmd.uvs = uvs;
  10517. cmd.indices = indices;
  10518. cmd.matrix = matrix;
  10519. cmd.alpha = alpha;
  10520. if (color) {
  10521. cmd.color = new ColorFilter();
  10522. var c = ColorUtils.create(color).arrColor;
  10523. cmd.color.color(c[0] * 255, c[1] * 255, c[2] * 255, c[3] * 255);
  10524. }
  10525. cmd.blendMode = blendMode;
  10526. cmd.colorNum = colorNum;
  10527. return cmd;
  10528. }
  10529. recover() {
  10530. this.texture = null;
  10531. this.vertices = null;
  10532. this.uvs = null;
  10533. this.indices = null;
  10534. this.matrix = null;
  10535. Pool.recover("DrawTrianglesCmd", this);
  10536. }
  10537. run(context, gx, gy) {
  10538. context.drawTriangles(this.texture, this.x + gx, this.y + gy, this.vertices, this.uvs, this.indices, this.matrix, this.alpha, this.color, this.blendMode, this.colorNum);
  10539. }
  10540. get cmdID() {
  10541. return DrawTrianglesCmd.ID;
  10542. }
  10543. }
  10544. DrawTrianglesCmd.ID = "DrawTriangles";
  10545. class Draw9GridTexture {
  10546. constructor() {
  10547. }
  10548. static create(texture, x, y, width, height, sizeGrid) {
  10549. var cmd = Pool.getItemByClass("Draw9GridTexture", Draw9GridTexture);
  10550. cmd.texture = texture;
  10551. texture._addReference();
  10552. cmd.x = x;
  10553. cmd.y = y;
  10554. cmd.width = width;
  10555. cmd.height = height;
  10556. cmd.sizeGrid = sizeGrid;
  10557. return cmd;
  10558. }
  10559. recover() {
  10560. this.texture._removeReference();
  10561. Pool.recover("Draw9GridTexture", this);
  10562. }
  10563. run(context, gx, gy) {
  10564. context.drawTextureWithSizeGrid(this.texture, this.x, this.y, this.width, this.height, this.sizeGrid, gx, gy);
  10565. }
  10566. get cmdID() {
  10567. return Draw9GridTexture.ID;
  10568. }
  10569. }
  10570. Draw9GridTexture.ID = "Draw9GridTexture";
  10571. class SaveCmd {
  10572. static create() {
  10573. var cmd = Pool.getItemByClass("SaveCmd", SaveCmd);
  10574. return cmd;
  10575. }
  10576. recover() {
  10577. Pool.recover("SaveCmd", this);
  10578. }
  10579. run(context, gx, gy) {
  10580. context.save();
  10581. }
  10582. get cmdID() {
  10583. return SaveCmd.ID;
  10584. }
  10585. }
  10586. SaveCmd.ID = "Save";
  10587. class GraphicsBounds {
  10588. constructor() {
  10589. this._cacheBoundsType = false;
  10590. }
  10591. destroy() {
  10592. this._graphics = null;
  10593. this._cacheBoundsType = false;
  10594. if (this._temp)
  10595. this._temp.length = 0;
  10596. if (this._rstBoundPoints)
  10597. this._rstBoundPoints.length = 0;
  10598. if (this._bounds)
  10599. this._bounds.recover();
  10600. this._bounds = null;
  10601. Pool.recover("GraphicsBounds", this);
  10602. }
  10603. static create() {
  10604. return Pool.getItemByClass("GraphicsBounds", GraphicsBounds);
  10605. }
  10606. reset() {
  10607. this._temp && (this._temp.length = 0);
  10608. }
  10609. getBounds(realSize = false) {
  10610. if (!this._bounds || !this._temp || this._temp.length < 1 || realSize != this._cacheBoundsType) {
  10611. this._bounds = Rectangle._getWrapRec(this.getBoundPoints(realSize), this._bounds);
  10612. }
  10613. this._cacheBoundsType = realSize;
  10614. return this._bounds;
  10615. }
  10616. getBoundPoints(realSize = false) {
  10617. if (!this._temp || this._temp.length < 1 || realSize != this._cacheBoundsType)
  10618. this._temp = this._getCmdPoints(realSize);
  10619. this._cacheBoundsType = realSize;
  10620. return this._rstBoundPoints = Utils.copyArray(this._rstBoundPoints, this._temp);
  10621. }
  10622. _getCmdPoints(realSize = false) {
  10623. var cmds = this._graphics.cmds;
  10624. var rst;
  10625. rst = this._temp || (this._temp = []);
  10626. rst.length = 0;
  10627. if (!cmds && this._graphics._one != null) {
  10628. GraphicsBounds._tempCmds.length = 0;
  10629. GraphicsBounds._tempCmds.push(this._graphics._one);
  10630. cmds = GraphicsBounds._tempCmds;
  10631. }
  10632. if (!cmds)
  10633. return rst;
  10634. var matrixs = GraphicsBounds._tempMatrixArrays;
  10635. matrixs.length = 0;
  10636. var tMatrix = GraphicsBounds._initMatrix;
  10637. tMatrix.identity();
  10638. var tempMatrix = GraphicsBounds._tempMatrix;
  10639. var cmd;
  10640. var tex;
  10641. for (var i = 0, n = cmds.length; i < n; i++) {
  10642. cmd = cmds[i];
  10643. switch (cmd.cmdID) {
  10644. case AlphaCmd.ID:
  10645. case SaveCmd.ID:
  10646. matrixs.push(tMatrix);
  10647. tMatrix = tMatrix.clone();
  10648. break;
  10649. case RestoreCmd.ID:
  10650. tMatrix = matrixs.pop();
  10651. break;
  10652. case ScaleCmd.ID:
  10653. tempMatrix.identity();
  10654. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10655. tempMatrix.scale(cmd.scaleX, cmd.scaleY);
  10656. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10657. this._switchMatrix(tMatrix, tempMatrix);
  10658. break;
  10659. case RotateCmd.ID:
  10660. tempMatrix.identity();
  10661. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10662. tempMatrix.rotate(cmd.angle);
  10663. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10664. this._switchMatrix(tMatrix, tempMatrix);
  10665. break;
  10666. case TranslateCmd.ID:
  10667. tempMatrix.identity();
  10668. tempMatrix.translate(cmd.tx, cmd.ty);
  10669. this._switchMatrix(tMatrix, tempMatrix);
  10670. break;
  10671. case TransformCmd.ID:
  10672. tempMatrix.identity();
  10673. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10674. tempMatrix.concat(cmd.matrix);
  10675. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10676. this._switchMatrix(tMatrix, tempMatrix);
  10677. break;
  10678. case DrawImageCmd.ID:
  10679. case FillTextureCmd.ID:
  10680. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10681. break;
  10682. case DrawTextureCmd.ID:
  10683. tMatrix.copyTo(tempMatrix);
  10684. if (cmd.matrix)
  10685. tempMatrix.concat(cmd.matrix);
  10686. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tempMatrix);
  10687. break;
  10688. case DrawImageCmd.ID:
  10689. tex = cmd.texture;
  10690. if (realSize) {
  10691. if (cmd.width && cmd.height) {
  10692. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10693. }
  10694. else {
  10695. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), tMatrix);
  10696. }
  10697. }
  10698. else {
  10699. var wRate = (cmd.width || tex.sourceWidth) / tex.width;
  10700. var hRate = (cmd.height || tex.sourceHeight) / tex.height;
  10701. var oWidth = wRate * tex.sourceWidth;
  10702. var oHeight = hRate * tex.sourceHeight;
  10703. var offX = tex.offsetX > 0 ? tex.offsetX : 0;
  10704. var offY = tex.offsetY > 0 ? tex.offsetY : 0;
  10705. offX *= wRate;
  10706. offY *= hRate;
  10707. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - offX, cmd.y - offY, oWidth, oHeight), tMatrix);
  10708. }
  10709. break;
  10710. case FillTextureCmd.ID:
  10711. if (cmd.width && cmd.height) {
  10712. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10713. }
  10714. else {
  10715. tex = cmd.texture;
  10716. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), tMatrix);
  10717. }
  10718. break;
  10719. case DrawTextureCmd.ID:
  10720. var drawMatrix;
  10721. if (cmd.matrix) {
  10722. tMatrix.copyTo(tempMatrix);
  10723. tempMatrix.concat(cmd.matrix);
  10724. drawMatrix = tempMatrix;
  10725. }
  10726. else {
  10727. drawMatrix = tMatrix;
  10728. }
  10729. if (realSize) {
  10730. if (cmd.width && cmd.height) {
  10731. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), drawMatrix);
  10732. }
  10733. else {
  10734. tex = cmd.texture;
  10735. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), drawMatrix);
  10736. }
  10737. }
  10738. else {
  10739. tex = cmd.texture;
  10740. wRate = (cmd.width || tex.sourceWidth) / tex.width;
  10741. hRate = (cmd.height || tex.sourceHeight) / tex.height;
  10742. oWidth = wRate * tex.sourceWidth;
  10743. oHeight = hRate * tex.sourceHeight;
  10744. offX = tex.offsetX > 0 ? tex.offsetX : 0;
  10745. offY = tex.offsetY > 0 ? tex.offsetY : 0;
  10746. offX *= wRate;
  10747. offY *= hRate;
  10748. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - offX, cmd.y - offY, oWidth, oHeight), drawMatrix);
  10749. }
  10750. break;
  10751. case DrawRectCmd.ID:
  10752. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10753. break;
  10754. case DrawCircleCmd.ID:
  10755. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - cmd.radius, cmd.y - cmd.radius, cmd.radius + cmd.radius, cmd.radius + cmd.radius), tMatrix);
  10756. break;
  10757. case DrawLineCmd.ID:
  10758. GraphicsBounds._tempPoints.length = 0;
  10759. var lineWidth;
  10760. lineWidth = cmd.lineWidth * 0.5;
  10761. if (cmd.fromX == cmd.toX) {
  10762. GraphicsBounds._tempPoints.push(cmd.fromX + lineWidth, cmd.fromY, cmd.toX + lineWidth, cmd.toY, cmd.fromX - lineWidth, cmd.fromY, cmd.toX - lineWidth, cmd.toY);
  10763. }
  10764. else if (cmd.fromY == cmd.toY) {
  10765. GraphicsBounds._tempPoints.push(cmd.fromX, cmd.fromY + lineWidth, cmd.toX, cmd.toY + lineWidth, cmd.fromX, cmd.fromY - lineWidth, cmd.toX, cmd.toY - lineWidth);
  10766. }
  10767. else {
  10768. GraphicsBounds._tempPoints.push(cmd.fromX, cmd.fromY, cmd.toX, cmd.toY);
  10769. }
  10770. GraphicsBounds._addPointArrToRst(rst, GraphicsBounds._tempPoints, tMatrix);
  10771. break;
  10772. case DrawCurvesCmd.ID:
  10773. GraphicsBounds._addPointArrToRst(rst, Bezier.I.getBezierPoints(cmd.points), tMatrix, cmd.x, cmd.y);
  10774. break;
  10775. case DrawLinesCmd.ID:
  10776. case DrawPolyCmd.ID:
  10777. GraphicsBounds._addPointArrToRst(rst, cmd.points, tMatrix, cmd.x, cmd.y);
  10778. break;
  10779. case DrawPathCmd.ID:
  10780. GraphicsBounds._addPointArrToRst(rst, this._getPathPoints(cmd.paths), tMatrix, cmd.x, cmd.y);
  10781. break;
  10782. case DrawPieCmd.ID:
  10783. GraphicsBounds._addPointArrToRst(rst, this._getPiePoints(cmd.x, cmd.y, cmd.radius, cmd.startAngle, cmd.endAngle), tMatrix);
  10784. break;
  10785. case DrawTrianglesCmd.ID:
  10786. GraphicsBounds._addPointArrToRst(rst, this._getTriAngBBXPoints(cmd.vertices), tMatrix);
  10787. break;
  10788. case Draw9GridTexture.ID:
  10789. GraphicsBounds._addPointArrToRst(rst, this._getDraw9GridBBXPoints(cmd), tMatrix);
  10790. break;
  10791. }
  10792. }
  10793. if (rst.length > 200) {
  10794. rst = Utils.copyArray(rst, Rectangle._getWrapRec(rst)._getBoundPoints());
  10795. }
  10796. else if (rst.length > 8)
  10797. rst = GrahamScan.scanPList(rst);
  10798. return rst;
  10799. }
  10800. _switchMatrix(tMatix, tempMatrix) {
  10801. tempMatrix.concat(tMatix);
  10802. tempMatrix.copyTo(tMatix);
  10803. }
  10804. static _addPointArrToRst(rst, points, matrix, dx = 0, dy = 0) {
  10805. var i, len;
  10806. len = points.length;
  10807. for (i = 0; i < len; i += 2) {
  10808. GraphicsBounds._addPointToRst(rst, points[i] + dx, points[i + 1] + dy, matrix);
  10809. }
  10810. }
  10811. static _addPointToRst(rst, x, y, matrix) {
  10812. var _tempPoint = Point.TEMP;
  10813. _tempPoint.setTo(x ? x : 0, y ? y : 0);
  10814. matrix.transformPoint(_tempPoint);
  10815. rst.push(_tempPoint.x, _tempPoint.y);
  10816. }
  10817. _getPiePoints(x, y, radius, startAngle, endAngle) {
  10818. var rst = GraphicsBounds._tempPoints;
  10819. GraphicsBounds._tempPoints.length = 0;
  10820. var k = Math.PI / 180;
  10821. var d1 = endAngle - startAngle;
  10822. if (d1 >= 360 || d1 <= -360) {
  10823. rst.push(x - radius, y - radius);
  10824. rst.push(x + radius, y - radius);
  10825. rst.push(x + radius, y + radius);
  10826. rst.push(x - radius, y + radius);
  10827. return rst;
  10828. }
  10829. rst.push(x, y);
  10830. var delta = d1 % 360;
  10831. if (delta < 0)
  10832. delta += 360;
  10833. var end1 = startAngle + delta;
  10834. var st = startAngle * k;
  10835. var ed = end1 * k;
  10836. rst.push(x + radius * Math.cos(st), y + radius * Math.sin(st));
  10837. rst.push(x + radius * Math.cos(ed), y + radius * Math.sin(ed));
  10838. var s1 = Math.ceil(startAngle / 90) * 90;
  10839. var s2 = Math.floor(end1 / 90) * 90;
  10840. for (var cs = s1; cs <= s2; cs += 90) {
  10841. var csr = cs * k;
  10842. rst.push(x + radius * Math.cos(csr), y + radius * Math.sin(csr));
  10843. }
  10844. return rst;
  10845. }
  10846. _getTriAngBBXPoints(vert) {
  10847. var vnum = vert.length;
  10848. if (vnum < 2)
  10849. return [];
  10850. var minx = vert[0];
  10851. var miny = vert[1];
  10852. var maxx = minx;
  10853. var maxy = miny;
  10854. for (var i = 2; i < vnum;) {
  10855. var cx = vert[i++];
  10856. var cy = vert[i++];
  10857. if (minx > cx)
  10858. minx = cx;
  10859. if (miny > cy)
  10860. miny = cy;
  10861. if (maxx < cx)
  10862. maxx = cx;
  10863. if (maxy < cy)
  10864. maxy = cy;
  10865. }
  10866. return [minx, miny, maxx, miny, maxx, maxy, minx, maxy];
  10867. }
  10868. _getDraw9GridBBXPoints(cmd) {
  10869. var minx = 0;
  10870. var miny = 0;
  10871. var maxx = cmd.width;
  10872. var maxy = cmd.height;
  10873. return [minx, miny, maxx, miny, maxx, maxy, minx, maxy];
  10874. }
  10875. _getPathPoints(paths) {
  10876. var i, len;
  10877. var rst = GraphicsBounds._tempPoints;
  10878. rst.length = 0;
  10879. len = paths.length;
  10880. var tCMD;
  10881. for (i = 0; i < len; i++) {
  10882. tCMD = paths[i];
  10883. if (tCMD.length > 1) {
  10884. rst.push(tCMD[1], tCMD[2]);
  10885. if (tCMD.length > 3) {
  10886. rst.push(tCMD[3], tCMD[4]);
  10887. }
  10888. }
  10889. }
  10890. return rst;
  10891. }
  10892. }
  10893. GraphicsBounds._tempMatrix = new Matrix();
  10894. GraphicsBounds._initMatrix = new Matrix();
  10895. GraphicsBounds._tempPoints = [];
  10896. GraphicsBounds._tempMatrixArrays = [];
  10897. GraphicsBounds._tempCmds = [];
  10898. class SpriteConst {
  10899. }
  10900. SpriteConst.ALPHA = 0x01;
  10901. SpriteConst.TRANSFORM = 0x02;
  10902. SpriteConst.BLEND = 0x04;
  10903. SpriteConst.CANVAS = 0x08;
  10904. SpriteConst.FILTERS = 0x10;
  10905. SpriteConst.MASK = 0x20;
  10906. SpriteConst.CLIP = 0x40;
  10907. SpriteConst.STYLE = 0x80;
  10908. SpriteConst.TEXTURE = 0x100;
  10909. SpriteConst.GRAPHICS = 0x200;
  10910. SpriteConst.LAYAGL3D = 0x400;
  10911. SpriteConst.CUSTOM = 0x800;
  10912. SpriteConst.ONECHILD = 0x1000;
  10913. SpriteConst.CHILDS = 0x2000;
  10914. SpriteConst.REPAINT_NONE = 0;
  10915. SpriteConst.REPAINT_NODE = 0x01;
  10916. SpriteConst.REPAINT_CACHE = 0x02;
  10917. SpriteConst.REPAINT_ALL = 0x03;
  10918. class ClipRectCmd {
  10919. static create(x, y, width, height) {
  10920. var cmd = Pool.getItemByClass("ClipRectCmd", ClipRectCmd);
  10921. cmd.x = x;
  10922. cmd.y = y;
  10923. cmd.width = width;
  10924. cmd.height = height;
  10925. return cmd;
  10926. }
  10927. recover() {
  10928. Pool.recover("ClipRectCmd", this);
  10929. }
  10930. run(context, gx, gy) {
  10931. context.clipRect(this.x + gx, this.y + gy, this.width, this.height);
  10932. }
  10933. get cmdID() {
  10934. return ClipRectCmd.ID;
  10935. }
  10936. }
  10937. ClipRectCmd.ID = "ClipRect";
  10938. class DrawTexturesCmd {
  10939. static create(texture, pos) {
  10940. var cmd = Pool.getItemByClass("DrawTexturesCmd", DrawTexturesCmd);
  10941. cmd.texture = texture;
  10942. texture._addReference();
  10943. cmd.pos = pos;
  10944. return cmd;
  10945. }
  10946. recover() {
  10947. this.texture._removeReference();
  10948. this.texture = null;
  10949. this.pos = null;
  10950. Pool.recover("DrawTexturesCmd", this);
  10951. }
  10952. run(context, gx, gy) {
  10953. context.drawTextures(this.texture, this.pos, gx, gy);
  10954. }
  10955. get cmdID() {
  10956. return DrawTexturesCmd.ID;
  10957. }
  10958. }
  10959. DrawTexturesCmd.ID = "DrawTextures";
  10960. class FillTextCmd {
  10961. constructor() {
  10962. this._textIsWorldText = false;
  10963. this._fontColor = 0xffffffff;
  10964. this._strokeColor = 0;
  10965. this._fontObj = FillTextCmd._defFontObj;
  10966. this._nTexAlign = 0;
  10967. }
  10968. static create(text, words, x, y, font, color, textAlign, lineWidth, borderColor) {
  10969. var cmd = Pool.getItemByClass("FillTextCmd", FillTextCmd);
  10970. cmd.text = text;
  10971. cmd._textIsWorldText = text instanceof WordText;
  10972. cmd._words = words;
  10973. cmd.x = x;
  10974. cmd.y = y;
  10975. cmd.font = font;
  10976. cmd.color = color;
  10977. cmd.textAlign = textAlign;
  10978. cmd._lineWidth = lineWidth;
  10979. cmd._borderColor = borderColor;
  10980. return cmd;
  10981. }
  10982. recover() {
  10983. Pool.recover("FillTextCmd", this);
  10984. }
  10985. run(context, gx, gy) {
  10986. if (ILaya.stage.isGlobalRepaint()) {
  10987. this._textIsWorldText && this._text.cleanCache();
  10988. }
  10989. if (this._words) {
  10990. Context._textRender.fillWords(context, this._words, this.x + gx, this.y + gy, this._fontObj, this._color, this._borderColor, this._lineWidth);
  10991. }
  10992. else {
  10993. if (this._textIsWorldText) {
  10994. context._fast_filltext(this._text, this.x + gx, this.y + gy, this._fontObj, this._color, this._borderColor, this._lineWidth, this._nTexAlign, 0);
  10995. }
  10996. else {
  10997. Context._textRender.filltext(context, this._text, this.x + gx, this.y + gy, this.font, this.color, this._borderColor, this._lineWidth, this._textAlign);
  10998. }
  10999. }
  11000. }
  11001. get cmdID() {
  11002. return FillTextCmd.ID;
  11003. }
  11004. get text() {
  11005. return this._text;
  11006. }
  11007. set text(value) {
  11008. this._text = value;
  11009. this._textIsWorldText = value instanceof WordText;
  11010. this._textIsWorldText && this._text.cleanCache();
  11011. }
  11012. get font() {
  11013. return this._font;
  11014. }
  11015. set font(value) {
  11016. this._font = value;
  11017. this._fontObj = FontInfo.Parse(value);
  11018. this._textIsWorldText && this._text.cleanCache();
  11019. }
  11020. get color() {
  11021. return this._color;
  11022. }
  11023. set color(value) {
  11024. this._color = value;
  11025. this._fontColor = ColorUtils.create(value).numColor;
  11026. this._textIsWorldText && this._text.cleanCache();
  11027. }
  11028. get textAlign() {
  11029. return this._textAlign;
  11030. }
  11031. set textAlign(value) {
  11032. this._textAlign = value;
  11033. switch (value) {
  11034. case 'center':
  11035. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  11036. break;
  11037. case 'right':
  11038. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  11039. break;
  11040. default:
  11041. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_DEFAULT;
  11042. }
  11043. this._textIsWorldText && this._text.cleanCache();
  11044. }
  11045. }
  11046. FillTextCmd.ID = "FillText";
  11047. FillTextCmd._defFontObj = new FontInfo(null);
  11048. class CacheManger {
  11049. constructor() {
  11050. }
  11051. static regCacheByFunction(disposeFunction, getCacheListFunction) {
  11052. CacheManger.unRegCacheByFunction(disposeFunction, getCacheListFunction);
  11053. var cache;
  11054. cache = { tryDispose: disposeFunction, getCacheList: getCacheListFunction };
  11055. CacheManger._cacheList.push(cache);
  11056. }
  11057. static unRegCacheByFunction(disposeFunction, getCacheListFunction) {
  11058. var i, len;
  11059. len = CacheManger._cacheList.length;
  11060. for (i = 0; i < len; i++) {
  11061. if (CacheManger._cacheList[i].tryDispose == disposeFunction && CacheManger._cacheList[i].getCacheList == getCacheListFunction) {
  11062. CacheManger._cacheList.splice(i, 1);
  11063. return;
  11064. }
  11065. }
  11066. }
  11067. static forceDispose() {
  11068. var i, len = CacheManger._cacheList.length;
  11069. for (i = 0; i < len; i++) {
  11070. CacheManger._cacheList[i].tryDispose(true);
  11071. }
  11072. }
  11073. static beginCheck(waitTime = 15000) {
  11074. ILaya.systemTimer.loop(waitTime, null, CacheManger._checkLoop);
  11075. }
  11076. static stopCheck() {
  11077. ILaya.systemTimer.clear(null, CacheManger._checkLoop);
  11078. }
  11079. static _checkLoop() {
  11080. var cacheList = CacheManger._cacheList;
  11081. if (cacheList.length < 1)
  11082. return;
  11083. var tTime = ILaya.Browser.now();
  11084. var count;
  11085. var len;
  11086. len = count = cacheList.length;
  11087. while (count > 0) {
  11088. CacheManger._index++;
  11089. CacheManger._index = CacheManger._index % len;
  11090. cacheList[CacheManger._index].tryDispose(false);
  11091. if (ILaya.Browser.now() - tTime > CacheManger.loopTimeLimit)
  11092. break;
  11093. count--;
  11094. }
  11095. }
  11096. }
  11097. CacheManger.loopTimeLimit = 2;
  11098. CacheManger._cacheList = [];
  11099. CacheManger._index = 0;
  11100. class VectorGraphManager {
  11101. constructor() {
  11102. this.useDic = {};
  11103. this.shapeDic = {};
  11104. this.shapeLineDic = {};
  11105. this._id = 0;
  11106. this._checkKey = false;
  11107. this._freeIdArray = [];
  11108. CacheManger.regCacheByFunction(this.startDispose.bind(this), this.getCacheList.bind(this));
  11109. }
  11110. static getInstance() {
  11111. return VectorGraphManager.instance = VectorGraphManager.instance || new VectorGraphManager();
  11112. }
  11113. getId() {
  11114. return this._id++;
  11115. }
  11116. addShape(id, shape) {
  11117. this.shapeDic[id] = shape;
  11118. if (!this.useDic[id]) {
  11119. this.useDic[id] = true;
  11120. }
  11121. }
  11122. addLine(id, Line) {
  11123. this.shapeLineDic[id] = Line;
  11124. if (!this.shapeLineDic[id]) {
  11125. this.shapeLineDic[id] = true;
  11126. }
  11127. }
  11128. getShape(id) {
  11129. if (this._checkKey) {
  11130. if (this.useDic[id] != null) {
  11131. this.useDic[id] = true;
  11132. }
  11133. }
  11134. }
  11135. deleteShape(id) {
  11136. if (this.shapeDic[id]) {
  11137. this.shapeDic[id] = null;
  11138. delete this.shapeDic[id];
  11139. }
  11140. if (this.shapeLineDic[id]) {
  11141. this.shapeLineDic[id] = null;
  11142. delete this.shapeLineDic[id];
  11143. }
  11144. if (this.useDic[id] != null) {
  11145. delete this.useDic[id];
  11146. }
  11147. }
  11148. getCacheList() {
  11149. var str;
  11150. var list = [];
  11151. for (str in this.shapeDic) {
  11152. list.push(this.shapeDic[str]);
  11153. }
  11154. for (str in this.shapeLineDic) {
  11155. list.push(this.shapeLineDic[str]);
  11156. }
  11157. return list;
  11158. }
  11159. startDispose(key) {
  11160. var str;
  11161. for (str in this.useDic) {
  11162. this.useDic[str] = false;
  11163. }
  11164. this._checkKey = true;
  11165. }
  11166. endDispose() {
  11167. if (this._checkKey) {
  11168. var str;
  11169. for (str in this.useDic) {
  11170. if (!this.useDic[str]) {
  11171. this.deleteShape(str);
  11172. }
  11173. }
  11174. this._checkKey = false;
  11175. }
  11176. }
  11177. }
  11178. class Graphics {
  11179. constructor() {
  11180. this._sp = null;
  11181. this._one = null;
  11182. this._render = this._renderEmpty;
  11183. this._cmds = null;
  11184. this._vectorgraphArray = null;
  11185. this._graphicBounds = null;
  11186. this.autoDestroy = false;
  11187. this._createData();
  11188. }
  11189. _createData() {
  11190. }
  11191. _clearData() {
  11192. }
  11193. _destroyData() {
  11194. }
  11195. destroy() {
  11196. this.clear(true);
  11197. if (this._graphicBounds)
  11198. this._graphicBounds.destroy();
  11199. this._graphicBounds = null;
  11200. this._vectorgraphArray = null;
  11201. if (this._sp) {
  11202. this._sp._renderType = 0;
  11203. this._sp._setRenderType(0);
  11204. this._sp = null;
  11205. }
  11206. this._destroyData();
  11207. }
  11208. clear(recoverCmds = true) {
  11209. if (recoverCmds) {
  11210. var tCmd = this._one;
  11211. if (this._cmds) {
  11212. var i, len = this._cmds.length;
  11213. for (i = 0; i < len; i++) {
  11214. tCmd = this._cmds[i];
  11215. tCmd.recover();
  11216. }
  11217. this._cmds.length = 0;
  11218. }
  11219. else if (tCmd) {
  11220. tCmd.recover();
  11221. }
  11222. }
  11223. else {
  11224. this._cmds = null;
  11225. }
  11226. this._one = null;
  11227. this._render = this._renderEmpty;
  11228. this._clearData();
  11229. if (this._sp) {
  11230. this._sp._renderType &= ~SpriteConst.GRAPHICS;
  11231. this._sp._setRenderType(this._sp._renderType);
  11232. }
  11233. this._repaint();
  11234. if (this._vectorgraphArray) {
  11235. for (i = 0, len = this._vectorgraphArray.length; i < len; i++) {
  11236. VectorGraphManager.getInstance().deleteShape(this._vectorgraphArray[i]);
  11237. }
  11238. this._vectorgraphArray.length = 0;
  11239. }
  11240. }
  11241. _clearBoundsCache() {
  11242. if (this._graphicBounds)
  11243. this._graphicBounds.reset();
  11244. }
  11245. _initGraphicBounds() {
  11246. if (!this._graphicBounds) {
  11247. this._graphicBounds = GraphicsBounds.create();
  11248. this._graphicBounds._graphics = this;
  11249. }
  11250. }
  11251. _repaint() {
  11252. this._clearBoundsCache();
  11253. this._sp && this._sp.repaint();
  11254. }
  11255. _isOnlyOne() {
  11256. return !this._cmds || this._cmds.length === 0;
  11257. }
  11258. get cmds() {
  11259. return this._cmds;
  11260. }
  11261. set cmds(value) {
  11262. if (this._sp) {
  11263. this._sp._renderType |= SpriteConst.GRAPHICS;
  11264. this._sp._setRenderType(this._sp._renderType);
  11265. }
  11266. this._cmds = value;
  11267. this._render = this._renderAll;
  11268. this._repaint();
  11269. }
  11270. getBounds(realSize = false) {
  11271. this._initGraphicBounds();
  11272. return this._graphicBounds.getBounds(realSize);
  11273. }
  11274. getBoundPoints(realSize = false) {
  11275. this._initGraphicBounds();
  11276. return this._graphicBounds.getBoundPoints(realSize);
  11277. }
  11278. drawImage(texture, x = 0, y = 0, width = 0, height = 0) {
  11279. if (!texture)
  11280. return null;
  11281. if (!width)
  11282. width = texture.sourceWidth;
  11283. if (!height)
  11284. height = texture.sourceHeight;
  11285. if (texture.getIsReady()) {
  11286. var wRate = width / texture.sourceWidth;
  11287. var hRate = height / texture.sourceHeight;
  11288. width = texture.width * wRate;
  11289. height = texture.height * hRate;
  11290. if (width <= 0 || height <= 0)
  11291. return null;
  11292. x += texture.offsetX * wRate;
  11293. y += texture.offsetY * hRate;
  11294. }
  11295. if (this._sp) {
  11296. this._sp._renderType |= SpriteConst.GRAPHICS;
  11297. this._sp._setRenderType(this._sp._renderType);
  11298. }
  11299. var args = DrawImageCmd.create.call(this, texture, x, y, width, height);
  11300. if (this._one == null) {
  11301. this._one = args;
  11302. this._render = this._renderOneImg;
  11303. }
  11304. else {
  11305. this._saveToCmd(null, args);
  11306. }
  11307. this._repaint();
  11308. return args;
  11309. }
  11310. drawTexture(texture, x = 0, y = 0, width = 0, height = 0, matrix = null, alpha = 1, color = null, blendMode = null, uv) {
  11311. if (!texture || alpha < 0.01)
  11312. return null;
  11313. if (!texture.getIsReady())
  11314. return null;
  11315. if (!width)
  11316. width = texture.sourceWidth;
  11317. if (!height)
  11318. height = texture.sourceHeight;
  11319. if (texture.getIsReady()) {
  11320. var wRate = width / texture.sourceWidth;
  11321. var hRate = height / texture.sourceHeight;
  11322. width = texture.width * wRate;
  11323. height = texture.height * hRate;
  11324. if (width <= 0 || height <= 0)
  11325. return null;
  11326. x += texture.offsetX * wRate;
  11327. y += texture.offsetY * hRate;
  11328. }
  11329. if (this._sp) {
  11330. this._sp._renderType |= SpriteConst.GRAPHICS;
  11331. this._sp._setRenderType(this._sp._renderType);
  11332. }
  11333. var args = DrawTextureCmd.create.call(this, texture, x, y, width, height, matrix, alpha, color, blendMode, uv);
  11334. this._repaint();
  11335. return this._saveToCmd(null, args);
  11336. }
  11337. drawTextures(texture, pos) {
  11338. if (!texture)
  11339. return null;
  11340. return this._saveToCmd(Render._context.drawTextures, DrawTexturesCmd.create.call(this, texture, pos));
  11341. }
  11342. drawTriangles(texture, x, y, vertices, uvs, indices, matrix = null, alpha = 1, color = null, blendMode = null, colorNum = undefined) {
  11343. return this._saveToCmd(Render._context.drawTriangles, DrawTrianglesCmd.create.call(this, texture, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode, colorNum));
  11344. }
  11345. fillTexture(texture, x, y, width = 0, height = 0, type = "repeat", offset = null) {
  11346. if (texture && texture.getIsReady())
  11347. return this._saveToCmd(Render._context._fillTexture, FillTextureCmd.create.call(this, texture, x, y, width, height, type, offset || Point.EMPTY, {}));
  11348. else
  11349. return null;
  11350. }
  11351. _saveToCmd(fun, args) {
  11352. if (this._sp) {
  11353. this._sp._renderType |= SpriteConst.GRAPHICS;
  11354. this._sp._setRenderType(this._sp._renderType);
  11355. }
  11356. if (this._one == null) {
  11357. this._one = args;
  11358. this._render = this._renderOne;
  11359. }
  11360. else {
  11361. this._render = this._renderAll;
  11362. (this._cmds || (this._cmds = [])).length === 0 && this._cmds.push(this._one);
  11363. this._cmds.push(args);
  11364. }
  11365. this._repaint();
  11366. return args;
  11367. }
  11368. clipRect(x, y, width, height) {
  11369. return this._saveToCmd(Render._context.clipRect, ClipRectCmd.create.call(this, x, y, width, height));
  11370. }
  11371. fillText(text, x, y, font, color, textAlign) {
  11372. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, text, null, x, y, font || ILaya.Text.defaultFontStr(), color, textAlign, 0, ""));
  11373. }
  11374. fillBorderText(text, x, y, font, fillColor, textAlign, lineWidth, borderColor) {
  11375. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, text, null, x, y, font || ILaya.Text.defaultFontStr(), fillColor, textAlign, lineWidth, borderColor));
  11376. }
  11377. fillWords(words, x, y, font, color) {
  11378. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, null, words, x, y, font || ILaya.Text.defaultFontStr(), color));
  11379. }
  11380. fillBorderWords(words, x, y, font, fillColor, borderColor, lineWidth) {
  11381. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, null, words, x, y, font || ILaya.Text.defaultFontStr(), fillColor, "", lineWidth, borderColor));
  11382. }
  11383. strokeText(text, x, y, font, color, lineWidth, textAlign) {
  11384. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, text, null, x, y, font || ILaya.Text.defaultFontStr(), null, textAlign, lineWidth, color));
  11385. }
  11386. alpha(alpha) {
  11387. return this._saveToCmd(Render._context.alpha, AlphaCmd.create.call(this, alpha));
  11388. }
  11389. transform(matrix, pivotX = 0, pivotY = 0) {
  11390. return this._saveToCmd(Render._context._transform, TransformCmd.create.call(this, matrix, pivotX, pivotY));
  11391. }
  11392. rotate(angle, pivotX = 0, pivotY = 0) {
  11393. return this._saveToCmd(Render._context._rotate, RotateCmd.create.call(this, angle, pivotX, pivotY));
  11394. }
  11395. scale(scaleX, scaleY, pivotX = 0, pivotY = 0) {
  11396. return this._saveToCmd(Render._context._scale, ScaleCmd.create.call(this, scaleX, scaleY, pivotX, pivotY));
  11397. }
  11398. translate(tx, ty) {
  11399. return this._saveToCmd(Render._context.translate, TranslateCmd.create.call(this, tx, ty));
  11400. }
  11401. save() {
  11402. return this._saveToCmd(Render._context._save, SaveCmd.create.call(this));
  11403. }
  11404. restore() {
  11405. return this._saveToCmd(Render._context.restore, RestoreCmd.create.call(this));
  11406. }
  11407. replaceText(text) {
  11408. this._repaint();
  11409. var cmds = this._cmds;
  11410. if (!cmds) {
  11411. if (this._one && this._isTextCmd(this._one)) {
  11412. this._one.text = text;
  11413. return true;
  11414. }
  11415. }
  11416. else {
  11417. for (var i = cmds.length - 1; i > -1; i--) {
  11418. if (this._isTextCmd(cmds[i])) {
  11419. cmds[i].text = text;
  11420. return true;
  11421. }
  11422. }
  11423. }
  11424. return false;
  11425. }
  11426. _isTextCmd(cmd) {
  11427. var cmdID = cmd.cmdID;
  11428. return cmdID == FillTextCmd.ID;
  11429. }
  11430. replaceTextColor(color) {
  11431. this._repaint();
  11432. var cmds = this._cmds;
  11433. if (!cmds) {
  11434. if (this._one && this._isTextCmd(this._one)) {
  11435. this._setTextCmdColor(this._one, color);
  11436. }
  11437. }
  11438. else {
  11439. for (var i = cmds.length - 1; i > -1; i--) {
  11440. if (this._isTextCmd(cmds[i])) {
  11441. this._setTextCmdColor(cmds[i], color);
  11442. }
  11443. }
  11444. }
  11445. }
  11446. _setTextCmdColor(cmdO, color) {
  11447. var cmdID = cmdO.cmdID;
  11448. switch (cmdID) {
  11449. case FillTextCmd.ID:
  11450. cmdO.color = color;
  11451. break;
  11452. }
  11453. }
  11454. loadImage(url, x = 0, y = 0, width = 0, height = 0, complete = null) {
  11455. var tex = ILaya.Loader.getRes(url);
  11456. if (!tex) {
  11457. tex = new Texture();
  11458. tex.load(url);
  11459. ILaya.Loader.cacheTexture(url, tex);
  11460. tex.once(Event.READY, this, this.drawImage, [tex, x, y, width, height]);
  11461. }
  11462. else {
  11463. if (!tex.getIsReady()) {
  11464. tex.once(Event.READY, this, this.drawImage, [tex, x, y, width, height]);
  11465. }
  11466. else
  11467. this.drawImage(tex, x, y, width, height);
  11468. }
  11469. if (complete != null) {
  11470. tex.getIsReady() ? complete.call(this._sp) : tex.on(Event.READY, this._sp, complete);
  11471. }
  11472. }
  11473. _renderEmpty(sprite, context, x, y) {
  11474. }
  11475. _renderAll(sprite, context, x, y) {
  11476. var cmds = this._cmds;
  11477. for (var i = 0, n = cmds.length; i < n; i++) {
  11478. cmds[i].run(context, x, y);
  11479. }
  11480. }
  11481. _renderOne(sprite, context, x, y) {
  11482. context.sprite = sprite;
  11483. this._one.run(context, x, y);
  11484. }
  11485. _renderOneImg(sprite, context, x, y) {
  11486. context.sprite = sprite;
  11487. this._one.run(context, x, y);
  11488. }
  11489. drawLine(fromX, fromY, toX, toY, lineColor, lineWidth = 1) {
  11490. var offset = (lineWidth < 1 || lineWidth % 2 === 0) ? 0 : 0.5;
  11491. return this._saveToCmd(Render._context._drawLine, DrawLineCmd.create.call(this, fromX + offset, fromY + offset, toX + offset, toY + offset, lineColor, lineWidth, 0));
  11492. }
  11493. drawLines(x, y, points, lineColor, lineWidth = 1) {
  11494. if (!points || points.length < 4)
  11495. return null;
  11496. var offset = (lineWidth < 1 || lineWidth % 2 === 0) ? 0 : 0.5;
  11497. return this._saveToCmd(Render._context._drawLines, DrawLinesCmd.create.call(this, x + offset, y + offset, points, lineColor, lineWidth, 0));
  11498. }
  11499. drawCurves(x, y, points, lineColor, lineWidth = 1) {
  11500. return this._saveToCmd(Render._context.drawCurves, DrawCurvesCmd.create.call(this, x, y, points, lineColor, lineWidth));
  11501. }
  11502. drawRect(x, y, width, height, fillColor, lineColor = null, lineWidth = 1) {
  11503. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11504. var lineOffset = lineColor ? lineWidth : 0;
  11505. return this._saveToCmd(Render._context.drawRect, DrawRectCmd.create.call(this, x + offset, y + offset, width - lineOffset, height - lineOffset, fillColor, lineColor, lineWidth));
  11506. }
  11507. drawCircle(x, y, radius, fillColor, lineColor = null, lineWidth = 1) {
  11508. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11509. return this._saveToCmd(Render._context._drawCircle, DrawCircleCmd.create.call(this, x, y, radius - offset, fillColor, lineColor, lineWidth, 0));
  11510. }
  11511. drawPie(x, y, radius, startAngle, endAngle, fillColor, lineColor = null, lineWidth = 1) {
  11512. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11513. var lineOffset = lineColor ? lineWidth : 0;
  11514. return this._saveToCmd(Render._context._drawPie, DrawPieCmd.create.call(this, x + offset, y + offset, radius - lineOffset, Utils.toRadian(startAngle), Utils.toRadian(endAngle), fillColor, lineColor, lineWidth, 0));
  11515. }
  11516. drawPoly(x, y, points, fillColor, lineColor = null, lineWidth = 1) {
  11517. var tIsConvexPolygon = false;
  11518. if (points.length > 6) {
  11519. tIsConvexPolygon = false;
  11520. }
  11521. else {
  11522. tIsConvexPolygon = true;
  11523. }
  11524. var offset = (lineWidth >= 1 && lineColor) ? (lineWidth % 2 === 0 ? 0 : 0.5) : 0;
  11525. return this._saveToCmd(Render._context._drawPoly, DrawPolyCmd.create.call(this, x + offset, y + offset, points, fillColor, lineColor, lineWidth, tIsConvexPolygon, 0));
  11526. }
  11527. drawPath(x, y, paths, brush = null, pen = null) {
  11528. return this._saveToCmd(Render._context._drawPath, DrawPathCmd.create.call(this, x, y, paths, brush, pen));
  11529. }
  11530. draw9Grid(texture, x = 0, y = 0, width = 0, height = 0, sizeGrid = null) {
  11531. this._saveToCmd(null, Draw9GridTexture.create(texture, x, y, width, height, sizeGrid));
  11532. }
  11533. }
  11534. class Const {
  11535. }
  11536. Const.NOT_ACTIVE = 0x01;
  11537. Const.ACTIVE_INHIERARCHY = 0x02;
  11538. Const.AWAKED = 0x04;
  11539. Const.NOT_READY = 0x08;
  11540. Const.DISPLAY = 0x10;
  11541. Const.HAS_ZORDER = 0x20;
  11542. Const.HAS_MOUSE = 0x40;
  11543. Const.DISPLAYED_INSTAGE = 0x80;
  11544. Const.DRAWCALL_OPTIMIZE = 0x100;
  11545. class LayaGLQuickRunner {
  11546. static __init__() {
  11547. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TRANSFORM | SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_transform_drawLayaGL;
  11548. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_drawLayaGL;
  11549. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.GRAPHICS] = LayaGLQuickRunner.transform_drawLayaGL;
  11550. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.CHILDS] = LayaGLQuickRunner.transform_drawNodes;
  11551. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TRANSFORM | SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_transform_drawTexture;
  11552. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_drawTexture;
  11553. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.TEXTURE] = LayaGLQuickRunner.transform_drawTexture;
  11554. LayaGLQuickRunner.map[SpriteConst.GRAPHICS | SpriteConst.CHILDS] = LayaGLQuickRunner.drawLayaGL_drawNodes;
  11555. }
  11556. static transform_drawTexture(sprite, context, x, y) {
  11557. var style = sprite._style;
  11558. var tex = sprite.texture;
  11559. context.saveTransform(LayaGLQuickRunner.curMat);
  11560. context.transformByMatrix(sprite.transform, x, y);
  11561. var width = sprite._width || tex.sourceWidth;
  11562. var height = sprite._height || tex.sourceHeight;
  11563. var wRate = width / tex.sourceWidth;
  11564. var hRate = height / tex.sourceHeight;
  11565. width = tex.width * wRate;
  11566. height = tex.height * hRate;
  11567. if (width <= 0 || height <= 0)
  11568. return null;
  11569. var px = -sprite.pivotX + tex.offsetX * wRate;
  11570. var py = -sprite.pivotY + tex.offsetY * hRate;
  11571. context.drawTexture(tex, px, py, width, height);
  11572. context.restoreTransform(LayaGLQuickRunner.curMat);
  11573. }
  11574. static alpha_drawTexture(sprite, context, x, y) {
  11575. var style = sprite._style;
  11576. var alpha;
  11577. var tex = sprite.texture;
  11578. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11579. var temp = context.globalAlpha;
  11580. context.globalAlpha *= alpha;
  11581. context.drawTexture(tex, x - style.pivotX + tex.offsetX, y - style.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  11582. context.globalAlpha = temp;
  11583. }
  11584. }
  11585. static alpha_transform_drawTexture(sprite, context, x, y) {
  11586. var style = sprite._style;
  11587. var alpha;
  11588. var tex = sprite.texture;
  11589. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11590. var temp = context.globalAlpha;
  11591. context.globalAlpha *= alpha;
  11592. context.saveTransform(LayaGLQuickRunner.curMat);
  11593. context.transformByMatrix(sprite.transform, x, y);
  11594. context.drawTexture(tex, -style.pivotX + tex.offsetX, -style.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  11595. context.restoreTransform(LayaGLQuickRunner.curMat);
  11596. context.globalAlpha = temp;
  11597. }
  11598. }
  11599. static alpha_transform_drawLayaGL(sprite, context, x, y) {
  11600. var style = sprite._style;
  11601. var alpha;
  11602. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11603. var temp = context.globalAlpha;
  11604. context.globalAlpha *= alpha;
  11605. context.saveTransform(LayaGLQuickRunner.curMat);
  11606. context.transformByMatrix(sprite.transform, x, y);
  11607. sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY);
  11608. context.restoreTransform(LayaGLQuickRunner.curMat);
  11609. context.globalAlpha = temp;
  11610. }
  11611. }
  11612. static alpha_drawLayaGL(sprite, context, x, y) {
  11613. var style = sprite._style;
  11614. var alpha;
  11615. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11616. var temp = context.globalAlpha;
  11617. context.globalAlpha *= alpha;
  11618. sprite._graphics && sprite._graphics._render(sprite, context, x - style.pivotX, y - style.pivotY);
  11619. context.globalAlpha = temp;
  11620. }
  11621. }
  11622. static transform_drawLayaGL(sprite, context, x, y) {
  11623. var style = sprite._style;
  11624. context.saveTransform(LayaGLQuickRunner.curMat);
  11625. context.transformByMatrix(sprite.transform, x, y);
  11626. sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY);
  11627. context.restoreTransform(LayaGLQuickRunner.curMat);
  11628. }
  11629. static transform_drawNodes(sprite, context, x, y) {
  11630. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  11631. var style = sprite._style;
  11632. context.saveTransform(LayaGLQuickRunner.curMat);
  11633. context.transformByMatrix(sprite.transform, x, y);
  11634. x = -style.pivotX;
  11635. y = -style.pivotY;
  11636. var childs = sprite._children, n = childs.length, ele;
  11637. if (style.viewport) {
  11638. var rect = style.viewport;
  11639. var left = rect.x;
  11640. var top = rect.y;
  11641. var right = rect.right;
  11642. var bottom = rect.bottom;
  11643. var _x, _y;
  11644. for (i = 0; i < n; ++i) {
  11645. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  11646. ele.render(context, x, y);
  11647. }
  11648. }
  11649. }
  11650. else {
  11651. for (var i = 0; i < n; ++i)
  11652. (ele = childs[i])._visible && ele.render(context, x, y);
  11653. }
  11654. context.restoreTransform(LayaGLQuickRunner.curMat);
  11655. textLastRender && context.drawCallOptimize(false);
  11656. }
  11657. static drawLayaGL_drawNodes(sprite, context, x, y) {
  11658. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  11659. var style = sprite._style;
  11660. x = x - style.pivotX;
  11661. y = y - style.pivotY;
  11662. sprite._graphics && sprite._graphics._render(sprite, context, x, y);
  11663. var childs = sprite._children, n = childs.length, ele;
  11664. if (style.viewport) {
  11665. var rect = style.viewport;
  11666. var left = rect.x;
  11667. var top = rect.y;
  11668. var right = rect.right;
  11669. var bottom = rect.bottom;
  11670. var _x, _y;
  11671. for (i = 0; i < n; ++i) {
  11672. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  11673. ele.render(context, x, y);
  11674. }
  11675. }
  11676. }
  11677. else {
  11678. for (var i = 0; i < n; ++i)
  11679. (ele = childs[i])._visible && ele.render(context, x, y);
  11680. }
  11681. textLastRender && context.drawCallOptimize(false);
  11682. }
  11683. }
  11684. LayaGLQuickRunner.map = [];
  11685. LayaGLQuickRunner.curMat = new Matrix();
  11686. class RenderSprite {
  11687. constructor(type, next) {
  11688. if (LayaGLQuickRunner.map[type]) {
  11689. this._fun = LayaGLQuickRunner.map[type];
  11690. this._next = RenderSprite.NORENDER;
  11691. return;
  11692. }
  11693. this._next = next || RenderSprite.NORENDER;
  11694. switch (type) {
  11695. case 0:
  11696. this._fun = this._no;
  11697. return;
  11698. case SpriteConst.ALPHA:
  11699. this._fun = this._alpha;
  11700. return;
  11701. case SpriteConst.TRANSFORM:
  11702. this._fun = this._transform;
  11703. return;
  11704. case SpriteConst.BLEND:
  11705. this._fun = this._blend;
  11706. return;
  11707. case SpriteConst.CANVAS:
  11708. this._fun = this._canvas;
  11709. return;
  11710. case SpriteConst.MASK:
  11711. this._fun = this._mask;
  11712. return;
  11713. case SpriteConst.CLIP:
  11714. this._fun = this._clip;
  11715. return;
  11716. case SpriteConst.STYLE:
  11717. this._fun = this._style;
  11718. return;
  11719. case SpriteConst.GRAPHICS:
  11720. this._fun = this._graphics;
  11721. return;
  11722. case SpriteConst.CHILDS:
  11723. this._fun = this._children;
  11724. return;
  11725. case SpriteConst.CUSTOM:
  11726. this._fun = this._custom;
  11727. return;
  11728. case SpriteConst.TEXTURE:
  11729. this._fun = this._texture;
  11730. return;
  11731. case SpriteConst.FILTERS:
  11732. this._fun = Filter._filter;
  11733. return;
  11734. case RenderSprite.INIT:
  11735. this._fun = RenderSprite._initRenderFun;
  11736. return;
  11737. }
  11738. this.onCreate(type);
  11739. }
  11740. static __init__() {
  11741. LayaGLQuickRunner.__init__();
  11742. var i, len;
  11743. var initRender;
  11744. initRender = new RenderSprite(RenderSprite.INIT, null);
  11745. len = RenderSprite.renders.length = SpriteConst.CHILDS * 2;
  11746. for (i = 0; i < len; i++)
  11747. RenderSprite.renders[i] = initRender;
  11748. RenderSprite.renders[0] = new RenderSprite(0, null);
  11749. }
  11750. static _initRenderFun(sprite, context, x, y) {
  11751. var type = sprite._renderType;
  11752. var r = RenderSprite.renders[type] = RenderSprite._getTypeRender(type);
  11753. r._fun(sprite, context, x, y);
  11754. }
  11755. static _getTypeRender(type) {
  11756. if (LayaGLQuickRunner.map[type])
  11757. return new RenderSprite(type, null);
  11758. var rst = null;
  11759. var tType = SpriteConst.CHILDS;
  11760. while (tType > 0) {
  11761. if (tType & type)
  11762. rst = new RenderSprite(tType, rst);
  11763. tType = tType >> 1;
  11764. }
  11765. return rst;
  11766. }
  11767. onCreate(type) {
  11768. }
  11769. _style(sprite, context, x, y) {
  11770. var style = sprite._style;
  11771. if (style.render != null)
  11772. style.render(sprite, context, x, y);
  11773. var next = this._next;
  11774. next._fun.call(next, sprite, context, x, y);
  11775. }
  11776. _no(sprite, context, x, y) {
  11777. }
  11778. _custom(sprite, context, x, y) {
  11779. sprite.customRender(context, x, y);
  11780. this._next._fun.call(this._next, sprite, context, 0, 0);
  11781. }
  11782. _clip(sprite, context, x, y) {
  11783. var next = this._next;
  11784. if (next == RenderSprite.NORENDER)
  11785. return;
  11786. var r = sprite._style.scrollRect;
  11787. var width = r.width;
  11788. var height = r.height;
  11789. if (width === 0 || height === 0) {
  11790. return;
  11791. }
  11792. context.save();
  11793. context.clipRect(x, y, width, height);
  11794. next._fun.call(next, sprite, context, x - r.x, y - r.y);
  11795. context.restore();
  11796. }
  11797. _texture(sprite, context, x, y) {
  11798. var tex = sprite.texture;
  11799. if (tex._getSource()) {
  11800. var width = sprite._width || tex.sourceWidth;
  11801. var height = sprite._height || tex.sourceHeight;
  11802. var wRate = width / tex.sourceWidth;
  11803. var hRate = height / tex.sourceHeight;
  11804. width = tex.width * wRate;
  11805. height = tex.height * hRate;
  11806. if (width <= 0 || height <= 0)
  11807. return;
  11808. var px = x - sprite.pivotX + tex.offsetX * wRate;
  11809. var py = y - sprite.pivotY + tex.offsetY * hRate;
  11810. context.drawTexture(tex, px, py, width, height);
  11811. }
  11812. var next = this._next;
  11813. if (next != RenderSprite.NORENDER)
  11814. next._fun.call(next, sprite, context, x, y);
  11815. }
  11816. _graphics(sprite, context, x, y) {
  11817. var style = sprite._style;
  11818. var g = sprite._graphics;
  11819. g && g._render(sprite, context, x - style.pivotX, y - style.pivotY);
  11820. var next = this._next;
  11821. if (next != RenderSprite.NORENDER)
  11822. next._fun.call(next, sprite, context, x, y);
  11823. }
  11824. _image(sprite, context, x, y) {
  11825. var style = sprite._style;
  11826. context.drawTexture2(x, y, style.pivotX, style.pivotY, sprite.transform, sprite._graphics._one);
  11827. }
  11828. _image2(sprite, context, x, y) {
  11829. var style = sprite._style;
  11830. context.drawTexture2(x, y, style.pivotX, style.pivotY, sprite.transform, sprite._graphics._one);
  11831. }
  11832. _alpha(sprite, context, x, y) {
  11833. var style = sprite._style;
  11834. var alpha;
  11835. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  11836. var temp = context.globalAlpha;
  11837. context.globalAlpha *= alpha;
  11838. var next = this._next;
  11839. next._fun.call(next, sprite, context, x, y);
  11840. context.globalAlpha = temp;
  11841. }
  11842. }
  11843. _transform(sprite, context, x, y) {
  11844. var transform = sprite.transform, _next = this._next;
  11845. var style = sprite._style;
  11846. if (transform && _next != RenderSprite.NORENDER) {
  11847. context.save();
  11848. context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx + x, transform.ty + y);
  11849. _next._fun.call(_next, sprite, context, 0, 0);
  11850. context.restore();
  11851. }
  11852. else {
  11853. if (_next != RenderSprite.NORENDER)
  11854. _next._fun.call(_next, sprite, context, x, y);
  11855. }
  11856. }
  11857. _children(sprite, context, x, y) {
  11858. var style = sprite._style;
  11859. var childs = sprite._children, n = childs.length, ele;
  11860. x = x - sprite.pivotX;
  11861. y = y - sprite.pivotY;
  11862. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  11863. if (style.viewport) {
  11864. var rect = style.viewport;
  11865. var left = rect.x;
  11866. var top = rect.y;
  11867. var right = rect.right;
  11868. var bottom = rect.bottom;
  11869. var _x, _y;
  11870. for (i = 0; i < n; ++i) {
  11871. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  11872. ele.render(context, x, y);
  11873. }
  11874. }
  11875. }
  11876. else {
  11877. for (var i = 0; i < n; ++i)
  11878. (ele = childs[i])._visible && ele.render(context, x, y);
  11879. }
  11880. textLastRender && context.drawCallOptimize(false);
  11881. }
  11882. _canvas(sprite, context, x, y) {
  11883. var _cacheStyle = sprite._cacheStyle;
  11884. var _next = this._next;
  11885. if (!_cacheStyle.enableCanvasRender) {
  11886. _next._fun.call(_next, sprite, context, x, y);
  11887. return;
  11888. }
  11889. _cacheStyle.cacheAs === 'bitmap' ? (Stat.canvasBitmap++) : (Stat.canvasNormal++);
  11890. var cacheNeedRebuild = false;
  11891. var textNeedRestore = false;
  11892. if (_cacheStyle.canvas) {
  11893. var canv = _cacheStyle.canvas;
  11894. var ctx = canv.context;
  11895. var charRIs = canv.touches;
  11896. if (charRIs) {
  11897. for (var ci = 0; ci < charRIs.length; ci++) {
  11898. if (charRIs[ci].deleted) {
  11899. textNeedRestore = true;
  11900. break;
  11901. }
  11902. }
  11903. }
  11904. cacheNeedRebuild = canv.isCacheValid && !canv.isCacheValid();
  11905. }
  11906. if (sprite._needRepaint() || (!_cacheStyle.canvas) || textNeedRestore || cacheNeedRebuild || ILaya.stage.isGlobalRepaint()) {
  11907. if (_cacheStyle.cacheAs === 'normal') {
  11908. if (context._targets) {
  11909. _next._fun.call(_next, sprite, context, x, y);
  11910. return;
  11911. }
  11912. else {
  11913. this._canvas_webgl_normal_repaint(sprite, context);
  11914. }
  11915. }
  11916. else {
  11917. this._canvas_repaint(sprite, context, x, y);
  11918. }
  11919. }
  11920. var tRec = _cacheStyle.cacheRect;
  11921. context.drawCanvas(_cacheStyle.canvas, x + tRec.x, y + tRec.y, tRec.width, tRec.height);
  11922. }
  11923. _canvas_repaint(sprite, context, x, y) {
  11924. var _cacheStyle = sprite._cacheStyle;
  11925. var _next = this._next;
  11926. var tx;
  11927. var canvas = _cacheStyle.canvas;
  11928. var left;
  11929. var top;
  11930. var tRec;
  11931. var tCacheType = _cacheStyle.cacheAs;
  11932. var w, h;
  11933. var scaleX, scaleY;
  11934. var scaleInfo;
  11935. scaleInfo = _cacheStyle._calculateCacheRect(sprite, tCacheType, x, y);
  11936. scaleX = scaleInfo.x;
  11937. scaleY = scaleInfo.y;
  11938. tRec = _cacheStyle.cacheRect;
  11939. w = tRec.width * scaleX;
  11940. h = tRec.height * scaleY;
  11941. left = tRec.x;
  11942. top = tRec.y;
  11943. if (tCacheType === 'bitmap' && (w > 2048 || h > 2048)) {
  11944. console.warn("cache bitmap size larger than 2048,cache ignored");
  11945. _cacheStyle.releaseContext();
  11946. _next._fun.call(_next, sprite, context, x, y);
  11947. return;
  11948. }
  11949. if (!canvas) {
  11950. _cacheStyle.createContext();
  11951. canvas = _cacheStyle.canvas;
  11952. }
  11953. tx = canvas.context;
  11954. tx.sprite = sprite;
  11955. (canvas.width != w || canvas.height != h) && canvas.size(w, h);
  11956. if (tCacheType === 'bitmap')
  11957. tx.asBitmap = true;
  11958. else if (tCacheType === 'normal')
  11959. tx.asBitmap = false;
  11960. tx.clear();
  11961. if (scaleX != 1 || scaleY != 1) {
  11962. var ctx = tx;
  11963. ctx.save();
  11964. ctx.scale(scaleX, scaleY);
  11965. _next._fun.call(_next, sprite, tx, -left, -top);
  11966. ctx.restore();
  11967. sprite._applyFilters();
  11968. }
  11969. else {
  11970. ctx = tx;
  11971. _next._fun.call(_next, sprite, tx, -left, -top);
  11972. sprite._applyFilters();
  11973. }
  11974. if (_cacheStyle.staticCache)
  11975. _cacheStyle.reCache = false;
  11976. Stat.canvasReCache++;
  11977. }
  11978. _canvas_webgl_normal_repaint(sprite, context) {
  11979. var _cacheStyle = sprite._cacheStyle;
  11980. var _next = this._next;
  11981. var canvas = _cacheStyle.canvas;
  11982. var tCacheType = _cacheStyle.cacheAs;
  11983. _cacheStyle._calculateCacheRect(sprite, tCacheType, 0, 0);
  11984. if (!canvas) {
  11985. canvas = new WebGLCacheAsNormalCanvas(context, sprite);
  11986. _cacheStyle.canvas = canvas;
  11987. }
  11988. var tx = canvas.context;
  11989. canvas.startRec();
  11990. _next._fun.call(_next, sprite, tx, sprite.pivotX, sprite.pivotY);
  11991. sprite._applyFilters();
  11992. Stat.canvasReCache++;
  11993. canvas.endRec();
  11994. }
  11995. _blend(sprite, context, x, y) {
  11996. var style = sprite._style;
  11997. var next = this._next;
  11998. if (style.blendMode) {
  11999. context.save();
  12000. context.globalCompositeOperation = style.blendMode;
  12001. next._fun.call(next, sprite, context, x, y);
  12002. context.restore();
  12003. }
  12004. else {
  12005. next._fun.call(next, sprite, context, x, y);
  12006. }
  12007. }
  12008. _mask(sprite, context, x, y) {
  12009. var next = this._next;
  12010. var mask = sprite.mask;
  12011. var ctx = context;
  12012. if (mask) {
  12013. ctx.save();
  12014. var preBlendMode = ctx.globalCompositeOperation;
  12015. var tRect = new Rectangle();
  12016. tRect.copyFrom(mask.getBounds());
  12017. tRect.width = Math.round(tRect.width);
  12018. tRect.height = Math.round(tRect.height);
  12019. tRect.x = Math.round(tRect.x);
  12020. tRect.y = Math.round(tRect.y);
  12021. if (tRect.width > 0 && tRect.height > 0) {
  12022. var w = tRect.width;
  12023. var h = tRect.height;
  12024. var tmpRT = WebGLRTMgr.getRT(w, h);
  12025. ctx.breakNextMerge();
  12026. ctx.pushRT();
  12027. ctx.addRenderObject(SubmitCMD.create([ctx, tmpRT, w, h], RenderSprite.tmpTarget, this));
  12028. mask.render(ctx, -tRect.x, -tRect.y);
  12029. ctx.breakNextMerge();
  12030. ctx.popRT();
  12031. ctx.save();
  12032. ctx.clipRect(x + tRect.x - sprite.getStyle().pivotX, y + tRect.y - sprite.getStyle().pivotY, w, h);
  12033. next._fun.call(next, sprite, ctx, x, y);
  12034. ctx.restore();
  12035. preBlendMode = ctx.globalCompositeOperation;
  12036. ctx.addRenderObject(SubmitCMD.create(["mask"], RenderSprite.setBlendMode, this));
  12037. var shaderValue = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  12038. var uv = Texture.INV_UV;
  12039. ctx.drawTarget(tmpRT, x + tRect.x - sprite.getStyle().pivotX, y + tRect.y - sprite.getStyle().pivotY, w, h, Matrix.TEMP.identity(), shaderValue, uv, 6);
  12040. ctx.addRenderObject(SubmitCMD.create([tmpRT], RenderSprite.recycleTarget, this));
  12041. ctx.addRenderObject(SubmitCMD.create([preBlendMode], RenderSprite.setBlendMode, this));
  12042. }
  12043. ctx.restore();
  12044. }
  12045. else {
  12046. next._fun.call(next, sprite, context, x, y);
  12047. }
  12048. }
  12049. static tmpTarget(ctx, rt, w, h) {
  12050. rt.start();
  12051. rt.clear(0, 0, 0, 0);
  12052. }
  12053. static recycleTarget(rt) {
  12054. WebGLRTMgr.releaseRT(rt);
  12055. }
  12056. static setBlendMode(blendMode) {
  12057. var gl = WebGLContext.mainContext;
  12058. BlendMode.targetFns[BlendMode.TOINT[blendMode]](gl);
  12059. }
  12060. }
  12061. RenderSprite.INIT = 0x11111;
  12062. RenderSprite.renders = [];
  12063. RenderSprite.NORENDER = new RenderSprite(0, null);
  12064. RenderSprite.tempUV = new Array(8);
  12065. class HTMLCanvas extends Bitmap {
  12066. constructor(createCanvas = false) {
  12067. super();
  12068. if (createCanvas)
  12069. this._source = Browser.createElement("canvas");
  12070. else {
  12071. this._source = this;
  12072. }
  12073. this.lock = true;
  12074. }
  12075. get source() {
  12076. return this._source;
  12077. }
  12078. _getSource() {
  12079. return this._source;
  12080. }
  12081. clear() {
  12082. if (this._ctx) {
  12083. if (this._ctx.clear) {
  12084. this._ctx.clear();
  12085. }
  12086. else {
  12087. this._ctx.clearRect(0, 0, this._width, this._height);
  12088. }
  12089. }
  12090. if (this._texture) {
  12091. this._texture.destroy();
  12092. this._texture = null;
  12093. }
  12094. }
  12095. destroy() {
  12096. super.destroy();
  12097. this._setCPUMemory(0);
  12098. this._ctx && this._ctx.destroy && this._ctx.destroy();
  12099. this._ctx = null;
  12100. }
  12101. release() {
  12102. }
  12103. get context() {
  12104. if (this._ctx)
  12105. return this._ctx;
  12106. if (this._source == this) {
  12107. this._ctx = new ILaya.Context();
  12108. }
  12109. else {
  12110. this._ctx = this._source.getContext(ILaya.Render.isConchApp ? 'layagl' : '2d');
  12111. }
  12112. this._ctx._canvas = this;
  12113. return this._ctx;
  12114. }
  12115. _setContext(context) {
  12116. this._ctx = context;
  12117. }
  12118. getContext(contextID, other = null) {
  12119. return this.context;
  12120. }
  12121. getMemSize() {
  12122. return 0;
  12123. }
  12124. size(w, h) {
  12125. if (this._width != w || this._height != h || (this._source && (this._source.width != w || this._source.height != h))) {
  12126. this._width = w;
  12127. this._height = h;
  12128. this._setCPUMemory(w * h * 4);
  12129. this._ctx && this._ctx.size && this._ctx.size(w, h);
  12130. if (this._source) {
  12131. this._source.height = h;
  12132. this._source.width = w;
  12133. }
  12134. if (this._texture) {
  12135. this._texture.destroy();
  12136. this._texture = null;
  12137. }
  12138. }
  12139. }
  12140. getTexture() {
  12141. if (!this._texture) {
  12142. var bitmap = new Texture2D();
  12143. bitmap.loadImageSource(this.source);
  12144. this._texture = new Texture(bitmap);
  12145. }
  12146. return this._texture;
  12147. }
  12148. toBase64(type, encoderOptions) {
  12149. if (this._source) {
  12150. if (ILaya.Render.isConchApp) {
  12151. var win = window;
  12152. if (win.conchConfig.threadMode == 2) {
  12153. throw "native 2 thread mode use toBase64Async";
  12154. }
  12155. var width = this._ctx._targets.sourceWidth;
  12156. var height = this._ctx._targets.sourceHeight;
  12157. var data = this._ctx._targets.getData(0, 0, width, height);
  12158. return win.conchToBase64FlipY ? win.conchToBase64FlipY(type, encoderOptions, data.buffer, width, height) : win.conchToBase64(type, encoderOptions, data.buffer, width, height);
  12159. }
  12160. else {
  12161. return this._source.toDataURL(type, encoderOptions);
  12162. }
  12163. }
  12164. return null;
  12165. }
  12166. toBase64Async(type, encoderOptions, callBack) {
  12167. var width = this._ctx._targets.sourceWidth;
  12168. var height = this._ctx._targets.sourceHeight;
  12169. this._ctx._targets.getDataAsync(0, 0, width, height, function (data) {
  12170. let win = window;
  12171. var base64 = win.conchToBase64FlipY ? win.conchToBase64FlipY(type, encoderOptions, data.buffer, width, height) : win.conchToBase64(type, encoderOptions, data.buffer, width, height);
  12172. callBack(base64);
  12173. });
  12174. }
  12175. }
  12176. class HitArea {
  12177. contains(x, y) {
  12178. if (!HitArea._isHitGraphic(x, y, this.hit))
  12179. return false;
  12180. return !HitArea._isHitGraphic(x, y, this.unHit);
  12181. }
  12182. static _isHitGraphic(x, y, graphic) {
  12183. if (!graphic)
  12184. return false;
  12185. var cmds = graphic.cmds;
  12186. if (!cmds && graphic._one) {
  12187. cmds = HitArea._cmds;
  12188. cmds.length = 1;
  12189. cmds[0] = graphic._one;
  12190. }
  12191. if (!cmds)
  12192. return false;
  12193. var i, len;
  12194. len = cmds.length;
  12195. var cmd;
  12196. for (i = 0; i < len; i++) {
  12197. cmd = cmds[i];
  12198. if (!cmd)
  12199. continue;
  12200. switch (cmd.cmdID) {
  12201. case "Translate":
  12202. x -= cmd.tx;
  12203. y -= cmd.ty;
  12204. }
  12205. if (HitArea._isHitCmd(x, y, cmd))
  12206. return true;
  12207. }
  12208. return false;
  12209. }
  12210. static _isHitCmd(x, y, cmd) {
  12211. if (!cmd)
  12212. return false;
  12213. var rst = false;
  12214. switch (cmd.cmdID) {
  12215. case "DrawRect":
  12216. HitArea._rect.setTo(cmd.x, cmd.y, cmd.width, cmd.height);
  12217. rst = HitArea._rect.contains(x, y);
  12218. break;
  12219. case "DrawCircle":
  12220. var d;
  12221. x -= cmd.x;
  12222. y -= cmd.y;
  12223. d = x * x + y * y;
  12224. rst = d < cmd.radius * cmd.radius;
  12225. break;
  12226. case "DrawPoly":
  12227. x -= cmd.x;
  12228. y -= cmd.y;
  12229. rst = HitArea._ptInPolygon(x, y, cmd.points);
  12230. break;
  12231. }
  12232. return rst;
  12233. }
  12234. static _ptInPolygon(x, y, areaPoints) {
  12235. var p = HitArea._ptPoint;
  12236. p.setTo(x, y);
  12237. var nCross = 0;
  12238. var p1x, p1y, p2x, p2y;
  12239. var len;
  12240. len = areaPoints.length;
  12241. for (var i = 0; i < len; i += 2) {
  12242. p1x = areaPoints[i];
  12243. p1y = areaPoints[i + 1];
  12244. p2x = areaPoints[(i + 2) % len];
  12245. p2y = areaPoints[(i + 3) % len];
  12246. if (p1y == p2y)
  12247. continue;
  12248. if (p.y < Math.min(p1y, p2y))
  12249. continue;
  12250. if (p.y >= Math.max(p1y, p2y))
  12251. continue;
  12252. var tx = (p.y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x;
  12253. if (tx > p.x)
  12254. nCross++;
  12255. }
  12256. return (nCross % 2 == 1);
  12257. }
  12258. get hit() {
  12259. if (!this._hit)
  12260. this._hit = new ILaya.Graphics();
  12261. return this._hit;
  12262. }
  12263. set hit(value) {
  12264. this._hit = value;
  12265. }
  12266. get unHit() {
  12267. if (!this._unHit)
  12268. this._unHit = new ILaya.Graphics();
  12269. return this._unHit;
  12270. }
  12271. set unHit(value) {
  12272. this._unHit = value;
  12273. }
  12274. }
  12275. HitArea._cmds = [];
  12276. HitArea._rect = new Rectangle();
  12277. HitArea._ptPoint = new Point();
  12278. class ClassUtils {
  12279. static regClass(className, classDef) {
  12280. ClassUtils._classMap[className] = classDef;
  12281. }
  12282. static regShortClassName(classes) {
  12283. for (var i = 0; i < classes.length; i++) {
  12284. var classDef = classes[i];
  12285. var className = classDef.name;
  12286. ClassUtils._classMap[className] = classDef;
  12287. }
  12288. }
  12289. static getRegClass(className) {
  12290. return ClassUtils._classMap[className];
  12291. }
  12292. static getClass(className) {
  12293. var classObject = ClassUtils._classMap[className] || ClassUtils._classMap['Laya.' + className] || className;
  12294. var glaya = ILaya.Laya;
  12295. if (typeof (classObject) == 'string')
  12296. return (ILaya.__classMap[classObject] || glaya[className]);
  12297. return classObject;
  12298. }
  12299. static getInstance(className) {
  12300. var compClass = ClassUtils.getClass(className);
  12301. if (compClass)
  12302. return new compClass();
  12303. else
  12304. console.warn("[error] Undefined class:", className);
  12305. return null;
  12306. }
  12307. static createByJson(json, node = null, root = null, customHandler = null, instanceHandler = null) {
  12308. if (typeof (json) == 'string')
  12309. json = JSON.parse(json);
  12310. var props = json.props;
  12311. if (!node) {
  12312. node = instanceHandler ? instanceHandler.runWith(json) : ClassUtils.getInstance(props.runtime || json.type);
  12313. if (!node)
  12314. return null;
  12315. }
  12316. var child = json.child;
  12317. if (child) {
  12318. for (var i = 0, n = child.length; i < n; i++) {
  12319. var data = child[i];
  12320. if ((data.props.name === "render" || data.props.renderType === "render") && node["_$set_itemRender"])
  12321. node.itemRender = data;
  12322. else {
  12323. if (data.type == "Graphic") {
  12324. ClassUtils._addGraphicsToSprite(data, node);
  12325. }
  12326. else if (ClassUtils._isDrawType(data.type)) {
  12327. ClassUtils._addGraphicToSprite(data, node, true);
  12328. }
  12329. else {
  12330. var tChild = ClassUtils.createByJson(data, null, root, customHandler, instanceHandler);
  12331. if (data.type === "Script") {
  12332. if ("owner" in tChild) {
  12333. tChild["owner"] = node;
  12334. }
  12335. else if ("target" in tChild) {
  12336. tChild["target"] = node;
  12337. }
  12338. }
  12339. else if (data.props.renderType == "mask") {
  12340. node.mask = tChild;
  12341. }
  12342. else {
  12343. node.addChild(tChild);
  12344. }
  12345. }
  12346. }
  12347. }
  12348. }
  12349. if (props) {
  12350. for (var prop in props) {
  12351. var value = props[prop];
  12352. if (prop === "var" && root) {
  12353. root[value] = node;
  12354. }
  12355. else if (value instanceof Array && node[prop] instanceof Function) {
  12356. node[prop].apply(node, value);
  12357. }
  12358. else {
  12359. node[prop] = value;
  12360. }
  12361. }
  12362. }
  12363. if (customHandler && json.customProps) {
  12364. customHandler.runWith([node, json]);
  12365. }
  12366. if (node["created"])
  12367. node.created();
  12368. return node;
  12369. }
  12370. static _addGraphicsToSprite(graphicO, sprite) {
  12371. var graphics = graphicO.child;
  12372. if (!graphics || graphics.length < 1)
  12373. return;
  12374. var g = ClassUtils._getGraphicsFromSprite(graphicO, sprite);
  12375. var ox = 0;
  12376. var oy = 0;
  12377. if (graphicO.props) {
  12378. ox = ClassUtils._getObjVar(graphicO.props, "x", 0);
  12379. oy = ClassUtils._getObjVar(graphicO.props, "y", 0);
  12380. }
  12381. if (ox != 0 && oy != 0) {
  12382. g.translate(ox, oy);
  12383. }
  12384. var i, len;
  12385. len = graphics.length;
  12386. for (i = 0; i < len; i++) {
  12387. ClassUtils._addGraphicToGraphics(graphics[i], g);
  12388. }
  12389. if (ox != 0 && oy != 0) {
  12390. g.translate(-ox, -oy);
  12391. }
  12392. }
  12393. static _addGraphicToSprite(graphicO, sprite, isChild = false) {
  12394. var g = isChild ? ClassUtils._getGraphicsFromSprite(graphicO, sprite) : sprite.graphics;
  12395. ClassUtils._addGraphicToGraphics(graphicO, g);
  12396. }
  12397. static _getGraphicsFromSprite(dataO, sprite) {
  12398. if (!dataO || !dataO.props)
  12399. return sprite.graphics;
  12400. var propsName = dataO.props.renderType;
  12401. if (propsName === "hit" || propsName === "unHit") {
  12402. var hitArea = sprite._style.hitArea || (sprite.hitArea = new HitArea());
  12403. if (!hitArea[propsName]) {
  12404. hitArea[propsName] = new Graphics();
  12405. }
  12406. var g = hitArea[propsName];
  12407. }
  12408. if (!g)
  12409. g = sprite.graphics;
  12410. return g;
  12411. }
  12412. static _getTransformData(propsO) {
  12413. var m;
  12414. if ("pivotX" in propsO || "pivotY" in propsO) {
  12415. m = m || new Matrix();
  12416. m.translate(-ClassUtils._getObjVar(propsO, "pivotX", 0), -ClassUtils._getObjVar(propsO, "pivotY", 0));
  12417. }
  12418. var sx = ClassUtils._getObjVar(propsO, "scaleX", 1), sy = ClassUtils._getObjVar(propsO, "scaleY", 1);
  12419. var rotate = ClassUtils._getObjVar(propsO, "rotation", 0);
  12420. var skewX = ClassUtils._getObjVar(propsO, "skewX", 0);
  12421. var skewY = ClassUtils._getObjVar(propsO, "skewY", 0);
  12422. if (sx != 1 || sy != 1 || rotate != 0) {
  12423. m = m || new Matrix();
  12424. m.scale(sx, sy);
  12425. m.rotate(rotate * 0.0174532922222222);
  12426. }
  12427. return m;
  12428. }
  12429. static _addGraphicToGraphics(graphicO, graphic) {
  12430. var propsO;
  12431. propsO = graphicO.props;
  12432. if (!propsO)
  12433. return;
  12434. var drawConfig;
  12435. drawConfig = ClassUtils.DrawTypeDic[graphicO.type];
  12436. if (!drawConfig)
  12437. return;
  12438. var g = graphic;
  12439. var params = ClassUtils._getParams(propsO, drawConfig[1], drawConfig[2], drawConfig[3]);
  12440. var m = ClassUtils._tM;
  12441. if (m || ClassUtils._alpha != 1) {
  12442. g.save();
  12443. if (m)
  12444. g.transform(m);
  12445. if (ClassUtils._alpha != 1)
  12446. g.alpha(ClassUtils._alpha);
  12447. }
  12448. g[drawConfig[0]].apply(g, params);
  12449. if (m || ClassUtils._alpha != 1) {
  12450. g.restore();
  12451. }
  12452. }
  12453. static _adptLineData(params) {
  12454. params[2] = parseFloat(params[0]) + parseFloat(params[2]);
  12455. params[3] = parseFloat(params[1]) + parseFloat(params[3]);
  12456. return params;
  12457. }
  12458. static _adptTextureData(params) {
  12459. params[0] = ILaya.Loader.getRes(params[0]);
  12460. return params;
  12461. }
  12462. static _adptLinesData(params) {
  12463. params[2] = ClassUtils._getPointListByStr(params[2]);
  12464. return params;
  12465. }
  12466. static _isDrawType(type) {
  12467. if (type === "Image")
  12468. return false;
  12469. return type in ClassUtils.DrawTypeDic;
  12470. }
  12471. static _getParams(obj, params, xPos = 0, adptFun = null) {
  12472. var rst = ClassUtils._temParam;
  12473. rst.length = params.length;
  12474. var i, len;
  12475. len = params.length;
  12476. for (i = 0; i < len; i++) {
  12477. rst[i] = ClassUtils._getObjVar(obj, params[i][0], params[i][1]);
  12478. }
  12479. ClassUtils._alpha = ClassUtils._getObjVar(obj, "alpha", 1);
  12480. var m;
  12481. m = ClassUtils._getTransformData(obj);
  12482. if (m) {
  12483. if (!xPos)
  12484. xPos = 0;
  12485. m.translate(rst[xPos], rst[xPos + 1]);
  12486. rst[xPos] = rst[xPos + 1] = 0;
  12487. ClassUtils._tM = m;
  12488. }
  12489. else {
  12490. ClassUtils._tM = null;
  12491. }
  12492. if (adptFun && ClassUtils[adptFun]) {
  12493. rst = ClassUtils[adptFun](rst);
  12494. }
  12495. return rst;
  12496. }
  12497. static _getPointListByStr(str) {
  12498. var pointArr = str.split(",");
  12499. var i, len;
  12500. len = pointArr.length;
  12501. for (i = 0; i < len; i++) {
  12502. pointArr[i] = parseFloat(pointArr[i]);
  12503. }
  12504. return pointArr;
  12505. }
  12506. static _getObjVar(obj, key, noValue) {
  12507. if (key in obj) {
  12508. return obj[key];
  12509. }
  12510. return noValue;
  12511. }
  12512. }
  12513. ClassUtils.DrawTypeDic = { "Rect": ["drawRect", [["x", 0], ["y", 0], ["width", 0], ["height", 0], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]]], "Circle": ["drawCircle", [["x", 0], ["y", 0], ["radius", 0], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]]], "Pie": ["drawPie", [["x", 0], ["y", 0], ["radius", 0], ["startAngle", 0], ["endAngle", 0], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]]], "Image": ["drawTexture", [["x", 0], ["y", 0], ["width", 0], ["height", 0]]], "Texture": ["drawTexture", [["skin", null], ["x", 0], ["y", 0], ["width", 0], ["height", 0]], 1, "_adptTextureData"], "FillTexture": ["fillTexture", [["skin", null], ["x", 0], ["y", 0], ["width", 0], ["height", 0], ["repeat", null]], 1, "_adptTextureData"], "FillText": ["fillText", [["text", ""], ["x", 0], ["y", 0], ["font", null], ["color", null], ["textAlign", null]], 1], "Line": ["drawLine", [["x", 0], ["y", 0], ["toX", 0], ["toY", 0], ["lineColor", null], ["lineWidth", 0]], 0, "_adptLineData"], "Lines": ["drawLines", [["x", 0], ["y", 0], ["points", ""], ["lineColor", null], ["lineWidth", 0]], 0, "_adptLinesData"], "Curves": ["drawCurves", [["x", 0], ["y", 0], ["points", ""], ["lineColor", null], ["lineWidth", 0]], 0, "_adptLinesData"], "Poly": ["drawPoly", [["x", 0], ["y", 0], ["points", ""], ["fillColor", null], ["lineColor", null], ["lineWidth", 1]], 0, "_adptLinesData"] };
  12514. ClassUtils._temParam = [];
  12515. ClassUtils._classMap = {};
  12516. class BoundsStyle {
  12517. reset() {
  12518. if (this.bounds)
  12519. this.bounds.recover();
  12520. if (this.userBounds)
  12521. this.userBounds.recover();
  12522. this.bounds = null;
  12523. this.userBounds = null;
  12524. this.temBM = null;
  12525. return this;
  12526. }
  12527. recover() {
  12528. Pool.recover("BoundsStyle", this.reset());
  12529. }
  12530. static create() {
  12531. return Pool.getItemByClass("BoundsStyle", BoundsStyle);
  12532. }
  12533. }
  12534. class CacheStyle {
  12535. constructor() {
  12536. this.reset();
  12537. }
  12538. needBitmapCache() {
  12539. return this.cacheForFilters || !!this.mask;
  12540. }
  12541. needEnableCanvasRender() {
  12542. return this.userSetCache != "none" || this.cacheForFilters || !!this.mask;
  12543. }
  12544. releaseContext() {
  12545. if (this.canvas && this.canvas.size) {
  12546. Pool.recover("CacheCanvas", this.canvas);
  12547. this.canvas.size(0, 0);
  12548. try {
  12549. this.canvas.width = 0;
  12550. this.canvas.height = 0;
  12551. }
  12552. catch (e) {
  12553. }
  12554. }
  12555. this.canvas = null;
  12556. }
  12557. createContext() {
  12558. if (!this.canvas) {
  12559. this.canvas = Pool.getItem("CacheCanvas") || new HTMLCanvas(false);
  12560. var tx = this.canvas.context;
  12561. if (!tx) {
  12562. tx = this.canvas.getContext('2d');
  12563. }
  12564. }
  12565. }
  12566. releaseFilterCache() {
  12567. var fc = this.filterCache;
  12568. if (fc) {
  12569. fc.destroy();
  12570. fc.recycle();
  12571. this.filterCache = null;
  12572. }
  12573. }
  12574. recover() {
  12575. if (this === CacheStyle.EMPTY)
  12576. return;
  12577. Pool.recover("SpriteCache", this.reset());
  12578. }
  12579. reset() {
  12580. this.releaseContext();
  12581. this.releaseFilterCache();
  12582. this.cacheAs = "none";
  12583. this.enableCanvasRender = false;
  12584. this.userSetCache = "none";
  12585. this.cacheForFilters = false;
  12586. this.staticCache = false;
  12587. this.reCache = true;
  12588. this.mask = null;
  12589. this.maskParent = null;
  12590. this.filterCache = null;
  12591. this.filters = null;
  12592. this.hasGlowFilter = false;
  12593. if (this.cacheRect)
  12594. this.cacheRect.recover();
  12595. this.cacheRect = null;
  12596. return this;
  12597. }
  12598. static create() {
  12599. return Pool.getItemByClass("SpriteCache", CacheStyle);
  12600. }
  12601. _calculateCacheRect(sprite, tCacheType, x, y) {
  12602. var _cacheStyle = sprite._cacheStyle;
  12603. if (!_cacheStyle.cacheRect)
  12604. _cacheStyle.cacheRect = Rectangle.create();
  12605. var tRec;
  12606. if (tCacheType === "bitmap") {
  12607. tRec = sprite.getSelfBounds();
  12608. tRec.width = tRec.width + CacheStyle.CANVAS_EXTEND_EDGE * 2;
  12609. tRec.height = tRec.height + CacheStyle.CANVAS_EXTEND_EDGE * 2;
  12610. tRec.x = tRec.x - sprite.pivotX;
  12611. tRec.y = tRec.y - sprite.pivotY;
  12612. tRec.x = tRec.x - CacheStyle.CANVAS_EXTEND_EDGE;
  12613. tRec.y = tRec.y - CacheStyle.CANVAS_EXTEND_EDGE;
  12614. tRec.x = Math.floor(tRec.x + x) - x;
  12615. tRec.y = Math.floor(tRec.y + y) - y;
  12616. tRec.width = Math.floor(tRec.width);
  12617. tRec.height = Math.floor(tRec.height);
  12618. _cacheStyle.cacheRect.copyFrom(tRec);
  12619. }
  12620. else {
  12621. _cacheStyle.cacheRect.setTo(-sprite._style.pivotX, -sprite._style.pivotY, 1, 1);
  12622. }
  12623. tRec = _cacheStyle.cacheRect;
  12624. if (sprite._style.scrollRect) {
  12625. var scrollRect = sprite._style.scrollRect;
  12626. tRec.x -= scrollRect.x;
  12627. tRec.y -= scrollRect.y;
  12628. }
  12629. CacheStyle._scaleInfo.setTo(1, 1);
  12630. return CacheStyle._scaleInfo;
  12631. }
  12632. }
  12633. CacheStyle.EMPTY = new CacheStyle();
  12634. CacheStyle._scaleInfo = new Point();
  12635. CacheStyle.CANVAS_EXTEND_EDGE = 16;
  12636. class SpriteStyle {
  12637. constructor() {
  12638. this.reset();
  12639. }
  12640. reset() {
  12641. this.scaleX = this.scaleY = 1;
  12642. this.skewX = this.skewY = 0;
  12643. this.pivotX = this.pivotY = this.rotation = 0;
  12644. this.alpha = 1;
  12645. if (this.scrollRect)
  12646. this.scrollRect.recover();
  12647. this.scrollRect = null;
  12648. if (this.viewport)
  12649. this.viewport.recover();
  12650. this.viewport = null;
  12651. this.hitArea = null;
  12652. this.dragging = null;
  12653. this.blendMode = null;
  12654. return this;
  12655. }
  12656. recover() {
  12657. if (this === SpriteStyle.EMPTY)
  12658. return;
  12659. Pool.recover("SpriteStyle", this.reset());
  12660. }
  12661. static create() {
  12662. return Pool.getItemByClass("SpriteStyle", SpriteStyle);
  12663. }
  12664. }
  12665. SpriteStyle.EMPTY = new SpriteStyle();
  12666. class Node extends EventDispatcher {
  12667. constructor() {
  12668. super();
  12669. this._bits = 0;
  12670. this._children = Node.ARRAY_EMPTY;
  12671. this._extUIChild = Node.ARRAY_EMPTY;
  12672. this._parent = null;
  12673. this.name = "";
  12674. this.destroyed = false;
  12675. this.createGLBuffer();
  12676. }
  12677. createGLBuffer() {
  12678. }
  12679. _setBit(type, value) {
  12680. if (type === Const.DISPLAY) {
  12681. var preValue = this._getBit(type);
  12682. if (preValue != value)
  12683. this._updateDisplayedInstage();
  12684. }
  12685. if (value)
  12686. this._bits |= type;
  12687. else
  12688. this._bits &= ~type;
  12689. }
  12690. _getBit(type) {
  12691. return (this._bits & type) != 0;
  12692. }
  12693. _setUpNoticeChain() {
  12694. if (this._getBit(Const.DISPLAY))
  12695. this._setBitUp(Const.DISPLAY);
  12696. }
  12697. _setBitUp(type) {
  12698. var ele = this;
  12699. ele._setBit(type, true);
  12700. ele = ele._parent;
  12701. while (ele) {
  12702. if (ele._getBit(type))
  12703. return;
  12704. ele._setBit(type, true);
  12705. ele = ele._parent;
  12706. }
  12707. }
  12708. on(type, caller, listener, args = null) {
  12709. if (type === Event.DISPLAY || type === Event.UNDISPLAY) {
  12710. if (!this._getBit(Const.DISPLAY))
  12711. this._setBitUp(Const.DISPLAY);
  12712. }
  12713. return this._createListener(type, caller, listener, args, false);
  12714. }
  12715. once(type, caller, listener, args = null) {
  12716. if (type === Event.DISPLAY || type === Event.UNDISPLAY) {
  12717. if (!this._getBit(Const.DISPLAY))
  12718. this._setBitUp(Const.DISPLAY);
  12719. }
  12720. return this._createListener(type, caller, listener, args, true);
  12721. }
  12722. destroy(destroyChild = true) {
  12723. this.destroyed = true;
  12724. this._destroyAllComponent();
  12725. this._parent && this._parent.removeChild(this);
  12726. if (this._children) {
  12727. if (destroyChild)
  12728. this.destroyChildren();
  12729. else
  12730. this.removeChildren();
  12731. }
  12732. this.onDestroy();
  12733. this._children = null;
  12734. this.offAll();
  12735. }
  12736. onDestroy() {
  12737. }
  12738. destroyChildren() {
  12739. if (this._children) {
  12740. for (var i = 0, n = this._children.length; i < n; i++) {
  12741. this._children[0].destroy(true);
  12742. }
  12743. }
  12744. }
  12745. addChild(node) {
  12746. if (!node || this.destroyed || node === this)
  12747. return node;
  12748. if (node._zOrder)
  12749. this._setBit(Const.HAS_ZORDER, true);
  12750. if (node._parent === this) {
  12751. var index = this.getChildIndex(node);
  12752. if (index !== this._children.length - 1) {
  12753. this._children.splice(index, 1);
  12754. this._children.push(node);
  12755. this._childChanged();
  12756. }
  12757. }
  12758. else {
  12759. node._parent && node._parent.removeChild(node);
  12760. this._children === Node.ARRAY_EMPTY && (this._children = []);
  12761. this._children.push(node);
  12762. node._setParent(this);
  12763. this._childChanged();
  12764. }
  12765. return node;
  12766. }
  12767. addInputChild(node) {
  12768. if (this._extUIChild == Node.ARRAY_EMPTY) {
  12769. this._extUIChild = [node];
  12770. }
  12771. else {
  12772. if (this._extUIChild.indexOf(node) >= 0) {
  12773. return null;
  12774. }
  12775. this._extUIChild.push(node);
  12776. }
  12777. return null;
  12778. }
  12779. removeInputChild(node) {
  12780. var idx = this._extUIChild.indexOf(node);
  12781. if (idx >= 0) {
  12782. this._extUIChild.splice(idx, 1);
  12783. }
  12784. }
  12785. addChildren(...args) {
  12786. var i = 0, n = args.length;
  12787. while (i < n) {
  12788. this.addChild(args[i++]);
  12789. }
  12790. }
  12791. addChildAt(node, index) {
  12792. if (!node || this.destroyed || node === this)
  12793. return node;
  12794. if (node._zOrder)
  12795. this._setBit(Const.HAS_ZORDER, true);
  12796. if (index >= 0 && index <= this._children.length) {
  12797. if (node._parent === this) {
  12798. var oldIndex = this.getChildIndex(node);
  12799. this._children.splice(oldIndex, 1);
  12800. this._children.splice(index, 0, node);
  12801. this._childChanged();
  12802. }
  12803. else {
  12804. node._parent && node._parent.removeChild(node);
  12805. this._children === Node.ARRAY_EMPTY && (this._children = []);
  12806. this._children.splice(index, 0, node);
  12807. node._setParent(this);
  12808. }
  12809. return node;
  12810. }
  12811. else {
  12812. throw new Error("appendChildAt:The index is out of bounds");
  12813. }
  12814. }
  12815. getChildIndex(node) {
  12816. return this._children.indexOf(node);
  12817. }
  12818. getChildByName(name) {
  12819. var nodes = this._children;
  12820. if (nodes) {
  12821. for (var i = 0, n = nodes.length; i < n; i++) {
  12822. var node = nodes[i];
  12823. if (node.name === name)
  12824. return node;
  12825. }
  12826. }
  12827. return null;
  12828. }
  12829. getChildAt(index) {
  12830. return this._children[index] || null;
  12831. }
  12832. setChildIndex(node, index) {
  12833. var childs = this._children;
  12834. if (index < 0 || index >= childs.length) {
  12835. throw new Error("setChildIndex:The index is out of bounds.");
  12836. }
  12837. var oldIndex = this.getChildIndex(node);
  12838. if (oldIndex < 0)
  12839. throw new Error("setChildIndex:node is must child of this object.");
  12840. childs.splice(oldIndex, 1);
  12841. childs.splice(index, 0, node);
  12842. this._childChanged();
  12843. return node;
  12844. }
  12845. _childChanged(child = null) {
  12846. }
  12847. removeChild(node) {
  12848. if (!this._children)
  12849. return node;
  12850. var index = this._children.indexOf(node);
  12851. return this.removeChildAt(index);
  12852. }
  12853. removeSelf() {
  12854. this._parent && this._parent.removeChild(this);
  12855. return this;
  12856. }
  12857. removeChildByName(name) {
  12858. var node = this.getChildByName(name);
  12859. node && this.removeChild(node);
  12860. return node;
  12861. }
  12862. removeChildAt(index) {
  12863. var node = this.getChildAt(index);
  12864. if (node) {
  12865. this._children.splice(index, 1);
  12866. node._setParent(null);
  12867. }
  12868. return node;
  12869. }
  12870. removeChildren(beginIndex = 0, endIndex = 0x7fffffff) {
  12871. if (this._children && this._children.length > 0) {
  12872. var childs = this._children;
  12873. if (beginIndex === 0 && endIndex >= childs.length - 1) {
  12874. var arr = childs;
  12875. this._children = Node.ARRAY_EMPTY;
  12876. }
  12877. else {
  12878. arr = childs.splice(beginIndex, endIndex - beginIndex);
  12879. }
  12880. for (var i = 0, n = arr.length; i < n; i++) {
  12881. arr[i]._setParent(null);
  12882. }
  12883. }
  12884. return this;
  12885. }
  12886. replaceChild(newNode, oldNode) {
  12887. var index = this._children.indexOf(oldNode);
  12888. if (index > -1) {
  12889. this._children.splice(index, 1, newNode);
  12890. oldNode._setParent(null);
  12891. newNode._setParent(this);
  12892. return newNode;
  12893. }
  12894. return null;
  12895. }
  12896. get numChildren() {
  12897. return this._children.length;
  12898. }
  12899. get parent() {
  12900. return this._parent;
  12901. }
  12902. _setParent(value) {
  12903. if (this._parent !== value) {
  12904. if (value) {
  12905. this._parent = value;
  12906. this._onAdded();
  12907. this.event(Event.ADDED);
  12908. if (this._getBit(Const.DISPLAY)) {
  12909. this._setUpNoticeChain();
  12910. value.displayedInStage && this._displayChild(this, true);
  12911. }
  12912. value._childChanged(this);
  12913. }
  12914. else {
  12915. this._onRemoved();
  12916. this.event(Event.REMOVED);
  12917. this._parent._childChanged();
  12918. if (this._getBit(Const.DISPLAY))
  12919. this._displayChild(this, false);
  12920. this._parent = value;
  12921. }
  12922. }
  12923. }
  12924. get displayedInStage() {
  12925. if (this._getBit(Const.DISPLAY))
  12926. return this._getBit(Const.DISPLAYED_INSTAGE);
  12927. this._setBitUp(Const.DISPLAY);
  12928. return this._getBit(Const.DISPLAYED_INSTAGE);
  12929. }
  12930. _updateDisplayedInstage() {
  12931. var ele;
  12932. ele = this;
  12933. var stage = ILaya.stage;
  12934. var displayedInStage = false;
  12935. while (ele) {
  12936. if (ele._getBit(Const.DISPLAY)) {
  12937. displayedInStage = ele._getBit(Const.DISPLAYED_INSTAGE);
  12938. break;
  12939. }
  12940. if (ele === stage || ele._getBit(Const.DISPLAYED_INSTAGE)) {
  12941. displayedInStage = true;
  12942. break;
  12943. }
  12944. ele = ele._parent;
  12945. }
  12946. this._setBit(Const.DISPLAYED_INSTAGE, displayedInStage);
  12947. }
  12948. _setDisplay(value) {
  12949. if (this._getBit(Const.DISPLAYED_INSTAGE) !== value) {
  12950. this._setBit(Const.DISPLAYED_INSTAGE, value);
  12951. if (value)
  12952. this.event(Event.DISPLAY);
  12953. else
  12954. this.event(Event.UNDISPLAY);
  12955. }
  12956. }
  12957. _displayChild(node, display) {
  12958. var childs = node._children;
  12959. if (childs) {
  12960. for (var i = 0, n = childs.length; i < n; i++) {
  12961. var child = childs[i];
  12962. if (!child._getBit(Const.DISPLAY))
  12963. continue;
  12964. if (child._children.length > 0) {
  12965. this._displayChild(child, display);
  12966. }
  12967. else {
  12968. child._setDisplay(display);
  12969. }
  12970. }
  12971. }
  12972. node._setDisplay(display);
  12973. }
  12974. contains(node) {
  12975. if (node === this)
  12976. return true;
  12977. while (node) {
  12978. if (node._parent === this)
  12979. return true;
  12980. node = node._parent;
  12981. }
  12982. return false;
  12983. }
  12984. timerLoop(delay, caller, method, args = null, coverBefore = true, jumpFrame = false) {
  12985. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12986. timer.loop(delay, caller, method, args, coverBefore, jumpFrame);
  12987. }
  12988. timerOnce(delay, caller, method, args = null, coverBefore = true) {
  12989. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12990. timer._create(false, false, delay, caller, method, args, coverBefore);
  12991. }
  12992. frameLoop(delay, caller, method, args = null, coverBefore = true) {
  12993. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12994. timer._create(true, true, delay, caller, method, args, coverBefore);
  12995. }
  12996. frameOnce(delay, caller, method, args = null, coverBefore = true) {
  12997. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12998. timer._create(true, false, delay, caller, method, args, coverBefore);
  12999. }
  13000. clearTimer(caller, method) {
  13001. var timer = this.scene ? this.scene.timer : ILaya.timer;
  13002. timer.clear(caller, method);
  13003. }
  13004. callLater(method, args = null) {
  13005. var timer = this.scene ? this.scene.timer : ILaya.timer;
  13006. timer.callLater(this, method, args);
  13007. }
  13008. runCallLater(method) {
  13009. var timer = this.scene ? this.scene.timer : ILaya.timer;
  13010. timer.runCallLater(this, method);
  13011. }
  13012. get scene() {
  13013. return this._scene;
  13014. }
  13015. get active() {
  13016. return !this._getBit(Const.NOT_READY) && !this._getBit(Const.NOT_ACTIVE);
  13017. }
  13018. set active(value) {
  13019. value = !!value;
  13020. if (!this._getBit(Const.NOT_ACTIVE) !== value) {
  13021. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  13022. if (value)
  13023. throw "Node: can't set the main inActive node active in hierarchy,if the operate is in main inActive node or it's children script's onDisable Event.";
  13024. else
  13025. throw "Node: can't set the main active node inActive in hierarchy,if the operate is in main active node or it's children script's onEnable Event.";
  13026. }
  13027. else {
  13028. this._setBit(Const.NOT_ACTIVE, !value);
  13029. if (this._parent) {
  13030. if (this._parent.activeInHierarchy) {
  13031. if (value)
  13032. this._processActive();
  13033. else
  13034. this._processInActive();
  13035. }
  13036. }
  13037. }
  13038. }
  13039. }
  13040. get activeInHierarchy() {
  13041. return this._getBit(Const.ACTIVE_INHIERARCHY);
  13042. }
  13043. _onActive() {
  13044. Stat.spriteCount++;
  13045. }
  13046. _onInActive() {
  13047. Stat.spriteCount--;
  13048. }
  13049. _onActiveInScene() {
  13050. }
  13051. _onInActiveInScene() {
  13052. }
  13053. _parse(data, spriteMap) {
  13054. }
  13055. _setBelongScene(scene) {
  13056. if (!this._scene) {
  13057. this._scene = scene;
  13058. this._onActiveInScene();
  13059. for (var i = 0, n = this._children.length; i < n; i++)
  13060. this._children[i]._setBelongScene(scene);
  13061. }
  13062. }
  13063. _setUnBelongScene() {
  13064. if (this._scene !== this) {
  13065. this._onInActiveInScene();
  13066. this._scene = null;
  13067. for (var i = 0, n = this._children.length; i < n; i++)
  13068. this._children[i]._setUnBelongScene();
  13069. }
  13070. }
  13071. onAwake() {
  13072. }
  13073. onEnable() {
  13074. }
  13075. _processActive() {
  13076. (this._activeChangeScripts) || (this._activeChangeScripts = []);
  13077. this._activeHierarchy(this._activeChangeScripts);
  13078. this._activeScripts();
  13079. }
  13080. _activeHierarchy(activeChangeScripts) {
  13081. this._setBit(Const.ACTIVE_INHIERARCHY, true);
  13082. if (this._components) {
  13083. for (var i = 0, n = this._components.length; i < n; i++) {
  13084. var comp = this._components[i];
  13085. if (comp._isScript())
  13086. (comp._enabled) && (activeChangeScripts.push(comp));
  13087. else
  13088. comp._setActive(true);
  13089. }
  13090. }
  13091. this._onActive();
  13092. for (i = 0, n = this._children.length; i < n; i++) {
  13093. var child = this._children[i];
  13094. (!child._getBit(Const.NOT_ACTIVE) && !child._getBit(Const.NOT_READY)) && (child._activeHierarchy(activeChangeScripts));
  13095. }
  13096. if (!this._getBit(Const.AWAKED)) {
  13097. this._setBit(Const.AWAKED, true);
  13098. this.onAwake();
  13099. }
  13100. this.onEnable();
  13101. }
  13102. _activeScripts() {
  13103. for (var i = 0, n = this._activeChangeScripts.length; i < n; i++) {
  13104. var comp = this._activeChangeScripts[i];
  13105. if (!comp._awaked) {
  13106. comp._awaked = true;
  13107. comp._onAwake();
  13108. }
  13109. comp._onEnable();
  13110. }
  13111. this._activeChangeScripts.length = 0;
  13112. }
  13113. _processInActive() {
  13114. (this._activeChangeScripts) || (this._activeChangeScripts = []);
  13115. this._inActiveHierarchy(this._activeChangeScripts);
  13116. this._inActiveScripts();
  13117. }
  13118. _inActiveHierarchy(activeChangeScripts) {
  13119. this._onInActive();
  13120. if (this._components) {
  13121. for (var i = 0, n = this._components.length; i < n; i++) {
  13122. var comp = this._components[i];
  13123. comp._setActive(false);
  13124. (comp._isScript() && comp._enabled) && (activeChangeScripts.push(comp));
  13125. }
  13126. }
  13127. this._setBit(Const.ACTIVE_INHIERARCHY, false);
  13128. for (i = 0, n = this._children.length; i < n; i++) {
  13129. var child = this._children[i];
  13130. (child && !child._getBit(Const.NOT_ACTIVE)) && (child._inActiveHierarchy(activeChangeScripts));
  13131. }
  13132. this.onDisable();
  13133. }
  13134. _inActiveScripts() {
  13135. for (var i = 0, n = this._activeChangeScripts.length; i < n; i++)
  13136. this._activeChangeScripts[i].onDisable();
  13137. this._activeChangeScripts.length = 0;
  13138. }
  13139. onDisable() {
  13140. }
  13141. _onAdded() {
  13142. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  13143. throw "Node: can't set the main inActive node active in hierarchy,if the operate is in main inActive node or it's children script's onDisable Event.";
  13144. }
  13145. else {
  13146. var parentScene = this._parent.scene;
  13147. parentScene && this._setBelongScene(parentScene);
  13148. (this._parent.activeInHierarchy && this.active) && this._processActive();
  13149. }
  13150. }
  13151. _onRemoved() {
  13152. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  13153. throw "Node: can't set the main active node inActive in hierarchy,if the operate is in main active node or it's children script's onEnable Event.";
  13154. }
  13155. else {
  13156. (this._parent.activeInHierarchy && this.active) && this._processInActive();
  13157. this._parent.scene && this._setUnBelongScene();
  13158. }
  13159. }
  13160. _addComponentInstance(comp) {
  13161. this._components = this._components || [];
  13162. this._components.push(comp);
  13163. comp.owner = this;
  13164. comp._onAdded();
  13165. if (this.activeInHierarchy)
  13166. comp._setActive(true);
  13167. }
  13168. _destroyComponent(comp) {
  13169. if (this._components) {
  13170. for (var i = 0, n = this._components.length; i < n; i++) {
  13171. var item = this._components[i];
  13172. if (item === comp) {
  13173. item._destroy();
  13174. this._components.splice(i, 1);
  13175. break;
  13176. }
  13177. }
  13178. }
  13179. }
  13180. _destroyAllComponent() {
  13181. if (this._components) {
  13182. for (var i = 0, n = this._components.length; i < n; i++) {
  13183. var item = this._components[i];
  13184. item && item._destroy();
  13185. }
  13186. this._components.length = 0;
  13187. }
  13188. }
  13189. _cloneTo(destObject, srcRoot, dstRoot) {
  13190. var destNode = destObject;
  13191. if (this._components) {
  13192. for (var i = 0, n = this._components.length; i < n; i++) {
  13193. var destComponent = destNode.addComponent(this._components[i].constructor);
  13194. this._components[i]._cloneTo(destComponent);
  13195. }
  13196. }
  13197. }
  13198. addComponentIntance(component) {
  13199. if (component.owner)
  13200. throw "Node:the component has belong to other node.";
  13201. if (component.isSingleton && this.getComponent(component.constructor))
  13202. throw "Node:the component is singleton,can't add the second one.";
  13203. this._addComponentInstance(component);
  13204. return component;
  13205. }
  13206. addComponent(componentType) {
  13207. var comp = Pool.createByClass(componentType);
  13208. comp._destroyed = false;
  13209. if (comp.isSingleton && this.getComponent(componentType))
  13210. throw "无法实例" + componentType + "组件" + "," + componentType + "组件已存在!";
  13211. this._addComponentInstance(comp);
  13212. return comp;
  13213. }
  13214. getComponent(componentType) {
  13215. if (this._components) {
  13216. for (var i = 0, n = this._components.length; i < n; i++) {
  13217. var comp = this._components[i];
  13218. if (comp instanceof componentType)
  13219. return comp;
  13220. }
  13221. }
  13222. return null;
  13223. }
  13224. getComponents(componentType) {
  13225. var arr;
  13226. if (this._components) {
  13227. for (var i = 0, n = this._components.length; i < n; i++) {
  13228. var comp = this._components[i];
  13229. if (comp instanceof componentType) {
  13230. arr = arr || [];
  13231. arr.push(comp);
  13232. }
  13233. }
  13234. }
  13235. return arr;
  13236. }
  13237. get timer() {
  13238. return this.scene ? this.scene.timer : ILaya.timer;
  13239. }
  13240. }
  13241. Node.ARRAY_EMPTY = [];
  13242. ClassUtils.regClass("laya.display.Node", Node);
  13243. ClassUtils.regClass("Laya.Node", Node);
  13244. class Sprite extends Node {
  13245. constructor() {
  13246. super();
  13247. this._x = 0;
  13248. this._y = 0;
  13249. this._width = 0;
  13250. this._height = 0;
  13251. this._visible = true;
  13252. this._mouseState = 0;
  13253. this._zOrder = 0;
  13254. this._renderType = 0;
  13255. this._transform = null;
  13256. this._tfChanged = false;
  13257. this._repaint = SpriteConst.REPAINT_NONE;
  13258. this._texture = null;
  13259. this._style = SpriteStyle.EMPTY;
  13260. this._cacheStyle = CacheStyle.EMPTY;
  13261. this._boundStyle = null;
  13262. this._graphics = null;
  13263. this.mouseThrough = false;
  13264. this.autoSize = false;
  13265. this.hitTestPrior = false;
  13266. }
  13267. destroy(destroyChild = true) {
  13268. super.destroy(destroyChild);
  13269. this._style && this._style.recover();
  13270. this._cacheStyle && this._cacheStyle.recover();
  13271. this._boundStyle && this._boundStyle.recover();
  13272. this._style = null;
  13273. this._cacheStyle = null;
  13274. this._boundStyle = null;
  13275. this._transform = null;
  13276. if (this._graphics && this._graphics.autoDestroy) {
  13277. this._graphics.destroy();
  13278. }
  13279. this._graphics = null;
  13280. this.texture = null;
  13281. }
  13282. updateZOrder() {
  13283. Utils.updateOrder(this._children) && this.repaint();
  13284. }
  13285. _getBoundsStyle() {
  13286. if (!this._boundStyle)
  13287. this._boundStyle = BoundsStyle.create();
  13288. return this._boundStyle;
  13289. }
  13290. _setCustomRender() {
  13291. }
  13292. set customRenderEnable(b) {
  13293. if (b) {
  13294. this._renderType |= SpriteConst.CUSTOM;
  13295. this._setRenderType(this._renderType);
  13296. this._setCustomRender();
  13297. }
  13298. }
  13299. get cacheAs() {
  13300. return this._cacheStyle.cacheAs;
  13301. }
  13302. _setCacheAs(value) {
  13303. }
  13304. set cacheAs(value) {
  13305. if (value === this._cacheStyle.userSetCache)
  13306. return;
  13307. if (this.mask && value === 'normal')
  13308. return;
  13309. this._setCacheAs(value);
  13310. this._getCacheStyle().userSetCache = value;
  13311. this._checkCanvasEnable();
  13312. this.repaint();
  13313. }
  13314. _checkCanvasEnable() {
  13315. var tEnable = this._cacheStyle.needEnableCanvasRender();
  13316. this._getCacheStyle().enableCanvasRender = tEnable;
  13317. if (tEnable) {
  13318. if (this._cacheStyle.needBitmapCache()) {
  13319. this._cacheStyle.cacheAs = "bitmap";
  13320. }
  13321. else {
  13322. this._cacheStyle.cacheAs = this._cacheStyle.userSetCache;
  13323. }
  13324. this._cacheStyle.reCache = true;
  13325. this._renderType |= SpriteConst.CANVAS;
  13326. }
  13327. else {
  13328. this._cacheStyle.cacheAs = "none";
  13329. this._cacheStyle.releaseContext();
  13330. this._renderType &= ~SpriteConst.CANVAS;
  13331. }
  13332. this._setCacheAs(this._cacheStyle.cacheAs);
  13333. this._setRenderType(this._renderType);
  13334. }
  13335. get staticCache() {
  13336. return this._cacheStyle.staticCache;
  13337. }
  13338. set staticCache(value) {
  13339. this._getCacheStyle().staticCache = value;
  13340. if (!value)
  13341. this.reCache();
  13342. }
  13343. reCache() {
  13344. this._cacheStyle.reCache = true;
  13345. this._repaint |= SpriteConst.REPAINT_CACHE;
  13346. }
  13347. getRepaint() {
  13348. return this._repaint;
  13349. }
  13350. _setX(value) {
  13351. this._x = value;
  13352. }
  13353. _setY(value) {
  13354. this._y = value;
  13355. }
  13356. _setWidth(texture, value) {
  13357. }
  13358. _setHeight(texture, value) {
  13359. }
  13360. get x() {
  13361. return this._x;
  13362. }
  13363. set x(value) {
  13364. if (this.destroyed)
  13365. return;
  13366. if (this._x !== value) {
  13367. this._setX(value);
  13368. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13369. var p = this._cacheStyle.maskParent;
  13370. if (p) {
  13371. p.repaint(SpriteConst.REPAINT_CACHE);
  13372. }
  13373. }
  13374. }
  13375. get y() {
  13376. return this._y;
  13377. }
  13378. set y(value) {
  13379. if (this.destroyed)
  13380. return;
  13381. if (this._y !== value) {
  13382. this._setY(value);
  13383. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13384. var p = this._cacheStyle.maskParent;
  13385. if (p) {
  13386. p.repaint(SpriteConst.REPAINT_CACHE);
  13387. }
  13388. }
  13389. }
  13390. get width() {
  13391. return this.get_width();
  13392. }
  13393. set width(value) {
  13394. this.set_width(value);
  13395. }
  13396. set_width(value) {
  13397. if (this._width !== value) {
  13398. this._width = value;
  13399. this._setWidth(this.texture, value);
  13400. this._setTranformChange();
  13401. }
  13402. }
  13403. get_width() {
  13404. if (!this.autoSize)
  13405. return this._width || (this.texture ? this.texture.width : 0);
  13406. if (this.texture)
  13407. return this.texture.width;
  13408. if (!this._graphics && this._children.length === 0)
  13409. return 0;
  13410. return this.getSelfBounds().width;
  13411. }
  13412. get height() {
  13413. return this.get_height();
  13414. }
  13415. set height(value) {
  13416. this.set_height(value);
  13417. }
  13418. set_height(value) {
  13419. if (this._height !== value) {
  13420. this._height = value;
  13421. this._setHeight(this.texture, value);
  13422. this._setTranformChange();
  13423. }
  13424. }
  13425. get_height() {
  13426. if (!this.autoSize)
  13427. return this._height || (this.texture ? this.texture.height : 0);
  13428. if (this.texture)
  13429. return this.texture.height;
  13430. if (!this._graphics && this._children.length === 0)
  13431. return 0;
  13432. return this.getSelfBounds().height;
  13433. }
  13434. get displayWidth() {
  13435. return this.width * this.scaleX;
  13436. }
  13437. get displayHeight() {
  13438. return this.height * this.scaleY;
  13439. }
  13440. setSelfBounds(bound) {
  13441. this._getBoundsStyle().userBounds = bound;
  13442. }
  13443. getBounds() {
  13444. return this._getBoundsStyle().bounds = Rectangle._getWrapRec(this._boundPointsToParent());
  13445. }
  13446. getSelfBounds() {
  13447. if (this._boundStyle && this._boundStyle.userBounds)
  13448. return this._boundStyle.userBounds;
  13449. if (!this._graphics && this._children.length === 0 && !this._texture)
  13450. return Rectangle.TEMP.setTo(0, 0, this.width, this.height);
  13451. return this._getBoundsStyle().bounds = Rectangle._getWrapRec(this._getBoundPointsM(false));
  13452. }
  13453. _boundPointsToParent(ifRotate = false) {
  13454. var pX = 0, pY = 0;
  13455. if (this._style) {
  13456. pX = this.pivotX;
  13457. pY = this.pivotY;
  13458. ifRotate = ifRotate || (this._style.rotation !== 0);
  13459. if (this._style.scrollRect) {
  13460. pX += this._style.scrollRect.x;
  13461. pY += this._style.scrollRect.y;
  13462. }
  13463. }
  13464. var pList = this._getBoundPointsM(ifRotate);
  13465. if (!pList || pList.length < 1)
  13466. return pList;
  13467. if (pList.length != 8) {
  13468. pList = ifRotate ? GrahamScan.scanPList(pList) : Rectangle._getWrapRec(pList, Rectangle.TEMP)._getBoundPoints();
  13469. }
  13470. if (!this.transform) {
  13471. Utils.transPointList(pList, this._x - pX, this._y - pY);
  13472. return pList;
  13473. }
  13474. var tPoint = Point.TEMP;
  13475. var i, len = pList.length;
  13476. for (i = 0; i < len; i += 2) {
  13477. tPoint.x = pList[i];
  13478. tPoint.y = pList[i + 1];
  13479. this.toParentPoint(tPoint);
  13480. pList[i] = tPoint.x;
  13481. pList[i + 1] = tPoint.y;
  13482. }
  13483. return pList;
  13484. }
  13485. getGraphicBounds(realSize = false) {
  13486. if (!this._graphics)
  13487. return Rectangle.TEMP.setTo(0, 0, 0, 0);
  13488. return this._graphics.getBounds(realSize);
  13489. }
  13490. _getBoundPointsM(ifRotate = false) {
  13491. if (this._boundStyle && this._boundStyle.userBounds)
  13492. return this._boundStyle.userBounds._getBoundPoints();
  13493. if (!this._boundStyle)
  13494. this._getBoundsStyle();
  13495. if (!this._boundStyle.temBM)
  13496. this._boundStyle.temBM = [];
  13497. if (this._style.scrollRect) {
  13498. var rst = Utils.clearArray(this._boundStyle.temBM);
  13499. var rec = Rectangle.TEMP;
  13500. rec.copyFrom(this._style.scrollRect);
  13501. Utils.concatArray(rst, rec._getBoundPoints());
  13502. return rst;
  13503. }
  13504. var pList;
  13505. if (this._graphics) {
  13506. pList = this._graphics.getBoundPoints();
  13507. }
  13508. else {
  13509. pList = Utils.clearArray(this._boundStyle.temBM);
  13510. if (this._texture) {
  13511. rec = Rectangle.TEMP;
  13512. rec.setTo(0, 0, this.width || this._texture.width, this.height || this._texture.height);
  13513. Utils.concatArray(pList, rec._getBoundPoints());
  13514. }
  13515. }
  13516. var child;
  13517. var cList;
  13518. var __childs;
  13519. __childs = this._children;
  13520. for (var i = 0, n = __childs.length; i < n; i++) {
  13521. child = __childs[i];
  13522. if (child instanceof Sprite && child._visible === true) {
  13523. cList = child._boundPointsToParent(ifRotate);
  13524. if (cList)
  13525. pList = pList ? Utils.concatArray(pList, cList) : cList;
  13526. }
  13527. }
  13528. return pList;
  13529. }
  13530. _getCacheStyle() {
  13531. this._cacheStyle === CacheStyle.EMPTY && (this._cacheStyle = CacheStyle.create());
  13532. return this._cacheStyle;
  13533. }
  13534. getStyle() {
  13535. this._style === SpriteStyle.EMPTY && (this._style = SpriteStyle.create());
  13536. return this._style;
  13537. }
  13538. setStyle(value) {
  13539. this._style = value;
  13540. }
  13541. get scaleX() {
  13542. return this._style.scaleX;
  13543. }
  13544. set scaleX(value) {
  13545. this.set_scaleX(value);
  13546. }
  13547. _setScaleX(value) {
  13548. this._style.scaleX = value;
  13549. }
  13550. get scaleY() {
  13551. return this._style.scaleY;
  13552. }
  13553. set scaleY(value) {
  13554. this.set_scaleY(value);
  13555. }
  13556. _setScaleY(value) {
  13557. this._style.scaleY = value;
  13558. }
  13559. set_scaleX(value) {
  13560. var style = this.getStyle();
  13561. if (style.scaleX !== value) {
  13562. this._setScaleX(value);
  13563. this._setTranformChange();
  13564. }
  13565. }
  13566. get_scaleX() {
  13567. return this._style.scaleX;
  13568. }
  13569. set_scaleY(value) {
  13570. var style = this.getStyle();
  13571. if (style.scaleY !== value) {
  13572. this._setScaleY(value);
  13573. this._setTranformChange();
  13574. }
  13575. }
  13576. get_scaleY() {
  13577. return this._style.scaleY;
  13578. }
  13579. get rotation() {
  13580. return this._style.rotation;
  13581. }
  13582. set rotation(value) {
  13583. var style = this.getStyle();
  13584. if (style.rotation !== value) {
  13585. this._setRotation(value);
  13586. this._setTranformChange();
  13587. }
  13588. }
  13589. _setRotation(value) {
  13590. this._style.rotation = value;
  13591. }
  13592. get skewX() {
  13593. return this._style.skewX;
  13594. }
  13595. set skewX(value) {
  13596. var style = this.getStyle();
  13597. if (style.skewX !== value) {
  13598. this._setSkewX(value);
  13599. this._setTranformChange();
  13600. }
  13601. }
  13602. _setSkewX(value) {
  13603. this._style.skewX = value;
  13604. }
  13605. get skewY() {
  13606. return this._style.skewY;
  13607. }
  13608. set skewY(value) {
  13609. var style = this.getStyle();
  13610. if (style.skewY !== value) {
  13611. this._setSkewY(value);
  13612. this._setTranformChange();
  13613. }
  13614. }
  13615. _setSkewY(value) {
  13616. this._style.skewY = value;
  13617. }
  13618. _createTransform() {
  13619. return Matrix.create();
  13620. }
  13621. _adjustTransform() {
  13622. this._tfChanged = false;
  13623. var style = this._style;
  13624. var sx = style.scaleX, sy = style.scaleY;
  13625. var sskx = style.skewX;
  13626. var ssky = style.skewY;
  13627. var rot = style.rotation;
  13628. var m = this._transform || (this._transform = this._createTransform());
  13629. if (rot || sx !== 1 || sy !== 1 || sskx !== 0 || ssky !== 0) {
  13630. m._bTransform = true;
  13631. var skx = (rot - sskx) * 0.0174532922222222;
  13632. var sky = (rot + ssky) * 0.0174532922222222;
  13633. var cx = Math.cos(sky);
  13634. var ssx = Math.sin(sky);
  13635. var cy = Math.sin(skx);
  13636. var ssy = Math.cos(skx);
  13637. m.a = sx * cx;
  13638. m.b = sx * ssx;
  13639. m.c = -sy * cy;
  13640. m.d = sy * ssy;
  13641. m.tx = m.ty = 0;
  13642. }
  13643. else {
  13644. m.identity();
  13645. this._renderType &= ~SpriteConst.TRANSFORM;
  13646. this._setRenderType(this._renderType);
  13647. }
  13648. return m;
  13649. }
  13650. _setTransform(value) {
  13651. }
  13652. get transform() {
  13653. return this._tfChanged ? this._adjustTransform() : this._transform;
  13654. }
  13655. set transform(value) {
  13656. this.set_transform(value);
  13657. }
  13658. get_transform() {
  13659. return this._tfChanged ? this._adjustTransform() : this._transform;
  13660. }
  13661. set_transform(value) {
  13662. this._tfChanged = false;
  13663. var m = this._transform || (this._transform = this._createTransform());
  13664. value.copyTo(m);
  13665. this._setTransform(m);
  13666. if (value) {
  13667. this._x = m.tx;
  13668. this._y = m.ty;
  13669. m.tx = m.ty = 0;
  13670. }
  13671. if (value)
  13672. this._renderType |= SpriteConst.TRANSFORM;
  13673. else {
  13674. this._renderType &= ~SpriteConst.TRANSFORM;
  13675. }
  13676. this._setRenderType(this._renderType);
  13677. this.parentRepaint();
  13678. }
  13679. _setPivotX(value) {
  13680. var style = this.getStyle();
  13681. style.pivotX = value;
  13682. }
  13683. _getPivotX() {
  13684. return this._style.pivotX;
  13685. }
  13686. _setPivotY(value) {
  13687. var style = this.getStyle();
  13688. style.pivotY = value;
  13689. }
  13690. _getPivotY() {
  13691. return this._style.pivotY;
  13692. }
  13693. get pivotX() {
  13694. return this._getPivotX();
  13695. }
  13696. set pivotX(value) {
  13697. this._setPivotX(value);
  13698. this.repaint();
  13699. }
  13700. get pivotY() {
  13701. return this._getPivotY();
  13702. }
  13703. set pivotY(value) {
  13704. this._setPivotY(value);
  13705. this.repaint();
  13706. }
  13707. _setAlpha(value) {
  13708. if (this._style.alpha !== value) {
  13709. var style = this.getStyle();
  13710. style.alpha = value;
  13711. if (value !== 1)
  13712. this._renderType |= SpriteConst.ALPHA;
  13713. else
  13714. this._renderType &= ~SpriteConst.ALPHA;
  13715. this._setRenderType(this._renderType);
  13716. this.parentRepaint();
  13717. }
  13718. }
  13719. _getAlpha() {
  13720. return this._style.alpha;
  13721. }
  13722. get alpha() {
  13723. return this._getAlpha();
  13724. }
  13725. set alpha(value) {
  13726. value = value < 0 ? 0 : (value > 1 ? 1 : value);
  13727. this._setAlpha(value);
  13728. }
  13729. get visible() {
  13730. return this.get_visible();
  13731. }
  13732. set visible(value) {
  13733. this.set_visible(value);
  13734. }
  13735. get_visible() {
  13736. return this._visible;
  13737. }
  13738. set_visible(value) {
  13739. if (this._visible !== value) {
  13740. this._visible = value;
  13741. this.parentRepaint(SpriteConst.REPAINT_ALL);
  13742. }
  13743. }
  13744. _setBlendMode(value) {
  13745. }
  13746. get blendMode() {
  13747. return this._style.blendMode;
  13748. }
  13749. set blendMode(value) {
  13750. this._setBlendMode(value);
  13751. this.getStyle().blendMode = value;
  13752. if (value && value != "source-over")
  13753. this._renderType |= SpriteConst.BLEND;
  13754. else
  13755. this._renderType &= ~SpriteConst.BLEND;
  13756. this._setRenderType(this._renderType);
  13757. this.parentRepaint();
  13758. }
  13759. get graphics() {
  13760. if (!this._graphics) {
  13761. this.graphics = new Graphics();
  13762. this._graphics.autoDestroy = true;
  13763. }
  13764. return this._graphics;
  13765. }
  13766. _setGraphics(value) {
  13767. }
  13768. _setGraphicsCallBack() {
  13769. }
  13770. set graphics(value) {
  13771. if (this._graphics)
  13772. this._graphics._sp = null;
  13773. this._graphics = value;
  13774. if (value) {
  13775. this._setGraphics(value);
  13776. this._renderType |= SpriteConst.GRAPHICS;
  13777. value._sp = this;
  13778. }
  13779. else {
  13780. this._renderType &= ~SpriteConst.GRAPHICS;
  13781. }
  13782. this._setRenderType(this._renderType);
  13783. this.repaint();
  13784. }
  13785. get scrollRect() {
  13786. return this._style.scrollRect;
  13787. }
  13788. _setScrollRect(value) {
  13789. }
  13790. set scrollRect(value) {
  13791. this.getStyle().scrollRect = value;
  13792. this._setScrollRect(value);
  13793. this.repaint();
  13794. if (value) {
  13795. this._renderType |= SpriteConst.CLIP;
  13796. }
  13797. else {
  13798. this._renderType &= ~SpriteConst.CLIP;
  13799. }
  13800. this._setRenderType(this._renderType);
  13801. }
  13802. pos(x, y, speedMode = false) {
  13803. if (this._x !== x || this._y !== y) {
  13804. if (this.destroyed)
  13805. return this;
  13806. if (speedMode) {
  13807. this._setX(x);
  13808. this._setY(y);
  13809. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13810. var p = this._cacheStyle.maskParent;
  13811. if (p) {
  13812. p.repaint(SpriteConst.REPAINT_CACHE);
  13813. }
  13814. }
  13815. else {
  13816. this.x = x;
  13817. this.y = y;
  13818. }
  13819. }
  13820. return this;
  13821. }
  13822. pivot(x, y) {
  13823. this.pivotX = x;
  13824. this.pivotY = y;
  13825. return this;
  13826. }
  13827. size(width, height) {
  13828. this.width = width;
  13829. this.height = height;
  13830. return this;
  13831. }
  13832. scale(scaleX, scaleY, speedMode = false) {
  13833. var style = this.getStyle();
  13834. if (style.scaleX != scaleX || style.scaleY != scaleY) {
  13835. if (this.destroyed)
  13836. return this;
  13837. if (speedMode) {
  13838. this._setScaleX(scaleX);
  13839. this._setScaleY(scaleY);
  13840. this._setTranformChange();
  13841. }
  13842. else {
  13843. this.scaleX = scaleX;
  13844. this.scaleY = scaleY;
  13845. }
  13846. }
  13847. return this;
  13848. }
  13849. skew(skewX, skewY) {
  13850. this.skewX = skewX;
  13851. this.skewY = skewY;
  13852. return this;
  13853. }
  13854. render(ctx, x, y) {
  13855. RenderSprite.renders[this._renderType]._fun(this, ctx, x + this._x, y + this._y);
  13856. this._repaint = 0;
  13857. }
  13858. drawToCanvas(canvasWidth, canvasHeight, offsetX, offsetY) {
  13859. return Sprite.drawToCanvas(this, this._renderType, canvasWidth, canvasHeight, offsetX, offsetY);
  13860. }
  13861. drawToTexture(canvasWidth, canvasHeight, offsetX, offsetY, rt = null) {
  13862. return Sprite.drawToTexture(this, this._renderType, canvasWidth, canvasHeight, offsetX, offsetY, rt);
  13863. }
  13864. drawToTexture3D(offx, offy, tex) {
  13865. throw 'not implement';
  13866. }
  13867. static drawToCanvas(sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  13868. offsetX -= sprite.x;
  13869. offsetY -= sprite.y;
  13870. offsetX |= 0;
  13871. offsetY |= 0;
  13872. canvasWidth |= 0;
  13873. canvasHeight |= 0;
  13874. var ctx = new Context();
  13875. ctx.size(canvasWidth, canvasHeight);
  13876. ctx.asBitmap = true;
  13877. ctx._targets.start();
  13878. ctx._targets.clear(0, 0, 0, 0);
  13879. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  13880. ctx.flush();
  13881. ctx._targets.end();
  13882. ctx._targets.restore();
  13883. var dt = ctx._targets.getData(0, 0, canvasWidth, canvasHeight);
  13884. ctx.destroy();
  13885. var imgdata = new ImageData(canvasWidth, canvasHeight);
  13886. var lineLen = canvasWidth * 4;
  13887. var dst = imgdata.data;
  13888. var y = canvasHeight - 1;
  13889. var off = y * lineLen;
  13890. var srcoff = 0;
  13891. for (; y >= 0; y--) {
  13892. dst.set(dt.subarray(srcoff, srcoff + lineLen), off);
  13893. off -= lineLen;
  13894. srcoff += lineLen;
  13895. }
  13896. var canv = new HTMLCanvas(true);
  13897. canv.size(canvasWidth, canvasHeight);
  13898. var ctx2d = canv.getContext('2d');
  13899. ctx2d.putImageData(imgdata, 0, 0);
  13900. return canv;
  13901. }
  13902. static drawToTexture(sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY, rt = null) {
  13903. if (!Sprite.drawtocanvCtx) {
  13904. Sprite.drawtocanvCtx = new Context();
  13905. }
  13906. offsetX -= sprite.x;
  13907. offsetY -= sprite.y;
  13908. offsetX |= 0;
  13909. offsetY |= 0;
  13910. canvasWidth |= 0;
  13911. canvasHeight |= 0;
  13912. var ctx = rt ? Sprite.drawtocanvCtx : new Context();
  13913. ctx.clear();
  13914. ctx.size(canvasWidth, canvasHeight);
  13915. if (rt) {
  13916. ctx._targets = rt;
  13917. }
  13918. else {
  13919. ctx.asBitmap = true;
  13920. }
  13921. if (ctx._targets) {
  13922. ctx._targets.start();
  13923. ctx._targets.clear(0, 0, 0, 0);
  13924. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  13925. ctx.flush();
  13926. ctx._targets.end();
  13927. ctx._targets.restore();
  13928. }
  13929. if (!rt) {
  13930. var rtex = new Texture(ctx._targets, Texture.INV_UV);
  13931. ctx.destroy(true);
  13932. return rtex;
  13933. }
  13934. sprite._repaint = 0;
  13935. return rt;
  13936. }
  13937. customRender(context, x, y) {
  13938. this._repaint = SpriteConst.REPAINT_ALL;
  13939. }
  13940. _applyFilters() {
  13941. }
  13942. get filters() {
  13943. return this._cacheStyle.filters;
  13944. }
  13945. _setColorFilter(value) { }
  13946. set filters(value) {
  13947. value && value.length === 0 && (value = null);
  13948. if (this._cacheStyle.filters == value)
  13949. return;
  13950. this._getCacheStyle().filters = value ? value.slice() : null;
  13951. if (value && value.length) {
  13952. this._setColorFilter(value[0]);
  13953. this._renderType |= SpriteConst.FILTERS;
  13954. }
  13955. else {
  13956. this._setColorFilter(null);
  13957. this._renderType &= ~SpriteConst.FILTERS;
  13958. }
  13959. this._setRenderType(this._renderType);
  13960. if (value && value.length > 0) {
  13961. if (!this._getBit(Const.DISPLAY))
  13962. this._setBitUp(Const.DISPLAY);
  13963. if (!(value.length == 1 && (value[0] instanceof ColorFilter))) {
  13964. this._getCacheStyle().cacheForFilters = true;
  13965. this._checkCanvasEnable();
  13966. }
  13967. }
  13968. else {
  13969. if (this._cacheStyle.cacheForFilters) {
  13970. this._cacheStyle.cacheForFilters = false;
  13971. this._checkCanvasEnable();
  13972. }
  13973. }
  13974. this._getCacheStyle().hasGlowFilter = this._isHaveGlowFilter();
  13975. this.repaint();
  13976. }
  13977. _isHaveGlowFilter() {
  13978. var i, len;
  13979. if (this.filters) {
  13980. for (i = 0; i < this.filters.length; i++) {
  13981. if (this.filters[i].type == Filter.GLOW) {
  13982. return true;
  13983. }
  13984. }
  13985. }
  13986. for (i = 0, len = this._children.length; i < len; i++) {
  13987. if (this._children[i]._isHaveGlowFilter()) {
  13988. return true;
  13989. }
  13990. }
  13991. return false;
  13992. }
  13993. localToGlobal(point, createNewPoint = false, globalNode = null) {
  13994. if (createNewPoint === true) {
  13995. point = new Point(point.x, point.y);
  13996. }
  13997. var ele = this;
  13998. globalNode = globalNode || ILaya.stage;
  13999. while (ele && !ele.destroyed) {
  14000. if (ele == globalNode)
  14001. break;
  14002. point = ele.toParentPoint(point);
  14003. ele = ele.parent;
  14004. }
  14005. return point;
  14006. }
  14007. globalToLocal(point, createNewPoint = false, globalNode = null) {
  14008. if (createNewPoint) {
  14009. point = new Point(point.x, point.y);
  14010. }
  14011. var ele = this;
  14012. var list = [];
  14013. globalNode = globalNode || ILaya.stage;
  14014. while (ele && !ele.destroyed) {
  14015. if (ele == globalNode)
  14016. break;
  14017. list.push(ele);
  14018. ele = ele.parent;
  14019. }
  14020. var i = list.length - 1;
  14021. while (i >= 0) {
  14022. ele = list[i];
  14023. point = ele.fromParentPoint(point);
  14024. i--;
  14025. }
  14026. return point;
  14027. }
  14028. toParentPoint(point) {
  14029. if (!point)
  14030. return point;
  14031. point.x -= this.pivotX;
  14032. point.y -= this.pivotY;
  14033. if (this.transform) {
  14034. this._transform.transformPoint(point);
  14035. }
  14036. point.x += this._x;
  14037. point.y += this._y;
  14038. var scroll = this._style.scrollRect;
  14039. if (scroll) {
  14040. point.x -= scroll.x;
  14041. point.y -= scroll.y;
  14042. }
  14043. return point;
  14044. }
  14045. fromParentPoint(point) {
  14046. if (!point)
  14047. return point;
  14048. point.x -= this._x;
  14049. point.y -= this._y;
  14050. var scroll = this._style.scrollRect;
  14051. if (scroll) {
  14052. point.x += scroll.x;
  14053. point.y += scroll.y;
  14054. }
  14055. if (this.transform) {
  14056. this._transform.invertTransformPoint(point);
  14057. }
  14058. point.x += this.pivotX;
  14059. point.y += this.pivotY;
  14060. return point;
  14061. }
  14062. fromStagePoint(point) {
  14063. return point;
  14064. }
  14065. on(type, caller, listener, args = null) {
  14066. if (this._mouseState !== 1 && this.isMouseEvent(type)) {
  14067. this.mouseEnabled = true;
  14068. this._setBit(Const.HAS_MOUSE, true);
  14069. if (this._parent) {
  14070. this._onDisplay();
  14071. }
  14072. return this._createListener(type, caller, listener, args, false);
  14073. }
  14074. return super.on(type, caller, listener, args);
  14075. }
  14076. once(type, caller, listener, args = null) {
  14077. if (this._mouseState !== 1 && this.isMouseEvent(type)) {
  14078. this.mouseEnabled = true;
  14079. this._setBit(Const.HAS_MOUSE, true);
  14080. if (this._parent) {
  14081. this._onDisplay();
  14082. }
  14083. return this._createListener(type, caller, listener, args, true);
  14084. }
  14085. return super.once(type, caller, listener, args);
  14086. }
  14087. _onDisplay(v) {
  14088. if (this._mouseState !== 1) {
  14089. var ele = this;
  14090. ele = ele.parent;
  14091. while (ele && ele._mouseState !== 1) {
  14092. if (ele._getBit(Const.HAS_MOUSE))
  14093. break;
  14094. ele.mouseEnabled = true;
  14095. ele._setBit(Const.HAS_MOUSE, true);
  14096. ele = ele.parent;
  14097. }
  14098. }
  14099. }
  14100. _setParent(value) {
  14101. super._setParent(value);
  14102. if (value && this._getBit(Const.HAS_MOUSE)) {
  14103. this._onDisplay();
  14104. }
  14105. }
  14106. loadImage(url, complete = null) {
  14107. if (!url) {
  14108. this.texture = null;
  14109. loaded.call(this);
  14110. }
  14111. else {
  14112. var tex = ILaya.Loader.textureMap[URL.formatURL(url)];
  14113. if (!tex) {
  14114. tex = new Texture();
  14115. tex.load(url);
  14116. ILaya.Loader.cacheTexture(url, tex);
  14117. }
  14118. this.texture = tex;
  14119. if (!tex.getIsReady())
  14120. tex.once(Event.READY, this, loaded);
  14121. else
  14122. loaded.call(this);
  14123. }
  14124. function loaded() {
  14125. this.repaint(SpriteConst.REPAINT_ALL);
  14126. complete && complete.run();
  14127. }
  14128. return this;
  14129. }
  14130. static fromImage(url) {
  14131. return new Sprite().loadImage(url);
  14132. }
  14133. repaint(type = SpriteConst.REPAINT_CACHE) {
  14134. if (!(this._repaint & type)) {
  14135. this._repaint |= type;
  14136. this.parentRepaint(type);
  14137. }
  14138. if (this._cacheStyle && this._cacheStyle.maskParent) {
  14139. this._cacheStyle.maskParent.repaint(type);
  14140. }
  14141. }
  14142. _needRepaint() {
  14143. return (this._repaint & SpriteConst.REPAINT_CACHE) && this._cacheStyle.enableCanvasRender && this._cacheStyle.reCache;
  14144. }
  14145. _childChanged(child = null) {
  14146. if (this._children.length)
  14147. this._renderType |= SpriteConst.CHILDS;
  14148. else
  14149. this._renderType &= ~SpriteConst.CHILDS;
  14150. this._setRenderType(this._renderType);
  14151. if (child && this._getBit(Const.HAS_ZORDER))
  14152. ILaya.systemTimer.callLater(this, this.updateZOrder);
  14153. this.repaint(SpriteConst.REPAINT_ALL);
  14154. }
  14155. parentRepaint(type = SpriteConst.REPAINT_CACHE) {
  14156. var p = this._parent;
  14157. if (p && !(p._repaint & type)) {
  14158. p._repaint |= type;
  14159. p.parentRepaint(type);
  14160. }
  14161. }
  14162. get stage() {
  14163. return ILaya.stage;
  14164. }
  14165. get hitArea() {
  14166. return this._style.hitArea;
  14167. }
  14168. set hitArea(value) {
  14169. this.getStyle().hitArea = value;
  14170. }
  14171. _setMask(value) {
  14172. }
  14173. get mask() {
  14174. return this._cacheStyle.mask;
  14175. }
  14176. set mask(value) {
  14177. if (value && this.mask && this.mask._cacheStyle.maskParent)
  14178. return;
  14179. this._getCacheStyle().mask = value;
  14180. this._setMask(value);
  14181. this._checkCanvasEnable();
  14182. if (value) {
  14183. value._getCacheStyle().maskParent = this;
  14184. }
  14185. else {
  14186. if (this.mask) {
  14187. this.mask._getCacheStyle().maskParent = null;
  14188. }
  14189. }
  14190. this._renderType |= SpriteConst.MASK;
  14191. this._setRenderType(this._renderType);
  14192. this.parentRepaint(SpriteConst.REPAINT_ALL);
  14193. }
  14194. get mouseEnabled() {
  14195. return this._mouseState > 1;
  14196. }
  14197. set mouseEnabled(value) {
  14198. this._mouseState = value ? 2 : 1;
  14199. }
  14200. startDrag(area = null, hasInertia = false, elasticDistance = 0, elasticBackTime = 300, data = null, disableMouseEvent = false, ratio = 0.92) {
  14201. this._style.dragging || (this.getStyle().dragging = new ILaya.Dragging());
  14202. this._style.dragging.start(this, area, hasInertia, elasticDistance, elasticBackTime, data, disableMouseEvent, ratio);
  14203. }
  14204. stopDrag() {
  14205. this._style.dragging && this._style.dragging.stop();
  14206. }
  14207. _setDisplay(value) {
  14208. if (!value) {
  14209. if (this._cacheStyle) {
  14210. this._cacheStyle.releaseContext();
  14211. this._cacheStyle.releaseFilterCache();
  14212. if (this._cacheStyle.hasGlowFilter) {
  14213. this._cacheStyle.hasGlowFilter = false;
  14214. }
  14215. }
  14216. }
  14217. super._setDisplay(value);
  14218. }
  14219. hitTestPoint(x, y) {
  14220. var point = this.globalToLocal(Point.TEMP.setTo(x, y));
  14221. x = point.x;
  14222. y = point.y;
  14223. var rect = this._style.hitArea ? this._style.hitArea : (this._width > 0 && this._height > 0) ? Rectangle.TEMP.setTo(0, 0, this._width, this._height) : this.getSelfBounds();
  14224. return rect.contains(x, y);
  14225. }
  14226. getMousePoint() {
  14227. return this.globalToLocal(Point.TEMP.setTo(ILaya.stage.mouseX, ILaya.stage.mouseY));
  14228. }
  14229. get globalScaleX() {
  14230. var scale = 1;
  14231. var ele = this;
  14232. while (ele) {
  14233. if (ele === ILaya.stage)
  14234. break;
  14235. scale *= ele.scaleX;
  14236. ele = ele.parent;
  14237. }
  14238. return scale;
  14239. }
  14240. get globalRotation() {
  14241. var angle = 0;
  14242. var ele = this;
  14243. while (ele) {
  14244. if (ele === ILaya.stage)
  14245. break;
  14246. angle += ele.rotation;
  14247. ele = ele.parent;
  14248. }
  14249. return angle;
  14250. }
  14251. get globalScaleY() {
  14252. var scale = 1;
  14253. var ele = this;
  14254. while (ele) {
  14255. if (ele === ILaya.stage)
  14256. break;
  14257. scale *= ele.scaleY;
  14258. ele = ele.parent;
  14259. }
  14260. return scale;
  14261. }
  14262. get mouseX() {
  14263. return this.getMousePoint().x;
  14264. }
  14265. get mouseY() {
  14266. return this.getMousePoint().y;
  14267. }
  14268. get zOrder() {
  14269. return this._zOrder;
  14270. }
  14271. set zOrder(value) {
  14272. if (this._zOrder != value) {
  14273. this._zOrder = value;
  14274. if (this._parent) {
  14275. value && this._parent._setBit(Const.HAS_ZORDER, true);
  14276. ILaya.systemTimer.callLater(this._parent, this.updateZOrder);
  14277. }
  14278. }
  14279. }
  14280. get texture() {
  14281. return this._texture;
  14282. }
  14283. _setTexture(value) {
  14284. }
  14285. set texture(value) {
  14286. if (typeof (value) == 'string') {
  14287. this.loadImage(value);
  14288. }
  14289. else if (this._texture != value) {
  14290. this._texture && this._texture._removeReference();
  14291. this._texture = value;
  14292. value && value._addReference();
  14293. this._setTexture(value);
  14294. this._setWidth(this._texture, this.width);
  14295. this._setHeight(this._texture, this.height);
  14296. if (value)
  14297. this._renderType |= SpriteConst.TEXTURE;
  14298. else
  14299. this._renderType &= ~SpriteConst.TEXTURE;
  14300. this._setRenderType(this._renderType);
  14301. this.repaint();
  14302. }
  14303. }
  14304. get viewport() {
  14305. return this._style.viewport;
  14306. }
  14307. set viewport(value) {
  14308. if (typeof (value) == 'string') {
  14309. var recArr;
  14310. recArr = value.split(",");
  14311. if (recArr.length > 3) {
  14312. value = new Rectangle(parseFloat(recArr[0]), parseFloat(recArr[1]), parseFloat(recArr[2]), parseFloat(recArr[3]));
  14313. }
  14314. }
  14315. this.getStyle().viewport = value;
  14316. }
  14317. _setRenderType(type) {
  14318. }
  14319. _setTranformChange() {
  14320. this._tfChanged = true;
  14321. this._renderType |= SpriteConst.TRANSFORM;
  14322. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  14323. }
  14324. _setBgStyleColor(x, y, width, height, fillColor) {
  14325. }
  14326. _setBorderStyleColor(x, y, width, height, fillColor, borderWidth) {
  14327. }
  14328. captureMouseEvent(exclusive) {
  14329. ILaya.MouseManager.instance.setCapture(this, exclusive);
  14330. }
  14331. releaseMouseEvent() {
  14332. ILaya.MouseManager.instance.releaseCapture();
  14333. }
  14334. set drawCallOptimize(value) {
  14335. this._setBit(Const.DRAWCALL_OPTIMIZE, value);
  14336. }
  14337. get drawCallOptimize() {
  14338. return this._getBit(Const.DRAWCALL_OPTIMIZE);
  14339. }
  14340. }
  14341. ClassUtils.regClass("laya.display.Sprite", Sprite);
  14342. ClassUtils.regClass("Laya.Sprite", Sprite);
  14343. class TextStyle extends SpriteStyle {
  14344. constructor() {
  14345. super(...arguments);
  14346. this.italic = false;
  14347. }
  14348. reset() {
  14349. super.reset();
  14350. this.italic = false;
  14351. this.align = "left";
  14352. this.wordWrap = false;
  14353. this.leading = 0;
  14354. this.padding = [0, 0, 0, 0];
  14355. this.bgColor = null;
  14356. this.borderColor = null;
  14357. this.asPassword = false;
  14358. this.stroke = 0;
  14359. this.strokeColor = "#000000";
  14360. this.bold = false;
  14361. this.underline = false;
  14362. this.underlineColor = null;
  14363. this.currBitmapFont = null;
  14364. return this;
  14365. }
  14366. recover() {
  14367. if (this === TextStyle.EMPTY)
  14368. return;
  14369. Pool.recover("TextStyle", this.reset());
  14370. }
  14371. static create() {
  14372. return Pool.getItemByClass("TextStyle", TextStyle);
  14373. }
  14374. render(sprite, context, x, y) {
  14375. (this.bgColor || this.borderColor) && context.drawRect(x, y, sprite.width, sprite.height, this.bgColor, this.borderColor, 1);
  14376. }
  14377. }
  14378. TextStyle.EMPTY = new TextStyle();
  14379. class Text extends Sprite {
  14380. constructor() {
  14381. super();
  14382. this._textWidth = 0;
  14383. this._textHeight = 0;
  14384. this._lines = [];
  14385. this._lineWidths = [];
  14386. this._startX = 0;
  14387. this._startY = 0;
  14388. this._charSize = {};
  14389. this._valign = "top";
  14390. this._fontSize = Text.defaultFontSize;
  14391. this._font = Text.defaultFont;
  14392. this._color = "#000000";
  14393. this._singleCharRender = false;
  14394. this.overflow = Text.VISIBLE;
  14395. this._style = TextStyle.EMPTY;
  14396. }
  14397. static defaultFontStr() {
  14398. return Text.defaultFontSize + "px " + Text.defaultFont;
  14399. }
  14400. getStyle() {
  14401. this._style === TextStyle.EMPTY && (this._style = TextStyle.create());
  14402. return this._style;
  14403. }
  14404. _getTextStyle() {
  14405. if (this._style === TextStyle.EMPTY) {
  14406. this._style = TextStyle.create();
  14407. }
  14408. return this._style;
  14409. }
  14410. static registerBitmapFont(name, bitmapFont) {
  14411. Text._bitmapFonts || (Text._bitmapFonts = {});
  14412. Text._bitmapFonts[name] = bitmapFont;
  14413. }
  14414. static unregisterBitmapFont(name, destroy = true) {
  14415. if (Text._bitmapFonts && Text._bitmapFonts[name]) {
  14416. var tBitmapFont = Text._bitmapFonts[name];
  14417. if (destroy)
  14418. tBitmapFont.destroy();
  14419. delete Text._bitmapFonts[name];
  14420. }
  14421. }
  14422. destroy(destroyChild = true) {
  14423. super.destroy(destroyChild);
  14424. this._clipPoint = null;
  14425. this._lines = null;
  14426. this._lineWidths = null;
  14427. this._words && this._words.forEach(function (w) {
  14428. w.cleanCache();
  14429. });
  14430. this._words = null;
  14431. this._charSize = null;
  14432. }
  14433. _getBoundPointsM(ifRotate = false) {
  14434. var rec = Rectangle.TEMP;
  14435. rec.setTo(0, 0, this.width, this.height);
  14436. return rec._getBoundPoints();
  14437. }
  14438. getGraphicBounds(realSize = false) {
  14439. var rec = Rectangle.TEMP;
  14440. rec.setTo(0, 0, this.width, this.height);
  14441. return rec;
  14442. }
  14443. get width() {
  14444. if (this._width)
  14445. return this._width;
  14446. return this.textWidth + this.padding[1] + this.padding[3];
  14447. }
  14448. set width(value) {
  14449. if (value != this._width) {
  14450. super.set_width(value);
  14451. this.isChanged = true;
  14452. if (this.borderColor) {
  14453. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14454. }
  14455. }
  14456. }
  14457. _getCSSStyle() {
  14458. return this._style;
  14459. }
  14460. get height() {
  14461. if (this._height)
  14462. return this._height;
  14463. return this.textHeight;
  14464. }
  14465. set height(value) {
  14466. if (value != this._height) {
  14467. super.set_height(value);
  14468. this.isChanged = true;
  14469. if (this.borderColor) {
  14470. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14471. }
  14472. }
  14473. }
  14474. get textWidth() {
  14475. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14476. return this._textWidth;
  14477. }
  14478. get textHeight() {
  14479. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14480. return this._textHeight;
  14481. }
  14482. get text() {
  14483. return this._text || "";
  14484. }
  14485. get_text() {
  14486. return this._text || "";
  14487. }
  14488. set_text(value) {
  14489. if (this._text !== value) {
  14490. this.lang(value + "");
  14491. this.isChanged = true;
  14492. this.event(Event.CHANGE);
  14493. if (this.borderColor) {
  14494. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14495. }
  14496. }
  14497. }
  14498. set text(value) {
  14499. this.set_text(value);
  14500. }
  14501. lang(text, arg1 = null, arg2 = null, arg3 = null, arg4 = null, arg5 = null, arg6 = null, arg7 = null, arg8 = null, arg9 = null, arg10 = null) {
  14502. text = Text.langPacks && Text.langPacks[text] ? Text.langPacks[text] : text;
  14503. if (arguments.length < 2) {
  14504. this._text = text;
  14505. }
  14506. else {
  14507. for (var i = 0, n = arguments.length; i < n; i++) {
  14508. text = text.replace("{" + i + "}", arguments[i + 1]);
  14509. }
  14510. this._text = text;
  14511. }
  14512. }
  14513. get font() {
  14514. return this._font;
  14515. }
  14516. set font(value) {
  14517. if (this._style.currBitmapFont) {
  14518. this._getTextStyle().currBitmapFont = null;
  14519. this.scale(1, 1);
  14520. }
  14521. if (Text._bitmapFonts && Text._bitmapFonts[value]) {
  14522. this._getTextStyle().currBitmapFont = Text._bitmapFonts[value];
  14523. }
  14524. this._font = value;
  14525. this.isChanged = true;
  14526. }
  14527. get fontSize() {
  14528. return this._fontSize;
  14529. }
  14530. set fontSize(value) {
  14531. if (this._fontSize != value) {
  14532. this._fontSize = value;
  14533. this.isChanged = true;
  14534. }
  14535. }
  14536. get bold() {
  14537. return this._style.bold;
  14538. }
  14539. set bold(value) {
  14540. this._getTextStyle().bold = value;
  14541. this.isChanged = true;
  14542. }
  14543. get color() {
  14544. return this._color;
  14545. }
  14546. set color(value) {
  14547. this.set_color(value);
  14548. }
  14549. get_color() {
  14550. return this._color;
  14551. }
  14552. set_color(value) {
  14553. if (this._color != value) {
  14554. this._color = value;
  14555. if (!this._isChanged && this._graphics) {
  14556. this._graphics.replaceTextColor(this.color);
  14557. }
  14558. else {
  14559. this.isChanged = true;
  14560. }
  14561. }
  14562. }
  14563. get italic() {
  14564. return this._style.italic;
  14565. }
  14566. set italic(value) {
  14567. this._getTextStyle().italic = value;
  14568. this.isChanged = true;
  14569. }
  14570. get align() {
  14571. return this._style.align;
  14572. }
  14573. set align(value) {
  14574. this._getTextStyle().align = value;
  14575. this.isChanged = true;
  14576. }
  14577. get valign() {
  14578. return this._valign;
  14579. }
  14580. set valign(value) {
  14581. this._valign = value;
  14582. this.isChanged = true;
  14583. }
  14584. get wordWrap() {
  14585. return this._style.wordWrap;
  14586. }
  14587. set wordWrap(value) {
  14588. this._getTextStyle().wordWrap = value;
  14589. this.isChanged = true;
  14590. }
  14591. get leading() {
  14592. return this._style.leading;
  14593. }
  14594. set leading(value) {
  14595. this._getTextStyle().leading = value;
  14596. this.isChanged = true;
  14597. }
  14598. get padding() {
  14599. return this._style.padding;
  14600. }
  14601. set padding(value) {
  14602. if (typeof (value) == 'string') {
  14603. var arr;
  14604. arr = value.split(",");
  14605. var i, len;
  14606. len = arr.length;
  14607. while (arr.length < 4) {
  14608. arr.push(0);
  14609. }
  14610. for (i = 0; i < len; i++) {
  14611. arr[i] = parseFloat(arr[i]) || 0;
  14612. }
  14613. value = arr;
  14614. }
  14615. this._getTextStyle().padding = value;
  14616. this.isChanged = true;
  14617. }
  14618. get bgColor() {
  14619. return this._style.bgColor;
  14620. }
  14621. set bgColor(value) {
  14622. this.set_bgColor(value);
  14623. }
  14624. set_bgColor(value) {
  14625. this._getTextStyle().bgColor = value;
  14626. this._renderType |= SpriteConst.STYLE;
  14627. this._setBgStyleColor(0, 0, this.width, this.height, value);
  14628. this._setRenderType(this._renderType);
  14629. this.isChanged = true;
  14630. }
  14631. get_bgColor() {
  14632. return this._style.bgColor;
  14633. }
  14634. get borderColor() {
  14635. return this._style.borderColor;
  14636. }
  14637. set borderColor(value) {
  14638. this._getTextStyle().borderColor = value;
  14639. this._renderType |= SpriteConst.STYLE;
  14640. this._setBorderStyleColor(0, 0, this.width, this.height, value, 1);
  14641. this._setRenderType(this._renderType);
  14642. this.isChanged = true;
  14643. }
  14644. get stroke() {
  14645. return this._style.stroke;
  14646. }
  14647. set stroke(value) {
  14648. this._getTextStyle().stroke = value;
  14649. this.isChanged = true;
  14650. }
  14651. get strokeColor() {
  14652. return this._style.strokeColor;
  14653. }
  14654. set strokeColor(value) {
  14655. this._getTextStyle().strokeColor = value;
  14656. this.isChanged = true;
  14657. }
  14658. set isChanged(value) {
  14659. if (this._isChanged !== value) {
  14660. this._isChanged = value;
  14661. value && ILaya.systemTimer.callLater(this, this.typeset);
  14662. }
  14663. }
  14664. _getContextFont() {
  14665. return (this.italic ? "italic " : "") + (this.bold ? "bold " : "") + this.fontSize + "px " + (ILaya.Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font) : this.font);
  14666. }
  14667. _isPassWordMode() {
  14668. var style = this._style;
  14669. var password = style.asPassword;
  14670. if (("prompt" in this) && this['prompt'] == this._text)
  14671. password = false;
  14672. return password;
  14673. }
  14674. _getPassWordTxt(txt) {
  14675. var len = txt.length;
  14676. var word;
  14677. word = "";
  14678. for (var j = len; j > 0; j--) {
  14679. word += "●";
  14680. }
  14681. return word;
  14682. }
  14683. _renderText() {
  14684. var padding = this.padding;
  14685. var visibleLineCount = this._lines.length;
  14686. if (this.overflow != Text.VISIBLE) {
  14687. visibleLineCount = Math.min(visibleLineCount, Math.floor((this.height - padding[0] - padding[2]) / (this.leading + this._charSize.height)) + 1);
  14688. }
  14689. var beginLine = this.scrollY / (this._charSize.height + this.leading) | 0;
  14690. var graphics = this.graphics;
  14691. graphics.clear(true);
  14692. var ctxFont = this._getContextFont();
  14693. ILaya.Browser.context.font = ctxFont;
  14694. var startX = padding[3];
  14695. var textAlgin = "left";
  14696. var lines = this._lines;
  14697. var lineHeight = this.leading + this._charSize.height;
  14698. var tCurrBitmapFont = this._style.currBitmapFont;
  14699. if (tCurrBitmapFont) {
  14700. lineHeight = this.leading + tCurrBitmapFont.getMaxHeight();
  14701. }
  14702. var startY = padding[0];
  14703. if ((!tCurrBitmapFont) && this._width > 0 && this._textWidth <= this._width) {
  14704. if (this.align == "right") {
  14705. textAlgin = "right";
  14706. startX = this._width - padding[1];
  14707. }
  14708. else if (this.align == "center") {
  14709. textAlgin = "center";
  14710. startX = this._width * 0.5 + padding[3] - padding[1];
  14711. }
  14712. }
  14713. if (this._height > 0) {
  14714. var tempVAlign = (this._textHeight > this._height) ? "top" : this.valign;
  14715. if (tempVAlign === "middle")
  14716. startY = (this._height - visibleLineCount * lineHeight) * 0.5 + padding[0] - padding[2];
  14717. else if (tempVAlign === "bottom")
  14718. startY = this._height - visibleLineCount * lineHeight - padding[2];
  14719. }
  14720. var style = this._style;
  14721. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14722. var bitmapScale = tCurrBitmapFont.fontSize / this.fontSize;
  14723. }
  14724. if (this._clipPoint) {
  14725. graphics.save();
  14726. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14727. var tClipWidth;
  14728. var tClipHeight;
  14729. this._width ? tClipWidth = (this._width - padding[3] - padding[1]) : tClipWidth = this._textWidth;
  14730. this._height ? tClipHeight = (this._height - padding[0] - padding[2]) : tClipHeight = this._textHeight;
  14731. tClipWidth *= bitmapScale;
  14732. tClipHeight *= bitmapScale;
  14733. graphics.clipRect(padding[3], padding[0], tClipWidth, tClipHeight);
  14734. }
  14735. else {
  14736. graphics.clipRect(padding[3], padding[0], this._width ? (this._width - padding[3] - padding[1]) : this._textWidth, this._height ? (this._height - padding[0] - padding[2]) : this._textHeight);
  14737. }
  14738. this.repaint();
  14739. }
  14740. var password = style.asPassword;
  14741. if (("prompt" in this) && this['prompt'] == this._text)
  14742. password = false;
  14743. var x = 0, y = 0;
  14744. var end = Math.min(this._lines.length, visibleLineCount + beginLine) || 1;
  14745. for (var i = beginLine; i < end; i++) {
  14746. var word = lines[i];
  14747. var _word;
  14748. if (password) {
  14749. var len = word.length;
  14750. word = "";
  14751. for (var j = len; j > 0; j--) {
  14752. word += "●";
  14753. }
  14754. }
  14755. if (word == null)
  14756. word = "";
  14757. x = startX - (this._clipPoint ? this._clipPoint.x : 0);
  14758. y = startY + lineHeight * i - (this._clipPoint ? this._clipPoint.y : 0);
  14759. this.underline && this._drawUnderline(textAlgin, x, y, i);
  14760. if (tCurrBitmapFont) {
  14761. var tWidth = this.width;
  14762. if (tCurrBitmapFont.autoScaleSize) {
  14763. tWidth = this.width * bitmapScale;
  14764. }
  14765. tCurrBitmapFont._drawText(word, this, x, y, this.align, tWidth);
  14766. }
  14767. else {
  14768. this._words || (this._words = []);
  14769. if (this._words.length > (i - beginLine)) {
  14770. _word = this._words[i - beginLine];
  14771. }
  14772. else {
  14773. _word = new WordText();
  14774. this._words.push(_word);
  14775. }
  14776. _word.setText(word);
  14777. _word.splitRender = this._singleCharRender;
  14778. style.stroke ? graphics.fillBorderText(_word, x, y, ctxFont, this.color, textAlgin, style.stroke, style.strokeColor) : graphics.fillText(_word, x, y, ctxFont, this.color, textAlgin);
  14779. }
  14780. }
  14781. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14782. var tScale = 1 / bitmapScale;
  14783. this.scale(tScale, tScale);
  14784. }
  14785. if (this._clipPoint)
  14786. graphics.restore();
  14787. this._startX = startX;
  14788. this._startY = startY;
  14789. }
  14790. _drawUnderline(align, x, y, lineIndex) {
  14791. var lineWidth = this._lineWidths[lineIndex];
  14792. switch (align) {
  14793. case 'center':
  14794. x -= lineWidth / 2;
  14795. break;
  14796. case 'right':
  14797. x -= lineWidth;
  14798. break;
  14799. case 'left':
  14800. default:
  14801. break;
  14802. }
  14803. y += this._charSize.height;
  14804. this._graphics.drawLine(x, y, x + lineWidth, y, this.underlineColor || this.color, 1);
  14805. }
  14806. typeset() {
  14807. this._isChanged = false;
  14808. if (!this._text) {
  14809. this._clipPoint = null;
  14810. this._textWidth = this._textHeight = 0;
  14811. this.graphics.clear(true);
  14812. return;
  14813. }
  14814. if (ILaya.Render.isConchApp) {
  14815. window.conchTextCanvas.font = this._getContextFont();
  14816. }
  14817. else {
  14818. ILaya.Browser.context.font = this._getContextFont();
  14819. }
  14820. this._lines.length = 0;
  14821. this._lineWidths.length = 0;
  14822. if (this._isPassWordMode()) {
  14823. this._parseLines(this._getPassWordTxt(this._text));
  14824. }
  14825. else
  14826. this._parseLines(this._text);
  14827. this._evalTextSize();
  14828. if (this._checkEnabledViewportOrNot())
  14829. this._clipPoint || (this._clipPoint = new Point(0, 0));
  14830. else
  14831. this._clipPoint = null;
  14832. this._renderText();
  14833. }
  14834. _evalTextSize() {
  14835. var nw, nh;
  14836. nw = Math.max.apply(this, this._lineWidths);
  14837. if (this._style.currBitmapFont)
  14838. nh = this._lines.length * (this._style.currBitmapFont.getMaxHeight() + this.leading) + this.padding[0] + this.padding[2];
  14839. else
  14840. nh = this._lines.length * (this._charSize.height + this.leading) + this.padding[0] + this.padding[2];
  14841. if (nw != this._textWidth || nh != this._textHeight) {
  14842. this._textWidth = nw;
  14843. this._textHeight = nh;
  14844. }
  14845. }
  14846. _checkEnabledViewportOrNot() {
  14847. return this.overflow == Text.SCROLL && ((this._width > 0 && this._textWidth > this._width) || (this._height > 0 && this._textHeight > this._height));
  14848. }
  14849. changeText(text) {
  14850. if (this._text !== text) {
  14851. this.lang(text + "");
  14852. if (this._graphics && this._graphics.replaceText(this._text)) ;
  14853. else {
  14854. this.typeset();
  14855. }
  14856. }
  14857. }
  14858. _parseLines(text) {
  14859. var needWordWrapOrTruncate = this.wordWrap || this.overflow == Text.HIDDEN;
  14860. if (needWordWrapOrTruncate) {
  14861. var wordWrapWidth = this._getWordWrapWidth();
  14862. }
  14863. var bitmapFont = this._style.currBitmapFont;
  14864. if (bitmapFont) {
  14865. this._charSize.width = bitmapFont.getMaxWidth();
  14866. this._charSize.height = bitmapFont.getMaxHeight();
  14867. }
  14868. else {
  14869. var measureResult = null;
  14870. if (ILaya.Render.isConchApp) {
  14871. measureResult = window.conchTextCanvas.measureText(Text._testWord);
  14872. }
  14873. else {
  14874. measureResult = ILaya.Browser.context.measureText(Text._testWord);
  14875. }
  14876. if (!measureResult)
  14877. measureResult = { width: 100 };
  14878. this._charSize.width = measureResult.width;
  14879. this._charSize.height = (measureResult.height || this.fontSize);
  14880. }
  14881. var lines = text.replace(/\r\n/g, "\n").split("\n");
  14882. for (var i = 0, n = lines.length; i < n; i++) {
  14883. var line = lines[i];
  14884. if (needWordWrapOrTruncate)
  14885. this._parseLine(line, wordWrapWidth);
  14886. else {
  14887. this._lineWidths.push(this._getTextWidth(line));
  14888. this._lines.push(line);
  14889. }
  14890. }
  14891. }
  14892. _parseLine(line, wordWrapWidth) {
  14893. var lines = this._lines;
  14894. var maybeIndex = 0;
  14895. var charsWidth = 0;
  14896. var wordWidth = 0;
  14897. var startIndex = 0;
  14898. charsWidth = this._getTextWidth(line);
  14899. if (charsWidth <= wordWrapWidth) {
  14900. lines.push(line);
  14901. this._lineWidths.push(charsWidth);
  14902. return;
  14903. }
  14904. charsWidth = this._charSize.width;
  14905. maybeIndex = Math.floor(wordWrapWidth / charsWidth);
  14906. (maybeIndex == 0) && (maybeIndex = 1);
  14907. charsWidth = this._getTextWidth(line.substring(0, maybeIndex));
  14908. wordWidth = charsWidth;
  14909. for (var j = maybeIndex, m = line.length; j < m; j++) {
  14910. charsWidth = this._getTextWidth(line.charAt(j));
  14911. wordWidth += charsWidth;
  14912. if (wordWidth > wordWrapWidth) {
  14913. if (this.wordWrap) {
  14914. var newLine = line.substring(startIndex, j);
  14915. if (newLine.charCodeAt(newLine.length - 1) < 255) {
  14916. var execResult = /(?:\w|-)+$/.exec(newLine);
  14917. if (execResult) {
  14918. j = execResult.index + startIndex;
  14919. if (execResult.index == 0)
  14920. j += newLine.length;
  14921. else
  14922. newLine = line.substring(startIndex, j);
  14923. }
  14924. }
  14925. lines.push(newLine);
  14926. this._lineWidths.push(wordWidth - charsWidth);
  14927. startIndex = j;
  14928. if (j + maybeIndex < m) {
  14929. j += maybeIndex;
  14930. charsWidth = this._getTextWidth(line.substring(startIndex, j));
  14931. wordWidth = charsWidth;
  14932. j--;
  14933. }
  14934. else {
  14935. lines.push(line.substring(startIndex, m));
  14936. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14937. startIndex = -1;
  14938. break;
  14939. }
  14940. }
  14941. else if (this.overflow == Text.HIDDEN) {
  14942. lines.push(line.substring(0, j));
  14943. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14944. return;
  14945. }
  14946. }
  14947. }
  14948. if (this.wordWrap && startIndex != -1) {
  14949. lines.push(line.substring(startIndex, m));
  14950. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14951. }
  14952. }
  14953. _getTextWidth(text) {
  14954. var bitmapFont = this._style.currBitmapFont;
  14955. if (bitmapFont)
  14956. return bitmapFont.getTextWidth(text);
  14957. else {
  14958. if (ILaya.Render.isConchApp) {
  14959. return window.conchTextCanvas.measureText(text).width;
  14960. }
  14961. else {
  14962. let ret = ILaya.Browser.context.measureText(text) || { width: 100 };
  14963. return ret.width;
  14964. }
  14965. }
  14966. }
  14967. _getWordWrapWidth() {
  14968. var p = this.padding;
  14969. var w;
  14970. var bitmapFont = this._style.currBitmapFont;
  14971. if (bitmapFont && bitmapFont.autoScaleSize)
  14972. w = this._width * (bitmapFont.fontSize / this.fontSize);
  14973. else
  14974. w = this._width;
  14975. if (w <= 0) {
  14976. w = this.wordWrap ? 100 : ILaya.Browser.width;
  14977. }
  14978. w <= 0 && (w = 100);
  14979. return w - p[3] - p[1];
  14980. }
  14981. getCharPoint(charIndex, out = null) {
  14982. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14983. var len = 0, lines = this._lines, startIndex = 0;
  14984. for (var i = 0, n = lines.length; i < n; i++) {
  14985. len += lines[i].length;
  14986. if (charIndex < len) {
  14987. var line = i;
  14988. break;
  14989. }
  14990. startIndex = len;
  14991. }
  14992. var ctxFont = (this.italic ? "italic " : "") + (this.bold ? "bold " : "") + this.fontSize + "px " + this.font;
  14993. ILaya.Browser.context.font = ctxFont;
  14994. var width = this._getTextWidth(this._text.substring(startIndex, charIndex));
  14995. var point = out || new Point();
  14996. return point.setTo(this._startX + width - (this._clipPoint ? this._clipPoint.x : 0), this._startY + line * (this._charSize.height + this.leading) - (this._clipPoint ? this._clipPoint.y : 0));
  14997. }
  14998. set scrollX(value) {
  14999. if (this.overflow != Text.SCROLL || (this.textWidth < this._width || !this._clipPoint))
  15000. return;
  15001. value = value < this.padding[3] ? this.padding[3] : value;
  15002. var maxScrollX = this._textWidth - this._width;
  15003. value = value > maxScrollX ? maxScrollX : value;
  15004. this._clipPoint.x = value;
  15005. this._renderText();
  15006. }
  15007. get scrollX() {
  15008. if (!this._clipPoint)
  15009. return 0;
  15010. return this._clipPoint.x;
  15011. }
  15012. set scrollY(value) {
  15013. if (this.overflow != Text.SCROLL || (this.textHeight < this._height || !this._clipPoint))
  15014. return;
  15015. value = value < this.padding[0] ? this.padding[0] : value;
  15016. var maxScrollY = this._textHeight - this._height;
  15017. value = value > maxScrollY ? maxScrollY : value;
  15018. this._clipPoint.y = value;
  15019. this._renderText();
  15020. }
  15021. get scrollY() {
  15022. if (!this._clipPoint)
  15023. return 0;
  15024. return this._clipPoint.y;
  15025. }
  15026. get maxScrollX() {
  15027. return (this.textWidth < this._width) ? 0 : this._textWidth - this._width;
  15028. }
  15029. get maxScrollY() {
  15030. return (this.textHeight < this._height) ? 0 : this._textHeight - this._height;
  15031. }
  15032. get lines() {
  15033. if (this._isChanged)
  15034. this.typeset();
  15035. return this._lines;
  15036. }
  15037. get underlineColor() {
  15038. return this._style.underlineColor;
  15039. }
  15040. set underlineColor(value) {
  15041. this._getTextStyle().underlineColor = value;
  15042. if (!this._isChanged)
  15043. this._renderText();
  15044. }
  15045. get underline() {
  15046. return this._style.underline;
  15047. }
  15048. set underline(value) {
  15049. this._getTextStyle().underline = value;
  15050. }
  15051. set singleCharRender(value) {
  15052. this._singleCharRender = value;
  15053. }
  15054. get singleCharRender() {
  15055. return this._singleCharRender;
  15056. }
  15057. }
  15058. Text.VISIBLE = "visible";
  15059. Text.SCROLL = "scroll";
  15060. Text.HIDDEN = "hidden";
  15061. Text.defaultFontSize = 12;
  15062. Text.defaultFont = "Arial";
  15063. Text.isComplexText = false;
  15064. Text.fontFamilyMap = { "报隶": "报隶-简", "黑体": "黑体-简", "楷体": "楷体-简", "兰亭黑": "兰亭黑-简", "隶变": "隶变-简", "凌慧体": "凌慧体-简", "翩翩体": "翩翩体-简", "苹方": "苹方-简", "手札体": "手札体-简", "宋体": "宋体-简", "娃娃体": "娃娃体-简", "魏碑": "魏碑-简", "行楷": "行楷-简", "雅痞": "雅痞-简", "圆体": "圆体-简" };
  15065. Text._testWord = "游";
  15066. Text.CharacterCache = true;
  15067. Text.RightToLeft = false;
  15068. ILaya.regClass(Text);
  15069. ClassUtils.regClass("laya.display.Text", Text);
  15070. ClassUtils.regClass("Laya.Text", Text);
  15071. class Input extends Text {
  15072. constructor() {
  15073. super();
  15074. this._multiline = false;
  15075. this._editable = true;
  15076. this._maxChars = 1E5;
  15077. this._type = "text";
  15078. this._prompt = '';
  15079. this._promptColor = "#A9A9A9";
  15080. this._originColor = "#000000";
  15081. this._content = '';
  15082. Input.IOS_IFRAME = (ILaya.Browser.onIOS && ILaya.Browser.window.top != ILaya.Browser.window.self);
  15083. this._width = 100;
  15084. this._height = 20;
  15085. this.multiline = false;
  15086. this.overflow = Text.SCROLL;
  15087. this.on(Event.MOUSE_DOWN, this, this._onMouseDown);
  15088. this.on(Event.UNDISPLAY, this, this._onUnDisplay);
  15089. }
  15090. static __init__() {
  15091. Input._createInputElement();
  15092. if (ILaya.Browser.onMobile) {
  15093. var isTrue = false;
  15094. if (ILaya.Browser.onMiniGame || ILaya.Browser.onBDMiniGame || ILaya.Browser.onQGMiniGame || ILaya.Browser.onKGMiniGame || ILaya.Browser.onVVMiniGame || ILaya.Browser.onAlipayMiniGame || ILaya.Browser.onQQMiniGame || ILaya.Browser.onBLMiniGame || ILaya.Browser.onTTMiniGame || ILaya.Browser.onHWMiniGame) {
  15095. isTrue = true;
  15096. }
  15097. ILaya.Render.canvas.addEventListener(Input.IOS_IFRAME ? (isTrue ? "touchend" : "click") : "touchend", Input._popupInputMethod);
  15098. }
  15099. }
  15100. static _popupInputMethod(e) {
  15101. if (!Input.isInputting)
  15102. return;
  15103. var input = Input.inputElement;
  15104. input.focus();
  15105. }
  15106. static _createInputElement() {
  15107. Input._initInput(Input.area = ILaya.Browser.createElement("textarea"));
  15108. Input._initInput(Input.input = ILaya.Browser.createElement("input"));
  15109. Input.inputContainer = ILaya.Browser.createElement("div");
  15110. Input.inputContainer.style.position = "absolute";
  15111. Input.inputContainer.style.zIndex = 1E5;
  15112. ILaya.Browser.container.appendChild(Input.inputContainer);
  15113. Input.inputContainer.setPos = function (x, y) {
  15114. Input.inputContainer.style.left = x + 'px';
  15115. Input.inputContainer.style.top = y + 'px';
  15116. };
  15117. }
  15118. static _initInput(input) {
  15119. var style = input.style;
  15120. style.cssText = "position:absolute;overflow:hidden;resize:none;transform-origin:0 0;-webkit-transform-origin:0 0;-moz-transform-origin:0 0;-o-transform-origin:0 0;";
  15121. style.resize = 'none';
  15122. style.backgroundColor = 'transparent';
  15123. style.border = 'none';
  15124. style.outline = 'none';
  15125. style.zIndex = 1;
  15126. input.addEventListener('input', Input._processInputting);
  15127. input.addEventListener('mousemove', Input._stopEvent);
  15128. input.addEventListener('mousedown', Input._stopEvent);
  15129. input.addEventListener('touchmove', Input._stopEvent);
  15130. input.setFontFace = function (fontFace) { input.style.fontFamily = fontFace; };
  15131. if (!ILaya.Render.isConchApp) {
  15132. input.setColor = function (color) { input.style.color = color; };
  15133. input.setFontSize = function (fontSize) { input.style.fontSize = fontSize + 'px'; };
  15134. }
  15135. }
  15136. static _processInputting(e) {
  15137. var input = Input.inputElement.target;
  15138. if (!input)
  15139. return;
  15140. var value = Input.inputElement.value;
  15141. if (input._restrictPattern) {
  15142. value = value.replace(/\u2006|\x27/g, "");
  15143. if (input._restrictPattern.test(value)) {
  15144. value = value.replace(input._restrictPattern, "");
  15145. Input.inputElement.value = value;
  15146. }
  15147. }
  15148. input._text = value;
  15149. input.event(Event.INPUT);
  15150. }
  15151. static _stopEvent(e) {
  15152. if (e.type == 'touchmove')
  15153. e.preventDefault();
  15154. e.stopPropagation && e.stopPropagation();
  15155. }
  15156. setSelection(startIndex, endIndex) {
  15157. this.focus = true;
  15158. Input.inputElement.selectionStart = startIndex;
  15159. Input.inputElement.selectionEnd = endIndex;
  15160. }
  15161. get multiline() {
  15162. return this._multiline;
  15163. }
  15164. set multiline(value) {
  15165. this._multiline = value;
  15166. this.valign = value ? "top" : "middle";
  15167. }
  15168. get nativeInput() {
  15169. return this._multiline ? Input.area : Input.input;
  15170. }
  15171. _onUnDisplay(e = null) {
  15172. this.focus = false;
  15173. }
  15174. _onMouseDown(e) {
  15175. this.focus = true;
  15176. }
  15177. _syncInputTransform() {
  15178. var inputElement = this.nativeInput;
  15179. var transform = Utils.getTransformRelativeToWindow(this, this.padding[3], this.padding[0]);
  15180. var inputWid = this._width - this.padding[1] - this.padding[3];
  15181. var inputHei = this._height - this.padding[0] - this.padding[2];
  15182. if (ILaya.Render.isConchApp) {
  15183. inputElement.setScale(transform.scaleX, transform.scaleY);
  15184. inputElement.setSize(inputWid, inputHei);
  15185. inputElement.setPos(transform.x, transform.y);
  15186. }
  15187. else {
  15188. Input.inputContainer.style.transform = Input.inputContainer.style.webkitTransform = "scale(" + transform.scaleX + "," + transform.scaleY + ") rotate(" + (ILaya.stage.canvasDegree) + "deg)";
  15189. inputElement.style.width = inputWid + 'px';
  15190. inputElement.style.height = inputHei + 'px';
  15191. Input.inputContainer.style.left = transform.x + 'px';
  15192. Input.inputContainer.style.top = transform.y + 'px';
  15193. }
  15194. }
  15195. select() {
  15196. this.nativeInput.select();
  15197. }
  15198. get focus() {
  15199. return this._focus;
  15200. }
  15201. set focus(value) {
  15202. var input = this.nativeInput;
  15203. if (this._focus !== value) {
  15204. if (value) {
  15205. if (input.target) {
  15206. input.target._focusOut();
  15207. }
  15208. else {
  15209. this._setInputMethod();
  15210. }
  15211. input.target = this;
  15212. this._focusIn();
  15213. }
  15214. else {
  15215. input.target = null;
  15216. this._focusOut();
  15217. ILaya.Browser.document.body.scrollTop = 0;
  15218. input.blur();
  15219. if (ILaya.Render.isConchApp)
  15220. input.setPos(-10000, -10000);
  15221. else if (Input.inputContainer.contains(input))
  15222. Input.inputContainer.removeChild(input);
  15223. }
  15224. }
  15225. }
  15226. _setInputMethod() {
  15227. Input.input.parentElement && (Input.inputContainer.removeChild(Input.input));
  15228. Input.area.parentElement && (Input.inputContainer.removeChild(Input.area));
  15229. Input.inputElement = (this._multiline ? Input.area : Input.input);
  15230. Input.inputContainer.appendChild(Input.inputElement);
  15231. if (Text.RightToLeft) {
  15232. Input.inputElement.style.direction = "rtl";
  15233. }
  15234. }
  15235. _focusIn() {
  15236. Input.isInputting = true;
  15237. var input = this.nativeInput;
  15238. this._focus = true;
  15239. var cssStyle = input.style;
  15240. cssStyle.whiteSpace = (this.wordWrap ? "pre-wrap" : "nowrap");
  15241. this._setPromptColor();
  15242. input.readOnly = !this._editable;
  15243. if (ILaya.Render.isConchApp) {
  15244. input.setType(this._type);
  15245. input.setForbidEdit(!this._editable);
  15246. }
  15247. input.maxLength = this._maxChars;
  15248. var padding = this.padding;
  15249. input.value = this._content;
  15250. input.placeholder = this._prompt;
  15251. ILaya.stage.off(Event.KEY_DOWN, this, this._onKeyDown);
  15252. ILaya.stage.on(Event.KEY_DOWN, this, this._onKeyDown);
  15253. ILaya.stage.focus = this;
  15254. this.event(Event.FOCUS);
  15255. if (ILaya.Browser.onPC)
  15256. input.focus();
  15257. if (!ILaya.Browser.onMiniGame && !ILaya.Browser.onBDMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame && !ILaya.Browser.onBLMiniGame && !ILaya.Browser.onTTMiniGame && !ILaya.Browser.onHWMiniGame) {
  15258. var temp = this._text;
  15259. this._text = null;
  15260. }
  15261. this.typeset();
  15262. input.setColor(this._originColor);
  15263. input.setFontSize(this.fontSize);
  15264. input.setFontFace(ILaya.Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font) : this.font);
  15265. if (ILaya.Render.isConchApp) {
  15266. input.setMultiAble && input.setMultiAble(this._multiline);
  15267. }
  15268. cssStyle.lineHeight = (this.leading + this.fontSize) + "px";
  15269. cssStyle.fontStyle = (this.italic ? "italic" : "normal");
  15270. cssStyle.fontWeight = (this.bold ? "bold" : "normal");
  15271. cssStyle.textAlign = this.align;
  15272. cssStyle.padding = "0 0";
  15273. this._syncInputTransform();
  15274. if (!ILaya.Render.isConchApp && ILaya.Browser.onPC)
  15275. ILaya.systemTimer.frameLoop(1, this, this._syncInputTransform);
  15276. }
  15277. _setPromptColor() {
  15278. Input.promptStyleDOM = ILaya.Browser.getElementById("promptStyle");
  15279. if (!Input.promptStyleDOM) {
  15280. Input.promptStyleDOM = ILaya.Browser.createElement("style");
  15281. Input.promptStyleDOM.setAttribute("id", "promptStyle");
  15282. ILaya.Browser.document.head.appendChild(Input.promptStyleDOM);
  15283. }
  15284. Input.promptStyleDOM.innerText = "input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {" + "color:" + this._promptColor + "}" + "input:-moz-placeholder, textarea:-moz-placeholder {" + "color:" + this._promptColor + "}" + "input::-moz-placeholder, textarea::-moz-placeholder {" + "color:" + this._promptColor + "}" + "input:-ms-input-placeholder, textarea:-ms-input-placeholder {" + "color:" + this._promptColor + "}";
  15285. }
  15286. _focusOut() {
  15287. if (!Input.isInputting)
  15288. return;
  15289. Input.isInputting = false;
  15290. this._focus = false;
  15291. this._text = null;
  15292. this._content = this.nativeInput.value;
  15293. if (!this._content) {
  15294. super.set_text(this._prompt);
  15295. super.set_color(this._promptColor);
  15296. }
  15297. else {
  15298. super.set_text(this._content);
  15299. super.set_color(this._originColor);
  15300. }
  15301. ILaya.stage.off(Event.KEY_DOWN, this, this._onKeyDown);
  15302. ILaya.stage.focus = null;
  15303. this.event(Event.BLUR);
  15304. this.event(Event.CHANGE);
  15305. if (ILaya.Render.isConchApp)
  15306. this.nativeInput.blur();
  15307. ILaya.Browser.onPC && ILaya.systemTimer.clear(this, this._syncInputTransform);
  15308. }
  15309. _onKeyDown(e) {
  15310. if (e.keyCode === 13) {
  15311. if (ILaya.Browser.onMobile && !this._multiline)
  15312. this.focus = false;
  15313. this.event(Event.ENTER);
  15314. }
  15315. }
  15316. set text(value) {
  15317. super.set_color(this._originColor);
  15318. value += '';
  15319. if (this._focus) {
  15320. this.nativeInput.value = value || '';
  15321. this.event(Event.CHANGE);
  15322. }
  15323. else {
  15324. if (!this._multiline)
  15325. value = value.replace(/\r?\n/g, '');
  15326. this._content = value;
  15327. if (value)
  15328. super.set_text(value);
  15329. else {
  15330. super.set_text(this._prompt);
  15331. super.set_color(this.promptColor);
  15332. }
  15333. }
  15334. }
  15335. get text() {
  15336. if (this._focus)
  15337. return this.nativeInput.value;
  15338. else
  15339. return this._content || "";
  15340. }
  15341. changeText(text) {
  15342. this._content = text;
  15343. if (this._focus) {
  15344. this.nativeInput.value = text || '';
  15345. this.event(Event.CHANGE);
  15346. }
  15347. else
  15348. super.changeText(text);
  15349. }
  15350. set color(value) {
  15351. if (this._focus)
  15352. this.nativeInput.setColor(value);
  15353. super.set_color(this._content ? value : this._promptColor);
  15354. this._originColor = value;
  15355. }
  15356. get color() {
  15357. return super.color;
  15358. }
  15359. set bgColor(value) {
  15360. super.set_bgColor(value);
  15361. if (ILaya.Render.isConchApp)
  15362. this.nativeInput.setBgColor(value);
  15363. }
  15364. get bgColor() {
  15365. return super.bgColor;
  15366. }
  15367. get restrict() {
  15368. if (this._restrictPattern) {
  15369. return this._restrictPattern.source;
  15370. }
  15371. return "";
  15372. }
  15373. set restrict(pattern) {
  15374. if (pattern) {
  15375. pattern = "[^" + pattern + "]";
  15376. if (pattern.indexOf("^^") > -1)
  15377. pattern = pattern.replace("^^", "");
  15378. this._restrictPattern = new RegExp(pattern, "g");
  15379. }
  15380. else
  15381. this._restrictPattern = null;
  15382. }
  15383. set editable(value) {
  15384. this._editable = value;
  15385. if (ILaya.Render.isConchApp) {
  15386. Input.input.setForbidEdit(!value);
  15387. }
  15388. }
  15389. get editable() {
  15390. return this._editable;
  15391. }
  15392. get maxChars() {
  15393. return this._maxChars;
  15394. }
  15395. set maxChars(value) {
  15396. if (value <= 0)
  15397. value = 1E5;
  15398. this._maxChars = value;
  15399. }
  15400. get prompt() {
  15401. return this._prompt;
  15402. }
  15403. set prompt(value) {
  15404. if (!this._text && value)
  15405. super.set_color(this._promptColor);
  15406. this.promptColor = this._promptColor;
  15407. if (this._text)
  15408. super.set_text((this._text == this._prompt) ? value : this._text);
  15409. else
  15410. super.set_text(value);
  15411. this._prompt = Text.langPacks && Text.langPacks[value] ? Text.langPacks[value] : value;
  15412. }
  15413. get promptColor() {
  15414. return this._promptColor;
  15415. }
  15416. set promptColor(value) {
  15417. this._promptColor = value;
  15418. if (!this._content)
  15419. super.set_color(value);
  15420. }
  15421. get type() {
  15422. return this._type;
  15423. }
  15424. set type(value) {
  15425. if (value === "password")
  15426. this._getTextStyle().asPassword = true;
  15427. else
  15428. this._getTextStyle().asPassword = false;
  15429. this._type = value;
  15430. }
  15431. }
  15432. Input.TYPE_TEXT = "text";
  15433. Input.TYPE_PASSWORD = "password";
  15434. Input.TYPE_EMAIL = "email";
  15435. Input.TYPE_URL = "url";
  15436. Input.TYPE_NUMBER = "number";
  15437. Input.TYPE_RANGE = "range";
  15438. Input.TYPE_DATE = "date";
  15439. Input.TYPE_MONTH = "month";
  15440. Input.TYPE_WEEK = "week";
  15441. Input.TYPE_TIME = "time";
  15442. Input.TYPE_DATE_TIME = "datetime";
  15443. Input.TYPE_DATE_TIME_LOCAL = "datetime-local";
  15444. Input.TYPE_SEARCH = "search";
  15445. Input.IOS_IFRAME = false;
  15446. Input.inputHeight = 45;
  15447. Input.isInputting = false;
  15448. ClassUtils.regClass("laya.display.Input", Input);
  15449. ClassUtils.regClass("Laya.Input", Input);
  15450. class TouchManager {
  15451. constructor() {
  15452. this.preOvers = [];
  15453. this.preDowns = [];
  15454. this.preRightDowns = [];
  15455. this.enable = true;
  15456. this._event = new Event();
  15457. this._lastClickTime = 0;
  15458. }
  15459. _clearTempArrs() {
  15460. TouchManager._oldArr.length = 0;
  15461. TouchManager._newArr.length = 0;
  15462. TouchManager._tEleArr.length = 0;
  15463. }
  15464. getTouchFromArr(touchID, arr) {
  15465. var i, len;
  15466. len = arr.length;
  15467. var tTouchO;
  15468. for (i = 0; i < len; i++) {
  15469. tTouchO = arr[i];
  15470. if (tTouchO.id == touchID) {
  15471. return tTouchO;
  15472. }
  15473. }
  15474. return null;
  15475. }
  15476. removeTouchFromArr(touchID, arr) {
  15477. var i;
  15478. for (i = arr.length - 1; i >= 0; i--) {
  15479. if (arr[i].id == touchID) {
  15480. arr.splice(i, 1);
  15481. }
  15482. }
  15483. }
  15484. createTouchO(ele, touchID) {
  15485. var rst;
  15486. rst = Pool.getItem("TouchData") || {};
  15487. rst.id = touchID;
  15488. rst.tar = ele;
  15489. return rst;
  15490. }
  15491. onMouseDown(ele, touchID, isLeft = false) {
  15492. if (!this.enable)
  15493. return;
  15494. var preO;
  15495. var tO;
  15496. var arrs;
  15497. preO = this.getTouchFromArr(touchID, this.preOvers);
  15498. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15499. if (!preO) {
  15500. tO = this.createTouchO(ele, touchID);
  15501. this.preOvers.push(tO);
  15502. }
  15503. else {
  15504. preO.tar = ele;
  15505. }
  15506. if (Browser.onMobile)
  15507. this.sendEvents(arrs, Event.MOUSE_OVER);
  15508. var preDowns;
  15509. preDowns = isLeft ? this.preDowns : this.preRightDowns;
  15510. preO = this.getTouchFromArr(touchID, preDowns);
  15511. if (!preO) {
  15512. tO = this.createTouchO(ele, touchID);
  15513. preDowns.push(tO);
  15514. }
  15515. else {
  15516. preO.tar = ele;
  15517. }
  15518. this.sendEvents(arrs, isLeft ? Event.MOUSE_DOWN : Event.RIGHT_MOUSE_DOWN);
  15519. this._clearTempArrs();
  15520. }
  15521. sendEvents(eles, type) {
  15522. var i, len;
  15523. len = eles.length;
  15524. this._event._stoped = false;
  15525. var _target;
  15526. _target = eles[0];
  15527. for (i = 0; i < len; i++) {
  15528. var tE = eles[i];
  15529. if (tE.destroyed)
  15530. return;
  15531. tE.event(type, this._event.setTo(type, tE, _target));
  15532. if (this._event._stoped)
  15533. break;
  15534. }
  15535. }
  15536. getEles(start, end = null, rst = null) {
  15537. if (!rst) {
  15538. rst = [];
  15539. }
  15540. else {
  15541. rst.length = 0;
  15542. }
  15543. while (start && start != end) {
  15544. rst.push(start);
  15545. start = start.parent;
  15546. }
  15547. return rst;
  15548. }
  15549. checkMouseOutAndOverOfMove(eleNew, elePre, touchID = 0) {
  15550. if (elePre == eleNew)
  15551. return;
  15552. var tar;
  15553. var arrs;
  15554. var i, len;
  15555. if (elePre.contains(eleNew)) {
  15556. arrs = this.getEles(eleNew, elePre, TouchManager._tEleArr);
  15557. this.sendEvents(arrs, Event.MOUSE_OVER);
  15558. }
  15559. else if (eleNew.contains(elePre)) {
  15560. arrs = this.getEles(elePre, eleNew, TouchManager._tEleArr);
  15561. this.sendEvents(arrs, Event.MOUSE_OUT);
  15562. }
  15563. else {
  15564. arrs = TouchManager._tEleArr;
  15565. arrs.length = 0;
  15566. var oldArr;
  15567. oldArr = this.getEles(elePre, null, TouchManager._oldArr);
  15568. var newArr;
  15569. newArr = this.getEles(eleNew, null, TouchManager._newArr);
  15570. len = oldArr.length;
  15571. var tIndex;
  15572. for (i = 0; i < len; i++) {
  15573. tar = oldArr[i];
  15574. tIndex = newArr.indexOf(tar);
  15575. if (tIndex >= 0) {
  15576. newArr.splice(tIndex, newArr.length - tIndex);
  15577. break;
  15578. }
  15579. else {
  15580. arrs.push(tar);
  15581. }
  15582. }
  15583. if (arrs.length > 0) {
  15584. this.sendEvents(arrs, Event.MOUSE_OUT);
  15585. }
  15586. if (newArr.length > 0) {
  15587. this.sendEvents(newArr, Event.MOUSE_OVER);
  15588. }
  15589. }
  15590. }
  15591. onMouseMove(ele, touchID) {
  15592. if (!this.enable)
  15593. return;
  15594. var preO;
  15595. preO = this.getTouchFromArr(touchID, this.preOvers);
  15596. var arrs;
  15597. if (!preO) {
  15598. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15599. this.sendEvents(arrs, Event.MOUSE_OVER);
  15600. this.preOvers.push(this.createTouchO(ele, touchID));
  15601. }
  15602. else {
  15603. this.checkMouseOutAndOverOfMove(ele, preO.tar);
  15604. preO.tar = ele;
  15605. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15606. }
  15607. this.sendEvents(arrs, Event.MOUSE_MOVE);
  15608. this._clearTempArrs();
  15609. }
  15610. getLastOvers() {
  15611. TouchManager._tEleArr.length = 0;
  15612. if (this.preOvers.length > 0 && this.preOvers[0].tar) {
  15613. return this.getEles(this.preOvers[0].tar, null, TouchManager._tEleArr);
  15614. }
  15615. TouchManager._tEleArr.push(ILaya.stage);
  15616. return TouchManager._tEleArr;
  15617. }
  15618. stageMouseOut() {
  15619. var lastOvers;
  15620. lastOvers = this.getLastOvers();
  15621. this.preOvers.length = 0;
  15622. this.sendEvents(lastOvers, Event.MOUSE_OUT);
  15623. }
  15624. onMouseUp(ele, touchID, isLeft = false) {
  15625. if (!this.enable)
  15626. return;
  15627. var preO;
  15628. var arrs;
  15629. var oldArr;
  15630. var i, len;
  15631. var tar;
  15632. var sendArr;
  15633. var onMobile = Browser.onMobile;
  15634. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15635. this.sendEvents(arrs, isLeft ? Event.MOUSE_UP : Event.RIGHT_MOUSE_UP);
  15636. var preDowns;
  15637. preDowns = isLeft ? this.preDowns : this.preRightDowns;
  15638. preO = this.getTouchFromArr(touchID, preDowns);
  15639. if (!preO) ;
  15640. else {
  15641. var isDouble;
  15642. var now = Browser.now();
  15643. isDouble = now - this._lastClickTime < 300;
  15644. this._lastClickTime = now;
  15645. if (ele == preO.tar) {
  15646. sendArr = arrs;
  15647. }
  15648. else {
  15649. oldArr = this.getEles(preO.tar, null, TouchManager._oldArr);
  15650. sendArr = TouchManager._newArr;
  15651. sendArr.length = 0;
  15652. len = oldArr.length;
  15653. for (i = 0; i < len; i++) {
  15654. tar = oldArr[i];
  15655. if (arrs.indexOf(tar) >= 0) {
  15656. sendArr.push(tar);
  15657. }
  15658. }
  15659. }
  15660. if (sendArr.length > 0) {
  15661. this.sendEvents(sendArr, isLeft ? Event.CLICK : Event.RIGHT_CLICK);
  15662. }
  15663. if (isLeft && isDouble) {
  15664. this.sendEvents(sendArr, Event.DOUBLE_CLICK);
  15665. }
  15666. this.removeTouchFromArr(touchID, preDowns);
  15667. preO.tar = null;
  15668. Pool.recover("TouchData", preO);
  15669. }
  15670. preO = this.getTouchFromArr(touchID, this.preOvers);
  15671. if (!preO) ;
  15672. else {
  15673. if (onMobile) {
  15674. sendArr = this.getEles(preO.tar, null, sendArr);
  15675. if (sendArr && sendArr.length > 0) {
  15676. this.sendEvents(sendArr, Event.MOUSE_OUT);
  15677. }
  15678. this.removeTouchFromArr(touchID, this.preOvers);
  15679. preO.tar = null;
  15680. Pool.recover("TouchData", preO);
  15681. }
  15682. }
  15683. this._clearTempArrs();
  15684. }
  15685. }
  15686. TouchManager.I = new TouchManager();
  15687. TouchManager._oldArr = [];
  15688. TouchManager._newArr = [];
  15689. TouchManager._tEleArr = [];
  15690. class MouseManager {
  15691. constructor() {
  15692. this.mouseX = 0;
  15693. this.mouseY = 0;
  15694. this.disableMouseEvent = false;
  15695. this.mouseDownTime = 0;
  15696. this.mouseMoveAccuracy = 2;
  15697. this._event = new Event();
  15698. this._captureSp = null;
  15699. this._captureChain = [];
  15700. this._captureExlusiveMode = false;
  15701. this._hitCaputreSp = false;
  15702. this._point = new Point();
  15703. this._rect = new Rectangle();
  15704. this._lastMoveTimer = 0;
  15705. this._prePoint = new Point();
  15706. this._touchIDs = {};
  15707. this._curTouchID = NaN;
  15708. this._id = 1;
  15709. }
  15710. __init__(stage, canvas) {
  15711. this._stage = stage;
  15712. var _this = this;
  15713. canvas.oncontextmenu = function (e) {
  15714. if (MouseManager.enabled)
  15715. return false;
  15716. };
  15717. canvas.addEventListener('mousedown', function (e) {
  15718. if (MouseManager.enabled) {
  15719. if (!Browser.onIE)
  15720. (e.cancelable) && (e.preventDefault());
  15721. _this.mouseDownTime = Browser.now();
  15722. _this.runEvent(e);
  15723. }
  15724. });
  15725. canvas.addEventListener('mouseup', function (e) {
  15726. if (MouseManager.enabled) {
  15727. (e.cancelable) && (e.preventDefault());
  15728. _this.mouseDownTime = -Browser.now();
  15729. _this.runEvent(e);
  15730. }
  15731. }, true);
  15732. canvas.addEventListener('mousemove', function (e) {
  15733. if (MouseManager.enabled) {
  15734. (e.cancelable) && (e.preventDefault());
  15735. var now = Browser.now();
  15736. if (now - _this._lastMoveTimer < 10)
  15737. return;
  15738. _this._lastMoveTimer = now;
  15739. _this.runEvent(e);
  15740. }
  15741. }, true);
  15742. canvas.addEventListener("mouseout", function (e) {
  15743. if (MouseManager.enabled)
  15744. _this.runEvent(e);
  15745. });
  15746. canvas.addEventListener("mouseover", function (e) {
  15747. if (MouseManager.enabled)
  15748. _this.runEvent(e);
  15749. });
  15750. canvas.addEventListener("touchstart", function (e) {
  15751. if (MouseManager.enabled) {
  15752. if (!MouseManager._isFirstTouch && !Input.isInputting)
  15753. (e.cancelable) && (e.preventDefault());
  15754. _this.mouseDownTime = Browser.now();
  15755. _this.runEvent(e);
  15756. }
  15757. });
  15758. canvas.addEventListener("touchend", function (e) {
  15759. if (MouseManager.enabled) {
  15760. if (!MouseManager._isFirstTouch && !Input.isInputting)
  15761. (e.cancelable) && (e.preventDefault());
  15762. MouseManager._isFirstTouch = false;
  15763. _this.mouseDownTime = -Browser.now();
  15764. _this.runEvent(e);
  15765. }
  15766. else {
  15767. _this._curTouchID = NaN;
  15768. }
  15769. }, true);
  15770. canvas.addEventListener("touchmove", function (e) {
  15771. if (MouseManager.enabled) {
  15772. (e.cancelable) && (e.preventDefault());
  15773. _this.runEvent(e);
  15774. }
  15775. }, true);
  15776. canvas.addEventListener("touchcancel", function (e) {
  15777. if (MouseManager.enabled) {
  15778. (e.cancelable) && (e.preventDefault());
  15779. _this.runEvent(e);
  15780. }
  15781. else {
  15782. _this._curTouchID = NaN;
  15783. }
  15784. }, true);
  15785. canvas.addEventListener('mousewheel', function (e) {
  15786. if (MouseManager.enabled)
  15787. _this.runEvent(e);
  15788. });
  15789. canvas.addEventListener('DOMMouseScroll', function (e) {
  15790. if (MouseManager.enabled)
  15791. _this.runEvent(e);
  15792. });
  15793. }
  15794. initEvent(e, nativeEvent = null) {
  15795. var _this = this;
  15796. _this._event._stoped = false;
  15797. _this._event.nativeEvent = nativeEvent || e;
  15798. _this._target = null;
  15799. this._point.setTo(e.pageX || e.clientX, e.pageY || e.clientY);
  15800. if (this._stage._canvasTransform) {
  15801. this._stage._canvasTransform.invertTransformPoint(this._point);
  15802. _this.mouseX = this._point.x;
  15803. _this.mouseY = this._point.y;
  15804. }
  15805. _this._event.touchId = e.identifier || 0;
  15806. this._tTouchID = _this._event.touchId;
  15807. var evt;
  15808. evt = TouchManager.I._event;
  15809. evt._stoped = false;
  15810. evt.nativeEvent = _this._event.nativeEvent;
  15811. evt.touchId = _this._event.touchId;
  15812. }
  15813. checkMouseWheel(e) {
  15814. this._event.delta = e.wheelDelta ? e.wheelDelta * 0.025 : -e.detail;
  15815. var _lastOvers = TouchManager.I.getLastOvers();
  15816. for (var i = 0, n = _lastOvers.length; i < n; i++) {
  15817. var ele = _lastOvers[i];
  15818. ele.event(Event.MOUSE_WHEEL, this._event.setTo(Event.MOUSE_WHEEL, ele, this._target));
  15819. }
  15820. }
  15821. onMouseMove(ele) {
  15822. TouchManager.I.onMouseMove(ele, this._tTouchID);
  15823. }
  15824. onMouseDown(ele) {
  15825. if (Input.isInputting && ILaya.stage.focus && ILaya.stage.focus["focus"] && !ILaya.stage.focus.contains(this._target)) {
  15826. var pre_input = ILaya.stage.focus['_tf'] || ILaya.stage.focus;
  15827. var new_input = ele['_tf'] || ele;
  15828. if (new_input instanceof Input && new_input.multiline == pre_input.multiline)
  15829. pre_input['_focusOut']();
  15830. else
  15831. pre_input.focus = false;
  15832. }
  15833. TouchManager.I.onMouseDown(ele, this._tTouchID, this._isLeftMouse);
  15834. }
  15835. onMouseUp(ele) {
  15836. TouchManager.I.onMouseUp(ele, this._tTouchID, this._isLeftMouse);
  15837. }
  15838. check(sp, mouseX, mouseY, callBack) {
  15839. this._point.setTo(mouseX, mouseY);
  15840. sp.fromParentPoint(this._point);
  15841. mouseX = this._point.x;
  15842. mouseY = this._point.y;
  15843. var scrollRect = sp._style.scrollRect;
  15844. if (scrollRect) {
  15845. this._rect.setTo(scrollRect.x, scrollRect.y, scrollRect.width, scrollRect.height);
  15846. if (!this._rect.contains(mouseX, mouseY))
  15847. return false;
  15848. }
  15849. if (!this.disableMouseEvent) {
  15850. if (sp.hitTestPrior && !sp.mouseThrough && !this.hitTest(sp, mouseX, mouseY)) {
  15851. return false;
  15852. }
  15853. for (var i = sp._children.length - 1; i > -1; i--) {
  15854. var child = sp._children[i];
  15855. if (!child.destroyed && child._mouseState > 1 && child._visible) {
  15856. if (this.check(child, mouseX, mouseY, callBack))
  15857. return true;
  15858. }
  15859. }
  15860. for (i = sp._extUIChild.length - 1; i >= 0; i--) {
  15861. var c = sp._extUIChild[i];
  15862. if (!c.destroyed && c._mouseState > 1 && c._visible) {
  15863. if (this.check(c, mouseX, mouseY, callBack))
  15864. return true;
  15865. }
  15866. }
  15867. }
  15868. var isHit = (sp.hitTestPrior && !sp.mouseThrough && !this.disableMouseEvent) ? true : this.hitTest(sp, mouseX, mouseY);
  15869. if (isHit) {
  15870. this._target = sp;
  15871. callBack.call(this, sp);
  15872. if (this._target == this._hitCaputreSp) {
  15873. this._hitCaputreSp = true;
  15874. }
  15875. }
  15876. else if (callBack === this.onMouseUp && sp === this._stage) {
  15877. this._target = this._stage;
  15878. callBack.call(this, this._target);
  15879. }
  15880. return isHit;
  15881. }
  15882. hitTest(sp, mouseX, mouseY) {
  15883. var isHit = false;
  15884. if (sp.scrollRect) {
  15885. mouseX -= sp._style.scrollRect.x;
  15886. mouseY -= sp._style.scrollRect.y;
  15887. }
  15888. var hitArea = sp._style.hitArea;
  15889. if (hitArea && hitArea._hit) {
  15890. return hitArea.contains(mouseX, mouseY);
  15891. }
  15892. if (sp.width > 0 && sp.height > 0 || sp.mouseThrough || hitArea) {
  15893. if (!sp.mouseThrough) {
  15894. isHit = (hitArea ? hitArea : this._rect.setTo(0, 0, sp.width, sp.height)).contains(mouseX, mouseY);
  15895. }
  15896. else {
  15897. isHit = sp.getGraphicBounds().contains(mouseX, mouseY);
  15898. }
  15899. }
  15900. return isHit;
  15901. }
  15902. _checkAllBaseUI(mousex, mousey, callback) {
  15903. var ret = this.handleExclusiveCapture(this.mouseX, this.mouseY, callback);
  15904. if (ret)
  15905. return true;
  15906. ret = this.check(this._stage, this.mouseX, this.mouseY, callback);
  15907. return this.handleCapture(this.mouseX, this.mouseY, callback) || ret;
  15908. }
  15909. check3DUI(mousex, mousey, callback) {
  15910. var uis = this._stage._3dUI;
  15911. var i = 0;
  15912. var ret = false;
  15913. for (; i < uis.length; i++) {
  15914. var curui = uis[i];
  15915. this._stage._curUIBase = curui;
  15916. if (!curui.destroyed && curui._mouseState > 1 && curui._visible) {
  15917. ret = ret || this.check(curui, this.mouseX, this.mouseY, callback);
  15918. }
  15919. }
  15920. this._stage._curUIBase = this._stage;
  15921. return ret;
  15922. }
  15923. handleExclusiveCapture(mousex, mousey, callback) {
  15924. if (this._captureExlusiveMode && this._captureSp && this._captureChain.length > 0) {
  15925. var cursp;
  15926. this._point.setTo(mousex, mousey);
  15927. for (var i = 0; i < this._captureChain.length; i++) {
  15928. cursp = this._captureChain[i];
  15929. cursp.fromParentPoint(this._point);
  15930. }
  15931. this._target = cursp;
  15932. callback.call(this, cursp);
  15933. return true;
  15934. }
  15935. return false;
  15936. }
  15937. handleCapture(mousex, mousey, callback) {
  15938. if (!this._hitCaputreSp && this._captureSp && this._captureChain.length > 0) {
  15939. var cursp;
  15940. this._point.setTo(mousex, mousey);
  15941. for (var i = 0; i < this._captureChain.length; i++) {
  15942. cursp = this._captureChain[i];
  15943. cursp.fromParentPoint(this._point);
  15944. }
  15945. this._target = cursp;
  15946. callback.call(this, cursp);
  15947. return true;
  15948. }
  15949. return false;
  15950. }
  15951. runEvent(evt) {
  15952. var i, n, touch;
  15953. if (evt.type !== 'mousemove')
  15954. this._prePoint.x = this._prePoint.y = -1000000;
  15955. switch (evt.type) {
  15956. case 'mousedown':
  15957. this._touchIDs[0] = this._id++;
  15958. if (!MouseManager._isTouchRespond) {
  15959. this._isLeftMouse = evt.button === 0;
  15960. this.initEvent(evt);
  15961. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseDown);
  15962. }
  15963. else
  15964. MouseManager._isTouchRespond = false;
  15965. break;
  15966. case 'mouseup':
  15967. this._isLeftMouse = evt.button === 0;
  15968. this.initEvent(evt);
  15969. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseUp);
  15970. break;
  15971. case 'mousemove':
  15972. if ((Math.abs(this._prePoint.x - evt.clientX) + Math.abs(this._prePoint.y - evt.clientY)) >= this.mouseMoveAccuracy) {
  15973. this._prePoint.x = evt.clientX;
  15974. this._prePoint.y = evt.clientY;
  15975. this.initEvent(evt);
  15976. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseMove);
  15977. }
  15978. break;
  15979. case "touchstart":
  15980. MouseManager._isTouchRespond = true;
  15981. this._isLeftMouse = true;
  15982. var touches = evt.changedTouches;
  15983. for (i = 0, n = touches.length; i < n; i++) {
  15984. touch = touches[i];
  15985. if (MouseManager.multiTouchEnabled || isNaN(this._curTouchID)) {
  15986. this._curTouchID = touch.identifier;
  15987. if (this._id % 200 === 0)
  15988. this._touchIDs = {};
  15989. this._touchIDs[touch.identifier] = this._id++;
  15990. this.initEvent(touch, evt);
  15991. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseDown);
  15992. }
  15993. }
  15994. break;
  15995. case "touchend":
  15996. case "touchcancel":
  15997. MouseManager._isTouchRespond = true;
  15998. this._isLeftMouse = true;
  15999. var touchends = evt.changedTouches;
  16000. for (i = 0, n = touchends.length; i < n; i++) {
  16001. touch = touchends[i];
  16002. if (MouseManager.multiTouchEnabled || touch.identifier == this._curTouchID) {
  16003. this._curTouchID = NaN;
  16004. this.initEvent(touch, evt);
  16005. var isChecked;
  16006. isChecked = this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseUp);
  16007. if (!isChecked) {
  16008. this.onMouseUp(null);
  16009. }
  16010. }
  16011. }
  16012. break;
  16013. case "touchmove":
  16014. var touchemoves = evt.changedTouches;
  16015. for (i = 0, n = touchemoves.length; i < n; i++) {
  16016. touch = touchemoves[i];
  16017. if (MouseManager.multiTouchEnabled || touch.identifier == this._curTouchID) {
  16018. this.initEvent(touch, evt);
  16019. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseMove);
  16020. }
  16021. }
  16022. break;
  16023. case "wheel":
  16024. case "mousewheel":
  16025. case "DOMMouseScroll":
  16026. this.checkMouseWheel(evt);
  16027. break;
  16028. case "mouseout":
  16029. TouchManager.I.stageMouseOut();
  16030. break;
  16031. case "mouseover":
  16032. this._stage.event(Event.MOUSE_OVER, this._event.setTo(Event.MOUSE_OVER, this._stage, this._stage));
  16033. break;
  16034. }
  16035. }
  16036. setCapture(sp, exclusive = false) {
  16037. this._captureSp = sp;
  16038. this._captureExlusiveMode = exclusive;
  16039. this._captureChain.length = 0;
  16040. this._captureChain.push(sp);
  16041. var cursp = sp;
  16042. while (true) {
  16043. if (cursp == ILaya.stage)
  16044. break;
  16045. if (cursp == ILaya.stage._curUIBase)
  16046. break;
  16047. cursp = cursp.parent;
  16048. if (!cursp)
  16049. break;
  16050. this._captureChain.splice(0, 0, cursp);
  16051. }
  16052. }
  16053. releaseCapture() {
  16054. console.log('release capture');
  16055. this._captureSp = null;
  16056. }
  16057. }
  16058. MouseManager.instance = new MouseManager();
  16059. MouseManager.enabled = true;
  16060. MouseManager.multiTouchEnabled = true;
  16061. MouseManager._isFirstTouch = true;
  16062. class CallLater {
  16063. constructor() {
  16064. this._pool = [];
  16065. this._map = {};
  16066. this._laters = [];
  16067. }
  16068. _update() {
  16069. let laters = this._laters;
  16070. let len = laters.length;
  16071. if (len > 0) {
  16072. for (let i = 0, n = len - 1; i <= n; i++) {
  16073. let handler = laters[i];
  16074. this._map[handler.key] = null;
  16075. if (handler.method !== null) {
  16076. handler.run();
  16077. handler.clear();
  16078. }
  16079. this._pool.push(handler);
  16080. i === n && (n = laters.length - 1);
  16081. }
  16082. laters.length = 0;
  16083. }
  16084. }
  16085. _getHandler(caller, method) {
  16086. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  16087. var mid = method.$_TID || (method.$_TID = (ILaya.Timer._mid++));
  16088. return this._map[cid + '.' + mid];
  16089. }
  16090. callLater(caller, method, args = null) {
  16091. if (this._getHandler(caller, method) == null) {
  16092. let handler;
  16093. if (this._pool.length)
  16094. handler = this._pool.pop();
  16095. else
  16096. handler = new LaterHandler();
  16097. handler.caller = caller;
  16098. handler.method = method;
  16099. handler.args = args;
  16100. var cid = caller ? caller.$_GID : 0;
  16101. var mid = method["$_TID"];
  16102. handler.key = cid + '.' + mid;
  16103. this._map[handler.key] = handler;
  16104. this._laters.push(handler);
  16105. }
  16106. }
  16107. runCallLater(caller, method) {
  16108. var handler = this._getHandler(caller, method);
  16109. if (handler && handler.method != null) {
  16110. this._map[handler.key] = null;
  16111. handler.run();
  16112. handler.clear();
  16113. }
  16114. }
  16115. }
  16116. CallLater.I = new CallLater();
  16117. class LaterHandler {
  16118. clear() {
  16119. this.caller = null;
  16120. this.method = null;
  16121. this.args = null;
  16122. }
  16123. run() {
  16124. var caller = this.caller;
  16125. if (caller && caller.destroyed)
  16126. return this.clear();
  16127. var method = this.method;
  16128. var args = this.args;
  16129. if (method == null)
  16130. return;
  16131. args ? method.apply(caller, args) : method.call(caller);
  16132. }
  16133. }
  16134. class RunDriver {
  16135. }
  16136. RunDriver.createShaderCondition = function (conditionScript) {
  16137. var fn = "(function() {return " + conditionScript + ";})";
  16138. return window.Laya._runScript(fn);
  16139. };
  16140. RunDriver.changeWebGLSize = function (w, h) {
  16141. WebGL.onStageResize(w, h);
  16142. };
  16143. class Stage extends Sprite {
  16144. constructor() {
  16145. super();
  16146. this.offset = new Point();
  16147. this._frameRate = "fast";
  16148. this.designWidth = 0;
  16149. this.designHeight = 0;
  16150. this.canvasRotation = false;
  16151. this.canvasDegree = 0;
  16152. this.renderingEnabled = true;
  16153. this.screenAdaptationEnabled = true;
  16154. this._canvasTransform = new Matrix();
  16155. this._screenMode = "none";
  16156. this._scaleMode = "noscale";
  16157. this._alignV = "top";
  16158. this._alignH = "left";
  16159. this._bgColor = "black";
  16160. this._mouseMoveTime = 0;
  16161. this._renderCount = 0;
  16162. this._safariOffsetY = 0;
  16163. this._frameStartTime = 0;
  16164. this._previousOrientation = Browser.window.orientation;
  16165. this._wgColor = [0, 0, 0, 1];
  16166. this._scene3Ds = [];
  16167. this._globalRepaintSet = false;
  16168. this._globalRepaintGet = false;
  16169. this._3dUI = [];
  16170. this._curUIBase = null;
  16171. this.useRetinalCanvas = false;
  16172. super.set_transform(this._createTransform());
  16173. this.mouseEnabled = true;
  16174. this.hitTestPrior = true;
  16175. this.autoSize = false;
  16176. this._setBit(Const.DISPLAYED_INSTAGE, true);
  16177. this._setBit(Const.ACTIVE_INHIERARCHY, true);
  16178. this._isFocused = true;
  16179. this._isVisibility = true;
  16180. this.useRetinalCanvas = Config.useRetinalCanvas;
  16181. var window = Browser.window;
  16182. window.addEventListener("focus", () => {
  16183. this._isFocused = true;
  16184. this.event(Event.FOCUS);
  16185. this.event(Event.FOCUS_CHANGE);
  16186. });
  16187. window.addEventListener("blur", () => {
  16188. this._isFocused = false;
  16189. this.event(Event.BLUR);
  16190. this.event(Event.FOCUS_CHANGE);
  16191. if (this._isInputting())
  16192. Input["inputElement"].target.focus = false;
  16193. });
  16194. var state = "visibilityState", visibilityChange = "visibilitychange";
  16195. var document = window.document;
  16196. if (typeof document.hidden !== "undefined") {
  16197. visibilityChange = "visibilitychange";
  16198. state = "visibilityState";
  16199. }
  16200. else if (typeof document.mozHidden !== "undefined") {
  16201. visibilityChange = "mozvisibilitychange";
  16202. state = "mozVisibilityState";
  16203. }
  16204. else if (typeof document.msHidden !== "undefined") {
  16205. visibilityChange = "msvisibilitychange";
  16206. state = "msVisibilityState";
  16207. }
  16208. else if (typeof document.webkitHidden !== "undefined") {
  16209. visibilityChange = "webkitvisibilitychange";
  16210. state = "webkitVisibilityState";
  16211. }
  16212. window.document.addEventListener(visibilityChange, () => {
  16213. if (Browser.document[state] == "hidden") {
  16214. this._isVisibility = false;
  16215. if (this._isInputting())
  16216. Input["inputElement"].target.focus = false;
  16217. }
  16218. else {
  16219. this._isVisibility = true;
  16220. }
  16221. this.renderingEnabled = this._isVisibility;
  16222. this.event(Event.VISIBILITY_CHANGE);
  16223. });
  16224. window.addEventListener("resize", () => {
  16225. var orientation = Browser.window.orientation;
  16226. if (orientation != null && orientation != this._previousOrientation && this._isInputting()) {
  16227. Input["inputElement"].target.focus = false;
  16228. }
  16229. this._previousOrientation = orientation;
  16230. if (this._isInputting())
  16231. return;
  16232. if (Browser.onSafari)
  16233. this._safariOffsetY = (Browser.window.__innerHeight || Browser.document.body.clientHeight || Browser.document.documentElement.clientHeight) - Browser.window.innerHeight;
  16234. this._resetCanvas();
  16235. });
  16236. window.addEventListener("orientationchange", (e) => {
  16237. this._resetCanvas();
  16238. });
  16239. this.on(Event.MOUSE_MOVE, this, this._onmouseMove);
  16240. if (Browser.onMobile)
  16241. this.on(Event.MOUSE_DOWN, this, this._onmouseMove);
  16242. }
  16243. _isInputting() {
  16244. return (Browser.onMobile && Input.isInputting);
  16245. }
  16246. set width(value) {
  16247. this.designWidth = value;
  16248. super.set_width(value);
  16249. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16250. }
  16251. get width() {
  16252. return super.get_width();
  16253. }
  16254. set height(value) {
  16255. this.designHeight = value;
  16256. super.set_height(value);
  16257. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16258. }
  16259. get height() {
  16260. return super.get_height();
  16261. }
  16262. set transform(value) {
  16263. super.set_transform(value);
  16264. }
  16265. get transform() {
  16266. if (this._tfChanged)
  16267. this._adjustTransform();
  16268. return (this._transform = this._transform || this._createTransform());
  16269. }
  16270. get isFocused() {
  16271. return this._isFocused;
  16272. }
  16273. get isVisibility() {
  16274. return this._isVisibility;
  16275. }
  16276. _changeCanvasSize() {
  16277. this.setScreenSize(Browser.clientWidth * Browser.pixelRatio, Browser.clientHeight * Browser.pixelRatio);
  16278. }
  16279. _resetCanvas() {
  16280. if (!this.screenAdaptationEnabled)
  16281. return;
  16282. this._changeCanvasSize();
  16283. }
  16284. setScreenSize(screenWidth, screenHeight) {
  16285. var rotation = false;
  16286. if (this._screenMode !== Stage.SCREEN_NONE) {
  16287. var screenType = screenWidth / screenHeight < 1 ? Stage.SCREEN_VERTICAL : Stage.SCREEN_HORIZONTAL;
  16288. rotation = screenType !== this._screenMode;
  16289. if (rotation) {
  16290. var temp = screenHeight;
  16291. screenHeight = screenWidth;
  16292. screenWidth = temp;
  16293. }
  16294. }
  16295. this.canvasRotation = rotation;
  16296. var canvas = Render._mainCanvas;
  16297. var canvasStyle = canvas.source.style;
  16298. var mat = this._canvasTransform.identity();
  16299. var scaleMode = this._scaleMode;
  16300. var scaleX = screenWidth / this.designWidth;
  16301. var scaleY = screenHeight / this.designHeight;
  16302. var canvasWidth = this.useRetinalCanvas ? screenWidth : this.designWidth;
  16303. var canvasHeight = this.useRetinalCanvas ? screenHeight : this.designHeight;
  16304. var realWidth = screenWidth;
  16305. var realHeight = screenHeight;
  16306. var pixelRatio = Browser.pixelRatio;
  16307. this._width = this.designWidth;
  16308. this._height = this.designHeight;
  16309. switch (scaleMode) {
  16310. case Stage.SCALE_NOSCALE:
  16311. scaleX = scaleY = 1;
  16312. realWidth = this.designWidth;
  16313. realHeight = this.designHeight;
  16314. break;
  16315. case Stage.SCALE_SHOWALL:
  16316. scaleX = scaleY = Math.min(scaleX, scaleY);
  16317. canvasWidth = realWidth = Math.round(this.designWidth * scaleX);
  16318. canvasHeight = realHeight = Math.round(this.designHeight * scaleY);
  16319. break;
  16320. case Stage.SCALE_NOBORDER:
  16321. scaleX = scaleY = Math.max(scaleX, scaleY);
  16322. realWidth = Math.round(this.designWidth * scaleX);
  16323. realHeight = Math.round(this.designHeight * scaleY);
  16324. break;
  16325. case Stage.SCALE_FULL:
  16326. scaleX = scaleY = 1;
  16327. this._width = canvasWidth = screenWidth;
  16328. this._height = canvasHeight = screenHeight;
  16329. break;
  16330. case Stage.SCALE_FIXED_WIDTH:
  16331. scaleY = scaleX;
  16332. this._height = canvasHeight = Math.round(screenHeight / scaleX);
  16333. break;
  16334. case Stage.SCALE_FIXED_HEIGHT:
  16335. scaleX = scaleY;
  16336. this._width = canvasWidth = Math.round(screenWidth / scaleY);
  16337. break;
  16338. case Stage.SCALE_FIXED_AUTO:
  16339. if ((screenWidth / screenHeight) < (this.designWidth / this.designHeight)) {
  16340. scaleY = scaleX;
  16341. this._height = canvasHeight = Math.round(screenHeight / scaleX);
  16342. }
  16343. else {
  16344. scaleX = scaleY;
  16345. this._width = canvasWidth = Math.round(screenWidth / scaleY);
  16346. }
  16347. break;
  16348. }
  16349. if (this.useRetinalCanvas) {
  16350. realWidth = canvasWidth = screenWidth;
  16351. realHeight = canvasHeight = screenHeight;
  16352. }
  16353. scaleX *= this.scaleX;
  16354. scaleY *= this.scaleY;
  16355. if (scaleX === 1 && scaleY === 1) {
  16356. this.transform.identity();
  16357. }
  16358. else {
  16359. this.transform.a = this._formatData(scaleX / (realWidth / canvasWidth));
  16360. this.transform.d = this._formatData(scaleY / (realHeight / canvasHeight));
  16361. }
  16362. canvas.size(canvasWidth, canvasHeight);
  16363. RunDriver.changeWebGLSize(canvasWidth, canvasHeight);
  16364. mat.scale(realWidth / canvasWidth / pixelRatio, realHeight / canvasHeight / pixelRatio);
  16365. if (this._alignH === Stage.ALIGN_LEFT)
  16366. this.offset.x = 0;
  16367. else if (this._alignH === Stage.ALIGN_RIGHT)
  16368. this.offset.x = screenWidth - realWidth;
  16369. else
  16370. this.offset.x = (screenWidth - realWidth) * 0.5 / pixelRatio;
  16371. if (this._alignV === Stage.ALIGN_TOP)
  16372. this.offset.y = 0;
  16373. else if (this._alignV === Stage.ALIGN_BOTTOM)
  16374. this.offset.y = screenHeight - realHeight;
  16375. else
  16376. this.offset.y = (screenHeight - realHeight) * 0.5 / pixelRatio;
  16377. this.offset.x = Math.round(this.offset.x);
  16378. this.offset.y = Math.round(this.offset.y);
  16379. mat.translate(this.offset.x, this.offset.y);
  16380. if (this._safariOffsetY)
  16381. mat.translate(0, this._safariOffsetY);
  16382. this.canvasDegree = 0;
  16383. if (rotation) {
  16384. if (this._screenMode === Stage.SCREEN_HORIZONTAL) {
  16385. mat.rotate(Math.PI / 2);
  16386. mat.translate(screenHeight / pixelRatio, 0);
  16387. this.canvasDegree = 90;
  16388. }
  16389. else {
  16390. mat.rotate(-Math.PI / 2);
  16391. mat.translate(0, screenWidth / pixelRatio);
  16392. this.canvasDegree = -90;
  16393. }
  16394. }
  16395. mat.a = this._formatData(mat.a);
  16396. mat.d = this._formatData(mat.d);
  16397. mat.tx = this._formatData(mat.tx);
  16398. mat.ty = this._formatData(mat.ty);
  16399. super.set_transform(this.transform);
  16400. canvasStyle.transformOrigin = canvasStyle.webkitTransformOrigin = canvasStyle.msTransformOrigin = canvasStyle.mozTransformOrigin = canvasStyle.oTransformOrigin = "0px 0px 0px";
  16401. canvasStyle.transform = canvasStyle.webkitTransform = canvasStyle.msTransform = canvasStyle.mozTransform = canvasStyle.oTransform = "matrix(" + mat.toString() + ")";
  16402. if (this._safariOffsetY)
  16403. mat.translate(0, -this._safariOffsetY);
  16404. mat.translate(parseInt(canvasStyle.left) || 0, parseInt(canvasStyle.top) || 0);
  16405. this.visible = true;
  16406. this._repaint |= SpriteConst.REPAINT_CACHE;
  16407. this.event(Event.RESIZE);
  16408. }
  16409. _formatData(value) {
  16410. if (Math.abs(value) < 0.000001)
  16411. return 0;
  16412. if (Math.abs(1 - value) < 0.001)
  16413. return value > 0 ? 1 : -1;
  16414. return value;
  16415. }
  16416. get scaleMode() {
  16417. return this._scaleMode;
  16418. }
  16419. set scaleMode(value) {
  16420. this._scaleMode = value;
  16421. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16422. }
  16423. get alignH() {
  16424. return this._alignH;
  16425. }
  16426. set alignH(value) {
  16427. this._alignH = value;
  16428. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16429. }
  16430. get alignV() {
  16431. return this._alignV;
  16432. }
  16433. set alignV(value) {
  16434. this._alignV = value;
  16435. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16436. }
  16437. get bgColor() {
  16438. return this._bgColor;
  16439. }
  16440. set bgColor(value) {
  16441. this._bgColor = value;
  16442. if (value)
  16443. this._wgColor = ColorUtils.create(value).arrColor;
  16444. else
  16445. this._wgColor = null;
  16446. if (value) {
  16447. Render.canvas.style.background = value;
  16448. }
  16449. else {
  16450. Render.canvas.style.background = "none";
  16451. }
  16452. }
  16453. get mouseX() {
  16454. return Math.round(MouseManager.instance.mouseX / this.clientScaleX);
  16455. }
  16456. get mouseY() {
  16457. return Math.round(MouseManager.instance.mouseY / this.clientScaleY);
  16458. }
  16459. getMousePoint() {
  16460. return Point.TEMP.setTo(this.mouseX, this.mouseY);
  16461. }
  16462. get clientScaleX() {
  16463. return this._transform ? this._transform.getScaleX() : 1;
  16464. }
  16465. get clientScaleY() {
  16466. return this._transform ? this._transform.getScaleY() : 1;
  16467. }
  16468. get screenMode() {
  16469. return this._screenMode;
  16470. }
  16471. set screenMode(value) {
  16472. this._screenMode = value;
  16473. }
  16474. repaint(type = SpriteConst.REPAINT_CACHE) {
  16475. this._repaint |= type;
  16476. }
  16477. parentRepaint(type = SpriteConst.REPAINT_CACHE) {
  16478. }
  16479. _loop() {
  16480. this._globalRepaintGet = this._globalRepaintSet;
  16481. this._globalRepaintSet = false;
  16482. this.render(Render._context, 0, 0);
  16483. return true;
  16484. }
  16485. getFrameTm() {
  16486. return this._frameStartTime;
  16487. }
  16488. _onmouseMove(e) {
  16489. this._mouseMoveTime = Browser.now();
  16490. }
  16491. getTimeFromFrameStart() {
  16492. return Browser.now() - this._frameStartTime;
  16493. }
  16494. set visible(value) {
  16495. if (this.visible !== value) {
  16496. super.set_visible(value);
  16497. var style = Render._mainCanvas.source.style;
  16498. style.visibility = value ? "visible" : "hidden";
  16499. }
  16500. }
  16501. get visible() {
  16502. return super.visible;
  16503. }
  16504. render(context, x, y) {
  16505. if (window.conch) {
  16506. this.renderToNative(context, x, y);
  16507. return;
  16508. }
  16509. if (this._frameRate === Stage.FRAME_SLEEP) {
  16510. var now = Browser.now();
  16511. if (now - this._frameStartTime >= 1000)
  16512. this._frameStartTime = now;
  16513. else
  16514. return;
  16515. }
  16516. else {
  16517. if (!this._visible) {
  16518. this._renderCount++;
  16519. if (this._renderCount % 5 === 0) {
  16520. CallLater.I._update();
  16521. Stat.loopCount++;
  16522. RenderInfo.loopCount = Stat.loopCount;
  16523. this._updateTimers();
  16524. }
  16525. return;
  16526. }
  16527. this._frameStartTime = Browser.now();
  16528. RenderInfo.loopStTm = this._frameStartTime;
  16529. }
  16530. this._renderCount++;
  16531. var frameMode = this._frameRate === Stage.FRAME_MOUSE ? (((this._frameStartTime - this._mouseMoveTime) < 2000) ? Stage.FRAME_FAST : Stage.FRAME_SLOW) : this._frameRate;
  16532. var isFastMode = (frameMode !== Stage.FRAME_SLOW);
  16533. var isDoubleLoop = (this._renderCount % 2 === 0);
  16534. Stat.renderSlow = !isFastMode;
  16535. if (!isFastMode && !isDoubleLoop)
  16536. return;
  16537. CallLater.I._update();
  16538. Stat.loopCount++;
  16539. RenderInfo.loopCount = Stat.loopCount;
  16540. if (this.renderingEnabled) {
  16541. for (var i = 0, n = this._scene3Ds.length; i < n; i++)
  16542. this._scene3Ds[i]._update();
  16543. context.clear();
  16544. super.render(context, x, y);
  16545. Stat._StatRender.renderNotCanvas(context, x, y);
  16546. }
  16547. if (this.renderingEnabled) {
  16548. Stage.clear(this._bgColor);
  16549. context.flush();
  16550. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  16551. }
  16552. this._updateTimers();
  16553. }
  16554. renderToNative(context, x, y) {
  16555. this._renderCount++;
  16556. if (!this._visible) {
  16557. if (this._renderCount % 5 === 0) {
  16558. CallLater.I._update();
  16559. Stat.loopCount++;
  16560. RenderInfo.loopCount = Stat.loopCount;
  16561. this._updateTimers();
  16562. }
  16563. return;
  16564. }
  16565. CallLater.I._update();
  16566. Stat.loopCount++;
  16567. RenderInfo.loopCount = Stat.loopCount;
  16568. if (this.renderingEnabled) {
  16569. for (var i = 0, n = this._scene3Ds.length; i < n; i++)
  16570. this._scene3Ds[i]._update();
  16571. context.clear();
  16572. super.render(context, x, y);
  16573. Stat._StatRender.renderNotCanvas(context, x, y);
  16574. }
  16575. if (this.renderingEnabled) {
  16576. Stage.clear(this._bgColor);
  16577. context.flush();
  16578. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  16579. }
  16580. this._updateTimers();
  16581. }
  16582. _updateTimers() {
  16583. ILaya.systemTimer._update();
  16584. ILaya.startTimer._update();
  16585. ILaya.physicsTimer._update();
  16586. ILaya.updateTimer._update();
  16587. ILaya.lateTimer._update();
  16588. ILaya.timer._update();
  16589. }
  16590. set fullScreenEnabled(value) {
  16591. var document = Browser.document;
  16592. var canvas = Render.canvas;
  16593. if (value) {
  16594. canvas.addEventListener('mousedown', this._requestFullscreen);
  16595. canvas.addEventListener('touchstart', this._requestFullscreen);
  16596. document.addEventListener("fullscreenchange", this._fullScreenChanged);
  16597. document.addEventListener("mozfullscreenchange", this._fullScreenChanged);
  16598. document.addEventListener("webkitfullscreenchange", this._fullScreenChanged);
  16599. document.addEventListener("msfullscreenchange", this._fullScreenChanged);
  16600. }
  16601. else {
  16602. canvas.removeEventListener('mousedown', this._requestFullscreen);
  16603. canvas.removeEventListener('touchstart', this._requestFullscreen);
  16604. document.removeEventListener("fullscreenchange", this._fullScreenChanged);
  16605. document.removeEventListener("mozfullscreenchange", this._fullScreenChanged);
  16606. document.removeEventListener("webkitfullscreenchange", this._fullScreenChanged);
  16607. document.removeEventListener("msfullscreenchange", this._fullScreenChanged);
  16608. }
  16609. }
  16610. get frameRate() {
  16611. if (!ILaya.Render.isConchApp) {
  16612. return this._frameRate;
  16613. }
  16614. else {
  16615. return this._frameRateNative;
  16616. }
  16617. }
  16618. set frameRate(value) {
  16619. if (!ILaya.Render.isConchApp) {
  16620. this._frameRate = value;
  16621. }
  16622. else {
  16623. var c = window.conch;
  16624. switch (value) {
  16625. case Stage.FRAME_FAST:
  16626. c.config.setLimitFPS(60);
  16627. break;
  16628. case Stage.FRAME_MOUSE:
  16629. c.config.setMouseFrame(2000);
  16630. break;
  16631. case Stage.FRAME_SLOW:
  16632. c.config.setSlowFrame(true);
  16633. break;
  16634. case Stage.FRAME_SLEEP:
  16635. c.config.setLimitFPS(1);
  16636. break;
  16637. }
  16638. this._frameRateNative = value;
  16639. }
  16640. }
  16641. _requestFullscreen() {
  16642. var element = Browser.document.documentElement;
  16643. if (element.requestFullscreen) {
  16644. element.requestFullscreen();
  16645. }
  16646. else if (element.mozRequestFullScreen) {
  16647. element.mozRequestFullScreen();
  16648. }
  16649. else if (element.webkitRequestFullscreen) {
  16650. element.webkitRequestFullscreen();
  16651. }
  16652. else if (element.msRequestFullscreen) {
  16653. element.msRequestFullscreen();
  16654. }
  16655. }
  16656. _fullScreenChanged() {
  16657. ILaya.stage.event(Event.FULL_SCREEN_CHANGE);
  16658. }
  16659. exitFullscreen() {
  16660. var document = Browser.document;
  16661. if (document.exitFullscreen) {
  16662. document.exitFullscreen();
  16663. }
  16664. else if (document.mozCancelFullScreen) {
  16665. document.mozCancelFullScreen();
  16666. }
  16667. else if (document.webkitExitFullscreen) {
  16668. document.webkitExitFullscreen();
  16669. }
  16670. }
  16671. isGlobalRepaint() {
  16672. return this._globalRepaintGet;
  16673. }
  16674. setGlobalRepaint() {
  16675. this._globalRepaintSet = true;
  16676. }
  16677. add3DUI(uibase) {
  16678. var uiroot = uibase.rootView;
  16679. if (this._3dUI.indexOf(uiroot) >= 0)
  16680. return;
  16681. this._3dUI.push(uiroot);
  16682. }
  16683. remove3DUI(uibase) {
  16684. var uiroot = uibase.rootView;
  16685. var p = this._3dUI.indexOf(uiroot);
  16686. if (p >= 0) {
  16687. this._3dUI.splice(p, 1);
  16688. return true;
  16689. }
  16690. return false;
  16691. }
  16692. }
  16693. Stage.SCALE_NOSCALE = "noscale";
  16694. Stage.SCALE_EXACTFIT = "exactfit";
  16695. Stage.SCALE_SHOWALL = "showall";
  16696. Stage.SCALE_NOBORDER = "noborder";
  16697. Stage.SCALE_FULL = "full";
  16698. Stage.SCALE_FIXED_WIDTH = "fixedwidth";
  16699. Stage.SCALE_FIXED_HEIGHT = "fixedheight";
  16700. Stage.SCALE_FIXED_AUTO = "fixedauto";
  16701. Stage.ALIGN_LEFT = "left";
  16702. Stage.ALIGN_RIGHT = "right";
  16703. Stage.ALIGN_CENTER = "center";
  16704. Stage.ALIGN_TOP = "top";
  16705. Stage.ALIGN_MIDDLE = "middle";
  16706. Stage.ALIGN_BOTTOM = "bottom";
  16707. Stage.SCREEN_NONE = "none";
  16708. Stage.SCREEN_HORIZONTAL = "horizontal";
  16709. Stage.SCREEN_VERTICAL = "vertical";
  16710. Stage.FRAME_FAST = "fast";
  16711. Stage.FRAME_SLOW = "slow";
  16712. Stage.FRAME_MOUSE = "mouse";
  16713. Stage.FRAME_SLEEP = "sleep";
  16714. Stage.clear = function (value) {
  16715. Context.set2DRenderConfig();
  16716. var gl = LayaGL.instance;
  16717. RenderState2D.worldScissorTest && gl.disable(gl.SCISSOR_TEST);
  16718. var ctx = Render.context;
  16719. var c = (ctx._submits._length == 0 || Config.preserveDrawingBuffer) ? ColorUtils.create(value).arrColor : ILaya.stage._wgColor;
  16720. if (c)
  16721. ctx.clearBG(c[0], c[1], c[2], c[3]);
  16722. else
  16723. ctx.clearBG(0, 0, 0, 0);
  16724. RenderState2D.clear();
  16725. };
  16726. ClassUtils.regClass("laya.display.Stage", Stage);
  16727. ClassUtils.regClass("Laya.Stage", Stage);
  16728. class KeyBoardManager {
  16729. static __init__() {
  16730. KeyBoardManager._addEvent("keydown");
  16731. KeyBoardManager._addEvent("keypress");
  16732. KeyBoardManager._addEvent("keyup");
  16733. }
  16734. static _addEvent(type) {
  16735. ILaya.Browser.document.addEventListener(type, function (e) {
  16736. KeyBoardManager._dispatch(e, type);
  16737. }, true);
  16738. }
  16739. static _dispatch(e, type) {
  16740. if (!KeyBoardManager.enabled)
  16741. return;
  16742. KeyBoardManager._event._stoped = false;
  16743. KeyBoardManager._event.nativeEvent = e;
  16744. KeyBoardManager._event.keyCode = e.keyCode || e.which || e.charCode;
  16745. if (type === "keydown")
  16746. KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode] = true;
  16747. else if (type === "keyup")
  16748. KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode] = null;
  16749. var target = (ILaya.stage.focus && (ILaya.stage.focus.event != null) && ILaya.stage.focus.displayedInStage) ? ILaya.stage.focus : ILaya.stage;
  16750. var ct = target;
  16751. while (ct) {
  16752. ct.event(type, KeyBoardManager._event.setTo(type, ct, target));
  16753. ct = ct.parent;
  16754. }
  16755. }
  16756. static hasKeyDown(key) {
  16757. return KeyBoardManager._pressKeys[key];
  16758. }
  16759. }
  16760. KeyBoardManager._pressKeys = {};
  16761. KeyBoardManager.enabled = true;
  16762. KeyBoardManager._event = new Event();
  16763. class SoundChannel extends EventDispatcher {
  16764. constructor() {
  16765. super(...arguments);
  16766. this.isStopped = false;
  16767. }
  16768. set volume(v) {
  16769. }
  16770. get volume() {
  16771. return 1;
  16772. }
  16773. get position() {
  16774. return 0;
  16775. }
  16776. get duration() {
  16777. return 0;
  16778. }
  16779. play() {
  16780. }
  16781. stop() {
  16782. if (this.completeHandler)
  16783. this.completeHandler.runWith(false);
  16784. }
  16785. pause() {
  16786. }
  16787. resume() {
  16788. }
  16789. __runComplete(handler) {
  16790. if (handler) {
  16791. handler.runWith(true);
  16792. }
  16793. }
  16794. }
  16795. class AudioSoundChannel extends SoundChannel {
  16796. constructor(audio) {
  16797. super();
  16798. this._audio = null;
  16799. this._onEnd = this.__onEnd.bind(this);
  16800. this._resumePlay = this.__resumePlay.bind(this);
  16801. audio.addEventListener("ended", this._onEnd);
  16802. this._audio = audio;
  16803. }
  16804. __onEnd(evt) {
  16805. if (this.loops == 1) {
  16806. if (this.completeHandler) {
  16807. ILaya.systemTimer.once(10, this, this.__runComplete, [this.completeHandler], false);
  16808. this.completeHandler = null;
  16809. }
  16810. this.stop();
  16811. this.event(Event.COMPLETE);
  16812. return;
  16813. }
  16814. if (this.loops > 0) {
  16815. this.loops--;
  16816. }
  16817. this.startTime = 0;
  16818. this.play();
  16819. }
  16820. __resumePlay() {
  16821. if (this._audio)
  16822. this._audio.removeEventListener("canplay", this._resumePlay);
  16823. if (this.isStopped)
  16824. return;
  16825. try {
  16826. this._audio.currentTime = this.startTime;
  16827. Browser.container.appendChild(this._audio);
  16828. this._audio.play();
  16829. }
  16830. catch (e) {
  16831. this.event(Event.ERROR);
  16832. }
  16833. }
  16834. play() {
  16835. this.isStopped = false;
  16836. try {
  16837. this._audio.playbackRate = ILaya.SoundManager.playbackRate;
  16838. this._audio.currentTime = this.startTime;
  16839. }
  16840. catch (e) {
  16841. this._audio.addEventListener("canplay", this._resumePlay);
  16842. return;
  16843. }
  16844. ILaya.SoundManager.addChannel(this);
  16845. Browser.container.appendChild(this._audio);
  16846. if ("play" in this._audio)
  16847. this._audio.play();
  16848. }
  16849. get position() {
  16850. if (!this._audio)
  16851. return 0;
  16852. return this._audio.currentTime;
  16853. }
  16854. get duration() {
  16855. if (!this._audio)
  16856. return 0;
  16857. return this._audio.duration;
  16858. }
  16859. stop() {
  16860. super.stop();
  16861. this.isStopped = true;
  16862. ILaya.SoundManager.removeChannel(this);
  16863. this.completeHandler = null;
  16864. if (!this._audio)
  16865. return;
  16866. if ("pause" in this._audio)
  16867. if (ILaya.Render.isConchApp) {
  16868. this._audio.stop();
  16869. }
  16870. this._audio.pause();
  16871. this._audio.removeEventListener("ended", this._onEnd);
  16872. this._audio.removeEventListener("canplay", this._resumePlay);
  16873. if (!ILaya.Browser.onIE) {
  16874. if (this._audio != ILaya.AudioSound._musicAudio) {
  16875. ILaya.Pool.recover("audio:" + this.url, this._audio);
  16876. }
  16877. }
  16878. Browser.removeElement(this._audio);
  16879. this._audio = null;
  16880. if (ILaya.SoundManager.autoReleaseSound)
  16881. ILaya.SoundManager.disposeSoundLater(this.url);
  16882. }
  16883. pause() {
  16884. this.isStopped = true;
  16885. ILaya.SoundManager.removeChannel(this);
  16886. if ("pause" in this._audio)
  16887. this._audio.pause();
  16888. if (ILaya.SoundManager.autoReleaseSound)
  16889. ILaya.SoundManager.disposeSoundLater(this.url);
  16890. }
  16891. resume() {
  16892. var audio = this._audio;
  16893. if (!audio)
  16894. return;
  16895. this.isStopped = false;
  16896. if (audio.readyState == 0) {
  16897. audio.src = this.url;
  16898. audio.addEventListener("canplay", this._resumePlay);
  16899. audio.load();
  16900. }
  16901. ILaya.SoundManager.addChannel(this);
  16902. if ("play" in audio) {
  16903. audio.play();
  16904. }
  16905. }
  16906. set volume(v) {
  16907. if (!this._audio)
  16908. return;
  16909. this._audio.volume = v;
  16910. }
  16911. get volume() {
  16912. if (!this._audio)
  16913. return 1;
  16914. return this._audio.volume;
  16915. }
  16916. }
  16917. class AudioSound extends EventDispatcher {
  16918. constructor() {
  16919. super(...arguments);
  16920. this.loaded = false;
  16921. }
  16922. dispose() {
  16923. var ad = AudioSound._audioCache[this.url];
  16924. Pool.clearBySign("audio:" + this.url);
  16925. if (ad) {
  16926. if (!Render.isConchApp) {
  16927. ad.src = "";
  16928. }
  16929. delete AudioSound._audioCache[this.url];
  16930. }
  16931. }
  16932. static _initMusicAudio() {
  16933. if (AudioSound._musicAudio)
  16934. return;
  16935. if (!AudioSound._musicAudio)
  16936. AudioSound._musicAudio = Browser.createElement("audio");
  16937. if (!Render.isConchApp) {
  16938. Browser.document.addEventListener("mousedown", AudioSound._makeMusicOK);
  16939. }
  16940. }
  16941. static _makeMusicOK() {
  16942. Browser.document.removeEventListener("mousedown", AudioSound._makeMusicOK);
  16943. if (!AudioSound._musicAudio.src) {
  16944. AudioSound._musicAudio.src = "";
  16945. AudioSound._musicAudio.load();
  16946. }
  16947. else {
  16948. AudioSound._musicAudio.play();
  16949. }
  16950. }
  16951. load(url) {
  16952. url = URL.formatURL(url);
  16953. this.url = url;
  16954. var ad;
  16955. if (url == ILaya.SoundManager._bgMusic) {
  16956. AudioSound._initMusicAudio();
  16957. ad = AudioSound._musicAudio;
  16958. if (ad.src != url) {
  16959. AudioSound._audioCache[ad.src] = null;
  16960. ad = null;
  16961. }
  16962. }
  16963. else {
  16964. ad = AudioSound._audioCache[url];
  16965. }
  16966. if (ad && ad.readyState >= 2) {
  16967. this.event(Event.COMPLETE);
  16968. return;
  16969. }
  16970. if (!ad) {
  16971. if (url == ILaya.SoundManager._bgMusic) {
  16972. AudioSound._initMusicAudio();
  16973. ad = AudioSound._musicAudio;
  16974. }
  16975. else {
  16976. ad = Browser.createElement("audio");
  16977. }
  16978. AudioSound._audioCache[url] = ad;
  16979. ad.src = url;
  16980. }
  16981. ad.addEventListener("canplaythrough", onLoaded);
  16982. ad.addEventListener("error", onErr);
  16983. var me = this;
  16984. function onLoaded() {
  16985. offs();
  16986. me.loaded = true;
  16987. me.event(Event.COMPLETE);
  16988. }
  16989. function onErr() {
  16990. ad.load = null;
  16991. offs();
  16992. me.event(Event.ERROR);
  16993. }
  16994. function offs() {
  16995. ad.removeEventListener("canplaythrough", onLoaded);
  16996. ad.removeEventListener("error", onErr);
  16997. }
  16998. this.audio = ad;
  16999. if (ad.load) {
  17000. ad.load();
  17001. }
  17002. else {
  17003. onErr();
  17004. }
  17005. }
  17006. play(startTime = 0, loops = 0) {
  17007. if (!this.url)
  17008. return null;
  17009. var ad;
  17010. if (this.url == ILaya.SoundManager._bgMusic) {
  17011. ad = AudioSound._musicAudio;
  17012. }
  17013. else {
  17014. ad = AudioSound._audioCache[this.url];
  17015. }
  17016. if (!ad)
  17017. return null;
  17018. var tAd;
  17019. tAd = Pool.getItem("audio:" + this.url);
  17020. if (Render.isConchApp) {
  17021. if (!tAd) {
  17022. tAd = Browser.createElement("audio");
  17023. tAd.src = this.url;
  17024. }
  17025. }
  17026. else {
  17027. if (this.url == ILaya.SoundManager._bgMusic) {
  17028. AudioSound._initMusicAudio();
  17029. tAd = AudioSound._musicAudio;
  17030. tAd.src = this.url;
  17031. }
  17032. else {
  17033. tAd = tAd ? tAd : ad.cloneNode(true);
  17034. }
  17035. }
  17036. var channel = new AudioSoundChannel(tAd);
  17037. channel.url = this.url;
  17038. channel.loops = loops;
  17039. channel.startTime = startTime;
  17040. channel.play();
  17041. ILaya.SoundManager.addChannel(channel);
  17042. return channel;
  17043. }
  17044. get duration() {
  17045. var ad;
  17046. ad = AudioSound._audioCache[this.url];
  17047. if (!ad)
  17048. return 0;
  17049. return ad.duration;
  17050. }
  17051. }
  17052. AudioSound._audioCache = {};
  17053. class WebAudioSoundChannel extends SoundChannel {
  17054. constructor() {
  17055. super();
  17056. this.bufferSource = null;
  17057. this._currentTime = 0;
  17058. this._volume = 1;
  17059. this._startTime = 0;
  17060. this._pauseTime = 0;
  17061. this.context = ILaya.WebAudioSound.ctx;
  17062. this._onPlayEnd = Utils.bind(this.__onPlayEnd, this);
  17063. if (this.context["createGain"]) {
  17064. this.gain = this.context["createGain"]();
  17065. }
  17066. else {
  17067. this.gain = this.context["createGainNode"]();
  17068. }
  17069. }
  17070. play() {
  17071. ILaya.SoundManager.addChannel(this);
  17072. this.isStopped = false;
  17073. this._clearBufferSource();
  17074. if (!this.audioBuffer)
  17075. return;
  17076. if (this.startTime >= this.duration)
  17077. return stop();
  17078. var context = this.context;
  17079. var gain = this.gain;
  17080. var bufferSource = context.createBufferSource();
  17081. this.bufferSource = bufferSource;
  17082. bufferSource.buffer = this.audioBuffer;
  17083. bufferSource.connect(gain);
  17084. if (gain)
  17085. gain.disconnect();
  17086. gain.connect(context.destination);
  17087. bufferSource.onended = this._onPlayEnd;
  17088. this._startTime = Browser.now();
  17089. if (this.gain.gain.setTargetAtTime) {
  17090. this.gain.gain.setTargetAtTime(this._volume, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  17091. }
  17092. else
  17093. this.gain.gain.value = this._volume;
  17094. if (this.loops == 0) {
  17095. bufferSource.loop = true;
  17096. }
  17097. if (bufferSource.playbackRate.setTargetAtTime) {
  17098. bufferSource.playbackRate.setTargetAtTime(ILaya.SoundManager.playbackRate, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  17099. }
  17100. else
  17101. bufferSource.playbackRate.value = ILaya.SoundManager.playbackRate;
  17102. bufferSource.start(0, this.startTime);
  17103. this._currentTime = 0;
  17104. }
  17105. __onPlayEnd() {
  17106. if (this.loops == 1) {
  17107. if (this.completeHandler) {
  17108. ILaya.timer.once(10, this, this.__runComplete, [this.completeHandler], false);
  17109. this.completeHandler = null;
  17110. }
  17111. this.stop();
  17112. this.event(Event.COMPLETE);
  17113. return;
  17114. }
  17115. if (this.loops > 0) {
  17116. this.loops--;
  17117. }
  17118. this.startTime = 0;
  17119. this.play();
  17120. }
  17121. get position() {
  17122. if (this.bufferSource) {
  17123. return (Browser.now() - this._startTime) / 1000 + this.startTime;
  17124. }
  17125. return 0;
  17126. }
  17127. get duration() {
  17128. if (this.audioBuffer) {
  17129. return this.audioBuffer.duration;
  17130. }
  17131. return 0;
  17132. }
  17133. _clearBufferSource() {
  17134. if (this.bufferSource) {
  17135. var sourceNode = this.bufferSource;
  17136. if (sourceNode.stop) {
  17137. sourceNode.stop(0);
  17138. }
  17139. else {
  17140. sourceNode.noteOff(0);
  17141. }
  17142. sourceNode.disconnect(0);
  17143. sourceNode.onended = null;
  17144. if (!WebAudioSoundChannel._tryCleanFailed)
  17145. this._tryClearBuffer(sourceNode);
  17146. this.bufferSource = null;
  17147. }
  17148. }
  17149. _tryClearBuffer(sourceNode) {
  17150. try {
  17151. sourceNode.buffer = null;
  17152. }
  17153. catch (e) {
  17154. WebAudioSoundChannel._tryCleanFailed = true;
  17155. }
  17156. }
  17157. stop() {
  17158. super.stop();
  17159. this._clearBufferSource();
  17160. this.audioBuffer = null;
  17161. if (this.gain)
  17162. this.gain.disconnect();
  17163. this.isStopped = true;
  17164. ILaya.SoundManager.removeChannel(this);
  17165. this.completeHandler = null;
  17166. if (ILaya.SoundManager.autoReleaseSound)
  17167. ILaya.SoundManager.disposeSoundLater(this.url);
  17168. }
  17169. pause() {
  17170. if (!this.isStopped) {
  17171. this._pauseTime = this.position;
  17172. }
  17173. this._clearBufferSource();
  17174. if (this.gain)
  17175. this.gain.disconnect();
  17176. this.isStopped = true;
  17177. ILaya.SoundManager.removeChannel(this);
  17178. if (ILaya.SoundManager.autoReleaseSound)
  17179. ILaya.SoundManager.disposeSoundLater(this.url);
  17180. }
  17181. resume() {
  17182. this.startTime = this._pauseTime;
  17183. this.play();
  17184. }
  17185. set volume(v) {
  17186. this._volume = v;
  17187. if (this.isStopped) {
  17188. return;
  17189. }
  17190. if (this.gain.gain.setTargetAtTime) {
  17191. this.gain.gain.setTargetAtTime(v, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  17192. }
  17193. else
  17194. this.gain.gain.value = v;
  17195. }
  17196. get volume() {
  17197. return this._volume;
  17198. }
  17199. }
  17200. WebAudioSoundChannel._tryCleanFailed = false;
  17201. WebAudioSoundChannel.SetTargetDelay = 0.001;
  17202. class WebAudioSound extends EventDispatcher {
  17203. constructor() {
  17204. super(...arguments);
  17205. this.loaded = false;
  17206. this._disposed = false;
  17207. }
  17208. static decode() {
  17209. if (WebAudioSound.buffs.length <= 0 || WebAudioSound.isDecoding) {
  17210. return;
  17211. }
  17212. WebAudioSound.isDecoding = true;
  17213. WebAudioSound.tInfo = WebAudioSound.buffs.shift();
  17214. WebAudioSound.ctx.decodeAudioData(WebAudioSound.tInfo["buffer"], WebAudioSound._done, WebAudioSound._fail);
  17215. }
  17216. static _done(audioBuffer) {
  17217. WebAudioSound.e.event("loaded:" + WebAudioSound.tInfo.url, audioBuffer);
  17218. WebAudioSound.isDecoding = false;
  17219. WebAudioSound.decode();
  17220. }
  17221. static _fail() {
  17222. WebAudioSound.e.event("err:" + WebAudioSound.tInfo.url, null);
  17223. WebAudioSound.isDecoding = false;
  17224. WebAudioSound.decode();
  17225. }
  17226. static _playEmptySound() {
  17227. if (WebAudioSound.ctx == null) {
  17228. return;
  17229. }
  17230. var source = WebAudioSound.ctx.createBufferSource();
  17231. source.buffer = WebAudioSound._miniBuffer;
  17232. source.connect(WebAudioSound.ctx.destination);
  17233. source.start(0, 0, 0);
  17234. }
  17235. static _unlock() {
  17236. if (WebAudioSound._unlocked) {
  17237. return;
  17238. }
  17239. WebAudioSound._playEmptySound();
  17240. if (WebAudioSound.ctx.state == "running") {
  17241. window.document.removeEventListener("mousedown", WebAudioSound._unlock, true);
  17242. window.document.removeEventListener("touchend", WebAudioSound._unlock, true);
  17243. window.document.removeEventListener("touchstart", WebAudioSound._unlock, true);
  17244. WebAudioSound._unlocked = true;
  17245. }
  17246. }
  17247. static initWebAudio() {
  17248. if (WebAudioSound.ctx.state != "running") {
  17249. WebAudioSound._unlock();
  17250. window.document.addEventListener("mousedown", WebAudioSound._unlock, true);
  17251. window.document.addEventListener("touchend", WebAudioSound._unlock, true);
  17252. window.document.addEventListener("touchstart", WebAudioSound._unlock, true);
  17253. }
  17254. }
  17255. load(url) {
  17256. var me = this;
  17257. url = URL.formatURL(url);
  17258. this.url = url;
  17259. this.audioBuffer = WebAudioSound._dataCache[url];
  17260. if (this.audioBuffer) {
  17261. this._loaded(this.audioBuffer);
  17262. return;
  17263. }
  17264. WebAudioSound.e.on("loaded:" + url, this, this._loaded);
  17265. WebAudioSound.e.on("err:" + url, this, this._err);
  17266. if (WebAudioSound.__loadingSound[url]) {
  17267. return;
  17268. }
  17269. WebAudioSound.__loadingSound[url] = true;
  17270. var request = new XMLHttpRequest();
  17271. request.open("GET", url, true);
  17272. request.responseType = "arraybuffer";
  17273. request.onload = function () {
  17274. if (me._disposed) {
  17275. me._removeLoadEvents();
  17276. return;
  17277. }
  17278. me.data = request.response;
  17279. WebAudioSound.buffs.push({ "buffer": me.data, "url": me.url });
  17280. WebAudioSound.decode();
  17281. };
  17282. request.onerror = function (e) {
  17283. me._err();
  17284. };
  17285. request.send();
  17286. }
  17287. _err() {
  17288. this._removeLoadEvents();
  17289. WebAudioSound.__loadingSound[this.url] = false;
  17290. this.event(Event.ERROR);
  17291. }
  17292. _loaded(audioBuffer) {
  17293. this._removeLoadEvents();
  17294. if (this._disposed) {
  17295. return;
  17296. }
  17297. this.audioBuffer = audioBuffer;
  17298. WebAudioSound._dataCache[this.url] = this.audioBuffer;
  17299. this.loaded = true;
  17300. this.event(Event.COMPLETE);
  17301. }
  17302. _removeLoadEvents() {
  17303. WebAudioSound.e.off("loaded:" + this.url, this, this._loaded);
  17304. WebAudioSound.e.off("err:" + this.url, this, this._err);
  17305. }
  17306. __playAfterLoaded() {
  17307. if (!this.__toPlays)
  17308. return;
  17309. var i, len;
  17310. var toPlays;
  17311. toPlays = this.__toPlays;
  17312. len = toPlays.length;
  17313. var tParams;
  17314. for (i = 0; i < len; i++) {
  17315. tParams = toPlays[i];
  17316. if (tParams[2] && !tParams[2].isStopped) {
  17317. this.play(tParams[0], tParams[1], tParams[2]);
  17318. }
  17319. }
  17320. this.__toPlays.length = 0;
  17321. }
  17322. play(startTime = 0, loops = 0, channel = null) {
  17323. channel = channel ? channel : new WebAudioSoundChannel();
  17324. if (!this.audioBuffer) {
  17325. if (this.url) {
  17326. if (!this.__toPlays)
  17327. this.__toPlays = [];
  17328. this.__toPlays.push([startTime, loops, channel]);
  17329. this.once(Event.COMPLETE, this, this.__playAfterLoaded);
  17330. this.load(this.url);
  17331. }
  17332. }
  17333. channel.url = this.url;
  17334. channel.loops = loops;
  17335. channel.audioBuffer = this.audioBuffer;
  17336. channel.startTime = startTime;
  17337. channel.play();
  17338. ILaya.SoundManager.addChannel(channel);
  17339. return channel;
  17340. }
  17341. get duration() {
  17342. if (this.audioBuffer) {
  17343. return this.audioBuffer.duration;
  17344. }
  17345. return 0;
  17346. }
  17347. dispose() {
  17348. this._disposed = true;
  17349. delete WebAudioSound._dataCache[this.url];
  17350. delete WebAudioSound.__loadingSound[this.url];
  17351. this.audioBuffer = null;
  17352. this.data = null;
  17353. this.__toPlays = [];
  17354. }
  17355. }
  17356. WebAudioSound._dataCache = {};
  17357. WebAudioSound.webAudioEnabled = window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"];
  17358. WebAudioSound.ctx = WebAudioSound.webAudioEnabled ? new (window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"])() : undefined;
  17359. WebAudioSound.buffs = [];
  17360. WebAudioSound.isDecoding = false;
  17361. WebAudioSound._miniBuffer = WebAudioSound.ctx ? WebAudioSound.ctx.createBuffer(1, 1, 22050) : undefined;
  17362. WebAudioSound.e = new EventDispatcher();
  17363. WebAudioSound._unlocked = false;
  17364. WebAudioSound.__loadingSound = {};
  17365. class SoundManager {
  17366. static __init__() {
  17367. var win = ILaya.Browser.window;
  17368. var supportWebAudio = win["AudioContext"] || win["webkitAudioContext"] || win["mozAudioContext"] ? true : false;
  17369. if (supportWebAudio)
  17370. WebAudioSound.initWebAudio();
  17371. SoundManager._soundClass = supportWebAudio ? WebAudioSound : AudioSound;
  17372. AudioSound._initMusicAudio();
  17373. SoundManager._musicClass = AudioSound;
  17374. return supportWebAudio;
  17375. }
  17376. static addChannel(channel) {
  17377. if (SoundManager._channels.indexOf(channel) >= 0)
  17378. return;
  17379. SoundManager._channels.push(channel);
  17380. }
  17381. static removeChannel(channel) {
  17382. var i;
  17383. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17384. if (SoundManager._channels[i] == channel) {
  17385. SoundManager._channels.splice(i, 1);
  17386. }
  17387. }
  17388. }
  17389. static disposeSoundLater(url) {
  17390. SoundManager._lastSoundUsedTimeDic[url] = ILaya.Browser.now();
  17391. if (!SoundManager._isCheckingDispose) {
  17392. SoundManager._isCheckingDispose = true;
  17393. ILaya.timer.loop(5000, null, SoundManager._checkDisposeSound);
  17394. }
  17395. }
  17396. static _checkDisposeSound() {
  17397. var key;
  17398. var tTime = ILaya.Browser.now();
  17399. var hasCheck = false;
  17400. for (key in SoundManager._lastSoundUsedTimeDic) {
  17401. if (tTime - SoundManager._lastSoundUsedTimeDic[key] > 30000) {
  17402. delete SoundManager._lastSoundUsedTimeDic[key];
  17403. SoundManager.disposeSoundIfNotUsed(key);
  17404. }
  17405. else {
  17406. hasCheck = true;
  17407. }
  17408. }
  17409. if (!hasCheck) {
  17410. SoundManager._isCheckingDispose = false;
  17411. ILaya.timer.clear(null, SoundManager._checkDisposeSound);
  17412. }
  17413. }
  17414. static disposeSoundIfNotUsed(url) {
  17415. var i;
  17416. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17417. if (SoundManager._channels[i].url == url) {
  17418. return;
  17419. }
  17420. }
  17421. SoundManager.destroySound(url);
  17422. }
  17423. static set autoStopMusic(v) {
  17424. ILaya.stage.off(Event.BLUR, null, SoundManager._stageOnBlur);
  17425. ILaya.stage.off(Event.FOCUS, null, SoundManager._stageOnFocus);
  17426. ILaya.stage.off(Event.VISIBILITY_CHANGE, null, SoundManager._visibilityChange);
  17427. SoundManager._autoStopMusic = v;
  17428. if (v) {
  17429. ILaya.stage.on(Event.BLUR, null, SoundManager._stageOnBlur);
  17430. ILaya.stage.on(Event.FOCUS, null, SoundManager._stageOnFocus);
  17431. ILaya.stage.on(Event.VISIBILITY_CHANGE, null, SoundManager._visibilityChange);
  17432. }
  17433. }
  17434. static get autoStopMusic() {
  17435. return SoundManager._autoStopMusic;
  17436. }
  17437. static _visibilityChange() {
  17438. if (ILaya.stage.isVisibility) {
  17439. SoundManager._stageOnFocus();
  17440. }
  17441. else {
  17442. SoundManager._stageOnBlur();
  17443. }
  17444. }
  17445. static _stageOnBlur() {
  17446. SoundManager._isActive = false;
  17447. if (SoundManager._musicChannel) {
  17448. if (!SoundManager._musicChannel.isStopped) {
  17449. SoundManager._blurPaused = true;
  17450. SoundManager._musicChannel.pause();
  17451. }
  17452. }
  17453. SoundManager.stopAllSound();
  17454. ILaya.stage.once(Event.MOUSE_DOWN, null, SoundManager._stageOnFocus);
  17455. }
  17456. static _recoverWebAudio() {
  17457. if (WebAudioSound.ctx && WebAudioSound.ctx.state != "running" && WebAudioSound.ctx.resume)
  17458. WebAudioSound.ctx.resume();
  17459. }
  17460. static _stageOnFocus() {
  17461. SoundManager._isActive = true;
  17462. SoundManager._recoverWebAudio();
  17463. ILaya.stage.off(Event.MOUSE_DOWN, null, SoundManager._stageOnFocus);
  17464. if (SoundManager._blurPaused) {
  17465. if (SoundManager._musicChannel && SoundManager._musicChannel.isStopped) {
  17466. SoundManager._blurPaused = false;
  17467. SoundManager._musicChannel.resume();
  17468. }
  17469. }
  17470. }
  17471. static set muted(value) {
  17472. if (value == SoundManager._muted)
  17473. return;
  17474. if (value) {
  17475. SoundManager.stopAllSound();
  17476. }
  17477. SoundManager.musicMuted = value;
  17478. SoundManager._muted = value;
  17479. }
  17480. static get muted() {
  17481. return SoundManager._muted;
  17482. }
  17483. static set soundMuted(value) {
  17484. SoundManager._soundMuted = value;
  17485. }
  17486. static get soundMuted() {
  17487. return SoundManager._soundMuted;
  17488. }
  17489. static set musicMuted(value) {
  17490. if (value == SoundManager._musicMuted)
  17491. return;
  17492. if (value) {
  17493. if (SoundManager._bgMusic) {
  17494. if (SoundManager._musicChannel && !SoundManager._musicChannel.isStopped) {
  17495. if (ILaya.Render.isConchApp) {
  17496. if (SoundManager._musicChannel._audio)
  17497. SoundManager._musicChannel._audio.muted = true;
  17498. }
  17499. else {
  17500. SoundManager._musicChannel.pause();
  17501. }
  17502. }
  17503. else {
  17504. SoundManager._musicChannel = null;
  17505. }
  17506. }
  17507. else {
  17508. SoundManager._musicChannel = null;
  17509. }
  17510. SoundManager._musicMuted = value;
  17511. }
  17512. else {
  17513. SoundManager._musicMuted = value;
  17514. if (SoundManager._bgMusic) {
  17515. if (SoundManager._musicChannel) {
  17516. if (ILaya.Render.isConchApp) {
  17517. if (SoundManager._musicChannel._audio)
  17518. SoundManager._musicChannel._audio.muted = false;
  17519. }
  17520. else {
  17521. SoundManager._musicChannel.resume();
  17522. }
  17523. }
  17524. }
  17525. }
  17526. }
  17527. static get musicMuted() {
  17528. return SoundManager._musicMuted;
  17529. }
  17530. static get useAudioMusic() {
  17531. return SoundManager._useAudioMusic;
  17532. }
  17533. static set useAudioMusic(value) {
  17534. SoundManager._useAudioMusic = value;
  17535. if (value) {
  17536. SoundManager._musicClass = AudioSound;
  17537. }
  17538. else {
  17539. SoundManager._musicClass = null;
  17540. }
  17541. }
  17542. static playSound(url, loops = 1, complete = null, soundClass = null, startTime = 0) {
  17543. if (!SoundManager._isActive || !url)
  17544. return null;
  17545. if (SoundManager._muted)
  17546. return null;
  17547. SoundManager._recoverWebAudio();
  17548. url = URL.formatURL(url);
  17549. if (url == SoundManager._bgMusic) {
  17550. if (SoundManager._musicMuted)
  17551. return null;
  17552. }
  17553. else {
  17554. if (ILaya.Render.isConchApp) {
  17555. var ext = Utils.getFileExtension(url);
  17556. if (ext != "wav" && ext != "ogg") {
  17557. alert("The sound only supports wav or ogg format,for optimal performance reason,please refer to the official website document.");
  17558. return null;
  17559. }
  17560. }
  17561. if (SoundManager._soundMuted)
  17562. return null;
  17563. }
  17564. var tSound;
  17565. if (!ILaya.Browser.onBDMiniGame && !ILaya.Browser.onMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame && !ILaya.Browser.onBLMiniGame && !ILaya.Browser.onTTMiniGame && !ILaya.Browser.onHWMiniGame) {
  17566. tSound = ILaya.loader.getRes(url);
  17567. }
  17568. if (!soundClass)
  17569. soundClass = SoundManager._soundClass;
  17570. if (!tSound) {
  17571. tSound = new soundClass();
  17572. tSound.load(url);
  17573. if (!ILaya.Browser.onBDMiniGame && !ILaya.Browser.onMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame && !ILaya.Browser.onBLMiniGame && !ILaya.Browser.onTTMiniGame && !ILaya.Browser.onHWMiniGame) {
  17574. ILaya.Loader.cacheRes(url, tSound);
  17575. }
  17576. }
  17577. var channel;
  17578. channel = tSound.play(startTime, loops);
  17579. if (!channel)
  17580. return null;
  17581. channel.url = url;
  17582. channel.volume = (url == SoundManager._bgMusic) ? SoundManager.musicVolume : SoundManager.soundVolume;
  17583. channel.completeHandler = complete;
  17584. return channel;
  17585. }
  17586. static destroySound(url) {
  17587. var tSound = ILaya.loader.getRes(url);
  17588. if (tSound) {
  17589. ILaya.Loader.clearRes(url);
  17590. tSound.dispose();
  17591. }
  17592. }
  17593. static playMusic(url, loops = 0, complete = null, startTime = 0) {
  17594. url = URL.formatURL(url);
  17595. SoundManager._bgMusic = url;
  17596. if (SoundManager._musicChannel)
  17597. SoundManager._musicChannel.stop();
  17598. return SoundManager._musicChannel = SoundManager.playSound(url, loops, complete, SoundManager._musicClass, startTime);
  17599. }
  17600. static stopSound(url) {
  17601. url = URL.formatURL(url);
  17602. var i;
  17603. var channel;
  17604. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17605. channel = SoundManager._channels[i];
  17606. if (channel.url == url) {
  17607. channel.stop();
  17608. }
  17609. }
  17610. }
  17611. static stopAll() {
  17612. SoundManager._bgMusic = null;
  17613. var i;
  17614. var channel;
  17615. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17616. channel = SoundManager._channels[i];
  17617. channel.stop();
  17618. }
  17619. }
  17620. static stopAllSound() {
  17621. var i;
  17622. var channel;
  17623. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17624. channel = SoundManager._channels[i];
  17625. if (channel.url != SoundManager._bgMusic) {
  17626. channel.stop();
  17627. }
  17628. }
  17629. }
  17630. static stopMusic() {
  17631. if (SoundManager._musicChannel)
  17632. SoundManager._musicChannel.stop();
  17633. SoundManager._bgMusic = null;
  17634. }
  17635. static setSoundVolume(volume, url = null) {
  17636. if (url) {
  17637. url = URL.formatURL(url);
  17638. SoundManager._setVolume(url, volume);
  17639. }
  17640. else {
  17641. SoundManager.soundVolume = volume;
  17642. var i;
  17643. var channel;
  17644. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17645. channel = SoundManager._channels[i];
  17646. if (channel.url != SoundManager._bgMusic) {
  17647. channel.volume = volume;
  17648. }
  17649. }
  17650. }
  17651. }
  17652. static setMusicVolume(volume) {
  17653. SoundManager.musicVolume = volume;
  17654. SoundManager._setVolume(SoundManager._bgMusic, volume);
  17655. }
  17656. static _setVolume(url, volume) {
  17657. url = URL.formatURL(url);
  17658. var i;
  17659. var channel;
  17660. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17661. channel = SoundManager._channels[i];
  17662. if (channel.url == url) {
  17663. channel.volume = volume;
  17664. }
  17665. }
  17666. }
  17667. }
  17668. SoundManager.musicVolume = 1;
  17669. SoundManager.soundVolume = 1;
  17670. SoundManager.playbackRate = 1;
  17671. SoundManager._useAudioMusic = true;
  17672. SoundManager._muted = false;
  17673. SoundManager._soundMuted = false;
  17674. SoundManager._musicMuted = false;
  17675. SoundManager._bgMusic = null;
  17676. SoundManager._musicChannel = null;
  17677. SoundManager._channels = [];
  17678. SoundManager._blurPaused = false;
  17679. SoundManager._isActive = true;
  17680. SoundManager._lastSoundUsedTimeDic = {};
  17681. SoundManager._isCheckingDispose = false;
  17682. SoundManager.autoReleaseSound = true;
  17683. class Prefab {
  17684. create() {
  17685. if (this.json)
  17686. return ILaya.SceneUtils.createByData(null, this.json);
  17687. return null;
  17688. }
  17689. }
  17690. class Byte {
  17691. constructor(data = null) {
  17692. this._xd_ = true;
  17693. this._allocated_ = 8;
  17694. this._pos_ = 0;
  17695. this._length = 0;
  17696. if (data) {
  17697. this._u8d_ = new Uint8Array(data);
  17698. this._d_ = new DataView(this._u8d_.buffer);
  17699. this._length = this._d_.byteLength;
  17700. }
  17701. else {
  17702. this._resizeBuffer(this._allocated_);
  17703. }
  17704. }
  17705. static getSystemEndian() {
  17706. if (!Byte._sysEndian) {
  17707. var buffer = new ArrayBuffer(2);
  17708. new DataView(buffer).setInt16(0, 256, true);
  17709. Byte._sysEndian = (new Int16Array(buffer))[0] === 256 ? Byte.LITTLE_ENDIAN : Byte.BIG_ENDIAN;
  17710. }
  17711. return Byte._sysEndian;
  17712. }
  17713. get buffer() {
  17714. var rstBuffer = this._d_.buffer;
  17715. if (rstBuffer.byteLength === this._length)
  17716. return rstBuffer;
  17717. return rstBuffer.slice(0, this._length);
  17718. }
  17719. get endian() {
  17720. return this._xd_ ? Byte.LITTLE_ENDIAN : Byte.BIG_ENDIAN;
  17721. }
  17722. set endian(value) {
  17723. this._xd_ = (value === Byte.LITTLE_ENDIAN);
  17724. }
  17725. set length(value) {
  17726. if (this._allocated_ < value)
  17727. this._resizeBuffer(this._allocated_ = Math.floor(Math.max(value, this._allocated_ * 2)));
  17728. else if (this._allocated_ > value)
  17729. this._resizeBuffer(this._allocated_ = value);
  17730. this._length = value;
  17731. }
  17732. get length() {
  17733. return this._length;
  17734. }
  17735. _resizeBuffer(len) {
  17736. try {
  17737. var newByteView = new Uint8Array(len);
  17738. if (this._u8d_ != null) {
  17739. if (this._u8d_.length <= len)
  17740. newByteView.set(this._u8d_);
  17741. else
  17742. newByteView.set(this._u8d_.subarray(0, len));
  17743. }
  17744. this._u8d_ = newByteView;
  17745. this._d_ = new DataView(newByteView.buffer);
  17746. }
  17747. catch (err) {
  17748. throw "Invalid typed array length:" + len;
  17749. }
  17750. }
  17751. getString() {
  17752. return this.readString();
  17753. }
  17754. readString() {
  17755. return this._rUTF(this.getUint16());
  17756. }
  17757. getFloat32Array(start, len) {
  17758. return this.readFloat32Array(start, len);
  17759. }
  17760. readFloat32Array(start, len) {
  17761. var end = start + len;
  17762. end = (end > this._length) ? this._length : end;
  17763. var v = new Float32Array(this._d_.buffer.slice(start, end));
  17764. this._pos_ = end;
  17765. return v;
  17766. }
  17767. getUint8Array(start, len) {
  17768. return this.readUint8Array(start, len);
  17769. }
  17770. readUint8Array(start, len) {
  17771. var end = start + len;
  17772. end = (end > this._length) ? this._length : end;
  17773. var v = new Uint8Array(this._d_.buffer.slice(start, end));
  17774. this._pos_ = end;
  17775. return v;
  17776. }
  17777. getInt16Array(start, len) {
  17778. return this.readInt16Array(start, len);
  17779. }
  17780. readInt16Array(start, len) {
  17781. var end = start + len;
  17782. end = (end > this._length) ? this._length : end;
  17783. var v = new Int16Array(this._d_.buffer.slice(start, end));
  17784. this._pos_ = end;
  17785. return v;
  17786. }
  17787. getFloat32() {
  17788. return this.readFloat32();
  17789. }
  17790. readFloat32() {
  17791. if (this._pos_ + 4 > this._length)
  17792. throw "getFloat32 error - Out of bounds";
  17793. var v = this._d_.getFloat32(this._pos_, this._xd_);
  17794. this._pos_ += 4;
  17795. return v;
  17796. }
  17797. getFloat64() {
  17798. return this.readFloat64();
  17799. }
  17800. readFloat64() {
  17801. if (this._pos_ + 8 > this._length)
  17802. throw "getFloat64 error - Out of bounds";
  17803. var v = this._d_.getFloat64(this._pos_, this._xd_);
  17804. this._pos_ += 8;
  17805. return v;
  17806. }
  17807. writeFloat32(value) {
  17808. this._ensureWrite(this._pos_ + 4);
  17809. this._d_.setFloat32(this._pos_, value, this._xd_);
  17810. this._pos_ += 4;
  17811. }
  17812. writeFloat64(value) {
  17813. this._ensureWrite(this._pos_ + 8);
  17814. this._d_.setFloat64(this._pos_, value, this._xd_);
  17815. this._pos_ += 8;
  17816. }
  17817. getInt32() {
  17818. return this.readInt32();
  17819. }
  17820. readInt32() {
  17821. if (this._pos_ + 4 > this._length)
  17822. throw "getInt32 error - Out of bounds";
  17823. var float = this._d_.getInt32(this._pos_, this._xd_);
  17824. this._pos_ += 4;
  17825. return float;
  17826. }
  17827. getUint32() {
  17828. return this.readUint32();
  17829. }
  17830. readUint32() {
  17831. if (this._pos_ + 4 > this._length)
  17832. throw "getUint32 error - Out of bounds";
  17833. var v = this._d_.getUint32(this._pos_, this._xd_);
  17834. this._pos_ += 4;
  17835. return v;
  17836. }
  17837. writeInt32(value) {
  17838. this._ensureWrite(this._pos_ + 4);
  17839. this._d_.setInt32(this._pos_, value, this._xd_);
  17840. this._pos_ += 4;
  17841. }
  17842. writeUint32(value) {
  17843. this._ensureWrite(this._pos_ + 4);
  17844. this._d_.setUint32(this._pos_, value, this._xd_);
  17845. this._pos_ += 4;
  17846. }
  17847. getInt16() {
  17848. return this.readInt16();
  17849. }
  17850. readInt16() {
  17851. if (this._pos_ + 2 > this._length)
  17852. throw "getInt16 error - Out of bounds";
  17853. var us = this._d_.getInt16(this._pos_, this._xd_);
  17854. this._pos_ += 2;
  17855. return us;
  17856. }
  17857. getUint16() {
  17858. return this.readUint16();
  17859. }
  17860. readUint16() {
  17861. if (this._pos_ + 2 > this._length)
  17862. throw "getUint16 error - Out of bounds";
  17863. var us = this._d_.getUint16(this._pos_, this._xd_);
  17864. this._pos_ += 2;
  17865. return us;
  17866. }
  17867. writeUint16(value) {
  17868. this._ensureWrite(this._pos_ + 2);
  17869. this._d_.setUint16(this._pos_, value, this._xd_);
  17870. this._pos_ += 2;
  17871. }
  17872. writeInt16(value) {
  17873. this._ensureWrite(this._pos_ + 2);
  17874. this._d_.setInt16(this._pos_, value, this._xd_);
  17875. this._pos_ += 2;
  17876. }
  17877. getUint8() {
  17878. return this.readUint8();
  17879. }
  17880. readUint8() {
  17881. if (this._pos_ + 1 > this._length)
  17882. throw "getUint8 error - Out of bounds";
  17883. return this._u8d_[this._pos_++];
  17884. }
  17885. writeUint8(value) {
  17886. this._ensureWrite(this._pos_ + 1);
  17887. this._d_.setUint8(this._pos_, value);
  17888. this._pos_++;
  17889. }
  17890. _getUInt8(pos) {
  17891. return this._readUInt8(pos);
  17892. }
  17893. _readUInt8(pos) {
  17894. return this._d_.getUint8(pos);
  17895. }
  17896. _getUint16(pos) {
  17897. return this._readUint16(pos);
  17898. }
  17899. _readUint16(pos) {
  17900. return this._d_.getUint16(pos, this._xd_);
  17901. }
  17902. _getMatrix() {
  17903. return this._readMatrix();
  17904. }
  17905. _readMatrix() {
  17906. var rst = new Matrix(this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32());
  17907. return rst;
  17908. }
  17909. _rUTF(len) {
  17910. var max = this._pos_ + len, c, c2, c3, f = String.fromCharCode;
  17911. var u = this._u8d_;
  17912. var strs = [];
  17913. var n = 0;
  17914. strs.length = 1000;
  17915. while (this._pos_ < max) {
  17916. c = u[this._pos_++];
  17917. if (c < 0x80) {
  17918. if (c != 0)
  17919. strs[n++] = f(c);
  17920. }
  17921. else if (c < 0xE0) {
  17922. strs[n++] = f(((c & 0x3F) << 6) | (u[this._pos_++] & 0x7F));
  17923. }
  17924. else if (c < 0xF0) {
  17925. c2 = u[this._pos_++];
  17926. strs[n++] = f(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (u[this._pos_++] & 0x7F));
  17927. }
  17928. else {
  17929. c2 = u[this._pos_++];
  17930. c3 = u[this._pos_++];
  17931. const _code = ((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 & 0x7F) << 6) | (u[this._pos_++] & 0x7F);
  17932. if (_code >= 0x10000) {
  17933. const _offset = _code - 0x10000;
  17934. const _lead = 0xd800 | (_offset >> 10);
  17935. const _trail = 0xdc00 | (_offset & 0x3ff);
  17936. strs[n++] = f(_lead);
  17937. strs[n++] = f(_trail);
  17938. }
  17939. else {
  17940. strs[n++] = f(_code);
  17941. }
  17942. }
  17943. }
  17944. strs.length = n;
  17945. return strs.join('');
  17946. }
  17947. getCustomString(len) {
  17948. return this.readCustomString(len);
  17949. }
  17950. readCustomString(len) {
  17951. var v = "", ulen = 0, c, c2, f = String.fromCharCode;
  17952. var u = this._u8d_;
  17953. while (len > 0) {
  17954. c = u[this._pos_];
  17955. if (c < 0x80) {
  17956. v += f(c);
  17957. this._pos_++;
  17958. len--;
  17959. }
  17960. else {
  17961. ulen = c - 0x80;
  17962. this._pos_++;
  17963. len -= ulen;
  17964. while (ulen > 0) {
  17965. c = u[this._pos_++];
  17966. c2 = u[this._pos_++];
  17967. v += f((c2 << 8) | c);
  17968. ulen--;
  17969. }
  17970. }
  17971. }
  17972. return v;
  17973. }
  17974. get pos() {
  17975. return this._pos_;
  17976. }
  17977. set pos(value) {
  17978. this._pos_ = value;
  17979. }
  17980. get bytesAvailable() {
  17981. return this._length - this._pos_;
  17982. }
  17983. clear() {
  17984. this._pos_ = 0;
  17985. this.length = 0;
  17986. }
  17987. __getBuffer() {
  17988. return this._d_.buffer;
  17989. }
  17990. writeUTFBytes(value) {
  17991. value = value + "";
  17992. for (var i = 0, sz = value.length; i < sz; i++) {
  17993. var c = value.charCodeAt(i);
  17994. if (c <= 0x7F) {
  17995. this.writeByte(c);
  17996. }
  17997. else if (c <= 0x7FF) {
  17998. this._ensureWrite(this._pos_ + 2);
  17999. this._u8d_.set([0xC0 | (c >> 6), 0x80 | (c & 0x3F)], this._pos_);
  18000. this._pos_ += 2;
  18001. }
  18002. else if (c >= 0xD800 && c <= 0xDBFF) {
  18003. i++;
  18004. const c2 = value.charCodeAt(i);
  18005. if (!Number.isNaN(c2) && c2 >= 0xDC00 && c2 <= 0xDFFF) {
  18006. const _p1 = (c & 0x3FF) + 0x40;
  18007. const _p2 = c2 & 0x3FF;
  18008. const _b1 = 0xF0 | ((_p1 >> 8) & 0x3F);
  18009. const _b2 = 0x80 | ((_p1 >> 2) & 0x3F);
  18010. const _b3 = 0x80 | ((_p1 & 0x3) << 4) | ((_p2 >> 6) & 0xF);
  18011. const _b4 = 0x80 | (_p2 & 0x3F);
  18012. this._ensureWrite(this._pos_ + 4);
  18013. this._u8d_.set([_b1, _b2, _b3, _b4], this._pos_);
  18014. this._pos_ += 4;
  18015. }
  18016. }
  18017. else if (c <= 0xFFFF) {
  18018. this._ensureWrite(this._pos_ + 3);
  18019. this._u8d_.set([0xE0 | (c >> 12), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F)], this._pos_);
  18020. this._pos_ += 3;
  18021. }
  18022. else {
  18023. this._ensureWrite(this._pos_ + 4);
  18024. this._u8d_.set([0xF0 | (c >> 18), 0x80 | ((c >> 12) & 0x3F), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F)], this._pos_);
  18025. this._pos_ += 4;
  18026. }
  18027. }
  18028. }
  18029. writeUTFString(value) {
  18030. var tPos = this.pos;
  18031. this.writeUint16(1);
  18032. this.writeUTFBytes(value);
  18033. var dPos = this.pos - tPos - 2;
  18034. this._d_.setUint16(tPos, dPos, this._xd_);
  18035. }
  18036. readUTFString() {
  18037. return this.readUTFBytes(this.getUint16());
  18038. }
  18039. getUTFString() {
  18040. return this.readUTFString();
  18041. }
  18042. readUTFBytes(len = -1) {
  18043. if (len === 0)
  18044. return "";
  18045. var lastBytes = this.bytesAvailable;
  18046. if (len > lastBytes)
  18047. throw "readUTFBytes error - Out of bounds";
  18048. len = len > 0 ? len : lastBytes;
  18049. return this._rUTF(len);
  18050. }
  18051. getUTFBytes(len = -1) {
  18052. return this.readUTFBytes(len);
  18053. }
  18054. writeByte(value) {
  18055. this._ensureWrite(this._pos_ + 1);
  18056. this._d_.setInt8(this._pos_, value);
  18057. this._pos_ += 1;
  18058. }
  18059. readByte() {
  18060. if (this._pos_ + 1 > this._length)
  18061. throw "readByte error - Out of bounds";
  18062. return this._d_.getInt8(this._pos_++);
  18063. }
  18064. getByte() {
  18065. return this.readByte();
  18066. }
  18067. _ensureWrite(lengthToEnsure) {
  18068. if (this._length < lengthToEnsure)
  18069. this._length = lengthToEnsure;
  18070. if (this._allocated_ < lengthToEnsure)
  18071. this.length = lengthToEnsure;
  18072. }
  18073. writeArrayBuffer(arraybuffer, offset = 0, length = 0) {
  18074. if (offset < 0 || length < 0)
  18075. throw "writeArrayBuffer error - Out of bounds";
  18076. if (length == 0)
  18077. length = arraybuffer.byteLength - offset;
  18078. this._ensureWrite(this._pos_ + length);
  18079. var uint8array = new Uint8Array(arraybuffer);
  18080. this._u8d_.set(uint8array.subarray(offset, offset + length), this._pos_);
  18081. this._pos_ += length;
  18082. }
  18083. readArrayBuffer(length) {
  18084. var rst;
  18085. rst = this._u8d_.buffer.slice(this._pos_, this._pos_ + length);
  18086. this._pos_ = this._pos_ + length;
  18087. return rst;
  18088. }
  18089. }
  18090. Byte.BIG_ENDIAN = "bigEndian";
  18091. Byte.LITTLE_ENDIAN = "littleEndian";
  18092. Byte._sysEndian = null;
  18093. class BitmapFont {
  18094. constructor() {
  18095. this._fontCharDic = {};
  18096. this._fontWidthMap = {};
  18097. this._maxWidth = 0;
  18098. this._spaceWidth = 10;
  18099. this.fontSize = 12;
  18100. this.autoScaleSize = false;
  18101. this.letterSpacing = 0;
  18102. }
  18103. loadFont(path, complete) {
  18104. this._path = path;
  18105. this._complete = complete;
  18106. if (!path || path.indexOf(".fnt") === -1) {
  18107. console.error('Bitmap font configuration information must be a ".fnt" file');
  18108. return;
  18109. }
  18110. ILaya.loader.load([{ url: path, type: ILaya.Loader.XML }, { url: path.replace(".fnt", ".png"), type: ILaya.Loader.IMAGE }], Handler.create(this, this._onLoaded));
  18111. }
  18112. _onLoaded() {
  18113. this.parseFont(ILaya.Loader.getRes(this._path), ILaya.Loader.getRes(this._path.replace(".fnt", ".png")));
  18114. this._complete && this._complete.run();
  18115. }
  18116. parseFont(xml, texture) {
  18117. if (xml == null || texture == null)
  18118. return;
  18119. this._texture = texture;
  18120. var tScale = 1;
  18121. var tInfo = xml.getElementsByTagName("info");
  18122. if (!tInfo[0].getAttributeNode) {
  18123. return this.parseFont2(xml, texture);
  18124. }
  18125. this.fontSize = parseInt(tInfo[0].getAttributeNode("size").nodeValue);
  18126. var tPadding = tInfo[0].getAttributeNode("padding").nodeValue;
  18127. var tPaddingArray = tPadding.split(",");
  18128. this._padding = [parseInt(tPaddingArray[0]), parseInt(tPaddingArray[1]), parseInt(tPaddingArray[2]), parseInt(tPaddingArray[3])];
  18129. var chars = xml.getElementsByTagName("char");
  18130. var i = 0;
  18131. for (i = 0; i < chars.length; i++) {
  18132. var tAttribute = chars[i];
  18133. var tId = parseInt(tAttribute.getAttributeNode("id").nodeValue);
  18134. var xOffset = parseInt(tAttribute.getAttributeNode("xoffset").nodeValue) / tScale;
  18135. var yOffset = parseInt(tAttribute.getAttributeNode("yoffset").nodeValue) / tScale;
  18136. var xAdvance = parseInt(tAttribute.getAttributeNode("xadvance").nodeValue) / tScale;
  18137. var region = new Rectangle();
  18138. region.x = parseInt(tAttribute.getAttributeNode("x").nodeValue);
  18139. region.y = parseInt(tAttribute.getAttributeNode("y").nodeValue);
  18140. region.width = parseInt(tAttribute.getAttributeNode("width").nodeValue);
  18141. region.height = parseInt(tAttribute.getAttributeNode("height").nodeValue);
  18142. var tTexture = Texture.create(texture, region.x, region.y, region.width, region.height, xOffset, yOffset);
  18143. this._maxWidth = Math.max(this._maxWidth, xAdvance + this.letterSpacing);
  18144. this._fontCharDic[tId] = tTexture;
  18145. this._fontWidthMap[tId] = xAdvance;
  18146. }
  18147. }
  18148. parseFont2(xml, texture) {
  18149. if (xml == null || texture == null)
  18150. return;
  18151. this._texture = texture;
  18152. var tScale = 1;
  18153. var tInfo = xml.getElementsByTagName("info");
  18154. this.fontSize = parseInt(tInfo[0].attributes["size"].nodeValue);
  18155. var tPadding = tInfo[0].attributes["padding"].nodeValue;
  18156. var tPaddingArray = tPadding.split(",");
  18157. this._padding = [parseInt(tPaddingArray[0]), parseInt(tPaddingArray[1]), parseInt(tPaddingArray[2]), parseInt(tPaddingArray[3])];
  18158. var chars = xml.getElementsByTagName("char");
  18159. var i = 0;
  18160. for (i = 0; i < chars.length; i++) {
  18161. var tAttribute = chars[i].attributes;
  18162. var tId = parseInt(tAttribute["id"].nodeValue);
  18163. var xOffset = parseInt(tAttribute["xoffset"].nodeValue) / tScale;
  18164. var yOffset = parseInt(tAttribute["yoffset"].nodeValue) / tScale;
  18165. var xAdvance = parseInt(tAttribute["xadvance"].nodeValue) / tScale;
  18166. var region = new Rectangle();
  18167. region.x = parseInt(tAttribute["x"].nodeValue);
  18168. region.y = parseInt(tAttribute["y"].nodeValue);
  18169. region.width = parseInt(tAttribute["width"].nodeValue);
  18170. region.height = parseInt(tAttribute["height"].nodeValue);
  18171. var tTexture = Texture.create(texture, region.x, region.y, region.width, region.height, xOffset, yOffset);
  18172. this._maxWidth = Math.max(this._maxWidth, xAdvance + this.letterSpacing);
  18173. this._fontCharDic[tId] = tTexture;
  18174. this._fontWidthMap[tId] = xAdvance;
  18175. }
  18176. }
  18177. getCharTexture(char) {
  18178. return this._fontCharDic[char.charCodeAt(0)];
  18179. }
  18180. destroy() {
  18181. if (this._texture) {
  18182. for (var p in this._fontCharDic) {
  18183. var tTexture = this._fontCharDic[p];
  18184. if (tTexture)
  18185. tTexture.destroy();
  18186. }
  18187. this._texture.destroy();
  18188. this._fontCharDic = null;
  18189. this._fontWidthMap = null;
  18190. this._texture = null;
  18191. this._complete = null;
  18192. this._padding = null;
  18193. }
  18194. }
  18195. setSpaceWidth(spaceWidth) {
  18196. this._spaceWidth = spaceWidth;
  18197. }
  18198. getCharWidth(char) {
  18199. var code = char.charCodeAt(0);
  18200. if (this._fontWidthMap[code])
  18201. return this._fontWidthMap[code] + this.letterSpacing;
  18202. if (char === " ")
  18203. return this._spaceWidth + this.letterSpacing;
  18204. return 0;
  18205. }
  18206. getTextWidth(text) {
  18207. var tWidth = 0;
  18208. for (var i = 0, n = text.length; i < n; i++) {
  18209. tWidth += this.getCharWidth(text.charAt(i));
  18210. }
  18211. return tWidth;
  18212. }
  18213. getMaxWidth() {
  18214. return this._maxWidth;
  18215. }
  18216. getMaxHeight() {
  18217. return this.fontSize;
  18218. }
  18219. _drawText(text, sprite, drawX, drawY, align, width) {
  18220. var tWidth = this.getTextWidth(text);
  18221. var tTexture;
  18222. var dx = 0;
  18223. align === "center" && (dx = (width - tWidth) / 2);
  18224. align === "right" && (dx = (width - tWidth));
  18225. var tx = 0;
  18226. for (var i = 0, n = text.length; i < n; i++) {
  18227. tTexture = this.getCharTexture(text.charAt(i));
  18228. if (tTexture) {
  18229. sprite.graphics.drawImage(tTexture, drawX + tx + dx, drawY);
  18230. tx += this.getCharWidth(text.charAt(i));
  18231. }
  18232. }
  18233. }
  18234. }
  18235. ClassUtils.regClass("laya.display.BitmapFont", BitmapFont);
  18236. ClassUtils.regClass("Laya.BitmapFont", BitmapFont);
  18237. class HttpRequest extends EventDispatcher {
  18238. constructor() {
  18239. super(...arguments);
  18240. this._http = new XMLHttpRequest();
  18241. }
  18242. send(url, data = null, method = "get", responseType = "text", headers = null) {
  18243. this._responseType = responseType;
  18244. this._data = null;
  18245. if (Browser.onVVMiniGame || Browser.onQGMiniGame || Browser.onQQMiniGame || Browser.onAlipayMiniGame || Browser.onBLMiniGame || Browser.onHWMiniGame || Browser.onTTMiniGame) {
  18246. url = HttpRequest._urlEncode(url);
  18247. }
  18248. this._url = url;
  18249. var _this = this;
  18250. var http = this._http;
  18251. url = URL.getAdptedFilePath(url);
  18252. http.open(method, url, true);
  18253. let isJson = false;
  18254. if (headers) {
  18255. for (var i = 0; i < headers.length; i++) {
  18256. http.setRequestHeader(headers[i++], headers[i]);
  18257. }
  18258. }
  18259. else if (!(window.conch)) {
  18260. if (!data || typeof (data) == 'string')
  18261. http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  18262. else {
  18263. http.setRequestHeader("Content-Type", "application/json");
  18264. isJson = true;
  18265. }
  18266. }
  18267. let restype = responseType !== "arraybuffer" ? "text" : "arraybuffer";
  18268. http.responseType = restype;
  18269. if (http.dataType) {
  18270. http.dataType = restype;
  18271. }
  18272. http.onerror = function (e) {
  18273. _this._onError(e);
  18274. };
  18275. http.onabort = function (e) {
  18276. _this._onAbort(e);
  18277. };
  18278. http.onprogress = function (e) {
  18279. _this._onProgress(e);
  18280. };
  18281. http.onload = function (e) {
  18282. _this._onLoad(e);
  18283. };
  18284. if (Browser.onBLMiniGame && Browser.onAndroid && !data)
  18285. data = {};
  18286. http.send(isJson ? JSON.stringify(data) : data);
  18287. }
  18288. _onProgress(e) {
  18289. if (e && e.lengthComputable)
  18290. this.event(Event.PROGRESS, e.loaded / e.total);
  18291. }
  18292. _onAbort(e) {
  18293. this.error("Request was aborted by user");
  18294. }
  18295. _onError(e) {
  18296. this.error("Request failed Status:" + this._http.status + " text:" + this._http.statusText);
  18297. }
  18298. _onLoad(e) {
  18299. var http = this._http;
  18300. var status = http.status !== undefined ? http.status : 200;
  18301. if (status === 200 || status === 204 || status === 0) {
  18302. this.complete();
  18303. }
  18304. else {
  18305. this.error("[" + http.status + "]" + http.statusText + ":" + http.responseURL);
  18306. }
  18307. }
  18308. error(message) {
  18309. this.clear();
  18310. console.warn(this.url, message);
  18311. this.event(Event.ERROR, message);
  18312. }
  18313. complete() {
  18314. this.clear();
  18315. var flag = true;
  18316. try {
  18317. if (this._responseType === "json") {
  18318. this._data = JSON.parse(this._http.responseText);
  18319. }
  18320. else if (this._responseType === "xml") {
  18321. this._data = Utils.parseXMLFromString(this._http.responseText);
  18322. }
  18323. else {
  18324. this._data = this._http.response || this._http.responseText;
  18325. }
  18326. }
  18327. catch (e) {
  18328. flag = false;
  18329. this.error(e.message);
  18330. }
  18331. flag && this.event(Event.COMPLETE, this._data instanceof Array ? [this._data] : this._data);
  18332. }
  18333. clear() {
  18334. var http = this._http;
  18335. http.onerror = http.onabort = http.onprogress = http.onload = null;
  18336. }
  18337. get url() {
  18338. return this._url;
  18339. }
  18340. get data() {
  18341. return this._data;
  18342. }
  18343. get http() {
  18344. return this._http;
  18345. }
  18346. }
  18347. HttpRequest._urlEncode = encodeURI;
  18348. class Loader extends EventDispatcher {
  18349. constructor() {
  18350. super(...arguments);
  18351. this._customParse = false;
  18352. }
  18353. static getTypeFromUrl(url) {
  18354. var type = Utils.getFileExtension(url);
  18355. if (type)
  18356. return Loader.typeMap[type];
  18357. console.warn("Not recognize the resources suffix", url);
  18358. return "text";
  18359. }
  18360. load(url, type = null, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
  18361. if (!url) {
  18362. this.onLoaded(null);
  18363. return;
  18364. }
  18365. Loader.setGroup(url, "666");
  18366. this._url = url;
  18367. if (url.indexOf("data:image") === 0)
  18368. type = Loader.IMAGE;
  18369. else
  18370. url = URL.formatURL(url);
  18371. this._type = type || (type = Loader.getTypeFromUrl(this._url));
  18372. this._cache = cache;
  18373. this._useWorkerLoader = useWorkerLoader;
  18374. this._data = null;
  18375. if (useWorkerLoader)
  18376. ILaya.WorkerLoader.enableWorkerLoader();
  18377. var cacheRes;
  18378. if (type == Loader.IMAGE)
  18379. cacheRes = Loader.textureMap[url];
  18380. else
  18381. cacheRes = Loader.loadedMap[url];
  18382. if (!ignoreCache && cacheRes) {
  18383. this._data = cacheRes;
  18384. this.event(Event.PROGRESS, 1);
  18385. this.event(Event.COMPLETE, this._data);
  18386. return;
  18387. }
  18388. if (group)
  18389. Loader.setGroup(url, group);
  18390. if (Loader.parserMap[type] != null) {
  18391. this._customParse = true;
  18392. if (Loader.parserMap[type] instanceof Handler)
  18393. Loader.parserMap[type].runWith(this);
  18394. else
  18395. Loader.parserMap[type].call(null, this);
  18396. return;
  18397. }
  18398. this._loadResourceFilter(type, url);
  18399. }
  18400. _loadResourceFilter(type, url) {
  18401. this._loadResource(type, url);
  18402. }
  18403. _loadResource(type, url) {
  18404. switch (type) {
  18405. case Loader.IMAGE:
  18406. case "htmlimage":
  18407. case "nativeimage":
  18408. this._loadImage(url);
  18409. break;
  18410. case Loader.SOUND:
  18411. this._loadSound(url);
  18412. break;
  18413. case Loader.TTF:
  18414. this._loadTTF(url);
  18415. break;
  18416. case Loader.ATLAS:
  18417. case Loader.PREFAB:
  18418. case Loader.PLF:
  18419. this._loadHttpRequestWhat(url, Loader.JSON);
  18420. break;
  18421. case Loader.FONT:
  18422. this._loadHttpRequestWhat(url, Loader.XML);
  18423. break;
  18424. case Loader.PLFB:
  18425. this._loadHttpRequestWhat(url, Loader.BUFFER);
  18426. break;
  18427. default:
  18428. this._loadHttpRequestWhat(url, type);
  18429. }
  18430. }
  18431. _loadHttpRequest(url, contentType, onLoadCaller, onLoad, onProcessCaller, onProcess, onErrorCaller, onError) {
  18432. if (Browser.onVVMiniGame || Browser.onHWMiniGame) {
  18433. this._http = new HttpRequest();
  18434. }
  18435. else {
  18436. if (!this._http)
  18437. this._http = new HttpRequest();
  18438. }
  18439. onProcess && this._http.on(Event.PROGRESS, onProcessCaller, onProcess);
  18440. onLoad && this._http.on(Event.COMPLETE, onLoadCaller, onLoad);
  18441. this._http.on(Event.ERROR, onErrorCaller, onError);
  18442. this._http.send(url, null, "get", contentType);
  18443. }
  18444. _loadHtmlImage(url, onLoadCaller, onLoad, onErrorCaller, onError) {
  18445. var image;
  18446. function clear() {
  18447. var img = image;
  18448. img.onload = null;
  18449. img.onerror = null;
  18450. delete Loader._imgCache[url];
  18451. }
  18452. var onerror = function () {
  18453. clear();
  18454. onError.call(onErrorCaller);
  18455. };
  18456. var onload = function () {
  18457. clear();
  18458. onLoad.call(onLoadCaller, image);
  18459. };
  18460. image = new Browser.window.Image();
  18461. image.crossOrigin = "anonymous";
  18462. image.onload = onload;
  18463. image.onerror = onerror;
  18464. image.src = url;
  18465. Loader._imgCache[url] = image;
  18466. }
  18467. _loadHttpRequestWhat(url, contentType) {
  18468. if (Loader.preLoadedMap[url])
  18469. this.onLoaded(Loader.preLoadedMap[url]);
  18470. else
  18471. this._loadHttpRequest(url, contentType, this, this.onLoaded, this, this.onProgress, this, this.onError);
  18472. }
  18473. _loadTTF(url) {
  18474. url = URL.formatURL(url);
  18475. var ttfLoader = new ILaya.TTFLoader();
  18476. ttfLoader.complete = Handler.create(this, this.onLoaded);
  18477. ttfLoader.load(url);
  18478. }
  18479. _loadImage(url, isformatURL = true) {
  18480. var _this = this;
  18481. if (isformatURL)
  18482. url = URL.formatURL(url);
  18483. var onError = function () {
  18484. _this.event(Event.ERROR, "Load image failed");
  18485. };
  18486. if (this._type === "nativeimage") {
  18487. this._loadHtmlImage(url, this, this.onLoaded, this, onError);
  18488. }
  18489. else {
  18490. var ext = Utils.getFileExtension(url);
  18491. if (ext === "ktx" || ext === "pvr")
  18492. this._loadHttpRequest(url, Loader.BUFFER, this, this.onLoaded, this, this.onProgress, this, this.onError);
  18493. else
  18494. this._loadHtmlImage(url, this, this.onLoaded, this, onError);
  18495. }
  18496. }
  18497. _loadSound(url) {
  18498. var sound = (new SoundManager._soundClass());
  18499. var _this = this;
  18500. sound.on(Event.COMPLETE, this, soundOnload);
  18501. sound.on(Event.ERROR, this, soundOnErr);
  18502. sound.load(url);
  18503. function soundOnload() {
  18504. clear();
  18505. _this.onLoaded(sound);
  18506. }
  18507. function soundOnErr() {
  18508. clear();
  18509. sound.dispose();
  18510. _this.event(Event.ERROR, "Load sound failed");
  18511. }
  18512. function clear() {
  18513. sound.offAll();
  18514. }
  18515. }
  18516. onProgress(value) {
  18517. if (this._type === Loader.ATLAS)
  18518. this.event(Event.PROGRESS, value * 0.3);
  18519. else if (this._originType == Loader.HIERARCHY)
  18520. this.event(Event.PROGRESS, value / 3);
  18521. else
  18522. this.event(Event.PROGRESS, value);
  18523. }
  18524. onError(message) {
  18525. this.event(Event.ERROR, message);
  18526. }
  18527. onLoaded(data = null) {
  18528. var type = this._type;
  18529. if (type == Loader.PLFB) {
  18530. this.parsePLFBData(data);
  18531. this.complete(data);
  18532. }
  18533. else if (type == Loader.PLF) {
  18534. this.parsePLFData(data);
  18535. this.complete(data);
  18536. }
  18537. else if (type === Loader.IMAGE) {
  18538. let tex;
  18539. if (data instanceof ArrayBuffer) {
  18540. var ext = Utils.getFileExtension(this._url);
  18541. let format;
  18542. switch (ext) {
  18543. case "ktx":
  18544. format = exports.TextureFormat.ETC1RGB;
  18545. break;
  18546. case "pvr":
  18547. format = exports.TextureFormat.PVRTCRGBA_4BPPV;
  18548. break;
  18549. default: {
  18550. console.error('unknown format', ext);
  18551. return;
  18552. }
  18553. }
  18554. tex = new Texture2D(0, 0, format, false, false);
  18555. tex.wrapModeU = exports.WarpMode.Clamp;
  18556. tex.wrapModeV = exports.WarpMode.Clamp;
  18557. tex.setCompressData(data);
  18558. tex._setCreateURL(this.url);
  18559. }
  18560. else if (!(data instanceof Texture2D)) {
  18561. tex = new Texture2D(data.width, data.height, 1, false, false);
  18562. tex.wrapModeU = exports.WarpMode.Clamp;
  18563. tex.wrapModeV = exports.WarpMode.Clamp;
  18564. tex.loadImageSource(data, true);
  18565. tex._setCreateURL(data.src);
  18566. }
  18567. else {
  18568. tex = data;
  18569. }
  18570. var texture = new Texture(tex);
  18571. texture.url = this._url;
  18572. this.complete(texture);
  18573. }
  18574. else if (type === Loader.SOUND || type === "nativeimage") {
  18575. this.complete(data);
  18576. }
  18577. else if (type === "htmlimage") {
  18578. let tex = new Texture2D(data.width, data.height, 1, false, false);
  18579. tex.wrapModeU = exports.WarpMode.Clamp;
  18580. tex.wrapModeV = exports.WarpMode.Clamp;
  18581. tex.loadImageSource(data, true);
  18582. tex._setCreateURL(data.src);
  18583. this.complete(tex);
  18584. }
  18585. else if (type === Loader.ATLAS) {
  18586. if (data.frames) {
  18587. var toloadPics = [];
  18588. if (!this._data) {
  18589. this._data = data;
  18590. if (data.meta && data.meta.image) {
  18591. toloadPics = data.meta.image.split(",");
  18592. var split = this._url.indexOf("/") >= 0 ? "/" : "\\";
  18593. var idx = this._url.lastIndexOf(split);
  18594. var folderPath = idx >= 0 ? this._url.substr(0, idx + 1) : "";
  18595. var changeType = null;
  18596. if (Browser.onAndroid && data.meta.compressTextureAndroid) {
  18597. changeType = ".ktx";
  18598. }
  18599. if (Browser.onIOS && data.meta.compressTextureIOS) {
  18600. changeType = ".pvr";
  18601. }
  18602. for (var i = 0, len = toloadPics.length; i < len; i++) {
  18603. if (changeType) {
  18604. toloadPics[i] = folderPath + toloadPics[i].replace(".png", changeType);
  18605. }
  18606. else {
  18607. toloadPics[i] = folderPath + toloadPics[i];
  18608. }
  18609. }
  18610. }
  18611. else {
  18612. toloadPics = [this._url.replace(".json", ".png")];
  18613. }
  18614. toloadPics.reverse();
  18615. data.toLoads = toloadPics;
  18616. data.pics = [];
  18617. }
  18618. this.event(Event.PROGRESS, 0.3 + 1 / toloadPics.length * 0.6);
  18619. return this._loadResourceFilter(Loader.IMAGE, toloadPics.pop());
  18620. }
  18621. else {
  18622. if (!(data instanceof Texture2D)) {
  18623. let tex = new Texture2D(data.width, data.height, 1, false, false);
  18624. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  18625. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  18626. tex.loadImageSource(data, true);
  18627. tex._setCreateURL(data.src);
  18628. data = tex;
  18629. }
  18630. this._data.pics.push(data);
  18631. if (this._data.toLoads.length > 0) {
  18632. this.event(Event.PROGRESS, 0.3 + 1 / this._data.toLoads.length * 0.6);
  18633. return this._loadResourceFilter(Loader.IMAGE, this._data.toLoads.pop());
  18634. }
  18635. var frames = this._data.frames;
  18636. var cleanUrl = this._url.split("?")[0];
  18637. var directory = (this._data.meta && this._data.meta.prefix) ? this._data.meta.prefix : cleanUrl.substring(0, cleanUrl.lastIndexOf(".")) + "/";
  18638. var pics = this._data.pics;
  18639. var atlasURL = URL.formatURL(this._url);
  18640. var map = Loader.atlasMap[atlasURL] || (Loader.atlasMap[atlasURL] = []);
  18641. map.dir = directory;
  18642. var scaleRate = 1;
  18643. if (this._data.meta && this._data.meta.scale && this._data.meta.scale != 1) {
  18644. scaleRate = parseFloat(this._data.meta.scale);
  18645. for (var name in frames) {
  18646. if(AtlasInfoManager.isResLang(directory + name)) continue;//图集中文件,在其它语言版本中有对应的资源,则不做处理
  18647. var obj = frames[name];
  18648. var tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18649. var url = URL.formatURL(directory + name);
  18650. tPic.scaleRate = scaleRate;
  18651. var tTexture;
  18652. tTexture = Texture._create(tPic, obj.frame.x, obj.frame.y, obj.frame.w, obj.frame.h, obj.spriteSourceSize.x, obj.spriteSourceSize.y, obj.sourceSize.w, obj.sourceSize.h, Loader.getRes(url));
  18653. Loader.cacheTexture(url, tTexture);
  18654. tTexture.url = url;
  18655. map.push(url);
  18656. }
  18657. }
  18658. else {
  18659. for (name in frames) {
  18660. if(AtlasInfoManager.isResLang(directory + name)) continue;//图集中文件,在其它语言版本中有对应的资源,则不做处理
  18661. obj = frames[name];
  18662. tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18663. url = URL.formatURL(directory + name);
  18664. tTexture = Texture._create(tPic, obj.frame.x, obj.frame.y, obj.frame.w, obj.frame.h, obj.spriteSourceSize.x, obj.spriteSourceSize.y, obj.sourceSize.w, obj.sourceSize.h, Loader.getRes(url));
  18665. Loader.cacheTexture(url, tTexture);
  18666. tTexture.url = url;
  18667. map.push(url);
  18668. }
  18669. }
  18670. delete this._data.pics;
  18671. this.complete(this._data);
  18672. }
  18673. }
  18674. else if (type === Loader.FONT) {
  18675. if (!data._source) {
  18676. this._data = data;
  18677. this.event(Event.PROGRESS, 0.5);
  18678. return this._loadResourceFilter(Loader.IMAGE, this._url.replace(".fnt", ".png"));
  18679. }
  18680. else {
  18681. var bFont = new BitmapFont();
  18682. bFont.parseFont(this._data, new Texture(data));
  18683. var tArr = this._url.split(".fnt")[0].split("/");
  18684. var fontName = tArr[tArr.length - 1];
  18685. Text.registerBitmapFont(fontName, bFont);
  18686. this._data = bFont;
  18687. this.complete(this._data);
  18688. }
  18689. }
  18690. else if (type === Loader.PREFAB) {
  18691. var prefab = new Prefab();
  18692. prefab.json = data;
  18693. this.complete(prefab);
  18694. }
  18695. else {
  18696. this.complete(data);
  18697. }
  18698. }
  18699. parsePLFData(plfData) {
  18700. var type;
  18701. var filePath;
  18702. var fileDic;
  18703. for (type in plfData) {
  18704. fileDic = plfData[type];
  18705. switch (type) {
  18706. case "json":
  18707. case "text":
  18708. for (filePath in fileDic) {
  18709. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18710. }
  18711. break;
  18712. default:
  18713. for (filePath in fileDic) {
  18714. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18715. }
  18716. }
  18717. }
  18718. }
  18719. parsePLFBData(plfData) {
  18720. var byte;
  18721. byte = new Byte(plfData);
  18722. var i, len;
  18723. len = byte.getInt32();
  18724. for (i = 0; i < len; i++) {
  18725. this.parseOnePLFBFile(byte);
  18726. }
  18727. }
  18728. parseOnePLFBFile(byte) {
  18729. var fileLen;
  18730. var fileName;
  18731. var fileData;
  18732. fileName = byte.getUTFString();
  18733. fileLen = byte.getInt32();
  18734. fileData = byte.readArrayBuffer(fileLen);
  18735. Loader.preLoadedMap[URL.formatURL(fileName)] = fileData;
  18736. }
  18737. complete(data) {
  18738. this._data = data;
  18739. if (this._customParse) {
  18740. this.event(Event.LOADED, data instanceof Array ? [data] : data);
  18741. }
  18742. else {
  18743. Loader._loaders.push(this);
  18744. if (!Loader._isWorking)
  18745. Loader.checkNext();
  18746. }
  18747. }
  18748. static checkNext() {
  18749. Loader._isWorking = true;
  18750. var startTimer = Browser.now();
  18751. while (Loader._startIndex < Loader._loaders.length) {
  18752. Loader._loaders[Loader._startIndex].endLoad();
  18753. Loader._startIndex++;
  18754. if (Browser.now() - startTimer > Loader.maxTimeOut) {
  18755. console.warn("loader callback cost a long time:" + (Browser.now() - startTimer) + " url=" + Loader._loaders[Loader._startIndex - 1].url);
  18756. ILaya.systemTimer.frameOnce(1, null, Loader.checkNext);
  18757. return;
  18758. }
  18759. }
  18760. Loader._loaders.length = 0;
  18761. Loader._startIndex = 0;
  18762. Loader._isWorking = false;
  18763. }
  18764. endLoad(content = null) {
  18765. content && (this._data = content);
  18766. if (this._cache)
  18767. Loader.cacheRes(this._url, this._data);
  18768. this.event(Event.PROGRESS, 1);
  18769. this.event(Event.COMPLETE, this.data instanceof Array ? [this.data] : this.data);
  18770. }
  18771. get url() {
  18772. return this._url;
  18773. }
  18774. get type() {
  18775. return this._type;
  18776. }
  18777. get cache() {
  18778. return this._cache;
  18779. }
  18780. get data() {
  18781. return this._data;
  18782. }
  18783. static clearRes(url) {
  18784. url = URL.formatURL(url);
  18785. var arr = Loader.getAtlas(url);
  18786. if (arr) {
  18787. for (var i = 0, n = arr.length; i < n; i++) {
  18788. var resUrl = arr[i];
  18789. var tex = Loader.getRes(resUrl);
  18790. delete Loader.textureMap[resUrl];
  18791. if (tex)
  18792. tex.destroy();
  18793. }
  18794. arr.length = 0;
  18795. delete Loader.atlasMap[url];
  18796. }
  18797. var texture = Loader.textureMap[url];
  18798. if (texture) {
  18799. texture.destroy();
  18800. delete Loader.textureMap[url];
  18801. }
  18802. var res = Loader.loadedMap[url];
  18803. (res) && (delete Loader.loadedMap[url]);
  18804. }
  18805. static clearTextureRes(url) {
  18806. url = URL.formatURL(url);
  18807. var arr = Loader.getAtlas(url);
  18808. if (arr && arr.length > 0) {
  18809. arr.forEach(function (t) {
  18810. var tex = Loader.getRes(t);
  18811. if (tex instanceof Texture) {
  18812. tex.disposeBitmap();
  18813. }
  18814. });
  18815. }
  18816. else {
  18817. var t = Loader.getRes(url);
  18818. if (t instanceof Texture) {
  18819. t.disposeBitmap();
  18820. }
  18821. }
  18822. }
  18823. static getRes(url) {
  18824. var res = Loader.textureMap[URL.formatURL(url)];
  18825. if (res)
  18826. return res;
  18827. else
  18828. return Loader.loadedMap[URL.formatURL(url)];
  18829. }
  18830. static getAtlas(url) {
  18831. return Loader.atlasMap[URL.formatURL(url)];
  18832. }
  18833. static cacheRes(url, data) {
  18834. url = URL.formatURL(url);
  18835. if (Loader.loadedMap[url] != null) {
  18836. console.warn("Resources already exist,is repeated loading:", url);
  18837. }
  18838. else {
  18839. if (data instanceof Texture) {
  18840. Loader.loadedMap[url] = data.bitmap;
  18841. Loader.textureMap[url] = data;
  18842. }
  18843. else {
  18844. Loader.loadedMap[url] = data;
  18845. }
  18846. }
  18847. }
  18848. static cacheTexture(url, data) {
  18849. url = URL.formatURL(url);
  18850. if (Loader.textureMap[url] != null) {
  18851. console.warn("Resources already exist,is repeated loading:", url);
  18852. }
  18853. else {
  18854. Loader.textureMap[url] = data;
  18855. }
  18856. }
  18857. static setGroup(url, group) {
  18858. if (!Loader.groupMap[group])
  18859. Loader.groupMap[group] = [];
  18860. Loader.groupMap[group].push(url);
  18861. }
  18862. static clearResByGroup(group) {
  18863. if (!Loader.groupMap[group])
  18864. return;
  18865. var arr = Loader.groupMap[group], i, len = arr.length;
  18866. for (i = 0; i < len; i++) {
  18867. Loader.clearRes(arr[i]);
  18868. }
  18869. arr.length = 0;
  18870. }
  18871. }
  18872. Loader.TEXT = "text";
  18873. Loader.JSON = "json";
  18874. Loader.PREFAB = "prefab";
  18875. Loader.XML = "xml";
  18876. Loader.BUFFER = "arraybuffer";
  18877. Loader.IMAGE = "image";
  18878. Loader.SOUND = "sound";
  18879. Loader.ATLAS = "atlas";
  18880. Loader.FONT = "font";
  18881. Loader.TTF = "ttf";
  18882. Loader.PLF = "plf";
  18883. Loader.PLFB = "plfb";
  18884. Loader.HIERARCHY = "HIERARCHY";
  18885. Loader.MESH = "MESH";
  18886. Loader.MATERIAL = "MATERIAL";
  18887. Loader.TEXTURE2D = "TEXTURE2D";
  18888. Loader.TEXTURECUBE = "TEXTURECUBE";
  18889. Loader.ANIMATIONCLIP = "ANIMATIONCLIP";
  18890. Loader.AVATAR = "AVATAR";
  18891. Loader.TERRAINHEIGHTDATA = "TERRAINHEIGHTDATA";
  18892. Loader.TERRAINRES = "TERRAIN";
  18893. Loader.typeMap = { "ttf": "ttf", "png": "image", "jpg": "image", "jpeg": "image", "ktx": "image", "pvr": "image", "txt": "text", "json": "json", "prefab": "prefab", "xml": "xml", "als": "atlas", "atlas": "atlas", "mp3": "sound", "ogg": "sound", "wav": "sound", "part": "json", "fnt": "font", "plf": "plf", "plfb": "plfb", "scene": "json", "ani": "json", "sk": "arraybuffer" };
  18894. Loader.parserMap = {};
  18895. Loader.maxTimeOut = 100;
  18896. Loader.groupMap = {};
  18897. Loader.loadedMap = {};
  18898. Loader.atlasMap = {};
  18899. Loader.textureMap = {};
  18900. Loader.preLoadedMap = {};
  18901. Loader._imgCache = {};
  18902. Loader._loaders = [];
  18903. Loader._isWorking = false;
  18904. Loader._startIndex = 0;
  18905. class AtlasInfoManager {
  18906. static enable(infoFile, callback = null) {
  18907. ILaya.loader.load(infoFile, Handler.create(null, AtlasInfoManager._onInfoLoaded, [callback]), null, Loader.JSON);
  18908. }
  18909. static _onInfoLoaded(callback, data) {
  18910. var tKey;
  18911. var tPrefix;
  18912. var tArr;
  18913. var i, len;
  18914. for (tKey in data) {
  18915. tArr = data[tKey];
  18916. tPrefix = tArr[0];
  18917. tArr = tArr[1];
  18918. len = tArr.length;
  18919. for (i = 0; i < len; i++) {
  18920. AtlasInfoManager._fileLoadDic[tPrefix + tArr[i]] = tKey;
  18921. }
  18922. }
  18923. callback && callback.run();
  18924. }
  18925. static getFileLoadPath(file) {
  18926. return AtlasInfoManager._fileLoadDic[file] || file;
  18927. }
  18928. static getFileLoadMapPath(file) {
  18929. return file;
  18930. }
  18931. static isResLang(file) {
  18932. return false;
  18933. }
  18934. }
  18935. AtlasInfoManager._fileLoadDic = {};
  18936. class LoaderManager extends EventDispatcher {
  18937. constructor() {
  18938. super();
  18939. this.retryNum = 1;
  18940. this.retryDelay = 0;
  18941. this.maxLoader = 5;
  18942. this._loaders = [];
  18943. this._loaderCount = 0;
  18944. this._resInfos = [];
  18945. this._infoPool = [];
  18946. this._maxPriority = 5;
  18947. this._failRes = {};
  18948. this._statInfo = { count: 1, loaded: 1 };
  18949. for (var i = 0; i < this._maxPriority; i++)
  18950. this._resInfos[i] = [];
  18951. }
  18952. getProgress() {
  18953. return this._statInfo.loaded / this._statInfo.count;
  18954. }
  18955. resetProgress() {
  18956. this._statInfo.count = this._statInfo.loaded = 1;
  18957. }
  18958. create(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18959. this._create(url, true, complete, progress, type, constructParams, propertyParams, priority, cache);
  18960. }
  18961. _create(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18962. if (url instanceof Array) {
  18963. var allScuess = true;
  18964. var items = url;
  18965. var itemCount = items.length;
  18966. var loadedCount = 0;
  18967. if (progress) {
  18968. var progress2 = Handler.create(progress.caller, progress ? progress.method : null, progress.args, false);
  18969. }
  18970. for (var i = 0; i < itemCount; i++) {
  18971. var item = items[i];
  18972. if (typeof (item) == 'string')
  18973. item = items[i] = { url: item };
  18974. item.progress = 0;
  18975. }
  18976. for (i = 0; i < itemCount; i++) {
  18977. item = items[i];
  18978. var progressHandler = progress ? Handler.create(null, function (item, value) {
  18979. item.progress = value;
  18980. var num = 0;
  18981. for (var j = 0; j < itemCount; j++) {
  18982. var item1 = items[j];
  18983. num += item1.progress;
  18984. }
  18985. var v = num / itemCount;
  18986. progress2.runWith(v);
  18987. }, [item], false) : null;
  18988. var completeHandler = (progress || complete) ? Handler.create(null, function (item, content = null) {
  18989. loadedCount++;
  18990. item.progress = 1;
  18991. content || (allScuess = false);
  18992. if (loadedCount === itemCount && complete) {
  18993. complete.runWith(allScuess);
  18994. }
  18995. }, [item]) : null;
  18996. this._createOne(item.url, mainResou, completeHandler, progressHandler, item.type || type, item.constructParams || constructParams, item.propertyParams || propertyParams, item.priority || priority, cache);
  18997. }
  18998. }
  18999. else {
  19000. this._createOne(url, mainResou, complete, progress, type, constructParams, propertyParams, priority, cache);
  19001. }
  19002. }
  19003. _createOne(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  19004. var item = this.getRes(url);
  19005. if (!item) {
  19006. var extension = (LoaderManager.createMap[Utils.getFilecompatibleExtension(url)]) ? Utils.getFilecompatibleExtension(url) : Utils.getFileExtension(url);
  19007. (type) || (type = LoaderManager.createMap[extension] ? LoaderManager.createMap[extension][0] : null);
  19008. if (!type) {
  19009. this.load(url, complete, progress, type, priority, cache);
  19010. return;
  19011. }
  19012. var parserMap = Loader.parserMap;
  19013. if (!parserMap[type]) {
  19014. this.load(url, complete, progress, type, priority, cache);
  19015. return;
  19016. }
  19017. this._createLoad(url, Handler.create(null, function (createRes) {
  19018. if (createRes) {
  19019. if (!mainResou && createRes instanceof Resource)
  19020. createRes._addReference();
  19021. createRes._setCreateURL(url);
  19022. }
  19023. complete && complete.runWith(createRes);
  19024. ILaya.loader.event(url);
  19025. }), progress, type, constructParams, propertyParams, priority, cache, true);
  19026. }
  19027. else {
  19028. if (!mainResou && item instanceof Resource)
  19029. item._addReference();
  19030. progress && progress.runWith(1);
  19031. complete && complete.runWith(item);
  19032. }
  19033. }
  19034. load(url, complete = null, progress = null, type = null, priority = 1, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
  19035. if (url instanceof Array) {
  19036. return this._loadAssets(url, complete, progress, type, priority, cache, group);
  19037. }
  19038. var content;
  19039. if (type === Loader.IMAGE)
  19040. content = Loader.textureMap[URL.formatURL(url)];
  19041. else
  19042. content = Loader.loadedMap[URL.formatURL(url)];
  19043. if (!ignoreCache && content != null) {
  19044. ILaya.systemTimer.callLater(this, function () {
  19045. progress && progress.runWith(1);
  19046. complete && complete.runWith(content instanceof Array ? [content] : content);
  19047. this._loaderCount || this.event(Event.COMPLETE);
  19048. });
  19049. }
  19050. else {
  19051. var original;
  19052. url = AtlasInfoManager.getFileLoadMapPath(url);
  19053. original = url;
  19054. url = AtlasInfoManager.getFileLoadPath(url);
  19055. if (url != original && type !== "nativeimage") {
  19056. type = Loader.ATLAS;
  19057. }
  19058. else {
  19059. original = null;
  19060. }
  19061. var info = LoaderManager._resMap[url];
  19062. if (!info) {
  19063. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  19064. info.url = url;
  19065. info.type = type;
  19066. info.cache = cache;
  19067. info.group = group;
  19068. info.ignoreCache = ignoreCache;
  19069. info.useWorkerLoader = useWorkerLoader;
  19070. info.originalUrl = original;
  19071. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  19072. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  19073. LoaderManager._resMap[url] = info;
  19074. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  19075. this._resInfos[priority].push(info);
  19076. this._statInfo.count++;
  19077. this.event(Event.PROGRESS, this.getProgress());
  19078. this._next();
  19079. }
  19080. else {
  19081. if (complete) {
  19082. if (original) {
  19083. complete && info._createListener(Event.COMPLETE, this, this._resInfoLoaded, [original, complete], false, false);
  19084. }
  19085. else {
  19086. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  19087. }
  19088. }
  19089. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  19090. }
  19091. }
  19092. return this;
  19093. }
  19094. _resInfoLoaded(original, complete) {
  19095. complete.runWith(Loader.getRes(original));
  19096. }
  19097. _createLoad(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true, ignoreCache = false) {
  19098. if (url instanceof Array)
  19099. return this._loadAssets(url, complete, progress, type, priority, cache);
  19100. var content = Loader.getRes(url);
  19101. if (content != null) {
  19102. ILaya.systemTimer.frameOnce(1, this, function () {
  19103. progress && progress.runWith(1);
  19104. complete && complete.runWith(content);
  19105. this._loaderCount || this.event(Event.COMPLETE);
  19106. });
  19107. }
  19108. else {
  19109. var info = LoaderManager._resMap[url];
  19110. if (!info) {
  19111. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  19112. info.url = url;
  19113. info.type = type;
  19114. info.cache = false;
  19115. info.ignoreCache = ignoreCache;
  19116. info.originalUrl = null;
  19117. info.group = null;
  19118. info.createCache = cache;
  19119. info.createConstructParams = constructParams;
  19120. info.createPropertyParams = propertyParams;
  19121. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  19122. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  19123. LoaderManager._resMap[url] = info;
  19124. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  19125. this._resInfos[priority].push(info);
  19126. this._statInfo.count++;
  19127. this.event(Event.PROGRESS, this.getProgress());
  19128. this._next();
  19129. }
  19130. else {
  19131. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  19132. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  19133. }
  19134. }
  19135. return this;
  19136. }
  19137. _next() {
  19138. if (this._loaderCount >= this.maxLoader)
  19139. return;
  19140. for (var i = 0; i < this._maxPriority; i++) {
  19141. var infos = this._resInfos[i];
  19142. while (infos.length > 0) {
  19143. var info = infos.shift();
  19144. if (info)
  19145. return this._doLoad(info);
  19146. }
  19147. }
  19148. this._loaderCount || this.event(Event.COMPLETE);
  19149. }
  19150. _doLoad(resInfo) {
  19151. this._loaderCount++;
  19152. var loader = this._loaders.length ? this._loaders.pop() : new Loader();
  19153. loader.on(Event.COMPLETE, null, onLoaded);
  19154. loader.on(Event.PROGRESS, null, function (num) {
  19155. resInfo.event(Event.PROGRESS, num);
  19156. });
  19157. loader.on(Event.ERROR, null, function (msg) {
  19158. onLoaded(null);
  19159. });
  19160. var _me = this;
  19161. function onLoaded(data = null) {
  19162. loader.offAll();
  19163. loader._data = null;
  19164. loader._customParse = false;
  19165. _me._loaders.push(loader);
  19166. _me._endLoad(resInfo, data instanceof Array ? [data] : data);
  19167. _me._loaderCount--;
  19168. _me._next();
  19169. }
  19170. loader._constructParams = resInfo.createConstructParams;
  19171. loader._propertyParams = resInfo.createPropertyParams;
  19172. loader._createCache = resInfo.createCache;
  19173. loader.load(resInfo.url, resInfo.type, resInfo.cache, resInfo.group, resInfo.ignoreCache, resInfo.useWorkerLoader);
  19174. }
  19175. _endLoad(resInfo, content) {
  19176. var url = resInfo.url;
  19177. if (content == null) {
  19178. var errorCount = this._failRes[url] || 0;
  19179. if (errorCount < this.retryNum) {
  19180. console.warn("[warn]Retry to load:", url);
  19181. this._failRes[url] = errorCount + 1;
  19182. ILaya.systemTimer.once(this.retryDelay, this, this._addReTry, [resInfo], false);
  19183. return;
  19184. }
  19185. else {
  19186. Loader.clearRes(url);
  19187. console.warn("[error]Failed to load:", url);
  19188. this.event(Event.ERROR, url);
  19189. }
  19190. }
  19191. if (this._failRes[url])
  19192. this._failRes[url] = 0;
  19193. delete LoaderManager._resMap[url];
  19194. if (resInfo.originalUrl) {
  19195. content = Loader.getRes(resInfo.originalUrl);
  19196. }
  19197. resInfo.event(Event.COMPLETE, content);
  19198. resInfo.offAll();
  19199. this._infoPool.push(resInfo);
  19200. this._statInfo.loaded++;
  19201. this.event(Event.PROGRESS, this.getProgress());
  19202. }
  19203. _addReTry(resInfo) {
  19204. this._resInfos[this._maxPriority - 1].push(resInfo);
  19205. this._next();
  19206. }
  19207. clearRes(url) {
  19208. Loader.clearRes(url);
  19209. }
  19210. clearTextureRes(url) {
  19211. Loader.clearTextureRes(url);
  19212. }
  19213. getRes(url) {
  19214. return Loader.getRes(url);
  19215. }
  19216. cacheRes(url, data) {
  19217. Loader.cacheRes(url, data);
  19218. }
  19219. setGroup(url, group) {
  19220. Loader.setGroup(url, group);
  19221. }
  19222. clearResByGroup(group) {
  19223. Loader.clearResByGroup(group);
  19224. }
  19225. static cacheRes(url, data) {
  19226. Loader.cacheRes(url, data);
  19227. }
  19228. clearUnLoaded() {
  19229. for (var i = 0; i < this._maxPriority; i++) {
  19230. var infos = this._resInfos[i];
  19231. for (var j = infos.length - 1; j > -1; j--) {
  19232. var info = infos[j];
  19233. if (info) {
  19234. info.offAll();
  19235. this._infoPool.push(info);
  19236. }
  19237. }
  19238. infos.length = 0;
  19239. }
  19240. this._loaderCount = 0;
  19241. LoaderManager._resMap = {};
  19242. }
  19243. cancelLoadByUrls(urls) {
  19244. if (!urls)
  19245. return;
  19246. for (var i = 0, n = urls.length; i < n; i++) {
  19247. this.cancelLoadByUrl(urls[i]);
  19248. }
  19249. }
  19250. cancelLoadByUrl(url) {
  19251. for (var i = 0; i < this._maxPriority; i++) {
  19252. var infos = this._resInfos[i];
  19253. for (var j = infos.length - 1; j > -1; j--) {
  19254. var info = infos[j];
  19255. if (info && info.url === url) {
  19256. infos[j] = null;
  19257. info.offAll();
  19258. this._infoPool.push(info);
  19259. }
  19260. }
  19261. }
  19262. if (LoaderManager._resMap[url])
  19263. delete LoaderManager._resMap[url];
  19264. }
  19265. _loadAssets(arr, complete = null, progress = null, type = null, priority = 1, cache = true, group = null) {
  19266. var itemCount = arr.length;
  19267. var loadedCount = 0;
  19268. var totalSize = 0;
  19269. var items = [];
  19270. var success = true;
  19271. for (var i = 0; i < itemCount; i++) {
  19272. let url = arr[i];
  19273. let item;
  19274. if (typeof (url) == 'string')
  19275. item = { url: url, type: type, size: 1, priority: priority };
  19276. else
  19277. item = url;
  19278. if (!item.size)
  19279. item.size = 1;
  19280. item.progress = 0;
  19281. totalSize += item.size;
  19282. items.push(item);
  19283. var progressHandler = progress ? Handler.create(null, loadProgress, [item], false) : null;
  19284. var completeHandler = (complete || progress) ? Handler.create(null, loadComplete, [item]) : null;
  19285. this.load(item.url, completeHandler, progressHandler, item.type, item.priority || 1, cache, item.group || group, false, item.useWorkerLoader);
  19286. }
  19287. function loadComplete(item, content = null) {
  19288. loadedCount++;
  19289. item.progress = 1;
  19290. if (!content)
  19291. success = false;
  19292. if (loadedCount === itemCount && complete) {
  19293. complete.runWith(success);
  19294. }
  19295. }
  19296. function loadProgress(item, value) {
  19297. if (progress != null) {
  19298. item.progress = value;
  19299. var num = 0;
  19300. for (var j = 0; j < items.length; j++) {
  19301. var item1 = items[j];
  19302. if (item1) {
  19303. let prog = item1.progress == undefined ? 0 : item1.progress;
  19304. num += item1.size == undefined ? 0 : item1.size * prog;
  19305. }
  19306. }
  19307. var v = num / totalSize;
  19308. progress.runWith(v);
  19309. }
  19310. }
  19311. return this;
  19312. }
  19313. decodeBitmaps(urls) {
  19314. var i, len = urls.length;
  19315. var ctx;
  19316. ctx = ILaya.Render._context;
  19317. for (i = 0; i < len; i++) {
  19318. var atlas;
  19319. atlas = Loader.getAtlas(urls[i]);
  19320. if (atlas) {
  19321. this._decodeTexture(atlas[0], ctx);
  19322. }
  19323. else {
  19324. var tex;
  19325. tex = this.getRes(urls[i]);
  19326. if (tex && tex instanceof Texture) {
  19327. this._decodeTexture(tex, ctx);
  19328. }
  19329. }
  19330. }
  19331. }
  19332. _decodeTexture(tex, ctx) {
  19333. var bitmap = tex.bitmap;
  19334. if (!tex || !bitmap)
  19335. return;
  19336. var tImg = bitmap.source || bitmap.image;
  19337. if (!tImg)
  19338. return;
  19339. if (tImg instanceof HTMLImageElement) {
  19340. ctx.drawImage(tImg, 0, 0, 1, 1);
  19341. var info = ctx.getImageData(0, 0, 1, 1);
  19342. }
  19343. }
  19344. }
  19345. LoaderManager._resMap = {};
  19346. LoaderManager.createMap = { atlas: [null, Loader.ATLAS] };
  19347. class ResInfo extends EventDispatcher {
  19348. }
  19349. class LocalStorage {
  19350. static __init__() {
  19351. if (!LocalStorage._baseClass) {
  19352. LocalStorage._baseClass = Storage;
  19353. Storage.init();
  19354. }
  19355. LocalStorage.items = LocalStorage._baseClass.items;
  19356. LocalStorage.support = LocalStorage._baseClass.support;
  19357. return LocalStorage.support;
  19358. }
  19359. static setItem(key, value) {
  19360. LocalStorage._baseClass.setItem(key, value);
  19361. }
  19362. static getItem(key) {
  19363. return LocalStorage._baseClass.getItem(key);
  19364. }
  19365. static setJSON(key, value) {
  19366. LocalStorage._baseClass.setJSON(key, value);
  19367. }
  19368. static getJSON(key) {
  19369. return LocalStorage._baseClass.getJSON(key);
  19370. }
  19371. static removeItem(key) {
  19372. LocalStorage._baseClass.removeItem(key);
  19373. }
  19374. static clear() {
  19375. LocalStorage._baseClass.clear();
  19376. }
  19377. }
  19378. LocalStorage.support = false;
  19379. class Storage {
  19380. static init() {
  19381. try {
  19382. Storage.support = true;
  19383. Storage.items = window.localStorage;
  19384. Storage.setItem('laya', '1');
  19385. Storage.removeItem('laya');
  19386. }
  19387. catch (e) {
  19388. Storage.support = false;
  19389. }
  19390. if (!Storage.support)
  19391. console.log('LocalStorage is not supprot or browser is private mode.');
  19392. }
  19393. static setItem(key, value) {
  19394. try {
  19395. Storage.support && Storage.items.setItem(key, value);
  19396. }
  19397. catch (e) {
  19398. console.warn("set localStorage failed", e);
  19399. }
  19400. }
  19401. static getItem(key) {
  19402. return Storage.support ? Storage.items.getItem(key) : null;
  19403. }
  19404. static setJSON(key, value) {
  19405. try {
  19406. Storage.support && Storage.items.setItem(key, JSON.stringify(value));
  19407. }
  19408. catch (e) {
  19409. console.warn("set localStorage failed", e);
  19410. }
  19411. }
  19412. static getJSON(key) {
  19413. try {
  19414. let obj = JSON.parse(Storage.support ? Storage.items.getItem(key) : null);
  19415. return obj;
  19416. }
  19417. catch (err) {
  19418. return Storage.items.getItem(key);
  19419. }
  19420. }
  19421. static removeItem(key) {
  19422. Storage.support && Storage.items.removeItem(key);
  19423. }
  19424. static clear() {
  19425. Storage.support && Storage.items.clear();
  19426. }
  19427. }
  19428. Storage.support = false;
  19429. class TTFLoader {
  19430. load(fontPath) {
  19431. this._url = fontPath;
  19432. var tArr = fontPath.split(".ttf")[0].split("/");
  19433. this.fontName = tArr[tArr.length - 1];
  19434. if (ILaya.Render.isConchApp) {
  19435. this._loadConch();
  19436. }
  19437. else if (window.FontFace) {
  19438. this._loadWithFontFace();
  19439. }
  19440. else {
  19441. this._loadWithCSS();
  19442. }
  19443. }
  19444. _loadConch() {
  19445. this._http = new HttpRequest();
  19446. this._http.on(Event.ERROR, this, this._onErr);
  19447. this._http.on(Event.COMPLETE, this, this._onHttpLoaded);
  19448. this._http.send(this._url, null, "get", Loader.BUFFER);
  19449. }
  19450. _onHttpLoaded(data = null) {
  19451. window["conchTextCanvas"].setFontFaceFromBuffer(this.fontName, data);
  19452. this._clearHttp();
  19453. this._complete();
  19454. }
  19455. _clearHttp() {
  19456. if (this._http) {
  19457. this._http.off(Event.ERROR, this, this._onErr);
  19458. this._http.off(Event.COMPLETE, this, this._onHttpLoaded);
  19459. this._http = null;
  19460. }
  19461. }
  19462. _onErr() {
  19463. this._clearHttp();
  19464. if (this.err) {
  19465. this.err.runWith("fail:" + this._url);
  19466. this.err = null;
  19467. }
  19468. }
  19469. _complete() {
  19470. ILaya.systemTimer.clear(this, this._complete);
  19471. ILaya.systemTimer.clear(this, this._checkComplete);
  19472. if (this._div && this._div.parentNode) {
  19473. this._div.parentNode.removeChild(this._div);
  19474. this._div = null;
  19475. }
  19476. if (this.complete) {
  19477. this.complete.runWith(this);
  19478. this.complete = null;
  19479. }
  19480. }
  19481. _checkComplete() {
  19482. if (ILaya.Browser.measureText(TTFLoader._testString, this._fontTxt).width != this._txtWidth) {
  19483. this._complete();
  19484. }
  19485. }
  19486. _loadWithFontFace() {
  19487. var fontFace = new window.FontFace(this.fontName, "url('" + this._url + "')");
  19488. document.fonts.add(fontFace);
  19489. var self = this;
  19490. fontFace.loaded.then((function () {
  19491. self._complete();
  19492. }));
  19493. fontFace.load();
  19494. }
  19495. _createDiv() {
  19496. this._div = Browser.createElement("div");
  19497. this._div.innerHTML = "laya";
  19498. var _style = this._div.style;
  19499. _style.fontFamily = this.fontName;
  19500. _style.position = "absolute";
  19501. _style.left = "-100px";
  19502. _style.top = "-100px";
  19503. document.body.appendChild(this._div);
  19504. }
  19505. _loadWithCSS() {
  19506. var fontStyle = Browser.createElement("style");
  19507. fontStyle.type = "text/css";
  19508. document.body.appendChild(fontStyle);
  19509. fontStyle.textContent = "@font-face { font-family:'" + this.fontName + "'; src:url('" + this._url + "');}";
  19510. this._fontTxt = "40px " + this.fontName;
  19511. this._txtWidth = Browser.measureText(TTFLoader._testString, this._fontTxt).width;
  19512. var self = this;
  19513. fontStyle.onload = function () {
  19514. ILaya.systemTimer.once(10000, self, self._complete);
  19515. };
  19516. ILaya.systemTimer.loop(20, this, this._checkComplete);
  19517. this._createDiv();
  19518. }
  19519. }
  19520. TTFLoader._testString = "LayaTTFFont";
  19521. class Ease {
  19522. static linearNone(t, b, c, d) {
  19523. return c * t / d + b;
  19524. }
  19525. static linearIn(t, b, c, d) {
  19526. return c * t / d + b;
  19527. }
  19528. static linearInOut(t, b, c, d) {
  19529. return c * t / d + b;
  19530. }
  19531. static linearOut(t, b, c, d) {
  19532. return c * t / d + b;
  19533. }
  19534. static bounceIn(t, b, c, d) {
  19535. return c - Ease.bounceOut(d - t, 0, c, d) + b;
  19536. }
  19537. static bounceInOut(t, b, c, d) {
  19538. if (t < d * 0.5)
  19539. return Ease.bounceIn(t * 2, 0, c, d) * .5 + b;
  19540. else
  19541. return Ease.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  19542. }
  19543. static bounceOut(t, b, c, d) {
  19544. if ((t /= d) < (1 / 2.75))
  19545. return c * (7.5625 * t * t) + b;
  19546. else if (t < (2 / 2.75))
  19547. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  19548. else if (t < (2.5 / 2.75))
  19549. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  19550. else
  19551. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  19552. }
  19553. static backIn(t, b, c, d, s = 1.70158) {
  19554. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  19555. }
  19556. static backInOut(t, b, c, d, s = 1.70158) {
  19557. if ((t /= d * 0.5) < 1)
  19558. return c * 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  19559. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  19560. }
  19561. static backOut(t, b, c, d, s = 1.70158) {
  19562. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  19563. }
  19564. static elasticIn(t, b, c, d, a = 0, p = 0) {
  19565. var s;
  19566. if (t == 0)
  19567. return b;
  19568. if ((t /= d) == 1)
  19569. return b + c;
  19570. if (!p)
  19571. p = d * .3;
  19572. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19573. a = c;
  19574. s = p / 4;
  19575. }
  19576. else
  19577. s = p / Ease.PI2 * Math.asin(c / a);
  19578. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19579. }
  19580. static elasticInOut(t, b, c, d, a = 0, p = 0) {
  19581. var s;
  19582. if (t == 0)
  19583. return b;
  19584. if ((t /= d * 0.5) == 2)
  19585. return b + c;
  19586. if (!p)
  19587. p = d * (.3 * 1.5);
  19588. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19589. a = c;
  19590. s = p / 4;
  19591. }
  19592. else
  19593. s = p / Ease.PI2 * Math.asin(c / a);
  19594. if (t < 1)
  19595. return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19596. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p) * .5 + c + b;
  19597. }
  19598. static elasticOut(t, b, c, d, a = 0, p = 0) {
  19599. var s;
  19600. if (t == 0)
  19601. return b;
  19602. if ((t /= d) == 1)
  19603. return b + c;
  19604. if (!p)
  19605. p = d * .3;
  19606. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19607. a = c;
  19608. s = p / 4;
  19609. }
  19610. else
  19611. s = p / Ease.PI2 * Math.asin(c / a);
  19612. return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * Ease.PI2 / p) + c + b);
  19613. }
  19614. static strongIn(t, b, c, d) {
  19615. return c * (t /= d) * t * t * t * t + b;
  19616. }
  19617. static strongInOut(t, b, c, d) {
  19618. if ((t /= d * 0.5) < 1)
  19619. return c * 0.5 * t * t * t * t * t + b;
  19620. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19621. }
  19622. static strongOut(t, b, c, d) {
  19623. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19624. }
  19625. static sineInOut(t, b, c, d) {
  19626. return -c * 0.5 * (Math.cos(Math.PI * t / d) - 1) + b;
  19627. }
  19628. static sineIn(t, b, c, d) {
  19629. return -c * Math.cos(t / d * Ease.HALF_PI) + c + b;
  19630. }
  19631. static sineOut(t, b, c, d) {
  19632. return c * Math.sin(t / d * Ease.HALF_PI) + b;
  19633. }
  19634. static quintIn(t, b, c, d) {
  19635. return c * (t /= d) * t * t * t * t + b;
  19636. }
  19637. static quintInOut(t, b, c, d) {
  19638. if ((t /= d * 0.5) < 1)
  19639. return c * 0.5 * t * t * t * t * t + b;
  19640. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19641. }
  19642. static quintOut(t, b, c, d) {
  19643. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19644. }
  19645. static quartIn(t, b, c, d) {
  19646. return c * (t /= d) * t * t * t + b;
  19647. }
  19648. static quartInOut(t, b, c, d) {
  19649. if ((t /= d * 0.5) < 1)
  19650. return c * 0.5 * t * t * t * t + b;
  19651. return -c * 0.5 * ((t -= 2) * t * t * t - 2) + b;
  19652. }
  19653. static quartOut(t, b, c, d) {
  19654. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  19655. }
  19656. static cubicIn(t, b, c, d) {
  19657. return c * (t /= d) * t * t + b;
  19658. }
  19659. static cubicInOut(t, b, c, d) {
  19660. if ((t /= d * 0.5) < 1)
  19661. return c * 0.5 * t * t * t + b;
  19662. return c * 0.5 * ((t -= 2) * t * t + 2) + b;
  19663. }
  19664. static cubicOut(t, b, c, d) {
  19665. return c * ((t = t / d - 1) * t * t + 1) + b;
  19666. }
  19667. static quadIn(t, b, c, d) {
  19668. return c * (t /= d) * t + b;
  19669. }
  19670. static quadInOut(t, b, c, d) {
  19671. if ((t /= d * 0.5) < 1)
  19672. return c * 0.5 * t * t + b;
  19673. return -c * 0.5 * ((--t) * (t - 2) - 1) + b;
  19674. }
  19675. static quadOut(t, b, c, d) {
  19676. return -c * (t /= d) * (t - 2) + b;
  19677. }
  19678. static expoIn(t, b, c, d) {
  19679. return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b - c * 0.001;
  19680. }
  19681. static expoInOut(t, b, c, d) {
  19682. if (t == 0)
  19683. return b;
  19684. if (t == d)
  19685. return b + c;
  19686. if ((t /= d * 0.5) < 1)
  19687. return c * 0.5 * Math.pow(2, 10 * (t - 1)) + b;
  19688. return c * 0.5 * (-Math.pow(2, -10 * --t) + 2) + b;
  19689. }
  19690. static expoOut(t, b, c, d) {
  19691. return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  19692. }
  19693. static circIn(t, b, c, d) {
  19694. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  19695. }
  19696. static circInOut(t, b, c, d) {
  19697. if ((t /= d * 0.5) < 1)
  19698. return -c * 0.5 * (Math.sqrt(1 - t * t) - 1) + b;
  19699. return c * 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  19700. }
  19701. static circOut(t, b, c, d) {
  19702. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  19703. }
  19704. }
  19705. Ease.HALF_PI = Math.PI * 0.5;
  19706. Ease.PI2 = Math.PI * 2;
  19707. class Tween {
  19708. constructor() {
  19709. this.gid = 0;
  19710. this.repeat = 1;
  19711. this._count = 0;
  19712. }
  19713. static to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19714. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, true, autoRecover, true);
  19715. }
  19716. static from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19717. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, false, autoRecover, true);
  19718. }
  19719. to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19720. return this._create(target, props, duration, ease, complete, delay, coverBefore, true, false, true);
  19721. }
  19722. from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19723. return this._create(target, props, duration, ease, complete, delay, coverBefore, false, false, true);
  19724. }
  19725. _create(target, props, duration, ease, complete, delay, coverBefore, isTo, usePool, runNow) {
  19726. if (!target)
  19727. throw new Error("Tween:target is null");
  19728. this._target = target;
  19729. this._duration = duration;
  19730. this._ease = ease || props.ease || Tween.easeNone;
  19731. this._complete = complete || props.complete;
  19732. this._delay = delay;
  19733. this._props = [];
  19734. this._usedTimer = 0;
  19735. this._startTimer = Browser.now();
  19736. this._usedPool = usePool;
  19737. this._delayParam = null;
  19738. this.update = props.update;
  19739. var gid = (target.$_GID || (target.$_GID = Utils.getGID()));
  19740. if (!Tween.tweenMap[gid]) {
  19741. Tween.tweenMap[gid] = [this];
  19742. }
  19743. else {
  19744. if (coverBefore)
  19745. Tween.clearTween(target);
  19746. Tween.tweenMap[gid].push(this);
  19747. }
  19748. if (runNow) {
  19749. if (delay <= 0)
  19750. this.firstStart(target, props, isTo);
  19751. else {
  19752. this._delayParam = [target, props, isTo];
  19753. ILaya.timer.once(delay, this, this.firstStart, this._delayParam);
  19754. }
  19755. }
  19756. else {
  19757. this._initProps(target, props, isTo);
  19758. }
  19759. return this;
  19760. }
  19761. firstStart(target, props, isTo) {
  19762. this._delayParam = null;
  19763. if (target.destroyed) {
  19764. this.clear();
  19765. return;
  19766. }
  19767. this._initProps(target, props, isTo);
  19768. this._beginLoop();
  19769. }
  19770. _initProps(target, props, isTo) {
  19771. for (var p in props) {
  19772. if (typeof (target[p]) == 'number') {
  19773. var start = isTo ? target[p] : props[p];
  19774. var end = isTo ? props[p] : target[p];
  19775. this._props.push([p, start, end - start]);
  19776. if (!isTo)
  19777. target[p] = start;
  19778. }
  19779. }
  19780. }
  19781. _beginLoop() {
  19782. ILaya.timer.frameLoop(1, this, this._doEase);
  19783. }
  19784. _doEase() {
  19785. this._updateEase(Browser.now());
  19786. }
  19787. _updateEase(time) {
  19788. var target = this._target;
  19789. if (!target)
  19790. return;
  19791. if (target.destroyed)
  19792. return Tween.clearTween(target);
  19793. var usedTimer = this._usedTimer = time - this._startTimer - this._delay;
  19794. if (usedTimer < 0)
  19795. return;
  19796. if (usedTimer >= this._duration)
  19797. return this.complete();
  19798. var ratio = usedTimer > 0 ? this._ease(usedTimer, 0, 1, this._duration) : 0;
  19799. var props = this._props;
  19800. for (var i = 0, n = props.length; i < n; i++) {
  19801. var prop = props[i];
  19802. target[prop[0]] = prop[1] + (ratio * prop[2]);
  19803. }
  19804. if (this.update)
  19805. this.update.run();
  19806. }
  19807. set progress(v) {
  19808. var uTime = v * this._duration;
  19809. this._startTimer = Browser.now() - this._delay - uTime;
  19810. }
  19811. complete() {
  19812. if (!this._target)
  19813. return;
  19814. ILaya.timer.runTimer(this, this.firstStart);
  19815. var target = this._target;
  19816. var props = this._props;
  19817. var handler = this._complete;
  19818. for (var i = 0, n = props.length; i < n; i++) {
  19819. var prop = props[i];
  19820. target[prop[0]] = prop[1] + prop[2];
  19821. }
  19822. if (this.update)
  19823. this.update.run();
  19824. this._count++;
  19825. if (this.repeat != 0 && this._count >= this.repeat) {
  19826. this.clear();
  19827. handler && handler.run();
  19828. }
  19829. else {
  19830. this.restart();
  19831. }
  19832. }
  19833. pause() {
  19834. ILaya.timer.clear(this, this._beginLoop);
  19835. ILaya.timer.clear(this, this._doEase);
  19836. ILaya.timer.clear(this, this.firstStart);
  19837. var time = Browser.now();
  19838. var dTime;
  19839. dTime = time - this._startTimer - this._delay;
  19840. if (dTime < 0) {
  19841. this._usedTimer = dTime;
  19842. }
  19843. }
  19844. setStartTime(startTime) {
  19845. this._startTimer = startTime;
  19846. }
  19847. static clearAll(target) {
  19848. if (!target || !target.$_GID)
  19849. return;
  19850. var tweens = Tween.tweenMap[target.$_GID];
  19851. if (tweens) {
  19852. for (var i = 0, n = tweens.length; i < n; i++) {
  19853. tweens[i]._clear();
  19854. }
  19855. tweens.length = 0;
  19856. }
  19857. }
  19858. static clear(tween) {
  19859. tween.clear();
  19860. }
  19861. static clearTween(target) {
  19862. Tween.clearAll(target);
  19863. }
  19864. clear() {
  19865. if (this._target) {
  19866. this._remove();
  19867. this._clear();
  19868. }
  19869. }
  19870. _clear() {
  19871. this.pause();
  19872. ILaya.timer.clear(this, this.firstStart);
  19873. this._complete = null;
  19874. this._target = null;
  19875. this._ease = null;
  19876. this._props = null;
  19877. this._delayParam = null;
  19878. this.repeat = 1;
  19879. if (this._usedPool) {
  19880. this.update = null;
  19881. Pool.recover("tween", this);
  19882. }
  19883. }
  19884. recover() {
  19885. this._usedPool = true;
  19886. this._clear();
  19887. }
  19888. _remove() {
  19889. var tweens = Tween.tweenMap[this._target.$_GID];
  19890. if (tweens) {
  19891. for (var i = 0, n = tweens.length; i < n; i++) {
  19892. if (tweens[i] === this) {
  19893. tweens.splice(i, 1);
  19894. break;
  19895. }
  19896. }
  19897. }
  19898. }
  19899. restart() {
  19900. this.pause();
  19901. this._usedTimer = 0;
  19902. this._startTimer = Browser.now();
  19903. if (this._delayParam) {
  19904. ILaya.timer.once(this._delay, this, this.firstStart, this._delayParam);
  19905. return;
  19906. }
  19907. var props = this._props;
  19908. for (var i = 0, n = props.length; i < n; i++) {
  19909. var prop = props[i];
  19910. this._target[prop[0]] = prop[1];
  19911. }
  19912. ILaya.timer.once(this._delay, this, this._beginLoop);
  19913. }
  19914. resume() {
  19915. if (this._usedTimer >= this._duration)
  19916. return;
  19917. this._startTimer = Browser.now() - this._usedTimer - this._delay;
  19918. if (this._delayParam) {
  19919. if (this._usedTimer < 0) {
  19920. ILaya.timer.once(-this._usedTimer, this, this.firstStart, this._delayParam);
  19921. }
  19922. else {
  19923. this.firstStart.apply(this, this._delayParam);
  19924. }
  19925. }
  19926. else {
  19927. this._beginLoop();
  19928. }
  19929. }
  19930. static easeNone(t, b, c, d) {
  19931. return c * t / d + b;
  19932. }
  19933. }
  19934. Tween.tweenMap = [];
  19935. class Dragging {
  19936. constructor() {
  19937. this.ratio = 0.92;
  19938. this.maxOffset = 60;
  19939. this._dragging = false;
  19940. this._clickOnly = true;
  19941. }
  19942. start(target, area, hasInertia, elasticDistance, elasticBackTime, data, disableMouseEvent, ratio = 0.92) {
  19943. this.clearTimer();
  19944. this.target = target;
  19945. this.area = area;
  19946. this.hasInertia = hasInertia;
  19947. this.elasticDistance = area ? elasticDistance : 0;
  19948. this.elasticBackTime = elasticBackTime;
  19949. this.data = data;
  19950. this._disableMouseEvent = disableMouseEvent;
  19951. this.ratio = ratio;
  19952. this._parent = target.parent;
  19953. this._clickOnly = true;
  19954. this._dragging = true;
  19955. this._elasticRateX = this._elasticRateY = 1;
  19956. this._lastX = this._parent.mouseX;
  19957. this._lastY = this._parent.mouseY;
  19958. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  19959. ILaya.stage.on(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19960. ILaya.systemTimer.frameLoop(1, this, this.loop);
  19961. }
  19962. clearTimer() {
  19963. ILaya.systemTimer.clear(this, this.loop);
  19964. ILaya.systemTimer.clear(this, this.tweenMove);
  19965. if (this._tween) {
  19966. this._tween.recover();
  19967. this._tween = null;
  19968. }
  19969. }
  19970. stop() {
  19971. if (this._dragging) {
  19972. MouseManager.instance.disableMouseEvent = false;
  19973. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  19974. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19975. this._dragging = false;
  19976. this.target && this.area && this.backToArea();
  19977. this.clear();
  19978. }
  19979. }
  19980. loop() {
  19981. var point = this._parent.getMousePoint();
  19982. var mouseX = point.x;
  19983. var mouseY = point.y;
  19984. var offsetX = mouseX - this._lastX;
  19985. var offsetY = mouseY - this._lastY;
  19986. if (this._clickOnly) {
  19987. if (Math.abs(offsetX * ILaya.stage._canvasTransform.getScaleX()) > 1 || Math.abs(offsetY * ILaya.stage._canvasTransform.getScaleY()) > 1) {
  19988. this._clickOnly = false;
  19989. this._offsets || (this._offsets = []);
  19990. this._offsets.length = 0;
  19991. this.target.event(Event.DRAG_START, this.data);
  19992. MouseManager.instance.disableMouseEvent = this._disableMouseEvent;
  19993. }
  19994. else
  19995. return;
  19996. }
  19997. else {
  19998. this._offsets.push(offsetX, offsetY);
  19999. }
  20000. if (offsetX === 0 && offsetY === 0)
  20001. return;
  20002. this._lastX = mouseX;
  20003. this._lastY = mouseY;
  20004. this.target.x += offsetX * this._elasticRateX;
  20005. this.target.y += offsetY * this._elasticRateY;
  20006. this.area && this.checkArea();
  20007. this.target.event(Event.DRAG_MOVE, this.data);
  20008. }
  20009. checkArea() {
  20010. if (this.elasticDistance <= 0) {
  20011. this.backToArea();
  20012. }
  20013. else {
  20014. if (this.target._x < this.area.x) {
  20015. var offsetX = this.area.x - this.target._x;
  20016. }
  20017. else if (this.target._x > this.area.x + this.area.width) {
  20018. offsetX = this.target._x - this.area.x - this.area.width;
  20019. }
  20020. else {
  20021. offsetX = 0;
  20022. }
  20023. this._elasticRateX = Math.max(0, 1 - (offsetX / this.elasticDistance));
  20024. if (this.target._y < this.area.y) {
  20025. var offsetY = this.area.y - this.target.y;
  20026. }
  20027. else if (this.target._y > this.area.y + this.area.height) {
  20028. offsetY = this.target._y - this.area.y - this.area.height;
  20029. }
  20030. else {
  20031. offsetY = 0;
  20032. }
  20033. this._elasticRateY = Math.max(0, 1 - (offsetY / this.elasticDistance));
  20034. }
  20035. }
  20036. backToArea() {
  20037. this.target.x = Math.min(Math.max(this.target._x, this.area.x), this.area.x + this.area.width);
  20038. this.target.y = Math.min(Math.max(this.target._y, this.area.y), this.area.y + this.area.height);
  20039. }
  20040. onStageMouseUp(e) {
  20041. MouseManager.instance.disableMouseEvent = false;
  20042. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  20043. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  20044. ILaya.systemTimer.clear(this, this.loop);
  20045. if (this._clickOnly || !this.target)
  20046. return;
  20047. if (this.hasInertia) {
  20048. if (this._offsets.length < 1) {
  20049. this._offsets.push(this._parent.mouseX - this._lastX, this._parent.mouseY - this._lastY);
  20050. }
  20051. this._offsetX = this._offsetY = 0;
  20052. var len = this._offsets.length;
  20053. var n = Math.min(len, 6);
  20054. var m = this._offsets.length - n;
  20055. for (var i = len - 1; i > m; i--) {
  20056. this._offsetY += this._offsets[i--];
  20057. this._offsetX += this._offsets[i];
  20058. }
  20059. this._offsetX = this._offsetX / n * 2;
  20060. this._offsetY = this._offsetY / n * 2;
  20061. if (Math.abs(this._offsetX) > this.maxOffset)
  20062. this._offsetX = this._offsetX > 0 ? this.maxOffset : -this.maxOffset;
  20063. if (Math.abs(this._offsetY) > this.maxOffset)
  20064. this._offsetY = this._offsetY > 0 ? this.maxOffset : -this.maxOffset;
  20065. ILaya.systemTimer.frameLoop(1, this, this.tweenMove);
  20066. }
  20067. else if (this.elasticDistance > 0) {
  20068. this.checkElastic();
  20069. }
  20070. else {
  20071. this.clear();
  20072. }
  20073. }
  20074. checkElastic() {
  20075. var tx = NaN;
  20076. var ty = NaN;
  20077. if (this.target.x < this.area.x)
  20078. tx = this.area.x;
  20079. else if (this.target._x > this.area.x + this.area.width)
  20080. tx = this.area.x + this.area.width;
  20081. if (this.target.y < this.area.y)
  20082. ty = this.area.y;
  20083. else if (this.target._y > this.area.y + this.area.height)
  20084. ty = this.area.y + this.area.height;
  20085. if (!isNaN(tx) || !isNaN(ty)) {
  20086. var obj = {};
  20087. if (!isNaN(tx))
  20088. obj.x = tx;
  20089. if (!isNaN(ty))
  20090. obj.y = ty;
  20091. this._tween = Tween.to(this.target, obj, this.elasticBackTime, Ease.sineOut, Handler.create(this, this.clear), 0, false, false);
  20092. }
  20093. else {
  20094. this.clear();
  20095. }
  20096. }
  20097. tweenMove() {
  20098. this._offsetX *= this.ratio * this._elasticRateX;
  20099. this._offsetY *= this.ratio * this._elasticRateY;
  20100. this.target.x += this._offsetX;
  20101. this.target.y += this._offsetY;
  20102. this.area && this.checkArea();
  20103. this.target.event(Event.DRAG_MOVE, this.data);
  20104. if ((Math.abs(this._offsetX) < 1 && Math.abs(this._offsetY) < 1) || this._elasticRateX < 0.5 || this._elasticRateY < 0.5) {
  20105. ILaya.systemTimer.clear(this, this.tweenMove);
  20106. if (this.elasticDistance > 0)
  20107. this.checkElastic();
  20108. else
  20109. this.clear();
  20110. }
  20111. }
  20112. clear() {
  20113. if (this.target) {
  20114. this.clearTimer();
  20115. var sp = this.target;
  20116. this.target = null;
  20117. this._parent = null;
  20118. sp.event(Event.DRAG_END, this.data);
  20119. }
  20120. }
  20121. }
  20122. class Component {
  20123. constructor() {
  20124. this._id = Utils.getGID();
  20125. this._resetComp();
  20126. }
  20127. get id() {
  20128. return this._id;
  20129. }
  20130. get enabled() {
  20131. return this._enabled;
  20132. }
  20133. set enabled(value) {
  20134. if (this._enabled != value) {
  20135. this._enabled = value;
  20136. if (this.owner) {
  20137. if (value)
  20138. this.owner.activeInHierarchy && this._onEnable();
  20139. else
  20140. this.owner.activeInHierarchy && this._onDisable();
  20141. }
  20142. }
  20143. }
  20144. get isSingleton() {
  20145. return true;
  20146. }
  20147. get destroyed() {
  20148. return this._destroyed;
  20149. }
  20150. _isScript() {
  20151. return false;
  20152. }
  20153. _resetComp() {
  20154. this._indexInList = -1;
  20155. this._enabled = true;
  20156. this._awaked = false;
  20157. this.owner = null;
  20158. }
  20159. _getIndexInList() {
  20160. return this._indexInList;
  20161. }
  20162. _setIndexInList(index) {
  20163. this._indexInList = index;
  20164. }
  20165. _onAdded() {
  20166. }
  20167. _onAwake() {
  20168. }
  20169. _onEnable() {
  20170. }
  20171. _onDisable() {
  20172. }
  20173. _onDestroy() {
  20174. }
  20175. onReset() {
  20176. }
  20177. _parse(data, interactMap = null) {
  20178. }
  20179. _parseInteractive(data = null, spriteMap = null) {
  20180. }
  20181. _cloneTo(dest) {
  20182. }
  20183. _setActive(value) {
  20184. if (value) {
  20185. if (!this._awaked) {
  20186. this._awaked = true;
  20187. this._onAwake();
  20188. }
  20189. this._enabled && this._onEnable();
  20190. }
  20191. else {
  20192. this._enabled && this._onDisable();
  20193. }
  20194. }
  20195. destroy() {
  20196. if (this.owner)
  20197. this.owner._destroyComponent(this);
  20198. }
  20199. _destroy() {
  20200. if (this.owner.activeInHierarchy && this._enabled)
  20201. this._setActive(false);
  20202. this._onDestroy();
  20203. this._destroyed = true;
  20204. if (this.onReset !== Component.prototype.onReset) {
  20205. this.onReset();
  20206. this._resetComp();
  20207. Pool.recoverByClass(this);
  20208. }
  20209. else {
  20210. this._resetComp();
  20211. }
  20212. }
  20213. }
  20214. class AnimationBase extends Sprite {
  20215. constructor() {
  20216. super();
  20217. this.wrapMode = 0;
  20218. this._interval = Config.animationInterval;
  20219. this._isReverse = false;
  20220. this._frameRateChanged = false;
  20221. this._setBitUp(Const.DISPLAY);
  20222. }
  20223. play(start = 0, loop = true, name = "") {
  20224. this._isPlaying = true;
  20225. this._actionName = name;
  20226. this.index = (typeof (start) == 'string') ? this._getFrameByLabel(start) : start;
  20227. this.loop = loop;
  20228. this._isReverse = this.wrapMode === AnimationBase.WRAP_REVERSE;
  20229. if (this.index == 0 && this._isReverse) {
  20230. this.index = this.count - 1;
  20231. }
  20232. if (this.interval > 0)
  20233. this.timerLoop(this.interval, this, this._frameLoop, null, true, true);
  20234. }
  20235. get interval() {
  20236. return this._interval;
  20237. }
  20238. set interval(value) {
  20239. if (this._interval != value) {
  20240. this._frameRateChanged = true;
  20241. this._interval = value;
  20242. if (this._isPlaying && value > 0) {
  20243. this.timerLoop(value, this, this._frameLoop, null, true, true);
  20244. }
  20245. }
  20246. }
  20247. _getFrameByLabel(label) {
  20248. for (var i = 0; i < this._count; i++) {
  20249. var item = this._labels[i];
  20250. if (item && item.indexOf(label) > -1)
  20251. return i;
  20252. }
  20253. return 0;
  20254. }
  20255. _frameLoop() {
  20256. if (this._isReverse) {
  20257. this._index--;
  20258. if (this._index < 0) {
  20259. if (this.loop) {
  20260. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  20261. this._index = this._count > 0 ? 1 : 0;
  20262. this._isReverse = false;
  20263. }
  20264. else {
  20265. this._index = this._count - 1;
  20266. }
  20267. this.event(Event.COMPLETE);
  20268. }
  20269. else {
  20270. this._index = 0;
  20271. this.stop();
  20272. this.event(Event.COMPLETE);
  20273. return;
  20274. }
  20275. }
  20276. }
  20277. else {
  20278. this._index++;
  20279. if (this._index >= this._count) {
  20280. if (this.loop) {
  20281. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  20282. this._index = this._count - 2 >= 0 ? this._count - 2 : 0;
  20283. this._isReverse = true;
  20284. }
  20285. else {
  20286. this._index = 0;
  20287. }
  20288. this.event(Event.COMPLETE);
  20289. }
  20290. else {
  20291. this._index--;
  20292. this.stop();
  20293. this.event(Event.COMPLETE);
  20294. return;
  20295. }
  20296. }
  20297. }
  20298. this.index = this._index;
  20299. }
  20300. _setControlNode(node) {
  20301. if (this._controlNode) {
  20302. this._controlNode.off(Event.DISPLAY, this, this._resumePlay);
  20303. this._controlNode.off(Event.UNDISPLAY, this, this._resumePlay);
  20304. }
  20305. this._controlNode = node;
  20306. if (node && node != this) {
  20307. node.on(Event.DISPLAY, this, this._resumePlay);
  20308. node.on(Event.UNDISPLAY, this, this._resumePlay);
  20309. }
  20310. }
  20311. _setDisplay(value) {
  20312. super._setDisplay(value);
  20313. this._resumePlay();
  20314. }
  20315. _resumePlay() {
  20316. if (this._isPlaying) {
  20317. if (this._controlNode.displayedInStage)
  20318. this.play(this._index, this.loop, this._actionName);
  20319. else
  20320. this.clearTimer(this, this._frameLoop);
  20321. }
  20322. }
  20323. stop() {
  20324. this._isPlaying = false;
  20325. this.clearTimer(this, this._frameLoop);
  20326. }
  20327. get isPlaying() {
  20328. return this._isPlaying;
  20329. }
  20330. addLabel(label, index) {
  20331. if (!this._labels)
  20332. this._labels = {};
  20333. if (!this._labels[index])
  20334. this._labels[index] = [];
  20335. this._labels[index].push(label);
  20336. }
  20337. removeLabel(label) {
  20338. if (!label)
  20339. this._labels = null;
  20340. else if (this._labels) {
  20341. for (var name in this._labels) {
  20342. this._removeLabelFromList(this._labels[name], label);
  20343. }
  20344. }
  20345. }
  20346. _removeLabelFromList(list, label) {
  20347. if (!list)
  20348. return;
  20349. for (var i = list.length - 1; i >= 0; i--) {
  20350. if (list[i] == label) {
  20351. list.splice(i, 1);
  20352. }
  20353. }
  20354. }
  20355. gotoAndStop(position) {
  20356. this.index = (typeof (position) == 'string') ? this._getFrameByLabel(position) : position;
  20357. this.stop();
  20358. }
  20359. get index() {
  20360. return this._index;
  20361. }
  20362. set index(value) {
  20363. this._index = value;
  20364. this._displayToIndex(value);
  20365. if (this._labels && this._labels[value]) {
  20366. var tArr = this._labels[value];
  20367. for (var i = 0, len = tArr.length; i < len; i++) {
  20368. this.event(Event.LABEL, tArr[i]);
  20369. }
  20370. }
  20371. }
  20372. _displayToIndex(value) {
  20373. }
  20374. get count() {
  20375. return this._count;
  20376. }
  20377. clear() {
  20378. this.stop();
  20379. this._labels = null;
  20380. return this;
  20381. }
  20382. }
  20383. AnimationBase.WRAP_POSITIVE = 0;
  20384. AnimationBase.WRAP_REVERSE = 1;
  20385. AnimationBase.WRAP_PINGPONG = 2;
  20386. ClassUtils.regClass("laya.display.AnimationBase", AnimationBase);
  20387. ClassUtils.regClass("Laya.AnimationBase", AnimationBase);
  20388. class MathUtil {
  20389. static subtractVector3(l, r, o) {
  20390. o[0] = l[0] - r[0];
  20391. o[1] = l[1] - r[1];
  20392. o[2] = l[2] - r[2];
  20393. }
  20394. static lerp(left, right, amount) {
  20395. return left * (1 - amount) + right * amount;
  20396. }
  20397. static scaleVector3(f, b, e) {
  20398. e[0] = f[0] * b;
  20399. e[1] = f[1] * b;
  20400. e[2] = f[2] * b;
  20401. }
  20402. static lerpVector3(l, r, t, o) {
  20403. var ax = l[0], ay = l[1], az = l[2];
  20404. o[0] = ax + t * (r[0] - ax);
  20405. o[1] = ay + t * (r[1] - ay);
  20406. o[2] = az + t * (r[2] - az);
  20407. }
  20408. static lerpVector4(l, r, t, o) {
  20409. var ax = l[0], ay = l[1], az = l[2], aw = l[3];
  20410. o[0] = ax + t * (r[0] - ax);
  20411. o[1] = ay + t * (r[1] - ay);
  20412. o[2] = az + t * (r[2] - az);
  20413. o[3] = aw + t * (r[3] - aw);
  20414. }
  20415. static slerpQuaternionArray(a, Offset1, b, Offset2, t, out, Offset3) {
  20416. var ax = a[Offset1 + 0], ay = a[Offset1 + 1], az = a[Offset1 + 2], aw = a[Offset1 + 3], bx = b[Offset2 + 0], by = b[Offset2 + 1], bz = b[Offset2 + 2], bw = b[Offset2 + 3];
  20417. var omega, cosom, sinom, scale0, scale1;
  20418. cosom = ax * bx + ay * by + az * bz + aw * bw;
  20419. if (cosom < 0.0) {
  20420. cosom = -cosom;
  20421. bx = -bx;
  20422. by = -by;
  20423. bz = -bz;
  20424. bw = -bw;
  20425. }
  20426. if ((1.0 - cosom) > 0.000001) {
  20427. omega = Math.acos(cosom);
  20428. sinom = Math.sin(omega);
  20429. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  20430. scale1 = Math.sin(t * omega) / sinom;
  20431. }
  20432. else {
  20433. scale0 = 1.0 - t;
  20434. scale1 = t;
  20435. }
  20436. out[Offset3 + 0] = scale0 * ax + scale1 * bx;
  20437. out[Offset3 + 1] = scale0 * ay + scale1 * by;
  20438. out[Offset3 + 2] = scale0 * az + scale1 * bz;
  20439. out[Offset3 + 3] = scale0 * aw + scale1 * bw;
  20440. return out;
  20441. }
  20442. static getRotation(x0, y0, x1, y1) {
  20443. return Math.atan2(y1 - y0, x1 - x0) / Math.PI * 180;
  20444. }
  20445. static sortBigFirst(a, b) {
  20446. if (a == b)
  20447. return 0;
  20448. return b > a ? 1 : -1;
  20449. }
  20450. static sortSmallFirst(a, b) {
  20451. if (a == b)
  20452. return 0;
  20453. return b > a ? -1 : 1;
  20454. }
  20455. static sortNumBigFirst(a, b) {
  20456. return parseFloat(b) - parseFloat(a);
  20457. }
  20458. static sortNumSmallFirst(a, b) {
  20459. return parseFloat(a) - parseFloat(b);
  20460. }
  20461. static sortByKey(key, bigFirst = false, forceNum = true) {
  20462. var _sortFun;
  20463. if (bigFirst) {
  20464. _sortFun = forceNum ? MathUtil.sortNumBigFirst : MathUtil.sortBigFirst;
  20465. }
  20466. else {
  20467. _sortFun = forceNum ? MathUtil.sortNumSmallFirst : MathUtil.sortSmallFirst;
  20468. }
  20469. return function (a, b) {
  20470. return _sortFun(a[key], b[key]);
  20471. };
  20472. }
  20473. }
  20474. class FrameAnimation extends AnimationBase {
  20475. constructor() {
  20476. super();
  20477. if (FrameAnimation._sortIndexFun === undefined) {
  20478. FrameAnimation._sortIndexFun = MathUtil.sortByKey("index", false, true);
  20479. }
  20480. }
  20481. static _sortIndexFun(objpre, objnext) {
  20482. return objpre.index - objnext.index;
  20483. }
  20484. _setUp(targetDic, animationData) {
  20485. this._targetDic = targetDic;
  20486. this._animationData = animationData;
  20487. this.interval = 1000 / animationData.frameRate;
  20488. if (animationData.parsed) {
  20489. this._count = animationData.count;
  20490. this._labels = animationData.labels;
  20491. this._usedFrames = animationData.animationNewFrames;
  20492. }
  20493. else {
  20494. this._usedFrames = [];
  20495. this._calculateDatas();
  20496. animationData.parsed = true;
  20497. animationData.labels = this._labels;
  20498. animationData.count = this._count;
  20499. animationData.animationNewFrames = this._usedFrames;
  20500. }
  20501. }
  20502. clear() {
  20503. super.clear();
  20504. this._targetDic = null;
  20505. this._animationData = null;
  20506. return this;
  20507. }
  20508. _displayToIndex(value) {
  20509. if (!this._animationData)
  20510. return;
  20511. if (value < 0)
  20512. value = 0;
  20513. if (value > this._count)
  20514. value = this._count;
  20515. var nodes = this._animationData.nodes, i, len = nodes.length;
  20516. for (i = 0; i < len; i++) {
  20517. this._displayNodeToFrame(nodes[i], value);
  20518. }
  20519. }
  20520. _displayNodeToFrame(node, frame, targetDic = null) {
  20521. if (!targetDic)
  20522. targetDic = this._targetDic;
  20523. var target = targetDic[node.target];
  20524. if (!target) {
  20525. return;
  20526. }
  20527. var frames = node.frames, key, propFrames, value;
  20528. var keys = node.keys, i, len = keys.length;
  20529. for (i = 0; i < len; i++) {
  20530. key = keys[i];
  20531. propFrames = frames[key];
  20532. if (propFrames.length > frame) {
  20533. value = propFrames[frame];
  20534. }
  20535. else {
  20536. value = propFrames[propFrames.length - 1];
  20537. }
  20538. target[key] = value;
  20539. }
  20540. var funkeys = node.funkeys;
  20541. len = funkeys.length;
  20542. var funFrames;
  20543. if (len == 0)
  20544. return;
  20545. for (i = 0; i < len; i++) {
  20546. key = funkeys[i];
  20547. funFrames = frames[key];
  20548. if (funFrames[frame] !== undefined) {
  20549. target[key] && target[key].apply(target, funFrames[frame]);
  20550. }
  20551. }
  20552. }
  20553. _calculateDatas() {
  20554. if (!this._animationData)
  20555. return;
  20556. var nodes = this._animationData.nodes, i, len = nodes.length, tNode;
  20557. this._count = 0;
  20558. for (i = 0; i < len; i++) {
  20559. tNode = nodes[i];
  20560. this._calculateKeyFrames(tNode);
  20561. }
  20562. this._count += 1;
  20563. }
  20564. _calculateKeyFrames(node) {
  20565. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  20566. if (!node.frames)
  20567. node.frames = {};
  20568. if (!node.keys)
  20569. node.keys = [];
  20570. else
  20571. node.keys.length = 0;
  20572. if (!node.funkeys)
  20573. node.funkeys = [];
  20574. else
  20575. node.funkeys.length = 0;
  20576. if (!node.initValues)
  20577. node.initValues = {};
  20578. for (key in keyFrames) {
  20579. var isFun = key.indexOf("()") != -1;
  20580. tKeyFrames = keyFrames[key];
  20581. if (isFun)
  20582. key = key.substr(0, key.length - 2);
  20583. if (!node.frames[key]) {
  20584. node.frames[key] = [];
  20585. }
  20586. if (!isFun) {
  20587. if (this._targetDic && this._targetDic[target]) {
  20588. node.initValues[key] = this._targetDic[target][key];
  20589. }
  20590. tKeyFrames.sort(FrameAnimation._sortIndexFun);
  20591. node.keys.push(key);
  20592. this._calculateNodePropFrames(tKeyFrames, node.frames[key], key, target);
  20593. }
  20594. else {
  20595. node.funkeys.push(key);
  20596. var map = node.frames[key];
  20597. for (var i = 0; i < tKeyFrames.length; i++) {
  20598. var temp = tKeyFrames[i];
  20599. map[temp.index] = temp.value;
  20600. if (temp.index > this._count)
  20601. this._count = temp.index;
  20602. }
  20603. }
  20604. }
  20605. }
  20606. resetNodes() {
  20607. if (!this._targetDic)
  20608. return;
  20609. if (!this._animationData)
  20610. return;
  20611. var nodes = this._animationData.nodes, i, len = nodes.length;
  20612. var tNode;
  20613. var initValues;
  20614. for (i = 0; i < len; i++) {
  20615. tNode = nodes[i];
  20616. initValues = tNode.initValues;
  20617. if (!initValues)
  20618. continue;
  20619. var target = this._targetDic[tNode.target];
  20620. if (!target)
  20621. continue;
  20622. var key;
  20623. for (key in initValues) {
  20624. target[key] = initValues[key];
  20625. }
  20626. }
  20627. }
  20628. _calculateNodePropFrames(keyframes, frames, key, target) {
  20629. var i, len = keyframes.length - 1;
  20630. frames.length = keyframes[len].index + 1;
  20631. for (i = 0; i < len; i++) {
  20632. this._dealKeyFrame(keyframes[i]);
  20633. this._calculateFrameValues(keyframes[i], keyframes[i + 1], frames);
  20634. }
  20635. if (len == 0) {
  20636. frames[0] = keyframes[0].value;
  20637. if (this._usedFrames)
  20638. this._usedFrames[keyframes[0].index] = true;
  20639. }
  20640. this._dealKeyFrame(keyframes[i]);
  20641. }
  20642. _dealKeyFrame(keyFrame) {
  20643. if (keyFrame.label && keyFrame.label != "")
  20644. this.addLabel(keyFrame.label, keyFrame.index);
  20645. }
  20646. _calculateFrameValues(startFrame, endFrame, result) {
  20647. var i, easeFun;
  20648. var start = startFrame.index, end = endFrame.index;
  20649. var startValue = startFrame.value;
  20650. var dValue = endFrame.value - startFrame.value;
  20651. var dLen = end - start;
  20652. var frames = this._usedFrames;
  20653. if (end > this._count)
  20654. this._count = end;
  20655. if (startFrame.tween) {
  20656. easeFun = Ease[startFrame.tweenMethod];
  20657. if (easeFun == null)
  20658. easeFun = Ease.linearNone;
  20659. for (i = start; i < end; i++) {
  20660. result[i] = easeFun(i - start, startValue, dValue, dLen);
  20661. if (frames)
  20662. frames[i] = true;
  20663. }
  20664. }
  20665. else {
  20666. for (i = start; i < end; i++) {
  20667. result[i] = startValue;
  20668. }
  20669. }
  20670. if (frames) {
  20671. frames[startFrame.index] = true;
  20672. frames[endFrame.index] = true;
  20673. }
  20674. result[endFrame.index] = endFrame.value;
  20675. }
  20676. }
  20677. ClassUtils.regClass("laya.display.FrameAnimation", FrameAnimation);
  20678. ClassUtils.regClass("Laya.FrameAnimation", FrameAnimation);
  20679. class WeakObject {
  20680. constructor() {
  20681. this._obj = {};
  20682. WeakObject._maps.push(this);
  20683. }
  20684. static __init__() {
  20685. WeakObject.I = new WeakObject();
  20686. if (!WeakObject.supportWeakMap)
  20687. ILaya.systemTimer.loop(WeakObject.delInterval, null, WeakObject.clearCache);
  20688. }
  20689. static clearCache() {
  20690. for (var i = 0, n = WeakObject._maps.length; i < n; i++) {
  20691. var obj = WeakObject._maps[i];
  20692. obj._obj = {};
  20693. }
  20694. }
  20695. set(key, value) {
  20696. if (key == null)
  20697. return;
  20698. if (WeakObject.supportWeakMap) ;
  20699. else {
  20700. if (typeof (key) == 'string' || typeof (key) == 'number') {
  20701. this._obj[key] = value;
  20702. }
  20703. else {
  20704. key.$_GID || (key.$_GID = Utils.getGID());
  20705. this._obj[key.$_GID] = value;
  20706. }
  20707. }
  20708. }
  20709. get(key) {
  20710. if (key == null)
  20711. return null;
  20712. if (WeakObject.supportWeakMap) ;
  20713. else {
  20714. if (typeof (key) == 'string' || typeof (key) == 'number')
  20715. return this._obj[key];
  20716. return this._obj[key.$_GID];
  20717. }
  20718. }
  20719. del(key) {
  20720. if (key == null)
  20721. return;
  20722. if (WeakObject.supportWeakMap) ;
  20723. else {
  20724. if (typeof (key) == 'string' || typeof (key) == 'number')
  20725. delete this._obj[key];
  20726. else
  20727. delete this._obj[this._obj.$_GID];
  20728. }
  20729. }
  20730. has(key) {
  20731. if (key == null)
  20732. return false;
  20733. if (WeakObject.supportWeakMap) ;
  20734. else {
  20735. if (typeof (key) == 'string' || typeof (key) == 'number')
  20736. return this._obj[key] != null;
  20737. return this._obj[this._obj.$_GID] != null;
  20738. }
  20739. }
  20740. }
  20741. WeakObject.supportWeakMap = false;
  20742. WeakObject.delInterval = 10 * 60 * 1000;
  20743. WeakObject._maps = [];
  20744. class SceneUtils {
  20745. static __init() {
  20746. SceneUtils._funMap = new WeakObject();
  20747. }
  20748. static getBindFun(value) {
  20749. var fun = SceneUtils._funMap.get(value);
  20750. if (fun == null) {
  20751. var temp = "\"" + value + "\"";
  20752. temp = temp.replace(/^"\${|}"$/g, "").replace(/\${/g, "\"+").replace(/}/g, "+\"");
  20753. var str = "(function(data){if(data==null)return;with(data){try{\nreturn " + temp + "\n}catch(e){}}})";
  20754. fun = window.Laya._runScript(str);
  20755. SceneUtils._funMap.set(value, fun);
  20756. }
  20757. return fun;
  20758. }
  20759. static createByData(root, uiView) {
  20760. var tInitTool = InitTool.create();
  20761. root = SceneUtils.createComp(uiView, root, root, null, tInitTool);
  20762. root._setBit(Const.NOT_READY, true);
  20763. if ("_idMap" in root) {
  20764. root["_idMap"] = tInitTool._idMap;
  20765. }
  20766. if (uiView.animations) {
  20767. var anilist = [];
  20768. var animations = uiView.animations;
  20769. var i, len = animations.length;
  20770. var tAni;
  20771. var tAniO;
  20772. for (i = 0; i < len; i++) {
  20773. tAni = new FrameAnimation();
  20774. tAniO = animations[i];
  20775. tAni._setUp(tInitTool._idMap, tAniO);
  20776. root[tAniO.name] = tAni;
  20777. tAni._setControlNode(root);
  20778. switch (tAniO.action) {
  20779. case 1:
  20780. tAni.play(0, false);
  20781. break;
  20782. case 2:
  20783. tAni.play(0, true);
  20784. break;
  20785. }
  20786. anilist.push(tAni);
  20787. }
  20788. root._aniList = anilist;
  20789. }
  20790. if (root._$componentType === "Scene" && root._width > 0 && uiView.props.hitTestPrior == null && !root.mouseThrough)
  20791. root.hitTestPrior = true;
  20792. tInitTool.beginLoad(root);
  20793. return root;
  20794. }
  20795. static createInitTool() {
  20796. return InitTool.create();
  20797. }
  20798. static createComp(uiView, comp = null, view = null, dataMap = null, initTool = null) {
  20799. if (uiView.type == "Scene3D" || uiView.type == "Sprite3D") {
  20800. var outBatchSprits = [];
  20801. var scene3D = ILaya.Laya["Utils3D"]._createSceneByJsonForMaker(uiView, outBatchSprits, initTool);
  20802. if (uiView.type == "Sprite3D")
  20803. ILaya.Laya["StaticBatchManager"].combine(scene3D, outBatchSprits);
  20804. else
  20805. ILaya.Laya["StaticBatchManager"].combine(null, outBatchSprits);
  20806. return scene3D;
  20807. }
  20808. comp = comp || SceneUtils.getCompInstance(uiView);
  20809. if (!comp) {
  20810. if (uiView.props && uiView.props.runtime)
  20811. console.warn("runtime not found:" + uiView.props.runtime);
  20812. else
  20813. console.warn("can not create:" + uiView.type);
  20814. return null;
  20815. }
  20816. var child = uiView.child;
  20817. if (child) {
  20818. var isList = comp["_$componentType"] == "List";
  20819. for (var i = 0, n = child.length; i < n; i++) {
  20820. var node = child[i];
  20821. if ('itemRender' in comp && (node.props.name == "render" || node.props.renderType === "render")) {
  20822. comp["itemRender"] = node;
  20823. }
  20824. else if (node.type == "Graphic") {
  20825. ILaya.ClassUtils._addGraphicsToSprite(node, comp);
  20826. }
  20827. else if (ILaya.ClassUtils._isDrawType(node.type)) {
  20828. ILaya.ClassUtils._addGraphicToSprite(node, comp, true);
  20829. }
  20830. else {
  20831. if (isList) {
  20832. var arr = [];
  20833. var tChild = SceneUtils.createComp(node, null, view, arr, initTool);
  20834. if (arr.length)
  20835. tChild["_$bindData"] = arr;
  20836. }
  20837. else {
  20838. tChild = SceneUtils.createComp(node, null, view, dataMap, initTool);
  20839. }
  20840. if (node.type == "Script") {
  20841. if (tChild instanceof Component) {
  20842. comp._addComponentInstance(tChild);
  20843. }
  20844. else {
  20845. if ("owner" in tChild) {
  20846. tChild["owner"] = comp;
  20847. }
  20848. else if ("target" in tChild) {
  20849. tChild["target"] = comp;
  20850. }
  20851. }
  20852. }
  20853. else if (node.props.renderType == "mask" || node.props.name == "mask") {
  20854. comp.mask = tChild;
  20855. }
  20856. else {
  20857. tChild instanceof Node && comp.addChild(tChild);
  20858. }
  20859. }
  20860. }
  20861. }
  20862. var props = uiView.props;
  20863. for (var prop in props) {
  20864. var value = props[prop];
  20865. if (typeof (value) == 'string' && (value.indexOf("@node:") >= 0 || value.indexOf("@Prefab:") >= 0)) {
  20866. if (initTool) {
  20867. initTool.addNodeRef(comp, prop, value);
  20868. }
  20869. }
  20870. else
  20871. SceneUtils.setCompValue(comp, prop, value, view, dataMap);
  20872. }
  20873. if (comp._afterInited) {
  20874. comp._afterInited();
  20875. }
  20876. if (uiView.compId && initTool && initTool._idMap) {
  20877. initTool._idMap[uiView.compId] = comp;
  20878. }
  20879. return comp;
  20880. }
  20881. static setCompValue(comp, prop, value, view = null, dataMap = null) {
  20882. if (typeof (value) == 'string' && value.indexOf("${") > -1) {
  20883. SceneUtils._sheet || (SceneUtils._sheet = ILaya.ClassUtils.getClass("laya.data.Table"));
  20884. if (!SceneUtils._sheet) {
  20885. console.warn("Can not find class Sheet");
  20886. return;
  20887. }
  20888. if (dataMap) {
  20889. dataMap.push(comp, prop, value);
  20890. }
  20891. else if (view) {
  20892. if (value.indexOf("].") == -1) {
  20893. value = value.replace(".", "[0].");
  20894. }
  20895. var watcher = new DataWatcher(comp, prop, value);
  20896. watcher.exe(view);
  20897. var one, temp;
  20898. var str = value.replace(/\[.*?\]\./g, ".");
  20899. while ((one = SceneUtils._parseWatchData.exec(str)) != null) {
  20900. var key1 = one[1];
  20901. while ((temp = SceneUtils._parseKeyWord.exec(key1)) != null) {
  20902. var key2 = temp[0];
  20903. var arr = (view._watchMap[key2] || (view._watchMap[key2] = []));
  20904. arr.push(watcher);
  20905. SceneUtils._sheet.I.notifer.on(key2, view, view.changeData, [key2]);
  20906. }
  20907. arr = (view._watchMap[key1] || (view._watchMap[key1] = []));
  20908. arr.push(watcher);
  20909. SceneUtils._sheet.I.notifer.on(key1, view, view.changeData, [key1]);
  20910. }
  20911. }
  20912. return;
  20913. }
  20914. if (prop === "var" && view) {
  20915. view[value] = comp;
  20916. }
  20917. else {
  20918. comp[prop] = (value === "true" ? true : (value === "false" ? false : value));
  20919. }
  20920. }
  20921. static getCompInstance(json) {
  20922. if (json.type == "UIView") {
  20923. if (json.props && json.props.pageData) {
  20924. return SceneUtils.createByData(null, json.props.pageData);
  20925. }
  20926. }
  20927. var runtime = (json.props && json.props.runtime) || json.type;
  20928. var compClass = ILaya.ClassUtils.getClass(runtime);
  20929. if (!compClass)
  20930. throw "Can not find class " + runtime;
  20931. if (json.type === "Script" && compClass.prototype._doAwake) {
  20932. var comp = Pool.createByClass(compClass);
  20933. comp._destroyed = false;
  20934. return comp;
  20935. }
  20936. if (json.props && "renderType" in json.props && json.props["renderType"] == "instance") {
  20937. if (!compClass["instance"])
  20938. compClass["instance"] = new compClass();
  20939. return compClass["instance"];
  20940. }
  20941. return new compClass();
  20942. }
  20943. }
  20944. SceneUtils._parseWatchData = /\${(.*?)}/g;
  20945. SceneUtils._parseKeyWord = /[a-zA-Z_][a-zA-Z0-9_]*(?:(?:\.[a-zA-Z_][a-zA-Z0-9_]*)+)/g;
  20946. class DataWatcher {
  20947. constructor(comp, prop, value) {
  20948. this.comp = comp;
  20949. this.prop = prop;
  20950. this.value = value;
  20951. }
  20952. exe(view) {
  20953. var fun = SceneUtils.getBindFun(this.value);
  20954. this.comp[this.prop] = fun.call(this, view);
  20955. }
  20956. }
  20957. class InitTool {
  20958. reset() {
  20959. this._nodeRefList = null;
  20960. this._initList = null;
  20961. this._idMap = null;
  20962. this._loadList = null;
  20963. this._scene = null;
  20964. }
  20965. recover() {
  20966. this.reset();
  20967. Pool.recover("InitTool", this);
  20968. }
  20969. static create() {
  20970. var tool = Pool.getItemByClass("InitTool", InitTool);
  20971. tool._idMap = [];
  20972. return tool;
  20973. }
  20974. addLoadRes(url, type = null) {
  20975. if (!this._loadList)
  20976. this._loadList = [];
  20977. if (ILaya.loader.getRes(url)) {
  20978. return;
  20979. }
  20980. if (!type) {
  20981. this._loadList.push(url);
  20982. }
  20983. else {
  20984. this._loadList.push({ url: url, type: type });
  20985. }
  20986. }
  20987. addNodeRef(node, prop, referStr) {
  20988. if (!this._nodeRefList)
  20989. this._nodeRefList = [];
  20990. this._nodeRefList.push([node, prop, referStr]);
  20991. if (referStr.indexOf("@Prefab:") >= 0) {
  20992. this.addLoadRes(referStr.replace("@Prefab:", ""), Loader.PREFAB);
  20993. }
  20994. }
  20995. setNodeRef() {
  20996. if (!this._nodeRefList)
  20997. return;
  20998. if (!this._idMap) {
  20999. this._nodeRefList = null;
  21000. return;
  21001. }
  21002. var i, len;
  21003. len = this._nodeRefList.length;
  21004. var tRefInfo;
  21005. for (i = 0; i < len; i++) {
  21006. tRefInfo = this._nodeRefList[i];
  21007. tRefInfo[0][tRefInfo[1]] = this.getReferData(tRefInfo[2]);
  21008. }
  21009. this._nodeRefList = null;
  21010. }
  21011. getReferData(referStr) {
  21012. if (referStr.indexOf("@Prefab:") >= 0) {
  21013. var prefab;
  21014. prefab = Loader.getRes(referStr.replace("@Prefab:", ""));
  21015. return prefab;
  21016. }
  21017. else if (referStr.indexOf("@arr:") >= 0) {
  21018. referStr = referStr.replace("@arr:", "");
  21019. var list;
  21020. list = referStr.split(",");
  21021. var i, len;
  21022. var tStr;
  21023. len = list.length;
  21024. for (i = 0; i < len; i++) {
  21025. tStr = list[i];
  21026. if (tStr) {
  21027. list[i] = this._idMap[tStr.replace("@node:", "")];
  21028. }
  21029. else {
  21030. list[i] = null;
  21031. }
  21032. }
  21033. return list;
  21034. }
  21035. else {
  21036. return this._idMap[referStr.replace("@node:", "")];
  21037. }
  21038. }
  21039. addInitItem(item) {
  21040. if (!this._initList)
  21041. this._initList = [];
  21042. this._initList.push(item);
  21043. }
  21044. doInits() {
  21045. if (!this._initList)
  21046. return;
  21047. this._initList = null;
  21048. }
  21049. finish() {
  21050. this.setNodeRef();
  21051. this.doInits();
  21052. this._scene._setBit(Const.NOT_READY, false);
  21053. if (this._scene.parent && this._scene.parent.activeInHierarchy && this._scene.active)
  21054. this._scene._processActive();
  21055. this._scene.event("onViewCreated");
  21056. this.recover();
  21057. }
  21058. beginLoad(scene) {
  21059. this._scene = scene;
  21060. if (!this._loadList || this._loadList.length < 1) {
  21061. this.finish();
  21062. }
  21063. else {
  21064. ILaya.loader.load(this._loadList, Handler.create(this, this.finish));
  21065. }
  21066. }
  21067. }
  21068. class IStatRender {
  21069. show(x = 0, y = 0) {
  21070. }
  21071. enable() {
  21072. }
  21073. hide() {
  21074. }
  21075. set_onclick(fn) {
  21076. }
  21077. isCanvasRender() {
  21078. return true;
  21079. }
  21080. renderNotCanvas(ctx, x, y) { }
  21081. }
  21082. class StatUI extends IStatRender {
  21083. constructor() {
  21084. super(...arguments);
  21085. this._show = false;
  21086. this._useCanvas = false;
  21087. this._height = 100;
  21088. this._view = [];
  21089. }
  21090. show(x = 0, y = 0) {
  21091. if (!Browser.onMiniGame && !ILaya.Render.isConchApp && !Browser.onBDMiniGame && !Browser.onKGMiniGame && !Browser.onQGMiniGame && !Browser.onQQMiniGame && !Browser.onAlipayMiniGame && !Browser.onBLMiniGame && !Browser.onTTMiniGame && !Browser.onHWMiniGame)
  21092. this._useCanvas = true;
  21093. this._show = true;
  21094. Stat._fpsData.length = 60;
  21095. this._view[0] = { title: "FPS(WebGL)", value: "_fpsStr", color: "yellow", units: "int" };
  21096. this._view[1] = { title: "Sprite", value: "_spriteStr", color: "white", units: "int" };
  21097. this._view[2] = { title: "RenderBatches", value: "renderBatches", color: "white", units: "int" };
  21098. this._view[3] = { title: "SavedRenderBatches", value: "savedRenderBatches", color: "white", units: "int" };
  21099. this._view[4] = { title: "CPUMemory", value: "cpuMemory", color: "yellow", units: "M" };
  21100. this._view[5] = { title: "GPUMemory", value: "gpuMemory", color: "yellow", units: "M" };
  21101. this._view[6] = { title: "Shader", value: "shaderCall", color: "white", units: "int" };
  21102. this._view[7] = { title: "Canvas", value: "_canvasStr", color: "white", units: "int" };
  21103. if (Render.is3DMode) {
  21104. this._view[0].title = "FPS(3D)";
  21105. this._view[8] = { title: "TriFaces", value: "trianglesFaces", color: "white", units: "int" };
  21106. this._view[9] = { title: "FrustumCulling", value: "frustumCulling", color: "white", units: "int" };
  21107. this._view[10] = { title: "OctreeNodeCulling", value: "octreeNodeCulling", color: "white", units: "int" };
  21108. }
  21109. if (this._useCanvas) {
  21110. this.createUIPre(x, y);
  21111. }
  21112. else
  21113. this.createUI(x, y);
  21114. this.enable();
  21115. }
  21116. createUIPre(x, y) {
  21117. var pixel = Browser.pixelRatio;
  21118. this._width = pixel * 180;
  21119. this._vx = pixel * 120;
  21120. this._height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  21121. StatUI._fontSize = 12 * pixel;
  21122. for (var i = 0; i < this._view.length; i++) {
  21123. this._view[i].x = 4;
  21124. this._view[i].y = i * StatUI._fontSize + 2 * pixel;
  21125. }
  21126. if (!this._canvas) {
  21127. this._canvas = new HTMLCanvas(true);
  21128. this._canvas.size(this._width, this._height);
  21129. this._ctx = this._canvas.getContext('2d');
  21130. this._ctx.textBaseline = "top";
  21131. this._ctx.font = StatUI._fontSize + "px Arial";
  21132. this._canvas.source.style.cssText = "pointer-events:none;background:rgba(150,150,150,0.8);z-index:100000;position: absolute;direction:ltr;left:" + x + "px;top:" + y + "px;width:" + (this._width / pixel) + "px;height:" + (this._height / pixel) + "px;";
  21133. }
  21134. if (!Browser.onKGMiniGame) {
  21135. Browser.container.appendChild(this._canvas.source);
  21136. }
  21137. this._first = true;
  21138. this.loop();
  21139. this._first = false;
  21140. }
  21141. createUI(x, y) {
  21142. var stat = this._sp;
  21143. var pixel = Browser.pixelRatio;
  21144. if (!stat) {
  21145. stat = new Sprite();
  21146. this._leftText = new Text();
  21147. this._leftText.pos(5, 5);
  21148. this._leftText.color = "#ffffff";
  21149. stat.addChild(this._leftText);
  21150. this._txt = new Text();
  21151. this._txt.pos(130 * pixel, 5);
  21152. this._txt.color = "#ffffff";
  21153. stat.addChild(this._txt);
  21154. this._sp = stat;
  21155. }
  21156. stat.pos(x, y);
  21157. var text = "";
  21158. for (var i = 0; i < this._view.length; i++) {
  21159. var one = this._view[i];
  21160. text += one.title + "\n";
  21161. }
  21162. this._leftText.text = text;
  21163. var width = pixel * 138;
  21164. var height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  21165. this._txt.fontSize = StatUI._fontSize * pixel;
  21166. this._leftText.fontSize = StatUI._fontSize * pixel;
  21167. stat.size(width, height);
  21168. stat.graphics.clear();
  21169. stat.graphics.alpha(0.5);
  21170. stat.graphics.drawRect(0, 0, width + 110, height + 30, "#999999");
  21171. stat.graphics.alpha(2);
  21172. this.loop();
  21173. }
  21174. enable() {
  21175. ILaya.systemTimer.frameLoop(1, this, this.loop);
  21176. }
  21177. hide() {
  21178. this._show = false;
  21179. ILaya.systemTimer.clear(this, this.loop);
  21180. if (this._canvas) {
  21181. Browser.removeElement(this._canvas.source);
  21182. }
  21183. }
  21184. set_onclick(fn) {
  21185. if (this._sp) {
  21186. this._sp.on("click", this._sp, fn);
  21187. }
  21188. if (this._canvas) {
  21189. this._canvas.source.onclick = fn;
  21190. this._canvas.source.style.pointerEvents = '';
  21191. }
  21192. }
  21193. loop() {
  21194. Stat._count++;
  21195. var timer = Browser.now();
  21196. if (timer - Stat._timer < 1000)
  21197. return;
  21198. var count = Stat._count;
  21199. Stat.FPS = Math.round((count * 1000) / (timer - Stat._timer));
  21200. if (this._show) {
  21201. Stat.trianglesFaces = Math.round(Stat.trianglesFaces / count);
  21202. if (!this._useCanvas) {
  21203. Stat.renderBatches = Math.round(Stat.renderBatches / count) - 1;
  21204. }
  21205. else {
  21206. Stat.renderBatches = Math.round(Stat.renderBatches / count);
  21207. }
  21208. Stat.savedRenderBatches = Math.round(Stat.savedRenderBatches / count);
  21209. Stat.shaderCall = Math.round(Stat.shaderCall / count);
  21210. Stat.spriteRenderUseCacheCount = Math.round(Stat.spriteRenderUseCacheCount / count);
  21211. Stat.canvasNormal = Math.round(Stat.canvasNormal / count);
  21212. Stat.canvasBitmap = Math.round(Stat.canvasBitmap / count);
  21213. Stat.canvasReCache = Math.ceil(Stat.canvasReCache / count);
  21214. Stat.frustumCulling = Math.round(Stat.frustumCulling / count);
  21215. Stat.octreeNodeCulling = Math.round(Stat.octreeNodeCulling / count);
  21216. var delay = Stat.FPS > 0 ? Math.floor(1000 / Stat.FPS).toString() : " ";
  21217. Stat._fpsStr = Stat.FPS + (Stat.renderSlow ? " slow" : "") + " " + delay;
  21218. Stat._spriteStr = Stat.spriteCount + (Stat.spriteRenderUseCacheCount ? ("/" + Stat.spriteRenderUseCacheCount) : '');
  21219. Stat._canvasStr = Stat.canvasReCache + "/" + Stat.canvasNormal + "/" + Stat.canvasBitmap;
  21220. Stat.cpuMemory = Resource.cpuMemory;
  21221. Stat.gpuMemory = Resource.gpuMemory;
  21222. if (this._useCanvas) {
  21223. this.renderInfoPre();
  21224. }
  21225. else
  21226. this.renderInfo();
  21227. Stat.clear();
  21228. }
  21229. Stat._count = 0;
  21230. Stat._timer = timer;
  21231. }
  21232. renderInfoPre() {
  21233. var i = 0;
  21234. var one;
  21235. var value;
  21236. if (this._canvas) {
  21237. var ctx = this._ctx;
  21238. ctx.clearRect(this._first ? 0 : this._vx, 0, this._width, this._height);
  21239. for (i = 0; i < this._view.length; i++) {
  21240. one = this._view[i];
  21241. if (this._first) {
  21242. ctx.fillStyle = "white";
  21243. ctx.fillText(one.title, one.x, one.y);
  21244. }
  21245. ctx.fillStyle = one.color;
  21246. value = Stat[one.value];
  21247. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21248. ctx.fillText(value + "", one.x + this._vx, one.y);
  21249. }
  21250. }
  21251. }
  21252. renderInfo() {
  21253. var text = "";
  21254. for (var i = 0; i < this._view.length; i++) {
  21255. var one = this._view[i];
  21256. var value = Stat[one.value];
  21257. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21258. (one.units == "K") && (value = Math.floor(value / (1024) * 100) / 100 + " K");
  21259. text += value + "\n";
  21260. }
  21261. this._txt.text = text;
  21262. }
  21263. isCanvasRender() {
  21264. return this._useCanvas;
  21265. }
  21266. renderNotCanvas(ctx, x, y) {
  21267. this._show && this._sp && this._sp.render(ctx, 0, 0);
  21268. }
  21269. }
  21270. StatUI._fontSize = 12;
  21271. class Timer {
  21272. constructor(autoActive = true) {
  21273. this.scale = 1;
  21274. this.currTimer = Date.now();
  21275. this.currFrame = 0;
  21276. this._delta = 0;
  21277. this._lastTimer = Date.now();
  21278. this._map = [];
  21279. this._handlers = [];
  21280. this._temp = [];
  21281. this._count = 0;
  21282. autoActive && Timer.gSysTimer && Timer.gSysTimer.frameLoop(1, this, this._update);
  21283. }
  21284. get delta() {
  21285. return this._delta;
  21286. }
  21287. _update() {
  21288. if (this.scale <= 0) {
  21289. this._lastTimer = Date.now();
  21290. this._delta = 0;
  21291. return;
  21292. }
  21293. var frame = this.currFrame = this.currFrame + this.scale;
  21294. var now = Date.now();
  21295. var awake = (now - this._lastTimer) > 30000;
  21296. this._delta = (now - this._lastTimer) * this.scale;
  21297. var timer = this.currTimer = this.currTimer + this._delta;
  21298. this._lastTimer = now;
  21299. var handlers = this._handlers;
  21300. this._count = 0;
  21301. for (var i = 0, n = handlers.length; i < n; i++) {
  21302. var handler = handlers[i];
  21303. if (handler.method !== null) {
  21304. var t = handler.userFrame ? frame : timer;
  21305. if (t >= handler.exeTime) {
  21306. if (handler.repeat) {
  21307. if (!handler.jumpFrame || awake) {
  21308. handler.exeTime += handler.delay;
  21309. handler.run(false);
  21310. if (t > handler.exeTime) {
  21311. handler.exeTime += Math.ceil((t - handler.exeTime) / handler.delay) * handler.delay;
  21312. }
  21313. }
  21314. else {
  21315. while (t >= handler.exeTime) {
  21316. handler.exeTime += handler.delay;
  21317. handler.run(false);
  21318. }
  21319. }
  21320. }
  21321. else {
  21322. handler.run(true);
  21323. }
  21324. }
  21325. }
  21326. else {
  21327. this._count++;
  21328. }
  21329. }
  21330. if (this._count > 30 || frame % 200 === 0)
  21331. this._clearHandlers();
  21332. }
  21333. _clearHandlers() {
  21334. var handlers = this._handlers;
  21335. for (var i = 0, n = handlers.length; i < n; i++) {
  21336. var handler = handlers[i];
  21337. if (handler.method !== null)
  21338. this._temp.push(handler);
  21339. else
  21340. this._recoverHandler(handler);
  21341. }
  21342. this._handlers = this._temp;
  21343. handlers.length = 0;
  21344. this._temp = handlers;
  21345. }
  21346. _recoverHandler(handler) {
  21347. if (this._map[handler.key] == handler)
  21348. this._map[handler.key] = null;
  21349. handler.clear();
  21350. Timer._pool.push(handler);
  21351. }
  21352. _create(useFrame, repeat, delay, caller, method, args, coverBefore) {
  21353. if (!delay) {
  21354. method.apply(caller, args);
  21355. return null;
  21356. }
  21357. if (coverBefore) {
  21358. var handler = this._getHandler(caller, method);
  21359. if (handler) {
  21360. handler.repeat = repeat;
  21361. handler.userFrame = useFrame;
  21362. handler.delay = delay;
  21363. handler.caller = caller;
  21364. handler.method = method;
  21365. handler.args = args;
  21366. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21367. return handler;
  21368. }
  21369. }
  21370. handler = Timer._pool.length > 0 ? Timer._pool.pop() : new TimerHandler();
  21371. handler.repeat = repeat;
  21372. handler.userFrame = useFrame;
  21373. handler.delay = delay;
  21374. handler.caller = caller;
  21375. handler.method = method;
  21376. handler.args = args;
  21377. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21378. this._indexHandler(handler);
  21379. this._handlers.push(handler);
  21380. return handler;
  21381. }
  21382. _indexHandler(handler) {
  21383. var caller = handler.caller;
  21384. var method = handler.method;
  21385. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21386. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21387. handler.key = cid + mid;
  21388. this._map[handler.key] = handler;
  21389. }
  21390. once(delay, caller, method, args = null, coverBefore = true) {
  21391. this._create(false, false, delay, caller, method, args, coverBefore);
  21392. }
  21393. loop(delay, caller, method, args = null, coverBefore = true, jumpFrame = false) {
  21394. var handler = this._create(false, true, delay, caller, method, args, coverBefore);
  21395. if (handler)
  21396. handler.jumpFrame = jumpFrame;
  21397. }
  21398. frameOnce(delay, caller, method, args = null, coverBefore = true) {
  21399. this._create(true, false, delay, caller, method, args, coverBefore);
  21400. }
  21401. frameLoop(delay, caller, method, args = null, coverBefore = true) {
  21402. this._create(true, true, delay, caller, method, args, coverBefore);
  21403. }
  21404. toString() {
  21405. return " handlers:" + this._handlers.length + " pool:" + Timer._pool.length;
  21406. }
  21407. clear(caller, method) {
  21408. var handler = this._getHandler(caller, method);
  21409. if (handler) {
  21410. this._map[handler.key] = null;
  21411. handler.key = 0;
  21412. handler.clear();
  21413. }
  21414. }
  21415. clearAll(caller) {
  21416. if (!caller)
  21417. return;
  21418. for (var i = 0, n = this._handlers.length; i < n; i++) {
  21419. var handler = this._handlers[i];
  21420. if (handler.caller === caller) {
  21421. this._map[handler.key] = null;
  21422. handler.key = 0;
  21423. handler.clear();
  21424. }
  21425. }
  21426. }
  21427. _getHandler(caller, method) {
  21428. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21429. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21430. return this._map[cid + mid];
  21431. }
  21432. callLater(caller, method, args = null) {
  21433. CallLater.I.callLater(caller, method, args);
  21434. }
  21435. runCallLater(caller, method) {
  21436. CallLater.I.runCallLater(caller, method);
  21437. }
  21438. runTimer(caller, method) {
  21439. var handler = this._getHandler(caller, method);
  21440. if (handler && handler.method != null) {
  21441. this._map[handler.key] = null;
  21442. handler.run(true);
  21443. }
  21444. }
  21445. pause() {
  21446. this.scale = 0;
  21447. }
  21448. resume() {
  21449. this.scale = 1;
  21450. }
  21451. }
  21452. Timer.gSysTimer = null;
  21453. Timer._pool = [];
  21454. Timer._mid = 1;
  21455. class TimerHandler {
  21456. clear() {
  21457. this.caller = null;
  21458. this.method = null;
  21459. this.args = null;
  21460. }
  21461. run(withClear) {
  21462. var caller = this.caller;
  21463. if (caller && caller.destroyed)
  21464. return this.clear();
  21465. var method = this.method;
  21466. var args = this.args;
  21467. withClear && this.clear();
  21468. if (method == null)
  21469. return;
  21470. args ? method.apply(caller, args) : method.call(caller);
  21471. }
  21472. }
  21473. class SkinSV extends Value2D {
  21474. constructor(type) {
  21475. super(ShaderDefines2D.SKINMESH, 0);
  21476. this.offsetX = 300;
  21477. this.offsetY = 0;
  21478. var gl = WebGLContext.mainContext;
  21479. var _vlen = 8 * CONST3D2D.BYTES_PE;
  21480. this.position = [2, gl.FLOAT, false, _vlen, 0];
  21481. this.texcoord = [2, gl.FLOAT, false, _vlen, 2 * CONST3D2D.BYTES_PE];
  21482. this.color = [4, gl.FLOAT, false, _vlen, 4 * CONST3D2D.BYTES_PE];
  21483. }
  21484. }
  21485. class PrimitiveSV extends Value2D {
  21486. constructor(args) {
  21487. super(ShaderDefines2D.PRIMITIVE, 0);
  21488. this._attribLocation = ['position', 0, 'attribColor', 1];
  21489. }
  21490. }
  21491. class TextureSV extends Value2D {
  21492. constructor(subID = 0) {
  21493. super(ShaderDefines2D.TEXTURE2D, subID);
  21494. this.strength = 0;
  21495. this.blurInfo = null;
  21496. this.colorMat = null;
  21497. this.colorAlpha = null;
  21498. this._attribLocation = ['posuv', 0, 'attribColor', 1, 'attribFlags', 2];
  21499. }
  21500. clear() {
  21501. this.texture = null;
  21502. this.shader = null;
  21503. this.defines._value = this.subID;
  21504. }
  21505. }
  21506. class InlcudeFile {
  21507. constructor(txt) {
  21508. this.codes = {};
  21509. this.funs = {};
  21510. this.curUseID = -1;
  21511. this.funnames = "";
  21512. this.script = txt;
  21513. var begin = 0, ofs, end;
  21514. while (true) {
  21515. begin = txt.indexOf("#begin", begin);
  21516. if (begin < 0)
  21517. break;
  21518. end = begin + 5;
  21519. while (true) {
  21520. end = txt.indexOf("#end", end);
  21521. if (end < 0)
  21522. break;
  21523. if (txt.charAt(end + 4) === 'i')
  21524. end += 5;
  21525. else
  21526. break;
  21527. }
  21528. if (end < 0) {
  21529. throw "add include err,no #end:" + txt;
  21530. }
  21531. ofs = txt.indexOf('\n', begin);
  21532. var words = ILaya.ShaderCompile.splitToWords(txt.substr(begin, ofs - begin), null);
  21533. if (words[1] == 'code') {
  21534. this.codes[words[2]] = txt.substr(ofs + 1, end - ofs - 1);
  21535. }
  21536. else if (words[1] == 'function') {
  21537. ofs = txt.indexOf("function", begin);
  21538. ofs += "function".length;
  21539. this.funs[words[3]] = txt.substr(ofs + 1, end - ofs - 1);
  21540. this.funnames += words[3] + ";";
  21541. }
  21542. begin = end + 1;
  21543. }
  21544. }
  21545. getWith(name = null) {
  21546. var r = name ? this.codes[name] : this.script;
  21547. if (!r) {
  21548. throw "get with error:" + name;
  21549. }
  21550. return r;
  21551. }
  21552. getFunsScript(funsdef) {
  21553. var r = "";
  21554. for (var i in this.funs) {
  21555. if (funsdef.indexOf(i + ";") >= 0) {
  21556. r += this.funs[i];
  21557. }
  21558. }
  21559. return r;
  21560. }
  21561. }
  21562. class ShaderNode {
  21563. constructor(includefiles) {
  21564. this.childs = [];
  21565. this.text = "";
  21566. this.useFuns = "";
  21567. this.z = 0;
  21568. this.includefiles = includefiles;
  21569. }
  21570. setParent(parent) {
  21571. parent.childs.push(this);
  21572. this.z = parent.z + 1;
  21573. this.parent = parent;
  21574. }
  21575. setCondition(condition, type) {
  21576. if (condition) {
  21577. this.conditionType = type;
  21578. condition = condition.replace(/(\s*$)/g, "");
  21579. this.condition = function () {
  21580. return this[condition];
  21581. };
  21582. this.condition.__condition = condition;
  21583. }
  21584. }
  21585. toscript(def, out) {
  21586. return this._toscript(def, out, ++ShaderNode.__id);
  21587. }
  21588. _toscript(def, out, id) {
  21589. if (this.childs.length < 1 && !this.text)
  21590. return out;
  21591. var outIndex = out.length;
  21592. if (this.condition) {
  21593. var ifdef = !!this.condition.call(def);
  21594. this.conditionType === ILaya.ShaderCompile.IFDEF_ELSE && (ifdef = !ifdef);
  21595. if (!ifdef)
  21596. return out;
  21597. }
  21598. this.text && out.push(this.text);
  21599. this.childs.length > 0 && this.childs.forEach(function (o, index, arr) {
  21600. o._toscript(def, out, id);
  21601. });
  21602. if (this.includefiles.length > 0 && this.useFuns.length > 0) {
  21603. var funsCode;
  21604. for (var i = 0, n = this.includefiles.length; i < n; i++) {
  21605. if (this.includefiles[i].curUseID == id) {
  21606. continue;
  21607. }
  21608. funsCode = this.includefiles[i].file.getFunsScript(this.useFuns);
  21609. if (funsCode.length > 0) {
  21610. this.includefiles[i].curUseID = id;
  21611. out[0] = funsCode + out[0];
  21612. }
  21613. }
  21614. }
  21615. return out;
  21616. }
  21617. }
  21618. ShaderNode.__id = 1;
  21619. class ShaderCompile {
  21620. constructor(vs, ps, nameMap) {
  21621. this.defs = {};
  21622. let _this = this;
  21623. function _compile(script) {
  21624. script = script.replace(ShaderCompile._clearCR, "");
  21625. var includefiles = [];
  21626. var top = new ShaderNode(includefiles);
  21627. _this._compileToTree(top, script.split('\n'), 0, includefiles, _this.defs);
  21628. return top;
  21629. }
  21630. var startTime = Date.now();
  21631. this._VS = _compile(vs);
  21632. this._PS = _compile(ps);
  21633. this._nameMap = nameMap;
  21634. if ((Date.now() - startTime) > 2)
  21635. console.log("ShaderCompile use time:" + (Date.now() - startTime) + " size:" + vs.length + "/" + ps.length);
  21636. }
  21637. static __init__() {
  21638. var gl = LayaGL.instance;
  21639. ShaderCompile.shaderParamsMap = { "float": gl.FLOAT, "int": gl.INT, "bool": gl.BOOL, "vec2": gl.FLOAT_VEC2, "vec3": gl.FLOAT_VEC3, "vec4": gl.FLOAT_VEC4, "ivec2": gl.INT_VEC2, "ivec3": gl.INT_VEC3, "ivec4": gl.INT_VEC4, "bvec2": gl.BOOL_VEC2, "bvec3": gl.BOOL_VEC3, "bvec4": gl.BOOL_VEC4, "mat2": gl.FLOAT_MAT2, "mat3": gl.FLOAT_MAT3, "mat4": gl.FLOAT_MAT4, "sampler2D": gl.SAMPLER_2D, "samplerCube": gl.SAMPLER_CUBE };
  21640. }
  21641. static _parseOne(attributes, uniforms, words, i, word, b) {
  21642. var one = { type: ShaderCompile.shaderParamsMap[words[i + 1]], name: words[i + 2], size: isNaN(parseInt(words[i + 3])) ? 1 : parseInt(words[i + 3]) };
  21643. if (b) {
  21644. if (word == "attribute") {
  21645. attributes.push(one);
  21646. }
  21647. else {
  21648. uniforms.push(one);
  21649. }
  21650. }
  21651. if (words[i + 3] == ':') {
  21652. one.type = words[i + 4];
  21653. i += 2;
  21654. }
  21655. i += 2;
  21656. return i;
  21657. }
  21658. static addInclude(fileName, txt) {
  21659. if (!txt || txt.length === 0)
  21660. throw new Error("add shader include file err:" + fileName);
  21661. if (ShaderCompile.includes[fileName])
  21662. throw new Error("add shader include file err, has add:" + fileName);
  21663. ShaderCompile.includes[fileName] = new InlcudeFile(txt);
  21664. }
  21665. static preGetParams(vs, ps) {
  21666. var text = [vs, ps];
  21667. var result = {};
  21668. var attributes = [];
  21669. var uniforms = [];
  21670. var definesInfo = {};
  21671. var definesName = [];
  21672. result.attributes = attributes;
  21673. result.uniforms = uniforms;
  21674. result.defines = definesInfo;
  21675. var i, n;
  21676. for (var s = 0; s < 2; s++) {
  21677. text[s] = text[s].replace(ShaderCompile._removeAnnotation, "");
  21678. var words = text[s].match(ShaderCompile._reg);
  21679. var tempelse;
  21680. for (i = 0, n = words.length; i < n; i++) {
  21681. var word = words[i];
  21682. if (word != "attribute" && word != "uniform") {
  21683. if (word == "#define") {
  21684. word = words[++i];
  21685. definesName[word] = 1;
  21686. continue;
  21687. }
  21688. else if (word == "#ifdef") {
  21689. tempelse = words[++i];
  21690. var def = definesInfo[tempelse] = definesInfo[tempelse] || [];
  21691. for (i++; i < n; i++) {
  21692. word = words[i];
  21693. if (word != "attribute" && word != "uniform") {
  21694. if (word == "#else") {
  21695. for (i++; i < n; i++) {
  21696. word = words[i];
  21697. if (word != "attribute" && word != "uniform") {
  21698. if (word == "#endif") {
  21699. break;
  21700. }
  21701. continue;
  21702. }
  21703. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, !definesName[tempelse]);
  21704. }
  21705. }
  21706. continue;
  21707. }
  21708. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, definesName[tempelse]);
  21709. }
  21710. }
  21711. continue;
  21712. }
  21713. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, true);
  21714. }
  21715. }
  21716. return result;
  21717. }
  21718. static splitToWords(str, block) {
  21719. var out = [];
  21720. var c;
  21721. var ofs = -1;
  21722. var word;
  21723. for (var i = 0, n = str.length; i < n; i++) {
  21724. c = str.charAt(i);
  21725. if (" \t=+-*/&%!<>()'\",;".indexOf(c) >= 0) {
  21726. if (ofs >= 0 && (i - ofs) > 1) {
  21727. word = str.substr(ofs, i - ofs);
  21728. out.push(word);
  21729. }
  21730. if (c == '"' || c == "'") {
  21731. var ofs2 = str.indexOf(c, i + 1);
  21732. if (ofs2 < 0) {
  21733. throw "Sharder err:" + str;
  21734. }
  21735. out.push(str.substr(i + 1, ofs2 - i - 1));
  21736. i = ofs2;
  21737. ofs = -1;
  21738. continue;
  21739. }
  21740. if (c == '(' && block && out.length > 0) {
  21741. word = out[out.length - 1] + ";";
  21742. if ("vec4;main;".indexOf(word) < 0)
  21743. block.useFuns += word;
  21744. }
  21745. ofs = -1;
  21746. continue;
  21747. }
  21748. if (ofs < 0)
  21749. ofs = i;
  21750. }
  21751. if (ofs < n && (n - ofs) > 1) {
  21752. word = str.substr(ofs, n - ofs);
  21753. out.push(word);
  21754. }
  21755. return out;
  21756. }
  21757. _compileToTree(parent, lines, start, includefiles, defs) {
  21758. var node, preNode;
  21759. var text, name, fname;
  21760. var ofs, words, noUseNode;
  21761. var i, n, j;
  21762. for (i = start; i < lines.length; i++) {
  21763. text = lines[i];
  21764. if (text.length < 1)
  21765. continue;
  21766. ofs = text.indexOf("//");
  21767. if (ofs === 0)
  21768. continue;
  21769. if (ofs >= 0)
  21770. text = text.substr(0, ofs);
  21771. node = noUseNode || new ShaderNode(includefiles);
  21772. noUseNode = null;
  21773. node.text = text;
  21774. node.noCompile = true;
  21775. if ((ofs = text.indexOf("#")) >= 0) {
  21776. name = "#";
  21777. for (j = ofs + 1, n = text.length; j < n; j++) {
  21778. var c = text.charAt(j);
  21779. if (c === ' ' || c === '\t' || c === '?')
  21780. break;
  21781. name += c;
  21782. }
  21783. node.name = name;
  21784. switch (name) {
  21785. case "#ifdef":
  21786. case "#ifndef":
  21787. node.src = text;
  21788. node.noCompile = text.match(/[!&|()=<>]/) != null;
  21789. if (!node.noCompile) {
  21790. words = text.replace(/^\s*/, '').split(/\s+/);
  21791. node.setCondition(words[1], name === "#ifdef" ? ShaderCompile.IFDEF_YES : ShaderCompile.IFDEF_ELSE);
  21792. node.text = "//" + node.text;
  21793. }
  21794. else {
  21795. console.log("function():Boolean{return " + text.substr(ofs + node.name.length) + "}");
  21796. }
  21797. node.setParent(parent);
  21798. parent = node;
  21799. if (defs) {
  21800. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21801. for (j = 0; j < words.length; j++) {
  21802. text = words[j];
  21803. text.length && (defs[text] = true);
  21804. }
  21805. }
  21806. continue;
  21807. case "#if":
  21808. node.src = text;
  21809. node.noCompile = true;
  21810. node.setParent(parent);
  21811. parent = node;
  21812. if (defs) {
  21813. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21814. for (j = 0; j < words.length; j++) {
  21815. text = words[j];
  21816. text.length && text != "defined" && (defs[text] = true);
  21817. }
  21818. }
  21819. continue;
  21820. case "#else":
  21821. node.src = text;
  21822. parent = parent.parent;
  21823. preNode = parent.childs[parent.childs.length - 1];
  21824. node.noCompile = preNode.noCompile;
  21825. if (!node.noCompile) {
  21826. node.condition = preNode.condition;
  21827. node.conditionType = preNode.conditionType == ShaderCompile.IFDEF_YES ? ShaderCompile.IFDEF_ELSE : ShaderCompile.IFDEF_YES;
  21828. node.text = "//" + node.text + " " + preNode.text + " " + node.conditionType;
  21829. }
  21830. node.setParent(parent);
  21831. parent = node;
  21832. continue;
  21833. case "#endif":
  21834. parent = parent.parent;
  21835. preNode = parent.childs[parent.childs.length - 1];
  21836. node.noCompile = preNode.noCompile;
  21837. if (!node.noCompile) {
  21838. node.text = "//" + node.text;
  21839. }
  21840. node.setParent(parent);
  21841. continue;
  21842. case "#include":
  21843. words = ShaderCompile.splitToWords(text, null);
  21844. var inlcudeFile = ShaderCompile.includes[words[1]];
  21845. if (!inlcudeFile) {
  21846. throw "ShaderCompile error no this include file:" + words[1];
  21847. }
  21848. if ((ofs = words[0].indexOf("?")) < 0) {
  21849. node.setParent(parent);
  21850. text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21851. this._compileToTree(node, text.split('\n'), 0, includefiles, defs);
  21852. node.text = "";
  21853. continue;
  21854. }
  21855. node.setCondition(words[0].substr(ofs + 1), ShaderCompile.IFDEF_YES);
  21856. node.text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21857. break;
  21858. case "#import":
  21859. words = ShaderCompile.splitToWords(text, null);
  21860. fname = words[1];
  21861. includefiles.push({ node: node, file: ShaderCompile.includes[fname], ofs: node.text.length });
  21862. continue;
  21863. }
  21864. }
  21865. else {
  21866. preNode = parent.childs[parent.childs.length - 1];
  21867. if (preNode && !preNode.name) {
  21868. includefiles.length > 0 && ShaderCompile.splitToWords(text, preNode);
  21869. noUseNode = node;
  21870. preNode.text += "\n" + text;
  21871. continue;
  21872. }
  21873. includefiles.length > 0 && ShaderCompile.splitToWords(text, node);
  21874. }
  21875. node.setParent(parent);
  21876. }
  21877. }
  21878. createShader(define, shaderName, createShader, bindAttrib) {
  21879. var defMap = {};
  21880. var defineStr = "";
  21881. if (define) {
  21882. for (var i in define) {
  21883. defineStr += "#define " + i + "\n";
  21884. defMap[i] = true;
  21885. }
  21886. }
  21887. var vs = this._VS.toscript(defMap, []);
  21888. var ps = this._PS.toscript(defMap, []);
  21889. return (createShader || Shader.create)(defineStr + vs.join('\n'), defineStr + ps.join('\n'), shaderName, this._nameMap, bindAttrib);
  21890. }
  21891. }
  21892. ShaderCompile.IFDEF_NO = 0;
  21893. ShaderCompile.IFDEF_YES = 1;
  21894. ShaderCompile.IFDEF_ELSE = 2;
  21895. ShaderCompile.IFDEF_PARENT = 3;
  21896. ShaderCompile._removeAnnotation = new RegExp("(/\\*([^*]|[\\r\\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/)|(//.*)", "g");
  21897. ShaderCompile._reg = new RegExp("(\".*\")|('.*')|([#\\w\\*-\\.+/()=<>{}\\\\]+)|([,;:\\\\])", "g");
  21898. ShaderCompile._splitToWordExps = new RegExp("[(\".*\")]+|[('.*')]+|([ \\t=\\+\\-*/&%!<>!%\(\),;])", "g");
  21899. ShaderCompile.includes = {};
  21900. ShaderCompile._clearCR = new RegExp("\r", "g");
  21901. ShaderCompile._splitToWordExps3 = new RegExp("[ \\t=\\+\\-*/&%!<>!%\(\),;\\|]", "g");
  21902. class WorkerLoader extends EventDispatcher {
  21903. constructor() {
  21904. super();
  21905. this.worker = new Worker(WorkerLoader.workerPath);
  21906. let me = this;
  21907. this.worker.onmessage = function (evt) {
  21908. me.workerMessage(evt.data);
  21909. };
  21910. }
  21911. static __init__() {
  21912. if (WorkerLoader._preLoadFun != null)
  21913. return false;
  21914. if (!Worker)
  21915. return false;
  21916. WorkerLoader._preLoadFun = Loader["prototype"]["_loadImage"];
  21917. Loader["prototype"]["_loadImage"] = WorkerLoader["prototype"]["_loadImage"];
  21918. if (!WorkerLoader.I)
  21919. WorkerLoader.I = new WorkerLoader();
  21920. return true;
  21921. }
  21922. static workerSupported() {
  21923. return Worker ? true : false;
  21924. }
  21925. static enableWorkerLoader() {
  21926. if (!WorkerLoader._tryEnabled) {
  21927. WorkerLoader.enable = true;
  21928. WorkerLoader._tryEnabled = true;
  21929. }
  21930. }
  21931. static set enable(value) {
  21932. if (WorkerLoader._enable != value) {
  21933. WorkerLoader._enable = value;
  21934. if (value && WorkerLoader._preLoadFun == null)
  21935. WorkerLoader._enable = WorkerLoader.__init__();
  21936. }
  21937. }
  21938. static get enable() {
  21939. return WorkerLoader._enable;
  21940. }
  21941. workerMessage(data) {
  21942. if (data) {
  21943. switch (data.type) {
  21944. case "Image":
  21945. this.imageLoaded(data);
  21946. break;
  21947. case "Disable":
  21948. WorkerLoader.enable = false;
  21949. break;
  21950. }
  21951. }
  21952. }
  21953. imageLoaded(data) {
  21954. if (!data.dataType || data.dataType != "imageBitmap") {
  21955. this.event(data.url, null);
  21956. return;
  21957. }
  21958. var imageData = data.imageBitmap;
  21959. console.log("load:", data.url);
  21960. this.event(data.url, imageData);
  21961. }
  21962. loadImage(url) {
  21963. this.worker.postMessage(url);
  21964. }
  21965. _loadImage(url) {
  21966. var _this = this;
  21967. let type = _this.type;
  21968. if (!this._useWorkerLoader || !WorkerLoader._enable) {
  21969. WorkerLoader._preLoadFun.call(_this, url);
  21970. return;
  21971. }
  21972. url = URL.formatURL(url);
  21973. function clear() {
  21974. WorkerLoader.I.off(url, _this, onload);
  21975. }
  21976. var onload = function (imageData) {
  21977. clear();
  21978. if (imageData) {
  21979. var image = imageData;
  21980. if (type !== "nativeimage") {
  21981. image = new Texture2D();
  21982. image.loadImageSource(imageData);
  21983. }
  21984. _this["onLoaded"](image);
  21985. }
  21986. else {
  21987. WorkerLoader._preLoadFun.call(_this, url);
  21988. }
  21989. };
  21990. WorkerLoader.I.on(url, _this, onload);
  21991. WorkerLoader.I.loadImage(url);
  21992. }
  21993. }
  21994. WorkerLoader.workerPath = "libs/workerloader.js";
  21995. WorkerLoader._enable = false;
  21996. WorkerLoader._tryEnabled = false;
  21997. class Mouse {
  21998. static set cursor(cursorStr) {
  21999. Mouse._style.cursor = cursorStr;
  22000. }
  22001. static get cursor() {
  22002. return Mouse._style.cursor;
  22003. }
  22004. static __init__() {
  22005. Mouse._style = Browser.document.body.style;
  22006. }
  22007. static hide() {
  22008. if (Mouse.cursor != "none") {
  22009. Mouse._preCursor = Mouse.cursor;
  22010. Mouse.cursor = "none";
  22011. }
  22012. }
  22013. static show() {
  22014. if (Mouse.cursor == "none") {
  22015. if (Mouse._preCursor) {
  22016. Mouse.cursor = Mouse._preCursor;
  22017. }
  22018. else {
  22019. Mouse.cursor = "auto";
  22020. }
  22021. }
  22022. }
  22023. }
  22024. class MeshParticle2D extends Mesh2D {
  22025. constructor(maxNum) {
  22026. super(MeshParticle2D.const_stride, maxNum * 4 * MeshParticle2D.const_stride, 4);
  22027. this.canReuse = true;
  22028. this.setAttributes(MeshParticle2D._fixattriInfo);
  22029. this.createQuadIB(maxNum);
  22030. this._quadNum = maxNum;
  22031. }
  22032. static __init__() {
  22033. var gl = LayaGL.instance;
  22034. MeshParticle2D._fixattriInfo = [gl.FLOAT, 4, 0,
  22035. gl.FLOAT, 3, 16,
  22036. gl.FLOAT, 3, 28,
  22037. gl.FLOAT, 4, 40,
  22038. gl.FLOAT, 4, 56,
  22039. gl.FLOAT, 3, 72,
  22040. gl.FLOAT, 2, 84,
  22041. gl.FLOAT, 4, 92,
  22042. gl.FLOAT, 1, 108,
  22043. gl.FLOAT, 1, 112];
  22044. }
  22045. setMaxParticleNum(maxNum) {
  22046. this._vb._resizeBuffer(maxNum * 4 * MeshParticle2D.const_stride, false);
  22047. this.createQuadIB(maxNum);
  22048. }
  22049. static getAMesh(maxNum) {
  22050. if (MeshParticle2D._POOL.length) {
  22051. var ret = MeshParticle2D._POOL.pop();
  22052. ret.setMaxParticleNum(maxNum);
  22053. return ret;
  22054. }
  22055. return new MeshParticle2D(maxNum);
  22056. }
  22057. releaseMesh() {
  22058. this._vb.setByteLength(0);
  22059. this.vertNum = 0;
  22060. this.indexNum = 0;
  22061. MeshParticle2D._POOL.push(this);
  22062. }
  22063. destroy() {
  22064. this._ib.destroy();
  22065. this._vb.destroy();
  22066. this._vb.deleteBuffer();
  22067. }
  22068. }
  22069. MeshParticle2D.const_stride = 116;
  22070. MeshParticle2D._POOL = [];
  22071. class HTMLImage extends Bitmap {
  22072. }
  22073. HTMLImage.create = function (width, height, format) {
  22074. var tex = new Texture2D(width, height, format, false, false);
  22075. tex.wrapModeU = exports.WarpMode.Clamp;
  22076. tex.wrapModeV = exports.WarpMode.Clamp;
  22077. return tex;
  22078. };
  22079. class Laya {
  22080. static __init(_classs) {
  22081. _classs.forEach(function (o) { o.__init$ && o.__init$(); });
  22082. }
  22083. static init(width, height, ...plugins) {
  22084. if (Laya._isinit)
  22085. return;
  22086. Laya._isinit = true;
  22087. ArrayBuffer.prototype.slice || (ArrayBuffer.prototype.slice = Laya._arrayBufferSlice);
  22088. Browser.__init__();
  22089. var mainCanv = Browser.mainCanvas = new HTMLCanvas(true);
  22090. var style = mainCanv.source.style;
  22091. style.position = 'absolute';
  22092. style.top = style.left = "0px";
  22093. style.background = "#000000";
  22094. if (!Browser.onKGMiniGame && !Browser.onAlipayMiniGame) {
  22095. Browser.container.appendChild(mainCanv.source);
  22096. }
  22097. Browser.canvas = new HTMLCanvas(true);
  22098. Browser.context = Browser.canvas.getContext('2d');
  22099. Browser.supportWebAudio = SoundManager.__init__();
  22100. Browser.supportLocalStorage = LocalStorage.__init__();
  22101. Laya.systemTimer = new Timer(false);
  22102. exports.systemTimer = Timer.gSysTimer = Laya.systemTimer;
  22103. Laya.startTimer = new Timer(false);
  22104. Laya.physicsTimer = new Timer(false);
  22105. Laya.updateTimer = new Timer(false);
  22106. Laya.lateTimer = new Timer(false);
  22107. Laya.timer = new Timer(false);
  22108. exports.startTimer = ILaya.startTimer = Laya.startTimer;
  22109. exports.lateTimer = ILaya.lateTimer = Laya.lateTimer;
  22110. exports.updateTimer = ILaya.updateTimer = Laya.updateTimer;
  22111. ILaya.systemTimer = Laya.systemTimer;
  22112. exports.timer = ILaya.timer = Laya.timer;
  22113. exports.physicsTimer = ILaya.physicsTimer = Laya.physicsTimer;
  22114. Laya.loader = new LoaderManager();
  22115. ILaya.Laya = Laya;
  22116. exports.loader = ILaya.loader = Laya.loader;
  22117. WeakObject.__init__();
  22118. SceneUtils.__init();
  22119. Mouse.__init__();
  22120. WebGL.inner_enable();
  22121. if (plugins) {
  22122. for (var i = 0, n = plugins.length; i < n; i++) {
  22123. if (plugins[i] && plugins[i].enable) {
  22124. plugins[i].enable();
  22125. }
  22126. }
  22127. }
  22128. if (ILaya.Render.isConchApp) {
  22129. Laya.enableNative();
  22130. }
  22131. Laya.enableWebGLPlus();
  22132. CacheManger.beginCheck();
  22133. exports.stage = Laya.stage = new Stage();
  22134. ILaya.stage = Laya.stage;
  22135. Utils.gStage = Laya.stage;
  22136. URL.rootPath = URL._basePath = Laya._getUrlPath();
  22137. MeshQuadTexture.__int__();
  22138. MeshVG.__init__();
  22139. MeshTexture.__init__();
  22140. Laya.render = new Render(0, 0, Browser.mainCanvas);
  22141. exports.render = Laya.render;
  22142. Laya.stage.size(width, height);
  22143. window.stage = Laya.stage;
  22144. WebGLContext.__init__();
  22145. MeshParticle2D.__init__();
  22146. ShaderCompile.__init__();
  22147. RenderSprite.__init__();
  22148. KeyBoardManager.__init__();
  22149. MouseManager.instance.__init__(Laya.stage, Render.canvas);
  22150. Input.__init__();
  22151. SoundManager.autoStopMusic = true;
  22152. Stat._StatRender = new StatUI();
  22153. Value2D._initone(ShaderDefines2D.TEXTURE2D, TextureSV);
  22154. Value2D._initone(ShaderDefines2D.TEXTURE2D | ShaderDefines2D.FILTERGLOW, TextureSV);
  22155. Value2D._initone(ShaderDefines2D.PRIMITIVE, PrimitiveSV);
  22156. Value2D._initone(ShaderDefines2D.SKINMESH, SkinSV);
  22157. return Render.canvas;
  22158. }
  22159. static _getUrlPath() {
  22160. return URL.getPath(location.protocol + "//" + location.host + location.pathname);
  22161. }
  22162. static _arrayBufferSlice(start, end) {
  22163. var arr = this;
  22164. var arrU8List = new Uint8Array(arr, start, end - start);
  22165. var newU8List = new Uint8Array(arrU8List.length);
  22166. newU8List.set(arrU8List);
  22167. return newU8List.buffer;
  22168. }
  22169. static alertGlobalError(value) {
  22170. var erralert = 0;
  22171. if (value) {
  22172. Browser.window.onerror = function (msg, url, line, column, detail) {
  22173. if (erralert++ < 5 && detail)
  22174. this.alert("出错啦,请把此信息截图给研发商\n" + msg + "\n" + detail.stack);
  22175. };
  22176. }
  22177. else {
  22178. Browser.window.onerror = null;
  22179. }
  22180. }
  22181. static _runScript(script) {
  22182. return Browser.window[Laya._evcode](script);
  22183. }
  22184. static enableDebugPanel(debugJsPath = "libs/laya.debugtool.js") {
  22185. if (!window['Laya']["DebugPanel"]) {
  22186. var script = Browser.createElement("script");
  22187. script.onload = function () {
  22188. window['Laya']["DebugPanel"].enable();
  22189. };
  22190. script.src = debugJsPath;
  22191. Browser.document.body.appendChild(script);
  22192. }
  22193. else {
  22194. window['Laya']["DebugPanel"].enable();
  22195. }
  22196. }
  22197. static enableWebGLPlus() {
  22198. WebGLContext.__init_native();
  22199. }
  22200. static enableNative() {
  22201. if (Laya.isNativeRender_enable)
  22202. return;
  22203. Laya.isNativeRender_enable = true;
  22204. if (Render.supportWebGLPlusRendering) {
  22205. Shader.prototype.uploadTexture2D = function (value) {
  22206. var gl = LayaGL.instance;
  22207. gl.bindTexture(gl.TEXTURE_2D, value);
  22208. };
  22209. }
  22210. RenderState2D.width = Browser.window.innerWidth;
  22211. RenderState2D.height = Browser.window.innerHeight;
  22212. Browser.measureText = function (txt, font) {
  22213. window["conchTextCanvas"].font = font;
  22214. return window["conchTextCanvas"].measureText(txt);
  22215. };
  22216. Stage.clear = function (color) {
  22217. Context.set2DRenderConfig();
  22218. var c = ColorUtils.create(color).arrColor;
  22219. var gl = LayaGL.instance;
  22220. if (c)
  22221. gl.clearColor(c[0], c[1], c[2], c[3]);
  22222. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
  22223. RenderState2D.clear();
  22224. };
  22225. Sprite.drawToCanvas = Sprite.drawToTexture = function (sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  22226. offsetX -= sprite.x;
  22227. offsetY -= sprite.y;
  22228. offsetX |= 0;
  22229. offsetY |= 0;
  22230. canvasWidth |= 0;
  22231. canvasHeight |= 0;
  22232. var canv = new HTMLCanvas(false);
  22233. var ctx = canv.getContext('2d');
  22234. canv.size(canvasWidth, canvasHeight);
  22235. ctx.asBitmap = true;
  22236. ctx._targets.start();
  22237. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  22238. ctx.flush();
  22239. ctx._targets.end();
  22240. ctx._targets.restore();
  22241. return canv;
  22242. };
  22243. Object["defineProperty"](RenderTexture2D.prototype, "uv", {
  22244. "get": function () {
  22245. return this._uv;
  22246. },
  22247. "set": function (v) {
  22248. this._uv = v;
  22249. }
  22250. });
  22251. HTMLCanvas.prototype.getTexture = function () {
  22252. if (!this._texture) {
  22253. this._texture = this.context._targets;
  22254. this._texture.uv = RenderTexture2D.flipyuv;
  22255. this._texture.bitmap = this._texture;
  22256. }
  22257. return this._texture;
  22258. };
  22259. }
  22260. }
  22261. Laya.stage = null;
  22262. Laya.systemTimer = null;
  22263. Laya.startTimer = null;
  22264. Laya.physicsTimer = null;
  22265. Laya.updateTimer = null;
  22266. Laya.lateTimer = null;
  22267. Laya.timer = null;
  22268. Laya.loader = null;
  22269. Laya.version = "2.7.1";
  22270. Laya._isinit = false;
  22271. Laya.isWXOpenDataContext = false;
  22272. Laya.isWXPosMsg = false;
  22273. Laya.__classmap = null;
  22274. Laya.Config = Config;
  22275. Laya.TextRender = TextRender;
  22276. Laya.EventDispatcher = EventDispatcher;
  22277. Laya.SoundChannel = SoundChannel;
  22278. Laya.Stage = Stage;
  22279. Laya.Render = Render;
  22280. Laya.Browser = Browser;
  22281. Laya.Sprite = Sprite;
  22282. Laya.Node = Node;
  22283. Laya.Context = Context;
  22284. Laya.WebGL = WebGL;
  22285. Laya.Handler = Handler;
  22286. Laya.RunDriver = RunDriver;
  22287. Laya.Utils = Utils;
  22288. Laya.Input = Input;
  22289. Laya.Loader = Loader;
  22290. Laya.LocalStorage = LocalStorage;
  22291. Laya.SoundManager = SoundManager;
  22292. Laya.URL = URL;
  22293. Laya.Event = Event;
  22294. Laya.Matrix = Matrix;
  22295. Laya.HTMLImage = HTMLImage;
  22296. Laya.Laya = Laya;
  22297. Laya._evcode = "eva" + "l";
  22298. Laya.isNativeRender_enable = false;
  22299. Laya.__classmap = ILaya.__classMap;
  22300. ILaya.Timer = Timer;
  22301. ILaya.Dragging = Dragging;
  22302. ILaya.GraphicsBounds = GraphicsBounds;
  22303. ILaya.Sprite = Sprite;
  22304. ILaya.TextRender = TextRender;
  22305. ILaya.Loader = Loader;
  22306. ILaya.TTFLoader = TTFLoader;
  22307. ILaya.WebAudioSound = WebAudioSound;
  22308. ILaya.SoundManager = SoundManager;
  22309. ILaya.ShaderCompile = ShaderCompile;
  22310. ILaya.ClassUtils = ClassUtils;
  22311. ILaya.SceneUtils = SceneUtils;
  22312. ILaya.Context = Context;
  22313. ILaya.Render = Render;
  22314. ILaya.MouseManager = MouseManager;
  22315. ILaya.Text = Text;
  22316. ILaya.Browser = Browser;
  22317. ILaya.WebGL = WebGL;
  22318. ILaya.AudioSound = AudioSound;
  22319. ILaya.Pool = Pool;
  22320. ILaya.Utils = Utils;
  22321. ILaya.Graphics = Graphics;
  22322. ILaya.Submit = Submit;
  22323. ILaya.Stage = Stage;
  22324. ILaya.Resource = Resource;
  22325. ILaya.WorkerLoader = WorkerLoader;
  22326. var libs = window._layalibs;
  22327. if (libs) {
  22328. libs.sort(function (a, b) {
  22329. return a.i - b.i;
  22330. });
  22331. for (var j = 0; j < libs.length; j++) {
  22332. libs[j].f(window, window.document, Laya);
  22333. }
  22334. }
  22335. let win = window;
  22336. if (win.Laya) {
  22337. win.Laya.Laya = Laya;
  22338. Object.assign(win.Laya, Laya);
  22339. }
  22340. else
  22341. win.Laya = Laya;
  22342. var __init = Laya.__init;
  22343. var init = Laya.init;
  22344. var version = Laya.version;
  22345. var isWXOpenDataContext;
  22346. var isWXPosMsg;
  22347. var alertGlobalError = Laya.alertGlobalError;
  22348. var enableDebugPanel = Laya.enableDebugPanel;
  22349. function _static(_class, def) {
  22350. for (var i = 0, sz = def.length; i < sz; i += 2) {
  22351. if (def[i] == 'length')
  22352. _class.length = def[i + 1].call(_class);
  22353. else {
  22354. function tmp() {
  22355. var name = def[i];
  22356. var getfn = def[i + 1];
  22357. Object.defineProperty(_class, name, {
  22358. get: function () { delete this[name]; return this[name] = getfn.call(this); },
  22359. set: function (v) { delete this[name]; this[name] = v; }, enumerable: true, configurable: true
  22360. });
  22361. }
  22362. tmp();
  22363. }
  22364. }
  22365. }
  22366. class CommonScript extends Component {
  22367. get isSingleton() {
  22368. return false;
  22369. }
  22370. constructor() {
  22371. super();
  22372. }
  22373. onAwake() {
  22374. }
  22375. onEnable() {
  22376. }
  22377. onStart() {
  22378. }
  22379. onUpdate() {
  22380. }
  22381. onLateUpdate() {
  22382. }
  22383. onDisable() {
  22384. }
  22385. onDestroy() {
  22386. }
  22387. }
  22388. class Script extends Component {
  22389. get isSingleton() {
  22390. return false;
  22391. }
  22392. _onAwake() {
  22393. this.onAwake();
  22394. if (this.onStart !== Script.prototype.onStart) {
  22395. ILaya.startTimer.callLater(this, this.onStart);
  22396. }
  22397. }
  22398. _onEnable() {
  22399. var proto = Script.prototype;
  22400. if (this.onTriggerEnter !== proto.onTriggerEnter) {
  22401. this.owner.on(Event.TRIGGER_ENTER, this, this.onTriggerEnter);
  22402. }
  22403. if (this.onTriggerStay !== proto.onTriggerStay) {
  22404. this.owner.on(Event.TRIGGER_STAY, this, this.onTriggerStay);
  22405. }
  22406. if (this.onTriggerExit !== proto.onTriggerExit) {
  22407. this.owner.on(Event.TRIGGER_EXIT, this, this.onTriggerExit);
  22408. }
  22409. if (this.onMouseDown !== proto.onMouseDown) {
  22410. this.owner.on(Event.MOUSE_DOWN, this, this.onMouseDown);
  22411. }
  22412. if (this.onMouseUp !== proto.onMouseUp) {
  22413. this.owner.on(Event.MOUSE_UP, this, this.onMouseUp);
  22414. }
  22415. if (this.onClick !== proto.onClick) {
  22416. this.owner.on(Event.CLICK, this, this.onClick);
  22417. }
  22418. if (this.onStageMouseDown !== proto.onStageMouseDown) {
  22419. ILaya.stage.on(Event.MOUSE_DOWN, this, this.onStageMouseDown);
  22420. }
  22421. if (this.onStageMouseUp !== proto.onStageMouseUp) {
  22422. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  22423. }
  22424. if (this.onStageClick !== proto.onStageClick) {
  22425. ILaya.stage.on(Event.CLICK, this, this.onStageClick);
  22426. }
  22427. if (this.onStageMouseMove !== proto.onStageMouseMove) {
  22428. ILaya.stage.on(Event.MOUSE_MOVE, this, this.onStageMouseMove);
  22429. }
  22430. if (this.onDoubleClick !== proto.onDoubleClick) {
  22431. this.owner.on(Event.DOUBLE_CLICK, this, this.onDoubleClick);
  22432. }
  22433. if (this.onRightClick !== proto.onRightClick) {
  22434. this.owner.on(Event.RIGHT_CLICK, this, this.onRightClick);
  22435. }
  22436. if (this.onMouseMove !== proto.onMouseMove) {
  22437. this.owner.on(Event.MOUSE_MOVE, this, this.onMouseMove);
  22438. }
  22439. if (this.onMouseOver !== proto.onMouseOver) {
  22440. this.owner.on(Event.MOUSE_OVER, this, this.onMouseOver);
  22441. }
  22442. if (this.onMouseOut !== proto.onMouseOut) {
  22443. this.owner.on(Event.MOUSE_OUT, this, this.onMouseOut);
  22444. }
  22445. if (this.onKeyDown !== proto.onKeyDown) {
  22446. ILaya.stage.on(Event.KEY_DOWN, this, this.onKeyDown);
  22447. }
  22448. if (this.onKeyPress !== proto.onKeyPress) {
  22449. ILaya.stage.on(Event.KEY_PRESS, this, this.onKeyPress);
  22450. }
  22451. if (this.onKeyUp !== proto.onKeyUp) {
  22452. ILaya.stage.on(Event.KEY_UP, this, this.onKeyUp);
  22453. }
  22454. if (this.onUpdate !== proto.onUpdate) {
  22455. ILaya.updateTimer.frameLoop(1, this, this.onUpdate);
  22456. }
  22457. if (this.onLateUpdate !== proto.onLateUpdate) {
  22458. ILaya.lateTimer.frameLoop(1, this, this.onLateUpdate);
  22459. }
  22460. if (this.onPreRender !== proto.onPreRender) {
  22461. ILaya.lateTimer.frameLoop(1, this, this.onPreRender);
  22462. }
  22463. this.onEnable();
  22464. }
  22465. _onDisable() {
  22466. this.owner.offAllCaller(this);
  22467. ILaya.stage.offAllCaller(this);
  22468. ILaya.startTimer.clearAll(this);
  22469. ILaya.updateTimer.clearAll(this);
  22470. ILaya.lateTimer.clearAll(this);
  22471. }
  22472. _isScript() {
  22473. return true;
  22474. }
  22475. _onDestroy() {
  22476. this.onDestroy();
  22477. }
  22478. onAwake() {
  22479. }
  22480. onEnable() {
  22481. }
  22482. onStart() {
  22483. }
  22484. onTriggerEnter(other, self, contact) {
  22485. }
  22486. onTriggerStay(other, self, contact) {
  22487. }
  22488. onTriggerExit(other, self, contact) {
  22489. }
  22490. onMouseDown(e) {
  22491. }
  22492. onMouseUp(e) {
  22493. }
  22494. onClick(e) {
  22495. }
  22496. onStageMouseDown(e) {
  22497. }
  22498. onStageMouseUp(e) {
  22499. }
  22500. onStageClick(e) {
  22501. }
  22502. onStageMouseMove(e) {
  22503. }
  22504. onDoubleClick(e) {
  22505. }
  22506. onRightClick(e) {
  22507. }
  22508. onMouseMove(e) {
  22509. }
  22510. onMouseOver(e) {
  22511. }
  22512. onMouseOut(e) {
  22513. }
  22514. onKeyDown(e) {
  22515. }
  22516. onKeyPress(e) {
  22517. }
  22518. onKeyUp(e) {
  22519. }
  22520. onUpdate() {
  22521. }
  22522. onLateUpdate() {
  22523. }
  22524. onPreRender() {
  22525. }
  22526. onPostRender() {
  22527. }
  22528. onDisable() {
  22529. }
  22530. onDestroy() {
  22531. }
  22532. }
  22533. class GraphicAnimation extends FrameAnimation {
  22534. constructor() {
  22535. super(...arguments);
  22536. this._nodeIDAniDic = {};
  22537. }
  22538. _parseNodeList(uiView) {
  22539. if (!this._nodeList)
  22540. this._nodeList = [];
  22541. this._nodeDefaultProps[uiView.compId] = uiView.props;
  22542. if (uiView.compId)
  22543. this._nodeList.push(uiView.compId);
  22544. var childs = uiView.child;
  22545. if (childs) {
  22546. var i, len = childs.length;
  22547. for (i = 0; i < len; i++) {
  22548. this._parseNodeList(childs[i]);
  22549. }
  22550. }
  22551. }
  22552. _calGraphicData(aniData) {
  22553. this._setUp(null, aniData);
  22554. this._createGraphicData();
  22555. if (this._nodeIDAniDic) {
  22556. var key;
  22557. for (key in this._nodeIDAniDic) {
  22558. this._nodeIDAniDic[key] = null;
  22559. }
  22560. }
  22561. }
  22562. _createGraphicData() {
  22563. var gList = [];
  22564. var i, len = this.count;
  22565. var animationDataNew = this._usedFrames;
  22566. if (!animationDataNew)
  22567. animationDataNew = [];
  22568. var preGraphic;
  22569. for (i = 0; i < len; i++) {
  22570. if (animationDataNew[i] || !preGraphic) {
  22571. preGraphic = this._createFrameGraphic(i);
  22572. }
  22573. gList.push(preGraphic);
  22574. }
  22575. this._gList = gList;
  22576. }
  22577. _createFrameGraphic(frame) {
  22578. var g = new Graphics();
  22579. if (!GraphicAnimation._rootMatrix)
  22580. GraphicAnimation._rootMatrix = new Matrix();
  22581. this._updateNodeGraphic(this._rootNode, frame, GraphicAnimation._rootMatrix, g);
  22582. return g;
  22583. }
  22584. _updateNodeGraphic(node, frame, parentTransfrom, g, alpha = 1) {
  22585. var tNodeG;
  22586. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22587. if (!tNodeG.resultTransform)
  22588. tNodeG.resultTransform = new Matrix();
  22589. var tResultTransform;
  22590. tResultTransform = tNodeG.resultTransform;
  22591. Matrix.mul(tNodeG.transform, parentTransfrom, tResultTransform);
  22592. var tTex;
  22593. var tGraphicAlpha = tNodeG.alpha * alpha;
  22594. if (tGraphicAlpha < 0.01)
  22595. return;
  22596. if (tNodeG.skin) {
  22597. tTex = this._getTextureByUrl(tNodeG.skin);
  22598. if (tTex) {
  22599. if (tResultTransform._checkTransform()) {
  22600. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tResultTransform, tGraphicAlpha);
  22601. tNodeG.resultTransform = null;
  22602. }
  22603. else {
  22604. g.drawTexture(tTex, tResultTransform.tx, tResultTransform.ty, tNodeG.width, tNodeG.height, null, tGraphicAlpha);
  22605. }
  22606. }
  22607. }
  22608. var childs = node.child;
  22609. if (!childs)
  22610. return;
  22611. var i, len;
  22612. len = childs.length;
  22613. for (i = 0; i < len; i++) {
  22614. this._updateNodeGraphic(childs[i], frame, tResultTransform, g, tGraphicAlpha);
  22615. }
  22616. }
  22617. _updateNoChilds(tNodeG, g) {
  22618. if (!tNodeG.skin)
  22619. return;
  22620. var tTex = this._getTextureByUrl(tNodeG.skin);
  22621. if (!tTex)
  22622. return;
  22623. var tTransform = tNodeG.transform;
  22624. tTransform._checkTransform();
  22625. var onlyTranslate;
  22626. onlyTranslate = !tTransform._bTransform;
  22627. if (!onlyTranslate) {
  22628. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tTransform.clone(), tNodeG.alpha);
  22629. }
  22630. else {
  22631. g.drawTexture(tTex, tTransform.tx, tTransform.ty, tNodeG.width, tNodeG.height, null, tNodeG.alpha);
  22632. }
  22633. }
  22634. _updateNodeGraphic2(node, frame, g) {
  22635. var tNodeG;
  22636. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22637. if (!node.child) {
  22638. this._updateNoChilds(tNodeG, g);
  22639. return;
  22640. }
  22641. var tTransform = tNodeG.transform;
  22642. tTransform._checkTransform();
  22643. var onlyTranslate;
  22644. onlyTranslate = !tTransform._bTransform;
  22645. var hasTrans;
  22646. hasTrans = onlyTranslate && (tTransform.tx != 0 || tTransform.ty != 0);
  22647. var ifSave;
  22648. ifSave = (tTransform._bTransform) || tNodeG.alpha != 1;
  22649. if (ifSave)
  22650. g.save();
  22651. if (tNodeG.alpha != 1)
  22652. g.alpha(tNodeG.alpha);
  22653. if (!onlyTranslate)
  22654. g.transform(tTransform.clone());
  22655. else if (hasTrans)
  22656. g.translate(tTransform.tx, tTransform.ty);
  22657. var childs = node.child;
  22658. var tTex;
  22659. if (tNodeG.skin) {
  22660. tTex = this._getTextureByUrl(tNodeG.skin);
  22661. if (tTex) {
  22662. g.drawImage(tTex, 0, 0, tNodeG.width, tNodeG.height);
  22663. }
  22664. }
  22665. if (childs) {
  22666. var i, len;
  22667. len = childs.length;
  22668. for (i = 0; i < len; i++) {
  22669. this._updateNodeGraphic2(childs[i], frame, g);
  22670. }
  22671. }
  22672. if (ifSave) {
  22673. g.restore();
  22674. }
  22675. else {
  22676. if (!onlyTranslate) {
  22677. g.transform(tTransform.clone().invert());
  22678. }
  22679. else if (hasTrans) {
  22680. g.translate(-tTransform.tx, -tTransform.ty);
  22681. }
  22682. }
  22683. }
  22684. _calculateKeyFrames(node) {
  22685. super._calculateKeyFrames(node);
  22686. this._nodeIDAniDic[node.target] = node;
  22687. }
  22688. getNodeDataByID(nodeID) {
  22689. return this._nodeIDAniDic[nodeID];
  22690. }
  22691. _getParams(obj, params, frame, obj2) {
  22692. var rst = GraphicAnimation._temParam;
  22693. rst.length = params.length;
  22694. var i, len = params.length;
  22695. for (i = 0; i < len; i++) {
  22696. rst[i] = this._getObjVar(obj, params[i][0], frame, params[i][1], obj2);
  22697. }
  22698. return rst;
  22699. }
  22700. _getObjVar(obj, key, frame, noValue, obj2) {
  22701. if (key in obj) {
  22702. var vArr = obj[key];
  22703. if (frame >= vArr.length)
  22704. frame = vArr.length - 1;
  22705. return obj[key][frame];
  22706. }
  22707. if (key in obj2) {
  22708. return obj2[key];
  22709. }
  22710. return noValue;
  22711. }
  22712. _getNodeGraphicData(nodeID, frame, rst) {
  22713. if (!rst)
  22714. rst = new GraphicNode();
  22715. if (!rst.transform) {
  22716. rst.transform = new Matrix();
  22717. }
  22718. else {
  22719. rst.transform.identity();
  22720. }
  22721. var node = this.getNodeDataByID(nodeID);
  22722. if (!node)
  22723. return rst;
  22724. var frameData = node.frames;
  22725. var params = this._getParams(frameData, GraphicAnimation._drawTextureCmd, frame, this._nodeDefaultProps[nodeID]);
  22726. var url = params[0];
  22727. var width, height;
  22728. var px = params[5], py = params[6];
  22729. var aX = params[13], aY = params[14];
  22730. var sx = params[7], sy = params[8];
  22731. var rotate = params[9];
  22732. var skewX = params[11], skewY = params[12];
  22733. width = params[3];
  22734. height = params[4];
  22735. if (width == 0 || height == 0)
  22736. url = null;
  22737. if (width == -1)
  22738. width = 0;
  22739. if (height == -1)
  22740. height = 0;
  22741. var tex;
  22742. rst.skin = url;
  22743. rst.width = width;
  22744. rst.height = height;
  22745. if (url) {
  22746. tex = this._getTextureByUrl(url);
  22747. if (tex) {
  22748. if (!width)
  22749. width = tex.sourceWidth;
  22750. if (!height)
  22751. height = tex.sourceHeight;
  22752. }
  22753. else {
  22754. console.warn("lost skin:", url, ",you may load pics first");
  22755. }
  22756. }
  22757. rst.alpha = params[10];
  22758. var m = rst.transform;
  22759. if (aX != 0) {
  22760. px = aX * width;
  22761. }
  22762. if (aY != 0) {
  22763. py = aY * height;
  22764. }
  22765. if (px != 0 || py != 0) {
  22766. m.translate(-px, -py);
  22767. }
  22768. var tm = null;
  22769. if (rotate || sx !== 1 || sy !== 1 || skewX || skewY) {
  22770. tm = GraphicAnimation._tempMt;
  22771. tm.identity();
  22772. tm._bTransform = true;
  22773. var skx = (rotate - skewX) * 0.0174532922222222;
  22774. var sky = (rotate + skewY) * 0.0174532922222222;
  22775. var cx = Math.cos(sky);
  22776. var ssx = Math.sin(sky);
  22777. var cy = Math.sin(skx);
  22778. var ssy = Math.cos(skx);
  22779. tm.a = sx * cx;
  22780. tm.b = sx * ssx;
  22781. tm.c = -sy * cy;
  22782. tm.d = sy * ssy;
  22783. tm.tx = tm.ty = 0;
  22784. }
  22785. if (tm) {
  22786. m = Matrix.mul(m, tm, m);
  22787. }
  22788. m.translate(params[1], params[2]);
  22789. return rst;
  22790. }
  22791. _getTextureByUrl(url) {
  22792. return Loader.getRes(url);
  22793. }
  22794. setAniData(uiView, aniName = null) {
  22795. if (uiView.animations) {
  22796. this._nodeDefaultProps = {};
  22797. this._nodeGDic = {};
  22798. if (this._nodeList)
  22799. this._nodeList.length = 0;
  22800. this._rootNode = uiView;
  22801. this._parseNodeList(uiView);
  22802. var aniDic = {};
  22803. var anilist = [];
  22804. var animations = uiView.animations;
  22805. var i, len = animations.length;
  22806. var tAniO;
  22807. for (i = 0; i < len; i++) {
  22808. tAniO = animations[i];
  22809. this._labels = null;
  22810. if (aniName && aniName != tAniO.name) {
  22811. continue;
  22812. }
  22813. if (!tAniO)
  22814. continue;
  22815. try {
  22816. this._calGraphicData(tAniO);
  22817. }
  22818. catch (e) {
  22819. console.warn("parse animation fail:" + tAniO.name + ",empty animation created");
  22820. this._gList = [];
  22821. }
  22822. var frameO = {};
  22823. frameO.interval = 1000 / tAniO["frameRate"];
  22824. frameO.frames = this._gList;
  22825. frameO.labels = this._labels;
  22826. frameO.name = tAniO.name;
  22827. anilist.push(frameO);
  22828. aniDic[tAniO.name] = frameO;
  22829. }
  22830. this.animationList = anilist;
  22831. this.animationDic = aniDic;
  22832. }
  22833. GraphicAnimation._temParam.length = 0;
  22834. }
  22835. parseByData(aniData) {
  22836. var rootNode, aniO;
  22837. rootNode = aniData.nodeRoot;
  22838. aniO = aniData.aniO;
  22839. delete aniData.nodeRoot;
  22840. delete aniData.aniO;
  22841. this._nodeDefaultProps = {};
  22842. this._nodeGDic = {};
  22843. if (this._nodeList)
  22844. this._nodeList.length = 0;
  22845. this._rootNode = rootNode;
  22846. this._parseNodeList(rootNode);
  22847. this._labels = null;
  22848. try {
  22849. this._calGraphicData(aniO);
  22850. }
  22851. catch (e) {
  22852. console.warn("parse animation fail:" + aniO.name + ",empty animation created");
  22853. this._gList = [];
  22854. }
  22855. var frameO = aniData;
  22856. frameO.interval = 1000 / aniO["frameRate"];
  22857. frameO.frames = this._gList;
  22858. frameO.labels = this._labels;
  22859. frameO.name = aniO.name;
  22860. return frameO;
  22861. }
  22862. setUpAniData(uiView) {
  22863. if (uiView.animations) {
  22864. var aniDic = {};
  22865. var anilist = [];
  22866. var animations = uiView.animations;
  22867. var i, len = animations.length;
  22868. var tAniO;
  22869. for (i = 0; i < len; i++) {
  22870. tAniO = animations[i];
  22871. if (!tAniO)
  22872. continue;
  22873. var frameO = {};
  22874. frameO.name = tAniO.name;
  22875. frameO.aniO = tAniO;
  22876. frameO.nodeRoot = uiView;
  22877. anilist.push(frameO);
  22878. aniDic[tAniO.name] = frameO;
  22879. }
  22880. this.animationList = anilist;
  22881. this.animationDic = aniDic;
  22882. }
  22883. }
  22884. _clear() {
  22885. this.animationList = null;
  22886. this.animationDic = null;
  22887. this._gList = null;
  22888. this._nodeGDic = null;
  22889. }
  22890. static parseAnimationByData(animationObject) {
  22891. if (!GraphicAnimation._I)
  22892. GraphicAnimation._I = new GraphicAnimation();
  22893. var rst;
  22894. rst = GraphicAnimation._I.parseByData(animationObject);
  22895. GraphicAnimation._I._clear();
  22896. return rst;
  22897. }
  22898. static parseAnimationData(aniData) {
  22899. if (!GraphicAnimation._I)
  22900. GraphicAnimation._I = new GraphicAnimation();
  22901. GraphicAnimation._I.setUpAniData(aniData);
  22902. var rst;
  22903. rst = {};
  22904. rst.animationList = GraphicAnimation._I.animationList;
  22905. rst.animationDic = GraphicAnimation._I.animationDic;
  22906. GraphicAnimation._I._clear();
  22907. return rst;
  22908. }
  22909. }
  22910. GraphicAnimation._drawTextureCmd = [["skin", null], ["x", 0], ["y", 0], ["width", -1], ["height", -1], ["pivotX", 0], ["pivotY", 0], ["scaleX", 1], ["scaleY", 1], ["rotation", 0], ["alpha", 1], ["skewX", 0], ["skewY", 0], ["anchorX", 0], ["anchorY", 0]];
  22911. GraphicAnimation._temParam = [];
  22912. GraphicAnimation._tempMt = new Matrix();
  22913. class GraphicNode {
  22914. constructor() {
  22915. this.alpha = 1;
  22916. }
  22917. }
  22918. class Animation extends AnimationBase {
  22919. constructor() {
  22920. super();
  22921. this._setControlNode(this);
  22922. }
  22923. destroy(destroyChild = true) {
  22924. this.stop();
  22925. super.destroy(destroyChild);
  22926. this._frames = null;
  22927. this._labels = null;
  22928. }
  22929. play(start = 0, loop = true, name = "") {
  22930. if (name)
  22931. this._setFramesFromCache(name, true);
  22932. super.play(start, loop, name);
  22933. }
  22934. _setFramesFromCache(name, showWarn = false) {
  22935. if (this._url)
  22936. name = this._url + "#" + name;
  22937. if (name && Animation.framesMap[name]) {
  22938. var tAniO = Animation.framesMap[name];
  22939. if (tAniO instanceof Array) {
  22940. this._frames = Animation.framesMap[name];
  22941. this._count = this._frames.length;
  22942. }
  22943. else {
  22944. if (tAniO.nodeRoot) {
  22945. Animation.framesMap[name] = GraphicAnimation.parseAnimationByData(tAniO);
  22946. tAniO = Animation.framesMap[name];
  22947. }
  22948. this._frames = tAniO.frames;
  22949. this._count = this._frames.length;
  22950. if (!this._frameRateChanged)
  22951. this._interval = tAniO.interval;
  22952. this._labels = this._copyLabels(tAniO.labels);
  22953. }
  22954. return true;
  22955. }
  22956. else {
  22957. if (showWarn)
  22958. console.log("ani not found:", name);
  22959. }
  22960. return false;
  22961. }
  22962. _copyLabels(labels) {
  22963. if (!labels)
  22964. return null;
  22965. var rst;
  22966. rst = {};
  22967. var key;
  22968. for (key in labels) {
  22969. rst[key] = Utils.copyArray([], labels[key]);
  22970. }
  22971. return rst;
  22972. }
  22973. _frameLoop() {
  22974. if (this._visible && this._style.alpha > 0.01 && this._frames) {
  22975. super._frameLoop();
  22976. }
  22977. }
  22978. _displayToIndex(value) {
  22979. if (this._frames)
  22980. this.graphics = this._frames[value];
  22981. }
  22982. get frames() {
  22983. return this._frames;
  22984. }
  22985. set frames(value) {
  22986. this._frames = value;
  22987. if (value) {
  22988. this._count = value.length;
  22989. if (this._actionName)
  22990. this._setFramesFromCache(this._actionName, true);
  22991. this.index = this._index;
  22992. }
  22993. }
  22994. set source(value) {
  22995. if (value.indexOf(".ani") > -1)
  22996. this.loadAnimation(value);
  22997. else if (value.indexOf(".json") > -1 || value.indexOf("als") > -1 || value.indexOf("atlas") > -1)
  22998. this.loadAtlas(value);
  22999. else
  23000. this.loadImages(value.split(","));
  23001. }
  23002. set autoAnimation(value) {
  23003. this.play(0, true, value);
  23004. }
  23005. set autoPlay(value) {
  23006. if (value)
  23007. this.play();
  23008. else
  23009. this.stop();
  23010. }
  23011. clear() {
  23012. super.clear();
  23013. this.stop();
  23014. this.graphics = null;
  23015. this._frames = null;
  23016. this._labels = null;
  23017. return this;
  23018. }
  23019. loadImages(urls, cacheName = "") {
  23020. this._url = "";
  23021. if (!this._setFramesFromCache(cacheName)) {
  23022. this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(urls, cacheName);
  23023. }
  23024. return this;
  23025. }
  23026. loadAtlas(url, loaded = null, cacheName = "") {
  23027. this._url = "";
  23028. var _this = this;
  23029. if (!_this._setFramesFromCache(cacheName)) {
  23030. function onLoaded(loadUrl) {
  23031. if (url === loadUrl) {
  23032. _this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(url, cacheName);
  23033. if (loaded)
  23034. loaded.run();
  23035. }
  23036. }
  23037. if (Loader.getAtlas(url))
  23038. onLoaded(url);
  23039. else
  23040. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.ATLAS);
  23041. }
  23042. return this;
  23043. }
  23044. loadAnimation(url, loaded = null, atlas = null) {
  23045. this._url = url;
  23046. var _this = this;
  23047. if (!this._actionName)
  23048. this._actionName = "";
  23049. if (!_this._setFramesFromCache(this._actionName)) {
  23050. if (!atlas || Loader.getAtlas(atlas)) {
  23051. this._loadAnimationData(url, loaded, atlas);
  23052. }
  23053. else {
  23054. ILaya.loader.load(atlas, Handler.create(this, this._loadAnimationData, [url, loaded, atlas]), null, Loader.ATLAS);
  23055. }
  23056. }
  23057. else {
  23058. _this._setFramesFromCache(this._actionName, true);
  23059. this.index = 0;
  23060. if (loaded)
  23061. loaded.run();
  23062. }
  23063. return this;
  23064. }
  23065. _loadAnimationData(url, loaded = null, atlas = null) {
  23066. if (atlas && !Loader.getAtlas(atlas)) {
  23067. console.warn("atlas load fail:" + atlas);
  23068. return;
  23069. }
  23070. var _this = this;
  23071. function onLoaded(loadUrl) {
  23072. if (!Loader.getRes(loadUrl)) {
  23073. if (Animation.framesMap[url + "#"]) {
  23074. _this._setFramesFromCache(_this._actionName, true);
  23075. _this.index = 0;
  23076. _this._resumePlay();
  23077. if (loaded)
  23078. loaded.run();
  23079. }
  23080. return;
  23081. }
  23082. if (url === loadUrl) {
  23083. var tAniO;
  23084. if (!Animation.framesMap[url + "#"]) {
  23085. var aniData = GraphicAnimation.parseAnimationData(Loader.getRes(url));
  23086. if (!aniData)
  23087. return;
  23088. var aniList = aniData.animationList;
  23089. var i, len = aniList.length;
  23090. var defaultO;
  23091. for (i = 0; i < len; i++) {
  23092. tAniO = aniList[i];
  23093. Animation.framesMap[url + "#" + tAniO.name] = tAniO;
  23094. if (!defaultO)
  23095. defaultO = tAniO;
  23096. }
  23097. if (defaultO) {
  23098. Animation.framesMap[url + "#"] = defaultO;
  23099. _this._setFramesFromCache(_this._actionName, true);
  23100. _this.index = 0;
  23101. }
  23102. _this._resumePlay();
  23103. }
  23104. else {
  23105. _this._setFramesFromCache(_this._actionName, true);
  23106. _this.index = 0;
  23107. _this._resumePlay();
  23108. }
  23109. if (loaded)
  23110. loaded.run();
  23111. }
  23112. Loader.clearRes(url);
  23113. }
  23114. if (Loader.getRes(url))
  23115. onLoaded(url);
  23116. else
  23117. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.JSON);
  23118. }
  23119. static createFrames(url, name) {
  23120. var arr;
  23121. if (typeof (url) == 'string') {
  23122. var atlas = Loader.getAtlas(url);
  23123. if (atlas && atlas.length) {
  23124. arr = [];
  23125. for (var i = 0, n = atlas.length; i < n; i++) {
  23126. var g = new Graphics();
  23127. g.drawImage(Loader.getRes(atlas[i]), 0, 0);
  23128. arr.push(g);
  23129. }
  23130. }
  23131. }
  23132. else if (url instanceof Array) {
  23133. arr = [];
  23134. for (i = 0, n = url.length; i < n; i++) {
  23135. g = new Graphics();
  23136. g.loadImage(url[i], 0, 0);
  23137. arr.push(g);
  23138. }
  23139. }
  23140. if (name)
  23141. Animation.framesMap[name] = arr;
  23142. return arr;
  23143. }
  23144. static clearCache(key) {
  23145. var cache = Animation.framesMap;
  23146. var val;
  23147. var key2 = key + "#";
  23148. for (val in cache) {
  23149. if (val === key || val.indexOf(key2) === 0) {
  23150. delete Animation.framesMap[val];
  23151. }
  23152. }
  23153. }
  23154. }
  23155. Animation.framesMap = {};
  23156. ILaya.regClass(Animation);
  23157. ClassUtils.regClass("laya.display.Animation", Animation);
  23158. ClassUtils.regClass("Laya.Animation", Animation);
  23159. class EffectAnimation extends FrameAnimation {
  23160. constructor() {
  23161. super(...arguments);
  23162. this._initData = {};
  23163. }
  23164. set target(v) {
  23165. if (this._target)
  23166. this._target.off(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  23167. this._target = v;
  23168. if (this._target)
  23169. this._target.on(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  23170. this._addEvent();
  23171. }
  23172. get target() {
  23173. return this._target;
  23174. }
  23175. _onOtherBegin(effect) {
  23176. if (effect === this)
  23177. return;
  23178. this.stop();
  23179. }
  23180. set playEvent(event) {
  23181. this._playEvent = event;
  23182. if (!event)
  23183. return;
  23184. this._addEvent();
  23185. }
  23186. _addEvent() {
  23187. if (!this._target || !this._playEvent)
  23188. return;
  23189. this._setControlNode(this._target);
  23190. this._target.on(this._playEvent, this, this._onPlayAction);
  23191. }
  23192. _onPlayAction() {
  23193. this.play(0, false);
  23194. }
  23195. play(start = 0, loop = true, name = "") {
  23196. if (!this._target)
  23197. return;
  23198. this._target.event(EffectAnimation.EFFECT_BEGIN, [this]);
  23199. this._recordInitData();
  23200. super.play(start, loop, name);
  23201. }
  23202. _recordInitData() {
  23203. if (!this._aniKeys)
  23204. return;
  23205. var i, len;
  23206. len = this._aniKeys.length;
  23207. var key;
  23208. for (i = 0; i < len; i++) {
  23209. key = this._aniKeys[i];
  23210. this._initData[key] = this._target[key];
  23211. }
  23212. }
  23213. set effectClass(classStr) {
  23214. this._effectClass = ClassUtils.getClass(classStr);
  23215. if (this._effectClass) {
  23216. var uiData = this._effectClass["uiView"];
  23217. if (uiData) {
  23218. var aniData = uiData["animations"];
  23219. if (aniData && aniData[0]) {
  23220. var data = aniData[0];
  23221. this._setUp({}, data);
  23222. if (data.nodes && data.nodes[0]) {
  23223. this._aniKeys = data.nodes[0].keys;
  23224. }
  23225. }
  23226. }
  23227. }
  23228. }
  23229. set effectData(uiData) {
  23230. if (uiData) {
  23231. var aniData = uiData["animations"];
  23232. if (aniData && aniData[0]) {
  23233. var data = aniData[0];
  23234. this._setUp({}, data);
  23235. if (data.nodes && data.nodes[0]) {
  23236. this._aniKeys = data.nodes[0].keys;
  23237. }
  23238. }
  23239. }
  23240. }
  23241. _displayToIndex(value) {
  23242. if (!this._animationData)
  23243. return;
  23244. if (value < 0)
  23245. value = 0;
  23246. if (value > this._count)
  23247. value = this._count;
  23248. var nodes = this._animationData.nodes, i, len = nodes.length;
  23249. len = len > 1 ? 1 : len;
  23250. for (i = 0; i < len; i++) {
  23251. this._displayNodeToFrame(nodes[i], value);
  23252. }
  23253. }
  23254. _displayNodeToFrame(node, frame, targetDic = null) {
  23255. if (!this._target)
  23256. return;
  23257. var target = this._target;
  23258. var frames = node.frames, key, propFrames, value;
  23259. var keys = node.keys, i, len = keys.length;
  23260. var secondFrames = node.secondFrames;
  23261. var tSecondFrame;
  23262. var easeFun;
  23263. var tKeyFrames;
  23264. var startFrame;
  23265. var endFrame;
  23266. for (i = 0; i < len; i++) {
  23267. key = keys[i];
  23268. propFrames = frames[key];
  23269. tSecondFrame = secondFrames[key];
  23270. if (tSecondFrame == -1) {
  23271. value = this._initData[key];
  23272. }
  23273. else {
  23274. if (frame < tSecondFrame) {
  23275. tKeyFrames = node.keyframes[key];
  23276. startFrame = tKeyFrames[0];
  23277. if (startFrame.tween) {
  23278. easeFun = Ease[startFrame.tweenMethod];
  23279. if (easeFun == null)
  23280. easeFun = Ease.linearNone;
  23281. endFrame = tKeyFrames[1];
  23282. value = easeFun(frame, this._initData[key], endFrame.value - this._initData[key], endFrame.index);
  23283. }
  23284. else {
  23285. value = this._initData[key];
  23286. }
  23287. }
  23288. else {
  23289. if (propFrames.length > frame)
  23290. value = propFrames[frame];
  23291. else
  23292. value = propFrames[propFrames.length - 1];
  23293. }
  23294. }
  23295. target[key] = value;
  23296. }
  23297. }
  23298. _calculateKeyFrames(node) {
  23299. super._calculateKeyFrames(node);
  23300. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  23301. var secondFrames = {};
  23302. node.secondFrames = secondFrames;
  23303. for (key in keyFrames) {
  23304. tKeyFrames = keyFrames[key];
  23305. if (tKeyFrames.length <= 1)
  23306. secondFrames[key] = -1;
  23307. else
  23308. secondFrames[key] = tKeyFrames[1].index;
  23309. }
  23310. }
  23311. }
  23312. EffectAnimation.EFFECT_BEGIN = "effectbegin";
  23313. ClassUtils.regClass("laya.display.EffectAnimation", EffectAnimation);
  23314. ClassUtils.regClass("Laya.EffectAnimation", EffectAnimation);
  23315. class SceneLoader extends EventDispatcher {
  23316. constructor() {
  23317. super();
  23318. this._completeHandler = new Handler(this, this.onOneLoadComplete);
  23319. this.reset();
  23320. }
  23321. reset() {
  23322. this._toLoadList = [];
  23323. this._isLoading = false;
  23324. this.totalCount = 0;
  23325. }
  23326. get leftCount() {
  23327. if (this._isLoading)
  23328. return this._toLoadList.length + 1;
  23329. return this._toLoadList.length;
  23330. }
  23331. get loadedCount() {
  23332. return this.totalCount - this.leftCount;
  23333. }
  23334. load(url, is3D = false, ifCheck = true) {
  23335. if (url instanceof Array) {
  23336. var i, len;
  23337. len = url.length;
  23338. for (i = 0; i < len; i++) {
  23339. this._addToLoadList(url[i], is3D);
  23340. }
  23341. }
  23342. else {
  23343. this._addToLoadList(url, is3D);
  23344. }
  23345. if (ifCheck)
  23346. this._checkNext();
  23347. }
  23348. _addToLoadList(url, is3D = false) {
  23349. if (this._toLoadList.indexOf(url) >= 0)
  23350. return;
  23351. if (Loader.getRes(url))
  23352. return;
  23353. if (is3D) {
  23354. this._toLoadList.push({ url: url });
  23355. }
  23356. else
  23357. this._toLoadList.push(url);
  23358. this.totalCount++;
  23359. }
  23360. _checkNext() {
  23361. if (!this._isLoading) {
  23362. if (this._toLoadList.length == 0) {
  23363. this.event(Event.COMPLETE);
  23364. return;
  23365. }
  23366. var tItem;
  23367. tItem = this._toLoadList.pop();
  23368. if (typeof (tItem) == 'string') {
  23369. this.loadOne(tItem);
  23370. }
  23371. else {
  23372. this.loadOne(tItem.url, true);
  23373. }
  23374. }
  23375. }
  23376. loadOne(url, is3D = false) {
  23377. this._curUrl = url;
  23378. var type = Utils.getFileExtension(this._curUrl);
  23379. if (is3D) {
  23380. ILaya.loader.create(url, this._completeHandler);
  23381. }
  23382. else if (SceneLoader.LoadableExtensions[type]) {
  23383. ILaya.loader.load(url, this._completeHandler, null, SceneLoader.LoadableExtensions[type]);
  23384. }
  23385. else if (url != AtlasInfoManager.getFileLoadPath(url) || SceneLoader.No3dLoadTypes[type] || !LoaderManager.createMap[type]) {
  23386. ILaya.loader.load(url, this._completeHandler);
  23387. }
  23388. else {
  23389. ILaya.loader.create(url, this._completeHandler);
  23390. }
  23391. }
  23392. onOneLoadComplete() {
  23393. this._isLoading = false;
  23394. if (!Loader.getRes(this._curUrl)) {
  23395. console.log("Fail to load:", this._curUrl);
  23396. }
  23397. var type = Utils.getFileExtension(this._curUrl);
  23398. if (SceneLoader.LoadableExtensions[type]) {
  23399. var dataO;
  23400. dataO = Loader.getRes(this._curUrl);
  23401. if (dataO && (dataO instanceof Prefab)) {
  23402. dataO = dataO.json;
  23403. }
  23404. if (dataO) {
  23405. if (dataO.loadList) {
  23406. this.load(dataO.loadList, false, false);
  23407. }
  23408. if (dataO.loadList3D) {
  23409. this.load(dataO.loadList3D, true, false);
  23410. }
  23411. }
  23412. }
  23413. if (type == "sk") {
  23414. this.load(this._curUrl.replace(".sk", ".png"), false, false);
  23415. }
  23416. this.event(Event.PROGRESS, this.getProgress());
  23417. this._checkNext();
  23418. }
  23419. getProgress() {
  23420. return this.loadedCount / this.totalCount;
  23421. }
  23422. }
  23423. SceneLoader.LoadableExtensions = { "scene": Loader.JSON, "scene3d": Loader.JSON, "ani": Loader.JSON, "ui": Loader.JSON, "prefab": Loader.PREFAB };
  23424. SceneLoader.No3dLoadTypes = { "png": true, "jpg": true, "txt": true };
  23425. class Scene extends Sprite {
  23426. constructor(createChildren = true) {
  23427. super();
  23428. this.autoDestroyAtClosed = false;
  23429. this.url = null;
  23430. this._viewCreated = false;
  23431. this._$componentType = "Scene";
  23432. this._setBit(Const.NOT_READY, true);
  23433. Scene.unDestroyedScenes.push(this);
  23434. this._scene = this;
  23435. if (createChildren)
  23436. this.createChildren();
  23437. }
  23438. createChildren() {
  23439. }
  23440. static setUIMap(url) {
  23441. let uimap = ILaya.loader.getRes(url);
  23442. if (uimap) {
  23443. for (let key in uimap) {
  23444. ILaya.Loader.loadedMap[URL.formatURL(key + ".scene")] = uimap[key];
  23445. }
  23446. }
  23447. else {
  23448. throw "请提前加载uimap的json,再使用该接口设置!";
  23449. }
  23450. }
  23451. loadScene(path) {
  23452. var url = path.indexOf(".") > -1 ? path : path + ".scene";
  23453. var view = ILaya.loader.getRes(url);
  23454. if (view) {
  23455. this.createView(view);
  23456. }
  23457. else {
  23458. ILaya.loader.resetProgress();
  23459. var loader = new SceneLoader();
  23460. loader.on(Event.COMPLETE, this, this._onSceneLoaded, [url]);
  23461. loader.load(url);
  23462. }
  23463. }
  23464. _onSceneLoaded(url) {
  23465. this.createView(ILaya.Loader.getRes(url));
  23466. }
  23467. createView(view) {
  23468. if (view && !this._viewCreated) {
  23469. this._viewCreated = true;
  23470. SceneUtils.createByData(this, view);
  23471. }
  23472. }
  23473. getNodeByID(id) {
  23474. if (this._idMap)
  23475. return this._idMap[id];
  23476. return null;
  23477. }
  23478. open(closeOther = true, param = null) {
  23479. if (closeOther)
  23480. Scene.closeAll();
  23481. Scene.root.addChild(this);
  23482. this.onOpened(param);
  23483. }
  23484. onOpened(param) {
  23485. }
  23486. close(type = null) {
  23487. this.onClosed(type);
  23488. if (this.autoDestroyAtClosed)
  23489. this.destroy();
  23490. else
  23491. this.removeSelf();
  23492. }
  23493. onClosed(type = null) {
  23494. }
  23495. destroy(destroyChild = true) {
  23496. this._idMap = null;
  23497. super.destroy(destroyChild);
  23498. var list = Scene.unDestroyedScenes;
  23499. for (var i = list.length - 1; i > -1; i--) {
  23500. if (list[i] === this) {
  23501. list.splice(i, 1);
  23502. return;
  23503. }
  23504. }
  23505. }
  23506. set scaleX(value) {
  23507. if (super.get_scaleX() == value)
  23508. return;
  23509. super.set_scaleX(value);
  23510. this.event(Event.RESIZE);
  23511. }
  23512. get scaleX() {
  23513. return super.scaleX;
  23514. }
  23515. set scaleY(value) {
  23516. if (super.get_scaleY() == value)
  23517. return;
  23518. super.set_scaleY(value);
  23519. this.event(Event.RESIZE);
  23520. }
  23521. get scaleY() {
  23522. return super.scaleY;
  23523. }
  23524. get width() {
  23525. if (this._width)
  23526. return this._width;
  23527. var max = 0;
  23528. for (var i = this.numChildren - 1; i > -1; i--) {
  23529. var comp = this.getChildAt(i);
  23530. if (comp._visible) {
  23531. max = Math.max(comp._x + comp.width * comp.scaleX, max);
  23532. }
  23533. }
  23534. return max;
  23535. }
  23536. set width(value) {
  23537. if (super.get_width() == value)
  23538. return;
  23539. super.set_width(value);
  23540. this.callLater(this._sizeChanged);
  23541. }
  23542. get height() {
  23543. if (this._height)
  23544. return this._height;
  23545. var max = 0;
  23546. for (var i = this.numChildren - 1; i > -1; i--) {
  23547. var comp = this.getChildAt(i);
  23548. if (comp._visible) {
  23549. max = Math.max(comp._y + comp.height * comp.scaleY, max);
  23550. }
  23551. }
  23552. return max;
  23553. }
  23554. set height(value) {
  23555. if (super.get_height() == value)
  23556. return;
  23557. super.set_height(value);
  23558. this.callLater(this._sizeChanged);
  23559. }
  23560. _sizeChanged() {
  23561. this.event(Event.RESIZE);
  23562. }
  23563. static get root() {
  23564. if (!Scene._root) {
  23565. Scene._root = ILaya.stage.addChild(new Sprite());
  23566. Scene._root.name = "root";
  23567. ILaya.stage.on("resize", null, () => {
  23568. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23569. Scene._root.event(Event.RESIZE);
  23570. });
  23571. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23572. Scene._root.event(Event.RESIZE);
  23573. }
  23574. return Scene._root;
  23575. }
  23576. get timer() {
  23577. return this._timer || ILaya.timer;
  23578. }
  23579. set timer(value) {
  23580. this._timer = value;
  23581. }
  23582. static load(url, complete = null, progress = null) {
  23583. ILaya.loader.resetProgress();
  23584. var loader = new SceneLoader();
  23585. loader.on(Event.PROGRESS, null, onProgress);
  23586. loader.once(Event.COMPLETE, null, create);
  23587. loader.load(url);
  23588. function onProgress(value) {
  23589. if (Scene._loadPage)
  23590. Scene._loadPage.event("progress", value);
  23591. progress && progress.runWith(value);
  23592. }
  23593. function create() {
  23594. loader.off(Event.PROGRESS, null, onProgress);
  23595. var obj = ILaya.Loader.getRes(url);
  23596. if (!obj)
  23597. throw "Can not find scene:" + url;
  23598. if (!obj.props)
  23599. throw "Scene data is error:" + url;
  23600. var runtime = obj.props.runtime ? obj.props.runtime : obj.type;
  23601. var clas = ILaya.ClassUtils.getClass(runtime);
  23602. if (obj.props.renderType == "instance") {
  23603. var scene = clas.instance || (clas.instance = new clas());
  23604. }
  23605. else {
  23606. scene = new clas();
  23607. }
  23608. if (scene && scene instanceof Node) {
  23609. scene.url = url;
  23610. if (!scene._getBit(Const.NOT_READY)) {
  23611. complete && complete.runWith(scene);
  23612. }
  23613. else {
  23614. scene.on("onViewCreated", null, function () {
  23615. complete && complete.runWith(scene);
  23616. });
  23617. scene.createView(obj);
  23618. }
  23619. Scene.hideLoadingPage();
  23620. }
  23621. else {
  23622. throw "Can not find scene:" + runtime;
  23623. }
  23624. }
  23625. }
  23626. static open(url, closeOther = true, param = null, complete = null, progress = null) {
  23627. if (param instanceof Handler) {
  23628. var temp = complete;
  23629. complete = param;
  23630. param = temp;
  23631. }
  23632. Scene.showLoadingPage();
  23633. Scene.load(url, Handler.create(null, this._onSceneLoaded, [closeOther, complete, param]), progress);
  23634. }
  23635. static _onSceneLoaded(closeOther, complete, param, scene) {
  23636. scene.open(closeOther, param);
  23637. if (complete)
  23638. complete.runWith(scene);
  23639. }
  23640. static close(url, name = "") {
  23641. var flag = false;
  23642. var list = Scene.unDestroyedScenes;
  23643. for (var i = 0, n = list.length; i < n; i++) {
  23644. var scene = list[i];
  23645. if (scene && scene.parent && scene.url === url && scene.name == name) {
  23646. scene.close();
  23647. flag = true;
  23648. }
  23649. }
  23650. return flag;
  23651. }
  23652. static closeAll() {
  23653. var root = Scene.root;
  23654. for (var i = 0, n = root.numChildren; i < n; i++) {
  23655. var scene = root.getChildAt(0);
  23656. if (scene instanceof Scene)
  23657. scene.close();
  23658. else
  23659. scene.removeSelf();
  23660. }
  23661. }
  23662. static destroy(url, name = "") {
  23663. var flag = false;
  23664. var list = [].concat(Scene.unDestroyedScenes);
  23665. for (var i = 0, n = list.length; i < n; i++) {
  23666. var scene = list[i];
  23667. if (scene.url === url && scene.name == name && !scene.destroyed) {
  23668. scene.destroy();
  23669. flag = true;
  23670. }
  23671. }
  23672. return flag;
  23673. }
  23674. static gc() {
  23675. Resource.destroyUnusedResources();
  23676. }
  23677. static setLoadingPage(loadPage) {
  23678. if (Scene._loadPage != loadPage) {
  23679. Scene._loadPage = loadPage;
  23680. }
  23681. }
  23682. static showLoadingPage(param = null, delay = 500) {
  23683. if (Scene._loadPage) {
  23684. ILaya.systemTimer.clear(null, Scene._showLoading);
  23685. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23686. ILaya.systemTimer.once(delay, null, Scene._showLoading, [param], false);
  23687. }
  23688. }
  23689. static _showLoading(param) {
  23690. ILaya.stage.addChild(Scene._loadPage);
  23691. Scene._loadPage.onOpened(param);
  23692. }
  23693. static _hideLoading() {
  23694. Scene._loadPage.close();
  23695. }
  23696. static hideLoadingPage(delay = 500) {
  23697. if (Scene._loadPage) {
  23698. ILaya.systemTimer.clear(null, Scene._showLoading);
  23699. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23700. ILaya.systemTimer.once(delay, null, Scene._hideLoading);
  23701. }
  23702. }
  23703. }
  23704. Scene.unDestroyedScenes = [];
  23705. ILaya.regClass(Scene);
  23706. ClassUtils.regClass("laya.display.Scene", Scene);
  23707. ClassUtils.regClass("Laya.Scene", Scene);
  23708. class DrawParticleCmd {
  23709. static create(_temp) {
  23710. var cmd = Pool.getItemByClass("DrawParticleCmd", DrawParticleCmd);
  23711. cmd._templ = _temp;
  23712. return cmd;
  23713. }
  23714. recover() {
  23715. this._templ = null;
  23716. Pool.recover("DrawParticleCmd", this);
  23717. }
  23718. run(context, gx, gy) {
  23719. context.drawParticle(gx, gy, this._templ);
  23720. }
  23721. get cmdID() {
  23722. return DrawParticleCmd.ID;
  23723. }
  23724. }
  23725. DrawParticleCmd.ID = "DrawParticleCmd";
  23726. class FilterSetterBase {
  23727. constructor() {
  23728. }
  23729. paramChanged() {
  23730. Laya.systemTimer.callLater(this, this.buildFilter);
  23731. }
  23732. buildFilter() {
  23733. if (this._target) {
  23734. this.addFilter(this._target);
  23735. }
  23736. }
  23737. addFilter(sprite) {
  23738. if (!sprite)
  23739. return;
  23740. if (!sprite.filters) {
  23741. sprite.filters = [this._filter];
  23742. }
  23743. else {
  23744. var preFilters;
  23745. preFilters = sprite.filters;
  23746. if (preFilters.indexOf(this._filter) < 0) {
  23747. preFilters.push(this._filter);
  23748. sprite.filters = Utils.copyArray([], preFilters);
  23749. }
  23750. }
  23751. }
  23752. removeFilter(sprite) {
  23753. if (!sprite)
  23754. return;
  23755. sprite.filters = null;
  23756. }
  23757. set target(value) {
  23758. if (this._target != value) {
  23759. this._target = value;
  23760. this.paramChanged();
  23761. }
  23762. }
  23763. }
  23764. class BlurFilterGLRender {
  23765. render(rt, ctx, width, height, filter) {
  23766. var shaderValue = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23767. this.setShaderInfo(shaderValue, filter, rt.width, rt.height);
  23768. ctx.drawTarget(rt, 0, 0, width, height, Matrix.EMPTY.identity(), shaderValue);
  23769. }
  23770. setShaderInfo(shader, filter, w, h) {
  23771. shader.defines.add(Filter.BLUR);
  23772. var sv = shader;
  23773. BlurFilterGLRender.blurinfo[0] = w;
  23774. BlurFilterGLRender.blurinfo[1] = h;
  23775. sv.blurInfo = BlurFilterGLRender.blurinfo;
  23776. var sigma = filter.strength / 3.0;
  23777. var sigma2 = sigma * sigma;
  23778. filter.strength_sig2_2sig2_gauss1[0] = filter.strength;
  23779. filter.strength_sig2_2sig2_gauss1[1] = sigma2;
  23780. filter.strength_sig2_2sig2_gauss1[2] = 2.0 * sigma2;
  23781. filter.strength_sig2_2sig2_gauss1[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23782. sv.strength_sig2_2sig2_gauss1 = filter.strength_sig2_2sig2_gauss1;
  23783. }
  23784. }
  23785. BlurFilterGLRender.blurinfo = new Array(2);
  23786. class BlurFilter extends Filter {
  23787. constructor(strength = 4) {
  23788. super();
  23789. this.strength_sig2_2sig2_gauss1 = [];
  23790. this.strength = strength;
  23791. this._glRender = new BlurFilterGLRender();
  23792. }
  23793. get type() {
  23794. return Filter.BLUR;
  23795. }
  23796. getStrenth_sig2_2sig2_native() {
  23797. if (!this.strength_sig2_native) {
  23798. this.strength_sig2_native = new Float32Array(4);
  23799. }
  23800. var sigma = this.strength / 3.0;
  23801. var sigma2 = sigma * sigma;
  23802. this.strength_sig2_native[0] = this.strength;
  23803. this.strength_sig2_native[1] = sigma2;
  23804. this.strength_sig2_native[2] = 2.0 * sigma2;
  23805. this.strength_sig2_native[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23806. return this.strength_sig2_native;
  23807. }
  23808. }
  23809. class BlurFilterSetter extends FilterSetterBase {
  23810. constructor() {
  23811. super();
  23812. this._strength = 4;
  23813. this._filter = new BlurFilter(this.strength);
  23814. }
  23815. buildFilter() {
  23816. this._filter = new BlurFilter(this.strength);
  23817. super.buildFilter();
  23818. }
  23819. get strength() {
  23820. return this._strength;
  23821. }
  23822. set strength(value) {
  23823. this._strength = value;
  23824. }
  23825. }
  23826. class ButtonEffect {
  23827. constructor() {
  23828. this._curState = 0;
  23829. this.effectScale = 1.5;
  23830. this.tweenTime = 300;
  23831. }
  23832. set target(tar) {
  23833. this._tar = tar;
  23834. tar.on(Event.MOUSE_DOWN, this, this.toChangedState);
  23835. tar.on(Event.MOUSE_UP, this, this.toInitState);
  23836. tar.on(Event.MOUSE_OUT, this, this.toInitState);
  23837. }
  23838. toChangedState() {
  23839. this._curState = 1;
  23840. if (this._curTween)
  23841. Tween.clear(this._curTween);
  23842. this._curTween = Tween.to(this._tar, { scaleX: this.effectScale, scaleY: this.effectScale }, this.tweenTime, Ease[this.effectEase], Handler.create(this, this.tweenComplete));
  23843. }
  23844. toInitState() {
  23845. if (this._curState == 2)
  23846. return;
  23847. if (this._curTween)
  23848. Tween.clear(this._curTween);
  23849. this._curState = 2;
  23850. this._curTween = Tween.to(this._tar, { scaleX: 1, scaleY: 1 }, this.tweenTime, Ease[this.backEase], Handler.create(this, this.tweenComplete));
  23851. }
  23852. tweenComplete() {
  23853. this._curState = 0;
  23854. this._curTween = null;
  23855. }
  23856. }
  23857. class ColorFilterSetter extends FilterSetterBase {
  23858. constructor() {
  23859. super();
  23860. this._brightness = 0;
  23861. this._contrast = 0;
  23862. this._saturation = 0;
  23863. this._hue = 0;
  23864. this._red = 0;
  23865. this._green = 0;
  23866. this._blue = 0;
  23867. this._alpha = 0;
  23868. this._filter = new ColorFilter();
  23869. }
  23870. buildFilter() {
  23871. this._filter.reset();
  23872. this._filter.color(this.red, this.green, this.blue, this.alpha);
  23873. this._filter.adjustHue(this.hue);
  23874. this._filter.adjustContrast(this.contrast);
  23875. this._filter.adjustBrightness(this.brightness);
  23876. this._filter.adjustSaturation(this.saturation);
  23877. super.buildFilter();
  23878. }
  23879. get brightness() {
  23880. return this._brightness;
  23881. }
  23882. set brightness(value) {
  23883. this._brightness = value;
  23884. this.paramChanged();
  23885. }
  23886. get contrast() {
  23887. return this._contrast;
  23888. }
  23889. set contrast(value) {
  23890. this._contrast = value;
  23891. this.paramChanged();
  23892. }
  23893. get saturation() {
  23894. return this._saturation;
  23895. }
  23896. set saturation(value) {
  23897. this._saturation = value;
  23898. this.paramChanged();
  23899. }
  23900. get hue() {
  23901. return this._hue;
  23902. }
  23903. set hue(value) {
  23904. this._hue = value;
  23905. this.paramChanged();
  23906. }
  23907. get red() {
  23908. return this._red;
  23909. }
  23910. set red(value) {
  23911. this._red = value;
  23912. this.paramChanged();
  23913. }
  23914. get green() {
  23915. return this._green;
  23916. }
  23917. set green(value) {
  23918. this._green = value;
  23919. this.paramChanged();
  23920. }
  23921. get blue() {
  23922. return this._blue;
  23923. }
  23924. set blue(value) {
  23925. this._blue = value;
  23926. this.paramChanged();
  23927. }
  23928. get color() {
  23929. return this._color;
  23930. }
  23931. set color(value) {
  23932. this._color = value;
  23933. var colorO;
  23934. colorO = ColorUtils.create(value);
  23935. this._red = colorO.arrColor[0] * 255;
  23936. this._green = colorO.arrColor[1] * 255;
  23937. this._blue = colorO.arrColor[2] * 255;
  23938. this.paramChanged();
  23939. }
  23940. get alpha() {
  23941. return this._alpha;
  23942. }
  23943. set alpha(value) {
  23944. this._alpha = value;
  23945. this.paramChanged();
  23946. }
  23947. }
  23948. class EffectBase extends Component {
  23949. constructor() {
  23950. super(...arguments);
  23951. this.duration = 1000;
  23952. this.delay = 0;
  23953. this.repeat = 0;
  23954. this.autoDestroyAtComplete = true;
  23955. }
  23956. _onAwake() {
  23957. this.target = this.target || this.owner;
  23958. if (this.autoDestroyAtComplete)
  23959. this._comlete = Handler.create(this.target, this.target.destroy, null, false);
  23960. if (this.eventName)
  23961. this.owner.on(this.eventName, this, this._exeTween);
  23962. else
  23963. this._exeTween();
  23964. }
  23965. _exeTween() {
  23966. this._tween = this._doTween();
  23967. this._tween.repeat = this.repeat;
  23968. }
  23969. _doTween() {
  23970. return null;
  23971. }
  23972. onReset() {
  23973. this.duration = 1000;
  23974. this.delay = 0;
  23975. this.repeat = 0;
  23976. this.ease = null;
  23977. this.target = null;
  23978. if (this.eventName) {
  23979. this.owner.off(this.eventName, this, this._exeTween);
  23980. this.eventName = null;
  23981. }
  23982. if (this._comlete) {
  23983. this._comlete.recover();
  23984. this._comlete = null;
  23985. }
  23986. if (this._tween) {
  23987. this._tween.clear();
  23988. this._tween = null;
  23989. }
  23990. }
  23991. }
  23992. class FadeIn extends EffectBase {
  23993. _doTween() {
  23994. this.target.alpha = 0;
  23995. return Tween.to(this.target, { alpha: 1 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  23996. }
  23997. }
  23998. class FadeOut extends EffectBase {
  23999. _doTween() {
  24000. this.target.alpha = 1;
  24001. return Tween.to(this.target, { alpha: 0 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  24002. }
  24003. }
  24004. class GlowFilterGLRender {
  24005. setShaderInfo(shader, w, h, data) {
  24006. shader.defines.add(data.type);
  24007. var sv = shader;
  24008. sv.u_blurInfo1 = data._sv_blurInfo1;
  24009. var info2 = data._sv_blurInfo2;
  24010. info2[0] = w;
  24011. info2[1] = h;
  24012. sv.u_blurInfo2 = info2;
  24013. sv.u_color = data.getColor();
  24014. }
  24015. render(rt, ctx, width, height, filter) {
  24016. var w = width, h = height;
  24017. var svBlur = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  24018. this.setShaderInfo(svBlur, w, h, filter);
  24019. var svCP = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  24020. var matI = Matrix.TEMP.identity();
  24021. ctx.drawTarget(rt, 0, 0, w, h, matI, svBlur);
  24022. ctx.drawTarget(rt, 0, 0, w, h, matI, svCP);
  24023. }
  24024. }
  24025. class GlowFilter extends Filter {
  24026. constructor(color, blur = 4, offX = 6, offY = 6) {
  24027. super();
  24028. this._elements = new Float32Array(9);
  24029. this._sv_blurInfo1 = new Array(4);
  24030. this._sv_blurInfo2 = [0, 0, 1, 0];
  24031. this._color = new ColorUtils(color);
  24032. this.blur = Math.min(blur, 20);
  24033. this.offX = offX;
  24034. this.offY = offY;
  24035. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = this.blur;
  24036. this._sv_blurInfo1[2] = offX;
  24037. this._sv_blurInfo1[3] = -offY;
  24038. this._glRender = new GlowFilterGLRender();
  24039. }
  24040. get type() {
  24041. return BlurFilter.GLOW;
  24042. }
  24043. get offY() {
  24044. return this._elements[6];
  24045. }
  24046. set offY(value) {
  24047. this._elements[6] = value;
  24048. this._sv_blurInfo1[3] = -value;
  24049. }
  24050. get offX() {
  24051. return this._elements[5];
  24052. }
  24053. set offX(value) {
  24054. this._elements[5] = value;
  24055. this._sv_blurInfo1[2] = value;
  24056. }
  24057. getColor() {
  24058. return this._color.arrColor;
  24059. }
  24060. get blur() {
  24061. return this._elements[4];
  24062. }
  24063. set blur(value) {
  24064. this._elements[4] = value;
  24065. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = value;
  24066. }
  24067. getColorNative() {
  24068. if (!this._color_native) {
  24069. this._color_native = new Float32Array(4);
  24070. }
  24071. var color = this.getColor();
  24072. this._color_native[0] = color[0];
  24073. this._color_native[1] = color[1];
  24074. this._color_native[2] = color[2];
  24075. this._color_native[3] = color[3];
  24076. return this._color_native;
  24077. }
  24078. getBlurInfo1Native() {
  24079. if (!this._blurInof1_native) {
  24080. this._blurInof1_native = new Float32Array(4);
  24081. }
  24082. this._blurInof1_native[0] = this._blurInof1_native[1] = this.blur;
  24083. this._blurInof1_native[2] = this.offX;
  24084. this._blurInof1_native[3] = this.offY;
  24085. return this._blurInof1_native;
  24086. }
  24087. getBlurInfo2Native() {
  24088. if (!this._blurInof2_native) {
  24089. this._blurInof2_native = new Float32Array(4);
  24090. }
  24091. this._blurInof2_native[2] = 1;
  24092. return this._blurInof2_native;
  24093. }
  24094. }
  24095. class GlowFilterSetter extends FilterSetterBase {
  24096. constructor() {
  24097. super();
  24098. this._color = "#ff0000";
  24099. this._blur = 4;
  24100. this._offX = 6;
  24101. this._offY = 6;
  24102. this._filter = new GlowFilter(this._color);
  24103. }
  24104. buildFilter() {
  24105. this._filter = new GlowFilter(this.color, this.blur, this.offX, this.offY);
  24106. super.buildFilter();
  24107. }
  24108. get color() {
  24109. return this._color;
  24110. }
  24111. set color(value) {
  24112. this._color = value;
  24113. this.paramChanged();
  24114. }
  24115. get blur() {
  24116. return this._blur;
  24117. }
  24118. set blur(value) {
  24119. this._blur = value;
  24120. this.paramChanged();
  24121. }
  24122. get offX() {
  24123. return this._offX;
  24124. }
  24125. set offX(value) {
  24126. this._offX = value;
  24127. this.paramChanged();
  24128. }
  24129. get offY() {
  24130. return this._offY;
  24131. }
  24132. set offY(value) {
  24133. this._offY = value;
  24134. this.paramChanged();
  24135. }
  24136. }
  24137. class KeyLocation {
  24138. }
  24139. KeyLocation.STANDARD = 0;
  24140. KeyLocation.LEFT = 1;
  24141. KeyLocation.RIGHT = 2;
  24142. KeyLocation.NUM_PAD = 3;
  24143. class Keyboard {
  24144. }
  24145. Keyboard.NUMBER_0 = 48;
  24146. Keyboard.NUMBER_1 = 49;
  24147. Keyboard.NUMBER_2 = 50;
  24148. Keyboard.NUMBER_3 = 51;
  24149. Keyboard.NUMBER_4 = 52;
  24150. Keyboard.NUMBER_5 = 53;
  24151. Keyboard.NUMBER_6 = 54;
  24152. Keyboard.NUMBER_7 = 55;
  24153. Keyboard.NUMBER_8 = 56;
  24154. Keyboard.NUMBER_9 = 57;
  24155. Keyboard.A = 65;
  24156. Keyboard.B = 66;
  24157. Keyboard.C = 67;
  24158. Keyboard.D = 68;
  24159. Keyboard.E = 69;
  24160. Keyboard.F = 70;
  24161. Keyboard.G = 71;
  24162. Keyboard.H = 72;
  24163. Keyboard.I = 73;
  24164. Keyboard.J = 74;
  24165. Keyboard.K = 75;
  24166. Keyboard.L = 76;
  24167. Keyboard.M = 77;
  24168. Keyboard.N = 78;
  24169. Keyboard.O = 79;
  24170. Keyboard.P = 80;
  24171. Keyboard.Q = 81;
  24172. Keyboard.R = 82;
  24173. Keyboard.S = 83;
  24174. Keyboard.T = 84;
  24175. Keyboard.U = 85;
  24176. Keyboard.V = 86;
  24177. Keyboard.W = 87;
  24178. Keyboard.X = 88;
  24179. Keyboard.Y = 89;
  24180. Keyboard.Z = 90;
  24181. Keyboard.F1 = 112;
  24182. Keyboard.F2 = 113;
  24183. Keyboard.F3 = 114;
  24184. Keyboard.F4 = 115;
  24185. Keyboard.F5 = 116;
  24186. Keyboard.F6 = 117;
  24187. Keyboard.F7 = 118;
  24188. Keyboard.F8 = 119;
  24189. Keyboard.F9 = 120;
  24190. Keyboard.F10 = 121;
  24191. Keyboard.F11 = 122;
  24192. Keyboard.F12 = 123;
  24193. Keyboard.F13 = 124;
  24194. Keyboard.F14 = 125;
  24195. Keyboard.F15 = 126;
  24196. Keyboard.NUMPAD = 21;
  24197. Keyboard.NUMPAD_0 = 96;
  24198. Keyboard.NUMPAD_1 = 97;
  24199. Keyboard.NUMPAD_2 = 98;
  24200. Keyboard.NUMPAD_3 = 99;
  24201. Keyboard.NUMPAD_4 = 100;
  24202. Keyboard.NUMPAD_5 = 101;
  24203. Keyboard.NUMPAD_6 = 102;
  24204. Keyboard.NUMPAD_7 = 103;
  24205. Keyboard.NUMPAD_8 = 104;
  24206. Keyboard.NUMPAD_9 = 105;
  24207. Keyboard.NUMPAD_ADD = 107;
  24208. Keyboard.NUMPAD_DECIMAL = 110;
  24209. Keyboard.NUMPAD_DIVIDE = 111;
  24210. Keyboard.NUMPAD_ENTER = 108;
  24211. Keyboard.NUMPAD_MULTIPLY = 106;
  24212. Keyboard.NUMPAD_SUBTRACT = 109;
  24213. Keyboard.SEMICOLON = 186;
  24214. Keyboard.EQUAL = 187;
  24215. Keyboard.COMMA = 188;
  24216. Keyboard.MINUS = 189;
  24217. Keyboard.PERIOD = 190;
  24218. Keyboard.SLASH = 191;
  24219. Keyboard.BACKQUOTE = 192;
  24220. Keyboard.LEFTBRACKET = 219;
  24221. Keyboard.BACKSLASH = 220;
  24222. Keyboard.RIGHTBRACKET = 221;
  24223. Keyboard.QUOTE = 222;
  24224. Keyboard.ALTERNATE = 18;
  24225. Keyboard.BACKSPACE = 8;
  24226. Keyboard.CAPS_LOCK = 20;
  24227. Keyboard.COMMAND = 15;
  24228. Keyboard.CONTROL = 17;
  24229. Keyboard.DELETE = 46;
  24230. Keyboard.ENTER = 13;
  24231. Keyboard.ESCAPE = 27;
  24232. Keyboard.PAGE_UP = 33;
  24233. Keyboard.PAGE_DOWN = 34;
  24234. Keyboard.END = 35;
  24235. Keyboard.HOME = 36;
  24236. Keyboard.LEFT = 37;
  24237. Keyboard.UP = 38;
  24238. Keyboard.RIGHT = 39;
  24239. Keyboard.DOWN = 40;
  24240. Keyboard.SHIFT = 16;
  24241. Keyboard.SPACE = 32;
  24242. Keyboard.TAB = 9;
  24243. Keyboard.INSERT = 45;
  24244. class CommandEncoder {
  24245. constructor(layagl, reserveSize, adjustSize, isSyncToRenderThread) {
  24246. this._idata = [];
  24247. }
  24248. getArrayData() {
  24249. return this._idata;
  24250. }
  24251. getPtrID() {
  24252. return 0;
  24253. }
  24254. beginEncoding() {
  24255. }
  24256. endEncoding() {
  24257. }
  24258. clearEncoding() {
  24259. this._idata.length = 0;
  24260. }
  24261. getCount() {
  24262. return this._idata.length;
  24263. }
  24264. add_ShaderValue(o) {
  24265. this._idata.push(o);
  24266. }
  24267. addShaderUniform(one) {
  24268. this.add_ShaderValue(one);
  24269. }
  24270. }
  24271. class LayaGLRunner {
  24272. static uploadShaderUniforms(layaGL, commandEncoder, shaderData, uploadUnTexture) {
  24273. var data = shaderData._data;
  24274. var shaderUniform = commandEncoder.getArrayData();
  24275. var shaderCall = 0;
  24276. for (var i = 0, n = shaderUniform.length; i < n; i++) {
  24277. var one = shaderUniform[i];
  24278. if (uploadUnTexture || one.textureID !== -1) {
  24279. var value = data[one.dataOffset];
  24280. if (value != null)
  24281. shaderCall += one.fun.call(one.caller, one, value);
  24282. }
  24283. }
  24284. return shaderCall;
  24285. }
  24286. static uploadCustomUniform(layaGL, custom, index, data) {
  24287. var shaderCall = 0;
  24288. var one = custom[index];
  24289. if (one && data != null)
  24290. shaderCall += one.fun.call(one.caller, one, data);
  24291. return shaderCall;
  24292. }
  24293. static uploadShaderUniformsForNative(layaGL, commandEncoder, shaderData) {
  24294. var nType = LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID;
  24295. if (shaderData._runtimeCopyValues.length > 0) {
  24296. nType = LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA;
  24297. }
  24298. var data = shaderData._data;
  24299. return LayaGL.instance.uploadShaderUniforms(commandEncoder, data, nType);
  24300. }
  24301. }
  24302. class QuickTestTool {
  24303. constructor() {
  24304. }
  24305. static getMCDName(type) {
  24306. return QuickTestTool._typeToNameDic[type];
  24307. }
  24308. static showRenderTypeInfo(type, force = false) {
  24309. if (!force && QuickTestTool.showedDic[type])
  24310. return;
  24311. QuickTestTool.showedDic[type] = true;
  24312. if (!QuickTestTool._rendertypeToStrDic[type]) {
  24313. var arr = [];
  24314. var tType;
  24315. tType = 1;
  24316. while (tType <= type) {
  24317. if (tType & type) {
  24318. arr.push(QuickTestTool.getMCDName(tType & type));
  24319. }
  24320. tType = tType << 1;
  24321. }
  24322. QuickTestTool._rendertypeToStrDic[type] = arr.join(",");
  24323. }
  24324. console.log("cmd:", QuickTestTool._rendertypeToStrDic[type]);
  24325. }
  24326. static __init__() {
  24327. QuickTestTool._typeToNameDic[SpriteConst.ALPHA] = "ALPHA";
  24328. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM] = "TRANSFORM";
  24329. QuickTestTool._typeToNameDic[SpriteConst.TEXTURE] = "TEXTURE";
  24330. QuickTestTool._typeToNameDic[SpriteConst.GRAPHICS] = "GRAPHICS";
  24331. QuickTestTool._typeToNameDic[SpriteConst.ONECHILD] = "ONECHILD";
  24332. QuickTestTool._typeToNameDic[SpriteConst.CHILDS] = "CHILDS";
  24333. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM | SpriteConst.ALPHA] = "TRANSFORM|ALPHA";
  24334. QuickTestTool._typeToNameDic[SpriteConst.CANVAS] = "CANVAS";
  24335. QuickTestTool._typeToNameDic[SpriteConst.BLEND] = "BLEND";
  24336. QuickTestTool._typeToNameDic[SpriteConst.FILTERS] = "FILTERS";
  24337. QuickTestTool._typeToNameDic[SpriteConst.MASK] = "MASK";
  24338. QuickTestTool._typeToNameDic[SpriteConst.CLIP] = "CLIP";
  24339. QuickTestTool._typeToNameDic[SpriteConst.LAYAGL3D] = "LAYAGL3D";
  24340. }
  24341. render(context, x, y) {
  24342. QuickTestTool._addType(this._renderType);
  24343. QuickTestTool.showRenderTypeInfo(this._renderType);
  24344. RenderSprite.renders[this._renderType]._fun(this, context, x + this._x, y + this._y);
  24345. this._repaint = 0;
  24346. }
  24347. _stageRender(context, x, y) {
  24348. QuickTestTool._countStart();
  24349. QuickTestTool._PreStageRender.call(ILaya.stage, context, x, y);
  24350. QuickTestTool._countEnd();
  24351. }
  24352. static _countStart() {
  24353. var key;
  24354. for (key in QuickTestTool._countDic) {
  24355. QuickTestTool._countDic[key] = 0;
  24356. }
  24357. }
  24358. static _countEnd() {
  24359. QuickTestTool._i++;
  24360. if (QuickTestTool._i > 60) {
  24361. QuickTestTool.showCountInfo();
  24362. QuickTestTool._i = 0;
  24363. }
  24364. }
  24365. static _addType(type) {
  24366. if (!QuickTestTool._countDic[type]) {
  24367. QuickTestTool._countDic[type] = 1;
  24368. }
  24369. else {
  24370. QuickTestTool._countDic[type] += 1;
  24371. }
  24372. }
  24373. static showCountInfo() {
  24374. console.log("===================");
  24375. var key;
  24376. for (key in QuickTestTool._countDic) {
  24377. console.log("count:" + QuickTestTool._countDic[key]);
  24378. QuickTestTool.showRenderTypeInfo(key, true);
  24379. }
  24380. }
  24381. static enableQuickTest() {
  24382. QuickTestTool.__init__();
  24383. Sprite["prototype"]["render"] = QuickTestTool["prototype"]["render"];
  24384. QuickTestTool._PreStageRender = Stage["prototype"]["render"];
  24385. Stage["prototype"]["render"] = QuickTestTool["prototype"]["_stageRender"];
  24386. }
  24387. }
  24388. QuickTestTool.showedDic = {};
  24389. QuickTestTool._rendertypeToStrDic = {};
  24390. QuickTestTool._typeToNameDic = {};
  24391. QuickTestTool._countDic = {};
  24392. QuickTestTool._i = 0;
  24393. class Sound extends EventDispatcher {
  24394. load(url) {
  24395. }
  24396. play(startTime = 0, loops = 0) {
  24397. return null;
  24398. }
  24399. get duration() {
  24400. return 0;
  24401. }
  24402. dispose() {
  24403. }
  24404. }
  24405. class SoundNode extends Sprite {
  24406. constructor() {
  24407. super();
  24408. this.visible = false;
  24409. this.on(Event.ADDED, this, this._onParentChange);
  24410. this.on(Event.REMOVED, this, this._onParentChange);
  24411. }
  24412. _onParentChange() {
  24413. this.target = this.parent;
  24414. }
  24415. play(loops = 1, complete = null) {
  24416. if (isNaN(loops)) {
  24417. loops = 1;
  24418. }
  24419. if (!this.url)
  24420. return;
  24421. this.stop();
  24422. this._channel = SoundManager.playSound(this.url, loops, complete);
  24423. }
  24424. stop() {
  24425. if (this._channel && !this._channel.isStopped) {
  24426. this._channel.stop();
  24427. }
  24428. this._channel = null;
  24429. }
  24430. _setPlayAction(tar, event, action, add = true) {
  24431. if (!this[action])
  24432. return;
  24433. if (!tar)
  24434. return;
  24435. if (add) {
  24436. tar.on(event, this, this[action]);
  24437. }
  24438. else {
  24439. tar.off(event, this, this[action]);
  24440. }
  24441. }
  24442. _setPlayActions(tar, events, action, add = true) {
  24443. if (!tar)
  24444. return;
  24445. if (!events)
  24446. return;
  24447. var eventArr = events.split(",");
  24448. var i, len;
  24449. len = eventArr.length;
  24450. for (i = 0; i < len; i++) {
  24451. this._setPlayAction(tar, eventArr[i], action, add);
  24452. }
  24453. }
  24454. set playEvent(events) {
  24455. this._playEvents = events;
  24456. if (!events)
  24457. return;
  24458. if (this._tar) {
  24459. this._setPlayActions(this._tar, events, "play");
  24460. }
  24461. }
  24462. set target(tar) {
  24463. if (this._tar) {
  24464. this._setPlayActions(this._tar, this._playEvents, "play", false);
  24465. this._setPlayActions(this._tar, this._stopEvents, "stop", false);
  24466. }
  24467. this._tar = tar;
  24468. if (this._tar) {
  24469. this._setPlayActions(this._tar, this._playEvents, "play", true);
  24470. this._setPlayActions(this._tar, this._stopEvents, "stop", true);
  24471. }
  24472. }
  24473. set stopEvent(events) {
  24474. this._stopEvents = events;
  24475. if (!events)
  24476. return;
  24477. if (this._tar) {
  24478. this._setPlayActions(this._tar, events, "stop");
  24479. }
  24480. }
  24481. }
  24482. ClassUtils.regClass("laya.media.SoundNode", SoundNode);
  24483. ClassUtils.regClass("Laya.SoundNode", SoundNode);
  24484. class ResourceVersion {
  24485. static enable(manifestFile, callback, type = 2) {
  24486. ResourceVersion.type = type;
  24487. ILaya.loader.load(manifestFile, Handler.create(null, ResourceVersion.onManifestLoaded, [callback]), null, Loader.JSON);
  24488. }
  24489. static onManifestLoaded(callback, data) {
  24490. ResourceVersion.manifest = data;
  24491. URL.customFormat = ResourceVersion.addVersionPrefix;
  24492. callback.run();
  24493. if (!data) {
  24494. console.warn("资源版本清单文件不存在,不使用资源版本管理。忽略ERR_FILE_NOT_FOUND错误。");
  24495. }
  24496. }
  24497. static addVersionPrefix(originURL) {
  24498. originURL = URL.getAdptedFilePath(originURL);
  24499. if (ResourceVersion.manifest && ResourceVersion.manifest[originURL]) {
  24500. if (ResourceVersion.type == ResourceVersion.FILENAME_VERSION)
  24501. return ResourceVersion.manifest[originURL];
  24502. return ResourceVersion.manifest[originURL] + "/" + originURL;
  24503. }
  24504. return originURL;
  24505. }
  24506. }
  24507. ResourceVersion.FOLDER_VERSION = 1;
  24508. ResourceVersion.FILENAME_VERSION = 2;
  24509. ResourceVersion.type = ResourceVersion.FOLDER_VERSION;
  24510. class Socket extends EventDispatcher {
  24511. constructor(host = null, port = 0, byteClass = null, protocols = null) {
  24512. super();
  24513. this.disableInput = false;
  24514. this.protocols = [];
  24515. this._byteClass = byteClass ? byteClass : Byte;
  24516. this.protocols = protocols;
  24517. this.endian = Socket.BIG_ENDIAN;
  24518. if (host && port > 0 && port < 65535)
  24519. this.connect(host, port);
  24520. }
  24521. get input() {
  24522. return this._input;
  24523. }
  24524. get output() {
  24525. return this._output;
  24526. }
  24527. get connected() {
  24528. return this._connected;
  24529. }
  24530. get endian() {
  24531. return this._endian;
  24532. }
  24533. set endian(value) {
  24534. this._endian = value;
  24535. if (this._input != null)
  24536. this._input.endian = value;
  24537. if (this._output != null)
  24538. this._output.endian = value;
  24539. }
  24540. connect(host, port) {
  24541. var url = "ws://" + host + ":" + port;
  24542. this.connectByUrl(url);
  24543. }
  24544. connectByUrl(url) {
  24545. if (this._socket != null)
  24546. this.close();
  24547. this._socket && this.cleanSocket();
  24548. if (!this.protocols || this.protocols.length == 0) {
  24549. this._socket = new Browser.window.WebSocket(url);
  24550. }
  24551. else {
  24552. this._socket = new Browser.window.WebSocket(url, this.protocols);
  24553. }
  24554. this._socket.binaryType = "arraybuffer";
  24555. this._output = new this._byteClass();
  24556. this._output.endian = this.endian;
  24557. this._input = new this._byteClass();
  24558. this._input.endian = this.endian;
  24559. this._addInputPosition = 0;
  24560. this._socket.onopen = (e) => {
  24561. this._onOpen(e);
  24562. };
  24563. this._socket.onmessage = (msg) => {
  24564. this._onMessage(msg);
  24565. };
  24566. this._socket.onclose = (e) => {
  24567. this._onClose(e);
  24568. };
  24569. this._socket.onerror = (e) => {
  24570. this._onError(e);
  24571. };
  24572. }
  24573. cleanSocket() {
  24574. this.close();
  24575. this._connected = false;
  24576. this._socket.onopen = null;
  24577. this._socket.onmessage = null;
  24578. this._socket.onclose = null;
  24579. this._socket.onerror = null;
  24580. this._socket = null;
  24581. }
  24582. close() {
  24583. if (this._socket != null) {
  24584. try {
  24585. this._socket.close();
  24586. }
  24587. catch (e) {
  24588. }
  24589. }
  24590. }
  24591. _onOpen(e) {
  24592. this._connected = true;
  24593. this.event(Event.OPEN, e);
  24594. }
  24595. _onMessage(msg) {
  24596. if (!msg || !msg.data)
  24597. return;
  24598. var data = msg.data;
  24599. if (this.disableInput && data) {
  24600. this.event(Event.MESSAGE, data);
  24601. return;
  24602. }
  24603. if (this._input.length > 0 && this._input.bytesAvailable < 1) {
  24604. this._input.clear();
  24605. this._addInputPosition = 0;
  24606. }
  24607. var pre = this._input.pos;
  24608. !this._addInputPosition && (this._addInputPosition = 0);
  24609. this._input.pos = this._addInputPosition;
  24610. if (data) {
  24611. if (typeof (data) == 'string') {
  24612. this._input.writeUTFBytes(data);
  24613. }
  24614. else {
  24615. this._input.writeArrayBuffer(data);
  24616. }
  24617. this._addInputPosition = this._input.pos;
  24618. this._input.pos = pre;
  24619. }
  24620. this.event(Event.MESSAGE, data);
  24621. }
  24622. _onClose(e) {
  24623. this._connected = false;
  24624. this.event(Event.CLOSE, e);
  24625. }
  24626. _onError(e) {
  24627. this.event(Event.ERROR, e);
  24628. }
  24629. send(data) {
  24630. this._socket.send(data);
  24631. }
  24632. flush() {
  24633. if (this._output && this._output.length > 0) {
  24634. var evt;
  24635. try {
  24636. this._socket && this._socket.send(this._output.__getBuffer().slice(0, this._output.length));
  24637. }
  24638. catch (e) {
  24639. evt = e;
  24640. }
  24641. this._output.endian = this.endian;
  24642. this._output.clear();
  24643. if (evt)
  24644. this.event(Event.ERROR, evt);
  24645. }
  24646. }
  24647. }
  24648. Socket.LITTLE_ENDIAN = "littleEndian";
  24649. Socket.BIG_ENDIAN = "bigEndian";
  24650. (function (TextureDecodeFormat) {
  24651. TextureDecodeFormat[TextureDecodeFormat["Normal"] = 0] = "Normal";
  24652. TextureDecodeFormat[TextureDecodeFormat["RGBM"] = 1] = "RGBM";
  24653. })(exports.TextureDecodeFormat || (exports.TextureDecodeFormat = {}));
  24654. class System {
  24655. static changeDefinition(name, classObj) {
  24656. window.Laya[name] = classObj;
  24657. var str = name + "=classObj";
  24658. window['eval'](str);
  24659. }
  24660. }
  24661. class HTMLChar {
  24662. constructor() {
  24663. this.reset();
  24664. }
  24665. setData(char, w, h, style) {
  24666. this.char = char;
  24667. this.charNum = char.charCodeAt(0);
  24668. this.x = this.y = 0;
  24669. this.width = w;
  24670. this.height = h;
  24671. this.style = style;
  24672. this.isWord = !HTMLChar._isWordRegExp.test(char);
  24673. return this;
  24674. }
  24675. reset() {
  24676. this.x = this.y = this.width = this.height = 0;
  24677. this.isWord = false;
  24678. this.char = null;
  24679. this.charNum = 0;
  24680. this.style = null;
  24681. return this;
  24682. }
  24683. recover() {
  24684. Pool.recover("HTMLChar", this.reset());
  24685. }
  24686. static create() {
  24687. return Pool.getItemByClass("HTMLChar", HTMLChar);
  24688. }
  24689. _isChar() {
  24690. return true;
  24691. }
  24692. _getCSSStyle() {
  24693. return this.style;
  24694. }
  24695. }
  24696. HTMLChar._isWordRegExp = new RegExp("[\\w\.]", "");
  24697. class Log {
  24698. static enable() {
  24699. if (!Log._logdiv) {
  24700. Log._logdiv = Browser.createElement('div');
  24701. Log._logdiv.style.cssText = "border:white;padding:4px;overflow-y:auto;z-index:1000000;background:rgba(100,100,100,0.6);color:white;position: absolute;left:0px;top:0px;width:50%;height:50%;";
  24702. Browser.document.body.appendChild(Log._logdiv);
  24703. Log._btn = Browser.createElement("button");
  24704. Log._btn.innerText = "Hide";
  24705. Log._btn.style.cssText = "z-index:1000001;position: absolute;left:10px;top:10px;";
  24706. Log._btn.onclick = Log.toggle;
  24707. Browser.document.body.appendChild(Log._btn);
  24708. }
  24709. }
  24710. static toggle() {
  24711. var style = Log._logdiv.style;
  24712. if (style.display === "") {
  24713. Log._btn.innerText = "Show";
  24714. style.display = "none";
  24715. }
  24716. else {
  24717. Log._btn.innerText = "Hide";
  24718. style.display = "";
  24719. }
  24720. }
  24721. static print(value) {
  24722. if (Log._logdiv) {
  24723. if (Log._count >= Log.maxCount)
  24724. Log.clear();
  24725. Log._count++;
  24726. Log._logdiv.innerText += value + "\n";
  24727. if (Log.autoScrollToBottom) {
  24728. if (Log._logdiv.scrollHeight - Log._logdiv.scrollTop - Log._logdiv.clientHeight < 50) {
  24729. Log._logdiv.scrollTop = Log._logdiv.scrollHeight;
  24730. }
  24731. }
  24732. }
  24733. }
  24734. static clear() {
  24735. Log._logdiv.innerText = "";
  24736. Log._count = 0;
  24737. }
  24738. }
  24739. Log._count = 0;
  24740. Log.maxCount = 50;
  24741. Log.autoScrollToBottom = true;
  24742. let DATANUM = 300;
  24743. class PerfData {
  24744. constructor(id, color, name, scale) {
  24745. this.scale = 1.0;
  24746. this.datas = new Array(DATANUM);
  24747. this.datapos = 0;
  24748. this.id = id;
  24749. this.color = color;
  24750. this.name = name;
  24751. this.scale = scale;
  24752. }
  24753. addData(v) {
  24754. this.datas[this.datapos] = v;
  24755. this.datapos++;
  24756. this.datapos %= DATANUM;
  24757. }
  24758. }
  24759. class PerfHUD extends Sprite {
  24760. constructor() {
  24761. super();
  24762. this.datas = [];
  24763. this.xdata = new Array(PerfHUD.DATANUM);
  24764. this.ydata = new Array(PerfHUD.DATANUM);
  24765. this.hud_width = 800;
  24766. this.hud_height = 200;
  24767. this.gMinV = 0;
  24768. this.gMaxV = 100;
  24769. this.textSpace = 40;
  24770. this.sttm = 0;
  24771. PerfHUD.inst = this;
  24772. this._renderType |= SpriteConst.CUSTOM;
  24773. this._setRenderType(this._renderType);
  24774. this._setCustomRender();
  24775. this.addDataDef(0, 0xffffff, 'frame', 1.0);
  24776. this.addDataDef(1, 0x00ff00, 'update', 1.0);
  24777. this.addDataDef(2, 0xff0000, 'flush', 1.0);
  24778. PerfHUD._now = performance ? performance.now.bind(performance) : Date.now;
  24779. }
  24780. now() {
  24781. return PerfHUD._now();
  24782. }
  24783. start() {
  24784. this.sttm = PerfHUD._now();
  24785. }
  24786. end(i) {
  24787. var dt = PerfHUD._now() - this.sttm;
  24788. this.updateValue(i, dt);
  24789. }
  24790. config(w, h) {
  24791. this.hud_width = w;
  24792. this.hud_height = h;
  24793. }
  24794. addDataDef(id, color, name, scale) {
  24795. this.datas[id] = new PerfData(id, color, name, scale);
  24796. }
  24797. updateValue(id, v) {
  24798. this.datas[id].addData(v);
  24799. }
  24800. v2y(v) {
  24801. var bb = this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24802. return this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24803. }
  24804. drawHLine(ctx, v, color, text) {
  24805. var sx = this._x;
  24806. var ex = this._x + this.hud_width;
  24807. var sy = this.v2y(v);
  24808. ctx.fillText(text, sx, sy - 6, null, 'green', null);
  24809. sx += this.textSpace;
  24810. ctx.fillStyle = color;
  24811. ctx.fillRect(sx, sy, this._x + this.hud_width, 1, null);
  24812. }
  24813. customRender(ctx, x, y) {
  24814. var now = performance.now();
  24815. if (PerfHUD._lastTm <= 0)
  24816. PerfHUD._lastTm = now;
  24817. this.updateValue(0, now - PerfHUD._lastTm);
  24818. PerfHUD._lastTm = now;
  24819. ctx.save();
  24820. ctx.fillRect(this._x, this._y, this.hud_width, this.hud_height + 4, '#000000cc');
  24821. ctx.globalAlpha = 0.9;
  24822. this.drawHLine(ctx, 0, 'green', ' 0');
  24823. this.drawHLine(ctx, 10, 'green', ' 10');
  24824. this.drawHLine(ctx, 16.667, 'red', ' ');
  24825. this.drawHLine(ctx, 20, 'green', '50|20');
  24826. this.drawHLine(ctx, 16.667 * 2, 'yellow', '');
  24827. this.drawHLine(ctx, 16.667 * 3, 'yellow', '');
  24828. this.drawHLine(ctx, 16.667 * 4, 'yellow', '');
  24829. this.drawHLine(ctx, 50, 'green', '20|50');
  24830. this.drawHLine(ctx, 100, 'green', '10|100');
  24831. for (var di = 0, sz = this.datas.length; di < sz; di++) {
  24832. var cd = this.datas[di];
  24833. if (!cd)
  24834. continue;
  24835. var dtlen = cd.datas.length;
  24836. var dx = (this.hud_width - this.textSpace) / dtlen;
  24837. var cx = cd.datapos;
  24838. var _cx = this._x + this.textSpace;
  24839. ctx.fillStyle = cd.color;
  24840. for (var dtsz = dtlen; cx < dtsz; cx++) {
  24841. var sty = this.v2y(cd.datas[cx] * cd.scale);
  24842. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24843. _cx += dx;
  24844. }
  24845. for (cx = 0; cx < cd.datapos; cx++) {
  24846. sty = this.v2y(cd.datas[cx] * cd.scale);
  24847. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24848. _cx += dx;
  24849. }
  24850. }
  24851. ctx.restore();
  24852. }
  24853. }
  24854. PerfHUD._lastTm = 0;
  24855. PerfHUD._now = null;
  24856. PerfHUD.DATANUM = 300;
  24857. PerfHUD.drawTexTm = 0;
  24858. class PoolCache {
  24859. constructor() {
  24860. this.maxCount = 1000;
  24861. }
  24862. getCacheList() {
  24863. return Pool.getPoolBySign(this.sign);
  24864. }
  24865. tryDispose(force) {
  24866. var list;
  24867. list = Pool.getPoolBySign(this.sign);
  24868. if (list.length > this.maxCount) {
  24869. list.splice(this.maxCount, list.length - this.maxCount);
  24870. }
  24871. }
  24872. static addPoolCacheManager(sign, maxCount = 100) {
  24873. var cache;
  24874. cache = new PoolCache();
  24875. cache.sign = sign;
  24876. cache.maxCount = maxCount;
  24877. CacheManger.regCacheByFunction(Utils.bind(cache.tryDispose, cache), Utils.bind(cache.getCacheList, cache));
  24878. }
  24879. }
  24880. class TimeLine extends EventDispatcher {
  24881. constructor() {
  24882. super(...arguments);
  24883. this._tweenDic = {};
  24884. this._tweenDataList = [];
  24885. this._currTime = 0;
  24886. this._lastTime = 0;
  24887. this._startTime = 0;
  24888. this._index = 0;
  24889. this._gidIndex = 0;
  24890. this._firstTweenDic = {};
  24891. this._startTimeSort = false;
  24892. this._endTimeSort = false;
  24893. this._loopKey = false;
  24894. this.scale = 1;
  24895. this._frameRate = 60;
  24896. this._frameIndex = 0;
  24897. this._total = 0;
  24898. }
  24899. static to(target, props, duration, ease = null, offset = 0) {
  24900. return (new TimeLine()).to(target, props, duration, ease, offset);
  24901. }
  24902. static from(target, props, duration, ease = null, offset = 0) {
  24903. return (new TimeLine()).from(target, props, duration, ease, offset);
  24904. }
  24905. to(target, props, duration, ease = null, offset = 0) {
  24906. return this._create(target, props, duration, ease, offset, true);
  24907. }
  24908. from(target, props, duration, ease = null, offset = 0) {
  24909. return this._create(target, props, duration, ease, offset, false);
  24910. }
  24911. _create(target, props, duration, ease, offset, isTo) {
  24912. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24913. tTweenData.isTo = isTo;
  24914. tTweenData.type = 0;
  24915. tTweenData.target = target;
  24916. tTweenData.duration = duration;
  24917. tTweenData.data = props;
  24918. tTweenData.startTime = this._startTime + offset;
  24919. tTweenData.endTime = tTweenData.startTime + tTweenData.duration;
  24920. tTweenData.ease = ease;
  24921. this._startTime = Math.max(tTweenData.endTime, this._startTime);
  24922. this._tweenDataList.push(tTweenData);
  24923. this._startTimeSort = true;
  24924. this._endTimeSort = true;
  24925. return this;
  24926. }
  24927. addLabel(label, offset) {
  24928. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24929. tTweenData.type = 1;
  24930. tTweenData.data = label;
  24931. tTweenData.endTime = tTweenData.startTime = this._startTime + offset;
  24932. this._labelDic || (this._labelDic = {});
  24933. this._labelDic[label] = tTweenData;
  24934. this._tweenDataList.push(tTweenData);
  24935. return this;
  24936. }
  24937. removeLabel(label) {
  24938. if (this._labelDic && this._labelDic[label]) {
  24939. var tTweenData = this._labelDic[label];
  24940. if (tTweenData) {
  24941. var tIndex = this._tweenDataList.indexOf(tTweenData);
  24942. if (tIndex > -1) {
  24943. this._tweenDataList.splice(tIndex, 1);
  24944. }
  24945. }
  24946. delete this._labelDic[label];
  24947. }
  24948. }
  24949. gotoTime(time) {
  24950. if (this._tweenDataList == null || this._tweenDataList.length == 0)
  24951. return;
  24952. var tTween;
  24953. var tObject;
  24954. for (var p in this._firstTweenDic) {
  24955. tObject = this._firstTweenDic[p];
  24956. if (tObject) {
  24957. for (var tDataP in tObject) {
  24958. if (tDataP in tObject.diyTarget) {
  24959. tObject.diyTarget[tDataP] = tObject[tDataP];
  24960. }
  24961. }
  24962. }
  24963. }
  24964. for (p in this._tweenDic) {
  24965. tTween = this._tweenDic[p];
  24966. tTween.clear();
  24967. delete this._tweenDic[p];
  24968. }
  24969. this._index = 0;
  24970. this._gidIndex = 0;
  24971. this._currTime = time;
  24972. this._lastTime = Browser.now();
  24973. var tTweenDataCopyList;
  24974. if (this._endTweenDataList == null || this._endTimeSort) {
  24975. this._endTimeSort = false;
  24976. this._endTweenDataList = tTweenDataCopyList = this._tweenDataList.concat();
  24977. function Compare(paraA, paraB) {
  24978. if (paraA.endTime > paraB.endTime) {
  24979. return 1;
  24980. }
  24981. else if (paraA.endTime < paraB.endTime) {
  24982. return -1;
  24983. }
  24984. else {
  24985. return 0;
  24986. }
  24987. }
  24988. tTweenDataCopyList.sort(Compare);
  24989. }
  24990. else {
  24991. tTweenDataCopyList = this._endTweenDataList;
  24992. }
  24993. var tTweenData;
  24994. for (var i = 0, n = tTweenDataCopyList.length; i < n; i++) {
  24995. tTweenData = tTweenDataCopyList[i];
  24996. if (tTweenData.type == 0) {
  24997. if (time >= tTweenData.endTime) {
  24998. this._index = Math.max(this._index, i + 1);
  24999. var props = tTweenData.data;
  25000. if (tTweenData.isTo) {
  25001. for (var tP in props) {
  25002. tTweenData.target[tP] = props[tP];
  25003. }
  25004. }
  25005. }
  25006. else {
  25007. break;
  25008. }
  25009. }
  25010. }
  25011. for (i = 0, n = this._tweenDataList.length; i < n; i++) {
  25012. tTweenData = this._tweenDataList[i];
  25013. if (tTweenData.type == 0) {
  25014. if (time >= tTweenData.startTime && time < tTweenData.endTime) {
  25015. this._index = Math.max(this._index, i + 1);
  25016. this._gidIndex++;
  25017. tTween = Pool.getItemByClass("tween", Tween);
  25018. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  25019. tTween.setStartTime(this._currTime - (time - tTweenData.startTime));
  25020. tTween._updateEase(this._currTime);
  25021. tTween.gid = this._gidIndex;
  25022. this._tweenDic[this._gidIndex] = tTween;
  25023. }
  25024. }
  25025. }
  25026. }
  25027. gotoLabel(Label) {
  25028. if (this._labelDic == null)
  25029. return;
  25030. var tLabelData = this._labelDic[Label];
  25031. if (tLabelData)
  25032. this.gotoTime(tLabelData.startTime);
  25033. }
  25034. pause() {
  25035. ILaya.timer.clear(this, this._update);
  25036. }
  25037. resume() {
  25038. this.play(this._currTime, this._loopKey);
  25039. }
  25040. play(timeOrLabel = 0, loop = false) {
  25041. if (!this._tweenDataList)
  25042. return;
  25043. if (this._startTimeSort) {
  25044. this._startTimeSort = false;
  25045. function Compare(paraA, paraB) {
  25046. if (paraA.startTime > paraB.startTime) {
  25047. return 1;
  25048. }
  25049. else if (paraA.startTime < paraB.startTime) {
  25050. return -1;
  25051. }
  25052. else {
  25053. return 0;
  25054. }
  25055. }
  25056. this._tweenDataList.sort(Compare);
  25057. for (var i = 0, n = this._tweenDataList.length; i < n; i++) {
  25058. var tTweenData = this._tweenDataList[i];
  25059. if (tTweenData != null && tTweenData.type == 0) {
  25060. var tTarget = tTweenData.target;
  25061. var gid = (tTarget.$_GID || (tTarget.$_GID = Utils.getGID()));
  25062. var tSrcData = null;
  25063. if (this._firstTweenDic[gid] == null) {
  25064. tSrcData = {};
  25065. tSrcData.diyTarget = tTarget;
  25066. this._firstTweenDic[gid] = tSrcData;
  25067. }
  25068. else {
  25069. tSrcData = this._firstTweenDic[gid];
  25070. }
  25071. for (var p in tTweenData.data) {
  25072. if (tSrcData[p] == null) {
  25073. tSrcData[p] = tTarget[p];
  25074. }
  25075. }
  25076. }
  25077. }
  25078. }
  25079. if (typeof (timeOrLabel) == 'string') {
  25080. this.gotoLabel(timeOrLabel);
  25081. }
  25082. else {
  25083. this.gotoTime(timeOrLabel);
  25084. }
  25085. this._loopKey = loop;
  25086. this._lastTime = Browser.now();
  25087. ILaya.timer.frameLoop(1, this, this._update);
  25088. }
  25089. _update() {
  25090. if (this._currTime >= this._startTime) {
  25091. if (this._loopKey) {
  25092. this._complete();
  25093. if (!this._tweenDataList)
  25094. return;
  25095. this.gotoTime(0);
  25096. }
  25097. else {
  25098. for (var p in this._tweenDic) {
  25099. tTween = this._tweenDic[p];
  25100. tTween.complete();
  25101. }
  25102. this.pause();
  25103. this._complete();
  25104. return;
  25105. }
  25106. }
  25107. var tNow = Browser.now();
  25108. var tFrameTime = tNow - this._lastTime;
  25109. var tCurrTime = this._currTime += tFrameTime * this.scale;
  25110. this._lastTime = tNow;
  25111. for (p in this._tweenDic) {
  25112. tTween = this._tweenDic[p];
  25113. tTween._updateEase(tCurrTime);
  25114. }
  25115. var tTween;
  25116. if (this._tweenDataList.length != 0 && this._index < this._tweenDataList.length) {
  25117. var tTweenData = this._tweenDataList[this._index];
  25118. if (tCurrTime >= tTweenData.startTime) {
  25119. this._index++;
  25120. if (tTweenData.type == 0) {
  25121. this._gidIndex++;
  25122. tTween = Pool.getItemByClass("tween", Tween);
  25123. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  25124. tTween.setStartTime(tCurrTime);
  25125. tTween.gid = this._gidIndex;
  25126. this._tweenDic[this._gidIndex] = tTween;
  25127. tTween._updateEase(tCurrTime);
  25128. }
  25129. else {
  25130. this.event(Event.LABEL, tTweenData.data);
  25131. }
  25132. }
  25133. }
  25134. }
  25135. _animComplete(index) {
  25136. var tTween = this._tweenDic[index];
  25137. if (tTween)
  25138. delete this._tweenDic[index];
  25139. }
  25140. _complete() {
  25141. this.event(Event.COMPLETE);
  25142. }
  25143. get index() {
  25144. return this._frameIndex;
  25145. }
  25146. set index(value) {
  25147. this._frameIndex = value;
  25148. this.gotoTime(this._frameIndex / this._frameRate * 1000);
  25149. }
  25150. get total() {
  25151. this._total = Math.floor(this._startTime / 1000 * this._frameRate);
  25152. return this._total;
  25153. }
  25154. reset() {
  25155. var p;
  25156. if (this._labelDic) {
  25157. for (p in this._labelDic) {
  25158. delete this._labelDic[p];
  25159. }
  25160. }
  25161. var tTween;
  25162. for (p in this._tweenDic) {
  25163. tTween = this._tweenDic[p];
  25164. tTween.clear();
  25165. delete this._tweenDic[p];
  25166. }
  25167. for (p in this._firstTweenDic) {
  25168. delete this._firstTweenDic[p];
  25169. }
  25170. this._endTweenDataList = null;
  25171. if (this._tweenDataList && this._tweenDataList.length) {
  25172. var i, len;
  25173. len = this._tweenDataList.length;
  25174. for (i = 0; i < len; i++) {
  25175. if (this._tweenDataList[i])
  25176. this._tweenDataList[i].destroy();
  25177. }
  25178. }
  25179. this._tweenDataList.length = 0;
  25180. this._currTime = 0;
  25181. this._lastTime = 0;
  25182. this._startTime = 0;
  25183. this._index = 0;
  25184. this._gidIndex = 0;
  25185. this.scale = 1;
  25186. ILaya.timer.clear(this, this._update);
  25187. }
  25188. destroy() {
  25189. this.reset();
  25190. this._labelDic = null;
  25191. this._tweenDic = null;
  25192. this._tweenDataList = null;
  25193. this._firstTweenDic = null;
  25194. }
  25195. }
  25196. class tweenData {
  25197. constructor() {
  25198. this.type = 0;
  25199. this.isTo = true;
  25200. }
  25201. destroy() {
  25202. this.target = null;
  25203. this.ease = null;
  25204. this.data = null;
  25205. this.isTo = true;
  25206. this.type = 0;
  25207. Pool.recover("tweenData", this);
  25208. }
  25209. }
  25210. class ShaderValue {
  25211. constructor() {
  25212. }
  25213. }
  25214. class ArabicReshaper {
  25215. characterMapContains(c) {
  25216. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  25217. if (ArabicReshaper.charsMap[i][0] === c) {
  25218. return true;
  25219. }
  25220. }
  25221. return false;
  25222. }
  25223. getCharRep(c) {
  25224. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  25225. if (ArabicReshaper.charsMap[i][0] === c) {
  25226. return ArabicReshaper.charsMap[i];
  25227. }
  25228. }
  25229. return false;
  25230. }
  25231. getCombCharRep(c1, c2) {
  25232. for (var i = 0; i < ArabicReshaper.combCharsMap.length; ++i) {
  25233. if (ArabicReshaper.combCharsMap[i][0][0] === c1 && ArabicReshaper.combCharsMap[i][0][1] === c2) {
  25234. return ArabicReshaper.combCharsMap[i];
  25235. }
  25236. }
  25237. return false;
  25238. }
  25239. isTransparent(c) {
  25240. for (var i = 0; i < ArabicReshaper.transChars.length; ++i) {
  25241. if (ArabicReshaper.transChars[i] === c) {
  25242. return true;
  25243. }
  25244. }
  25245. return false;
  25246. }
  25247. getOriginalCharsFromCode(code) {
  25248. var j;
  25249. for (j = 0; j < ArabicReshaper.charsMap.length; ++j) {
  25250. if (ArabicReshaper.charsMap[j].indexOf(code) > -1) {
  25251. return String.fromCharCode(ArabicReshaper.charsMap[j][0]);
  25252. }
  25253. }
  25254. for (j = 0; j < ArabicReshaper.combCharsMap.length; ++j) {
  25255. if (ArabicReshaper.combCharsMap[j].indexOf(code) > -1) {
  25256. return String.fromCharCode(ArabicReshaper.combCharsMap[j][0][0]) +
  25257. String.fromCharCode(ArabicReshaper.combCharsMap[j][0][1]);
  25258. }
  25259. }
  25260. return String.fromCharCode(code);
  25261. }
  25262. convertArabic(normal) {
  25263. var crep, combcrep, shaped = '';
  25264. for (var i = 0; i < normal.length; ++i) {
  25265. var current = normal.charCodeAt(i);
  25266. if (this.characterMapContains(current)) {
  25267. var prev = null, next = null, prevID = i - 1, nextID = i + 1;
  25268. for (; prevID >= 0; --prevID) {
  25269. if (!this.isTransparent(normal.charCodeAt(prevID))) {
  25270. break;
  25271. }
  25272. }
  25273. prev = (prevID >= 0) ? normal.charCodeAt(prevID) : null;
  25274. crep = prev ? this.getCharRep(prev) : false;
  25275. if (!crep || crep[2] == null && crep[3] == null) {
  25276. prev = null;
  25277. }
  25278. for (; nextID < normal.length; ++nextID) {
  25279. if (!this.isTransparent(normal.charCodeAt(nextID))) {
  25280. break;
  25281. }
  25282. }
  25283. next = (nextID < normal.length) ? normal.charCodeAt(nextID) : null;
  25284. crep = next ? this.getCharRep(next) : false;
  25285. if (!crep || crep[3] == null && crep[4] == null) {
  25286. next = null;
  25287. }
  25288. if (current === 0x0644 && next != null &&
  25289. (next === 0x0622 || next === 0x0623 || next === 0x0625 || next === 0x0627)) {
  25290. combcrep = this.getCombCharRep(current, next);
  25291. if (prev != null) {
  25292. shaped += String.fromCharCode(combcrep[4]);
  25293. }
  25294. else {
  25295. shaped += String.fromCharCode(combcrep[1]);
  25296. }
  25297. ++i;
  25298. continue;
  25299. }
  25300. crep = this.getCharRep(current);
  25301. if (prev != null && next != null && crep[3] != null) {
  25302. shaped += String.fromCharCode(crep[3]);
  25303. continue;
  25304. }
  25305. else if (prev != null && crep[4] != null) {
  25306. shaped += String.fromCharCode(crep[4]);
  25307. continue;
  25308. }
  25309. else if (next != null && crep[2] != null) {
  25310. shaped += String.fromCharCode(crep[2]);
  25311. continue;
  25312. }
  25313. else {
  25314. shaped += String.fromCharCode(crep[1]);
  25315. }
  25316. }
  25317. else {
  25318. shaped += String.fromCharCode(current);
  25319. }
  25320. }
  25321. return shaped;
  25322. }
  25323. convertArabicBack(apfb) {
  25324. var toReturn = '', selectedChar;
  25325. var i;
  25326. for (i = 0; i < apfb.length; ++i) {
  25327. selectedChar = apfb.charCodeAt(i);
  25328. toReturn += this.getOriginalCharsFromCode(selectedChar);
  25329. }
  25330. return toReturn;
  25331. }
  25332. }
  25333. ArabicReshaper.charsMap = [[0x0621, 0xFE80, null, null, null],
  25334. [0x0622, 0xFE81, null, null, 0xFE82],
  25335. [0x0623, 0xFE83, null, null, 0xFE84],
  25336. [0x0624, 0xFE85, null, null, 0xFE86],
  25337. [0x0625, 0xFE87, null, null, 0xFE88],
  25338. [0x0626, 0xFE89, 0xFE8B, 0xFE8C, 0xFE8A],
  25339. [0x0627, 0xFE8D, null, null, 0xFE8E],
  25340. [0x0628, 0xFE8F, 0xFE91, 0xFE92, 0xFE90],
  25341. [0x0629, 0xFE93, null, null, 0xFE94],
  25342. [0x062A, 0xFE95, 0xFE97, 0xFE98, 0xFE96],
  25343. [0x062B, 0xFE99, 0xFE9B, 0xFE9C, 0xFE9A],
  25344. [0x062C, 0xFE9D, 0xFE9F, 0xFEA0, 0xFE9E],
  25345. [0x062D, 0xFEA1, 0xFEA3, 0xFEA4, 0xFEA2],
  25346. [0x062E, 0xFEA5, 0xFEA7, 0xFEA8, 0xFEA6],
  25347. [0x062F, 0xFEA9, null, null, 0xFEAA],
  25348. [0x0630, 0xFEAB, null, null, 0xFEAC],
  25349. [0x0631, 0xFEAD, null, null, 0xFEAE],
  25350. [0x0632, 0xFEAF, null, null, 0xFEB0],
  25351. [0x0633, 0xFEB1, 0xFEB3, 0xFEB4, 0xFEB2],
  25352. [0x0634, 0xFEB5, 0xFEB7, 0xFEB8, 0xFEB6],
  25353. [0x0635, 0xFEB9, 0xFEBB, 0xFEBC, 0xFEBA],
  25354. [0x0636, 0xFEBD, 0xFEBF, 0xFEC0, 0xFEBE],
  25355. [0x0637, 0xFEC1, 0xFEC3, 0xFEC4, 0xFEC2],
  25356. [0x0638, 0xFEC5, 0xFEC7, 0xFEC8, 0xFEC6],
  25357. [0x0639, 0xFEC9, 0xFECB, 0xFECC, 0xFECA],
  25358. [0x063A, 0xFECD, 0xFECF, 0xFED0, 0xFECE],
  25359. [0x0640, 0x0640, 0x0640, 0x0640, 0x0640],
  25360. [0x0641, 0xFED1, 0xFED3, 0xFED4, 0xFED2],
  25361. [0x0642, 0xFED5, 0xFED7, 0xFED8, 0xFED6],
  25362. [0x0643, 0xFED9, 0xFEDB, 0xFEDC, 0xFEDA],
  25363. [0x0644, 0xFEDD, 0xFEDF, 0xFEE0, 0xFEDE],
  25364. [0x0645, 0xFEE1, 0xFEE3, 0xFEE4, 0xFEE2],
  25365. [0x0646, 0xFEE5, 0xFEE7, 0xFEE8, 0xFEE6],
  25366. [0x0647, 0xFEE9, 0xFEEB, 0xFEEC, 0xFEEA],
  25367. [0x0648, 0xFEED, null, null, 0xFEEE],
  25368. [0x0649, 0xFEEF, null, null, 0xFEF0],
  25369. [0x064A, 0xFEF1, 0xFEF3, 0xFEF4, 0xFEF2],
  25370. [0x067E, 0xFB56, 0xFB58, 0xFB59, 0xFB57],
  25371. [0x06CC, 0xFBFC, 0xFBFE, 0xFBFF, 0xFBFD],
  25372. [0x0686, 0xFB7A, 0xFB7C, 0xFB7D, 0xFB7B],
  25373. [0x06A9, 0xFB8E, 0xFB90, 0xFB91, 0xFB8F],
  25374. [0x06AF, 0xFB92, 0xFB94, 0xFB95, 0xFB93],
  25375. [0x0698, 0xFB8A, null, null, 0xFB8B]];
  25376. ArabicReshaper.combCharsMap = [[[0x0644, 0x0622], 0xFEF5, null, null, 0xFEF6],
  25377. [[0x0644, 0x0623], 0xFEF7, null, null, 0xFEF8],
  25378. [[0x0644, 0x0625], 0xFEF9, null, null, 0xFEFA],
  25379. [[0x0644, 0x0627], 0xFEFB, null, null, 0xFEFC]];
  25380. ArabicReshaper.transChars = [0x0610,
  25381. 0x0612,
  25382. 0x0613,
  25383. 0x0614,
  25384. 0x0615,
  25385. 0x064B,
  25386. 0x064C,
  25387. 0x064D,
  25388. 0x064E,
  25389. 0x064F,
  25390. 0x0650,
  25391. 0x0651,
  25392. 0x0652,
  25393. 0x0653,
  25394. 0x0654,
  25395. 0x0655,
  25396. 0x0656,
  25397. 0x0657,
  25398. 0x0658,
  25399. 0x0670,
  25400. 0x06D6,
  25401. 0x06D7,
  25402. 0x06D8,
  25403. 0x06D9,
  25404. 0x06DA,
  25405. 0x06DB,
  25406. 0x06DC,
  25407. 0x06DF,
  25408. 0x06E0,
  25409. 0x06E1,
  25410. 0x06E2,
  25411. 0x06E3,
  25412. 0x06E4,
  25413. 0x06E7,
  25414. 0x06E8,
  25415. 0x06EA,
  25416. 0x06EB,
  25417. 0x06EC,
  25418. 0x06ED];
  25419. class MatirxArray {
  25420. static ArrayMul(a, b, o) {
  25421. if (!a) {
  25422. MatirxArray.copyArray(b, o);
  25423. return;
  25424. }
  25425. if (!b) {
  25426. MatirxArray.copyArray(a, o);
  25427. return;
  25428. }
  25429. var ai0, ai1, ai2, ai3;
  25430. for (var i = 0; i < 4; i++) {
  25431. ai0 = a[i];
  25432. ai1 = a[i + 4];
  25433. ai2 = a[i + 8];
  25434. ai3 = a[i + 12];
  25435. o[i] = ai0 * b[0] + ai1 * b[1] + ai2 * b[2] + ai3 * b[3];
  25436. o[i + 4] = ai0 * b[4] + ai1 * b[5] + ai2 * b[6] + ai3 * b[7];
  25437. o[i + 8] = ai0 * b[8] + ai1 * b[9] + ai2 * b[10] + ai3 * b[11];
  25438. o[i + 12] = ai0 * b[12] + ai1 * b[13] + ai2 * b[14] + ai3 * b[15];
  25439. }
  25440. }
  25441. static copyArray(f, t) {
  25442. if (!f)
  25443. return;
  25444. if (!t)
  25445. return;
  25446. for (var i = 0; i < f.length; i++) {
  25447. t[i] = f[i];
  25448. }
  25449. }
  25450. }
  25451. exports.AlphaCmd = AlphaCmd;
  25452. exports.Animation = Animation;
  25453. exports.AnimationBase = AnimationBase;
  25454. exports.ArabicReshaper = ArabicReshaper;
  25455. exports.AtlasGrid = AtlasGrid;
  25456. exports.AtlasInfoManager = AtlasInfoManager;
  25457. exports.AudioSound = AudioSound;
  25458. exports.AudioSoundChannel = AudioSoundChannel;
  25459. exports.BasePoly = BasePoly;
  25460. exports.BaseShader = BaseShader;
  25461. exports.BaseTexture = BaseTexture;
  25462. exports.Bezier = Bezier;
  25463. exports.Bitmap = Bitmap;
  25464. exports.BitmapFont = BitmapFont;
  25465. exports.BlendMode = BlendMode;
  25466. exports.BlurFilter = BlurFilter;
  25467. exports.BlurFilterGLRender = BlurFilterGLRender;
  25468. exports.BlurFilterSetter = BlurFilterSetter;
  25469. exports.BoundsStyle = BoundsStyle;
  25470. exports.Browser = Browser;
  25471. exports.Buffer = Buffer;
  25472. exports.Buffer2D = Buffer2D;
  25473. exports.BufferState2D = BufferState2D;
  25474. exports.BufferStateBase = BufferStateBase;
  25475. exports.ButtonEffect = ButtonEffect;
  25476. exports.Byte = Byte;
  25477. exports.CONST3D2D = CONST3D2D;
  25478. exports.CacheManger = CacheManger;
  25479. exports.CacheStyle = CacheStyle;
  25480. exports.CallLater = CallLater;
  25481. exports.CharRenderInfo = CharRenderInfo;
  25482. exports.CharRender_Canvas = CharRender_Canvas;
  25483. exports.CharRender_Native = CharRender_Native;
  25484. exports.CharSubmitCache = CharSubmitCache;
  25485. exports.ClassUtils = ClassUtils;
  25486. exports.ClipRectCmd = ClipRectCmd;
  25487. exports.ColorFilter = ColorFilter;
  25488. exports.ColorFilterSetter = ColorFilterSetter;
  25489. exports.ColorUtils = ColorUtils;
  25490. exports.CommandEncoder = CommandEncoder;
  25491. exports.CommonScript = CommonScript;
  25492. exports.Component = Component;
  25493. exports.Config = Config;
  25494. exports.Const = Const;
  25495. exports.Context = Context;
  25496. exports.Dragging = Dragging;
  25497. exports.Draw9GridTexture = Draw9GridTexture;
  25498. exports.DrawCircleCmd = DrawCircleCmd;
  25499. exports.DrawCurvesCmd = DrawCurvesCmd;
  25500. exports.DrawImageCmd = DrawImageCmd;
  25501. exports.DrawLineCmd = DrawLineCmd;
  25502. exports.DrawLinesCmd = DrawLinesCmd;
  25503. exports.DrawParticleCmd = DrawParticleCmd;
  25504. exports.DrawPathCmd = DrawPathCmd;
  25505. exports.DrawPieCmd = DrawPieCmd;
  25506. exports.DrawPolyCmd = DrawPolyCmd;
  25507. exports.DrawRectCmd = DrawRectCmd;
  25508. exports.DrawStyle = DrawStyle;
  25509. exports.DrawTextureCmd = DrawTextureCmd;
  25510. exports.DrawTexturesCmd = DrawTexturesCmd;
  25511. exports.DrawTrianglesCmd = DrawTrianglesCmd;
  25512. exports.Earcut = Earcut;
  25513. exports.EarcutNode = EarcutNode;
  25514. exports.Ease = Ease;
  25515. exports.EffectAnimation = EffectAnimation;
  25516. exports.EffectBase = EffectBase;
  25517. exports.Event = Event;
  25518. exports.EventDispatcher = EventDispatcher;
  25519. exports.FadeIn = FadeIn;
  25520. exports.FadeOut = FadeOut;
  25521. exports.FillTextCmd = FillTextCmd;
  25522. exports.FillTextureCmd = FillTextureCmd;
  25523. exports.Filter = Filter;
  25524. exports.FilterSetterBase = FilterSetterBase;
  25525. exports.FontInfo = FontInfo;
  25526. exports.FrameAnimation = FrameAnimation;
  25527. exports.GlowFilter = GlowFilter;
  25528. exports.GlowFilterGLRender = GlowFilterGLRender;
  25529. exports.GlowFilterSetter = GlowFilterSetter;
  25530. exports.GrahamScan = GrahamScan;
  25531. exports.GraphicAnimation = GraphicAnimation;
  25532. exports.Graphics = Graphics;
  25533. exports.GraphicsBounds = GraphicsBounds;
  25534. exports.HTMLCanvas = HTMLCanvas;
  25535. exports.HTMLChar = HTMLChar;
  25536. exports.HTMLImage = HTMLImage;
  25537. exports.Handler = Handler;
  25538. exports.HitArea = HitArea;
  25539. exports.HttpRequest = HttpRequest;
  25540. exports.ICharRender = ICharRender;
  25541. exports.ILaya = ILaya;
  25542. exports.IStatRender = IStatRender;
  25543. exports.IndexBuffer2D = IndexBuffer2D;
  25544. exports.InlcudeFile = InlcudeFile;
  25545. exports.Input = Input;
  25546. exports.KeyBoardManager = KeyBoardManager;
  25547. exports.KeyLocation = KeyLocation;
  25548. exports.Keyboard = Keyboard;
  25549. exports.Laya = Laya;
  25550. exports.LayaGL = LayaGL;
  25551. exports.LayaGLQuickRunner = LayaGLQuickRunner;
  25552. exports.LayaGLRunner = LayaGLRunner;
  25553. exports.LayaGPU = LayaGPU;
  25554. exports.Loader = Loader;
  25555. exports.LoaderManager = LoaderManager;
  25556. exports.LocalStorage = LocalStorage;
  25557. exports.Log = Log;
  25558. exports.MathUtil = MathUtil;
  25559. exports.MatirxArray = MatirxArray;
  25560. exports.Matrix = Matrix;
  25561. exports.Mesh2D = Mesh2D;
  25562. exports.MeshParticle2D = MeshParticle2D;
  25563. exports.MeshQuadTexture = MeshQuadTexture;
  25564. exports.MeshTexture = MeshTexture;
  25565. exports.MeshVG = MeshVG;
  25566. exports.Mouse = Mouse;
  25567. exports.MouseManager = MouseManager;
  25568. exports.Node = Node;
  25569. exports.Path = Path;
  25570. exports.PerfData = PerfData;
  25571. exports.PerfHUD = PerfHUD;
  25572. exports.Point = Point;
  25573. exports.Pool = Pool;
  25574. exports.PoolCache = PoolCache;
  25575. exports.Prefab = Prefab;
  25576. exports.PrimitiveSV = PrimitiveSV;
  25577. exports.QuickTestTool = QuickTestTool;
  25578. exports.Rectangle = Rectangle;
  25579. exports.Render = Render;
  25580. exports.RenderInfo = RenderInfo;
  25581. exports.RenderSprite = RenderSprite;
  25582. exports.RenderState2D = RenderState2D;
  25583. exports.RenderTexture2D = RenderTexture2D;
  25584. exports.Resource = Resource;
  25585. exports.ResourceVersion = ResourceVersion;
  25586. exports.RestoreCmd = RestoreCmd;
  25587. exports.RotateCmd = RotateCmd;
  25588. exports.RunDriver = RunDriver;
  25589. exports.SaveBase = SaveBase;
  25590. exports.SaveClipRect = SaveClipRect;
  25591. exports.SaveCmd = SaveCmd;
  25592. exports.SaveMark = SaveMark;
  25593. exports.SaveTransform = SaveTransform;
  25594. exports.SaveTranslate = SaveTranslate;
  25595. exports.ScaleCmd = ScaleCmd;
  25596. exports.Scene = Scene;
  25597. exports.SceneLoader = SceneLoader;
  25598. exports.SceneUtils = SceneUtils;
  25599. exports.Script = Script;
  25600. exports.Shader = Shader;
  25601. exports.Shader2D = Shader2D;
  25602. exports.Shader2X = Shader2X;
  25603. exports.ShaderCompile = ShaderCompile;
  25604. exports.ShaderDefines2D = ShaderDefines2D;
  25605. exports.ShaderDefinesBase = ShaderDefinesBase;
  25606. exports.ShaderNode = ShaderNode;
  25607. exports.ShaderValue = ShaderValue;
  25608. exports.SkinMeshBuffer = SkinMeshBuffer;
  25609. exports.SkinSV = SkinSV;
  25610. exports.Socket = Socket;
  25611. exports.Sound = Sound;
  25612. exports.SoundChannel = SoundChannel;
  25613. exports.SoundManager = SoundManager;
  25614. exports.SoundNode = SoundNode;
  25615. exports.Sprite = Sprite;
  25616. exports.SpriteConst = SpriteConst;
  25617. exports.SpriteStyle = SpriteStyle;
  25618. exports.Stage = Stage;
  25619. exports.Stat = Stat;
  25620. exports.StatUI = StatUI;
  25621. exports.StringKey = StringKey;
  25622. exports.Submit = Submit;
  25623. exports.SubmitBase = SubmitBase;
  25624. exports.SubmitCMD = SubmitCMD;
  25625. exports.SubmitCanvas = SubmitCanvas;
  25626. exports.SubmitKey = SubmitKey;
  25627. exports.SubmitTarget = SubmitTarget;
  25628. exports.SubmitTexture = SubmitTexture;
  25629. exports.System = System;
  25630. exports.SystemUtils = SystemUtils;
  25631. exports.TTFLoader = TTFLoader;
  25632. exports.Text = Text;
  25633. exports.TextAtlas = TextAtlas;
  25634. exports.TextRender = TextRender;
  25635. exports.TextStyle = TextStyle;
  25636. exports.TextTexture = TextTexture;
  25637. exports.Texture = Texture;
  25638. exports.Texture2D = Texture2D;
  25639. exports.TextureSV = TextureSV;
  25640. exports.TimeLine = TimeLine;
  25641. exports.Timer = Timer;
  25642. exports.TouchManager = TouchManager;
  25643. exports.TransformCmd = TransformCmd;
  25644. exports.TranslateCmd = TranslateCmd;
  25645. exports.Tween = Tween;
  25646. exports.URL = URL;
  25647. exports.Utils = Utils;
  25648. exports.Value2D = Value2D;
  25649. exports.VectorGraphManager = VectorGraphManager;
  25650. exports.VertexArrayObject = VertexArrayObject;
  25651. exports.VertexBuffer2D = VertexBuffer2D;
  25652. exports.WeakObject = WeakObject;
  25653. exports.WebAudioSound = WebAudioSound;
  25654. exports.WebAudioSoundChannel = WebAudioSoundChannel;
  25655. exports.WebGL = WebGL;
  25656. exports.WebGLCacheAsNormalCanvas = WebGLCacheAsNormalCanvas;
  25657. exports.WebGLContext = WebGLContext;
  25658. exports.WebGLRTMgr = WebGLRTMgr;
  25659. exports.WordText = WordText;
  25660. exports.WorkerLoader = WorkerLoader;
  25661. exports.__init = __init;
  25662. exports._static = _static;
  25663. exports.alertGlobalError = alertGlobalError;
  25664. exports.enableDebugPanel = enableDebugPanel;
  25665. exports.init = init;
  25666. exports.isWXOpenDataContext = isWXOpenDataContext;
  25667. exports.isWXPosMsg = isWXPosMsg;
  25668. exports.version = version;
  25669. exports.static=_static;
  25670. return exports;
  25671. }({}));