laya.core.js 976 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647
  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 = true;
  14. Config.useRetinalCanvas = false;
  15. window.Config = Config;
  16. class ILaya {
  17. static regClass(c) {
  18. ILaya.__classMap[c.name] = c;
  19. }
  20. }
  21. ILaya.Laya = null;
  22. ILaya.Timer = null;
  23. ILaya.WorkerLoader = null;
  24. ILaya.Dragging = null;
  25. ILaya.GraphicsBounds = null;
  26. ILaya.Sprite = null;
  27. ILaya.TextRender = null;
  28. ILaya.TextAtlas = null;
  29. ILaya.timer = null;
  30. ILaya.systemTimer = null;
  31. ILaya.startTimer = null;
  32. ILaya.updateTimer = null;
  33. ILaya.lateTimer = null;
  34. ILaya.physicsTimer = null;
  35. ILaya.stage = null;
  36. ILaya.Loader = null;
  37. ILaya.loader = null;
  38. ILaya.TTFLoader = null;
  39. ILaya.SoundManager = null;
  40. ILaya.WebAudioSound = null;
  41. ILaya.AudioSound = null;
  42. ILaya.ShaderCompile = null;
  43. ILaya.ClassUtils = null;
  44. ILaya.SceneUtils = null;
  45. ILaya.Context = null;
  46. ILaya.Render = null;
  47. ILaya.MouseManager = null;
  48. ILaya.Text = null;
  49. ILaya.Browser = null;
  50. ILaya.WebGL = null;
  51. ILaya.Pool = null;
  52. ILaya.Utils = null;
  53. ILaya.Graphics = null;
  54. ILaya.Submit = null;
  55. ILaya.Stage = null;
  56. ILaya.Resource = null;
  57. ILaya.__classMap = {};
  58. class Pool {
  59. static getPoolBySign(sign) {
  60. return Pool._poolDic[sign] || (Pool._poolDic[sign] = []);
  61. }
  62. static clearBySign(sign) {
  63. if (Pool._poolDic[sign])
  64. Pool._poolDic[sign].length = 0;
  65. }
  66. static recover(sign, item) {
  67. if (item[Pool.POOLSIGN])
  68. return;
  69. item[Pool.POOLSIGN] = true;
  70. Pool.getPoolBySign(sign).push(item);
  71. }
  72. static recoverByClass(instance) {
  73. if (instance) {
  74. var className = instance["__className"] || instance.constructor._$gid;
  75. if (className)
  76. Pool.recover(className, instance);
  77. }
  78. }
  79. static _getClassSign(cla) {
  80. var className = cla["__className"] || cla["_$gid"];
  81. if (!className) {
  82. cla["_$gid"] = className = Pool._CLSID + "";
  83. Pool._CLSID++;
  84. }
  85. return className;
  86. }
  87. static createByClass(cls) {
  88. return Pool.getItemByClass(Pool._getClassSign(cls), cls);
  89. }
  90. static getItemByClass(sign, cls) {
  91. if (!Pool._poolDic[sign])
  92. return new cls();
  93. var pool = Pool.getPoolBySign(sign);
  94. if (pool.length) {
  95. var rst = pool.pop();
  96. rst[Pool.POOLSIGN] = false;
  97. }
  98. else {
  99. rst = new cls();
  100. }
  101. return rst;
  102. }
  103. static getItemByCreateFun(sign, createFun, caller = null) {
  104. var pool = Pool.getPoolBySign(sign);
  105. var rst = pool.length ? pool.pop() : createFun.call(caller);
  106. rst[Pool.POOLSIGN] = false;
  107. return rst;
  108. }
  109. static getItem(sign) {
  110. var pool = Pool.getPoolBySign(sign);
  111. var rst = pool.length ? pool.pop() : null;
  112. if (rst) {
  113. rst[Pool.POOLSIGN] = false;
  114. }
  115. return rst;
  116. }
  117. }
  118. Pool._CLSID = 0;
  119. Pool.POOLSIGN = "__InPool";
  120. Pool._poolDic = {};
  121. class AlphaCmd {
  122. static create(alpha) {
  123. var cmd = Pool.getItemByClass("AlphaCmd", AlphaCmd);
  124. cmd.alpha = alpha;
  125. return cmd;
  126. }
  127. recover() {
  128. Pool.recover("AlphaCmd", this);
  129. }
  130. run(context, gx, gy) {
  131. context.alpha(this.alpha);
  132. }
  133. get cmdID() {
  134. return AlphaCmd.ID;
  135. }
  136. }
  137. AlphaCmd.ID = "Alpha";
  138. class DrawCircleCmd {
  139. static create(x, y, radius, fillColor, lineColor, lineWidth, vid) {
  140. var cmd = Pool.getItemByClass("DrawCircleCmd", DrawCircleCmd);
  141. cmd.x = x;
  142. cmd.y = y;
  143. cmd.radius = radius;
  144. cmd.fillColor = fillColor;
  145. cmd.lineColor = lineColor;
  146. cmd.lineWidth = lineWidth;
  147. cmd.vid = vid;
  148. return cmd;
  149. }
  150. recover() {
  151. this.fillColor = null;
  152. this.lineColor = null;
  153. Pool.recover("DrawCircleCmd", this);
  154. }
  155. run(context, gx, gy) {
  156. context._drawCircle(this.x + gx, this.y + gy, this.radius, this.fillColor, this.lineColor, this.lineWidth, this.vid);
  157. }
  158. get cmdID() {
  159. return DrawCircleCmd.ID;
  160. }
  161. }
  162. DrawCircleCmd.ID = "DrawCircle";
  163. class DrawCurvesCmd {
  164. static create(x, y, points, lineColor, lineWidth) {
  165. var cmd = Pool.getItemByClass("DrawCurvesCmd", DrawCurvesCmd);
  166. cmd.x = x;
  167. cmd.y = y;
  168. cmd.points = points;
  169. cmd.lineColor = lineColor;
  170. cmd.lineWidth = lineWidth;
  171. return cmd;
  172. }
  173. recover() {
  174. this.points = null;
  175. this.lineColor = null;
  176. Pool.recover("DrawCurvesCmd", this);
  177. }
  178. run(context, gx, gy) {
  179. context.drawCurves(this.x + gx, this.y + gy, this.points, this.lineColor, this.lineWidth);
  180. }
  181. get cmdID() {
  182. return DrawCurvesCmd.ID;
  183. }
  184. }
  185. DrawCurvesCmd.ID = "DrawCurves";
  186. class DrawImageCmd {
  187. static create(texture, x, y, width, height) {
  188. var cmd = Pool.getItemByClass("DrawImageCmd", DrawImageCmd);
  189. cmd.texture = texture;
  190. texture._addReference();
  191. cmd.x = x;
  192. cmd.y = y;
  193. cmd.width = width;
  194. cmd.height = height;
  195. return cmd;
  196. }
  197. recover() {
  198. this.texture._removeReference();
  199. this.texture = null;
  200. Pool.recover("DrawImageCmd", this);
  201. }
  202. run(context, gx, gy) {
  203. context.drawTexture(this.texture, this.x + gx, this.y + gy, this.width, this.height);
  204. }
  205. get cmdID() {
  206. return DrawImageCmd.ID;
  207. }
  208. }
  209. DrawImageCmd.ID = "DrawImage";
  210. class DrawLineCmd {
  211. static create(fromX, fromY, toX, toY, lineColor, lineWidth, vid) {
  212. var cmd = Pool.getItemByClass("DrawLineCmd", DrawLineCmd);
  213. cmd.fromX = fromX;
  214. cmd.fromY = fromY;
  215. cmd.toX = toX;
  216. cmd.toY = toY;
  217. cmd.lineColor = lineColor;
  218. cmd.lineWidth = lineWidth;
  219. cmd.vid = vid;
  220. return cmd;
  221. }
  222. recover() {
  223. Pool.recover("DrawLineCmd", this);
  224. }
  225. run(context, gx, gy) {
  226. context._drawLine(gx, gy, this.fromX, this.fromY, this.toX, this.toY, this.lineColor, this.lineWidth, this.vid);
  227. }
  228. get cmdID() {
  229. return DrawLineCmd.ID;
  230. }
  231. }
  232. DrawLineCmd.ID = "DrawLine";
  233. class DrawLinesCmd {
  234. static create(x, y, points, lineColor, lineWidth, vid) {
  235. var cmd = Pool.getItemByClass("DrawLinesCmd", DrawLinesCmd);
  236. cmd.x = x;
  237. cmd.y = y;
  238. cmd.points = points;
  239. cmd.lineColor = lineColor;
  240. cmd.lineWidth = lineWidth;
  241. cmd.vid = vid;
  242. return cmd;
  243. }
  244. recover() {
  245. this.points = null;
  246. this.lineColor = null;
  247. Pool.recover("DrawLinesCmd", this);
  248. }
  249. run(context, gx, gy) {
  250. context._drawLines(this.x + gx, this.y + gy, this.points, this.lineColor, this.lineWidth, this.vid);
  251. }
  252. get cmdID() {
  253. return DrawLinesCmd.ID;
  254. }
  255. }
  256. DrawLinesCmd.ID = "DrawLines";
  257. class DrawPathCmd {
  258. static create(x, y, paths, brush, pen) {
  259. var cmd = Pool.getItemByClass("DrawPathCmd", DrawPathCmd);
  260. cmd.x = x;
  261. cmd.y = y;
  262. cmd.paths = paths;
  263. cmd.brush = brush;
  264. cmd.pen = pen;
  265. return cmd;
  266. }
  267. recover() {
  268. this.paths = null;
  269. this.brush = null;
  270. this.pen = null;
  271. Pool.recover("DrawPathCmd", this);
  272. }
  273. run(context, gx, gy) {
  274. context._drawPath(this.x + gx, this.y + gy, this.paths, this.brush, this.pen);
  275. }
  276. get cmdID() {
  277. return DrawPathCmd.ID;
  278. }
  279. }
  280. DrawPathCmd.ID = "DrawPath";
  281. class DrawPieCmd {
  282. static create(x, y, radius, startAngle, endAngle, fillColor, lineColor, lineWidth, vid) {
  283. var cmd = Pool.getItemByClass("DrawPieCmd", DrawPieCmd);
  284. cmd.x = x;
  285. cmd.y = y;
  286. cmd.radius = radius;
  287. cmd._startAngle = startAngle;
  288. cmd._endAngle = endAngle;
  289. cmd.fillColor = fillColor;
  290. cmd.lineColor = lineColor;
  291. cmd.lineWidth = lineWidth;
  292. cmd.vid = vid;
  293. return cmd;
  294. }
  295. recover() {
  296. this.fillColor = null;
  297. this.lineColor = null;
  298. Pool.recover("DrawPieCmd", this);
  299. }
  300. run(context, gx, gy) {
  301. context._drawPie(this.x + gx, this.y + gy, this.radius, this._startAngle, this._endAngle, this.fillColor, this.lineColor, this.lineWidth, this.vid);
  302. }
  303. get cmdID() {
  304. return DrawPieCmd.ID;
  305. }
  306. get startAngle() {
  307. return this._startAngle * 180 / Math.PI;
  308. }
  309. set startAngle(value) {
  310. this._startAngle = value * Math.PI / 180;
  311. }
  312. get endAngle() {
  313. return this._endAngle * 180 / Math.PI;
  314. }
  315. set endAngle(value) {
  316. this._endAngle = value * Math.PI / 180;
  317. }
  318. }
  319. DrawPieCmd.ID = "DrawPie";
  320. class DrawPolyCmd {
  321. static create(x, y, points, fillColor, lineColor, lineWidth, isConvexPolygon, vid) {
  322. var cmd = Pool.getItemByClass("DrawPolyCmd", DrawPolyCmd);
  323. cmd.x = x;
  324. cmd.y = y;
  325. cmd.points = points;
  326. cmd.fillColor = fillColor;
  327. cmd.lineColor = lineColor;
  328. cmd.lineWidth = lineWidth;
  329. cmd.isConvexPolygon = isConvexPolygon;
  330. cmd.vid = vid;
  331. return cmd;
  332. }
  333. recover() {
  334. this.points = null;
  335. this.fillColor = null;
  336. this.lineColor = null;
  337. Pool.recover("DrawPolyCmd", this);
  338. }
  339. run(context, gx, gy) {
  340. context._drawPoly(this.x + gx, this.y + gy, this.points, this.fillColor, this.lineColor, this.lineWidth, this.isConvexPolygon, this.vid);
  341. }
  342. get cmdID() {
  343. return DrawPolyCmd.ID;
  344. }
  345. }
  346. DrawPolyCmd.ID = "DrawPoly";
  347. class DrawRectCmd {
  348. static create(x, y, width, height, fillColor, lineColor, lineWidth) {
  349. var cmd = Pool.getItemByClass("DrawRectCmd", DrawRectCmd);
  350. cmd.x = x;
  351. cmd.y = y;
  352. cmd.width = width;
  353. cmd.height = height;
  354. cmd.fillColor = fillColor;
  355. cmd.lineColor = lineColor;
  356. cmd.lineWidth = lineWidth;
  357. return cmd;
  358. }
  359. recover() {
  360. this.fillColor = null;
  361. this.lineColor = null;
  362. Pool.recover("DrawRectCmd", this);
  363. }
  364. run(context, gx, gy) {
  365. context.drawRect(this.x + gx, this.y + gy, this.width, this.height, this.fillColor, this.lineColor, this.lineWidth);
  366. }
  367. get cmdID() {
  368. return DrawRectCmd.ID;
  369. }
  370. }
  371. DrawRectCmd.ID = "DrawRect";
  372. class Matrix {
  373. constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0, nums = 0) {
  374. this._bTransform = false;
  375. if (Matrix._createFun != null) {
  376. return Matrix._createFun(a, b, c, d, tx, ty, nums);
  377. }
  378. this.a = a;
  379. this.b = b;
  380. this.c = c;
  381. this.d = d;
  382. this.tx = tx;
  383. this.ty = ty;
  384. this._checkTransform();
  385. }
  386. identity() {
  387. this.a = this.d = 1;
  388. this.b = this.tx = this.ty = this.c = 0;
  389. this._bTransform = false;
  390. return this;
  391. }
  392. _checkTransform() {
  393. return this._bTransform = (this.a !== 1 || this.b !== 0 || this.c !== 0 || this.d !== 1);
  394. }
  395. setTranslate(x, y) {
  396. this.tx = x;
  397. this.ty = y;
  398. return this;
  399. }
  400. translate(x, y) {
  401. this.tx += x;
  402. this.ty += y;
  403. return this;
  404. }
  405. scale(x, y) {
  406. this.a *= x;
  407. this.d *= y;
  408. this.c *= x;
  409. this.b *= y;
  410. this.tx *= x;
  411. this.ty *= y;
  412. this._bTransform = true;
  413. return this;
  414. }
  415. rotate(angle) {
  416. var cos = Math.cos(angle);
  417. var sin = Math.sin(angle);
  418. var a1 = this.a;
  419. var c1 = this.c;
  420. var tx1 = this.tx;
  421. this.a = a1 * cos - this.b * sin;
  422. this.b = a1 * sin + this.b * cos;
  423. this.c = c1 * cos - this.d * sin;
  424. this.d = c1 * sin + this.d * cos;
  425. this.tx = tx1 * cos - this.ty * sin;
  426. this.ty = tx1 * sin + this.ty * cos;
  427. this._bTransform = true;
  428. return this;
  429. }
  430. skew(x, y) {
  431. var tanX = Math.tan(x);
  432. var tanY = Math.tan(y);
  433. var a1 = this.a;
  434. var b1 = this.b;
  435. this.a += tanY * this.c;
  436. this.b += tanY * this.d;
  437. this.c += tanX * a1;
  438. this.d += tanX * b1;
  439. return this;
  440. }
  441. invertTransformPoint(out) {
  442. var a1 = this.a;
  443. var b1 = this.b;
  444. var c1 = this.c;
  445. var d1 = this.d;
  446. var tx1 = this.tx;
  447. var n = a1 * d1 - b1 * c1;
  448. var a2 = d1 / n;
  449. var b2 = -b1 / n;
  450. var c2 = -c1 / n;
  451. var d2 = a1 / n;
  452. var tx2 = (c1 * this.ty - d1 * tx1) / n;
  453. var ty2 = -(a1 * this.ty - b1 * tx1) / n;
  454. return out.setTo(a2 * out.x + c2 * out.y + tx2, b2 * out.x + d2 * out.y + ty2);
  455. }
  456. transformPoint(out) {
  457. return out.setTo(this.a * out.x + this.c * out.y + this.tx, this.b * out.x + this.d * out.y + this.ty);
  458. }
  459. transformPointN(out) {
  460. return out.setTo(this.a * out.x + this.c * out.y, this.b * out.x + this.d * out.y);
  461. }
  462. getScaleX() {
  463. return this.b === 0 ? this.a : Math.sqrt(this.a * this.a + this.b * this.b);
  464. }
  465. getScaleY() {
  466. return this.c === 0 ? this.d : Math.sqrt(this.c * this.c + this.d * this.d);
  467. }
  468. invert() {
  469. var a1 = this.a;
  470. var b1 = this.b;
  471. var c1 = this.c;
  472. var d1 = this.d;
  473. var tx1 = this.tx;
  474. var n = a1 * d1 - b1 * c1;
  475. this.a = d1 / n;
  476. this.b = -b1 / n;
  477. this.c = -c1 / n;
  478. this.d = a1 / n;
  479. this.tx = (c1 * this.ty - d1 * tx1) / n;
  480. this.ty = -(a1 * this.ty - b1 * tx1) / n;
  481. return this;
  482. }
  483. setTo(a, b, c, d, tx, ty) {
  484. this.a = a, this.b = b, this.c = c, this.d = d, this.tx = tx, this.ty = ty;
  485. return this;
  486. }
  487. concat(matrix) {
  488. var a = this.a;
  489. var c = this.c;
  490. var tx = this.tx;
  491. this.a = a * matrix.a + this.b * matrix.c;
  492. this.b = a * matrix.b + this.b * matrix.d;
  493. this.c = c * matrix.a + this.d * matrix.c;
  494. this.d = c * matrix.b + this.d * matrix.d;
  495. this.tx = tx * matrix.a + this.ty * matrix.c + matrix.tx;
  496. this.ty = tx * matrix.b + this.ty * matrix.d + matrix.ty;
  497. return this;
  498. }
  499. static mul(m1, m2, out) {
  500. var aa = m1.a, ab = m1.b, ac = m1.c, ad = m1.d, atx = m1.tx, aty = m1.ty;
  501. var ba = m2.a, bb = m2.b, bc = m2.c, bd = m2.d, btx = m2.tx, bty = m2.ty;
  502. if (bb !== 0 || bc !== 0) {
  503. out.a = aa * ba + ab * bc;
  504. out.b = aa * bb + ab * bd;
  505. out.c = ac * ba + ad * bc;
  506. out.d = ac * bb + ad * bd;
  507. out.tx = ba * atx + bc * aty + btx;
  508. out.ty = bb * atx + bd * aty + bty;
  509. }
  510. else {
  511. out.a = aa * ba;
  512. out.b = ab * bd;
  513. out.c = ac * ba;
  514. out.d = ad * bd;
  515. out.tx = ba * atx + btx;
  516. out.ty = bd * aty + bty;
  517. }
  518. return out;
  519. }
  520. static mul16(m1, m2, out) {
  521. var aa = m1.a, ab = m1.b, ac = m1.c, ad = m1.d, atx = m1.tx, aty = m1.ty;
  522. var ba = m2.a, bb = m2.b, bc = m2.c, bd = m2.d, btx = m2.tx, bty = m2.ty;
  523. if (bb !== 0 || bc !== 0) {
  524. out[0] = aa * ba + ab * bc;
  525. out[1] = aa * bb + ab * bd;
  526. out[4] = ac * ba + ad * bc;
  527. out[5] = ac * bb + ad * bd;
  528. out[12] = ba * atx + bc * aty + btx;
  529. out[13] = bb * atx + bd * aty + bty;
  530. }
  531. else {
  532. out[0] = aa * ba;
  533. out[1] = ab * bd;
  534. out[4] = ac * ba;
  535. out[5] = ad * bd;
  536. out[12] = ba * atx + btx;
  537. out[13] = bd * aty + bty;
  538. }
  539. return out;
  540. }
  541. scaleEx(x, y) {
  542. var ba = this.a, bb = this.b, bc = this.c, bd = this.d;
  543. if (bb !== 0 || bc !== 0) {
  544. this.a = x * ba;
  545. this.b = x * bb;
  546. this.c = y * bc;
  547. this.d = y * bd;
  548. }
  549. else {
  550. this.a = x * ba;
  551. this.b = 0 * bd;
  552. this.c = 0 * ba;
  553. this.d = y * bd;
  554. }
  555. this._bTransform = true;
  556. }
  557. rotateEx(angle) {
  558. var cos = Math.cos(angle);
  559. var sin = Math.sin(angle);
  560. var ba = this.a, bb = this.b, bc = this.c, bd = this.d;
  561. if (bb !== 0 || bc !== 0) {
  562. this.a = cos * ba + sin * bc;
  563. this.b = cos * bb + sin * bd;
  564. this.c = -sin * ba + cos * bc;
  565. this.d = -sin * bb + cos * bd;
  566. }
  567. else {
  568. this.a = cos * ba;
  569. this.b = sin * bd;
  570. this.c = -sin * ba;
  571. this.d = cos * bd;
  572. }
  573. this._bTransform = true;
  574. }
  575. clone() {
  576. var dec = Matrix.create();
  577. dec.a = this.a;
  578. dec.b = this.b;
  579. dec.c = this.c;
  580. dec.d = this.d;
  581. dec.tx = this.tx;
  582. dec.ty = this.ty;
  583. dec._bTransform = this._bTransform;
  584. return dec;
  585. }
  586. copyTo(dec) {
  587. dec.a = this.a;
  588. dec.b = this.b;
  589. dec.c = this.c;
  590. dec.d = this.d;
  591. dec.tx = this.tx;
  592. dec.ty = this.ty;
  593. dec._bTransform = this._bTransform;
  594. return dec;
  595. }
  596. toString() {
  597. return this.a + "," + this.b + "," + this.c + "," + this.d + "," + this.tx + "," + this.ty;
  598. }
  599. destroy() {
  600. this.recover();
  601. }
  602. recover() {
  603. Pool.recover("Matrix", this.identity());
  604. }
  605. static create() {
  606. return Pool.getItemByClass("Matrix", Matrix);
  607. }
  608. }
  609. Matrix.EMPTY = new Matrix();
  610. Matrix.TEMP = new Matrix();
  611. Matrix._createFun = null;
  612. class Point {
  613. constructor(x = 0, y = 0) {
  614. this.x = x;
  615. this.y = y;
  616. }
  617. static create() {
  618. return Pool.getItemByClass("Point", Point);
  619. }
  620. setTo(x, y) {
  621. this.x = x;
  622. this.y = y;
  623. return this;
  624. }
  625. reset() {
  626. this.x = this.y = 0;
  627. return this;
  628. }
  629. recover() {
  630. Pool.recover("Point", this.reset());
  631. }
  632. distance(x, y) {
  633. return Math.sqrt((this.x - x) * (this.x - x) + (this.y - y) * (this.y - y));
  634. }
  635. toString() {
  636. return this.x + "," + this.y;
  637. }
  638. normalize() {
  639. var d = Math.sqrt(this.x * this.x + this.y * this.y);
  640. if (d > 0) {
  641. var id = 1.0 / d;
  642. this.x *= id;
  643. this.y *= id;
  644. }
  645. }
  646. copy(point) {
  647. return this.setTo(point.x, point.y);
  648. }
  649. }
  650. Point.TEMP = new Point();
  651. Point.EMPTY = new Point();
  652. class Rectangle {
  653. constructor(x = 0, y = 0, width = 0, height = 0) {
  654. this.x = x;
  655. this.y = y;
  656. this.width = width;
  657. this.height = height;
  658. }
  659. get right() {
  660. return this.x + this.width;
  661. }
  662. get bottom() {
  663. return this.y + this.height;
  664. }
  665. setTo(x, y, width, height) {
  666. this.x = x;
  667. this.y = y;
  668. this.width = width;
  669. this.height = height;
  670. return this;
  671. }
  672. reset() {
  673. this.x = this.y = this.width = this.height = 0;
  674. return this;
  675. }
  676. recover() {
  677. if (this == Rectangle.TEMP || this == Rectangle.EMPTY) {
  678. console.log("recover Temp or Empty:", this);
  679. return;
  680. }
  681. Pool.recover("Rectangle", this.reset());
  682. }
  683. static create() {
  684. return Pool.getItemByClass("Rectangle", Rectangle);
  685. }
  686. copyFrom(source) {
  687. this.x = source.x;
  688. this.y = source.y;
  689. this.width = source.width;
  690. this.height = source.height;
  691. return this;
  692. }
  693. contains(x, y) {
  694. if (this.width <= 0 || this.height <= 0)
  695. return false;
  696. if (x >= this.x && x < this.right) {
  697. if (y >= this.y && y < this.bottom) {
  698. return true;
  699. }
  700. }
  701. return false;
  702. }
  703. intersects(rect) {
  704. 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);
  705. }
  706. intersection(rect, out = null) {
  707. if (!this.intersects(rect))
  708. return null;
  709. out || (out = new Rectangle());
  710. out.x = Math.max(this.x, rect.x);
  711. out.y = Math.max(this.y, rect.y);
  712. out.width = Math.min(this.right, rect.right) - out.x;
  713. out.height = Math.min(this.bottom, rect.bottom) - out.y;
  714. return out;
  715. }
  716. union(source, out = null) {
  717. out || (out = new Rectangle());
  718. this.clone(out);
  719. if (source.width <= 0 || source.height <= 0)
  720. return out;
  721. out.addPoint(source.x, source.y);
  722. out.addPoint(source.right, source.bottom);
  723. return this;
  724. }
  725. clone(out = null) {
  726. out || (out = new Rectangle());
  727. out.x = this.x;
  728. out.y = this.y;
  729. out.width = this.width;
  730. out.height = this.height;
  731. return out;
  732. }
  733. toString() {
  734. return this.x + "," + this.y + "," + this.width + "," + this.height;
  735. }
  736. equals(rect) {
  737. if (!rect || rect.x !== this.x || rect.y !== this.y || rect.width !== this.width || rect.height !== this.height)
  738. return false;
  739. return true;
  740. }
  741. addPoint(x, y) {
  742. this.x > x && (this.width += this.x - x, this.x = x);
  743. this.y > y && (this.height += this.y - y, this.y = y);
  744. if (this.width < x - this.x)
  745. this.width = x - this.x;
  746. if (this.height < y - this.y)
  747. this.height = y - this.y;
  748. return this;
  749. }
  750. _getBoundPoints() {
  751. var rst = Rectangle._temB;
  752. rst.length = 0;
  753. if (this.width == 0 || this.height == 0)
  754. return rst;
  755. 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);
  756. return rst;
  757. }
  758. static _getBoundPointS(x, y, width, height) {
  759. var rst = Rectangle._temA;
  760. rst.length = 0;
  761. if (width == 0 || height == 0)
  762. return rst;
  763. rst.push(x, y, x + width, y, x, y + height, x + width, y + height);
  764. return rst;
  765. }
  766. static _getWrapRec(pointList, rst = null) {
  767. if (!pointList || pointList.length < 1)
  768. return rst ? rst.setTo(0, 0, 0, 0) : Rectangle.TEMP.setTo(0, 0, 0, 0);
  769. rst = rst ? rst : Rectangle.create();
  770. var i, len = pointList.length, minX, maxX, minY, maxY, tPoint = Point.TEMP;
  771. minX = minY = 99999;
  772. maxX = maxY = -minX;
  773. for (i = 0; i < len; i += 2) {
  774. tPoint.x = pointList[i];
  775. tPoint.y = pointList[i + 1];
  776. minX = minX < tPoint.x ? minX : tPoint.x;
  777. minY = minY < tPoint.y ? minY : tPoint.y;
  778. maxX = maxX > tPoint.x ? maxX : tPoint.x;
  779. maxY = maxY > tPoint.y ? maxY : tPoint.y;
  780. }
  781. return rst.setTo(minX, minY, maxX - minX, maxY - minY);
  782. }
  783. isEmpty() {
  784. if (this.width <= 0 || this.height <= 0)
  785. return true;
  786. return false;
  787. }
  788. }
  789. Rectangle.EMPTY = new Rectangle();
  790. Rectangle.TEMP = new Rectangle();
  791. Rectangle._temB = [];
  792. Rectangle._temA = [];
  793. class LayaGL {
  794. }
  795. LayaGL.ARRAY_BUFFER_TYPE_DATA = 0;
  796. LayaGL.ARRAY_BUFFER_TYPE_CMD = 1;
  797. LayaGL.ARRAY_BUFFER_REF_REFERENCE = 0;
  798. LayaGL.ARRAY_BUFFER_REF_COPY = 1;
  799. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID = 0;
  800. LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA = 1;
  801. class Handler {
  802. constructor(caller = null, method = null, args = null, once = false) {
  803. this.once = false;
  804. this._id = 0;
  805. this.setTo(caller, method, args, once);
  806. }
  807. setTo(caller, method, args, once) {
  808. this._id = Handler._gid++;
  809. this.caller = caller;
  810. this.method = method;
  811. this.args = args;
  812. this.once = once;
  813. return this;
  814. }
  815. run() {
  816. if (this.method == null)
  817. return null;
  818. var id = this._id;
  819. var result = this.method.apply(this.caller, this.args);
  820. this._id === id && this.once && this.recover();
  821. return result;
  822. }
  823. runWith(data) {
  824. if (this.method == null)
  825. return null;
  826. var id = this._id;
  827. if (data == null)
  828. var result = this.method.apply(this.caller, this.args);
  829. else if (!this.args && !data.unshift)
  830. result = this.method.call(this.caller, data);
  831. else if (this.args)
  832. result = this.method.apply(this.caller, this.args.concat(data));
  833. else
  834. result = this.method.apply(this.caller, data);
  835. this._id === id && this.once && this.recover();
  836. return result;
  837. }
  838. clear() {
  839. this.caller = null;
  840. this.method = null;
  841. this.args = null;
  842. return this;
  843. }
  844. recover() {
  845. if (this._id > 0) {
  846. this._id = 0;
  847. Handler._pool.push(this.clear());
  848. }
  849. }
  850. static create(caller, method, args = null, once = true) {
  851. if (Handler._pool.length)
  852. return Handler._pool.pop().setTo(caller, method, args, once);
  853. return new Handler(caller, method, args, once);
  854. }
  855. }
  856. Handler._pool = [];
  857. Handler._gid = 1;
  858. class EventDispatcher {
  859. hasListener(type) {
  860. var listener = this._events && this._events[type];
  861. return !!listener;
  862. }
  863. event(type, data = null) {
  864. if (!this._events || !this._events[type])
  865. return false;
  866. var listeners = this._events[type];
  867. if (listeners.run) {
  868. if (listeners.once)
  869. delete this._events[type];
  870. data != null ? listeners.runWith(data) : listeners.run();
  871. }
  872. else {
  873. for (var i = 0, n = listeners.length; i < n; i++) {
  874. var listener = listeners[i];
  875. if (listener) {
  876. (data != null) ? listener.runWith(data) : listener.run();
  877. }
  878. if (!listener || listener.once) {
  879. listeners.splice(i, 1);
  880. i--;
  881. n--;
  882. }
  883. }
  884. if (listeners.length === 0 && this._events)
  885. delete this._events[type];
  886. }
  887. return true;
  888. }
  889. on(type, caller, listener, args = null) {
  890. return this._createListener(type, caller, listener, args, false);
  891. }
  892. once(type, caller, listener, args = null) {
  893. return this._createListener(type, caller, listener, args, true);
  894. }
  895. _createListener(type, caller, listener, args, once, offBefore = true) {
  896. offBefore && this.off(type, caller, listener, once);
  897. var handler = EventHandler.create(caller || this, listener, args, once);
  898. this._events || (this._events = {});
  899. var events = this._events;
  900. if (!events[type])
  901. events[type] = handler;
  902. else {
  903. if (!events[type].run)
  904. events[type].push(handler);
  905. else
  906. events[type] = [events[type], handler];
  907. }
  908. return this;
  909. }
  910. off(type, caller, listener, onceOnly = false) {
  911. if (!this._events || !this._events[type])
  912. return this;
  913. var listeners = this._events[type];
  914. if (listeners != null) {
  915. if (listeners.run) {
  916. if ((!caller || listeners.caller === caller) && (listener == null || listeners.method === listener) && (!onceOnly || listeners.once)) {
  917. delete this._events[type];
  918. listeners.recover();
  919. }
  920. }
  921. else {
  922. var count = 0;
  923. for (var i = 0, n = listeners.length; i < n; i++) {
  924. var item = listeners[i];
  925. if (!item) {
  926. count++;
  927. continue;
  928. }
  929. if (item && (!caller || item.caller === caller) && (listener == null || item.method === listener) && (!onceOnly || item.once)) {
  930. count++;
  931. listeners[i] = null;
  932. item.recover();
  933. }
  934. }
  935. if (count === n)
  936. delete this._events[type];
  937. }
  938. }
  939. return this;
  940. }
  941. offAll(type = null) {
  942. var events = this._events;
  943. if (!events)
  944. return this;
  945. if (type) {
  946. this._recoverHandlers(events[type]);
  947. delete events[type];
  948. }
  949. else {
  950. for (var name in events) {
  951. this._recoverHandlers(events[name]);
  952. }
  953. this._events = null;
  954. }
  955. return this;
  956. }
  957. offAllCaller(caller) {
  958. if (caller && this._events) {
  959. for (var name in this._events) {
  960. this.off(name, caller, null);
  961. }
  962. }
  963. return this;
  964. }
  965. _recoverHandlers(arr) {
  966. if (!arr)
  967. return;
  968. if (arr.run) {
  969. arr.recover();
  970. }
  971. else {
  972. for (var i = arr.length - 1; i > -1; i--) {
  973. if (arr[i]) {
  974. arr[i].recover();
  975. arr[i] = null;
  976. }
  977. }
  978. }
  979. }
  980. isMouseEvent(type) {
  981. return EventDispatcher.MOUSE_EVENTS[type] || false;
  982. }
  983. }
  984. EventDispatcher.MOUSE_EVENTS = { "rightmousedown": true, "rightmouseup": true, "rightclick": true, "mousedown": true, "mouseup": true, "mousemove": true, "mouseover": true, "mouseout": true, "click": true, "doubleclick": true };
  985. class EventHandler extends Handler {
  986. constructor(caller, method, args, once) {
  987. super(caller, method, args, once);
  988. }
  989. recover() {
  990. if (this._id > 0) {
  991. this._id = 0;
  992. EventHandler._pool.push(this.clear());
  993. }
  994. }
  995. static create(caller, method, args = null, once = true) {
  996. if (EventHandler._pool.length)
  997. return EventHandler._pool.pop().setTo(caller, method, args, once);
  998. return new EventHandler(caller, method, args, once);
  999. }
  1000. }
  1001. EventHandler._pool = [];
  1002. class URL {
  1003. constructor(url) {
  1004. this._url = URL.formatURL(url);
  1005. this._path = URL.getPath(url);
  1006. }
  1007. get url() {
  1008. return this._url;
  1009. }
  1010. get path() {
  1011. return this._path;
  1012. }
  1013. static set basePath(value) {
  1014. URL._basePath = ILaya.Laya._getUrlPath();
  1015. URL._basePath = URL.formatURL(value);
  1016. }
  1017. static get basePath() {
  1018. return URL._basePath;
  1019. }
  1020. static formatURL(url) {
  1021. if (!url)
  1022. return "null path";
  1023. if (url.indexOf(":") > 0)
  1024. return url;
  1025. if (URL.customFormat != null)
  1026. url = URL.customFormat(url);
  1027. if (url.indexOf(":") > 0)
  1028. return url;
  1029. var char1 = url.charAt(0);
  1030. if (char1 === ".") {
  1031. return URL._formatRelativePath(URL._basePath + url);
  1032. }
  1033. else if (char1 === '~') {
  1034. return URL.rootPath + url.substring(1);
  1035. }
  1036. else if (char1 === "d") {
  1037. if (url.indexOf("data:image") === 0)
  1038. return url;
  1039. }
  1040. else if (char1 === "/") {
  1041. return url;
  1042. }
  1043. return URL._basePath + url;
  1044. }
  1045. static _formatRelativePath(value) {
  1046. var parts = value.split("/");
  1047. for (var i = 0, len = parts.length; i < len; i++) {
  1048. if (parts[i] == '..') {
  1049. parts.splice(i - 1, 2);
  1050. i -= 2;
  1051. }
  1052. }
  1053. return parts.join('/');
  1054. }
  1055. static getPath(url) {
  1056. var ofs = url.lastIndexOf('/');
  1057. return ofs > 0 ? url.substr(0, ofs + 1) : "";
  1058. }
  1059. static getFileName(url) {
  1060. var ofs = url.lastIndexOf('/');
  1061. return ofs > 0 ? url.substr(ofs + 1) : url;
  1062. }
  1063. static getAdptedFilePath(url) {
  1064. if (!URL.exportSceneToJson || !url)
  1065. return url;
  1066. var i, len;
  1067. len = URL._adpteTypeList.length;
  1068. var tArr;
  1069. for (i = 0; i < len; i++) {
  1070. tArr = URL._adpteTypeList[i];
  1071. url = url.replace(tArr[0], tArr[1]);
  1072. }
  1073. return url;
  1074. }
  1075. }
  1076. URL.version = {};
  1077. URL.exportSceneToJson = false;
  1078. URL._basePath = "";
  1079. URL.rootPath = "";
  1080. URL.customFormat = function (url) {
  1081. var newUrl = URL.version[url];
  1082. if (!window.conch && newUrl)
  1083. url += "?v=" + newUrl;
  1084. return url;
  1085. };
  1086. URL._adpteTypeList = [[".scene3d", ".json"], [".scene", ".json"], [".taa", ".json"], [".prefab", ".json"]];
  1087. class Resource extends EventDispatcher {
  1088. constructor() {
  1089. super();
  1090. this._id = 0;
  1091. this._url = null;
  1092. this._cpuMemory = 0;
  1093. this._gpuMemory = 0;
  1094. this._destroyed = false;
  1095. this._referenceCount = 0;
  1096. this.lock = false;
  1097. this.name = null;
  1098. this._id = ++Resource._uniqueIDCounter;
  1099. this._destroyed = false;
  1100. this._referenceCount = 0;
  1101. Resource._idResourcesMap[this.id] = this;
  1102. this.lock = false;
  1103. }
  1104. static get cpuMemory() {
  1105. return Resource._cpuMemory;
  1106. }
  1107. static get gpuMemory() {
  1108. return Resource._gpuMemory;
  1109. }
  1110. static _addCPUMemory(size) {
  1111. Resource._cpuMemory += size;
  1112. }
  1113. static _addGPUMemory(size) {
  1114. Resource._gpuMemory += size;
  1115. }
  1116. static _addMemory(cpuSize, gpuSize) {
  1117. Resource._cpuMemory += cpuSize;
  1118. Resource._gpuMemory += gpuSize;
  1119. }
  1120. static getResourceByID(id) {
  1121. return Resource._idResourcesMap[id];
  1122. }
  1123. static getResourceByURL(url, index = 0) {
  1124. return Resource._urlResourcesMap[url][index];
  1125. }
  1126. static destroyUnusedResources() {
  1127. for (var k in Resource._idResourcesMap) {
  1128. var res = Resource._idResourcesMap[k];
  1129. if (!res.lock && res._referenceCount === 0)
  1130. res.destroy();
  1131. }
  1132. }
  1133. get id() {
  1134. return this._id;
  1135. }
  1136. get url() {
  1137. return this._url;
  1138. }
  1139. get cpuMemory() {
  1140. return this._cpuMemory;
  1141. }
  1142. get gpuMemory() {
  1143. return this._gpuMemory;
  1144. }
  1145. get destroyed() {
  1146. return this._destroyed;
  1147. }
  1148. get referenceCount() {
  1149. return this._referenceCount;
  1150. }
  1151. _setCPUMemory(value) {
  1152. var offsetValue = value - this._cpuMemory;
  1153. this._cpuMemory = value;
  1154. Resource._addCPUMemory(offsetValue);
  1155. }
  1156. _setGPUMemory(value) {
  1157. var offsetValue = value - this._gpuMemory;
  1158. this._gpuMemory = value;
  1159. Resource._addGPUMemory(offsetValue);
  1160. }
  1161. _setCreateURL(url) {
  1162. url = URL.formatURL(url);
  1163. if (this._url !== url) {
  1164. var resList;
  1165. if (this._url) {
  1166. resList = Resource._urlResourcesMap[this._url];
  1167. resList.splice(resList.indexOf(this), 1);
  1168. (resList.length === 0) && (delete Resource._urlResourcesMap[this._url]);
  1169. }
  1170. if (url) {
  1171. resList = Resource._urlResourcesMap[url];
  1172. (resList) || (Resource._urlResourcesMap[url] = resList = []);
  1173. resList.push(this);
  1174. }
  1175. this._url = url;
  1176. }
  1177. }
  1178. _addReference(count = 1) {
  1179. this._referenceCount += count;
  1180. }
  1181. _removeReference(count = 1) {
  1182. this._referenceCount -= count;
  1183. }
  1184. _clearReference() {
  1185. this._referenceCount = 0;
  1186. }
  1187. _recoverResource() {
  1188. }
  1189. _disposeResource() {
  1190. }
  1191. _activeResource() {
  1192. }
  1193. destroy() {
  1194. if (this._destroyed)
  1195. return;
  1196. this._destroyed = true;
  1197. this.lock = false;
  1198. this._disposeResource();
  1199. delete Resource._idResourcesMap[this.id];
  1200. var resList;
  1201. if (this._url) {
  1202. resList = Resource._urlResourcesMap[this._url];
  1203. if (resList) {
  1204. resList.splice(resList.indexOf(this), 1);
  1205. (resList.length === 0) && (delete Resource._urlResourcesMap[this._url]);
  1206. }
  1207. var resou = ILaya.Loader.getRes(this._url);
  1208. (resou == this) && (delete ILaya.Loader.loadedMap[this._url]);
  1209. }
  1210. }
  1211. }
  1212. Resource._uniqueIDCounter = 0;
  1213. Resource._idResourcesMap = {};
  1214. Resource._urlResourcesMap = {};
  1215. Resource._cpuMemory = 0;
  1216. Resource._gpuMemory = 0;
  1217. class Bitmap extends Resource {
  1218. get width() {
  1219. return this._width;
  1220. }
  1221. set width(width) {
  1222. this._width = width;
  1223. }
  1224. get height() {
  1225. return this._height;
  1226. }
  1227. set height(height) {
  1228. this._height = height;
  1229. }
  1230. constructor() {
  1231. super();
  1232. this._width = -1;
  1233. this._height = -1;
  1234. }
  1235. _getSource() {
  1236. throw "Bitmap: must override it.";
  1237. }
  1238. }
  1239. class WebGLContext {
  1240. static __init__() {
  1241. var gl = LayaGL.instance;
  1242. WebGLContext._depthFunc = gl.LESS;
  1243. WebGLContext._sFactor = gl.ONE;
  1244. WebGLContext._dFactor = gl.ZERO;
  1245. WebGLContext._srcAlpha = gl.ONE;
  1246. WebGLContext._dstAlpha = gl.ZERO;
  1247. WebGLContext._activedTextureID = gl.TEXTURE0;
  1248. WebGLContext._glTextureIDs = [gl.TEXTURE0, gl.TEXTURE1, gl.TEXTURE2, gl.TEXTURE3, gl.TEXTURE4, gl.TEXTURE5, gl.TEXTURE6, gl.TEXTURE7];
  1249. }
  1250. static useProgram(gl, program) {
  1251. if (WebGLContext._useProgram === program)
  1252. return false;
  1253. gl.useProgram(program);
  1254. WebGLContext._useProgram = program;
  1255. return true;
  1256. }
  1257. static setDepthTest(gl, value) {
  1258. value !== WebGLContext._depthTest && (WebGLContext._depthTest = value, value ? gl.enable(gl.DEPTH_TEST) : gl.disable(gl.DEPTH_TEST));
  1259. }
  1260. static setDepthMask(gl, value) {
  1261. value !== WebGLContext._depthMask && (WebGLContext._depthMask = value, gl.depthMask(value));
  1262. }
  1263. static setDepthFunc(gl, value) {
  1264. value !== WebGLContext._depthFunc && (WebGLContext._depthFunc = value, gl.depthFunc(value));
  1265. }
  1266. static setBlend(gl, value) {
  1267. value !== WebGLContext._blend && (WebGLContext._blend = value, value ? gl.enable(gl.BLEND) : gl.disable(gl.BLEND));
  1268. }
  1269. static setBlendFunc(gl, sFactor, dFactor) {
  1270. (sFactor !== WebGLContext._sFactor || dFactor !== WebGLContext._dFactor) && (WebGLContext._sFactor = WebGLContext._srcAlpha = sFactor, WebGLContext._dFactor = WebGLContext._dstAlpha = dFactor, gl.blendFunc(sFactor, dFactor));
  1271. }
  1272. static setBlendFuncSeperate(gl, srcRGB, dstRGB, srcAlpha, dstAlpha) {
  1273. if (srcRGB !== WebGLContext._sFactor || dstRGB !== WebGLContext._dFactor || srcAlpha !== WebGLContext._srcAlpha || dstAlpha !== WebGLContext._dstAlpha) {
  1274. WebGLContext._sFactor = srcRGB;
  1275. WebGLContext._dFactor = dstRGB;
  1276. WebGLContext._srcAlpha = srcAlpha;
  1277. WebGLContext._dstAlpha = dstAlpha;
  1278. gl.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
  1279. }
  1280. }
  1281. static setCullFace(gl, value) {
  1282. value !== WebGLContext._cullFace && (WebGLContext._cullFace = value, value ? gl.enable(gl.CULL_FACE) : gl.disable(gl.CULL_FACE));
  1283. }
  1284. static setFrontFace(gl, value) {
  1285. value !== WebGLContext._frontFace && (WebGLContext._frontFace = value, gl.frontFace(value));
  1286. }
  1287. static activeTexture(gl, textureID) {
  1288. if (WebGLContext._activedTextureID !== textureID) {
  1289. gl.activeTexture(textureID);
  1290. WebGLContext._activedTextureID = textureID;
  1291. }
  1292. }
  1293. static bindTexture(gl, target, texture) {
  1294. if (WebGLContext._activeTextures[WebGLContext._activedTextureID - gl.TEXTURE0] !== texture) {
  1295. gl.bindTexture(target, texture);
  1296. WebGLContext._activeTextures[WebGLContext._activedTextureID - gl.TEXTURE0] = texture;
  1297. }
  1298. }
  1299. static __init_native() {
  1300. if (!ILaya.Render.supportWebGLPlusRendering)
  1301. return;
  1302. var webGLContext = WebGLContext;
  1303. webGLContext.activeTexture = webGLContext.activeTextureForNative;
  1304. webGLContext.bindTexture = webGLContext.bindTextureForNative;
  1305. }
  1306. static useProgramForNative(gl, program) {
  1307. gl.useProgram(program);
  1308. return true;
  1309. }
  1310. static setDepthTestForNative(gl, value) {
  1311. if (value)
  1312. gl.enable(gl.DEPTH_TEST);
  1313. else
  1314. gl.disable(gl.DEPTH_TEST);
  1315. }
  1316. static setDepthMaskForNative(gl, value) {
  1317. gl.depthMask(value);
  1318. }
  1319. static setDepthFuncForNative(gl, value) {
  1320. gl.depthFunc(value);
  1321. }
  1322. static setBlendForNative(gl, value) {
  1323. if (value)
  1324. gl.enable(gl.BLEND);
  1325. else
  1326. gl.disable(gl.BLEND);
  1327. }
  1328. static setBlendFuncForNative(gl, sFactor, dFactor) {
  1329. gl.blendFunc(sFactor, dFactor);
  1330. }
  1331. static setCullFaceForNative(gl, value) {
  1332. if (value)
  1333. gl.enable(gl.CULL_FACE);
  1334. else
  1335. gl.disable(gl.CULL_FACE);
  1336. }
  1337. static setFrontFaceForNative(gl, value) {
  1338. gl.frontFace(value);
  1339. }
  1340. static activeTextureForNative(gl, textureID) {
  1341. gl.activeTexture(textureID);
  1342. }
  1343. static bindTextureForNative(gl, target, texture) {
  1344. gl.bindTexture(target, texture);
  1345. }
  1346. static bindVertexArrayForNative(gl, vertexArray) {
  1347. gl.bindVertexArray(vertexArray);
  1348. }
  1349. }
  1350. WebGLContext.mainContext = null;
  1351. WebGLContext._activeTextures = new Array(8);
  1352. WebGLContext._useProgram = null;
  1353. WebGLContext._depthTest = true;
  1354. WebGLContext._depthMask = true;
  1355. WebGLContext._blend = false;
  1356. WebGLContext._cullFace = false;
  1357. class BaseTexture extends Bitmap {
  1358. constructor(format, mipMap) {
  1359. super();
  1360. this._wrapModeU = BaseTexture.WARPMODE_REPEAT;
  1361. this._wrapModeV = BaseTexture.WARPMODE_REPEAT;
  1362. this._filterMode = BaseTexture.FILTERMODE_BILINEAR;
  1363. this._readyed = false;
  1364. this._width = -1;
  1365. this._height = -1;
  1366. this._format = format;
  1367. this._mipmap = mipMap;
  1368. this._anisoLevel = 1;
  1369. this._glTexture = LayaGL.instance.createTexture();
  1370. }
  1371. get mipmap() {
  1372. return this._mipmap;
  1373. }
  1374. get format() {
  1375. return this._format;
  1376. }
  1377. get wrapModeU() {
  1378. return this._wrapModeU;
  1379. }
  1380. set wrapModeU(value) {
  1381. if (this._wrapModeU !== value) {
  1382. this._wrapModeU = value;
  1383. (this._width !== -1) && (this._setWarpMode(LayaGL.instance.TEXTURE_WRAP_S, value));
  1384. }
  1385. }
  1386. get wrapModeV() {
  1387. return this._wrapModeV;
  1388. }
  1389. set wrapModeV(value) {
  1390. if (this._wrapModeV !== value) {
  1391. this._wrapModeV = value;
  1392. (this._height !== -1) && (this._setWarpMode(LayaGL.instance.TEXTURE_WRAP_T, value));
  1393. }
  1394. }
  1395. get filterMode() {
  1396. return this._filterMode;
  1397. }
  1398. set filterMode(value) {
  1399. if (value !== this._filterMode) {
  1400. this._filterMode = value;
  1401. ((this._width !== -1) && (this._height !== -1)) && (this._setFilterMode(value));
  1402. }
  1403. }
  1404. get anisoLevel() {
  1405. return this._anisoLevel;
  1406. }
  1407. set anisoLevel(value) {
  1408. if (value !== this._anisoLevel) {
  1409. this._anisoLevel = Math.max(1, Math.min(16, value));
  1410. ((this._width !== -1) && (this._height !== -1)) && (this._setAnisotropy(value));
  1411. }
  1412. }
  1413. get mipmapCount() {
  1414. return this._mipmapCount;
  1415. }
  1416. get defaulteTexture() {
  1417. throw "BaseTexture:must override it.";
  1418. }
  1419. _getFormatByteCount() {
  1420. switch (this._format) {
  1421. case BaseTexture.FORMAT_R8G8B8:
  1422. return 3;
  1423. case BaseTexture.FORMAT_R8G8B8A8:
  1424. return 4;
  1425. case BaseTexture.FORMAT_ALPHA8:
  1426. return 1;
  1427. default:
  1428. throw "Texture2D: unknown format.";
  1429. }
  1430. }
  1431. _isPot(size) {
  1432. return (size & (size - 1)) === 0;
  1433. }
  1434. _getGLFormat() {
  1435. var glFormat;
  1436. var gl = LayaGL.instance;
  1437. var gpu = LayaGL.layaGPUInstance;
  1438. switch (this._format) {
  1439. case BaseTexture.FORMAT_R8G8B8:
  1440. glFormat = gl.RGB;
  1441. break;
  1442. case BaseTexture.FORMAT_R8G8B8A8:
  1443. glFormat = gl.RGBA;
  1444. break;
  1445. case BaseTexture.FORMAT_ALPHA8:
  1446. glFormat = gl.ALPHA;
  1447. break;
  1448. case BaseTexture.FORMAT_DXT1:
  1449. if (gpu._compressedTextureS3tc)
  1450. glFormat = gpu._compressedTextureS3tc.COMPRESSED_RGB_S3TC_DXT1_EXT;
  1451. else
  1452. throw "BaseTexture: not support DXT1 format.";
  1453. break;
  1454. case BaseTexture.FORMAT_DXT5:
  1455. if (gpu._compressedTextureS3tc)
  1456. glFormat = gpu._compressedTextureS3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  1457. else
  1458. throw "BaseTexture: not support DXT5 format.";
  1459. break;
  1460. case BaseTexture.FORMAT_ETC1RGB:
  1461. if (gpu._compressedTextureEtc1)
  1462. glFormat = gpu._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL;
  1463. else
  1464. throw "BaseTexture: not support ETC1RGB format.";
  1465. break;
  1466. case BaseTexture.FORMAT_PVRTCRGB_2BPPV:
  1467. if (gpu._compressedTexturePvrtc)
  1468. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  1469. else
  1470. throw "BaseTexture: not support PVRTCRGB_2BPPV format.";
  1471. break;
  1472. case BaseTexture.FORMAT_PVRTCRGBA_2BPPV:
  1473. if (gpu._compressedTexturePvrtc)
  1474. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  1475. else
  1476. throw "BaseTexture: not support PVRTCRGBA_2BPPV format.";
  1477. break;
  1478. case BaseTexture.FORMAT_PVRTCRGB_4BPPV:
  1479. if (gpu._compressedTexturePvrtc)
  1480. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  1481. else
  1482. throw "BaseTexture: not support PVRTCRGB_4BPPV format.";
  1483. break;
  1484. case BaseTexture.FORMAT_PVRTCRGBA_4BPPV:
  1485. if (gpu._compressedTexturePvrtc)
  1486. glFormat = gpu._compressedTexturePvrtc.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  1487. else
  1488. throw "BaseTexture: not support PVRTCRGBA_4BPPV format.";
  1489. break;
  1490. default:
  1491. throw "BaseTexture: unknown texture format.";
  1492. }
  1493. return glFormat;
  1494. }
  1495. _setFilterMode(value) {
  1496. var gl = LayaGL.instance;
  1497. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1498. switch (value) {
  1499. case BaseTexture.FILTERMODE_POINT:
  1500. if (this._mipmap)
  1501. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
  1502. else
  1503. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  1504. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  1505. break;
  1506. case BaseTexture.FILTERMODE_BILINEAR:
  1507. if (this._mipmap)
  1508. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
  1509. else
  1510. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1511. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1512. break;
  1513. case BaseTexture.FILTERMODE_TRILINEAR:
  1514. if (this._mipmap)
  1515. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
  1516. else
  1517. gl.texParameteri(this._glTextureType, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  1518. gl.texParameteri(this._glTextureType, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1519. break;
  1520. default:
  1521. throw new Error("BaseTexture:unknown filterMode value.");
  1522. }
  1523. }
  1524. _setWarpMode(orientation, mode) {
  1525. var gl = LayaGL.instance;
  1526. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1527. if (this._isPot(this._width) && this._isPot(this._height)) {
  1528. switch (mode) {
  1529. case BaseTexture.WARPMODE_REPEAT:
  1530. gl.texParameteri(this._glTextureType, orientation, gl.REPEAT);
  1531. break;
  1532. case BaseTexture.WARPMODE_CLAMP:
  1533. gl.texParameteri(this._glTextureType, orientation, gl.CLAMP_TO_EDGE);
  1534. break;
  1535. }
  1536. }
  1537. else {
  1538. gl.texParameteri(this._glTextureType, orientation, gl.CLAMP_TO_EDGE);
  1539. }
  1540. }
  1541. _setAnisotropy(value) {
  1542. var anisotropic = LayaGL.layaGPUInstance._extTextureFilterAnisotropic;
  1543. if (anisotropic) {
  1544. value = Math.max(value, 1);
  1545. var gl = LayaGL.instance;
  1546. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1547. value = Math.min(gl.getParameter(anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT), value);
  1548. gl.texParameterf(this._glTextureType, anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, value);
  1549. }
  1550. }
  1551. _disposeResource() {
  1552. if (this._glTexture) {
  1553. LayaGL.instance.deleteTexture(this._glTexture);
  1554. this._glTexture = null;
  1555. this._setGPUMemory(0);
  1556. }
  1557. }
  1558. _getSource() {
  1559. if (this._readyed)
  1560. return this._glTexture;
  1561. else
  1562. return null;
  1563. }
  1564. generateMipmap() {
  1565. if (this._isPot(this.width) && this._isPot(this.height))
  1566. LayaGL.instance.generateMipmap(this._glTextureType);
  1567. }
  1568. }
  1569. BaseTexture.WARPMODE_REPEAT = 0;
  1570. BaseTexture.WARPMODE_CLAMP = 1;
  1571. BaseTexture.FILTERMODE_POINT = 0;
  1572. BaseTexture.FILTERMODE_BILINEAR = 1;
  1573. BaseTexture.FILTERMODE_TRILINEAR = 2;
  1574. BaseTexture.FORMAT_R8G8B8 = 0;
  1575. BaseTexture.FORMAT_R8G8B8A8 = 1;
  1576. BaseTexture.FORMAT_ALPHA8 = 2;
  1577. BaseTexture.FORMAT_DXT1 = 3;
  1578. BaseTexture.FORMAT_DXT5 = 4;
  1579. BaseTexture.FORMAT_ETC1RGB = 5;
  1580. BaseTexture.FORMAT_PVRTCRGB_2BPPV = 9;
  1581. BaseTexture.FORMAT_PVRTCRGBA_2BPPV = 10;
  1582. BaseTexture.FORMAT_PVRTCRGB_4BPPV = 11;
  1583. BaseTexture.FORMAT_PVRTCRGBA_4BPPV = 12;
  1584. BaseTexture.RENDERTEXTURE_FORMAT_RGBA_HALF_FLOAT = 14;
  1585. BaseTexture.FORMAT_DEPTH_16 = 0;
  1586. BaseTexture.FORMAT_STENCIL_8 = 1;
  1587. BaseTexture.FORMAT_DEPTHSTENCIL_16_8 = 2;
  1588. BaseTexture.FORMAT_DEPTHSTENCIL_NONE = 3;
  1589. class Texture2D extends BaseTexture {
  1590. constructor(width = 0, height = 0, format = BaseTexture.FORMAT_R8G8B8A8, mipmap = true, canRead = false) {
  1591. super(format, mipmap);
  1592. var gl = LayaGL.instance;
  1593. this._glTextureType = gl.TEXTURE_2D;
  1594. this._width = width;
  1595. this._height = height;
  1596. this._canRead = canRead;
  1597. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  1598. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  1599. this._setFilterMode(this._filterMode);
  1600. this._setAnisotropy(this._anisoLevel);
  1601. if (this._mipmap) {
  1602. this._mipmapCount = Math.max(Math.ceil(Math.log2(width)) + 1, Math.ceil(Math.log2(height)) + 1);
  1603. for (var i = 0; i < this._mipmapCount; i++)
  1604. this._setPixels(null, i, Math.max(width >> i, 1), Math.max(height >> i, 1));
  1605. this._setGPUMemory(width * height * 4 * (1 + 1 / 3));
  1606. }
  1607. else {
  1608. this._mipmapCount = 1;
  1609. this._setGPUMemory(width * height * 4);
  1610. }
  1611. }
  1612. static __init__() {
  1613. var pixels = new Uint8Array(3);
  1614. pixels[0] = 128;
  1615. pixels[1] = 128;
  1616. pixels[2] = 128;
  1617. Texture2D.grayTexture = new Texture2D(1, 1, BaseTexture.FORMAT_R8G8B8, false, false);
  1618. Texture2D.grayTexture.setPixels(pixels);
  1619. Texture2D.grayTexture.lock = true;
  1620. pixels[0] = 255;
  1621. pixels[1] = 255;
  1622. pixels[2] = 255;
  1623. Texture2D.whiteTexture = new Texture2D(1, 1, BaseTexture.FORMAT_R8G8B8, false, false);
  1624. Texture2D.whiteTexture.setPixels(pixels);
  1625. Texture2D.whiteTexture.lock = true;
  1626. pixels[0] = 0;
  1627. pixels[1] = 0;
  1628. pixels[2] = 0;
  1629. Texture2D.blackTexture = new Texture2D(1, 1, BaseTexture.FORMAT_R8G8B8, false, false);
  1630. Texture2D.blackTexture.setPixels(pixels);
  1631. Texture2D.blackTexture.lock = true;
  1632. }
  1633. static _parse(data, propertyParams = null, constructParams = null) {
  1634. var texture = constructParams ? new Texture2D(constructParams[0], constructParams[1], constructParams[2], constructParams[3], constructParams[4]) : new Texture2D(0, 0);
  1635. if (propertyParams) {
  1636. texture.wrapModeU = propertyParams.wrapModeU;
  1637. texture.wrapModeV = propertyParams.wrapModeV;
  1638. texture.filterMode = propertyParams.filterMode;
  1639. texture.anisoLevel = propertyParams.anisoLevel;
  1640. }
  1641. switch (texture._format) {
  1642. case BaseTexture.FORMAT_R8G8B8:
  1643. case BaseTexture.FORMAT_R8G8B8A8:
  1644. texture.loadImageSource(data);
  1645. break;
  1646. case BaseTexture.FORMAT_DXT1:
  1647. case BaseTexture.FORMAT_DXT5:
  1648. case BaseTexture.FORMAT_ETC1RGB:
  1649. case BaseTexture.FORMAT_PVRTCRGB_2BPPV:
  1650. case BaseTexture.FORMAT_PVRTCRGBA_2BPPV:
  1651. case BaseTexture.FORMAT_PVRTCRGB_4BPPV:
  1652. case BaseTexture.FORMAT_PVRTCRGBA_4BPPV:
  1653. texture.setCompressData(data);
  1654. break;
  1655. default:
  1656. throw "Texture2D:unkonwn format.";
  1657. }
  1658. return texture;
  1659. }
  1660. static load(url, complete) {
  1661. ILaya.loader.create(url, complete, null, ILaya.Loader.TEXTURE2D);
  1662. }
  1663. get defaulteTexture() {
  1664. return Texture2D.grayTexture;
  1665. }
  1666. _setPixels(pixels, miplevel, width, height) {
  1667. var gl = LayaGL.instance;
  1668. var textureType = this._glTextureType;
  1669. var glFormat = this._getGLFormat();
  1670. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1671. if (this.format === BaseTexture.FORMAT_R8G8B8) {
  1672. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  1673. gl.texImage2D(textureType, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels);
  1674. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  1675. }
  1676. else {
  1677. gl.texImage2D(textureType, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels);
  1678. }
  1679. }
  1680. _calcualatesCompressedDataSize(format, width, height) {
  1681. switch (format) {
  1682. case BaseTexture.FORMAT_DXT1:
  1683. case BaseTexture.FORMAT_ETC1RGB:
  1684. return ((width + 3) >> 2) * ((height + 3) >> 2) * 8;
  1685. case BaseTexture.FORMAT_DXT5:
  1686. return ((width + 3) >> 2) * ((height + 3) >> 2) * 16;
  1687. case BaseTexture.FORMAT_PVRTCRGB_4BPPV:
  1688. case BaseTexture.FORMAT_PVRTCRGBA_4BPPV:
  1689. return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);
  1690. case BaseTexture.FORMAT_PVRTCRGB_2BPPV:
  1691. case BaseTexture.FORMAT_PVRTCRGBA_2BPPV:
  1692. return Math.floor((Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8);
  1693. default:
  1694. return 0;
  1695. }
  1696. }
  1697. _pharseDDS(arrayBuffer) {
  1698. const FOURCC_DXT1 = 827611204;
  1699. const FOURCC_DXT5 = 894720068;
  1700. const DDPF_FOURCC = 0x4;
  1701. const DDSD_MIPMAPCOUNT = 0x20000;
  1702. const DDS_MAGIC = 0x20534444;
  1703. const DDS_HEADER_LENGTH = 31;
  1704. const DDS_HEADER_MAGIC = 0;
  1705. const DDS_HEADER_SIZE = 1;
  1706. const DDS_HEADER_FLAGS = 2;
  1707. const DDS_HEADER_HEIGHT = 3;
  1708. const DDS_HEADER_WIDTH = 4;
  1709. const DDS_HEADER_MIPMAPCOUNT = 7;
  1710. const DDS_HEADER_PF_FLAGS = 20;
  1711. const DDS_HEADER_PF_FOURCC = 21;
  1712. var header = new Int32Array(arrayBuffer, 0, DDS_HEADER_LENGTH);
  1713. if (header[DDS_HEADER_MAGIC] != DDS_MAGIC)
  1714. throw "Invalid magic number in DDS header";
  1715. if (!(header[DDS_HEADER_PF_FLAGS] & DDPF_FOURCC))
  1716. throw "Unsupported format, must contain a FourCC code";
  1717. var compressedFormat = header[DDS_HEADER_PF_FOURCC];
  1718. switch (this._format) {
  1719. case BaseTexture.FORMAT_DXT1:
  1720. if (compressedFormat !== FOURCC_DXT1)
  1721. throw "the FourCC code is not same with texture format.";
  1722. break;
  1723. case BaseTexture.FORMAT_DXT5:
  1724. if (compressedFormat !== FOURCC_DXT5)
  1725. throw "the FourCC code is not same with texture format.";
  1726. break;
  1727. default:
  1728. throw "unknown texture format.";
  1729. }
  1730. var mipLevels = 1;
  1731. if (header[DDS_HEADER_FLAGS] & DDSD_MIPMAPCOUNT) {
  1732. mipLevels = Math.max(1, header[DDS_HEADER_MIPMAPCOUNT]);
  1733. if (!this._mipmap)
  1734. throw "the mipmap is not same with Texture2D.";
  1735. }
  1736. else {
  1737. if (this._mipmap)
  1738. throw "the mipmap is not same with Texture2D.";
  1739. }
  1740. var width = header[DDS_HEADER_WIDTH];
  1741. var height = header[DDS_HEADER_HEIGHT];
  1742. this._width = width;
  1743. this._height = height;
  1744. var dataOffset = header[DDS_HEADER_SIZE] + 4;
  1745. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 0);
  1746. }
  1747. _pharseKTX(arrayBuffer) {
  1748. const ETC_HEADER_LENGTH = 13;
  1749. const ETC_HEADER_FORMAT = 4;
  1750. const ETC_HEADER_HEIGHT = 7;
  1751. const ETC_HEADER_WIDTH = 6;
  1752. const ETC_HEADER_MIPMAPCOUNT = 11;
  1753. const ETC_HEADER_METADATA = 12;
  1754. var id = new Uint8Array(arrayBuffer, 0, 12);
  1755. 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)
  1756. throw ("Invalid fileIdentifier in KTX header");
  1757. var header = new Int32Array(id.buffer, id.length, ETC_HEADER_LENGTH);
  1758. var compressedFormat = header[ETC_HEADER_FORMAT];
  1759. switch (compressedFormat) {
  1760. case LayaGL.layaGPUInstance._compressedTextureEtc1.COMPRESSED_RGB_ETC1_WEBGL:
  1761. this._format = BaseTexture.FORMAT_ETC1RGB;
  1762. break;
  1763. default:
  1764. throw "unknown texture format.";
  1765. }
  1766. var mipLevels = header[ETC_HEADER_MIPMAPCOUNT];
  1767. var width = header[ETC_HEADER_WIDTH];
  1768. var height = header[ETC_HEADER_HEIGHT];
  1769. this._width = width;
  1770. this._height = height;
  1771. var dataOffset = 64 + header[ETC_HEADER_METADATA];
  1772. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 4);
  1773. }
  1774. _pharsePVR(arrayBuffer) {
  1775. const PVR_FORMAT_2BPP_RGB = 0;
  1776. const PVR_FORMAT_2BPP_RGBA = 1;
  1777. const PVR_FORMAT_4BPP_RGB = 2;
  1778. const PVR_FORMAT_4BPP_RGBA = 3;
  1779. const PVR_MAGIC = 0x03525650;
  1780. const PVR_HEADER_LENGTH = 13;
  1781. const PVR_HEADER_MAGIC = 0;
  1782. const PVR_HEADER_FORMAT = 2;
  1783. const PVR_HEADER_HEIGHT = 6;
  1784. const PVR_HEADER_WIDTH = 7;
  1785. const PVR_HEADER_MIPMAPCOUNT = 11;
  1786. const PVR_HEADER_METADATA = 12;
  1787. var header = new Int32Array(arrayBuffer, 0, PVR_HEADER_LENGTH);
  1788. if (header[PVR_HEADER_MAGIC] != PVR_MAGIC)
  1789. throw ("Invalid magic number in PVR header");
  1790. var compressedFormat = header[PVR_HEADER_FORMAT];
  1791. switch (compressedFormat) {
  1792. case PVR_FORMAT_2BPP_RGB:
  1793. this._format = BaseTexture.FORMAT_PVRTCRGB_2BPPV;
  1794. break;
  1795. case PVR_FORMAT_4BPP_RGB:
  1796. this._format = BaseTexture.FORMAT_PVRTCRGB_4BPPV;
  1797. break;
  1798. case PVR_FORMAT_2BPP_RGBA:
  1799. this._format = BaseTexture.FORMAT_PVRTCRGBA_2BPPV;
  1800. break;
  1801. case PVR_FORMAT_4BPP_RGBA:
  1802. this._format = BaseTexture.FORMAT_PVRTCRGBA_4BPPV;
  1803. break;
  1804. default:
  1805. throw "Texture2D:unknown PVR format.";
  1806. }
  1807. var mipLevels = header[PVR_HEADER_MIPMAPCOUNT];
  1808. var width = header[PVR_HEADER_WIDTH];
  1809. var height = header[PVR_HEADER_HEIGHT];
  1810. this._width = width;
  1811. this._height = height;
  1812. var dataOffset = header[PVR_HEADER_METADATA] + 52;
  1813. this._upLoadCompressedTexImage2D(arrayBuffer, width, height, mipLevels, dataOffset, 0);
  1814. }
  1815. _upLoadCompressedTexImage2D(data, width, height, miplevelCount, dataOffset, imageSizeOffset) {
  1816. var gl = LayaGL.instance;
  1817. var textureType = this._glTextureType;
  1818. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1819. var glFormat = this._getGLFormat();
  1820. var offset = dataOffset;
  1821. for (var i = 0; i < miplevelCount; i++) {
  1822. offset += imageSizeOffset;
  1823. var mipDataSize = this._calcualatesCompressedDataSize(this._format, width, height);
  1824. var mipData = new Uint8Array(data, offset, mipDataSize);
  1825. gl.compressedTexImage2D(textureType, i, glFormat, width, height, 0, mipData);
  1826. width = Math.max(width >> 1, 1.0);
  1827. height = Math.max(height >> 1, 1.0);
  1828. offset += mipDataSize;
  1829. }
  1830. var memory = offset;
  1831. this._setGPUMemory(memory);
  1832. this._readyed = true;
  1833. this._activeResource();
  1834. }
  1835. loadImageSource(source, premultiplyAlpha = false) {
  1836. var gl = LayaGL.instance;
  1837. var width = source.width;
  1838. var height = source.height;
  1839. this._width = width;
  1840. this._height = height;
  1841. if (!(this._isPot(width) && this._isPot(height)))
  1842. this._mipmap = false;
  1843. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  1844. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  1845. this._setFilterMode(this._filterMode);
  1846. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  1847. var glFormat = this._getGLFormat();
  1848. if (ILaya.Render.isConchApp) {
  1849. if (source.setPremultiplyAlpha) {
  1850. source.setPremultiplyAlpha(premultiplyAlpha);
  1851. }
  1852. gl.texImage2D(this._glTextureType, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
  1853. }
  1854. else {
  1855. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true));
  1856. gl.texImage2D(this._glTextureType, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source);
  1857. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false));
  1858. }
  1859. if (this._mipmap) {
  1860. gl.generateMipmap(this._glTextureType);
  1861. this._setGPUMemory(width * height * 4 * (1 + 1 / 3));
  1862. }
  1863. else {
  1864. this._setGPUMemory(width * height * 4);
  1865. }
  1866. if (this._canRead) {
  1867. if (ILaya.Render.isConchApp) {
  1868. this._pixels = new Uint8Array(source._nativeObj.getImageData(0, 0, width, height));
  1869. }
  1870. else {
  1871. ILaya.Browser.canvas.size(width, height);
  1872. ILaya.Browser.canvas.clear();
  1873. ILaya.Browser.context.drawImage(source, 0, 0, width, height);
  1874. this._pixels = new Uint8Array(ILaya.Browser.context.getImageData(0, 0, width, height).data.buffer);
  1875. }
  1876. }
  1877. this._readyed = true;
  1878. this._activeResource();
  1879. }
  1880. setPixels(pixels, miplevel = 0) {
  1881. if (!pixels)
  1882. throw "Texture2D:pixels can't be null.";
  1883. var width = Math.max(this._width >> miplevel, 1);
  1884. var height = Math.max(this._height >> miplevel, 1);
  1885. var pixelsCount = width * height * this._getFormatByteCount();
  1886. if (pixels.length < pixelsCount)
  1887. throw "Texture2D:pixels length should at least " + pixelsCount + ".";
  1888. this._setPixels(pixels, miplevel, width, height);
  1889. if (this._canRead)
  1890. this._pixels = pixels;
  1891. this._readyed = true;
  1892. this._activeResource();
  1893. }
  1894. setSubPixels(x, y, width, height, pixels, miplevel = 0) {
  1895. if (!pixels)
  1896. throw "Texture2D:pixels can't be null.";
  1897. var gl = LayaGL.instance;
  1898. var textureType = this._glTextureType;
  1899. WebGLContext.bindTexture(gl, textureType, this._glTexture);
  1900. var glFormat = this._getGLFormat();
  1901. if (this._format === BaseTexture.FORMAT_R8G8B8) {
  1902. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  1903. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  1904. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  1905. }
  1906. else {
  1907. gl.texSubImage2D(textureType, miplevel, x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  1908. }
  1909. this._readyed = true;
  1910. this._activeResource();
  1911. }
  1912. setCompressData(data) {
  1913. switch (this._format) {
  1914. case BaseTexture.FORMAT_DXT1:
  1915. case BaseTexture.FORMAT_DXT5:
  1916. this._pharseDDS(data);
  1917. break;
  1918. case BaseTexture.FORMAT_ETC1RGB:
  1919. this._pharseKTX(data);
  1920. break;
  1921. case BaseTexture.FORMAT_PVRTCRGB_2BPPV:
  1922. case BaseTexture.FORMAT_PVRTCRGBA_2BPPV:
  1923. case BaseTexture.FORMAT_PVRTCRGB_4BPPV:
  1924. case BaseTexture.FORMAT_PVRTCRGBA_4BPPV:
  1925. this._pharsePVR(data);
  1926. break;
  1927. default:
  1928. throw "Texture2D:unkonwn format.";
  1929. }
  1930. }
  1931. _recoverResource() {
  1932. }
  1933. getPixels() {
  1934. if (this._canRead)
  1935. return this._pixels;
  1936. else
  1937. throw new Error("Texture2D: must set texture canRead is true.");
  1938. }
  1939. }
  1940. Texture2D.TEXTURE2D = "TEXTURE2D";
  1941. Texture2D.grayTexture = null;
  1942. Texture2D.whiteTexture = null;
  1943. Texture2D.blackTexture = null;
  1944. class BaseShader extends Resource {
  1945. constructor() {
  1946. super();
  1947. }
  1948. }
  1949. class RenderState2D {
  1950. static mat2MatArray(mat, matArray) {
  1951. var m = mat;
  1952. var m4 = matArray;
  1953. m4[0] = m.a;
  1954. m4[1] = m.b;
  1955. m4[2] = RenderState2D.EMPTYMAT4_ARRAY[2];
  1956. m4[3] = RenderState2D.EMPTYMAT4_ARRAY[3];
  1957. m4[4] = m.c;
  1958. m4[5] = m.d;
  1959. m4[6] = RenderState2D.EMPTYMAT4_ARRAY[6];
  1960. m4[7] = RenderState2D.EMPTYMAT4_ARRAY[7];
  1961. m4[8] = RenderState2D.EMPTYMAT4_ARRAY[8];
  1962. m4[9] = RenderState2D.EMPTYMAT4_ARRAY[9];
  1963. m4[10] = RenderState2D.EMPTYMAT4_ARRAY[10];
  1964. m4[11] = RenderState2D.EMPTYMAT4_ARRAY[11];
  1965. m4[12] = m.tx;
  1966. m4[13] = m.ty;
  1967. m4[14] = RenderState2D.EMPTYMAT4_ARRAY[14];
  1968. m4[15] = RenderState2D.EMPTYMAT4_ARRAY[15];
  1969. return matArray;
  1970. }
  1971. static restoreTempArray() {
  1972. RenderState2D.TEMPMAT4_ARRAY[0] = 1;
  1973. RenderState2D.TEMPMAT4_ARRAY[1] = 0;
  1974. RenderState2D.TEMPMAT4_ARRAY[4] = 0;
  1975. RenderState2D.TEMPMAT4_ARRAY[5] = 1;
  1976. RenderState2D.TEMPMAT4_ARRAY[12] = 0;
  1977. RenderState2D.TEMPMAT4_ARRAY[13] = 0;
  1978. }
  1979. static clear() {
  1980. RenderState2D.worldScissorTest = false;
  1981. RenderState2D.worldAlpha = 1;
  1982. }
  1983. }
  1984. RenderState2D._MAXSIZE = 99999999;
  1985. RenderState2D.EMPTYMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  1986. RenderState2D.TEMPMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  1987. RenderState2D.worldMatrix4 = RenderState2D.TEMPMAT4_ARRAY;
  1988. RenderState2D.worldMatrix = new Matrix();
  1989. RenderState2D.matWVP = null;
  1990. RenderState2D.worldAlpha = 1.0;
  1991. RenderState2D.worldScissorTest = false;
  1992. RenderState2D.width = 0;
  1993. RenderState2D.height = 0;
  1994. class RenderTexture2D extends BaseTexture {
  1995. constructor(width, height, format = BaseTexture.FORMAT_R8G8B8, depthStencilFormat = BaseTexture.FORMAT_DEPTH_16) {
  1996. super(format, false);
  1997. this._mgrKey = 0;
  1998. this._glTextureType = LayaGL.instance.TEXTURE_2D;
  1999. this._width = width;
  2000. this._height = height;
  2001. this._depthStencilFormat = depthStencilFormat;
  2002. this._create(width, height);
  2003. this.lock = true;
  2004. }
  2005. static get currentActive() {
  2006. return RenderTexture2D._currentActive;
  2007. }
  2008. get depthStencilFormat() {
  2009. return this._depthStencilFormat;
  2010. }
  2011. get defaulteTexture() {
  2012. return Texture2D.grayTexture;
  2013. }
  2014. getIsReady() {
  2015. return true;
  2016. }
  2017. get sourceWidth() {
  2018. return this._width;
  2019. }
  2020. get sourceHeight() {
  2021. return this._height;
  2022. }
  2023. get offsetX() {
  2024. return 0;
  2025. }
  2026. get offsetY() {
  2027. return 0;
  2028. }
  2029. _create(width, height) {
  2030. var gl = LayaGL.instance;
  2031. this._frameBuffer = gl.createFramebuffer();
  2032. WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  2033. var glFormat = this._getGLFormat();
  2034. gl.texImage2D(this._glTextureType, 0, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, null);
  2035. this._setGPUMemory(width * height * 4);
  2036. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2037. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, 0);
  2038. if (this._depthStencilFormat !== BaseTexture.FORMAT_DEPTHSTENCIL_NONE) {
  2039. this._depthStencilBuffer = gl.createRenderbuffer();
  2040. gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthStencilBuffer);
  2041. switch (this._depthStencilFormat) {
  2042. case BaseTexture.FORMAT_DEPTH_16:
  2043. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
  2044. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2045. break;
  2046. case BaseTexture.FORMAT_STENCIL_8:
  2047. gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height);
  2048. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2049. break;
  2050. case BaseTexture.FORMAT_DEPTHSTENCIL_16_8:
  2051. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
  2052. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilBuffer);
  2053. break;
  2054. default:
  2055. }
  2056. }
  2057. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2058. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  2059. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  2060. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  2061. this._setFilterMode(this._filterMode);
  2062. this._setAnisotropy(this._anisoLevel);
  2063. this._readyed = true;
  2064. this._activeResource();
  2065. }
  2066. generateMipmap() {
  2067. if (this._isPot(this.width) && this._isPot(this.height)) {
  2068. this._mipmap = true;
  2069. LayaGL.instance.generateMipmap(this._glTextureType);
  2070. this._setFilterMode(this._filterMode);
  2071. this._setGPUMemory(this.width * this.height * 4 * (1 + 1 / 3));
  2072. }
  2073. else {
  2074. this._mipmap = false;
  2075. this._setGPUMemory(this.width * this.height * 4);
  2076. }
  2077. }
  2078. static pushRT() {
  2079. RenderTexture2D.rtStack.push({ rt: RenderTexture2D._currentActive, w: RenderState2D.width, h: RenderState2D.height });
  2080. }
  2081. static popRT() {
  2082. var gl = LayaGL.instance;
  2083. var top = RenderTexture2D.rtStack.pop();
  2084. if (top) {
  2085. if (RenderTexture2D._currentActive != top.rt) {
  2086. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, top.rt ? top.rt._frameBuffer : null);
  2087. RenderTexture2D._currentActive = top.rt;
  2088. }
  2089. gl.viewport(0, 0, top.w, top.h);
  2090. RenderState2D.width = top.w;
  2091. RenderState2D.height = top.h;
  2092. }
  2093. }
  2094. start() {
  2095. var gl = LayaGL.instance;
  2096. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2097. this._lastRT = RenderTexture2D._currentActive;
  2098. RenderTexture2D._currentActive = this;
  2099. this._readyed = true;
  2100. gl.viewport(0, 0, this._width, this._height);
  2101. this._lastWidth = RenderState2D.width;
  2102. this._lastHeight = RenderState2D.height;
  2103. RenderState2D.width = this._width;
  2104. RenderState2D.height = this._height;
  2105. BaseShader.activeShader = null;
  2106. }
  2107. end() {
  2108. var gl = LayaGL.instance;
  2109. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2110. RenderTexture2D._currentActive = null;
  2111. this._readyed = true;
  2112. }
  2113. restore() {
  2114. var gl = LayaGL.instance;
  2115. if (this._lastRT != RenderTexture2D._currentActive) {
  2116. LayaGL.instance.bindFramebuffer(gl.FRAMEBUFFER, this._lastRT ? this._lastRT._frameBuffer : null);
  2117. RenderTexture2D._currentActive = this._lastRT;
  2118. }
  2119. this._readyed = true;
  2120. gl.viewport(0, 0, this._lastWidth, this._lastHeight);
  2121. RenderState2D.width = this._lastWidth;
  2122. RenderState2D.height = this._lastHeight;
  2123. BaseShader.activeShader = null;
  2124. }
  2125. clear(r = 0.0, g = 0.0, b = 0.0, a = 1.0) {
  2126. var gl = LayaGL.instance;
  2127. gl.clearColor(r, g, b, a);
  2128. var clearFlag = gl.COLOR_BUFFER_BIT;
  2129. switch (this._depthStencilFormat) {
  2130. case gl.DEPTH_COMPONENT16:
  2131. clearFlag |= gl.DEPTH_BUFFER_BIT;
  2132. break;
  2133. case gl.STENCIL_INDEX8:
  2134. clearFlag |= gl.STENCIL_BUFFER_BIT;
  2135. break;
  2136. case gl.DEPTH_STENCIL:
  2137. clearFlag |= gl.DEPTH_BUFFER_BIT;
  2138. clearFlag |= gl.STENCIL_BUFFER_BIT;
  2139. break;
  2140. }
  2141. gl.clear(clearFlag);
  2142. }
  2143. getData(x, y, width, height) {
  2144. if (ILaya.Render.isConchApp && window.conchConfig.threadMode == 2) {
  2145. throw "native 2 thread mode use getDataAsync";
  2146. }
  2147. var gl = LayaGL.instance;
  2148. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2149. var canRead = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);
  2150. if (!canRead) {
  2151. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2152. return null;
  2153. }
  2154. var pixels = new Uint8Array(this._width * this._height * 4);
  2155. var glFormat = this._getGLFormat();
  2156. gl.readPixels(x, y, width, height, glFormat, gl.UNSIGNED_BYTE, pixels);
  2157. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2158. return pixels;
  2159. }
  2160. getDataAsync(x, y, width, height, callBack) {
  2161. var gl = LayaGL.instance;
  2162. gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
  2163. gl.readPixelsAsync(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, function (data) {
  2164. callBack(new Uint8Array(data));
  2165. });
  2166. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  2167. }
  2168. recycle() {
  2169. }
  2170. _disposeResource() {
  2171. if (this._frameBuffer) {
  2172. var gl = LayaGL.instance;
  2173. gl.deleteTexture(this._glTexture);
  2174. gl.deleteFramebuffer(this._frameBuffer);
  2175. gl.deleteRenderbuffer(this._depthStencilBuffer);
  2176. this._glTexture = null;
  2177. this._frameBuffer = null;
  2178. this._depthStencilBuffer = null;
  2179. this._setGPUMemory(0);
  2180. }
  2181. }
  2182. }
  2183. RenderTexture2D.rtStack = [];
  2184. RenderTexture2D.defuv = [0, 0, 1, 0, 1, 1, 0, 1];
  2185. RenderTexture2D.flipyuv = [0, 1, 1, 1, 1, 0, 0, 0];
  2186. class WebGLRTMgr {
  2187. static getRT(w, h) {
  2188. w = w | 0;
  2189. h = h | 0;
  2190. if (w >= 10000) {
  2191. console.error('getRT error! w too big');
  2192. }
  2193. var ret;
  2194. ret = new RenderTexture2D(w, h, BaseTexture.FORMAT_R8G8B8A8, -1);
  2195. return ret;
  2196. }
  2197. static releaseRT(rt) {
  2198. rt._disposeResource();
  2199. return;
  2200. }
  2201. }
  2202. WebGLRTMgr.dict = {};
  2203. class BlendMode {
  2204. static _init_(gl) {
  2205. BlendMode.fns = [BlendMode.BlendNormal, BlendMode.BlendAdd, BlendMode.BlendMultiply, BlendMode.BlendScreen, BlendMode.BlendOverlay, BlendMode.BlendLight, BlendMode.BlendMask, BlendMode.BlendDestinationOut];
  2206. BlendMode.targetFns = [BlendMode.BlendNormalTarget, BlendMode.BlendAddTarget, BlendMode.BlendMultiplyTarget, BlendMode.BlendScreenTarget, BlendMode.BlendOverlayTarget, BlendMode.BlendLightTarget, BlendMode.BlendMask, BlendMode.BlendDestinationOut];
  2207. }
  2208. static BlendNormal(gl) {
  2209. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  2210. }
  2211. static BlendAdd(gl) {
  2212. WebGLContext.setBlendFunc(gl, gl.ONE, gl.DST_ALPHA);
  2213. }
  2214. static BlendMultiply(gl) {
  2215. WebGLContext.setBlendFunc(gl, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA);
  2216. }
  2217. static BlendScreen(gl) {
  2218. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2219. }
  2220. static BlendOverlay(gl) {
  2221. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_COLOR);
  2222. }
  2223. static BlendLight(gl) {
  2224. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2225. }
  2226. static BlendNormalTarget(gl) {
  2227. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  2228. }
  2229. static BlendAddTarget(gl) {
  2230. WebGLContext.setBlendFunc(gl, gl.ONE, gl.DST_ALPHA);
  2231. }
  2232. static BlendMultiplyTarget(gl) {
  2233. WebGLContext.setBlendFunc(gl, gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA);
  2234. }
  2235. static BlendScreenTarget(gl) {
  2236. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2237. }
  2238. static BlendOverlayTarget(gl) {
  2239. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_COLOR);
  2240. }
  2241. static BlendLightTarget(gl) {
  2242. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE);
  2243. }
  2244. static BlendMask(gl) {
  2245. WebGLContext.setBlendFunc(gl, gl.ZERO, gl.SRC_ALPHA);
  2246. }
  2247. static BlendDestinationOut(gl) {
  2248. WebGLContext.setBlendFunc(gl, gl.ZERO, gl.ZERO);
  2249. }
  2250. }
  2251. BlendMode.activeBlendFunction = null;
  2252. BlendMode.NAMES = ["normal", "add", "multiply", "screen", "overlay", "light", "mask", "destination-out"];
  2253. BlendMode.TOINT = { "normal": 0, "add": 1, "multiply": 2, "screen": 3, "overlay": 4, "light": 5, "mask": 6, "destination-out": 7, "lighter": 1 };
  2254. BlendMode.NORMAL = "normal";
  2255. BlendMode.ADD = "add";
  2256. BlendMode.MULTIPLY = "multiply";
  2257. BlendMode.SCREEN = "screen";
  2258. BlendMode.OVERLAY = "overlay";
  2259. BlendMode.LIGHT = "light";
  2260. BlendMode.MASK = "mask";
  2261. BlendMode.DESTINATIONOUT = "destination-out";
  2262. BlendMode.LIGHTER = "lighter";
  2263. BlendMode.fns = [];
  2264. BlendMode.targetFns = [];
  2265. class ShaderDefinesBase {
  2266. constructor(name2int, int2name, int2nameMap) {
  2267. this._value = 0;
  2268. this._name2int = name2int;
  2269. this._int2name = int2name;
  2270. this._int2nameMap = int2nameMap;
  2271. }
  2272. add(value) {
  2273. if (typeof (value) == 'string') {
  2274. this._value |= this._name2int[value];
  2275. }
  2276. else {
  2277. this._value |= value;
  2278. }
  2279. return this._value;
  2280. }
  2281. addInt(value) {
  2282. this._value |= value;
  2283. return this._value;
  2284. }
  2285. remove(value) {
  2286. if (typeof (value) == 'string') {
  2287. this._value &= ~(this._name2int[value]);
  2288. }
  2289. else {
  2290. this._value &= (~value);
  2291. }
  2292. return this._value;
  2293. }
  2294. isDefine(def) {
  2295. return (this._value & def) === def;
  2296. }
  2297. getValue() {
  2298. return this._value;
  2299. }
  2300. setValue(value) {
  2301. this._value = value;
  2302. }
  2303. toNameDic() {
  2304. var r = this._int2nameMap[this._value];
  2305. return r ? r : ShaderDefinesBase._toText(this._value, this._int2name, this._int2nameMap);
  2306. }
  2307. static _reg(name, value, _name2int, _int2name) {
  2308. _name2int[name] = value;
  2309. _int2name[value] = name;
  2310. }
  2311. static _toText(value, _int2name, _int2nameMap) {
  2312. var r = _int2nameMap[value];
  2313. if (r)
  2314. return r;
  2315. var o = {};
  2316. var d = 1;
  2317. for (var i = 0; i < 32; i++) {
  2318. d = 1 << i;
  2319. if (d > value)
  2320. break;
  2321. if (value & d) {
  2322. var name = _int2name[d];
  2323. name && (o[name] = "");
  2324. }
  2325. }
  2326. _int2nameMap[value] = o;
  2327. return o;
  2328. }
  2329. static _toInt(names, _name2int) {
  2330. var words = names.split('.');
  2331. var num = 0;
  2332. for (var i = 0, n = words.length; i < n; i++) {
  2333. var value = _name2int[words[i]];
  2334. if (!value)
  2335. throw new Error("Defines to int err:" + names + "/" + words[i]);
  2336. num |= value;
  2337. }
  2338. return num;
  2339. }
  2340. }
  2341. class ShaderDefines2D extends ShaderDefinesBase {
  2342. constructor() {
  2343. super(ShaderDefines2D.__name2int, ShaderDefines2D.__int2name, ShaderDefines2D.__int2nameMap);
  2344. }
  2345. static __init__() {
  2346. ShaderDefines2D.reg("TEXTURE2D", ShaderDefines2D.TEXTURE2D);
  2347. ShaderDefines2D.reg("PRIMITIVE", ShaderDefines2D.PRIMITIVE);
  2348. ShaderDefines2D.reg("GLOW_FILTER", ShaderDefines2D.FILTERGLOW);
  2349. ShaderDefines2D.reg("BLUR_FILTER", ShaderDefines2D.FILTERBLUR);
  2350. ShaderDefines2D.reg("COLOR_FILTER", ShaderDefines2D.FILTERCOLOR);
  2351. ShaderDefines2D.reg("COLOR_ADD", ShaderDefines2D.COLORADD);
  2352. ShaderDefines2D.reg("WORLDMAT", ShaderDefines2D.WORLDMAT);
  2353. ShaderDefines2D.reg("FILLTEXTURE", ShaderDefines2D.FILLTEXTURE);
  2354. ShaderDefines2D.reg("FSHIGHPRECISION", ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION);
  2355. ShaderDefines2D.reg('MVP3D', ShaderDefines2D.MVP3D);
  2356. }
  2357. static reg(name, value) {
  2358. this._reg(name, value, ShaderDefines2D.__name2int, ShaderDefines2D.__int2name);
  2359. }
  2360. static toText(value, int2name, int2nameMap) {
  2361. return this._toText(value, int2name, int2nameMap);
  2362. }
  2363. static toInt(names) {
  2364. return this._toInt(names, ShaderDefines2D.__name2int);
  2365. }
  2366. }
  2367. ShaderDefines2D.TEXTURE2D = 0x01;
  2368. ShaderDefines2D.PRIMITIVE = 0x04;
  2369. ShaderDefines2D.FILTERGLOW = 0x08;
  2370. ShaderDefines2D.FILTERBLUR = 0x10;
  2371. ShaderDefines2D.FILTERCOLOR = 0x20;
  2372. ShaderDefines2D.COLORADD = 0x40;
  2373. ShaderDefines2D.WORLDMAT = 0x80;
  2374. ShaderDefines2D.FILLTEXTURE = 0x100;
  2375. ShaderDefines2D.SKINMESH = 0x200;
  2376. ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION = 0x400;
  2377. ShaderDefines2D.MVP3D = 0x800;
  2378. ShaderDefines2D.NOOPTMASK = ShaderDefines2D.FILTERGLOW | ShaderDefines2D.FILTERBLUR | ShaderDefines2D.FILTERCOLOR | ShaderDefines2D.FILLTEXTURE;
  2379. ShaderDefines2D.__name2int = {};
  2380. ShaderDefines2D.__int2name = [];
  2381. ShaderDefines2D.__int2nameMap = [];
  2382. class Stat {
  2383. static show(x = 0, y = 0) {
  2384. Stat._StatRender.show(x, y);
  2385. }
  2386. static enable() {
  2387. Stat._StatRender.enable();
  2388. }
  2389. static hide() {
  2390. Stat._StatRender.hide();
  2391. }
  2392. static clear() {
  2393. Stat.trianglesFaces = Stat.renderBatches = Stat.savedRenderBatches = Stat.shaderCall = Stat.spriteRenderUseCacheCount = Stat.frustumCulling = Stat.octreeNodeCulling = Stat.canvasNormal = Stat.canvasBitmap = Stat.canvasReCache = 0;
  2394. }
  2395. static set onclick(fn) {
  2396. Stat._StatRender.set_onclick(fn);
  2397. }
  2398. }
  2399. Stat.FPS = 0;
  2400. Stat.loopCount = 0;
  2401. Stat.shaderCall = 0;
  2402. Stat.renderBatches = 0;
  2403. Stat.savedRenderBatches = 0;
  2404. Stat.trianglesFaces = 0;
  2405. Stat.spriteCount = 0;
  2406. Stat.spriteRenderUseCacheCount = 0;
  2407. Stat.frustumCulling = 0;
  2408. Stat.octreeNodeCulling = 0;
  2409. Stat.canvasNormal = 0;
  2410. Stat.canvasBitmap = 0;
  2411. Stat.canvasReCache = 0;
  2412. Stat.renderSlow = false;
  2413. Stat._fpsData = [];
  2414. Stat._timer = 0;
  2415. Stat._count = 0;
  2416. Stat._StatRender = null;
  2417. class StringKey {
  2418. constructor() {
  2419. this._strsToID = {};
  2420. this._idToStrs = [];
  2421. this._length = 0;
  2422. }
  2423. add(str) {
  2424. var index = this._strsToID[str];
  2425. if (index != null)
  2426. return index;
  2427. this._idToStrs[this._length] = str;
  2428. return this._strsToID[str] = this._length++;
  2429. }
  2430. getID(str) {
  2431. var index = this._strsToID[str];
  2432. return index == null ? -1 : index;
  2433. }
  2434. getName(id) {
  2435. var str = this._idToStrs[id];
  2436. return str == null ? undefined : str;
  2437. }
  2438. }
  2439. class Shader extends BaseShader {
  2440. constructor(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2441. super();
  2442. this._attribInfo = null;
  2443. this.customCompile = false;
  2444. this._curActTexIndex = 0;
  2445. this.tag = {};
  2446. this._program = null;
  2447. this._params = null;
  2448. this._paramsMap = {};
  2449. if ((!vs) || (!ps))
  2450. throw "Shader Error";
  2451. this._attribInfo = bindAttrib;
  2452. this._id = ++Shader._count;
  2453. this._vs = vs;
  2454. this._ps = ps;
  2455. this._nameMap = nameMap ? nameMap : {};
  2456. saveName != null && (Shader.sharders[saveName] = this);
  2457. this.recreateResource();
  2458. this.lock = true;
  2459. }
  2460. static getShader(name) {
  2461. return Shader.sharders[name];
  2462. }
  2463. static create(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2464. return new Shader(vs, ps, saveName, nameMap, bindAttrib);
  2465. }
  2466. static withCompile(nameID, define, shaderName, createShader) {
  2467. if (shaderName && Shader.sharders[shaderName])
  2468. return Shader.sharders[shaderName];
  2469. var pre = Shader._preCompileShader[Shader.SHADERNAME2ID * nameID];
  2470. if (!pre)
  2471. throw new Error("withCompile shader err!" + nameID);
  2472. return pre.createShader(define, shaderName, createShader, null);
  2473. }
  2474. static withCompile2D(nameID, mainID, define, shaderName, createShader, bindAttrib = null) {
  2475. if (shaderName && Shader.sharders[shaderName])
  2476. return Shader.sharders[shaderName];
  2477. var pre = Shader._preCompileShader[Shader.SHADERNAME2ID * nameID + mainID];
  2478. if (!pre)
  2479. throw new Error("withCompile shader err!" + nameID + " " + mainID);
  2480. return pre.createShader(define, shaderName, createShader, bindAttrib);
  2481. }
  2482. static addInclude(fileName, txt) {
  2483. ILaya.ShaderCompile.addInclude(fileName, txt);
  2484. }
  2485. static preCompile(nameID, vs, ps, nameMap) {
  2486. var id = Shader.SHADERNAME2ID * nameID;
  2487. Shader._preCompileShader[id] = new ILaya.ShaderCompile(vs, ps, nameMap);
  2488. }
  2489. static preCompile2D(nameID, mainID, vs, ps, nameMap) {
  2490. var id = Shader.SHADERNAME2ID * nameID + mainID;
  2491. Shader._preCompileShader[id] = new ILaya.ShaderCompile(vs, ps, nameMap);
  2492. }
  2493. recreateResource() {
  2494. this._compile();
  2495. this._setGPUMemory(0);
  2496. }
  2497. _disposeResource() {
  2498. WebGLContext.mainContext.deleteShader(this._vshader);
  2499. WebGLContext.mainContext.deleteShader(this._pshader);
  2500. WebGLContext.mainContext.deleteProgram(this._program);
  2501. this._vshader = this._pshader = this._program = null;
  2502. this._params = null;
  2503. this._paramsMap = {};
  2504. this._setGPUMemory(0);
  2505. this._curActTexIndex = 0;
  2506. }
  2507. _compile() {
  2508. if (!this._vs || !this._ps || this._params)
  2509. return;
  2510. this._reCompile = true;
  2511. this._params = [];
  2512. var result;
  2513. if (this.customCompile)
  2514. result = ILaya.ShaderCompile.preGetParams(this._vs, this._ps);
  2515. var gl = WebGLContext.mainContext;
  2516. this._program = gl.createProgram();
  2517. this._vshader = Shader._createShader(gl, this._vs, gl.VERTEX_SHADER);
  2518. this._pshader = Shader._createShader(gl, this._ps, gl.FRAGMENT_SHADER);
  2519. gl.attachShader(this._program, this._vshader);
  2520. gl.attachShader(this._program, this._pshader);
  2521. var one, i, n, location;
  2522. var attribDescNum = this._attribInfo ? this._attribInfo.length : 0;
  2523. for (i = 0; i < attribDescNum; i += 2) {
  2524. gl.bindAttribLocation(this._program, this._attribInfo[i + 1], this._attribInfo[i]);
  2525. }
  2526. gl.linkProgram(this._program);
  2527. if (!this.customCompile && !gl.getProgramParameter(this._program, gl.LINK_STATUS)) {
  2528. throw gl.getProgramInfoLog(this._program);
  2529. }
  2530. var nUniformNum = this.customCompile ? result.uniforms.length : gl.getProgramParameter(this._program, gl.ACTIVE_UNIFORMS);
  2531. for (i = 0; i < nUniformNum; i++) {
  2532. var uniform = this.customCompile ? result.uniforms[i] : gl.getActiveUniform(this._program, i);
  2533. location = gl.getUniformLocation(this._program, uniform.name);
  2534. one = { vartype: "uniform", glfun: null, ivartype: 1, location: location, name: uniform.name, type: uniform.type, isArray: false, isSame: false, preValue: null, indexOfParams: 0 };
  2535. if (one.name.indexOf('[0]') > 0) {
  2536. one.name = one.name.substr(0, one.name.length - 3);
  2537. one.isArray = true;
  2538. one.location = gl.getUniformLocation(this._program, one.name);
  2539. }
  2540. this._params.push(one);
  2541. }
  2542. for (i = 0, n = this._params.length; i < n; i++) {
  2543. one = this._params[i];
  2544. one.indexOfParams = i;
  2545. one.index = 1;
  2546. one.value = [one.location, null];
  2547. one.codename = one.name;
  2548. one.name = this._nameMap[one.codename] ? this._nameMap[one.codename] : one.codename;
  2549. this._paramsMap[one.name] = one;
  2550. one._this = this;
  2551. one.uploadedValue = [];
  2552. switch (one.type) {
  2553. case gl.INT:
  2554. one.fun = one.isArray ? this._uniform1iv : this._uniform1i;
  2555. break;
  2556. case gl.FLOAT:
  2557. one.fun = one.isArray ? this._uniform1fv : this._uniform1f;
  2558. break;
  2559. case gl.FLOAT_VEC2:
  2560. one.fun = one.isArray ? this._uniform_vec2v : this._uniform_vec2;
  2561. break;
  2562. case gl.FLOAT_VEC3:
  2563. one.fun = one.isArray ? this._uniform_vec3v : this._uniform_vec3;
  2564. break;
  2565. case gl.FLOAT_VEC4:
  2566. one.fun = one.isArray ? this._uniform_vec4v : this._uniform_vec4;
  2567. break;
  2568. case gl.SAMPLER_2D:
  2569. one.fun = this._uniform_sampler2D;
  2570. break;
  2571. case gl.SAMPLER_CUBE:
  2572. one.fun = this._uniform_samplerCube;
  2573. break;
  2574. case gl.FLOAT_MAT4:
  2575. one.glfun = gl.uniformMatrix4fv;
  2576. one.fun = this._uniformMatrix4fv;
  2577. break;
  2578. case gl.BOOL:
  2579. one.fun = this._uniform1i;
  2580. break;
  2581. case gl.FLOAT_MAT2:
  2582. case gl.FLOAT_MAT3:
  2583. throw new Error("compile shader err!");
  2584. default:
  2585. throw new Error("compile shader err!");
  2586. }
  2587. }
  2588. }
  2589. static _createShader(gl, str, type) {
  2590. var shader = gl.createShader(type);
  2591. gl.shaderSource(shader, str);
  2592. gl.compileShader(shader);
  2593. if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  2594. return shader;
  2595. }
  2596. else {
  2597. console.log(gl.getShaderInfoLog(shader));
  2598. return null;
  2599. }
  2600. }
  2601. getUniform(name) {
  2602. return this._paramsMap[name];
  2603. }
  2604. _uniform1f(one, value) {
  2605. var uploadedValue = one.uploadedValue;
  2606. if (uploadedValue[0] !== value) {
  2607. WebGLContext.mainContext.uniform1f(one.location, uploadedValue[0] = value);
  2608. return 1;
  2609. }
  2610. return 0;
  2611. }
  2612. _uniform1fv(one, value) {
  2613. if (value.length < 4) {
  2614. var uploadedValue = one.uploadedValue;
  2615. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2616. WebGLContext.mainContext.uniform1fv(one.location, value);
  2617. uploadedValue[0] = value[0];
  2618. uploadedValue[1] = value[1];
  2619. uploadedValue[2] = value[2];
  2620. uploadedValue[3] = value[3];
  2621. return 1;
  2622. }
  2623. return 0;
  2624. }
  2625. else {
  2626. WebGLContext.mainContext.uniform1fv(one.location, value);
  2627. return 1;
  2628. }
  2629. }
  2630. _uniform_vec2(one, value) {
  2631. var uploadedValue = one.uploadedValue;
  2632. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  2633. WebGLContext.mainContext.uniform2f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  2634. return 1;
  2635. }
  2636. return 0;
  2637. }
  2638. _uniform_vec2v(one, value) {
  2639. if (value.length < 2) {
  2640. var uploadedValue = one.uploadedValue;
  2641. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2642. WebGLContext.mainContext.uniform2fv(one.location, value);
  2643. uploadedValue[0] = value[0];
  2644. uploadedValue[1] = value[1];
  2645. uploadedValue[2] = value[2];
  2646. uploadedValue[3] = value[3];
  2647. return 1;
  2648. }
  2649. return 0;
  2650. }
  2651. else {
  2652. WebGLContext.mainContext.uniform2fv(one.location, value);
  2653. return 1;
  2654. }
  2655. }
  2656. _uniform_vec3(one, value) {
  2657. var uploadedValue = one.uploadedValue;
  2658. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  2659. WebGLContext.mainContext.uniform3f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  2660. return 1;
  2661. }
  2662. return 0;
  2663. }
  2664. _uniform_vec3v(one, value) {
  2665. WebGLContext.mainContext.uniform3fv(one.location, value);
  2666. return 1;
  2667. }
  2668. _uniform_vec4(one, value) {
  2669. var uploadedValue = one.uploadedValue;
  2670. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  2671. WebGLContext.mainContext.uniform4f(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  2672. return 1;
  2673. }
  2674. return 0;
  2675. }
  2676. _uniform_vec4v(one, value) {
  2677. WebGLContext.mainContext.uniform4fv(one.location, value);
  2678. return 1;
  2679. }
  2680. _uniformMatrix2fv(one, value) {
  2681. WebGLContext.mainContext.uniformMatrix2fv(one.location, false, value);
  2682. return 1;
  2683. }
  2684. _uniformMatrix3fv(one, value) {
  2685. WebGLContext.mainContext.uniformMatrix3fv(one.location, false, value);
  2686. return 1;
  2687. }
  2688. _uniformMatrix4fv(one, value) {
  2689. WebGLContext.mainContext.uniformMatrix4fv(one.location, false, value);
  2690. return 1;
  2691. }
  2692. _uniform1i(one, value) {
  2693. var uploadedValue = one.uploadedValue;
  2694. if (uploadedValue[0] !== value) {
  2695. WebGLContext.mainContext.uniform1i(one.location, uploadedValue[0] = value);
  2696. return 1;
  2697. }
  2698. return 0;
  2699. }
  2700. _uniform1iv(one, value) {
  2701. WebGLContext.mainContext.uniform1iv(one.location, value);
  2702. return 1;
  2703. }
  2704. _uniform_ivec2(one, value) {
  2705. var uploadedValue = one.uploadedValue;
  2706. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  2707. WebGLContext.mainContext.uniform2i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  2708. return 1;
  2709. }
  2710. return 0;
  2711. }
  2712. _uniform_ivec2v(one, value) {
  2713. WebGLContext.mainContext.uniform2iv(one.location, value);
  2714. return 1;
  2715. }
  2716. _uniform_vec3i(one, value) {
  2717. var uploadedValue = one.uploadedValue;
  2718. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  2719. WebGLContext.mainContext.uniform3i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  2720. return 1;
  2721. }
  2722. return 0;
  2723. }
  2724. _uniform_vec3vi(one, value) {
  2725. WebGLContext.mainContext.uniform3iv(one.location, value);
  2726. return 1;
  2727. }
  2728. _uniform_vec4i(one, value) {
  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.uniform4i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  2732. return 1;
  2733. }
  2734. return 0;
  2735. }
  2736. _uniform_vec4vi(one, value) {
  2737. WebGLContext.mainContext.uniform4iv(one.location, value);
  2738. return 1;
  2739. }
  2740. _uniform_sampler2D(one, value) {
  2741. var gl = WebGLContext.mainContext;
  2742. var uploadedValue = one.uploadedValue;
  2743. if (uploadedValue[0] == null) {
  2744. uploadedValue[0] = this._curActTexIndex;
  2745. gl.uniform1i(one.location, this._curActTexIndex);
  2746. WebGLContext.activeTexture(gl, gl.TEXTURE0 + this._curActTexIndex);
  2747. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  2748. this._curActTexIndex++;
  2749. return 1;
  2750. }
  2751. else {
  2752. WebGLContext.activeTexture(gl, gl.TEXTURE0 + uploadedValue[0]);
  2753. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  2754. return 0;
  2755. }
  2756. }
  2757. _uniform_samplerCube(one, value) {
  2758. var gl = WebGLContext.mainContext;
  2759. var uploadedValue = one.uploadedValue;
  2760. if (uploadedValue[0] == null) {
  2761. uploadedValue[0] = this._curActTexIndex;
  2762. gl.uniform1i(one.location, this._curActTexIndex);
  2763. WebGLContext.activeTexture(gl, gl.TEXTURE0 + this._curActTexIndex);
  2764. WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  2765. this._curActTexIndex++;
  2766. return 1;
  2767. }
  2768. else {
  2769. WebGLContext.activeTexture(gl, gl.TEXTURE0 + uploadedValue[0]);
  2770. WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  2771. return 0;
  2772. }
  2773. }
  2774. _noSetValue(one) {
  2775. console.log("no....:" + one.name);
  2776. }
  2777. uploadOne(name, value) {
  2778. WebGLContext.useProgram(WebGLContext.mainContext, this._program);
  2779. var one = this._paramsMap[name];
  2780. one.fun.call(this, one, value);
  2781. }
  2782. uploadTexture2D(value) {
  2783. var CTX = WebGLContext;
  2784. if (CTX._activeTextures[0] !== value) {
  2785. CTX.bindTexture(WebGLContext.mainContext, LayaGL.instance.TEXTURE_2D, value);
  2786. CTX._activeTextures[0] = value;
  2787. }
  2788. }
  2789. upload(shaderValue, params = null) {
  2790. BaseShader.activeShader = BaseShader.bindShader = this;
  2791. var gl = WebGLContext.mainContext;
  2792. WebGLContext.useProgram(gl, this._program);
  2793. if (this._reCompile) {
  2794. params = this._params;
  2795. this._reCompile = false;
  2796. }
  2797. else {
  2798. params = params || this._params;
  2799. }
  2800. var one, value, n = params.length, shaderCall = 0;
  2801. for (var i = 0; i < n; i++) {
  2802. one = params[i];
  2803. if ((value = shaderValue[one.name]) !== null)
  2804. shaderCall += one.fun.call(this, one, value);
  2805. }
  2806. Stat.shaderCall += shaderCall;
  2807. }
  2808. uploadArray(shaderValue, length, _bufferUsage) {
  2809. BaseShader.activeShader = this;
  2810. BaseShader.bindShader = this;
  2811. WebGLContext.useProgram(WebGLContext.mainContext, this._program);
  2812. var params = this._params, value;
  2813. var one, shaderCall = 0;
  2814. for (var i = length - 2; i >= 0; i -= 2) {
  2815. one = this._paramsMap[shaderValue[i]];
  2816. if (!one)
  2817. continue;
  2818. value = shaderValue[i + 1];
  2819. if (value != null) {
  2820. _bufferUsage && _bufferUsage[one.name] && _bufferUsage[one.name].bind();
  2821. shaderCall += one.fun.call(this, one, value);
  2822. }
  2823. }
  2824. Stat.shaderCall += shaderCall;
  2825. }
  2826. getParams() {
  2827. return this._params;
  2828. }
  2829. setAttributesLocation(attribDesc) {
  2830. this._attribInfo = attribDesc;
  2831. }
  2832. }
  2833. Shader._count = 0;
  2834. Shader._preCompileShader = {};
  2835. Shader.SHADERNAME2ID = 0.0002;
  2836. Shader.nameKey = new StringKey();
  2837. Shader.sharders = new Array(0x20);
  2838. class Shader2X extends Shader {
  2839. constructor(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2840. super(vs, ps, saveName, nameMap, bindAttrib);
  2841. this._params2dQuick2 = null;
  2842. this._shaderValueWidth = 0;
  2843. this._shaderValueHeight = 0;
  2844. }
  2845. _disposeResource() {
  2846. super._disposeResource();
  2847. this._params2dQuick2 = null;
  2848. }
  2849. upload2dQuick2(shaderValue) {
  2850. this.upload(shaderValue, this._params2dQuick2 || this._make2dQuick2());
  2851. }
  2852. _make2dQuick2() {
  2853. if (!this._params2dQuick2) {
  2854. this._params2dQuick2 = [];
  2855. var params = this._params, one;
  2856. for (var i = 0, n = params.length; i < n; i++) {
  2857. one = params[i];
  2858. if (one.name !== "size")
  2859. this._params2dQuick2.push(one);
  2860. }
  2861. }
  2862. return this._params2dQuick2;
  2863. }
  2864. static create(vs, ps, saveName = null, nameMap = null, bindAttrib = null) {
  2865. return new Shader2X(vs, ps, saveName, nameMap, bindAttrib);
  2866. }
  2867. }
  2868. class Value2D {
  2869. constructor(mainID, subID) {
  2870. this.defines = new ShaderDefines2D();
  2871. this.size = [0, 0];
  2872. this.alpha = 1.0;
  2873. this.ALPHA = 1.0;
  2874. this.subID = 0;
  2875. this.ref = 1;
  2876. this._cacheID = 0;
  2877. this.clipMatDir = [ILaya.Context._MAXSIZE, 0, 0, ILaya.Context._MAXSIZE];
  2878. this.clipMatPos = [0, 0];
  2879. this.clipOff = [0, 0];
  2880. this.mainID = mainID;
  2881. this.subID = subID;
  2882. this.textureHost = null;
  2883. this.texture = null;
  2884. this.color = null;
  2885. this.colorAdd = null;
  2886. this.u_mmat2 = null;
  2887. this._cacheID = mainID | subID;
  2888. this._inClassCache = Value2D._cache[this._cacheID];
  2889. if (mainID > 0 && !this._inClassCache) {
  2890. this._inClassCache = Value2D._cache[this._cacheID] = [];
  2891. this._inClassCache._length = 0;
  2892. }
  2893. this.clear();
  2894. }
  2895. static _initone(type, classT) {
  2896. Value2D._typeClass[type] = classT;
  2897. Value2D._cache[type] = [];
  2898. Value2D._cache[type]._length = 0;
  2899. }
  2900. static __init__() {
  2901. }
  2902. setValue(value) { }
  2903. _ShaderWithCompile() {
  2904. var ret = Shader.withCompile2D(0, this.mainID, this.defines.toNameDic(), this.mainID | this.defines._value, Shader2X.create, this._attribLocation);
  2905. return ret;
  2906. }
  2907. upload() {
  2908. var renderstate2d = RenderState2D;
  2909. RenderState2D.worldMatrix4 === RenderState2D.TEMPMAT4_ARRAY || this.defines.addInt(ShaderDefines2D.WORLDMAT);
  2910. this.mmat = renderstate2d.worldMatrix4;
  2911. if (RenderState2D.matWVP) {
  2912. this.defines.addInt(ShaderDefines2D.MVP3D);
  2913. this.u_MvpMatrix = RenderState2D.matWVP.elements;
  2914. }
  2915. var sd = Shader.sharders[this.mainID | this.defines._value] || this._ShaderWithCompile();
  2916. if (sd._shaderValueWidth !== renderstate2d.width || sd._shaderValueHeight !== renderstate2d.height) {
  2917. this.size[0] = renderstate2d.width;
  2918. this.size[1] = renderstate2d.height;
  2919. sd._shaderValueWidth = renderstate2d.width;
  2920. sd._shaderValueHeight = renderstate2d.height;
  2921. sd.upload(this, null);
  2922. }
  2923. else {
  2924. sd.upload(this, sd._params2dQuick2 || sd._make2dQuick2());
  2925. }
  2926. }
  2927. setFilters(value) {
  2928. this.filters = value;
  2929. if (!value)
  2930. return;
  2931. var n = value.length, f;
  2932. for (var i = 0; i < n; i++) {
  2933. f = value[i];
  2934. if (f) {
  2935. this.defines.add(f.type);
  2936. f.action.setValue(this);
  2937. }
  2938. }
  2939. }
  2940. clear() {
  2941. this.defines._value = this.subID + (ILaya.WebGL.shaderHighPrecision ? ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION : 0);
  2942. this.clipOff[0] = 0;
  2943. }
  2944. release() {
  2945. if ((--this.ref) < 1) {
  2946. this._inClassCache && (this._inClassCache[this._inClassCache._length++] = this);
  2947. this.clear();
  2948. this.filters = null;
  2949. this.ref = 1;
  2950. this.clipOff[0] = 0;
  2951. }
  2952. }
  2953. static create(mainType, subType) {
  2954. var types = Value2D._cache[mainType | subType];
  2955. if (types._length)
  2956. return types[--types._length];
  2957. else
  2958. return new Value2D._typeClass[mainType | subType](subType);
  2959. }
  2960. }
  2961. Value2D._cache = [];
  2962. Value2D._typeClass = [];
  2963. Value2D.TEMPMAT4_ARRAY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  2964. class SubmitKey {
  2965. constructor() {
  2966. this.clear();
  2967. }
  2968. clear() {
  2969. this.submitType = -1;
  2970. this.blendShader = this.other = 0;
  2971. }
  2972. copyFrom(src) {
  2973. this.other = src.other;
  2974. this.blendShader = src.blendShader;
  2975. this.submitType = src.submitType;
  2976. }
  2977. copyFrom2(src, submitType, other) {
  2978. this.other = other;
  2979. this.submitType = submitType;
  2980. }
  2981. equal3_2(next, submitType, other) {
  2982. return this.submitType === submitType && this.other === other && this.blendShader === next.blendShader;
  2983. }
  2984. equal4_2(next, submitType, other) {
  2985. return this.submitType === submitType && this.other === other && this.blendShader === next.blendShader;
  2986. }
  2987. equal_3(next) {
  2988. return this.submitType === next.submitType && this.blendShader === next.blendShader;
  2989. }
  2990. equal(next) {
  2991. return this.other === next.other && this.submitType === next.submitType && this.blendShader === next.blendShader;
  2992. }
  2993. }
  2994. class SubmitCMD {
  2995. constructor() {
  2996. this._ref = 1;
  2997. this._key = new SubmitKey();
  2998. }
  2999. renderSubmit() {
  3000. this.fun.apply(this._this, this.args);
  3001. return 1;
  3002. }
  3003. getRenderType() {
  3004. return 0;
  3005. }
  3006. releaseRender() {
  3007. if ((--this._ref) < 1) {
  3008. var pool = SubmitCMD.POOL;
  3009. pool[pool._length++] = this;
  3010. }
  3011. }
  3012. static create(args, fun, thisobj) {
  3013. var o = SubmitCMD.POOL._length ? SubmitCMD.POOL[--SubmitCMD.POOL._length] : new SubmitCMD();
  3014. o.fun = fun;
  3015. o.args = args;
  3016. o._this = thisobj;
  3017. o._ref = 1;
  3018. o._key.clear();
  3019. return o;
  3020. }
  3021. }
  3022. SubmitCMD.POOL = [];
  3023. {
  3024. SubmitCMD.POOL._length = 0;
  3025. }
  3026. class Filter {
  3027. constructor() { }
  3028. get type() { return -1; }
  3029. }
  3030. Filter.BLUR = 0x10;
  3031. Filter.COLOR = 0x20;
  3032. Filter.GLOW = 0x08;
  3033. Filter._filter = function (sprite, context, x, y) {
  3034. var webglctx = context;
  3035. var next = this._next;
  3036. if (next) {
  3037. var filters = sprite.filters, len = filters.length;
  3038. if (len == 1 && (filters[0].type == Filter.COLOR)) {
  3039. context.save();
  3040. context.setColorFilter(filters[0]);
  3041. next._fun.call(next, sprite, context, x, y);
  3042. context.restore();
  3043. return;
  3044. }
  3045. var svCP = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  3046. var b;
  3047. var p = Point.TEMP;
  3048. var tMatrix = webglctx._curMat;
  3049. var mat = Matrix.create();
  3050. tMatrix.copyTo(mat);
  3051. var tPadding = 0;
  3052. var tHalfPadding = 0;
  3053. var tIsHaveGlowFilter = false;
  3054. var source = null;
  3055. var out = sprite._cacheStyle.filterCache || null;
  3056. if (!out || sprite.getRepaint() != 0) {
  3057. tIsHaveGlowFilter = sprite._isHaveGlowFilter();
  3058. if (tIsHaveGlowFilter) {
  3059. tPadding = 50;
  3060. tHalfPadding = 25;
  3061. }
  3062. b = new Rectangle();
  3063. b.copyFrom(sprite.getSelfBounds());
  3064. b.x += sprite.x;
  3065. b.y += sprite.y;
  3066. b.x -= sprite.pivotX + 4;
  3067. b.y -= sprite.pivotY + 4;
  3068. var tSX = b.x;
  3069. var tSY = b.y;
  3070. b.width += (tPadding + 8);
  3071. b.height += (tPadding + 8);
  3072. p.x = b.x * mat.a + b.y * mat.c;
  3073. p.y = b.y * mat.d + b.x * mat.b;
  3074. b.x = p.x;
  3075. b.y = p.y;
  3076. p.x = b.width * mat.a + b.height * mat.c;
  3077. p.y = b.height * mat.d + b.width * mat.b;
  3078. b.width = p.x;
  3079. b.height = p.y;
  3080. if (b.width <= 0 || b.height <= 0) {
  3081. return;
  3082. }
  3083. out && WebGLRTMgr.releaseRT(out);
  3084. source = WebGLRTMgr.getRT(b.width, b.height);
  3085. var outRT = out = WebGLRTMgr.getRT(b.width, b.height);
  3086. sprite._getCacheStyle().filterCache = out;
  3087. webglctx.pushRT();
  3088. webglctx.useRT(source);
  3089. var tX = sprite.x - tSX + tHalfPadding;
  3090. var tY = sprite.y - tSY + tHalfPadding;
  3091. next._fun.call(next, sprite, context, tX, tY);
  3092. webglctx.useRT(outRT);
  3093. for (var i = 0; i < len; i++) {
  3094. if (i != 0) {
  3095. webglctx.useRT(source);
  3096. webglctx.drawTarget(outRT, 0, 0, b.width, b.height, Matrix.TEMP.identity(), svCP, null, BlendMode.TOINT.overlay);
  3097. webglctx.useRT(outRT);
  3098. }
  3099. var fil = filters[i];
  3100. switch (fil.type) {
  3101. case Filter.BLUR:
  3102. fil._glRender && fil._glRender.render(source, context, b.width, b.height, fil);
  3103. break;
  3104. case Filter.GLOW:
  3105. fil._glRender && fil._glRender.render(source, context, b.width, b.height, fil);
  3106. break;
  3107. case Filter.COLOR:
  3108. webglctx.setColorFilter(fil);
  3109. webglctx.drawTarget(source, 0, 0, b.width, b.height, Matrix.EMPTY.identity(), Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  3110. webglctx.setColorFilter(null);
  3111. break;
  3112. }
  3113. }
  3114. webglctx.popRT();
  3115. }
  3116. else {
  3117. tIsHaveGlowFilter = sprite._cacheStyle.hasGlowFilter || false;
  3118. if (tIsHaveGlowFilter) {
  3119. tPadding = 50;
  3120. tHalfPadding = 25;
  3121. }
  3122. b = sprite.getBounds();
  3123. if (b.width <= 0 || b.height <= 0) {
  3124. return;
  3125. }
  3126. b.width += tPadding;
  3127. b.height += tPadding;
  3128. p.x = b.x * mat.a + b.y * mat.c;
  3129. p.y = b.y * mat.d + b.x * mat.b;
  3130. b.x = p.x;
  3131. b.y = p.y;
  3132. p.x = b.width * mat.a + b.height * mat.c;
  3133. p.y = b.height * mat.d + b.width * mat.b;
  3134. b.width = p.x;
  3135. b.height = p.y;
  3136. }
  3137. x = x - tHalfPadding - sprite.x;
  3138. y = y - tHalfPadding - sprite.y;
  3139. p.setTo(x, y);
  3140. mat.transformPoint(p);
  3141. x = p.x + b.x;
  3142. y = p.y + b.y;
  3143. webglctx._drawRenderTexture(out, x, y, b.width, b.height, Matrix.TEMP.identity(), 1.0, RenderTexture2D.defuv);
  3144. if (source) {
  3145. var submit = SubmitCMD.create([source], function (s) {
  3146. s.destroy();
  3147. }, this);
  3148. source = null;
  3149. context.addRenderObject(submit);
  3150. }
  3151. mat.destroy();
  3152. }
  3153. };
  3154. class Utils {
  3155. static toRadian(angle) {
  3156. return angle * Utils._pi2;
  3157. }
  3158. static toAngle(radian) {
  3159. return radian * Utils._pi;
  3160. }
  3161. static toHexColor(color) {
  3162. if (color < 0 || isNaN(color))
  3163. return null;
  3164. var str = color.toString(16);
  3165. while (str.length < 6)
  3166. str = "0" + str;
  3167. return "#" + str;
  3168. }
  3169. static getGID() {
  3170. return Utils._gid++;
  3171. }
  3172. static concatArray(source, array) {
  3173. if (!array)
  3174. return source;
  3175. if (!source)
  3176. return array;
  3177. var i, len = array.length;
  3178. for (i = 0; i < len; i++) {
  3179. source.push(array[i]);
  3180. }
  3181. return source;
  3182. }
  3183. static clearArray(array) {
  3184. if (!array)
  3185. return array;
  3186. array.length = 0;
  3187. return array;
  3188. }
  3189. static copyArray(source, array) {
  3190. source || (source = []);
  3191. if (!array)
  3192. return source;
  3193. source.length = array.length;
  3194. var i, len = array.length;
  3195. for (i = 0; i < len; i++) {
  3196. source[i] = array[i];
  3197. }
  3198. return source;
  3199. }
  3200. static getGlobalRecByPoints(sprite, x0, y0, x1, y1) {
  3201. var newLTPoint;
  3202. newLTPoint = Point.create().setTo(x0, y0);
  3203. newLTPoint = sprite.localToGlobal(newLTPoint);
  3204. var newRBPoint;
  3205. newRBPoint = Point.create().setTo(x1, y1);
  3206. newRBPoint = sprite.localToGlobal(newRBPoint);
  3207. var rst = Rectangle._getWrapRec([newLTPoint.x, newLTPoint.y, newRBPoint.x, newRBPoint.y]);
  3208. newLTPoint.recover();
  3209. newRBPoint.recover();
  3210. return rst;
  3211. }
  3212. static getGlobalPosAndScale(sprite) {
  3213. return Utils.getGlobalRecByPoints(sprite, 0, 0, 1, 1);
  3214. }
  3215. static bind(fun, scope) {
  3216. var rst = fun;
  3217. rst = fun.bind(scope);
  3218. return rst;
  3219. }
  3220. static updateOrder(array) {
  3221. if (!array || array.length < 2)
  3222. return false;
  3223. var i = 1, j, len = array.length, key, c;
  3224. while (i < len) {
  3225. j = i;
  3226. c = array[j];
  3227. key = array[j]._zOrder;
  3228. while (--j > -1) {
  3229. if (array[j]._zOrder > key)
  3230. array[j + 1] = array[j];
  3231. else
  3232. break;
  3233. }
  3234. array[j + 1] = c;
  3235. i++;
  3236. }
  3237. return true;
  3238. }
  3239. static transPointList(points, x, y) {
  3240. var i, len = points.length;
  3241. for (i = 0; i < len; i += 2) {
  3242. points[i] += x;
  3243. points[i + 1] += y;
  3244. }
  3245. }
  3246. static parseInt(str, radix = 0) {
  3247. var result = parseInt(str, radix);
  3248. if (isNaN(result))
  3249. return 0;
  3250. return result;
  3251. }
  3252. static getFileExtension(path) {
  3253. Utils._extReg.lastIndex = path.lastIndexOf(".");
  3254. var result = Utils._extReg.exec(path);
  3255. if (result && result.length > 1) {
  3256. return result[1].toLowerCase();
  3257. }
  3258. return null;
  3259. }
  3260. static getTransformRelativeToWindow(coordinateSpace, x, y) {
  3261. var stage = Utils.gStage;
  3262. var globalTransform = Utils.getGlobalPosAndScale(coordinateSpace);
  3263. var canvasMatrix = stage._canvasTransform.clone();
  3264. var canvasLeft = canvasMatrix.tx;
  3265. var canvasTop = canvasMatrix.ty;
  3266. canvasMatrix.rotate(-Math.PI / 180 * stage.canvasDegree);
  3267. canvasMatrix.scale(stage.clientScaleX, stage.clientScaleY);
  3268. var perpendicular = (stage.canvasDegree % 180 != 0);
  3269. var tx, ty;
  3270. if (perpendicular) {
  3271. tx = y + globalTransform.y;
  3272. ty = x + globalTransform.x;
  3273. tx *= canvasMatrix.d;
  3274. ty *= canvasMatrix.a;
  3275. if (stage.canvasDegree == 90) {
  3276. tx = canvasLeft - tx;
  3277. ty += canvasTop;
  3278. }
  3279. else {
  3280. tx += canvasLeft;
  3281. ty = canvasTop - ty;
  3282. }
  3283. }
  3284. else {
  3285. tx = x + globalTransform.x;
  3286. ty = y + globalTransform.y;
  3287. tx *= canvasMatrix.a;
  3288. ty *= canvasMatrix.d;
  3289. tx += canvasLeft;
  3290. ty += canvasTop;
  3291. }
  3292. ty += stage['_safariOffsetY'];
  3293. var domScaleX, domScaleY;
  3294. if (perpendicular) {
  3295. domScaleX = canvasMatrix.d * globalTransform.height;
  3296. domScaleY = canvasMatrix.a * globalTransform.width;
  3297. }
  3298. else {
  3299. domScaleX = canvasMatrix.a * globalTransform.width;
  3300. domScaleY = canvasMatrix.d * globalTransform.height;
  3301. }
  3302. return { x: tx, y: ty, scaleX: domScaleX, scaleY: domScaleY };
  3303. }
  3304. static fitDOMElementInArea(dom, coordinateSpace, x, y, width, height) {
  3305. if (!dom._fitLayaAirInitialized) {
  3306. dom._fitLayaAirInitialized = true;
  3307. dom.style.transformOrigin = dom.style.webKittransformOrigin = "left top";
  3308. dom.style.position = "absolute";
  3309. }
  3310. var transform = Utils.getTransformRelativeToWindow(coordinateSpace, x, y);
  3311. dom.style.transform = dom.style.webkitTransform = "scale(" + transform.scaleX + "," + transform.scaleY + ") rotate(" + (Utils.gStage.canvasDegree) + "deg)";
  3312. dom.style.width = width + 'px';
  3313. dom.style.height = height + 'px';
  3314. dom.style.left = transform.x + 'px';
  3315. dom.style.top = transform.y + 'px';
  3316. }
  3317. static isOkTextureList(textureList) {
  3318. if (!textureList)
  3319. return false;
  3320. var i, len = textureList.length;
  3321. var tTexture;
  3322. for (i = 0; i < len; i++) {
  3323. tTexture = textureList[i];
  3324. if (!tTexture || !tTexture._getSource())
  3325. return false;
  3326. }
  3327. return true;
  3328. }
  3329. static isOKCmdList(cmds) {
  3330. if (!cmds)
  3331. return false;
  3332. var i, len = cmds.length;
  3333. var cmd;
  3334. for (i = 0; i < len; i++) {
  3335. cmd = cmds[i];
  3336. }
  3337. return true;
  3338. }
  3339. static getQueryString(name) {
  3340. if (ILaya.Browser.onMiniGame)
  3341. return null;
  3342. if (!window.location || !window.location.search)
  3343. return null;
  3344. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  3345. var r = window.location.search.substr(1).match(reg);
  3346. if (r != null)
  3347. return unescape(r[2]);
  3348. return null;
  3349. }
  3350. }
  3351. Utils.gStage = null;
  3352. Utils._gid = 1;
  3353. Utils._pi = 180 / Math.PI;
  3354. Utils._pi2 = Math.PI / 180;
  3355. Utils._extReg = /\.(\w+)\??/g;
  3356. Utils.parseXMLFromString = function (value) {
  3357. var rst;
  3358. value = value.replace(/>\s+</g, '><');
  3359. rst = (new DOMParser()).parseFromString(value, 'text/xml');
  3360. if (rst.firstChild.textContent.indexOf("This page contains the following errors") > -1) {
  3361. throw new Error(rst.firstChild.firstChild.textContent);
  3362. }
  3363. return rst;
  3364. };
  3365. class ColorUtils {
  3366. constructor(value) {
  3367. this.arrColor = [];
  3368. if (value == null) {
  3369. this.strColor = "#00000000";
  3370. this.numColor = 0;
  3371. this.arrColor = [0, 0, 0, 0];
  3372. return;
  3373. }
  3374. var i, len;
  3375. var color;
  3376. if (typeof (value) == 'string') {
  3377. if (value.indexOf("rgba(") >= 0 || value.indexOf("rgb(") >= 0) {
  3378. var tStr = value;
  3379. var beginI, endI;
  3380. beginI = tStr.indexOf("(");
  3381. endI = tStr.indexOf(")");
  3382. tStr = tStr.substring(beginI + 1, endI);
  3383. this.arrColor = tStr.split(",");
  3384. len = this.arrColor.length;
  3385. for (i = 0; i < len; i++) {
  3386. this.arrColor[i] = parseFloat(this.arrColor[i]);
  3387. if (i < 3) {
  3388. this.arrColor[i] = Math.round(this.arrColor[i]);
  3389. }
  3390. }
  3391. if (this.arrColor.length == 4) {
  3392. color = ((this.arrColor[0] * 256 + this.arrColor[1]) * 256 + this.arrColor[2]) * 256 + Math.round(this.arrColor[3] * 255);
  3393. }
  3394. else {
  3395. color = ((this.arrColor[0] * 256 + this.arrColor[1]) * 256 + this.arrColor[2]);
  3396. }
  3397. this.strColor = value;
  3398. }
  3399. else {
  3400. this.strColor = value;
  3401. value.charAt(0) === '#' && (value = value.substr(1));
  3402. len = value.length;
  3403. if (len === 3 || len === 4) {
  3404. var temp = "";
  3405. for (i = 0; i < len; i++) {
  3406. temp += (value[i] + value[i]);
  3407. }
  3408. value = temp;
  3409. }
  3410. color = parseInt(value, 16);
  3411. }
  3412. }
  3413. else {
  3414. color = value;
  3415. this.strColor = Utils.toHexColor(color);
  3416. }
  3417. if (this.strColor.indexOf("rgba") >= 0 || this.strColor.length === 9) {
  3418. this.arrColor = [((0xFF000000 & color) >>> 24) / 255, ((0xFF0000 & color) >> 16) / 255, ((0xFF00 & color) >> 8) / 255, (0xFF & color) / 255];
  3419. this.numColor = (0xff000000 & color) >>> 24 | (color & 0xff0000) >> 8 | (color & 0x00ff00) << 8 | ((color & 0xff) << 24);
  3420. }
  3421. else {
  3422. this.arrColor = [((0xFF0000 & color) >> 16) / 255, ((0xFF00 & color) >> 8) / 255, (0xFF & color) / 255, 1];
  3423. this.numColor = 0xff000000 | (color & 0xff0000) >> 16 | (color & 0x00ff00) | (color & 0xff) << 16;
  3424. }
  3425. this.arrColor.__id = ++ColorUtils._COLODID;
  3426. }
  3427. static _initDefault() {
  3428. ColorUtils._DEFAULT = {};
  3429. for (var i in ColorUtils._COLOR_MAP)
  3430. ColorUtils._SAVE[i] = ColorUtils._DEFAULT[i] = new ColorUtils(ColorUtils._COLOR_MAP[i]);
  3431. return ColorUtils._DEFAULT;
  3432. }
  3433. static _initSaveMap() {
  3434. ColorUtils._SAVE_SIZE = 0;
  3435. ColorUtils._SAVE = {};
  3436. for (var i in ColorUtils._DEFAULT)
  3437. ColorUtils._SAVE[i] = ColorUtils._DEFAULT[i];
  3438. }
  3439. static create(value) {
  3440. var key = value + "";
  3441. var color = ColorUtils._SAVE[key];
  3442. if (color != null)
  3443. return color;
  3444. if (ColorUtils._SAVE_SIZE < 1000)
  3445. ColorUtils._initSaveMap();
  3446. return ColorUtils._SAVE[key] = new ColorUtils(value);
  3447. }
  3448. }
  3449. ColorUtils._SAVE = {};
  3450. ColorUtils._SAVE_SIZE = 0;
  3451. ColorUtils._COLOR_MAP = { "purple": "#800080", "orange": "#ffa500", "white": '#FFFFFF', "red": '#FF0000', "green": '#00FF00', "blue": '#0000FF', "black": '#000000', "yellow": '#FFFF00', 'gray': '#808080' };
  3452. ColorUtils._DEFAULT = ColorUtils._initDefault();
  3453. ColorUtils._COLODID = 1;
  3454. class ColorFilter extends Filter {
  3455. constructor(mat = null) {
  3456. super();
  3457. if (!mat)
  3458. mat = this._copyMatrix(ColorFilter.IDENTITY_MATRIX);
  3459. this._mat = new Float32Array(16);
  3460. this._alpha = new Float32Array(4);
  3461. this.setByMatrix(mat);
  3462. }
  3463. gray() {
  3464. return this.setByMatrix(ColorFilter.GRAY_MATRIX);
  3465. }
  3466. color(red = 0, green = 0, blue = 0, alpha = 1) {
  3467. return this.setByMatrix([1, 0, 0, 0, red, 0, 1, 0, 0, green, 0, 0, 1, 0, blue, 0, 0, 0, 1, alpha]);
  3468. }
  3469. setColor(color) {
  3470. var arr = ColorUtils.create(color).arrColor;
  3471. 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];
  3472. return this.setByMatrix(mt);
  3473. }
  3474. setByMatrix(matrix) {
  3475. if (this._matrix != matrix)
  3476. this._copyMatrix(matrix);
  3477. var j = 0;
  3478. var z = 0;
  3479. for (var i = 0; i < 20; i++) {
  3480. if (i % 5 != 4) {
  3481. this._mat[j++] = matrix[i];
  3482. }
  3483. else {
  3484. this._alpha[z++] = matrix[i];
  3485. }
  3486. }
  3487. return this;
  3488. }
  3489. get type() {
  3490. return Filter.COLOR;
  3491. }
  3492. adjustColor(brightness, contrast, saturation, hue) {
  3493. this.adjustHue(hue);
  3494. this.adjustContrast(contrast);
  3495. this.adjustBrightness(brightness);
  3496. this.adjustSaturation(saturation);
  3497. return this;
  3498. }
  3499. adjustBrightness(brightness) {
  3500. brightness = this._clampValue(brightness, 100);
  3501. if (brightness == 0 || isNaN(brightness))
  3502. return this;
  3503. 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]);
  3504. }
  3505. adjustContrast(contrast) {
  3506. contrast = this._clampValue(contrast, 100);
  3507. if (contrast == 0 || isNaN(contrast))
  3508. return this;
  3509. var x;
  3510. if (contrast < 0) {
  3511. x = 127 + contrast / 100 * 127;
  3512. }
  3513. else {
  3514. x = contrast % 1;
  3515. if (x == 0) {
  3516. x = ColorFilter.DELTA_INDEX[contrast];
  3517. }
  3518. else {
  3519. x = ColorFilter.DELTA_INDEX[(contrast << 0)] * (1 - x) + ColorFilter.DELTA_INDEX[(contrast << 0) + 1] * x;
  3520. }
  3521. x = x * 127 + 127;
  3522. }
  3523. var x1 = x / 127;
  3524. var x2 = (127 - x) * 0.5;
  3525. 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]);
  3526. }
  3527. adjustSaturation(saturation) {
  3528. saturation = this._clampValue(saturation, 100);
  3529. if (saturation == 0 || isNaN(saturation))
  3530. return this;
  3531. var x = 1 + ((saturation > 0) ? 3 * saturation / 100 : saturation / 100);
  3532. var dx = 1 - x;
  3533. var r = 0.3086 * dx;
  3534. var g = 0.6094 * dx;
  3535. var b = 0.0820 * dx;
  3536. 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]);
  3537. }
  3538. adjustHue(hue) {
  3539. hue = this._clampValue(hue, 180) / 180 * Math.PI;
  3540. if (hue == 0 || isNaN(hue))
  3541. return this;
  3542. var cos = Math.cos(hue);
  3543. var sin = Math.sin(hue);
  3544. var r = 0.213;
  3545. var g = 0.715;
  3546. var b = 0.072;
  3547. 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]);
  3548. }
  3549. reset() {
  3550. return this.setByMatrix(this._copyMatrix(ColorFilter.IDENTITY_MATRIX));
  3551. }
  3552. _multiplyMatrix(matrix) {
  3553. var col = [];
  3554. this._matrix = this._fixMatrix(this._matrix);
  3555. for (var i = 0; i < 5; i++) {
  3556. for (var j = 0; j < 5; j++) {
  3557. col[j] = this._matrix[j + i * 5];
  3558. }
  3559. for (j = 0; j < 5; j++) {
  3560. var val = 0;
  3561. for (var k = 0; k < 5; k++) {
  3562. val += matrix[j + k * 5] * col[k];
  3563. }
  3564. this._matrix[j + i * 5] = val;
  3565. }
  3566. }
  3567. return this.setByMatrix(this._matrix);
  3568. }
  3569. _clampValue(val, limit) {
  3570. return Math.min(limit, Math.max(-limit, val));
  3571. }
  3572. _fixMatrix(matrix = null) {
  3573. if (matrix == null)
  3574. return ColorFilter.IDENTITY_MATRIX;
  3575. if (matrix.length < ColorFilter.LENGTH)
  3576. matrix = matrix.slice(0, matrix.length).concat(ColorFilter.IDENTITY_MATRIX.slice(matrix.length, ColorFilter.LENGTH));
  3577. else if (matrix.length > ColorFilter.LENGTH)
  3578. matrix = matrix.slice(0, ColorFilter.LENGTH);
  3579. return matrix;
  3580. }
  3581. _copyMatrix(matrix) {
  3582. var len = ColorFilter.LENGTH;
  3583. if (!this._matrix)
  3584. this._matrix = [];
  3585. for (var i = 0; i < len; i++) {
  3586. this._matrix[i] = matrix[i];
  3587. }
  3588. return this._matrix;
  3589. }
  3590. }
  3591. 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];
  3592. 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];
  3593. 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];
  3594. ColorFilter.LENGTH = 25;
  3595. class DrawTextureCmd {
  3596. constructor() {
  3597. this.colorFlt = null;
  3598. this.uv = null;
  3599. }
  3600. static create(texture, x, y, width, height, matrix, alpha, color, blendMode, uv) {
  3601. var cmd = Pool.getItemByClass("DrawTextureCmd", DrawTextureCmd);
  3602. cmd.texture = texture;
  3603. texture._addReference();
  3604. cmd.x = x;
  3605. cmd.y = y;
  3606. cmd.width = width;
  3607. cmd.height = height;
  3608. cmd.matrix = matrix;
  3609. cmd.alpha = alpha;
  3610. cmd.color = color;
  3611. cmd.blendMode = blendMode;
  3612. cmd.uv = uv;
  3613. if (color) {
  3614. cmd.colorFlt = new ColorFilter();
  3615. cmd.colorFlt.setColor(color);
  3616. }
  3617. return cmd;
  3618. }
  3619. recover() {
  3620. this.texture._removeReference();
  3621. this.texture = null;
  3622. this.matrix = null;
  3623. Pool.recover("DrawTextureCmd", this);
  3624. }
  3625. run(context, gx, gy) {
  3626. context.drawTextureWithTransform(this.texture, this.x, this.y, this.width, this.height, this.matrix, gx, gy, this.alpha, this.blendMode, this.colorFlt, this.uv);
  3627. }
  3628. get cmdID() {
  3629. return DrawTextureCmd.ID;
  3630. }
  3631. }
  3632. DrawTextureCmd.ID = "DrawTexture";
  3633. class FillTextureCmd {
  3634. static create(texture, x, y, width, height, type, offset, other) {
  3635. var cmd = Pool.getItemByClass("FillTextureCmd", FillTextureCmd);
  3636. cmd.texture = texture;
  3637. cmd.x = x;
  3638. cmd.y = y;
  3639. cmd.width = width;
  3640. cmd.height = height;
  3641. cmd.type = type;
  3642. cmd.offset = offset;
  3643. cmd.other = other;
  3644. return cmd;
  3645. }
  3646. recover() {
  3647. this.texture = null;
  3648. this.offset = null;
  3649. this.other = null;
  3650. Pool.recover("FillTextureCmd", this);
  3651. }
  3652. run(context, gx, gy) {
  3653. context.fillTexture(this.texture, this.x + gx, this.y + gy, this.width, this.height, this.type, this.offset, this.other);
  3654. }
  3655. get cmdID() {
  3656. return FillTextureCmd.ID;
  3657. }
  3658. }
  3659. FillTextureCmd.ID = "FillTexture";
  3660. class RestoreCmd {
  3661. static create() {
  3662. var cmd = Pool.getItemByClass("RestoreCmd", RestoreCmd);
  3663. return cmd;
  3664. }
  3665. recover() {
  3666. Pool.recover("RestoreCmd", this);
  3667. }
  3668. run(context, gx, gy) {
  3669. context.restore();
  3670. }
  3671. get cmdID() {
  3672. return RestoreCmd.ID;
  3673. }
  3674. }
  3675. RestoreCmd.ID = "Restore";
  3676. class RotateCmd {
  3677. static create(angle, pivotX, pivotY) {
  3678. var cmd = Pool.getItemByClass("RotateCmd", RotateCmd);
  3679. cmd.angle = angle;
  3680. cmd.pivotX = pivotX;
  3681. cmd.pivotY = pivotY;
  3682. return cmd;
  3683. }
  3684. recover() {
  3685. Pool.recover("RotateCmd", this);
  3686. }
  3687. run(context, gx, gy) {
  3688. context._rotate(this.angle, this.pivotX + gx, this.pivotY + gy);
  3689. }
  3690. get cmdID() {
  3691. return RotateCmd.ID;
  3692. }
  3693. }
  3694. RotateCmd.ID = "Rotate";
  3695. class ScaleCmd {
  3696. static create(scaleX, scaleY, pivotX, pivotY) {
  3697. var cmd = Pool.getItemByClass("ScaleCmd", ScaleCmd);
  3698. cmd.scaleX = scaleX;
  3699. cmd.scaleY = scaleY;
  3700. cmd.pivotX = pivotX;
  3701. cmd.pivotY = pivotY;
  3702. return cmd;
  3703. }
  3704. recover() {
  3705. Pool.recover("ScaleCmd", this);
  3706. }
  3707. run(context, gx, gy) {
  3708. context._scale(this.scaleX, this.scaleY, this.pivotX + gx, this.pivotY + gy);
  3709. }
  3710. get cmdID() {
  3711. return ScaleCmd.ID;
  3712. }
  3713. }
  3714. ScaleCmd.ID = "Scale";
  3715. class TransformCmd {
  3716. static create(matrix, pivotX, pivotY) {
  3717. var cmd = Pool.getItemByClass("TransformCmd", TransformCmd);
  3718. cmd.matrix = matrix;
  3719. cmd.pivotX = pivotX;
  3720. cmd.pivotY = pivotY;
  3721. return cmd;
  3722. }
  3723. recover() {
  3724. this.matrix = null;
  3725. Pool.recover("TransformCmd", this);
  3726. }
  3727. run(context, gx, gy) {
  3728. context._transform(this.matrix, this.pivotX + gx, this.pivotY + gy);
  3729. }
  3730. get cmdID() {
  3731. return TransformCmd.ID;
  3732. }
  3733. }
  3734. TransformCmd.ID = "Transform";
  3735. class TranslateCmd {
  3736. static create(tx, ty) {
  3737. var cmd = Pool.getItemByClass("TranslateCmd", TranslateCmd);
  3738. cmd.tx = tx;
  3739. cmd.ty = ty;
  3740. return cmd;
  3741. }
  3742. recover() {
  3743. Pool.recover("TranslateCmd", this);
  3744. }
  3745. run(context, gx, gy) {
  3746. context.translate(this.tx, this.ty);
  3747. }
  3748. get cmdID() {
  3749. return TranslateCmd.ID;
  3750. }
  3751. }
  3752. TranslateCmd.ID = "Translate";
  3753. class Bezier {
  3754. constructor() {
  3755. this._controlPoints = [new Point(), new Point(), new Point()];
  3756. this._calFun = this.getPoint2;
  3757. }
  3758. _switchPoint(x, y) {
  3759. var tPoint = this._controlPoints.shift();
  3760. tPoint.setTo(x, y);
  3761. this._controlPoints.push(tPoint);
  3762. }
  3763. getPoint2(t, rst) {
  3764. var p1 = this._controlPoints[0];
  3765. var p2 = this._controlPoints[1];
  3766. var p3 = this._controlPoints[2];
  3767. var lineX = Math.pow((1 - t), 2) * p1.x + 2 * t * (1 - t) * p2.x + Math.pow(t, 2) * p3.x;
  3768. var lineY = Math.pow((1 - t), 2) * p1.y + 2 * t * (1 - t) * p2.y + Math.pow(t, 2) * p3.y;
  3769. rst.push(lineX, lineY);
  3770. }
  3771. getPoint3(t, rst) {
  3772. var p1 = this._controlPoints[0];
  3773. var p2 = this._controlPoints[1];
  3774. var p3 = this._controlPoints[2];
  3775. var p4 = this._controlPoints[3];
  3776. 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);
  3777. 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);
  3778. rst.push(lineX, lineY);
  3779. }
  3780. insertPoints(count, rst) {
  3781. var i;
  3782. count = count > 0 ? count : 5;
  3783. var dLen;
  3784. dLen = 1 / count;
  3785. for (i = 0; i <= 1; i += dLen) {
  3786. this._calFun(i, rst);
  3787. }
  3788. }
  3789. getBezierPoints(pList, inSertCount = 5, count = 2) {
  3790. var i, len;
  3791. len = pList.length;
  3792. if (len < (count + 1) * 2)
  3793. return [];
  3794. var rst = [];
  3795. switch (count) {
  3796. case 2:
  3797. this._calFun = this.getPoint2;
  3798. break;
  3799. case 3:
  3800. this._calFun = this.getPoint3;
  3801. break;
  3802. default:
  3803. return [];
  3804. }
  3805. while (this._controlPoints.length <= count) {
  3806. this._controlPoints.push(Point.create());
  3807. }
  3808. for (i = 0; i < count * 2; i += 2) {
  3809. this._switchPoint(pList[i], pList[i + 1]);
  3810. }
  3811. for (i = count * 2; i < len; i += 2) {
  3812. this._switchPoint(pList[i], pList[i + 1]);
  3813. if ((i / 2) % count == 0)
  3814. this.insertPoints(inSertCount, rst);
  3815. }
  3816. return rst;
  3817. }
  3818. }
  3819. Bezier.I = new Bezier();
  3820. class GrahamScan {
  3821. static multiply(p1, p2, p0) {
  3822. return ((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y));
  3823. }
  3824. static dis(p1, p2) {
  3825. return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
  3826. }
  3827. static _getPoints(count, tempUse = false, rst = null) {
  3828. if (!GrahamScan._mPointList)
  3829. GrahamScan._mPointList = [];
  3830. while (GrahamScan._mPointList.length < count)
  3831. GrahamScan._mPointList.push(new Point());
  3832. if (!rst)
  3833. rst = [];
  3834. rst.length = 0;
  3835. if (tempUse) {
  3836. GrahamScan.getFrom(rst, GrahamScan._mPointList, count);
  3837. }
  3838. else {
  3839. GrahamScan.getFromR(rst, GrahamScan._mPointList, count);
  3840. }
  3841. return rst;
  3842. }
  3843. static getFrom(rst, src, count) {
  3844. var i;
  3845. for (i = 0; i < count; i++) {
  3846. rst.push(src[i]);
  3847. }
  3848. return rst;
  3849. }
  3850. static getFromR(rst, src, count) {
  3851. var i;
  3852. for (i = 0; i < count; i++) {
  3853. rst.push(src.pop());
  3854. }
  3855. return rst;
  3856. }
  3857. static pListToPointList(pList, tempUse = false) {
  3858. var i, len = pList.length / 2, rst = GrahamScan._getPoints(len, tempUse, GrahamScan._tempPointList);
  3859. for (i = 0; i < len; i++) {
  3860. rst[i].setTo(pList[i + i], pList[i + i + 1]);
  3861. }
  3862. return rst;
  3863. }
  3864. static pointListToPlist(pointList) {
  3865. var i, len = pointList.length, rst = GrahamScan._temPList, tPoint;
  3866. rst.length = 0;
  3867. for (i = 0; i < len; i++) {
  3868. tPoint = pointList[i];
  3869. rst.push(tPoint.x, tPoint.y);
  3870. }
  3871. return rst;
  3872. }
  3873. static scanPList(pList) {
  3874. return Utils.copyArray(pList, GrahamScan.pointListToPlist(GrahamScan.scan(GrahamScan.pListToPointList(pList, true))));
  3875. }
  3876. static scan(PointSet) {
  3877. var i, j, k = 0, tmp, n = PointSet.length, ch;
  3878. var _tmpDic = {};
  3879. var key;
  3880. ch = GrahamScan._temArr;
  3881. ch.length = 0;
  3882. n = PointSet.length;
  3883. for (i = n - 1; i >= 0; i--) {
  3884. tmp = PointSet[i];
  3885. key = tmp.x + "_" + tmp.y;
  3886. if (!(key in _tmpDic)) {
  3887. _tmpDic[key] = true;
  3888. ch.push(tmp);
  3889. }
  3890. }
  3891. n = ch.length;
  3892. Utils.copyArray(PointSet, ch);
  3893. for (i = 1; i < n; i++)
  3894. if ((PointSet[i].y < PointSet[k].y) || ((PointSet[i].y == PointSet[k].y) && (PointSet[i].x < PointSet[k].x)))
  3895. k = i;
  3896. tmp = PointSet[0];
  3897. PointSet[0] = PointSet[k];
  3898. PointSet[k] = tmp;
  3899. for (i = 1; i < n - 1; i++) {
  3900. k = i;
  3901. for (j = i + 1; j < n; j++)
  3902. 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]))))
  3903. k = j;
  3904. tmp = PointSet[i];
  3905. PointSet[i] = PointSet[k];
  3906. PointSet[k] = tmp;
  3907. }
  3908. ch = GrahamScan._temArr;
  3909. ch.length = 0;
  3910. if (PointSet.length < 3) {
  3911. return Utils.copyArray(ch, PointSet);
  3912. }
  3913. ch.push(PointSet[0], PointSet[1], PointSet[2]);
  3914. for (i = 3; i < n; i++) {
  3915. while (ch.length >= 2 && GrahamScan.multiply(PointSet[i], ch[ch.length - 1], ch[ch.length - 2]) >= 0)
  3916. ch.pop();
  3917. PointSet[i] && ch.push(PointSet[i]);
  3918. }
  3919. return ch;
  3920. }
  3921. }
  3922. GrahamScan._tempPointList = [];
  3923. GrahamScan._temPList = [];
  3924. GrahamScan._temArr = [];
  3925. class DrawStyle {
  3926. constructor(value) {
  3927. this.setValue(value);
  3928. }
  3929. static create(value) {
  3930. if (value) {
  3931. var color = (value instanceof ColorUtils) ? value : ColorUtils.create(value);
  3932. return color._drawStyle || (color._drawStyle = new DrawStyle(value));
  3933. }
  3934. return DrawStyle.DEFAULT;
  3935. }
  3936. setValue(value) {
  3937. if (value) {
  3938. this._color = (value instanceof ColorUtils) ? value : ColorUtils.create(value);
  3939. }
  3940. else
  3941. this._color = ColorUtils.create("#000000");
  3942. }
  3943. reset() {
  3944. this._color = ColorUtils.create("#000000");
  3945. }
  3946. toInt() {
  3947. return this._color.numColor;
  3948. }
  3949. equal(value) {
  3950. if (typeof (value) == 'string')
  3951. return this._color.strColor === value;
  3952. if (value instanceof ColorUtils)
  3953. return this._color.numColor === value.numColor;
  3954. return false;
  3955. }
  3956. toColorStr() {
  3957. return this._color.strColor;
  3958. }
  3959. }
  3960. DrawStyle.DEFAULT = new DrawStyle("#000000");
  3961. class Path {
  3962. constructor() {
  3963. this._lastOriX = 0;
  3964. this._lastOriY = 0;
  3965. this.paths = [];
  3966. this._curPath = null;
  3967. }
  3968. beginPath(convex) {
  3969. this.paths.length = 1;
  3970. this._curPath = this.paths[0] = new renderPath();
  3971. this._curPath.convex = convex;
  3972. }
  3973. closePath() {
  3974. this._curPath.loop = true;
  3975. }
  3976. newPath() {
  3977. this._curPath = new renderPath();
  3978. this.paths.push(this._curPath);
  3979. }
  3980. addPoint(pointX, pointY) {
  3981. this._curPath.path.push(pointX, pointY);
  3982. }
  3983. push(points, convex) {
  3984. if (!this._curPath) {
  3985. this._curPath = new renderPath();
  3986. this.paths.push(this._curPath);
  3987. }
  3988. else if (this._curPath.path.length > 0) {
  3989. this._curPath = new renderPath();
  3990. this.paths.push(this._curPath);
  3991. }
  3992. var rp = this._curPath;
  3993. rp.path = points.slice();
  3994. rp.convex = convex;
  3995. }
  3996. reset() {
  3997. this.paths.length = 0;
  3998. }
  3999. }
  4000. class renderPath {
  4001. constructor() {
  4002. this.path = [];
  4003. this.loop = false;
  4004. this.convex = false;
  4005. }
  4006. }
  4007. class SubmitBase {
  4008. constructor(renderType = SubmitBase.TYPE_2D) {
  4009. this.clipInfoID = -1;
  4010. this._mesh = null;
  4011. this._blendFn = null;
  4012. this._id = 0;
  4013. this._renderType = 0;
  4014. this._parent = null;
  4015. this._key = new SubmitKey();
  4016. this._startIdx = 0;
  4017. this._numEle = 0;
  4018. this._ref = 1;
  4019. this.shaderValue = null;
  4020. this._renderType = renderType;
  4021. this._id = ++SubmitBase.ID;
  4022. }
  4023. static __init__() {
  4024. var s = SubmitBase.RENDERBASE = new SubmitBase(-1);
  4025. s.shaderValue = new Value2D(0, 0);
  4026. s.shaderValue.ALPHA = 1;
  4027. s._ref = 0xFFFFFFFF;
  4028. }
  4029. getID() {
  4030. return this._id;
  4031. }
  4032. getRenderType() {
  4033. return this._renderType;
  4034. }
  4035. toString() {
  4036. return "ibindex:" + this._startIdx + " num:" + this._numEle + " key=" + this._key;
  4037. }
  4038. renderSubmit() { return 1; }
  4039. releaseRender() { }
  4040. }
  4041. SubmitBase.TYPE_2D = 10000;
  4042. SubmitBase.TYPE_CANVAS = 10003;
  4043. SubmitBase.TYPE_CMDSETRT = 10004;
  4044. SubmitBase.TYPE_CUSTOM = 10005;
  4045. SubmitBase.TYPE_BLURRT = 10006;
  4046. SubmitBase.TYPE_CMDDESTORYPRERT = 10007;
  4047. SubmitBase.TYPE_DISABLESTENCIL = 10008;
  4048. SubmitBase.TYPE_OTHERIBVB = 10009;
  4049. SubmitBase.TYPE_PRIMITIVE = 10010;
  4050. SubmitBase.TYPE_RT = 10011;
  4051. SubmitBase.TYPE_BLUR_RT = 10012;
  4052. SubmitBase.TYPE_TARGET = 10013;
  4053. SubmitBase.TYPE_CHANGE_VALUE = 10014;
  4054. SubmitBase.TYPE_SHAPE = 10015;
  4055. SubmitBase.TYPE_TEXTURE = 10016;
  4056. SubmitBase.TYPE_FILLTEXTURE = 10017;
  4057. SubmitBase.KEY_ONCE = -1;
  4058. SubmitBase.KEY_FILLRECT = 1;
  4059. SubmitBase.KEY_DRAWTEXTURE = 2;
  4060. SubmitBase.KEY_VG = 3;
  4061. SubmitBase.KEY_TRIANGLES = 4;
  4062. SubmitBase.ID = 1;
  4063. SubmitBase.preRender = null;
  4064. class SaveBase {
  4065. constructor() {
  4066. }
  4067. static _createArray() {
  4068. var value = [];
  4069. value._length = 0;
  4070. return value;
  4071. }
  4072. static _init() {
  4073. var namemap = SaveBase._namemap = {};
  4074. namemap[SaveBase.TYPE_ALPHA] = "ALPHA";
  4075. namemap[SaveBase.TYPE_FILESTYLE] = "fillStyle";
  4076. namemap[SaveBase.TYPE_FONT] = "font";
  4077. namemap[SaveBase.TYPE_LINEWIDTH] = "lineWidth";
  4078. namemap[SaveBase.TYPE_STROKESTYLE] = "strokeStyle";
  4079. namemap[SaveBase.TYPE_ENABLEMERGE] = "_mergeID";
  4080. namemap[SaveBase.TYPE_MARK] = namemap[SaveBase.TYPE_TRANSFORM] = namemap[SaveBase.TYPE_TRANSLATE] = [];
  4081. namemap[SaveBase.TYPE_TEXTBASELINE] = "textBaseline";
  4082. namemap[SaveBase.TYPE_TEXTALIGN] = "textAlign";
  4083. namemap[SaveBase.TYPE_GLOBALCOMPOSITEOPERATION] = "_nBlendType";
  4084. namemap[SaveBase.TYPE_SHADER] = "shader";
  4085. namemap[SaveBase.TYPE_FILTERS] = "filters";
  4086. namemap[SaveBase.TYPE_COLORFILTER] = '_colorFiler';
  4087. return namemap;
  4088. }
  4089. isSaveMark() { return false; }
  4090. restore(context) {
  4091. this._dataObj[this._valueName] = this._value;
  4092. SaveBase.POOL[SaveBase.POOL._length++] = this;
  4093. this._newSubmit && (context._curSubmit = SubmitBase.RENDERBASE);
  4094. }
  4095. static save(context, type, dataObj, newSubmit) {
  4096. if ((context._saveMark._saveuse & type) !== type) {
  4097. context._saveMark._saveuse |= type;
  4098. var cache = SaveBase.POOL;
  4099. var o = cache._length > 0 ? cache[--cache._length] : (new SaveBase());
  4100. o._value = dataObj[o._valueName = SaveBase._namemap[type]];
  4101. o._dataObj = dataObj;
  4102. o._newSubmit = newSubmit;
  4103. var _save = context._save;
  4104. _save[_save._length++] = o;
  4105. }
  4106. }
  4107. }
  4108. SaveBase.TYPE_ALPHA = 0x1;
  4109. SaveBase.TYPE_FILESTYLE = 0x2;
  4110. SaveBase.TYPE_FONT = 0x8;
  4111. SaveBase.TYPE_LINEWIDTH = 0x100;
  4112. SaveBase.TYPE_STROKESTYLE = 0x200;
  4113. SaveBase.TYPE_MARK = 0x400;
  4114. SaveBase.TYPE_TRANSFORM = 0x800;
  4115. SaveBase.TYPE_TRANSLATE = 0x1000;
  4116. SaveBase.TYPE_ENABLEMERGE = 0x2000;
  4117. SaveBase.TYPE_TEXTBASELINE = 0x4000;
  4118. SaveBase.TYPE_TEXTALIGN = 0x8000;
  4119. SaveBase.TYPE_GLOBALCOMPOSITEOPERATION = 0x10000;
  4120. SaveBase.TYPE_CLIPRECT = 0x20000;
  4121. SaveBase.TYPE_CLIPRECT_STENCIL = 0x40000;
  4122. SaveBase.TYPE_IBVB = 0x80000;
  4123. SaveBase.TYPE_SHADER = 0x100000;
  4124. SaveBase.TYPE_FILTERS = 0x200000;
  4125. SaveBase.TYPE_FILTERS_TYPE = 0x400000;
  4126. SaveBase.TYPE_COLORFILTER = 0x800000;
  4127. SaveBase.POOL = SaveBase._createArray();
  4128. SaveBase._namemap = SaveBase._init();
  4129. class SaveClipRect {
  4130. constructor() {
  4131. this._globalClipMatrix = new Matrix();
  4132. this._clipInfoID = -1;
  4133. this._clipRect = new Rectangle();
  4134. this.incache = false;
  4135. }
  4136. isSaveMark() { return false; }
  4137. restore(context) {
  4138. this._globalClipMatrix.copyTo(context._globalClipMatrix);
  4139. this._clipRect.clone(context._clipRect);
  4140. context._clipInfoID = this._clipInfoID;
  4141. SaveClipRect.POOL[SaveClipRect.POOL._length++] = this;
  4142. context._clipInCache = this.incache;
  4143. }
  4144. static save(context) {
  4145. if ((context._saveMark._saveuse & SaveBase.TYPE_CLIPRECT) == SaveBase.TYPE_CLIPRECT)
  4146. return;
  4147. context._saveMark._saveuse |= SaveBase.TYPE_CLIPRECT;
  4148. var cache = SaveClipRect.POOL;
  4149. var o = cache._length > 0 ? cache[--cache._length] : (new SaveClipRect());
  4150. context._globalClipMatrix.copyTo(o._globalClipMatrix);
  4151. context._clipRect.clone(o._clipRect);
  4152. o._clipInfoID = context._clipInfoID;
  4153. o.incache = context._clipInCache;
  4154. var _save = context._save;
  4155. _save[_save._length++] = o;
  4156. }
  4157. }
  4158. SaveClipRect.POOL = SaveBase._createArray();
  4159. class SaveMark {
  4160. constructor() {
  4161. this._saveuse = 0;
  4162. }
  4163. isSaveMark() {
  4164. return true;
  4165. }
  4166. restore(context) {
  4167. context._saveMark = this._preSaveMark;
  4168. SaveMark.POOL[SaveMark.POOL._length++] = this;
  4169. }
  4170. static Create(context) {
  4171. var no = SaveMark.POOL;
  4172. var o = no._length > 0 ? no[--no._length] : (new SaveMark());
  4173. o._saveuse = 0;
  4174. o._preSaveMark = context._saveMark;
  4175. context._saveMark = o;
  4176. return o;
  4177. }
  4178. }
  4179. SaveMark.POOL = SaveBase._createArray();
  4180. class SaveTransform {
  4181. constructor() {
  4182. this._matrix = new Matrix();
  4183. }
  4184. isSaveMark() { return false; }
  4185. restore(context) {
  4186. context._curMat = this._savematrix;
  4187. SaveTransform.POOL[SaveTransform.POOL._length++] = this;
  4188. }
  4189. static save(context) {
  4190. var _saveMark = context._saveMark;
  4191. if ((_saveMark._saveuse & SaveBase.TYPE_TRANSFORM) === SaveBase.TYPE_TRANSFORM)
  4192. return;
  4193. _saveMark._saveuse |= SaveBase.TYPE_TRANSFORM;
  4194. var no = SaveTransform.POOL;
  4195. var o = no._length > 0 ? no[--no._length] : (new SaveTransform());
  4196. o._savematrix = context._curMat;
  4197. context._curMat = context._curMat.copyTo(o._matrix);
  4198. var _save = context._save;
  4199. _save[_save._length++] = o;
  4200. }
  4201. }
  4202. SaveTransform.POOL = SaveBase._createArray();
  4203. class SaveTranslate {
  4204. constructor() {
  4205. this._mat = new Matrix();
  4206. }
  4207. isSaveMark() { return false; }
  4208. restore(context) {
  4209. this._mat.copyTo(context._curMat);
  4210. SaveTranslate.POOL[SaveTranslate.POOL._length++] = this;
  4211. }
  4212. static save(context) {
  4213. var no = SaveTranslate.POOL;
  4214. var o = no._length > 0 ? no[--no._length] : (new SaveTranslate());
  4215. context._curMat.copyTo(o._mat);
  4216. var _save = context._save;
  4217. _save[_save._length++] = o;
  4218. }
  4219. }
  4220. SaveTranslate.POOL = SaveBase._createArray();
  4221. class RenderInfo {
  4222. }
  4223. RenderInfo.loopStTm = 0;
  4224. RenderInfo.loopCount = 0;
  4225. class Buffer {
  4226. constructor() {
  4227. this._byteLength = 0;
  4228. this._glBuffer = LayaGL.instance.createBuffer();
  4229. }
  4230. get bufferUsage() {
  4231. return this._bufferUsage;
  4232. }
  4233. _bindForVAO() {
  4234. }
  4235. bind() {
  4236. return false;
  4237. }
  4238. destroy() {
  4239. if (this._glBuffer) {
  4240. LayaGL.instance.deleteBuffer(this._glBuffer);
  4241. this._glBuffer = null;
  4242. }
  4243. }
  4244. }
  4245. class Buffer2D extends Buffer {
  4246. constructor() {
  4247. super();
  4248. this._maxsize = 0;
  4249. this._upload = true;
  4250. this._uploadSize = 0;
  4251. this._bufferSize = 0;
  4252. this._u8Array = null;
  4253. }
  4254. static __int__(gl) {
  4255. }
  4256. get bufferLength() {
  4257. return this._buffer.byteLength;
  4258. }
  4259. set byteLength(value) {
  4260. this.setByteLength(value);
  4261. }
  4262. setByteLength(value) {
  4263. if (this._byteLength !== value) {
  4264. value <= this._bufferSize || (this._resizeBuffer(value * 2 + 256, true));
  4265. this._byteLength = value;
  4266. }
  4267. }
  4268. needSize(sz) {
  4269. var old = this._byteLength;
  4270. if (sz) {
  4271. var needsz = this._byteLength + sz;
  4272. needsz <= this._bufferSize || (this._resizeBuffer(needsz << 1, true));
  4273. this._byteLength = needsz;
  4274. }
  4275. return old;
  4276. }
  4277. _bufferData() {
  4278. this._maxsize = Math.max(this._maxsize, this._byteLength);
  4279. if (RenderInfo.loopCount % 30 == 0) {
  4280. if (this._buffer.byteLength > (this._maxsize + 64)) {
  4281. this._buffer = this._buffer.slice(0, this._maxsize + 64);
  4282. this._bufferSize = this._buffer.byteLength;
  4283. this._checkArrayUse();
  4284. }
  4285. this._maxsize = this._byteLength;
  4286. }
  4287. if (this._uploadSize < this._buffer.byteLength) {
  4288. this._uploadSize = this._buffer.byteLength;
  4289. LayaGL.instance.bufferData(this._bufferType, this._uploadSize, this._bufferUsage);
  4290. }
  4291. LayaGL.instance.bufferSubData(this._bufferType, 0, new Uint8Array(this._buffer, 0, this._byteLength));
  4292. }
  4293. _bufferSubData(offset = 0, dataStart = 0, dataLength = 0) {
  4294. this._maxsize = Math.max(this._maxsize, this._byteLength);
  4295. if (RenderInfo.loopCount % 30 == 0) {
  4296. if (this._buffer.byteLength > (this._maxsize + 64)) {
  4297. this._buffer = this._buffer.slice(0, this._maxsize + 64);
  4298. this._bufferSize = this._buffer.byteLength;
  4299. this._checkArrayUse();
  4300. }
  4301. this._maxsize = this._byteLength;
  4302. }
  4303. if (this._uploadSize < this._buffer.byteLength) {
  4304. this._uploadSize = this._buffer.byteLength;
  4305. LayaGL.instance.bufferData(this._bufferType, this._uploadSize, this._bufferUsage);
  4306. }
  4307. if (dataStart || dataLength) {
  4308. var subBuffer = this._buffer.slice(dataStart, dataLength);
  4309. LayaGL.instance.bufferSubData(this._bufferType, offset, subBuffer);
  4310. }
  4311. else {
  4312. LayaGL.instance.bufferSubData(this._bufferType, offset, this._buffer);
  4313. }
  4314. }
  4315. _checkArrayUse() {
  4316. }
  4317. _bind_uploadForVAO() {
  4318. if (!this._upload)
  4319. return false;
  4320. this._upload = false;
  4321. this._bindForVAO();
  4322. this._bufferData();
  4323. return true;
  4324. }
  4325. _bind_upload() {
  4326. if (!this._upload)
  4327. return false;
  4328. this._upload = false;
  4329. this.bind();
  4330. this._bufferData();
  4331. return true;
  4332. }
  4333. _bind_subUpload(offset = 0, dataStart = 0, dataLength = 0) {
  4334. if (!this._upload)
  4335. return false;
  4336. this._upload = false;
  4337. this.bind();
  4338. this._bufferSubData(offset, dataStart, dataLength);
  4339. return true;
  4340. }
  4341. _resizeBuffer(nsz, copy) {
  4342. var buff = this._buffer;
  4343. if (nsz <= buff.byteLength)
  4344. return this;
  4345. var u8buf = this._u8Array;
  4346. if (copy && buff && buff.byteLength > 0) {
  4347. var newbuffer = new ArrayBuffer(nsz);
  4348. var oldU8Arr = (u8buf && u8buf.buffer == buff) ? u8buf : new Uint8Array(buff);
  4349. u8buf = this._u8Array = new Uint8Array(newbuffer);
  4350. u8buf.set(oldU8Arr, 0);
  4351. buff = this._buffer = newbuffer;
  4352. }
  4353. else {
  4354. buff = this._buffer = new ArrayBuffer(nsz);
  4355. this._u8Array = null;
  4356. }
  4357. this._checkArrayUse();
  4358. this._upload = true;
  4359. this._bufferSize = buff.byteLength;
  4360. return this;
  4361. }
  4362. append(data) {
  4363. this._upload = true;
  4364. var byteLen, n;
  4365. byteLen = data.byteLength;
  4366. if (data instanceof Uint8Array) {
  4367. this._resizeBuffer(this._byteLength + byteLen, true);
  4368. n = new Uint8Array(this._buffer, this._byteLength);
  4369. }
  4370. else if (data instanceof Uint16Array) {
  4371. this._resizeBuffer(this._byteLength + byteLen, true);
  4372. n = new Uint16Array(this._buffer, this._byteLength);
  4373. }
  4374. else if (data instanceof Float32Array) {
  4375. this._resizeBuffer(this._byteLength + byteLen, true);
  4376. n = new Float32Array(this._buffer, this._byteLength);
  4377. }
  4378. n.set(data, 0);
  4379. this._byteLength += byteLen;
  4380. this._checkArrayUse();
  4381. }
  4382. appendU16Array(data, len) {
  4383. this._resizeBuffer(this._byteLength + len * 2, true);
  4384. var u = new Uint16Array(this._buffer, this._byteLength, len);
  4385. if (len == 6) {
  4386. u[0] = data[0];
  4387. u[1] = data[1];
  4388. u[2] = data[2];
  4389. u[3] = data[3];
  4390. u[4] = data[4];
  4391. u[5] = data[5];
  4392. }
  4393. else if (len >= 100) {
  4394. u.set(new Uint16Array(data.buffer, 0, len));
  4395. }
  4396. else {
  4397. for (var i = 0; i < len; i++) {
  4398. u[i] = data[i];
  4399. }
  4400. }
  4401. this._byteLength += len * 2;
  4402. this._checkArrayUse();
  4403. }
  4404. appendEx(data, type) {
  4405. this._upload = true;
  4406. var byteLen, n;
  4407. byteLen = data.byteLength;
  4408. this._resizeBuffer(this._byteLength + byteLen, true);
  4409. n = new type(this._buffer, this._byteLength);
  4410. n.set(data, 0);
  4411. this._byteLength += byteLen;
  4412. this._checkArrayUse();
  4413. }
  4414. appendEx2(data, type, dataLen, perDataLen = 1) {
  4415. this._upload = true;
  4416. var byteLen, n;
  4417. byteLen = dataLen * perDataLen;
  4418. this._resizeBuffer(this._byteLength + byteLen, true);
  4419. n = new type(this._buffer, this._byteLength);
  4420. var i;
  4421. for (i = 0; i < dataLen; i++) {
  4422. n[i] = data[i];
  4423. }
  4424. this._byteLength += byteLen;
  4425. this._checkArrayUse();
  4426. }
  4427. getBuffer() {
  4428. return this._buffer;
  4429. }
  4430. setNeedUpload() {
  4431. this._upload = true;
  4432. }
  4433. getNeedUpload() {
  4434. return this._upload;
  4435. }
  4436. upload() {
  4437. var gl = LayaGL.instance;
  4438. var scuess = this._bind_upload();
  4439. gl.bindBuffer(this._bufferType, null);
  4440. if (this._bufferType == gl.ARRAY_BUFFER)
  4441. Buffer._bindedVertexBuffer = null;
  4442. if (this._bufferType == gl.ELEMENT_ARRAY_BUFFER)
  4443. Buffer._bindedIndexBuffer = null;
  4444. BaseShader.activeShader = null;
  4445. return scuess;
  4446. }
  4447. subUpload(offset = 0, dataStart = 0, dataLength = 0) {
  4448. var gl = LayaGL.instance;
  4449. var scuess = this._bind_subUpload();
  4450. gl.bindBuffer(this._bufferType, null);
  4451. if (this._bufferType == gl.ARRAY_BUFFER)
  4452. Buffer._bindedVertexBuffer = null;
  4453. if (this._bufferType == gl.ELEMENT_ARRAY_BUFFER)
  4454. Buffer._bindedIndexBuffer = null;
  4455. BaseShader.activeShader = null;
  4456. return scuess;
  4457. }
  4458. _disposeResource() {
  4459. this._upload = true;
  4460. this._uploadSize = 0;
  4461. }
  4462. clear() {
  4463. this._byteLength = 0;
  4464. this._upload = true;
  4465. }
  4466. }
  4467. Buffer2D.FLOAT32 = 4;
  4468. Buffer2D.SHORT = 2;
  4469. class VertexBuffer2D extends Buffer2D {
  4470. constructor(vertexStride, bufferUsage) {
  4471. super();
  4472. this._vertexStride = vertexStride;
  4473. this._bufferUsage = bufferUsage;
  4474. this._bufferType = LayaGL.instance.ARRAY_BUFFER;
  4475. this._buffer = new ArrayBuffer(8);
  4476. this._floatArray32 = new Float32Array(this._buffer);
  4477. this._uint32Array = new Uint32Array(this._buffer);
  4478. }
  4479. get vertexStride() {
  4480. return this._vertexStride;
  4481. }
  4482. getFloat32Array() {
  4483. return this._floatArray32;
  4484. }
  4485. appendArray(data) {
  4486. var oldoff = this._byteLength >> 2;
  4487. this.setByteLength(this._byteLength + data.length * 4);
  4488. var vbdata = this.getFloat32Array();
  4489. vbdata.set(data, oldoff);
  4490. this._upload = true;
  4491. }
  4492. _checkArrayUse() {
  4493. this._floatArray32 && (this._floatArray32 = new Float32Array(this._buffer));
  4494. this._uint32Array && (this._uint32Array = new Uint32Array(this._buffer));
  4495. }
  4496. deleteBuffer() {
  4497. super._disposeResource();
  4498. }
  4499. _bindForVAO() {
  4500. var gl = LayaGL.instance;
  4501. gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
  4502. }
  4503. bind() {
  4504. if (Buffer._bindedVertexBuffer !== this._glBuffer) {
  4505. var gl = LayaGL.instance;
  4506. gl.bindBuffer(gl.ARRAY_BUFFER, this._glBuffer);
  4507. Buffer._bindedVertexBuffer = this._glBuffer;
  4508. return true;
  4509. }
  4510. return false;
  4511. }
  4512. destroy() {
  4513. super.destroy();
  4514. this._byteLength = 0;
  4515. this._upload = true;
  4516. this._buffer = null;
  4517. this._floatArray32 = null;
  4518. }
  4519. }
  4520. VertexBuffer2D.create = function (vertexStride, bufferUsage = 0x88e8) {
  4521. return new VertexBuffer2D(vertexStride, bufferUsage);
  4522. };
  4523. class IndexBuffer2D extends Buffer2D {
  4524. constructor(bufferUsage = 0x88e4) {
  4525. super();
  4526. this._bufferUsage = bufferUsage;
  4527. this._bufferType = LayaGL.instance.ELEMENT_ARRAY_BUFFER;
  4528. this._buffer = new ArrayBuffer(8);
  4529. }
  4530. _checkArrayUse() {
  4531. this._uint16Array && (this._uint16Array = new Uint16Array(this._buffer));
  4532. }
  4533. getUint16Array() {
  4534. return this._uint16Array || (this._uint16Array = new Uint16Array(this._buffer));
  4535. }
  4536. _bindForVAO() {
  4537. var gl = LayaGL.instance;
  4538. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  4539. }
  4540. bind() {
  4541. if (Buffer._bindedIndexBuffer !== this._glBuffer) {
  4542. var gl = LayaGL.instance;
  4543. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._glBuffer);
  4544. Buffer._bindedIndexBuffer = this._glBuffer;
  4545. return true;
  4546. }
  4547. return false;
  4548. }
  4549. destory() {
  4550. this._uint16Array = null;
  4551. this._buffer = null;
  4552. }
  4553. disposeResource() {
  4554. this._disposeResource();
  4555. }
  4556. }
  4557. IndexBuffer2D.create = function (bufferUsage = 0x88e4) {
  4558. return new IndexBuffer2D(bufferUsage);
  4559. };
  4560. class BufferStateBase {
  4561. constructor() {
  4562. this._nativeVertexArrayObject = LayaGL.layaGPUInstance.createVertexArray();
  4563. }
  4564. bind() {
  4565. if (BufferStateBase._curBindedBufferState !== this) {
  4566. LayaGL.layaGPUInstance.bindVertexArray(this._nativeVertexArrayObject);
  4567. BufferStateBase._curBindedBufferState = this;
  4568. }
  4569. }
  4570. unBind() {
  4571. if (BufferStateBase._curBindedBufferState === this) {
  4572. LayaGL.layaGPUInstance.bindVertexArray(null);
  4573. BufferStateBase._curBindedBufferState = null;
  4574. }
  4575. else {
  4576. throw "BufferState: must call bind() function first.";
  4577. }
  4578. }
  4579. destroy() {
  4580. LayaGL.layaGPUInstance.deleteVertexArray(this._nativeVertexArrayObject);
  4581. }
  4582. bindForNative() {
  4583. LayaGL.instance.bindVertexArray(this._nativeVertexArrayObject);
  4584. BufferStateBase._curBindedBufferState = this;
  4585. }
  4586. unBindForNative() {
  4587. LayaGL.instance.bindVertexArray(null);
  4588. BufferStateBase._curBindedBufferState = null;
  4589. }
  4590. }
  4591. class BufferState2D extends BufferStateBase {
  4592. constructor() {
  4593. super();
  4594. }
  4595. }
  4596. class Mesh2D {
  4597. constructor(stride, vballoc, iballoc) {
  4598. this._stride = 0;
  4599. this.vertNum = 0;
  4600. this.indexNum = 0;
  4601. this._applied = false;
  4602. this._quadNum = 0;
  4603. this.canReuse = false;
  4604. this._stride = stride;
  4605. this._vb = new VertexBuffer2D(stride, LayaGL.instance.DYNAMIC_DRAW);
  4606. if (vballoc) {
  4607. this._vb._resizeBuffer(vballoc, false);
  4608. }
  4609. else {
  4610. Config.webGL2D_MeshAllocMaxMem && this._vb._resizeBuffer(64 * 1024 * stride, false);
  4611. }
  4612. this._ib = new IndexBuffer2D();
  4613. if (iballoc) {
  4614. this._ib._resizeBuffer(iballoc, false);
  4615. }
  4616. }
  4617. cloneWithNewVB() {
  4618. var mesh = new Mesh2D(this._stride, 0, 0);
  4619. mesh._ib = this._ib;
  4620. mesh._quadNum = this._quadNum;
  4621. mesh._attribInfo = this._attribInfo;
  4622. return mesh;
  4623. }
  4624. cloneWithNewVBIB() {
  4625. var mesh = new Mesh2D(this._stride, 0, 0);
  4626. mesh._attribInfo = this._attribInfo;
  4627. return mesh;
  4628. }
  4629. getVBW() {
  4630. this._vb.setNeedUpload();
  4631. return this._vb;
  4632. }
  4633. getVBR() {
  4634. return this._vb;
  4635. }
  4636. getIBR() {
  4637. return this._ib;
  4638. }
  4639. getIBW() {
  4640. this._ib.setNeedUpload();
  4641. return this._ib;
  4642. }
  4643. createQuadIB(QuadNum) {
  4644. this._quadNum = QuadNum;
  4645. this._ib._resizeBuffer(QuadNum * 6 * 2, false);
  4646. this._ib.byteLength = this._ib.bufferLength;
  4647. var bd = this._ib.getUint16Array();
  4648. var idx = 0;
  4649. var curvert = 0;
  4650. for (var i = 0; i < QuadNum; i++) {
  4651. bd[idx++] = curvert;
  4652. bd[idx++] = curvert + 2;
  4653. bd[idx++] = curvert + 1;
  4654. bd[idx++] = curvert;
  4655. bd[idx++] = curvert + 3;
  4656. bd[idx++] = curvert + 2;
  4657. curvert += 4;
  4658. }
  4659. this._ib.setNeedUpload();
  4660. }
  4661. setAttributes(attribs) {
  4662. this._attribInfo = attribs;
  4663. if (this._attribInfo.length % 3 != 0) {
  4664. throw 'Mesh2D setAttributes error!';
  4665. }
  4666. }
  4667. configVAO(gl) {
  4668. if (this._applied)
  4669. return;
  4670. this._applied = true;
  4671. if (!this._vao) {
  4672. this._vao = new BufferState2D();
  4673. }
  4674. this._vao.bind();
  4675. this._vb._bindForVAO();
  4676. this._ib.setNeedUpload();
  4677. this._ib._bind_uploadForVAO();
  4678. var attribNum = this._attribInfo.length / 3;
  4679. var idx = 0;
  4680. for (var i = 0; i < attribNum; i++) {
  4681. var _size = this._attribInfo[idx + 1];
  4682. var _type = this._attribInfo[idx];
  4683. var _off = this._attribInfo[idx + 2];
  4684. gl.enableVertexAttribArray(i);
  4685. gl.vertexAttribPointer(i, _size, _type, false, this._stride, _off);
  4686. idx += 3;
  4687. }
  4688. this._vao.unBind();
  4689. }
  4690. useMesh(gl) {
  4691. this._applied || this.configVAO(gl);
  4692. this._vao.bind();
  4693. this._vb.bind();
  4694. this._ib._bind_upload() || this._ib.bind();
  4695. this._vb._bind_upload() || this._vb.bind();
  4696. }
  4697. getEleNum() {
  4698. return this._ib.getBuffer().byteLength / 2;
  4699. }
  4700. releaseMesh() { }
  4701. destroy() {
  4702. }
  4703. clearVB() {
  4704. this._vb.clear();
  4705. }
  4706. }
  4707. Mesh2D._gvaoid = 0;
  4708. class MeshQuadTexture extends Mesh2D {
  4709. constructor() {
  4710. super(MeshQuadTexture.const_stride, 4, 4);
  4711. this.canReuse = true;
  4712. this.setAttributes(MeshQuadTexture._fixattriInfo);
  4713. if (!MeshQuadTexture._fixib) {
  4714. this.createQuadIB(MeshQuadTexture._maxIB);
  4715. MeshQuadTexture._fixib = this._ib;
  4716. }
  4717. else {
  4718. this._ib = MeshQuadTexture._fixib;
  4719. this._quadNum = MeshQuadTexture._maxIB;
  4720. }
  4721. }
  4722. static __int__() {
  4723. MeshQuadTexture._fixattriInfo = [5126, 4, 0,
  4724. 5121, 4, 16,
  4725. 5121, 4, 20];
  4726. }
  4727. static getAMesh(mainctx) {
  4728. var ret = null;
  4729. if (MeshQuadTexture._POOL.length) {
  4730. ret = MeshQuadTexture._POOL.pop();
  4731. }
  4732. else
  4733. ret = new MeshQuadTexture();
  4734. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshQuadTexture.const_stride, false);
  4735. return ret;
  4736. }
  4737. releaseMesh() {
  4738. this._vb.setByteLength(0);
  4739. this.vertNum = 0;
  4740. this.indexNum = 0;
  4741. MeshQuadTexture._POOL.push(this);
  4742. }
  4743. destroy() {
  4744. this._vb.destroy();
  4745. this._vb.deleteBuffer();
  4746. }
  4747. addQuad(pos, uv, color, useTex) {
  4748. var vb = this._vb;
  4749. var vpos = (vb._byteLength >> 2);
  4750. vb.setByteLength((vpos + MeshQuadTexture.const_stride) << 2);
  4751. var vbdata = vb._floatArray32 || vb.getFloat32Array();
  4752. var vbu32Arr = vb._uint32Array;
  4753. var cpos = vpos;
  4754. var useTexVal = useTex ? 0xff : 0;
  4755. vbdata[cpos++] = pos[0];
  4756. vbdata[cpos++] = pos[1];
  4757. vbdata[cpos++] = uv[0];
  4758. vbdata[cpos++] = uv[1];
  4759. vbu32Arr[cpos++] = color;
  4760. vbu32Arr[cpos++] = useTexVal;
  4761. vbdata[cpos++] = pos[2];
  4762. vbdata[cpos++] = pos[3];
  4763. vbdata[cpos++] = uv[2];
  4764. vbdata[cpos++] = uv[3];
  4765. vbu32Arr[cpos++] = color;
  4766. vbu32Arr[cpos++] = useTexVal;
  4767. vbdata[cpos++] = pos[4];
  4768. vbdata[cpos++] = pos[5];
  4769. vbdata[cpos++] = uv[4];
  4770. vbdata[cpos++] = uv[5];
  4771. vbu32Arr[cpos++] = color;
  4772. vbu32Arr[cpos++] = useTexVal;
  4773. vbdata[cpos++] = pos[6];
  4774. vbdata[cpos++] = pos[7];
  4775. vbdata[cpos++] = uv[6];
  4776. vbdata[cpos++] = uv[7];
  4777. vbu32Arr[cpos++] = color;
  4778. vbu32Arr[cpos++] = useTexVal;
  4779. vb._upload = true;
  4780. }
  4781. }
  4782. MeshQuadTexture.const_stride = 24;
  4783. MeshQuadTexture._maxIB = 16 * 1024;
  4784. MeshQuadTexture._POOL = [];
  4785. class MeshTexture extends Mesh2D {
  4786. constructor() {
  4787. super(MeshTexture.const_stride, 4, 4);
  4788. this.canReuse = true;
  4789. this.setAttributes(MeshTexture._fixattriInfo);
  4790. }
  4791. static __init__() {
  4792. MeshTexture._fixattriInfo = [5126, 4, 0,
  4793. 5121, 4, 16,
  4794. 5121, 4, 20];
  4795. }
  4796. static getAMesh(mainctx) {
  4797. var ret;
  4798. if (MeshTexture._POOL.length) {
  4799. ret = MeshTexture._POOL.pop();
  4800. }
  4801. else
  4802. ret = new MeshTexture();
  4803. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshTexture.const_stride, false);
  4804. return ret;
  4805. }
  4806. addData(vertices, uvs, idx, matrix, rgba) {
  4807. var vb = this._vb;
  4808. var ib = this._ib;
  4809. var vertsz = vertices.length >> 1;
  4810. var startpos = vb.needSize(vertsz * MeshTexture.const_stride);
  4811. var f32pos = startpos >> 2;
  4812. var vbdata = vb._floatArray32 || vb.getFloat32Array();
  4813. var vbu32Arr = vb._uint32Array;
  4814. var ci = 0;
  4815. var m00 = matrix.a;
  4816. var m01 = matrix.b;
  4817. var m10 = matrix.c;
  4818. var m11 = matrix.d;
  4819. var tx = matrix.tx;
  4820. var ty = matrix.ty;
  4821. var i = 0;
  4822. for (i = 0; i < vertsz; i++) {
  4823. var x = vertices[ci], y = vertices[ci + 1];
  4824. vbdata[f32pos] = x * m00 + y * m10 + tx;
  4825. vbdata[f32pos + 1] = x * m01 + y * m11 + ty;
  4826. vbdata[f32pos + 2] = uvs[ci];
  4827. vbdata[f32pos + 3] = uvs[ci + 1];
  4828. vbu32Arr[f32pos + 4] = rgba;
  4829. vbu32Arr[f32pos + 5] = 0xff;
  4830. f32pos += 6;
  4831. ci += 2;
  4832. }
  4833. vb.setNeedUpload();
  4834. var vertN = this.vertNum;
  4835. var sz = idx.length;
  4836. var stib = ib.needSize(idx.byteLength);
  4837. var cidx = ib.getUint16Array();
  4838. var stibid = stib >> 1;
  4839. if (vertN > 0) {
  4840. var end = stibid + sz;
  4841. var si = 0;
  4842. for (i = stibid; i < end; i++, si++) {
  4843. cidx[i] = idx[si] + vertN;
  4844. }
  4845. }
  4846. else {
  4847. cidx.set(idx, stibid);
  4848. }
  4849. ib.setNeedUpload();
  4850. this.vertNum += vertsz;
  4851. this.indexNum += idx.length;
  4852. }
  4853. releaseMesh() {
  4854. this._vb.setByteLength(0);
  4855. this._ib.setByteLength(0);
  4856. this.vertNum = 0;
  4857. this.indexNum = 0;
  4858. MeshTexture._POOL.push(this);
  4859. }
  4860. destroy() {
  4861. this._ib.destroy();
  4862. this._vb.destroy();
  4863. this._ib.disposeResource();
  4864. this._vb.deleteBuffer();
  4865. }
  4866. }
  4867. MeshTexture.const_stride = 24;
  4868. MeshTexture._POOL = [];
  4869. class MeshVG extends Mesh2D {
  4870. constructor() {
  4871. super(MeshVG.const_stride, 4, 4);
  4872. this.canReuse = true;
  4873. this.setAttributes(MeshVG._fixattriInfo);
  4874. }
  4875. static __init__() {
  4876. MeshVG._fixattriInfo = [5126, 2, 0,
  4877. 5121, 4, 8];
  4878. }
  4879. static getAMesh(mainctx) {
  4880. var ret;
  4881. if (MeshVG._POOL.length) {
  4882. ret = MeshVG._POOL.pop();
  4883. }
  4884. else
  4885. ret = new MeshVG();
  4886. mainctx && ret._vb._resizeBuffer(64 * 1024 * MeshVG.const_stride, false);
  4887. return ret;
  4888. }
  4889. addVertAndIBToMesh(ctx, points, rgba, ib) {
  4890. var startpos = this._vb.needSize(points.length / 2 * MeshVG.const_stride);
  4891. var f32pos = startpos >> 2;
  4892. var vbdata = this._vb._floatArray32 || this._vb.getFloat32Array();
  4893. var vbu32Arr = this._vb._uint32Array;
  4894. var ci = 0;
  4895. var sz = points.length / 2;
  4896. for (var i = 0; i < sz; i++) {
  4897. vbdata[f32pos++] = points[ci];
  4898. vbdata[f32pos++] = points[ci + 1];
  4899. ci += 2;
  4900. vbu32Arr[f32pos++] = rgba;
  4901. }
  4902. this._vb.setNeedUpload();
  4903. this._ib.append(new Uint16Array(ib));
  4904. this._ib.setNeedUpload();
  4905. this.vertNum += sz;
  4906. this.indexNum += ib.length;
  4907. }
  4908. releaseMesh() {
  4909. this._vb.setByteLength(0);
  4910. this._ib.setByteLength(0);
  4911. this.vertNum = 0;
  4912. this.indexNum = 0;
  4913. MeshVG._POOL.push(this);
  4914. }
  4915. destroy() {
  4916. this._ib.destroy();
  4917. this._vb.destroy();
  4918. this._ib.disposeResource();
  4919. this._vb.deleteBuffer();
  4920. }
  4921. }
  4922. MeshVG.const_stride = 12;
  4923. MeshVG._POOL = [];
  4924. class WebGLCacheAsNormalCanvas {
  4925. constructor(ctx, sp) {
  4926. this.submitStartPos = 0;
  4927. this.submitEndPos = 0;
  4928. this.context = null;
  4929. this.touches = [];
  4930. this.submits = [];
  4931. this.sprite = null;
  4932. this.meshlist = [];
  4933. this.cachedClipInfo = new Matrix();
  4934. this.oldTx = 0;
  4935. this.oldTy = 0;
  4936. this.invMat = new Matrix();
  4937. this.context = ctx;
  4938. this.sprite = sp;
  4939. ctx._globalClipMatrix.copyTo(this.cachedClipInfo);
  4940. }
  4941. startRec() {
  4942. if (this.context._charSubmitCache._enbale) {
  4943. this.context._charSubmitCache.enable(false, this.context);
  4944. this.context._charSubmitCache.enable(true, this.context);
  4945. }
  4946. this.context._incache = true;
  4947. this.touches.length = 0;
  4948. this.context.touches = this.touches;
  4949. this.context._globalClipMatrix.copyTo(this.cachedClipInfo);
  4950. this.submits.length = 0;
  4951. this.submitStartPos = this.context._submits._length;
  4952. for (var i = 0, sz = this.meshlist.length; i < sz; i++) {
  4953. var curm = this.meshlist[i];
  4954. curm.canReuse ? (curm.releaseMesh()) : (curm.destroy());
  4955. }
  4956. this.meshlist.length = 0;
  4957. this._mesh = MeshQuadTexture.getAMesh(false);
  4958. this._pathMesh = MeshVG.getAMesh(false);
  4959. this._triangleMesh = MeshTexture.getAMesh(false);
  4960. this.meshlist.push(this._mesh);
  4961. this.meshlist.push(this._pathMesh);
  4962. this.meshlist.push(this._triangleMesh);
  4963. this.context._curSubmit = SubmitBase.RENDERBASE;
  4964. this._oldMesh = this.context._mesh;
  4965. this._oldPathMesh = this.context._pathMesh;
  4966. this._oldTriMesh = this.context._triangleMesh;
  4967. this._oldMeshList = this.context.meshlist;
  4968. this.context._mesh = this._mesh;
  4969. this.context._pathMesh = this._pathMesh;
  4970. this.context._triangleMesh = this._triangleMesh;
  4971. this.context.meshlist = this.meshlist;
  4972. this.oldTx = this.context._curMat.tx;
  4973. this.oldTy = this.context._curMat.ty;
  4974. this.context._curMat.tx = 0;
  4975. this.context._curMat.ty = 0;
  4976. this.context._curMat.copyTo(this.invMat);
  4977. this.invMat.invert();
  4978. }
  4979. endRec() {
  4980. if (this.context._charSubmitCache._enbale) {
  4981. this.context._charSubmitCache.enable(false, this.context);
  4982. this.context._charSubmitCache.enable(true, this.context);
  4983. }
  4984. var parsubmits = this.context._submits;
  4985. this.submitEndPos = parsubmits._length;
  4986. var num = this.submitEndPos - this.submitStartPos;
  4987. for (var i = 0; i < num; i++) {
  4988. this.submits.push(parsubmits[this.submitStartPos + i]);
  4989. }
  4990. parsubmits._length -= num;
  4991. this.context._mesh = this._oldMesh;
  4992. this.context._pathMesh = this._oldPathMesh;
  4993. this.context._triangleMesh = this._oldTriMesh;
  4994. this.context.meshlist = this._oldMeshList;
  4995. this.context._curSubmit = SubmitBase.RENDERBASE;
  4996. this.context._curMat.tx = this.oldTx;
  4997. this.context._curMat.ty = this.oldTy;
  4998. this.context.touches = null;
  4999. this.context._incache = false;
  5000. }
  5001. isCacheValid() {
  5002. var curclip = this.context._globalClipMatrix;
  5003. if (curclip.a != this.cachedClipInfo.a || curclip.b != this.cachedClipInfo.b || curclip.c != this.cachedClipInfo.c
  5004. || curclip.d != this.cachedClipInfo.d || curclip.tx != this.cachedClipInfo.tx || curclip.ty != this.cachedClipInfo.ty)
  5005. return false;
  5006. return true;
  5007. }
  5008. flushsubmit() {
  5009. var curSubmit = SubmitBase.RENDERBASE;
  5010. this.submits.forEach(function (subm) {
  5011. if (subm == SubmitBase.RENDERBASE)
  5012. return;
  5013. SubmitBase.preRender = curSubmit;
  5014. curSubmit = subm;
  5015. subm.renderSubmit();
  5016. });
  5017. }
  5018. releaseMem() {
  5019. }
  5020. }
  5021. WebGLCacheAsNormalCanvas.matI = new Matrix();
  5022. 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}";
  5023. var texture_ps = "/*\r\n\ttexture和fillrect使用的。\r\n*/\r\n#ifdef FSHIGHPRECISION\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}";
  5024. 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}";
  5025. 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}";
  5026. 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}";
  5027. 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}";
  5028. class Shader2D {
  5029. constructor() {
  5030. this.ALPHA = 1;
  5031. this.defines = new ShaderDefines2D();
  5032. this.shaderType = 0;
  5033. this.fillStyle = DrawStyle.DEFAULT;
  5034. this.strokeStyle = DrawStyle.DEFAULT;
  5035. }
  5036. destroy() {
  5037. this.defines = null;
  5038. this.filters = null;
  5039. }
  5040. static __init__() {
  5041. Shader.preCompile2D(0, ShaderDefines2D.TEXTURE2D, texture_vs, texture_ps, null);
  5042. Shader.preCompile2D(0, ShaderDefines2D.PRIMITIVE, prime_vs, prime_ps, null);
  5043. Shader.preCompile2D(0, ShaderDefines2D.SKINMESH, skin_vs, skin_ps, null);
  5044. }
  5045. }
  5046. class SkinMeshBuffer {
  5047. constructor() {
  5048. var gl = LayaGL.instance;
  5049. this.ib = IndexBuffer2D.create(gl.DYNAMIC_DRAW);
  5050. this.vb = VertexBuffer2D.create(8);
  5051. }
  5052. static getInstance() {
  5053. return SkinMeshBuffer.instance = SkinMeshBuffer.instance || new SkinMeshBuffer();
  5054. }
  5055. addSkinMesh(skinMesh) {
  5056. skinMesh.getData2(this.vb, this.ib, this.vb._byteLength / 32);
  5057. }
  5058. reset() {
  5059. this.vb.clear();
  5060. this.ib.clear();
  5061. }
  5062. }
  5063. class BasePoly {
  5064. static createLine2(p, indices, lineWidth, indexBase, outVertex, loop) {
  5065. if (p.length < 4)
  5066. return null;
  5067. var points = BasePoly.tempData.length > (p.length + 2) ? BasePoly.tempData : new Array(p.length + 2);
  5068. points[0] = p[0];
  5069. points[1] = p[1];
  5070. var newlen = 2;
  5071. var i = 0;
  5072. var length = p.length;
  5073. for (i = 2; i < length; i += 2) {
  5074. if (Math.abs(p[i] - p[i - 2]) + Math.abs(p[i + 1] - p[i - 1]) > 0.01) {
  5075. points[newlen++] = p[i];
  5076. points[newlen++] = p[i + 1];
  5077. }
  5078. }
  5079. if (loop && Math.abs(p[0] - points[newlen - 2]) + Math.abs(p[1] - points[newlen - 1]) > 0.01) {
  5080. points[newlen++] = p[0];
  5081. points[newlen++] = p[1];
  5082. }
  5083. var result = outVertex;
  5084. length = newlen / 2;
  5085. var w = lineWidth / 2;
  5086. var px, py, p1x, p1y, p2x, p2y, p3x, p3y;
  5087. var perpx, perpy, perp2x, perp2y;
  5088. var a1, b1, c1, a2, b2, c2;
  5089. var denom, dist;
  5090. p1x = points[0];
  5091. p1y = points[1];
  5092. p2x = points[2];
  5093. p2y = points[3];
  5094. perpx = -(p1y - p2y);
  5095. perpy = p1x - p2x;
  5096. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5097. perpx = perpx / dist * w;
  5098. perpy = perpy / dist * w;
  5099. result.push(p1x - perpx, p1y - perpy, p1x + perpx, p1y + perpy);
  5100. for (i = 1; i < length - 1; i++) {
  5101. p1x = points[(i - 1) * 2];
  5102. p1y = points[(i - 1) * 2 + 1];
  5103. p2x = points[(i) * 2];
  5104. p2y = points[(i) * 2 + 1];
  5105. p3x = points[(i + 1) * 2];
  5106. p3y = points[(i + 1) * 2 + 1];
  5107. perpx = -(p1y - p2y);
  5108. perpy = p1x - p2x;
  5109. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5110. perpx = perpx / dist * w;
  5111. perpy = perpy / dist * w;
  5112. perp2x = -(p2y - p3y);
  5113. perp2y = p2x - p3x;
  5114. dist = Math.sqrt(perp2x * perp2x + perp2y * perp2y);
  5115. perp2x = perp2x / dist * w;
  5116. perp2y = perp2y / dist * w;
  5117. a1 = (-perpy + p1y) - (-perpy + p2y);
  5118. b1 = (-perpx + p2x) - (-perpx + p1x);
  5119. c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y);
  5120. a2 = (-perp2y + p3y) - (-perp2y + p2y);
  5121. b2 = (-perp2x + p2x) - (-perp2x + p3x);
  5122. c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y);
  5123. denom = a1 * b2 - a2 * b1;
  5124. if (Math.abs(denom) < 0.1) {
  5125. denom += 10.1;
  5126. result.push(p2x - perpx, p2y - perpy, p2x + perpx, p2y + perpy);
  5127. continue;
  5128. }
  5129. px = (b1 * c2 - b2 * c1) / denom;
  5130. py = (a2 * c1 - a1 * c2) / denom;
  5131. result.push(px, py, p2x - (px - p2x), p2y - (py - p2y));
  5132. }
  5133. p1x = points[newlen - 4];
  5134. p1y = points[newlen - 3];
  5135. p2x = points[newlen - 2];
  5136. p2y = points[newlen - 1];
  5137. perpx = -(p1y - p2y);
  5138. perpy = p1x - p2x;
  5139. dist = Math.sqrt(perpx * perpx + perpy * perpy);
  5140. perpx = perpx / dist * w;
  5141. perpy = perpy / dist * w;
  5142. result.push(p2x - perpx, p2y - perpy, p2x + perpx, p2y + perpy);
  5143. for (i = 1; i < length; i++) {
  5144. 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);
  5145. }
  5146. return result;
  5147. }
  5148. static createLineTriangle(path, color, width, loop, outvb, vbstride, outib) {
  5149. var points = path.slice();
  5150. var ptlen = points.length;
  5151. var p1x = points[0], p1y = points[1];
  5152. var p2x = points[2], p2y = points[2];
  5153. var len = 0;
  5154. var rp = 0;
  5155. var dx = 0, dy = 0;
  5156. var pointnum = ptlen / 2;
  5157. if (pointnum <= 1)
  5158. return;
  5159. if (pointnum == 2) {
  5160. return;
  5161. }
  5162. var tmpData = new Array(pointnum * 4);
  5163. var realPtNum = 0;
  5164. var ci = 0;
  5165. for (var i = 0; i < pointnum - 1; i++) {
  5166. p1x = points[ci++], p1y = points[ci++];
  5167. p2x = points[ci++], p2y = points[ci++];
  5168. dx = p2x - p1x, dy = p2y - p1y;
  5169. if (dx != 0 && dy != 0) {
  5170. len = Math.sqrt(dx * dx + dy * dy);
  5171. if (len > 1e-3) {
  5172. rp = realPtNum * 4;
  5173. tmpData[rp] = p1x;
  5174. tmpData[rp + 1] = p1y;
  5175. tmpData[rp + 2] = dx / len;
  5176. tmpData[rp + 3] = dy / len;
  5177. realPtNum++;
  5178. }
  5179. }
  5180. }
  5181. if (loop) {
  5182. p1x = points[ptlen - 2], p1y = points[ptlen - 1];
  5183. p2x = points[0], p2y = points[1];
  5184. dx = p2x - p1x, dy = p2y - p1y;
  5185. if (dx != 0 && dy != 0) {
  5186. len = Math.sqrt(dx * dx + dy * dy);
  5187. if (len > 1e-3) {
  5188. rp = realPtNum * 4;
  5189. tmpData[rp] = p1x;
  5190. tmpData[rp + 1] = p1y;
  5191. tmpData[rp + 2] = dx / len;
  5192. tmpData[rp + 3] = dy / len;
  5193. realPtNum++;
  5194. }
  5195. }
  5196. }
  5197. else {
  5198. rp = realPtNum * 4;
  5199. tmpData[rp] = p1x;
  5200. tmpData[rp + 1] = p1y;
  5201. tmpData[rp + 2] = dx / len;
  5202. tmpData[rp + 3] = dy / len;
  5203. realPtNum++;
  5204. }
  5205. ci = 0;
  5206. for (i = 0; i < pointnum; i++) {
  5207. p1x = points[ci], p1y = points[ci + 1];
  5208. p2x = points[ci + 2], p2y = points[ci + 3];
  5209. var p3x = points[ci + 4], p3y = points[ci + 5];
  5210. }
  5211. }
  5212. }
  5213. BasePoly.tempData = new Array(256);
  5214. class EarcutNode {
  5215. constructor(i, x, y) {
  5216. this.i = i;
  5217. this.x = x;
  5218. this.y = y;
  5219. this.prev = null;
  5220. this.next = null;
  5221. this.z = null;
  5222. this.prevZ = null;
  5223. this.nextZ = null;
  5224. this.steiner = false;
  5225. }
  5226. }
  5227. class Earcut {
  5228. static earcut(data, holeIndices, dim) {
  5229. dim = dim || 2;
  5230. var hasHoles = holeIndices && holeIndices.length, outerLen = hasHoles ? holeIndices[0] * dim : data.length, outerNode = Earcut.linkedList(data, 0, outerLen, dim, true), triangles = [];
  5231. if (!outerNode)
  5232. return triangles;
  5233. var minX, minY, maxX, maxY, x, y, invSize;
  5234. if (hasHoles)
  5235. outerNode = Earcut.eliminateHoles(data, holeIndices, outerNode, dim);
  5236. if (data.length > 80 * dim) {
  5237. minX = maxX = data[0];
  5238. minY = maxY = data[1];
  5239. for (var i = dim; i < outerLen; i += dim) {
  5240. x = data[i];
  5241. y = data[i + 1];
  5242. if (x < minX)
  5243. minX = x;
  5244. if (y < minY)
  5245. minY = y;
  5246. if (x > maxX)
  5247. maxX = x;
  5248. if (y > maxY)
  5249. maxY = y;
  5250. }
  5251. invSize = Math.max(maxX - minX, maxY - minY);
  5252. invSize = invSize !== 0 ? 1 / invSize : 0;
  5253. }
  5254. Earcut.earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  5255. return triangles;
  5256. }
  5257. static linkedList(data, start, end, dim, clockwise) {
  5258. var i, last;
  5259. if (clockwise === (Earcut.signedArea(data, start, end, dim) > 0)) {
  5260. for (i = start; i < end; i += dim)
  5261. last = Earcut.insertNode(i, data[i], data[i + 1], last);
  5262. }
  5263. else {
  5264. for (i = end - dim; i >= start; i -= dim)
  5265. last = Earcut.insertNode(i, data[i], data[i + 1], last);
  5266. }
  5267. if (last && Earcut.equals(last, last.next)) {
  5268. Earcut.removeNode(last);
  5269. last = last.next;
  5270. }
  5271. return last;
  5272. }
  5273. static filterPoints(start, end) {
  5274. if (!start)
  5275. return start;
  5276. if (!end)
  5277. end = start;
  5278. var p = start, again;
  5279. do {
  5280. again = false;
  5281. if (!p.steiner && (Earcut.equals(p, p.next) || Earcut.area(p.prev, p, p.next) === 0)) {
  5282. Earcut.removeNode(p);
  5283. p = end = p.prev;
  5284. if (p === p.next)
  5285. break;
  5286. again = true;
  5287. }
  5288. else {
  5289. p = p.next;
  5290. }
  5291. } while (again || p !== end);
  5292. return end;
  5293. }
  5294. static earcutLinked(ear, triangles, dim, minX, minY, invSize, pass = null) {
  5295. if (!ear)
  5296. return;
  5297. if (!pass && invSize)
  5298. Earcut.indexCurve(ear, minX, minY, invSize);
  5299. var stop = ear, prev, next;
  5300. while (ear.prev !== ear.next) {
  5301. prev = ear.prev;
  5302. next = ear.next;
  5303. if (invSize ? Earcut.isEarHashed(ear, minX, minY, invSize) : Earcut.isEar(ear)) {
  5304. triangles.push(prev.i / dim);
  5305. triangles.push(ear.i / dim);
  5306. triangles.push(next.i / dim);
  5307. Earcut.removeNode(ear);
  5308. ear = next.next;
  5309. stop = next.next;
  5310. continue;
  5311. }
  5312. ear = next;
  5313. if (ear === stop) {
  5314. if (!pass) {
  5315. Earcut.earcutLinked(Earcut.filterPoints(ear, null), triangles, dim, minX, minY, invSize, 1);
  5316. }
  5317. else if (pass === 1) {
  5318. ear = Earcut.cureLocalIntersections(ear, triangles, dim);
  5319. Earcut.earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
  5320. }
  5321. else if (pass === 2) {
  5322. Earcut.splitEarcut(ear, triangles, dim, minX, minY, invSize);
  5323. }
  5324. break;
  5325. }
  5326. }
  5327. }
  5328. static isEar(ear) {
  5329. var a = ear.prev, b = ear, c = ear.next;
  5330. if (Earcut.area(a, b, c) >= 0)
  5331. return false;
  5332. var p = ear.next.next;
  5333. while (p !== ear.prev) {
  5334. if (Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5335. Earcut.area(p.prev, p, p.next) >= 0)
  5336. return false;
  5337. p = p.next;
  5338. }
  5339. return true;
  5340. }
  5341. static isEarHashed(ear, minX, minY, invSize) {
  5342. var a = ear.prev, b = ear, c = ear.next;
  5343. if (Earcut.area(a, b, c) >= 0)
  5344. return false;
  5345. 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);
  5346. var minZ = Earcut.zOrder(minTX, minTY, minX, minY, invSize), maxZ = Earcut.zOrder(maxTX, maxTY, minX, minY, invSize);
  5347. var p = ear.nextZ;
  5348. while (p && p.z <= maxZ) {
  5349. if (p !== ear.prev && p !== ear.next &&
  5350. Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5351. Earcut.area(p.prev, p, p.next) >= 0)
  5352. return false;
  5353. p = p.nextZ;
  5354. }
  5355. p = ear.prevZ;
  5356. while (p && p.z >= minZ) {
  5357. if (p !== ear.prev && p !== ear.next &&
  5358. Earcut.pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  5359. Earcut.area(p.prev, p, p.next) >= 0)
  5360. return false;
  5361. p = p.prevZ;
  5362. }
  5363. return true;
  5364. }
  5365. static cureLocalIntersections(start, triangles, dim) {
  5366. var p = start;
  5367. do {
  5368. var a = p.prev, b = p.next.next;
  5369. if (!Earcut.equals(a, b) && Earcut.intersects(a, p, p.next, b) && Earcut.locallyInside(a, b) && Earcut.locallyInside(b, a)) {
  5370. triangles.push(a.i / dim);
  5371. triangles.push(p.i / dim);
  5372. triangles.push(b.i / dim);
  5373. Earcut.removeNode(p);
  5374. Earcut.removeNode(p.next);
  5375. p = start = b;
  5376. }
  5377. p = p.next;
  5378. } while (p !== start);
  5379. return p;
  5380. }
  5381. static splitEarcut(start, triangles, dim, minX, minY, invSize) {
  5382. var a = start;
  5383. do {
  5384. var b = a.next.next;
  5385. while (b !== a.prev) {
  5386. if (a.i !== b.i && Earcut.isValidDiagonal(a, b)) {
  5387. var c = Earcut.splitPolygon(a, b);
  5388. a = Earcut.filterPoints(a, a.next);
  5389. c = Earcut.filterPoints(c, c.next);
  5390. Earcut.earcutLinked(a, triangles, dim, minX, minY, invSize);
  5391. Earcut.earcutLinked(c, triangles, dim, minX, minY, invSize);
  5392. return;
  5393. }
  5394. b = b.next;
  5395. }
  5396. a = a.next;
  5397. } while (a !== start);
  5398. }
  5399. static eliminateHoles(data, holeIndices, outerNode, dim) {
  5400. var queue = [], i, len, start, end, list;
  5401. for (i = 0, len = holeIndices.length; i < len; i++) {
  5402. start = holeIndices[i] * dim;
  5403. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  5404. list = Earcut.linkedList(data, start, end, dim, false);
  5405. if (list === list.next)
  5406. list.steiner = true;
  5407. queue.push(Earcut.getLeftmost(list));
  5408. }
  5409. queue.sort(Earcut.compareX);
  5410. for (i = 0; i < queue.length; i++) {
  5411. Earcut.eliminateHole(queue[i], outerNode);
  5412. outerNode = Earcut.filterPoints(outerNode, outerNode.next);
  5413. }
  5414. return outerNode;
  5415. }
  5416. static compareX(a, b) {
  5417. return a.x - b.x;
  5418. }
  5419. static eliminateHole(hole, outerNode) {
  5420. outerNode = Earcut.findHoleBridge(hole, outerNode);
  5421. if (outerNode) {
  5422. var b = Earcut.splitPolygon(outerNode, hole);
  5423. Earcut.filterPoints(b, b.next);
  5424. }
  5425. }
  5426. static findHoleBridge(hole, outerNode) {
  5427. var p = outerNode, hx = hole.x, hy = hole.y, qx = -Infinity, m;
  5428. do {
  5429. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  5430. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  5431. if (x <= hx && x > qx) {
  5432. qx = x;
  5433. if (x === hx) {
  5434. if (hy === p.y)
  5435. return p;
  5436. if (hy === p.next.y)
  5437. return p.next;
  5438. }
  5439. m = p.x < p.next.x ? p : p.next;
  5440. }
  5441. }
  5442. p = p.next;
  5443. } while (p !== outerNode);
  5444. if (!m)
  5445. return null;
  5446. if (hx === qx)
  5447. return m.prev;
  5448. var stop = m, mx = m.x, my = m.y, tanMin = Infinity, tan;
  5449. p = m.next;
  5450. while (p !== stop) {
  5451. if (hx >= p.x && p.x >= mx && hx !== p.x &&
  5452. Earcut.pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  5453. tan = Math.abs(hy - p.y) / (hx - p.x);
  5454. if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && Earcut.locallyInside(p, hole)) {
  5455. m = p;
  5456. tanMin = tan;
  5457. }
  5458. }
  5459. p = p.next;
  5460. }
  5461. return m;
  5462. }
  5463. static indexCurve(start, minX, minY, invSize) {
  5464. var p = start;
  5465. do {
  5466. if (p.z === null)
  5467. p.z = Earcut.zOrder(p.x, p.y, minX, minY, invSize);
  5468. p.prevZ = p.prev;
  5469. p.nextZ = p.next;
  5470. p = p.next;
  5471. } while (p !== start);
  5472. p.prevZ.nextZ = null;
  5473. p.prevZ = null;
  5474. Earcut.sortLinked(p);
  5475. }
  5476. static sortLinked(list) {
  5477. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  5478. do {
  5479. p = list;
  5480. list = null;
  5481. tail = null;
  5482. numMerges = 0;
  5483. while (p) {
  5484. numMerges++;
  5485. q = p;
  5486. pSize = 0;
  5487. for (i = 0; i < inSize; i++) {
  5488. pSize++;
  5489. q = q.nextZ;
  5490. if (!q)
  5491. break;
  5492. }
  5493. qSize = inSize;
  5494. while (pSize > 0 || (qSize > 0 && q)) {
  5495. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  5496. e = p;
  5497. p = p.nextZ;
  5498. pSize--;
  5499. }
  5500. else {
  5501. e = q;
  5502. q = q.nextZ;
  5503. qSize--;
  5504. }
  5505. if (tail)
  5506. tail.nextZ = e;
  5507. else
  5508. list = e;
  5509. e.prevZ = tail;
  5510. tail = e;
  5511. }
  5512. p = q;
  5513. }
  5514. tail.nextZ = null;
  5515. inSize *= 2;
  5516. } while (numMerges > 1);
  5517. return list;
  5518. }
  5519. static zOrder(x, y, minX, minY, invSize) {
  5520. x = 32767 * (x - minX) * invSize;
  5521. y = 32767 * (y - minY) * invSize;
  5522. x = (x | (x << 8)) & 0x00FF00FF;
  5523. x = (x | (x << 4)) & 0x0F0F0F0F;
  5524. x = (x | (x << 2)) & 0x33333333;
  5525. x = (x | (x << 1)) & 0x55555555;
  5526. y = (y | (y << 8)) & 0x00FF00FF;
  5527. y = (y | (y << 4)) & 0x0F0F0F0F;
  5528. y = (y | (y << 2)) & 0x33333333;
  5529. y = (y | (y << 1)) & 0x55555555;
  5530. return x | (y << 1);
  5531. }
  5532. static getLeftmost(start) {
  5533. var p = start, leftmost = start;
  5534. do {
  5535. if (p.x < leftmost.x)
  5536. leftmost = p;
  5537. p = p.next;
  5538. } while (p !== start);
  5539. return leftmost;
  5540. }
  5541. static pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  5542. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
  5543. (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
  5544. (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  5545. }
  5546. static isValidDiagonal(a, b) {
  5547. return a.next.i !== b.i && a.prev.i !== b.i && !Earcut.intersectsPolygon(a, b) &&
  5548. Earcut.locallyInside(a, b) && Earcut.locallyInside(b, a) && Earcut.middleInside(a, b);
  5549. }
  5550. static area(p, q, r) {
  5551. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  5552. }
  5553. static equals(p1, p2) {
  5554. return p1.x === p2.x && p1.y === p2.y;
  5555. }
  5556. static intersects(p1, q1, p2, q2) {
  5557. if ((Earcut.equals(p1, q1) && Earcut.equals(p2, q2)) ||
  5558. (Earcut.equals(p1, q2) && Earcut.equals(p2, q1)))
  5559. return true;
  5560. return Earcut.area(p1, q1, p2) > 0 !== Earcut.area(p1, q1, q2) > 0 &&
  5561. Earcut.area(p2, q2, p1) > 0 !== Earcut.area(p2, q2, q1) > 0;
  5562. }
  5563. static intersectsPolygon(a, b) {
  5564. var p = a;
  5565. do {
  5566. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  5567. Earcut.intersects(p, p.next, a, b))
  5568. return true;
  5569. p = p.next;
  5570. } while (p !== a);
  5571. return false;
  5572. }
  5573. static locallyInside(a, b) {
  5574. return Earcut.area(a.prev, a, a.next) < 0 ?
  5575. Earcut.area(a, b, a.next) >= 0 && Earcut.area(a, a.prev, b) >= 0 :
  5576. Earcut.area(a, b, a.prev) < 0 || Earcut.area(a, a.next, b) < 0;
  5577. }
  5578. static middleInside(a, b) {
  5579. var p = a, inside = false, px = (a.x + b.x) / 2, py = (a.y + b.y) / 2;
  5580. do {
  5581. if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
  5582. (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  5583. inside = !inside;
  5584. p = p.next;
  5585. } while (p !== a);
  5586. return inside;
  5587. }
  5588. static splitPolygon(a, b) {
  5589. 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;
  5590. a.next = b;
  5591. b.prev = a;
  5592. a2.next = an;
  5593. an.prev = a2;
  5594. b2.next = a2;
  5595. a2.prev = b2;
  5596. bp.next = b2;
  5597. b2.prev = bp;
  5598. return b2;
  5599. }
  5600. static insertNode(i, x, y, last) {
  5601. var p = new EarcutNode(i, x, y);
  5602. if (!last) {
  5603. p.prev = p;
  5604. p.next = p;
  5605. }
  5606. else {
  5607. p.next = last.next;
  5608. p.prev = last;
  5609. last.next.prev = p;
  5610. last.next = p;
  5611. }
  5612. return p;
  5613. }
  5614. static removeNode(p) {
  5615. p.next.prev = p.prev;
  5616. p.prev.next = p.next;
  5617. if (p.prevZ)
  5618. p.prevZ.nextZ = p.nextZ;
  5619. if (p.nextZ)
  5620. p.nextZ.prevZ = p.prevZ;
  5621. }
  5622. static signedArea(data, start, end, dim) {
  5623. var sum = 0;
  5624. for (var i = start, j = end - dim; i < end; i += dim) {
  5625. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  5626. j = i;
  5627. }
  5628. return sum;
  5629. }
  5630. }
  5631. class CONST3D2D {
  5632. }
  5633. CONST3D2D.BYTES_PE = 4;
  5634. CONST3D2D.BYTES_PIDX = 2;
  5635. CONST3D2D.defaultMatrix4 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  5636. CONST3D2D.defaultMinusYMatrix4 = [1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  5637. CONST3D2D.uniformMatrix3 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0];
  5638. CONST3D2D._TMPARRAY = [];
  5639. CONST3D2D._OFFSETX = 0;
  5640. CONST3D2D._OFFSETY = 0;
  5641. class Submit extends SubmitBase {
  5642. constructor(renderType = SubmitBase.TYPE_2D) {
  5643. super(renderType);
  5644. }
  5645. renderSubmit() {
  5646. if (this._numEle === 0 || !this._mesh || this._numEle == 0)
  5647. return 1;
  5648. var _tex = this.shaderValue.textureHost;
  5649. if (_tex) {
  5650. var source = _tex._getSource();
  5651. if (!source)
  5652. return 1;
  5653. this.shaderValue.texture = source;
  5654. }
  5655. var gl = WebGLContext.mainContext;
  5656. this._mesh.useMesh(gl);
  5657. this.shaderValue.upload();
  5658. if (BlendMode.activeBlendFunction !== this._blendFn) {
  5659. WebGLContext.setBlend(gl, true);
  5660. this._blendFn(gl);
  5661. BlendMode.activeBlendFunction = this._blendFn;
  5662. }
  5663. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5664. Stat.renderBatches++;
  5665. Stat.trianglesFaces += this._numEle / 3;
  5666. return 1;
  5667. }
  5668. releaseRender() {
  5669. if (SubmitBase.RENDERBASE == this)
  5670. return;
  5671. if ((--this._ref) < 1) {
  5672. Submit.POOL[Submit._poolSize++] = this;
  5673. this.shaderValue.release();
  5674. this.shaderValue = null;
  5675. this._mesh = null;
  5676. this._parent && (this._parent.releaseRender(), this._parent = null);
  5677. }
  5678. }
  5679. static create(context, mesh, sv) {
  5680. var o = Submit._poolSize ? Submit.POOL[--Submit._poolSize] : new Submit();
  5681. o._ref = 1;
  5682. o._mesh = mesh;
  5683. o._key.clear();
  5684. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5685. o._numEle = 0;
  5686. var blendType = context._nBlendType;
  5687. o._blendFn = context._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5688. o.shaderValue = sv;
  5689. o.shaderValue.setValue(context._shader2D);
  5690. var filters = context._shader2D.filters;
  5691. filters && o.shaderValue.setFilters(filters);
  5692. return o;
  5693. }
  5694. static createShape(ctx, mesh, numEle, sv) {
  5695. var o = Submit._poolSize ? Submit.POOL[--Submit._poolSize] : (new Submit());
  5696. o._mesh = mesh;
  5697. o._numEle = numEle;
  5698. o._startIdx = mesh.indexNum * 2;
  5699. o._ref = 1;
  5700. o.shaderValue = sv;
  5701. o.shaderValue.setValue(ctx._shader2D);
  5702. var blendType = ctx._nBlendType;
  5703. o._key.blendShader = blendType;
  5704. o._blendFn = ctx._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5705. return o;
  5706. }
  5707. }
  5708. Submit._poolSize = 0;
  5709. Submit.POOL = [];
  5710. class SubmitCanvas extends SubmitBase {
  5711. constructor() {
  5712. super(SubmitBase.TYPE_2D);
  5713. this._matrix = new Matrix();
  5714. this._matrix4 = CONST3D2D.defaultMatrix4.concat();
  5715. this.shaderValue = new Value2D(0, 0);
  5716. }
  5717. static create(canvas, alpha, filters) {
  5718. var o = (!SubmitCanvas.POOL._length) ? (new SubmitCanvas()) : SubmitCanvas.POOL[--SubmitCanvas.POOL._length];
  5719. o.canv = canvas;
  5720. o._ref = 1;
  5721. o._numEle = 0;
  5722. var v = o.shaderValue;
  5723. v.alpha = alpha;
  5724. v.defines.setValue(0);
  5725. filters && filters.length && v.setFilters(filters);
  5726. return o;
  5727. }
  5728. renderSubmit() {
  5729. var preAlpha = RenderState2D.worldAlpha;
  5730. var preMatrix4 = RenderState2D.worldMatrix4;
  5731. var preMatrix = RenderState2D.worldMatrix;
  5732. var preFilters = RenderState2D.worldFilters;
  5733. var preWorldShaderDefines = RenderState2D.worldShaderDefines;
  5734. var v = this.shaderValue;
  5735. var m = this._matrix;
  5736. var m4 = this._matrix4;
  5737. var mout = Matrix.TEMP;
  5738. Matrix.mul(m, preMatrix, mout);
  5739. m4[0] = mout.a;
  5740. m4[1] = mout.b;
  5741. m4[4] = mout.c;
  5742. m4[5] = mout.d;
  5743. m4[12] = mout.tx;
  5744. m4[13] = mout.ty;
  5745. RenderState2D.worldMatrix = mout.clone();
  5746. RenderState2D.worldMatrix4 = m4;
  5747. RenderState2D.worldAlpha = RenderState2D.worldAlpha * v.alpha;
  5748. if (v.filters && v.filters.length) {
  5749. RenderState2D.worldFilters = v.filters;
  5750. RenderState2D.worldShaderDefines = v.defines;
  5751. }
  5752. this.canv['flushsubmit']();
  5753. RenderState2D.worldAlpha = preAlpha;
  5754. RenderState2D.worldMatrix4 = preMatrix4;
  5755. RenderState2D.worldMatrix.destroy();
  5756. RenderState2D.worldMatrix = preMatrix;
  5757. RenderState2D.worldFilters = preFilters;
  5758. RenderState2D.worldShaderDefines = preWorldShaderDefines;
  5759. return 1;
  5760. }
  5761. releaseRender() {
  5762. if ((--this._ref) < 1) {
  5763. var cache = SubmitCanvas.POOL;
  5764. this._mesh = null;
  5765. cache[cache._length++] = this;
  5766. }
  5767. }
  5768. getRenderType() {
  5769. return SubmitBase.TYPE_CANVAS;
  5770. }
  5771. ;
  5772. }
  5773. SubmitCanvas.POOL = [];
  5774. {
  5775. SubmitCanvas.POOL._length = 0;
  5776. }
  5777. class SubmitTarget {
  5778. constructor() {
  5779. this.blendType = 0;
  5780. this._ref = 1;
  5781. this._key = new SubmitKey();
  5782. }
  5783. renderSubmit() {
  5784. var gl = WebGLContext.mainContext;
  5785. this._mesh.useMesh(gl);
  5786. var target = this.srcRT;
  5787. if (target) {
  5788. this.shaderValue.texture = target._getSource();
  5789. this.shaderValue.upload();
  5790. this.blend();
  5791. Stat.renderBatches++;
  5792. Stat.trianglesFaces += this._numEle / 3;
  5793. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5794. }
  5795. return 1;
  5796. }
  5797. blend() {
  5798. if (BlendMode.activeBlendFunction !== BlendMode.fns[this.blendType]) {
  5799. var gl = WebGLContext.mainContext;
  5800. gl.enable(gl.BLEND);
  5801. BlendMode.fns[this.blendType](gl);
  5802. BlendMode.activeBlendFunction = BlendMode.fns[this.blendType];
  5803. }
  5804. }
  5805. getRenderType() {
  5806. return 0;
  5807. }
  5808. releaseRender() {
  5809. if ((--this._ref) < 1) {
  5810. var pool = SubmitTarget.POOL;
  5811. pool[pool._length++] = this;
  5812. }
  5813. }
  5814. static create(context, mesh, sv, rt) {
  5815. var o = SubmitTarget.POOL._length ? SubmitTarget.POOL[--SubmitTarget.POOL._length] : new SubmitTarget();
  5816. o._mesh = mesh;
  5817. o.srcRT = rt;
  5818. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5819. o._ref = 1;
  5820. o._key.clear();
  5821. o._numEle = 0;
  5822. o.blendType = context._nBlendType;
  5823. o._key.blendShader = o.blendType;
  5824. o.shaderValue = sv;
  5825. o.shaderValue.setValue(context._shader2D);
  5826. if (context._colorFiler) {
  5827. var ft = context._colorFiler;
  5828. sv.defines.add(ft.type);
  5829. sv.colorMat = ft._mat;
  5830. sv.colorAlpha = ft._alpha;
  5831. }
  5832. return o;
  5833. }
  5834. }
  5835. SubmitTarget.POOL = [];
  5836. {
  5837. SubmitTarget.POOL._length = 0;
  5838. }
  5839. class SubmitTexture extends SubmitBase {
  5840. constructor(renderType = SubmitBase.TYPE_2D) {
  5841. super(renderType);
  5842. }
  5843. releaseRender() {
  5844. if ((--this._ref) < 1) {
  5845. SubmitTexture.POOL[SubmitTexture._poolSize++] = this;
  5846. this.shaderValue.release();
  5847. this._mesh = null;
  5848. this._parent && (this._parent.releaseRender(), this._parent = null);
  5849. }
  5850. }
  5851. renderSubmit() {
  5852. if (this._numEle === 0)
  5853. return 1;
  5854. var tex = this.shaderValue.textureHost;
  5855. if (tex) {
  5856. var source = tex ? tex._getSource() : null;
  5857. if (!source)
  5858. return 1;
  5859. }
  5860. var gl = WebGLContext.mainContext;
  5861. this._mesh.useMesh(gl);
  5862. var lastSubmit = SubmitBase.preRender;
  5863. var prekey = SubmitBase.preRender._key;
  5864. if (this._key.blendShader === 0 && (this._key.submitType === prekey.submitType && this._key.blendShader === prekey.blendShader) && BaseShader.activeShader &&
  5865. SubmitBase.preRender.clipInfoID == this.clipInfoID &&
  5866. lastSubmit.shaderValue.defines._value === this.shaderValue.defines._value &&
  5867. (this.shaderValue.defines._value & ShaderDefines2D.NOOPTMASK) == 0) {
  5868. BaseShader.activeShader.uploadTexture2D(source);
  5869. }
  5870. else {
  5871. if (BlendMode.activeBlendFunction !== this._blendFn) {
  5872. WebGLContext.setBlend(gl, true);
  5873. this._blendFn(gl);
  5874. BlendMode.activeBlendFunction = this._blendFn;
  5875. }
  5876. this.shaderValue.texture = source;
  5877. this.shaderValue.upload();
  5878. }
  5879. gl.drawElements(gl.TRIANGLES, this._numEle, gl.UNSIGNED_SHORT, this._startIdx);
  5880. Stat.renderBatches++;
  5881. Stat.trianglesFaces += this._numEle / 3;
  5882. return 1;
  5883. }
  5884. static create(context, mesh, sv) {
  5885. var o = SubmitTexture._poolSize ? SubmitTexture.POOL[--SubmitTexture._poolSize] : new SubmitTexture(SubmitBase.TYPE_TEXTURE);
  5886. o._mesh = mesh;
  5887. o._key.clear();
  5888. o._key.submitType = SubmitBase.KEY_DRAWTEXTURE;
  5889. o._ref = 1;
  5890. o._startIdx = mesh.indexNum * CONST3D2D.BYTES_PIDX;
  5891. o._numEle = 0;
  5892. var blendType = context._nBlendType;
  5893. o._key.blendShader = blendType;
  5894. o._blendFn = context._targets ? BlendMode.targetFns[blendType] : BlendMode.fns[blendType];
  5895. o.shaderValue = sv;
  5896. if (context._colorFiler) {
  5897. var ft = context._colorFiler;
  5898. sv.defines.add(ft.type);
  5899. sv.colorMat = ft._mat;
  5900. sv.colorAlpha = ft._alpha;
  5901. }
  5902. return o;
  5903. }
  5904. }
  5905. SubmitTexture._poolSize = 0;
  5906. SubmitTexture.POOL = [];
  5907. class CharSubmitCache {
  5908. constructor() {
  5909. this._data = [];
  5910. this._ndata = 0;
  5911. this._clipid = -1;
  5912. this._clipMatrix = new Matrix();
  5913. this._enbale = false;
  5914. }
  5915. clear() {
  5916. this._tex = null;
  5917. this._imgId = -1;
  5918. this._ndata = 0;
  5919. this._enbale = false;
  5920. this._colorFiler = null;
  5921. }
  5922. destroy() {
  5923. this.clear();
  5924. this._data.length = 0;
  5925. this._data = null;
  5926. }
  5927. add(ctx, tex, imgid, pos, uv, color) {
  5928. if (this._ndata > 0 && (this._tex != tex || this._imgId != imgid ||
  5929. (this._clipid >= 0 && this._clipid != ctx._clipInfoID))) {
  5930. this.submit(ctx);
  5931. }
  5932. this._clipid = ctx._clipInfoID;
  5933. ctx._globalClipMatrix.copyTo(this._clipMatrix);
  5934. this._tex = tex;
  5935. this._imgId = imgid;
  5936. this._colorFiler = ctx._colorFiler;
  5937. this._data[this._ndata] = pos;
  5938. this._data[this._ndata + 1] = uv;
  5939. this._data[this._ndata + 2] = color;
  5940. this._ndata += 3;
  5941. }
  5942. getPos() {
  5943. if (CharSubmitCache.__nPosPool == 0)
  5944. return new Array(8);
  5945. return CharSubmitCache.__posPool[--CharSubmitCache.__nPosPool];
  5946. }
  5947. enable(value, ctx) {
  5948. if (value === this._enbale)
  5949. return;
  5950. this._enbale = value;
  5951. this._enbale || this.submit(ctx);
  5952. }
  5953. submit(ctx) {
  5954. var n = this._ndata;
  5955. if (!n)
  5956. return;
  5957. var _mesh = ctx._mesh;
  5958. var colorFiler = ctx._colorFiler;
  5959. ctx._colorFiler = this._colorFiler;
  5960. var submit = SubmitTexture.create(ctx, _mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  5961. ctx._submits[ctx._submits._length++] = ctx._curSubmit = submit;
  5962. submit.shaderValue.textureHost = this._tex;
  5963. submit._key.other = this._imgId;
  5964. ctx._colorFiler = colorFiler;
  5965. ctx._copyClipInfo(submit, this._clipMatrix);
  5966. submit.clipInfoID = this._clipid;
  5967. for (var i = 0; i < n; i += 3) {
  5968. _mesh.addQuad(this._data[i], this._data[i + 1], this._data[i + 2], true);
  5969. CharSubmitCache.__posPool[CharSubmitCache.__nPosPool++] = this._data[i];
  5970. }
  5971. n /= 3;
  5972. submit._numEle += n * 6;
  5973. _mesh.indexNum += n * 6;
  5974. _mesh.vertNum += n * 4;
  5975. ctx._drawCount += n;
  5976. this._ndata = 0;
  5977. if (RenderInfo.loopCount % 100 == 0)
  5978. this._data.length = 0;
  5979. }
  5980. }
  5981. CharSubmitCache.__posPool = [];
  5982. CharSubmitCache.__nPosPool = 0;
  5983. class AtlasGrid {
  5984. constructor(width = 0, height = 0, id = 0) {
  5985. this.atlasID = 0;
  5986. this._width = 0;
  5987. this._height = 0;
  5988. this._texCount = 0;
  5989. this._rowInfo = null;
  5990. this._cells = null;
  5991. this._used = 0;
  5992. this._cells = null;
  5993. this._rowInfo = null;
  5994. this.atlasID = id;
  5995. this._init(width, height);
  5996. }
  5997. addRect(type, width, height, pt) {
  5998. if (!this._get(width, height, pt))
  5999. return false;
  6000. this._fill(pt.x, pt.y, width, height, type);
  6001. this._texCount++;
  6002. return true;
  6003. }
  6004. _release() {
  6005. this._cells = null;
  6006. this._rowInfo = null;
  6007. }
  6008. _init(width, height) {
  6009. this._width = width;
  6010. this._height = height;
  6011. this._release();
  6012. if (this._width == 0)
  6013. return false;
  6014. this._cells = new Uint8Array(this._width * this._height * 3);
  6015. this._rowInfo = new Uint8Array(this._height);
  6016. this._used = 0;
  6017. this._clear();
  6018. return true;
  6019. }
  6020. _get(width, height, pt) {
  6021. if (width > this._width || height > this._height) {
  6022. return false;
  6023. }
  6024. var rx = -1;
  6025. var ry = -1;
  6026. var nWidth = this._width;
  6027. var nHeight = this._height;
  6028. var pCellBox = this._cells;
  6029. for (var y = 0; y < nHeight; y++) {
  6030. if (this._rowInfo[y] < width)
  6031. continue;
  6032. for (var x = 0; x < nWidth;) {
  6033. var tm = (y * nWidth + x) * 3;
  6034. if (pCellBox[tm] != 0 || pCellBox[tm + 1] < width || pCellBox[tm + 2] < height) {
  6035. x += pCellBox[tm + 1];
  6036. continue;
  6037. }
  6038. rx = x;
  6039. ry = y;
  6040. for (var xx = 0; xx < width; xx++) {
  6041. if (pCellBox[3 * xx + tm + 2] < height) {
  6042. rx = -1;
  6043. break;
  6044. }
  6045. }
  6046. if (rx < 0) {
  6047. x += pCellBox[tm + 1];
  6048. continue;
  6049. }
  6050. pt.x = rx;
  6051. pt.y = ry;
  6052. return true;
  6053. }
  6054. }
  6055. return false;
  6056. }
  6057. _fill(x, y, w, h, type) {
  6058. var nWidth = this._width;
  6059. var nHeghit = this._height;
  6060. this._check((x + w) <= nWidth && (y + h) <= nHeghit);
  6061. for (var yy = y; yy < (h + y); ++yy) {
  6062. this._check(this._rowInfo[yy] >= w);
  6063. this._rowInfo[yy] -= w;
  6064. for (var xx = 0; xx < w; xx++) {
  6065. var tm = (x + yy * nWidth + xx) * 3;
  6066. this._check(this._cells[tm] == 0);
  6067. this._cells[tm] = type;
  6068. this._cells[tm + 1] = w;
  6069. this._cells[tm + 2] = h;
  6070. }
  6071. }
  6072. if (x > 0) {
  6073. for (yy = 0; yy < h; ++yy) {
  6074. var s = 0;
  6075. for (xx = x - 1; xx >= 0; --xx, ++s) {
  6076. if (this._cells[((y + yy) * nWidth + xx) * 3] != 0)
  6077. break;
  6078. }
  6079. for (xx = s; xx > 0; --xx) {
  6080. this._cells[((y + yy) * nWidth + x - xx) * 3 + 1] = xx;
  6081. this._check(xx > 0);
  6082. }
  6083. }
  6084. }
  6085. if (y > 0) {
  6086. for (xx = x; xx < (x + w); ++xx) {
  6087. s = 0;
  6088. for (yy = y - 1; yy >= 0; --yy, s++) {
  6089. if (this._cells[(xx + yy * nWidth) * 3] != 0)
  6090. break;
  6091. }
  6092. for (yy = s; yy > 0; --yy) {
  6093. this._cells[(xx + (y - yy) * nWidth) * 3 + 2] = yy;
  6094. this._check(yy > 0);
  6095. }
  6096. }
  6097. }
  6098. this._used += (w * h) / (this._width * this._height);
  6099. }
  6100. _check(ret) {
  6101. if (ret == false) {
  6102. console.log("xtexMerger 错误啦");
  6103. }
  6104. }
  6105. _clear() {
  6106. this._texCount = 0;
  6107. for (var y = 0; y < this._height; y++) {
  6108. this._rowInfo[y] = this._width;
  6109. }
  6110. for (var i = 0; i < this._height; i++) {
  6111. for (var j = 0; j < this._width; j++) {
  6112. var tm = (i * this._width + j) * 3;
  6113. this._cells[tm] = 0;
  6114. this._cells[tm + 1] = this._width - j;
  6115. this._cells[tm + 2] = this._width - i;
  6116. }
  6117. }
  6118. }
  6119. }
  6120. class TextTexture extends Resource {
  6121. constructor(textureW, textureH) {
  6122. super();
  6123. this._texW = 0;
  6124. this._texH = 0;
  6125. this.__destroyed = false;
  6126. this._discardTm = 0;
  6127. this.genID = 0;
  6128. this.bitmap = { id: 0, _glTexture: null };
  6129. this.curUsedCovRate = 0;
  6130. this.curUsedCovRateAtlas = 0;
  6131. this.lastTouchTm = 0;
  6132. this.ri = null;
  6133. this._texW = textureW || TextTexture.gTextRender.atlasWidth;
  6134. this._texH = textureH || TextTexture.gTextRender.atlasWidth;
  6135. this.bitmap.id = this.id;
  6136. this.lock = true;
  6137. }
  6138. recreateResource() {
  6139. if (this._source)
  6140. return;
  6141. var gl = LayaGL.instance;
  6142. var glTex = this._source = gl.createTexture();
  6143. this.bitmap._glTexture = glTex;
  6144. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, glTex);
  6145. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._texW, this._texH, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  6146. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
  6147. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  6148. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  6149. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  6150. if (TextTexture.gTextRender.debugUV) {
  6151. this.fillWhite();
  6152. }
  6153. }
  6154. addChar(data, x, y, uv = null) {
  6155. if (TextTexture.gTextRender.isWan1Wan) {
  6156. return this.addCharCanvas(data, x, y, uv);
  6157. }
  6158. !this._source && this.recreateResource();
  6159. var gl = LayaGL.instance;
  6160. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, this._source);
  6161. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  6162. var dt = data.data;
  6163. if (data.data instanceof Uint8ClampedArray)
  6164. dt = new Uint8Array(dt.buffer);
  6165. gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, data.width, data.height, gl.RGBA, gl.UNSIGNED_BYTE, dt);
  6166. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  6167. var u0;
  6168. var v0;
  6169. var u1;
  6170. var v1;
  6171. if (ILaya.Render.isConchApp) {
  6172. u0 = x / this._texW;
  6173. v0 = y / this._texH;
  6174. u1 = (x + data.width) / this._texW;
  6175. v1 = (y + data.height) / this._texH;
  6176. }
  6177. else {
  6178. u0 = (x + 1) / this._texW;
  6179. v0 = (y) / this._texH;
  6180. u1 = (x + data.width - 1) / this._texW;
  6181. v1 = (y + data.height - 1) / this._texH;
  6182. }
  6183. uv = uv || new Array(8);
  6184. uv[0] = u0, uv[1] = v0;
  6185. uv[2] = u1, uv[3] = v0;
  6186. uv[4] = u1, uv[5] = v1;
  6187. uv[6] = u0, uv[7] = v1;
  6188. return uv;
  6189. }
  6190. addCharCanvas(canv, x, y, uv = null) {
  6191. !this._source && this.recreateResource();
  6192. var gl = LayaGL.instance;
  6193. WebGLContext.bindTexture(gl, gl.TEXTURE_2D, this._source);
  6194. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
  6195. gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, gl.RGBA, gl.UNSIGNED_BYTE, canv);
  6196. !ILaya.Render.isConchApp && gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  6197. var u0;
  6198. var v0;
  6199. var u1;
  6200. var v1;
  6201. if (ILaya.Render.isConchApp) {
  6202. u0 = x / this._texW;
  6203. v0 = y / this._texH;
  6204. u1 = (x + canv.width) / this._texW;
  6205. v1 = (y + canv.height) / this._texH;
  6206. }
  6207. else {
  6208. u0 = (x + 1) / this._texW;
  6209. v0 = (y + 1) / this._texH;
  6210. u1 = (x + canv.width - 1) / this._texW;
  6211. v1 = (y + canv.height - 1) / this._texH;
  6212. }
  6213. uv = uv || new Array(8);
  6214. uv[0] = u0, uv[1] = v0;
  6215. uv[2] = u1, uv[3] = v0;
  6216. uv[4] = u1, uv[5] = v1;
  6217. uv[6] = u0, uv[7] = v1;
  6218. return uv;
  6219. }
  6220. fillWhite() {
  6221. !this._source && this.recreateResource();
  6222. var gl = LayaGL.instance;
  6223. var dt = new Uint8Array(this._texW * this._texH * 4);
  6224. dt.fill(0xff);
  6225. gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this._texW, this._texH, gl.RGBA, gl.UNSIGNED_BYTE, dt);
  6226. }
  6227. discard() {
  6228. if (this._texW != TextTexture.gTextRender.atlasWidth || this._texH != TextTexture.gTextRender.atlasWidth) {
  6229. this.destroy();
  6230. return;
  6231. }
  6232. this.genID++;
  6233. if (TextTexture.poolLen >= TextTexture.pool.length) {
  6234. TextTexture.pool = TextTexture.pool.concat(new Array(10));
  6235. }
  6236. this._discardTm = RenderInfo.loopStTm;
  6237. TextTexture.pool[TextTexture.poolLen++] = this;
  6238. }
  6239. static getTextTexture(w, h) {
  6240. if (w != TextTexture.gTextRender.atlasWidth || w != TextTexture.gTextRender.atlasWidth)
  6241. return new TextTexture(w, h);
  6242. if (TextTexture.poolLen > 0) {
  6243. var ret = TextTexture.pool[--TextTexture.poolLen];
  6244. if (TextTexture.poolLen > 0)
  6245. TextTexture.clean();
  6246. return ret;
  6247. }
  6248. return new TextTexture(w, h);
  6249. }
  6250. destroy() {
  6251. this.__destroyed = true;
  6252. var gl = LayaGL.instance;
  6253. this._source && gl.deleteTexture(this._source);
  6254. this._source = null;
  6255. }
  6256. static clean() {
  6257. var curtm = RenderInfo.loopStTm;
  6258. if (TextTexture.cleanTm === 0)
  6259. TextTexture.cleanTm = curtm;
  6260. if (curtm - TextTexture.cleanTm >= TextTexture.gTextRender.checkCleanTextureDt) {
  6261. for (var i = 0; i < TextTexture.poolLen; i++) {
  6262. var p = TextTexture.pool[i];
  6263. if (curtm - p._discardTm >= TextTexture.gTextRender.destroyUnusedTextureDt) {
  6264. p.destroy();
  6265. TextTexture.pool[i] = TextTexture.pool[TextTexture.poolLen - 1];
  6266. TextTexture.poolLen--;
  6267. i--;
  6268. }
  6269. }
  6270. TextTexture.cleanTm = curtm;
  6271. }
  6272. }
  6273. touchRect(ri, curloop) {
  6274. if (this.lastTouchTm != curloop) {
  6275. this.curUsedCovRate = 0;
  6276. this.curUsedCovRateAtlas = 0;
  6277. this.lastTouchTm = curloop;
  6278. }
  6279. var texw2 = TextTexture.gTextRender.atlasWidth * TextTexture.gTextRender.atlasWidth;
  6280. var gridw2 = ILaya.TextAtlas.atlasGridW * ILaya.TextAtlas.atlasGridW;
  6281. this.curUsedCovRate += (ri.bmpWidth * ri.bmpHeight) / texw2;
  6282. this.curUsedCovRateAtlas += (Math.ceil(ri.bmpWidth / ILaya.TextAtlas.atlasGridW) * Math.ceil(ri.bmpHeight / ILaya.TextAtlas.atlasGridW)) / (texw2 / gridw2);
  6283. }
  6284. get texture() {
  6285. return this;
  6286. }
  6287. _getSource() {
  6288. return this._source;
  6289. }
  6290. drawOnScreen(x, y) {
  6291. }
  6292. }
  6293. TextTexture.gTextRender = null;
  6294. TextTexture.pool = new Array(10);
  6295. TextTexture.poolLen = 0;
  6296. TextTexture.cleanTm = 0;
  6297. class TextAtlas {
  6298. constructor() {
  6299. this.texWidth = 1024;
  6300. this.texHeight = 1024;
  6301. this.protectDist = 1;
  6302. this.texture = null;
  6303. this.charMaps = {};
  6304. this.texHeight = this.texWidth = ILaya.TextRender.atlasWidth;
  6305. this.texture = TextTexture.getTextTexture(this.texWidth, this.texHeight);
  6306. if (this.texWidth / TextAtlas.atlasGridW > 256) {
  6307. TextAtlas.atlasGridW = Math.ceil(this.texWidth / 256);
  6308. }
  6309. this.atlasgrid = new AtlasGrid(this.texWidth / TextAtlas.atlasGridW, this.texHeight / TextAtlas.atlasGridW, this.texture.id);
  6310. }
  6311. setProtecteDist(d) {
  6312. this.protectDist = d;
  6313. }
  6314. getAEmpty(w, h, pt) {
  6315. var find = this.atlasgrid.addRect(1, Math.ceil(w / TextAtlas.atlasGridW), Math.ceil(h / TextAtlas.atlasGridW), pt);
  6316. if (find) {
  6317. pt.x *= TextAtlas.atlasGridW;
  6318. pt.y *= TextAtlas.atlasGridW;
  6319. }
  6320. return find;
  6321. }
  6322. get usedRate() {
  6323. return this.atlasgrid._used;
  6324. }
  6325. destroy() {
  6326. for (var k in this.charMaps) {
  6327. var ri = this.charMaps[k];
  6328. ri.deleted = true;
  6329. }
  6330. this.texture.discard();
  6331. }
  6332. printDebugInfo() {
  6333. }
  6334. }
  6335. TextAtlas.atlasGridW = 16;
  6336. class Event {
  6337. setTo(type, currentTarget, target) {
  6338. this.type = type;
  6339. this.currentTarget = currentTarget;
  6340. this.target = target;
  6341. return this;
  6342. }
  6343. stopPropagation() {
  6344. this._stoped = true;
  6345. }
  6346. get touches() {
  6347. if (!this.nativeEvent)
  6348. return null;
  6349. var arr = this.nativeEvent.touches;
  6350. if (arr) {
  6351. var stage = ILaya.stage;
  6352. for (var i = 0, n = arr.length; i < n; i++) {
  6353. var e = arr[i];
  6354. var point = Point.TEMP;
  6355. point.setTo(e.clientX, e.clientY);
  6356. stage._canvasTransform.invertTransformPoint(point);
  6357. stage.transform.invertTransformPoint(point);
  6358. e.stageX = point.x;
  6359. e.stageY = point.y;
  6360. }
  6361. }
  6362. return arr;
  6363. }
  6364. get altKey() {
  6365. return this.nativeEvent.altKey;
  6366. }
  6367. get ctrlKey() {
  6368. return this.nativeEvent.ctrlKey;
  6369. }
  6370. get shiftKey() {
  6371. return this.nativeEvent.shiftKey;
  6372. }
  6373. get charCode() {
  6374. return this.nativeEvent.charCode;
  6375. }
  6376. get keyLocation() {
  6377. return this.nativeEvent.location || this.nativeEvent.keyLocation;
  6378. }
  6379. get stageX() {
  6380. return ILaya.stage.mouseX;
  6381. }
  6382. get stageY() {
  6383. return ILaya.stage.mouseY;
  6384. }
  6385. }
  6386. Event.EMPTY = new Event();
  6387. Event.MOUSE_DOWN = "mousedown";
  6388. Event.MOUSE_UP = "mouseup";
  6389. Event.CLICK = "click";
  6390. Event.RIGHT_MOUSE_DOWN = "rightmousedown";
  6391. Event.RIGHT_MOUSE_UP = "rightmouseup";
  6392. Event.RIGHT_CLICK = "rightclick";
  6393. Event.MOUSE_MOVE = "mousemove";
  6394. Event.MOUSE_OVER = "mouseover";
  6395. Event.MOUSE_OUT = "mouseout";
  6396. Event.MOUSE_WHEEL = "mousewheel";
  6397. Event.ROLL_OVER = "mouseover";
  6398. Event.ROLL_OUT = "mouseout";
  6399. Event.DOUBLE_CLICK = "doubleclick";
  6400. Event.CHANGE = "change";
  6401. Event.CHANGED = "changed";
  6402. Event.RESIZE = "resize";
  6403. Event.ADDED = "added";
  6404. Event.REMOVED = "removed";
  6405. Event.DISPLAY = "display";
  6406. Event.UNDISPLAY = "undisplay";
  6407. Event.ERROR = "error";
  6408. Event.COMPLETE = "complete";
  6409. Event.LOADED = "loaded";
  6410. Event.READY = "ready";
  6411. Event.PROGRESS = "progress";
  6412. Event.INPUT = "input";
  6413. Event.RENDER = "render";
  6414. Event.OPEN = "open";
  6415. Event.MESSAGE = "message";
  6416. Event.CLOSE = "close";
  6417. Event.KEY_DOWN = "keydown";
  6418. Event.KEY_PRESS = "keypress";
  6419. Event.KEY_UP = "keyup";
  6420. Event.FRAME = "enterframe";
  6421. Event.DRAG_START = "dragstart";
  6422. Event.DRAG_MOVE = "dragmove";
  6423. Event.DRAG_END = "dragend";
  6424. Event.ENTER = "enter";
  6425. Event.SELECT = "select";
  6426. Event.BLUR = "blur";
  6427. Event.FOCUS = "focus";
  6428. Event.VISIBILITY_CHANGE = "visibilitychange";
  6429. Event.FOCUS_CHANGE = "focuschange";
  6430. Event.PLAYED = "played";
  6431. Event.PAUSED = "paused";
  6432. Event.STOPPED = "stopped";
  6433. Event.START = "start";
  6434. Event.END = "end";
  6435. Event.COMPONENT_ADDED = "componentadded";
  6436. Event.COMPONENT_REMOVED = "componentremoved";
  6437. Event.RELEASED = "released";
  6438. Event.LINK = "link";
  6439. Event.LABEL = "label";
  6440. Event.FULL_SCREEN_CHANGE = "fullscreenchange";
  6441. Event.DEVICE_LOST = "devicelost";
  6442. Event.TRANSFORM_CHANGED = "transformchanged";
  6443. Event.ANIMATION_CHANGED = "animationchanged";
  6444. Event.TRAIL_FILTER_CHANGE = "trailfilterchange";
  6445. Event.TRIGGER_ENTER = "triggerenter";
  6446. Event.TRIGGER_STAY = "triggerstay";
  6447. Event.TRIGGER_EXIT = "triggerexit";
  6448. class Texture extends EventDispatcher {
  6449. constructor(bitmap = null, uv = null, sourceWidth = 0, sourceHeight = 0) {
  6450. super();
  6451. this.uvrect = [0, 0, 1, 1];
  6452. this._destroyed = false;
  6453. this._referenceCount = 0;
  6454. this.$_GID = 0;
  6455. this.offsetX = 0;
  6456. this.offsetY = 0;
  6457. this._w = 0;
  6458. this._h = 0;
  6459. this.sourceWidth = 0;
  6460. this.sourceHeight = 0;
  6461. this.url = null;
  6462. this.scaleRate = 1;
  6463. this.setTo(bitmap, uv, sourceWidth, sourceHeight);
  6464. }
  6465. static moveUV(offsetX, offsetY, uv) {
  6466. for (var i = 0; i < 8; i += 2) {
  6467. uv[i] += offsetX;
  6468. uv[i + 1] += offsetY;
  6469. }
  6470. return uv;
  6471. }
  6472. static create(source, x, y, width, height, offsetX = 0, offsetY = 0, sourceWidth = 0, sourceHeight = 0) {
  6473. return Texture._create(source, x, y, width, height, offsetX, offsetY, sourceWidth, sourceHeight);
  6474. }
  6475. static _create(source, x, y, width, height, offsetX = 0, offsetY = 0, sourceWidth = 0, sourceHeight = 0, outTexture = null) {
  6476. var btex = source instanceof Texture;
  6477. var uv = btex ? source.uv : Texture.DEF_UV;
  6478. var bitmap = btex ? source.bitmap : source;
  6479. if (bitmap.width && (x + width) > bitmap.width)
  6480. width = bitmap.width - x;
  6481. if (bitmap.height && (y + height) > bitmap.height)
  6482. height = bitmap.height - y;
  6483. var tex;
  6484. if (outTexture) {
  6485. tex = outTexture;
  6486. tex.setTo(bitmap, null, sourceWidth || width, sourceHeight || height);
  6487. }
  6488. else {
  6489. tex = new Texture(bitmap, null, sourceWidth || width, sourceHeight || height);
  6490. }
  6491. tex.width = width;
  6492. tex.height = height;
  6493. tex.offsetX = offsetX;
  6494. tex.offsetY = offsetY;
  6495. var dwidth = 1 / bitmap.width;
  6496. var dheight = 1 / bitmap.height;
  6497. x *= dwidth;
  6498. y *= dheight;
  6499. width *= dwidth;
  6500. height *= dheight;
  6501. var u1 = tex.uv[0], v1 = tex.uv[1], u2 = tex.uv[4], v2 = tex.uv[5];
  6502. var inAltasUVWidth = (u2 - u1), inAltasUVHeight = (v2 - v1);
  6503. var oriUV = Texture.moveUV(uv[0], uv[1], [x, y, x + width, y, x + width, y + height, x, y + height]);
  6504. tex.uv = new Float32Array([u1 + oriUV[0] * inAltasUVWidth, v1 + oriUV[1] * inAltasUVHeight,
  6505. u2 - (1 - oriUV[2]) * inAltasUVWidth, v1 + oriUV[3] * inAltasUVHeight,
  6506. u2 - (1 - oriUV[4]) * inAltasUVWidth, v2 - (1 - oriUV[5]) * inAltasUVHeight,
  6507. u1 + oriUV[6] * inAltasUVWidth, v2 - (1 - oriUV[7]) * inAltasUVHeight]);
  6508. var bitmapScale = bitmap.scaleRate;
  6509. if (bitmapScale && bitmapScale != 1) {
  6510. tex.sourceWidth /= bitmapScale;
  6511. tex.sourceHeight /= bitmapScale;
  6512. tex.width /= bitmapScale;
  6513. tex.height /= bitmapScale;
  6514. tex.scaleRate = bitmapScale;
  6515. }
  6516. else {
  6517. tex.scaleRate = 1;
  6518. }
  6519. return tex;
  6520. }
  6521. static createFromTexture(texture, x, y, width, height) {
  6522. var texScaleRate = texture.scaleRate;
  6523. if (texScaleRate != 1) {
  6524. x *= texScaleRate;
  6525. y *= texScaleRate;
  6526. width *= texScaleRate;
  6527. height *= texScaleRate;
  6528. }
  6529. var rect = Rectangle.TEMP.setTo(x - texture.offsetX, y - texture.offsetY, width, height);
  6530. var result = rect.intersection(Texture._rect1.setTo(0, 0, texture.width, texture.height), Texture._rect2);
  6531. if (result)
  6532. var tex = Texture.create(texture, result.x, result.y, result.width, result.height, result.x - rect.x, result.y - rect.y, width, height);
  6533. else
  6534. return null;
  6535. return tex;
  6536. }
  6537. get uv() {
  6538. return this._uv;
  6539. }
  6540. set uv(value) {
  6541. this.uvrect[0] = Math.min(value[0], value[2], value[4], value[6]);
  6542. this.uvrect[1] = Math.min(value[1], value[3], value[5], value[7]);
  6543. this.uvrect[2] = Math.max(value[0], value[2], value[4], value[6]) - this.uvrect[0];
  6544. this.uvrect[3] = Math.max(value[1], value[3], value[5], value[7]) - this.uvrect[1];
  6545. this._uv = value;
  6546. }
  6547. get width() {
  6548. if (this._w)
  6549. return this._w;
  6550. if (!this.bitmap)
  6551. return 0;
  6552. return (this.uv && this.uv !== Texture.DEF_UV) ? (this.uv[2] - this.uv[0]) * this.bitmap.width : this.bitmap.width;
  6553. }
  6554. set width(value) {
  6555. this._w = value;
  6556. this.sourceWidth || (this.sourceWidth = value);
  6557. }
  6558. get height() {
  6559. if (this._h)
  6560. return this._h;
  6561. if (!this.bitmap)
  6562. return 0;
  6563. return (this.uv && this.uv !== Texture.DEF_UV) ? (this.uv[5] - this.uv[1]) * this.bitmap.height : this.bitmap.height;
  6564. }
  6565. set height(value) {
  6566. this._h = value;
  6567. this.sourceHeight || (this.sourceHeight = value);
  6568. }
  6569. get bitmap() {
  6570. return this._bitmap;
  6571. }
  6572. set bitmap(value) {
  6573. this._bitmap && this._bitmap._removeReference(this._referenceCount);
  6574. this._bitmap = value;
  6575. value && (value._addReference(this._referenceCount));
  6576. }
  6577. get destroyed() {
  6578. return this._destroyed;
  6579. }
  6580. _addReference() {
  6581. this._bitmap && this._bitmap._addReference();
  6582. this._referenceCount++;
  6583. }
  6584. _removeReference() {
  6585. this._bitmap && this._bitmap._removeReference();
  6586. this._referenceCount--;
  6587. }
  6588. _getSource(cb = null) {
  6589. if (this._destroyed || !this._bitmap)
  6590. return null;
  6591. this.recoverBitmap(cb);
  6592. return this._bitmap.destroyed ? null : this.bitmap._getSource();
  6593. }
  6594. _onLoaded(complete, context) {
  6595. if (!context) ;
  6596. else if (context == this) ;
  6597. else if (context instanceof Texture) {
  6598. var tex = context;
  6599. Texture._create(context, 0, 0, tex.width, tex.height, 0, 0, tex.sourceWidth, tex.sourceHeight, this);
  6600. }
  6601. else {
  6602. this.bitmap = context;
  6603. this.sourceWidth = this._w = context.width;
  6604. this.sourceHeight = this._h = context.height;
  6605. }
  6606. complete && complete.run();
  6607. this.event(Event.READY, this);
  6608. }
  6609. getIsReady() {
  6610. return this._destroyed ? false : (this._bitmap ? true : false);
  6611. }
  6612. setTo(bitmap = null, uv = null, sourceWidth = 0, sourceHeight = 0) {
  6613. this.bitmap = bitmap;
  6614. this.sourceWidth = sourceWidth;
  6615. this.sourceHeight = sourceHeight;
  6616. if (bitmap) {
  6617. this._w = bitmap.width;
  6618. this._h = bitmap.height;
  6619. this.sourceWidth = this.sourceWidth || bitmap.width;
  6620. this.sourceHeight = this.sourceHeight || bitmap.height;
  6621. }
  6622. this.uv = uv || Texture.DEF_UV;
  6623. }
  6624. load(url, complete = null) {
  6625. if (!this._destroyed)
  6626. ILaya.loader.load(url, Handler.create(this, this._onLoaded, [complete]), null, "htmlimage", 1, false, null, true);
  6627. }
  6628. getTexturePixels(x, y, width, height) {
  6629. var st, dst, i;
  6630. var tex2d = this.bitmap;
  6631. var texw = tex2d.width;
  6632. var texh = tex2d.height;
  6633. if (x + width > texw)
  6634. width -= (x + width) - texw;
  6635. if (y + height > texh)
  6636. height -= (y + height) - texh;
  6637. if (width <= 0 || height <= 0)
  6638. return null;
  6639. var wstride = width * 4;
  6640. var pix = null;
  6641. try {
  6642. pix = tex2d.getPixels();
  6643. }
  6644. catch (e) {
  6645. }
  6646. if (pix) {
  6647. if (x == 0 && y == 0 && width == texw && height == texh)
  6648. return pix;
  6649. var ret = new Uint8Array(width * height * 4);
  6650. wstride = texw * 4;
  6651. st = x * 4;
  6652. dst = (y + height - 1) * wstride + x * 4;
  6653. for (i = height - 1; i >= 0; i--) {
  6654. ret.set(dt.slice(dst, dst + width * 4), st);
  6655. st += wstride;
  6656. dst -= wstride;
  6657. }
  6658. return ret;
  6659. }
  6660. var ctx = new ILaya.Context();
  6661. ctx.size(width, height);
  6662. ctx.asBitmap = true;
  6663. var uv = null;
  6664. if (x != 0 || y != 0 || width != texw || height != texh) {
  6665. uv = this._uv.slice();
  6666. var stu = uv[0];
  6667. var stv = uv[1];
  6668. var uvw = uv[2] - stu;
  6669. var uvh = uv[7] - stv;
  6670. var uk = uvw / texw;
  6671. var vk = uvh / texh;
  6672. uv = [stu + x * uk, stv + y * vk,
  6673. stu + (x + width) * uk, stv + y * vk,
  6674. stu + (x + width) * uk, stv + (y + height) * vk,
  6675. stu + x * uk, stv + (y + height) * vk];
  6676. }
  6677. ctx._drawTextureM(this, 0, 0, width, height, null, 1.0, uv);
  6678. ctx._targets.start();
  6679. ctx.flush();
  6680. ctx._targets.end();
  6681. ctx._targets.restore();
  6682. var dt = ctx._targets.getData(0, 0, width, height);
  6683. ctx.destroy();
  6684. ret = new Uint8Array(width * height * 4);
  6685. st = 0;
  6686. dst = (height - 1) * wstride;
  6687. for (i = height - 1; i >= 0; i--) {
  6688. ret.set(dt.slice(dst, dst + wstride), st);
  6689. st += wstride;
  6690. dst -= wstride;
  6691. }
  6692. return ret;
  6693. }
  6694. getPixels(x, y, width, height) {
  6695. if (window.conch) {
  6696. return this._nativeObj.getImageData(x, y, width, height);
  6697. }
  6698. else {
  6699. return this.getTexturePixels(x, y, width, height);
  6700. }
  6701. }
  6702. recoverBitmap(onok = null) {
  6703. var url = this._bitmap.url;
  6704. if (!this._destroyed && (!this._bitmap || this._bitmap.destroyed) && url) {
  6705. ILaya.loader.load(url, Handler.create(this, function (bit) {
  6706. this.bitmap = bit;
  6707. onok && onok();
  6708. }), null, "htmlimage", 1, false, null, true);
  6709. }
  6710. }
  6711. disposeBitmap() {
  6712. if (!this._destroyed && this._bitmap) {
  6713. this._bitmap.destroy();
  6714. }
  6715. }
  6716. destroy(force = false) {
  6717. if (!this._destroyed) {
  6718. this._destroyed = true;
  6719. var bit = this._bitmap;
  6720. if (bit) {
  6721. bit._removeReference(this._referenceCount);
  6722. if (bit.referenceCount === 0 || force)
  6723. bit.destroy();
  6724. bit = null;
  6725. }
  6726. if (this.url && this === ILaya.loader.getRes(this.url))
  6727. ILaya.loader.clearRes(this.url);
  6728. }
  6729. }
  6730. }
  6731. Texture.DEF_UV = new Float32Array([0, 0, 1.0, 0, 1.0, 1.0, 0, 1.0]);
  6732. Texture.NO_UV = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]);
  6733. Texture.INV_UV = new Float32Array([0, 1, 1.0, 1, 1.0, 0.0, 0, 0.0]);
  6734. Texture._rect1 = new Rectangle();
  6735. Texture._rect2 = new Rectangle();
  6736. class FontInfo {
  6737. constructor(font) {
  6738. this._font = "14px Arial";
  6739. this._family = "Arial";
  6740. this._size = 14;
  6741. this._italic = false;
  6742. this._bold = false;
  6743. this._id = FontInfo._gfontID++;
  6744. this.setFont(font || this._font);
  6745. }
  6746. static Parse(font) {
  6747. if (font === FontInfo._lastFont) {
  6748. return FontInfo._lastFontInfo;
  6749. }
  6750. var r = FontInfo._cache[font];
  6751. if (!r) {
  6752. r = FontInfo._cache[font] = new FontInfo(font);
  6753. }
  6754. FontInfo._lastFont = font;
  6755. FontInfo._lastFontInfo = r;
  6756. return r;
  6757. }
  6758. setFont(value) {
  6759. this._font = value;
  6760. var _words = value.split(' ');
  6761. var l = _words.length;
  6762. if (l < 2) {
  6763. if (l == 1) {
  6764. if (_words[0].indexOf('px') > 0) {
  6765. this._size = parseInt(_words[0]);
  6766. }
  6767. }
  6768. return;
  6769. }
  6770. var szpos = -1;
  6771. for (var i = 0; i < l; i++) {
  6772. if (_words[i].indexOf('px') > 0 || _words[i].indexOf('pt') > 0) {
  6773. szpos = i;
  6774. this._size = parseInt(_words[i]);
  6775. if (this._size <= 0) {
  6776. console.error('font parse error:' + value);
  6777. this._size = 14;
  6778. }
  6779. break;
  6780. }
  6781. }
  6782. var fpos = szpos + 1;
  6783. var familys = _words[fpos];
  6784. fpos++;
  6785. for (; fpos < l; fpos++) {
  6786. familys += ' ' + _words[fpos];
  6787. }
  6788. this._family = (familys.split(','))[0];
  6789. this._italic = _words.indexOf('italic') >= 0;
  6790. this._bold = _words.indexOf('bold') >= 0;
  6791. }
  6792. }
  6793. FontInfo.EMPTY = new FontInfo(null);
  6794. FontInfo._cache = {};
  6795. FontInfo._gfontID = 0;
  6796. FontInfo._lastFont = '';
  6797. class WordText {
  6798. constructor() {
  6799. this.save = [];
  6800. this.toUpperCase = null;
  6801. this.width = -1;
  6802. this.pageChars = [];
  6803. this.startID = 0;
  6804. this.startIDStroke = 0;
  6805. this.lastGCCnt = 0;
  6806. this.splitRender = false;
  6807. }
  6808. setText(txt) {
  6809. this.changed = true;
  6810. this._text = txt;
  6811. this.width = -1;
  6812. this.cleanCache();
  6813. }
  6814. toString() {
  6815. return this._text;
  6816. }
  6817. get length() {
  6818. return this._text ? this._text.length : 0;
  6819. }
  6820. charCodeAt(i) {
  6821. return this._text ? this._text.charCodeAt(i) : NaN;
  6822. }
  6823. charAt(i) {
  6824. return this._text ? this._text.charAt(i) : null;
  6825. }
  6826. cleanCache() {
  6827. this.pageChars.forEach(function (p) {
  6828. var tex = p.tex;
  6829. var words = p.words;
  6830. if (p.words.length == 1 && tex && tex.ri) {
  6831. tex.destroy();
  6832. }
  6833. });
  6834. this.pageChars = [];
  6835. this.startID = 0;
  6836. }
  6837. }
  6838. class CharRenderInfo {
  6839. constructor() {
  6840. this.char = '';
  6841. this.deleted = false;
  6842. this.uv = new Array(8);
  6843. this.pos = 0;
  6844. this.orix = 0;
  6845. this.oriy = 0;
  6846. this.touchTick = 0;
  6847. this.isSpace = false;
  6848. }
  6849. touch() {
  6850. var curLoop = RenderInfo.loopCount;
  6851. if (this.touchTick != curLoop) {
  6852. this.tex.touchRect(this, curLoop);
  6853. }
  6854. this.touchTick = curLoop;
  6855. }
  6856. }
  6857. class ICharRender {
  6858. constructor() {
  6859. this.fontsz = 16;
  6860. }
  6861. getWidth(font, str) { return 0; }
  6862. scale(sx, sy) {
  6863. }
  6864. get canvasWidth() {
  6865. return 0;
  6866. }
  6867. set canvasWidth(w) {
  6868. }
  6869. getCharBmp(char, font, lineWidth, colStr, strokeColStr, size, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  6870. return null;
  6871. }
  6872. }
  6873. class Browser {
  6874. static __init__() {
  6875. var Laya = window.Laya || ILaya.Laya;
  6876. if (Browser._window)
  6877. return Browser._window;
  6878. var win = Browser._window = window;
  6879. var doc = Browser._document = win.document;
  6880. var u = Browser.userAgent = win.navigator.userAgent;
  6881. if (u.indexOf('AlipayMiniGame') > -1 && "my" in Browser.window) {
  6882. window.aliMiniGame(Laya, Laya);
  6883. window.aliPayMiniGame(Laya, Laya);
  6884. if (!Laya["ALIMiniAdapter"]) {
  6885. console.error("请先添加阿里小游戏适配库");
  6886. }
  6887. else {
  6888. Laya["ALIMiniAdapter"].enable();
  6889. }
  6890. }
  6891. if (u.indexOf('OPPO') == -1 && u.indexOf("MiniGame") > -1 && "wx" in Browser.window) {
  6892. if ("qq" in Browser.window) {
  6893. window.qqMiniGame(Laya, Laya);
  6894. if (!Laya["QQMiniAdapter"]) {
  6895. console.error("请引入手机QQ小游戏的适配库:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6896. }
  6897. else {
  6898. Laya["QQMiniAdapter"].enable();
  6899. }
  6900. }
  6901. else {
  6902. window.wxMiniGame(Laya, Laya);
  6903. if (!Laya["MiniAdpter"]) {
  6904. console.error("请先添加小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6905. }
  6906. else {
  6907. Laya["MiniAdpter"].enable();
  6908. }
  6909. }
  6910. }
  6911. if (u.indexOf("SwanGame") > -1) {
  6912. window.bdMiniGame(Laya, Laya);
  6913. if (!Laya["BMiniAdapter"]) {
  6914. console.error("请先添加百度小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6915. }
  6916. else {
  6917. Laya["BMiniAdapter"].enable();
  6918. }
  6919. }
  6920. if (u.indexOf('QuickGame') > -1) {
  6921. window.miMiniGame(Laya, Laya);
  6922. if (!Laya["KGMiniAdapter"]) {
  6923. console.error("请先添加小米小游戏适配库,详细教程:https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-0");
  6924. }
  6925. else {
  6926. Laya["KGMiniAdapter"].enable();
  6927. }
  6928. }
  6929. if (u.indexOf('OPPO') > -1 && u.indexOf('MiniGame') > -1) {
  6930. window.qgMiniGame(Laya, Laya);
  6931. if (!Laya["QGMiniAdapter"]) {
  6932. console.error("请先添加OPPO小游戏适配库");
  6933. }
  6934. else {
  6935. Laya["QGMiniAdapter"].enable();
  6936. }
  6937. }
  6938. if (u.indexOf('VVGame') > -1) {
  6939. window.vvMiniGame(Laya, Laya);
  6940. if (!Laya["VVMiniAdapter"]) {
  6941. console.error("请先添加VIVO小游戏适配库");
  6942. }
  6943. else {
  6944. Laya["VVMiniAdapter"].enable();
  6945. }
  6946. }
  6947. win.trace = console.log;
  6948. win.requestAnimationFrame = win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || win.oRequestAnimationFrame || win.msRequestAnimationFrame || function (fun) {
  6949. return win.setTimeout(fun, 1000 / 60);
  6950. };
  6951. var bodyStyle = doc.body.style;
  6952. bodyStyle.margin = 0;
  6953. bodyStyle.overflow = 'hidden';
  6954. bodyStyle['-webkit-user-select'] = 'none';
  6955. bodyStyle['-webkit-tap-highlight-color'] = 'rgba(200,200,200,0)';
  6956. var metas = doc.getElementsByTagName('meta');
  6957. var i = 0, flag = false, content = 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no';
  6958. while (i < metas.length) {
  6959. var meta = metas[i];
  6960. if (meta.name == 'viewport') {
  6961. meta.content = content;
  6962. flag = true;
  6963. break;
  6964. }
  6965. i++;
  6966. }
  6967. if (!flag) {
  6968. meta = doc.createElement('meta');
  6969. meta.name = 'viewport', meta.content = content;
  6970. doc.getElementsByTagName('head')[0].appendChild(meta);
  6971. }
  6972. Browser.onMobile = window.isConchApp ? true : u.indexOf("Mobile") > -1;
  6973. Browser.onIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  6974. Browser.onIPhone = u.indexOf("iPhone") > -1;
  6975. Browser.onMac = u.indexOf("Mac OS X") > -1;
  6976. Browser.onIPad = u.indexOf("iPad") > -1;
  6977. Browser.onAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
  6978. Browser.onWP = u.indexOf("Windows Phone") > -1;
  6979. Browser.onQQBrowser = u.indexOf("QQBrowser") > -1;
  6980. Browser.onMQQBrowser = u.indexOf("MQQBrowser") > -1 || (u.indexOf("Mobile") > -1 && u.indexOf("QQ") > -1);
  6981. Browser.onIE = !!win.ActiveXObject || "ActiveXObject" in win;
  6982. Browser.onWeiXin = u.indexOf('MicroMessenger') > -1;
  6983. Browser.onSafari = u.indexOf("Safari") > -1;
  6984. Browser.onPC = !Browser.onMobile;
  6985. Browser.onMiniGame = u.indexOf('MiniGame') > -1;
  6986. Browser.onBDMiniGame = u.indexOf('SwanGame') > -1;
  6987. Browser.onLayaRuntime = !!Browser.window.conch;
  6988. if (u.indexOf('OPPO') > -1 && u.indexOf('MiniGame') > -1) {
  6989. Browser.onQGMiniGame = true;
  6990. Browser.onMiniGame = false;
  6991. }
  6992. else if ("qq" in Browser.window && u.indexOf('MiniGame') > -1) {
  6993. Browser.onQQMiniGame = true;
  6994. Browser.onMiniGame = false;
  6995. }
  6996. Browser.onVVMiniGame = u.indexOf('VVGame') > -1;
  6997. Browser.onKGMiniGame = u.indexOf('QuickGame') > -1;
  6998. if (u.indexOf('AlipayMiniGame') > -1) {
  6999. Browser.onAlipayMiniGame = true;
  7000. Browser.onMiniGame = false;
  7001. }
  7002. return win;
  7003. }
  7004. static createElement(type) {
  7005. Browser.__init__();
  7006. return Browser._document.createElement(type);
  7007. }
  7008. static getElementById(type) {
  7009. Browser.__init__();
  7010. return Browser._document.getElementById(type);
  7011. }
  7012. static removeElement(ele) {
  7013. if (ele && ele.parentNode)
  7014. ele.parentNode.removeChild(ele);
  7015. }
  7016. static now() {
  7017. return Date.now();
  7018. }
  7019. static get clientWidth() {
  7020. Browser.__init__();
  7021. return Browser._window.innerWidth || Browser._document.body.clientWidth;
  7022. }
  7023. static get clientHeight() {
  7024. Browser.__init__();
  7025. return Browser._window.innerHeight || Browser._document.body.clientHeight || Browser._document.documentElement.clientHeight;
  7026. }
  7027. static get width() {
  7028. Browser.__init__();
  7029. return ((ILaya.stage && ILaya.stage.canvasRotation) ? Browser.clientHeight : Browser.clientWidth) * Browser.pixelRatio;
  7030. }
  7031. static get height() {
  7032. Browser.__init__();
  7033. return ((ILaya.stage && ILaya.stage.canvasRotation) ? Browser.clientWidth : Browser.clientHeight) * Browser.pixelRatio;
  7034. }
  7035. static get pixelRatio() {
  7036. if (Browser._pixelRatio < 0) {
  7037. Browser.__init__();
  7038. if (Browser.userAgent.indexOf("Mozilla/6.0(Linux; Android 6.0; HUAWEI NXT-AL10 Build/HUAWEINXT-AL10)") > -1)
  7039. Browser._pixelRatio = 2;
  7040. else {
  7041. Browser._pixelRatio = (Browser._window.devicePixelRatio || 1);
  7042. if (Browser._pixelRatio < 1)
  7043. Browser._pixelRatio = 1;
  7044. }
  7045. }
  7046. return Browser._pixelRatio;
  7047. }
  7048. static get container() {
  7049. if (!Browser._container) {
  7050. Browser.__init__();
  7051. Browser._container = Browser.createElement("div");
  7052. Browser._container.id = "layaContainer";
  7053. Browser._document.body.appendChild(Browser._container);
  7054. }
  7055. return Browser._container;
  7056. }
  7057. static set container(value) {
  7058. Browser._container = value;
  7059. }
  7060. static get window() {
  7061. return Browser._window || Browser.__init__();
  7062. }
  7063. static get document() {
  7064. Browser.__init__();
  7065. return Browser._document;
  7066. }
  7067. }
  7068. Browser._pixelRatio = -1;
  7069. Browser.mainCanvas = null;
  7070. Browser.hanzi = new RegExp("^[\u4E00-\u9FA5]$");
  7071. Browser.fontMap = [];
  7072. Browser.measureText = function (txt, font) {
  7073. var isChinese = Browser.hanzi.test(txt);
  7074. if (isChinese && Browser.fontMap[font]) {
  7075. return Browser.fontMap[font];
  7076. }
  7077. var ctx = Browser.context;
  7078. ctx.font = font;
  7079. var r = ctx.measureText(txt);
  7080. if (isChinese)
  7081. Browser.fontMap[font] = r;
  7082. return r;
  7083. };
  7084. class CharRender_Canvas extends ICharRender {
  7085. constructor(maxw, maxh, scalefont = true, useImageData = true, showdbg = false) {
  7086. super();
  7087. this.ctx = null;
  7088. this.lastScaleX = 1.0;
  7089. this.lastScaleY = 1.0;
  7090. this.needResetScale = false;
  7091. this.maxTexW = 0;
  7092. this.maxTexH = 0;
  7093. this.scaleFontSize = true;
  7094. this.showDbgInfo = false;
  7095. this.supportImageData = true;
  7096. this.maxTexW = maxw;
  7097. this.maxTexH = maxh;
  7098. this.scaleFontSize = scalefont;
  7099. this.supportImageData = useImageData;
  7100. this.showDbgInfo = showdbg;
  7101. if (!CharRender_Canvas.canvas) {
  7102. CharRender_Canvas.canvas = Browser.createElement('canvas');
  7103. CharRender_Canvas.canvas.width = 1024;
  7104. CharRender_Canvas.canvas.height = 512;
  7105. CharRender_Canvas.canvas.style.left = "-10000px";
  7106. CharRender_Canvas.canvas.style.position = "absolute";
  7107. document.body.appendChild(CharRender_Canvas.canvas);
  7108. this.ctx = CharRender_Canvas.canvas.getContext('2d');
  7109. }
  7110. }
  7111. get canvasWidth() {
  7112. return CharRender_Canvas.canvas.width;
  7113. }
  7114. set canvasWidth(w) {
  7115. if (CharRender_Canvas.canvas.width == w)
  7116. return;
  7117. CharRender_Canvas.canvas.width = w;
  7118. if (w > 2048) {
  7119. console.warn("画文字设置的宽度太大,超过2048了");
  7120. }
  7121. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  7122. this.ctx.scale(this.lastScaleX, this.lastScaleY);
  7123. }
  7124. getWidth(font, str) {
  7125. if (!this.ctx)
  7126. return 0;
  7127. if (this.ctx._lastFont != font) {
  7128. this.ctx.font = font;
  7129. this.ctx._lastFont = font;
  7130. }
  7131. return this.ctx.measureText(str).width;
  7132. }
  7133. scale(sx, sy) {
  7134. if (!this.supportImageData) {
  7135. this.lastScaleX = sx;
  7136. this.lastScaleY = sy;
  7137. return;
  7138. }
  7139. if (this.lastScaleX != sx || this.lastScaleY != sy) {
  7140. this.ctx.setTransform(sx, 0, 0, sy, 0, 0);
  7141. this.lastScaleX = sx;
  7142. this.lastScaleY = sy;
  7143. }
  7144. }
  7145. getCharBmp(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  7146. if (!this.supportImageData)
  7147. return this.getCharCanvas(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom);
  7148. var ctx = this.ctx;
  7149. var sz = this.fontsz;
  7150. if (ctx.font != font) {
  7151. ctx.font = font;
  7152. ctx._lastFont = font;
  7153. }
  7154. cri.width = ctx.measureText(char).width;
  7155. var w = cri.width * this.lastScaleX;
  7156. var h = cri.height * this.lastScaleY;
  7157. w += (margin_left + margin_right) * this.lastScaleX;
  7158. h += (margin_top + margin_bottom) * this.lastScaleY;
  7159. w = Math.ceil(w);
  7160. h = Math.ceil(h);
  7161. w = Math.min(w, CharRender_Canvas.canvas.width);
  7162. h = Math.min(h, CharRender_Canvas.canvas.height);
  7163. var clearW = w + lineWidth * 2 + 1;
  7164. var clearH = h + lineWidth * 2 + 1;
  7165. if (rect) {
  7166. clearW = Math.max(clearW, rect[0] + rect[2] + 1);
  7167. clearH = Math.max(clearH, rect[1] + rect[3] + 1);
  7168. }
  7169. ctx.clearRect(0, 0, clearW, clearH);
  7170. ctx.save();
  7171. ctx.textBaseline = "middle";
  7172. if (lineWidth > 0) {
  7173. ctx.strokeStyle = strokeColStr;
  7174. ctx.lineWidth = lineWidth;
  7175. ctx.strokeText(char, margin_left, margin_top + sz / 2);
  7176. }
  7177. if (colStr) {
  7178. ctx.fillStyle = colStr;
  7179. ctx.fillText(char, margin_left, margin_top + sz / 2);
  7180. }
  7181. if (this.showDbgInfo) {
  7182. ctx.strokeStyle = '#ff0000';
  7183. ctx.strokeRect(1, 1, w - 2, h - 2);
  7184. ctx.strokeStyle = '#00ff00';
  7185. ctx.strokeRect(margin_left, margin_top, cri.width, cri.height);
  7186. }
  7187. if (rect) {
  7188. if (rect[2] == -1)
  7189. rect[2] = Math.ceil((cri.width + lineWidth * 2) * this.lastScaleX);
  7190. }
  7191. var imgdt = rect ? (ctx.getImageData(rect[0], rect[1], rect[2], rect[3])) : (ctx.getImageData(0, 0, w, h));
  7192. ctx.restore();
  7193. cri.bmpWidth = imgdt.width;
  7194. cri.bmpHeight = imgdt.height;
  7195. return imgdt;
  7196. }
  7197. getCharCanvas(char, font, lineWidth, colStr, strokeColStr, cri, margin_left, margin_top, margin_right, margin_bottom) {
  7198. var ctx = this.ctx;
  7199. if (ctx.font != font) {
  7200. ctx.font = font;
  7201. ctx._lastFont = font;
  7202. }
  7203. cri.width = ctx.measureText(char).width;
  7204. var w = cri.width * this.lastScaleX;
  7205. var h = cri.height * this.lastScaleY;
  7206. w += (margin_left + margin_right) * this.lastScaleX;
  7207. h += ((margin_top + margin_bottom) * this.lastScaleY + 1);
  7208. w = Math.min(w, this.maxTexW);
  7209. h = Math.min(h, this.maxTexH);
  7210. CharRender_Canvas.canvas.width = Math.min(w + 1, this.maxTexW);
  7211. CharRender_Canvas.canvas.height = Math.min(h + 1, this.maxTexH);
  7212. ctx.font = font;
  7213. ctx.clearRect(0, 0, w + 1 + lineWidth, h + 1 + lineWidth);
  7214. ctx.setTransform(1, 0, 0, 1, 0, 0);
  7215. ctx.save();
  7216. if (this.scaleFontSize) {
  7217. ctx.scale(this.lastScaleX, this.lastScaleY);
  7218. }
  7219. ctx.translate(margin_left, margin_top);
  7220. ctx.textAlign = "left";
  7221. var sz = this.fontsz;
  7222. ctx.textBaseline = "middle";
  7223. if (lineWidth > 0) {
  7224. ctx.strokeStyle = strokeColStr;
  7225. ctx.fillStyle = colStr;
  7226. ctx.lineWidth = lineWidth;
  7227. if (ctx.fillAndStrokeText) {
  7228. ctx.fillAndStrokeText(char, 0, sz / 2);
  7229. }
  7230. else {
  7231. ctx.strokeText(char, 0, sz / 2);
  7232. ctx.fillText(char, 0, sz / 2);
  7233. }
  7234. }
  7235. else if (colStr) {
  7236. ctx.fillStyle = colStr;
  7237. ctx.fillText(char, 0, sz / 2);
  7238. }
  7239. if (this.showDbgInfo) {
  7240. ctx.strokeStyle = '#ff0000';
  7241. ctx.strokeRect(0, 0, w, h);
  7242. ctx.strokeStyle = '#00ff00';
  7243. ctx.strokeRect(0, 0, cri.width, cri.height);
  7244. }
  7245. ctx.restore();
  7246. cri.bmpWidth = CharRender_Canvas.canvas.width;
  7247. cri.bmpHeight = CharRender_Canvas.canvas.height;
  7248. return CharRender_Canvas.canvas;
  7249. }
  7250. }
  7251. CharRender_Canvas.canvas = null;
  7252. class CharRender_Native extends ICharRender {
  7253. constructor() {
  7254. super();
  7255. this.lastFont = '';
  7256. }
  7257. getWidth(font, str) {
  7258. if (!window.conchTextCanvas)
  7259. return 0;
  7260. window.conchTextCanvas.font = font;
  7261. this.lastFont = font;
  7262. return window.conchTextCanvas.measureText(str).width;
  7263. }
  7264. scale(sx, sy) {
  7265. }
  7266. getCharBmp(char, font, lineWidth, colStr, strokeColStr, size, margin_left, margin_top, margin_right, margin_bottom, rect = null) {
  7267. if (!window.conchTextCanvas)
  7268. return null;
  7269. window.conchTextCanvas.font = font;
  7270. this.lastFont = font;
  7271. var w = size.width = window.conchTextCanvas.measureText(char).width;
  7272. var h = size.height;
  7273. w += (margin_left + margin_right);
  7274. h += (margin_top + margin_bottom);
  7275. var c1 = ColorUtils.create(strokeColStr);
  7276. var nStrokeColor = c1.numColor;
  7277. var c2 = ColorUtils.create(colStr);
  7278. var nTextColor = c2.numColor;
  7279. var textInfo = window.conchTextCanvas.getTextBitmapData(char, nTextColor, lineWidth > 2 ? 2 : lineWidth, nStrokeColor);
  7280. size.bmpWidth = textInfo.width;
  7281. size.bmpHeight = textInfo.height;
  7282. return textInfo;
  7283. }
  7284. }
  7285. class TextRender {
  7286. constructor() {
  7287. this.fontSizeInfo = {};
  7288. this.charRender = null;
  7289. this.mapFont = {};
  7290. this.fontID = 0;
  7291. this.mapColor = [];
  7292. this.colorID = 0;
  7293. this.fontScaleX = 1.0;
  7294. this.fontScaleY = 1.0;
  7295. this._curStrPos = 0;
  7296. this.textAtlases = [];
  7297. this.isoTextures = [];
  7298. this.lastFont = null;
  7299. this.fontSizeW = 0;
  7300. this.fontSizeH = 0;
  7301. this.fontSizeOffX = 0;
  7302. this.fontSizeOffY = 0;
  7303. this.renderPerChar = true;
  7304. this.tmpAtlasPos = new Point();
  7305. this.textureMem = 0;
  7306. ILaya.TextAtlas = TextAtlas;
  7307. var bugIOS = false;
  7308. var miniadp = ILaya.Laya['MiniAdpter'];
  7309. if (miniadp && miniadp.systemInfo && miniadp.systemInfo.system) {
  7310. bugIOS = miniadp.systemInfo.system.toLowerCase() === 'ios 10.1.1';
  7311. }
  7312. if (ILaya.Browser.onMiniGame && !bugIOS)
  7313. TextRender.isWan1Wan = true;
  7314. this.charRender = ILaya.Render.isConchApp ? (new CharRender_Native()) : (new CharRender_Canvas(TextRender.atlasWidth, TextRender.atlasWidth, TextRender.scaleFontWithCtx, !TextRender.isWan1Wan, false));
  7315. TextRender.textRenderInst = this;
  7316. ILaya.Laya['textRender'] = this;
  7317. TextRender.atlasWidth2 = TextRender.atlasWidth * TextRender.atlasWidth;
  7318. }
  7319. setFont(font) {
  7320. if (this.lastFont == font)
  7321. return;
  7322. this.lastFont = font;
  7323. var fontsz = this.getFontSizeInfo(font._family);
  7324. var offx = fontsz >> 24;
  7325. var offy = (fontsz >> 16) & 0xff;
  7326. var fw = (fontsz >> 8) & 0xff;
  7327. var fh = fontsz & 0xff;
  7328. var k = font._size / TextRender.standardFontSize;
  7329. this.fontSizeOffX = Math.ceil(offx * k);
  7330. this.fontSizeOffY = Math.ceil(offy * k);
  7331. this.fontSizeW = Math.ceil(fw * k);
  7332. this.fontSizeH = Math.ceil(fh * k);
  7333. if (font._font.indexOf('italic') >= 0) {
  7334. this.fontStr = font._font.replace('italic', '');
  7335. }
  7336. else {
  7337. this.fontStr = font._font;
  7338. }
  7339. }
  7340. getNextChar(str) {
  7341. var len = str.length;
  7342. var start = this._curStrPos;
  7343. if (start >= len)
  7344. return null;
  7345. var i = start;
  7346. var state = 0;
  7347. for (; i < len; i++) {
  7348. var c = str.charCodeAt(i);
  7349. if ((c >>> 11) == 0x1b) {
  7350. if (state == 1)
  7351. break;
  7352. state = 1;
  7353. i++;
  7354. }
  7355. else if (c === 0xfe0e || c === 0xfe0f) ;
  7356. else if (c == 0x200d) {
  7357. state = 2;
  7358. }
  7359. else {
  7360. if (state == 0)
  7361. state = 1;
  7362. else if (state == 1)
  7363. break;
  7364. }
  7365. }
  7366. this._curStrPos = i;
  7367. return str.substring(start, i);
  7368. }
  7369. filltext(ctx, data, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  7370. if (data.length <= 0)
  7371. return;
  7372. var font = FontInfo.Parse(fontStr);
  7373. var nTextAlign = 0;
  7374. switch (textAlign) {
  7375. case 'center':
  7376. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  7377. break;
  7378. case 'right':
  7379. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  7380. break;
  7381. }
  7382. this._fast_filltext(ctx, data, null, x, y, font, color, strokeColor, lineWidth, nTextAlign, underLine);
  7383. }
  7384. fillWords(ctx, data, x, y, fontStr, color, strokeColor, lineWidth) {
  7385. if (!data)
  7386. return;
  7387. if (data.length <= 0)
  7388. return;
  7389. var font = FontInfo.Parse(fontStr);
  7390. this._fast_filltext(ctx, null, data, x, y, font, color, strokeColor, lineWidth, 0, 0);
  7391. }
  7392. _fast_filltext(ctx, data, htmlchars, x, y, font, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  7393. if (data && data.length < 1)
  7394. return;
  7395. if (htmlchars && htmlchars.length < 1)
  7396. return;
  7397. if (lineWidth < 0)
  7398. lineWidth = 0;
  7399. this.setFont(font);
  7400. this.fontScaleX = this.fontScaleY = 1.0;
  7401. if (!ILaya.Render.isConchApp && TextRender.scaleFontWithCtx) {
  7402. var sx = 1;
  7403. var sy = 1;
  7404. if (ILaya.Render.isConchApp) {
  7405. sx = ctx._curMat.getScaleX();
  7406. sy = ctx._curMat.getScaleY();
  7407. }
  7408. else {
  7409. sx = ctx.getMatScaleX();
  7410. sy = ctx.getMatScaleY();
  7411. }
  7412. if (sx < 1e-4 || sy < 1e-1)
  7413. return;
  7414. if (sx > 1)
  7415. this.fontScaleX = sx;
  7416. if (sy > 1)
  7417. this.fontScaleY = sy;
  7418. }
  7419. font._italic && (ctx._italicDeg = 13);
  7420. var wt = data;
  7421. var isWT = !htmlchars && (data instanceof WordText);
  7422. var str = data;
  7423. var isHtmlChar = !!htmlchars;
  7424. var sameTexData = isWT ? wt.pageChars : [];
  7425. var strWidth = 0;
  7426. if (isWT) {
  7427. str = wt._text;
  7428. strWidth = wt.width;
  7429. if (strWidth < 0) {
  7430. strWidth = wt.width = this.charRender.getWidth(this.fontStr, str);
  7431. }
  7432. }
  7433. else {
  7434. strWidth = str ? this.charRender.getWidth(this.fontStr, str) : 0;
  7435. }
  7436. switch (textAlign) {
  7437. case ILaya.Context.ENUM_TEXTALIGN_CENTER:
  7438. x -= strWidth / 2;
  7439. break;
  7440. case ILaya.Context.ENUM_TEXTALIGN_RIGHT:
  7441. x -= strWidth;
  7442. break;
  7443. }
  7444. if (wt && sameTexData) {
  7445. if (this.hasFreedText(sameTexData)) {
  7446. sameTexData = wt.pageChars = [];
  7447. }
  7448. }
  7449. var ri = null;
  7450. var splitTex = this.renderPerChar = (!isWT) || TextRender.forceSplitRender || isHtmlChar || (isWT && wt.splitRender);
  7451. if (!sameTexData || sameTexData.length < 1) {
  7452. if (splitTex) {
  7453. var stx = 0;
  7454. var sty = 0;
  7455. this._curStrPos = 0;
  7456. var curstr;
  7457. while (true) {
  7458. if (isHtmlChar) {
  7459. var chc = htmlchars[this._curStrPos++];
  7460. if (chc) {
  7461. curstr = chc.char;
  7462. stx = chc.x;
  7463. sty = chc.y;
  7464. }
  7465. else {
  7466. curstr = null;
  7467. }
  7468. }
  7469. else {
  7470. curstr = this.getNextChar(str);
  7471. }
  7472. if (!curstr)
  7473. break;
  7474. ri = this.getCharRenderInfo(curstr, font, color, strokeColor, lineWidth, false);
  7475. if (!ri) {
  7476. break;
  7477. }
  7478. if (ri.isSpace) ;
  7479. else {
  7480. var add = sameTexData[ri.tex.id];
  7481. if (!add) {
  7482. var o1 = { texgen: ri.tex.genID, tex: ri.tex, words: [] };
  7483. sameTexData[ri.tex.id] = o1;
  7484. add = o1.words;
  7485. }
  7486. else {
  7487. add = add.words;
  7488. }
  7489. if (ILaya.Render.isConchApp) {
  7490. add.push({ ri: ri, x: stx, y: sty, w: ri.bmpWidth / this.fontScaleX, h: ri.bmpHeight / this.fontScaleY });
  7491. }
  7492. else {
  7493. add.push({ ri: ri, x: stx + 1 / this.fontScaleX, y: sty, w: (ri.bmpWidth - 2) / this.fontScaleX, h: (ri.bmpHeight - 1) / this.fontScaleY });
  7494. }
  7495. stx += ri.width;
  7496. }
  7497. }
  7498. }
  7499. else {
  7500. var isotex = TextRender.noAtlas || strWidth * this.fontScaleX > TextRender.atlasWidth;
  7501. ri = this.getCharRenderInfo(str, font, color, strokeColor, lineWidth, isotex);
  7502. if (ILaya.Render.isConchApp) {
  7503. 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 }] };
  7504. }
  7505. else {
  7506. sameTexData[0] = { texgen: ri.tex.genID, tex: ri.tex, words: [{ ri: ri, x: 1 / this.fontScaleX, y: 0 / this.fontScaleY, w: (ri.bmpWidth - 2) / this.fontScaleX, h: (ri.bmpHeight - 1) / this.fontScaleY }] };
  7507. }
  7508. }
  7509. }
  7510. this._drawResortedWords(ctx, x, y, sameTexData);
  7511. ctx._italicDeg = 0;
  7512. }
  7513. _drawResortedWords(ctx, startx, starty, samePagesData) {
  7514. var isLastRender = ctx._charSubmitCache && ctx._charSubmitCache._enbale;
  7515. var mat = ctx._curMat;
  7516. var slen = samePagesData.length;
  7517. for (var id = 0; id < slen; id++) {
  7518. var dt = samePagesData[id];
  7519. if (!dt)
  7520. continue;
  7521. var pri = dt.words;
  7522. var pisz = pri.length;
  7523. if (pisz <= 0)
  7524. continue;
  7525. var tex = samePagesData[id].tex;
  7526. for (var j = 0; j < pisz; j++) {
  7527. var riSaved = pri[j];
  7528. var ri = riSaved.ri;
  7529. if (ri.isSpace)
  7530. continue;
  7531. ri.touch();
  7532. ctx.drawTexAlign = true;
  7533. if (ILaya.Render.isConchApp) {
  7534. ctx._drawTextureM(tex.texture, startx + riSaved.x - ri.orix, starty + riSaved.y - ri.oriy, riSaved.w, riSaved.h, null, 1.0, ri.uv);
  7535. }
  7536. else {
  7537. let t = tex;
  7538. 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);
  7539. }
  7540. if (ctx.touches) {
  7541. ctx.touches.push(ri);
  7542. }
  7543. }
  7544. }
  7545. }
  7546. hasFreedText(txts) {
  7547. var sz = txts.length;
  7548. for (var i = 0; i < sz; i++) {
  7549. var pri = txts[i];
  7550. if (!pri)
  7551. continue;
  7552. var tex = pri.tex;
  7553. if (tex.__destroyed || tex.genID != pri.texgen) {
  7554. return true;
  7555. }
  7556. }
  7557. return false;
  7558. }
  7559. getCharRenderInfo(str, font, color, strokeColor, lineWidth, isoTexture = false) {
  7560. var fid = this.mapFont[font._family];
  7561. if (fid == undefined) {
  7562. this.mapFont[font._family] = fid = this.fontID++;
  7563. }
  7564. var key = str + '_' + fid + '_' + font._size + '_' + color;
  7565. if (lineWidth > 0)
  7566. key += '_' + strokeColor + lineWidth;
  7567. if (font._bold)
  7568. key += 'P';
  7569. if (this.fontScaleX != 1 || this.fontScaleY != 1) {
  7570. key += (this.fontScaleX * 20 | 0) + '_' + (this.fontScaleY * 20 | 0);
  7571. }
  7572. var i = 0;
  7573. var sz = this.textAtlases.length;
  7574. var ri = null;
  7575. var atlas = null;
  7576. if (!isoTexture) {
  7577. for (i = 0; i < sz; i++) {
  7578. atlas = this.textAtlases[i];
  7579. ri = atlas.charMaps[key];
  7580. if (ri) {
  7581. ri.touch();
  7582. return ri;
  7583. }
  7584. }
  7585. }
  7586. ri = new CharRenderInfo();
  7587. this.charRender.scale(this.fontScaleX, this.fontScaleY);
  7588. ri.char = str;
  7589. ri.height = font._size;
  7590. var margin = ILaya.Render.isConchApp ? 0 : (font._size / 3 | 0);
  7591. var imgdt = null;
  7592. var w1 = Math.ceil(this.charRender.getWidth(this.fontStr, str) * this.fontScaleX);
  7593. if (w1 > this.charRender.canvasWidth) {
  7594. this.charRender.canvasWidth = Math.min(2048, w1 + margin * 2);
  7595. }
  7596. if (isoTexture) {
  7597. this.charRender.fontsz = font._size;
  7598. imgdt = this.charRender.getCharBmp(str, this.fontStr, lineWidth, color, strokeColor, ri, margin, margin, margin, margin, null);
  7599. var tex = TextTexture.getTextTexture(imgdt.width, imgdt.height);
  7600. tex.addChar(imgdt, 0, 0, ri.uv);
  7601. ri.tex = tex;
  7602. ri.orix = margin;
  7603. ri.oriy = margin;
  7604. tex.ri = ri;
  7605. this.isoTextures.push(tex);
  7606. }
  7607. else {
  7608. var len = str.length;
  7609. var lineExt = lineWidth * 1;
  7610. var fw = Math.ceil((this.fontSizeW + lineExt * 2) * this.fontScaleX);
  7611. var fh = Math.ceil((this.fontSizeH + lineExt * 2) * this.fontScaleY);
  7612. TextRender.imgdtRect[0] = ((margin - this.fontSizeOffX - lineExt) * this.fontScaleX) | 0;
  7613. TextRender.imgdtRect[1] = ((margin - this.fontSizeOffY - lineExt) * this.fontScaleY) | 0;
  7614. if (this.renderPerChar || len == 1) {
  7615. TextRender.imgdtRect[2] = Math.max(w1, fw);
  7616. TextRender.imgdtRect[3] = Math.max(w1, fh);
  7617. }
  7618. else {
  7619. TextRender.imgdtRect[2] = -1;
  7620. TextRender.imgdtRect[3] = fh;
  7621. }
  7622. this.charRender.fontsz = font._size;
  7623. imgdt = this.charRender.getCharBmp(str, this.fontStr, lineWidth, color, strokeColor, ri, margin, margin, margin, margin, TextRender.imgdtRect);
  7624. atlas = this.addBmpData(imgdt, ri);
  7625. if (TextRender.isWan1Wan) {
  7626. ri.orix = margin;
  7627. ri.oriy = margin;
  7628. }
  7629. else {
  7630. ri.orix = (this.fontSizeOffX + lineExt);
  7631. ri.oriy = (this.fontSizeOffY + lineExt);
  7632. }
  7633. atlas.charMaps[key] = ri;
  7634. }
  7635. return ri;
  7636. }
  7637. addBmpData(data, ri) {
  7638. var w = data.width;
  7639. var h = data.height;
  7640. var sz = this.textAtlases.length;
  7641. var atlas = null;
  7642. var find = false;
  7643. for (var i = 0; i < sz; i++) {
  7644. atlas = this.textAtlases[i];
  7645. find = atlas.getAEmpty(w, h, this.tmpAtlasPos);
  7646. if (find) {
  7647. break;
  7648. }
  7649. }
  7650. if (!find) {
  7651. atlas = new TextAtlas();
  7652. this.textAtlases.push(atlas);
  7653. find = atlas.getAEmpty(w, h, this.tmpAtlasPos);
  7654. if (!find) {
  7655. throw 'err1';
  7656. }
  7657. this.cleanAtlases();
  7658. }
  7659. if (find) {
  7660. atlas.texture.addChar(data, this.tmpAtlasPos.x, this.tmpAtlasPos.y, ri.uv);
  7661. ri.tex = atlas.texture;
  7662. }
  7663. return atlas;
  7664. }
  7665. GC() {
  7666. var i = 0;
  7667. var sz = this.textAtlases.length;
  7668. var dt = 0;
  7669. var destroyDt = TextRender.destroyAtlasDt;
  7670. var totalUsedRate = 0;
  7671. var totalUsedRateAtlas = 0;
  7672. var curloop = RenderInfo.loopCount;
  7673. var maxWasteRateID = -1;
  7674. var maxWasteRate = 0;
  7675. var tex = null;
  7676. var curatlas = null;
  7677. for (; i < sz; i++) {
  7678. curatlas = this.textAtlases[i];
  7679. tex = curatlas.texture;
  7680. if (tex) {
  7681. totalUsedRate += tex.curUsedCovRate;
  7682. totalUsedRateAtlas += tex.curUsedCovRateAtlas;
  7683. var waste = curatlas.usedRate - tex.curUsedCovRateAtlas;
  7684. if (maxWasteRate < waste) {
  7685. maxWasteRate = waste;
  7686. maxWasteRateID = i;
  7687. }
  7688. }
  7689. dt = curloop - curatlas.texture.lastTouchTm;
  7690. if (dt > destroyDt) {
  7691. TextRender.showLog && console.log('TextRender GC delete atlas ' + tex ? curatlas.texture.id : 'unk');
  7692. curatlas.destroy();
  7693. this.textAtlases[i] = this.textAtlases[sz - 1];
  7694. sz--;
  7695. i--;
  7696. maxWasteRateID = -1;
  7697. }
  7698. }
  7699. this.textAtlases.length = sz;
  7700. sz = this.isoTextures.length;
  7701. for (i = 0; i < sz; i++) {
  7702. tex = this.isoTextures[i];
  7703. dt = curloop - tex.lastTouchTm;
  7704. if (dt > TextRender.destroyUnusedTextureDt) {
  7705. tex.ri.deleted = true;
  7706. tex.ri.tex = null;
  7707. tex.destroy();
  7708. this.isoTextures[i] = this.isoTextures[sz - 1];
  7709. sz--;
  7710. i--;
  7711. }
  7712. }
  7713. this.isoTextures.length = sz;
  7714. var needGC = this.textAtlases.length > 1 && this.textAtlases.length - totalUsedRateAtlas >= 2;
  7715. if (TextRender.atlasWidth * TextRender.atlasWidth * 4 * this.textAtlases.length > TextRender.cleanMem || needGC || TextRender.simClean) {
  7716. TextRender.simClean = false;
  7717. TextRender.showLog && console.log('清理使用率低的贴图。总使用率:', totalUsedRateAtlas, ':', this.textAtlases.length, '最差贴图:' + maxWasteRateID);
  7718. if (maxWasteRateID >= 0) {
  7719. curatlas = this.textAtlases[maxWasteRateID];
  7720. curatlas.destroy();
  7721. this.textAtlases[maxWasteRateID] = this.textAtlases[this.textAtlases.length - 1];
  7722. this.textAtlases.length = this.textAtlases.length - 1;
  7723. }
  7724. }
  7725. TextTexture.clean();
  7726. }
  7727. cleanAtlases() {
  7728. }
  7729. getCharBmp(c) {
  7730. }
  7731. checkBmpLine(data, l, sx, ex) {
  7732. if (this.bmpData32.buffer != data.data.buffer) {
  7733. this.bmpData32 = new Uint32Array(data.data.buffer);
  7734. }
  7735. var stpos = data.width * l + sx;
  7736. for (var x = sx; x < ex; x++) {
  7737. if (this.bmpData32[stpos++] != 0)
  7738. return true;
  7739. }
  7740. return false;
  7741. }
  7742. updateBbx(data, curbbx, onlyH = false) {
  7743. var w = data.width;
  7744. var h = data.height;
  7745. var x = 0;
  7746. var sy = curbbx[1];
  7747. var ey = 0;
  7748. var y = sy;
  7749. if (this.checkBmpLine(data, sy, 0, w)) {
  7750. while (true) {
  7751. y = (sy + ey) / 2 | 0;
  7752. if (y + 1 >= sy) {
  7753. curbbx[1] = y;
  7754. break;
  7755. }
  7756. if (this.checkBmpLine(data, y, 0, w)) {
  7757. sy = y;
  7758. }
  7759. else {
  7760. ey = y;
  7761. }
  7762. }
  7763. }
  7764. if (curbbx[3] > h)
  7765. curbbx[3] = h;
  7766. else {
  7767. y = sy = curbbx[3];
  7768. ey = h;
  7769. if (this.checkBmpLine(data, sy, 0, w)) {
  7770. while (true) {
  7771. y = (sy + ey) / 2 | 0;
  7772. if (y - 1 <= sy) {
  7773. curbbx[3] = y;
  7774. break;
  7775. }
  7776. if (this.checkBmpLine(data, y, 0, w)) {
  7777. sy = y;
  7778. }
  7779. else {
  7780. ey = y;
  7781. }
  7782. }
  7783. }
  7784. }
  7785. if (onlyH)
  7786. return;
  7787. var minx = curbbx[0];
  7788. var stpos = w * curbbx[1];
  7789. for (y = curbbx[1]; y < curbbx[3]; y++) {
  7790. for (x = 0; x < minx; x++) {
  7791. if (this.bmpData32[stpos + x] != 0) {
  7792. minx = x;
  7793. break;
  7794. }
  7795. }
  7796. stpos += w;
  7797. }
  7798. curbbx[0] = minx;
  7799. var maxx = curbbx[2];
  7800. stpos = w * curbbx[1];
  7801. for (y = curbbx[1]; y < curbbx[3]; y++) {
  7802. for (x = maxx; x < w; x++) {
  7803. if (this.bmpData32[stpos + x] != 0) {
  7804. maxx = x;
  7805. break;
  7806. }
  7807. }
  7808. stpos += w;
  7809. }
  7810. curbbx[2] = maxx;
  7811. }
  7812. getFontSizeInfo(font) {
  7813. var finfo = this.fontSizeInfo[font];
  7814. if (finfo != undefined)
  7815. return finfo;
  7816. var fontstr = 'bold ' + TextRender.standardFontSize + 'px ' + font;
  7817. if (TextRender.isWan1Wan) {
  7818. this.fontSizeW = this.charRender.getWidth(fontstr, '有') * 1.5;
  7819. this.fontSizeH = TextRender.standardFontSize * 1.5;
  7820. var szinfo = this.fontSizeW << 8 | this.fontSizeH;
  7821. this.fontSizeInfo[font] = szinfo;
  7822. return szinfo;
  7823. }
  7824. TextRender.pixelBBX[0] = TextRender.standardFontSize / 2;
  7825. TextRender.pixelBBX[1] = TextRender.standardFontSize / 2;
  7826. TextRender.pixelBBX[2] = TextRender.standardFontSize;
  7827. TextRender.pixelBBX[3] = TextRender.standardFontSize;
  7828. var orix = 16;
  7829. var oriy = 16;
  7830. var marginr = 16;
  7831. var marginb = 16;
  7832. this.charRender.scale(1, 1);
  7833. TextRender.tmpRI.height = TextRender.standardFontSize;
  7834. this.charRender.fontsz = TextRender.standardFontSize;
  7835. var bmpdt = this.charRender.getCharBmp('g', fontstr, 0, 'red', null, TextRender.tmpRI, orix, oriy, marginr, marginb);
  7836. if (ILaya.Render.isConchApp) {
  7837. bmpdt.data = new Uint8ClampedArray(bmpdt.data);
  7838. }
  7839. this.bmpData32 = new Uint32Array(bmpdt.data.buffer);
  7840. this.updateBbx(bmpdt, TextRender.pixelBBX, false);
  7841. bmpdt = this.charRender.getCharBmp('有', fontstr, 0, 'red', null, TextRender.tmpRI, oriy, oriy, marginr, marginb);
  7842. if (ILaya.Render.isConchApp) {
  7843. bmpdt.data = new Uint8ClampedArray(bmpdt.data);
  7844. }
  7845. this.bmpData32 = new Uint32Array(bmpdt.data.buffer);
  7846. if (TextRender.pixelBBX[2] < orix + TextRender.tmpRI.width)
  7847. TextRender.pixelBBX[2] = orix + TextRender.tmpRI.width;
  7848. this.updateBbx(bmpdt, TextRender.pixelBBX, false);
  7849. if (ILaya.Render.isConchApp) {
  7850. orix = 0;
  7851. oriy = 0;
  7852. }
  7853. var xoff = Math.max(orix - TextRender.pixelBBX[0], 0);
  7854. var yoff = Math.max(oriy - TextRender.pixelBBX[1], 0);
  7855. var bbxw = TextRender.pixelBBX[2] - TextRender.pixelBBX[0];
  7856. var bbxh = TextRender.pixelBBX[3] - TextRender.pixelBBX[1];
  7857. var sizeinfo = xoff << 24 | yoff << 16 | bbxw << 8 | bbxh;
  7858. this.fontSizeInfo[font] = sizeinfo;
  7859. return sizeinfo;
  7860. }
  7861. printDbgInfo() {
  7862. console.log('图集个数:' + this.textAtlases.length + ',每个图集大小:' + TextRender.atlasWidth + 'x' + TextRender.atlasWidth, ' 用canvas:', TextRender.isWan1Wan);
  7863. console.log('图集占用空间:' + (TextRender.atlasWidth * TextRender.atlasWidth * 4 / 1024 / 1024 * this.textAtlases.length) + 'M');
  7864. console.log('缓存用到的字体:');
  7865. for (var f in this.mapFont) {
  7866. var fontsz = this.getFontSizeInfo(f);
  7867. var offx = fontsz >> 24;
  7868. var offy = (fontsz >> 16) & 0xff;
  7869. var fw = (fontsz >> 8) & 0xff;
  7870. var fh = fontsz & 0xff;
  7871. console.log(' ' + f, ' off:', offx, offy, ' size:', fw, fh);
  7872. }
  7873. var num = 0;
  7874. console.log('缓存数据:');
  7875. var totalUsedRate = 0;
  7876. var totalUsedRateAtlas = 0;
  7877. this.textAtlases.forEach(function (a) {
  7878. var id = a.texture.id;
  7879. var dt = RenderInfo.loopCount - a.texture.lastTouchTm;
  7880. var dtstr = dt > 0 ? ('' + dt + '帧以前') : '当前帧';
  7881. totalUsedRate += a.texture.curUsedCovRate;
  7882. totalUsedRateAtlas += a.texture.curUsedCovRateAtlas;
  7883. console.log('--图集(id:' + id + ',当前使用率:' + (a.texture.curUsedCovRate * 1000 | 0) + '‰', '当前图集使用率:', (a.texture.curUsedCovRateAtlas * 100 | 0) + '%', '图集使用率:', (a.usedRate * 100 | 0), '%, 使用于:' + dtstr + ')--:');
  7884. for (var k in a.charMaps) {
  7885. var ri = a.charMaps[k];
  7886. 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);
  7887. num++;
  7888. }
  7889. });
  7890. console.log('独立贴图文字(' + this.isoTextures.length + '个):');
  7891. this.isoTextures.forEach(function (tex) {
  7892. console.log(' size:', tex._texW, tex._texH, 'touch间隔:', (RenderInfo.loopCount - tex.lastTouchTm), 'char:', tex.ri.char);
  7893. });
  7894. console.log('总缓存:', num, '总使用率:', totalUsedRate, '总当前图集使用率:', totalUsedRateAtlas);
  7895. }
  7896. showAtlas(n, bgcolor, x, y, w, h) {
  7897. if (!this.textAtlases[n]) {
  7898. console.log('没有这个图集');
  7899. return null;
  7900. }
  7901. var sp = new ILaya.Sprite();
  7902. var texttex = this.textAtlases[n].texture;
  7903. var texture = {
  7904. width: TextRender.atlasWidth,
  7905. height: TextRender.atlasWidth,
  7906. sourceWidth: TextRender.atlasWidth,
  7907. sourceHeight: TextRender.atlasWidth,
  7908. offsetX: 0,
  7909. offsetY: 0,
  7910. getIsReady: function () { return true; },
  7911. _addReference: function () { },
  7912. _removeReference: function () { },
  7913. _getSource: function () { return texttex._getSource(); },
  7914. bitmap: { id: texttex.id },
  7915. _uv: Texture.DEF_UV
  7916. };
  7917. sp.size = function (w, h) {
  7918. this.width = w;
  7919. this.height = h;
  7920. sp.graphics.clear();
  7921. sp.graphics.drawRect(0, 0, sp.width, sp.height, bgcolor);
  7922. sp.graphics.drawTexture(texture, 0, 0, sp.width, sp.height);
  7923. return this;
  7924. };
  7925. sp.graphics.drawRect(0, 0, w, h, bgcolor);
  7926. sp.graphics.drawTexture(texture, 0, 0, w, h);
  7927. sp.pos(x, y);
  7928. ILaya.stage.addChild(sp);
  7929. return sp;
  7930. }
  7931. filltext_native(ctx, data, htmlchars, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  7932. if (data && data.length <= 0)
  7933. return;
  7934. if (htmlchars && htmlchars.length < 1)
  7935. return;
  7936. var font = FontInfo.Parse(fontStr);
  7937. var nTextAlign = 0;
  7938. switch (textAlign) {
  7939. case 'center':
  7940. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  7941. break;
  7942. case 'right':
  7943. nTextAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  7944. break;
  7945. }
  7946. return this._fast_filltext(ctx, data, htmlchars, x, y, font, color, strokeColor, lineWidth, nTextAlign, underLine);
  7947. }
  7948. }
  7949. TextRender.useOldCharBook = false;
  7950. TextRender.atlasWidth = 2048;
  7951. TextRender.noAtlas = false;
  7952. TextRender.forceSplitRender = false;
  7953. TextRender.forceWholeRender = false;
  7954. TextRender.scaleFontWithCtx = true;
  7955. TextRender.standardFontSize = 32;
  7956. TextRender.destroyAtlasDt = 10;
  7957. TextRender.checkCleanTextureDt = 2000;
  7958. TextRender.destroyUnusedTextureDt = 3000;
  7959. TextRender.cleanMem = 100 * 1024 * 1024;
  7960. TextRender.isWan1Wan = false;
  7961. TextRender.showLog = false;
  7962. TextRender.debugUV = false;
  7963. TextRender.atlasWidth2 = 2048 * 2048;
  7964. TextRender.tmpRI = new CharRenderInfo();
  7965. TextRender.pixelBBX = [0, 0, 0, 0];
  7966. TextRender.textRenderInst = null;
  7967. TextRender.imgdtRect = [0, 0, 0, 0];
  7968. TextRender.simClean = false;
  7969. TextTexture.gTextRender = TextRender;
  7970. class Context {
  7971. constructor() {
  7972. this._tmpMatrix = new Matrix();
  7973. this._drawTexToDrawTri_Vert = new Float32Array(8);
  7974. this._drawTexToDrawTri_Index = new Uint16Array([0, 1, 2, 0, 2, 3]);
  7975. this._tempUV = new Float32Array(8);
  7976. this._drawTriUseAbsMatrix = false;
  7977. this._id = ++Context._COUNT;
  7978. this._other = null;
  7979. this._renderNextSubmitIndex = 0;
  7980. this._path = null;
  7981. this._drawCount = 1;
  7982. this._width = Context._MAXSIZE;
  7983. this._height = Context._MAXSIZE;
  7984. this._renderCount = 0;
  7985. this._isConvexCmd = true;
  7986. this._submits = null;
  7987. this._curSubmit = null;
  7988. this._submitKey = new SubmitKey();
  7989. this._mesh = null;
  7990. this._pathMesh = null;
  7991. this._triangleMesh = null;
  7992. this.meshlist = [];
  7993. this._transedPoints = new Array(8);
  7994. this._temp4Points = new Array(8);
  7995. this._clipRect = Context.MAXCLIPRECT;
  7996. this._globalClipMatrix = new Matrix(Context._MAXSIZE, 0, 0, Context._MAXSIZE, 0, 0);
  7997. this._clipInCache = false;
  7998. this._clipInfoID = 0;
  7999. this._clipID_Gen = 0;
  8000. this._curMat = null;
  8001. this._lastMatScaleX = 1.0;
  8002. this._lastMatScaleY = 1.0;
  8003. this._lastMat_a = 1.0;
  8004. this._lastMat_b = 0.0;
  8005. this._lastMat_c = 0.0;
  8006. this._lastMat_d = 1.0;
  8007. this._nBlendType = 0;
  8008. this._save = null;
  8009. this._targets = null;
  8010. this._charSubmitCache = null;
  8011. this._saveMark = null;
  8012. this._shader2D = new Shader2D();
  8013. this.sprite = null;
  8014. this._italicDeg = 0;
  8015. this._lastTex = null;
  8016. this._fillColor = 0;
  8017. this._flushCnt = 0;
  8018. this.defTexture = null;
  8019. this._colorFiler = null;
  8020. this.drawTexAlign = false;
  8021. this._incache = false;
  8022. this.isMain = false;
  8023. Context._contextcount++;
  8024. Context._textRender = Context._textRender || new TextRender();
  8025. if (!this.defTexture) {
  8026. var defTex2d = new Texture2D(2, 2);
  8027. defTex2d.setPixels(new Uint8Array(16));
  8028. defTex2d.lock = true;
  8029. this.defTexture = new Texture(defTex2d);
  8030. }
  8031. this._lastTex = this.defTexture;
  8032. this.clear();
  8033. }
  8034. static __init__() {
  8035. Context.MAXCLIPRECT = new Rectangle(0, 0, Context._MAXSIZE, Context._MAXSIZE);
  8036. ContextParams.DEFAULT = new ContextParams();
  8037. }
  8038. drawImage(...args) {
  8039. }
  8040. getImageData(...args) {
  8041. }
  8042. measureText(text) {
  8043. return null;
  8044. }
  8045. setTransform(...args) {
  8046. }
  8047. $transform(a, b, c, d, tx, ty) {
  8048. }
  8049. get lineJoin() {
  8050. return null;
  8051. }
  8052. set lineJoin(value) {
  8053. }
  8054. get lineCap() {
  8055. return null;
  8056. }
  8057. set lineCap(value) {
  8058. }
  8059. get miterLimit() {
  8060. return null;
  8061. }
  8062. set miterLimit(value) {
  8063. }
  8064. clearRect(x, y, width, height) {
  8065. }
  8066. _drawRect(x, y, width, height, style) {
  8067. Stat.renderBatches++;
  8068. style && (this.fillStyle = style);
  8069. this.fillRect(x, y, width, height, null);
  8070. }
  8071. drawTexture2(x, y, pivotX, pivotY, m, args2) {
  8072. }
  8073. transformByMatrix(matrix, tx, ty) {
  8074. this.transform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx + tx, matrix.ty + ty);
  8075. }
  8076. saveTransform(matrix) {
  8077. this.save();
  8078. }
  8079. restoreTransform(matrix) {
  8080. this.restore();
  8081. }
  8082. drawRect(x, y, width, height, fillColor, lineColor, lineWidth) {
  8083. var ctx = this;
  8084. if (fillColor != null) {
  8085. ctx.fillStyle = fillColor;
  8086. ctx.fillRect(x, y, width, height);
  8087. }
  8088. if (lineColor != null) {
  8089. ctx.strokeStyle = lineColor;
  8090. ctx.lineWidth = lineWidth;
  8091. ctx.strokeRect(x, y, width, height);
  8092. }
  8093. }
  8094. alpha(value) {
  8095. this.globalAlpha *= value;
  8096. }
  8097. _transform(mat, pivotX, pivotY) {
  8098. this.translate(pivotX, pivotY);
  8099. this.transform(mat.a, mat.b, mat.c, mat.d, mat.tx, mat.ty);
  8100. this.translate(-pivotX, -pivotY);
  8101. }
  8102. _rotate(angle, pivotX, pivotY) {
  8103. this.translate(pivotX, pivotY);
  8104. this.rotate(angle);
  8105. this.translate(-pivotX, -pivotY);
  8106. }
  8107. _scale(scaleX, scaleY, pivotX, pivotY) {
  8108. this.translate(pivotX, pivotY);
  8109. this.scale(scaleX, scaleY);
  8110. this.translate(-pivotX, -pivotY);
  8111. }
  8112. _drawLine(x, y, fromX, fromY, toX, toY, lineColor, lineWidth, vid) {
  8113. this.beginPath();
  8114. this.strokeStyle = lineColor;
  8115. this.lineWidth = lineWidth;
  8116. this.moveTo(x + fromX, y + fromY);
  8117. this.lineTo(x + toX, y + toY);
  8118. this.stroke();
  8119. }
  8120. _drawLines(x, y, points, lineColor, lineWidth, vid) {
  8121. this.beginPath();
  8122. this.strokeStyle = lineColor;
  8123. this.lineWidth = lineWidth;
  8124. var n = points.length;
  8125. this.addPath(points.slice(), false, false, x, y);
  8126. this.stroke();
  8127. }
  8128. drawCurves(x, y, points, lineColor, lineWidth) {
  8129. this.beginPath();
  8130. this.strokeStyle = lineColor;
  8131. this.lineWidth = lineWidth;
  8132. this.moveTo(x + points[0], y + points[1]);
  8133. var i = 2, n = points.length;
  8134. while (i < n) {
  8135. this.quadraticCurveTo(x + points[i++], y + points[i++], x + points[i++], y + points[i++]);
  8136. }
  8137. this.stroke();
  8138. }
  8139. _fillAndStroke(fillColor, strokeColor, lineWidth, isConvexPolygon = false) {
  8140. if (fillColor != null) {
  8141. this.fillStyle = fillColor;
  8142. this.fill();
  8143. }
  8144. if (strokeColor != null && lineWidth > 0) {
  8145. this.strokeStyle = strokeColor;
  8146. this.lineWidth = lineWidth;
  8147. this.stroke();
  8148. }
  8149. }
  8150. _drawCircle(x, y, radius, fillColor, lineColor, lineWidth, vid) {
  8151. Stat.renderBatches++;
  8152. this.beginPath(true);
  8153. this.arc(x, y, radius, 0, Context.PI2);
  8154. this.closePath();
  8155. this._fillAndStroke(fillColor, lineColor, lineWidth);
  8156. }
  8157. _drawPie(x, y, radius, startAngle, endAngle, fillColor, lineColor, lineWidth, vid) {
  8158. this.beginPath();
  8159. this.moveTo(x, y);
  8160. this.arc(x, y, radius, startAngle, endAngle);
  8161. this.closePath();
  8162. this._fillAndStroke(fillColor, lineColor, lineWidth);
  8163. }
  8164. _drawPoly(x, y, points, fillColor, lineColor, lineWidth, isConvexPolygon, vid) {
  8165. var n = points.length;
  8166. this.beginPath();
  8167. this.addPath(points.slice(), true, isConvexPolygon, x, y);
  8168. this.closePath();
  8169. this._fillAndStroke(fillColor, lineColor, lineWidth, isConvexPolygon);
  8170. }
  8171. _drawPath(x, y, paths, brush, pen) {
  8172. this.beginPath();
  8173. for (var i = 0, n = paths.length; i < n; i++) {
  8174. var path = paths[i];
  8175. switch (path[0]) {
  8176. case "moveTo":
  8177. this.moveTo(x + path[1], y + path[2]);
  8178. break;
  8179. case "lineTo":
  8180. this.lineTo(x + path[1], y + path[2]);
  8181. break;
  8182. case "arcTo":
  8183. this.arcTo(x + path[1], y + path[2], x + path[3], y + path[4], path[5]);
  8184. break;
  8185. case "closePath":
  8186. this.closePath();
  8187. break;
  8188. }
  8189. }
  8190. if (brush != null) {
  8191. this.fillStyle = brush.fillStyle;
  8192. this.fill();
  8193. }
  8194. if (pen != null) {
  8195. this.strokeStyle = pen.strokeStyle;
  8196. this.lineWidth = pen.lineWidth || 1;
  8197. this.lineJoin = pen.lineJoin;
  8198. this.lineCap = pen.lineCap;
  8199. this.miterLimit = pen.miterLimit;
  8200. this.stroke();
  8201. }
  8202. }
  8203. static set2DRenderConfig() {
  8204. var gl = LayaGL.instance;
  8205. WebGLContext.setBlend(gl, true);
  8206. WebGLContext.setBlendFunc(gl, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  8207. WebGLContext.setDepthTest(gl, false);
  8208. WebGLContext.setCullFace(gl, false);
  8209. WebGLContext.setDepthMask(gl, true);
  8210. WebGLContext.setFrontFace(gl, gl.CCW);
  8211. gl.viewport(0, 0, RenderState2D.width, RenderState2D.height);
  8212. }
  8213. clearBG(r, g, b, a) {
  8214. var gl = WebGLContext.mainContext;
  8215. gl.clearColor(r, g, b, a);
  8216. gl.clear(gl.COLOR_BUFFER_BIT);
  8217. }
  8218. _getSubmits() {
  8219. return this._submits;
  8220. }
  8221. _releaseMem(keepRT = false) {
  8222. if (!this._submits)
  8223. return;
  8224. this._curMat.destroy();
  8225. this._curMat = null;
  8226. this._shader2D.destroy();
  8227. this._shader2D = null;
  8228. this._charSubmitCache.clear();
  8229. for (var i = 0, n = this._submits._length; i < n; i++) {
  8230. this._submits[i].releaseRender();
  8231. }
  8232. this._submits.length = 0;
  8233. this._submits._length = 0;
  8234. this._submits = null;
  8235. this._curSubmit = null;
  8236. this._path = null;
  8237. this._save = null;
  8238. var sz;
  8239. for (i = 0, sz = this.meshlist.length; i < sz; i++) {
  8240. var curm = this.meshlist[i];
  8241. curm.destroy();
  8242. }
  8243. this.meshlist.length = 0;
  8244. this.sprite = null;
  8245. if (!keepRT) {
  8246. this._targets && (this._targets.destroy());
  8247. this._targets = null;
  8248. }
  8249. }
  8250. destroy(keepRT = false) {
  8251. --Context._contextcount;
  8252. this.sprite = null;
  8253. this._releaseMem(keepRT);
  8254. this._charSubmitCache.destroy();
  8255. this._mesh.destroy();
  8256. if (!keepRT) {
  8257. this._targets && this._targets.destroy();
  8258. this._targets = null;
  8259. }
  8260. }
  8261. clear() {
  8262. if (!this._submits) {
  8263. this._other = ContextParams.DEFAULT;
  8264. this._curMat = Matrix.create();
  8265. this._charSubmitCache = new CharSubmitCache();
  8266. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8267. this.meshlist.push(this._mesh);
  8268. this._pathMesh = MeshVG.getAMesh(this.isMain);
  8269. this.meshlist.push(this._pathMesh);
  8270. this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  8271. this.meshlist.push(this._triangleMesh);
  8272. this._submits = [];
  8273. this._save = [SaveMark.Create(this)];
  8274. this._save.length = 10;
  8275. this._shader2D = new Shader2D();
  8276. }
  8277. this._submitKey.clear();
  8278. this._mesh.clearVB();
  8279. this._renderCount++;
  8280. this._drawCount = 1;
  8281. this._other = ContextParams.DEFAULT;
  8282. this._other.lineWidth = this._shader2D.ALPHA = 1.0;
  8283. this._nBlendType = 0;
  8284. this._clipRect = Context.MAXCLIPRECT;
  8285. this._curSubmit = SubmitBase.RENDERBASE;
  8286. SubmitBase.RENDERBASE._ref = 0xFFFFFF;
  8287. SubmitBase.RENDERBASE._numEle = 0;
  8288. this._shader2D.fillStyle = this._shader2D.strokeStyle = DrawStyle.DEFAULT;
  8289. for (var i = 0, n = this._submits._length; i < n; i++)
  8290. this._submits[i].releaseRender();
  8291. this._submits._length = 0;
  8292. this._curMat.identity();
  8293. this._other.clear();
  8294. this._saveMark = this._save[0];
  8295. this._save._length = 1;
  8296. }
  8297. size(w, h) {
  8298. if (this._width != w || this._height != h) {
  8299. this._width = w;
  8300. this._height = h;
  8301. if (this._targets) {
  8302. this._targets.destroy();
  8303. this._targets = new RenderTexture2D(w, h, BaseTexture.FORMAT_R8G8B8A8, -1);
  8304. }
  8305. if (this.isMain) {
  8306. WebGLContext.mainContext.viewport(0, 0, w, h);
  8307. RenderState2D.width = w;
  8308. RenderState2D.height = h;
  8309. }
  8310. }
  8311. if (w === 0 && h === 0)
  8312. this._releaseMem();
  8313. }
  8314. set asBitmap(value) {
  8315. if (value) {
  8316. this._targets || (this._targets = new RenderTexture2D(this._width, this._height, BaseTexture.FORMAT_R8G8B8A8, -1));
  8317. if (!this._width || !this._height)
  8318. throw Error("asBitmap no size!");
  8319. }
  8320. else {
  8321. this._targets && this._targets.destroy();
  8322. this._targets = null;
  8323. }
  8324. }
  8325. getMatScaleX() {
  8326. if (this._lastMat_a == this._curMat.a && this._lastMat_b == this._curMat.b)
  8327. return this._lastMatScaleX;
  8328. this._lastMatScaleX = this._curMat.getScaleX();
  8329. this._lastMat_a = this._curMat.a;
  8330. this._lastMat_b = this._curMat.b;
  8331. return this._lastMatScaleX;
  8332. }
  8333. getMatScaleY() {
  8334. if (this._lastMat_c == this._curMat.c && this._lastMat_d == this._curMat.d)
  8335. return this._lastMatScaleY;
  8336. this._lastMatScaleY = this._curMat.getScaleY();
  8337. this._lastMat_c = this._curMat.c;
  8338. this._lastMat_d = this._curMat.d;
  8339. return this._lastMatScaleY;
  8340. }
  8341. setFillColor(color) {
  8342. this._fillColor = color;
  8343. }
  8344. getFillColor() {
  8345. return this._fillColor;
  8346. }
  8347. set fillStyle(value) {
  8348. if (!this._shader2D.fillStyle.equal(value)) {
  8349. SaveBase.save(this, SaveBase.TYPE_FILESTYLE, this._shader2D, false);
  8350. this._shader2D.fillStyle = DrawStyle.create(value);
  8351. this._submitKey.other = -this._shader2D.fillStyle.toInt();
  8352. }
  8353. }
  8354. get fillStyle() {
  8355. return this._shader2D.fillStyle;
  8356. }
  8357. set globalAlpha(value) {
  8358. value = Math.floor(value * 1000) / 1000;
  8359. if (value != this._shader2D.ALPHA) {
  8360. SaveBase.save(this, SaveBase.TYPE_ALPHA, this._shader2D, false);
  8361. this._shader2D.ALPHA = value;
  8362. }
  8363. }
  8364. get globalAlpha() {
  8365. return this._shader2D.ALPHA;
  8366. }
  8367. set textAlign(value) {
  8368. (this._other.textAlign === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_TEXTALIGN, this._other, false), this._other.textAlign = value);
  8369. }
  8370. get textAlign() {
  8371. return this._other.textAlign;
  8372. }
  8373. set textBaseline(value) {
  8374. (this._other.textBaseline === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_TEXTBASELINE, this._other, false), this._other.textBaseline = value);
  8375. }
  8376. get textBaseline() {
  8377. return this._other.textBaseline;
  8378. }
  8379. set globalCompositeOperation(value) {
  8380. var n = BlendMode.TOINT[value];
  8381. n == null || (this._nBlendType === n) || (SaveBase.save(this, SaveBase.TYPE_GLOBALCOMPOSITEOPERATION, this, true), this._curSubmit = SubmitBase.RENDERBASE, this._nBlendType = n);
  8382. }
  8383. get globalCompositeOperation() {
  8384. return BlendMode.NAMES[this._nBlendType];
  8385. }
  8386. set strokeStyle(value) {
  8387. 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());
  8388. }
  8389. get strokeStyle() {
  8390. return this._shader2D.strokeStyle;
  8391. }
  8392. translate(x, y) {
  8393. if (x !== 0 || y !== 0) {
  8394. SaveTranslate.save(this);
  8395. if (this._curMat._bTransform) {
  8396. SaveTransform.save(this);
  8397. this._curMat.tx += (x * this._curMat.a + y * this._curMat.c);
  8398. this._curMat.ty += (x * this._curMat.b + y * this._curMat.d);
  8399. }
  8400. else {
  8401. this._curMat.tx = x;
  8402. this._curMat.ty = y;
  8403. }
  8404. }
  8405. }
  8406. set lineWidth(value) {
  8407. (this._other.lineWidth === value) || (this._other = this._other.make(), SaveBase.save(this, SaveBase.TYPE_LINEWIDTH, this._other, false), this._other.lineWidth = value);
  8408. }
  8409. get lineWidth() {
  8410. return this._other.lineWidth;
  8411. }
  8412. save() {
  8413. this._save[this._save._length++] = SaveMark.Create(this);
  8414. }
  8415. restore() {
  8416. var sz = this._save._length;
  8417. var lastBlend = this._nBlendType;
  8418. if (sz < 1)
  8419. return;
  8420. for (var i = sz - 1; i >= 0; i--) {
  8421. var o = this._save[i];
  8422. o.restore(this);
  8423. if (o.isSaveMark()) {
  8424. this._save._length = i;
  8425. return;
  8426. }
  8427. }
  8428. if (lastBlend != this._nBlendType) {
  8429. this._curSubmit = SubmitBase.RENDERBASE;
  8430. }
  8431. }
  8432. set font(str) {
  8433. this._other = this._other.make();
  8434. SaveBase.save(this, SaveBase.TYPE_FONT, this._other, false);
  8435. }
  8436. fillText(txt, x, y, fontStr, color, align) {
  8437. this._fillText(txt, null, x, y, fontStr, color, null, 0, null);
  8438. }
  8439. _fillText(txt, words, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  8440. if (txt)
  8441. Context._textRender.filltext(this, txt, x, y, fontStr, color, strokeColor, lineWidth, textAlign, underLine);
  8442. else if (words)
  8443. Context._textRender.fillWords(this, words, x, y, fontStr, color, strokeColor, lineWidth);
  8444. }
  8445. _fast_filltext(data, x, y, fontObj, color, strokeColor, lineWidth, textAlign, underLine = 0) {
  8446. Context._textRender._fast_filltext(this, data, null, x, y, fontObj, color, strokeColor, lineWidth, textAlign, underLine);
  8447. }
  8448. fillWords(words, x, y, fontStr, color) {
  8449. this._fillText(null, words, x, y, fontStr, color, null, -1, null, 0);
  8450. }
  8451. fillBorderWords(words, x, y, font, color, borderColor, lineWidth) {
  8452. this._fillBorderText(null, words, x, y, font, color, borderColor, lineWidth, null);
  8453. }
  8454. drawText(text, x, y, font, color, textAlign) {
  8455. this._fillText(text, null, x, y, font, ColorUtils.create(color).strColor, null, -1, textAlign);
  8456. }
  8457. strokeWord(text, x, y, font, color, lineWidth, textAlign) {
  8458. this._fillText(text, null, x, y, font, null, ColorUtils.create(color).strColor, lineWidth || 1, textAlign);
  8459. }
  8460. fillBorderText(txt, x, y, fontStr, fillColor, borderColor, lineWidth, textAlign) {
  8461. this._fillBorderText(txt, null, x, y, fontStr, ColorUtils.create(fillColor).strColor, ColorUtils.create(borderColor).strColor, lineWidth, textAlign);
  8462. }
  8463. _fillBorderText(txt, words, x, y, fontStr, fillColor, borderColor, lineWidth, textAlign) {
  8464. this._fillText(txt, words, x, y, fontStr, fillColor, borderColor, lineWidth || 1, textAlign);
  8465. }
  8466. _fillRect(x, y, width, height, rgba) {
  8467. var submit = this._curSubmit;
  8468. var sameKey = submit && (submit._key.submitType === SubmitBase.KEY_DRAWTEXTURE && submit._key.blendShader === this._nBlendType);
  8469. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8470. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8471. this.meshlist.push(this._mesh);
  8472. sameKey = false;
  8473. }
  8474. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  8475. this.transformQuad(x, y, width, height, 0, this._curMat, this._transedPoints);
  8476. if (!this.clipedOff(this._transedPoints)) {
  8477. this._mesh.addQuad(this._transedPoints, Texture.NO_UV, rgba, false);
  8478. if (!sameKey) {
  8479. submit = this._curSubmit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8480. this._submits[this._submits._length++] = submit;
  8481. this._copyClipInfo(submit, this._globalClipMatrix);
  8482. submit.shaderValue.textureHost = this._lastTex;
  8483. submit._key.other = (this._lastTex && this._lastTex.bitmap) ? this._lastTex.bitmap.id : -1;
  8484. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8485. }
  8486. this._curSubmit._numEle += 6;
  8487. this._mesh.indexNum += 6;
  8488. this._mesh.vertNum += 4;
  8489. }
  8490. }
  8491. fillRect(x, y, width, height, fillStyle) {
  8492. var drawstyle = fillStyle ? DrawStyle.create(fillStyle) : this._shader2D.fillStyle;
  8493. var rgba = this.mixRGBandAlpha(drawstyle.toInt());
  8494. this._fillRect(x, y, width, height, rgba);
  8495. }
  8496. fillTexture(texture, x, y, width, height, type, offset, other) {
  8497. if (!texture._getSource()) {
  8498. this.sprite && ILaya.systemTimer.callLater(this, this._repaintSprite);
  8499. return;
  8500. }
  8501. this._fillTexture(texture, texture.width, texture.height, texture.uvrect, x, y, width, height, type, offset.x, offset.y);
  8502. }
  8503. _fillTexture(texture, texw, texh, texuvRect, x, y, width, height, type, offsetx, offsety) {
  8504. var submit = this._curSubmit;
  8505. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8506. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8507. this.meshlist.push(this._mesh);
  8508. }
  8509. var repeatx = true;
  8510. var repeaty = true;
  8511. switch (type) {
  8512. case "repeat": break;
  8513. case "repeat-x":
  8514. repeaty = false;
  8515. break;
  8516. case "repeat-y":
  8517. repeatx = false;
  8518. break;
  8519. case "no-repeat":
  8520. repeatx = repeaty = false;
  8521. break;
  8522. default: break;
  8523. }
  8524. var uv = this._temp4Points;
  8525. var stu = 0;
  8526. var stv = 0;
  8527. var stx = 0, sty = 0, edx = 0, edy = 0;
  8528. if (offsetx < 0) {
  8529. stx = x;
  8530. stu = (-offsetx % texw) / texw;
  8531. }
  8532. else {
  8533. stx = x + offsetx;
  8534. }
  8535. if (offsety < 0) {
  8536. sty = y;
  8537. stv = (-offsety % texh) / texh;
  8538. }
  8539. else {
  8540. sty = y + offsety;
  8541. }
  8542. edx = x + width;
  8543. edy = y + height;
  8544. (!repeatx) && (edx = Math.min(edx, x + offsetx + texw));
  8545. (!repeaty) && (edy = Math.min(edy, y + offsety + texh));
  8546. if (edx < x || edy < y)
  8547. return;
  8548. if (stx > edx || sty > edy)
  8549. return;
  8550. var edu = (edx - x - offsetx) / texw;
  8551. var edv = (edy - y - offsety) / texh;
  8552. this.transformQuad(stx, sty, edx - stx, edy - sty, 0, this._curMat, this._transedPoints);
  8553. uv[0] = stu;
  8554. uv[1] = stv;
  8555. uv[2] = edu;
  8556. uv[3] = stv;
  8557. uv[4] = edu;
  8558. uv[5] = edv;
  8559. uv[6] = stu;
  8560. uv[7] = edv;
  8561. if (!this.clipedOff(this._transedPoints)) {
  8562. var rgba = this._mixRGBandAlpha(0xffffffff, this._shader2D.ALPHA);
  8563. this._mesh.addQuad(this._transedPoints, uv, rgba, true);
  8564. var sv = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  8565. sv.defines.add(ShaderDefines2D.FILLTEXTURE);
  8566. sv.u_TexRange = texuvRect;
  8567. submit = this._curSubmit = SubmitTexture.create(this, this._mesh, sv);
  8568. this._submits[this._submits._length++] = submit;
  8569. this._copyClipInfo(submit, this._globalClipMatrix);
  8570. submit.shaderValue.textureHost = texture;
  8571. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8572. this._curSubmit._numEle += 6;
  8573. this._mesh.indexNum += 6;
  8574. this._mesh.vertNum += 4;
  8575. }
  8576. this.breakNextMerge();
  8577. }
  8578. setColorFilter(filter) {
  8579. SaveBase.save(this, SaveBase.TYPE_COLORFILTER, this, true);
  8580. this._colorFiler = filter;
  8581. this._curSubmit = SubmitBase.RENDERBASE;
  8582. }
  8583. drawTexture(tex, x, y, width, height) {
  8584. this._drawTextureM(tex, x, y, width, height, null, 1, null);
  8585. }
  8586. drawTextures(tex, pos, tx, ty) {
  8587. if (!tex._getSource()) {
  8588. this.sprite && ILaya.systemTimer.callLater(this, this._repaintSprite);
  8589. return;
  8590. }
  8591. var n = pos.length / 2;
  8592. var ipos = 0;
  8593. var bmpid = tex.bitmap.id;
  8594. for (var i = 0; i < n; i++) {
  8595. this._inner_drawTexture(tex, bmpid, pos[ipos++] + tx, pos[ipos++] + ty, 0, 0, null, null, 1.0, false);
  8596. }
  8597. }
  8598. _drawTextureAddSubmit(imgid, tex) {
  8599. var submit = null;
  8600. submit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8601. this._submits[this._submits._length++] = submit;
  8602. submit.shaderValue.textureHost = tex;
  8603. submit._key.other = imgid;
  8604. submit._renderType = SubmitBase.TYPE_TEXTURE;
  8605. this._curSubmit = submit;
  8606. }
  8607. _drawTextureM(tex, x, y, width, height, m, alpha, uv) {
  8608. var cs = this.sprite;
  8609. if (!tex._getSource(function () {
  8610. if (cs) {
  8611. cs.repaint();
  8612. }
  8613. })) {
  8614. return false;
  8615. }
  8616. return this._inner_drawTexture(tex, tex.bitmap.id, x, y, width, height, m, uv, alpha, false);
  8617. }
  8618. _drawRenderTexture(tex, x, y, width, height, m, alpha, uv) {
  8619. return this._inner_drawTexture(tex, -1, x, y, width, height, m, uv, 1.0, false);
  8620. }
  8621. submitDebugger() {
  8622. this._submits[this._submits._length++] = SubmitCMD.create([], function () { debugger; }, this);
  8623. }
  8624. _copyClipInfo(submit, clipInfo) {
  8625. var cm = submit.shaderValue.clipMatDir;
  8626. cm[0] = clipInfo.a;
  8627. cm[1] = clipInfo.b;
  8628. cm[2] = clipInfo.c;
  8629. cm[3] = clipInfo.d;
  8630. var cmp = submit.shaderValue.clipMatPos;
  8631. cmp[0] = clipInfo.tx;
  8632. cmp[1] = clipInfo.ty;
  8633. submit.clipInfoID = this._clipInfoID;
  8634. if (this._clipInCache) {
  8635. submit.shaderValue.clipOff[0] = 1;
  8636. }
  8637. }
  8638. isSameClipInfo(submit) {
  8639. return (submit.clipInfoID === this._clipInfoID);
  8640. }
  8641. _useNewTex2DSubmit(tex, minVertNum) {
  8642. if (this._mesh.vertNum + minVertNum > Context._MAXVERTNUM) {
  8643. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8644. this.meshlist.push(this._mesh);
  8645. }
  8646. var submit = SubmitTexture.create(this, this._mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8647. this._submits[this._submits._length++] = this._curSubmit = submit;
  8648. submit.shaderValue.textureHost = tex;
  8649. this._copyClipInfo(submit, this._globalClipMatrix);
  8650. }
  8651. _drawTexRect(x, y, w, h, uv) {
  8652. this.transformQuad(x, y, w, h, this._italicDeg, this._curMat, this._transedPoints);
  8653. var ops = this._transedPoints;
  8654. ops[0] = (ops[0] + 0.5) | 0;
  8655. ops[1] = (ops[1] + 0.5) | 0;
  8656. ops[2] = (ops[2] + 0.5) | 0;
  8657. ops[3] = (ops[3] + 0.5) | 0;
  8658. ops[4] = (ops[4] + 0.5) | 0;
  8659. ops[5] = (ops[5] + 0.5) | 0;
  8660. ops[6] = (ops[6] + 0.5) | 0;
  8661. ops[7] = (ops[7] + 0.5) | 0;
  8662. if (!this.clipedOff(this._transedPoints)) {
  8663. this._mesh.addQuad(this._transedPoints, uv, this._fillColor, true);
  8664. this._curSubmit._numEle += 6;
  8665. this._mesh.indexNum += 6;
  8666. this._mesh.vertNum += 4;
  8667. }
  8668. }
  8669. drawCallOptimize(enbale) {
  8670. this._charSubmitCache.enable(enbale, this);
  8671. return enbale;
  8672. }
  8673. _inner_drawTexture(tex, imgid, x, y, width, height, m, uv, alpha, lastRender) {
  8674. var preKey = this._curSubmit._key;
  8675. uv = uv || tex._uv;
  8676. if (preKey.submitType === SubmitBase.KEY_TRIANGLES && preKey.other === imgid) {
  8677. var tv = this._drawTexToDrawTri_Vert;
  8678. tv[0] = x;
  8679. tv[1] = y;
  8680. tv[2] = x + width, tv[3] = y, tv[4] = x + width, tv[5] = y + height, tv[6] = x, tv[7] = y + height;
  8681. this._drawTriUseAbsMatrix = true;
  8682. var tuv = this._tempUV;
  8683. tuv[0] = uv[0];
  8684. tuv[1] = uv[1];
  8685. tuv[2] = uv[2];
  8686. tuv[3] = uv[3];
  8687. tuv[4] = uv[4];
  8688. tuv[5] = uv[5];
  8689. tuv[6] = uv[6];
  8690. tuv[7] = uv[7];
  8691. this.drawTriangles(tex, 0, 0, tv, tuv, this._drawTexToDrawTri_Index, m, alpha, null, null);
  8692. this._drawTriUseAbsMatrix = false;
  8693. return true;
  8694. }
  8695. var mesh = this._mesh;
  8696. var submit = this._curSubmit;
  8697. var ops = lastRender ? this._charSubmitCache.getPos() : this._transedPoints;
  8698. this.transformQuad(x, y, width || tex.width, height || tex.height, this._italicDeg, m || this._curMat, ops);
  8699. if (this.drawTexAlign) {
  8700. var round = Math.round;
  8701. ops[0] = round(ops[0]);
  8702. ops[1] = round(ops[1]);
  8703. ops[2] = round(ops[2]);
  8704. ops[3] = round(ops[3]);
  8705. ops[4] = round(ops[4]);
  8706. ops[5] = round(ops[5]);
  8707. ops[6] = round(ops[6]);
  8708. ops[7] = round(ops[7]);
  8709. this.drawTexAlign = false;
  8710. }
  8711. var rgba = this._mixRGBandAlpha(0xffffffff, this._shader2D.ALPHA * alpha);
  8712. if (lastRender) {
  8713. this._charSubmitCache.add(this, tex, imgid, ops, uv, rgba);
  8714. return true;
  8715. }
  8716. this._drawCount++;
  8717. var sameKey = imgid >= 0 && preKey.submitType === SubmitBase.KEY_DRAWTEXTURE && preKey.other === imgid;
  8718. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  8719. this._lastTex = tex;
  8720. if (mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8721. mesh = this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8722. this.meshlist.push(mesh);
  8723. sameKey = false;
  8724. }
  8725. {
  8726. mesh.addQuad(ops, uv, rgba, true);
  8727. if (!sameKey) {
  8728. this._submits[this._submits._length++] = this._curSubmit = submit = SubmitTexture.create(this, mesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  8729. submit.shaderValue.textureHost = tex;
  8730. submit._key.other = imgid;
  8731. this._copyClipInfo(submit, this._globalClipMatrix);
  8732. }
  8733. submit._numEle += 6;
  8734. mesh.indexNum += 6;
  8735. mesh.vertNum += 4;
  8736. return true;
  8737. }
  8738. return false;
  8739. }
  8740. transform4Points(a, m, out) {
  8741. var tx = m.tx;
  8742. var ty = m.ty;
  8743. var ma = m.a;
  8744. var mb = m.b;
  8745. var mc = m.c;
  8746. var md = m.d;
  8747. var a0 = a[0];
  8748. var a1 = a[1];
  8749. var a2 = a[2];
  8750. var a3 = a[3];
  8751. var a4 = a[4];
  8752. var a5 = a[5];
  8753. var a6 = a[6];
  8754. var a7 = a[7];
  8755. if (m._bTransform) {
  8756. out[0] = a0 * ma + a1 * mc + tx;
  8757. out[1] = a0 * mb + a1 * md + ty;
  8758. out[2] = a2 * ma + a3 * mc + tx;
  8759. out[3] = a2 * mb + a3 * md + ty;
  8760. out[4] = a4 * ma + a5 * mc + tx;
  8761. out[5] = a4 * mb + a5 * md + ty;
  8762. out[6] = a6 * ma + a7 * mc + tx;
  8763. out[7] = a6 * mb + a7 * md + ty;
  8764. }
  8765. else {
  8766. out[0] = a0 + tx;
  8767. out[1] = a1 + ty;
  8768. out[2] = a2 + tx;
  8769. out[3] = a3 + ty;
  8770. out[4] = a4 + tx;
  8771. out[5] = a5 + ty;
  8772. out[6] = a6 + tx;
  8773. out[7] = a7 + ty;
  8774. }
  8775. }
  8776. clipedOff(pt) {
  8777. if (this._clipRect.width <= 0 || this._clipRect.height <= 0)
  8778. return true;
  8779. return false;
  8780. }
  8781. transformQuad(x, y, w, h, italicDeg, m, out) {
  8782. var xoff = 0;
  8783. if (italicDeg != 0) {
  8784. xoff = Math.tan(italicDeg * Math.PI / 180) * h;
  8785. }
  8786. var maxx = x + w;
  8787. var maxy = y + h;
  8788. var tx = m.tx;
  8789. var ty = m.ty;
  8790. var ma = m.a;
  8791. var mb = m.b;
  8792. var mc = m.c;
  8793. var md = m.d;
  8794. var a0 = x + xoff;
  8795. var a1 = y;
  8796. var a2 = maxx + xoff;
  8797. var a3 = y;
  8798. var a4 = maxx;
  8799. var a5 = maxy;
  8800. var a6 = x;
  8801. var a7 = maxy;
  8802. if (m._bTransform) {
  8803. out[0] = a0 * ma + a1 * mc + tx;
  8804. out[1] = a0 * mb + a1 * md + ty;
  8805. out[2] = a2 * ma + a3 * mc + tx;
  8806. out[3] = a2 * mb + a3 * md + ty;
  8807. out[4] = a4 * ma + a5 * mc + tx;
  8808. out[5] = a4 * mb + a5 * md + ty;
  8809. out[6] = a6 * ma + a7 * mc + tx;
  8810. out[7] = a6 * mb + a7 * md + ty;
  8811. }
  8812. else {
  8813. out[0] = a0 + tx;
  8814. out[1] = a1 + ty;
  8815. out[2] = a2 + tx;
  8816. out[3] = a3 + ty;
  8817. out[4] = a4 + tx;
  8818. out[5] = a5 + ty;
  8819. out[6] = a6 + tx;
  8820. out[7] = a7 + ty;
  8821. }
  8822. }
  8823. pushRT() {
  8824. this.addRenderObject(SubmitCMD.create(null, RenderTexture2D.pushRT, this));
  8825. }
  8826. popRT() {
  8827. this.addRenderObject(SubmitCMD.create(null, RenderTexture2D.popRT, this));
  8828. this.breakNextMerge();
  8829. }
  8830. useRT(rt) {
  8831. function _use(rt) {
  8832. if (!rt) {
  8833. throw 'error useRT';
  8834. }
  8835. else {
  8836. rt.start();
  8837. rt.clear(0, 0, 0, 0);
  8838. }
  8839. }
  8840. this.addRenderObject(SubmitCMD.create([rt], _use, this));
  8841. this.breakNextMerge();
  8842. }
  8843. RTRestore(rt) {
  8844. function _restore(rt) {
  8845. rt.restore();
  8846. }
  8847. this.addRenderObject(SubmitCMD.create([rt], _restore, this));
  8848. this.breakNextMerge();
  8849. }
  8850. breakNextMerge() {
  8851. this._curSubmit = SubmitBase.RENDERBASE;
  8852. }
  8853. _repaintSprite() {
  8854. this.sprite && this.sprite.repaint();
  8855. }
  8856. drawTextureWithTransform(tex, x, y, width, height, transform, tx, ty, alpha, blendMode, colorfilter = null, uv) {
  8857. var oldcomp = null;
  8858. var curMat = this._curMat;
  8859. if (blendMode) {
  8860. oldcomp = this.globalCompositeOperation;
  8861. this.globalCompositeOperation = blendMode;
  8862. }
  8863. var oldColorFilter = this._colorFiler;
  8864. if (colorfilter) {
  8865. this.setColorFilter(colorfilter);
  8866. }
  8867. if (!transform) {
  8868. this._drawTextureM(tex, x + tx, y + ty, width, height, curMat, alpha, uv);
  8869. if (blendMode) {
  8870. this.globalCompositeOperation = oldcomp;
  8871. }
  8872. if (colorfilter) {
  8873. this.setColorFilter(oldColorFilter);
  8874. }
  8875. return;
  8876. }
  8877. var tmpMat = this._tmpMatrix;
  8878. tmpMat.a = transform.a;
  8879. tmpMat.b = transform.b;
  8880. tmpMat.c = transform.c;
  8881. tmpMat.d = transform.d;
  8882. tmpMat.tx = transform.tx + tx;
  8883. tmpMat.ty = transform.ty + ty;
  8884. tmpMat._bTransform = transform._bTransform;
  8885. if (transform && curMat._bTransform) {
  8886. Matrix.mul(tmpMat, curMat, tmpMat);
  8887. transform = tmpMat;
  8888. transform._bTransform = true;
  8889. }
  8890. else {
  8891. tmpMat.tx += curMat.tx;
  8892. tmpMat.ty += curMat.ty;
  8893. transform = tmpMat;
  8894. }
  8895. this._drawTextureM(tex, x, y, width, height, transform, alpha, uv);
  8896. if (blendMode) {
  8897. this.globalCompositeOperation = oldcomp;
  8898. }
  8899. if (colorfilter) {
  8900. this.setColorFilter(oldColorFilter);
  8901. }
  8902. }
  8903. _flushToTarget(context, target) {
  8904. RenderState2D.worldScissorTest = false;
  8905. var gl = LayaGL.instance;
  8906. gl.disable(gl.SCISSOR_TEST);
  8907. var preAlpha = RenderState2D.worldAlpha;
  8908. var preMatrix4 = RenderState2D.worldMatrix4;
  8909. var preMatrix = RenderState2D.worldMatrix;
  8910. RenderState2D.worldMatrix = Matrix.EMPTY;
  8911. RenderState2D.restoreTempArray();
  8912. RenderState2D.worldMatrix4 = RenderState2D.TEMPMAT4_ARRAY;
  8913. RenderState2D.worldAlpha = 1;
  8914. BaseShader.activeShader = null;
  8915. target.start();
  8916. if (context._submits._length > 0)
  8917. target.clear(0, 0, 0, 0);
  8918. context._curSubmit = SubmitBase.RENDERBASE;
  8919. context.flush();
  8920. context.clear();
  8921. target.restore();
  8922. context._curSubmit = SubmitBase.RENDERBASE;
  8923. BaseShader.activeShader = null;
  8924. RenderState2D.worldAlpha = preAlpha;
  8925. RenderState2D.worldMatrix4 = preMatrix4;
  8926. RenderState2D.worldMatrix = preMatrix;
  8927. }
  8928. drawCanvas(canvas, x, y, width, height) {
  8929. if (!canvas)
  8930. return;
  8931. var src = canvas.context;
  8932. var submit;
  8933. if (src._targets) {
  8934. if (src._submits._length > 0) {
  8935. submit = SubmitCMD.create([src, src._targets], this._flushToTarget, this);
  8936. this._submits[this._submits._length++] = submit;
  8937. }
  8938. this._drawRenderTexture(src._targets, x, y, width, height, null, 1.0, RenderTexture2D.flipyuv);
  8939. this._curSubmit = SubmitBase.RENDERBASE;
  8940. }
  8941. else {
  8942. var canv = canvas;
  8943. if (canv.touches) {
  8944. canv.touches.forEach(function (v) { v.touch(); });
  8945. }
  8946. submit = SubmitCanvas.create(canvas, this._shader2D.ALPHA, this._shader2D.filters);
  8947. this._submits[this._submits._length++] = submit;
  8948. submit._key.clear();
  8949. var mat = submit._matrix;
  8950. this._curMat.copyTo(mat);
  8951. var tx = mat.tx, ty = mat.ty;
  8952. mat.tx = mat.ty = 0;
  8953. mat.transformPoint(Point.TEMP.setTo(x, y));
  8954. mat.translate(Point.TEMP.x + tx, Point.TEMP.y + ty);
  8955. Matrix.mul(canv.invMat, mat, mat);
  8956. this._curSubmit = SubmitBase.RENDERBASE;
  8957. }
  8958. }
  8959. drawTarget(rt, x, y, width, height, m, shaderValue, uv = null, blend = -1) {
  8960. this._drawCount++;
  8961. if (this._mesh.vertNum + 4 > Context._MAXVERTNUM) {
  8962. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  8963. this.meshlist.push(this._mesh);
  8964. }
  8965. this.transformQuad(x, y, width, height, 0, m || this._curMat, this._transedPoints);
  8966. if (!this.clipedOff(this._transedPoints)) {
  8967. this._mesh.addQuad(this._transedPoints, uv || Texture.DEF_UV, 0xffffffff, true);
  8968. var submit = this._curSubmit = SubmitTarget.create(this, this._mesh, shaderValue, rt);
  8969. submit.blendType = (blend == -1) ? this._nBlendType : blend;
  8970. this._copyClipInfo(submit, this._globalClipMatrix);
  8971. submit._numEle = 6;
  8972. this._mesh.indexNum += 6;
  8973. this._mesh.vertNum += 4;
  8974. this._submits[this._submits._length++] = submit;
  8975. this._curSubmit = SubmitBase.RENDERBASE;
  8976. return true;
  8977. }
  8978. this._curSubmit = SubmitBase.RENDERBASE;
  8979. return false;
  8980. }
  8981. drawTriangles(tex, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode) {
  8982. if (!tex._getSource()) {
  8983. if (this.sprite) {
  8984. ILaya.systemTimer.callLater(this, this._repaintSprite);
  8985. }
  8986. return;
  8987. }
  8988. this._drawCount++;
  8989. var tmpMat = this._tmpMatrix;
  8990. var triMesh = this._triangleMesh;
  8991. var oldColorFilter = null;
  8992. var needRestorFilter = false;
  8993. if (color) {
  8994. oldColorFilter = this._colorFiler;
  8995. this._colorFiler = color;
  8996. this._curSubmit = SubmitBase.RENDERBASE;
  8997. needRestorFilter = oldColorFilter != color;
  8998. }
  8999. var webGLImg = tex.bitmap;
  9000. var preKey = this._curSubmit._key;
  9001. var sameKey = preKey.submitType === SubmitBase.KEY_TRIANGLES && preKey.other === webGLImg.id && preKey.blendShader == this._nBlendType;
  9002. if (triMesh.vertNum + vertices.length / 2 > Context._MAXVERTNUM) {
  9003. triMesh = this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  9004. this.meshlist.push(triMesh);
  9005. sameKey = false;
  9006. }
  9007. if (!sameKey) {
  9008. var submit = this._curSubmit = SubmitTexture.create(this, triMesh, Value2D.create(ShaderDefines2D.TEXTURE2D, 0));
  9009. submit.shaderValue.textureHost = tex;
  9010. submit._renderType = SubmitBase.TYPE_TEXTURE;
  9011. submit._key.submitType = SubmitBase.KEY_TRIANGLES;
  9012. submit._key.other = webGLImg.id;
  9013. this._copyClipInfo(submit, this._globalClipMatrix);
  9014. this._submits[this._submits._length++] = submit;
  9015. }
  9016. var rgba = this._mixRGBandAlpha(0xffffffff, this._shader2D.ALPHA * alpha);
  9017. if (!this._drawTriUseAbsMatrix) {
  9018. if (!matrix) {
  9019. tmpMat.a = 1;
  9020. tmpMat.b = 0;
  9021. tmpMat.c = 0;
  9022. tmpMat.d = 1;
  9023. tmpMat.tx = x;
  9024. tmpMat.ty = y;
  9025. }
  9026. else {
  9027. tmpMat.a = matrix.a;
  9028. tmpMat.b = matrix.b;
  9029. tmpMat.c = matrix.c;
  9030. tmpMat.d = matrix.d;
  9031. tmpMat.tx = matrix.tx + x;
  9032. tmpMat.ty = matrix.ty + y;
  9033. }
  9034. Matrix.mul(tmpMat, this._curMat, tmpMat);
  9035. triMesh.addData(vertices, uvs, indices, tmpMat, rgba);
  9036. }
  9037. else {
  9038. triMesh.addData(vertices, uvs, indices, matrix, rgba);
  9039. }
  9040. this._curSubmit._numEle += indices.length;
  9041. if (needRestorFilter) {
  9042. this._colorFiler = oldColorFilter;
  9043. this._curSubmit = SubmitBase.RENDERBASE;
  9044. }
  9045. }
  9046. transform(a, b, c, d, tx, ty) {
  9047. SaveTransform.save(this);
  9048. Matrix.mul(Matrix.TEMP.setTo(a, b, c, d, tx, ty), this._curMat, this._curMat);
  9049. this._curMat._checkTransform();
  9050. }
  9051. _transformByMatrix(matrix, tx, ty) {
  9052. matrix.setTranslate(tx, ty);
  9053. Matrix.mul(matrix, this._curMat, this._curMat);
  9054. matrix.setTranslate(0, 0);
  9055. this._curMat._bTransform = true;
  9056. }
  9057. setTransformByMatrix(value) {
  9058. value.copyTo(this._curMat);
  9059. }
  9060. rotate(angle) {
  9061. SaveTransform.save(this);
  9062. this._curMat.rotateEx(angle);
  9063. }
  9064. scale(scaleX, scaleY) {
  9065. SaveTransform.save(this);
  9066. this._curMat.scaleEx(scaleX, scaleY);
  9067. }
  9068. clipRect(x, y, width, height) {
  9069. SaveClipRect.save(this);
  9070. if (this._clipRect == Context.MAXCLIPRECT) {
  9071. this._clipRect = new Rectangle(x, y, width, height);
  9072. }
  9073. else {
  9074. this._clipRect.width = width;
  9075. this._clipRect.height = height;
  9076. this._clipRect.x = x;
  9077. this._clipRect.y = y;
  9078. }
  9079. this._clipID_Gen++;
  9080. this._clipID_Gen %= 10000;
  9081. this._clipInfoID = this._clipID_Gen;
  9082. var cm = this._globalClipMatrix;
  9083. var minx = cm.tx;
  9084. var miny = cm.ty;
  9085. var maxx = minx + cm.a;
  9086. var maxy = miny + cm.d;
  9087. if (this._clipRect.width >= Context._MAXSIZE) {
  9088. cm.a = cm.d = Context._MAXSIZE;
  9089. cm.b = cm.c = cm.tx = cm.ty = 0;
  9090. }
  9091. else {
  9092. if (this._curMat._bTransform) {
  9093. cm.tx = this._clipRect.x * this._curMat.a + this._clipRect.y * this._curMat.c + this._curMat.tx;
  9094. cm.ty = this._clipRect.x * this._curMat.b + this._clipRect.y * this._curMat.d + this._curMat.ty;
  9095. cm.a = this._clipRect.width * this._curMat.a;
  9096. cm.b = this._clipRect.width * this._curMat.b;
  9097. cm.c = this._clipRect.height * this._curMat.c;
  9098. cm.d = this._clipRect.height * this._curMat.d;
  9099. }
  9100. else {
  9101. cm.tx = this._clipRect.x + this._curMat.tx;
  9102. cm.ty = this._clipRect.y + this._curMat.ty;
  9103. cm.a = this._clipRect.width;
  9104. cm.b = cm.c = 0;
  9105. cm.d = this._clipRect.height;
  9106. }
  9107. if (this._incache) {
  9108. this._clipInCache = true;
  9109. }
  9110. }
  9111. if (cm.a > 0 && cm.d > 0) {
  9112. var cmaxx = cm.tx + cm.a;
  9113. var cmaxy = cm.ty + cm.d;
  9114. if (cmaxx <= minx || cmaxy <= miny || cm.tx >= maxx || cm.ty >= maxy) {
  9115. cm.a = -0.1;
  9116. cm.d = -0.1;
  9117. }
  9118. else {
  9119. if (cm.tx < minx) {
  9120. cm.a -= (minx - cm.tx);
  9121. cm.tx = minx;
  9122. }
  9123. if (cmaxx > maxx) {
  9124. cm.a -= (cmaxx - maxx);
  9125. }
  9126. if (cm.ty < miny) {
  9127. cm.d -= (miny - cm.ty);
  9128. cm.ty = miny;
  9129. }
  9130. if (cmaxy > maxy) {
  9131. cm.d -= (cmaxy - maxy);
  9132. }
  9133. if (cm.a <= 0)
  9134. cm.a = -0.1;
  9135. if (cm.d <= 0)
  9136. cm.d = -0.1;
  9137. }
  9138. }
  9139. }
  9140. drawMesh(x, y, ib, vb, numElement, mat, shader, shaderValues, startIndex = 0) {
  9141. }
  9142. addRenderObject(o) {
  9143. this._submits[this._submits._length++] = o;
  9144. }
  9145. submitElement(start, end) {
  9146. var mainCtx = this.isMain;
  9147. var renderList = this._submits;
  9148. var ret = renderList._length;
  9149. end < 0 && (end = renderList._length);
  9150. var submit = SubmitBase.RENDERBASE;
  9151. while (start < end) {
  9152. this._renderNextSubmitIndex = start + 1;
  9153. if (renderList[start] === SubmitBase.RENDERBASE) {
  9154. start++;
  9155. continue;
  9156. }
  9157. SubmitBase.preRender = submit;
  9158. submit = renderList[start];
  9159. start += submit.renderSubmit();
  9160. }
  9161. return ret;
  9162. }
  9163. flush() {
  9164. this._clipID_Gen = 0;
  9165. var ret = this.submitElement(0, this._submits._length);
  9166. this._path && this._path.reset();
  9167. SkinMeshBuffer.instance && SkinMeshBuffer.getInstance().reset();
  9168. this._curSubmit = SubmitBase.RENDERBASE;
  9169. for (var i = 0, sz = this.meshlist.length; i < sz; i++) {
  9170. var curm = this.meshlist[i];
  9171. curm.canReuse ? (curm.releaseMesh()) : (curm.destroy());
  9172. }
  9173. this.meshlist.length = 0;
  9174. this._mesh = MeshQuadTexture.getAMesh(this.isMain);
  9175. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9176. this._triangleMesh = MeshTexture.getAMesh(this.isMain);
  9177. this.meshlist.push(this._mesh, this._pathMesh, this._triangleMesh);
  9178. this._flushCnt++;
  9179. if (this._flushCnt % 60 == 0 && this.isMain) {
  9180. if (TextRender.textRenderInst) {
  9181. TextRender.textRenderInst.GC();
  9182. }
  9183. }
  9184. return ret;
  9185. }
  9186. beginPath(convex = false) {
  9187. var tPath = this._getPath();
  9188. tPath.beginPath(convex);
  9189. }
  9190. closePath() {
  9191. this._path.closePath();
  9192. }
  9193. addPath(points, close, convex, dx, dy) {
  9194. var ci = 0;
  9195. for (var i = 0, sz = points.length / 2; i < sz; i++) {
  9196. var x1 = points[ci] + dx, y1 = points[ci + 1] + dy;
  9197. points[ci] = x1;
  9198. points[ci + 1] = y1;
  9199. ci += 2;
  9200. }
  9201. this._getPath().push(points, convex);
  9202. }
  9203. fill() {
  9204. var m = this._curMat;
  9205. var tPath = this._getPath();
  9206. var submit = this._curSubmit;
  9207. var sameKey = (submit._key.submitType === SubmitBase.KEY_VG && submit._key.blendShader === this._nBlendType);
  9208. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  9209. if (!sameKey) {
  9210. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9211. }
  9212. var rgba = this.mixRGBandAlpha(this.fillStyle.toInt());
  9213. var curEleNum = 0;
  9214. var idx;
  9215. for (var i = 0, sz = tPath.paths.length; i < sz; i++) {
  9216. var p = tPath.paths[i];
  9217. var vertNum = p.path.length / 2;
  9218. if (vertNum < 3 || (vertNum == 3 && !p.convex))
  9219. continue;
  9220. var cpath = p.path.concat();
  9221. var pi = 0;
  9222. var xp, yp;
  9223. var _x, _y;
  9224. if (m._bTransform) {
  9225. for (pi = 0; pi < vertNum; pi++) {
  9226. xp = pi << 1;
  9227. yp = xp + 1;
  9228. _x = cpath[xp];
  9229. _y = cpath[yp];
  9230. cpath[xp] = m.a * _x + m.c * _y + m.tx;
  9231. cpath[yp] = m.b * _x + m.d * _y + m.ty;
  9232. }
  9233. }
  9234. else {
  9235. for (pi = 0; pi < vertNum; pi++) {
  9236. xp = pi << 1;
  9237. yp = xp + 1;
  9238. _x = cpath[xp];
  9239. _y = cpath[yp];
  9240. cpath[xp] = _x + m.tx;
  9241. cpath[yp] = _y + m.ty;
  9242. }
  9243. }
  9244. if (this._pathMesh.vertNum + vertNum > Context._MAXVERTNUM) {
  9245. this._curSubmit._numEle += curEleNum;
  9246. curEleNum = 0;
  9247. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9248. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9249. }
  9250. var curvert = this._pathMesh.vertNum;
  9251. if (p.convex) {
  9252. var faceNum = vertNum - 2;
  9253. idx = new Array(faceNum * 3);
  9254. var idxpos = 0;
  9255. for (var fi = 0; fi < faceNum; fi++) {
  9256. idx[idxpos++] = curvert;
  9257. idx[idxpos++] = fi + 1 + curvert;
  9258. idx[idxpos++] = fi + 2 + curvert;
  9259. }
  9260. }
  9261. else {
  9262. idx = Earcut.earcut(cpath, null, 2);
  9263. if (curvert > 0) {
  9264. for (var ii = 0; ii < idx.length; ii++) {
  9265. idx[ii] += curvert;
  9266. }
  9267. }
  9268. }
  9269. this._pathMesh.addVertAndIBToMesh(this, cpath, rgba, idx);
  9270. curEleNum += idx.length;
  9271. }
  9272. this._curSubmit._numEle += curEleNum;
  9273. }
  9274. addVGSubmit(mesh) {
  9275. var submit = Submit.createShape(this, mesh, 0, Value2D.create(ShaderDefines2D.PRIMITIVE, 0));
  9276. submit._key.submitType = SubmitBase.KEY_VG;
  9277. this._submits[this._submits._length++] = submit;
  9278. this._copyClipInfo(submit, this._globalClipMatrix);
  9279. return submit;
  9280. }
  9281. stroke() {
  9282. if (this.lineWidth > 0) {
  9283. var rgba = this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  9284. var tPath = this._getPath();
  9285. var submit = this._curSubmit;
  9286. var sameKey = (submit._key.submitType === SubmitBase.KEY_VG && submit._key.blendShader === this._nBlendType);
  9287. sameKey && (sameKey = sameKey && this.isSameClipInfo(submit));
  9288. if (!sameKey) {
  9289. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9290. }
  9291. var curEleNum = 0;
  9292. for (var i = 0, sz = tPath.paths.length; i < sz; i++) {
  9293. var p = tPath.paths[i];
  9294. if (p.path.length <= 0)
  9295. continue;
  9296. var idx = [];
  9297. var vertex = [];
  9298. var maxVertexNum = p.path.length * 2;
  9299. if (maxVertexNum < 2)
  9300. continue;
  9301. if (this._pathMesh.vertNum + maxVertexNum > Context._MAXVERTNUM) {
  9302. this._curSubmit._numEle += curEleNum;
  9303. curEleNum = 0;
  9304. this._pathMesh = MeshVG.getAMesh(this.isMain);
  9305. this.meshlist.push(this._pathMesh);
  9306. this._curSubmit = this.addVGSubmit(this._pathMesh);
  9307. }
  9308. BasePoly.createLine2(p.path, idx, this.lineWidth, this._pathMesh.vertNum, vertex, p.loop);
  9309. var ptnum = vertex.length / 2;
  9310. var m = this._curMat;
  9311. var pi = 0;
  9312. var xp, yp;
  9313. var _x, _y;
  9314. if (m._bTransform) {
  9315. for (pi = 0; pi < ptnum; pi++) {
  9316. xp = pi << 1;
  9317. yp = xp + 1;
  9318. _x = vertex[xp];
  9319. _y = vertex[yp];
  9320. vertex[xp] = m.a * _x + m.c * _y + m.tx;
  9321. vertex[yp] = m.b * _x + m.d * _y + m.ty;
  9322. }
  9323. }
  9324. else {
  9325. for (pi = 0; pi < ptnum; pi++) {
  9326. xp = pi << 1;
  9327. yp = xp + 1;
  9328. _x = vertex[xp];
  9329. _y = vertex[yp];
  9330. vertex[xp] = _x + m.tx;
  9331. vertex[yp] = _y + m.ty;
  9332. }
  9333. }
  9334. this._pathMesh.addVertAndIBToMesh(this, vertex, rgba, idx);
  9335. curEleNum += idx.length;
  9336. }
  9337. this._curSubmit._numEle += curEleNum;
  9338. }
  9339. }
  9340. moveTo(x, y) {
  9341. var tPath = this._getPath();
  9342. tPath.newPath();
  9343. tPath._lastOriX = x;
  9344. tPath._lastOriY = y;
  9345. tPath.addPoint(x, y);
  9346. }
  9347. lineTo(x, y) {
  9348. var tPath = this._getPath();
  9349. if (Math.abs(x - tPath._lastOriX) < 1e-3 && Math.abs(y - tPath._lastOriY) < 1e-3)
  9350. return;
  9351. tPath._lastOriX = x;
  9352. tPath._lastOriY = y;
  9353. tPath.addPoint(x, y);
  9354. }
  9355. arcTo(x1, y1, x2, y2, r) {
  9356. var i = 0;
  9357. var x = 0, y = 0;
  9358. var dx = this._path._lastOriX - x1;
  9359. var dy = this._path._lastOriY - y1;
  9360. var len1 = Math.sqrt(dx * dx + dy * dy);
  9361. if (len1 <= 0.000001) {
  9362. return;
  9363. }
  9364. var ndx = dx / len1;
  9365. var ndy = dy / len1;
  9366. var dx2 = x2 - x1;
  9367. var dy2 = y2 - y1;
  9368. var len22 = dx2 * dx2 + dy2 * dy2;
  9369. var len2 = Math.sqrt(len22);
  9370. if (len2 <= 0.000001) {
  9371. return;
  9372. }
  9373. var ndx2 = dx2 / len2;
  9374. var ndy2 = dy2 / len2;
  9375. var odx = ndx + ndx2;
  9376. var ody = ndy + ndy2;
  9377. var olen = Math.sqrt(odx * odx + ody * ody);
  9378. if (olen <= 0.000001) {
  9379. return;
  9380. }
  9381. var nOdx = odx / olen;
  9382. var nOdy = ody / olen;
  9383. var alpha = Math.acos(nOdx * ndx + nOdy * ndy);
  9384. var halfAng = Math.PI / 2 - alpha;
  9385. len1 = r / Math.tan(halfAng);
  9386. var ptx1 = len1 * ndx + x1;
  9387. var pty1 = len1 * ndy + y1;
  9388. var orilen = Math.sqrt(len1 * len1 + r * r);
  9389. var orix = x1 + nOdx * orilen;
  9390. var oriy = y1 + nOdy * orilen;
  9391. var dir = ndx * ndy2 - ndy * ndx2;
  9392. var fChgAng = 0;
  9393. var sinx = 0.0;
  9394. var cosx = 0.0;
  9395. if (dir >= 0) {
  9396. fChgAng = halfAng * 2;
  9397. var fda = fChgAng / Context.SEGNUM;
  9398. sinx = Math.sin(fda);
  9399. cosx = Math.cos(fda);
  9400. }
  9401. else {
  9402. fChgAng = -halfAng * 2;
  9403. fda = fChgAng / Context.SEGNUM;
  9404. sinx = Math.sin(fda);
  9405. cosx = Math.cos(fda);
  9406. }
  9407. var lastx = this._path._lastOriX, lasty = this._path._lastOriY;
  9408. var _x1 = ptx1, _y1 = pty1;
  9409. if (Math.abs(_x1 - this._path._lastOriX) > 0.1 || Math.abs(_y1 - this._path._lastOriY) > 0.1) {
  9410. x = _x1;
  9411. y = _y1;
  9412. lastx = _x1;
  9413. lasty = _y1;
  9414. this._path.addPoint(x, y);
  9415. }
  9416. var cvx = ptx1 - orix;
  9417. var cvy = pty1 - oriy;
  9418. for (i = 0; i < Context.SEGNUM; i++) {
  9419. var cx = cvx * cosx + cvy * sinx;
  9420. var cy = -cvx * sinx + cvy * cosx;
  9421. x = cx + orix;
  9422. y = cy + oriy;
  9423. if (Math.abs(lastx - x) > 0.1 || Math.abs(lasty - y) > 0.1) {
  9424. this._path.addPoint(x, y);
  9425. lastx = x;
  9426. lasty = y;
  9427. }
  9428. cvx = cx;
  9429. cvy = cy;
  9430. }
  9431. }
  9432. arc(cx, cy, r, startAngle, endAngle, counterclockwise = false, b = true) {
  9433. var a = 0, da = 0;
  9434. var dx = 0, dy = 0, x = 0, y = 0;
  9435. var i, ndivs;
  9436. da = endAngle - startAngle;
  9437. if (!counterclockwise) {
  9438. if (Math.abs(da) >= Math.PI * 2) {
  9439. da = Math.PI * 2;
  9440. }
  9441. else {
  9442. while (da < 0.0) {
  9443. da += Math.PI * 2;
  9444. }
  9445. }
  9446. }
  9447. else {
  9448. if (Math.abs(da) >= Math.PI * 2) {
  9449. da = -Math.PI * 2;
  9450. }
  9451. else {
  9452. while (da > 0.0) {
  9453. da -= Math.PI * 2;
  9454. }
  9455. }
  9456. }
  9457. var sx = this.getMatScaleX();
  9458. var sy = this.getMatScaleY();
  9459. var sr = r * (sx > sy ? sx : sy);
  9460. var cl = 2 * Math.PI * sr;
  9461. ndivs = (Math.max(cl / 10, 10)) | 0;
  9462. var tPath = this._getPath();
  9463. for (i = 0; i <= ndivs; i++) {
  9464. a = startAngle + da * (i / ndivs);
  9465. dx = Math.cos(a);
  9466. dy = Math.sin(a);
  9467. x = cx + dx * r;
  9468. y = cy + dy * r;
  9469. if (x != this._path._lastOriX || y != this._path._lastOriY) {
  9470. tPath.addPoint(x, y);
  9471. }
  9472. }
  9473. dx = Math.cos(endAngle);
  9474. dy = Math.sin(endAngle);
  9475. x = cx + dx * r;
  9476. y = cy + dy * r;
  9477. if (x != this._path._lastOriX || y != this._path._lastOriY) {
  9478. tPath.addPoint(x, y);
  9479. }
  9480. }
  9481. quadraticCurveTo(cpx, cpy, x, y) {
  9482. var tBezier = Bezier.I;
  9483. var tArray = tBezier.getBezierPoints([this._path._lastOriX, this._path._lastOriY, cpx, cpy, x, y], 30, 2);
  9484. for (var i = 0, n = tArray.length / 2; i < n; i++) {
  9485. this.lineTo(tArray[i * 2], tArray[i * 2 + 1]);
  9486. }
  9487. this.lineTo(x, y);
  9488. }
  9489. mixRGBandAlpha(color) {
  9490. return this._mixRGBandAlpha(color, this._shader2D.ALPHA);
  9491. }
  9492. _mixRGBandAlpha(color, alpha) {
  9493. if (alpha >= 1) {
  9494. return color;
  9495. }
  9496. var a = ((color & 0xff000000) >>> 24);
  9497. if (a != 0) {
  9498. a *= alpha;
  9499. }
  9500. else {
  9501. a = alpha * 255;
  9502. }
  9503. return (color & 0x00ffffff) | (a << 24);
  9504. }
  9505. strokeRect(x, y, width, height, parameterLineWidth) {
  9506. if (this.lineWidth > 0) {
  9507. var rgba = this.mixRGBandAlpha(this.strokeStyle._color.numColor);
  9508. var hw = this.lineWidth / 2;
  9509. this._fillRect(x - hw, y - hw, width + this.lineWidth, this.lineWidth, rgba);
  9510. this._fillRect(x - hw, y - hw + height, width + this.lineWidth, this.lineWidth, rgba);
  9511. this._fillRect(x - hw, y + hw, this.lineWidth, height - this.lineWidth, rgba);
  9512. this._fillRect(x - hw + width, y + hw, this.lineWidth, height - this.lineWidth, rgba);
  9513. }
  9514. }
  9515. clip() {
  9516. }
  9517. drawParticle(x, y, pt) {
  9518. pt.x = x;
  9519. pt.y = y;
  9520. this._submits[this._submits._length++] = pt;
  9521. }
  9522. _getPath() {
  9523. return this._path || (this._path = new Path());
  9524. }
  9525. get canvas() {
  9526. return this._canvas;
  9527. }
  9528. _fillTexture_h(tex, imgid, uv, oriw, orih, x, y, w) {
  9529. var stx = x;
  9530. var num = Math.floor(w / oriw);
  9531. var left = w % oriw;
  9532. for (var i = 0; i < num; i++) {
  9533. this._inner_drawTexture(tex, imgid, stx, y, oriw, orih, this._curMat, uv, 1, false);
  9534. stx += oriw;
  9535. }
  9536. if (left > 0) {
  9537. var du = uv[2] - uv[0];
  9538. var uvr = uv[0] + du * (left / oriw);
  9539. var tuv = Context.tmpuv1;
  9540. tuv[0] = uv[0];
  9541. tuv[1] = uv[1];
  9542. tuv[2] = uvr;
  9543. tuv[3] = uv[3];
  9544. tuv[4] = uvr;
  9545. tuv[5] = uv[5];
  9546. tuv[6] = uv[6];
  9547. tuv[7] = uv[7];
  9548. this._inner_drawTexture(tex, imgid, stx, y, left, orih, this._curMat, tuv, 1, false);
  9549. }
  9550. }
  9551. _fillTexture_v(tex, imgid, uv, oriw, orih, x, y, h) {
  9552. var sty = y;
  9553. var num = Math.floor(h / orih);
  9554. var left = h % orih;
  9555. for (var i = 0; i < num; i++) {
  9556. this._inner_drawTexture(tex, imgid, x, sty, oriw, orih, this._curMat, uv, 1, false);
  9557. sty += orih;
  9558. }
  9559. if (left > 0) {
  9560. var dv = uv[7] - uv[1];
  9561. var uvb = uv[1] + dv * (left / orih);
  9562. var tuv = Context.tmpuv1;
  9563. tuv[0] = uv[0];
  9564. tuv[1] = uv[1];
  9565. tuv[2] = uv[2];
  9566. tuv[3] = uv[3];
  9567. tuv[4] = uv[4];
  9568. tuv[5] = uvb;
  9569. tuv[6] = uv[6];
  9570. tuv[7] = uvb;
  9571. this._inner_drawTexture(tex, imgid, x, sty, oriw, left, this._curMat, tuv, 1, false);
  9572. }
  9573. }
  9574. drawTextureWithSizeGrid(tex, tx, ty, width, height, sizeGrid, gx, gy) {
  9575. if (!tex._getSource())
  9576. return;
  9577. tx += gx;
  9578. ty += gy;
  9579. var uv = tex.uv, w = tex.bitmap.width, h = tex.bitmap.height;
  9580. var top = sizeGrid[0];
  9581. var left = sizeGrid[3];
  9582. var d_top = top / h;
  9583. var d_left = left / w;
  9584. var right = sizeGrid[1];
  9585. var bottom = sizeGrid[2];
  9586. var d_right = right / w;
  9587. var d_bottom = bottom / h;
  9588. var repeat = sizeGrid[4];
  9589. var needClip = false;
  9590. if (width == w) {
  9591. left = right = 0;
  9592. }
  9593. if (height == h) {
  9594. top = bottom = 0;
  9595. }
  9596. if (left + right > width) {
  9597. var clipWidth = width;
  9598. needClip = true;
  9599. width = left + right;
  9600. this.save();
  9601. this.clipRect(0 + tx, 0 + ty, clipWidth, height);
  9602. }
  9603. var imgid = tex.bitmap.id;
  9604. var mat = this._curMat;
  9605. var tuv = this._tempUV;
  9606. var uvl = uv[0];
  9607. var uvt = uv[1];
  9608. var uvr = uv[4];
  9609. var uvb = uv[5];
  9610. var uvl_ = uvl;
  9611. var uvt_ = uvt;
  9612. var uvr_ = uvr;
  9613. var uvb_ = uvb;
  9614. if (left && top) {
  9615. uvr_ = uvl + d_left;
  9616. uvb_ = uvt + d_top;
  9617. tuv[0] = uvl, tuv[1] = uvt, tuv[2] = uvr_, tuv[3] = uvt,
  9618. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl, tuv[7] = uvb_;
  9619. this._inner_drawTexture(tex, imgid, tx, ty, left, top, mat, tuv, 1, false);
  9620. }
  9621. if (right && top) {
  9622. uvl_ = uvr - d_right;
  9623. uvt_ = uvt;
  9624. uvr_ = uvr;
  9625. uvb_ = uvt + d_top;
  9626. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9627. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9628. this._inner_drawTexture(tex, imgid, width - right + tx, 0 + ty, right, top, mat, tuv, 1, false);
  9629. }
  9630. if (left && bottom) {
  9631. uvl_ = uvl;
  9632. uvt_ = uvb - d_bottom;
  9633. uvr_ = uvl + d_left;
  9634. uvb_ = uvb;
  9635. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9636. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9637. this._inner_drawTexture(tex, imgid, 0 + tx, height - bottom + ty, left, bottom, mat, tuv, 1, false);
  9638. }
  9639. if (right && bottom) {
  9640. uvl_ = uvr - d_right;
  9641. uvt_ = uvb - d_bottom;
  9642. uvr_ = uvr;
  9643. uvb_ = uvb;
  9644. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9645. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9646. this._inner_drawTexture(tex, imgid, width - right + tx, height - bottom + ty, right, bottom, mat, tuv, 1, false);
  9647. }
  9648. if (top) {
  9649. uvl_ = uvl + d_left;
  9650. uvt_ = uvt;
  9651. uvr_ = uvr - d_right;
  9652. uvb_ = uvt + d_top;
  9653. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9654. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9655. if (repeat) {
  9656. this._fillTexture_h(tex, imgid, tuv, tex.width - left - right, top, left + tx, ty, width - left - right);
  9657. }
  9658. else {
  9659. this._inner_drawTexture(tex, imgid, left + tx, ty, width - left - right, top, mat, tuv, 1, false);
  9660. }
  9661. }
  9662. if (bottom) {
  9663. uvl_ = uvl + d_left;
  9664. uvt_ = uvb - d_bottom;
  9665. uvr_ = uvr - d_right;
  9666. uvb_ = uvb;
  9667. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9668. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9669. if (repeat) {
  9670. this._fillTexture_h(tex, imgid, tuv, tex.width - left - right, bottom, left + tx, height - bottom + ty, width - left - right);
  9671. }
  9672. else {
  9673. this._inner_drawTexture(tex, imgid, left + tx, height - bottom + ty, width - left - right, bottom, mat, tuv, 1, false);
  9674. }
  9675. }
  9676. if (left) {
  9677. uvl_ = uvl;
  9678. uvt_ = uvt + d_top;
  9679. uvr_ = uvl + d_left;
  9680. uvb_ = uvb - d_bottom;
  9681. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9682. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9683. if (repeat) {
  9684. this._fillTexture_v(tex, imgid, tuv, left, tex.height - top - bottom, tx, top + ty, height - top - bottom);
  9685. }
  9686. else {
  9687. this._inner_drawTexture(tex, imgid, tx, top + ty, left, height - top - bottom, mat, tuv, 1, false);
  9688. }
  9689. }
  9690. if (right) {
  9691. uvl_ = uvr - d_right;
  9692. uvt_ = uvt + d_top;
  9693. uvr_ = uvr;
  9694. uvb_ = uvb - d_bottom;
  9695. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9696. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9697. if (repeat) {
  9698. this._fillTexture_v(tex, imgid, tuv, right, tex.height - top - bottom, width - right + tx, top + ty, height - top - bottom);
  9699. }
  9700. else {
  9701. this._inner_drawTexture(tex, imgid, width - right + tx, top + ty, right, height - top - bottom, mat, tuv, 1, false);
  9702. }
  9703. }
  9704. uvl_ = uvl + d_left;
  9705. uvt_ = uvt + d_top;
  9706. uvr_ = uvr - d_right;
  9707. uvb_ = uvb - d_bottom;
  9708. tuv[0] = uvl_, tuv[1] = uvt_, tuv[2] = uvr_, tuv[3] = uvt_,
  9709. tuv[4] = uvr_, tuv[5] = uvb_, tuv[6] = uvl_, tuv[7] = uvb_;
  9710. if (repeat) {
  9711. var tuvr = Context.tmpUVRect;
  9712. tuvr[0] = uvl_;
  9713. tuvr[1] = uvt_;
  9714. tuvr[2] = uvr_ - uvl_;
  9715. tuvr[3] = uvb_ - uvt_;
  9716. 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);
  9717. }
  9718. else {
  9719. this._inner_drawTexture(tex, imgid, left + tx, top + ty, width - left - right, height - top - bottom, mat, tuv, 1, false);
  9720. }
  9721. if (needClip)
  9722. this.restore();
  9723. }
  9724. }
  9725. Context.ENUM_TEXTALIGN_DEFAULT = 0;
  9726. Context.ENUM_TEXTALIGN_CENTER = 1;
  9727. Context.ENUM_TEXTALIGN_RIGHT = 2;
  9728. Context._SUBMITVBSIZE = 32000;
  9729. Context._MAXSIZE = 99999999;
  9730. Context._MAXVERTNUM = 65535;
  9731. Context.MAXCLIPRECT = null;
  9732. Context._COUNT = 0;
  9733. Context.SEGNUM = 32;
  9734. Context._contextcount = 0;
  9735. Context.PI2 = 2 * Math.PI;
  9736. Context._textRender = null;
  9737. Context.tmpuv1 = [0, 0, 0, 0, 0, 0, 0, 0];
  9738. Context.tmpUV = [0, 0, 0, 0, 0, 0, 0, 0];
  9739. Context.tmpUVRect = [0, 0, 0, 0];
  9740. class ContextParams {
  9741. constructor() {
  9742. this.lineWidth = 1;
  9743. }
  9744. clear() {
  9745. this.lineWidth = 1;
  9746. this.textAlign = this.textBaseline = null;
  9747. }
  9748. make() {
  9749. return this === ContextParams.DEFAULT ? new ContextParams() : this;
  9750. }
  9751. }
  9752. class WebGL {
  9753. static _uint8ArraySlice() {
  9754. var _this = this;
  9755. var sz = _this.length;
  9756. var dec = new Uint8Array(_this.length);
  9757. for (var i = 0; i < sz; i++)
  9758. dec[i] = _this[i];
  9759. return dec;
  9760. }
  9761. static _float32ArraySlice() {
  9762. var _this = this;
  9763. var sz = _this.length;
  9764. var dec = new Float32Array(_this.length);
  9765. for (var i = 0; i < sz; i++)
  9766. dec[i] = _this[i];
  9767. return dec;
  9768. }
  9769. static _uint16ArraySlice(...arg) {
  9770. var _this = this;
  9771. var sz;
  9772. var dec;
  9773. var i;
  9774. if (arg.length === 0) {
  9775. sz = _this.length;
  9776. dec = new Uint16Array(sz);
  9777. for (i = 0; i < sz; i++)
  9778. dec[i] = _this[i];
  9779. }
  9780. else if (arg.length === 2) {
  9781. var start = arg[0];
  9782. var end = arg[1];
  9783. if (end > start) {
  9784. sz = end - start;
  9785. dec = new Uint16Array(sz);
  9786. for (i = start; i < end; i++)
  9787. dec[i - start] = _this[i];
  9788. }
  9789. else {
  9790. dec = new Uint16Array(0);
  9791. }
  9792. }
  9793. return dec;
  9794. }
  9795. static _nativeRender_enable() {
  9796. }
  9797. static enable() {
  9798. return true;
  9799. }
  9800. static inner_enable() {
  9801. Float32Array.prototype.slice || (Float32Array.prototype.slice = WebGL._float32ArraySlice);
  9802. Uint16Array.prototype.slice || (Uint16Array.prototype.slice = WebGL._uint16ArraySlice);
  9803. Uint8Array.prototype.slice || (Uint8Array.prototype.slice = WebGL._uint8ArraySlice);
  9804. return true;
  9805. }
  9806. static onStageResize(width, height) {
  9807. if (WebGLContext.mainContext == null)
  9808. return;
  9809. WebGLContext.mainContext.viewport(0, 0, width, height);
  9810. RenderState2D.width = width;
  9811. RenderState2D.height = height;
  9812. }
  9813. }
  9814. WebGL._isWebGL2 = false;
  9815. WebGL.isNativeRender_enable = false;
  9816. class VertexArrayObject {
  9817. constructor() {
  9818. }
  9819. }
  9820. (function () {
  9821. var glErrorShadow = {};
  9822. function error(msg) {
  9823. if (window.console && window.console.error) {
  9824. window.console.error(msg);
  9825. }
  9826. }
  9827. function log(msg) {
  9828. if (window.console && window.console.log) {
  9829. window.console.log(msg);
  9830. }
  9831. }
  9832. function synthesizeGLError(err, opt_msg) {
  9833. glErrorShadow[err] = true;
  9834. if (opt_msg !== undefined) {
  9835. error(opt_msg);
  9836. }
  9837. }
  9838. function wrapGLError(gl) {
  9839. var f = gl.getError;
  9840. gl.getError = function () {
  9841. var err;
  9842. do {
  9843. err = f.apply(gl);
  9844. if (err != gl.NO_ERROR) {
  9845. glErrorShadow[err] = true;
  9846. }
  9847. } while (err != gl.NO_ERROR);
  9848. for (var err1 in glErrorShadow) {
  9849. if (glErrorShadow[err1]) {
  9850. delete glErrorShadow[err1];
  9851. return parseInt(err1);
  9852. }
  9853. }
  9854. return gl.NO_ERROR;
  9855. };
  9856. }
  9857. var WebGLVertexArrayObjectOES = function WebGLVertexArrayObjectOES(ext) {
  9858. var gl = ext.gl;
  9859. this.ext = ext;
  9860. this.isAlive = true;
  9861. this.hasBeenBound = false;
  9862. this.elementArrayBuffer = null;
  9863. this.attribs = new Array(ext.maxVertexAttribs);
  9864. for (var n = 0; n < this.attribs.length; n++) {
  9865. var attrib = new WebGLVertexArrayObjectOES.VertexAttrib(gl);
  9866. this.attribs[n] = attrib;
  9867. }
  9868. this.maxAttrib = 0;
  9869. };
  9870. WebGLVertexArrayObjectOES.VertexAttrib = function VertexAttrib(gl) {
  9871. this.enabled = false;
  9872. this.buffer = null;
  9873. this.size = 4;
  9874. this.type = gl.FLOAT;
  9875. this.normalized = false;
  9876. this.stride = 16;
  9877. this.offset = 0;
  9878. this.cached = "";
  9879. this.recache();
  9880. };
  9881. WebGLVertexArrayObjectOES.VertexAttrib.prototype.recache = function recache() {
  9882. this.cached = [this.size, this.type, this.normalized, this.stride, this.offset].join(":");
  9883. };
  9884. var OESVertexArrayObject = function OESVertexArrayObject(gl) {
  9885. var self = this;
  9886. this.gl = gl;
  9887. wrapGLError(gl);
  9888. var original = this.original = {
  9889. getParameter: gl.getParameter,
  9890. enableVertexAttribArray: gl.enableVertexAttribArray,
  9891. disableVertexAttribArray: gl.disableVertexAttribArray,
  9892. bindBuffer: gl.bindBuffer,
  9893. getVertexAttrib: gl.getVertexAttrib,
  9894. vertexAttribPointer: gl.vertexAttribPointer
  9895. };
  9896. gl.getParameter = function getParameter(pname) {
  9897. if (pname == self.VERTEX_ARRAY_BINDING_OES) {
  9898. if (self.currentVertexArrayObject == self.defaultVertexArrayObject) {
  9899. return null;
  9900. }
  9901. else {
  9902. return self.currentVertexArrayObject;
  9903. }
  9904. }
  9905. return original.getParameter.apply(this, arguments);
  9906. };
  9907. gl.enableVertexAttribArray = function enableVertexAttribArray(index) {
  9908. var vao = self.currentVertexArrayObject;
  9909. vao.maxAttrib = Math.max(vao.maxAttrib, index);
  9910. var attrib = vao.attribs[index];
  9911. attrib.enabled = true;
  9912. return original.enableVertexAttribArray.apply(this, arguments);
  9913. };
  9914. gl.disableVertexAttribArray = function disableVertexAttribArray(index) {
  9915. var vao = self.currentVertexArrayObject;
  9916. vao.maxAttrib = Math.max(vao.maxAttrib, index);
  9917. var attrib = vao.attribs[index];
  9918. attrib.enabled = false;
  9919. return original.disableVertexAttribArray.apply(this, arguments);
  9920. };
  9921. gl.bindBuffer = function bindBuffer(target, buffer) {
  9922. switch (target) {
  9923. case gl.ARRAY_BUFFER:
  9924. self.currentArrayBuffer = buffer;
  9925. break;
  9926. case gl.ELEMENT_ARRAY_BUFFER:
  9927. self.currentVertexArrayObject.elementArrayBuffer = buffer;
  9928. break;
  9929. }
  9930. return original.bindBuffer.apply(this, arguments);
  9931. };
  9932. gl.getVertexAttrib = function getVertexAttrib(index, pname) {
  9933. var vao = self.currentVertexArrayObject;
  9934. var attrib = vao.attribs[index];
  9935. switch (pname) {
  9936. case gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
  9937. return attrib.buffer;
  9938. case gl.VERTEX_ATTRIB_ARRAY_ENABLED:
  9939. return attrib.enabled;
  9940. case gl.VERTEX_ATTRIB_ARRAY_SIZE:
  9941. return attrib.size;
  9942. case gl.VERTEX_ATTRIB_ARRAY_STRIDE:
  9943. return attrib.stride;
  9944. case gl.VERTEX_ATTRIB_ARRAY_TYPE:
  9945. return attrib.type;
  9946. case gl.VERTEX_ATTRIB_ARRAY_NORMALIZED:
  9947. return attrib.normalized;
  9948. default:
  9949. return original.getVertexAttrib.apply(this, arguments);
  9950. }
  9951. };
  9952. gl.vertexAttribPointer = function vertexAttribPointer(indx, size, type, normalized, stride, offset) {
  9953. var vao = self.currentVertexArrayObject;
  9954. vao.maxAttrib = Math.max(vao.maxAttrib, indx);
  9955. var attrib = vao.attribs[indx];
  9956. attrib.buffer = self.currentArrayBuffer;
  9957. attrib.size = size;
  9958. attrib.type = type;
  9959. attrib.normalized = normalized;
  9960. attrib.stride = stride;
  9961. attrib.offset = offset;
  9962. attrib.recache();
  9963. return original.vertexAttribPointer.apply(this, arguments);
  9964. };
  9965. if (gl.instrumentExtension) {
  9966. gl.instrumentExtension(this, "OES_vertex_array_object");
  9967. }
  9968. gl.canvas.addEventListener('webglcontextrestored', function () {
  9969. log("OESVertexArrayObject emulation library context restored");
  9970. self.reset_();
  9971. }, true);
  9972. this.reset_();
  9973. };
  9974. OESVertexArrayObject.prototype.VERTEX_ARRAY_BINDING_OES = 0x85B5;
  9975. OESVertexArrayObject.prototype.reset_ = function reset_() {
  9976. var contextWasLost = this.vertexArrayObjects !== undefined;
  9977. if (contextWasLost) {
  9978. for (var ii = 0; ii < this.vertexArrayObjects.length; ++ii) {
  9979. this.vertexArrayObjects.isAlive = false;
  9980. }
  9981. }
  9982. var gl = this.gl;
  9983. this.maxVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
  9984. this.defaultVertexArrayObject = new WebGLVertexArrayObjectOES(this);
  9985. this.currentVertexArrayObject = null;
  9986. this.currentArrayBuffer = null;
  9987. this.vertexArrayObjects = [this.defaultVertexArrayObject];
  9988. this.bindVertexArrayOES(null);
  9989. };
  9990. OESVertexArrayObject.prototype.createVertexArrayOES = function createVertexArrayOES() {
  9991. var arrayObject = new WebGLVertexArrayObjectOES(this);
  9992. this.vertexArrayObjects.push(arrayObject);
  9993. return arrayObject;
  9994. };
  9995. OESVertexArrayObject.prototype.deleteVertexArrayOES = function deleteVertexArrayOES(arrayObject) {
  9996. arrayObject.isAlive = false;
  9997. this.vertexArrayObjects.splice(this.vertexArrayObjects.indexOf(arrayObject), 1);
  9998. if (this.currentVertexArrayObject == arrayObject) {
  9999. this.bindVertexArrayOES(null);
  10000. }
  10001. };
  10002. OESVertexArrayObject.prototype.isVertexArrayOES = function isVertexArrayOES(arrayObject) {
  10003. if (arrayObject && arrayObject instanceof WebGLVertexArrayObjectOES) {
  10004. if (arrayObject.hasBeenBound && arrayObject.ext == this) {
  10005. return true;
  10006. }
  10007. }
  10008. return false;
  10009. };
  10010. OESVertexArrayObject.prototype.bindVertexArrayOES = function bindVertexArrayOES(arrayObject) {
  10011. var gl = this.gl;
  10012. if (arrayObject && !arrayObject.isAlive) {
  10013. synthesizeGLError(gl.INVALID_OPERATION, "bindVertexArrayOES: attempt to bind deleted arrayObject");
  10014. return;
  10015. }
  10016. var original = this.original;
  10017. var oldVAO = this.currentVertexArrayObject;
  10018. this.currentVertexArrayObject = arrayObject || this.defaultVertexArrayObject;
  10019. this.currentVertexArrayObject.hasBeenBound = true;
  10020. var newVAO = this.currentVertexArrayObject;
  10021. if (oldVAO == newVAO) {
  10022. return;
  10023. }
  10024. if (!oldVAO || newVAO.elementArrayBuffer != oldVAO.elementArrayBuffer) {
  10025. original.bindBuffer.call(gl, gl.ELEMENT_ARRAY_BUFFER, newVAO.elementArrayBuffer);
  10026. }
  10027. var currentBinding = this.currentArrayBuffer;
  10028. var maxAttrib = Math.max(oldVAO ? oldVAO.maxAttrib : 0, newVAO.maxAttrib);
  10029. for (var n = 0; n <= maxAttrib; n++) {
  10030. var attrib = newVAO.attribs[n];
  10031. var oldAttrib = oldVAO ? oldVAO.attribs[n] : null;
  10032. if (!oldVAO || attrib.enabled != oldAttrib.enabled) {
  10033. if (attrib.enabled) {
  10034. original.enableVertexAttribArray.call(gl, n);
  10035. }
  10036. else {
  10037. original.disableVertexAttribArray.call(gl, n);
  10038. }
  10039. }
  10040. if (attrib.enabled) {
  10041. var bufferChanged = false;
  10042. if (!oldVAO || attrib.buffer != oldAttrib.buffer) {
  10043. if (currentBinding != attrib.buffer) {
  10044. original.bindBuffer.call(gl, gl.ARRAY_BUFFER, attrib.buffer);
  10045. currentBinding = attrib.buffer;
  10046. }
  10047. bufferChanged = true;
  10048. }
  10049. if (bufferChanged || attrib.cached != oldAttrib.cached) {
  10050. original.vertexAttribPointer.call(gl, n, attrib.size, attrib.type, attrib.normalized, attrib.stride, attrib.offset);
  10051. }
  10052. }
  10053. }
  10054. if (this.currentArrayBuffer != currentBinding) {
  10055. original.bindBuffer.call(gl, gl.ARRAY_BUFFER, this.currentArrayBuffer);
  10056. }
  10057. };
  10058. window._setupVertexArrayObject = function (gl) {
  10059. var original_getSupportedExtensions = gl.getSupportedExtensions;
  10060. gl.getSupportedExtensions = function getSupportedExtensions() {
  10061. var list = original_getSupportedExtensions.call(this) || [];
  10062. if (list.indexOf("OES_vertex_array_object") < 0) {
  10063. list.push("OES_vertex_array_object");
  10064. }
  10065. return list;
  10066. };
  10067. var original_getExtension = gl.getExtension;
  10068. gl.getExtension = function getExtension(name) {
  10069. var ext = original_getExtension.call(this, name);
  10070. if (ext) {
  10071. return ext;
  10072. }
  10073. if (name !== "OES_vertex_array_object") {
  10074. return null;
  10075. }
  10076. if (!this.__OESVertexArrayObject) {
  10077. console.log("Setup OES_vertex_array_object polyfill");
  10078. this.__OESVertexArrayObject = new OESVertexArrayObject(this);
  10079. }
  10080. return this.__OESVertexArrayObject;
  10081. };
  10082. };
  10083. window._forceSetupVertexArrayObject = function (gl) {
  10084. var original_getSupportedExtensions = gl.getSupportedExtensions;
  10085. gl.getSupportedExtensions = function getSupportedExtensions() {
  10086. var list = original_getSupportedExtensions.call(this) || [];
  10087. if (list.indexOf("OES_vertex_array_object") < 0) {
  10088. list.push("OES_vertex_array_object");
  10089. }
  10090. return list;
  10091. };
  10092. var original_getExtension = gl.getExtension;
  10093. gl.getExtension = function getExtension(name) {
  10094. if (name === "OES_vertex_array_object") {
  10095. if (!this.__OESVertexArrayObject) {
  10096. console.log("Setup OES_vertex_array_object polyfill");
  10097. this.__OESVertexArrayObject = new OESVertexArrayObject(this);
  10098. }
  10099. return this.__OESVertexArrayObject;
  10100. }
  10101. else {
  10102. var ext = original_getExtension.call(this, name);
  10103. if (ext) {
  10104. return ext;
  10105. }
  10106. else {
  10107. return null;
  10108. }
  10109. }
  10110. };
  10111. };
  10112. }());
  10113. class LayaGPU {
  10114. constructor(gl, isWebGL2) {
  10115. this._gl = null;
  10116. this._vaoExt = null;
  10117. this._angleInstancedArrays = null;
  10118. this._isWebGL2 = false;
  10119. this._oesTextureHalfFloat = null;
  10120. this._extTextureFilterAnisotropic = null;
  10121. this._compressedTextureS3tc = null;
  10122. this._compressedTexturePvrtc = null;
  10123. this._compressedTextureEtc1 = null;
  10124. this._gl = gl;
  10125. this._isWebGL2 = isWebGL2;
  10126. try {
  10127. var precisionFormat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
  10128. precisionFormat.precision ? (WebGL.shaderHighPrecision = true) : WebGL.shaderHighPrecision = false;
  10129. }
  10130. catch (e) {
  10131. }
  10132. if (!isWebGL2) {
  10133. var forceVAO = LayaGPU._forceSupportVAOPlatform();
  10134. if (!ILaya.Render.isConchApp) {
  10135. if (window._setupVertexArrayObject) {
  10136. if (forceVAO)
  10137. window._forceSetupVertexArrayObject(gl);
  10138. else
  10139. window._setupVertexArrayObject(gl);
  10140. }
  10141. }
  10142. this._vaoExt = this._getExtension("OES_vertex_array_object");
  10143. if (!forceVAO)
  10144. this._angleInstancedArrays = this._getExtension("ANGLE_instanced_arrays");
  10145. this._oesTextureHalfFloat = this._getExtension("OES_texture_half_float");
  10146. this._getExtension("OES_texture_half_float_linear");
  10147. }
  10148. else {
  10149. this._getExtension("EXT_color_buffer_float");
  10150. }
  10151. this._extTextureFilterAnisotropic = this._getExtension("EXT_texture_filter_anisotropic");
  10152. this._compressedTextureS3tc = this._getExtension("WEBGL_compressed_texture_s3tc");
  10153. this._compressedTexturePvrtc = this._getExtension("WEBGL_compressed_texture_pvrtc");
  10154. this._compressedTextureEtc1 = this._getExtension("WEBGL_compressed_texture_etc1");
  10155. }
  10156. static _forceSupportVAOPlatform() {
  10157. let Browser = ILaya.Browser;
  10158. return (Browser.onMiniGame && Browser.onIOS) || Browser.onBDMiniGame || Browser.onQGMiniGame;
  10159. }
  10160. _getExtension(name) {
  10161. var prefixes = LayaGPU._extentionVendorPrefixes;
  10162. for (var k in prefixes) {
  10163. var ext = this._gl.getExtension(prefixes[k] + name);
  10164. if (ext)
  10165. return ext;
  10166. }
  10167. return null;
  10168. }
  10169. createVertexArray() {
  10170. if (this._isWebGL2)
  10171. return this._gl.createVertexArray();
  10172. else
  10173. return this._vaoExt.createVertexArrayOES();
  10174. }
  10175. bindVertexArray(vertexArray) {
  10176. if (this._isWebGL2)
  10177. this._gl.bindVertexArray(vertexArray);
  10178. else
  10179. this._vaoExt.bindVertexArrayOES(vertexArray);
  10180. }
  10181. deleteVertexArray(vertexArray) {
  10182. if (this._isWebGL2)
  10183. this._gl.deleteVertexArray(vertexArray);
  10184. else
  10185. this._vaoExt.deleteVertexArrayOES(vertexArray);
  10186. }
  10187. isVertexArray(vertexArray) {
  10188. if (this._isWebGL2)
  10189. this._gl.isVertexArray(vertexArray);
  10190. else
  10191. this._vaoExt.isVertexArrayOES(vertexArray);
  10192. }
  10193. drawElementsInstanced(mode, count, type, offset, instanceCount) {
  10194. if (this._isWebGL2)
  10195. this._gl.drawElementsInstanced(mode, count, type, offset, instanceCount);
  10196. else
  10197. this._angleInstancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount);
  10198. }
  10199. drawArraysInstanced(mode, first, count, instanceCount) {
  10200. if (this._isWebGL2)
  10201. this._gl.drawArraysInstanced(mode, first, count, instanceCount);
  10202. else
  10203. this._angleInstancedArrays.drawArraysInstancedANGLE(mode, first, count, instanceCount);
  10204. }
  10205. vertexAttribDivisor(index, divisor) {
  10206. if (this._isWebGL2)
  10207. this._gl.vertexAttribDivisor(index, divisor);
  10208. else
  10209. this._angleInstancedArrays.vertexAttribDivisorANGLE(index, divisor);
  10210. }
  10211. supportInstance() {
  10212. if (this._isWebGL2 || this._angleInstancedArrays)
  10213. return true;
  10214. else
  10215. return false;
  10216. }
  10217. }
  10218. LayaGPU._extentionVendorPrefixes = ["", "WEBKIT_", "MOZ_"];
  10219. class Render {
  10220. constructor(width, height, mainCanv) {
  10221. this._timeId = 0;
  10222. Render._mainCanvas = mainCanv;
  10223. Render._mainCanvas.source.id = "layaCanvas";
  10224. Render._mainCanvas.source.width = width;
  10225. Render._mainCanvas.source.height = height;
  10226. if (Render.isConchApp) {
  10227. document.body.appendChild(Render._mainCanvas.source);
  10228. }
  10229. this.initRender(Render._mainCanvas, width, height);
  10230. window.requestAnimationFrame(loop);
  10231. function loop(stamp) {
  10232. ILaya.stage._loop();
  10233. window.requestAnimationFrame(loop);
  10234. }
  10235. ILaya.stage.on("visibilitychange", this, this._onVisibilitychange);
  10236. }
  10237. _onVisibilitychange() {
  10238. if (!ILaya.stage.isVisibility) {
  10239. this._timeId = window.setInterval(this._enterFrame, 1000);
  10240. }
  10241. else if (this._timeId != 0) {
  10242. window.clearInterval(this._timeId);
  10243. }
  10244. }
  10245. initRender(canvas, w, h) {
  10246. function getWebGLContext(canvas) {
  10247. var gl;
  10248. var names = ["webgl2", "webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
  10249. if (!Config.useWebGL2 || Browser.onBDMiniGame) {
  10250. names.shift();
  10251. }
  10252. for (var i = 0; i < names.length; i++) {
  10253. try {
  10254. gl = canvas.getContext(names[i], { stencil: Config.isStencil, alpha: Config.isAlpha, antialias: Config.isAntialias, premultipliedAlpha: Config.premultipliedAlpha, preserveDrawingBuffer: Config.preserveDrawingBuffer });
  10255. }
  10256. catch (e) {
  10257. }
  10258. if (gl) {
  10259. (names[i] === 'webgl2') && (WebGL._isWebGL2 = true);
  10260. return gl;
  10261. }
  10262. }
  10263. return null;
  10264. }
  10265. var gl = LayaGL.instance = WebGLContext.mainContext = getWebGLContext(Render._mainCanvas.source);
  10266. if (!gl)
  10267. return false;
  10268. LayaGL.instance = gl;
  10269. LayaGL.layaGPUInstance = new LayaGPU(gl, WebGL._isWebGL2);
  10270. canvas.size(w, h);
  10271. Context.__init__();
  10272. SubmitBase.__init__();
  10273. var ctx = new Context();
  10274. ctx.isMain = true;
  10275. Render._context = ctx;
  10276. canvas._setContext(ctx);
  10277. ShaderDefines2D.__init__();
  10278. Value2D.__init__();
  10279. Shader2D.__init__();
  10280. Buffer2D.__int__(gl);
  10281. BlendMode._init_(gl);
  10282. return true;
  10283. }
  10284. _enterFrame(e = null) {
  10285. ILaya.stage._loop();
  10286. }
  10287. static get context() {
  10288. return Render._context;
  10289. }
  10290. static get canvas() {
  10291. return Render._mainCanvas.source;
  10292. }
  10293. }
  10294. Render.supportWebGLPlusCulling = false;
  10295. Render.supportWebGLPlusAnimation = false;
  10296. Render.supportWebGLPlusRendering = false;
  10297. Render.isConchApp = false;
  10298. {
  10299. Render.isConchApp = (window.conch != null);
  10300. if (Render.isConchApp) {
  10301. Render.supportWebGLPlusCulling = false;
  10302. Render.supportWebGLPlusAnimation = true;
  10303. Render.supportWebGLPlusRendering = true;
  10304. }
  10305. else if (window.qq != null && window.qq.webglPlus != null) {
  10306. Render.supportWebGLPlusCulling = false;
  10307. Render.supportWebGLPlusAnimation = true;
  10308. Render.supportWebGLPlusRendering = true;
  10309. }
  10310. }
  10311. class DrawTrianglesCmd {
  10312. static create(texture, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode) {
  10313. var cmd = Pool.getItemByClass("DrawTrianglesCmd", DrawTrianglesCmd);
  10314. cmd.texture = texture;
  10315. cmd.x = x;
  10316. cmd.y = y;
  10317. cmd.vertices = vertices;
  10318. cmd.uvs = uvs;
  10319. cmd.indices = indices;
  10320. cmd.matrix = matrix;
  10321. cmd.alpha = alpha;
  10322. if (color) {
  10323. cmd.color = new ColorFilter();
  10324. var c = ColorUtils.create(color).arrColor;
  10325. cmd.color.color(c[0] * 255, c[1] * 255, c[2] * 255, c[3] * 255);
  10326. }
  10327. cmd.blendMode = blendMode;
  10328. return cmd;
  10329. }
  10330. recover() {
  10331. this.texture = null;
  10332. this.vertices = null;
  10333. this.uvs = null;
  10334. this.indices = null;
  10335. this.matrix = null;
  10336. Pool.recover("DrawTrianglesCmd", this);
  10337. }
  10338. run(context, gx, gy) {
  10339. context.drawTriangles(this.texture, this.x + gx, this.y + gy, this.vertices, this.uvs, this.indices, this.matrix, this.alpha, this.color, this.blendMode);
  10340. }
  10341. get cmdID() {
  10342. return DrawTrianglesCmd.ID;
  10343. }
  10344. }
  10345. DrawTrianglesCmd.ID = "DrawTriangles";
  10346. class Draw9GridTexture {
  10347. constructor() {
  10348. }
  10349. static create(texture, x, y, width, height, sizeGrid) {
  10350. var cmd = Pool.getItemByClass("Draw9GridTexture", Draw9GridTexture);
  10351. cmd.texture = texture;
  10352. texture._addReference();
  10353. cmd.x = x;
  10354. cmd.y = y;
  10355. cmd.width = width;
  10356. cmd.height = height;
  10357. cmd.sizeGrid = sizeGrid;
  10358. return cmd;
  10359. }
  10360. recover() {
  10361. this.texture._removeReference();
  10362. Pool.recover("Draw9GridTexture", this);
  10363. }
  10364. run(context, gx, gy) {
  10365. context.drawTextureWithSizeGrid(this.texture, this.x, this.y, this.width, this.height, this.sizeGrid, gx, gy);
  10366. }
  10367. get cmdID() {
  10368. return Draw9GridTexture.ID;
  10369. }
  10370. }
  10371. Draw9GridTexture.ID = "Draw9GridTexture";
  10372. class GraphicsBounds {
  10373. constructor() {
  10374. this._cacheBoundsType = false;
  10375. }
  10376. destroy() {
  10377. this._graphics = null;
  10378. this._cacheBoundsType = false;
  10379. if (this._temp)
  10380. this._temp.length = 0;
  10381. if (this._rstBoundPoints)
  10382. this._rstBoundPoints.length = 0;
  10383. if (this._bounds)
  10384. this._bounds.recover();
  10385. this._bounds = null;
  10386. Pool.recover("GraphicsBounds", this);
  10387. }
  10388. static create() {
  10389. return Pool.getItemByClass("GraphicsBounds", GraphicsBounds);
  10390. }
  10391. reset() {
  10392. this._temp && (this._temp.length = 0);
  10393. }
  10394. getBounds(realSize = false) {
  10395. if (!this._bounds || !this._temp || this._temp.length < 1 || realSize != this._cacheBoundsType) {
  10396. this._bounds = Rectangle._getWrapRec(this.getBoundPoints(realSize), this._bounds);
  10397. }
  10398. this._cacheBoundsType = realSize;
  10399. return this._bounds;
  10400. }
  10401. getBoundPoints(realSize = false) {
  10402. if (!this._temp || this._temp.length < 1 || realSize != this._cacheBoundsType)
  10403. this._temp = this._getCmdPoints(realSize);
  10404. this._cacheBoundsType = realSize;
  10405. return this._rstBoundPoints = Utils.copyArray(this._rstBoundPoints, this._temp);
  10406. }
  10407. _getCmdPoints(realSize = false) {
  10408. var cmds = this._graphics.cmds;
  10409. var rst;
  10410. rst = this._temp || (this._temp = []);
  10411. rst.length = 0;
  10412. if (!cmds && this._graphics._one != null) {
  10413. GraphicsBounds._tempCmds.length = 0;
  10414. GraphicsBounds._tempCmds.push(this._graphics._one);
  10415. cmds = GraphicsBounds._tempCmds;
  10416. }
  10417. if (!cmds)
  10418. return rst;
  10419. var matrixs = GraphicsBounds._tempMatrixArrays;
  10420. matrixs.length = 0;
  10421. var tMatrix = GraphicsBounds._initMatrix;
  10422. tMatrix.identity();
  10423. var tempMatrix = GraphicsBounds._tempMatrix;
  10424. var cmd;
  10425. var tex;
  10426. for (var i = 0, n = cmds.length; i < n; i++) {
  10427. cmd = cmds[i];
  10428. switch (cmd.cmdID) {
  10429. case AlphaCmd.ID:
  10430. matrixs.push(tMatrix);
  10431. tMatrix = tMatrix.clone();
  10432. break;
  10433. case RestoreCmd.ID:
  10434. tMatrix = matrixs.pop();
  10435. break;
  10436. case ScaleCmd.ID:
  10437. tempMatrix.identity();
  10438. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10439. tempMatrix.scale(cmd.scaleX, cmd.scaleY);
  10440. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10441. this._switchMatrix(tMatrix, tempMatrix);
  10442. break;
  10443. case RotateCmd.ID:
  10444. tempMatrix.identity();
  10445. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10446. tempMatrix.rotate(cmd.angle);
  10447. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10448. this._switchMatrix(tMatrix, tempMatrix);
  10449. break;
  10450. case TranslateCmd.ID:
  10451. tempMatrix.identity();
  10452. tempMatrix.translate(cmd.tx, cmd.ty);
  10453. this._switchMatrix(tMatrix, tempMatrix);
  10454. break;
  10455. case TransformCmd.ID:
  10456. tempMatrix.identity();
  10457. tempMatrix.translate(-cmd.pivotX, -cmd.pivotY);
  10458. tempMatrix.concat(cmd.matrix);
  10459. tempMatrix.translate(cmd.pivotX, cmd.pivotY);
  10460. this._switchMatrix(tMatrix, tempMatrix);
  10461. break;
  10462. case DrawImageCmd.ID:
  10463. case FillTextureCmd.ID:
  10464. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10465. break;
  10466. case DrawTextureCmd.ID:
  10467. tMatrix.copyTo(tempMatrix);
  10468. if (cmd.matrix)
  10469. tempMatrix.concat(cmd.matrix);
  10470. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tempMatrix);
  10471. break;
  10472. case DrawImageCmd.ID:
  10473. tex = cmd.texture;
  10474. if (realSize) {
  10475. if (cmd.width && cmd.height) {
  10476. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10477. }
  10478. else {
  10479. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), tMatrix);
  10480. }
  10481. }
  10482. else {
  10483. var wRate = (cmd.width || tex.sourceWidth) / tex.width;
  10484. var hRate = (cmd.height || tex.sourceHeight) / tex.height;
  10485. var oWidth = wRate * tex.sourceWidth;
  10486. var oHeight = hRate * tex.sourceHeight;
  10487. var offX = tex.offsetX > 0 ? tex.offsetX : 0;
  10488. var offY = tex.offsetY > 0 ? tex.offsetY : 0;
  10489. offX *= wRate;
  10490. offY *= hRate;
  10491. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - offX, cmd.y - offY, oWidth, oHeight), tMatrix);
  10492. }
  10493. break;
  10494. case FillTextureCmd.ID:
  10495. if (cmd.width && cmd.height) {
  10496. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10497. }
  10498. else {
  10499. tex = cmd.texture;
  10500. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), tMatrix);
  10501. }
  10502. break;
  10503. case DrawTextureCmd.ID:
  10504. var drawMatrix;
  10505. if (cmd.matrix) {
  10506. tMatrix.copyTo(tempMatrix);
  10507. tempMatrix.concat(cmd.matrix);
  10508. drawMatrix = tempMatrix;
  10509. }
  10510. else {
  10511. drawMatrix = tMatrix;
  10512. }
  10513. if (realSize) {
  10514. if (cmd.width && cmd.height) {
  10515. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), drawMatrix);
  10516. }
  10517. else {
  10518. tex = cmd.texture;
  10519. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, tex.width, tex.height), drawMatrix);
  10520. }
  10521. }
  10522. else {
  10523. tex = cmd.texture;
  10524. wRate = (cmd.width || tex.sourceWidth) / tex.width;
  10525. hRate = (cmd.height || tex.sourceHeight) / tex.height;
  10526. oWidth = wRate * tex.sourceWidth;
  10527. oHeight = hRate * tex.sourceHeight;
  10528. offX = tex.offsetX > 0 ? tex.offsetX : 0;
  10529. offY = tex.offsetY > 0 ? tex.offsetY : 0;
  10530. offX *= wRate;
  10531. offY *= hRate;
  10532. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - offX, cmd.y - offY, oWidth, oHeight), drawMatrix);
  10533. }
  10534. break;
  10535. case DrawRectCmd.ID:
  10536. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x, cmd.y, cmd.width, cmd.height), tMatrix);
  10537. break;
  10538. case DrawCircleCmd.ID:
  10539. GraphicsBounds._addPointArrToRst(rst, Rectangle._getBoundPointS(cmd.x - cmd.radius, cmd.y - cmd.radius, cmd.radius + cmd.radius, cmd.radius + cmd.radius), tMatrix);
  10540. break;
  10541. case DrawLineCmd.ID:
  10542. GraphicsBounds._tempPoints.length = 0;
  10543. var lineWidth;
  10544. lineWidth = cmd.lineWidth * 0.5;
  10545. if (cmd.fromX == cmd.toX) {
  10546. GraphicsBounds._tempPoints.push(cmd.fromX + lineWidth, cmd.fromY, cmd.toX + lineWidth, cmd.toY, cmd.fromX - lineWidth, cmd.fromY, cmd.toX - lineWidth, cmd.toY);
  10547. }
  10548. else if (cmd.fromY == cmd.toY) {
  10549. GraphicsBounds._tempPoints.push(cmd.fromX, cmd.fromY + lineWidth, cmd.toX, cmd.toY + lineWidth, cmd.fromX, cmd.fromY - lineWidth, cmd.toX, cmd.toY - lineWidth);
  10550. }
  10551. else {
  10552. GraphicsBounds._tempPoints.push(cmd.fromX, cmd.fromY, cmd.toX, cmd.toY);
  10553. }
  10554. GraphicsBounds._addPointArrToRst(rst, GraphicsBounds._tempPoints, tMatrix);
  10555. break;
  10556. case DrawCurvesCmd.ID:
  10557. GraphicsBounds._addPointArrToRst(rst, Bezier.I.getBezierPoints(cmd.points), tMatrix, cmd.x, cmd.y);
  10558. break;
  10559. case DrawLinesCmd.ID:
  10560. case DrawPolyCmd.ID:
  10561. GraphicsBounds._addPointArrToRst(rst, cmd.points, tMatrix, cmd.x, cmd.y);
  10562. break;
  10563. case DrawPathCmd.ID:
  10564. GraphicsBounds._addPointArrToRst(rst, this._getPathPoints(cmd.paths), tMatrix, cmd.x, cmd.y);
  10565. break;
  10566. case DrawPieCmd.ID:
  10567. GraphicsBounds._addPointArrToRst(rst, this._getPiePoints(cmd.x, cmd.y, cmd.radius, cmd.startAngle, cmd.endAngle), tMatrix);
  10568. break;
  10569. case DrawTrianglesCmd.ID:
  10570. GraphicsBounds._addPointArrToRst(rst, this._getTriAngBBXPoints(cmd.vertices), tMatrix);
  10571. break;
  10572. case Draw9GridTexture.ID:
  10573. GraphicsBounds._addPointArrToRst(rst, this._getDraw9GridBBXPoints(cmd), tMatrix);
  10574. break;
  10575. }
  10576. }
  10577. if (rst.length > 200) {
  10578. rst = Utils.copyArray(rst, Rectangle._getWrapRec(rst)._getBoundPoints());
  10579. }
  10580. else if (rst.length > 8)
  10581. rst = GrahamScan.scanPList(rst);
  10582. return rst;
  10583. }
  10584. _switchMatrix(tMatix, tempMatrix) {
  10585. tempMatrix.concat(tMatix);
  10586. tempMatrix.copyTo(tMatix);
  10587. }
  10588. static _addPointArrToRst(rst, points, matrix, dx = 0, dy = 0) {
  10589. var i, len;
  10590. len = points.length;
  10591. for (i = 0; i < len; i += 2) {
  10592. GraphicsBounds._addPointToRst(rst, points[i] + dx, points[i + 1] + dy, matrix);
  10593. }
  10594. }
  10595. static _addPointToRst(rst, x, y, matrix) {
  10596. var _tempPoint = Point.TEMP;
  10597. _tempPoint.setTo(x ? x : 0, y ? y : 0);
  10598. matrix.transformPoint(_tempPoint);
  10599. rst.push(_tempPoint.x, _tempPoint.y);
  10600. }
  10601. _getPiePoints(x, y, radius, startAngle, endAngle) {
  10602. var rst = GraphicsBounds._tempPoints;
  10603. GraphicsBounds._tempPoints.length = 0;
  10604. var k = Math.PI / 180;
  10605. var d1 = endAngle - startAngle;
  10606. if (d1 >= 360 || d1 <= -360) {
  10607. rst.push(x - radius, y - radius);
  10608. rst.push(x + radius, y - radius);
  10609. rst.push(x + radius, y + radius);
  10610. rst.push(x - radius, y + radius);
  10611. return rst;
  10612. }
  10613. rst.push(x, y);
  10614. var delta = d1 % 360;
  10615. if (delta < 0)
  10616. delta += 360;
  10617. var end1 = startAngle + delta;
  10618. var st = startAngle * k;
  10619. var ed = end1 * k;
  10620. rst.push(x + radius * Math.cos(st), y + radius * Math.sin(st));
  10621. rst.push(x + radius * Math.cos(ed), y + radius * Math.sin(ed));
  10622. var s1 = Math.ceil(startAngle / 90) * 90;
  10623. var s2 = Math.floor(end1 / 90) * 90;
  10624. for (var cs = s1; cs <= s2; cs += 90) {
  10625. var csr = cs * k;
  10626. rst.push(x + radius * Math.cos(csr), y + radius * Math.sin(csr));
  10627. }
  10628. return rst;
  10629. }
  10630. _getTriAngBBXPoints(vert) {
  10631. var vnum = vert.length;
  10632. if (vnum < 2)
  10633. return [];
  10634. var minx = vert[0];
  10635. var miny = vert[1];
  10636. var maxx = minx;
  10637. var maxy = miny;
  10638. for (var i = 2; i < vnum;) {
  10639. var cx = vert[i++];
  10640. var cy = vert[i++];
  10641. if (minx > cx)
  10642. minx = cx;
  10643. if (miny > cy)
  10644. miny = cy;
  10645. if (maxx < cx)
  10646. maxx = cx;
  10647. if (maxy < cy)
  10648. maxy = cy;
  10649. }
  10650. return [minx, miny, maxx, miny, maxx, maxy, minx, maxy];
  10651. }
  10652. _getDraw9GridBBXPoints(cmd) {
  10653. var minx = 0;
  10654. var miny = 0;
  10655. var maxx = cmd.width;
  10656. var maxy = cmd.height;
  10657. return [minx, miny, maxx, miny, maxx, maxy, minx, maxy];
  10658. }
  10659. _getPathPoints(paths) {
  10660. var i, len;
  10661. var rst = GraphicsBounds._tempPoints;
  10662. rst.length = 0;
  10663. len = paths.length;
  10664. var tCMD;
  10665. for (i = 0; i < len; i++) {
  10666. tCMD = paths[i];
  10667. if (tCMD.length > 1) {
  10668. rst.push(tCMD[1], tCMD[2]);
  10669. if (tCMD.length > 3) {
  10670. rst.push(tCMD[3], tCMD[4]);
  10671. }
  10672. }
  10673. }
  10674. return rst;
  10675. }
  10676. }
  10677. GraphicsBounds._tempMatrix = new Matrix();
  10678. GraphicsBounds._initMatrix = new Matrix();
  10679. GraphicsBounds._tempPoints = [];
  10680. GraphicsBounds._tempMatrixArrays = [];
  10681. GraphicsBounds._tempCmds = [];
  10682. class SpriteConst {
  10683. }
  10684. SpriteConst.ALPHA = 0x01;
  10685. SpriteConst.TRANSFORM = 0x02;
  10686. SpriteConst.BLEND = 0x04;
  10687. SpriteConst.CANVAS = 0x08;
  10688. SpriteConst.FILTERS = 0x10;
  10689. SpriteConst.MASK = 0x20;
  10690. SpriteConst.CLIP = 0x40;
  10691. SpriteConst.STYLE = 0x80;
  10692. SpriteConst.TEXTURE = 0x100;
  10693. SpriteConst.GRAPHICS = 0x200;
  10694. SpriteConst.LAYAGL3D = 0x400;
  10695. SpriteConst.CUSTOM = 0x800;
  10696. SpriteConst.ONECHILD = 0x1000;
  10697. SpriteConst.CHILDS = 0x2000;
  10698. SpriteConst.REPAINT_NONE = 0;
  10699. SpriteConst.REPAINT_NODE = 0x01;
  10700. SpriteConst.REPAINT_CACHE = 0x02;
  10701. SpriteConst.REPAINT_ALL = 0x03;
  10702. class ClipRectCmd {
  10703. static create(x, y, width, height) {
  10704. var cmd = Pool.getItemByClass("ClipRectCmd", ClipRectCmd);
  10705. cmd.x = x;
  10706. cmd.y = y;
  10707. cmd.width = width;
  10708. cmd.height = height;
  10709. return cmd;
  10710. }
  10711. recover() {
  10712. Pool.recover("ClipRectCmd", this);
  10713. }
  10714. run(context, gx, gy) {
  10715. context.clipRect(this.x + gx, this.y + gy, this.width, this.height);
  10716. }
  10717. get cmdID() {
  10718. return ClipRectCmd.ID;
  10719. }
  10720. }
  10721. ClipRectCmd.ID = "ClipRect";
  10722. class DrawTexturesCmd {
  10723. static create(texture, pos) {
  10724. var cmd = Pool.getItemByClass("DrawTexturesCmd", DrawTexturesCmd);
  10725. cmd.texture = texture;
  10726. texture._addReference();
  10727. cmd.pos = pos;
  10728. return cmd;
  10729. }
  10730. recover() {
  10731. this.texture._removeReference();
  10732. this.texture = null;
  10733. this.pos = null;
  10734. Pool.recover("DrawTexturesCmd", this);
  10735. }
  10736. run(context, gx, gy) {
  10737. context.drawTextures(this.texture, this.pos, gx, gy);
  10738. }
  10739. get cmdID() {
  10740. return DrawTexturesCmd.ID;
  10741. }
  10742. }
  10743. DrawTexturesCmd.ID = "DrawTextures";
  10744. class FillBorderTextCmd {
  10745. static create(text, x, y, font, fillColor, borderColor, lineWidth, textAlign) {
  10746. var cmd = Pool.getItemByClass("FillBorderTextCmd", FillBorderTextCmd);
  10747. cmd.text = text;
  10748. cmd.x = x;
  10749. cmd.y = y;
  10750. cmd.font = font;
  10751. cmd.fillColor = fillColor;
  10752. cmd.borderColor = borderColor;
  10753. cmd.lineWidth = lineWidth;
  10754. cmd.textAlign = textAlign;
  10755. return cmd;
  10756. }
  10757. recover() {
  10758. Pool.recover("FillBorderTextCmd", this);
  10759. }
  10760. run(context, gx, gy) {
  10761. context.fillBorderText(this.text, this.x + gx, this.y + gy, this.font, this.fillColor, this.borderColor, this.lineWidth, this.textAlign);
  10762. }
  10763. get cmdID() {
  10764. return FillBorderTextCmd.ID;
  10765. }
  10766. }
  10767. FillBorderTextCmd.ID = "FillBorderText";
  10768. class FillBorderWordsCmd {
  10769. static create(words, x, y, font, fillColor, borderColor, lineWidth) {
  10770. var cmd = Pool.getItemByClass("FillBorderWordsCmd", FillBorderWordsCmd);
  10771. cmd.words = words;
  10772. cmd.x = x;
  10773. cmd.y = y;
  10774. cmd.font = font;
  10775. cmd.fillColor = fillColor;
  10776. cmd.borderColor = borderColor;
  10777. cmd.lineWidth = lineWidth;
  10778. return cmd;
  10779. }
  10780. recover() {
  10781. this.words = null;
  10782. Pool.recover("FillBorderWordsCmd", this);
  10783. }
  10784. run(context, gx, gy) {
  10785. context.fillBorderWords(this.words, this.x + gx, this.y + gy, this.font, this.fillColor, this.borderColor, this.lineWidth);
  10786. }
  10787. get cmdID() {
  10788. return FillBorderWordsCmd.ID;
  10789. }
  10790. }
  10791. FillBorderWordsCmd.ID = "FillBorderWords";
  10792. class FillTextCmd {
  10793. constructor() {
  10794. this._textIsWorldText = false;
  10795. this._fontColor = 0xffffffff;
  10796. this._strokeColor = 0;
  10797. this._fontObj = FillTextCmd._defFontObj;
  10798. this._nTexAlign = 0;
  10799. }
  10800. static create(text, x, y, font, color, textAlign) {
  10801. var cmd = Pool.getItemByClass("FillTextCmd", FillTextCmd);
  10802. cmd.text = text;
  10803. cmd._textIsWorldText = text instanceof WordText;
  10804. cmd.x = x;
  10805. cmd.y = y;
  10806. cmd.font = font;
  10807. cmd.color = color;
  10808. cmd.textAlign = textAlign;
  10809. return cmd;
  10810. }
  10811. recover() {
  10812. Pool.recover("FillTextCmd", this);
  10813. }
  10814. run(context, gx, gy) {
  10815. if (ILaya.stage.isGlobalRepaint()) {
  10816. this._textIsWorldText && this._text.cleanCache();
  10817. }
  10818. if (this._textIsWorldText) {
  10819. context._fast_filltext(this._text, this.x + gx, this.y + gy, this._fontObj, this._color, null, 0, this._nTexAlign, 0);
  10820. }
  10821. else {
  10822. context.drawText(this._text, this.x + gx, this.y + gy, this._font, this._color, this._textAlign);
  10823. }
  10824. }
  10825. get cmdID() {
  10826. return FillTextCmd.ID;
  10827. }
  10828. get text() {
  10829. return this._text;
  10830. }
  10831. set text(value) {
  10832. this._text = value;
  10833. this._textIsWorldText = value instanceof WordText;
  10834. this._textIsWorldText && this._text.cleanCache();
  10835. }
  10836. get font() {
  10837. return this._font;
  10838. }
  10839. set font(value) {
  10840. this._font = value;
  10841. this._fontObj = FontInfo.Parse(value);
  10842. this._textIsWorldText && this._text.cleanCache();
  10843. }
  10844. get color() {
  10845. return this._color;
  10846. }
  10847. set color(value) {
  10848. this._color = value;
  10849. this._fontColor = ColorUtils.create(value).numColor;
  10850. this._textIsWorldText && this._text.cleanCache();
  10851. }
  10852. get textAlign() {
  10853. return this._textAlign;
  10854. }
  10855. set textAlign(value) {
  10856. this._textAlign = value;
  10857. switch (value) {
  10858. case 'center':
  10859. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER;
  10860. break;
  10861. case 'right':
  10862. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT;
  10863. break;
  10864. default:
  10865. this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_DEFAULT;
  10866. }
  10867. this._textIsWorldText && this._text.cleanCache();
  10868. }
  10869. }
  10870. FillTextCmd.ID = "FillText";
  10871. FillTextCmd._defFontObj = new FontInfo(null);
  10872. class FillWordsCmd {
  10873. static create(words, x, y, font, color) {
  10874. var cmd = Pool.getItemByClass("FillWordsCmd", FillWordsCmd);
  10875. cmd.words = words;
  10876. cmd.x = x;
  10877. cmd.y = y;
  10878. cmd.font = font;
  10879. cmd.color = color;
  10880. return cmd;
  10881. }
  10882. recover() {
  10883. this.words = null;
  10884. Pool.recover("FillWordsCmd", this);
  10885. }
  10886. run(context, gx, gy) {
  10887. context.fillWords(this.words, this.x + gx, this.y + gy, this.font, this.color);
  10888. }
  10889. get cmdID() {
  10890. return FillWordsCmd.ID;
  10891. }
  10892. }
  10893. FillWordsCmd.ID = "FillWords";
  10894. class SaveCmd {
  10895. static create() {
  10896. var cmd = Pool.getItemByClass("SaveCmd", SaveCmd);
  10897. return cmd;
  10898. }
  10899. recover() {
  10900. Pool.recover("SaveCmd", this);
  10901. }
  10902. run(context, gx, gy) {
  10903. context.save();
  10904. }
  10905. get cmdID() {
  10906. return SaveCmd.ID;
  10907. }
  10908. }
  10909. SaveCmd.ID = "Save";
  10910. class StrokeTextCmd {
  10911. static create(text, x, y, font, color, lineWidth, textAlign) {
  10912. var cmd = Pool.getItemByClass("StrokeTextCmd", StrokeTextCmd);
  10913. cmd.text = text;
  10914. cmd.x = x;
  10915. cmd.y = y;
  10916. cmd.font = font;
  10917. cmd.color = color;
  10918. cmd.lineWidth = lineWidth;
  10919. cmd.textAlign = textAlign;
  10920. return cmd;
  10921. }
  10922. recover() {
  10923. Pool.recover("StrokeTextCmd", this);
  10924. }
  10925. run(context, gx, gy) {
  10926. context.strokeWord(this.text, this.x + gx, this.y + gy, this.font, this.color, this.lineWidth, this.textAlign);
  10927. }
  10928. get cmdID() {
  10929. return StrokeTextCmd.ID;
  10930. }
  10931. }
  10932. StrokeTextCmd.ID = "StrokeText";
  10933. class CacheManger {
  10934. constructor() {
  10935. }
  10936. static regCacheByFunction(disposeFunction, getCacheListFunction) {
  10937. CacheManger.unRegCacheByFunction(disposeFunction, getCacheListFunction);
  10938. var cache;
  10939. cache = { tryDispose: disposeFunction, getCacheList: getCacheListFunction };
  10940. CacheManger._cacheList.push(cache);
  10941. }
  10942. static unRegCacheByFunction(disposeFunction, getCacheListFunction) {
  10943. var i, len;
  10944. len = CacheManger._cacheList.length;
  10945. for (i = 0; i < len; i++) {
  10946. if (CacheManger._cacheList[i].tryDispose == disposeFunction && CacheManger._cacheList[i].getCacheList == getCacheListFunction) {
  10947. CacheManger._cacheList.splice(i, 1);
  10948. return;
  10949. }
  10950. }
  10951. }
  10952. static forceDispose() {
  10953. var i, len = CacheManger._cacheList.length;
  10954. for (i = 0; i < len; i++) {
  10955. CacheManger._cacheList[i].tryDispose(true);
  10956. }
  10957. }
  10958. static beginCheck(waitTime = 15000) {
  10959. ILaya.systemTimer.loop(waitTime, null, CacheManger._checkLoop);
  10960. }
  10961. static stopCheck() {
  10962. ILaya.systemTimer.clear(null, CacheManger._checkLoop);
  10963. }
  10964. static _checkLoop() {
  10965. var cacheList = CacheManger._cacheList;
  10966. if (cacheList.length < 1)
  10967. return;
  10968. var tTime = ILaya.Browser.now();
  10969. var count;
  10970. var len;
  10971. len = count = cacheList.length;
  10972. while (count > 0) {
  10973. CacheManger._index++;
  10974. CacheManger._index = CacheManger._index % len;
  10975. cacheList[CacheManger._index].tryDispose(false);
  10976. if (ILaya.Browser.now() - tTime > CacheManger.loopTimeLimit)
  10977. break;
  10978. count--;
  10979. }
  10980. }
  10981. }
  10982. CacheManger.loopTimeLimit = 2;
  10983. CacheManger._cacheList = [];
  10984. CacheManger._index = 0;
  10985. class VectorGraphManager {
  10986. constructor() {
  10987. this.useDic = {};
  10988. this.shapeDic = {};
  10989. this.shapeLineDic = {};
  10990. this._id = 0;
  10991. this._checkKey = false;
  10992. this._freeIdArray = [];
  10993. CacheManger.regCacheByFunction(this.startDispose.bind(this), this.getCacheList.bind(this));
  10994. }
  10995. static getInstance() {
  10996. return VectorGraphManager.instance = VectorGraphManager.instance || new VectorGraphManager();
  10997. }
  10998. getId() {
  10999. return this._id++;
  11000. }
  11001. addShape(id, shape) {
  11002. this.shapeDic[id] = shape;
  11003. if (!this.useDic[id]) {
  11004. this.useDic[id] = true;
  11005. }
  11006. }
  11007. addLine(id, Line) {
  11008. this.shapeLineDic[id] = Line;
  11009. if (!this.shapeLineDic[id]) {
  11010. this.shapeLineDic[id] = true;
  11011. }
  11012. }
  11013. getShape(id) {
  11014. if (this._checkKey) {
  11015. if (this.useDic[id] != null) {
  11016. this.useDic[id] = true;
  11017. }
  11018. }
  11019. }
  11020. deleteShape(id) {
  11021. if (this.shapeDic[id]) {
  11022. this.shapeDic[id] = null;
  11023. delete this.shapeDic[id];
  11024. }
  11025. if (this.shapeLineDic[id]) {
  11026. this.shapeLineDic[id] = null;
  11027. delete this.shapeLineDic[id];
  11028. }
  11029. if (this.useDic[id] != null) {
  11030. delete this.useDic[id];
  11031. }
  11032. }
  11033. getCacheList() {
  11034. var str;
  11035. var list = [];
  11036. for (str in this.shapeDic) {
  11037. list.push(this.shapeDic[str]);
  11038. }
  11039. for (str in this.shapeLineDic) {
  11040. list.push(this.shapeLineDic[str]);
  11041. }
  11042. return list;
  11043. }
  11044. startDispose(key) {
  11045. var str;
  11046. for (str in this.useDic) {
  11047. this.useDic[str] = false;
  11048. }
  11049. this._checkKey = true;
  11050. }
  11051. endDispose() {
  11052. if (this._checkKey) {
  11053. var str;
  11054. for (str in this.useDic) {
  11055. if (!this.useDic[str]) {
  11056. this.deleteShape(str);
  11057. }
  11058. }
  11059. this._checkKey = false;
  11060. }
  11061. }
  11062. }
  11063. class Graphics {
  11064. constructor() {
  11065. this._sp = null;
  11066. this._one = null;
  11067. this._render = this._renderEmpty;
  11068. this._cmds = null;
  11069. this._vectorgraphArray = null;
  11070. this._graphicBounds = null;
  11071. this.autoDestroy = false;
  11072. this._createData();
  11073. }
  11074. _createData() {
  11075. }
  11076. _clearData() {
  11077. }
  11078. _destroyData() {
  11079. }
  11080. destroy() {
  11081. this.clear(true);
  11082. if (this._graphicBounds)
  11083. this._graphicBounds.destroy();
  11084. this._graphicBounds = null;
  11085. this._vectorgraphArray = null;
  11086. if (this._sp) {
  11087. this._sp._renderType = 0;
  11088. this._sp._setRenderType(0);
  11089. this._sp = null;
  11090. }
  11091. this._destroyData();
  11092. }
  11093. clear(recoverCmds = true) {
  11094. if (recoverCmds) {
  11095. var tCmd = this._one;
  11096. if (this._cmds) {
  11097. var i, len = this._cmds.length;
  11098. for (i = 0; i < len; i++) {
  11099. tCmd = this._cmds[i];
  11100. tCmd.recover();
  11101. }
  11102. this._cmds.length = 0;
  11103. }
  11104. else if (tCmd) {
  11105. tCmd.recover();
  11106. }
  11107. }
  11108. else {
  11109. this._cmds = null;
  11110. }
  11111. this._one = null;
  11112. this._render = this._renderEmpty;
  11113. this._clearData();
  11114. if (this._sp) {
  11115. this._sp._renderType &= ~SpriteConst.GRAPHICS;
  11116. this._sp._setRenderType(this._sp._renderType);
  11117. }
  11118. this._repaint();
  11119. if (this._vectorgraphArray) {
  11120. for (i = 0, len = this._vectorgraphArray.length; i < len; i++) {
  11121. VectorGraphManager.getInstance().deleteShape(this._vectorgraphArray[i]);
  11122. }
  11123. this._vectorgraphArray.length = 0;
  11124. }
  11125. }
  11126. _clearBoundsCache() {
  11127. if (this._graphicBounds)
  11128. this._graphicBounds.reset();
  11129. }
  11130. _initGraphicBounds() {
  11131. if (!this._graphicBounds) {
  11132. this._graphicBounds = GraphicsBounds.create();
  11133. this._graphicBounds._graphics = this;
  11134. }
  11135. }
  11136. _repaint() {
  11137. this._clearBoundsCache();
  11138. this._sp && this._sp.repaint();
  11139. }
  11140. _isOnlyOne() {
  11141. return !this._cmds || this._cmds.length === 0;
  11142. }
  11143. get cmds() {
  11144. return this._cmds;
  11145. }
  11146. set cmds(value) {
  11147. if (this._sp) {
  11148. this._sp._renderType |= SpriteConst.GRAPHICS;
  11149. this._sp._setRenderType(this._sp._renderType);
  11150. }
  11151. this._cmds = value;
  11152. this._render = this._renderAll;
  11153. this._repaint();
  11154. }
  11155. getBounds(realSize = false) {
  11156. this._initGraphicBounds();
  11157. return this._graphicBounds.getBounds(realSize);
  11158. }
  11159. getBoundPoints(realSize = false) {
  11160. this._initGraphicBounds();
  11161. return this._graphicBounds.getBoundPoints(realSize);
  11162. }
  11163. drawImage(texture, x = 0, y = 0, width = 0, height = 0) {
  11164. if (!texture)
  11165. return null;
  11166. if (!width)
  11167. width = texture.sourceWidth;
  11168. if (!height)
  11169. height = texture.sourceHeight;
  11170. if (texture.getIsReady()) {
  11171. var wRate = width / texture.sourceWidth;
  11172. var hRate = height / texture.sourceHeight;
  11173. width = texture.width * wRate;
  11174. height = texture.height * hRate;
  11175. if (width <= 0 || height <= 0)
  11176. return null;
  11177. x += texture.offsetX * wRate;
  11178. y += texture.offsetY * hRate;
  11179. }
  11180. if (this._sp) {
  11181. this._sp._renderType |= SpriteConst.GRAPHICS;
  11182. this._sp._setRenderType(this._sp._renderType);
  11183. }
  11184. var args = DrawImageCmd.create.call(this, texture, x, y, width, height);
  11185. if (this._one == null) {
  11186. this._one = args;
  11187. this._render = this._renderOneImg;
  11188. }
  11189. else {
  11190. this._saveToCmd(null, args);
  11191. }
  11192. this._repaint();
  11193. return args;
  11194. }
  11195. drawTexture(texture, x = 0, y = 0, width = 0, height = 0, matrix = null, alpha = 1, color = null, blendMode = null, uv) {
  11196. if (!texture || alpha < 0.01)
  11197. return null;
  11198. if (!texture.getIsReady())
  11199. return null;
  11200. if (!width)
  11201. width = texture.sourceWidth;
  11202. if (!height)
  11203. height = texture.sourceHeight;
  11204. if (texture.getIsReady()) {
  11205. var wRate = width / texture.sourceWidth;
  11206. var hRate = height / texture.sourceHeight;
  11207. width = texture.width * wRate;
  11208. height = texture.height * hRate;
  11209. if (width <= 0 || height <= 0)
  11210. return null;
  11211. x += texture.offsetX * wRate;
  11212. y += texture.offsetY * hRate;
  11213. }
  11214. if (this._sp) {
  11215. this._sp._renderType |= SpriteConst.GRAPHICS;
  11216. this._sp._setRenderType(this._sp._renderType);
  11217. }
  11218. var args = DrawTextureCmd.create.call(this, texture, x, y, width, height, matrix, alpha, color, blendMode, uv);
  11219. this._repaint();
  11220. return this._saveToCmd(null, args);
  11221. }
  11222. drawTextures(texture, pos) {
  11223. if (!texture)
  11224. return null;
  11225. return this._saveToCmd(Render._context.drawTextures, DrawTexturesCmd.create.call(this, texture, pos));
  11226. }
  11227. drawTriangles(texture, x, y, vertices, uvs, indices, matrix = null, alpha = 1, color = null, blendMode = null) {
  11228. return this._saveToCmd(Render._context.drawTriangles, DrawTrianglesCmd.create.call(this, texture, x, y, vertices, uvs, indices, matrix, alpha, color, blendMode));
  11229. }
  11230. fillTexture(texture, x, y, width = 0, height = 0, type = "repeat", offset = null) {
  11231. if (texture && texture.getIsReady())
  11232. return this._saveToCmd(Render._context._fillTexture, FillTextureCmd.create.call(this, texture, x, y, width, height, type, offset || Point.EMPTY, {}));
  11233. else
  11234. return null;
  11235. }
  11236. _saveToCmd(fun, args) {
  11237. if (this._sp) {
  11238. this._sp._renderType |= SpriteConst.GRAPHICS;
  11239. this._sp._setRenderType(this._sp._renderType);
  11240. }
  11241. if (this._one == null) {
  11242. this._one = args;
  11243. this._render = this._renderOne;
  11244. }
  11245. else {
  11246. this._render = this._renderAll;
  11247. (this._cmds || (this._cmds = [])).length === 0 && this._cmds.push(this._one);
  11248. this._cmds.push(args);
  11249. }
  11250. this._repaint();
  11251. return args;
  11252. }
  11253. clipRect(x, y, width, height) {
  11254. return this._saveToCmd(Render._context.clipRect, ClipRectCmd.create.call(this, x, y, width, height));
  11255. }
  11256. fillText(text, x, y, font, color, textAlign) {
  11257. return this._saveToCmd(Render._context.fillText, FillTextCmd.create.call(this, text, x, y, font || ILaya.Text.defaultFontStr(), color, textAlign));
  11258. }
  11259. fillBorderText(text, x, y, font, fillColor, borderColor, lineWidth, textAlign) {
  11260. return this._saveToCmd(Render._context.fillBorderText, FillBorderTextCmd.create.call(this, text, x, y, font || ILaya.Text.defaultFontStr(), fillColor, borderColor, lineWidth, textAlign));
  11261. }
  11262. fillWords(words, x, y, font, color) {
  11263. return this._saveToCmd(Render._context.fillWords, FillWordsCmd.create.call(this, words, x, y, font || ILaya.Text.defaultFontStr(), color));
  11264. }
  11265. fillBorderWords(words, x, y, font, fillColor, borderColor, lineWidth) {
  11266. return this._saveToCmd(Render._context.fillBorderWords, FillBorderWordsCmd.create.call(this, words, x, y, font || ILaya.Text.defaultFontStr(), fillColor, borderColor, lineWidth));
  11267. }
  11268. strokeText(text, x, y, font, color, lineWidth, textAlign) {
  11269. return this._saveToCmd(Render._context.fillBorderText, StrokeTextCmd.create.call(this, text, x, y, font || ILaya.Text.defaultFontStr(), color, lineWidth, textAlign));
  11270. }
  11271. alpha(alpha) {
  11272. return this._saveToCmd(Render._context.alpha, AlphaCmd.create.call(this, alpha));
  11273. }
  11274. transform(matrix, pivotX = 0, pivotY = 0) {
  11275. return this._saveToCmd(Render._context._transform, TransformCmd.create.call(this, matrix, pivotX, pivotY));
  11276. }
  11277. rotate(angle, pivotX = 0, pivotY = 0) {
  11278. return this._saveToCmd(Render._context._rotate, RotateCmd.create.call(this, angle, pivotX, pivotY));
  11279. }
  11280. scale(scaleX, scaleY, pivotX = 0, pivotY = 0) {
  11281. return this._saveToCmd(Render._context._scale, ScaleCmd.create.call(this, scaleX, scaleY, pivotX, pivotY));
  11282. }
  11283. translate(tx, ty) {
  11284. return this._saveToCmd(Render._context.translate, TranslateCmd.create.call(this, tx, ty));
  11285. }
  11286. save() {
  11287. return this._saveToCmd(Render._context._save, SaveCmd.create.call(this));
  11288. }
  11289. restore() {
  11290. return this._saveToCmd(Render._context.restore, RestoreCmd.create.call(this));
  11291. }
  11292. replaceText(text) {
  11293. this._repaint();
  11294. var cmds = this._cmds;
  11295. if (!cmds) {
  11296. if (this._one && this._isTextCmd(this._one)) {
  11297. this._one.text = text;
  11298. return true;
  11299. }
  11300. }
  11301. else {
  11302. for (var i = cmds.length - 1; i > -1; i--) {
  11303. if (this._isTextCmd(cmds[i])) {
  11304. cmds[i].text = text;
  11305. return true;
  11306. }
  11307. }
  11308. }
  11309. return false;
  11310. }
  11311. _isTextCmd(cmd) {
  11312. var cmdID = cmd.cmdID;
  11313. return cmdID == FillTextCmd.ID || cmdID == StrokeTextCmd.ID || cmdID == FillBorderTextCmd.ID;
  11314. }
  11315. replaceTextColor(color) {
  11316. this._repaint();
  11317. var cmds = this._cmds;
  11318. if (!cmds) {
  11319. if (this._one && this._isTextCmd(this._one)) {
  11320. this._setTextCmdColor(this._one, color);
  11321. }
  11322. }
  11323. else {
  11324. for (var i = cmds.length - 1; i > -1; i--) {
  11325. if (this._isTextCmd(cmds[i])) {
  11326. this._setTextCmdColor(cmds[i], color);
  11327. }
  11328. }
  11329. }
  11330. }
  11331. _setTextCmdColor(cmdO, color) {
  11332. var cmdID = cmdO.cmdID;
  11333. switch (cmdID) {
  11334. case FillTextCmd.ID:
  11335. case StrokeTextCmd.ID:
  11336. cmdO.color = color;
  11337. break;
  11338. case FillBorderTextCmd.ID:
  11339. case FillBorderWordsCmd.ID:
  11340. case FillBorderTextCmd.ID:
  11341. cmdO.fillColor = color;
  11342. break;
  11343. }
  11344. }
  11345. loadImage(url, x = 0, y = 0, width = 0, height = 0, complete = null) {
  11346. var tex = ILaya.Loader.getRes(url);
  11347. if (!tex) {
  11348. tex = new Texture();
  11349. tex.load(url);
  11350. ILaya.Loader.cacheRes(url, tex);
  11351. tex.once(Event.READY, this, this.drawImage, [tex, x, y, width, height]);
  11352. }
  11353. else {
  11354. if (!tex.getIsReady()) {
  11355. tex.once(Event.READY, this, this.drawImage, [tex, x, y, width, height]);
  11356. }
  11357. else
  11358. this.drawImage(tex, x, y, width, height);
  11359. }
  11360. if (complete != null) {
  11361. tex.getIsReady() ? complete.call(this._sp) : tex.on(Event.READY, this._sp, complete);
  11362. }
  11363. }
  11364. _renderEmpty(sprite, context, x, y) {
  11365. }
  11366. _renderAll(sprite, context, x, y) {
  11367. var cmds = this._cmds;
  11368. for (var i = 0, n = cmds.length; i < n; i++) {
  11369. cmds[i].run(context, x, y);
  11370. }
  11371. }
  11372. _renderOne(sprite, context, x, y) {
  11373. context.sprite = sprite;
  11374. this._one.run(context, x, y);
  11375. }
  11376. _renderOneImg(sprite, context, x, y) {
  11377. context.sprite = sprite;
  11378. this._one.run(context, x, y);
  11379. }
  11380. drawLine(fromX, fromY, toX, toY, lineColor, lineWidth = 1) {
  11381. var offset = (lineWidth < 1 || lineWidth % 2 === 0) ? 0 : 0.5;
  11382. return this._saveToCmd(Render._context._drawLine, DrawLineCmd.create.call(this, fromX + offset, fromY + offset, toX + offset, toY + offset, lineColor, lineWidth, 0));
  11383. }
  11384. drawLines(x, y, points, lineColor, lineWidth = 1) {
  11385. if (!points || points.length < 4)
  11386. return null;
  11387. var offset = (lineWidth < 1 || lineWidth % 2 === 0) ? 0 : 0.5;
  11388. return this._saveToCmd(Render._context._drawLines, DrawLinesCmd.create.call(this, x + offset, y + offset, points, lineColor, lineWidth, 0));
  11389. }
  11390. drawCurves(x, y, points, lineColor, lineWidth = 1) {
  11391. return this._saveToCmd(Render._context.drawCurves, DrawCurvesCmd.create.call(this, x, y, points, lineColor, lineWidth));
  11392. }
  11393. drawRect(x, y, width, height, fillColor, lineColor = null, lineWidth = 1) {
  11394. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11395. var lineOffset = lineColor ? lineWidth : 0;
  11396. return this._saveToCmd(Render._context.drawRect, DrawRectCmd.create.call(this, x + offset, y + offset, width - lineOffset, height - lineOffset, fillColor, lineColor, lineWidth));
  11397. }
  11398. drawCircle(x, y, radius, fillColor, lineColor = null, lineWidth = 1) {
  11399. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11400. return this._saveToCmd(Render._context._drawCircle, DrawCircleCmd.create.call(this, x, y, radius - offset, fillColor, lineColor, lineWidth, 0));
  11401. }
  11402. drawPie(x, y, radius, startAngle, endAngle, fillColor, lineColor = null, lineWidth = 1) {
  11403. var offset = (lineWidth >= 1 && lineColor) ? lineWidth / 2 : 0;
  11404. var lineOffset = lineColor ? lineWidth : 0;
  11405. 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));
  11406. }
  11407. drawPoly(x, y, points, fillColor, lineColor = null, lineWidth = 1) {
  11408. var tIsConvexPolygon = false;
  11409. if (points.length > 6) {
  11410. tIsConvexPolygon = false;
  11411. }
  11412. else {
  11413. tIsConvexPolygon = true;
  11414. }
  11415. var offset = (lineWidth >= 1 && lineColor) ? (lineWidth % 2 === 0 ? 0 : 0.5) : 0;
  11416. return this._saveToCmd(Render._context._drawPoly, DrawPolyCmd.create.call(this, x + offset, y + offset, points, fillColor, lineColor, lineWidth, tIsConvexPolygon, 0));
  11417. }
  11418. drawPath(x, y, paths, brush = null, pen = null) {
  11419. return this._saveToCmd(Render._context._drawPath, DrawPathCmd.create.call(this, x, y, paths, brush, pen));
  11420. }
  11421. draw9Grid(texture, x = 0, y = 0, width = 0, height = 0, sizeGrid = null) {
  11422. this._saveToCmd(null, Draw9GridTexture.create(texture, x, y, width, height, sizeGrid));
  11423. }
  11424. }
  11425. class Const {
  11426. }
  11427. Const.NOT_ACTIVE = 0x01;
  11428. Const.ACTIVE_INHIERARCHY = 0x02;
  11429. Const.AWAKED = 0x04;
  11430. Const.NOT_READY = 0x08;
  11431. Const.DISPLAY = 0x10;
  11432. Const.HAS_ZORDER = 0x20;
  11433. Const.HAS_MOUSE = 0x40;
  11434. Const.DISPLAYED_INSTAGE = 0x80;
  11435. Const.DRAWCALL_OPTIMIZE = 0x100;
  11436. class HitArea {
  11437. contains(x, y) {
  11438. if (!HitArea._isHitGraphic(x, y, this.hit))
  11439. return false;
  11440. return !HitArea._isHitGraphic(x, y, this.unHit);
  11441. }
  11442. static _isHitGraphic(x, y, graphic) {
  11443. if (!graphic)
  11444. return false;
  11445. var cmds = graphic.cmds;
  11446. if (!cmds && graphic._one) {
  11447. cmds = HitArea._cmds;
  11448. cmds.length = 1;
  11449. cmds[0] = graphic._one;
  11450. }
  11451. if (!cmds)
  11452. return false;
  11453. var i, len;
  11454. len = cmds.length;
  11455. var cmd;
  11456. for (i = 0; i < len; i++) {
  11457. cmd = cmds[i];
  11458. if (!cmd)
  11459. continue;
  11460. switch (cmd.cmdID) {
  11461. case "Translate":
  11462. x -= cmd.tx;
  11463. y -= cmd.ty;
  11464. }
  11465. if (HitArea._isHitCmd(x, y, cmd))
  11466. return true;
  11467. }
  11468. return false;
  11469. }
  11470. static _isHitCmd(x, y, cmd) {
  11471. if (!cmd)
  11472. return false;
  11473. var rst = false;
  11474. switch (cmd.cmdID) {
  11475. case "DrawRect":
  11476. HitArea._rect.setTo(cmd.x, cmd.y, cmd.width, cmd.height);
  11477. rst = HitArea._rect.contains(x, y);
  11478. break;
  11479. case "DrawCircle":
  11480. var d;
  11481. x -= cmd.x;
  11482. y -= cmd.y;
  11483. d = x * x + y * y;
  11484. rst = d < cmd.radius * cmd.radius;
  11485. break;
  11486. case "DrawPoly":
  11487. x -= cmd.x;
  11488. y -= cmd.y;
  11489. rst = HitArea._ptInPolygon(x, y, cmd.points);
  11490. break;
  11491. }
  11492. return rst;
  11493. }
  11494. static _ptInPolygon(x, y, areaPoints) {
  11495. var p = HitArea._ptPoint;
  11496. p.setTo(x, y);
  11497. var nCross = 0;
  11498. var p1x, p1y, p2x, p2y;
  11499. var len;
  11500. len = areaPoints.length;
  11501. for (var i = 0; i < len; i += 2) {
  11502. p1x = areaPoints[i];
  11503. p1y = areaPoints[i + 1];
  11504. p2x = areaPoints[(i + 2) % len];
  11505. p2y = areaPoints[(i + 3) % len];
  11506. if (p1y == p2y)
  11507. continue;
  11508. if (p.y < Math.min(p1y, p2y))
  11509. continue;
  11510. if (p.y >= Math.max(p1y, p2y))
  11511. continue;
  11512. var tx = (p.y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x;
  11513. if (tx > p.x)
  11514. nCross++;
  11515. }
  11516. return (nCross % 2 == 1);
  11517. }
  11518. get hit() {
  11519. if (!this._hit)
  11520. this._hit = new ILaya.Graphics();
  11521. return this._hit;
  11522. }
  11523. set hit(value) {
  11524. this._hit = value;
  11525. }
  11526. get unHit() {
  11527. if (!this._unHit)
  11528. this._unHit = new ILaya.Graphics();
  11529. return this._unHit;
  11530. }
  11531. set unHit(value) {
  11532. this._unHit = value;
  11533. }
  11534. }
  11535. HitArea._cmds = [];
  11536. HitArea._rect = new Rectangle();
  11537. HitArea._ptPoint = new Point();
  11538. class ClassUtils {
  11539. static regClass(className, classDef) {
  11540. ClassUtils._classMap[className] = classDef;
  11541. }
  11542. static regShortClassName(classes) {
  11543. for (var i = 0; i < classes.length; i++) {
  11544. var classDef = classes[i];
  11545. var className = classDef.name;
  11546. ClassUtils._classMap[className] = classDef;
  11547. }
  11548. }
  11549. static getRegClass(className) {
  11550. return ClassUtils._classMap[className];
  11551. }
  11552. static getClass(className) {
  11553. var classObject = ClassUtils._classMap[className] || ClassUtils._classMap['Laya.' + className] || className;
  11554. var glaya = ILaya.Laya;
  11555. if (typeof (classObject) == 'string')
  11556. return (ILaya.__classMap[classObject] || glaya[className]);
  11557. return classObject;
  11558. }
  11559. static getInstance(className) {
  11560. var compClass = ClassUtils.getClass(className);
  11561. if (compClass)
  11562. return new compClass();
  11563. else
  11564. console.warn("[error] Undefined class:", className);
  11565. return null;
  11566. }
  11567. static createByJson(json, node = null, root = null, customHandler = null, instanceHandler = null) {
  11568. if (typeof (json) == 'string')
  11569. json = JSON.parse(json);
  11570. var props = json.props;
  11571. if (!node) {
  11572. node = instanceHandler ? instanceHandler.runWith(json) : ClassUtils.getInstance(props.runtime || json.type);
  11573. if (!node)
  11574. return null;
  11575. }
  11576. var child = json.child;
  11577. if (child) {
  11578. for (var i = 0, n = child.length; i < n; i++) {
  11579. var data = child[i];
  11580. if ((data.props.name === "render" || data.props.renderType === "render") && node["_$set_itemRender"])
  11581. node.itemRender = data;
  11582. else {
  11583. if (data.type == "Graphic") {
  11584. ClassUtils._addGraphicsToSprite(data, node);
  11585. }
  11586. else if (ClassUtils._isDrawType(data.type)) {
  11587. ClassUtils._addGraphicToSprite(data, node, true);
  11588. }
  11589. else {
  11590. var tChild = ClassUtils.createByJson(data, null, root, customHandler, instanceHandler);
  11591. if (data.type === "Script") {
  11592. if ("owner" in tChild) {
  11593. tChild["owner"] = node;
  11594. }
  11595. else if ("target" in tChild) {
  11596. tChild["target"] = node;
  11597. }
  11598. }
  11599. else if (data.props.renderType == "mask") {
  11600. node.mask = tChild;
  11601. }
  11602. else {
  11603. node.addChild(tChild);
  11604. }
  11605. }
  11606. }
  11607. }
  11608. }
  11609. if (props) {
  11610. for (var prop in props) {
  11611. var value = props[prop];
  11612. if (prop === "var" && root) {
  11613. root[value] = node;
  11614. }
  11615. else if (value instanceof Array && node[prop] instanceof Function) {
  11616. node[prop].apply(node, value);
  11617. }
  11618. else {
  11619. node[prop] = value;
  11620. }
  11621. }
  11622. }
  11623. if (customHandler && json.customProps) {
  11624. customHandler.runWith([node, json]);
  11625. }
  11626. if (node["created"])
  11627. node.created();
  11628. return node;
  11629. }
  11630. static _addGraphicsToSprite(graphicO, sprite) {
  11631. var graphics = graphicO.child;
  11632. if (!graphics || graphics.length < 1)
  11633. return;
  11634. var g = ClassUtils._getGraphicsFromSprite(graphicO, sprite);
  11635. var ox = 0;
  11636. var oy = 0;
  11637. if (graphicO.props) {
  11638. ox = ClassUtils._getObjVar(graphicO.props, "x", 0);
  11639. oy = ClassUtils._getObjVar(graphicO.props, "y", 0);
  11640. }
  11641. if (ox != 0 && oy != 0) {
  11642. g.translate(ox, oy);
  11643. }
  11644. var i, len;
  11645. len = graphics.length;
  11646. for (i = 0; i < len; i++) {
  11647. ClassUtils._addGraphicToGraphics(graphics[i], g);
  11648. }
  11649. if (ox != 0 && oy != 0) {
  11650. g.translate(-ox, -oy);
  11651. }
  11652. }
  11653. static _addGraphicToSprite(graphicO, sprite, isChild = false) {
  11654. var g = isChild ? ClassUtils._getGraphicsFromSprite(graphicO, sprite) : sprite.graphics;
  11655. ClassUtils._addGraphicToGraphics(graphicO, g);
  11656. }
  11657. static _getGraphicsFromSprite(dataO, sprite) {
  11658. if (!dataO || !dataO.props)
  11659. return sprite.graphics;
  11660. var propsName = dataO.props.renderType;
  11661. if (propsName === "hit" || propsName === "unHit") {
  11662. var hitArea = sprite._style.hitArea || (sprite.hitArea = new HitArea());
  11663. if (!hitArea[propsName]) {
  11664. hitArea[propsName] = new Graphics();
  11665. }
  11666. var g = hitArea[propsName];
  11667. }
  11668. if (!g)
  11669. g = sprite.graphics;
  11670. return g;
  11671. }
  11672. static _getTransformData(propsO) {
  11673. var m;
  11674. if ("pivotX" in propsO || "pivotY" in propsO) {
  11675. m = m || new Matrix();
  11676. m.translate(-ClassUtils._getObjVar(propsO, "pivotX", 0), -ClassUtils._getObjVar(propsO, "pivotY", 0));
  11677. }
  11678. var sx = ClassUtils._getObjVar(propsO, "scaleX", 1), sy = ClassUtils._getObjVar(propsO, "scaleY", 1);
  11679. var rotate = ClassUtils._getObjVar(propsO, "rotation", 0);
  11680. var skewX = ClassUtils._getObjVar(propsO, "skewX", 0);
  11681. var skewY = ClassUtils._getObjVar(propsO, "skewY", 0);
  11682. if (sx != 1 || sy != 1 || rotate != 0) {
  11683. m = m || new Matrix();
  11684. m.scale(sx, sy);
  11685. m.rotate(rotate * 0.0174532922222222);
  11686. }
  11687. return m;
  11688. }
  11689. static _addGraphicToGraphics(graphicO, graphic) {
  11690. var propsO;
  11691. propsO = graphicO.props;
  11692. if (!propsO)
  11693. return;
  11694. var drawConfig;
  11695. drawConfig = ClassUtils.DrawTypeDic[graphicO.type];
  11696. if (!drawConfig)
  11697. return;
  11698. var g = graphic;
  11699. var params = ClassUtils._getParams(propsO, drawConfig[1], drawConfig[2], drawConfig[3]);
  11700. var m = ClassUtils._tM;
  11701. if (m || ClassUtils._alpha != 1) {
  11702. g.save();
  11703. if (m)
  11704. g.transform(m);
  11705. if (ClassUtils._alpha != 1)
  11706. g.alpha(ClassUtils._alpha);
  11707. }
  11708. g[drawConfig[0]].apply(g, params);
  11709. if (m || ClassUtils._alpha != 1) {
  11710. g.restore();
  11711. }
  11712. }
  11713. static _adptLineData(params) {
  11714. params[2] = parseFloat(params[0]) + parseFloat(params[2]);
  11715. params[3] = parseFloat(params[1]) + parseFloat(params[3]);
  11716. return params;
  11717. }
  11718. static _adptTextureData(params) {
  11719. params[0] = ILaya.Loader.getRes(params[0]);
  11720. return params;
  11721. }
  11722. static _adptLinesData(params) {
  11723. params[2] = ClassUtils._getPointListByStr(params[2]);
  11724. return params;
  11725. }
  11726. static _isDrawType(type) {
  11727. if (type === "Image")
  11728. return false;
  11729. return type in ClassUtils.DrawTypeDic;
  11730. }
  11731. static _getParams(obj, params, xPos = 0, adptFun = null) {
  11732. var rst = ClassUtils._temParam;
  11733. rst.length = params.length;
  11734. var i, len;
  11735. len = params.length;
  11736. for (i = 0; i < len; i++) {
  11737. rst[i] = ClassUtils._getObjVar(obj, params[i][0], params[i][1]);
  11738. }
  11739. ClassUtils._alpha = ClassUtils._getObjVar(obj, "alpha", 1);
  11740. var m;
  11741. m = ClassUtils._getTransformData(obj);
  11742. if (m) {
  11743. if (!xPos)
  11744. xPos = 0;
  11745. m.translate(rst[xPos], rst[xPos + 1]);
  11746. rst[xPos] = rst[xPos + 1] = 0;
  11747. ClassUtils._tM = m;
  11748. }
  11749. else {
  11750. ClassUtils._tM = null;
  11751. }
  11752. if (adptFun && ClassUtils[adptFun]) {
  11753. rst = ClassUtils[adptFun](rst);
  11754. }
  11755. return rst;
  11756. }
  11757. static _getPointListByStr(str) {
  11758. var pointArr = str.split(",");
  11759. var i, len;
  11760. len = pointArr.length;
  11761. for (i = 0; i < len; i++) {
  11762. pointArr[i] = parseFloat(pointArr[i]);
  11763. }
  11764. return pointArr;
  11765. }
  11766. static _getObjVar(obj, key, noValue) {
  11767. if (key in obj) {
  11768. return obj[key];
  11769. }
  11770. return noValue;
  11771. }
  11772. }
  11773. 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"] };
  11774. ClassUtils._temParam = [];
  11775. ClassUtils._classMap = {};
  11776. class Node extends EventDispatcher {
  11777. constructor() {
  11778. super();
  11779. this._bits = 0;
  11780. this._children = Node.ARRAY_EMPTY;
  11781. this._extUIChild = Node.ARRAY_EMPTY;
  11782. this._parent = null;
  11783. this.name = "";
  11784. this.destroyed = false;
  11785. this.createGLBuffer();
  11786. }
  11787. createGLBuffer() {
  11788. }
  11789. _setBit(type, value) {
  11790. if (type === Const.DISPLAY) {
  11791. var preValue = this._getBit(type);
  11792. if (preValue != value)
  11793. this._updateDisplayedInstage();
  11794. }
  11795. if (value)
  11796. this._bits |= type;
  11797. else
  11798. this._bits &= ~type;
  11799. }
  11800. _getBit(type) {
  11801. return (this._bits & type) != 0;
  11802. }
  11803. _setUpNoticeChain() {
  11804. if (this._getBit(Const.DISPLAY))
  11805. this._setBitUp(Const.DISPLAY);
  11806. }
  11807. _setBitUp(type) {
  11808. var ele = this;
  11809. ele._setBit(type, true);
  11810. ele = ele._parent;
  11811. while (ele) {
  11812. if (ele._getBit(type))
  11813. return;
  11814. ele._setBit(type, true);
  11815. ele = ele._parent;
  11816. }
  11817. }
  11818. on(type, caller, listener, args = null) {
  11819. if (type === Event.DISPLAY || type === Event.UNDISPLAY) {
  11820. if (!this._getBit(Const.DISPLAY))
  11821. this._setBitUp(Const.DISPLAY);
  11822. }
  11823. return this._createListener(type, caller, listener, args, false);
  11824. }
  11825. once(type, caller, listener, args = null) {
  11826. if (type === Event.DISPLAY || type === Event.UNDISPLAY) {
  11827. if (!this._getBit(Const.DISPLAY))
  11828. this._setBitUp(Const.DISPLAY);
  11829. }
  11830. return this._createListener(type, caller, listener, args, true);
  11831. }
  11832. destroy(destroyChild = true) {
  11833. this.destroyed = true;
  11834. this._destroyAllComponent();
  11835. this._parent && this._parent.removeChild(this);
  11836. if (this._children) {
  11837. if (destroyChild)
  11838. this.destroyChildren();
  11839. else
  11840. this.removeChildren();
  11841. }
  11842. this.onDestroy();
  11843. this._children = null;
  11844. this.offAll();
  11845. }
  11846. onDestroy() {
  11847. }
  11848. destroyChildren() {
  11849. if (this._children) {
  11850. for (var i = 0, n = this._children.length; i < n; i++) {
  11851. this._children[0].destroy(true);
  11852. }
  11853. }
  11854. }
  11855. addChild(node) {
  11856. if (!node || this.destroyed || node === this)
  11857. return node;
  11858. if (node._zOrder)
  11859. this._setBit(Const.HAS_ZORDER, true);
  11860. if (node._parent === this) {
  11861. var index = this.getChildIndex(node);
  11862. if (index !== this._children.length - 1) {
  11863. this._children.splice(index, 1);
  11864. this._children.push(node);
  11865. this._childChanged();
  11866. }
  11867. }
  11868. else {
  11869. node._parent && node._parent.removeChild(node);
  11870. this._children === Node.ARRAY_EMPTY && (this._children = []);
  11871. this._children.push(node);
  11872. node._setParent(this);
  11873. this._childChanged();
  11874. }
  11875. return node;
  11876. }
  11877. addInputChild(node) {
  11878. if (this._extUIChild == Node.ARRAY_EMPTY) {
  11879. this._extUIChild = [node];
  11880. }
  11881. else {
  11882. if (this._extUIChild.indexOf(node) >= 0) {
  11883. return null;
  11884. }
  11885. this._extUIChild.push(node);
  11886. }
  11887. return null;
  11888. }
  11889. removeInputChild(node) {
  11890. var idx = this._extUIChild.indexOf(node);
  11891. if (idx >= 0) {
  11892. this._extUIChild.splice(idx, 1);
  11893. }
  11894. }
  11895. addChildren(...args) {
  11896. var i = 0, n = args.length;
  11897. while (i < n) {
  11898. this.addChild(args[i++]);
  11899. }
  11900. }
  11901. addChildAt(node, index) {
  11902. if (!node || this.destroyed || node === this)
  11903. return node;
  11904. if (node._zOrder)
  11905. this._setBit(Const.HAS_ZORDER, true);
  11906. if (index >= 0 && index <= this._children.length) {
  11907. if (node._parent === this) {
  11908. var oldIndex = this.getChildIndex(node);
  11909. this._children.splice(oldIndex, 1);
  11910. this._children.splice(index, 0, node);
  11911. this._childChanged();
  11912. }
  11913. else {
  11914. node._parent && node._parent.removeChild(node);
  11915. this._children === Node.ARRAY_EMPTY && (this._children = []);
  11916. this._children.splice(index, 0, node);
  11917. node._setParent(this);
  11918. }
  11919. return node;
  11920. }
  11921. else {
  11922. throw new Error("appendChildAt:The index is out of bounds");
  11923. }
  11924. }
  11925. getChildIndex(node) {
  11926. return this._children.indexOf(node);
  11927. }
  11928. getChildByName(name) {
  11929. var nodes = this._children;
  11930. if (nodes) {
  11931. for (var i = 0, n = nodes.length; i < n; i++) {
  11932. var node = nodes[i];
  11933. if (node.name === name)
  11934. return node;
  11935. }
  11936. }
  11937. return null;
  11938. }
  11939. getChildAt(index) {
  11940. return this._children[index] || null;
  11941. }
  11942. setChildIndex(node, index) {
  11943. var childs = this._children;
  11944. if (index < 0 || index >= childs.length) {
  11945. throw new Error("setChildIndex:The index is out of bounds.");
  11946. }
  11947. var oldIndex = this.getChildIndex(node);
  11948. if (oldIndex < 0)
  11949. throw new Error("setChildIndex:node is must child of this object.");
  11950. childs.splice(oldIndex, 1);
  11951. childs.splice(index, 0, node);
  11952. this._childChanged();
  11953. return node;
  11954. }
  11955. _childChanged(child = null) {
  11956. }
  11957. removeChild(node) {
  11958. if (!this._children)
  11959. return node;
  11960. var index = this._children.indexOf(node);
  11961. return this.removeChildAt(index);
  11962. }
  11963. removeSelf() {
  11964. this._parent && this._parent.removeChild(this);
  11965. return this;
  11966. }
  11967. removeChildByName(name) {
  11968. var node = this.getChildByName(name);
  11969. node && this.removeChild(node);
  11970. return node;
  11971. }
  11972. removeChildAt(index) {
  11973. var node = this.getChildAt(index);
  11974. if (node) {
  11975. this._children.splice(index, 1);
  11976. node._setParent(null);
  11977. }
  11978. return node;
  11979. }
  11980. removeChildren(beginIndex = 0, endIndex = 0x7fffffff) {
  11981. if (this._children && this._children.length > 0) {
  11982. var childs = this._children;
  11983. if (beginIndex === 0 && endIndex >= childs.length - 1) {
  11984. var arr = childs;
  11985. this._children = Node.ARRAY_EMPTY;
  11986. }
  11987. else {
  11988. arr = childs.splice(beginIndex, endIndex - beginIndex);
  11989. }
  11990. for (var i = 0, n = arr.length; i < n; i++) {
  11991. arr[i]._setParent(null);
  11992. }
  11993. }
  11994. return this;
  11995. }
  11996. replaceChild(newNode, oldNode) {
  11997. var index = this._children.indexOf(oldNode);
  11998. if (index > -1) {
  11999. this._children.splice(index, 1, newNode);
  12000. oldNode._setParent(null);
  12001. newNode._setParent(this);
  12002. return newNode;
  12003. }
  12004. return null;
  12005. }
  12006. get numChildren() {
  12007. return this._children.length;
  12008. }
  12009. get parent() {
  12010. return this._parent;
  12011. }
  12012. _setParent(value) {
  12013. if (this._parent !== value) {
  12014. if (value) {
  12015. this._parent = value;
  12016. this._onAdded();
  12017. this.event(Event.ADDED);
  12018. if (this._getBit(Const.DISPLAY)) {
  12019. this._setUpNoticeChain();
  12020. value.displayedInStage && this._displayChild(this, true);
  12021. }
  12022. value._childChanged(this);
  12023. }
  12024. else {
  12025. this._onRemoved();
  12026. this.event(Event.REMOVED);
  12027. this._parent._childChanged();
  12028. if (this._getBit(Const.DISPLAY))
  12029. this._displayChild(this, false);
  12030. this._parent = value;
  12031. }
  12032. }
  12033. }
  12034. get displayedInStage() {
  12035. if (this._getBit(Const.DISPLAY))
  12036. return this._getBit(Const.DISPLAYED_INSTAGE);
  12037. this._setBitUp(Const.DISPLAY);
  12038. return this._getBit(Const.DISPLAYED_INSTAGE);
  12039. }
  12040. _updateDisplayedInstage() {
  12041. var ele;
  12042. ele = this;
  12043. var stage = ILaya.stage;
  12044. var displayedInStage = false;
  12045. while (ele) {
  12046. if (ele._getBit(Const.DISPLAY)) {
  12047. displayedInStage = ele._getBit(Const.DISPLAYED_INSTAGE);
  12048. break;
  12049. }
  12050. if (ele === stage || ele._getBit(Const.DISPLAYED_INSTAGE)) {
  12051. displayedInStage = true;
  12052. break;
  12053. }
  12054. ele = ele._parent;
  12055. }
  12056. this._setBit(Const.DISPLAYED_INSTAGE, displayedInStage);
  12057. }
  12058. _setDisplay(value) {
  12059. if (this._getBit(Const.DISPLAYED_INSTAGE) !== value) {
  12060. this._setBit(Const.DISPLAYED_INSTAGE, value);
  12061. if (value)
  12062. this.event(Event.DISPLAY);
  12063. else
  12064. this.event(Event.UNDISPLAY);
  12065. }
  12066. }
  12067. _displayChild(node, display) {
  12068. var childs = node._children;
  12069. if (childs) {
  12070. for (var i = 0, n = childs.length; i < n; i++) {
  12071. var child = childs[i];
  12072. if (!child._getBit(Const.DISPLAY))
  12073. continue;
  12074. if (child._children.length > 0) {
  12075. this._displayChild(child, display);
  12076. }
  12077. else {
  12078. child._setDisplay(display);
  12079. }
  12080. }
  12081. }
  12082. node._setDisplay(display);
  12083. }
  12084. contains(node) {
  12085. if (node === this)
  12086. return true;
  12087. while (node) {
  12088. if (node._parent === this)
  12089. return true;
  12090. node = node._parent;
  12091. }
  12092. return false;
  12093. }
  12094. timerLoop(delay, caller, method, args = null, coverBefore = true, jumpFrame = false) {
  12095. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12096. timer.loop(delay, caller, method, args, coverBefore, jumpFrame);
  12097. }
  12098. timerOnce(delay, caller, method, args = null, coverBefore = true) {
  12099. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12100. timer._create(false, false, delay, caller, method, args, coverBefore);
  12101. }
  12102. frameLoop(delay, caller, method, args = null, coverBefore = true) {
  12103. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12104. timer._create(true, true, delay, caller, method, args, coverBefore);
  12105. }
  12106. frameOnce(delay, caller, method, args = null, coverBefore = true) {
  12107. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12108. timer._create(true, false, delay, caller, method, args, coverBefore);
  12109. }
  12110. clearTimer(caller, method) {
  12111. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12112. timer.clear(caller, method);
  12113. }
  12114. callLater(method, args = null) {
  12115. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12116. timer.callLater(this, method, args);
  12117. }
  12118. runCallLater(method) {
  12119. var timer = this.scene ? this.scene.timer : ILaya.timer;
  12120. timer.runCallLater(this, method);
  12121. }
  12122. get scene() {
  12123. return this._scene;
  12124. }
  12125. get active() {
  12126. return !this._getBit(Const.NOT_READY) && !this._getBit(Const.NOT_ACTIVE);
  12127. }
  12128. set active(value) {
  12129. value = !!value;
  12130. if (!this._getBit(Const.NOT_ACTIVE) !== value) {
  12131. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  12132. if (value)
  12133. 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.";
  12134. else
  12135. 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.";
  12136. }
  12137. else {
  12138. this._setBit(Const.NOT_ACTIVE, !value);
  12139. if (this._parent) {
  12140. if (this._parent.activeInHierarchy) {
  12141. if (value)
  12142. this._processActive();
  12143. else
  12144. this._processInActive();
  12145. }
  12146. }
  12147. }
  12148. }
  12149. }
  12150. get activeInHierarchy() {
  12151. return this._getBit(Const.ACTIVE_INHIERARCHY);
  12152. }
  12153. _onActive() {
  12154. Stat.spriteCount++;
  12155. }
  12156. _onInActive() {
  12157. Stat.spriteCount--;
  12158. }
  12159. _onActiveInScene() {
  12160. }
  12161. _onInActiveInScene() {
  12162. }
  12163. _parse(data, spriteMap) {
  12164. }
  12165. _setBelongScene(scene) {
  12166. if (!this._scene) {
  12167. this._scene = scene;
  12168. this._onActiveInScene();
  12169. for (var i = 0, n = this._children.length; i < n; i++)
  12170. this._children[i]._setBelongScene(scene);
  12171. }
  12172. }
  12173. _setUnBelongScene() {
  12174. if (this._scene !== this) {
  12175. this._onInActiveInScene();
  12176. this._scene = null;
  12177. for (var i = 0, n = this._children.length; i < n; i++)
  12178. this._children[i]._setUnBelongScene();
  12179. }
  12180. }
  12181. onAwake() {
  12182. }
  12183. onEnable() {
  12184. }
  12185. _processActive() {
  12186. (this._activeChangeScripts) || (this._activeChangeScripts = []);
  12187. this._activeHierarchy(this._activeChangeScripts);
  12188. this._activeScripts();
  12189. }
  12190. _activeHierarchy(activeChangeScripts) {
  12191. this._setBit(Const.ACTIVE_INHIERARCHY, true);
  12192. if (this._components) {
  12193. for (var i = 0, n = this._components.length; i < n; i++) {
  12194. var comp = this._components[i];
  12195. comp._setActive(true);
  12196. (comp._isScript() && comp._enabled) && (activeChangeScripts.push(comp));
  12197. }
  12198. }
  12199. this._onActive();
  12200. for (i = 0, n = this._children.length; i < n; i++) {
  12201. var child = this._children[i];
  12202. (!child._getBit(Const.NOT_ACTIVE)) && (child._activeHierarchy(activeChangeScripts));
  12203. }
  12204. if (!this._getBit(Const.AWAKED)) {
  12205. this._setBit(Const.AWAKED, true);
  12206. this.onAwake();
  12207. }
  12208. this.onEnable();
  12209. }
  12210. _activeScripts() {
  12211. for (var i = 0, n = this._activeChangeScripts.length; i < n; i++)
  12212. this._activeChangeScripts[i].onEnable();
  12213. this._activeChangeScripts.length = 0;
  12214. }
  12215. _processInActive() {
  12216. (this._activeChangeScripts) || (this._activeChangeScripts = []);
  12217. this._inActiveHierarchy(this._activeChangeScripts);
  12218. this._inActiveScripts();
  12219. }
  12220. _inActiveHierarchy(activeChangeScripts) {
  12221. this._onInActive();
  12222. if (this._components) {
  12223. for (var i = 0, n = this._components.length; i < n; i++) {
  12224. var comp = this._components[i];
  12225. comp._setActive(false);
  12226. (comp._isScript() && comp._enabled) && (activeChangeScripts.push(comp));
  12227. }
  12228. }
  12229. this._setBit(Const.ACTIVE_INHIERARCHY, false);
  12230. for (i = 0, n = this._children.length; i < n; i++) {
  12231. var child = this._children[i];
  12232. (child && !child._getBit(Const.NOT_ACTIVE)) && (child._inActiveHierarchy(activeChangeScripts));
  12233. }
  12234. this.onDisable();
  12235. }
  12236. _inActiveScripts() {
  12237. for (var i = 0, n = this._activeChangeScripts.length; i < n; i++)
  12238. this._activeChangeScripts[i].onDisable();
  12239. this._activeChangeScripts.length = 0;
  12240. }
  12241. onDisable() {
  12242. }
  12243. _onAdded() {
  12244. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  12245. 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.";
  12246. }
  12247. else {
  12248. var parentScene = this._parent.scene;
  12249. parentScene && this._setBelongScene(parentScene);
  12250. (this._parent.activeInHierarchy && this.active) && this._processActive();
  12251. }
  12252. }
  12253. _onRemoved() {
  12254. if (this._activeChangeScripts && this._activeChangeScripts.length !== 0) {
  12255. 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.";
  12256. }
  12257. else {
  12258. (this._parent.activeInHierarchy && this.active) && this._processInActive();
  12259. this._parent.scene && this._setUnBelongScene();
  12260. }
  12261. }
  12262. _addComponentInstance(comp) {
  12263. this._components = this._components || [];
  12264. this._components.push(comp);
  12265. comp.owner = this;
  12266. comp._onAdded();
  12267. if (this.activeInHierarchy) {
  12268. comp._setActive(true);
  12269. (comp._isScript() && comp._enabled) && (comp.onEnable());
  12270. }
  12271. }
  12272. _destroyComponent(comp) {
  12273. if (this._components) {
  12274. for (var i = 0, n = this._components.length; i < n; i++) {
  12275. var item = this._components[i];
  12276. if (item === comp) {
  12277. item._destroy();
  12278. this._components.splice(i, 1);
  12279. break;
  12280. }
  12281. }
  12282. }
  12283. }
  12284. _destroyAllComponent() {
  12285. if (this._components) {
  12286. for (var i = 0, n = this._components.length; i < n; i++) {
  12287. var item = this._components[i];
  12288. item._destroy();
  12289. }
  12290. this._components.length = 0;
  12291. }
  12292. }
  12293. _cloneTo(destObject, srcRoot, dstRoot) {
  12294. var destNode = destObject;
  12295. if (this._components) {
  12296. for (var i = 0, n = this._components.length; i < n; i++) {
  12297. var destComponent = destNode.addComponent(this._components[i].constructor);
  12298. this._components[i]._cloneTo(destComponent);
  12299. }
  12300. }
  12301. }
  12302. addComponentIntance(comp) {
  12303. if (comp.owner)
  12304. throw "Node:the component has belong to other node.";
  12305. if (comp.isSingleton && this.getComponent(comp.constructor))
  12306. throw "Node:the component is singleton,can't add the second one.";
  12307. this._addComponentInstance(comp);
  12308. return comp;
  12309. }
  12310. addComponent(type) {
  12311. var comp = Pool.createByClass(type);
  12312. comp._destroyed = false;
  12313. if (comp.isSingleton && this.getComponent(type))
  12314. throw "无法实例" + type + "组件" + "," + type + "组件已存在!";
  12315. this._addComponentInstance(comp);
  12316. return comp;
  12317. }
  12318. getComponent(clas) {
  12319. if (this._components) {
  12320. for (var i = 0, n = this._components.length; i < n; i++) {
  12321. var comp = this._components[i];
  12322. if (comp instanceof clas)
  12323. return comp;
  12324. }
  12325. }
  12326. return null;
  12327. }
  12328. getComponents(clas) {
  12329. var arr;
  12330. if (this._components) {
  12331. for (var i = 0, n = this._components.length; i < n; i++) {
  12332. var comp = this._components[i];
  12333. if (comp instanceof clas) {
  12334. arr = arr || [];
  12335. arr.push(comp);
  12336. }
  12337. }
  12338. }
  12339. return arr;
  12340. }
  12341. get timer() {
  12342. return this.scene ? this.scene.timer : ILaya.timer;
  12343. }
  12344. }
  12345. Node.ARRAY_EMPTY = [];
  12346. ClassUtils.regClass("laya.display.Node", Node);
  12347. ClassUtils.regClass("Laya.Node", Node);
  12348. class BoundsStyle {
  12349. reset() {
  12350. if (this.bounds)
  12351. this.bounds.recover();
  12352. if (this.userBounds)
  12353. this.userBounds.recover();
  12354. this.bounds = null;
  12355. this.userBounds = null;
  12356. this.temBM = null;
  12357. return this;
  12358. }
  12359. recover() {
  12360. Pool.recover("BoundsStyle", this.reset());
  12361. }
  12362. static create() {
  12363. return Pool.getItemByClass("BoundsStyle", BoundsStyle);
  12364. }
  12365. }
  12366. class HTMLCanvas extends Bitmap {
  12367. get source() {
  12368. return this._source;
  12369. }
  12370. _getSource() {
  12371. return this._source;
  12372. }
  12373. constructor(createCanvas = false) {
  12374. super();
  12375. if (createCanvas)
  12376. this._source = Browser.createElement("canvas");
  12377. else {
  12378. this._source = this;
  12379. }
  12380. this.lock = true;
  12381. }
  12382. clear() {
  12383. this._ctx && this._ctx.clear && this._ctx.clear();
  12384. if (this._texture) {
  12385. this._texture.destroy();
  12386. this._texture = null;
  12387. }
  12388. }
  12389. destroy() {
  12390. super.destroy();
  12391. this._setCPUMemory(0);
  12392. this._ctx && this._ctx.destroy && this._ctx.destroy();
  12393. this._ctx = null;
  12394. }
  12395. release() {
  12396. }
  12397. get context() {
  12398. if (this._ctx)
  12399. return this._ctx;
  12400. if (this._source == this) {
  12401. this._ctx = new ILaya.Context();
  12402. }
  12403. else {
  12404. this._ctx = this._source.getContext(ILaya.Render.isConchApp ? 'layagl' : '2d');
  12405. }
  12406. this._ctx._canvas = this;
  12407. return this._ctx;
  12408. }
  12409. _setContext(context) {
  12410. this._ctx = context;
  12411. }
  12412. getContext(contextID, other = null) {
  12413. return this.context;
  12414. }
  12415. getMemSize() {
  12416. return 0;
  12417. }
  12418. size(w, h) {
  12419. if (this._width != w || this._height != h || (this._source && (this._source.width != w || this._source.height != h))) {
  12420. this._width = w;
  12421. this._height = h;
  12422. this._setCPUMemory(w * h * 4);
  12423. this._ctx && this._ctx.size && this._ctx.size(w, h);
  12424. if (this._source) {
  12425. this._source.height = h;
  12426. this._source.width = w;
  12427. }
  12428. if (this._texture) {
  12429. this._texture.destroy();
  12430. this._texture = null;
  12431. }
  12432. }
  12433. }
  12434. getTexture() {
  12435. if (!this._texture) {
  12436. var bitmap = new Texture2D();
  12437. bitmap.loadImageSource(this.source);
  12438. this._texture = new Texture(bitmap);
  12439. }
  12440. return this._texture;
  12441. }
  12442. toBase64(type, encoderOptions) {
  12443. if (this._source) {
  12444. if (ILaya.Render.isConchApp) {
  12445. var win = window;
  12446. if (win.conchConfig.threadMode == 2) {
  12447. throw "native 2 thread mode use toBase64Async";
  12448. }
  12449. var width = this._ctx._targets.sourceWidth;
  12450. var height = this._ctx._targets.sourceHeight;
  12451. var data = this._ctx._targets.getData(0, 0, width, height);
  12452. return win.conchToBase64FlipY ? win.conchToBase64FlipY(type, encoderOptions, data.buffer, width, height) : win.conchToBase64(type, encoderOptions, data.buffer, width, height);
  12453. }
  12454. else {
  12455. return this._source.toDataURL(type, encoderOptions);
  12456. }
  12457. }
  12458. return null;
  12459. }
  12460. toBase64Async(type, encoderOptions, callBack) {
  12461. var width = this._ctx._targets.sourceWidth;
  12462. var height = this._ctx._targets.sourceHeight;
  12463. this._ctx._targets.getDataAsync(0, 0, width, height, function (data) {
  12464. let win = window;
  12465. var base64 = win.conchToBase64FlipY ? win.conchToBase64FlipY(type, encoderOptions, data.buffer, width, height) : win.conchToBase64(type, encoderOptions, data.buffer, width, height);
  12466. callBack(base64);
  12467. });
  12468. }
  12469. }
  12470. class CacheStyle {
  12471. constructor() {
  12472. this.reset();
  12473. }
  12474. needBitmapCache() {
  12475. return this.cacheForFilters || !!this.mask;
  12476. }
  12477. needEnableCanvasRender() {
  12478. return this.userSetCache != "none" || this.cacheForFilters || !!this.mask;
  12479. }
  12480. releaseContext() {
  12481. if (this.canvas && this.canvas.size) {
  12482. Pool.recover("CacheCanvas", this.canvas);
  12483. this.canvas.size(0, 0);
  12484. try {
  12485. this.canvas.width = 0;
  12486. this.canvas.height = 0;
  12487. }
  12488. catch (e) {
  12489. }
  12490. }
  12491. this.canvas = null;
  12492. }
  12493. createContext() {
  12494. if (!this.canvas) {
  12495. this.canvas = Pool.getItem("CacheCanvas") || new HTMLCanvas(false);
  12496. var tx = this.canvas.context;
  12497. if (!tx) {
  12498. tx = this.canvas.getContext('2d');
  12499. }
  12500. }
  12501. }
  12502. releaseFilterCache() {
  12503. var fc = this.filterCache;
  12504. if (fc) {
  12505. fc.destroy();
  12506. fc.recycle();
  12507. this.filterCache = null;
  12508. }
  12509. }
  12510. recover() {
  12511. if (this === CacheStyle.EMPTY)
  12512. return;
  12513. Pool.recover("SpriteCache", this.reset());
  12514. }
  12515. reset() {
  12516. this.releaseContext();
  12517. this.releaseFilterCache();
  12518. this.cacheAs = "none";
  12519. this.enableCanvasRender = false;
  12520. this.userSetCache = "none";
  12521. this.cacheForFilters = false;
  12522. this.staticCache = false;
  12523. this.reCache = true;
  12524. this.mask = null;
  12525. this.maskParent = null;
  12526. this.filterCache = null;
  12527. this.filters = null;
  12528. this.hasGlowFilter = false;
  12529. if (this.cacheRect)
  12530. this.cacheRect.recover();
  12531. this.cacheRect = null;
  12532. return this;
  12533. }
  12534. static create() {
  12535. return Pool.getItemByClass("SpriteCache", CacheStyle);
  12536. }
  12537. _calculateCacheRect(sprite, tCacheType, x, y) {
  12538. var _cacheStyle = sprite._cacheStyle;
  12539. if (!_cacheStyle.cacheRect)
  12540. _cacheStyle.cacheRect = Rectangle.create();
  12541. var tRec;
  12542. if (tCacheType === "bitmap") {
  12543. tRec = sprite.getSelfBounds();
  12544. tRec.width = tRec.width + CacheStyle.CANVAS_EXTEND_EDGE * 2;
  12545. tRec.height = tRec.height + CacheStyle.CANVAS_EXTEND_EDGE * 2;
  12546. tRec.x = tRec.x - sprite.pivotX;
  12547. tRec.y = tRec.y - sprite.pivotY;
  12548. tRec.x = tRec.x - CacheStyle.CANVAS_EXTEND_EDGE;
  12549. tRec.y = tRec.y - CacheStyle.CANVAS_EXTEND_EDGE;
  12550. tRec.x = Math.floor(tRec.x + x) - x;
  12551. tRec.y = Math.floor(tRec.y + y) - y;
  12552. tRec.width = Math.floor(tRec.width);
  12553. tRec.height = Math.floor(tRec.height);
  12554. _cacheStyle.cacheRect.copyFrom(tRec);
  12555. }
  12556. else {
  12557. _cacheStyle.cacheRect.setTo(-sprite._style.pivotX, -sprite._style.pivotY, 1, 1);
  12558. }
  12559. tRec = _cacheStyle.cacheRect;
  12560. if (sprite._style.scrollRect) {
  12561. var scrollRect = sprite._style.scrollRect;
  12562. tRec.x -= scrollRect.x;
  12563. tRec.y -= scrollRect.y;
  12564. }
  12565. CacheStyle._scaleInfo.setTo(1, 1);
  12566. return CacheStyle._scaleInfo;
  12567. }
  12568. }
  12569. CacheStyle.EMPTY = new CacheStyle();
  12570. CacheStyle._scaleInfo = new Point();
  12571. CacheStyle.CANVAS_EXTEND_EDGE = 16;
  12572. class SpriteStyle {
  12573. constructor() {
  12574. this.reset();
  12575. }
  12576. reset() {
  12577. this.scaleX = this.scaleY = 1;
  12578. this.skewX = this.skewY = 0;
  12579. this.pivotX = this.pivotY = this.rotation = 0;
  12580. this.alpha = 1;
  12581. if (this.scrollRect)
  12582. this.scrollRect.recover();
  12583. this.scrollRect = null;
  12584. if (this.viewport)
  12585. this.viewport.recover();
  12586. this.viewport = null;
  12587. this.hitArea = null;
  12588. this.dragging = null;
  12589. this.blendMode = null;
  12590. return this;
  12591. }
  12592. recover() {
  12593. if (this === SpriteStyle.EMPTY)
  12594. return;
  12595. Pool.recover("SpriteStyle", this.reset());
  12596. }
  12597. static create() {
  12598. return Pool.getItemByClass("SpriteStyle", SpriteStyle);
  12599. }
  12600. }
  12601. SpriteStyle.EMPTY = new SpriteStyle();
  12602. class LayaGLQuickRunner {
  12603. static __init__() {
  12604. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TRANSFORM | SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_transform_drawLayaGL;
  12605. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.GRAPHICS] = LayaGLQuickRunner.alpha_drawLayaGL;
  12606. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.GRAPHICS] = LayaGLQuickRunner.transform_drawLayaGL;
  12607. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.CHILDS] = LayaGLQuickRunner.transform_drawNodes;
  12608. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TRANSFORM | SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_transform_drawTexture;
  12609. LayaGLQuickRunner.map[SpriteConst.ALPHA | SpriteConst.TEXTURE] = LayaGLQuickRunner.alpha_drawTexture;
  12610. LayaGLQuickRunner.map[SpriteConst.TRANSFORM | SpriteConst.TEXTURE] = LayaGLQuickRunner.transform_drawTexture;
  12611. LayaGLQuickRunner.map[SpriteConst.GRAPHICS | SpriteConst.CHILDS] = LayaGLQuickRunner.drawLayaGL_drawNodes;
  12612. }
  12613. static transform_drawTexture(sprite, context, x, y) {
  12614. var style = sprite._style;
  12615. var tex = sprite.texture;
  12616. context.saveTransform(LayaGLQuickRunner.curMat);
  12617. context.transformByMatrix(sprite.transform, x, y);
  12618. context.drawTexture(tex, -sprite.pivotX, -sprite.pivotY, sprite._width || tex.width, sprite._height || tex.height);
  12619. context.restoreTransform(LayaGLQuickRunner.curMat);
  12620. }
  12621. static alpha_drawTexture(sprite, context, x, y) {
  12622. var style = sprite._style;
  12623. var alpha;
  12624. var tex = sprite.texture;
  12625. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  12626. var temp = context.globalAlpha;
  12627. context.globalAlpha *= alpha;
  12628. context.drawTexture(tex, x - style.pivotX + tex.offsetX, y - style.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  12629. context.globalAlpha = temp;
  12630. }
  12631. }
  12632. static alpha_transform_drawTexture(sprite, context, x, y) {
  12633. var style = sprite._style;
  12634. var alpha;
  12635. var tex = sprite.texture;
  12636. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  12637. var temp = context.globalAlpha;
  12638. context.globalAlpha *= alpha;
  12639. context.saveTransform(LayaGLQuickRunner.curMat);
  12640. context.transformByMatrix(sprite.transform, x, y);
  12641. context.drawTexture(tex, -style.pivotX + tex.offsetX, -style.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  12642. context.restoreTransform(LayaGLQuickRunner.curMat);
  12643. context.globalAlpha = temp;
  12644. }
  12645. }
  12646. static alpha_transform_drawLayaGL(sprite, context, x, y) {
  12647. var style = sprite._style;
  12648. var alpha;
  12649. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  12650. var temp = context.globalAlpha;
  12651. context.globalAlpha *= alpha;
  12652. context.saveTransform(LayaGLQuickRunner.curMat);
  12653. context.transformByMatrix(sprite.transform, x, y);
  12654. sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY);
  12655. context.restoreTransform(LayaGLQuickRunner.curMat);
  12656. context.globalAlpha = temp;
  12657. }
  12658. }
  12659. static alpha_drawLayaGL(sprite, context, x, y) {
  12660. var style = sprite._style;
  12661. var alpha;
  12662. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  12663. var temp = context.globalAlpha;
  12664. context.globalAlpha *= alpha;
  12665. sprite._graphics && sprite._graphics._render(sprite, context, x - style.pivotX, y - style.pivotY);
  12666. context.globalAlpha = temp;
  12667. }
  12668. }
  12669. static transform_drawLayaGL(sprite, context, x, y) {
  12670. var style = sprite._style;
  12671. context.saveTransform(LayaGLQuickRunner.curMat);
  12672. context.transformByMatrix(sprite.transform, x, y);
  12673. sprite._graphics && sprite._graphics._render(sprite, context, -style.pivotX, -style.pivotY);
  12674. context.restoreTransform(LayaGLQuickRunner.curMat);
  12675. }
  12676. static transform_drawNodes(sprite, context, x, y) {
  12677. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  12678. var style = sprite._style;
  12679. context.saveTransform(LayaGLQuickRunner.curMat);
  12680. context.transformByMatrix(sprite.transform, x, y);
  12681. x = -style.pivotX;
  12682. y = -style.pivotY;
  12683. var childs = sprite._children, n = childs.length, ele;
  12684. if (style.viewport) {
  12685. var rect = style.viewport;
  12686. var left = rect.x;
  12687. var top = rect.y;
  12688. var right = rect.right;
  12689. var bottom = rect.bottom;
  12690. var _x, _y;
  12691. for (i = 0; i < n; ++i) {
  12692. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  12693. ele.render(context, x, y);
  12694. }
  12695. }
  12696. }
  12697. else {
  12698. for (var i = 0; i < n; ++i)
  12699. (ele = childs[i])._visible && ele.render(context, x, y);
  12700. }
  12701. context.restoreTransform(LayaGLQuickRunner.curMat);
  12702. textLastRender && context.drawCallOptimize(false);
  12703. }
  12704. static drawLayaGL_drawNodes(sprite, context, x, y) {
  12705. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  12706. var style = sprite._style;
  12707. x = x - style.pivotX;
  12708. y = y - style.pivotY;
  12709. sprite._graphics && sprite._graphics._render(sprite, context, x, y);
  12710. var childs = sprite._children, n = childs.length, ele;
  12711. if (style.viewport) {
  12712. var rect = style.viewport;
  12713. var left = rect.x;
  12714. var top = rect.y;
  12715. var right = rect.right;
  12716. var bottom = rect.bottom;
  12717. var _x, _y;
  12718. for (i = 0; i < n; ++i) {
  12719. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  12720. ele.render(context, x, y);
  12721. }
  12722. }
  12723. }
  12724. else {
  12725. for (var i = 0; i < n; ++i)
  12726. (ele = childs[i])._visible && ele.render(context, x, y);
  12727. }
  12728. textLastRender && context.drawCallOptimize(false);
  12729. }
  12730. }
  12731. LayaGLQuickRunner.map = {};
  12732. LayaGLQuickRunner.curMat = new Matrix();
  12733. class RenderSprite {
  12734. constructor(type, next) {
  12735. if (LayaGLQuickRunner.map[type]) {
  12736. this._fun = LayaGLQuickRunner.map[type];
  12737. this._next = RenderSprite.NORENDER;
  12738. return;
  12739. }
  12740. this._next = next || RenderSprite.NORENDER;
  12741. switch (type) {
  12742. case 0:
  12743. this._fun = this._no;
  12744. return;
  12745. case SpriteConst.ALPHA:
  12746. this._fun = this._alpha;
  12747. return;
  12748. case SpriteConst.TRANSFORM:
  12749. this._fun = this._transform;
  12750. return;
  12751. case SpriteConst.BLEND:
  12752. this._fun = this._blend;
  12753. return;
  12754. case SpriteConst.CANVAS:
  12755. this._fun = this._canvas;
  12756. return;
  12757. case SpriteConst.MASK:
  12758. this._fun = this._mask;
  12759. return;
  12760. case SpriteConst.CLIP:
  12761. this._fun = this._clip;
  12762. return;
  12763. case SpriteConst.STYLE:
  12764. this._fun = this._style;
  12765. return;
  12766. case SpriteConst.GRAPHICS:
  12767. this._fun = this._graphics;
  12768. return;
  12769. case SpriteConst.CHILDS:
  12770. this._fun = this._children;
  12771. return;
  12772. case SpriteConst.CUSTOM:
  12773. this._fun = this._custom;
  12774. return;
  12775. case SpriteConst.TEXTURE:
  12776. this._fun = this._texture;
  12777. return;
  12778. case SpriteConst.FILTERS:
  12779. this._fun = Filter._filter;
  12780. return;
  12781. case RenderSprite.INIT:
  12782. this._fun = RenderSprite._initRenderFun;
  12783. return;
  12784. }
  12785. this.onCreate(type);
  12786. }
  12787. static __init__() {
  12788. LayaGLQuickRunner.__init__();
  12789. var i, len;
  12790. var initRender;
  12791. initRender = new RenderSprite(RenderSprite.INIT, null);
  12792. len = RenderSprite.renders.length = SpriteConst.CHILDS * 2;
  12793. for (i = 0; i < len; i++)
  12794. RenderSprite.renders[i] = initRender;
  12795. RenderSprite.renders[0] = new RenderSprite(0, null);
  12796. }
  12797. static _initRenderFun(sprite, context, x, y) {
  12798. var type = sprite._renderType;
  12799. var r = RenderSprite.renders[type] = RenderSprite._getTypeRender(type);
  12800. r._fun(sprite, context, x, y);
  12801. }
  12802. static _getTypeRender(type) {
  12803. if (LayaGLQuickRunner.map[type])
  12804. return new RenderSprite(type, null);
  12805. var rst = null;
  12806. var tType = SpriteConst.CHILDS;
  12807. while (tType > 0) {
  12808. if (tType & type)
  12809. rst = new RenderSprite(tType, rst);
  12810. tType = tType >> 1;
  12811. }
  12812. return rst;
  12813. }
  12814. onCreate(type) {
  12815. }
  12816. _style(sprite, context, x, y) {
  12817. var style = sprite._style;
  12818. if (style.render != null)
  12819. style.render(sprite, context, x, y);
  12820. var next = this._next;
  12821. next._fun.call(next, sprite, context, x, y);
  12822. }
  12823. _no(sprite, context, x, y) {
  12824. }
  12825. _custom(sprite, context, x, y) {
  12826. sprite.customRender(context, x, y);
  12827. this._next._fun.call(this._next, sprite, context, x - sprite.pivotX, y - sprite.pivotY);
  12828. }
  12829. _clip(sprite, context, x, y) {
  12830. var next = this._next;
  12831. if (next == RenderSprite.NORENDER)
  12832. return;
  12833. var r = sprite._style.scrollRect;
  12834. context.save();
  12835. context.clipRect(x, y, r.width, r.height);
  12836. next._fun.call(next, sprite, context, x - r.x, y - r.y);
  12837. context.restore();
  12838. }
  12839. _texture(sprite, context, x, y) {
  12840. var tex = sprite.texture;
  12841. if (tex._getSource())
  12842. context.drawTexture(tex, x - sprite.pivotX + tex.offsetX, y - sprite.pivotY + tex.offsetY, sprite._width || tex.width, sprite._height || tex.height);
  12843. var next = this._next;
  12844. if (next != RenderSprite.NORENDER)
  12845. next._fun.call(next, sprite, context, x, y);
  12846. }
  12847. _graphics(sprite, context, x, y) {
  12848. var style = sprite._style;
  12849. var g = sprite._graphics;
  12850. g && g._render(sprite, context, x - style.pivotX, y - style.pivotY);
  12851. var next = this._next;
  12852. if (next != RenderSprite.NORENDER)
  12853. next._fun.call(next, sprite, context, x, y);
  12854. }
  12855. _image(sprite, context, x, y) {
  12856. var style = sprite._style;
  12857. context.drawTexture2(x, y, style.pivotX, style.pivotY, sprite.transform, sprite._graphics._one);
  12858. }
  12859. _image2(sprite, context, x, y) {
  12860. var style = sprite._style;
  12861. context.drawTexture2(x, y, style.pivotX, style.pivotY, sprite.transform, sprite._graphics._one);
  12862. }
  12863. _alpha(sprite, context, x, y) {
  12864. var style = sprite._style;
  12865. var alpha;
  12866. if ((alpha = style.alpha) > 0.01 || sprite._needRepaint()) {
  12867. var temp = context.globalAlpha;
  12868. context.globalAlpha *= alpha;
  12869. var next = this._next;
  12870. next._fun.call(next, sprite, context, x, y);
  12871. context.globalAlpha = temp;
  12872. }
  12873. }
  12874. _transform(sprite, context, x, y) {
  12875. var transform = sprite.transform, _next = this._next;
  12876. var style = sprite._style;
  12877. if (transform && _next != RenderSprite.NORENDER) {
  12878. context.save();
  12879. context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx + x, transform.ty + y);
  12880. _next._fun.call(_next, sprite, context, 0, 0);
  12881. context.restore();
  12882. }
  12883. else {
  12884. if (_next != RenderSprite.NORENDER)
  12885. _next._fun.call(_next, sprite, context, x, y);
  12886. }
  12887. }
  12888. _children(sprite, context, x, y) {
  12889. var style = sprite._style;
  12890. var childs = sprite._children, n = childs.length, ele;
  12891. x = x - sprite.pivotX;
  12892. y = y - sprite.pivotY;
  12893. var textLastRender = sprite._getBit(Const.DRAWCALL_OPTIMIZE) && context.drawCallOptimize(true);
  12894. if (style.viewport) {
  12895. var rect = style.viewport;
  12896. var left = rect.x;
  12897. var top = rect.y;
  12898. var right = rect.right;
  12899. var bottom = rect.bottom;
  12900. var _x, _y;
  12901. for (i = 0; i < n; ++i) {
  12902. if ((ele = childs[i])._visible && ((_x = ele._x) < right && (_x + ele.width) > left && (_y = ele._y) < bottom && (_y + ele.height) > top)) {
  12903. ele.render(context, x, y);
  12904. }
  12905. }
  12906. }
  12907. else {
  12908. for (var i = 0; i < n; ++i)
  12909. (ele = childs[i])._visible && ele.render(context, x, y);
  12910. }
  12911. textLastRender && context.drawCallOptimize(false);
  12912. }
  12913. _canvas(sprite, context, x, y) {
  12914. var _cacheStyle = sprite._cacheStyle;
  12915. var _next = this._next;
  12916. if (!_cacheStyle.enableCanvasRender) {
  12917. _next._fun.call(_next, sprite, context, x, y);
  12918. return;
  12919. }
  12920. _cacheStyle.cacheAs === 'bitmap' ? (Stat.canvasBitmap++) : (Stat.canvasNormal++);
  12921. var cacheNeedRebuild = false;
  12922. var textNeedRestore = false;
  12923. if (_cacheStyle.canvas) {
  12924. var canv = _cacheStyle.canvas;
  12925. var ctx = canv.context;
  12926. var charRIs = canv.touches;
  12927. if (charRIs) {
  12928. for (var ci = 0; ci < charRIs.length; ci++) {
  12929. if (charRIs[ci].deleted) {
  12930. textNeedRestore = true;
  12931. break;
  12932. }
  12933. }
  12934. }
  12935. cacheNeedRebuild = canv.isCacheValid && !canv.isCacheValid();
  12936. }
  12937. if (sprite._needRepaint() || (!_cacheStyle.canvas) || textNeedRestore || cacheNeedRebuild || ILaya.stage.isGlobalRepaint()) {
  12938. if (_cacheStyle.cacheAs === 'normal') {
  12939. if (context._targets) {
  12940. _next._fun.call(_next, sprite, context, x, y);
  12941. return;
  12942. }
  12943. else {
  12944. this._canvas_webgl_normal_repaint(sprite, context);
  12945. }
  12946. }
  12947. else {
  12948. this._canvas_repaint(sprite, context, x, y);
  12949. }
  12950. }
  12951. var tRec = _cacheStyle.cacheRect;
  12952. context.drawCanvas(_cacheStyle.canvas, x + tRec.x, y + tRec.y, tRec.width, tRec.height);
  12953. }
  12954. _canvas_repaint(sprite, context, x, y) {
  12955. var _cacheStyle = sprite._cacheStyle;
  12956. var _next = this._next;
  12957. var tx;
  12958. var canvas = _cacheStyle.canvas;
  12959. var left;
  12960. var top;
  12961. var tRec;
  12962. var tCacheType = _cacheStyle.cacheAs;
  12963. var w, h;
  12964. var scaleX, scaleY;
  12965. var scaleInfo;
  12966. scaleInfo = _cacheStyle._calculateCacheRect(sprite, tCacheType, x, y);
  12967. scaleX = scaleInfo.x;
  12968. scaleY = scaleInfo.y;
  12969. tRec = _cacheStyle.cacheRect;
  12970. w = tRec.width * scaleX;
  12971. h = tRec.height * scaleY;
  12972. left = tRec.x;
  12973. top = tRec.y;
  12974. if (tCacheType === 'bitmap' && (w > 2048 || h > 2048)) {
  12975. console.warn("cache bitmap size larger than 2048,cache ignored");
  12976. _cacheStyle.releaseContext();
  12977. _next._fun.call(_next, sprite, context, x, y);
  12978. return;
  12979. }
  12980. if (!canvas) {
  12981. _cacheStyle.createContext();
  12982. canvas = _cacheStyle.canvas;
  12983. }
  12984. tx = canvas.context;
  12985. tx.sprite = sprite;
  12986. (canvas.width != w || canvas.height != h) && canvas.size(w, h);
  12987. if (tCacheType === 'bitmap')
  12988. tx.asBitmap = true;
  12989. else if (tCacheType === 'normal')
  12990. tx.asBitmap = false;
  12991. tx.clear();
  12992. if (scaleX != 1 || scaleY != 1) {
  12993. var ctx = tx;
  12994. ctx.save();
  12995. ctx.scale(scaleX, scaleY);
  12996. _next._fun.call(_next, sprite, tx, -left, -top);
  12997. ctx.restore();
  12998. sprite._applyFilters();
  12999. }
  13000. else {
  13001. ctx = tx;
  13002. _next._fun.call(_next, sprite, tx, -left, -top);
  13003. sprite._applyFilters();
  13004. }
  13005. if (_cacheStyle.staticCache)
  13006. _cacheStyle.reCache = false;
  13007. Stat.canvasReCache++;
  13008. }
  13009. _canvas_webgl_normal_repaint(sprite, context) {
  13010. var _cacheStyle = sprite._cacheStyle;
  13011. var _next = this._next;
  13012. var canvas = _cacheStyle.canvas;
  13013. var tCacheType = _cacheStyle.cacheAs;
  13014. var scaleInfo = _cacheStyle._calculateCacheRect(sprite, tCacheType, 0, 0);
  13015. if (!canvas) {
  13016. canvas = _cacheStyle.canvas = new WebGLCacheAsNormalCanvas(context, sprite);
  13017. }
  13018. var tx = canvas.context;
  13019. canvas['startRec']();
  13020. _next._fun.call(_next, sprite, tx, sprite.pivotX, sprite.pivotY);
  13021. sprite._applyFilters();
  13022. Stat.canvasReCache++;
  13023. canvas['endRec']();
  13024. }
  13025. _blend(sprite, context, x, y) {
  13026. var style = sprite._style;
  13027. var next = this._next;
  13028. if (style.blendMode) {
  13029. context.save();
  13030. context.globalCompositeOperation = style.blendMode;
  13031. next._fun.call(next, sprite, context, x, y);
  13032. context.restore();
  13033. }
  13034. else {
  13035. next._fun.call(next, sprite, context, x, y);
  13036. }
  13037. }
  13038. _mask(sprite, context, x, y) {
  13039. var next = this._next;
  13040. var mask = sprite.mask;
  13041. var ctx = context;
  13042. if (mask) {
  13043. ctx.save();
  13044. var preBlendMode = ctx.globalCompositeOperation;
  13045. var tRect = new Rectangle();
  13046. tRect.copyFrom(mask.getBounds());
  13047. tRect.width = Math.round(tRect.width);
  13048. tRect.height = Math.round(tRect.height);
  13049. tRect.x = Math.round(tRect.x);
  13050. tRect.y = Math.round(tRect.y);
  13051. if (tRect.width > 0 && tRect.height > 0) {
  13052. var w = tRect.width;
  13053. var h = tRect.height;
  13054. var tmpRT = WebGLRTMgr.getRT(w, h);
  13055. ctx.breakNextMerge();
  13056. ctx.pushRT();
  13057. ctx.addRenderObject(SubmitCMD.create([ctx, tmpRT, w, h], RenderSprite.tmpTarget, this));
  13058. mask.render(ctx, -tRect.x, -tRect.y);
  13059. ctx.breakNextMerge();
  13060. ctx.popRT();
  13061. ctx.save();
  13062. ctx.clipRect(x + tRect.x - sprite.getStyle().pivotX, y + tRect.y - sprite.getStyle().pivotY, w, h);
  13063. next._fun.call(next, sprite, ctx, x, y);
  13064. ctx.restore();
  13065. preBlendMode = ctx.globalCompositeOperation;
  13066. ctx.addRenderObject(SubmitCMD.create(["mask"], RenderSprite.setBlendMode, this));
  13067. var shaderValue = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  13068. var uv = Texture.INV_UV;
  13069. ctx.drawTarget(tmpRT, x + tRect.x - sprite.getStyle().pivotX, y + tRect.y - sprite.getStyle().pivotY, w, h, Matrix.TEMP.identity(), shaderValue, uv, 6);
  13070. ctx.addRenderObject(SubmitCMD.create([tmpRT], RenderSprite.recycleTarget, this));
  13071. ctx.addRenderObject(SubmitCMD.create([preBlendMode], RenderSprite.setBlendMode, this));
  13072. }
  13073. ctx.restore();
  13074. }
  13075. else {
  13076. next._fun.call(next, sprite, context, x, y);
  13077. }
  13078. }
  13079. static tmpTarget(ctx, rt, w, h) {
  13080. rt.start();
  13081. rt.clear(0, 0, 0, 0);
  13082. }
  13083. static recycleTarget(rt) {
  13084. WebGLRTMgr.releaseRT(rt);
  13085. }
  13086. static setBlendMode(blendMode) {
  13087. var gl = WebGLContext.mainContext;
  13088. BlendMode.targetFns[BlendMode.TOINT[blendMode]](gl);
  13089. }
  13090. }
  13091. RenderSprite.INIT = 0x11111;
  13092. RenderSprite.renders = [];
  13093. RenderSprite.NORENDER = new RenderSprite(0, null);
  13094. RenderSprite.tempUV = new Array(8);
  13095. class Sprite extends Node {
  13096. constructor() {
  13097. super();
  13098. this._x = 0;
  13099. this._y = 0;
  13100. this._width = 0;
  13101. this._height = 0;
  13102. this._visible = true;
  13103. this._mouseState = 0;
  13104. this._zOrder = 0;
  13105. this._renderType = 0;
  13106. this._transform = null;
  13107. this._tfChanged = false;
  13108. this._repaint = SpriteConst.REPAINT_NONE;
  13109. this._texture = null;
  13110. this._style = SpriteStyle.EMPTY;
  13111. this._cacheStyle = CacheStyle.EMPTY;
  13112. this._boundStyle = null;
  13113. this._graphics = null;
  13114. this.mouseThrough = false;
  13115. this.autoSize = false;
  13116. this.hitTestPrior = false;
  13117. }
  13118. destroy(destroyChild = true) {
  13119. super.destroy(destroyChild);
  13120. this._style && this._style.recover();
  13121. this._cacheStyle && this._cacheStyle.recover();
  13122. this._boundStyle && this._boundStyle.recover();
  13123. this._style = null;
  13124. this._cacheStyle = null;
  13125. this._boundStyle = null;
  13126. this._transform = null;
  13127. if (this._graphics && this._graphics.autoDestroy) {
  13128. this._graphics.destroy();
  13129. }
  13130. this._graphics = null;
  13131. this.texture = null;
  13132. }
  13133. updateZOrder() {
  13134. Utils.updateOrder(this._children) && this.repaint();
  13135. }
  13136. _getBoundsStyle() {
  13137. if (!this._boundStyle)
  13138. this._boundStyle = BoundsStyle.create();
  13139. return this._boundStyle;
  13140. }
  13141. _setCustomRender() {
  13142. }
  13143. set customRenderEnable(b) {
  13144. if (b) {
  13145. this._renderType |= SpriteConst.CUSTOM;
  13146. this._setRenderType(this._renderType);
  13147. this._setCustomRender();
  13148. }
  13149. }
  13150. get cacheAs() {
  13151. return this._cacheStyle.cacheAs;
  13152. }
  13153. _setCacheAs(value) {
  13154. }
  13155. set cacheAs(value) {
  13156. if (value === this._cacheStyle.userSetCache)
  13157. return;
  13158. if (this.mask && value === 'normal')
  13159. return;
  13160. this._setCacheAs(value);
  13161. this._getCacheStyle().userSetCache = value;
  13162. this._checkCanvasEnable();
  13163. this.repaint();
  13164. }
  13165. _checkCanvasEnable() {
  13166. var tEnable = this._cacheStyle.needEnableCanvasRender();
  13167. this._getCacheStyle().enableCanvasRender = tEnable;
  13168. if (tEnable) {
  13169. if (this._cacheStyle.needBitmapCache()) {
  13170. this._cacheStyle.cacheAs = "bitmap";
  13171. }
  13172. else {
  13173. this._cacheStyle.cacheAs = this._cacheStyle.userSetCache;
  13174. }
  13175. this._cacheStyle.reCache = true;
  13176. this._renderType |= SpriteConst.CANVAS;
  13177. }
  13178. else {
  13179. this._cacheStyle.cacheAs = "none";
  13180. this._cacheStyle.releaseContext();
  13181. this._renderType &= ~SpriteConst.CANVAS;
  13182. }
  13183. this._setCacheAs(this._cacheStyle.cacheAs);
  13184. this._setRenderType(this._renderType);
  13185. }
  13186. get staticCache() {
  13187. return this._cacheStyle.staticCache;
  13188. }
  13189. set staticCache(value) {
  13190. this._getCacheStyle().staticCache = value;
  13191. if (!value)
  13192. this.reCache();
  13193. }
  13194. reCache() {
  13195. this._cacheStyle.reCache = true;
  13196. this._repaint |= SpriteConst.REPAINT_CACHE;
  13197. }
  13198. getRepaint() {
  13199. return this._repaint;
  13200. }
  13201. _setX(value) {
  13202. this._x = value;
  13203. }
  13204. _setY(value) {
  13205. this._y = value;
  13206. }
  13207. _setWidth(texture, value) {
  13208. }
  13209. _setHeight(texture, value) {
  13210. }
  13211. get x() {
  13212. return this._x;
  13213. }
  13214. set x(value) {
  13215. if (this.destroyed)
  13216. return;
  13217. if (this._x !== value) {
  13218. this._setX(value);
  13219. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13220. var p = this._cacheStyle.maskParent;
  13221. if (p) {
  13222. p.repaint(SpriteConst.REPAINT_CACHE);
  13223. }
  13224. }
  13225. }
  13226. get y() {
  13227. return this._y;
  13228. }
  13229. set y(value) {
  13230. if (this.destroyed)
  13231. return;
  13232. if (this._y !== value) {
  13233. this._setY(value);
  13234. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13235. var p = this._cacheStyle.maskParent;
  13236. if (p) {
  13237. p.repaint(SpriteConst.REPAINT_CACHE);
  13238. }
  13239. }
  13240. }
  13241. get width() {
  13242. return this.get_width();
  13243. }
  13244. set width(value) {
  13245. this.set_width(value);
  13246. }
  13247. set_width(value) {
  13248. if (this._width !== value) {
  13249. this._width = value;
  13250. this._setWidth(this.texture, value);
  13251. this._setTranformChange();
  13252. }
  13253. }
  13254. get_width() {
  13255. if (!this.autoSize)
  13256. return this._width || (this.texture ? this.texture.width : 0);
  13257. if (this.texture)
  13258. return this.texture.width;
  13259. if (!this._graphics && this._children.length === 0)
  13260. return 0;
  13261. return this.getSelfBounds().width;
  13262. }
  13263. get height() {
  13264. return this.get_height();
  13265. }
  13266. set height(value) {
  13267. this.set_height(value);
  13268. }
  13269. set_height(value) {
  13270. if (this._height !== value) {
  13271. this._height = value;
  13272. this._setHeight(this.texture, value);
  13273. this._setTranformChange();
  13274. }
  13275. }
  13276. get_height() {
  13277. if (!this.autoSize)
  13278. return this._height || (this.texture ? this.texture.height : 0);
  13279. if (this.texture)
  13280. return this.texture.height;
  13281. if (!this._graphics && this._children.length === 0)
  13282. return 0;
  13283. return this.getSelfBounds().height;
  13284. }
  13285. get displayWidth() {
  13286. return this.width * this.scaleX;
  13287. }
  13288. get displayHeight() {
  13289. return this.height * this.scaleY;
  13290. }
  13291. setSelfBounds(bound) {
  13292. this._getBoundsStyle().userBounds = bound;
  13293. }
  13294. getBounds() {
  13295. return this._getBoundsStyle().bounds = Rectangle._getWrapRec(this._boundPointsToParent());
  13296. }
  13297. getSelfBounds() {
  13298. if (this._boundStyle && this._boundStyle.userBounds)
  13299. return this._boundStyle.userBounds;
  13300. if (!this._graphics && this._children.length === 0 && !this._texture)
  13301. return Rectangle.TEMP.setTo(0, 0, this.width, this.height);
  13302. return this._getBoundsStyle().bounds = Rectangle._getWrapRec(this._getBoundPointsM(false));
  13303. }
  13304. _boundPointsToParent(ifRotate = false) {
  13305. var pX = 0, pY = 0;
  13306. if (this._style) {
  13307. pX = this.pivotX;
  13308. pY = this.pivotY;
  13309. ifRotate = ifRotate || (this._style.rotation !== 0);
  13310. if (this._style.scrollRect) {
  13311. pX += this._style.scrollRect.x;
  13312. pY += this._style.scrollRect.y;
  13313. }
  13314. }
  13315. var pList = this._getBoundPointsM(ifRotate);
  13316. if (!pList || pList.length < 1)
  13317. return pList;
  13318. if (pList.length != 8) {
  13319. pList = ifRotate ? GrahamScan.scanPList(pList) : Rectangle._getWrapRec(pList, Rectangle.TEMP)._getBoundPoints();
  13320. }
  13321. if (!this.transform) {
  13322. Utils.transPointList(pList, this._x - pX, this._y - pY);
  13323. return pList;
  13324. }
  13325. var tPoint = Point.TEMP;
  13326. var i, len = pList.length;
  13327. for (i = 0; i < len; i += 2) {
  13328. tPoint.x = pList[i];
  13329. tPoint.y = pList[i + 1];
  13330. this.toParentPoint(tPoint);
  13331. pList[i] = tPoint.x;
  13332. pList[i + 1] = tPoint.y;
  13333. }
  13334. return pList;
  13335. }
  13336. getGraphicBounds(realSize = false) {
  13337. if (!this._graphics)
  13338. return Rectangle.TEMP.setTo(0, 0, 0, 0);
  13339. return this._graphics.getBounds(realSize);
  13340. }
  13341. _getBoundPointsM(ifRotate = false) {
  13342. if (this._boundStyle && this._boundStyle.userBounds)
  13343. return this._boundStyle.userBounds._getBoundPoints();
  13344. if (!this._boundStyle)
  13345. this._getBoundsStyle();
  13346. if (!this._boundStyle.temBM)
  13347. this._boundStyle.temBM = [];
  13348. if (this._style.scrollRect) {
  13349. var rst = Utils.clearArray(this._boundStyle.temBM);
  13350. var rec = Rectangle.TEMP;
  13351. rec.copyFrom(this._style.scrollRect);
  13352. Utils.concatArray(rst, rec._getBoundPoints());
  13353. return rst;
  13354. }
  13355. var pList;
  13356. if (this._graphics) {
  13357. pList = this._graphics.getBoundPoints();
  13358. }
  13359. else {
  13360. pList = Utils.clearArray(this._boundStyle.temBM);
  13361. if (this._texture) {
  13362. rec = Rectangle.TEMP;
  13363. rec.setTo(0, 0, this.width || this._texture.width, this.height || this._texture.height);
  13364. Utils.concatArray(pList, rec._getBoundPoints());
  13365. }
  13366. }
  13367. var child;
  13368. var cList;
  13369. var __childs;
  13370. __childs = this._children;
  13371. for (var i = 0, n = __childs.length; i < n; i++) {
  13372. child = __childs[i];
  13373. if (child instanceof Sprite && child._visible === true) {
  13374. cList = child._boundPointsToParent(ifRotate);
  13375. if (cList)
  13376. pList = pList ? Utils.concatArray(pList, cList) : cList;
  13377. }
  13378. }
  13379. return pList;
  13380. }
  13381. _getCacheStyle() {
  13382. this._cacheStyle === CacheStyle.EMPTY && (this._cacheStyle = CacheStyle.create());
  13383. return this._cacheStyle;
  13384. }
  13385. getStyle() {
  13386. this._style === SpriteStyle.EMPTY && (this._style = SpriteStyle.create());
  13387. return this._style;
  13388. }
  13389. setStyle(value) {
  13390. this._style = value;
  13391. }
  13392. get scaleX() {
  13393. return this._style.scaleX;
  13394. }
  13395. set scaleX(value) {
  13396. this.set_scaleX(value);
  13397. }
  13398. _setScaleX(value) {
  13399. this._style.scaleX = value;
  13400. }
  13401. get scaleY() {
  13402. return this._style.scaleY;
  13403. }
  13404. set scaleY(value) {
  13405. this.set_scaleY(value);
  13406. }
  13407. _setScaleY(value) {
  13408. this._style.scaleY = value;
  13409. }
  13410. set_scaleX(value) {
  13411. var style = this.getStyle();
  13412. if (style.scaleX !== value) {
  13413. this._setScaleX(value);
  13414. this._setTranformChange();
  13415. }
  13416. }
  13417. get_scaleX() {
  13418. return this._style.scaleX;
  13419. }
  13420. set_scaleY(value) {
  13421. var style = this.getStyle();
  13422. if (style.scaleY !== value) {
  13423. this._setScaleY(value);
  13424. this._setTranformChange();
  13425. }
  13426. }
  13427. get_scaleY() {
  13428. return this._style.scaleY;
  13429. }
  13430. get rotation() {
  13431. return this._style.rotation;
  13432. }
  13433. set rotation(value) {
  13434. var style = this.getStyle();
  13435. if (style.rotation !== value) {
  13436. this._setRotation(value);
  13437. this._setTranformChange();
  13438. }
  13439. }
  13440. _setRotation(value) {
  13441. this._style.rotation = value;
  13442. }
  13443. get skewX() {
  13444. return this._style.skewX;
  13445. }
  13446. set skewX(value) {
  13447. var style = this.getStyle();
  13448. if (style.skewX !== value) {
  13449. this._setSkewX(value);
  13450. this._setTranformChange();
  13451. }
  13452. }
  13453. _setSkewX(value) {
  13454. this._style.skewX = value;
  13455. }
  13456. get skewY() {
  13457. return this._style.skewY;
  13458. }
  13459. set skewY(value) {
  13460. var style = this.getStyle();
  13461. if (style.skewY !== value) {
  13462. this._setSkewY(value);
  13463. this._setTranformChange();
  13464. }
  13465. }
  13466. _setSkewY(value) {
  13467. this._style.skewY = value;
  13468. }
  13469. _createTransform() {
  13470. return Matrix.create();
  13471. }
  13472. _adjustTransform() {
  13473. this._tfChanged = false;
  13474. var style = this._style;
  13475. var sx = style.scaleX, sy = style.scaleY;
  13476. var sskx = style.skewX;
  13477. var ssky = style.skewY;
  13478. var rot = style.rotation;
  13479. var m = this._transform || (this._transform = this._createTransform());
  13480. if (rot || sx !== 1 || sy !== 1 || sskx !== 0 || ssky !== 0) {
  13481. m._bTransform = true;
  13482. var skx = (rot - sskx) * 0.0174532922222222;
  13483. var sky = (rot + ssky) * 0.0174532922222222;
  13484. var cx = Math.cos(sky);
  13485. var ssx = Math.sin(sky);
  13486. var cy = Math.sin(skx);
  13487. var ssy = Math.cos(skx);
  13488. m.a = sx * cx;
  13489. m.b = sx * ssx;
  13490. m.c = -sy * cy;
  13491. m.d = sy * ssy;
  13492. m.tx = m.ty = 0;
  13493. }
  13494. else {
  13495. m.identity();
  13496. this._renderType &= ~SpriteConst.TRANSFORM;
  13497. this._setRenderType(this._renderType);
  13498. }
  13499. return m;
  13500. }
  13501. _setTransform(value) {
  13502. }
  13503. get transform() {
  13504. return this._tfChanged ? this._adjustTransform() : this._transform;
  13505. }
  13506. set transform(value) {
  13507. this.set_transform(value);
  13508. }
  13509. get_transform() {
  13510. return this._tfChanged ? this._adjustTransform() : this._transform;
  13511. }
  13512. set_transform(value) {
  13513. this._tfChanged = false;
  13514. var m = this._transform || (this._transform = this._createTransform());
  13515. value.copyTo(m);
  13516. this._setTransform(m);
  13517. if (value) {
  13518. this._x = m.tx;
  13519. this._y = m.ty;
  13520. m.tx = m.ty = 0;
  13521. }
  13522. if (value)
  13523. this._renderType |= SpriteConst.TRANSFORM;
  13524. else {
  13525. this._renderType &= ~SpriteConst.TRANSFORM;
  13526. }
  13527. this._setRenderType(this._renderType);
  13528. this.parentRepaint();
  13529. }
  13530. _setPivotX(value) {
  13531. var style = this.getStyle();
  13532. style.pivotX = value;
  13533. }
  13534. _getPivotX() {
  13535. return this._style.pivotX;
  13536. }
  13537. _setPivotY(value) {
  13538. var style = this.getStyle();
  13539. style.pivotY = value;
  13540. }
  13541. _getPivotY() {
  13542. return this._style.pivotY;
  13543. }
  13544. get pivotX() {
  13545. return this._getPivotX();
  13546. }
  13547. set pivotX(value) {
  13548. this._setPivotX(value);
  13549. this.repaint();
  13550. }
  13551. get pivotY() {
  13552. return this._getPivotY();
  13553. }
  13554. set pivotY(value) {
  13555. this._setPivotY(value);
  13556. this.repaint();
  13557. }
  13558. _setAlpha(value) {
  13559. if (this._style.alpha !== value) {
  13560. var style = this.getStyle();
  13561. style.alpha = value;
  13562. if (value !== 1)
  13563. this._renderType |= SpriteConst.ALPHA;
  13564. else
  13565. this._renderType &= ~SpriteConst.ALPHA;
  13566. this._setRenderType(this._renderType);
  13567. this.parentRepaint();
  13568. }
  13569. }
  13570. _getAlpha() {
  13571. return this._style.alpha;
  13572. }
  13573. get alpha() {
  13574. return this._getAlpha();
  13575. }
  13576. set alpha(value) {
  13577. value = value < 0 ? 0 : (value > 1 ? 1 : value);
  13578. this._setAlpha(value);
  13579. }
  13580. get visible() {
  13581. return this.get_visible();
  13582. }
  13583. set visible(value) {
  13584. this.set_visible(value);
  13585. }
  13586. get_visible() {
  13587. return this._visible;
  13588. }
  13589. set_visible(value) {
  13590. if (this._visible !== value) {
  13591. this._visible = value;
  13592. this.parentRepaint(SpriteConst.REPAINT_ALL);
  13593. }
  13594. }
  13595. _setBlendMode(value) {
  13596. }
  13597. get blendMode() {
  13598. return this._style.blendMode;
  13599. }
  13600. set blendMode(value) {
  13601. this._setBlendMode(value);
  13602. this.getStyle().blendMode = value;
  13603. if (value && value != "source-over")
  13604. this._renderType |= SpriteConst.BLEND;
  13605. else
  13606. this._renderType &= ~SpriteConst.BLEND;
  13607. this._setRenderType(this._renderType);
  13608. this.parentRepaint();
  13609. }
  13610. get graphics() {
  13611. if (!this._graphics) {
  13612. this.graphics = new Graphics();
  13613. this._graphics.autoDestroy = true;
  13614. }
  13615. return this._graphics;
  13616. }
  13617. _setGraphics(value) {
  13618. }
  13619. _setGraphicsCallBack() {
  13620. }
  13621. set graphics(value) {
  13622. if (this._graphics)
  13623. this._graphics._sp = null;
  13624. this._graphics = value;
  13625. if (value) {
  13626. this._setGraphics(value);
  13627. this._renderType |= SpriteConst.GRAPHICS;
  13628. value._sp = this;
  13629. }
  13630. else {
  13631. this._renderType &= ~SpriteConst.GRAPHICS;
  13632. }
  13633. this._setRenderType(this._renderType);
  13634. this.repaint();
  13635. }
  13636. get scrollRect() {
  13637. return this._style.scrollRect;
  13638. }
  13639. _setScrollRect(value) {
  13640. }
  13641. set scrollRect(value) {
  13642. this.getStyle().scrollRect = value;
  13643. this._setScrollRect(value);
  13644. this.repaint();
  13645. if (value) {
  13646. this._renderType |= SpriteConst.CLIP;
  13647. }
  13648. else {
  13649. this._renderType &= ~SpriteConst.CLIP;
  13650. }
  13651. this._setRenderType(this._renderType);
  13652. }
  13653. pos(x, y, speedMode = false) {
  13654. if (this._x !== x || this._y !== y) {
  13655. if (this.destroyed)
  13656. return this;
  13657. if (speedMode) {
  13658. this._setX(x);
  13659. this._setY(y);
  13660. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  13661. var p = this._cacheStyle.maskParent;
  13662. if (p) {
  13663. p.repaint(SpriteConst.REPAINT_CACHE);
  13664. }
  13665. }
  13666. else {
  13667. this.x = x;
  13668. this.y = y;
  13669. }
  13670. }
  13671. return this;
  13672. }
  13673. pivot(x, y) {
  13674. this.pivotX = x;
  13675. this.pivotY = y;
  13676. return this;
  13677. }
  13678. size(width, height) {
  13679. this.width = width;
  13680. this.height = height;
  13681. return this;
  13682. }
  13683. scale(scaleX, scaleY, speedMode = false) {
  13684. var style = this.getStyle();
  13685. if (style.scaleX != scaleX || style.scaleY != scaleY) {
  13686. if (this.destroyed)
  13687. return this;
  13688. if (speedMode) {
  13689. this._setScaleX(scaleX);
  13690. this._setScaleY(scaleY);
  13691. this._setTranformChange();
  13692. }
  13693. else {
  13694. this.scaleX = scaleX;
  13695. this.scaleY = scaleY;
  13696. }
  13697. }
  13698. return this;
  13699. }
  13700. skew(skewX, skewY) {
  13701. this.skewX = skewX;
  13702. this.skewY = skewY;
  13703. return this;
  13704. }
  13705. render(ctx, x, y) {
  13706. RenderSprite.renders[this._renderType]._fun(this, ctx, x + this._x, y + this._y);
  13707. this._repaint = 0;
  13708. }
  13709. drawToCanvas(canvasWidth, canvasHeight, offsetX, offsetY) {
  13710. return Sprite.drawToCanvas(this, this._renderType, canvasWidth, canvasHeight, offsetX, offsetY);
  13711. }
  13712. drawToTexture(canvasWidth, canvasHeight, offsetX, offsetY) {
  13713. return Sprite.drawToTexture(this, this._renderType, canvasWidth, canvasHeight, offsetX, offsetY);
  13714. }
  13715. drawToTexture3D(offx, offy, tex) {
  13716. throw 'not implement';
  13717. }
  13718. customRender(context, x, y) {
  13719. this._repaint = SpriteConst.REPAINT_ALL;
  13720. }
  13721. _applyFilters() {
  13722. }
  13723. get filters() {
  13724. return this._cacheStyle.filters;
  13725. }
  13726. _setColorFilter(value) { }
  13727. set filters(value) {
  13728. value && value.length === 0 && (value = null);
  13729. if (this._cacheStyle.filters == value)
  13730. return;
  13731. this._getCacheStyle().filters = value ? value.slice() : null;
  13732. if (value && value.length) {
  13733. this._setColorFilter(value[0]);
  13734. this._renderType |= SpriteConst.FILTERS;
  13735. }
  13736. else {
  13737. this._setColorFilter(null);
  13738. this._renderType &= ~SpriteConst.FILTERS;
  13739. }
  13740. this._setRenderType(this._renderType);
  13741. if (value && value.length > 0) {
  13742. if (!this._getBit(Const.DISPLAY))
  13743. this._setBitUp(Const.DISPLAY);
  13744. if (!(value.length == 1 && (value[0] instanceof ColorFilter))) {
  13745. this._getCacheStyle().cacheForFilters = true;
  13746. this._checkCanvasEnable();
  13747. }
  13748. }
  13749. else {
  13750. if (this._cacheStyle.cacheForFilters) {
  13751. this._cacheStyle.cacheForFilters = false;
  13752. this._checkCanvasEnable();
  13753. }
  13754. }
  13755. this._getCacheStyle().hasGlowFilter = this._isHaveGlowFilter();
  13756. this.repaint();
  13757. }
  13758. _isHaveGlowFilter() {
  13759. var i, len;
  13760. if (this.filters) {
  13761. for (i = 0; i < this.filters.length; i++) {
  13762. if (this.filters[i].type == Filter.GLOW) {
  13763. return true;
  13764. }
  13765. }
  13766. }
  13767. for (i = 0, len = this._children.length; i < len; i++) {
  13768. if (this._children[i]._isHaveGlowFilter()) {
  13769. return true;
  13770. }
  13771. }
  13772. return false;
  13773. }
  13774. localToGlobal(point, createNewPoint = false, globalNode = null) {
  13775. if (createNewPoint === true) {
  13776. point = new Point(point.x, point.y);
  13777. }
  13778. var ele = this;
  13779. globalNode = globalNode || ILaya.stage;
  13780. while (ele && !ele.destroyed) {
  13781. if (ele == globalNode)
  13782. break;
  13783. point = ele.toParentPoint(point);
  13784. ele = ele.parent;
  13785. }
  13786. return point;
  13787. }
  13788. globalToLocal(point, createNewPoint = false, globalNode = null) {
  13789. if (createNewPoint) {
  13790. point = new Point(point.x, point.y);
  13791. }
  13792. var ele = this;
  13793. var list = [];
  13794. globalNode = globalNode || ILaya.stage;
  13795. while (ele && !ele.destroyed) {
  13796. if (ele == globalNode)
  13797. break;
  13798. list.push(ele);
  13799. ele = ele.parent;
  13800. }
  13801. var i = list.length - 1;
  13802. while (i >= 0) {
  13803. ele = list[i];
  13804. point = ele.fromParentPoint(point);
  13805. i--;
  13806. }
  13807. return point;
  13808. }
  13809. toParentPoint(point) {
  13810. if (!point)
  13811. return point;
  13812. point.x -= this.pivotX;
  13813. point.y -= this.pivotY;
  13814. if (this.transform) {
  13815. this._transform.transformPoint(point);
  13816. }
  13817. point.x += this._x;
  13818. point.y += this._y;
  13819. var scroll = this._style.scrollRect;
  13820. if (scroll) {
  13821. point.x -= scroll.x;
  13822. point.y -= scroll.y;
  13823. }
  13824. return point;
  13825. }
  13826. fromParentPoint(point) {
  13827. if (!point)
  13828. return point;
  13829. point.x -= this._x;
  13830. point.y -= this._y;
  13831. var scroll = this._style.scrollRect;
  13832. if (scroll) {
  13833. point.x += scroll.x;
  13834. point.y += scroll.y;
  13835. }
  13836. if (this.transform) {
  13837. this._transform.invertTransformPoint(point);
  13838. }
  13839. point.x += this.pivotX;
  13840. point.y += this.pivotY;
  13841. return point;
  13842. }
  13843. fromStagePoint(point) {
  13844. return point;
  13845. }
  13846. on(type, caller, listener, args = null) {
  13847. if (this._mouseState !== 1 && this.isMouseEvent(type)) {
  13848. this.mouseEnabled = true;
  13849. this._setBit(Const.HAS_MOUSE, true);
  13850. if (this._parent) {
  13851. this._onDisplay();
  13852. }
  13853. return this._createListener(type, caller, listener, args, false);
  13854. }
  13855. return super.on(type, caller, listener, args);
  13856. }
  13857. once(type, caller, listener, args = null) {
  13858. if (this._mouseState !== 1 && this.isMouseEvent(type)) {
  13859. this.mouseEnabled = true;
  13860. this._setBit(Const.HAS_MOUSE, true);
  13861. if (this._parent) {
  13862. this._onDisplay();
  13863. }
  13864. return this._createListener(type, caller, listener, args, true);
  13865. }
  13866. return super.once(type, caller, listener, args);
  13867. }
  13868. _onDisplay(v) {
  13869. if (this._mouseState !== 1) {
  13870. var ele = this;
  13871. ele = ele.parent;
  13872. while (ele && ele._mouseState !== 1) {
  13873. if (ele._getBit(Const.HAS_MOUSE))
  13874. break;
  13875. ele.mouseEnabled = true;
  13876. ele._setBit(Const.HAS_MOUSE, true);
  13877. ele = ele.parent;
  13878. }
  13879. }
  13880. }
  13881. _setParent(value) {
  13882. super._setParent(value);
  13883. if (value && this._getBit(Const.HAS_MOUSE)) {
  13884. this._onDisplay();
  13885. }
  13886. }
  13887. loadImage(url, complete = null) {
  13888. if (!url) {
  13889. this.texture = null;
  13890. loaded.call(this);
  13891. }
  13892. else {
  13893. var tex = ILaya.Loader.getRes(url);
  13894. if (!tex) {
  13895. tex = new Texture();
  13896. tex.load(url);
  13897. ILaya.Loader.cacheRes(url, tex);
  13898. }
  13899. this.texture = tex;
  13900. if (!tex.getIsReady())
  13901. tex.once(Event.READY, this, loaded);
  13902. else
  13903. loaded.call(this);
  13904. }
  13905. function loaded() {
  13906. this.repaint(SpriteConst.REPAINT_ALL);
  13907. complete && complete.run();
  13908. }
  13909. return this;
  13910. }
  13911. static fromImage(url) {
  13912. return new Sprite().loadImage(url);
  13913. }
  13914. repaint(type = SpriteConst.REPAINT_CACHE) {
  13915. if (!(this._repaint & type)) {
  13916. this._repaint |= type;
  13917. this.parentRepaint(type);
  13918. }
  13919. if (this._cacheStyle && this._cacheStyle.maskParent) {
  13920. this._cacheStyle.maskParent.repaint(type);
  13921. }
  13922. }
  13923. _needRepaint() {
  13924. return (this._repaint & SpriteConst.REPAINT_CACHE) && this._cacheStyle.enableCanvasRender && this._cacheStyle.reCache;
  13925. }
  13926. _childChanged(child = null) {
  13927. if (this._children.length)
  13928. this._renderType |= SpriteConst.CHILDS;
  13929. else
  13930. this._renderType &= ~SpriteConst.CHILDS;
  13931. this._setRenderType(this._renderType);
  13932. if (child && this._getBit(Const.HAS_ZORDER))
  13933. ILaya.systemTimer.callLater(this, this.updateZOrder);
  13934. this.repaint(SpriteConst.REPAINT_ALL);
  13935. }
  13936. parentRepaint(type = SpriteConst.REPAINT_CACHE) {
  13937. var p = this._parent;
  13938. if (p && !(p._repaint & type)) {
  13939. p._repaint |= type;
  13940. p.parentRepaint(type);
  13941. }
  13942. }
  13943. get stage() {
  13944. return ILaya.stage;
  13945. }
  13946. get hitArea() {
  13947. return this._style.hitArea;
  13948. }
  13949. set hitArea(value) {
  13950. this.getStyle().hitArea = value;
  13951. }
  13952. _setMask(value) {
  13953. }
  13954. get mask() {
  13955. return this._cacheStyle.mask;
  13956. }
  13957. set mask(value) {
  13958. if (value && this.mask && this.mask._cacheStyle.maskParent)
  13959. return;
  13960. this._getCacheStyle().mask = value;
  13961. this._setMask(value);
  13962. this._checkCanvasEnable();
  13963. if (value) {
  13964. value._getCacheStyle().maskParent = this;
  13965. }
  13966. else {
  13967. if (this.mask) {
  13968. this.mask._getCacheStyle().maskParent = null;
  13969. }
  13970. }
  13971. this._renderType |= SpriteConst.MASK;
  13972. this._setRenderType(this._renderType);
  13973. this.parentRepaint(SpriteConst.REPAINT_ALL);
  13974. }
  13975. get mouseEnabled() {
  13976. return this._mouseState > 1;
  13977. }
  13978. set mouseEnabled(value) {
  13979. this._mouseState = value ? 2 : 1;
  13980. }
  13981. startDrag(area = null, hasInertia = false, elasticDistance = 0, elasticBackTime = 300, data = null, disableMouseEvent = false, ratio = 0.92) {
  13982. this._style.dragging || (this.getStyle().dragging = new ILaya.Dragging());
  13983. this._style.dragging.start(this, area, hasInertia, elasticDistance, elasticBackTime, data, disableMouseEvent, ratio);
  13984. }
  13985. stopDrag() {
  13986. this._style.dragging && this._style.dragging.stop();
  13987. }
  13988. _setDisplay(value) {
  13989. if (!value) {
  13990. if (this._cacheStyle) {
  13991. this._cacheStyle.releaseContext();
  13992. this._cacheStyle.releaseFilterCache();
  13993. if (this._cacheStyle.hasGlowFilter) {
  13994. this._cacheStyle.hasGlowFilter = false;
  13995. }
  13996. }
  13997. }
  13998. super._setDisplay(value);
  13999. }
  14000. hitTestPoint(x, y) {
  14001. var point = this.globalToLocal(Point.TEMP.setTo(x, y));
  14002. x = point.x;
  14003. y = point.y;
  14004. 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();
  14005. return rect.contains(x, y);
  14006. }
  14007. getMousePoint() {
  14008. return this.globalToLocal(Point.TEMP.setTo(ILaya.stage.mouseX, ILaya.stage.mouseY));
  14009. }
  14010. get globalScaleX() {
  14011. var scale = 1;
  14012. var ele = this;
  14013. while (ele) {
  14014. if (ele === ILaya.stage)
  14015. break;
  14016. scale *= ele.scaleX;
  14017. ele = ele.parent;
  14018. }
  14019. return scale;
  14020. }
  14021. get globalRotation() {
  14022. var angle = 0;
  14023. var ele = this;
  14024. while (ele) {
  14025. if (ele === ILaya.stage)
  14026. break;
  14027. angle += ele.rotation;
  14028. ele = ele.parent;
  14029. }
  14030. return angle;
  14031. }
  14032. get globalScaleY() {
  14033. var scale = 1;
  14034. var ele = this;
  14035. while (ele) {
  14036. if (ele === ILaya.stage)
  14037. break;
  14038. scale *= ele.scaleY;
  14039. ele = ele.parent;
  14040. }
  14041. return scale;
  14042. }
  14043. get mouseX() {
  14044. return this.getMousePoint().x;
  14045. }
  14046. get mouseY() {
  14047. return this.getMousePoint().y;
  14048. }
  14049. get zOrder() {
  14050. return this._zOrder;
  14051. }
  14052. set zOrder(value) {
  14053. if (this._zOrder != value) {
  14054. this._zOrder = value;
  14055. if (this._parent) {
  14056. value && this._parent._setBit(Const.HAS_ZORDER, true);
  14057. ILaya.systemTimer.callLater(this._parent, this.updateZOrder);
  14058. }
  14059. }
  14060. }
  14061. get texture() {
  14062. return this._texture;
  14063. }
  14064. _setTexture(value) {
  14065. }
  14066. set texture(value) {
  14067. if (typeof (value) == 'string') {
  14068. this.loadImage(value);
  14069. }
  14070. else if (this._texture != value) {
  14071. this._texture && this._texture._removeReference();
  14072. this._texture = value;
  14073. value && value._addReference();
  14074. this._setTexture(value);
  14075. this._setWidth(this._texture, this.width);
  14076. this._setHeight(this._texture, this.height);
  14077. if (value)
  14078. this._renderType |= SpriteConst.TEXTURE;
  14079. else
  14080. this._renderType &= ~SpriteConst.TEXTURE;
  14081. this._setRenderType(this._renderType);
  14082. this.repaint();
  14083. }
  14084. }
  14085. get viewport() {
  14086. return this._style.viewport;
  14087. }
  14088. set viewport(value) {
  14089. if (typeof (value) == 'string') {
  14090. var recArr;
  14091. recArr = value.split(",");
  14092. if (recArr.length > 3) {
  14093. value = new Rectangle(parseFloat(recArr[0]), parseFloat(recArr[1]), parseFloat(recArr[2]), parseFloat(recArr[3]));
  14094. }
  14095. }
  14096. this.getStyle().viewport = value;
  14097. }
  14098. _setRenderType(type) {
  14099. }
  14100. _setTranformChange() {
  14101. this._tfChanged = true;
  14102. this._renderType |= SpriteConst.TRANSFORM;
  14103. this.parentRepaint(SpriteConst.REPAINT_CACHE);
  14104. }
  14105. _setBgStyleColor(x, y, width, height, fillColor) {
  14106. }
  14107. _setBorderStyleColor(x, y, width, height, fillColor, borderWidth) {
  14108. }
  14109. captureMouseEvent(exclusive) {
  14110. ILaya.MouseManager.instance.setCapture(this, exclusive);
  14111. }
  14112. releaseMouseEvent() {
  14113. ILaya.MouseManager.instance.releaseCapture();
  14114. }
  14115. set drawCallOptimize(value) {
  14116. this._setBit(Const.DRAWCALL_OPTIMIZE, value);
  14117. }
  14118. get drawCallOptimize() {
  14119. return this._getBit(Const.DRAWCALL_OPTIMIZE);
  14120. }
  14121. }
  14122. Sprite.drawToCanvas = function (sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  14123. offsetX -= sprite.x;
  14124. offsetY -= sprite.y;
  14125. offsetX |= 0;
  14126. offsetY |= 0;
  14127. canvasWidth |= 0;
  14128. canvasHeight |= 0;
  14129. var ctx = new Context();
  14130. ctx.size(canvasWidth, canvasHeight);
  14131. ctx.asBitmap = true;
  14132. ctx._targets.start();
  14133. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  14134. ctx.flush();
  14135. ctx._targets.end();
  14136. ctx._targets.restore();
  14137. var dt = ctx._targets.getData(0, 0, canvasWidth, canvasHeight);
  14138. ctx.destroy();
  14139. var imgdata = new ImageData(canvasWidth, canvasHeight);
  14140. var lineLen = canvasWidth * 4;
  14141. var dst = imgdata.data;
  14142. var y = canvasHeight - 1;
  14143. var off = y * lineLen;
  14144. var srcoff = 0;
  14145. for (; y >= 0; y--) {
  14146. dst.set(dt.subarray(srcoff, srcoff + lineLen), off);
  14147. off -= lineLen;
  14148. srcoff += lineLen;
  14149. }
  14150. var canv = new HTMLCanvas(true);
  14151. canv.size(canvasWidth, canvasHeight);
  14152. var ctx2d = canv.getContext('2d');
  14153. ctx2d.putImageData(imgdata, 0, 0);
  14154. return canv;
  14155. };
  14156. Sprite.drawToTexture = function (sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  14157. offsetX -= sprite.x;
  14158. offsetY -= sprite.y;
  14159. offsetX |= 0;
  14160. offsetY |= 0;
  14161. canvasWidth |= 0;
  14162. canvasHeight |= 0;
  14163. var ctx = new Context();
  14164. ctx.size(canvasWidth, canvasHeight);
  14165. ctx.asBitmap = true;
  14166. ctx._targets.start();
  14167. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  14168. ctx.flush();
  14169. ctx._targets.end();
  14170. ctx._targets.restore();
  14171. var rtex = new Texture(ctx._targets, Texture.INV_UV);
  14172. ctx.destroy(true);
  14173. return rtex;
  14174. };
  14175. ClassUtils.regClass("laya.display.Sprite", Sprite);
  14176. ClassUtils.regClass("Laya.Sprite", Sprite);
  14177. class TextStyle extends SpriteStyle {
  14178. constructor() {
  14179. super(...arguments);
  14180. this.italic = false;
  14181. }
  14182. reset() {
  14183. super.reset();
  14184. this.italic = false;
  14185. this.align = "left";
  14186. this.wordWrap = false;
  14187. this.leading = 0;
  14188. this.padding = [0, 0, 0, 0];
  14189. this.bgColor = null;
  14190. this.borderColor = null;
  14191. this.asPassword = false;
  14192. this.stroke = 0;
  14193. this.strokeColor = "#000000";
  14194. this.bold = false;
  14195. this.underline = false;
  14196. this.underlineColor = null;
  14197. this.currBitmapFont = null;
  14198. return this;
  14199. }
  14200. recover() {
  14201. if (this === TextStyle.EMPTY)
  14202. return;
  14203. Pool.recover("TextStyle", this.reset());
  14204. }
  14205. static create() {
  14206. return Pool.getItemByClass("TextStyle", TextStyle);
  14207. }
  14208. render(sprite, context, x, y) {
  14209. (this.bgColor || this.borderColor) && context.drawRect(x, y, sprite.width, sprite.height, this.bgColor, this.borderColor, 1);
  14210. }
  14211. }
  14212. TextStyle.EMPTY = new TextStyle();
  14213. class Text extends Sprite {
  14214. constructor() {
  14215. super();
  14216. this._textWidth = 0;
  14217. this._textHeight = 0;
  14218. this._lines = [];
  14219. this._lineWidths = [];
  14220. this._startX = 0;
  14221. this._startY = 0;
  14222. this._charSize = {};
  14223. this._valign = "top";
  14224. this._fontSize = Text.defaultFontSize;
  14225. this._font = Text.defaultFont;
  14226. this._color = "#000000";
  14227. this._singleCharRender = false;
  14228. this.overflow = Text.VISIBLE;
  14229. this._style = TextStyle.EMPTY;
  14230. }
  14231. static defaultFontStr() {
  14232. return Text.defaultFontSize + "px " + Text.defaultFont;
  14233. }
  14234. getStyle() {
  14235. this._style === TextStyle.EMPTY && (this._style = TextStyle.create());
  14236. return this._style;
  14237. }
  14238. _getTextStyle() {
  14239. if (this._style === TextStyle.EMPTY) {
  14240. this._style = TextStyle.create();
  14241. }
  14242. return this._style;
  14243. }
  14244. static registerBitmapFont(name, bitmapFont) {
  14245. Text._bitmapFonts || (Text._bitmapFonts = {});
  14246. Text._bitmapFonts[name] = bitmapFont;
  14247. }
  14248. static unregisterBitmapFont(name, destroy = true) {
  14249. if (Text._bitmapFonts && Text._bitmapFonts[name]) {
  14250. var tBitmapFont = Text._bitmapFonts[name];
  14251. if (destroy)
  14252. tBitmapFont.destroy();
  14253. delete Text._bitmapFonts[name];
  14254. }
  14255. }
  14256. destroy(destroyChild = true) {
  14257. super.destroy(destroyChild);
  14258. this._clipPoint = null;
  14259. this._lines = null;
  14260. this._lineWidths = null;
  14261. this._words && this._words.forEach(function (w) {
  14262. w.cleanCache();
  14263. });
  14264. this._words = null;
  14265. this._charSize = null;
  14266. }
  14267. _getBoundPointsM(ifRotate = false) {
  14268. var rec = Rectangle.TEMP;
  14269. rec.setTo(0, 0, this.width, this.height);
  14270. return rec._getBoundPoints();
  14271. }
  14272. getGraphicBounds(realSize = false) {
  14273. var rec = Rectangle.TEMP;
  14274. rec.setTo(0, 0, this.width, this.height);
  14275. return rec;
  14276. }
  14277. get width() {
  14278. if (this._width)
  14279. return this._width;
  14280. return this.textWidth + this.padding[1] + this.padding[3];
  14281. }
  14282. set width(value) {
  14283. if (value != this._width) {
  14284. super.set_width(value);
  14285. this.isChanged = true;
  14286. if (this.borderColor) {
  14287. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14288. }
  14289. }
  14290. }
  14291. _getCSSStyle() {
  14292. return this._style;
  14293. }
  14294. get height() {
  14295. if (this._height)
  14296. return this._height;
  14297. return this.textHeight;
  14298. }
  14299. set height(value) {
  14300. if (value != this._height) {
  14301. super.set_height(value);
  14302. this.isChanged = true;
  14303. if (this.borderColor) {
  14304. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14305. }
  14306. }
  14307. }
  14308. get textWidth() {
  14309. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14310. return this._textWidth;
  14311. }
  14312. get textHeight() {
  14313. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14314. return this._textHeight;
  14315. }
  14316. get text() {
  14317. return this._text || "";
  14318. }
  14319. get_text() {
  14320. return this._text || "";
  14321. }
  14322. set_text(value) {
  14323. if (this._text !== value) {
  14324. this.lang(value + "");
  14325. this.isChanged = true;
  14326. this.event(Event.CHANGE);
  14327. if (this.borderColor) {
  14328. this._setBorderStyleColor(0, 0, this.width, this.height, this.borderColor, 1);
  14329. }
  14330. }
  14331. }
  14332. set text(value) {
  14333. this.set_text(value);
  14334. }
  14335. lang(text, arg1 = null, arg2 = null, arg3 = null, arg4 = null, arg5 = null, arg6 = null, arg7 = null, arg8 = null, arg9 = null, arg10 = null) {
  14336. text = Text.langPacks && Text.langPacks[text] ? Text.langPacks[text] : text;
  14337. if (arguments.length < 2) {
  14338. this._text = text;
  14339. }
  14340. else {
  14341. for (var i = 0, n = arguments.length; i < n; i++) {
  14342. text = text.replace("{" + i + "}", arguments[i + 1]);
  14343. }
  14344. this._text = text;
  14345. }
  14346. }
  14347. get font() {
  14348. return this._font;
  14349. }
  14350. set font(value) {
  14351. if (this._style.currBitmapFont) {
  14352. this._getTextStyle().currBitmapFont = null;
  14353. this.scale(1, 1);
  14354. }
  14355. if (Text._bitmapFonts && Text._bitmapFonts[value]) {
  14356. this._getTextStyle().currBitmapFont = Text._bitmapFonts[value];
  14357. }
  14358. this._font = value;
  14359. this.isChanged = true;
  14360. }
  14361. get fontSize() {
  14362. return this._fontSize;
  14363. }
  14364. set fontSize(value) {
  14365. if (this._fontSize != value) {
  14366. this._fontSize = value;
  14367. this.isChanged = true;
  14368. }
  14369. }
  14370. get bold() {
  14371. return this._style.bold;
  14372. }
  14373. set bold(value) {
  14374. this._getTextStyle().bold = value;
  14375. this.isChanged = true;
  14376. }
  14377. get color() {
  14378. return this._color;
  14379. }
  14380. set color(value) {
  14381. this.set_color(value);
  14382. }
  14383. get_color() {
  14384. return this._color;
  14385. }
  14386. set_color(value) {
  14387. if (this._color != value) {
  14388. this._color = value;
  14389. if (!this._isChanged && this._graphics) {
  14390. this._graphics.replaceTextColor(this.color);
  14391. }
  14392. else {
  14393. this.isChanged = true;
  14394. }
  14395. }
  14396. }
  14397. get italic() {
  14398. return this._style.italic;
  14399. }
  14400. set italic(value) {
  14401. this._getTextStyle().italic = value;
  14402. this.isChanged = true;
  14403. }
  14404. get align() {
  14405. return this._style.align;
  14406. }
  14407. set align(value) {
  14408. this._getTextStyle().align = value;
  14409. this.isChanged = true;
  14410. }
  14411. get valign() {
  14412. return this._valign;
  14413. }
  14414. set valign(value) {
  14415. this._valign = value;
  14416. this.isChanged = true;
  14417. }
  14418. get wordWrap() {
  14419. return this._style.wordWrap;
  14420. }
  14421. set wordWrap(value) {
  14422. this._getTextStyle().wordWrap = value;
  14423. this.isChanged = true;
  14424. }
  14425. get leading() {
  14426. return this._style.leading;
  14427. }
  14428. set leading(value) {
  14429. this._getTextStyle().leading = value;
  14430. this.isChanged = true;
  14431. }
  14432. get padding() {
  14433. return this._style.padding;
  14434. }
  14435. set padding(value) {
  14436. if (typeof (value) == 'string') {
  14437. var arr;
  14438. arr = value.split(",");
  14439. var i, len;
  14440. len = arr.length;
  14441. while (arr.length < 4) {
  14442. arr.push(0);
  14443. }
  14444. for (i = 0; i < len; i++) {
  14445. arr[i] = parseFloat(arr[i]) || 0;
  14446. }
  14447. value = arr;
  14448. }
  14449. this._getTextStyle().padding = value;
  14450. this.isChanged = true;
  14451. }
  14452. get bgColor() {
  14453. return this._style.bgColor;
  14454. }
  14455. set bgColor(value) {
  14456. this.set_bgColor(value);
  14457. }
  14458. set_bgColor(value) {
  14459. this._getTextStyle().bgColor = value;
  14460. this._renderType |= SpriteConst.STYLE;
  14461. this._setBgStyleColor(0, 0, this.width, this.height, value);
  14462. this._setRenderType(this._renderType);
  14463. this.isChanged = true;
  14464. }
  14465. get_bgColor() {
  14466. return this._style.bgColor;
  14467. }
  14468. get borderColor() {
  14469. return this._style.borderColor;
  14470. }
  14471. set borderColor(value) {
  14472. this._getTextStyle().borderColor = value;
  14473. this._renderType |= SpriteConst.STYLE;
  14474. this._setBorderStyleColor(0, 0, this.width, this.height, value, 1);
  14475. this._setRenderType(this._renderType);
  14476. this.isChanged = true;
  14477. }
  14478. get stroke() {
  14479. return this._style.stroke;
  14480. }
  14481. set stroke(value) {
  14482. this._getTextStyle().stroke = value;
  14483. this.isChanged = true;
  14484. }
  14485. get strokeColor() {
  14486. return this._style.strokeColor;
  14487. }
  14488. set strokeColor(value) {
  14489. this._getTextStyle().strokeColor = value;
  14490. this.isChanged = true;
  14491. }
  14492. set isChanged(value) {
  14493. if (this._isChanged !== value) {
  14494. this._isChanged = value;
  14495. value && ILaya.systemTimer.callLater(this, this.typeset);
  14496. }
  14497. }
  14498. _getContextFont() {
  14499. return (this.italic ? "italic " : "") + (this.bold ? "bold " : "") + this.fontSize + "px " + (ILaya.Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font) : this.font);
  14500. }
  14501. _isPassWordMode() {
  14502. var style = this._style;
  14503. var password = style.asPassword;
  14504. if (("prompt" in this) && this['prompt'] == this._text)
  14505. password = false;
  14506. return password;
  14507. }
  14508. _getPassWordTxt(txt) {
  14509. var len = txt.length;
  14510. var word;
  14511. word = "";
  14512. for (var j = len; j > 0; j--) {
  14513. word += "●";
  14514. }
  14515. return word;
  14516. }
  14517. _renderText() {
  14518. var padding = this.padding;
  14519. var visibleLineCount = this._lines.length;
  14520. if (this.overflow != Text.VISIBLE) {
  14521. visibleLineCount = Math.min(visibleLineCount, Math.floor((this.height - padding[0] - padding[2]) / (this.leading + this._charSize.height)) + 1);
  14522. }
  14523. var beginLine = this.scrollY / (this._charSize.height + this.leading) | 0;
  14524. var graphics = this.graphics;
  14525. graphics.clear(true);
  14526. var ctxFont = this._getContextFont();
  14527. ILaya.Browser.context.font = ctxFont;
  14528. var startX = padding[3];
  14529. var textAlgin = "left";
  14530. var lines = this._lines;
  14531. var lineHeight = this.leading + this._charSize.height;
  14532. var tCurrBitmapFont = this._style.currBitmapFont;
  14533. if (tCurrBitmapFont) {
  14534. lineHeight = this.leading + tCurrBitmapFont.getMaxHeight();
  14535. }
  14536. var startY = padding[0];
  14537. if ((!tCurrBitmapFont) && this._width > 0 && this._textWidth <= this._width) {
  14538. if (this.align == "right") {
  14539. textAlgin = "right";
  14540. startX = this._width - padding[1];
  14541. }
  14542. else if (this.align == "center") {
  14543. textAlgin = "center";
  14544. startX = this._width * 0.5 + padding[3] - padding[1];
  14545. }
  14546. }
  14547. if (this._height > 0) {
  14548. var tempVAlign = (this._textHeight > this._height) ? "top" : this.valign;
  14549. if (tempVAlign === "middle")
  14550. startY = (this._height - visibleLineCount * lineHeight) * 0.5 + padding[0] - padding[2];
  14551. else if (tempVAlign === "bottom")
  14552. startY = this._height - visibleLineCount * lineHeight - padding[2];
  14553. }
  14554. var style = this._style;
  14555. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14556. var bitmapScale = tCurrBitmapFont.fontSize / this.fontSize;
  14557. }
  14558. if (this._clipPoint) {
  14559. graphics.save();
  14560. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14561. var tClipWidth;
  14562. var tClipHeight;
  14563. this._width ? tClipWidth = (this._width - padding[3] - padding[1]) : tClipWidth = this._textWidth;
  14564. this._height ? tClipHeight = (this._height - padding[0] - padding[2]) : tClipHeight = this._textHeight;
  14565. tClipWidth *= bitmapScale;
  14566. tClipHeight *= bitmapScale;
  14567. graphics.clipRect(padding[3], padding[0], tClipWidth, tClipHeight);
  14568. }
  14569. else {
  14570. 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);
  14571. }
  14572. this.repaint();
  14573. }
  14574. var password = style.asPassword;
  14575. if (("prompt" in this) && this['prompt'] == this._text)
  14576. password = false;
  14577. var x = 0, y = 0;
  14578. var end = Math.min(this._lines.length, visibleLineCount + beginLine) || 1;
  14579. for (var i = beginLine; i < end; i++) {
  14580. var word = lines[i];
  14581. var _word;
  14582. if (password) {
  14583. var len = word.length;
  14584. word = "";
  14585. for (var j = len; j > 0; j--) {
  14586. word += "●";
  14587. }
  14588. }
  14589. if (word == null)
  14590. word = "";
  14591. x = startX - (this._clipPoint ? this._clipPoint.x : 0);
  14592. y = startY + lineHeight * i - (this._clipPoint ? this._clipPoint.y : 0);
  14593. this.underline && this._drawUnderline(textAlgin, x, y, i);
  14594. if (tCurrBitmapFont) {
  14595. var tWidth = this.width;
  14596. if (tCurrBitmapFont.autoScaleSize) {
  14597. tWidth = this.width * bitmapScale;
  14598. }
  14599. tCurrBitmapFont._drawText(word, this, x, y, this.align, tWidth);
  14600. }
  14601. else {
  14602. this._words || (this._words = []);
  14603. if (this._words.length > (i - beginLine)) {
  14604. _word = this._words[i - beginLine];
  14605. }
  14606. else {
  14607. _word = new WordText();
  14608. this._words.push(_word);
  14609. }
  14610. _word.setText(word);
  14611. _word.splitRender = this._singleCharRender;
  14612. style.stroke ? graphics.fillBorderText(_word, x, y, ctxFont, this.color, style.strokeColor, style.stroke, textAlgin) : graphics.fillText(_word, x, y, ctxFont, this.color, textAlgin);
  14613. }
  14614. }
  14615. if (tCurrBitmapFont && tCurrBitmapFont.autoScaleSize) {
  14616. var tScale = 1 / bitmapScale;
  14617. this.scale(tScale, tScale);
  14618. }
  14619. if (this._clipPoint)
  14620. graphics.restore();
  14621. this._startX = startX;
  14622. this._startY = startY;
  14623. }
  14624. _drawUnderline(align, x, y, lineIndex) {
  14625. var lineWidth = this._lineWidths[lineIndex];
  14626. switch (align) {
  14627. case 'center':
  14628. x -= lineWidth / 2;
  14629. break;
  14630. case 'right':
  14631. x -= lineWidth;
  14632. break;
  14633. case 'left':
  14634. default:
  14635. break;
  14636. }
  14637. y += this._charSize.height;
  14638. this._graphics.drawLine(x, y, x + lineWidth, y, this.underlineColor || this.color, 1);
  14639. }
  14640. typeset() {
  14641. this._isChanged = false;
  14642. if (!this._text) {
  14643. this._clipPoint = null;
  14644. this._textWidth = this._textHeight = 0;
  14645. this.graphics.clear(true);
  14646. return;
  14647. }
  14648. if (ILaya.Render.isConchApp) {
  14649. window.conchTextCanvas.font = this._getContextFont();
  14650. }
  14651. else {
  14652. ILaya.Browser.context.font = this._getContextFont();
  14653. }
  14654. this._lines.length = 0;
  14655. this._lineWidths.length = 0;
  14656. if (this._isPassWordMode()) {
  14657. this._parseLines(this._getPassWordTxt(this._text));
  14658. }
  14659. else
  14660. this._parseLines(this._text);
  14661. this._evalTextSize();
  14662. if (this._checkEnabledViewportOrNot())
  14663. this._clipPoint || (this._clipPoint = new Point(0, 0));
  14664. else
  14665. this._clipPoint = null;
  14666. this._renderText();
  14667. }
  14668. _evalTextSize() {
  14669. var nw, nh;
  14670. nw = Math.max.apply(this, this._lineWidths);
  14671. if (this._style.currBitmapFont)
  14672. nh = this._lines.length * (this._style.currBitmapFont.getMaxHeight() + this.leading) + this.padding[0] + this.padding[2];
  14673. else
  14674. nh = this._lines.length * (this._charSize.height + this.leading) + this.padding[0] + this.padding[2];
  14675. if (nw != this._textWidth || nh != this._textHeight) {
  14676. this._textWidth = nw;
  14677. this._textHeight = nh;
  14678. }
  14679. }
  14680. _checkEnabledViewportOrNot() {
  14681. return this.overflow == Text.SCROLL && ((this._width > 0 && this._textWidth > this._width) || (this._height > 0 && this._textHeight > this._height));
  14682. }
  14683. changeText(text) {
  14684. if (this._text !== text) {
  14685. this.lang(text + "");
  14686. if (this._graphics && this._graphics.replaceText(this._text)) ;
  14687. else {
  14688. this.typeset();
  14689. }
  14690. }
  14691. }
  14692. _parseLines(text) {
  14693. var needWordWrapOrTruncate = this.wordWrap || this.overflow == Text.HIDDEN;
  14694. if (needWordWrapOrTruncate) {
  14695. var wordWrapWidth = this._getWordWrapWidth();
  14696. }
  14697. var bitmapFont = this._style.currBitmapFont;
  14698. if (bitmapFont) {
  14699. this._charSize.width = bitmapFont.getMaxWidth();
  14700. this._charSize.height = bitmapFont.getMaxHeight();
  14701. }
  14702. else {
  14703. var measureResult = null;
  14704. if (ILaya.Render.isConchApp) {
  14705. measureResult = window.conchTextCanvas.measureText(Text._testWord);
  14706. }
  14707. else {
  14708. measureResult = ILaya.Browser.context.measureText(Text._testWord);
  14709. }
  14710. if (!measureResult)
  14711. measureResult = { width: 100 };
  14712. this._charSize.width = measureResult.width;
  14713. this._charSize.height = (measureResult.height || this.fontSize);
  14714. }
  14715. var lines = text.replace(/\r\n/g, "\n").split("\n");
  14716. for (var i = 0, n = lines.length; i < n; i++) {
  14717. var line = lines[i];
  14718. if (needWordWrapOrTruncate)
  14719. this._parseLine(line, wordWrapWidth);
  14720. else {
  14721. this._lineWidths.push(this._getTextWidth(line));
  14722. this._lines.push(line);
  14723. }
  14724. }
  14725. }
  14726. _parseLine(line, wordWrapWidth) {
  14727. var lines = this._lines;
  14728. var maybeIndex = 0;
  14729. var charsWidth = 0;
  14730. var wordWidth = 0;
  14731. var startIndex = 0;
  14732. charsWidth = this._getTextWidth(line);
  14733. if (charsWidth <= wordWrapWidth) {
  14734. lines.push(line);
  14735. this._lineWidths.push(charsWidth);
  14736. return;
  14737. }
  14738. charsWidth = this._charSize.width;
  14739. maybeIndex = Math.floor(wordWrapWidth / charsWidth);
  14740. (maybeIndex == 0) && (maybeIndex = 1);
  14741. charsWidth = this._getTextWidth(line.substring(0, maybeIndex));
  14742. wordWidth = charsWidth;
  14743. for (var j = maybeIndex, m = line.length; j < m; j++) {
  14744. charsWidth = this._getTextWidth(line.charAt(j));
  14745. wordWidth += charsWidth;
  14746. if (wordWidth > wordWrapWidth) {
  14747. if (this.wordWrap) {
  14748. var newLine = line.substring(startIndex, j);
  14749. if (newLine.charCodeAt(newLine.length - 1) < 255) {
  14750. var execResult = /(?:\w|-)+$/.exec(newLine);
  14751. if (execResult) {
  14752. j = execResult.index + startIndex;
  14753. if (execResult.index == 0)
  14754. j += newLine.length;
  14755. else
  14756. newLine = line.substring(startIndex, j);
  14757. }
  14758. }
  14759. lines.push(newLine);
  14760. this._lineWidths.push(wordWidth - charsWidth);
  14761. startIndex = j;
  14762. if (j + maybeIndex < m) {
  14763. j += maybeIndex;
  14764. charsWidth = this._getTextWidth(line.substring(startIndex, j));
  14765. wordWidth = charsWidth;
  14766. j--;
  14767. }
  14768. else {
  14769. lines.push(line.substring(startIndex, m));
  14770. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14771. startIndex = -1;
  14772. break;
  14773. }
  14774. }
  14775. else if (this.overflow == Text.HIDDEN) {
  14776. lines.push(line.substring(0, j));
  14777. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14778. return;
  14779. }
  14780. }
  14781. }
  14782. if (this.wordWrap && startIndex != -1) {
  14783. lines.push(line.substring(startIndex, m));
  14784. this._lineWidths.push(this._getTextWidth(lines[lines.length - 1]));
  14785. }
  14786. }
  14787. _getTextWidth(text) {
  14788. var bitmapFont = this._style.currBitmapFont;
  14789. if (bitmapFont)
  14790. return bitmapFont.getTextWidth(text);
  14791. else {
  14792. if (ILaya.Render.isConchApp) {
  14793. return window.conchTextCanvas.measureText(text).width;
  14794. }
  14795. else
  14796. return ILaya.Browser.context.measureText(text).width;
  14797. }
  14798. }
  14799. _getWordWrapWidth() {
  14800. var p = this.padding;
  14801. var w;
  14802. var bitmapFont = this._style.currBitmapFont;
  14803. if (bitmapFont && bitmapFont.autoScaleSize)
  14804. w = this._width * (bitmapFont.fontSize / this.fontSize);
  14805. else
  14806. w = this._width;
  14807. if (w <= 0) {
  14808. w = this.wordWrap ? 100 : ILaya.Browser.width;
  14809. }
  14810. w <= 0 && (w = 100);
  14811. return w - p[3] - p[1];
  14812. }
  14813. getCharPoint(charIndex, out = null) {
  14814. this._isChanged && ILaya.systemTimer.runCallLater(this, this.typeset);
  14815. var len = 0, lines = this._lines, startIndex = 0;
  14816. for (var i = 0, n = lines.length; i < n; i++) {
  14817. len += lines[i].length;
  14818. if (charIndex < len) {
  14819. var line = i;
  14820. break;
  14821. }
  14822. startIndex = len;
  14823. }
  14824. var ctxFont = (this.italic ? "italic " : "") + (this.bold ? "bold " : "") + this.fontSize + "px " + this.font;
  14825. ILaya.Browser.context.font = ctxFont;
  14826. var width = this._getTextWidth(this._text.substring(startIndex, charIndex));
  14827. var point = out || new Point();
  14828. 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));
  14829. }
  14830. set scrollX(value) {
  14831. if (this.overflow != Text.SCROLL || (this.textWidth < this._width || !this._clipPoint))
  14832. return;
  14833. value = value < this.padding[3] ? this.padding[3] : value;
  14834. var maxScrollX = this._textWidth - this._width;
  14835. value = value > maxScrollX ? maxScrollX : value;
  14836. this._clipPoint.x = value;
  14837. this._renderText();
  14838. }
  14839. get scrollX() {
  14840. if (!this._clipPoint)
  14841. return 0;
  14842. return this._clipPoint.x;
  14843. }
  14844. set scrollY(value) {
  14845. if (this.overflow != Text.SCROLL || (this.textHeight < this._height || !this._clipPoint))
  14846. return;
  14847. value = value < this.padding[0] ? this.padding[0] : value;
  14848. var maxScrollY = this._textHeight - this._height;
  14849. value = value > maxScrollY ? maxScrollY : value;
  14850. this._clipPoint.y = value;
  14851. this._renderText();
  14852. }
  14853. get scrollY() {
  14854. if (!this._clipPoint)
  14855. return 0;
  14856. return this._clipPoint.y;
  14857. }
  14858. get maxScrollX() {
  14859. return (this.textWidth < this._width) ? 0 : this._textWidth - this._width;
  14860. }
  14861. get maxScrollY() {
  14862. return (this.textHeight < this._height) ? 0 : this._textHeight - this._height;
  14863. }
  14864. get lines() {
  14865. if (this._isChanged)
  14866. this.typeset();
  14867. return this._lines;
  14868. }
  14869. get underlineColor() {
  14870. return this._style.underlineColor;
  14871. }
  14872. set underlineColor(value) {
  14873. this._getTextStyle().underlineColor = value;
  14874. if (!this._isChanged)
  14875. this._renderText();
  14876. }
  14877. get underline() {
  14878. return this._style.underline;
  14879. }
  14880. set underline(value) {
  14881. this._getTextStyle().underline = value;
  14882. }
  14883. set singleCharRender(value) {
  14884. this._singleCharRender = value;
  14885. }
  14886. get singleCharRender() {
  14887. return this._singleCharRender;
  14888. }
  14889. }
  14890. Text.VISIBLE = "visible";
  14891. Text.SCROLL = "scroll";
  14892. Text.HIDDEN = "hidden";
  14893. Text.defaultFontSize = 12;
  14894. Text.defaultFont = "Arial";
  14895. Text.isComplexText = false;
  14896. Text.fontFamilyMap = { "报隶": "报隶-简", "黑体": "黑体-简", "楷体": "楷体-简", "兰亭黑": "兰亭黑-简", "隶变": "隶变-简", "凌慧体": "凌慧体-简", "翩翩体": "翩翩体-简", "苹方": "苹方-简", "手札体": "手札体-简", "宋体": "宋体-简", "娃娃体": "娃娃体-简", "魏碑": "魏碑-简", "行楷": "行楷-简", "雅痞": "雅痞-简", "圆体": "圆体-简" };
  14897. Text._testWord = "游";
  14898. Text.CharacterCache = true;
  14899. Text.RightToLeft = false;
  14900. ILaya.regClass(Text);
  14901. ClassUtils.regClass("laya.display.Text", Text);
  14902. ClassUtils.regClass("Laya.Text", Text);
  14903. class Input extends Text {
  14904. constructor() {
  14905. super();
  14906. this._multiline = false;
  14907. this._editable = true;
  14908. this._maxChars = 1E5;
  14909. this._type = "text";
  14910. this._prompt = '';
  14911. this._promptColor = "#A9A9A9";
  14912. this._originColor = "#000000";
  14913. this._content = '';
  14914. Input.IOS_IFRAME = (ILaya.Browser.onIOS && ILaya.Browser.window.top != ILaya.Browser.window.self);
  14915. this._width = 100;
  14916. this._height = 20;
  14917. this.multiline = false;
  14918. this.overflow = Text.SCROLL;
  14919. this.on(Event.MOUSE_DOWN, this, this._onMouseDown);
  14920. this.on(Event.UNDISPLAY, this, this._onUnDisplay);
  14921. }
  14922. static __init__() {
  14923. Input._createInputElement();
  14924. if (ILaya.Browser.onMobile) {
  14925. var isTrue = false;
  14926. if (ILaya.Browser.onMiniGame || ILaya.Browser.onBDMiniGame || ILaya.Browser.onQGMiniGame || ILaya.Browser.onKGMiniGame || ILaya.Browser.onVVMiniGame || ILaya.Browser.onAlipayMiniGame || ILaya.Browser.onQQMiniGame) {
  14927. isTrue = true;
  14928. }
  14929. ILaya.Render.canvas.addEventListener(Input.IOS_IFRAME ? (isTrue ? "touchend" : "click") : "touchend", Input._popupInputMethod);
  14930. }
  14931. }
  14932. static _popupInputMethod(e) {
  14933. if (!Input.isInputting)
  14934. return;
  14935. var input = Input.inputElement;
  14936. input.focus();
  14937. }
  14938. static _createInputElement() {
  14939. Input._initInput(Input.area = ILaya.Browser.createElement("textarea"));
  14940. Input._initInput(Input.input = ILaya.Browser.createElement("input"));
  14941. Input.inputContainer = ILaya.Browser.createElement("div");
  14942. Input.inputContainer.style.position = "absolute";
  14943. Input.inputContainer.style.zIndex = 1E5;
  14944. ILaya.Browser.container.appendChild(Input.inputContainer);
  14945. Input.inputContainer.setPos = function (x, y) {
  14946. Input.inputContainer.style.left = x + 'px';
  14947. Input.inputContainer.style.top = y + 'px';
  14948. };
  14949. }
  14950. static _initInput(input) {
  14951. var style = input.style;
  14952. 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;";
  14953. style.resize = 'none';
  14954. style.backgroundColor = 'transparent';
  14955. style.border = 'none';
  14956. style.outline = 'none';
  14957. style.zIndex = 1;
  14958. input.addEventListener('input', Input._processInputting);
  14959. input.addEventListener('mousemove', Input._stopEvent);
  14960. input.addEventListener('mousedown', Input._stopEvent);
  14961. input.addEventListener('touchmove', Input._stopEvent);
  14962. input.setFontFace = function (fontFace) { input.style.fontFamily = fontFace; };
  14963. if (!ILaya.Render.isConchApp) {
  14964. input.setColor = function (color) { input.style.color = color; };
  14965. input.setFontSize = function (fontSize) { input.style.fontSize = fontSize + 'px'; };
  14966. }
  14967. }
  14968. static _processInputting(e) {
  14969. var input = Input.inputElement.target;
  14970. if (!input)
  14971. return;
  14972. var value = Input.inputElement.value;
  14973. if (input._restrictPattern) {
  14974. value = value.replace(/\u2006|\x27/g, "");
  14975. if (input._restrictPattern.test(value)) {
  14976. value = value.replace(input._restrictPattern, "");
  14977. Input.inputElement.value = value;
  14978. }
  14979. }
  14980. input._text = value;
  14981. input.event(Event.INPUT);
  14982. }
  14983. static _stopEvent(e) {
  14984. if (e.type == 'touchmove')
  14985. e.preventDefault();
  14986. e.stopPropagation && e.stopPropagation();
  14987. }
  14988. setSelection(startIndex, endIndex) {
  14989. this.focus = true;
  14990. Input.inputElement.selectionStart = startIndex;
  14991. Input.inputElement.selectionEnd = endIndex;
  14992. }
  14993. get multiline() {
  14994. return this._multiline;
  14995. }
  14996. set multiline(value) {
  14997. this._multiline = value;
  14998. this.valign = value ? "top" : "middle";
  14999. }
  15000. get nativeInput() {
  15001. return this._multiline ? Input.area : Input.input;
  15002. }
  15003. _onUnDisplay(e = null) {
  15004. this.focus = false;
  15005. }
  15006. _onMouseDown(e) {
  15007. this.focus = true;
  15008. }
  15009. _syncInputTransform() {
  15010. var inputElement = this.nativeInput;
  15011. var transform = Utils.getTransformRelativeToWindow(this, this.padding[3], this.padding[0]);
  15012. var inputWid = this._width - this.padding[1] - this.padding[3];
  15013. var inputHei = this._height - this.padding[0] - this.padding[2];
  15014. if (ILaya.Render.isConchApp) {
  15015. inputElement.setScale(transform.scaleX, transform.scaleY);
  15016. inputElement.setSize(inputWid, inputHei);
  15017. inputElement.setPos(transform.x, transform.y);
  15018. }
  15019. else {
  15020. Input.inputContainer.style.transform = Input.inputContainer.style.webkitTransform = "scale(" + transform.scaleX + "," + transform.scaleY + ") rotate(" + (ILaya.stage.canvasDegree) + "deg)";
  15021. inputElement.style.width = inputWid + 'px';
  15022. inputElement.style.height = inputHei + 'px';
  15023. Input.inputContainer.style.left = transform.x + 'px';
  15024. Input.inputContainer.style.top = transform.y + 'px';
  15025. }
  15026. }
  15027. select() {
  15028. this.nativeInput.select();
  15029. }
  15030. get focus() {
  15031. return this._focus;
  15032. }
  15033. set focus(value) {
  15034. var input = this.nativeInput;
  15035. if (this._focus !== value) {
  15036. if (value) {
  15037. if (input.target) {
  15038. input.target._focusOut();
  15039. }
  15040. else {
  15041. this._setInputMethod();
  15042. }
  15043. input.target = this;
  15044. this._focusIn();
  15045. }
  15046. else {
  15047. input.target = null;
  15048. this._focusOut();
  15049. ILaya.Browser.document.body.scrollTop = 0;
  15050. input.blur();
  15051. if (ILaya.Render.isConchApp)
  15052. input.setPos(-10000, -10000);
  15053. else if (Input.inputContainer.contains(input))
  15054. Input.inputContainer.removeChild(input);
  15055. }
  15056. }
  15057. }
  15058. _setInputMethod() {
  15059. Input.input.parentElement && (Input.inputContainer.removeChild(Input.input));
  15060. Input.area.parentElement && (Input.inputContainer.removeChild(Input.area));
  15061. Input.inputElement = (this._multiline ? Input.area : Input.input);
  15062. Input.inputContainer.appendChild(Input.inputElement);
  15063. if (Text.RightToLeft) {
  15064. Input.inputElement.style.direction = "rtl";
  15065. }
  15066. }
  15067. _focusIn() {
  15068. Input.isInputting = true;
  15069. var input = this.nativeInput;
  15070. this._focus = true;
  15071. var cssStyle = input.style;
  15072. cssStyle.whiteSpace = (this.wordWrap ? "pre-wrap" : "nowrap");
  15073. this._setPromptColor();
  15074. input.readOnly = !this._editable;
  15075. if (ILaya.Render.isConchApp) {
  15076. input.setType(this._type);
  15077. input.setForbidEdit(!this._editable);
  15078. }
  15079. input.maxLength = this._maxChars;
  15080. var padding = this.padding;
  15081. input.value = this._content;
  15082. input.placeholder = this._prompt;
  15083. ILaya.stage.off(Event.KEY_DOWN, this, this._onKeyDown);
  15084. ILaya.stage.on(Event.KEY_DOWN, this, this._onKeyDown);
  15085. ILaya.stage.focus = this;
  15086. this.event(Event.FOCUS);
  15087. if (ILaya.Browser.onPC)
  15088. input.focus();
  15089. if (!ILaya.Browser.onMiniGame && !ILaya.Browser.onBDMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame) {
  15090. var temp = this._text;
  15091. this._text = null;
  15092. }
  15093. this.typeset();
  15094. input.setColor(this._originColor);
  15095. input.setFontSize(this.fontSize);
  15096. input.setFontFace(ILaya.Browser.onIPhone ? (Text.fontFamilyMap[this.font] || this.font) : this.font);
  15097. if (ILaya.Render.isConchApp) {
  15098. input.setMultiAble && input.setMultiAble(this._multiline);
  15099. }
  15100. cssStyle.lineHeight = (this.leading + this.fontSize) + "px";
  15101. cssStyle.fontStyle = (this.italic ? "italic" : "normal");
  15102. cssStyle.fontWeight = (this.bold ? "bold" : "normal");
  15103. cssStyle.textAlign = this.align;
  15104. cssStyle.padding = "0 0";
  15105. this._syncInputTransform();
  15106. if (!ILaya.Render.isConchApp && ILaya.Browser.onPC)
  15107. ILaya.systemTimer.frameLoop(1, this, this._syncInputTransform);
  15108. }
  15109. _setPromptColor() {
  15110. Input.promptStyleDOM = ILaya.Browser.getElementById("promptStyle");
  15111. if (!Input.promptStyleDOM) {
  15112. Input.promptStyleDOM = ILaya.Browser.createElement("style");
  15113. Input.promptStyleDOM.setAttribute("id", "promptStyle");
  15114. ILaya.Browser.document.head.appendChild(Input.promptStyleDOM);
  15115. }
  15116. 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 + "}";
  15117. }
  15118. _focusOut() {
  15119. Input.isInputting = false;
  15120. this._focus = false;
  15121. this._text = null;
  15122. this._content = this.nativeInput.value;
  15123. if (!this._content) {
  15124. super.set_text(this._prompt);
  15125. super.set_color(this._promptColor);
  15126. }
  15127. else {
  15128. super.set_text(this._content);
  15129. super.set_color(this._originColor);
  15130. }
  15131. ILaya.stage.off(Event.KEY_DOWN, this, this._onKeyDown);
  15132. ILaya.stage.focus = null;
  15133. this.event(Event.BLUR);
  15134. this.event(Event.CHANGE);
  15135. if (ILaya.Render.isConchApp)
  15136. this.nativeInput.blur();
  15137. ILaya.Browser.onPC && ILaya.systemTimer.clear(this, this._syncInputTransform);
  15138. }
  15139. _onKeyDown(e) {
  15140. if (e.keyCode === 13) {
  15141. if (ILaya.Browser.onMobile && !this._multiline)
  15142. this.focus = false;
  15143. this.event(Event.ENTER);
  15144. }
  15145. }
  15146. set text(value) {
  15147. super.set_color(this._originColor);
  15148. value += '';
  15149. if (this._focus) {
  15150. this.nativeInput.value = value || '';
  15151. this.event(Event.CHANGE);
  15152. }
  15153. else {
  15154. if (!this._multiline)
  15155. value = value.replace(/\r?\n/g, '');
  15156. this._content = value;
  15157. if (value)
  15158. super.set_text(value);
  15159. else {
  15160. super.set_text(this._prompt);
  15161. super.set_color(this.promptColor);
  15162. }
  15163. }
  15164. }
  15165. get text() {
  15166. if (this._focus)
  15167. return this.nativeInput.value;
  15168. else
  15169. return this._content || "";
  15170. }
  15171. changeText(text) {
  15172. this._content = text;
  15173. if (this._focus) {
  15174. this.nativeInput.value = text || '';
  15175. this.event(Event.CHANGE);
  15176. }
  15177. else
  15178. super.changeText(text);
  15179. }
  15180. set color(value) {
  15181. if (this._focus)
  15182. this.nativeInput.setColor(value);
  15183. super.set_color(this._content ? value : this._promptColor);
  15184. this._originColor = value;
  15185. }
  15186. get color() {
  15187. return super.color;
  15188. }
  15189. set bgColor(value) {
  15190. super.set_bgColor(value);
  15191. if (ILaya.Render.isConchApp)
  15192. this.nativeInput.setBgColor(value);
  15193. }
  15194. get bgColor() {
  15195. return super.bgColor;
  15196. }
  15197. get restrict() {
  15198. if (this._restrictPattern) {
  15199. return this._restrictPattern.source;
  15200. }
  15201. return "";
  15202. }
  15203. set restrict(pattern) {
  15204. if (pattern) {
  15205. pattern = "[^" + pattern + "]";
  15206. if (pattern.indexOf("^^") > -1)
  15207. pattern = pattern.replace("^^", "");
  15208. this._restrictPattern = new RegExp(pattern, "g");
  15209. }
  15210. else
  15211. this._restrictPattern = null;
  15212. }
  15213. set editable(value) {
  15214. this._editable = value;
  15215. if (ILaya.Render.isConchApp) {
  15216. Input.input.setForbidEdit(!value);
  15217. }
  15218. }
  15219. get editable() {
  15220. return this._editable;
  15221. }
  15222. get maxChars() {
  15223. return this._maxChars;
  15224. }
  15225. set maxChars(value) {
  15226. if (value <= 0)
  15227. value = 1E5;
  15228. this._maxChars = value;
  15229. }
  15230. get prompt() {
  15231. return this._prompt;
  15232. }
  15233. set prompt(value) {
  15234. if (!this._text && value)
  15235. super.set_color(this._promptColor);
  15236. this.promptColor = this._promptColor;
  15237. if (this._text)
  15238. super.set_text((this._text == this._prompt) ? value : this._text);
  15239. else
  15240. super.set_text(value);
  15241. this._prompt = Text.langPacks && Text.langPacks[value] ? Text.langPacks[value] : value;
  15242. }
  15243. get promptColor() {
  15244. return this._promptColor;
  15245. }
  15246. set promptColor(value) {
  15247. this._promptColor = value;
  15248. if (!this._content)
  15249. super.set_color(value);
  15250. }
  15251. get type() {
  15252. return this._type;
  15253. }
  15254. set type(value) {
  15255. if (value === "password")
  15256. this._getTextStyle().asPassword = true;
  15257. else
  15258. this._getTextStyle().asPassword = false;
  15259. this._type = value;
  15260. }
  15261. }
  15262. Input.TYPE_TEXT = "text";
  15263. Input.TYPE_PASSWORD = "password";
  15264. Input.TYPE_EMAIL = "email";
  15265. Input.TYPE_URL = "url";
  15266. Input.TYPE_NUMBER = "number";
  15267. Input.TYPE_RANGE = "range";
  15268. Input.TYPE_DATE = "date";
  15269. Input.TYPE_MONTH = "month";
  15270. Input.TYPE_WEEK = "week";
  15271. Input.TYPE_TIME = "time";
  15272. Input.TYPE_DATE_TIME = "datetime";
  15273. Input.TYPE_DATE_TIME_LOCAL = "datetime-local";
  15274. Input.TYPE_SEARCH = "search";
  15275. Input.IOS_IFRAME = false;
  15276. Input.inputHeight = 45;
  15277. Input.isInputting = false;
  15278. ClassUtils.regClass("laya.display.Input", Input);
  15279. ClassUtils.regClass("Laya.Input", Input);
  15280. class TouchManager {
  15281. constructor() {
  15282. this.preOvers = [];
  15283. this.preDowns = [];
  15284. this.preRightDowns = [];
  15285. this.enable = true;
  15286. this._event = new Event();
  15287. this._lastClickTime = 0;
  15288. }
  15289. _clearTempArrs() {
  15290. TouchManager._oldArr.length = 0;
  15291. TouchManager._newArr.length = 0;
  15292. TouchManager._tEleArr.length = 0;
  15293. }
  15294. getTouchFromArr(touchID, arr) {
  15295. var i, len;
  15296. len = arr.length;
  15297. var tTouchO;
  15298. for (i = 0; i < len; i++) {
  15299. tTouchO = arr[i];
  15300. if (tTouchO.id == touchID) {
  15301. return tTouchO;
  15302. }
  15303. }
  15304. return null;
  15305. }
  15306. removeTouchFromArr(touchID, arr) {
  15307. var i;
  15308. for (i = arr.length - 1; i >= 0; i--) {
  15309. if (arr[i].id == touchID) {
  15310. arr.splice(i, 1);
  15311. }
  15312. }
  15313. }
  15314. createTouchO(ele, touchID) {
  15315. var rst;
  15316. rst = Pool.getItem("TouchData") || {};
  15317. rst.id = touchID;
  15318. rst.tar = ele;
  15319. return rst;
  15320. }
  15321. onMouseDown(ele, touchID, isLeft = false) {
  15322. if (!this.enable)
  15323. return;
  15324. var preO;
  15325. var tO;
  15326. var arrs;
  15327. preO = this.getTouchFromArr(touchID, this.preOvers);
  15328. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15329. if (!preO) {
  15330. tO = this.createTouchO(ele, touchID);
  15331. this.preOvers.push(tO);
  15332. }
  15333. else {
  15334. preO.tar = ele;
  15335. }
  15336. if (Browser.onMobile)
  15337. this.sendEvents(arrs, Event.MOUSE_OVER);
  15338. var preDowns;
  15339. preDowns = isLeft ? this.preDowns : this.preRightDowns;
  15340. preO = this.getTouchFromArr(touchID, preDowns);
  15341. if (!preO) {
  15342. tO = this.createTouchO(ele, touchID);
  15343. preDowns.push(tO);
  15344. }
  15345. else {
  15346. preO.tar = ele;
  15347. }
  15348. this.sendEvents(arrs, isLeft ? Event.MOUSE_DOWN : Event.RIGHT_MOUSE_DOWN);
  15349. this._clearTempArrs();
  15350. }
  15351. sendEvents(eles, type) {
  15352. var i, len;
  15353. len = eles.length;
  15354. this._event._stoped = false;
  15355. var _target;
  15356. _target = eles[0];
  15357. for (i = 0; i < len; i++) {
  15358. var tE = eles[i];
  15359. if (tE.destroyed)
  15360. return;
  15361. tE.event(type, this._event.setTo(type, tE, _target));
  15362. if (this._event._stoped)
  15363. break;
  15364. }
  15365. }
  15366. getEles(start, end = null, rst = null) {
  15367. if (!rst) {
  15368. rst = [];
  15369. }
  15370. else {
  15371. rst.length = 0;
  15372. }
  15373. while (start && start != end) {
  15374. rst.push(start);
  15375. start = start.parent;
  15376. }
  15377. return rst;
  15378. }
  15379. checkMouseOutAndOverOfMove(eleNew, elePre, touchID = 0) {
  15380. if (elePre == eleNew)
  15381. return;
  15382. var tar;
  15383. var arrs;
  15384. var i, len;
  15385. if (elePre.contains(eleNew)) {
  15386. arrs = this.getEles(eleNew, elePre, TouchManager._tEleArr);
  15387. this.sendEvents(arrs, Event.MOUSE_OVER);
  15388. }
  15389. else if (eleNew.contains(elePre)) {
  15390. arrs = this.getEles(elePre, eleNew, TouchManager._tEleArr);
  15391. this.sendEvents(arrs, Event.MOUSE_OUT);
  15392. }
  15393. else {
  15394. arrs = TouchManager._tEleArr;
  15395. arrs.length = 0;
  15396. var oldArr;
  15397. oldArr = this.getEles(elePre, null, TouchManager._oldArr);
  15398. var newArr;
  15399. newArr = this.getEles(eleNew, null, TouchManager._newArr);
  15400. len = oldArr.length;
  15401. var tIndex;
  15402. for (i = 0; i < len; i++) {
  15403. tar = oldArr[i];
  15404. tIndex = newArr.indexOf(tar);
  15405. if (tIndex >= 0) {
  15406. newArr.splice(tIndex, newArr.length - tIndex);
  15407. break;
  15408. }
  15409. else {
  15410. arrs.push(tar);
  15411. }
  15412. }
  15413. if (arrs.length > 0) {
  15414. this.sendEvents(arrs, Event.MOUSE_OUT);
  15415. }
  15416. if (newArr.length > 0) {
  15417. this.sendEvents(newArr, Event.MOUSE_OVER);
  15418. }
  15419. }
  15420. }
  15421. onMouseMove(ele, touchID) {
  15422. if (!this.enable)
  15423. return;
  15424. var preO;
  15425. preO = this.getTouchFromArr(touchID, this.preOvers);
  15426. var arrs;
  15427. if (!preO) {
  15428. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15429. this.sendEvents(arrs, Event.MOUSE_OVER);
  15430. this.preOvers.push(this.createTouchO(ele, touchID));
  15431. }
  15432. else {
  15433. this.checkMouseOutAndOverOfMove(ele, preO.tar);
  15434. preO.tar = ele;
  15435. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15436. }
  15437. this.sendEvents(arrs, Event.MOUSE_MOVE);
  15438. this._clearTempArrs();
  15439. }
  15440. getLastOvers() {
  15441. TouchManager._tEleArr.length = 0;
  15442. if (this.preOvers.length > 0 && this.preOvers[0].tar) {
  15443. return this.getEles(this.preOvers[0].tar, null, TouchManager._tEleArr);
  15444. }
  15445. TouchManager._tEleArr.push(ILaya.stage);
  15446. return TouchManager._tEleArr;
  15447. }
  15448. stageMouseOut() {
  15449. var lastOvers;
  15450. lastOvers = this.getLastOvers();
  15451. this.preOvers.length = 0;
  15452. this.sendEvents(lastOvers, Event.MOUSE_OUT);
  15453. }
  15454. onMouseUp(ele, touchID, isLeft = false) {
  15455. if (!this.enable)
  15456. return;
  15457. var preO;
  15458. var arrs;
  15459. var oldArr;
  15460. var i, len;
  15461. var tar;
  15462. var sendArr;
  15463. var onMobile = Browser.onMobile;
  15464. arrs = this.getEles(ele, null, TouchManager._tEleArr);
  15465. this.sendEvents(arrs, isLeft ? Event.MOUSE_UP : Event.RIGHT_MOUSE_UP);
  15466. var preDowns;
  15467. preDowns = isLeft ? this.preDowns : this.preRightDowns;
  15468. preO = this.getTouchFromArr(touchID, preDowns);
  15469. if (!preO) ;
  15470. else {
  15471. var isDouble;
  15472. var now = Browser.now();
  15473. isDouble = now - this._lastClickTime < 300;
  15474. this._lastClickTime = now;
  15475. if (ele == preO.tar) {
  15476. sendArr = arrs;
  15477. }
  15478. else {
  15479. oldArr = this.getEles(preO.tar, null, TouchManager._oldArr);
  15480. sendArr = TouchManager._newArr;
  15481. sendArr.length = 0;
  15482. len = oldArr.length;
  15483. for (i = 0; i < len; i++) {
  15484. tar = oldArr[i];
  15485. if (arrs.indexOf(tar) >= 0) {
  15486. sendArr.push(tar);
  15487. }
  15488. }
  15489. }
  15490. if (sendArr.length > 0) {
  15491. this.sendEvents(sendArr, isLeft ? Event.CLICK : Event.RIGHT_CLICK);
  15492. }
  15493. if (isLeft && isDouble) {
  15494. this.sendEvents(sendArr, Event.DOUBLE_CLICK);
  15495. }
  15496. this.removeTouchFromArr(touchID, preDowns);
  15497. preO.tar = null;
  15498. Pool.recover("TouchData", preO);
  15499. }
  15500. preO = this.getTouchFromArr(touchID, this.preOvers);
  15501. if (!preO) ;
  15502. else {
  15503. if (onMobile) {
  15504. sendArr = this.getEles(preO.tar, null, sendArr);
  15505. if (sendArr && sendArr.length > 0) {
  15506. this.sendEvents(sendArr, Event.MOUSE_OUT);
  15507. }
  15508. this.removeTouchFromArr(touchID, this.preOvers);
  15509. preO.tar = null;
  15510. Pool.recover("TouchData", preO);
  15511. }
  15512. }
  15513. this._clearTempArrs();
  15514. }
  15515. }
  15516. TouchManager.I = new TouchManager();
  15517. TouchManager._oldArr = [];
  15518. TouchManager._newArr = [];
  15519. TouchManager._tEleArr = [];
  15520. class MouseManager {
  15521. constructor() {
  15522. this.mouseX = 0;
  15523. this.mouseY = 0;
  15524. this.disableMouseEvent = false;
  15525. this.mouseDownTime = 0;
  15526. this.mouseMoveAccuracy = 2;
  15527. this._event = new Event();
  15528. this._captureSp = null;
  15529. this._captureChain = [];
  15530. this._captureExlusiveMode = false;
  15531. this._hitCaputreSp = false;
  15532. this._point = new Point();
  15533. this._rect = new Rectangle();
  15534. this._lastMoveTimer = 0;
  15535. this._prePoint = new Point();
  15536. this._touchIDs = {};
  15537. this._curTouchID = NaN;
  15538. this._id = 1;
  15539. }
  15540. __init__(stage, canvas) {
  15541. this._stage = stage;
  15542. var _this = this;
  15543. canvas.oncontextmenu = function (e) {
  15544. if (MouseManager.enabled)
  15545. return false;
  15546. };
  15547. canvas.addEventListener('mousedown', function (e) {
  15548. if (MouseManager.enabled) {
  15549. if (!Browser.onIE)
  15550. e.preventDefault();
  15551. _this.mouseDownTime = Browser.now();
  15552. _this.runEvent(e);
  15553. }
  15554. });
  15555. canvas.addEventListener('mouseup', function (e) {
  15556. if (MouseManager.enabled) {
  15557. e.preventDefault();
  15558. _this.mouseDownTime = -Browser.now();
  15559. _this.runEvent(e);
  15560. }
  15561. }, true);
  15562. canvas.addEventListener('mousemove', function (e) {
  15563. if (MouseManager.enabled) {
  15564. e.preventDefault();
  15565. var now = Browser.now();
  15566. if (now - _this._lastMoveTimer < 10)
  15567. return;
  15568. _this._lastMoveTimer = now;
  15569. _this.runEvent(e);
  15570. }
  15571. }, true);
  15572. canvas.addEventListener("mouseout", function (e) {
  15573. if (MouseManager.enabled)
  15574. _this.runEvent(e);
  15575. });
  15576. canvas.addEventListener("mouseover", function (e) {
  15577. if (MouseManager.enabled)
  15578. _this.runEvent(e);
  15579. });
  15580. canvas.addEventListener("touchstart", function (e) {
  15581. if (MouseManager.enabled) {
  15582. if (!MouseManager._isFirstTouch && !Input.isInputting)
  15583. e.preventDefault();
  15584. _this.mouseDownTime = Browser.now();
  15585. _this.runEvent(e);
  15586. }
  15587. });
  15588. canvas.addEventListener("touchend", function (e) {
  15589. if (MouseManager.enabled) {
  15590. if (!MouseManager._isFirstTouch && !Input.isInputting)
  15591. e.preventDefault();
  15592. MouseManager._isFirstTouch = false;
  15593. _this.mouseDownTime = -Browser.now();
  15594. _this.runEvent(e);
  15595. }
  15596. else {
  15597. _this._curTouchID = NaN;
  15598. }
  15599. }, true);
  15600. canvas.addEventListener("touchmove", function (e) {
  15601. if (MouseManager.enabled) {
  15602. e.preventDefault();
  15603. _this.runEvent(e);
  15604. }
  15605. }, true);
  15606. canvas.addEventListener("touchcancel", function (e) {
  15607. if (MouseManager.enabled) {
  15608. e.preventDefault();
  15609. _this.runEvent(e);
  15610. }
  15611. else {
  15612. _this._curTouchID = NaN;
  15613. }
  15614. }, true);
  15615. canvas.addEventListener('mousewheel', function (e) {
  15616. if (MouseManager.enabled)
  15617. _this.runEvent(e);
  15618. });
  15619. canvas.addEventListener('DOMMouseScroll', function (e) {
  15620. if (MouseManager.enabled)
  15621. _this.runEvent(e);
  15622. });
  15623. }
  15624. initEvent(e, nativeEvent = null) {
  15625. var _this = this;
  15626. _this._event._stoped = false;
  15627. _this._event.nativeEvent = nativeEvent || e;
  15628. _this._target = null;
  15629. this._point.setTo(e.pageX || e.clientX, e.pageY || e.clientY);
  15630. if (this._stage._canvasTransform) {
  15631. this._stage._canvasTransform.invertTransformPoint(this._point);
  15632. _this.mouseX = this._point.x;
  15633. _this.mouseY = this._point.y;
  15634. }
  15635. _this._event.touchId = e.identifier || 0;
  15636. this._tTouchID = _this._event.touchId;
  15637. var evt;
  15638. evt = TouchManager.I._event;
  15639. evt._stoped = false;
  15640. evt.nativeEvent = _this._event.nativeEvent;
  15641. evt.touchId = _this._event.touchId;
  15642. }
  15643. checkMouseWheel(e) {
  15644. this._event.delta = e.wheelDelta ? e.wheelDelta * 0.025 : -e.detail;
  15645. var _lastOvers = TouchManager.I.getLastOvers();
  15646. for (var i = 0, n = _lastOvers.length; i < n; i++) {
  15647. var ele = _lastOvers[i];
  15648. ele.event(Event.MOUSE_WHEEL, this._event.setTo(Event.MOUSE_WHEEL, ele, this._target));
  15649. }
  15650. }
  15651. onMouseMove(ele) {
  15652. TouchManager.I.onMouseMove(ele, this._tTouchID);
  15653. }
  15654. onMouseDown(ele) {
  15655. if (Input.isInputting && ILaya.stage.focus && ILaya.stage.focus["focus"] && !ILaya.stage.focus.contains(this._target)) {
  15656. var pre_input = ILaya.stage.focus['_tf'] || ILaya.stage.focus;
  15657. var new_input = ele['_tf'] || ele;
  15658. if (new_input instanceof Input && new_input.multiline == pre_input.multiline)
  15659. pre_input['_focusOut']();
  15660. else
  15661. pre_input.focus = false;
  15662. }
  15663. TouchManager.I.onMouseDown(ele, this._tTouchID, this._isLeftMouse);
  15664. }
  15665. onMouseUp(ele) {
  15666. TouchManager.I.onMouseUp(ele, this._tTouchID, this._isLeftMouse);
  15667. }
  15668. check(sp, mouseX, mouseY, callBack) {
  15669. this._point.setTo(mouseX, mouseY);
  15670. sp.fromParentPoint(this._point);
  15671. mouseX = this._point.x;
  15672. mouseY = this._point.y;
  15673. var scrollRect = sp._style.scrollRect;
  15674. if (scrollRect) {
  15675. this._rect.setTo(scrollRect.x, scrollRect.y, scrollRect.width, scrollRect.height);
  15676. if (!this._rect.contains(mouseX, mouseY))
  15677. return false;
  15678. }
  15679. if (!this.disableMouseEvent) {
  15680. if (sp.hitTestPrior && !sp.mouseThrough && !this.hitTest(sp, mouseX, mouseY)) {
  15681. return false;
  15682. }
  15683. for (var i = sp._children.length - 1; i > -1; i--) {
  15684. var child = sp._children[i];
  15685. if (!child.destroyed && child._mouseState > 1 && child._visible) {
  15686. if (this.check(child, mouseX, mouseY, callBack))
  15687. return true;
  15688. }
  15689. }
  15690. for (i = sp._extUIChild.length - 1; i >= 0; i--) {
  15691. var c = sp._extUIChild[i];
  15692. if (!c.destroyed && c._mouseState > 1 && c._visible) {
  15693. if (this.check(c, mouseX, mouseY, callBack))
  15694. return true;
  15695. }
  15696. }
  15697. }
  15698. var isHit = (sp.hitTestPrior && !sp.mouseThrough && !this.disableMouseEvent) ? true : this.hitTest(sp, mouseX, mouseY);
  15699. if (isHit) {
  15700. this._target = sp;
  15701. callBack.call(this, sp);
  15702. if (this._target == this._hitCaputreSp) {
  15703. this._hitCaputreSp = true;
  15704. }
  15705. }
  15706. else if (callBack === this.onMouseUp && sp === this._stage) {
  15707. this._target = this._stage;
  15708. callBack.call(this, this._target);
  15709. }
  15710. return isHit;
  15711. }
  15712. hitTest(sp, mouseX, mouseY) {
  15713. var isHit = false;
  15714. if (sp.scrollRect) {
  15715. mouseX -= sp._style.scrollRect.x;
  15716. mouseY -= sp._style.scrollRect.y;
  15717. }
  15718. var hitArea = sp._style.hitArea;
  15719. if (hitArea && hitArea._hit) {
  15720. return hitArea.contains(mouseX, mouseY);
  15721. }
  15722. if (sp.width > 0 && sp.height > 0 || sp.mouseThrough || hitArea) {
  15723. if (!sp.mouseThrough) {
  15724. isHit = (hitArea ? hitArea : this._rect.setTo(0, 0, sp.width, sp.height)).contains(mouseX, mouseY);
  15725. }
  15726. else {
  15727. isHit = sp.getGraphicBounds().contains(mouseX, mouseY);
  15728. }
  15729. }
  15730. return isHit;
  15731. }
  15732. _checkAllBaseUI(mousex, mousey, callback) {
  15733. var ret = this.handleExclusiveCapture(this.mouseX, this.mouseY, callback);
  15734. if (ret)
  15735. return true;
  15736. ret = this.check(this._stage, this.mouseX, this.mouseY, callback);
  15737. return this.handleCapture(this.mouseX, this.mouseY, callback) || ret;
  15738. }
  15739. check3DUI(mousex, mousey, callback) {
  15740. var uis = this._stage._3dUI;
  15741. var i = 0;
  15742. var ret = false;
  15743. for (; i < uis.length; i++) {
  15744. var curui = uis[i];
  15745. this._stage._curUIBase = curui;
  15746. if (!curui.destroyed && curui._mouseState > 1 && curui._visible) {
  15747. ret = ret || this.check(curui, this.mouseX, this.mouseY, callback);
  15748. }
  15749. }
  15750. this._stage._curUIBase = this._stage;
  15751. return ret;
  15752. }
  15753. handleExclusiveCapture(mousex, mousey, callback) {
  15754. if (this._captureExlusiveMode && this._captureSp && this._captureChain.length > 0) {
  15755. var cursp;
  15756. this._point.setTo(mousex, mousey);
  15757. for (var i = 0; i < this._captureChain.length; i++) {
  15758. cursp = this._captureChain[i];
  15759. cursp.fromParentPoint(this._point);
  15760. }
  15761. this._target = cursp;
  15762. callback.call(this, cursp);
  15763. return true;
  15764. }
  15765. return false;
  15766. }
  15767. handleCapture(mousex, mousey, callback) {
  15768. if (!this._hitCaputreSp && this._captureSp && this._captureChain.length > 0) {
  15769. var cursp;
  15770. this._point.setTo(mousex, mousey);
  15771. for (var i = 0; i < this._captureChain.length; i++) {
  15772. cursp = this._captureChain[i];
  15773. cursp.fromParentPoint(this._point);
  15774. }
  15775. this._target = cursp;
  15776. callback.call(this, cursp);
  15777. return true;
  15778. }
  15779. return false;
  15780. }
  15781. runEvent(evt) {
  15782. var i, n, touch;
  15783. if (evt.type !== 'mousemove')
  15784. this._prePoint.x = this._prePoint.y = -1000000;
  15785. switch (evt.type) {
  15786. case 'mousedown':
  15787. this._touchIDs[0] = this._id++;
  15788. if (!MouseManager._isTouchRespond) {
  15789. this._isLeftMouse = evt.button === 0;
  15790. this.initEvent(evt);
  15791. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseDown);
  15792. }
  15793. else
  15794. MouseManager._isTouchRespond = false;
  15795. break;
  15796. case 'mouseup':
  15797. this._isLeftMouse = evt.button === 0;
  15798. this.initEvent(evt);
  15799. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseUp);
  15800. break;
  15801. case 'mousemove':
  15802. if ((Math.abs(this._prePoint.x - evt.clientX) + Math.abs(this._prePoint.y - evt.clientY)) >= this.mouseMoveAccuracy) {
  15803. this._prePoint.x = evt.clientX;
  15804. this._prePoint.y = evt.clientY;
  15805. this.initEvent(evt);
  15806. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseMove);
  15807. }
  15808. break;
  15809. case "touchstart":
  15810. MouseManager._isTouchRespond = true;
  15811. this._isLeftMouse = true;
  15812. var touches = evt.changedTouches;
  15813. for (i = 0, n = touches.length; i < n; i++) {
  15814. touch = touches[i];
  15815. if (MouseManager.multiTouchEnabled || isNaN(this._curTouchID)) {
  15816. this._curTouchID = touch.identifier;
  15817. if (this._id % 200 === 0)
  15818. this._touchIDs = {};
  15819. this._touchIDs[touch.identifier] = this._id++;
  15820. this.initEvent(touch, evt);
  15821. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseDown);
  15822. }
  15823. }
  15824. break;
  15825. case "touchend":
  15826. case "touchcancel":
  15827. MouseManager._isTouchRespond = true;
  15828. this._isLeftMouse = true;
  15829. var touchends = evt.changedTouches;
  15830. for (i = 0, n = touchends.length; i < n; i++) {
  15831. touch = touchends[i];
  15832. if (MouseManager.multiTouchEnabled || touch.identifier == this._curTouchID) {
  15833. this._curTouchID = NaN;
  15834. this.initEvent(touch, evt);
  15835. var isChecked;
  15836. isChecked = this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseUp);
  15837. if (!isChecked) {
  15838. this.onMouseUp(null);
  15839. }
  15840. }
  15841. }
  15842. break;
  15843. case "touchmove":
  15844. var touchemoves = evt.changedTouches;
  15845. for (i = 0, n = touchemoves.length; i < n; i++) {
  15846. touch = touchemoves[i];
  15847. if (MouseManager.multiTouchEnabled || touch.identifier == this._curTouchID) {
  15848. this.initEvent(touch, evt);
  15849. this._checkAllBaseUI(this.mouseX, this.mouseY, this.onMouseMove);
  15850. }
  15851. }
  15852. break;
  15853. case "wheel":
  15854. case "mousewheel":
  15855. case "DOMMouseScroll":
  15856. this.checkMouseWheel(evt);
  15857. break;
  15858. case "mouseout":
  15859. TouchManager.I.stageMouseOut();
  15860. break;
  15861. case "mouseover":
  15862. this._stage.event(Event.MOUSE_OVER, this._event.setTo(Event.MOUSE_OVER, this._stage, this._stage));
  15863. break;
  15864. }
  15865. }
  15866. setCapture(sp, exclusive = false) {
  15867. this._captureSp = sp;
  15868. this._captureExlusiveMode = exclusive;
  15869. this._captureChain.length = 0;
  15870. this._captureChain.push(sp);
  15871. var cursp = sp;
  15872. while (true) {
  15873. if (cursp == ILaya.stage)
  15874. break;
  15875. if (cursp == ILaya.stage._curUIBase)
  15876. break;
  15877. cursp = cursp.parent;
  15878. if (!cursp)
  15879. break;
  15880. this._captureChain.splice(0, 0, cursp);
  15881. }
  15882. }
  15883. releaseCapture() {
  15884. console.log('release capture');
  15885. this._captureSp = null;
  15886. }
  15887. }
  15888. MouseManager.instance = new MouseManager();
  15889. MouseManager.enabled = true;
  15890. MouseManager.multiTouchEnabled = true;
  15891. MouseManager._isFirstTouch = true;
  15892. class CallLater {
  15893. constructor() {
  15894. this._pool = [];
  15895. this._map = [];
  15896. this._laters = [];
  15897. }
  15898. _update() {
  15899. var laters = this._laters;
  15900. var len = laters.length;
  15901. if (len > 0) {
  15902. for (var i = 0, n = len - 1; i <= n; i++) {
  15903. var handler = laters[i];
  15904. this._map[handler.key] = null;
  15905. if (handler.method !== null) {
  15906. handler.run();
  15907. handler.clear();
  15908. }
  15909. this._pool.push(handler);
  15910. i === n && (n = laters.length - 1);
  15911. }
  15912. laters.length = 0;
  15913. }
  15914. }
  15915. _getHandler(caller, method) {
  15916. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  15917. var mid = method.$_TID || (method.$_TID = (ILaya.Timer._mid++) * 100000);
  15918. return this._map[cid + mid];
  15919. }
  15920. callLater(caller, method, args = null) {
  15921. if (this._getHandler(caller, method) == null) {
  15922. if (this._pool.length)
  15923. var handler = this._pool.pop();
  15924. else
  15925. handler = new LaterHandler();
  15926. handler.caller = caller;
  15927. handler.method = method;
  15928. handler.args = args;
  15929. var cid = caller ? caller.$_GID : 0;
  15930. var mid = method["$_TID"];
  15931. handler.key = cid + mid;
  15932. this._map[handler.key] = handler;
  15933. this._laters.push(handler);
  15934. }
  15935. }
  15936. runCallLater(caller, method) {
  15937. var handler = this._getHandler(caller, method);
  15938. if (handler && handler.method != null) {
  15939. this._map[handler.key] = null;
  15940. handler.run();
  15941. handler.clear();
  15942. }
  15943. }
  15944. }
  15945. CallLater.I = new CallLater();
  15946. class LaterHandler {
  15947. clear() {
  15948. this.caller = null;
  15949. this.method = null;
  15950. this.args = null;
  15951. }
  15952. run() {
  15953. var caller = this.caller;
  15954. if (caller && caller.destroyed)
  15955. return this.clear();
  15956. var method = this.method;
  15957. var args = this.args;
  15958. if (method == null)
  15959. return;
  15960. args ? method.apply(caller, args) : method.call(caller);
  15961. }
  15962. }
  15963. class RunDriver {
  15964. }
  15965. RunDriver.createShaderCondition = function (conditionScript) {
  15966. var fn = "(function() {return " + conditionScript + ";})";
  15967. return window.Laya._runScript(fn);
  15968. };
  15969. RunDriver.changeWebGLSize = function (w, h) {
  15970. WebGL.onStageResize(w, h);
  15971. };
  15972. class Stage extends Sprite {
  15973. constructor() {
  15974. super();
  15975. this.offset = new Point();
  15976. this._frameRate = "fast";
  15977. this.designWidth = 0;
  15978. this.designHeight = 0;
  15979. this.canvasRotation = false;
  15980. this.canvasDegree = 0;
  15981. this.renderingEnabled = true;
  15982. this.screenAdaptationEnabled = true;
  15983. this._canvasTransform = new Matrix();
  15984. this._screenMode = "none";
  15985. this._scaleMode = "noscale";
  15986. this._alignV = "top";
  15987. this._alignH = "left";
  15988. this._bgColor = "black";
  15989. this._mouseMoveTime = 0;
  15990. this._renderCount = 0;
  15991. this._safariOffsetY = 0;
  15992. this._frameStartTime = 0;
  15993. this._previousOrientation = Browser.window.orientation;
  15994. this._wgColor = [0, 0, 0, 1];
  15995. this._scene3Ds = [];
  15996. this._globalRepaintSet = false;
  15997. this._globalRepaintGet = false;
  15998. this._3dUI = [];
  15999. this._curUIBase = null;
  16000. this.useRetinalCanvas = false;
  16001. super.set_transform(this._createTransform());
  16002. this.mouseEnabled = true;
  16003. this.hitTestPrior = true;
  16004. this.autoSize = false;
  16005. this._setBit(Const.DISPLAYED_INSTAGE, true);
  16006. this._setBit(Const.ACTIVE_INHIERARCHY, true);
  16007. this._isFocused = true;
  16008. this._isVisibility = true;
  16009. this.useRetinalCanvas = Config.useRetinalCanvas;
  16010. var window = Browser.window;
  16011. var _me = this;
  16012. window.addEventListener("focus", function () {
  16013. this._isFocused = true;
  16014. _me.event(Event.FOCUS);
  16015. _me.event(Event.FOCUS_CHANGE);
  16016. });
  16017. window.addEventListener("blur", function () {
  16018. this._isFocused = false;
  16019. _me.event(Event.BLUR);
  16020. _me.event(Event.FOCUS_CHANGE);
  16021. if (_me._isInputting())
  16022. Input["inputElement"].target.focus = false;
  16023. });
  16024. var state = "visibilityState", visibilityChange = "visibilitychange";
  16025. var document = window.document;
  16026. if (typeof document.hidden !== "undefined") {
  16027. visibilityChange = "visibilitychange";
  16028. state = "visibilityState";
  16029. }
  16030. else if (typeof document.mozHidden !== "undefined") {
  16031. visibilityChange = "mozvisibilitychange";
  16032. state = "mozVisibilityState";
  16033. }
  16034. else if (typeof document.msHidden !== "undefined") {
  16035. visibilityChange = "msvisibilitychange";
  16036. state = "msVisibilityState";
  16037. }
  16038. else if (typeof document.webkitHidden !== "undefined") {
  16039. visibilityChange = "webkitvisibilitychange";
  16040. state = "webkitVisibilityState";
  16041. }
  16042. window.document.addEventListener(visibilityChange, visibleChangeFun);
  16043. function visibleChangeFun() {
  16044. if (Browser.document[state] == "hidden") {
  16045. this._isVisibility = false;
  16046. if (_me._isInputting())
  16047. Input["inputElement"].target.focus = false;
  16048. }
  16049. else {
  16050. this._isVisibility = true;
  16051. }
  16052. this.renderingEnabled = this._isVisibility;
  16053. _me.event(Event.VISIBILITY_CHANGE);
  16054. }
  16055. window.addEventListener("resize", function () {
  16056. var orientation = Browser.window.orientation;
  16057. if (orientation != null && orientation != this._previousOrientation && _me._isInputting()) {
  16058. Input["inputElement"].target.focus = false;
  16059. }
  16060. this._previousOrientation = orientation;
  16061. if (_me._isInputting())
  16062. return;
  16063. if (Browser.onSafari)
  16064. _me._safariOffsetY = (Browser.window.__innerHeight || Browser.document.body.clientHeight || Browser.document.documentElement.clientHeight) - Browser.window.innerHeight;
  16065. _me._resetCanvas();
  16066. });
  16067. window.addEventListener("orientationchange", function (e) {
  16068. _me._resetCanvas();
  16069. });
  16070. this.on(Event.MOUSE_MOVE, this, this._onmouseMove);
  16071. if (Browser.onMobile)
  16072. this.on(Event.MOUSE_DOWN, this, this._onmouseMove);
  16073. }
  16074. _isInputting() {
  16075. return (Browser.onMobile && Input.isInputting);
  16076. }
  16077. set width(value) {
  16078. this.designWidth = value;
  16079. super.set_width(value);
  16080. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16081. }
  16082. get width() {
  16083. return super.get_width();
  16084. }
  16085. set height(value) {
  16086. this.designHeight = value;
  16087. super.set_height(value);
  16088. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16089. }
  16090. get height() {
  16091. return super.get_height();
  16092. }
  16093. set transform(value) {
  16094. super.set_transform(value);
  16095. }
  16096. get transform() {
  16097. if (this._tfChanged)
  16098. this._adjustTransform();
  16099. return (this._transform = this._transform || this._createTransform());
  16100. }
  16101. get isFocused() {
  16102. return this._isFocused;
  16103. }
  16104. get isVisibility() {
  16105. return this._isVisibility;
  16106. }
  16107. _changeCanvasSize() {
  16108. this.setScreenSize(Browser.clientWidth * Browser.pixelRatio, Browser.clientHeight * Browser.pixelRatio);
  16109. }
  16110. _resetCanvas() {
  16111. if (!this.screenAdaptationEnabled)
  16112. return;
  16113. this._changeCanvasSize();
  16114. }
  16115. setScreenSize(screenWidth, screenHeight) {
  16116. var rotation = false;
  16117. if (this._screenMode !== Stage.SCREEN_NONE) {
  16118. var screenType = screenWidth / screenHeight < 1 ? Stage.SCREEN_VERTICAL : Stage.SCREEN_HORIZONTAL;
  16119. rotation = screenType !== this._screenMode;
  16120. if (rotation) {
  16121. var temp = screenHeight;
  16122. screenHeight = screenWidth;
  16123. screenWidth = temp;
  16124. }
  16125. }
  16126. this.canvasRotation = rotation;
  16127. var canvas = Render._mainCanvas;
  16128. var canvasStyle = canvas.source.style;
  16129. var mat = this._canvasTransform.identity();
  16130. var scaleMode = this._scaleMode;
  16131. var scaleX = screenWidth / this.designWidth;
  16132. var scaleY = screenHeight / this.designHeight;
  16133. var canvasWidth = this.useRetinalCanvas ? screenWidth : this.designWidth;
  16134. var canvasHeight = this.useRetinalCanvas ? screenHeight : this.designHeight;
  16135. var realWidth = screenWidth;
  16136. var realHeight = screenHeight;
  16137. var pixelRatio = Browser.pixelRatio;
  16138. this._width = this.designWidth;
  16139. this._height = this.designHeight;
  16140. switch (scaleMode) {
  16141. case Stage.SCALE_NOSCALE:
  16142. scaleX = scaleY = 1;
  16143. realWidth = this.designWidth;
  16144. realHeight = this.designHeight;
  16145. break;
  16146. case Stage.SCALE_SHOWALL:
  16147. scaleX = scaleY = Math.min(scaleX, scaleY);
  16148. canvasWidth = realWidth = Math.round(this.designWidth * scaleX);
  16149. canvasHeight = realHeight = Math.round(this.designHeight * scaleY);
  16150. break;
  16151. case Stage.SCALE_NOBORDER:
  16152. scaleX = scaleY = Math.max(scaleX, scaleY);
  16153. realWidth = Math.round(this.designWidth * scaleX);
  16154. realHeight = Math.round(this.designHeight * scaleY);
  16155. break;
  16156. case Stage.SCALE_FULL:
  16157. scaleX = scaleY = 1;
  16158. this._width = canvasWidth = screenWidth;
  16159. this._height = canvasHeight = screenHeight;
  16160. break;
  16161. case Stage.SCALE_FIXED_WIDTH:
  16162. scaleY = scaleX;
  16163. this._height = canvasHeight = Math.round(screenHeight / scaleX);
  16164. break;
  16165. case Stage.SCALE_FIXED_HEIGHT:
  16166. scaleX = scaleY;
  16167. this._width = canvasWidth = Math.round(screenWidth / scaleY);
  16168. break;
  16169. case Stage.SCALE_FIXED_AUTO:
  16170. if ((screenWidth / screenHeight) < (this.designWidth / this.designHeight)) {
  16171. scaleY = scaleX;
  16172. this._height = canvasHeight = Math.round(screenHeight / scaleX);
  16173. }
  16174. else {
  16175. scaleX = scaleY;
  16176. this._width = canvasWidth = Math.round(screenWidth / scaleY);
  16177. }
  16178. break;
  16179. }
  16180. if (this.useRetinalCanvas) {
  16181. canvasWidth = screenWidth;
  16182. canvasHeight = screenHeight;
  16183. }
  16184. scaleX *= this.scaleX;
  16185. scaleY *= this.scaleY;
  16186. if (scaleX === 1 && scaleY === 1) {
  16187. this.transform.identity();
  16188. }
  16189. else {
  16190. this.transform.a = this._formatData(scaleX / (realWidth / canvasWidth));
  16191. this.transform.d = this._formatData(scaleY / (realHeight / canvasHeight));
  16192. }
  16193. canvas.size(canvasWidth, canvasHeight);
  16194. RunDriver.changeWebGLSize(canvasWidth, canvasHeight);
  16195. mat.scale(realWidth / canvasWidth / pixelRatio, realHeight / canvasHeight / pixelRatio);
  16196. if (this._alignH === Stage.ALIGN_LEFT)
  16197. this.offset.x = 0;
  16198. else if (this._alignH === Stage.ALIGN_RIGHT)
  16199. this.offset.x = screenWidth - realWidth;
  16200. else
  16201. this.offset.x = (screenWidth - realWidth) * 0.5 / pixelRatio;
  16202. if (this._alignV === Stage.ALIGN_TOP)
  16203. this.offset.y = 0;
  16204. else if (this._alignV === Stage.ALIGN_BOTTOM)
  16205. this.offset.y = screenHeight - realHeight;
  16206. else
  16207. this.offset.y = (screenHeight - realHeight) * 0.5 / pixelRatio;
  16208. this.offset.x = Math.round(this.offset.x);
  16209. this.offset.y = Math.round(this.offset.y);
  16210. mat.translate(this.offset.x, this.offset.y);
  16211. if (this._safariOffsetY)
  16212. mat.translate(0, this._safariOffsetY);
  16213. this.canvasDegree = 0;
  16214. if (rotation) {
  16215. if (this._screenMode === Stage.SCREEN_HORIZONTAL) {
  16216. mat.rotate(Math.PI / 2);
  16217. mat.translate(screenHeight / pixelRatio, 0);
  16218. this.canvasDegree = 90;
  16219. }
  16220. else {
  16221. mat.rotate(-Math.PI / 2);
  16222. mat.translate(0, screenWidth / pixelRatio);
  16223. this.canvasDegree = -90;
  16224. }
  16225. }
  16226. mat.a = this._formatData(mat.a);
  16227. mat.d = this._formatData(mat.d);
  16228. mat.tx = this._formatData(mat.tx);
  16229. mat.ty = this._formatData(mat.ty);
  16230. super.set_transform(this.transform);
  16231. canvasStyle.transformOrigin = canvasStyle.webkitTransformOrigin = canvasStyle.msTransformOrigin = canvasStyle.mozTransformOrigin = canvasStyle.oTransformOrigin = "0px 0px 0px";
  16232. canvasStyle.transform = canvasStyle.webkitTransform = canvasStyle.msTransform = canvasStyle.mozTransform = canvasStyle.oTransform = "matrix(" + mat.toString() + ")";
  16233. if (this._safariOffsetY)
  16234. mat.translate(0, -this._safariOffsetY);
  16235. mat.translate(parseInt(canvasStyle.left) || 0, parseInt(canvasStyle.top) || 0);
  16236. this.visible = true;
  16237. this._repaint |= SpriteConst.REPAINT_CACHE;
  16238. this.event(Event.RESIZE);
  16239. }
  16240. _formatData(value) {
  16241. if (Math.abs(value) < 0.000001)
  16242. return 0;
  16243. if (Math.abs(1 - value) < 0.001)
  16244. return value > 0 ? 1 : -1;
  16245. return value;
  16246. }
  16247. get scaleMode() {
  16248. return this._scaleMode;
  16249. }
  16250. set scaleMode(value) {
  16251. this._scaleMode = value;
  16252. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16253. }
  16254. get alignH() {
  16255. return this._alignH;
  16256. }
  16257. set alignH(value) {
  16258. this._alignH = value;
  16259. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16260. }
  16261. get alignV() {
  16262. return this._alignV;
  16263. }
  16264. set alignV(value) {
  16265. this._alignV = value;
  16266. ILaya.systemTimer.callLater(this, this._changeCanvasSize);
  16267. }
  16268. get bgColor() {
  16269. return this._bgColor;
  16270. }
  16271. set bgColor(value) {
  16272. this._bgColor = value;
  16273. if (value)
  16274. this._wgColor = ColorUtils.create(value).arrColor;
  16275. else
  16276. this._wgColor = null;
  16277. if (value) {
  16278. Render.canvas.style.background = value;
  16279. }
  16280. else {
  16281. Render.canvas.style.background = "none";
  16282. }
  16283. }
  16284. get mouseX() {
  16285. return Math.round(MouseManager.instance.mouseX / this.clientScaleX);
  16286. }
  16287. get mouseY() {
  16288. return Math.round(MouseManager.instance.mouseY / this.clientScaleY);
  16289. }
  16290. getMousePoint() {
  16291. return Point.TEMP.setTo(this.mouseX, this.mouseY);
  16292. }
  16293. get clientScaleX() {
  16294. return this._transform ? this._transform.getScaleX() : 1;
  16295. }
  16296. get clientScaleY() {
  16297. return this._transform ? this._transform.getScaleY() : 1;
  16298. }
  16299. get screenMode() {
  16300. return this._screenMode;
  16301. }
  16302. set screenMode(value) {
  16303. this._screenMode = value;
  16304. }
  16305. repaint(type = SpriteConst.REPAINT_CACHE) {
  16306. this._repaint |= type;
  16307. }
  16308. parentRepaint(type = SpriteConst.REPAINT_CACHE) {
  16309. }
  16310. _loop() {
  16311. this._globalRepaintGet = this._globalRepaintSet;
  16312. this._globalRepaintSet = false;
  16313. this.render(Render._context, 0, 0);
  16314. return true;
  16315. }
  16316. getFrameTm() {
  16317. return this._frameStartTime;
  16318. }
  16319. _onmouseMove(e) {
  16320. this._mouseMoveTime = Browser.now();
  16321. }
  16322. getTimeFromFrameStart() {
  16323. return Browser.now() - this._frameStartTime;
  16324. }
  16325. set visible(value) {
  16326. if (this.visible !== value) {
  16327. super.set_visible(value);
  16328. var style = Render._mainCanvas.source.style;
  16329. style.visibility = value ? "visible" : "hidden";
  16330. }
  16331. }
  16332. get visible() {
  16333. return super.visible;
  16334. }
  16335. render(context, x, y) {
  16336. if (window.conch) {
  16337. this.renderToNative(context, x, y);
  16338. return;
  16339. }
  16340. Stage._dbgSprite.graphics.clear();
  16341. if (this._frameRate === Stage.FRAME_SLEEP) {
  16342. var now = Browser.now();
  16343. if (now - this._frameStartTime >= 1000)
  16344. this._frameStartTime = now;
  16345. else
  16346. return;
  16347. }
  16348. else {
  16349. if (!this._visible) {
  16350. this._renderCount++;
  16351. if (this._renderCount % 5 === 0) {
  16352. CallLater.I._update();
  16353. Stat.loopCount++;
  16354. RenderInfo.loopCount = Stat.loopCount;
  16355. this._updateTimers();
  16356. }
  16357. return;
  16358. }
  16359. this._frameStartTime = Browser.now();
  16360. RenderInfo.loopStTm = this._frameStartTime;
  16361. }
  16362. this._renderCount++;
  16363. var frameMode = this._frameRate === Stage.FRAME_MOUSE ? (((this._frameStartTime - this._mouseMoveTime) < 2000) ? Stage.FRAME_FAST : Stage.FRAME_SLOW) : this._frameRate;
  16364. var isFastMode = (frameMode !== Stage.FRAME_SLOW);
  16365. var isDoubleLoop = (this._renderCount % 2 === 0);
  16366. Stat.renderSlow = !isFastMode;
  16367. if (!isFastMode && !isDoubleLoop)
  16368. return;
  16369. CallLater.I._update();
  16370. Stat.loopCount++;
  16371. RenderInfo.loopCount = Stat.loopCount;
  16372. if (this.renderingEnabled) {
  16373. for (var i = 0, n = this._scene3Ds.length; i < n; i++)
  16374. this._scene3Ds[i]._update();
  16375. context.clear();
  16376. super.render(context, x, y);
  16377. Stat._StatRender.renderNotCanvas(context, x, y);
  16378. }
  16379. Stage._dbgSprite.render(context, 0, 0);
  16380. if (this.renderingEnabled) {
  16381. Stage.clear(this._bgColor);
  16382. context.flush();
  16383. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  16384. }
  16385. this._updateTimers();
  16386. }
  16387. renderToNative(context, x, y) {
  16388. this._renderCount++;
  16389. if (!this._visible) {
  16390. if (this._renderCount % 5 === 0) {
  16391. CallLater.I._update();
  16392. Stat.loopCount++;
  16393. RenderInfo.loopCount = Stat.loopCount;
  16394. this._updateTimers();
  16395. }
  16396. return;
  16397. }
  16398. CallLater.I._update();
  16399. Stat.loopCount++;
  16400. RenderInfo.loopCount = Stat.loopCount;
  16401. if (this.renderingEnabled) {
  16402. for (var i = 0, n = this._scene3Ds.length; i < n; i++)
  16403. this._scene3Ds[i]._update();
  16404. context.clear();
  16405. super.render(context, x, y);
  16406. Stat._StatRender.renderNotCanvas(context, x, y);
  16407. }
  16408. if (this.renderingEnabled) {
  16409. Stage.clear(this._bgColor);
  16410. context.flush();
  16411. VectorGraphManager.instance && VectorGraphManager.getInstance().endDispose();
  16412. }
  16413. this._updateTimers();
  16414. }
  16415. _updateTimers() {
  16416. ILaya.systemTimer._update();
  16417. ILaya.startTimer._update();
  16418. ILaya.physicsTimer._update();
  16419. ILaya.updateTimer._update();
  16420. ILaya.lateTimer._update();
  16421. ILaya.timer._update();
  16422. }
  16423. set fullScreenEnabled(value) {
  16424. var document = Browser.document;
  16425. var canvas = Render.canvas;
  16426. if (value) {
  16427. canvas.addEventListener('mousedown', this._requestFullscreen);
  16428. canvas.addEventListener('touchstart', this._requestFullscreen);
  16429. document.addEventListener("fullscreenchange", this._fullScreenChanged);
  16430. document.addEventListener("mozfullscreenchange", this._fullScreenChanged);
  16431. document.addEventListener("webkitfullscreenchange", this._fullScreenChanged);
  16432. document.addEventListener("msfullscreenchange", this._fullScreenChanged);
  16433. }
  16434. else {
  16435. canvas.removeEventListener('mousedown', this._requestFullscreen);
  16436. canvas.removeEventListener('touchstart', this._requestFullscreen);
  16437. document.removeEventListener("fullscreenchange", this._fullScreenChanged);
  16438. document.removeEventListener("mozfullscreenchange", this._fullScreenChanged);
  16439. document.removeEventListener("webkitfullscreenchange", this._fullScreenChanged);
  16440. document.removeEventListener("msfullscreenchange", this._fullScreenChanged);
  16441. }
  16442. }
  16443. get frameRate() {
  16444. if (!ILaya.Render.isConchApp) {
  16445. return this._frameRate;
  16446. }
  16447. else {
  16448. return this._frameRateNative;
  16449. }
  16450. }
  16451. set frameRate(value) {
  16452. if (!ILaya.Render.isConchApp) {
  16453. this._frameRate = value;
  16454. }
  16455. else {
  16456. var c = window.conch;
  16457. switch (value) {
  16458. case Stage.FRAME_FAST:
  16459. c.config.setLimitFPS(60);
  16460. break;
  16461. case Stage.FRAME_MOUSE:
  16462. c.config.setMouseFrame(2000);
  16463. break;
  16464. case Stage.FRAME_SLOW:
  16465. c.config.setSlowFrame(true);
  16466. break;
  16467. case Stage.FRAME_SLEEP:
  16468. c.config.setLimitFPS(1);
  16469. break;
  16470. }
  16471. this._frameRateNative = value;
  16472. }
  16473. }
  16474. _requestFullscreen() {
  16475. var element = Browser.document.documentElement;
  16476. if (element.requestFullscreen) {
  16477. element.requestFullscreen();
  16478. }
  16479. else if (element.mozRequestFullScreen) {
  16480. element.mozRequestFullScreen();
  16481. }
  16482. else if (element.webkitRequestFullscreen) {
  16483. element.webkitRequestFullscreen();
  16484. }
  16485. else if (element.msRequestFullscreen) {
  16486. element.msRequestFullscreen();
  16487. }
  16488. }
  16489. _fullScreenChanged() {
  16490. ILaya.stage.event(Event.FULL_SCREEN_CHANGE);
  16491. }
  16492. exitFullscreen() {
  16493. var document = Browser.document;
  16494. if (document.exitFullscreen) {
  16495. document.exitFullscreen();
  16496. }
  16497. else if (document.mozCancelFullScreen) {
  16498. document.mozCancelFullScreen();
  16499. }
  16500. else if (document.webkitExitFullscreen) {
  16501. document.webkitExitFullscreen();
  16502. }
  16503. }
  16504. isGlobalRepaint() {
  16505. return this._globalRepaintGet;
  16506. }
  16507. setGlobalRepaint() {
  16508. this._globalRepaintSet = true;
  16509. }
  16510. add3DUI(uibase) {
  16511. var uiroot = uibase.rootView;
  16512. if (this._3dUI.indexOf(uiroot) >= 0)
  16513. return;
  16514. this._3dUI.push(uiroot);
  16515. }
  16516. remove3DUI(uibase) {
  16517. var uiroot = uibase.rootView;
  16518. var p = this._3dUI.indexOf(uiroot);
  16519. if (p >= 0) {
  16520. this._3dUI.splice(p, 1);
  16521. return true;
  16522. }
  16523. return false;
  16524. }
  16525. }
  16526. Stage.SCALE_NOSCALE = "noscale";
  16527. Stage.SCALE_EXACTFIT = "exactfit";
  16528. Stage.SCALE_SHOWALL = "showall";
  16529. Stage.SCALE_NOBORDER = "noborder";
  16530. Stage.SCALE_FULL = "full";
  16531. Stage.SCALE_FIXED_WIDTH = "fixedwidth";
  16532. Stage.SCALE_FIXED_HEIGHT = "fixedheight";
  16533. Stage.SCALE_FIXED_AUTO = "fixedauto";
  16534. Stage.ALIGN_LEFT = "left";
  16535. Stage.ALIGN_RIGHT = "right";
  16536. Stage.ALIGN_CENTER = "center";
  16537. Stage.ALIGN_TOP = "top";
  16538. Stage.ALIGN_MIDDLE = "middle";
  16539. Stage.ALIGN_BOTTOM = "bottom";
  16540. Stage.SCREEN_NONE = "none";
  16541. Stage.SCREEN_HORIZONTAL = "horizontal";
  16542. Stage.SCREEN_VERTICAL = "vertical";
  16543. Stage.FRAME_FAST = "fast";
  16544. Stage.FRAME_SLOW = "slow";
  16545. Stage.FRAME_MOUSE = "mouse";
  16546. Stage.FRAME_SLEEP = "sleep";
  16547. Stage._dbgSprite = new Sprite();
  16548. Stage.clear = function (value) {
  16549. Context.set2DRenderConfig();
  16550. var gl = LayaGL.instance;
  16551. RenderState2D.worldScissorTest && gl.disable(gl.SCISSOR_TEST);
  16552. var ctx = Render.context;
  16553. var c = (ctx._submits._length == 0 || Config.preserveDrawingBuffer) ? ColorUtils.create(value).arrColor : window.Laya.stage._wgColor;
  16554. if (c)
  16555. ctx.clearBG(c[0], c[1], c[2], c[3]);
  16556. else
  16557. ctx.clearBG(0, 0, 0, 0);
  16558. RenderState2D.clear();
  16559. };
  16560. ClassUtils.regClass("laya.display.Stage", Stage);
  16561. ClassUtils.regClass("Laya.Stage", Stage);
  16562. class KeyBoardManager {
  16563. static __init__() {
  16564. KeyBoardManager._addEvent("keydown");
  16565. KeyBoardManager._addEvent("keypress");
  16566. KeyBoardManager._addEvent("keyup");
  16567. }
  16568. static _addEvent(type) {
  16569. ILaya.Browser.document.addEventListener(type, function (e) {
  16570. KeyBoardManager._dispatch(e, type);
  16571. }, true);
  16572. }
  16573. static _dispatch(e, type) {
  16574. if (!KeyBoardManager.enabled)
  16575. return;
  16576. KeyBoardManager._event._stoped = false;
  16577. KeyBoardManager._event.nativeEvent = e;
  16578. KeyBoardManager._event.keyCode = e.keyCode || e.which || e.charCode;
  16579. if (type === "keydown")
  16580. KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode] = true;
  16581. else if (type === "keyup")
  16582. KeyBoardManager._pressKeys[KeyBoardManager._event.keyCode] = null;
  16583. var target = (ILaya.stage.focus && (ILaya.stage.focus.event != null) && ILaya.stage.focus.displayedInStage) ? ILaya.stage.focus : ILaya.stage;
  16584. var ct = target;
  16585. while (ct) {
  16586. ct.event(type, KeyBoardManager._event.setTo(type, ct, target));
  16587. ct = ct.parent;
  16588. }
  16589. }
  16590. static hasKeyDown(key) {
  16591. return KeyBoardManager._pressKeys[key];
  16592. }
  16593. }
  16594. KeyBoardManager._pressKeys = {};
  16595. KeyBoardManager.enabled = true;
  16596. KeyBoardManager._event = new Event();
  16597. class SoundChannel extends EventDispatcher {
  16598. constructor() {
  16599. super(...arguments);
  16600. this.isStopped = false;
  16601. }
  16602. set volume(v) {
  16603. }
  16604. get volume() {
  16605. return 1;
  16606. }
  16607. get position() {
  16608. return 0;
  16609. }
  16610. get duration() {
  16611. return 0;
  16612. }
  16613. play() {
  16614. }
  16615. stop() {
  16616. if (this.completeHandler)
  16617. this.completeHandler.run();
  16618. }
  16619. pause() {
  16620. }
  16621. resume() {
  16622. }
  16623. __runComplete(handler) {
  16624. if (handler) {
  16625. handler.run();
  16626. }
  16627. }
  16628. }
  16629. class AudioSoundChannel extends SoundChannel {
  16630. constructor(audio) {
  16631. super();
  16632. this._audio = null;
  16633. this._onEnd = this.__onEnd.bind(this);
  16634. this._resumePlay = this.__resumePlay.bind(this);
  16635. audio.addEventListener("ended", this._onEnd);
  16636. this._audio = audio;
  16637. }
  16638. __onEnd(evt) {
  16639. if (this.loops == 1) {
  16640. if (this.completeHandler) {
  16641. ILaya.systemTimer.once(10, this, this.__runComplete, [this.completeHandler], false);
  16642. this.completeHandler = null;
  16643. }
  16644. this.stop();
  16645. this.event(Event.COMPLETE);
  16646. return;
  16647. }
  16648. if (this.loops > 0) {
  16649. this.loops--;
  16650. }
  16651. this.startTime = 0;
  16652. this.play();
  16653. }
  16654. __resumePlay() {
  16655. if (this._audio)
  16656. this._audio.removeEventListener("canplay", this._resumePlay);
  16657. if (this.isStopped)
  16658. return;
  16659. try {
  16660. this._audio.currentTime = this.startTime;
  16661. Browser.container.appendChild(this._audio);
  16662. this._audio.play();
  16663. }
  16664. catch (e) {
  16665. this.event(Event.ERROR);
  16666. }
  16667. }
  16668. play() {
  16669. this.isStopped = false;
  16670. try {
  16671. this._audio.playbackRate = ILaya.SoundManager.playbackRate;
  16672. this._audio.currentTime = this.startTime;
  16673. }
  16674. catch (e) {
  16675. this._audio.addEventListener("canplay", this._resumePlay);
  16676. return;
  16677. }
  16678. ILaya.SoundManager.addChannel(this);
  16679. Browser.container.appendChild(this._audio);
  16680. if ("play" in this._audio)
  16681. this._audio.play();
  16682. }
  16683. get position() {
  16684. if (!this._audio)
  16685. return 0;
  16686. return this._audio.currentTime;
  16687. }
  16688. get duration() {
  16689. if (!this._audio)
  16690. return 0;
  16691. return this._audio.duration;
  16692. }
  16693. stop() {
  16694. super.stop();
  16695. this.isStopped = true;
  16696. ILaya.SoundManager.removeChannel(this);
  16697. this.completeHandler = null;
  16698. if (!this._audio)
  16699. return;
  16700. if ("pause" in this._audio)
  16701. if (ILaya.Render.isConchApp) {
  16702. this._audio.stop();
  16703. }
  16704. this._audio.pause();
  16705. this._audio.removeEventListener("ended", this._onEnd);
  16706. this._audio.removeEventListener("canplay", this._resumePlay);
  16707. if (!ILaya.Browser.onIE) {
  16708. if (this._audio != ILaya.AudioSound._musicAudio) {
  16709. ILaya.Pool.recover("audio:" + this.url, this._audio);
  16710. }
  16711. }
  16712. Browser.removeElement(this._audio);
  16713. this._audio = null;
  16714. if (ILaya.SoundManager.autoReleaseSound)
  16715. ILaya.SoundManager.disposeSoundLater(this.url);
  16716. }
  16717. pause() {
  16718. this.isStopped = true;
  16719. ILaya.SoundManager.removeChannel(this);
  16720. if ("pause" in this._audio)
  16721. this._audio.pause();
  16722. if (ILaya.SoundManager.autoReleaseSound)
  16723. ILaya.SoundManager.disposeSoundLater(this.url);
  16724. }
  16725. resume() {
  16726. if (!this._audio)
  16727. return;
  16728. this.isStopped = false;
  16729. ILaya.SoundManager.addChannel(this);
  16730. if ("play" in this._audio)
  16731. this._audio.play();
  16732. }
  16733. set volume(v) {
  16734. if (!this._audio)
  16735. return;
  16736. this._audio.volume = v;
  16737. }
  16738. get volume() {
  16739. if (!this._audio)
  16740. return 1;
  16741. return this._audio.volume;
  16742. }
  16743. }
  16744. class AudioSound extends EventDispatcher {
  16745. constructor() {
  16746. super(...arguments);
  16747. this.loaded = false;
  16748. }
  16749. dispose() {
  16750. var ad = AudioSound._audioCache[this.url];
  16751. Pool.clearBySign("audio:" + this.url);
  16752. if (ad) {
  16753. if (!Render.isConchApp) {
  16754. ad.src = "";
  16755. }
  16756. delete AudioSound._audioCache[this.url];
  16757. }
  16758. }
  16759. static _initMusicAudio() {
  16760. if (AudioSound._musicAudio)
  16761. return;
  16762. if (!AudioSound._musicAudio)
  16763. AudioSound._musicAudio = Browser.createElement("audio");
  16764. if (!Render.isConchApp) {
  16765. Browser.document.addEventListener("mousedown", AudioSound._makeMusicOK);
  16766. }
  16767. }
  16768. static _makeMusicOK() {
  16769. Browser.document.removeEventListener("mousedown", AudioSound._makeMusicOK);
  16770. if (!AudioSound._musicAudio.src) {
  16771. AudioSound._musicAudio.src = "";
  16772. AudioSound._musicAudio.load();
  16773. }
  16774. else {
  16775. AudioSound._musicAudio.play();
  16776. }
  16777. }
  16778. load(url) {
  16779. url = URL.formatURL(url);
  16780. this.url = url;
  16781. var ad;
  16782. if (url == ILaya.SoundManager._bgMusic) {
  16783. AudioSound._initMusicAudio();
  16784. ad = AudioSound._musicAudio;
  16785. if (ad.src != url) {
  16786. AudioSound._audioCache[ad.src] = null;
  16787. ad = null;
  16788. }
  16789. }
  16790. else {
  16791. ad = AudioSound._audioCache[url];
  16792. }
  16793. if (ad && ad.readyState >= 2) {
  16794. this.event(Event.COMPLETE);
  16795. return;
  16796. }
  16797. if (!ad) {
  16798. if (url == ILaya.SoundManager._bgMusic) {
  16799. AudioSound._initMusicAudio();
  16800. ad = AudioSound._musicAudio;
  16801. }
  16802. else {
  16803. ad = Browser.createElement("audio");
  16804. }
  16805. AudioSound._audioCache[url] = ad;
  16806. ad.src = url;
  16807. }
  16808. ad.addEventListener("canplaythrough", onLoaded);
  16809. ad.addEventListener("error", onErr);
  16810. var me = this;
  16811. function onLoaded() {
  16812. offs();
  16813. me.loaded = true;
  16814. me.event(Event.COMPLETE);
  16815. }
  16816. function onErr() {
  16817. ad.load = null;
  16818. offs();
  16819. me.event(Event.ERROR);
  16820. }
  16821. function offs() {
  16822. ad.removeEventListener("canplaythrough", onLoaded);
  16823. ad.removeEventListener("error", onErr);
  16824. }
  16825. this.audio = ad;
  16826. if (ad.load) {
  16827. ad.load();
  16828. }
  16829. else {
  16830. onErr();
  16831. }
  16832. }
  16833. play(startTime = 0, loops = 0) {
  16834. if (!this.url)
  16835. return null;
  16836. var ad;
  16837. if (this.url == ILaya.SoundManager._bgMusic) {
  16838. ad = AudioSound._musicAudio;
  16839. }
  16840. else {
  16841. ad = AudioSound._audioCache[this.url];
  16842. }
  16843. if (!ad)
  16844. return null;
  16845. var tAd;
  16846. tAd = Pool.getItem("audio:" + this.url);
  16847. if (Render.isConchApp) {
  16848. if (!tAd) {
  16849. tAd = Browser.createElement("audio");
  16850. tAd.src = this.url;
  16851. }
  16852. }
  16853. else {
  16854. if (this.url == ILaya.SoundManager._bgMusic) {
  16855. AudioSound._initMusicAudio();
  16856. tAd = AudioSound._musicAudio;
  16857. tAd.src = this.url;
  16858. }
  16859. else {
  16860. tAd = tAd ? tAd : ad.cloneNode(true);
  16861. }
  16862. }
  16863. var channel = new AudioSoundChannel(tAd);
  16864. channel.url = this.url;
  16865. channel.loops = loops;
  16866. channel.startTime = startTime;
  16867. channel.play();
  16868. ILaya.SoundManager.addChannel(channel);
  16869. return channel;
  16870. }
  16871. get duration() {
  16872. var ad;
  16873. ad = AudioSound._audioCache[this.url];
  16874. if (!ad)
  16875. return 0;
  16876. return ad.duration;
  16877. }
  16878. }
  16879. AudioSound._audioCache = {};
  16880. class WebAudioSoundChannel extends SoundChannel {
  16881. constructor() {
  16882. super();
  16883. this.bufferSource = null;
  16884. this._currentTime = 0;
  16885. this._volume = 1;
  16886. this._startTime = 0;
  16887. this._pauseTime = 0;
  16888. this.context = ILaya.WebAudioSound.ctx;
  16889. this._onPlayEnd = Utils.bind(this.__onPlayEnd, this);
  16890. if (this.context["createGain"]) {
  16891. this.gain = this.context["createGain"]();
  16892. }
  16893. else {
  16894. this.gain = this.context["createGainNode"]();
  16895. }
  16896. }
  16897. play() {
  16898. ILaya.SoundManager.addChannel(this);
  16899. this.isStopped = false;
  16900. this._clearBufferSource();
  16901. if (!this.audioBuffer)
  16902. return;
  16903. if (this.startTime >= this.duration)
  16904. return stop();
  16905. var context = this.context;
  16906. var gain = this.gain;
  16907. var bufferSource = context.createBufferSource();
  16908. this.bufferSource = bufferSource;
  16909. bufferSource.buffer = this.audioBuffer;
  16910. bufferSource.connect(gain);
  16911. if (gain)
  16912. gain.disconnect();
  16913. gain.connect(context.destination);
  16914. bufferSource.onended = this._onPlayEnd;
  16915. this._startTime = Browser.now();
  16916. if (this.gain.gain.setTargetAtTime) {
  16917. this.gain.gain.setTargetAtTime(this._volume, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  16918. }
  16919. else
  16920. this.gain.gain.value = this._volume;
  16921. if (this.loops == 0) {
  16922. bufferSource.loop = true;
  16923. }
  16924. if (bufferSource.playbackRate.setTargetAtTime) {
  16925. bufferSource.playbackRate.setTargetAtTime(ILaya.SoundManager.playbackRate, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  16926. }
  16927. else
  16928. bufferSource.playbackRate.value = ILaya.SoundManager.playbackRate;
  16929. bufferSource.start(0, this.startTime);
  16930. this._currentTime = 0;
  16931. }
  16932. __onPlayEnd() {
  16933. if (this.loops == 1) {
  16934. if (this.completeHandler) {
  16935. ILaya.timer.once(10, this, this.__runComplete, [this.completeHandler], false);
  16936. this.completeHandler = null;
  16937. }
  16938. this.stop();
  16939. this.event(Event.COMPLETE);
  16940. return;
  16941. }
  16942. if (this.loops > 0) {
  16943. this.loops--;
  16944. }
  16945. this.startTime = 0;
  16946. this.play();
  16947. }
  16948. get position() {
  16949. if (this.bufferSource) {
  16950. return (Browser.now() - this._startTime) / 1000 + this.startTime;
  16951. }
  16952. return 0;
  16953. }
  16954. get duration() {
  16955. if (this.audioBuffer) {
  16956. return this.audioBuffer.duration;
  16957. }
  16958. return 0;
  16959. }
  16960. _clearBufferSource() {
  16961. if (this.bufferSource) {
  16962. var sourceNode = this.bufferSource;
  16963. if (sourceNode.stop) {
  16964. sourceNode.stop(0);
  16965. }
  16966. else {
  16967. sourceNode.noteOff(0);
  16968. }
  16969. sourceNode.disconnect(0);
  16970. sourceNode.onended = null;
  16971. if (!WebAudioSoundChannel._tryCleanFailed)
  16972. this._tryClearBuffer(sourceNode);
  16973. this.bufferSource = null;
  16974. }
  16975. }
  16976. _tryClearBuffer(sourceNode) {
  16977. if (!Browser.onMac) {
  16978. try {
  16979. sourceNode.buffer = null;
  16980. }
  16981. catch (e) {
  16982. WebAudioSoundChannel._tryCleanFailed = true;
  16983. }
  16984. return;
  16985. }
  16986. try {
  16987. sourceNode.buffer = ILaya.WebAudioSound._miniBuffer;
  16988. }
  16989. catch (e) {
  16990. WebAudioSoundChannel._tryCleanFailed = true;
  16991. }
  16992. }
  16993. stop() {
  16994. super.stop();
  16995. this._clearBufferSource();
  16996. this.audioBuffer = null;
  16997. if (this.gain)
  16998. this.gain.disconnect();
  16999. this.isStopped = true;
  17000. ILaya.SoundManager.removeChannel(this);
  17001. this.completeHandler = null;
  17002. if (ILaya.SoundManager.autoReleaseSound)
  17003. ILaya.SoundManager.disposeSoundLater(this.url);
  17004. }
  17005. pause() {
  17006. if (!this.isStopped) {
  17007. this._pauseTime = this.position;
  17008. }
  17009. this._clearBufferSource();
  17010. if (this.gain)
  17011. this.gain.disconnect();
  17012. this.isStopped = true;
  17013. ILaya.SoundManager.removeChannel(this);
  17014. if (ILaya.SoundManager.autoReleaseSound)
  17015. ILaya.SoundManager.disposeSoundLater(this.url);
  17016. }
  17017. resume() {
  17018. this.startTime = this._pauseTime;
  17019. this.play();
  17020. }
  17021. set volume(v) {
  17022. this._volume = v;
  17023. if (this.isStopped) {
  17024. return;
  17025. }
  17026. if (this.gain.gain.setTargetAtTime) {
  17027. this.gain.gain.setTargetAtTime(v, this.context.currentTime, WebAudioSoundChannel.SetTargetDelay);
  17028. }
  17029. else
  17030. this.gain.gain.value = v;
  17031. }
  17032. get volume() {
  17033. return this._volume;
  17034. }
  17035. }
  17036. WebAudioSoundChannel._tryCleanFailed = false;
  17037. WebAudioSoundChannel.SetTargetDelay = 0.001;
  17038. class WebAudioSound extends EventDispatcher {
  17039. constructor() {
  17040. super(...arguments);
  17041. this.loaded = false;
  17042. this._disposed = false;
  17043. }
  17044. static decode() {
  17045. if (WebAudioSound.buffs.length <= 0 || WebAudioSound.isDecoding) {
  17046. return;
  17047. }
  17048. WebAudioSound.isDecoding = true;
  17049. WebAudioSound.tInfo = WebAudioSound.buffs.shift();
  17050. WebAudioSound.ctx.decodeAudioData(WebAudioSound.tInfo["buffer"], WebAudioSound._done, WebAudioSound._fail);
  17051. }
  17052. static _done(audioBuffer) {
  17053. WebAudioSound.e.event("loaded:" + WebAudioSound.tInfo.url, audioBuffer);
  17054. WebAudioSound.isDecoding = false;
  17055. WebAudioSound.decode();
  17056. }
  17057. static _fail() {
  17058. WebAudioSound.e.event("err:" + WebAudioSound.tInfo.url, null);
  17059. WebAudioSound.isDecoding = false;
  17060. WebAudioSound.decode();
  17061. }
  17062. static _playEmptySound() {
  17063. if (WebAudioSound.ctx == null) {
  17064. return;
  17065. }
  17066. var source = WebAudioSound.ctx.createBufferSource();
  17067. source.buffer = WebAudioSound._miniBuffer;
  17068. source.connect(WebAudioSound.ctx.destination);
  17069. source.start(0, 0, 0);
  17070. }
  17071. static _unlock() {
  17072. if (WebAudioSound._unlocked) {
  17073. return;
  17074. }
  17075. WebAudioSound._playEmptySound();
  17076. if (WebAudioSound.ctx.state == "running") {
  17077. window.document.removeEventListener("mousedown", WebAudioSound._unlock, true);
  17078. window.document.removeEventListener("touchend", WebAudioSound._unlock, true);
  17079. window.document.removeEventListener("touchstart", WebAudioSound._unlock, true);
  17080. WebAudioSound._unlocked = true;
  17081. }
  17082. }
  17083. static initWebAudio() {
  17084. if (WebAudioSound.ctx.state != "running") {
  17085. WebAudioSound._unlock();
  17086. window.document.addEventListener("mousedown", WebAudioSound._unlock, true);
  17087. window.document.addEventListener("touchend", WebAudioSound._unlock, true);
  17088. window.document.addEventListener("touchstart", WebAudioSound._unlock, true);
  17089. }
  17090. }
  17091. load(url) {
  17092. var me = this;
  17093. url = URL.formatURL(url);
  17094. this.url = url;
  17095. this.audioBuffer = WebAudioSound._dataCache[url];
  17096. if (this.audioBuffer) {
  17097. this._loaded(this.audioBuffer);
  17098. return;
  17099. }
  17100. WebAudioSound.e.on("loaded:" + url, this, this._loaded);
  17101. WebAudioSound.e.on("err:" + url, this, this._err);
  17102. if (WebAudioSound.__loadingSound[url]) {
  17103. return;
  17104. }
  17105. WebAudioSound.__loadingSound[url] = true;
  17106. var request = new XMLHttpRequest();
  17107. request.open("GET", url, true);
  17108. request.responseType = "arraybuffer";
  17109. request.onload = function () {
  17110. if (me._disposed) {
  17111. me._removeLoadEvents();
  17112. return;
  17113. }
  17114. me.data = request.response;
  17115. WebAudioSound.buffs.push({ "buffer": me.data, "url": me.url });
  17116. WebAudioSound.decode();
  17117. };
  17118. request.onerror = function (e) {
  17119. me._err();
  17120. };
  17121. request.send();
  17122. }
  17123. _err() {
  17124. this._removeLoadEvents();
  17125. WebAudioSound.__loadingSound[this.url] = false;
  17126. this.event(Event.ERROR);
  17127. }
  17128. _loaded(audioBuffer) {
  17129. this._removeLoadEvents();
  17130. if (this._disposed) {
  17131. return;
  17132. }
  17133. this.audioBuffer = audioBuffer;
  17134. WebAudioSound._dataCache[this.url] = this.audioBuffer;
  17135. this.loaded = true;
  17136. this.event(Event.COMPLETE);
  17137. }
  17138. _removeLoadEvents() {
  17139. WebAudioSound.e.off("loaded:" + this.url, this, this._loaded);
  17140. WebAudioSound.e.off("err:" + this.url, this, this._err);
  17141. }
  17142. __playAfterLoaded() {
  17143. if (!this.__toPlays)
  17144. return;
  17145. var i, len;
  17146. var toPlays;
  17147. toPlays = this.__toPlays;
  17148. len = toPlays.length;
  17149. var tParams;
  17150. for (i = 0; i < len; i++) {
  17151. tParams = toPlays[i];
  17152. if (tParams[2] && !tParams[2].isStopped) {
  17153. this.play(tParams[0], tParams[1], tParams[2]);
  17154. }
  17155. }
  17156. this.__toPlays.length = 0;
  17157. }
  17158. play(startTime = 0, loops = 0, channel = null) {
  17159. channel = channel ? channel : new WebAudioSoundChannel();
  17160. if (!this.audioBuffer) {
  17161. if (this.url) {
  17162. if (!this.__toPlays)
  17163. this.__toPlays = [];
  17164. this.__toPlays.push([startTime, loops, channel]);
  17165. this.once(Event.COMPLETE, this, this.__playAfterLoaded);
  17166. this.load(this.url);
  17167. }
  17168. }
  17169. channel.url = this.url;
  17170. channel.loops = loops;
  17171. channel["audioBuffer"] = this.audioBuffer;
  17172. channel.startTime = startTime;
  17173. channel.play();
  17174. ILaya.SoundManager.addChannel(channel);
  17175. return channel;
  17176. }
  17177. get duration() {
  17178. if (this.audioBuffer) {
  17179. return this.audioBuffer.duration;
  17180. }
  17181. return 0;
  17182. }
  17183. dispose() {
  17184. this._disposed = true;
  17185. delete WebAudioSound._dataCache[this.url];
  17186. delete WebAudioSound.__loadingSound[this.url];
  17187. this.audioBuffer = null;
  17188. this.data = null;
  17189. this.__toPlays = [];
  17190. }
  17191. }
  17192. WebAudioSound._dataCache = {};
  17193. WebAudioSound.webAudioEnabled = window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"];
  17194. WebAudioSound.ctx = WebAudioSound.webAudioEnabled ? new (window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"])() : undefined;
  17195. WebAudioSound.buffs = [];
  17196. WebAudioSound.isDecoding = false;
  17197. WebAudioSound._miniBuffer = WebAudioSound.ctx ? WebAudioSound.ctx.createBuffer(1, 1, 22050) : undefined;
  17198. WebAudioSound.e = new EventDispatcher();
  17199. WebAudioSound._unlocked = false;
  17200. WebAudioSound.__loadingSound = {};
  17201. class SoundManager {
  17202. static __init__() {
  17203. var win = ILaya.Browser.window;
  17204. var supportWebAudio = win["AudioContext"] || win["webkitAudioContext"] || win["mozAudioContext"] ? true : false;
  17205. if (supportWebAudio)
  17206. WebAudioSound.initWebAudio();
  17207. SoundManager._soundClass = supportWebAudio ? WebAudioSound : AudioSound;
  17208. AudioSound._initMusicAudio();
  17209. SoundManager._musicClass = AudioSound;
  17210. return supportWebAudio;
  17211. }
  17212. static addChannel(channel) {
  17213. if (SoundManager._channels.indexOf(channel) >= 0)
  17214. return;
  17215. SoundManager._channels.push(channel);
  17216. }
  17217. static removeChannel(channel) {
  17218. var i;
  17219. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17220. if (SoundManager._channels[i] == channel) {
  17221. SoundManager._channels.splice(i, 1);
  17222. }
  17223. }
  17224. }
  17225. static disposeSoundLater(url) {
  17226. SoundManager._lastSoundUsedTimeDic[url] = ILaya.Browser.now();
  17227. if (!SoundManager._isCheckingDispose) {
  17228. SoundManager._isCheckingDispose = true;
  17229. ILaya.timer.loop(5000, null, SoundManager._checkDisposeSound);
  17230. }
  17231. }
  17232. static _checkDisposeSound() {
  17233. var key;
  17234. var tTime = ILaya.Browser.now();
  17235. var hasCheck = false;
  17236. for (key in SoundManager._lastSoundUsedTimeDic) {
  17237. if (tTime - SoundManager._lastSoundUsedTimeDic[key] > 30000) {
  17238. delete SoundManager._lastSoundUsedTimeDic[key];
  17239. SoundManager.disposeSoundIfNotUsed(key);
  17240. }
  17241. else {
  17242. hasCheck = true;
  17243. }
  17244. }
  17245. if (!hasCheck) {
  17246. SoundManager._isCheckingDispose = false;
  17247. ILaya.timer.clear(null, SoundManager._checkDisposeSound);
  17248. }
  17249. }
  17250. static disposeSoundIfNotUsed(url) {
  17251. var i;
  17252. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17253. if (SoundManager._channels[i].url == url) {
  17254. return;
  17255. }
  17256. }
  17257. SoundManager.destroySound(url);
  17258. }
  17259. static set autoStopMusic(v) {
  17260. ILaya.stage.off(Event.BLUR, null, SoundManager._stageOnBlur);
  17261. ILaya.stage.off(Event.FOCUS, null, SoundManager._stageOnFocus);
  17262. ILaya.stage.off(Event.VISIBILITY_CHANGE, null, SoundManager._visibilityChange);
  17263. SoundManager._autoStopMusic = v;
  17264. if (v) {
  17265. ILaya.stage.on(Event.BLUR, null, SoundManager._stageOnBlur);
  17266. ILaya.stage.on(Event.FOCUS, null, SoundManager._stageOnFocus);
  17267. ILaya.stage.on(Event.VISIBILITY_CHANGE, null, SoundManager._visibilityChange);
  17268. }
  17269. }
  17270. static get autoStopMusic() {
  17271. return SoundManager._autoStopMusic;
  17272. }
  17273. static _visibilityChange() {
  17274. if (ILaya.stage.isVisibility) {
  17275. SoundManager._stageOnFocus();
  17276. }
  17277. else {
  17278. SoundManager._stageOnBlur();
  17279. }
  17280. }
  17281. static _stageOnBlur() {
  17282. SoundManager._isActive = false;
  17283. if (SoundManager._musicChannel) {
  17284. if (!SoundManager._musicChannel.isStopped) {
  17285. SoundManager._blurPaused = true;
  17286. SoundManager._musicChannel.pause();
  17287. }
  17288. }
  17289. SoundManager.stopAllSound();
  17290. ILaya.stage.once(Event.MOUSE_DOWN, null, SoundManager._stageOnFocus);
  17291. }
  17292. static _recoverWebAudio() {
  17293. if (WebAudioSound.ctx && WebAudioSound.ctx.state != "running" && WebAudioSound.ctx.resume)
  17294. WebAudioSound.ctx.resume();
  17295. }
  17296. static _stageOnFocus() {
  17297. SoundManager._isActive = true;
  17298. SoundManager._recoverWebAudio();
  17299. ILaya.stage.off(Event.MOUSE_DOWN, null, SoundManager._stageOnFocus);
  17300. if (SoundManager._blurPaused) {
  17301. if (SoundManager._musicChannel && SoundManager._musicChannel.isStopped) {
  17302. SoundManager._blurPaused = false;
  17303. SoundManager._musicChannel.resume();
  17304. }
  17305. }
  17306. }
  17307. static set muted(value) {
  17308. if (value == SoundManager._muted)
  17309. return;
  17310. if (value) {
  17311. SoundManager.stopAllSound();
  17312. }
  17313. SoundManager.musicMuted = value;
  17314. SoundManager._muted = value;
  17315. }
  17316. static get muted() {
  17317. return SoundManager._muted;
  17318. }
  17319. static set soundMuted(value) {
  17320. SoundManager._soundMuted = value;
  17321. }
  17322. static get soundMuted() {
  17323. return SoundManager._soundMuted;
  17324. }
  17325. static set musicMuted(value) {
  17326. if (value == SoundManager._musicMuted)
  17327. return;
  17328. if (value) {
  17329. if (SoundManager._bgMusic) {
  17330. if (SoundManager._musicChannel && !SoundManager._musicChannel.isStopped) {
  17331. if (ILaya.Render.isConchApp) {
  17332. if (SoundManager._musicChannel._audio)
  17333. SoundManager._musicChannel._audio.muted = true;
  17334. }
  17335. else {
  17336. SoundManager._musicChannel.pause();
  17337. }
  17338. }
  17339. else {
  17340. SoundManager._musicChannel = null;
  17341. }
  17342. }
  17343. else {
  17344. SoundManager._musicChannel = null;
  17345. }
  17346. SoundManager._musicMuted = value;
  17347. }
  17348. else {
  17349. SoundManager._musicMuted = value;
  17350. if (SoundManager._bgMusic) {
  17351. if (SoundManager._musicChannel) {
  17352. if (ILaya.Render.isConchApp) {
  17353. if (SoundManager._musicChannel._audio)
  17354. SoundManager._musicChannel._audio.muted = false;
  17355. }
  17356. else {
  17357. SoundManager._musicChannel.resume();
  17358. }
  17359. }
  17360. }
  17361. }
  17362. }
  17363. static get musicMuted() {
  17364. return SoundManager._musicMuted;
  17365. }
  17366. static get useAudioMusic() {
  17367. return SoundManager._useAudioMusic;
  17368. }
  17369. static set useAudioMusic(value) {
  17370. SoundManager._useAudioMusic = value;
  17371. if (value) {
  17372. SoundManager._musicClass = AudioSound;
  17373. }
  17374. else {
  17375. SoundManager._musicClass = null;
  17376. }
  17377. }
  17378. static playSound(url, loops = 1, complete = null, soundClass = null, startTime = 0) {
  17379. if (!SoundManager._isActive || !url)
  17380. return null;
  17381. if (SoundManager._muted)
  17382. return null;
  17383. SoundManager._recoverWebAudio();
  17384. url = URL.formatURL(url);
  17385. if (url == SoundManager._bgMusic) {
  17386. if (SoundManager._musicMuted)
  17387. return null;
  17388. }
  17389. else {
  17390. if (ILaya.Render.isConchApp) {
  17391. var ext = Utils.getFileExtension(url);
  17392. if (ext != "wav" && ext != "ogg") {
  17393. alert("The sound only supports wav or ogg format,for optimal performance reason,please refer to the official website document.");
  17394. return null;
  17395. }
  17396. }
  17397. if (SoundManager._soundMuted)
  17398. return null;
  17399. }
  17400. var tSound;
  17401. if (!ILaya.Browser.onBDMiniGame && !ILaya.Browser.onMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame) {
  17402. tSound = ILaya.loader.getRes(url);
  17403. }
  17404. if (!soundClass)
  17405. soundClass = SoundManager._soundClass;
  17406. if (!tSound) {
  17407. tSound = new soundClass();
  17408. tSound.load(url);
  17409. if (!ILaya.Browser.onBDMiniGame && !ILaya.Browser.onMiniGame && !ILaya.Browser.onKGMiniGame && !ILaya.Browser.onQGMiniGame && !ILaya.Browser.onVVMiniGame && !ILaya.Browser.onAlipayMiniGame && !ILaya.Browser.onQQMiniGame) {
  17410. ILaya.Loader.cacheRes(url, tSound);
  17411. }
  17412. }
  17413. var channel;
  17414. channel = tSound.play(startTime, loops);
  17415. if (!channel)
  17416. return null;
  17417. channel.url = url;
  17418. channel.volume = (url == SoundManager._bgMusic) ? SoundManager.musicVolume : SoundManager.soundVolume;
  17419. channel.completeHandler = complete;
  17420. return channel;
  17421. }
  17422. static destroySound(url) {
  17423. var tSound = ILaya.loader.getRes(url);
  17424. if (tSound) {
  17425. ILaya.Loader.clearRes(url);
  17426. tSound.dispose();
  17427. }
  17428. }
  17429. static playMusic(url, loops = 0, complete = null, startTime = 0) {
  17430. url = URL.formatURL(url);
  17431. SoundManager._bgMusic = url;
  17432. if (SoundManager._musicChannel)
  17433. SoundManager._musicChannel.stop();
  17434. return SoundManager._musicChannel = SoundManager.playSound(url, loops, complete, SoundManager._musicClass, startTime);
  17435. }
  17436. static stopSound(url) {
  17437. url = URL.formatURL(url);
  17438. var i;
  17439. var channel;
  17440. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17441. channel = SoundManager._channels[i];
  17442. if (channel.url == url) {
  17443. channel.stop();
  17444. }
  17445. }
  17446. }
  17447. static stopAll() {
  17448. SoundManager._bgMusic = null;
  17449. var i;
  17450. var channel;
  17451. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17452. channel = SoundManager._channels[i];
  17453. channel.stop();
  17454. }
  17455. }
  17456. static stopAllSound() {
  17457. var i;
  17458. var channel;
  17459. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17460. channel = SoundManager._channels[i];
  17461. if (channel.url != SoundManager._bgMusic) {
  17462. channel.stop();
  17463. }
  17464. }
  17465. }
  17466. static stopMusic() {
  17467. if (SoundManager._musicChannel)
  17468. SoundManager._musicChannel.stop();
  17469. SoundManager._bgMusic = null;
  17470. }
  17471. static setSoundVolume(volume, url = null) {
  17472. if (url) {
  17473. url = URL.formatURL(url);
  17474. SoundManager._setVolume(url, volume);
  17475. }
  17476. else {
  17477. SoundManager.soundVolume = volume;
  17478. var i;
  17479. var channel;
  17480. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17481. channel = SoundManager._channels[i];
  17482. if (channel.url != SoundManager._bgMusic) {
  17483. channel.volume = volume;
  17484. }
  17485. }
  17486. }
  17487. }
  17488. static setMusicVolume(volume) {
  17489. SoundManager.musicVolume = volume;
  17490. SoundManager._setVolume(SoundManager._bgMusic, volume);
  17491. }
  17492. static _setVolume(url, volume) {
  17493. url = URL.formatURL(url);
  17494. var i;
  17495. var channel;
  17496. for (i = SoundManager._channels.length - 1; i >= 0; i--) {
  17497. channel = SoundManager._channels[i];
  17498. if (channel.url == url) {
  17499. channel.volume = volume;
  17500. }
  17501. }
  17502. }
  17503. }
  17504. SoundManager.musicVolume = 1;
  17505. SoundManager.soundVolume = 1;
  17506. SoundManager.playbackRate = 1;
  17507. SoundManager._useAudioMusic = true;
  17508. SoundManager._muted = false;
  17509. SoundManager._soundMuted = false;
  17510. SoundManager._musicMuted = false;
  17511. SoundManager._bgMusic = null;
  17512. SoundManager._musicChannel = null;
  17513. SoundManager._channels = [];
  17514. SoundManager._blurPaused = false;
  17515. SoundManager._isActive = true;
  17516. SoundManager._lastSoundUsedTimeDic = {};
  17517. SoundManager._isCheckingDispose = false;
  17518. SoundManager.autoReleaseSound = true;
  17519. class HttpRequest extends EventDispatcher {
  17520. constructor() {
  17521. super(...arguments);
  17522. this._http = new XMLHttpRequest();
  17523. }
  17524. send(url, data = null, method = "get", responseType = "text", headers = null) {
  17525. this._responseType = responseType;
  17526. this._data = null;
  17527. if (Browser.onVVMiniGame || Browser.onQGMiniGame || Browser.onQQMiniGame) {
  17528. url = encodeURI(url);
  17529. }
  17530. this._url = url;
  17531. var _this = this;
  17532. var http = this._http;
  17533. url = URL.getAdptedFilePath(url);
  17534. http.open(method, url, true);
  17535. if (headers) {
  17536. for (var i = 0; i < headers.length; i++) {
  17537. http.setRequestHeader(headers[i++], headers[i]);
  17538. }
  17539. }
  17540. else if (!(window.conch)) {
  17541. if (!data || typeof (data) == 'string')
  17542. http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  17543. else
  17544. http.setRequestHeader("Content-Type", "application/json");
  17545. }
  17546. let restype = responseType !== "arraybuffer" ? "text" : "arraybuffer";
  17547. http.responseType = restype;
  17548. if (http.dataType) {
  17549. http.dataType = restype;
  17550. }
  17551. http.onerror = function (e) {
  17552. _this._onError(e);
  17553. };
  17554. http.onabort = function (e) {
  17555. _this._onAbort(e);
  17556. };
  17557. http.onprogress = function (e) {
  17558. _this._onProgress(e);
  17559. };
  17560. http.onload = function (e) {
  17561. _this._onLoad(e);
  17562. };
  17563. http.send(data);
  17564. }
  17565. _onProgress(e) {
  17566. if (e && e.lengthComputable)
  17567. this.event(Event.PROGRESS, e.loaded / e.total);
  17568. }
  17569. _onAbort(e) {
  17570. this.error("Request was aborted by user");
  17571. }
  17572. _onError(e) {
  17573. this.error("Request failed Status:" + this._http.status + " text:" + this._http.statusText);
  17574. }
  17575. _onLoad(e) {
  17576. var http = this._http;
  17577. var status = http.status !== undefined ? http.status : 200;
  17578. if (status === 200 || status === 204 || status === 0) {
  17579. this.complete();
  17580. }
  17581. else {
  17582. this.error("[" + http.status + "]" + http.statusText + ":" + http.responseURL);
  17583. }
  17584. }
  17585. error(message) {
  17586. this.clear();
  17587. console.warn(this.url, message);
  17588. this.event(Event.ERROR, message);
  17589. }
  17590. complete() {
  17591. this.clear();
  17592. var flag = true;
  17593. try {
  17594. if (this._responseType === "json") {
  17595. this._data = JSON.parse(this._http.responseText);
  17596. }
  17597. else if (this._responseType === "xml") {
  17598. this._data = Utils.parseXMLFromString(this._http.responseText);
  17599. }
  17600. else {
  17601. this._data = this._http.response || this._http.responseText;
  17602. }
  17603. }
  17604. catch (e) {
  17605. flag = false;
  17606. this.error(e.message);
  17607. }
  17608. flag && this.event(Event.COMPLETE, this._data instanceof Array ? [this._data] : this._data);
  17609. }
  17610. clear() {
  17611. var http = this._http;
  17612. http.onerror = http.onabort = http.onprogress = http.onload = null;
  17613. }
  17614. get url() {
  17615. return this._url;
  17616. }
  17617. get data() {
  17618. return this._data;
  17619. }
  17620. get http() {
  17621. return this._http;
  17622. }
  17623. }
  17624. class BitmapFont {
  17625. constructor() {
  17626. this._fontCharDic = {};
  17627. this._fontWidthMap = {};
  17628. this._maxWidth = 0;
  17629. this._spaceWidth = 10;
  17630. this.fontSize = 12;
  17631. this.autoScaleSize = false;
  17632. this.letterSpacing = 0;
  17633. }
  17634. loadFont(path, complete) {
  17635. this._path = path;
  17636. this._complete = complete;
  17637. if (!path || path.indexOf(".fnt") === -1) {
  17638. console.error('Bitmap font configuration information must be a ".fnt" file');
  17639. return;
  17640. }
  17641. ILaya.loader.load([{ url: path, type: ILaya.Loader.XML }, { url: path.replace(".fnt", ".png"), type: ILaya.Loader.IMAGE }], Handler.create(this, this._onLoaded));
  17642. }
  17643. _onLoaded() {
  17644. this.parseFont(ILaya.Loader.getRes(this._path), ILaya.Loader.getRes(this._path.replace(".fnt", ".png")));
  17645. this._complete && this._complete.run();
  17646. }
  17647. parseFont(xml, texture) {
  17648. if (xml == null || texture == null)
  17649. return;
  17650. this._texture = texture;
  17651. var tScale = 1;
  17652. var tInfo = xml.getElementsByTagName("info");
  17653. if (!tInfo[0].getAttributeNode) {
  17654. return this.parseFont2(xml, texture);
  17655. }
  17656. this.fontSize = parseInt(tInfo[0].getAttributeNode("size").nodeValue);
  17657. var tPadding = tInfo[0].getAttributeNode("padding").nodeValue;
  17658. var tPaddingArray = tPadding.split(",");
  17659. this._padding = [parseInt(tPaddingArray[0]), parseInt(tPaddingArray[1]), parseInt(tPaddingArray[2]), parseInt(tPaddingArray[3])];
  17660. var chars = xml.getElementsByTagName("char");
  17661. var i = 0;
  17662. for (i = 0; i < chars.length; i++) {
  17663. var tAttribute = chars[i];
  17664. var tId = parseInt(tAttribute.getAttributeNode("id").nodeValue);
  17665. var xOffset = parseInt(tAttribute.getAttributeNode("xoffset").nodeValue) / tScale;
  17666. var yOffset = parseInt(tAttribute.getAttributeNode("yoffset").nodeValue) / tScale;
  17667. var xAdvance = parseInt(tAttribute.getAttributeNode("xadvance").nodeValue) / tScale;
  17668. var region = new Rectangle();
  17669. region.x = parseInt(tAttribute.getAttributeNode("x").nodeValue);
  17670. region.y = parseInt(tAttribute.getAttributeNode("y").nodeValue);
  17671. region.width = parseInt(tAttribute.getAttributeNode("width").nodeValue);
  17672. region.height = parseInt(tAttribute.getAttributeNode("height").nodeValue);
  17673. var tTexture = Texture.create(texture, region.x, region.y, region.width, region.height, xOffset, yOffset);
  17674. this._maxWidth = Math.max(this._maxWidth, xAdvance + this.letterSpacing);
  17675. this._fontCharDic[tId] = tTexture;
  17676. this._fontWidthMap[tId] = xAdvance;
  17677. }
  17678. }
  17679. parseFont2(xml, texture) {
  17680. if (xml == null || texture == null)
  17681. return;
  17682. this._texture = texture;
  17683. var tScale = 1;
  17684. var tInfo = xml.getElementsByTagName("info");
  17685. this.fontSize = parseInt(tInfo[0].attributes["size"].nodeValue);
  17686. var tPadding = tInfo[0].attributes["padding"].nodeValue;
  17687. var tPaddingArray = tPadding.split(",");
  17688. this._padding = [parseInt(tPaddingArray[0]), parseInt(tPaddingArray[1]), parseInt(tPaddingArray[2]), parseInt(tPaddingArray[3])];
  17689. var chars = xml.getElementsByTagName("char");
  17690. var i = 0;
  17691. for (i = 0; i < chars.length; i++) {
  17692. var tAttribute = chars[i].attributes;
  17693. var tId = parseInt(tAttribute["id"].nodeValue);
  17694. var xOffset = parseInt(tAttribute["xoffset"].nodeValue) / tScale;
  17695. var yOffset = parseInt(tAttribute["yoffset"].nodeValue) / tScale;
  17696. var xAdvance = parseInt(tAttribute["xadvance"].nodeValue) / tScale;
  17697. var region = new Rectangle();
  17698. region.x = parseInt(tAttribute["x"].nodeValue);
  17699. region.y = parseInt(tAttribute["y"].nodeValue);
  17700. region.width = parseInt(tAttribute["width"].nodeValue);
  17701. region.height = parseInt(tAttribute["height"].nodeValue);
  17702. var tTexture = Texture.create(texture, region.x, region.y, region.width, region.height, xOffset, yOffset);
  17703. this._maxWidth = Math.max(this._maxWidth, xAdvance + this.letterSpacing);
  17704. this._fontCharDic[tId] = tTexture;
  17705. this._fontWidthMap[tId] = xAdvance;
  17706. }
  17707. }
  17708. getCharTexture(char) {
  17709. return this._fontCharDic[char.charCodeAt(0)];
  17710. }
  17711. destroy() {
  17712. if (this._texture) {
  17713. for (var p in this._fontCharDic) {
  17714. var tTexture = this._fontCharDic[p];
  17715. if (tTexture)
  17716. tTexture.destroy();
  17717. }
  17718. this._texture.destroy();
  17719. this._fontCharDic = null;
  17720. this._fontWidthMap = null;
  17721. this._texture = null;
  17722. this._complete = null;
  17723. this._padding = null;
  17724. }
  17725. }
  17726. setSpaceWidth(spaceWidth) {
  17727. this._spaceWidth = spaceWidth;
  17728. }
  17729. getCharWidth(char) {
  17730. var code = char.charCodeAt(0);
  17731. if (this._fontWidthMap[code])
  17732. return this._fontWidthMap[code] + this.letterSpacing;
  17733. if (char === " ")
  17734. return this._spaceWidth + this.letterSpacing;
  17735. return 0;
  17736. }
  17737. getTextWidth(text) {
  17738. var tWidth = 0;
  17739. for (var i = 0, n = text.length; i < n; i++) {
  17740. tWidth += this.getCharWidth(text.charAt(i));
  17741. }
  17742. return tWidth;
  17743. }
  17744. getMaxWidth() {
  17745. return this._maxWidth;
  17746. }
  17747. getMaxHeight() {
  17748. return this.fontSize;
  17749. }
  17750. _drawText(text, sprite, drawX, drawY, align, width) {
  17751. var tWidth = this.getTextWidth(text);
  17752. var tTexture;
  17753. var dx = 0;
  17754. align === "center" && (dx = (width - tWidth) / 2);
  17755. align === "right" && (dx = (width - tWidth));
  17756. var tx = 0;
  17757. for (var i = 0, n = text.length; i < n; i++) {
  17758. tTexture = this.getCharTexture(text.charAt(i));
  17759. if (tTexture) {
  17760. sprite.graphics.drawImage(tTexture, drawX + tx + dx, drawY);
  17761. tx += this.getCharWidth(text.charAt(i));
  17762. }
  17763. }
  17764. }
  17765. }
  17766. ClassUtils.regClass("laya.display.BitmapFont", BitmapFont);
  17767. ClassUtils.regClass("Laya.BitmapFont", BitmapFont);
  17768. class Prefab {
  17769. create() {
  17770. if (this.json)
  17771. return ILaya.SceneUtils.createByData(null, this.json);
  17772. return null;
  17773. }
  17774. }
  17775. class Byte {
  17776. constructor(data = null) {
  17777. this._xd_ = true;
  17778. this._allocated_ = 8;
  17779. this._pos_ = 0;
  17780. this._length = 0;
  17781. if (data) {
  17782. this._u8d_ = new Uint8Array(data);
  17783. this._d_ = new DataView(this._u8d_.buffer);
  17784. this._length = this._d_.byteLength;
  17785. }
  17786. else {
  17787. this._resizeBuffer(this._allocated_);
  17788. }
  17789. }
  17790. static getSystemEndian() {
  17791. if (!Byte._sysEndian) {
  17792. var buffer = new ArrayBuffer(2);
  17793. new DataView(buffer).setInt16(0, 256, true);
  17794. Byte._sysEndian = (new Int16Array(buffer))[0] === 256 ? Byte.LITTLE_ENDIAN : Byte.BIG_ENDIAN;
  17795. }
  17796. return Byte._sysEndian;
  17797. }
  17798. get buffer() {
  17799. var rstBuffer = this._d_.buffer;
  17800. if (rstBuffer.byteLength === this._length)
  17801. return rstBuffer;
  17802. return rstBuffer.slice(0, this._length);
  17803. }
  17804. get endian() {
  17805. return this._xd_ ? Byte.LITTLE_ENDIAN : Byte.BIG_ENDIAN;
  17806. }
  17807. set endian(value) {
  17808. this._xd_ = (value === Byte.LITTLE_ENDIAN);
  17809. }
  17810. set length(value) {
  17811. if (this._allocated_ < value)
  17812. this._resizeBuffer(this._allocated_ = Math.floor(Math.max(value, this._allocated_ * 2)));
  17813. else if (this._allocated_ > value)
  17814. this._resizeBuffer(this._allocated_ = value);
  17815. this._length = value;
  17816. }
  17817. get length() {
  17818. return this._length;
  17819. }
  17820. _resizeBuffer(len) {
  17821. try {
  17822. var newByteView = new Uint8Array(len);
  17823. if (this._u8d_ != null) {
  17824. if (this._u8d_.length <= len)
  17825. newByteView.set(this._u8d_);
  17826. else
  17827. newByteView.set(this._u8d_.subarray(0, len));
  17828. }
  17829. this._u8d_ = newByteView;
  17830. this._d_ = new DataView(newByteView.buffer);
  17831. }
  17832. catch (err) {
  17833. throw "Invalid typed array length:" + len;
  17834. }
  17835. }
  17836. getString() {
  17837. return this.readString();
  17838. }
  17839. readString() {
  17840. return this._rUTF(this.getUint16());
  17841. }
  17842. getFloat32Array(start, len) {
  17843. return this.readFloat32Array(start, len);
  17844. }
  17845. readFloat32Array(start, len) {
  17846. var end = start + len;
  17847. end = (end > this._length) ? this._length : end;
  17848. var v = new Float32Array(this._d_.buffer.slice(start, end));
  17849. this._pos_ = end;
  17850. return v;
  17851. }
  17852. getUint8Array(start, len) {
  17853. return this.readUint8Array(start, len);
  17854. }
  17855. readUint8Array(start, len) {
  17856. var end = start + len;
  17857. end = (end > this._length) ? this._length : end;
  17858. var v = new Uint8Array(this._d_.buffer.slice(start, end));
  17859. this._pos_ = end;
  17860. return v;
  17861. }
  17862. getInt16Array(start, len) {
  17863. return this.readInt16Array(start, len);
  17864. }
  17865. readInt16Array(start, len) {
  17866. var end = start + len;
  17867. end = (end > this._length) ? this._length : end;
  17868. var v = new Int16Array(this._d_.buffer.slice(start, end));
  17869. this._pos_ = end;
  17870. return v;
  17871. }
  17872. getFloat32() {
  17873. return this.readFloat32();
  17874. }
  17875. readFloat32() {
  17876. if (this._pos_ + 4 > this._length)
  17877. throw "getFloat32 error - Out of bounds";
  17878. var v = this._d_.getFloat32(this._pos_, this._xd_);
  17879. this._pos_ += 4;
  17880. return v;
  17881. }
  17882. getFloat64() {
  17883. return this.readFloat64();
  17884. }
  17885. readFloat64() {
  17886. if (this._pos_ + 8 > this._length)
  17887. throw "getFloat64 error - Out of bounds";
  17888. var v = this._d_.getFloat64(this._pos_, this._xd_);
  17889. this._pos_ += 8;
  17890. return v;
  17891. }
  17892. writeFloat32(value) {
  17893. this._ensureWrite(this._pos_ + 4);
  17894. this._d_.setFloat32(this._pos_, value, this._xd_);
  17895. this._pos_ += 4;
  17896. }
  17897. writeFloat64(value) {
  17898. this._ensureWrite(this._pos_ + 8);
  17899. this._d_.setFloat64(this._pos_, value, this._xd_);
  17900. this._pos_ += 8;
  17901. }
  17902. getInt32() {
  17903. return this.readInt32();
  17904. }
  17905. readInt32() {
  17906. if (this._pos_ + 4 > this._length)
  17907. throw "getInt32 error - Out of bounds";
  17908. var float = this._d_.getInt32(this._pos_, this._xd_);
  17909. this._pos_ += 4;
  17910. return float;
  17911. }
  17912. getUint32() {
  17913. return this.readUint32();
  17914. }
  17915. readUint32() {
  17916. if (this._pos_ + 4 > this._length)
  17917. throw "getUint32 error - Out of bounds";
  17918. var v = this._d_.getUint32(this._pos_, this._xd_);
  17919. this._pos_ += 4;
  17920. return v;
  17921. }
  17922. writeInt32(value) {
  17923. this._ensureWrite(this._pos_ + 4);
  17924. this._d_.setInt32(this._pos_, value, this._xd_);
  17925. this._pos_ += 4;
  17926. }
  17927. writeUint32(value) {
  17928. this._ensureWrite(this._pos_ + 4);
  17929. this._d_.setUint32(this._pos_, value, this._xd_);
  17930. this._pos_ += 4;
  17931. }
  17932. getInt16() {
  17933. return this.readInt16();
  17934. }
  17935. readInt16() {
  17936. if (this._pos_ + 2 > this._length)
  17937. throw "getInt16 error - Out of bounds";
  17938. var us = this._d_.getInt16(this._pos_, this._xd_);
  17939. this._pos_ += 2;
  17940. return us;
  17941. }
  17942. getUint16() {
  17943. return this.readUint16();
  17944. }
  17945. readUint16() {
  17946. if (this._pos_ + 2 > this._length)
  17947. throw "getUint16 error - Out of bounds";
  17948. var us = this._d_.getUint16(this._pos_, this._xd_);
  17949. this._pos_ += 2;
  17950. return us;
  17951. }
  17952. writeUint16(value) {
  17953. this._ensureWrite(this._pos_ + 2);
  17954. this._d_.setUint16(this._pos_, value, this._xd_);
  17955. this._pos_ += 2;
  17956. }
  17957. writeInt16(value) {
  17958. this._ensureWrite(this._pos_ + 2);
  17959. this._d_.setInt16(this._pos_, value, this._xd_);
  17960. this._pos_ += 2;
  17961. }
  17962. getUint8() {
  17963. return this.readUint8();
  17964. }
  17965. readUint8() {
  17966. if (this._pos_ + 1 > this._length)
  17967. throw "getUint8 error - Out of bounds";
  17968. return this._u8d_[this._pos_++];
  17969. }
  17970. writeUint8(value) {
  17971. this._ensureWrite(this._pos_ + 1);
  17972. this._d_.setUint8(this._pos_, value);
  17973. this._pos_++;
  17974. }
  17975. _getUInt8(pos) {
  17976. return this._readUInt8(pos);
  17977. }
  17978. _readUInt8(pos) {
  17979. return this._d_.getUint8(pos);
  17980. }
  17981. _getUint16(pos) {
  17982. return this._readUint16(pos);
  17983. }
  17984. _readUint16(pos) {
  17985. return this._d_.getUint16(pos, this._xd_);
  17986. }
  17987. _getMatrix() {
  17988. return this._readMatrix();
  17989. }
  17990. _readMatrix() {
  17991. var rst = new Matrix(this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32(), this.getFloat32());
  17992. return rst;
  17993. }
  17994. _rUTF(len) {
  17995. var max = this._pos_ + len, c, c2, c3, f = String.fromCharCode;
  17996. var u = this._u8d_;
  17997. var strs = [];
  17998. var n = 0;
  17999. strs.length = 1000;
  18000. while (this._pos_ < max) {
  18001. c = u[this._pos_++];
  18002. if (c < 0x80) {
  18003. if (c != 0)
  18004. strs[n++] = f(c);
  18005. }
  18006. else if (c < 0xE0) {
  18007. strs[n++] = f(((c & 0x3F) << 6) | (u[this._pos_++] & 0x7F));
  18008. }
  18009. else if (c < 0xF0) {
  18010. c2 = u[this._pos_++];
  18011. strs[n++] = f(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (u[this._pos_++] & 0x7F));
  18012. }
  18013. else {
  18014. c2 = u[this._pos_++];
  18015. c3 = u[this._pos_++];
  18016. strs[n++] = f(((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 << 6) & 0x7F) | (u[this._pos_++] & 0x7F));
  18017. }
  18018. }
  18019. strs.length = n;
  18020. return strs.join('');
  18021. }
  18022. getCustomString(len) {
  18023. return this.readCustomString(len);
  18024. }
  18025. readCustomString(len) {
  18026. var v = "", ulen = 0, c, c2, f = String.fromCharCode;
  18027. var u = this._u8d_;
  18028. while (len > 0) {
  18029. c = u[this._pos_];
  18030. if (c < 0x80) {
  18031. v += f(c);
  18032. this._pos_++;
  18033. len--;
  18034. }
  18035. else {
  18036. ulen = c - 0x80;
  18037. this._pos_++;
  18038. len -= ulen;
  18039. while (ulen > 0) {
  18040. c = u[this._pos_++];
  18041. c2 = u[this._pos_++];
  18042. v += f((c2 << 8) | c);
  18043. ulen--;
  18044. }
  18045. }
  18046. }
  18047. return v;
  18048. }
  18049. get pos() {
  18050. return this._pos_;
  18051. }
  18052. set pos(value) {
  18053. this._pos_ = value;
  18054. }
  18055. get bytesAvailable() {
  18056. return this._length - this._pos_;
  18057. }
  18058. clear() {
  18059. this._pos_ = 0;
  18060. this.length = 0;
  18061. }
  18062. __getBuffer() {
  18063. return this._d_.buffer;
  18064. }
  18065. writeUTFBytes(value) {
  18066. value = value + "";
  18067. for (var i = 0, sz = value.length; i < sz; i++) {
  18068. var c = value.charCodeAt(i);
  18069. if (c <= 0x7F) {
  18070. this.writeByte(c);
  18071. }
  18072. else if (c <= 0x7FF) {
  18073. this._ensureWrite(this._pos_ + 2);
  18074. this._u8d_.set([0xC0 | (c >> 6), 0x80 | (c & 0x3F)], this._pos_);
  18075. this._pos_ += 2;
  18076. }
  18077. else if (c <= 0xFFFF) {
  18078. this._ensureWrite(this._pos_ + 3);
  18079. this._u8d_.set([0xE0 | (c >> 12), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F)], this._pos_);
  18080. this._pos_ += 3;
  18081. }
  18082. else {
  18083. this._ensureWrite(this._pos_ + 4);
  18084. this._u8d_.set([0xF0 | (c >> 18), 0x80 | ((c >> 12) & 0x3F), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F)], this._pos_);
  18085. this._pos_ += 4;
  18086. }
  18087. }
  18088. }
  18089. writeUTFString(value) {
  18090. var tPos = this.pos;
  18091. this.writeUint16(1);
  18092. this.writeUTFBytes(value);
  18093. var dPos = this.pos - tPos - 2;
  18094. this._d_.setUint16(tPos, dPos, this._xd_);
  18095. }
  18096. readUTFString() {
  18097. return this.readUTFBytes(this.getUint16());
  18098. }
  18099. getUTFString() {
  18100. return this.readUTFString();
  18101. }
  18102. readUTFBytes(len = -1) {
  18103. if (len === 0)
  18104. return "";
  18105. var lastBytes = this.bytesAvailable;
  18106. if (len > lastBytes)
  18107. throw "readUTFBytes error - Out of bounds";
  18108. len = len > 0 ? len : lastBytes;
  18109. return this._rUTF(len);
  18110. }
  18111. getUTFBytes(len = -1) {
  18112. return this.readUTFBytes(len);
  18113. }
  18114. writeByte(value) {
  18115. this._ensureWrite(this._pos_ + 1);
  18116. this._d_.setInt8(this._pos_, value);
  18117. this._pos_ += 1;
  18118. }
  18119. readByte() {
  18120. if (this._pos_ + 1 > this._length)
  18121. throw "readByte error - Out of bounds";
  18122. return this._d_.getInt8(this._pos_++);
  18123. }
  18124. getByte() {
  18125. return this.readByte();
  18126. }
  18127. _ensureWrite(lengthToEnsure) {
  18128. if (this._length < lengthToEnsure)
  18129. this._length = lengthToEnsure;
  18130. if (this._allocated_ < lengthToEnsure)
  18131. this.length = lengthToEnsure;
  18132. }
  18133. writeArrayBuffer(arraybuffer, offset = 0, length = 0) {
  18134. if (offset < 0 || length < 0)
  18135. throw "writeArrayBuffer error - Out of bounds";
  18136. if (length == 0)
  18137. length = arraybuffer.byteLength - offset;
  18138. this._ensureWrite(this._pos_ + length);
  18139. var uint8array = new Uint8Array(arraybuffer);
  18140. this._u8d_.set(uint8array.subarray(offset, offset + length), this._pos_);
  18141. this._pos_ += length;
  18142. }
  18143. readArrayBuffer(length) {
  18144. var rst;
  18145. rst = this._u8d_.buffer.slice(this._pos_, this._pos_ + length);
  18146. this._pos_ = this._pos_ + length;
  18147. return rst;
  18148. }
  18149. }
  18150. Byte.BIG_ENDIAN = "bigEndian";
  18151. Byte.LITTLE_ENDIAN = "littleEndian";
  18152. Byte._sysEndian = null;
  18153. class Loader extends EventDispatcher {
  18154. constructor() {
  18155. super(...arguments);
  18156. this._customParse = false;
  18157. }
  18158. static getTypeFromUrl(url) {
  18159. var type = Utils.getFileExtension(url);
  18160. if (type)
  18161. return Loader.typeMap[type];
  18162. console.warn("Not recognize the resources suffix", url);
  18163. return "text";
  18164. }
  18165. load(url, type = null, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
  18166. if (!url) {
  18167. this.onLoaded(null);
  18168. return;
  18169. }
  18170. Loader.setGroup(url, "666");
  18171. this._url = url;
  18172. if (url.indexOf("data:image") === 0)
  18173. type = Loader.IMAGE;
  18174. else
  18175. url = URL.formatURL(url);
  18176. this._type = type || (type = Loader.getTypeFromUrl(this._url));
  18177. this._cache = cache;
  18178. this._useWorkerLoader = useWorkerLoader;
  18179. this._data = null;
  18180. if (useWorkerLoader)
  18181. ILaya.WorkerLoader.enableWorkerLoader();
  18182. if (!ignoreCache && Loader.loadedMap[url]) {
  18183. this._data = Loader.loadedMap[url];
  18184. this.event(Event.PROGRESS, 1);
  18185. this.event(Event.COMPLETE, this._data);
  18186. return;
  18187. }
  18188. if (group)
  18189. Loader.setGroup(url, group);
  18190. if (Loader.parserMap[type] != null) {
  18191. this._customParse = true;
  18192. if (Loader.parserMap[type] instanceof Handler)
  18193. Loader.parserMap[type].runWith(this);
  18194. else
  18195. Loader.parserMap[type].call(null, this);
  18196. return;
  18197. }
  18198. this._loadResourceFilter(type, url);
  18199. }
  18200. _loadResourceFilter(type, url) {
  18201. this._loadResource(type, url);
  18202. }
  18203. _loadResource(type, url) {
  18204. switch (type) {
  18205. case Loader.IMAGE:
  18206. case "htmlimage":
  18207. case "nativeimage":
  18208. this._loadImage(url);
  18209. break;
  18210. case Loader.SOUND:
  18211. this._loadSound(url);
  18212. break;
  18213. case Loader.TTF:
  18214. this._loadTTF(url);
  18215. break;
  18216. case Loader.ATLAS:
  18217. case Loader.PREFAB:
  18218. case Loader.PLF:
  18219. this._loadHttpRequestWhat(url, Loader.JSON);
  18220. break;
  18221. case Loader.FONT:
  18222. this._loadHttpRequestWhat(url, Loader.XML);
  18223. break;
  18224. case Loader.PLFB:
  18225. this._loadHttpRequestWhat(url, Loader.BUFFER);
  18226. break;
  18227. default:
  18228. this._loadHttpRequestWhat(url, type);
  18229. }
  18230. }
  18231. _loadHttpRequest(url, contentType, onLoadCaller, onLoad, onProcessCaller, onProcess, onErrorCaller, onError) {
  18232. if (Browser.onVVMiniGame) {
  18233. this._http = new HttpRequest();
  18234. }
  18235. else {
  18236. if (!this._http)
  18237. this._http = new HttpRequest();
  18238. }
  18239. this._http.on(Event.PROGRESS, onProcessCaller, onProcess);
  18240. this._http.on(Event.COMPLETE, onLoadCaller, onLoad);
  18241. this._http.on(Event.ERROR, onErrorCaller, onError);
  18242. this._http.send(url, null, "get", contentType);
  18243. }
  18244. _loadHtmlImage(url, onLoadCaller, onLoad, onErrorCaller, onError) {
  18245. var image;
  18246. function clear() {
  18247. var img = image;
  18248. img.onload = null;
  18249. img.onerror = null;
  18250. delete Loader._imgCache[url];
  18251. }
  18252. var onerror = function () {
  18253. clear();
  18254. onError.call(onErrorCaller);
  18255. };
  18256. var onload = function () {
  18257. clear();
  18258. onLoad.call(onLoadCaller, image);
  18259. };
  18260. image = new Browser.window.Image();
  18261. image.crossOrigin = "";
  18262. image.onload = onload;
  18263. image.onerror = onerror;
  18264. image.src = url;
  18265. Loader._imgCache[url] = image;
  18266. }
  18267. _loadHttpRequestWhat(url, contentType) {
  18268. if (Loader.preLoadedMap[url])
  18269. this.onLoaded(Loader.preLoadedMap[url]);
  18270. else
  18271. this._loadHttpRequest(url, contentType, this, this.onLoaded, this, this.onProgress, this, this.onError);
  18272. }
  18273. _loadTTF(url) {
  18274. url = URL.formatURL(url);
  18275. var ttfLoader = new ILaya.TTFLoader();
  18276. ttfLoader.complete = Handler.create(this, this.onLoaded);
  18277. ttfLoader.load(url);
  18278. }
  18279. _loadImage(url) {
  18280. var _this = this;
  18281. url = URL.formatURL(url);
  18282. var onLoaded;
  18283. var onError = function () {
  18284. _this.event(Event.ERROR, "Load image failed");
  18285. };
  18286. if (this._type === "nativeimage") {
  18287. onLoaded = function (image) {
  18288. _this.onLoaded(image);
  18289. };
  18290. this._loadHtmlImage(url, this, onLoaded, this, onError);
  18291. }
  18292. else {
  18293. var ext = Utils.getFileExtension(url);
  18294. if (ext === "ktx" || ext === "pvr") {
  18295. onLoaded = function (imageData) {
  18296. var format;
  18297. switch (ext) {
  18298. case "ktx":
  18299. format = 5;
  18300. break;
  18301. case "pvr":
  18302. format = 12;
  18303. break;
  18304. }
  18305. var tex = new Texture2D(0, 0, format, false, false);
  18306. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  18307. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  18308. tex.setCompressData(imageData);
  18309. tex._setCreateURL(url);
  18310. _this.onLoaded(tex);
  18311. };
  18312. this._loadHttpRequest(url, Loader.BUFFER, this, onLoaded, null, null, this, onError);
  18313. }
  18314. else {
  18315. onLoaded = function (image) {
  18316. var tex = new Texture2D(image.width, image.height, 1, false, false);
  18317. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  18318. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  18319. tex.loadImageSource(image, true);
  18320. tex._setCreateURL(url);
  18321. _this.onLoaded(tex);
  18322. };
  18323. this._loadHtmlImage(url, this, onLoaded, this, onError);
  18324. }
  18325. }
  18326. }
  18327. _loadSound(url) {
  18328. var sound = (new SoundManager._soundClass());
  18329. var _this = this;
  18330. sound.on(Event.COMPLETE, this, soundOnload);
  18331. sound.on(Event.ERROR, this, soundOnErr);
  18332. sound.load(url);
  18333. function soundOnload() {
  18334. clear();
  18335. _this.onLoaded(sound);
  18336. }
  18337. function soundOnErr() {
  18338. clear();
  18339. sound.dispose();
  18340. _this.event(Event.ERROR, "Load sound failed");
  18341. }
  18342. function clear() {
  18343. sound.offAll();
  18344. }
  18345. }
  18346. onProgress(value) {
  18347. if (this._type === Loader.ATLAS)
  18348. this.event(Event.PROGRESS, value * 0.3);
  18349. else
  18350. this.event(Event.PROGRESS, value);
  18351. }
  18352. onError(message) {
  18353. this.event(Event.ERROR, message);
  18354. }
  18355. onLoaded(data = null) {
  18356. var type = this._type;
  18357. if (type == Loader.PLFB) {
  18358. this.parsePLFBData(data);
  18359. this.complete(data);
  18360. }
  18361. else if (type == Loader.PLF) {
  18362. this.parsePLFData(data);
  18363. this.complete(data);
  18364. }
  18365. else if (type === Loader.IMAGE) {
  18366. var tex = new Texture(data);
  18367. tex.url = this._url;
  18368. this.complete(tex);
  18369. }
  18370. else if (type === Loader.SOUND || type === "htmlimage" || type === "nativeimage") {
  18371. this.complete(data);
  18372. }
  18373. else if (type === Loader.ATLAS) {
  18374. if (!(data instanceof Texture2D)) {
  18375. if (!this._data) {
  18376. this._data = data;
  18377. if (data.meta && data.meta.image) {
  18378. var toloadPics = data.meta.image.split(",");
  18379. var split = this._url.indexOf("/") >= 0 ? "/" : "\\";
  18380. var idx = this._url.lastIndexOf(split);
  18381. var folderPath = idx >= 0 ? this._url.substr(0, idx + 1) : "";
  18382. var changeType;
  18383. if (Browser.onAndroid && data.meta.compressTextureAndroid) {
  18384. changeType = ".ktx";
  18385. }
  18386. if (Browser.onIOS && data.meta.compressTextureIOS) {
  18387. changeType = ".pvr";
  18388. }
  18389. for (var i = 0, len = toloadPics.length; i < len; i++) {
  18390. if (changeType) {
  18391. toloadPics[i] = folderPath + toloadPics[i].replace(".png", changeType);
  18392. }
  18393. else {
  18394. toloadPics[i] = folderPath + toloadPics[i];
  18395. }
  18396. }
  18397. }
  18398. else {
  18399. toloadPics = [this._url.replace(".json", ".png")];
  18400. }
  18401. toloadPics.reverse();
  18402. data.toLoads = toloadPics;
  18403. data.pics = [];
  18404. }
  18405. this.event(Event.PROGRESS, 0.3 + 1 / toloadPics.length * 0.6);
  18406. return this._loadResourceFilter(Loader.IMAGE, toloadPics.pop());
  18407. }
  18408. else {
  18409. this._data.pics.push(data);
  18410. if (this._data.toLoads.length > 0) {
  18411. this.event(Event.PROGRESS, 0.3 + 1 / this._data.toLoads.length * 0.6);
  18412. return this._loadResourceFilter(Loader.IMAGE, this._data.toLoads.pop());
  18413. }
  18414. var frames = this._data.frames;
  18415. var cleanUrl = this._url.split("?")[0];
  18416. var directory = (this._data.meta && this._data.meta.prefix) ? this._data.meta.prefix : cleanUrl.substring(0, cleanUrl.lastIndexOf(".")) + "/";
  18417. var pics = this._data.pics;
  18418. var atlasURL = URL.formatURL(this._url);
  18419. var map = Loader.atlasMap[atlasURL] || (Loader.atlasMap[atlasURL] = []);
  18420. map.dir = directory;
  18421. var scaleRate = 1;
  18422. if (this._data.meta && this._data.meta.scale && this._data.meta.scale != 1) {
  18423. scaleRate = parseFloat(this._data.meta.scale);
  18424. for (var name in frames) {
  18425. var obj = frames[name];
  18426. var tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18427. var url = URL.formatURL(directory + name);
  18428. tPic.scaleRate = scaleRate;
  18429. var tTexture;
  18430. 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));
  18431. Loader.cacheRes(url, tTexture);
  18432. tTexture.url = url;
  18433. map.push(url);
  18434. }
  18435. }
  18436. else {
  18437. for (name in frames) {
  18438. obj = frames[name];
  18439. tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
  18440. url = URL.formatURL(directory + name);
  18441. 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));
  18442. Loader.cacheRes(url, tTexture);
  18443. tTexture.url = url;
  18444. map.push(url);
  18445. }
  18446. }
  18447. delete this._data.pics;
  18448. this.complete(this._data);
  18449. }
  18450. }
  18451. else if (type === Loader.FONT) {
  18452. if (!data._source) {
  18453. this._data = data;
  18454. this.event(Event.PROGRESS, 0.5);
  18455. return this._loadImage(this._url.replace(".fnt", ".png"));
  18456. }
  18457. else {
  18458. var bFont = new BitmapFont();
  18459. bFont.parseFont(this._data, new Texture(data));
  18460. var tArr = this._url.split(".fnt")[0].split("/");
  18461. var fontName = tArr[tArr.length - 1];
  18462. Text.registerBitmapFont(fontName, bFont);
  18463. this._data = bFont;
  18464. this.complete(this._data);
  18465. }
  18466. }
  18467. else if (type === Loader.PREFAB) {
  18468. var prefab = new Prefab();
  18469. prefab.json = data;
  18470. this.complete(prefab);
  18471. }
  18472. else {
  18473. this.complete(data);
  18474. }
  18475. }
  18476. parsePLFData(plfData) {
  18477. var type;
  18478. var filePath;
  18479. var fileDic;
  18480. for (type in plfData) {
  18481. fileDic = plfData[type];
  18482. switch (type) {
  18483. case "json":
  18484. case "text":
  18485. for (filePath in fileDic) {
  18486. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18487. }
  18488. break;
  18489. default:
  18490. for (filePath in fileDic) {
  18491. Loader.preLoadedMap[URL.formatURL(filePath)] = fileDic[filePath];
  18492. }
  18493. }
  18494. }
  18495. }
  18496. parsePLFBData(plfData) {
  18497. var byte;
  18498. byte = new Byte(plfData);
  18499. var i, len;
  18500. len = byte.getInt32();
  18501. for (i = 0; i < len; i++) {
  18502. this.parseOnePLFBFile(byte);
  18503. }
  18504. }
  18505. parseOnePLFBFile(byte) {
  18506. var fileLen;
  18507. var fileName;
  18508. var fileData;
  18509. fileName = byte.getUTFString();
  18510. fileLen = byte.getInt32();
  18511. fileData = byte.readArrayBuffer(fileLen);
  18512. Loader.preLoadedMap[URL.formatURL(fileName)] = fileData;
  18513. }
  18514. complete(data) {
  18515. this._data = data;
  18516. if (this._customParse) {
  18517. this.event(Event.LOADED, data instanceof Array ? [data] : data);
  18518. }
  18519. else {
  18520. Loader._loaders.push(this);
  18521. if (!Loader._isWorking)
  18522. Loader.checkNext();
  18523. }
  18524. }
  18525. static checkNext() {
  18526. Loader._isWorking = true;
  18527. var startTimer = Browser.now();
  18528. var thisTimer = startTimer;
  18529. while (Loader._startIndex < Loader._loaders.length) {
  18530. thisTimer = Browser.now();
  18531. Loader._loaders[Loader._startIndex].endLoad();
  18532. Loader._startIndex++;
  18533. if (Browser.now() - startTimer > Loader.maxTimeOut) {
  18534. console.warn("loader callback cost a long time:" + (Browser.now() - startTimer) + " url=" + Loader._loaders[Loader._startIndex - 1].url);
  18535. ILaya.systemTimer.frameOnce(1, null, Loader.checkNext);
  18536. return;
  18537. }
  18538. }
  18539. Loader._loaders.length = 0;
  18540. Loader._startIndex = 0;
  18541. Loader._isWorking = false;
  18542. }
  18543. endLoad(content = null) {
  18544. content && (this._data = content);
  18545. if (this._cache)
  18546. Loader.cacheRes(this._url, this._data);
  18547. this.event(Event.PROGRESS, 1);
  18548. this.event(Event.COMPLETE, this.data instanceof Array ? [this.data] : this.data);
  18549. }
  18550. get url() {
  18551. return this._url;
  18552. }
  18553. get type() {
  18554. return this._type;
  18555. }
  18556. get cache() {
  18557. return this._cache;
  18558. }
  18559. get data() {
  18560. return this._data;
  18561. }
  18562. static clearRes(url) {
  18563. url = URL.formatURL(url);
  18564. var arr = Loader.getAtlas(url);
  18565. if (arr) {
  18566. for (var i = 0, n = arr.length; i < n; i++) {
  18567. var resUrl = arr[i];
  18568. var tex = Loader.getRes(resUrl);
  18569. delete Loader.loadedMap[resUrl];
  18570. if (tex)
  18571. tex.destroy();
  18572. }
  18573. arr.length = 0;
  18574. delete Loader.atlasMap[url];
  18575. delete Loader.loadedMap[url];
  18576. }
  18577. else {
  18578. var res = Loader.loadedMap[url];
  18579. if (res) {
  18580. delete Loader.loadedMap[url];
  18581. if (res instanceof Texture && res.bitmap)
  18582. res.destroy();
  18583. }
  18584. }
  18585. }
  18586. static clearTextureRes(url) {
  18587. url = URL.formatURL(url);
  18588. var arr = Loader.getAtlas(url);
  18589. if (arr && arr.length > 0) {
  18590. arr.forEach(function (t) {
  18591. var tex = Loader.getRes(t);
  18592. if (tex instanceof Texture) {
  18593. tex.disposeBitmap();
  18594. }
  18595. });
  18596. }
  18597. else {
  18598. var t = Loader.getRes(url);
  18599. if (t instanceof Texture) {
  18600. t.disposeBitmap();
  18601. }
  18602. }
  18603. }
  18604. static getRes(url) {
  18605. return Loader.loadedMap[URL.formatURL(url)];
  18606. }
  18607. static getAtlas(url) {
  18608. return Loader.atlasMap[URL.formatURL(url)];
  18609. }
  18610. static cacheRes(url, data) {
  18611. url = URL.formatURL(url);
  18612. if (Loader.loadedMap[url] != null) {
  18613. // console.warn("Resources already exist,is repeated loading:", url);
  18614. }
  18615. else {
  18616. Loader.loadedMap[url] = data;
  18617. }
  18618. }
  18619. static setGroup(url, group) {
  18620. if (!Loader.groupMap[group])
  18621. Loader.groupMap[group] = [];
  18622. Loader.groupMap[group].push(url);
  18623. }
  18624. static clearResByGroup(group) {
  18625. if (!Loader.groupMap[group])
  18626. return;
  18627. var arr = Loader.groupMap[group], i, len = arr.length;
  18628. for (i = 0; i < len; i++) {
  18629. Loader.clearRes(arr[i]);
  18630. }
  18631. arr.length = 0;
  18632. }
  18633. }
  18634. Loader.TEXT = "text";
  18635. Loader.JSON = "json";
  18636. Loader.PREFAB = "prefab";
  18637. Loader.XML = "xml";
  18638. Loader.BUFFER = "arraybuffer";
  18639. Loader.IMAGE = "image";
  18640. Loader.SOUND = "sound";
  18641. Loader.ATLAS = "atlas";
  18642. Loader.FONT = "font";
  18643. Loader.TTF = "ttf";
  18644. Loader.PLF = "plf";
  18645. Loader.PLFB = "plfb";
  18646. Loader.HIERARCHY = "HIERARCHY";
  18647. Loader.MESH = "MESH";
  18648. Loader.MATERIAL = "MATERIAL";
  18649. Loader.TEXTURE2D = "TEXTURE2D";
  18650. Loader.TEXTURECUBE = "TEXTURECUBE";
  18651. Loader.ANIMATIONCLIP = "ANIMATIONCLIP";
  18652. Loader.AVATAR = "AVATAR";
  18653. Loader.TERRAINHEIGHTDATA = "TERRAINHEIGHTDATA";
  18654. Loader.TERRAINRES = "TERRAIN";
  18655. 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" };
  18656. Loader.parserMap = {};
  18657. Loader.maxTimeOut = 100;
  18658. Loader.groupMap = {};
  18659. Loader.loadedMap = {};
  18660. Loader.atlasMap = {};
  18661. Loader.preLoadedMap = {};
  18662. Loader._imgCache = {};
  18663. Loader._loaders = [];
  18664. Loader._isWorking = false;
  18665. Loader._startIndex = 0;
  18666. class AtlasInfoManager {
  18667. static enable(infoFile, callback = null) {
  18668. ILaya.loader.load(infoFile, Handler.create(null, AtlasInfoManager._onInfoLoaded, [callback]), null, Loader.JSON);
  18669. }
  18670. static _onInfoLoaded(callback, data) {
  18671. var tKey;
  18672. var tPrefix;
  18673. var tArr;
  18674. var i, len;
  18675. for (tKey in data) {
  18676. tArr = data[tKey];
  18677. tPrefix = tArr[0];
  18678. tArr = tArr[1];
  18679. len = tArr.length;
  18680. for (i = 0; i < len; i++) {
  18681. AtlasInfoManager._fileLoadDic[tPrefix + tArr[i]] = tKey;
  18682. }
  18683. }
  18684. callback && callback.run();
  18685. }
  18686. static getFileLoadPath(file) {
  18687. return AtlasInfoManager._fileLoadDic[file] || file;
  18688. }
  18689. }
  18690. AtlasInfoManager._fileLoadDic = {};
  18691. class LoaderManager extends EventDispatcher {
  18692. constructor() {
  18693. super();
  18694. this.retryNum = 1;
  18695. this.retryDelay = 0;
  18696. this.maxLoader = 5;
  18697. this._loaders = [];
  18698. this._loaderCount = 0;
  18699. this._resInfos = [];
  18700. this._infoPool = [];
  18701. this._maxPriority = 5;
  18702. this._failRes = {};
  18703. this._statInfo = { count: 1, loaded: 1 };
  18704. for (var i = 0; i < this._maxPriority; i++)
  18705. this._resInfos[i] = [];
  18706. }
  18707. getProgress() {
  18708. return this._statInfo.loaded / this._statInfo.count;
  18709. }
  18710. resetProgress() {
  18711. this._statInfo.count = this._statInfo.loaded = 1;
  18712. }
  18713. create(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18714. this._create(url, true, complete, progress, type, constructParams, propertyParams, priority, cache);
  18715. }
  18716. _create(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18717. if (url instanceof Array) {
  18718. var allScuess = true;
  18719. var items = url;
  18720. var itemCount = items.length;
  18721. var loadedCount = 0;
  18722. if (progress) {
  18723. var progress2 = Handler.create(progress.caller, progress.method, progress.args, false);
  18724. }
  18725. for (var i = 0; i < itemCount; i++) {
  18726. var item = items[i];
  18727. if (typeof (item) == 'string')
  18728. item = items[i] = { url: item };
  18729. item.progress = 0;
  18730. }
  18731. for (i = 0; i < itemCount; i++) {
  18732. item = items[i];
  18733. var progressHandler = progress ? Handler.create(null, function (item, value) {
  18734. item.progress = value;
  18735. var num = 0;
  18736. for (var j = 0; j < itemCount; j++) {
  18737. var item1 = items[j];
  18738. num += item1.progress;
  18739. }
  18740. var v = num / itemCount;
  18741. progress2.runWith(v);
  18742. }, [item], false) : null;
  18743. var completeHandler = (progress || complete) ? Handler.create(null, function (item, content = null) {
  18744. loadedCount++;
  18745. item.progress = 1;
  18746. content || (allScuess = false);
  18747. if (loadedCount === itemCount && complete) {
  18748. complete.runWith(allScuess);
  18749. }
  18750. }, [item]) : null;
  18751. this._createOne(item.url, mainResou, completeHandler, progressHandler, item.type || type, item.constructParams || constructParams, item.propertyParams || propertyParams, item.priority || priority, cache);
  18752. }
  18753. }
  18754. else {
  18755. this._createOne(url, mainResou, complete, progress, type, constructParams, propertyParams, priority, cache);
  18756. }
  18757. }
  18758. _createOne(url, mainResou, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true) {
  18759. var item = this.getRes(url);
  18760. if (!item) {
  18761. var extension = Utils.getFileExtension(url);
  18762. (type) || (type = LoaderManager.createMap[extension] ? LoaderManager.createMap[extension][0] : null);
  18763. if (!type) {
  18764. this.load(url, complete, progress, type, priority, cache);
  18765. return;
  18766. }
  18767. var parserMap = Loader.parserMap;
  18768. if (!parserMap[type]) {
  18769. this.load(url, complete, progress, type, priority, cache);
  18770. return;
  18771. }
  18772. this._createLoad(url, Handler.create(null, function (createRes) {
  18773. if (createRes) {
  18774. if (!mainResou && createRes instanceof Resource)
  18775. createRes._addReference();
  18776. createRes._setCreateURL(url);
  18777. }
  18778. complete && complete.runWith(createRes);
  18779. ILaya.loader.event(url);
  18780. }), progress, type, constructParams, propertyParams, priority, cache, true);
  18781. }
  18782. else {
  18783. if (!mainResou && item instanceof Resource)
  18784. item._addReference();
  18785. progress && progress.runWith(1);
  18786. complete && complete.runWith(item);
  18787. }
  18788. }
  18789. load(url, complete = null, progress = null, type = null, priority = 1, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
  18790. if (url instanceof Array)
  18791. return this._loadAssets(url, complete, progress, type, priority, cache, group);
  18792. var content = Loader.getRes(url);
  18793. if (!ignoreCache && content != null) {
  18794. ILaya.systemTimer.frameOnce(1, this, function () {
  18795. progress && progress.runWith(1);
  18796. complete && complete.runWith(content instanceof Array ? [content] : content);
  18797. this._loaderCount || this.event(Event.COMPLETE);
  18798. });
  18799. }
  18800. else {
  18801. var original;
  18802. original = url;
  18803. url = AtlasInfoManager.getFileLoadPath(url);
  18804. if (url != original && type !== "nativeimage") {
  18805. type = Loader.ATLAS;
  18806. }
  18807. else {
  18808. original = null;
  18809. }
  18810. var info = LoaderManager._resMap[url];
  18811. if (!info) {
  18812. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  18813. info.url = url;
  18814. info.type = type;
  18815. info.cache = cache;
  18816. info.group = group;
  18817. info.ignoreCache = ignoreCache;
  18818. info.useWorkerLoader = useWorkerLoader;
  18819. info.originalUrl = original;
  18820. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  18821. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  18822. LoaderManager._resMap[url] = info;
  18823. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  18824. this._resInfos[priority].push(info);
  18825. this._statInfo.count++;
  18826. this.event(Event.PROGRESS, this.getProgress());
  18827. this._next();
  18828. }
  18829. else {
  18830. if (complete) {
  18831. if (original) {
  18832. complete && info._createListener(Event.COMPLETE, this, this._resInfoLoaded, [original, complete], false, false);
  18833. }
  18834. else {
  18835. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  18836. }
  18837. }
  18838. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  18839. }
  18840. }
  18841. return this;
  18842. }
  18843. _resInfoLoaded(original, complete) {
  18844. complete.runWith(Loader.getRes(original));
  18845. }
  18846. _createLoad(url, complete = null, progress = null, type = null, constructParams = null, propertyParams = null, priority = 1, cache = true, ignoreCache = false) {
  18847. if (url instanceof Array)
  18848. return this._loadAssets(url, complete, progress, type, priority, cache);
  18849. var content = Loader.getRes(url);
  18850. if (content != null) {
  18851. ILaya.systemTimer.frameOnce(1, this, function () {
  18852. progress && progress.runWith(1);
  18853. complete && complete.runWith(content);
  18854. this._loaderCount || this.event(Event.COMPLETE);
  18855. });
  18856. }
  18857. else {
  18858. var info = LoaderManager._resMap[url];
  18859. if (!info) {
  18860. info = this._infoPool.length ? this._infoPool.pop() : new ResInfo();
  18861. info.url = url;
  18862. info.type = type;
  18863. info.cache = false;
  18864. info.ignoreCache = ignoreCache;
  18865. info.originalUrl = null;
  18866. info.group = null;
  18867. info.createCache = cache;
  18868. info.createConstructParams = constructParams;
  18869. info.createPropertyParams = propertyParams;
  18870. complete && info.on(Event.COMPLETE, complete.caller, complete.method, complete.args);
  18871. progress && info.on(Event.PROGRESS, progress.caller, progress.method, progress.args);
  18872. LoaderManager._resMap[url] = info;
  18873. priority = priority < this._maxPriority ? priority : this._maxPriority - 1;
  18874. this._resInfos[priority].push(info);
  18875. this._statInfo.count++;
  18876. this.event(Event.PROGRESS, this.getProgress());
  18877. this._next();
  18878. }
  18879. else {
  18880. complete && info._createListener(Event.COMPLETE, complete.caller, complete.method, complete.args, false, false);
  18881. progress && info._createListener(Event.PROGRESS, progress.caller, progress.method, progress.args, false, false);
  18882. }
  18883. }
  18884. return this;
  18885. }
  18886. _next() {
  18887. if (this._loaderCount >= this.maxLoader)
  18888. return;
  18889. for (var i = 0; i < this._maxPriority; i++) {
  18890. var infos = this._resInfos[i];
  18891. while (infos.length > 0) {
  18892. var info = infos.shift();
  18893. if (info)
  18894. return this._doLoad(info);
  18895. }
  18896. }
  18897. this._loaderCount || this.event(Event.COMPLETE);
  18898. }
  18899. _doLoad(resInfo) {
  18900. this._loaderCount++;
  18901. var loader = this._loaders.length ? this._loaders.pop() : new Loader();
  18902. loader.on(Event.COMPLETE, null, onLoaded);
  18903. loader.on(Event.PROGRESS, null, function (num) {
  18904. resInfo.event(Event.PROGRESS, num);
  18905. });
  18906. loader.on(Event.ERROR, null, function (msg) {
  18907. onLoaded(null);
  18908. });
  18909. var _me = this;
  18910. function onLoaded(data = null) {
  18911. loader.offAll();
  18912. loader._data = null;
  18913. loader._customParse = false;
  18914. _me._loaders.push(loader);
  18915. _me._endLoad(resInfo, data instanceof Array ? [data] : data);
  18916. _me._loaderCount--;
  18917. _me._next();
  18918. }
  18919. loader._constructParams = resInfo.createConstructParams;
  18920. loader._propertyParams = resInfo.createPropertyParams;
  18921. loader._createCache = resInfo.createCache;
  18922. loader.load(resInfo.url, resInfo.type, resInfo.cache, resInfo.group, resInfo.ignoreCache, resInfo.useWorkerLoader);
  18923. }
  18924. _endLoad(resInfo, content) {
  18925. var url = resInfo.url;
  18926. if (content == null) {
  18927. var errorCount = this._failRes[url] || 0;
  18928. if (errorCount < this.retryNum) {
  18929. console.warn("[warn]Retry to load:", url);
  18930. this._failRes[url] = errorCount + 1;
  18931. ILaya.systemTimer.once(this.retryDelay, this, this._addReTry, [resInfo], false);
  18932. return;
  18933. }
  18934. else {
  18935. Loader.clearRes(url);
  18936. console.warn("[error]Failed to load:", url);
  18937. this.event(Event.ERROR, url);
  18938. }
  18939. }
  18940. if (this._failRes[url])
  18941. this._failRes[url] = 0;
  18942. delete LoaderManager._resMap[url];
  18943. if (resInfo.originalUrl) {
  18944. content = Loader.getRes(resInfo.originalUrl);
  18945. }
  18946. resInfo.event(Event.COMPLETE, content);
  18947. resInfo.offAll();
  18948. this._infoPool.push(resInfo);
  18949. this._statInfo.loaded++;
  18950. this.event(Event.PROGRESS, this.getProgress());
  18951. }
  18952. _addReTry(resInfo) {
  18953. this._resInfos[this._maxPriority - 1].push(resInfo);
  18954. this._next();
  18955. }
  18956. clearRes(url) {
  18957. Loader.clearRes(url);
  18958. }
  18959. clearTextureRes(url) {
  18960. Loader.clearTextureRes(url);
  18961. }
  18962. getRes(url) {
  18963. return Loader.getRes(url);
  18964. }
  18965. cacheRes(url, data) {
  18966. Loader.cacheRes(url, data);
  18967. }
  18968. setGroup(url, group) {
  18969. Loader.setGroup(url, group);
  18970. }
  18971. clearResByGroup(group) {
  18972. Loader.clearResByGroup(group);
  18973. }
  18974. static cacheRes(url, data) {
  18975. Loader.cacheRes(url, data);
  18976. }
  18977. clearUnLoaded() {
  18978. for (var i = 0; i < this._maxPriority; i++) {
  18979. var infos = this._resInfos[i];
  18980. for (var j = infos.length - 1; j > -1; j--) {
  18981. var info = infos[j];
  18982. if (info) {
  18983. info.offAll();
  18984. this._infoPool.push(info);
  18985. }
  18986. }
  18987. infos.length = 0;
  18988. }
  18989. this._loaderCount = 0;
  18990. LoaderManager._resMap = {};
  18991. }
  18992. cancelLoadByUrls(urls) {
  18993. if (!urls)
  18994. return;
  18995. for (var i = 0, n = urls.length; i < n; i++) {
  18996. this.cancelLoadByUrl(urls[i]);
  18997. }
  18998. }
  18999. cancelLoadByUrl(url) {
  19000. for (var i = 0; i < this._maxPriority; i++) {
  19001. var infos = this._resInfos[i];
  19002. for (var j = infos.length - 1; j > -1; j--) {
  19003. var info = infos[j];
  19004. if (info && info.url === url) {
  19005. infos[j] = null;
  19006. info.offAll();
  19007. this._infoPool.push(info);
  19008. }
  19009. }
  19010. }
  19011. if (LoaderManager._resMap[url])
  19012. delete LoaderManager._resMap[url];
  19013. }
  19014. _loadAssets(arr, complete = null, progress = null, type = null, priority = 1, cache = true, group = null) {
  19015. var itemCount = arr.length;
  19016. var loadedCount = 0;
  19017. var totalSize = 0;
  19018. var items = [];
  19019. var success = true;
  19020. for (var i = 0; i < itemCount; i++) {
  19021. var item = arr[i];
  19022. if (typeof (item) == 'string')
  19023. item = { url: item, type: type, size: 1, priority: priority };
  19024. if (!item.size)
  19025. item.size = 1;
  19026. item.progress = 0;
  19027. totalSize += item.size;
  19028. items.push(item);
  19029. var progressHandler = progress ? Handler.create(null, loadProgress, [item], false) : null;
  19030. var completeHandler = (complete || progress) ? Handler.create(null, loadComplete, [item]) : null;
  19031. this.load(item.url, completeHandler, progressHandler, item.type, item.priority || 1, cache, item.group || group, false, item.useWorkerLoader);
  19032. }
  19033. function loadComplete(item, content = null) {
  19034. loadedCount++;
  19035. item.progress = 1;
  19036. if (!content)
  19037. success = false;
  19038. if (loadedCount === itemCount && complete) {
  19039. complete.runWith(success);
  19040. }
  19041. }
  19042. function loadProgress(item, value) {
  19043. if (progress != null) {
  19044. item.progress = value;
  19045. var num = 0;
  19046. for (var j = 0; j < items.length; j++) {
  19047. var item1 = items[j];
  19048. num += item1.size * item1.progress;
  19049. }
  19050. var v = num / totalSize;
  19051. progress.runWith(v);
  19052. }
  19053. }
  19054. return this;
  19055. }
  19056. decodeBitmaps(urls) {
  19057. var i, len = urls.length;
  19058. var ctx;
  19059. ctx = ILaya.Render._context;
  19060. for (i = 0; i < len; i++) {
  19061. var atlas;
  19062. atlas = Loader.getAtlas(urls[i]);
  19063. if (atlas) {
  19064. this._decodeTexture(atlas[0], ctx);
  19065. }
  19066. else {
  19067. var tex;
  19068. tex = this.getRes(urls[i]);
  19069. if (tex && tex instanceof Texture) {
  19070. this._decodeTexture(tex, ctx);
  19071. }
  19072. }
  19073. }
  19074. }
  19075. _decodeTexture(tex, ctx) {
  19076. var bitmap = tex.bitmap;
  19077. if (!tex || !bitmap)
  19078. return;
  19079. var tImg = bitmap.source || bitmap.image;
  19080. if (!tImg)
  19081. return;
  19082. if (tImg instanceof HTMLImageElement) {
  19083. ctx.drawImage(tImg, 0, 0, 1, 1);
  19084. var info = ctx.getImageData(0, 0, 1, 1);
  19085. }
  19086. }
  19087. }
  19088. LoaderManager._resMap = {};
  19089. LoaderManager.createMap = { atlas: [null, Loader.ATLAS] };
  19090. class ResInfo extends EventDispatcher {
  19091. }
  19092. class LocalStorage {
  19093. static __init__() {
  19094. if (!LocalStorage._baseClass) {
  19095. LocalStorage._baseClass = Storage;
  19096. Storage.init();
  19097. }
  19098. LocalStorage.items = LocalStorage._baseClass.items;
  19099. LocalStorage.support = LocalStorage._baseClass.support;
  19100. return LocalStorage.support;
  19101. }
  19102. static setItem(key, value) {
  19103. LocalStorage._baseClass.setItem(key, value);
  19104. }
  19105. static getItem(key) {
  19106. return LocalStorage._baseClass.getItem(key);
  19107. }
  19108. static setJSON(key, value) {
  19109. LocalStorage._baseClass.setJSON(key, value);
  19110. }
  19111. static getJSON(key) {
  19112. return LocalStorage._baseClass.getJSON(key);
  19113. }
  19114. static removeItem(key) {
  19115. LocalStorage._baseClass.removeItem(key);
  19116. }
  19117. static clear() {
  19118. LocalStorage._baseClass.clear();
  19119. }
  19120. }
  19121. LocalStorage.support = false;
  19122. class Storage {
  19123. static init() {
  19124. try {
  19125. Storage.support = true;
  19126. Storage.items = window.localStorage;
  19127. Storage.setItem('laya', '1');
  19128. Storage.removeItem('laya');
  19129. }
  19130. catch (e) {
  19131. Storage.support = false;
  19132. }
  19133. if (!Storage.support)
  19134. console.log('LocalStorage is not supprot or browser is private mode.');
  19135. }
  19136. static setItem(key, value) {
  19137. try {
  19138. Storage.support && Storage.items.setItem(key, value);
  19139. }
  19140. catch (e) {
  19141. console.warn("set localStorage failed", e);
  19142. }
  19143. }
  19144. static getItem(key) {
  19145. return Storage.support ? Storage.items.getItem(key) : null;
  19146. }
  19147. static setJSON(key, value) {
  19148. try {
  19149. Storage.support && Storage.items.setItem(key, JSON.stringify(value));
  19150. }
  19151. catch (e) {
  19152. console.warn("set localStorage failed", e);
  19153. }
  19154. }
  19155. static getJSON(key) {
  19156. return JSON.parse(Storage.support ? Storage.items.getItem(key) : null);
  19157. }
  19158. static removeItem(key) {
  19159. Storage.support && Storage.items.removeItem(key);
  19160. }
  19161. static clear() {
  19162. Storage.support && Storage.items.clear();
  19163. }
  19164. }
  19165. Storage.support = false;
  19166. class TTFLoader {
  19167. load(fontPath) {
  19168. this._url = fontPath;
  19169. var tArr = fontPath.split(".ttf")[0].split("/");
  19170. this.fontName = tArr[tArr.length - 1];
  19171. if (ILaya.Render.isConchApp) {
  19172. this._loadConch();
  19173. }
  19174. else if (window.FontFace) {
  19175. this._loadWithFontFace();
  19176. }
  19177. else {
  19178. this._loadWithCSS();
  19179. }
  19180. }
  19181. _loadConch() {
  19182. this._http = new HttpRequest();
  19183. this._http.on(Event.ERROR, this, this._onErr);
  19184. this._http.on(Event.COMPLETE, this, this._onHttpLoaded);
  19185. this._http.send(this._url, null, "get", Loader.BUFFER);
  19186. }
  19187. _onHttpLoaded(data = null) {
  19188. window["conchTextCanvas"].setFontFaceFromBuffer(this.fontName, data);
  19189. this._clearHttp();
  19190. this._complete();
  19191. }
  19192. _clearHttp() {
  19193. if (this._http) {
  19194. this._http.off(Event.ERROR, this, this._onErr);
  19195. this._http.off(Event.COMPLETE, this, this._onHttpLoaded);
  19196. this._http = null;
  19197. }
  19198. }
  19199. _onErr() {
  19200. this._clearHttp();
  19201. if (this.err) {
  19202. this.err.runWith("fail:" + this._url);
  19203. this.err = null;
  19204. }
  19205. }
  19206. _complete() {
  19207. ILaya.systemTimer.clear(this, this._complete);
  19208. ILaya.systemTimer.clear(this, this._checkComplete);
  19209. if (this._div && this._div.parentNode) {
  19210. this._div.parentNode.removeChild(this._div);
  19211. this._div = null;
  19212. }
  19213. if (this.complete) {
  19214. this.complete.runWith(this);
  19215. this.complete = null;
  19216. }
  19217. }
  19218. _checkComplete() {
  19219. if (ILaya.Browser.measureText(TTFLoader._testString, this._fontTxt).width != this._txtWidth) {
  19220. this._complete();
  19221. }
  19222. }
  19223. _loadWithFontFace() {
  19224. var fontFace = new window.FontFace(this.fontName, "url('" + this._url + "')");
  19225. document.fonts.add(fontFace);
  19226. var self = this;
  19227. fontFace.loaded.then((function () {
  19228. self._complete();
  19229. }));
  19230. fontFace.load();
  19231. }
  19232. _createDiv() {
  19233. this._div = Browser.createElement("div");
  19234. this._div.innerHTML = "laya";
  19235. var _style = this._div.style;
  19236. _style.fontFamily = this.fontName;
  19237. _style.position = "absolute";
  19238. _style.left = "-100px";
  19239. _style.top = "-100px";
  19240. document.body.appendChild(this._div);
  19241. }
  19242. _loadWithCSS() {
  19243. var fontStyle = Browser.createElement("style");
  19244. fontStyle.type = "text/css";
  19245. document.body.appendChild(fontStyle);
  19246. fontStyle.textContent = "@font-face { font-family:'" + this.fontName + "'; src:url('" + this._url + "');}";
  19247. this._fontTxt = "40px " + this.fontName;
  19248. this._txtWidth = Browser.measureText(TTFLoader._testString, this._fontTxt).width;
  19249. var self = this;
  19250. fontStyle.onload = function () {
  19251. ILaya.systemTimer.once(10000, self, this._complete);
  19252. };
  19253. ILaya.systemTimer.loop(20, this, this._checkComplete);
  19254. this._createDiv();
  19255. }
  19256. }
  19257. TTFLoader._testString = "LayaTTFFont";
  19258. class Ease {
  19259. static linearNone(t, b, c, d) {
  19260. return c * t / d + b;
  19261. }
  19262. static linearIn(t, b, c, d) {
  19263. return c * t / d + b;
  19264. }
  19265. static linearInOut(t, b, c, d) {
  19266. return c * t / d + b;
  19267. }
  19268. static linearOut(t, b, c, d) {
  19269. return c * t / d + b;
  19270. }
  19271. static bounceIn(t, b, c, d) {
  19272. return c - Ease.bounceOut(d - t, 0, c, d) + b;
  19273. }
  19274. static bounceInOut(t, b, c, d) {
  19275. if (t < d * 0.5)
  19276. return Ease.bounceIn(t * 2, 0, c, d) * .5 + b;
  19277. else
  19278. return Ease.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  19279. }
  19280. static bounceOut(t, b, c, d) {
  19281. if ((t /= d) < (1 / 2.75))
  19282. return c * (7.5625 * t * t) + b;
  19283. else if (t < (2 / 2.75))
  19284. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  19285. else if (t < (2.5 / 2.75))
  19286. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  19287. else
  19288. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  19289. }
  19290. static backIn(t, b, c, d, s = 1.70158) {
  19291. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  19292. }
  19293. static backInOut(t, b, c, d, s = 1.70158) {
  19294. if ((t /= d * 0.5) < 1)
  19295. return c * 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  19296. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  19297. }
  19298. static backOut(t, b, c, d, s = 1.70158) {
  19299. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  19300. }
  19301. static elasticIn(t, b, c, d, a = 0, p = 0) {
  19302. var s;
  19303. if (t == 0)
  19304. return b;
  19305. if ((t /= d) == 1)
  19306. return b + c;
  19307. if (!p)
  19308. p = d * .3;
  19309. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19310. a = c;
  19311. s = p / 4;
  19312. }
  19313. else
  19314. s = p / Ease.PI2 * Math.asin(c / a);
  19315. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19316. }
  19317. static elasticInOut(t, b, c, d, a = 0, p = 0) {
  19318. var s;
  19319. if (t == 0)
  19320. return b;
  19321. if ((t /= d * 0.5) == 2)
  19322. return b + c;
  19323. if (!p)
  19324. p = d * (.3 * 1.5);
  19325. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19326. a = c;
  19327. s = p / 4;
  19328. }
  19329. else
  19330. s = p / Ease.PI2 * Math.asin(c / a);
  19331. if (t < 1)
  19332. return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p)) + b;
  19333. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * Ease.PI2 / p) * .5 + c + b;
  19334. }
  19335. static elasticOut(t, b, c, d, a = 0, p = 0) {
  19336. var s;
  19337. if (t == 0)
  19338. return b;
  19339. if ((t /= d) == 1)
  19340. return b + c;
  19341. if (!p)
  19342. p = d * .3;
  19343. if (!a || (c > 0 && a < c) || (c < 0 && a < -c)) {
  19344. a = c;
  19345. s = p / 4;
  19346. }
  19347. else
  19348. s = p / Ease.PI2 * Math.asin(c / a);
  19349. return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * Ease.PI2 / p) + c + b);
  19350. }
  19351. static strongIn(t, b, c, d) {
  19352. return c * (t /= d) * t * t * t * t + b;
  19353. }
  19354. static strongInOut(t, b, c, d) {
  19355. if ((t /= d * 0.5) < 1)
  19356. return c * 0.5 * t * t * t * t * t + b;
  19357. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19358. }
  19359. static strongOut(t, b, c, d) {
  19360. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19361. }
  19362. static sineInOut(t, b, c, d) {
  19363. return -c * 0.5 * (Math.cos(Math.PI * t / d) - 1) + b;
  19364. }
  19365. static sineIn(t, b, c, d) {
  19366. return -c * Math.cos(t / d * Ease.HALF_PI) + c + b;
  19367. }
  19368. static sineOut(t, b, c, d) {
  19369. return c * Math.sin(t / d * Ease.HALF_PI) + b;
  19370. }
  19371. static quintIn(t, b, c, d) {
  19372. return c * (t /= d) * t * t * t * t + b;
  19373. }
  19374. static quintInOut(t, b, c, d) {
  19375. if ((t /= d * 0.5) < 1)
  19376. return c * 0.5 * t * t * t * t * t + b;
  19377. return c * 0.5 * ((t -= 2) * t * t * t * t + 2) + b;
  19378. }
  19379. static quintOut(t, b, c, d) {
  19380. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  19381. }
  19382. static quartIn(t, b, c, d) {
  19383. return c * (t /= d) * t * t * t + b;
  19384. }
  19385. static quartInOut(t, b, c, d) {
  19386. if ((t /= d * 0.5) < 1)
  19387. return c * 0.5 * t * t * t * t + b;
  19388. return -c * 0.5 * ((t -= 2) * t * t * t - 2) + b;
  19389. }
  19390. static quartOut(t, b, c, d) {
  19391. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  19392. }
  19393. static cubicIn(t, b, c, d) {
  19394. return c * (t /= d) * t * t + b;
  19395. }
  19396. static cubicInOut(t, b, c, d) {
  19397. if ((t /= d * 0.5) < 1)
  19398. return c * 0.5 * t * t * t + b;
  19399. return c * 0.5 * ((t -= 2) * t * t + 2) + b;
  19400. }
  19401. static cubicOut(t, b, c, d) {
  19402. return c * ((t = t / d - 1) * t * t + 1) + b;
  19403. }
  19404. static quadIn(t, b, c, d) {
  19405. return c * (t /= d) * t + b;
  19406. }
  19407. static quadInOut(t, b, c, d) {
  19408. if ((t /= d * 0.5) < 1)
  19409. return c * 0.5 * t * t + b;
  19410. return -c * 0.5 * ((--t) * (t - 2) - 1) + b;
  19411. }
  19412. static quadOut(t, b, c, d) {
  19413. return -c * (t /= d) * (t - 2) + b;
  19414. }
  19415. static expoIn(t, b, c, d) {
  19416. return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b - c * 0.001;
  19417. }
  19418. static expoInOut(t, b, c, d) {
  19419. if (t == 0)
  19420. return b;
  19421. if (t == d)
  19422. return b + c;
  19423. if ((t /= d * 0.5) < 1)
  19424. return c * 0.5 * Math.pow(2, 10 * (t - 1)) + b;
  19425. return c * 0.5 * (-Math.pow(2, -10 * --t) + 2) + b;
  19426. }
  19427. static expoOut(t, b, c, d) {
  19428. return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  19429. }
  19430. static circIn(t, b, c, d) {
  19431. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  19432. }
  19433. static circInOut(t, b, c, d) {
  19434. if ((t /= d * 0.5) < 1)
  19435. return -c * 0.5 * (Math.sqrt(1 - t * t) - 1) + b;
  19436. return c * 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  19437. }
  19438. static circOut(t, b, c, d) {
  19439. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  19440. }
  19441. }
  19442. Ease.HALF_PI = Math.PI * 0.5;
  19443. Ease.PI2 = Math.PI * 2;
  19444. class Tween {
  19445. constructor() {
  19446. this.gid = 0;
  19447. this.repeat = 1;
  19448. this._count = 0;
  19449. }
  19450. static to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19451. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, true, autoRecover, true);
  19452. }
  19453. static from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false, autoRecover = true) {
  19454. return Pool.getItemByClass("tween", Tween)._create(target, props, duration, ease, complete, delay, coverBefore, false, autoRecover, true);
  19455. }
  19456. to(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19457. return this._create(target, props, duration, ease, complete, delay, coverBefore, true, false, true);
  19458. }
  19459. from(target, props, duration, ease = null, complete = null, delay = 0, coverBefore = false) {
  19460. return this._create(target, props, duration, ease, complete, delay, coverBefore, false, false, true);
  19461. }
  19462. _create(target, props, duration, ease, complete, delay, coverBefore, isTo, usePool, runNow) {
  19463. if (!target)
  19464. throw new Error("Tween:target is null");
  19465. this._target = target;
  19466. this._duration = duration;
  19467. this._ease = ease || props.ease || Tween.easeNone;
  19468. this._complete = complete || props.complete;
  19469. this._delay = delay;
  19470. this._props = [];
  19471. this._usedTimer = 0;
  19472. this._startTimer = Browser.now();
  19473. this._usedPool = usePool;
  19474. this._delayParam = null;
  19475. this.update = props.update;
  19476. var gid = (target.$_GID || (target.$_GID = Utils.getGID()));
  19477. if (!Tween.tweenMap[gid]) {
  19478. Tween.tweenMap[gid] = [this];
  19479. }
  19480. else {
  19481. if (coverBefore)
  19482. Tween.clearTween(target);
  19483. Tween.tweenMap[gid].push(this);
  19484. }
  19485. if (runNow) {
  19486. if (delay <= 0)
  19487. this.firstStart(target, props, isTo);
  19488. else {
  19489. this._delayParam = [target, props, isTo];
  19490. ILaya.timer.once(delay, this, this.firstStart, this._delayParam);
  19491. }
  19492. }
  19493. else {
  19494. this._initProps(target, props, isTo);
  19495. }
  19496. return this;
  19497. }
  19498. firstStart(target, props, isTo) {
  19499. this._delayParam = null;
  19500. if (target.destroyed) {
  19501. this.clear();
  19502. return;
  19503. }
  19504. this._initProps(target, props, isTo);
  19505. this._beginLoop();
  19506. }
  19507. _initProps(target, props, isTo) {
  19508. for (var p in props) {
  19509. if (typeof (target[p]) == 'number') {
  19510. var start = isTo ? target[p] : props[p];
  19511. var end = isTo ? props[p] : target[p];
  19512. this._props.push([p, start, end - start]);
  19513. if (!isTo)
  19514. target[p] = start;
  19515. }
  19516. }
  19517. }
  19518. _beginLoop() {
  19519. ILaya.timer.frameLoop(1, this, this._doEase);
  19520. }
  19521. _doEase() {
  19522. this._updateEase(Browser.now());
  19523. }
  19524. _updateEase(time) {
  19525. var target = this._target;
  19526. if (!target)
  19527. return;
  19528. if (target.destroyed)
  19529. return Tween.clearTween(target);
  19530. var usedTimer = this._usedTimer = time - this._startTimer - this._delay;
  19531. if (usedTimer < 0)
  19532. return;
  19533. if (usedTimer >= this._duration)
  19534. return this.complete();
  19535. var ratio = usedTimer > 0 ? this._ease(usedTimer, 0, 1, this._duration) : 0;
  19536. var props = this._props;
  19537. for (var i = 0, n = props.length; i < n; i++) {
  19538. var prop = props[i];
  19539. target[prop[0]] = prop[1] + (ratio * prop[2]);
  19540. }
  19541. if (this.update)
  19542. this.update.run();
  19543. }
  19544. set progress(v) {
  19545. var uTime = v * this._duration;
  19546. this._startTimer = Browser.now() - this._delay - uTime;
  19547. }
  19548. complete() {
  19549. if (!this._target)
  19550. return;
  19551. ILaya.timer.runTimer(this, this.firstStart);
  19552. var target = this._target;
  19553. var props = this._props;
  19554. var handler = this._complete;
  19555. for (var i = 0, n = props.length; i < n; i++) {
  19556. var prop = props[i];
  19557. target[prop[0]] = prop[1] + prop[2];
  19558. }
  19559. if (this.update)
  19560. this.update.run();
  19561. this._count++;
  19562. if (this.repeat != 0 && this._count >= this.repeat) {
  19563. this.clear();
  19564. handler && handler.run();
  19565. }
  19566. else {
  19567. this.restart();
  19568. }
  19569. }
  19570. pause() {
  19571. ILaya.timer.clear(this, this._beginLoop);
  19572. ILaya.timer.clear(this, this._doEase);
  19573. ILaya.timer.clear(this, this.firstStart);
  19574. var time = Browser.now();
  19575. var dTime;
  19576. dTime = time - this._startTimer - this._delay;
  19577. if (dTime < 0) {
  19578. this._usedTimer = dTime;
  19579. }
  19580. }
  19581. setStartTime(startTime) {
  19582. this._startTimer = startTime;
  19583. }
  19584. static clearAll(target) {
  19585. if (!target || !target.$_GID)
  19586. return;
  19587. var tweens = Tween.tweenMap[target.$_GID];
  19588. if (tweens) {
  19589. for (var i = 0, n = tweens.length; i < n; i++) {
  19590. tweens[i]._clear();
  19591. }
  19592. tweens.length = 0;
  19593. }
  19594. }
  19595. static clear(tween) {
  19596. tween.clear();
  19597. }
  19598. static clearTween(target) {
  19599. Tween.clearAll(target);
  19600. }
  19601. clear() {
  19602. if (this._target) {
  19603. this._remove();
  19604. this._clear();
  19605. }
  19606. }
  19607. _clear() {
  19608. this.pause();
  19609. ILaya.timer.clear(this, this.firstStart);
  19610. this._complete = null;
  19611. this._target = null;
  19612. this._ease = null;
  19613. this._props = null;
  19614. this._delayParam = null;
  19615. if (this._usedPool) {
  19616. this.update = null;
  19617. Pool.recover("tween", this);
  19618. }
  19619. }
  19620. recover() {
  19621. this._usedPool = true;
  19622. this._clear();
  19623. }
  19624. _remove() {
  19625. var tweens = Tween.tweenMap[this._target.$_GID];
  19626. if (tweens) {
  19627. for (var i = 0, n = tweens.length; i < n; i++) {
  19628. if (tweens[i] === this) {
  19629. tweens.splice(i, 1);
  19630. break;
  19631. }
  19632. }
  19633. }
  19634. }
  19635. restart() {
  19636. this.pause();
  19637. this._usedTimer = 0;
  19638. this._startTimer = Browser.now();
  19639. if (this._delayParam) {
  19640. ILaya.timer.once(this._delay, this, this.firstStart, this._delayParam);
  19641. return;
  19642. }
  19643. var props = this._props;
  19644. for (var i = 0, n = props.length; i < n; i++) {
  19645. var prop = props[i];
  19646. this._target[prop[0]] = prop[1];
  19647. }
  19648. ILaya.timer.once(this._delay, this, this._beginLoop);
  19649. }
  19650. resume() {
  19651. if (this._usedTimer >= this._duration)
  19652. return;
  19653. this._startTimer = Browser.now() - this._usedTimer - this._delay;
  19654. if (this._delayParam) {
  19655. if (this._usedTimer < 0) {
  19656. ILaya.timer.once(-this._usedTimer, this, this.firstStart, this._delayParam);
  19657. }
  19658. else {
  19659. this.firstStart.apply(this, this._delayParam);
  19660. }
  19661. }
  19662. else {
  19663. this._beginLoop();
  19664. }
  19665. }
  19666. static easeNone(t, b, c, d) {
  19667. return c * t / d + b;
  19668. }
  19669. }
  19670. Tween.tweenMap = [];
  19671. class Dragging {
  19672. constructor() {
  19673. this.ratio = 0.92;
  19674. this.maxOffset = 60;
  19675. this._dragging = false;
  19676. this._clickOnly = true;
  19677. }
  19678. start(target, area, hasInertia, elasticDistance, elasticBackTime, data, disableMouseEvent, ratio = 0.92) {
  19679. this.clearTimer();
  19680. this.target = target;
  19681. this.area = area;
  19682. this.hasInertia = hasInertia;
  19683. this.elasticDistance = area ? elasticDistance : 0;
  19684. this.elasticBackTime = elasticBackTime;
  19685. this.data = data;
  19686. this._disableMouseEvent = disableMouseEvent;
  19687. this.ratio = ratio;
  19688. this._parent = target.parent;
  19689. this._clickOnly = true;
  19690. this._dragging = true;
  19691. this._elasticRateX = this._elasticRateY = 1;
  19692. this._lastX = this._parent.mouseX;
  19693. this._lastY = this._parent.mouseY;
  19694. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  19695. ILaya.stage.on(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19696. ILaya.systemTimer.frameLoop(1, this, this.loop);
  19697. }
  19698. clearTimer() {
  19699. ILaya.systemTimer.clear(this, this.loop);
  19700. ILaya.systemTimer.clear(this, this.tweenMove);
  19701. if (this._tween) {
  19702. this._tween.recover();
  19703. this._tween = null;
  19704. }
  19705. }
  19706. stop() {
  19707. if (this._dragging) {
  19708. MouseManager.instance.disableMouseEvent = false;
  19709. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  19710. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19711. this._dragging = false;
  19712. this.target && this.area && this.backToArea();
  19713. this.clear();
  19714. }
  19715. }
  19716. loop() {
  19717. var point = this._parent.getMousePoint();
  19718. var mouseX = point.x;
  19719. var mouseY = point.y;
  19720. var offsetX = mouseX - this._lastX;
  19721. var offsetY = mouseY - this._lastY;
  19722. if (this._clickOnly) {
  19723. if (Math.abs(offsetX * ILaya.stage._canvasTransform.getScaleX()) > 1 || Math.abs(offsetY * ILaya.stage._canvasTransform.getScaleY()) > 1) {
  19724. this._clickOnly = false;
  19725. this._offsets || (this._offsets = []);
  19726. this._offsets.length = 0;
  19727. this.target.event(Event.DRAG_START, this.data);
  19728. MouseManager.instance.disableMouseEvent = this._disableMouseEvent;
  19729. }
  19730. else
  19731. return;
  19732. }
  19733. else {
  19734. this._offsets.push(offsetX, offsetY);
  19735. }
  19736. if (offsetX === 0 && offsetY === 0)
  19737. return;
  19738. this._lastX = mouseX;
  19739. this._lastY = mouseY;
  19740. this.target.x += offsetX * this._elasticRateX;
  19741. this.target.y += offsetY * this._elasticRateY;
  19742. this.area && this.checkArea();
  19743. this.target.event(Event.DRAG_MOVE, this.data);
  19744. }
  19745. checkArea() {
  19746. if (this.elasticDistance <= 0) {
  19747. this.backToArea();
  19748. }
  19749. else {
  19750. if (this.target._x < this.area.x) {
  19751. var offsetX = this.area.x - this.target._x;
  19752. }
  19753. else if (this.target._x > this.area.x + this.area.width) {
  19754. offsetX = this.target._x - this.area.x - this.area.width;
  19755. }
  19756. else {
  19757. offsetX = 0;
  19758. }
  19759. this._elasticRateX = Math.max(0, 1 - (offsetX / this.elasticDistance));
  19760. if (this.target._y < this.area.y) {
  19761. var offsetY = this.area.y - this.target.y;
  19762. }
  19763. else if (this.target._y > this.area.y + this.area.height) {
  19764. offsetY = this.target._y - this.area.y - this.area.height;
  19765. }
  19766. else {
  19767. offsetY = 0;
  19768. }
  19769. this._elasticRateY = Math.max(0, 1 - (offsetY / this.elasticDistance));
  19770. }
  19771. }
  19772. backToArea() {
  19773. this.target.x = Math.min(Math.max(this.target._x, this.area.x), this.area.x + this.area.width);
  19774. this.target.y = Math.min(Math.max(this.target._y, this.area.y), this.area.y + this.area.height);
  19775. }
  19776. onStageMouseUp(e) {
  19777. MouseManager.instance.disableMouseEvent = false;
  19778. ILaya.stage.off(Event.MOUSE_UP, this, this.onStageMouseUp);
  19779. ILaya.stage.off(Event.MOUSE_OUT, this, this.onStageMouseUp);
  19780. ILaya.systemTimer.clear(this, this.loop);
  19781. if (this._clickOnly || !this.target)
  19782. return;
  19783. if (this.hasInertia) {
  19784. if (this._offsets.length < 1) {
  19785. this._offsets.push(this._parent.mouseX - this._lastX, this._parent.mouseY - this._lastY);
  19786. }
  19787. this._offsetX = this._offsetY = 0;
  19788. var len = this._offsets.length;
  19789. var n = Math.min(len, 6);
  19790. var m = this._offsets.length - n;
  19791. for (var i = len - 1; i > m; i--) {
  19792. this._offsetY += this._offsets[i--];
  19793. this._offsetX += this._offsets[i];
  19794. }
  19795. this._offsetX = this._offsetX / n * 2;
  19796. this._offsetY = this._offsetY / n * 2;
  19797. if (Math.abs(this._offsetX) > this.maxOffset)
  19798. this._offsetX = this._offsetX > 0 ? this.maxOffset : -this.maxOffset;
  19799. if (Math.abs(this._offsetY) > this.maxOffset)
  19800. this._offsetY = this._offsetY > 0 ? this.maxOffset : -this.maxOffset;
  19801. ILaya.systemTimer.frameLoop(1, this, this.tweenMove);
  19802. }
  19803. else if (this.elasticDistance > 0) {
  19804. this.checkElastic();
  19805. }
  19806. else {
  19807. this.clear();
  19808. }
  19809. }
  19810. checkElastic() {
  19811. var tx = NaN;
  19812. var ty = NaN;
  19813. if (this.target.x < this.area.x)
  19814. tx = this.area.x;
  19815. else if (this.target._x > this.area.x + this.area.width)
  19816. tx = this.area.x + this.area.width;
  19817. if (this.target.y < this.area.y)
  19818. ty = this.area.y;
  19819. else if (this.target._y > this.area.y + this.area.height)
  19820. ty = this.area.y + this.area.height;
  19821. if (!isNaN(tx) || !isNaN(ty)) {
  19822. var obj = {};
  19823. if (!isNaN(tx))
  19824. obj.x = tx;
  19825. if (!isNaN(ty))
  19826. obj.y = ty;
  19827. this._tween = Tween.to(this.target, obj, this.elasticBackTime, Ease.sineOut, Handler.create(this, this.clear), 0, false, false);
  19828. }
  19829. else {
  19830. this.clear();
  19831. }
  19832. }
  19833. tweenMove() {
  19834. this._offsetX *= this.ratio * this._elasticRateX;
  19835. this._offsetY *= this.ratio * this._elasticRateY;
  19836. this.target.x += this._offsetX;
  19837. this.target.y += this._offsetY;
  19838. this.area && this.checkArea();
  19839. this.target.event(Event.DRAG_MOVE, this.data);
  19840. if ((Math.abs(this._offsetX) < 1 && Math.abs(this._offsetY) < 1) || this._elasticRateX < 0.5 || this._elasticRateY < 0.5) {
  19841. ILaya.systemTimer.clear(this, this.tweenMove);
  19842. if (this.elasticDistance > 0)
  19843. this.checkElastic();
  19844. else
  19845. this.clear();
  19846. }
  19847. }
  19848. clear() {
  19849. if (this.target) {
  19850. this.clearTimer();
  19851. var sp = this.target;
  19852. this.target = null;
  19853. this._parent = null;
  19854. sp.event(Event.DRAG_END, this.data);
  19855. }
  19856. }
  19857. }
  19858. class Component {
  19859. constructor() {
  19860. this._id = Utils.getGID();
  19861. this._resetComp();
  19862. }
  19863. get id() {
  19864. return this._id;
  19865. }
  19866. get enabled() {
  19867. return this._enabled;
  19868. }
  19869. set enabled(value) {
  19870. if (this._enabled != value) {
  19871. this._enabled = value;
  19872. if (this.owner) {
  19873. if (value)
  19874. this.owner.activeInHierarchy && this._onEnable();
  19875. else
  19876. this.owner.activeInHierarchy && this._onDisable();
  19877. }
  19878. }
  19879. }
  19880. get isSingleton() {
  19881. return true;
  19882. }
  19883. get destroyed() {
  19884. return this._destroyed;
  19885. }
  19886. _isScript() {
  19887. return false;
  19888. }
  19889. _resetComp() {
  19890. this._indexInList = -1;
  19891. this._enabled = true;
  19892. this._awaked = false;
  19893. this.owner = null;
  19894. }
  19895. _getIndexInList() {
  19896. return this._indexInList;
  19897. }
  19898. _setIndexInList(index) {
  19899. this._indexInList = index;
  19900. }
  19901. _onAdded() {
  19902. }
  19903. _onAwake() {
  19904. }
  19905. _onEnable() {
  19906. }
  19907. _onDisable() {
  19908. }
  19909. _onDestroy() {
  19910. }
  19911. onReset() {
  19912. }
  19913. _parse(data) {
  19914. }
  19915. _cloneTo(dest) {
  19916. }
  19917. _setActive(value) {
  19918. if (value) {
  19919. if (!this._awaked) {
  19920. this._awaked = true;
  19921. this._onAwake();
  19922. }
  19923. this._enabled && this._onEnable();
  19924. }
  19925. else {
  19926. this._enabled && this._onDisable();
  19927. }
  19928. }
  19929. destroy() {
  19930. if (this.owner)
  19931. this.owner._destroyComponent(this);
  19932. }
  19933. _destroy() {
  19934. if (this.owner.activeInHierarchy && this._enabled) {
  19935. this._setActive(false);
  19936. (this._isScript()) && (this.onDisable());
  19937. }
  19938. this._onDestroy();
  19939. this._destroyed = true;
  19940. if (this.onReset !== Component.prototype.onReset) {
  19941. this.onReset();
  19942. this._resetComp();
  19943. Pool.recoverByClass(this);
  19944. }
  19945. else {
  19946. this._resetComp();
  19947. }
  19948. }
  19949. }
  19950. class AnimationBase extends Sprite {
  19951. constructor() {
  19952. super();
  19953. this.wrapMode = 0;
  19954. this._interval = Config.animationInterval;
  19955. this._isReverse = false;
  19956. this._frameRateChanged = false;
  19957. this._setBitUp(Const.DISPLAY);
  19958. }
  19959. play(start = 0, loop = true, name = "") {
  19960. this._isPlaying = true;
  19961. this._actionName = name;
  19962. this.index = (typeof (start) == 'string') ? this._getFrameByLabel(start) : start;
  19963. this.loop = loop;
  19964. this._isReverse = this.wrapMode === AnimationBase.WRAP_REVERSE;
  19965. if (this.index == 0 && this._isReverse) {
  19966. this.index = this.count - 1;
  19967. }
  19968. if (this.interval > 0)
  19969. this.timerLoop(this.interval, this, this._frameLoop, null, true, true);
  19970. }
  19971. get interval() {
  19972. return this._interval;
  19973. }
  19974. set interval(value) {
  19975. if (this._interval != value) {
  19976. this._frameRateChanged = true;
  19977. this._interval = value;
  19978. if (this._isPlaying && value > 0) {
  19979. this.timerLoop(value, this, this._frameLoop, null, true, true);
  19980. }
  19981. }
  19982. }
  19983. _getFrameByLabel(label) {
  19984. for (var i = 0; i < this._count; i++) {
  19985. var item = this._labels[i];
  19986. if (item && item.indexOf(label) > -1)
  19987. return i;
  19988. }
  19989. return 0;
  19990. }
  19991. _frameLoop() {
  19992. if (this._isReverse) {
  19993. this._index--;
  19994. if (this._index < 0) {
  19995. if (this.loop) {
  19996. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  19997. this._index = this._count > 0 ? 1 : 0;
  19998. this._isReverse = false;
  19999. }
  20000. else {
  20001. this._index = this._count - 1;
  20002. }
  20003. this.event(Event.COMPLETE);
  20004. }
  20005. else {
  20006. this._index = 0;
  20007. this.stop();
  20008. this.event(Event.COMPLETE);
  20009. return;
  20010. }
  20011. }
  20012. }
  20013. else {
  20014. this._index++;
  20015. if (this._index >= this._count) {
  20016. if (this.loop) {
  20017. if (this.wrapMode == AnimationBase.WRAP_PINGPONG) {
  20018. this._index = this._count - 2 >= 0 ? this._count - 2 : 0;
  20019. this._isReverse = true;
  20020. }
  20021. else {
  20022. this._index = 0;
  20023. }
  20024. this.event(Event.COMPLETE);
  20025. }
  20026. else {
  20027. this._index--;
  20028. this.stop();
  20029. this.event(Event.COMPLETE);
  20030. return;
  20031. }
  20032. }
  20033. }
  20034. this.index = this._index;
  20035. }
  20036. _setControlNode(node) {
  20037. if (this._controlNode) {
  20038. this._controlNode.off(Event.DISPLAY, this, this._resumePlay);
  20039. this._controlNode.off(Event.UNDISPLAY, this, this._resumePlay);
  20040. }
  20041. this._controlNode = node;
  20042. if (node && node != this) {
  20043. node.on(Event.DISPLAY, this, this._resumePlay);
  20044. node.on(Event.UNDISPLAY, this, this._resumePlay);
  20045. }
  20046. }
  20047. _setDisplay(value) {
  20048. super._setDisplay(value);
  20049. this._resumePlay();
  20050. }
  20051. _resumePlay() {
  20052. if (this._isPlaying) {
  20053. if (this._controlNode.displayedInStage)
  20054. this.play(this._index, this.loop, this._actionName);
  20055. else
  20056. this.clearTimer(this, this._frameLoop);
  20057. }
  20058. }
  20059. stop() {
  20060. this._isPlaying = false;
  20061. this.clearTimer(this, this._frameLoop);
  20062. }
  20063. get isPlaying() {
  20064. return this._isPlaying;
  20065. }
  20066. addLabel(label, index) {
  20067. if (!this._labels)
  20068. this._labels = {};
  20069. if (!this._labels[index])
  20070. this._labels[index] = [];
  20071. this._labels[index].push(label);
  20072. }
  20073. removeLabel(label) {
  20074. if (!label)
  20075. this._labels = null;
  20076. else if (this._labels) {
  20077. for (var name in this._labels) {
  20078. this._removeLabelFromList(this._labels[name], label);
  20079. }
  20080. }
  20081. }
  20082. _removeLabelFromList(list, label) {
  20083. if (!list)
  20084. return;
  20085. for (var i = list.length - 1; i >= 0; i--) {
  20086. if (list[i] == label) {
  20087. list.splice(i, 1);
  20088. }
  20089. }
  20090. }
  20091. gotoAndStop(position) {
  20092. this.index = (typeof (position) == 'string') ? this._getFrameByLabel(position) : position;
  20093. this.stop();
  20094. }
  20095. get index() {
  20096. return this._index;
  20097. }
  20098. set index(value) {
  20099. this._index = value;
  20100. this._displayToIndex(value);
  20101. if (this._labels && this._labels[value]) {
  20102. var tArr = this._labels[value];
  20103. for (var i = 0, len = tArr.length; i < len; i++) {
  20104. this.event(Event.LABEL, tArr[i]);
  20105. }
  20106. }
  20107. }
  20108. _displayToIndex(value) {
  20109. }
  20110. get count() {
  20111. return this._count;
  20112. }
  20113. clear() {
  20114. this.stop();
  20115. this._labels = null;
  20116. return this;
  20117. }
  20118. }
  20119. AnimationBase.WRAP_POSITIVE = 0;
  20120. AnimationBase.WRAP_REVERSE = 1;
  20121. AnimationBase.WRAP_PINGPONG = 2;
  20122. ClassUtils.regClass("laya.display.AnimationBase", AnimationBase);
  20123. ClassUtils.regClass("Laya.AnimationBase", AnimationBase);
  20124. class MathUtil {
  20125. static subtractVector3(l, r, o) {
  20126. o[0] = l[0] - r[0];
  20127. o[1] = l[1] - r[1];
  20128. o[2] = l[2] - r[2];
  20129. }
  20130. static lerp(left, right, amount) {
  20131. return left * (1 - amount) + right * amount;
  20132. }
  20133. static scaleVector3(f, b, e) {
  20134. e[0] = f[0] * b;
  20135. e[1] = f[1] * b;
  20136. e[2] = f[2] * b;
  20137. }
  20138. static lerpVector3(l, r, t, o) {
  20139. var ax = l[0], ay = l[1], az = l[2];
  20140. o[0] = ax + t * (r[0] - ax);
  20141. o[1] = ay + t * (r[1] - ay);
  20142. o[2] = az + t * (r[2] - az);
  20143. }
  20144. static lerpVector4(l, r, t, o) {
  20145. var ax = l[0], ay = l[1], az = l[2], aw = l[3];
  20146. o[0] = ax + t * (r[0] - ax);
  20147. o[1] = ay + t * (r[1] - ay);
  20148. o[2] = az + t * (r[2] - az);
  20149. o[3] = aw + t * (r[3] - aw);
  20150. }
  20151. static slerpQuaternionArray(a, Offset1, b, Offset2, t, out, Offset3) {
  20152. 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];
  20153. var omega, cosom, sinom, scale0, scale1;
  20154. cosom = ax * bx + ay * by + az * bz + aw * bw;
  20155. if (cosom < 0.0) {
  20156. cosom = -cosom;
  20157. bx = -bx;
  20158. by = -by;
  20159. bz = -bz;
  20160. bw = -bw;
  20161. }
  20162. if ((1.0 - cosom) > 0.000001) {
  20163. omega = Math.acos(cosom);
  20164. sinom = Math.sin(omega);
  20165. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  20166. scale1 = Math.sin(t * omega) / sinom;
  20167. }
  20168. else {
  20169. scale0 = 1.0 - t;
  20170. scale1 = t;
  20171. }
  20172. out[Offset3 + 0] = scale0 * ax + scale1 * bx;
  20173. out[Offset3 + 1] = scale0 * ay + scale1 * by;
  20174. out[Offset3 + 2] = scale0 * az + scale1 * bz;
  20175. out[Offset3 + 3] = scale0 * aw + scale1 * bw;
  20176. return out;
  20177. }
  20178. static getRotation(x0, y0, x1, y1) {
  20179. return Math.atan2(y1 - y0, x1 - x0) / Math.PI * 180;
  20180. }
  20181. static sortBigFirst(a, b) {
  20182. if (a == b)
  20183. return 0;
  20184. return b > a ? 1 : -1;
  20185. }
  20186. static sortSmallFirst(a, b) {
  20187. if (a == b)
  20188. return 0;
  20189. return b > a ? -1 : 1;
  20190. }
  20191. static sortNumBigFirst(a, b) {
  20192. return parseFloat(b) - parseFloat(a);
  20193. }
  20194. static sortNumSmallFirst(a, b) {
  20195. return parseFloat(a) - parseFloat(b);
  20196. }
  20197. static sortByKey(key, bigFirst = false, forceNum = true) {
  20198. var _sortFun;
  20199. if (bigFirst) {
  20200. _sortFun = forceNum ? MathUtil.sortNumBigFirst : MathUtil.sortBigFirst;
  20201. }
  20202. else {
  20203. _sortFun = forceNum ? MathUtil.sortNumSmallFirst : MathUtil.sortSmallFirst;
  20204. }
  20205. return function (a, b) {
  20206. return _sortFun(a[key], b[key]);
  20207. };
  20208. }
  20209. }
  20210. class FrameAnimation extends AnimationBase {
  20211. constructor() {
  20212. super();
  20213. if (FrameAnimation._sortIndexFun === null) {
  20214. FrameAnimation._sortIndexFun = MathUtil.sortByKey("index", false, true);
  20215. }
  20216. }
  20217. _setUp(targetDic, animationData) {
  20218. this._targetDic = targetDic;
  20219. this._animationData = animationData;
  20220. this.interval = 1000 / animationData.frameRate;
  20221. if (animationData.parsed) {
  20222. this._count = animationData.count;
  20223. this._labels = animationData.labels;
  20224. this._usedFrames = animationData.animationNewFrames;
  20225. }
  20226. else {
  20227. this._usedFrames = [];
  20228. this._calculateDatas();
  20229. animationData.parsed = true;
  20230. animationData.labels = this._labels;
  20231. animationData.count = this._count;
  20232. animationData.animationNewFrames = this._usedFrames;
  20233. }
  20234. }
  20235. clear() {
  20236. super.clear();
  20237. this._targetDic = null;
  20238. this._animationData = null;
  20239. return this;
  20240. }
  20241. _displayToIndex(value) {
  20242. if (!this._animationData)
  20243. return;
  20244. if (value < 0)
  20245. value = 0;
  20246. if (value > this._count)
  20247. value = this._count;
  20248. var nodes = this._animationData.nodes, i, len = nodes.length;
  20249. for (i = 0; i < len; i++) {
  20250. this._displayNodeToFrame(nodes[i], value);
  20251. }
  20252. }
  20253. _displayNodeToFrame(node, frame, targetDic = null) {
  20254. if (!targetDic)
  20255. targetDic = this._targetDic;
  20256. var target = targetDic[node.target];
  20257. if (!target) {
  20258. return;
  20259. }
  20260. var frames = node.frames, key, propFrames, value;
  20261. var keys = node.keys, i, len = keys.length;
  20262. for (i = 0; i < len; i++) {
  20263. key = keys[i];
  20264. propFrames = frames[key];
  20265. if (propFrames.length > frame) {
  20266. value = propFrames[frame];
  20267. }
  20268. else {
  20269. value = propFrames[propFrames.length - 1];
  20270. }
  20271. target[key] = value;
  20272. }
  20273. var funkeys = node.funkeys;
  20274. len = funkeys.length;
  20275. var funFrames;
  20276. if (len == 0)
  20277. return;
  20278. for (i = 0; i < len; i++) {
  20279. key = funkeys[i];
  20280. funFrames = frames[key];
  20281. if (funFrames[frame] !== undefined) {
  20282. target[key] && target[key].apply(target, funFrames[frame]);
  20283. }
  20284. }
  20285. }
  20286. _calculateDatas() {
  20287. if (!this._animationData)
  20288. return;
  20289. var nodes = this._animationData.nodes, i, len = nodes.length, tNode;
  20290. this._count = 0;
  20291. for (i = 0; i < len; i++) {
  20292. tNode = nodes[i];
  20293. this._calculateKeyFrames(tNode);
  20294. }
  20295. this._count += 1;
  20296. }
  20297. _calculateKeyFrames(node) {
  20298. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  20299. if (!node.frames)
  20300. node.frames = {};
  20301. if (!node.keys)
  20302. node.keys = [];
  20303. else
  20304. node.keys.length = 0;
  20305. if (!node.funkeys)
  20306. node.funkeys = [];
  20307. else
  20308. node.funkeys.length = 0;
  20309. if (!node.initValues)
  20310. node.initValues = {};
  20311. for (key in keyFrames) {
  20312. var isFun = key.indexOf("()") != -1;
  20313. tKeyFrames = keyFrames[key];
  20314. if (isFun)
  20315. key = key.substr(0, key.length - 2);
  20316. if (!node.frames[key]) {
  20317. node.frames[key] = [];
  20318. }
  20319. if (!isFun) {
  20320. if (this._targetDic && this._targetDic[target]) {
  20321. node.initValues[key] = this._targetDic[target][key];
  20322. }
  20323. tKeyFrames.sort(FrameAnimation._sortIndexFun);
  20324. node.keys.push(key);
  20325. this._calculateNodePropFrames(tKeyFrames, node.frames[key], key, target);
  20326. }
  20327. else {
  20328. node.funkeys.push(key);
  20329. var map = node.frames[key];
  20330. for (var i = 0; i < tKeyFrames.length; i++) {
  20331. var temp = tKeyFrames[i];
  20332. map[temp.index] = temp.value;
  20333. if (temp.index > this._count)
  20334. this._count = temp.index;
  20335. }
  20336. }
  20337. }
  20338. }
  20339. resetNodes() {
  20340. if (!this._targetDic)
  20341. return;
  20342. if (!this._animationData)
  20343. return;
  20344. var nodes = this._animationData.nodes, i, len = nodes.length;
  20345. var tNode;
  20346. var initValues;
  20347. for (i = 0; i < len; i++) {
  20348. tNode = nodes[i];
  20349. initValues = tNode.initValues;
  20350. if (!initValues)
  20351. continue;
  20352. var target = this._targetDic[tNode.target];
  20353. if (!target)
  20354. continue;
  20355. var key;
  20356. for (key in initValues) {
  20357. target[key] = initValues[key];
  20358. }
  20359. }
  20360. }
  20361. _calculateNodePropFrames(keyframes, frames, key, target) {
  20362. var i, len = keyframes.length - 1;
  20363. frames.length = keyframes[len].index + 1;
  20364. for (i = 0; i < len; i++) {
  20365. this._dealKeyFrame(keyframes[i]);
  20366. this._calculateFrameValues(keyframes[i], keyframes[i + 1], frames);
  20367. }
  20368. if (len == 0) {
  20369. frames[0] = keyframes[0].value;
  20370. if (this._usedFrames)
  20371. this._usedFrames[keyframes[0].index] = true;
  20372. }
  20373. this._dealKeyFrame(keyframes[i]);
  20374. }
  20375. _dealKeyFrame(keyFrame) {
  20376. if (keyFrame.label && keyFrame.label != "")
  20377. this.addLabel(keyFrame.label, keyFrame.index);
  20378. }
  20379. _calculateFrameValues(startFrame, endFrame, result) {
  20380. var i, easeFun;
  20381. var start = startFrame.index, end = endFrame.index;
  20382. var startValue = startFrame.value;
  20383. var dValue = endFrame.value - startFrame.value;
  20384. var dLen = end - start;
  20385. var frames = this._usedFrames;
  20386. if (end > this._count)
  20387. this._count = end;
  20388. if (startFrame.tween) {
  20389. easeFun = Ease[startFrame.tweenMethod];
  20390. if (easeFun == null)
  20391. easeFun = Ease.linearNone;
  20392. for (i = start; i < end; i++) {
  20393. result[i] = easeFun(i - start, startValue, dValue, dLen);
  20394. if (frames)
  20395. frames[i] = true;
  20396. }
  20397. }
  20398. else {
  20399. for (i = start; i < end; i++) {
  20400. result[i] = startValue;
  20401. }
  20402. }
  20403. if (frames) {
  20404. frames[startFrame.index] = true;
  20405. frames[endFrame.index] = true;
  20406. }
  20407. result[endFrame.index] = endFrame.value;
  20408. }
  20409. }
  20410. ClassUtils.regClass("laya.display.FrameAnimation", FrameAnimation);
  20411. ClassUtils.regClass("Laya.FrameAnimation", FrameAnimation);
  20412. var supportWeakMap = !!WeakMap;
  20413. class WeakObject {
  20414. constructor() {
  20415. this._obj = WeakObject.supportWeakMap ? new Browser.window.WeakMap() : {};
  20416. if (!WeakObject.supportWeakMap)
  20417. WeakObject._maps.push(this);
  20418. }
  20419. static __init__() {
  20420. WeakObject.I = new WeakObject();
  20421. if (!WeakObject.supportWeakMap)
  20422. ILaya.systemTimer.loop(WeakObject.delInterval, null, WeakObject.clearCache);
  20423. }
  20424. static clearCache() {
  20425. for (var i = 0, n = WeakObject._maps.length; i < n; i++) {
  20426. var obj = WeakObject._maps[i];
  20427. obj._obj = {};
  20428. }
  20429. }
  20430. set(key, value) {
  20431. if (key == null)
  20432. return;
  20433. if (WeakObject.supportWeakMap) {
  20434. var objKey = key;
  20435. if (typeof (key) == 'string' || typeof (key) == 'number') {
  20436. objKey = WeakObject._keys[key];
  20437. if (!objKey)
  20438. objKey = WeakObject._keys[key] = { k: key };
  20439. }
  20440. this._obj.set(objKey, value);
  20441. }
  20442. else {
  20443. if (typeof (key) == 'string' || typeof (key) == 'number') {
  20444. this._obj[key] = value;
  20445. }
  20446. else {
  20447. key.$_GID || (key.$_GID = Utils.getGID());
  20448. this._obj[key.$_GID] = value;
  20449. }
  20450. }
  20451. }
  20452. get(key) {
  20453. if (key == null)
  20454. return null;
  20455. if (WeakObject.supportWeakMap) {
  20456. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20457. if (!objKey)
  20458. return null;
  20459. return this._obj.get(objKey);
  20460. }
  20461. else {
  20462. if (typeof (key) == 'string' || typeof (key) == 'number')
  20463. return this._obj[key];
  20464. return this._obj[key.$_GID];
  20465. }
  20466. }
  20467. del(key) {
  20468. if (key == null)
  20469. return;
  20470. if (WeakObject.supportWeakMap) {
  20471. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20472. if (!objKey)
  20473. return;
  20474. this._obj.delete(objKey);
  20475. }
  20476. else {
  20477. if (typeof (key) == 'string' || typeof (key) == 'number')
  20478. delete this._obj[key];
  20479. else
  20480. delete this._obj[this._obj.$_GID];
  20481. }
  20482. }
  20483. has(key) {
  20484. if (key == null)
  20485. return false;
  20486. if (WeakObject.supportWeakMap) {
  20487. var objKey = (typeof (key) == 'string' || typeof (key) == 'number') ? WeakObject._keys[key] : key;
  20488. return this._obj.has(objKey);
  20489. }
  20490. else {
  20491. if (typeof (key) == 'string' || typeof (key) == 'number')
  20492. return this._obj[key] != null;
  20493. return this._obj[this._obj.$_GID] != null;
  20494. }
  20495. }
  20496. }
  20497. WeakObject.supportWeakMap = supportWeakMap;
  20498. WeakObject.delInterval = 10 * 60 * 1000;
  20499. WeakObject._keys = {};
  20500. WeakObject._maps = [];
  20501. class SceneUtils {
  20502. static __init() {
  20503. SceneUtils._funMap = new WeakObject();
  20504. }
  20505. static getBindFun(value) {
  20506. var fun = SceneUtils._funMap.get(value);
  20507. if (fun == null) {
  20508. var temp = "\"" + value + "\"";
  20509. temp = temp.replace(/^"\${|}"$/g, "").replace(/\${/g, "\"+").replace(/}/g, "+\"");
  20510. var str = "(function(data){if(data==null)return;with(data){try{\nreturn " + temp + "\n}catch(e){}}})";
  20511. fun = window.Laya._runScript(str);
  20512. SceneUtils._funMap.set(value, fun);
  20513. }
  20514. return fun;
  20515. }
  20516. static createByData(root, uiView) {
  20517. var tInitTool = InitTool.create();
  20518. root = SceneUtils.createComp(uiView, root, root, null, tInitTool);
  20519. root._setBit(Const.NOT_READY, true);
  20520. if ("_idMap" in root) {
  20521. root["_idMap"] = tInitTool._idMap;
  20522. }
  20523. if (uiView.animations) {
  20524. var anilist = [];
  20525. var animations = uiView.animations;
  20526. var i, len = animations.length;
  20527. var tAni;
  20528. var tAniO;
  20529. for (i = 0; i < len; i++) {
  20530. tAni = new FrameAnimation();
  20531. tAniO = animations[i];
  20532. tAni._setUp(tInitTool._idMap, tAniO);
  20533. root[tAniO.name] = tAni;
  20534. tAni._setControlNode(root);
  20535. switch (tAniO.action) {
  20536. case 1:
  20537. tAni.play(0, false);
  20538. break;
  20539. case 2:
  20540. tAni.play(0, true);
  20541. break;
  20542. }
  20543. anilist.push(tAni);
  20544. }
  20545. root._aniList = anilist;
  20546. }
  20547. if (root._$componentType === "Scene" && root._width > 0 && uiView.props.hitTestPrior == null && !root.mouseThrough)
  20548. root.hitTestPrior = true;
  20549. tInitTool.beginLoad(root);
  20550. return root;
  20551. }
  20552. static createInitTool() {
  20553. return InitTool.create();
  20554. }
  20555. static createComp(uiView, comp = null, view = null, dataMap = null, initTool = null) {
  20556. if (uiView.type == "Scene3D" || uiView.type == "Sprite3D") {
  20557. var outBatchSprits = [];
  20558. var scene3D = ILaya.Laya["Utils3D"]._createSceneByJsonForMaker(uiView, outBatchSprits, initTool);
  20559. if (uiView.type == "Sprite3D")
  20560. ILaya.Laya["StaticBatchManager"].combine(scene3D, outBatchSprits);
  20561. else
  20562. ILaya.Laya["StaticBatchManager"].combine(null, outBatchSprits);
  20563. return scene3D;
  20564. }
  20565. comp = comp || SceneUtils.getCompInstance(uiView);
  20566. if (!comp) {
  20567. if (uiView.props && uiView.props.runtime)
  20568. console.warn("runtime not found:" + uiView.props.runtime);
  20569. else
  20570. console.warn("can not create:" + uiView.type);
  20571. return null;
  20572. }
  20573. var child = uiView.child;
  20574. if (child) {
  20575. var isList = comp["_$componentType"] == "List";
  20576. for (var i = 0, n = child.length; i < n; i++) {
  20577. var node = child[i];
  20578. if ('itemRender' in comp && (node.props.name == "render" || node.props.renderType === "render")) {
  20579. comp["itemRender"] = node;
  20580. }
  20581. else if (node.type == "Graphic") {
  20582. ILaya.ClassUtils._addGraphicsToSprite(node, comp);
  20583. }
  20584. else if (ILaya.ClassUtils._isDrawType(node.type)) {
  20585. ILaya.ClassUtils._addGraphicToSprite(node, comp, true);
  20586. }
  20587. else {
  20588. if (isList) {
  20589. var arr = [];
  20590. var tChild = SceneUtils.createComp(node, null, view, arr, initTool);
  20591. if (arr.length)
  20592. tChild["_$bindData"] = arr;
  20593. }
  20594. else {
  20595. tChild = SceneUtils.createComp(node, null, view, dataMap, initTool);
  20596. }
  20597. if (node.type == "Script") {
  20598. if (tChild instanceof Component) {
  20599. comp._addComponentInstance(tChild);
  20600. }
  20601. else {
  20602. if ("owner" in tChild) {
  20603. tChild["owner"] = comp;
  20604. }
  20605. else if ("target" in tChild) {
  20606. tChild["target"] = comp;
  20607. }
  20608. }
  20609. }
  20610. else if (node.props.renderType == "mask" || node.props.name == "mask") {
  20611. comp.mask = tChild;
  20612. }
  20613. else {
  20614. tChild instanceof Node && comp.addChild(tChild);
  20615. }
  20616. }
  20617. }
  20618. }
  20619. var props = uiView.props;
  20620. for (var prop in props) {
  20621. var value = props[prop];
  20622. if (typeof (value) == 'string' && (value.indexOf("@node:") >= 0 || value.indexOf("@Prefab:") >= 0)) {
  20623. if (initTool) {
  20624. initTool.addNodeRef(comp, prop, value);
  20625. }
  20626. }
  20627. else
  20628. SceneUtils.setCompValue(comp, prop, value, view, dataMap);
  20629. }
  20630. if (comp._afterInited) {
  20631. comp._afterInited();
  20632. }
  20633. if (uiView.compId && initTool && initTool._idMap) {
  20634. initTool._idMap[uiView.compId] = comp;
  20635. }
  20636. return comp;
  20637. }
  20638. static setCompValue(comp, prop, value, view = null, dataMap = null) {
  20639. if (typeof (value) == 'string' && value.indexOf("${") > -1) {
  20640. SceneUtils._sheet || (SceneUtils._sheet = ILaya.ClassUtils.getClass("laya.data.Table"));
  20641. if (!SceneUtils._sheet) {
  20642. console.warn("Can not find class Sheet");
  20643. return;
  20644. }
  20645. if (dataMap) {
  20646. dataMap.push(comp, prop, value);
  20647. }
  20648. else if (view) {
  20649. if (value.indexOf("].") == -1) {
  20650. value = value.replace(".", "[0].");
  20651. }
  20652. var watcher = new DataWatcher(comp, prop, value);
  20653. watcher.exe(view);
  20654. var one, temp;
  20655. var str = value.replace(/\[.*?\]\./g, ".");
  20656. while ((one = SceneUtils._parseWatchData.exec(str)) != null) {
  20657. var key1 = one[1];
  20658. while ((temp = SceneUtils._parseKeyWord.exec(key1)) != null) {
  20659. var key2 = temp[0];
  20660. var arr = (view._watchMap[key2] || (view._watchMap[key2] = []));
  20661. arr.push(watcher);
  20662. SceneUtils._sheet.I.notifer.on(key2, view, view.changeData, [key2]);
  20663. }
  20664. arr = (view._watchMap[key1] || (view._watchMap[key1] = []));
  20665. arr.push(watcher);
  20666. SceneUtils._sheet.I.notifer.on(key1, view, view.changeData, [key1]);
  20667. }
  20668. }
  20669. return;
  20670. }
  20671. if (prop === "var" && view) {
  20672. view[value] = comp;
  20673. }
  20674. else {
  20675. comp[prop] = (value === "true" ? true : (value === "false" ? false : value));
  20676. }
  20677. }
  20678. static getCompInstance(json) {
  20679. if (json.type == "UIView") {
  20680. if (json.props && json.props.pageData) {
  20681. return SceneUtils.createByData(null, json.props.pageData);
  20682. }
  20683. }
  20684. var runtime = (json.props && json.props.runtime) || json.type;
  20685. var compClass = ILaya.ClassUtils.getClass(runtime);
  20686. if (!compClass)
  20687. throw "Can not find class " + runtime;
  20688. if (json.type === "Script" && compClass.prototype._doAwake) {
  20689. var comp = Pool.createByClass(compClass);
  20690. comp._destroyed = false;
  20691. return comp;
  20692. }
  20693. if (json.props && "renderType" in json.props && json.props["renderType"] == "instance") {
  20694. if (!compClass["instance"])
  20695. compClass["instance"] = new compClass();
  20696. return compClass["instance"];
  20697. }
  20698. return new compClass();
  20699. }
  20700. }
  20701. SceneUtils._parseWatchData = /\${(.*?)}/g;
  20702. SceneUtils._parseKeyWord = /[a-zA-Z_][a-zA-Z0-9_]*(?:(?:\.[a-zA-Z_][a-zA-Z0-9_]*)+)/g;
  20703. class DataWatcher {
  20704. constructor(comp, prop, value) {
  20705. this.comp = comp;
  20706. this.prop = prop;
  20707. this.value = value;
  20708. }
  20709. exe(view) {
  20710. var fun = SceneUtils.getBindFun(this.value);
  20711. this.comp[this.prop] = fun.call(this, view);
  20712. }
  20713. }
  20714. class InitTool {
  20715. reset() {
  20716. this._nodeRefList = null;
  20717. this._initList = null;
  20718. this._idMap = null;
  20719. this._loadList = null;
  20720. this._scene = null;
  20721. }
  20722. recover() {
  20723. this.reset();
  20724. Pool.recover("InitTool", this);
  20725. }
  20726. static create() {
  20727. var tool = Pool.getItemByClass("InitTool", InitTool);
  20728. tool._idMap = [];
  20729. return tool;
  20730. }
  20731. addLoadRes(url, type = null) {
  20732. if (!this._loadList)
  20733. this._loadList = [];
  20734. if (!type) {
  20735. this._loadList.push(url);
  20736. }
  20737. else {
  20738. this._loadList.push({ url: url, type: type });
  20739. }
  20740. }
  20741. addNodeRef(node, prop, referStr) {
  20742. if (!this._nodeRefList)
  20743. this._nodeRefList = [];
  20744. this._nodeRefList.push([node, prop, referStr]);
  20745. if (referStr.indexOf("@Prefab:") >= 0) {
  20746. this.addLoadRes(referStr.replace("@Prefab:", ""), Loader.PREFAB);
  20747. }
  20748. }
  20749. setNodeRef() {
  20750. if (!this._nodeRefList)
  20751. return;
  20752. if (!this._idMap) {
  20753. this._nodeRefList = null;
  20754. return;
  20755. }
  20756. var i, len;
  20757. len = this._nodeRefList.length;
  20758. var tRefInfo;
  20759. for (i = 0; i < len; i++) {
  20760. tRefInfo = this._nodeRefList[i];
  20761. tRefInfo[0][tRefInfo[1]] = this.getReferData(tRefInfo[2]);
  20762. }
  20763. this._nodeRefList = null;
  20764. }
  20765. getReferData(referStr) {
  20766. if (referStr.indexOf("@Prefab:") >= 0) {
  20767. var prefab;
  20768. prefab = Loader.getRes(referStr.replace("@Prefab:", ""));
  20769. return prefab;
  20770. }
  20771. else if (referStr.indexOf("@arr:") >= 0) {
  20772. referStr = referStr.replace("@arr:", "");
  20773. var list;
  20774. list = referStr.split(",");
  20775. var i, len;
  20776. var tStr;
  20777. len = list.length;
  20778. for (i = 0; i < len; i++) {
  20779. tStr = list[i];
  20780. if (tStr) {
  20781. list[i] = this._idMap[tStr.replace("@node:", "")];
  20782. }
  20783. else {
  20784. list[i] = null;
  20785. }
  20786. }
  20787. return list;
  20788. }
  20789. else {
  20790. return this._idMap[referStr.replace("@node:", "")];
  20791. }
  20792. }
  20793. addInitItem(item) {
  20794. if (!this._initList)
  20795. this._initList = [];
  20796. this._initList.push(item);
  20797. }
  20798. doInits() {
  20799. if (!this._initList)
  20800. return;
  20801. this._initList = null;
  20802. }
  20803. finish() {
  20804. this.setNodeRef();
  20805. this.doInits();
  20806. this._scene._setBit(Const.NOT_READY, false);
  20807. if (this._scene.parent && this._scene.parent.activeInHierarchy && this._scene.active)
  20808. this._scene._processActive();
  20809. this._scene.event("onViewCreated");
  20810. this.recover();
  20811. }
  20812. beginLoad(scene) {
  20813. this._scene = scene;
  20814. if (!this._loadList || this._loadList.length < 1) {
  20815. this.finish();
  20816. }
  20817. else {
  20818. ILaya.loader.load(this._loadList, Handler.create(this, this.finish));
  20819. }
  20820. }
  20821. }
  20822. class IStatRender {
  20823. show(x = 0, y = 0) {
  20824. }
  20825. enable() {
  20826. }
  20827. hide() {
  20828. }
  20829. set_onclick(fn) {
  20830. }
  20831. isCanvasRender() {
  20832. return true;
  20833. }
  20834. renderNotCanvas(ctx, x, y) { }
  20835. }
  20836. class StatUI extends IStatRender {
  20837. constructor() {
  20838. super(...arguments);
  20839. this._show = false;
  20840. this._useCanvas = false;
  20841. this._height = 100;
  20842. this._view = [];
  20843. }
  20844. show(x = 0, y = 0) {
  20845. if (!Browser.onMiniGame && !ILaya.Render.isConchApp && !Browser.onBDMiniGame && !Browser.onKGMiniGame && !Browser.onQGMiniGame && !Browser.onQQMiniGame)
  20846. this._useCanvas = true;
  20847. this._show = true;
  20848. Stat._fpsData.length = 60;
  20849. this._view[0] = { title: "FPS(Canvas)", value: "_fpsStr", color: "yellow", units: "int" };
  20850. this._view[1] = { title: "Sprite", value: "_spriteStr", color: "white", units: "int" };
  20851. this._view[2] = { title: "RenderBatches", value: "renderBatches", color: "white", units: "int" };
  20852. this._view[3] = { title: "SavedRenderBatches", value: "savedRenderBatches", color: "white", units: "int" };
  20853. this._view[4] = { title: "CPUMemory", value: "cpuMemory", color: "yellow", units: "M" };
  20854. this._view[5] = { title: "GPUMemory", value: "gpuMemory", color: "yellow", units: "M" };
  20855. this._view[6] = { title: "Shader", value: "shaderCall", color: "white", units: "int" };
  20856. if (!Render.is3DMode) {
  20857. this._view[0].title = "FPS(WebGL)";
  20858. this._view[7] = { title: "Canvas", value: "_canvasStr", color: "white", units: "int" };
  20859. }
  20860. else {
  20861. this._view[0].title = "FPS(3D)";
  20862. this._view[7] = { title: "TriFaces", value: "trianglesFaces", color: "white", units: "int" };
  20863. this._view[8] = { title: "FrustumCulling", value: "frustumCulling", color: "white", units: "int" };
  20864. this._view[9] = { title: "OctreeNodeCulling", value: "octreeNodeCulling", color: "white", units: "int" };
  20865. }
  20866. if (this._useCanvas) {
  20867. this.createUIPre(x, y);
  20868. }
  20869. else
  20870. this.createUI(x, y);
  20871. this.enable();
  20872. }
  20873. createUIPre(x, y) {
  20874. var pixel = Browser.pixelRatio;
  20875. this._width = pixel * 180;
  20876. this._vx = pixel * 120;
  20877. this._height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  20878. StatUI._fontSize = 12 * pixel;
  20879. for (var i = 0; i < this._view.length; i++) {
  20880. this._view[i].x = 4;
  20881. this._view[i].y = i * StatUI._fontSize + 2 * pixel;
  20882. }
  20883. if (!this._canvas) {
  20884. this._canvas = new HTMLCanvas(true);
  20885. this._canvas.size(this._width, this._height);
  20886. this._ctx = this._canvas.getContext('2d');
  20887. this._ctx.textBaseline = "top";
  20888. this._ctx.font = StatUI._fontSize + "px Arial";
  20889. 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;";
  20890. }
  20891. if (!Browser.onKGMiniGame) {
  20892. Browser.container.appendChild(this._canvas.source);
  20893. }
  20894. this._first = true;
  20895. this.loop();
  20896. this._first = false;
  20897. }
  20898. createUI(x, y) {
  20899. var stat = this._sp;
  20900. var pixel = Browser.pixelRatio;
  20901. if (!stat) {
  20902. stat = new Sprite();
  20903. this._leftText = new Text();
  20904. this._leftText.pos(5, 5);
  20905. this._leftText.color = "#ffffff";
  20906. stat.addChild(this._leftText);
  20907. this._txt = new Text();
  20908. this._txt.pos(80 * pixel, 5);
  20909. this._txt.color = "#ffffff";
  20910. stat.addChild(this._txt);
  20911. this._sp = stat;
  20912. }
  20913. stat.pos(x, y);
  20914. var text = "";
  20915. for (var i = 0; i < this._view.length; i++) {
  20916. var one = this._view[i];
  20917. text += one.title + "\n";
  20918. }
  20919. this._leftText.text = text;
  20920. var width = pixel * 138;
  20921. var height = pixel * (this._view.length * 12 + 3 * pixel) + 4;
  20922. this._txt.fontSize = StatUI._fontSize * pixel;
  20923. this._leftText.fontSize = StatUI._fontSize * pixel;
  20924. stat.size(width, height);
  20925. stat.graphics.clear();
  20926. stat.graphics.alpha(0.5);
  20927. stat.graphics.drawRect(0, 0, width, height, "#999999");
  20928. stat.graphics.alpha(2);
  20929. this.loop();
  20930. }
  20931. enable() {
  20932. ILaya.systemTimer.frameLoop(1, this, this.loop);
  20933. }
  20934. hide() {
  20935. this._show = false;
  20936. ILaya.systemTimer.clear(this, this.loop);
  20937. if (this._canvas) {
  20938. Browser.removeElement(this._canvas.source);
  20939. }
  20940. }
  20941. set_onclick(fn) {
  20942. if (this._sp) {
  20943. this._sp.on("click", this._sp, fn);
  20944. }
  20945. if (this._canvas) {
  20946. this._canvas.source.onclick = fn;
  20947. this._canvas.source.style.pointerEvents = '';
  20948. }
  20949. }
  20950. loop() {
  20951. Stat._count++;
  20952. var timer = Browser.now();
  20953. if (timer - Stat._timer < 1000)
  20954. return;
  20955. var count = Stat._count;
  20956. Stat.FPS = Math.round((count * 1000) / (timer - Stat._timer));
  20957. if (this._show) {
  20958. Stat.trianglesFaces = Math.round(Stat.trianglesFaces / count);
  20959. if (!this._useCanvas) {
  20960. Stat.renderBatches = Math.round(Stat.renderBatches / count) - 1;
  20961. }
  20962. else {
  20963. Stat.renderBatches = Math.round(Stat.renderBatches / count);
  20964. }
  20965. Stat.savedRenderBatches = Math.round(Stat.savedRenderBatches / count);
  20966. Stat.shaderCall = Math.round(Stat.shaderCall / count);
  20967. Stat.spriteRenderUseCacheCount = Math.round(Stat.spriteRenderUseCacheCount / count);
  20968. Stat.canvasNormal = Math.round(Stat.canvasNormal / count);
  20969. Stat.canvasBitmap = Math.round(Stat.canvasBitmap / count);
  20970. Stat.canvasReCache = Math.ceil(Stat.canvasReCache / count);
  20971. Stat.frustumCulling = Math.round(Stat.frustumCulling / count);
  20972. Stat.octreeNodeCulling = Math.round(Stat.octreeNodeCulling / count);
  20973. var delay = Stat.FPS > 0 ? Math.floor(1000 / Stat.FPS).toString() : " ";
  20974. Stat._fpsStr = Stat.FPS + (Stat.renderSlow ? " slow" : "") + " " + delay;
  20975. Stat._spriteStr = Stat.spriteCount + (Stat.spriteRenderUseCacheCount ? ("/" + Stat.spriteRenderUseCacheCount) : '');
  20976. Stat._canvasStr = Stat.canvasReCache + "/" + Stat.canvasNormal + "/" + Stat.canvasBitmap;
  20977. Stat.cpuMemory = Resource.cpuMemory;
  20978. Stat.gpuMemory = Resource.gpuMemory;
  20979. if (this._useCanvas) {
  20980. this.renderInfoPre();
  20981. }
  20982. else
  20983. this.renderInfo();
  20984. Stat.clear();
  20985. }
  20986. Stat._count = 0;
  20987. Stat._timer = timer;
  20988. }
  20989. renderInfoPre() {
  20990. var i = 0;
  20991. var one;
  20992. var value;
  20993. if (this._canvas) {
  20994. var ctx = this._ctx;
  20995. ctx.clearRect(this._first ? 0 : this._vx, 0, this._width, this._height);
  20996. for (i = 0; i < this._view.length; i++) {
  20997. one = this._view[i];
  20998. if (this._first) {
  20999. ctx.fillStyle = "white";
  21000. ctx.fillText(one.title, one.x, one.y);
  21001. }
  21002. ctx.fillStyle = one.color;
  21003. value = Stat[one.value];
  21004. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21005. ctx.fillText(value + "", one.x + this._vx, one.y);
  21006. }
  21007. }
  21008. }
  21009. renderInfo() {
  21010. var text = "";
  21011. for (var i = 0; i < this._view.length; i++) {
  21012. var one = this._view[i];
  21013. var value = Stat[one.value];
  21014. (one.units == "M") && (value = Math.floor(value / (1024 * 1024) * 100) / 100 + " M");
  21015. (one.units == "K") && (value = Math.floor(value / (1024) * 100) / 100 + " K");
  21016. text += value + "\n";
  21017. }
  21018. this._txt.text = text;
  21019. }
  21020. isCanvasRender() {
  21021. return this._useCanvas;
  21022. }
  21023. renderNotCanvas(ctx, x, y) {
  21024. this._show && this._sp && this._sp.render(ctx, 0, 0);
  21025. }
  21026. }
  21027. StatUI._fontSize = 12;
  21028. class Timer {
  21029. constructor(autoActive = true) {
  21030. this.scale = 1;
  21031. this.currTimer = Date.now();
  21032. this.currFrame = 0;
  21033. this._delta = 0;
  21034. this._lastTimer = Date.now();
  21035. this._map = [];
  21036. this._handlers = [];
  21037. this._temp = [];
  21038. this._count = 0;
  21039. autoActive && Timer.gSysTimer && Timer.gSysTimer.frameLoop(1, this, this._update);
  21040. }
  21041. get delta() {
  21042. return this._delta;
  21043. }
  21044. _update() {
  21045. if (this.scale <= 0) {
  21046. this._lastTimer = Date.now();
  21047. this._delta = 0;
  21048. return;
  21049. }
  21050. var frame = this.currFrame = this.currFrame + this.scale;
  21051. var now = Date.now();
  21052. var awake = (now - this._lastTimer) > 30000;
  21053. this._delta = (now - this._lastTimer) * this.scale;
  21054. var timer = this.currTimer = this.currTimer + this._delta;
  21055. this._lastTimer = now;
  21056. var handlers = this._handlers;
  21057. this._count = 0;
  21058. for (var i = 0, n = handlers.length; i < n; i++) {
  21059. var handler = handlers[i];
  21060. if (handler.method !== null) {
  21061. var t = handler.userFrame ? frame : timer;
  21062. if (t >= handler.exeTime) {
  21063. if (handler.repeat) {
  21064. if (!handler.jumpFrame || awake) {
  21065. handler.exeTime += handler.delay;
  21066. handler.run(false);
  21067. if (t > handler.exeTime) {
  21068. handler.exeTime += Math.ceil((t - handler.exeTime) / handler.delay) * handler.delay;
  21069. }
  21070. }
  21071. else {
  21072. while (t >= handler.exeTime) {
  21073. handler.exeTime += handler.delay;
  21074. handler.run(false);
  21075. }
  21076. }
  21077. }
  21078. else {
  21079. handler.run(true);
  21080. }
  21081. }
  21082. }
  21083. else {
  21084. this._count++;
  21085. }
  21086. }
  21087. if (this._count > 30 || frame % 200 === 0)
  21088. this._clearHandlers();
  21089. }
  21090. _clearHandlers() {
  21091. var handlers = this._handlers;
  21092. for (var i = 0, n = handlers.length; i < n; i++) {
  21093. var handler = handlers[i];
  21094. if (handler.method !== null)
  21095. this._temp.push(handler);
  21096. else
  21097. this._recoverHandler(handler);
  21098. }
  21099. this._handlers = this._temp;
  21100. handlers.length = 0;
  21101. this._temp = handlers;
  21102. }
  21103. _recoverHandler(handler) {
  21104. if (this._map[handler.key] == handler)
  21105. this._map[handler.key] = null;
  21106. handler.clear();
  21107. Timer._pool.push(handler);
  21108. }
  21109. _create(useFrame, repeat, delay, caller, method, args, coverBefore) {
  21110. if (!delay) {
  21111. method.apply(caller, args);
  21112. return null;
  21113. }
  21114. if (coverBefore) {
  21115. var handler = this._getHandler(caller, method);
  21116. if (handler) {
  21117. handler.repeat = repeat;
  21118. handler.userFrame = useFrame;
  21119. handler.delay = delay;
  21120. handler.caller = caller;
  21121. handler.method = method;
  21122. handler.args = args;
  21123. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21124. return handler;
  21125. }
  21126. }
  21127. handler = Timer._pool.length > 0 ? Timer._pool.pop() : new TimerHandler();
  21128. handler.repeat = repeat;
  21129. handler.userFrame = useFrame;
  21130. handler.delay = delay;
  21131. handler.caller = caller;
  21132. handler.method = method;
  21133. handler.args = args;
  21134. handler.exeTime = delay + (useFrame ? this.currFrame : this.currTimer + Date.now() - this._lastTimer);
  21135. this._indexHandler(handler);
  21136. this._handlers.push(handler);
  21137. return handler;
  21138. }
  21139. _indexHandler(handler) {
  21140. var caller = handler.caller;
  21141. var method = handler.method;
  21142. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21143. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21144. handler.key = cid + mid;
  21145. this._map[handler.key] = handler;
  21146. }
  21147. once(delay, caller, method, args = null, coverBefore = true) {
  21148. this._create(false, false, delay, caller, method, args, coverBefore);
  21149. }
  21150. loop(delay, caller, method, args = null, coverBefore = true, jumpFrame = false) {
  21151. var handler = this._create(false, true, delay, caller, method, args, coverBefore);
  21152. if (handler)
  21153. handler.jumpFrame = jumpFrame;
  21154. }
  21155. frameOnce(delay, caller, method, args = null, coverBefore = true) {
  21156. this._create(true, false, delay, caller, method, args, coverBefore);
  21157. }
  21158. frameLoop(delay, caller, method, args = null, coverBefore = true) {
  21159. this._create(true, true, delay, caller, method, args, coverBefore);
  21160. }
  21161. toString() {
  21162. return " handlers:" + this._handlers.length + " pool:" + Timer._pool.length;
  21163. }
  21164. clear(caller, method) {
  21165. var handler = this._getHandler(caller, method);
  21166. if (handler) {
  21167. this._map[handler.key] = null;
  21168. handler.key = 0;
  21169. handler.clear();
  21170. }
  21171. }
  21172. clearAll(caller) {
  21173. if (!caller)
  21174. return;
  21175. for (var i = 0, n = this._handlers.length; i < n; i++) {
  21176. var handler = this._handlers[i];
  21177. if (handler.caller === caller) {
  21178. this._map[handler.key] = null;
  21179. handler.key = 0;
  21180. handler.clear();
  21181. }
  21182. }
  21183. }
  21184. _getHandler(caller, method) {
  21185. var cid = caller ? caller.$_GID || (caller.$_GID = ILaya.Utils.getGID()) : 0;
  21186. var mid = method.$_TID || (method.$_TID = (Timer._mid++) * 100000);
  21187. return this._map[cid + mid];
  21188. }
  21189. callLater(caller, method, args = null) {
  21190. CallLater.I.callLater(caller, method, args);
  21191. }
  21192. runCallLater(caller, method) {
  21193. CallLater.I.runCallLater(caller, method);
  21194. }
  21195. runTimer(caller, method) {
  21196. var handler = this._getHandler(caller, method);
  21197. if (handler && handler.method != null) {
  21198. this._map[handler.key] = null;
  21199. handler.run(true);
  21200. }
  21201. }
  21202. pause() {
  21203. this.scale = 0;
  21204. }
  21205. resume() {
  21206. this.scale = 1;
  21207. }
  21208. }
  21209. Timer.gSysTimer = null;
  21210. Timer._pool = [];
  21211. Timer._mid = 1;
  21212. class TimerHandler {
  21213. clear() {
  21214. this.caller = null;
  21215. this.method = null;
  21216. this.args = null;
  21217. }
  21218. run(withClear) {
  21219. var caller = this.caller;
  21220. if (caller && caller.destroyed)
  21221. return this.clear();
  21222. var method = this.method;
  21223. var args = this.args;
  21224. withClear && this.clear();
  21225. if (method == null)
  21226. return;
  21227. args ? method.apply(caller, args) : method.call(caller);
  21228. }
  21229. }
  21230. class SkinSV extends Value2D {
  21231. constructor(type) {
  21232. super(ShaderDefines2D.SKINMESH, 0);
  21233. this.offsetX = 300;
  21234. this.offsetY = 0;
  21235. var gl = WebGLContext.mainContext;
  21236. var _vlen = 8 * CONST3D2D.BYTES_PE;
  21237. this.position = [2, gl.FLOAT, false, _vlen, 0];
  21238. this.texcoord = [2, gl.FLOAT, false, _vlen, 2 * CONST3D2D.BYTES_PE];
  21239. this.color = [4, gl.FLOAT, false, _vlen, 4 * CONST3D2D.BYTES_PE];
  21240. }
  21241. }
  21242. class PrimitiveSV extends Value2D {
  21243. constructor(args) {
  21244. super(ShaderDefines2D.PRIMITIVE, 0);
  21245. this._attribLocation = ['position', 0, 'attribColor', 1];
  21246. }
  21247. }
  21248. class TextureSV extends Value2D {
  21249. constructor(subID = 0) {
  21250. super(ShaderDefines2D.TEXTURE2D, subID);
  21251. this.strength = 0;
  21252. this.blurInfo = null;
  21253. this.colorMat = null;
  21254. this.colorAlpha = null;
  21255. this._attribLocation = ['posuv', 0, 'attribColor', 1, 'attribFlags', 2];
  21256. }
  21257. clear() {
  21258. this.texture = null;
  21259. this.shader = null;
  21260. this.defines._value = this.subID + (WebGL.shaderHighPrecision ? ShaderDefines2D.SHADERDEFINE_FSHIGHPRECISION : 0);
  21261. }
  21262. }
  21263. class InlcudeFile {
  21264. constructor(txt) {
  21265. this.codes = {};
  21266. this.funs = {};
  21267. this.curUseID = -1;
  21268. this.funnames = "";
  21269. this.script = txt;
  21270. var begin = 0, ofs, end;
  21271. while (true) {
  21272. begin = txt.indexOf("#begin", begin);
  21273. if (begin < 0)
  21274. break;
  21275. end = begin + 5;
  21276. while (true) {
  21277. end = txt.indexOf("#end", end);
  21278. if (end < 0)
  21279. break;
  21280. if (txt.charAt(end + 4) === 'i')
  21281. end += 5;
  21282. else
  21283. break;
  21284. }
  21285. if (end < 0) {
  21286. throw "add include err,no #end:" + txt;
  21287. }
  21288. ofs = txt.indexOf('\n', begin);
  21289. var words = ILaya.ShaderCompile.splitToWords(txt.substr(begin, ofs - begin), null);
  21290. if (words[1] == 'code') {
  21291. this.codes[words[2]] = txt.substr(ofs + 1, end - ofs - 1);
  21292. }
  21293. else if (words[1] == 'function') {
  21294. ofs = txt.indexOf("function", begin);
  21295. ofs += "function".length;
  21296. this.funs[words[3]] = txt.substr(ofs + 1, end - ofs - 1);
  21297. this.funnames += words[3] + ";";
  21298. }
  21299. begin = end + 1;
  21300. }
  21301. }
  21302. getWith(name = null) {
  21303. var r = name ? this.codes[name] : this.script;
  21304. if (!r) {
  21305. throw "get with error:" + name;
  21306. }
  21307. return r;
  21308. }
  21309. getFunsScript(funsdef) {
  21310. var r = "";
  21311. for (var i in this.funs) {
  21312. if (funsdef.indexOf(i + ";") >= 0) {
  21313. r += this.funs[i];
  21314. }
  21315. }
  21316. return r;
  21317. }
  21318. }
  21319. class ShaderNode {
  21320. constructor(includefiles) {
  21321. this.childs = [];
  21322. this.text = "";
  21323. this.useFuns = "";
  21324. this.z = 0;
  21325. this.includefiles = includefiles;
  21326. }
  21327. setParent(parent) {
  21328. parent.childs.push(this);
  21329. this.z = parent.z + 1;
  21330. this.parent = parent;
  21331. }
  21332. setCondition(condition, type) {
  21333. if (condition) {
  21334. this.conditionType = type;
  21335. condition = condition.replace(/(\s*$)/g, "");
  21336. this.condition = function () {
  21337. return this[condition];
  21338. };
  21339. this.condition.__condition = condition;
  21340. }
  21341. }
  21342. toscript(def, out) {
  21343. return this._toscript(def, out, ++ShaderNode.__id);
  21344. }
  21345. _toscript(def, out, id) {
  21346. if (this.childs.length < 1 && !this.text)
  21347. return out;
  21348. var outIndex = out.length;
  21349. if (this.condition) {
  21350. var ifdef = !!this.condition.call(def);
  21351. this.conditionType === ILaya.ShaderCompile.IFDEF_ELSE && (ifdef = !ifdef);
  21352. if (!ifdef)
  21353. return out;
  21354. }
  21355. this.text && out.push(this.text);
  21356. this.childs.length > 0 && this.childs.forEach(function (o, index, arr) {
  21357. o._toscript(def, out, id);
  21358. });
  21359. if (this.includefiles.length > 0 && this.useFuns.length > 0) {
  21360. var funsCode;
  21361. for (var i = 0, n = this.includefiles.length; i < n; i++) {
  21362. if (this.includefiles[i].curUseID == id) {
  21363. continue;
  21364. }
  21365. funsCode = this.includefiles[i].file.getFunsScript(this.useFuns);
  21366. if (funsCode.length > 0) {
  21367. this.includefiles[i].curUseID = id;
  21368. out[0] = funsCode + out[0];
  21369. }
  21370. }
  21371. }
  21372. return out;
  21373. }
  21374. }
  21375. ShaderNode.__id = 1;
  21376. class ShaderCompile {
  21377. constructor(vs, ps, nameMap) {
  21378. this.defs = {};
  21379. let _this = this;
  21380. function _compile(script) {
  21381. script = script.replace(ShaderCompile._clearCR, "");
  21382. var includefiles = [];
  21383. var top = new ShaderNode(includefiles);
  21384. _this._compileToTree(top, script.split('\n'), 0, includefiles, _this.defs);
  21385. return top;
  21386. }
  21387. var startTime = Date.now();
  21388. this._VS = _compile(vs);
  21389. this._PS = _compile(ps);
  21390. this._nameMap = nameMap;
  21391. if ((Date.now() - startTime) > 2)
  21392. console.log("ShaderCompile use time:" + (Date.now() - startTime) + " size:" + vs.length + "/" + ps.length);
  21393. }
  21394. static __init__() {
  21395. var gl = LayaGL.instance;
  21396. 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 };
  21397. }
  21398. static _parseOne(attributes, uniforms, words, i, word, b) {
  21399. var one = { type: ShaderCompile.shaderParamsMap[words[i + 1]], name: words[i + 2], size: isNaN(parseInt(words[i + 3])) ? 1 : parseInt(words[i + 3]) };
  21400. if (b) {
  21401. if (word == "attribute") {
  21402. attributes.push(one);
  21403. }
  21404. else {
  21405. uniforms.push(one);
  21406. }
  21407. }
  21408. if (words[i + 3] == ':') {
  21409. one.type = words[i + 4];
  21410. i += 2;
  21411. }
  21412. i += 2;
  21413. return i;
  21414. }
  21415. static addInclude(fileName, txt) {
  21416. if (!txt || txt.length === 0)
  21417. throw new Error("add shader include file err:" + fileName);
  21418. if (ShaderCompile.includes[fileName])
  21419. throw new Error("add shader include file err, has add:" + fileName);
  21420. ShaderCompile.includes[fileName] = new InlcudeFile(txt);
  21421. }
  21422. static preGetParams(vs, ps) {
  21423. var text = [vs, ps];
  21424. var result = {};
  21425. var attributes = [];
  21426. var uniforms = [];
  21427. var definesInfo = {};
  21428. var definesName = [];
  21429. result.attributes = attributes;
  21430. result.uniforms = uniforms;
  21431. result.defines = definesInfo;
  21432. var i, n;
  21433. for (var s = 0; s < 2; s++) {
  21434. text[s] = text[s].replace(ShaderCompile._removeAnnotation, "");
  21435. var words = text[s].match(ShaderCompile._reg);
  21436. var tempelse;
  21437. for (i = 0, n = words.length; i < n; i++) {
  21438. var word = words[i];
  21439. if (word != "attribute" && word != "uniform") {
  21440. if (word == "#define") {
  21441. word = words[++i];
  21442. definesName[word] = 1;
  21443. continue;
  21444. }
  21445. else if (word == "#ifdef") {
  21446. tempelse = words[++i];
  21447. var def = definesInfo[tempelse] = definesInfo[tempelse] || [];
  21448. for (i++; i < n; i++) {
  21449. word = words[i];
  21450. if (word != "attribute" && word != "uniform") {
  21451. if (word == "#else") {
  21452. for (i++; i < n; i++) {
  21453. word = words[i];
  21454. if (word != "attribute" && word != "uniform") {
  21455. if (word == "#endif") {
  21456. break;
  21457. }
  21458. continue;
  21459. }
  21460. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, !definesName[tempelse]);
  21461. }
  21462. }
  21463. continue;
  21464. }
  21465. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, definesName[tempelse]);
  21466. }
  21467. }
  21468. continue;
  21469. }
  21470. i = ShaderCompile._parseOne(attributes, uniforms, words, i, word, true);
  21471. }
  21472. }
  21473. return result;
  21474. }
  21475. static splitToWords(str, block) {
  21476. var out = [];
  21477. var c;
  21478. var ofs = -1;
  21479. var word;
  21480. for (var i = 0, n = str.length; i < n; i++) {
  21481. c = str.charAt(i);
  21482. if (" \t=+-*/&%!<>()'\",;".indexOf(c) >= 0) {
  21483. if (ofs >= 0 && (i - ofs) > 1) {
  21484. word = str.substr(ofs, i - ofs);
  21485. out.push(word);
  21486. }
  21487. if (c == '"' || c == "'") {
  21488. var ofs2 = str.indexOf(c, i + 1);
  21489. if (ofs2 < 0) {
  21490. throw "Sharder err:" + str;
  21491. }
  21492. out.push(str.substr(i + 1, ofs2 - i - 1));
  21493. i = ofs2;
  21494. ofs = -1;
  21495. continue;
  21496. }
  21497. if (c == '(' && block && out.length > 0) {
  21498. word = out[out.length - 1] + ";";
  21499. if ("vec4;main;".indexOf(word) < 0)
  21500. block.useFuns += word;
  21501. }
  21502. ofs = -1;
  21503. continue;
  21504. }
  21505. if (ofs < 0)
  21506. ofs = i;
  21507. }
  21508. if (ofs < n && (n - ofs) > 1) {
  21509. word = str.substr(ofs, n - ofs);
  21510. out.push(word);
  21511. }
  21512. return out;
  21513. }
  21514. _compileToTree(parent, lines, start, includefiles, defs) {
  21515. var node, preNode;
  21516. var text, name, fname;
  21517. var ofs, words, noUseNode;
  21518. var i, n, j;
  21519. for (i = start; i < lines.length; i++) {
  21520. text = lines[i];
  21521. if (text.length < 1)
  21522. continue;
  21523. ofs = text.indexOf("//");
  21524. if (ofs === 0)
  21525. continue;
  21526. if (ofs >= 0)
  21527. text = text.substr(0, ofs);
  21528. node = noUseNode || new ShaderNode(includefiles);
  21529. noUseNode = null;
  21530. node.text = text;
  21531. node.noCompile = true;
  21532. if ((ofs = text.indexOf("#")) >= 0) {
  21533. name = "#";
  21534. for (j = ofs + 1, n = text.length; j < n; j++) {
  21535. var c = text.charAt(j);
  21536. if (c === ' ' || c === '\t' || c === '?')
  21537. break;
  21538. name += c;
  21539. }
  21540. node.name = name;
  21541. switch (name) {
  21542. case "#ifdef":
  21543. case "#ifndef":
  21544. node.src = text;
  21545. node.noCompile = text.match(/[!&|()=<>]/) != null;
  21546. if (!node.noCompile) {
  21547. words = text.replace(/^\s*/, '').split(/\s+/);
  21548. node.setCondition(words[1], name === "#ifdef" ? ShaderCompile.IFDEF_YES : ShaderCompile.IFDEF_ELSE);
  21549. node.text = "//" + node.text;
  21550. }
  21551. else {
  21552. console.log("function():Boolean{return " + text.substr(ofs + node.name.length) + "}");
  21553. }
  21554. node.setParent(parent);
  21555. parent = node;
  21556. if (defs) {
  21557. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21558. for (j = 0; j < words.length; j++) {
  21559. text = words[j];
  21560. text.length && (defs[text] = true);
  21561. }
  21562. }
  21563. continue;
  21564. case "#if":
  21565. node.src = text;
  21566. node.noCompile = true;
  21567. node.setParent(parent);
  21568. parent = node;
  21569. if (defs) {
  21570. words = text.substr(j).split(ShaderCompile._splitToWordExps3);
  21571. for (j = 0; j < words.length; j++) {
  21572. text = words[j];
  21573. text.length && text != "defined" && (defs[text] = true);
  21574. }
  21575. }
  21576. continue;
  21577. case "#else":
  21578. node.src = text;
  21579. parent = parent.parent;
  21580. preNode = parent.childs[parent.childs.length - 1];
  21581. node.noCompile = preNode.noCompile;
  21582. if (!node.noCompile) {
  21583. node.condition = preNode.condition;
  21584. node.conditionType = preNode.conditionType == ShaderCompile.IFDEF_YES ? ShaderCompile.IFDEF_ELSE : ShaderCompile.IFDEF_YES;
  21585. node.text = "//" + node.text + " " + preNode.text + " " + node.conditionType;
  21586. }
  21587. node.setParent(parent);
  21588. parent = node;
  21589. continue;
  21590. case "#endif":
  21591. parent = parent.parent;
  21592. preNode = parent.childs[parent.childs.length - 1];
  21593. node.noCompile = preNode.noCompile;
  21594. if (!node.noCompile) {
  21595. node.text = "//" + node.text;
  21596. }
  21597. node.setParent(parent);
  21598. continue;
  21599. case "#include":
  21600. words = ShaderCompile.splitToWords(text, null);
  21601. var inlcudeFile = ShaderCompile.includes[words[1]];
  21602. if (!inlcudeFile) {
  21603. throw "ShaderCompile error no this include file:" + words[1];
  21604. }
  21605. if ((ofs = words[0].indexOf("?")) < 0) {
  21606. node.setParent(parent);
  21607. text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21608. this._compileToTree(node, text.split('\n'), 0, includefiles, defs);
  21609. node.text = "";
  21610. continue;
  21611. }
  21612. node.setCondition(words[0].substr(ofs + 1), ShaderCompile.IFDEF_YES);
  21613. node.text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  21614. break;
  21615. case "#import":
  21616. words = ShaderCompile.splitToWords(text, null);
  21617. fname = words[1];
  21618. includefiles.push({ node: node, file: ShaderCompile.includes[fname], ofs: node.text.length });
  21619. continue;
  21620. }
  21621. }
  21622. else {
  21623. preNode = parent.childs[parent.childs.length - 1];
  21624. if (preNode && !preNode.name) {
  21625. includefiles.length > 0 && ShaderCompile.splitToWords(text, preNode);
  21626. noUseNode = node;
  21627. preNode.text += "\n" + text;
  21628. continue;
  21629. }
  21630. includefiles.length > 0 && ShaderCompile.splitToWords(text, node);
  21631. }
  21632. node.setParent(parent);
  21633. }
  21634. }
  21635. createShader(define, shaderName, createShader, bindAttrib) {
  21636. var defMap = {};
  21637. var defineStr = "";
  21638. if (define) {
  21639. for (var i in define) {
  21640. defineStr += "#define " + i + "\n";
  21641. defMap[i] = true;
  21642. }
  21643. }
  21644. var vs = this._VS.toscript(defMap, []);
  21645. var ps = this._PS.toscript(defMap, []);
  21646. return (createShader || Shader.create)(defineStr + vs.join('\n'), defineStr + ps.join('\n'), shaderName, this._nameMap, bindAttrib);
  21647. }
  21648. }
  21649. ShaderCompile.IFDEF_NO = 0;
  21650. ShaderCompile.IFDEF_YES = 1;
  21651. ShaderCompile.IFDEF_ELSE = 2;
  21652. ShaderCompile.IFDEF_PARENT = 3;
  21653. ShaderCompile._removeAnnotation = new RegExp("(/\\*([^*]|[\\r\\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/)|(//.*)", "g");
  21654. ShaderCompile._reg = new RegExp("(\".*\")|('.*')|([#\\w\\*-\\.+/()=<>{}\\\\]+)|([,;:\\\\])", "g");
  21655. ShaderCompile._splitToWordExps = new RegExp("[(\".*\")]+|[('.*')]+|([ \\t=\\+\\-*/&%!<>!%\(\),;])", "g");
  21656. ShaderCompile.includes = {};
  21657. ShaderCompile._clearCR = new RegExp("\r", "g");
  21658. ShaderCompile._splitToWordExps3 = new RegExp("[ \\t=\\+\\-*/&%!<>!%\(\),;\\|]", "g");
  21659. class WorkerLoader extends EventDispatcher {
  21660. constructor() {
  21661. super();
  21662. this.worker = new Worker(WorkerLoader.workerPath);
  21663. let me = this;
  21664. this.worker.onmessage = function (evt) {
  21665. me.workerMessage(evt.data);
  21666. };
  21667. }
  21668. static __init__() {
  21669. if (WorkerLoader._preLoadFun != null)
  21670. return false;
  21671. if (!Worker)
  21672. return false;
  21673. WorkerLoader._preLoadFun = Loader["prototype"]["_loadImage"];
  21674. Loader["prototype"]["_loadImage"] = WorkerLoader["prototype"]["_loadImage"];
  21675. if (!WorkerLoader.I)
  21676. WorkerLoader.I = new WorkerLoader();
  21677. return true;
  21678. }
  21679. static workerSupported() {
  21680. return Worker ? true : false;
  21681. }
  21682. static enableWorkerLoader() {
  21683. if (!WorkerLoader._tryEnabled) {
  21684. WorkerLoader.enable = true;
  21685. WorkerLoader._tryEnabled = true;
  21686. }
  21687. }
  21688. static set enable(value) {
  21689. if (WorkerLoader._enable != value) {
  21690. WorkerLoader._enable = value;
  21691. if (value && WorkerLoader._preLoadFun == null)
  21692. WorkerLoader._enable = WorkerLoader.__init__();
  21693. }
  21694. }
  21695. static get enable() {
  21696. return WorkerLoader._enable;
  21697. }
  21698. workerMessage(data) {
  21699. if (data) {
  21700. switch (data.type) {
  21701. case "Image":
  21702. this.imageLoaded(data);
  21703. break;
  21704. case "Disable":
  21705. WorkerLoader.enable = false;
  21706. break;
  21707. }
  21708. }
  21709. }
  21710. imageLoaded(data) {
  21711. if (!data.dataType || data.dataType != "imageBitmap") {
  21712. this.event(data.url, null);
  21713. return;
  21714. }
  21715. var imageData = data.imageBitmap;
  21716. var tex = new Texture2D();
  21717. tex.loadImageSource(imageData);
  21718. console.log("load:", data.url);
  21719. this.event(data.url, tex);
  21720. }
  21721. loadImage(url) {
  21722. this.worker.postMessage(url);
  21723. }
  21724. _loadImage(url) {
  21725. var _this = this;
  21726. if (!this._useWorkerLoader || !WorkerLoader._enable) {
  21727. WorkerLoader._preLoadFun.call(_this, url);
  21728. return;
  21729. }
  21730. url = URL.formatURL(url);
  21731. function clear() {
  21732. WorkerLoader.I.off(url, _this, onload);
  21733. }
  21734. var onload = function (image) {
  21735. clear();
  21736. if (image) {
  21737. _this["onLoaded"](image);
  21738. }
  21739. else {
  21740. WorkerLoader._preLoadFun.call(_this, url);
  21741. }
  21742. };
  21743. WorkerLoader.I.on(url, _this, onload);
  21744. WorkerLoader.I.loadImage(url);
  21745. }
  21746. }
  21747. WorkerLoader.workerPath = "libs/workerloader.js";
  21748. WorkerLoader._enable = false;
  21749. WorkerLoader._tryEnabled = false;
  21750. class Mouse {
  21751. static set cursor(cursorStr) {
  21752. Mouse._style.cursor = cursorStr;
  21753. }
  21754. static get cursor() {
  21755. return Mouse._style.cursor;
  21756. }
  21757. static __init__() {
  21758. }
  21759. static hide() {
  21760. if (Mouse.cursor != "none") {
  21761. Mouse._preCursor = Mouse.cursor;
  21762. Mouse.cursor = "none";
  21763. }
  21764. }
  21765. static show() {
  21766. if (Mouse.cursor == "none") {
  21767. if (Mouse._preCursor) {
  21768. Mouse.cursor = Mouse._preCursor;
  21769. }
  21770. else {
  21771. Mouse.cursor = "auto";
  21772. }
  21773. }
  21774. }
  21775. }
  21776. class MeshParticle2D extends Mesh2D {
  21777. constructor(maxNum) {
  21778. super(MeshParticle2D.const_stride, maxNum * 4 * MeshParticle2D.const_stride, 4);
  21779. this.canReuse = true;
  21780. this.setAttributes(MeshParticle2D._fixattriInfo);
  21781. this.createQuadIB(maxNum);
  21782. this._quadNum = maxNum;
  21783. }
  21784. static __init__() {
  21785. var gl = LayaGL.instance;
  21786. MeshParticle2D._fixattriInfo = [gl.FLOAT, 4, 0,
  21787. gl.FLOAT, 3, 16,
  21788. gl.FLOAT, 3, 28,
  21789. gl.FLOAT, 4, 40,
  21790. gl.FLOAT, 4, 56,
  21791. gl.FLOAT, 3, 72,
  21792. gl.FLOAT, 2, 84,
  21793. gl.FLOAT, 4, 92,
  21794. gl.FLOAT, 1, 108,
  21795. gl.FLOAT, 1, 112];
  21796. }
  21797. setMaxParticleNum(maxNum) {
  21798. this._vb._resizeBuffer(maxNum * 4 * MeshParticle2D.const_stride, false);
  21799. this.createQuadIB(maxNum);
  21800. }
  21801. static getAMesh(maxNum) {
  21802. if (MeshParticle2D._POOL.length) {
  21803. var ret = MeshParticle2D._POOL.pop();
  21804. ret.setMaxParticleNum(maxNum);
  21805. return ret;
  21806. }
  21807. return new MeshParticle2D(maxNum);
  21808. }
  21809. releaseMesh() {
  21810. this._vb.setByteLength(0);
  21811. this.vertNum = 0;
  21812. this.indexNum = 0;
  21813. MeshParticle2D._POOL.push(this);
  21814. }
  21815. destroy() {
  21816. this._ib.destroy();
  21817. this._vb.destroy();
  21818. this._vb.deleteBuffer();
  21819. }
  21820. }
  21821. MeshParticle2D.const_stride = 116;
  21822. MeshParticle2D._POOL = [];
  21823. class HTMLImage extends Bitmap {
  21824. }
  21825. HTMLImage.create = function (width, height, format) {
  21826. var tex = new Texture2D(width, height, format, false, false);
  21827. tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
  21828. tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
  21829. return tex;
  21830. };
  21831. class Laya {
  21832. static __init(_classs) {
  21833. _classs.forEach(function (o) { o.__init$ && o.__init$(); });
  21834. }
  21835. static init(width, height, ...plugins) {
  21836. if (Laya._isinit)
  21837. return;
  21838. Laya._isinit = true;
  21839. ArrayBuffer.prototype.slice || (ArrayBuffer.prototype.slice = Laya._arrayBufferSlice);
  21840. Browser.__init__();
  21841. var mainCanv = Browser.mainCanvas = new HTMLCanvas(true);
  21842. var style = mainCanv.source.style;
  21843. style.position = 'absolute';
  21844. style.top = style.left = "0px";
  21845. style.background = "#000000";
  21846. if (!Browser.onKGMiniGame && !Browser.onAlipayMiniGame) {
  21847. Browser.container.appendChild(mainCanv.source);
  21848. }
  21849. Browser.canvas = new HTMLCanvas(true);
  21850. Browser.context = Browser.canvas.getContext('2d');
  21851. Browser.supportWebAudio = SoundManager.__init__();
  21852. Browser.supportLocalStorage = LocalStorage.__init__();
  21853. Laya.systemTimer = new Timer(false);
  21854. exports.systemTimer = Timer.gSysTimer = Laya.systemTimer;
  21855. Laya.startTimer = new Timer(false);
  21856. Laya.physicsTimer = new Timer(false);
  21857. Laya.updateTimer = new Timer(false);
  21858. Laya.lateTimer = new Timer(false);
  21859. Laya.timer = new Timer(false);
  21860. exports.startTimer = ILaya.startTimer = Laya.startTimer;
  21861. exports.lateTimer = ILaya.lateTimer = Laya.lateTimer;
  21862. exports.updateTimer = ILaya.updateTimer = Laya.updateTimer;
  21863. ILaya.systemTimer = Laya.systemTimer;
  21864. exports.timer = ILaya.timer = Laya.timer;
  21865. exports.physicsTimer = ILaya.physicsTimer = Laya.physicsTimer;
  21866. Laya.loader = new LoaderManager();
  21867. ILaya.Laya = Laya;
  21868. exports.loader = ILaya.loader = Laya.loader;
  21869. WeakObject.__init__();
  21870. SceneUtils.__init();
  21871. Mouse.__init__();
  21872. WebGL.inner_enable();
  21873. for (var i = 0, n = plugins.length; i < n; i++) {
  21874. if (plugins[i] && plugins[i].enable) {
  21875. plugins[i].enable();
  21876. }
  21877. }
  21878. if (ILaya.Render.isConchApp) {
  21879. Laya.enableNative();
  21880. }
  21881. Laya.enableWebGLPlus();
  21882. CacheManger.beginCheck();
  21883. exports.stage = Laya.stage = new Stage();
  21884. ILaya.stage = Laya.stage;
  21885. Utils.gStage = Laya.stage;
  21886. URL.rootPath = URL._basePath = Laya._getUrlPath();
  21887. MeshQuadTexture.__int__();
  21888. MeshVG.__init__();
  21889. MeshTexture.__init__();
  21890. Laya.render = new Render(0, 0, Browser.mainCanvas);
  21891. exports.render = Laya.render;
  21892. Laya.stage.size(width, height);
  21893. window.stage = Laya.stage;
  21894. WebGLContext.__init__();
  21895. MeshParticle2D.__init__();
  21896. ShaderCompile.__init__();
  21897. RenderSprite.__init__();
  21898. KeyBoardManager.__init__();
  21899. MouseManager.instance.__init__(Laya.stage, Render.canvas);
  21900. Input.__init__();
  21901. SoundManager.autoStopMusic = true;
  21902. Stat._StatRender = new StatUI();
  21903. Value2D._initone(ShaderDefines2D.TEXTURE2D, TextureSV);
  21904. Value2D._initone(ShaderDefines2D.TEXTURE2D | ShaderDefines2D.FILTERGLOW, TextureSV);
  21905. Value2D._initone(ShaderDefines2D.PRIMITIVE, PrimitiveSV);
  21906. Value2D._initone(ShaderDefines2D.SKINMESH, SkinSV);
  21907. return Render.canvas;
  21908. }
  21909. static _getUrlPath() {
  21910. var location = Browser.window.location;
  21911. var pathName = location.pathname;
  21912. pathName = pathName.charAt(2) == ':' ? pathName.substring(1) : pathName;
  21913. return URL.getPath(location.protocol == "file:" ? pathName : location.protocol + "//" + location.host + location.pathname);
  21914. }
  21915. static _arrayBufferSlice(start, end) {
  21916. var arr = this;
  21917. var arrU8List = new Uint8Array(arr, start, end - start);
  21918. var newU8List = new Uint8Array(arrU8List.length);
  21919. newU8List.set(arrU8List);
  21920. return newU8List.buffer;
  21921. }
  21922. static set alertGlobalError(value) {
  21923. var erralert = 0;
  21924. if (value) {
  21925. Browser.window.onerror = function (msg, url, line, column, detail) {
  21926. if (erralert++ < 5 && detail)
  21927. this.alert("出错啦,请把此信息截图给研发商\n" + msg + "\n" + detail.stack);
  21928. };
  21929. }
  21930. else {
  21931. Browser.window.onerror = null;
  21932. }
  21933. }
  21934. static _runScript(script) {
  21935. return Browser.window[Laya._evcode](script);
  21936. }
  21937. static enableDebugPanel(debugJsPath = "libs/laya.debugtool.js") {
  21938. if (!Laya["DebugPanel"]) {
  21939. var script = Browser.createElement("script");
  21940. script.onload = function () {
  21941. Laya["DebugPanel"].enable();
  21942. };
  21943. script.src = debugJsPath;
  21944. Browser.document.body.appendChild(script);
  21945. }
  21946. else {
  21947. Laya["DebugPanel"].enable();
  21948. }
  21949. }
  21950. static enableWebGLPlus() {
  21951. WebGLContext.__init_native();
  21952. }
  21953. static enableNative() {
  21954. if (Laya.isNativeRender_enable)
  21955. return;
  21956. Laya.isNativeRender_enable = true;
  21957. Shader.prototype.uploadTexture2D = function (value) {
  21958. var gl = LayaGL.instance;
  21959. gl.bindTexture(gl.TEXTURE_2D, value);
  21960. };
  21961. RenderState2D.width = Browser.window.innerWidth;
  21962. RenderState2D.height = Browser.window.innerHeight;
  21963. Browser.measureText = function (txt, font) {
  21964. window["conchTextCanvas"].font = font;
  21965. return window["conchTextCanvas"].measureText(txt);
  21966. };
  21967. Stage.clear = function (color) {
  21968. Context.set2DRenderConfig();
  21969. var c = ColorUtils.create(color).arrColor;
  21970. var gl = LayaGL.instance;
  21971. if (c)
  21972. gl.clearColor(c[0], c[1], c[2], c[3]);
  21973. gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
  21974. RenderState2D.clear();
  21975. };
  21976. Sprite.drawToCanvas = Sprite.drawToTexture = function (sprite, _renderType, canvasWidth, canvasHeight, offsetX, offsetY) {
  21977. offsetX -= sprite.x;
  21978. offsetY -= sprite.y;
  21979. offsetX |= 0;
  21980. offsetY |= 0;
  21981. canvasWidth |= 0;
  21982. canvasHeight |= 0;
  21983. var canv = new HTMLCanvas(false);
  21984. var ctx = canv.getContext('2d');
  21985. canv.size(canvasWidth, canvasHeight);
  21986. ctx.asBitmap = true;
  21987. ctx._targets.start();
  21988. RenderSprite.renders[_renderType]._fun(sprite, ctx, offsetX, offsetY);
  21989. ctx.flush();
  21990. ctx._targets.end();
  21991. ctx._targets.restore();
  21992. return canv;
  21993. };
  21994. Object["defineProperty"](RenderTexture2D.prototype, "uv", {
  21995. "get": function () {
  21996. return this._uv;
  21997. },
  21998. "set": function (v) {
  21999. this._uv = v;
  22000. }
  22001. });
  22002. HTMLCanvas.prototype.getTexture = function () {
  22003. if (!this._texture) {
  22004. this._texture = this.context._targets;
  22005. this._texture.uv = RenderTexture2D.flipyuv;
  22006. this._texture.bitmap = this._texture;
  22007. }
  22008. return this._texture;
  22009. };
  22010. }
  22011. }
  22012. Laya.stage = null;
  22013. Laya.systemTimer = null;
  22014. Laya.startTimer = null;
  22015. Laya.physicsTimer = null;
  22016. Laya.updateTimer = null;
  22017. Laya.lateTimer = null;
  22018. Laya.timer = null;
  22019. Laya.loader = null;
  22020. Laya.version = "2.2.0";
  22021. Laya._isinit = false;
  22022. Laya.isWXOpenDataContext = false;
  22023. Laya.isWXPosMsg = false;
  22024. Laya.__classmap = null;
  22025. Laya.Config = Config;
  22026. Laya.TextRender = TextRender;
  22027. Laya.EventDispatcher = EventDispatcher;
  22028. Laya.SoundChannel = SoundChannel;
  22029. Laya.Stage = Stage;
  22030. Laya.Render = Render;
  22031. Laya.Browser = Browser;
  22032. Laya.Sprite = Sprite;
  22033. Laya.Node = Node;
  22034. Laya.Context = Context;
  22035. Laya.WebGL = WebGL;
  22036. Laya.Handler = Handler;
  22037. Laya.RunDriver = RunDriver;
  22038. Laya.Utils = Utils;
  22039. Laya.Input = Input;
  22040. Laya.Loader = Loader;
  22041. Laya.LocalStorage = LocalStorage;
  22042. Laya.SoundManager = SoundManager;
  22043. Laya.URL = URL;
  22044. Laya.Event = Event;
  22045. Laya.Matrix = Matrix;
  22046. Laya.HTMLImage = HTMLImage;
  22047. Laya.Laya = Laya;
  22048. Laya._evcode = "eva" + "l";
  22049. Laya.isNativeRender_enable = false;
  22050. Laya.__classmap = ILaya.__classMap;
  22051. ILaya.Timer = Timer;
  22052. ILaya.Dragging = Dragging;
  22053. ILaya.GraphicsBounds = GraphicsBounds;
  22054. ILaya.Sprite = Sprite;
  22055. ILaya.TextRender = TextRender;
  22056. ILaya.Loader = Loader;
  22057. ILaya.TTFLoader = TTFLoader;
  22058. ILaya.WebAudioSound = WebAudioSound;
  22059. ILaya.SoundManager = SoundManager;
  22060. ILaya.ShaderCompile = ShaderCompile;
  22061. ILaya.ClassUtils = ClassUtils;
  22062. ILaya.SceneUtils = SceneUtils;
  22063. ILaya.Context = Context;
  22064. ILaya.Render = Render;
  22065. ILaya.MouseManager = MouseManager;
  22066. ILaya.Text = Text;
  22067. ILaya.Browser = Browser;
  22068. ILaya.WebGL = WebGL;
  22069. ILaya.AudioSound = AudioSound;
  22070. ILaya.Pool = Pool;
  22071. ILaya.Utils = Utils;
  22072. ILaya.Graphics = Graphics;
  22073. ILaya.Submit = Submit;
  22074. ILaya.Stage = Stage;
  22075. ILaya.Resource = Resource;
  22076. ILaya.WorkerLoader = WorkerLoader;
  22077. var libs = window._layalibs;
  22078. if (libs) {
  22079. libs.sort(function (a, b) {
  22080. return a.i - b.i;
  22081. });
  22082. for (var j = 0; j < libs.length; j++) {
  22083. libs[j].f(window, window.document, Laya);
  22084. }
  22085. }
  22086. let win = window;
  22087. if (win.Laya) {
  22088. win.Laya.Laya = Laya;
  22089. Object.assign(win.Laya, Laya);
  22090. }
  22091. else
  22092. win.Laya = Laya;
  22093. var __init = Laya.__init;
  22094. var init = Laya.init;
  22095. var version = Laya.version;
  22096. var isWXOpenDataContext;
  22097. var isWXPosMsg;
  22098. var alertGlobalError = Laya.alertGlobalError;
  22099. var enableDebugPanel = Laya.enableDebugPanel;
  22100. function _static(_class, def) {
  22101. for (var i = 0, sz = def.length; i < sz; i += 2) {
  22102. if (def[i] == 'length')
  22103. _class.length = def[i + 1].call(_class);
  22104. else {
  22105. function tmp() {
  22106. var name = def[i];
  22107. var getfn = def[i + 1];
  22108. Object.defineProperty(_class, name, {
  22109. get: function () { delete this[name]; return this[name] = getfn.call(this); },
  22110. set: function (v) { delete this[name]; this[name] = v; }, enumerable: true, configurable: true
  22111. });
  22112. }
  22113. tmp();
  22114. }
  22115. }
  22116. }
  22117. class CommonScript extends Component {
  22118. get isSingleton() {
  22119. return false;
  22120. }
  22121. constructor() {
  22122. super();
  22123. }
  22124. onAwake() {
  22125. }
  22126. onEnable() {
  22127. }
  22128. onStart() {
  22129. }
  22130. onUpdate() {
  22131. }
  22132. onLateUpdate() {
  22133. }
  22134. onDisable() {
  22135. }
  22136. onDestroy() {
  22137. }
  22138. }
  22139. class Script extends Component {
  22140. get isSingleton() {
  22141. return false;
  22142. }
  22143. _onAwake() {
  22144. this.onAwake();
  22145. if (this.onStart !== Script.prototype.onStart) {
  22146. ILaya.startTimer.callLater(this, this.onStart);
  22147. }
  22148. }
  22149. _onEnable() {
  22150. var proto = Script.prototype;
  22151. if (this.onTriggerEnter !== proto.onTriggerEnter) {
  22152. this.owner.on(Event.TRIGGER_ENTER, this, this.onTriggerEnter);
  22153. }
  22154. if (this.onTriggerStay !== proto.onTriggerStay) {
  22155. this.owner.on(Event.TRIGGER_STAY, this, this.onTriggerStay);
  22156. }
  22157. if (this.onTriggerExit !== proto.onTriggerExit) {
  22158. this.owner.on(Event.TRIGGER_EXIT, this, this.onTriggerExit);
  22159. }
  22160. if (this.onMouseDown !== proto.onMouseDown) {
  22161. this.owner.on(Event.MOUSE_DOWN, this, this.onMouseDown);
  22162. }
  22163. if (this.onMouseUp !== proto.onMouseUp) {
  22164. this.owner.on(Event.MOUSE_UP, this, this.onMouseUp);
  22165. }
  22166. if (this.onClick !== proto.onClick) {
  22167. this.owner.on(Event.CLICK, this, this.onClick);
  22168. }
  22169. if (this.onStageMouseDown !== proto.onStageMouseDown) {
  22170. ILaya.stage.on(Event.MOUSE_DOWN, this, this.onStageMouseDown);
  22171. }
  22172. if (this.onStageMouseUp !== proto.onStageMouseUp) {
  22173. ILaya.stage.on(Event.MOUSE_UP, this, this.onStageMouseUp);
  22174. }
  22175. if (this.onStageClick !== proto.onStageClick) {
  22176. ILaya.stage.on(Event.CLICK, this, this.onStageClick);
  22177. }
  22178. if (this.onStageMouseMove !== proto.onStageMouseMove) {
  22179. ILaya.stage.on(Event.MOUSE_MOVE, this, this.onStageMouseMove);
  22180. }
  22181. if (this.onDoubleClick !== proto.onDoubleClick) {
  22182. this.owner.on(Event.DOUBLE_CLICK, this, this.onDoubleClick);
  22183. }
  22184. if (this.onRightClick !== proto.onRightClick) {
  22185. this.owner.on(Event.RIGHT_CLICK, this, this.onRightClick);
  22186. }
  22187. if (this.onMouseMove !== proto.onMouseMove) {
  22188. this.owner.on(Event.MOUSE_MOVE, this, this.onMouseMove);
  22189. }
  22190. if (this.onMouseOver !== proto.onMouseOver) {
  22191. this.owner.on(Event.MOUSE_OVER, this, this.onMouseOver);
  22192. }
  22193. if (this.onMouseOut !== proto.onMouseOut) {
  22194. this.owner.on(Event.MOUSE_OUT, this, this.onMouseOut);
  22195. }
  22196. if (this.onKeyDown !== proto.onKeyDown) {
  22197. ILaya.stage.on(Event.KEY_DOWN, this, this.onKeyDown);
  22198. }
  22199. if (this.onKeyPress !== proto.onKeyPress) {
  22200. ILaya.stage.on(Event.KEY_PRESS, this, this.onKeyPress);
  22201. }
  22202. if (this.onKeyUp !== proto.onKeyUp) {
  22203. ILaya.stage.on(Event.KEY_UP, this, this.onKeyUp);
  22204. }
  22205. if (this.onUpdate !== proto.onUpdate) {
  22206. ILaya.updateTimer.frameLoop(1, this, this.onUpdate);
  22207. }
  22208. if (this.onLateUpdate !== proto.onLateUpdate) {
  22209. ILaya.lateTimer.frameLoop(1, this, this.onLateUpdate);
  22210. }
  22211. if (this.onPreRender !== proto.onPreRender) {
  22212. ILaya.lateTimer.frameLoop(1, this, this.onPreRender);
  22213. }
  22214. }
  22215. _onDisable() {
  22216. this.owner.offAllCaller(this);
  22217. ILaya.stage.offAllCaller(this);
  22218. ILaya.startTimer.clearAll(this);
  22219. ILaya.updateTimer.clearAll(this);
  22220. ILaya.lateTimer.clearAll(this);
  22221. }
  22222. _isScript() {
  22223. return true;
  22224. }
  22225. _onDestroy() {
  22226. this.onDestroy();
  22227. }
  22228. onAwake() {
  22229. }
  22230. onEnable() {
  22231. }
  22232. onStart() {
  22233. }
  22234. onTriggerEnter(other, self, contact) {
  22235. }
  22236. onTriggerStay(other, self, contact) {
  22237. }
  22238. onTriggerExit(other, self, contact) {
  22239. }
  22240. onMouseDown(e) {
  22241. }
  22242. onMouseUp(e) {
  22243. }
  22244. onClick(e) {
  22245. }
  22246. onStageMouseDown(e) {
  22247. }
  22248. onStageMouseUp(e) {
  22249. }
  22250. onStageClick(e) {
  22251. }
  22252. onStageMouseMove(e) {
  22253. }
  22254. onDoubleClick(e) {
  22255. }
  22256. onRightClick(e) {
  22257. }
  22258. onMouseMove(e) {
  22259. }
  22260. onMouseOver(e) {
  22261. }
  22262. onMouseOut(e) {
  22263. }
  22264. onKeyDown(e) {
  22265. }
  22266. onKeyPress(e) {
  22267. }
  22268. onKeyUp(e) {
  22269. }
  22270. onUpdate() {
  22271. }
  22272. onLateUpdate() {
  22273. }
  22274. onPreRender() {
  22275. }
  22276. onPostRender() {
  22277. }
  22278. onDisable() {
  22279. }
  22280. onDestroy() {
  22281. }
  22282. }
  22283. class GraphicAnimation extends FrameAnimation {
  22284. constructor() {
  22285. super(...arguments);
  22286. this._nodeIDAniDic = {};
  22287. }
  22288. _parseNodeList(uiView) {
  22289. if (!this._nodeList)
  22290. this._nodeList = [];
  22291. this._nodeDefaultProps[uiView.compId] = uiView.props;
  22292. if (uiView.compId)
  22293. this._nodeList.push(uiView.compId);
  22294. var childs = uiView.child;
  22295. if (childs) {
  22296. var i, len = childs.length;
  22297. for (i = 0; i < len; i++) {
  22298. this._parseNodeList(childs[i]);
  22299. }
  22300. }
  22301. }
  22302. _calGraphicData(aniData) {
  22303. this._setUp(null, aniData);
  22304. this._createGraphicData();
  22305. if (this._nodeIDAniDic) {
  22306. var key;
  22307. for (key in this._nodeIDAniDic) {
  22308. this._nodeIDAniDic[key] = null;
  22309. }
  22310. }
  22311. }
  22312. _createGraphicData() {
  22313. var gList = [];
  22314. var i, len = this.count;
  22315. var animationDataNew = this._usedFrames;
  22316. if (!animationDataNew)
  22317. animationDataNew = [];
  22318. var preGraphic;
  22319. for (i = 0; i < len; i++) {
  22320. if (animationDataNew[i] || !preGraphic) {
  22321. preGraphic = this._createFrameGraphic(i);
  22322. }
  22323. gList.push(preGraphic);
  22324. }
  22325. this._gList = gList;
  22326. }
  22327. _createFrameGraphic(frame) {
  22328. var g = new Graphics();
  22329. if (!GraphicAnimation._rootMatrix)
  22330. GraphicAnimation._rootMatrix = new Matrix();
  22331. this._updateNodeGraphic(this._rootNode, frame, GraphicAnimation._rootMatrix, g);
  22332. return g;
  22333. }
  22334. _updateNodeGraphic(node, frame, parentTransfrom, g, alpha = 1) {
  22335. var tNodeG;
  22336. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22337. if (!tNodeG.resultTransform)
  22338. tNodeG.resultTransform = new Matrix();
  22339. var tResultTransform;
  22340. tResultTransform = tNodeG.resultTransform;
  22341. Matrix.mul(tNodeG.transform, parentTransfrom, tResultTransform);
  22342. var tTex;
  22343. var tGraphicAlpha = tNodeG.alpha * alpha;
  22344. if (tGraphicAlpha < 0.01)
  22345. return;
  22346. if (tNodeG.skin) {
  22347. tTex = this._getTextureByUrl(tNodeG.skin);
  22348. if (tTex) {
  22349. if (tResultTransform._checkTransform()) {
  22350. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tResultTransform, tGraphicAlpha);
  22351. tNodeG.resultTransform = null;
  22352. }
  22353. else {
  22354. g.drawTexture(tTex, tResultTransform.tx, tResultTransform.ty, tNodeG.width, tNodeG.height, null, tGraphicAlpha);
  22355. }
  22356. }
  22357. }
  22358. var childs = node.child;
  22359. if (!childs)
  22360. return;
  22361. var i, len;
  22362. len = childs.length;
  22363. for (i = 0; i < len; i++) {
  22364. this._updateNodeGraphic(childs[i], frame, tResultTransform, g, tGraphicAlpha);
  22365. }
  22366. }
  22367. _updateNoChilds(tNodeG, g) {
  22368. if (!tNodeG.skin)
  22369. return;
  22370. var tTex = this._getTextureByUrl(tNodeG.skin);
  22371. if (!tTex)
  22372. return;
  22373. var tTransform = tNodeG.transform;
  22374. tTransform._checkTransform();
  22375. var onlyTranslate;
  22376. onlyTranslate = !tTransform._bTransform;
  22377. if (!onlyTranslate) {
  22378. g.drawTexture(tTex, 0, 0, tNodeG.width, tNodeG.height, tTransform.clone(), tNodeG.alpha);
  22379. }
  22380. else {
  22381. g.drawTexture(tTex, tTransform.tx, tTransform.ty, tNodeG.width, tNodeG.height, null, tNodeG.alpha);
  22382. }
  22383. }
  22384. _updateNodeGraphic2(node, frame, g) {
  22385. var tNodeG;
  22386. tNodeG = this._nodeGDic[node.compId] = this._getNodeGraphicData(node.compId, frame, this._nodeGDic[node.compId]);
  22387. if (!node.child) {
  22388. this._updateNoChilds(tNodeG, g);
  22389. return;
  22390. }
  22391. var tTransform = tNodeG.transform;
  22392. tTransform._checkTransform();
  22393. var onlyTranslate;
  22394. onlyTranslate = !tTransform._bTransform;
  22395. var hasTrans;
  22396. hasTrans = onlyTranslate && (tTransform.tx != 0 || tTransform.ty != 0);
  22397. var ifSave;
  22398. ifSave = (tTransform._bTransform) || tNodeG.alpha != 1;
  22399. if (ifSave)
  22400. g.save();
  22401. if (tNodeG.alpha != 1)
  22402. g.alpha(tNodeG.alpha);
  22403. if (!onlyTranslate)
  22404. g.transform(tTransform.clone());
  22405. else if (hasTrans)
  22406. g.translate(tTransform.tx, tTransform.ty);
  22407. var childs = node.child;
  22408. var tTex;
  22409. if (tNodeG.skin) {
  22410. tTex = this._getTextureByUrl(tNodeG.skin);
  22411. if (tTex) {
  22412. g.drawImage(tTex, 0, 0, tNodeG.width, tNodeG.height);
  22413. }
  22414. }
  22415. if (childs) {
  22416. var i, len;
  22417. len = childs.length;
  22418. for (i = 0; i < len; i++) {
  22419. this._updateNodeGraphic2(childs[i], frame, g);
  22420. }
  22421. }
  22422. if (ifSave) {
  22423. g.restore();
  22424. }
  22425. else {
  22426. if (!onlyTranslate) {
  22427. g.transform(tTransform.clone().invert());
  22428. }
  22429. else if (hasTrans) {
  22430. g.translate(-tTransform.tx, -tTransform.ty);
  22431. }
  22432. }
  22433. }
  22434. _calculateKeyFrames(node) {
  22435. super._calculateKeyFrames(node);
  22436. this._nodeIDAniDic[node.target] = node;
  22437. }
  22438. getNodeDataByID(nodeID) {
  22439. return this._nodeIDAniDic[nodeID];
  22440. }
  22441. _getParams(obj, params, frame, obj2) {
  22442. var rst = GraphicAnimation._temParam;
  22443. rst.length = params.length;
  22444. var i, len = params.length;
  22445. for (i = 0; i < len; i++) {
  22446. rst[i] = this._getObjVar(obj, params[i][0], frame, params[i][1], obj2);
  22447. }
  22448. return rst;
  22449. }
  22450. _getObjVar(obj, key, frame, noValue, obj2) {
  22451. if (key in obj) {
  22452. var vArr = obj[key];
  22453. if (frame >= vArr.length)
  22454. frame = vArr.length - 1;
  22455. return obj[key][frame];
  22456. }
  22457. if (key in obj2) {
  22458. return obj2[key];
  22459. }
  22460. return noValue;
  22461. }
  22462. _getNodeGraphicData(nodeID, frame, rst) {
  22463. if (!rst)
  22464. rst = new GraphicNode();
  22465. if (!rst.transform) {
  22466. rst.transform = new Matrix();
  22467. }
  22468. else {
  22469. rst.transform.identity();
  22470. }
  22471. var node = this.getNodeDataByID(nodeID);
  22472. if (!node)
  22473. return rst;
  22474. var frameData = node.frames;
  22475. var params = this._getParams(frameData, GraphicAnimation._drawTextureCmd, frame, this._nodeDefaultProps[nodeID]);
  22476. var url = params[0];
  22477. var width, height;
  22478. var px = params[5], py = params[6];
  22479. var aX = params[13], aY = params[14];
  22480. var sx = params[7], sy = params[8];
  22481. var rotate = params[9];
  22482. var skewX = params[11], skewY = params[12];
  22483. width = params[3];
  22484. height = params[4];
  22485. if (width == 0 || height == 0)
  22486. url = null;
  22487. if (width == -1)
  22488. width = 0;
  22489. if (height == -1)
  22490. height = 0;
  22491. var tex;
  22492. rst.skin = url;
  22493. rst.width = width;
  22494. rst.height = height;
  22495. if (url) {
  22496. tex = this._getTextureByUrl(url);
  22497. if (tex) {
  22498. if (!width)
  22499. width = tex.sourceWidth;
  22500. if (!height)
  22501. height = tex.sourceHeight;
  22502. }
  22503. else {
  22504. console.warn("lost skin:", url, ",you may load pics first");
  22505. }
  22506. }
  22507. rst.alpha = params[10];
  22508. var m = rst.transform;
  22509. if (aX != 0) {
  22510. px = aX * width;
  22511. }
  22512. if (aY != 0) {
  22513. py = aY * height;
  22514. }
  22515. if (px != 0 || py != 0) {
  22516. m.translate(-px, -py);
  22517. }
  22518. var tm = null;
  22519. if (rotate || sx !== 1 || sy !== 1 || skewX || skewY) {
  22520. tm = GraphicAnimation._tempMt;
  22521. tm.identity();
  22522. tm._bTransform = true;
  22523. var skx = (rotate - skewX) * 0.0174532922222222;
  22524. var sky = (rotate + skewY) * 0.0174532922222222;
  22525. var cx = Math.cos(sky);
  22526. var ssx = Math.sin(sky);
  22527. var cy = Math.sin(skx);
  22528. var ssy = Math.cos(skx);
  22529. tm.a = sx * cx;
  22530. tm.b = sx * ssx;
  22531. tm.c = -sy * cy;
  22532. tm.d = sy * ssy;
  22533. tm.tx = tm.ty = 0;
  22534. }
  22535. if (tm) {
  22536. m = Matrix.mul(m, tm, m);
  22537. }
  22538. m.translate(params[1], params[2]);
  22539. return rst;
  22540. }
  22541. _getTextureByUrl(url) {
  22542. return Loader.getRes(url);
  22543. }
  22544. setAniData(uiView, aniName = null) {
  22545. if (uiView.animations) {
  22546. this._nodeDefaultProps = {};
  22547. this._nodeGDic = {};
  22548. if (this._nodeList)
  22549. this._nodeList.length = 0;
  22550. this._rootNode = uiView;
  22551. this._parseNodeList(uiView);
  22552. var aniDic = {};
  22553. var anilist = [];
  22554. var animations = uiView.animations;
  22555. var i, len = animations.length;
  22556. var tAniO;
  22557. for (i = 0; i < len; i++) {
  22558. tAniO = animations[i];
  22559. this._labels = null;
  22560. if (aniName && aniName != tAniO.name) {
  22561. continue;
  22562. }
  22563. if (!tAniO)
  22564. continue;
  22565. try {
  22566. this._calGraphicData(tAniO);
  22567. }
  22568. catch (e) {
  22569. console.warn("parse animation fail:" + tAniO.name + ",empty animation created");
  22570. this._gList = [];
  22571. }
  22572. var frameO = {};
  22573. frameO.interval = 1000 / tAniO["frameRate"];
  22574. frameO.frames = this._gList;
  22575. frameO.labels = this._labels;
  22576. frameO.name = tAniO.name;
  22577. anilist.push(frameO);
  22578. aniDic[tAniO.name] = frameO;
  22579. }
  22580. this.animationList = anilist;
  22581. this.animationDic = aniDic;
  22582. }
  22583. GraphicAnimation._temParam.length = 0;
  22584. }
  22585. parseByData(aniData) {
  22586. var rootNode, aniO;
  22587. rootNode = aniData.nodeRoot;
  22588. aniO = aniData.aniO;
  22589. delete aniData.nodeRoot;
  22590. delete aniData.aniO;
  22591. this._nodeDefaultProps = {};
  22592. this._nodeGDic = {};
  22593. if (this._nodeList)
  22594. this._nodeList.length = 0;
  22595. this._rootNode = rootNode;
  22596. this._parseNodeList(rootNode);
  22597. this._labels = null;
  22598. try {
  22599. this._calGraphicData(aniO);
  22600. }
  22601. catch (e) {
  22602. console.warn("parse animation fail:" + aniO.name + ",empty animation created");
  22603. this._gList = [];
  22604. }
  22605. var frameO = aniData;
  22606. frameO.interval = 1000 / aniO["frameRate"];
  22607. frameO.frames = this._gList;
  22608. frameO.labels = this._labels;
  22609. frameO.name = aniO.name;
  22610. return frameO;
  22611. }
  22612. setUpAniData(uiView) {
  22613. if (uiView.animations) {
  22614. var aniDic = {};
  22615. var anilist = [];
  22616. var animations = uiView.animations;
  22617. var i, len = animations.length;
  22618. var tAniO;
  22619. for (i = 0; i < len; i++) {
  22620. tAniO = animations[i];
  22621. if (!tAniO)
  22622. continue;
  22623. var frameO = {};
  22624. frameO.name = tAniO.name;
  22625. frameO.aniO = tAniO;
  22626. frameO.nodeRoot = uiView;
  22627. anilist.push(frameO);
  22628. aniDic[tAniO.name] = frameO;
  22629. }
  22630. this.animationList = anilist;
  22631. this.animationDic = aniDic;
  22632. }
  22633. }
  22634. _clear() {
  22635. this.animationList = null;
  22636. this.animationDic = null;
  22637. this._gList = null;
  22638. this._nodeGDic = null;
  22639. }
  22640. static parseAnimationByData(animationObject) {
  22641. if (!GraphicAnimation._I)
  22642. GraphicAnimation._I = new GraphicAnimation();
  22643. var rst;
  22644. rst = GraphicAnimation._I.parseByData(animationObject);
  22645. GraphicAnimation._I._clear();
  22646. return rst;
  22647. }
  22648. static parseAnimationData(aniData) {
  22649. if (!GraphicAnimation._I)
  22650. GraphicAnimation._I = new GraphicAnimation();
  22651. GraphicAnimation._I.setUpAniData(aniData);
  22652. var rst;
  22653. rst = {};
  22654. rst.animationList = GraphicAnimation._I.animationList;
  22655. rst.animationDic = GraphicAnimation._I.animationDic;
  22656. GraphicAnimation._I._clear();
  22657. return rst;
  22658. }
  22659. }
  22660. 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]];
  22661. GraphicAnimation._temParam = [];
  22662. GraphicAnimation._tempMt = new Matrix();
  22663. class GraphicNode {
  22664. constructor() {
  22665. this.alpha = 1;
  22666. }
  22667. }
  22668. class Animation extends AnimationBase {
  22669. constructor() {
  22670. super();
  22671. this._setControlNode(this);
  22672. }
  22673. destroy(destroyChild = true) {
  22674. this.stop();
  22675. super.destroy(destroyChild);
  22676. this._frames = null;
  22677. this._labels = null;
  22678. }
  22679. play(start = 0, loop = true, name = "") {
  22680. if (name)
  22681. this._setFramesFromCache(name, true);
  22682. super.play(start, loop, name);
  22683. }
  22684. _setFramesFromCache(name, showWarn = false) {
  22685. if (this._url)
  22686. name = this._url + "#" + name;
  22687. if (name && Animation.framesMap[name]) {
  22688. var tAniO = Animation.framesMap[name];
  22689. if (tAniO instanceof Array) {
  22690. this._frames = Animation.framesMap[name];
  22691. this._count = this._frames.length;
  22692. }
  22693. else {
  22694. if (tAniO.nodeRoot) {
  22695. Animation.framesMap[name] = GraphicAnimation.parseAnimationByData(tAniO);
  22696. tAniO = Animation.framesMap[name];
  22697. }
  22698. this._frames = tAniO.frames;
  22699. this._count = this._frames.length;
  22700. if (!this._frameRateChanged)
  22701. this._interval = tAniO.interval;
  22702. this._labels = this._copyLabels(tAniO.labels);
  22703. }
  22704. return true;
  22705. }
  22706. else {
  22707. if (showWarn)
  22708. console.log("ani not found:", name);
  22709. }
  22710. return false;
  22711. }
  22712. _copyLabels(labels) {
  22713. if (!labels)
  22714. return null;
  22715. var rst;
  22716. rst = {};
  22717. var key;
  22718. for (key in labels) {
  22719. rst[key] = Utils.copyArray([], labels[key]);
  22720. }
  22721. return rst;
  22722. }
  22723. _frameLoop() {
  22724. if (this._visible && this._style.alpha > 0.01 && this._frames) {
  22725. super._frameLoop();
  22726. }
  22727. }
  22728. _displayToIndex(value) {
  22729. if (this._frames)
  22730. this.graphics = this._frames[value];
  22731. }
  22732. get frames() {
  22733. return this._frames;
  22734. }
  22735. set frames(value) {
  22736. this._frames = value;
  22737. if (value) {
  22738. this._count = value.length;
  22739. if (this._actionName)
  22740. this._setFramesFromCache(this._actionName, true);
  22741. this.index = this._index;
  22742. }
  22743. }
  22744. set source(value) {
  22745. if (value.indexOf(".ani") > -1)
  22746. this.loadAnimation(value);
  22747. else if (value.indexOf(".json") > -1 || value.indexOf("als") > -1 || value.indexOf("atlas") > -1)
  22748. this.loadAtlas(value);
  22749. else
  22750. this.loadImages(value.split(","));
  22751. }
  22752. set autoAnimation(value) {
  22753. this.play(0, true, value);
  22754. }
  22755. set autoPlay(value) {
  22756. if (value)
  22757. this.play();
  22758. else
  22759. this.stop();
  22760. }
  22761. clear() {
  22762. super.clear();
  22763. this.stop();
  22764. this.graphics = null;
  22765. this._frames = null;
  22766. this._labels = null;
  22767. return this;
  22768. }
  22769. loadImages(urls, cacheName = "") {
  22770. this._url = "";
  22771. if (!this._setFramesFromCache(cacheName)) {
  22772. this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(urls, cacheName);
  22773. }
  22774. return this;
  22775. }
  22776. loadAtlas(url, loaded = null, cacheName = "") {
  22777. this._url = "";
  22778. var _this = this;
  22779. if (!_this._setFramesFromCache(cacheName)) {
  22780. function onLoaded(loadUrl) {
  22781. if (url === loadUrl) {
  22782. _this.frames = Animation.framesMap[cacheName] ? Animation.framesMap[cacheName] : Animation.createFrames(url, cacheName);
  22783. if (loaded)
  22784. loaded.run();
  22785. }
  22786. }
  22787. if (Loader.getAtlas(url))
  22788. onLoaded(url);
  22789. else
  22790. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.ATLAS);
  22791. }
  22792. return this;
  22793. }
  22794. loadAnimation(url, loaded = null, atlas = null) {
  22795. this._url = url;
  22796. var _this = this;
  22797. if (!this._actionName)
  22798. this._actionName = "";
  22799. if (!_this._setFramesFromCache(this._actionName)) {
  22800. if (!atlas || Loader.getAtlas(atlas)) {
  22801. this._loadAnimationData(url, loaded, atlas);
  22802. }
  22803. else {
  22804. ILaya.loader.load(atlas, Handler.create(this, this._loadAnimationData, [url, loaded, atlas]), null, Loader.ATLAS);
  22805. }
  22806. }
  22807. else {
  22808. _this._setFramesFromCache(this._actionName, true);
  22809. this.index = 0;
  22810. if (loaded)
  22811. loaded.run();
  22812. }
  22813. return this;
  22814. }
  22815. _loadAnimationData(url, loaded = null, atlas = null) {
  22816. if (atlas && !Loader.getAtlas(atlas)) {
  22817. console.warn("atlas load fail:" + atlas);
  22818. return;
  22819. }
  22820. var _this = this;
  22821. function onLoaded(loadUrl) {
  22822. if (!Loader.getRes(loadUrl)) {
  22823. if (Animation.framesMap[url + "#"]) {
  22824. _this._setFramesFromCache(this._actionName, true);
  22825. _this.index = 0;
  22826. _this._resumePlay();
  22827. if (loaded)
  22828. loaded.run();
  22829. }
  22830. return;
  22831. }
  22832. if (url === loadUrl) {
  22833. var tAniO;
  22834. if (!Animation.framesMap[url + "#"]) {
  22835. var aniData = GraphicAnimation.parseAnimationData(Loader.getRes(url));
  22836. if (!aniData)
  22837. return;
  22838. var aniList = aniData.animationList;
  22839. var i, len = aniList.length;
  22840. var defaultO;
  22841. for (i = 0; i < len; i++) {
  22842. tAniO = aniList[i];
  22843. Animation.framesMap[url + "#" + tAniO.name] = tAniO;
  22844. if (!defaultO)
  22845. defaultO = tAniO;
  22846. }
  22847. if (defaultO) {
  22848. Animation.framesMap[url + "#"] = defaultO;
  22849. _this._setFramesFromCache(_this._actionName, true);
  22850. _this.index = 0;
  22851. }
  22852. _this._resumePlay();
  22853. }
  22854. else {
  22855. _this._setFramesFromCache(_this._actionName, true);
  22856. _this.index = 0;
  22857. _this._resumePlay();
  22858. }
  22859. if (loaded)
  22860. loaded.run();
  22861. }
  22862. Loader.clearRes(url);
  22863. }
  22864. if (Loader.getRes(url))
  22865. onLoaded(url);
  22866. else
  22867. ILaya.loader.load(url, Handler.create(null, onLoaded, [url]), null, Loader.JSON);
  22868. }
  22869. static createFrames(url, name) {
  22870. var arr;
  22871. if (typeof (url) == 'string') {
  22872. var atlas = Loader.getAtlas(url);
  22873. if (atlas && atlas.length) {
  22874. arr = [];
  22875. for (var i = 0, n = atlas.length; i < n; i++) {
  22876. var g = new Graphics();
  22877. g.drawImage(Loader.getRes(atlas[i]), 0, 0);
  22878. arr.push(g);
  22879. }
  22880. }
  22881. }
  22882. else if (url instanceof Array) {
  22883. arr = [];
  22884. for (i = 0, n = url.length; i < n; i++) {
  22885. g = new Graphics();
  22886. g.loadImage(url[i], 0, 0);
  22887. arr.push(g);
  22888. }
  22889. }
  22890. if (name)
  22891. Animation.framesMap[name] = arr;
  22892. return arr;
  22893. }
  22894. static clearCache(key) {
  22895. var cache = Animation.framesMap;
  22896. var val;
  22897. var key2 = key + "#";
  22898. for (val in cache) {
  22899. if (val === key || val.indexOf(key2) === 0) {
  22900. delete Animation.framesMap[val];
  22901. }
  22902. }
  22903. }
  22904. }
  22905. Animation.framesMap = {};
  22906. ILaya.regClass(Animation);
  22907. ClassUtils.regClass("laya.display.Animation", Animation);
  22908. ClassUtils.regClass("Laya.Animation", Animation);
  22909. class EffectAnimation extends FrameAnimation {
  22910. constructor() {
  22911. super(...arguments);
  22912. this._initData = {};
  22913. }
  22914. set target(v) {
  22915. if (this._target)
  22916. this._target.off(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  22917. this._target = v;
  22918. if (this._target)
  22919. this._target.on(EffectAnimation.EFFECT_BEGIN, this, this._onOtherBegin);
  22920. this._addEvent();
  22921. }
  22922. get target() {
  22923. return this._target;
  22924. }
  22925. _onOtherBegin(effect) {
  22926. if (effect === this)
  22927. return;
  22928. this.stop();
  22929. }
  22930. set playEvent(event) {
  22931. this._playEvent = event;
  22932. if (!event)
  22933. return;
  22934. this._addEvent();
  22935. }
  22936. _addEvent() {
  22937. if (!this._target || !this._playEvent)
  22938. return;
  22939. this._setControlNode(this._target);
  22940. this._target.on(this._playEvent, this, this._onPlayAction);
  22941. }
  22942. _onPlayAction() {
  22943. this.play(0, false);
  22944. }
  22945. play(start = 0, loop = true, name = "") {
  22946. if (!this._target)
  22947. return;
  22948. this._target.event(EffectAnimation.EFFECT_BEGIN, [this]);
  22949. this._recordInitData();
  22950. super.play(start, loop, name);
  22951. }
  22952. _recordInitData() {
  22953. if (!this._aniKeys)
  22954. return;
  22955. var i, len;
  22956. len = this._aniKeys.length;
  22957. var key;
  22958. for (i = 0; i < len; i++) {
  22959. key = this._aniKeys[i];
  22960. this._initData[key] = this._target[key];
  22961. }
  22962. }
  22963. set effectClass(classStr) {
  22964. this._effectClass = ClassUtils.getClass(classStr);
  22965. if (this._effectClass) {
  22966. var uiData = this._effectClass["uiView"];
  22967. if (uiData) {
  22968. var aniData = uiData["animations"];
  22969. if (aniData && aniData[0]) {
  22970. var data = aniData[0];
  22971. this._setUp({}, data);
  22972. if (data.nodes && data.nodes[0]) {
  22973. this._aniKeys = data.nodes[0].keys;
  22974. }
  22975. }
  22976. }
  22977. }
  22978. }
  22979. set effectData(uiData) {
  22980. if (uiData) {
  22981. var aniData = uiData["animations"];
  22982. if (aniData && aniData[0]) {
  22983. var data = aniData[0];
  22984. this._setUp({}, data);
  22985. if (data.nodes && data.nodes[0]) {
  22986. this._aniKeys = data.nodes[0].keys;
  22987. }
  22988. }
  22989. }
  22990. }
  22991. _displayToIndex(value) {
  22992. if (!this._animationData)
  22993. return;
  22994. if (value < 0)
  22995. value = 0;
  22996. if (value > this._count)
  22997. value = this._count;
  22998. var nodes = this._animationData.nodes, i, len = nodes.length;
  22999. len = len > 1 ? 1 : len;
  23000. for (i = 0; i < len; i++) {
  23001. this._displayNodeToFrame(nodes[i], value);
  23002. }
  23003. }
  23004. _displayNodeToFrame(node, frame, targetDic = null) {
  23005. if (!this._target)
  23006. return;
  23007. var target = this._target;
  23008. var frames = node.frames, key, propFrames, value;
  23009. var keys = node.keys, i, len = keys.length;
  23010. var secondFrames = node.secondFrames;
  23011. var tSecondFrame;
  23012. var easeFun;
  23013. var tKeyFrames;
  23014. var startFrame;
  23015. var endFrame;
  23016. for (i = 0; i < len; i++) {
  23017. key = keys[i];
  23018. propFrames = frames[key];
  23019. tSecondFrame = secondFrames[key];
  23020. if (tSecondFrame == -1) {
  23021. value = this._initData[key];
  23022. }
  23023. else {
  23024. if (frame < tSecondFrame) {
  23025. tKeyFrames = node.keyframes[key];
  23026. startFrame = tKeyFrames[0];
  23027. if (startFrame.tween) {
  23028. easeFun = Ease[startFrame.tweenMethod];
  23029. if (easeFun == null)
  23030. easeFun = Ease.linearNone;
  23031. endFrame = tKeyFrames[1];
  23032. value = easeFun(frame, this._initData[key], endFrame.value - this._initData[key], endFrame.index);
  23033. }
  23034. else {
  23035. value = this._initData[key];
  23036. }
  23037. }
  23038. else {
  23039. if (propFrames.length > frame)
  23040. value = propFrames[frame];
  23041. else
  23042. value = propFrames[propFrames.length - 1];
  23043. }
  23044. }
  23045. target[key] = value;
  23046. }
  23047. }
  23048. _calculateKeyFrames(node) {
  23049. super._calculateKeyFrames(node);
  23050. var keyFrames = node.keyframes, key, tKeyFrames, target = node.target;
  23051. var secondFrames = {};
  23052. node.secondFrames = secondFrames;
  23053. for (key in keyFrames) {
  23054. tKeyFrames = keyFrames[key];
  23055. if (tKeyFrames.length <= 1)
  23056. secondFrames[key] = -1;
  23057. else
  23058. secondFrames[key] = tKeyFrames[1].index;
  23059. }
  23060. }
  23061. }
  23062. EffectAnimation.EFFECT_BEGIN = "effectbegin";
  23063. ClassUtils.regClass("laya.display.EffectAnimation", EffectAnimation);
  23064. ClassUtils.regClass("Laya.EffectAnimation", EffectAnimation);
  23065. class SceneLoader extends EventDispatcher {
  23066. constructor() {
  23067. super();
  23068. this._completeHandler = new Handler(this, this.onOneLoadComplete);
  23069. this.reset();
  23070. }
  23071. reset() {
  23072. this._toLoadList = [];
  23073. this._isLoading = false;
  23074. this.totalCount = 0;
  23075. }
  23076. get leftCount() {
  23077. if (this._isLoading)
  23078. return this._toLoadList.length + 1;
  23079. return this._toLoadList.length;
  23080. }
  23081. get loadedCount() {
  23082. return this.totalCount - this.leftCount;
  23083. }
  23084. load(url, is3D = false, ifCheck = true) {
  23085. if (url instanceof Array) {
  23086. var i, len;
  23087. len = url.length;
  23088. for (i = 0; i < len; i++) {
  23089. this._addToLoadList(url[i], is3D);
  23090. }
  23091. }
  23092. else {
  23093. this._addToLoadList(url, is3D);
  23094. }
  23095. if (ifCheck)
  23096. this._checkNext();
  23097. }
  23098. _addToLoadList(url, is3D = false) {
  23099. if (this._toLoadList.indexOf(url) >= 0)
  23100. return;
  23101. if (Loader.getRes(url))
  23102. return;
  23103. if (is3D) {
  23104. this._toLoadList.push({ url: url });
  23105. }
  23106. else
  23107. this._toLoadList.push(url);
  23108. this.totalCount++;
  23109. }
  23110. _checkNext() {
  23111. if (!this._isLoading) {
  23112. if (this._toLoadList.length == 0) {
  23113. this.event(Event.COMPLETE);
  23114. return;
  23115. }
  23116. var tItem;
  23117. tItem = this._toLoadList.pop();
  23118. if (typeof (tItem) == 'string') {
  23119. this.loadOne(tItem);
  23120. }
  23121. else {
  23122. this.loadOne(tItem.url, true);
  23123. }
  23124. }
  23125. }
  23126. loadOne(url, is3D = false) {
  23127. this._curUrl = url;
  23128. var type = Utils.getFileExtension(this._curUrl);
  23129. if (is3D) {
  23130. ILaya.loader.create(url, this._completeHandler);
  23131. }
  23132. else if (SceneLoader.LoadableExtensions[type]) {
  23133. ILaya.loader.load(url, this._completeHandler, null, SceneLoader.LoadableExtensions[type]);
  23134. }
  23135. else if (url != AtlasInfoManager.getFileLoadPath(url) || SceneLoader.No3dLoadTypes[type] || !LoaderManager.createMap[type]) {
  23136. ILaya.loader.load(url, this._completeHandler);
  23137. }
  23138. else {
  23139. ILaya.loader.create(url, this._completeHandler);
  23140. }
  23141. }
  23142. onOneLoadComplete() {
  23143. this._isLoading = false;
  23144. if (!Loader.getRes(this._curUrl)) {
  23145. console.log("Fail to load:", this._curUrl);
  23146. }
  23147. var type = Utils.getFileExtension(this._curUrl);
  23148. if (SceneLoader.LoadableExtensions[type]) {
  23149. var dataO;
  23150. dataO = Loader.getRes(this._curUrl);
  23151. if (dataO && (dataO instanceof Prefab)) {
  23152. dataO = dataO.json;
  23153. }
  23154. if (dataO) {
  23155. if (dataO.loadList) {
  23156. this.load(dataO.loadList, false, false);
  23157. }
  23158. if (dataO.loadList3D) {
  23159. this.load(dataO.loadList3D, true, false);
  23160. }
  23161. }
  23162. }
  23163. if (type == "sk") {
  23164. this.load(this._curUrl.replace(".sk", ".png"), false, false);
  23165. }
  23166. this.event(Event.PROGRESS, this.getProgress());
  23167. this._checkNext();
  23168. }
  23169. getProgress() {
  23170. return this.loadedCount / this.totalCount;
  23171. }
  23172. }
  23173. SceneLoader.LoadableExtensions = { "scene": Loader.JSON, "scene3d": Loader.JSON, "ani": Loader.JSON, "ui": Loader.JSON, "prefab": Loader.PREFAB };
  23174. SceneLoader.No3dLoadTypes = { "png": true, "jpg": true, "txt": true };
  23175. class Scene extends Sprite {
  23176. constructor(createChildren = true) {
  23177. super();
  23178. this.autoDestroyAtClosed = false;
  23179. this.url = null;
  23180. this._viewCreated = false;
  23181. this._$componentType = "Scene";
  23182. this._setBit(Const.NOT_READY, true);
  23183. Scene.unDestroyedScenes.push(this);
  23184. this._scene = this;
  23185. if (createChildren)
  23186. this.createChildren();
  23187. }
  23188. createChildren() {
  23189. }
  23190. loadScene(path) {
  23191. var url = path.indexOf(".") > -1 ? path : path + ".scene";
  23192. var view = ILaya.loader.getRes(url);
  23193. if (view) {
  23194. this.createView(view);
  23195. }
  23196. else {
  23197. ILaya.loader.resetProgress();
  23198. var loader = new SceneLoader();
  23199. loader.on(Event.COMPLETE, this, this._onSceneLoaded, [url]);
  23200. loader.load(url);
  23201. }
  23202. }
  23203. _onSceneLoaded(url) {
  23204. this.createView(ILaya.Loader.getRes(url));
  23205. }
  23206. createView(view) {
  23207. if (view && !this._viewCreated) {
  23208. this._viewCreated = true;
  23209. SceneUtils.createByData(this, view);
  23210. }
  23211. }
  23212. getNodeByID(id) {
  23213. if (this._idMap)
  23214. return this._idMap[id];
  23215. return null;
  23216. }
  23217. open(closeOther = true, param = null) {
  23218. if (closeOther)
  23219. Scene.closeAll();
  23220. Scene.root.addChild(this);
  23221. this.onOpened(param);
  23222. }
  23223. onOpened(param) {
  23224. }
  23225. close(type = null) {
  23226. this.onClosed(type);
  23227. if (this.autoDestroyAtClosed)
  23228. this.destroy();
  23229. else
  23230. this.removeSelf();
  23231. }
  23232. onClosed(type = null) {
  23233. }
  23234. destroy(destroyChild = true) {
  23235. this._idMap = null;
  23236. super.destroy(destroyChild);
  23237. var list = Scene.unDestroyedScenes;
  23238. for (var i = list.length - 1; i > -1; i--) {
  23239. if (list[i] === this) {
  23240. list.splice(i, 1);
  23241. return;
  23242. }
  23243. }
  23244. }
  23245. set scaleX(value) {
  23246. if (super.get_scaleX() == value)
  23247. return;
  23248. super.set_scaleX(value);
  23249. this.event(Event.RESIZE);
  23250. }
  23251. get scaleX() {
  23252. return super.scaleX;
  23253. }
  23254. set scaleY(value) {
  23255. if (super.get_scaleY() == value)
  23256. return;
  23257. super.set_scaleY(value);
  23258. this.event(Event.RESIZE);
  23259. }
  23260. get scaleY() {
  23261. return super.scaleY;
  23262. }
  23263. get width() {
  23264. if (this._width)
  23265. return this._width;
  23266. var max = 0;
  23267. for (var i = this.numChildren - 1; i > -1; i--) {
  23268. var comp = this.getChildAt(i);
  23269. if (comp._visible) {
  23270. max = Math.max(comp._x + comp.width * comp.scaleX, max);
  23271. }
  23272. }
  23273. return max;
  23274. }
  23275. set width(value) {
  23276. if (super.get_width() == value)
  23277. return;
  23278. super.set_width(value);
  23279. this.callLater(this._sizeChanged);
  23280. }
  23281. get height() {
  23282. if (this._height)
  23283. return this._height;
  23284. var max = 0;
  23285. for (var i = this.numChildren - 1; i > -1; i--) {
  23286. var comp = this.getChildAt(i);
  23287. if (comp._visible) {
  23288. max = Math.max(comp._y + comp.height * comp.scaleY, max);
  23289. }
  23290. }
  23291. return max;
  23292. }
  23293. set height(value) {
  23294. if (super.get_height() == value)
  23295. return;
  23296. super.set_height(value);
  23297. this.callLater(this._sizeChanged);
  23298. }
  23299. _sizeChanged() {
  23300. this.event(Event.RESIZE);
  23301. }
  23302. static get root() {
  23303. if (!Scene._root) {
  23304. Scene._root = ILaya.stage.addChild(new Sprite());
  23305. Scene._root.name = "root";
  23306. ILaya.stage.on("resize", null, () => {
  23307. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23308. Scene._root.event(Event.RESIZE);
  23309. });
  23310. Scene._root.size(ILaya.stage.width, ILaya.stage.height);
  23311. Scene._root.event(Event.RESIZE);
  23312. }
  23313. return Scene._root;
  23314. }
  23315. get timer() {
  23316. return this._timer || ILaya.timer;
  23317. }
  23318. set timer(value) {
  23319. this._timer = value;
  23320. }
  23321. static load(url, complete = null, progress = null) {
  23322. ILaya.loader.resetProgress();
  23323. var loader = new SceneLoader();
  23324. loader.on(Event.PROGRESS, null, onProgress);
  23325. loader.once(Event.COMPLETE, null, create);
  23326. loader.load(url);
  23327. function onProgress(value) {
  23328. if (Scene._loadPage)
  23329. Scene._loadPage.event("progress", value);
  23330. progress && progress.runWith(value);
  23331. }
  23332. function create() {
  23333. loader.off(Event.PROGRESS, null, onProgress);
  23334. var obj = ILaya.Loader.getRes(url);
  23335. if (!obj)
  23336. throw "Can not find scene:" + url;
  23337. if (!obj.props)
  23338. throw "Scene data is error:" + url;
  23339. var runtime = obj.props.runtime ? obj.props.runtime : obj.type;
  23340. var clas = ILaya.ClassUtils.getClass(runtime);
  23341. if (obj.props.renderType == "instance") {
  23342. var scene = clas.instance || (clas.instance = new clas());
  23343. }
  23344. else {
  23345. scene = new clas();
  23346. }
  23347. if (scene && scene instanceof Node) {
  23348. scene.url = url;
  23349. if (!scene._getBit(Const.NOT_READY)) {
  23350. complete && complete.runWith(scene);
  23351. }
  23352. else {
  23353. scene.on("onViewCreated", null, function () {
  23354. complete && complete.runWith(scene);
  23355. });
  23356. scene.createView(obj);
  23357. }
  23358. Scene.hideLoadingPage();
  23359. }
  23360. else {
  23361. throw "Can not find scene:" + runtime;
  23362. }
  23363. }
  23364. }
  23365. static open(url, closeOther = true, param = null, complete = null, progress = null) {
  23366. if (param instanceof Handler) {
  23367. var temp = complete;
  23368. complete = param;
  23369. param = temp;
  23370. }
  23371. Scene.showLoadingPage();
  23372. Scene.load(url, Handler.create(null, this._onSceneLoaded, [closeOther, complete, param]), progress);
  23373. }
  23374. static _onSceneLoaded(closeOther, complete, param, scene) {
  23375. scene.open(closeOther, param);
  23376. if (complete)
  23377. complete.runWith(scene);
  23378. }
  23379. static close(url, name = "") {
  23380. var flag = false;
  23381. var list = Scene.unDestroyedScenes;
  23382. for (var i = 0, n = list.length; i < n; i++) {
  23383. var scene = list[i];
  23384. if (scene && scene.parent && scene.url === url && scene.name == name) {
  23385. scene.close();
  23386. flag = true;
  23387. }
  23388. }
  23389. return flag;
  23390. }
  23391. static closeAll() {
  23392. var root = Scene.root;
  23393. for (var i = 0, n = root.numChildren; i < n; i++) {
  23394. var scene = root.getChildAt(0);
  23395. if (scene instanceof Scene)
  23396. scene.close();
  23397. else
  23398. scene.removeSelf();
  23399. }
  23400. }
  23401. static destroy(url, name = "") {
  23402. var flag = false;
  23403. var list = Scene.unDestroyedScenes;
  23404. for (var i = 0, n = list.length; i < n; i++) {
  23405. var scene = list[i];
  23406. if (scene.url === url && scene.name == name) {
  23407. scene.destroy();
  23408. flag = true;
  23409. }
  23410. }
  23411. return flag;
  23412. }
  23413. static gc() {
  23414. Resource.destroyUnusedResources();
  23415. }
  23416. static setLoadingPage(loadPage) {
  23417. if (Scene._loadPage != loadPage) {
  23418. Scene._loadPage = loadPage;
  23419. }
  23420. }
  23421. static showLoadingPage(param = null, delay = 500) {
  23422. if (Scene._loadPage) {
  23423. ILaya.systemTimer.clear(null, Scene._showLoading);
  23424. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23425. ILaya.systemTimer.once(delay, null, Scene._showLoading, [param], false);
  23426. }
  23427. }
  23428. static _showLoading(param) {
  23429. ILaya.stage.addChild(Scene._loadPage);
  23430. Scene._loadPage.onOpened(param);
  23431. }
  23432. static _hideLoading() {
  23433. Scene._loadPage.close();
  23434. }
  23435. static hideLoadingPage(delay = 500) {
  23436. if (Scene._loadPage) {
  23437. ILaya.systemTimer.clear(null, Scene._showLoading);
  23438. ILaya.systemTimer.clear(null, Scene._hideLoading);
  23439. ILaya.systemTimer.once(delay, null, Scene._hideLoading);
  23440. }
  23441. }
  23442. }
  23443. Scene.unDestroyedScenes = [];
  23444. ILaya.regClass(Scene);
  23445. ClassUtils.regClass("laya.display.Scene", Scene);
  23446. ClassUtils.regClass("Laya.Scene", Scene);
  23447. class DrawCanvasCmd {
  23448. constructor() {
  23449. this._paramData = null;
  23450. }
  23451. static create(texture, x, y, width, height) {
  23452. return null;
  23453. }
  23454. recover() {
  23455. this._graphicsCmdEncoder = null;
  23456. Pool.recover("DrawCanvasCmd", this);
  23457. }
  23458. get cmdID() {
  23459. return DrawCanvasCmd.ID;
  23460. }
  23461. }
  23462. DrawCanvasCmd.ID = "DrawCanvasCmd";
  23463. DrawCanvasCmd._DRAW_IMAGE_CMD_ENCODER_ = null;
  23464. DrawCanvasCmd._PARAM_TEXTURE_POS_ = 2;
  23465. DrawCanvasCmd._PARAM_VB_POS_ = 5;
  23466. class DrawParticleCmd {
  23467. static create(_temp) {
  23468. var cmd = Pool.getItemByClass("DrawParticleCmd", DrawParticleCmd);
  23469. cmd._templ = _temp;
  23470. return cmd;
  23471. }
  23472. recover() {
  23473. this._templ = null;
  23474. Pool.recover("DrawParticleCmd", this);
  23475. }
  23476. run(context, gx, gy) {
  23477. context.drawParticle(gx, gy, this._templ);
  23478. }
  23479. get cmdID() {
  23480. return DrawParticleCmd.ID;
  23481. }
  23482. }
  23483. DrawParticleCmd.ID = "DrawParticleCmd";
  23484. class FilterSetterBase {
  23485. constructor() {
  23486. }
  23487. paramChanged() {
  23488. Laya.systemTimer.callLater(this, this.buildFilter);
  23489. }
  23490. buildFilter() {
  23491. if (this._target) {
  23492. this.addFilter(this._target);
  23493. }
  23494. }
  23495. addFilter(sprite) {
  23496. if (!sprite)
  23497. return;
  23498. if (!sprite.filters) {
  23499. sprite.filters = [this._filter];
  23500. }
  23501. else {
  23502. var preFilters;
  23503. preFilters = sprite.filters;
  23504. if (preFilters.indexOf(this._filter) < 0) {
  23505. preFilters.push(this._filter);
  23506. sprite.filters = Utils.copyArray([], preFilters);
  23507. }
  23508. }
  23509. }
  23510. removeFilter(sprite) {
  23511. if (!sprite)
  23512. return;
  23513. sprite.filters = null;
  23514. }
  23515. set target(value) {
  23516. if (this._target != value) {
  23517. this._target = value;
  23518. this.paramChanged();
  23519. }
  23520. }
  23521. }
  23522. class BlurFilterGLRender {
  23523. render(rt, ctx, width, height, filter) {
  23524. var shaderValue = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23525. this.setShaderInfo(shaderValue, filter, rt.width, rt.height);
  23526. ctx.drawTarget(rt, 0, 0, width, height, Matrix.EMPTY.identity(), shaderValue);
  23527. }
  23528. setShaderInfo(shader, filter, w, h) {
  23529. shader.defines.add(Filter.BLUR);
  23530. var sv = shader;
  23531. BlurFilterGLRender.blurinfo[0] = w;
  23532. BlurFilterGLRender.blurinfo[1] = h;
  23533. sv.blurInfo = BlurFilterGLRender.blurinfo;
  23534. var sigma = filter.strength / 3.0;
  23535. var sigma2 = sigma * sigma;
  23536. filter.strength_sig2_2sig2_gauss1[0] = filter.strength;
  23537. filter.strength_sig2_2sig2_gauss1[1] = sigma2;
  23538. filter.strength_sig2_2sig2_gauss1[2] = 2.0 * sigma2;
  23539. filter.strength_sig2_2sig2_gauss1[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23540. sv.strength_sig2_2sig2_gauss1 = filter.strength_sig2_2sig2_gauss1;
  23541. }
  23542. }
  23543. BlurFilterGLRender.blurinfo = new Array(2);
  23544. class BlurFilter extends Filter {
  23545. constructor(strength = 4) {
  23546. super();
  23547. this.strength_sig2_2sig2_gauss1 = [];
  23548. this.strength = strength;
  23549. this._glRender = new BlurFilterGLRender();
  23550. }
  23551. get type() {
  23552. return Filter.BLUR;
  23553. }
  23554. getStrenth_sig2_2sig2_native() {
  23555. if (!this.strength_sig2_native) {
  23556. this.strength_sig2_native = new Float32Array(4);
  23557. }
  23558. var sigma = this.strength / 3.0;
  23559. var sigma2 = sigma * sigma;
  23560. this.strength_sig2_native[0] = this.strength;
  23561. this.strength_sig2_native[1] = sigma2;
  23562. this.strength_sig2_native[2] = 2.0 * sigma2;
  23563. this.strength_sig2_native[3] = 1.0 / (2.0 * Math.PI * sigma2);
  23564. return this.strength_sig2_native;
  23565. }
  23566. }
  23567. class BlurFilterSetter extends FilterSetterBase {
  23568. constructor() {
  23569. super();
  23570. this._strength = 4;
  23571. this._filter = new BlurFilter(this.strength);
  23572. }
  23573. buildFilter() {
  23574. this._filter = new BlurFilter(this.strength);
  23575. super.buildFilter();
  23576. }
  23577. get strength() {
  23578. return this._strength;
  23579. }
  23580. set strength(value) {
  23581. this._strength = value;
  23582. }
  23583. }
  23584. class ButtonEffect {
  23585. constructor() {
  23586. this._curState = 0;
  23587. this.effectScale = 1.5;
  23588. this.tweenTime = 300;
  23589. }
  23590. set target(tar) {
  23591. this._tar = tar;
  23592. tar.on(Event.MOUSE_DOWN, this, this.toChangedState);
  23593. tar.on(Event.MOUSE_UP, this, this.toInitState);
  23594. tar.on(Event.MOUSE_OUT, this, this.toInitState);
  23595. }
  23596. toChangedState() {
  23597. this._curState = 1;
  23598. if (this._curTween)
  23599. Tween.clear(this._curTween);
  23600. this._curTween = Tween.to(this._tar, { scaleX: this.effectScale, scaleY: this.effectScale }, this.tweenTime, Ease[this.effectEase], Handler.create(this, this.tweenComplete));
  23601. }
  23602. toInitState() {
  23603. if (this._curState == 2)
  23604. return;
  23605. if (this._curTween)
  23606. Tween.clear(this._curTween);
  23607. this._curState = 2;
  23608. this._curTween = Tween.to(this._tar, { scaleX: 1, scaleY: 1 }, this.tweenTime, Ease[this.backEase], Handler.create(this, this.tweenComplete));
  23609. }
  23610. tweenComplete() {
  23611. this._curState = 0;
  23612. this._curTween = null;
  23613. }
  23614. }
  23615. class ColorFilterSetter extends FilterSetterBase {
  23616. constructor() {
  23617. super();
  23618. this._brightness = 0;
  23619. this._contrast = 0;
  23620. this._saturation = 0;
  23621. this._hue = 0;
  23622. this._red = 0;
  23623. this._green = 0;
  23624. this._blue = 0;
  23625. this._alpha = 0;
  23626. this._filter = new ColorFilter();
  23627. }
  23628. buildFilter() {
  23629. this._filter.reset();
  23630. this._filter.color(this.red, this.green, this.blue, this.alpha);
  23631. this._filter.adjustHue(this.hue);
  23632. this._filter.adjustContrast(this.contrast);
  23633. this._filter.adjustBrightness(this.brightness);
  23634. this._filter.adjustSaturation(this.saturation);
  23635. super.buildFilter();
  23636. }
  23637. get brightness() {
  23638. return this._brightness;
  23639. }
  23640. set brightness(value) {
  23641. this._brightness = value;
  23642. this.paramChanged();
  23643. }
  23644. get contrast() {
  23645. return this._contrast;
  23646. }
  23647. set contrast(value) {
  23648. this._contrast = value;
  23649. this.paramChanged();
  23650. }
  23651. get saturation() {
  23652. return this._saturation;
  23653. }
  23654. set saturation(value) {
  23655. this._saturation = value;
  23656. this.paramChanged();
  23657. }
  23658. get hue() {
  23659. return this._hue;
  23660. }
  23661. set hue(value) {
  23662. this._hue = value;
  23663. this.paramChanged();
  23664. }
  23665. get red() {
  23666. return this._red;
  23667. }
  23668. set red(value) {
  23669. this._red = value;
  23670. this.paramChanged();
  23671. }
  23672. get green() {
  23673. return this._green;
  23674. }
  23675. set green(value) {
  23676. this._green = value;
  23677. this.paramChanged();
  23678. }
  23679. get blue() {
  23680. return this._blue;
  23681. }
  23682. set blue(value) {
  23683. this._blue = value;
  23684. this.paramChanged();
  23685. }
  23686. get color() {
  23687. return this._color;
  23688. }
  23689. set color(value) {
  23690. this._color = value;
  23691. var colorO;
  23692. colorO = ColorUtils.create(value);
  23693. this._red = colorO.arrColor[0] * 255;
  23694. this._green = colorO.arrColor[1] * 255;
  23695. this._blue = colorO.arrColor[2] * 255;
  23696. this.paramChanged();
  23697. }
  23698. get alpha() {
  23699. return this._alpha;
  23700. }
  23701. set alpha(value) {
  23702. this._alpha = value;
  23703. this.paramChanged();
  23704. }
  23705. }
  23706. class EffectBase extends Component {
  23707. constructor() {
  23708. super(...arguments);
  23709. this.duration = 1000;
  23710. this.delay = 0;
  23711. this.repeat = 0;
  23712. this.autoDestroyAtComplete = true;
  23713. }
  23714. _onAwake() {
  23715. this.target = this.target || this.owner;
  23716. if (this.autoDestroyAtComplete)
  23717. this._comlete = Handler.create(this.target, this.target.destroy, null, false);
  23718. if (this.eventName)
  23719. this.owner.on(this.eventName, this, this._exeTween);
  23720. else
  23721. this._exeTween();
  23722. }
  23723. _exeTween() {
  23724. this._tween = this._doTween();
  23725. this._tween.repeat = this.repeat;
  23726. }
  23727. _doTween() {
  23728. return null;
  23729. }
  23730. onReset() {
  23731. this.duration = 1000;
  23732. this.delay = 0;
  23733. this.repeat = 0;
  23734. this.ease = null;
  23735. this.target = null;
  23736. if (this.eventName) {
  23737. this.owner.off(this.eventName, this, this._exeTween);
  23738. this.eventName = null;
  23739. }
  23740. if (this._comlete) {
  23741. this._comlete.recover();
  23742. this._comlete = null;
  23743. }
  23744. if (this._tween) {
  23745. this._tween.clear();
  23746. this._tween = null;
  23747. }
  23748. }
  23749. }
  23750. class FadeIn extends EffectBase {
  23751. _doTween() {
  23752. this.target.alpha = 0;
  23753. return Tween.to(this.target, { alpha: 1 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  23754. }
  23755. }
  23756. class FadeOut extends EffectBase {
  23757. _doTween() {
  23758. this.target.alpha = 1;
  23759. return Tween.to(this.target, { alpha: 0 }, this.duration, Ease[this.ease], this._comlete, this.delay);
  23760. }
  23761. }
  23762. class GlowFilterGLRender {
  23763. setShaderInfo(shader, w, h, data) {
  23764. shader.defines.add(data.type);
  23765. var sv = shader;
  23766. sv.u_blurInfo1 = data._sv_blurInfo1;
  23767. var info2 = data._sv_blurInfo2;
  23768. info2[0] = w;
  23769. info2[1] = h;
  23770. sv.u_blurInfo2 = info2;
  23771. sv.u_color = data.getColor();
  23772. }
  23773. render(rt, ctx, width, height, filter) {
  23774. var w = width, h = height;
  23775. var svBlur = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23776. this.setShaderInfo(svBlur, w, h, filter);
  23777. var svCP = Value2D.create(ShaderDefines2D.TEXTURE2D, 0);
  23778. var matI = Matrix.TEMP.identity();
  23779. ctx.drawTarget(rt, 0, 0, w, h, matI, svBlur);
  23780. ctx.drawTarget(rt, 0, 0, w, h, matI, svCP);
  23781. }
  23782. }
  23783. class GlowFilter extends Filter {
  23784. constructor(color, blur = 4, offX = 6, offY = 6) {
  23785. super();
  23786. this._elements = new Float32Array(9);
  23787. this._sv_blurInfo1 = new Array(4);
  23788. this._sv_blurInfo2 = [0, 0, 1, 0];
  23789. this._color = new ColorUtils(color);
  23790. this.blur = Math.min(blur, 20);
  23791. this.offX = offX;
  23792. this.offY = offY;
  23793. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = this.blur;
  23794. this._sv_blurInfo1[2] = offX;
  23795. this._sv_blurInfo1[3] = -offY;
  23796. this._glRender = new GlowFilterGLRender();
  23797. }
  23798. get type() {
  23799. return BlurFilter.GLOW;
  23800. }
  23801. get offY() {
  23802. return this._elements[6];
  23803. }
  23804. set offY(value) {
  23805. this._elements[6] = value;
  23806. this._sv_blurInfo1[3] = -value;
  23807. }
  23808. get offX() {
  23809. return this._elements[5];
  23810. }
  23811. set offX(value) {
  23812. this._elements[5] = value;
  23813. this._sv_blurInfo1[2] = value;
  23814. }
  23815. getColor() {
  23816. return this._color.arrColor;
  23817. }
  23818. get blur() {
  23819. return this._elements[4];
  23820. }
  23821. set blur(value) {
  23822. this._elements[4] = value;
  23823. this._sv_blurInfo1[0] = this._sv_blurInfo1[1] = value;
  23824. }
  23825. getColorNative() {
  23826. if (!this._color_native) {
  23827. this._color_native = new Float32Array(4);
  23828. }
  23829. var color = this.getColor();
  23830. this._color_native[0] = color[0];
  23831. this._color_native[1] = color[1];
  23832. this._color_native[2] = color[2];
  23833. this._color_native[3] = color[3];
  23834. return this._color_native;
  23835. }
  23836. getBlurInfo1Native() {
  23837. if (!this._blurInof1_native) {
  23838. this._blurInof1_native = new Float32Array(4);
  23839. }
  23840. this._blurInof1_native[0] = this._blurInof1_native[1] = this.blur;
  23841. this._blurInof1_native[2] = this.offX;
  23842. this._blurInof1_native[3] = this.offY;
  23843. return this._blurInof1_native;
  23844. }
  23845. getBlurInfo2Native() {
  23846. if (!this._blurInof2_native) {
  23847. this._blurInof2_native = new Float32Array(4);
  23848. }
  23849. this._blurInof2_native[2] = 1;
  23850. return this._blurInof2_native;
  23851. }
  23852. }
  23853. class GlowFilterSetter extends FilterSetterBase {
  23854. constructor() {
  23855. super();
  23856. this._color = "#ff0000";
  23857. this._blur = 4;
  23858. this._offX = 6;
  23859. this._offY = 6;
  23860. this._filter = new GlowFilter(this._color);
  23861. }
  23862. buildFilter() {
  23863. this._filter = new GlowFilter(this.color, this.blur, this.offX, this.offY);
  23864. super.buildFilter();
  23865. }
  23866. get color() {
  23867. return this._color;
  23868. }
  23869. set color(value) {
  23870. this._color = value;
  23871. this.paramChanged();
  23872. }
  23873. get blur() {
  23874. return this._blur;
  23875. }
  23876. set blur(value) {
  23877. this._blur = value;
  23878. this.paramChanged();
  23879. }
  23880. get offX() {
  23881. return this._offX;
  23882. }
  23883. set offX(value) {
  23884. this._offX = value;
  23885. this.paramChanged();
  23886. }
  23887. get offY() {
  23888. return this._offY;
  23889. }
  23890. set offY(value) {
  23891. this._offY = value;
  23892. this.paramChanged();
  23893. }
  23894. }
  23895. class KeyLocation {
  23896. }
  23897. KeyLocation.STANDARD = 0;
  23898. KeyLocation.LEFT = 1;
  23899. KeyLocation.RIGHT = 2;
  23900. KeyLocation.NUM_PAD = 3;
  23901. class Keyboard {
  23902. }
  23903. Keyboard.NUMBER_0 = 48;
  23904. Keyboard.NUMBER_1 = 49;
  23905. Keyboard.NUMBER_2 = 50;
  23906. Keyboard.NUMBER_3 = 51;
  23907. Keyboard.NUMBER_4 = 52;
  23908. Keyboard.NUMBER_5 = 53;
  23909. Keyboard.NUMBER_6 = 54;
  23910. Keyboard.NUMBER_7 = 55;
  23911. Keyboard.NUMBER_8 = 56;
  23912. Keyboard.NUMBER_9 = 57;
  23913. Keyboard.A = 65;
  23914. Keyboard.B = 66;
  23915. Keyboard.C = 67;
  23916. Keyboard.D = 68;
  23917. Keyboard.E = 69;
  23918. Keyboard.F = 70;
  23919. Keyboard.G = 71;
  23920. Keyboard.H = 72;
  23921. Keyboard.I = 73;
  23922. Keyboard.J = 74;
  23923. Keyboard.K = 75;
  23924. Keyboard.L = 76;
  23925. Keyboard.M = 77;
  23926. Keyboard.N = 78;
  23927. Keyboard.O = 79;
  23928. Keyboard.P = 80;
  23929. Keyboard.Q = 81;
  23930. Keyboard.R = 82;
  23931. Keyboard.S = 83;
  23932. Keyboard.T = 84;
  23933. Keyboard.U = 85;
  23934. Keyboard.V = 86;
  23935. Keyboard.W = 87;
  23936. Keyboard.X = 88;
  23937. Keyboard.Y = 89;
  23938. Keyboard.Z = 90;
  23939. Keyboard.F1 = 112;
  23940. Keyboard.F2 = 113;
  23941. Keyboard.F3 = 114;
  23942. Keyboard.F4 = 115;
  23943. Keyboard.F5 = 116;
  23944. Keyboard.F6 = 117;
  23945. Keyboard.F7 = 118;
  23946. Keyboard.F8 = 119;
  23947. Keyboard.F9 = 120;
  23948. Keyboard.F10 = 121;
  23949. Keyboard.F11 = 122;
  23950. Keyboard.F12 = 123;
  23951. Keyboard.F13 = 124;
  23952. Keyboard.F14 = 125;
  23953. Keyboard.F15 = 126;
  23954. Keyboard.NUMPAD = 21;
  23955. Keyboard.NUMPAD_0 = 96;
  23956. Keyboard.NUMPAD_1 = 97;
  23957. Keyboard.NUMPAD_2 = 98;
  23958. Keyboard.NUMPAD_3 = 99;
  23959. Keyboard.NUMPAD_4 = 100;
  23960. Keyboard.NUMPAD_5 = 101;
  23961. Keyboard.NUMPAD_6 = 102;
  23962. Keyboard.NUMPAD_7 = 103;
  23963. Keyboard.NUMPAD_8 = 104;
  23964. Keyboard.NUMPAD_9 = 105;
  23965. Keyboard.NUMPAD_ADD = 107;
  23966. Keyboard.NUMPAD_DECIMAL = 110;
  23967. Keyboard.NUMPAD_DIVIDE = 111;
  23968. Keyboard.NUMPAD_ENTER = 108;
  23969. Keyboard.NUMPAD_MULTIPLY = 106;
  23970. Keyboard.NUMPAD_SUBTRACT = 109;
  23971. Keyboard.SEMICOLON = 186;
  23972. Keyboard.EQUAL = 187;
  23973. Keyboard.COMMA = 188;
  23974. Keyboard.MINUS = 189;
  23975. Keyboard.PERIOD = 190;
  23976. Keyboard.SLASH = 191;
  23977. Keyboard.BACKQUOTE = 192;
  23978. Keyboard.LEFTBRACKET = 219;
  23979. Keyboard.BACKSLASH = 220;
  23980. Keyboard.RIGHTBRACKET = 221;
  23981. Keyboard.QUOTE = 222;
  23982. Keyboard.ALTERNATE = 18;
  23983. Keyboard.BACKSPACE = 8;
  23984. Keyboard.CAPS_LOCK = 20;
  23985. Keyboard.COMMAND = 15;
  23986. Keyboard.CONTROL = 17;
  23987. Keyboard.DELETE = 46;
  23988. Keyboard.ENTER = 13;
  23989. Keyboard.ESCAPE = 27;
  23990. Keyboard.PAGE_UP = 33;
  23991. Keyboard.PAGE_DOWN = 34;
  23992. Keyboard.END = 35;
  23993. Keyboard.HOME = 36;
  23994. Keyboard.LEFT = 37;
  23995. Keyboard.UP = 38;
  23996. Keyboard.RIGHT = 39;
  23997. Keyboard.DOWN = 40;
  23998. Keyboard.SHIFT = 16;
  23999. Keyboard.SPACE = 32;
  24000. Keyboard.TAB = 9;
  24001. Keyboard.INSERT = 45;
  24002. class CommandEncoder {
  24003. constructor(layagl, reserveSize, adjustSize, isSyncToRenderThread) {
  24004. this._idata = [];
  24005. }
  24006. getArrayData() {
  24007. return this._idata;
  24008. }
  24009. getPtrID() {
  24010. return 0;
  24011. }
  24012. beginEncoding() {
  24013. }
  24014. endEncoding() {
  24015. }
  24016. clearEncoding() {
  24017. this._idata.length = 0;
  24018. }
  24019. getCount() {
  24020. return this._idata.length;
  24021. }
  24022. add_ShaderValue(o) {
  24023. this._idata.push(o);
  24024. }
  24025. addShaderUniform(one) {
  24026. this.add_ShaderValue(one);
  24027. }
  24028. }
  24029. class LayaGLRunner {
  24030. static uploadShaderUniforms(layaGL, commandEncoder, shaderData, uploadUnTexture) {
  24031. var data = shaderData._data;
  24032. var shaderUniform = commandEncoder.getArrayData();
  24033. var shaderCall = 0;
  24034. for (var i = 0, n = shaderUniform.length; i < n; i++) {
  24035. var one = shaderUniform[i];
  24036. if (uploadUnTexture || one.textureID !== -1) {
  24037. var value = data[one.dataOffset];
  24038. if (value != null)
  24039. shaderCall += one.fun.call(one.caller, one, value);
  24040. }
  24041. }
  24042. return shaderCall;
  24043. }
  24044. static uploadCustomUniform(layaGL, custom, index, data) {
  24045. var shaderCall = 0;
  24046. var one = custom[index];
  24047. if (one && data != null)
  24048. shaderCall += one.fun.call(one.caller, one, data);
  24049. return shaderCall;
  24050. }
  24051. static uploadShaderUniformsForNative(layaGL, commandEncoder, shaderData) {
  24052. return LayaGL.instance.uploadShaderUniforms(commandEncoder, shaderData._data, shaderData._runtimeCopyValues.length > 0 ? LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_DATA : LayaGL.UPLOAD_SHADER_UNIFORM_TYPE_ID);
  24053. }
  24054. }
  24055. class QuickTestTool {
  24056. constructor() {
  24057. }
  24058. static getMCDName(type) {
  24059. return QuickTestTool._typeToNameDic[type];
  24060. }
  24061. static showRenderTypeInfo(type, force = false) {
  24062. if (!force && QuickTestTool.showedDic[type])
  24063. return;
  24064. QuickTestTool.showedDic[type] = true;
  24065. if (!QuickTestTool._rendertypeToStrDic[type]) {
  24066. var arr = [];
  24067. var tType;
  24068. tType = 1;
  24069. while (tType <= type) {
  24070. if (tType & type) {
  24071. arr.push(QuickTestTool.getMCDName(tType & type));
  24072. }
  24073. tType = tType << 1;
  24074. }
  24075. QuickTestTool._rendertypeToStrDic[type] = arr.join(",");
  24076. }
  24077. console.log("cmd:", QuickTestTool._rendertypeToStrDic[type]);
  24078. }
  24079. static __init__() {
  24080. QuickTestTool._typeToNameDic[SpriteConst.ALPHA] = "ALPHA";
  24081. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM] = "TRANSFORM";
  24082. QuickTestTool._typeToNameDic[SpriteConst.TEXTURE] = "TEXTURE";
  24083. QuickTestTool._typeToNameDic[SpriteConst.GRAPHICS] = "GRAPHICS";
  24084. QuickTestTool._typeToNameDic[SpriteConst.ONECHILD] = "ONECHILD";
  24085. QuickTestTool._typeToNameDic[SpriteConst.CHILDS] = "CHILDS";
  24086. QuickTestTool._typeToNameDic[SpriteConst.TRANSFORM | SpriteConst.ALPHA] = "TRANSFORM|ALPHA";
  24087. QuickTestTool._typeToNameDic[SpriteConst.CANVAS] = "CANVAS";
  24088. QuickTestTool._typeToNameDic[SpriteConst.BLEND] = "BLEND";
  24089. QuickTestTool._typeToNameDic[SpriteConst.FILTERS] = "FILTERS";
  24090. QuickTestTool._typeToNameDic[SpriteConst.MASK] = "MASK";
  24091. QuickTestTool._typeToNameDic[SpriteConst.CLIP] = "CLIP";
  24092. QuickTestTool._typeToNameDic[SpriteConst.LAYAGL3D] = "LAYAGL3D";
  24093. }
  24094. render(context, x, y) {
  24095. QuickTestTool._addType(this._renderType);
  24096. QuickTestTool.showRenderTypeInfo(this._renderType);
  24097. RenderSprite.renders[this._renderType]._fun(this, context, x + this._x, y + this._y);
  24098. this._repaint = 0;
  24099. }
  24100. _stageRender(context, x, y) {
  24101. QuickTestTool._countStart();
  24102. QuickTestTool._PreStageRender.call(ILaya.stage, context, x, y);
  24103. QuickTestTool._countEnd();
  24104. }
  24105. static _countStart() {
  24106. var key;
  24107. for (key in QuickTestTool._countDic) {
  24108. QuickTestTool._countDic[key] = 0;
  24109. }
  24110. }
  24111. static _countEnd() {
  24112. QuickTestTool._i++;
  24113. if (QuickTestTool._i > 60) {
  24114. QuickTestTool.showCountInfo();
  24115. QuickTestTool._i = 0;
  24116. }
  24117. }
  24118. static _addType(type) {
  24119. if (!QuickTestTool._countDic[type]) {
  24120. QuickTestTool._countDic[type] = 1;
  24121. }
  24122. else {
  24123. QuickTestTool._countDic[type] += 1;
  24124. }
  24125. }
  24126. static showCountInfo() {
  24127. console.log("===================");
  24128. var key;
  24129. for (key in QuickTestTool._countDic) {
  24130. console.log("count:" + QuickTestTool._countDic[key]);
  24131. QuickTestTool.showRenderTypeInfo(key, true);
  24132. }
  24133. }
  24134. static enableQuickTest() {
  24135. QuickTestTool.__init__();
  24136. Sprite["prototype"]["render"] = QuickTestTool["prototype"]["render"];
  24137. QuickTestTool._PreStageRender = Stage["prototype"]["render"];
  24138. Stage["prototype"]["render"] = QuickTestTool["prototype"]["_stageRender"];
  24139. }
  24140. }
  24141. QuickTestTool.showedDic = {};
  24142. QuickTestTool._rendertypeToStrDic = {};
  24143. QuickTestTool._typeToNameDic = {};
  24144. QuickTestTool._countDic = {};
  24145. QuickTestTool._i = 0;
  24146. class Sound extends EventDispatcher {
  24147. load(url) {
  24148. }
  24149. play(startTime = 0, loops = 0) {
  24150. return null;
  24151. }
  24152. get duration() {
  24153. return 0;
  24154. }
  24155. dispose() {
  24156. }
  24157. }
  24158. class SoundNode extends Sprite {
  24159. constructor() {
  24160. super();
  24161. this.visible = false;
  24162. this.on(Event.ADDED, this, this._onParentChange);
  24163. this.on(Event.REMOVED, this, this._onParentChange);
  24164. }
  24165. _onParentChange() {
  24166. this.target = this.parent;
  24167. }
  24168. play(loops = 1, complete = null) {
  24169. if (isNaN(loops)) {
  24170. loops = 1;
  24171. }
  24172. if (!this.url)
  24173. return;
  24174. this.stop();
  24175. this._channel = SoundManager.playSound(this.url, loops, complete);
  24176. }
  24177. stop() {
  24178. if (this._channel && !this._channel.isStopped) {
  24179. this._channel.stop();
  24180. }
  24181. this._channel = null;
  24182. }
  24183. _setPlayAction(tar, event, action, add = true) {
  24184. if (!this[action])
  24185. return;
  24186. if (!tar)
  24187. return;
  24188. if (add) {
  24189. tar.on(event, this, this[action]);
  24190. }
  24191. else {
  24192. tar.off(event, this, this[action]);
  24193. }
  24194. }
  24195. _setPlayActions(tar, events, action, add = true) {
  24196. if (!tar)
  24197. return;
  24198. if (!events)
  24199. return;
  24200. var eventArr = events.split(",");
  24201. var i, len;
  24202. len = eventArr.length;
  24203. for (i = 0; i < len; i++) {
  24204. this._setPlayAction(tar, eventArr[i], action, add);
  24205. }
  24206. }
  24207. set playEvent(events) {
  24208. this._playEvents = events;
  24209. if (!events)
  24210. return;
  24211. if (this._tar) {
  24212. this._setPlayActions(this._tar, events, "play");
  24213. }
  24214. }
  24215. set target(tar) {
  24216. if (this._tar) {
  24217. this._setPlayActions(this._tar, this._playEvents, "play", false);
  24218. this._setPlayActions(this._tar, this._stopEvents, "stop", false);
  24219. }
  24220. this._tar = tar;
  24221. if (this._tar) {
  24222. this._setPlayActions(this._tar, this._playEvents, "play", true);
  24223. this._setPlayActions(this._tar, this._stopEvents, "stop", true);
  24224. }
  24225. }
  24226. set stopEvent(events) {
  24227. this._stopEvents = events;
  24228. if (!events)
  24229. return;
  24230. if (this._tar) {
  24231. this._setPlayActions(this._tar, events, "stop");
  24232. }
  24233. }
  24234. }
  24235. class ResourceVersion {
  24236. static enable(manifestFile, callback, type = 2) {
  24237. ResourceVersion.type = type;
  24238. ILaya.loader.load(manifestFile, Handler.create(null, ResourceVersion.onManifestLoaded, [callback]), null, Loader.JSON);
  24239. }
  24240. static onManifestLoaded(callback, data) {
  24241. ResourceVersion.manifest = data;
  24242. URL.customFormat = ResourceVersion.addVersionPrefix;
  24243. callback.run();
  24244. if (!data) {
  24245. console.warn("资源版本清单文件不存在,不使用资源版本管理。忽略ERR_FILE_NOT_FOUND错误。");
  24246. }
  24247. }
  24248. static addVersionPrefix(originURL) {
  24249. originURL = URL.getAdptedFilePath(originURL);
  24250. if (ResourceVersion.manifest && ResourceVersion.manifest[originURL]) {
  24251. if (ResourceVersion.type == ResourceVersion.FILENAME_VERSION)
  24252. return ResourceVersion.manifest[originURL];
  24253. return ResourceVersion.manifest[originURL] + "/" + originURL;
  24254. }
  24255. return originURL;
  24256. }
  24257. }
  24258. ResourceVersion.FOLDER_VERSION = 1;
  24259. ResourceVersion.FILENAME_VERSION = 2;
  24260. ResourceVersion.type = ResourceVersion.FOLDER_VERSION;
  24261. class Socket extends EventDispatcher {
  24262. constructor(host = null, port = 0, byteClass = null, protocols = null) {
  24263. super();
  24264. this.disableInput = false;
  24265. this.protocols = [];
  24266. this._byteClass = byteClass ? byteClass : Byte;
  24267. this.protocols = protocols;
  24268. this.endian = Socket.BIG_ENDIAN;
  24269. if (host && port > 0 && port < 65535)
  24270. this.connect(host, port);
  24271. }
  24272. get input() {
  24273. return this._input;
  24274. }
  24275. get output() {
  24276. return this._output;
  24277. }
  24278. get connected() {
  24279. return this._connected;
  24280. }
  24281. get endian() {
  24282. return this._endian;
  24283. }
  24284. set endian(value) {
  24285. this._endian = value;
  24286. if (this._input != null)
  24287. this._input.endian = value;
  24288. if (this._output != null)
  24289. this._output.endian = value;
  24290. }
  24291. connect(host, port) {
  24292. var url = "ws://" + host + ":" + port;
  24293. this.connectByUrl(url);
  24294. }
  24295. connectByUrl(url) {
  24296. if (this._socket != null)
  24297. this.close();
  24298. this._socket && this.cleanSocket();
  24299. if (!this.protocols || this.protocols.length == 0) {
  24300. this._socket = new Browser.window.WebSocket(url);
  24301. }
  24302. else {
  24303. this._socket = new Browser.window.WebSocket(url, this.protocols);
  24304. }
  24305. this._socket.binaryType = "arraybuffer";
  24306. this._output = new this._byteClass();
  24307. this._output.endian = this.endian;
  24308. this._input = new this._byteClass();
  24309. this._input.endian = this.endian;
  24310. this._addInputPosition = 0;
  24311. this._socket.onopen = (e) => {
  24312. this._onOpen(e);
  24313. };
  24314. this._socket.onmessage = (msg) => {
  24315. this._onMessage(msg);
  24316. };
  24317. this._socket.onclose = (e) => {
  24318. this._onClose(e);
  24319. };
  24320. this._socket.onerror = (e) => {
  24321. this._onError(e);
  24322. };
  24323. }
  24324. cleanSocket() {
  24325. this.close();
  24326. this._connected = false;
  24327. this._socket.onopen = null;
  24328. this._socket.onmessage = null;
  24329. this._socket.onclose = null;
  24330. this._socket.onerror = null;
  24331. this._socket = null;
  24332. }
  24333. close() {
  24334. if (this._socket != null) {
  24335. try {
  24336. this._socket.close();
  24337. }
  24338. catch (e) {
  24339. }
  24340. }
  24341. }
  24342. _onOpen(e) {
  24343. this._connected = true;
  24344. this.event(Event.OPEN, e);
  24345. }
  24346. _onMessage(msg) {
  24347. if (!msg || !msg.data)
  24348. return;
  24349. var data = msg.data;
  24350. if (this.disableInput && data) {
  24351. this.event(Event.MESSAGE, data);
  24352. return;
  24353. }
  24354. if (this._input.length > 0 && this._input.bytesAvailable < 1) {
  24355. this._input.clear();
  24356. this._addInputPosition = 0;
  24357. }
  24358. var pre = this._input.pos;
  24359. !this._addInputPosition && (this._addInputPosition = 0);
  24360. this._input.pos = this._addInputPosition;
  24361. if (data) {
  24362. if (typeof (data) == 'string') {
  24363. this._input.writeUTFBytes(data);
  24364. }
  24365. else {
  24366. this._input.writeArrayBuffer(data);
  24367. }
  24368. this._addInputPosition = this._input.pos;
  24369. this._input.pos = pre;
  24370. }
  24371. this.event(Event.MESSAGE, data);
  24372. }
  24373. _onClose(e) {
  24374. this._connected = false;
  24375. this.event(Event.CLOSE, e);
  24376. }
  24377. _onError(e) {
  24378. this.event(Event.ERROR, e);
  24379. }
  24380. send(data) {
  24381. this._socket.send(data);
  24382. }
  24383. flush() {
  24384. if (this._output && this._output.length > 0) {
  24385. var evt;
  24386. try {
  24387. this._socket && this._socket.send(this._output.__getBuffer().slice(0, this._output.length));
  24388. }
  24389. catch (e) {
  24390. evt = e;
  24391. }
  24392. this._output.endian = this.endian;
  24393. this._output.clear();
  24394. if (evt)
  24395. this.event(Event.ERROR, evt);
  24396. }
  24397. }
  24398. }
  24399. Socket.LITTLE_ENDIAN = "littleEndian";
  24400. Socket.BIG_ENDIAN = "bigEndian";
  24401. class System {
  24402. static changeDefinition(name, classObj) {
  24403. window.Laya[name] = classObj;
  24404. var str = name + "=classObj";
  24405. window['eval'](str);
  24406. }
  24407. }
  24408. class HTMLChar {
  24409. constructor() {
  24410. this.reset();
  24411. }
  24412. setData(char, w, h, style) {
  24413. this.char = char;
  24414. this.charNum = char.charCodeAt(0);
  24415. this.x = this.y = 0;
  24416. this.width = w;
  24417. this.height = h;
  24418. this.style = style;
  24419. this.isWord = !HTMLChar._isWordRegExp.test(char);
  24420. return this;
  24421. }
  24422. reset() {
  24423. this.x = this.y = this.width = this.height = 0;
  24424. this.isWord = false;
  24425. this.char = null;
  24426. this.charNum = 0;
  24427. this.style = null;
  24428. return this;
  24429. }
  24430. recover() {
  24431. Pool.recover("HTMLChar", this.reset());
  24432. }
  24433. static create() {
  24434. return Pool.getItemByClass("HTMLChar", HTMLChar);
  24435. }
  24436. _isChar() {
  24437. return true;
  24438. }
  24439. _getCSSStyle() {
  24440. return this.style;
  24441. }
  24442. }
  24443. HTMLChar._isWordRegExp = new RegExp("[\\w\.]", "");
  24444. class Log {
  24445. static enable() {
  24446. if (!Log._logdiv) {
  24447. Log._logdiv = Browser.createElement('div');
  24448. 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%;";
  24449. Browser.document.body.appendChild(Log._logdiv);
  24450. Log._btn = Browser.createElement("button");
  24451. Log._btn.innerText = "Hide";
  24452. Log._btn.style.cssText = "z-index:1000001;position: absolute;left:10px;top:10px;";
  24453. Log._btn.onclick = Log.toggle;
  24454. Browser.document.body.appendChild(Log._btn);
  24455. }
  24456. }
  24457. static toggle() {
  24458. var style = Log._logdiv.style;
  24459. if (style.display === "") {
  24460. Log._btn.innerText = "Show";
  24461. style.display = "none";
  24462. }
  24463. else {
  24464. Log._btn.innerText = "Hide";
  24465. style.display = "";
  24466. }
  24467. }
  24468. static print(value) {
  24469. if (Log._logdiv) {
  24470. if (Log._count >= Log.maxCount)
  24471. Log.clear();
  24472. Log._count++;
  24473. Log._logdiv.innerText += value + "\n";
  24474. if (Log.autoScrollToBottom) {
  24475. if (Log._logdiv.scrollHeight - Log._logdiv.scrollTop - Log._logdiv.clientHeight < 50) {
  24476. Log._logdiv.scrollTop = Log._logdiv.scrollHeight;
  24477. }
  24478. }
  24479. }
  24480. }
  24481. static clear() {
  24482. Log._logdiv.innerText = "";
  24483. Log._count = 0;
  24484. }
  24485. }
  24486. Log._count = 0;
  24487. Log.maxCount = 50;
  24488. Log.autoScrollToBottom = true;
  24489. let DATANUM = 300;
  24490. class PerfData {
  24491. constructor(id, color, name, scale) {
  24492. this.scale = 1.0;
  24493. this.datas = new Array(DATANUM);
  24494. this.datapos = 0;
  24495. this.id = id;
  24496. this.color = color;
  24497. this.name = name;
  24498. this.scale = scale;
  24499. }
  24500. addData(v) {
  24501. this.datas[this.datapos] = v;
  24502. this.datapos++;
  24503. this.datapos %= DATANUM;
  24504. }
  24505. }
  24506. class PerfHUD extends Sprite {
  24507. constructor() {
  24508. super();
  24509. this.datas = [];
  24510. this.xdata = new Array(PerfHUD.DATANUM);
  24511. this.ydata = new Array(PerfHUD.DATANUM);
  24512. this.hud_width = 800;
  24513. this.hud_height = 200;
  24514. this.gMinV = 0;
  24515. this.gMaxV = 100;
  24516. this.textSpace = 40;
  24517. this.sttm = 0;
  24518. PerfHUD.inst = this;
  24519. this._renderType |= SpriteConst.CUSTOM;
  24520. this._setRenderType(this._renderType);
  24521. this._setCustomRender();
  24522. this.addDataDef(0, 0xffffff, 'frame', 1.0);
  24523. this.addDataDef(1, 0x00ff00, 'update', 1.0);
  24524. this.addDataDef(2, 0xff0000, 'flush', 1.0);
  24525. PerfHUD._now = performance ? performance.now.bind(performance) : Date.now;
  24526. }
  24527. now() {
  24528. return PerfHUD._now();
  24529. }
  24530. start() {
  24531. this.sttm = PerfHUD._now();
  24532. }
  24533. end(i) {
  24534. var dt = PerfHUD._now() - this.sttm;
  24535. this.updateValue(i, dt);
  24536. }
  24537. config(w, h) {
  24538. this.hud_width = w;
  24539. this.hud_height = h;
  24540. }
  24541. addDataDef(id, color, name, scale) {
  24542. this.datas[id] = new PerfData(id, color, name, scale);
  24543. }
  24544. updateValue(id, v) {
  24545. this.datas[id].addData(v);
  24546. }
  24547. v2y(v) {
  24548. var bb = this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24549. return this._y + this.hud_height * (1 - (v - this.gMinV) / this.gMaxV);
  24550. }
  24551. drawHLine(ctx, v, color, text) {
  24552. var sx = this._x;
  24553. var ex = this._x + this.hud_width;
  24554. var sy = this.v2y(v);
  24555. ctx.fillText(text, sx, sy - 6, null, 'green', null);
  24556. sx += this.textSpace;
  24557. ctx.fillStyle = color;
  24558. ctx.fillRect(sx, sy, this._x + this.hud_width, 1, null);
  24559. }
  24560. customRender(ctx, x, y) {
  24561. var now = performance.now();
  24562. if (PerfHUD._lastTm <= 0)
  24563. PerfHUD._lastTm = now;
  24564. this.updateValue(0, now - PerfHUD._lastTm);
  24565. PerfHUD._lastTm = now;
  24566. ctx.save();
  24567. ctx.fillRect(this._x, this._y, this.hud_width, this.hud_height + 4, '#000000cc');
  24568. ctx.globalAlpha = 0.9;
  24569. this.drawHLine(ctx, 0, 'green', ' 0');
  24570. this.drawHLine(ctx, 10, 'green', ' 10');
  24571. this.drawHLine(ctx, 16.667, 'red', ' ');
  24572. this.drawHLine(ctx, 20, 'green', '50|20');
  24573. this.drawHLine(ctx, 16.667 * 2, 'yellow', '');
  24574. this.drawHLine(ctx, 16.667 * 3, 'yellow', '');
  24575. this.drawHLine(ctx, 16.667 * 4, 'yellow', '');
  24576. this.drawHLine(ctx, 50, 'green', '20|50');
  24577. this.drawHLine(ctx, 100, 'green', '10|100');
  24578. for (var di = 0, sz = this.datas.length; di < sz; di++) {
  24579. var cd = this.datas[di];
  24580. if (!cd)
  24581. continue;
  24582. var dtlen = cd.datas.length;
  24583. var dx = (this.hud_width - this.textSpace) / dtlen;
  24584. var cx = cd.datapos;
  24585. var _cx = this._x + this.textSpace;
  24586. ctx.fillStyle = cd.color;
  24587. for (var dtsz = dtlen; cx < dtsz; cx++) {
  24588. var sty = this.v2y(cd.datas[cx] * cd.scale);
  24589. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24590. _cx += dx;
  24591. }
  24592. for (cx = 0; cx < cd.datapos; cx++) {
  24593. sty = this.v2y(cd.datas[cx] * cd.scale);
  24594. ctx.fillRect(_cx, sty, dx, this.hud_height + this._y - sty, null);
  24595. _cx += dx;
  24596. }
  24597. }
  24598. ctx.restore();
  24599. }
  24600. }
  24601. PerfHUD._lastTm = 0;
  24602. PerfHUD._now = null;
  24603. PerfHUD.DATANUM = 300;
  24604. PerfHUD.drawTexTm = 0;
  24605. class PoolCache {
  24606. constructor() {
  24607. this.maxCount = 1000;
  24608. }
  24609. getCacheList() {
  24610. return Pool.getPoolBySign(this.sign);
  24611. }
  24612. tryDispose(force) {
  24613. var list;
  24614. list = Pool.getPoolBySign(this.sign);
  24615. if (list.length > this.maxCount) {
  24616. list.splice(this.maxCount, list.length - this.maxCount);
  24617. }
  24618. }
  24619. static addPoolCacheManager(sign, maxCount = 100) {
  24620. var cache;
  24621. cache = new PoolCache();
  24622. cache.sign = sign;
  24623. cache.maxCount = maxCount;
  24624. CacheManger.regCacheByFunction(Utils.bind(cache.tryDispose, cache), Utils.bind(cache.getCacheList, cache));
  24625. }
  24626. }
  24627. class TimeLine extends EventDispatcher {
  24628. constructor() {
  24629. super(...arguments);
  24630. this._tweenDic = {};
  24631. this._tweenDataList = [];
  24632. this._currTime = 0;
  24633. this._lastTime = 0;
  24634. this._startTime = 0;
  24635. this._index = 0;
  24636. this._gidIndex = 0;
  24637. this._firstTweenDic = {};
  24638. this._startTimeSort = false;
  24639. this._endTimeSort = false;
  24640. this._loopKey = false;
  24641. this.scale = 1;
  24642. this._frameRate = 60;
  24643. this._frameIndex = 0;
  24644. this._total = 0;
  24645. }
  24646. static to(target, props, duration, ease = null, offset = 0) {
  24647. return (new TimeLine()).to(target, props, duration, ease, offset);
  24648. }
  24649. static from(target, props, duration, ease = null, offset = 0) {
  24650. return (new TimeLine()).from(target, props, duration, ease, offset);
  24651. }
  24652. to(target, props, duration, ease = null, offset = 0) {
  24653. return this._create(target, props, duration, ease, offset, true);
  24654. }
  24655. from(target, props, duration, ease = null, offset = 0) {
  24656. return this._create(target, props, duration, ease, offset, false);
  24657. }
  24658. _create(target, props, duration, ease, offset, isTo) {
  24659. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24660. tTweenData.isTo = isTo;
  24661. tTweenData.type = 0;
  24662. tTweenData.target = target;
  24663. tTweenData.duration = duration;
  24664. tTweenData.data = props;
  24665. tTweenData.startTime = this._startTime + offset;
  24666. tTweenData.endTime = tTweenData.startTime + tTweenData.duration;
  24667. tTweenData.ease = ease;
  24668. this._startTime = Math.max(tTweenData.endTime, this._startTime);
  24669. this._tweenDataList.push(tTweenData);
  24670. this._startTimeSort = true;
  24671. this._endTimeSort = true;
  24672. return this;
  24673. }
  24674. addLabel(label, offset) {
  24675. var tTweenData = Pool.getItemByClass("tweenData", tweenData);
  24676. tTweenData.type = 1;
  24677. tTweenData.data = label;
  24678. tTweenData.endTime = tTweenData.startTime = this._startTime + offset;
  24679. this._labelDic || (this._labelDic = {});
  24680. this._labelDic[label] = tTweenData;
  24681. this._tweenDataList.push(tTweenData);
  24682. return this;
  24683. }
  24684. removeLabel(label) {
  24685. if (this._labelDic && this._labelDic[label]) {
  24686. var tTweenData = this._labelDic[label];
  24687. if (tTweenData) {
  24688. var tIndex = this._tweenDataList.indexOf(tTweenData);
  24689. if (tIndex > -1) {
  24690. this._tweenDataList.splice(tIndex, 1);
  24691. }
  24692. }
  24693. delete this._labelDic[label];
  24694. }
  24695. }
  24696. gotoTime(time) {
  24697. if (this._tweenDataList == null || this._tweenDataList.length == 0)
  24698. return;
  24699. var tTween;
  24700. var tObject;
  24701. for (var p in this._firstTweenDic) {
  24702. tObject = this._firstTweenDic[p];
  24703. if (tObject) {
  24704. for (var tDataP in tObject) {
  24705. if (tDataP in tObject.diyTarget) {
  24706. tObject.diyTarget[tDataP] = tObject[tDataP];
  24707. }
  24708. }
  24709. }
  24710. }
  24711. for (p in this._tweenDic) {
  24712. tTween = this._tweenDic[p];
  24713. tTween.clear();
  24714. delete this._tweenDic[p];
  24715. }
  24716. this._index = 0;
  24717. this._gidIndex = 0;
  24718. this._currTime = time;
  24719. this._lastTime = Browser.now();
  24720. var tTweenDataCopyList;
  24721. if (this._endTweenDataList == null || this._endTimeSort) {
  24722. this._endTimeSort = false;
  24723. this._endTweenDataList = tTweenDataCopyList = this._tweenDataList.concat();
  24724. function Compare(paraA, paraB) {
  24725. if (paraA.endTime > paraB.endTime) {
  24726. return 1;
  24727. }
  24728. else if (paraA.endTime < paraB.endTime) {
  24729. return -1;
  24730. }
  24731. else {
  24732. return 0;
  24733. }
  24734. }
  24735. tTweenDataCopyList.sort(Compare);
  24736. }
  24737. else {
  24738. tTweenDataCopyList = this._endTweenDataList;
  24739. }
  24740. var tTweenData;
  24741. for (var i = 0, n = tTweenDataCopyList.length; i < n; i++) {
  24742. tTweenData = tTweenDataCopyList[i];
  24743. if (tTweenData.type == 0) {
  24744. if (time >= tTweenData.endTime) {
  24745. this._index = Math.max(this._index, i + 1);
  24746. var props = tTweenData.data;
  24747. if (tTweenData.isTo) {
  24748. for (var tP in props) {
  24749. tTweenData.target[tP] = props[tP];
  24750. }
  24751. }
  24752. }
  24753. else {
  24754. break;
  24755. }
  24756. }
  24757. }
  24758. for (i = 0, n = this._tweenDataList.length; i < n; i++) {
  24759. tTweenData = this._tweenDataList[i];
  24760. if (tTweenData.type == 0) {
  24761. if (time >= tTweenData.startTime && time < tTweenData.endTime) {
  24762. this._index = Math.max(this._index, i + 1);
  24763. this._gidIndex++;
  24764. tTween = Pool.getItemByClass("tween", Tween);
  24765. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  24766. tTween.setStartTime(this._currTime - (time - tTweenData.startTime));
  24767. tTween._updateEase(this._currTime);
  24768. tTween.gid = this._gidIndex;
  24769. this._tweenDic[this._gidIndex] = tTween;
  24770. }
  24771. }
  24772. }
  24773. }
  24774. gotoLabel(Label) {
  24775. if (this._labelDic == null)
  24776. return;
  24777. var tLabelData = this._labelDic[Label];
  24778. if (tLabelData)
  24779. this.gotoTime(tLabelData.startTime);
  24780. }
  24781. pause() {
  24782. ILaya.timer.clear(this, this._update);
  24783. }
  24784. resume() {
  24785. this.play(this._currTime, this._loopKey);
  24786. }
  24787. play(timeOrLabel = 0, loop = false) {
  24788. if (!this._tweenDataList)
  24789. return;
  24790. if (this._startTimeSort) {
  24791. this._startTimeSort = false;
  24792. function Compare(paraA, paraB) {
  24793. if (paraA.startTime > paraB.startTime) {
  24794. return 1;
  24795. }
  24796. else if (paraA.startTime < paraB.startTime) {
  24797. return -1;
  24798. }
  24799. else {
  24800. return 0;
  24801. }
  24802. }
  24803. this._tweenDataList.sort(Compare);
  24804. for (var i = 0, n = this._tweenDataList.length; i < n; i++) {
  24805. var tTweenData = this._tweenDataList[i];
  24806. if (tTweenData != null && tTweenData.type == 0) {
  24807. var tTarget = tTweenData.target;
  24808. var gid = (tTarget.$_GID || (tTarget.$_GID = Utils.getGID()));
  24809. var tSrcData = null;
  24810. if (this._firstTweenDic[gid] == null) {
  24811. tSrcData = {};
  24812. tSrcData.diyTarget = tTarget;
  24813. this._firstTweenDic[gid] = tSrcData;
  24814. }
  24815. else {
  24816. tSrcData = this._firstTweenDic[gid];
  24817. }
  24818. for (var p in tTweenData.data) {
  24819. if (tSrcData[p] == null) {
  24820. tSrcData[p] = tTarget[p];
  24821. }
  24822. }
  24823. }
  24824. }
  24825. }
  24826. if (typeof (timeOrLabel) == 'string') {
  24827. this.gotoLabel(timeOrLabel);
  24828. }
  24829. else {
  24830. this.gotoTime(timeOrLabel);
  24831. }
  24832. this._loopKey = loop;
  24833. this._lastTime = Browser.now();
  24834. ILaya.timer.frameLoop(1, this, this._update);
  24835. }
  24836. _update() {
  24837. if (this._currTime >= this._startTime) {
  24838. if (this._loopKey) {
  24839. this._complete();
  24840. if (!this._tweenDataList)
  24841. return;
  24842. this.gotoTime(0);
  24843. }
  24844. else {
  24845. for (var p in this._tweenDic) {
  24846. tTween = this._tweenDic[p];
  24847. tTween.complete();
  24848. }
  24849. this._complete();
  24850. this.pause();
  24851. return;
  24852. }
  24853. }
  24854. var tNow = Browser.now();
  24855. var tFrameTime = tNow - this._lastTime;
  24856. var tCurrTime = this._currTime += tFrameTime * this.scale;
  24857. this._lastTime = tNow;
  24858. for (p in this._tweenDic) {
  24859. tTween = this._tweenDic[p];
  24860. tTween._updateEase(tCurrTime);
  24861. }
  24862. var tTween;
  24863. if (this._tweenDataList.length != 0 && this._index < this._tweenDataList.length) {
  24864. var tTweenData = this._tweenDataList[this._index];
  24865. if (tCurrTime >= tTweenData.startTime) {
  24866. this._index++;
  24867. if (tTweenData.type == 0) {
  24868. this._gidIndex++;
  24869. tTween = Pool.getItemByClass("tween", Tween);
  24870. tTween._create(tTweenData.target, tTweenData.data, tTweenData.duration, tTweenData.ease, Handler.create(this, this._animComplete, [this._gidIndex]), 0, false, tTweenData.isTo, true, false);
  24871. tTween.setStartTime(tCurrTime);
  24872. tTween.gid = this._gidIndex;
  24873. this._tweenDic[this._gidIndex] = tTween;
  24874. tTween._updateEase(tCurrTime);
  24875. }
  24876. else {
  24877. this.event(Event.LABEL, tTweenData.data);
  24878. }
  24879. }
  24880. }
  24881. }
  24882. _animComplete(index) {
  24883. var tTween = this._tweenDic[index];
  24884. if (tTween)
  24885. delete this._tweenDic[index];
  24886. }
  24887. _complete() {
  24888. this.event(Event.COMPLETE);
  24889. }
  24890. get index() {
  24891. return this._frameIndex;
  24892. }
  24893. set index(value) {
  24894. this._frameIndex = value;
  24895. this.gotoTime(this._frameIndex / this._frameRate * 1000);
  24896. }
  24897. get total() {
  24898. this._total = Math.floor(this._startTime / 1000 * this._frameRate);
  24899. return this._total;
  24900. }
  24901. reset() {
  24902. var p;
  24903. if (this._labelDic) {
  24904. for (p in this._labelDic) {
  24905. delete this._labelDic[p];
  24906. }
  24907. }
  24908. var tTween;
  24909. for (p in this._tweenDic) {
  24910. tTween = this._tweenDic[p];
  24911. tTween.clear();
  24912. delete this._tweenDic[p];
  24913. }
  24914. for (p in this._firstTweenDic) {
  24915. delete this._firstTweenDic[p];
  24916. }
  24917. this._endTweenDataList = null;
  24918. if (this._tweenDataList && this._tweenDataList.length) {
  24919. var i, len;
  24920. len = this._tweenDataList.length;
  24921. for (i = 0; i < len; i++) {
  24922. if (this._tweenDataList[i])
  24923. this._tweenDataList[i].destroy();
  24924. }
  24925. }
  24926. this._tweenDataList.length = 0;
  24927. this._currTime = 0;
  24928. this._lastTime = 0;
  24929. this._startTime = 0;
  24930. this._index = 0;
  24931. this._gidIndex = 0;
  24932. this.scale = 1;
  24933. ILaya.timer.clear(this, this._update);
  24934. }
  24935. destroy() {
  24936. this.reset();
  24937. this._labelDic = null;
  24938. this._tweenDic = null;
  24939. this._tweenDataList = null;
  24940. this._firstTweenDic = null;
  24941. }
  24942. }
  24943. class tweenData {
  24944. constructor() {
  24945. this.type = 0;
  24946. this.isTo = true;
  24947. }
  24948. destroy() {
  24949. this.target = null;
  24950. this.ease = null;
  24951. this.data = null;
  24952. this.isTo = true;
  24953. this.type = 0;
  24954. Pool.recover("tweenData", this);
  24955. }
  24956. }
  24957. class ShaderValue {
  24958. constructor() {
  24959. }
  24960. }
  24961. class ArabicReshaper {
  24962. characterMapContains(c) {
  24963. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  24964. if (ArabicReshaper.charsMap[i][0] === c) {
  24965. return true;
  24966. }
  24967. }
  24968. return false;
  24969. }
  24970. getCharRep(c) {
  24971. for (var i = 0; i < ArabicReshaper.charsMap.length; ++i) {
  24972. if (ArabicReshaper.charsMap[i][0] === c) {
  24973. return ArabicReshaper.charsMap[i];
  24974. }
  24975. }
  24976. return false;
  24977. }
  24978. getCombCharRep(c1, c2) {
  24979. for (var i = 0; i < ArabicReshaper.combCharsMap.length; ++i) {
  24980. if (ArabicReshaper.combCharsMap[i][0][0] === c1 && ArabicReshaper.combCharsMap[i][0][1] === c2) {
  24981. return ArabicReshaper.combCharsMap[i];
  24982. }
  24983. }
  24984. return false;
  24985. }
  24986. isTransparent(c) {
  24987. for (var i = 0; i < ArabicReshaper.transChars.length; ++i) {
  24988. if (ArabicReshaper.transChars[i] === c) {
  24989. return true;
  24990. }
  24991. }
  24992. return false;
  24993. }
  24994. getOriginalCharsFromCode(code) {
  24995. var j;
  24996. for (j = 0; j < ArabicReshaper.charsMap.length; ++j) {
  24997. if (ArabicReshaper.charsMap[j].indexOf(code) > -1) {
  24998. return String.fromCharCode(ArabicReshaper.charsMap[j][0]);
  24999. }
  25000. }
  25001. for (j = 0; j < ArabicReshaper.combCharsMap.length; ++j) {
  25002. if (ArabicReshaper.combCharsMap[j].indexOf(code) > -1) {
  25003. return String.fromCharCode(ArabicReshaper.combCharsMap[j][0][0]) +
  25004. String.fromCharCode(ArabicReshaper.combCharsMap[j][0][1]);
  25005. }
  25006. }
  25007. return String.fromCharCode(code);
  25008. }
  25009. convertArabic(normal) {
  25010. var crep, combcrep, shaped = '';
  25011. for (var i = 0; i < normal.length; ++i) {
  25012. var current = normal.charCodeAt(i);
  25013. if (this.characterMapContains(current)) {
  25014. var prev = null, next = null, prevID = i - 1, nextID = i + 1;
  25015. for (; prevID >= 0; --prevID) {
  25016. if (!this.isTransparent(normal.charCodeAt(prevID))) {
  25017. break;
  25018. }
  25019. }
  25020. prev = (prevID >= 0) ? normal.charCodeAt(prevID) : null;
  25021. crep = prev ? this.getCharRep(prev) : false;
  25022. if (!crep || crep[2] == null && crep[3] == null) {
  25023. prev = null;
  25024. }
  25025. for (; nextID < normal.length; ++nextID) {
  25026. if (!this.isTransparent(normal.charCodeAt(nextID))) {
  25027. break;
  25028. }
  25029. }
  25030. next = (nextID < normal.length) ? normal.charCodeAt(nextID) : null;
  25031. crep = next ? this.getCharRep(next) : false;
  25032. if (!crep || crep[3] == null && crep[4] == null) {
  25033. next = null;
  25034. }
  25035. if (current === 0x0644 && next != null &&
  25036. (next === 0x0622 || next === 0x0623 || next === 0x0625 || next === 0x0627)) {
  25037. combcrep = this.getCombCharRep(current, next);
  25038. if (prev != null) {
  25039. shaped += String.fromCharCode(combcrep[4]);
  25040. }
  25041. else {
  25042. shaped += String.fromCharCode(combcrep[1]);
  25043. }
  25044. ++i;
  25045. continue;
  25046. }
  25047. crep = this.getCharRep(current);
  25048. if (prev != null && next != null && crep[3] != null) {
  25049. shaped += String.fromCharCode(crep[3]);
  25050. continue;
  25051. }
  25052. else if (prev != null && crep[4] != null) {
  25053. shaped += String.fromCharCode(crep[4]);
  25054. continue;
  25055. }
  25056. else if (next != null && crep[2] != null) {
  25057. shaped += String.fromCharCode(crep[2]);
  25058. continue;
  25059. }
  25060. else {
  25061. shaped += String.fromCharCode(crep[1]);
  25062. }
  25063. }
  25064. else {
  25065. shaped += String.fromCharCode(current);
  25066. }
  25067. }
  25068. return shaped;
  25069. }
  25070. convertArabicBack(apfb) {
  25071. var toReturn = '', selectedChar;
  25072. var i;
  25073. for (i = 0; i < apfb.length; ++i) {
  25074. selectedChar = apfb.charCodeAt(i);
  25075. toReturn += this.getOriginalCharsFromCode(selectedChar);
  25076. }
  25077. return toReturn;
  25078. }
  25079. }
  25080. ArabicReshaper.charsMap = [[0x0621, 0xFE80, null, null, null],
  25081. [0x0622, 0xFE81, null, null, 0xFE82],
  25082. [0x0623, 0xFE83, null, null, 0xFE84],
  25083. [0x0624, 0xFE85, null, null, 0xFE86],
  25084. [0x0625, 0xFE87, null, null, 0xFE88],
  25085. [0x0626, 0xFE89, 0xFE8B, 0xFE8C, 0xFE8A],
  25086. [0x0627, 0xFE8D, null, null, 0xFE8E],
  25087. [0x0628, 0xFE8F, 0xFE91, 0xFE92, 0xFE90],
  25088. [0x0629, 0xFE93, null, null, 0xFE94],
  25089. [0x062A, 0xFE95, 0xFE97, 0xFE98, 0xFE96],
  25090. [0x062B, 0xFE99, 0xFE9B, 0xFE9C, 0xFE9A],
  25091. [0x062C, 0xFE9D, 0xFE9F, 0xFEA0, 0xFE9E],
  25092. [0x062D, 0xFEA1, 0xFEA3, 0xFEA4, 0xFEA2],
  25093. [0x062E, 0xFEA5, 0xFEA7, 0xFEA8, 0xFEA6],
  25094. [0x062F, 0xFEA9, null, null, 0xFEAA],
  25095. [0x0630, 0xFEAB, null, null, 0xFEAC],
  25096. [0x0631, 0xFEAD, null, null, 0xFEAE],
  25097. [0x0632, 0xFEAF, null, null, 0xFEB0],
  25098. [0x0633, 0xFEB1, 0xFEB3, 0xFEB4, 0xFEB2],
  25099. [0x0634, 0xFEB5, 0xFEB7, 0xFEB8, 0xFEB6],
  25100. [0x0635, 0xFEB9, 0xFEBB, 0xFEBC, 0xFEBA],
  25101. [0x0636, 0xFEBD, 0xFEBF, 0xFEC0, 0xFEBE],
  25102. [0x0637, 0xFEC1, 0xFEC3, 0xFEC4, 0xFEC2],
  25103. [0x0638, 0xFEC5, 0xFEC7, 0xFEC8, 0xFEC6],
  25104. [0x0639, 0xFEC9, 0xFECB, 0xFECC, 0xFECA],
  25105. [0x063A, 0xFECD, 0xFECF, 0xFED0, 0xFECE],
  25106. [0x0640, 0x0640, 0x0640, 0x0640, 0x0640],
  25107. [0x0641, 0xFED1, 0xFED3, 0xFED4, 0xFED2],
  25108. [0x0642, 0xFED5, 0xFED7, 0xFED8, 0xFED6],
  25109. [0x0643, 0xFED9, 0xFEDB, 0xFEDC, 0xFEDA],
  25110. [0x0644, 0xFEDD, 0xFEDF, 0xFEE0, 0xFEDE],
  25111. [0x0645, 0xFEE1, 0xFEE3, 0xFEE4, 0xFEE2],
  25112. [0x0646, 0xFEE5, 0xFEE7, 0xFEE8, 0xFEE6],
  25113. [0x0647, 0xFEE9, 0xFEEB, 0xFEEC, 0xFEEA],
  25114. [0x0648, 0xFEED, null, null, 0xFEEE],
  25115. [0x0649, 0xFEEF, null, null, 0xFEF0],
  25116. [0x064A, 0xFEF1, 0xFEF3, 0xFEF4, 0xFEF2],
  25117. [0x067E, 0xFB56, 0xFB58, 0xFB59, 0xFB57],
  25118. [0x06CC, 0xFBFC, 0xFBFE, 0xFBFF, 0xFBFD],
  25119. [0x0686, 0xFB7A, 0xFB7C, 0xFB7D, 0xFB7B],
  25120. [0x06A9, 0xFB8E, 0xFB90, 0xFB91, 0xFB8F],
  25121. [0x06AF, 0xFB92, 0xFB94, 0xFB95, 0xFB93],
  25122. [0x0698, 0xFB8A, null, null, 0xFB8B]];
  25123. ArabicReshaper.combCharsMap = [[[0x0644, 0x0622], 0xFEF5, null, null, 0xFEF6],
  25124. [[0x0644, 0x0623], 0xFEF7, null, null, 0xFEF8],
  25125. [[0x0644, 0x0625], 0xFEF9, null, null, 0xFEFA],
  25126. [[0x0644, 0x0627], 0xFEFB, null, null, 0xFEFC]];
  25127. ArabicReshaper.transChars = [0x0610,
  25128. 0x0612,
  25129. 0x0613,
  25130. 0x0614,
  25131. 0x0615,
  25132. 0x064B,
  25133. 0x064C,
  25134. 0x064D,
  25135. 0x064E,
  25136. 0x064F,
  25137. 0x0650,
  25138. 0x0651,
  25139. 0x0652,
  25140. 0x0653,
  25141. 0x0654,
  25142. 0x0655,
  25143. 0x0656,
  25144. 0x0657,
  25145. 0x0658,
  25146. 0x0670,
  25147. 0x06D6,
  25148. 0x06D7,
  25149. 0x06D8,
  25150. 0x06D9,
  25151. 0x06DA,
  25152. 0x06DB,
  25153. 0x06DC,
  25154. 0x06DF,
  25155. 0x06E0,
  25156. 0x06E1,
  25157. 0x06E2,
  25158. 0x06E3,
  25159. 0x06E4,
  25160. 0x06E7,
  25161. 0x06E8,
  25162. 0x06EA,
  25163. 0x06EB,
  25164. 0x06EC,
  25165. 0x06ED];
  25166. class MatirxArray {
  25167. static ArrayMul(a, b, o) {
  25168. if (!a) {
  25169. MatirxArray.copyArray(b, o);
  25170. return;
  25171. }
  25172. if (!b) {
  25173. MatirxArray.copyArray(a, o);
  25174. return;
  25175. }
  25176. var ai0, ai1, ai2, ai3;
  25177. for (var i = 0; i < 4; i++) {
  25178. ai0 = a[i];
  25179. ai1 = a[i + 4];
  25180. ai2 = a[i + 8];
  25181. ai3 = a[i + 12];
  25182. o[i] = ai0 * b[0] + ai1 * b[1] + ai2 * b[2] + ai3 * b[3];
  25183. o[i + 4] = ai0 * b[4] + ai1 * b[5] + ai2 * b[6] + ai3 * b[7];
  25184. o[i + 8] = ai0 * b[8] + ai1 * b[9] + ai2 * b[10] + ai3 * b[11];
  25185. o[i + 12] = ai0 * b[12] + ai1 * b[13] + ai2 * b[14] + ai3 * b[15];
  25186. }
  25187. }
  25188. static copyArray(f, t) {
  25189. if (!f)
  25190. return;
  25191. if (!t)
  25192. return;
  25193. for (var i = 0; i < f.length; i++) {
  25194. t[i] = f[i];
  25195. }
  25196. }
  25197. }
  25198. exports.AlphaCmd = AlphaCmd;
  25199. exports.Animation = Animation;
  25200. exports.AnimationBase = AnimationBase;
  25201. exports.ArabicReshaper = ArabicReshaper;
  25202. exports.AtlasGrid = AtlasGrid;
  25203. exports.AtlasInfoManager = AtlasInfoManager;
  25204. exports.AudioSound = AudioSound;
  25205. exports.AudioSoundChannel = AudioSoundChannel;
  25206. exports.BasePoly = BasePoly;
  25207. exports.BaseShader = BaseShader;
  25208. exports.BaseTexture = BaseTexture;
  25209. exports.Bezier = Bezier;
  25210. exports.Bitmap = Bitmap;
  25211. exports.BitmapFont = BitmapFont;
  25212. exports.BlendMode = BlendMode;
  25213. exports.BlurFilter = BlurFilter;
  25214. exports.BlurFilterGLRender = BlurFilterGLRender;
  25215. exports.BlurFilterSetter = BlurFilterSetter;
  25216. exports.BoundsStyle = BoundsStyle;
  25217. exports.Browser = Browser;
  25218. exports.Buffer = Buffer;
  25219. exports.Buffer2D = Buffer2D;
  25220. exports.BufferState2D = BufferState2D;
  25221. exports.BufferStateBase = BufferStateBase;
  25222. exports.ButtonEffect = ButtonEffect;
  25223. exports.Byte = Byte;
  25224. exports.CONST3D2D = CONST3D2D;
  25225. exports.CacheManger = CacheManger;
  25226. exports.CacheStyle = CacheStyle;
  25227. exports.CallLater = CallLater;
  25228. exports.CharRenderInfo = CharRenderInfo;
  25229. exports.CharRender_Canvas = CharRender_Canvas;
  25230. exports.CharRender_Native = CharRender_Native;
  25231. exports.CharSubmitCache = CharSubmitCache;
  25232. exports.ClassUtils = ClassUtils;
  25233. exports.ClipRectCmd = ClipRectCmd;
  25234. exports.ColorFilter = ColorFilter;
  25235. exports.ColorFilterSetter = ColorFilterSetter;
  25236. exports.ColorUtils = ColorUtils;
  25237. exports.CommandEncoder = CommandEncoder;
  25238. exports.CommonScript = CommonScript;
  25239. exports.Component = Component;
  25240. exports.Config = Config;
  25241. exports.Const = Const;
  25242. exports.Context = Context;
  25243. exports.Dragging = Dragging;
  25244. exports.Draw9GridTexture = Draw9GridTexture;
  25245. exports.DrawCanvasCmd = DrawCanvasCmd;
  25246. exports.DrawCircleCmd = DrawCircleCmd;
  25247. exports.DrawCurvesCmd = DrawCurvesCmd;
  25248. exports.DrawImageCmd = DrawImageCmd;
  25249. exports.DrawLineCmd = DrawLineCmd;
  25250. exports.DrawLinesCmd = DrawLinesCmd;
  25251. exports.DrawParticleCmd = DrawParticleCmd;
  25252. exports.DrawPathCmd = DrawPathCmd;
  25253. exports.DrawPieCmd = DrawPieCmd;
  25254. exports.DrawPolyCmd = DrawPolyCmd;
  25255. exports.DrawRectCmd = DrawRectCmd;
  25256. exports.DrawStyle = DrawStyle;
  25257. exports.DrawTextureCmd = DrawTextureCmd;
  25258. exports.DrawTexturesCmd = DrawTexturesCmd;
  25259. exports.DrawTrianglesCmd = DrawTrianglesCmd;
  25260. exports.Earcut = Earcut;
  25261. exports.EarcutNode = EarcutNode;
  25262. exports.Ease = Ease;
  25263. exports.EffectAnimation = EffectAnimation;
  25264. exports.EffectBase = EffectBase;
  25265. exports.Event = Event;
  25266. exports.EventDispatcher = EventDispatcher;
  25267. exports.FadeIn = FadeIn;
  25268. exports.FadeOut = FadeOut;
  25269. exports.FillBorderTextCmd = FillBorderTextCmd;
  25270. exports.FillBorderWordsCmd = FillBorderWordsCmd;
  25271. exports.FillTextCmd = FillTextCmd;
  25272. exports.FillTextureCmd = FillTextureCmd;
  25273. exports.FillWordsCmd = FillWordsCmd;
  25274. exports.Filter = Filter;
  25275. exports.FilterSetterBase = FilterSetterBase;
  25276. exports.FontInfo = FontInfo;
  25277. exports.FrameAnimation = FrameAnimation;
  25278. exports.GlowFilter = GlowFilter;
  25279. exports.GlowFilterGLRender = GlowFilterGLRender;
  25280. exports.GlowFilterSetter = GlowFilterSetter;
  25281. exports.GrahamScan = GrahamScan;
  25282. exports.GraphicAnimation = GraphicAnimation;
  25283. exports.Graphics = Graphics;
  25284. exports.GraphicsBounds = GraphicsBounds;
  25285. exports.HTMLCanvas = HTMLCanvas;
  25286. exports.HTMLChar = HTMLChar;
  25287. exports.HTMLImage = HTMLImage;
  25288. exports.Handler = Handler;
  25289. exports.HitArea = HitArea;
  25290. exports.HttpRequest = HttpRequest;
  25291. exports.ICharRender = ICharRender;
  25292. exports.ILaya = ILaya;
  25293. exports.IStatRender = IStatRender;
  25294. exports.IndexBuffer2D = IndexBuffer2D;
  25295. exports.InlcudeFile = InlcudeFile;
  25296. exports.Input = Input;
  25297. exports.KeyBoardManager = KeyBoardManager;
  25298. exports.KeyLocation = KeyLocation;
  25299. exports.Keyboard = Keyboard;
  25300. exports.Laya = Laya;
  25301. exports.LayaGL = LayaGL;
  25302. exports.LayaGLQuickRunner = LayaGLQuickRunner;
  25303. exports.LayaGLRunner = LayaGLRunner;
  25304. exports.LayaGPU = LayaGPU;
  25305. exports.Loader = Loader;
  25306. exports.LoaderManager = LoaderManager;
  25307. exports.LocalStorage = LocalStorage;
  25308. exports.Log = Log;
  25309. exports.MathUtil = MathUtil;
  25310. exports.MatirxArray = MatirxArray;
  25311. exports.Matrix = Matrix;
  25312. exports.Mesh2D = Mesh2D;
  25313. exports.MeshParticle2D = MeshParticle2D;
  25314. exports.MeshQuadTexture = MeshQuadTexture;
  25315. exports.MeshTexture = MeshTexture;
  25316. exports.MeshVG = MeshVG;
  25317. exports.Mouse = Mouse;
  25318. exports.MouseManager = MouseManager;
  25319. exports.Node = Node;
  25320. exports.Path = Path;
  25321. exports.PerfData = PerfData;
  25322. exports.PerfHUD = PerfHUD;
  25323. exports.Point = Point;
  25324. exports.Pool = Pool;
  25325. exports.PoolCache = PoolCache;
  25326. exports.Prefab = Prefab;
  25327. exports.PrimitiveSV = PrimitiveSV;
  25328. exports.QuickTestTool = QuickTestTool;
  25329. exports.Rectangle = Rectangle;
  25330. exports.Render = Render;
  25331. exports.RenderInfo = RenderInfo;
  25332. exports.RenderSprite = RenderSprite;
  25333. exports.RenderState2D = RenderState2D;
  25334. exports.RenderTexture2D = RenderTexture2D;
  25335. exports.Resource = Resource;
  25336. exports.ResourceVersion = ResourceVersion;
  25337. exports.RestoreCmd = RestoreCmd;
  25338. exports.RotateCmd = RotateCmd;
  25339. exports.RunDriver = RunDriver;
  25340. exports.SaveBase = SaveBase;
  25341. exports.SaveClipRect = SaveClipRect;
  25342. exports.SaveCmd = SaveCmd;
  25343. exports.SaveMark = SaveMark;
  25344. exports.SaveTransform = SaveTransform;
  25345. exports.SaveTranslate = SaveTranslate;
  25346. exports.ScaleCmd = ScaleCmd;
  25347. exports.Scene = Scene;
  25348. exports.SceneLoader = SceneLoader;
  25349. exports.SceneUtils = SceneUtils;
  25350. exports.Script = Script;
  25351. exports.Shader = Shader;
  25352. exports.Shader2D = Shader2D;
  25353. exports.Shader2X = Shader2X;
  25354. exports.ShaderCompile = ShaderCompile;
  25355. exports.ShaderDefines2D = ShaderDefines2D;
  25356. exports.ShaderDefinesBase = ShaderDefinesBase;
  25357. exports.ShaderNode = ShaderNode;
  25358. exports.ShaderValue = ShaderValue;
  25359. exports.SkinMeshBuffer = SkinMeshBuffer;
  25360. exports.SkinSV = SkinSV;
  25361. exports.Socket = Socket;
  25362. exports.Sound = Sound;
  25363. exports.SoundChannel = SoundChannel;
  25364. exports.SoundManager = SoundManager;
  25365. exports.SoundNode = SoundNode;
  25366. exports.Sprite = Sprite;
  25367. exports.SpriteConst = SpriteConst;
  25368. exports.SpriteStyle = SpriteStyle;
  25369. exports.Stage = Stage;
  25370. exports.Stat = Stat;
  25371. exports.StatUI = StatUI;
  25372. exports.StringKey = StringKey;
  25373. exports.StrokeTextCmd = StrokeTextCmd;
  25374. exports.Submit = Submit;
  25375. exports.SubmitBase = SubmitBase;
  25376. exports.SubmitCMD = SubmitCMD;
  25377. exports.SubmitCanvas = SubmitCanvas;
  25378. exports.SubmitKey = SubmitKey;
  25379. exports.SubmitTarget = SubmitTarget;
  25380. exports.SubmitTexture = SubmitTexture;
  25381. exports.System = System;
  25382. exports.TTFLoader = TTFLoader;
  25383. exports.Text = Text;
  25384. exports.TextAtlas = TextAtlas;
  25385. exports.TextRender = TextRender;
  25386. exports.TextStyle = TextStyle;
  25387. exports.TextTexture = TextTexture;
  25388. exports.Texture = Texture;
  25389. exports.Texture2D = Texture2D;
  25390. exports.TextureSV = TextureSV;
  25391. exports.TimeLine = TimeLine;
  25392. exports.Timer = Timer;
  25393. exports.TouchManager = TouchManager;
  25394. exports.TransformCmd = TransformCmd;
  25395. exports.TranslateCmd = TranslateCmd;
  25396. exports.Tween = Tween;
  25397. exports.URL = URL;
  25398. exports.Utils = Utils;
  25399. exports.Value2D = Value2D;
  25400. exports.VectorGraphManager = VectorGraphManager;
  25401. exports.VertexArrayObject = VertexArrayObject;
  25402. exports.VertexBuffer2D = VertexBuffer2D;
  25403. exports.WeakObject = WeakObject;
  25404. exports.WebAudioSound = WebAudioSound;
  25405. exports.WebAudioSoundChannel = WebAudioSoundChannel;
  25406. exports.WebGL = WebGL;
  25407. exports.WebGLCacheAsNormalCanvas = WebGLCacheAsNormalCanvas;
  25408. exports.WebGLContext = WebGLContext;
  25409. exports.WebGLRTMgr = WebGLRTMgr;
  25410. exports.WordText = WordText;
  25411. exports.WorkerLoader = WorkerLoader;
  25412. exports.__init = __init;
  25413. exports._static = _static;
  25414. exports.alertGlobalError = alertGlobalError;
  25415. exports.enableDebugPanel = enableDebugPanel;
  25416. exports.init = init;
  25417. exports.isWXOpenDataContext = isWXOpenDataContext;
  25418. exports.isWXPosMsg = isWXPosMsg;
  25419. exports.version = version;
  25420. exports.static=_static;
  25421. return exports;
  25422. }({}));